Skip to content

Commit 47bca7e

Browse files
committed
CONSOLE: fix module command option
1 parent 1652cc3 commit 47bca7e

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

src/common/extlib.c

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,20 @@ int slib_add_external_func(const char *func_name, uint32_t lib_id) {
187187
*/
188188
int slib_get_kid(int lib_id, const char *name) {
189189
slib_t *lib = get_lib(lib_id);
190-
const char *dot = strchr(name, '.');
191-
const char *field = (dot != NULL ? dot + 1 : name);
192-
for (int i = 0; i < lib->proc_count; i++) {
193-
if (lib->proc_list[i].lib_id == lib_id &&
194-
strcmp(lib->proc_list[i].name, field) == 0) {
195-
return i;
190+
if (lib != NULL) {
191+
const char *dot = strchr(name, '.');
192+
const char *field = (dot != NULL ? dot + 1 : name);
193+
for (int i = 0; i < lib->proc_count; i++) {
194+
if (lib->proc_list[i].lib_id == lib_id &&
195+
strcmp(lib->proc_list[i].name, field) == 0) {
196+
return i;
197+
}
196198
}
197-
}
198-
for (int i = 0; i < lib->func_count; i++) {
199-
if (lib->func_list[i].lib_id == lib_id &&
200-
strcmp(lib->func_list[i].name, field) == 0) {
201-
return i;
199+
for (int i = 0; i < lib->func_count; i++) {
200+
if (lib->func_list[i].lib_id == lib_id &&
201+
strcmp(lib->func_list[i].name, field) == 0) {
202+
return i;
203+
}
202204
}
203205
}
204206
return -1;
@@ -272,7 +274,7 @@ void slib_import_routines(slib_t *lib, int comp) {
272274
}
273275

274276
if (!total) {
275-
log_printf("LIB: module has no exports...\n");
277+
log_printf("LIB: module '%s' has no exports\n", lib->name);
276278
}
277279
}
278280

@@ -312,13 +314,10 @@ void slib_open(const char *fullname, const char *name) {
312314
lib->imported = 0;
313315

314316
if (!opt_quiet) {
315-
log_printf("LIB: importing %s", fullname);
317+
log_printf("LIB: registering '%s'", fullname);
316318
}
317319
if (slib_llopen(lib)) {
318320
slib_count++;
319-
if (!opt_quiet) {
320-
log_printf("... done\n");
321-
}
322321
// override default name
323322
sblib_get_module_name_fn get_module_name = slib_getoptptr(lib, "sblib_get_module_name");
324323
if (get_module_name) {
@@ -383,7 +382,7 @@ void slib_scan_path(const char *path) {
383382
}
384383
}
385384
} else if (!opt_quiet) {
386-
log_printf("LIB: module path %s not found.\n", path);
385+
log_printf("LIB: module path '%s' not found.\n", path);
387386
}
388387
}
389388

@@ -410,17 +409,15 @@ void slib_init() {
410409
slib_count = 0;
411410

412411
if (!prog_error && opt_loadmod) {
413-
if (!opt_quiet) {
414-
log_printf("LIB: scanning for modules...\n");
415-
}
416-
417412
if (opt_modpath[0] == '\0') {
418413
const char *modpath = getenv("SBASICPATH");
419414
if (modpath != NULL) {
420415
strlcpy(opt_modpath, modpath, OPT_MOD_SZ);
421416
}
422417
}
423-
418+
if (!opt_quiet) {
419+
log_printf("LIB: scanning for modules in '%s'\n", opt_modpath);
420+
}
424421
slib_init_path();
425422
}
426423
}

src/platform/console/main.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void console_init();
2626
static struct option OPTIONS[] = {
2727
{"verbose", no_argument, NULL, 'v'},
2828
{"keywords", no_argument, NULL, 'k'},
29-
{"no-file-perm", no_argument, NULL, 'f'},
29+
{"no-file-access", no_argument, NULL, 'f'},
3030
{"gen-sbx", no_argument, NULL, 'x'},
3131
{"module-path", optional_argument, NULL, 'm'},
3232
{"decompile", optional_argument, NULL, 's'},
@@ -241,7 +241,7 @@ bool process_options(int argc, char *argv[], char **runFile, bool *tmpFile) {
241241
bool result = true;
242242
while (result) {
243243
int option_index = 0;
244-
int c = getopt_long(argc, argv, "vkfxm::s::o:c:h::", OPTIONS, &option_index);
244+
int c = getopt_long(argc, argv, "vkfxm:s:o:c:h::", OPTIONS, &option_index);
245245
if (c == -1 && !option_index) {
246246
// no more options
247247
for (int i = 1; i < argc; i++) {
@@ -337,6 +337,12 @@ bool process_options(int argc, char *argv[], char **runFile, bool *tmpFile) {
337337
show_brief_help();
338338
result = false;
339339
}
340+
341+
if (opt_modpath[0] != '\0' && access(opt_modpath, R_OK) != 0) {
342+
fprintf(stdout, "sbasic: can't open path '%s': [Errno %d] %s\n", opt_modpath, errno, strerror(errno));
343+
result = false;
344+
}
345+
340346
return result;
341347
}
342348

0 commit comments

Comments
 (0)