From a9e6d0ad129590a3776c5b5cd4992d709cd9810f Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Fri, 15 Dec 2023 09:48:23 +0900 Subject: [PATCH] bim: Different approach to finding kuroko search paths --- apps/bim.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/apps/bim.c b/apps/bim.c index 48cf32a2a..f54a013b7 100644 --- a/apps/bim.c +++ b/apps/bim.c @@ -11467,21 +11467,31 @@ void initialize(void) { krk_startModule(""); -#ifdef __toaru__ -# define KUROKO_SEARCH_PATH "/lib/kuroko/" -#else -# define KUROKO_SEARCH_PATH "/usr/lib/kuroko/" -#endif - - /* Try to import the shared object 'os' module. If we can't, - * try adjusting the module_paths to find it. */ - krk_interpret( - "try:\n" - " import os\n" - "except:\n" - " import kuroko\n" - " if '" KUROKO_SEARCH_PATH "' not in kuroko.module_paths:\n" - " kuroko.module_paths.append('" KUROKO_SEARCH_PATH "')", ""); + /* Try to import the shared object 'os' module. If we can't, try adjusting the module_paths to find it. */ + const char * potential_search_paths[] = {"/usr/lib/kuroko/","/usr/local/lib/kuroko/","/lib/kuroko/",NULL}; + const char ** next = potential_search_paths; + while (*next) { + KrkValue result = krk_interpret( + "try:\n" + " import os\n" + " return True\n" + "except:\n" + " return False\n", ""); + if (IS_BOOLEAN(result) && AS_BOOLEAN(result)) break; + if (!access(*next, R_OK)) { + char snippet[1000]; + snprintf(snippet, 1000, + "try:\n" + " import kuroko\n" + " if '%s' not in kuroko.module_paths:\n" + " kuroko.module_paths.append('%s')\n" + "except:\n" + " pass", + *next, *next); + krk_interpret(snippet, ""); + } + next++; + } import_directory("syntax"); krk_startModule("");