#endif
static int do_assignment_internal (const WORD_DESC *, int);
-static char *string_extract_verbatim (const char *, size_t, int *, char *, int);
-static char *string_extract (const char *, int *, const char *, int);
-static char *string_extract_double_quoted (const char *, int *, int);
-static inline char *string_extract_single_quoted (const char *, int *, int);
-static inline int skip_single_quoted (const char *, size_t, int, int);
-static int skip_double_quoted (const char *, size_t, int, int);
-static char *extract_delimited_string (const char *, int *, char *, char *, char *, int);
-static char *extract_heredoc_dolbrace_string (const char *, int *, int, int);
-static char *extract_dollar_brace_string (const char *, int *, int, int);
+static char *string_extract_verbatim (const char *, size_t, size_t *, char *, int);
+static char *string_extract (const char *, size_t *, const char *, int);
+static char *string_extract_double_quoted (const char *, size_t *, int);
+static inline char *string_extract_single_quoted (const char *, size_t *, int);
+static inline size_t skip_single_quoted (const char *, size_t, size_t, int);
+static int skip_double_quoted (const char *, size_t, size_t, int);
+static char *extract_delimited_string (const char *, size_t *, char *, char *, char *, int);
+static char *extract_heredoc_dolbrace_string (const char *, size_t *, int, int);
+static char *extract_dollar_brace_string (const char *, size_t *, int, int);
static int skip_matched_pair (const char *, int, int, int, int);
static char *pos_params (const char *, int, int, int, int);
static char *pos_params_casemod (char *, char *, int, int);
static char *parameter_brace_casemod (char *, char *, array_eltstate_t *, int, char *, int, int, int);
-static WORD_DESC *parameter_brace_expand (char *, int *, int, int, int *, int *);
-static WORD_DESC *param_expand (char *, int *, int, int *, int *, int *, int *, int);
+static WORD_DESC *parameter_brace_expand (char *, size_t *, int, int, int *, int *);
+static WORD_DESC *param_expand (char *, size_t *, int, int *, int *, int *, int *, int);
static WORD_LIST *expand_word_internal (WORD_DESC *, int, int, int *, int *);
static int
unquoted_member (int character, const char *string)
{
- size_t slen;
- int sindex, c;
+ size_t slen, sindex;
+ int c;
DECLARE_MBSTATE;
slen = strlen (string);
static int
unquoted_substring (const char *substr, const char *string)
{
- size_t slen;
- int sindex, c, sublen;
+ size_t sindex, slen, sublen;
+ int c;
DECLARE_MBSTATE;
if (substr == 0 || *substr == '\0')
update SINDEX. If (flags & SX_REQMATCH) is non-zero, the string must
contain a closing character from CHARLIST. */
static char *
-string_extract (const char *string, int *sindex, const char *charlist, int flags)
+string_extract (const char *string, size_t *sindex, const char *charlist, int flags)
{
- register int c, i;
+ int c;
int found;
- size_t slen;
+ size_t i, slen;
char *temp;
DECLARE_MBSTATE;
Backslashes between the embedded double quotes are processed. If STRIPDQ
is zero, an unquoted `"' terminates the string. */
static char *
-string_extract_double_quoted (const char *string, int *sindex, int flags)
+string_extract_double_quoted (const char *string, size_t *sindex, int flags)
{
- size_t slen;
+ size_t i, j, t, si, slen;
const char *send;
- int j, i, t;
unsigned char c;
char *temp, *ret; /* The new string we return. */
- int pass_next, backquote, si; /* State variables for the machine. */
+ int pass_next, backquote; /* State variables for the machine. */
int dquote;
int stripdq;
DECLARE_MBSTATE;
/* This should really be another option to string_extract_double_quoted. */
static int
-skip_double_quoted (const char *string, size_t slen, int sind, int flags)
+skip_double_quoted (const char *string, size_t slen, size_t sind, int flags)
{
- int c, i;
+ int c;
+ size_t i, si;
char *ret;
- int pass_next, backquote, si;
+ int pass_next, backquote;
DECLARE_MBSTATE;
pass_next = backquote = 0;
the closing single quote. ALLOWESC allows the single quote to be quoted by
a backslash; it's not used yet. */
static inline char *
-string_extract_single_quoted (const char *string, int *sindex, int allowesc)
+string_extract_single_quoted (const char *string, size_t *sindex, int allowesc)
{
- register int i;
- size_t slen;
+ size_t i, slen;
char *t;
int pass_next;
DECLARE_MBSTATE;
/* Skip over a single-quoted string. We overload the SX_COMPLETE flag to mean
that we are splitting out words for completion and have encountered a $'...'
string, which allows backslash-escaped single quotes. */
-static inline int
-skip_single_quoted (const char *string, size_t slen, int sind, int flags)
+static inline size_t
+skip_single_quoted (const char *string, size_t slen, size_t sind, int flags)
{
- register int c;
+ size_t si;
DECLARE_MBSTATE;
- c = sind;
- while (string[c] && string[c] != '\'')
+ si = sind;
+ while (string[si] && string[si] != '\'')
{
- if ((flags & SX_COMPLETE) && string[c] == '\\' && string[c+1] == '\'' && string[c+2])
- ADVANCE_CHAR (string, slen, c);
- ADVANCE_CHAR (string, slen, c);
+ if ((flags & SX_COMPLETE) && string[si] == '\\' && string[si+1] == '\'' && string[si+2])
+ ADVANCE_CHAR (string, slen, si);
+ ADVANCE_CHAR (string, slen, si);
}
- if (string[c])
- c++;
- return c;
+ if (string[si])
+ si++;
+ return si;
}
/* Just like string_extract, but doesn't hack backslashes or any of
that other stuff. Obeys CTLESC quoting. Used to do splitting on $IFS. */
static char *
-string_extract_verbatim (const char *string, size_t slen, int *sindex, char *charlist, int flags)
+string_extract_verbatim (const char *string, size_t slen, size_t *sindex, char *charlist, int flags)
{
- register int i;
+ size_t i, c;
#if defined (HANDLE_MULTIBYTE)
wchar_t *wcharlist;
mbstate_t mbstmp;
#endif
- int c;
char *temp;
DECLARE_MBSTATE;
Make (SINDEX) get the position of the matching ")". )
XFLAGS is additional flags to pass to other extraction functions. */
char *
-extract_command_subst (const char *string, int *sindex, int xflags)
+extract_command_subst (const char *string, size_t *sindex, int xflags)
{
char *ret;
char *xstr;
/* Take a ${Ccommand} where C is a character that introduces a function
substitution and extract the string. */
char *
-extract_function_subst (const char *string, int *sindex, int quoted, int xflags)
+extract_function_subst (const char *string, size_t *sindex, int quoted, int xflags)
{
char *ret;
char *xstr;
Start extracting at (SINDEX) as if we had just seen "$[".
Make (SINDEX) get the position of the matching "]". */
char *
-extract_arithmetic_subst (const char *string, int *sindex)
+extract_arithmetic_subst (const char *string, size_t *sindex)
{
return (extract_delimited_string (string, sindex, "$[", "[", "]", 0)); /*]*/
}
Start extracting at (SINDEX) as if we had just seen "<(".
Make (SINDEX) get the position of the matching ")". */ /*))*/
char *
-extract_process_subst (const char *string, char *starter, int *sindex, int xflags)
+extract_process_subst (const char *string, char *starter, size_t *sindex, int xflags)
{
#if 0
/* XXX - check xflags&SX_COMPLETE here? */
each caller verifies that the last character in STRING is a right paren,
we don't even need to call extract_delimited_string. */
char *
-extract_array_assignment_list (const char *string, int *sindex)
+extract_array_assignment_list (const char *string, size_t *sindex)
{
- int slen;
+ size_t slen;
char *ret;
slen = strlen (string);
contains a character string that can also match CLOSER and thus
needs to be skipped. */
static char *
-extract_delimited_string (const char *string, int *sindex, char *opener, char *alt_opener, char *closer, int flags)
+extract_delimited_string (const char *string, size_t *sindex, char *opener, char *alt_opener, char *closer, int flags)
{
- int i, c, si;
- size_t slen;
+ int c;
+ size_t i, si, slen;
char *t, *result;
int pass_character, nesting_level, in_comment;
size_t len_closer, len_opener, len_alt_opener;
the end of the string, catch it and cut the loop. */
if (i > slen)
{
- i = slen;
c = string[i = slen];
break;
}
This needs to match the logic in parse.y:parse_matched_pair so we get
consistent behavior between here-documents and double-quoted strings. */
static char *
-extract_heredoc_dolbrace_string (const char *string, int *sindex, int quoted, int flags)
+extract_heredoc_dolbrace_string (const char *string, size_t *sindex, int quoted, int flags)
{
- register int i, c;
- size_t slen, tlen, result_index, result_size;
- int pass_character, nesting_level, si, dolbrace_state;
+ register int c;
+ size_t i, si, slen, tlen, result_index, result_size;
+ int pass_character, nesting_level, dolbrace_state;
char *result, *t;
const char *send;
DECLARE_MBSTATE;
occurs inside double quotes. */
/* XXX -- this is very similar to extract_delimited_string -- XXX */
static char *
-extract_dollar_brace_string (const char *string, int *sindex, int quoted, int flags)
+extract_dollar_brace_string (const char *string, size_t *sindex, int quoted, int flags)
{
register int i, c;
- size_t slen;
- int pass_character, nesting_level, si, dolbrace_state;
+ size_t si, slen;
+ int pass_character, nesting_level, dolbrace_state;
char *result, *t;
DECLARE_MBSTATE;
de_backslash (char *string, int qflags)
{
register size_t slen;
- register int i, j, prev_i;
+ register size_t i, j, prev_i;
DECLARE_MBSTATE;
slen = strlen (string);
static int
skip_matched_pair (const char *string, int start, int open, int close, int flags)
{
- int i, pass_next, backq, si, c, count, oldjmp;
- size_t slen;
+ int pass_next, backq, c, count, oldjmp;
+ size_t i, si, slen;
char *temp;
DECLARE_MBSTATE;
int
skip_to_delim (const char *string, int start, const char *delims, int flags)
{
- int i, pass_next, backq, dquote, si, c, oldjmp;
+ int pass_next, backq, dquote, c, oldjmp;
int invert, skipquote, skipcmd, noprocsub, completeflag;
int arithexp, skipcol;
- size_t slen;
+ size_t i, si, slen;
char *temp, open[3];
DECLARE_MBSTATE;
int
skip_to_histexp (const char *string, int start, const char *delims, int flags)
{
- int i, pass_next, backq, dquote, c, oldjmp;
+ int pass_next, backq, dquote, c, oldjmp;
int histexp_comsub, histexp_backq, old_dquote;
- size_t slen;
+ size_t i, slen;
DECLARE_MBSTATE;
slen = strlen (string + start) + start;
WORD_LIST *result;
WORD_DESC *t;
char *current_word, *s;
- int sindex, sh_style_split, whitesep, xflags, free_word;
+ int sh_style_split, whitesep, xflags, free_word;
+ size_t sindex;
size_t slen;
if (!string || !*string)
skip sequences of whitespace characters as long as they are separators
This obeys the field splitting rules in Posix.2. */
slen = STRLEN (string);
- for (result = (WORD_LIST *)NULL, sindex = 0; string[sindex]; )
+ result = NULL;
+ for (sindex = 0; sindex < slen; )
{
/* Don't need string length in ADVANCE_CHAR unless multibyte chars are
possible, but need it in string_extract_verbatim for bounds checking */
{
register char *s;
char *current_word;
- int sindex, sh_style_split, whitesep, xflags;
+ int sh_style_split, whitesep, xflags;
unsigned char local_cmap[UCHAR_MAX+1]; /* really only need single-byte chars here */
+ size_t sindex;
size_t slen;
if (!stringp || !*stringp || !**stringp)
{
WORD_LIST *list;
char *token, *s;
- size_t s_len;
+ size_t slen;
int c, i, tokstart, len;
for (s = string; s && *s && spctabnl (*s); s++)
if (s == 0 || *s == 0)
return ((WORD_LIST *)NULL);
- s_len = strlen (s);
+ slen = strlen (s);
tokstart = i = 0;
list = (WORD_LIST *)NULL;
while (1)
i++;
}
else if (c == '\'')
- i = skip_single_quoted (s, s_len, ++i, 0);
+ i = skip_single_quoted (s, slen, ++i, 0);
else if (c == '"')
- i = skip_double_quoted (s, s_len, ++i, 0);
+ i = skip_double_quoted (s, slen, ++i, 0);
else if (c == 0 || spctabnl (c))
{
/* We have found the end of a token. Make a word out of it and
SHELL_VAR *entry;
#if defined (ARRAY_VARS)
char *t;
- int ni;
+ size_t ni;
#endif
char *string;
#if defined (ARRAY_VARS)
if (expand && (word->flags & W_COMPASSIGN))
{
- assign_list = ni = 1;
+ assign_list = 1;
+ ni = 1;
value = extract_array_assignment_list (temp, &ni);
}
else
expand_string_dollar_quote (const char *string, int flags)
{
size_t slen, retind, retsize;
- int sindex, c, peekc, news, tlen;
+ size_t sindex, news;
+ int c, peekc;
char *ret, *trans, *t;
size_t translen;
const char *send;
}
else if (var_is_special) /* ${@} */
{
- int sindex;
+ size_t sindex;
+
tt = (char *)xmalloc (2 + strlen (name));
tt[sindex = 0] = '$';
strcpy (tt + 1, name);
WORD_DESC *w;
WORD_LIST *l, *tl;
char *t, *t1, *temp, *vname, *newval;
- int l_hasdollat, sindex, arrayref;
+ int l_hasdollat, arrayref;
+ size_t sindex;
SHELL_VAR *v;
array_eltstate_t es;
static int
shouldexp_replacement (const char *s)
{
- size_t slen;
- int sindex, c;
+ size_t sindex, slen;
+ int c;
DECLARE_MBSTATE;
sindex = 0;
/* ${[#][!]name[[:][^[^]][,[,]]#[#]%[%]-=?+[word][:e1[:e2]]]} */
static WORD_DESC *
-parameter_brace_expand (char *string, int *indexp, int quoted, int pflags, int *quoted_dollar_atp, int *contains_dollar_at)
+parameter_brace_expand (char *string, size_t *indexp, int quoted, int pflags, int *quoted_dollar_atp, int *contains_dollar_at)
{
int check_nullness, var_is_set, var_is_null, var_is_special;
int want_substring, want_indir, want_patsub, want_casemod, want_attributes;
char *name, *value, *temp, *temp1;
WORD_DESC *tdesc, *ret;
- int t_index, sindex, c, tflag, modspec, local_pflags, all_element_arrayref;
+ size_t t_index, sindex;
+ int c, tflag, modspec, local_pflags, all_element_arrayref;
intmax_t number;
array_eltstate_t es;
the braces are used, parameter_brace_expand() does the work,
possibly calling param_expand recursively. */
static WORD_DESC *
-param_expand (char *string, int *sindex, int quoted,
+param_expand (char *string, size_t *sindex, int quoted,
int *expanded_something, int *contains_dollar_at, int *quoted_dollar_at_p,
int *had_quoted_null_p, int pflags)
{
char *temp, *temp1, uerror[3], *savecmd;
- int zindex, t_index, expok, eflag;
+ size_t zindex, t_index;
+ int expok, eflag;
unsigned char c;
intmax_t number;
SHELL_VAR *var;
only expand it once, we quote the characters that would start another
expansion and the bracket characters that are special to array subscripts. */
static char *
-expand_array_subscript (const char *string, int *sindex, int quoted, int flags)
+expand_array_subscript (const char *string, size_t *sindex, int quoted, int flags)
{
char *ret, *exp, *t;
- size_t slen;
- int si, ni;
+ size_t si, slen;
+ int ni;
si = *sindex;
slen = STRLEN (string);
size_t string_size;
/* The index into STRING. */
- int sindex;
+ size_t sindex;
/* This gets 1 if we see a $@ while quoted. */
int quoted_dollar_at;
int assignoff; /* If assignment, offset of `=' */
register unsigned char c; /* Current character. */
- int t_index; /* For calls to string_extract_xxx. */
+ size_t t_index; /* For calls to string_extract_xxx. */
char twochars[2];
char *
string_quote_removal (const char *string, int quoted)
{
- size_t slen;
+ size_t slen, sindex, tindex;
char *r, *result_string, *temp;
const char *send;
- int sindex, tindex, dquote;
+ int dquote;
unsigned char c;
DECLARE_MBSTATE;
expand_compound_assignment_word (WORD_LIST *tlist, int atype)
{
WORD_LIST *l;
- int wlen, oind, t;
+ size_t wlen, oind;
+ int t;
char *value, *temp;
/*itrace("expand_compound_assignment_word: original word = -%s-", tlist->word->word);*/