2 * Copyright (C) 1984-2009 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 about less, or for information on how to
8 * contact the author, see the README file.
13 * Handling functions for command line options.
15 * Most options are handled by the generic code in option.c.
16 * But all string options, and a few non-string options, require
17 * special handling specific to the particular option.
18 * This special processing is done by the "handling functions" in this file.
20 * Each handling function is passed a "type" and, if it is a string
21 * option, the string which should be "assigned" to the option.
22 * The type may be one of:
23 * INIT The option is being initialized from the command line.
24 * TOGGLE The option is being changed from within the program.
25 * QUERY The setting of the option is merely being queried.
34 extern int plusoption;
40 extern int any_display;
41 extern char openquote;
42 extern char closequote;
43 extern char *prproto[];
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;
64 extern int nm_fg_color, nm_bg_color;
65 extern int bo_fg_color, bo_bg_color;
66 extern int ul_fg_color, ul_bg_color;
67 extern int so_fg_color, so_bg_color;
68 extern int bl_fg_color, bl_bg_color;
74 * Handler for -o option.
85 error("log file support is not available", NULL_PARG);
94 if (ch_getflags() & CH_CANSEEK)
96 error("Input is not a pipe", NULL_PARG);
101 error("Log file is already in use", NULL_PARG);
105 namelogfile = lglob(s);
106 use_logfile(namelogfile);
111 error("No log file", NULL_PARG);
114 parg.p_string = namelogfile;
115 error("Log file \"%s\"", &parg);
122 * Handler for -O option.
129 force_logfile = TRUE;
135 * Handlers for -l option.
150 n = getnum(&t, "l", &err);
153 error("Line number is required after -l", NULL_PARG);
163 * Handlers for -j option.
182 jump_sline_fraction = getfraction(&s, "j", &err);
184 error("Invalid line fraction", NULL_PARG);
189 int sline = getnum(&s, "j", &err);
191 error("Invalid line number", NULL_PARG);
195 jump_sline_fraction = -1;
200 if (jump_sline_fraction < 0)
202 parg.p_int = jump_sline;
203 error("Position target at screen line %d", &parg);
207 sprintf(buf, ".%06d", jump_sline_fraction);
209 while (len > 2 && buf[len-1] == '0')
213 error("Position target at screen position %s", &parg);
222 if (jump_sline_fraction < 0)
224 jump_sline = sc_height * jump_sline_fraction / NUM_FRAC_DENOM;
228 * Handlers for -# option.
247 shift_count_fraction = getfraction(&s, "#", &err);
249 error("Invalid column fraction", NULL_PARG);
254 int hs = getnum(&s, "#", &err);
256 error("Invalid column number", NULL_PARG);
260 shift_count_fraction = -1;
265 if (shift_count_fraction < 0)
267 parg.p_int = shift_count;
268 error("Horizontal shift %d columns", &parg);
272 sprintf(buf, ".%06d", shift_count_fraction);
274 while (len > 2 && buf[len-1] == '0')
278 error("Horizontal shift %s of screen width", &parg);
286 if (shift_count_fraction < 0)
288 shift_count = sc_width * shift_count_fraction / NUM_FRAC_DENOM;
305 error("Cannot use lesskey file \"%s\"", &parg);
314 * Handler for -t option.
328 /* Do the rest in main() */
333 error("tags support is not available", NULL_PARG);
337 save_ifile = save_curr_ifile();
339 * Try to open the file containing the tag
340 * and search for the tag in that file.
342 if (edit_tagfile() || (pos = tagsearch()) == NULL_POSITION)
344 /* Failed: reopen the old file. */
345 reedit_ifile(save_ifile);
348 unsave_ifile(save_ifile);
349 jump_loc(pos, jump_sline);
355 * Handler for -T option.
374 parg.p_string = tags;
375 error("Tags file \"%s\"", &parg);
382 * Handler for -p option.
393 * Unget a search command for the specified string.
394 * {{ This won't work if the "/" command is
395 * changed or invalidated by a .lesskey file. }}
400 * In "more" mode, the -p argument is a command,
401 * not a search string, so we don't need a slash.
410 * Handler for -P option.
417 register char **proto;
425 * Figure out which prototype string should be changed.
429 case 's': proto = &prproto[PR_SHORT]; s++; break;
430 case 'm': proto = &prproto[PR_MEDIUM]; s++; break;
431 case 'M': proto = &prproto[PR_LONG]; s++; break;
432 case '=': proto = &eqproto; s++; break;
433 case 'h': proto = &hproto; s++; break;
434 case 'w': proto = &wproto; s++; break;
435 default: proto = &prproto[PR_SHORT]; break;
441 parg.p_string = prproto[pr_type];
448 * Handler for the -b option.
461 * Set the new number of buffers.
463 ch_setbufspace(bufspace);
471 * Handler for the -i option.
491 * Handler for the -V option.
507 * Force output to stdout per GNU standard for --version output.
512 putstr("\nCopyright (C) 1984-2009 Mark Nudelman\n\n");
513 putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");
514 putstr("For information about the terms of redistribution,\n");
515 putstr("see the file named README in the less distribution.\n");
516 putstr("Homepage: http://www.greenwoodsoftware.com/less\n");
524 * Parse an MSDOS color descriptor.
527 colordesc(s, fg_color, bg_color)
535 fg = getnum(&s, "D", &err);
538 error("Missing fg color in -D", NULL_PARG);
546 bg = getnum(&s, "D", &err);
549 error("Missing bg color in -D", NULL_PARG);
554 error("Extra characters at end of -D option", NULL_PARG);
560 * Handler for the -D option.
575 colordesc(s, &nm_fg_color, &nm_bg_color);
578 colordesc(s, &bo_fg_color, &bo_bg_color);
581 colordesc(s, &ul_fg_color, &ul_bg_color);
584 colordesc(s, &bl_fg_color, &bl_bg_color);
587 colordesc(s, &so_fg_color, &so_bg_color);
590 error("-D must be followed by n, d, u, k or s", NULL_PARG);
595 at_enter(AT_STANDOUT);
606 * Handler for the -x option.
613 extern int tabstops[];
614 extern int ntabstops;
615 extern int tabdefault;
616 char msg[60+(4*TABSTOP_MAX)];
624 /* Start at 1 because tabstops[0] is always zero. */
625 for (i = 1; i < TABSTOP_MAX; )
629 while (*s >= '0' && *s <= '9')
630 n = (10 * n) + (*s++ - '0');
631 if (n > tabstops[i-1])
640 tabdefault = tabstops[ntabstops-1] - tabstops[ntabstops-2];
643 strcpy(msg, "Tab stops ");
646 for (i = 1; i < ntabstops; i++)
650 sprintf(msg+strlen(msg), "%d", tabstops[i]);
652 sprintf(msg+strlen(msg), " and then ");
654 sprintf(msg+strlen(msg), "every %d spaces",
664 * Handler for the -" option.
680 openquote = closequote = '\0';
683 if (s[1] != '\0' && s[2] != '\0')
685 error("-\" must be followed by 1 or 2 chars", NULL_PARG);
690 closequote = openquote;
699 error("quotes %s", &parg);
705 * "-?" means display a help message.
706 * If from the command line, exit immediately.
718 error("Use \"h\" for help", NULL_PARG);
726 * Get the "screen window" size.
733 return (sc_height + swindow);