1*14342Skarels /* bugfiler.c 4.3 83/08/05 */ 212375Sralph /* 312375Sralph * Bug report processing program. 412375Sralph * It is designed to be invoked by alias(5) and to be compatible with mh. 512375Sralph */ 612375Sralph 712375Sralph #include <stdio.h> 812375Sralph #include <ctype.h> 912375Sralph #include <signal.h> 1012375Sralph #include <sys/types.h> 1112375Sralph #include <sys/stat.h> 1212695Sralph #include <sys/dir.h> 1312375Sralph 1412375Sralph char deliver[] = "/usr/local/lib/mh/deliver"; 1512375Sralph char unixtomh[] = "/usr/local/lib/mh/unixtomh"; 1612375Sralph char *maildir = "/ra/bugs/mail"; 1712375Sralph char ackfile[] = ".ack"; 1812375Sralph char errfile[] = ".format"; 1912375Sralph char sumfile[] = "summary"; 2012375Sralph char logfile[] = "errors/log"; 2112375Sralph char tmpname[] = "BfXXXXXX"; 2212375Sralph char draft[] = "RpXXXXXX"; 2312375Sralph 2412695Sralph char buf[8192]; 2512375Sralph char folder[MAXNAMLEN]; 2612375Sralph int num; 2712375Sralph int msg_prot = 0664; 2812375Sralph 2912375Sralph int debug; 3012375Sralph 3112375Sralph char *index(); 3212375Sralph char *rindex(); 3312375Sralph char *fixaddr(); 3412375Sralph 3512375Sralph main(argc, argv) 3612375Sralph char *argv[]; 3712375Sralph { 3812375Sralph register char *cp; 3912695Sralph register int n; 4012695Sralph int pfd[2]; 4112375Sralph 4212375Sralph if (argc > 3) { 4312375Sralph usage: 4412695Sralph fprintf(stderr, "Usage: bugfiler [-d] [-mmsg_mode] [maildir]\n"); 4512375Sralph exit(1); 4612375Sralph } 4712375Sralph while (--argc > 0) { 4812375Sralph cp = *++argv; 4912695Sralph if (*cp == '-') 5012695Sralph switch (cp[1]) { 5112375Sralph case 'd': 5212375Sralph debug++; 5312375Sralph break; 5412695Sralph 5512695Sralph case 'm': /* set message protection */ 5612695Sralph n = 0; 5712695Sralph for (cp += 2; *cp >= '0' && *cp <= '7'; ) 5812695Sralph n = (n << 3) + (*cp++ - '0'); 5912695Sralph msg_prot = n & 0777; 6012695Sralph break; 6112695Sralph 6212375Sralph default: 6312375Sralph goto usage; 6412375Sralph } 6512375Sralph else 6612375Sralph maildir = cp; 6712375Sralph } 6812695Sralph if (!debug) 6912695Sralph freopen(logfile, "a", stderr); 7012695Sralph 7112375Sralph if (chdir(maildir) < 0) { 7212375Sralph fprintf(stderr, "can't chdir to %s\n", maildir); 7312375Sralph exit(1); 7412375Sralph } 7512695Sralph umask(0); 7612695Sralph 7712695Sralph #ifdef UNIXCOMP 7812695Sralph /* 7912695Sralph * Convert UNIX style mail to mh style by filtering stdin through 8012695Sralph * unixtomh. 8112695Sralph */ 8212695Sralph if (pipe(pfd) >= 0) { 8312695Sralph while ((n = fork()) == -1) 8412695Sralph sleep(5); 8512695Sralph if (n == 0) { 8612695Sralph close(pfd[0]); 8712695Sralph dup2(pfd[1], 1); 8812695Sralph close(pfd[1]); 8912695Sralph execl(unixtomh, "unixtomh", 0); 9012695Sralph _exit(127); 9112695Sralph } 9212695Sralph close(pfd[1]); 9312695Sralph dup2(pfd[0], 0); 9412695Sralph close(pfd[0]); 9512695Sralph } 9612695Sralph #endif 9712695Sralph while (process()) 9812695Sralph ; 9912695Sralph exit(0); 10012375Sralph } 10112375Sralph 10212695Sralph /* states */ 10312695Sralph 10412695Sralph #define EOM 0 /* End of message seen */ 10512695Sralph #define FLD 1 /* Looking for header lines */ 10612695Sralph #define BODY 2 /* Looking for message body lines */ 10712695Sralph 10812375Sralph /* defines used for tag attributes */ 10912375Sralph 11012375Sralph #define H_REQ 01 11112695Sralph #define H_SAV 02 11212695Sralph #define H_HDR 04 11312695Sralph #define H_FND 010 11412375Sralph 11512375Sralph #define FROM_I headers[0].h_info 11612375Sralph #define SUBJECT_I headers[1].h_info 11712375Sralph #define INDEX &headers[2] 11812375Sralph #define INDEX_I headers[2].h_info 11912375Sralph #define DATE_I headers[3].h_info 12012375Sralph #define MSGID_I headers[4].h_info 12112375Sralph #define REPLYTO_I headers[5].h_info 12212375Sralph #define RETURNPATH_I headers[6].h_info 12312375Sralph #define TO_I headers[7].h_info 12412375Sralph #define CC_I headers[8].h_info 12512375Sralph #define FIX headers[11] 12612375Sralph 12712375Sralph struct header { 12812375Sralph char *h_tag; 12912375Sralph int h_flags; 13012375Sralph char *h_info; 13112375Sralph } headers[] = { 13212695Sralph "From", H_REQ|H_SAV|H_HDR, 0, 13312695Sralph "Subject", H_REQ|H_SAV|H_HDR, 0, 13412375Sralph "Index", H_REQ|H_SAV, 0, 13512695Sralph "Date", H_SAV|H_HDR, 0, 13612695Sralph "Message-Id", H_SAV|H_HDR, 0, 13712695Sralph "Reply-To", H_SAV|H_HDR, 0, 13812695Sralph "Return-Path", H_SAV|H_HDR, 0, 13912695Sralph "To", H_SAV|H_HDR, 0, 14012695Sralph "Cc", H_SAV|H_HDR, 0, 14112375Sralph "Description", H_REQ, 0, 14212375Sralph "Repeat-By", H_REQ, 0, 14312695Sralph "Fix", 0, 0, 14412375Sralph 0, 0, 0, 14512375Sralph }; 14612375Sralph 14712695Sralph struct header *findheader(); 14812695Sralph 14912375Sralph process() 15012375Sralph { 15112375Sralph register struct header *hp; 15212375Sralph register char *cp; 15312695Sralph register int c; 15412375Sralph char *info; 15512695Sralph int state, tmp; 15612695Sralph FILE *tfp, *fs; 15712375Sralph 15812375Sralph /* 15912375Sralph * Insure all headers are in a consistent 16012375Sralph * state. Anything left there is free'd. 16112375Sralph */ 16212375Sralph for (hp = headers; hp->h_tag; hp++) { 16312695Sralph hp->h_flags &= ~H_FND; 16412375Sralph if (hp->h_info) { 16512695Sralph free(hp->h_info); 16612375Sralph hp->h_info = 0; 16712375Sralph } 16812375Sralph } 16912375Sralph /* 17012375Sralph * Read the report and make a copy. Must conform to RFC822 and 17112375Sralph * be of the form... <tag>: <info> 17212695Sralph * Note that the input is expected to be in mh mail format 17312695Sralph * (i.e., messages are separated by lines of ^A's). 17412375Sralph */ 17512695Sralph while ((c = getchar()) == '\001' && peekc(stdin) == '\001') 17612695Sralph while (getchar() != '\n') 17712695Sralph ; 17812695Sralph if (c == EOF) 17912695Sralph return(0); /* all done */ 18012695Sralph 18112375Sralph mktemp(tmpname); 18212695Sralph if ((tmp = creat(tmpname, msg_prot)) < 0) { 18312695Sralph fprintf(stderr, "cannont create %s\n", tmpname); 18412695Sralph exit(1); 18512695Sralph } 18612695Sralph if ((tfp = fdopen(tmp, "w")) == NULL) { 18712695Sralph fprintf(stderr, "cannot fdopen temp file\n"); 18812695Sralph exit(1); 18912695Sralph } 19012695Sralph 19112695Sralph for (state = FLD; state != EOF && state != EOM; c = getchar()) { 19212695Sralph switch (state) { 19312695Sralph case FLD: 19412695Sralph if (c == '\n' || c == '-') 19512695Sralph goto body; 19612695Sralph for (cp = buf; c != ':'; c = getchar()) { 19712695Sralph if (cp < buf+sizeof(buf)-1 && c != '\n' && c != EOF) { 19812695Sralph *cp++ = c; 19912695Sralph continue; 20012695Sralph } 20112695Sralph *cp = '\0'; 20212695Sralph fputs(buf, tfp); 20312695Sralph state = EOF; 20412695Sralph while (c != EOF) { 20512695Sralph if (c == '\n') 20612695Sralph if ((tmp = peekc(stdin)) == EOF) 20712695Sralph break; 20812695Sralph else if (tmp == '\001') { 20912695Sralph state = EOM; 21012695Sralph break; 21112695Sralph } 21212695Sralph putc(c, tfp); 21312695Sralph c = getchar(); 21412695Sralph } 21512695Sralph fclose(tfp); 21612695Sralph goto badfmt; 21712695Sralph } 21812695Sralph *cp = '\0'; 21912695Sralph fprintf(tfp, "%s:", buf); 22012695Sralph hp = findheader(buf, state); 22112695Sralph 22212695Sralph for (cp = buf; ; ) { 22312695Sralph if (cp >= buf+sizeof(buf)-1) { 22412695Sralph fprintf(stderr, "field truncated\n"); 22512695Sralph while ((c = getchar()) != EOF && c != '\n') 22612695Sralph putc(c, tfp); 22712695Sralph } 22812695Sralph if ((c = getchar()) == EOF) { 22912695Sralph state = EOF; 23012695Sralph break; 23112695Sralph } 23212695Sralph putc(c, tfp); 23312695Sralph *cp++ = c; 23412695Sralph if (c == '\n') 23512695Sralph if ((c = peekc(stdin)) != ' ' && c != '\t') { 23612695Sralph if (c == EOF) 23712695Sralph state = EOF; 23812695Sralph else if (c == '\001') 23912695Sralph state = EOM; 24012695Sralph break; 24112695Sralph } 24212695Sralph } 24312695Sralph *cp = '\0'; 24412695Sralph cp = buf; 24512695Sralph break; 24612695Sralph 24712695Sralph body: 24812695Sralph state = BODY; 24912695Sralph case BODY: 25012695Sralph for (cp = buf; ; c = getchar()) { 25112695Sralph if (c == EOF) { 25212695Sralph state = EOF; 25312695Sralph break; 25412695Sralph } 25512695Sralph if (c == '\001' && peekc(stdin) == '\001') { 25612695Sralph state = EOM; 25712695Sralph break; 25812695Sralph } 25912695Sralph putc(c, tfp); 26012695Sralph *cp++ = c; 26112695Sralph if (cp >= buf+sizeof(buf)-1 || c == '\n') 26212695Sralph break; 26312695Sralph } 26412695Sralph *cp = '\0'; 26512695Sralph if ((cp = index(buf, ':')) == NULL) 26612695Sralph continue; 26712695Sralph *cp++ = '\0'; 26812695Sralph hp = findheader(buf, state); 26912695Sralph } 27012695Sralph 27112695Sralph /* 27212695Sralph * Don't save the info if the header wasn't found, we don't 27312695Sralph * care about the info, or the header is repeated. 27412695Sralph */ 27512695Sralph if (hp == NULL || !(hp->h_flags & H_SAV) || hp->h_info) 27612375Sralph continue; 27712375Sralph while (isspace(*cp)) 27812375Sralph cp++; 27912375Sralph if (*cp) { 28012375Sralph info = cp; 28112375Sralph while (*cp++); 28212375Sralph cp--; 28312375Sralph while (isspace(cp[-1])) 28412375Sralph *--cp = '\0'; 28512375Sralph hp->h_info = (char *) malloc(strlen(info) + 1); 28612695Sralph if (hp->h_info == NULL) { 28712695Sralph fprintf(stderr, "ran out of memory\n"); 28812375Sralph continue; 28912695Sralph } 29012375Sralph strcpy(hp->h_info, info); 29112375Sralph if (hp == INDEX) 29212375Sralph chkindex(hp); 29312375Sralph } 29412375Sralph } 29512695Sralph fclose(tfp); 29612375Sralph /* 29712375Sralph * Verify all the required pieces of information 29812375Sralph * are present. 29912375Sralph */ 30012695Sralph for (hp = headers; hp->h_tag; hp++) { 30112375Sralph /* 30212375Sralph * Mail the bug report back to the sender with a note 30312375Sralph * explaining they must conform to the specification. 30412375Sralph */ 30512695Sralph if ((hp->h_flags & H_REQ) && !(hp->h_flags & H_FND)) { 30612695Sralph if (debug) 30712695Sralph printf("Missing %s\n", hp->h_tag); 30812695Sralph badfmt: 30912695Sralph reply(FROM_I, errfile, tmpname); 31012695Sralph file(tmpname, "errors"); 31112695Sralph return(state == EOM); 31212695Sralph } 31312375Sralph } 31412375Sralph /* 31512695Sralph * Acknowledge receipt. 31612695Sralph */ 31712695Sralph reply(FROM_I, ackfile, (char *)0); 31812695Sralph file(tmpname, folder); 31912695Sralph /* 32012375Sralph * Append information about the new bug report 32112375Sralph * to the summary file. 32212375Sralph */ 32312695Sralph if ((fs = fopen(sumfile, "a")) == NULL) 32412375Sralph fprintf(stderr, "Can't open %s\n", sumfile); 32512695Sralph else { 32612695Sralph fprintf(fs, "%14.14s/%-3d ", folder, num); 32712695Sralph fprintf(fs, "%-51.51s Recv\n", INDEX_I); 32812695Sralph fprintf(fs, "\t\t %-51.51s\n", SUBJECT_I); 32912375Sralph } 33012375Sralph fclose(fs); 33112695Sralph return(state == EOM); 33212375Sralph } 33312375Sralph 33412375Sralph /* 33512695Sralph * Lookup the string in the list of headers and return a pointer 33612695Sralph * to the entry or NULL. 33712695Sralph */ 33812695Sralph 33912695Sralph struct header * 34012695Sralph findheader(name, state) 34112695Sralph char *name; 34212695Sralph int state; 34312695Sralph { 34412695Sralph register struct header *hp; 34512695Sralph 34612695Sralph if (debug) 34712695Sralph printf("findheader(%s, %d)\n", name, state); 34812695Sralph 34912695Sralph for (hp = headers; hp->h_tag; hp++) { 35012695Sralph if (!streq(hp->h_tag, buf)) 35112695Sralph continue; 35212695Sralph if ((hp->h_flags & H_HDR) && state != FLD) 35312695Sralph continue; 35412695Sralph hp->h_flags |= H_FND; 35512695Sralph return(hp); 35612695Sralph } 35712695Sralph return(NULL); 35812695Sralph } 35912695Sralph 36012695Sralph /* 36112375Sralph * Check the format of the Index information. 36212375Sralph * A side effect is to set the name of the folder if all is well. 36312375Sralph */ 36412375Sralph 36512375Sralph chkindex(hp) 36612375Sralph struct header *hp; 36712375Sralph { 36812695Sralph register char *cp1, *cp2; 36912375Sralph register char c; 37012375Sralph struct stat stbuf; 37112375Sralph 37212375Sralph if (debug) 37312695Sralph printf("chkindex(%s)\n", hp->h_info); 37412375Sralph /* 37512695Sralph * Strip of leading "/", "usr/", "src/" or "sys/". 37612695Sralph */ 37712695Sralph cp1 = hp->h_info; 37812695Sralph while (*cp1 == '/') 37912695Sralph cp1++; 38012695Sralph while (substr(cp1, "usr/") || substr(cp1, "src/") || substr(cp1, "sys/")) 38112695Sralph cp1 += 4; 38212695Sralph /* 38312375Sralph * Read the folder name and remove it from the index line. 38412375Sralph */ 38512695Sralph for (cp2 = folder; ;) { 38612695Sralph switch (c = *cp1++) { 38712695Sralph case '/': 38812695Sralph if (cp2 == folder) 38912695Sralph continue; 39012375Sralph break; 39112695Sralph case '\0': 39212695Sralph cp1--; 39312695Sralph break; 39412695Sralph case ' ': 39512695Sralph case '\t': 39612695Sralph while (isspace(*cp1)) 39712695Sralph cp1++; 39812695Sralph break; 39912695Sralph default: 40012695Sralph if (cp2 < folder+sizeof(folder)-1) 40112695Sralph *cp2++ = c; 40212695Sralph continue; 40312375Sralph } 40412695Sralph *cp2 = '\0'; 40512695Sralph for (cp2 = hp->h_info; *cp2++ = *cp1++; ) 40612695Sralph ; 40712695Sralph break; 40812375Sralph } 40912695Sralph if (debug) 41012695Sralph printf("folder = %s\n", folder); 41112375Sralph /* 41212375Sralph * Check to make sure we have a valid folder name 41312375Sralph */ 41412375Sralph if (stat(folder, &stbuf) == 0 && (stbuf.st_mode & S_IFMT) == S_IFDIR) 41512375Sralph return; 41612375Sralph /* 41712375Sralph * The Index line is not in the correct format so clear 41812695Sralph * the H_FND flag to mail back the correct format. 41912375Sralph */ 42012695Sralph hp->h_flags &= ~H_FND; 42112375Sralph } 42212375Sralph 42312375Sralph /* 42412375Sralph * Move or copy the file msg to the folder (directory). 42512375Sralph * A side effect is to set num to the number of the file in folder. 42612375Sralph */ 42712375Sralph 42812375Sralph file(fname, folder) 42912375Sralph char *fname, *folder; 43012375Sralph { 43112375Sralph register char *cp, n; 43212375Sralph char msgname[MAXNAMLEN*2+2]; 43312375Sralph struct stat stbuf; 43412375Sralph DIR *dirp; 43512375Sralph struct direct *d; 43612375Sralph 43712375Sralph if (debug) 43812695Sralph printf("file(%s, %s)\n", fname, folder); 43912375Sralph /* 44012375Sralph * Get the next number to use by finding the last message number 44112375Sralph * in folder and adding one. 44212375Sralph */ 44312375Sralph if ((dirp = opendir(folder)) == NULL) { 44412375Sralph fprintf(stderr, "Cannot open %s/%s\n", maildir, folder); 44512375Sralph return; 44612375Sralph } 44712375Sralph num = 0; 44812375Sralph while ((d = readdir(dirp)) != NULL) { 44912375Sralph cp = d->d_name; 45012375Sralph n = 0; 45112375Sralph while (isdigit(*cp)) 45212375Sralph n = n * 10 + (*cp++ - '0'); 45312375Sralph if (*cp == '\0' && n > num) 45412375Sralph num = n; 45512375Sralph } 45612375Sralph closedir(dirp); 45712375Sralph num++; 45812375Sralph /* 45912375Sralph * Create the destination file "folder/num" and copy fname to it. 46012375Sralph */ 46112375Sralph sprintf(msgname, "%s/%d", folder, num); 46212375Sralph if (link(fname, msgname) < 0) { 46312375Sralph int fin, fout; 46412375Sralph 46512695Sralph if ((fin = open(fname, 0)) < 0) { 46612695Sralph fprintf(stderr, "cannot open %s\n", fname); 46712375Sralph return; 46812695Sralph } 46912695Sralph if ((fout = creat(msgname, msg_prot)) < 0) { 47012695Sralph fprintf(stderr, "cannot create %s\n", msgname); 47112375Sralph return; 47212695Sralph } 47312695Sralph while ((n = read(fin, buf, sizeof(buf))) > 0) 47412695Sralph write(fout, buf, n); 47512375Sralph close(fin); 47612375Sralph close(fout); 47712375Sralph } 47812375Sralph unlink(fname); 47912375Sralph } 48012375Sralph 48112375Sralph /* 48212375Sralph * Mail file1 and file2 back to the sender. 48312375Sralph */ 48412375Sralph 48512375Sralph reply(to, file1, file2) 48612375Sralph char *to, *file1, *file2; 48712375Sralph { 48812375Sralph int (*istat)(), (*qstat)(); 48912375Sralph int pid, w, status, pfd[2], in; 49012375Sralph FILE *fout; 49112375Sralph 49212375Sralph if (debug) 49312695Sralph printf("reply(%s, %s, %s)\n", to, file1, file2); 49412695Sralph 49512375Sralph /* 49612375Sralph * Create a temporary file to put the message in. 49712375Sralph */ 49812375Sralph mktemp(draft); 49912375Sralph if ((fout = fopen(draft, "w")) == NULL) { 50012375Sralph fprintf(stderr, "Can't create %s\n", draft); 50112375Sralph return; 50212375Sralph } 50312375Sralph /* 50412375Sralph * Output the proper header information. 50512375Sralph */ 506*14342Skarels fprintf(fout, "Reply-To: 4bsd-bugs%%ucbarpa@BERKELEY\n"); 50712375Sralph if (RETURNPATH_I != NULL) 50812375Sralph to = RETURNPATH_I; 50912375Sralph if (REPLYTO_I != NULL) 51012375Sralph to = REPLYTO_I; 51112375Sralph if ((to = fixaddr(to)) == 0) { 51212375Sralph fprintf(stderr, "No one to reply to\n"); 51312375Sralph return; 51412375Sralph } 51512375Sralph fprintf(fout, "To: %s\n", to); 51612375Sralph if (SUBJECT_I) { 51712375Sralph fprintf(fout, "Subject: "); 51812375Sralph if ((SUBJECT_I[0] != 'R' && SUBJECT_I[0] != 'r') || 51912375Sralph (SUBJECT_I[1] != 'E' && SUBJECT_I[1] != 'e') || 52012375Sralph SUBJECT_I[2] != ':') 52112375Sralph fprintf(fout, "Re: "); 52212375Sralph fprintf(fout, "%s\n", SUBJECT_I); 52312375Sralph } 52412375Sralph if (DATE_I) { 52512375Sralph fprintf(fout, "In-Acknowledgement-Of: Your message of "); 52612375Sralph fprintf(fout, "%s.\n", DATE_I); 52712375Sralph if (MSGID_I) 52812375Sralph fprintf(fout, " %s\n", MSGID_I); 52912375Sralph } 53012375Sralph fprintf(fout, "----------\n"); 53112375Sralph if ((in = open(file1, 0)) >= 0) { 53212695Sralph while ((w = read(in, buf, sizeof(buf))) > 0) 53312695Sralph fwrite(buf, 1, w, fout); 53412375Sralph close(in); 53512375Sralph } 53612375Sralph if (file2 && (in = open(file2, 0)) >= 0) { 53712695Sralph while ((w = read(in, buf, sizeof(buf))) > 0) 53812695Sralph fwrite(buf, 1, w, fout); 53912375Sralph close(in); 54012375Sralph } 54112375Sralph fclose(fout); 54212375Sralph while ((pid = fork()) == -1) 54312375Sralph sleep(5); 54412375Sralph if (pid == 0) { 54512375Sralph execl(deliver, "deliver", draft, 0); 54612375Sralph _exit(127); 54712375Sralph } 54812375Sralph istat = signal(SIGINT, SIG_IGN); 54912375Sralph qstat = signal(SIGQUIT, SIG_IGN); 55012375Sralph while ((w = wait(&status)) != -1 && w != pid); 55112375Sralph signal(SIGINT, istat); 55212375Sralph signal(SIGQUIT, qstat); 55312375Sralph if (w != -1 && status == 0) 55412375Sralph unlink(draft); 55512375Sralph } 55612375Sralph 55712375Sralph /* 55812375Sralph * fix names like "xxx (something)" to "xxx" and 55912375Sralph * "xxx <something>" to "something". 56012375Sralph */ 56112375Sralph 56212375Sralph char * 56312375Sralph fixaddr(text) 56412375Sralph char *text; 56512375Sralph { 56612375Sralph register char *cp, *lp, c; 56712375Sralph char *tp; 56812375Sralph 56912375Sralph if (!text) 57012375Sralph return(0); 57112375Sralph for (lp = cp = text; ; ) { 57212375Sralph switch (c = *cp++) { 57312375Sralph case '(': 57412375Sralph while (*cp && *cp++ != ')'); 57512375Sralph continue; 57612375Sralph case '<': 57712375Sralph lp = text; 57812375Sralph case '>': 57912375Sralph continue; 58012375Sralph case '\0': 58112375Sralph while (lp != text && (*lp == ' ' || *lp == '\t')) 58212375Sralph lp--; 58312375Sralph *lp = c; 58412375Sralph return(text); 58512375Sralph } 58612375Sralph *lp++ = c; 58712375Sralph } 58812375Sralph } 58912375Sralph 59012375Sralph /* 59112375Sralph * Compare two strings and convert any upper case letters to lower case. 59212375Sralph */ 59312375Sralph 59412695Sralph streq(s1, s2) 59512695Sralph register char *s1, *s2; 59612375Sralph { 59712375Sralph register int c; 59812375Sralph 59912695Sralph while (c = *s1++) 60012695Sralph if ((c | 040) != (*s2++ | 040)) 60112375Sralph return(0); 60212695Sralph return(*s2 == '\0'); 60312375Sralph } 60412695Sralph 60512695Sralph /* 60612695Sralph * Return true if string s2 matches the first part of s1. 60712695Sralph */ 60812695Sralph 60912695Sralph substr(s1, s2) 61012695Sralph register char *s1, *s2; 61112695Sralph { 61212695Sralph register int c; 61312695Sralph 61412695Sralph while (c = *s2++) 61512695Sralph if (c != *s1++) 61612695Sralph return(0); 61712695Sralph return(1); 61812695Sralph } 61912695Sralph 62012695Sralph peekc(fp) 62112695Sralph FILE *fp; 62212695Sralph { 62312695Sralph register c; 62412695Sralph 62512695Sralph c = getc(fp); 62612695Sralph ungetc(c, fp); 62712695Sralph return(c); 62812695Sralph } 629