mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-06-29 00:19:51 +02:00
commit bash-20040802 snapshot
This commit is contained in:
@@ -9763,3 +9763,33 @@ arrayfunc.c
|
||||
{locale,variables}.c
|
||||
- support LC_TIME as a special locale variable so HISTTIMEFORMAT tracks
|
||||
the current locale
|
||||
|
||||
8/2
|
||||
---
|
||||
variables.c
|
||||
- fixed small memory leak in makunbound() when a local array variable
|
||||
is unset. Fix from William Park
|
||||
|
||||
lib/readline/display.c
|
||||
- fixed a problem when computing the number of invisible characters on
|
||||
the first line of a prompt whose length exceeds the screen width
|
||||
(should only happen when invisible characters occur after the
|
||||
line wrap). Bug reported by agriffis@gentoo.org
|
||||
|
||||
builtins/command.def
|
||||
- `command -V' passes a new flag, CDESC_ABSPATH, which means to convert
|
||||
to an absolute path
|
||||
|
||||
builtins/type.def
|
||||
- in posix mode, `type' and `command -v/-V' should not report
|
||||
non-executable files, even if the execution code will attempt to
|
||||
run them. Other posix shells do this
|
||||
|
||||
doc/bashref.texi
|
||||
- add note to POSIX Mode section describing behavior of type and command
|
||||
when finding a non-executable file
|
||||
|
||||
execute_cmd.c
|
||||
- force extended_glob to 1 before calling binary_test in
|
||||
execute_cond_node so that the right extended pattern matching gets
|
||||
performed
|
||||
|
||||
@@ -9763,3 +9763,28 @@ arrayfunc.c
|
||||
{locale,variables}.c
|
||||
- support LC_TIME as a special locale variable so HISTTIMEFORMAT tracks
|
||||
the current locale
|
||||
|
||||
8/2
|
||||
---
|
||||
variables.c
|
||||
- fixed small memory leak in makunbound() when a local array variable
|
||||
is unset. Fix from William Park
|
||||
|
||||
lib/readline/display.c
|
||||
- fixed a problem when computing the number of invisible characters on
|
||||
the first line of a prompt whose length exceeds the screen width
|
||||
(should only happen when invisible characters occur after the
|
||||
line wrap). Bug reported by agriffis@gentoo.org
|
||||
|
||||
builtins/command.def
|
||||
- `command -V' passes a new flag, CDESC_ABSPATH, which means to convert
|
||||
to an absolute path
|
||||
|
||||
builtins/type.def
|
||||
- in posix mode, `type' and `command -v/-V' should not report
|
||||
non-executable files, even if the execution code will attempt to
|
||||
run them. Other posix shells do this
|
||||
|
||||
doc/bashref.texi
|
||||
- add note to POSIX Mode section describing behavior of type and command
|
||||
when finding a non-executable file
|
||||
|
||||
@@ -78,7 +78,7 @@ command_builtin (list)
|
||||
use_standard_path = 1;
|
||||
break;
|
||||
case 'V':
|
||||
verbose = CDESC_SHORTDESC; /* look in common.h for constants */
|
||||
verbose = CDESC_SHORTDESC|CDESC_ABSPATH; /* look in common.h for constants */
|
||||
break;
|
||||
case 'v':
|
||||
verbose = CDESC_REUSABLE; /* ditto */
|
||||
|
||||
@@ -53,7 +53,7 @@ $END
|
||||
extern size_t confstr __P((int, char *, size_t));
|
||||
#endif
|
||||
|
||||
extern int subshell_environment, posixly_correct;
|
||||
extern int subshell_environment;
|
||||
|
||||
static void restore_path __P((char *));
|
||||
static char *get_standard_path __P((void));
|
||||
@@ -101,7 +101,7 @@ command_builtin (list)
|
||||
{
|
||||
found = describe_command (list->word->word, verbose);
|
||||
|
||||
if (found == 0 && (posixly_correct == 0 || verbose != CDESC_REUSABLE))
|
||||
if (found == 0 && verbose != CDESC_REUSABLE)
|
||||
sh_notfound (list->word->word);
|
||||
|
||||
any_found += found;
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#define CDESC_PATH_ONLY 0x010 /* type -p */
|
||||
#define CDESC_FORCE_PATH 0x020 /* type -ap or type -P */
|
||||
#define CDESC_NOFUNCS 0x040 /* type -f */
|
||||
#define CDESC_ABSPATH 0x080 /* convert to absolute path, no ./ */
|
||||
|
||||
/* Flags for get_job_by_name */
|
||||
#define JM_PREFIX 0x01 /* prefix of job name */
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
/* common.h -- extern declarations for functions defined in common.c. */
|
||||
|
||||
/* Copyright (C) 1993-2004 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 2, 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, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
||||
|
||||
#if !defined (__COMMON_H)
|
||||
# define __COMMON_H
|
||||
|
||||
#include "stdc.h"
|
||||
|
||||
#define ISOPTION(s, c) (s[0] == '-' && !s[2] && s[1] == c)
|
||||
|
||||
/* Flag values for parse_and_execute () */
|
||||
#define SEVAL_NONINT 0x001
|
||||
#define SEVAL_INTERACT 0x002
|
||||
#define SEVAL_NOHIST 0x004
|
||||
#define SEVAL_NOFREE 0x008
|
||||
#define SEVAL_RESETLINE 0x010
|
||||
|
||||
/* Flags for describe_command, shared between type.def and command.def */
|
||||
#define CDESC_ALL 0x001 /* type -a */
|
||||
#define CDESC_SHORTDESC 0x002 /* command -V */
|
||||
#define CDESC_REUSABLE 0x004 /* command -v */
|
||||
#define CDESC_TYPE 0x008 /* type -t */
|
||||
#define CDESC_PATH_ONLY 0x010 /* type -p */
|
||||
#define CDESC_FORCE_PATH 0x020 /* type -ap or type -P */
|
||||
#define CDESC_NOFUNCS 0x040 /* type -f */
|
||||
|
||||
/* Flags for get_job_by_name */
|
||||
#define JM_PREFIX 0x01 /* prefix of job name */
|
||||
#define JM_SUBSTRING 0x02 /* substring of job name */
|
||||
#define JM_EXACT 0x04 /* match job name exactly */
|
||||
#define JM_STOPPED 0x08 /* match stopped jobs only */
|
||||
#define JM_FIRSTMATCH 0x10 /* return first matching job */
|
||||
|
||||
/* Flags for remember_args and value of changed_dollar_vars */
|
||||
#define ARGS_NONE 0x0
|
||||
#define ARGS_INVOC 0x01
|
||||
#define ARGS_FUNC 0x02
|
||||
#define ARGS_SETBLTIN 0x04
|
||||
|
||||
/* Functions from common.c */
|
||||
extern void builtin_error __P((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
|
||||
extern void builtin_usage __P((void));
|
||||
extern void no_args __P((WORD_LIST *));
|
||||
extern int no_options __P((WORD_LIST *));
|
||||
|
||||
/* common error message functions */
|
||||
extern void sh_needarg __P((char *));
|
||||
extern void sh_neednumarg __P((char *));
|
||||
extern void sh_notfound __P((char *));
|
||||
extern void sh_invalidopt __P((char *));
|
||||
extern void sh_invalidoptname __P((char *));
|
||||
extern void sh_invalidid __P((char *));
|
||||
extern void sh_invalidnum __P((char *));
|
||||
extern void sh_invalidsig __P((char *));
|
||||
extern void sh_erange __P((char *, char *));
|
||||
extern void sh_badpid __P((char *));
|
||||
extern void sh_badjob __P((char *));
|
||||
extern void sh_readonly __P((const char *));
|
||||
extern void sh_nojobs __P((char *));
|
||||
extern void sh_restricted __P((char *));
|
||||
extern void sh_notbuiltin __P((char *));
|
||||
|
||||
extern char **make_builtin_argv __P((WORD_LIST *, int *));
|
||||
extern void remember_args __P((WORD_LIST *, int));
|
||||
|
||||
extern int dollar_vars_changed __P((void));
|
||||
extern void set_dollar_vars_unchanged __P((void));
|
||||
extern void set_dollar_vars_changed __P((void));
|
||||
|
||||
extern intmax_t get_numeric_arg __P((WORD_LIST *, int));
|
||||
extern int get_exitstat __P((WORD_LIST *));
|
||||
extern int read_octal __P((char *));
|
||||
|
||||
/* Keeps track of the current working directory. */
|
||||
extern char *the_current_working_directory;
|
||||
extern char *get_working_directory __P((char *));
|
||||
extern void set_working_directory __P((char *));
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
extern int get_job_by_name __P((const char *, int));
|
||||
extern int get_job_spec __P((WORD_LIST *));
|
||||
#endif
|
||||
extern int display_signal_list __P((WORD_LIST *, int));
|
||||
|
||||
/* It's OK to declare a function as returning a Function * without
|
||||
providing a definition of what a `Function' is. */
|
||||
extern struct builtin *builtin_address_internal __P((char *, int));
|
||||
extern sh_builtin_func_t *find_shell_builtin __P((char *));
|
||||
extern sh_builtin_func_t *builtin_address __P((char *));
|
||||
extern sh_builtin_func_t *find_special_builtin __P((char *));
|
||||
extern void initialize_shell_builtins __P((void));
|
||||
|
||||
/* Functions from exit.def */
|
||||
extern void bash_logout __P((void));
|
||||
|
||||
/* Functions from getopts.def */
|
||||
extern void getopts_reset __P((int));
|
||||
|
||||
/* Functions from set.def */
|
||||
extern int minus_o_option_value __P((char *));
|
||||
extern void list_minus_o_opts __P((int, int));
|
||||
extern char **get_minus_o_opts __P((void));
|
||||
extern int set_minus_o_option __P((int, char *));
|
||||
|
||||
extern void set_shellopts __P((void));
|
||||
extern void parse_shellopts __P((char *));
|
||||
extern void initialize_shell_options __P((int));
|
||||
|
||||
extern void reset_shell_options __P((void));
|
||||
|
||||
/* Functions from shopt.def */
|
||||
extern void reset_shopt_options __P((void));
|
||||
extern char **get_shopt_options __P((void));
|
||||
|
||||
extern int shopt_setopt __P((char *, int));
|
||||
extern int shopt_listopt __P((char *, int));
|
||||
|
||||
extern int set_login_shell __P((int));
|
||||
|
||||
/* Functions from type.def */
|
||||
extern int describe_command __P((char *, int));
|
||||
|
||||
/* Functions from setattr.def */
|
||||
extern int set_or_show_attributes __P((WORD_LIST *, int, int));
|
||||
extern int show_var_attributes __P((SHELL_VAR *, int, int));
|
||||
extern int show_name_attributes __P((char *, int));
|
||||
extern void set_var_attribute __P((char *, int, int));
|
||||
|
||||
/* Functions from pushd.def */
|
||||
extern char *get_dirstack_from_string __P((char *));
|
||||
extern char *get_dirstack_element __P((intmax_t, int));
|
||||
extern void set_dirstack_element __P((intmax_t, int, char *));
|
||||
extern WORD_LIST *get_directory_stack __P((void));
|
||||
|
||||
/* Functions from evalstring.c */
|
||||
extern int parse_and_execute __P((char *, const char *, int));
|
||||
extern void parse_and_execute_cleanup __P((void));
|
||||
|
||||
/* Functions from evalfile.c */
|
||||
extern int maybe_execute_file __P((const char *, int));
|
||||
extern int source_file __P((const char *, int));
|
||||
extern int fc_execute_file __P((const char *));
|
||||
|
||||
#endif /* !__COMMON_H */
|
||||
+12
-4
@@ -74,7 +74,7 @@ $END
|
||||
extern int find_reserved_word __P((char *));
|
||||
|
||||
extern char *this_command_name;
|
||||
extern int expand_aliases;
|
||||
extern int expand_aliases, posixly_correct;
|
||||
|
||||
/* For each word in LIST, find out what the shell is going to do with
|
||||
it as a simple command. i.e., which file would this shell use to
|
||||
@@ -201,6 +201,7 @@ type_builtin (list)
|
||||
* CDESC_PATH_ONLY print the path for type -p
|
||||
* CDESC_FORCE_PATH force a path search for type -P
|
||||
* CDESC_NOFUNCS skip function lookup for type -f
|
||||
* CDESC_ABSPATH convert to absolute path, no ./ prefix
|
||||
*
|
||||
* CDESC_ALL says whether or not to look for all occurrences of COMMAND, or
|
||||
* return after finding it once.
|
||||
@@ -359,8 +360,9 @@ describe_command (command, dflags)
|
||||
|
||||
/* If we found the command as itself by looking through $PATH, it
|
||||
probably doesn't exist. Check whether or not the command is an
|
||||
executable file. If it's not, don't report a match. */
|
||||
if (STREQ (full_path, command))
|
||||
executable file. If it's not, don't report a match. This is
|
||||
the default posix mode behavior */
|
||||
if (STREQ (full_path, command) || posixly_correct)
|
||||
{
|
||||
f = file_status (full_path);
|
||||
if ((f & FS_EXECABLE) == 0)
|
||||
@@ -371,8 +373,14 @@ describe_command (command, dflags)
|
||||
break;
|
||||
}
|
||||
else if (dflags & (CDESC_REUSABLE|CDESC_PATH_ONLY|CDESC_SHORTDESC))
|
||||
full_path = sh_makepath ((char *)NULL, full_path, MP_DOCWD);
|
||||
{
|
||||
f = MP_DOCWD | ((dflags & CDESC_ABSPATH) ? MP_RMDOT : 0);
|
||||
full_path = sh_makepath ((char *)NULL, full_path, f);
|
||||
}
|
||||
}
|
||||
/* If we require a full path and don't have one, make one */
|
||||
else if ((dflags & CDESC_ABSPATH) && ABSPATH (full_path) == 0)
|
||||
full_path = sh_makepath ((char *)NULL, full_path, MP_DOCWD|MP_RMDOT);
|
||||
|
||||
found_file++;
|
||||
found = 1;
|
||||
|
||||
@@ -0,0 +1,403 @@
|
||||
This file is type.def, from which is created type.c.
|
||||
It implements the builtin "type" in Bash.
|
||||
|
||||
Copyright (C) 1987-2002 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 2, 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, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
|
||||
$PRODUCES type.c
|
||||
|
||||
$BUILTIN type
|
||||
$FUNCTION type_builtin
|
||||
$SHORT_DOC type [-afptP] name [name ...]
|
||||
For each NAME, indicate how it would be interpreted if used as a
|
||||
command name.
|
||||
|
||||
If the -t option is used, `type' outputs a single word which is one of
|
||||
`alias', `keyword', `function', `builtin', `file' or `', if NAME is an
|
||||
alias, shell reserved word, shell function, shell builtin, disk file,
|
||||
or unfound, respectively.
|
||||
|
||||
If the -p flag is used, `type' either returns the name of the disk
|
||||
file that would be executed, or nothing if `type -t NAME' would not
|
||||
return `file'.
|
||||
|
||||
If the -a flag is used, `type' displays all of the places that contain
|
||||
an executable named `file'. This includes aliases, builtins, and
|
||||
functions, if and only if the -p flag is not also used.
|
||||
|
||||
The -f flag suppresses shell function lookup.
|
||||
|
||||
The -P flag forces a PATH search for each NAME, even if it is an alias,
|
||||
builtin, or function, and returns the name of the disk file that would
|
||||
be executed.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "../bashtypes.h"
|
||||
#include "posixstat.h"
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../bashansi.h"
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../findcmd.h"
|
||||
#include "../hashcmd.h"
|
||||
|
||||
#if defined (ALIAS)
|
||||
#include "../alias.h"
|
||||
#endif /* ALIAS */
|
||||
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
extern int find_reserved_word __P((char *));
|
||||
|
||||
extern char *this_command_name;
|
||||
extern int expand_aliases, posixly_correct;
|
||||
|
||||
/* For each word in LIST, find out what the shell is going to do with
|
||||
it as a simple command. i.e., which file would this shell use to
|
||||
execve, or if it is a builtin command, or an alias. Possible flag
|
||||
arguments:
|
||||
-t Returns the "type" of the object, one of
|
||||
`alias', `keyword', `function', `builtin',
|
||||
or `file'.
|
||||
|
||||
-p Returns the pathname of the file if -type is
|
||||
a file.
|
||||
|
||||
-a Returns all occurrences of words, whether they
|
||||
be a filename in the path, alias, function,
|
||||
or builtin.
|
||||
|
||||
-f Suppress shell function lookup, like `command'.
|
||||
|
||||
-P Force a path search even in the presence of other
|
||||
definitions.
|
||||
|
||||
Order of evaluation:
|
||||
alias
|
||||
keyword
|
||||
function
|
||||
builtin
|
||||
file
|
||||
*/
|
||||
|
||||
int
|
||||
type_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int dflags, successful_finds, opt;
|
||||
WORD_LIST *this;
|
||||
|
||||
if (list == 0)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
dflags = CDESC_SHORTDESC; /* default */
|
||||
successful_finds = 0;
|
||||
|
||||
/* Handle the obsolescent `-type', `-path', and `-all' by prescanning
|
||||
the arguments and converting those options to the form that
|
||||
internal_getopt recognizes. Converts `--type', `--path', and `--all'
|
||||
also. THIS SHOULD REALLY GO AWAY. */
|
||||
for (this = list; this && this->word->word[0] == '-'; this = this->next)
|
||||
{
|
||||
char *flag = &(this->word->word[1]);
|
||||
|
||||
if (STREQ (flag, "type") || STREQ (flag, "-type"))
|
||||
{
|
||||
this->word->word[1] = 't';
|
||||
this->word->word[2] = '\0';
|
||||
}
|
||||
else if (STREQ (flag, "path") || STREQ (flag, "-path"))
|
||||
{
|
||||
this->word->word[1] = 'p';
|
||||
this->word->word[2] = '\0';
|
||||
}
|
||||
else if (STREQ (flag, "all") || STREQ (flag, "-all"))
|
||||
{
|
||||
this->word->word[1] = 'a';
|
||||
this->word->word[2] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
reset_internal_getopt ();
|
||||
while ((opt = internal_getopt (list, "afptP")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'a':
|
||||
dflags |= CDESC_ALL;
|
||||
break;
|
||||
case 'f':
|
||||
dflags |= CDESC_NOFUNCS;
|
||||
break;
|
||||
case 'p':
|
||||
dflags |= CDESC_PATH_ONLY;
|
||||
dflags &= ~(CDESC_TYPE|CDESC_SHORTDESC);
|
||||
break;
|
||||
case 't':
|
||||
dflags |= CDESC_TYPE;
|
||||
dflags &= ~(CDESC_PATH_ONLY|CDESC_SHORTDESC);
|
||||
break;
|
||||
case 'P': /* shorthand for type -ap */
|
||||
dflags |= (CDESC_PATH_ONLY|CDESC_FORCE_PATH);
|
||||
dflags &= ~(CDESC_TYPE|CDESC_SHORTDESC);
|
||||
break;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
while (list)
|
||||
{
|
||||
int found;
|
||||
|
||||
found = describe_command (list->word->word, dflags);
|
||||
|
||||
if (!found && (dflags & (CDESC_PATH_ONLY|CDESC_TYPE)) == 0)
|
||||
sh_notfound (list->word->word);
|
||||
|
||||
successful_finds += found;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
fflush (stdout);
|
||||
|
||||
return ((successful_finds != 0) ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Describe COMMAND as required by the type and command builtins.
|
||||
*
|
||||
* Behavior is controlled by DFLAGS. Flag values are
|
||||
* CDESC_ALL print all descriptions of a command
|
||||
* CDESC_SHORTDESC print the description for type and command -V
|
||||
* CDESC_REUSABLE print in a format that may be reused as input
|
||||
* CDESC_TYPE print the type for type -t
|
||||
* CDESC_PATH_ONLY print the path for type -p
|
||||
* CDESC_FORCE_PATH force a path search for type -P
|
||||
* CDESC_NOFUNCS skip function lookup for type -f
|
||||
* CDESC_ABSPATH convert to absolute path, no ./ prefix
|
||||
*
|
||||
* CDESC_ALL says whether or not to look for all occurrences of COMMAND, or
|
||||
* return after finding it once.
|
||||
*/
|
||||
int
|
||||
describe_command (command, dflags)
|
||||
char *command;
|
||||
int dflags;
|
||||
{
|
||||
int found, i, found_file, f, all;
|
||||
char *full_path, *x;
|
||||
SHELL_VAR *func;
|
||||
#if defined (ALIAS)
|
||||
alias_t *alias;
|
||||
#endif
|
||||
|
||||
all = (dflags & CDESC_ALL) != 0;
|
||||
found = found_file = 0;
|
||||
full_path = (char *)NULL;
|
||||
|
||||
#if defined (ALIAS)
|
||||
/* Command is an alias? */
|
||||
if (((dflags & CDESC_FORCE_PATH) == 0) && expand_aliases && (alias = find_alias (command)))
|
||||
{
|
||||
if (dflags & CDESC_TYPE)
|
||||
puts ("alias");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
printf (_("%s is aliased to `%s'\n"), command, alias->value);
|
||||
else if (dflags & CDESC_REUSABLE)
|
||||
{
|
||||
x = sh_single_quote (alias->value);
|
||||
printf ("alias %s=%s\n", command, x);
|
||||
free (x);
|
||||
}
|
||||
|
||||
found = 1;
|
||||
|
||||
if (all == 0)
|
||||
return (1);
|
||||
}
|
||||
#endif /* ALIAS */
|
||||
|
||||
/* Command is a shell reserved word? */
|
||||
if (((dflags & CDESC_FORCE_PATH) == 0) && (i = find_reserved_word (command)) >= 0)
|
||||
{
|
||||
if (dflags & CDESC_TYPE)
|
||||
puts ("keyword");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
printf (_("%s is a shell keyword\n"), command);
|
||||
else if (dflags & CDESC_REUSABLE)
|
||||
printf ("%s\n", command);
|
||||
|
||||
found = 1;
|
||||
|
||||
if (all == 0)
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Command is a function? */
|
||||
if (((dflags & (CDESC_FORCE_PATH|CDESC_NOFUNCS)) == 0) && (func = find_function (command)))
|
||||
{
|
||||
if (dflags & CDESC_TYPE)
|
||||
puts ("function");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
{
|
||||
#define PRETTY_PRINT_FUNC 1
|
||||
char *result;
|
||||
|
||||
printf (_("%s is a function\n"), command);
|
||||
|
||||
/* We're blowing away THE_PRINTED_COMMAND here... */
|
||||
|
||||
result = named_function_string (command,
|
||||
(COMMAND *) function_cell (func),
|
||||
PRETTY_PRINT_FUNC);
|
||||
printf ("%s\n", result);
|
||||
#undef PRETTY_PRINT_FUNC
|
||||
}
|
||||
else if (dflags & CDESC_REUSABLE)
|
||||
printf ("%s\n", command);
|
||||
|
||||
found = 1;
|
||||
|
||||
if (all == 0)
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Command is a builtin? */
|
||||
if (((dflags & CDESC_FORCE_PATH) == 0) && find_shell_builtin (command))
|
||||
{
|
||||
if (dflags & CDESC_TYPE)
|
||||
puts ("builtin");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
printf (_("%s is a shell builtin\n"), command);
|
||||
else if (dflags & CDESC_REUSABLE)
|
||||
printf ("%s\n", command);
|
||||
|
||||
found = 1;
|
||||
|
||||
if (all == 0)
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Command is a disk file? */
|
||||
/* If the command name given is already an absolute command, just
|
||||
check to see if it is executable. */
|
||||
if (absolute_program (command))
|
||||
{
|
||||
f = file_status (command);
|
||||
if (f & FS_EXECABLE)
|
||||
{
|
||||
if (dflags & CDESC_TYPE)
|
||||
puts ("file");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
printf (_("%s is %s\n"), command, command);
|
||||
else if (dflags & (CDESC_REUSABLE|CDESC_PATH_ONLY))
|
||||
printf ("%s\n", command);
|
||||
|
||||
/* There's no use looking in the hash table or in $PATH,
|
||||
because they're not consulted when an absolute program
|
||||
name is supplied. */
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* If the user isn't doing "-a", then we might care about
|
||||
whether the file is present in our hash table. */
|
||||
if (all == 0 || (dflags & CDESC_FORCE_PATH))
|
||||
{
|
||||
if (full_path = phash_search (command))
|
||||
{
|
||||
if (dflags & CDESC_TYPE)
|
||||
puts ("file");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
printf (_("%s is hashed (%s)\n"), command, full_path);
|
||||
else if (dflags & (CDESC_REUSABLE|CDESC_PATH_ONLY))
|
||||
printf ("%s\n", full_path);
|
||||
|
||||
free (full_path);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Now search through $PATH. */
|
||||
while (1)
|
||||
{
|
||||
if (all == 0)
|
||||
full_path = find_user_command (command);
|
||||
else
|
||||
full_path =
|
||||
user_command_matches (command, FS_EXEC_ONLY, found_file);
|
||||
/* XXX - should that be FS_EXEC_PREFERRED? */
|
||||
|
||||
if (!full_path)
|
||||
break;
|
||||
|
||||
/* If we found the command as itself by looking through $PATH, it
|
||||
probably doesn't exist. Check whether or not the command is an
|
||||
executable file. If it's not, don't report a match. This is
|
||||
the default posix mode behavior */
|
||||
if (STREQ (full_path, command) || posixly_correct)
|
||||
{
|
||||
f = file_status (full_path);
|
||||
if ((f & FS_EXECABLE) == 0)
|
||||
{
|
||||
free (full_path);
|
||||
full_path = (char *)NULL;
|
||||
if (all == 0)
|
||||
break;
|
||||
}
|
||||
else if (dflags & (CDESC_REUSABLE|CDESC_PATH_ONLY|CDESC_SHORTDESC))
|
||||
{
|
||||
f = MP_DOCWD | (dflags & CDESC_ABSPATH) ? MP_RMDOT : 0;
|
||||
full_path = sh_makepath ((char *)NULL, full_path, f);
|
||||
}
|
||||
}
|
||||
/* If we require a full path and don't have one, make one */
|
||||
else if ((dflags & CDESC_ABSPATH) && ABSPATH (full_path) == 0)
|
||||
full_path = sh_makepath ((char *)NULL, full_path, MP_DOCWD|MP_RMDOT);
|
||||
|
||||
found_file++;
|
||||
found = 1;
|
||||
|
||||
if (dflags & CDESC_TYPE)
|
||||
puts ("file");
|
||||
else if (dflags & CDESC_SHORTDESC)
|
||||
printf ("%s is %s\n", command, full_path);
|
||||
else if (dflags & (CDESC_REUSABLE|CDESC_PATH_ONLY))
|
||||
printf ("%s\n", full_path);
|
||||
|
||||
free (full_path);
|
||||
full_path = (char *)NULL;
|
||||
|
||||
if (all == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return (found);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
*** ../bash-3.0/arrayfunc.c Fri Dec 19 00:03:09 2003
|
||||
--- arrayfunc.c Sun Aug 1 20:43:00 2004
|
||||
***************
|
||||
*** 612,616 ****
|
||||
|
||||
free (t);
|
||||
! return var;
|
||||
}
|
||||
|
||||
--- 612,616 ----
|
||||
|
||||
free (t);
|
||||
! return (var == 0 || invisible_p (var)) ? (SHELL_VAR *)0 : var;
|
||||
}
|
||||
|
||||
@@ -5997,6 +5997,11 @@ indication of whether or not a history entry has been modified.
|
||||
@item
|
||||
The default editor used by @code{fc} is @code{ed}.
|
||||
|
||||
@item
|
||||
The @code{type} and @code{command} builtins will not report a non-executable
|
||||
file as having been found, though the shell will attempt to execute such a
|
||||
file if it is the only so-named file found in @code{$PATH}.
|
||||
|
||||
@end enumerate
|
||||
|
||||
There is other @sc{posix} 1003.2 behavior that Bash does not implement.
|
||||
|
||||
@@ -5994,6 +5994,9 @@ falling back to @var{physical} mode.
|
||||
When listing the history, the @code{fc} builtin does not include an
|
||||
indication of whether or not a history entry has been modified.
|
||||
|
||||
@item
|
||||
The default editor used by @code{fc} is @code{ed}.
|
||||
|
||||
@end enumerate
|
||||
|
||||
There is other @sc{posix} 1003.2 behavior that Bash does not implement.
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ Copyright (C) 1988-2004 Free Software Foundation, Inc.
|
||||
|
||||
@set EDITION 3.0
|
||||
@set VERSION 3.0
|
||||
@set UPDATED 1 August 2004
|
||||
@set UPDATED 2 August 2004
|
||||
@set UPDATED-MONTH August 2004
|
||||
|
||||
@set LASTCHANGE Sun Aug 1 14:48:46 EDT 2004
|
||||
@set LASTCHANGE Mon Aug 2 22:45:05 EDT 2004
|
||||
|
||||
+3
-3
@@ -4,7 +4,7 @@ Copyright (C) 1988-2004 Free Software Foundation, Inc.
|
||||
|
||||
@set EDITION 3.0
|
||||
@set VERSION 3.0
|
||||
@set UPDATED 27 July 2004
|
||||
@set UPDATED-MONTH July 2004
|
||||
@set UPDATED 1 August 2004
|
||||
@set UPDATED-MONTH August 2004
|
||||
|
||||
@set LASTCHANGE Tue Jul 27 09:12:07 EDT 2004
|
||||
@set LASTCHANGE Sun Aug 1 14:48:46 EDT 2004
|
||||
|
||||
+9
-3
@@ -2508,9 +2508,15 @@ execute_cond_node (cond)
|
||||
}
|
||||
else
|
||||
#endif /* COND_REGEXP */
|
||||
result = binary_test (cond->op->word, arg1, arg2, TEST_PATMATCH|TEST_ARITHEXP)
|
||||
? EXECUTION_SUCCESS
|
||||
: EXECUTION_FAILURE;
|
||||
{
|
||||
int oe;
|
||||
oe = extended_glob;
|
||||
extended_glob = 1;
|
||||
result = binary_test (cond->op->word, arg1, arg2, TEST_PATMATCH|TEST_ARITHEXP)
|
||||
? EXECUTION_SUCCESS
|
||||
: EXECUTION_FAILURE;
|
||||
extended_glob = oe;
|
||||
}
|
||||
if (arg1 != nullstr)
|
||||
free (arg1);
|
||||
if (arg2 != nullstr)
|
||||
|
||||
+4028
File diff suppressed because it is too large
Load Diff
@@ -201,7 +201,7 @@ expand_prompt (pmt, lp, lip, niflp, vlp)
|
||||
int *lp, *lip, *niflp, *vlp;
|
||||
{
|
||||
char *r, *ret, *p;
|
||||
int l, rl, last, ignoring, ninvis, invfl, ind, pind, physchars;
|
||||
int l, rl, last, ignoring, ninvis, invfl, invflset, ind, pind, physchars;
|
||||
|
||||
/* Short-circuit if we can. */
|
||||
if ((MB_CUR_MAX <= 1 || rl_byte_oriented) && strchr (pmt, RL_PROMPT_START_IGNORE) == 0)
|
||||
@@ -222,6 +222,7 @@ expand_prompt (pmt, lp, lip, niflp, vlp)
|
||||
r = ret = (char *)xmalloc (l + 1);
|
||||
|
||||
invfl = 0; /* invisible chars in first line of prompt */
|
||||
invflset = 0; /* we only want to set invfl once */
|
||||
|
||||
for (rl = ignoring = last = ninvis = physchars = 0, p = pmt; p && *p; p++)
|
||||
{
|
||||
@@ -264,8 +265,11 @@ expand_prompt (pmt, lp, lip, niflp, vlp)
|
||||
ninvis++; /* invisible chars byte counter */
|
||||
}
|
||||
|
||||
if (rl >= _rl_screenwidth)
|
||||
invfl = ninvis;
|
||||
if (invflset == 0 && rl >= _rl_screenwidth)
|
||||
{
|
||||
invfl = ninvis;
|
||||
invflset = 1;
|
||||
}
|
||||
|
||||
if (ignoring == 0)
|
||||
physchars++;
|
||||
|
||||
+3
-5
@@ -1,7 +1,6 @@
|
||||
./type.tests: line 9: type: -r: invalid option
|
||||
type: usage: type [-afptP] name [name ...]
|
||||
./type.tests: line 12: type: notthere: not found
|
||||
./type.tests: line 13: command: notthere: not found
|
||||
function
|
||||
keyword
|
||||
builtin
|
||||
@@ -25,8 +24,7 @@ func ()
|
||||
}
|
||||
while
|
||||
while is a shell keyword
|
||||
./type.tests: line 42: type: m: not found
|
||||
./type.tests: line 43: command: m: not found
|
||||
./type.tests: line 43: type: m: not found
|
||||
alias m='more'
|
||||
alias m='more'
|
||||
m is aliased to `more'
|
||||
@@ -39,8 +37,8 @@ builtin
|
||||
builtin is a shell builtin
|
||||
/bin/sh
|
||||
/bin/sh is /bin/sh
|
||||
./type.tests: line 64: type: func: not found
|
||||
./type.tests: line 66: type: m: not found
|
||||
./type.tests: line 65: type: func: not found
|
||||
./type.tests: line 67: type: m: not found
|
||||
/bin/sh
|
||||
/tmp/bash
|
||||
bash is hashed (/tmp/bash)
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
./type.tests: line 9: type: -r: invalid option
|
||||
type: usage: type [-afptP] name [name ...]
|
||||
./type.tests: line 12: type: notthere: not found
|
||||
function
|
||||
keyword
|
||||
builtin
|
||||
file
|
||||
file
|
||||
file
|
||||
func is a function
|
||||
func ()
|
||||
{
|
||||
echo this is func
|
||||
}
|
||||
while is a shell keyword
|
||||
while is a shell keyword
|
||||
builtin is a shell builtin
|
||||
/bin/sh is /bin/sh
|
||||
func
|
||||
func is a function
|
||||
func ()
|
||||
{
|
||||
echo this is func
|
||||
}
|
||||
while
|
||||
while is a shell keyword
|
||||
./type.tests: line 42: type: m: not found
|
||||
alias m='more'
|
||||
alias m='more'
|
||||
m is aliased to `more'
|
||||
alias
|
||||
alias m='more'
|
||||
alias m='more'
|
||||
alias m='more'
|
||||
m is aliased to `more'
|
||||
builtin
|
||||
builtin is a shell builtin
|
||||
/bin/sh
|
||||
/bin/sh is /bin/sh
|
||||
./type.tests: line 64: type: func: not found
|
||||
./type.tests: line 66: type: m: not found
|
||||
/bin/sh
|
||||
/tmp/bash
|
||||
bash is hashed (/tmp/bash)
|
||||
file
|
||||
hits command
|
||||
3 /tmp/bash
|
||||
1 /bin/sh
|
||||
+2
-1
@@ -36,7 +36,8 @@ command -V func
|
||||
command -v while
|
||||
command -V while
|
||||
|
||||
# the following three lines should produce the same output
|
||||
# the following two lines should produce the same output
|
||||
# post-3.0 patch makes command -v silent, as posix specifies
|
||||
# first test with alias expansion off (should all fail or produce no output)
|
||||
type -t m
|
||||
type m
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
set +o posix
|
||||
|
||||
hash -r
|
||||
unalias -a
|
||||
|
||||
# this should echo nothing
|
||||
type
|
||||
# this should be a usage error
|
||||
type -r ${THIS_SH}
|
||||
|
||||
# these should behave identically
|
||||
type notthere
|
||||
command -v notthere
|
||||
|
||||
alias m=more
|
||||
|
||||
unset -f func 2>/dev/null
|
||||
func() { echo this is func; }
|
||||
|
||||
type -t func
|
||||
type -t while
|
||||
type -t builtin
|
||||
type -t /bin/sh
|
||||
type -t ${THIS_SH}
|
||||
type -t mv
|
||||
|
||||
type func
|
||||
# the following two should produce identical output
|
||||
type while
|
||||
type -a while
|
||||
type builtin
|
||||
type /bin/sh
|
||||
|
||||
command -v func
|
||||
command -V func
|
||||
command -v while
|
||||
command -V while
|
||||
|
||||
# the following three lines should produce the same output
|
||||
# first test with alias expansion off (should all fail or produce no output)
|
||||
type -t m
|
||||
type m
|
||||
command -v m
|
||||
alias -p
|
||||
alias m
|
||||
|
||||
# then test with alias expansion on
|
||||
shopt -s expand_aliases
|
||||
type m
|
||||
type -t m
|
||||
command -v m
|
||||
alias -p
|
||||
alias m
|
||||
|
||||
command -V m
|
||||
shopt -u expand_aliases
|
||||
|
||||
command -v builtin
|
||||
command -V builtin
|
||||
command -v /bin/sh
|
||||
command -V /bin/sh
|
||||
|
||||
unset -f func
|
||||
type func
|
||||
unalias m
|
||||
type m
|
||||
|
||||
hash -r
|
||||
|
||||
hash -p /bin/sh sh
|
||||
type -p sh
|
||||
|
||||
SHBASE=${THIS_SH##*/}
|
||||
hash -p /tmp/$SHBASE $SHBASE
|
||||
type -p $SHBASE
|
||||
type $SHBASE
|
||||
|
||||
type -t $SHBASE
|
||||
|
||||
# make sure the hash table looks right
|
||||
hash
|
||||
+6
-1
@@ -2302,13 +2302,18 @@ makunbound (name, vc)
|
||||
We also need to add it back into the correct hash table. */
|
||||
if (old_var && local_p (old_var) && variable_context == old_var->context)
|
||||
{
|
||||
#if defined (ARRAY_VARS)
|
||||
if (array_p (old_var))
|
||||
array_dispose (array_cell (old_var));
|
||||
else
|
||||
#endif
|
||||
FREE (value_cell (old_var));
|
||||
/* Reset the attributes. Preserve the export attribute if the variable
|
||||
came from a temporary environment. Make sure it stays local, and
|
||||
make it invisible. */
|
||||
old_var->attributes = (exported_p (old_var) && tempvar_p (old_var)) ? att_exported : 0;
|
||||
VSETATTR (old_var, att_local);
|
||||
VSETATTR (old_var, att_invisible);
|
||||
FREE (value_cell (old_var));
|
||||
var_setvalue (old_var, (char *)NULL);
|
||||
INVALIDATE_EXPORTSTR (old_var);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user