2 * Copyright (C) 1984-2012 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.
19 * Variables controlled by command line options.
21 public int quiet; /* Should we suppress the audible bell? */
22 public int how_search; /* Where should forward searches start? */
23 public int top_scroll; /* Repaint screen from top?
24 (alternative is scroll from bottom) */
25 public int pr_type; /* Type of prompt (short, medium, long) */
26 public int bs_mode; /* How to process backspaces */
27 public int know_dumb; /* Don't complain about dumb terminals */
28 public int quit_at_eof; /* Quit after hitting end of file twice */
29 public int quit_if_one_screen; /* Quit if EOF on first screen */
30 public int squeeze; /* Squeeze multiple blank lines into one */
31 public int tabstop; /* Tab settings */
32 public int back_scroll; /* Repaint screen on backwards movement */
33 public int forw_scroll; /* Repaint screen on forward movement */
34 public int caseless; /* Do "caseless" searches */
35 public int linenums; /* Use line numbers */
36 public int autobuf; /* Automatically allocate buffers as needed */
37 public int bufspace; /* Max buffer space per file (K) */
38 public int ctldisp; /* Send control chars to screen untranslated */
39 public int force_open; /* Open the file even if not regular file */
40 public int swindow; /* Size of scrolling window */
41 public int jump_sline; /* Screen line of "jump target" */
42 public long jump_sline_fraction = -1;
43 public long shift_count_fraction = -1;
44 public int chopline; /* Truncate displayed lines at screen width */
45 public int no_init; /* Disable sending ti/te termcap strings */
46 public int no_keypad; /* Disable sending ks/ke termcap strings */
47 public int twiddle; /* Show tildes after EOF */
48 public int show_attn; /* Hilite first unread line */
49 public int shift_count; /* Number of positions to shift horizontally */
50 public int status_col; /* Display a status column */
51 public int use_lessopen; /* Use the LESSOPEN filter */
52 public int quit_on_intr; /* Quit on interrupt */
53 public int follow_mode; /* F cmd Follows file desc or file name? */
54 public int oldbot; /* Old bottom of screen behavior {{REMOVE}} */
56 public int hilite_search; /* Highlight matched search patterns? */
59 public int less_is_more = 0; /* Make compatible with POSIX more */
64 static struct optname a_optname = { "search-skip-screen", NULL };
65 static struct optname b_optname = { "buffers", NULL };
66 static struct optname B__optname = { "auto-buffers", NULL };
67 static struct optname c_optname = { "clear-screen", NULL };
68 static struct optname d_optname = { "dumb", NULL };
70 static struct optname D__optname = { "color", NULL };
72 static struct optname e_optname = { "quit-at-eof", NULL };
73 static struct optname f_optname = { "force", NULL };
74 static struct optname F__optname = { "quit-if-one-screen", NULL };
76 static struct optname g_optname = { "hilite-search", NULL };
78 static struct optname h_optname = { "max-back-scroll", NULL };
79 static struct optname i_optname = { "ignore-case", NULL };
80 static struct optname j_optname = { "jump-target", NULL };
81 static struct optname J__optname = { "status-column", NULL };
83 static struct optname k_optname = { "lesskey-file", NULL };
85 static struct optname K__optname = { "quit-on-intr", NULL };
86 static struct optname L__optname = { "no-lessopen", NULL };
87 static struct optname m_optname = { "long-prompt", NULL };
88 static struct optname n_optname = { "line-numbers", NULL };
90 static struct optname o_optname = { "log-file", NULL };
91 static struct optname O__optname = { "LOG-FILE", NULL };
93 static struct optname p_optname = { "pattern", NULL };
94 static struct optname P__optname = { "prompt", NULL };
95 static struct optname q2_optname = { "silent", NULL };
96 static struct optname q_optname = { "quiet", &q2_optname };
97 static struct optname r_optname = { "raw-control-chars", NULL };
98 static struct optname s_optname = { "squeeze-blank-lines", NULL };
99 static struct optname S__optname = { "chop-long-lines", NULL };
101 static struct optname t_optname = { "tag", NULL };
102 static struct optname T__optname = { "tag-file", NULL };
104 static struct optname u_optname = { "underline-special", NULL };
105 static struct optname V__optname = { "version", NULL };
106 static struct optname w_optname = { "hilite-unread", NULL };
107 static struct optname x_optname = { "tabs", NULL };
108 static struct optname X__optname = { "no-init", NULL };
109 static struct optname y_optname = { "max-forw-scroll", NULL };
110 static struct optname z_optname = { "window", NULL };
111 static struct optname quote_optname = { "quotes", NULL };
112 static struct optname tilde_optname = { "tilde", NULL };
113 static struct optname query_optname = { "help", NULL };
114 static struct optname pound_optname = { "shift", NULL };
115 static struct optname keypad_optname = { "no-keypad", NULL };
116 static struct optname oldbot_optname = { "old-bot", NULL };
117 static struct optname follow_optname = { "follow-name", NULL };
121 * Table of all options and their semantics.
123 * For BOOL and TRIPLE options, odesc[0], odesc[1], odesc[2] are
124 * the description of the option when set to 0, 1 or 2, respectively.
125 * For NUMBER options, odesc[0] is the prompt to use when entering
126 * a new value, and odesc[1] is the description, which should contain
127 * one %d which is replaced by the value of the number.
128 * For STRING options, odesc[0] is the prompt to use when entering
129 * a new value, and odesc[1], if not NULL, is the set of characters
130 * that are valid in the string.
132 static struct loption option[] =
135 TRIPLE, OPT_ONPLUS, &how_search, NULL,
137 "Search includes displayed screen",
138 "Search skips displayed screen",
139 "Search includes all of displayed screen"
144 NUMBER|INIT_HANDLER, 64, &bufspace, opt_b,
146 "Max buffer space per file (K): ",
147 "Max buffer space per file: %dK",
152 BOOL, OPT_ON, &autobuf, NULL,
154 "Don't automatically allocate buffers",
155 "Automatically allocate buffers when needed",
160 TRIPLE, OPT_OFF, &top_scroll, NULL,
162 "Repaint by scrolling from bottom of screen",
163 "Repaint by painting from top of screen",
164 "Repaint by painting from top of screen"
168 BOOL|NO_TOGGLE, OPT_OFF, &know_dumb, NULL,
170 "Assume intelligent terminal",
171 "Assume dumb terminal",
177 STRING|REPAINT|NO_QUERY, 0, NULL, opt_D,
186 TRIPLE, OPT_OFF, &quit_at_eof, NULL,
188 "Don't quit at end-of-file",
189 "Quit at end-of-file",
190 "Quit immediately at end-of-file"
194 BOOL, OPT_OFF, &force_open, NULL,
196 "Open only regular files",
197 "Open even non-regular files",
202 BOOL, OPT_OFF, &quit_if_one_screen, NULL,
204 "Don't quit if end-of-file on first screen",
205 "Quit if end-of-file on first screen",
211 TRIPLE|HL_REPAINT, OPT_ONPLUS, &hilite_search, NULL,
213 "Don't highlight search matches",
214 "Highlight matches for previous search only",
215 "Highlight all matches for previous search pattern",
220 NUMBER, -1, &back_scroll, NULL,
222 "Backwards scroll limit: ",
223 "Backwards scroll limit is %d lines",
228 TRIPLE|HL_REPAINT, OPT_OFF, &caseless, opt_i,
230 "Case is significant in searches",
231 "Ignore case in searches",
232 "Ignore case in searches and in patterns"
236 STRING, 0, NULL, opt_j,
244 BOOL|REPAINT, OPT_OFF, &status_col, NULL,
246 "Don't display a status column",
247 "Display a status column",
253 STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_k,
258 BOOL, OPT_OFF, &quit_on_intr, NULL,
260 "Interrupt (ctrl-C) returns to prompt",
261 "Interrupt (ctrl-C) exits less",
266 BOOL, OPT_ON, &use_lessopen, NULL,
268 "Don't use the LESSOPEN filter",
269 "Use the LESSOPEN filter",
274 TRIPLE, OPT_OFF, &pr_type, NULL,
282 TRIPLE|REPAINT, OPT_ON, &linenums, NULL,
284 "Don't use line numbers",
286 "Constantly display line numbers"
291 STRING, 0, NULL, opt_o,
292 { "log file: ", NULL, NULL }
295 STRING, 0, NULL, opt__O,
296 { "Log file: ", NULL, NULL }
300 STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_p,
304 STRING, 0, NULL, opt__P,
305 { "prompt: ", NULL, NULL }
308 TRIPLE, OPT_OFF, &quiet, NULL,
310 "Ring the bell for errors AND at eof/bof",
311 "Ring the bell for errors but not at eof/bof",
312 "Never ring the bell"
316 TRIPLE|REPAINT, OPT_OFF, &ctldisp, NULL,
318 "Display control characters as ^X",
319 "Display control characters directly",
320 "Display control characters directly, processing ANSI sequences"
324 BOOL|REPAINT, OPT_OFF, &squeeze, NULL,
326 "Display all blank lines",
327 "Squeeze multiple blank lines",
332 BOOL|REPAINT, OPT_OFF, &chopline, NULL,
341 STRING|NO_QUERY, 0, NULL, opt_t,
342 { "tag: ", NULL, NULL }
345 STRING, 0, NULL, opt__T,
346 { "tags file: ", NULL, NULL }
350 TRIPLE|REPAINT, OPT_OFF, &bs_mode, NULL,
352 "Display underlined text in underline mode",
353 "Backspaces cause overstrike",
354 "Print backspace as ^H"
358 NOVAR, 0, NULL, opt__V,
362 TRIPLE|REPAINT, OPT_OFF, &show_attn, NULL,
364 "Don't highlight first unread line",
365 "Highlight first unread line after forward-screen",
366 "Highlight first unread line after any forward movement",
370 STRING|REPAINT, 0, NULL, opt_x,
378 BOOL|NO_TOGGLE, OPT_OFF, &no_init, NULL,
380 "Send init/deinit strings to terminal",
381 "Don't use init/deinit strings",
386 NUMBER, -1, &forw_scroll, NULL,
388 "Forward scroll limit: ",
389 "Forward scroll limit is %d lines",
394 NUMBER, -1, &swindow, NULL,
396 "Scroll window size: ",
397 "Scroll window size is %d lines",
401 { '"', "e_optname,
402 STRING, 0, NULL, opt_quote,
403 { "quotes: ", NULL, NULL }
405 { '~', &tilde_optname,
406 BOOL|REPAINT, OPT_ON, &twiddle, NULL,
408 "Don't show tildes after end of file",
409 "Show tildes after end of file",
413 { '?', &query_optname,
414 NOVAR, 0, NULL, opt_query,
417 { '#', £_optname,
418 STRING, 0, NULL, opt_shift,
420 "Horizontal shift: ",
425 { OLETTER_NONE, &keypad_optname,
426 BOOL|NO_TOGGLE, OPT_OFF, &no_keypad, NULL,
429 "Don't use keypad mode",
433 { OLETTER_NONE, &oldbot_optname,
434 BOOL, OPT_OFF, &oldbot, NULL,
436 "Use new bottom of screen behavior",
437 "Use old bottom of screen behavior",
441 { OLETTER_NONE, &follow_optname,
442 BOOL, FOLLOW_DESC, &follow_mode, NULL,
444 "F command follows file descriptor",
445 "F command follows file name",
449 { '\0', NULL, NOVAR, 0, NULL, NULL, { NULL, NULL, NULL } }
454 * Initialize each option to its default value.
459 register struct loption *o;
462 p = lgetenv("LESS_IS_MORE");
463 if (p != NULL && *p != '\0')
466 for (o = option; o->oletter != '\0'; o++)
469 * Set each variable to its default.
472 *(o->ovar) = o->odefault;
473 if (o->otype & INIT_HANDLER)
474 (*(o->ofunc))(INIT, (char *) NULL);
479 * Find an option in the option table, given its option letter.
481 public struct loption *
485 register struct loption *o;
487 for (o = option; o->oletter != '\0'; o++)
491 if ((o->otype & TRIPLE) && ASCII_TO_UPPER(o->oletter) == c)
504 if (ASCII_IS_UPPER(c))
506 if (ASCII_IS_LOWER(c))
514 * Find an option in the option table, given its option name.
515 * p_optname is the (possibly partial) name to look for, and
516 * is updated to point after the matched name.
517 * p_oname if non-NULL is set to point to the full option name.
519 public struct loption *
520 findopt_name(p_optname, p_oname, p_err)
525 char *optname = *p_optname;
526 register struct loption *o;
527 register struct optname *oname;
530 struct loption *maxo = NULL;
531 struct optname *maxoname = NULL;
539 for (o = option; o->oletter != '\0'; o++)
542 * Check all names for this option.
544 for (oname = o->onames; oname != NULL; oname = oname->onext)
547 * Try normal match first (uppercase == 0),
548 * then, then if it's a TRIPLE option,
549 * try uppercase match (uppercase == 1).
551 for (uppercase = 0; uppercase <= 1; uppercase++)
553 len = sprefix(optname, oname->oname, uppercase);
554 if (len <= 0 || is_optchar(optname[len]))
557 * We didn't use all of the option name.
561 if (!exact && len == maxlen)
563 * Already had a partial match,
564 * and now there's another one that
565 * matches the same length.
568 else if (len > maxlen)
571 * Found a better match than
578 exact = (len == (int)strlen(oname->oname));
580 if (!(o->otype & TRIPLE))
588 * Name matched more than one option.
594 *p_optname = optname + maxlen;
596 *p_oname = maxoname == NULL ? NULL : maxoname->oname;