|
|
1.1 ! root 1: #ident "@(#)head.c 1.3 'attmail mail(1) command'" ! 2: #ident "@(#)mailx:head.c 1.3.1.1" ! 3: /* Copyright (c) 1984 AT&T */ ! 4: /* All Rights Reserved */ ! 5: ! 6: /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T */ ! 7: /* The copyright notice above does not evidence any */ ! 8: /* actual or intended publication of such source code. */ ! 9: ! 10: #ident "@(#)mailx:head.c 1.3" ! 11: ! 12: #include "rcv.h" ! 13: ! 14: /* ! 15: * mailx -- a modified version of a University of California at Berkeley ! 16: * mail program ! 17: * ! 18: * Routines for processing and detecting headlines. ! 19: */ ! 20: ! 21: static char *copyin(); ! 22: static int isname(); ! 23: static char *nextword(); ! 24: ! 25: /* ! 26: * Split a headline into its useful components. ! 27: * Copy the line into dynamic string space, then set ! 28: * pointers into the copied line in the passed headline ! 29: * structure. Actually, it scans. ! 30: */ ! 31: void ! 32: parse(line, hl, pbuf) ! 33: char line[], pbuf[]; ! 34: struct headline *hl; ! 35: { ! 36: register char *cp, *dp; ! 37: char *sp; ! 38: char word[LINESIZE]; ! 39: ! 40: hl->l_from = NOSTR; ! 41: hl->l_tty = NOSTR; ! 42: hl->l_date = NOSTR; ! 43: cp = line; ! 44: sp = pbuf; ! 45: ! 46: /* ! 47: * Skip the first "word" of the line, which should be "From" ! 48: * anyway. ! 49: */ ! 50: ! 51: cp = nextword(cp, word); ! 52: dp = nextword(cp, word); ! 53: if (dp == NOSTR) return; ! 54: if (!equal(word, "")) ! 55: hl->l_from = copyin(word, &sp); ! 56: if (isname(dp, "tty", 3)) { ! 57: cp = nextword(dp, word); ! 58: hl->l_tty = copyin(word, &sp); ! 59: if (cp != NOSTR) ! 60: hl->l_date = copyin(cp, &sp); ! 61: } ! 62: else ! 63: if (dp != NOSTR) ! 64: hl->l_date = copyin(dp, &sp); ! 65: } ! 66: ! 67: /* ! 68: * Copy the string on the left into the string on the right ! 69: * and bump the right (reference) string pointer by the length. ! 70: * Thus, dynamically allocate space in the right string, copying ! 71: * the left string into it. ! 72: */ ! 73: ! 74: static char * ! 75: copyin(src, space) ! 76: char src[]; ! 77: char **space; ! 78: { ! 79: register char *cp, *top; ! 80: register int s; ! 81: ! 82: s = strlen(src); ! 83: cp = *space; ! 84: top = cp; ! 85: strcpy(cp, src); ! 86: cp += s + 1; ! 87: *space = cp; ! 88: return(top); ! 89: } ! 90: ! 91: static ! 92: isname(as1, as2, acount) ! 93: char *as1, *as2; ! 94: { ! 95: register char *s1, *s2; ! 96: register count; ! 97: ! 98: s1 = as1; ! 99: s2 = as2; ! 100: count = acount; ! 101: if (count > 0) ! 102: do ! 103: if (*s1++ != *s2++) ! 104: return(0); ! 105: while (--count); ! 106: return(1); ! 107: } ! 108: ! 109: /* ! 110: * Collect a liberal (space, tab delimited) word into the word buffer ! 111: * passed. Also, return a pointer to the next word following that, ! 112: * or NOSTR if none follow. ! 113: */ ! 114: ! 115: static char * ! 116: nextword(wp, wbuf) ! 117: char wp[], wbuf[]; ! 118: { ! 119: register char *cp, *cp2; ! 120: ! 121: if ((cp = wp) == NOSTR) { ! 122: copy("", wbuf); ! 123: return(NOSTR); ! 124: } ! 125: cp2 = wbuf; ! 126: while (!any(*cp, " \t") && *cp != '\0') ! 127: if (*cp == '"') { ! 128: *cp2++ = *cp++; ! 129: while (*cp != '\0' && *cp != '"') ! 130: *cp2++ = *cp++; ! 131: if (*cp == '"') ! 132: *cp2++ = *cp++; ! 133: } else ! 134: *cp2++ = *cp++; ! 135: *cp2 = '\0'; ! 136: while (any(*cp, " \t")) ! 137: cp++; ! 138: if (*cp == '\0') ! 139: return(NOSTR); ! 140: return(cp); ! 141: } ! 142: ! 143: /* ! 144: * Copy str1 to str2, return pointer to null in str2. ! 145: */ ! 146: ! 147: char * ! 148: copy(str1, str2) ! 149: char *str1, *str2; ! 150: { ! 151: register char *s1, *s2; ! 152: ! 153: s1 = str1; ! 154: s2 = str2; ! 155: while (*s1) ! 156: *s2++ = *s1++; ! 157: *s2 = 0; ! 158: return(s2); ! 159: } ! 160: ! 161: /* ! 162: * Is ch any of the characters in str? ! 163: */ ! 164: ! 165: any(ch, str) ! 166: char *str; ! 167: { ! 168: register char *f; ! 169: register c; ! 170: ! 171: f = str; ! 172: c = ch; ! 173: while (*f) ! 174: if (c == *f++) ! 175: return(1); ! 176: return(0); ! 177: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.