2 * Copyright (C) 1984-2015 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;
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;
75 * Handler for -o option.
86 error("log file support is not available", NULL_PARG);
92 namelogfile = save(s);
95 if (ch_getflags() & CH_CANSEEK)
97 error("Input is not a pipe", NULL_PARG);
102 error("Log file is already in use", NULL_PARG);
106 if (namelogfile != NULL)
108 namelogfile = lglob(s);
109 use_logfile(namelogfile);
114 error("No log file", NULL_PARG);
117 parg.p_string = namelogfile;
118 error("Log file \"%s\"", &parg);
125 * Handler for -O option.
132 force_logfile = TRUE;
138 * Handlers for -j option.
157 jump_sline_fraction = getfraction(&s, "j", &err);
159 error("Invalid line fraction", NULL_PARG);
164 int sline = getnum(&s, "j", &err);
166 error("Invalid line number", NULL_PARG);
170 jump_sline_fraction = -1;
175 if (jump_sline_fraction < 0)
177 parg.p_int = jump_sline;
178 error("Position target at screen line %d", &parg);
182 sprintf(buf, ".%06d", jump_sline_fraction);
183 len = (int) strlen(buf);
184 while (len > 2 && buf[len-1] == '0')
188 error("Position target at screen position %s", &parg);
197 if (jump_sline_fraction < 0)
199 jump_sline = sc_height * jump_sline_fraction / NUM_FRAC_DENOM;
203 * Handlers for -# option.
222 shift_count_fraction = getfraction(&s, "#", &err);
224 error("Invalid column fraction", NULL_PARG);
229 int hs = getnum(&s, "#", &err);
231 error("Invalid column number", NULL_PARG);
235 shift_count_fraction = -1;
240 if (shift_count_fraction < 0)
242 parg.p_int = shift_count;
243 error("Horizontal shift %d columns", &parg);
247 sprintf(buf, ".%06d", shift_count_fraction);
248 len = (int) strlen(buf);
249 while (len > 2 && buf[len-1] == '0')
253 error("Horizontal shift %s of screen width", &parg);
261 if (shift_count_fraction < 0)
263 shift_count = sc_width * shift_count_fraction / NUM_FRAC_DENOM;
280 error("Cannot use lesskey file \"%s\"", &parg);
289 * Handler for -t option.
303 /* Do the rest in main() */
308 error("tags support is not available", NULL_PARG);
312 save_ifile = save_curr_ifile();
314 * Try to open the file containing the tag
315 * and search for the tag in that file.
317 if (edit_tagfile() || (pos = tagsearch()) == NULL_POSITION)
319 /* Failed: reopen the old file. */
320 reedit_ifile(save_ifile);
323 unsave_ifile(save_ifile);
324 jump_loc(pos, jump_sline);
330 * Handler for -T option.
346 if (tags != NULL && tags != ztags)
351 parg.p_string = tags;
352 error("Tags file \"%s\"", &parg);
359 * Handler for -p option.
370 * Unget a command for the specified string.
375 * In "more" mode, the -p argument is a command,
376 * not a search string, so we don't need a slash.
378 every_first_cmd = save(s);
382 ungetcc(CHAR_END_COMMAND);
385 * {{ This won't work if the "/" command is
386 * changed or invalidated by a .lesskey file. }}
395 * Handler for -P option.
402 register char **proto;
410 * Figure out which prototype string should be changed.
414 case 's': proto = &prproto[PR_SHORT]; s++; break;
415 case 'm': proto = &prproto[PR_MEDIUM]; s++; break;
416 case 'M': proto = &prproto[PR_LONG]; s++; break;
417 case '=': proto = &eqproto; s++; break;
418 case 'h': proto = &hproto; s++; break;
419 case 'w': proto = &wproto; s++; break;
420 default: proto = &prproto[PR_SHORT]; break;
426 parg.p_string = prproto[pr_type];
433 * Handler for the -b option.
446 * Set the new number of buffers.
448 ch_setbufspace(bufspace);
456 * Handler for the -i option.
476 * Handler for the -V option.
492 * Force output to stdout per GNU standard for --version output.
501 #if HAVE_POSIX_REGCOMP
514 putstr("Spencer V8 ");
516 #if !HAVE_GNU_REGEX && !HAVE_POSIX_REGCOMP && !HAVE_PCRE && !HAVE_RE_COMP && !HAVE_REGCMP && !HAVE_V8_REGCOMP
519 putstr("regular expressions)\n");
520 putstr("Copyright (C) 1984-2015 Mark Nudelman\n\n");
521 putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");
522 putstr("For information about the terms of redistribution,\n");
523 putstr("see the file named README in the less distribution.\n");
524 putstr("Homepage: http://www.greenwoodsoftware.com/less\n");
532 * Parse an MSDOS color descriptor.
535 colordesc(s, fg_color, bg_color)
543 fg = getnum(&s, "D", &err);
546 error("Missing fg color in -D", NULL_PARG);
554 bg = getnum(&s, "D", &err);
557 error("Missing bg color in -D", NULL_PARG);
562 error("Extra characters at end of -D option", NULL_PARG);
568 * Handler for the -D option.
583 colordesc(s, &nm_fg_color, &nm_bg_color);
586 colordesc(s, &bo_fg_color, &bo_bg_color);
589 colordesc(s, &ul_fg_color, &ul_bg_color);
592 colordesc(s, &bl_fg_color, &bl_bg_color);
595 colordesc(s, &so_fg_color, &so_bg_color);
598 error("-D must be followed by n, d, u, k or s", NULL_PARG);
603 at_enter(AT_STANDOUT);
614 * Handler for the -x option.
621 extern int tabstops[];
622 extern int ntabstops;
623 extern int tabdefault;
624 char msg[60+(4*TABSTOP_MAX)];
632 /* Start at 1 because tabstops[0] is always zero. */
633 for (i = 1; i < TABSTOP_MAX; )
637 while (*s >= '0' && *s <= '9')
638 n = (10 * n) + (*s++ - '0');
639 if (n > tabstops[i-1])
648 tabdefault = tabstops[ntabstops-1] - tabstops[ntabstops-2];
651 strcpy(msg, "Tab stops ");
654 for (i = 1; i < ntabstops; i++)
658 sprintf(msg+strlen(msg), "%d", tabstops[i]);
660 sprintf(msg+strlen(msg), " and then ");
662 sprintf(msg+strlen(msg), "every %d spaces",
672 * Handler for the -" option.
688 openquote = closequote = '\0';
691 if (s[1] != '\0' && s[2] != '\0')
693 error("-\" must be followed by 1 or 2 chars", NULL_PARG);
698 closequote = openquote;
707 error("quotes %s", &parg);
713 * "-?" means display a help message.
714 * If from the command line, exit immediately.
726 error("Use \"h\" for help", NULL_PARG);
734 * Get the "screen window" size.
741 return (sc_height + swindow);