diff --git a/C/fli_absmi_insts.h b/C/fli_absmi_insts.h index abbf83629..948066a8a 100644 --- a/C/fli_absmi_insts.h +++ b/C/fli_absmi_insts.h @@ -10,7 +10,7 @@ #endif /* INDENT_CODE */ BOp(call_cpred, Osbpp); -#if __ANDROID__ +#if __ANDROID__ && STRONG_DEBUG char *s; Atom name; if (PREG->y_u.Osbpp.p->ArityOfPE) { Functor f = PREG->y_u.Osbpp.p->FunctorOfPred; diff --git a/C/init.c b/C/init.c index 6fb511dbc..4bd867efc 100755 --- a/C/init.c +++ b/C/init.c @@ -1125,12 +1125,21 @@ InitAtoms(void) HashChain[i].Entry = NIL; } NOfAtoms = 0; +#if OLD_STYLE_INITIAL_ATOMS Yap_LookupAtomWithAddress("**",(AtomEntry *)&(SF_STORE->AtFoundVar)); Yap_ReleaseAtom(AtomFoundVar); Yap_LookupAtomWithAddress("?",(AtomEntry *)&(SF_STORE->AtFreeTerm)); Yap_ReleaseAtom(AtomFreeTerm); Yap_LookupAtomWithAddress("[]",(AtomEntry *)&(SF_STORE->AtNil)); Yap_LookupAtomWithAddress(".",(AtomEntry *)&(SF_STORE->AtDot)); +#else + SF_STORE->AtFoundVar = Yap_LookupAtom("**"); + Yap_ReleaseAtom(AtomFoundVar); + SF_STORE->AtFreeTerm = Yap_LookupAtom("?"); + Yap_ReleaseAtom(AtomFreeTerm); + SF_STORE->AtNil = Yap_LookupAtom("[]"); + SF_STORE->AtDot = Yap_LookupAtom("."); +#endif } static void diff --git a/C/pl-yap.c b/C/pl-yap.c index e6e0e5621..40aff9d92 100755 --- a/C/pl-yap.c +++ b/C/pl-yap.c @@ -931,11 +931,16 @@ Yap_HandleToString(term_t l, size_t sz, size_t *length, int *encoding, int flags char *buf; + size_t size = 4096, total = size; IOSTREAM *fd; total = size; buf = malloc(total); +#ifdef DEBUG + {CACHE_REGS + __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text %p \n", buf);} +#endif while ( (fd = Sopenmem(&buf, &size, "w")) == NULL || (( fd->encoding = ENC_UTF8) && FALSE) || (PL_write_term(fd, l, 1200, flags) == 0) || @@ -944,7 +949,7 @@ Yap_HandleToString(term_t l, size_t sz, size_t *length, int *encoding, int flags { #ifdef DEBUG {CACHE_REGS - __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text %p, %x buf=%s\n", fd, LOCAL_SlotBase[28], buf);} + __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "fd %p, %x buf=%s\n", fd, LOCAL_SlotBase[28], buf);} #endif Sclose(fd); if (!fd) diff --git a/C/sysbits.c b/C/sysbits.c index fd1443da5..7e6c7cf96 100644 --- a/C/sysbits.c +++ b/C/sysbits.c @@ -2721,7 +2721,7 @@ p_yap_paths( USES_REGS1 ) { out2 = MkAtomTerm(Yap_LookupAtom(destdir)); } else { #if __ANDROID__ - out2 = MkAtomTerm(Yap_LookupAtom("/assets/share")); + out2 = MkAtomTerm(Yap_LookupAtom("/assets/share/Yap")); #else out2 = MkAtomTerm(Yap_LookupAtom(YAP_SHAREDIR)); #endif diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp index 90cc1b055..f438b72ae 100644 --- a/CXX/yapi.cpp +++ b/CXX/yapi.cpp @@ -196,7 +196,7 @@ YAP_tag_t YAPTerm::tag() { return YAP_TAG_ATOM; return YAP_TAG_INT; } else { - Functor f = FunctorOfTerm(tt); + Functor f = FunctorOfTerm(tt); if (IsExtensionFunctor(f)) { if (f == FunctorDBRef) { @@ -288,18 +288,10 @@ const char *YAPTerm::text() { int enc; BACKUP_MACHINE_REGS(); -#ifdef DEBUG - {CACHE_REGS - __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text %d, %x \n", t, LOCAL_SlotBase[t]);} -#endif if (!(os = Yap_HandleToString(t, sze, &length, &enc, 0))) { RECOVER_MACHINE_REGS(); return (char *)NULL; } -#ifdef DEBUG - {CACHE_REGS - __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text %d, %x %p\n", t, LOCAL_SlotBase[t], os);} -#endif RECOVER_MACHINE_REGS(); return os; } @@ -315,16 +307,11 @@ char *YAPQuery::text() { RECOVER_MACHINE_REGS(); return (char *)NULL; } - { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "II ") ; } + { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "II %s", os) ; } RECOVER_MACHINE_REGS(); return os; } -bool YAPListTerm::nil() { - CACHE_REGS - return gt() == TermNil; -} - YAPIntegerTerm::YAPIntegerTerm(intptr_t i) { CACHE_REGS Term tn = MkIntegerTerm( i ); mk( tn ); } @@ -348,14 +335,14 @@ YAPTerm::YAPTerm(intptr_t i) { CACHE_REGS Term tn = MkIntegerTerm( i ); mk( tn ) YAPTerm YAPListTerm::car() { Term to = gt(); - { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "to=%d", to) ; } + { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "to=%p", to) ; } if (IsPairTerm(to)) return YAPTerm(HeadOfTerm(to)); else - return MkIntTerm(-1); + throw YAPError::YAP_DOMAIN_ERROR; } - YAPVarTerm::YAPVarTerm() { CACHE_REGS mk( MkVarTerm( ) ); } +YAPVarTerm::YAPVarTerm() { CACHE_REGS mk( MkVarTerm( ) ); } char *YAPAtom::getName(void) { diff --git a/CXX/yapt.hh b/CXX/yapt.hh index 223ea67d6..eeb92e7aa 100644 --- a/CXX/yapt.hh +++ b/CXX/yapt.hh @@ -121,10 +121,20 @@ public: YAPAtomTerm(wchar_t *s) ; // Constructor: receives a sequence of n wchar_ts, whatever they may be; YAPAtomTerm(wchar_t *s, size_t len); + virtual bool isVar() { return false; } /// type check for unbound + virtual bool isAtom() { return true; } /// type check for atom + virtual bool isInteger() { return false; } /// type check for integer + virtual bool isFloat() { return false; } /// type check for floating-point + virtual bool isString() { return false; } /// type check for a string " ... " + virtual bool isCompound() { return false; } /// is a primitive term + virtual bool isAppl() { return false; } /// is a structured term + virtual bool isPair() { return false; } /// is a pair term + virtual bool isGround() { return true; } /// term is ground + virtual bool isList() { return gt() == TermNil; } /// [] is a list // Getter: outputs the atom; YAPAtom getAtom() { return YAPAtom(AtomOfTerm( gt() )); } // Getter: outputs the name as a sequence of ISO-LATIN1 codes; - const char *getName() { return AtomOfTerm( gt() )->StrOfAE; } + const char *text() { return AtomOfTerm( gt() )->StrOfAE; } }; /** @@ -139,6 +149,16 @@ public: YAPApplTerm(YAPFunctor f); YAPFunctor getFunctor(); YAPTerm getArg(int i); + virtual bool isVar() { return false; } /// type check for unbound + virtual bool isAtom() { return false; } /// type check for atom + virtual bool isInteger() { return false; } /// type check for integer + virtual bool isFloat() { return false; } /// type check for floating-point + virtual bool isString() { return false; } /// type check for a string " ... " + virtual bool isCompound() { return true; } /// is a primitive term + virtual bool isAppl() { return true; } /// is a structured term + virtual bool isPair() { return false; } /// is a pair term + virtual bool isGround() { return true; } /// term is ground + virtual bool isList() { return false; } /// [] is a list }; /** @@ -158,14 +178,14 @@ public: * @brief Integer Term */ -class YAPIntegerTerm: private YAPTerm { +class YAPIntegerTerm: YAPTerm { public: YAPIntegerTerm(intptr_t i); intptr_t getInteger() { return IntegerOfTerm( gt() ); } bool isTagged() { return IsIntTerm( gt() ); } }; -class YAPListTerm: private YAPTerm { +class YAPListTerm: public YAPTerm { public: /// Create a list term out of a standard term. Check if a valid operation. /// @@ -204,7 +224,13 @@ public: /// Check if the list is empty. /// /// @param[in] the list - bool nil(); + inline bool nil() { + CACHE_REGS + { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "II %x %x", gt(), TermNil) ; } + return gt() == TermNil; + } + +; }; /** diff --git a/H/TermExt.h b/H/TermExt.h index 6c37edfd0..cda5a0873 100755 --- a/H/TermExt.h +++ b/H/TermExt.h @@ -32,16 +32,21 @@ language. Next, we discuss support to the most important ones. #define SF_STORE ((special_functors *)HEAP_INIT_BASE) #endif -#ifdef USE_OFFSETS +#if defined(USE_OFFSETS) #define AtomFoundVar ((Atom)(&(((special_functors *)(NULL))->AtFoundVar))) #define AtomFreeTerm ((Atom)(&(((special_functors *)(NULL))->AtFreeTerm))) #define AtomNil ((Atom)(&(((special_functors *)(NULL))->AtNil))) #define AtomDot ((Atom)(&(((special_functors *)(NULL))->AtDot))) -#else +#elif OLD_STYLE_INITIAL_ATOMS #define AtomFoundVar AbsAtom((AtomEntry *)&(SF_STORE->AtFoundVar)) #define AtomFreeTerm AbsAtom((AtomEntry *)&(SF_STORE->AtFreeTerm)) #define AtomNil AbsAtom((AtomEntry *)&(SF_STORE->AtNil)) #define AtomDot AbsAtom((AtomEntry *)&(SF_STORE->AtDot)) +#else +#define AtomFoundVar AbsAtom(SF_STORE->AtFoundVar) +#define AtomFreeTerm AbsAtom(SF_STORE->AtFreeTerm) +#define AtomNil AbsAtom(SF_STORE->AtNil) +#define AtomDot AbsAtom(SF_STORE->AtDot) #endif #define TermFoundVar MkAtomTerm(AtomFoundVar) @@ -164,10 +169,18 @@ exts; in the heap when we start the system */ typedef struct special_functors_struct { + +#if 0 struct ExtraAtomEntryStruct AtFoundVar; struct ExtraAtomEntryStruct AtFreeTerm; struct ExtraAtomEntryStruct AtNil; struct ExtraAtomEntryStruct AtDot; +#else + struct AtomEntryStruct *AtFoundVar; + struct AtomEntryStruct *AtFreeTerm; + struct AtomEntryStruct *AtNil; + struct AtomEntryStruct *AtDot; +#endif } special_functors; #endif /* YAP_H */ diff --git a/Makefile.in b/Makefile.in index 692c737d7..0039d29fe 100755 --- a/Makefile.in +++ b/Makefile.in @@ -625,9 +625,12 @@ libYap.a: $(LIB_OBJECTS) yapi.o adb shell mkdir -p /data/yap adb shell mkdir -p /data/yap/pl adb shell mkdir -p /data/yap/swi/library - adb shell mkdir -p /data/yap/packages adb shell mkdir -p /data/yap/packages/chr adb shell mkdir -p /data/yap/packages/clib + adb shell mkdir -p /data/yap/packages/myddas + adb shell mkdir -p /data/yap/assets/myddas + adb shell mkdir -p /data/yap/assets/lib + adb shell mkdir -p /data/yap/assets/share adb push yap /data/yap/ adb push @DYNYAPLIB@ /data/yap/ for p in $(EXTRAYAPLIBS); do \ @@ -639,6 +642,9 @@ libYap.a: $(LIB_OBJECTS) yapi.o adb push $(srcdir)/swi/library /data/yap/swi/library adb push $(srcdir)/pl /data/yap/pl/ adb push $(srcdir)/library /data/yap/library/ + adb push $(srcdir)/packages/myddas /data/yap/packages/myddas/ + adb push $(srcdir)/packages/chr /data/yap/packages/chr/ + adb push $(srcdir)/packages/clib /data/yap/packages/clib/ adb shell "echo \"bootstrap('/data/yap/pl/init.yap'). module(user). qsave_program('/data/yap/startup.yss').\" | LD_LIBRARY_PATH=/data/yap /data/yap/yap@EXEC_SUFFIX@ -b /data/yap/pl/boot.yap" adb pull /data/yap/startup.yss #adb shell rm -rf /data/yap diff --git a/library/lineutils.yap b/library/lineutils.yap index 0a157cdd1..4cf4fc937 100644 --- a/library/lineutils.yap +++ b/library/lineutils.yap @@ -15,6 +15,7 @@ copy_line/2, filter/3, file_filter/3, + file_select/2, file_filter_with_initialization/5, process/2 ]). @@ -297,15 +298,22 @@ process(StreamInp, Command) :- fail ). +/** + * @pred file_filter(+ _FileIn_, + _FileOut_, + _Goal_) is meta + * + * @param _FileIn_ File to process + * @param _FileOut_ Output file, often user_error + * @param _Goal_ to be metacalled, receives FileIn and FileOut as + * extra arguments + * + * @return succeeds -/** @pred file_filter(+ _FileIn_, + _FileOut_, + _Goal_) is meta + For every line _LineIn_ in file _FileIn_, execute + `call(Goal,LineIn,LineOut)`, and output _LineOut_ to file + _FileOut_. -For every line _LineIn_ in file _FileIn_, execute -`call(Goal,LineIn,LineOut)`, and output _LineOut_ to file - _FileOut_. - - The input stream is accessible through the alias `filter_input`, and the output - stream is accessible through `filter_output`. + The input stream is accessible through the alias `filter_input`, and + the output stream is accessible through `filter_output`. */ file_filter(Inp, Out, Command) :- open(Inp, read, StreamInp, [alias(filter_input)]), @@ -327,6 +335,37 @@ file_filter_with_initialization(Inp, Out, Command, FormatString, Parameters) :- filter(StreamInp, StreamOut, Command), close(StreamInp), close(StreamOut). + + +/** + * @pred file_select(+ _FileIn_, + _Goal_) is meta + * + * @param _FileIn_ File to process + * @param _Goal_ to be metacalled, receives FileIn as + * extra arguments + * + * @return bindings to arguments of _Goal_. + + For every line _LineIn_ in file _FileIn_, execute + `call(`Goal,LineIn)`. + + The input stream is accessible through the alias `filter_input`, and + the output stream is accessible through `filter_output`. +*/ +file_select(Inp, Command) :- + open(Inp, read, StreamInp, [alias(filter_input)]), + repeat, + read_line_to_codes(StreamInp, Line), + ( + Line == end_of_file + -> + close(StreamInp), + !, + fail + ; + call(Command, Line) + ). + /** @} */ diff --git a/os/pl-os.c b/os/pl-os.c index eba8df666..9a7a09e20 100755 --- a/os/pl-os.c +++ b/os/pl-os.c @@ -1550,7 +1550,7 @@ to be implemented directly. What about other Unixes? #endif #if __ANDROID__ - if (LOCAL_InAssetDir) { + if (LOCAL_InAssetDir ) { rval = strncpy(buf, LOCAL_InAssetDir, sizeof(buf)); } else #endif @@ -1676,7 +1676,7 @@ ChDir(const char *path) size_t sz = strlen(ospath)+1; AAssetDir_close(dir); LOCAL_InAssetDir = (char *)malloc(sz); - strncpy(LOCAL_InAssetDir, ospath, sz-1); + strncpy(LOCAL_InAssetDir, ospath, sz); succeed; } else { fail; diff --git a/packages/raptor b/packages/raptor index 36f99e3c3..b36fdac22 160000 --- a/packages/raptor +++ b/packages/raptor @@ -1 +1 @@ -Subproject commit 36f99e3c3c978fef25f899dc4fab1ffee334d73c +Subproject commit b36fdac2281b7eef141095375d81456410dbcd2f diff --git a/packages/swig/android/JavaYap.java b/packages/swig/android/JavaYap.java index 4f34539c7..09e4f32af 100644 --- a/packages/swig/android/JavaYap.java +++ b/packages/swig/android/JavaYap.java @@ -1,27 +1,27 @@ package pt.up.fc.dcc.yap; /**** using sqlite - For example,the following: +For example,the following: - import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase; - should be replaced with: +should be replaced with: - import org.sqlite.database.sqlite.SQLiteDatabase; +import org.sqlite.database.sqlite.SQLiteDatabase; - As well as replacing all uses of the classes in the android.database.sqlite.* namespace, the application must also be sure to use the following two: +As well as replacing all uses of the classes in the android.database.sqlite.* namespace, the application must also be sure to use the following two: - org.sqlite.database.SQLException - org.sqlite.database.DatabaseErrorHandler +org.sqlite.database.SQLException +org.sqlite.database.DatabaseErrorHandler - instead of: +instead of: - android.database.SQLException - android.database.DatabaseErrorHandler +android.database.SQLException +android.database.DatabaseErrorHandler - Aside from namespace changes, there are other differences from the stock Android interface that applications need to be aware of: +Aside from namespace changes, there are other differences from the stock Android interface that applications need to be aware of: - The SQLiteStatement.simpleQueryForBlobFileDescriptor() API is not available. The collation sequence "UNICODE" is not available. The collation sequence "LOCALIZED", which normally changes with the system's current locale, is always equivalent to SQLite's built in collation BINARY. +The SQLiteStatement.simpleQueryForBlobFileDescriptor() API is not available. The collation sequence "UNICODE" is not available. The collation sequence "LOCALIZED", which normally changes with the system's current locale, is always equivalent to SQLite's built in collation BINARY. ****/ @@ -33,7 +33,7 @@ import android.widget.ScrollView; import android.text.method.ScrollingMovementMethod; import android.content.pm.PackageManager; import android.content.pm.PackageInfo; -import android.content.pm.PackageManager.NameNotFoundException; +import android.content.pm.PackageManager.NameNotFoundException; import android.util.Log; import android.content.res.AssetManager; import android.widget.EditText; @@ -46,212 +46,224 @@ import org.sqlite.database.sqlite.SQLiteOpenHelper; import org.sqlite.database.SQLException; import org.sqlite.database.DatabaseErrorHandler; class DoNotDeleteErrorHandler implements DatabaseErrorHandler { - private static final String TAG = "DoNotDeleteErrorHandler"; - public void onCorruption(SQLiteDatabase dbObj) { - Log.e(TAG, "Corruption reported by sqlite on database: " + dbObj.getPath()); - } + private static final String TAG = "DoNotDeleteErrorHandler"; + public void onCorruption(SQLiteDatabase dbObj) { + Log.e(TAG, "Corruption reported by sqlite on database: " + dbObj.getPath()); + } } public class JavaYap extends Activity { - TextView outputText = null; - ScrollView scroller = null; - YAPEngine eng = null; - EditText text; - String str; - String buf; + TextView outputText = null; + ScrollView scroller = null; + YAPEngine eng = null; + EditText text; + String str; + String buf; + YAPQuery q; + Boolean running = false; + int i=1; + YAPListTerm vs0; - void runQuery(String str) - { - try - { - YAPQuery q = eng.query( str ); + void runQuery(String str, Boolean more) + { + try + { + // check if at initial query + if (!running) { + q = eng.query( str ); + // get the uninstantiated query variables. + vs0 = q.namedVars(); + running = true; + } + // start computing + Boolean compute = true; - if (BuildConfig.DEBUG) { - Log.i(TAG, "onQueryButtonClick called"); - } - YAPListTerm vs0 = q.namedVars(); - Boolean rc; + if (BuildConfig.DEBUG) { + Log.i(TAG, "onQueryButtonClick called"); + } - // text.setText(""); - if (vs0.nil()) { - if (BuildConfig.DEBUG) { - Log.i(TAG, "q0=\n"); - } - if (q.next()) { - outputText.append( "yes\n" ); - } else { - outputText.append( "no\n" ); - } - } else { - int i=1; - if (BuildConfig.DEBUG) { - //Log.i(TAG, "q1= "+vs0.text()+"\n"); + Boolean rc = true; - } - while (rc = q.next()) { - YAPListTerm vs = vs0; - while(!vs.nil()){ - YAPTerm eq = vs.car(); - if (BuildConfig.DEBUG) { - Log.i(TAG, "q= "+vs0+"\n"); - } - //outputText.append(Integer.toString(i) + ": " + eq.text() ); - outputText.append(Integer.toString(i++)); - Log.i(TAG, "q= "+ eq.getArg(1)+"\n"); - Log.i(TAG, "q= "+ eq.getArg(2)+"\n"); - Log.i(TAG, "q= "+ eq.getArg(1).text()+"\n"); - Log.i(TAG, "q= "+ eq.getArg(2).text()+"\n"); -outputText.append(":\t" + eq.getArg(1).text() + " = " + eq.getArg(2).text() +"\n" ); - vs = vs.cdr(); - } - } - } - q.close(); - } catch(Exception e){ - outputText.append("Exception thrown :" + e); - return; + // text.setText(""); + if (vs0.nil()) { + if (BuildConfig.DEBUG) { + Log.i(TAG, "q0=\n"); + } + if (compute && q.next()) { + outputText.append( "yes\n" ); + running = compute = more; + } else { + outputText.append( "no\n" ); + running = false; + compute = false; + } + } else { + if (BuildConfig.DEBUG) { + Log.i(TAG, "q1= "+vs0.text()+"\n"); + } + while (compute && (rc = q.next()) ) { + YAPListTerm vs = vs0; + while(!vs.nil()){ + if (BuildConfig.DEBUG) { + Log.i(TAG, "q= "+vs0.text()+"\n"); + } + YAPTerm eq = vs.car(); + //outputText.append(Integer.toString(i) + ": " + eq.text() ); + outputText.append(Integer.toString(i++)); + outputText.append(":\t" + eq.getArg(1).text() + " = " + eq.getArg(2).text() +"\n" ); + vs = vs.cdr(); + } + compute = more; + } + } + if ( !rc) { + q.close(); + running = compute = false; + } + } catch(Exception e){ + outputText.append("Exception thrown :" + e); + return; + } } - } - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) - { - String s = null; - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - try { - PackageManager m = getPackageManager(); - s = getPackageName(); - PackageInfo p = m.getPackageInfo(s, 0); - //s = p.applicationInfo.dataDir; - AssetManager mgr = getResources().getAssets(); - Log.i(TAG, "mgr=" +mgr + " " + s); - load(mgr); - } catch(NameNotFoundException e) { - Log.e(TAG, "Couldn't find package information in PackageManager", e); - } - Log.i(TAG, "mgr=" +mgr); + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) + { + String s = null; + super.onCreate(savedInstanceState); + setContentView(R.layout.main); - text = (EditText)findViewById(R.id.EditText01); - outputText = (TextView)findViewById(R.id.OutputText); - outputText.setText("Application " + s + "\nPress 'Query' to start...\n"); - outputText.setMovementMethod(new ScrollingMovementMethod()); - scroller = (ScrollView)findViewById(R.id.Scroller); - if (BuildConfig.DEBUG) { - Log.i(TAG, "window making done"); - } - eng = new YAPEngine( ); - if (BuildConfig.DEBUG) { - Log.i(TAG, "engine done"); - } - if (BuildConfig.DEBUG) { - Log.i(TAG, "onClearButtonClick called"); - } - JavaCallback callback = new JavaCallback( outputText ); - // set the Java Callback - if (BuildConfig.DEBUG) { - Log.i(TAG, "before setting callback"); - } - eng.setYAPCallback(callback); - if (BuildConfig.DEBUG) { - Log.i(TAG, "callback done"); - } - } + try { + PackageManager m = getPackageManager(); + s = getPackageName(); + PackageInfo p = m.getPackageInfo(s, 0); + //s = p.applicationInfo.dataDir; + AssetManager mgr = getResources().getAssets(); + Log.i(TAG, "mgr=" +mgr + " " + s); + load(mgr); + } catch(NameNotFoundException e) { + Log.e(TAG, "Couldn't find package information in PackageManager", e); + } + Log.i(TAG, "mgr=" +mgr); - public void onClearButtonClick(View view) - { - if (BuildConfig.DEBUG) { - Log.i(TAG, "onClearButtonClick called"); - } - // Ensure scroll to end of text - scroller.post(new Runnable() { - public void run() { - scroller.fullScroll(ScrollView.FOCUS_DOWN); - text.setText(""); - } - }); - } - - public void onQueryButtonClick(View view) - { - if (BuildConfig.DEBUG) { - Log.i(TAG, "onQueryButtonClick called"); - } - // Ensure scroll to end of text - scroller.post(new Runnable() { - public void run() { - scroller.fullScroll(ScrollView.FOCUS_DOWN); - str = text.getText().toString(); - outputText.append("?- " + str); - Log.i(TAG, "onQueryButtonClick "+str + "\n"); - runQuery(str); - } - }); - } + text = (EditText)findViewById(R.id.EditText01); + outputText = (TextView)findViewById(R.id.OutputText); + outputText.setText("Application " + s + "\nPress 'Query' to start...\n"); + outputText.setMovementMethod(new ScrollingMovementMethod()); + scroller = (ScrollView)findViewById(R.id.Scroller); + if (BuildConfig.DEBUG) { + Log.i(TAG, "window making done"); + } + eng = new YAPEngine( ); + if (BuildConfig.DEBUG) { + Log.i(TAG, "engine done"); + } + if (BuildConfig.DEBUG) { + Log.i(TAG, "onClearButtonClick called"); + } + JavaCallback callback = new JavaCallback( outputText ); + // set the Java Callback + if (BuildConfig.DEBUG) { + Log.i(TAG, "before setting callback"); + } + eng.setYAPCallback(callback); + if (BuildConfig.DEBUG) { + Log.i(TAG, "callback done"); + } + } - public void onQuerySelectionButtonClick(View view) - { - if (BuildConfig.DEBUG) { - Log.i(TAG, "onQuerySelectionButtonClick called"); - } - // Ensure scroll to end of text - scroller.post(new Runnable() { - public void run() { - scroller.fullScroll(ScrollView.FOCUS_DOWN); - int startSelection = text.getSelectionStart(); - int endSelection = text.getSelectionEnd(); - str = text.getText().toString().substring( startSelection, endSelection ); - Log.i(TAG, "onQuerySelectionButtonClick "+str); - outputText.append("?- " + str + "\n"); - runQuery(str); - } - }); - } + public void onClearButtonClick(View view) + { + if (BuildConfig.DEBUG) { + Log.i(TAG, "onClearButtonClick called"); + } + // Ensure scroll to end of text + scroller.post(new Runnable() { + public void run() { + scroller.fullScroll(ScrollView.FOCUS_DOWN); + text.setText(""); + } + }); + } + + public void onFirstButtonClick(View view) + { + if (BuildConfig.DEBUG) { + Log.i(TAG, "onQueryButtonClick called"); + } + // Ensure scroll to end of text + scroller.post(new Runnable() { + public void run() { + scroller.fullScroll(ScrollView.FOCUS_DOWN); + str = text.getText().toString(); + //outputText.append("?- " + str+"\n\n"); + Log.i(TAG, "onQueryAnyButtonClick "+str + "\n"); + runQuery(str, false); + } + }); + } + + public void onAllButtonClick(View view) + { + if (BuildConfig.DEBUG) { + Log.i(TAG, "onQueryButtonClick called"); + } + // Ensure scroll to end of text + scroller.post(new Runnable() { + public void run() { + scroller.fullScroll(ScrollView.FOCUS_DOWN); + str = text.getText().toString(); + outputText.append("?- " + str+"\n\n"); + Log.i(TAG, "onAllButtonClick "+str + "\n"); + runQuery(str, true); + } + }); + } - /** static constructor */ - static { - System.loadLibrary("android"); - System.loadLibrary("log"); - System.loadLibrary("gmp"); - System.loadLibrary("sqliteX"); - System.loadLibrary("example"); - } - private static native void load(AssetManager mgr); + /** static constructor */ + static { + System.loadLibrary("android"); + System.loadLibrary("log"); + System.loadLibrary("gmp"); + System.loadLibrary("sqliteX"); + System.loadLibrary("example"); + } - private AssetManager mgr; + private static native void load(AssetManager mgr); - private static final String TAG = "JavaYap"; + private AssetManager mgr; + + private static final String TAG = "JavaYap"; } class JavaCallback extends YAPCallback { - TextView output; - - public JavaCallback( TextView outputText ) - { - super(); - output = outputText; - Log.i(TAG, "java callback init"); - } + TextView output; + + public JavaCallback( TextView outputText ) + { + super(); + output = outputText; + Log.i(TAG, "java callback init"); + } - public void run() - { - Log.i(TAG, "java callback "); - System.out.println("JavaCallback.run() "); - } - - public void run(String s) - { - Log.i(TAG, "java callback "); - output.append(s); - } - - private static final String TAG = "JavaCallback"; + public void run() + { + Log.i(TAG, "java callback "); + System.out.println("JavaCallback.run() "); + } + + public void run(String s) + { + Log.i(TAG, "java callback "); + output.append(s); + } + + private static final String TAG = "JavaCallback"; } diff --git a/packages/swig/android/main.xml b/packages/swig/android/main.xml index 20f2f5896..0808ee96d 100644 --- a/packages/swig/android/main.xml +++ b/packages/swig/android/main.xml @@ -9,12 +9,16 @@ android:lines="6" /> -