option.c (161475) | option.c (170256) |
---|---|
1/* | 1/* |
2 * Copyright (C) 1984-2004 Mark Nudelman | 2 * Copyright (C) 1984-2007 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 --- 13 unchanged lines hidden (view full) --- 24static struct loption *pendopt; 25public int plusoption = FALSE; 26 27static char *propt(); 28static char *optstring(); 29static int flip_triple(); 30 31extern int screen_trashed; | 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 --- 13 unchanged lines hidden (view full) --- 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; |
|
32extern char *every_first_cmd; 33 34/* 35 * Scan an argument (either from the command line or from the 36 * LESS environment variable) and process it. 37 */ 38 public void 39scan_option(s) --- 87 unchanged lines hidden (view full) --- 127 /* 128 * Special "more" compatibility form "-<number>" 129 * instead of -z<number> to set the scrolling 130 * window size. 131 */ 132 s--; 133 optc = 'z'; 134 break; | 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) --- 87 unchanged lines hidden (view full) --- 129 /* 130 * Special "more" compatibility form "-<number>" 131 * instead of -z<number> to set the scrolling 132 * window size. 133 */ 134 s--; 135 optc = 'z'; 136 break; |
137 case 'n': 138 if (less_is_more) 139 optc = 'z'; 140 break; |
|
135 } 136 137 /* 138 * Not a special case. 139 * Look up the option letter in the option table. 140 */ 141 err = 0; 142 if (optname == NULL) --- 436 unchanged lines hidden (view full) --- 579 } 580 break; 581 } 582 } 583 return (p); 584} 585 586/* | 141 } 142 143 /* 144 * Not a special case. 145 * Look up the option letter in the option table. 146 */ 147 err = 0; 148 if (optname == NULL) --- 436 unchanged lines hidden (view full) --- 585 } 586 break; 587 } 588 } 589 return (p); 590} 591 592/* |
593 */ 594 static int 595num_error(printopt, errp) 596 char *printopt; 597 int *errp; 598{ 599 PARG parg; 600 601 if (errp != NULL) 602 { 603 *errp = TRUE; 604 return (-1); 605 } 606 if (printopt != NULL) 607 { 608 parg.p_string = printopt; 609 error("Number is required after %s", &parg); 610 } 611 quit(QUIT_ERROR); 612 /* NOTREACHED */ 613 return (-1); 614} 615 616/* |
|
587 * Translate a string into a number. 588 * Like atoi(), but takes a pointer to a char *, and updates 589 * the char * to point after the translated number. 590 */ 591 public int 592getnum(sp, printopt, errp) 593 char **sp; 594 char *printopt; 595 int *errp; 596{ 597 register char *s; 598 register int n; 599 register int neg; | 617 * Translate a string into a number. 618 * Like atoi(), but takes a pointer to a char *, and updates 619 * the char * to point after the translated number. 620 */ 621 public int 622getnum(sp, printopt, errp) 623 char **sp; 624 char *printopt; 625 int *errp; 626{ 627 register char *s; 628 register int n; 629 register int neg; |
600 PARG parg; | |
601 602 s = skipsp(*sp); 603 neg = FALSE; 604 if (*s == '-') 605 { 606 neg = TRUE; 607 s++; 608 } 609 if (*s < '0' || *s > '9') | 630 631 s = skipsp(*sp); 632 neg = FALSE; 633 if (*s == '-') 634 { 635 neg = TRUE; 636 s++; 637 } 638 if (*s < '0' || *s > '9') |
610 { 611 if (errp != NULL) 612 { 613 *errp = TRUE; 614 return (-1); 615 } 616 if (printopt != NULL) 617 { 618 parg.p_string = printopt; 619 error("Number is required after %s", &parg); 620 } 621 quit(QUIT_ERROR); 622 } | 639 return (num_error(printopt, errp)); |
623 624 n = 0; 625 while (*s >= '0' && *s <= '9') 626 n = 10 * n + *s++ - '0'; 627 *sp = s; 628 if (errp != NULL) 629 *errp = FALSE; 630 if (neg) 631 n = -n; 632 return (n); 633} | 640 641 n = 0; 642 while (*s >= '0' && *s <= '9') 643 n = 10 * n + *s++ - '0'; 644 *sp = s; 645 if (errp != NULL) 646 *errp = FALSE; 647 if (neg) 648 n = -n; 649 return (n); 650} |
651 652/* 653 * Translate a string into a fraction, represented by the part of a 654 * number which would follow a decimal point. 655 * The value of the fraction is returned as parts per NUM_FRAC_DENOM. 656 * That is, if "n" is returned, the fraction intended is n/NUM_FRAC_DENOM. 657 */ 658 public long 659getfraction(sp, printopt, errp) 660 char **sp; 661 char *printopt; 662 int *errp; 663{ 664 register char *s; 665 long frac = 0; 666 int fraclen = 0; 667 668 s = skipsp(*sp); 669 if (*s < '0' || *s > '9') 670 return (num_error(printopt, errp)); 671 672 for ( ; *s >= '0' && *s <= '9'; s++) 673 { 674 frac = (frac * 10) + (*s - '0'); 675 fraclen++; 676 } 677 if (fraclen > NUM_LOG_FRAC_DENOM) 678 while (fraclen-- > NUM_LOG_FRAC_DENOM) 679 frac /= 10; 680 else 681 while (fraclen++ < NUM_LOG_FRAC_DENOM) 682 frac *= 10; 683 *sp = s; 684 if (errp != NULL) 685 *errp = FALSE; 686 return (frac); 687} 688 689 690/* 691 * Get the value of the -e flag. 692 */ 693 public int 694get_quit_at_eof() 695{ 696 if (!less_is_more) 697 return quit_at_eof; 698 /* When less_is_more is set, the -e flag semantics are different. */ 699 return quit_at_eof ? OPT_ON : OPT_ONPLUS; 700} |
|