Deleted Added
sdiff udiff text old ( 195941 ) new ( 221715 )
full compact
1/*
2 * Copyright (C) 1984-2009 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 *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
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:
72 printopt = propt(pendopt->oletter);
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
264toggle_option(c, s, how_toggle)
265 int c;
266 char *s;
267 int how_toggle;
268{
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
278 /*
279 * Look up the option letter in the option table.
280 */
281 o = findopt(c);
282 if (o == NULL)
283 {
284 parg.p_string = propt(c);
285 error("There is no %s option", &parg);
286 return;
287 }
288
289 if (how_toggle == OPT_TOGGLE && (o->otype & NO_TOGGLE))
290 {
291 parg.p_string = propt(c);
292 error("Cannot change the %s option", &parg);
293 return;
294 }
295
296 if (how_toggle == OPT_NO_TOGGLE && (o->otype & NO_QUERY))
297 {
298 parg.p_string = propt(c);
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:
358 *(o->ovar) = flip_triple(*(o->ovar),
359 ASCII_IS_LOWER(c));
360 break;
361 case OPT_UNSET:
362 *(o->ovar) = o->odefault;
363 break;
364 case OPT_SET:
365 *(o->ovar) = flip_triple(o->odefault,
366 ASCII_IS_LOWER(c));
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/*
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".
470 */
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
486single_char_option(c)
487 int c;
488{
489 register struct loption *o;
490
491 o = findopt(c);
492 if (o == NULL)
493 return (TRUE);
494 return ((o->otype & (BOOL|TRIPLE|NOVAR|NO_TOGGLE)) != 0);
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 *
502opt_prompt(c)
503 int c;
504{
505 register struct loption *o;
506
507 o = findopt(c);
508 if (o == NULL || (o->otype & (STRING|NUMBER)) == 0)
509 return (NULL);
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{
544 nostring(propt(pendopt->oletter));
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 ---