static void continue_action (Widget w, XtPointer client_data, XtPointer call_data) { Widget dialog = (Widget) client_data; XtPopdown (XtParent (dialog)); destroy_popup_prompt (NULL, (XtPointer) dialog, (XtPointer) NULL); continue_popup = NULL; execute_program (PC, 1, 0, 1); /* Step over breakpoint */ execute_program (PC, DEFAULT_RUN_STEPS - 1, 0, 0); }
int main(int argc, char *argv[], char *envp[]) { time_t t; time(&t); #ifdef DEBUG g_stream = fopen("exec_process.log", "w"); setvbuf(g_stream, (char *) NULL, _IONBF, 0); #endif printf("Welcome - %s \n", ctime(&t)); char *args[3] = {"./add", "Rajendra", NULL}; char *input[3]= {"20", "30"}; char *output = NULL; execute_program(args[0], args, envp, 2, input, &output); /* char *args[4]= {"/bin/ls", "-al", NULL}; char *output = NULL; execute_program(args[0], args, envp, 0, NULL, &output); */ printf("Executed program %s\nOutput:\n%s", args[0], output); free(output); #ifdef DEBUG fclose(g_stream); #endif return 0; }
int main(int argc, char* argv[]) { std::string program = "" "parent(great_grandad, nana).\n" "parent(great_nana, nana).\n" "parent(great_pop, grandad).\n" "parent(great_grandma, grandad).\n" "parent(grandad, dad).\n" "parent(nana, dad).\n" "parent(grandad, uncle).\n" "parent(nana, uncle).\n" "parent(dad, miss).\n" "parent(dad, master).\n" "ancestor(X, Y) :- parent(X, Y).\n" "ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).\n" ; runtime rt; std::stringstream ssprogram(program); parser p; execute_program(p.parse_program(ssprogram), rt); rt.dump_program(); run_predicate("ancestor(dad,B)", rt); enumerate_predicate("ancestor(Ancestor, master)", rt); return 0; }
int main() { Mem mem[SZ]; short registers[NUM_REGISTERS]= {0, 11, 9, 7, 5, 2, 0, 0}; short exp_registers[NUM_REGISTERS]= {0, 0, 1, 1, 1, 5}; int num_instructions; Status ret; num_instructions= assemble("public03.a", mem); if (num_instructions == 0) printf("Regretfully the program couldn't be assembled. Bye.\n"); else { ret= execute_program(mem, registers, 0, num_instructions, 0); if (ret != ACTIVE) /* because there's no halt instruction */ printf("execute_program() returned unexpected value (%d).\n", ret); else if ((ret= compare_registers(registers, exp_registers, 1, 5)) != -1) { printf("Registers appear incorrect after execute_program() call.\n"); printf("First incorrect register is %d (%d instead of %d).\n", ret, registers[ret], exp_registers[ret]); } else printf("Registers are correct after execute_program() call!\n"); } return 0; }
int main(int argc, char ** argv) { arena_init(); init_lexer(); execute_program(parse_program()); return 0; }
int main() { Mem mem[SZ]= {0}; short registers[NUM_REGISTERS]= {0}; short exp_registers[NUM_REGISTERS]= {0, 3, 5, 9, 14, 4, 0xfe, 0xa}; int num_instructions; Status ret; num_instructions= assemble("public12.a", &mem[10]); if (num_instructions == 0) printf("Regretfully the program couldn't be assembled. Bye.\n"); else { ret= execute_program(mem, registers, 20, num_instructions, 0); if (ret != TERMINATED) printf("execute_program() returned unexpected value (%d).\n", ret); else if ((ret= compare_registers(registers, exp_registers, 0, 8)) != -1) { printf("Registers appear incorrect after execute_program() call.\n"); printf("First incorrect register is %d (%d instead of %d).\n", ret, registers[ret], exp_registers[ret]); } else printf("Registers are correct after execute_program() call!\n"); } return 0; }
void ltrace_init(int argc, char **argv) { struct opt_p_t *opt_p_tmp; atexit(normal_exit); signal(SIGINT, signal_exit); /* Detach processes when interrupted */ signal(SIGTERM, signal_exit); /* ... or killed */ argv = process_options(argc, argv); init_global_config(); while (opt_F) { /* If filename begins with ~, expand it to the user's home */ /* directory. This does not correctly handle ~yoda, but that */ /* isn't as bad as it seems because the shell will normally */ /* be doing the expansion for us; only the hardcoded */ /* ~/.ltrace.conf should ever use this code. */ if (opt_F->filename[0] == '~') { char path[PATH_MAX]; char *home_dir = getenv("HOME"); if (home_dir) { strncpy(path, home_dir, PATH_MAX - 1); path[PATH_MAX - 1] = '\0'; strncat(path, opt_F->filename + 1, PATH_MAX - strlen(path) - 1); read_config_file(path); } } else { read_config_file(opt_F->filename); } struct opt_F_t *next = opt_F->next; if (opt_F->own_filename) free(opt_F->filename); free(opt_F); opt_F = next; } if (command) { /* Check that the binary ABI is supported before * calling execute_program. */ struct ltelf lte = {}; open_elf(<e, command); do_close_elf(<e); pid_t pid = execute_program(command, argv); struct Process *proc = open_program(command, pid); if (proc == NULL) { fprintf(stderr, "couldn't open program '%s': %s\n", command, strerror(errno)); exit(EXIT_FAILURE); } trace_set_options(proc); continue_process(pid); } opt_p_tmp = opt_p; while (opt_p_tmp) { open_pid(opt_p_tmp->pid); opt_p_tmp = opt_p_tmp->next; } }
int main(int argc, char *argv[]) { parse_command_line(argc, argv); yyin = fopen(input_file, "r"); if (!yyin) die_err("can not open input file"); if (translate_flag) { yyout = fopen(translate_file, "w"); if (!yyout) die_err("can not open translate file"); } else { int fd = mkstemp(temp_file); if (fd < 0) die_err("mkstemp() failed"); yyout = fdopen(fd, "w"); if (!yyout) die_err("can not open temporary file"); } if (yyparse() != 0) die("Parsing failed."); if (typeCheckingFail) die("Sorry, type checking failed."); fclose(yyin); fclose(yyout); /* code formatting */ if (translate_flag) strcpy(format_file, translate_file); else strcpy(format_file, temp_file); execute_program(ASTYLE_OPTIONS); /* invoking g++ */ if (!translate_flag) execute_program(CXX_OPTIONS); return 0; }
static void step_continue_action (Widget w, XtPointer client_data, XtPointer call_data) { Widget dialog = (Widget) client_data; XtPopdown (XtParent (dialog)); destroy_popup_prompt (NULL, (XtPointer) dialog, (XtPointer) NULL); step_popup = NULL; execute_program (PC, DEFAULT_RUN_STEPS, 0, 0); }
void ltrace_init(int argc, char **argv) { struct opt_p_t *opt_p_tmp; #ifdef HAVE_PYTHON Py_Initialize(); #endif atexit(normal_exit); signal(SIGINT, signal_exit); /* Detach processes when interrupted */ signal(SIGTERM, signal_exit); /* ... or killed */ argv = process_options(argc, argv); while (opt_F) { /* If filename begins with ~, expand it to the user's home */ /* directory. This does not correctly handle ~yoda, but that */ /* isn't as bad as it seems because the shell will normally */ /* be doing the expansion for us; only the hardcoded */ /* ~/.ltrace.conf should ever use this code. */ if (opt_F->filename[0] == '~') { char path[PATH_MAX]; char *home_dir = getenv("HOME"); if (home_dir) { strncpy(path, home_dir, PATH_MAX - 1); path[PATH_MAX - 1] = '\0'; strncat(path, opt_F->filename + 1, PATH_MAX - strlen(path) - 1); read_config_file(path); } } else { read_config_file(opt_F->filename); } opt_F = opt_F->next; } if (opt_e) { struct opt_e_t *tmp = opt_e; while (tmp) { debug(1, "Option -e: %s\n", tmp->name); tmp = tmp->next; } } if (command) { /* Check that the binary ABI is supported before * calling execute_program. */ struct ltelf lte = {}; open_elf(<e, command); open_program(command, execute_program(command, argv), 0); } opt_p_tmp = opt_p; while (opt_p_tmp) { open_pid(opt_p_tmp->pid); opt_p_tmp = opt_p_tmp->next; } }
void enter_program(uint8_t number) { // If the program has not changed, do nothing if (current_program.number == number) { return; } // Load program and execute program current_program.number = number; current_program.data = read_program_data(number); execute_program(current_program.data); }
int main(int argc, char** argv) { for (int n=1; n<argc; ++n) { Lua_State L; open_libs(L); int s = luaL_loadfile(L, argv[n]); if (s==0) s = execute_program(L); report_errors(L, s); // lua_close(L) automatically called here } return 0; }
static int oncore(int argc, char *argv[]) { if(argc < 3) { printf("Usage: %s <core id> <program> [args]\n", argv[0]); return 1; } int core = atoi(argv[1]); argc -= 2; argv += 2; domainid_t domain_id; int ret = execute_program(core, argc, argv, &domain_id); // TODO: do something with domain_id return ret; }
void ltrace_init(int argc, char **argv) { setlocale(LC_ALL, ""); struct opt_p_t *opt_p_tmp; atexit(normal_exit); signal(SIGINT, signal_exit); /* Detach processes when interrupted */ signal(SIGTERM, signal_exit); /* ... or killed */ argv = process_options(argc, argv); init_global_config(); if (command) { /* Check that the binary ABI is supported before * calling execute_program. */ { struct ltelf lte; if (ltelf_init(<e, command) == 0) ltelf_destroy(<e); else exit(EXIT_FAILURE); } pid_t pid = execute_program(command, argv); struct process *proc = open_program(command, pid); if (proc == NULL) { fprintf(stderr, "couldn't open program '%s': %s\n", command, strerror(errno)); exit(EXIT_FAILURE); } trace_set_options(proc); continue_process(pid); } opt_p_tmp = opt_p; while (opt_p_tmp) { open_pid(opt_p_tmp->pid); opt_p_tmp = opt_p_tmp->next; } }
int main(int argc, char* argv[]) { if (argc < 2){ printf("\nUsage: %s <brainfuck-code.txt>\n", argv[0]); free_memory(); exit(EXIT_FAILURE); } clean_memory(); reset_pointer(); load_program(argv[1]); if (!is_balanced(program, program_size)){ printf("ERROR: Unbalanced brackets found in the supplied Brainfuck code.\n"); free_memory(); exit(EXIT_FAILURE); } execute_program(); free_memory(); return 0; }
static void step_program_action (Widget w, XtPointer client_data, XtPointer call_data) { Arg args[10]; String st; mem_addr addr; int steps; XtSetArg (args[0], XtNstring, &st); XtGetValues (step_field1_text, args, ONE); steps = atoi (st); free (step_size); step_size = str_copy (st); addr = starting_address (); if (steps > 0 && addr > 0) execute_program (addr, steps, 1, 1); else error ("Cannot step %d steps from 0x%x\n", steps, addr); }
int main(int argc, char* argv[]) { int input_len; char *code; bool code_ok; code = argv[1]; code_ok = validate_code_input(code); if (!code_ok) { exit(EXIT_FAILURE); } // This does it for both code length and program length input_len = strlen(code); cmd_t *program = parse_code(argv[1], input_len); execute_program(program, input_len); return 0; }
void run_program(char** instructions, int n_instructions, var** input_variables, int n_inputs, var** temp_variables, int n_temps, var** output_variables, int n_outputs) { var** vars = (var **) malloc(256 * sizeof(var *)); vars['0'] = new_var('0', 0); vars['1'] = new_var('1', 1); int i; for (i = 0; i < n_inputs; i++) { vars[(int) (input_variables[i] -> name)] = input_variables[i]; } for (i = 0; i < n_temps; i++) { vars[(int) (temp_variables[i] -> name)] = temp_variables[i]; } for (i = 0; i < n_outputs; i++) { vars[(int) (output_variables[i] -> name)] = output_variables[i]; } execute_program(instructions, n_instructions, vars); print_output(output_variables, n_outputs); }
void execute_config(const char* path) { FILE* config = fopen(path, "r"); if(!config) { LOG("Could not open config file!"); while(1) sleep(1000); } char* content; fseek(config, 0, SEEK_END); size_t sz = ftell(config); fseek(config, 0, SEEK_SET); content = (char*) malloc(sz+1); fread(content, sz, 1, config); char* p = strtok(content, "\n"); while(p != NULL) { if(!strcmp(p, "delay")) { sleep(250); } else if(strcmp(p, "")) { LOG(p); if(!execute_program(p, 0, NULL)) LOG_STRING("Could not execute program", p); } p = strtok(NULL, "\n"); } fclose(config); free(content); }
/** * Main loop. Handles the following: * - Input from STDIN. * - Messages from programs. * - Packets from the socket. * - Timeouts. */ void do_loop() { char buf[MAX_PACKET_SIZE]; conn_t *conn = NULL; while (true) { memset(buf, 0, MAX_PACKET_SIZE); poll(events, NUM_POLL + num_connected, need_timer_in(&last_timeout, ctcp_cfg->timer)); /* Input from stdin. Server will only send to most-recently connected client. */ if (!run_program && events[STDIN_FILENO].revents & POLLIN) { conn = get_connections(); if (conn != NULL) ctcp_read(conn->state); } /* See if we can output more. */ if (events[STDOUT_FILENO].revents & (POLLOUT | POLLHUP | POLLERR)) { for (conn = get_connections(); conn; conn = conn->next) { conn_drain(conn); } } /* Poll for output received from running programs. Send to client client associated with this program instance. */ if (run_program) { conn = get_connections(); while (conn != NULL) { if (conn->poll_fd->revents & POLLIN) { ctcp_read(conn->state); } conn = conn->next; } } /* Receive packet on socket from other hosts. Ignore packets if they are not large enough or not for us. */ if (events[2].revents & POLLIN) { conn = NULL; int len = recv_filter(config->socket, buf, MAX_PACKET_SIZE, 0, &conn); if (len >= FULL_HDR_SIZE) { tcphdr_t *tcp_hdr = (tcphdr_t *) (buf + IP_HDR_SIZE); /* Packet from an established connection. Pass to student code. */ if (conn != NULL) { ctcp_segment_t *segment = convert_to_ctcp(conn, buf, len); len = len - FULL_HDR_SIZE + sizeof(ctcp_segment_t); /* Don't log or forward to student code if it's an ACK from a new connection. */ if (tcp_hdr->th_sport == new_connection && (segment->flags & TH_ACK) && ntohl(segment->seqno) == 1 && ntohl(segment->ackno) == 1) { new_connection = 0; free(segment); } else { if (log_file != -1 || test_debug_on) { log_segment(log_file, config->ip_addr, config->port, conn, segment, len, false, unix_socket); } ctcp_receive(conn->state, segment, len); } } /* New connection. */ else if (tcp_hdr->th_flags & TH_SYN) { conn_t *conn = tcp_new_connection(buf); /* Start a new program associated with this client. */ if (run_program && conn) execute_program(conn); new_connection = tcp_hdr->th_sport; } } } /* Check if timer is up. */ if (need_timer_in(&last_timeout, ctcp_cfg->timer) == 0) { ctcp_timer(); get_time(&last_timeout); } /* Delete connections if needed. */ delete_all_connections(); } }
int main(int argc, const char *argv[]) { char input[MAX_LINE]; int exitcode = 0; bool is_bootscript = true; coreid_t my_core_id = disp_get_core_id(); // XXX: parse aguments to determine input sources to use unsigned stdin_sources = 0; vfs_init(); for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "serial") == 0) { stdin_sources |= TERMINAL_SOURCE_SERIAL; } else if (strcmp(argv[i], "keyboard") == 0) { stdin_sources |= TERMINAL_SOURCE_KEYBOARD; } else if (strcmp(argv[i], "nobootscript") == 0) { is_bootscript = false; } } // fallback default: use serial, as before if (stdin_sources == 0) { stdin_sources = TERMINAL_SOURCE_SERIAL; } // XXX: All the following calls should go away once we have stable APIs errval_t e = terminal_want_stdin(stdin_sources); assert(err_is_ok(e)); cwd = strdup("/"); printf("fish v0.2 -- pleased to meet you!\n"); // run canned pre-boot commands if(is_bootscript) { runbootscript(); } for(;;) { int cmd_argc; char *cmd_argv[64]; // Support a max of 64 cmd args struct cmd *cmd; printf("> "); fflush(stdout); getline(input, MAX_LINE); cmd_argc = makeargs(input, cmd_argv); /* check for trailing '&' (== run in background) */ bool wait = true; if (cmd_argc > 0) { size_t len = strlen(cmd_argv[cmd_argc - 1]); if (len > 0 && cmd_argv[cmd_argc - 1][len - 1] == '&') { wait = false; // remove '&' character from args if (len == 1) { cmd_argc--; } else { cmd_argv[cmd_argc - 1][len - 1] = '\0'; } } } if (cmd_argc == 0) { continue; } else if ((cmd = find_command(cmd_argv[0])) != NULL) { exitcode = cmd->cmd(cmd_argc, cmd_argv); } else { // Try loading a program off disk if VFS is initialized domainid_t domain_id; exitcode = execute_program(my_core_id, cmd_argc, cmd_argv, &domain_id); // wait if it succeeds if(exitcode == 0 && wait) { exitcode = wait_domain_id(domain_id); char exitstr[128]; snprintf(exitstr, 128, "%u", exitcode); int r = setenv("EXITCODE", exitstr, 1); assert(r == 0); // Reacquire terminal for stdin e = terminal_want_stdin(stdin_sources); assert(err_is_ok(e)); } } } }
void execute_program(std::string fname, std::string args, bool wait) { execute_program("open", fname, args, wait); }
/** * NOTE: The technique is not the same as that used in TinyVM. * The return value indicates the impact of the call on the VM * system. EXEC_CONTINUE normal return the system should return to the return * address provided by the VM. EXEC_RUN The call has modified the value of * VM PC and this should be used to restart execution. EXEC_RETRY The call * needs to be re-tried (typically for a GC failure), all global state * should be left intact, the PC has been set appropriately. * */ int dispatch_native(TWOBYTES signature, STACKWORD * paramBase) { STACKWORD p0 = paramBase[0]; switch (signature) { case wait_4_5V: return monitor_wait((Object *) word2ptr(p0), 0); case wait_4J_5V: return monitor_wait((Object *) word2ptr(p0), ((int)paramBase[1] > 0 ? 0x7fffffff : paramBase[2])); case notify_4_5V: return monitor_notify((Object *) word2ptr(p0), false); case notifyAll_4_5V: return monitor_notify((Object *) word2ptr(p0), true); case start_4_5V: // Create thread, allow for instruction restart return init_thread((Thread *) word2ptr(p0)); case yield_4_5V: schedule_request(REQUEST_SWITCH_THREAD); break; case sleep_4J_5V: sleep_thread(((int)p0 > 0 ? 0x7fffffff : paramBase[1])); schedule_request(REQUEST_SWITCH_THREAD); break; case getPriority_4_5I: push_word(get_thread_priority((Thread *) word2ptr(p0))); break; case setPriority_4I_5V: { STACKWORD p = (STACKWORD) paramBase[1]; if (p > MAX_PRIORITY || p < MIN_PRIORITY) return throw_new_exception(JAVA_LANG_ILLEGALARGUMENTEXCEPTION); else set_thread_priority((Thread *) word2ptr(p0), p); } break; case currentThread_4_5Ljava_3lang_3Thread_2: push_ref(ptr2ref(currentThread)); break; case interrupt_4_5V: interrupt_thread((Thread *) word2ptr(p0)); break; case interrupted_4_5Z: { JBYTE i = currentThread->interruptState != INTERRUPT_CLEARED; currentThread->interruptState = INTERRUPT_CLEARED; push_word(i); } break; case isInterrupted_4_5Z: push_word(((Thread *) word2ptr(p0))->interruptState != INTERRUPT_CLEARED); break; case join_4_5V: join_thread((Thread *) word2ptr(p0), 0); break; case join_4J_5V: join_thread((Thread *) word2obj(p0), paramBase[2]); break; case halt_4I_5V: schedule_request(REQUEST_EXIT); break; case shutdown_4_5V: shutdown_program(false); break; case currentTimeMillis_4_5J: push_word(0); push_word(systick_get_ms()); break; case readSensorValue_4I_5I: push_word(sp_read(p0, SP_ANA)); break; case setPowerTypeById_4II_5V: sp_set_power(p0, paramBase[1]); break; case freeMemory_4_5J: push_word(0); push_word(getHeapFree()); break; case totalMemory_4_5J: push_word(0); push_word(getHeapSize()); break; case floatToRawIntBits_4F_5I: // Fall through case intBitsToFloat_4I_5F: push_word(p0); break; case doubleToRawLongBits_4D_5J: // Fall through case longBitsToDouble_4J_5D: push_word(p0); push_word(paramBase[1]); break; case drawString_4Ljava_3lang_3String_2II_5V: { String *p = (String *)word2obj(p0); Object *charArray; if (!p) return throw_new_exception(JAVA_LANG_NULLPOINTEREXCEPTION); charArray = (Object *) word2ptr(get_word_4_ns(fields_start(p))); if (!charArray) return throw_new_exception(JAVA_LANG_NULLPOINTEREXCEPTION); display_goto_xy(paramBase[1], paramBase[2]); display_jstring(p); } break; case drawInt_4III_5V: display_goto_xy(paramBase[1], paramBase[2]); display_int(p0, 0); break; case drawInt_4IIII_5V: display_goto_xy(paramBase[2], paramBase[3]); display_int(p0, paramBase[1]); break; case asyncRefresh_4_5V: display_update(); break; case clear_4_5V: display_clear(0); break; case getDisplay_4_5_1B: push_word(display_get_array()); break; case setAutoRefreshPeriod_4I_5I: push_word(display_set_auto_update_period(p0)); break; case getRefreshCompleteTime_4_5I: push_word(display_get_update_complete_time()); break; case bitBlt_4_1BIIII_1BIIIIIII_5V: { Object *src = word2ptr(p0); Object *dst = word2ptr(paramBase[5]); display_bitblt((byte *)(src != NULL ?jbyte_array(src):NULL), paramBase[1], paramBase[2], paramBase[3], paramBase[4], (byte *)(dst!=NULL?jbyte_array(dst):NULL), paramBase[6], paramBase[7], paramBase[8], paramBase[9], paramBase[10], paramBase[11], paramBase[12]); break; } case getSystemFont_4_5_1B: push_word(display_get_font()); break; case setContrast_4I_5V: nxt_lcd_set_pot(p0); break; case getBatteryStatus_4_5I: push_word(battery_voltage()); break; case getButtons_4_5I: push_word(buttons_get()); break; case getTachoCountById_4I_5I: push_word(nxt_motor_get_count(p0)); break; case controlMotorById_4III_5V: nxt_motor_set_speed(p0, paramBase[1], paramBase[2]); break; case resetTachoCountById_4I_5V: nxt_motor_set_count(p0, 0); break; case i2cEnableById_4II_5V: if (i2c_enable(p0, paramBase[1]) == 0) return EXEC_RETRY; else break; case i2cDisableById_4I_5V: i2c_disable(p0); break; case i2cStatusById_4I_5I: push_word(i2c_status(p0)); break; case i2cStartById_4II_1BIII_5I: { Object *p = word2obj(paramBase[2]); JBYTE *byteArray = p ? jbyte_array(p) + paramBase[3] : NULL; push_word(i2c_start(p0, paramBase[1], (U8 *)byteArray, paramBase[4], paramBase[5])); } break; case i2cCompleteById_4I_1BII_5I: { Object *p = word2ptr(paramBase[1]); JBYTE *byteArray = p ? jbyte_array(p) + paramBase[2] : NULL; push_word(i2c_complete(p0, (U8 *)byteArray, paramBase[3])); } break; case playFreq_4III_5V: sound_freq(p0,paramBase[1], paramBase[2]); break; case btGetBC4CmdMode_4_5I: push_word(bt_get_mode()); break; case btSetArmCmdMode_4I_5V: if (p0 == 0) bt_set_arm7_cmd(); else bt_clear_arm7_cmd(); break; case btSetResetLow_4_5V: bt_set_reset_low(); break; case btSetResetHigh_4_5V: bt_set_reset_high(); break; case btWrite_4_1BII_5I: { Object *p = word2ptr(p0); byte *byteArray = (byte *) jbyte_array(p); push_word(bt_write(byteArray, paramBase[1], paramBase[2])); } break; case btRead_4_1BII_5I: { Object *p = word2ptr(p0); byte *byteArray = (byte *) jbyte_array(p); push_word(bt_read(byteArray, paramBase[1], paramBase[2])); } break; case btPending_4_5I: { push_word(bt_event_check(0xffffffff)); } break; case btEnable_4_5V: if (bt_enable() == 0) return EXEC_RETRY; else break; case btDisable_4_5V: bt_disable(); break; case usbRead_4_1BII_5I: { Object *p = word2ptr(p0); byte *byteArray = (byte *) jbyte_array(p); push_word(udp_read(byteArray,paramBase[1], paramBase[2])); } break; case usbWrite_4_1BII_5I: { Object *p = word2ptr(p0); byte *byteArray = (byte *) jbyte_array(p); push_word(udp_write(byteArray,paramBase[1], paramBase[2])); } break; case usbStatus_4_5I: { push_word(udp_event_check(0xffffffff)); } break; case usbEnable_4I_5V: { udp_enable(p0); } break; case usbDisable_4_5V: { udp_disable(); } break; case usbReset_4_5V: udp_reset(); break; case usbSetSerialNo_4Ljava_3lang_3String_2_5V: { byte *p = word2ptr(p0); int len; Object *charArray = (Object *) word2ptr(get_word_4_ns(fields_start(p))); len = get_array_length(charArray); udp_set_serialno((U8 *)jchar_array(charArray), len); } break; case usbSetName_4Ljava_3lang_3String_2_5V: { byte *p = word2ptr(p0); int len; Object *charArray = (Object *) word2ptr(get_word_4_ns(fields_start(p))); len = get_array_length(charArray); udp_set_name((U8 *)jchar_array(charArray), len); } break; case flashWritePage_4_1BI_5I: { Object *p = word2ptr(p0); unsigned long *intArray = (unsigned long *) jint_array(p); push_word(flash_write_page(intArray,paramBase[1])); } break; case flashReadPage_4_1BI_5I: { Object *p = word2ptr(p0); unsigned long *intArray = (unsigned long *) jint_array(p); push_word(flash_read_page(intArray,paramBase[1])); } break; case flashExec_4II_5I: push_word(run_program((byte *)(&FLASH_BASE[(p0*FLASH_PAGE_SIZE)]), paramBase[1])); break; case playSample_4IIIII_5V: sound_play_sample(((unsigned char *) &FLASH_BASE[(p0*FLASH_PAGE_SIZE)]) + paramBase[1],paramBase[2],paramBase[3],paramBase[4]); break; case playQueuedSample_4_1BIIII_5I: push_word(sound_add_sample((U8 *)jbyte_array(word2obj(p0)) + paramBase[1],paramBase[2],paramBase[3],paramBase[4])); break; case getTime_4_5I: push_word(sound_get_time()); break; case getDataAddress_4Ljava_3lang_3Object_2_5I: if (is_array(word2obj(p0))) push_word (ptr2word ((byte *) array_start(word2ptr(p0)))); else push_word (ptr2word ((byte *) fields_start(word2ptr(p0)))); break; case getObjectAddress_4Ljava_3lang_3Object_2_5I: push_word(p0); break; case gc_4_5V: // Restartable garbage collection return garbage_collect(); case shutDown_4_5V: shutdown(); // does not return case boot_4_5V: display_clear(1); while (1) nxt_avr_firmware_update_mode(); // does not return case arraycopy_4Ljava_3lang_3Object_2ILjava_3lang_3Object_2II_5V: return arraycopy(word2ptr(p0), paramBase[1], word2ptr(paramBase[2]), paramBase[3], paramBase[4]); case executeProgram_4I_5V: // Exceute program, allow for instruction re-start return execute_program(p0); case setDebug_4_5V: set_debug(word2ptr(p0)); break; case eventOptions_4II_5I: { byte old = debugEventOptions[p0]; debugEventOptions[p0] = (byte)paramBase[1]; push_word(old); } break; case suspendThread_4Ljava_3lang_3Object_2_5V: suspend_thread(ref2ptr(p0)); break; case resumeThread_4Ljava_3lang_3Object_2_5V: resume_thread(ref2ptr(p0)); break; case getProgramExecutionsCount_4_5I: push_word(gProgramExecutions); break; case getFirmwareRevision_4_5I: push_word((STACKWORD) getRevision()); break; case getFirmwareRawVersion_4_5I: push_word((STACKWORD) VERSION_NUMBER); break; case hsEnable_4II_5V: { if (hs_enable((int)p0, (int)paramBase[1]) == 0) return EXEC_RETRY; } break; case hsDisable_4_5V: { hs_disable(); } break; case hsWrite_4_1BII_5I: { Object *p = word2ptr(p0); byte *byteArray = (byte *) jbyte_array(p); push_word(hs_write(byteArray, paramBase[1], paramBase[2])); } break; case hsRead_4_1BII_5I: { Object *p = word2ptr(p0); byte *byteArray = (byte *) jbyte_array(p); push_word(hs_read(byteArray, paramBase[1], paramBase[2])); } break; case hsPending_4_5I: { push_word(hs_pending()); } break; case hsSend_4BB_1BII_1C_5I: { Object *p = word2ptr(paramBase[2]); U8 *data = (U8 *)jbyte_array(p); p = word2ptr(paramBase[5]); U16 *crc = (U16 *)jchar_array(p); push_word(hs_send((U8) p0, (U8)paramBase[1], data, paramBase[3], paramBase[4], crc)); } break; case hsRecv_4_1BI_1CI_5I: { Object *p = word2ptr(p0); U8 *data = (U8 *)jbyte_array(p); p = word2ptr(paramBase[2]); U16 *crc = (U16 *)jchar_array(p); push_word(hs_recv(data, paramBase[1], crc, paramBase[3])); } break; case getUserPages_4_5I: push_word(FLASH_MAX_PAGES - flash_start_page); break; case setVMOptions_4I_5V: gVMOptions = p0; break; case getVMOptions_4_5I: push_word(gVMOptions); break; case isAssignable_4II_5Z: push_word(is_assignable(p0, paramBase[1])); break; case cloneObject_4Ljava_3lang_3Object_2_5Ljava_3lang_3Object_2: { Object *newObj = clone((Object *)ref2obj(p0)); if (newObj == NULL) return EXEC_RETRY; push_word(obj2ref(newObj)); } break; case memPeek_4III_5I: push_word(mem_peek(p0, paramBase[1], paramBase[2])); break; case memCopy_4Ljava_3lang_3Object_2IIII_5V: mem_copy(word2ptr(p0), paramBase[1], paramBase[2], paramBase[3], paramBase[4]); break; case memGetReference_4II_5Ljava_3lang_3Object_2: push_word(mem_get_reference(p0, paramBase[1])); break; case setSensorPin_4III_5V: sp_set(p0, paramBase[1], paramBase[2]); break; case getSensorPin_4II_5I: push_word(sp_get(p0, paramBase[1])); break; case setSensorPinMode_4III_5V: sp_set_mode(p0, paramBase[1], paramBase[2]); break; case readSensorPin_4II_5I: push_word(sp_read(p0, paramBase[1])); break; case nanoTime_4_5J: { U64 ns = systick_get_ns(); push_word(ns >> 32); push_word(ns); } break; case createStackTrace_4Ljava_3lang_3Thread_2Ljava_3lang_3Object_2_5_1I: { Object *trace = create_stack_trace((Thread *)ref2obj(p0), ref2obj(paramBase[1])); if (trace == NULL) return EXEC_RETRY; push_word(obj2ref(trace)); } break; case registerEvent_4_5I: push_word(register_event((NXTEvent *) ref2obj(p0))); break; case unregisterEvent_4_5I: push_word(unregister_event((NXTEvent *) ref2obj(p0))); break; case changeEvent_4II_5I: push_word(change_event((NXTEvent *) ref2obj(p0), paramBase[1], paramBase[2])); break; case isInitialized_4I_5Z: push_word(is_initialized_idx(p0)); break; case allocate_4II_5Ljava_3lang_3Object_2: { Object *allocated; if(paramBase[1]>0){ allocated=new_single_array(p0,paramBase[1]); }else{ allocated=new_object_for_class(p0); } if(allocated == NULL) return EXEC_RETRY; push_word(obj2ref(allocated)); } break; case memPut_4IIII_5V: store_word_ns((byte *)(memory_base[p0] + paramBase[1]), paramBase[2],paramBase[3]); break; case notifyEvent_4ILjava_3lang_3Thread_2_5Z: push_word(debug_event(paramBase[1], NULL, (Thread*) ref2obj(paramBase[2]), 0, 0, 0, 0)); break; case setThreadRequest_4Ljava_3lang_3Thread_2Llejos_3nxt_3debug_3SteppingRequest_2_5V: { Thread *th = (Thread*) ref2obj(p0); th->debugData = (REFERENCE) paramBase[1]; // currently we only get stepping requests if(paramBase[1]) th->flags |= THREAD_STEPPING; else th->flags &= ~THREAD_STEPPING; } break; case isStepping_4Ljava_3lang_3Thread_2_5Z: { Thread *th = (Thread*) ref2obj(p0); push_word(is_stepping(th)); } break; case setBreakpointList_4_1Llejos_3nxt_3debug_3Breakpoint_2I_5V: breakpoint_set_list((Breakpoint**) array_start(p0), paramBase[1]); break; case enableBreakpoint_4Llejos_3nxt_3debug_3Breakpoint_2Z_5V: breakpoint_enable((Breakpoint*) word2ptr(p0), (boolean) paramBase[1]); break; case firmwareExceptionHandler_4Ljava_3lang_3Throwable_2II_5V: firmware_exception_handler((Throwable *)p0, paramBase[1], paramBase[2]); break; case exitThread_4_5V: currentThread->state = DEAD; schedule_request(REQUEST_SWITCH_THREAD); break; case updateThreadFlags_4Ljava_3lang_3Thread_2II_5I: ((Thread *)p0)->flags |= paramBase[1]; ((Thread *)p0)->flags &= ~paramBase[2]; //printf("m %x %d\n", p0, ((Thread *)p0)->flags); push_word(((Thread *)p0)->flags); break; default: return throw_new_exception(JAVA_LANG_NOSUCHMETHODERROR); } return EXEC_CONTINUE; }
// // ダイアログメッセージ処理 // BOOL APIENTRY MainFunc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND h; HDROP hDrop; OPENFILENAME ofn; HICON hicon; TCHAR temp[MAX_PATH]; TCHAR *ext; switch(message) { case WM_INITDIALOG: // アイコンをセット if(hicon = LoadIcon(h_instance, MAKEINTRESOURCE(IDI_ICON_SEXE))) { SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hicon); SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hicon); } // 設定値をコントロールにセット h = GetDlgItem(hDlg, IDC_EDIT_EXE); SendMessage(h, EM_LIMITTEXT, MAX_PATH, 0); SetWindowText(h, exe_name); EnableWindow(h, !service_install_flag); h = GetDlgItem(hDlg, IDC_EDIT_OPTION); SendMessage(h, EM_LIMITTEXT, MAX_PATH, 0); SetWindowText(h, option_name); EnableWindow(h, !service_install_flag); h = GetDlgItem(hDlg, IDC_EDIT_NAME); SendMessage(h, EM_LIMITTEXT, MAX_PATH, 0); SetWindowText(h, service_name); EnableWindow(h, !service_install_flag); h = GetDlgItem(hDlg, IDC_EDIT_DESCRIPTION); SendMessage(h, EM_LIMITTEXT, MAX_PATH, 0); SetWindowText(h, description_name); EnableWindow(h, !service_install_flag); h = GetDlgItem(hDlg, IDC_COMBO_END); LoadString(h_instance, IDS_ITEM_CLOSE, temp, MAX_PATH); SendMessage(h, CB_ADDSTRING, 0, (DWORD_PTR)temp); // 2002/6/18 LoadString(h_instance, IDS_ITEM_SYSCOMMAND, temp, MAX_PATH); SendMessage(h, CB_ADDSTRING, 0, (DWORD_PTR)temp); LoadString(h_instance, IDS_ITEM_SYS_CLOSE, temp, MAX_PATH); SendMessage(h, CB_ADDSTRING, 0, (DWORD_PTR)temp); // 2004/8/9 LoadString(h_instance, IDS_ITEM_CTRL_BREAK, temp, MAX_PATH); SendMessage(h, CB_ADDSTRING, 0, (DWORD_PTR)temp); SendMessage(h, CB_SETCURSEL, end_pattern, 0); EnableWindow(h, !service_install_flag); // 2001/11/9 h = GetDlgItem(hDlg, IDC_BUTTON_EXE); EnableWindow(h, !service_install_flag); h = GetDlgItem(hDlg, IDC_BUTTON_TEST); if(service_install_flag) { LoadString(h_instance, IDS_BUTTON_DELETE, temp, MAX_PATH); SetWindowText(h, temp); } // 2004/8/9 h = GetDlgItem(hDlg, IDC_CHECK_AUTO); SendMessage(h, BM_SETCHECK, auto_flag, 0); EnableWindow(h, !service_install_flag); h = GetDlgItem(hDlg, IDC_CHECK_DESKTOP); SendMessage(h, BM_SETCHECK, desktop_flag, 0); EnableWindow(h, !service_install_flag); h = GetDlgItem(hDlg, IDC_CHECK_RETRY); SendMessage(h, BM_SETCHECK, retry_flag, 0); EnableWindow(h, !service_install_flag); break; case WM_COMMAND: switch(LOWORD (wParam)) { case IDOK: // 設定値得る if(!service_install_flag) { h = GetDlgItem(hDlg, IDC_EDIT_NAME); GetWindowText(h, service_name, MAX_PATH); if(service_name[0] == _T('\0')) { // サービス名を指定してください MessageBoxResourceText(hDlg, IDS_ERROR_NO_SERVICE_NAME, NULL, ERROR_HEADER, MB_OK); break; } h = GetDlgItem(hDlg, IDC_EDIT_EXE); GetWindowText(h, exe_name, MAX_PATH); // 2007/12/14 test ext = extract_ext(exe_name); if(exe_name[0] == _T('\0') || (_tcsicmp(ext, _T("exe")) && _tcsicmp(ext, _T("bat")))) { // プログラム名を指定してください MessageBoxResourceText(hDlg, IDS_ERROR_NO_PROGRAM_NAME, NULL, ERROR_HEADER, MB_OK); break; } h = GetDlgItem(hDlg, IDC_EDIT_OPTION); GetWindowText(h, option_name, MAX_PATH); h = GetDlgItem(hDlg, IDC_EDIT_DESCRIPTION); GetWindowText(h, description_name, MAX_PATH); h = GetDlgItem(hDlg, IDC_COMBO_END); end_pattern = (int)SendMessage(h, CB_GETCURSEL, 0, 0); // 2004/8/9 h = GetDlgItem(hDlg, IDC_CHECK_AUTO); auto_flag = (int)SendMessage(h, BM_GETCHECK, 0, 0); h = GetDlgItem(hDlg, IDC_CHECK_DESKTOP); desktop_flag = (int)SendMessage(h, BM_GETCHECK, 0, 0); h = GetDlgItem(hDlg, IDC_CHECK_RETRY); retry_flag = (int)SendMessage(h, BM_GETCHECK, 0, 0); // 設定値を保存 set_inifile(); // サービス %s を登録しますか? if(MessageBoxResourceText(hDlg, IDS_QUESTION_INSTALL, service_name, HEADER, MB_YESNO) == IDYES) { int err; if((err = install_service()) == ERROR_SUCCESS) { // 2001/11/9 // サービス %s を登録しました。サービスとして起動しますか? if(MessageBoxResourceText(hDlg, IDS_QUESTION_INSTALL_START, service_name, HEADER, MB_YESNO) == IDYES) { restart_service(); } } else { if(err == ERROR_SERVICE_EXISTS) { // すでに同名のサービスが登録済みです MessageBoxResourceText(NULL, IDS_ERROR_SAME_SERVICE, NULL, ERROR_HEADER, MB_OK); } else { // サービスに登録できませんでした。\nサービスの権限があるユーザーでログインして実行してください。 MessageBoxResourceText(hDlg, IDS_ERROR_INSTALL_SERVICE, NULL, HEADER, MB_OK); } } } } DestroyWindow(hDlg); break; case IDCANCEL: DestroyWindow(hDlg); break; case IDC_BUTTON_EXE: { TCHAR filter[MAX_PATH]; TCHAR title[MAX_PATH]; int len; // 参照ボタンが押された temp[0] = '\0'; FillMemory(&ofn, sizeof(OPENFILENAME), 0); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hDlg; ofn.nMaxFile = MAX_PATH; ofn.lpstrFile = temp; // 実行ファイル(*.exe)\0*.exe\0" LoadString(h_instance, IDS_FILE_EXE, filter, MAX_PATH); len = lstrlen(filter); LoadString(h_instance, IDS_FILE_WILD_EXE, filter + len + 1, MAX_PATH - len - 2); len += lstrlen(filter + len + 1); *(filter + len + 2) = '\0'; ofn.lpstrFilter = filter; // 実行ファイルの選択 LoadString(h_instance, IDS_FILE_TITLE, title, MAX_PATH); ofn.lpstrTitle = title; ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR; if(GetOpenFileName(&ofn)) { ext = extract_ext(temp); if(!_tcsicmp(ext, _T("exe")) || !_tcsicmp(ext, _T("bat"))) { TCHAR name[MAX_PATH]; // .exe ファイルをセット h = GetDlgItem(hDlg, IDC_EDIT_EXE); SetWindowText(h, (LPCTSTR)temp); // サービス名として .exe ファイルの名前をセット extract_name_only(name, temp); h = GetDlgItem(hDlg, IDC_EDIT_NAME); SetWindowText(h, (LPCTSTR)name); } else { // プログラムファイルのみ登録可能です。 MessageBoxResourceText(hDlg, IDS_ERROR_NOT_PROGRAM, NULL, ERROR_HEADER, MB_OK); } } } break; case IDC_BUTTON_TEST: // サービスとしてインストール済み? if(service_install_flag) { // サービス service_name を削除しますか? if(MessageBoxResourceText(hDlg, IDS_QUESTION_UNINSTALL, service_name, HEADER, MB_YESNO) == IDYES) { // サービスから削除 if(remove_service()) { // サービス service_name を削除しました MessageBoxResourceText(hDlg, IDS_UNINSTALL_OK, service_name, HEADER, MB_OK); service_install_flag = FALSE; h = GetDlgItem(hDlg, IDC_EDIT_EXE); EnableWindow(h, TRUE); h = GetDlgItem(hDlg, IDC_EDIT_OPTION); EnableWindow(h, TRUE); h = GetDlgItem(hDlg, IDC_EDIT_NAME); EnableWindow(h, TRUE); h = GetDlgItem(hDlg, IDC_EDIT_DESCRIPTION); EnableWindow(h, TRUE); h = GetDlgItem(hDlg, IDC_COMBO_END); EnableWindow(h, TRUE); // 2001/11/9 h = GetDlgItem(hDlg, IDC_BUTTON_EXE); EnableWindow(h, TRUE); h = GetDlgItem(hDlg, IDC_BUTTON_TEST); // テスト起動(&T) LoadString(h_instance, IDS_BUTTON_TEST, temp, MAX_PATH); SetWindowText(h, temp); // 2004/8/9 h = GetDlgItem(hDlg, IDC_CHECK_AUTO); EnableWindow(h, TRUE); h = GetDlgItem(hDlg, IDC_CHECK_DESKTOP); EnableWindow(h, TRUE); h = GetDlgItem(hDlg, IDC_CHECK_RETRY); EnableWindow(h, TRUE); } else { // サービスから削除できませんでした。\nサービスの権限があるユーザーでログインして実行してください。 MessageBoxResourceText(NULL, IDS_ERROR_UNINSTALL_SERVICE, NULL, ERROR_HEADER, MB_OK); } } } else { TCHAR param[MAX_PATH]; // テスト起動処理 h = GetDlgItem(hDlg, IDC_EDIT_EXE); GetWindowText(h, temp, MAX_PATH); h = GetDlgItem(hDlg, IDC_EDIT_OPTION); GetWindowText(h, param, MAX_PATH); h = GetDlgItem(hDlg, IDC_COMBO_END); execute_program(hDlg, temp, param, (int)SendMessage(h, CB_GETCURSEL, 0, 0)); } break; } break; case WM_DROPFILES: // Drag&Drop で受けたファイル名を取り出す hDrop = (HDROP)wParam; DragQueryFile(hDrop, 0, temp, MAX_PATH); DragFinish(hDrop); if(!service_install_flag) { if(!_tcsicmp(extract_ext(temp), _T("exe"))) { TCHAR name[MAX_PATH]; // .exe ファイルをセット h = GetDlgItem(hDlg, IDC_EDIT_EXE); SetWindowText(h, temp); // サービス名として .exe ファイルの名前をセット extract_name_only(name, temp); h = GetDlgItem(hDlg, IDC_EDIT_NAME); SetWindowText(h, (LPCTSTR)name); } else { // プログラムファイルのみ登録可能です。 MessageBoxResourceText(hDlg, IDS_ERROR_NOT_PROGRAM, NULL, ERROR_HEADER, MB_OK); } } SetForegroundWindow(hDlg); break; case WM_HELP: ShellExecute(hDlg, _T("open"), _T("sexe.chm"), NULL, NULL, SW_SHOW); break; case WM_DESTROY: // 2001/11/9 if(service_stop_flag) { restart_service(); } PostQuitMessage(0); break; default: return FALSE; } return FALSE; }
/* * determine the action to perform */ static void lookup_action(char *op, key_serial_t key, char *ktype, char *kdesc, char *callout_info) { char buf[4096 + 2], *p, *q; FILE *conf; int len, oplen, ktlen, kdlen, cilen; oplen = strlen(op); ktlen = strlen(ktype); kdlen = strlen(kdesc); cilen = strlen(callout_info); /* search the config file for a command to run */ conf = fopen(xdebug < 2 ? "/etc/request-key.conf" : "request-key.conf", "r"); if (!conf) error("Cannot open /etc/request-key.conf: %m\n"); for (confline = 1;; confline++) { /* read the file line-by-line */ if (!fgets(buf, sizeof(buf), conf)) { if (feof(conf)) error("Cannot find command to construct key %d\n", key); error("Error reading /etc/request-key.conf\n"); } len = strlen(buf); if (len >= sizeof(buf) - 2) error("/etc/request-key.conf:%d: Line too long\n", confline); /* ignore blank lines and comments */ if (len == 1 || buf[0] == '#' || isspace(buf[0])) continue; buf[--len] = 0; p = buf; /* attempt to match the op */ q = p; while (*p && !isspace(*p)) p++; if (!*p) goto syntax_error; *p = 0; if (!match(q, p - q, op, oplen)) continue; p++; /* attempt to match the type */ while (isspace(*p)) p++; if (!*p) goto syntax_error; q = p; while (*p && !isspace(*p)) p++; if (!*p) goto syntax_error; *p = 0; if (!match(q, p - q, ktype, ktlen)) continue; p++; /* attempt to match the description */ while (isspace(*p)) p++; if (!*p) goto syntax_error; q = p; while (*p && !isspace(*p)) p++; if (!*p) goto syntax_error; *p = 0; if (!match(q, p - q, kdesc, kdlen)) continue; p++; /* attempt to match the callout info */ while (isspace(*p)) p++; if (!*p) goto syntax_error; q = p; while (*p && !isspace(*p)) p++; if (!*p) goto syntax_error; *p = 0; if (!match(q, p - q, callout_info, cilen)) continue; p++; debug("Line %d matches\n", confline); /* we've got an action */ while (isspace(*p)) p++; if (!*p) goto syntax_error; fclose(conf); execute_program(op, key, ktype, kdesc, callout_info, p); } error("/etc/request-key.conf: No matching action\n"); syntax_error: error("/etc/request-key.conf:%d: Syntax error\n", confline); } /* end lookup_action() */
void execute() { execute_program(); return; }
int emulate_zend(int argc, char** argv) { std::vector<std::string> newargv; newargv.push_back(argv[0]); bool lint = false; bool show = false; bool need_file = true; int ini_fd = -1; char ini_path[] = "/tmp/php-ini-XXXXXX.ini"; std::string ini_section = ""; const char* program = nullptr; int cnt = 1; bool ignore_default_configs = false; while (cnt < argc) { if (check_option(argv[cnt])) { newargv.push_back(argv[cnt++]); continue; } if (strcmp(argv[cnt], "-a") == 0 || strcmp(argv[cnt], "--interactive") == 0) { need_file = false; newargv.push_back("-a"); cnt++; continue; } if (strcmp(argv[cnt], "-z") == 0) { std::string arg = "-vDynamicExtensions.0="; arg.append(argv[cnt+1]); newargv.push_back(arg.c_str()); cnt += 2; continue; } if (strcmp(argv[cnt], "-l") == 0 || strcmp(argv[cnt], "--lint") == 0) { cnt++; lint = true; continue; } if (strcmp(argv[cnt], "-r") == 0) { if (cnt + 1 == argc) { // Hmm, no program fragment passed along. Let hhvm print its usage // message? newargv.push_back(argv[cnt++]); continue; } assert(cnt + 1 < argc); program = argv[cnt + 1]; need_file = true; cnt += 2; continue; } if (strcmp(argv[cnt], "-w") == 0) { cnt++; show = true; continue; } if (strcmp(argv[cnt], "-v") == 0 || strcmp(argv[cnt], "--version") == 0) { newargv.push_back("--version"); cnt = argc; // no need to check the rest of options and arguments need_file = false; break; } if (strcmp(argv[cnt], "-f") == 0 || strcmp(argv[cnt], "--file") == 0) { cnt++; newargv.push_back(lint ? "-l" : "-f"); newargv.push_back(argv[cnt++]); need_file = false; break; } if (strcmp(argv[cnt], "-n") == 0) { ignore_default_configs = true; cnt++; newargv.push_back("--no-config"); continue; } if (strcmp(argv[cnt], "-c") == 0) { if (cnt + 1 < argc && argv[cnt + 1][0] != '-') { newargv.push_back("-c"); newargv.push_back(argv[cnt + 1]); cnt = cnt + 2; continue; } else { fprintf(stderr, "Notice: No config file specified"); exit(EXIT_FAILURE); } } if (strcmp(argv[cnt], "-d") == 0) { ini_fd = get_tempfile_if_not_exists(ini_fd, ini_path); std::string line = argv[cnt+1]; std::string section = "php"; int pos_period = line.find_first_of('.'); int pos_equals = line.find_first_of('='); if (pos_period != std::string::npos && pos_equals != std::string::npos && pos_period < pos_equals) { section = line.substr(0, pos_period); } if (section != ini_section) { ini_section = section; write(ini_fd, "[", 1); write(ini_fd, section.c_str(), section.length()); write(ini_fd, "]\n", 2); } write(ini_fd, line.c_str(), line.length()); write(ini_fd, "\n", 1); cnt += 2; continue; } if (argv[cnt][0] != '-') { if (show) { newargv.push_back("-w"); } else { newargv.push_back(lint ? "-l" : "-f"); } newargv.push_back(argv[cnt++]); need_file = false; break; } if (strcmp(argv[cnt], "--") == 0) { break; } cnt++; // skip unknown options } if (need_file) { char tmp[] = "/tmp/php-wrap-XXXXXX"; int tmp_fd = mkstemp(tmp); if (tmp_fd == -1) { fprintf(stderr, "Error: unable to open temporary file"); exit(EXIT_FAILURE); } if (program == nullptr) { // If the program wasn't specified on the command-line, ala' -r, // is no command-line parameter, read the PHP file from stdin. std::string line; while (std::getline(std::cin, line)) { write(tmp_fd, line.c_str(), line.length()); write(tmp_fd, "\n", 1); } } else { // -r omits the braces write(tmp_fd, "<?\n", 3); write(tmp_fd, program, strlen(program)); } close(tmp_fd); if (show) { newargv.push_back("-w"); } else { newargv.push_back(lint ? "-l" : "-f"); } newargv.push_back(tmp); newargv.push_back("--temp-file"); } if (ini_fd != -1) { newargv.push_back("-c"); newargv.push_back(ini_path); } if (ignore_default_configs) { // Appending empty file to -c options to avoid loading defaults ini_fd = get_tempfile_if_not_exists(ini_fd, ini_path); } else { // Should only include this default if not explicitly ignored. #ifdef PHP_DEFAULT_HDF newargv.push_back("-c"); newargv.push_back(PHP_DEFAULT_HDF); #endif // If the -c option is specified without a -n, php behavior is to // load the default ini/hdf auto cb = [&newargv] (const char *filename) { newargv.push_back("-c"); newargv.push_back(filename); }; add_default_config_files_globbed("/etc/hhvm/php*.ini", cb); add_default_config_files_globbed("/etc/hhvm/config*.hdf", cb); } if (cnt < argc && strcmp(argv[cnt], "--") == 0) cnt++; if (cnt < argc) { // There are arguments following the filename, so copy them. newargv.push_back("--"); for (int i = cnt; i < argc; i++) { newargv.push_back(argv[i]); } } char *newargv_array[newargv.size() + 1]; for (unsigned i = 0; i < newargv.size(); i++) { // printf("%s\n", newargv[i].data()); newargv_array[i] = (char *)newargv[i].data(); } // NULL-terminate the argument array. newargv_array[newargv.size()] = nullptr; auto ret = execute_program(newargv.size(), newargv_array); if (ini_fd != -1) { unlink(ini_path); } return ret; }