mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2025-12-05 18:30:24 -08:00
android/example: cosmetic: indent / untabify
This commit is contained in:
parent
5e2edcae92
commit
4ee8e62135
4 changed files with 181 additions and 183 deletions
|
|
@ -34,72 +34,72 @@ extern void loadLispFromAssets(char* fn);
|
|||
|
||||
int ecl_boot(const char *root_dir)
|
||||
{
|
||||
char *ecl = "ecl";
|
||||
char tmp[2048];
|
||||
char *ecl = "ecl";
|
||||
char tmp[2048];
|
||||
|
||||
LOGI("ECL boot beginning\n");
|
||||
LOGI("ECL boot beginning\n");
|
||||
|
||||
LOGI("Setting directories\n");
|
||||
setenv("HOME", root_dir, 1);
|
||||
LOGI("Setting directories\n");
|
||||
setenv("HOME", root_dir, 1);
|
||||
|
||||
sprintf(tmp, "%s/lib/", root_dir);
|
||||
setenv("ECLDIR", tmp, 1);
|
||||
sprintf(tmp, "%s/lib/", root_dir);
|
||||
setenv("ECLDIR", tmp, 1);
|
||||
|
||||
sprintf(tmp, "%s/etc/", root_dir);
|
||||
setenv("ETC", tmp, 1);
|
||||
sprintf(tmp, "%s/etc/", root_dir);
|
||||
setenv("ETC", tmp, 1);
|
||||
|
||||
sprintf(tmp, "%s/home/", root_dir);
|
||||
setenv("HOME", tmp, 1);
|
||||
sprintf(tmp, "%s/home/", root_dir);
|
||||
setenv("HOME", tmp, 1);
|
||||
|
||||
LOGI("Directories set\n");
|
||||
LOGI("Directories set\n");
|
||||
|
||||
/* ecl_set_option(ECL_OPT_TRAP_SIGFPE, 0); */
|
||||
/* ecl_set_option(ECL_OPT_TRAP_SIGSEGV, 0); */
|
||||
/* ecl_set_option(ECL_OPT_TRAP_SIGINT, 0); */
|
||||
/* ecl_set_option(ECL_OPT_TRAP_SIGILL, 0); */
|
||||
/* ecl_set_option(ECL_OPT_TRAP_SIGBUS, 0); */
|
||||
/* ecl_set_option(ECL_OPT_TRAP_INTERRUPT_SIGNAL, 0); */
|
||||
/* ecl_set_option(ECL_OPT_SIGNAL_HANDLING_THREAD, 0); */
|
||||
/* ecl_set_option(ECL_OPT_INCREMENTAL_GC, 0); */
|
||||
/* ecl_set_option(ECL_OPT_TRAP_SIGFPE, 0); */
|
||||
/* ecl_set_option(ECL_OPT_TRAP_SIGSEGV, 0); */
|
||||
/* ecl_set_option(ECL_OPT_TRAP_SIGINT, 0); */
|
||||
/* ecl_set_option(ECL_OPT_TRAP_SIGILL, 0); */
|
||||
/* ecl_set_option(ECL_OPT_TRAP_SIGBUS, 0); */
|
||||
/* ecl_set_option(ECL_OPT_TRAP_INTERRUPT_SIGNAL, 0); */
|
||||
/* ecl_set_option(ECL_OPT_SIGNAL_HANDLING_THREAD, 0); */
|
||||
/* ecl_set_option(ECL_OPT_INCREMENTAL_GC, 0); */
|
||||
|
||||
cl_boot(1, &ecl);
|
||||
cl_boot(1, &ecl);
|
||||
|
||||
LOGI("installing bytecodes compiler\n");
|
||||
si_safe_eval(3, c_string_to_object("(si:install-bytecodes-compiler)"), ECL_NIL, OBJNULL);
|
||||
LOGI("installing bytecodes compiler\n");
|
||||
si_safe_eval(3, c_string_to_object("(si:install-bytecodes-compiler)"), ECL_NIL, OBJNULL);
|
||||
|
||||
/* LOGI("initializing linked modules\n"); */
|
||||
/* ecl_init_module(NULL, init_lib_ECL_HELP); */
|
||||
/* ecl_init_module(NULL, init_lib_ASDF); */
|
||||
/* ecl_init_module(NULL, init_lib_SOCKETS); */
|
||||
/* ecl_init_module(NULL, init_lib_SERVE_EVENT); */
|
||||
/* LOGI("initializing linked modules\n"); */
|
||||
/* ecl_init_module(NULL, init_lib_ECL_HELP); */
|
||||
/* ecl_init_module(NULL, init_lib_ASDF); */
|
||||
/* ecl_init_module(NULL, init_lib_SOCKETS); */
|
||||
/* ecl_init_module(NULL, init_lib_SERVE_EVENT); */
|
||||
|
||||
LOGI("writing some info to stdout\n");
|
||||
si_safe_eval
|
||||
(3, c_string_to_object
|
||||
("(format t \"ECL_BOOT, features = ~A ~%\" *features*)"),
|
||||
Cnil, OBJNULL);
|
||||
si_safe_eval
|
||||
(3, c_string_to_object
|
||||
("(format t \"(truename SYS:): ~A)\" (truename \"SYS:\"))"),
|
||||
Cnil, OBJNULL);
|
||||
LOGI("writing some info to stdout\n");
|
||||
si_safe_eval
|
||||
(3, c_string_to_object
|
||||
("(format t \"ECL_BOOT, features = ~A ~%\" *features*)"),
|
||||
Cnil, OBJNULL);
|
||||
si_safe_eval
|
||||
(3, c_string_to_object
|
||||
("(format t \"(truename SYS:): ~A)\" (truename \"SYS:\"))"),
|
||||
Cnil, OBJNULL);
|
||||
|
||||
ecl_toplevel(root_dir);
|
||||
return 0;
|
||||
ecl_toplevel(root_dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ecl_toplevel(const char *home)
|
||||
{
|
||||
char tmp[2048];
|
||||
char tmp[2048];
|
||||
|
||||
LOGI("Executing the init scripts\n");
|
||||
LOGI("Executing the init scripts\n");
|
||||
|
||||
CL_CATCH_ALL_BEGIN(ecl_process_env())
|
||||
{
|
||||
sprintf(tmp, "(setq *default-pathname-defaults* #p\"%s/\")", home);
|
||||
si_safe_eval(3, c_string_to_object(tmp), Cnil, OBJNULL);
|
||||
si_select_package(ecl_make_simple_base_string("CL-USER", 7));
|
||||
si_safe_eval(3, c_string_to_object("(load \"etc/init\")"), Cnil, OBJNULL);
|
||||
} CL_CATCH_ALL_END;
|
||||
CL_CATCH_ALL_BEGIN(ecl_process_env())
|
||||
{
|
||||
sprintf(tmp, "(setq *default-pathname-defaults* #p\"%s/\")", home);
|
||||
si_safe_eval(3, c_string_to_object(tmp), Cnil, OBJNULL);
|
||||
si_select_package(ecl_make_simple_base_string("CL-USER", 7));
|
||||
si_safe_eval(3, c_string_to_object("(load \"etc/init\")"), Cnil, OBJNULL);
|
||||
} CL_CATCH_ALL_END;
|
||||
|
||||
LOGI("Toplevel initialization done\n");
|
||||
LOGI("Toplevel initialization done\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,62 +32,60 @@
|
|||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_lisp_ecl_EmbeddedCommonLisp_start(JNIEnv *env, jobject this,
|
||||
jstring path) {
|
||||
Java_org_lisp_ecl_EmbeddedCommonLisp_start(JNIEnv *env, jobject this, jstring path) {
|
||||
|
||||
const char *lisp_dir = (*env)->GetStringUTFChars(env, path, NULL);
|
||||
LOGI("XXX: ECL starting: *default-pathname-defaults* to: %s\n", lisp_dir);
|
||||
ecl_boot(lisp_dir);
|
||||
LOGI("ECL started.");
|
||||
const char *lisp_dir = (*env)->GetStringUTFChars(env, path, NULL);
|
||||
LOGI("XXX: ECL starting: *default-pathname-defaults* to: %s\n", lisp_dir);
|
||||
ecl_boot(lisp_dir);
|
||||
LOGI("ECL started.");
|
||||
};
|
||||
|
||||
/* This was fun to make UTF8 work across Java-C-Lisp boundaries.
|
||||
-evrim, 2014. */
|
||||
cl_object java_string_to_ecl_string(JNIEnv *env, jstring str) {
|
||||
const jchar *txt = (*env)->GetStringChars(env, str, NULL);
|
||||
jsize len = (*env)->GetStringLength(env, str);
|
||||
cl_object ecl_txt = ecl_alloc_simple_extended_string(len);
|
||||
cl_index i;
|
||||
const jchar *txt = (*env)->GetStringChars(env, str, NULL);
|
||||
jsize len = (*env)->GetStringLength(env, str);
|
||||
cl_object ecl_txt = ecl_alloc_simple_extended_string(len);
|
||||
cl_index i;
|
||||
|
||||
for (i=0;i<len;i++) {
|
||||
ecl_txt->string.self[i] = txt[i];
|
||||
};
|
||||
|
||||
(*env)->ReleaseStringChars(env, str, txt);
|
||||
for (i=0;i<len;i++) {
|
||||
ecl_txt->string.self[i] = txt[i];
|
||||
};
|
||||
|
||||
return ecl_txt;
|
||||
(*env)->ReleaseStringChars(env, str, txt);
|
||||
|
||||
return ecl_txt;
|
||||
}
|
||||
|
||||
|
||||
jstring ecl_object_to_java_string(JNIEnv *env, cl_object o) {
|
||||
jstring ret;
|
||||
if (ECL_EXTENDED_STRING_P(o)) {
|
||||
LOGI("ecl->java extended string of fillp: %d, dim: %d",
|
||||
o->string.fillp,
|
||||
o->string.dim);
|
||||
|
||||
jsize len = o->string.fillp;
|
||||
jchar *arr = malloc(sizeof(jchar)*(len+1));
|
||||
cl_index i;
|
||||
for (i=0; i<len; i++) {
|
||||
arr[i] = o->string.self[i];
|
||||
}
|
||||
arr[len] = 0;
|
||||
ret = (*env)->NewString(env, arr, len);
|
||||
free(arr);
|
||||
} else if (ECL_STRINGP(o)) {
|
||||
LOGI("ecl->java base string of len %d: %s",
|
||||
o->base_string.dim,
|
||||
o->base_string.self);
|
||||
jstring ret;
|
||||
if (ECL_EXTENDED_STRING_P(o)) {
|
||||
LOGI("ecl->java extended string of fillp: %d, dim: %d",
|
||||
o->string.fillp,
|
||||
o->string.dim);
|
||||
|
||||
ret = (*env)->NewStringUTF(env,
|
||||
(const char*)o->base_string.self);
|
||||
} else {
|
||||
LOGI("ecl->java not a string, coercing");
|
||||
return ecl_object_to_java_string(env, cl_princ_to_string(o));
|
||||
}
|
||||
jsize len = o->string.fillp;
|
||||
jchar *arr = malloc(sizeof(jchar)*(len+1));
|
||||
cl_index i;
|
||||
for (i=0; i<len; i++) {
|
||||
arr[i] = o->string.self[i];
|
||||
}
|
||||
arr[len] = 0;
|
||||
ret = (*env)->NewString(env, arr, len);
|
||||
free(arr);
|
||||
} else if (ECL_STRINGP(o)) {
|
||||
LOGI("ecl->java base string of len %d: %s",
|
||||
o->base_string.dim,
|
||||
o->base_string.self);
|
||||
|
||||
return ret;
|
||||
ret = (*env)->NewStringUTF(env, (const char*)o->base_string.self);
|
||||
} else {
|
||||
LOGI("ecl->java not a string, coercing");
|
||||
return ecl_object_to_java_string(env, cl_princ_to_string(o));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -97,17 +95,17 @@ jstring ecl_object_to_java_string(JNIEnv *env, cl_object o) {
|
|||
*/
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_lisp_ecl_EmbeddedCommonLisp_exec(JNIEnv *env, jobject this, jstring str) {
|
||||
jstring ret;
|
||||
cl_object txt = java_string_to_ecl_string(env, str);
|
||||
cl_object result = si_safe_eval(3, jni_ecl_read_from_string(txt), Cnil, OBJNULL);
|
||||
|
||||
if (result) {
|
||||
ret = ecl_object_to_java_string(env, result);
|
||||
} else {
|
||||
ret = (*env)->NewStringUTF(env, "ERROR in eval");
|
||||
}
|
||||
|
||||
return ret;
|
||||
jstring ret;
|
||||
cl_object txt = java_string_to_ecl_string(env, str);
|
||||
cl_object result = si_safe_eval(3, jni_ecl_read_from_string(txt), Cnil, OBJNULL);
|
||||
|
||||
if (result) {
|
||||
ret = ecl_object_to_java_string(env, result);
|
||||
} else {
|
||||
ret = (*env)->NewStringUTF(env, "ERROR in eval");
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
#undef jni_ecl_read_from_string
|
||||
|
|
@ -119,16 +117,16 @@ Java_org_lisp_ecl_EmbeddedCommonLisp_exec(JNIEnv *env, jobject this, jstring str
|
|||
*/
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_lisp_ecl_EmbeddedCommonLisp_exec_(JNIEnv *env, jobject this, jstring str) {
|
||||
jstring ret;
|
||||
const char *cmd = (*env)->GetStringUTFChars(env, str, NULL);
|
||||
cl_object result = si_safe_eval(3, c_string_to_object(cmd),
|
||||
Cnil, OBJNULL);
|
||||
jstring ret;
|
||||
const char *cmd = (*env)->GetStringUTFChars(env, str, NULL);
|
||||
cl_object result = si_safe_eval(3, c_string_to_object(cmd),
|
||||
Cnil, OBJNULL);
|
||||
|
||||
if (result) {
|
||||
cl_object out = si_coerce_to_base_string(cl_princ_to_string(result));
|
||||
ret = (*env)->NewStringUTF(env, (const char*) out->base_string.self);
|
||||
} else {
|
||||
ret = (*env)->NewStringUTF(env, "ERROR in eval");
|
||||
}
|
||||
return ret;
|
||||
if (result) {
|
||||
cl_object out = si_coerce_to_base_string(cl_princ_to_string(result));
|
||||
ret = (*env)->NewStringUTF(env, (const char*) out->base_string.self);
|
||||
} else {
|
||||
ret = (*env)->NewStringUTF(env, "ERROR in eval");
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import android.util.Log;
|
|||
|
||||
public class EmbeddedCommonLisp {
|
||||
private static String TAG = "EmbeddedCommonLisp";
|
||||
|
||||
|
||||
public void start() {
|
||||
start(System.getenv("user.dir"));
|
||||
start(System.getenv("user.dir"));
|
||||
}
|
||||
public native void start(String path);
|
||||
public native String exec(String string);
|
||||
|
|
@ -14,7 +14,7 @@ public class EmbeddedCommonLisp {
|
|||
|
||||
static {
|
||||
System.loadLibrary("ecl");
|
||||
System.loadLibrary("ecl_android");
|
||||
Log.w(TAG,"Done loading library");
|
||||
System.loadLibrary("ecl_android");
|
||||
Log.w(TAG,"Done loading library");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ public class HelloEclActivity extends Activity
|
|||
private static String RESOURCES_DIR = "lisp";
|
||||
private static String APP_RESOURCES_DIR = "resources";
|
||||
private EmbeddedCommonLisp ecl = new EmbeddedCommonLisp();
|
||||
|
||||
|
||||
private static boolean DEBUG = false;
|
||||
|
||||
static AssetManager assetManager;
|
||||
static File uncompressedFilesDir;
|
||||
static AssetManager assetManager;
|
||||
static File uncompressedFilesDir;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
|
|
@ -43,12 +43,12 @@ public class HelloEclActivity extends Activity
|
|||
uncompressedFilesDir = getDir(APP_RESOURCES_DIR,MODE_PRIVATE);
|
||||
|
||||
if(!assetsUncompressed)
|
||||
{
|
||||
uncompressDir(RESOURCES_DIR,uncompressedFilesDir);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putBoolean("assetsUncompressed", true);
|
||||
editor.commit();
|
||||
}
|
||||
{
|
||||
uncompressDir(RESOURCES_DIR,uncompressedFilesDir);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putBoolean("assetsUncompressed", true);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
Log.w(TAG,"ECL starting.");
|
||||
ecl.start(getResourcesPath());
|
||||
|
|
@ -56,51 +56,51 @@ public class HelloEclActivity extends Activity
|
|||
|
||||
setContentView(R.layout.main);
|
||||
|
||||
String result = ecl.exec("(format nil \"Hello from lisp\")");
|
||||
System.out.println("Result: " + result);
|
||||
|
||||
Context context = getApplicationContext();
|
||||
int duration = Toast.LENGTH_LONG;
|
||||
|
||||
Toast toast = Toast.makeText(context, result, duration);
|
||||
toast.show();
|
||||
String result = ecl.exec("(format nil \"Hello from lisp\")");
|
||||
System.out.println("Result: " + result);
|
||||
|
||||
Context context = getApplicationContext();
|
||||
int duration = Toast.LENGTH_LONG;
|
||||
|
||||
Toast toast = Toast.makeText(context, result, duration);
|
||||
toast.show();
|
||||
}
|
||||
|
||||
public void uncompressDir(String in, File out)
|
||||
{
|
||||
try
|
||||
{
|
||||
String[] files = assetManager.list(in);
|
||||
Log.w(TAG,"Uncompressing: " + files.length + " files");
|
||||
for(int i=0; i<files.length; i++)
|
||||
{
|
||||
Log.w(TAG,"Uncompressing: " + files[i]);
|
||||
File fileIn = new File(in,files[i]);
|
||||
File fileOut = new File(out,files[i]);
|
||||
|
||||
try
|
||||
{
|
||||
uncompressFile(fileIn,fileOut);
|
||||
}
|
||||
catch(FileNotFoundException e)
|
||||
{
|
||||
// fileIn is a directory, uncompress the subdir
|
||||
if(!fileOut.isDirectory())
|
||||
String[] files = assetManager.list(in);
|
||||
Log.w(TAG,"Uncompressing: " + files.length + " files");
|
||||
for(int i=0; i<files.length; i++)
|
||||
{
|
||||
Log.w(TAG,"Creating dir: " + fileOut.getAbsolutePath());
|
||||
fileOut.mkdir();
|
||||
Log.w(TAG,"Uncompressing: " + files[i]);
|
||||
File fileIn = new File(in,files[i]);
|
||||
File fileOut = new File(out,files[i]);
|
||||
|
||||
try
|
||||
{
|
||||
uncompressFile(fileIn,fileOut);
|
||||
}
|
||||
catch(FileNotFoundException e)
|
||||
{
|
||||
// fileIn is a directory, uncompress the subdir
|
||||
if(!fileOut.isDirectory())
|
||||
{
|
||||
Log.w(TAG,"Creating dir: " + fileOut.getAbsolutePath());
|
||||
fileOut.mkdir();
|
||||
}
|
||||
uncompressDir(fileIn.getPath(), fileOut);
|
||||
}
|
||||
}
|
||||
uncompressDir(fileIn.getPath(), fileOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Initiating Menu XML file (menu.xml)
|
||||
// Initiating Menu XML file (menu.xml)
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
|
|
@ -117,36 +117,36 @@ public class HelloEclActivity extends Activity
|
|||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
switch (item.getItemId())
|
||||
{
|
||||
case R.id.menu_uncompress:
|
||||
uncompressDir(RESOURCES_DIR,uncompressedFilesDir);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
{
|
||||
case R.id.menu_uncompress:
|
||||
uncompressDir(RESOURCES_DIR,uncompressedFilesDir);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getResourcesPath()
|
||||
{
|
||||
return uncompressedFilesDir.getAbsolutePath();
|
||||
}
|
||||
public static String getResourcesPath()
|
||||
{
|
||||
return uncompressedFilesDir.getAbsolutePath();
|
||||
}
|
||||
|
||||
public static void uncompressFile(File fileIn,File fileOut)
|
||||
public static void uncompressFile(File fileIn,File fileOut)
|
||||
throws IOException
|
||||
{
|
||||
InputStream in = assetManager.open(fileIn.getPath(),
|
||||
android.content.res.AssetManager.ACCESS_RANDOM);
|
||||
OutputStream out = new FileOutputStream(fileOut);
|
||||
OutputStream out = new FileOutputStream(fileOut);
|
||||
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0)
|
||||
{
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0)
|
||||
{
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
|
||||
in.close();
|
||||
out.close();
|
||||
Log.i(TAG,"File copied.");
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
Log.i(TAG,"File copied.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue