2 * Copyright (C) 1984-2012 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 IFILE curr_ifile
;
47 extern char version
[];
48 extern int jump_sline
;
49 extern int jump_sline_fraction
;
50 extern int shift_count
;
51 extern int shift_count_fraction
;
52 extern int less_is_more
;
54 extern char *namelogfile
;
55 extern int force_logfile
;
59 public char *tagoption
= NULL
;
63 extern int nm_fg_color
, nm_bg_color
;
64 extern int bo_fg_color
, bo_bg_color
;
65 extern int ul_fg_color
, ul_bg_color
;
66 extern int so_fg_color
, so_bg_color
;
67 extern int bl_fg_color
, bl_bg_color
;
73 * Handler for -o option.
84 error("log file support is not available", NULL_PARG
);
93 if (ch_getflags() & CH_CANSEEK
)
95 error("Input is not a pipe", NULL_PARG
);
100 error("Log file is already in use", NULL_PARG
);
104 namelogfile
= lglob(s
);
105 use_logfile(namelogfile
);
110 error("No log file", NULL_PARG
);
113 parg
.p_string
= namelogfile
;
114 error("Log file \"%s\"", &parg
);
121 * Handler for -O option.
128 force_logfile
= TRUE
;
134 * Handlers for -j option.
153 jump_sline_fraction
= getfraction(&s
, "j", &err
);
155 error("Invalid line fraction", NULL_PARG
);
160 int sline
= getnum(&s
, "j", &err
);
162 error("Invalid line number", NULL_PARG
);
166 jump_sline_fraction
= -1;
171 if (jump_sline_fraction
< 0)
173 parg
.p_int
= jump_sline
;
174 error("Position target at screen line %d", &parg
);
178 sprintf(buf
, ".%06d", jump_sline_fraction
);
180 while (len
> 2 && buf
[len
-1] == '0')
184 error("Position target at screen position %s", &parg
);
193 if (jump_sline_fraction
< 0)
195 jump_sline
= sc_height
* jump_sline_fraction
/ NUM_FRAC_DENOM
;
199 * Handlers for -# option.
218 shift_count_fraction
= getfraction(&s
, "#", &err
);
220 error("Invalid column fraction", NULL_PARG
);
225 int hs
= getnum(&s
, "#", &err
);
227 error("Invalid column number", NULL_PARG
);
231 shift_count_fraction
= -1;
236 if (shift_count_fraction
< 0)
238 parg
.p_int
= shift_count
;
239 error("Horizontal shift %d columns", &parg
);
243 sprintf(buf
, ".%06d", shift_count_fraction
);
245 while (len
> 2 && buf
[len
-1] == '0')
249 error("Horizontal shift %s of screen width", &parg
);
257 if (shift_count_fraction
< 0)
259 shift_count
= sc_width
* shift_count_fraction
/ NUM_FRAC_DENOM
;
276 error("Cannot use lesskey file \"%s\"", &parg
);
285 * Handler for -t option.
299 /* Do the rest in main() */
304 error("tags support is not available", NULL_PARG
);
308 save_ifile
= save_curr_ifile();
310 * Try to open the file containing the tag
311 * and search for the tag in that file.
313 if (edit_tagfile() || (pos
= tagsearch()) == NULL_POSITION
)
315 /* Failed: reopen the old file. */
316 reedit_ifile(save_ifile
);
319 unsave_ifile(save_ifile
);
320 jump_loc(pos
, jump_sline
);
326 * Handler for -T option.
345 parg
.p_string
= tags
;
346 error("Tags file \"%s\"", &parg
);
353 * Handler for -p option.
364 * Unget a search command for the specified string.
365 * {{ This won't work if the "/" command is
366 * changed or invalidated by a .lesskey file. }}
371 * In "more" mode, the -p argument is a command,
372 * not a search string, so we don't need a slash.
381 * Handler for -P option.
388 register char **proto
;
396 * Figure out which prototype string should be changed.
400 case 's': proto
= &prproto
[PR_SHORT
]; s
++; break;
401 case 'm': proto
= &prproto
[PR_MEDIUM
]; s
++; break;
402 case 'M': proto
= &prproto
[PR_LONG
]; s
++; break;
403 case '=': proto
= &eqproto
; s
++; break;
404 case 'h': proto
= &hproto
; s
++; break;
405 case 'w': proto
= &wproto
; s
++; break;
406 default: proto
= &prproto
[PR_SHORT
]; break;
412 parg
.p_string
= prproto
[pr_type
];
419 * Handler for the -b option.
432 * Set the new number of buffers.
434 ch_setbufspace(bufspace
);
442 * Handler for the -i option.
462 * Handler for the -V option.
478 * Force output to stdout per GNU standard for --version output.
487 #if HAVE_POSIX_REGCOMP
500 putstr("Spencer V8 ");
502 #if !HAVE_GNU_REGEX && !HAVE_POSIX_REGCOMP && !HAVE_PCRE && !HAVE_RE_COMP && !HAVE_REGCMP && !HAVE_V8_REGCOMP
505 putstr("regular expressions)\n");
506 putstr("Copyright (C) 1984-2012 Mark Nudelman\n\n");
507 putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");
508 putstr("For information about the terms of redistribution,\n");
509 putstr("see the file named README in the less distribution.\n");
510 putstr("Homepage: http://www.greenwoodsoftware.com/less\n");
518 * Parse an MSDOS color descriptor.
521 colordesc(s
, fg_color
, bg_color
)
529 fg
= getnum(&s
, "D", &err
);
532 error("Missing fg color in -D", NULL_PARG
);
540 bg
= getnum(&s
, "D", &err
);
543 error("Missing bg color in -D", NULL_PARG
);
548 error("Extra characters at end of -D option", NULL_PARG
);
554 * Handler for the -D option.
569 colordesc(s
, &nm_fg_color
, &nm_bg_color
);
572 colordesc(s
, &bo_fg_color
, &bo_bg_color
);
575 colordesc(s
, &ul_fg_color
, &ul_bg_color
);
578 colordesc(s
, &bl_fg_color
, &bl_bg_color
);
581 colordesc(s
, &so_fg_color
, &so_bg_color
);
584 error("-D must be followed by n, d, u, k or s", NULL_PARG
);
589 at_enter(AT_STANDOUT
);
600 * Handler for the -x option.
607 extern int tabstops
[];
608 extern int ntabstops
;
609 extern int tabdefault
;
610 char msg
[60+(4*TABSTOP_MAX
)];
618 /* Start at 1 because tabstops[0] is always zero. */
619 for (i
= 1; i
< TABSTOP_MAX
; )
623 while (*s
>= '0' && *s
<= '9')
624 n
= (10 * n
) + (*s
++ - '0');
625 if (n
> tabstops
[i
-1])
634 tabdefault
= tabstops
[ntabstops
-1] - tabstops
[ntabstops
-2];
637 strcpy(msg
, "Tab stops ");
640 for (i
= 1; i
< ntabstops
; i
++)
644 sprintf(msg
+strlen(msg
), "%d", tabstops
[i
]);
646 sprintf(msg
+strlen(msg
), " and then ");
648 sprintf(msg
+strlen(msg
), "every %d spaces",
658 * Handler for the -" option.
674 openquote
= closequote
= '\0';
677 if (s
[1] != '\0' && s
[2] != '\0')
679 error("-\" must be followed by 1 or 2 chars", NULL_PARG
);
684 closequote
= openquote
;
693 error("quotes %s", &parg
);
699 * "-?" means display a help message.
700 * If from the command line, exit immediately.
712 error("Use \"h\" for help", NULL_PARG
);
720 * Get the "screen window" size.
727 return (sc_height
+ swindow
);