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 LWCHAR rscroll_char;
54 extern int rscroll_attr;
55 extern int less_is_more;
57 extern char *namelogfile;
58 extern int force_logfile;
62 public char *tagoption = NULL;
67 extern int nm_fg_color, nm_bg_color;
68 extern int bo_fg_color, bo_bg_color;
69 extern int ul_fg_color, ul_bg_color;
70 extern int so_fg_color, so_bg_color;
71 extern int bl_fg_color, bl_bg_color;
73 #if MSDOS_COMPILER==WIN32C
74 #ifndef COMMON_LVB_UNDERSCORE
75 #define COMMON_LVB_UNDERSCORE 0x8000
83 * Handler for -o option.
95 error("log file support is not available", NULL_PARG);
101 namelogfile = save(s);
104 if (ch_getflags() & CH_CANSEEK)
106 error("Input is not a pipe", NULL_PARG);
111 error("Log file is already in use", NULL_PARG);
115 if (namelogfile != NULL)
118 namelogfile = shell_unquote(filename);
120 use_logfile(namelogfile);
125 error("No log file", NULL_PARG);
128 parg.p_string = namelogfile;
129 error("Log file \"%s\"", &parg);
136 * Handler for -O option.
143 force_logfile = TRUE;
149 * Handlers for -j option.
168 jump_sline_fraction = getfraction(&s, "j", &err);
170 error("Invalid line fraction", NULL_PARG);
175 int sline = getnum(&s, "j", &err);
177 error("Invalid line number", NULL_PARG);
181 jump_sline_fraction = -1;
186 if (jump_sline_fraction < 0)
188 parg.p_int = jump_sline;
189 error("Position target at screen line %d", &parg);
193 sprintf(buf, ".%06ld", jump_sline_fraction);
194 len = (int) strlen(buf);
195 while (len > 2 && buf[len-1] == '0')
199 error("Position target at screen position %s", &parg);
208 if (jump_sline_fraction < 0)
210 jump_sline = sc_height * jump_sline_fraction / NUM_FRAC_DENOM;
214 * Handlers for -# option.
233 shift_count_fraction = getfraction(&s, "#", &err);
235 error("Invalid column fraction", NULL_PARG);
240 int hs = getnum(&s, "#", &err);
242 error("Invalid column number", NULL_PARG);
246 shift_count_fraction = -1;
251 if (shift_count_fraction < 0)
253 parg.p_int = shift_count;
254 error("Horizontal shift %d columns", &parg);
258 sprintf(buf, ".%06ld", shift_count_fraction);
259 len = (int) strlen(buf);
260 while (len > 2 && buf[len-1] == '0')
264 error("Horizontal shift %s of screen width", &parg);
272 if (shift_count_fraction < 0)
274 shift_count = sc_width * shift_count_fraction / NUM_FRAC_DENOM;
291 error("Cannot use lesskey file \"%s\"", &parg);
300 * Handler for -t option.
314 /* Do the rest in main() */
319 error("tags support is not available", NULL_PARG);
323 save_ifile = save_curr_ifile();
325 * Try to open the file containing the tag
326 * and search for the tag in that file.
328 if (edit_tagfile() || (pos = tagsearch()) == NULL_POSITION)
330 /* Failed: reopen the old file. */
331 reedit_ifile(save_ifile);
334 unsave_ifile(save_ifile);
335 jump_loc(pos, jump_sline);
341 * Handler for -T option.
358 if (tags != NULL && tags != ztags)
361 tags = shell_unquote(filename);
365 parg.p_string = tags;
366 error("Tags file \"%s\"", &parg);
373 * Handler for -p option.
384 * Unget a command for the specified string.
389 * In "more" mode, the -p argument is a command,
390 * not a search string, so we don't need a slash.
392 every_first_cmd = save(s);
396 ungetcc(CHAR_END_COMMAND);
399 * {{ This won't work if the "/" command is
400 * changed or invalidated by a .lesskey file. }}
409 * Handler for -P option.
424 * Figure out which prototype string should be changed.
428 case 's': proto = &prproto[PR_SHORT]; s++; break;
429 case 'm': proto = &prproto[PR_MEDIUM]; s++; break;
430 case 'M': proto = &prproto[PR_LONG]; s++; break;
431 case '=': proto = &eqproto; s++; break;
432 case 'h': proto = &hproto; s++; break;
433 case 'w': proto = &wproto; s++; break;
434 default: proto = &prproto[PR_SHORT]; break;
440 parg.p_string = prproto[pr_type];
447 * Handler for the -b option.
460 * Set the new number of buffers.
462 ch_setbufspace(bufspace);
470 * Handler for the -i option.
490 * Handler for the -V option.
506 * Force output to stdout per GNU standard for --version output.
515 #if HAVE_POSIX_REGCOMP
528 putstr("Spencer V8 ");
530 #if !HAVE_GNU_REGEX && !HAVE_POSIX_REGCOMP && !HAVE_PCRE && !HAVE_RE_COMP && !HAVE_REGCMP && !HAVE_V8_REGCOMP
533 putstr("regular expressions)\n");
534 putstr("Copyright (C) 1984-2017 Mark Nudelman\n\n");
535 putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");
536 putstr("For information about the terms of redistribution,\n");
537 putstr("see the file named README in the less distribution.\n");
538 putstr("Homepage: http://www.greenwoodsoftware.com/less\n");
546 * Parse an MSDOS color descriptor.
549 colordesc(s, fg_color, bg_color)
556 #if MSDOS_COMPILER==WIN32C
561 ul = COMMON_LVB_UNDERSCORE;
565 fg = getnum(&s, "D", &err);
568 #if MSDOS_COMPILER==WIN32C
574 error("Missing fg color in -D", NULL_PARG);
583 bg = getnum(&s, "D", &err);
586 error("Missing bg color in -D", NULL_PARG);
590 #if MSDOS_COMPILER==WIN32C
593 ul = COMMON_LVB_UNDERSCORE;
599 error("Extra characters at end of -D option", NULL_PARG);
605 * Handler for the -D option.
622 colordesc(s, &nm_fg_color, &nm_bg_color);
625 colordesc(s, &bo_fg_color, &bo_bg_color);
628 colordesc(s, &ul_fg_color, &ul_bg_color);
631 colordesc(s, &bl_fg_color, &bl_bg_color);
634 colordesc(s, &so_fg_color, &so_bg_color);
637 sgr_mode = !sgr_mode;
640 error("-D must be followed by n, d, u, k, s or a", NULL_PARG);
645 at_enter(AT_STANDOUT);
650 p.p_string = (sgr_mode) ? "on" : "off";
651 error("SGR mode is %s", &p);
658 * Handler for the -x option.
665 extern int tabstops[];
666 extern int ntabstops;
667 extern int tabdefault;
668 char msg[60+(4*TABSTOP_MAX)];
676 /* Start at 1 because tabstops[0] is always zero. */
677 for (i = 1; i < TABSTOP_MAX; )
681 while (*s >= '0' && *s <= '9')
682 n = (10 * n) + (*s++ - '0');
683 if (n > tabstops[i-1])
692 tabdefault = tabstops[ntabstops-1] - tabstops[ntabstops-2];
695 strcpy(msg, "Tab stops ");
698 for (i = 1; i < ntabstops; i++)
702 sprintf(msg+strlen(msg), "%d", tabstops[i]);
704 sprintf(msg+strlen(msg), " and then ");
706 sprintf(msg+strlen(msg), "every %d spaces",
716 * Handler for the -" option.
732 openquote = closequote = '\0';
735 if (s[1] != '\0' && s[2] != '\0')
737 error("-\" must be followed by 1 or 2 chars", NULL_PARG);
742 closequote = openquote;
751 error("quotes %s", &parg);
757 * Handler for the --rscroll option.
772 int attr = AT_STANDOUT;
773 setfmt(s, &fmt, &attr, "*s>");
774 if (strcmp(fmt, "-") == 0)
779 rscroll_char = *fmt ? *fmt : '>';
784 p.p_string = rscroll_char ? prchar(rscroll_char) : "-";
785 error("rscroll char is %s", &p);
791 * "-?" means display a help message.
792 * If from the command line, exit immediately.
804 error("Use \"h\" for help", NULL_PARG);
812 * Get the "screen window" size.
819 return (sc_height + swindow);