std::wstring processServerCommand(ServerCommandContext *ctx) { std::wostringstream os(std::ios_base::binary); ctx->flags = 1; // Default, unless we change it. u64 privs = ctx->privs; if(ctx->parms.size() == 0 || ctx->parms[0] == L"help") { os<<L"-!- Available commands: "; os<<L"status privs "; if(privs & PRIV_SERVER) os<<L"shutdown setting "; if(privs & PRIV_SETTIME) os<<L" time"; if(privs & PRIV_TELEPORT) os<<L" teleport"; if(privs & PRIV_PRIVS) os<<L" grant revoke"; } else if(ctx->parms[0] == L"status") { cmd_status(os, ctx); } else if(ctx->parms[0] == L"privs") { cmd_privs(os, ctx); } else if(ctx->parms[0] == L"grant" || ctx->parms[0] == L"revoke") { cmd_grantrevoke(os, ctx); } else if(ctx->parms[0] == L"time") { cmd_time(os, ctx); } else if(ctx->parms[0] == L"shutdown") { cmd_shutdown(os, ctx); } else if(ctx->parms[0] == L"setting") { cmd_setting(os, ctx); } else if(ctx->parms[0] == L"teleport") { cmd_teleport(os, ctx); } else { os<<L"-!- Invalid command: " + ctx->parms[0]; } return os.str(); }
std::wstring processServerCommand(ServerCommandContext *ctx) { std::wostringstream os(std::ios_base::binary); ctx->flags = SEND_TO_SENDER; // Default, unless we change it. u64 privs = ctx->privs; if(ctx->parms.size() == 0 || ctx->parms[0] == L"help") { os<<L"-!- Available commands: "; os<<L"me status privs"; if(privs & PRIV_SERVER) os<<L" shutdown setting clearobjects"; if(privs & PRIV_SETTIME) os<<L" time"; if(privs & PRIV_TELEPORT) os<<L" teleport"; if(privs & PRIV_PRIVS) os<<L" grant revoke"; if(privs & PRIV_BAN) os<<L" ban unban"; if(privs & PRIV_PASSWORD) os<<L" setpassword clearpassword"; } else if(ctx->parms[0] == L"status") cmd_status(os, ctx); else if(ctx->parms[0] == L"privs") cmd_privs(os, ctx); else if(ctx->parms[0] == L"grant" || ctx->parms[0] == L"revoke") cmd_grantrevoke(os, ctx); else if(ctx->parms[0] == L"time") cmd_time(os, ctx); else if(ctx->parms[0] == L"shutdown") cmd_shutdown(os, ctx); else if(ctx->parms[0] == L"setting") cmd_setting(os, ctx); else if(ctx->parms[0] == L"teleport") cmd_teleport(os, ctx); else if(ctx->parms[0] == L"ban" || ctx->parms[0] == L"unban") cmd_banunban(os, ctx); else if(ctx->parms[0] == L"setpassword" || ctx->parms[0] == L"clearpassword") cmd_setclearpassword(os, ctx); else if(ctx->parms[0] == L"me") cmd_me(os, ctx); else if(ctx->parms[0] == L"clearobjects") cmd_clearobjects(os, ctx); else os<<L"-!- Invalid command: " + ctx->parms[0]; return os.str(); }
std::wstring processServerCommand(ServerCommandContext *ctx) { std::wostringstream os(std::ios_base::binary); ctx->flags = SEND_TO_SENDER; // Default, unless we change it. if(ctx->parms[0] == L"status") cmd_status(os, ctx); else if(ctx->parms[0] == L"time") cmd_time(os, ctx); else if(ctx->parms[0] == L"shutdown") cmd_shutdown(os, ctx); else if(ctx->parms[0] == L"ban" || ctx->parms[0] == L"unban") cmd_banunban(os, ctx); else if(ctx->parms[0] == L"me") cmd_me(os, ctx); else if(ctx->parms[0] == L"clearobjects") cmd_clearobjects(os, ctx); else os<<L"-!- Invalid command: " + ctx->parms[0]; return os.str(); }
int initialize(void) { int comPath; /* path to COMMAND.COM (for COMSPEC/reload) */ char *newTTY; /* what to change TTY to */ int showinfo; /* show initial info only if no command line options */ int key; int ec; /* error code */ unsigned offs; /* offset into environment segment */ int cmdlen; /* length of command line */ char *cmdline; /* command line duplicated into heap */ char *p, *h, *q; #ifdef FEATURE_CALL_LOGGING FILE *f; #endif /* Set up the host environment of COMMAND.COM */ /* Install the ^Break handler (see chkCBreak() for more details) */ extern void initCBreakCatcher(void); initCBreakCatcher(); /* Install INT 24 Critical error handler */ init_error_handler(); /* DOS shells patch the PPID to the own PID, how stupid this is, however, because then DOS won't terminate them, e.g. when a Critical Error occurs that is not detected by COMMAND.COM */ oldPSP = OwnerPSP; atexit(exitfct); OwnerPSP = _psp; /* Some elder DOSs may not pass an initialzied environment segment */ if (env_glbSeg && !isMCB(SEG2MCB(env_glbSeg))) env_setGlbSeg(0); /* Disable the environment */ /* Now parse the command line parameters passed to COMMAND.COM */ /* Preparations */ newTTY = NULL; comPath = tracemode = 0; showinfo = 1; /* Because FreeCom should be executed in a DOS3+ compatible environment most of the time, it is assumed that its path can be determined from the environment. This has the advantage that the string area is accessable very early in the run. The name of the current file is string #0. */ if((offs = env_string(0, 0)) != 0) /* OK, environment filled */ grabComFilename(0, (char far *)MK_FP(env_glbSeg, offs)); /* Aquire the command line, there are three possible sources: 1) DOS command line @PSP:0x80 as pascal string, 2) extended DOS command line environment variable CMDLINE, if peekb(PSP, 0x80) == 127,& 3) MKS command line @ENV:2, if peekb(ENV, 0) == '~' Currently implemented is version #1 only */ cmdlen = peekb(_psp, 0x80); if(cmdlen < 0 || cmdlen > 126) { error_corrupt_command_line(); cmdlen = 0; } /* duplicate the command line into the local address space */ if((cmdline = malloc(cmdlen + 1)) == NULL) { error_out_of_memory(); /* Cannot recover from this problem */ return E_NoMem; } _fmemcpy((char far*)cmdline, MK_FP(_psp, 0x81), cmdlen); cmdline[cmdlen] = '\0'; #ifdef FEATURE_CALL_LOGGING if((f = fopen(logFilename, "at")) == NULL) { fprintf(stderr, "Cannot open logfile: \"%s\"\n", logFilename); exit(125); } putc('"', f); if(ComPath) /* path to command.com already known */ fputs(ComPath, f); putc('"', f); putc(':', f); fputs(cmdline, f); putc('\n', f); fclose(f); #endif p = cmdline; /* start of the command line */ do { ec = leadOptions(&p, opt_init, NULL); if(ec == E_NoOption) { /* /C or /K */ assert(p && *p); if(!isoption(p)) { error_quoted_c_k(); p = NULL; break; } assert(p[1] && strchr("kKcC", p[1])); p += 2; /* p := start of command line to execute */ break; } else if(ec != E_None) { showhelp = 1; p = NULL; break; } assert(p && !isoption(p) && !isspace(*p)); if(!*p) { p = NULL; break; /* end of line reached */ } q = unquote(p, h = skip_word(p)); p = h; /* Skip this word */ if(!q) { error_out_of_memory(); p = NULL; break; } if(!comPath) { /* 1st argument */ grabComFilename(1, (char far*)q); comPath = 1; free(q); } else if(!newTTY) { /* 2nd argument */ #ifdef INCLUDE_CMD_CTTY newTTY = q; #else error_ctty_excluded(); free(q); #endif } else { error_too_many_parameters(q); showhelp = 1; free(q); break; } } while(1); /* * Now: * + autoexec: AUTOEXEC.BAT file to be executed if /P switch * is enabled; if NULL, use default * + comPath: user-defined PATH to COMMAND.COM; if NULL, use * the one from the environment * + newTTY: the name of the device to be CTTY'ed; if NULL, * no change * + p: pointer to the command to be executed: * *p == 'c' or 'C' --> spawn command, then terminate shell * *p == 'k' or 'K' --> spawn command, then go interactive * &p[1] --> command line, unless the first character is an * argument character */ /* Now process the options */ #ifdef INCLUDE_CMD_CTTY if (newTTY) { /* change TTY as early as possible so the caller gets the messages into the correct channel */ cmd_ctty(newTTY); free(newTTY); } #endif if(!ComPath) { /* FreeCom is unable to find itself --> print error message */ /* Emergency error */ puts("You must specify the complete path to " COM_NAME); puts("as the first argument of COMMAND,"); puts("for instance: C:\\FDOS"); return E_Useage; } /* First of all, set up the environment */ env_resizeCtrl |= ENV_USEUMB | ENV_ALLOWMOVE; if (envSize < 0) envSize = 32767; /* Numeric overflow (number > 32767 specified) */ else if (envSize < 256) envSize = 256; /* Minimum size of 256. */ if(envSize > env_resize(0, 0)) /* Test if to enlarge environment */ env_setsize(0, envSize); /* Set the COMSPEC variable. */ #if 0 if (chgEnv("COMSPEC", ComPath)) error_env_var("COMSPEC"); #else if (chgEnv("COMSPEC", ComPath)) { /* Failed to add this variable, the most likely problem should be that the environment is too small --> it is increased and the operation is redone */ env_resize(0, strlen(ComPath) + 10); if (chgEnv("COMSPEC", ComPath)) error_env_var("COMSPEC"); } #endif if(internalBufLen) error_l_notimplemented(); if(inputBufLen) error_u_notimplemented(); if(tracemode) showinfo = 0; if (showhelp) displayString(TEXT_CMDHELP_COMMAND); if ((showhelp || exitflag) && canexit) return E_None; /* Now the /P option can be processed */ if (!canexit) { char *autoexec; autoexec = user_autoexec? user_autoexec: AUTO_EXEC; showinfo = 0; short_version(); /* JP: changed so that if autoexec does not exist, then don't ask to trace or bypass. */ if (exist(autoexec)) { printf("\nPress F8 for trace mode, or F5 to bypass %s... ", autoexec); key = WaitForFkeys(); putchar('\n'); if (key == KEY_F8) { tracemode = 1; } if (key == KEY_F5) { printf("Bypassing %s\n", autoexec); } else process_input(1, autoexec); } else { if(user_autoexec) printf("%s not found.\n", autoexec); #ifdef INCLUDE_CMD_DATE cmd_date(NULL); #endif #ifdef INCLUDE_CMD_TIME cmd_time(NULL); #endif } free(user_autoexec); } else { assert(user_autoexec == NULL); } /* Now the /C or /K option can be processed */ if (p) { process_input(1, p); return spawnAndExit; } /* Don't place something here that must be executed after a /K or /C */ if (showinfo) { short_version(); putchar('\n'); showcmds(NULL); putchar('\n'); } return E_None; }
int exec_parsed(){ // Execs a parsed command line. int error=0,i,got=-1,n; // Now execute the command. if(parse_nwords!=0){ // Search for a matching known command. for(i=0;i<max_cmds;i++){ if(strcmp(con_cmds[i].name,parse_words[0])==0){ got=i; } } if(got>=0){ // Make sure that we have the correct number of arguments for a command. if(con_cmds[got].type=='C'){ if(parse_nwords!=con_cmds[got].max+1){ got=-2; } } // If we have a variable, deal with it here. else{ // No arguments means view the variable. if(parse_nwords==1){ view_variable(got); got=1000; } // One argument means set the variable. if(parse_nwords==2){ // Find the value to set the variable to. if(con_cmds[got].type=='F'){ // It's a FIXED variable. n=ftofix(atof(parse_words[1])); } if(con_cmds[got].type=='I'){ // It's an INT. n=atoi(parse_words[1]); } if(con_cmds[got].type=='S'){ // It's a string. internal_setstring(con_cmds[got].s_mirror,parse_words[1]); } else{ // Put the value within limits. if(n<con_cmds[got].min){n=con_cmds[got].min;} if(n>con_cmds[got].max){n=con_cmds[got].max;} // Set the mirror to the value. con_cmds[got].mirror=n; } } // If we don't have one or two arguments, then its an error. if(parse_nwords>2){ got=-2; } } } // Execute an actual command, or set a given variable. switch(got){ case -1: internal_error();break; case 0: cmd_clear();break; case 1: player_crosshair=n;break; case 2: player_crosshair_color=n;break; case 3: cmd_dir();break; case 4: cmd_disconnect();break; case 5: cmd_exec();break; case 6: player_floors=n;break; case 7: player_fov_degrees=fixtof(n);break; case 8: player_fps=n;break; case 9: player_gamma=n;cmd_gamma();break; case 10: player_gfx_mode=n;cmd_gfx_mode();break; case 11: cmd_gfx_modes();break; case 12: player_heightfix=n;break; case 13: player_invert=n;break; case 14: light_con=n;break; case 15: light_depth=fixtof(n);break; case 16: cmd_loopdemo();break; case 17: cmd_map();break; case 18: cmd_mapinfo();break; case 19: player_map_rotate=n;break; case 20: player_map=n;break; case 21: player_map_size=n;break; case 22: cmd_mem();break; case 23: internal_setstring(player_pic_con,parse_words[1]); cmd_pic_con();break; case 24: cmd_playdemo();break; case 25: cmd_pwad();break; case 26: cmd_quit();break; case 27: cmd_recdemo();break; case 28: player_r_grad=n;break; case 29: player_r_gun=n;break; case 30: cmd_stop();break; case 31: cmd_syntax();break; case 32: cmd_time();break; case 33: cmd_timerefresh();break; case 34: player_trace=1;break; case 35: cmd_viewpic();break; case 36: cmd_viewtex();break; case 37: player_vsync=n;break; case 38: cmd_wads();break; case 39: player_walls=n;break; case 40: player_windowsize=n;break; } } // Return the error value. DEBUG: Do we use this? return(error); }
int main(void) { cmd_time("time", ""); return 1; }
int main (void) { sei(); uart_init(UART_BAUD_SELECT(9600, F_CPU)); uart_puts("\r\n\r\nTHIS PROGRAM USES 57600 BAUD - PLEASE CHANGE\r\n\r\n"); _delay_ms(100); uart_init(UART_BAUD_SELECT(57600, F_CPU)); cmd_clear(); uart_puts_P("\n\n\n\n\r"); uart_puts_P("--------------------------\r\n"); uart_puts_P("System [OK]\r\n"); systimer_init(); uart_puts_P("System Timer [OK]\r\n"); /* SD Karte Initilisieren */ cmd_init(); uart_puts_P("--------------------------\r\n\r\n"); _delay_ms(100); char input[50]={0}; static char parameters[10][32]; while(1) { for (uint8_t i = 0; i<=10; *parameters[++i]=0x00); // Input uart_puts_P("> "); uart_input(input); // Process Input getparams(input, 10, 32, parameters); char *cmd = parameters[0]; // Call Functions if (strings_equal(cmd, "ls")) { uint32_t cluster = 0; if (parameters[1][0] != 0x00) cluster = str2num(parameters[1], 16); cmd_ls(cluster); } else if (strings_equal(cmd, "cat")) { if (parameters[1][0] == 0x00 || parameters[2][0] == 0x00) cmd_help("cat"); else { uint64_t cluster = str2num(parameters[1], 16); uint64_t size = str2num(parameters[2], 16); cmd_cat(cluster, size); } } else if (strings_equal(cmd, "readtest")) { if (parameters[1][0] == 0x00 || parameters[2][0] == 0x00) cmd_help("readtest"); else { uint64_t cluster = str2num(parameters[1], 16); uint64_t size = str2num(parameters[2], 16); cmd_readtest(cluster, size); } } else if (strings_equal(cmd, "write")) { if (parameters[1][0] == 0x00 || parameters[2][0] == 0x00) cmd_help("write"); else { uint64_t cluster = str2num(parameters[1], 16); uint8_t adcport = str2num(parameters[2], 10); uint64_t maxsize = str2num(parameters[3], 16); uint8_t speed = str2num(parameters[4], 10); if (parameters[3][0] == 0x00) maxsize = 512; if (parameters[4][0] == 0x00) speed = 50; cmd_write(cluster, adcport, maxsize, speed); } } else if (strings_equal(cmd, "clear")) cmd_clear(); else if (strings_equal(cmd, "time")) cmd_time(); else if (strings_equal(cmd, "init")) cmd_init(); else if (strings_equal(cmd, "help")) cmd_help(parameters[1]); else uart_puts_P("Error: Command not found\n\r"); } while (1); return (1); }
int initialize(void) { //int rc; int comPath; /* path to COMMAND.COM (for COMSPEC/reload) */ char *newTTY; /* what to change TTY to */ int showinfo; /* show initial info only if no command line options */ int ec; /* error code */ unsigned offs; /* offset into environment segment */ int cmdlen; /* length of command line */ char *cmdline; /* command line duplicated into heap */ char *p, *h, *q; #ifdef FEATURE_CALL_LOGGING #ifndef INCLUDE_CMD_FDDEBUG FILE *f; #endif #endif /* Set up the host environment of COMMAND.COM */ /* Install the dummy handlers for Criter and ^Break */ initCBreak(); setvect(0x23, cbreak_handler); setvect(0x24, dummy_criter_handler); /* DOS shells patch the PPID to the own PID, how stupid this is, however, because then DOS won't terminate them, e.g. when a Critical Error occurs that is not detected by COMMAND.COM */ oldPSP = OwnerPSP; atexit(exitfct); OwnerPSP = _psp; dbg_printmem(); #ifdef DEBUG { void* p; if((p = malloc(5*1024)) == 0) dprintf(("[MEM: Out of memory allocating test block during INIT]")); else free(p); } #endif #ifdef FEATURE_KERNEL_SWAP_SHELL if(kswapInit()) { /* re-invoked */ if(kswapLoadStruc()) { /* OK, on success we need not really keep the shell trick (pretend we are our own parent), which might cause problems with beta-software-bugs ;-) In fact, KSSF will catch up our crashes and re-invoke FreeCOM, probably with the loss of any internal settings. */ OwnerPSP = oldPSP; return E_None; } } #endif /* Some elder DOSs may not pass an initializied environment segment */ if (env_glbSeg && !isMCB(SEG2MCB(env_glbSeg))) env_setGlbSeg(0); /* Disable the environment */ /* Now parse the command line parameters passed to COMMAND.COM */ /* Preparations */ newTTY = 0; comPath = tracemode = 0; showinfo = 1; /* Because FreeCom should be executed in a DOS3+ compatible environment most of the time, it is assumed that its path can be determined from the environment. This has the advantage that the string area is accessable very early in the run. The name of the current file is string #0. */ if((offs = env_string(0, 0)) != 0) /* OK, environment filled */ grabComFilename(0, (char far *)MK_FP(env_glbSeg, offs)); /* After that argv[0] is no longer used and maybe zapped. This also will help, as most programs altering the environment segment externally don't expect a string area. */ env_nullStrings(0); /* Aquire the command line, there are three possible sources: 1) DOS command line @PSP:0x80 as pascal string, 2) extended DOS command line environment variable CMDLINE, if peekb(PSP, 0x80) == 127,& 3) MKS command line @ENV:2, if peekb(ENV, 0) == '~' && peekb(ENV, 1) == '=' Currently implemented is version #1 only */ cmdlen = peekb(_psp, 0x80); if(cmdlen < 0 || cmdlen > 126) { error_corrupt_command_line(); cmdlen = 0; } /* duplicate the command line into the local address space */ if((cmdline = malloc(cmdlen + 1)) == 0) { error_out_of_memory(); /* Cannot recover from this problem */ return E_NoMem; } _fmemcpy((char far*)cmdline, MK_FP(_psp, 0x81), cmdlen); cmdline[cmdlen] = '\0'; #ifdef FEATURE_CALL_LOGGING #ifndef INCLUDE_CMD_FDDEBUG if((f = fopen(logFilename, "at")) == 0) { fprintf(stderr, "Cannot open logfile: \"%s\"\n", logFilename); } else { putc('"', f); if(ComPath) /* path to command.com already known */ fputs(ComPath, f); putc('"', f); putc(':', f); fputs(cmdline, f); putc('\n', f); fclose(f); } #else cmd_fddebug(logFilename); dbg_outc('"'); dbg_outs(ComPath); dbg_outc('"'); dbg_outc(':'); dbg_outsn(cmdline); #endif #endif canexit = 1; p = cmdline; /* start of the command line */ do { ec = leadOptions(&p, opt_init, 0); if(ec == E_NoOption) { /* /C or /K */ assert(p && *p); if(!isoption(p)) { error_quoted_c_k(); p = 0; break; } assert(p[1] && strchr("kKcC", p[1])); p += 2; /* p := start of command line to execute */ break; } else if(ec != E_None) { showhelp = 1; p = 0; break; } assert(p && !isoption(p) && !isspace(*p)); if(!*p) { p = 0; break; /* end of line reached */ } q = unquote(p, h = skip_word(p)); p = h; /* Skip this word */ if(!q) { error_out_of_memory(); p = 0; break; } if(!comPath) { /* 1st argument */ grabComFilename(1, (char far*)q); comPath = 1; free(q); } else if(!newTTY) { /* 2nd argument */ #ifdef INCLUDE_CMD_CTTY newTTY = q; #else error_ctty_excluded(); free(q); #endif } else { error_too_many_parameters(q); showhelp = 1; free(q); break; } } while(1); /* * Now: * + autoexec: AUTOEXEC.BAT file to be executed if /P switch * is enabled; if NULL, use default * + comPath: user-defined PATH to COMMAND.COM; if NULL, use * the one from the environment * + newTTY: the name of the device to be CTTY'ed; if NULL, * no change * + p: pointer to the command to be executed: * *p == 'c' or 'C' --> spawn command, then terminate shell * *p == 'k' or 'K' --> spawn command, then go interactive * &p[1] --> command line, unless the first character is an * argument character */ /* Now process the options */ #ifdef INCLUDE_CMD_CTTY if (newTTY) { /* change TTY as early as possible so the caller gets the messages into the correct channel */ cmd_ctty(newTTY); free(newTTY); } #endif if(!ComPath) { /* FreeCom is unable to find itself --> print error message */ /* Emergency error */ #undef TEXT_MSG_FREECOM_NOT_FOUND puts(TEXT_MSG_FREECOM_NOT_FOUND); return E_Useage; } /* First of all, set up the environment */ /* If a new valid size is specified, use that */ env_resizeCtrl |= ENV_USEUMB | ENV_ALLOWMOVE; if(newEnvSize > 16 && newEnvSize < 32767) env_setsize(0, newEnvSize); /* Otherwise the path is placed into the environment */ /* Set the COMSPEC variable. */ if(chgEnv("COMSPEC", ComPath)) { /* keep it silent */ /* Failed to add this variable, the most likely problem should be that the environment is too small --> it is increased and the operation is redone */ env_resize(0, strlen(ComPath) + 10); if(chgEnv("COMSPEC", ComPath)) chgEnv("COMSPEC", NULL); /* Cannot set -> zap an old one */ } inInit = 0; /* Install INT 24 Critical error handler */ /* Needs the ComPath variable, eventually */ if(!kswapContext) { /* Load the module/context into memory */ if((kswapContext = modContext()) == 0) { error_loading_context(); return E_NoMem; } #ifdef FEATURE_KERNEL_SWAP_SHELL if(swapOnExec != ERROR) kswapRegister(kswapContext); #endif } ctxtCreate(); /* re-use the already loaded Module */ setvect(0x24, (void interrupt(*)()) MK_FP(FP_SEG(kswapContext->cbreak_hdlr), kswapContext->ofs_criter)); if(internalBufLen) error_l_notimplemented(); if(inputBufLen) error_u_notimplemented(); if(tracemode) showinfo = 0; if (showhelp) displayString(TEXT_CMDHELP_COMMAND); if ((showhelp || exitflag) && canexit) return E_None; /* Now the /P option can be processed */ if(!canexit) { char *autoexec; autoexec = user_autoexec? user_autoexec: AUTO_EXEC; showinfo = 0; short_version(); if(skipAUTOEXEC) { /* /D option */ showinfo = 0; displayString(TEXT_MSG_INIT_BYPASSING_AUTOEXEC, autoexec); } else { if(exist(autoexec)) { #ifdef FEATURE_BOOT_KEYS struct REGPACK r; int key; r.r_ax = 0x3000; /* Get DOS version & OEM ID */ intr(0x21, &r); if(!tracemode /* /Y --> F8 on CONFIG.SYS */ || ((r.r_bx & 0xff00) == 0xfd00 /* FreeDOS >= build 2025 */ && !(r.r_cx > 0x101 || (r.r_bx & 0xff) > 24))) { displayString(TEXT_MSG_INIT_BYPASS_AUTOEXEC, autoexec); key = cgetchar_timed(3); putchar('\n'); } else key = 0; if(key == KEY_F8) tracemode = 1; if(key == KEY_F5) displayString(TEXT_MSG_INIT_BYPASSING_AUTOEXEC, autoexec); else #endif process_input(1, autoexec); } else { if(user_autoexec) error_sfile_not_found(user_autoexec); #ifdef INCLUDE_CMD_DATE cmd_date(0); #endif #ifdef INCLUDE_CMD_TIME cmd_time(0); #endif } } free(user_autoexec); } else { assert(user_autoexec == 0); } /* Now the /C or /K option can be processed */ if (p) { process_input(1, p); return spawnAndExit; } /* Don't place something here that must be executed after a /K or /C */ if (showinfo) { short_version(); #ifndef DEBUG putchar('\n'); showcmds(0); putchar('\n'); #endif } return E_None; }
void cli_loop(void) { while (1) { curchar = getline(">"); printf("\n"); /* Process medium changes before executing the command */ if (disk_state != DISK_OK && disk_state != DISK_REMOVED) { FRESULT res; printf("Medium changed... "); res = f_mount(0,&fatfs); if (res != FR_OK) { printf("Failed to mount new medium, result %d\n",res); } else { printf("Ok\n"); } } /* Remove whitespace */ while (*curchar == ' ') curchar++; while (strlen(curchar) > 0 && curchar[strlen(curchar)-1] == ' ') curchar[strlen(curchar)-1] = 0; /* Ignore empty lines */ if (strlen(curchar) == 0) continue; /* Parse command */ int8_t command = parse_wordlist(command_words); if (command < 0) continue; FRESULT res; switch (command) { case CMD_CD: #if _FS_RPATH if (strlen(curchar) == 0) { f_getcwd((TCHAR*)file_lfn, 255); printf("%s\n",file_lfn); break; } res = f_chdir((const TCHAR *)curchar); if (res != FR_OK) { printf("chdir %s failed with result %d\n",curchar,res); } else { printf("Ok.\n"); } #else printf("cd not supported.\n"); res; #endif break; case CMD_RESET: cmd_reset(); break; case CMD_SRESET: cmd_sreset(); break; case CMD_DIR: case CMD_LS: cmd_show_directory(); break; case CMD_RESUME: return; break; case CMD_LOADROM: cmd_loadrom(); break; case CMD_LOADRAW: cmd_loadraw(); break; case CMD_SAVERAW: cmd_saveraw(); break; case CMD_RM: cmd_rm(); break; case CMD_D4: cmd_d4(); break; case CMD_VMODE: cmd_vmode(); break; case CMD_PUT: cmd_put(); break; case CMD_MAPPER: cmd_mapper(); break; case CMD_SETTIME: cmd_settime(); break; case CMD_TIME: cmd_time(); break; case CMD_TEST: testbattery(); break; case CMD_SETFEATURE: cmd_setfeature(); break; case CMD_HEXDUMP: cmd_hexdump(); break; case CMD_W8: cmd_w8(); break; case CMD_W16: cmd_w16(); break; } } }