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