2 * Copyright (C) 1984-2019 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 char rscroll_char
;
54 extern int rscroll_attr
;
56 extern int wheel_lines
;
57 extern int less_is_more
;
59 extern char *namelogfile
;
60 extern int force_logfile
;
64 public char *tagoption
= NULL
;
69 extern int nm_fg_color
, nm_bg_color
;
70 extern int bo_fg_color
, bo_bg_color
;
71 extern int ul_fg_color
, ul_bg_color
;
72 extern int so_fg_color
, so_bg_color
;
73 extern int bl_fg_color
, bl_bg_color
;
75 #if MSDOS_COMPILER==WIN32C
76 #ifndef COMMON_LVB_UNDERSCORE
77 #define COMMON_LVB_UNDERSCORE 0x8000
85 * Handler for -o option.
97 error("log file support is not available", NULL_PARG
);
103 namelogfile
= save(s
);
106 if (ch_getflags() & CH_CANSEEK
)
108 error("Input is not a pipe", NULL_PARG
);
113 error("Log file is already in use", NULL_PARG
);
117 if (namelogfile
!= NULL
)
120 namelogfile
= shell_unquote(filename
);
122 use_logfile(namelogfile
);
127 error("No log file", NULL_PARG
);
130 parg
.p_string
= namelogfile
;
131 error("Log file \"%s\"", &parg
);
138 * Handler for -O option.
145 force_logfile
= TRUE
;
151 * Handlers for -j option.
170 jump_sline_fraction
= getfraction(&s
, "j", &err
);
172 error("Invalid line fraction", NULL_PARG
);
177 int sline
= getnum(&s
, "j", &err
);
179 error("Invalid line number", NULL_PARG
);
183 jump_sline_fraction
= -1;
188 if (jump_sline_fraction
< 0)
190 parg
.p_int
= jump_sline
;
191 error("Position target at screen line %d", &parg
);
195 sprintf(buf
, ".%06ld", jump_sline_fraction
);
196 len
= (int) strlen(buf
);
197 while (len
> 2 && buf
[len
-1] == '0')
201 error("Position target at screen position %s", &parg
);
208 calc_jump_sline(VOID_PARAM
)
210 if (jump_sline_fraction
< 0)
212 jump_sline
= sc_height
* jump_sline_fraction
/ NUM_FRAC_DENOM
;
216 * Handlers for -# option.
235 shift_count_fraction
= getfraction(&s
, "#", &err
);
237 error("Invalid column fraction", NULL_PARG
);
242 int hs
= getnum(&s
, "#", &err
);
244 error("Invalid column number", NULL_PARG
);
248 shift_count_fraction
= -1;
253 if (shift_count_fraction
< 0)
255 parg
.p_int
= shift_count
;
256 error("Horizontal shift %d columns", &parg
);
260 sprintf(buf
, ".%06ld", shift_count_fraction
);
261 len
= (int) strlen(buf
);
262 while (len
> 2 && buf
[len
-1] == '0')
266 error("Horizontal shift %s of screen width", &parg
);
272 calc_shift_count(VOID_PARAM
)
274 if (shift_count_fraction
< 0)
276 shift_count
= sc_width
* shift_count_fraction
/ NUM_FRAC_DENOM
;
293 error("Cannot use lesskey file \"%s\"", &parg
);
302 * Handler for -t option.
316 /* Do the rest in main() */
321 error("tags support is not available", NULL_PARG
);
325 save_ifile
= save_curr_ifile();
327 * Try to open the file containing the tag
328 * and search for the tag in that file.
330 if (edit_tagfile() || (pos
= tagsearch()) == NULL_POSITION
)
332 /* Failed: reopen the old file. */
333 reedit_ifile(save_ifile
);
336 unsave_ifile(save_ifile
);
337 jump_loc(pos
, jump_sline
);
343 * Handler for -T option.
360 if (tags
!= NULL
&& tags
!= ztags
)
363 tags
= shell_unquote(filename
);
367 parg
.p_string
= tags
;
368 error("Tags file \"%s\"", &parg
);
375 * Handler for -p option.
386 * Unget a command for the specified string.
391 * In "more" mode, the -p argument is a command,
392 * not a search string, so we don't need a slash.
394 every_first_cmd
= save(s
);
398 ungetcc(CHAR_END_COMMAND
);
401 * {{ This won't work if the "/" command is
402 * changed or invalidated by a .lesskey file. }}
411 * Handler for -P option.
426 * Figure out which prototype string should be changed.
430 case 's': proto
= &prproto
[PR_SHORT
]; s
++; break;
431 case 'm': proto
= &prproto
[PR_MEDIUM
]; s
++; break;
432 case 'M': proto
= &prproto
[PR_LONG
]; s
++; break;
433 case '=': proto
= &eqproto
; s
++; break;
434 case 'h': proto
= &hproto
; s
++; break;
435 case 'w': proto
= &wproto
; s
++; break;
436 default: proto
= &prproto
[PR_SHORT
]; break;
442 parg
.p_string
= prproto
[pr_type
];
449 * Handler for the -b option.
462 * Set the new number of buffers.
464 ch_setbufspace(bufspace
);
472 * Handler for the -i option.
492 * Handler for the -V option.
508 * Force output to stdout per GNU standard for --version output.
514 putstr(pattern_lib_name());
515 putstr(" regular expressions)\n");
516 putstr("Copyright (C) 1984-2019 Mark Nudelman\n\n");
517 putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");
518 putstr("For information about the terms of redistribution,\n");
519 putstr("see the file named README in the less distribution.\n");
520 putstr("Home page: http://www.greenwoodsoftware.com/less\n");
528 * Parse an MSDOS color descriptor.
531 colordesc(s
, fg_color
, bg_color
)
538 #if MSDOS_COMPILER==WIN32C
543 ul
= COMMON_LVB_UNDERSCORE
;
547 fg
= getnum(&s
, "D", &err
);
550 #if MSDOS_COMPILER==WIN32C
556 error("Missing fg color in -D", NULL_PARG
);
565 bg
= getnum(&s
, "D", &err
);
568 error("Missing bg color in -D", NULL_PARG
);
572 #if MSDOS_COMPILER==WIN32C
575 ul
= COMMON_LVB_UNDERSCORE
;
581 error("Extra characters at end of -D option", NULL_PARG
);
587 * Handler for the -D option.
604 colordesc(s
, &nm_fg_color
, &nm_bg_color
);
607 colordesc(s
, &bo_fg_color
, &bo_bg_color
);
610 colordesc(s
, &ul_fg_color
, &ul_bg_color
);
613 colordesc(s
, &bl_fg_color
, &bl_bg_color
);
616 colordesc(s
, &so_fg_color
, &so_bg_color
);
619 sgr_mode
= !sgr_mode
;
622 error("-D must be followed by n, d, u, k, s or a", NULL_PARG
);
627 at_enter(AT_STANDOUT
);
632 p
.p_string
= (sgr_mode
) ? "on" : "off";
633 error("SGR mode is %s", &p
);
640 * Handler for the -x option.
647 extern int tabstops
[];
648 extern int ntabstops
;
649 extern int tabdefault
;
650 char msg
[60+(4*TABSTOP_MAX
)];
658 /* Start at 1 because tabstops[0] is always zero. */
659 for (i
= 1; i
< TABSTOP_MAX
; )
663 while (*s
>= '0' && *s
<= '9')
664 n
= (10 * n
) + (*s
++ - '0');
665 if (n
> tabstops
[i
-1])
674 tabdefault
= tabstops
[ntabstops
-1] - tabstops
[ntabstops
-2];
677 strcpy(msg
, "Tab stops ");
680 for (i
= 1; i
< ntabstops
; i
++)
684 sprintf(msg
+strlen(msg
), "%d", tabstops
[i
]);
686 sprintf(msg
+strlen(msg
), " and then ");
688 sprintf(msg
+strlen(msg
), "every %d spaces",
698 * Handler for the -" option.
714 openquote
= closequote
= '\0';
717 if (s
[1] != '\0' && s
[2] != '\0')
719 error("-\" must be followed by 1 or 2 chars", NULL_PARG
);
724 closequote
= openquote
;
733 error("quotes %s", &parg
);
739 * Handler for the --rscroll option.
754 int attr
= AT_STANDOUT
;
755 setfmt(s
, &fmt
, &attr
, "*s>");
756 if (strcmp(fmt
, "-") == 0)
761 rscroll_char
= *fmt
? *fmt
: '>';
766 p
.p_string
= rscroll_char
? prchar(rscroll_char
) : "-";
767 error("rscroll char is %s", &p
);
773 * "-?" means display a help message.
774 * If from the command line, exit immediately.
786 error("Use \"h\" for help", NULL_PARG
);
794 * Handler for the --mouse option.
798 opt_mousecap(type
, s
)
805 if (mousecap
== OPT_OFF
)
817 * Handler for the --wheel-lines option.
821 opt_wheel_lines(type
, s
)
829 if (wheel_lines
<= 0)
830 wheel_lines
= default_wheel_lines();
838 * Get the "screen window" size.
841 get_swindow(VOID_PARAM
)
845 return (sc_height
+ swindow
);