Skip to content

Commit

Permalink
bim: Different approach to finding kuroko search paths
Browse files Browse the repository at this point in the history
  • Loading branch information
klange committed Dec 15, 2023
1 parent 2005732 commit a9e6d0a
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions apps/bim.c
Original file line number Diff line number Diff line change
Expand Up @@ -11467,21 +11467,31 @@ void initialize(void) {

krk_startModule("<bim-syntax>");

#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 "')", "<bim-syntax>");
/* 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", "<bim-syntax>");
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, "<bim-syntax>");
}
next++;
}

import_directory("syntax");
krk_startModule("<bim-themes>");
Expand Down

0 comments on commit a9e6d0a

Please sign in to comment.