3 * Copyright (C) 1984-2021 Mark Nudelman
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Less License, as specified in the README file.
8 * For more information, see the README file.
13 * User-level command processor.
17 #if MSDOS_COMPILER==WIN32C
24 extern int erase_char, erase2_char, kill_char;
26 extern int quit_if_one_screen;
32 extern int jump_sline;
35 extern int top_scroll;
36 extern int ignore_eoi;
41 extern int less_is_more;
42 extern int status_col;
43 extern POSITION highest_hilite;
44 extern POSITION start_attnpos;
45 extern POSITION end_attnpos;
46 extern char *every_first_cmd;
47 extern char version[];
48 extern struct scrpos initial_scrpos;
49 extern IFILE curr_ifile;
50 extern void *ml_search;
51 extern void *ml_examine;
52 extern int wheel_lines;
53 #if SHELL_ESCAPE || PIPEC
54 extern void *ml_shell;
58 extern char *editproto;
60 extern int screen_trashed; /* The screen has been overwritten */
61 extern int shift_count;
63 extern int forw_prompt;
64 extern int incr_search;
65 #if MSDOS_COMPILER==WIN32C
70 static char *shellcmd = NULL; /* For holding last shell command for "!!" */
72 static int mca; /* The multicharacter command (action) */
73 static int search_type; /* The previous type of search */
74 static LINENUM number; /* The number typed by the user */
75 static long fraction; /* The fractional part of the number */
76 static struct loption *curropt;
79 static int optgetname;
80 static POSITION bottompos;
81 static int save_hshift;
82 static int save_bs_mode;
87 /* Stack of ungotten chars (via ungetcc) */
89 struct ungot *ug_next;
92 static struct ungot* ungot = NULL;
94 static void multi_search LESSPARAMS((char *pattern, int n, int silent));
97 * Move the cursor to start of prompt line before executing a command.
98 * This looks nicer if the command takes a long time before
99 * updating the screen.
110 * Indicate we are reading a multi-character command.
122 * Indicate we are not reading a multi-character command.
125 clear_mca(VOID_PARAM)
133 * Set up the display to start a new multi-character command.
136 start_mca(action, prompt, mlist, cmdflags)
138 constant char *prompt;
144 set_mlist(mlist, cmdflags);
150 return (mca != 0 && mca != A_PREFIX);
154 * Set up the display to start a new search command.
157 mca_search(VOID_PARAM)
160 if (search_type & SRCH_FILTER)
164 if (search_type & SRCH_FORW)
169 if (search_type & SRCH_NO_MATCH)
170 cmd_putstr("Non-match ");
171 if (search_type & SRCH_FIRST_FILE)
172 cmd_putstr("First-file ");
173 if (search_type & SRCH_PAST_EOF)
174 cmd_putstr("EOF-ignore ");
175 if (search_type & SRCH_NO_MOVE)
176 cmd_putstr("Keep-pos ");
177 if (search_type & SRCH_NO_REGEX)
178 cmd_putstr("Regex-off ");
179 if (search_type & SRCH_WRAP)
183 if (search_type & SRCH_FILTER)
187 if (search_type & SRCH_FORW)
192 set_mlist(ml_search, 0);
196 * Set up the display to start a new toggle-option command.
199 mca_opt_toggle(VOID_PARAM)
205 no_prompt = (optflag & OPT_NO_PROMPT);
206 flag = (optflag & ~OPT_NO_PROMPT);
207 dash = (flag == OPT_NO_TOGGLE) ? "_" : "-";
209 set_mca(A_OPT_TOGGLE);
229 * Execute a multicharacter command.
243 multi_search(cbuf, (int) number, 0);
247 search_type ^= SRCH_NO_MATCH;
248 set_filter_pattern(cbuf, search_type);
253 * Skip leading spaces or + signs in the string.
255 while (*cbuf == '+' || *cbuf == ' ')
257 if (every_first_cmd != NULL)
258 free(every_first_cmd);
260 every_first_cmd = NULL;
262 every_first_cmd = save(cbuf);
265 toggle_option(curropt, opt_lower, cbuf, optflag);
269 match_brac(cbuf[0], cbuf[1], 1, (int) number);
272 match_brac(cbuf[1], cbuf[0], 0, (int) number);
280 /* If tag structure is loaded then clean it up. */
288 * !! just uses whatever is in shellcmd.
289 * Otherwise, copy cmdbuf to shellcmd,
290 * expanding any special characters ("%" or "#").
294 if (shellcmd != NULL)
296 shellcmd = fexpand(cbuf);
301 if (shellcmd == NULL)
302 lsystem("", "!done");
304 lsystem(shellcmd, "!done");
311 (void) pipe_mark(pipec, cbuf);
312 error("|done", NULL_PARG);
319 * Is a character an erase or kill char?
325 return (c == erase_char || c == erase2_char || c == kill_char);
329 * Is a character a carriage return or newline?
335 return (c == '\n' || c == '\r');
339 * Handle the first char of an option (after the initial dash).
342 mca_opt_first_char(c)
345 int flag = (optflag & ~OPT_NO_PROMPT);
346 if (flag == OPT_NO_TOGGLE)
351 /* "__" = long option name. */
362 optflag = (flag == OPT_UNSET) ?
363 OPT_TOGGLE : OPT_UNSET;
368 optflag = (flag == OPT_SET) ?
369 OPT_TOGGLE : OPT_SET;
373 optflag ^= OPT_NO_PROMPT;
377 /* "--" = long option name. */
383 /* Char was not handled here. */
388 * Add a char to a long option name.
389 * See if we've got a match for an option name yet.
390 * If so, display the complete name and stop
391 * accepting chars until user hits RETURN.
394 mca_opt_nonfirst_char(c)
404 * Already have a match for the name.
405 * Don't accept anything but erase/kill.
407 if (is_erase_char(c))
412 * Add char to cmd buffer and try to match
415 if (cmd_char(c) == CC_QUIT)
418 opt_lower = ASCII_IS_LOWER(p[0]);
420 curropt = findopt_name(&p, &oname, &err);
425 * Remember the option and
426 * display the full option name.
430 for (p = oname; *p != '\0'; p++)
433 if (!opt_lower && ASCII_IS_LOWER(c))
434 c = ASCII_TO_UPPER(c);
435 if (cmd_char(c) != CC_OK)
438 } else if (err != OPT_AMBIG)
446 * Handle a char of an option toggle command.
455 * This may be a short option (single char),
456 * or one char of a long option name,
457 * or one char of the option parameter.
459 if (curropt == NULL && len_cmdbuf() == 0)
461 int ret = mca_opt_first_char(c);
467 /* We're getting a long option name. */
468 if (!is_newline_char(c))
469 return (mca_opt_nonfirst_char(c));
472 parg.p_string = get_cmdbuf();
473 error("There is no --%s option", &parg);
480 if (is_erase_char(c))
483 /* We're getting the option parameter. */
485 curropt = findopt(c);
488 parg.p_string = propt(c);
489 error("There is no %s option", &parg);
492 opt_lower = ASCII_IS_LOWER(c);
495 * If the option which was entered does not take a
496 * parameter, toggle the option immediately,
497 * so user doesn't have to hit RETURN.
499 if ((optflag & ~OPT_NO_PROMPT) != OPT_TOGGLE ||
500 !opt_has_param(curropt))
502 toggle_option(curropt, opt_lower, "", optflag);
506 * Display a prompt appropriate for the option parameter.
508 start_mca(A_OPT_TOGGLE, opt_prompt(curropt), (void*)NULL, 0);
513 * Handle a char of a search command.
522 * Certain characters as the first char of
523 * the pattern have special meaning:
524 * ! Toggle the NO_MATCH flag
525 * * Toggle the PAST_EOF flag
526 * @ Toggle the FIRST_FILE flag
528 if (len_cmdbuf() > 0)
536 case CONTROL('E'): /* ignore END of file */
538 flag = SRCH_PAST_EOF;
543 case CONTROL('F'): /* FIRST file */
545 flag = SRCH_FIRST_FILE;
547 case CONTROL('K'): /* KEEP position */
551 case CONTROL('W'): /* WRAP around */
555 case CONTROL('R'): /* Don't use REGULAR EXPRESSIONS */
556 flag = SRCH_NO_REGEX;
558 case CONTROL('N'): /* NOT match */
560 flag = SRCH_NO_MATCH;
566 /* Toggle flag, but keep PAST_EOF and WRAP mutually exclusive. */
567 search_type ^= flag | (search_type & (SRCH_PAST_EOF|SRCH_WRAP));
575 * Handle a character of a multi-character command.
587 * We're not in a multicharacter command.
593 * In the prefix of a command.
594 * This not considered a multichar command
595 * (even tho it uses cmdbuf, etc.).
596 * It is handled in the commands() switch.
602 * Entering digits of a number.
603 * Terminated by a non-digit.
605 if ((c >= '0' && c <= '9') || c == '.')
607 switch (editchar(c, ECF_PEEK|ECF_NOHISTORY|ECF_NOCOMPLETE|ECF_NORIGHTLEFT))
611 * Ignore this char and get another one.
616 * Not part of the number.
617 * End the number and treat this char
618 * as a normal command character.
620 number = cmd_int(&fraction);
628 ret = mca_opt_char(c);
636 ret = mca_search_char(c);
642 /* Other multicharacter command. */
647 * The multichar command is terminated by a newline.
649 if (is_newline_char(c))
652 * Execute the command.
659 * Append the char to the command buffer.
661 if (cmd_char(c) == CC_QUIT)
663 * Abort the multi-char command.
671 if (len_cmdbuf() >= 2)
674 * Special case for the bracket-matching commands.
675 * Execute the command after getting exactly two
676 * characters from the user.
686 /* Incremental search: do a search after every input char. */
687 int st = (search_type & (SRCH_FORW|SRCH_BACK|SRCH_NO_MATCH|SRCH_NO_REGEX|SRCH_NO_MOVE|SRCH_WRAP));
688 char *pattern = get_cmdbuf();
690 if (*pattern == '\0')
692 /* User has backspaced to an empty pattern. */
696 if (search(st | SRCH_INCR, pattern, 1) != 0)
697 /* No match, invalid pattern, etc. */
700 /* Redraw the search prompt and search string. */
708 * Need another character.
714 * Discard any buffered file data.
717 clear_buffers(VOID_PARAM)
719 if (!(ch_getflags() & CH_CANSEEK))
729 * Make sure the screen is displayed.
732 make_display(VOID_PARAM)
735 * If nothing is displayed yet, display starting from initial_scrpos.
739 if (initial_scrpos.pos == NULL_POSITION)
740 jump_loc(ch_zero(), 1);
742 jump_loc(initial_scrpos.pos, initial_scrpos.ln);
743 } else if (screen_trashed)
745 int save_top_scroll = top_scroll;
746 int save_ignore_eoi = ignore_eoi;
749 if (screen_trashed == 2)
751 /* Special case used by ignore_eoi: re-open the input file
752 * and jump to the end of the file. */
757 top_scroll = save_top_scroll;
758 ignore_eoi = save_ignore_eoi;
763 * Display the appropriate prompt.
770 if (ungot != NULL && ungot->ug_char != CHAR_END_COMMAND)
773 * No prompt necessary if commands are from
774 * ungotten chars rather than from the user.
780 * Make sure the screen is displayed.
783 bottompos = position(BOTTOM_PLUS_ONE);
786 * If we've hit EOF on the last file and the -E flag is set, quit.
788 if (get_quit_at_eof() == OPT_ONPLUS &&
789 eof_displayed() && !(ch_getflags() & CH_HELPFILE) &&
790 next_ifile(curr_ifile) == NULL_IFILE)
794 * If the entire file is displayed and the -F flag is set, quit.
796 if (quit_if_one_screen &&
797 entire_file_displayed() && !(ch_getflags() & CH_HELPFILE) &&
798 next_ifile(curr_ifile) == NULL_IFILE)
800 quit_if_one_screen = FALSE; /* only get one chance at this */
802 #if MSDOS_COMPILER==WIN32C
804 * In Win32, display the file name in the window title.
806 if (!(ch_getflags() & CH_HELPFILE))
808 WCHAR w[MAX_PATH+16];
809 p = pr_expand("Less?f - %f.", 0);
810 MultiByteToWideChar(CP_ACP, 0, p, -1, w, sizeof(w)/sizeof(*w));
816 * Select the proper prompt and display it.
819 * If the previous action was a forward movement,
820 * don't clear the bottom line of the display;
821 * just print the prompt since the forward movement guarantees
822 * that we're in the right position to display the prompt.
823 * Clearing the line could cause a problem: for example, if the last
824 * line displayed ended at the right screen edge without a newline,
825 * then clearing would clear the last displayed line rather than
837 if (p == NULL || *p == '\0')
839 at_enter(AT_NORMAL|AT_COLOR_PROMPT);
844 #if MSDOS_COMPILER==WIN32C
847 MultiByteToWideChar(CP_ACP, 0, p, -1, w, sizeof(w)/sizeof(*w));
848 WideCharToMultiByte(utf_mode ? CP_UTF8 : GetConsoleOutputCP(),
849 0, w, -1, a, sizeof(a), NULL, NULL);
852 at_enter(AT_STANDOUT|AT_COLOR_PROMPT);
860 * Display the less version message.
863 dispversion(VOID_PARAM)
867 parg.p_string = version;
868 error("less %s", &parg);
872 * Return a character to complete a partial command, if possible.
875 getcc_end_command(VOID_PARAM)
880 /* We have a number but no command. Treat as #g. */
884 /* We have "/string" but no newline. Add the \n. */
887 /* Some other incomplete command. Let user complete it. */
888 return ((ungot == NULL) ? getchr() : 0);
893 * Get command character.
894 * The character normally comes from the keyboard,
895 * but may come from ungotten characters
896 * (characters previously given to ungetcc or ungetsc).
906 /* Normal case: no ungotten chars.
907 * Get char from the user. */
911 /* Ungotten chars available:
912 * Take the top of stack (most recent). */
913 struct ungot *ug = ungot;
918 if (c == CHAR_END_COMMAND)
919 c = getcc_end_command();
926 * Get a command character, but if we receive the orig sequence,
927 * convert it to the repl sequence.
930 getcc_repl(orig, repl, gr_getc, gr_ungetc)
933 LWCHAR (*gr_getc)(VOID_PARAM);
934 void (*gr_ungetc)(LWCHAR);
941 if (orig == NULL || orig[0] == '\0')
946 if (c != orig[ki] || ki >= sizeof(keys)-1)
948 /* This is not orig we have been receiving.
949 * If we have stashed chars in keys[],
950 * unget them and return the first one. */
952 (*gr_ungetc)(keys[ki--]);
955 if (orig[++ki] == '\0')
957 /* We've received the full orig sequence.
958 * Return the repl sequence. */
961 (*gr_ungetc)(repl[ki--]);
964 /* We've received a partial orig sequence (ki chars of it).
965 * Get next char and see if it continues to match orig. */
971 * Get command character.
976 /* Replace kent (keypad Enter) with a newline. */
977 return getcc_repl(kent, "\n", getccu, ungetcc);
981 * "Unget" a command character.
982 * The next getcc() will return this character.
988 struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot));
996 * "Unget" a command character.
997 * If any other chars are already ungotten, put this one after those.
1003 struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot));
1011 for (pu = ungot; pu->ug_next != NULL; pu = pu->ug_next)
1018 * Unget a whole string of command characters.
1019 * The next sequence of getcc()'s will return this string.
1030 * Peek the next command character, without consuming it.
1041 * Search for a pattern, possibly in multiple files.
1042 * If SRCH_FIRST_FILE is set, begin searching at the first file.
1043 * If SRCH_PAST_EOF is set, continue the search thru multiple files.
1046 multi_search(pattern, n, silent)
1056 save_ifile = save_curr_ifile();
1058 if (search_type & SRCH_FIRST_FILE)
1061 * Start at the first (or last) file
1062 * in the command line list.
1064 if (search_type & SRCH_FORW)
1065 nomore = edit_first();
1067 nomore = edit_last();
1070 unsave_ifile(save_ifile);
1074 search_type &= ~SRCH_FIRST_FILE;
1079 n = search(search_type, pattern, n);
1081 * The SRCH_NO_MOVE flag doesn't "stick": it gets cleared
1082 * after being used once. This allows "n" to work after
1083 * using a /@@ search.
1085 search_type &= ~SRCH_NO_MOVE;
1091 unsave_ifile(save_ifile);
1097 * Some kind of error in the search.
1098 * Error message has been printed by search().
1102 if ((search_type & SRCH_PAST_EOF) == 0)
1104 * We didn't find a match, but we're
1105 * supposed to search only one file.
1109 * Move on to the next file.
1111 if (search_type & SRCH_FORW)
1112 nomore = edit_next(1);
1114 nomore = edit_prev(1);
1122 * Print an error message if we haven't already.
1124 if (n > 0 && !silent)
1125 error("Pattern not found", NULL_PARG);
1130 * Restore the file we were originally viewing.
1132 reedit_ifile(save_ifile);
1135 unsave_ifile(save_ifile);
1140 * Forward forever, or until a highlighted line appears.
1143 forw_loop(until_hilite)
1148 if (ch_getflags() & CH_HELPFILE)
1149 return (A_NOACTION);
1152 jump_forw_buffered();
1153 curr_len = ch_length();
1154 highest_hilite = until_hilite ? curr_len : NULL_POSITION;
1158 if (until_hilite && highest_hilite > curr_len)
1170 * This gets us back in "F mode" after processing
1171 * a non-abort signal (e.g. window-change).
1173 if (sigs && !ABORT_SIGS())
1174 return (until_hilite ? A_F_UNTIL_HILITE : A_F_FOREVER);
1176 return (A_NOACTION);
1180 * Main command processor.
1181 * Accept and execute commands until a quit command.
1184 commands(VOID_PARAM)
1190 int save_jump_sline;
1191 int save_search_type;
1199 search_type = SRCH_FORW;
1200 wscroll = (sc_height + 1) / 2;
1201 newaction = A_NOACTION;
1211 * See if any signals need processing.
1217 quit(QUIT_SAVED_STATUS);
1221 * See if window size changed, for systems that don't
1222 * generate SIGWINCH.
1227 * Display prompt and accept a character.
1233 if (newaction == A_NOACTION)
1240 if (newaction != A_NOACTION)
1243 newaction = A_NOACTION;
1247 * If we are in a multicharacter command, call mca_char.
1248 * Otherwise we call fcmd_decode to determine the
1249 * action to be performed.
1252 switch (mca_char(c))
1256 * Need another character.
1262 * Command has been handled by mca_char.
1263 * Start clean with a prompt.
1268 * Not a multi-char command
1269 * (at least, not anymore).
1275 * Decode the command character and decide what to do.
1280 * We're in a multichar command.
1281 * Add the character to the command buffer
1282 * and display it on the screen.
1283 * If the user backspaces past the start
1284 * of the line, abort the command.
1286 if (cmd_char(c) == CC_QUIT || len_cmdbuf() == 0)
1288 cbuf = get_cmdbuf();
1292 * Don't use cmd_char if we're starting fresh
1293 * at the beginning of a command, because we
1294 * don't want to echo the command until we know
1295 * it is a multichar command. We also don't
1296 * want erase_char/kill_char to be treated
1297 * as line editing characters.
1304 action = fcmd_decode(cbuf, &extra);
1306 * If an "extra" string was returned,
1307 * process it as a string of command characters.
1313 * Clear the cmdbuf string.
1314 * (But not if we're in the prefix of a command,
1315 * because the partial command string is kept there.)
1317 if (action != A_PREFIX)
1324 * First digit of a number.
1326 start_mca(A_DIGIT, ":", (void*)NULL, CF_QUIT_ON_ERASE);
1331 * Forward one window (and set the window size).
1334 swindow = (int) number;
1338 * Forward one screen.
1341 number = get_swindow();
1344 set_attnpos(bottompos);
1345 forward((int) number, 0, 1);
1350 * Backward one window (and set the window size).
1353 swindow = (int) number;
1357 * Backward one screen.
1360 number = get_swindow();
1362 backward((int) number, 0, 1);
1367 * Forward N (default 1) line.
1372 if (show_attn == OPT_ONPLUS && number > 1)
1373 set_attnpos(bottompos);
1374 forward((int) number, 0, 0);
1379 * Backward N (default 1) line.
1384 backward((int) number, 0, 0);
1389 * Forward wheel_lines lines.
1392 forward(wheel_lines, 0, 0);
1397 * Backward wheel_lines lines.
1400 backward(wheel_lines, 0, 0);
1405 * Force forward N (default 1) line.
1410 if (show_attn == OPT_ONPLUS && number > 1)
1411 set_attnpos(bottompos);
1412 forward((int) number, 1, 0);
1417 * Force backward N (default 1) line.
1422 backward((int) number, 1, 0);
1427 * Force forward one screen.
1430 number = get_swindow();
1432 if (show_attn == OPT_ONPLUS)
1433 set_attnpos(bottompos);
1434 forward((int) number, 1, 0);
1439 * Forward forever, ignoring EOF.
1442 set_attnpos(bottompos);
1443 newaction = forw_loop(0);
1446 case A_F_UNTIL_HILITE:
1447 newaction = forw_loop(1);
1453 * (default same as last 'd' or 'u' command).
1456 wscroll = (int) number;
1458 if (show_attn == OPT_ONPLUS)
1459 set_attnpos(bottompos);
1460 forward(wscroll, 0, 0);
1466 * (default same as last 'd' or 'u' command).
1469 wscroll = (int) number;
1471 backward(wscroll, 0, 0);
1476 * Flush buffers, then repaint screen.
1477 * Don't flush the buffers on a pipe!
1491 * Go to line N, default beginning of file.
1492 * If N <= 0, ignore jump_sline in order to avoid
1493 * empty lines before the beginning of the file.
1495 save_jump_sline = jump_sline;
1503 jump_sline = save_jump_sline;
1508 * Go to a specified percentage into the file.
1515 if (number > 100 || (number == 100 && fraction != 0))
1521 jump_percent((int) number, fraction);
1526 * Go to line N, default end of file.
1537 * Go to line N, default last buffered byte.
1541 jump_forw_buffered();
1548 * Go to a specified byte position in the file.
1553 jump_line_loc((POSITION) number, jump_sline);
1558 * Print file name, etc.
1560 if (ch_getflags() & CH_HELPFILE)
1563 parg.p_string = eq_message();
1569 * Print version number.
1579 if (curr_ifile != NULL_IFILE &&
1580 ch_getflags() & CH_HELPFILE)
1583 * Quit while viewing the help file
1584 * just means return to viewing the
1587 hshift = save_hshift;
1588 bs_mode = save_bs_mode;
1589 if (edit_prev(1) == 0)
1598 * Define abbreviation for a commonly used sequence below.
1600 #define DO_SEARCH() \
1601 if (number <= 0) number = 1; \
1604 multi_search((char *)NULL, (int) number, 0);
1609 * Search forward for a pattern.
1610 * Get the first char of the pattern.
1612 search_type = SRCH_FORW;
1621 * Search backward for a pattern.
1622 * Get the first char of the pattern.
1624 search_type = SRCH_BACK;
1633 search_type = SRCH_FORW | SRCH_FILTER;
1638 error("Command not available", NULL_PARG);
1642 case A_AGAIN_SEARCH:
1644 * Repeat previous search.
1649 case A_T_AGAIN_SEARCH:
1651 * Repeat previous search, multiple files.
1653 search_type |= SRCH_PAST_EOF;
1657 case A_REVERSE_SEARCH:
1659 * Repeat previous search, in reverse direction.
1661 save_search_type = search_type;
1662 search_type = SRCH_REVERSE(search_type);
1664 search_type = save_search_type;
1667 case A_T_REVERSE_SEARCH:
1669 * Repeat previous search,
1670 * multiple files in reverse direction.
1672 save_search_type = search_type;
1673 search_type = SRCH_REVERSE(search_type);
1674 search_type |= SRCH_PAST_EOF;
1676 search_type = save_search_type;
1682 * Clear search string highlighting.
1684 undo_search(action == A_CLR_SEARCH);
1691 if (ch_getflags() & CH_HELPFILE)
1694 save_hshift = hshift;
1696 save_bs_mode = bs_mode;
1697 bs_mode = BS_SPECIAL;
1698 (void) edit(FAKE_HELPFILE);
1703 * Edit a new file. Get the filename.
1708 start_mca(A_EXAMINE, "Examine: ", ml_examine, 0);
1713 error("Command not available", NULL_PARG);
1718 * Invoke an editor on the input file.
1723 if (ch_getflags() & CH_HELPFILE)
1725 if (strcmp(get_filename(curr_ifile), "-") == 0)
1727 error("Cannot edit standard input", NULL_PARG);
1730 if (get_altfilename(curr_ifile) != NULL)
1732 error("WARNING: This file was viewed via LESSOPEN",
1735 start_mca(A_SHELL, "!", ml_shell, 0);
1737 * Expand the editor prototype string
1738 * and pass it to the system to execute.
1739 * (Make sure the screen is displayed so the
1740 * expansion of "+%lm" works.)
1744 lsystem(pr_expand(editproto, 0), (char*)NULL);
1748 error("Command not available", NULL_PARG);
1753 * Examine next file.
1758 error("No next file", NULL_PARG);
1764 if (edit_next((int) number))
1766 if (get_quit_at_eof() && eof_displayed() &&
1767 !(ch_getflags() & CH_HELPFILE))
1769 parg.p_string = (number > 1) ? "(N-th) " : "";
1770 error("No %snext file", &parg);
1776 * Examine previous file.
1781 error("No previous file", NULL_PARG);
1787 if (edit_prev((int) number))
1789 parg.p_string = (number > 1) ? "(N-th) " : "";
1790 error("No %sprevious file", &parg);
1796 * Jump to the next tag in the current tag list.
1801 tagfile = nexttag((int) number);
1802 if (tagfile == NULL)
1804 error("No next tag", NULL_PARG);
1808 if (edit(tagfile) == 0)
1810 POSITION pos = tagsearch();
1811 if (pos != NULL_POSITION)
1812 jump_loc(pos, jump_sline);
1815 error("Command not available", NULL_PARG);
1821 * Jump to the previous tag in the current tag list.
1826 tagfile = prevtag((int) number);
1827 if (tagfile == NULL)
1829 error("No previous tag", NULL_PARG);
1833 if (edit(tagfile) == 0)
1835 POSITION pos = tagsearch();
1836 if (pos != NULL_POSITION)
1837 jump_loc(pos, jump_sline);
1840 error("Command not available", NULL_PARG);
1846 * Examine a particular file.
1850 if (edit_index((int) number))
1851 error("No such file", NULL_PARG);
1856 * Remove a file from the input file list.
1858 if (ch_getflags() & CH_HELPFILE)
1860 old_ifile = curr_ifile;
1861 new_ifile = getoff_ifile(curr_ifile);
1862 if (new_ifile == NULL_IFILE)
1867 if (edit_ifile(new_ifile) != 0)
1869 reedit_ifile(old_ifile);
1872 del_ifile(old_ifile);
1877 * Change the setting of an option.
1879 optflag = OPT_TOGGLE;
1883 cbuf = opt_toggle_disallowed(c);
1886 error(cbuf, NULL_PARG);
1893 * Report the setting of an option.
1895 optflag = OPT_NO_TOGGLE;
1903 * Set an initial command for new files.
1905 start_mca(A_FIRSTCMD, "+", (void*)NULL, 0);
1916 start_mca(A_SHELL, "!", ml_shell, 0);
1921 error("Command not available", NULL_PARG);
1929 if (ch_getflags() & CH_HELPFILE)
1931 start_mca(A_SETMARK, "set mark: ", (void*)NULL, 0);
1933 if (is_erase_char(c) || is_newline_char(c))
1935 setmark(c, action == A_SETMARKBOT ? BOTTOM : TOP);
1943 start_mca(A_CLRMARK, "clear mark: ", (void*)NULL, 0);
1945 if (is_erase_char(c) || is_newline_char(c))
1953 * Jump to a marked position.
1955 start_mca(A_GOMARK, "goto mark: ", (void*)NULL, 0);
1957 if (is_erase_char(c) || is_newline_char(c))
1965 * Write part of the input to a pipe to a shell command.
1970 start_mca(A_PIPE, "|mark: ", (void*)NULL, 0);
1972 if (is_erase_char(c))
1974 if (is_newline_char(c))
1979 start_mca(A_PIPE, "!", ml_shell, 0);
1984 error("Command not available", NULL_PARG);
1989 start_mca(action, "Brackets: ", (void*)NULL, 0);
1998 shift_count = number;
2000 number = (shift_count > 0) ?
2001 shift_count : sc_width / 2;
2002 if (number > hshift)
2013 shift_count = number;
2015 number = (shift_count > 0) ?
2016 shift_count : sc_width / 2;
2023 * Shift view left to margin.
2031 * Shift view right to view rightmost char on screen.
2039 * The command is incomplete (more chars are needed).
2040 * Display the current char, so the user knows
2041 * what's going on, and get another character.
2043 if (mca != A_PREFIX)
2046 start_mca(A_PREFIX, " ", (void*)NULL,