void script_char( int c ) { /* Check the state of the scripting flag in the game flags. If it is on * then check to see if the scripting file is open as well */ if ( ( get_word( H_FLAGS ) & SCRIPTING_FLAG ) != 0 && scripting == OFF ) { open_script( ); } /* Check the state of the scripting flag in the game flags. If it is off * then check to see if the scripting file is closed as well */ if ( ( get_word( H_FLAGS ) & SCRIPTING_FLAG ) == 0 && scripting == ON ) { close_script( ); } /* If scripting file is open, we are in the text window and the character is * printable then write the character */ if ( scripting == ON && scripting_disable == OFF && ( c == '\n' || ( isprint( c ) ) ) ) { putc( c, sfp ); } } /* script_char */
int execute_script_line(void) { char line[1024]; if(g_context.args.exec[0]) { int ret = execute_line(g_context.args.exec); g_context.args.exec[0] = ' '; g_context.args.exec[1] = 0; if(ret < 0) { return -1; } if(ret > 0) { return 1; } /* Only way we get here is if there were no lines to execute */ close_script(); } else if(g_context.fscript) { while(fgets(line, sizeof(line), g_context.fscript)) { int ret = execute_line(line); if(ret < 0) { return -1; } /* Only return if we have sent a line to the PSP */ if(ret > 0) { return 1; } } /* Only way we get here is if there were no lines to execute */ close_script(); } return 0; }
static void execute_smt (void) { Bool cont = TRUE; EVENT *event; struct_ggscrp_error *ggscrp_error; struct_ggscrp_done *ggscrp_done; char *ptr; while (cont) { while (cont && (myqueue-> cur_events == 0)) cont = smt_exec_step (); if (myqueue-> cur_events) { event = event_accept (myqueue, NULL); coprintf ("Received event: %s", event-> name); if (streq (event-> name, GGSCRP_ERROR)) { get_ggscrp_error (event-> body, & ggscrp_error); coprintf ("From job: %i", ggscrp_error-> job); ptr = strtok (ggscrp_error-> error_text, "\n"); while (ptr) { coprintf ("(%s %u): %s", ggscrp_error-> error_name, ggscrp_error-> error_line, ptr); ptr = strtok (NULL, "\n"); } free_ggscrp_error (& ggscrp_error); } else if (streq (event-> name, GGSCRP_DONE)) { get_ggscrp_done (event-> body, & ggscrp_done); coprintf ("From job: %i Size=%u", ggscrp_done-> job, ((SCRIPT_SOURCE *) ggscrp_done-> script_source) -> size); close_script ((SCRIPT_SOURCE *) ggscrp_done-> script_source); free_ggscrp_done (& ggscrp_done); } event_destroy (event); } } }
int cleanupJS(int dummy) { #else ( void ) interpret( ); #endif unload_cache( ); close_story( ); close_script( ); reset_screen( ); exit( EXIT_SUCCESS ); return ( 0 ); } /* main */
void cli_handler(char *buf) { if(buf) { if(g_context.ttymode) { if(strncmp(buf, "~.", 2) == 0) { char prompt[PATH_MAX]; g_context.ttymode = 0; rl_callback_handler_remove(); snprintf(prompt, PATH_MAX, "%s> ", g_context.currpath); rl_callback_handler_install(prompt, cli_handler); } else if(g_context.outsock >= 0) { char b[1024]; snprintf(b, sizeof(b), "%s\n", buf); write(g_context.outsock, b, strlen(b)); } return; } while(isspace(*buf)) { buf++; } if(*buf == 0) { if(g_context.asmmode) { char prompt[PATH_MAX]; g_context.asmmode = 0; g_context.asmaddr = 0; rl_callback_handler_remove(); snprintf(prompt, PATH_MAX, "%s> ", g_context.currpath); rl_callback_handler_install(prompt, cli_handler); } return; } if(in_script()) { /* When a script is running only accept stop */ if(strcmp(buf, "stop") == 0) { close_script(); } return; } if(g_context.asmmode) { char cmd[1024]; /* Do assembler */ unsigned int opcode; if(asmAssemble(buf, g_context.asmaddr, &opcode) == 0) { sprintf(cmd, "pokew 0x%08X 0x%08X ", g_context.asmaddr, opcode); execute_line(cmd); } return; } add_history(buf); if(buf[0] == '!') { if(strncmp(&buf[1], "cd ", 3) == 0) { chdir(&buf[4]); } else { system(&buf[1]); } return; } else if(buf[0] == '@') { if(g_context.fssock >= 0) { (void) write(g_context.fssock, &buf[1], strlen(&buf[1])); } return; } else if(buf[0] == '%') { execute_script(&buf[1]); return; } execute_line(buf); } else { shutdown_app(); exit(0); } }
int open_script(const char *file, int sargc, char **sargv) { int ret = 0; int i; do { /* Ensure script is closed */ close_script(); if(strcmp(file, "-") == 0) { g_context.fscript = stdin; } else { g_context.fscript = fopen(file, "r"); if(g_context.fscript == NULL) { fprintf(stderr, "Could not open script file %s\n", file); break; } } if(sargc > 0) { g_context.sargv = (char**) malloc(sizeof(char*)*sargc); if(g_context.sargv == NULL) { fprintf(stderr, "Could not allocate script arguments\n"); break; } for(i = 0; i < sargc; i++) { g_context.sargv[i] = strdup(sargv[i]); if(g_context.sargv[i] == NULL) { fprintf(stderr, "Could not allocate argument string %d\n", i); break; } } if(i < sargc) { break; } g_context.sargc = sargc; } ret = 1; } while(0); if(!ret) { close_script(); } return ret; }
int process_cmd(const unsigned char *str) { if(*str < 128) { if(g_context.fredir) { fprintf(g_context.fredir, "%s", str); } else { printf("%s", str); } } else { if(*str == SHELL_CMD_CWD) { snprintf(g_context.currpath, PATH_MAX, "%s", str+1); (void) setenv("PSPPWD", g_context.currpath, 1); } else if((*str == SHELL_CMD_SUCCESS) || (*str == SHELL_CMD_ERROR)) { char prompt[PATH_MAX]; if(*str == SHELL_CMD_ERROR) { /* If there was a command then print the help */ if(g_context.currcmd[0]) { const struct sh_command *cmd = find_command(g_context.currcmd); if(cmd == NULL) { fprintf(stderr, "Unknown command %s\n", g_context.currcmd); } else { if(cmd->help) { fprintf(stderr, "Usage: %s\n", cmd->help); } else { fprintf(stderr, "Command %s has no help associated\n", g_context.currcmd); } } } /* On error stop any executing script */ if(in_script()) { close_script(); } /* Set return code */ g_context.lasterr = 1; } else { g_context.lasterr = 0; } (void) setenv("?", (char*) (str+1), 1); g_context.currcmd[0] = 0; if(g_context.fredir) { fclose(g_context.fredir); g_context.fredir = NULL; } else { fflush(stdout); } /* Only restore if there is no pending script and we didn't execute a line */ if((execute_script_line() <= 0) && (g_context.args.script == 0)) { if(g_context.asmmode) { if(!g_context.asmaddr) { g_context.asmaddr = strtoul((char*) str+1, NULL, 0); } else { g_context.asmaddr += 4; } } rl_callback_handler_remove(); if(g_context.asmmode) { snprintf(prompt, PATH_MAX, "asm:0x%08X> ", g_context.asmaddr); } else { snprintf(prompt, PATH_MAX, "%s> ", g_context.currpath); g_context.ttymode = 0; } rl_callback_handler_install(prompt, cli_handler); } } else if(*str == SHELL_CMD_TAB) { fprintf(stderr, "Mismatched Tab Match: %s\n", str+1); } else if(*str == SHELL_CMD_DISASM) { unsigned int addr; unsigned int opcode; char *endp; str++; addr = strtoul((char*) str, &endp, 16); if(*endp != ':') { fprintf(stderr, "Invalid disasm command %s\n", str); } else { opcode = strtoul(endp+1, NULL, 16); printf("%s\n", disasmInstruction(opcode, addr, NULL, NULL, 0)); } } else if(*str == SHELL_CMD_SYMLOAD) { char sha1[41]; char addr[9]; const char *name; str++; if(strlen((const char*) str) > (40+8)) { memcpy(sha1, str, 40); sha1[40] = 0; memcpy(addr, &str[40], 8); addr[8] = 0; name = (const char*) &str[40+8]; printf("Symbol Load - Name %32s, Address 0x%s, SHA1 %s\n", name, addr, sha1); } } } return 1; }