2 * Copyright (C) 1984-2002 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 about less, or for information on how to
8 * contact the author, see the README file.
20 * Variables controlled by command line options.
22 public int quiet; /* Should we suppress the audible bell? */
23 public int how_search; /* Where should forward searches start? */
24 public int top_scroll; /* Repaint screen from top?
25 (alternative is scroll from bottom) */
26 public int pr_type; /* Type of prompt (short, medium, long) */
27 public int bs_mode; /* How to process backspaces */
28 public int know_dumb; /* Don't complain about dumb terminals */
29 public int quit_at_eof; /* Quit after hitting end of file twice */
30 public int quit_if_one_screen; /* Quit if EOF on first screen */
31 public int squeeze; /* Squeeze multiple blank lines into one */
32 public int tabstop; /* Tab settings */
33 public int back_scroll; /* Repaint screen on backwards movement */
34 public int forw_scroll; /* Repaint screen on forward movement */
35 public int caseless; /* Do "caseless" searches */
36 public int linenums; /* Use line numbers */
37 public int autobuf; /* Automatically allocate buffers as needed */
38 public int bufspace; /* Max buffer space per file (K) */
39 public int ctldisp; /* Send control chars to screen untranslated */
40 public int force_open; /* Open the file even if not regular file */
41 public int swindow; /* Size of scrolling window */
42 public int jump_sline; /* Screen line of "jump target" */
43 public int chopline; /* Truncate displayed lines at screen width */
44 public int no_init; /* Disable sending ti/te termcap strings */
45 public int no_keypad; /* Disable sending ks/ke termcap strings */
46 public int twiddle; /* Show tildes after EOF */
47 public int show_attn; /* Hilite first unread line */
48 public int shift_count; /* Number of positions to shift horizontally */
49 public int status_col; /* Display a status column */
50 public int use_lessopen; /* Use the LESSOPEN filter */
52 public int hilite_search; /* Highlight matched search patterns? */
58 static struct optname a_optname = { "search-skip-screen", NULL };
59 static struct optname b_optname = { "buffers", NULL };
60 static struct optname B__optname = { "auto-buffers", NULL };
61 static struct optname c_optname = { "clear-screen", NULL };
62 static struct optname d_optname = { "dumb", NULL };
64 static struct optname D__optname = { "color", NULL };
66 static struct optname e_optname = { "quit-at-eof", NULL };
67 static struct optname f_optname = { "force", NULL };
68 static struct optname F__optname = { "quit-if-one-screen", NULL };
70 static struct optname g_optname = { "hilite-search", NULL };
72 static struct optname h_optname = { "max-back-scroll", NULL };
73 static struct optname i_optname = { "ignore-case", NULL };
74 static struct optname j_optname = { "jump-target", NULL };
75 static struct optname J__optname = { "status-column", NULL };
77 static struct optname k_optname = { "lesskey-file", NULL };
79 static struct optname L__optname = { "no-lessopen", NULL };
80 static struct optname m_optname = { "long-prompt", NULL };
81 static struct optname n_optname = { "line-numbers", NULL };
83 static struct optname o_optname = { "log-file", NULL };
84 static struct optname O__optname = { "LOG-FILE", NULL };
86 static struct optname p_optname = { "pattern", NULL };
87 static struct optname P__optname = { "prompt", NULL };
88 static struct optname q2_optname = { "silent", NULL };
89 static struct optname q_optname = { "quiet", &q2_optname };
90 static struct optname r_optname = { "raw-control-chars", NULL };
91 static struct optname s_optname = { "squeeze-blank-lines", NULL };
92 static struct optname S__optname = { "chop-long-lines", NULL };
94 static struct optname t_optname = { "tag", NULL };
95 static struct optname T__optname = { "tag-file", NULL };
97 static struct optname u_optname = { "underline-special", NULL };
98 static struct optname V__optname = { "version", NULL };
99 static struct optname w_optname = { "hilite-unread", NULL };
100 static struct optname x_optname = { "tabs", NULL };
101 static struct optname X__optname = { "no-init", NULL };
102 static struct optname y_optname = { "max-forw-scroll", NULL };
103 static struct optname z_optname = { "window", NULL };
104 static struct optname quote_optname = { "quotes", NULL };
105 static struct optname tilde_optname = { "tilde", NULL };
106 static struct optname query_optname = { "help", NULL };
107 static struct optname pound_optname = { "shift", NULL };
108 static struct optname keypad_optname = { "no-keypad", NULL };
112 * Table of all options and their semantics.
114 * For BOOL and TRIPLE options, odesc[0], odesc[1], odesc[2] are
115 * the description of the option when set to 0, 1 or 2, respectively.
116 * For NUMBER options, odesc[0] is the prompt to use when entering
117 * a new value, and odesc[1] is the description, which should contain
118 * one %d which is replaced by the value of the number.
119 * For STRING options, odesc[0] is the prompt to use when entering
120 * a new value, and odesc[1], if not NULL, is the set of characters
121 * that are valid in the string.
123 static struct loption option[] =
126 BOOL, OPT_OFF, &how_search, NULL,
128 "Search includes displayed screen",
129 "Search skips displayed screen",
135 NUMBER|INIT_HANDLER, 64, &bufspace, opt_b,
137 "Max buffer space per file (K): ",
138 "Max buffer space per file: %dK",
143 BOOL, OPT_ON, &autobuf, NULL,
145 "Don't automatically allocate buffers",
146 "Automatically allocate buffers when needed",
151 TRIPLE, OPT_OFF, &top_scroll, NULL,
153 "Repaint by scrolling from bottom of screen",
154 "Repaint by clearing each line",
155 "Repaint by painting from top of screen"
159 BOOL|NO_TOGGLE, OPT_OFF, &know_dumb, NULL,
161 "Assume intelligent terminal",
162 "Assume dumb terminal",
168 STRING|REPAINT|NO_QUERY, 0, NULL, opt_D,
177 TRIPLE, OPT_OFF, &quit_at_eof, NULL,
179 "Don't quit at end-of-file",
180 "Quit at end-of-file",
181 "Quit immediately at end-of-file"
185 BOOL, OPT_OFF, &force_open, NULL,
187 "Open only regular files",
188 "Open even non-regular files",
193 BOOL, OPT_OFF, &quit_if_one_screen, NULL,
195 "Don't quit if end-of-file on first screen",
196 "Quit if end-of-file on first screen",
202 TRIPLE|HL_REPAINT, OPT_ONPLUS, &hilite_search, NULL,
204 "Don't highlight search matches",
205 "Highlight matches for previous search only",
206 "Highlight all matches for previous search pattern",
211 NUMBER, -1, &back_scroll, NULL,
213 "Backwards scroll limit: ",
214 "Backwards scroll limit is %d lines",
219 TRIPLE|HL_REPAINT, OPT_OFF, &caseless, opt_i,
221 "Case is significant in searches",
222 "Ignore case in searches",
223 "Ignore case in searches and in patterns"
227 NUMBER, 1, &jump_sline, NULL,
230 "Position target at screen line %d",
235 BOOL|REPAINT, OPT_OFF, &status_col, NULL,
237 "Don't display a status column",
238 "Display a status column",
244 STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_k,
249 STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_l,
253 BOOL, OPT_ON, &use_lessopen, NULL,
255 "Don't use the LESSOPEN filter",
256 "Use the LESSOPEN filter",
261 TRIPLE, OPT_OFF, &pr_type, NULL,
269 TRIPLE|REPAINT, OPT_ON, &linenums, NULL,
271 "Don't use line numbers",
273 "Constantly display line numbers"
278 STRING, 0, NULL, opt_o,
279 { "log file: ", NULL, NULL }
282 STRING, 0, NULL, opt__O,
283 { "Log file: ", NULL, NULL }
287 STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_p,
291 STRING, 0, NULL, opt__P,
292 { "prompt: ", NULL, NULL }
295 TRIPLE, OPT_OFF, &quiet, NULL,
297 "Ring the bell for errors AND at eof/bof",
298 "Ring the bell for errors but not at eof/bof",
299 "Never ring the bell"
303 TRIPLE|REPAINT, OPT_OFF, &ctldisp, NULL,
305 "Display control characters as ^X",
306 "Display control characters directly",
307 "Display control characters directly, processing ANSI sequences"
311 BOOL|REPAINT, OPT_OFF, &squeeze, NULL,
313 "Display all blank lines",
314 "Squeeze multiple blank lines",
319 BOOL|REPAINT, OPT_OFF, &chopline, NULL,
328 STRING|NO_QUERY, 0, NULL, opt_t,
329 { "tag: ", NULL, NULL }
332 STRING, 0, NULL, opt__T,
333 { "tags file: ", NULL, NULL }
337 TRIPLE|REPAINT, OPT_OFF, &bs_mode, NULL,
339 "Display underlined text in underline mode",
340 "Backspaces cause overstrike",
341 "Print backspace as ^H"
345 NOVAR, 0, NULL, opt__V,
349 TRIPLE|REPAINT, OPT_OFF, &show_attn, NULL,
351 "Don't highlight first unread line",
352 "Highlight first unread line after forward-screen",
353 "Highlight first unread line after any forward movement",
357 STRING|REPAINT, 0, NULL, opt_x,
365 BOOL|NO_TOGGLE, OPT_OFF, &no_init, NULL,
367 "Send init/deinit strings to terminal",
368 "Don't use init/deinit strings",
373 NUMBER, -1, &forw_scroll, NULL,
375 "Forward scroll limit: ",
376 "Forward scroll limit is %d lines",
381 NUMBER, -1, &swindow, NULL,
383 "Scroll window size: ",
384 "Scroll window size is %d lines",
388 { '"', "e_optname,
389 STRING, 0, NULL, opt_quote,
390 { "quotes: ", NULL, NULL }
392 { '~', &tilde_optname,
393 BOOL|REPAINT, OPT_ON, &twiddle, NULL,
395 "Don't show tildes after end of file",
396 "Show tildes after end of file",
400 { '?', &query_optname,
401 NOVAR, 0, NULL, opt_query,
404 { '#', £_optname,
405 NUMBER, 0, &shift_count, NULL,
407 "Horizontal shift: ",
408 "Horizontal shift %d positions",
412 { '.', &keypad_optname,
413 BOOL|NO_TOGGLE, OPT_OFF, &no_keypad, NULL,
416 "Don't use keypad mode",
420 { '\0', NULL, NOVAR, 0, NULL, NULL, { NULL, NULL, NULL } }
425 * Initialize each option to its default value.
430 register struct loption *o;
432 for (o = option; o->oletter != '\0'; o++)
435 * Set each variable to its default.
438 *(o->ovar) = o->odefault;
439 if (o->otype & INIT_HANDLER)
440 (*(o->ofunc))(INIT, (char *) NULL);
445 * Find an option in the option table, given its option letter.
447 public struct loption *
451 register struct loption *o;
453 for (o = option; o->oletter != '\0'; o++)
457 if ((o->otype & TRIPLE) && toupper(o->oletter) == c)
470 if (SIMPLE_IS_UPPER(c))
472 if (SIMPLE_IS_LOWER(c))
480 * Find an option in the option table, given its option name.
481 * p_optname is the (possibly partial) name to look for, and
482 * is updated to point after the matched name.
483 * p_oname if non-NULL is set to point to the full option name.
485 public struct loption *
486 findopt_name(p_optname, p_oname, p_err)
491 char *optname = *p_optname;
492 register struct loption *o;
493 register struct optname *oname;
496 struct loption *maxo = NULL;
497 struct optname *maxoname = NULL;
506 for (o = option; o->oletter != '\0'; o++)
509 * Check all names for this option.
511 for (oname = o->onames; oname != NULL; oname = oname->onext)
514 * Try normal match first (uppercase == 0),
515 * then, then if it's a TRIPLE option,
516 * try uppercase match (uppercase == 1).
518 for (uppercase = 0; uppercase <= 1; uppercase++)
520 len = sprefix(optname, oname->oname, uppercase);
521 if (len <= 0 || is_optchar(optname[len]))
524 * We didn't use all of the option name.
528 if (!exact && len == maxlen)
530 * Already had a partial match,
531 * and now there's another one that
532 * matches the same length.
535 else if (len > maxlen)
538 * Found a better match than
545 exact = (len == (int)strlen(oname->oname));
547 if (!(o->otype & TRIPLE))
555 * Name matched more than one option.
561 *p_optname = optname + maxlen;
563 *p_oname = maxoname == NULL ? NULL : maxoname->oname;