version 1.17, 2014/05/10 20:09:38 |
version 1.18, 2015/11/05 22:08:43 |
|
|
* |
* |
* For more information, see the README file. |
* For more information, see the README file. |
*/ |
*/ |
|
/* |
|
* Modified for use with illumos. |
|
* Copyright 2014 Garrett D'Amore <garrett@damore.org> |
|
*/ |
|
|
|
|
/* |
/* |
* User-level command processor. |
* User-level command processor. |
*/ |
*/ |
|
|
#include "less.h" |
#include "less.h" |
#if MSDOS_COMPILER==WIN32C |
|
#include <windows.h> |
|
#endif |
|
#include "position.h" |
#include "position.h" |
#include "option.h" |
#include "option.h" |
#include "cmd.h" |
#include "cmd.h" |
|
|
extern int erase_char, erase2_char, kill_char; |
extern int erase_char, erase2_char, kill_char; |
extern volatile sig_atomic_t sigs; |
extern volatile sig_atomic_t sigs; |
extern int quit_if_one_screen; |
extern int quit_if_one_screen; |
|
extern int less_is_more; |
extern int squished; |
extern int squished; |
extern int sc_width; |
extern int sc_width; |
extern int sc_height; |
extern int sc_height; |
|
|
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 off_t 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 struct scrpos initial_scrpos; |
extern struct scrpos initial_scrpos; |
extern IFILE curr_ifile; |
extern IFILE curr_ifile; |
extern void constant *ml_search; |
extern void *ml_search; |
extern void constant *ml_examine; |
extern void *ml_examine; |
#if SHELL_ESCAPE || PIPEC |
extern void *ml_shell; |
extern void constant *ml_shell; |
|
#endif |
|
#if EDITOR |
|
extern char *editor; |
extern char *editor; |
extern char *editproto; |
extern char *editproto; |
#endif |
|
extern int screen_trashed; /* The screen has been overwritten */ |
extern int screen_trashed; /* The screen has been overwritten */ |
extern int shift_count; |
extern int shift_count; |
extern int oldbot; |
extern int oldbot; |
extern int forw_prompt; |
extern int forw_prompt; |
extern int less_is_more; |
|
|
|
#if SHELL_ESCAPE |
|
static char *shellcmd = NULL; /* For holding last shell command for "!!" */ |
static char *shellcmd = NULL; /* For holding last shell command for "!!" */ |
#endif |
|
static int mca; /* The multicharacter command (action) */ |
static int mca; /* The multicharacter command (action) */ |
static int search_type; /* The previous type of search */ |
static int search_type; /* The previous type of search */ |
static LINENUM number; /* The number typed by the user */ |
static LINENUM number; /* The number typed by the user */ |
|
|
static int opt_lower; |
static int opt_lower; |
static int optflag; |
static int optflag; |
static int optgetname; |
static int optgetname; |
static POSITION bottompos; |
static off_t bottompos; |
static int save_hshift; |
static int save_hshift; |
#if PIPEC |
static int pipec; |
static char pipec; |
|
#endif |
|
|
|
struct ungot { |
struct ungot { |
struct ungot *ug_next; |
struct ungot *ug_next; |
char ug_char; |
int ug_char; |
}; |
}; |
static struct ungot* ungot = NULL; |
static struct ungot *ungot = NULL; |
static int unget_end = 0; |
static int unget_end = 0; |
|
|
static void multi_search(); |
static void multi_search(); |
|
|
* This looks nicer if the command takes a long time before |
* This looks nicer if the command takes a long time before |
* updating the screen. |
* updating the screen. |
*/ |
*/ |
static void |
static void |
cmd_exec() |
cmd_exec(void) |
{ |
{ |
#if HILITE_SEARCH |
|
clear_attn(); |
clear_attn(); |
#endif |
|
clear_bot(); |
clear_bot(); |
flush(); |
flush(); |
} |
} |
|
|
/* |
/* |
* Set up the display to start a new multi-character command. |
* Set up the display to start a new multi-character command. |
*/ |
*/ |
static void |
static void |
start_mca(action, prompt, mlist, cmdflags) |
start_mca(int action, const char *prompt, void *mlist, int cmdflags) |
int action; |
|
constant char *prompt; |
|
constant void *mlist; |
|
int cmdflags; |
|
{ |
{ |
mca = action; |
mca = action; |
clear_bot(); |
clear_bot(); |
clear_cmd(); |
clear_cmd(); |
cmd_putstr(prompt); |
cmd_putstr((char *)prompt); |
set_mlist(mlist, cmdflags); |
set_mlist(mlist, cmdflags); |
} |
} |
|
|
public int |
int |
in_mca() |
in_mca(void) |
{ |
{ |
return (mca != 0 && mca != A_PREFIX); |
return (mca != 0 && mca != A_PREFIX); |
} |
} |
|
|
/* |
/* |
* Set up the display to start a new search command. |
* Set up the display to start a new search command. |
*/ |
*/ |
static void |
static void |
mca_search() |
mca_search(void) |
{ |
{ |
#if HILITE_SEARCH |
|
if (search_type & SRCH_FILTER) |
if (search_type & SRCH_FILTER) |
mca = A_FILTER; |
mca = A_FILTER; |
else |
else if (search_type & SRCH_FORW) |
#endif |
|
if (search_type & SRCH_FORW) |
|
mca = A_F_SEARCH; |
mca = A_F_SEARCH; |
else |
else |
mca = A_B_SEARCH; |
mca = A_B_SEARCH; |
|
|
if (search_type & SRCH_NO_REGEX) |
if (search_type & SRCH_NO_REGEX) |
cmd_putstr("Regex-off "); |
cmd_putstr("Regex-off "); |
|
|
#if HILITE_SEARCH |
|
if (search_type & SRCH_FILTER) |
if (search_type & SRCH_FILTER) |
cmd_putstr("&/"); |
cmd_putstr("&/"); |
else |
else if (search_type & SRCH_FORW) |
#endif |
|
if (search_type & SRCH_FORW) |
|
cmd_putstr("/"); |
cmd_putstr("/"); |
else |
else |
cmd_putstr("?"); |
cmd_putstr("?"); |
|
|
/* |
/* |
* Set up the display to start a new toggle-option command. |
* Set up the display to start a new toggle-option command. |
*/ |
*/ |
static void |
static void |
mca_opt_toggle() |
mca_opt_toggle(void) |
{ |
{ |
int no_prompt; |
int no_prompt; |
int flag; |
int flag; |
char *dash; |
char *dash; |
|
|
no_prompt = (optflag & OPT_NO_PROMPT); |
no_prompt = (optflag & OPT_NO_PROMPT); |
flag = (optflag & ~OPT_NO_PROMPT); |
flag = (optflag & ~OPT_NO_PROMPT); |
dash = (flag == OPT_NO_TOGGLE) ? "_" : "-"; |
dash = (flag == OPT_NO_TOGGLE) ? "_" : "-"; |
|
|
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) { |
{ |
|
case OPT_UNSET: |
case OPT_UNSET: |
cmd_putstr("+"); |
cmd_putstr("+"); |
break; |
break; |
|
|
/* |
/* |
* Execute a multicharacter command. |
* Execute a multicharacter command. |
*/ |
*/ |
static void |
static void |
exec_mca() |
exec_mca(void) |
{ |
{ |
register char *cbuf; |
char *cbuf; |
|
|
cmd_exec(); |
cmd_exec(); |
cbuf = get_cmdbuf(); |
cbuf = get_cmdbuf(); |
|
|
switch (mca) |
switch (mca) { |
{ |
|
case A_F_SEARCH: |
case A_F_SEARCH: |
case A_B_SEARCH: |
case A_B_SEARCH: |
multi_search(cbuf, (int) number); |
multi_search(cbuf, (int)number); |
break; |
break; |
#if HILITE_SEARCH |
|
case A_FILTER: |
case A_FILTER: |
search_type ^= SRCH_NO_MATCH; |
search_type ^= SRCH_NO_MATCH; |
set_filter_pattern(cbuf, search_type); |
set_filter_pattern(cbuf, search_type); |
break; |
break; |
#endif |
|
case A_FIRSTCMD: |
case A_FIRSTCMD: |
/* |
/* |
* Skip leading spaces or + signs in the string. |
* Skip leading spaces or + signs in the string. |
|
|
curropt = NULL; |
curropt = NULL; |
break; |
break; |
case A_F_BRACKET: |
case A_F_BRACKET: |
match_brac(cbuf[0], cbuf[1], 1, (int) number); |
match_brac(cbuf[0], cbuf[1], 1, (int)number); |
break; |
break; |
case A_B_BRACKET: |
case A_B_BRACKET: |
match_brac(cbuf[1], cbuf[0], 0, (int) number); |
match_brac(cbuf[1], cbuf[0], 0, (int)number); |
break; |
break; |
#if EXAMINE |
|
case A_EXAMINE: |
case A_EXAMINE: |
if (secure) |
if (secure) |
break; |
break; |
|
|
|
/* POSIX behavior, but possibly generally useful */ |
|
if (strlen(cbuf) == 0) { |
|
reopen_curr_ifile(); |
|
jump_back(1); |
|
break; |
|
} |
|
/* POSIX behavior - probably not generally useful */ |
|
if (less_is_more && (strcmp(cbuf, "#") == 0)) { |
|
if (ntags()) { |
|
error("No previous file", NULL_PARG); |
|
break; |
|
} |
|
if (edit_prev(1)) { |
|
error("No previous file", NULL_PARG); |
|
} else { |
|
jump_back(1); |
|
} |
|
break; |
|
} |
edit_list(cbuf); |
edit_list(cbuf); |
#if TAGS |
|
/* If tag structure is loaded then clean it up. */ |
/* If tag structure is loaded then clean it up. */ |
cleantags(); |
cleantags(); |
#endif |
|
break; |
break; |
#endif |
|
#if SHELL_ESCAPE |
|
case A_SHELL: |
case A_SHELL: |
/* |
/* |
* !! just uses whatever is in shellcmd. |
* !! just uses whatever is in shellcmd. |
* Otherwise, copy cmdbuf to shellcmd, |
* Otherwise, copy cmdbuf to shellcmd, |
* expanding any special characters ("%" or "#"). |
* expanding any special characters ("%" or "#"). |
*/ |
*/ |
if (*cbuf != '!') |
if (*cbuf != '!') { |
{ |
|
if (shellcmd != NULL) |
if (shellcmd != NULL) |
free(shellcmd); |
free(shellcmd); |
shellcmd = fexpand(cbuf); |
shellcmd = fexpand(cbuf); |
|
|
else |
else |
lsystem(shellcmd, "!done"); |
lsystem(shellcmd, "!done"); |
break; |
break; |
#endif |
|
#if PIPEC |
|
case A_PIPE: |
case A_PIPE: |
if (secure) |
if (secure) |
break; |
break; |
(void) pipe_mark(pipec, cbuf); |
(void) pipe_mark(pipec, cbuf); |
error("|done", NULL_PARG); |
error("|done", NULL_PARG); |
break; |
break; |
#endif |
|
} |
} |
} |
} |
|
|
/* |
/* |
* Is a character an erase or kill char? |
* Is a character an erase or kill char? |
*/ |
*/ |
static int |
static int |
is_erase_char(c) |
is_erase_char(int c) |
int c; |
|
{ |
{ |
return (c == erase_char || c == erase2_char || c == kill_char); |
return (c == erase_char || c == erase2_char || c == kill_char); |
} |
} |
|
|
/* |
/* |
* Handle the first char of an option (after the initial dash). |
* Handle the first char of an option (after the initial dash). |
*/ |
*/ |
static int |
static int |
mca_opt_first_char(c) |
mca_opt_first_char(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) |
|
{ |
|
case '_': |
case '_': |
/* "__" = long option name. */ |
/* "__" = long option name. */ |
optgetname = TRUE; |
optgetname = TRUE; |
mca_opt_toggle(); |
mca_opt_toggle(); |
return (MCA_MORE); |
return (MCA_MORE); |
} |
} |
} else |
} else { |
#endif |
switch (c) { |
{ |
|
switch (c) |
|
{ |
|
case '+': |
case '+': |
/* "-+" = UNSET. */ |
/* "-+" = UNSET. */ |
optflag = (flag == OPT_UNSET) ? |
optflag = (flag == OPT_UNSET) ? OPT_TOGGLE : OPT_UNSET; |
OPT_TOGGLE : OPT_UNSET; |
|
mca_opt_toggle(); |
mca_opt_toggle(); |
return (MCA_MORE); |
return (MCA_MORE); |
case '!': |
case '!': |
/* "-!" = SET */ |
/* "-!" = SET */ |
optflag = (flag == OPT_SET) ? |
optflag = (flag == OPT_SET) ? OPT_TOGGLE : OPT_SET; |
OPT_TOGGLE : OPT_SET; |
|
mca_opt_toggle(); |
mca_opt_toggle(); |
return (MCA_MORE); |
return (MCA_MORE); |
case CONTROL('P'): |
case CONTROL('P'): |
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. |
* If so, display the complete name and stop |
* If so, display the complete name and stop |
* accepting chars until user hits RETURN. |
* accepting chars until user hits RETURN. |
*/ |
*/ |
static int |
static int |
mca_opt_nonfirst_char(c) |
mca_opt_nonfirst_char(int c) |
int c; |
|
{ |
{ |
char *p; |
char *p; |
char *oname; |
char *oname; |
|
|
if (curropt != NULL) |
if (curropt != NULL) { |
{ |
|
/* |
/* |
* Already have a match for the name. |
* Already have a match for the name. |
* Don't accept anything but erase/kill. |
* Don't accept anything but erase/kill. |
|
|
if (cmd_char(c) == CC_QUIT) |
if (cmd_char(c) == CC_QUIT) |
return (MCA_DONE); |
return (MCA_DONE); |
p = get_cmdbuf(); |
p = get_cmdbuf(); |
opt_lower = ASCII_IS_LOWER(p[0]); |
opt_lower = islower(p[0]); |
curropt = findopt_name(&p, &oname, NULL); |
curropt = findopt_name(&p, &oname, NULL); |
if (curropt != NULL) |
if (curropt != NULL) { |
{ |
|
/* |
/* |
* Got a match. |
* Got a match. |
* Remember the option and |
* Remember the option and |
|
|
*/ |
*/ |
cmd_reset(); |
cmd_reset(); |
mca_opt_toggle(); |
mca_opt_toggle(); |
for (p = oname; *p != '\0'; p++) |
for (p = oname; *p != '\0'; p++) { |
{ |
|
c = *p; |
c = *p; |
if (!opt_lower && ASCII_IS_LOWER(c)) |
if (!opt_lower && islower(c)) |
c = ASCII_TO_UPPER(c); |
c = toupper(c); |
if (cmd_char(c) != CC_OK) |
if (cmd_char(c) != CC_OK) |
return (MCA_DONE); |
return (MCA_DONE); |
} |
} |
} |
} |
return (MCA_MORE); |
return (MCA_MORE); |
} |
} |
#endif |
|
|
|
/* |
/* |
* Handle a char of an option toggle command. |
* Handle a char of an option toggle command. |
*/ |
*/ |
static int |
static int |
mca_opt_char(c) |
mca_opt_char(int c) |
int c; |
|
{ |
{ |
PARG parg; |
PARG parg; |
|
|
|
|
* or one char of a long option name, |
* or one char of a long option name, |
* or one char of the option parameter. |
* or one char of the option parameter. |
*/ |
*/ |
if (curropt == NULL && len_cmdbuf() == 0) |
if (curropt == NULL && len_cmdbuf() == 0) { |
{ |
|
int ret = mca_opt_first_char(c); |
int ret = mca_opt_first_char(c); |
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. */ |
if (c != '\n' && c != '\r') |
if (c != '\n' && c != '\r') |
return (mca_opt_nonfirst_char(c)); |
return (mca_opt_nonfirst_char(c)); |
if (curropt == NULL) |
if (curropt == NULL) { |
{ |
|
parg.p_string = get_cmdbuf(); |
parg.p_string = get_cmdbuf(); |
error("There is no --%s option", &parg); |
error("There is no --%s option", &parg); |
return (MCA_DONE); |
return (MCA_DONE); |
} |
} |
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); |
if (curropt != NULL) |
if (curropt != NULL) |
/* We're getting the option parameter. */ |
/* We're getting the option parameter. */ |
return (NO_MCA); |
return (NO_MCA); |
curropt = findopt(c); |
curropt = findopt(c); |
if (curropt == NULL) |
if (curropt == NULL) { |
{ |
|
parg.p_string = propt(c); |
parg.p_string = propt(c); |
error("There is no %s option", &parg); |
error("There is no %s option", &parg); |
return (MCA_DONE); |
return (MCA_DONE); |
} |
} |
} |
} |
/* |
/* |
* If the option which was entered does not take a |
* If the option which was entered does not take a |
* parameter, toggle the option immediately, |
* parameter, toggle the option immediately, |
* so user doesn't have to hit RETURN. |
* so user doesn't have to hit RETURN. |
*/ |
*/ |
if ((optflag & ~OPT_NO_PROMPT) != OPT_TOGGLE || |
if ((optflag & ~OPT_NO_PROMPT) != OPT_TOGGLE || |
!opt_has_param(curropt)) |
!opt_has_param(curropt)) { |
{ |
toggle_option(curropt, islower(c), "", optflag); |
toggle_option(curropt, ASCII_IS_LOWER(c), "", optflag); |
|
return (MCA_DONE); |
return (MCA_DONE); |
} |
} |
/* |
/* |
* Display a prompt appropriate for the option parameter. |
* Display a prompt appropriate for the option parameter. |
*/ |
*/ |
start_mca(A_OPT_TOGGLE, opt_prompt(curropt), (void*)NULL, 0); |
start_mca(A_OPT_TOGGLE, opt_prompt(curropt), NULL, 0); |
return (MCA_MORE); |
return (MCA_MORE); |
} |
} |
|
|
/* |
/* |
* Handle a char of a search command. |
* Handle a char of a search command. |
*/ |
*/ |
static int |
static int |
mca_search_char(c) |
mca_search_char(int c) |
int c; |
|
{ |
{ |
int flag = 0; |
int flag = 0; |
|
|
/* |
/* |
* Certain characters as the first char of |
* Certain characters as the first char of |
* the pattern have special meaning: |
* the pattern have special meaning: |
* ! Toggle the NO_MATCH flag |
* ! Toggle the NO_MATCH flag |
* * Toggle the PAST_EOF flag |
* * Toggle the PAST_EOF flag |
|
|
if (len_cmdbuf() > 0) |
if (len_cmdbuf() > 0) |
return (NO_MCA); |
return (NO_MCA); |
|
|
switch (c) |
switch (c) { |
{ |
|
case CONTROL('E'): /* ignore END of file */ |
case CONTROL('E'): /* ignore END of file */ |
case '*': |
case '*': |
if (mca != A_FILTER) |
if (mca != A_FILTER) |
|
|
break; |
break; |
} |
} |
|
|
if (flag != 0) |
if (flag != 0) { |
{ |
|
search_type ^= flag; |
search_type ^= flag; |
mca_search(); |
mca_search(); |
return (MCA_MORE); |
return (MCA_MORE); |
|
|
/* |
/* |
* Handle a character of a multi-character command. |
* Handle a character of a multi-character command. |
*/ |
*/ |
static int |
static int |
mca_char(c) |
mca_char(int c) |
int c; |
|
{ |
{ |
int ret; |
int ret; |
|
|
switch (mca) |
switch (mca) { |
{ |
|
case 0: |
case 0: |
/* |
/* |
* We're not in a multicharacter command. |
* We're not in a multicharacter command. |
|
|
* Entering digits of a number. |
* Entering digits of a number. |
* Terminated by a non-digit. |
* Terminated by a non-digit. |
*/ |
*/ |
if (!((c >= '0' && c <= '9') || c == '.') && |
if (!((c >= '0' && c <= '9') || c == '.') && editchar(c, |
editchar(c, EC_PEEK|EC_NOHISTORY|EC_NOCOMPLETE|EC_NORIGHTLEFT) == A_INVALID) |
EC_PEEK|EC_NOHISTORY|EC_NOCOMPLETE|EC_NORIGHTLEFT) == |
{ |
A_INVALID) { |
/* |
/* |
* Not part of the number. |
* Not part of the number. |
* End the number and treat this char |
* End the number and treat this char |
* as a normal command character. |
* as a normal command character. |
*/ |
*/ |
number = cmd_int(&fraction); |
number = cmd_int(&fraction); |
|
|
/* |
/* |
* The multichar command is terminated by a newline. |
* The multichar command is terminated by a newline. |
*/ |
*/ |
if (c == '\n' || c == '\r') |
if (c == '\n' || c == '\r') { |
{ |
|
/* |
/* |
* Execute the command. |
* Execute the command. |
*/ |
*/ |
|
|
*/ |
*/ |
return (MCA_DONE); |
return (MCA_DONE); |
|
|
if ((mca == A_F_BRACKET || mca == A_B_BRACKET) && len_cmdbuf() >= 2) |
if ((mca == A_F_BRACKET || mca == A_B_BRACKET) && len_cmdbuf() >= 2) { |
{ |
|
/* |
/* |
* Special case for the bracket-matching commands. |
* Special case for the bracket-matching commands. |
* Execute the command after getting exactly two |
* Execute the command after getting exactly two |
|
|
/* |
/* |
* Discard any buffered file data. |
* Discard any buffered file data. |
*/ |
*/ |
static void |
static void |
clear_buffers() |
clear_buffers(void) |
{ |
{ |
if (!(ch_getflags() & CH_CANSEEK)) |
if (!(ch_getflags() & CH_CANSEEK)) |
return; |
return; |
ch_flush(); |
ch_flush(); |
clr_linenum(); |
clr_linenum(); |
#if HILITE_SEARCH |
|
clr_hilite(); |
clr_hilite(); |
#endif |
|
} |
} |
|
|
/* |
/* |
* Make sure the screen is displayed. |
* Make sure the screen is displayed. |
*/ |
*/ |
static void |
static void |
make_display() |
make_display(void) |
{ |
{ |
/* |
/* |
* If nothing is displayed yet, display starting from initial_scrpos. |
* If nothing is displayed yet, display starting from initial_scrpos. |
*/ |
*/ |
if (empty_screen()) |
if (empty_screen()) { |
{ |
if (initial_scrpos.pos == -1) |
if (initial_scrpos.pos == NULL_POSITION) |
|
/* |
/* |
* {{ Maybe this should be: |
* {{ Maybe this should be: |
* jump_loc(ch_zero(), jump_sline); |
* jump_loc(ch_zero(), jump_sline); |
* but this behavior seems rather unexpected |
* but this behavior seems rather unexpected |
* on the first screen. }} |
* on the first screen. }} |
*/ |
*/ |
jump_loc(ch_zero(), 1); |
jump_loc(ch_zero(), 1); |
else |
else |
jump_loc(initial_scrpos.pos, initial_scrpos.ln); |
jump_loc(initial_scrpos.pos, initial_scrpos.ln); |
} else if (screen_trashed) |
} else if (screen_trashed) { |
{ |
|
int save_top_scroll = top_scroll; |
int save_top_scroll = top_scroll; |
int save_ignore_eoi = ignore_eoi; |
int save_ignore_eoi = ignore_eoi; |
top_scroll = 1; |
top_scroll = 1; |
ignore_eoi = 0; |
ignore_eoi = 0; |
if (screen_trashed == 2) |
if (screen_trashed == 2) { |
{ |
/* |
/* Special case used by ignore_eoi: re-open the input file |
* Special case used by ignore_eoi: re-open the input |
* and jump to the end of the file. */ |
* file and jump to the end of the file. |
|
*/ |
reopen_curr_ifile(); |
reopen_curr_ifile(); |
jump_forw(); |
jump_forw(); |
} |
} |
|
|
/* |
/* |
* Display the appropriate prompt. |
* Display the appropriate prompt. |
*/ |
*/ |
static void |
static void |
prompt() |
prompt(void) |
{ |
{ |
register constant char *p; |
const char *p; |
|
|
if (ungot != NULL) |
if (ungot != NULL) { |
{ |
|
/* |
/* |
* No prompt necessary if commands are from |
* No prompt necessary if commands are from |
* ungotten chars rather than from the user. |
* ungotten chars rather than from the user. |
*/ |
*/ |
return; |
return; |
|
|
* If we've hit EOF on the last file and the -E flag is set, quit. |
* If we've hit EOF on the last file and the -E flag is set, quit. |
*/ |
*/ |
if (get_quit_at_eof() == OPT_ONPLUS && |
if (get_quit_at_eof() == OPT_ONPLUS && |
eof_displayed() && !(ch_getflags() & CH_HELPFILE) && |
eof_displayed() && !(ch_getflags() & CH_HELPFILE) && |
next_ifile(curr_ifile) == NULL_IFILE) |
next_ifile(curr_ifile) == NULL_IFILE) |
quit(QUIT_OK); |
quit(QUIT_OK); |
|
|
|
|
* If the entire file is displayed and the -F flag is set, quit. |
* If the entire file is displayed and the -F flag is set, quit. |
*/ |
*/ |
if (quit_if_one_screen && |
if (quit_if_one_screen && |
entire_file_displayed() && !(ch_getflags() & CH_HELPFILE) && |
entire_file_displayed() && !(ch_getflags() & CH_HELPFILE) && |
next_ifile(curr_ifile) == NULL_IFILE) |
next_ifile(curr_ifile) == NULL_IFILE) |
quit(QUIT_OK); |
quit(QUIT_OK); |
|
|
#if MSDOS_COMPILER==WIN32C |
|
/* |
|
* In Win32, display the file name in the window title. |
|
*/ |
|
if (!(ch_getflags() & CH_HELPFILE)) |
|
SetConsoleTitle(pr_expand("Less?f - %f.", 0)); |
|
#endif |
|
/* |
/* |
* Select the proper prompt and display it. |
* Select the proper prompt and display it. |
*/ |
*/ |
/* |
/* |
* If the previous action was a forward movement, |
* If the previous action was a forward movement, |
* don't clear the bottom line of the display; |
* don't clear the bottom line of the display; |
* just print the prompt since the forward movement guarantees |
* just print the prompt since the forward movement guarantees |
* that we're in the right position to display the prompt. |
* that we're in the right position to display the prompt. |
* Clearing the line could cause a problem: for example, if the last |
* Clearing the line could cause a problem: for example, if the last |
* line displayed ended at the right screen edge without a newline, |
* line displayed ended at the right screen edge without a newline, |
|
|
clear_bot(); |
clear_bot(); |
clear_cmd(); |
clear_cmd(); |
forw_prompt = 0; |
forw_prompt = 0; |
p = pr_string(); |
p = prompt_string(); |
if (is_filtering()) |
if (is_filtering()) |
putstr("& "); |
putstr("& "); |
if (p == NULL || *p == '\0') |
if (p == NULL || *p == '\0') { |
putchr(':'); |
putchr(':'); |
else |
} else { |
{ |
|
at_enter(AT_STANDOUT); |
at_enter(AT_STANDOUT); |
putstr(p); |
putstr(p); |
at_exit(); |
at_exit(); |
|
|
/* |
/* |
* Display the less version message. |
* Display the less version message. |
*/ |
*/ |
public void |
void |
dispversion() |
dispversion(void) |
{ |
{ |
PARG parg; |
PARG parg; |
|
|
|
|
* but may come from ungotten characters |
* but may come from ungotten characters |
* (characters previously given to ungetcc or ungetsc). |
* (characters previously given to ungetcc or ungetsc). |
*/ |
*/ |
public int |
int |
getcc() |
getcc(void) |
{ |
{ |
if (unget_end) |
if (unget_end) { |
{ |
|
/* |
/* |
* We have just run out of ungotten chars. |
* We have just run out of ungotten chars. |
*/ |
*/ |
|
|
/* |
/* |
* Command is incomplete, so try to complete it. |
* Command is incomplete, so try to complete it. |
*/ |
*/ |
switch (mca) |
switch (mca) { |
{ |
|
case A_DIGIT: |
case A_DIGIT: |
/* |
/* |
* We have a number but no command. Treat as #g. |
* We have a number but no command. Treat as #g. |
|
|
/* |
/* |
* We have "/string" but no newline. Add the \n. |
* We have "/string" but no newline. Add the \n. |
*/ |
*/ |
return ('\n'); |
return ('\n'); |
|
|
default: |
default: |
/* |
/* |
|
|
} |
} |
} |
} |
|
|
if (ungot == NULL) |
if (ungot == NULL) { |
{ |
|
/* |
/* |
* Normal case: no ungotten chars, so get one from the user. |
* Normal case: no ungotten chars, so get one from the user. |
*/ |
*/ |
|
|
*/ |
*/ |
{ |
{ |
struct ungot *ug = ungot; |
struct ungot *ug = ungot; |
char c = ug->ug_char; |
int c = ug->ug_char; |
ungot = ug->ug_next; |
ungot = ug->ug_next; |
free(ug); |
free(ug); |
unget_end = (ungot == NULL); |
unget_end = (ungot == NULL); |
|
|
* "Unget" a command character. |
* "Unget" a command character. |
* The next getcc() will return this character. |
* The next getcc() will return this character. |
*/ |
*/ |
public void |
void |
ungetcc(c) |
ungetcc(int c) |
int c; |
|
{ |
{ |
struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot)); |
struct ungot *ug = ecalloc(1, sizeof (struct ungot)); |
|
|
ug->ug_char = c; |
ug->ug_char = c; |
ug->ug_next = ungot; |
ug->ug_next = ungot; |
|
|
* Unget a whole string of command characters. |
* Unget a whole string of command characters. |
* The next sequence of getcc()'s will return this string. |
* The next sequence of getcc()'s will return this string. |
*/ |
*/ |
public void |
void |
ungetsc(s) |
ungetsc(char *s) |
char *s; |
|
{ |
{ |
register char *p; |
register char *p; |
|
|
|
|
* If SRCH_FIRST_FILE is set, begin searching at the first file. |
* If SRCH_FIRST_FILE is set, begin searching at the first file. |
* If SRCH_PAST_EOF is set, continue the search thru multiple files. |
* If SRCH_PAST_EOF is set, continue the search thru multiple files. |
*/ |
*/ |
static void |
static void |
multi_search(pattern, n) |
multi_search(char *pattern, int n) |
char *pattern; |
|
int n; |
|
{ |
{ |
register int nomore; |
int nomore; |
IFILE save_ifile; |
IFILE save_ifile; |
int changed_file; |
int changed_file; |
|
|
changed_file = 0; |
changed_file = 0; |
save_ifile = save_curr_ifile(); |
save_ifile = save_curr_ifile(); |
|
|
if (search_type & SRCH_FIRST_FILE) |
if (search_type & SRCH_FIRST_FILE) { |
{ |
|
/* |
/* |
* Start at the first (or last) file |
* Start at the first (or last) file |
* in the command line list. |
* in the command line list. |
*/ |
*/ |
if (search_type & SRCH_FORW) |
if (search_type & SRCH_FORW) |
nomore = edit_first(); |
nomore = edit_first(); |
else |
else |
nomore = edit_last(); |
nomore = edit_last(); |
if (nomore) |
if (nomore) { |
{ |
|
unsave_ifile(save_ifile); |
unsave_ifile(save_ifile); |
return; |
return; |
} |
} |
|
|
search_type &= ~SRCH_FIRST_FILE; |
search_type &= ~SRCH_FIRST_FILE; |
} |
} |
|
|
for (;;) |
for (;;) { |
{ |
|
n = search(search_type, pattern, n); |
n = search(search_type, pattern, n); |
/* |
/* |
* The SRCH_NO_MOVE flag doesn't "stick": it gets cleared |
* The SRCH_NO_MOVE flag doesn't "stick": it gets cleared |
|
|
* using a /@@ search. |
* using a /@@ search. |
*/ |
*/ |
search_type &= ~SRCH_NO_MOVE; |
search_type &= ~SRCH_NO_MOVE; |
if (n == 0) |
if (n == 0) { |
{ |
|
/* |
/* |
* Found it. |
* Found it. |
*/ |
*/ |
|
|
if (n > 0) |
if (n > 0) |
error("Pattern not found", NULL_PARG); |
error("Pattern not found", NULL_PARG); |
|
|
if (changed_file) |
if (changed_file) { |
{ |
|
/* |
/* |
* Restore the file we were originally viewing. |
* Restore the file we were originally viewing. |
*/ |
*/ |
reedit_ifile(save_ifile); |
reedit_ifile(save_ifile); |
} else |
} else { |
{ |
|
unsave_ifile(save_ifile); |
unsave_ifile(save_ifile); |
} |
} |
} |
} |
|
|
/* |
/* |
* Forward forever, or until a highlighted line appears. |
* Forward forever, or until a highlighted line appears. |
*/ |
*/ |
static int |
static int |
forw_loop(until_hilite) |
forw_loop(int until_hilite) |
int until_hilite; |
|
{ |
{ |
POSITION curr_len; |
off_t curr_len; |
|
|
if (ch_getflags() & CH_HELPFILE) |
if (ch_getflags() & CH_HELPFILE) |
return (A_NOACTION); |
return (A_NOACTION); |
|
|
cmd_exec(); |
cmd_exec(); |
jump_forw(); |
jump_forw(); |
curr_len = ch_length(); |
curr_len = ch_length(); |
highest_hilite = until_hilite ? curr_len : NULL_POSITION; |
highest_hilite = until_hilite ? curr_len : -1; |
ignore_eoi = 1; |
ignore_eoi = 1; |
while (!sigs) |
while (!sigs) { |
{ |
if (until_hilite && highest_hilite > curr_len) { |
if (until_hilite && highest_hilite > curr_len) |
ring_bell(); |
{ |
|
bell(); |
|
break; |
break; |
} |
} |
make_display(); |
make_display(); |
|
|
ch_set_eof(); |
ch_set_eof(); |
|
|
/* |
/* |
* This gets us back in "F mode" after processing |
* This gets us back in "F mode" after processing |
* a non-abort signal (e.g. window-change). |
* a non-abort signal (e.g. window-change). |
*/ |
*/ |
if (sigs && !ABORT_SIGS()) |
if (sigs && !ABORT_SIGS()) |
return (until_hilite ? A_F_UNTIL_HILITE : A_F_FOREVER); |
return (until_hilite ? A_F_UNTIL_HILITE : A_F_FOREVER); |
|
|
* Main command processor. |
* Main command processor. |
* Accept and execute commands until a quit command. |
* Accept and execute commands until a quit command. |
*/ |
*/ |
public void |
void |
commands() |
commands(void) |
{ |
{ |
register int c; |
int c = 0; |
register int action; |
int action; |
register char *cbuf; |
char *cbuf; |
int newaction; |
int newaction; |
int save_search_type; |
int save_search_type; |
char *extra; |
char *extra; |
|
|
wscroll = (sc_height + 1) / 2; |
wscroll = (sc_height + 1) / 2; |
newaction = A_NOACTION; |
newaction = A_NOACTION; |
|
|
for (;;) |
for (;;) { |
{ |
|
mca = 0; |
mca = 0; |
cmd_accept(); |
cmd_accept(); |
number = 0; |
number = 0; |
|
|
/* |
/* |
* See if any signals need processing. |
* See if any signals need processing. |
*/ |
*/ |
if (sigs) |
if (sigs) { |
{ |
|
psignals(); |
psignals(); |
if (quitting) |
if (quitting) |
quit(QUIT_SAVED_STATUS); |
quit(QUIT_SAVED_STATUS); |
} |
} |
|
|
/* |
/* |
* See if window size changed, for systems that don't |
|
* generate SIGWINCH. |
|
*/ |
|
check_winch(); |
|
|
|
/* |
|
* Display prompt and accept a character. |
* Display prompt and accept a character. |
*/ |
*/ |
cmd_reset(); |
cmd_reset(); |
|
|
if (newaction == A_NOACTION) |
if (newaction == A_NOACTION) |
c = getcc(); |
c = getcc(); |
|
|
again: |
again: |
if (sigs) |
if (sigs) |
continue; |
continue; |
|
|
if (newaction != A_NOACTION) |
if (newaction != A_NOACTION) { |
{ |
|
action = newaction; |
action = newaction; |
newaction = A_NOACTION; |
newaction = A_NOACTION; |
} else |
} else { |
{ |
|
/* |
/* |
* If we are in a multicharacter command, call mca_char. |
* If we are in a multicharacter command, call mca_char. |
* Otherwise we call fcmd_decode to determine the |
* Otherwise we call fcmd_decode to determine the |
* action to be performed. |
* action to be performed. |
*/ |
*/ |
if (mca) |
if (mca) |
switch (mca_char(c)) |
switch (mca_char(c)) { |
{ |
|
case MCA_MORE: |
case MCA_MORE: |
/* |
/* |
* Need another character. |
* Need another character. |
|
|
/* |
/* |
* Decode the command character and decide what to do. |
* Decode the command character and decide what to do. |
*/ |
*/ |
if (mca) |
if (mca) { |
{ |
|
/* |
/* |
* We're in a multichar command. |
* We're in a multichar command. |
* Add the character to the command buffer |
* Add the character to the command buffer |
* and display it on the screen. |
* and display it on the screen. |
* If the user backspaces past the start |
* If the user backspaces past the start |
* of the line, abort the command. |
* of the line, abort the command. |
*/ |
*/ |
if (cmd_char(c) == CC_QUIT || len_cmdbuf() == 0) |
if (cmd_char(c) == CC_QUIT || len_cmdbuf() == 0) |
continue; |
continue; |
cbuf = get_cmdbuf(); |
cbuf = get_cmdbuf(); |
} else |
} else { |
{ |
|
/* |
/* |
* Don't use cmd_char if we're starting fresh |
* Don't use cmd_char if we're starting fresh |
* at the beginning of a command, because we |
* at the beginning of a command, because we |
|
|
* want erase_char/kill_char to be treated |
* want erase_char/kill_char to be treated |
* as line editing characters. |
* as line editing characters. |
*/ |
*/ |
tbuf[0] = c; |
tbuf[0] = (char)c; |
tbuf[1] = '\0'; |
tbuf[1] = '\0'; |
cbuf = tbuf; |
cbuf = tbuf; |
} |
} |
|
|
if (action != A_PREFIX) |
if (action != A_PREFIX) |
cmd_reset(); |
cmd_reset(); |
|
|
switch (action) |
switch (action) { |
{ |
|
case A_DIGIT: |
case A_DIGIT: |
/* |
/* |
* First digit of a number. |
* First digit of a number. |
|
|
* Forward one window (and set the window size). |
* Forward one window (and set the window size). |
*/ |
*/ |
if (number > 0) |
if (number > 0) |
swindow = (int) number; |
swindow = (int)number; |
/* FALLTHRU */ |
/* FALLTHRU */ |
case A_F_SCREEN: |
case A_F_SCREEN: |
/* |
/* |
|
|
cmd_exec(); |
cmd_exec(); |
if (show_attn) |
if (show_attn) |
set_attnpos(bottompos); |
set_attnpos(bottompos); |
forward((int) number, 0, 1); |
forward((int)number, 0, 1); |
break; |
break; |
|
|
case A_B_WINDOW: |
case A_B_WINDOW: |
|
|
* Backward one window (and set the window size). |
* Backward one window (and set the window size). |
*/ |
*/ |
if (number > 0) |
if (number > 0) |
swindow = (int) number; |
swindow = (int)number; |
/* FALLTHRU */ |
/* FALLTHRU */ |
case A_B_SCREEN: |
case A_B_SCREEN: |
/* |
/* |
|
|
if (number <= 0) |
if (number <= 0) |
number = get_swindow(); |
number = get_swindow(); |
cmd_exec(); |
cmd_exec(); |
backward((int) number, 0, 1); |
backward((int)number, 0, 1); |
break; |
break; |
|
|
case A_F_LINE: |
case A_F_LINE: |
|
|
cmd_exec(); |
cmd_exec(); |
if (show_attn == OPT_ONPLUS && number > 1) |
if (show_attn == OPT_ONPLUS && number > 1) |
set_attnpos(bottompos); |
set_attnpos(bottompos); |
forward((int) number, 0, 0); |
forward((int)number, 0, 0); |
break; |
break; |
|
|
case A_B_LINE: |
case A_B_LINE: |
|
|
if (number <= 0) |
if (number <= 0) |
number = 1; |
number = 1; |
cmd_exec(); |
cmd_exec(); |
backward((int) number, 0, 0); |
backward((int)number, 0, 0); |
break; |
break; |
|
|
|
case A_F_SKIP: |
|
/* |
|
* Skip ahead one screen, and then number lines. |
|
*/ |
|
if (number <= 0) { |
|
number = get_swindow(); |
|
} else { |
|
number += get_swindow(); |
|
} |
|
cmd_exec(); |
|
if (show_attn == OPT_ONPLUS) |
|
set_attnpos(bottompos); |
|
forward((int)number, 0, 1); |
|
break; |
|
|
case A_FF_LINE: |
case A_FF_LINE: |
/* |
/* |
* Force forward N (default 1) line. |
* Force forward N (default 1) line. |
|
|
cmd_exec(); |
cmd_exec(); |
if (show_attn == OPT_ONPLUS && number > 1) |
if (show_attn == OPT_ONPLUS && number > 1) |
set_attnpos(bottompos); |
set_attnpos(bottompos); |
forward((int) number, 1, 0); |
forward((int)number, 1, 0); |
break; |
break; |
|
|
case A_BF_LINE: |
case A_BF_LINE: |
|
|
if (number <= 0) |
if (number <= 0) |
number = 1; |
number = 1; |
cmd_exec(); |
cmd_exec(); |
backward((int) number, 1, 0); |
backward((int)number, 1, 0); |
break; |
break; |
|
|
case A_FF_SCREEN: |
case A_FF_SCREEN: |
/* |
/* |
* Force forward one screen. |
* Force forward one screen. |
|
|
cmd_exec(); |
cmd_exec(); |
if (show_attn == OPT_ONPLUS) |
if (show_attn == OPT_ONPLUS) |
set_attnpos(bottompos); |
set_attnpos(bottompos); |
forward((int) number, 1, 0); |
forward((int)number, 1, 0); |
break; |
break; |
|
|
case A_F_FOREVER: |
case A_F_FOREVER: |
|
|
|
|
case A_F_SCROLL: |
case A_F_SCROLL: |
/* |
/* |
* Forward N lines |
* Forward N lines |
* (default same as last 'd' or 'u' command). |
* (default same as last 'd' or 'u' command). |
*/ |
*/ |
if (number > 0) |
if (number > 0) |
wscroll = (int) number; |
wscroll = (int)number; |
cmd_exec(); |
cmd_exec(); |
if (show_attn == OPT_ONPLUS) |
if (show_attn == OPT_ONPLUS) |
set_attnpos(bottompos); |
set_attnpos(bottompos); |
|
|
|
|
case A_B_SCROLL: |
case A_B_SCROLL: |
/* |
/* |
* Forward N lines |
* Forward N lines |
* (default same as last 'd' or 'u' command). |
* (default same as last 'd' or 'u' command). |
*/ |
*/ |
if (number > 0) |
if (number > 0) |
wscroll = (int) number; |
wscroll = (int)number; |
cmd_exec(); |
cmd_exec(); |
backward(wscroll, 0, 0); |
backward(wscroll, 0, 0); |
break; |
break; |
|
|
/* |
/* |
* Go to a specified percentage into the file. |
* Go to a specified percentage into the file. |
*/ |
*/ |
if (number < 0) |
if (number < 0) { |
{ |
|
number = 0; |
number = 0; |
fraction = 0; |
fraction = 0; |
} |
} |
if (number > 100) |
if (number > 100) { |
{ |
|
number = 100; |
number = 100; |
fraction = 0; |
fraction = 0; |
} |
} |
cmd_exec(); |
cmd_exec(); |
jump_percent((int) number, fraction); |
jump_percent((int)number, fraction); |
break; |
break; |
|
|
case A_GOEND: |
case A_GOEND: |
|
|
cmd_exec(); |
cmd_exec(); |
if (number < 0) |
if (number < 0) |
number = 0; |
number = 0; |
jump_line_loc((POSITION) number, jump_sline); |
jump_line_loc((off_t) number, jump_sline); |
break; |
break; |
|
|
case A_STAT: |
case A_STAT: |
|
|
/* |
/* |
* Exit. |
* Exit. |
*/ |
*/ |
#if !SMALL |
if (curr_ifile != NULL_IFILE && |
if (curr_ifile != NULL_IFILE && |
ch_getflags() & CH_HELPFILE) { |
ch_getflags() & CH_HELPFILE) |
|
{ |
|
/* |
/* |
* Quit while viewing the help file |
* Quit while viewing the help file |
* just means return to viewing the |
* just means return to viewing the |
|
|
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); |
|
|
if (number <= 0) number = 1; \ |
if (number <= 0) number = 1; \ |
mca_search(); \ |
mca_search(); \ |
cmd_exec(); \ |
cmd_exec(); \ |
multi_search((char *)NULL, (int) number); |
multi_search(NULL, (int)number); |
|
|
|
|
case A_F_SEARCH: |
case A_F_SEARCH: |
|
|
goto again; |
goto again; |
|
|
case A_FILTER: |
case A_FILTER: |
#if HILITE_SEARCH |
|
search_type = SRCH_FORW | SRCH_FILTER; |
search_type = SRCH_FORW | SRCH_FILTER; |
mca_search(); |
mca_search(); |
c = getcc(); |
c = getcc(); |
goto again; |
goto again; |
#else |
|
error("Command not available", NULL_PARG); |
|
break; |
|
#endif |
|
|
|
case A_AGAIN_SEARCH: |
case A_AGAIN_SEARCH: |
/* |
/* |
|
|
*/ |
*/ |
DO_SEARCH(); |
DO_SEARCH(); |
break; |
break; |
|
|
case A_T_AGAIN_SEARCH: |
case A_T_AGAIN_SEARCH: |
/* |
/* |
* Repeat previous search, multiple files. |
* Repeat previous search, multiple files. |
|
|
break; |
break; |
|
|
case A_T_REVERSE_SEARCH: |
case A_T_REVERSE_SEARCH: |
/* |
/* |
* Repeat previous search, |
* Repeat previous search, |
* multiple files in reverse direction. |
* multiple files in reverse direction. |
*/ |
*/ |
save_search_type = search_type; |
save_search_type = search_type; |
|
|
/* |
/* |
* Help. |
* Help. |
*/ |
*/ |
#if !SMALL |
|
if (ch_getflags() & CH_HELPFILE) |
if (ch_getflags() & CH_HELPFILE) |
break; |
break; |
if (ungot != NULL || unget_end) { |
if (ungot != NULL || unget_end) { |
|
|
save_hshift = hshift; |
save_hshift = hshift; |
hshift = 0; |
hshift = 0; |
(void) edit(helpfile()); |
(void) edit(helpfile()); |
#endif /* !SMALL */ |
|
break; |
break; |
|
|
case A_EXAMINE: |
case A_EXAMINE: |
#if EXAMINE |
|
/* |
/* |
* Edit a new file. Get the filename. |
* Edit a new file. Get the filename. |
*/ |
*/ |
if (secure) |
if (secure) { |
{ |
|
error("Command not available", NULL_PARG); |
error("Command not available", NULL_PARG); |
break; |
break; |
} |
} |
start_mca(A_EXAMINE, "Examine: ", ml_examine, 0); |
start_mca(A_EXAMINE, "Examine: ", ml_examine, 0); |
c = getcc(); |
c = getcc(); |
goto again; |
goto again; |
#else |
|
error("Command not available", NULL_PARG); |
|
break; |
|
#endif |
|
|
|
case A_VISUAL: |
case A_VISUAL: |
/* |
/* |
* Invoke an editor on the input file. |
* Invoke an editor on the input file. |
*/ |
*/ |
#if EDITOR |
if (secure) { |
if (secure) |
|
{ |
|
error("Command not available", NULL_PARG); |
error("Command not available", NULL_PARG); |
break; |
break; |
} |
} |
if (ch_getflags() & CH_HELPFILE) |
if (ch_getflags() & CH_HELPFILE) |
break; |
break; |
if (strcmp(get_filename(curr_ifile), "-") == 0) |
if (strcmp(get_filename(curr_ifile), "-") == 0) { |
{ |
|
error("Cannot edit standard input", NULL_PARG); |
error("Cannot edit standard input", NULL_PARG); |
break; |
break; |
} |
} |
if (curr_altfilename != NULL) |
if (curr_altfilename != NULL) { |
{ |
error("WARNING: This file was viewed via " |
error("WARNING: This file was viewed via LESSOPEN", |
"LESSOPEN", NULL_PARG); |
NULL_PARG); |
|
} |
} |
start_mca(A_SHELL, "!", ml_shell, 0); |
start_mca(A_SHELL, "!", ml_shell, 0); |
/* |
/* |
|
|
*/ |
*/ |
make_display(); |
make_display(); |
cmd_exec(); |
cmd_exec(); |
lsystem(pr_expand(editproto, 0), (char*)NULL); |
lsystem(pr_expand(editproto, 0), NULL); |
break; |
break; |
#else |
|
error("Command not available", NULL_PARG); |
|
break; |
|
#endif |
|
|
|
case A_NEXT_FILE: |
case A_NEXT_FILE: |
/* |
/* |
* Examine next file. |
* Examine next file. |
*/ |
*/ |
#if TAGS |
if (ntags()) { |
if (ntags()) |
|
{ |
|
error("No next file", NULL_PARG); |
error("No next file", NULL_PARG); |
break; |
break; |
} |
} |
#endif |
|
if (number <= 0) |
if (number <= 0) |
number = 1; |
number = 1; |
if (edit_next((int) number)) |
if (edit_next((int)number)) { |
{ |
if (get_quit_at_eof() && eof_displayed() && |
if (get_quit_at_eof() && eof_displayed() && |
|
!(ch_getflags() & CH_HELPFILE)) |
!(ch_getflags() & CH_HELPFILE)) |
quit(QUIT_OK); |
quit(QUIT_OK); |
parg.p_string = (number > 1) ? "(N-th) " : ""; |
parg.p_string = (number > 1) ? "(N-th) " : ""; |
|
|
/* |
/* |
* Examine previous file. |
* Examine previous file. |
*/ |
*/ |
#if TAGS |
if (ntags()) { |
if (ntags()) |
|
{ |
|
error("No previous file", NULL_PARG); |
error("No previous file", NULL_PARG); |
break; |
break; |
} |
} |
#endif |
|
if (number <= 0) |
if (number <= 0) |
number = 1; |
number = 1; |
if (edit_prev((int) number)) |
if (edit_prev((int)number)) { |
{ |
|
parg.p_string = (number > 1) ? "(N-th) " : ""; |
parg.p_string = (number > 1) ? "(N-th) " : ""; |
error("No %sprevious file", &parg); |
error("No %sprevious file", &parg); |
} |
} |
break; |
break; |
|
|
case A_NEXT_TAG: |
case A_NEXT_TAG: |
#if TAGS |
|
if (number <= 0) |
if (number <= 0) |
number = 1; |
number = 1; |
tagfile = nexttag((int) number); |
tagfile = nexttag((int)number); |
if (tagfile == NULL) |
if (tagfile == NULL) { |
{ |
|
error("No next tag", NULL_PARG); |
error("No next tag", NULL_PARG); |
break; |
break; |
} |
} |
if (edit(tagfile) == 0) |
if (edit(tagfile) == 0) { |
{ |
off_t pos = tagsearch(); |
POSITION pos = tagsearch(); |
if (pos != -1) |
if (pos != NULL_POSITION) |
|
jump_loc(pos, jump_sline); |
jump_loc(pos, jump_sline); |
} |
} |
#else |
|
error("Command not available", NULL_PARG); |
|
#endif |
|
break; |
break; |
|
|
case A_PREV_TAG: |
case A_PREV_TAG: |
#if TAGS |
|
if (number <= 0) |
if (number <= 0) |
number = 1; |
number = 1; |
tagfile = prevtag((int) number); |
tagfile = prevtag((int)number); |
if (tagfile == NULL) |
if (tagfile == NULL) { |
{ |
|
error("No previous tag", NULL_PARG); |
error("No previous tag", NULL_PARG); |
break; |
break; |
} |
} |
if (edit(tagfile) == 0) |
if (edit(tagfile) == 0) { |
{ |
off_t pos = tagsearch(); |
POSITION pos = tagsearch(); |
if (pos != -1) |
if (pos != NULL_POSITION) |
|
jump_loc(pos, jump_sline); |
jump_loc(pos, jump_sline); |
} |
} |
#else |
|
error("Command not available", NULL_PARG); |
|
#endif |
|
break; |
break; |
|
|
case A_INDEX_FILE: |
case A_INDEX_FILE: |
|
|
*/ |
*/ |
if (number <= 0) |
if (number <= 0) |
number = 1; |
number = 1; |
if (edit_index((int) number)) |
if (edit_index((int)number)) |
error("No such file", NULL_PARG); |
error("No such file", NULL_PARG); |
break; |
break; |
|
|
|
|
break; |
break; |
old_ifile = curr_ifile; |
old_ifile = curr_ifile; |
new_ifile = getoff_ifile(curr_ifile); |
new_ifile = getoff_ifile(curr_ifile); |
if (new_ifile == NULL_IFILE) |
if (new_ifile == NULL_IFILE) { |
{ |
ring_bell(); |
bell(); |
|
break; |
break; |
} |
} |
if (edit_ifile(new_ifile) != 0) |
if (edit_ifile(new_ifile) != 0) { |
{ |
|
reedit_ifile(old_ifile); |
reedit_ifile(old_ifile); |
break; |
break; |
} |
} |
|
|
/* |
/* |
* Set an initial command for new files. |
* Set an initial command for new files. |
*/ |
*/ |
start_mca(A_FIRSTCMD, "+", (void*)NULL, 0); |
start_mca(A_FIRSTCMD, "+", NULL, 0); |
c = getcc(); |
c = getcc(); |
goto again; |
goto again; |
|
|
|
|
/* |
/* |
* Shell escape. |
* Shell escape. |
*/ |
*/ |
#if SHELL_ESCAPE |
if (secure) { |
if (secure) |
|
{ |
|
error("Command not available", NULL_PARG); |
error("Command not available", NULL_PARG); |
break; |
break; |
} |
} |
start_mca(A_SHELL, "!", ml_shell, 0); |
start_mca(A_SHELL, "!", ml_shell, 0); |
c = getcc(); |
c = getcc(); |
goto again; |
goto again; |
#else |
|
error("Command not available", NULL_PARG); |
|
break; |
|
#endif |
|
|
|
case A_SETMARK: |
case A_SETMARK: |
/* |
/* |
|
|
break; |
break; |
|
|
case A_PIPE: |
case A_PIPE: |
#if PIPEC |
if (secure) { |
if (secure) |
|
{ |
|
error("Command not available", NULL_PARG); |
error("Command not available", NULL_PARG); |
break; |
break; |
} |
} |
start_mca(A_PIPE, "|mark: ", (void*)NULL, 0); |
start_mca(A_PIPE, "|mark: ", (void*)NULL, 0); |
c = getcc(); |
c = getcc(); |
if (c == erase_char || c == erase2_char || c == kill_char) |
if (c == erase_char || c == erase2_char || |
|
c == kill_char) |
break; |
break; |
if (c == '\n' || c == '\r') |
if (c == '\n' || c == '\r') |
c = '.'; |
c = '.'; |
|
|
start_mca(A_PIPE, "!", ml_shell, 0); |
start_mca(A_PIPE, "!", ml_shell, 0); |
c = getcc(); |
c = getcc(); |
goto again; |
goto again; |
#else |
|
error("Command not available", NULL_PARG); |
|
break; |
|
#endif |
|
|
|
case A_B_BRACKET: |
case A_B_BRACKET: |
case A_F_BRACKET: |
case A_F_BRACKET: |
|
|
shift_count = number; |
shift_count = number; |
else |
else |
number = (shift_count > 0) ? |
number = (shift_count > 0) ? |
shift_count : sc_width / 2; |
shift_count : sc_width / 2; |
if (number > hshift) |
if (number > hshift) |
number = hshift; |
number = hshift; |
hshift -= number; |
hshift -= number; |
|
|
shift_count = number; |
shift_count = number; |
else |
else |
number = (shift_count > 0) ? |
number = (shift_count > 0) ? |
shift_count : sc_width / 2; |
shift_count : sc_width / 2; |
hshift += number; |
hshift += number; |
screen_trashed = 1; |
screen_trashed = 1; |
break; |
break; |
|
|
* Display the current char, so the user knows |
* Display the current char, so the user knows |
* what's going on, and get another character. |
* what's going on, and get another character. |
*/ |
*/ |
if (mca != A_PREFIX) |
if (mca != A_PREFIX) { |
{ |
|
cmd_reset(); |
cmd_reset(); |
start_mca(A_PREFIX, " ", (void*)NULL, |
start_mca(A_PREFIX, " ", (void*)NULL, |
CF_QUIT_ON_ERASE); |
CF_QUIT_ON_ERASE); |
(void) cmd_char(c); |
(void) cmd_char(c); |
} |
} |
c = getcc(); |
c = getcc(); |
|
|
break; |
break; |
|
|
default: |
default: |
bell(); |
ring_bell(); |
break; |
break; |
} |
} |
} |
} |