2
* Copyright (C) 1984-2000 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 */
51
public int hilite_search; /* Highlight matched search patterns? */
57
static struct optname a_optname = { "search-skip-screen", NULL };
58
static struct optname b_optname = { "buffers", NULL };
59
static struct optname B__optname = { "auto-buffers", NULL };
60
static struct optname c_optname = { "clear-screen", NULL };
61
static struct optname d_optname = { "dumb", NULL };
63
static struct optname D__optname = { "color", NULL };
65
static struct optname e_optname = { "quit-at-eof", NULL };
66
static struct optname f_optname = { "force", NULL };
67
static struct optname F__optname = { "quit-if-one-screen", NULL };
69
static struct optname g_optname = { "hilite-search", NULL };
71
static struct optname h_optname = { "max-back-scroll", NULL };
72
static struct optname i_optname = { "ignore-case", NULL };
73
static struct optname j_optname = { "jump-target", NULL };
74
static struct optname J__optname = { "status-column", NULL };
76
static struct optname k_optname = { "lesskey-file", NULL };
78
static struct optname m_optname = { "long-prompt", NULL };
79
static struct optname n_optname = { "line-numbers", NULL };
81
static struct optname o_optname = { "log-file", NULL };
82
static struct optname O__optname = { "LOG-FILE", NULL };
84
static struct optname p_optname = { "pattern", NULL };
85
static struct optname P__optname = { "prompt", NULL };
86
static struct optname q2_optname = { "silent", NULL };
87
static struct optname q_optname = { "quiet", &q2_optname };
88
static struct optname r_optname = { "raw-control-chars", NULL };
89
static struct optname s_optname = { "squeeze-blank-lines", NULL };
90
static struct optname S__optname = { "chop-long-lines", NULL };
92
static struct optname t_optname = { "tag", NULL };
93
static struct optname T__optname = { "tag-file", NULL };
95
static struct optname u_optname = { "underline-special", NULL };
96
static struct optname V__optname = { "version", NULL };
97
static struct optname w_optname = { "hilite-unread", NULL };
98
static struct optname x_optname = { "tabs", NULL };
99
static struct optname X__optname = { "no-init", NULL };
100
static struct optname y_optname = { "max-forw-scroll", NULL };
101
static struct optname z_optname = { "window", NULL };
102
static struct optname quote_optname = { "quotes", NULL };
103
static struct optname tilde_optname = { "tilde", NULL };
104
static struct optname query_optname = { "help", NULL };
105
static struct optname pound_optname = { "shift", NULL };
106
static struct optname keypad_optname = { "no-keypad", NULL };
110
* Table of all options and their semantics.
112
* For BOOL and TRIPLE options, odesc[0], odesc[1], odesc[2] are
113
* the description of the option when set to 0, 1 or 2, respectively.
114
* For NUMBER options, odesc[0] is the prompt to use when entering
115
* a new value, and odesc[1] is the description, which should contain
116
* one %d which is replaced by the value of the number.
117
* For STRING options, odesc[0] is the prompt to use when entering
118
* a new value, and odesc[1], if not NULL, is the set of characters
119
* that are valid in the string.
121
static struct loption option[] =
124
BOOL, OPT_OFF, &how_search, NULL,
125
"Search includes displayed screen",
126
"Search skips displayed screen",
131
NUMBER, 64, &bufspace, opt_b,
132
"Max buffer space per file (K): ",
133
"Max buffer space per file: %dK",
137
BOOL, OPT_ON, &autobuf, NULL,
138
"Don't automatically allocate buffers",
139
"Automatically allocate buffers when needed",
143
TRIPLE, OPT_OFF, &top_scroll, NULL,
144
"Repaint by scrolling from bottom of screen",
145
"Repaint by clearing each line",
146
"Repaint by painting from top of screen"
149
BOOL|NO_TOGGLE, OPT_OFF, &know_dumb, NULL,
150
"Assume intelligent terminal",
151
"Assume dumb terminal",
156
STRING|REPAINT|NO_QUERY, 0, NULL, opt_D,
158
"Ddknsu0123456789. ",
163
TRIPLE, OPT_OFF, &quit_at_eof, NULL,
164
"Don't quit at end-of-file",
165
"Quit at end-of-file",
166
"Quit immediately at end-of-file"
169
BOOL, OPT_OFF, &force_open, NULL,
170
"Open only regular files",
171
"Open even non-regular files",
175
BOOL, OPT_OFF, &quit_if_one_screen, NULL,
176
"Don't quit if end-of-file on first screen",
177
"Quit if end-of-file on first screen",
182
TRIPLE|HL_REPAINT, OPT_ONPLUS, &hilite_search, NULL,
183
"Don't highlight search matches",
184
"Highlight matches for previous search only",
185
"Highlight all matches for previous search pattern",
189
NUMBER, -1, &back_scroll, NULL,
190
"Backwards scroll limit: ",
191
"Backwards scroll limit is %d lines",
195
TRIPLE|HL_REPAINT, OPT_OFF, &caseless, opt_i,
196
"Case is significant in searches",
197
"Ignore case in searches",
198
"Ignore case in searches and in patterns"
201
NUMBER, 1, &jump_sline, NULL,
203
"Position target at screen line %d",
207
BOOL|REPAINT, OPT_OFF, &status_col, NULL,
208
"Don't display a status column",
209
"Display a status column",
214
STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_k,
219
STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_l,
223
TRIPLE, OPT_OFF, &pr_type, NULL,
229
TRIPLE|REPAINT, OPT_ON, &linenums, NULL,
230
"Don't use line numbers",
232
"Constantly display line numbers"
236
STRING, 0, NULL, opt_o,
237
"log file: ", NULL, NULL
240
STRING, 0, NULL, opt__O,
241
"Log file: ", NULL, NULL
245
STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_p,
249
STRING, 0, NULL, opt__P,
250
"prompt: ", NULL, NULL
253
TRIPLE, OPT_OFF, &quiet, NULL,
254
"Ring the bell for errors AND at eof/bof",
255
"Ring the bell for errors but not at eof/bof",
256
"Never ring the bell"
259
TRIPLE|REPAINT, OPT_OFF, &ctldisp, NULL,
260
"Display control characters as ^X",
261
"Display control characters directly",
262
"Display control characters directly, processing ANSI sequences"
265
BOOL|REPAINT, OPT_OFF, &squeeze, NULL,
266
"Display all blank lines",
267
"Squeeze multiple blank lines",
271
BOOL|REPAINT, OPT_OFF, &chopline, NULL,
278
STRING|NO_QUERY, 0, NULL, opt_t,
282
STRING, 0, NULL, opt__T,
283
"tags file: ", NULL, NULL
287
TRIPLE|REPAINT, OPT_OFF, &bs_mode, NULL,
288
"Display underlined text in underline mode",
289
"Backspaces cause overstrike",
290
"Print backspace as ^H"
293
NOVAR, 0, NULL, opt__V,
297
TRIPLE|REPAINT, OPT_OFF, &show_attn, NULL,
298
"Don't highlight first unread line",
299
"Highlight first unread line after forward-screen",
300
"Highlight first unread line after any forward movement",
303
STRING|REPAINT, 0, NULL, opt_x,
309
BOOL|NO_TOGGLE, OPT_OFF, &no_init, NULL,
310
"Send init/deinit strings to terminal",
311
"Don't use init/deinit strings",
315
NUMBER, -1, &forw_scroll, NULL,
316
"Forward scroll limit: ",
317
"Forward scroll limit is %d lines",
321
NUMBER, -1, &swindow, NULL,
322
"Scroll window size: ",
323
"Scroll window size is %d lines",
326
{ '"', "e_optname,
327
STRING, 0, NULL, opt_quote,
328
"quotes: ", NULL, NULL
330
{ '~', &tilde_optname,
331
BOOL|REPAINT, OPT_ON, &twiddle, NULL,
332
"Don't show tildes after end of file",
333
"Show tildes after end of file",
336
{ '?', &query_optname,
337
NOVAR, 0, NULL, opt_query,
340
{ '#', £_optname,
341
NUMBER, 0, &shift_count, NULL,
342
"Horizontal shift: ",
343
"Horizontal shift %d positions",
346
{ '.', &keypad_optname,
347
BOOL|NO_TOGGLE, OPT_OFF, &no_keypad, NULL,
349
"Don't use keypad mode",
352
{ '\0', NULL, NOVAR, 0, NULL, NULL, NULL, NULL, NULL }
357
* Initialize each option to its default value.
362
register struct loption *o;
364
for (o = option; o->oletter != '\0'; o++)
367
* Set each variable to its default.
370
*(o->ovar) = o->odefault;
375
* Find an option in the option table, given its option letter.
377
public struct loption *
381
register struct loption *o;
383
for (o = option; o->oletter != '\0'; o++)
387
if ((o->otype & TRIPLE) && toupper(o->oletter) == c)
394
* Find an option in the option table, given its option name.
395
* p_optname is the (possibly partial) name to look for, and
396
* is updated to point after the matched name.
397
* p_oname if non-NULL is set to point to the full option name.
399
public struct loption *
400
findopt_name(p_optname, p_oname, p_err)
405
char *optname = *p_optname;
406
register struct loption *o;
407
register struct optname *oname;
410
struct loption *maxo = NULL;
411
struct optname *maxoname = NULL;
419
for (o = option; o->oletter != '\0'; o++)
422
* Check all names for this option.
424
for (oname = o->onames; oname != NULL; oname = oname->onext)
427
* Try normal match first (uppercase == 0),
428
* then, then if it's a TRIPLE option,
429
* try uppercase match (uppercase == 1).
431
for (uppercase = 0; uppercase <= 1; uppercase++)
433
len = sprefix(optname, oname->oname, uppercase);
434
if (!exact && len == maxlen)
436
* Already had a partial match,
437
* and now there's another one that
438
* matches the same length.
441
else if (len > maxlen)
444
* Found a better match than
451
exact = (len == (int)strlen(oname->oname));
453
if (!(o->otype & TRIPLE))
461
* Name matched more than one option.
467
*p_optname = optname + maxlen;
469
*p_oname = maxoname->oname;