19b50d902SRodney W. Grimes /* 29b50d902SRodney W. Grimes * Copyright (c) 1980, 1993 39b50d902SRodney W. Grimes * The Regents of the University of California. All rights reserved. 49b50d902SRodney W. Grimes * 59b50d902SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 69b50d902SRodney W. Grimes * modification, are permitted provided that the following conditions 79b50d902SRodney W. Grimes * are met: 89b50d902SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 99b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 109b50d902SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 119b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 129b50d902SRodney W. Grimes * documentation and/or other materials provided with the distribution. 139b50d902SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 149b50d902SRodney W. Grimes * must display the following acknowledgement: 159b50d902SRodney W. Grimes * This product includes software developed by the University of 169b50d902SRodney W. Grimes * California, Berkeley and its contributors. 179b50d902SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 189b50d902SRodney W. Grimes * may be used to endorse or promote products derived from this software 199b50d902SRodney W. Grimes * without specific prior written permission. 209b50d902SRodney W. Grimes * 219b50d902SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 229b50d902SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 239b50d902SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 249b50d902SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 259b50d902SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 269b50d902SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 279b50d902SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 289b50d902SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 299b50d902SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 309b50d902SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 319b50d902SRodney W. Grimes * SUCH DAMAGE. 329b50d902SRodney W. Grimes */ 339b50d902SRodney W. Grimes 349b50d902SRodney W. Grimes #ifndef lint 359b50d902SRodney W. Grimes static char sccsid[] = "@(#)cmd2.c 8.1 (Berkeley) 6/6/93"; 369b50d902SRodney W. Grimes #endif /* not lint */ 379b50d902SRodney W. Grimes 389b50d902SRodney W. Grimes #include "rcv.h" 399b50d902SRodney W. Grimes #include <sys/wait.h> 409b50d902SRodney W. Grimes #include "extern.h" 419b50d902SRodney W. Grimes 429b50d902SRodney W. Grimes /* 439b50d902SRodney W. Grimes * Mail -- a mail program 449b50d902SRodney W. Grimes * 459b50d902SRodney W. Grimes * More user commands. 469b50d902SRodney W. Grimes */ 479b50d902SRodney W. Grimes 489b50d902SRodney W. Grimes /* 499b50d902SRodney W. Grimes * If any arguments were given, go to the next applicable argument 509b50d902SRodney W. Grimes * following dot, otherwise, go to the next applicable message. 519b50d902SRodney W. Grimes * If given as first command with no arguments, print first message. 529b50d902SRodney W. Grimes */ 539b50d902SRodney W. Grimes int 549b50d902SRodney W. Grimes next(msgvec) 559b50d902SRodney W. Grimes int *msgvec; 569b50d902SRodney W. Grimes { 579b50d902SRodney W. Grimes register struct message *mp; 589b50d902SRodney W. Grimes register int *ip, *ip2; 599b50d902SRodney W. Grimes int list[2], mdot; 609b50d902SRodney W. Grimes 61d030d2d2SPoul-Henning Kamp if (*msgvec != 0) { 629b50d902SRodney W. Grimes 639b50d902SRodney W. Grimes /* 649b50d902SRodney W. Grimes * If some messages were supplied, find the 659b50d902SRodney W. Grimes * first applicable one following dot using 669b50d902SRodney W. Grimes * wrap around. 679b50d902SRodney W. Grimes */ 689b50d902SRodney W. Grimes 699b50d902SRodney W. Grimes mdot = dot - &message[0] + 1; 709b50d902SRodney W. Grimes 719b50d902SRodney W. Grimes /* 729b50d902SRodney W. Grimes * Find the first message in the supplied 739b50d902SRodney W. Grimes * message list which follows dot. 749b50d902SRodney W. Grimes */ 759b50d902SRodney W. Grimes 76d030d2d2SPoul-Henning Kamp for (ip = msgvec; *ip != 0; ip++) 779b50d902SRodney W. Grimes if (*ip > mdot) 789b50d902SRodney W. Grimes break; 79d030d2d2SPoul-Henning Kamp if (*ip == 0) 809b50d902SRodney W. Grimes ip = msgvec; 819b50d902SRodney W. Grimes ip2 = ip; 829b50d902SRodney W. Grimes do { 839b50d902SRodney W. Grimes mp = &message[*ip2 - 1]; 849b50d902SRodney W. Grimes if ((mp->m_flag & MDELETED) == 0) { 859b50d902SRodney W. Grimes dot = mp; 869b50d902SRodney W. Grimes goto hitit; 879b50d902SRodney W. Grimes } 88d030d2d2SPoul-Henning Kamp if (*ip2 != 0) 899b50d902SRodney W. Grimes ip2++; 90d030d2d2SPoul-Henning Kamp if (*ip2 == 0) 919b50d902SRodney W. Grimes ip2 = msgvec; 929b50d902SRodney W. Grimes } while (ip2 != ip); 939b50d902SRodney W. Grimes printf("No messages applicable\n"); 949b50d902SRodney W. Grimes return(1); 959b50d902SRodney W. Grimes } 969b50d902SRodney W. Grimes 979b50d902SRodney W. Grimes /* 989b50d902SRodney W. Grimes * If this is the first command, select message 1. 999b50d902SRodney W. Grimes * Note that this must exist for us to get here at all. 1009b50d902SRodney W. Grimes */ 1019b50d902SRodney W. Grimes 1029b50d902SRodney W. Grimes if (!sawcom) 1039b50d902SRodney W. Grimes goto hitit; 1049b50d902SRodney W. Grimes 1059b50d902SRodney W. Grimes /* 1069b50d902SRodney W. Grimes * Just find the next good message after dot, no 1079b50d902SRodney W. Grimes * wraparound. 1089b50d902SRodney W. Grimes */ 1099b50d902SRodney W. Grimes 1109b50d902SRodney W. Grimes for (mp = dot+1; mp < &message[msgCount]; mp++) 1119b50d902SRodney W. Grimes if ((mp->m_flag & (MDELETED|MSAVED)) == 0) 1129b50d902SRodney W. Grimes break; 1139b50d902SRodney W. Grimes if (mp >= &message[msgCount]) { 1149b50d902SRodney W. Grimes printf("At EOF\n"); 1159b50d902SRodney W. Grimes return(0); 1169b50d902SRodney W. Grimes } 1179b50d902SRodney W. Grimes dot = mp; 1189b50d902SRodney W. Grimes hitit: 1199b50d902SRodney W. Grimes /* 1209b50d902SRodney W. Grimes * Print dot. 1219b50d902SRodney W. Grimes */ 1229b50d902SRodney W. Grimes 1239b50d902SRodney W. Grimes list[0] = dot - &message[0] + 1; 124d030d2d2SPoul-Henning Kamp list[1] = 0; 1259b50d902SRodney W. Grimes return(type(list)); 1269b50d902SRodney W. Grimes } 1279b50d902SRodney W. Grimes 1289b50d902SRodney W. Grimes /* 1299b50d902SRodney W. Grimes * Save a message in a file. Mark the message as saved 1309b50d902SRodney W. Grimes * so we can discard when the user quits. 1319b50d902SRodney W. Grimes */ 1329b50d902SRodney W. Grimes int 1339b50d902SRodney W. Grimes save(str) 1349b50d902SRodney W. Grimes char str[]; 1359b50d902SRodney W. Grimes { 1369b50d902SRodney W. Grimes 1379b50d902SRodney W. Grimes return save1(str, 1, "save", saveignore); 1389b50d902SRodney W. Grimes } 1399b50d902SRodney W. Grimes 1409b50d902SRodney W. Grimes /* 1419b50d902SRodney W. Grimes * Copy a message to a file without affected its saved-ness 1429b50d902SRodney W. Grimes */ 1439b50d902SRodney W. Grimes int 1449b50d902SRodney W. Grimes copycmd(str) 1459b50d902SRodney W. Grimes char str[]; 1469b50d902SRodney W. Grimes { 1479b50d902SRodney W. Grimes 1489b50d902SRodney W. Grimes return save1(str, 0, "copy", saveignore); 1499b50d902SRodney W. Grimes } 1509b50d902SRodney W. Grimes 1519b50d902SRodney W. Grimes /* 1529b50d902SRodney W. Grimes * Save/copy the indicated messages at the end of the passed file name. 1539b50d902SRodney W. Grimes * If mark is true, mark the message "saved." 1549b50d902SRodney W. Grimes */ 1559b50d902SRodney W. Grimes int 1569b50d902SRodney W. Grimes save1(str, mark, cmd, ignore) 1579b50d902SRodney W. Grimes char str[]; 1589b50d902SRodney W. Grimes int mark; 1599b50d902SRodney W. Grimes char *cmd; 1609b50d902SRodney W. Grimes struct ignoretab *ignore; 1619b50d902SRodney W. Grimes { 1629b50d902SRodney W. Grimes register int *ip; 1639b50d902SRodney W. Grimes register struct message *mp; 1649b50d902SRodney W. Grimes char *file, *disp; 1659b50d902SRodney W. Grimes int f, *msgvec; 1669b50d902SRodney W. Grimes FILE *obuf; 1679b50d902SRodney W. Grimes 1689b50d902SRodney W. Grimes msgvec = (int *) salloc((msgCount + 2) * sizeof *msgvec); 1699b50d902SRodney W. Grimes if ((file = snarf(str, &f)) == NOSTR) 1709b50d902SRodney W. Grimes return(1); 1719b50d902SRodney W. Grimes if (!f) { 1729b50d902SRodney W. Grimes *msgvec = first(0, MMNORM); 173d030d2d2SPoul-Henning Kamp if (*msgvec == 0) { 1749b50d902SRodney W. Grimes printf("No messages to %s.\n", cmd); 1759b50d902SRodney W. Grimes return(1); 1769b50d902SRodney W. Grimes } 177d030d2d2SPoul-Henning Kamp msgvec[1] = 0; 1789b50d902SRodney W. Grimes } 1799b50d902SRodney W. Grimes if (f && getmsglist(str, msgvec, 0) < 0) 1809b50d902SRodney W. Grimes return(1); 1819b50d902SRodney W. Grimes if ((file = expand(file)) == NOSTR) 1829b50d902SRodney W. Grimes return(1); 1839b50d902SRodney W. Grimes printf("\"%s\" ", file); 1849b50d902SRodney W. Grimes fflush(stdout); 1859b50d902SRodney W. Grimes if (access(file, 0) >= 0) 1869b50d902SRodney W. Grimes disp = "[Appended]"; 1879b50d902SRodney W. Grimes else 1889b50d902SRodney W. Grimes disp = "[New file]"; 1899b50d902SRodney W. Grimes if ((obuf = Fopen(file, "a")) == NULL) { 1909b50d902SRodney W. Grimes perror(NOSTR); 1919b50d902SRodney W. Grimes return(1); 1929b50d902SRodney W. Grimes } 1939b50d902SRodney W. Grimes for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) { 1949b50d902SRodney W. Grimes mp = &message[*ip - 1]; 1959b50d902SRodney W. Grimes touch(mp); 1969b50d902SRodney W. Grimes if (send(mp, obuf, ignore, NOSTR) < 0) { 1979b50d902SRodney W. Grimes perror(file); 1989b50d902SRodney W. Grimes Fclose(obuf); 1999b50d902SRodney W. Grimes return(1); 2009b50d902SRodney W. Grimes } 2019b50d902SRodney W. Grimes if (mark) 2029b50d902SRodney W. Grimes mp->m_flag |= MSAVED; 2039b50d902SRodney W. Grimes } 2049b50d902SRodney W. Grimes fflush(obuf); 2059b50d902SRodney W. Grimes if (ferror(obuf)) 2069b50d902SRodney W. Grimes perror(file); 2079b50d902SRodney W. Grimes Fclose(obuf); 2089b50d902SRodney W. Grimes printf("%s\n", disp); 2099b50d902SRodney W. Grimes return(0); 2109b50d902SRodney W. Grimes } 2119b50d902SRodney W. Grimes 2129b50d902SRodney W. Grimes /* 2139b50d902SRodney W. Grimes * Write the indicated messages at the end of the passed 2149b50d902SRodney W. Grimes * file name, minus header and trailing blank line. 2159b50d902SRodney W. Grimes */ 2169b50d902SRodney W. Grimes int 2179b50d902SRodney W. Grimes swrite(str) 2189b50d902SRodney W. Grimes char str[]; 2199b50d902SRodney W. Grimes { 2209b50d902SRodney W. Grimes 2219b50d902SRodney W. Grimes return save1(str, 1, "write", ignoreall); 2229b50d902SRodney W. Grimes } 2239b50d902SRodney W. Grimes 2249b50d902SRodney W. Grimes /* 2259b50d902SRodney W. Grimes * Snarf the file from the end of the command line and 2269b50d902SRodney W. Grimes * return a pointer to it. If there is no file attached, 2279b50d902SRodney W. Grimes * just return NOSTR. Put a null in front of the file 2289b50d902SRodney W. Grimes * name so that the message list processing won't see it, 2299b50d902SRodney W. Grimes * unless the file name is the only thing on the line, in 2309b50d902SRodney W. Grimes * which case, return 0 in the reference flag variable. 2319b50d902SRodney W. Grimes */ 2329b50d902SRodney W. Grimes 2339b50d902SRodney W. Grimes char * 2349b50d902SRodney W. Grimes snarf(linebuf, flag) 2359b50d902SRodney W. Grimes char linebuf[]; 2369b50d902SRodney W. Grimes int *flag; 2379b50d902SRodney W. Grimes { 2389b50d902SRodney W. Grimes register char *cp; 2399b50d902SRodney W. Grimes 2409b50d902SRodney W. Grimes *flag = 1; 2419b50d902SRodney W. Grimes cp = strlen(linebuf) + linebuf - 1; 2429b50d902SRodney W. Grimes 2439b50d902SRodney W. Grimes /* 2449b50d902SRodney W. Grimes * Strip away trailing blanks. 2459b50d902SRodney W. Grimes */ 2469b50d902SRodney W. Grimes 2479b50d902SRodney W. Grimes while (cp > linebuf && isspace(*cp)) 2489b50d902SRodney W. Grimes cp--; 2499b50d902SRodney W. Grimes *++cp = 0; 2509b50d902SRodney W. Grimes 2519b50d902SRodney W. Grimes /* 2529b50d902SRodney W. Grimes * Now search for the beginning of the file name. 2539b50d902SRodney W. Grimes */ 2549b50d902SRodney W. Grimes 2559b50d902SRodney W. Grimes while (cp > linebuf && !isspace(*cp)) 2569b50d902SRodney W. Grimes cp--; 2579b50d902SRodney W. Grimes if (*cp == '\0') { 2589b50d902SRodney W. Grimes printf("No file specified.\n"); 2599b50d902SRodney W. Grimes return(NOSTR); 2609b50d902SRodney W. Grimes } 2619b50d902SRodney W. Grimes if (isspace(*cp)) 2629b50d902SRodney W. Grimes *cp++ = 0; 2639b50d902SRodney W. Grimes else 2649b50d902SRodney W. Grimes *flag = 0; 2659b50d902SRodney W. Grimes return(cp); 2669b50d902SRodney W. Grimes } 2679b50d902SRodney W. Grimes 2689b50d902SRodney W. Grimes /* 2699b50d902SRodney W. Grimes * Delete messages. 2709b50d902SRodney W. Grimes */ 2719b50d902SRodney W. Grimes int 2729b50d902SRodney W. Grimes delete(msgvec) 2739b50d902SRodney W. Grimes int msgvec[]; 2749b50d902SRodney W. Grimes { 2759b50d902SRodney W. Grimes delm(msgvec); 2769b50d902SRodney W. Grimes return 0; 2779b50d902SRodney W. Grimes } 2789b50d902SRodney W. Grimes 2799b50d902SRodney W. Grimes /* 2809b50d902SRodney W. Grimes * Delete messages, then type the new dot. 2819b50d902SRodney W. Grimes */ 2829b50d902SRodney W. Grimes int 2839b50d902SRodney W. Grimes deltype(msgvec) 2849b50d902SRodney W. Grimes int msgvec[]; 2859b50d902SRodney W. Grimes { 2869b50d902SRodney W. Grimes int list[2]; 2879b50d902SRodney W. Grimes int lastdot; 2889b50d902SRodney W. Grimes 2899b50d902SRodney W. Grimes lastdot = dot - &message[0] + 1; 2909b50d902SRodney W. Grimes if (delm(msgvec) >= 0) { 2919b50d902SRodney W. Grimes list[0] = dot - &message[0] + 1; 2929b50d902SRodney W. Grimes if (list[0] > lastdot) { 2939b50d902SRodney W. Grimes touch(dot); 294d030d2d2SPoul-Henning Kamp list[1] = 0; 2959b50d902SRodney W. Grimes return(type(list)); 2969b50d902SRodney W. Grimes } 2979b50d902SRodney W. Grimes printf("At EOF\n"); 2989b50d902SRodney W. Grimes } else 2999b50d902SRodney W. Grimes printf("No more messages\n"); 3009b50d902SRodney W. Grimes return(0); 3019b50d902SRodney W. Grimes } 3029b50d902SRodney W. Grimes 3039b50d902SRodney W. Grimes /* 3049b50d902SRodney W. Grimes * Delete the indicated messages. 3059b50d902SRodney W. Grimes * Set dot to some nice place afterwards. 3069b50d902SRodney W. Grimes * Internal interface. 3079b50d902SRodney W. Grimes */ 3089b50d902SRodney W. Grimes int 3099b50d902SRodney W. Grimes delm(msgvec) 3109b50d902SRodney W. Grimes int *msgvec; 3119b50d902SRodney W. Grimes { 3129b50d902SRodney W. Grimes register struct message *mp; 3139b50d902SRodney W. Grimes register *ip; 3149b50d902SRodney W. Grimes int last; 3159b50d902SRodney W. Grimes 316d030d2d2SPoul-Henning Kamp last = 0; 317d030d2d2SPoul-Henning Kamp for (ip = msgvec; *ip != 0; ip++) { 3189b50d902SRodney W. Grimes mp = &message[*ip - 1]; 3199b50d902SRodney W. Grimes touch(mp); 3209b50d902SRodney W. Grimes mp->m_flag |= MDELETED|MTOUCH; 3219b50d902SRodney W. Grimes mp->m_flag &= ~(MPRESERVE|MSAVED|MBOX); 3229b50d902SRodney W. Grimes last = *ip; 3239b50d902SRodney W. Grimes } 324d030d2d2SPoul-Henning Kamp if (last != 0) { 3259b50d902SRodney W. Grimes dot = &message[last-1]; 3269b50d902SRodney W. Grimes last = first(0, MDELETED); 327d030d2d2SPoul-Henning Kamp if (last != 0) { 3289b50d902SRodney W. Grimes dot = &message[last-1]; 3299b50d902SRodney W. Grimes return(0); 3309b50d902SRodney W. Grimes } 3319b50d902SRodney W. Grimes else { 3329b50d902SRodney W. Grimes dot = &message[0]; 3339b50d902SRodney W. Grimes return(-1); 3349b50d902SRodney W. Grimes } 3359b50d902SRodney W. Grimes } 3369b50d902SRodney W. Grimes 3379b50d902SRodney W. Grimes /* 3389b50d902SRodney W. Grimes * Following can't happen -- it keeps lint happy 3399b50d902SRodney W. Grimes */ 3409b50d902SRodney W. Grimes 3419b50d902SRodney W. Grimes return(-1); 3429b50d902SRodney W. Grimes } 3439b50d902SRodney W. Grimes 3449b50d902SRodney W. Grimes /* 3459b50d902SRodney W. Grimes * Undelete the indicated messages. 3469b50d902SRodney W. Grimes */ 3479b50d902SRodney W. Grimes int 348c05b924fSBruce Evans undelete_messages(msgvec) 3499b50d902SRodney W. Grimes int *msgvec; 3509b50d902SRodney W. Grimes { 3519b50d902SRodney W. Grimes register struct message *mp; 3529b50d902SRodney W. Grimes register *ip; 3539b50d902SRodney W. Grimes 3549b50d902SRodney W. Grimes for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) { 3559b50d902SRodney W. Grimes mp = &message[*ip - 1]; 3569b50d902SRodney W. Grimes touch(mp); 3579b50d902SRodney W. Grimes dot = mp; 3589b50d902SRodney W. Grimes mp->m_flag &= ~MDELETED; 3599b50d902SRodney W. Grimes } 3609b50d902SRodney W. Grimes return 0; 3619b50d902SRodney W. Grimes } 3629b50d902SRodney W. Grimes 3639b50d902SRodney W. Grimes /* 3649b50d902SRodney W. Grimes * Interactively dump core on "core" 3659b50d902SRodney W. Grimes */ 3669b50d902SRodney W. Grimes int 3679b50d902SRodney W. Grimes core() 3689b50d902SRodney W. Grimes { 3699b50d902SRodney W. Grimes int pid; 3709b50d902SRodney W. Grimes extern union wait wait_status; 3719b50d902SRodney W. Grimes 37246ccc3e9SBruce Evans switch (pid = fork()) { 3739b50d902SRodney W. Grimes case -1: 3749b50d902SRodney W. Grimes perror("fork"); 3759b50d902SRodney W. Grimes return(1); 3769b50d902SRodney W. Grimes case 0: 3779b50d902SRodney W. Grimes abort(); 3789b50d902SRodney W. Grimes _exit(1); 3799b50d902SRodney W. Grimes } 3809b50d902SRodney W. Grimes printf("Okie dokie"); 3819b50d902SRodney W. Grimes fflush(stdout); 3829b50d902SRodney W. Grimes wait_child(pid); 3839b50d902SRodney W. Grimes if (wait_status.w_coredump) 3849b50d902SRodney W. Grimes printf(" -- Core dumped.\n"); 3859b50d902SRodney W. Grimes else 3869b50d902SRodney W. Grimes printf(" -- Can't dump core.\n"); 3879b50d902SRodney W. Grimes return 0; 3889b50d902SRodney W. Grimes } 3899b50d902SRodney W. Grimes 3909b50d902SRodney W. Grimes /* 3919b50d902SRodney W. Grimes * Clobber as many bytes of stack as the user requests. 3929b50d902SRodney W. Grimes */ 3939b50d902SRodney W. Grimes int 3949b50d902SRodney W. Grimes clobber(argv) 3959b50d902SRodney W. Grimes char **argv; 3969b50d902SRodney W. Grimes { 3979b50d902SRodney W. Grimes register int times; 3989b50d902SRodney W. Grimes 3999b50d902SRodney W. Grimes if (argv[0] == 0) 4009b50d902SRodney W. Grimes times = 1; 4019b50d902SRodney W. Grimes else 4029b50d902SRodney W. Grimes times = (atoi(argv[0]) + 511) / 512; 4039b50d902SRodney W. Grimes clob1(times); 4049b50d902SRodney W. Grimes return 0; 4059b50d902SRodney W. Grimes } 4069b50d902SRodney W. Grimes 4079b50d902SRodney W. Grimes /* 4089b50d902SRodney W. Grimes * Clobber the stack. 4099b50d902SRodney W. Grimes */ 4109b50d902SRodney W. Grimes void 4119b50d902SRodney W. Grimes clob1(n) 4129b50d902SRodney W. Grimes int n; 4139b50d902SRodney W. Grimes { 4149b50d902SRodney W. Grimes char buf[512]; 4159b50d902SRodney W. Grimes register char *cp; 4169b50d902SRodney W. Grimes 4179b50d902SRodney W. Grimes if (n <= 0) 4189b50d902SRodney W. Grimes return; 4199b50d902SRodney W. Grimes for (cp = buf; cp < &buf[512]; *cp++ = 0xFF) 4209b50d902SRodney W. Grimes ; 4219b50d902SRodney W. Grimes clob1(n - 1); 4229b50d902SRodney W. Grimes } 4239b50d902SRodney W. Grimes 4249b50d902SRodney W. Grimes /* 4259b50d902SRodney W. Grimes * Add the given header fields to the retained list. 4269b50d902SRodney W. Grimes * If no arguments, print the current list of retained fields. 4279b50d902SRodney W. Grimes */ 4289b50d902SRodney W. Grimes int 4299b50d902SRodney W. Grimes retfield(list) 4309b50d902SRodney W. Grimes char *list[]; 4319b50d902SRodney W. Grimes { 4329b50d902SRodney W. Grimes 4339b50d902SRodney W. Grimes return ignore1(list, ignore + 1, "retained"); 4349b50d902SRodney W. Grimes } 4359b50d902SRodney W. Grimes 4369b50d902SRodney W. Grimes /* 4379b50d902SRodney W. Grimes * Add the given header fields to the ignored list. 4389b50d902SRodney W. Grimes * If no arguments, print the current list of ignored fields. 4399b50d902SRodney W. Grimes */ 4409b50d902SRodney W. Grimes int 4419b50d902SRodney W. Grimes igfield(list) 4429b50d902SRodney W. Grimes char *list[]; 4439b50d902SRodney W. Grimes { 4449b50d902SRodney W. Grimes 4459b50d902SRodney W. Grimes return ignore1(list, ignore, "ignored"); 4469b50d902SRodney W. Grimes } 4479b50d902SRodney W. Grimes 4489b50d902SRodney W. Grimes int 4499b50d902SRodney W. Grimes saveretfield(list) 4509b50d902SRodney W. Grimes char *list[]; 4519b50d902SRodney W. Grimes { 4529b50d902SRodney W. Grimes 4539b50d902SRodney W. Grimes return ignore1(list, saveignore + 1, "retained"); 4549b50d902SRodney W. Grimes } 4559b50d902SRodney W. Grimes 4569b50d902SRodney W. Grimes int 4579b50d902SRodney W. Grimes saveigfield(list) 4589b50d902SRodney W. Grimes char *list[]; 4599b50d902SRodney W. Grimes { 4609b50d902SRodney W. Grimes 4619b50d902SRodney W. Grimes return ignore1(list, saveignore, "ignored"); 4629b50d902SRodney W. Grimes } 4639b50d902SRodney W. Grimes 4649b50d902SRodney W. Grimes int 4659b50d902SRodney W. Grimes ignore1(list, tab, which) 4669b50d902SRodney W. Grimes char *list[]; 4679b50d902SRodney W. Grimes struct ignoretab *tab; 4689b50d902SRodney W. Grimes char *which; 4699b50d902SRodney W. Grimes { 4709b50d902SRodney W. Grimes char field[BUFSIZ]; 4719b50d902SRodney W. Grimes register int h; 4729b50d902SRodney W. Grimes register struct ignore *igp; 4739b50d902SRodney W. Grimes char **ap; 4749b50d902SRodney W. Grimes 4759b50d902SRodney W. Grimes if (*list == NOSTR) 4769b50d902SRodney W. Grimes return igshow(tab, which); 4779b50d902SRodney W. Grimes for (ap = list; *ap != 0; ap++) { 4789b50d902SRodney W. Grimes istrcpy(field, *ap); 4799b50d902SRodney W. Grimes if (member(field, tab)) 4809b50d902SRodney W. Grimes continue; 4819b50d902SRodney W. Grimes h = hash(field); 4829b50d902SRodney W. Grimes igp = (struct ignore *) calloc(1, sizeof (struct ignore)); 4839b50d902SRodney W. Grimes igp->i_field = calloc((unsigned) strlen(field) + 1, 4849b50d902SRodney W. Grimes sizeof (char)); 4859b50d902SRodney W. Grimes strcpy(igp->i_field, field); 4869b50d902SRodney W. Grimes igp->i_link = tab->i_head[h]; 4879b50d902SRodney W. Grimes tab->i_head[h] = igp; 4889b50d902SRodney W. Grimes tab->i_count++; 4899b50d902SRodney W. Grimes } 4909b50d902SRodney W. Grimes return 0; 4919b50d902SRodney W. Grimes } 4929b50d902SRodney W. Grimes 4939b50d902SRodney W. Grimes /* 4949b50d902SRodney W. Grimes * Print out all currently retained fields. 4959b50d902SRodney W. Grimes */ 4969b50d902SRodney W. Grimes int 4979b50d902SRodney W. Grimes igshow(tab, which) 4989b50d902SRodney W. Grimes struct ignoretab *tab; 4999b50d902SRodney W. Grimes char *which; 5009b50d902SRodney W. Grimes { 5019b50d902SRodney W. Grimes register int h; 5029b50d902SRodney W. Grimes struct ignore *igp; 5039b50d902SRodney W. Grimes char **ap, **ring; 5049b50d902SRodney W. Grimes int igcomp(); 5059b50d902SRodney W. Grimes 5069b50d902SRodney W. Grimes if (tab->i_count == 0) { 5079b50d902SRodney W. Grimes printf("No fields currently being %s.\n", which); 5089b50d902SRodney W. Grimes return 0; 5099b50d902SRodney W. Grimes } 5109b50d902SRodney W. Grimes ring = (char **) salloc((tab->i_count + 1) * sizeof (char *)); 5119b50d902SRodney W. Grimes ap = ring; 5129b50d902SRodney W. Grimes for (h = 0; h < HSHSIZE; h++) 5139b50d902SRodney W. Grimes for (igp = tab->i_head[h]; igp != 0; igp = igp->i_link) 5149b50d902SRodney W. Grimes *ap++ = igp->i_field; 5159b50d902SRodney W. Grimes *ap = 0; 5169b50d902SRodney W. Grimes qsort(ring, tab->i_count, sizeof (char *), igcomp); 5179b50d902SRodney W. Grimes for (ap = ring; *ap != 0; ap++) 5189b50d902SRodney W. Grimes printf("%s\n", *ap); 5199b50d902SRodney W. Grimes return 0; 5209b50d902SRodney W. Grimes } 5219b50d902SRodney W. Grimes 5229b50d902SRodney W. Grimes /* 5239b50d902SRodney W. Grimes * Compare two names for sorting ignored field list. 5249b50d902SRodney W. Grimes */ 5259b50d902SRodney W. Grimes int 5269b50d902SRodney W. Grimes igcomp(l, r) 5279b50d902SRodney W. Grimes const void *l, *r; 5289b50d902SRodney W. Grimes { 5299b50d902SRodney W. Grimes return (strcmp(*(char **)l, *(char **)r)); 5309b50d902SRodney W. Grimes } 531