static ALLEGRO_FS_ENTRY *fs_apk_read_directory(ALLEGRO_FS_ENTRY *fse) { ALLEGRO_FS_ENTRY_APK *e = (ALLEGRO_FS_ENTRY_APK *)fse; ALLEGRO_FS_ENTRY *next; ALLEGRO_USTR *tmp; if (!e->file_list_pos) return NULL; if (!*e->file_list_pos) return NULL; tmp = al_ustr_new(e->path_cstr); ensure_trailing_slash(tmp); char *name = e->file_list_pos; char *semi = strchr(name, ';'); if (semi) { *semi = 0; e->file_list_pos = semi + 1; } else { e->file_list_pos = name + strlen(name); } al_ustr_append_cstr(tmp, name); next = fs_apk_create_entry(al_cstr(tmp)); al_ustr_free(tmp); return next; }
static bool fs_apk_change_directory(const char *path) { ALLEGRO_USTR *us; bool ret; /* Figure out which directory we are trying to change to. */ if (path_is_absolute(path)) us = al_ustr_new(path); else us = apply_cwd(path); ensure_trailing_slash(us); if ((size_t) al_ustr_size(us) < sizeof(fs_apk_cwd)) { al_ustr_to_buffer(us, fs_apk_cwd, sizeof(fs_apk_cwd)); ret = true; } al_ustr_free(us); return ret; }
int main(int argc, char **argv) { config.verbose = false; config.quiet = false; config.repl = false; config.javascript = false; config.static_fns = false; config.elide_asserts = false; config.cache_path = NULL; config.theme = "light"; config.dumb_terminal = false; config.out_path = NULL; config.num_src_paths = 0; config.src_paths = NULL; config.num_scripts = 0; config.scripts = NULL; config.main_ns_name = NULL; struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"legal", no_argument, NULL, 'l'}, {"verbose", no_argument, NULL, 'v'}, {"quiet", no_argument, NULL, 'q'}, {"repl", no_argument, NULL, 'r'}, {"static-fns", no_argument, NULL, 's'}, {"elide-asserts", no_argument, NULL, 'a'}, {"cache", required_argument, NULL, 'k'}, {"eval", required_argument, NULL, 'e'}, {"theme", required_argument, NULL, 't'}, {"dumb-terminal", no_argument, NULL, 'd'}, {"classpath", required_argument, NULL, 'c'}, {"auto-cache", no_argument, NULL, 'K'}, {"init", required_argument, NULL, 'i'}, {"main", required_argument, NULL, 'm'}, // development options {"javascript", no_argument, NULL, 'j'}, {"out", required_argument, NULL, 'o'}, {0, 0, 0, 0} }; int opt, option_index; while ((opt = getopt_long(argc, argv, "h?lvrsak:je:t:dc:o:Ki:qm:", long_options, &option_index)) != -1) { switch (opt) { case 'h': usage(argv[0]); exit(0); case 'l': legal(); return 0; case 'v': config.verbose = true; break; case 'q': config.quiet = true; break; case 'r': config.repl = true; break; case 's': config.static_fns = true; break; case 'a': config.elide_asserts = true; break; case 'k': config.cache_path = argv[optind - 1]; break; case 'K': config.cache_path = ".planck_cache"; { char *path_copy = strdup(config.cache_path); char *dir = dirname(path_copy); if (mkdir_p(dir) < 0) { fprintf(stderr, "Could not create %s: %s\n", config.cache_path, strerror(errno)); } free(path_copy); } break; case 'j': config.javascript = true; break; case 'e': config.num_scripts += 1; config.scripts = realloc(config.scripts, config.num_scripts * sizeof(struct script)); config.scripts[config.num_scripts - 1].type = "text"; config.scripts[config.num_scripts - 1].expression = true; config.scripts[config.num_scripts - 1].source = argv[optind - 1]; break; case 'i': config.num_scripts += 1; config.scripts = realloc(config.scripts, config.num_scripts * sizeof(struct script)); config.scripts[config.num_scripts - 1].type = "path"; config.scripts[config.num_scripts - 1].expression = false; config.scripts[config.num_scripts - 1].source = argv[optind - 1]; break; case 'm': config.main_ns_name = argv[optind - 1]; break; case 't': config.theme = argv[optind - 1]; break; case 'd': config.dumb_terminal = true; break; case 'c': { char *classpath = argv[optind - 1]; char *source = strtok(classpath, ":"); while (source != NULL) { char *type = "src"; if (str_has_suffix(source, ".jar") == 0) { type = "jar"; } config.num_src_paths += 1; config.src_paths = realloc(config.src_paths, config.num_src_paths * sizeof(struct src_path)); config.src_paths[config.num_src_paths - 1].type = type; config.src_paths[config.num_src_paths - 1].path = strcmp(type, "jar") == 0 ? strdup(source) : ensure_trailing_slash(source); source = strtok(NULL, ":"); } break; } case 'o': config.out_path = ensure_trailing_slash(argv[optind - 1]); break; case '?': usage(argv[0]); exit(1); default: printf("unhandled argument: %c\n", opt); } } if (config.dumb_terminal) { config.theme = "dumb"; } config.num_rest_args = 0; config.rest_args = NULL; if (optind < argc) { config.num_rest_args = argc - optind; config.rest_args = malloc((argc - optind) * sizeof(char*)); int i = 0; while (optind < argc) { config.rest_args[i++] = argv[optind++]; } } if (config.num_scripts == 0 && config.main_ns_name == NULL && config.num_rest_args == 0) { config.repl = true; } if (config.main_ns_name != NULL && config.repl) { printf("Only one main-opt can be specified.\n"); exit(1); } config.is_tty = isatty(STDIN_FILENO) == 1; JSGlobalContextRef ctx = JSGlobalContextCreate(NULL); global_ctx = ctx; cljs_engine_init(ctx); // Process init arguments for (int i = 0; i < config.num_scripts; i++) { // TODO: exit if not successfull struct script script = config.scripts[i]; evaluate_source(ctx, script.type, script.source, script.expression, false, NULL, config.theme, true); } // Process main arguments if (config.main_ns_name != NULL) { run_main_in_ns(ctx, config.main_ns_name, config.num_rest_args, config.rest_args); } else if (!config.repl && config.num_rest_args > 0) { char *path = config.rest_args[0]; struct script script; if (strcmp(path, "-") == 0) { char *source = read_all(stdin); script.type = "text"; script.source = source; script.expression = false; } else { script.type = "path"; script.source = path; script.expression = false; } evaluate_source(ctx, script.type, script.source, script.expression, false, NULL, config.theme, true); } else if (config.repl) { if (!config.quiet) { banner(); } run_repl(ctx); } return exit_value; }