?? fc.def
字號(hào):
} /* "When not listing, the fc command that caused the editing shall not be entered into the history list." */ if (listing == 0 && hist_last_line_added) { bash_delete_last_history (); /* If we're editing a single command -- the last command in the history -- and we just removed the dummy command added by edit_and_execute_command (), we need to check whether or not we just removed the last command in the history and need to back the pointer up. remember_on_history is off because we're running in parse_and_execute(). */ if (histbeg == histend && histend == last_hist && hlist[last_hist] == 0) last_hist = histbeg = --histend; } /* We print error messages for line specifications out of range. */ if ((histbeg < 0) || (histend < 0)) { sh_erange ((char *)NULL, _("history specification")); return (EXECUTION_FAILURE); if (histend < histbeg) { i = histend; histend = histbeg; histbeg = i; reverse = 1; } if (listing) stream = stdout; else { numbering = 0; stream = sh_mktmpfp ("bash-fc", MT_USERANDOM|MT_USETMPDIR, &fn); if (stream == 0) { builtin_error (_("%s: cannot open temp file: %s"), fn ? fn : "", strerror (errno)); FREE (fn); return (EXECUTION_FAILURE); } } for (i = reverse ? histend : histbeg; reverse ? i >= histbeg : i <= histend; reverse ? i-- : i++) { QUIT; if (numbering) fprintf (stream, "%d", i + history_base); if (listing) { if (posixly_correct) fputs ("\t", stream); else fprintf (stream, "\t%c", histdata (i) ? '*' : ' '); } fprintf (stream, "%s\n", histline (i)); } if (listing) return (sh_chkwrite (EXECUTION_SUCCESS)); fflush (stream); if (ferror (stream)) { sh_wrerror (); fclose (stream); return (EXECUTION_FAILURE); } fclose (stream); /* Now edit the file of commands. */ if (ename) { command = (char *)xmalloc (strlen (ename) + strlen (fn) + 2); sprintf (command, "%s %s", ename, fn); } else { fcedit = posixly_correct ? POSIX_FC_EDIT_COMMAND : FC_EDIT_COMMAND; command = (char *)xmalloc (3 + strlen (fcedit) + strlen (fn)); sprintf (command, "%s %s", fcedit, fn); } retval = parse_and_execute (command, "fc", SEVAL_NOHIST); if (retval != EXECUTION_SUCCESS) { unlink (fn); free (fn); return (EXECUTION_FAILURE); } /* Make sure parse_and_execute doesn't turn this off, even though a call to parse_and_execute farther up the function call stack (e.g., if this is called by vi_edit_and_execute_command) may have already called bash_history_disable. */ remember_on_history = 1; /* Turn on the `v' flag while fc_execute_file runs so the commands will be echoed as they are read by the parser. */ begin_unwind_frame ("fc builtin"); add_unwind_protect ((Function *)xfree, fn); add_unwind_protect (unlink, fn); unwind_protect_int (echo_input_at_read); echo_input_at_read = 1; retval = fc_execute_file (fn); run_unwind_frame ("fc builtin"); return (retval);}/* Return 1 if LIST->word->word is a legal number for fc's use. */static intfc_number (list) WORD_LIST *list;{ char *s; if (list == 0) return 0; s = list->word->word; if (*s == '-') s++; return (legal_number (s, (intmax_t *)NULL));}/* Return an absolute index into HLIST which corresponds to COMMAND. If COMMAND is a number, then it was specified in relative terms. If it is a string, then it is the start of a command line present in HLIST. */static intfc_gethnum (command, hlist) char *command; HIST_ENTRY **hlist;{ int sign, n, clen, rh; register int i, j; register char *s; sign = 1; /* Count history elements. */ for (i = 0; hlist[i]; i++); /* With the Bash implementation of history, the current command line ("fc blah..." and so on) is already part of the history list by the time we get to this point. This just skips over that command and makes the last command that this deals with be the last command the user entered before the fc. We need to check whether the line was actually added (HISTIGNORE may have caused it to not be), so we check hist_last_line_added. This needs to agree with the calculation of last_hist in fc_builtin above. */ /* Even though command substitution through parse_and_execute turns off remember_on_history, command substitution in a shell when set -o history has been enabled (interactive or not) should use it in the last_hist calculation as if it were on. */ rh = remember_on_history || ((subshell_environment & SUBSHELL_COMSUB) && enable_history_list); i -= rh + hist_last_line_added; /* No specification defaults to most recent command. */ if (command == NULL) return (i); /* Otherwise, there is a specification. It can be a number relative to the current position, or an absolute history number. */ s = command; /* Handle possible leading minus sign. */ if (s && (*s == '-')) { sign = -1; s++; } if (s && DIGIT(*s)) { n = atoi (s); n *= sign; /* If the value is negative or zero, then it is an offset from the current history item. */ if (n < 0) { n += i + 1; return (n < 0 ? 0 : n); } else if (n == 0) return (i); else { n -= history_base; return (i < n ? i : n); } } clen = strlen (command); for (j = i; j >= 0; j--) { if (STREQN (command, histline (j), clen)) return (j); } return (-1);}/* Locate the most recent history line which begins with COMMAND in HLIST, and return a malloc()'ed copy of it. */static char *fc_gethist (command, hlist) char *command; HIST_ENTRY **hlist;{ int i; if (hlist == 0) return ((char *)NULL); i = fc_gethnum (command, hlist); if (i >= 0) return (savestring (histline (i))); else return ((char *)NULL);}#ifdef INCLUDE_UNUSED/* Read the edited history lines from STREAM and return them one at a time. This can read unlimited length lines. The caller should free the storage. */static char *fc_readline (stream) FILE *stream;{ register int c; int line_len = 0, lindex = 0; char *line = (char *)NULL; while ((c = getc (stream)) != EOF) { if ((lindex + 2) >= line_len) line = (char *)xrealloc (line, (line_len += 128)); if (c == '\n') { line[lindex++] = '\n'; line[lindex++] = '\0'; return (line); } else line[lindex++] = c; } if (!lindex) { if (line) free (line); return ((char *)NULL); } if (lindex + 2 >= line_len) line = (char *)xrealloc (line, lindex + 3); line[lindex++] = '\n'; /* Finish with newline if none in file */ line[lindex++] = '\0'; return (line);}#endif/* Perform the SUBS on COMMAND. SUBS is a list of substitutions, and COMMAND is a simple string. Return a pointer to a malloc'ed string which contains the substituted command. */static char *fc_dosubs (command, subs) char *command; REPL *subs;{ register char *new, *t; register REPL *r; for (new = savestring (command), r = subs; r; r = r->next) { t = strsub (new, r->pat, r->rep, 1); free (new); new = t; } return (new);}/* Use `command' to replace the last entry in the history list, which, by this time, is `fc blah...'. The intent is that the new command become the history entry, and that `fc' should never appear in the history list. This way you can do `r' to your heart's content. */static voidfc_replhist (command) char *command;{ int n; if (command == 0 || *command == '\0') return; n = strlen (command); if (command[n - 1] == '\n') command[n - 1] = '\0'; if (command && *command) { bash_delete_last_history (); maybe_add_history (command); /* Obeys HISTCONTROL setting. */ }}#ifdef INCLUDE_UNUSED/* Add LINE to the history, after removing a single trailing newline. */static voidfc_addhist (line) char *line;{ register int n; if (line == 0 || *line == 0) return; n = strlen (line); if (line[n - 1] == '\n') line[n - 1] = '\0'; if (line && *line) maybe_add_history (line); /* Obeys HISTCONTROL setting. */}#endif#endif /* HISTORY */
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -