int main(int argc, char *argv[]) { duk_int_t res = 0; /* initialize */ duk_context *ctx = duk_create_heap_default(); /* duktape does not expose a standard "global" by default */ DOIT("var global = (function(){ return this; }).call(null);"); /* load library */ res = eval_file(ctx, "shim.min.js"); if(res != 0) FAIL("shim load") res = eval_file(ctx, "xlsx.full.min.js"); if(res != 0) FAIL("library load") /* get version string */ duk_eval_string(ctx, "XLSX.version"); printf("SheetJS library version %s\n", duk_get_string(ctx, -1)); duk_pop(ctx); /* read file */ res = load_file(ctx, argv[1], "buf"); if(res != 0) FAIL("file load") printf("Loaded file %s\n", argv[1]); /* parse workbook */ DOIT("wb = XLSX.read(buf, {type:'buffer', cellNF:true});"); DOIT("ws = wb.Sheets[wb.SheetNames[0]]"); /* print CSV */ duk_eval_string(ctx, "XLSX.utils.sheet_to_csv(ws)"); printf("%s\n", duk_get_string(ctx, -1)); duk_pop(ctx); /* change cell A1 to 3 */ DOIT("ws['A1'].v = 3; delete ws['A1'].w;"); /* write file */ #define WRITE_TYPE(BOOKTYPE) \ DOIT("newbuf = (XLSX.write(wb, {type:'array', bookType:'" BOOKTYPE "'}));");\ res = save_file(ctx, "sheetjsw." BOOKTYPE, "newbuf");\ if(res != 0) FAIL("save sheetjsw." BOOKTYPE) WRITE_TYPE("xlsb") WRITE_TYPE("xlsx") WRITE_TYPE("xls") WRITE_TYPE("csv") /* cleanup */ duk_destroy_heap(ctx); return res; }
static int create_manifest_filelist(char **argv, char *reloc_root) { int ret_status = EXIT; char input_fname[PATH_MAX]; while (read_filelist(reloc_root, argv, input_fname, sizeof (input_fname)) != -1) { struct stat64 stat_buf; int ret; ret = lstat64(input_fname, &stat_buf); if (ret < 0) { ret_status = WARNING_EXIT; perror(input_fname); } else { ret = eval_file(input_fname, &stat_buf); if (ret == WARNING_EXIT) ret_status = WARNING_EXIT; } } return (ret_status); }
int main(int argc, char **argv) { Obj *root = NULL; printf("sizeof(Obj): %d MEMORY_SIZE: %d\n", sizeof(Obj), HEAP_SIZE); memory.len = 0; memory.capa = MAX_HEAPS_SIZE; memory.heaps = malloc(sizeof(Obj*) * MAX_HEAPS_SIZE); free_list = alloc_heap(); if (DEBUG_GC) printf("MEMORY: %p + %x\n", memory, HEAP_SIZE); Nil = make_spe(TNIL); Dot = make_spe(TDOT); Cparen = make_spe(TCPAREN); True = make_spe(TTRUE); Env *env = malloc(sizeof(Env)); env->vars = Nil; env->next = NULL; define_consts(env, root); define_primitives(env, root); if (argc < 2) { do_repl(env, root); } else { eval_file(env, root, argv[1]); } return 0; }
void initialize_js(struct flim *flim) { flim->js_runtime = JS_NewRuntime(8L * 1024L * 1024L); flim->js_context = JS_NewContext(flim->js_runtime, 8192); JS_SetOptions(flim->js_context, JSOPTION_VAROBJFIX | JSOPTION_METHODJIT); JS_SetVersion(flim->js_context, JSVERSION_LATEST); JS_SetErrorReporter(flim->js_context, report_error); flim->global = JS_NewCompartmentAndGlobalObject( flim->js_context, &global_class, NULL); JS_InitStandardClasses(flim->js_context, flim->global); JS_DefineFunctions(flim->js_context, flim->global, js_functions); eval_file("runtime/flim.js"); eval_file("runtime/underscore.js"); }
void test_runtime() { printf("core runtime tests\n"); test_eval_true("print != false"); test_eval_true("println != false"); test_eval_true("assert != false"); test_eval_true("assert (true, '') true"); eval_file("tests/list-sum.zeta"); eval_file("tests/read_text_file.zeta"); }
int main(int argc, char *argv[]) { init(); atexit(cleanup); signal(SIGINT, cleanup_signal_handler); signal(SIGKILL, cleanup_signal_handler); eval_file("startup.lisp"); if (argc > 1) { int i; for (i = 1; i < argc; ++i) eval_file(argv[i]); } else { run(); } return 0; }
int main(int argc, char **argv){ //printf("string compare %d\n", contains_str("help", "pl")); //compare_answer("/foo 1 \n /test 2", "/foo 1 \n /test 2"); //add some code here that will get a file from the commandline arg FILE *expression_file = fopen ("test/expressions.txt" , "r"); if (expression_file == NULL) perror("Error opening file"); eval_file(expression_file); }
int main(int argc, char **argv) { char *file_to_eval = NULL; int replize = argc < 1; for(int i = 1; i < argc; i++) { if(!strcmp("-f", argv[i])) file_to_eval = argv[++i]; else if(!strcmp("--verbose", argv[i])) VERBOSE = true; else if(!strcmp("-i", argv[i])) replize = true; } init_alloc_system(); init_symboltable(); register_builtin_functions(); new_var(new_symbol("nil"), (LispObject*)nil); new_var(new_symbol("t"), (LispObject*)new_symbol("t")); nexception_points++; if(setjmp(exception_points[nexception_points - 1]) == 0) { eval_file("prelude.l"); if(file_to_eval) eval_file(file_to_eval); else repl(); } else { fprintf(stderr, "%s", error_string); printf("Stack trace:\n"); for(int i = 0; i < call_stack->size; i++) { printf(" "); obj_print(vector_getitem(call_stack, i)); printf("\n"); } while(scopes->size > 1) pop_scope(); while(call_stack->size > 1) vector_remove(call_stack, -1); if(replize) repl(); } }
int main(void) { Pile *p_pile = NULL; File *p_file = NULL; char entry[MAX_ENTRY] = ""; //double result = 0; fgets(entry, sizeof(entry), stdin); eval_expr(entry, &p_file, &p_pile); puts("\nEn Notation Polonaise Inverse: "); print_file(p_file); printf("\n\nResultat = %f\n", eval_file(&p_file)); return 0; }
int main() { // 1. init interpreter ruby_init(); ruby_init_loadpath(); //ruby_script("embed.rb"); // 2. load global objects Init_SysInfo(); // 3. run script // int state = eval_buffer("puts \"kamin babo\"\nprint $hardware"); // int state = eval_file("/Users/yielding/test/rb/embed/embed.rb"); int state = eval_file("embed.rb"); if (state) printf("error\n"); print_array(hardware_list); // 4. finalize // ruby_finalize(); ruby_cleanup(0); }
/* * Callback function for nftw() */ static int walker(const char *name, const struct stat64 *sp, int type, struct FTW *ftwx) { int ret; struct statvfs path_vfs; boolean_t dir_flag = B_FALSE; struct rule *rule; switch (type) { case FTW_F: /* file */ rule = check_rules(name, 'F'); if (rule != NULL) { if (rule->attr_list & ATTR_CONTENTS) compute_chksum = 1; else compute_chksum = 0; } break; case FTW_SL: /* symbolic link */ case FTW_DP: /* end of directory */ case FTW_DNR: /* unreadable directory */ case FTW_NS: /* unstatable file */ break; case FTW_D: /* enter directory */ /* * Check to see if any subsequent rules are a subset * of this rule; if they are, then mark them as * "traversed". */ rule = subtree_root->next; while (rule != NULL) { if (strcmp(name, rule->subtree) == 0) rule->traversed = B_TRUE; rule = rule->next; } dir_flag = B_TRUE; ret = statvfs(name, &path_vfs); if (ret < 0) eval_err = WARNING_EXIT; break; default: (void) fprintf(stderr, INVALID_FILE, name); eval_err = WARNING_EXIT; break; } /* This is the function which really processes the file */ ret = eval_file(name, sp); /* * Since the parameters to walker() are constrained by nftw(), * need to use a global to reflect a WARNING. Sigh. */ if (ret == WARNING_EXIT) eval_err = WARNING_EXIT; /* * This is a case of a directory which crosses into a mounted * filesystem of a different type, e.g., UFS -> NFS. * BART should not walk the new filesystem (by specification), so * set this consolidation-private flag so the rest of the subtree * under this directory is not waled. */ if (dir_flag && (strcmp(parent_vfs.f_basetype, path_vfs.f_basetype) != 0)) ftwx->quit = FTW_PRUNE; return (0); }
void EQWParser::DoInit() { const char *argv_eqemu[] = { "", "-w", "-W", "-e", "0;", nullptr }; int argc = 5; char **argv = (char **)argv_eqemu; char **env = { nullptr }; PL_perl_destruct_level = 1; perl_construct(my_perl); PERL_SYS_INIT3(&argc, &argv, &env); perl_parse(my_perl, xs_init, argc, argv, env); perl_run(my_perl); //a little routine we use a lot. eval_pv("sub my_eval {eval $_[0];}", TRUE); //dies on error //ruin the perl exit and command: eval_pv("sub my_exit {}",TRUE); eval_pv("sub my_sleep {}",TRUE); if(gv_stashpv("CORE::GLOBAL", FALSE)) { GV *exitgp = gv_fetchpv("CORE::GLOBAL::exit", TRUE, SVt_PVCV); GvCV_set(exitgp, perl_get_cv("my_exit", TRUE)); //dies on error GvIMPORTED_CV_on(exitgp); GV *sleepgp = gv_fetchpv("CORE::GLOBAL::sleep", TRUE, SVt_PVCV); GvCV_set(sleepgp, perl_get_cv("my_sleep", TRUE)); //dies on error GvIMPORTED_CV_on(sleepgp); } //setup eval_file eval_pv( "our %Cache;" "use Symbol qw(delete_package);" "sub eval_file {" "my($package, $filename) = @_;" "$filename=~s/\'//g;" "if(! -r $filename) { print \"Unable to read perl file '$filename'\\n\"; return; }" "my $mtime = -M $filename;" "if(defined $Cache{$package}{mtime}&&$Cache{$package}{mtime} <= $mtime && !($package eq 'plugin')){" " return;" "} else {" //we 'my' $filename,$mtime,$package,$sub to prevent them from changing our state up here. " eval(\"package $package; my(\\$filename,\\$mtime,\\$package,\\$sub); \\$isloaded = 1; require '$filename'; \");" "}" "}" ,FALSE); //make a tie-able class to capture IO and get it where it needs to go eval_pv( "package EQWIO; " // "&boot_EQEmuIO;" "sub TIEHANDLE { my $me = bless {}, $_[0]; $me->PRINT('Creating '.$me); return($me); } " "sub WRITE { } " "sub PRINTF { my $me = shift; my $fmt = shift; $me->PRINT(sprintf($fmt, @_)); } " "sub CLOSE { my $me = shift; $me->PRINT('Closing '.$me); } " "sub DESTROY { my $me = shift; $me->PRINT('Destroying '.$me); } " //this ties us for all packages "package MAIN;" " if(tied *STDOUT) { untie(*STDOUT); }" " if(tied *STDERR) { untie(*STDERR); }" " tie *STDOUT, 'EQWIO';" " tie *STDERR, 'EQWIO';" ,FALSE); eval_pv( "package world; " ,FALSE ); //make sure the EQW pointer is set up in this package EQW *curc = EQW::Singleton(); SV *l = get_sv("world::EQW", true); if(curc != nullptr) { sv_setref_pv(l, "EQW", curc); } else { //clear out the value, mainly to get rid of blessedness sv_setsv(l, _empty_sv); } //make sure the EQDB pointer is set up in this package EQDB::SetMySQL(database.getMySQL()); EQDB *curc_db = EQDB::Singleton(); SV *l_db = get_sv("world::EQDB", true); if(curc_db != nullptr) { sv_setref_pv(l_db, "EQDB", curc_db); } else { //clear out the value, mainly to get rid of blessedness sv_setsv(l_db, _empty_sv); } //load up EQW eval_pv( "package EQW;" "&boot_EQW;" //load our EQW XS "package EQDB;" "&boot_EQDB;" //load our EQW XS "package EQDBRes;" "&boot_EQDBRes;" //load our EQW XS "package HTTPRequest;" "&boot_HTTPRequest;" //load our HTTPRequest XS "package EQLConfig;" "&boot_EQLConfig;" //load our EQLConfig XS , FALSE ); #ifdef EMBPERL_PLUGIN Log.Out(Logs::Detail, Logs::World_Server, "Loading worldui perl plugins."); std::string err; if(!eval_file("world", "worldui.pl", err)) { Log.Out(Logs::Detail, Logs::World_Server, "Warning - world.pl: %s", err.c_str()); } eval_pv( "package world; " "if(opendir(D,'worldui')) { " " my @d = readdir(D);" " closedir(D);" " foreach(@d){ " " next unless(/\\.pl$); " " require 'templates/'.$_;" " }" "}" ,FALSE); #endif //EMBPERL_PLUGIN }
/** To keep things simple options are parsed first then arguments like files, although some options take arguments immediately after them. A library for parsing command line options like *getopt* should be used, this would reduce the portability of the program. It is not recommended that arguments are parsed in this manner. **/ int main(int argc, char **argv) { FILE *in = NULL, *dump = NULL; int rval = 0, i = 1; int save = 0, /* attempt to save core if true */ eval = 0, /* have we evaluated anything? */ readterm = 0, /* read from standard in */ use_line_editor = 0, /* use a line editor, *if* one exists */ mset = 0; /* memory size specified */ enum forth_debug_level verbose = FORTH_DEBUG_OFF; /* verbosity level */ static const size_t kbpc = 1024 / sizeof(forth_cell_t); /*kilobytes per cell*/ static const char *dump_name = "forth.core"; char *optarg = NULL; forth_cell_t core_size = DEFAULT_CORE_SIZE; forth_t *o = NULL; int orig_argc = argc; char **orig_argv = argv; #ifdef _WIN32 /* unmess up Windows file descriptors: there is a warning about an * implicit declaration of _fileno when compiling under Windows in C99 * mode */ _setmode(_fileno(stdin), _O_BINARY); _setmode(_fileno(stdout), _O_BINARY); _setmode(_fileno(stderr), _O_BINARY); #endif /** This loop processes any options that may have been passed to the program, it looks for arguments beginning with '-' and attempts to process that option, if the argument does not start with '-' the option processing stops. It is a simple mechanism for processing program arguments and there are better ways of doing it (such as "getopt" and "getopts"), but by using them we sacrifice portability. **/ for(i = 1; i < argc && argv[i][0] == '-'; i++) { if(strlen(argv[i]) > 2) { fatal("Only one option allowed at a time (got %s)", argv[i]); goto fail; } switch(argv[i][1]) { case '\0': goto done; /* stop processing options */ case 'h': usage(argv[0]); help(); return -1; case 'L': use_line_editor = 1; /* XXX fall through */ case 't': readterm = 1; if(verbose >= FORTH_DEBUG_NOTE) note("stdin on. line editor %s", use_line_editor ? "on" : "off"); break; case 'u': return libforth_unit_tests(0, 0, 0); case 'e': if(i >= (argc - 1)) goto fail; forth_initial_enviroment(&o, core_size, stdin, stdout, verbose, orig_argc, orig_argv); optarg = argv[++i]; if(verbose >= FORTH_DEBUG_NOTE) note("evaluating '%s'", optarg); if(forth_eval(o, optarg) < 0) goto end; eval = 1; break; case 'f': if(i >= (argc - 1)) goto fail; forth_initial_enviroment(&o, core_size, stdin, stdout, verbose, orig_argc, orig_argv); optarg = argv[++i]; if(verbose >= FORTH_DEBUG_NOTE) note("reading from file '%s'", optarg); if(eval_file(o, optarg, verbose) < 0) goto end; break; case 's': if(i >= (argc - 1)) goto fail; dump_name = argv[++i]; /* XXX fall through */ case 'd': /*use default name */ if(verbose >= FORTH_DEBUG_NOTE) note("saving core file to '%s' (on exit)", dump_name); save = 1; break; case 'm': if(o || (i >= argc - 1) || forth_string_to_cell(10, &core_size, argv[++i])) goto fail; if((core_size *= kbpc) < MINIMUM_CORE_SIZE) { fatal("-m too small (minimum %zu)", MINIMUM_CORE_SIZE / kbpc); return -1; } if(verbose >= FORTH_DEBUG_NOTE) note("memory size set to %zu", core_size); mset = 1; break; case 'l': if(o || mset || (i >= argc - 1)) goto fail; optarg = argv[++i]; if(verbose >= FORTH_DEBUG_NOTE) note("loading core file '%s'", optarg); if(!(o = forth_load_core_file(dump = forth_fopen_or_die(optarg, "rb")))) { fatal("%s, core load failed", optarg); return -1; } forth_set_debug_level(o, verbose); fclose(dump); break; case 'v': verbose++; break; case 'V': version(); return EXIT_SUCCESS; break; default: fail: fatal("invalid argument '%s'", argv[i]); usage(argv[0]); return -1; } } done: /* if no files are given, read stdin */ readterm = (!eval && i == argc) || readterm; forth_initial_enviroment(&o, core_size, stdin, stdout, verbose, orig_argc, orig_argv); for(; i < argc; i++) /* process all files on command line */ if(eval_file(o, argv[i], verbose) < 0) goto end; if(readterm) { /* if '-t' or no files given, read from stdin */ if(verbose >= FORTH_DEBUG_NOTE) note("reading from stdin (%p)", stdin); #ifdef USE_LINE_EDITOR if(use_line_editor) { rval = forth_line_editor(o); goto end; } #endif forth_set_file_input(o, stdin); rval = forth_run(o); } end: fclose_input(&in); /** If the save option has been given we only want to save valid core files, we might want to make an option to force saving of core files for debugging purposes, but in general we do not want to over write valid previously saved state with invalid data. **/ if(save) { /* save core file */ if(rval || forth_is_invalid(o)) { fatal("refusing to save invalid core, %u/%d", rval, forth_is_invalid(o)); return -1; } if(verbose >= FORTH_DEBUG_NOTE) note("saving for file to '%s'", dump_name); if(forth_save_core_file(o, dump = forth_fopen_or_die(dump_name, "wb"))) { fatal("core file save to '%s' failed", dump_name); rval = -1; } fclose(dump); } /** Whilst the following **forth_free** is not strictly necessary, there is often a debate that comes up making short lived programs or programs whose memory use stays either constant or only goes up, when these programs exit it is not necessary to clean up the environment and in some case (although not this one) it can slow down the exit of the program for no reason. However not freeing the memory after use does not play nice with programs that detect memory leaks, like Valgrind. Either way, we free the memory used here, but only if no other errors have occurred before hand. **/ forth_free(o); return rval; }