2 * Copyright (C) 1984-2022 Mark Nudelman
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
7 * For more information, see the README file.
12 * User-level command processor.
16 #if MSDOS_COMPILER==WIN32C
23 extern int erase_char
, erase2_char
, kill_char
;
25 extern int quit_if_one_screen
;
31 extern int jump_sline
;
34 extern int top_scroll
;
35 extern int ignore_eoi
;
40 extern int status_col
;
41 extern POSITION highest_hilite
;
42 extern POSITION start_attnpos
;
43 extern POSITION end_attnpos
;
44 extern char *every_first_cmd
;
45 extern char version
[];
46 extern struct scrpos initial_scrpos
;
47 extern IFILE curr_ifile
;
48 extern void *ml_search
;
49 extern void *ml_examine
;
50 extern int wheel_lines
;
51 extern int header_lines
;
52 extern int def_search_type
;
53 extern int updown_match
;
54 #if SHELL_ESCAPE || PIPEC
55 extern void *ml_shell
;
59 extern char *editproto
;
61 extern int screen_trashed
; /* The screen has been overwritten */
62 extern int shift_count
;
64 extern int forw_prompt
;
65 extern int incr_search
;
66 #if MSDOS_COMPILER==WIN32C
71 static char *shellcmd
= NULL
; /* For holding last shell command for "!!" */
73 static int mca
; /* The multicharacter command (action) */
74 static int search_type
; /* The previous type of search */
75 static LINENUM number
; /* The number typed by the user */
76 static long fraction
; /* The fractional part of the number */
77 static struct loption
*curropt
;
80 static int optgetname
;
81 static POSITION bottompos
;
82 static int save_hshift
;
83 static int save_bs_mode
;
88 /* Stack of ungotten chars (via ungetcc) */
90 struct ungot
*ug_next
;
93 static struct ungot
* ungot
= NULL
;
95 static void multi_search
LESSPARAMS((char *pattern
, int n
, int silent
));
98 * Move the cursor to start of prompt line before executing a command.
99 * This looks nicer if the command takes a long time before
100 * updating the screen.
111 * Indicate we are reading a multi-character command.
123 * Indicate we are not reading a multi-character command.
126 clear_mca(VOID_PARAM
)
134 * Set up the display to start a new multi-character command.
137 start_mca(action
, prompt
, mlist
, cmdflags
)
139 constant
char *prompt
;
145 set_mlist(mlist
, cmdflags
);
151 return (mca
!= 0 && mca
!= A_PREFIX
);
155 * Set up the display to start a new search command.
158 mca_search1(VOID_PARAM
)
161 if (search_type
& SRCH_FILTER
)
165 if (search_type
& SRCH_FORW
)
170 if (search_type
& SRCH_NO_MATCH
)
171 cmd_putstr("Non-match ");
172 if (search_type
& SRCH_FIRST_FILE
)
173 cmd_putstr("First-file ");
174 if (search_type
& SRCH_PAST_EOF
)
175 cmd_putstr("EOF-ignore ");
176 if (search_type
& SRCH_NO_MOVE
)
177 cmd_putstr("Keep-pos ");
178 if (search_type
& SRCH_NO_REGEX
)
179 cmd_putstr("Regex-off ");
180 if (search_type
& SRCH_WRAP
)
184 if (search_type
& SRCH_FILTER
)
188 if (search_type
& SRCH_FORW
)
196 mca_search(VOID_PARAM
)
199 set_mlist(ml_search
, 0);
203 * Set up the display to start a new toggle-option command.
206 mca_opt_toggle(VOID_PARAM
)
212 no_prompt
= (optflag
& OPT_NO_PROMPT
);
213 flag
= (optflag
& ~OPT_NO_PROMPT
);
214 dash
= (flag
== OPT_NO_TOGGLE
) ? "_" : "-";
216 set_mca(A_OPT_TOGGLE
);
236 * Execute a multicharacter command.
252 multi_search(cbuf
, (int) number
, 0);
256 search_type
^= SRCH_NO_MATCH
;
257 set_filter_pattern(cbuf
, search_type
);
262 * Skip leading spaces or + signs in the string.
264 while (*cbuf
== '+' || *cbuf
== ' ')
266 if (every_first_cmd
!= NULL
)
267 free(every_first_cmd
);
269 every_first_cmd
= NULL
;
271 every_first_cmd
= save(cbuf
);
274 toggle_option(curropt
, opt_lower
, cbuf
, optflag
);
278 match_brac(cbuf
[0], cbuf
[1], 1, (int) number
);
281 match_brac(cbuf
[1], cbuf
[0], 0, (int) number
);
289 /* If tag structure is loaded then clean it up. */
297 * !! just uses whatever is in shellcmd.
298 * Otherwise, copy cmdbuf to shellcmd,
299 * expanding any special characters ("%" or "#").
303 if (shellcmd
!= NULL
)
305 shellcmd
= fexpand(cbuf
);
310 if (shellcmd
== NULL
)
311 lsystem("", "!done");
313 lsystem(shellcmd
, "!done");
320 (void) pipe_mark(pipec
, cbuf
);
321 error("|done", NULL_PARG
);
328 * Is a character an erase or kill char?
334 return (c
== erase_char
|| c
== erase2_char
|| c
== kill_char
);
338 * Is a character a carriage return or newline?
344 return (c
== '\n' || c
== '\r');
348 * Handle the first char of an option (after the initial dash).
351 mca_opt_first_char(c
)
354 int no_prompt
= (optflag
& OPT_NO_PROMPT
);
355 int flag
= (optflag
& ~OPT_NO_PROMPT
);
356 if (flag
== OPT_NO_TOGGLE
)
361 /* "__" = long option name. */
372 optflag
= no_prompt
| ((flag
== OPT_UNSET
) ?
373 OPT_TOGGLE
: OPT_UNSET
);
378 optflag
= no_prompt
| ((flag
== OPT_SET
) ?
379 OPT_TOGGLE
: OPT_SET
);
383 optflag
^= OPT_NO_PROMPT
;
387 /* "--" = long option name. */
393 /* Char was not handled here. */
398 * Add a char to a long option name.
399 * See if we've got a match for an option name yet.
400 * If so, display the complete name and stop
401 * accepting chars until user hits RETURN.
404 mca_opt_nonfirst_char(c
)
414 * Already have a match for the name.
415 * Don't accept anything but erase/kill.
417 if (is_erase_char(c
))
422 * Add char to cmd buffer and try to match
425 if (cmd_char(c
) == CC_QUIT
)
430 opt_lower
= ASCII_IS_LOWER(p
[0]);
432 curropt
= findopt_name(&p
, &oname
, &err
);
437 * Remember the option and
438 * display the full option name.
442 for (p
= oname
; *p
!= '\0'; p
++)
445 if (!opt_lower
&& ASCII_IS_LOWER(c
))
446 c
= ASCII_TO_UPPER(c
);
447 if (cmd_char(c
) != CC_OK
)
450 } else if (err
!= OPT_AMBIG
)
458 * Handle a char of an option toggle command.
467 * This may be a short option (single char),
468 * or one char of a long option name,
469 * or one char of the option parameter.
471 if (curropt
== NULL
&& len_cmdbuf() == 0)
473 int ret
= mca_opt_first_char(c
);
479 /* We're getting a long option name. */
480 if (!is_newline_char(c
) && c
!= '=')
481 return (mca_opt_nonfirst_char(c
));
484 parg
.p_string
= get_cmdbuf();
485 if (parg
.p_string
== NULL
)
487 error("There is no --%s option", &parg
);
494 if (is_erase_char(c
))
497 /* We're getting the option parameter. */
499 curropt
= findopt(c
);
502 parg
.p_string
= propt(c
);
503 error("There is no %s option", &parg
);
506 opt_lower
= ASCII_IS_LOWER(c
);
509 * If the option which was entered does not take a
510 * parameter, toggle the option immediately,
511 * so user doesn't have to hit RETURN.
513 if ((optflag
& ~OPT_NO_PROMPT
) != OPT_TOGGLE
||
514 !opt_has_param(curropt
))
516 toggle_option(curropt
, opt_lower
, "", optflag
);
520 * Display a prompt appropriate for the option parameter.
522 start_mca(A_OPT_TOGGLE
, opt_prompt(curropt
), (void*)NULL
, 0);
527 * Normalize search type.
533 /* WRAP and PAST_EOF are mutually exclusive. */
534 if ((st
& (SRCH_PAST_EOF
|SRCH_WRAP
)) == (SRCH_PAST_EOF
|SRCH_WRAP
))
540 * Handle a char of a search command.
549 * Certain characters as the first char of
550 * the pattern have special meaning:
551 * ! Toggle the NO_MATCH flag
552 * * Toggle the PAST_EOF flag
553 * @ Toggle the FIRST_FILE flag
555 if (len_cmdbuf() > 0)
560 case CONTROL('E'): /* ignore END of file */
563 flag
= SRCH_PAST_EOF
;
565 case CONTROL('F'): /* FIRST file */
568 flag
= SRCH_FIRST_FILE
;
570 case CONTROL('K'): /* KEEP position */
574 case CONTROL('W'): /* WRAP around */
578 case CONTROL('R'): /* Don't use REGULAR EXPRESSIONS */
579 flag
= SRCH_NO_REGEX
;
581 case CONTROL('N'): /* NOT match */
583 flag
= SRCH_NO_MATCH
;
589 search_type
= norm_search_type(search_type
^ flag
);
597 * Handle a character of a multi-character command.
609 * We're not in a multicharacter command.
615 * In the prefix of a command.
616 * This not considered a multichar command
617 * (even tho it uses cmdbuf, etc.).
618 * It is handled in the commands() switch.
624 * Entering digits of a number.
625 * Terminated by a non-digit.
627 if ((c
>= '0' && c
<= '9') || c
== '.')
629 switch (editchar(c
, ECF_PEEK
|ECF_NOHISTORY
|ECF_NOCOMPLETE
|ECF_NORIGHTLEFT
))
633 * Ignore this char and get another one.
638 * Not part of the number.
639 * End the number and treat this char
640 * as a normal command character.
642 number
= cmd_int(&fraction
);
650 ret
= mca_opt_char(c
);
658 ret
= mca_search_char(c
);
664 /* Other multicharacter command. */
669 * The multichar command is terminated by a newline.
671 if (is_newline_char(c
))
674 * Execute the command.
681 * Append the char to the command buffer.
683 if (cmd_char(c
) == CC_QUIT
)
685 * Abort the multi-char command.
693 if (len_cmdbuf() >= 2)
696 * Special case for the bracket-matching commands.
697 * Execute the command after getting exactly two
698 * characters from the user.
708 /* Incremental search: do a search after every input char. */
709 int st
= (search_type
& (SRCH_FORW
|SRCH_BACK
|SRCH_NO_MATCH
|SRCH_NO_REGEX
|SRCH_NO_MOVE
|SRCH_WRAP
));
710 char *pattern
= get_cmdbuf();
714 * Must save updown_match because mca_search
715 * reinits it. That breaks history scrolling.
716 * {{ This is ugly. mca_search probably shouldn't call set_mlist. }}
718 int save_updown_match
= updown_match
;
720 if (*pattern
== '\0')
722 /* User has backspaced to an empty pattern. */
726 if (search(st
| SRCH_INCR
, pattern
, 1) != 0)
727 /* No match, invalid pattern, etc. */
730 /* Redraw the search prompt and search string. */
732 updown_match
= save_updown_match
;
739 * Need another character.
745 * Discard any buffered file data.
748 clear_buffers(VOID_PARAM
)
750 if (!(ch_getflags() & CH_CANSEEK
))
760 * Make sure the screen is displayed.
763 make_display(VOID_PARAM
)
766 * If nothing is displayed yet, display starting from initial_scrpos.
770 if (initial_scrpos
.pos
== NULL_POSITION
)
771 jump_loc(ch_zero(), 1);
773 jump_loc(initial_scrpos
.pos
, initial_scrpos
.ln
);
774 } else if (screen_trashed
)
776 int save_top_scroll
= top_scroll
;
777 int save_ignore_eoi
= ignore_eoi
;
780 if (screen_trashed
== 2)
782 /* Special case used by ignore_eoi: re-open the input file
783 * and jump to the end of the file. */
788 top_scroll
= save_top_scroll
;
789 ignore_eoi
= save_ignore_eoi
;
794 * Display the appropriate prompt.
801 if (ungot
!= NULL
&& ungot
->ug_char
!= CHAR_END_COMMAND
)
804 * No prompt necessary if commands are from
805 * ungotten chars rather than from the user.
811 * Make sure the screen is displayed.
814 bottompos
= position(BOTTOM_PLUS_ONE
);
817 * If we've hit EOF on the last file and the -E flag is set, quit.
819 if (get_quit_at_eof() == OPT_ONPLUS
&&
820 eof_displayed() && !(ch_getflags() & CH_HELPFILE
) &&
821 next_ifile(curr_ifile
) == NULL_IFILE
)
825 * If the entire file is displayed and the -F flag is set, quit.
827 if (quit_if_one_screen
&&
828 entire_file_displayed() && !(ch_getflags() & CH_HELPFILE
) &&
829 next_ifile(curr_ifile
) == NULL_IFILE
)
831 quit_if_one_screen
= FALSE
; /* only get one chance at this */
833 #if MSDOS_COMPILER==WIN32C
835 * In Win32, display the file name in the window title.
837 if (!(ch_getflags() & CH_HELPFILE
))
839 WCHAR w
[MAX_PATH
+16];
840 p
= pr_expand("Less?f - %f.");
841 MultiByteToWideChar(CP_ACP
, 0, p
, -1, w
, sizeof(w
)/sizeof(*w
));
847 * Select the proper prompt and display it.
850 * If the previous action was a forward movement,
851 * don't clear the bottom line of the display;
852 * just print the prompt since the forward movement guarantees
853 * that we're in the right position to display the prompt.
854 * Clearing the line could cause a problem: for example, if the last
855 * line displayed ended at the right screen edge without a newline,
856 * then clearing would clear the last displayed line rather than
868 if (p
== NULL
|| *p
== '\0')
870 at_enter(AT_NORMAL
|AT_COLOR_PROMPT
);
875 #if MSDOS_COMPILER==WIN32C
878 MultiByteToWideChar(CP_ACP
, 0, p
, -1, w
, sizeof(w
)/sizeof(*w
));
879 WideCharToMultiByte(utf_mode
? CP_UTF8
: GetConsoleOutputCP(),
880 0, w
, -1, a
, sizeof(a
), NULL
, NULL
);
890 * Display the less version message.
893 dispversion(VOID_PARAM
)
897 parg
.p_string
= version
;
898 error("less %s", &parg
);
902 * Return a character to complete a partial command, if possible.
905 getcc_end_command(VOID_PARAM
)
910 /* We have a number but no command. Treat as #g. */
914 /* We have "/string" but no newline. Add the \n. */
917 /* Some other incomplete command. Let user complete it. */
918 return ((ungot
== NULL
) ? getchr() : 0);
923 * Get command character.
924 * The character normally comes from the keyboard,
925 * but may come from ungotten characters
926 * (characters previously given to ungetcc or ungetsc).
936 /* Normal case: no ungotten chars.
937 * Get char from the user. */
941 /* Ungotten chars available:
942 * Take the top of stack (most recent). */
943 struct ungot
*ug
= ungot
;
948 if (c
== CHAR_END_COMMAND
)
949 c
= getcc_end_command();
956 * Get a command character, but if we receive the orig sequence,
957 * convert it to the repl sequence.
960 getcc_repl(orig
, repl
, gr_getc
, gr_ungetc
)
963 LWCHAR (*gr_getc
)(VOID_PARAM
);
964 void (*gr_ungetc
)(LWCHAR
);
971 if (orig
== NULL
|| orig
[0] == '\0')
976 if (c
!= orig
[ki
] || ki
>= sizeof(keys
)-1)
978 /* This is not orig we have been receiving.
979 * If we have stashed chars in keys[],
980 * unget them and return the first one. */
982 (*gr_ungetc
)(keys
[ki
--]);
985 if (orig
[++ki
] == '\0')
987 /* We've received the full orig sequence.
988 * Return the repl sequence. */
991 (*gr_ungetc
)(repl
[ki
--]);
994 /* We've received a partial orig sequence (ki chars of it).
995 * Get next char and see if it continues to match orig. */
1001 * Get command character.
1006 /* Replace kent (keypad Enter) with a newline. */
1007 return getcc_repl(kent
, "\n", getccu
, ungetcc
);
1011 * "Unget" a command character.
1012 * The next getcc() will return this character.
1018 struct ungot
*ug
= (struct ungot
*) ecalloc(1, sizeof(struct ungot
));
1021 ug
->ug_next
= ungot
;
1026 * "Unget" a command character.
1027 * If any other chars are already ungotten, put this one after those.
1033 struct ungot
*ug
= (struct ungot
*) ecalloc(1, sizeof(struct ungot
));
1041 for (pu
= ungot
; pu
->ug_next
!= NULL
; pu
= pu
->ug_next
)
1048 * Unget a whole string of command characters.
1049 * The next sequence of getcc()'s will return this string.
1060 * Peek the next command character, without consuming it.
1071 * Search for a pattern, possibly in multiple files.
1072 * If SRCH_FIRST_FILE is set, begin searching at the first file.
1073 * If SRCH_PAST_EOF is set, continue the search thru multiple files.
1076 multi_search(pattern
, n
, silent
)
1086 save_ifile
= save_curr_ifile();
1088 if (search_type
& SRCH_FIRST_FILE
)
1091 * Start at the first (or last) file
1092 * in the command line list.
1094 if (search_type
& SRCH_FORW
)
1095 nomore
= edit_first();
1097 nomore
= edit_last();
1100 unsave_ifile(save_ifile
);
1104 search_type
&= ~SRCH_FIRST_FILE
;
1109 n
= search(search_type
, pattern
, n
);
1111 * The SRCH_NO_MOVE flag doesn't "stick": it gets cleared
1112 * after being used once. This allows "n" to work after
1113 * using a /@@ search.
1115 search_type
&= ~SRCH_NO_MOVE
;
1121 unsave_ifile(save_ifile
);
1127 * Some kind of error in the search.
1128 * Error message has been printed by search().
1132 if ((search_type
& SRCH_PAST_EOF
) == 0)
1134 * We didn't find a match, but we're
1135 * supposed to search only one file.
1139 * Move on to the next file.
1141 if (search_type
& SRCH_FORW
)
1142 nomore
= edit_next(1);
1144 nomore
= edit_prev(1);
1152 * Print an error message if we haven't already.
1154 if (n
> 0 && !silent
)
1155 error("Pattern not found", NULL_PARG
);
1160 * Restore the file we were originally viewing.
1162 reedit_ifile(save_ifile
);
1165 unsave_ifile(save_ifile
);
1170 * Forward forever, or until a highlighted line appears.
1173 forw_loop(until_hilite
)
1178 if (ch_getflags() & CH_HELPFILE
)
1179 return (A_NOACTION
);
1182 jump_forw_buffered();
1183 curr_len
= ch_length();
1184 highest_hilite
= until_hilite
? curr_len
: NULL_POSITION
;
1188 if (until_hilite
&& highest_hilite
> curr_len
)
1200 * This gets us back in "F mode" after processing
1201 * a non-abort signal (e.g. window-change).
1203 if (sigs
&& !ABORT_SIGS())
1204 return (until_hilite
? A_F_UNTIL_HILITE
: A_F_FOREVER
);
1206 return (A_NOACTION
);
1210 * Main command processor.
1211 * Accept and execute commands until a quit command.
1214 commands(VOID_PARAM
)
1220 int save_jump_sline
;
1221 int save_search_type
;
1229 search_type
= SRCH_FORW
;
1230 wscroll
= (sc_height
+ 1) / 2;
1231 newaction
= A_NOACTION
;
1241 * See if any signals need processing.
1247 quit(QUIT_SAVED_STATUS
);
1251 * See if window size changed, for systems that don't
1252 * generate SIGWINCH.
1257 * Display prompt and accept a character.
1263 if (newaction
== A_NOACTION
)
1270 if (newaction
!= A_NOACTION
)
1273 newaction
= A_NOACTION
;
1277 * If we are in a multicharacter command, call mca_char.
1278 * Otherwise we call fcmd_decode to determine the
1279 * action to be performed.
1282 switch (mca_char(c
))
1286 * Need another character.
1292 * Command has been handled by mca_char.
1293 * Start clean with a prompt.
1298 * Not a multi-char command
1299 * (at least, not anymore).
1305 * Decode the command character and decide what to do.
1310 * We're in a multichar command.
1311 * Add the character to the command buffer
1312 * and display it on the screen.
1313 * If the user backspaces past the start
1314 * of the line, abort the command.
1316 if (cmd_char(c
) == CC_QUIT
|| len_cmdbuf() == 0)
1318 cbuf
= get_cmdbuf();
1324 * Don't use cmd_char if we're starting fresh
1325 * at the beginning of a command, because we
1326 * don't want to echo the command until we know
1327 * it is a multichar command. We also don't
1328 * want erase_char/kill_char to be treated
1329 * as line editing characters.
1336 action
= fcmd_decode(cbuf
, &extra
);
1338 * If an "extra" string was returned,
1339 * process it as a string of command characters.
1345 * Clear the cmdbuf string.
1346 * (But not if we're in the prefix of a command,
1347 * because the partial command string is kept there.)
1349 if (action
!= A_PREFIX
)
1356 * First digit of a number.
1358 start_mca(A_DIGIT
, ":", (void*)NULL
, CF_QUIT_ON_ERASE
);
1363 * Forward one window (and set the window size).
1366 swindow
= (int) number
;
1370 * Forward one screen.
1373 number
= get_swindow();
1376 set_attnpos(bottompos
);
1377 forward((int) number
, 0, 1);
1382 * Backward one window (and set the window size).
1385 swindow
= (int) number
;
1389 * Backward one screen.
1392 number
= get_swindow();
1394 backward((int) number
, 0, 1);
1399 * Forward N (default 1) line.
1404 if (show_attn
== OPT_ONPLUS
&& number
> 1)
1405 set_attnpos(bottompos
);
1406 forward((int) number
, 0, 0);
1411 * Backward N (default 1) line.
1416 backward((int) number
, 0, 0);
1421 * Forward wheel_lines lines.
1424 forward(wheel_lines
, 0, 0);
1429 * Backward wheel_lines lines.
1432 backward(wheel_lines
, 0, 0);
1437 * Force forward N (default 1) line.
1442 if (show_attn
== OPT_ONPLUS
&& number
> 1)
1443 set_attnpos(bottompos
);
1444 forward((int) number
, 1, 0);
1449 * Force backward N (default 1) line.
1454 backward((int) number
, 1, 0);
1459 * Force forward one screen.
1462 number
= get_swindow();
1464 if (show_attn
== OPT_ONPLUS
)
1465 set_attnpos(bottompos
);
1466 forward((int) number
, 1, 0);
1471 * Forward forever, ignoring EOF.
1474 set_attnpos(bottompos
);
1475 newaction
= forw_loop(0);
1478 case A_F_UNTIL_HILITE
:
1479 newaction
= forw_loop(1);
1485 * (default same as last 'd' or 'u' command).
1488 wscroll
= (int) number
;
1490 if (show_attn
== OPT_ONPLUS
)
1491 set_attnpos(bottompos
);
1492 forward(wscroll
, 0, 0);
1498 * (default same as last 'd' or 'u' command).
1501 wscroll
= (int) number
;
1503 backward(wscroll
, 0, 0);
1508 * Flush buffers, then repaint screen.
1509 * Don't flush the buffers on a pipe!
1523 * Go to line N, default beginning of file.
1524 * If N <= 0, ignore jump_sline in order to avoid
1525 * empty lines before the beginning of the file.
1527 save_jump_sline
= jump_sline
;
1535 jump_sline
= save_jump_sline
;
1540 * Go to a specified percentage into the file.
1547 if (number
> 100 || (number
== 100 && fraction
!= 0))
1553 jump_percent((int) number
, fraction
);
1558 * Go to line N, default end of file.
1569 * Go to line N, default last buffered byte.
1573 jump_forw_buffered();
1580 * Go to a specified byte position in the file.
1585 jump_line_loc((POSITION
) number
, jump_sline
);
1590 * Print file name, etc.
1592 if (ch_getflags() & CH_HELPFILE
)
1595 parg
.p_string
= eq_message();
1601 * Print version number.
1611 if (curr_ifile
!= NULL_IFILE
&&
1612 ch_getflags() & CH_HELPFILE
)
1615 * Quit while viewing the help file
1616 * just means return to viewing the
1619 hshift
= save_hshift
;
1620 bs_mode
= save_bs_mode
;
1621 if (edit_prev(1) == 0)
1630 * Define abbreviation for a commonly used sequence below.
1632 #define DO_SEARCH() \
1633 if (number <= 0) number = 1; \
1636 multi_search((char *)NULL, (int) number, 0);
1641 * Search forward for a pattern.
1642 * Get the first char of the pattern.
1644 search_type
= SRCH_FORW
| def_search_type
;
1653 * Search backward for a pattern.
1654 * Get the first char of the pattern.
1656 search_type
= SRCH_BACK
| def_search_type
;
1665 search_type
= SRCH_FORW
| SRCH_FILTER
;
1670 error("Command not available", NULL_PARG
);
1674 case A_AGAIN_SEARCH
:
1676 * Repeat previous search.
1681 case A_T_AGAIN_SEARCH
:
1683 * Repeat previous search, multiple files.
1685 search_type
|= SRCH_PAST_EOF
;
1689 case A_REVERSE_SEARCH
:
1691 * Repeat previous search, in reverse direction.
1693 save_search_type
= search_type
;
1694 search_type
= SRCH_REVERSE(search_type
);
1696 search_type
= save_search_type
;
1699 case A_T_REVERSE_SEARCH
:
1701 * Repeat previous search,
1702 * multiple files in reverse direction.
1704 save_search_type
= search_type
;
1705 search_type
= SRCH_REVERSE(search_type
);
1706 search_type
|= SRCH_PAST_EOF
;
1708 search_type
= save_search_type
;
1714 * Clear search string highlighting.
1716 undo_search(action
== A_CLR_SEARCH
);
1723 if (ch_getflags() & CH_HELPFILE
)
1726 save_hshift
= hshift
;
1728 save_bs_mode
= bs_mode
;
1729 bs_mode
= BS_SPECIAL
;
1730 (void) edit(FAKE_HELPFILE
);
1735 * Edit a new file. Get the filename.
1740 start_mca(A_EXAMINE
, "Examine: ", ml_examine
, 0);
1745 error("Command not available", NULL_PARG
);
1750 * Invoke an editor on the input file.
1755 if (ch_getflags() & CH_HELPFILE
)
1757 if (strcmp(get_filename(curr_ifile
), "-") == 0)
1759 error("Cannot edit standard input", NULL_PARG
);
1762 if (get_altfilename(curr_ifile
) != NULL
)
1764 error("WARNING: This file was viewed via LESSOPEN",
1767 start_mca(A_SHELL
, "!", ml_shell
, 0);
1769 * Expand the editor prototype string
1770 * and pass it to the system to execute.
1771 * (Make sure the screen is displayed so the
1772 * expansion of "+%lm" works.)
1776 lsystem(pr_expand(editproto
), (char*)NULL
);
1780 error("Command not available", NULL_PARG
);
1785 * Examine next file.
1790 error("No next file", NULL_PARG
);
1796 if (edit_next((int) number
))
1798 if (get_quit_at_eof() && eof_displayed() &&
1799 !(ch_getflags() & CH_HELPFILE
))
1801 parg
.p_string
= (number
> 1) ? "(N-th) " : "";
1802 error("No %snext file", &parg
);
1808 * Examine previous file.
1813 error("No previous file", NULL_PARG
);
1819 if (edit_prev((int) number
))
1821 parg
.p_string
= (number
> 1) ? "(N-th) " : "";
1822 error("No %sprevious file", &parg
);
1828 * Jump to the next tag in the current tag list.
1833 tagfile
= nexttag((int) number
);
1834 if (tagfile
== NULL
)
1836 error("No next tag", NULL_PARG
);
1840 if (edit(tagfile
) == 0)
1842 POSITION pos
= tagsearch();
1843 if (pos
!= NULL_POSITION
)
1844 jump_loc(pos
, jump_sline
);
1847 error("Command not available", NULL_PARG
);
1853 * Jump to the previous tag in the current tag list.
1858 tagfile
= prevtag((int) number
);
1859 if (tagfile
== NULL
)
1861 error("No previous tag", NULL_PARG
);
1865 if (edit(tagfile
) == 0)
1867 POSITION pos
= tagsearch();
1868 if (pos
!= NULL_POSITION
)
1869 jump_loc(pos
, jump_sline
);
1872 error("Command not available", NULL_PARG
);
1878 * Examine a particular file.
1882 if (edit_index((int) number
))
1883 error("No such file", NULL_PARG
);
1888 * Remove a file from the input file list.
1890 if (ch_getflags() & CH_HELPFILE
)
1892 old_ifile
= curr_ifile
;
1893 new_ifile
= getoff_ifile(curr_ifile
);
1894 if (new_ifile
== NULL_IFILE
)
1899 if (edit_ifile(new_ifile
) != 0)
1901 reedit_ifile(old_ifile
);
1904 del_ifile(old_ifile
);
1909 * Change the setting of an option.
1911 optflag
= OPT_TOGGLE
;
1915 cbuf
= opt_toggle_disallowed(c
);
1918 error(cbuf
, NULL_PARG
);
1925 * Report the setting of an option.
1927 optflag
= OPT_NO_TOGGLE
;
1935 * Set an initial command for new files.
1937 start_mca(A_FIRSTCMD
, "+", (void*)NULL
, 0);
1948 start_mca(A_SHELL
, "!", ml_shell
, 0);
1953 error("Command not available", NULL_PARG
);
1961 if (ch_getflags() & CH_HELPFILE
)
1963 start_mca(A_SETMARK
, "set mark: ", (void*)NULL
, 0);
1965 if (is_erase_char(c
) || is_newline_char(c
))
1967 setmark(c
, action
== A_SETMARKBOT
? BOTTOM
: TOP
);
1975 start_mca(A_CLRMARK
, "clear mark: ", (void*)NULL
, 0);
1977 if (is_erase_char(c
) || is_newline_char(c
))
1985 * Jump to a marked position.
1987 start_mca(A_GOMARK
, "goto mark: ", (void*)NULL
, 0);
1989 if (is_erase_char(c
) || is_newline_char(c
))
1997 * Write part of the input to a pipe to a shell command.
2002 start_mca(A_PIPE
, "|mark: ", (void*)NULL
, 0);
2004 if (is_erase_char(c
))
2006 if (is_newline_char(c
))
2011 start_mca(A_PIPE
, "!", ml_shell
, 0);
2016 error("Command not available", NULL_PARG
);
2021 start_mca(action
, "Brackets: ", (void*)NULL
, 0);
2030 shift_count
= number
;
2032 number
= (shift_count
> 0) ?
2033 shift_count
: sc_width
/ 2;
2034 if (number
> hshift
)
2045 shift_count
= number
;
2047 number
= (shift_count
> 0) ?
2048 shift_count
: sc_width
/ 2;
2055 * Shift view left to margin.
2063 * Shift view right to view rightmost char on screen.
2071 * The command is incomplete (more chars are needed).
2072 * Display the current char, so the user knows
2073 * what's going on, and get another character.
2075 if (mca
!= A_PREFIX
)
2078 start_mca(A_PREFIX
, " ", (void*)NULL
,