/** * @brief Shell thread function. * * @param[in] p pointer to a @p BaseSequentialStream object * @return Termination reason. * @retval RDY_OK terminated by command. * @retval RDY_RESET terminated by reset condition on the I/O channel. * * @notapi */ static msg_t shell_thread(void *p) { int n; BaseSequentialStream *chp = ((ShellConfig *)p)->sc_channel; const ShellCommand *scp = ((ShellConfig *)p)->sc_commands; char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH]; char *args[SHELL_MAX_ARGUMENTS + 1]; chRegSetThreadName("shell"); chprintf(chp, "\r\nChibiOS/RT Shell\r\n"); while (TRUE) { chprintf(chp, "mamad_OS> "); if (shellGetLine(chp, line, sizeof(line))) { chprintf(chp, "\r\nlogout"); break; } lp = _strtok(line, " \t", &tokp); cmd = lp; n = 0; while ((lp = _strtok(NULL, " \t", &tokp)) != NULL) { if (n >= SHELL_MAX_ARGUMENTS) { chprintf(chp, "too many arguments\r\n"); cmd = NULL; break; } args[n++] = lp; } args[n] = NULL; if (cmd != NULL) { if (strcasecmp(cmd, "exit") == 0) { if (n > 0) { usage(chp, "exit"); continue; } break; } else if (strcasecmp(cmd, "help") == 0) { if (n > 0) { usage(chp, "help"); continue; } // chprintf(chp, "Commands: help exit "); chprintf(chp, "Available Commands : \r\n"); chprintf(chp,"help\r\n"); list_commands(chp, local_commands); if (scp != NULL) list_commands(chp, scp); chprintf(chp, "\r\n"); } else if (cmdexec(local_commands, chp, cmd, n, args) && ((scp == NULL) || cmdexec(scp, chp, cmd, n, args))) { chprintf(chp, "%s", cmd); chprintf(chp, " ?\r\n"); } } } shellExit(RDY_OK); /* Never executed, silencing a warning.*/ return 0; }
void shellStart(const ShellConfig *p) { int n; Stream *chp = p->sc_channel; const ShellCommand *scp = p->sc_commands; char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH]; char *args[SHELL_MAX_ARGUMENTS + 1]; chp->printf("\r\nEmbed/RX Shell\r\n"); while (true) { chp->printf(">> "); if (shellGetLine(chp, line, sizeof(line))) { chp->printf("\r\nlogout"); break; } lp = _strtok(line, " \t", &tokp); cmd = lp; n = 0; while ((lp = _strtok(NULL, " \t", &tokp)) != NULL) { if (n >= SHELL_MAX_ARGUMENTS) { chp->printf("too many arguments\r\n"); cmd = NULL; break; } args[n++] = lp; } args[n] = NULL; if (cmd != NULL) { if (strcasecmp(cmd, "exit") == 0) { if (n > 0) { shellUsage(chp, "exit"); continue; } // Break here breaks the outer loop // hence, we exit the shell. break; } else if (strcasecmp(cmd, "help") == 0) { if (n > 0) { shellUsage(chp, "help"); continue; } chp->printf("Commands: help exit "); list_commands(chp, local_commands); if (scp != NULL) list_commands(chp, scp); chp->printf("\r\n"); } else if (cmdexec(local_commands, chp, cmd, n, args) && ((scp == NULL) || cmdexec(scp, chp, cmd, n, args))) { chp->printf("%s", cmd); chp->printf(" ?\r\n"); } } } }
/** * @brief Shell thread function. * * @param[in] p pointer to a @p BaseSequentialStream object */ static THD_FUNCTION(shell_thread, p) { int n; BaseSequentialStream *chp = ((ShellConfig *)p)->sc_channel; const ShellCommand *scp = ((ShellConfig *)p)->sc_commands; char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH]; char *args[SHELL_MAX_ARGUMENTS + 1]; chRegSetThreadName("shell"); chprintf(chp, "\r\nChibiOS/RT Shell\r\n"); while (true) { chprintf(chp, "ch> "); if (shellGetLine(chp, line, sizeof(line))) { chprintf(chp, "\r\nlogout"); break; } lp = _strtok(line, " \t", &tokp); cmd = lp; n = 0; while ((lp = _strtok(NULL, " \t", &tokp)) != NULL) { if (n >= SHELL_MAX_ARGUMENTS) { chprintf(chp, "too many arguments\r\n"); cmd = NULL; break; } args[n++] = lp; } args[n] = NULL; if (cmd != NULL) { if (strcasecmp(cmd, "exit") == 0) { if (n > 0) { usage(chp, "exit"); continue; } break; } else if (strcasecmp(cmd, "help") == 0) { if (n > 0) { usage(chp, "help"); continue; } chprintf(chp, "Commands: help exit "); list_commands(chp, local_commands); if (scp != NULL) list_commands(chp, scp); chprintf(chp, "\r\n"); } else if (cmdexec(local_commands, chp, cmd, n, args) && ((scp == NULL) || cmdexec(scp, chp, cmd, n, args))) { chprintf(chp, "%s", cmd); chprintf(chp, " ?\r\n"); } } } shellExit(MSG_OK); }
int split(char *str, const char *sep, double **out){ int i = strlen(str); double *buf = init_ptr(i, (double) 0); i = 0; char *pch; char *end_ptr; while(str != NULL){ pch = _strtok(&str, sep); if(strlen(pch) == 0){ delete [] pch; continue; } buf[i++] = strtod(pch, &end_ptr); // Check if double if(*end_ptr) i--; delete [] pch; } *out = init_ptr(i, (double) 0); memcpy(*out, buf, i*sizeof(double)); delete [] buf; return(i); }
/*************************** split() function to, given a string (str), splits into array (out) on char (sep) ***************************/ int split(char *str, const char *sep, int **out){ int i = strlen(str); int *buf = init_ptr(i, 0); i = 0; char *pch; char *end_ptr; while(str != NULL){ pch = _strtok(&str, sep); if(strlen(pch) == 0){ delete [] pch; continue; } buf[i++] = strtol(pch, &end_ptr, 0); // Check if an int if(*end_ptr) i--; delete [] pch; } *out = init_ptr(i, 0); // FGV: why the need for *out?!?!!? memcpy(*out, buf, i*sizeof(int)); delete [] buf; return(i); }
int split(char *str, const char *sep, char ***out){ int i = strlen(str); char **buf = init_ptr(i, 0, (char*) NULL); i = 0; while(str != NULL) buf[i++] = _strtok(&str, sep); *out = init_ptr(i, 0, (char*) NULL); memcpy(*out, buf, i*sizeof(char*)); delete [] buf; return(i); }
/** * @brief Shell thread function. * * @param[in] p pointer to a @p BaseSequentialStream object * @return Termination reason. * @retval RDY_OK terminated by command. * @retval RDY_RESET terminated by reset condition on the I/O channel. */ static msg_t shell_thread(void *p) { int n; msg_t msg = RDY_OK; BaseSequentialStream *chp = ((ShellConfig *)p)->sc_channel; const ShellCommand *scp = ((ShellConfig *)p)->sc_commands; char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH]; char *args[SHELL_MAX_ARGUMENTS + 1]; chRegSetThreadName("shell"); chprintf(chp, "\r\nChibiOS/RT Shell\r\n"); while (TRUE) { chprintf(chp, "ch> "); if (shellGetLine(chp, line, sizeof(line))) { chprintf(chp, "\r\nlogout"); break; } lp = _strtok(line, " \009", &tokp); cmd = lp; n = 0; while ((lp = _strtok(NULL, " \009", &tokp)) != NULL) { if (n >= SHELL_MAX_ARGUMENTS) { chprintf(chp, "too many arguments\r\n"); cmd = NULL; break; } args[n++] = lp; } args[n] = NULL; if (cmd != NULL) { if (strcasecmp(cmd, "exit") == 0) { if (n > 0) { usage(chp, "exit"); continue; } break; } else if (strcasecmp(cmd, "help") == 0) { if (n > 0) { usage(chp, "help"); continue; } chprintf(chp, "Commands: help exit "); list_commands(chp, local_commands); if (scp != NULL) list_commands(chp, scp); chprintf(chp, "\r\n"); } else if (cmdexec(local_commands, chp, cmd, n, args) && ((scp == NULL) || cmdexec(scp, chp, cmd, n, args))) { chprintf(chp, "%s", cmd); chprintf(chp, " ?\r\n"); } } } /* Atomically broadcasting the event source and terminating the thread, there is not a chSysUnlock() because the thread terminates upon return.*/ chSysLock(); chEvtBroadcastI(&shell_terminated); chThdExitS(msg); return 0; /* Never executed.*/ }
bool parse_srt_timing(srt_event *e, char *s, const uint8_t *flags) { char token[MAXLINE]; uint16_t i = 0; int *j; char *w_token = _("Can't get %s timing from this token: '%s' at line '%u'."); char *p = s, *v; bool result = true; struct point *xy; char *delim = ""; if ((i = _strtok(s, "-->")) <= 0) return false; strncpy(token, p, i); token[i] = '\0'; trim_spaces(token, LINE_START | LINE_END); if (!get_srt_timing(&e->start, token)) { log_msg(warn, w_token, "start", token, line_num); return false; } p = p + i + 3; /* " 00:00:00,000 " + "-->" */ while (*p == ' ') p++; /* " 00:00:00,000 --> |00:00:00,000" */ if ((i = _strtok(token, (flags) ? " " : "")) <= 0) return false; strncpy(token, p, i); if (!get_srt_timing(&e->end, token)) { log_msg(warn, w_token, "end", token, line_num); return false; } if (result && flags) { p += i; /* " 00:00:00,000 --> 00:00:00,000| ..." */ if (*flags & SRT_E_HAVE_POSITION) { delim = " "; trim_spaces(p, LINE_START); string_lowercase(p, 0); for (i = 0; (i = _strtok(p, delim)) > 0;) { strncpy(token, p, i); token[i] = '\0'; trim_spaces(token, LINE_END); v = strchr(token, ':'), v += 1; xy = (*(token + 1) == '1') ? &e->top_left : &e->bottom_right; j = (*token == 'x') ? &xy->x : &xy->y ; *j = atoi(v); p += i; trim_spaces(p, LINE_START); } } else if (*flags & SRT_E_HAVE_STYLE) { delim = ","; /* TODO: make it "implemented" */ log_msg(error, MSG_W_UNIMPL); } } return result; }
int main(int argc, char **argv){ char ElfPath[32]; DINIT(); DPRINTF("OPL EE core start!\n"); SifInitRpc(0); int i = 0; if (!_strncmp(argv[i], "USB_MODE", 8)) GameMode = USB_MODE; else if (!_strncmp(argv[i], "ETH_MODE", 8)) GameMode = ETH_MODE; else if (!_strncmp(argv[i], "HDD_MODE", 8)) GameMode = HDD_MODE; DPRINTF("Game Mode = %d\n", GameMode); DisableDebug = 0; if (!_strncmp(&argv[i][9], "1", 1)) { DisableDebug = 1; DPRINTF("Debug Colors disabled\n"); } PS2Logo = 0; if (!_strncmp(&argv[i][11], "1", 1)) { PS2Logo = 1; DPRINTF("PS2 Logo enabled\n"); } char *p = _strtok(&argv[i][13], " "); if (!_strncmp(p, "Browser", 7)) ExitPath[0] = '\0'; else _strcpy(ExitPath, p); DPRINTF("Exit Path = (%s)\n", ExitPath); p = _strtok(NULL, " "); HDDSpindown = _strtoui(p); DPRINTF("HDD Spindown = %d\n", HDDSpindown); p = _strtok(NULL, " "); _strcpy(g_ps2_ip, p); p = _strtok(NULL, " "); _strcpy(g_ps2_netmask, p); p = _strtok(NULL, " "); _strcpy(g_ps2_gateway, p); g_ps2_ETHOpMode=_strtoui(_strtok(NULL, " ")); DPRINTF("IP=%s NM=%s GW=%s mode: %d\n", g_ps2_ip, g_ps2_netmask, g_ps2_gateway, g_ps2_ETHOpMode); #ifdef CHEAT EnableCheatOp = (gCheatList = (void*)_strtoui(_strtok(NULL, " "))) != NULL; DPRINTF("PS2RD Cheat Engine = %s\n", EnableCheatOp==0?"Disabled":"Enabled"); #endif #ifdef GSM EnableGSMOp = _strtoi(_strtok(NULL, " ")); DPRINTF("GSM = %s\n", EnableGSMOp==0?"Disabled":"Enabled"); #endif i++; ModStorageStart = (void*)_strtoui(_strtok(argv[i], " ")); ModStorageEnd = (void*)_strtoui(_strtok(NULL, " ")); i++; argv[i][11]=0x00; // fix for 8+3 filename. _strcpy(ElfPath, "cdrom0:\\"); _strcat(ElfPath, argv[i]); _strcat(ElfPath, ";1"); strncpy(GameID, argv[i], sizeof(GameID) - 1); GameID[sizeof(GameID) - 1] = '\0'; DPRINTF("Elf path = '%s'\n", ElfPath); DPRINTF("Game ID = '%s'\n", GameID); i++; // bitmask of the compat. settings g_compat_mask = _strtoui(argv[i]); DPRINTF("Compat Mask = 0x%02x\n", g_compat_mask); i++; #ifdef CHEAT if(EnableCheatOp){ EnableCheats(); } #endif #ifdef GSM if(EnableGSMOp){ u32 interlace, mode, ffmd, dx_offset, dy_offset, skip_videos_fix; u64 display, syncv, smode2; interlace=_strtoui(_strtok(argv[i], " ")); mode=_strtoui(_strtok(NULL, " ")); ffmd=_strtoui(_strtok(NULL, " ")); display=_strtoul(_strtok(NULL, " ")); syncv=_strtoul(_strtok(NULL, " ")); smode2=_strtoui(_strtok(NULL, " ")); dx_offset=_strtoui(_strtok(NULL, " ")); dy_offset=_strtoui(_strtok(NULL, " ")); skip_videos_fix=_strtoui(_strtok(NULL, " ")); UpdateGSMParams(interlace, mode, ffmd, display, syncv, smode2, dx_offset, dy_offset, skip_videos_fix); EnableGSM(); } #endif set_ipconfig(); /* installing kernel hooks */ DPRINTF("Installing Kernel Hooks...\n"); Install_Kernel_Hooks(); if(!DisableDebug) GS_BGCOLOUR = 0xff0000; //Blue SifExitRpc(); DPRINTF("Executing '%s'...\n", ElfPath); //PS2LOGO Caller, based on l_oliveira & SP193 tips if (PS2Logo) { char *argvs[1]; argvs[0] = ElfPath; argvs[1] = NULL; LoadExecPS2("rom0:PS2LOGO", 1, argvs); } else { LoadExecPS2(ElfPath, 0, NULL); } if(!DisableDebug) GS_BGCOLOUR = 0x0000ff; //Red DPRINTF("LoadExecPS2 failed!\n"); SleepThread(); return 0; }
void Shell::process(void const *argument) { char ch; static char line[SHELL_MAX_LINE_LEN]; bool ret; char *cmd, *argPos, *tok; int i; static char *args[SHELL_MAX_ARGUMENTS + 1]; const Command *exec; int result; TraceLine(); Trace("welcome to gBike"); TraceLine(); m_pthread = (Thread*)argument; memset(line, 0, SHELL_MAX_LINE_LEN); while(m_exit == false) { osEvent evt = m_serialQ.get(); if (evt.status != osEventMessage) { Trace("queue->get() return %02x status", evt.status); continue; } ch = (char)evt.value.v; ret = getLine(ch, line, SHELL_MAX_LINE_LEN); if (false == ret) continue; cmd = _strtok(line, " \t", &tok); i = 0; while((argPos = _strtok(NULL," \t", &tok)) != NULL) { if (i >= SHELL_MAX_ARGUMENTS) { Trace("too many arguments!"); cmd = NULL; break; } args[i++] = argPos; } args[i] = NULL; if (cmd == NULL) { goto loop; } exec = findCommand(cmd); if (exec) { exec->function(i, args, &result); } else { Trace("unknow command:%s", cmd); } loop: memset(line, 0, SHELL_MAX_LINE_LEN); } }