list.c (8874) | list.c (74769) |
---|---|
1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint | 1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint |
35#if 0 |
|
35static char sccsid[] = "@(#)list.c 8.2 (Berkeley) 4/19/94"; | 36static char sccsid[] = "@(#)list.c 8.2 (Berkeley) 4/19/94"; |
37#endif 38static const char rcsid[] = 39 "$FreeBSD: head/usr.bin/mail/list.c 74769 2001-03-25 04:57:05Z mikeh $"; |
|
36#endif /* not lint */ 37 38#include "rcv.h" 39#include <ctype.h> 40#include "extern.h" 41 42/* 43 * Mail -- a mail program --- 342 unchanged lines hidden (view full) --- 386int 387getrawlist(line, argv, argc) 388 char line[]; 389 char **argv; 390 int argc; 391{ 392 register char c, *cp, *cp2, quotec; 393 int argn; | 40#endif /* not lint */ 41 42#include "rcv.h" 43#include <ctype.h> 44#include "extern.h" 45 46/* 47 * Mail -- a mail program --- 342 unchanged lines hidden (view full) --- 390int 391getrawlist(line, argv, argc) 392 char line[]; 393 char **argv; 394 int argc; 395{ 396 register char c, *cp, *cp2, quotec; 397 int argn; |
394 char linebuf[BUFSIZ]; | 398 char *linebuf; 399 size_t linebufsize = BUFSIZ; |
395 | 400 |
401 if ((linebuf = (char *)malloc(linebufsize)) == NULL) 402 err(1, "Out of memory"); 403 |
|
396 argn = 0; 397 cp = line; 398 for (;;) { 399 for (; *cp == ' ' || *cp == '\t'; cp++) 400 ; 401 if (*cp == '\0') 402 break; 403 if (argn >= argc - 1) { 404 printf( 405 "Too many elements in the list; excess discarded.\n"); 406 break; 407 } 408 cp2 = linebuf; 409 quotec = '\0'; 410 while ((c = *cp) != '\0') { | 404 argn = 0; 405 cp = line; 406 for (;;) { 407 for (; *cp == ' ' || *cp == '\t'; cp++) 408 ; 409 if (*cp == '\0') 410 break; 411 if (argn >= argc - 1) { 412 printf( 413 "Too many elements in the list; excess discarded.\n"); 414 break; 415 } 416 cp2 = linebuf; 417 quotec = '\0'; 418 while ((c = *cp) != '\0') { |
419 /* Allocate more space if necessary */ 420 if (cp2 - linebuf == linebufsize - 1) { 421 linebufsize += BUFSIZ; 422 if ((linebuf = realloc(linebuf, linebufsize)) == NULL) 423 err(1, "Out of memory"); 424 cp2 = linebuf + linebufsize - BUFSIZ - 1; 425 } |
|
411 cp++; 412 if (quotec != '\0') { 413 if (c == quotec) 414 quotec = '\0'; 415 else if (c == '\\') 416 switch (c = *cp++) { 417 case '\0': 418 *cp2++ = '\\'; --- 49 unchanged lines hidden (view full) --- 468 break; 469 else 470 *cp2++ = c; 471 } 472 *cp2 = '\0'; 473 argv[argn++] = savestr(linebuf); 474 } 475 argv[argn] = NOSTR; | 426 cp++; 427 if (quotec != '\0') { 428 if (c == quotec) 429 quotec = '\0'; 430 else if (c == '\\') 431 switch (c = *cp++) { 432 case '\0': 433 *cp2++ = '\\'; --- 49 unchanged lines hidden (view full) --- 483 break; 484 else 485 *cp2++ = c; 486 } 487 *cp2 = '\0'; 488 argv[argn++] = savestr(linebuf); 489 } 490 argv[argn] = NOSTR; |
491 free(linebuf); |
|
476 return argn; 477} 478 479/* 480 * scan out a single lexical item and return its token number, 481 * updating the string pointer passed **p. Also, store the value 482 * of the number or string scanned in lexnumber or lexstring as 483 * appropriate. In any event, store the scanned `thing' in lexstring. --- 116 unchanged lines hidden (view full) --- 600/* 601 * Unscan the named token by pushing it onto the regret stack. 602 */ 603void 604regret(token) 605 int token; 606{ 607 if (++regretp >= REGDEP) | 492 return argn; 493} 494 495/* 496 * scan out a single lexical item and return its token number, 497 * updating the string pointer passed **p. Also, store the value 498 * of the number or string scanned in lexnumber or lexstring as 499 * appropriate. In any event, store the scanned `thing' in lexstring. --- 116 unchanged lines hidden (view full) --- 616/* 617 * Unscan the named token by pushing it onto the regret stack. 618 */ 619void 620regret(token) 621 int token; 622{ 623 if (++regretp >= REGDEP) |
608 panic("Too many regrets"); | 624 errx(1, "Too many regrets"); |
609 regretstack[regretp] = token; 610 lexstring[STRINGLEN-1] = '\0'; 611 string_stack[regretp] = savestr(lexstring); 612 numberstack[regretp] = lexnumber; 613} 614 615/* 616 * Reset all the scanner global variables. --- 40 unchanged lines hidden (view full) --- 657 658 if (!*str) /* null string matches nothing instead of everything */ 659 return 0; 660 backup = cp2 = nameof(&message[mesg - 1], 0); 661 cp = str; 662 while (*cp2) { 663 if (*cp == 0) 664 return(1); | 625 regretstack[regretp] = token; 626 lexstring[STRINGLEN-1] = '\0'; 627 string_stack[regretp] = savestr(lexstring); 628 numberstack[regretp] = lexnumber; 629} 630 631/* 632 * Reset all the scanner global variables. --- 40 unchanged lines hidden (view full) --- 673 674 if (!*str) /* null string matches nothing instead of everything */ 675 return 0; 676 backup = cp2 = nameof(&message[mesg - 1], 0); 677 cp = str; 678 while (*cp2) { 679 if (*cp == 0) 680 return(1); |
665 if (raise(*cp++) != raise(*cp2++)) { | 681 if (toupper(*cp++) != toupper(*cp2++)) { |
666 cp2 = ++backup; 667 cp = str; 668 } 669 } 670 return(*cp == 0); 671} 672 673/* 674 * See if the given string matches inside the subject field of the 675 * given message. For the purpose of the scan, we ignore case differences. 676 * If it does, return true. The string search argument is assumed to 677 * have the form "/search-string." If it is of the form "/," we use the 678 * previous search string. 679 */ 680 | 682 cp2 = ++backup; 683 cp = str; 684 } 685 } 686 return(*cp == 0); 687} 688 689/* 690 * See if the given string matches inside the subject field of the 691 * given message. For the purpose of the scan, we ignore case differences. 692 * If it does, return true. The string search argument is assumed to 693 * have the form "/search-string." If it is of the form "/," we use the 694 * previous search string. 695 */ 696 |
681char lastscan[128]; | 697char lastscan[STRINGLEN]; |
682int 683matchsubj(str, mesg) 684 char *str; 685 int mesg; 686{ 687 register struct message *mp; 688 register char *cp, *cp2, *backup; 689 690 str++; | 698int 699matchsubj(str, mesg) 700 char *str; 701 int mesg; 702{ 703 register struct message *mp; 704 register char *cp, *cp2, *backup; 705 706 str++; |
691 if (strlen(str) == 0) | 707 if (*str == '\0') |
692 str = lastscan; 693 else | 708 str = lastscan; 709 else |
694 strcpy(lastscan, str); | 710 strlcpy(lastscan, str, sizeof(lastscan)); |
695 mp = &message[mesg-1]; 696 697 /* 698 * Now look, ignoring case, for the word in the string. 699 */ 700 | 711 mp = &message[mesg-1]; 712 713 /* 714 * Now look, ignoring case, for the word in the string. 715 */ 716 |
701 if (value("searchheaders") && (cp = index(str, ':'))) { | 717 if (value("searchheaders") && (cp = strchr(str, ':'))) { |
702 *cp++ = '\0'; 703 cp2 = hfield(str, mp); 704 cp[-1] = ':'; 705 str = cp; 706 } else { 707 cp = str; 708 cp2 = hfield("subject", mp); 709 } 710 if (cp2 == NOSTR) 711 return(0); 712 backup = cp2; 713 while (*cp2) { 714 if (*cp == 0) 715 return(1); | 718 *cp++ = '\0'; 719 cp2 = hfield(str, mp); 720 cp[-1] = ':'; 721 str = cp; 722 } else { 723 cp = str; 724 cp2 = hfield("subject", mp); 725 } 726 if (cp2 == NOSTR) 727 return(0); 728 backup = cp2; 729 while (*cp2) { 730 if (*cp == 0) 731 return(1); |
716 if (raise(*cp++) != raise(*cp2++)) { | 732 if (toupper(*cp++) != toupper(*cp2++)) { |
717 cp2 = ++backup; 718 cp = str; 719 } 720 } 721 return(*cp == 0); 722} 723 724/* 725 * Mark the named message by setting its mark bit. 726 */ 727void 728mark(mesg) 729 int mesg; 730{ 731 register int i; 732 733 i = mesg; 734 if (i < 1 || i > msgCount) | 733 cp2 = ++backup; 734 cp = str; 735 } 736 } 737 return(*cp == 0); 738} 739 740/* 741 * Mark the named message by setting its mark bit. 742 */ 743void 744mark(mesg) 745 int mesg; 746{ 747 register int i; 748 749 i = mesg; 750 if (i < 1 || i > msgCount) |
735 panic("Bad message number to mark"); | 751 errx(1, "Bad message number to mark"); |
736 message[i-1].m_flag |= MMARK; 737} 738 739/* 740 * Unmark the named message. 741 */ 742void 743unmark(mesg) 744 int mesg; 745{ 746 register int i; 747 748 i = mesg; 749 if (i < 1 || i > msgCount) | 752 message[i-1].m_flag |= MMARK; 753} 754 755/* 756 * Unmark the named message. 757 */ 758void 759unmark(mesg) 760 int mesg; 761{ 762 register int i; 763 764 i = mesg; 765 if (i < 1 || i > msgCount) |
750 panic("Bad message number to unmark"); | 766 errx(1, "Bad message number to unmark"); |
751 message[i-1].m_flag &= ~MMARK; 752} 753 754/* 755 * Return the message number corresponding to the passed meta character. 756 */ 757int 758metamess(meta, f) --- 43 unchanged lines hidden --- | 767 message[i-1].m_flag &= ~MMARK; 768} 769 770/* 771 * Return the message number corresponding to the passed meta character. 772 */ 773int 774metamess(meta, f) --- 43 unchanged lines hidden --- |