libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 141f6da61f852b17649fb91044e14cec7a53dc63
parent cfce815af55237294fb1be747ef48630a29ffe6d
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon,  4 Jul 2005 16:18:35 +0000

ready for 0.5.1Ä


Diffstat:
MChangeLog | 6++++++
MINSTALL | 61++++++++++++++++++++++++++++++++++---------------------------
Mcompile | 90++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Mconfigure.ac | 15---------------
Mlibltdl/install-sh | 102+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/include/extractor.h | 3+--
Msrc/main/Makefile.am | 12+-----------
Msrc/main/extractor.c | 208+------------------------------------------------------------------------------
Dsrc/main/libextractor_python.c | 527-------------------------------------------------------------------------------
Dsrc/main/libextractor_python_setup.py | 17-----------------
Dsrc/main/org_gnunet_libextractor_Extractor.h | 109-------------------------------------------------------------------------------
Dsrc/org/gnunet/libextractor/.cvsignore | 1-
Dsrc/org/gnunet/libextractor/Extractor.java | 290-------------------------------------------------------------------------------
Dsrc/org/gnunet/libextractor/Xtract.java | 45---------------------------------------------
14 files changed, 141 insertions(+), 1345 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,9 @@ +Mon Jul 4 18:10:14 CEST 2005 + Preliminary integration of exiv2 support (not enabled + by default due to bugs). Moved Python and Java + bindings into seperate packages. + Releasing libextractor 0.5.1. + Wed Jun 29 15:37:51 CEST 2005 Finally found out how to disable building static libs. This should cut down compile time and installed size diff --git a/INSTALL b/INSTALL @@ -1,13 +1,16 @@ -Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software -Foundation, Inc. +Installation Instructions +************************* - This file is free documentation; the Free Software Foundation gives +Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free +Software Foundation, Inc. + +This file is free documentation; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. Basic Installation ================== - These are generic installation instructions. +These are generic installation instructions. The `configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses @@ -67,9 +70,9 @@ The simplest way to compile this package is: Compilers and Options ===================== - Some systems require unusual options for compilation or linking that -the `configure' script does not know about. Run `./configure --help' -for details on some of the pertinent environment variables. +Some systems require unusual options for compilation or linking that the +`configure' script does not know about. Run `./configure --help' for +details on some of the pertinent environment variables. You can give `configure' initial values for configuration parameters by setting variables in the command line or in the environment. Here @@ -82,7 +85,7 @@ is an example: Compiling For Multiple Architectures ==================================== - You can compile the package for more than one kind of computer at the +You can compile the package for more than one kind of computer at the same time, by placing the object files for each architecture in their own directory. To do this, you must use a version of `make' that supports the `VPATH' variable, such as GNU `make'. `cd' to the @@ -99,19 +102,19 @@ for another architecture. Installation Names ================== - By default, `make install' will install the package's files in +By default, `make install' will install the package's files in `/usr/local/bin', `/usr/local/man', etc. You can specify an installation prefix other than `/usr/local' by giving `configure' the -option `--prefix=PATH'. +option `--prefix=PREFIX'. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you -give `configure' the option `--exec-prefix=PATH', the package will use -PATH as the prefix for installing programs and libraries. +give `configure' the option `--exec-prefix=PREFIX', the package will +use PREFIX as the prefix for installing programs and libraries. Documentation and other data files will still use the regular prefix. In addition, if you use an unusual directory layout you can give -options like `--bindir=PATH' to specify different values for particular +options like `--bindir=DIR' to specify different values for particular kinds of files. Run `configure --help' for a list of the directories you can set and what kinds of files go in them. @@ -122,7 +125,7 @@ option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. Optional Features ================= - Some packages pay attention to `--enable-FEATURE' options to +Some packages pay attention to `--enable-FEATURE' options to `configure', where FEATURE indicates an optional part of the package. They may also pay attention to `--with-PACKAGE' options, where PACKAGE is something like `gnu-as' or `x' (for the X Window System). The @@ -137,11 +140,11 @@ you can use the `configure' options `--x-includes=DIR' and Specifying the System Type ========================== - There may be some features `configure' cannot figure out -automatically, but needs to determine by the type of machine the package -will run on. Usually, assuming the package is built to be run on the -_same_ architectures, `configure' can figure that out, but if it prints -a message saying it cannot guess the machine type, give it the +There may be some features `configure' cannot figure out automatically, +but needs to determine by the type of machine the package will run on. +Usually, assuming the package is built to be run on the _same_ +architectures, `configure' can figure that out, but if it prints a +message saying it cannot guess the machine type, give it the `--build=TYPE' option. TYPE can either be a short name for the system type, such as `sun4', or a canonical name which has the form: @@ -167,9 +170,9 @@ eventually be run) with `--host=TYPE'. Sharing Defaults ================ - If you want to set default values for `configure' scripts to share, -you can create a site shell script called `config.site' that gives -default values for variables like `CC', `cache_file', and `prefix'. +If you want to set default values for `configure' scripts to share, you +can create a site shell script called `config.site' that gives default +values for variables like `CC', `cache_file', and `prefix'. `configure' looks for `PREFIX/share/config.site' if it exists, then `PREFIX/etc/config.site' if it exists. Or, you can set the `CONFIG_SITE' environment variable to the location of the site script. @@ -178,7 +181,7 @@ A warning: not all `configure' scripts look for a site script. Defining Variables ================== - Variables not defined in a site shell script can be set in the +Variables not defined in a site shell script can be set in the environment passed to `configure'. However, some packages may run configure again during the build, and the customized values of these variables may be lost. In order to avoid this problem, you should set @@ -186,14 +189,18 @@ them in the `configure' command line, using `VAR=value'. For example: ./configure CC=/usr/local2/bin/gcc -will cause the specified gcc to be used as the C compiler (unless it is -overridden in the site shell script). +causes the specified `gcc' to be used as the C compiler (unless it is +overridden in the site shell script). Here is a another example: + + /bin/bash ./configure CONFIG_SHELL=/bin/bash + +Here the `CONFIG_SHELL=/bin/bash' operand causes subsequent +configuration-related scripts to be executed by `/bin/bash'. `configure' Invocation ====================== - `configure' recognizes the following options to control how it -operates. +`configure' recognizes the following options to control how it operates. `--help' `-h' diff --git a/compile b/compile @@ -1,9 +1,9 @@ #! /bin/sh # Wrapper for compilers which do not understand `-c -o'. -scriptversion=2003-11-09.00 +scriptversion=2005-02-03.08 -# Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc. +# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc. # Written by Tom Tromey <tromey@cygnus.com>. # # This program is free software; you can redistribute it and/or modify @@ -47,45 +47,49 @@ right script to run: please start by reading the file `INSTALL'. Report bugs to <bug-automake@gnu.org>. EOF - exit 0 + exit $? ;; -v | --v*) echo "compile $scriptversion" - exit 0 + exit $? ;; esac - -prog=$1 -shift - ofile= cfile= -args= -while test $# -gt 0; do - case "$1" in - -o) - # configure might choose to run compile as `compile cc -o foo foo.c'. - # So we do something ugly here. - ofile=$2 - shift - case "$ofile" in - *.o | *.obj) - ;; - *) - args="$args -o $ofile" - ofile= - ;; - esac - ;; - *.c) - cfile=$1 - args="$args $1" - ;; - *) - args="$args $1" - ;; - esac +eat= + +for arg +do + if test -n "$eat"; then + eat= + else + case $1 in + -o) + # configure might choose to run compile as `compile cc -o foo foo.c'. + # So we strip `-o arg' only if arg is an object. + eat=1 + case $2 in + *.o | *.obj) + ofile=$2 + ;; + *) + set x "$@" -o "$2" + shift + ;; + esac + ;; + *.c) + cfile=$1 + set x "$@" "$1" + shift + ;; + *) + set x "$@" "$1" + shift + ;; + esac + fi shift done @@ -95,36 +99,38 @@ if test -z "$ofile" || test -z "$cfile"; then # normal compilation that the losing compiler can handle. If no # `.c' file was seen then we are probably linking. That is also # ok. - exec "$prog" $args + exec "$@" fi # Name of file we expect compiler to create. -cofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'` +cofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'` # Create the lock directory. # Note: use `[/.-]' here to ensure that we don't use the same name # that we are using for the .o file. Also, base the name on the expected # object file name, since that is what matters with a parallel build. -lockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d +lockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d while true; do - if mkdir $lockdir > /dev/null 2>&1; then + if mkdir "$lockdir" >/dev/null 2>&1; then break fi sleep 1 done # FIXME: race condition here if user kills between mkdir and trap. -trap "rmdir $lockdir; exit 1" 1 2 15 +trap "rmdir '$lockdir'; exit 1" 1 2 15 # Run the compile. -"$prog" $args -status=$? +"$@" +ret=$? if test -f "$cofile"; then mv "$cofile" "$ofile" +elif test -f "${cofile}bj"; then + mv "${cofile}bj" "$ofile" fi -rmdir $lockdir -exit $status +rmdir "$lockdir" +exit $ret # Local Variables: # mode: shell-script diff --git a/configure.ac b/configure.ac @@ -158,21 +158,6 @@ AC_CHECK_HEADERS([fcntl.h netinet/in.h stdlib.h string.h unistd.h libintl.h limi AC_CHECK_HEADERS([ltdl.h iconv.h]) # fixme, we need to die here if a header is not found! -AC_CHECK_HEADERS([jni.h]) -# jni.h is purely optional! But if not present => no Java support! - -AC_PYTHON_DEVEL - -AC_MSG_CHECKING(for python) -if test -z "$python_path"; -then - AC_MSG_RESULT(yes) - AM_CONDITIONAL(HAVE_PYTHON,false) -else - AC_MSG_RESULT(no) - AM_CONDITIONAL(HAVE_PYTHON,true) -fi - AC_CHECK_HEADERS([vorbis/vorbisfile.h]) # Checks for typedefs, structures, and compiler characteristics. diff --git a/libltdl/install-sh b/libltdl/install-sh @@ -1,7 +1,7 @@ #!/bin/sh # install - install a program, script, or datafile -scriptversion=2004-04-01.17 +scriptversion=2005-02-02.21 # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the @@ -58,9 +58,6 @@ stripprog="${STRIPPROG-strip}" rmprog="${RMPROG-rm}" mkdirprog="${MKDIRPROG-mkdir}" -transformbasename= -transform_arg= -instcmd="$mvprog" chmodcmd="$chmodprog 0755" chowncmd= chgrpcmd= @@ -70,23 +67,27 @@ mvcmd="$mvprog" src= dst= dir_arg= +dstarg= +no_target_directory= -usage="Usage: $0 [OPTION]... SRCFILE DSTFILE +usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE or: $0 [OPTION]... SRCFILES... DIRECTORY - or: $0 -d DIRECTORIES... + or: $0 [OPTION]... -t DIRECTORY SRCFILES... + or: $0 [OPTION]... -d DIRECTORIES... -In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default. -In the second, create the directory path DIR. +In the 1st form, copy SRCFILE to DSTFILE. +In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. +In the 4th, create DIRECTORIES. Options: --b=TRANSFORMBASENAME --c copy source (using $cpprog) instead of moving (using $mvprog). +-c (ignored) -d create directories instead of installing files. --g GROUP $chgrp installed files to GROUP. --m MODE $chmod installed files to MODE. --o USER $chown installed files to USER. --s strip installed files (using $stripprog). --t=TRANSFORM +-g GROUP $chgrpprog installed files to GROUP. +-m MODE $chmodprog installed files to MODE. +-o USER $chownprog installed files to USER. +-s $stripprog installed files. +-t DIRECTORY install into DIRECTORY. +-T report an error if DSTFILE is a directory. --help display this help and exit. --version display version info and exit. @@ -96,12 +97,7 @@ Environment variables override the default commands: while test -n "$1"; do case $1 in - -b=*) transformbasename=`echo $1 | sed 's/-b=//'` - shift - continue;; - - -c) instcmd=$cpprog - shift + -c) shift continue;; -d) dir_arg=true @@ -113,7 +109,7 @@ while test -n "$1"; do shift continue;; - --help) echo "$usage"; exit 0;; + --help) echo "$usage"; exit $?;; -m) chmodcmd="$chmodprog $2" shift @@ -129,14 +125,20 @@ while test -n "$1"; do shift continue;; - -t=*) transformarg=`echo $1 | sed 's/-t=//'` - shift - continue;; + -t) dstarg=$2 + shift + shift + continue;; - --version) echo "$0 $scriptversion"; exit 0;; + -T) no_target_directory=true + shift + continue;; + + --version) echo "$0 $scriptversion"; exit $?;; *) # When -d is used, all remaining arguments are directories to create. - test -n "$dir_arg" && break + # When -t is used, the destination is already specified. + test -n "$dir_arg$dstarg" && break # Otherwise, the last argument is the destination. Remove it from $@. for arg do @@ -174,13 +176,13 @@ do src= if test -d "$dst"; then - instcmd=: + mkdircmd=: chmodcmd= else - instcmd=$mkdirprog + mkdircmd=$mkdirprog fi else - # Waiting for this to be detected by the "$instcmd $src $dsttmp" command + # Waiting for this to be detected by the "$cpprog $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if test ! -f "$src" && test ! -d "$src"; then @@ -202,12 +204,16 @@ do # If destination is a directory, append the input filename; won't work # if double slashes aren't ignored. if test -d "$dst"; then + if test -n "$no_target_directory"; then + echo "$0: $dstarg: Is a directory" >&2 + exit 1 + fi dst=$dst/`basename "$src"` fi fi # This sed command emulates the dirname command. - dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'` # Make sure that the destination directory exists. @@ -220,7 +226,8 @@ do oIFS=$IFS # Some sh's can't handle IFS=/ for some reason. IFS='%' - set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` + set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` + shift IFS=$oIFS pathcomp= @@ -229,51 +236,42 @@ do pathcomp=$pathcomp$1 shift if test ! -d "$pathcomp"; then - $mkdirprog "$pathcomp" || lasterr=$? + $mkdirprog "$pathcomp" # mkdir can fail with a `File exist' error in case several # install-sh are creating the directory concurrently. This # is OK. - test ! -d "$pathcomp" && { (exit ${lasterr-1}); exit; } + test -d "$pathcomp" || exit fi pathcomp=$pathcomp/ done fi if test -n "$dir_arg"; then - $doit $instcmd "$dst" \ + $doit $mkdircmd "$dst" \ && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \ && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \ && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \ && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; } else - # If we're going to rename the final executable, determine the name now. - if test -z "$transformarg"; then - dstfile=`basename "$dst"` - else - dstfile=`basename "$dst" $transformbasename \ - | sed $transformarg`$transformbasename - fi - - # don't allow the sed command to completely eliminate the filename. - test -z "$dstfile" && dstfile=`basename "$dst"` + dstfile=`basename "$dst"` # Make a couple of temp file names in the proper directory. dsttmp=$dstdir/_inst.$$_ rmtmp=$dstdir/_rm.$$_ # Trap to clean up those temp files at exit. - trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0 + trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 trap '(exit $?); exit' 1 2 13 15 - # Move or copy the file name to the temp name - $doit $instcmd "$src" "$dsttmp" && + # Copy the file name to the temp name. + $doit $cpprog "$src" "$dsttmp" && # and set any options; do chmod last to preserve setuid bits. # # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore - # errors from the above "$doit $instcmd $src $dsttmp" command. + # errors from the above "$doit $cpprog $src $dsttmp" command. # { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ @@ -298,7 +296,7 @@ do || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \ || { echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 - (exit 1); exit + (exit 1); exit 1 } else : @@ -309,12 +307,12 @@ do $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" } } - fi || { (exit 1); exit; } + fi || { (exit 1); exit 1; } done # The final little trick to "correctly" pass the exit status to the exit trap. { - (exit 0); exit + (exit 0); exit 0 } # Local variables: diff --git a/src/include/extractor.h b/src/include/extractor.h @@ -137,8 +137,7 @@ typedef enum { EXTRACTOR_MACRO_MODE = 84, EXTRACTOR_IMAGE_QUALITY = 85, EXTRACTOR_WHITE_BALANCE = 86, - EXTRACTOR_FILESIZE = 87, - EXTRACTOR_ORIENTATION = 88, + EXTRACTOR_ORIENTATION = 87, } EXTRACTOR_KeywordType; /** diff --git a/src/main/Makefile.am b/src/main/Makefile.am @@ -33,10 +33,6 @@ libextractor_la_DEPENDENCIES = \ EXTRA_DIST = \ winproc.c \ - libextractor_python.c \ - Extractor.py \ - libextractor_python_setup.py \ - extract.py \ iconv.c if MINGW @@ -45,8 +41,7 @@ endif libextractor_la_SOURCES = \ extractor.c \ - $(winproc) \ - org_gnunet_libextractor_Extractor.h + $(winproc) extract_SOURCES = \ extract.c \ @@ -54,8 +49,3 @@ extract_SOURCES = \ getopt.h \ getopt1.c -if HAVE_PYTHON -install-exec-local: - python libextractor_python_setup.py $(libdir) build - python libextractor_python_setup.py $(libdir) install --prefix=$(PYTHON_PREFIX) -endif diff --git a/src/main/extractor.c b/src/main/extractor.c @@ -121,13 +121,12 @@ static const char *keywordTypes[] = { gettext_noop("macro mode"), gettext_noop("image quality"), gettext_noop("white balance"), - gettext_noop("filesize"), gettext_noop("orientation"), NULL, }; /* the number of keyword types (for bounds-checking) */ -#define HIGHEST_TYPE_NUMBER 89 +#define HIGHEST_TYPE_NUMBER 88 #ifdef HAVE_LIBOGG #if HAVE_VORBIS @@ -903,209 +902,4 @@ EXTRACTOR_countKeywords (EXTRACTOR_KeywordList * keywords) return count; } - - -/* ******************* Java support *********************** */ - -#ifdef HAVE_JNI_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" - -/* - * 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 = gettext(keywordTypes[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; -} - -/* #ifdef HAVE_JNI_H */ -#endif - - /* end of extractor.c */ diff --git a/src/main/libextractor_python.c b/src/main/libextractor_python.c @@ -1,527 +0,0 @@ -/* - This file is part of libextractor. - (C) 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. - */ - - -/* libextractor_python.c - --------------------- - - Implements the Python wrapper for libextractor. The wrapper builds on the - Python type module, which wraps a single module, over extractor, which - implements the extractor from modules, up to keyword(list), which implements - keyword handling. */ - -/* Includes. */ - -#include <Python.h> -#include "extractor.h" - -/* Typedefs. */ - -typedef struct { - PyObject_HEAD - PyObject *mlist; - int locks; -} ModuleList; - -typedef struct { - PyObject_HEAD - EXTRACTOR_ExtractorList *module; - ModuleList *mlist; -} Module; - -/* Type objects. */ - -static PyTypeObject ModuleListType; -static PyTypeObject ModuleType; - -/* Module list type. */ - -static inline int ModuleList_checkModule(Module *arg) -{ - if( !PyObject_IsInstance((PyObject*)arg,(PyObject*)&ModuleType) ) { - PyErr_SetString(PyExc_TypeError,"append only accepts a Module."); - return -1; - } - - if( arg->mlist ) { - PyErr_SetString(PyExc_TypeError,"cannot take ownership of module."); - return -1; - } - - return 0; -} - -static PyObject *ModuleList_prepend(ModuleList *self, Module *arg) -{ - PyObject *rv = NULL; - Module *first = NULL; - int mlistlen = 0; - - if( ModuleList_checkModule(arg) ) - goto error; - - mlistlen = PyList_GET_SIZE(self->mlist); - if( mlistlen ) { - first = (Module*)PyList_GET_ITEM(self->mlist,0); - arg->module->next = first->module; - } - - if( PyList_Insert(self->mlist,0,(PyObject*)arg) ) - goto error; - arg->mlist = self; - Py_INCREF(self); - - rv = (PyObject*)arg; - Py_INCREF(rv); - - goto finish; - - error: - Py_XDECREF(rv); - rv = NULL; - - finish: - return (PyObject*)rv; -} - -static PyObject *ModuleList_append(ModuleList *self, Module *arg) -{ - PyObject *rv = NULL; - Module *last = NULL; - int mlistlen = 0; - - if( ModuleList_checkModule(arg) ) - goto error; - - mlistlen = PyList_GET_SIZE(self->mlist); - if( mlistlen ) { - last = (Module*)PyList_GET_ITEM(self->mlist,mlistlen-1); - last->module->next = arg->module; - } - - if( PyList_Append(self->mlist,(PyObject*)arg) ) - goto error; - arg->mlist = self; - Py_INCREF(self); - - rv = (PyObject*)arg; - Py_INCREF(rv); - - goto finish; - - error: - Py_XDECREF(rv); - rv = NULL; - - finish: - return (PyObject*)rv; -} - -static PyObject *ModuleList_new(PyTypeObject *type, PyObject *args, - PyObject *kwargs) -{ - ModuleList *self = NULL; - - if( !( self = (ModuleList*)type->tp_alloc(type,0) ) ) - goto error; - self->locks = 0; - - if( !( self->mlist = PyList_New(0) ) ) - goto error; - - goto finish; - - error: - Py_XDECREF(self); - self = NULL; - - finish: - return (PyObject*)self; -} - -static int ModuleList_init(ModuleList *self, PyObject *args, PyObject *kwargs) -{ - PyObject *mod = NULL, *mod_iter = NULL, *mod_item = NULL; - EXTRACTOR_ExtractorList *elist = NULL, *ecur = NULL; - char *kwargs_list[] = {"modules",NULL}; - int rv = 0; - - if( !PyArg_ParseTupleAndKeywords(args,kwargs,"|O:__init__",kwargs_list, - &mod) ) - goto error; - - if( !mod || mod == Py_None || PyString_Check(mod) ) { - if( !mod || mod == Py_None ) - elist = EXTRACTOR_loadDefaultLibraries(); - else - elist = EXTRACTOR_loadConfigLibraries(NULL,PyString_AsString(mod)); - - ecur = elist; - while( ecur ) { - if( !( mod_item = (PyObject*)PyObject_GC_New(Module,&ModuleType) ) ) - goto error; - - elist = ecur; - ecur = elist->next; - elist->next = NULL; - - ((Module*)mod_item)->module = elist; - ((Module*)mod_item)->mlist = NULL; - - if( !ModuleList_append(self,(Module*)mod_item) ) - goto error; - Py_DECREF(mod_item); - mod_item = NULL; - } - } else if( PyObject_IsInstance(mod,(PyObject*)&ModuleType) ) { - if( !ModuleList_append(self,(Module*)mod) ) - goto error; - } else { - if( !( mod_iter = PyObject_GetIter(mod) ) ) - goto error; - - while( ( mod_item = PyIter_Next(mod_iter) ) ) { - if( !ModuleList_append(self,(Module*)mod_item) ) - goto error; - Py_DECREF(mod_item); - mod_item = NULL; - } - } - - goto finish; - - error: - EXTRACTOR_removeAll(ecur); - Py_XDECREF(mod_item); - rv = -1; - - finish: - Py_XDECREF(mod_iter); - return rv; -} - -static PyObject *ModuleList_repr(ModuleList *self) -{ - return PyString_FromFormat("<ModuleList: %i modules>", - PyList_GET_SIZE(self->mlist)); -} - -static int ModuleList_traverse(ModuleList *self, visitproc visit, void *arg) -{ -#ifdef Py_VISIT - Py_VISIT(self->mlist); -#endif - return 0; -} - -static int ModuleList_clear(ModuleList *self) -{ -#ifdef Py_CLEAR - Py_CLEAR(self->mlist); -#endif - return 0; -} - -static void ModuleList_dealloc(ModuleList *self) -{ - ModuleList_clear(self); - self->ob_type->tp_free((PyObject*)self); -} - -static PyMethodDef ModuleList_methods[] = { - {"prepend",(PyCFunction)ModuleList_prepend,METH_O, - "Prepend a single module to the structure."}, - {"append",(PyCFunction)ModuleList_append,METH_O, - "Append a single module to the structure."}, - {NULL} /* Sentinel */ -}; - -static PyTypeObject ModuleListType = { - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ - "extractor.ModuleList", /*tp_name*/ - sizeof(ModuleList), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)ModuleList_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - (reprfunc)ModuleList_repr, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "ModuleList objects", /* tp_doc */ - (traverseproc)ModuleList_traverse, /* tp_traverse */ - (inquiry)ModuleList_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - ModuleList_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ModuleList_init, /* tp_init */ - 0, /* tp_alloc */ - ModuleList_new, /* tp_new */ -}; - -/* Module type. */ - -static EXTRACTOR_KeywordList *Module_extractMethod(const char *filename, - char *data, size_t filesize, - EXTRACTOR_KeywordList *next, - const char *options) -{ - Module *self = NULL; - - self = (Module*)atoi(options); /* convert back from string repr of self. */ - - printf("In the extractor with object %i.",(int)self); - return next; -} - -static PyObject *Module_new(PyTypeObject *type, PyObject *args, - PyObject *kwargs) -{ - Module *self = NULL; - char *name = NULL, *options = NULL; - char *kwargs_list[] = {"name","options",NULL}; - int namelen = 0, i; - - if( !PyArg_ParseTupleAndKeywords(args,kwargs,"s#|z:__new__",kwargs_list, - &name,&namelen,&options) ) - goto error; - - i = 0; - while( name[i] ) - if( name[i++] == '(' ) { - PyErr_SetString(PyExc_ValueError,"name may not contain (."); - goto error; - } - - if( !( self = (Module*)type->tp_alloc(type,0) ) ) - goto error; - - /* Somewhat a HACK, creates a module structure from scratch. */ - self->module = malloc(sizeof(EXTRACTOR_ExtractorList)); - self->module->libraryHandle = NULL; - self->module->extractMethod = (ExtractMethod)&Module_extractMethod; - self->module->libname = strdup(name); - self->module->options = malloc(12); /* store self as string in options. */ - sprintf(self->module->options,"%i",(int)self); - self->module->next = NULL; - - goto finish; - - error: - Py_XDECREF(self); - self = NULL; - - finish: - return (PyObject*)self; -} - -static int Module_init(Module *self, PyObject *args, PyObject *kwargs) -{ - char *name = NULL, *options = NULL, *optstring = NULL; - char *kwargs_list[] = {"name","options",NULL}; - int namelen = 0, optionslen = 0, i, rv = 0; - - if( !PyArg_ParseTupleAndKeywords(args,kwargs,"s#|z#:__init__",kwargs_list, - &name,&namelen,&options,&optionslen) ) - goto error; - - i = 0; - while( options && options[i] ) - if( options[i++] == ')' ) { - PyErr_SetString(PyExc_ValueError,"option may not contain )."); - goto error; - } - - EXTRACTOR_removeAll(self->module); /* slight crutch, was allocated in */ - self->module = NULL; /* __new__, so that programmer can create subtype. */ - - optstring = malloc(namelen+optionslen+3); - if( options ) - sprintf(optstring,"%s(%s)",name,options); - else - sprintf(optstring,"%s",name); - if( !( self->module = EXTRACTOR_loadConfigLibraries(NULL,optstring) ) ) { - PyErr_SetString(PyExc_ValueError,"could not load module."); - goto error; - } - - goto finish; - - error: - rv = -1; - - finish: - if( optstring ) - free(optstring); - return rv; -} - -static PyObject *Module_getattr(Module *self, char *name) -{ - if( !strcmp(name,"libname") ) - return PyString_FromString(self->module->libname); - else if( !strcmp(name,"options") ) - return PyString_FromString(self->module->options); - else if( !strcmp(name,"mlist") ) - return (PyObject*)self->mlist; - PyErr_SetString(PyExc_AttributeError,name); - return NULL; -} - -static int Module_setattr(Module *self, char *name, PyObject *value) -{ - if( !strcmp(name,"libname") || !strcmp(name,"options") || - !strcmp(name,"mlist") ) - PyErr_Format(PyExc_AttributeError,"cannot set %s.",name); - else - PyErr_SetString(PyExc_AttributeError,name); - return -1; -} - -static PyObject *Module_repr(Module *self) -{ - if( self->module->options ) - return PyString_FromFormat("%s(\"%s\",\"%s\")",self->ob_type->tp_name, - self->module->libname,self->module->options); - else - return PyString_FromFormat("%s(\"%s\")",self->ob_type->tp_name, - self->module->libname); -} - -static long Module_hash(Module *self) -{ - return (int)self->module; -} - -static int Module_traverse(Module *self, visitproc visit, void *arg) -{ -#ifdef Py_VISIT - Py_VISIT((PyObject*)self->mlist); -#endif - return 0; -} - -static int Module_clear(Module *self) -{ - printf("Removing module in clear: %s.\n",self->module->libname); -#ifdef Py_CLEAR - Py_CLEAR(self->mlist); -#endif - return 0; -} - -static void Module_dealloc(Module *self) -{ - Module_clear(self); - printf("Removing module: %s.\n",self->module->libname); - self->module->next = NULL; - EXTRACTOR_removeAll(self->module); - self->ob_type->tp_free((PyObject*)self); -} - -static PyMethodDef Module_methods[] = { - {NULL} /* Sentinel */ -}; - -static PyTypeObject ModuleType = { - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ - "extractor.Module", /*tp_name*/ - sizeof(Module), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)Module_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - (getattrfunc)Module_getattr, /*tp_getattr*/ - (setattrfunc)Module_setattr, /*tp_setattr*/ - 0, /*tp_compare*/ - (reprfunc)Module_repr, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - (hashfunc)Module_hash, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "Module objects", /* tp_doc */ - (traverseproc)Module_traverse, /* tp_traverse */ - (inquiry)Module_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - Module_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Module_init, /* tp_init */ - 0, /* tp_alloc */ - Module_new, /* tp_new */ -}; - -/* Module level. */ - -static PyMethodDef Extractor_Module_methods[] = { - {NULL} /* Sentinel */ -}; - -PyMODINIT_FUNC initextractor(void) -{ - PyObject *m; - - if( PyType_Ready(&ModuleListType) ) - return; - if( PyType_Ready(&ModuleType) ) - return; - - m = Py_InitModule3("extractor",Extractor_Module_methods,"Extractor module."); - if (m == NULL) - return; - - Py_INCREF(&ModuleListType); - Py_INCREF(&ModuleType); - PyModule_AddObject(m,"ModuleList",(PyObject*)&ModuleListType); - PyModule_AddObject(m,"Module",(PyObject*)&ModuleType); -} diff --git a/src/main/libextractor_python_setup.py b/src/main/libextractor_python_setup.py @@ -1,17 +0,0 @@ -from distutils.core import Extension, setup -import sys - -path=sys.argv[0] -sys.argv = sys.argv[1:] - -cmod = Extension("extractor",["libextractor_python.c"], - libraries=["extractor"], - include_dirs=["../include"], - library_dirs=[path]) - -setup(name="Extractor", - version="0.5.0", - ext_modules=[cmod], - author="Christian Grothoff, Heiko Wundram", - author_email="libextractor@gnu.org") - diff --git a/src/main/org_gnunet_libextractor_Extractor.h b/src/main/org_gnunet_libextractor_Extractor.h @@ -1,109 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include <jni.h> -/* Header for class org_gnunet_libextractor_Extractor */ - -#ifndef _Included_org_gnunet_libextractor_Extractor -#define _Included_org_gnunet_libextractor_Extractor -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: org_gnunet_libextractor_Extractor - * Method: loadDefaultInternal - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_org_gnunet_libextractor_Extractor_loadDefaultInternal - (JNIEnv *, jclass); - -/* - * Class: org_gnunet_libextractor_Extractor - * Method: unloadInternal - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_org_gnunet_libextractor_Extractor_unloadInternal - (JNIEnv *, jclass, jlong); - -/* - * Class: org_gnunet_libextractor_Extractor - * Method: extractInternal - * Signature: (JLjava/lang/String;)J - */ -JNIEXPORT jlong JNICALL Java_org_gnunet_libextractor_Extractor_extractInternal - (JNIEnv *, jclass, jlong, jstring); - -/* - * Class: org_gnunet_libextractor_Extractor - * Method: freeInternal - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_org_gnunet_libextractor_Extractor_freeInternal - (JNIEnv *, jclass, jlong); - -/* - * Class: org_gnunet_libextractor_Extractor - * Method: typeInternal - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_org_gnunet_libextractor_Extractor_typeInternal - (JNIEnv *, jclass, jlong); - -/* - * Class: org_gnunet_libextractor_Extractor - * Method: keywordInternal - * Signature: (J)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_gnunet_libextractor_Extractor_keywordInternal - (JNIEnv *, jclass, jlong); - -/* - * Class: org_gnunet_libextractor_Extractor - * Method: nextInternal - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL Java_org_gnunet_libextractor_Extractor_nextInternal - (JNIEnv *, jclass, jlong); - -/* - * Class: org_gnunet_libextractor_Extractor - * Method: getTypeAsStringInternal - * Signature: (I)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_gnunet_libextractor_Extractor_getTypeAsStringInternal - (JNIEnv *, jclass, jint); - -/* - * Class: org_gnunet_libextractor_Extractor - * Method: getVersionInternal - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_org_gnunet_libextractor_Extractor_getVersionInternal - (JNIEnv *, jclass); - -/* - * Class: org_gnunet_libextractor_Extractor - * Method: getMaxTypeInternal - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_org_gnunet_libextractor_Extractor_getMaxTypeInternal - (JNIEnv *, jclass); - -/* - * Class: org_gnunet_libextractor_Extractor - * Method: unloadPlugin - * Signature: (JLjava/lang/String;)J - */ -JNIEXPORT jlong JNICALL Java_org_gnunet_libextractor_Extractor_unloadPlugin - (JNIEnv *, jclass, jlong, jstring); - -/* - * Class: org_gnunet_libextractor_Extractor - * Method: loadPlugin - * Signature: (JLjava/lang/String;Z)J - */ -JNIEXPORT jlong JNICALL Java_org_gnunet_libextractor_Extractor_loadPlugin - (JNIEnv *, jclass, jlong, jstring, jboolean); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/org/gnunet/libextractor/.cvsignore b/src/org/gnunet/libextractor/.cvsignore @@ -1 +0,0 @@ -*.class diff --git a/src/org/gnunet/libextractor/Extractor.java b/src/org/gnunet/libextractor/Extractor.java @@ -1,289 +0,0 @@ -/* - This file is part of libextractor. - (C) 2002, 2003, 2004 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. - */ -package org.gnunet.libextractor; - -import java.util.Vector; -import java.io.File; - -/** - * Java Binding for libextractor. - * - * @see Xtract - * @author Christian Grothoff - */ -public final class Extractor { - - private static boolean warn_; - - /** - * LE version. 0 if LE was compiled without JNI/Java support, in which - * case we better not call any native methods... - */ - private final static int version_; - - /** - * Cached list of Strings describing keyword types. - */ - private final static String[] typeCache_; - - static { - // first, initialize warn_ - boolean warn = false; - try { - if (System.getProperty("libextractor.warn") != null) - warn = true; - } catch (SecurityException se) { - // ignore - } finally { - warn_ = warn; - } - - // next, load library and determine version_ - int ver = 0; - try { - System.loadLibrary("extractor"); - } catch (UnsatisfiedLinkError ule) { - ver = -1; - warn("Did not find libextractor library: " + ule); - } - if (ver == 0) { - try { - ver = getVersionInternal(); - } catch (UnsatisfiedLinkError ule) { - // warn: libextractor compiled without Java support - warn("libextractor library compiled without Java support: " + ule); - } - } - version_ = ver; - - // finally, initialize typeCache_ - if (ver > 0) { - typeCache_ = new String[getMaxTypeInternal()]; - } else { - typeCache_ = null; - } - } - - private static void warn(String warning) { - if (warn_) - System.err.println("WARNING: " + warning); - } - - /** - * @return -1 if LE library was not found, 0 if LE library - * was found but compiled without JNI support, otherwise - * the LE version number - */ - public static int getVersion() { - return version_; - } - - /** - * Get the 'default' extractor, that is an extractor that loads - * the default set of extractor plugins. - */ - public static Extractor getDefault() { - if (version_ > 0) - return new Extractor(loadDefaultInternal()); - else - return new Extractor(0); - } - - /** - * Get the 'empty' extractor, that is an extractor that does not - * have any plugins loaded. This is useful to manually construct - * an Extractor from scratch. - */ - public static Extractor getEmpty() { - return new Extractor(0L); - } - - /** - * Note that the current implementation of function is quite - * costly, we should probably build a cache (String[]) of all - * keyword types on startup and keep that around instead of - * doing a native call each time (initialize cache lazily!, - * just determine the size in the static initializer!). - * - * @throws IllegalArgumentException if the type is not within range - * @return an empty string if LE was not loaded - */ - public static String getTypeAsString(int type) { - if (version_ > 0) { - if ( (type >= 0) && (type <= typeCache_.length)) { - if (typeCache_[type] == null) - typeCache_[type] - = getTypeAsStringInternal(type); - return typeCache_[type]; - } else - throw new IllegalArgumentException("Type out of range [0,"+typeCache_.length+")"); - } else - return ""; - } - - /** - * Handle to the list of plugins (a C pointer, long to support - * 64-bit architectures!). - */ - private long pluginHandle_; - - /** - * Creates an extractor. - * - * @param pluginHandle the internal handle (C pointer!) refering - * to the list of plugins. 0 means no plugins. - */ - private Extractor(long pluginHandle) { - this.pluginHandle_ = pluginHandle; - } - - protected void finalize() { - if (pluginHandle_ != 0) - unloadInternal(pluginHandle_); - } - - public void unloadPlugin(String pluginName) { - if (pluginHandle_ != 0) { - pluginHandle_ = unloadPlugin(pluginHandle_, - pluginName); - } - } - - /** - * @param append if true, add the plugin at the end, otherwise at the - * beginning - */ - public void loadPlugin(String pluginName, - boolean append) { - if (version_ <= 0) - return; - pluginHandle_ = loadPlugin(pluginHandle_, - pluginName, - append); - } - - /** - * Extract keywords (meta-data) from the given file. - * - * @param f the file to extract meta-data from - * @return a Vector of Extractor.Keywords - */ - public Vector extract(File f) { - return extract(f.getName()); - } - - /** - * Extract keywords (meta-data) from the given file. - * - * @param file the name of the file - * @return a Vector of Extractor.Keywords - */ - public Vector extract(String filename) { - if (pluginHandle_ == 0) - return new Vector(0); // fast way out - long list - = extractInternal(pluginHandle_, - filename); // toChars? - long pos - = list; - Vector res - = new Vector(); - while (pos != 0) { - int type - = typeInternal(pos); - String keyword - = keywordInternal(pos); - res.add(new Keyword(type, keyword)); - pos = nextInternal(pos); - } - freeInternal(list); - return res; - } - - - /* ********************* native calls ******************** */ - - private static native long loadDefaultInternal(); - - private static native void unloadInternal(long handle); - - private static native long extractInternal(long handle, - String filename); - - // free memory allocated by extractInternal - private static native void freeInternal(long list); - - private static native int typeInternal(long pos); - - private static native String keywordInternal(long pos); - - private static native long nextInternal(long pos); - - private static native String getTypeAsStringInternal(int type); - - private static native int getVersionInternal(); - - private static native int getMaxTypeInternal(); - - private static native long unloadPlugin(long handle, - String pluginName); - - /** - * @param append if true, add the plugin at the end, otherwise at the - * beginning - */ - private static native long loadPlugin(long handle, - String pluginName, - boolean append); - - /** - * Representation of a keyword. Each keyword in libextractor - * has a type (in Java modeled as an int) which describes what - * the keyword is about. - * - * @author Christian Grothoff - */ - public static final class Keyword { - - private final int type_; - - private final String keyword_; - - Keyword(int type, - String key) { - this.type_ = type; - this.keyword_ = key; - } - - public String toString() { - return getTypeAsString(type_) + ": " + keyword_; - } - - public int getType() { - return type_; - } - - public String getKeyword() { - return keyword_; - } - - } // end of Extractor.Keyword - -} // end of Extractor -\ No newline at end of file diff --git a/src/org/gnunet/libextractor/Xtract.java b/src/org/gnunet/libextractor/Xtract.java @@ -1,44 +0,0 @@ -/* - This file is part of libextractor. - (C) 2002, 2003, 2004 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. - */ -package org.gnunet.libextractor; - -import java.util.Vector; - -/** - * Java version of extract. This is just a tiny demo-application - * to show how to use the Java API. The C version of extract is - * much better and should probably be used in practice. - * - * @author Christian Grothoff - */ -public final class Xtract { - - public static void main(String[] args) { - Extractor ex = Extractor.getDefault(); - for (int i=0;i<args.length;i++) { - Vector keywords = ex.extract(args[i]); - System.out.println("Keywords for " + args[i] + ":\n"); - for (int j=0;j<keywords.size();j++) - System.out.println(keywords.elementAt(j)); - } - // no need to unload, finalizer does the rest... - } - -} // end of Xtract -\ No newline at end of file