2 * Copyright (C) 1984-2017 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 long jump_sline_fraction;
51 extern int shift_count;
52 extern long shift_count_fraction;
53 extern int less_is_more;
55 extern char *namelogfile;
56 extern int force_logfile;
60 public char *tagoption = NULL;
65 extern int nm_fg_color, nm_bg_color;
66 extern int bo_fg_color, bo_bg_color;
67 extern int ul_fg_color, ul_bg_color;
68 extern int so_fg_color, so_bg_color;
69 extern int bl_fg_color, bl_bg_color;
76 * Handler for -o option.
87 error("log file support is not available", NULL_PARG);
93 namelogfile = save(s);
96 if (ch_getflags() & CH_CANSEEK)
98 error("Input is not a pipe", NULL_PARG);
103 error("Log file is already in use", NULL_PARG);
107 if (namelogfile != NULL)
109 namelogfile = lglob(s);
110 use_logfile(namelogfile);
115 error("No log file", NULL_PARG);
118 parg.p_string = namelogfile;
119 error("Log file \"%s\"", &parg);
126 * Handler for -O option.
133 force_logfile = TRUE;
139 * Handlers for -j option.
158 jump_sline_fraction = getfraction(&s, "j", &err);
160 error("Invalid line fraction", NULL_PARG);
165 int sline = getnum(&s, "j", &err);
167 error("Invalid line number", NULL_PARG);
171 jump_sline_fraction = -1;
176 if (jump_sline_fraction < 0)
178 parg.p_int = jump_sline;
179 error("Position target at screen line %d", &parg);
183 sprintf(buf, ".%06ld", jump_sline_fraction);
184 len = (int) strlen(buf);
185 while (len > 2 && buf[len-1] == '0')
189 error("Position target at screen position %s", &parg);
198 if (jump_sline_fraction < 0)
200 jump_sline = sc_height * jump_sline_fraction / NUM_FRAC_DENOM;
204 * Handlers for -# option.
223 shift_count_fraction = getfraction(&s, "#", &err);
225 error("Invalid column fraction", NULL_PARG);
230 int hs = getnum(&s, "#", &err);
232 error("Invalid column number", NULL_PARG);
236 shift_count_fraction = -1;
241 if (shift_count_fraction < 0)
243 parg.p_int = shift_count;
244 error("Horizontal shift %d columns", &parg);
248 sprintf(buf, ".%06ld", shift_count_fraction);
249 len = (int) strlen(buf);
250 while (len > 2 && buf[len-1] == '0')
254 error("Horizontal shift %s of screen width", &parg);
262 if (shift_count_fraction < 0)
264 shift_count = sc_width * shift_count_fraction / NUM_FRAC_DENOM;
281 error("Cannot use lesskey file \"%s\"", &parg);
290 * Handler for -t option.
304 /* Do the rest in main() */
309 error("tags support is not available", NULL_PARG);
313 save_ifile = save_curr_ifile();
315 * Try to open the file containing the tag
316 * and search for the tag in that file.
318 if (edit_tagfile() || (pos = tagsearch()) == NULL_POSITION)
320 /* Failed: reopen the old file. */
321 reedit_ifile(save_ifile);
324 unsave_ifile(save_ifile);
325 jump_loc(pos, jump_sline);
331 * Handler for -T option.
347 if (tags != NULL && tags != ztags)
352 parg.p_string = tags;
353 error("Tags file \"%s\"", &parg);
360 * Handler for -p option.
371 * Unget a command for the specified string.
376 * In "more" mode, the -p argument is a command,
377 * not a search string, so we don't need a slash.
379 every_first_cmd = save(s);
383 ungetcc(CHAR_END_COMMAND);
386 * {{ This won't work if the "/" command is
387 * changed or invalidated by a .lesskey file. }}
396 * Handler for -P option.
411 * Figure out which prototype string should be changed.
415 case 's': proto = &prproto[PR_SHORT]; s++; break;
416 case 'm': proto = &prproto[PR_MEDIUM]; s++; break;
417 case 'M': proto = &prproto[PR_LONG]; s++; break;
418 case '=': proto = &eqproto; s++; break;
419 case 'h': proto = &hproto; s++; break;
420 case 'w': proto = &wproto; s++; break;
421 default: proto = &prproto[PR_SHORT]; break;
427 parg.p_string = prproto[pr_type];
434 * Handler for the -b option.
447 * Set the new number of buffers.
449 ch_setbufspace(bufspace);
457 * Handler for the -i option.
477 * Handler for the -V option.
493 * Force output to stdout per GNU standard for --version output.
502 #if HAVE_POSIX_REGCOMP
515 putstr("Spencer V8 ");
517 #if !HAVE_GNU_REGEX && !HAVE_POSIX_REGCOMP && !HAVE_PCRE && !HAVE_RE_COMP && !HAVE_REGCMP && !HAVE_V8_REGCOMP
520 putstr("regular expressions)\n");
521 putstr("Copyright (C) 1984-2017 Mark Nudelman\n\n");
522 putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");
523 putstr("For information about the terms of redistribution,\n");
524 putstr("see the file named README in the less distribution.\n");
525 putstr("Homepage: http://www.greenwoodsoftware.com/less\n");
533 * Parse an MSDOS color descriptor.
536 colordesc(s, fg_color, bg_color)
544 fg = getnum(&s, "D", &err);
547 error("Missing fg color in -D", NULL_PARG);
555 bg = getnum(&s, "D", &err);
558 error("Missing bg color in -D", NULL_PARG);
563 error("Extra characters at end of -D option", NULL_PARG);
569 * Handler for the -D option.
586 colordesc(s, &nm_fg_color, &nm_bg_color);
589 colordesc(s, &bo_fg_color, &bo_bg_color);
592 colordesc(s, &ul_fg_color, &ul_bg_color);
595 colordesc(s, &bl_fg_color, &bl_bg_color);
598 colordesc(s, &so_fg_color, &so_bg_color);
601 sgr_mode = !sgr_mode;
604 error("-D must be followed by n, d, u, k, s or a", NULL_PARG);
609 at_enter(AT_STANDOUT);
614 p.p_string = (sgr_mode) ? "on" : "off";
615 error("SGR mode is %s", &p);
622 * Handler for the -x option.
629 extern int tabstops[];
630 extern int ntabstops;
631 extern int tabdefault;
632 char msg[60+(4*TABSTOP_MAX)];
640 /* Start at 1 because tabstops[0] is always zero. */
641 for (i = 1; i < TABSTOP_MAX; )
645 while (*s >= '0' && *s <= '9')
646 n = (10 * n) + (*s++ - '0');
647 if (n > tabstops[i-1])
656 tabdefault = tabstops[ntabstops-1] - tabstops[ntabstops-2];
659 strcpy(msg, "Tab stops ");
662 for (i = 1; i < ntabstops; i++)
666 sprintf(msg+strlen(msg), "%d", tabstops[i]);
668 sprintf(msg+strlen(msg), " and then ");
670 sprintf(msg+strlen(msg), "every %d spaces",
680 * Handler for the -" option.
696 openquote = closequote = '\0';
699 if (s[1] != '\0' && s[2] != '\0')
701 error("-\" must be followed by 1 or 2 chars", NULL_PARG);
706 closequote = openquote;
715 error("quotes %s", &parg);
721 * "-?" means display a help message.
722 * If from the command line, exit immediately.
734 error("Use \"h\" for help", NULL_PARG);
742 * Get the "screen window" size.
749 return (sc_height + swindow);