2019-02-09 12:11:07 +03:00
|
|
|
/* $NetBSD: alias.c,v 1.21 2019/02/09 09:11:07 kre Exp $ */
|
1995-03-21 12:01:59 +03:00
|
|
|
|
1994-05-11 21:01:00 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Kenneth Almquist.
|
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 13:05:01 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-11 21:01:00 +04: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.
|
|
|
|
*/
|
|
|
|
|
1997-07-05 01:01:48 +04:00
|
|
|
#include <sys/cdefs.h>
|
1994-05-11 21:01:00 +04:00
|
|
|
#ifndef lint
|
1995-03-21 12:01:59 +03:00
|
|
|
#if 0
|
1995-05-12 01:28:33 +04:00
|
|
|
static char sccsid[] = "@(#)alias.c 8.3 (Berkeley) 5/4/95";
|
1995-03-21 12:01:59 +03:00
|
|
|
#else
|
2019-02-09 12:11:07 +03:00
|
|
|
__RCSID("$NetBSD: alias.c,v 1.21 2019/02/09 09:11:07 kre Exp $");
|
1995-03-21 12:01:59 +03:00
|
|
|
#endif
|
1994-05-11 21:01:00 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1995-05-12 01:28:33 +04:00
|
|
|
#include <stdlib.h>
|
1994-05-11 21:01:00 +04:00
|
|
|
#include "shell.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "output.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "memalloc.h"
|
|
|
|
#include "mystring.h"
|
|
|
|
#include "alias.h"
|
|
|
|
#include "options.h" /* XXX for argptr (should remove?) */
|
2011-06-19 01:18:46 +04:00
|
|
|
#include "builtins.h"
|
2002-11-25 01:35:38 +03:00
|
|
|
#include "var.h"
|
1994-05-11 21:01:00 +04:00
|
|
|
|
|
|
|
#define ATABSIZE 39
|
|
|
|
|
|
|
|
struct alias *atab[ATABSIZE];
|
|
|
|
|
2002-11-25 01:35:38 +03:00
|
|
|
STATIC void setalias(char *, char *);
|
2018-10-08 02:17:52 +03:00
|
|
|
STATIC int by_name(const void *, const void *);
|
|
|
|
STATIC void list_aliases(void);
|
2002-11-25 01:35:38 +03:00
|
|
|
STATIC int unalias(char *);
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
STATIC struct alias **freealias(struct alias **, int);
|
2014-06-18 22:17:30 +04:00
|
|
|
STATIC struct alias **hashalias(const char *);
|
2019-02-09 12:11:07 +03:00
|
|
|
STATIC int countaliases(void);
|
1994-05-11 21:01:00 +04:00
|
|
|
|
|
|
|
STATIC
|
1994-12-04 10:11:37 +03:00
|
|
|
void
|
2002-11-25 01:35:38 +03:00
|
|
|
setalias(char *name, char *val)
|
1994-12-04 10:11:37 +03:00
|
|
|
{
|
1994-05-11 21:01:00 +04:00
|
|
|
struct alias *ap, **app;
|
|
|
|
|
2018-12-02 13:27:58 +03:00
|
|
|
(void) unalias(name); /* old one (if any) is now gone */
|
1994-05-11 21:01:00 +04:00
|
|
|
app = hashalias(name);
|
2018-12-02 13:27:58 +03:00
|
|
|
|
1994-05-11 21:01:00 +04:00
|
|
|
INTOFF;
|
|
|
|
ap = ckmalloc(sizeof (struct alias));
|
|
|
|
ap->name = savestr(name);
|
2010-10-29 21:04:48 +04:00
|
|
|
ap->flag = 0;
|
1994-05-11 21:01:00 +04:00
|
|
|
ap->val = savestr(val);
|
|
|
|
ap->next = *app;
|
|
|
|
*app = ap;
|
|
|
|
INTON;
|
|
|
|
}
|
|
|
|
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
STATIC struct alias **
|
|
|
|
freealias(struct alias **app, int force)
|
|
|
|
{
|
|
|
|
struct alias *ap = *app;
|
|
|
|
|
|
|
|
if (ap == NULL)
|
|
|
|
return app;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if the alias is currently in use (i.e. its
|
|
|
|
* buffer is being used by the input routine) we
|
|
|
|
* just null out the name instead of discarding it.
|
|
|
|
* If we encounter it later, when it is idle,
|
|
|
|
* we will finish freeing it then.
|
|
|
|
*
|
|
|
|
* Unless we want to simply free everything (INIT)
|
|
|
|
*/
|
|
|
|
if (ap->flag & ALIASINUSE && !force) {
|
|
|
|
*ap->name = '\0';
|
|
|
|
return &ap->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
INTOFF;
|
|
|
|
*app = ap->next;
|
|
|
|
ckfree(ap->name);
|
|
|
|
ckfree(ap->val);
|
|
|
|
ckfree(ap);
|
|
|
|
INTON;
|
|
|
|
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
1994-05-11 21:01:00 +04:00
|
|
|
STATIC int
|
2002-11-25 01:35:38 +03:00
|
|
|
unalias(char *name)
|
|
|
|
{
|
1994-05-11 21:01:00 +04:00
|
|
|
struct alias *ap, **app;
|
|
|
|
|
|
|
|
app = hashalias(name);
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
while ((ap = *app) != NULL) {
|
1994-05-11 21:01:00 +04:00
|
|
|
if (equal(name, ap->name)) {
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
(void) freealias(app, 0);
|
2018-12-01 04:20:05 +03:00
|
|
|
return 0;
|
1994-05-11 21:01:00 +04:00
|
|
|
}
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
app = &ap->next;
|
1994-05-11 21:01:00 +04:00
|
|
|
}
|
|
|
|
|
2018-12-01 04:20:05 +03:00
|
|
|
return 1;
|
1994-05-11 21:01:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef mkinit
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
MKINIT void rmaliases(int);
|
1994-05-11 21:01:00 +04:00
|
|
|
|
|
|
|
SHELLPROC {
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
rmaliases(1);
|
1994-05-11 21:01:00 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
rmaliases(int force)
|
2002-11-25 01:35:38 +03:00
|
|
|
{
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
struct alias **app;
|
1994-05-11 21:01:00 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
INTOFF;
|
|
|
|
for (i = 0; i < ATABSIZE; i++) {
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
app = &atab[i];
|
|
|
|
while (*app)
|
|
|
|
app = freealias(app, force);
|
1994-05-11 21:01:00 +04:00
|
|
|
}
|
|
|
|
INTON;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct alias *
|
2014-06-18 22:17:30 +04:00
|
|
|
lookupalias(const char *name, int check)
|
1994-12-04 10:11:37 +03:00
|
|
|
{
|
1994-05-11 21:01:00 +04:00
|
|
|
struct alias *ap = *hashalias(name);
|
|
|
|
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
while (ap != NULL) {
|
1994-05-11 21:01:00 +04:00
|
|
|
if (equal(name, ap->name)) {
|
|
|
|
if (check && (ap->flag & ALIASINUSE))
|
2018-12-01 04:20:05 +03:00
|
|
|
return NULL;
|
|
|
|
return ap;
|
1994-05-11 21:01:00 +04:00
|
|
|
}
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
ap = ap->next;
|
1994-05-11 21:01:00 +04:00
|
|
|
}
|
|
|
|
|
2018-12-01 04:20:05 +03:00
|
|
|
return NULL;
|
1994-05-11 21:01:00 +04:00
|
|
|
}
|
|
|
|
|
2014-06-18 22:17:30 +04:00
|
|
|
const char *
|
|
|
|
alias_text(void *dummy __unused, const char *name)
|
2002-11-25 01:35:38 +03:00
|
|
|
{
|
|
|
|
struct alias *ap;
|
|
|
|
|
|
|
|
ap = lookupalias(name, 0);
|
|
|
|
if (ap == NULL)
|
|
|
|
return NULL;
|
|
|
|
return ap->val;
|
|
|
|
}
|
|
|
|
|
2018-10-08 02:17:52 +03:00
|
|
|
STATIC int
|
|
|
|
by_name(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
|
|
|
|
return strcmp(
|
|
|
|
(*(const struct alias * const *)a)->name,
|
|
|
|
(*(const struct alias * const *)b)->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
STATIC void
|
|
|
|
list_aliases(void)
|
|
|
|
{
|
2019-02-09 12:11:07 +03:00
|
|
|
int i, j, n;
|
2018-10-08 02:17:52 +03:00
|
|
|
const struct alias **aliases;
|
|
|
|
const struct alias *ap;
|
|
|
|
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
INTOFF;
|
|
|
|
n = countaliases();
|
2019-02-09 12:11:07 +03:00
|
|
|
aliases = stalloc(n * (int)(sizeof aliases[0]));
|
2018-10-08 02:17:52 +03:00
|
|
|
|
|
|
|
j = 0;
|
|
|
|
for (i = 0; i < ATABSIZE; i++)
|
|
|
|
for (ap = atab[i]; ap != NULL; ap = ap->next)
|
|
|
|
if (ap->name[0] != '\0')
|
|
|
|
aliases[j++] = ap;
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
if (j != n)
|
|
|
|
error("Alias count botch");
|
|
|
|
INTON;
|
2018-10-08 02:17:52 +03:00
|
|
|
|
|
|
|
qsort(aliases, n, sizeof aliases[0], by_name);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
out1fmt("alias %s=", aliases[i]->name);
|
|
|
|
print_quoted(aliases[i]->val);
|
|
|
|
out1c('\n');
|
|
|
|
}
|
|
|
|
|
2019-02-09 12:11:07 +03:00
|
|
|
stunalloc(aliases);
|
2018-10-08 02:17:52 +03:00
|
|
|
}
|
|
|
|
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
/*
|
|
|
|
* Count how many aliases are defined (skipping any
|
|
|
|
* that have been deleted, but don't know it yet).
|
|
|
|
* Use this opportunity to clean up any of those
|
|
|
|
* zombies that are no longer needed.
|
|
|
|
*/
|
2019-02-09 12:11:07 +03:00
|
|
|
STATIC int
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
countaliases(void)
|
|
|
|
{
|
|
|
|
struct alias *ap, **app;
|
|
|
|
size_t n;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
for (i = 0; i < ATABSIZE; i++)
|
|
|
|
for (app = &atab[i]; (ap = *app) != NULL;) {
|
|
|
|
if (ap->name[0] != '\0')
|
|
|
|
n++;
|
|
|
|
else {
|
|
|
|
app = freealias(app, 0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
app = &ap->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
1994-12-04 10:11:37 +03:00
|
|
|
int
|
2002-11-25 01:35:38 +03:00
|
|
|
aliascmd(int argc, char **argv)
|
1994-12-04 10:11:37 +03:00
|
|
|
{
|
1994-05-11 21:01:00 +04:00
|
|
|
char *n, *v;
|
|
|
|
int ret = 0;
|
|
|
|
struct alias *ap;
|
|
|
|
|
|
|
|
if (argc == 1) {
|
2018-10-08 02:17:52 +03:00
|
|
|
list_aliases();
|
2018-12-01 04:20:05 +03:00
|
|
|
return 0;
|
1994-05-11 21:01:00 +04:00
|
|
|
}
|
2018-10-08 02:17:52 +03:00
|
|
|
|
1995-05-12 01:28:33 +04:00
|
|
|
while ((n = *++argv) != NULL) {
|
1998-05-20 04:27:56 +04:00
|
|
|
if ((v = strchr(n+1, '=')) == NULL) { /* n+1: funny ksh stuff */
|
1994-05-11 21:01:00 +04:00
|
|
|
if ((ap = lookupalias(n, 0)) == NULL) {
|
|
|
|
outfmt(out2, "alias: %s not found\n", n);
|
|
|
|
ret = 1;
|
2002-11-25 01:35:38 +03:00
|
|
|
} else {
|
|
|
|
out1fmt("alias %s=", n);
|
|
|
|
print_quoted(ap->val);
|
|
|
|
out1c('\n');
|
|
|
|
}
|
|
|
|
} else {
|
1994-05-11 21:01:00 +04:00
|
|
|
*v++ = '\0';
|
|
|
|
setalias(n, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-01 04:20:05 +03:00
|
|
|
return ret;
|
1994-05-11 21:01:00 +04:00
|
|
|
}
|
|
|
|
|
1994-12-04 10:11:37 +03:00
|
|
|
int
|
2002-11-25 01:35:38 +03:00
|
|
|
unaliascmd(int argc, char **argv)
|
1994-12-04 10:11:37 +03:00
|
|
|
{
|
1994-05-11 21:01:00 +04:00
|
|
|
int i;
|
1996-10-16 19:45:03 +04:00
|
|
|
|
1994-05-11 21:01:00 +04:00
|
|
|
while ((i = nextopt("a")) != '\0') {
|
|
|
|
if (i == 'a') {
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
rmaliases(0);
|
2018-12-01 04:20:05 +03:00
|
|
|
return 0;
|
1994-05-11 21:01:00 +04:00
|
|
|
}
|
|
|
|
}
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
|
|
|
|
(void)countaliases(); /* delete any dead ones */
|
1994-05-11 21:01:00 +04:00
|
|
|
for (i = 0; *argptr; argptr++)
|
Revamp aliases - as dumb an idea as they are, if we're going
to have them, they should work as documented, not cause core
dumps, reference after free, incorrect replacements, failing
to implement alias after alias, ...
The big comment that ended:
This is a good idea ------- ***NOT***
and the hack it was describing are gone.
Note that most of this was from original CVS version 1.1
code (ie: came from the original import, even before 4.4-Lite
was merged. That is, May 1994. And no-one in 24.5 years
noticed (or at least complained about) all the bugs (or at
least, most of them)).
With these changes, aliases ought to work (if you can call it
that) as they are expected to by POSIX. Now if only we could
get POSIX to delete them (or make them optional)...
Changes partly inspired by similar changes made by FreeBSD,
(as was the previous change to alias.c, forgot ack in commit
log for that one, apologies) but done a little differently,
and perhaps with a slightly better outcome.
2018-12-03 09:40:26 +03:00
|
|
|
i |= unalias(*argptr);
|
1994-05-11 21:01:00 +04:00
|
|
|
|
2018-12-01 04:20:05 +03:00
|
|
|
return i;
|
1994-05-11 21:01:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STATIC struct alias **
|
2014-06-18 22:17:30 +04:00
|
|
|
hashalias(const char *p)
|
2002-11-25 01:35:38 +03:00
|
|
|
{
|
1994-05-11 21:01:00 +04:00
|
|
|
unsigned int hashval;
|
|
|
|
|
2017-07-24 15:34:45 +03:00
|
|
|
hashval = *(const unsigned char *)p << 4;
|
1994-05-11 21:01:00 +04:00
|
|
|
while (*p)
|
2017-07-24 15:34:45 +03:00
|
|
|
hashval += *p++;
|
1994-05-11 21:01:00 +04:00
|
|
|
return &atab[hashval % ATABSIZE];
|
|
|
|
}
|