bash-4.3/ 0000755 0001750 0000144 00000000000 12305026060 011142 5 ustar doko users bash-4.3/assoc.c 0000644 0001750 0000144 00000026017 11655317351 012441 0 ustar doko users /*
* assoc.c - functions to manipulate associative arrays
*
* Associative arrays are standard shell hash tables.
*
* Chet Ramey
* chet@ins.cwru.edu
*/
/* Copyright (C) 2008,2009,2011 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 3 of the License, 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. If not, see .
*/
#include "config.h"
#if defined (ARRAY_VARS)
#if defined (HAVE_UNISTD_H)
# ifdef _MINIX
# include
# endif
# include
#endif
#include
#include "bashansi.h"
#include "shell.h"
#include "array.h"
#include "assoc.h"
#include "builtins/common.h"
static WORD_LIST *assoc_to_word_list_internal __P((HASH_TABLE *, int));
/* assoc_create == hash_create */
void
assoc_dispose (hash)
HASH_TABLE *hash;
{
if (hash)
{
hash_flush (hash, 0);
hash_dispose (hash);
}
}
void
assoc_flush (hash)
HASH_TABLE *hash;
{
hash_flush (hash, 0);
}
int
assoc_insert (hash, key, value)
HASH_TABLE *hash;
char *key;
char *value;
{
BUCKET_CONTENTS *b;
b = hash_search (key, hash, HASH_CREATE);
if (b == 0)
return -1;
/* If we are overwriting an existing element's value, we're not going to
use the key. Nothing in the array assignment code path frees the key
string, so we can free it here to avoid a memory leak. */
if (b->key != key)
free (key);
FREE (b->data);
b->data = value ? savestring (value) : (char *)0;
return (0);
}
/* Like assoc_insert, but returns b->data instead of freeing it */
PTR_T
assoc_replace (hash, key, value)
HASH_TABLE *hash;
char *key;
char *value;
{
BUCKET_CONTENTS *b;
PTR_T t;
b = hash_search (key, hash, HASH_CREATE);
if (b == 0)
return (PTR_T)0;
/* If we are overwriting an existing element's value, we're not going to
use the key. Nothing in the array assignment code path frees the key
string, so we can free it here to avoid a memory leak. */
if (b->key != key)
free (key);
t = b->data;
b->data = value ? savestring (value) : (char *)0;
return t;
}
void
assoc_remove (hash, string)
HASH_TABLE *hash;
char *string;
{
BUCKET_CONTENTS *b;
b = hash_remove (string, hash, 0);
if (b)
{
free ((char *)b->data);
free (b->key);
free (b);
}
}
char *
assoc_reference (hash, string)
HASH_TABLE *hash;
char *string;
{
BUCKET_CONTENTS *b;
if (hash == 0)
return (char *)0;
b = hash_search (string, hash, 0);
return (b ? (char *)b->data : 0);
}
/* Quote the data associated with each element of the hash table ASSOC,
using quote_string */
HASH_TABLE *
assoc_quote (h)
HASH_TABLE *h;
{
int i;
BUCKET_CONTENTS *tlist;
char *t;
if (h == 0 || assoc_empty (h))
return ((HASH_TABLE *)NULL);
for (i = 0; i < h->nbuckets; i++)
for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
{
t = quote_string ((char *)tlist->data);
FREE (tlist->data);
tlist->data = t;
}
return h;
}
/* Quote escape characters in the data associated with each element
of the hash table ASSOC, using quote_escapes */
HASH_TABLE *
assoc_quote_escapes (h)
HASH_TABLE *h;
{
int i;
BUCKET_CONTENTS *tlist;
char *t;
if (h == 0 || assoc_empty (h))
return ((HASH_TABLE *)NULL);
for (i = 0; i < h->nbuckets; i++)
for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
{
t = quote_escapes ((char *)tlist->data);
FREE (tlist->data);
tlist->data = t;
}
return h;
}
HASH_TABLE *
assoc_dequote (h)
HASH_TABLE *h;
{
int i;
BUCKET_CONTENTS *tlist;
char *t;
if (h == 0 || assoc_empty (h))
return ((HASH_TABLE *)NULL);
for (i = 0; i < h->nbuckets; i++)
for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
{
t = dequote_string ((char *)tlist->data);
FREE (tlist->data);
tlist->data = t;
}
return h;
}
HASH_TABLE *
assoc_dequote_escapes (h)
HASH_TABLE *h;
{
int i;
BUCKET_CONTENTS *tlist;
char *t;
if (h == 0 || assoc_empty (h))
return ((HASH_TABLE *)NULL);
for (i = 0; i < h->nbuckets; i++)
for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
{
t = dequote_escapes ((char *)tlist->data);
FREE (tlist->data);
tlist->data = t;
}
return h;
}
HASH_TABLE *
assoc_remove_quoted_nulls (h)
HASH_TABLE *h;
{
int i;
BUCKET_CONTENTS *tlist;
char *t;
if (h == 0 || assoc_empty (h))
return ((HASH_TABLE *)NULL);
for (i = 0; i < h->nbuckets; i++)
for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
{
t = remove_quoted_nulls ((char *)tlist->data);
tlist->data = t;
}
return h;
}
/*
* Return a string whose elements are the members of array H beginning at
* the STARTth element and spanning NELEM members. Null elements are counted.
*/
char *
assoc_subrange (hash, start, nelem, starsub, quoted)
HASH_TABLE *hash;
arrayind_t start, nelem;
int starsub, quoted;
{
WORD_LIST *l, *save, *h, *t;
int i, j;
char *ret;
if (assoc_empty (hash))
return ((char *)NULL);
save = l = assoc_to_word_list (hash);
if (save == 0)
return ((char *)NULL);
for (i = 1; l && i < start; i++)
l = l->next;
if (l == 0)
return ((char *)NULL);
for (j = 0,h = t = l; l && j < nelem; j++)
{
t = l;
l = l->next;
}
t->next = (WORD_LIST *)NULL;
ret = string_list_pos_params (starsub ? '*' : '@', h, quoted);
if (t != l)
t->next = l;
dispose_words (save);
return (ret);
}
char *
assoc_patsub (h, pat, rep, mflags)
HASH_TABLE *h;
char *pat, *rep;
int mflags;
{
BUCKET_CONTENTS *tlist;
int i, slen;
HASH_TABLE *h2;
char *t, *sifs, *ifs;
if (h == 0 || assoc_empty (h))
return ((char *)NULL);
h2 = assoc_copy (h);
for (i = 0; i < h2->nbuckets; i++)
for (tlist = hash_items (i, h2); tlist; tlist = tlist->next)
{
t = pat_subst ((char *)tlist->data, pat, rep, mflags);
FREE (tlist->data);
tlist->data = t;
}
if (mflags & MATCH_QUOTED)
assoc_quote (h2);
else
assoc_quote_escapes (h2);
if (mflags & MATCH_STARSUB)
{
assoc_remove_quoted_nulls (h2);
sifs = ifs_firstchar ((int *)NULL);
t = assoc_to_string (h2, sifs, 0);
free (sifs);
}
else if (mflags & MATCH_QUOTED)
{
/* ${array[@]} */
sifs = ifs_firstchar (&slen);
ifs = getifs ();
if (ifs == 0 || *ifs == 0)
{
if (slen < 2)
sifs = xrealloc (sifs, 2);
sifs[0] = ' ';
sifs[1] = '\0';
}
t = assoc_to_string (h2, sifs, 0);
free(sifs);
}
else
t = assoc_to_string (h2, " ", 0);
assoc_dispose (h2);
return t;
}
char *
assoc_modcase (h, pat, modop, mflags)
HASH_TABLE *h;
char *pat;
int modop;
int mflags;
{
BUCKET_CONTENTS *tlist;
int i, slen;
HASH_TABLE *h2;
char *t, *sifs, *ifs;
if (h == 0 || assoc_empty (h))
return ((char *)NULL);
h2 = assoc_copy (h);
for (i = 0; i < h2->nbuckets; i++)
for (tlist = hash_items (i, h2); tlist; tlist = tlist->next)
{
t = sh_modcase ((char *)tlist->data, pat, modop);
FREE (tlist->data);
tlist->data = t;
}
if (mflags & MATCH_QUOTED)
assoc_quote (h2);
else
assoc_quote_escapes (h2);
if (mflags & MATCH_STARSUB)
{
assoc_remove_quoted_nulls (h2);
sifs = ifs_firstchar ((int *)NULL);
t = assoc_to_string (h2, sifs, 0);
free (sifs);
}
else if (mflags & MATCH_QUOTED)
{
/* ${array[@]} */
sifs = ifs_firstchar (&slen);
ifs = getifs ();
if (ifs == 0 || *ifs == 0)
{
if (slen < 2)
sifs = xrealloc (sifs, 2);
sifs[0] = ' ';
sifs[1] = '\0';
}
t = assoc_to_string (h2, sifs, 0);
free(sifs);
}
else
t = assoc_to_string (h2, " ", 0);
assoc_dispose (h2);
return t;
}
char *
assoc_to_assign (hash, quoted)
HASH_TABLE *hash;
int quoted;
{
char *ret;
char *istr, *vstr;
int i, rsize, rlen, elen;
BUCKET_CONTENTS *tlist;
if (hash == 0 || assoc_empty (hash))
return (char *)0;
ret = xmalloc (rsize = 128);
ret[0] = '(';
rlen = 1;
for (i = 0; i < hash->nbuckets; i++)
for (tlist = hash_items (i, hash); tlist; tlist = tlist->next)
{
#if 1
if (sh_contains_shell_metas (tlist->key))
istr = sh_double_quote (tlist->key);
else
istr = tlist->key;
#else
istr = tlist->key;
#endif
vstr = tlist->data ? sh_double_quote ((char *)tlist->data) : (char *)0;
elen = STRLEN (istr) + 8 + STRLEN (vstr);
RESIZE_MALLOCED_BUFFER (ret, rlen, (elen+1), rsize, rsize);
ret[rlen++] = '[';
strcpy (ret+rlen, istr);
rlen += STRLEN (istr);
ret[rlen++] = ']';
ret[rlen++] = '=';
if (vstr)
{
strcpy (ret + rlen, vstr);
rlen += STRLEN (vstr);
}
ret[rlen++] = ' ';
if (istr != tlist->key)
FREE (istr);
FREE (vstr);
}
RESIZE_MALLOCED_BUFFER (ret, rlen, 1, rsize, 8);
ret[rlen++] = ')';
ret[rlen] = '\0';
if (quoted)
{
vstr = sh_single_quote (ret);
free (ret);
ret = vstr;
}
return ret;
}
static WORD_LIST *
assoc_to_word_list_internal (h, t)
HASH_TABLE *h;
int t;
{
WORD_LIST *list;
int i;
BUCKET_CONTENTS *tlist;
char *w;
if (h == 0 || assoc_empty (h))
return((WORD_LIST *)NULL);
list = (WORD_LIST *)NULL;
for (i = 0; i < h->nbuckets; i++)
for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
{
w = (t == 0) ? (char *)tlist->data : (char *)tlist->key;
list = make_word_list (make_bare_word(w), list);
}
return (REVERSE_LIST(list, WORD_LIST *));
}
WORD_LIST *
assoc_to_word_list (h)
HASH_TABLE *h;
{
return (assoc_to_word_list_internal (h, 0));
}
WORD_LIST *
assoc_keys_to_word_list (h)
HASH_TABLE *h;
{
return (assoc_to_word_list_internal (h, 1));
}
char *
assoc_to_string (h, sep, quoted)
HASH_TABLE *h;
char *sep;
int quoted;
{
BUCKET_CONTENTS *tlist;
int i;
char *result, *t, *w;
WORD_LIST *list, *l;
if (h == 0)
return ((char *)NULL);
if (assoc_empty (h))
return (savestring (""));
result = NULL;
l = list = NULL;
/* This might be better implemented directly, but it's simple to implement
by converting to a word list first, possibly quoting the data, then
using list_string */
for (i = 0; i < h->nbuckets; i++)
for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
{
w = (char *)tlist->data;
if (w == 0)
continue;
t = quoted ? quote_string (w) : savestring (w);
list = make_word_list (make_bare_word(t), list);
FREE (t);
}
l = REVERSE_LIST(list, WORD_LIST *);
result = l ? string_list_internal (l, sep) : savestring ("");
dispose_words (l);
return result;
}
#endif /* ARRAY_VARS */
bash-4.3/bashline.h 0000644 0001750 0000144 00000004042 11674507056 013121 0 ustar doko users /* bashline.h -- interface to the bash readline functions in bashline.c. */
/* Copyright (C) 1993-2009 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 3 of the License, 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. If not, see .
*/
#if !defined (_BASHLINE_H_)
#define _BASHLINE_H_
#include "stdc.h"
extern int bash_readline_initialized;
extern void posix_readline_initialize __P((int));
extern void reset_completer_word_break_chars __P((void));
extern int enable_hostname_completion __P((int));
extern void initialize_readline __P((void));
extern void bashline_reset __P((void));
extern void bashline_reinitialize __P((void));
extern int bash_re_edit __P((char *));
extern void bashline_set_event_hook __P((void));
extern void bashline_reset_event_hook __P((void));
extern int bind_keyseq_to_unix_command __P((char *));
extern int print_unix_command_map __P((void));
extern char **bash_default_completion __P((const char *, int, int, int, int));
void set_directory_hook __P((void));
/* Used by programmable completion code. */
extern char *command_word_completion_function __P((const char *, int));
extern char *bash_groupname_completion_function __P((const char *, int));
extern char *bash_servicename_completion_function __P((const char *, int));
extern char **get_hostname_list __P((void));
extern void clear_hostname_list __P((void));
extern char **bash_directory_completion_matches __P((const char *));
extern char *bash_dequote_text __P((const char *));
#endif /* _BASHLINE_H_ */
bash-4.3/test.c 0000644 0001750 0000144 00000050050 12274260472 012301 0 ustar doko users /* test.c - GNU test program (ksb and mjb) */
/* Modified to run with the GNU shell Apr 25, 1988 by bfox. */
/* Copyright (C) 1987-2010 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 3 of the License, 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. If not, see .
*/
/* Define PATTERN_MATCHING to get the csh-like =~ and !~ pattern-matching
binary operators. */
/* #define PATTERN_MATCHING */
#if defined (HAVE_CONFIG_H)
# include
#endif
#include
#include "bashtypes.h"
#if !defined (HAVE_LIMITS_H) && defined (HAVE_SYS_PARAM_H)
# include
#endif
#if defined (HAVE_UNISTD_H)
# include
#endif
#include
#if !defined (errno)
extern int errno;
#endif /* !errno */
#if !defined (_POSIX_VERSION) && defined (HAVE_SYS_FILE_H)
# include
#endif /* !_POSIX_VERSION */
#include "posixstat.h"
#include "filecntl.h"
#include "stat-time.h"
#include "bashintl.h"
#include "shell.h"
#include "pathexp.h"
#include "test.h"
#include "builtins/common.h"
#include
#if !defined (STRLEN)
# define STRLEN(s) ((s)[0] ? ((s)[1] ? ((s)[2] ? strlen(s) : 2) : 1) : 0)
#endif
#if !defined (STREQ)
# define STREQ(a, b) ((a)[0] == (b)[0] && strcmp ((a), (b)) == 0)
#endif /* !STREQ */
#define STRCOLLEQ(a, b) ((a)[0] == (b)[0] && strcoll ((a), (b)) == 0)
#if !defined (R_OK)
#define R_OK 4
#define W_OK 2
#define X_OK 1
#define F_OK 0
#endif /* R_OK */
#define EQ 0
#define NE 1
#define LT 2
#define GT 3
#define LE 4
#define GE 5
#define NT 0
#define OT 1
#define EF 2
/* The following few defines control the truth and false output of each stage.
TRUE and FALSE are what we use to compute the final output value.
SHELL_BOOLEAN is the form which returns truth or falseness in shell terms.
Default is TRUE = 1, FALSE = 0, SHELL_BOOLEAN = (!value). */
#define TRUE 1
#define FALSE 0
#define SHELL_BOOLEAN(value) (!(value))
#define TEST_ERREXIT_STATUS 2
static procenv_t test_exit_buf;
static int test_error_return;
#define test_exit(val) \
do { test_error_return = val; longjmp (test_exit_buf, 1); } while (0)
extern int sh_stat __P((const char *, struct stat *));
static int pos; /* The offset of the current argument in ARGV. */
static int argc; /* The number of arguments present in ARGV. */
static char **argv; /* The argument list. */
static int noeval;
static void test_syntax_error __P((char *, char *)) __attribute__((__noreturn__));
static void beyond __P((void)) __attribute__((__noreturn__));
static void integer_expected_error __P((char *)) __attribute__((__noreturn__));
static int unary_operator __P((void));
static int binary_operator __P((void));
static int two_arguments __P((void));
static int three_arguments __P((void));
static int posixtest __P((void));
static int expr __P((void));
static int term __P((void));
static int and __P((void));
static int or __P((void));
static int filecomp __P((char *, char *, int));
static int arithcomp __P((char *, char *, int, int));
static int patcomp __P((char *, char *, int));
static void
test_syntax_error (format, arg)
char *format, *arg;
{
builtin_error (format, arg);
test_exit (TEST_ERREXIT_STATUS);
}
/*
* beyond - call when we're beyond the end of the argument list (an
* error condition)
*/
static void
beyond ()
{
test_syntax_error (_("argument expected"), (char *)NULL);
}
/* Syntax error for when an integer argument was expected, but
something else was found. */
static void
integer_expected_error (pch)
char *pch;
{
test_syntax_error (_("%s: integer expression expected"), pch);
}
/* Increment our position in the argument list. Check that we're not
past the end of the argument list. This check is suppressed if the
argument is FALSE. Made a macro for efficiency. */
#define advance(f) do { ++pos; if (f && pos >= argc) beyond (); } while (0)
#define unary_advance() do { advance (1); ++pos; } while (0)
/*
* expr:
* or
*/
static int
expr ()
{
if (pos >= argc)
beyond ();
return (FALSE ^ or ()); /* Same with this. */
}
/*
* or:
* and
* and '-o' or
*/
static int
or ()
{
int value, v2;
value = and ();
if (pos < argc && argv[pos][0] == '-' && argv[pos][1] == 'o' && !argv[pos][2])
{
advance (0);
v2 = or ();
return (value || v2);
}
return (value);
}
/*
* and:
* term
* term '-a' and
*/
static int
and ()
{
int value, v2;
value = term ();
if (pos < argc && argv[pos][0] == '-' && argv[pos][1] == 'a' && !argv[pos][2])
{
advance (0);
v2 = and ();
return (value && v2);
}
return (value);
}
/*
* term - parse a term and return 1 or 0 depending on whether the term
* evaluates to true or false, respectively.
*
* term ::=
* '-'('a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'k'|'p'|'r'|'s'|'u'|'w'|'x') filename
* '-'('G'|'L'|'O'|'S'|'N') filename
* '-t' [int]
* '-'('z'|'n') string
* '-o' option
* string
* string ('!='|'='|'==') string
* '-'(eq|ne|le|lt|ge|gt)
* file '-'(nt|ot|ef) file
* '(' ')'
* int ::=
* positive and negative integers
*/
static int
term ()
{
int value;
if (pos >= argc)
beyond ();
/* Deal with leading `not's. */
if (argv[pos][0] == '!' && argv[pos][1] == '\0')
{
value = 0;
while (pos < argc && argv[pos][0] == '!' && argv[pos][1] == '\0')
{
advance (1);
value = 1 - value;
}
return (value ? !term() : term());
}
/* A paren-bracketed argument. */
if (argv[pos][0] == '(' && argv[pos][1] == '\0') /* ) */
{
advance (1);
value = expr ();
if (argv[pos] == 0) /* ( */
test_syntax_error (_("`)' expected"), (char *)NULL);
else if (argv[pos][0] != ')' || argv[pos][1]) /* ( */
test_syntax_error (_("`)' expected, found %s"), argv[pos]);
advance (0);
return (value);
}
/* are there enough arguments left that this could be dyadic? */
if ((pos + 3 <= argc) && test_binop (argv[pos + 1]))
value = binary_operator ();
/* Might be a switch type argument */
else if (argv[pos][0] == '-' && argv[pos][2] == '\0')
{
if (test_unop (argv[pos]))
value = unary_operator ();
else
test_syntax_error (_("%s: unary operator expected"), argv[pos]);
}
else
{
value = argv[pos][0] != '\0';
advance (0);
}
return (value);
}
static int
stat_mtime (fn, st, ts)
char *fn;
struct stat *st;
struct timespec *ts;
{
int r;
r = sh_stat (fn, st);
if (r < 0)
return r;
*ts = get_stat_mtime (st);
return 0;
}
static int
filecomp (s, t, op)
char *s, *t;
int op;
{
struct stat st1, st2;
struct timespec ts1, ts2;
int r1, r2;
if ((r1 = stat_mtime (s, &st1, &ts1)) < 0)
{
if (op == EF)
return (FALSE);
}
if ((r2 = stat_mtime (t, &st2, &ts2)) < 0)
{
if (op == EF)
return (FALSE);
}
switch (op)
{
case OT: return (r1 < r2 || (r2 == 0 && timespec_cmp (ts1, ts2) < 0));
case NT: return (r1 > r2 || (r1 == 0 && timespec_cmp (ts1, ts2) > 0));
case EF: return (same_file (s, t, &st1, &st2));
}
return (FALSE);
}
static int
arithcomp (s, t, op, flags)
char *s, *t;
int op, flags;
{
intmax_t l, r;
int expok;
if (flags & TEST_ARITHEXP)
{
l = evalexp (s, &expok);
if (expok == 0)
return (FALSE); /* should probably longjmp here */
r = evalexp (t, &expok);
if (expok == 0)
return (FALSE); /* ditto */
}
else
{
if (legal_number (s, &l) == 0)
integer_expected_error (s);
if (legal_number (t, &r) == 0)
integer_expected_error (t);
}
switch (op)
{
case EQ: return (l == r);
case NE: return (l != r);
case LT: return (l < r);
case GT: return (l > r);
case LE: return (l <= r);
case GE: return (l >= r);
}
return (FALSE);
}
static int
patcomp (string, pat, op)
char *string, *pat;
int op;
{
int m;
m = strmatch (pat, string, FNMATCH_EXTFLAG|FNMATCH_IGNCASE);
return ((op == EQ) ? (m == 0) : (m != 0));
}
int
binary_test (op, arg1, arg2, flags)
char *op, *arg1, *arg2;
int flags;
{
int patmatch;
patmatch = (flags & TEST_PATMATCH);
if (op[0] == '=' && (op[1] == '\0' || (op[1] == '=' && op[2] == '\0')))
return (patmatch ? patcomp (arg1, arg2, EQ) : STREQ (arg1, arg2));
else if ((op[0] == '>' || op[0] == '<') && op[1] == '\0')
{
#if defined (HAVE_STRCOLL)
if (shell_compatibility_level > 40 && flags & TEST_LOCALE)
return ((op[0] == '>') ? (strcoll (arg1, arg2) > 0) : (strcoll (arg1, arg2) < 0));
else
#endif
return ((op[0] == '>') ? (strcmp (arg1, arg2) > 0) : (strcmp (arg1, arg2) < 0));
}
else if (op[0] == '!' && op[1] == '=' && op[2] == '\0')
return (patmatch ? patcomp (arg1, arg2, NE) : (STREQ (arg1, arg2) == 0));
else if (op[2] == 't')
{
switch (op[1])
{
case 'n': return (filecomp (arg1, arg2, NT)); /* -nt */
case 'o': return (filecomp (arg1, arg2, OT)); /* -ot */
case 'l': return (arithcomp (arg1, arg2, LT, flags)); /* -lt */
case 'g': return (arithcomp (arg1, arg2, GT, flags)); /* -gt */
}
}
else if (op[1] == 'e')
{
switch (op[2])
{
case 'f': return (filecomp (arg1, arg2, EF)); /* -ef */
case 'q': return (arithcomp (arg1, arg2, EQ, flags)); /* -eq */
}
}
else if (op[2] == 'e')
{
switch (op[1])
{
case 'n': return (arithcomp (arg1, arg2, NE, flags)); /* -ne */
case 'g': return (arithcomp (arg1, arg2, GE, flags)); /* -ge */
case 'l': return (arithcomp (arg1, arg2, LE, flags)); /* -le */
}
}
return (FALSE); /* should never get here */
}
static int
binary_operator ()
{
int value;
char *w;
w = argv[pos + 1];
if ((w[0] == '=' && (w[1] == '\0' || (w[1] == '=' && w[2] == '\0'))) || /* =, == */
((w[0] == '>' || w[0] == '<') && w[1] == '\0') || /* <, > */
(w[0] == '!' && w[1] == '=' && w[2] == '\0')) /* != */
{
value = binary_test (w, argv[pos], argv[pos + 2], 0);
pos += 3;
return (value);
}
#if defined (PATTERN_MATCHING)
if ((w[0] == '=' || w[0] == '!') && w[1] == '~' && w[2] == '\0')
{
value = patcomp (argv[pos], argv[pos + 2], w[0] == '=' ? EQ : NE);
pos += 3;
return (value);
}
#endif
if ((w[0] != '-' || w[3] != '\0') || test_binop (w) == 0)
{
test_syntax_error (_("%s: binary operator expected"), w);
/* NOTREACHED */
return (FALSE);
}
value = binary_test (w, argv[pos], argv[pos + 2], 0);
pos += 3;
return value;
}
static int
unary_operator ()
{
char *op;
intmax_t r;
op = argv[pos];
if (test_unop (op) == 0)
return (FALSE);
/* the only tricky case is `-t', which may or may not take an argument. */
if (op[1] == 't')
{
advance (0);
if (pos < argc)
{
if (legal_number (argv[pos], &r))
{
advance (0);
return (unary_test (op, argv[pos - 1]));
}
else
return (FALSE);
}
else
return (unary_test (op, "1"));
}
/* All of the unary operators take an argument, so we first call
unary_advance (), which checks to make sure that there is an
argument, and then advances pos right past it. This means that
pos - 1 is the location of the argument. */
unary_advance ();
return (unary_test (op, argv[pos - 1]));
}
int
unary_test (op, arg)
char *op, *arg;
{
intmax_t r;
struct stat stat_buf;
SHELL_VAR *v;
switch (op[1])
{
case 'a': /* file exists in the file system? */
case 'e':
return (sh_stat (arg, &stat_buf) == 0);
case 'r': /* file is readable? */
return (sh_eaccess (arg, R_OK) == 0);
case 'w': /* File is writeable? */
return (sh_eaccess (arg, W_OK) == 0);
case 'x': /* File is executable? */
return (sh_eaccess (arg, X_OK) == 0);
case 'O': /* File is owned by you? */
return (sh_stat (arg, &stat_buf) == 0 &&
(uid_t) current_user.euid == (uid_t) stat_buf.st_uid);
case 'G': /* File is owned by your group? */
return (sh_stat (arg, &stat_buf) == 0 &&
(gid_t) current_user.egid == (gid_t) stat_buf.st_gid);
case 'N':
return (sh_stat (arg, &stat_buf) == 0 &&
stat_buf.st_atime <= stat_buf.st_mtime);
case 'f': /* File is a file? */
if (sh_stat (arg, &stat_buf) < 0)
return (FALSE);
/* -f is true if the given file exists and is a regular file. */
#if defined (S_IFMT)
return (S_ISREG (stat_buf.st_mode) || (stat_buf.st_mode & S_IFMT) == 0);
#else
return (S_ISREG (stat_buf.st_mode));
#endif /* !S_IFMT */
case 'd': /* File is a directory? */
return (sh_stat (arg, &stat_buf) == 0 && (S_ISDIR (stat_buf.st_mode)));
case 's': /* File has something in it? */
return (sh_stat (arg, &stat_buf) == 0 && stat_buf.st_size > (off_t) 0);
case 'S': /* File is a socket? */
#if !defined (S_ISSOCK)
return (FALSE);
#else
return (sh_stat (arg, &stat_buf) == 0 && S_ISSOCK (stat_buf.st_mode));
#endif /* S_ISSOCK */
case 'c': /* File is character special? */
return (sh_stat (arg, &stat_buf) == 0 && S_ISCHR (stat_buf.st_mode));
case 'b': /* File is block special? */
return (sh_stat (arg, &stat_buf) == 0 && S_ISBLK (stat_buf.st_mode));
case 'p': /* File is a named pipe? */
#ifndef S_ISFIFO
return (FALSE);
#else
return (sh_stat (arg, &stat_buf) == 0 && S_ISFIFO (stat_buf.st_mode));
#endif /* S_ISFIFO */
case 'L': /* Same as -h */
case 'h': /* File is a symbolic link? */
#if !defined (S_ISLNK) || !defined (HAVE_LSTAT)
return (FALSE);
#else
return ((arg[0] != '\0') &&
(lstat (arg, &stat_buf) == 0) && S_ISLNK (stat_buf.st_mode));
#endif /* S_IFLNK && HAVE_LSTAT */
case 'u': /* File is setuid? */
return (sh_stat (arg, &stat_buf) == 0 && (stat_buf.st_mode & S_ISUID) != 0);
case 'g': /* File is setgid? */
return (sh_stat (arg, &stat_buf) == 0 && (stat_buf.st_mode & S_ISGID) != 0);
case 'k': /* File has sticky bit set? */
#if !defined (S_ISVTX)
/* This is not Posix, and is not defined on some Posix systems. */
return (FALSE);
#else
return (sh_stat (arg, &stat_buf) == 0 && (stat_buf.st_mode & S_ISVTX) != 0);
#endif
case 't': /* File fd is a terminal? */
if (legal_number (arg, &r) == 0)
return (FALSE);
return ((r == (int)r) && isatty ((int)r));
case 'n': /* True if arg has some length. */
return (arg[0] != '\0');
case 'z': /* True if arg has no length. */
return (arg[0] == '\0');
case 'o': /* True if option `arg' is set. */
return (minus_o_option_value (arg) == 1);
case 'v':
v = find_variable (arg);
#if defined (ARRAY_VARS)
if (v == 0 && valid_array_reference (arg))
{
char *t;
t = array_value (arg, 0, 0, (int *)0, (arrayind_t *)0);
return (t ? TRUE : FALSE);
}
else if (v && invisible_p (v) == 0 && array_p (v))
{
char *t;
/* [[ -v foo ]] == [[ -v foo[0] ]] */
t = array_reference (array_cell (v), 0);
return (t ? TRUE : FALSE);
}
else if (v && invisible_p (v) == 0 && assoc_p (v))
{
char *t;
t = assoc_reference (assoc_cell (v), "0");
return (t ? TRUE : FALSE);
}
#endif
return (v && invisible_p (v) == 0 && var_isset (v) ? TRUE : FALSE);
case 'R':
v = find_variable (arg);
return (v && invisible_p (v) == 0 && var_isset (v) && nameref_p (v) ? TRUE : FALSE);
}
/* We can't actually get here, but this shuts up gcc. */
return (FALSE);
}
/* Return TRUE if OP is one of the test command's binary operators. */
int
test_binop (op)
char *op;
{
if (op[0] == '=' && op[1] == '\0')
return (1); /* '=' */
else if ((op[0] == '<' || op[0] == '>') && op[1] == '\0') /* string <, > */
return (1);
else if ((op[0] == '=' || op[0] == '!') && op[1] == '=' && op[2] == '\0')
return (1); /* `==' and `!=' */
#if defined (PATTERN_MATCHING)
else if (op[2] == '\0' && op[1] == '~' && (op[0] == '=' || op[0] == '!'))
return (1);
#endif
else if (op[0] != '-' || op[2] == '\0' || op[3] != '\0')
return (0);
else
{
if (op[2] == 't')
switch (op[1])
{
case 'n': /* -nt */
case 'o': /* -ot */
case 'l': /* -lt */
case 'g': /* -gt */
return (1);
default:
return (0);
}
else if (op[1] == 'e')
switch (op[2])
{
case 'q': /* -eq */
case 'f': /* -ef */
return (1);
default:
return (0);
}
else if (op[2] == 'e')
switch (op[1])
{
case 'n': /* -ne */
case 'g': /* -ge */
case 'l': /* -le */
return (1);
default:
return (0);
}
else
return (0);
}
}
/* Return non-zero if OP is one of the test command's unary operators. */
int
test_unop (op)
char *op;
{
if (op[0] != '-' || op[2] != 0)
return (0);
switch (op[1])
{
case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f': case 'g': case 'h': case 'k': case 'n':
case 'o': case 'p': case 'r': case 's': case 't':
case 'u': case 'v': case 'w': case 'x': case 'z':
case 'G': case 'L': case 'O': case 'S': case 'N':
return (1);
}
return (0);
}
static int
two_arguments ()
{
if (argv[pos][0] == '!' && argv[pos][1] == '\0')
return (argv[pos + 1][0] == '\0');
else if (argv[pos][0] == '-' && argv[pos][2] == '\0')
{
if (test_unop (argv[pos]))
return (unary_operator ());
else
test_syntax_error (_("%s: unary operator expected"), argv[pos]);
}
else
test_syntax_error (_("%s: unary operator expected"), argv[pos]);
return (0);
}
#define ANDOR(s) (s[0] == '-' && !s[2] && (s[1] == 'a' || s[1] == 'o'))
/* This could be augmented to handle `-t' as equivalent to `-t 1', but
POSIX requires that `-t' be given an argument. */
#define ONE_ARG_TEST(s) ((s)[0] != '\0')
static int
three_arguments ()
{
int value;
if (test_binop (argv[pos+1]))
{
value = binary_operator ();
pos = argc;
}
else if (ANDOR (argv[pos+1]))
{
if (argv[pos+1][1] == 'a')
value = ONE_ARG_TEST(argv[pos]) && ONE_ARG_TEST(argv[pos+2]);
else
value = ONE_ARG_TEST(argv[pos]) || ONE_ARG_TEST(argv[pos+2]);
pos = argc;
}
else if (argv[pos][0] == '!' && argv[pos][1] == '\0')
{
advance (1);
value = !two_arguments ();
}
else if (argv[pos][0] == '(' && argv[pos+2][0] == ')')
{
value = ONE_ARG_TEST(argv[pos+1]);
pos = argc;
}
else
test_syntax_error (_("%s: binary operator expected"), argv[pos+1]);
return (value);
}
/* This is an implementation of a Posix.2 proposal by David Korn. */
static int
posixtest ()
{
int value;
switch (argc - 1) /* one extra passed in */
{
case 0:
value = FALSE;
pos = argc;
break;
case 1:
value = ONE_ARG_TEST(argv[1]);
pos = argc;
break;
case 2:
value = two_arguments ();
pos = argc;
break;
case 3:
value = three_arguments ();
break;
case 4:
if (argv[pos][0] == '!' && argv[pos][1] == '\0')
{
advance (1);
value = !three_arguments ();
break;
}
/* FALLTHROUGH */
default:
value = expr ();
}
return (value);
}
/*
* [:
* '[' expr ']'
* test:
* test expr
*/
int
test_command (margc, margv)
int margc;
char **margv;
{
int value;
int code;
USE_VAR(margc);
code = setjmp_nosigs (test_exit_buf);
if (code)
return (test_error_return);
argv = margv;
if (margv[0] && margv[0][0] == '[' && margv[0][1] == '\0')
{
--margc;
if (margv[margc] && (margv[margc][0] != ']' || margv[margc][1]))
test_syntax_error (_("missing `]'"), (char *)NULL);
if (margc < 2)
test_exit (SHELL_BOOLEAN (FALSE));
}
argc = margc;
pos = 1;
if (pos >= argc)
test_exit (SHELL_BOOLEAN (FALSE));
noeval = 0;
value = posixtest ();
if (pos != argc)
test_syntax_error (_("too many arguments"), (char *)NULL);
test_exit (SHELL_BOOLEAN (value));
}
bash-4.3/execute_cmd.h 0000644 0001750 0000144 00000004675 11134175017 013622 0 ustar doko users /* execute_cmd.h - functions from execute_cmd.c. */
/* Copyright (C) 1993-2009 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 3 of the License, 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. If not, see .
*/
#if !defined (_EXECUTE_CMD_H_)
#define _EXECUTE_CMD_H_
#include "stdc.h"
extern struct fd_bitmap *new_fd_bitmap __P((int));
extern void dispose_fd_bitmap __P((struct fd_bitmap *));
extern void close_fd_bitmap __P((struct fd_bitmap *));
extern int executing_line_number __P((void));
extern int execute_command __P((COMMAND *));
extern int execute_command_internal __P((COMMAND *, int, int, int, struct fd_bitmap *));
extern int shell_execve __P((char *, char **, char **));
extern void setup_async_signals __P((void));
extern void dispose_exec_redirects __P ((void));
extern int execute_shell_function __P((SHELL_VAR *, WORD_LIST *));
extern struct coproc *getcoprocbypid __P((pid_t));
extern struct coproc *getcoprocbyname __P((const char *));
extern void coproc_init __P((struct coproc *));
extern struct coproc *coproc_alloc __P((char *, pid_t));
extern void coproc_dispose __P((struct coproc *));
extern void coproc_flush __P((void));
extern void coproc_close __P((struct coproc *));
extern void coproc_closeall __P((void));
extern void coproc_reap __P((void));
extern void coproc_rclose __P((struct coproc *, int));
extern void coproc_wclose __P((struct coproc *, int));
extern void coproc_fdclose __P((struct coproc *, int));
extern void coproc_checkfd __P((struct coproc *, int));
extern void coproc_fdchk __P((int));
extern void coproc_pidchk __P((pid_t, int));
extern void coproc_fdsave __P((struct coproc *));
extern void coproc_fdrestore __P((struct coproc *));
extern void coproc_setvars __P((struct coproc *));
extern void coproc_unsetvars __P((struct coproc *));
#if defined (PROCESS_SUBSTITUTION)
extern void close_all_files __P((void));
#endif
#endif /* _EXECUTE_CMD_H_ */
bash-4.3/make_cmd.c 0000644 0001750 0000144 00000054332 11672641261 013071 0 ustar doko users /* make_cmd.c -- Functions for making instances of the various
parser constructs. */
/* Copyright (C) 1989-2009 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 3 of the License, 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. If not, see .
*/
#include "config.h"
#include
#include "bashtypes.h"
#if !defined (_MINIX) && defined (HAVE_SYS_FILE_H)
# include
#endif
#include "filecntl.h"
#include "bashansi.h"
#if defined (HAVE_UNISTD_H)
# include
#endif
#include "bashintl.h"
#include "parser.h"
#include "syntax.h"
#include "command.h"
#include "general.h"
#include "error.h"
#include "flags.h"
#include "make_cmd.h"
#include "dispose_cmd.h"
#include "variables.h"
#include "subst.h"
#include "input.h"
#include "ocache.h"
#include "externs.h"
#if defined (JOB_CONTROL)
#include "jobs.h"
#endif
#include "shmbutil.h"
extern int line_number, current_command_line_count, parser_state;
extern int last_command_exit_value;
/* Object caching */
sh_obj_cache_t wdcache = {0, 0, 0};
sh_obj_cache_t wlcache = {0, 0, 0};
#define WDCACHESIZE 60
#define WLCACHESIZE 60
static COMMAND *make_for_or_select __P((enum command_type, WORD_DESC *, WORD_LIST *, COMMAND *, int));
#if defined (ARITH_FOR_COMMAND)
static WORD_LIST *make_arith_for_expr __P((char *));
#endif
static COMMAND *make_until_or_while __P((enum command_type, COMMAND *, COMMAND *));
void
cmd_init ()
{
ocache_create (wdcache, WORD_DESC, WDCACHESIZE);
ocache_create (wlcache, WORD_LIST, WLCACHESIZE);
}
WORD_DESC *
alloc_word_desc ()
{
WORD_DESC *temp;
ocache_alloc (wdcache, WORD_DESC, temp);
temp->flags = 0;
temp->word = 0;
return temp;
}
WORD_DESC *
make_bare_word (string)
const char *string;
{
WORD_DESC *temp;
temp = alloc_word_desc ();
if (*string)
temp->word = savestring (string);
else
{
temp->word = (char *)xmalloc (1);
temp->word[0] = '\0';
}
return (temp);
}
WORD_DESC *
make_word_flags (w, string)
WORD_DESC *w;
const char *string;
{
register int i;
size_t slen;
DECLARE_MBSTATE;
i = 0;
slen = strlen (string);
while (i < slen)
{
switch (string[i])
{
case '$':
w->flags |= W_HASDOLLAR;
break;
case '\\':
break; /* continue the loop */
case '\'':
case '`':
case '"':
w->flags |= W_QUOTED;
break;
}
ADVANCE_CHAR (string, slen, i);
}
return (w);
}
WORD_DESC *
make_word (string)
const char *string;
{
WORD_DESC *temp;
temp = make_bare_word (string);
return (make_word_flags (temp, string));
}
WORD_DESC *
make_word_from_token (token)
int token;
{
char tokenizer[2];
tokenizer[0] = token;
tokenizer[1] = '\0';
return (make_word (tokenizer));
}
WORD_LIST *
make_word_list (word, wlink)
WORD_DESC *word;
WORD_LIST *wlink;
{
WORD_LIST *temp;
ocache_alloc (wlcache, WORD_LIST, temp);
temp->word = word;
temp->next = wlink;
return (temp);
}
COMMAND *
make_command (type, pointer)
enum command_type type;
SIMPLE_COM *pointer;
{
COMMAND *temp;
temp = (COMMAND *)xmalloc (sizeof (COMMAND));
temp->type = type;
temp->value.Simple = pointer;
temp->value.Simple->flags = temp->flags = 0;
temp->redirects = (REDIRECT *)NULL;
return (temp);
}
COMMAND *
command_connect (com1, com2, connector)
COMMAND *com1, *com2;
int connector;
{
CONNECTION *temp;
temp = (CONNECTION *)xmalloc (sizeof (CONNECTION));
temp->connector = connector;
temp->first = com1;
temp->second = com2;
return (make_command (cm_connection, (SIMPLE_COM *)temp));
}
static COMMAND *
make_for_or_select (type, name, map_list, action, lineno)
enum command_type type;
WORD_DESC *name;
WORD_LIST *map_list;
COMMAND *action;
int lineno;
{
FOR_COM *temp;
temp = (FOR_COM *)xmalloc (sizeof (FOR_COM));
temp->flags = 0;
temp->name = name;
temp->line = lineno;
temp->map_list = map_list;
temp->action = action;
return (make_command (type, (SIMPLE_COM *)temp));
}
COMMAND *
make_for_command (name, map_list, action, lineno)
WORD_DESC *name;
WORD_LIST *map_list;
COMMAND *action;
int lineno;
{
return (make_for_or_select (cm_for, name, map_list, action, lineno));
}
COMMAND *
make_select_command (name, map_list, action, lineno)
WORD_DESC *name;
WORD_LIST *map_list;
COMMAND *action;
int lineno;
{
#if defined (SELECT_COMMAND)
return (make_for_or_select (cm_select, name, map_list, action, lineno));
#else
last_command_exit_value = 2;
return ((COMMAND *)NULL);
#endif
}
#if defined (ARITH_FOR_COMMAND)
static WORD_LIST *
make_arith_for_expr (s)
char *s;
{
WORD_LIST *result;
WORD_DESC *wd;
if (s == 0 || *s == '\0')
return ((WORD_LIST *)NULL);
wd = make_word (s);
wd->flags |= W_NOGLOB|W_NOSPLIT|W_QUOTED|W_DQUOTE; /* no word splitting or globbing */
result = make_word_list (wd, (WORD_LIST *)NULL);
return result;
}
#endif
/* Note that this function calls dispose_words on EXPRS, since it doesn't
use the word list directly. We free it here rather than at the caller
because no other function in this file requires that the caller free
any arguments. */
COMMAND *
make_arith_for_command (exprs, action, lineno)
WORD_LIST *exprs;
COMMAND *action;
int lineno;
{
#if defined (ARITH_FOR_COMMAND)
ARITH_FOR_COM *temp;
WORD_LIST *init, *test, *step;
char *s, *t, *start;
int nsemi, i;
init = test = step = (WORD_LIST *)NULL;
/* Parse the string into the three component sub-expressions. */
start = t = s = exprs->word->word;
for (nsemi = 0; ;)
{
/* skip whitespace at the start of each sub-expression. */
while (whitespace (*s))
s++;
start = s;
/* skip to the semicolon or EOS */
i = skip_to_delim (start, 0, ";", SD_NOJMP);
s = start + i;
t = (i > 0) ? substring (start, 0, i) : (char *)NULL;
nsemi++;
switch (nsemi)
{
case 1:
init = make_arith_for_expr (t);
break;
case 2:
test = make_arith_for_expr (t);
break;
case 3:
step = make_arith_for_expr (t);
break;
}
FREE (t);
if (*s == '\0')
break;
s++; /* skip over semicolon */
}
if (nsemi != 3)
{
if (nsemi < 3)
parser_error (lineno, _("syntax error: arithmetic expression required"));
else
parser_error (lineno, _("syntax error: `;' unexpected"));
parser_error (lineno, _("syntax error: `((%s))'"), exprs->word->word);
free (init);
free (test);
free (step);
last_command_exit_value = 2;
return ((COMMAND *)NULL);
}
temp = (ARITH_FOR_COM *)xmalloc (sizeof (ARITH_FOR_COM));
temp->flags = 0;
temp->line = lineno;
temp->init = init ? init : make_arith_for_expr ("1");
temp->test = test ? test : make_arith_for_expr ("1");
temp->step = step ? step : make_arith_for_expr ("1");
temp->action = action;
dispose_words (exprs);
return (make_command (cm_arith_for, (SIMPLE_COM *)temp));
#else
dispose_words (exprs);
last_command_exit_value = 2;
return ((COMMAND *)NULL);
#endif /* ARITH_FOR_COMMAND */
}
COMMAND *
make_group_command (command)
COMMAND *command;
{
GROUP_COM *temp;
temp = (GROUP_COM *)xmalloc (sizeof (GROUP_COM));
temp->command = command;
return (make_command (cm_group, (SIMPLE_COM *)temp));
}
COMMAND *
make_case_command (word, clauses, lineno)
WORD_DESC *word;
PATTERN_LIST *clauses;
int lineno;
{
CASE_COM *temp;
temp = (CASE_COM *)xmalloc (sizeof (CASE_COM));
temp->flags = 0;
temp->line = lineno;
temp->word = word;
temp->clauses = REVERSE_LIST (clauses, PATTERN_LIST *);
return (make_command (cm_case, (SIMPLE_COM *)temp));
}
PATTERN_LIST *
make_pattern_list (patterns, action)
WORD_LIST *patterns;
COMMAND *action;
{
PATTERN_LIST *temp;
temp = (PATTERN_LIST *)xmalloc (sizeof (PATTERN_LIST));
temp->patterns = REVERSE_LIST (patterns, WORD_LIST *);
temp->action = action;
temp->next = NULL;
temp->flags = 0;
return (temp);
}
COMMAND *
make_if_command (test, true_case, false_case)
COMMAND *test, *true_case, *false_case;
{
IF_COM *temp;
temp = (IF_COM *)xmalloc (sizeof (IF_COM));
temp->flags = 0;
temp->test = test;
temp->true_case = true_case;
temp->false_case = false_case;
return (make_command (cm_if, (SIMPLE_COM *)temp));
}
static COMMAND *
make_until_or_while (which, test, action)
enum command_type which;
COMMAND *test, *action;
{
WHILE_COM *temp;
temp = (WHILE_COM *)xmalloc (sizeof (WHILE_COM));
temp->flags = 0;
temp->test = test;
temp->action = action;
return (make_command (which, (SIMPLE_COM *)temp));
}
COMMAND *
make_while_command (test, action)
COMMAND *test, *action;
{
return (make_until_or_while (cm_while, test, action));
}
COMMAND *
make_until_command (test, action)
COMMAND *test, *action;
{
return (make_until_or_while (cm_until, test, action));
}
COMMAND *
make_arith_command (exp)
WORD_LIST *exp;
{
#if defined (DPAREN_ARITHMETIC)
COMMAND *command;
ARITH_COM *temp;
command = (COMMAND *)xmalloc (sizeof (COMMAND));
command->value.Arith = temp = (ARITH_COM *)xmalloc (sizeof (ARITH_COM));
temp->flags = 0;
temp->line = line_number;
temp->exp = exp;
command->type = cm_arith;
command->redirects = (REDIRECT *)NULL;
command->flags = 0;
return (command);
#else
last_command_exit_value = 2;
return ((COMMAND *)NULL);
#endif
}
#if defined (COND_COMMAND)
struct cond_com *
make_cond_node (type, op, left, right)
int type;
WORD_DESC *op;
struct cond_com *left, *right;
{
COND_COM *temp;
temp = (COND_COM *)xmalloc (sizeof (COND_COM));
temp->flags = 0;
temp->line = line_number;
temp->type = type;
temp->op = op;
temp->left = left;
temp->right = right;
return (temp);
}
#endif
COMMAND *
make_cond_command (cond_node)
COND_COM *cond_node;
{
#if defined (COND_COMMAND)
COMMAND *command;
command = (COMMAND *)xmalloc (sizeof (COMMAND));
command->value.Cond = cond_node;
command->type = cm_cond;
command->redirects = (REDIRECT *)NULL;
command->flags = 0;
command->line = cond_node ? cond_node->line : 0;
return (command);
#else
last_command_exit_value = 2;
return ((COMMAND *)NULL);
#endif
}
COMMAND *
make_bare_simple_command ()
{
COMMAND *command;
SIMPLE_COM *temp;
command = (COMMAND *)xmalloc (sizeof (COMMAND));
command->value.Simple = temp = (SIMPLE_COM *)xmalloc (sizeof (SIMPLE_COM));
temp->flags = 0;
temp->line = line_number;
temp->words = (WORD_LIST *)NULL;
temp->redirects = (REDIRECT *)NULL;
command->type = cm_simple;
command->redirects = (REDIRECT *)NULL;
command->flags = 0;
return (command);
}
/* Return a command which is the connection of the word or redirection
in ELEMENT, and the command * or NULL in COMMAND. */
COMMAND *
make_simple_command (element, command)
ELEMENT element;
COMMAND *command;
{
/* If we are starting from scratch, then make the initial command
structure. Also note that we have to fill in all the slots, since
malloc doesn't return zeroed space. */
if (command == 0)
{
command = make_bare_simple_command ();
parser_state |= PST_REDIRLIST;
}
if (element.word)
{
command->value.Simple->words = make_word_list (element.word, command->value.Simple->words);
parser_state &= ~PST_REDIRLIST;
}
else if (element.redirect)
{
REDIRECT *r = element.redirect;
/* Due to the way <> is implemented, there may be more than a single
redirection in element.redirect. We just follow the chain as far
as it goes, and hook onto the end. */
while (r->next)
r = r->next;
r->next = command->value.Simple->redirects;
command->value.Simple->redirects = element.redirect;
}
return (command);
}
/* Because we are Bourne compatible, we read the input for this
<< or <<- redirection now, from wherever input is coming from.
We store the input read into a WORD_DESC. Replace the text of
the redirectee.word with the new input text. If <<- is on,
then remove leading TABS from each line. */
void
make_here_document (temp, lineno)
REDIRECT *temp;
int lineno;
{
int kill_leading, redir_len;
char *redir_word, *document, *full_line;
int document_index, document_size, delim_unquoted;
if (temp->instruction != r_deblank_reading_until &&
temp->instruction != r_reading_until)
{
internal_error (_("make_here_document: bad instruction type %d"), temp->instruction);
return;
}
kill_leading = temp->instruction == r_deblank_reading_until;
document = (char *)NULL;
document_index = document_size = 0;
/* Quote removal is the only expansion performed on the delimiter
for here documents, making it an extremely special case. */
redir_word = string_quote_removal (temp->redirectee.filename->word, 0);
/* redirection_expand will return NULL if the expansion results in
multiple words or no words. Check for that here, and just abort
this here document if it does. */
if (redir_word)
redir_len = strlen (redir_word);
else
{
temp->here_doc_eof = (char *)xmalloc (1);
temp->here_doc_eof[0] = '\0';
goto document_done;
}
free (temp->redirectee.filename->word);
temp->here_doc_eof = redir_word;
/* Read lines from wherever lines are coming from.
For each line read, if kill_leading, then kill the
leading tab characters.
If the line matches redir_word exactly, then we have
manufactured the document. Otherwise, add the line to the
list of lines in the document. */
/* If the here-document delimiter was quoted, the lines should
be read verbatim from the input. If it was not quoted, we
need to perform backslash-quoted newline removal. */
delim_unquoted = (temp->redirectee.filename->flags & W_QUOTED) == 0;
while (full_line = read_secondary_line (delim_unquoted))
{
register char *line;
int len;
line = full_line;
line_number++;
/* If set -v is in effect, echo the line read. read_secondary_line/
read_a_line leaves the newline at the end, so don't print another. */
if (echo_input_at_read)
fprintf (stderr, "%s", line);
if (kill_leading && *line)
{
/* Hack: To be compatible with some Bourne shells, we
check the word before stripping the whitespace. This
is a hack, though. */
if (STREQN (line, redir_word, redir_len) && line[redir_len] == '\n')
goto document_done;
while (*line == '\t')
line++;
}
if (*line == 0)
continue;
if (STREQN (line, redir_word, redir_len) && line[redir_len] == '\n')
goto document_done;
len = strlen (line);
if (len + document_index >= document_size)
{
document_size = document_size ? 2 * (document_size + len) : len + 2;
document = (char *)xrealloc (document, document_size);
}
/* len is guaranteed to be > 0 because of the check for line
being an empty string before the call to strlen. */
FASTCOPY (line, document + document_index, len);
document_index += len;
}
if (full_line == 0)
internal_warning (_("here-document at line %d delimited by end-of-file (wanted `%s')"), lineno, redir_word);
document_done:
if (document)
document[document_index] = '\0';
else
{
document = (char *)xmalloc (1);
document[0] = '\0';
}
temp->redirectee.filename->word = document;
}
/* Generate a REDIRECT from SOURCE, DEST, and INSTRUCTION.
INSTRUCTION is the instruction type, SOURCE is a file descriptor,
and DEST is a file descriptor or a WORD_DESC *. */
REDIRECT *
make_redirection (source, instruction, dest_and_filename, flags)
REDIRECTEE source;
enum r_instruction instruction;
REDIRECTEE dest_and_filename;
int flags;
{
REDIRECT *temp;
WORD_DESC *w;
int wlen;
intmax_t lfd;
temp = (REDIRECT *)xmalloc (sizeof (REDIRECT));
/* First do the common cases. */
temp->redirector = source;
temp->redirectee = dest_and_filename;
temp->instruction = instruction;
temp->flags = 0;
temp->rflags = flags;
temp->next = (REDIRECT *)NULL;
switch (instruction)
{
case r_output_direction: /* >foo */
case r_output_force: /* >| foo */
case r_err_and_out: /* &>filename */
temp->flags = O_TRUNC | O_WRONLY | O_CREAT;
break;
case r_appending_to: /* >>foo */
case r_append_err_and_out: /* &>> filename */
temp->flags = O_APPEND | O_WRONLY | O_CREAT;
break;
case r_input_direction: /* flags = O_RDONLY;
break;
case r_input_output: /* <>foo */
temp->flags = O_RDWR | O_CREAT;
break;
case r_deblank_reading_until: /* <<-foo */
case r_reading_until: /* << foo */
case r_reading_string: /* <<< foo */
case r_close_this: /* <&- */
case r_duplicating_input: /* 1<&2 */
case r_duplicating_output: /* 1>&2 */
break;
/* the parser doesn't pass these. */
case r_move_input: /* 1<&2- */
case r_move_output: /* 1>&2- */
case r_move_input_word: /* 1<&$foo- */
case r_move_output_word: /* 1>&$foo- */
break;
/* The way the lexer works we have to do this here. */
case r_duplicating_input_word: /* 1<&$foo */
case r_duplicating_output_word: /* 1>&$foo */
w = dest_and_filename.filename;
wlen = strlen (w->word) - 1;
if (w->word[wlen] == '-') /* Yuck */
{
w->word[wlen] = '\0';
if (all_digits (w->word) && legal_number (w->word, &lfd) && lfd == (int)lfd)
{
dispose_word (w);
temp->instruction = (instruction == r_duplicating_input_word) ? r_move_input : r_move_output;
temp->redirectee.dest = lfd;
}
else
temp->instruction = (instruction == r_duplicating_input_word) ? r_move_input_word : r_move_output_word;
}
break;
default:
programming_error (_("make_redirection: redirection instruction `%d' out of range"), instruction);
abort ();
break;
}
return (temp);
}
COMMAND *
make_function_def (name, command, lineno, lstart)
WORD_DESC *name;
COMMAND *command;
int lineno, lstart;
{
FUNCTION_DEF *temp;
#if defined (ARRAY_VARS)
SHELL_VAR *bash_source_v;
ARRAY *bash_source_a;
#endif
temp = (FUNCTION_DEF *)xmalloc (sizeof (FUNCTION_DEF));
temp->command = command;
temp->name = name;
temp->line = lineno;
temp->flags = 0;
command->line = lstart;
/* Information used primarily for debugging. */
temp->source_file = 0;
#if defined (ARRAY_VARS)
GET_ARRAY_FROM_VAR ("BASH_SOURCE", bash_source_v, bash_source_a);
if (bash_source_a && array_num_elements (bash_source_a) > 0)
temp->source_file = array_reference (bash_source_a, 0);
#endif
#if defined (DEBUGGER)
bind_function_def (name->word, temp);
#endif
temp->source_file = temp->source_file ? savestring (temp->source_file) : 0;
return (make_command (cm_function_def, (SIMPLE_COM *)temp));
}
COMMAND *
make_subshell_command (command)
COMMAND *command;
{
SUBSHELL_COM *temp;
temp = (SUBSHELL_COM *)xmalloc (sizeof (SUBSHELL_COM));
temp->command = command;
temp->flags = CMD_WANT_SUBSHELL;
return (make_command (cm_subshell, (SIMPLE_COM *)temp));
}
COMMAND *
make_coproc_command (name, command)
char *name;
COMMAND *command;
{
COPROC_COM *temp;
temp = (COPROC_COM *)xmalloc (sizeof (COPROC_COM));
temp->name = savestring (name);
temp->command = command;
temp->flags = CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;
return (make_command (cm_coproc, (SIMPLE_COM *)temp));
}
/* Reverse the word list and redirection list in the simple command
has just been parsed. It seems simpler to do this here the one
time then by any other method that I can think of. */
COMMAND *
clean_simple_command (command)
COMMAND *command;
{
if (command->type != cm_simple)
command_error ("clean_simple_command", CMDERR_BADTYPE, command->type, 0);
else
{
command->value.Simple->words =
REVERSE_LIST (command->value.Simple->words, WORD_LIST *);
command->value.Simple->redirects =
REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
}
parser_state &= ~PST_REDIRLIST;
return (command);
}
/* The Yacc grammar productions have a problem, in that they take a
list followed by an ampersand (`&') and do a simple command connection,
making the entire list effectively asynchronous, instead of just
the last command. This means that when the list is executed, all
the commands have stdin set to /dev/null when job control is not
active, instead of just the last. This is wrong, and needs fixing
up. This function takes the `&' and applies it to the last command
in the list. This is done only for lists connected by `;'; it makes
`;' bind `tighter' than `&'. */
COMMAND *
connect_async_list (command, command2, connector)
COMMAND *command, *command2;
int connector;
{
COMMAND *t, *t1, *t2;
t1 = command;
t = command->value.Connection->second;
if (!t || (command->flags & CMD_WANT_SUBSHELL) ||
command->value.Connection->connector != ';')
{
t = command_connect (command, command2, connector);
return t;
}
/* This is just defensive programming. The Yacc precedence rules
will generally hand this function a command where t points directly
to the command we want (e.g. given a ; b ; c ; d &, t1 will point
to the `a ; b ; c' list and t will be the `d'). We only want to do
this if the list is not being executed as a unit in the background
with `( ... )', so we have to check for CMD_WANT_SUBSHELL. That's
the only way to tell. */
while (((t->flags & CMD_WANT_SUBSHELL) == 0) && t->type == cm_connection &&
t->value.Connection->connector == ';')
{
t1 = t;
t = t->value.Connection->second;
}
/* Now we have t pointing to the last command in the list, and
t1->value.Connection->second == t. */
t2 = command_connect (t, command2, connector);
t1->value.Connection->second = t2;
return command;
}
bash-4.3/arrayfunc.h 0000644 0001750 0000144 00000005517 11753201115 013317 0 ustar doko users /* arrayfunc.h -- declarations for miscellaneous array functions in arrayfunc.c */
/* Copyright (C) 2001-2010 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 3 of the License, 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. If not, see .
*/
#if !defined (_ARRAYFUNC_H_)
#define _ARRAYFUNC_H_
/* Must include variables.h before including this file. */
#if defined (ARRAY_VARS)
/* Flags for array_value_internal and callers array_value/get_array_value */
#define AV_ALLOWALL 0x001
#define AV_QUOTED 0x002
#define AV_USEIND 0x004
extern SHELL_VAR *convert_var_to_array __P((SHELL_VAR *));
extern SHELL_VAR *convert_var_to_assoc __P((SHELL_VAR *));
extern char *make_array_variable_value __P((SHELL_VAR *, arrayind_t, char *, char *, int));
extern SHELL_VAR *bind_array_variable __P((char *, arrayind_t, char *, int));
extern SHELL_VAR *bind_array_element __P((SHELL_VAR *, arrayind_t, char *, int));
extern SHELL_VAR *assign_array_element __P((char *, char *, int));
extern SHELL_VAR *bind_assoc_variable __P((SHELL_VAR *, char *, char *, char *, int));
extern SHELL_VAR *find_or_make_array_variable __P((char *, int));
extern SHELL_VAR *assign_array_from_string __P((char *, char *, int));
extern SHELL_VAR *assign_array_var_from_word_list __P((SHELL_VAR *, WORD_LIST *, int));
extern WORD_LIST *expand_compound_array_assignment __P((SHELL_VAR *, char *, int));
extern void assign_compound_array_list __P((SHELL_VAR *, WORD_LIST *, int));
extern SHELL_VAR *assign_array_var_from_string __P((SHELL_VAR *, char *, int));
extern int unbind_array_element __P((SHELL_VAR *, char *));
extern int skipsubscript __P((const char *, int, int));
extern void print_array_assignment __P((SHELL_VAR *, int));
extern void print_assoc_assignment __P((SHELL_VAR *, int));
extern arrayind_t array_expand_index __P((SHELL_VAR *, char *, int));
extern int valid_array_reference __P((char *));
extern char *array_value __P((char *, int, int, int *, arrayind_t *));
extern char *get_array_value __P((char *, int, int *, arrayind_t *));
extern char *array_keys __P((char *, int));
extern char *array_variable_name __P((char *, char **, int *));
extern SHELL_VAR *array_variable_part __P((char *, char **, int *));
#else
#define AV_ALLOWALL 0
#define AV_QUOTED 0
#define AV_USEIND 0
#endif
#endif /* !_ARRAYFUNC_H_ */
bash-4.3/version.c 0000644 0001750 0000144 00000005563 12117140315 013005 0 ustar doko users /* version.c -- distribution and version numbers. */
/* Copyright (C) 1989-2013 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 3 of the License, 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. If not, see .
*/
#include
#include
#include "stdc.h"
#include "version.h"
#include "patchlevel.h"
#include "conftypes.h"
#include "bashintl.h"
extern char *shell_name;
/* Defines from version.h */
const char * const dist_version = DISTVERSION;
const int patch_level = PATCHLEVEL;
const int build_version = BUILDVERSION;
#ifdef RELSTATUS
const char * const release_status = RELSTATUS;
#else
const char * const release_status = (char *)0;
#endif
const char * const sccs_version = SCCSVERSION;
const char * const bash_copyright = N_("Copyright (C) 2013 Free Software Foundation, Inc.");
const char * const bash_license = N_("License GPLv3+: GNU GPL version 3 or later \n");
/* If == 31, shell compatible with bash-3.1, == 32 with bash-3.2, and so on */
int shell_compatibility_level = DEFAULT_COMPAT_LEVEL;
/* Functions for getting, setting, and displaying the shell version. */
/* Forward declarations so we don't have to include externs.h */
extern char *shell_version_string __P((void));
extern void show_shell_version __P((int));
/* Give version information about this shell. */
char *
shell_version_string ()
{
static char tt[32] = { '\0' };
if (tt[0] == '\0')
{
if (release_status)
#if defined (HAVE_SNPRINTF)
snprintf (tt, sizeof (tt), "%s.%d(%d)-%s", dist_version, patch_level, build_version, release_status);
#else
sprintf (tt, "%s.%d(%d)-%s", dist_version, patch_level, build_version, release_status);
#endif
else
#if defined (HAVE_SNPRINTF)
snprintf (tt, sizeof (tt), "%s.%d(%d)", dist_version, patch_level, build_version);
#else
sprintf (tt, "%s.%d(%d)", dist_version, patch_level, build_version);
#endif
}
return tt;
}
void
show_shell_version (extended)
int extended;
{
printf (_("GNU bash, version %s (%s)\n"), shell_version_string (), MACHTYPE);
if (extended)
{
printf ("%s\n", _(bash_copyright));
printf ("%s\n", _(bash_license));
printf ("%s\n", _("This is free software; you are free to change and redistribute it."));
printf ("%s\n", _("There is NO WARRANTY, to the extent permitted by law."));
}
}
bash-4.3/mksyntax.c 0000644 0001750 0000144 00000016316 12005345726 013205 0 ustar doko users /*
* mksyntax.c - construct shell syntax table for fast char attribute lookup.
*/
/* Copyright (C) 2000-2009 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 3 of the License, 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. If not, see .
*/
#include "config.h"
#include
#include "bashansi.h"
#include "chartypes.h"
#include
#ifdef HAVE_UNISTD_H
# include
#endif
#include "syntax.h"
extern int optind;
extern char *optarg;
#ifndef errno
extern int errno;
#endif
#ifndef HAVE_STRERROR
extern char *strerror();
#endif
struct wordflag {
int flag;
char *fstr;
} wordflags[] = {
{ CWORD, "CWORD" },
{ CSHMETA, "CSHMETA" },
{ CSHBRK, "CSHBRK" },
{ CBACKQ, "CBACKQ" },
{ CQUOTE, "CQUOTE" },
{ CSPECL, "CSPECL" },
{ CEXP, "CEXP" },
{ CBSDQUOTE, "CBSDQUOTE" },
{ CBSHDOC, "CBSHDOC" },
{ CGLOB, "CGLOB" },
{ CXGLOB, "CXGLOB" },
{ CXQUOTE, "CXQUOTE" },
{ CSPECVAR, "CSPECVAR" },
{ CSUBSTOP, "CSUBSTOP" },
{ CBLANK, "CBLANK" },
};
#define N_WFLAGS (sizeof (wordflags) / sizeof (wordflags[0]))
#define SYNSIZE 256
int lsyntax[SYNSIZE];
int debug;
char *progname;
char preamble[] = "\
/*\n\
* This file was generated by mksyntax. DO NOT EDIT.\n\
*/\n\
\n";
char includes[] = "\
#include \"config.h\"\n\
#include \"stdc.h\"\n\
#include \"syntax.h\"\n\n";
static void
usage()
{
fprintf (stderr, "%s: usage: %s [-d] [-o filename]\n", progname, progname);
exit (2);
}
#ifdef INCLUDE_UNUSED
static int
getcflag (s)
char *s;
{
int i;
for (i = 0; i < N_WFLAGS; i++)
if (strcmp (s, wordflags[i].fstr) == 0)
return wordflags[i].flag;
return -1;
}
#endif
static char *
cdesc (i)
int i;
{
static char xbuf[16];
if (i == ' ')
return "SPC";
else if (ISPRINT (i))
{
xbuf[0] = i;
xbuf[1] = '\0';
return (xbuf);
}
else if (i == CTLESC)
return "CTLESC";
else if (i == CTLNUL)
return "CTLNUL";
else if (i == '\033') /* ASCII */
return "ESC";
xbuf[0] = '\\';
xbuf[2] = '\0';
switch (i)
{
#ifdef __STDC__
case '\a': xbuf[1] = 'a'; break;
case '\v': xbuf[1] = 'v'; break;
#else
case '\007': xbuf[1] = 'a'; break;
case 0x0B: xbuf[1] = 'v'; break;
#endif
case '\b': xbuf[1] = 'b'; break;
case '\f': xbuf[1] = 'f'; break;
case '\n': xbuf[1] = 'n'; break;
case '\r': xbuf[1] = 'r'; break;
case '\t': xbuf[1] = 't'; break;
default: sprintf (xbuf, "%d", i); break;
}
return xbuf;
}
static char *
getcstr (f)
int f;
{
int i;
for (i = 0; i < N_WFLAGS; i++)
if (f == wordflags[i].flag)
return (wordflags[i].fstr);
return ((char *)NULL);
}
static void
addcstr (str, flag)
char *str;
int flag;
{
char *s, *fstr;
unsigned char uc;
for (s = str; s && *s; s++)
{
uc = *s;
if (debug)
{
fstr = getcstr (flag);
fprintf(stderr, "added %s for character %s\n", fstr, cdesc(uc));
}
lsyntax[uc] |= flag;
}
}
static void
addcchar (c, flag)
unsigned char c;
int flag;
{
char *fstr;
if (debug)
{
fstr = getcstr (flag);
fprintf (stderr, "added %s for character %s\n", fstr, cdesc(c));
}
lsyntax[c] |= flag;
}
static void
addblanks ()
{
register int i;
unsigned char uc;
for (i = 0; i < SYNSIZE; i++)
{
uc = i;
/* Since we don't call setlocale(), this defaults to the "C" locale, and
the default blank characters will be space and tab. */
if (isblank (uc))
lsyntax[uc] |= CBLANK;
}
}
/* load up the correct flag values in lsyntax */
static void
load_lsyntax ()
{
/* shell metacharacters */
addcstr (shell_meta_chars, CSHMETA);
/* shell word break characters */
addcstr (shell_break_chars, CSHBRK);
addcchar ('`', CBACKQ);
addcstr (shell_quote_chars, CQUOTE);
addcchar (CTLESC, CSPECL);
addcchar (CTLNUL, CSPECL);
addcstr (shell_exp_chars, CEXP);
addcstr (slashify_in_quotes, CBSDQUOTE);
addcstr (slashify_in_here_document, CBSHDOC);
addcstr (shell_glob_chars, CGLOB);
#if defined (EXTENDED_GLOB)
addcstr (ext_glob_chars, CXGLOB);
#endif
addcstr (shell_quote_chars, CXQUOTE);
addcchar ('\\', CXQUOTE);
addcstr ("@*#?-$!", CSPECVAR); /* omits $0...$9 and $_ */
addcstr ("-=?+", CSUBSTOP); /* OP in ${paramOPword} */
addblanks ();
}
static void
dump_lflags (fp, ind)
FILE *fp;
int ind;
{
int xflags, first, i;
xflags = lsyntax[ind];
first = 1;
if (xflags == 0)
fputs (wordflags[0].fstr, fp);
else
{
for (i = 1; i < N_WFLAGS; i++)
if (xflags & wordflags[i].flag)
{
if (first)
first = 0;
else
putc ('|', fp);
fputs (wordflags[i].fstr, fp);
}
}
}
static void
wcomment (fp, i)
FILE *fp;
int i;
{
fputs ("\t\t/* ", fp);
fprintf (fp, "%s", cdesc(i));
fputs (" */", fp);
}
static void
dump_lsyntax (fp)
FILE *fp;
{
int i;
fprintf (fp, "int sh_syntabsiz = %d;\n", SYNSIZE);
fprintf (fp, "int sh_syntaxtab[%d] = {\n", SYNSIZE);
for (i = 0; i < SYNSIZE; i++)
{
putc ('\t', fp);
dump_lflags (fp, i);
putc (',', fp);
wcomment (fp, i);
putc ('\n', fp);
}
fprintf (fp, "};\n");
}
int
main(argc, argv)
int argc;
char **argv;
{
int opt, i;
char *filename;
FILE *fp;
if ((progname = strrchr (argv[0], '/')) == 0)
progname = argv[0];
else
progname++;
filename = (char *)NULL;
debug = 0;
while ((opt = getopt (argc, argv, "do:")) != EOF)
{
switch (opt)
{
case 'd':
debug = 1;
break;
case 'o':
filename = optarg;
break;
default:
usage();
}
}
argc -= optind;
argv += optind;
if (filename)
{
fp = fopen (filename, "w");
if (fp == 0)
{
fprintf (stderr, "%s: %s: cannot open: %s\n", progname, filename, strerror(errno));
exit (1);
}
}
else
{
filename = "stdout";
fp = stdout;
}
for (i = 0; i < SYNSIZE; i++)
lsyntax[i] = CWORD;
load_lsyntax ();
fprintf (fp, "%s\n", preamble);
fprintf (fp, "%s\n", includes);
dump_lsyntax (fp);
if (fp != stdout)
fclose (fp);
exit (0);
}
#if !defined (HAVE_STRERROR)
#include
#if defined (HAVE_SYS_PARAM_H)
# include
#endif
#if defined (HAVE_UNISTD_H)
# include
#endif
/* Return a string corresponding to the error number E. From
the ANSI C spec. */
#if defined (strerror)
# undef strerror
#endif
char *
strerror (e)
int e;
{
static char emsg[40];
#if defined (HAVE_SYS_ERRLIST)
extern int sys_nerr;
extern char *sys_errlist[];
if (e > 0 && e < sys_nerr)
return (sys_errlist[e]);
else
#endif /* HAVE_SYS_ERRLIST */
{
sprintf (emsg, "Unknown system error %d", e);
return (&emsg[0]);
}
}
#endif /* HAVE_STRERROR */
bash-4.3/m4/ 0000755 0001750 0000144 00000000000 12303125031 011456 5 ustar doko users bash-4.3/m4/stat-time.m4 0000644 0001750 0000144 00000004316 11725661744 013662 0 ustar doko users # Checks for stat-related time functions.
# Copyright (C) 1998-1999, 2001, 2003, 2005-2007, 2009-2012 Free Software
# Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
dnl From Paul Eggert.
dnl Modified by Chet Ramey for bash.
# st_atim.tv_nsec - Linux, Solaris, Cygwin
# st_atimespec.tv_nsec - FreeBSD, NetBSD, if ! defined _POSIX_SOURCE
# st_atimensec - FreeBSD, NetBSD, if defined _POSIX_SOURCE
# st_atim.st__tim.tv_nsec - UnixWare (at least 2.1.2 through 7.1)
# st_birthtimespec - FreeBSD, NetBSD (hidden on OpenBSD 3.9, anyway)
# st_birthtim - Cygwin 1.7.0+
AC_DEFUN([BASH_STAT_TIME],
[
AC_REQUIRE([AC_C_INLINE])
AC_CHECK_HEADERS_ONCE([sys/time.h])
AC_CHECK_MEMBERS([struct stat.st_atim.tv_nsec],
[AC_CACHE_CHECK([whether struct stat.st_atim is of type struct timespec],
[ac_cv_typeof_struct_stat_st_atim_is_struct_timespec],
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[
#include
#include
#if HAVE_SYS_TIME_H
# include
#endif
#include
struct timespec ts;
struct stat st;
]],
[[
st.st_atim = ts;
]])],
[ac_cv_typeof_struct_stat_st_atim_is_struct_timespec=yes],
[ac_cv_typeof_struct_stat_st_atim_is_struct_timespec=no])])
if test $ac_cv_typeof_struct_stat_st_atim_is_struct_timespec = yes; then
AC_DEFINE([TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC], [1],
[Define to 1 if the type of the st_atim member of a struct stat is
struct timespec.])
fi],
[AC_CHECK_MEMBERS([struct stat.st_atimespec.tv_nsec], [],
[AC_CHECK_MEMBERS([struct stat.st_atimensec], [],
[AC_CHECK_MEMBERS([struct stat.st_atim.st__tim.tv_nsec], [], [],
[#include
#include ])],
[#include
#include ])],
[#include
#include ])],
[#include
#include ])
])
bash-4.3/m4/timespec.m4 0000644 0001750 0000144 00000005152 11725667466 013572 0 ustar doko users # Configure checks for struct timespec
# Copyright (C) 2000-2001, 2003-2007, 2009-2011, 2012 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# Original written by Paul Eggert and Jim Meyering.
# Modified by Chet Ramey for bash
dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared
dnl in time.h, sys/time.h, or pthread.h.
AC_DEFUN([BASH_CHECK_TYPE_STRUCT_TIMESPEC],
[
AC_CHECK_HEADERS_ONCE([sys/time.h])
AC_CACHE_CHECK([for struct timespec in ],
[bash_cv_sys_struct_timespec_in_time_h],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#include
]],
[[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
[bash_cv_sys_struct_timespec_in_time_h=yes],
[bash_cv_sys_struct_timespec_in_time_h=no])])
HAVE_STRUCT_TIMESPEC=0
TIME_H_DEFINES_STRUCT_TIMESPEC=0
SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0
if test $bash_cv_sys_struct_timespec_in_time_h = yes; then
AC_DEFINE([HAVE_STRUCT_TIMESPEC])
AC_DEFINE([TIME_H_DEFINES_STRUCT_TIMESPEC])
TIME_H_DEFINES_STRUCT_TIMESPEC=1
else
AC_CACHE_CHECK([for struct timespec in ],
[bash_cv_sys_struct_timespec_in_sys_time_h],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#include
]],
[[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
[bash_cv_sys_struct_timespec_in_sys_time_h=yes],
[bash_cv_sys_struct_timespec_in_sys_time_h=no])])
if test $bash_cv_sys_struct_timespec_in_sys_time_h = yes; then
SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
AC_DEFINE([HAVE_STRUCT_TIMESPEC])
AC_DEFINE([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
else
AC_CACHE_CHECK([for struct timespec in ],
[bash_cv_sys_struct_timespec_in_pthread_h],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#include
]],
[[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
[bash_cv_sys_struct_timespec_in_pthread_h=yes],
[bash_cv_sys_struct_timespec_in_pthread_h=no])])
if test $bash_cv_sys_struct_timespec_in_pthread_h = yes; then
PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1
AC_DEFINE([HAVE_STRUCT_TIMESPEC])
AC_DEFINE([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
fi
fi
fi
AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
])
bash-4.3/array.h 0000644 0001750 0000144 00000007676 11163764635 012473 0 ustar doko users /* array.h -- definitions for the interface exported by array.c that allows
the rest of the shell to manipulate array variables. */
/* Copyright (C) 1997-2009 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 3 of the License, 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. If not, see .
*/
#ifndef _ARRAY_H_
#define _ARRAY_H_
#include "stdc.h"
typedef intmax_t arrayind_t;
enum atype {array_indexed, array_assoc};
typedef struct array {
enum atype type;
arrayind_t max_index;
int num_elements;
struct array_element *head;
} ARRAY;
typedef struct array_element {
arrayind_t ind;
char *value;
struct array_element *next, *prev;
} ARRAY_ELEMENT;
typedef int sh_ae_map_func_t __P((ARRAY_ELEMENT *, void *));
/* Basic operations on entire arrays */
extern ARRAY *array_create __P((void));
extern void array_flush __P((ARRAY *));
extern void array_dispose __P((ARRAY *));
extern ARRAY *array_copy __P((ARRAY *));
extern ARRAY *array_slice __P((ARRAY *, ARRAY_ELEMENT *, ARRAY_ELEMENT *));
extern void array_walk __P((ARRAY *, sh_ae_map_func_t *, void *));
extern ARRAY_ELEMENT *array_shift __P((ARRAY *, int, int));
extern int array_rshift __P((ARRAY *, int, char *));
extern ARRAY_ELEMENT *array_unshift_element __P((ARRAY *));
extern int array_shift_element __P((ARRAY *, char *));
extern ARRAY *array_quote __P((ARRAY *));
extern ARRAY *array_quote_escapes __P((ARRAY *));
extern ARRAY *array_dequote __P((ARRAY *));
extern ARRAY *array_dequote_escapes __P((ARRAY *));
extern ARRAY *array_remove_quoted_nulls __P((ARRAY *));
extern char *array_subrange __P((ARRAY *, arrayind_t, arrayind_t, int, int));
extern char *array_patsub __P((ARRAY *, char *, char *, int));
extern char *array_modcase __P((ARRAY *, char *, int, int));
/* Basic operations on array elements. */
extern ARRAY_ELEMENT *array_create_element __P((arrayind_t, char *));
extern ARRAY_ELEMENT *array_copy_element __P((ARRAY_ELEMENT *));
extern void array_dispose_element __P((ARRAY_ELEMENT *));
extern int array_insert __P((ARRAY *, arrayind_t, char *));
extern ARRAY_ELEMENT *array_remove __P((ARRAY *, arrayind_t));
extern char *array_reference __P((ARRAY *, arrayind_t));
/* Converting to and from arrays */
extern WORD_LIST *array_to_word_list __P((ARRAY *));
extern ARRAY *array_from_word_list __P((WORD_LIST *));
extern WORD_LIST *array_keys_to_word_list __P((ARRAY *));
extern ARRAY *array_assign_list __P((ARRAY *, WORD_LIST *));
extern char **array_to_argv __P((ARRAY *));
extern char *array_to_assign __P((ARRAY *, int));
extern char *array_to_string __P((ARRAY *, char *, int));
extern ARRAY *array_from_string __P((char *, char *));
/* Flags for array_shift */
#define AS_DISPOSE 0x01
#define array_num_elements(a) ((a)->num_elements)
#define array_max_index(a) ((a)->max_index)
#define array_head(a) ((a)->head)
#define array_empty(a) ((a)->num_elements == 0)
#define element_value(ae) ((ae)->value)
#define element_index(ae) ((ae)->ind)
#define element_forw(ae) ((ae)->next)
#define element_back(ae) ((ae)->prev)
/* Convenience */
#define array_push(a,v) \
do { array_rshift ((a), 1, (v)); } while (0)
#define array_pop(a) \
do { array_dispose_element (array_shift ((a), 1, 0)); } while (0)
#define GET_ARRAY_FROM_VAR(n, v, a) \
do { \
(v) = find_variable (n); \
(a) = ((v) && array_p ((v))) ? array_cell (v) : (ARRAY *)0; \
} while (0)
#define ALL_ELEMENT_SUB(c) ((c) == '@' || (c) == '*')
#endif /* _ARRAY_H_ */
bash-4.3/findcmd.c 0000644 0001750 0000144 00000042466 12036773500 012737 0 ustar doko users /* findcmd.c -- Functions to search for commands by name. */
/* Copyright (C) 1997-2012 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 3 of the License, 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. If not, see .
*/
#include "config.h"
#include
#include "chartypes.h"
#include "bashtypes.h"
#if !defined (_MINIX) && defined (HAVE_SYS_FILE_H)
# include
#endif
#include "filecntl.h"
#include "posixstat.h"
#if defined (HAVE_UNISTD_H)
# include
#endif
#include
#include "bashansi.h"
#include "memalloc.h"
#include "shell.h"
#include "flags.h"
#include "hashlib.h"
#include "pathexp.h"
#include "hashcmd.h"
#include "findcmd.h" /* matching prototypes and declarations */
#if !defined (errno)
extern int errno;
#endif
extern int posixly_correct;
extern int last_command_exit_value;
/* Static functions defined and used in this file. */
static char *_find_user_command_internal __P((const char *, int));
static char *find_user_command_internal __P((const char *, int));
static char *find_user_command_in_path __P((const char *, char *, int));
static char *find_in_path_element __P((const char *, char *, int, int, struct stat *));
static char *find_absolute_program __P((const char *, int));
static char *get_next_path_element __P((char *, int *));
/* The file name which we would try to execute, except that it isn't
possible to execute it. This is the first file that matches the
name that we are looking for while we are searching $PATH for a
suitable one to execute. If we cannot find a suitable executable
file, then we use this one. */
static char *file_to_lose_on;
/* Non-zero if we should stat every command found in the hash table to
make sure it still exists. */
int check_hashed_filenames;
/* DOT_FOUND_IN_SEARCH becomes non-zero when find_user_command ()
encounters a `.' as the directory pathname while scanning the
list of possible pathnames; i.e., if `.' comes before the directory
containing the file of interest. */
int dot_found_in_search = 0;
/* Return some flags based on information about this file.
The EXISTS bit is non-zero if the file is found.
The EXECABLE bit is non-zero the file is executble.
Zero is returned if the file is not found. */
int
file_status (name)
const char *name;
{
struct stat finfo;
int r;
/* Determine whether this file exists or not. */
if (stat (name, &finfo) < 0)
return (0);
/* If the file is a directory, then it is not "executable" in the
sense of the shell. */
if (S_ISDIR (finfo.st_mode))
return (FS_EXISTS|FS_DIRECTORY);
r = FS_EXISTS;
#if defined (HAVE_EACCESS)
/* Use eaccess(2) if we have it to take things like ACLs and other
file access mechanisms into account. eaccess uses the effective
user and group IDs, not the real ones. We could use sh_eaccess,
but we don't want any special treatment for /dev/fd. */
if (eaccess (name, X_OK) == 0)
r |= FS_EXECABLE;
if (eaccess (name, R_OK) == 0)
r |= FS_READABLE;
return r;
#elif defined (AFS)
/* We have to use access(2) to determine access because AFS does not
support Unix file system semantics. This may produce wrong
answers for non-AFS files when ruid != euid. I hate AFS. */
if (access (name, X_OK) == 0)
r |= FS_EXECABLE;
if (access (name, R_OK) == 0)
r |= FS_READABLE;
return r;
#else /* !HAVE_EACCESS && !AFS */
/* Find out if the file is actually executable. By definition, the
only other criteria is that the file has an execute bit set that
we can use. The same with whether or not a file is readable. */
/* Root only requires execute permission for any of owner, group or
others to be able to exec a file, and can read any file. */
if (current_user.euid == (uid_t)0)
{
r |= FS_READABLE;
if (finfo.st_mode & S_IXUGO)
r |= FS_EXECABLE;
return r;
}
/* If we are the owner of the file, the owner bits apply. */
if (current_user.euid == finfo.st_uid)
{
if (finfo.st_mode & S_IXUSR)
r |= FS_EXECABLE;
if (finfo.st_mode & S_IRUSR)
r |= FS_READABLE;
}
/* If we are in the owning group, the group permissions apply. */
else if (group_member (finfo.st_gid))
{
if (finfo.st_mode & S_IXGRP)
r |= FS_EXECABLE;
if (finfo.st_mode & S_IRGRP)
r |= FS_READABLE;
}
/* Else we check whether `others' have permission to execute the file */
else
{
if (finfo.st_mode & S_IXOTH)
r |= FS_EXECABLE;
if (finfo.st_mode & S_IROTH)
r |= FS_READABLE;
}
return r;
#endif /* !AFS */
}
/* Return non-zero if FILE exists and is executable.
Note that this function is the definition of what an
executable file is; do not change this unless YOU know
what an executable file is. */
int
executable_file (file)
const char *file;
{
int s;
s = file_status (file);
#if defined EISDIR
if (s & FS_DIRECTORY)
errno = EISDIR; /* let's see if we can improve error messages */
#endif
return ((s & FS_EXECABLE) && ((s & FS_DIRECTORY) == 0));
}
int
is_directory (file)
const char *file;
{
return (file_status (file) & FS_DIRECTORY);
}
int
executable_or_directory (file)
const char *file;
{
int s;
s = file_status (file);
return ((s & FS_EXECABLE) || (s & FS_DIRECTORY));
}
/* Locate the executable file referenced by NAME, searching along
the contents of the shell PATH variable. Return a new string
which is the full pathname to the file, or NULL if the file
couldn't be found. If a file is found that isn't executable,
and that is the only match, then return that. */
char *
find_user_command (name)
const char *name;
{
return (find_user_command_internal (name, FS_EXEC_PREFERRED|FS_NODIRS));
}
/* Locate the file referenced by NAME, searching along the contents
of the shell PATH variable. Return a new string which is the full
pathname to the file, or NULL if the file couldn't be found. This
returns the first readable file found; designed to be used to look
for shell scripts or files to source. */
char *
find_path_file (name)
const char *name;
{
return (find_user_command_internal (name, FS_READABLE));
}
static char *
_find_user_command_internal (name, flags)
const char *name;
int flags;
{
char *path_list, *cmd;
SHELL_VAR *var;
/* Search for the value of PATH in both the temporary environments and
in the regular list of variables. */
if (var = find_variable_tempenv ("PATH")) /* XXX could be array? */
path_list = value_cell (var);
else
path_list = (char *)NULL;
if (path_list == 0 || *path_list == '\0')
return (savestring (name));
cmd = find_user_command_in_path (name, path_list, flags);
return (cmd);
}
static char *
find_user_command_internal (name, flags)
const char *name;
int flags;
{
#ifdef __WIN32__
char *res, *dotexe;
dotexe = (char *)xmalloc (strlen (name) + 5);
strcpy (dotexe, name);
strcat (dotexe, ".exe");
res = _find_user_command_internal (dotexe, flags);
free (dotexe);
if (res == 0)
res = _find_user_command_internal (name, flags);
return res;
#else
return (_find_user_command_internal (name, flags));
#endif
}
/* Return the next element from PATH_LIST, a colon separated list of
paths. PATH_INDEX_POINTER is the address of an index into PATH_LIST;
the index is modified by this function.
Return the next element of PATH_LIST or NULL if there are no more. */
static char *
get_next_path_element (path_list, path_index_pointer)
char *path_list;
int *path_index_pointer;
{
char *path;
path = extract_colon_unit (path_list, path_index_pointer);
if (path == 0)
return (path);
if (*path == '\0')
{
free (path);
path = savestring (".");
}
return (path);
}
/* Look for PATHNAME in $PATH. Returns either the hashed command
corresponding to PATHNAME or the first instance of PATHNAME found
in $PATH. If (FLAGS&1) is non-zero, insert the instance of PATHNAME
found in $PATH into the command hash table. Returns a newly-allocated
string. */
char *
search_for_command (pathname, flags)
const char *pathname;
int flags;
{
char *hashed_file, *command;
int temp_path, st;
SHELL_VAR *path;
hashed_file = command = (char *)NULL;
/* If PATH is in the temporary environment for this command, don't use the
hash table to search for the full pathname. */
path = find_variable_tempenv ("PATH");
temp_path = path && tempvar_p (path);
if (temp_path == 0 && path)
path = (SHELL_VAR *)NULL;
/* Don't waste time trying to find hashed data for a pathname
that is already completely specified or if we're using a command-
specific value for PATH. */
if (path == 0 && absolute_program (pathname) == 0)
hashed_file = phash_search (pathname);
/* If a command found in the hash table no longer exists, we need to
look for it in $PATH. Thank you Posix.2. This forces us to stat
every command found in the hash table. */
if (hashed_file && (posixly_correct || check_hashed_filenames))
{
st = file_status (hashed_file);
if ((st & (FS_EXISTS|FS_EXECABLE)) != (FS_EXISTS|FS_EXECABLE))
{
phash_remove (pathname);
free (hashed_file);
hashed_file = (char *)NULL;
}
}
if (hashed_file)
command = hashed_file;
else if (absolute_program (pathname))
/* A command containing a slash is not looked up in PATH or saved in
the hash table. */
command = savestring (pathname);
else
{
/* If $PATH is in the temporary environment, we've already retrieved
it, so don't bother trying again. */
if (temp_path)
{
command = find_user_command_in_path (pathname, value_cell (path),
FS_EXEC_PREFERRED|FS_NODIRS);
}
else
command = find_user_command (pathname);
if (command && hashing_enabled && temp_path == 0 && (flags & 1))
phash_insert ((char *)pathname, command, dot_found_in_search, 1); /* XXX fix const later */
}
return (command);
}
char *
user_command_matches (name, flags, state)
const char *name;
int flags, state;
{
register int i;
int path_index, name_len;
char *path_list, *path_element, *match;
struct stat dotinfo;
static char **match_list = NULL;
static int match_list_size = 0;
static int match_index = 0;
if (state == 0)
{
/* Create the list of matches. */
if (match_list == 0)
{
match_list_size = 5;
match_list = strvec_create (match_list_size);
}
/* Clear out the old match list. */
for (i = 0; i < match_list_size; i++)
match_list[i] = 0;
/* We haven't found any files yet. */
match_index = 0;
if (absolute_program (name))
{
match_list[0] = find_absolute_program (name, flags);
match_list[1] = (char *)NULL;
path_list = (char *)NULL;
}
else
{
name_len = strlen (name);
file_to_lose_on = (char *)NULL;
dot_found_in_search = 0;
if (stat (".", &dotinfo) < 0)
dotinfo.st_dev = dotinfo.st_ino = 0; /* so same_file won't match */
path_list = get_string_value ("PATH");
path_index = 0;
}
while (path_list && path_list[path_index])
{
path_element = get_next_path_element (path_list, &path_index);
if (path_element == 0)
break;
match = find_in_path_element (name, path_element, flags, name_len, &dotinfo);
free (path_element);
if (match == 0)
continue;
if (match_index + 1 == match_list_size)
{
match_list_size += 10;
match_list = strvec_resize (match_list, (match_list_size + 1));
}
match_list[match_index++] = match;
match_list[match_index] = (char *)NULL;
FREE (file_to_lose_on);
file_to_lose_on = (char *)NULL;
}
/* We haven't returned any strings yet. */
match_index = 0;
}
match = match_list[match_index];
if (match)
match_index++;
return (match);
}
static char *
find_absolute_program (name, flags)
const char *name;
int flags;
{
int st;
st = file_status (name);
/* If the file doesn't exist, quit now. */
if ((st & FS_EXISTS) == 0)
return ((char *)NULL);
/* If we only care about whether the file exists or not, return
this filename. Otherwise, maybe we care about whether this
file is executable. If it is, and that is what we want, return it. */
if ((flags & FS_EXISTS) || ((flags & FS_EXEC_ONLY) && (st & FS_EXECABLE)))
return (savestring (name));
return (NULL);
}
static char *
find_in_path_element (name, path, flags, name_len, dotinfop)
const char *name;
char *path;
int flags, name_len;
struct stat *dotinfop;
{
int status;
char *full_path, *xpath;
xpath = (*path == '~') ? bash_tilde_expand (path, 0) : path;
/* Remember the location of "." in the path, in all its forms
(as long as they begin with a `.', e.g. `./.') */
if (dot_found_in_search == 0 && *xpath == '.')
dot_found_in_search = same_file (".", xpath, dotinfop, (struct stat *)NULL);
full_path = sh_makepath (xpath, name, 0);
status = file_status (full_path);
if (xpath != path)
free (xpath);
if ((status & FS_EXISTS) == 0)
{
free (full_path);
return ((char *)NULL);
}
/* The file exists. If the caller simply wants the first file, here it is. */
if (flags & FS_EXISTS)
return (full_path);
/* If we have a readable file, and the caller wants a readable file, this
is it. */
if ((flags & FS_READABLE) && (status & FS_READABLE))
return (full_path);
/* If the file is executable, then it satisfies the cases of
EXEC_ONLY and EXEC_PREFERRED. Return this file unconditionally. */
if ((status & FS_EXECABLE) && (flags & (FS_EXEC_ONLY|FS_EXEC_PREFERRED)) &&
(((flags & FS_NODIRS) == 0) || ((status & FS_DIRECTORY) == 0)))
{
FREE (file_to_lose_on);
file_to_lose_on = (char *)NULL;
return (full_path);
}
/* The file is not executable, but it does exist. If we prefer
an executable, then remember this one if it is the first one
we have found. */
if ((flags & FS_EXEC_PREFERRED) && file_to_lose_on == 0)
file_to_lose_on = savestring (full_path);
/* If we want only executable files, or we don't want directories and
this file is a directory, or we want a readable file and this file
isn't readable, fail. */
if ((flags & (FS_EXEC_ONLY|FS_EXEC_PREFERRED)) ||
((flags & FS_NODIRS) && (status & FS_DIRECTORY)) ||
((flags & FS_READABLE) && (status & FS_READABLE) == 0))
{
free (full_path);
return ((char *)NULL);
}
else
return (full_path);
}
/* This does the dirty work for find_user_command_internal () and
user_command_matches ().
NAME is the name of the file to search for.
PATH_LIST is a colon separated list of directories to search.
FLAGS contains bit fields which control the files which are eligible.
Some values are:
FS_EXEC_ONLY: The file must be an executable to be found.
FS_EXEC_PREFERRED: If we can't find an executable, then the
the first file matching NAME will do.
FS_EXISTS: The first file found will do.
FS_NODIRS: Don't find any directories.
*/
static char *
find_user_command_in_path (name, path_list, flags)
const char *name;
char *path_list;
int flags;
{
char *full_path, *path;
int path_index, name_len;
struct stat dotinfo;
/* We haven't started looking, so we certainly haven't seen
a `.' as the directory path yet. */
dot_found_in_search = 0;
if (absolute_program (name))
{
full_path = find_absolute_program (name, flags);
return (full_path);
}
if (path_list == 0 || *path_list == '\0')
return (savestring (name)); /* XXX */
file_to_lose_on = (char *)NULL;
name_len = strlen (name);
if (stat (".", &dotinfo) < 0)
dotinfo.st_dev = dotinfo.st_ino = 0;
path_index = 0;
while (path_list[path_index])
{
/* Allow the user to interrupt out of a lengthy path search. */
QUIT;
path = get_next_path_element (path_list, &path_index);
if (path == 0)
break;
/* Side effects: sets dot_found_in_search, possibly sets
file_to_lose_on. */
full_path = find_in_path_element (name, path, flags, name_len, &dotinfo);
free (path);
/* This should really be in find_in_path_element, but there isn't the
right combination of flags. */
if (full_path && is_directory (full_path))
{
free (full_path);
continue;
}
if (full_path)
{
FREE (file_to_lose_on);
return (full_path);
}
}
/* We didn't find exactly what the user was looking for. Return
the contents of FILE_TO_LOSE_ON which is NULL when the search
required an executable, or non-NULL if a file was found and the
search would accept a non-executable as a last resort. If the
caller specified FS_NODIRS, and file_to_lose_on is a directory,
return NULL. */
if (file_to_lose_on && (flags & FS_NODIRS) && is_directory (file_to_lose_on))
{
free (file_to_lose_on);
file_to_lose_on = (char *)NULL;
}
return (file_to_lose_on);
}
bash-4.3/unwind_prot.c 0000644 0001750 0000144 00000021054 12112226235 013662 0 ustar doko users /* unwind_prot.c - a simple unwind-protect system for internal variables */
/* I can't stand it anymore! Please can't we just write the
whole Unix system in lisp or something? */
/* Copyright (C) 1987-2009 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 3 of the License, 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. If not, see .
*/
/* **************************************************************** */
/* */
/* Unwind Protection Scheme for Bash */
/* */
/* **************************************************************** */
#include "config.h"
#include "bashtypes.h"
#include "bashansi.h"
#if defined (HAVE_UNISTD_H)
# include
#endif
#if STDC_HEADERS
# include
#endif
#ifndef offsetof
# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#include "command.h"
#include "general.h"
#include "unwind_prot.h"
#include "sig.h"
#include "quit.h"
#include "error.h" /* for internal_warning */
/* Structure describing a saved variable and the value to restore it to. */
typedef struct {
char *variable;
int size;
char desired_setting[1]; /* actual size is `size' */
} SAVED_VAR;
/* If HEAD.CLEANUP is null, then ARG.V contains a tag to throw back to.
If HEAD.CLEANUP is restore_variable, then SV.V contains the saved
variable. Otherwise, call HEAD.CLEANUP (ARG.V) to clean up. */
typedef union uwp {
struct uwp_head {
union uwp *next;
Function *cleanup;
} head;
struct {
struct uwp_head uwp_head;
char *v;
} arg;
struct {
struct uwp_head uwp_head;
SAVED_VAR v;
} sv;
} UNWIND_ELT;
static void without_interrupts __P((VFunction *, char *, char *));
static void unwind_frame_discard_internal __P((char *, char *));
static void unwind_frame_run_internal __P((char *, char *));
static void add_unwind_protect_internal __P((Function *, char *));
static void remove_unwind_protect_internal __P((char *, char *));
static void run_unwind_protects_internal __P((char *, char *));
static void clear_unwind_protects_internal __P((char *, char *));
static inline void restore_variable __P((SAVED_VAR *));
static void unwind_protect_mem_internal __P((char *, char *));
static UNWIND_ELT *unwind_protect_list = (UNWIND_ELT *)NULL;
#define uwpalloc(elt) (elt) = (UNWIND_ELT *)xmalloc (sizeof (UNWIND_ELT))
#define uwpfree(elt) free(elt)
/* Run a function without interrupts. This relies on the fact that the
FUNCTION cannot change the value of interrupt_immediately. (I.e., does
not call QUIT (). */
static void
without_interrupts (function, arg1, arg2)
VFunction *function;
char *arg1, *arg2;
{
int old_interrupt_immediately;
old_interrupt_immediately = interrupt_immediately;
interrupt_immediately = 0;
(*function)(arg1, arg2);
interrupt_immediately = old_interrupt_immediately;
}
/* Start the beginning of a region. */
void
begin_unwind_frame (tag)
char *tag;
{
add_unwind_protect ((Function *)NULL, tag);
}
/* Discard the unwind protects back to TAG. */
void
discard_unwind_frame (tag)
char *tag;
{
if (unwind_protect_list)
without_interrupts (unwind_frame_discard_internal, tag, (char *)NULL);
}
/* Run the unwind protects back to TAG. */
void
run_unwind_frame (tag)
char *tag;
{
if (unwind_protect_list)
without_interrupts (unwind_frame_run_internal, tag, (char *)NULL);
}
/* Add the function CLEANUP with ARG to the list of unwindable things. */
void
add_unwind_protect (cleanup, arg)
Function *cleanup;
char *arg;
{
without_interrupts (add_unwind_protect_internal, (char *)cleanup, arg);
}
/* Remove the top unwind protect from the list. */
void
remove_unwind_protect ()
{
if (unwind_protect_list)
without_interrupts
(remove_unwind_protect_internal, (char *)NULL, (char *)NULL);
}
/* Run the list of cleanup functions in unwind_protect_list. */
void
run_unwind_protects ()
{
if (unwind_protect_list)
without_interrupts
(run_unwind_protects_internal, (char *)NULL, (char *)NULL);
}
/* Erase the unwind-protect list. If flags is 1, free the elements. */
void
clear_unwind_protect_list (flags)
int flags;
{
char *flag;
if (unwind_protect_list)
{
flag = flags ? "" : (char *)NULL;
without_interrupts
(clear_unwind_protects_internal, flag, (char *)NULL);
}
}
int
have_unwind_protects ()
{
return (unwind_protect_list != 0);
}
/* **************************************************************** */
/* */
/* The Actual Functions */
/* */
/* **************************************************************** */
static void
add_unwind_protect_internal (cleanup, arg)
Function *cleanup;
char *arg;
{
UNWIND_ELT *elt;
uwpalloc (elt);
elt->head.next = unwind_protect_list;
elt->head.cleanup = cleanup;
elt->arg.v = arg;
unwind_protect_list = elt;
}
static void
remove_unwind_protect_internal (ignore1, ignore2)
char *ignore1, *ignore2;
{
UNWIND_ELT *elt;
elt = unwind_protect_list;
if (elt)
{
unwind_protect_list = unwind_protect_list->head.next;
uwpfree (elt);
}
}
static void
run_unwind_protects_internal (ignore1, ignore2)
char *ignore1, *ignore2;
{
unwind_frame_run_internal ((char *) NULL, (char *) NULL);
}
static void
clear_unwind_protects_internal (flag, ignore)
char *flag, *ignore;
{
if (flag)
{
while (unwind_protect_list)
remove_unwind_protect_internal ((char *)NULL, (char *)NULL);
}
unwind_protect_list = (UNWIND_ELT *)NULL;
}
static void
unwind_frame_discard_internal (tag, ignore)
char *tag, *ignore;
{
UNWIND_ELT *elt;
int found;
found = 0;
while (elt = unwind_protect_list)
{
unwind_protect_list = unwind_protect_list->head.next;
if (elt->head.cleanup == 0 && (STREQ (elt->arg.v, tag)))
{
uwpfree (elt);
found = 1;
break;
}
else
uwpfree (elt);
}
if (found == 0)
internal_warning ("unwind_frame_discard: %s: frame not found", tag);
}
/* Restore the value of a variable, based on the contents of SV.
sv->desired_setting is a block of memory SIZE bytes long holding the
value itself. This block of memory is copied back into the variable. */
static inline void
restore_variable (sv)
SAVED_VAR *sv;
{
FASTCOPY (sv->desired_setting, sv->variable, sv->size);
}
static void
unwind_frame_run_internal (tag, ignore)
char *tag, *ignore;
{
UNWIND_ELT *elt;
int found;
found = 0;
while (elt = unwind_protect_list)
{
unwind_protect_list = elt->head.next;
/* If tag, then compare. */
if (elt->head.cleanup == 0)
{
if (tag && STREQ (elt->arg.v, tag))
{
uwpfree (elt);
found = 1;
break;
}
}
else
{
if (elt->head.cleanup == (Function *) restore_variable)
restore_variable (&elt->sv.v);
else
(*(elt->head.cleanup)) (elt->arg.v);
}
uwpfree (elt);
}
if (tag && found == 0)
internal_warning ("unwind_frame_run: %s: frame not found", tag);
}
static void
unwind_protect_mem_internal (var, psize)
char *var;
char *psize;
{
int size, allocated;
UNWIND_ELT *elt;
size = *(int *) psize;
allocated = size + offsetof (UNWIND_ELT, sv.v.desired_setting[0]);
elt = (UNWIND_ELT *)xmalloc (allocated);
elt->head.next = unwind_protect_list;
elt->head.cleanup = (Function *) restore_variable;
elt->sv.v.variable = var;
elt->sv.v.size = size;
FASTCOPY (var, elt->sv.v.desired_setting, size);
unwind_protect_list = elt;
}
/* Save the value of a variable so it will be restored when unwind-protects
are run. VAR is a pointer to the variable. SIZE is the size in
bytes of VAR. */
void
unwind_protect_mem (var, size)
char *var;
int size;
{
without_interrupts (unwind_protect_mem_internal, var, (char *) &size);
}
#if defined (DEBUG)
#include
void
print_unwind_protect_tags ()
{
UNWIND_ELT *elt;
elt = unwind_protect_list;
while (elt)
{
unwind_protect_list = unwind_protect_list->head.next;
if (elt->head.cleanup == 0)
fprintf(stderr, "tag: %s\n", elt->arg.v);
elt = unwind_protect_list;
}
}
#endif
bash-4.3/general.h 0000644 0001750 0000144 00000023741 12226771506 012755 0 ustar doko users /* general.h -- defines that everybody likes to use. */
/* Copyright (C) 1993-2009 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 3 of the License, 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. If not, see .
*/
#if !defined (_GENERAL_H_)
#define _GENERAL_H_
#include "stdc.h"
#include "bashtypes.h"
#include "chartypes.h"
#if defined (HAVE_SYS_RESOURCE_H) && defined (RLIMTYPE)
# if defined (HAVE_SYS_TIME_H)
# include
# endif
# include
#endif
#if defined (HAVE_STRING_H)
# include
#else
# include
#endif /* !HAVE_STRING_H */
#if defined (HAVE_LIMITS_H)
# include
#endif
#include "xmalloc.h"
/* NULL pointer type. */
#if !defined (NULL)
# if defined (__STDC__)
# define NULL ((void *) 0)
# else
# define NULL 0x0
# endif /* !__STDC__ */
#endif /* !NULL */
/* Hardly used anymore */
#define pointer_to_int(x) (int)((char *)x - (char *)0)
#if defined (alpha) && defined (__GNUC__) && !defined (strchr) && !defined (__STDC__)
extern char *strchr (), *strrchr ();
#endif
#if !defined (strcpy) && (defined (HAVE_DECL_STRCPY) && !HAVE_DECL_STRCPY)
extern char *strcpy __P((char *, const char *));
#endif
#if !defined (savestring)
# define savestring(x) (char *)strcpy (xmalloc (1 + strlen (x)), (x))
#endif
#ifndef member
# define member(c, s) ((c) ? ((char *)mbschr ((s), (c)) != (char *)NULL) : 0)
#endif
#ifndef whitespace
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
#endif
#ifndef CHAR_MAX
# ifdef __CHAR_UNSIGNED__
# define CHAR_MAX 0xff
# else
# define CHAR_MAX 0x7f
# endif
#endif
#ifndef CHAR_BIT
# define CHAR_BIT 8
#endif
/* Nonzero if the integer type T is signed. */
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
/* Bound on length of the string representing an integer value of type T.
Subtract one for the sign bit if T is signed;
302 / 1000 is log10 (2) rounded up;
add one for integer division truncation;
add one more for a minus sign if t is signed. */
#define INT_STRLEN_BOUND(t) \
((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 1000 \
+ 1 + TYPE_SIGNED (t))
/* Define exactly what a legal shell identifier consists of. */
#define legal_variable_starter(c) (ISALPHA(c) || (c == '_'))
#define legal_variable_char(c) (ISALNUM(c) || c == '_')
/* Definitions used in subst.c and by the `read' builtin for field
splitting. */
#define spctabnl(c) ((c) == ' ' || (c) == '\t' || (c) == '\n')
/* All structs which contain a `next' field should have that field
as the first field in the struct. This means that functions
can be written to handle the general case for linked lists. */
typedef struct g_list {
struct g_list *next;
} GENERIC_LIST;
/* Here is a generic structure for associating character strings
with integers. It is used in the parser for shell tokenization. */
typedef struct {
char *word;
int token;
} STRING_INT_ALIST;
/* A macro to avoid making an unneccessary function call. */
#define REVERSE_LIST(list, type) \
((list && list->next) ? (type)list_reverse ((GENERIC_LIST *)list) \
: (type)(list))
#if __GNUC__ > 1
# define FASTCOPY(s, d, n) __builtin_memcpy ((d), (s), (n))
#else /* !__GNUC__ */
# if !defined (HAVE_BCOPY)
# if !defined (HAVE_MEMMOVE)
# define FASTCOPY(s, d, n) memcpy ((d), (s), (n))
# else
# define FASTCOPY(s, d, n) memmove ((d), (s), (n))
# endif /* !HAVE_MEMMOVE */
# else /* HAVE_BCOPY */
# define FASTCOPY(s, d, n) bcopy ((s), (d), (n))
# endif /* HAVE_BCOPY */
#endif /* !__GNUC__ */
/* String comparisons that possibly save a function call each. */
#define STREQ(a, b) ((a)[0] == (b)[0] && strcmp(a, b) == 0)
#define STREQN(a, b, n) ((n == 0) ? (1) \
: ((a)[0] == (b)[0] && strncmp(a, b, n) == 0))
/* More convenience definitions that possibly save system or libc calls. */
#define STRLEN(s) (((s) && (s)[0]) ? ((s)[1] ? ((s)[2] ? strlen(s) : 2) : 1) : 0)
#define FREE(s) do { if (s) free (s); } while (0)
#define MEMBER(c, s) (((c) && c == (s)[0] && !(s)[1]) || (member(c, s)))
/* A fairly hairy macro to check whether an allocated string has more room,
and to resize it using xrealloc if it does not.
STR is the string (char *)
CIND is the current index into the string (int)
ROOM is the amount of additional room we need in the string (int)
CSIZE is the currently-allocated size of STR (int)
SINCR is how much to increment CSIZE before calling xrealloc (int) */
#define RESIZE_MALLOCED_BUFFER(str, cind, room, csize, sincr) \
do { \
if ((cind) + (room) >= csize) \
{ \
while ((cind) + (room) >= csize) \
csize += (sincr); \
str = xrealloc (str, csize); \
} \
} while (0)
/* Function pointers can be declared as (Function *)foo. */
#if !defined (_FUNCTION_DEF)
# define _FUNCTION_DEF
typedef int Function ();
typedef void VFunction ();
typedef char *CPFunction (); /* no longer used */
typedef char **CPPFunction (); /* no longer used */
#endif /* _FUNCTION_DEF */
#ifndef SH_FUNCTION_TYPEDEF
# define SH_FUNCTION_TYPEDEF
/* Shell function typedefs with prototypes */
/* `Generic' function pointer typedefs */
typedef int sh_intfunc_t __P((int));
typedef int sh_ivoidfunc_t __P((void));
typedef int sh_icpfunc_t __P((char *));
typedef int sh_icppfunc_t __P((char **));
typedef int sh_iptrfunc_t __P((PTR_T));
typedef void sh_voidfunc_t __P((void));
typedef void sh_vintfunc_t __P((int));
typedef void sh_vcpfunc_t __P((char *));
typedef void sh_vcppfunc_t __P((char **));
typedef void sh_vptrfunc_t __P((PTR_T));
typedef int sh_wdesc_func_t __P((WORD_DESC *));
typedef int sh_wlist_func_t __P((WORD_LIST *));
typedef int sh_glist_func_t __P((GENERIC_LIST *));
typedef char *sh_string_func_t __P((char *)); /* like savestring, et al. */
typedef int sh_msg_func_t __P((const char *, ...)); /* printf(3)-like */
typedef void sh_vmsg_func_t __P((const char *, ...)); /* printf(3)-like */
/* Specific function pointer typedefs. Most of these could be done
with #defines. */
typedef void sh_sv_func_t __P((char *)); /* sh_vcpfunc_t */
typedef void sh_free_func_t __P((PTR_T)); /* sh_vptrfunc_t */
typedef void sh_resetsig_func_t __P((int)); /* sh_vintfunc_t */
typedef int sh_ignore_func_t __P((const char *)); /* sh_icpfunc_t */
typedef int sh_assign_func_t __P((const char *));
typedef int sh_wassign_func_t __P((WORD_DESC *, int));
typedef int sh_builtin_func_t __P((WORD_LIST *)); /* sh_wlist_func_t */
#endif /* SH_FUNCTION_TYPEDEF */
#define NOW ((time_t) time ((time_t *) 0))
/* Some defines for calling file status functions. */
#define FS_EXISTS 0x1
#define FS_EXECABLE 0x2
#define FS_EXEC_PREFERRED 0x4
#define FS_EXEC_ONLY 0x8
#define FS_DIRECTORY 0x10
#define FS_NODIRS 0x20
#define FS_READABLE 0x40
/* Default maximum for move_to_high_fd */
#define HIGH_FD_MAX 256
/* The type of function passed as the fourth argument to qsort(3). */
#ifdef __STDC__
typedef int QSFUNC (const void *, const void *);
#else
typedef int QSFUNC ();
#endif
/* Some useful definitions for Unix pathnames. Argument convention:
x == string, c == character */
#if !defined (__CYGWIN__)
# define ABSPATH(x) ((x)[0] == '/')
# define RELPATH(x) ((x)[0] != '/')
#else /* __CYGWIN__ */
# define ABSPATH(x) (((x)[0] && ISALPHA((unsigned char)(x)[0]) && (x)[1] == ':') || ISDIRSEP((x)[0]))
# define RELPATH(x) (ABSPATH(x) == 0)
#endif /* __CYGWIN__ */
#define ROOTEDPATH(x) (ABSPATH(x))
#define DIRSEP '/'
#if !defined (__CYGWIN__)
# define ISDIRSEP(c) ((c) == '/')
#else
# define ISDIRSEP(c) ((c) == '/' || (c) == '\\')
#endif /* __CYGWIN__ */
#define PATHSEP(c) (ISDIRSEP(c) || (c) == 0)
#if 0
/* Declarations for functions defined in xmalloc.c */
extern PTR_T xmalloc __P((size_t));
extern PTR_T xrealloc __P((void *, size_t));
extern void xfree __P((void *));
#endif
/* Declarations for functions defined in general.c */
extern void posix_initialize __P((int));
#if defined (RLIMTYPE)
extern RLIMTYPE string_to_rlimtype __P((char *));
extern void print_rlimtype __P((RLIMTYPE, int));
#endif
extern int all_digits __P((char *));
extern int legal_number __P((const char *, intmax_t *));
extern int legal_identifier __P((char *));
extern int check_identifier __P((WORD_DESC *, int));
extern int legal_alias_name __P((char *, int));
extern int assignment __P((const char *, int));
extern int sh_unset_nodelay_mode __P((int));
extern int sh_validfd __P((int));
extern int fd_ispipe __P((int));
extern void check_dev_tty __P((void));
extern int move_to_high_fd __P((int, int, int));
extern int check_binary_file __P((char *, int));
#ifdef _POSIXSTAT_H_
extern int same_file __P((char *, char *, struct stat *, struct stat *));
#endif
extern int sh_openpipe __P((int *));
extern int sh_closepipe __P((int *));
extern int file_exists __P((char *));
extern int file_isdir __P((char *));
extern int file_iswdir __P((char *));
extern int path_dot_or_dotdot __P((const char *));
extern int absolute_pathname __P((const char *));
extern int absolute_program __P((const char *));
extern char *make_absolute __P((char *, char *));
extern char *base_pathname __P((char *));
extern char *full_pathname __P((char *));
extern char *polite_directory_format __P((char *));
extern char *trim_pathname __P((char *, int));
extern char *extract_colon_unit __P((char *, int *));
extern void tilde_initialize __P((void));
extern char *bash_tilde_find_word __P((const char *, int, int *));
extern char *bash_tilde_expand __P((const char *, int));
extern int group_member __P((gid_t));
extern char **get_group_list __P((int *));
extern int *get_group_array __P((int *));
#endif /* _GENERAL_H_ */
bash-4.3/COPYING 0000644 0001750 0000144 00000104513 11050304560 012201 0 ustar doko users GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program 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 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
bash-4.3/bashhist.c 0000644 0001750 0000144 00000057050 11764156117 013141 0 ustar doko users /* bashhist.c -- bash interface to the GNU history library. */
/* Copyright (C) 1993-2012 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 3 of the License, 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. If not, see .
*/
#include "config.h"
#if defined (HISTORY)
#if defined (HAVE_UNISTD_H)
# ifdef _MINIX
# include
# endif
# include
#endif
#include "bashtypes.h"
#include
#include
#include "bashansi.h"
#include "posixstat.h"
#include "filecntl.h"
#include "bashintl.h"
#if defined (SYSLOG_HISTORY)
# include
#endif
#include "shell.h"
#include "flags.h"
#include "input.h"
#include "parser.h" /* for the struct dstack stuff. */
#include "pathexp.h" /* for the struct ignorevar stuff */
#include "bashhist.h" /* matching prototypes and declarations */
#include "builtins/common.h"
#include
#include
#include
#if defined (READLINE)
# include "bashline.h"
extern int rl_done, rl_dispatching; /* should really include readline.h */
#endif
#if !defined (errno)
extern int errno;
#endif
static int histignore_item_func __P((struct ign *));
static int check_history_control __P((char *));
static void hc_erasedups __P((char *));
static void really_add_history __P((char *));
static struct ignorevar histignore =
{
"HISTIGNORE",
(struct ign *)0,
0,
(char *)0,
(sh_iv_item_func_t *)histignore_item_func,
};
#define HIGN_EXPAND 0x01
/* Declarations of bash history variables. */
/* Non-zero means to remember lines typed to the shell on the history
list. This is different than the user-controlled behaviour; this
becomes zero when we read lines from a file, for example. */
int remember_on_history = 1;
int enable_history_list = 1; /* value for `set -o history' */
/* The number of lines that Bash has added to this history session. The
difference between the number of the top element in the history list
(offset from history_base) and the number of lines in the history file.
Appending this session's history to the history file resets this to 0. */
int history_lines_this_session;
/* The number of lines that Bash has read from the history file. */
int history_lines_in_file;
#if defined (BANG_HISTORY)
/* Non-zero means do no history expansion on this line, regardless
of what history_expansion says. */
int history_expansion_inhibited;
#endif
/* With the old default, every line was saved in the history individually.
I.e., if the user enters:
bash$ for i in a b c
> do
> echo $i
> done
Each line will be individually saved in the history.
bash$ history
10 for i in a b c
11 do
12 echo $i
13 done
14 history
If the variable command_oriented_history is set, multiple lines
which form one command will be saved as one history entry.
bash$ for i in a b c
> do
> echo $i
> done
bash$ history
10 for i in a b c
do
echo $i
done
11 history
The user can then recall the whole command all at once instead
of just being able to recall one line at a time.
This is now enabled by default.
*/
int command_oriented_history = 1;
/* Set to 1 if the first line of a possibly-multi-line command was saved
in the history list. Managed by maybe_add_history(), but global so
the history-manipluating builtins can see it. */
int current_command_first_line_saved = 0;
/* Non-zero means to store newlines in the history list when using
command_oriented_history rather than trying to use semicolons. */
int literal_history;
/* Non-zero means to append the history to the history file at shell
exit, even if the history has been stifled. */
int force_append_history;
/* A nit for picking at history saving. Flags have the following values:
Value == 0 means save all lines parsed by the shell on the history.
Value & HC_IGNSPACE means save all lines that do not start with a space.
Value & HC_IGNDUPS means save all lines that do not match the last
line saved.
Value & HC_ERASEDUPS means to remove all other matching lines from the
history list before saving the latest line. */
int history_control;
/* Set to 1 if the last command was added to the history list successfully
as a separate history entry; set to 0 if the line was ignored or added
to a previous entry as part of command-oriented-history processing. */
int hist_last_line_added;
/* Set to 1 if builtins/history.def:push_history added the last history
entry. */
int hist_last_line_pushed;
#if defined (READLINE)
/* If non-zero, and readline is being used, the user is offered the
chance to re-edit a failed history expansion. */
int history_reediting;
/* If non-zero, and readline is being used, don't directly execute a
line with history substitution. Reload it into the editing buffer
instead and let the user further edit and confirm with a newline. */
int hist_verify;
#endif /* READLINE */
/* Non-zero means to not save function definitions in the history list. */
int dont_save_function_defs;
/* Variables declared in other files used here. */
extern int current_command_line_count;
extern struct dstack dstack;
extern int parser_state;
static int bash_history_inhibit_expansion __P((char *, int));
#if defined (READLINE)
static void re_edit __P((char *));
#endif
static int history_expansion_p __P((char *));
static int shell_comment __P((char *));
static int should_expand __P((char *));
static HIST_ENTRY *last_history_entry __P((void));
static char *expand_histignore_pattern __P((char *));
static int history_should_ignore __P((char *));
/* Is the history expansion starting at string[i] one that should not
be expanded? */
static int
bash_history_inhibit_expansion (string, i)
char *string;
int i;
{
/* The shell uses ! as a pattern negation character in globbing [...]
expressions, so let those pass without expansion. */
if (i > 0 && (string[i - 1] == '[') && member (']', string + i + 1))
return (1);
/* The shell uses ! as the indirect expansion character, so let those
expansions pass as well. */
else if (i > 1 && string[i - 1] == '{' && string[i - 2] == '$' &&
member ('}', string + i + 1))
return (1);
/* The shell uses $! as a defined parameter expansion. */
else if (i > 1 && string[i - 1] == '$' && string[i] == '!')
return (1);
#if defined (EXTENDED_GLOB)
else if (extended_glob && i > 1 && string[i+1] == '(' && member (')', string + i + 2))
return (1);
#endif
else
return (0);
}
void
bash_initialize_history ()
{
history_quotes_inhibit_expansion = 1;
history_search_delimiter_chars = ";&()|<>";
history_inhibit_expansion_function = bash_history_inhibit_expansion;
#if defined (BANG_HISTORY)
sv_histchars ("histchars");
#endif
}
void
bash_history_reinit (interact)
int interact;
{
#if defined (BANG_HISTORY)
history_expansion = interact != 0;
history_expansion_inhibited = 1;
#endif
remember_on_history = enable_history_list = interact != 0;
history_inhibit_expansion_function = bash_history_inhibit_expansion;
}
void
bash_history_disable ()
{
remember_on_history = 0;
#if defined (BANG_HISTORY)
history_expansion_inhibited = 1;
#endif
}
void
bash_history_enable ()
{
remember_on_history = 1;
#if defined (BANG_HISTORY)
history_expansion_inhibited = 0;
#endif
history_inhibit_expansion_function = bash_history_inhibit_expansion;
sv_history_control ("HISTCONTROL");
sv_histignore ("HISTIGNORE");
}
/* Load the history list from the history file. */
void
load_history ()
{
char *hf;
/* Truncate history file for interactive shells which desire it.
Note that the history file is automatically truncated to the
size of HISTSIZE if the user does not explicitly set the size
differently. */
set_if_not ("HISTSIZE", "500");
sv_histsize ("HISTSIZE");
set_if_not ("HISTFILESIZE", get_string_value ("HISTSIZE"));
sv_histsize ("HISTFILESIZE");
/* Read the history in HISTFILE into the history list. */
hf = get_string_value ("HISTFILE");
if (hf && *hf && file_exists (hf))
{
read_history (hf);
using_history ();
history_lines_in_file = where_history ();
}
}
void
bash_clear_history ()
{
clear_history ();
history_lines_this_session = 0;
}
/* Delete and free the history list entry at offset I. */
int
bash_delete_histent (i)
int i;
{
HIST_ENTRY *discard;
discard = remove_history (i);
if (discard)
free_history_entry (discard);
history_lines_this_session--;
return 1;
}
int
bash_delete_last_history ()
{
register int i;
HIST_ENTRY **hlist, *histent;
int r;
hlist = history_list ();
if (hlist == NULL)
return 0;
for (i = 0; hlist[i]; i++)
;
i--;
/* History_get () takes a parameter that must be offset by history_base. */
histent = history_get (history_base + i); /* Don't free this */
if (histent == NULL)
return 0;
r = bash_delete_histent (i);
if (where_history () > history_length)
history_set_pos (history_length);
return r;
}
#ifdef INCLUDE_UNUSED
/* Write the existing history out to the history file. */
void
save_history ()
{
char *hf;
int r;
hf = get_string_value ("HISTFILE");
if (hf && *hf && file_exists (hf))
{
/* Append only the lines that occurred this session to
the history file. */
using_history ();
if (history_lines_this_session <= where_history () || force_append_history)
r = append_history (history_lines_this_session, hf);
else
r = write_history (hf);
sv_histsize ("HISTFILESIZE");
}
}
#endif
int
maybe_append_history (filename)
char *filename;
{
int fd, result;
struct stat buf;
result = EXECUTION_SUCCESS;
if (history_lines_this_session && (history_lines_this_session <= where_history ()))
{
/* If the filename was supplied, then create it if necessary. */
if (stat (filename, &buf) == -1 && errno == ENOENT)
{
fd = open (filename, O_WRONLY|O_CREAT, 0600);
if (fd < 0)
{
builtin_error (_("%s: cannot create: %s"), filename, strerror (errno));
return (EXECUTION_FAILURE);
}
close (fd);
}
result = append_history (history_lines_this_session, filename);
history_lines_in_file += history_lines_this_session;
history_lines_this_session = 0;
}
return (result);
}
/* If this is an interactive shell, then append the lines executed
this session to the history file. */
int
maybe_save_shell_history ()
{
int result;
char *hf;
result = 0;
if (history_lines_this_session)
{
hf = get_string_value ("HISTFILE");
if (hf && *hf)
{
/* If the file doesn't exist, then create it. */
if (file_exists (hf) == 0)
{
int file;
file = open (hf, O_CREAT | O_TRUNC | O_WRONLY, 0600);
if (file != -1)
close (file);
}
/* Now actually append the lines if the history hasn't been
stifled. If the history has been stifled, rewrite the
history file. */
using_history ();
if (history_lines_this_session <= where_history () || force_append_history)
{
result = append_history (history_lines_this_session, hf);
history_lines_in_file += history_lines_this_session;
}
else
{
result = write_history (hf);
history_lines_in_file = history_lines_this_session;
}
history_lines_this_session = 0;
sv_histsize ("HISTFILESIZE");
}
}
return (result);
}
#if defined (READLINE)
/* Tell readline () that we have some text for it to edit. */
static void
re_edit (text)
char *text;
{
if (bash_input.type == st_stdin)
bash_re_edit (text);
}
#endif /* READLINE */
/* Return 1 if this line needs history expansion. */
static int
history_expansion_p (line)
char *line;
{
register char *s;
for (s = line; *s; s++)
if (*s == history_expansion_char || *s == history_subst_char)
return 1;
return 0;
}
/* Do pre-processing on LINE. If PRINT_CHANGES is non-zero, then
print the results of expanding the line if there were any changes.
If there is an error, return NULL, otherwise the expanded line is
returned. If ADDIT is non-zero the line is added to the history
list after history expansion. ADDIT is just a suggestion;
REMEMBER_ON_HISTORY can veto, and does.
Right now this does history expansion. */
char *
pre_process_line (line, print_changes, addit)
char *line;
int print_changes, addit;
{
char *history_value;
char *return_value;
int expanded;
return_value = line;
expanded = 0;
# if defined (BANG_HISTORY)
/* History expand the line. If this results in no errors, then
add that line to the history if ADDIT is non-zero. */
if (!history_expansion_inhibited && history_expansion && history_expansion_p (line))
{
expanded = history_expand (line, &history_value);
if (expanded)
{
if (print_changes)
{
if (expanded < 0)
internal_error ("%s", history_value);
#if defined (READLINE)
else if (hist_verify == 0 || expanded == 2)
#else
else
#endif
fprintf (stderr, "%s\n", history_value);
}
/* If there was an error, return NULL. */
if (expanded < 0 || expanded == 2) /* 2 == print only */
{
# if defined (READLINE)
if (expanded == 2 && rl_dispatching == 0 && *history_value)
# else
if (expanded == 2 && *history_value)
# endif /* !READLINE */
maybe_add_history (history_value);
free (history_value);
# if defined (READLINE)
/* New hack. We can allow the user to edit the
failed history expansion. */
if (history_reediting && expanded < 0 && rl_done)
re_edit (line);
# endif /* READLINE */
return ((char *)NULL);
}
# if defined (READLINE)
if (hist_verify && expanded == 1)
{
re_edit (history_value);
return ((char *)NULL);
}
# endif
}
/* Let other expansions know that return_value can be free'ed,
and that a line has been added to the history list. Note
that we only add lines that have something in them. */
expanded = 1;
return_value = history_value;
}
# endif /* BANG_HISTORY */
if (addit && remember_on_history && *return_value)
maybe_add_history (return_value);
#if 0
if (expanded == 0)
return_value = savestring (line);
#endif
return (return_value);
}
/* Return 1 if the first non-whitespace character in LINE is a `#', indicating
* that the line is a shell comment. */
static int
shell_comment (line)
char *line;
{
char *p;
for (p = line; p && *p && whitespace (*p); p++)
;
return (p && *p == '#');
}
#ifdef INCLUDE_UNUSED
/* Remove shell comments from LINE. A `#' and anything after it is a comment.
This isn't really useful yet, since it doesn't handle quoting. */
static char *
filter_comments (line)
char *line;
{
char *p;
for (p = line; p && *p && *p != '#'; p++)
;
if (p && *p == '#')
*p = '\0';
return (line);
}
#endif
/* Check LINE against what HISTCONTROL says to do. Returns 1 if the line
should be saved; 0 if it should be discarded. */
static int
check_history_control (line)
char *line;
{
HIST_ENTRY *temp;
int r;
if (history_control == 0)
return 1;
/* ignorespace or ignoreboth */
if ((history_control & HC_IGNSPACE) && *line == ' ')
return 0;
/* ignoredups or ignoreboth */
if (history_control & HC_IGNDUPS)
{
using_history ();
temp = previous_history ();
r = (temp == 0 || STREQ (temp->line, line) == 0);
using_history ();
if (r == 0)
return r;
}
return 1;
}
/* Remove all entries matching LINE from the history list. Triggered when
HISTCONTROL includes `erasedups'. */
static void
hc_erasedups (line)
char *line;
{
HIST_ENTRY *temp;
int r;
using_history ();
while (temp = previous_history ())
{
if (STREQ (temp->line, line))
{
r = where_history ();
remove_history (r);
}
}
using_history ();
}
/* Add LINE to the history list, handling possibly multi-line compound
commands. We note whether or not we save the first line of each command
(which is usually the entire command and history entry), and don't add
the second and subsequent lines of a multi-line compound command if we
didn't save the first line. We don't usually save shell comment lines in
compound commands in the history, because they could have the effect of
commenting out the rest of the command when the entire command is saved as
a single history entry (when COMMAND_ORIENTED_HISTORY is enabled). If
LITERAL_HISTORY is set, we're saving lines in the history with embedded
newlines, so it's OK to save comment lines. If we're collecting the body
of a here-document, we should act as if literal_history is enabled, because
we want to save the entire contents of the here-document as it was
entered. We also make sure to save multiple-line quoted strings or other
constructs. */
void
maybe_add_history (line)
char *line;
{
hist_last_line_added = 0;
/* Don't use the value of history_control to affect the second
and subsequent lines of a multi-line command (old code did
this only when command_oriented_history is enabled). */
if (current_command_line_count > 1)
{
if (current_command_first_line_saved &&
((parser_state & PST_HEREDOC) || literal_history || dstack.delimiter_depth != 0 || shell_comment (line) == 0))
bash_add_history (line);
return;
}
/* This is the first line of a (possible multi-line) command. Note whether
or not we should save the first line and remember it. */
current_command_first_line_saved = check_add_history (line, 0);
}
/* Just check LINE against HISTCONTROL and HISTIGNORE and add it to the
history if it's OK. Used by `history -s' as well as maybe_add_history().
Returns 1 if the line was saved in the history, 0 otherwise. */
int
check_add_history (line, force)
char *line;
int force;
{
if (check_history_control (line) && history_should_ignore (line) == 0)
{
/* We're committed to saving the line. If the user has requested it,
remove other matching lines from the history. */
if (history_control & HC_ERASEDUPS)
hc_erasedups (line);
if (force)
{
really_add_history (line);
using_history ();
}
else
bash_add_history (line);
return 1;
}
return 0;
}
#if defined (SYSLOG_HISTORY)
#define SYSLOG_MAXLEN 600
void
bash_syslog_history (line)
const char *line;
{
char trunc[SYSLOG_MAXLEN];
if (strlen(line) < SYSLOG_MAXLEN)
syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY: PID=%d UID=%d %s", getpid(), current_user.uid, line);
else
{
strncpy (trunc, line, SYSLOG_MAXLEN);
trunc[SYSLOG_MAXLEN - 1] = '\0';
syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY (TRUNCATED): PID=%d UID=%d %s", getpid(), current_user.uid, trunc);
}
}
#endif
/* Add a line to the history list.
The variable COMMAND_ORIENTED_HISTORY controls the style of history
remembering; when non-zero, and LINE is not the first line of a
complete parser construct, append LINE to the last history line instead
of adding it as a new line. */
void
bash_add_history (line)
char *line;
{
int add_it, offset, curlen;
HIST_ENTRY *current, *old;
char *chars_to_add, *new_line;
add_it = 1;
if (command_oriented_history && current_command_line_count > 1)
{
/* The second and subsequent lines of a here document have the trailing
newline preserved. We don't want to add extra newlines here, but we
do want to add one after the first line (which is the command that
contains the here-doc specifier). parse.y:history_delimiting_chars()
does the right thing to take care of this for us. We don't want to
add extra newlines if the user chooses to enable literal_history,
so we have to duplicate some of what that function does here. */
if ((parser_state & PST_HEREDOC) && literal_history && current_command_line_count > 2 && line[strlen (line) - 1] == '\n')
chars_to_add = "";
else
chars_to_add = literal_history ? "\n" : history_delimiting_chars (line);
using_history ();
current = previous_history ();
if (current)
{
/* If the previous line ended with an escaped newline (escaped
with backslash, but otherwise unquoted), then remove the quoted
newline, since that is what happens when the line is parsed. */
curlen = strlen (current->line);
if (dstack.delimiter_depth == 0 && current->line[curlen - 1] == '\\' &&
current->line[curlen - 2] != '\\')
{
current->line[curlen - 1] = '\0';
curlen--;
chars_to_add = "";
}
/* If we're not in some kind of quoted construct, the current history
entry ends with a newline, and we're going to add a semicolon,
don't. In some cases, it results in a syntax error (e.g., before
a close brace), and it should not be needed. */
if (dstack.delimiter_depth == 0 && current->line[curlen - 1] == '\n' && *chars_to_add == ';')
chars_to_add++;
new_line = (char *)xmalloc (1
+ curlen
+ strlen (line)
+ strlen (chars_to_add));
sprintf (new_line, "%s%s%s", current->line, chars_to_add, line);
offset = where_history ();
old = replace_history_entry (offset, new_line, current->data);
free (new_line);
if (old)
free_history_entry (old);
add_it = 0;
}
}
if (add_it)
really_add_history (line);
#if defined (SYSLOG_HISTORY)
bash_syslog_history (line);
#endif
using_history ();
}
static void
really_add_history (line)
char *line;
{
hist_last_line_added = 1;
hist_last_line_pushed = 0;
add_history (line);
history_lines_this_session++;
}
int
history_number ()
{
using_history ();
return (remember_on_history ? history_base + where_history () : 1);
}
static int
should_expand (s)
char *s;
{
char *p;
for (p = s; p && *p; p++)
{
if (*p == '\\')
p++;
else if (*p == '&')
return 1;
}
return 0;
}
static int
histignore_item_func (ign)
struct ign *ign;
{
if (should_expand (ign->val))
ign->flags |= HIGN_EXPAND;
return (0);
}
void
setup_history_ignore (varname)
char *varname;
{
setup_ignore_patterns (&histignore);
}
static HIST_ENTRY *
last_history_entry ()
{
HIST_ENTRY *he;
using_history ();
he = previous_history ();
using_history ();
return he;
}
char *
last_history_line ()
{
HIST_ENTRY *he;
he = last_history_entry ();
if (he == 0)
return ((char *)NULL);
return he->line;
}
static char *
expand_histignore_pattern (pat)
char *pat;
{
HIST_ENTRY *phe;
char *ret;
phe = last_history_entry ();
if (phe == (HIST_ENTRY *)0)
return (savestring (pat));
ret = strcreplace (pat, '&', phe->line, 1);
return ret;
}
/* Return 1 if we should not put LINE into the history according to the
patterns in HISTIGNORE. */
static int
history_should_ignore (line)
char *line;
{
register int i, match;
char *npat;
if (histignore.num_ignores == 0)
return 0;
for (i = match = 0; i < histignore.num_ignores; i++)
{
if (histignore.ignores[i].flags & HIGN_EXPAND)
npat = expand_histignore_pattern (histignore.ignores[i].val);
else
npat = histignore.ignores[i].val;
match = strmatch (npat, line, FNMATCH_EXTFLAG) != FNM_NOMATCH;
if (histignore.ignores[i].flags & HIGN_EXPAND)
free (npat);
if (match)
break;
}
return match;
}
#endif /* HISTORY */
bash-4.3/bashhist.h 0000644 0001750 0000144 00000004641 11130207306 013124 0 ustar doko users /* bashhist.h -- interface to the bash history functions in bashhist.c. */
/* Copyright (C) 1993-2009 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 3 of the License, 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. If not, see .
*/
#if !defined (_BASHHIST_H_)
#define _BASHHIST_H_
#include "stdc.h"
/* Flag values for history_control */
#define HC_IGNSPACE 0x01
#define HC_IGNDUPS 0x02
#define HC_ERASEDUPS 0x04
#define HC_IGNBOTH (HC_IGNSPACE|HC_IGNDUPS)
extern int remember_on_history;
extern int enable_history_list; /* value for `set -o history' */
extern int literal_history; /* controlled by `shopt lithist' */
extern int force_append_history;
extern int history_lines_this_session;
extern int history_lines_in_file;
extern int history_expansion;
extern int history_control;
extern int command_oriented_history;
extern int current_command_first_line_saved;
extern int hist_last_line_added;
extern int hist_last_line_pushed;
# if defined (BANG_HISTORY)
extern int history_expansion_inhibited;
# endif /* BANG_HISTORY */
extern void bash_initialize_history __P((void));
extern void bash_history_reinit __P((int));
extern void bash_history_disable __P((void));
extern void bash_history_enable __P((void));
extern void bash_clear_history __P((void));
extern int bash_delete_histent __P((int));
extern int bash_delete_last_history __P((void));
extern void load_history __P((void));
extern void save_history __P((void));
extern int maybe_append_history __P((char *));
extern int maybe_save_shell_history __P((void));
extern char *pre_process_line __P((char *, int, int));
extern void maybe_add_history __P((char *));
extern void bash_add_history __P((char *));
extern int check_add_history __P((char *, int));
extern int history_number __P((void));
extern void setup_history_ignore __P((char *));
extern char *last_history_line __P((void));
#endif /* _BASHHIST_H_ */
bash-4.3/hashcmd.h 0000644 0001750 0000144 00000002660 11130207315 012725 0 ustar doko users /* hashcmd.h - Common defines for hashing filenames. */
/* Copyright (C) 1993-2009 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 3 of the License, 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. If not, see .
*/
#include "stdc.h"
#include "hashlib.h"
#define FILENAME_HASH_BUCKETS 64 /* must be power of two */
extern HASH_TABLE *hashed_filenames;
typedef struct _pathdata {
char *path; /* The full pathname of the file. */
int flags;
} PATH_DATA;
#define HASH_RELPATH 0x01 /* this filename is a relative pathname. */
#define HASH_CHKDOT 0x02 /* check `.' since it was earlier in $PATH */
#define pathdata(x) ((PATH_DATA *)(x)->data)
extern void phash_create __P((void));
extern void phash_flush __P((void));
extern void phash_insert __P((char *, char *, int, int));
extern int phash_remove __P((const char *));
extern char *phash_search __P((const char *));
bash-4.3/INSTALL 0000644 0001750 0000144 00000041415 12216323744 012212 0 ustar doko users Basic Installation
==================
These are installation instructions for Bash.
The simplest way to compile Bash is:
1. `cd' to the directory containing the source code and type
`./configure' to configure Bash for your system. If you're using
`csh' on an old version of System V, you might need to type `sh
./configure' instead to prevent `csh' from trying to execute
`configure' itself.
Running `configure' takes some time. While running, it prints
messages telling which features it is checking for.
2. Type `make' to compile Bash and build the `bashbug' bug reporting
script.
3. Optionally, type `make tests' to run the Bash test suite.
4. Type `make install' to install `bash' and `bashbug'. This will
also install the manual pages and Info file.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package
(the top directory, the `builtins', `doc', and `support' directories,
each directory under `lib', and several others). It also creates a
`config.h' file containing system-dependent definitions. Finally, it
creates a shell script named `config.status' that you can run in the
future to recreate the current configuration, a file `config.cache'
that saves the results of its tests to speed up reconfiguring, and a
file `config.log' containing compiler output (useful mainly for
debugging `configure'). If at some point `config.cache' contains
results you don't want to keep, you may remove or edit it.
To find out more about the options and arguments that the `configure'
script understands, type
bash-2.04$ ./configure --help
at the Bash prompt in your Bash source directory.
If you need to do unusual things to compile Bash, please try to figure
out how `configure' could check whether or not to do them, and mail
diffs or instructions to so they can be
considered for the next release.
The file `configure.ac' is used to create `configure' by a program
called Autoconf. You only need `configure.ac' if you want to change it
or regenerate `configure' using a newer version of Autoconf. If you do
this, make sure you are using Autoconf version 2.50 or newer.
You can remove the program binaries and object files from the source
code directory by typing `make clean'. To also remove the files that
`configure' created (so you can compile Bash for a different kind of
computer), type `make distclean'.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
the `configure' script does not know about. You can give `configure'
initial values for variables by setting them in the environment. Using
a Bourne-compatible shell, you can do that on the command line like
this:
CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
On systems that have the `env' program, you can do it like this:
env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
The configuration process uses GCC to build Bash if it is available.
Compiling For Multiple Architectures
====================================
You can compile Bash for more than one kind of computer at the same
time, by placing the object files for each architecture in their own
directory. To do this, you must use a version of `make' that supports
the `VPATH' variable, such as GNU `make'. `cd' to the directory where
you want the object files and executables to go and run the `configure'
script from the source directory. You may need to supply the
`--srcdir=PATH' argument to tell `configure' where the source files
are. `configure' automatically checks for the source code in the
directory that `configure' is in and in `..'.
If you have to use a `make' that does not supports the `VPATH'
variable, you can compile Bash for one architecture at a time in the
source code directory. After you have installed Bash for one
architecture, use `make distclean' before reconfiguring for another
architecture.
Alternatively, if your system supports symbolic links, you can use the
`support/mkclone' script to create a build tree which has symbolic
links back to each file in the source directory. Here's an example
that creates a build directory in the current directory from a source
directory `/usr/gnu/src/bash-2.0':
bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
The `mkclone' script requires Bash, so you must have already built Bash
for at least one architecture before you can create build directories
for other architectures.
Installation Names
==================
By default, `make install' will install into `/usr/local/bin',
`/usr/local/man', etc. You can specify an installation prefix other
than `/usr/local' by giving `configure' the option `--prefix=PATH', or
by specifying a value for the `DESTDIR' `make' variable when running
`make install'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
give `configure' the option `--exec-prefix=PATH', `make install' will
use PATH as the prefix for installing programs and libraries.
Documentation and other data files will still use the regular prefix.
Specifying the System Type
==========================
There may be some features `configure' can not figure out
automatically, but need to determine by the type of host Bash will run
on. Usually `configure' can figure that out, but if it prints a
message saying it can not guess the host type, give it the
`--host=TYPE' option. `TYPE' can either be a short name for the system
type, such as `sun4', or a canonical name with three fields:
`CPU-COMPANY-SYSTEM' (e.g., `i386-unknown-freebsd4.2').
See the file `support/config.sub' for the possible values of each field.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share, you
can create a site shell script called `config.site' that gives default
values for variables like `CC', `cache_file', and `prefix'. `configure'
looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: the Bash `configure' looks for a site script, but not all
`configure' scripts do.
Operation Controls
==================
`configure' recognizes the following options to control how it operates.
`--cache-file=FILE'
Use and save the results of the tests in FILE instead of
`./config.cache'. Set FILE to `/dev/null' to disable caching, for
debugging `configure'.
`--help'
Print a summary of the options to `configure', and exit.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made.
`--srcdir=DIR'
Look for the Bash source code in directory DIR. Usually
`configure' can determine that directory automatically.
`--version'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`configure' also accepts some other, not widely used, boilerplate
options. `configure --help' prints the complete list.
Optional Features
=================
The Bash `configure' has a number of `--enable-FEATURE' options, where
FEATURE indicates an optional part of Bash. There are also several
`--with-PACKAGE' options, where PACKAGE is something like `bash-malloc'
or `purify'. To turn off the default use of a package, use
`--without-PACKAGE'. To configure Bash without a feature that is
enabled by default, use `--disable-FEATURE'.
Here is a complete list of the `--enable-' and `--with-' options that
the Bash `configure' recognizes.
`--with-afs'
Define if you are using the Andrew File System from Transarc.
`--with-bash-malloc'
Use the Bash version of `malloc' in the directory `lib/malloc'.
This is not the same `malloc' that appears in GNU libc, but an
older version originally derived from the 4.2 BSD `malloc'. This
`malloc' is very fast, but wastes some space on each allocation.
This option is enabled by default. The `NOTES' file contains a
list of systems for which this should be turned off, and
`configure' disables this option automatically for a number of
systems.
`--with-curses'
Use the curses library instead of the termcap library. This should
be supplied if your system has an inadequate or incomplete termcap
database.
`--with-gnu-malloc'
A synonym for `--with-bash-malloc'.
`--with-installed-readline[=PREFIX]'
Define this to make Bash link with a locally-installed version of
Readline rather than the version in `lib/readline'. This works
only with Readline 5.0 and later versions. If PREFIX is `yes' or
not supplied, `configure' uses the values of the make variables
`includedir' and `libdir', which are subdirectories of `prefix' by
default, to find the installed version of Readline if it is not in
the standard system include and library directories. If PREFIX is
`no', Bash links with the version in `lib/readline'. If PREFIX is
set to any other value, `configure' treats it as a directory
pathname and looks for the installed version of Readline in
subdirectories of that directory (include files in
PREFIX/`include' and the library in PREFIX/`lib').
`--with-purify'
Define this to use the Purify memory allocation checker from
Rational Software.
`--enable-minimal-config'
This produces a shell with minimal features, close to the
historical Bourne shell.
There are several `--enable-' options that alter how Bash is compiled
and linked, rather than changing run-time features.
`--enable-largefile'
Enable support for large files
(http://www.sas.com/standards/large_file/x_open.20Mar96.html) if
the operating system requires special compiler options to build
programs which can access large files. This is enabled by
default, if the operating system provides large file support.
`--enable-profiling'
This builds a Bash binary that produces profiling information to be
processed by `gprof' each time it is executed.
`--enable-static-link'
This causes Bash to be linked statically, if `gcc' is being used.
This could be used to build a version to use as root's shell.
The `minimal-config' option can be used to disable all of the following
options, but it is processed first, so individual options may be
enabled using `enable-FEATURE'.
All of the following options except for `disabled-builtins',
`directpand-default', and `xpg-echo-default' are enabled by default,
unless the operating system does not provide the necessary support.
`--enable-alias'
Allow alias expansion and include the `alias' and `unalias'
builtins (*note Aliases::).
`--enable-arith-for-command'
Include support for the alternate form of the `for' command that
behaves like the C language `for' statement (*note Looping
Constructs::).
`--enable-array-variables'
Include support for one-dimensional array shell variables (*note
Arrays::).
`--enable-bang-history'
Include support for `csh'-like history substitution (*note History
Interaction::).
`--enable-brace-expansion'
Include `csh'-like brace expansion ( `b{a,b}c' ==> `bac bbc' ).
See *note Brace Expansion::, for a complete description.
`--enable-casemod-attributes'
Include support for case-modifying attributes in the `declare'
builtin and assignment statements. Variables with the UPPERCASE
attribute, for example, will have their values converted to
uppercase upon assignment.
`--enable-casemod-expansion'
Include support for case-modifying word expansions.
`--enable-command-timing'
Include support for recognizing `time' as a reserved word and for
displaying timing statistics for the pipeline following `time'
(*note Pipelines::). This allows pipelines as well as shell
builtins and functions to be timed.
`--enable-cond-command'
Include support for the `[[' conditional command. (*note
Conditional Constructs::).
`--enable-cond-regexp'
Include support for matching POSIX regular expressions using the
`=~' binary operator in the `[[' conditional command. (*note
Conditional Constructs::).
`--enable-coprocesses'
Include support for coprocesses and the `coproc' reserved word
(*note Pipelines::).
`--enable-debugger'
Include support for the bash debugger (distributed separately).
`--enable-direxpand-default'
Cause the `direxpand' shell option (*note The Shopt Builtin::) to
be enabled by default when the shell starts. It is normally
disabled by default.
`--enable-directory-stack'
Include support for a `csh'-like directory stack and the `pushd',
`popd', and `dirs' builtins (*note The Directory Stack::).
`--enable-disabled-builtins'
Allow builtin commands to be invoked via `builtin xxx' even after
`xxx' has been disabled using `enable -n xxx'. See *note Bash
Builtins::, for details of the `builtin' and `enable' builtin
commands.
`--enable-dparen-arithmetic'
Include support for the `((...))' command (*note Conditional
Constructs::).
`--enable-extended-glob'
Include support for the extended pattern matching features
described above under *note Pattern Matching::.
`--enable-extended-glob-default'
Set the default value of the EXTGLOB shell option described above
under *note The Shopt Builtin:: to be enabled.
`--enable-glob-asciirange-default'
Set the default value of the GLOBASCIIRANGES shell option described
above under *note The Shopt Builtin:: to be enabled. This
controls the behavior of character ranges when used in pattern
matching bracket expressions.
`--enable-help-builtin'
Include the `help' builtin, which displays help on shell builtins
and variables (*note Bash Builtins::).
`--enable-history'
Include command history and the `fc' and `history' builtin
commands (*note Bash History Facilities::).
`--enable-job-control'
This enables the job control features (*note Job Control::), if
the operating system supports them.
`--enable-multibyte'
This enables support for multibyte characters if the operating
system provides the necessary support.
`--enable-net-redirections'
This enables the special handling of filenames of the form
`/dev/tcp/HOST/PORT' and `/dev/udp/HOST/PORT' when used in
redirections (*note Redirections::).
`--enable-process-substitution'
This enables process substitution (*note Process Substitution::) if
the operating system provides the necessary support.
`--enable-progcomp'
Enable the programmable completion facilities (*note Programmable
Completion::). If Readline is not enabled, this option has no
effect.
`--enable-prompt-string-decoding'
Turn on the interpretation of a number of backslash-escaped
characters in the `$PS1', `$PS2', `$PS3', and `$PS4' prompt
strings. See *note Controlling the Prompt::, for a complete list
of prompt string escape sequences.
`--enable-readline'
Include support for command-line editing and history with the Bash
version of the Readline library (*note Command Line Editing::).
`--enable-restricted'
Include support for a "restricted shell". If this is enabled,
Bash, when called as `rbash', enters a restricted mode. See *note
The Restricted Shell::, for a description of restricted mode.
`--enable-select'
Include the `select' compound command, which allows the generation
of simple menus (*note Conditional Constructs::).
`--enable-separate-helpfiles'
Use external files for the documentation displayed by the `help'
builtin instead of storing the text internally.
`--enable-single-help-strings'
Store the text displayed by the `help' builtin as a single string
for each help topic. This aids in translating the text to
different languages. You may need to disable this if your
compiler cannot handle very long string literals.
`--enable-strict-posix-default'
Make Bash POSIX-conformant by default (*note Bash POSIX Mode::).
`--enable-usg-echo-default'
A synonym for `--enable-xpg-echo-default'.
`--enable-xpg-echo-default'
Make the `echo' builtin expand backslash-escaped characters by
default, without requiring the `-e' option. This sets the default
value of the `xpg_echo' shell option to `on', which makes the Bash
`echo' behave more like the version specified in the Single Unix
Specification, version 3. *Note Bash Builtins::, for a
description of the escape sequences that `echo' recognizes.
The file `config-top.h' contains C Preprocessor `#define' statements
for options which are not settable from `configure'. Some of these are
not meant to be changed; beware of the consequences if you do. Read
the comments associated with each definition for more information about
its effect.
bash-4.3/array.c 0000644 0001750 0000144 00000057337 11732352110 012444 0 ustar doko users /*
* array.c - functions to create, destroy, access, and manipulate arrays
* of strings.
*
* Arrays are sparse doubly-linked lists. An element's index is stored
* with it.
*
* Chet Ramey
* chet@ins.cwru.edu
*/
/* Copyright (C) 1997-2009 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 3 of the License, 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. If not, see .
*/
#include "config.h"
#if defined (ARRAY_VARS)
#if defined (HAVE_UNISTD_H)
# ifdef _MINIX
# include
# endif
# include
#endif
#include
#include "bashansi.h"
#include "shell.h"
#include "array.h"
#include "builtins/common.h"
#define ADD_BEFORE(ae, new) \
do { \
ae->prev->next = new; \
new->prev = ae->prev; \
ae->prev = new; \
new->next = ae; \
} while(0)
static char *array_to_string_internal __P((ARRAY_ELEMENT *, ARRAY_ELEMENT *, char *, int));
static ARRAY *lastarray = 0;
static ARRAY_ELEMENT *lastref = 0;
#define IS_LASTREF(a) (lastarray && (a) == lastarray)
#define LASTREF_START(a, i) \
(IS_LASTREF(a) && i >= element_index(lastref)) ? lastref \
: element_forw(a->head)
#define INVALIDATE_LASTREF(a) \
do { \
if ((a) == lastarray) { \
lastarray = 0; \
lastref = 0; \
} \
} while (0)
#define SET_LASTREF(a, e) \
do { \
lastarray = (a); \
lastref = (e); \
} while (0)
#define UNSET_LASTREF() \
do { \
lastarray = 0; \
lastref = 0; \
} while (0)
ARRAY *
array_create()
{
ARRAY *r;
ARRAY_ELEMENT *head;
r =(ARRAY *)xmalloc(sizeof(ARRAY));
r->type = array_indexed;
r->max_index = -1;
r->num_elements = 0;
head = array_create_element(-1, (char *)NULL); /* dummy head */
head->prev = head->next = head;
r->head = head;
return(r);
}
void
array_flush (a)
ARRAY *a;
{
register ARRAY_ELEMENT *r, *r1;
if (a == 0)
return;
for (r = element_forw(a->head); r != a->head; ) {
r1 = element_forw(r);
array_dispose_element(r);
r = r1;
}
a->head->next = a->head->prev = a->head;
a->max_index = -1;
a->num_elements = 0;
INVALIDATE_LASTREF(a);
}
void
array_dispose(a)
ARRAY *a;
{
if (a == 0)
return;
array_flush (a);
array_dispose_element(a->head);
free(a);
}
ARRAY *
array_copy(a)
ARRAY *a;
{
ARRAY *a1;
ARRAY_ELEMENT *ae, *new;
if (a == 0)
return((ARRAY *) NULL);
a1 = array_create();
a1->type = a->type;
a1->max_index = a->max_index;
a1->num_elements = a->num_elements;
for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae)) {
new = array_create_element(element_index(ae), element_value(ae));
ADD_BEFORE(a1->head, new);
}
return(a1);
}
/*
* Make and return a new array composed of the elements in array A from
* S to E, inclusive.
*/
ARRAY *
array_slice(array, s, e)
ARRAY *array;
ARRAY_ELEMENT *s, *e;
{
ARRAY *a;
ARRAY_ELEMENT *p, *n;
int i;
arrayind_t mi;
a = array_create ();
a->type = array->type;
for (mi = 0, p = s, i = 0; p != e; p = element_forw(p), i++) {
n = array_create_element (element_index(p), element_value(p));
ADD_BEFORE(a->head, n);
mi = element_index(n);
}
a->num_elements = i;
a->max_index = mi;
return a;
}
/*
* Walk the array, calling FUNC once for each element, with the array
* element as the argument.
*/
void
array_walk(a, func, udata)
ARRAY *a;
sh_ae_map_func_t *func;
void *udata;
{
register ARRAY_ELEMENT *ae;
if (a == 0 || array_empty(a))
return;
for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae))
if ((*func)(ae, udata) < 0)
return;
}
/*
* Shift the array A N elements to the left. Delete the first N elements
* and subtract N from the indices of the remaining elements. If FLAGS
* does not include AS_DISPOSE, this returns a singly-linked null-terminated
* list of elements so the caller can dispose of the chain. If FLAGS
* includes AS_DISPOSE, this function disposes of the shifted-out elements
* and returns NULL.
*/
ARRAY_ELEMENT *
array_shift(a, n, flags)
ARRAY *a;
int n, flags;
{
register ARRAY_ELEMENT *ae, *ret;
register int i;
if (a == 0 || array_empty(a) || n <= 0)
return ((ARRAY_ELEMENT *)NULL);
INVALIDATE_LASTREF(a);
for (i = 0, ret = ae = element_forw(a->head); ae != a->head && i < n; ae = element_forw(ae), i++)
;
if (ae == a->head) {
/* Easy case; shifting out all of the elements */
if (flags & AS_DISPOSE) {
array_flush (a);
return ((ARRAY_ELEMENT *)NULL);
}
for (ae = ret; element_forw(ae) != a->head; ae = element_forw(ae))
;
element_forw(ae) = (ARRAY_ELEMENT *)NULL;
a->head->next = a->head->prev = a->head;
a->max_index = -1;
a->num_elements = 0;
return ret;
}
/*
* ae now points to the list of elements we want to retain.
* ret points to the list we want to either destroy or return.
*/
ae->prev->next = (ARRAY_ELEMENT *)NULL; /* null-terminate RET */
a->head->next = ae; /* slice RET out of the array */
ae->prev = a->head;
for ( ; ae != a->head; ae = element_forw(ae))
element_index(ae) -= n; /* renumber retained indices */
a->num_elements -= n; /* modify bookkeeping information */
a->max_index = element_index(a->head->prev);
if (flags & AS_DISPOSE) {
for (ae = ret; ae; ) {
ret = element_forw(ae);
array_dispose_element(ae);
ae = ret;
}
return ((ARRAY_ELEMENT *)NULL);
}
return ret;
}
/*
* Shift array A right N indices. If S is non-null, it becomes the value of
* the new element 0. Returns the number of elements in the array after the
* shift.
*/
int
array_rshift (a, n, s)
ARRAY *a;
int n;
char *s;
{
register ARRAY_ELEMENT *ae, *new;
if (a == 0 || (array_empty(a) && s == 0))
return 0;
else if (n <= 0)
return (a->num_elements);
ae = element_forw(a->head);
if (s) {
new = array_create_element(0, s);
ADD_BEFORE(ae, new);
a->num_elements++;
if (array_num_elements(a) == 1) { /* array was empty */
a->max_index = 0;
return 1;
}
}
/*
* Renumber all elements in the array except the one we just added.
*/
for ( ; ae != a->head; ae = element_forw(ae))
element_index(ae) += n;
a->max_index = element_index(a->head->prev);
INVALIDATE_LASTREF(a);
return (a->num_elements);
}
ARRAY_ELEMENT *
array_unshift_element(a)
ARRAY *a;
{
return (array_shift (a, 1, 0));
}
int
array_shift_element(a, v)
ARRAY *a;
char *v;
{
return (array_rshift (a, 1, v));
}
ARRAY *
array_quote(array)
ARRAY *array;
{
ARRAY_ELEMENT *a;
char *t;
if (array == 0 || array_head(array) == 0 || array_empty(array))
return (ARRAY *)NULL;
for (a = element_forw(array->head); a != array->head; a = element_forw(a)) {
t = quote_string (a->value);
FREE(a->value);
a->value = t;
}
return array;
}
ARRAY *
array_quote_escapes(array)
ARRAY *array;
{
ARRAY_ELEMENT *a;
char *t;
if (array == 0 || array_head(array) == 0 || array_empty(array))
return (ARRAY *)NULL;
for (a = element_forw(array->head); a != array->head; a = element_forw(a)) {
t = quote_escapes (a->value);
FREE(a->value);
a->value = t;
}
return array;
}
ARRAY *
array_dequote(array)
ARRAY *array;
{
ARRAY_ELEMENT *a;
char *t;
if (array == 0 || array_head(array) == 0 || array_empty(array))
return (ARRAY *)NULL;
for (a = element_forw(array->head); a != array->head; a = element_forw(a)) {
t = dequote_string (a->value);
FREE(a->value);
a->value = t;
}
return array;
}
ARRAY *
array_dequote_escapes(array)
ARRAY *array;
{
ARRAY_ELEMENT *a;
char *t;
if (array == 0 || array_head(array) == 0 || array_empty(array))
return (ARRAY *)NULL;
for (a = element_forw(array->head); a != array->head; a = element_forw(a)) {
t = dequote_escapes (a->value);
FREE(a->value);
a->value = t;
}
return array;
}
ARRAY *
array_remove_quoted_nulls(array)
ARRAY *array;
{
ARRAY_ELEMENT *a;
char *t;
if (array == 0 || array_head(array) == 0 || array_empty(array))
return (ARRAY *)NULL;
for (a = element_forw(array->head); a != array->head; a = element_forw(a))
a->value = remove_quoted_nulls (a->value);
return array;
}
/*
* Return a string whose elements are the members of array A beginning at
* index START and spanning NELEM members. Null elements are counted.
* Since arrays are sparse, unset array elements are not counted.
*/
char *
array_subrange (a, start, nelem, starsub, quoted)
ARRAY *a;
arrayind_t start, nelem;
int starsub, quoted;
{
ARRAY *a2;
ARRAY_ELEMENT *h, *p;
arrayind_t i;
char *ifs, *sifs, *t;
int slen;
p = a ? array_head (a) : 0;
if (p == 0 || array_empty (a) || start > array_max_index(a))
return ((char *)NULL);
/*
* Find element with index START. If START corresponds to an unset
* element (arrays can be sparse), use the first element whose index
* is >= START. If START is < 0, we count START indices back from
* the end of A (not elements, even with sparse arrays -- START is an
* index).
*/
for (p = element_forw(p); p != array_head(a) && start > element_index(p); p = element_forw(p))
;
if (p == a->head)
return ((char *)NULL);
/* Starting at P, take NELEM elements, inclusive. */
for (i = 0, h = p; p != a->head && i < nelem; i++, p = element_forw(p))
;
a2 = array_slice(a, h, p);
if (quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT))
array_quote(a2);
else
array_quote_escapes(a2);
if (starsub && (quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT))) {
/* ${array[*]} */
array_remove_quoted_nulls (a2);
sifs = ifs_firstchar ((int *)NULL);
t = array_to_string (a2, sifs, 0);
free (sifs);
} else if (quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT)) {
/* ${array[@]} */
sifs = ifs_firstchar (&slen);
ifs = getifs ();
if (ifs == 0 || *ifs == 0) {
if (slen < 2)
sifs = xrealloc(sifs, 2);
sifs[0] = ' ';
sifs[1] = '\0';
}
t = array_to_string (a2, sifs, 0);
free (sifs);
} else
t = array_to_string (a2, " ", 0);
array_dispose(a2);
return t;
}
char *
array_patsub (a, pat, rep, mflags)
ARRAY *a;
char *pat, *rep;
int mflags;
{
ARRAY *a2;
ARRAY_ELEMENT *e;
char *t, *sifs, *ifs;
int slen;
if (a == 0 || array_head(a) == 0 || array_empty(a))
return ((char *)NULL);
a2 = array_copy(a);
for (e = element_forw(a2->head); e != a2->head; e = element_forw(e)) {
t = pat_subst(element_value(e), pat, rep, mflags);
FREE(element_value(e));
e->value = t;
}
if (mflags & MATCH_QUOTED)
array_quote(a2);
else
array_quote_escapes(a2);
if (mflags & MATCH_STARSUB) {
array_remove_quoted_nulls (a2);
sifs = ifs_firstchar((int *)NULL);
t = array_to_string (a2, sifs, 0);
free(sifs);
} else if (mflags & MATCH_QUOTED) {
/* ${array[@]} */
sifs = ifs_firstchar (&slen);
ifs = getifs ();
if (ifs == 0 || *ifs == 0) {
if (slen < 2)
sifs = xrealloc (sifs, 2);
sifs[0] = ' ';
sifs[1] = '\0';
}
t = array_to_string (a2, sifs, 0);
free(sifs);
} else
t = array_to_string (a2, " ", 0);
array_dispose (a2);
return t;
}
char *
array_modcase (a, pat, modop, mflags)
ARRAY *a;
char *pat;
int modop;
int mflags;
{
ARRAY *a2;
ARRAY_ELEMENT *e;
char *t, *sifs, *ifs;
int slen;
if (a == 0 || array_head(a) == 0 || array_empty(a))
return ((char *)NULL);
a2 = array_copy(a);
for (e = element_forw(a2->head); e != a2->head; e = element_forw(e)) {
t = sh_modcase(element_value(e), pat, modop);
FREE(element_value(e));
e->value = t;
}
if (mflags & MATCH_QUOTED)
array_quote(a2);
else
array_quote_escapes(a2);
if (mflags & MATCH_STARSUB) {
array_remove_quoted_nulls (a2);
sifs = ifs_firstchar((int *)NULL);
t = array_to_string (a2, sifs, 0);
free(sifs);
} else if (mflags & MATCH_QUOTED) {
/* ${array[@]} */
sifs = ifs_firstchar (&slen);
ifs = getifs ();
if (ifs == 0 || *ifs == 0) {
if (slen < 2)
sifs = xrealloc (sifs, 2);
sifs[0] = ' ';
sifs[1] = '\0';
}
t = array_to_string (a2, sifs, 0);
free(sifs);
} else
t = array_to_string (a2, " ", 0);
array_dispose (a2);
return t;
}
/*
* Allocate and return a new array element with index INDEX and value
* VALUE.
*/
ARRAY_ELEMENT *
array_create_element(indx, value)
arrayind_t indx;
char *value;
{
ARRAY_ELEMENT *r;
r = (ARRAY_ELEMENT *)xmalloc(sizeof(ARRAY_ELEMENT));
r->ind = indx;
r->value = value ? savestring(value) : (char *)NULL;
r->next = r->prev = (ARRAY_ELEMENT *) NULL;
return(r);
}
#ifdef INCLUDE_UNUSED
ARRAY_ELEMENT *
array_copy_element(ae)
ARRAY_ELEMENT *ae;
{
return(ae ? array_create_element(element_index(ae), element_value(ae))
: (ARRAY_ELEMENT *) NULL);
}
#endif
void
array_dispose_element(ae)
ARRAY_ELEMENT *ae;
{
if (ae) {
FREE(ae->value);
free(ae);
}
}
/*
* Add a new element with index I and value V to array A (a[i] = v).
*/
int
array_insert(a, i, v)
ARRAY *a;
arrayind_t i;
char *v;
{
register ARRAY_ELEMENT *new, *ae, *start;
if (a == 0)
return(-1);
new = array_create_element(i, v);
if (i > array_max_index(a)) {
/*
* Hook onto the end. This also works for an empty array.
* Fast path for the common case of allocating arrays
* sequentially.
*/
ADD_BEFORE(a->head, new);
a->max_index = i;
a->num_elements++;
SET_LASTREF(a, new);
return(0);
}
#if OPTIMIZE_SEQUENTIAL_ARRAY_ASSIGNMENT
/*
* Otherwise we search for the spot to insert it. The lastref
* handle optimizes the case of sequential or almost-sequential
* assignments that are not at the end of the array.
*/
start = LASTREF_START(a, i);
#else
start = element_forw(ae->head);
#endif
for (ae = start; ae != a->head; ae = element_forw(ae)) {
if (element_index(ae) == i) {
/*
* Replacing an existing element.
*/
array_dispose_element(new);
free(element_value(ae));
ae->value = v ? savestring(v) : (char *)NULL;
SET_LASTREF(a, ae);
return(0);
} else if (element_index(ae) > i) {
ADD_BEFORE(ae, new);
a->num_elements++;
SET_LASTREF(a, new);
return(0);
}
}
array_dispose_element(new);
INVALIDATE_LASTREF(a);
return (-1); /* problem */
}
/*
* Delete the element with index I from array A and return it so the
* caller can dispose of it.
*/
ARRAY_ELEMENT *
array_remove(a, i)
ARRAY *a;
arrayind_t i;
{
register ARRAY_ELEMENT *ae, *start;
if (a == 0 || array_empty(a))
return((ARRAY_ELEMENT *) NULL);
start = LASTREF_START(a, i);
for (ae = start; ae != a->head; ae = element_forw(ae))
if (element_index(ae) == i) {
ae->next->prev = ae->prev;
ae->prev->next = ae->next;
a->num_elements--;
if (i == array_max_index(a))
a->max_index = element_index(ae->prev);
#if 0
INVALIDATE_LASTREF(a);
#else
if (ae->next != a->head)
SET_LASTREF(a, ae->next);
else if (ae->prev != a->head)
SET_LASTREF(a, ae->prev);
else
INVALIDATE_LASTREF(a);
#endif
return(ae);
}
return((ARRAY_ELEMENT *) NULL);
}
/*
* Return the value of a[i].
*/
char *
array_reference(a, i)
ARRAY *a;
arrayind_t i;
{
register ARRAY_ELEMENT *ae, *start;
if (a == 0 || array_empty(a))
return((char *) NULL);
if (i > array_max_index(a))
return((char *)NULL); /* Keep roving pointer into array to optimize sequential access */
start = LASTREF_START(a, i);
for (ae = start; ae != a->head; ae = element_forw(ae))
if (element_index(ae) == i) {
SET_LASTREF(a, ae);
return(element_value(ae));
}
UNSET_LASTREF();
return((char *) NULL);
}
/* Convenience routines for the shell to translate to and from the form used
by the rest of the code. */
WORD_LIST *
array_to_word_list(a)
ARRAY *a;
{
WORD_LIST *list;
ARRAY_ELEMENT *ae;
if (a == 0 || array_empty(a))
return((WORD_LIST *)NULL);
list = (WORD_LIST *)NULL;
for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae))
list = make_word_list (make_bare_word(element_value(ae)), list);
return (REVERSE_LIST(list, WORD_LIST *));
}
ARRAY *
array_from_word_list (list)
WORD_LIST *list;
{
ARRAY *a;
if (list == 0)
return((ARRAY *)NULL);
a = array_create();
return (array_assign_list (a, list));
}
WORD_LIST *
array_keys_to_word_list(a)
ARRAY *a;
{
WORD_LIST *list;
ARRAY_ELEMENT *ae;
char *t;
if (a == 0 || array_empty(a))
return((WORD_LIST *)NULL);
list = (WORD_LIST *)NULL;
for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae)) {
t = itos(element_index(ae));
list = make_word_list (make_bare_word(t), list);
free(t);
}
return (REVERSE_LIST(list, WORD_LIST *));
}
ARRAY *
array_assign_list (array, list)
ARRAY *array;
WORD_LIST *list;
{
register WORD_LIST *l;
register arrayind_t i;
for (l = list, i = 0; l; l = l->next, i++)
array_insert(array, i, l->word->word);
return array;
}
char **
array_to_argv (a)
ARRAY *a;
{
char **ret, *t;
int i;
ARRAY_ELEMENT *ae;
if (a == 0 || array_empty(a))
return ((char **)NULL);
ret = strvec_create (array_num_elements (a) + 1);
i = 0;
for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae)) {
t = element_value (ae);
ret[i++] = t ? savestring (t) : (char *)NULL;
}
ret[i] = (char *)NULL;
return (ret);
}
/*
* Return a string that is the concatenation of the elements in A from START
* to END, separated by SEP.
*/
static char *
array_to_string_internal (start, end, sep, quoted)
ARRAY_ELEMENT *start, *end;
char *sep;
int quoted;
{
char *result, *t;
ARRAY_ELEMENT *ae;
int slen, rsize, rlen, reg;
if (start == end) /* XXX - should not happen */
return ((char *)NULL);
slen = strlen(sep);
result = NULL;
for (rsize = rlen = 0, ae = start; ae != end; ae = element_forw(ae)) {
if (rsize == 0)
result = (char *)xmalloc (rsize = 64);
if (element_value(ae)) {
t = quoted ? quote_string(element_value(ae)) : element_value(ae);
reg = strlen(t);
RESIZE_MALLOCED_BUFFER (result, rlen, (reg + slen + 2),
rsize, rsize);
strcpy(result + rlen, t);
rlen += reg;
if (quoted && t)
free(t);
/*
* Add a separator only after non-null elements.
*/
if (element_forw(ae) != end) {
strcpy(result + rlen, sep);
rlen += slen;
}
}
}
if (result)
result[rlen] = '\0'; /* XXX */
return(result);
}
char *
array_to_assign (a, quoted)
ARRAY *a;
int quoted;
{
char *result, *valstr, *is;
char indstr[INT_STRLEN_BOUND(intmax_t) + 1];
ARRAY_ELEMENT *ae;
int rsize, rlen, elen;
if (a == 0 || array_empty (a))
return((char *)NULL);
result = (char *)xmalloc (rsize = 128);
result[0] = '(';
rlen = 1;
for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae)) {
is = inttostr (element_index(ae), indstr, sizeof(indstr));
valstr = element_value (ae) ? sh_double_quote (element_value(ae))
: (char *)NULL;
elen = STRLEN (is) + 8 + STRLEN (valstr);
RESIZE_MALLOCED_BUFFER (result, rlen, (elen + 1), rsize, rsize);
result[rlen++] = '[';
strcpy (result + rlen, is);
rlen += STRLEN (is);
result[rlen++] = ']';
result[rlen++] = '=';
if (valstr) {
strcpy (result + rlen, valstr);
rlen += STRLEN (valstr);
}
if (element_forw(ae) != a->head)
result[rlen++] = ' ';
FREE (valstr);
}
RESIZE_MALLOCED_BUFFER (result, rlen, 1, rsize, 8);
result[rlen++] = ')';
result[rlen] = '\0';
if (quoted) {
/* This is not as efficient as it could be... */
valstr = sh_single_quote (result);
free (result);
result = valstr;
}
return(result);
}
char *
array_to_string (a, sep, quoted)
ARRAY *a;
char *sep;
int quoted;
{
if (a == 0)
return((char *)NULL);
if (array_empty(a))
return(savestring(""));
return (array_to_string_internal (element_forw(a->head), a->head, sep, quoted));
}
#if defined (INCLUDE_UNUSED) || defined (TEST_ARRAY)
/*
* Return an array consisting of elements in S, separated by SEP
*/
ARRAY *
array_from_string(s, sep)
char *s, *sep;
{
ARRAY *a;
WORD_LIST *w;
if (s == 0)
return((ARRAY *)NULL);
w = list_string (s, sep, 0);
if (w == 0)
return((ARRAY *)NULL);
a = array_from_word_list (w);
return (a);
}
#endif
#if defined (TEST_ARRAY)
/*
* To make a running version, compile -DTEST_ARRAY and link with:
* xmalloc.o syntax.o lib/malloc/libmalloc.a lib/sh/libsh.a
*/
int interrupt_immediately = 0;
int
signal_is_trapped(s)
int s;
{
return 0;
}
void
fatal_error(const char *s, ...)
{
fprintf(stderr, "array_test: fatal memory error\n");
abort();
}
void
programming_error(const char *s, ...)
{
fprintf(stderr, "array_test: fatal programming error\n");
abort();
}
WORD_DESC *
make_bare_word (s)
const char *s;
{
WORD_DESC *w;
w = (WORD_DESC *)xmalloc(sizeof(WORD_DESC));
w->word = s ? savestring(s) : savestring ("");
w->flags = 0;
return w;
}
WORD_LIST *
make_word_list(x, l)
WORD_DESC *x;
WORD_LIST *l;
{
WORD_LIST *w;
w = (WORD_LIST *)xmalloc(sizeof(WORD_LIST));
w->word = x;
w->next = l;
return w;
}
WORD_LIST *
list_string(s, t, i)
char *s, *t;
int i;
{
char *r, *a;
WORD_LIST *wl;
if (s == 0)
return (WORD_LIST *)NULL;
r = savestring(s);
wl = (WORD_LIST *)NULL;
a = strtok(r, t);
while (a) {
wl = make_word_list (make_bare_word(a), wl);
a = strtok((char *)NULL, t);
}
return (REVERSE_LIST (wl, WORD_LIST *));
}
GENERIC_LIST *
list_reverse (list)
GENERIC_LIST *list;
{
register GENERIC_LIST *next, *prev;
for (prev = 0; list; ) {
next = list->next;
list->next = prev;
prev = list;
list = next;
}
return prev;
}
char *
pat_subst(s, t, u, i)
char *s, *t, *u;
int i;
{
return ((char *)NULL);
}
char *
quote_string(s)
char *s;
{
return savestring(s);
}
print_element(ae)
ARRAY_ELEMENT *ae;
{
char lbuf[INT_STRLEN_BOUND (intmax_t) + 1];
printf("array[%s] = %s\n",
inttostr (element_index(ae), lbuf, sizeof (lbuf)),
element_value(ae));
}
print_array(a)
ARRAY *a;
{
printf("\n");
array_walk(a, print_element, (void *)NULL);
}
main()
{
ARRAY *a, *new_a, *copy_of_a;
ARRAY_ELEMENT *ae, *aew;
char *s;
a = array_create();
array_insert(a, 1, "one");
array_insert(a, 7, "seven");
array_insert(a, 4, "four");
array_insert(a, 1029, "one thousand twenty-nine");
array_insert(a, 12, "twelve");
array_insert(a, 42, "forty-two");
print_array(a);
s = array_to_string (a, " ", 0);
printf("s = %s\n", s);
copy_of_a = array_from_string(s, " ");
printf("copy_of_a:");
print_array(copy_of_a);
array_dispose(copy_of_a);
printf("\n");
free(s);
ae = array_remove(a, 4);
array_dispose_element(ae);
ae = array_remove(a, 1029);
array_dispose_element(ae);
array_insert(a, 16, "sixteen");
print_array(a);
s = array_to_string (a, " ", 0);
printf("s = %s\n", s);
copy_of_a = array_from_string(s, " ");
printf("copy_of_a:");
print_array(copy_of_a);
array_dispose(copy_of_a);
printf("\n");
free(s);
array_insert(a, 2, "two");
array_insert(a, 1029, "new one thousand twenty-nine");
array_insert(a, 0, "zero");
array_insert(a, 134, "");
print_array(a);
s = array_to_string (a, ":", 0);
printf("s = %s\n", s);
copy_of_a = array_from_string(s, ":");
printf("copy_of_a:");
print_array(copy_of_a);
array_dispose(copy_of_a);
printf("\n");
free(s);
new_a = array_copy(a);
print_array(new_a);
s = array_to_string (new_a, ":", 0);
printf("s = %s\n", s);
copy_of_a = array_from_string(s, ":");
free(s);
printf("copy_of_a:");
print_array(copy_of_a);
array_shift(copy_of_a, 2, AS_DISPOSE);
printf("copy_of_a shifted by two:");
print_array(copy_of_a);
ae = array_shift(copy_of_a, 2, 0);
printf("copy_of_a shifted by two:");
print_array(copy_of_a);
for ( ; ae; ) {
aew = element_forw(ae);
array_dispose_element(ae);
ae = aew;
}
array_rshift(copy_of_a, 1, (char *)0);
printf("copy_of_a rshift by 1:");
print_array(copy_of_a);
array_rshift(copy_of_a, 2, "new element zero");
printf("copy_of_a rshift again by 2 with new element zero:");
print_array(copy_of_a);
s = array_to_assign(copy_of_a, 0);
printf("copy_of_a=%s\n", s);
free(s);
ae = array_shift(copy_of_a, array_num_elements(copy_of_a), 0);
for ( ; ae; ) {
aew = element_forw(ae);
array_dispose_element(ae);
ae = aew;
}
array_dispose(copy_of_a);
printf("\n");
array_dispose(a);
array_dispose(new_a);
}
#endif /* TEST_ARRAY */
#endif /* ARRAY_VARS */
bash-4.3/command.h 0000644 0001750 0000144 00000034562 12226770757 012770 0 ustar doko users /* command.h -- The structures used internally to represent commands, and
the extern declarations of the functions used to create them. */
/* Copyright (C) 1993-2010 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 3 of the License, 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. If not, see .
*/
#if !defined (_COMMAND_H_)
#define _COMMAND_H_
#include "stdc.h"
/* Instructions describing what kind of thing to do for a redirection. */
enum r_instruction {
r_output_direction, r_input_direction, r_inputa_direction,
r_appending_to, r_reading_until, r_reading_string,
r_duplicating_input, r_duplicating_output, r_deblank_reading_until,
r_close_this, r_err_and_out, r_input_output, r_output_force,
r_duplicating_input_word, r_duplicating_output_word,
r_move_input, r_move_output, r_move_input_word, r_move_output_word,
r_append_err_and_out
};
/* Redirection flags; values for rflags */
#define REDIR_VARASSIGN 0x01
/* Redirection errors. */
#define AMBIGUOUS_REDIRECT -1
#define NOCLOBBER_REDIRECT -2
#define RESTRICTED_REDIRECT -3 /* can only happen in restricted shells. */
#define HEREDOC_REDIRECT -4 /* here-doc temp file can't be created */
#define BADVAR_REDIRECT -5 /* something wrong with {varname}redir */
#define CLOBBERING_REDIRECT(ri) \
(ri == r_output_direction || ri == r_err_and_out)
#define OUTPUT_REDIRECT(ri) \
(ri == r_output_direction || ri == r_input_output || ri == r_err_and_out || ri == r_append_err_and_out)
#define INPUT_REDIRECT(ri) \
(ri == r_input_direction || ri == r_inputa_direction || ri == r_input_output)
#define WRITE_REDIRECT(ri) \
(ri == r_output_direction || \
ri == r_input_output || \
ri == r_err_and_out || \
ri == r_appending_to || \
ri == r_append_err_and_out || \
ri == r_output_force)
/* redirection needs translation */
#define TRANSLATE_REDIRECT(ri) \
(ri == r_duplicating_input_word || ri == r_duplicating_output_word || \
ri == r_move_input_word || ri == r_move_output_word)
/* Command Types: */
enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple, cm_select,
cm_connection, cm_function_def, cm_until, cm_group,
cm_arith, cm_cond, cm_arith_for, cm_subshell, cm_coproc };
/* Possible values for the `flags' field of a WORD_DESC. */
#define W_HASDOLLAR 0x000001 /* Dollar sign present. */
#define W_QUOTED 0x000002 /* Some form of quote character is present. */
#define W_ASSIGNMENT 0x000004 /* This word is a variable assignment. */
#define W_SPLITSPACE 0x000008 /* Split this word on " " regardless of IFS */
#define W_NOSPLIT 0x000010 /* Do not perform word splitting on this word because ifs is empty string. */
#define W_NOGLOB 0x000020 /* Do not perform globbing on this word. */
#define W_NOSPLIT2 0x000040 /* Don't split word except for $@ expansion (using spaces) because context does not allow it. */
#define W_TILDEEXP 0x000080 /* Tilde expand this assignment word */
#define W_DOLLARAT 0x000100 /* $@ and its special handling */
#define W_DOLLARSTAR 0x000200 /* $* and its special handling */
#define W_NOCOMSUB 0x000400 /* Don't perform command substitution on this word */
#define W_ASSIGNRHS 0x000800 /* Word is rhs of an assignment statement */
#define W_NOTILDE 0x001000 /* Don't perform tilde expansion on this word */
#define W_ITILDE 0x002000 /* Internal flag for word expansion */
#define W_NOEXPAND 0x004000 /* Don't expand at all -- do quote removal */
#define W_COMPASSIGN 0x008000 /* Compound assignment */
#define W_ASSNBLTIN 0x010000 /* word is a builtin command that takes assignments */
#define W_ASSIGNARG 0x020000 /* word is assignment argument to command */
#define W_HASQUOTEDNULL 0x040000 /* word contains a quoted null character */
#define W_DQUOTE 0x080000 /* word should be treated as if double-quoted */
#define W_NOPROCSUB 0x100000 /* don't perform process substitution */
#define W_HASCTLESC 0x200000 /* word contains literal CTLESC characters */
#define W_ASSIGNASSOC 0x400000 /* word looks like associative array assignment */
#define W_ASSIGNARRAY 0x800000 /* word looks like a compound indexed array assignment */
#define W_ARRAYIND 0x1000000 /* word is an array index being expanded */
#define W_ASSNGLOBAL 0x2000000 /* word is a global assignment to declare (declare/typeset -g) */
#define W_NOBRACE 0x4000000 /* Don't perform brace expansion */
#define W_ASSIGNINT 0x8000000 /* word is an integer assignment to declare */
/* Possible values for subshell_environment */
#define SUBSHELL_ASYNC 0x01 /* subshell caused by `command &' */
#define SUBSHELL_PAREN 0x02 /* subshell caused by ( ... ) */
#define SUBSHELL_COMSUB 0x04 /* subshell caused by `command` or $(command) */
#define SUBSHELL_FORK 0x08 /* subshell caused by executing a disk command */
#define SUBSHELL_PIPE 0x10 /* subshell from a pipeline element */
#define SUBSHELL_PROCSUB 0x20 /* subshell caused by <(command) or >(command) */
#define SUBSHELL_COPROC 0x40 /* subshell from a coproc pipeline */
#define SUBSHELL_RESETTRAP 0x80 /* subshell needs to reset trap strings on first call to trap */
/* A structure which represents a word. */
typedef struct word_desc {
char *word; /* Zero terminated string. */
int flags; /* Flags associated with this word. */
} WORD_DESC;
/* A linked list of words. */
typedef struct word_list {
struct word_list *next;
WORD_DESC *word;
} WORD_LIST;
/* **************************************************************** */
/* */
/* Shell Command Structs */
/* */
/* **************************************************************** */
/* What a redirection descriptor looks like. If the redirection instruction
is ri_duplicating_input or ri_duplicating_output, use DEST, otherwise
use the file in FILENAME. Out-of-range descriptors are identified by a
negative DEST. */
typedef union {
int dest; /* Place to redirect REDIRECTOR to, or ... */
WORD_DESC *filename; /* filename to redirect to. */
} REDIRECTEE;
/* Structure describing a redirection. If REDIRECTOR is negative, the parser
(or translator in redir.c) encountered an out-of-range file descriptor. */
typedef struct redirect {
struct redirect *next; /* Next element, or NULL. */
REDIRECTEE redirector; /* Descriptor or varname to be redirected. */
int rflags; /* Private flags for this redirection */
int flags; /* Flag value for `open'. */
enum r_instruction instruction; /* What to do with the information. */
REDIRECTEE redirectee; /* File descriptor or filename */
char *here_doc_eof; /* The word that appeared in <flags. */
#define CMD_WANT_SUBSHELL 0x01 /* User wants a subshell: ( command ) */
#define CMD_FORCE_SUBSHELL 0x02 /* Shell needs to force a subshell. */
#define CMD_INVERT_RETURN 0x04 /* Invert the exit value. */
#define CMD_IGNORE_RETURN 0x08 /* Ignore the exit value. For set -e. */
#define CMD_NO_FUNCTIONS 0x10 /* Ignore functions during command lookup. */
#define CMD_INHIBIT_EXPANSION 0x20 /* Do not expand the command words. */
#define CMD_NO_FORK 0x40 /* Don't fork; just call execve */
#define CMD_TIME_PIPELINE 0x80 /* Time a pipeline */
#define CMD_TIME_POSIX 0x100 /* time -p; use POSIX.2 time output spec. */
#define CMD_AMPERSAND 0x200 /* command & */
#define CMD_STDIN_REDIR 0x400 /* async command needs implicit