1 /*
2 * Copyright (C) 1984-2024 Mark Nudelman
3 *
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.
6 *
7 * For more information, see the README file.
8 */
9
10
11 /*
12 * The option table.
13 */
14
15 #include "less.h"
16 #include "option.h"
17
18 /*
19 * Variables controlled by command line options.
20 */
21 public int quiet; /* Should we suppress the audible bell? */
22 public int no_vbell; /* Should we suppress the visual 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 long jump_sline_fraction = -1;
44 public int shift_count; /* Number of positions to shift horizontally */
45 public long shift_count_fraction = -1;
46 public int chopline; /* Truncate displayed lines at screen width */
47 public int wordwrap; /* Wrap lines at space */
48 public int no_init; /* Disable sending ti/te termcap strings */
49 public int no_keypad; /* Disable sending ks/ke termcap strings */
50 public int twiddle; /* Show tildes after EOF */
51 public int show_attn; /* Hilite first unread line */
52 public int status_col; /* Display a status column */
53 public int use_lessopen; /* Use the LESSOPEN filter */
54 public int quit_on_intr; /* Quit on interrupt */
55 public int follow_mode; /* F cmd Follows file desc or file name? */
56 public int oldbot; /* Old bottom of screen behavior {{REMOVE}} */
57 public int opt_use_backslash; /* Use backslash escaping in option parsing */
58 public LWCHAR rscroll_char; /* Char which marks chopped lines with -S */
59 public int rscroll_attr; /* Attribute of rscroll_char */
60 public int no_hist_dups; /* Remove dups from history list */
61 public int mousecap; /* Allow mouse for scrolling */
62 public int wheel_lines; /* Number of lines to scroll on mouse wheel scroll */
63 public int perma_marks; /* Save marks in history file */
64 public int linenum_width; /* Width of line numbers */
65 public int status_col_width; /* Width of status column */
66 public int incr_search; /* Incremental search */
67 public int use_color; /* Use UI color */
68 public int want_filesize; /* Scan to EOF if necessary to get file size */
69 public int status_line; /* Highlight entire marked lines */
70 public int header_lines; /* Freeze header lines at top of screen */
71 public int header_cols; /* Freeze header columns at left of screen */
72 public int nonum_headers; /* Don't give headers line numbers */
73 public int nosearch_header_lines = 0; /* Don't search in header lines */
74 public int nosearch_header_cols = 0; /* Don't search in header columns */
75 public int redraw_on_quit; /* Redraw last screen after term deinit */
76 public int def_search_type; /* */
77 public int exit_F_on_close; /* Exit F command when input closes */
78 public int modelines; /* Lines to read looking for modelines */
79 public int show_preproc_error; /* Display msg when preproc exits with error */
80 public int proc_backspace; /* Special handling of backspace */
81 public int proc_tab; /* Special handling of tab */
82 public int proc_return; /* Special handling of carriage return */
83 public int match_shift; /* Extra horizontal shift on search match */
84 public long match_shift_fraction = NUM_FRAC_DENOM/2; /* 1/2 of screen width */
85 public char intr_char = CONTROL('X'); /* Char to interrupt reads */
86 #if HILITE_SEARCH
87 public int hilite_search; /* Highlight matched search patterns? */
88 #endif
89
90 public int less_is_more = 0; /* Make compatible with POSIX more */
91
92 /*
93 * Long option names.
94 */
95 static struct optname a_optname = { "search-skip-screen", NULL };
96 static struct optname b_optname = { "buffers", NULL };
97 static struct optname B__optname = { "auto-buffers", NULL };
98 static struct optname c_optname = { "clear-screen", NULL };
99 static struct optname d_optname = { "dumb", NULL };
100 static struct optname D__optname = { "color", NULL };
101 static struct optname e_optname = { "quit-at-eof", NULL };
102 static struct optname f_optname = { "force", NULL };
103 static struct optname F__optname = { "quit-if-one-screen", NULL };
104 #if HILITE_SEARCH
105 static struct optname g_optname = { "hilite-search", NULL };
106 #endif
107 static struct optname h_optname = { "max-back-scroll", NULL };
108 static struct optname i_optname = { "ignore-case", NULL };
109 static struct optname j_optname = { "jump-target", NULL };
110 static struct optname J__optname = { "status-column", NULL };
111 #if USERFILE
112 static struct optname k_optname = { "lesskey-file", NULL };
113 #if HAVE_LESSKEYSRC
114 static struct optname ks_optname = { "lesskey-src", NULL };
115 static struct optname kc_optname = { "lesskey-content", NULL };
116 #endif /* HAVE_LESSKEYSRC */
117 #endif
118 static struct optname K__optname = { "quit-on-intr", NULL };
119 static struct optname L__optname = { "no-lessopen", NULL };
120 static struct optname m_optname = { "long-prompt", NULL };
121 static struct optname n_optname = { "line-numbers", NULL };
122 #if LOGFILE
123 static struct optname o_optname = { "log-file", NULL };
124 static struct optname O__optname = { "LOG-FILE", NULL };
125 #endif
126 static struct optname p_optname = { "pattern", NULL };
127 static struct optname P__optname = { "prompt", NULL };
128 static struct optname q2_optname = { "silent", NULL };
129 static struct optname q_optname = { "quiet", &q2_optname };
130 static struct optname r_optname = { "raw-control-chars", NULL };
131 static struct optname s_optname = { "squeeze-blank-lines", NULL };
132 static struct optname S__optname = { "chop-long-lines", NULL };
133 #if TAGS
134 static struct optname t_optname = { "tag", NULL };
135 static struct optname T__optname = { "tag-file", NULL };
136 #endif
137 static struct optname u_optname = { "underline-special", NULL };
138 static struct optname V__optname = { "version", NULL };
139 static struct optname w_optname = { "hilite-unread", NULL };
140 static struct optname x_optname = { "tabs", NULL };
141 static struct optname X__optname = { "no-init", NULL };
142 static struct optname y_optname = { "max-forw-scroll", NULL };
143 static struct optname z_optname = { "window", NULL };
144 static struct optname quote_optname = { "quotes", NULL };
145 static struct optname tilde_optname = { "tilde", NULL };
146 static struct optname query_optname = { "help", NULL };
147 static struct optname pound_optname = { "shift", NULL };
148 static struct optname keypad_optname = { "no-keypad", NULL };
149 static struct optname oldbot_optname = { "old-bot", NULL };
150 static struct optname follow_optname = { "follow-name", NULL };
151 static struct optname use_backslash_optname = { "use-backslash", NULL };
152 static struct optname rscroll_optname = { "rscroll", NULL };
153 static struct optname nohistdups_optname = { "no-histdups", NULL };
154 static struct optname mousecap_optname = { "mouse", NULL };
155 static struct optname wheel_lines_optname = { "wheel-lines", NULL };
156 static struct optname perma_marks_optname = { "save-marks", NULL };
157 static struct optname linenum_width_optname = { "line-num-width", NULL };
158 static struct optname status_col_width_optname = { "status-col-width", NULL };
159 static struct optname incr_search_optname = { "incsearch", NULL };
160 static struct optname use_color_optname = { "use-color", NULL };
161 static struct optname want_filesize_optname = { "file-size", NULL };
162 static struct optname status_line_optname = { "status-line", NULL };
163 static struct optname header_optname = { "header", NULL };
164 static struct optname nonum_headers_optname = { "no-number-headers", NULL };
165 static struct optname nosearch_headers_optname = { "no-search-headers", NULL };
166 static struct optname nosearch_header_lines_optname = { "no-search-header-lines", NULL };
167 static struct optname nosearch_header_cols_optname = { "no-search-header-columns", NULL };
168 static struct optname redraw_on_quit_optname = { "redraw-on-quit", NULL };
169 static struct optname search_type_optname = { "search-options", NULL };
170 static struct optname exit_F_on_close_optname = { "exit-follow-on-close", NULL };
171 static struct optname modelines_optname = { "modelines", NULL };
172 static struct optname no_vbell_optname = { "no-vbell", NULL };
173 static struct optname intr_optname = { "intr", NULL };
174 static struct optname wordwrap_optname = { "wordwrap", NULL };
175 static struct optname show_preproc_error_optname = { "show-preproc-errors", NULL };
176 static struct optname proc_backspace_optname = { "proc-backspace", NULL };
177 static struct optname proc_tab_optname = { "proc-tab", NULL };
178 static struct optname proc_return_optname = { "proc-return", NULL };
179 static struct optname match_shift_optname = { "match-shift", NULL };
180 #if LESSTEST
181 static struct optname ttyin_name_optname = { "tty", NULL };
182 #endif /*LESSTEST*/
183
184
185 /*
186 * Table of all options and their semantics.
187 *
188 * For BOOL and TRIPLE options, odesc[0], odesc[1], odesc[2] are
189 * the description of the option when set to 0, 1 or 2, respectively.
190 * For NUMBER options, odesc[0] is the prompt to use when entering
191 * a new value, and odesc[1] is the description, which should contain
192 * one %d which is replaced by the value of the number.
193 * For STRING options, odesc[0] is the prompt to use when entering
194 * a new value, and odesc[1], if not NULL, is the set of characters
195 * that are valid in the string.
196 */
197 static struct loption option[] =
198 {
199 { 'a', &a_optname,
200 TRIPLE, OPT_ONPLUS, &how_search, NULL,
201 {
202 "Search includes displayed screen",
203 "Search skips displayed screen",
204 "Search includes all of displayed screen"
205 }
206 },
207
208 { 'b', &b_optname,
209 NUMBER|INIT_HANDLER, 64, &bufspace, opt_b,
210 {
211 "Max buffer space per file (K): ",
212 "Max buffer space per file: %dK",
213 NULL
214 }
215 },
216 { 'B', &B__optname,
217 BOOL, OPT_ON, &autobuf, NULL,
218 {
219 "Don't automatically allocate buffers",
220 "Automatically allocate buffers when needed",
221 NULL
222 }
223 },
224 { 'c', &c_optname,
225 TRIPLE, OPT_OFF, &top_scroll, NULL,
226 {
227 "Repaint by scrolling from bottom of screen",
228 "Repaint by painting from top of screen",
229 "Repaint by painting from top of screen"
230 }
231 },
232 { 'd', &d_optname,
233 BOOL|NO_TOGGLE, OPT_OFF, &know_dumb, NULL,
234 {
235 "Assume intelligent terminal",
236 "Assume dumb terminal",
237 NULL
238 }
239 },
240 { 'D', &D__optname,
241 STRING|REPAINT|NO_QUERY, 0, NULL, opt_D,
242 { "color desc: ", "s", NULL }
243 },
244 { 'e', &e_optname,
245 TRIPLE, OPT_OFF, &quit_at_eof, NULL,
246 {
247 "Don't quit at end-of-file",
248 "Quit at end-of-file",
249 "Quit immediately at end-of-file"
250 }
251 },
252 { 'f', &f_optname,
253 BOOL, OPT_OFF, &force_open, NULL,
254 {
255 "Open only regular files",
256 "Open even non-regular files",
257 NULL
258 }
259 },
260 { 'F', &F__optname,
261 BOOL, OPT_OFF, &quit_if_one_screen, NULL,
262 {
263 "Don't quit if end-of-file on first screen",
264 "Quit if end-of-file on first screen",
265 NULL
266 }
267 },
268 #if HILITE_SEARCH
269 { 'g', &g_optname,
270 TRIPLE|HL_REPAINT, OPT_ONPLUS, &hilite_search, NULL,
271 {
272 "Don't highlight search matches",
273 "Highlight matches for previous search only",
274 "Highlight all matches for previous search pattern",
275 }
276 },
277 #endif
278 { 'h', &h_optname,
279 NUMBER, -1, &back_scroll, NULL,
280 {
281 "Backwards scroll limit: ",
282 "Backwards scroll limit is %d lines",
283 NULL
284 }
285 },
286 { 'i', &i_optname,
287 TRIPLE|HL_REPAINT, OPT_OFF, &caseless, opt_i,
288 {
289 "Case is significant in searches",
290 "Ignore case in searches",
291 "Ignore case in searches and in patterns"
292 }
293 },
294 { 'j', &j_optname,
295 STRING, 0, NULL, opt_j,
296 {
297 "Target line: ",
298 "-.d",
299 NULL
300 }
301 },
302 { 'J', &J__optname,
303 BOOL|REPAINT, OPT_OFF, &status_col, NULL,
304 {
305 "Don't display a status column",
306 "Display a status column",
307 NULL
308 }
309 },
310 #if USERFILE
311 { 'k', &k_optname,
312 STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_k,
313 { NULL, NULL, NULL }
314 },
315 #if HAVE_LESSKEYSRC
316 { OLETTER_NONE, &kc_optname,
317 STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_kc,
318 { NULL, NULL, NULL }
319 },
320 { OLETTER_NONE, &ks_optname,
321 STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_ks,
322 { NULL, NULL, NULL }
323 },
324 #endif /* HAVE_LESSKEYSRC */
325 #endif
326 { 'K', &K__optname,
327 BOOL, OPT_OFF, &quit_on_intr, NULL,
328 {
329 "Interrupt (ctrl-C) returns to prompt",
330 "Interrupt (ctrl-C) exits less",
331 NULL
332 }
333 },
334 { 'L', &L__optname,
335 BOOL, OPT_ON, &use_lessopen, NULL,
336 {
337 "Don't use the LESSOPEN filter",
338 "Use the LESSOPEN filter",
339 NULL
340 }
341 },
342 { 'm', &m_optname,
343 TRIPLE, OPT_OFF, &pr_type, NULL,
344 {
345 "Short prompt",
346 "Medium prompt",
347 "Long prompt"
348 }
349 },
350 { 'n', &n_optname,
351 TRIPLE|REPAINT, OPT_ON, &linenums, NULL,
352 {
353 "Don't use line numbers",
354 "Use line numbers",
355 "Constantly display line numbers"
356 }
357 },
358 #if LOGFILE
359 { 'o', &o_optname,
360 STRING, 0, NULL, opt_o,
361 { "log file: ", NULL, NULL }
362 },
363 { 'O', &O__optname,
364 STRING, 0, NULL, opt__O,
365 { "Log file: ", NULL, NULL }
366 },
367 #endif
368 { 'p', &p_optname,
369 STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_p,
370 { NULL, NULL, NULL }
371 },
372 { 'P', &P__optname,
373 STRING, 0, NULL, opt__P,
374 { "prompt: ", NULL, NULL }
375 },
376 { 'q', &q_optname,
377 TRIPLE, OPT_OFF, &quiet, NULL,
378 {
379 "Ring the bell for errors AND at eof/bof",
380 "Ring the bell for errors but not at eof/bof",
381 "Never ring the bell"
382 }
383 },
384 { 'r', &r_optname,
385 TRIPLE|REPAINT, OPT_OFF, &ctldisp, NULL,
386 {
387 "Display control characters as ^X",
388 "Display control characters directly (not recommended)",
389 "Display ANSI sequences directly, other control characters as ^X"
390 }
391 },
392 { 's', &s_optname,
393 BOOL|REPAINT, OPT_OFF, &squeeze, NULL,
394 {
395 "Display all blank lines",
396 "Squeeze multiple blank lines",
397 NULL
398 }
399 },
400 { 'S', &S__optname,
401 BOOL|REPAINT, OPT_OFF, &chopline, opt__S,
402 {
403 "Fold long lines",
404 "Chop long lines",
405 NULL
406 }
407 },
408 #if TAGS
409 { 't', &t_optname,
410 STRING|NO_QUERY, 0, NULL, opt_t,
411 { "tag: ", NULL, NULL }
412 },
413 { 'T', &T__optname,
414 STRING, 0, NULL, opt__T,
415 { "tags file: ", NULL, NULL }
416 },
417 #endif
418 { 'u', &u_optname,
419 TRIPLE|REPAINT|HL_REPAINT, OPT_OFF, &bs_mode, NULL,
420 {
421 "Display underlined text in underline mode",
422 "Backspaces cause overstrike",
423 "Print backspace as ^H"
424 }
425 },
426 { 'V', &V__optname,
427 NOVAR, 0, NULL, opt__V,
428 { NULL, NULL, NULL }
429 },
430 { 'w', &w_optname,
431 TRIPLE|REPAINT, OPT_OFF, &show_attn, NULL,
432 {
433 "Don't highlight first unread line",
434 "Highlight first unread line after forward-screen",
435 "Highlight first unread line after any forward movement",
436 }
437 },
438 { 'x', &x_optname,
439 STRING|REPAINT, 0, NULL, opt_x,
440 {
441 "Tab stops: ",
442 "d,",
443 NULL
444 }
445 },
446 { 'X', &X__optname,
447 BOOL|NO_TOGGLE, OPT_OFF, &no_init, NULL,
448 {
449 "Send init/deinit strings to terminal",
450 "Don't use init/deinit strings",
451 NULL
452 }
453 },
454 { 'y', &y_optname,
455 NUMBER, -1, &forw_scroll, NULL,
456 {
457 "Forward scroll limit: ",
458 "Forward scroll limit is %d lines",
459 NULL
460 }
461 },
462 { 'z', &z_optname,
463 NUMBER, -1, &swindow, NULL,
464 {
465 "Scroll window size: ",
466 "Scroll window size is %d lines",
467 NULL
468 }
469 },
470 { '"', "e_optname,
471 STRING, 0, NULL, opt_quote,
472 { "quotes: ", "s", NULL }
473 },
474 { '~', &tilde_optname,
475 BOOL|REPAINT, OPT_ON, &twiddle, NULL,
476 {
477 "Don't show tildes after end of file",
478 "Show tildes after end of file",
479 NULL
480 }
481 },
482 { '?', &query_optname,
483 NOVAR, 0, NULL, opt_query,
484 { NULL, NULL, NULL }
485 },
486 { '#', £_optname,
487 STRING, 0, NULL, opt_shift,
488 {
489 "Horizontal shift: ",
490 ".d",
491 NULL
492 }
493 },
494 { OLETTER_NONE, &keypad_optname,
495 BOOL|NO_TOGGLE, OPT_OFF, &no_keypad, NULL,
496 {
497 "Use keypad mode",
498 "Don't use keypad mode",
499 NULL
500 }
501 },
502 { OLETTER_NONE, &oldbot_optname,
503 BOOL, OPT_OFF, &oldbot, NULL,
504 {
505 "Use new bottom of screen behavior",
506 "Use old bottom of screen behavior",
507 NULL
508 }
509 },
510 { OLETTER_NONE, &follow_optname,
511 BOOL, FOLLOW_DESC, &follow_mode, NULL,
512 {
513 "F command follows file descriptor",
514 "F command follows file name",
515 NULL
516 }
517 },
518 { OLETTER_NONE, &use_backslash_optname,
519 BOOL, OPT_OFF, &opt_use_backslash, NULL,
520 {
521 "Use backslash escaping in command line parameters",
522 "Don't use backslash escaping in command line parameters",
523 NULL
524 }
525 },
526 { OLETTER_NONE, &rscroll_optname,
527 STRING|REPAINT|INIT_HANDLER, 0, NULL, opt_rscroll,
528 { "rscroll character: ", "s", NULL }
529 },
530 { OLETTER_NONE, &nohistdups_optname,
531 BOOL, OPT_OFF, &no_hist_dups, NULL,
532 {
533 "Allow duplicates in history list",
534 "Remove duplicates from history list",
535 NULL
536 }
537 },
538 { OLETTER_NONE, &mousecap_optname,
539 TRIPLE, OPT_OFF, &mousecap, opt_mousecap,
540 {
541 "Ignore mouse input",
542 "Use the mouse for scrolling",
543 "Use the mouse for scrolling (reverse)"
544 }
545 },
546 { OLETTER_NONE, &wheel_lines_optname,
547 NUMBER|INIT_HANDLER, 0, &wheel_lines, opt_wheel_lines,
548 {
549 "Lines to scroll on mouse wheel: ",
550 "Scroll %d line(s) on mouse wheel",
551 NULL
552 }
553 },
554 { OLETTER_NONE, &perma_marks_optname,
555 BOOL, OPT_OFF, &perma_marks, NULL,
556 {
557 "Don't save marks in history file",
558 "Save marks in history file",
559 NULL
560 }
561 },
562 { OLETTER_NONE, &linenum_width_optname,
563 NUMBER|REPAINT, MIN_LINENUM_WIDTH, &linenum_width, opt_linenum_width,
564 {
565 "Line number width: ",
566 "Line number width is %d chars",
567 NULL
568 }
569 },
570 { OLETTER_NONE, &status_col_width_optname,
571 NUMBER|REPAINT, 2, &status_col_width, opt_status_col_width,
572 {
573 "Status column width: ",
574 "Status column width is %d chars",
575 NULL
576 }
577 },
578 { OLETTER_NONE, &incr_search_optname,
579 BOOL, OPT_OFF, &incr_search, NULL,
580 {
581 "Incremental search is off",
582 "Incremental search is on",
583 NULL
584 }
585 },
586 { OLETTER_NONE, &use_color_optname,
587 BOOL|REPAINT, OPT_OFF, &use_color, NULL,
588 {
589 "Don't use color",
590 "Use color",
591 NULL
592 }
593 },
594 { OLETTER_NONE, &want_filesize_optname,
595 BOOL|REPAINT, OPT_OFF, &want_filesize, opt_filesize,
596 {
597 "Don't get size of each file",
598 "Get size of each file",
599 NULL
600 }
601 },
602 { OLETTER_NONE, &status_line_optname,
603 BOOL|REPAINT, OPT_OFF, &status_line, NULL,
604 {
605 "Don't color each line with its status column color",
606 "Color each line with its status column color",
607 NULL
608 }
609 },
610 { OLETTER_NONE, &header_optname,
611 STRING|REPAINT, 0, NULL, opt_header,
612 { "Header lines: ", "d,", NULL }
613 },
614 { OLETTER_NONE, &nonum_headers_optname,
615 BOOL|REPAINT, 0, &nonum_headers, NULL,
616 {
617 "Number header lines",
618 "Don't number header lines",
619 NULL
620 }
621 },
622 { OLETTER_NONE, &nosearch_headers_optname,
623 BOOL|HL_REPAINT, 0, NULL, opt_nosearch_headers,
624 {
625 NULL, NULL, NULL
626 }
627 },
628 { OLETTER_NONE, &nosearch_header_lines_optname,
629 BOOL|HL_REPAINT, 0, NULL, opt_nosearch_header_lines,
630 {
631 NULL, NULL, NULL
632 }
633 },
634 { OLETTER_NONE, &nosearch_header_cols_optname,
635 BOOL|HL_REPAINT, 0, NULL, opt_nosearch_header_cols,
636 {
637 NULL, NULL, NULL
638 }
639 },
640 { OLETTER_NONE, &redraw_on_quit_optname,
641 BOOL, OPT_OFF, &redraw_on_quit, NULL,
642 {
643 "Don't redraw screen when quitting",
644 "Redraw last screen when quitting",
645 NULL
646 }
647 },
648 { OLETTER_NONE, &search_type_optname,
649 STRING, 0, NULL, opt_search_type,
650 { "Search options: ", "s", NULL }
651 },
652 { OLETTER_NONE, &exit_F_on_close_optname,
653 BOOL, OPT_OFF, &exit_F_on_close, NULL,
654 {
655 "Don't exit F command when input closes",
656 "Exit F command when input closes",
657 NULL
658 }
659 },
660 { OLETTER_NONE, &no_vbell_optname,
661 BOOL, OPT_OFF, &no_vbell, NULL,
662 {
663 "Display visual bell",
664 "Don't display visual bell",
665 NULL
666 }
667 },
668 { OLETTER_NONE, &modelines_optname,
669 NUMBER, 0, &modelines, NULL,
670 {
671 "Lines to read looking for modelines: ",
672 "Read %d lines looking for modelines",
673 NULL
674 }
675 },
676 { OLETTER_NONE, &intr_optname,
677 STRING, 0, NULL, opt_intr,
678 { "interrupt character: ", "s", NULL }
679 },
680 { OLETTER_NONE, &wordwrap_optname,
681 BOOL|REPAINT, OPT_OFF, &wordwrap, NULL,
682 {
683 "Wrap lines at any character",
684 "Wrap lines at spaces",
685 NULL
686 }
687 },
688 { OLETTER_NONE, &show_preproc_error_optname,
689 BOOL, OPT_OFF, &show_preproc_error, NULL,
690 {
691 "Don't show error message if preprocessor fails",
692 "Show error message if preprocessor fails",
693 NULL
694 }
695 },
696 { OLETTER_NONE, &proc_backspace_optname,
697 TRIPLE|REPAINT|HL_REPAINT, OPT_OFF, &proc_backspace, NULL,
698 {
699 "Backspace handling is specified by the -U option",
700 "Display underline text in underline mode",
701 "Print backspaces as ^H"
702 }
703 },
704 { OLETTER_NONE, &proc_tab_optname,
705 TRIPLE|REPAINT|HL_REPAINT, OPT_OFF, &proc_tab, NULL,
706 {
707 "Tab handling is specified by the -U option",
708 "Expand tabs to spaces",
709 "Print tabs as ^I"
710 }
711 },
712 { OLETTER_NONE, &proc_return_optname,
713 TRIPLE|REPAINT|HL_REPAINT, OPT_OFF, &proc_return, NULL,
714 {
715 "Carriage return handling is specified by the -U option",
716 "Delete carriage return before newline",
717 "Print carriage return as ^M"
718 }
719 },
720 { OLETTER_NONE, &match_shift_optname,
721 STRING|INIT_HANDLER, 0, NULL, opt_match_shift,
722 {
723 "Search match shift: ",
724 ".d",
725 NULL
726 }
727 },
728 #if LESSTEST
729 { OLETTER_NONE, &ttyin_name_optname,
730 STRING|NO_TOGGLE, 0, NULL, opt_ttyin_name,
731 {
732 NULL,
733 NULL,
734 NULL
735 }
736 },
737 #endif /*LESSTEST*/
738 { '\0', NULL, NOVAR, 0, NULL, NULL, { NULL, NULL, NULL } }
739 };
740
741
742 /*
743 * Initialize each option to its default value.
744 */
init_option(void)745 public void init_option(void)
746 {
747 struct loption *o;
748 constant char *p;
749
750 p = lgetenv("LESS_IS_MORE");
751 if (!isnullenv(p))
752 less_is_more = 1;
753
754 for (o = option; o->oletter != '\0'; o++)
755 {
756 /*
757 * Set each variable to its default.
758 */
759 if (o->ovar != NULL)
760 *(o->ovar) = o->odefault;
761 if (o->otype & INIT_HANDLER)
762 (*(o->ofunc))(INIT, (char *) NULL);
763 }
764 }
765
766 /*
767 * Find an option in the option table, given its option letter.
768 */
findopt(int c)769 public struct loption * findopt(int c)
770 {
771 struct loption *o;
772
773 for (o = option; o->oletter != '\0'; o++)
774 {
775 if (o->oletter == c)
776 return (o);
777 if ((o->otype & TRIPLE) && ASCII_TO_UPPER(o->oletter) == c)
778 return (o);
779 }
780 return (NULL);
781 }
782
783 /*
784 *
785 */
is_optchar(char c)786 static lbool is_optchar(char c)
787 {
788 if (ASCII_IS_UPPER(c))
789 return TRUE;
790 if (ASCII_IS_LOWER(c))
791 return TRUE;
792 if (c == '-')
793 return TRUE;
794 return FALSE;
795 }
796
797 /*
798 * Find an option in the option table, given its option name.
799 * p_optname is the (possibly partial) name to look for, and
800 * is updated to point after the matched name.
801 * p_oname if non-NULL is set to point to the full option name.
802 */
findopt_name(constant char ** p_optname,constant char ** p_oname,lbool * p_ambig)803 public struct loption * findopt_name(constant char **p_optname, constant char **p_oname, lbool *p_ambig)
804 {
805 constant char *optname = *p_optname;
806 struct loption *o;
807 struct optname *oname;
808 size_t len;
809 int uppercase;
810 struct loption *maxo = NULL;
811 struct optname *maxoname = NULL;
812 size_t maxlen = 0;
813 lbool ambig = FALSE;
814 lbool exact = FALSE;
815
816 /*
817 * Check all options.
818 */
819 for (o = option; o->oletter != '\0'; o++)
820 {
821 /*
822 * Check all names for this option.
823 */
824 for (oname = o->onames; oname != NULL; oname = oname->onext)
825 {
826 /*
827 * Try normal match first (uppercase == 0),
828 * then, then if it's a TRIPLE option,
829 * try uppercase match (uppercase == 1).
830 */
831 for (uppercase = 0; uppercase <= 1; uppercase++)
832 {
833 len = sprefix(optname, oname->oname, uppercase);
834 if (len == 0 || is_optchar(optname[len]))
835 {
836 /*
837 * We didn't use all of the option name.
838 */
839 continue;
840 }
841 if (!exact && len == maxlen)
842 /*
843 * Already had a partial match,
844 * and now there's another one that
845 * matches the same length.
846 */
847 ambig = TRUE;
848 else if (len > maxlen)
849 {
850 /*
851 * Found a better match than
852 * the one we had.
853 */
854 maxo = o;
855 maxoname = oname;
856 maxlen = len;
857 ambig = FALSE;
858 exact = (len == strlen(oname->oname));
859 }
860 if (!(o->otype & TRIPLE))
861 break;
862 }
863 }
864 }
865 if (p_ambig != NULL)
866 *p_ambig = ambig;
867 if (ambig)
868 {
869 /*
870 * Name matched more than one option.
871 */
872 return (NULL);
873 }
874 *p_optname = optname + maxlen;
875 if (p_oname != NULL)
876 *p_oname = maxoname == NULL ? NULL : maxoname->oname;
877 return (maxo);
878 }
879