1 /* $NetBSD: optfunc.c,v 1.3 2013/09/04 19:44:21 tron Exp $ */
4 * Copyright (C) 1984-2012 Mark Nudelman
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Less License, as specified in the README file.
9 * For more information, see the README file.
14 * Handling functions for command line options.
16 * Most options are handled by the generic code in option.c.
17 * But all string options, and a few non-string options, require
18 * special handling specific to the particular option.
19 * This special processing is done by the "handling functions" in this file.
21 * Each handling function is passed a "type" and, if it is a string
22 * option, the string which should be "assigned" to the option.
23 * The type may be one of:
24 * INIT The option is being initialized from the command line.
25 * TOGGLE The option is being changed from within the program.
26 * QUERY The setting of the option is merely being queried.
35 extern int plusoption
;
41 extern int any_display
;
42 extern char openquote
;
43 extern char closequote
;
44 extern char *prproto
[];
48 extern IFILE curr_ifile
;
49 extern char version
[];
50 extern int jump_sline
;
51 extern int jump_sline_fraction
;
52 extern int shift_count
;
53 extern int shift_count_fraction
;
54 extern int less_is_more
;
56 extern char *namelogfile
;
57 extern int force_logfile
;
61 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
);
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 namelogfile
= lglob(s
);
107 use_logfile(namelogfile
);
112 error("No log file", NULL_PARG
);
115 parg
.p_string
= namelogfile
;
116 error("Log file \"%s\"", &parg
);
123 * Handler for -O option.
130 force_logfile
= TRUE
;
136 * Handlers for -j option.
155 jump_sline_fraction
= getfraction(&s
, "j", &err
);
157 error("Invalid line fraction", NULL_PARG
);
162 int sline
= getnum(&s
, "j", &err
);
164 error("Invalid line number", NULL_PARG
);
168 jump_sline_fraction
= -1;
173 if (jump_sline_fraction
< 0)
175 parg
.p_int
= jump_sline
;
176 error("Position target at screen line %d", &parg
);
180 sprintf(buf
, ".%06d", jump_sline_fraction
);
182 while (len
> 2 && buf
[len
-1] == '0')
186 error("Position target at screen position %s", &parg
);
195 if (jump_sline_fraction
< 0)
197 jump_sline
= sc_height
* jump_sline_fraction
/ NUM_FRAC_DENOM
;
201 * Handlers for -# option.
220 shift_count_fraction
= getfraction(&s
, "#", &err
);
222 error("Invalid column fraction", NULL_PARG
);
227 int hs
= getnum(&s
, "#", &err
);
229 error("Invalid column number", NULL_PARG
);
233 shift_count_fraction
= -1;
238 if (shift_count_fraction
< 0)
240 parg
.p_int
= shift_count
;
241 error("Horizontal shift %d columns", &parg
);
245 sprintf(buf
, ".%06d", shift_count_fraction
);
247 while (len
> 2 && buf
[len
-1] == '0')
251 error("Horizontal shift %s of screen width", &parg
);
259 if (shift_count_fraction
< 0)
261 shift_count
= sc_width
* shift_count_fraction
/ NUM_FRAC_DENOM
;
278 error("Cannot use lesskey file \"%s\"", &parg
);
287 * Handler for -t option.
301 /* Do the rest in main() */
306 error("tags support is not available", NULL_PARG
);
310 save_ifile
= save_curr_ifile();
312 * Try to open the file containing the tag
313 * and search for the tag in that file.
315 if (edit_tagfile() || (pos
= tagsearch()) == NULL_POSITION
)
317 /* Failed: reopen the old file. */
318 reedit_ifile(save_ifile
);
321 unsave_ifile(save_ifile
);
322 jump_loc(pos
, jump_sline
);
328 * Handler for -T option.
347 parg
.p_string
= tags
;
348 error("Tags file \"%s\"", &parg
);
355 * Handler for -p option.
366 * Unget a search command for the specified string.
367 * {{ This won't work if the "/" command is
368 * changed or invalidated by a .lesskey file. }}
373 * In "more" mode, the -p argument is a command,
374 * not a search string, so we don't need a slash.
383 * Handler for -P option.
390 register char **proto
;
398 * Figure out which prototype string should be changed.
402 case 's': proto
= &prproto
[PR_SHORT
]; s
++; break;
403 case 'm': proto
= &prproto
[PR_MEDIUM
]; s
++; break;
404 case 'M': proto
= &prproto
[PR_LONG
]; s
++; break;
405 case '=': proto
= &eqproto
; s
++; break;
406 case 'h': proto
= &hproto
; s
++; break;
407 case 'w': proto
= &wproto
; s
++; break;
408 default: proto
= &prproto
[PR_SHORT
]; break;
414 parg
.p_string
= prproto
[pr_type
];
421 * Handler for the -b option.
434 * Set the new number of buffers.
436 ch_setbufspace(bufspace
);
444 * Handler for the -i option.
464 * Handler for the -V option.
480 * Force output to stdout per GNU standard for --version output.
489 #if HAVE_POSIX_REGCOMP
502 putstr("Spencer V8 ");
504 #if !HAVE_GNU_REGEX && !HAVE_POSIX_REGCOMP && !HAVE_PCRE && !HAVE_RE_COMP && !HAVE_REGCMP && !HAVE_V8_REGCOMP
507 putstr("regular expressions)\n");
508 putstr("Copyright (C) 1984-2012 Mark Nudelman\n\n");
509 putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");
510 putstr("For information about the terms of redistribution,\n");
511 putstr("see the file named README in the less distribution.\n");
512 putstr("Homepage: http://www.greenwoodsoftware.com/less\n");
520 * Parse an MSDOS color descriptor.
523 colordesc(s
, fg_color
, bg_color
)
531 fg
= getnum(&s
, "D", &err
);
534 error("Missing fg color in -D", NULL_PARG
);
542 bg
= getnum(&s
, "D", &err
);
545 error("Missing bg color in -D", NULL_PARG
);
550 error("Extra characters at end of -D option", NULL_PARG
);
556 * Handler for the -D option.
571 colordesc(s
, &nm_fg_color
, &nm_bg_color
);
574 colordesc(s
, &bo_fg_color
, &bo_bg_color
);
577 colordesc(s
, &ul_fg_color
, &ul_bg_color
);
580 colordesc(s
, &bl_fg_color
, &bl_bg_color
);
583 colordesc(s
, &so_fg_color
, &so_bg_color
);
586 error("-D must be followed by n, d, u, k or s", NULL_PARG
);
591 at_enter(AT_STANDOUT
);
602 * Handler for the -x option.
609 extern int tabstops
[];
610 extern int ntabstops
;
611 extern int tabdefault
;
612 char msg
[60+(4*TABSTOP_MAX
)];
620 /* Start at 1 because tabstops[0] is always zero. */
621 for (i
= 1; i
< TABSTOP_MAX
; )
625 while (*s
>= '0' && *s
<= '9')
626 n
= (10 * n
) + (*s
++ - '0');
627 if (n
> tabstops
[i
-1])
636 tabdefault
= tabstops
[ntabstops
-1] - tabstops
[ntabstops
-2];
639 strcpy(msg
, "Tab stops ");
642 for (i
= 1; i
< ntabstops
; i
++)
646 sprintf(msg
+strlen(msg
), "%d", tabstops
[i
]);
648 sprintf(msg
+strlen(msg
), " and then ");
650 sprintf(msg
+strlen(msg
), "every %d spaces",
660 * Handler for the -" option.
676 openquote
= closequote
= '\0';
679 if (s
[1] != '\0' && s
[2] != '\0')
681 error("-\" must be followed by 1 or 2 chars", NULL_PARG
);
686 closequote
= openquote
;
695 error("quotes %s", &parg
);
701 * "-?" means display a help message.
702 * If from the command line, exit immediately.
714 error("Use \"h\" for help", NULL_PARG
);
722 * Get the "screen window" size.
729 return (sc_height
+ swindow
);