Deleted Added
sdiff udiff text old ( 195941 ) new ( 221715 )
full compact
1/*
2 * Copyright (C) 1984-2011 Mark Nudelman
3 *
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.
6 *
7 * For more information about less, or for information on how to
8 * contact the author, see the README file.
9 */
10

--- 8 unchanged lines hidden (view full) ---

19 */
20
21#include "less.h"
22#include "option.h"
23
24static struct loption *pendopt;
25public int plusoption = FALSE;
26
27static char *optstring();
28static int flip_triple();
29
30extern int screen_trashed;
31extern int less_is_more;
32extern int quit_at_eof;
33extern char *every_first_cmd;
34
35/*
36 * Return a printable description of an option.
37 */
38 static char *
39opt_desc(o)
40 struct loption *o;
41{
42 static char buf[OPTNAME_MAX + 10];
43 if (o->oletter == OLETTER_NONE)
44 SNPRINTF1(buf, sizeof(buf), "--%s", o->onames->oname);
45 else
46 SNPRINTF2(buf, sizeof(buf), "-%c (--%s)", o->oletter, o->onames->oname);
47 return (buf);
48}
49
50/*
51 * Return a string suitable for printing as the "name" of an option.
52 * For example, if the option letter is 'x', just return "-x".
53 */
54 public char *
55propt(c)
56 int c;
57{
58 static char buf[8];
59
60 sprintf(buf, "-%s", prchar(c));
61 return (buf);
62}
63
64/*
65 * Scan an argument (either from the command line or from the
66 * LESS environment variable) and process it.
67 */
68 public void
69scan_option(s)
70 char *s;
71{

--- 20 unchanged lines hidden (view full) ---

92 if (pendopt != NULL)
93 {
94 switch (pendopt->otype & OTYPE)
95 {
96 case STRING:
97 (*pendopt->ofunc)(INIT, s);
98 break;
99 case NUMBER:
100 printopt = opt_desc(pendopt);
101 *(pendopt->ovar) = getnum(&s, printopt, (int*)NULL);
102 break;
103 }
104 pendopt = NULL;
105 return;
106 }
107
108 set_default = FALSE;

--- 175 unchanged lines hidden (view full) ---

284 * Used by the "-" and "_" commands.
285 * how_toggle may be:
286 * OPT_NO_TOGGLE just report the current setting, without changing it.
287 * OPT_TOGGLE invert the current setting
288 * OPT_UNSET set to the default value
289 * OPT_SET set to the inverse of the default value
290 */
291 public void
292toggle_option(o, lower, s, how_toggle)
293 struct loption *o;
294 int lower;
295 char *s;
296 int how_toggle;
297{
298 register int num;
299 int no_prompt;
300 int err;
301 PARG parg;
302
303 no_prompt = (how_toggle & OPT_NO_PROMPT);
304 how_toggle &= ~OPT_NO_PROMPT;
305
306 if (o == NULL)
307 {
308 error("No such option", NULL_PARG);
309 return;
310 }
311
312 if (how_toggle == OPT_TOGGLE && (o->otype & NO_TOGGLE))
313 {
314 parg.p_string = opt_desc(o);
315 error("Cannot change the %s option", &parg);
316 return;
317 }
318
319 if (how_toggle == OPT_NO_TOGGLE && (o->otype & NO_QUERY))
320 {
321 parg.p_string = opt_desc(o);
322 error("Cannot query the %s option", &parg);
323 return;
324 }
325
326 /*
327 * Check for something which appears to be a do_toggle
328 * (because the "-" command was used), but really is not.
329 * This could be a string option with no string, or

--- 43 unchanged lines hidden (view full) ---

373 * If user gave the lower case letter, then switch
374 * to 1 unless already 1, in which case make it 0.
375 * If user gave the upper case letter, then switch
376 * to 2 unless already 2, in which case make it 0.
377 */
378 switch (how_toggle)
379 {
380 case OPT_TOGGLE:
381 *(o->ovar) = flip_triple(*(o->ovar), lower);
382 break;
383 case OPT_UNSET:
384 *(o->ovar) = o->odefault;
385 break;
386 case OPT_SET:
387 *(o->ovar) = flip_triple(o->odefault, lower);
388 break;
389 }
390 break;
391 case STRING:
392 /*
393 * String: don't do anything here.
394 * The handling function will do everything.
395 */

--- 85 unchanged lines hidden (view full) ---

481{
482 if (lc)
483 return ((val == OPT_ON) ? OPT_OFF : OPT_ON);
484 else
485 return ((val == OPT_ONPLUS) ? OPT_OFF : OPT_ONPLUS);
486}
487
488/*
489 * Determine if an option takes a parameter.
490 */
491 public int
492opt_has_param(o)
493 struct loption *o;
494{
495 if (o == NULL)
496 return (0);
497 if (o->otype & (BOOL|TRIPLE|NOVAR|NO_TOGGLE))
498 return (0);
499 return (1);
500}
501
502/*
503 * Return the prompt to be used for a given option letter.
504 * Only string and number valued options have prompts.
505 */
506 public char *
507opt_prompt(o)
508 struct loption *o;
509{
510 if (o == NULL || (o->otype & (STRING|NUMBER)) == 0)
511 return ("?");
512 return (o->odesc[0]);
513}
514
515/*
516 * Return whether or not there is a string option pending;
517 * that is, if the previous option was a string-valued option letter
518 * (like -P) without a following string.
519 * In that case, the current option is taken to be the string for

--- 18 unchanged lines hidden (view full) ---

538}
539
540/*
541 * Print error message if a STRING type option is not followed by a string.
542 */
543 public void
544nopendopt()
545{
546 nostring(opt_desc(pendopt));
547}
548
549/*
550 * Scan to end of string or to an END_OPTION_STRING character.
551 * In the latter case, replace the char with a null char.
552 * Return a pointer to the remainder of the string, if any.
553 */
554 static char *

--- 148 unchanged lines hidden ---