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.
13
* Handling functions for command line options.
15
* Most options are handled by the generic code in option.c.
16
* But all string options, and a few non-string options, require
17
* special handling specific to the particular option.
18
* This special processing is done by the "handling functions" in this file.
20
* Each handling function is passed a "type" and, if it is a string
21
* option, the string which should be "assigned" to the option.
22
* The type may be one of:
23
* INIT The option is being initialized from the command line.
24
* TOGGLE The option is being changed from within the program.
25
* QUERY The setting of the option is merely being queried.
34
extern int plusoption;
39
extern int any_display;
40
extern char openquote;
41
extern char closequote;
42
extern char *prproto[];
46
extern IFILE curr_ifile;
47
extern char version[];
49
extern char *namelogfile;
50
extern int force_logfile;
54
public char *tagoption = NULL;
56
extern int jump_sline;
59
extern int nm_fg_color, nm_bg_color;
60
extern int bo_fg_color, bo_bg_color;
61
extern int ul_fg_color, ul_bg_color;
62
extern int so_fg_color, so_bg_color;
63
extern int bl_fg_color, bl_bg_color;
69
* Handler for -o option.
80
error("log file support is not available", NULL_PARG);
89
if (ch_getflags() & CH_CANSEEK)
91
error("Input is not a pipe", NULL_PARG);
96
error("Log file is already in use", NULL_PARG);
100
namelogfile = lglob(s);
101
use_logfile(namelogfile);
106
error("No log file", NULL_PARG);
109
parg.p_string = namelogfile;
110
error("Log file \"%s\"", &parg);
117
* Handler for -O option.
124
force_logfile = TRUE;
130
* Handlers for -l option.
145
n = getnum(&t, 'l', &err);
148
error("Line number is required after -l", NULL_PARG);
171
error("Cannot use lesskey file \"%s\"", &parg);
180
* Handler for -t option.
194
/* Do the rest in main() */
199
error("tags support is not available", NULL_PARG);
203
save_ifile = save_curr_ifile();
206
if ((pos = tagsearch()) == NULL_POSITION)
208
reedit_ifile(save_ifile);
211
unsave_ifile(save_ifile);
212
jump_loc(pos, jump_sline);
218
* Handler for -T option.
237
parg.p_string = tags;
238
error("Tags file \"%s\"", &parg);
245
* Handler for -p option.
256
* Unget a search command for the specified string.
257
* {{ This won't work if the "/" command is
258
* changed or invalidated by a .lesskey file. }}
268
* Handler for -P option.
275
register char **proto;
283
* Figure out which prototype string should be changed.
287
case 's': proto = &prproto[PR_SHORT]; s++; break;
288
case 'm': proto = &prproto[PR_MEDIUM]; s++; break;
289
case 'M': proto = &prproto[PR_LONG]; s++; break;
290
case '=': proto = &eqproto; s++; break;
291
case 'h': proto = &hproto; s++; break;
292
case 'w': proto = &wproto; s++; break;
293
default: proto = &prproto[PR_SHORT]; break;
299
parg.p_string = prproto[pr_type];
306
* Handler for the -b option.
319
* Set the new number of buffers.
321
ch_setbufspace(bufspace);
329
* Handler for the -i option.
349
* Handler for the -V option.
365
* Force output to stdout per GNU standard for --version output.
370
putstr("\nCopyright (C) 2001 Mark Nudelman\n\n");
371
putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");
372
putstr("For information about the terms of redistribution,\n");
373
putstr("see the file named README in the less distribution.\n");
374
putstr("Homepage: http://www.greenwoodsoftware.com/less\n");
382
* Parse an MSDOS color descriptor.
385
colordesc(s, fg_color, bg_color)
393
fg = getnum(&s, 'D', &err);
396
error("Missing fg color in -D", NULL_PARG);
404
bg = getnum(&s, 'D', &err);
407
error("Missing fg color in -D", NULL_PARG);
412
error("Extra characters at end of -D option", NULL_PARG);
418
* Handler for the -D option.
433
colordesc(s, &nm_fg_color, &nm_bg_color);
436
colordesc(s, &bo_fg_color, &bo_bg_color);
439
colordesc(s, &ul_fg_color, &ul_bg_color);
442
colordesc(s, &bl_fg_color, &bl_bg_color);
445
colordesc(s, &so_fg_color, &so_bg_color);
448
error("-D must be followed by n, d, u, k or s", NULL_PARG);
464
* Handler for the -x option.
471
extern int tabstops[];
472
extern int ntabstops;
473
extern int tabdefault;
474
char msg[60+(4*TABSTOP_MAX)];
482
/* Start at 1 because tabstops[0] is always zero. */
483
for (i = 1; i < TABSTOP_MAX; )
487
while (*s >= '0' && *s <= '9')
488
n = (10 * n) + (*s++ - '0');
489
if (n > tabstops[i-1])
498
tabdefault = tabstops[ntabstops-1] - tabstops[ntabstops-2];
501
strcpy(msg, "Tab stops ");
504
for (i = 1; i < ntabstops; i++)
508
sprintf(msg+strlen(msg), "%d", tabstops[i]);
510
sprintf(msg+strlen(msg), " and then ");
512
sprintf(msg+strlen(msg), "every %d spaces",
522
* Handler for the -" option.
538
openquote = closequote = '\0';
541
if (s[1] != '\0' && s[2] != '\0')
543
error("-\" must be followed by 1 or 2 chars", NULL_PARG);
548
closequote = openquote;
557
error("quotes %s", &parg);
563
* "-?" means display a help message.
564
* If from the command line, exit immediately.
576
error("Use \"h\" for help", NULL_PARG);
584
* Get the "screen window" size.
591
return (sc_height + swindow);