3 * Copyright (C) 1984-2020 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 #if MSDOS_COMPILER==WIN32C
69 static char *shellcmd = NULL; /* For holding last shell command for "!!" */
71 static int mca; /* The multicharacter command (action) */
72 static int search_type; /* The previous type of search */
73 static LINENUM number; /* The number typed by the user */
74 static long fraction; /* The fractional part of the number */
75 static struct loption *curropt;
78 static int optgetname;
79 static POSITION bottompos;
80 static int save_hshift;
81 static int save_bs_mode;
86 /* Stack of ungotten chars (via ungetcc) */
88 struct ungot *ug_next;
91 static struct ungot* ungot = NULL;
93 static void multi_search LESSPARAMS((char *pattern, int n, int silent));
96 * Move the cursor to start of prompt line before executing a command.
97 * This looks nicer if the command takes a long time before
98 * updating the screen.
109 * Indicate we are reading a multi-character command.
116 deinit_mouse(); /* we don't want mouse events while entering a cmd */
122 * Indicate we are not reading a multi-character command.
125 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_search(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 ");
182 if (search_type & SRCH_FILTER)
186 if (search_type & SRCH_FORW)
191 set_mlist(ml_search, 0);
195 * Set up the display to start a new toggle-option command.
198 mca_opt_toggle(VOID_PARAM)
204 no_prompt = (optflag & OPT_NO_PROMPT);
205 flag = (optflag & ~OPT_NO_PROMPT);
206 dash = (flag == OPT_NO_TOGGLE) ? "_" : "-";
208 set_mca(A_OPT_TOGGLE);
228 * Execute a multicharacter command.
242 multi_search(cbuf, (int) number, 0);
246 search_type ^= SRCH_NO_MATCH;
247 set_filter_pattern(cbuf, search_type);
252 * Skip leading spaces or + signs in the string.
254 while (*cbuf == '+' || *cbuf == ' ')
256 if (every_first_cmd != NULL)
257 free(every_first_cmd);
259 every_first_cmd = NULL;
261 every_first_cmd = save(cbuf);
264 toggle_option(curropt, opt_lower, cbuf, optflag);
268 match_brac(cbuf[0], cbuf[1], 1, (int) number);
271 match_brac(cbuf[1], cbuf[0], 0, (int) number);
279 /* If tag structure is loaded then clean it up. */
287 * !! just uses whatever is in shellcmd.
288 * Otherwise, copy cmdbuf to shellcmd,
289 * expanding any special characters ("%" or "#").
293 if (shellcmd != NULL)
295 shellcmd = fexpand(cbuf);
300 if (shellcmd == NULL)
301 lsystem("", "!done");
303 lsystem(shellcmd, "!done");
310 (void) pipe_mark(pipec, cbuf);
311 error("|done", NULL_PARG);
318 * Is a character an erase or kill char?
324 return (c == erase_char || c == erase2_char || c == kill_char);
328 * Is a character a carriage return or newline?
334 return (c == '\n' || c == '\r');
338 * Handle the first char of an option (after the initial dash).
341 mca_opt_first_char(c)
344 int flag = (optflag & ~OPT_NO_PROMPT);
345 if (flag == OPT_NO_TOGGLE)
350 /* "__" = long option name. */
361 optflag = (flag == OPT_UNSET) ?
362 OPT_TOGGLE : OPT_UNSET;
367 optflag = (flag == OPT_SET) ?
368 OPT_TOGGLE : OPT_SET;
372 optflag ^= OPT_NO_PROMPT;
376 /* "--" = long option name. */
382 /* Char was not handled here. */
387 * Add a char to a long option name.
388 * See if we've got a match for an option name yet.
389 * If so, display the complete name and stop
390 * accepting chars until user hits RETURN.
393 mca_opt_nonfirst_char(c)
403 * Already have a match for the name.
404 * Don't accept anything but erase/kill.
406 if (is_erase_char(c))
411 * Add char to cmd buffer and try to match
414 if (cmd_char(c) == CC_QUIT)
417 opt_lower = ASCII_IS_LOWER(p[0]);
419 curropt = findopt_name(&p, &oname, &err);
424 * Remember the option and
425 * display the full option name.
429 for (p = oname; *p != '\0'; p++)
432 if (!opt_lower && ASCII_IS_LOWER(c))
433 c = ASCII_TO_UPPER(c);
434 if (cmd_char(c) != CC_OK)
437 } else if (err != OPT_AMBIG)
445 * Handle a char of an option toggle command.
454 * This may be a short option (single char),
455 * or one char of a long option name,
456 * or one char of the option parameter.
458 if (curropt == NULL && len_cmdbuf() == 0)
460 int ret = mca_opt_first_char(c);
466 /* We're getting a long option name. */
467 if (!is_newline_char(c))
468 return (mca_opt_nonfirst_char(c));
471 parg.p_string = get_cmdbuf();
472 error("There is no --%s option", &parg);
479 if (is_erase_char(c))
482 /* We're getting the option parameter. */
484 curropt = findopt(c);
487 parg.p_string = propt(c);
488 error("There is no %s option", &parg);
491 opt_lower = ASCII_IS_LOWER(c);
494 * If the option which was entered does not take a
495 * parameter, toggle the option immediately,
496 * so user doesn't have to hit RETURN.
498 if ((optflag & ~OPT_NO_PROMPT) != OPT_TOGGLE ||
499 !opt_has_param(curropt))
501 toggle_option(curropt, opt_lower, "", optflag);
505 * Display a prompt appropriate for the option parameter.
507 start_mca(A_OPT_TOGGLE, opt_prompt(curropt), (void*)NULL, 0);
512 * Handle a char of a search command.
521 * Certain characters as the first char of
522 * the pattern have special meaning:
523 * ! Toggle the NO_MATCH flag
524 * * Toggle the PAST_EOF flag
525 * @ Toggle the FIRST_FILE flag
527 if (len_cmdbuf() > 0)
535 case CONTROL('E'): /* ignore END of file */
537 flag = SRCH_PAST_EOF;
542 case CONTROL('F'): /* FIRST file */
544 flag = SRCH_FIRST_FILE;
546 case CONTROL('K'): /* KEEP position */
550 case CONTROL('R'): /* Don't use REGULAR EXPRESSIONS */
551 flag = SRCH_NO_REGEX;
553 case CONTROL('N'): /* NOT match */
555 flag = SRCH_NO_MATCH;
569 * Handle a character of a multi-character command.
581 * We're not in a multicharacter command.
587 * In the prefix of a command.
588 * This not considered a multichar command
589 * (even tho it uses cmdbuf, etc.).
590 * It is handled in the commands() switch.
596 * Entering digits of a number.
597 * Terminated by a non-digit.
599 if (!((c >= '0' && c <= '9') || c == '.') &&
600 editchar(c, EC_PEEK|EC_NOHISTORY|EC_NOCOMPLETE|EC_NORIGHTLEFT) == A_INVALID)
603 * Not part of the number.
604 * End the number and treat this char
605 * as a normal command character.
607 number = cmd_int(&fraction);
615 ret = mca_opt_char(c);
623 ret = mca_search_char(c);
629 /* Other multicharacter command. */
634 * The multichar command is terminated by a newline.
636 if (is_newline_char(c))
639 * Execute the command.
646 * Append the char to the command buffer.
648 if (cmd_char(c) == CC_QUIT)
650 * Abort the multi-char command.
654 if ((mca == A_F_BRACKET || mca == A_B_BRACKET) && len_cmdbuf() >= 2)
657 * Special case for the bracket-matching commands.
658 * Execute the command after getting exactly two
659 * characters from the user.
666 * Need another character.
672 * Discard any buffered file data.
675 clear_buffers(VOID_PARAM)
677 if (!(ch_getflags() & CH_CANSEEK))
687 * Make sure the screen is displayed.
690 make_display(VOID_PARAM)
693 * If nothing is displayed yet, display starting from initial_scrpos.
697 if (initial_scrpos.pos == NULL_POSITION)
699 * {{ Maybe this should be:
700 * jump_loc(ch_zero(), jump_sline);
701 * but this behavior seems rather unexpected
702 * on the first screen. }}
704 jump_loc(ch_zero(), 1);
706 jump_loc(initial_scrpos.pos, initial_scrpos.ln);
707 } else if (screen_trashed)
709 int save_top_scroll = top_scroll;
710 int save_ignore_eoi = ignore_eoi;
713 if (screen_trashed == 2)
715 /* Special case used by ignore_eoi: re-open the input file
716 * and jump to the end of the file. */
721 top_scroll = save_top_scroll;
722 ignore_eoi = save_ignore_eoi;
727 * Display the appropriate prompt.
734 if (ungot != NULL && ungot->ug_char != CHAR_END_COMMAND)
737 * No prompt necessary if commands are from
738 * ungotten chars rather than from the user.
744 * Make sure the screen is displayed.
747 bottompos = position(BOTTOM_PLUS_ONE);
750 * If we've hit EOF on the last file and the -E flag is set, quit.
752 if (get_quit_at_eof() == OPT_ONPLUS &&
753 eof_displayed() && !(ch_getflags() & CH_HELPFILE) &&
754 next_ifile(curr_ifile) == NULL_IFILE)
758 * If the entire file is displayed and the -F flag is set, quit.
760 if (quit_if_one_screen &&
761 entire_file_displayed() && !(ch_getflags() & CH_HELPFILE) &&
762 next_ifile(curr_ifile) == NULL_IFILE)
765 #if MSDOS_COMPILER==WIN32C
767 * In Win32, display the file name in the window title.
769 if (!(ch_getflags() & CH_HELPFILE))
771 WCHAR w[MAX_PATH+16];
772 p = pr_expand("Less?f - %f.", 0);
773 MultiByteToWideChar(CP_ACP, 0, p, -1, w, sizeof(w)/sizeof(*w));
779 * Select the proper prompt and display it.
782 * If the previous action was a forward movement,
783 * don't clear the bottom line of the display;
784 * just print the prompt since the forward movement guarantees
785 * that we're in the right position to display the prompt.
786 * Clearing the line could cause a problem: for example, if the last
787 * line displayed ended at the right screen edge without a newline,
788 * then clearing would clear the last displayed line rather than
798 if (p == NULL || *p == '\0')
802 #if MSDOS_COMPILER==WIN32C
805 MultiByteToWideChar(CP_ACP, 0, p, -1, w, sizeof(w)/sizeof(*w));
806 WideCharToMultiByte(utf_mode ? CP_UTF8 : GetConsoleOutputCP(),
807 0, w, -1, a, sizeof(a), NULL, NULL);
810 at_enter(AT_STANDOUT);
818 * Display the less version message.
821 dispversion(VOID_PARAM)
825 parg.p_string = version;
826 error("less %s", &parg);
830 * Return a character to complete a partial command, if possible.
833 getcc_end_command(VOID_PARAM)
838 /* We have a number but no command. Treat as #g. */
842 /* We have "/string" but no newline. Add the \n. */
845 /* Some other incomplete command. Let user complete it. */
851 * Get command character.
852 * The character normally comes from the keyboard,
853 * but may come from ungotten characters
854 * (characters previously given to ungetcc or ungetsc).
862 /* Normal case: no ungotten chars.
863 * Get char from the user. */
867 /* Ungotten chars available:
868 * Take the top of stack (most recent). */
869 struct ungot *ug = ungot;
874 if (c == CHAR_END_COMMAND)
875 c = getcc_end_command();
881 * Get a command character, but if we receive the orig sequence,
882 * convert it to the repl sequence.
885 getcc_repl(orig, repl, gr_getc, gr_ungetc)
888 LWCHAR (*gr_getc)(VOID_PARAM);
889 void (*gr_ungetc)(LWCHAR);
896 if (orig == NULL || orig[0] == '\0')
901 if (c != orig[ki] || ki >= sizeof(keys)-1)
903 /* This is not orig we have been receiving.
904 * If we have stashed chars in keys[],
905 * unget them and return the first one. */
907 (*gr_ungetc)(keys[ki--]);
910 if (orig[++ki] == '\0')
912 /* We've received the full orig sequence.
913 * Return the repl sequence. */
916 (*gr_ungetc)(repl[ki--]);
919 /* We've received a partial orig sequence (ki chars of it).
920 * Get next char and see if it continues to match orig. */
926 * Get command character.
931 /* Replace kent (keypad Enter) with a newline. */
932 return getcc_repl(kent, "\n", getccu, ungetcc);
936 * "Unget" a command character.
937 * The next getcc() will return this character.
943 struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot));
951 * Unget a whole string of command characters.
952 * The next sequence of getcc()'s will return this string.
960 for (p = s + strlen(s) - 1; p >= s; p--)
965 * Peek the next command character, without consuming it.
976 * Search for a pattern, possibly in multiple files.
977 * If SRCH_FIRST_FILE is set, begin searching at the first file.
978 * If SRCH_PAST_EOF is set, continue the search thru multiple files.
981 multi_search(pattern, n, silent)
991 save_ifile = save_curr_ifile();
993 if (search_type & SRCH_FIRST_FILE)
996 * Start at the first (or last) file
997 * in the command line list.
999 if (search_type & SRCH_FORW)
1000 nomore = edit_first();
1002 nomore = edit_last();
1005 unsave_ifile(save_ifile);
1009 search_type &= ~SRCH_FIRST_FILE;
1014 n = search(search_type, pattern, n);
1016 * The SRCH_NO_MOVE flag doesn't "stick": it gets cleared
1017 * after being used once. This allows "n" to work after
1018 * using a /@@ search.
1020 search_type &= ~SRCH_NO_MOVE;
1026 unsave_ifile(save_ifile);
1032 * Some kind of error in the search.
1033 * Error message has been printed by search().
1037 if ((search_type & SRCH_PAST_EOF) == 0)
1039 * We didn't find a match, but we're
1040 * supposed to search only one file.
1044 * Move on to the next file.
1046 if (search_type & SRCH_FORW)
1047 nomore = edit_next(1);
1049 nomore = edit_prev(1);
1057 * Print an error message if we haven't already.
1059 if (n > 0 && !silent)
1060 error("Pattern not found", NULL_PARG);
1065 * Restore the file we were originally viewing.
1067 reedit_ifile(save_ifile);
1070 unsave_ifile(save_ifile);
1075 * Forward forever, or until a highlighted line appears.
1078 forw_loop(until_hilite)
1083 if (ch_getflags() & CH_HELPFILE)
1084 return (A_NOACTION);
1087 jump_forw_buffered();
1088 curr_len = ch_length();
1089 highest_hilite = until_hilite ? curr_len : NULL_POSITION;
1093 if (until_hilite && highest_hilite > curr_len)
1105 * This gets us back in "F mode" after processing
1106 * a non-abort signal (e.g. window-change).
1108 if (sigs && !ABORT_SIGS())
1109 return (until_hilite ? A_F_UNTIL_HILITE : A_F_FOREVER);
1111 return (A_NOACTION);
1115 * Main command processor.
1116 * Accept and execute commands until a quit command.
1119 commands(VOID_PARAM)
1125 int save_search_type;
1133 search_type = SRCH_FORW;
1134 wscroll = (sc_height + 1) / 2;
1135 newaction = A_NOACTION;
1145 * See if any signals need processing.
1151 quit(QUIT_SAVED_STATUS);
1155 * See if window size changed, for systems that don't
1156 * generate SIGWINCH.
1161 * Display prompt and accept a character.
1167 if (newaction == A_NOACTION)
1174 if (newaction != A_NOACTION)
1177 newaction = A_NOACTION;
1181 * If we are in a multicharacter command, call mca_char.
1182 * Otherwise we call fcmd_decode to determine the
1183 * action to be performed.
1186 switch (mca_char(c))
1190 * Need another character.
1196 * Command has been handled by mca_char.
1197 * Start clean with a prompt.
1202 * Not a multi-char command
1203 * (at least, not anymore).
1209 * Decode the command character and decide what to do.
1214 * We're in a multichar command.
1215 * Add the character to the command buffer
1216 * and display it on the screen.
1217 * If the user backspaces past the start
1218 * of the line, abort the command.
1220 if (cmd_char(c) == CC_QUIT || len_cmdbuf() == 0)
1222 cbuf = get_cmdbuf();
1226 * Don't use cmd_char if we're starting fresh
1227 * at the beginning of a command, because we
1228 * don't want to echo the command until we know
1229 * it is a multichar command. We also don't
1230 * want erase_char/kill_char to be treated
1231 * as line editing characters.
1238 action = fcmd_decode(cbuf, &extra);
1240 * If an "extra" string was returned,
1241 * process it as a string of command characters.
1247 * Clear the cmdbuf string.
1248 * (But not if we're in the prefix of a command,
1249 * because the partial command string is kept there.)
1251 if (action != A_PREFIX)
1258 * First digit of a number.
1260 start_mca(A_DIGIT, ":", (void*)NULL, CF_QUIT_ON_ERASE);
1265 * Forward one window (and set the window size).
1268 swindow = (int) number;
1272 * Forward one screen.
1275 number = get_swindow();
1278 set_attnpos(bottompos);
1279 forward((int) number, 0, 1);
1284 * Backward one window (and set the window size).
1287 swindow = (int) number;
1291 * Backward one screen.
1294 number = get_swindow();
1296 backward((int) number, 0, 1);
1301 * Forward N (default 1) line.
1306 if (show_attn == OPT_ONPLUS && number > 1)
1307 set_attnpos(bottompos);
1308 forward((int) number, 0, 0);
1313 * Backward N (default 1) line.
1318 backward((int) number, 0, 0);
1323 * Forward wheel_lines lines.
1326 forward(wheel_lines, 0, 0);
1331 * Backward wheel_lines lines.
1334 backward(wheel_lines, 0, 0);
1339 * Force forward N (default 1) line.
1344 if (show_attn == OPT_ONPLUS && number > 1)
1345 set_attnpos(bottompos);
1346 forward((int) number, 1, 0);
1351 * Force backward N (default 1) line.
1356 backward((int) number, 1, 0);
1361 * Force forward one screen.
1364 number = get_swindow();
1366 if (show_attn == OPT_ONPLUS)
1367 set_attnpos(bottompos);
1368 forward((int) number, 1, 0);
1373 * Forward forever, ignoring EOF.
1376 set_attnpos(bottompos);
1377 newaction = forw_loop(0);
1380 case A_F_UNTIL_HILITE:
1381 newaction = forw_loop(1);
1387 * (default same as last 'd' or 'u' command).
1390 wscroll = (int) number;
1392 if (show_attn == OPT_ONPLUS)
1393 set_attnpos(bottompos);
1394 forward(wscroll, 0, 0);
1400 * (default same as last 'd' or 'u' command).
1403 wscroll = (int) number;
1405 backward(wscroll, 0, 0);
1410 * Flush buffers, then repaint screen.
1411 * Don't flush the buffers on a pipe!
1425 * Go to line N, default beginning of file.
1435 * Go to a specified percentage into the file.
1442 if (number > 100 || (number == 100 && fraction != 0))
1448 jump_percent((int) number, fraction);
1453 * Go to line N, default end of file.
1464 * Go to line N, default last buffered byte.
1468 jump_forw_buffered();
1475 * Go to a specified byte position in the file.
1480 jump_line_loc((POSITION) number, jump_sline);
1485 * Print file name, etc.
1487 if (ch_getflags() & CH_HELPFILE)
1490 parg.p_string = eq_message();
1496 * Print version number, without the "@(#)".
1506 if (curr_ifile != NULL_IFILE &&
1507 ch_getflags() & CH_HELPFILE)
1510 * Quit while viewing the help file
1511 * just means return to viewing the
1514 hshift = save_hshift;
1515 bs_mode = save_bs_mode;
1516 if (edit_prev(1) == 0)
1525 * Define abbreviation for a commonly used sequence below.
1527 #define DO_SEARCH() \
1528 if (number <= 0) number = 1; \
1531 multi_search((char *)NULL, (int) number, 0);
1536 * Search forward for a pattern.
1537 * Get the first char of the pattern.
1539 search_type = SRCH_FORW;
1548 * Search backward for a pattern.
1549 * Get the first char of the pattern.
1551 search_type = SRCH_BACK;
1560 search_type = SRCH_FORW | SRCH_FILTER;
1565 error("Command not available", NULL_PARG);
1569 case A_AGAIN_SEARCH:
1571 * Repeat previous search.
1576 case A_T_AGAIN_SEARCH:
1578 * Repeat previous search, multiple files.
1580 search_type |= SRCH_PAST_EOF;
1584 case A_REVERSE_SEARCH:
1586 * Repeat previous search, in reverse direction.
1588 save_search_type = search_type;
1589 search_type = SRCH_REVERSE(search_type);
1591 search_type = save_search_type;
1594 case A_T_REVERSE_SEARCH:
1596 * Repeat previous search,
1597 * multiple files in reverse direction.
1599 save_search_type = search_type;
1600 search_type = SRCH_REVERSE(search_type);
1601 search_type |= SRCH_PAST_EOF;
1603 search_type = save_search_type;
1608 * Clear search string highlighting.
1617 if (ch_getflags() & CH_HELPFILE)
1620 save_hshift = hshift;
1622 save_bs_mode = bs_mode;
1623 bs_mode = BS_SPECIAL;
1624 (void) edit(FAKE_HELPFILE);
1629 * Edit a new file. Get the filename.
1634 start_mca(A_EXAMINE, "Examine: ", ml_examine, 0);
1639 error("Command not available", NULL_PARG);
1644 * Invoke an editor on the input file.
1649 if (ch_getflags() & CH_HELPFILE)
1651 if (strcmp(get_filename(curr_ifile), "-") == 0)
1653 error("Cannot edit standard input", NULL_PARG);
1656 if (get_altfilename(curr_ifile) != NULL)
1658 error("WARNING: This file was viewed via LESSOPEN",
1661 start_mca(A_SHELL, "!", ml_shell, 0);
1663 * Expand the editor prototype string
1664 * and pass it to the system to execute.
1665 * (Make sure the screen is displayed so the
1666 * expansion of "+%lm" works.)
1670 lsystem(pr_expand(editproto, 0), (char*)NULL);
1674 error("Command not available", NULL_PARG);
1679 * Examine next file.
1684 error("No next file", NULL_PARG);
1690 if (edit_next((int) number))
1692 if (get_quit_at_eof() && eof_displayed() &&
1693 !(ch_getflags() & CH_HELPFILE))
1695 parg.p_string = (number > 1) ? "(N-th) " : "";
1696 error("No %snext file", &parg);
1702 * Examine previous file.
1707 error("No previous file", NULL_PARG);
1713 if (edit_prev((int) number))
1715 parg.p_string = (number > 1) ? "(N-th) " : "";
1716 error("No %sprevious file", &parg);
1722 * Jump to the next tag in the current tag list.
1727 tagfile = nexttag((int) number);
1728 if (tagfile == NULL)
1730 error("No next tag", NULL_PARG);
1734 if (edit(tagfile) == 0)
1736 POSITION pos = tagsearch();
1737 if (pos != NULL_POSITION)
1738 jump_loc(pos, jump_sline);
1741 error("Command not available", NULL_PARG);
1747 * Jump to the previous tag in the current tag list.
1752 tagfile = prevtag((int) number);
1753 if (tagfile == NULL)
1755 error("No previous tag", NULL_PARG);
1759 if (edit(tagfile) == 0)
1761 POSITION pos = tagsearch();
1762 if (pos != NULL_POSITION)
1763 jump_loc(pos, jump_sline);
1766 error("Command not available", NULL_PARG);
1772 * Examine a particular file.
1776 if (edit_index((int) number))
1777 error("No such file", NULL_PARG);
1782 * Remove a file from the input file list.
1784 if (ch_getflags() & CH_HELPFILE)
1786 old_ifile = curr_ifile;
1787 new_ifile = getoff_ifile(curr_ifile);
1788 if (new_ifile == NULL_IFILE)
1793 if (edit_ifile(new_ifile) != 0)
1795 reedit_ifile(old_ifile);
1798 del_ifile(old_ifile);
1803 * Change the setting of an option.
1805 optflag = OPT_TOGGLE;
1809 cbuf = opt_toggle_disallowed(c);
1812 error(cbuf, NULL_PARG);
1819 * Report the setting of an option.
1821 optflag = OPT_NO_TOGGLE;
1829 * Set an initial command for new files.
1831 start_mca(A_FIRSTCMD, "+", (void*)NULL, 0);
1842 start_mca(A_SHELL, "!", ml_shell, 0);
1847 error("Command not available", NULL_PARG);
1855 if (ch_getflags() & CH_HELPFILE)
1857 start_mca(A_SETMARK, "set mark: ", (void*)NULL, 0);
1859 if (is_erase_char(c) || is_newline_char(c))
1861 setmark(c, action == A_SETMARKBOT ? BOTTOM : TOP);
1869 start_mca(A_CLRMARK, "clear mark: ", (void*)NULL, 0);
1871 if (is_erase_char(c) || is_newline_char(c))
1879 * Jump to a marked position.
1881 start_mca(A_GOMARK, "goto mark: ", (void*)NULL, 0);
1883 if (is_erase_char(c) || is_newline_char(c))
1891 * Write part of the input to a pipe to a shell command.
1896 start_mca(A_PIPE, "|mark: ", (void*)NULL, 0);
1898 if (is_erase_char(c))
1900 if (is_newline_char(c))
1905 start_mca(A_PIPE, "!", ml_shell, 0);
1910 error("Command not available", NULL_PARG);
1915 start_mca(action, "Brackets: ", (void*)NULL, 0);
1924 shift_count = number;
1926 number = (shift_count > 0) ?
1927 shift_count : sc_width / 2;
1928 if (number > hshift)
1939 shift_count = number;
1941 number = (shift_count > 0) ?
1942 shift_count : sc_width / 2;
1949 * Shift view left to margin.
1957 * Shift view right to view rightmost char on screen.
1965 * The command is incomplete (more chars are needed).
1966 * Display the current char, so the user knows
1967 * what's going on, and get another character.
1969 if (mca != A_PREFIX)
1972 start_mca(A_PREFIX, " ", (void*)NULL,