Annotation of src/usr.bin/less/opttbl.c, Revision 1.3
1.1 etheisen 1: /*
2: * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: * 1. Redistributions of source code must retain the above copyright
9: * notice, this list of conditions and the following disclaimer.
10: * 2. Redistributions in binary form must reproduce the above copyright
11: * notice in the documentation and/or other materials provided with
12: * the distribution.
13: *
14: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
15: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
18: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
20: * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
21: * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24: * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25: */
26:
27:
28: /*
29: * The option table.
30: */
31:
32: #include "less.h"
33: #include "option.h"
34:
35: /*
36: * Variables controlled by command line options.
37: */
38: public int quiet; /* Should we suppress the audible bell? */
39: public int how_search; /* Where should forward searches start? */
40: public int top_scroll; /* Repaint screen from top?
41: (alternative is scroll from bottom) */
42: public int pr_type; /* Type of prompt (short, medium, long) */
43: public int bs_mode; /* How to process backspaces */
44: public int know_dumb; /* Don't complain about dumb terminals */
45: public int quit_at_eof; /* Quit after hitting end of file twice */
1.2 etheisen 46: public int be_helpful; /* more(1) style -d */
1.1 etheisen 47: public int squeeze; /* Squeeze multiple blank lines into one */
48: public int tabstop; /* Tab settings */
49: public int back_scroll; /* Repaint screen on backwards movement */
50: public int forw_scroll; /* Repaint screen on forward movement */
51: public int twiddle; /* Display "~" for lines after EOF */
52: public int caseless; /* Do "caseless" searches */
53: public int linenums; /* Use line numbers */
54: public int cbufs; /* Current number of buffers */
55: public int autobuf; /* Automatically allocate buffers as needed */
56: public int nohelp; /* Disable the HELP command */
57: public int ctldisp; /* Send control chars to screen untranslated */
58: public int force_open; /* Open the file even if not regular file */
59: public int swindow; /* Size of scrolling window */
60: public int jump_sline; /* Screen line of "jump target" */
61: public int chopline; /* Truncate displayed lines at screen width */
62: public int no_init; /* Disable sending ti/te termcap strings */
63: #if HILITE_SEARCH
64: public int hilite_search; /* Highlight matched search patterns? */
65: #endif
66:
67: /*
68: * Table of all options and their semantics.
69: */
70: static struct option option[] =
71: {
72: { 'a', BOOL, OPT_OFF, &how_search, NULL,
73: "Search includes displayed screen",
74: "Search skips displayed screen",
75: NULL
76: },
77: { 'b', NUMBER, 10, &cbufs, opt_b,
78: "Buffers: ",
79: "%d buffers",
80: NULL
81: },
82: { 'B', BOOL, OPT_ON, &autobuf, NULL,
83: "Don't automatically allocate buffers",
84: "Automatically allocate buffers when needed",
85: NULL
86: },
87: { 'c', TRIPLE, OPT_OFF, &top_scroll, NULL,
88: "Repaint by scrolling from bottom of screen",
89: "Repaint by clearing each line",
90: "Repaint by painting from top of screen"
91: },
1.2 etheisen 92: #if 0
1.1 etheisen 93: { 'd', BOOL|NO_TOGGLE, OPT_OFF, &know_dumb, NULL,
94: "Assume intelligent terminal",
95: "Assume dumb terminal",
96: NULL
97: },
1.2 etheisen 98: #else
99: { 'd', BOOL, OPT_OFF, &be_helpful, NULL,
1.3 ! deraadt 100: "Be less helpful in prompts",
1.2 etheisen 101: "Be helpful in prompts",
102: NULL,
103: },
104: #endif
1.1 etheisen 105: #if MSOFTC
106: { 'D', STRING|REPAINT, 0, NULL, opt_D,
107: "color desc: ", NULL, NULL
108: },
109: #endif
110: { 'e', TRIPLE, OPT_OFF, &quit_at_eof, NULL,
111: "Don't quit at end-of-file",
112: "Quit at end-of-file",
113: "Quit immediately at end-of-file"
114: },
115: { 'f', BOOL, OPT_OFF, &force_open, NULL,
116: "Open only regular files",
117: "Open even non-regular files",
118: NULL
119: },
120: #if HILITE_SEARCH
121: { 'g', TRIPLE|HL_REPAINT, OPT_ONPLUS, &hilite_search, NULL,
122: "Don't highlight search matches",
123: "Highlight matches for previous search only",
124: "Highlight all matches for previous search pattern",
125: },
126: #endif
127: { 'h', NUMBER, -1, &back_scroll, NULL,
128: "Backwards scroll limit: ",
129: "Backwards scroll limit is %d lines",
130: NULL
131: },
132: { 'H', BOOL|NO_TOGGLE, OPT_OFF, &nohelp, NULL,
133: "Allow help command",
134: "Don't allow help command",
135: NULL
136: },
137: { 'i', TRIPLE|HL_REPAINT, OPT_OFF, &caseless, opt_i,
138: "Case is significant in searches",
139: "Ignore case in searches",
140: "Ignore case in searches and in patterns"
141: },
142: { 'j', NUMBER, 1, &jump_sline, NULL,
143: "Target line: ",
144: "Position target at screen line %d",
145: NULL
146: },
147: #if USERFILE
148: { 'k', STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_k,
149: NULL, NULL, NULL
150: },
151: #endif
152: { 'l', STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_l,
153: NULL, NULL, NULL
154: },
155: { 'm', TRIPLE, OPT_OFF, &pr_type, NULL,
156: "Short prompt",
157: "Medium prompt",
158: "Long prompt"
159: },
160: { 'n', TRIPLE|REPAINT, OPT_ON, &linenums, NULL,
161: "Don't use line numbers",
162: "Use line numbers",
163: "Constantly display line numbers"
164: },
165: #if LOGFILE
166: { 'o', STRING, 0, NULL, opt_o,
167: "log file: ", NULL, NULL
168: },
169: { 'O', STRING, 0, NULL, opt__O,
170: "Log file: ", NULL, NULL
171: },
172: #endif
173: { 'p', STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_p,
174: NULL, NULL, NULL
175: },
176: { 'P', STRING, 0, NULL, opt__P,
177: "prompt: ", NULL, NULL
178: },
179: { 'q', TRIPLE, OPT_OFF, &quiet, NULL,
180: "Ring the bell for errors AND at eof/bof",
181: "Ring the bell for errors but not at eof/bof",
182: "Never ring the bell"
183: },
184: { 'r', BOOL|REPAINT, OPT_ON, &ctldisp, NULL,
185: "Display control characters directly",
186: "Display control characters as ^X",
187: NULL
188: },
189: { 's', BOOL|REPAINT, OPT_OFF, &squeeze, NULL,
190: "Display all blank lines",
191: "Squeeze multiple blank lines",
192: NULL
193: },
194: { 'S', BOOL|REPAINT, OPT_OFF, &chopline, NULL,
195: "Fold long lines",
196: "Chop long lines",
197: NULL
198: },
199: #if TAGS
200: { 't', STRING|NO_QUERY, 0, NULL, opt_t,
201: "tag: ", NULL, NULL
202: },
203: { 'T', STRING, 0, NULL, opt__T,
204: "tags file: ", NULL, NULL
205: },
206: #endif
207: { 'u', TRIPLE|REPAINT, OPT_OFF, &bs_mode, NULL,
208: "Display underlined text in underline mode",
209: "Backspaces cause overstrike",
210: "Print backspace as ^H"
211: },
212: { 'V', NOVAR, 0, NULL, opt__V,
213: NULL, NULL, NULL
214: },
215: { 'w', BOOL|REPAINT, OPT_ON, &twiddle, NULL,
216: "Display nothing for lines after end-of-file",
217: "Display ~ for lines after end-of-file",
218: NULL
219: },
220: { 'x', NUMBER|REPAINT, 8, &tabstop, NULL,
221: "Tab stops: ",
222: "Tab stops every %d spaces",
223: NULL
224: },
225: { 'X', BOOL|NO_TOGGLE, OPT_OFF, &no_init, NULL,
226: "Send init/deinit strings to terminal",
227: "Don't use init/deinit strings",
228: NULL
229: },
230: { 'y', NUMBER, -1, &forw_scroll, NULL,
231: "Forward scroll limit: ",
232: "Forward scroll limit is %d lines",
233: NULL
234: },
235: { 'z', NUMBER, -1, &swindow, NULL,
236: "Scroll window size: ",
237: "Scroll window size is %d lines",
238: NULL
239: },
240: { '?', NOVAR, 0, NULL, opt_query,
241: NULL, NULL, NULL
242: },
243: { '\0' }
244: };
245:
246:
247: /*
248: * Initialize each option to its default value.
249: */
250: public void
251: init_option()
252: {
253: register struct option *o;
254:
255: for (o = option; o->oletter != '\0'; o++)
256: {
257: /*
258: * Set each variable to its default.
259: */
260: if (o->ovar != NULL)
261: *(o->ovar) = o->odefault;
262: }
263: }
264:
265: /*
266: * Find an option in the option table.
267: */
268: public struct option *
269: findopt(c)
270: int c;
271: {
272: register struct option *o;
273:
274: for (o = option; o->oletter != '\0'; o++)
275: {
276: if (o->oletter == c)
277: return (o);
278: if ((o->otype & TRIPLE) && toupper(o->oletter) == c)
279: return (o);
280: }
281: return (NULL);
282: }