2 * Copyright (C) 1984-2020 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 #if SHELL_ESCAPE || PIPEC
52 extern void *ml_shell;
56 extern char *editproto;
58 extern int screen_trashed; /* The screen has been overwritten */
59 extern int shift_count;
61 extern int forw_prompt;
62 #if MSDOS_COMPILER==WIN32C
67 static char *shellcmd = NULL; /* For holding last shell command for "!!" */
69 static int mca; /* The multicharacter command (action) */
70 static int search_type; /* The previous type of search */
71 static LINENUM number; /* The number typed by the user */
72 static long fraction; /* The fractional part of the number */
73 static struct loption *curropt;
76 static int optgetname;
77 static POSITION bottompos;
78 static int save_hshift;
79 static int save_bs_mode;
84 /* Stack of ungotten chars (via ungetcc) */
86 struct ungot *ug_next;
89 static struct ungot* ungot = NULL;
91 static void multi_search LESSPARAMS((char *pattern, int n, int silent));
94 * Move the cursor to start of prompt line before executing a command.
95 * This looks nicer if the command takes a long time before
96 * updating the screen.
107 * Indicate we are reading a multi-character command.
114 deinit_mouse(); /* we don't want mouse events while entering a cmd */
120 * Indicate we are not reading a multi-character command.
123 clear_mca(VOID_PARAM)
132 * Set up the display to start a new multi-character command.
135 start_mca(action, prompt, mlist, cmdflags)
137 constant char *prompt;
143 set_mlist(mlist, cmdflags);
149 return (mca != 0 && mca != A_PREFIX);
153 * Set up the display to start a new search command.
156 mca_search(VOID_PARAM)
159 if (search_type & SRCH_FILTER)
163 if (search_type & SRCH_FORW)
168 if (search_type & SRCH_NO_MATCH)
169 cmd_putstr("Non-match ");
170 if (search_type & SRCH_FIRST_FILE)
171 cmd_putstr("First-file ");
172 if (search_type & SRCH_PAST_EOF)
173 cmd_putstr("EOF-ignore ");
174 if (search_type & SRCH_NO_MOVE)
175 cmd_putstr("Keep-pos ");
176 if (search_type & SRCH_NO_REGEX)
177 cmd_putstr("Regex-off ");
180 if (search_type & SRCH_FILTER)
184 if (search_type & SRCH_FORW)
189 set_mlist(ml_search, 0);
193 * Set up the display to start a new toggle-option command.
196 mca_opt_toggle(VOID_PARAM)
202 no_prompt = (optflag & OPT_NO_PROMPT);
203 flag = (optflag & ~OPT_NO_PROMPT);
204 dash = (flag == OPT_NO_TOGGLE) ? "_" : "-";
206 set_mca(A_OPT_TOGGLE);
226 * Execute a multicharacter command.
240 multi_search(cbuf, (int) number, 0);
244 search_type ^= SRCH_NO_MATCH;
245 set_filter_pattern(cbuf, search_type);
250 * Skip leading spaces or + signs in the string.
252 while (*cbuf == '+' || *cbuf == ' ')
254 if (every_first_cmd != NULL)
255 free(every_first_cmd);
257 every_first_cmd = NULL;
259 every_first_cmd = save(cbuf);
262 toggle_option(curropt, opt_lower, cbuf, optflag);
266 match_brac(cbuf[0], cbuf[1], 1, (int) number);
269 match_brac(cbuf[1], cbuf[0], 0, (int) number);
277 /* If tag structure is loaded then clean it up. */
285 * !! just uses whatever is in shellcmd.
286 * Otherwise, copy cmdbuf to shellcmd,
287 * expanding any special characters ("%" or "#").
291 if (shellcmd != NULL)
293 shellcmd = fexpand(cbuf);
298 if (shellcmd == NULL)
299 lsystem("", "!done");
301 lsystem(shellcmd, "!done");
308 (void) pipe_mark(pipec, cbuf);
309 error("|done", NULL_PARG);
316 * Is a character an erase or kill char?
322 return (c == erase_char || c == erase2_char || c == kill_char);
326 * Is a character a carriage return or newline?
332 return (c == '\n' || c == '\r');
336 * Handle the first char of an option (after the initial dash).
339 mca_opt_first_char(c)
342 int flag = (optflag & ~OPT_NO_PROMPT);
343 if (flag == OPT_NO_TOGGLE)
348 /* "__" = long option name. */
359 optflag = (flag == OPT_UNSET) ?
360 OPT_TOGGLE : OPT_UNSET;
365 optflag = (flag == OPT_SET) ?
366 OPT_TOGGLE : OPT_SET;
370 optflag ^= OPT_NO_PROMPT;
374 /* "--" = long option name. */
380 /* Char was not handled here. */
385 * Add a char to a long option name.
386 * See if we've got a match for an option name yet.
387 * If so, display the complete name and stop
388 * accepting chars until user hits RETURN.
391 mca_opt_nonfirst_char(c)
401 * Already have a match for the name.
402 * Don't accept anything but erase/kill.
404 if (is_erase_char(c))
409 * Add char to cmd buffer and try to match
412 if (cmd_char(c) == CC_QUIT)
415 opt_lower = ASCII_IS_LOWER(p[0]);
417 curropt = findopt_name(&p, &oname, &err);
422 * Remember the option and
423 * display the full option name.
427 for (p = oname; *p != '\0'; p++)
430 if (!opt_lower && ASCII_IS_LOWER(c))
431 c = ASCII_TO_UPPER(c);
432 if (cmd_char(c) != CC_OK)
435 } else if (err != OPT_AMBIG)
443 * Handle a char of an option toggle command.
452 * This may be a short option (single char),
453 * or one char of a long option name,
454 * or one char of the option parameter.
456 if (curropt == NULL && len_cmdbuf() == 0)
458 int ret = mca_opt_first_char(c);
464 /* We're getting a long option name. */
465 if (!is_newline_char(c))
466 return (mca_opt_nonfirst_char(c));
469 parg.p_string = get_cmdbuf();
470 error("There is no --%s option", &parg);
477 if (is_erase_char(c))
480 /* We're getting the option parameter. */
482 curropt = findopt(c);
485 parg.p_string = propt(c);
486 error("There is no %s option", &parg);
489 opt_lower = ASCII_IS_LOWER(c);
492 * If the option which was entered does not take a
493 * parameter, toggle the option immediately,
494 * so user doesn't have to hit RETURN.
496 if ((optflag & ~OPT_NO_PROMPT) != OPT_TOGGLE ||
497 !opt_has_param(curropt))
499 toggle_option(curropt, opt_lower, "", optflag);
503 * Display a prompt appropriate for the option parameter.
505 start_mca(A_OPT_TOGGLE, opt_prompt(curropt), (void*)NULL, 0);
510 * Handle a char of a search command.
519 * Certain characters as the first char of
520 * the pattern have special meaning:
521 * ! Toggle the NO_MATCH flag
522 * * Toggle the PAST_EOF flag
523 * @ Toggle the FIRST_FILE flag
525 if (len_cmdbuf() > 0)
530 case CONTROL('E'): /* ignore END of file */
533 flag = SRCH_PAST_EOF;
535 case CONTROL('F'): /* FIRST file */
538 flag = SRCH_FIRST_FILE;
540 case CONTROL('K'): /* KEEP position */
544 case CONTROL('R'): /* Don't use REGULAR EXPRESSIONS */
545 flag = SRCH_NO_REGEX;
547 case CONTROL('N'): /* NOT match */
549 flag = SRCH_NO_MATCH;
563 * Handle a character of a multi-character command.
575 * We're not in a multicharacter command.
581 * In the prefix of a command.
582 * This not considered a multichar command
583 * (even tho it uses cmdbuf, etc.).
584 * It is handled in the commands() switch.
590 * Entering digits of a number.
591 * Terminated by a non-digit.
593 if (!((c >= '0' && c <= '9') || c == '.') &&
594 editchar(c, EC_PEEK|EC_NOHISTORY|EC_NOCOMPLETE|EC_NORIGHTLEFT) == A_INVALID)
597 * Not part of the number.
598 * End the number and treat this char
599 * as a normal command character.
601 number = cmd_int(&fraction);
609 ret = mca_opt_char(c);
617 ret = mca_search_char(c);
623 /* Other multicharacter command. */
628 * The multichar command is terminated by a newline.
630 if (is_newline_char(c))
633 * Execute the command.
640 * Append the char to the command buffer.
642 if (cmd_char(c) == CC_QUIT)
644 * Abort the multi-char command.
648 if ((mca == A_F_BRACKET || mca == A_B_BRACKET) && len_cmdbuf() >= 2)
651 * Special case for the bracket-matching commands.
652 * Execute the command after getting exactly two
653 * characters from the user.
660 * Need another character.
666 * Discard any buffered file data.
669 clear_buffers(VOID_PARAM)
671 if (!(ch_getflags() & CH_CANSEEK))
681 * Make sure the screen is displayed.
684 make_display(VOID_PARAM)
687 * If nothing is displayed yet, display starting from initial_scrpos.
691 if (initial_scrpos.pos == NULL_POSITION)
693 * {{ Maybe this should be:
694 * jump_loc(ch_zero(), jump_sline);
695 * but this behavior seems rather unexpected
696 * on the first screen. }}
698 jump_loc(ch_zero(), 1);
700 jump_loc(initial_scrpos.pos, initial_scrpos.ln);
701 } else if (screen_trashed)
703 int save_top_scroll = top_scroll;
704 int save_ignore_eoi = ignore_eoi;
707 if (screen_trashed == 2)
709 /* Special case used by ignore_eoi: re-open the input file
710 * and jump to the end of the file. */
715 top_scroll = save_top_scroll;
716 ignore_eoi = save_ignore_eoi;
721 * Display the appropriate prompt.
728 if (ungot != NULL && ungot->ug_char != CHAR_END_COMMAND)
731 * No prompt necessary if commands are from
732 * ungotten chars rather than from the user.
738 * Make sure the screen is displayed.
741 bottompos = position(BOTTOM_PLUS_ONE);
744 * If we've hit EOF on the last file and the -E flag is set, quit.
746 if (get_quit_at_eof() == OPT_ONPLUS &&
747 eof_displayed() && !(ch_getflags() & CH_HELPFILE) &&
748 next_ifile(curr_ifile) == NULL_IFILE)
752 * If the entire file is displayed and the -F flag is set, quit.
754 if (quit_if_one_screen &&
755 entire_file_displayed() && !(ch_getflags() & CH_HELPFILE) &&
756 next_ifile(curr_ifile) == NULL_IFILE)
759 #if MSDOS_COMPILER==WIN32C
761 * In Win32, display the file name in the window title.
763 if (!(ch_getflags() & CH_HELPFILE))
765 WCHAR w[MAX_PATH+16];
766 p = pr_expand("Less?f - %f.", 0);
767 MultiByteToWideChar(CP_ACP, 0, p, -1, w, sizeof(w)/sizeof(*w));
773 * Select the proper prompt and display it.
776 * If the previous action was a forward movement,
777 * don't clear the bottom line of the display;
778 * just print the prompt since the forward movement guarantees
779 * that we're in the right position to display the prompt.
780 * Clearing the line could cause a problem: for example, if the last
781 * line displayed ended at the right screen edge without a newline,
782 * then clearing would clear the last displayed line rather than
792 if (p == NULL || *p == '\0')
796 #if MSDOS_COMPILER==WIN32C
799 MultiByteToWideChar(CP_ACP, 0, p, -1, w, sizeof(w)/sizeof(*w));
800 WideCharToMultiByte(utf_mode ? CP_UTF8 : GetConsoleOutputCP(),
801 0, w, -1, a, sizeof(a), NULL, NULL);
804 at_enter(AT_STANDOUT);
812 * Display the less version message.
815 dispversion(VOID_PARAM)
819 parg.p_string = version;
820 error("less %s", &parg);
824 * Return a character to complete a partial command, if possible.
827 getcc_end_command(VOID_PARAM)
832 /* We have a number but no command. Treat as #g. */
836 /* We have "/string" but no newline. Add the \n. */
839 /* Some other incomplete command. Let user complete it. */
845 * Get command character.
846 * The character normally comes from the keyboard,
847 * but may come from ungotten characters
848 * (characters previously given to ungetcc or ungetsc).
856 /* Normal case: no ungotten chars.
857 * Get char from the user. */
861 /* Ungotten chars available:
862 * Take the top of stack (most recent). */
863 struct ungot *ug = ungot;
868 if (c == CHAR_END_COMMAND)
869 c = getcc_end_command();
875 * Get a command character, but if we receive the orig sequence,
876 * convert it to the repl sequence.
879 getcc_repl(orig, repl, gr_getc, gr_ungetc)
882 LWCHAR (*gr_getc)(VOID_PARAM);
883 void (*gr_ungetc)(LWCHAR);
890 if (orig == NULL || orig[0] == '\0')
895 if (c != orig[ki] || ki >= sizeof(keys)-1)
897 /* This is not orig we have been receiving.
898 * If we have stashed chars in keys[],
899 * unget them and return the first one. */
901 (*gr_ungetc)(keys[ki--]);
904 if (orig[++ki] == '\0')
906 /* We've received the full orig sequence.
907 * Return the repl sequence. */
910 (*gr_ungetc)(repl[ki--]);
913 /* We've received a partial orig sequence (ki chars of it).
914 * Get next char and see if it continues to match orig. */
920 * Get command character.
925 /* Replace kent (keypad Enter) with a newline. */
926 return getcc_repl(kent, "\n", getccu, ungetcc);
930 * "Unget" a command character.
931 * The next getcc() will return this character.
937 struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot));
945 * Unget a whole string of command characters.
946 * The next sequence of getcc()'s will return this string.
954 for (p = s + strlen(s) - 1; p >= s; p--)
959 * Peek the next command character, without consuming it.
970 * Search for a pattern, possibly in multiple files.
971 * If SRCH_FIRST_FILE is set, begin searching at the first file.
972 * If SRCH_PAST_EOF is set, continue the search thru multiple files.
975 multi_search(pattern, n, silent)
985 save_ifile = save_curr_ifile();
987 if (search_type & SRCH_FIRST_FILE)
990 * Start at the first (or last) file
991 * in the command line list.
993 if (search_type & SRCH_FORW)
994 nomore = edit_first();
996 nomore = edit_last();
999 unsave_ifile(save_ifile);
1003 search_type &= ~SRCH_FIRST_FILE;
1008 n = search(search_type, pattern, n);
1010 * The SRCH_NO_MOVE flag doesn't "stick": it gets cleared
1011 * after being used once. This allows "n" to work after
1012 * using a /@@ search.
1014 search_type &= ~SRCH_NO_MOVE;
1020 unsave_ifile(save_ifile);
1026 * Some kind of error in the search.
1027 * Error message has been printed by search().
1031 if ((search_type & SRCH_PAST_EOF) == 0)
1033 * We didn't find a match, but we're
1034 * supposed to search only one file.
1038 * Move on to the next file.
1040 if (search_type & SRCH_FORW)
1041 nomore = edit_next(1);
1043 nomore = edit_prev(1);
1051 * Print an error message if we haven't already.
1053 if (n > 0 && !silent)
1054 error("Pattern not found", NULL_PARG);
1059 * Restore the file we were originally viewing.
1061 reedit_ifile(save_ifile);
1064 unsave_ifile(save_ifile);
1069 * Forward forever, or until a highlighted line appears.
1072 forw_loop(until_hilite)
1077 if (ch_getflags() & CH_HELPFILE)
1078 return (A_NOACTION);
1081 jump_forw_buffered();
1082 curr_len = ch_length();
1083 highest_hilite = until_hilite ? curr_len : NULL_POSITION;
1087 if (until_hilite && highest_hilite > curr_len)
1099 * This gets us back in "F mode" after processing
1100 * a non-abort signal (e.g. window-change).
1102 if (sigs && !ABORT_SIGS())
1103 return (until_hilite ? A_F_UNTIL_HILITE : A_F_FOREVER);
1105 return (A_NOACTION);
1109 * Main command processor.
1110 * Accept and execute commands until a quit command.
1113 commands(VOID_PARAM)
1119 int save_search_type;
1127 search_type = SRCH_FORW;
1128 wscroll = (sc_height + 1) / 2;
1129 newaction = A_NOACTION;
1139 * See if any signals need processing.
1145 quit(QUIT_SAVED_STATUS);
1149 * See if window size changed, for systems that don't
1150 * generate SIGWINCH.
1155 * Display prompt and accept a character.
1161 if (newaction == A_NOACTION)
1168 if (newaction != A_NOACTION)
1171 newaction = A_NOACTION;
1175 * If we are in a multicharacter command, call mca_char.
1176 * Otherwise we call fcmd_decode to determine the
1177 * action to be performed.
1180 switch (mca_char(c))
1184 * Need another character.
1190 * Command has been handled by mca_char.
1191 * Start clean with a prompt.
1196 * Not a multi-char command
1197 * (at least, not anymore).
1203 * Decode the command character and decide what to do.
1208 * We're in a multichar command.
1209 * Add the character to the command buffer
1210 * and display it on the screen.
1211 * If the user backspaces past the start
1212 * of the line, abort the command.
1214 if (cmd_char(c) == CC_QUIT || len_cmdbuf() == 0)
1216 cbuf = get_cmdbuf();
1220 * Don't use cmd_char if we're starting fresh
1221 * at the beginning of a command, because we
1222 * don't want to echo the command until we know
1223 * it is a multichar command. We also don't
1224 * want erase_char/kill_char to be treated
1225 * as line editing characters.
1232 action = fcmd_decode(cbuf, &extra);
1234 * If an "extra" string was returned,
1235 * process it as a string of command characters.
1241 * Clear the cmdbuf string.
1242 * (But not if we're in the prefix of a command,
1243 * because the partial command string is kept there.)
1245 if (action != A_PREFIX)
1252 * First digit of a number.
1254 start_mca(A_DIGIT, ":", (void*)NULL, CF_QUIT_ON_ERASE);
1259 * Forward one window (and set the window size).
1262 swindow = (int) number;
1266 * Forward one screen.
1269 number = get_swindow();
1272 set_attnpos(bottompos);
1273 forward((int) number, 0, 1);
1278 * Backward one window (and set the window size).
1281 swindow = (int) number;
1285 * Backward one screen.
1288 number = get_swindow();
1290 backward((int) number, 0, 1);
1295 * Forward N (default 1) line.
1300 if (show_attn == OPT_ONPLUS && number > 1)
1301 set_attnpos(bottompos);
1302 forward((int) number, 0, 0);
1307 * Backward N (default 1) line.
1312 backward((int) number, 0, 0);
1317 * Forward wheel_lines lines.
1320 forward(wheel_lines, 0, 0);
1325 * Backward wheel_lines lines.
1328 backward(wheel_lines, 0, 0);
1333 * Force forward N (default 1) line.
1338 if (show_attn == OPT_ONPLUS && number > 1)
1339 set_attnpos(bottompos);
1340 forward((int) number, 1, 0);
1345 * Force backward N (default 1) line.
1350 backward((int) number, 1, 0);
1355 * Force forward one screen.
1358 number = get_swindow();
1360 if (show_attn == OPT_ONPLUS)
1361 set_attnpos(bottompos);
1362 forward((int) number, 1, 0);
1367 * Forward forever, ignoring EOF.
1370 set_attnpos(bottompos);
1371 newaction = forw_loop(0);
1374 case A_F_UNTIL_HILITE:
1375 newaction = forw_loop(1);
1381 * (default same as last 'd' or 'u' command).
1384 wscroll = (int) number;
1386 if (show_attn == OPT_ONPLUS)
1387 set_attnpos(bottompos);
1388 forward(wscroll, 0, 0);
1394 * (default same as last 'd' or 'u' command).
1397 wscroll = (int) number;
1399 backward(wscroll, 0, 0);
1404 * Flush buffers, then repaint screen.
1405 * Don't flush the buffers on a pipe!
1419 * Go to line N, default beginning of file.
1429 * Go to a specified percentage into the file.
1436 if (number > 100 || (number == 100 && fraction != 0))
1442 jump_percent((int) number, fraction);
1447 * Go to line N, default end of file.
1458 * Go to line N, default last buffered byte.
1462 jump_forw_buffered();
1469 * Go to a specified byte position in the file.
1474 jump_line_loc((POSITION) number, jump_sline);
1479 * Print file name, etc.
1481 if (ch_getflags() & CH_HELPFILE)
1484 parg.p_string = eq_message();
1490 * Print version number, without the "@(#)".
1500 if (curr_ifile != NULL_IFILE &&
1501 ch_getflags() & CH_HELPFILE)
1504 * Quit while viewing the help file
1505 * just means return to viewing the
1508 hshift = save_hshift;
1509 bs_mode = save_bs_mode;
1510 if (edit_prev(1) == 0)
1519 * Define abbreviation for a commonly used sequence below.
1521 #define DO_SEARCH() \
1522 if (number <= 0) number = 1; \
1525 multi_search((char *)NULL, (int) number, 0);
1530 * Search forward for a pattern.
1531 * Get the first char of the pattern.
1533 search_type = SRCH_FORW;
1542 * Search backward for a pattern.
1543 * Get the first char of the pattern.
1545 search_type = SRCH_BACK;
1554 search_type = SRCH_FORW | SRCH_FILTER;
1559 error("Command not available", NULL_PARG);
1563 case A_AGAIN_SEARCH:
1565 * Repeat previous search.
1570 case A_T_AGAIN_SEARCH:
1572 * Repeat previous search, multiple files.
1574 search_type |= SRCH_PAST_EOF;
1578 case A_REVERSE_SEARCH:
1580 * Repeat previous search, in reverse direction.
1582 save_search_type = search_type;
1583 search_type = SRCH_REVERSE(search_type);
1585 search_type = save_search_type;
1588 case A_T_REVERSE_SEARCH:
1590 * Repeat previous search,
1591 * multiple files in reverse direction.
1593 save_search_type = search_type;
1594 search_type = SRCH_REVERSE(search_type);
1595 search_type |= SRCH_PAST_EOF;
1597 search_type = save_search_type;
1602 * Clear search string highlighting.
1611 if (ch_getflags() & CH_HELPFILE)
1614 save_hshift = hshift;
1616 save_bs_mode = bs_mode;
1617 bs_mode = BS_SPECIAL;
1618 (void) edit(FAKE_HELPFILE);
1623 * Edit a new file. Get the filename.
1628 start_mca(A_EXAMINE, "Examine: ", ml_examine, 0);
1633 error("Command not available", NULL_PARG);
1638 * Invoke an editor on the input file.
1643 if (ch_getflags() & CH_HELPFILE)
1645 if (strcmp(get_filename(curr_ifile), "-") == 0)
1647 error("Cannot edit standard input", NULL_PARG);
1650 if (get_altfilename(curr_ifile) != NULL)
1652 error("WARNING: This file was viewed via LESSOPEN",
1655 start_mca(A_SHELL, "!", ml_shell, 0);
1657 * Expand the editor prototype string
1658 * and pass it to the system to execute.
1659 * (Make sure the screen is displayed so the
1660 * expansion of "+%lm" works.)
1664 lsystem(pr_expand(editproto, 0), (char*)NULL);
1668 error("Command not available", NULL_PARG);
1673 * Examine next file.
1678 error("No next file", NULL_PARG);
1684 if (edit_next((int) number))
1686 if (get_quit_at_eof() && eof_displayed() &&
1687 !(ch_getflags() & CH_HELPFILE))
1689 parg.p_string = (number > 1) ? "(N-th) " : "";
1690 error("No %snext file", &parg);
1696 * Examine previous file.
1701 error("No previous file", NULL_PARG);
1707 if (edit_prev((int) number))
1709 parg.p_string = (number > 1) ? "(N-th) " : "";
1710 error("No %sprevious file", &parg);
1716 * Jump to the next tag in the current tag list.
1721 tagfile = nexttag((int) number);
1722 if (tagfile == NULL)
1724 error("No next tag", NULL_PARG);
1728 if (edit(tagfile) == 0)
1730 POSITION pos = tagsearch();
1731 if (pos != NULL_POSITION)
1732 jump_loc(pos, jump_sline);
1735 error("Command not available", NULL_PARG);
1741 * Jump to the previous tag in the current tag list.
1746 tagfile = prevtag((int) number);
1747 if (tagfile == NULL)
1749 error("No previous tag", NULL_PARG);
1753 if (edit(tagfile) == 0)
1755 POSITION pos = tagsearch();
1756 if (pos != NULL_POSITION)
1757 jump_loc(pos, jump_sline);
1760 error("Command not available", NULL_PARG);
1766 * Examine a particular file.
1770 if (edit_index((int) number))
1771 error("No such file", NULL_PARG);
1776 * Remove a file from the input file list.
1778 if (ch_getflags() & CH_HELPFILE)
1780 old_ifile = curr_ifile;
1781 new_ifile = getoff_ifile(curr_ifile);
1782 if (new_ifile == NULL_IFILE)
1787 if (edit_ifile(new_ifile) != 0)
1789 reedit_ifile(old_ifile);
1792 del_ifile(old_ifile);
1797 * Change the setting of an option.
1799 optflag = OPT_TOGGLE;
1803 cbuf = opt_toggle_disallowed(c);
1806 error(cbuf, NULL_PARG);
1813 * Report the setting of an option.
1815 optflag = OPT_NO_TOGGLE;
1823 * Set an initial command for new files.
1825 start_mca(A_FIRSTCMD, "+", (void*)NULL, 0);
1836 start_mca(A_SHELL, "!", ml_shell, 0);
1841 error("Command not available", NULL_PARG);
1849 if (ch_getflags() & CH_HELPFILE)
1851 start_mca(A_SETMARK, "set mark: ", (void*)NULL, 0);
1853 if (is_erase_char(c) || is_newline_char(c))
1855 setmark(c, action == A_SETMARKBOT ? BOTTOM : TOP);
1863 start_mca(A_CLRMARK, "clear mark: ", (void*)NULL, 0);
1865 if (is_erase_char(c) || is_newline_char(c))
1873 * Jump to a marked position.
1875 start_mca(A_GOMARK, "goto mark: ", (void*)NULL, 0);
1877 if (is_erase_char(c) || is_newline_char(c))
1885 * Write part of the input to a pipe to a shell command.
1890 start_mca(A_PIPE, "|mark: ", (void*)NULL, 0);
1892 if (is_erase_char(c))
1894 if (is_newline_char(c))
1899 start_mca(A_PIPE, "!", ml_shell, 0);
1904 error("Command not available", NULL_PARG);
1909 start_mca(action, "Brackets: ", (void*)NULL, 0);
1918 shift_count = number;
1920 number = (shift_count > 0) ?
1921 shift_count : sc_width / 2;
1922 if (number > hshift)
1933 shift_count = number;
1935 number = (shift_count > 0) ?
1936 shift_count : sc_width / 2;
1943 * Shift view left to margin.
1951 * Shift view right to view rightmost char on screen.
1959 * The command is incomplete (more chars are needed).
1960 * Display the current char, so the user knows
1961 * what's going on, and get another character.
1963 if (mca != A_PREFIX)
1966 start_mca(A_PREFIX, " ", (void*)NULL,