PR/32964: Johan Veenhuizen: implement the unalias command

This commit is contained in:
christos 2006-03-03 13:36:27 +00:00
parent 4c71230ec5
commit 463f84da0a
3 changed files with 54 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmd3.c,v 1.27 2005/07/19 23:07:10 christos Exp $ */
/* $NetBSD: cmd3.c,v 1.28 2006/03/03 13:36:27 christos Exp $ */
/*
* Copyright (c) 1980, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)cmd3.c 8.2 (Berkeley) 4/20/95";
#else
__RCSID("$NetBSD: cmd3.c,v 1.27 2005/07/19 23:07:10 christos Exp $");
__RCSID("$NetBSD: cmd3.c,v 1.28 2006/03/03 13:36:27 christos Exp $");
#endif
#endif /* not lint */
@ -46,6 +46,7 @@ __RCSID("$NetBSD: cmd3.c,v 1.27 2005/07/19 23:07:10 christos Exp $");
*
* Still more user commands.
*/
static int delgroup(const char *);
static int diction(const void *, const void *);
/*
@ -503,6 +504,51 @@ group(void *v)
return(0);
}
/*
* The unalias command takes a list of alises
* and discards the remembered groups of users.
*/
int
unalias(void *v)
{
char **ap;
for (ap = v; *ap != NULL; ap++)
(void)delgroup(*ap);
return 0;
}
/*
* Delete the named group alias. Return zero if the group was
* successfully deleted, or -1 if there was no such group.
*/
static int
delgroup(const char *name)
{
struct grouphead *gh, *p;
struct group *g;
int h;
h = hash(name);
for (gh = groups[h], p = NULL; gh != NULL; p = gh, gh = gh->g_link)
if (strcmp(gh->g_name, name) == 0) {
if (p == NULL)
groups[h] = gh->g_link;
else
p->g_link = gh->g_link;
while (gh->g_list != NULL) {
g = gh->g_list;
gh->g_list = g->ge_link;
free(g->ge_name);
free(g);
}
free(gh->g_name);
free(gh);
return 0;
}
return -1;
}
/*
* Sort the passed string vecotor into ascending dictionary
* order.

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmdtab.c,v 1.10 2003/08/07 11:14:36 agc Exp $ */
/* $NetBSD: cmdtab.c,v 1.11 2006/03/03 13:36:27 christos Exp $ */
/*
* Copyright (c) 1980, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)cmdtab.c 8.2 (Berkeley) 4/20/95";
#else
__RCSID("$NetBSD: cmdtab.c,v 1.10 2003/08/07 11:14:36 agc Exp $");
__RCSID("$NetBSD: cmdtab.c,v 1.11 2006/03/03 13:36:27 christos Exp $");
#endif
#endif /* not lint */
@ -69,6 +69,7 @@ const struct cmd cmdtab[] = {
{ "page", more, MSGLIST, 0, MMNDEL },
{ "More", More, MSGLIST, 0, MMNDEL },
{ "Page", More, MSGLIST, 0, MMNDEL },
{ "unalias", unalias, M|RAWLIST, 1, 1000 },
{ "unread", unread, MSGLIST, 0, MMNDEL },
{ "!", shell, I|STRLIST, 0, 0 },
{ "copy", copycmd, M|STRLIST, 0, 0 },

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.22 2006/01/05 02:13:41 christos Exp $ */
/* $NetBSD: extern.h,v 1.23 2006/03/03 13:36:27 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -29,7 +29,7 @@
* SUCH DAMAGE.
*
* @(#)extern.h 8.2 (Berkeley) 4/20/95
* $NetBSD: extern.h,v 1.22 2006/01/05 02:13:41 christos Exp $
* $NetBSD: extern.h,v 1.23 2006/03/03 13:36:27 christos Exp $
*/
struct name;
@ -148,6 +148,7 @@ int help(void *);
void holdsigs(void);
int ifcmd(void *);
int igfield(void *);
int unalias(void *);
struct ignoretab;
int ignore1(char *[], struct ignoretab *, const char *);
int igshow(struct ignoretab *, const char *);