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 = unquote_file(namelogfile);
110 error("Log file \"%s\"", &parg);
118 * Handler for -O option.
125 force_logfile = TRUE;
131 * Handlers for -l option.
146 n = getnum(&t, 'l', &err);
149 error("Line number is required after -l", NULL_PARG);
171 parg.p_string = unquote_file(s);
172 error("Cannot use lesskey file \"%s\"", &parg);
182 * Handler for -t option.
196 /* Do the rest in main() */
201 error("tags support is not available", NULL_PARG);
205 save_ifile = save_curr_ifile();
208 if ((pos = tagsearch()) == NULL_POSITION)
210 reedit_ifile(save_ifile);
213 unsave_ifile(save_ifile);
214 jump_loc(pos, jump_sline);
220 * Handler for -T option.
239 parg.p_string = unquote_file(tags);
240 error("Tags file \"%s\"", &parg);
248 * Handler for -p option.
259 * Unget a search command for the specified string.
260 * {{ This won't work if the "/" command is
261 * changed or invalidated by a .lesskey file. }}
271 * Handler for -P option.
278 register char **proto;
286 * Figure out which prototype string should be changed.
290 case 's': proto = &prproto[PR_SHORT]; s++; break;
291 case 'm': proto = &prproto[PR_MEDIUM]; s++; break;
292 case 'M': proto = &prproto[PR_LONG]; s++; break;
293 case '=': proto = &eqproto; s++; break;
294 case 'h': proto = &hproto; s++; break;
295 case 'w': proto = &wproto; s++; break;
296 default: proto = &prproto[PR_SHORT]; break;
302 parg.p_string = prproto[pr_type];
309 * Handler for the -b option.
322 * Allocate the new number of buffers.
324 cbufs = ch_nbuf(cbufs);
332 * Handler for the -i option.
352 * Handler for the -V option.
368 * Force output to stdout per GNU standard for --version output.
373 putstr("\nCopyright (C) 2001 Mark Nudelman\n\n");
374 putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");
375 putstr("For information about the terms of redistribution,\n");
376 putstr("see the file named README in the less distribution.\n");
377 putstr("Homepage: http://www.greenwoodsoftware.com/less\n");
385 * Parse an MSDOS color descriptor.
388 colordesc(s, fg_color, bg_color)
396 fg = getnum(&s, 'D', &err);
399 error("Missing fg color in -D", NULL_PARG);
407 bg = getnum(&s, 'D', &err);
410 error("Missing fg color in -D", NULL_PARG);
415 error("Extra characters at end of -D option", NULL_PARG);
421 * Handler for the -D option.
436 colordesc(s, &nm_fg_color, &nm_bg_color);
439 colordesc(s, &bo_fg_color, &bo_bg_color);
442 colordesc(s, &ul_fg_color, &ul_bg_color);
445 colordesc(s, &bl_fg_color, &bl_bg_color);
448 colordesc(s, &so_fg_color, &so_bg_color);
451 error("-D must be followed by n, d, u, k or s", NULL_PARG);
467 * Handler for the -x option.
474 extern int tabstops[];
475 extern int ntabstops;
476 extern int tabdefault;
477 char msg[60+(4*TABSTOP_MAX)];
485 /* Start at 1 because tabstops[0] is always zero. */
486 for (i = 1; i < TABSTOP_MAX; )
489 while (*s >= '0' && *s <= '9')
490 n = (10 * n) + (*s++ - '0');
491 if (n > tabstops[i-1])
499 tabdefault = tabstops[ntabstops-1] - tabstops[ntabstops-2];
502 strcpy(msg, "Tab stops ");
505 for (i = 1; i < ntabstops; i++)
509 sprintf(msg+strlen(msg), "%d", tabstops[i]);
511 sprintf(msg+strlen(msg), " and then ");
513 sprintf(msg+strlen(msg), "every %d spaces",
523 * Handler for the -" option.
537 if (s[1] != '\0' && s[2] != '\0')
539 error("-\" must be followed by 1 or 2 chars", NULL_PARG);
544 closequote = openquote;
553 error("quotes %s", &parg);
559 * "-?" means display a help message.
560 * If from the command line, exit immediately.
572 error("Use \"h\" for help", NULL_PARG);
580 * Get the "screen window" size.
587 return (sc_height + swindow);