?? cli-script.c
字號:
ret = recurse_read_control_structure (next); control_level--; if (ret != simple_control) break; } } dont_repeat (); return ret;}/* Read lines from the input stream and accumulate them in a chain of struct command_line's, which is then returned. For input from a terminal, the special command "end" is used to mark the end of the input, and is not included in the returned chain of commands. */#define END_MESSAGE "End with a line saying just \"end\"."struct command_line *read_command_lines (char *prompt_arg, int from_tty){ struct command_line *head, *tail, *next; struct cleanup *old_chain; enum command_control_type ret; enum misc_command_type val; control_level = 0; if (deprecated_readline_begin_hook) { /* Note - intentional to merge messages with no newline */ (*deprecated_readline_begin_hook) ("%s %s\n", prompt_arg, END_MESSAGE); } else if (from_tty && input_from_terminal_p ()) { printf_unfiltered ("%s\n%s\n", prompt_arg, END_MESSAGE); gdb_flush (gdb_stdout); } head = tail = NULL; old_chain = NULL; while (1) { val = read_next_line (&next); /* Ignore blank lines or comments. */ if (val == nop_command) continue; if (val == end_command) { ret = simple_control; break; } if (val != ok_command) { ret = invalid_control; break; } if (next->control_type == while_control || next->control_type == if_control) { control_level++; ret = recurse_read_control_structure (next); control_level--; if (ret == invalid_control) break; } if (tail) { tail->next = next; } else { head = next; old_chain = make_cleanup_free_command_lines (&head); } tail = next; } dont_repeat (); if (head) { if (ret != invalid_control) { discard_cleanups (old_chain); } else do_cleanups (old_chain); } if (deprecated_readline_end_hook) { (*deprecated_readline_end_hook) (); } return (head);}/* Free a chain of struct command_line's. */voidfree_command_lines (struct command_line **lptr){ struct command_line *l = *lptr; struct command_line *next; struct command_line **blist; int i; while (l) { if (l->body_count > 0) { blist = l->body_list; for (i = 0; i < l->body_count; i++, blist++) free_command_lines (blist); } next = l->next; xfree (l->line); xfree (l); l = next; } *lptr = NULL;}static voiddo_free_command_lines_cleanup (void *arg){ free_command_lines (arg);}struct cleanup *make_cleanup_free_command_lines (struct command_line **arg){ return make_cleanup (do_free_command_lines_cleanup, arg);}struct command_line *copy_command_lines (struct command_line *cmds){ struct command_line *result = NULL; if (cmds) { result = (struct command_line *) xmalloc (sizeof (struct command_line)); result->next = copy_command_lines (cmds->next); result->line = xstrdup (cmds->line); result->control_type = cmds->control_type; result->body_count = cmds->body_count; if (cmds->body_count > 0) { int i; result->body_list = (struct command_line **) xmalloc (sizeof (struct command_line *) * cmds->body_count); for (i = 0; i < cmds->body_count; i++) result->body_list[i] = copy_command_lines (cmds->body_list[i]); } else result->body_list = NULL; } return result;}static voidvalidate_comname (char *comname){ char *p; if (comname == 0) error_no_arg ("name of command to define"); p = comname; while (*p) { if (!isalnum (*p) && *p != '-' && *p != '_') error ("Junk in argument list: \"%s\"", p); p++; }}/* This is just a placeholder in the command data structures. */static voiduser_defined_command (char *ignore, int from_tty){}voiddefine_command (char *comname, int from_tty){#define MAX_TMPBUF 128 enum cmd_hook_type { CMD_NO_HOOK = 0, CMD_PRE_HOOK, CMD_POST_HOOK }; struct command_line *cmds; struct cmd_list_element *c, *newc, *oldc, *hookc = 0; char *tem = comname; char *tem2; char tmpbuf[MAX_TMPBUF]; int hook_type = CMD_NO_HOOK; int hook_name_size = 0; #define HOOK_STRING "hook-"#define HOOK_LEN 5#define HOOK_POST_STRING "hookpost-"#define HOOK_POST_LEN 9 validate_comname (comname); /* Look it up, and verify that we got an exact match. */ c = lookup_cmd (&tem, cmdlist, "", -1, 1); if (c && strcmp (comname, c->name) != 0) c = 0; if (c) { int q; if (c->class == class_user || c->class == class_alias) q = query ("Redefine command \"%s\"? ", c->name); else q = query ("Really redefine built-in command \"%s\"? ", c->name); if (!q) error ("Command \"%s\" not redefined.", c->name); } /* If this new command is a hook, then mark the command which it is hooking. Note that we allow hooking `help' commands, so that we can hook the `stop' pseudo-command. */ if (!strncmp (comname, HOOK_STRING, HOOK_LEN)) { hook_type = CMD_PRE_HOOK; hook_name_size = HOOK_LEN; } else if (!strncmp (comname, HOOK_POST_STRING, HOOK_POST_LEN)) { hook_type = CMD_POST_HOOK; hook_name_size = HOOK_POST_LEN; } if (hook_type != CMD_NO_HOOK) { /* Look up cmd it hooks, and verify that we got an exact match. */ tem = comname + hook_name_size; hookc = lookup_cmd (&tem, cmdlist, "", -1, 0); if (hookc && strcmp (comname + hook_name_size, hookc->name) != 0) hookc = 0; if (!hookc) { warning ("Your new `%s' command does not hook any existing command.", comname); if (!query ("Proceed? ")) error ("Not confirmed."); } } comname = savestring (comname, strlen (comname)); /* If the rest of the commands will be case insensitive, this one should behave in the same manner. */ for (tem = comname; *tem; tem++) if (isupper (*tem)) *tem = tolower (*tem); sprintf (tmpbuf, "Type commands for definition of \"%s\".", comname); cmds = read_command_lines (tmpbuf, from_tty); if (c && c->class == class_user) free_command_lines (&c->user_commands); newc = add_cmd (comname, class_user, user_defined_command, (c && c->class == class_user) ? c->doc : savestring ("User-defined.", 13), &cmdlist); newc->user_commands = cmds; /* If this new command is a hook, then mark both commands as being tied. */ if (hookc) { switch (hook_type) { case CMD_PRE_HOOK: hookc->hook_pre = newc; /* Target gets hooked. */ newc->hookee_pre = hookc; /* We are marked as hooking target cmd. */ break; case CMD_POST_HOOK: hookc->hook_post = newc; /* Target gets hooked. */ newc->hookee_post = hookc; /* We are marked as hooking target cmd. */ break; default: /* Should never come here as hookc would be 0. */ internal_error (__FILE__, __LINE__, "bad switch"); } }}voiddocument_command (char *comname, int from_tty){ struct command_line *doclines; struct cmd_list_element *c; char *tem = comname; char tmpbuf[128]; validate_comname (comname); c = lookup_cmd (&tem, cmdlist, "", 0, 1); if (c->class != class_user) error ("Command \"%s\" is built-in.", comname); sprintf (tmpbuf, "Type documentation for \"%s\".", comname); doclines = read_command_lines (tmpbuf, from_tty); if (c->doc) xfree (c->doc); { struct command_line *cl1; int len = 0; for (cl1 = doclines; cl1; cl1 = cl1->next) len += strlen (cl1->line) + 1; c->doc = (char *) xmalloc (len + 1); *c->doc = 0; for (cl1 = doclines; cl1; cl1 = cl1->next) { strcat (c->doc, cl1->line); if (cl1->next) strcat (c->doc, "\n"); } } free_command_lines (&doclines);}struct source_cleanup_lines_args{ int old_line; char *old_file; char *old_pre_error; char *old_error_pre_print;};static voidsource_cleanup_lines (void *args){ struct source_cleanup_lines_args *p = (struct source_cleanup_lines_args *) args; source_line_number = p->old_line; source_file_name = p->old_file; source_pre_error = p->old_pre_error; error_pre_print = p->old_error_pre_print;}static voiddo_fclose_cleanup (void *stream){ fclose (stream);}/* Used to implement source_command */voidscript_from_file (FILE *stream, char *file){ struct cleanup *old_cleanups; struct source_cleanup_lines_args old_lines; int needed_length; if (stream == NULL) { internal_error (__FILE__, __LINE__, "called with NULL file pointer!"); } old_cleanups = make_cleanup (do_fclose_cleanup, stream); old_lines.old_line = source_line_number; old_lines.old_file = source_file_name; old_lines.old_pre_error = source_pre_error; old_lines.old_error_pre_print = error_pre_print; make_cleanup (source_cleanup_lines, &old_lines); source_line_number = 0; source_file_name = file; source_pre_error = error_pre_print == NULL ? "" : error_pre_print; source_pre_error = savestring (source_pre_error, strlen (source_pre_error)); make_cleanup (xfree, source_pre_error); /* This will get set every time we read a line. So it won't stay "" for long. */ error_pre_print = ""; needed_length = strlen (source_file_name) + strlen (source_pre_error) + 80; if (source_error_allocated < needed_length) { source_error_allocated *= 2; if (source_error_allocated < needed_length) source_error_allocated = needed_length; if (source_error == NULL) source_error = xmalloc (source_error_allocated); else source_error = xrealloc (source_error, source_error_allocated); } read_command_file (stream); do_cleanups (old_cleanups);}voidshow_user_1 (struct cmd_list_element *c, struct ui_file *stream){ struct command_line *cmdlines; cmdlines = c->user_commands; if (!cmdlines) return; fputs_filtered ("User command ", stream); fputs_filtered (c->name, stream); fputs_filtered (":\n", stream); print_command_lines (uiout, cmdlines, 1); fputs_filtered ("\n", stream);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -