message::transaction read_transaction( deserializer& deserial, message::transaction& packet) { packet.version = deserial.read_4_bytes(); uint64_t tx_in_count = deserial.read_variable_uint(); for (size_t tx_in_i = 0; tx_in_i < tx_in_count; ++tx_in_i) { message::transaction_input input; input.previous_output.hash = deserial.read_hash(); input.previous_output.index = deserial.read_4_bytes(); if (previous_output_is_null(input.previous_output)) input.input_script = coinbase_script(read_raw_script(deserial)); else input.input_script = read_script(deserial); input.sequence = deserial.read_4_bytes(); packet.inputs.push_back(input); } uint64_t tx_out_count = deserial.read_variable_uint(); for (size_t tx_out_i = 0; tx_out_i < tx_out_count; ++tx_out_i) { message::transaction_output output; output.value = deserial.read_8_bytes(); output.output_script = read_script(deserial); packet.outputs.push_back(output); } packet.locktime = deserial.read_4_bytes(); return packet; }
int parse_script_and_set_config(int argc, char *argv[], struct config *config, struct script *script, const char *script_path, const char *script_buffer) { struct invocation invocation = { .argc = argc, .argv = argv, .config = config, .script = script, }; DEBUGP("parse_and_run_script: %s\n", script_path); assert(script_path != NULL); init_script(script); set_default_config(config); config->script_path = strdup(script_path); if (script_buffer != NULL) copy_script(script_buffer, script); else read_script(script_path, script); return parse_script(config, script, &invocation); }
int main (int argc, char *argv[]) { printf("PROTO v%s%s (Kernel %s) (Developed by MIT Space-Time Programming Group 2005-2008)\n", PROTO_VERSION, "[opsim]", KERNEL_VERSION); Args *args = new Args(argc,argv); // set up the arg parser // define color palette #ifdef WANT_GLUT palette = Palette::default_palette; #endif //WANT_GLUT computer = new SpatialComputer(args,!test_mode); // then the computer int len = -1; if(args->argc <= 0) FATAL("Insufficient arguments"); uint8_t* s = read_script(args->argv[args->argc-1],&len); if(len > 0 && s != NULL) computer->load_script(s,len); cout << "DONE load_script." << endl; // and start! bool headless = args->extract_switch("-headless") || DEFAULT_HEADLESS; if(args->extract_switch("-stop-after")) stop_time = args->pop_number(); computer->is_dump = true; computer->is_debug = true; computer->dump_period = stop_time-1; if(headless) { if(stop_time==INFINITY) uerror("Headless runs must set an end time with -stop-after N"); while(1) idle(); } cout << "Exiting OPSIM." << endl; }
bash_ast::bash_ast(const std::istream& source, std::function<pANTLR3_BASE_TREE(plibbashParser)> p, bool trim): parse(p) { read_script(source, trim); init_parser("unknown source"); }
// ----------------------------------------------------------------------- void dbg_step() { struct evlb_t *bhit = NULL; if ((!dbg_enter) && (!(bhit=dbg_brk_check()))) { dbg_fin_cycle(); return; } dbg_loop_fin = 0; while (!dbg_loop_fin) { if (aw_layout_changed) { awin_tb_scroll_end(W_CMD); aw_layout_redo(); } else { aw_layout_refresh(); } if (script_name) { int sr = read_script(script_name); if (sr == INT_MIN) { awtbprint(W_CMD, C_ERROR, "Cannot open script file: %s\n", script_name); } else if (sr<0) { awtbprint(W_CMD, C_ERROR, "Error at line: %i\n", -sr); } else { awtbprint(W_CMD, C_LABEL, "Read %i line(s)\n", sr); } free(script_name); script_name = NULL; aw_layout_refresh(); } int res = aw_readline(W_CMD, C_PROMPT, "em400> ", input_buf, INPUT_BUF_SIZE); if ((res == KEY_ENTER) && (*input_buf)) { if (ui_mode == O_NCURSES) { awtbprint(W_CMD, C_PROMPT, "%s", "em400> "); awtbprint(W_CMD, C_LABEL, "%s\n", input_buf); awin_tb_scroll_end(W_CMD); } int len = strlen(input_buf); input_buf[len] = '\n'; input_buf[len+1] = '\0'; dbg_parse(input_buf); } else if (res == KEY_NPAGE) { awin_tb_scroll(W_CMD, 10); } else if (res == KEY_PPAGE) { awin_tb_scroll(W_CMD, -10); } } dbg_fin_cycle(); }
bash_ast::bash_ast(const std::string& script_path, std::function<pANTLR3_BASE_TREE(plibbashParser)> p, bool trim): parse(p) { std::stringstream stream; std::ifstream file_stream(script_path); if(!file_stream) throw libbash::parse_exception(script_path + " can't be read"); read_script(file_stream, trim); init_parser(script_path); }
void do_all(int argc, char * argv[]) { parse_args(argc, argv); text = read_script(file); if (!text) return; if (eval_shell(text)) return; if (write_C(file, argv)) return; if (make()) return; exit(0); }
int32 interpreter::load_script(char* script_name) { int32 error; int32 len = 0; byte* buffer = read_script(script_name, &len); if (!buffer) return OPERATION_FAIL; no_action++; error = luaL_loadbuffer(current_state, (const char*) buffer, len, (const char*) script_name) || lua_pcall(current_state, 0, 0, 0); if (error) { sprintf(pduel->strbuffer, lua_tostring(current_state, -1)); handle_message(pduel, 1); lua_pop(current_state, 1); no_action--; return OPERATION_FAIL; } no_action--; return OPERATION_SUCCESS; }
/*!***************************************************************************** ******************************************************************************* \note initialize \date January, 1994 \remarks initializes all necessary things ******************************************************************************* Function Parameters: [in]=input,[out]=output none ******************************************************************************/ void initialize(void) { int i,rc,ans=0; /* read script file */ rc=system("/bin/rm -f *.rf"); /* added -f, 1/30/00, Jorg Conradt */ /* so it doesn't complain about missing *.rf files */ read_script(); /* some general variable defaults */ last_nMSE = 1.e+10; n_iterations = 0; current_test_point = 0; }
int get_input_char(void) { if (is_script_executing()) { static struct key key; static int bytes_pos; if (!key.modifiers.multibytes || bytes_pos >= strlen(key.data.bytes)) { if (!read_script(&key)) return 0; bytes_pos = 0; } if (!key.modifiers.multibytes) { if (key.data.value < 128) return key.data.value; die("Only ASCII control characters can be used in prompts: %d", key.data.value); } return key.data.bytes[bytes_pos++]; } return getc(opt_tty); }
int main (int argc, char *argv[]) { post("PROTO v%s%s (%s) (Developed by MIT Space-Time Programming Group 2005-2008)\n", PROTO_VERSION, #if USE_NEOCOMPILER "[neo]", #else "[paleo]", #endif KERNEL_VERSION); Args *args = new Args(argc,argv); // set up the arg parser // initialize randomness [JAH: fmod added for OS X bug] unsigned int seed = (unsigned int) (args->extract_switch("-seed") ? args->pop_number() : fmod(get_real_secs()*1000, RAND_MAX)); post("Using random seed %d\n", seed); srand(seed); process_app_args(args); bool headless = args->extract_switch("-headless") || DEFAULT_HEADLESS; if(!headless) { vis = new Visualizer(args); // start visualizer } else { #ifdef WANT_GLUT palette = Palette::default_palette; #endif // WANT_GLUT } computer = new SpatialComputer(args,!test_mode); if(opcode_file != "") { post("reading opcodes from: %s\n", opcode_file.c_str()); // read from file int len = -1; uint8_t* s = read_script(opcode_file,&len); //post("script[%d]=\n",len); //for(unsigned int i=0; i<len; ++i) // post("%d\n", s[i]); if(len > 0 && s != NULL) { computer->load_script(s,len); } else uerror("Problem loading opcode file: %s", opcode_file.c_str()); if(!headless) { vis->set_bounds(computer->vis_volume); // connect to computer register_app_colors(); } } else { // use a compiler #if USE_NEOCOMPILER compiler = new NeoCompiler(args); // first the compiler compiler->emitter = new ProtoKernelEmitter(compiler,args); #else compiler = new PaleoCompiler(args); // first the compiler #endif string defops; computer->appendDefops(defops); compiler->setDefops(defops); if(!headless) { vis->set_bounds(computer->vis_volume); // connect to computer register_app_colors(); } // next the forwarder for the motes, if desired if(args->extract_switch("-motelink")) motelink = new MoteLink(args); // load the script int len; if(args->argc==1) { uerror("No program specified: all arguments consumed."); } else { uint8_t* s = compiler->compile(args->argv[args->argc-1],&len); computer->load_script(s,len); if(args->argc>2) { post("WARNING: %d unhandled arguments:",args->argc-2); for(int i=2;i<args->argc;i++) post(" '%s'",args->argv[i-1]); post("\n"); } } } // if in test mode, swap the C++ file for a C file for the SpatialComputer if(test_mode) { delete cpout; computer->dump_file = fopen(dump_name,"a"); } // and start! if(headless) { if(stop_time==INFINITY) uerror("Headless runs must set an end time with -stop-after N"); while(1) idle(); } else { #ifdef WANT_GLUT // set up callbacks for user interface and idle glutMouseFunc(on_mouse_button); glutMotionFunc(on_mouse_motion); glutPassiveMotionFunc(on_mouse_motion); glutDisplayFunc(render); glutReshapeFunc(resize); glutIdleFunc(idle); glutKeyboardFunc(keyboard_handler); glutSpecialFunc(special_handler); // finally, hand off control to the glut event-loop glutMainLoop(); #endif } }
int logtools_read_logfile( logtools_log_data_t * rec, char * filename ) { enum logtools_file_t inp_type = UNKOWN; char fname[MAX_NAME_LENGTH]; fprintf( stderr, "#####################################################################\n" ); if ( !fnmatch( "script:*", filename, 0) ) { fprintf( stderr, "# INFO: use script-file-type!\n" ); strncpy( fname, &(filename[7]), MAX_NAME_LENGTH ); inp_type = SCRIPT; } else if ( !fnmatch( "rec:*", filename, 0) ) { fprintf( stderr, "# INFO: read rec-file-type!\n" ); strncpy( fname, &(filename[4]), MAX_NAME_LENGTH ); inp_type = REC; } else if ( !fnmatch( "carmen:*", filename, 0) ) { fprintf( stderr, "# INFO: read carmen-file-type!\n" ); strncpy( fname, &(filename[7]), MAX_NAME_LENGTH ); inp_type = CARMEN; } else if ( !fnmatch( "moos:*", filename, 0) ) { fprintf( stderr, "# INFO: read moos-file-type!\n" ); strncpy( fname, &(filename[5]), MAX_NAME_LENGTH ); inp_type = MOOS; } else if ( !fnmatch( "player:*", filename, 0) ) { fprintf( stderr, "# INFO: read player-file-type!\n" ); strncpy( fname, &(filename[7]), MAX_NAME_LENGTH ); inp_type = PLAYER; } else if ( !fnmatch( "placelab:*", filename, 0) ) { fprintf( stderr, "# INFO: read placelab-file-type!\n" ); strncpy( fname, &(filename[9]), MAX_NAME_LENGTH ); inp_type = PLACELAB; } else if ( !fnmatch( "plab:*", filename, 0) ) { fprintf( stderr, "# INFO: read placelab-file-type!\n" ); strncpy( fname, &(filename[5]), MAX_NAME_LENGTH ); inp_type = PLACELAB; } else if ( !fnmatch( "*" FILE_SCRIPT_EXT, filename, 0) ) { fprintf( stderr, "# INFO: use script-file-type!\n" ); strncpy( fname, filename, MAX_NAME_LENGTH ); inp_type = SCRIPT; } else if ( !fnmatch( "*" FILE_REC_EXT, filename, 0) ) { fprintf( stderr, "# INFO: read rec-file-type!\n" ); strncpy( fname, filename, MAX_NAME_LENGTH ); inp_type = REC; } else if ( !fnmatch( "*"FILE_CARMEN_EXT, filename, 0) ) { fprintf( stderr, "# INFO: read carmen-file-type!\n" ); strncpy( fname, filename, MAX_NAME_LENGTH ); inp_type = CARMEN; } else if ( !fnmatch( "*" FILE_MOOS_EXT, filename, 0) ) { fprintf( stderr, "# INFO: read moos-file-type!\n" ); strncpy( fname, filename, MAX_NAME_LENGTH ); inp_type = MOOS; } else if ( !fnmatch( "*" FILE_PLAYER_EXT, filename, 0) ) { fprintf( stderr, "# INFO: read player-file-type!\n" ); strncpy( fname, filename, MAX_NAME_LENGTH ); inp_type = PLAYER; } else if ( !fnmatch( "*" FILE_PLACELAB_EXT, filename, 0) ) { fprintf( stderr, "# INFO: read placelab-file-type!\n" ); strncpy( fname, filename, MAX_NAME_LENGTH ); inp_type = PLACELAB; } else if ( !fnmatch( "*" FILE_SAPHIRA_EXT, filename, 0) ) { fprintf( stderr, "# INFO: read saphira-file-type!\n" ); strncpy( fname, filename, MAX_NAME_LENGTH ); inp_type = SAPHIRA; } else { fprintf( stderr, "# INFO: read carmen-file-type!\n" ); strncpy( fname, filename, MAX_NAME_LENGTH ); inp_type = CARMEN; } switch (inp_type) { case SCRIPT: if (read_script( fname, rec, 1 ) !=0 ) return(FALSE); break; case REC: if (load_rec2d_file( fname, rec, REC, READ_MODE_DONT_STOP ) !=0 ) return(FALSE); break; case CARMEN: if (load_rec2d_file( fname, rec, CARMEN, READ_MODE_DONT_STOP ) !=0 ) return(FALSE); break; case MOOS: if (load_rec2d_file( fname, rec, MOOS, READ_MODE_DONT_STOP ) !=0 ) return(FALSE); break; case PLAYER: if (load_rec2d_file( fname, rec, PLAYER, READ_MODE_DONT_STOP ) !=0 ) return(FALSE); break; case SAPHIRA: if (load_rec2d_file( fname, rec, SAPHIRA, READ_MODE_DONT_STOP ) !=0 ) return(FALSE); break; case PLACELAB: if (load_rec2d_file( fname, rec, PLACELAB, READ_MODE_DONT_STOP ) !=0 ) return(FALSE); break; default: fprintf( stderr, "ERROR: unknown file-type!\n" ); return(FALSE); } return(TRUE); }