2 * Copyright (C) 1984-2007 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[];
48 extern int jump_sline;
49 extern int jump_sline_fraction;
50 extern int less_is_more;
52 extern char *namelogfile;
53 extern int force_logfile;
57 public char *tagoption = NULL;
61 extern int nm_fg_color, nm_bg_color;
62 extern int bo_fg_color, bo_bg_color;
63 extern int ul_fg_color, ul_bg_color;
64 extern int so_fg_color, so_bg_color;
65 extern int bl_fg_color, bl_bg_color;
71 * Handler for -o option.
82 error("log file support is not available", NULL_PARG);
91 if (ch_getflags() & CH_CANSEEK)
93 error("Input is not a pipe", NULL_PARG);
98 error("Log file is already in use", NULL_PARG);
102 namelogfile = lglob(s);
103 use_logfile(namelogfile);
108 error("No log file", NULL_PARG);
111 parg.p_string = namelogfile;
112 error("Log file \"%s\"", &parg);
119 * Handler for -O option.
126 force_logfile = TRUE;
132 * Handlers for -l option.
147 n = getnum(&t, "l", &err);
150 error("Line number is required after -l", NULL_PARG);
160 * Handlers for -j option.
179 jump_sline_fraction = getfraction(&s, "j", &err);
181 error("Invalid line fraction", NULL_PARG);
186 int sline = getnum(&s, "j", &err);
188 error("Invalid line number", NULL_PARG);
192 jump_sline_fraction = -1;
197 if (jump_sline_fraction < 0)
199 parg.p_int = jump_sline;
200 error("Position target at screen line %d", &parg);
204 sprintf(buf, ".%06d", jump_sline_fraction);
206 while (len > 2 && buf[len-1] == '0')
210 error("Position target at screen position %s", &parg);
219 if (jump_sline_fraction < 0)
221 jump_sline = sc_height * jump_sline_fraction / NUM_FRAC_DENOM;
238 error("Cannot use lesskey file \"%s\"", &parg);
247 * Handler for -t option.
261 /* Do the rest in main() */
266 error("tags support is not available", NULL_PARG);
270 save_ifile = save_curr_ifile();
272 * Try to open the file containing the tag
273 * and search for the tag in that file.
275 if (edit_tagfile() || (pos = tagsearch()) == NULL_POSITION)
277 /* Failed: reopen the old file. */
278 reedit_ifile(save_ifile);
281 unsave_ifile(save_ifile);
282 jump_loc(pos, jump_sline);
288 * Handler for -T option.
307 parg.p_string = tags;
308 error("Tags file \"%s\"", &parg);
315 * Handler for -p option.
326 * Unget a search command for the specified string.
327 * {{ This won't work if the "/" command is
328 * changed or invalidated by a .lesskey file. }}
333 * In "more" mode, the -p argument is a command,
334 * not a search string, so we don't need a slash.
343 * Handler for -P option.
350 register char **proto;
358 * Figure out which prototype string should be changed.
362 case 's': proto = &prproto[PR_SHORT]; s++; break;
363 case 'm': proto = &prproto[PR_MEDIUM]; s++; break;
364 case 'M': proto = &prproto[PR_LONG]; s++; break;
365 case '=': proto = &eqproto; s++; break;
366 case 'h': proto = &hproto; s++; break;
367 case 'w': proto = &wproto; s++; break;
368 default: proto = &prproto[PR_SHORT]; break;
374 parg.p_string = prproto[pr_type];
381 * Handler for the -b option.
394 * Set the new number of buffers.
396 ch_setbufspace(bufspace);
404 * Handler for the -i option.
424 * Handler for the -V option.
440 * Force output to stdout per GNU standard for --version output.
445 putstr("\nCopyright (C) 1984-2007 Mark Nudelman\n\n");
446 putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");
447 putstr("For information about the terms of redistribution,\n");
448 putstr("see the file named README in the less distribution.\n");
449 putstr("Homepage: http://www.greenwoodsoftware.com/less\n");
457 * Parse an MSDOS color descriptor.
460 colordesc(s, fg_color, bg_color)
468 fg = getnum(&s, "D", &err);
471 error("Missing fg color in -D", NULL_PARG);
479 bg = getnum(&s, "D", &err);
482 error("Missing fg color in -D", NULL_PARG);
487 error("Extra characters at end of -D option", NULL_PARG);
493 * Handler for the -D option.
508 colordesc(s, &nm_fg_color, &nm_bg_color);
511 colordesc(s, &bo_fg_color, &bo_bg_color);
514 colordesc(s, &ul_fg_color, &ul_bg_color);
517 colordesc(s, &bl_fg_color, &bl_bg_color);
520 colordesc(s, &so_fg_color, &so_bg_color);
523 error("-D must be followed by n, d, u, k or s", NULL_PARG);
528 at_enter(AT_STANDOUT);
539 * Handler for the -x option.
546 extern int tabstops[];
547 extern int ntabstops;
548 extern int tabdefault;
549 char msg[60+(4*TABSTOP_MAX)];
557 /* Start at 1 because tabstops[0] is always zero. */
558 for (i = 1; i < TABSTOP_MAX; )
562 while (*s >= '0' && *s <= '9')
563 n = (10 * n) + (*s++ - '0');
564 if (n > tabstops[i-1])
573 tabdefault = tabstops[ntabstops-1] - tabstops[ntabstops-2];
576 strcpy(msg, "Tab stops ");
579 for (i = 1; i < ntabstops; i++)
583 sprintf(msg+strlen(msg), "%d", tabstops[i]);
585 sprintf(msg+strlen(msg), " and then ");
587 sprintf(msg+strlen(msg), "every %d spaces",
597 * Handler for the -" option.
613 openquote = closequote = '\0';
616 if (s[1] != '\0' && s[2] != '\0')
618 error("-\" must be followed by 1 or 2 chars", NULL_PARG);
623 closequote = openquote;
632 error("quotes %s", &parg);
638 * "-?" means display a help message.
639 * If from the command line, exit immediately.
651 error("Use \"h\" for help", NULL_PARG);
659 * Get the "screen window" size.
666 return (sc_height + swindow);