Deleted Added
full compact
option.c (195941) option.c (221715)
1/*
1/*
2 * Copyright (C) 1984-2009 Mark Nudelman
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
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 *propt();
28static char *optstring();
29static int flip_triple();
30
31extern int screen_trashed;
32extern int less_is_more;
33extern int quit_at_eof;
34extern char *every_first_cmd;
35
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
36/*
37 * Scan an argument (either from the command line or from the
38 * LESS environment variable) and process it.
39 */
40 public void
41scan_option(s)
42 char *s;
43{

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

64 if (pendopt != NULL)
65 {
66 switch (pendopt->otype & OTYPE)
67 {
68 case STRING:
69 (*pendopt->ofunc)(INIT, s);
70 break;
71 case NUMBER:
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:
72 printopt = propt(pendopt->oletter);
100 printopt = opt_desc(pendopt);
73 *(pendopt->ovar) = getnum(&s, printopt, (int*)NULL);
74 break;
75 }
76 pendopt = NULL;
77 return;
78 }
79
80 set_default = FALSE;

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

256 * Used by the "-" and "_" commands.
257 * how_toggle may be:
258 * OPT_NO_TOGGLE just report the current setting, without changing it.
259 * OPT_TOGGLE invert the current setting
260 * OPT_UNSET set to the default value
261 * OPT_SET set to the inverse of the default value
262 */
263 public void
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
264toggle_option(c, s, how_toggle)
265 int c;
292toggle_option(o, lower, s, how_toggle)
293 struct loption *o;
294 int lower;
266 char *s;
267 int how_toggle;
268{
295 char *s;
296 int how_toggle;
297{
269 register struct loption *o;
270 register int num;
271 int no_prompt;
272 int err;
273 PARG parg;
274
275 no_prompt = (how_toggle & OPT_NO_PROMPT);
276 how_toggle &= ~OPT_NO_PROMPT;
277
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
278 /*
279 * Look up the option letter in the option table.
280 */
281 o = findopt(c);
282 if (o == NULL)
283 {
306 if (o == NULL)
307 {
284 parg.p_string = propt(c);
285 error("There is no %s option", &parg);
308 error("No such option", NULL_PARG);
286 return;
287 }
288
289 if (how_toggle == OPT_TOGGLE && (o->otype & NO_TOGGLE))
290 {
309 return;
310 }
311
312 if (how_toggle == OPT_TOGGLE && (o->otype & NO_TOGGLE))
313 {
291 parg.p_string = propt(c);
314 parg.p_string = opt_desc(o);
292 error("Cannot change the %s option", &parg);
293 return;
315 error("Cannot change the %s option", &parg);
316 return;
294 }
317 }
295
296 if (how_toggle == OPT_NO_TOGGLE && (o->otype & NO_QUERY))
297 {
318
319 if (how_toggle == OPT_NO_TOGGLE && (o->otype & NO_QUERY))
320 {
298 parg.p_string = propt(c);
321 parg.p_string = opt_desc(o);
299 error("Cannot query the %s option", &parg);
300 return;
301 }
302
303 /*
304 * Check for something which appears to be a do_toggle
305 * (because the "-" command was used), but really is not.
306 * This could be a string option with no string, or

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

350 * If user gave the lower case letter, then switch
351 * to 1 unless already 1, in which case make it 0.
352 * If user gave the upper case letter, then switch
353 * to 2 unless already 2, in which case make it 0.
354 */
355 switch (how_toggle)
356 {
357 case OPT_TOGGLE:
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:
358 *(o->ovar) = flip_triple(*(o->ovar),
359 ASCII_IS_LOWER(c));
381 *(o->ovar) = flip_triple(*(o->ovar), lower);
360 break;
361 case OPT_UNSET:
362 *(o->ovar) = o->odefault;
363 break;
364 case OPT_SET:
382 break;
383 case OPT_UNSET:
384 *(o->ovar) = o->odefault;
385 break;
386 case OPT_SET:
365 *(o->ovar) = flip_triple(o->odefault,
366 ASCII_IS_LOWER(c));
387 *(o->ovar) = flip_triple(o->odefault, lower);
367 break;
368 }
369 break;
370 case STRING:
371 /*
372 * String: don't do anything here.
373 * The handling function will do everything.
374 */

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

460{
461 if (lc)
462 return ((val == OPT_ON) ? OPT_OFF : OPT_ON);
463 else
464 return ((val == OPT_ONPLUS) ? OPT_OFF : OPT_ONPLUS);
465}
466
467/*
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/*
468 * Return a string suitable for printing as the "name" of an option.
469 * For example, if the option letter is 'x', just return "-x".
489 * Determine if an option takes a parameter.
470 */
490 */
471 static char *
472propt(c)
473 int c;
474{
475 static char buf[8];
476
477 sprintf(buf, "-%s", prchar(c));
478 return (buf);
479}
480
481/*
482 * Determine if an option is a single character option (BOOL or TRIPLE),
483 * or if it a multi-character option (NUMBER).
484 */
485 public int
491 public int
486single_char_option(c)
487 int c;
492opt_has_param(o)
493 struct loption *o;
488{
494{
489 register struct loption *o;
490
491 o = findopt(c);
492 if (o == NULL)
495 if (o == NULL)
493 return (TRUE);
494 return ((o->otype & (BOOL|TRIPLE|NOVAR|NO_TOGGLE)) != 0);
496 return (0);
497 if (o->otype & (BOOL|TRIPLE|NOVAR|NO_TOGGLE))
498 return (0);
499 return (1);
495}
496
497/*
498 * Return the prompt to be used for a given option letter.
499 * Only string and number valued options have prompts.
500 */
501 public char *
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 *
502opt_prompt(c)
503 int c;
507opt_prompt(o)
508 struct loption *o;
504{
509{
505 register struct loption *o;
506
507 o = findopt(c);
508 if (o == NULL || (o->otype & (STRING|NUMBER)) == 0)
510 if (o == NULL || (o->otype & (STRING|NUMBER)) == 0)
509 return (NULL);
511 return ("?");
510 return (o->odesc[0]);
511}
512
513/*
514 * Return whether or not there is a string option pending;
515 * that is, if the previous option was a string-valued option letter
516 * (like -P) without a following string.
517 * In that case, the current option is taken to be the string for

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

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

--- 148 unchanged lines hidden ---
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 ---