version 1.1.1.3, 2011/09/16 17:47:02 |
version 1.1.1.4, 2014/04/25 13:33:42 |
|
|
/* |
/* |
* Copyright (C) 1984-2011 Mark Nudelman |
* Copyright (C) 1984-2012 Mark Nudelman |
* |
* |
* You may distribute under the terms of either the GNU General Public |
* You may distribute under the terms of either the GNU General Public |
* License or the Less License, as specified in the README file. |
* License or the Less License, as specified in the README file. |
* |
* |
* For more information about less, or for information on how to |
* For more information, see the README file. |
* contact the author, see the README file. |
|
*/ |
*/ |
|
|
|
|
|
|
#include "cmd.h" |
#include "cmd.h" |
|
|
extern int erase_char, erase2_char, kill_char; |
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 quit_if_one_screen; |
extern int squished; |
extern int squished; |
extern int sc_width; |
extern int sc_width; |
|
|
extern int secure; |
extern int secure; |
extern int hshift; |
extern int hshift; |
extern int show_attn; |
extern int show_attn; |
|
extern POSITION highest_hilite; |
extern char *every_first_cmd; |
extern char *every_first_cmd; |
extern char *curr_altfilename; |
extern char *curr_altfilename; |
extern char version[]; |
extern char version[]; |
|
|
extern int shift_count; |
extern int shift_count; |
extern int oldbot; |
extern int oldbot; |
extern int forw_prompt; |
extern int forw_prompt; |
|
extern int be_helpful; |
|
extern int less_is_more; |
|
extern int quit_at_eof; |
|
|
#if SHELL_ESCAPE |
#if SHELL_ESCAPE |
static char *shellcmd = NULL; /* For holding last shell command for "!!" */ |
static char *shellcmd = NULL; /* For holding last shell command for "!!" */ |
|
|
static int optgetname; |
static int optgetname; |
static POSITION bottompos; |
static POSITION bottompos; |
static int save_hshift; |
static int save_hshift; |
|
static char *help_prompt; |
#if PIPEC |
#if PIPEC |
static char pipec; |
static char pipec; |
#endif |
#endif |
|
|
static void |
static void |
start_mca(action, prompt, mlist, cmdflags) |
start_mca(action, prompt, mlist, cmdflags) |
int action; |
int action; |
char *prompt; |
constant char *prompt; |
void *mlist; |
constant void *mlist; |
int cmdflags; |
int cmdflags; |
{ |
{ |
mca = action; |
mca = action; |
|
|
clear_bot(); |
clear_bot(); |
clear_cmd(); |
clear_cmd(); |
cmd_putstr(dash); |
cmd_putstr(dash); |
|
#if GNU_OPTIONS |
if (optgetname) |
if (optgetname) |
cmd_putstr(dash); |
cmd_putstr(dash); |
|
#endif |
if (no_prompt) |
if (no_prompt) |
cmd_putstr("(P)"); |
cmd_putstr("(P)"); |
switch (flag) |
switch (flag) |
|
|
int c; |
int c; |
{ |
{ |
int flag = (optflag & ~OPT_NO_PROMPT); |
int flag = (optflag & ~OPT_NO_PROMPT); |
|
#if GNU_OPTIONS |
if (flag == OPT_NO_TOGGLE) |
if (flag == OPT_NO_TOGGLE) |
{ |
{ |
switch (c) |
switch (c) |
|
|
return (MCA_MORE); |
return (MCA_MORE); |
} |
} |
} else |
} else |
|
#endif |
{ |
{ |
switch (c) |
switch (c) |
{ |
{ |
|
|
optflag ^= OPT_NO_PROMPT; |
optflag ^= OPT_NO_PROMPT; |
mca_opt_toggle(); |
mca_opt_toggle(); |
return (MCA_MORE); |
return (MCA_MORE); |
|
#if GNU_OPTIONS |
case '-': |
case '-': |
/* "--" = long option name. */ |
/* "--" = long option name. */ |
optgetname = TRUE; |
optgetname = TRUE; |
mca_opt_toggle(); |
mca_opt_toggle(); |
return (MCA_MORE); |
return (MCA_MORE); |
|
#endif |
} |
} |
} |
} |
/* Char was not handled here. */ |
/* Char was not handled here. */ |
return (NO_MCA); |
return (NO_MCA); |
} |
} |
|
|
|
#if GNU_OPTIONS |
/* |
/* |
* Add a char to a long option name. |
* Add a char to a long option name. |
* See if we've got a match for an option name yet. |
* See if we've got a match for an option name yet. |
|
|
} |
} |
return (MCA_MORE); |
return (MCA_MORE); |
} |
} |
|
#endif |
|
|
/* |
/* |
* Handle a char of an option toggle command. |
* Handle a char of an option toggle command. |
|
|
if (ret != NO_MCA) |
if (ret != NO_MCA) |
return (ret); |
return (ret); |
} |
} |
|
#if GNU_OPTIONS |
if (optgetname) |
if (optgetname) |
{ |
{ |
/* We're getting a long option name. */ |
/* We're getting a long option name. */ |
|
|
optgetname = FALSE; |
optgetname = FALSE; |
cmd_reset(); |
cmd_reset(); |
} else |
} else |
|
#endif |
{ |
{ |
if (is_erase_char(c)) |
if (is_erase_char(c)) |
return (NO_MCA); |
return (NO_MCA); |
|
|
static void |
static void |
prompt() |
prompt() |
{ |
{ |
register char *p; |
register constant char *p; |
|
|
if (ungot != NULL) |
if (ungot != NULL) |
{ |
{ |
|
|
clear_bot(); |
clear_bot(); |
clear_cmd(); |
clear_cmd(); |
forw_prompt = 0; |
forw_prompt = 0; |
p = pr_string(); |
p = help_prompt ? help_prompt : pr_string(); |
if (is_filtering()) |
if (is_filtering()) |
putstr("& "); |
putstr("& "); |
if (p == NULL || *p == '\0') |
if (p == NULL || *p == '\0') |
|
|
{ |
{ |
at_enter(AT_STANDOUT); |
at_enter(AT_STANDOUT); |
putstr(p); |
putstr(p); |
|
if (be_helpful && !help_prompt && strlen(p) + 40 < sc_width) |
|
putstr(" [Press space to continue, 'q' to quit.]"); |
at_exit(); |
at_exit(); |
} |
} |
|
help_prompt = NULL; |
clear_eol(); |
clear_eol(); |
} |
} |
|
|
|
|
} |
} |
|
|
/* |
/* |
|
* 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. |
* Main command processor. |
* Accept and execute commands until a quit command. |
* Accept and execute commands until a quit command. |
*/ |
*/ |
|
|
IFILE old_ifile; |
IFILE old_ifile; |
IFILE new_ifile; |
IFILE new_ifile; |
char *tagfile; |
char *tagfile; |
|
int until_hilite = 0; |
|
|
search_type = SRCH_FORW; |
search_type = SRCH_FORW; |
wscroll = (sc_height + 1) / 2; |
wscroll = (sc_height + 1) / 2; |
|
|
/* |
/* |
* Forward forever, ignoring EOF. |
* Forward forever, ignoring EOF. |
*/ |
*/ |
if (ch_getflags() & CH_HELPFILE) |
newaction = forw_loop(0); |
break; |
if (less_is_more) |
cmd_exec(); |
quit_at_eof = OPT_ON; |
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; |
|
break; |
break; |
|
|
|
case A_F_UNTIL_HILITE: |
|
newaction = forw_loop(1); |
|
break; |
|
|
case A_F_SCROLL: |
case A_F_SCROLL: |
/* |
/* |
* Forward N lines |
* Forward N lines |
|
|
/* |
/* |
* Exit. |
* Exit. |
*/ |
*/ |
|
#if !SMALL |
if (curr_ifile != NULL_IFILE && |
if (curr_ifile != NULL_IFILE && |
ch_getflags() & CH_HELPFILE) |
ch_getflags() & CH_HELPFILE) |
{ |
{ |
|
|
if (edit_prev(1) == 0) |
if (edit_prev(1) == 0) |
break; |
break; |
} |
} |
|
#endif /* !SMALL */ |
if (extra != NULL) |
if (extra != NULL) |
quit(*extra); |
quit(*extra); |
quit(QUIT_OK); |
quit(QUIT_OK); |
|
|
/* |
/* |
* Help. |
* Help. |
*/ |
*/ |
|
#if !SMALL |
if (ch_getflags() & CH_HELPFILE) |
if (ch_getflags() & CH_HELPFILE) |
break; |
break; |
|
if (ungot != NULL || unget_end) { |
|
error(less_is_more |
|
? "Invalid option -p h" |
|
: "Invalid option ++h", |
|
NULL_PARG); |
|
break; |
|
} |
cmd_exec(); |
cmd_exec(); |
save_hshift = hshift; |
save_hshift = hshift; |
hshift = 0; |
hshift = 0; |
(void) edit(FAKE_HELPFILE); |
(void) edit(HELPFILE); |
|
#endif /* !SMALL */ |
break; |
break; |
|
|
case A_EXAMINE: |
case A_EXAMINE: |
|
|
break; |
break; |
|
|
default: |
default: |
bell(); |
if (be_helpful) |
|
help_prompt = "[Press 'h' for instructions.]"; |
|
else |
|
bell(); |
break; |
break; |
} |
} |
} |
} |