2 * Copyright (C) 1984-2011 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;
40 extern int any_display;
41 extern char openquote;
42 extern char closequote;
43 extern char *prproto[];
47 extern IFILE curr_ifile;
48 extern char version[];
49 extern int jump_sline;
50 extern int jump_sline_fraction;
51 extern int shift_count;
52 extern int shift_count_fraction;
53 extern int less_is_more;
55 extern char *namelogfile;
56 extern int force_logfile;
60 public char *tagoption = NULL;
64 extern int nm_fg_color, nm_bg_color;
65 extern int bo_fg_color, bo_bg_color;
66 extern int ul_fg_color, ul_bg_color;
67 extern int so_fg_color, so_bg_color;
68 extern int bl_fg_color, bl_bg_color;
74 * Handler for -o option.
85 error("log file support is not available", NULL_PARG);
94 if (ch_getflags() & CH_CANSEEK)
96 error("Input is not a pipe", NULL_PARG);
101 error("Log file is already in use", NULL_PARG);
105 namelogfile = lglob(s);
106 use_logfile(namelogfile);
111 error("No log file", NULL_PARG);
114 parg.p_string = namelogfile;
115 error("Log file \"%s\"", &parg);
122 * Handler for -O option.
129 force_logfile = TRUE;
135 * Handlers for -j option.
154 jump_sline_fraction = getfraction(&s, "j", &err);
156 error("Invalid line fraction", NULL_PARG);
161 int sline = getnum(&s, "j", &err);
163 error("Invalid line number", NULL_PARG);
167 jump_sline_fraction = -1;
172 if (jump_sline_fraction < 0)
174 parg.p_int = jump_sline;
175 error("Position target at screen line %d", &parg);
179 sprintf(buf, ".%06d", jump_sline_fraction);
181 while (len > 2 && buf[len-1] == '0')
185 error("Position target at screen position %s", &parg);
194 if (jump_sline_fraction < 0)
196 jump_sline = sc_height * jump_sline_fraction / NUM_FRAC_DENOM;
200 * Handlers for -# option.
219 shift_count_fraction = getfraction(&s, "#", &err);
221 error("Invalid column fraction", NULL_PARG);
226 int hs = getnum(&s, "#", &err);
228 error("Invalid column number", NULL_PARG);
232 shift_count_fraction = -1;
237 if (shift_count_fraction < 0)
239 parg.p_int = shift_count;
240 error("Horizontal shift %d columns", &parg);
244 sprintf(buf, ".%06d", shift_count_fraction);
246 while (len > 2 && buf[len-1] == '0')
250 error("Horizontal shift %s of screen width", &parg);
258 if (shift_count_fraction < 0)
260 shift_count = sc_width * shift_count_fraction / NUM_FRAC_DENOM;
277 error("Cannot use lesskey file \"%s\"", &parg);
286 * Handler for -t option.
300 /* Do the rest in main() */
305 error("tags support is not available", NULL_PARG);
309 save_ifile = save_curr_ifile();
311 * Try to open the file containing the tag
312 * and search for the tag in that file.
314 if (edit_tagfile() || (pos = tagsearch()) == NULL_POSITION)
316 /* Failed: reopen the old file. */
317 reedit_ifile(save_ifile);
320 unsave_ifile(save_ifile);
321 jump_loc(pos, jump_sline);
327 * Handler for -T option.
346 parg.p_string = tags;
347 error("Tags file \"%s\"", &parg);
354 * Handler for -p option.
365 * Unget a search command for the specified string.
366 * {{ This won't work if the "/" command is
367 * changed or invalidated by a .lesskey file. }}
372 * In "more" mode, the -p argument is a command,
373 * not a search string, so we don't need a slash.
382 * Handler for -P option.
389 register char **proto;
397 * Figure out which prototype string should be changed.
401 case 's': proto = &prproto[PR_SHORT]; s++; break;
402 case 'm': proto = &prproto[PR_MEDIUM]; s++; break;
403 case 'M': proto = &prproto[PR_LONG]; s++; break;
404 case '=': proto = &eqproto; s++; break;
405 case 'h': proto = &hproto; s++; break;
406 case 'w': proto = &wproto; s++; break;
407 default: proto = &prproto[PR_SHORT]; break;
413 parg.p_string = prproto[pr_type];
420 * Handler for the -b option.
433 * Set the new number of buffers.
435 ch_setbufspace(bufspace);
443 * Handler for the -i option.
463 * Handler for the -V option.
479 * Force output to stdout per GNU standard for --version output.
484 putstr("\nCopyright (C) 1984-2009 Mark Nudelman\n\n");
485 putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");
486 putstr("For information about the terms of redistribution,\n");
487 putstr("see the file named README in the less distribution.\n");
488 putstr("Homepage: http://www.greenwoodsoftware.com/less\n");
496 * Parse an MSDOS color descriptor.
499 colordesc(s, fg_color, bg_color)
507 fg = getnum(&s, "D", &err);
510 error("Missing fg color in -D", NULL_PARG);
518 bg = getnum(&s, "D", &err);
521 error("Missing bg color in -D", NULL_PARG);
526 error("Extra characters at end of -D option", NULL_PARG);
532 * Handler for the -D option.
547 colordesc(s, &nm_fg_color, &nm_bg_color);
550 colordesc(s, &bo_fg_color, &bo_bg_color);
553 colordesc(s, &ul_fg_color, &ul_bg_color);
556 colordesc(s, &bl_fg_color, &bl_bg_color);
559 colordesc(s, &so_fg_color, &so_bg_color);
562 error("-D must be followed by n, d, u, k or s", NULL_PARG);
567 at_enter(AT_STANDOUT);
578 * Handler for the -x option.
585 extern int tabstops[];
586 extern int ntabstops;
587 extern int tabdefault;
588 char msg[60+(4*TABSTOP_MAX)];
596 /* Start at 1 because tabstops[0] is always zero. */
597 for (i = 1; i < TABSTOP_MAX; )
601 while (*s >= '0' && *s <= '9')
602 n = (10 * n) + (*s++ - '0');
603 if (n > tabstops[i-1])
612 tabdefault = tabstops[ntabstops-1] - tabstops[ntabstops-2];
615 strcpy(msg, "Tab stops ");
618 for (i = 1; i < ntabstops; i++)
622 sprintf(msg+strlen(msg), "%d", tabstops[i]);
624 sprintf(msg+strlen(msg), " and then ");
626 sprintf(msg+strlen(msg), "every %d spaces",
636 * Handler for the -" option.
652 openquote = closequote = '\0';
655 if (s[1] != '\0' && s[2] != '\0')
657 error("-\" must be followed by 1 or 2 chars", NULL_PARG);
662 closequote = openquote;
671 error("quotes %s", &parg);
677 * "-?" means display a help message.
678 * If from the command line, exit immediately.
690 error("Use \"h\" for help", NULL_PARG);
698 * Get the "screen window" size.
705 return (sc_height + swindow);