=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/command.c,v retrieving revision 1.1.1.3 retrieving revision 1.1.1.4 diff -u -r1.1.1.3 -r1.1.1.4 --- src/usr.bin/less/command.c 2011/09/16 17:47:02 1.1.1.3 +++ src/usr.bin/less/command.c 2014/04/25 13:33:42 1.1.1.4 @@ -1,11 +1,10 @@ /* - * Copyright (C) 1984-2011 Mark Nudelman + * Copyright (C) 1984-2012 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. * - * For more information about less, or for information on how to - * contact the author, see the README file. + * For more information, see the README file. */ @@ -22,7 +21,7 @@ #include "cmd.h" extern int erase_char, erase2_char, kill_char; -extern int sigs; +extern volatile sig_atomic_t sigs; extern int quit_if_one_screen; extern int squished; extern int sc_width; @@ -36,6 +35,7 @@ extern int secure; extern int hshift; extern int show_attn; +extern POSITION highest_hilite; extern char *every_first_cmd; extern char *curr_altfilename; extern char version[]; @@ -54,6 +54,9 @@ extern int shift_count; extern int oldbot; extern int forw_prompt; +extern int be_helpful; +extern int less_is_more; +extern int quit_at_eof; #if SHELL_ESCAPE static char *shellcmd = NULL; /* For holding last shell command for "!!" */ @@ -68,6 +71,7 @@ static int optgetname; static POSITION bottompos; static int save_hshift; +static char *help_prompt; #if PIPEC static char pipec; #endif @@ -102,8 +106,8 @@ static void start_mca(action, prompt, mlist, cmdflags) int action; - char *prompt; - void *mlist; + constant char *prompt; + constant void *mlist; int cmdflags; { mca = action; @@ -179,8 +183,10 @@ clear_bot(); clear_cmd(); cmd_putstr(dash); +#if GNU_OPTIONS if (optgetname) cmd_putstr(dash); +#endif if (no_prompt) cmd_putstr("(P)"); switch (flag) @@ -303,6 +309,7 @@ int c; { int flag = (optflag & ~OPT_NO_PROMPT); +#if GNU_OPTIONS if (flag == OPT_NO_TOGGLE) { switch (c) @@ -314,6 +321,7 @@ return (MCA_MORE); } } else +#endif { switch (c) { @@ -333,17 +341,20 @@ optflag ^= OPT_NO_PROMPT; mca_opt_toggle(); return (MCA_MORE); +#if GNU_OPTIONS case '-': /* "--" = long option name. */ optgetname = TRUE; mca_opt_toggle(); return (MCA_MORE); +#endif } } /* Char was not handled here. */ return (NO_MCA); } +#if GNU_OPTIONS /* * Add a char to a long option name. * See if we've got a match for an option name yet. @@ -396,6 +407,7 @@ } return (MCA_MORE); } +#endif /* * Handle a char of an option toggle command. @@ -417,6 +429,7 @@ if (ret != NO_MCA) return (ret); } +#if GNU_OPTIONS if (optgetname) { /* We're getting a long option name. */ @@ -431,6 +444,7 @@ optgetname = FALSE; cmd_reset(); } else +#endif { if (is_erase_char(c)) return (NO_MCA); @@ -680,7 +694,7 @@ static void prompt() { - register char *p; + register constant char *p; if (ungot != NULL) { @@ -737,7 +751,7 @@ clear_bot(); clear_cmd(); forw_prompt = 0; - p = pr_string(); + p = help_prompt ? help_prompt : pr_string(); if (is_filtering()) putstr("& "); if (p == NULL || *p == '\0') @@ -746,8 +760,11 @@ { at_enter(AT_STANDOUT); putstr(p); + if (be_helpful && !help_prompt && strlen(p) + 40 < sc_width) + putstr(" [Press space to continue, 'q' to quit.]"); at_exit(); } + help_prompt = NULL; clear_eol(); } @@ -956,6 +973,46 @@ } /* + * Forward forever, or until a highlighted line appears. + */ + static int +forw_loop(until_hilite) + int until_hilite; +{ + POSITION curr_len; + + if (ch_getflags() & CH_HELPFILE) + return (A_NOACTION); + + cmd_exec(); + jump_forw(); + curr_len = ch_length(); + highest_hilite = until_hilite ? curr_len : NULL_POSITION; + ignore_eoi = 1; + while (!sigs) + { + if (until_hilite && highest_hilite > curr_len) + { + bell(); + break; + } + make_display(); + forward(1, 0, 0); + } + ignore_eoi = 0; + ch_set_eof(); + + /* + * This gets us back in "F mode" after processing + * a non-abort signal (e.g. window-change). + */ + if (sigs && !ABORT_SIGS()) + return (until_hilite ? A_F_UNTIL_HILITE : A_F_FOREVER); + + return (A_NOACTION); +} + +/* * Main command processor. * Accept and execute commands until a quit command. */ @@ -973,6 +1030,7 @@ IFILE old_ifile; IFILE new_ifile; char *tagfile; + int until_hilite = 0; search_type = SRCH_FORW; wscroll = (sc_height + 1) / 2; @@ -1200,25 +1258,15 @@ /* * Forward forever, ignoring EOF. */ - if (ch_getflags() & CH_HELPFILE) - break; - cmd_exec(); - jump_forw(); - ignore_eoi = 1; - while (!sigs) - { - make_display(); - forward(1, 0, 0); - } - ignore_eoi = 0; - /* - * This gets us back in "F mode" after processing - * a non-abort signal (e.g. window-change). - */ - if (sigs && !ABORT_SIGS()) - newaction = A_F_FOREVER; + newaction = forw_loop(0); + if (less_is_more) + quit_at_eof = OPT_ON; break; + case A_F_UNTIL_HILITE: + newaction = forw_loop(1); + break; + case A_F_SCROLL: /* * Forward N lines @@ -1330,6 +1378,7 @@ /* * Exit. */ +#if !SMALL if (curr_ifile != NULL_IFILE && ch_getflags() & CH_HELPFILE) { @@ -1342,6 +1391,7 @@ if (edit_prev(1) == 0) break; } +#endif /* !SMALL */ if (extra != NULL) quit(*extra); quit(QUIT_OK); @@ -1437,12 +1487,21 @@ /* * Help. */ +#if !SMALL if (ch_getflags() & CH_HELPFILE) break; + if (ungot != NULL || unget_end) { + error(less_is_more + ? "Invalid option -p h" + : "Invalid option ++h", + NULL_PARG); + break; + } cmd_exec(); save_hshift = hshift; hshift = 0; - (void) edit(FAKE_HELPFILE); + (void) edit(HELPFILE); +#endif /* !SMALL */ break; case A_EXAMINE: @@ -1756,7 +1815,10 @@ break; default: - bell(); + if (be_helpful) + help_prompt = "[Press 'h' for instructions.]"; + else + bell(); break; } }