104 lines
2.7 KiB
Modula-2
104 lines
2.7 KiB
Modula-2
This file is enable.def, from which is created enable.c.
|
|
It implements the builtin "enable" in Bash.
|
|
|
|
Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
|
|
|
|
This file is part of GNU Bash, the Bourne Again SHell.
|
|
|
|
Bash is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free
|
|
Software Foundation; either version 1, or (at your option) any later
|
|
version.
|
|
|
|
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
with Bash; see the file COPYING. If not, write to the Free Software
|
|
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
$PRODUCES enable.c
|
|
|
|
$BUILTIN enable
|
|
$FUNCTION enable_builtin
|
|
$SHORT_DOC enable [-n] [name ...]
|
|
Enable and disable builtin shell commands. This allows
|
|
you to use a disk command which has the same name as a shell
|
|
builtin. If -n is used, the NAMEs become disabled. Otherwise
|
|
NAMEs are enabled. For example, to use the `test' found on your
|
|
path instead of the shell builtin version, you type `enable -n test'.
|
|
$END
|
|
|
|
#include "../shell.h"
|
|
#include "../builtins.h"
|
|
|
|
static int enable_shell_command ();
|
|
|
|
/* Enable/disable shell commands present in LIST. If list is not specified,
|
|
then print out a list of shell commands showing which are enabled and
|
|
which are disabled. */
|
|
enable_builtin (list)
|
|
WORD_LIST *list;
|
|
{
|
|
int result = 0, any_failed = 0;
|
|
|
|
if (!list)
|
|
{
|
|
register int i;
|
|
|
|
for (i = 0; i < num_shell_builtins; i++)
|
|
{
|
|
if (!shell_builtins[i].function)
|
|
continue;
|
|
|
|
printf ("enable %s%s\n", shell_builtins[i].enabled ? "" : "-n ",
|
|
shell_builtins[i].name);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int disable_p = (strcmp (list->word->word, "-n") == 0);
|
|
|
|
if (disable_p)
|
|
list = list->next;
|
|
|
|
while (list)
|
|
{
|
|
result = enable_shell_command (list->word->word, disable_p);
|
|
if (!result)
|
|
{
|
|
builtin_error ("%s: not a shell builtin", list->word->word);
|
|
any_failed++;
|
|
}
|
|
list = list->next;
|
|
}
|
|
}
|
|
return (any_failed ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
|
|
}
|
|
|
|
/* Enable the shell command NAME. If DISABLE_P is non-zero, then
|
|
disable NAME instead. */
|
|
static int
|
|
enable_shell_command (name, disable_p)
|
|
char *name;
|
|
int disable_p;
|
|
{
|
|
register int i;
|
|
int found = 0;
|
|
|
|
for (i = 0; i < num_shell_builtins; i++)
|
|
{
|
|
if (!shell_builtins[i].function)
|
|
continue;
|
|
|
|
if (strcmp (name, shell_builtins[i].name) == 0)
|
|
{
|
|
found++;
|
|
shell_builtins[i].enabled = !disable_p;
|
|
}
|
|
}
|
|
return (found);
|
|
}
|