void Theme::init_interpreter(void) { if(priv->sc) return; scheme *ss = edelib_scheme_init_raw(); if(!ss) { E_WARNING(E_STRLOC ": Unable to init interpreter\n"); return; } priv->sc = ss; /* must be called */ scheme_set_input_port_file(ss, stdin); scheme_set_output_port_file(ss, stdout); /* install user supplied error handler first, if given */ if(priv->err_func) { ss->vptr->scheme_define(ss, ss->global_env, ss->vptr->mk_symbol(ss, "private:theme.error_hook"), ss->vptr->mk_foreign_func(ss, theme_error_hook)); /* make sure interpreter does not use this function at all */ scheme_set_external_data(ss, (void*)priv); } /* load init stuff */ scheme_load_string(ss, init_ss_content); /* load theme stuff */ scheme_load_string(ss, theme_ss_content); /* * Set (or override) common variables before actual script was loaded. * Variables are static and can't be changed. */ pointer sym; sym = mk_symbol(ss, "*edelib-dir-separator*"); scheme_define(ss, ss->global_env, sym, mk_string(ss, E_DIR_SEPARATOR_STR)); ss->vptr->setimmutable(sym); sym = mk_symbol(ss, "*edelib-version*"); scheme_define(ss, ss->global_env, sym, mk_string(ss, EDELIB_VERSION)); ss->vptr->setimmutable(sym); }
void ShellService::ExecuteCommand(const std::string& cmd) { std::size_t pos = cmd.find_first_not_of(' '); if (pos == std::string::npos) return; std::string command = cmd.substr(pos); if (command[0] != '(') { command = "(" + command + ")"; } scheme_load_string(d->m_Scheme, command.c_str()); }
void ShellService::LoadSchemeResource(const BundleResource& res) { std::cout << "Reading " << res.GetResourcePath(); BundleResourceStream resStream(res); int resBufLen = res.GetSize() + 1; char* resBuf = new char[resBufLen]; resStream.read(resBuf, resBufLen); if (resStream.eof() || resStream.good()) { resBuf[static_cast<std::size_t>(resStream.gcount())] = '\0'; scheme_load_string(d->m_Scheme, resBuf); } else { std::cerr << "Could not read " << res.GetResourcePath() << " file from resource"; } delete[] resBuf; }
int main(int argc, char **argv) { FILE *fin = NULL; const char *expr = NULL; scheme sc; if(argc > 1) { if(argv[1][0] == '-') { if((strcmp(argv[1], "--help") == 0) || (strcmp(argv[1], "-h") == 0)) { help(); return 0; } else if((strcmp(argv[1], "--expression") == 0) || (strcmp(argv[1], "-e") == 0)) { if(!argv[2]) { printf("This option requires a parameter\n"); return 1; } expr = argv[2]; } else { printf("Unrecognized option. Use 'ede-scriptbus --help' for options\n"); return 1; } } if(!expr) { fin = fopen(argv[1], "r"); if(!fin) { fprintf(stderr, "Unable to load '%s' file!\n", argv[1]); return 1; } } } if(!scheme_init(&sc)) { fprintf(stderr, "Fatal: Unable to initialize interpreter!\n"); return 1; } scheme_set_input_port_file(&sc, stdin); scheme_set_output_port_file(&sc, stdout); /* load basic stuff */ scheme_load_string(&sc, init_scm_content); /* register additional functions */ register_sys_functions(&sc); register_communication_functions(&sc); register_string_functions(&sc); register_wm_functions(&sc); /* construct *args* */ pointer args = sc.NIL; for(int i = 0; i < argc; i++) { pointer value = mk_string(&sc, argv[i]); args = cons(&sc, value, args); } args = scheme_reverse(&sc, args); scheme_define(&sc, sc.global_env, mk_symbol(&sc, "*args*"), args); if(!expr) { /* load file or go into console */ if(!fin) { fin = stdin; printf("Type '(quit)' or press Ctrl-D to quit"); } scheme_load_file(&sc, fin); } else { /* or execute expression */ scheme_load_string(&sc, expr); if(sc.retcode != 0) printf("Bad expression: '%s'\n", expr); } scheme_deinit(&sc); return 0; }
int main(int argc, char **argv) { scheme sc; FILE *fin; char *file_name = INITFILE; int isfile = 1; if (argc == 1) { printf(BANNER); } if (argc == 2 && strcmp(argv[1], "-?") == 0) { usage(); return 1; } if (!scheme_init(&sc)) { fprintf(stderr, "Could not initialize!\n"); return 2; } scheme_set_input_port_file(&sc, stdin); scheme_set_output_port_file(&sc, stdout); #if USE_DL scheme_define(&sc, sc.global_env, mk_symbol(&sc, "load-extension"), mk_foreign_func(&sc, scm_load_ext)); #endif argv++; if (access(file_name, 0) != 0) { char *p = getenv("TINYSCHEMEINIT"); if (p != 0) { file_name = p; } } do { if (strcmp(file_name, "-") == 0) { fin = stdin; } else if (strcmp(file_name, "-1") == 0 || strcmp(file_name, "-c") == 0) { pointer args = sc.NIL; isfile = file_name[1] == '1'; file_name = *argv++; if (strcmp(file_name, "-") == 0) { fin = stdin; } else if (isfile) { fin = fopen(file_name, "r"); } for (; *argv; argv++) { pointer value = mk_string(&sc, *argv); args = cons(&sc, value, args); } args = reverse_in_place(&sc, sc.NIL, args); scheme_define(&sc, sc.global_env, mk_symbol(&sc, "*args*"), args); } else { fin = fopen(file_name, "r"); } if (isfile && fin == 0) { fprintf(stderr, "Could not open file %s\n", file_name); } else { if (isfile) { scheme_load_named_file(&sc, fin, file_name); } else { scheme_load_string(&sc, file_name); } if (!isfile || fin != stdin) { if (sc.retcode != 0) { fprintf(stderr, "Errors encountered reading %s\n", file_name); } if (isfile) { fclose(fin); } } } file_name = *argv++; } while (file_name != 0); if (argc == 1) { scheme_load_named_file(&sc, stdin, 0); } scheme_deinit(&sc); return sc.retcode; }
scheme* scheme_get_interp(void * p) { scheme * sc = queue_get(&interp_queue); sc->ext_data = p; scheme_load_string(sc,scheme_init_code); return sc; }