1*b36f9237Ssimonb /* $NetBSD: opttbl.c,v 1.6 2023/10/06 07:29:42 simonb Exp $ */
220006a0bStron
320006a0bStron /*
4838f5788Ssimonb * Copyright (C) 1984-2023 Mark Nudelman
520006a0bStron *
620006a0bStron * You may distribute under the terms of either the GNU General Public
720006a0bStron * License or the Less License, as specified in the README file.
820006a0bStron *
9ec18bca0Stron * For more information, see the README file.
1020006a0bStron */
1120006a0bStron
1220006a0bStron
1320006a0bStron /*
1420006a0bStron * The option table.
1520006a0bStron */
1620006a0bStron
1720006a0bStron #include "less.h"
1820006a0bStron #include "option.h"
1920006a0bStron
2020006a0bStron /*
2120006a0bStron * Variables controlled by command line options.
2220006a0bStron */
2320006a0bStron public int quiet; /* Should we suppress the audible bell? */
24838f5788Ssimonb public int no_vbell; /* Should we suppress the visual bell? */
2520006a0bStron public int how_search; /* Where should forward searches start? */
2620006a0bStron public int top_scroll; /* Repaint screen from top?
2720006a0bStron (alternative is scroll from bottom) */
2820006a0bStron public int pr_type; /* Type of prompt (short, medium, long) */
2920006a0bStron public int bs_mode; /* How to process backspaces */
3020006a0bStron public int know_dumb; /* Don't complain about dumb terminals */
3120006a0bStron public int quit_at_eof; /* Quit after hitting end of file twice */
3220006a0bStron public int quit_if_one_screen; /* Quit if EOF on first screen */
33824a88bbStron public int be_helpful; /* more(1) style -d */
3420006a0bStron public int squeeze; /* Squeeze multiple blank lines into one */
3520006a0bStron public int tabstop; /* Tab settings */
3620006a0bStron public int back_scroll; /* Repaint screen on backwards movement */
3720006a0bStron public int forw_scroll; /* Repaint screen on forward movement */
3820006a0bStron public int caseless; /* Do "caseless" searches */
3920006a0bStron public int linenums; /* Use line numbers */
4020006a0bStron public int autobuf; /* Automatically allocate buffers as needed */
4120006a0bStron public int bufspace; /* Max buffer space per file (K) */
4220006a0bStron public int ctldisp; /* Send control chars to screen untranslated */
4320006a0bStron public int force_open; /* Open the file even if not regular file */
4420006a0bStron public int swindow; /* Size of scrolling window */
4520006a0bStron public int jump_sline; /* Screen line of "jump target" */
4620006a0bStron public long jump_sline_fraction = -1;
4720006a0bStron public long shift_count_fraction = -1;
4820006a0bStron public int chopline; /* Truncate displayed lines at screen width */
49838f5788Ssimonb public int wordwrap; /* Wrap lines at space */
5020006a0bStron public int no_init; /* Disable sending ti/te termcap strings */
5120006a0bStron public int no_keypad; /* Disable sending ks/ke termcap strings */
5220006a0bStron public int twiddle; /* Show tildes after EOF */
5320006a0bStron public int show_attn; /* Hilite first unread line */
5420006a0bStron public int shift_count; /* Number of positions to shift horizontally */
5520006a0bStron public int status_col; /* Display a status column */
5620006a0bStron public int use_lessopen; /* Use the LESSOPEN filter */
5720006a0bStron public int quit_on_intr; /* Quit on interrupt */
5820006a0bStron public int follow_mode; /* F cmd Follows file desc or file name? */
5920006a0bStron public int oldbot; /* Old bottom of screen behavior {{REMOVE}} */
60ec18bca0Stron public int opt_use_backslash; /* Use backslash escaping in option parsing */
61838f5788Ssimonb public char rscroll_char; /* Char which marks chopped lines with -S */
62838f5788Ssimonb public int rscroll_attr; /* Attribute of rscroll_char */
63838f5788Ssimonb public int no_hist_dups; /* Remove dups from history list */
64838f5788Ssimonb public int mousecap; /* Allow mouse for scrolling */
65838f5788Ssimonb public int wheel_lines; /* Number of lines to scroll on mouse wheel scroll */
66838f5788Ssimonb public int perma_marks; /* Save marks in history file */
67838f5788Ssimonb public int linenum_width; /* Width of line numbers */
68838f5788Ssimonb public int status_col_width; /* Width of status column */
69838f5788Ssimonb public int incr_search; /* Incremental search */
70838f5788Ssimonb public int use_color; /* Use UI color */
71838f5788Ssimonb public int want_filesize; /* Scan to EOF if necessary to get file size */
72838f5788Ssimonb public int status_line; /* Highlight entire marked lines */
73838f5788Ssimonb public int header_lines; /* Freeze header lines at top of screen */
74838f5788Ssimonb public int header_cols; /* Freeze header columns at left of screen */
75838f5788Ssimonb public int nonum_headers; /* Don't give headers line numbers */
76838f5788Ssimonb public int nosearch_headers; /* Don't search in header lines or columns */
77838f5788Ssimonb public int redraw_on_quit; /* Redraw last screen after term deinit */
78838f5788Ssimonb public int def_search_type; /* */
79838f5788Ssimonb public int exit_F_on_close; /* Exit F command when input closes */
80838f5788Ssimonb public int modelines; /* Lines to read looking for modelines */
81838f5788Ssimonb public int show_preproc_error; /* Display msg when preproc exits with error */
82838f5788Ssimonb public int proc_backspace; /* Special handling of backspace */
83838f5788Ssimonb public int proc_tab; /* Special handling of tab */
84838f5788Ssimonb public int proc_return; /* Special handling of carriage return */
85838f5788Ssimonb public char intr_char = CONTROL('X'); /* Char to interrupt reads */
8620006a0bStron #if HILITE_SEARCH
8720006a0bStron public int hilite_search; /* Highlight matched search patterns? */
8820006a0bStron #endif
8920006a0bStron
9020006a0bStron public int less_is_more = 0; /* Make compatible with POSIX more */
9120006a0bStron
9220006a0bStron /*
9320006a0bStron * Long option names.
9420006a0bStron */
9520006a0bStron static struct optname a_optname = { "search-skip-screen", NULL };
9620006a0bStron static struct optname b_optname = { "buffers", NULL };
9720006a0bStron static struct optname B__optname = { "auto-buffers", NULL };
9820006a0bStron static struct optname c_optname = { "clear-screen", NULL };
9920006a0bStron static struct optname d_optname = { "dumb", NULL };
10020006a0bStron static struct optname D__optname = { "color", NULL };
10120006a0bStron static struct optname e_optname = { "quit-at-eof", NULL };
10220006a0bStron static struct optname f_optname = { "force", NULL };
10320006a0bStron static struct optname F__optname = { "quit-if-one-screen", NULL };
10420006a0bStron #if HILITE_SEARCH
10520006a0bStron static struct optname g_optname = { "hilite-search", NULL };
10620006a0bStron #endif
10720006a0bStron static struct optname h_optname = { "max-back-scroll", NULL };
10820006a0bStron static struct optname i_optname = { "ignore-case", NULL };
10920006a0bStron static struct optname j_optname = { "jump-target", NULL };
11020006a0bStron static struct optname J__optname = { "status-column", NULL };
11120006a0bStron #if USERFILE
11220006a0bStron static struct optname k_optname = { "lesskey-file", NULL };
113838f5788Ssimonb #if HAVE_LESSKEYSRC
114838f5788Ssimonb static struct optname ks_optname = { "lesskey-src", NULL };
115838f5788Ssimonb #endif /* HAVE_LESSKEYSRC */
11620006a0bStron #endif
11720006a0bStron static struct optname K__optname = { "quit-on-intr", NULL };
11820006a0bStron static struct optname L__optname = { "no-lessopen", NULL };
11920006a0bStron static struct optname m_optname = { "long-prompt", NULL };
12020006a0bStron static struct optname n_optname = { "line-numbers", NULL };
12120006a0bStron #if LOGFILE
12220006a0bStron static struct optname o_optname = { "log-file", NULL };
12320006a0bStron static struct optname O__optname = { "LOG-FILE", NULL };
12420006a0bStron #endif
12520006a0bStron static struct optname p_optname = { "pattern", NULL };
12620006a0bStron static struct optname P__optname = { "prompt", NULL };
12720006a0bStron static struct optname q2_optname = { "silent", NULL };
12820006a0bStron static struct optname q_optname = { "quiet", &q2_optname };
12920006a0bStron static struct optname r_optname = { "raw-control-chars", NULL };
13020006a0bStron static struct optname s_optname = { "squeeze-blank-lines", NULL };
13120006a0bStron static struct optname S__optname = { "chop-long-lines", NULL };
13220006a0bStron #if TAGS
13320006a0bStron static struct optname t_optname = { "tag", NULL };
13420006a0bStron static struct optname T__optname = { "tag-file", NULL };
13520006a0bStron #endif
13620006a0bStron static struct optname u_optname = { "underline-special", NULL };
13720006a0bStron static struct optname V__optname = { "version", NULL };
13820006a0bStron static struct optname w_optname = { "hilite-unread", NULL };
13920006a0bStron static struct optname x_optname = { "tabs", NULL };
14020006a0bStron static struct optname X__optname = { "no-init", NULL };
14120006a0bStron static struct optname y_optname = { "max-forw-scroll", NULL };
14220006a0bStron static struct optname z_optname = { "window", NULL };
14320006a0bStron static struct optname quote_optname = { "quotes", NULL };
14420006a0bStron static struct optname tilde_optname = { "tilde", NULL };
14520006a0bStron static struct optname query_optname = { "help", NULL };
14620006a0bStron static struct optname pound_optname = { "shift", NULL };
14720006a0bStron static struct optname keypad_optname = { "no-keypad", NULL };
14820006a0bStron static struct optname oldbot_optname = { "old-bot", NULL };
14920006a0bStron static struct optname follow_optname = { "follow-name", NULL };
150ec18bca0Stron static struct optname use_backslash_optname = { "use-backslash", NULL };
151838f5788Ssimonb static struct optname rscroll_optname = { "rscroll", NULL };
152838f5788Ssimonb static struct optname nohistdups_optname = { "no-histdups", NULL };
153838f5788Ssimonb static struct optname mousecap_optname = { "mouse", NULL };
154838f5788Ssimonb static struct optname wheel_lines_optname = { "wheel-lines", NULL };
155838f5788Ssimonb static struct optname perma_marks_optname = { "save-marks", NULL };
156838f5788Ssimonb static struct optname linenum_width_optname = { "line-num-width", NULL };
157838f5788Ssimonb static struct optname status_col_width_optname = { "status-col-width", NULL };
158838f5788Ssimonb static struct optname incr_search_optname = { "incsearch", NULL };
159838f5788Ssimonb static struct optname use_color_optname = { "use-color", NULL };
160838f5788Ssimonb static struct optname want_filesize_optname = { "file-size", NULL };
161838f5788Ssimonb static struct optname status_line_optname = { "status-line", NULL };
162838f5788Ssimonb static struct optname header_optname = { "header", NULL };
163838f5788Ssimonb static struct optname nonum_headers_optname = { "no-number-headers", NULL };
164838f5788Ssimonb static struct optname nosearch_headers_optname = { "no-search-headers", NULL };
165838f5788Ssimonb static struct optname redraw_on_quit_optname = { "redraw-on-quit", NULL };
166838f5788Ssimonb static struct optname search_type_optname = { "search-options", NULL };
167838f5788Ssimonb static struct optname exit_F_on_close_optname = { "exit-follow-on-close", NULL };
168838f5788Ssimonb static struct optname modelines_optname = { "modelines", NULL };
169838f5788Ssimonb static struct optname no_vbell_optname = { "no-vbell", NULL };
170838f5788Ssimonb static struct optname intr_optname = { "intr", NULL };
171838f5788Ssimonb static struct optname wordwrap_optname = { "wordwrap", NULL };
172838f5788Ssimonb static struct optname show_preproc_error_optname = { "show-preproc-errors", NULL };
173838f5788Ssimonb static struct optname proc_backspace_optname = { "proc-backspace", NULL };
174838f5788Ssimonb static struct optname proc_tab_optname = { "proc-tab", NULL };
175838f5788Ssimonb static struct optname proc_return_optname = { "proc-return", NULL };
176838f5788Ssimonb #if LESSTEST
177838f5788Ssimonb static struct optname ttyin_name_optname = { "tty", NULL };
178838f5788Ssimonb #endif /*LESSTEST*/
17920006a0bStron
18020006a0bStron
18120006a0bStron /*
18220006a0bStron * Table of all options and their semantics.
18320006a0bStron *
18420006a0bStron * For BOOL and TRIPLE options, odesc[0], odesc[1], odesc[2] are
18520006a0bStron * the description of the option when set to 0, 1 or 2, respectively.
18620006a0bStron * For NUMBER options, odesc[0] is the prompt to use when entering
18720006a0bStron * a new value, and odesc[1] is the description, which should contain
18820006a0bStron * one %d which is replaced by the value of the number.
18920006a0bStron * For STRING options, odesc[0] is the prompt to use when entering
19020006a0bStron * a new value, and odesc[1], if not NULL, is the set of characters
19120006a0bStron * that are valid in the string.
19220006a0bStron */
19320006a0bStron static struct loption option[] =
19420006a0bStron {
19520006a0bStron { 'a', &a_optname,
19620006a0bStron TRIPLE, OPT_ONPLUS, &how_search, NULL,
19720006a0bStron {
19820006a0bStron "Search includes displayed screen",
19920006a0bStron "Search skips displayed screen",
20020006a0bStron "Search includes all of displayed screen"
20120006a0bStron }
20220006a0bStron },
20320006a0bStron
20420006a0bStron { 'b', &b_optname,
20520006a0bStron NUMBER|INIT_HANDLER, 64, &bufspace, opt_b,
20620006a0bStron {
20720006a0bStron "Max buffer space per file (K): ",
20820006a0bStron "Max buffer space per file: %dK",
20920006a0bStron NULL
21020006a0bStron }
21120006a0bStron },
21220006a0bStron { 'B', &B__optname,
21320006a0bStron BOOL, OPT_ON, &autobuf, NULL,
21420006a0bStron {
21520006a0bStron "Don't automatically allocate buffers",
21620006a0bStron "Automatically allocate buffers when needed",
21720006a0bStron NULL
21820006a0bStron }
21920006a0bStron },
22020006a0bStron { 'c', &c_optname,
22120006a0bStron TRIPLE, OPT_OFF, &top_scroll, NULL,
22220006a0bStron {
22320006a0bStron "Repaint by scrolling from bottom of screen",
22420006a0bStron "Repaint by painting from top of screen",
22520006a0bStron "Repaint by painting from top of screen"
22620006a0bStron }
22720006a0bStron },
228824a88bbStron #if 1
22920006a0bStron { 'd', &d_optname,
230824a88bbStron BOOL, OPT_OFF, &be_helpful, NULL,
231824a88bbStron { "Be less helpful in prompts",
232824a88bbStron "Be helpful in prompts",
233824a88bbStron NULL }
234824a88bbStron },
235824a88bbStron #endif
236824a88bbStron { -1, &d_optname,
23720006a0bStron BOOL|NO_TOGGLE, OPT_OFF, &know_dumb, NULL,
23820006a0bStron {
23920006a0bStron "Assume intelligent terminal",
24020006a0bStron "Assume dumb terminal",
24120006a0bStron NULL
24220006a0bStron }
24320006a0bStron },
24420006a0bStron { 'D', &D__optname,
24520006a0bStron STRING|REPAINT|NO_QUERY, 0, NULL, opt_D,
24620006a0bStron {
24720006a0bStron "color desc: ",
248838f5788Ssimonb NULL,
24920006a0bStron NULL
25020006a0bStron }
25120006a0bStron },
25220006a0bStron { 'e', &e_optname,
25320006a0bStron TRIPLE, OPT_OFF, &quit_at_eof, NULL,
25420006a0bStron {
25520006a0bStron "Don't quit at end-of-file",
25620006a0bStron "Quit at end-of-file",
25720006a0bStron "Quit immediately at end-of-file"
25820006a0bStron }
25920006a0bStron },
26020006a0bStron { 'f', &f_optname,
26120006a0bStron BOOL, OPT_OFF, &force_open, NULL,
26220006a0bStron {
26320006a0bStron "Open only regular files",
26420006a0bStron "Open even non-regular files",
26520006a0bStron NULL
26620006a0bStron }
26720006a0bStron },
26820006a0bStron { 'F', &F__optname,
26920006a0bStron BOOL, OPT_OFF, &quit_if_one_screen, NULL,
27020006a0bStron {
27120006a0bStron "Don't quit if end-of-file on first screen",
27220006a0bStron "Quit if end-of-file on first screen",
27320006a0bStron NULL
27420006a0bStron }
27520006a0bStron },
27620006a0bStron #if HILITE_SEARCH
27720006a0bStron { 'g', &g_optname,
27820006a0bStron TRIPLE|HL_REPAINT, OPT_ONPLUS, &hilite_search, NULL,
27920006a0bStron {
28020006a0bStron "Don't highlight search matches",
28120006a0bStron "Highlight matches for previous search only",
28220006a0bStron "Highlight all matches for previous search pattern",
28320006a0bStron }
28420006a0bStron },
28520006a0bStron #endif
28620006a0bStron { 'h', &h_optname,
28720006a0bStron NUMBER, -1, &back_scroll, NULL,
28820006a0bStron {
28920006a0bStron "Backwards scroll limit: ",
29020006a0bStron "Backwards scroll limit is %d lines",
29120006a0bStron NULL
29220006a0bStron }
29320006a0bStron },
29420006a0bStron { 'i', &i_optname,
29520006a0bStron TRIPLE|HL_REPAINT, OPT_OFF, &caseless, opt_i,
29620006a0bStron {
29720006a0bStron "Case is significant in searches",
29820006a0bStron "Ignore case in searches",
29920006a0bStron "Ignore case in searches and in patterns"
30020006a0bStron }
30120006a0bStron },
30220006a0bStron { 'j', &j_optname,
30320006a0bStron STRING, 0, NULL, opt_j,
30420006a0bStron {
30520006a0bStron "Target line: ",
30620006a0bStron "0123456789.-",
30720006a0bStron NULL
30820006a0bStron }
30920006a0bStron },
31020006a0bStron { 'J', &J__optname,
31120006a0bStron BOOL|REPAINT, OPT_OFF, &status_col, NULL,
31220006a0bStron {
31320006a0bStron "Don't display a status column",
31420006a0bStron "Display a status column",
31520006a0bStron NULL
31620006a0bStron }
31720006a0bStron },
31820006a0bStron #if USERFILE
31920006a0bStron { 'k', &k_optname,
32020006a0bStron STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_k,
32120006a0bStron { NULL, NULL, NULL }
32220006a0bStron },
323838f5788Ssimonb #if HAVE_LESSKEYSRC
324838f5788Ssimonb { OLETTER_NONE, &ks_optname,
325838f5788Ssimonb STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_ks,
326838f5788Ssimonb { NULL, NULL, NULL }
327838f5788Ssimonb },
328838f5788Ssimonb #endif /* HAVE_LESSKEYSRC */
32920006a0bStron #endif
33020006a0bStron { 'K', &K__optname,
33120006a0bStron BOOL, OPT_OFF, &quit_on_intr, NULL,
33220006a0bStron {
33320006a0bStron "Interrupt (ctrl-C) returns to prompt",
33420006a0bStron "Interrupt (ctrl-C) exits less",
33520006a0bStron NULL
33620006a0bStron }
33720006a0bStron },
33820006a0bStron { 'L', &L__optname,
33920006a0bStron BOOL, OPT_ON, &use_lessopen, NULL,
34020006a0bStron {
34120006a0bStron "Don't use the LESSOPEN filter",
34220006a0bStron "Use the LESSOPEN filter",
34320006a0bStron NULL
34420006a0bStron }
34520006a0bStron },
34620006a0bStron { 'm', &m_optname,
34720006a0bStron TRIPLE, OPT_OFF, &pr_type, NULL,
34820006a0bStron {
34920006a0bStron "Short prompt",
35020006a0bStron "Medium prompt",
35120006a0bStron "Long prompt"
35220006a0bStron }
35320006a0bStron },
35420006a0bStron { 'n', &n_optname,
35520006a0bStron TRIPLE|REPAINT, OPT_ON, &linenums, NULL,
35620006a0bStron {
35720006a0bStron "Don't use line numbers",
35820006a0bStron "Use line numbers",
35920006a0bStron "Constantly display line numbers"
36020006a0bStron }
36120006a0bStron },
36220006a0bStron #if LOGFILE
36320006a0bStron { 'o', &o_optname,
36420006a0bStron STRING, 0, NULL, opt_o,
36520006a0bStron { "log file: ", NULL, NULL }
36620006a0bStron },
36720006a0bStron { 'O', &O__optname,
36820006a0bStron STRING, 0, NULL, opt__O,
36920006a0bStron { "Log file: ", NULL, NULL }
37020006a0bStron },
37120006a0bStron #endif
37220006a0bStron { 'p', &p_optname,
37320006a0bStron STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_p,
37420006a0bStron { NULL, NULL, NULL }
37520006a0bStron },
37620006a0bStron { 'P', &P__optname,
37720006a0bStron STRING, 0, NULL, opt__P,
37820006a0bStron { "prompt: ", NULL, NULL }
37920006a0bStron },
38020006a0bStron { 'q', &q_optname,
38120006a0bStron TRIPLE, OPT_OFF, &quiet, NULL,
38220006a0bStron {
38320006a0bStron "Ring the bell for errors AND at eof/bof",
38420006a0bStron "Ring the bell for errors but not at eof/bof",
38520006a0bStron "Never ring the bell"
38620006a0bStron }
38720006a0bStron },
38820006a0bStron { 'r', &r_optname,
38920006a0bStron TRIPLE|REPAINT, OPT_OFF, &ctldisp, NULL,
39020006a0bStron {
39120006a0bStron "Display control characters as ^X",
392838f5788Ssimonb "Display control characters directly (not recommended)",
393838f5788Ssimonb "Display ANSI sequences directly, other control characters as ^X"
39420006a0bStron }
39520006a0bStron },
39620006a0bStron { 's', &s_optname,
39720006a0bStron BOOL|REPAINT, OPT_OFF, &squeeze, NULL,
39820006a0bStron {
39920006a0bStron "Display all blank lines",
40020006a0bStron "Squeeze multiple blank lines",
40120006a0bStron NULL
40220006a0bStron }
40320006a0bStron },
40420006a0bStron { 'S', &S__optname,
40520006a0bStron BOOL|REPAINT, OPT_OFF, &chopline, NULL,
40620006a0bStron {
40720006a0bStron "Fold long lines",
40820006a0bStron "Chop long lines",
40920006a0bStron NULL
41020006a0bStron }
41120006a0bStron },
41220006a0bStron #if TAGS
41320006a0bStron { 't', &t_optname,
41420006a0bStron STRING|NO_QUERY, 0, NULL, opt_t,
41520006a0bStron { "tag: ", NULL, NULL }
41620006a0bStron },
41720006a0bStron { 'T', &T__optname,
41820006a0bStron STRING, 0, NULL, opt__T,
41920006a0bStron { "tags file: ", NULL, NULL }
42020006a0bStron },
42120006a0bStron #endif
42220006a0bStron { 'u', &u_optname,
423838f5788Ssimonb TRIPLE|REPAINT|HL_REPAINT, OPT_OFF, &bs_mode, NULL,
42420006a0bStron {
42520006a0bStron "Display underlined text in underline mode",
42620006a0bStron "Backspaces cause overstrike",
42720006a0bStron "Print backspace as ^H"
42820006a0bStron }
42920006a0bStron },
43020006a0bStron { 'V', &V__optname,
43120006a0bStron NOVAR, 0, NULL, opt__V,
43220006a0bStron { NULL, NULL, NULL }
43320006a0bStron },
43420006a0bStron { 'w', &w_optname,
43520006a0bStron TRIPLE|REPAINT, OPT_OFF, &show_attn, NULL,
43620006a0bStron {
43720006a0bStron "Don't highlight first unread line",
43820006a0bStron "Highlight first unread line after forward-screen",
43920006a0bStron "Highlight first unread line after any forward movement",
44020006a0bStron }
44120006a0bStron },
44220006a0bStron { 'x', &x_optname,
44320006a0bStron STRING|REPAINT, 0, NULL, opt_x,
44420006a0bStron {
44520006a0bStron "Tab stops: ",
44620006a0bStron "0123456789,",
44720006a0bStron NULL
44820006a0bStron }
44920006a0bStron },
45020006a0bStron { 'X', &X__optname,
45120006a0bStron BOOL|NO_TOGGLE, OPT_OFF, &no_init, NULL,
45220006a0bStron {
45320006a0bStron "Send init/deinit strings to terminal",
45420006a0bStron "Don't use init/deinit strings",
45520006a0bStron NULL
45620006a0bStron }
45720006a0bStron },
45820006a0bStron { 'y', &y_optname,
45920006a0bStron NUMBER, -1, &forw_scroll, NULL,
46020006a0bStron {
46120006a0bStron "Forward scroll limit: ",
46220006a0bStron "Forward scroll limit is %d lines",
46320006a0bStron NULL
46420006a0bStron }
46520006a0bStron },
46620006a0bStron { 'z', &z_optname,
46720006a0bStron NUMBER, -1, &swindow, NULL,
46820006a0bStron {
46920006a0bStron "Scroll window size: ",
47020006a0bStron "Scroll window size is %d lines",
47120006a0bStron NULL
47220006a0bStron }
47320006a0bStron },
47420006a0bStron { '"', "e_optname,
47520006a0bStron STRING, 0, NULL, opt_quote,
47620006a0bStron { "quotes: ", NULL, NULL }
47720006a0bStron },
47820006a0bStron { '~', &tilde_optname,
47920006a0bStron BOOL|REPAINT, OPT_ON, &twiddle, NULL,
48020006a0bStron {
48120006a0bStron "Don't show tildes after end of file",
48220006a0bStron "Show tildes after end of file",
48320006a0bStron NULL
48420006a0bStron }
48520006a0bStron },
48620006a0bStron { '?', &query_optname,
48720006a0bStron NOVAR, 0, NULL, opt_query,
48820006a0bStron { NULL, NULL, NULL }
48920006a0bStron },
49020006a0bStron { '#', £_optname,
49120006a0bStron STRING, 0, NULL, opt_shift,
49220006a0bStron {
49320006a0bStron "Horizontal shift: ",
49420006a0bStron "0123456789.",
49520006a0bStron NULL
49620006a0bStron }
49720006a0bStron },
49820006a0bStron { OLETTER_NONE, &keypad_optname,
49920006a0bStron BOOL|NO_TOGGLE, OPT_OFF, &no_keypad, NULL,
50020006a0bStron {
50120006a0bStron "Use keypad mode",
50220006a0bStron "Don't use keypad mode",
50320006a0bStron NULL
50420006a0bStron }
50520006a0bStron },
50620006a0bStron { OLETTER_NONE, &oldbot_optname,
50720006a0bStron BOOL, OPT_OFF, &oldbot, NULL,
50820006a0bStron {
50920006a0bStron "Use new bottom of screen behavior",
51020006a0bStron "Use old bottom of screen behavior",
51120006a0bStron NULL
51220006a0bStron }
51320006a0bStron },
51420006a0bStron { OLETTER_NONE, &follow_optname,
51520006a0bStron BOOL, FOLLOW_DESC, &follow_mode, NULL,
51620006a0bStron {
51720006a0bStron "F command follows file descriptor",
51820006a0bStron "F command follows file name",
51920006a0bStron NULL
52020006a0bStron }
52120006a0bStron },
522ec18bca0Stron { OLETTER_NONE, &use_backslash_optname,
523ec18bca0Stron BOOL, OPT_OFF, &opt_use_backslash, NULL,
524ec18bca0Stron {
525ec18bca0Stron "Use backslash escaping in command line parameters",
526ec18bca0Stron "Don't use backslash escaping in command line parameters",
527ec18bca0Stron NULL
528ec18bca0Stron }
529ec18bca0Stron },
530838f5788Ssimonb { OLETTER_NONE, &rscroll_optname,
531838f5788Ssimonb STRING|REPAINT|INIT_HANDLER, 0, NULL, opt_rscroll,
532838f5788Ssimonb { "rscroll character: ", NULL, NULL }
533838f5788Ssimonb },
534838f5788Ssimonb { OLETTER_NONE, &nohistdups_optname,
535838f5788Ssimonb BOOL, OPT_OFF, &no_hist_dups, NULL,
536838f5788Ssimonb {
537838f5788Ssimonb "Allow duplicates in history list",
538838f5788Ssimonb "Remove duplicates from history list",
539838f5788Ssimonb NULL
540838f5788Ssimonb }
541838f5788Ssimonb },
542838f5788Ssimonb { OLETTER_NONE, &mousecap_optname,
543838f5788Ssimonb TRIPLE, OPT_OFF, &mousecap, opt_mousecap,
544838f5788Ssimonb {
545838f5788Ssimonb "Ignore mouse input",
546838f5788Ssimonb "Use the mouse for scrolling",
547838f5788Ssimonb "Use the mouse for scrolling (reverse)"
548838f5788Ssimonb }
549838f5788Ssimonb },
550838f5788Ssimonb { OLETTER_NONE, &wheel_lines_optname,
551838f5788Ssimonb NUMBER|INIT_HANDLER, 0, &wheel_lines, opt_wheel_lines,
552838f5788Ssimonb {
553838f5788Ssimonb "Lines to scroll on mouse wheel: ",
554838f5788Ssimonb "Scroll %d line(s) on mouse wheel",
555838f5788Ssimonb NULL
556838f5788Ssimonb }
557838f5788Ssimonb },
558838f5788Ssimonb { OLETTER_NONE, &perma_marks_optname,
559838f5788Ssimonb BOOL, OPT_OFF, &perma_marks, NULL,
560838f5788Ssimonb {
561838f5788Ssimonb "Don't save marks in history file",
562838f5788Ssimonb "Save marks in history file",
563838f5788Ssimonb NULL
564838f5788Ssimonb }
565838f5788Ssimonb },
566838f5788Ssimonb { OLETTER_NONE, &linenum_width_optname,
567838f5788Ssimonb NUMBER|REPAINT, MIN_LINENUM_WIDTH, &linenum_width, opt_linenum_width,
568838f5788Ssimonb {
569838f5788Ssimonb "Line number width: ",
570838f5788Ssimonb "Line number width is %d chars",
571838f5788Ssimonb NULL
572838f5788Ssimonb }
573838f5788Ssimonb },
574838f5788Ssimonb { OLETTER_NONE, &status_col_width_optname,
575838f5788Ssimonb NUMBER|REPAINT, 2, &status_col_width, opt_status_col_width,
576838f5788Ssimonb {
577838f5788Ssimonb "Status column width: ",
578838f5788Ssimonb "Status column width is %d chars",
579838f5788Ssimonb NULL
580838f5788Ssimonb }
581838f5788Ssimonb },
582838f5788Ssimonb { OLETTER_NONE, &incr_search_optname,
583838f5788Ssimonb BOOL, OPT_OFF, &incr_search, NULL,
584838f5788Ssimonb {
585838f5788Ssimonb "Incremental search is off",
586838f5788Ssimonb "Incremental search is on",
587838f5788Ssimonb NULL
588838f5788Ssimonb }
589838f5788Ssimonb },
590838f5788Ssimonb { OLETTER_NONE, &use_color_optname,
591838f5788Ssimonb BOOL|REPAINT, OPT_OFF, &use_color, NULL,
592838f5788Ssimonb {
593838f5788Ssimonb "Don't use color",
594838f5788Ssimonb "Use color",
595838f5788Ssimonb NULL
596838f5788Ssimonb }
597838f5788Ssimonb },
598838f5788Ssimonb { OLETTER_NONE, &want_filesize_optname,
599838f5788Ssimonb BOOL|REPAINT, OPT_OFF, &want_filesize, opt_filesize,
600838f5788Ssimonb {
601838f5788Ssimonb "Don't get size of each file",
602838f5788Ssimonb "Get size of each file",
603838f5788Ssimonb NULL
604838f5788Ssimonb }
605838f5788Ssimonb },
606838f5788Ssimonb { OLETTER_NONE, &status_line_optname,
607838f5788Ssimonb BOOL|REPAINT, OPT_OFF, &status_line, NULL,
608838f5788Ssimonb {
609838f5788Ssimonb "Don't color each line with its status column color",
610838f5788Ssimonb "Color each line with its status column color",
611838f5788Ssimonb NULL
612838f5788Ssimonb }
613838f5788Ssimonb },
614838f5788Ssimonb { OLETTER_NONE, &header_optname,
615838f5788Ssimonb STRING|REPAINT, 0, NULL, opt_header,
616838f5788Ssimonb {
617838f5788Ssimonb "Header lines: ",
618838f5788Ssimonb NULL,
619838f5788Ssimonb NULL
620838f5788Ssimonb }
621838f5788Ssimonb },
622838f5788Ssimonb { OLETTER_NONE, &nonum_headers_optname,
623838f5788Ssimonb BOOL|REPAINT, 0, &nonum_headers, NULL,
624838f5788Ssimonb {
625838f5788Ssimonb "Number header lines",
626838f5788Ssimonb "Don't number header lines",
627838f5788Ssimonb NULL
628838f5788Ssimonb }
629838f5788Ssimonb },
630838f5788Ssimonb { OLETTER_NONE, &nosearch_headers_optname,
631838f5788Ssimonb BOOL|HL_REPAINT, 0, &nosearch_headers, NULL,
632838f5788Ssimonb {
633838f5788Ssimonb "Search includes header lines",
634838f5788Ssimonb "Search does not include header lines",
635838f5788Ssimonb NULL
636838f5788Ssimonb }
637838f5788Ssimonb },
638838f5788Ssimonb { OLETTER_NONE, &redraw_on_quit_optname,
639838f5788Ssimonb BOOL, OPT_OFF, &redraw_on_quit, NULL,
640838f5788Ssimonb {
641838f5788Ssimonb "Don't redraw screen when quitting",
642838f5788Ssimonb "Redraw last screen when quitting",
643838f5788Ssimonb NULL
644838f5788Ssimonb }
645838f5788Ssimonb },
646838f5788Ssimonb { OLETTER_NONE, &search_type_optname,
647838f5788Ssimonb STRING, 0, NULL, opt_search_type,
648838f5788Ssimonb {
649838f5788Ssimonb "Search options: ",
650838f5788Ssimonb NULL,
651838f5788Ssimonb NULL
652838f5788Ssimonb }
653838f5788Ssimonb },
654838f5788Ssimonb { OLETTER_NONE, &exit_F_on_close_optname,
655838f5788Ssimonb BOOL, OPT_OFF, &exit_F_on_close, NULL,
656838f5788Ssimonb {
657838f5788Ssimonb "Don't exit F command when input closes",
658838f5788Ssimonb "Exit F command when input closes",
659838f5788Ssimonb NULL
660838f5788Ssimonb }
661838f5788Ssimonb },
662838f5788Ssimonb { OLETTER_NONE, &no_vbell_optname,
663838f5788Ssimonb BOOL, OPT_OFF, &no_vbell, NULL,
664838f5788Ssimonb {
665838f5788Ssimonb "Display visual bell",
666838f5788Ssimonb "Don't display visual bell",
667838f5788Ssimonb NULL
668838f5788Ssimonb }
669838f5788Ssimonb },
670838f5788Ssimonb { OLETTER_NONE, &modelines_optname,
671838f5788Ssimonb NUMBER, 0, &modelines, NULL,
672838f5788Ssimonb {
673838f5788Ssimonb "Lines to read looking for modelines: ",
674838f5788Ssimonb "Read %d lines looking for modelines",
675838f5788Ssimonb NULL
676838f5788Ssimonb }
677838f5788Ssimonb },
678838f5788Ssimonb { OLETTER_NONE, &intr_optname,
679838f5788Ssimonb STRING, 0, NULL, opt_intr,
680838f5788Ssimonb { "interrupt character: ", NULL, NULL }
681838f5788Ssimonb },
682838f5788Ssimonb { OLETTER_NONE, &wordwrap_optname,
683838f5788Ssimonb BOOL|REPAINT, OPT_OFF, &wordwrap, NULL,
684838f5788Ssimonb {
685838f5788Ssimonb "Wrap lines at any character",
686838f5788Ssimonb "Wrap lines at spaces",
687838f5788Ssimonb NULL
688838f5788Ssimonb }
689838f5788Ssimonb },
690838f5788Ssimonb { OLETTER_NONE, &show_preproc_error_optname,
691838f5788Ssimonb BOOL, OPT_OFF, &show_preproc_error, NULL,
692838f5788Ssimonb {
693838f5788Ssimonb "Don't show error message if preprocessor fails",
694838f5788Ssimonb "Show error message if preprocessor fails",
695838f5788Ssimonb NULL
696838f5788Ssimonb }
697838f5788Ssimonb },
698838f5788Ssimonb { OLETTER_NONE, &proc_backspace_optname,
699838f5788Ssimonb TRIPLE|REPAINT|HL_REPAINT, OPT_OFF, &proc_backspace, NULL,
700838f5788Ssimonb {
701838f5788Ssimonb "Backspace handling is specified by the -U option",
702838f5788Ssimonb "Display underline text in underline mode",
703838f5788Ssimonb "Print backspaces as ^H"
704838f5788Ssimonb }
705838f5788Ssimonb },
706838f5788Ssimonb { OLETTER_NONE, &proc_tab_optname,
707838f5788Ssimonb TRIPLE|REPAINT|HL_REPAINT, OPT_OFF, &proc_tab, NULL,
708838f5788Ssimonb {
709838f5788Ssimonb "Tab handling is specified by the -U option",
710838f5788Ssimonb "Expand tabs to spaces",
711838f5788Ssimonb "Print tabs as ^I"
712838f5788Ssimonb }
713838f5788Ssimonb },
714838f5788Ssimonb { OLETTER_NONE, &proc_return_optname,
715838f5788Ssimonb TRIPLE|REPAINT|HL_REPAINT, OPT_OFF, &proc_return, NULL,
716838f5788Ssimonb {
717838f5788Ssimonb "Carriage return handling is specified by the -U option",
718838f5788Ssimonb "Delete carriage return before newline",
719838f5788Ssimonb "Print carriage return as ^M"
720838f5788Ssimonb }
721838f5788Ssimonb },
722838f5788Ssimonb #if LESSTEST
723838f5788Ssimonb { OLETTER_NONE, &ttyin_name_optname,
724838f5788Ssimonb STRING|NO_TOGGLE, 0, NULL, opt_ttyin_name,
725838f5788Ssimonb {
726838f5788Ssimonb NULL,
727838f5788Ssimonb NULL,
728838f5788Ssimonb NULL
729838f5788Ssimonb }
730838f5788Ssimonb },
731838f5788Ssimonb #endif /*LESSTEST*/
73220006a0bStron { '\0', NULL, NOVAR, 0, NULL, NULL, { NULL, NULL, NULL } }
73320006a0bStron };
73420006a0bStron
73520006a0bStron
73620006a0bStron /*
73720006a0bStron * Initialize each option to its default value.
73820006a0bStron */
init_option(void)739838f5788Ssimonb public void init_option(void)
74020006a0bStron {
741838f5788Ssimonb struct loption *o;
74220006a0bStron char *p;
74320006a0bStron
74420006a0bStron p = lgetenv("LESS_IS_MORE");
745838f5788Ssimonb if (!isnullenv(p))
74620006a0bStron less_is_more = 1;
74720006a0bStron
74820006a0bStron for (o = option; o->oletter != '\0'; o++)
74920006a0bStron {
75020006a0bStron /*
75120006a0bStron * Set each variable to its default.
75220006a0bStron */
75320006a0bStron if (o->ovar != NULL)
75420006a0bStron *(o->ovar) = o->odefault;
75520006a0bStron if (o->otype & INIT_HANDLER)
75620006a0bStron (*(o->ofunc))(INIT, (char *) NULL);
75720006a0bStron }
75820006a0bStron }
75920006a0bStron
76020006a0bStron /*
76120006a0bStron * Find an option in the option table, given its option letter.
76220006a0bStron */
findopt(int c)763838f5788Ssimonb public struct loption * findopt(int c)
76420006a0bStron {
765838f5788Ssimonb struct loption *o;
76620006a0bStron
76720006a0bStron for (o = option; o->oletter != '\0'; o++)
76820006a0bStron {
76920006a0bStron if (o->oletter == c)
77020006a0bStron return (o);
77120006a0bStron if ((o->otype & TRIPLE) && ASCII_TO_UPPER(o->oletter) == c)
77220006a0bStron return (o);
77320006a0bStron }
77420006a0bStron return (NULL);
77520006a0bStron }
77620006a0bStron
77720006a0bStron /*
77820006a0bStron *
77920006a0bStron */
is_optchar(char c)780838f5788Ssimonb static int is_optchar(char c)
78120006a0bStron {
78220006a0bStron if (ASCII_IS_UPPER(c))
78320006a0bStron return 1;
78420006a0bStron if (ASCII_IS_LOWER(c))
78520006a0bStron return 1;
78620006a0bStron if (c == '-')
78720006a0bStron return 1;
78820006a0bStron return 0;
78920006a0bStron }
79020006a0bStron
79120006a0bStron /*
79220006a0bStron * Find an option in the option table, given its option name.
79320006a0bStron * p_optname is the (possibly partial) name to look for, and
79420006a0bStron * is updated to point after the matched name.
79520006a0bStron * p_oname if non-NULL is set to point to the full option name.
79620006a0bStron */
findopt_name(char ** p_optname,char ** p_oname,int * p_err)797838f5788Ssimonb public struct loption * findopt_name(char **p_optname, char **p_oname, int *p_err)
79820006a0bStron {
79920006a0bStron char *optname = *p_optname;
800838f5788Ssimonb struct loption *o;
801838f5788Ssimonb struct optname *oname;
802838f5788Ssimonb int len;
80320006a0bStron int uppercase;
80420006a0bStron struct loption *maxo = NULL;
80520006a0bStron struct optname *maxoname = NULL;
80620006a0bStron int maxlen = 0;
80720006a0bStron int ambig = 0;
80820006a0bStron int exact = 0;
80920006a0bStron
81020006a0bStron /*
81120006a0bStron * Check all options.
81220006a0bStron */
81320006a0bStron for (o = option; o->oletter != '\0'; o++)
81420006a0bStron {
81520006a0bStron /*
81620006a0bStron * Check all names for this option.
81720006a0bStron */
81820006a0bStron for (oname = o->onames; oname != NULL; oname = oname->onext)
81920006a0bStron {
82020006a0bStron /*
82120006a0bStron * Try normal match first (uppercase == 0),
82220006a0bStron * then, then if it's a TRIPLE option,
82320006a0bStron * try uppercase match (uppercase == 1).
82420006a0bStron */
82520006a0bStron for (uppercase = 0; uppercase <= 1; uppercase++)
82620006a0bStron {
82720006a0bStron len = sprefix(optname, oname->oname, uppercase);
82820006a0bStron if (len <= 0 || is_optchar(optname[len]))
82920006a0bStron {
83020006a0bStron /*
83120006a0bStron * We didn't use all of the option name.
83220006a0bStron */
83320006a0bStron continue;
83420006a0bStron }
83520006a0bStron if (!exact && len == maxlen)
83620006a0bStron /*
83720006a0bStron * Already had a partial match,
83820006a0bStron * and now there's another one that
83920006a0bStron * matches the same length.
84020006a0bStron */
84120006a0bStron ambig = 1;
84220006a0bStron else if (len > maxlen)
84320006a0bStron {
84420006a0bStron /*
84520006a0bStron * Found a better match than
84620006a0bStron * the one we had.
84720006a0bStron */
84820006a0bStron maxo = o;
84920006a0bStron maxoname = oname;
85020006a0bStron maxlen = len;
85120006a0bStron ambig = 0;
85220006a0bStron exact = (len == (int)strlen(oname->oname));
85320006a0bStron }
85420006a0bStron if (!(o->otype & TRIPLE))
85520006a0bStron break;
85620006a0bStron }
85720006a0bStron }
85820006a0bStron }
85920006a0bStron if (ambig)
86020006a0bStron {
86120006a0bStron /*
86220006a0bStron * Name matched more than one option.
86320006a0bStron */
86420006a0bStron if (p_err != NULL)
86520006a0bStron *p_err = OPT_AMBIG;
86620006a0bStron return (NULL);
86720006a0bStron }
86820006a0bStron *p_optname = optname + maxlen;
86920006a0bStron if (p_oname != NULL)
87020006a0bStron *p_oname = maxoname == NULL ? NULL : maxoname->oname;
87120006a0bStron return (maxo);
87220006a0bStron }
873