]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/miscellany/less-177/opttbl.c
ap: Fix write past end of addrs[] array.
[nmh] / docs / historical / mh-6.8.5 / miscellany / less-177 / opttbl.c
1 /*
2 * The option table.
3 */
4
5 #include "less.h"
6 #include "option.h"
7
8 #define toupper(c) ((c)-'a'+'A')
9
10 /*
11 * Variables controlled by command line options.
12 */
13 public int quiet; /* Should we suppress the audible bell? */
14 public int how_search; /* Where should forward searches start? */
15 public int top_scroll; /* Repaint screen from top?
16 (alternative is scroll from bottom) */
17 public int pr_type; /* Type of prompt (short, medium, long) */
18 public int bs_mode; /* How to process backspaces */
19 public int know_dumb; /* Don't complain about dumb terminals */
20 public int quit_at_eof; /* Quit after hitting end of file twice */
21 public int squeeze; /* Squeeze multiple blank lines into one */
22 public int tabstop; /* Tab settings */
23 public int back_scroll; /* Repaint screen on backwards movement */
24 public int forw_scroll; /* Repaint screen on forward movement */
25 public int twiddle; /* Display "~" for lines after EOF */
26 public int caseless; /* Do "caseless" searches */
27 public int linenums; /* Use line numbers */
28 public int cbufs; /* Current number of buffers */
29 public int autobuf; /* Automatically allocate buffers as needed */
30 public int nohelp; /* Disable the HELP command */
31 public int ctldisp; /* Send control chars to screen untranslated */
32 public int force_open; /* Open the file even if not regular file */
33 public int swindow; /* Size of scrolling window */
34 public int jump_sline; /* Screen line of "jump target" */
35 public int chopline; /* Truncate displayed lines at screen width */
36 #if __MSDOS__
37 public int output_mode; /* Which screen output method */
38 public int refresh_on_quit; /* Repaint screen on quit, if possible */
39 #endif
40
41 /*
42 * Table of all options and their semantics.
43 */
44 static struct option option[] =
45 {
46 { 'a', BOOL, 0, &how_search, NULL,
47 "Search includes displayed screen",
48 "Search skips displayed screen",
49 NULL
50 },
51 { 'b', NUMBER, 10, &cbufs, opt_b,
52 "Buffers: ",
53 "%d buffers",
54 NULL
55 },
56 { 'B', BOOL, 1, &autobuf, NULL,
57 "Don't automatically allocate buffers",
58 "Automatically allocate buffers when needed",
59 NULL
60 },
61 { 'c', TRIPLE, 0, &top_scroll, NULL,
62 "Repaint by scrolling from bottom of screen",
63 "Repaint by clearing each line",
64 "Repaint by painting from top of screen"
65 },
66 { 'd', BOOL|NO_TOGGLE, 0, &know_dumb, NULL,
67 "Assume intelligent terminal",
68 "Assume dumb terminal",
69 NULL
70 },
71 { 'e', TRIPLE, 0, &quit_at_eof, NULL,
72 "Don't quit at end-of-file",
73 "Quit at end-of-file",
74 "Quit immediately at end-of-file"
75 },
76 { 'f', BOOL, 0, &force_open, NULL,
77 "Open only regular files",
78 "Open even non-regular files",
79 NULL
80 },
81 { 'h', NUMBER, -1, &back_scroll, NULL,
82 "Backwards scroll limit: ",
83 "Backwards scroll limit is %d lines",
84 NULL
85 },
86 { 'H', BOOL|NO_TOGGLE, 0, &nohelp, NULL,
87 "Allow help command",
88 "Don't allow help command",
89 NULL
90 },
91 { 'i', BOOL, 0, &caseless, NULL,
92 "Case is significant in searches",
93 "Ignore case in searches",
94 NULL
95 },
96 { 'j', NUMBER, 1, &jump_sline, NULL,
97 "Target line: ",
98 "Position target at screen line %d",
99 NULL
100 },
101 #if USERFILE
102 { 'k', STRING|NO_TOGGLE, 0, NULL, opt_k,
103 NULL, NULL, NULL
104 },
105 #endif
106 #if LOGFILE
107 { 'l', STRING, 0, NULL, opt_l,
108 NULL, NULL, NULL
109 },
110 { 'L', STRING, 0, NULL, opt__L,
111 NULL, NULL, NULL
112 },
113 #endif
114 { 'm', TRIPLE, 0, &pr_type, NULL,
115 "Short prompt",
116 "Medium prompt",
117 "Long prompt"
118 },
119 { 'n', TRIPLE|REPAINT, 1, &linenums, NULL,
120 "Don't use line numbers",
121 "Use line numbers",
122 "Constantly display line numbers"
123 },
124 #if LOGFILE
125 { 'o', STRING, 0, NULL, opt_o,
126 "log file: ", NULL, NULL
127 },
128 { 'O', STRING, 0, NULL, opt__O,
129 "Log file: ", NULL, NULL
130 },
131 #endif
132 { 'p', STRING|NO_TOGGLE, 0, NULL, opt_p,
133 NULL, NULL, NULL
134 },
135 { 'P', STRING, 0, NULL, opt__P,
136 "prompt: ", NULL, NULL
137 },
138 { 'q', TRIPLE, 0, &quiet, NULL,
139 "Ring the bell for errors AND at eof/bof",
140 "Ring the bell for errors but not at eof/bof",
141 "Never ring the bell"
142 },
143 { 'r', BOOL|REPAINT, 1, &ctldisp, NULL,
144 "Display control characters directly",
145 "Display control characters as ^X",
146 NULL
147 },
148 #if __MSDOS__
149 { 'R', BOOL|REPAINT, 0, &refresh_on_quit, NULL,
150 "Don't repaint screen on quit",
151 "Repaint screen on quit",
152 NULL
153 },
154 #endif
155 { 's', BOOL|REPAINT, 0, &squeeze, NULL,
156 "Display all blank lines",
157 "Squeeze multiple blank lines",
158 NULL
159 },
160 { 'S', BOOL|REPAINT, 0, &chopline, NULL,
161 "Fold long lines",
162 "Chop long lines",
163 NULL
164 },
165 #if TAGS
166 { 't', STRING, 0, NULL, opt_t,
167 "tag: ", NULL, NULL
168 },
169 { 'T', STRING, 0, NULL, opt__T,
170 "tags file: ", NULL, NULL
171 },
172 #endif
173 { 'u', TRIPLE|REPAINT, 0, &bs_mode, NULL,
174 "Display underlined text in underline mode",
175 "Backspaces cause overstrike",
176 "Print backspace as ^H"
177 },
178 #if __MSDOS__
179 { 'v', TRIPLE|NO_TOGGLE, 0, &output_mode, opt_v,
180 "Output is to standard output, using ansi screen control",
181 "Output is to video BIOS",
182 "Output is directly to memory mapped video"
183 },
184 #endif
185 { 'w', BOOL|REPAINT, 1, &twiddle, NULL,
186 "Display nothing for lines after end-of-file",
187 "Display ~ for lines after end-of-file",
188 NULL
189 },
190 #if __MSDOS__
191 #if MOVE_WINDOW
192 #define W_FLAGS STRING
193 #else
194 #define W_FLAGS STRING|NO_TOGGLE
195 #endif
196 { 'W', W_FLAGS, 0, NULL, opt_W,
197 "window boundaries: ", NULL, NULL
198 },
199 #undef W_FLAGS
200 #endif
201 { 'x', NUMBER|REPAINT, 8, &tabstop, NULL,
202 "Tab stops: ",
203 "Tab stops every %d spaces",
204 NULL
205 },
206 { 'y', NUMBER, -1, &forw_scroll, NULL,
207 "Forward scroll limit: ",
208 "Forward scroll limit is %d lines",
209 NULL
210 },
211 { 'z', NUMBER, -1, &swindow, NULL,
212 "Scroll window size: ",
213 "Scroll window size is %d lines",
214 NULL
215 },
216 { '?', NOVAR, 0, NULL, opt_query,
217 NULL, NULL, NULL
218 },
219 { '\0' }
220 };
221
222
223 /*
224 * Initialize each option to its default value.
225 */
226 public void
227 init_option()
228 {
229 register struct option *o;
230
231 for (o = option; o->oletter != '\0'; o++)
232 {
233 /*
234 * Set each variable to its default.
235 */
236 if (o->ovar != NULL)
237 *(o->ovar) = o->odefault;
238 }
239 }
240
241 /*
242 * Find an option in the option table.
243 */
244 public struct option *
245 findopt(c)
246 int c;
247 {
248 register struct option *o;
249
250 for (o = option; o->oletter != '\0'; o++)
251 {
252 if (o->oletter == c)
253 return (o);
254 if ((o->otype & TRIPLE) && toupper(o->oletter) == c)
255 return (o);
256 }
257 return (NULL);
258 }