Whitespace cleanup

This commit is contained in:
Sergey Poznyakoff 2019-05-14 19:59:07 +03:00
parent a2c81cc5fa
commit a19f8397ed
2 changed files with 92 additions and 93 deletions

View file

@ -30,16 +30,16 @@ typedef struct wordsplit wordsplit_t;
must be set (or unset, if starting with !) in ws_flags (if starting with must be set (or unset, if starting with !) in ws_flags (if starting with
WRDSF_) or ws_options (if starting with WRDSO_) to initialize or use the WRDSF_) or ws_options (if starting with WRDSO_) to initialize or use the
given member. given member.
If not redefined explicitly, most of them are set to some reasonable If not redefined explicitly, most of them are set to some reasonable
default value upon entry to wordsplit(). */ default value upon entry to wordsplit(). */
struct wordsplit struct wordsplit
{ {
size_t ws_wordc; /* [Output] Number of words in ws_wordv. */ size_t ws_wordc; /* [Output] Number of words in ws_wordv. */
char **ws_wordv; /* [Output] Array of parsed out words. */ char **ws_wordv; /* [Output] Array of parsed out words. */
size_t ws_offs; /* [Input] (WRDSF_DOOFFS) Number of initial size_t ws_offs; /* [Input] (WRDSF_DOOFFS) Number of initial
elements in ws_wordv to fill with NULLs. */ elements in ws_wordv to fill with NULLs. */
size_t ws_wordn; /* Number of elements ws_wordv can accomodate. */ size_t ws_wordn; /* Number of elements ws_wordv can accomodate. */
int ws_flags; /* [Input] Flags passed to wordsplit. */ int ws_flags; /* [Input] Flags passed to wordsplit. */
int ws_options; /* [Input] (WRDSF_OPTIONS) int ws_options; /* [Input] (WRDSF_OPTIONS)
Additional options. */ Additional options. */
@ -53,15 +53,15 @@ struct wordsplit
const char *ws_escape[2]; /* [Input] (WRDSF_ESCAPE) Characters to be escaped const char *ws_escape[2]; /* [Input] (WRDSF_ESCAPE) Characters to be escaped
with backslash. */ with backslash. */
void (*ws_alloc_die) (wordsplit_t *wsp); void (*ws_alloc_die) (wordsplit_t *wsp);
/* [Input] (WRDSF_ALLOC_DIE) Function called when /* [Input] (WRDSF_ALLOC_DIE) Function called when
out of memory. Must not return. */ out of memory. Must not return. */
void (*ws_error) (const char *, ...) void (*ws_error) (const char *, ...)
__attribute__ ((__format__ (__printf__, 1, 2))); __attribute__ ((__format__ (__printf__, 1, 2)));
/* [Input] (WRDSF_ERROR) Function used for error /* [Input] (WRDSF_ERROR) Function used for error
reporting */ reporting */
void (*ws_debug) (const char *, ...) void (*ws_debug) (const char *, ...)
__attribute__ ((__format__ (__printf__, 1, 2))); __attribute__ ((__format__ (__printf__, 1, 2)));
/* [Input] (WRDSF_DEBUG) Function used for debug /* [Input] (WRDSF_DEBUG) Function used for debug
output. */ output. */
const char **ws_env; /* [Input] (WRDSF_ENV, !WRDSF_NOVAR) Array of const char **ws_env; /* [Input] (WRDSF_ENV, !WRDSF_NOVAR) Array of
environment variables. */ environment variables. */
@ -80,14 +80,14 @@ struct wordsplit
parameters */ parameters */
size_t ws_paramc; /* Number of positional parameters */ size_t ws_paramc; /* Number of positional parameters */
/* Temporary storage for parameters. Works similarly to ws_enbuf. /* Temporary storage for parameters. Works similarly to ws_enbuf.
*/ */
char **ws_parambuf; char **ws_parambuf;
size_t ws_paramidx; size_t ws_paramidx;
size_t ws_paramsiz; size_t ws_paramsiz;
int (*ws_getvar) (char **ret, const char *var, size_t len, void *clos); int (*ws_getvar) (char **ret, const char *var, size_t len, void *clos);
/* [Input] (WRDSF_GETVAR, !WRDSF_NOVAR) Looks up /* [Input] (WRDSF_GETVAR, !WRDSF_NOVAR) Looks up
the name VAR (LEN bytes long) in the table of the name VAR (LEN bytes long) in the table of
variables and if found returns in memory variables and if found returns in memory
location pointed to by RET the value of that location pointed to by RET the value of that
@ -96,13 +96,13 @@ struct wordsplit
on error. User-specific errors can be returned on error. User-specific errors can be returned
by storing the error diagnostic string in RET by storing the error diagnostic string in RET
and returning WRDSE_USERERR. and returning WRDSE_USERERR.
Whatever is stored in RET, it must be allocated Whatever is stored in RET, it must be allocated
using malloc(3). */ using malloc(3). */
void *ws_closure; /* [Input] (WRDSF_CLOSURE) Passed as the CLOS void *ws_closure; /* [Input] (WRDSF_CLOSURE) Passed as the CLOS
argument to ws_getvar and ws_command. */ argument to ws_getvar and ws_command. */
int (*ws_command) (char **ret, const char *cmd, size_t len, char **argv, int (*ws_command) (char **ret, const char *cmd, size_t len, char **argv,
void *clos); void *clos);
/* [Input] (!WRDSF_NOCMD) Returns in the memory /* [Input] (!WRDSF_NOCMD) Returns in the memory
location pointed to by RET the expansion of location pointed to by RET the expansion of
the command CMD (LEN bytes long). On input, the command CMD (LEN bytes long). On input,
ARGV contains CMD split out to words. ARGV contains CMD split out to words.
@ -110,7 +110,7 @@ struct wordsplit
See ws_getvar for a discussion of possible See ws_getvar for a discussion of possible
return values. */ return values. */
const char *ws_input; /* Input string (the S argument to wordsplit. */ const char *ws_input; /* Input string (the S argument to wordsplit. */
size_t ws_len; /* Length of ws_input. */ size_t ws_len; /* Length of ws_input. */
size_t ws_endp; /* Points past the last processed byte in size_t ws_endp; /* Points past the last processed byte in
ws_input. */ ws_input. */
@ -119,7 +119,7 @@ struct wordsplit
the error, if ws_errno is WRDSE_USERERR. Must the error, if ws_errno is WRDSE_USERERR. Must
be allocated with malloc(3). */ be allocated with malloc(3). */
struct wordsplit_node *ws_head, *ws_tail; struct wordsplit_node *ws_head, *ws_tail;
/* Doubly-linked list of parsed out nodes. */ /* Doubly-linked list of parsed out nodes. */
int ws_lvl; /* Invocation nesting level. */ int ws_lvl; /* Invocation nesting level. */
}; };
@ -242,9 +242,9 @@ struct wordsplit
parameter) */ parameter) */
#define WRDSO_PARAM_NEGIDX 0x00008000 #define WRDSO_PARAM_NEGIDX 0x00008000
#define WRDSO_BSKEEP WRDSO_BSKEEP_WORD #define WRDSO_BSKEEP WRDSO_BSKEEP_WORD
#define WRDSO_OESC WRDSO_OESC_WORD #define WRDSO_OESC WRDSO_OESC_WORD
#define WRDSO_XESC WRDSO_XESC_WORD #define WRDSO_XESC WRDSO_XESC_WORD
/* Indices into ws_escape */ /* Indices into ws_escape */
#define WRDSX_WORD 0 #define WRDSX_WORD 0

View file

@ -70,7 +70,7 @@ _wsplt_alloc_die (struct wordsplit *wsp)
abort (); abort ();
} }
static void static void
_wsplt_error (const char *fmt, ...) _wsplt_error (const char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -91,7 +91,7 @@ _wsplt_seterr (struct wordsplit *wsp, int ec)
wordsplit_perror (wsp); wordsplit_perror (wsp);
return ec; return ec;
} }
static int static int
_wsplt_nomem (struct wordsplit *wsp) _wsplt_nomem (struct wordsplit *wsp)
{ {
@ -122,7 +122,7 @@ _wsplt_subsplit (struct wordsplit *wsp, struct wordsplit *wss,
int flags, int finalize) int flags, int finalize)
{ {
int rc; int rc;
wss->ws_delim = wsp->ws_delim; wss->ws_delim = wsp->ws_delim;
wss->ws_debug = wsp->ws_debug; wss->ws_debug = wsp->ws_debug;
wss->ws_error = wsp->ws_error; wss->ws_error = wsp->ws_error;
@ -146,12 +146,12 @@ _wsplt_subsplit (struct wordsplit *wsp, struct wordsplit *wss,
} }
wss->ws_options = wsp->ws_options; wss->ws_options = wsp->ws_options;
flags |= WRDSF_DELIM flags |= WRDSF_DELIM
| WRDSF_ALLOC_DIE | WRDSF_ALLOC_DIE
| WRDSF_ERROR | WRDSF_ERROR
| WRDSF_DEBUG | WRDSF_DEBUG
| (wsp->ws_flags & (WRDSF_SHOWDBG | WRDSF_SHOWERR | WRDSF_OPTIONS)); | (wsp->ws_flags & (WRDSF_SHOWDBG | WRDSF_SHOWERR | WRDSF_OPTIONS));
rc = wordsplit_init (wss, str, len, flags); rc = wordsplit_init (wss, str, len, flags);
if (rc) if (rc)
@ -205,7 +205,7 @@ wordsplit_init0 (struct wordsplit *wsp)
} }
char wordsplit_c_escape_tab[] = "\\\\\"\"a\ab\bf\fn\nr\rt\tv\v"; char wordsplit_c_escape_tab[] = "\\\\\"\"a\ab\bf\fn\nr\rt\tv\v";
static int static int
wordsplit_init (struct wordsplit *wsp, const char *input, size_t len, wordsplit_init (struct wordsplit *wsp, const char *input, size_t len,
int flags) int flags)
@ -278,8 +278,8 @@ wordsplit_init (struct wordsplit *wsp, const char *input, size_t len,
{ {
wsp->ws_escape[WRDSX_WORD] = wordsplit_c_escape_tab; wsp->ws_escape[WRDSX_WORD] = wordsplit_c_escape_tab;
wsp->ws_escape[WRDSX_QUOTE] = wordsplit_c_escape_tab; wsp->ws_escape[WRDSX_QUOTE] = wordsplit_c_escape_tab;
wsp->ws_options |= WRDSO_OESC_QUOTE | WRDSO_OESC_WORD wsp->ws_options |= WRDSO_OESC_QUOTE | WRDSO_OESC_WORD
| WRDSO_XESC_QUOTE | WRDSO_XESC_WORD; | WRDSO_XESC_QUOTE | WRDSO_XESC_WORD;
} }
else else
{ {
@ -296,16 +296,16 @@ wordsplit_init (struct wordsplit *wsp, const char *input, size_t len,
} }
wsp->ws_paramidx = wsp->ws_paramsiz = 0; wsp->ws_paramidx = wsp->ws_paramsiz = 0;
wsp->ws_parambuf = NULL; wsp->ws_parambuf = NULL;
wsp->ws_endp = 0; wsp->ws_endp = 0;
wsp->ws_wordi = 0; wsp->ws_wordi = 0;
if (wsp->ws_flags & WRDSF_REUSE) if (wsp->ws_flags & WRDSF_REUSE)
wordsplit_free_nodes (wsp); wordsplit_free_nodes (wsp);
wsp->ws_head = wsp->ws_tail = NULL; wsp->ws_head = wsp->ws_tail = NULL;
wordsplit_init0 (wsp); wordsplit_init0 (wsp);
return 0; return 0;
} }
@ -591,7 +591,7 @@ coalesce_segment (struct wordsplit *wsp, struct wordsplit_node *node)
if (!(node->flags & _WSNF_JOIN)) if (!(node->flags & _WSNF_JOIN))
return 0; return 0;
for (p = node; p && (p->flags & _WSNF_JOIN); p = p->next) for (p = node; p && (p->flags & _WSNF_JOIN); p = p->next)
{ {
len += wsnode_len (p); len += wsnode_len (p);
@ -721,11 +721,11 @@ wordsplit_finish (struct wordsplit *wsp)
Nodes of type _WSNF_DELIM get inserted to the node list if either Nodes of type _WSNF_DELIM get inserted to the node list if either
WRDSF_RETURN_DELIMS flag or WRDSO_MAXWORDS option is set. WRDSF_RETURN_DELIMS flag or WRDSO_MAXWORDS option is set.
The following cases should be distinguished: The following cases should be distinguished:
1. If both WRDSF_SQUEEZE_DELIMS and WRDSF_RETURN_DELIMS are set, compress 1. If both WRDSF_SQUEEZE_DELIMS and WRDSF_RETURN_DELIMS are set, compress
any runs of similar delimiter nodes to a single node. The nodes are any runs of similar delimiter nodes to a single node. The nodes are
'similar' if they point to the same delimiter character. 'similar' if they point to the same delimiter character.
If WRDSO_MAXWORDS option is set, stop compressing when If WRDSO_MAXWORDS option is set, stop compressing when
@ -733,12 +733,12 @@ wordsplit_finish (struct wordsplit *wsp)
a single last node. a single last node.
2. If WRDSO_MAXWORDS option is set, but WRDSF_RETURN_DELIMS is not, 2. If WRDSO_MAXWORDS option is set, but WRDSF_RETURN_DELIMS is not,
remove any delimiter nodes. Stop operation when remove any delimiter nodes. Stop operation when
ws_wordi + 1 == ws_maxwords, and coalesce the rest of nodes into ws_wordi + 1 == ws_maxwords, and coalesce the rest of nodes into
a single last node. a single last node.
3. If incremental operation is in progress, restart the loop any time 3. If incremental operation is in progress, restart the loop any time
a delimiter node is about to be returned, unless WRDSF_RETURN_DELIMS a delimiter node is about to be returned, unless WRDSF_RETURN_DELIMS
is set. is set.
*/ */
again: again:
@ -785,7 +785,7 @@ wordsplit_finish (struct wordsplit *wsp)
continue; continue;
} }
} }
else else
{ {
if (delim) if (delim)
{ {
@ -858,8 +858,8 @@ wordsplit_finish (struct wordsplit *wsp)
char *newstr = malloc (slen + 1); char *newstr = malloc (slen + 1);
/* Assign newstr first, even if it is NULL. This way /* Assign newstr first, even if it is NULL. This way
wordsplit_free will work even if we return wordsplit_free will work even if we return
nomem later. */ nomem later. */
wsp->ws_wordv[wsp->ws_offs + wsp->ws_wordc] = newstr; wsp->ws_wordv[wsp->ws_offs + wsp->ws_wordc] = newstr;
if (!newstr) if (!newstr)
return _wsplt_nomem (wsp); return _wsplt_nomem (wsp);
@ -972,7 +972,7 @@ find_closing_paren (const char *str, size_t i, size_t len, size_t *poff,
break; break;
} }
break; break;
case '"': case '"':
state = st_dquote; state = st_dquote;
break; break;
@ -1052,7 +1052,7 @@ wsplt_assign_var (struct wordsplit *wsp, const char *name, size_t namelen,
{ {
int n = (wsp->ws_flags & WRDSF_ENV_KV) ? 2 : 1; int n = (wsp->ws_flags & WRDSF_ENV_KV) ? 2 : 1;
char *v; char *v;
if (wsp->ws_envidx + n >= wsp->ws_envsiz) if (wsp->ws_envidx + n >= wsp->ws_envsiz)
{ {
size_t sz; size_t sz;
@ -1069,7 +1069,7 @@ wsplt_assign_var (struct wordsplit *wsp, const char *name, size_t namelen,
for (; wsp->ws_env[i]; i++) for (; wsp->ws_env[i]; i++)
; ;
} }
sz = i + n + 1; sz = i + n + 1;
newenv = calloc (sz, sizeof(newenv[0])); newenv = calloc (sz, sizeof(newenv[0]));
@ -1088,7 +1088,7 @@ wsplt_assign_var (struct wordsplit *wsp, const char *name, size_t namelen,
} }
} }
newenv[j] = NULL; newenv[j] = NULL;
wsp->ws_envbuf = newenv; wsp->ws_envbuf = newenv;
wsp->ws_envidx = i; wsp->ws_envidx = i;
wsp->ws_envsiz = sz; wsp->ws_envsiz = sz;
@ -1109,7 +1109,7 @@ wsplt_assign_var (struct wordsplit *wsp, const char *name, size_t namelen,
else else
{ {
size_t n = wsp->ws_envsiz; size_t n = wsp->ws_envsiz;
if ((size_t) -1 / 3 * 2 / sizeof (wsp->ws_envbuf[0]) <= n) if ((size_t) -1 / 3 * 2 / sizeof (wsp->ws_envbuf[0]) <= n)
return _wsplt_nomem (wsp); return _wsplt_nomem (wsp);
n += (n + 1) / 2; n += (n + 1) / 2;
@ -1121,7 +1121,7 @@ wsplt_assign_var (struct wordsplit *wsp, const char *name, size_t namelen,
wsp->ws_env = (const char**) wsp->ws_envbuf; wsp->ws_env = (const char**) wsp->ws_envbuf;
} }
} }
if (wsp->ws_flags & WRDSF_ENV_KV) if (wsp->ws_flags & WRDSF_ENV_KV)
{ {
/* A key-value pair environment */ /* A key-value pair environment */
@ -1158,7 +1158,7 @@ int
wsplt_assign_param (struct wordsplit *wsp, int param_idx, char *value) wsplt_assign_param (struct wordsplit *wsp, int param_idx, char *value)
{ {
char *v; char *v;
if (param_idx < 0) if (param_idx < 0)
return WRDSE_BADPARAM; return WRDSE_BADPARAM;
if (param_idx == wsp->ws_paramc) if (param_idx == wsp->ws_paramc)
@ -1167,7 +1167,7 @@ wsplt_assign_param (struct wordsplit *wsp, int param_idx, char *value)
if (!wsp->ws_parambuf) if (!wsp->ws_parambuf)
{ {
size_t i; size_t i;
parambuf = calloc ((size_t)param_idx + 1, sizeof (parambuf[0])); parambuf = calloc ((size_t)param_idx + 1, sizeof (parambuf[0]));
if (!parambuf) if (!parambuf)
return _wsplt_nomem (wsp); return _wsplt_nomem (wsp);
@ -1183,7 +1183,7 @@ wsplt_assign_param (struct wordsplit *wsp, int param_idx, char *value)
return _wsplt_nomem (wsp); return _wsplt_nomem (wsp);
} }
} }
wsp->ws_parambuf = parambuf; wsp->ws_parambuf = parambuf;
wsp->ws_paramidx = param_idx; wsp->ws_paramidx = param_idx;
wsp->ws_paramsiz = param_idx + 1; wsp->ws_paramsiz = param_idx + 1;
@ -1191,7 +1191,7 @@ wsplt_assign_param (struct wordsplit *wsp, int param_idx, char *value)
else else
{ {
size_t n = wsp->ws_paramsiz; size_t n = wsp->ws_paramsiz;
if ((size_t) -1 / 3 * 2 / sizeof (wsp->ws_parambuf[0]) <= n) if ((size_t) -1 / 3 * 2 / sizeof (wsp->ws_parambuf[0]) <= n)
return _wsplt_nomem (wsp); return _wsplt_nomem (wsp);
n += (n + 1) / 2; n += (n + 1) / 2;
@ -1208,11 +1208,11 @@ wsplt_assign_param (struct wordsplit *wsp, int param_idx, char *value)
} }
else if (param_idx > wsp->ws_paramc) else if (param_idx > wsp->ws_paramc)
return WRDSE_BADPARAM; return WRDSE_BADPARAM;
v = strdup (value); v = strdup (value);
if (!v) if (!v)
return _wsplt_nomem (wsp); return _wsplt_nomem (wsp);
free (wsp->ws_parambuf[param_idx]); free (wsp->ws_parambuf[param_idx]);
wsp->ws_parambuf[param_idx] = v; wsp->ws_parambuf[param_idx] = v;
return WRDSE_OK; return WRDSE_OK;
@ -1247,10 +1247,10 @@ expand_paramv (struct wordsplit *wsp, struct wordsplit_node **ptail, int flg,
{ {
struct wordsplit ws; struct wordsplit ws;
int wsflags = WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_QUOTE int wsflags = WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_QUOTE
| (WSP_RETURN_DELIMS (wsp) ? WRDSF_RETURN_DELIMS : 0) | (WSP_RETURN_DELIMS (wsp) ? WRDSF_RETURN_DELIMS : 0)
| (q ? WRDSF_NOSPLIT : 0); | (q ? WRDSF_NOSPLIT : 0);
size_t i; size_t i;
for (i = 0; i < wsp->ws_paramc; i++) for (i = 0; i < wsp->ws_paramc; i++)
{ {
struct wordsplit_node *np; struct wordsplit_node *np;
@ -1272,7 +1272,7 @@ expand_paramv (struct wordsplit *wsp, struct wordsplit_node **ptail, int flg,
*ptail = np; *ptail = np;
np->flags = _WSNF_WORD | _WSNF_NOEXPAND | flg; np->flags = _WSNF_WORD | _WSNF_NOEXPAND | flg;
np->v.word = ws.ws_wordv[0]; np->v.word = ws.ws_wordv[0];
ws.ws_wordv[0] = NULL; ws.ws_wordv[0] = NULL;
} }
else else
@ -1283,7 +1283,7 @@ expand_paramv (struct wordsplit *wsp, struct wordsplit_node **ptail, int flg,
*ptail = ws.ws_tail; *ptail = ws.ws_tail;
ws.ws_head = ws.ws_tail = NULL; ws.ws_head = ws.ws_tail = NULL;
} }
wsflags |= WRDSF_REUSE; wsflags |= WRDSF_REUSE;
} }
if (wsflags & WRDSF_REUSE) if (wsflags & WRDSF_REUSE)
@ -1305,7 +1305,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
struct wordsplit ws; struct wordsplit ws;
int is_param = 0; int is_param = 0;
long param_idx = 0; long param_idx = 0;
if (ISVARBEG (str[0])) if (ISVARBEG (str[0]))
{ {
for (i = 1; i < len; i++) for (i = 1; i < len; i++)
@ -1358,7 +1358,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
if (str[i] == ':') if (str[i] == ':')
{ {
size_t j; size_t j;
defstr = str + i + 1; defstr = str + i + 1;
if (find_closing_paren (str, i + 1, len, &j, "{}")) if (find_closing_paren (str, i + 1, len, &j, "{}"))
return _wsplt_seterr (wsp, WRDSE_CBRACE); return _wsplt_seterr (wsp, WRDSE_CBRACE);
@ -1374,7 +1374,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
else if (strchr ("-+?=", str[i])) else if (strchr ("-+?=", str[i]))
{ {
size_t j; size_t j;
defstr = str + i; defstr = str + i;
if (find_closing_paren (str, i, len, &j, "{}")) if (find_closing_paren (str, i, len, &j, "{}"))
return _wsplt_seterr (wsp, WRDSE_CBRACE); return _wsplt_seterr (wsp, WRDSE_CBRACE);
@ -1400,10 +1400,10 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
return expvar_recover (wsp, str - 1, ptail, pend, flg); return expvar_recover (wsp, str - 1, ptail, pend, flg);
} }
} }
if (is_param && str[0] == '-') if (is_param && str[0] == '-')
param_idx = wsp->ws_paramc - param_idx; param_idx = wsp->ws_paramc - param_idx;
if (i == len) if (i == len)
return _wsplt_seterr (wsp, WRDSE_CBRACE); return _wsplt_seterr (wsp, WRDSE_CBRACE);
} }
@ -1456,7 +1456,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
else else
rc = WRDSE_UNDEF; rc = WRDSE_UNDEF;
} }
if (rc == WRDSE_OK if (rc == WRDSE_OK
&& (!value || value[0] == 0) && (!value || value[0] == 0)
&& defstr && defstr[-1] == ':') && defstr && defstr[-1] == ':')
@ -1465,7 +1465,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
rc = WRDSE_UNDEF; rc = WRDSE_UNDEF;
} }
} }
switch (rc) switch (rc)
{ {
case WRDSE_OK: case WRDSE_OK:
@ -1485,7 +1485,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
wordsplit_free (&ws); wordsplit_free (&ws);
} }
break; break;
case WRDSE_UNDEF: case WRDSE_UNDEF:
if (defstr) if (defstr)
{ {
@ -1505,7 +1505,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
value = ws.ws_wordv[0]; value = ws.ws_wordv[0];
ws.ws_wordv[0] = NULL; ws.ws_wordv[0] = NULL;
wordsplit_free (&ws); wordsplit_free (&ws);
if (defstr[-1] == '=') if (defstr[-1] == '=')
{ {
if (is_param) if (is_param)
@ -1519,7 +1519,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
return rc; return rc;
} }
} }
else else
{ {
if (*defstr == '?') if (*defstr == '?')
{ {
@ -1567,7 +1567,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
} }
} }
break; break;
case WRDSE_NOSPACE: case WRDSE_NOSPACE:
return _wsplt_nomem (wsp); return _wsplt_nomem (wsp);
@ -1606,7 +1606,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
{ {
struct wordsplit ws; struct wordsplit ws;
int rc; int rc;
rc = _wsplt_subsplit (wsp, &ws, value, strlen (value), rc = _wsplt_subsplit (wsp, &ws, value, strlen (value),
WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_NOVAR | WRDSF_NOCMD |
WRDSF_QUOTE WRDSF_QUOTE
@ -1711,7 +1711,7 @@ node_expand (struct wordsplit *wsp, struct wordsplit_node *node,
} }
return 0; return 0;
} }
/* Remove NULL nodes from the list */ /* Remove NULL nodes from the list */
static void static void
wsnode_nullelim (struct wordsplit *wsp) wsnode_nullelim (struct wordsplit *wsp)
@ -1765,7 +1765,7 @@ expcmd (struct wordsplit *wsp, const char *str, size_t len,
char *value; char *value;
struct wordsplit_node *newnode; struct wordsplit_node *newnode;
struct wordsplit ws; struct wordsplit ws;
str++; str++;
len--; len--;
@ -1785,7 +1785,7 @@ expcmd (struct wordsplit *wsp, const char *str, size_t len,
} }
rc = wsp->ws_command (&value, str, j, ws.ws_wordv, wsp->ws_closure); rc = wsp->ws_command (&value, str, j, ws.ws_wordv, wsp->ws_closure);
wordsplit_free (&ws); wordsplit_free (&ws);
if (rc == WRDSE_NOSPACE) if (rc == WRDSE_NOSPACE)
return _wsplt_nomem (wsp); return _wsplt_nomem (wsp);
else if (rc) else if (rc)
@ -1893,13 +1893,13 @@ wordsplit_trimws (struct wordsplit *wsp)
; ;
p->v.segm.beg = n; p->v.segm.beg = n;
} }
while (p->next && (p->flags & _WSNF_JOIN)) while (p->next && (p->flags & _WSNF_JOIN))
p = p->next; p = p->next;
if (p->flags & _WSNF_QUOTE) if (p->flags & _WSNF_QUOTE)
continue; continue;
/* Trim trailing whitespace */ /* Trim trailing whitespace */
for (n = p->v.segm.end; for (n = p->v.segm.end;
n > p->v.segm.beg && ISWS (wsp->ws_input[n - 1]); n--); n > p->v.segm.beg && ISWS (wsp->ws_input[n - 1]); n--);
@ -1918,7 +1918,7 @@ wordsplit_tildexpand (struct wordsplit *wsp)
struct wordsplit_node *p; struct wordsplit_node *p;
char *uname = NULL; char *uname = NULL;
size_t usize = 0; size_t usize = 0;
for (p = wsp->ws_head; p; p = p->next) for (p = wsp->ws_head; p; p = p->next)
{ {
const char *str; const char *str;
@ -1933,7 +1933,7 @@ wordsplit_tildexpand (struct wordsplit *wsp)
size_t slen = wsnode_len (p); size_t slen = wsnode_len (p);
struct passwd *pw; struct passwd *pw;
char *newstr; char *newstr;
for (i = 1; i < slen && str[i] != '/'; i++) for (i = 1; i < slen && str[i] != '/'; i++)
; ;
if (i == slen) if (i == slen)
@ -2009,7 +2009,7 @@ wordsplit_pathexpand (struct wordsplit *wsp)
if (wsp->ws_options & WRDSO_DOTGLOB) if (wsp->ws_options & WRDSO_DOTGLOB)
flags = GLOB_PERIOD; flags = GLOB_PERIOD;
#endif #endif
for (p = wsp->ws_head; p; p = next) for (p = wsp->ws_head; p; p = next)
{ {
const char *str; const char *str;
@ -2027,7 +2027,7 @@ wordsplit_pathexpand (struct wordsplit *wsp)
int i; int i;
glob_t g; glob_t g;
struct wordsplit_node *prev; struct wordsplit_node *prev;
if (slen + 1 > patsize) if (slen + 1 > patsize)
{ {
char *p = realloc (pattern, slen + 1); char *p = realloc (pattern, slen + 1);
@ -2038,16 +2038,16 @@ wordsplit_pathexpand (struct wordsplit *wsp)
} }
memcpy (pattern, str, slen); memcpy (pattern, str, slen);
pattern[slen] = 0; pattern[slen] = 0;
switch (glob (pattern, flags, NULL, &g)) switch (glob (pattern, flags, NULL, &g))
{ {
case 0: case 0:
break; break;
case GLOB_NOSPACE: case GLOB_NOSPACE:
free (pattern); free (pattern);
return _wsplt_nomem (wsp); return _wsplt_nomem (wsp);
case GLOB_NOMATCH: case GLOB_NOMATCH:
if (wsp->ws_options & WRDSO_NULLGLOB) if (wsp->ws_options & WRDSO_NULLGLOB)
{ {
@ -2069,7 +2069,7 @@ wordsplit_pathexpand (struct wordsplit *wsp)
return _wsplt_seterr (wsp, WRDSE_USERERR); return _wsplt_seterr (wsp, WRDSE_USERERR);
} }
continue; continue;
default: default:
free (pattern); free (pattern);
return _wsplt_seterr (wsp, WRDSE_GLOBERR); return _wsplt_seterr (wsp, WRDSE_GLOBERR);
@ -2080,7 +2080,7 @@ wordsplit_pathexpand (struct wordsplit *wsp)
{ {
struct wordsplit_node *newnode; struct wordsplit_node *newnode;
char *newstr; char *newstr;
if (wsnode_new (wsp, &newnode)) if (wsnode_new (wsp, &newnode))
return 1; return 1;
newstr = strdup (g.gl_pathv[i]); newstr = strdup (g.gl_pathv[i]);
@ -2196,7 +2196,7 @@ scan_word (struct wordsplit *wsp, size_t start, int consume_all)
int join = 0; int join = 0;
int flags = 0; int flags = 0;
struct wordsplit_node *np = wsp->ws_tail; struct wordsplit_node *np = wsp->ws_tail;
size_t i = start; size_t i = start;
if (i >= len) if (i >= len)
@ -2287,7 +2287,7 @@ scan_word (struct wordsplit *wsp, size_t start, int consume_all)
wsp->ws_endp = i; wsp->ws_endp = i;
if (wsp->ws_flags & WRDSF_INCREMENTAL) if (wsp->ws_flags & WRDSF_INCREMENTAL)
return _WRDS_EOF; return _WRDS_EOF;
if (consume_all) if (consume_all)
{ {
if (!np) if (!np)
@ -2298,7 +2298,7 @@ scan_word (struct wordsplit *wsp, size_t start, int consume_all)
np = np->next; np = np->next;
} }
} }
return _WRDS_OK; return _WRDS_OK;
} }
@ -2562,7 +2562,7 @@ wordsplit_process_list (struct wordsplit *wsp, size_t start)
if (wsp->ws_flags & WRDSF_SHOWDBG) if (wsp->ws_flags & WRDSF_SHOWDBG)
wsp->ws_debug (_("(%02d) Input:%.*s;"), wsp->ws_debug (_("(%02d) Input:%.*s;"),
wsp->ws_lvl, (int) wsp->ws_len, wsp->ws_input); wsp->ws_lvl, (int) wsp->ws_len, wsp->ws_input);
if ((wsp->ws_flags & WRDSF_NOSPLIT) if ((wsp->ws_flags & WRDSF_NOSPLIT)
|| ((wsp->ws_options & WRDSO_MAXWORDS) || ((wsp->ws_options & WRDSO_MAXWORDS)
&& wsp->ws_wordi + 1 == wsp->ws_maxwords)) && wsp->ws_wordi + 1 == wsp->ws_maxwords))
@ -2623,7 +2623,7 @@ wordsplit_process_list (struct wordsplit *wsp, size_t start)
static int static int
wordsplit_run (const char *command, size_t length, struct wordsplit *wsp, wordsplit_run (const char *command, size_t length, struct wordsplit *wsp,
int flags, int lvl) int flags, int lvl)
{ {
int rc; int rc;
size_t start; size_t start;
@ -2659,8 +2659,8 @@ wordsplit_run (const char *command, size_t length, struct wordsplit *wsp,
} }
int int
wordsplit_len (const char *command, size_t length, struct wordsplit *wsp, wordsplit_len (const char *command, size_t length, struct wordsplit *wsp,
int flags) int flags)
{ {
return wordsplit_run (command, length, wsp, flags, 0); return wordsplit_run (command, length, wsp, flags, 0);
} }
@ -2800,4 +2800,3 @@ wordsplit_perror (struct wordsplit *wsp)
wsp->ws_error ("%s", wordsplit_strerror (wsp)); wsp->ws_error ("%s", wordsplit_strerror (wsp));
} }
} }