Changeset View
Changeset View
Standalone View
Standalone View
contrib/less/command.c
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | |||||
struct ungot { | struct ungot { | ||||
struct ungot *ug_next; | struct ungot *ug_next; | ||||
char ug_char; | char ug_char; | ||||
char ug_end_command; | char ug_end_command; | ||||
}; | }; | ||||
static struct ungot* ungot = NULL; | static struct ungot* ungot = NULL; | ||||
static void multi_search(); | static void multi_search(char *pattern, int n, int silent); | ||||
/* | /* | ||||
* Move the cursor to start of prompt line before executing a command. | * Move the cursor to start of prompt line before executing a command. | ||||
* 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 | #if HILITE_SEARCH | ||||
clear_attn(); | clear_attn(); | ||||
#endif | #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, constant char *prompt, constant 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(prompt); | ||||
set_mlist(mlist, cmdflags); | set_mlist(mlist, cmdflags); | ||||
} | } | ||||
public int | public 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 HILITE_SEARCH | ||||
if (search_type & SRCH_FILTER) | if (search_type & SRCH_FILTER) | ||||
mca = A_FILTER; | mca = A_FILTER; | ||||
else | else | ||||
#endif | #endif | ||||
if (search_type & SRCH_FORW) | if (search_type & SRCH_FORW) | ||||
mca = A_F_SEARCH; | mca = A_F_SEARCH; | ||||
Show All 26 Lines | #endif | ||||
forw_prompt = 0; | forw_prompt = 0; | ||||
set_mlist(ml_search, 0); | set_mlist(ml_search, 0); | ||||
} | } | ||||
/* | /* | ||||
* 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) ? "_" : "-"; | ||||
Show All 18 Lines | mca_opt_toggle(void) | ||||
forw_prompt = 0; | forw_prompt = 0; | ||||
set_mlist(NULL, 0); | set_mlist(NULL, 0); | ||||
} | } | ||||
/* | /* | ||||
* 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: | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | |||||
#endif | #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 (flag == OPT_NO_TOGGLE) | if (flag == OPT_NO_TOGGLE) | ||||
{ | { | ||||
switch (c) | switch (c) | ||||
{ | { | ||||
case '_': | case '_': | ||||
/* "__" = long option name. */ | /* "__" = long option name. */ | ||||
Show All 34 Lines | |||||
/* | /* | ||||
* 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. | ||||
Show All 32 Lines | mca_opt_nonfirst_char(int c) | ||||
} | } | ||||
return (MCA_MORE); | return (MCA_MORE); | ||||
} | } | ||||
/* | /* | ||||
* 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; | ||||
/* | /* | ||||
* This may be a short option (single char), | * This may be a short option (single char), | ||||
* 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. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | mca_opt_char(int c) | ||||
start_mca(A_OPT_TOGGLE, opt_prompt(curropt), (void*)NULL, 0); | start_mca(A_OPT_TOGGLE, opt_prompt(curropt), (void*)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 | ||||
Show All 39 Lines | mca_search_char(int c) | ||||
} | } | ||||
return (NO_MCA); | return (NO_MCA); | ||||
} | } | ||||
/* | /* | ||||
* 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. | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | mca_char(int c) | ||||
*/ | */ | ||||
return (MCA_MORE); | return (MCA_MORE); | ||||
} | } | ||||
/* | /* | ||||
* 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 | #if HILITE_SEARCH | ||||
clr_hilite(); | clr_hilite(); | ||||
#endif | #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 == NULL_POSITION) | if (initial_scrpos.pos == NULL_POSITION) | ||||
/* | /* | ||||
Show All 23 Lines | if (empty_screen()) | ||||
ignore_eoi = save_ignore_eoi; | ignore_eoi = save_ignore_eoi; | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Display the appropriate prompt. | * Display the appropriate prompt. | ||||
*/ | */ | ||||
static void | static void | ||||
prompt() | prompt(void) | ||||
{ | { | ||||
register constant char *p; | constant char *p; | ||||
if (ungot != NULL && !ungot->ug_end_command) | if (ungot != NULL && !ungot->ug_end_command) | ||||
{ | { | ||||
/* | /* | ||||
* 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; | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | #endif | ||||
} | } | ||||
clear_eol(); | clear_eol(); | ||||
} | } | ||||
/* | /* | ||||
* Display the less version message. | * Display the less version message. | ||||
*/ | */ | ||||
public void | public void | ||||
dispversion() | dispversion(void) | ||||
{ | { | ||||
PARG parg; | PARG parg; | ||||
parg.p_string = version; | parg.p_string = version; | ||||
error("less %s", &parg); | error("less %s", &parg); | ||||
} | } | ||||
/* | /* | ||||
* Get command character. | * Get command character. | ||||
* The character normally comes from the keyboard, | * The character normally comes from the keyboard, | ||||
* 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 | public int | ||||
getcc() | getcc(void) | ||||
{ | { | ||||
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. | ||||
*/ | */ | ||||
return (getchr()); | return (getchr()); | ||||
} | } | ||||
Show All 38 Lines | getcc(void) | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* "Unget" a command character. | * "Unget" a command character. | ||||
* The next getcc() will return this character. | * The next getcc() will return this character. | ||||
*/ | */ | ||||
public void | public void | ||||
ungetcc(c) | ungetcc(int c) | ||||
int c; | |||||
{ | { | ||||
struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot)); | struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot)); | ||||
ug->ug_char = (char) c; | ug->ug_char = (char) c; | ||||
ug->ug_end_command = (c == CHAR_END_COMMAND); | ug->ug_end_command = (c == CHAR_END_COMMAND); | ||||
ug->ug_next = ungot; | ug->ug_next = ungot; | ||||
ungot = ug; | ungot = ug; | ||||
} | } | ||||
/* | /* | ||||
* 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 | public void | ||||
ungetsc(s) | ungetsc(char *s) | ||||
char *s; | |||||
{ | { | ||||
register char *p; | char *p; | ||||
for (p = s + strlen(s) - 1; p >= s; p--) | for (p = s + strlen(s) - 1; p >= s; p--) | ||||
ungetcc(*p); | ungetcc(*p); | ||||
} | } | ||||
/* | /* | ||||
* Search for a pattern, possibly in multiple files. | * Search for a pattern, possibly in multiple files. | ||||
* 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, silent) | multi_search(char *pattern, int n, int silent) | ||||
char *pattern; | |||||
int n; | |||||
int silent; | |||||
{ | { | ||||
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) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | if (changed_file) | ||||
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; | POSITION curr_len; | ||||
if (ch_getflags() & CH_HELPFILE) | if (ch_getflags() & CH_HELPFILE) | ||||
return (A_NOACTION); | return (A_NOACTION); | ||||
cmd_exec(); | cmd_exec(); | ||||
jump_forw_buffered(); | jump_forw_buffered(); | ||||
Show All 23 Lines | forw_loop(int until_hilite) | ||||
return (A_NOACTION); | 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. | ||||
*/ | */ | ||||
public void | public void | ||||
commands() | commands(void) | ||||
{ | { | ||||
register int c; | int c; | ||||
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; | ||||
char tbuf[2]; | char tbuf[2]; | ||||
PARG parg; | PARG parg; | ||||
IFILE old_ifile; | IFILE old_ifile; | ||||
IFILE new_ifile; | IFILE new_ifile; | ||||
char *tagfile; | char *tagfile; | ||||
▲ Show 20 Lines • Show All 792 Lines • Show Last 20 Lines |