File: extractor.c

package info (click to toggle)
libextractor-java 0.5.6-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,540 kB
  • ctags: 407
  • sloc: sh: 8,422; ansic: 690; java: 159; makefile: 80
file content (231 lines) | stat: -rw-r--r-- 6,255 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*
     This file is part of libextractor.
     (C) 2002, 2003, 2004, 2005 Vidyut Samanta and Christian Grothoff

     libextractor is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 2, or (at your
     option) any later version.

     libextractor is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with libextractor; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, USA.
 */

#include "config.h"
#include <extractor.h>
#include <jni.h>

/* gcj's jni.h does not define JNIEXPORT/JNICALL (at least
 * not in my version).  Sun defines it to 'empty' on GNU/Linux,
 * so that should work */
#ifndef JNIEXPORT
#define JNIEXPORT
#endif
#ifndef JNICALL
#define JNICALL
#endif

#include "org_gnunet_libextractor_Extractor.h"

#define HIGHEST_TYPE_NUMBER EXTRACTOR_getHighestKeywordTypeNumber()

/*
 * Class:     org_gnunet_libextractor_Extractor
 * Method:    loadDefaultInternal
 * Signature: ()J
 */
JNIEXPORT jlong JNICALL 
Java_org_gnunet_libextractor_Extractor_loadDefaultInternal(JNIEnv * env,
							   jclass c) {
  return (jlong) (long) EXTRACTOR_loadDefaultLibraries();
}

/*
 * Class:     org_gnunet_libextractor_Extractor
 * Method:    unloadInternal
 * Signature: (J)V
 */
JNIEXPORT void JNICALL 
Java_org_gnunet_libextractor_Extractor_unloadInternal(JNIEnv * env,
						      jclass c,
						      jlong arg) {
  EXTRACTOR_removeAll((EXTRACTOR_ExtractorList*) (long) arg);
}

/*
 * Class:     org_gnunet_libextractor_Extractor
 * Method:    extractInternal
 * Signature: (JLjava/lang/String;)J
 */
JNIEXPORT jlong JNICALL 
Java_org_gnunet_libextractor_Extractor_extractInternal(JNIEnv * env,
						       jclass c,
						       jlong arg,
						       jstring f) {
  const char * fname;
  jboolean bo;
  jlong ret;

  bo = JNI_FALSE;
  fname = (*env)->GetStringUTFChars(env, f, &bo);
  ret = (jlong) (long) EXTRACTOR_getKeywords((EXTRACTOR_ExtractorList*) (long) arg,
					     fname);
  (*env)->ReleaseStringUTFChars(env, f, fname);
  return ret;
}

/*
 * Class:     org_gnunet_libextractor_Extractor
 * Method:    freeInternal
 * Signature: (J)V
 */
JNIEXPORT void JNICALL 
Java_org_gnunet_libextractor_Extractor_freeInternal(JNIEnv * env,
						    jclass c,
						    jlong list) {
  EXTRACTOR_freeKeywords( (EXTRACTOR_KeywordList*) (long) list);
}

/*
 * Class:     org_gnunet_libextractor_Extractor
 * Method:    typeInternal
 * Signature: (J)I
 */
JNIEXPORT jint JNICALL 
Java_org_gnunet_libextractor_Extractor_typeInternal(JNIEnv * env,
						    jclass c,
						    jlong list) {
  if (list == 0)
    return -1; /* error! */
  return ((EXTRACTOR_KeywordList*) (long) list)->keywordType;
}

/*
 * Class:     org_gnunet_libextractor_Extractor
 * Method:    keywordInternal
 * Signature: (J)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL 
Java_org_gnunet_libextractor_Extractor_keywordInternal(JNIEnv * env,
						       jclass c,
						       jlong list) {
  char * str;
  if (list == 0)
    return NULL; /* error! */
  str = ((EXTRACTOR_KeywordList*) (long) list)->keyword;
  return (*env)->NewStringUTF(env, str);
}

/*
 * Class:     org_gnunet_libextractor_Extractor
 * Method:    nextInternal
 * Signature: (J)J
 */
JNIEXPORT jlong JNICALL 
Java_org_gnunet_libextractor_Extractor_nextInternal(JNIEnv * env,
						    jclass j,
						    jlong list) {
  if (list == 0)
    return 0; /* error! */
  return (jlong) (long) ((EXTRACTOR_KeywordList*) (long) list)->next;
}

/*
 * Class:     org_gnunet_libextractor_Extractor
 * Method:    getTypeAsStringInternal
 * Signature: (I)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL 
Java_org_gnunet_libextractor_Extractor_getTypeAsStringInternal(JNIEnv * env,
							       jclass c,
							       jint type) {
  const char * str;
  if ( (type < 0) || (type > HIGHEST_TYPE_NUMBER) )
    return NULL; /* error! */
  str = EXTRACTOR_getKeywordTypeAsString((EXTRACTOR_KeywordType)type);
  if (str == NULL)
    return NULL;
  return (*env)->NewStringUTF(env,
			      str);
}


/*
 * Class:     org_gnunet_libextractor_Extractor
 * Method:    getVersionInternal
 * Signature: ()I
 */
JNIEXPORT jint JNICALL 
Java_org_gnunet_libextractor_Extractor_getVersionInternal(JNIEnv * env,
							  jclass c) {
  return EXTRACTOR_VERSION;
}

/*
 * Class:     org_gnunet_libextractor_Extractor
 * Method:    getMaxTypeInternal
 * Signature: ()I
 */
JNIEXPORT jint JNICALL 
Java_org_gnunet_libextractor_Extractor_getMaxTypeInternal(JNIEnv * env,
							  jclass c) {
  return HIGHEST_TYPE_NUMBER;
}

/*
 * Class:     org_gnunet_libextractor_Extractor
 * Method:    unloadPlugin
 * Signature: (JLjava/lang/String;)J
 */
JNIEXPORT jlong JNICALL 
Java_org_gnunet_libextractor_Extractor_unloadPlugin(JNIEnv * env,
									  jclass c,
									  jlong handle,
									  jstring name) {
  const char * lname;
  jboolean bo;
  jlong ret;

  bo = JNI_FALSE;
  lname = (*env)->GetStringUTFChars(env, name, &bo);
  ret = (jlong) (long) EXTRACTOR_removeLibrary((EXTRACTOR_ExtractorList*) (long) handle,
					       lname);
  (*env)->ReleaseStringUTFChars(env, name, lname);
  return ret;
}

/*
 * Class:     org_gnunet_libextractor_Extractor
 * Method:    loadPlugin
 * Signature: (JLjava/lang/String;Z)J
 */
JNIEXPORT jlong JNICALL 
Java_org_gnunet_libextractor_Extractor_loadPlugin(JNIEnv * env,
						  jclass c,
						  jlong handle,
						  jstring name,
						  jboolean place) {
  const char * lname;
  jboolean bo;
  jlong ret;

  bo = JNI_FALSE;
  lname = (*env)->GetStringUTFChars(env, name, &bo);
  if (place == JNI_TRUE) {
    ret = (jlong) (long) EXTRACTOR_addLibraryLast((EXTRACTOR_ExtractorList*) (long) handle,
						  lname);
  } else {
    ret = (jlong) (long) EXTRACTOR_addLibrary((EXTRACTOR_ExtractorList*) (long) handle,
					      lname);
  }
  (*env)->ReleaseStringUTFChars(env, name, lname);
  return ret;
}