2017-11-20 19:49:47 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
1994-05-27 12:33:43 +00:00
|
|
|
* Copyright (c) 1980, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-27 12:33:43 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
2001-03-25 04:57:05 +00:00
|
|
|
#if 0
|
1994-05-27 12:33:43 +00:00
|
|
|
static char sccsid[] = "@(#)cmd2.c 8.1 (Berkeley) 6/6/93";
|
2001-03-25 04:57:05 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif /* not lint */
|
2002-06-30 05:25:07 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#include "rcv.h"
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include "extern.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mail -- a mail program
|
|
|
|
*
|
|
|
|
* More user commands.
|
|
|
|
*/
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
extern int wait_status;
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* If any arguments were given, go to the next applicable argument
|
|
|
|
* following dot, otherwise, go to the next applicable message.
|
|
|
|
* If given as first command with no arguments, print first message.
|
|
|
|
*/
|
|
|
|
int
|
2016-07-15 15:37:54 +00:00
|
|
|
next(void *v)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
struct message *mp;
|
2016-07-15 15:37:54 +00:00
|
|
|
int *msgvec = v;
|
2001-05-27 20:26:22 +00:00
|
|
|
int *ip, *ip2, list[2], mdot;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1997-09-18 14:08:40 +00:00
|
|
|
if (*msgvec != 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
1995-05-30 06:41:30 +00:00
|
|
|
* If some messages were supplied, find the
|
1994-05-27 12:33:43 +00:00
|
|
|
* first applicable one following dot using
|
|
|
|
* wrap around.
|
|
|
|
*/
|
|
|
|
|
|
|
|
mdot = dot - &message[0] + 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the first message in the supplied
|
|
|
|
* message list which follows dot.
|
|
|
|
*/
|
|
|
|
|
1997-09-18 14:08:40 +00:00
|
|
|
for (ip = msgvec; *ip != 0; ip++)
|
1994-05-27 12:33:43 +00:00
|
|
|
if (*ip > mdot)
|
|
|
|
break;
|
1997-09-18 14:08:40 +00:00
|
|
|
if (*ip == 0)
|
1994-05-27 12:33:43 +00:00
|
|
|
ip = msgvec;
|
|
|
|
ip2 = ip;
|
|
|
|
do {
|
|
|
|
mp = &message[*ip2 - 1];
|
|
|
|
if ((mp->m_flag & MDELETED) == 0) {
|
|
|
|
dot = mp;
|
|
|
|
goto hitit;
|
|
|
|
}
|
1997-09-18 14:08:40 +00:00
|
|
|
if (*ip2 != 0)
|
1994-05-27 12:33:43 +00:00
|
|
|
ip2++;
|
1997-09-18 14:08:40 +00:00
|
|
|
if (*ip2 == 0)
|
1994-05-27 12:33:43 +00:00
|
|
|
ip2 = msgvec;
|
|
|
|
} while (ip2 != ip);
|
|
|
|
printf("No messages applicable\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is the first command, select message 1.
|
|
|
|
* Note that this must exist for us to get here at all.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!sawcom)
|
|
|
|
goto hitit;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Just find the next good message after dot, no
|
|
|
|
* wraparound.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (mp = dot+1; mp < &message[msgCount]; mp++)
|
|
|
|
if ((mp->m_flag & (MDELETED|MSAVED)) == 0)
|
|
|
|
break;
|
|
|
|
if (mp >= &message[msgCount]) {
|
|
|
|
printf("At EOF\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
dot = mp;
|
|
|
|
hitit:
|
|
|
|
/*
|
|
|
|
* Print dot.
|
|
|
|
*/
|
|
|
|
|
|
|
|
list[0] = dot - &message[0] + 1;
|
1997-09-18 14:08:40 +00:00
|
|
|
list[1] = 0;
|
2001-05-27 20:26:22 +00:00
|
|
|
return (type(list));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save a message in a file. Mark the message as saved
|
|
|
|
* so we can discard when the user quits.
|
|
|
|
*/
|
|
|
|
int
|
2016-07-13 16:45:26 +00:00
|
|
|
save(void *v)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2016-07-13 16:45:26 +00:00
|
|
|
char *str = v;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
return (save1(str, 1, "save", saveignore));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy a message to a file without affected its saved-ness
|
|
|
|
*/
|
|
|
|
int
|
2016-07-13 16:45:26 +00:00
|
|
|
copycmd(void *v)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2016-07-13 16:45:26 +00:00
|
|
|
char *str = v;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
return (save1(str, 0, "copy", saveignore));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save/copy the indicated messages at the end of the passed file name.
|
|
|
|
* If mark is true, mark the message "saved."
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
save1(char str[], int mark, const char *cmd, struct ignoretab *ignore)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
struct message *mp;
|
|
|
|
char *file;
|
|
|
|
const char *disp;
|
|
|
|
int f, *msgvec, *ip;
|
1994-05-27 12:33:43 +00:00
|
|
|
FILE *obuf;
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
msgvec = (int *)salloc((msgCount + 2) * sizeof(*msgvec));
|
|
|
|
if ((file = snarf(str, &f)) == NULL)
|
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (!f) {
|
|
|
|
*msgvec = first(0, MMNORM);
|
1997-09-18 14:08:40 +00:00
|
|
|
if (*msgvec == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("No messages to %s.\n", cmd);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1997-09-18 14:08:40 +00:00
|
|
|
msgvec[1] = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (f && getmsglist(str, msgvec, 0) < 0)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
|
|
|
if ((file = expand(file)) == NULL)
|
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("\"%s\" ", file);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fflush(stdout);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (access(file, 0) >= 0)
|
|
|
|
disp = "[Appended]";
|
|
|
|
else
|
|
|
|
disp = "[New file]";
|
|
|
|
if ((obuf = Fopen(file, "a")) == NULL) {
|
2001-05-27 20:26:22 +00:00
|
|
|
warn((char *)NULL);
|
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
|
|
|
|
mp = &message[*ip - 1];
|
|
|
|
touch(mp);
|
2001-05-27 20:26:22 +00:00
|
|
|
if (sendmessage(mp, obuf, ignore, NULL) < 0) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warnx("%s", file);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(obuf);
|
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (mark)
|
|
|
|
mp->m_flag |= MSAVED;
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fflush(obuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (ferror(obuf))
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", file);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(obuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("%s\n", disp);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the indicated messages at the end of the passed
|
|
|
|
* file name, minus header and trailing blank line.
|
|
|
|
*/
|
|
|
|
int
|
2016-07-15 15:37:54 +00:00
|
|
|
swrite(void *v)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2016-07-15 15:37:54 +00:00
|
|
|
char *str = v;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
return (save1(str, 1, "write", ignoreall));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Snarf the file from the end of the command line and
|
|
|
|
* return a pointer to it. If there is no file attached,
|
2001-05-27 20:26:22 +00:00
|
|
|
* just return NULL. Put a null in front of the file
|
1994-05-27 12:33:43 +00:00
|
|
|
* name so that the message list processing won't see it,
|
|
|
|
* unless the file name is the only thing on the line, in
|
|
|
|
* which case, return 0 in the reference flag variable.
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *
|
2016-07-15 15:37:54 +00:00
|
|
|
snarf(char *linebuf, int *flag)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
char *cp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
*flag = 1;
|
|
|
|
cp = strlen(linebuf) + linebuf - 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Strip away trailing blanks.
|
|
|
|
*/
|
|
|
|
|
2001-12-19 21:50:22 +00:00
|
|
|
while (cp > linebuf && isspace((unsigned char)*cp))
|
1994-05-27 12:33:43 +00:00
|
|
|
cp--;
|
2001-05-27 20:26:22 +00:00
|
|
|
*++cp = '\0';
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now search for the beginning of the file name.
|
|
|
|
*/
|
|
|
|
|
2001-12-19 21:50:22 +00:00
|
|
|
while (cp > linebuf && !isspace((unsigned char)*cp))
|
1994-05-27 12:33:43 +00:00
|
|
|
cp--;
|
|
|
|
if (*cp == '\0') {
|
|
|
|
printf("No file specified.\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-12-19 21:50:22 +00:00
|
|
|
if (isspace((unsigned char)*cp))
|
2001-05-27 20:26:22 +00:00
|
|
|
*cp++ = '\0';
|
1994-05-27 12:33:43 +00:00
|
|
|
else
|
|
|
|
*flag = 0;
|
2001-05-27 20:26:22 +00:00
|
|
|
return (cp);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete messages.
|
|
|
|
*/
|
|
|
|
int
|
2016-07-15 15:37:54 +00:00
|
|
|
deletecmd(void *v)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2016-07-15 15:37:54 +00:00
|
|
|
int *msgvec = v;
|
2001-05-27 20:26:22 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
delm(msgvec);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete messages, then type the new dot.
|
|
|
|
*/
|
|
|
|
int
|
2016-07-15 15:37:54 +00:00
|
|
|
deltype(void *v)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2016-07-15 15:37:54 +00:00
|
|
|
int *msgvec = v;
|
1994-05-27 12:33:43 +00:00
|
|
|
int list[2];
|
|
|
|
int lastdot;
|
|
|
|
|
|
|
|
lastdot = dot - &message[0] + 1;
|
|
|
|
if (delm(msgvec) >= 0) {
|
|
|
|
list[0] = dot - &message[0] + 1;
|
|
|
|
if (list[0] > lastdot) {
|
|
|
|
touch(dot);
|
1997-09-18 14:08:40 +00:00
|
|
|
list[1] = 0;
|
2001-05-27 20:26:22 +00:00
|
|
|
return (type(list));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
printf("At EOF\n");
|
|
|
|
} else
|
|
|
|
printf("No more messages\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete the indicated messages.
|
|
|
|
* Set dot to some nice place afterwards.
|
|
|
|
* Internal interface.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
delm(int *msgvec)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
struct message *mp;
|
|
|
|
int *ip, last;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1997-09-18 14:08:40 +00:00
|
|
|
last = 0;
|
|
|
|
for (ip = msgvec; *ip != 0; ip++) {
|
1994-05-27 12:33:43 +00:00
|
|
|
mp = &message[*ip - 1];
|
|
|
|
touch(mp);
|
|
|
|
mp->m_flag |= MDELETED|MTOUCH;
|
|
|
|
mp->m_flag &= ~(MPRESERVE|MSAVED|MBOX);
|
|
|
|
last = *ip;
|
|
|
|
}
|
1997-09-18 14:08:40 +00:00
|
|
|
if (last != 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
dot = &message[last-1];
|
|
|
|
last = first(0, MDELETED);
|
1997-09-18 14:08:40 +00:00
|
|
|
if (last != 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
dot = &message[last-1];
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
dot = &message[0];
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Following can't happen -- it keeps lint happy
|
|
|
|
*/
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Undelete the indicated messages.
|
|
|
|
*/
|
|
|
|
int
|
2016-07-15 15:37:54 +00:00
|
|
|
undeletecmd(void *v)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2016-07-15 15:37:54 +00:00
|
|
|
int *msgvec = v;
|
2001-05-27 20:26:22 +00:00
|
|
|
int *ip;
|
2016-07-15 15:37:54 +00:00
|
|
|
struct message *mp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
|
|
|
|
mp = &message[*ip - 1];
|
|
|
|
touch(mp);
|
|
|
|
dot = mp;
|
|
|
|
mp->m_flag &= ~MDELETED;
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interactively dump core on "core"
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
core(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
int pid;
|
|
|
|
|
1998-10-10 19:21:39 +00:00
|
|
|
switch (pid = fork()) {
|
1994-05-27 12:33:43 +00:00
|
|
|
case -1:
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("fork");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
case 0:
|
|
|
|
abort();
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
printf("Okie dokie");
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fflush(stdout);
|
1994-05-27 12:33:43 +00:00
|
|
|
wait_child(pid);
|
2001-03-25 04:57:05 +00:00
|
|
|
if (WIFSIGNALED(wait_status) && WCOREDUMP(wait_status))
|
1994-05-27 12:33:43 +00:00
|
|
|
printf(" -- Core dumped.\n");
|
|
|
|
else
|
|
|
|
printf(" -- Can't dump core.\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clobber as many bytes of stack as the user requests.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
clobber(char **argv)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int times;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (argv[0] == 0)
|
|
|
|
times = 1;
|
|
|
|
else
|
|
|
|
times = (atoi(argv[0]) + 511) / 512;
|
|
|
|
clob1(times);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clobber the stack.
|
|
|
|
*/
|
|
|
|
void
|
2010-12-19 16:25:23 +00:00
|
|
|
clob1(int n)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
char buf[512];
|
2001-05-27 20:26:22 +00:00
|
|
|
char *cp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (n <= 0)
|
|
|
|
return;
|
|
|
|
for (cp = buf; cp < &buf[512]; *cp++ = 0xFF)
|
|
|
|
;
|
|
|
|
clob1(n - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the given header fields to the retained list.
|
|
|
|
* If no arguments, print the current list of retained fields.
|
|
|
|
*/
|
|
|
|
int
|
2016-07-15 15:37:54 +00:00
|
|
|
retfield(void *v)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2016-07-15 15:37:54 +00:00
|
|
|
char **list = v;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
return (ignore1(list, ignore + 1, "retained"));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the given header fields to the ignored list.
|
|
|
|
* If no arguments, print the current list of ignored fields.
|
|
|
|
*/
|
|
|
|
int
|
2016-07-15 15:37:54 +00:00
|
|
|
igfield(void *v)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2016-07-15 15:37:54 +00:00
|
|
|
char **list = v;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
return (ignore1(list, ignore, "ignored"));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-07-15 15:37:54 +00:00
|
|
|
saveretfield(void *v)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2016-07-15 15:37:54 +00:00
|
|
|
char **list = v;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
return (ignore1(list, saveignore + 1, "retained"));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-07-15 15:37:54 +00:00
|
|
|
saveigfield(void *v)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2016-07-15 15:37:54 +00:00
|
|
|
char **list = v;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
return (ignore1(list, saveignore, "ignored"));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-07-15 15:37:54 +00:00
|
|
|
ignore1(char **list, struct ignoretab *tab, const char *which)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-03-25 04:57:05 +00:00
|
|
|
char field[LINESIZE];
|
1994-05-27 12:33:43 +00:00
|
|
|
char **ap;
|
2016-07-15 15:37:54 +00:00
|
|
|
struct ignore *igp;
|
|
|
|
int h;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
if (*list == NULL)
|
|
|
|
return (igshow(tab, which));
|
1994-05-27 12:33:43 +00:00
|
|
|
for (ap = list; *ap != 0; ap++) {
|
2001-03-25 04:57:05 +00:00
|
|
|
istrncpy(field, *ap, sizeof(field));
|
1994-05-27 12:33:43 +00:00
|
|
|
if (member(field, tab))
|
|
|
|
continue;
|
|
|
|
h = hash(field);
|
2001-05-27 20:26:22 +00:00
|
|
|
igp = calloc(1, sizeof(struct ignore));
|
|
|
|
igp->i_field = calloc((unsigned)strlen(field) + 1,
|
|
|
|
sizeof(char));
|
1994-05-27 12:33:43 +00:00
|
|
|
strcpy(igp->i_field, field);
|
|
|
|
igp->i_link = tab->i_head[h];
|
|
|
|
tab->i_head[h] = igp;
|
|
|
|
tab->i_count++;
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out all currently retained fields.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
igshow(struct ignoretab *tab, const char *which)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int h;
|
1994-05-27 12:33:43 +00:00
|
|
|
struct ignore *igp;
|
|
|
|
char **ap, **ring;
|
|
|
|
|
|
|
|
if (tab->i_count == 0) {
|
|
|
|
printf("No fields currently being %s.\n", which);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
ring = (char **)salloc((tab->i_count + 1) * sizeof(char *));
|
1994-05-27 12:33:43 +00:00
|
|
|
ap = ring;
|
|
|
|
for (h = 0; h < HSHSIZE; h++)
|
2001-05-27 20:26:22 +00:00
|
|
|
for (igp = tab->i_head[h]; igp != NULL; igp = igp->i_link)
|
1994-05-27 12:33:43 +00:00
|
|
|
*ap++ = igp->i_field;
|
|
|
|
*ap = 0;
|
2001-05-27 20:26:22 +00:00
|
|
|
qsort(ring, tab->i_count, sizeof(char *), igcomp);
|
1994-05-27 12:33:43 +00:00
|
|
|
for (ap = ring; *ap != 0; ap++)
|
|
|
|
printf("%s\n", *ap);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare two names for sorting ignored field list.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
igcomp(const void *l, const void *r)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
|
|
|
|
return (strcmp(*(const char **)l, *(const char **)r));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|