~ubuntu-branches/ubuntu/trusty/hyperestraier/trusty-proposed

« back to all changes in this revision

Viewing changes to javanative/myconf.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2006-11-14 05:28:32 UTC
  • mfrom: (2.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061114052832-0lzqzcefn8mt4yqe
Tags: 1.4.9-1.1
* Non-maintainer upload.
* High-urgency upload for RC bugfix.
* Set HOME=$(CURDIR)/junkhome when building, otherwise the package build
  will incorrectly look for headers there -- and fail when the directory
  exists and is unreadable, as happens sometimes on sudo-using
  autobuilders!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*************************************************************************************************
2
2
 * Java binding of Hyper Estraier
3
 
 *                                                      Copyright (C) 2004-2005 Mikio Hirabayashi
 
3
 *                                                      Copyright (C) 2004-2006 Mikio Hirabayashi
4
4
 * This file is part of Hyper Estraier.
5
5
 * Hyper Estraier is free software; you can redistribute it and/or modify it under the terms of
6
6
 * the GNU Lesser General Public License as published by the Free Software Foundation; either
53
53
jobject cblisttoobj(JNIEnv *env, const CBLIST *list){
54
54
  jclass cls;
55
55
  jmethodID mid;
56
 
  jobject obj;
 
56
  jobject obj, kobj;
57
57
  int i;
58
58
  assert(list);
59
59
  cls = (*env)->FindClass(env, CLSARRAYLIST);
61
61
  obj = (*env)->NewObject(env, cls, mid);
62
62
  mid = (*env)->GetMethodID(env, cls, "add", "(L" CLSOBJECT ";)Z");
63
63
  for(i = 0; i < cblistnum(list); i++){
64
 
    (*env)->CallVoidMethod(env, obj, mid, (*env)->NewStringUTF(env, cblistval(list, i, NULL)));
 
64
    kobj = (*env)->NewStringUTF(env, cblistval(list, i, NULL));
 
65
    (*env)->CallVoidMethod(env, obj, mid, kobj);
 
66
    (*env)->DeleteLocalRef(env, kobj);
65
67
  }
66
68
  return obj;
67
69
}
96
98
jobject cbmaptoobj(JNIEnv *env, CBMAP *map){
97
99
  jclass cls;
98
100
  jmethodID mid;
99
 
  jobject obj;
 
101
  jobject obj, kobj, vobj;
100
102
  const char *kbuf, *vbuf;
101
 
  int ksiz;
102
103
  assert(list);
103
104
  cls = (*env)->FindClass(env, CLSLHMAP);
104
105
  mid = (*env)->GetMethodID(env, cls, "<init>", "()V");
105
106
  obj = (*env)->NewObject(env, cls, mid);
106
107
  mid = (*env)->GetMethodID(env, cls, "put", "(L" CLSOBJECT ";L" CLSOBJECT ";)L" CLSOBJECT ";");
107
108
  cbmapiterinit(map);
108
 
  while((kbuf = cbmapiternext(map, &ksiz)) != NULL){
109
 
    vbuf = cbmapget(map, kbuf, ksiz, NULL);
110
 
    (*env)->CallObjectMethod(env, obj, mid,
111
 
                             (*env)->NewStringUTF(env, kbuf), (*env)->NewStringUTF(env, vbuf));
 
109
  while((kbuf = cbmapiternext(map, NULL)) != NULL){
 
110
    vbuf = cbmapiterval(kbuf, NULL);
 
111
    kobj = (*env)->NewStringUTF(env, kbuf);
 
112
    vobj = (*env)->NewStringUTF(env, vbuf);
 
113
    (*env)->CallObjectMethod(env, obj, mid, kobj, vobj);
 
114
    (*env)->DeleteLocalRef(env, kobj);
 
115
    (*env)->DeleteLocalRef(env, vobj);
112
116
  }
113
117
  return obj;
114
118
}
115
119
 
116
120
 
 
121
CBMAP *objtocbmap(JNIEnv *env, jobject obj){
 
122
  jclass map, set, it;
 
123
  jmethodID midks, midg, midit, midhn, midn;
 
124
  jobject ksobj, itobj, ekobj, evobj;
 
125
  jboolean ickey, icval;
 
126
  CBMAP *tmap;
 
127
  const char *tkey, *tval;
 
128
  assert(obj);
 
129
  tmap = cbmapopenex(31);
 
130
  map = (*env)->GetObjectClass(env, obj);
 
131
  midks = (*env)->GetMethodID(env, map, "keySet", "()L" CLSSET ";");
 
132
  midg = (*env)->GetMethodID(env, map, "get", "(L" CLSOBJECT ";)L" CLSOBJECT ";");
 
133
  ksobj = (*env)->CallObjectMethod(env, obj, midks);
 
134
  set = (*env)->GetObjectClass(env, ksobj);
 
135
  midit = (*env)->GetMethodID(env, set, "iterator", "()L" CLSITERATOR ";");
 
136
  itobj = (*env)->CallObjectMethod(env, ksobj, midit);
 
137
  it = (*env)->GetObjectClass(env, itobj);
 
138
  midhn = (*env)->GetMethodID(env, it, "hasNext", "()Z");
 
139
  midn = (*env)->GetMethodID(env, it, "next", "()L" CLSOBJECT ";");
 
140
  while((*env)->CallBooleanMethod(env, itobj, midhn)){
 
141
    ekobj = (*env)->CallObjectMethod(env, itobj, midn);
 
142
    if(!isinstanceof(env, ekobj, CLSSTRING)) continue;
 
143
    if(!(tkey = (*env)->GetStringUTFChars(env, ekobj, &ickey))) continue;
 
144
    evobj = (*env)->CallObjectMethod(env, obj, midg, ekobj);
 
145
    if(!isinstanceof(env, evobj, CLSSTRING) ||
 
146
       !(tval = (*env)->GetStringUTFChars(env, evobj, &icval))){
 
147
      if(ickey == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, ekobj, tkey);
 
148
      continue;
 
149
    }
 
150
    cbmapput(tmap, tkey, -1, tval, -1, TRUE);
 
151
    if(icval == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, evobj, tval);
 
152
    if(ickey == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, ekobj, tkey);
 
153
  }
 
154
  return tmap;
 
155
}
 
156
 
 
157
 
117
158
 
118
159
/* END OF FILE */