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 #include "rcv.h"
339b50d902SRodney W. Grimes #include <sys/wait.h>
349b50d902SRodney W. Grimes #include "extern.h"
359b50d902SRodney W. Grimes
369b50d902SRodney W. Grimes /*
379b50d902SRodney W. Grimes * Mail -- a mail program
389b50d902SRodney W. Grimes *
399b50d902SRodney W. Grimes * More user commands.
409b50d902SRodney W. Grimes */
419b50d902SRodney W. Grimes
429ce73e90SMike Heffner extern int wait_status;
439ce73e90SMike Heffner
449b50d902SRodney W. Grimes /*
459b50d902SRodney W. Grimes * If any arguments were given, go to the next applicable argument
469b50d902SRodney W. Grimes * following dot, otherwise, go to the next applicable message.
479b50d902SRodney W. Grimes * If given as first command with no arguments, print first message.
489b50d902SRodney W. Grimes */
499b50d902SRodney W. Grimes int
next(void * v)50b948550dSPedro F. Giffuni next(void *v)
519b50d902SRodney W. Grimes {
529ce73e90SMike Heffner struct message *mp;
53b948550dSPedro F. Giffuni int *msgvec = v;
549ce73e90SMike Heffner int *ip, *ip2, list[2], mdot;
559b50d902SRodney W. Grimes
56d030d2d2SPoul-Henning Kamp if (*msgvec != 0) {
579b50d902SRodney W. Grimes
589b50d902SRodney W. Grimes /*
599b50d902SRodney W. Grimes * If some messages were supplied, find the
609b50d902SRodney W. Grimes * first applicable one following dot using
619b50d902SRodney W. Grimes * wrap around.
629b50d902SRodney W. Grimes */
639b50d902SRodney W. Grimes
649b50d902SRodney W. Grimes mdot = dot - &message[0] + 1;
659b50d902SRodney W. Grimes
669b50d902SRodney W. Grimes /*
679b50d902SRodney W. Grimes * Find the first message in the supplied
689b50d902SRodney W. Grimes * message list which follows dot.
699b50d902SRodney W. Grimes */
709b50d902SRodney W. Grimes
71d030d2d2SPoul-Henning Kamp for (ip = msgvec; *ip != 0; ip++)
729b50d902SRodney W. Grimes if (*ip > mdot)
739b50d902SRodney W. Grimes break;
74d030d2d2SPoul-Henning Kamp if (*ip == 0)
759b50d902SRodney W. Grimes ip = msgvec;
769b50d902SRodney W. Grimes ip2 = ip;
779b50d902SRodney W. Grimes do {
789b50d902SRodney W. Grimes mp = &message[*ip2 - 1];
799b50d902SRodney W. Grimes if ((mp->m_flag & MDELETED) == 0) {
809b50d902SRodney W. Grimes dot = mp;
819b50d902SRodney W. Grimes goto hitit;
829b50d902SRodney W. Grimes }
83d030d2d2SPoul-Henning Kamp if (*ip2 != 0)
849b50d902SRodney W. Grimes ip2++;
85d030d2d2SPoul-Henning Kamp if (*ip2 == 0)
869b50d902SRodney W. Grimes ip2 = msgvec;
879b50d902SRodney W. Grimes } while (ip2 != ip);
889b50d902SRodney W. Grimes printf("No messages applicable\n");
899b50d902SRodney W. Grimes return (1);
909b50d902SRodney W. Grimes }
919b50d902SRodney W. Grimes
929b50d902SRodney W. Grimes /*
939b50d902SRodney W. Grimes * If this is the first command, select message 1.
949b50d902SRodney W. Grimes * Note that this must exist for us to get here at all.
959b50d902SRodney W. Grimes */
969b50d902SRodney W. Grimes
979b50d902SRodney W. Grimes if (!sawcom)
989b50d902SRodney W. Grimes goto hitit;
999b50d902SRodney W. Grimes
1009b50d902SRodney W. Grimes /*
1019b50d902SRodney W. Grimes * Just find the next good message after dot, no
1029b50d902SRodney W. Grimes * wraparound.
1039b50d902SRodney W. Grimes */
1049b50d902SRodney W. Grimes
1059b50d902SRodney W. Grimes for (mp = dot+1; mp < &message[msgCount]; mp++)
1069b50d902SRodney W. Grimes if ((mp->m_flag & (MDELETED|MSAVED)) == 0)
1079b50d902SRodney W. Grimes break;
1089b50d902SRodney W. Grimes if (mp >= &message[msgCount]) {
1099b50d902SRodney W. Grimes printf("At EOF\n");
1109b50d902SRodney W. Grimes return (0);
1119b50d902SRodney W. Grimes }
1129b50d902SRodney W. Grimes dot = mp;
1139b50d902SRodney W. Grimes hitit:
1149b50d902SRodney W. Grimes /*
1159b50d902SRodney W. Grimes * Print dot.
1169b50d902SRodney W. Grimes */
1179b50d902SRodney W. Grimes
1189b50d902SRodney W. Grimes list[0] = dot - &message[0] + 1;
119d030d2d2SPoul-Henning Kamp list[1] = 0;
1209b50d902SRodney W. Grimes return (type(list));
1219b50d902SRodney W. Grimes }
1229b50d902SRodney W. Grimes
1239b50d902SRodney W. Grimes /*
1249b50d902SRodney W. Grimes * Save a message in a file. Mark the message as saved
1259b50d902SRodney W. Grimes * so we can discard when the user quits.
1269b50d902SRodney W. Grimes */
1279b50d902SRodney W. Grimes int
save(void * v)128b22a8699SPedro F. Giffuni save(void *v)
1299b50d902SRodney W. Grimes {
130b22a8699SPedro F. Giffuni char *str = v;
1319b50d902SRodney W. Grimes
1329ce73e90SMike Heffner return (save1(str, 1, "save", saveignore));
1339b50d902SRodney W. Grimes }
1349b50d902SRodney W. Grimes
1359b50d902SRodney W. Grimes /*
1369b50d902SRodney W. Grimes * Copy a message to a file without affected its saved-ness
1379b50d902SRodney W. Grimes */
1389b50d902SRodney W. Grimes int
copycmd(void * v)139b22a8699SPedro F. Giffuni copycmd(void *v)
1409b50d902SRodney W. Grimes {
141b22a8699SPedro F. Giffuni char *str = v;
1429b50d902SRodney W. Grimes
1439ce73e90SMike Heffner return (save1(str, 0, "copy", saveignore));
1449b50d902SRodney W. Grimes }
1459b50d902SRodney W. Grimes
1469b50d902SRodney W. Grimes /*
1479b50d902SRodney W. Grimes * Save/copy the indicated messages at the end of the passed file name.
1489b50d902SRodney W. Grimes * If mark is true, mark the message "saved."
1499b50d902SRodney W. Grimes */
1509b50d902SRodney W. Grimes int
save1(char str[],int mark,const char * cmd,struct ignoretab * ignore)1516d8484b0SPhilippe Charnier save1(char str[], int mark, const char *cmd, struct ignoretab *ignore)
1529b50d902SRodney W. Grimes {
1539ce73e90SMike Heffner struct message *mp;
1549ce73e90SMike Heffner char *file;
1559ce73e90SMike Heffner const char *disp;
1569ce73e90SMike Heffner int f, *msgvec, *ip;
1579b50d902SRodney W. Grimes FILE *obuf;
1589b50d902SRodney W. Grimes
1599ce73e90SMike Heffner msgvec = (int *)salloc((msgCount + 2) * sizeof(*msgvec));
1609ce73e90SMike Heffner if ((file = snarf(str, &f)) == NULL)
1619b50d902SRodney W. Grimes return (1);
1629b50d902SRodney W. Grimes if (!f) {
1639b50d902SRodney W. Grimes *msgvec = first(0, MMNORM);
164d030d2d2SPoul-Henning Kamp if (*msgvec == 0) {
1659b50d902SRodney W. Grimes printf("No messages to %s.\n", cmd);
1669b50d902SRodney W. Grimes return (1);
1679b50d902SRodney W. Grimes }
168d030d2d2SPoul-Henning Kamp msgvec[1] = 0;
1699b50d902SRodney W. Grimes }
1709b50d902SRodney W. Grimes if (f && getmsglist(str, msgvec, 0) < 0)
1719b50d902SRodney W. Grimes return (1);
1729ce73e90SMike Heffner if ((file = expand(file)) == NULL)
1739b50d902SRodney W. Grimes return (1);
1749b50d902SRodney W. Grimes printf("\"%s\" ", file);
1759ce73e90SMike Heffner (void)fflush(stdout);
1769b50d902SRodney W. Grimes if (access(file, 0) >= 0)
1779b50d902SRodney W. Grimes disp = "[Appended]";
1789b50d902SRodney W. Grimes else
1799b50d902SRodney W. Grimes disp = "[New file]";
1809b50d902SRodney W. Grimes if ((obuf = Fopen(file, "a")) == NULL) {
1819ce73e90SMike Heffner warn((char *)NULL);
1829b50d902SRodney W. Grimes return (1);
1839b50d902SRodney W. Grimes }
1849b50d902SRodney W. Grimes for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
1859b50d902SRodney W. Grimes mp = &message[*ip - 1];
1869b50d902SRodney W. Grimes touch(mp);
1879ce73e90SMike Heffner if (sendmessage(mp, obuf, ignore, NULL) < 0) {
1880c3a8314SMike Heffner warnx("%s", file);
1899ce73e90SMike Heffner (void)Fclose(obuf);
1909b50d902SRodney W. Grimes return (1);
1919b50d902SRodney W. Grimes }
1929b50d902SRodney W. Grimes if (mark)
1939b50d902SRodney W. Grimes mp->m_flag |= MSAVED;
1949b50d902SRodney W. Grimes }
1959ce73e90SMike Heffner (void)fflush(obuf);
1969b50d902SRodney W. Grimes if (ferror(obuf))
1970c3a8314SMike Heffner warn("%s", file);
1989ce73e90SMike Heffner (void)Fclose(obuf);
1999b50d902SRodney W. Grimes printf("%s\n", disp);
2009b50d902SRodney W. Grimes return (0);
2019b50d902SRodney W. Grimes }
2029b50d902SRodney W. Grimes
2039b50d902SRodney W. Grimes /*
2049b50d902SRodney W. Grimes * Write the indicated messages at the end of the passed
2059b50d902SRodney W. Grimes * file name, minus header and trailing blank line.
2069b50d902SRodney W. Grimes */
2079b50d902SRodney W. Grimes int
swrite(void * v)208b948550dSPedro F. Giffuni swrite(void *v)
2099b50d902SRodney W. Grimes {
210b948550dSPedro F. Giffuni char *str = v;
2119b50d902SRodney W. Grimes
2129ce73e90SMike Heffner return (save1(str, 1, "write", ignoreall));
2139b50d902SRodney W. Grimes }
2149b50d902SRodney W. Grimes
2159b50d902SRodney W. Grimes /*
2169b50d902SRodney W. Grimes * Snarf the file from the end of the command line and
2179b50d902SRodney W. Grimes * return a pointer to it. If there is no file attached,
2189ce73e90SMike Heffner * just return NULL. Put a null in front of the file
2199b50d902SRodney W. Grimes * name so that the message list processing won't see it,
2209b50d902SRodney W. Grimes * unless the file name is the only thing on the line, in
2219b50d902SRodney W. Grimes * which case, return 0 in the reference flag variable.
2229b50d902SRodney W. Grimes */
2239b50d902SRodney W. Grimes
2249b50d902SRodney W. Grimes char *
snarf(char * linebuf,int * flag)225b948550dSPedro F. Giffuni snarf(char *linebuf, int *flag)
2269b50d902SRodney W. Grimes {
2279ce73e90SMike Heffner char *cp;
2289b50d902SRodney W. Grimes
2299b50d902SRodney W. Grimes *flag = 1;
2309b50d902SRodney W. Grimes cp = strlen(linebuf) + linebuf - 1;
2319b50d902SRodney W. Grimes
2329b50d902SRodney W. Grimes /*
2339b50d902SRodney W. Grimes * Strip away trailing blanks.
2349b50d902SRodney W. Grimes */
2359b50d902SRodney W. Grimes
2366d48fa43SAndrey A. Chernov while (cp > linebuf && isspace((unsigned char)*cp))
2379b50d902SRodney W. Grimes cp--;
2389ce73e90SMike Heffner *++cp = '\0';
2399b50d902SRodney W. Grimes
2409b50d902SRodney W. Grimes /*
2419b50d902SRodney W. Grimes * Now search for the beginning of the file name.
2429b50d902SRodney W. Grimes */
2439b50d902SRodney W. Grimes
2446d48fa43SAndrey A. Chernov while (cp > linebuf && !isspace((unsigned char)*cp))
2459b50d902SRodney W. Grimes cp--;
2469b50d902SRodney W. Grimes if (*cp == '\0') {
2479b50d902SRodney W. Grimes printf("No file specified.\n");
2489ce73e90SMike Heffner return (NULL);
2499b50d902SRodney W. Grimes }
2506d48fa43SAndrey A. Chernov if (isspace((unsigned char)*cp))
2519ce73e90SMike Heffner *cp++ = '\0';
2529b50d902SRodney W. Grimes else
2539b50d902SRodney W. Grimes *flag = 0;
2549b50d902SRodney W. Grimes return (cp);
2559b50d902SRodney W. Grimes }
2569b50d902SRodney W. Grimes
2579b50d902SRodney W. Grimes /*
2589b50d902SRodney W. Grimes * Delete messages.
2599b50d902SRodney W. Grimes */
2609b50d902SRodney W. Grimes int
deletecmd(void * v)261b948550dSPedro F. Giffuni deletecmd(void *v)
2629b50d902SRodney W. Grimes {
263b948550dSPedro F. Giffuni int *msgvec = v;
2649ce73e90SMike Heffner
2659b50d902SRodney W. Grimes delm(msgvec);
2669ce73e90SMike Heffner return (0);
2679b50d902SRodney W. Grimes }
2689b50d902SRodney W. Grimes
2699b50d902SRodney W. Grimes /*
2709b50d902SRodney W. Grimes * Delete messages, then type the new dot.
2719b50d902SRodney W. Grimes */
2729b50d902SRodney W. Grimes int
deltype(void * v)273b948550dSPedro F. Giffuni deltype(void *v)
2749b50d902SRodney W. Grimes {
275b948550dSPedro F. Giffuni int *msgvec = v;
2769b50d902SRodney W. Grimes int list[2];
2779b50d902SRodney W. Grimes int lastdot;
2789b50d902SRodney W. Grimes
2799b50d902SRodney W. Grimes lastdot = dot - &message[0] + 1;
2809b50d902SRodney W. Grimes if (delm(msgvec) >= 0) {
2819b50d902SRodney W. Grimes list[0] = dot - &message[0] + 1;
2829b50d902SRodney W. Grimes if (list[0] > lastdot) {
2839b50d902SRodney W. Grimes touch(dot);
284d030d2d2SPoul-Henning Kamp list[1] = 0;
2859b50d902SRodney W. Grimes return (type(list));
2869b50d902SRodney W. Grimes }
2879b50d902SRodney W. Grimes printf("At EOF\n");
2889b50d902SRodney W. Grimes } else
2899b50d902SRodney W. Grimes printf("No more messages\n");
2909b50d902SRodney W. Grimes return (0);
2919b50d902SRodney W. Grimes }
2929b50d902SRodney W. Grimes
2939b50d902SRodney W. Grimes /*
2949b50d902SRodney W. Grimes * Delete the indicated messages.
2959b50d902SRodney W. Grimes * Set dot to some nice place afterwards.
2969b50d902SRodney W. Grimes * Internal interface.
2979b50d902SRodney W. Grimes */
2989b50d902SRodney W. Grimes int
delm(int * msgvec)2996d8484b0SPhilippe Charnier delm(int *msgvec)
3009b50d902SRodney W. Grimes {
3019ce73e90SMike Heffner struct message *mp;
3029ce73e90SMike Heffner int *ip, last;
3039b50d902SRodney W. Grimes
304d030d2d2SPoul-Henning Kamp last = 0;
305d030d2d2SPoul-Henning Kamp for (ip = msgvec; *ip != 0; ip++) {
3069b50d902SRodney W. Grimes mp = &message[*ip - 1];
3079b50d902SRodney W. Grimes touch(mp);
3089b50d902SRodney W. Grimes mp->m_flag |= MDELETED|MTOUCH;
3099b50d902SRodney W. Grimes mp->m_flag &= ~(MPRESERVE|MSAVED|MBOX);
3109b50d902SRodney W. Grimes last = *ip;
3119b50d902SRodney W. Grimes }
312d030d2d2SPoul-Henning Kamp if (last != 0) {
3139b50d902SRodney W. Grimes dot = &message[last-1];
3149b50d902SRodney W. Grimes last = first(0, MDELETED);
315d030d2d2SPoul-Henning Kamp if (last != 0) {
3169b50d902SRodney W. Grimes dot = &message[last-1];
3179b50d902SRodney W. Grimes return (0);
3189b50d902SRodney W. Grimes }
3199b50d902SRodney W. Grimes else {
3209b50d902SRodney W. Grimes dot = &message[0];
3219b50d902SRodney W. Grimes return (-1);
3229b50d902SRodney W. Grimes }
3239b50d902SRodney W. Grimes }
3249b50d902SRodney W. Grimes
3259b50d902SRodney W. Grimes /*
3269b50d902SRodney W. Grimes * Following can't happen -- it keeps lint happy
3279b50d902SRodney W. Grimes */
3289b50d902SRodney W. Grimes
3299b50d902SRodney W. Grimes return (-1);
3309b50d902SRodney W. Grimes }
3319b50d902SRodney W. Grimes
3329b50d902SRodney W. Grimes /*
3339b50d902SRodney W. Grimes * Undelete the indicated messages.
3349b50d902SRodney W. Grimes */
3359b50d902SRodney W. Grimes int
undeletecmd(void * v)336b948550dSPedro F. Giffuni undeletecmd(void *v)
3379b50d902SRodney W. Grimes {
338b948550dSPedro F. Giffuni int *msgvec = v;
3399ce73e90SMike Heffner int *ip;
340b948550dSPedro F. Giffuni struct message *mp;
3419b50d902SRodney W. Grimes
3429b50d902SRodney W. Grimes for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
3439b50d902SRodney W. Grimes mp = &message[*ip - 1];
3449b50d902SRodney W. Grimes touch(mp);
3459b50d902SRodney W. Grimes dot = mp;
3469b50d902SRodney W. Grimes mp->m_flag &= ~MDELETED;
3479b50d902SRodney W. Grimes }
3489ce73e90SMike Heffner return (0);
3499b50d902SRodney W. Grimes }
3509b50d902SRodney W. Grimes
3519b50d902SRodney W. Grimes /*
3529b50d902SRodney W. Grimes * Interactively dump core on "core"
3539b50d902SRodney W. Grimes */
3549b50d902SRodney W. Grimes int
core(void * arg __unused)355*d28a9551SJohn Baldwin core(void *arg __unused)
3569b50d902SRodney W. Grimes {
3579b50d902SRodney W. Grimes int pid;
3589b50d902SRodney W. Grimes
35946ccc3e9SBruce Evans switch (pid = fork()) {
3609b50d902SRodney W. Grimes case -1:
3610c3a8314SMike Heffner warn("fork");
3629b50d902SRodney W. Grimes return (1);
3639b50d902SRodney W. Grimes case 0:
3649b50d902SRodney W. Grimes abort();
3659b50d902SRodney W. Grimes _exit(1);
3669b50d902SRodney W. Grimes }
3679b50d902SRodney W. Grimes printf("Okie dokie");
3689ce73e90SMike Heffner (void)fflush(stdout);
3699b50d902SRodney W. Grimes wait_child(pid);
3700c3a8314SMike Heffner if (WIFSIGNALED(wait_status) && WCOREDUMP(wait_status))
3719b50d902SRodney W. Grimes printf(" -- Core dumped.\n");
3729b50d902SRodney W. Grimes else
3739b50d902SRodney W. Grimes printf(" -- Can't dump core.\n");
3749ce73e90SMike Heffner return (0);
3759b50d902SRodney W. Grimes }
3769b50d902SRodney W. Grimes
3779b50d902SRodney W. Grimes /*
3789b50d902SRodney W. Grimes * Clobber as many bytes of stack as the user requests.
3799b50d902SRodney W. Grimes */
3809b50d902SRodney W. Grimes int
clobber(void * arg)381*d28a9551SJohn Baldwin clobber(void *arg)
3829b50d902SRodney W. Grimes {
383*d28a9551SJohn Baldwin char **argv = arg;
3849ce73e90SMike Heffner int times;
3859b50d902SRodney W. Grimes
3869b50d902SRodney W. Grimes if (argv[0] == 0)
3879b50d902SRodney W. Grimes times = 1;
3889b50d902SRodney W. Grimes else
3899b50d902SRodney W. Grimes times = (atoi(argv[0]) + 511) / 512;
3909b50d902SRodney W. Grimes clob1(times);
3919ce73e90SMike Heffner return (0);
3929b50d902SRodney W. Grimes }
3939b50d902SRodney W. Grimes
3949b50d902SRodney W. Grimes /*
3959b50d902SRodney W. Grimes * Clobber the stack.
3969b50d902SRodney W. Grimes */
3979b50d902SRodney W. Grimes void
clob1(int n)3986d8484b0SPhilippe Charnier clob1(int n)
3999b50d902SRodney W. Grimes {
4009b50d902SRodney W. Grimes char buf[512];
4019ce73e90SMike Heffner char *cp;
4029b50d902SRodney W. Grimes
4039b50d902SRodney W. Grimes if (n <= 0)
4049b50d902SRodney W. Grimes return;
4059b50d902SRodney W. Grimes for (cp = buf; cp < &buf[512]; *cp++ = 0xFF)
4069b50d902SRodney W. Grimes ;
4079b50d902SRodney W. Grimes clob1(n - 1);
4089b50d902SRodney W. Grimes }
4099b50d902SRodney W. Grimes
4109b50d902SRodney W. Grimes /*
4119b50d902SRodney W. Grimes * Add the given header fields to the retained list.
4129b50d902SRodney W. Grimes * If no arguments, print the current list of retained fields.
4139b50d902SRodney W. Grimes */
4149b50d902SRodney W. Grimes int
retfield(void * v)415b948550dSPedro F. Giffuni retfield(void *v)
4169b50d902SRodney W. Grimes {
417b948550dSPedro F. Giffuni char **list = v;
4189b50d902SRodney W. Grimes
4199ce73e90SMike Heffner return (ignore1(list, ignore + 1, "retained"));
4209b50d902SRodney W. Grimes }
4219b50d902SRodney W. Grimes
4229b50d902SRodney W. Grimes /*
4239b50d902SRodney W. Grimes * Add the given header fields to the ignored list.
4249b50d902SRodney W. Grimes * If no arguments, print the current list of ignored fields.
4259b50d902SRodney W. Grimes */
4269b50d902SRodney W. Grimes int
igfield(void * v)427b948550dSPedro F. Giffuni igfield(void *v)
4289b50d902SRodney W. Grimes {
429b948550dSPedro F. Giffuni char **list = v;
4309b50d902SRodney W. Grimes
4319ce73e90SMike Heffner return (ignore1(list, ignore, "ignored"));
4329b50d902SRodney W. Grimes }
4339b50d902SRodney W. Grimes
4349b50d902SRodney W. Grimes int
saveretfield(void * v)435b948550dSPedro F. Giffuni saveretfield(void *v)
4369b50d902SRodney W. Grimes {
437b948550dSPedro F. Giffuni char **list = v;
4389b50d902SRodney W. Grimes
4399ce73e90SMike Heffner return (ignore1(list, saveignore + 1, "retained"));
4409b50d902SRodney W. Grimes }
4419b50d902SRodney W. Grimes
4429b50d902SRodney W. Grimes int
saveigfield(void * v)443b948550dSPedro F. Giffuni saveigfield(void *v)
4449b50d902SRodney W. Grimes {
445b948550dSPedro F. Giffuni char **list = v;
4469b50d902SRodney W. Grimes
4479ce73e90SMike Heffner return (ignore1(list, saveignore, "ignored"));
4489b50d902SRodney W. Grimes }
4499b50d902SRodney W. Grimes
4509b50d902SRodney W. Grimes int
ignore1(char ** list,struct ignoretab * tab,const char * which)451b948550dSPedro F. Giffuni ignore1(char **list, struct ignoretab *tab, const char *which)
4529b50d902SRodney W. Grimes {
4530c3a8314SMike Heffner char field[LINESIZE];
4549b50d902SRodney W. Grimes char **ap;
455b948550dSPedro F. Giffuni struct ignore *igp;
456b948550dSPedro F. Giffuni int h;
4579b50d902SRodney W. Grimes
4589ce73e90SMike Heffner if (*list == NULL)
4599ce73e90SMike Heffner return (igshow(tab, which));
4609b50d902SRodney W. Grimes for (ap = list; *ap != 0; ap++) {
4610c3a8314SMike Heffner istrncpy(field, *ap, sizeof(field));
4629b50d902SRodney W. Grimes if (member(field, tab))
4639b50d902SRodney W. Grimes continue;
4649b50d902SRodney W. Grimes h = hash(field);
4659ce73e90SMike Heffner igp = calloc(1, sizeof(struct ignore));
4669b50d902SRodney W. Grimes igp->i_field = calloc((unsigned)strlen(field) + 1,
4679b50d902SRodney W. Grimes sizeof(char));
4689b50d902SRodney W. Grimes strcpy(igp->i_field, field);
4699b50d902SRodney W. Grimes igp->i_link = tab->i_head[h];
4709b50d902SRodney W. Grimes tab->i_head[h] = igp;
4719b50d902SRodney W. Grimes tab->i_count++;
4729b50d902SRodney W. Grimes }
4739ce73e90SMike Heffner return (0);
4749b50d902SRodney W. Grimes }
4759b50d902SRodney W. Grimes
4769b50d902SRodney W. Grimes /*
4779b50d902SRodney W. Grimes * Print out all currently retained fields.
4789b50d902SRodney W. Grimes */
4799b50d902SRodney W. Grimes int
igshow(struct ignoretab * tab,const char * which)4806d8484b0SPhilippe Charnier igshow(struct ignoretab *tab, const char *which)
4819b50d902SRodney W. Grimes {
4829ce73e90SMike Heffner int h;
4839b50d902SRodney W. Grimes struct ignore *igp;
4849b50d902SRodney W. Grimes char **ap, **ring;
4859b50d902SRodney W. Grimes
4869b50d902SRodney W. Grimes if (tab->i_count == 0) {
4879b50d902SRodney W. Grimes printf("No fields currently being %s.\n", which);
4889ce73e90SMike Heffner return (0);
4899b50d902SRodney W. Grimes }
4909b50d902SRodney W. Grimes ring = (char **)salloc((tab->i_count + 1) * sizeof(char *));
4919b50d902SRodney W. Grimes ap = ring;
4929b50d902SRodney W. Grimes for (h = 0; h < HSHSIZE; h++)
4939ce73e90SMike Heffner for (igp = tab->i_head[h]; igp != NULL; igp = igp->i_link)
4949b50d902SRodney W. Grimes *ap++ = igp->i_field;
4959b50d902SRodney W. Grimes *ap = 0;
4969b50d902SRodney W. Grimes qsort(ring, tab->i_count, sizeof(char *), igcomp);
4979b50d902SRodney W. Grimes for (ap = ring; *ap != 0; ap++)
4989b50d902SRodney W. Grimes printf("%s\n", *ap);
4999ce73e90SMike Heffner return (0);
5009b50d902SRodney W. Grimes }
5019b50d902SRodney W. Grimes
5029b50d902SRodney W. Grimes /*
5039b50d902SRodney W. Grimes * Compare two names for sorting ignored field list.
5049b50d902SRodney W. Grimes */
5059b50d902SRodney W. Grimes int
igcomp(const void * l,const void * r)5066d8484b0SPhilippe Charnier igcomp(const void *l, const void *r)
5079b50d902SRodney W. Grimes {
5089ce73e90SMike Heffner
5099ce73e90SMike Heffner return (strcmp(*(const char **)l, *(const char **)r));
5109b50d902SRodney W. Grimes }
511