Home | History | Annotate | Line # | Download | only in mail
cmd2.c revision 1.19
      1  1.19  christos /*	$NetBSD: cmd2.c,v 1.19 2005/07/19 23:07:10 christos Exp $	*/
      2   1.5  christos 
      3   1.1       cgd /*
      4   1.3   deraadt  * Copyright (c) 1980, 1993
      5   1.3   deraadt  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15  1.17       agc  * 3. Neither the name of the University nor the names of its contributors
     16   1.1       cgd  *    may be used to endorse or promote products derived from this software
     17   1.1       cgd  *    without specific prior written permission.
     18   1.1       cgd  *
     19   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1       cgd  * SUCH DAMAGE.
     30   1.1       cgd  */
     31   1.1       cgd 
     32   1.8     lukem #include <sys/cdefs.h>
     33   1.1       cgd #ifndef lint
     34   1.5  christos #if 0
     35   1.5  christos static char sccsid[] = "@(#)cmd2.c	8.1 (Berkeley) 6/6/93";
     36   1.5  christos #else
     37  1.19  christos __RCSID("$NetBSD: cmd2.c,v 1.19 2005/07/19 23:07:10 christos Exp $");
     38   1.5  christos #endif
     39   1.1       cgd #endif /* not lint */
     40   1.1       cgd 
     41   1.1       cgd #include "rcv.h"
     42   1.3   deraadt #include "extern.h"
     43   1.1       cgd 
     44   1.1       cgd /*
     45   1.1       cgd  * Mail -- a mail program
     46   1.1       cgd  *
     47   1.1       cgd  * More user commands.
     48   1.1       cgd  */
     49  1.12       wiz static int igcomp(const void *, const void *);
     50   1.1       cgd 
     51   1.1       cgd /*
     52   1.1       cgd  * If any arguments were given, go to the next applicable argument
     53   1.1       cgd  * following dot, otherwise, go to the next applicable message.
     54   1.1       cgd  * If given as first command with no arguments, print first message.
     55   1.1       cgd  */
     56   1.3   deraadt int
     57  1.12       wiz next(void *v)
     58   1.1       cgd {
     59   1.5  christos 	int *msgvec = v;
     60   1.8     lukem 	struct message *mp;
     61   1.8     lukem 	int *ip, *ip2;
     62   1.1       cgd 	int list[2], mdot;
     63   1.1       cgd 
     64   1.7        pk 	if (*msgvec != 0) {
     65   1.1       cgd 
     66   1.1       cgd 		/*
     67   1.7        pk 		 * If some messages were supplied, find the
     68   1.1       cgd 		 * first applicable one following dot using
     69   1.1       cgd 		 * wrap around.
     70   1.1       cgd 		 */
     71   1.1       cgd 
     72   1.1       cgd 		mdot = dot - &message[0] + 1;
     73   1.1       cgd 
     74   1.1       cgd 		/*
     75   1.1       cgd 		 * Find the first message in the supplied
     76   1.1       cgd 		 * message list which follows dot.
     77   1.1       cgd 		 */
     78   1.1       cgd 
     79   1.7        pk 		for (ip = msgvec; *ip != 0; ip++)
     80   1.1       cgd 			if (*ip > mdot)
     81   1.1       cgd 				break;
     82   1.7        pk 		if (*ip == 0)
     83   1.1       cgd 			ip = msgvec;
     84   1.1       cgd 		ip2 = ip;
     85   1.1       cgd 		do {
     86   1.1       cgd 			mp = &message[*ip2 - 1];
     87   1.1       cgd 			if ((mp->m_flag & MDELETED) == 0) {
     88   1.1       cgd 				dot = mp;
     89   1.1       cgd 				goto hitit;
     90   1.1       cgd 			}
     91   1.7        pk 			if (*ip2 != 0)
     92   1.1       cgd 				ip2++;
     93   1.7        pk 			if (*ip2 == 0)
     94   1.1       cgd 				ip2 = msgvec;
     95   1.1       cgd 		} while (ip2 != ip);
     96  1.19  christos 		(void)printf("No messages applicable\n");
     97   1.1       cgd 		return(1);
     98   1.1       cgd 	}
     99   1.1       cgd 
    100   1.1       cgd 	/*
    101   1.1       cgd 	 * If this is the first command, select message 1.
    102   1.1       cgd 	 * Note that this must exist for us to get here at all.
    103   1.1       cgd 	 */
    104   1.1       cgd 
    105   1.1       cgd 	if (!sawcom)
    106   1.1       cgd 		goto hitit;
    107   1.1       cgd 
    108   1.1       cgd 	/*
    109   1.1       cgd 	 * Just find the next good message after dot, no
    110   1.1       cgd 	 * wraparound.
    111   1.1       cgd 	 */
    112   1.1       cgd 
    113   1.1       cgd 	for (mp = dot+1; mp < &message[msgCount]; mp++)
    114   1.1       cgd 		if ((mp->m_flag & (MDELETED|MSAVED)) == 0)
    115   1.1       cgd 			break;
    116   1.1       cgd 	if (mp >= &message[msgCount]) {
    117  1.19  christos 		(void)printf("At EOF\n");
    118   1.1       cgd 		return(0);
    119   1.1       cgd 	}
    120   1.1       cgd 	dot = mp;
    121   1.1       cgd hitit:
    122   1.1       cgd 	/*
    123   1.1       cgd 	 * Print dot.
    124   1.1       cgd 	 */
    125   1.1       cgd 
    126   1.1       cgd 	list[0] = dot - &message[0] + 1;
    127   1.7        pk 	list[1] = 0;
    128   1.1       cgd 	return(type(list));
    129   1.1       cgd }
    130   1.1       cgd 
    131   1.1       cgd /*
    132   1.1       cgd  * Save a message in a file.  Mark the message as saved
    133   1.1       cgd  * so we can discard when the user quits.
    134   1.1       cgd  */
    135   1.3   deraadt int
    136  1.12       wiz save(void *v)
    137   1.1       cgd {
    138   1.5  christos 	char *str = v;
    139   1.1       cgd 
    140   1.1       cgd 	return save1(str, 1, "save", saveignore);
    141  1.16      ross }
    142  1.16      ross 
    143  1.16      ross /*
    144  1.16      ross  * Save a message in a file.  Mark the message as saved
    145  1.16      ross  * so we can discard when the user quits.  Save all fields
    146  1.16      ross  * overriding saveignore and saveretain.
    147  1.16      ross  */
    148  1.16      ross int
    149  1.16      ross Save(v)
    150  1.16      ross 	void *v;
    151  1.16      ross {
    152  1.16      ross 	char *str = v;
    153  1.16      ross 
    154  1.16      ross 	return save1(str, 1, "Save", NULL);
    155   1.1       cgd }
    156   1.1       cgd 
    157   1.1       cgd /*
    158   1.1       cgd  * Copy a message to a file without affected its saved-ness
    159   1.1       cgd  */
    160   1.3   deraadt int
    161  1.12       wiz copycmd(void *v)
    162   1.1       cgd {
    163   1.5  christos 	char *str = v;
    164   1.1       cgd 
    165   1.1       cgd 	return save1(str, 0, "copy", saveignore);
    166   1.1       cgd }
    167   1.1       cgd 
    168   1.1       cgd /*
    169   1.1       cgd  * Save/copy the indicated messages at the end of the passed file name.
    170  1.13       wiz  * If markmsg is true, mark the message "saved."
    171   1.1       cgd  */
    172   1.3   deraadt int
    173  1.18  christos save1(char str[], int markmsg, const char *cmd, struct ignoretab *ignoretabs)
    174   1.1       cgd {
    175   1.8     lukem 	int *ip;
    176   1.8     lukem 	struct message *mp;
    177  1.18  christos 	const char *fn;
    178  1.18  christos 	const char *disp;
    179   1.1       cgd 	int f, *msgvec;
    180   1.1       cgd 	FILE *obuf;
    181   1.1       cgd 
    182  1.18  christos 	msgvec = salloc((msgCount + 2) * sizeof *msgvec);
    183  1.14       wiz 	if ((fn = snarf(str, &f)) == NULL)
    184   1.1       cgd 		return(1);
    185   1.1       cgd 	if (!f) {
    186   1.1       cgd 		*msgvec = first(0, MMNORM);
    187   1.7        pk 		if (*msgvec == 0) {
    188  1.19  christos 			(void)printf("No messages to %s.\n", cmd);
    189   1.1       cgd 			return(1);
    190   1.1       cgd 		}
    191   1.7        pk 		msgvec[1] = 0;
    192   1.1       cgd 	}
    193   1.1       cgd 	if (f && getmsglist(str, msgvec, 0) < 0)
    194   1.1       cgd 		return(1);
    195  1.14       wiz 	if ((fn = expand(fn)) == NULL)
    196   1.1       cgd 		return(1);
    197  1.19  christos 	(void)printf("\"%s\" ", fn);
    198  1.19  christos 	(void)fflush(stdout);
    199  1.13       wiz 	if (access(fn, 0) >= 0)
    200   1.1       cgd 		disp = "[Appended]";
    201   1.1       cgd 	else
    202   1.1       cgd 		disp = "[New file]";
    203  1.13       wiz 	if ((obuf = Fopen(fn, "a")) == NULL) {
    204  1.15       wiz 		warn(NULL);
    205   1.1       cgd 		return(1);
    206   1.1       cgd 	}
    207   1.1       cgd 	for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
    208   1.1       cgd 		mp = &message[*ip - 1];
    209   1.1       cgd 		touch(mp);
    210  1.14       wiz 		if (sendmessage(mp, obuf, ignoretabs, NULL) < 0) {
    211  1.15       wiz 			warn("%s", fn);
    212  1.19  christos 			(void)Fclose(obuf);
    213   1.1       cgd 			return(1);
    214   1.1       cgd 		}
    215  1.13       wiz 		if (markmsg)
    216   1.1       cgd 			mp->m_flag |= MSAVED;
    217   1.1       cgd 	}
    218  1.19  christos 	(void)fflush(obuf);
    219   1.1       cgd 	if (ferror(obuf))
    220  1.15       wiz 		warn("%s", fn);
    221  1.19  christos 	(void)Fclose(obuf);
    222  1.19  christos 	(void)printf("%s\n", disp);
    223   1.1       cgd 	return(0);
    224   1.1       cgd }
    225   1.1       cgd 
    226   1.1       cgd /*
    227   1.1       cgd  * Write the indicated messages at the end of the passed
    228   1.1       cgd  * file name, minus header and trailing blank line.
    229   1.1       cgd  */
    230   1.3   deraadt int
    231  1.12       wiz swrite(void *v)
    232   1.1       cgd {
    233   1.5  christos 	char *str = v;
    234   1.1       cgd 
    235   1.1       cgd 	return save1(str, 1, "write", ignoreall);
    236   1.1       cgd }
    237   1.1       cgd 
    238   1.1       cgd /*
    239   1.1       cgd  * Snarf the file from the end of the command line and
    240   1.1       cgd  * return a pointer to it.  If there is no file attached,
    241  1.14       wiz  * just return NULL.  Put a null in front of the file
    242   1.1       cgd  * name so that the message list processing won't see it,
    243   1.1       cgd  * unless the file name is the only thing on the line, in
    244   1.1       cgd  * which case, return 0 in the reference flag variable.
    245   1.1       cgd  */
    246   1.1       cgd 
    247   1.1       cgd char *
    248  1.12       wiz snarf(char linebuf[], int *flag)
    249   1.1       cgd {
    250   1.8     lukem 	char *cp;
    251   1.1       cgd 
    252   1.1       cgd 	*flag = 1;
    253   1.1       cgd 	cp = strlen(linebuf) + linebuf - 1;
    254   1.1       cgd 
    255   1.1       cgd 	/*
    256   1.1       cgd 	 * Strip away trailing blanks.
    257   1.1       cgd 	 */
    258   1.1       cgd 
    259   1.9  christos 	while (cp > linebuf && isspace((unsigned char)*cp))
    260   1.1       cgd 		cp--;
    261   1.1       cgd 	*++cp = 0;
    262   1.1       cgd 
    263   1.1       cgd 	/*
    264   1.1       cgd 	 * Now search for the beginning of the file name.
    265   1.1       cgd 	 */
    266   1.1       cgd 
    267   1.9  christos 	while (cp > linebuf && !isspace((unsigned char)*cp))
    268   1.1       cgd 		cp--;
    269   1.1       cgd 	if (*cp == '\0') {
    270  1.19  christos 		(void)printf("No file specified.\n");
    271  1.14       wiz 		return(NULL);
    272   1.1       cgd 	}
    273   1.9  christos 	if (isspace((unsigned char)*cp))
    274   1.1       cgd 		*cp++ = 0;
    275   1.1       cgd 	else
    276   1.1       cgd 		*flag = 0;
    277   1.1       cgd 	return(cp);
    278   1.1       cgd }
    279   1.1       cgd 
    280   1.1       cgd /*
    281   1.1       cgd  * Delete messages.
    282   1.1       cgd  */
    283   1.3   deraadt int
    284  1.12       wiz delete(void *v)
    285   1.1       cgd {
    286   1.5  christos 	int *msgvec = v;
    287  1.19  christos 	(void)delm(msgvec);
    288   1.1       cgd 	return 0;
    289   1.1       cgd }
    290   1.1       cgd 
    291   1.1       cgd /*
    292   1.1       cgd  * Delete messages, then type the new dot.
    293   1.1       cgd  */
    294   1.3   deraadt int
    295  1.12       wiz deltype(void *v)
    296   1.1       cgd {
    297   1.5  christos 	int *msgvec = v;
    298   1.1       cgd 	int list[2];
    299   1.1       cgd 	int lastdot;
    300   1.1       cgd 
    301   1.1       cgd 	lastdot = dot - &message[0] + 1;
    302   1.1       cgd 	if (delm(msgvec) >= 0) {
    303   1.1       cgd 		list[0] = dot - &message[0] + 1;
    304   1.1       cgd 		if (list[0] > lastdot) {
    305   1.1       cgd 			touch(dot);
    306   1.7        pk 			list[1] = 0;
    307   1.1       cgd 			return(type(list));
    308   1.1       cgd 		}
    309  1.19  christos 		(void)printf("At EOF\n");
    310   1.1       cgd 	} else
    311  1.19  christos 		(void)printf("No more messages\n");
    312   1.1       cgd 	return(0);
    313   1.1       cgd }
    314   1.1       cgd 
    315   1.1       cgd /*
    316   1.1       cgd  * Delete the indicated messages.
    317   1.1       cgd  * Set dot to some nice place afterwards.
    318   1.1       cgd  * Internal interface.
    319   1.1       cgd  */
    320   1.3   deraadt int
    321  1.12       wiz delm(int *msgvec)
    322   1.1       cgd {
    323   1.8     lukem 	struct message *mp;
    324   1.8     lukem 	int *ip;
    325   1.1       cgd 	int last;
    326   1.1       cgd 
    327   1.7        pk 	last = 0;
    328   1.7        pk 	for (ip = msgvec; *ip != 0; ip++) {
    329   1.1       cgd 		mp = &message[*ip - 1];
    330   1.1       cgd 		touch(mp);
    331   1.1       cgd 		mp->m_flag |= MDELETED|MTOUCH;
    332   1.1       cgd 		mp->m_flag &= ~(MPRESERVE|MSAVED|MBOX);
    333   1.1       cgd 		last = *ip;
    334   1.1       cgd 	}
    335   1.7        pk 	if (last != 0) {
    336   1.1       cgd 		dot = &message[last-1];
    337   1.1       cgd 		last = first(0, MDELETED);
    338   1.7        pk 		if (last != 0) {
    339   1.1       cgd 			dot = &message[last-1];
    340   1.1       cgd 			return(0);
    341   1.1       cgd 		}
    342   1.1       cgd 		else {
    343   1.1       cgd 			dot = &message[0];
    344   1.1       cgd 			return(-1);
    345   1.1       cgd 		}
    346   1.1       cgd 	}
    347   1.1       cgd 
    348   1.1       cgd 	/*
    349   1.1       cgd 	 * Following can't happen -- it keeps lint happy
    350   1.1       cgd 	 */
    351   1.1       cgd 
    352   1.1       cgd 	return(-1);
    353   1.1       cgd }
    354   1.1       cgd 
    355   1.1       cgd /*
    356   1.1       cgd  * Undelete the indicated messages.
    357   1.1       cgd  */
    358   1.3   deraadt int
    359  1.12       wiz undeletecmd(void *v)
    360   1.1       cgd {
    361   1.5  christos 	int *msgvec = v;
    362   1.8     lukem 	struct message *mp;
    363   1.8     lukem 	int *ip;
    364   1.1       cgd 
    365   1.1       cgd 	for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
    366   1.1       cgd 		mp = &message[*ip - 1];
    367   1.1       cgd 		touch(mp);
    368   1.1       cgd 		dot = mp;
    369   1.1       cgd 		mp->m_flag &= ~MDELETED;
    370   1.1       cgd 	}
    371   1.1       cgd 	return 0;
    372   1.1       cgd }
    373   1.1       cgd 
    374   1.1       cgd /*
    375   1.1       cgd  * Interactively dump core on "core"
    376   1.1       cgd  */
    377   1.3   deraadt int
    378  1.19  christos /*ARGSUSED*/
    379  1.12       wiz core(void *v)
    380   1.1       cgd {
    381   1.1       cgd 	int pid;
    382   1.1       cgd 
    383   1.1       cgd 	switch (pid = vfork()) {
    384   1.1       cgd 	case -1:
    385  1.15       wiz 		warn("fork");
    386   1.1       cgd 		return(1);
    387   1.1       cgd 	case 0:
    388   1.1       cgd 		abort();
    389   1.1       cgd 		_exit(1);
    390   1.1       cgd 	}
    391  1.19  christos 	(void)printf("Okie dokie");
    392  1.19  christos 	(void)fflush(stdout);
    393  1.19  christos 	(void)wait_child(pid);
    394   1.9  christos 	if (WCOREDUMP(wait_status))
    395  1.19  christos 		(void)printf(" -- Core dumped.\n");
    396   1.1       cgd 	else
    397  1.19  christos 		(void)printf(" -- Can't dump core.\n");
    398   1.1       cgd 	return 0;
    399   1.1       cgd }
    400   1.1       cgd 
    401   1.1       cgd /*
    402   1.1       cgd  * Clobber as many bytes of stack as the user requests.
    403   1.1       cgd  */
    404   1.3   deraadt int
    405  1.12       wiz clobber(void *v)
    406   1.1       cgd {
    407   1.5  christos 	char **argv = v;
    408   1.8     lukem 	int times;
    409   1.1       cgd 
    410   1.1       cgd 	if (argv[0] == 0)
    411   1.1       cgd 		times = 1;
    412   1.1       cgd 	else
    413   1.1       cgd 		times = (atoi(argv[0]) + 511) / 512;
    414   1.1       cgd 	clob1(times);
    415   1.1       cgd 	return 0;
    416   1.1       cgd }
    417   1.1       cgd 
    418   1.1       cgd /*
    419   1.1       cgd  * Clobber the stack.
    420   1.1       cgd  */
    421   1.3   deraadt void
    422  1.12       wiz clob1(int n)
    423   1.1       cgd {
    424   1.1       cgd 	char buf[512];
    425   1.8     lukem 	char *cp;
    426   1.1       cgd 
    427   1.1       cgd 	if (n <= 0)
    428   1.1       cgd 		return;
    429  1.19  christos 	for (cp = buf; cp < &buf[512]; *cp++ = (char)0xFF)
    430   1.1       cgd 		;
    431   1.1       cgd 	clob1(n - 1);
    432   1.1       cgd }
    433   1.1       cgd 
    434   1.1       cgd /*
    435   1.1       cgd  * Add the given header fields to the retained list.
    436   1.1       cgd  * If no arguments, print the current list of retained fields.
    437   1.1       cgd  */
    438   1.3   deraadt int
    439  1.12       wiz retfield(void *v)
    440   1.1       cgd {
    441   1.5  christos 	char **list = v;
    442   1.1       cgd 
    443   1.1       cgd 	return ignore1(list, ignore + 1, "retained");
    444   1.1       cgd }
    445   1.1       cgd 
    446   1.1       cgd /*
    447   1.1       cgd  * Add the given header fields to the ignored list.
    448   1.1       cgd  * If no arguments, print the current list of ignored fields.
    449   1.1       cgd  */
    450   1.3   deraadt int
    451  1.12       wiz igfield(void *v)
    452   1.1       cgd {
    453   1.5  christos 	char **list = v;
    454   1.1       cgd 
    455   1.1       cgd 	return ignore1(list, ignore, "ignored");
    456   1.1       cgd }
    457   1.1       cgd 
    458   1.3   deraadt int
    459  1.12       wiz saveretfield(void *v)
    460   1.1       cgd {
    461   1.5  christos 	char **list = v;
    462   1.1       cgd 
    463   1.1       cgd 	return ignore1(list, saveignore + 1, "retained");
    464   1.1       cgd }
    465   1.1       cgd 
    466   1.3   deraadt int
    467  1.12       wiz saveigfield(void *v)
    468   1.1       cgd {
    469   1.5  christos 	char **list = v;
    470   1.1       cgd 
    471   1.1       cgd 	return ignore1(list, saveignore, "ignored");
    472   1.1       cgd }
    473   1.1       cgd 
    474   1.3   deraadt int
    475  1.18  christos ignore1(char *list[], struct ignoretab *tab, const char *which)
    476   1.1       cgd {
    477   1.6     mikel 	char field[LINESIZE];
    478   1.8     lukem 	int h;
    479   1.8     lukem 	struct ignore *igp;
    480   1.1       cgd 	char **ap;
    481   1.1       cgd 
    482  1.14       wiz 	if (*list == NULL)
    483   1.1       cgd 		return igshow(tab, which);
    484   1.1       cgd 	for (ap = list; *ap != 0; ap++) {
    485   1.1       cgd 		istrcpy(field, *ap);
    486   1.1       cgd 		if (member(field, tab))
    487   1.1       cgd 			continue;
    488   1.1       cgd 		h = hash(field);
    489   1.1       cgd 		igp = (struct ignore *) calloc(1, sizeof (struct ignore));
    490   1.1       cgd 		igp->i_field = calloc((unsigned) strlen(field) + 1,
    491   1.1       cgd 			sizeof (char));
    492  1.19  christos 		(void)strcpy(igp->i_field, field);
    493   1.1       cgd 		igp->i_link = tab->i_head[h];
    494   1.1       cgd 		tab->i_head[h] = igp;
    495   1.1       cgd 		tab->i_count++;
    496   1.1       cgd 	}
    497   1.1       cgd 	return 0;
    498   1.1       cgd }
    499   1.1       cgd 
    500   1.1       cgd /*
    501   1.1       cgd  * Print out all currently retained fields.
    502   1.1       cgd  */
    503   1.3   deraadt int
    504  1.18  christos igshow(struct ignoretab *tab, const char *which)
    505   1.1       cgd {
    506   1.8     lukem 	int h;
    507   1.1       cgd 	struct ignore *igp;
    508   1.1       cgd 	char **ap, **ring;
    509   1.1       cgd 
    510   1.1       cgd 	if (tab->i_count == 0) {
    511  1.19  christos 		(void)printf("No fields currently being %s.\n", which);
    512   1.1       cgd 		return 0;
    513   1.1       cgd 	}
    514  1.18  christos 	ring = salloc((tab->i_count + 1) * sizeof (char *));
    515   1.1       cgd 	ap = ring;
    516   1.1       cgd 	for (h = 0; h < HSHSIZE; h++)
    517   1.1       cgd 		for (igp = tab->i_head[h]; igp != 0; igp = igp->i_link)
    518   1.1       cgd 			*ap++ = igp->i_field;
    519   1.1       cgd 	*ap = 0;
    520   1.3   deraadt 	qsort(ring, tab->i_count, sizeof (char *), igcomp);
    521   1.1       cgd 	for (ap = ring; *ap != 0; ap++)
    522  1.19  christos 		(void)printf("%s\n", *ap);
    523   1.1       cgd 	return 0;
    524   1.1       cgd }
    525   1.1       cgd 
    526   1.1       cgd /*
    527   1.1       cgd  * Compare two names for sorting ignored field list.
    528   1.1       cgd  */
    529   1.5  christos static int
    530  1.12       wiz igcomp(const void *l, const void *r)
    531   1.1       cgd {
    532  1.18  christos 	return (strcmp(*(const char *const *)l, *(const char *const *)r));
    533   1.1       cgd }
    534