/** * @brief Shell thread function. * * @param[in] p pointer to a @p BaseSequentialStream object */ THD_FUNCTION(shellThread, 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]; chprintf(chp, "\r\nChibiOS/RT Shell\r\n"); while (true) { chprintf(chp, "ch> "); if (shellGetLine(chp, line, sizeof(line))) { #if (SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_) chprintf(chp, "\r\nlogout"); break; #else /* Putting a delay in order to avoid an endless loop trying to read an unavailable stream.*/ osalThreadSleepMilliseconds(100); #endif } lp = parse_arguments(line, &tokp); cmd = lp; n = 0; while ((lp = parse_arguments(NULL, &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 (strcmp(cmd, "exit") == 0) { if (n > 0) { usage(chp, "exit"); continue; } break; } else if (strcmp(cmd, "help") == 0) { if (n > 0) { usage(chp, "help"); continue; } chprintf(chp, "Commands: help exit "); list_commands(chp, shell_local_commands); if (scp != NULL) list_commands(chp, scp); chprintf(chp, "\r\n"); } else if (cmdexec(shell_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); }
/** * @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; }
/** * @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); }
void printHelp() { char* fn = "garfield-shell"; printf("%s utility\n", fn); //options printf("Usage: %s [options] <mode> [mode-args]\n", fn); printf("Available options:\n"); printf("\t-u | --user <user>\tGarfield user name\n"); printf("\t-p | --pass <password>\tGarfield password\n"); printf("\t-d | --debug\t\tPrint some debug info\n"); printf("\t-g | --pgpass\t\tUse pgpass file\n"); printf("\t-h | --help\t\tShow this help\n"); //examples printf("\nExamples:\n"); printf("%s -u test -p test\t\topens shell with user *test* and password *test*\n", fn); shellExit(); }
/** * shell function */ int shell() { debug("shell init"); checkLogin(); char input[MAXLENGTH]; for (;;) { printf("%s>", getUser()); read_line(input); if (sequals(input, "exit")) { debug("shut down"); shellExit(); } else if (begins(input, "set ")) { debug("exec set cmd"); parseSet(input + 4); } else if (begins(input, "list ")) { debug("exec list cmd"); parseList(input + 5); } else if (begins(input, "search ")) { debug("exec find cmd from search"); find(input + 7); } else if (begins(input, "find ")) { debug("exec find cmd"); find(input + 5); } else if (begins(input, "buy ")) { debug("exec buy cmd"); buy(input + 4); } else if (begins(input, "help")) { debug("exec help cmd"); printInternHelp(); } else if (begins(input, "balance")) { debug("exec balance cmd"); balanceUser(); } else { debug("no match found in shell"); printf("Don't know what you mean...\n"); } } return 0; }
/** * @brief Shell thread function. * * @param[in] p pointer to a @p BaseSequentialStream object */ THD_FUNCTION(shellThread, p) { int n; ShellConfig *scfg = p; BaseSequentialStream *chp = scfg->sc_channel; const ShellCommand *scp = scfg->sc_commands; char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH]; char *args[SHELL_MAX_ARGUMENTS + 1]; #if SHELL_USE_HISTORY == TRUE *(scfg->sc_histbuf) = 0; ShellHistory hist = { scfg->sc_histbuf, scfg->sc_histsize, 0, 0, 0 }; ShellHistory *shp = &hist; #else ShellHistory *shp = NULL; #endif chprintf(chp, SHELL_NEWLINE_STR); chprintf(chp, "ChibiOS/RT Shell"SHELL_NEWLINE_STR); while (true) { chprintf(chp, SHELL_PROMPT_STR); if (shellGetLine(scfg, line, sizeof(line), shp)) { #if (SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_) chprintf(chp, SHELL_NEWLINE_STR); chprintf(chp, "logout"); break; #else /* Putting a delay in order to avoid an endless loop trying to read an unavailable stream.*/ osalThreadSleepMilliseconds(100); #endif } lp = parse_arguments(line, &tokp); cmd = lp; n = 0; while ((lp = parse_arguments(NULL, &tokp)) != NULL) { if (n >= SHELL_MAX_ARGUMENTS) { chprintf(chp, "too many arguments"SHELL_NEWLINE_STR); cmd = NULL; break; } args[n++] = lp; } args[n] = NULL; if (cmd != NULL) { if (strcmp(cmd, "help") == 0) { if (n > 0) { shellUsage(chp, "help"); continue; } chprintf(chp, "Commands: help "); list_commands(chp, shell_local_commands); if (scp != NULL) list_commands(chp, scp); chprintf(chp, SHELL_NEWLINE_STR); } else if (cmdexec(shell_local_commands, chp, cmd, n, args) && ((scp == NULL) || cmdexec(scp, chp, cmd, n, args))) { chprintf(chp, "%s", cmd); chprintf(chp, " ?"SHELL_NEWLINE_STR); } } } shellExit(MSG_OK); }