Imported from ../bash-3.0.tar.gz.
This commit is contained in:
parent
7117c2d221
commit
b80f6443b6
400 changed files with 69247 additions and 13346 deletions
|
|
@ -1,7 +1,7 @@
|
|||
This file is alias.def, from which is created alias.c
|
||||
It implements the builtins "alias" and "unalias" in Bash.
|
||||
|
||||
Copyright (C) 1987-2002 Free Software Foundation, Inc.
|
||||
Copyright (C) 1987-2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
|
|
@ -44,6 +44,7 @@ $END
|
|||
#endif
|
||||
|
||||
# include "../bashansi.h"
|
||||
# include "../bashintl.h"
|
||||
|
||||
# include <stdio.h>
|
||||
# include "../shell.h"
|
||||
|
|
@ -51,17 +52,23 @@ $END
|
|||
# include "common.h"
|
||||
# include "bashgetopt.h"
|
||||
|
||||
static void print_alias __P((alias_t *));
|
||||
/* Flags for print_alias */
|
||||
#define AL_REUSABLE 0x01
|
||||
|
||||
static void print_alias __P((alias_t *, int));
|
||||
|
||||
extern int posixly_correct;
|
||||
|
||||
/* Hack the alias command in a Korn shell way. */
|
||||
int
|
||||
alias_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int any_failed, offset, pflag;
|
||||
int any_failed, offset, pflag, dflags;
|
||||
alias_t **alias_list, *t;
|
||||
char *name, *value;
|
||||
|
||||
dflags = posixly_correct ? 0 : AL_REUSABLE;
|
||||
pflag = 0;
|
||||
reset_internal_getopt ();
|
||||
while ((offset = internal_getopt (list, "p")) != -1)
|
||||
|
|
@ -70,6 +77,7 @@ alias_builtin (list)
|
|||
{
|
||||
case 'p':
|
||||
pflag = 1;
|
||||
dflags |= AL_REUSABLE;
|
||||
break;
|
||||
default:
|
||||
builtin_usage ();
|
||||
|
|
@ -90,7 +98,7 @@ alias_builtin (list)
|
|||
return (EXECUTION_SUCCESS);
|
||||
|
||||
for (offset = 0; alias_list[offset]; offset++)
|
||||
print_alias (alias_list[offset]);
|
||||
print_alias (alias_list[offset], dflags);
|
||||
|
||||
free (alias_list); /* XXX - Do not free the strings. */
|
||||
|
||||
|
|
@ -111,13 +119,19 @@ alias_builtin (list)
|
|||
name[offset] = '\0';
|
||||
value = name + offset + 1;
|
||||
|
||||
add_alias (name, value);
|
||||
if (legal_alias_name (name, 0) == 0)
|
||||
{
|
||||
builtin_error (_("`%s': invalid alias name"), name);
|
||||
any_failed++;
|
||||
}
|
||||
else
|
||||
add_alias (name, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
t = find_alias (name);
|
||||
if (t)
|
||||
print_alias (t);
|
||||
print_alias (t, dflags);
|
||||
else
|
||||
{
|
||||
sh_notfound (name);
|
||||
|
|
@ -134,7 +148,7 @@ alias_builtin (list)
|
|||
$BUILTIN unalias
|
||||
$FUNCTION unalias_builtin
|
||||
$DEPENDS_ON ALIAS
|
||||
$SHORT_DOC unalias [-a] [name ...]
|
||||
$SHORT_DOC unalias [-a] name [name ...]
|
||||
Remove NAMEs from the list of defined aliases. If the -a option is given,
|
||||
then remove all alias definitions.
|
||||
$END
|
||||
|
|
@ -171,6 +185,12 @@ unalias_builtin (list)
|
|||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
aflag = 0;
|
||||
while (list)
|
||||
{
|
||||
|
|
@ -192,13 +212,16 @@ unalias_builtin (list)
|
|||
|
||||
/* Output ALIAS in such a way as to allow it to be read back in. */
|
||||
static void
|
||||
print_alias (alias)
|
||||
print_alias (alias, flags)
|
||||
alias_t *alias;
|
||||
int flags;
|
||||
{
|
||||
char *value;
|
||||
|
||||
value = sh_single_quote (alias->value);
|
||||
printf ("alias %s=%s\n", alias->name, value);
|
||||
if (flags & AL_REUSABLE)
|
||||
printf ("alias ");
|
||||
printf ("%s=%s\n", alias->name, value);
|
||||
free (value);
|
||||
|
||||
fflush (stdout);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue