📄 mon-command.c
字号:
/* * Only process the history if we have a command and *a history. */ if (strlen (buffer)) { if (history_next && (history == history_next)) { /* * Do not place the last command into the history *if the same. */ if (strcmp (history_buffer[history_next - 1], buffer)) repeating = 0; } else repeating = 0; } if (!repeating) { memcpy (history_buffer[history_next], buffer, RTEMS_COMMAND_BUFFER_SIZE); history_pos[history_next] = pos; if (history_next < (RTEMS_COMMAND_HISTORIES - 1)) history_next++; else { memmove (history_buffer[0], history_buffer[1], RTEMS_COMMAND_BUFFER_SIZE * (RTEMS_COMMAND_HISTORIES - 1)); memmove (&history_pos[0], &history_pos[1], sizeof (history_pos[0]) * (RTEMS_COMMAND_HISTORIES - 1)); } } else {#ifdef ENABLE_ENTER_REPEATS if (history_next) memcpy (buffer, history_buffer[history_next - 1], RTEMS_COMMAND_BUFFER_SIZE);#endif } memmove (command, buffer, RTEMS_COMMAND_BUFFER_SIZE); return repeating; break; default: if ((pos < (RTEMS_COMMAND_BUFFER_SIZE - 1)) && (c >= ' ') && (c <= 'z')) { int end; end = strlen (buffer); if ((pos < end) && (end < RTEMS_COMMAND_BUFFER_SIZE)) { int ch, bs; for (ch = end + 1; ch > pos; ch--) buffer[ch] = buffer[ch - 1]; printf (buffer + pos); for (bs = 0; bs < (end - pos + 1); bs++) putchar ('\b'); } buffer[pos++] = c; if (pos > end) buffer[pos] = '\0'; putchar (c); } break; } } } }}#endif/* * make_argv(cp): token-count * Break up the command line in 'cp' into global argv[] and argc (return * value). */intrtems_monitor_make_argv( char *cp, int *argc_p, char **argv){ int argc = 0; while ((cp = strtok(cp, " \t\n\r"))) { argv[argc++] = cp; cp = (char *) NULL; } argv[argc] = (char *) NULL; /* end of argv */ return *argc_p = argc;}/* * Read and break up a monitor command * * We have to loop on the gets call, since it will return NULL under UNIX * RTEMS when we get a signal (eg: SIGALRM). */intrtems_monitor_command_read(char *command, int *argc, char **argv){ char *env_prompt; env_prompt = getenv("RTEMS_MONITOR_PROMPT"); /* * put node number in the prompt if we are multiprocessing */ if (!rtems_configuration_get_user_multiprocessing_table ()) sprintf (monitor_prompt, "%s", (env_prompt == NULL) ? MONITOR_PROMPT: env_prompt); else if (rtems_monitor_default_node != rtems_monitor_node) sprintf (monitor_prompt, "%d-%s-%d", rtems_monitor_node, (env_prompt == NULL) ? MONITOR_PROMPT : env_prompt, rtems_monitor_default_node); else sprintf (monitor_prompt, "%d-%s", rtems_monitor_node, (env_prompt == NULL) ? MONITOR_PROMPT : env_prompt);#if defined(RTEMS_UNIX) /* RTEMS on unix gets so many interrupt system calls this is hosed */ printf ("%s> ", monitor_prompt); fflush (stdout); while (gets(command) == (char *) 0) ;#else rtems_monitor_line_editor (command);#endif return rtems_monitor_make_argv (command, argc, argv);}/* * Look up a command in a command table * */rtems_monitor_command_entry_t *rtems_monitor_command_lookup( rtems_monitor_command_entry_t *table, int argc, char **argv){ int command_length; rtems_monitor_command_entry_t *found_it = NULL; command_length = strlen (argv[0]); if ((table == 0) || (argv[0] == 0)) return 0; while (table) { if (table->command) { /* * Check for ambiguity */ if (!strncmp (table->command, argv[0], command_length)) { if (found_it) { return 0; } else found_it = table; } } table = table->next; } /* * No ambiguity (the possible partial command was unique after all) */ if (found_it) { if (found_it->command_function == 0) return 0; return found_it; } return 0;}voidrtems_monitor_show_help ( rtems_monitor_command_entry_t *help_cmd, int max_cmd_len){#define MAX_HELP_LINE_LENGTH (75 - max_cmd_len - 2) if (help_cmd && help_cmd->command) { const char *help = help_cmd->usage; int help_len = strlen (help); int spaces = max_cmd_len - strlen (help_cmd->command); int show_this_line = 0; int line_one = 1; int c; printf ("%s", help_cmd->command); if (help_len == 0) { printf (" - No help associated.\n"); return; } while (help_len) { printf ("%*c", spaces, ' '); if (line_one) printf (" - "); spaces = max_cmd_len + 2; line_one = 0; /* * See if greater then the line length if so, work back * from the end for a space, tab or lf or cr. */ if (help_len > MAX_HELP_LINE_LENGTH) { for (show_this_line = MAX_HELP_LINE_LENGTH - 1; show_this_line; show_this_line--) if ((help[show_this_line] == ' ') || (help[show_this_line] == '\n') || (help[show_this_line] == '\r')) break; /* * If show_this_line is 0, it is a very long word !! */ if (show_this_line == 0) show_this_line = MAX_HELP_LINE_LENGTH - 1; } else show_this_line = help_len; for (c = 0; c < show_this_line; c++) if ((help[c] == '\r') || (help[c] == '\n')) show_this_line = c; else putchar (help[c]); printf ("\n"); help += show_this_line; help_len -= show_this_line; /* * Move past the line feeds or what ever else is being skipped. */ while (help_len) { if ((*help != '\r') && (*help != '\n')) break; if (*help != ' ') { help++; help_len--; break; } help++; help_len--; } } }}voidrtems_monitor_command_usage( rtems_monitor_command_entry_t *table, char *command_string){ rtems_monitor_command_entry_t *command = table; int max_cmd_len = 0; /* if first entry in table is a usage, then print it out */ if (command_string && (*command_string != '\0')) { char *argv[2]; argv[0] = command_string; argv[1] = 0; command = rtems_monitor_command_lookup (table, 1, argv); if (command) rtems_monitor_show_help (command, strlen (command_string)); else printf ("Unrecognised command; try just 'help'\n"); return; } /* * Find the largest command size. */ while (command) { int len = command->command ? strlen (command->command) : 0 ; if (len > max_cmd_len) max_cmd_len = len; command = command->next; } max_cmd_len++; command = table; /* * Now some nice formatting for the help. */ while (command) { rtems_monitor_show_help (command, max_cmd_len); command = command->next; }}voidrtems_monitor_help_cmd( int argc, char **argv, unsigned32 command_arg, boolean verbose){ int arg; rtems_monitor_command_entry_t *command; command = (rtems_monitor_command_entry_t *) command_arg; if (argc == 1) rtems_monitor_command_usage(command, 0); else { for (arg = 1; argv[arg]; arg++) rtems_monitor_command_usage(command, argv[arg]); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -