2 * Copyright (C) 1984-2014 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, see the README file.
12 * Handling functions for command line options.
14 * Most options are handled by the generic code in option.c.
15 * But all string options, and a few non-string options, require
16 * special handling specific to the particular option.
17 * This special processing is done by the "handling functions" in this file.
19 * Each handling function is passed a "type" and, if it is a string
20 * option, the string which should be "assigned" to the option.
21 * The type may be one of:
22 * INIT The option is being initialized from the command line.
23 * TOGGLE The option is being changed from within the program.
24 * QUERY The setting of the option is merely being queried.
33 extern int plusoption;
39 extern int any_display;
40 extern char openquote;
41 extern char closequote;
42 extern char *prproto[];
46 extern char *every_first_cmd;
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 command for the specified string.
370 * In "more" mode, the -p argument is a command,
371 * not a search string, so we don't need a slash.
373 every_first_cmd = save(s);
379 * {{ This won't work if the "/" command is
380 * changed or invalidated by a .lesskey file. }}
389 * Handler for -P option.
396 register char **proto;
404 * Figure out which prototype string should be changed.
408 case 's': proto = &prproto[PR_SHORT]; s++; break;
409 case 'm': proto = &prproto[PR_MEDIUM]; s++; break;
410 case 'M': proto = &prproto[PR_LONG]; s++; break;
411 case '=': proto = &eqproto; s++; break;
412 case 'h': proto = &hproto; s++; break;
413 case 'w': proto = &wproto; s++; break;
414 default: proto = &prproto[PR_SHORT]; break;
420 parg.p_string = prproto[pr_type];
427 * Handler for the -b option.
440 * Set the new number of buffers.
442 ch_setbufspace(bufspace);
450 * Handler for the -i option.
470 * Handler for the -V option.
486 * Force output to stdout per GNU standard for --version output.
495 #if HAVE_POSIX_REGCOMP
508 putstr("Spencer V8 ");
510 #if !HAVE_GNU_REGEX && !HAVE_POSIX_REGCOMP && !HAVE_PCRE && !HAVE_RE_COMP && !HAVE_REGCMP && !HAVE_V8_REGCOMP
513 putstr("regular expressions)\n");
514 putstr("Copyright (C) 1984-2014 Mark Nudelman\n\n");
515 putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");
516 putstr("For information about the terms of redistribution,\n");
517 putstr("see the file named README in the less distribution.\n");
518 putstr("Homepage: http://www.greenwoodsoftware.com/less\n");
526 * Parse an MSDOS color descriptor.
529 colordesc(s, fg_color, bg_color)
537 fg = getnum(&s, "D", &err);
540 error("Missing fg color in -D", NULL_PARG);
548 bg = getnum(&s, "D", &err);
551 error("Missing bg color in -D", NULL_PARG);
556 error("Extra characters at end of -D option", NULL_PARG);
562 * Handler for the -D option.
577 colordesc(s, &nm_fg_color, &nm_bg_color);
580 colordesc(s, &bo_fg_color, &bo_bg_color);
583 colordesc(s, &ul_fg_color, &ul_bg_color);
586 colordesc(s, &bl_fg_color, &bl_bg_color);
589 colordesc(s, &so_fg_color, &so_bg_color);
592 error("-D must be followed by n, d, u, k or s", NULL_PARG);
597 at_enter(AT_STANDOUT);
608 * Handler for the -x option.
615 extern int tabstops[];
616 extern int ntabstops;
617 extern int tabdefault;
618 char msg[60+(4*TABSTOP_MAX)];
626 /* Start at 1 because tabstops[0] is always zero. */
627 for (i = 1; i < TABSTOP_MAX; )
631 while (*s >= '0' && *s <= '9')
632 n = (10 * n) + (*s++ - '0');
633 if (n > tabstops[i-1])
642 tabdefault = tabstops[ntabstops-1] - tabstops[ntabstops-2];
645 strcpy(msg, "Tab stops ");
648 for (i = 1; i < ntabstops; i++)
652 sprintf(msg+strlen(msg), "%d", tabstops[i]);
654 sprintf(msg+strlen(msg), " and then ");
656 sprintf(msg+strlen(msg), "every %d spaces",
666 * Handler for the -" option.
682 openquote = closequote = '\0';
685 if (s[1] != '\0' && s[2] != '\0')
687 error("-\" must be followed by 1 or 2 chars", NULL_PARG);
692 closequote = openquote;
701 error("quotes %s", &parg);
707 * "-?" means display a help message.
708 * If from the command line, exit immediately.
720 error("Use \"h\" for help", NULL_PARG);
728 * Get the "screen window" size.
735 return (sc_height + swindow);