1 /* $NetBSD: opttbl.c,v 1.4 2013/09/04 19:44:21 tron Exp $ */
4 * Copyright (C) 1984-2012 Mark Nudelman
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Less License, as specified in the README file.
9 * For more information, see the README file.
21 * Variables controlled by command line options.
23 public int quiet
; /* Should we suppress the audible bell? */
24 public int how_search
; /* Where should forward searches start? */
25 public int top_scroll
; /* Repaint screen from top?
26 (alternative is scroll from bottom) */
27 public int pr_type
; /* Type of prompt (short, medium, long) */
28 public int bs_mode
; /* How to process backspaces */
29 public int know_dumb
; /* Don't complain about dumb terminals */
30 public int quit_at_eof
; /* Quit after hitting end of file twice */
31 public int quit_if_one_screen
; /* Quit if EOF on first screen */
32 public int be_helpful
; /* more(1) style -d */
33 public int squeeze
; /* Squeeze multiple blank lines into one */
34 public int tabstop
; /* Tab settings */
35 public int back_scroll
; /* Repaint screen on backwards movement */
36 public int forw_scroll
; /* Repaint screen on forward movement */
37 public int caseless
; /* Do "caseless" searches */
38 public int linenums
; /* Use line numbers */
39 public int autobuf
; /* Automatically allocate buffers as needed */
40 public int bufspace
; /* Max buffer space per file (K) */
41 public int ctldisp
; /* Send control chars to screen untranslated */
42 public int force_open
; /* Open the file even if not regular file */
43 public int swindow
; /* Size of scrolling window */
44 public int jump_sline
; /* Screen line of "jump target" */
45 public long jump_sline_fraction
= -1;
46 public long shift_count_fraction
= -1;
47 public int chopline
; /* Truncate displayed lines at screen width */
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 shift_count
; /* Number of positions to shift horizontally */
53 public int status_col
; /* Display a status column */
54 public int use_lessopen
; /* Use the LESSOPEN filter */
55 public int quit_on_intr
; /* Quit on interrupt */
56 public int follow_mode
; /* F cmd Follows file desc or file name? */
57 public int oldbot
; /* Old bottom of screen behavior {{REMOVE}} */
58 public int opt_use_backslash
; /* Use backslash escaping in option parsing */
60 public int hilite_search
; /* Highlight matched search patterns? */
63 public int less_is_more
= 0; /* Make compatible with POSIX more */
68 static struct optname a_optname
= { "search-skip-screen", NULL
};
69 static struct optname b_optname
= { "buffers", NULL
};
70 static struct optname B__optname
= { "auto-buffers", NULL
};
71 static struct optname c_optname
= { "clear-screen", NULL
};
72 static struct optname d_optname
= { "dumb", NULL
};
74 static struct optname D__optname
= { "color", NULL
};
76 static struct optname e_optname
= { "quit-at-eof", NULL
};
77 static struct optname f_optname
= { "force", NULL
};
78 static struct optname F__optname
= { "quit-if-one-screen", NULL
};
80 static struct optname g_optname
= { "hilite-search", NULL
};
82 static struct optname h_optname
= { "max-back-scroll", NULL
};
83 static struct optname i_optname
= { "ignore-case", NULL
};
84 static struct optname j_optname
= { "jump-target", NULL
};
85 static struct optname J__optname
= { "status-column", NULL
};
87 static struct optname k_optname
= { "lesskey-file", NULL
};
89 static struct optname K__optname
= { "quit-on-intr", NULL
};
90 static struct optname L__optname
= { "no-lessopen", NULL
};
91 static struct optname m_optname
= { "long-prompt", NULL
};
92 static struct optname n_optname
= { "line-numbers", NULL
};
94 static struct optname o_optname
= { "log-file", NULL
};
95 static struct optname O__optname
= { "LOG-FILE", NULL
};
97 static struct optname p_optname
= { "pattern", NULL
};
98 static struct optname P__optname
= { "prompt", NULL
};
99 static struct optname q2_optname
= { "silent", NULL
};
100 static struct optname q_optname
= { "quiet", &q2_optname
};
101 static struct optname r_optname
= { "raw-control-chars", NULL
};
102 static struct optname s_optname
= { "squeeze-blank-lines", NULL
};
103 static struct optname S__optname
= { "chop-long-lines", NULL
};
105 static struct optname t_optname
= { "tag", NULL
};
106 static struct optname T__optname
= { "tag-file", NULL
};
108 static struct optname u_optname
= { "underline-special", NULL
};
109 static struct optname V__optname
= { "version", NULL
};
110 static struct optname w_optname
= { "hilite-unread", NULL
};
111 static struct optname x_optname
= { "tabs", NULL
};
112 static struct optname X__optname
= { "no-init", NULL
};
113 static struct optname y_optname
= { "max-forw-scroll", NULL
};
114 static struct optname z_optname
= { "window", NULL
};
115 static struct optname quote_optname
= { "quotes", NULL
};
116 static struct optname tilde_optname
= { "tilde", NULL
};
117 static struct optname query_optname
= { "help", NULL
};
118 static struct optname pound_optname
= { "shift", NULL
};
119 static struct optname keypad_optname
= { "no-keypad", NULL
};
120 static struct optname oldbot_optname
= { "old-bot", NULL
};
121 static struct optname follow_optname
= { "follow-name", NULL
};
122 static struct optname use_backslash_optname
= { "use-backslash", NULL
};
126 * Table of all options and their semantics.
128 * For BOOL and TRIPLE options, odesc[0], odesc[1], odesc[2] are
129 * the description of the option when set to 0, 1 or 2, respectively.
130 * For NUMBER options, odesc[0] is the prompt to use when entering
131 * a new value, and odesc[1] is the description, which should contain
132 * one %d which is replaced by the value of the number.
133 * For STRING options, odesc[0] is the prompt to use when entering
134 * a new value, and odesc[1], if not NULL, is the set of characters
135 * that are valid in the string.
137 static struct loption option
[] =
140 TRIPLE
, OPT_ONPLUS
, &how_search
, NULL
,
142 "Search includes displayed screen",
143 "Search skips displayed screen",
144 "Search includes all of displayed screen"
149 NUMBER
|INIT_HANDLER
, 64, &bufspace
, opt_b
,
151 "Max buffer space per file (K): ",
152 "Max buffer space per file: %dK",
157 BOOL
, OPT_ON
, &autobuf
, NULL
,
159 "Don't automatically allocate buffers",
160 "Automatically allocate buffers when needed",
165 TRIPLE
, OPT_OFF
, &top_scroll
, NULL
,
167 "Repaint by scrolling from bottom of screen",
168 "Repaint by painting from top of screen",
169 "Repaint by painting from top of screen"
174 BOOL
, OPT_OFF
, &be_helpful
, NULL
,
175 { "Be less helpful in prompts",
176 "Be helpful in prompts",
181 BOOL
|NO_TOGGLE
, OPT_OFF
, &know_dumb
, NULL
,
183 "Assume intelligent terminal",
184 "Assume dumb terminal",
190 STRING
|REPAINT
|NO_QUERY
, 0, NULL
, opt_D
,
199 TRIPLE
, OPT_OFF
, &quit_at_eof
, NULL
,
201 "Don't quit at end-of-file",
202 "Quit at end-of-file",
203 "Quit immediately at end-of-file"
207 BOOL
, OPT_OFF
, &force_open
, NULL
,
209 "Open only regular files",
210 "Open even non-regular files",
215 BOOL
, OPT_OFF
, &quit_if_one_screen
, NULL
,
217 "Don't quit if end-of-file on first screen",
218 "Quit if end-of-file on first screen",
224 TRIPLE
|HL_REPAINT
, OPT_ONPLUS
, &hilite_search
, NULL
,
226 "Don't highlight search matches",
227 "Highlight matches for previous search only",
228 "Highlight all matches for previous search pattern",
233 NUMBER
, -1, &back_scroll
, NULL
,
235 "Backwards scroll limit: ",
236 "Backwards scroll limit is %d lines",
241 TRIPLE
|HL_REPAINT
, OPT_OFF
, &caseless
, opt_i
,
243 "Case is significant in searches",
244 "Ignore case in searches",
245 "Ignore case in searches and in patterns"
249 STRING
, 0, NULL
, opt_j
,
257 BOOL
|REPAINT
, OPT_OFF
, &status_col
, NULL
,
259 "Don't display a status column",
260 "Display a status column",
266 STRING
|NO_TOGGLE
|NO_QUERY
, 0, NULL
, opt_k
,
271 BOOL
, OPT_OFF
, &quit_on_intr
, NULL
,
273 "Interrupt (ctrl-C) returns to prompt",
274 "Interrupt (ctrl-C) exits less",
279 BOOL
, OPT_ON
, &use_lessopen
, NULL
,
281 "Don't use the LESSOPEN filter",
282 "Use the LESSOPEN filter",
287 TRIPLE
, OPT_OFF
, &pr_type
, NULL
,
295 TRIPLE
|REPAINT
, OPT_ON
, &linenums
, NULL
,
297 "Don't use line numbers",
299 "Constantly display line numbers"
304 STRING
, 0, NULL
, opt_o
,
305 { "log file: ", NULL
, NULL
}
308 STRING
, 0, NULL
, opt__O
,
309 { "Log file: ", NULL
, NULL
}
313 STRING
|NO_TOGGLE
|NO_QUERY
, 0, NULL
, opt_p
,
317 STRING
, 0, NULL
, opt__P
,
318 { "prompt: ", NULL
, NULL
}
321 TRIPLE
, OPT_OFF
, &quiet
, NULL
,
323 "Ring the bell for errors AND at eof/bof",
324 "Ring the bell for errors but not at eof/bof",
325 "Never ring the bell"
329 TRIPLE
|REPAINT
, OPT_OFF
, &ctldisp
, NULL
,
331 "Display control characters as ^X",
332 "Display control characters directly",
333 "Display control characters directly, processing ANSI sequences"
337 BOOL
|REPAINT
, OPT_OFF
, &squeeze
, NULL
,
339 "Display all blank lines",
340 "Squeeze multiple blank lines",
345 BOOL
|REPAINT
, OPT_OFF
, &chopline
, NULL
,
354 STRING
|NO_QUERY
, 0, NULL
, opt_t
,
355 { "tag: ", NULL
, NULL
}
358 STRING
, 0, NULL
, opt__T
,
359 { "tags file: ", NULL
, NULL
}
363 TRIPLE
|REPAINT
, OPT_OFF
, &bs_mode
, NULL
,
365 "Display underlined text in underline mode",
366 "Backspaces cause overstrike",
367 "Print backspace as ^H"
371 NOVAR
, 0, NULL
, opt__V
,
375 TRIPLE
|REPAINT
, OPT_OFF
, &show_attn
, NULL
,
377 "Don't highlight first unread line",
378 "Highlight first unread line after forward-screen",
379 "Highlight first unread line after any forward movement",
383 STRING
|REPAINT
, 0, NULL
, opt_x
,
391 BOOL
|NO_TOGGLE
, OPT_OFF
, &no_init
, NULL
,
393 "Send init/deinit strings to terminal",
394 "Don't use init/deinit strings",
399 NUMBER
, -1, &forw_scroll
, NULL
,
401 "Forward scroll limit: ",
402 "Forward scroll limit is %d lines",
407 NUMBER
, -1, &swindow
, NULL
,
409 "Scroll window size: ",
410 "Scroll window size is %d lines",
414 { '"', "e_optname
,
415 STRING
, 0, NULL
, opt_quote
,
416 { "quotes: ", NULL
, NULL
}
418 { '~', &tilde_optname
,
419 BOOL
|REPAINT
, OPT_ON
, &twiddle
, NULL
,
421 "Don't show tildes after end of file",
422 "Show tildes after end of file",
426 { '?', &query_optname
,
427 NOVAR
, 0, NULL
, opt_query
,
430 { '#', £_optname
,
431 STRING
, 0, NULL
, opt_shift
,
433 "Horizontal shift: ",
438 { OLETTER_NONE
, &keypad_optname
,
439 BOOL
|NO_TOGGLE
, OPT_OFF
, &no_keypad
, NULL
,
442 "Don't use keypad mode",
446 { OLETTER_NONE
, &oldbot_optname
,
447 BOOL
, OPT_OFF
, &oldbot
, NULL
,
449 "Use new bottom of screen behavior",
450 "Use old bottom of screen behavior",
454 { OLETTER_NONE
, &follow_optname
,
455 BOOL
, FOLLOW_DESC
, &follow_mode
, NULL
,
457 "F command follows file descriptor",
458 "F command follows file name",
462 { OLETTER_NONE
, &use_backslash_optname
,
463 BOOL
, OPT_OFF
, &opt_use_backslash
, NULL
,
465 "Use backslash escaping in command line parameters",
466 "Don't use backslash escaping in command line parameters",
470 { '\0', NULL
, NOVAR
, 0, NULL
, NULL
, { NULL
, NULL
, NULL
} }
475 * Initialize each option to its default value.
480 register struct loption
*o
;
483 p
= lgetenv("LESS_IS_MORE");
484 if (p
!= NULL
&& *p
!= '\0')
487 for (o
= option
; o
->oletter
!= '\0'; o
++)
490 * Set each variable to its default.
493 *(o
->ovar
) = o
->odefault
;
494 if (o
->otype
& INIT_HANDLER
)
495 (*(o
->ofunc
))(INIT
, (char *) NULL
);
500 * Find an option in the option table, given its option letter.
502 public struct loption
*
506 register struct loption
*o
;
508 for (o
= option
; o
->oletter
!= '\0'; o
++)
512 if ((o
->otype
& TRIPLE
) && ASCII_TO_UPPER(o
->oletter
) == c
)
525 if (ASCII_IS_UPPER(c
))
527 if (ASCII_IS_LOWER(c
))
535 * Find an option in the option table, given its option name.
536 * p_optname is the (possibly partial) name to look for, and
537 * is updated to point after the matched name.
538 * p_oname if non-NULL is set to point to the full option name.
540 public struct loption
*
541 findopt_name(p_optname
, p_oname
, p_err
)
546 char *optname
= *p_optname
;
547 register struct loption
*o
;
548 register struct optname
*oname
;
551 struct loption
*maxo
= NULL
;
552 struct optname
*maxoname
= NULL
;
560 for (o
= option
; o
->oletter
!= '\0'; o
++)
563 * Check all names for this option.
565 for (oname
= o
->onames
; oname
!= NULL
; oname
= oname
->onext
)
568 * Try normal match first (uppercase == 0),
569 * then, then if it's a TRIPLE option,
570 * try uppercase match (uppercase == 1).
572 for (uppercase
= 0; uppercase
<= 1; uppercase
++)
574 len
= sprefix(optname
, oname
->oname
, uppercase
);
575 if (len
<= 0 || is_optchar(optname
[len
]))
578 * We didn't use all of the option name.
582 if (!exact
&& len
== maxlen
)
584 * Already had a partial match,
585 * and now there's another one that
586 * matches the same length.
589 else if (len
> maxlen
)
592 * Found a better match than
599 exact
= (len
== (int)strlen(oname
->oname
));
601 if (!(o
->otype
& TRIPLE
))
609 * Name matched more than one option.
615 *p_optname
= optname
+ maxlen
;
617 *p_oname
= maxoname
== NULL
? NULL
: maxoname
->oname
;