2 * Copyright (C) 1984-2005 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 int less_is_more;
41 extern char openquote;
42 extern char closequote;
43 extern char *prproto[];
47 extern IFILE curr_ifile;
48 extern char version[];
50 extern char *namelogfile;
51 extern int force_logfile;
55 public char *tagoption = NULL;
57 extern int jump_sline;
60 extern int nm_fg_color, nm_bg_color;
61 extern int bo_fg_color, bo_bg_color;
62 extern int ul_fg_color, ul_bg_color;
63 extern int so_fg_color, so_bg_color;
64 extern int bl_fg_color, bl_bg_color;
70 * Handler for -o option.
81 error("log file support is not available", NULL_PARG);
90 if (ch_getflags() & CH_CANSEEK)
92 error("Input is not a pipe", NULL_PARG);
97 error("Log file is already in use", NULL_PARG);
101 namelogfile = lglob(s);
102 use_logfile(namelogfile);
107 error("No log file", NULL_PARG);
110 parg.p_string = namelogfile;
111 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);
172 error("Cannot use lesskey file \"%s\"", &parg);
181 * Handler for -t option.
195 /* Do the rest in main() */
200 error("tags support is not available", NULL_PARG);
204 save_ifile = save_curr_ifile();
206 * Try to open the file containing the tag
207 * and search for the tag in that file.
209 if (edit_tagfile() || (pos = tagsearch()) == NULL_POSITION)
211 /* Failed: reopen the old file. */
212 reedit_ifile(save_ifile);
215 unsave_ifile(save_ifile);
216 jump_loc(pos, jump_sline);
222 * Handler for -T option.
241 parg.p_string = tags;
242 error("Tags file \"%s\"", &parg);
249 * Handler for -p option.
260 * Unget a search command for the specified string.
261 * {{ This won't work if the "/" command is
262 * changed or invalidated by a .lesskey file. }}
267 * In "more" mode, the -p argument is a command,
268 * not a search string, so we don't need a slash.
277 * Handler for -P option.
284 register char **proto;
292 * Figure out which prototype string should be changed.
296 case 's': proto = &prproto[PR_SHORT]; s++; break;
297 case 'm': proto = &prproto[PR_MEDIUM]; s++; break;
298 case 'M': proto = &prproto[PR_LONG]; s++; break;
299 case '=': proto = &eqproto; s++; break;
300 case 'h': proto = &hproto; s++; break;
301 case 'w': proto = &wproto; s++; break;
302 default: proto = &prproto[PR_SHORT]; break;
308 parg.p_string = prproto[pr_type];
315 * Handler for the -b option.
328 * Set the new number of buffers.
330 ch_setbufspace(bufspace);
338 * Handler for the -i option.
358 * Handler for the -V option.
374 * Force output to stdout per GNU standard for --version output.
379 putstr("\nCopyright (C) 1984-2005 Mark Nudelman\n\n");
380 putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");
381 putstr("For information about the terms of redistribution,\n");
382 putstr("see the file named README in the less distribution.\n");
383 putstr("Homepage: http://www.greenwoodsoftware.com/less\n");
391 * Parse an MSDOS color descriptor.
394 colordesc(s, fg_color, bg_color)
402 fg = getnum(&s, "D", &err);
405 error("Missing fg color in -D", NULL_PARG);
413 bg = getnum(&s, "D", &err);
416 error("Missing fg color in -D", NULL_PARG);
421 error("Extra characters at end of -D option", NULL_PARG);
427 * Handler for the -D option.
442 colordesc(s, &nm_fg_color, &nm_bg_color);
445 colordesc(s, &bo_fg_color, &bo_bg_color);
448 colordesc(s, &ul_fg_color, &ul_bg_color);
451 colordesc(s, &bl_fg_color, &bl_bg_color);
454 colordesc(s, &so_fg_color, &so_bg_color);
457 error("-D must be followed by n, d, u, k or s", NULL_PARG);
462 at_enter(AT_STANDOUT);
473 * Handler for the -x option.
480 extern int tabstops[];
481 extern int ntabstops;
482 extern int tabdefault;
483 char msg[60+(4*TABSTOP_MAX)];
491 /* Start at 1 because tabstops[0] is always zero. */
492 for (i = 1; i < TABSTOP_MAX; )
496 while (*s >= '0' && *s <= '9')
497 n = (10 * n) + (*s++ - '0');
498 if (n > tabstops[i-1])
507 tabdefault = tabstops[ntabstops-1] - tabstops[ntabstops-2];
510 strcpy(msg, "Tab stops ");
513 for (i = 1; i < ntabstops; i++)
517 sprintf(msg+strlen(msg), "%d", tabstops[i]);
519 sprintf(msg+strlen(msg), " and then ");
521 sprintf(msg+strlen(msg), "every %d spaces",
531 * Handler for the -" option.
547 openquote = closequote = '\0';
550 if (s[1] != '\0' && s[2] != '\0')
552 error("-\" must be followed by 1 or 2 chars", NULL_PARG);
557 closequote = openquote;
566 error("quotes %s", &parg);
572 * "-?" means display a help message.
573 * If from the command line, exit immediately.
585 error("Use \"h\" for help", NULL_PARG);
593 * Get the "screen window" size.
600 return (sc_height + swindow);