summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2019-05-14 16:59:07 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2019-05-14 16:59:07 (GMT)
commit39beda10e855d265b5af74ea53a5d7a89a91296a (patch) (unidiff)
tree86f671ebea706d691d1667304522c260f56924bd
parentf6586d810d8430d6d9f833119af39726a60e4a6c (diff)
downloadgrecs-39beda10e855d265b5af74ea53a5d7a89a91296a.tar.gz
grecs-39beda10e855d265b5af74ea53a5d7a89a91296a.tar.bz2
wordsplit: whitespace cleanup
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/wordsplit.h38
-rw-r--r--src/wordsplit.c147
2 files changed, 92 insertions, 93 deletions
diff --git a/include/wordsplit.h b/include/wordsplit.h
index d7eb26f..d4975b3 100644
--- a/include/wordsplit.h
+++ b/include/wordsplit.h
@@ -30,16 +30,16 @@ typedef struct wordsplit wordsplit_t;
30 must be set (or unset, if starting with !) in ws_flags (if starting with 30 must be set (or unset, if starting with !) in ws_flags (if starting with
31 WRDSF_) or ws_options (if starting with WRDSO_) to initialize or use the 31 WRDSF_) or ws_options (if starting with WRDSO_) to initialize or use the
32 given member. 32 given member.
33 33
34 If not redefined explicitly, most of them are set to some reasonable 34 If not redefined explicitly, most of them are set to some reasonable
35 default value upon entry to wordsplit(). */ 35 default value upon entry to wordsplit(). */
36struct wordsplit 36struct wordsplit
37{ 37{
38 size_t ws_wordc; /* [Output] Number of words in ws_wordv. */ 38 size_t ws_wordc; /* [Output] Number of words in ws_wordv. */
39 char **ws_wordv; /* [Output] Array of parsed out words. */ 39 char **ws_wordv; /* [Output] Array of parsed out words. */
40 size_t ws_offs; /* [Input] (WRDSF_DOOFFS) Number of initial 40 size_t ws_offs; /* [Input] (WRDSF_DOOFFS) Number of initial
41 elements in ws_wordv to fill with NULLs. */ 41 elements in ws_wordv to fill with NULLs. */
42 size_t ws_wordn; /* Number of elements ws_wordv can accomodate. */ 42 size_t ws_wordn; /* Number of elements ws_wordv can accomodate. */
43 int ws_flags; /* [Input] Flags passed to wordsplit. */ 43 int ws_flags; /* [Input] Flags passed to wordsplit. */
44 int ws_options; /* [Input] (WRDSF_OPTIONS) 44 int ws_options; /* [Input] (WRDSF_OPTIONS)
45 Additional options. */ 45 Additional options. */
@@ -53,15 +53,15 @@ struct wordsplit
53 const char *ws_escape[2]; /* [Input] (WRDSF_ESCAPE) Characters to be escaped 53 const char *ws_escape[2]; /* [Input] (WRDSF_ESCAPE) Characters to be escaped
54 with backslash. */ 54 with backslash. */
55 void (*ws_alloc_die) (wordsplit_t *wsp); 55 void (*ws_alloc_die) (wordsplit_t *wsp);
56 /* [Input] (WRDSF_ALLOC_DIE) Function called when 56 /* [Input] (WRDSF_ALLOC_DIE) Function called when
57 out of memory. Must not return. */ 57 out of memory. Must not return. */
58 void (*ws_error) (const char *, ...) 58 void (*ws_error) (const char *, ...)
59 __attribute__ ((__format__ (__printf__, 1, 2))); 59 __attribute__ ((__format__ (__printf__, 1, 2)));
60 /* [Input] (WRDSF_ERROR) Function used for error 60 /* [Input] (WRDSF_ERROR) Function used for error
61 reporting */ 61 reporting */
62 void (*ws_debug) (const char *, ...) 62 void (*ws_debug) (const char *, ...)
63 __attribute__ ((__format__ (__printf__, 1, 2))); 63 __attribute__ ((__format__ (__printf__, 1, 2)));
64 /* [Input] (WRDSF_DEBUG) Function used for debug 64 /* [Input] (WRDSF_DEBUG) Function used for debug
65 output. */ 65 output. */
66 const char **ws_env; /* [Input] (WRDSF_ENV, !WRDSF_NOVAR) Array of 66 const char **ws_env; /* [Input] (WRDSF_ENV, !WRDSF_NOVAR) Array of
67 environment variables. */ 67 environment variables. */
@@ -80,14 +80,14 @@ struct wordsplit
80 parameters */ 80 parameters */
81 size_t ws_paramc; /* Number of positional parameters */ 81 size_t ws_paramc; /* Number of positional parameters */
82 82
83 /* Temporary storage for parameters. Works similarly to ws_enbuf. 83 /* Temporary storage for parameters. Works similarly to ws_enbuf.
84 */ 84 */
85 char **ws_parambuf; 85 char **ws_parambuf;
86 size_t ws_paramidx; 86 size_t ws_paramidx;
87 size_t ws_paramsiz; 87 size_t ws_paramsiz;
88 88
89 int (*ws_getvar) (char **ret, const char *var, size_t len, void *clos); 89 int (*ws_getvar) (char **ret, const char *var, size_t len, void *clos);
90 /* [Input] (WRDSF_GETVAR, !WRDSF_NOVAR) Looks up 90 /* [Input] (WRDSF_GETVAR, !WRDSF_NOVAR) Looks up
91 the name VAR (LEN bytes long) in the table of 91 the name VAR (LEN bytes long) in the table of
92 variables and if found returns in memory 92 variables and if found returns in memory
93 location pointed to by RET the value of that 93 location pointed to by RET the value of that
@@ -96,13 +96,13 @@ struct wordsplit
96 on error. User-specific errors can be returned 96 on error. User-specific errors can be returned
97 by storing the error diagnostic string in RET 97 by storing the error diagnostic string in RET
98 and returning WRDSE_USERERR. 98 and returning WRDSE_USERERR.
99 Whatever is stored in RET, it must be allocated 99 Whatever is stored in RET, it must be allocated
100 using malloc(3). */ 100 using malloc(3). */
101 void *ws_closure; /* [Input] (WRDSF_CLOSURE) Passed as the CLOS 101 void *ws_closure; /* [Input] (WRDSF_CLOSURE) Passed as the CLOS
102 argument to ws_getvar and ws_command. */ 102 argument to ws_getvar and ws_command. */
103 int (*ws_command) (char **ret, const char *cmd, size_t len, char **argv, 103 int (*ws_command) (char **ret, const char *cmd, size_t len, char **argv,
104 void *clos); 104 void *clos);
105 /* [Input] (!WRDSF_NOCMD) Returns in the memory 105 /* [Input] (!WRDSF_NOCMD) Returns in the memory
106 location pointed to by RET the expansion of 106 location pointed to by RET the expansion of
107 the command CMD (LEN bytes long). On input, 107 the command CMD (LEN bytes long). On input,
108 ARGV contains CMD split out to words. 108 ARGV contains CMD split out to words.
@@ -110,7 +110,7 @@ struct wordsplit
110 See ws_getvar for a discussion of possible 110 See ws_getvar for a discussion of possible
111 return values. */ 111 return values. */
112 112
113 const char *ws_input; /* Input string (the S argument to wordsplit. */ 113 const char *ws_input; /* Input string (the S argument to wordsplit. */
114 size_t ws_len; /* Length of ws_input. */ 114 size_t ws_len; /* Length of ws_input. */
115 size_t ws_endp; /* Points past the last processed byte in 115 size_t ws_endp; /* Points past the last processed byte in
116 ws_input. */ 116 ws_input. */
@@ -119,7 +119,7 @@ struct wordsplit
119 the error, if ws_errno is WRDSE_USERERR. Must 119 the error, if ws_errno is WRDSE_USERERR. Must
120 be allocated with malloc(3). */ 120 be allocated with malloc(3). */
121 struct wordsplit_node *ws_head, *ws_tail; 121 struct wordsplit_node *ws_head, *ws_tail;
122 /* Doubly-linked list of parsed out nodes. */ 122 /* Doubly-linked list of parsed out nodes. */
123 int ws_lvl; /* Invocation nesting level. */ 123 int ws_lvl; /* Invocation nesting level. */
124}; 124};
125 125
@@ -242,9 +242,9 @@ struct wordsplit
242 parameter) */ 242 parameter) */
243#define WRDSO_PARAM_NEGIDX 0x00008000 243#define WRDSO_PARAM_NEGIDX 0x00008000
244 244
245#define WRDSO_BSKEEP WRDSO_BSKEEP_WORD 245#define WRDSO_BSKEEP WRDSO_BSKEEP_WORD
246#define WRDSO_OESC WRDSO_OESC_WORD 246#define WRDSO_OESC WRDSO_OESC_WORD
247#define WRDSO_XESC WRDSO_XESC_WORD 247#define WRDSO_XESC WRDSO_XESC_WORD
248 248
249/* Indices into ws_escape */ 249/* Indices into ws_escape */
250#define WRDSX_WORD 0 250#define WRDSX_WORD 0
diff --git a/src/wordsplit.c b/src/wordsplit.c
index 05c3643..f563725 100644
--- a/src/wordsplit.c
+++ b/src/wordsplit.c
@@ -70,7 +70,7 @@ _wsplt_alloc_die (struct wordsplit *wsp)
70 abort (); 70 abort ();
71} 71}
72 72
73static void 73static void
74_wsplt_error (const char *fmt, ...) 74_wsplt_error (const char *fmt, ...)
75{ 75{
76 va_list ap; 76 va_list ap;
@@ -91,7 +91,7 @@ _wsplt_seterr (struct wordsplit *wsp, int ec)
91 wordsplit_perror (wsp); 91 wordsplit_perror (wsp);
92 return ec; 92 return ec;
93} 93}
94 94
95static int 95static int
96_wsplt_nomem (struct wordsplit *wsp) 96_wsplt_nomem (struct wordsplit *wsp)
97{ 97{
@@ -122,7 +122,7 @@ _wsplt_subsplit (struct wordsplit *wsp, struct wordsplit *wss,
122 int flags, int finalize) 122 int flags, int finalize)
123{ 123{
124 int rc; 124 int rc;
125 125
126 wss->ws_delim = wsp->ws_delim; 126 wss->ws_delim = wsp->ws_delim;
127 wss->ws_debug = wsp->ws_debug; 127 wss->ws_debug = wsp->ws_debug;
128 wss->ws_error = wsp->ws_error; 128 wss->ws_error = wsp->ws_error;
@@ -146,12 +146,12 @@ _wsplt_subsplit (struct wordsplit *wsp, struct wordsplit *wss,
146 } 146 }
147 147
148 wss->ws_options = wsp->ws_options; 148 wss->ws_options = wsp->ws_options;
149 149
150 flags |= WRDSF_DELIM 150 flags |= WRDSF_DELIM
151 | WRDSF_ALLOC_DIE 151 | WRDSF_ALLOC_DIE
152 | WRDSF_ERROR 152 | WRDSF_ERROR
153 | WRDSF_DEBUG 153 | WRDSF_DEBUG
154 | (wsp->ws_flags & (WRDSF_SHOWDBG | WRDSF_SHOWERR | WRDSF_OPTIONS)); 154 | (wsp->ws_flags & (WRDSF_SHOWDBG | WRDSF_SHOWERR | WRDSF_OPTIONS));
155 155
156 rc = wordsplit_init (wss, str, len, flags); 156 rc = wordsplit_init (wss, str, len, flags);
157 if (rc) 157 if (rc)
@@ -205,7 +205,7 @@ wordsplit_init0 (struct wordsplit *wsp)
205} 205}
206 206
207char wordsplit_c_escape_tab[] = "\\\\\"\"a\ab\bf\fn\nr\rt\tv\v"; 207char wordsplit_c_escape_tab[] = "\\\\\"\"a\ab\bf\fn\nr\rt\tv\v";
208 208
209static int 209static int
210wordsplit_init (struct wordsplit *wsp, const char *input, size_t len, 210wordsplit_init (struct wordsplit *wsp, const char *input, size_t len,
211 int flags) 211 int flags)
@@ -278,8 +278,8 @@ wordsplit_init (struct wordsplit *wsp, const char *input, size_t len,
278 { 278 {
279 wsp->ws_escape[WRDSX_WORD] = wordsplit_c_escape_tab; 279 wsp->ws_escape[WRDSX_WORD] = wordsplit_c_escape_tab;
280 wsp->ws_escape[WRDSX_QUOTE] = wordsplit_c_escape_tab; 280 wsp->ws_escape[WRDSX_QUOTE] = wordsplit_c_escape_tab;
281 wsp->ws_options |= WRDSO_OESC_QUOTE | WRDSO_OESC_WORD 281 wsp->ws_options |= WRDSO_OESC_QUOTE | WRDSO_OESC_WORD
282 | WRDSO_XESC_QUOTE | WRDSO_XESC_WORD; 282 | WRDSO_XESC_QUOTE | WRDSO_XESC_WORD;
283 } 283 }
284 else 284 else
285 { 285 {
@@ -296,16 +296,16 @@ wordsplit_init (struct wordsplit *wsp, const char *input, size_t len,
296 } 296 }
297 wsp->ws_paramidx = wsp->ws_paramsiz = 0; 297 wsp->ws_paramidx = wsp->ws_paramsiz = 0;
298 wsp->ws_parambuf = NULL; 298 wsp->ws_parambuf = NULL;
299 299
300 wsp->ws_endp = 0; 300 wsp->ws_endp = 0;
301 wsp->ws_wordi = 0; 301 wsp->ws_wordi = 0;
302 302
303 if (wsp->ws_flags & WRDSF_REUSE) 303 if (wsp->ws_flags & WRDSF_REUSE)
304 wordsplit_free_nodes (wsp); 304 wordsplit_free_nodes (wsp);
305 wsp->ws_head = wsp->ws_tail = NULL; 305 wsp->ws_head = wsp->ws_tail = NULL;
306 306
307 wordsplit_init0 (wsp); 307 wordsplit_init0 (wsp);
308 308
309 return 0; 309 return 0;
310} 310}
311 311
@@ -591,7 +591,7 @@ coalesce_segment (struct wordsplit *wsp, struct wordsplit_node *node)
591 591
592 if (!(node->flags & _WSNF_JOIN)) 592 if (!(node->flags & _WSNF_JOIN))
593 return 0; 593 return 0;
594 594
595 for (p = node; p && (p->flags & _WSNF_JOIN); p = p->next) 595 for (p = node; p && (p->flags & _WSNF_JOIN); p = p->next)
596 { 596 {
597 len += wsnode_len (p); 597 len += wsnode_len (p);
@@ -721,11 +721,11 @@ wordsplit_finish (struct wordsplit *wsp)
721 721
722 Nodes of type _WSNF_DELIM get inserted to the node list if either 722 Nodes of type _WSNF_DELIM get inserted to the node list if either
723 WRDSF_RETURN_DELIMS flag or WRDSO_MAXWORDS option is set. 723 WRDSF_RETURN_DELIMS flag or WRDSO_MAXWORDS option is set.
724 724
725 The following cases should be distinguished: 725 The following cases should be distinguished:
726 726
727 1. If both WRDSF_SQUEEZE_DELIMS and WRDSF_RETURN_DELIMS are set, compress 727 1. If both WRDSF_SQUEEZE_DELIMS and WRDSF_RETURN_DELIMS are set, compress
728 any runs of similar delimiter nodes to a single node. The nodes are 728 any runs of similar delimiter nodes to a single node. The nodes are
729 'similar' if they point to the same delimiter character. 729 'similar' if they point to the same delimiter character.
730 730
731 If WRDSO_MAXWORDS option is set, stop compressing when 731 If WRDSO_MAXWORDS option is set, stop compressing when
@@ -733,12 +733,12 @@ wordsplit_finish (struct wordsplit *wsp)
733 a single last node. 733 a single last node.
734 734
735 2. If WRDSO_MAXWORDS option is set, but WRDSF_RETURN_DELIMS is not, 735 2. If WRDSO_MAXWORDS option is set, but WRDSF_RETURN_DELIMS is not,
736 remove any delimiter nodes. Stop operation when 736 remove any delimiter nodes. Stop operation when
737 ws_wordi + 1 == ws_maxwords, and coalesce the rest of nodes into 737 ws_wordi + 1 == ws_maxwords, and coalesce the rest of nodes into
738 a single last node. 738 a single last node.
739 739
740 3. If incremental operation is in progress, restart the loop any time 740 3. If incremental operation is in progress, restart the loop any time
741 a delimiter node is about to be returned, unless WRDSF_RETURN_DELIMS 741 a delimiter node is about to be returned, unless WRDSF_RETURN_DELIMS
742 is set. 742 is set.
743 */ 743 */
744 again: 744 again:
@@ -785,7 +785,7 @@ wordsplit_finish (struct wordsplit *wsp)
785 continue; 785 continue;
786 } 786 }
787 } 787 }
788 else 788 else
789 { 789 {
790 if (delim) 790 if (delim)
791 { 791 {
@@ -858,8 +858,8 @@ wordsplit_finish (struct wordsplit *wsp)
858 char *newstr = malloc (slen + 1); 858 char *newstr = malloc (slen + 1);
859 859
860 /* Assign newstr first, even if it is NULL. This way 860 /* Assign newstr first, even if it is NULL. This way
861 wordsplit_free will work even if we return 861 wordsplit_free will work even if we return
862 nomem later. */ 862 nomem later. */
863 wsp->ws_wordv[wsp->ws_offs + wsp->ws_wordc] = newstr; 863 wsp->ws_wordv[wsp->ws_offs + wsp->ws_wordc] = newstr;
864 if (!newstr) 864 if (!newstr)
865 return _wsplt_nomem (wsp); 865 return _wsplt_nomem (wsp);
@@ -972,7 +972,7 @@ find_closing_paren (const char *str, size_t i, size_t len, size_t *poff,
972 break; 972 break;
973 } 973 }
974 break; 974 break;
975 975
976 case '"': 976 case '"':
977 state = st_dquote; 977 state = st_dquote;
978 break; 978 break;
@@ -1052,7 +1052,7 @@ wsplt_assign_var (struct wordsplit *wsp, const char *name, size_t namelen,
1052{ 1052{
1053 int n = (wsp->ws_flags & WRDSF_ENV_KV) ? 2 : 1; 1053 int n = (wsp->ws_flags & WRDSF_ENV_KV) ? 2 : 1;
1054 char *v; 1054 char *v;
1055 1055
1056 if (wsp->ws_envidx + n >= wsp->ws_envsiz) 1056 if (wsp->ws_envidx + n >= wsp->ws_envsiz)
1057 { 1057 {
1058 size_t sz; 1058 size_t sz;
@@ -1069,7 +1069,7 @@ wsplt_assign_var (struct wordsplit *wsp, const char *name, size_t namelen,
1069 for (; wsp->ws_env[i]; i++) 1069 for (; wsp->ws_env[i]; i++)
1070 ; 1070 ;
1071 } 1071 }
1072 1072
1073 sz = i + n + 1; 1073 sz = i + n + 1;
1074 1074
1075 newenv = calloc (sz, sizeof(newenv[0])); 1075 newenv = calloc (sz, sizeof(newenv[0]));
@@ -1088,7 +1088,7 @@ wsplt_assign_var (struct wordsplit *wsp, const char *name, size_t namelen,
1088 } 1088 }
1089 } 1089 }
1090 newenv[j] = NULL; 1090 newenv[j] = NULL;
1091 1091
1092 wsp->ws_envbuf = newenv; 1092 wsp->ws_envbuf = newenv;
1093 wsp->ws_envidx = i; 1093 wsp->ws_envidx = i;
1094 wsp->ws_envsiz = sz; 1094 wsp->ws_envsiz = sz;
@@ -1109,7 +1109,7 @@ wsplt_assign_var (struct wordsplit *wsp, const char *name, size_t namelen,
1109 else 1109 else
1110 { 1110 {
1111 size_t n = wsp->ws_envsiz; 1111 size_t n = wsp->ws_envsiz;
1112 1112
1113 if ((size_t) -1 / 3 * 2 / sizeof (wsp->ws_envbuf[0]) <= n) 1113 if ((size_t) -1 / 3 * 2 / sizeof (wsp->ws_envbuf[0]) <= n)
1114 return _wsplt_nomem (wsp); 1114 return _wsplt_nomem (wsp);
1115 n += (n + 1) / 2; 1115 n += (n + 1) / 2;
@@ -1121,7 +1121,7 @@ wsplt_assign_var (struct wordsplit *wsp, const char *name, size_t namelen,
1121 wsp->ws_env = (const char**) wsp->ws_envbuf; 1121 wsp->ws_env = (const char**) wsp->ws_envbuf;
1122 } 1122 }
1123 } 1123 }
1124 1124
1125 if (wsp->ws_flags & WRDSF_ENV_KV) 1125 if (wsp->ws_flags & WRDSF_ENV_KV)
1126 { 1126 {
1127 /* A key-value pair environment */ 1127 /* A key-value pair environment */
@@ -1158,7 +1158,7 @@ int
1158wsplt_assign_param (struct wordsplit *wsp, int param_idx, char *value) 1158wsplt_assign_param (struct wordsplit *wsp, int param_idx, char *value)
1159{ 1159{
1160 char *v; 1160 char *v;
1161 1161
1162 if (param_idx < 0) 1162 if (param_idx < 0)
1163 return WRDSE_BADPARAM; 1163 return WRDSE_BADPARAM;
1164 if (param_idx == wsp->ws_paramc) 1164 if (param_idx == wsp->ws_paramc)
@@ -1167,7 +1167,7 @@ wsplt_assign_param (struct wordsplit *wsp, int param_idx, char *value)
1167 if (!wsp->ws_parambuf) 1167 if (!wsp->ws_parambuf)
1168 { 1168 {
1169 size_t i; 1169 size_t i;
1170 1170
1171 parambuf = calloc ((size_t)param_idx + 1, sizeof (parambuf[0])); 1171 parambuf = calloc ((size_t)param_idx + 1, sizeof (parambuf[0]));
1172 if (!parambuf) 1172 if (!parambuf)
1173 return _wsplt_nomem (wsp); 1173 return _wsplt_nomem (wsp);
@@ -1183,7 +1183,7 @@ wsplt_assign_param (struct wordsplit *wsp, int param_idx, char *value)
1183 return _wsplt_nomem (wsp); 1183 return _wsplt_nomem (wsp);
1184 } 1184 }
1185 } 1185 }
1186 1186
1187 wsp->ws_parambuf = parambuf; 1187 wsp->ws_parambuf = parambuf;
1188 wsp->ws_paramidx = param_idx; 1188 wsp->ws_paramidx = param_idx;
1189 wsp->ws_paramsiz = param_idx + 1; 1189 wsp->ws_paramsiz = param_idx + 1;
@@ -1191,7 +1191,7 @@ wsplt_assign_param (struct wordsplit *wsp, int param_idx, char *value)
1191 else 1191 else
1192 { 1192 {
1193 size_t n = wsp->ws_paramsiz; 1193 size_t n = wsp->ws_paramsiz;
1194 1194
1195 if ((size_t) -1 / 3 * 2 / sizeof (wsp->ws_parambuf[0]) <= n) 1195 if ((size_t) -1 / 3 * 2 / sizeof (wsp->ws_parambuf[0]) <= n)
1196 return _wsplt_nomem (wsp); 1196 return _wsplt_nomem (wsp);
1197 n += (n + 1) / 2; 1197 n += (n + 1) / 2;
@@ -1208,11 +1208,11 @@ wsplt_assign_param (struct wordsplit *wsp, int param_idx, char *value)
1208 } 1208 }
1209 else if (param_idx > wsp->ws_paramc) 1209 else if (param_idx > wsp->ws_paramc)
1210 return WRDSE_BADPARAM; 1210 return WRDSE_BADPARAM;
1211 1211
1212 v = strdup (value); 1212 v = strdup (value);
1213 if (!v) 1213 if (!v)
1214 return _wsplt_nomem (wsp); 1214 return _wsplt_nomem (wsp);
1215 1215
1216 free (wsp->ws_parambuf[param_idx]); 1216 free (wsp->ws_parambuf[param_idx]);
1217 wsp->ws_parambuf[param_idx] = v; 1217 wsp->ws_parambuf[param_idx] = v;
1218 return WRDSE_OK; 1218 return WRDSE_OK;
@@ -1247,10 +1247,10 @@ expand_paramv (struct wordsplit *wsp, struct wordsplit_node **ptail, int flg,
1247{ 1247{
1248 struct wordsplit ws; 1248 struct wordsplit ws;
1249 int wsflags = WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_QUOTE 1249 int wsflags = WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_QUOTE
1250 | (WSP_RETURN_DELIMS (wsp) ? WRDSF_RETURN_DELIMS : 0) 1250 | (WSP_RETURN_DELIMS (wsp) ? WRDSF_RETURN_DELIMS : 0)
1251 | (q ? WRDSF_NOSPLIT : 0); 1251 | (q ? WRDSF_NOSPLIT : 0);
1252 size_t i; 1252 size_t i;
1253 1253
1254 for (i = 0; i < wsp->ws_paramc; i++) 1254 for (i = 0; i < wsp->ws_paramc; i++)
1255 { 1255 {
1256 struct wordsplit_node *np; 1256 struct wordsplit_node *np;
@@ -1272,7 +1272,7 @@ expand_paramv (struct wordsplit *wsp, struct wordsplit_node **ptail, int flg,
1272 *ptail = np; 1272 *ptail = np;
1273 np->flags = _WSNF_WORD | _WSNF_NOEXPAND | flg; 1273 np->flags = _WSNF_WORD | _WSNF_NOEXPAND | flg;
1274 np->v.word = ws.ws_wordv[0]; 1274 np->v.word = ws.ws_wordv[0];
1275 1275
1276 ws.ws_wordv[0] = NULL; 1276 ws.ws_wordv[0] = NULL;
1277 } 1277 }
1278 else 1278 else
@@ -1283,7 +1283,7 @@ expand_paramv (struct wordsplit *wsp, struct wordsplit_node **ptail, int flg,
1283 *ptail = ws.ws_tail; 1283 *ptail = ws.ws_tail;
1284 ws.ws_head = ws.ws_tail = NULL; 1284 ws.ws_head = ws.ws_tail = NULL;
1285 } 1285 }
1286 1286
1287 wsflags |= WRDSF_REUSE; 1287 wsflags |= WRDSF_REUSE;
1288 } 1288 }
1289 if (wsflags & WRDSF_REUSE) 1289 if (wsflags & WRDSF_REUSE)
@@ -1305,7 +1305,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
1305 struct wordsplit ws; 1305 struct wordsplit ws;
1306 int is_param = 0; 1306 int is_param = 0;
1307 long param_idx = 0; 1307 long param_idx = 0;
1308 1308
1309 if (ISVARBEG (str[0])) 1309 if (ISVARBEG (str[0]))
1310 { 1310 {
1311 for (i = 1; i < len; i++) 1311 for (i = 1; i < len; i++)
@@ -1358,7 +1358,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
1358 if (str[i] == ':') 1358 if (str[i] == ':')
1359 { 1359 {
1360 size_t j; 1360 size_t j;
1361 1361
1362 defstr = str + i + 1; 1362 defstr = str + i + 1;
1363 if (find_closing_paren (str, i + 1, len, &j, "{}")) 1363 if (find_closing_paren (str, i + 1, len, &j, "{}"))
1364 return _wsplt_seterr (wsp, WRDSE_CBRACE); 1364 return _wsplt_seterr (wsp, WRDSE_CBRACE);
@@ -1374,7 +1374,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
1374 else if (strchr ("-+?=", str[i])) 1374 else if (strchr ("-+?=", str[i]))
1375 { 1375 {
1376 size_t j; 1376 size_t j;
1377 1377
1378 defstr = str + i; 1378 defstr = str + i;
1379 if (find_closing_paren (str, i, len, &j, "{}")) 1379 if (find_closing_paren (str, i, len, &j, "{}"))
1380 return _wsplt_seterr (wsp, WRDSE_CBRACE); 1380 return _wsplt_seterr (wsp, WRDSE_CBRACE);
@@ -1400,10 +1400,10 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
1400 return expvar_recover (wsp, str - 1, ptail, pend, flg); 1400 return expvar_recover (wsp, str - 1, ptail, pend, flg);
1401 } 1401 }
1402 } 1402 }
1403 1403
1404 if (is_param && str[0] == '-') 1404 if (is_param && str[0] == '-')
1405 param_idx = wsp->ws_paramc - param_idx; 1405 param_idx = wsp->ws_paramc - param_idx;
1406 1406
1407 if (i == len) 1407 if (i == len)
1408 return _wsplt_seterr (wsp, WRDSE_CBRACE); 1408 return _wsplt_seterr (wsp, WRDSE_CBRACE);
1409 } 1409 }
@@ -1456,7 +1456,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
1456 else 1456 else
1457 rc = WRDSE_UNDEF; 1457 rc = WRDSE_UNDEF;
1458 } 1458 }
1459 1459
1460 if (rc == WRDSE_OK 1460 if (rc == WRDSE_OK
1461 && (!value || value[0] == 0) 1461 && (!value || value[0] == 0)
1462 && defstr && defstr[-1] == ':') 1462 && defstr && defstr[-1] == ':')
@@ -1465,7 +1465,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
1465 rc = WRDSE_UNDEF; 1465 rc = WRDSE_UNDEF;
1466 } 1466 }
1467 } 1467 }
1468 1468
1469 switch (rc) 1469 switch (rc)
1470 { 1470 {
1471 case WRDSE_OK: 1471 case WRDSE_OK:
@@ -1485,7 +1485,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
1485 wordsplit_free (&ws); 1485 wordsplit_free (&ws);
1486 } 1486 }
1487 break; 1487 break;
1488 1488
1489 case WRDSE_UNDEF: 1489 case WRDSE_UNDEF:
1490 if (defstr) 1490 if (defstr)
1491 { 1491 {
@@ -1505,7 +1505,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
1505 value = ws.ws_wordv[0]; 1505 value = ws.ws_wordv[0];
1506 ws.ws_wordv[0] = NULL; 1506 ws.ws_wordv[0] = NULL;
1507 wordsplit_free (&ws); 1507 wordsplit_free (&ws);
1508 1508
1509 if (defstr[-1] == '=') 1509 if (defstr[-1] == '=')
1510 { 1510 {
1511 if (is_param) 1511 if (is_param)
@@ -1519,7 +1519,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
1519 return rc; 1519 return rc;
1520 } 1520 }
1521 } 1521 }
1522 else 1522 else
1523 { 1523 {
1524 if (*defstr == '?') 1524 if (*defstr == '?')
1525 { 1525 {
@@ -1567,7 +1567,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
1567 } 1567 }
1568 } 1568 }
1569 break; 1569 break;
1570 1570
1571 case WRDSE_NOSPACE: 1571 case WRDSE_NOSPACE:
1572 return _wsplt_nomem (wsp); 1572 return _wsplt_nomem (wsp);
1573 1573
@@ -1606,7 +1606,7 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
1606 { 1606 {
1607 struct wordsplit ws; 1607 struct wordsplit ws;
1608 int rc; 1608 int rc;
1609 1609
1610 rc = _wsplt_subsplit (wsp, &ws, value, strlen (value), 1610 rc = _wsplt_subsplit (wsp, &ws, value, strlen (value),
1611 WRDSF_NOVAR | WRDSF_NOCMD | 1611 WRDSF_NOVAR | WRDSF_NOCMD |
1612 WRDSF_QUOTE 1612 WRDSF_QUOTE
@@ -1711,7 +1711,7 @@ node_expand (struct wordsplit *wsp, struct wordsplit_node *node,
1711 } 1711 }
1712 return 0; 1712 return 0;
1713} 1713}
1714 1714
1715/* Remove NULL nodes from the list */ 1715/* Remove NULL nodes from the list */
1716static void 1716static void
1717wsnode_nullelim (struct wordsplit *wsp) 1717wsnode_nullelim (struct wordsplit *wsp)
@@ -1765,7 +1765,7 @@ expcmd (struct wordsplit *wsp, const char *str, size_t len,
1765 char *value; 1765 char *value;
1766 struct wordsplit_node *newnode; 1766 struct wordsplit_node *newnode;
1767 struct wordsplit ws; 1767 struct wordsplit ws;
1768 1768
1769 str++; 1769 str++;
1770 len--; 1770 len--;
1771 1771
@@ -1785,7 +1785,7 @@ expcmd (struct wordsplit *wsp, const char *str, size_t len,
1785 } 1785 }
1786 rc = wsp->ws_command (&value, str, j, ws.ws_wordv, wsp->ws_closure); 1786 rc = wsp->ws_command (&value, str, j, ws.ws_wordv, wsp->ws_closure);
1787 wordsplit_free (&ws); 1787 wordsplit_free (&ws);
1788 1788
1789 if (rc == WRDSE_NOSPACE) 1789 if (rc == WRDSE_NOSPACE)
1790 return _wsplt_nomem (wsp); 1790 return _wsplt_nomem (wsp);
1791 else if (rc) 1791 else if (rc)
@@ -1893,13 +1893,13 @@ wordsplit_trimws (struct wordsplit *wsp)
1893 ; 1893 ;
1894 p->v.segm.beg = n; 1894 p->v.segm.beg = n;
1895 } 1895 }
1896 1896
1897 while (p->next && (p->flags & _WSNF_JOIN)) 1897 while (p->next && (p->flags & _WSNF_JOIN))
1898 p = p->next; 1898 p = p->next;
1899 1899
1900 if (p->flags & _WSNF_QUOTE) 1900 if (p->flags & _WSNF_QUOTE)
1901 continue; 1901 continue;
1902 1902
1903 /* Trim trailing whitespace */ 1903 /* Trim trailing whitespace */
1904 for (n = p->v.segm.end; 1904 for (n = p->v.segm.end;
1905 n > p->v.segm.beg && ISWS (wsp->ws_input[n - 1]); n--); 1905 n > p->v.segm.beg && ISWS (wsp->ws_input[n - 1]); n--);
@@ -1918,7 +1918,7 @@ wordsplit_tildexpand (struct wordsplit *wsp)
1918 struct wordsplit_node *p; 1918 struct wordsplit_node *p;
1919 char *uname = NULL; 1919 char *uname = NULL;
1920 size_t usize = 0; 1920 size_t usize = 0;
1921 1921
1922 for (p = wsp->ws_head; p; p = p->next) 1922 for (p = wsp->ws_head; p; p = p->next)
1923 { 1923 {
1924 const char *str; 1924 const char *str;
@@ -1933,7 +1933,7 @@ wordsplit_tildexpand (struct wordsplit *wsp)
1933 size_t slen = wsnode_len (p); 1933 size_t slen = wsnode_len (p);
1934 struct passwd *pw; 1934 struct passwd *pw;
1935 char *newstr; 1935 char *newstr;
1936 1936
1937 for (i = 1; i < slen && str[i] != '/'; i++) 1937 for (i = 1; i < slen && str[i] != '/'; i++)
1938 ; 1938 ;
1939 if (i == slen) 1939 if (i == slen)
@@ -2009,7 +2009,7 @@ wordsplit_pathexpand (struct wordsplit *wsp)
2009 if (wsp->ws_options & WRDSO_DOTGLOB) 2009 if (wsp->ws_options & WRDSO_DOTGLOB)
2010 flags = GLOB_PERIOD; 2010 flags = GLOB_PERIOD;
2011#endif 2011#endif
2012 2012
2013 for (p = wsp->ws_head; p; p = next) 2013 for (p = wsp->ws_head; p; p = next)
2014 { 2014 {
2015 const char *str; 2015 const char *str;
@@ -2027,7 +2027,7 @@ wordsplit_pathexpand (struct wordsplit *wsp)
2027 int i; 2027 int i;
2028 glob_t g; 2028 glob_t g;
2029 struct wordsplit_node *prev; 2029 struct wordsplit_node *prev;
2030 2030
2031 if (slen + 1 > patsize) 2031 if (slen + 1 > patsize)
2032 { 2032 {
2033 char *p = realloc (pattern, slen + 1); 2033 char *p = realloc (pattern, slen + 1);
@@ -2038,16 +2038,16 @@ wordsplit_pathexpand (struct wordsplit *wsp)
2038 } 2038 }
2039 memcpy (pattern, str, slen); 2039 memcpy (pattern, str, slen);
2040 pattern[slen] = 0; 2040 pattern[slen] = 0;
2041 2041
2042 switch (glob (pattern, flags, NULL, &g)) 2042 switch (glob (pattern, flags, NULL, &g))
2043 { 2043 {
2044 case 0: 2044 case 0:
2045 break; 2045 break;
2046 2046
2047 case GLOB_NOSPACE: 2047 case GLOB_NOSPACE:
2048 free (pattern); 2048 free (pattern);
2049 return _wsplt_nomem (wsp); 2049 return _wsplt_nomem (wsp);
2050 2050
2051 case GLOB_NOMATCH: 2051 case GLOB_NOMATCH:
2052 if (wsp->ws_options & WRDSO_NULLGLOB) 2052 if (wsp->ws_options & WRDSO_NULLGLOB)
2053 { 2053 {
@@ -2069,7 +2069,7 @@ wordsplit_pathexpand (struct wordsplit *wsp)
2069 return _wsplt_seterr (wsp, WRDSE_USERERR); 2069 return _wsplt_seterr (wsp, WRDSE_USERERR);
2070 } 2070 }
2071 continue; 2071 continue;
2072 2072
2073 default: 2073 default:
2074 free (pattern); 2074 free (pattern);
2075 return _wsplt_seterr (wsp, WRDSE_GLOBERR); 2075 return _wsplt_seterr (wsp, WRDSE_GLOBERR);
@@ -2080,7 +2080,7 @@ wordsplit_pathexpand (struct wordsplit *wsp)
2080 { 2080 {
2081 struct wordsplit_node *newnode; 2081 struct wordsplit_node *newnode;
2082 char *newstr; 2082 char *newstr;
2083 2083
2084 if (wsnode_new (wsp, &newnode)) 2084 if (wsnode_new (wsp, &newnode))
2085 return 1; 2085 return 1;
2086 newstr = strdup (g.gl_pathv[i]); 2086 newstr = strdup (g.gl_pathv[i]);
@@ -2196,7 +2196,7 @@ scan_word (struct wordsplit *wsp, size_t start, int consume_all)
2196 int join = 0; 2196 int join = 0;
2197 int flags = 0; 2197 int flags = 0;
2198 struct wordsplit_node *np = wsp->ws_tail; 2198 struct wordsplit_node *np = wsp->ws_tail;
2199 2199
2200 size_t i = start; 2200 size_t i = start;
2201 2201
2202 if (i >= len) 2202 if (i >= len)
@@ -2287,7 +2287,7 @@ scan_word (struct wordsplit *wsp, size_t start, int consume_all)
2287 wsp->ws_endp = i; 2287 wsp->ws_endp = i;
2288 if (wsp->ws_flags & WRDSF_INCREMENTAL) 2288 if (wsp->ws_flags & WRDSF_INCREMENTAL)
2289 return _WRDS_EOF; 2289 return _WRDS_EOF;
2290 2290
2291 if (consume_all) 2291 if (consume_all)
2292 { 2292 {
2293 if (!np) 2293 if (!np)
@@ -2298,7 +2298,7 @@ scan_word (struct wordsplit *wsp, size_t start, int consume_all)
2298 np = np->next; 2298 np = np->next;
2299 } 2299 }
2300 } 2300 }
2301 2301
2302 return _WRDS_OK; 2302 return _WRDS_OK;
2303} 2303}
2304 2304
@@ -2562,7 +2562,7 @@ wordsplit_process_list (struct wordsplit *wsp, size_t start)
2562 if (wsp->ws_flags & WRDSF_SHOWDBG) 2562 if (wsp->ws_flags & WRDSF_SHOWDBG)
2563 wsp->ws_debug (_("(%02d) Input:%.*s;"), 2563 wsp->ws_debug (_("(%02d) Input:%.*s;"),
2564 wsp->ws_lvl, (int) wsp->ws_len, wsp->ws_input); 2564 wsp->ws_lvl, (int) wsp->ws_len, wsp->ws_input);
2565 2565
2566 if ((wsp->ws_flags & WRDSF_NOSPLIT) 2566 if ((wsp->ws_flags & WRDSF_NOSPLIT)
2567 || ((wsp->ws_options & WRDSO_MAXWORDS) 2567 || ((wsp->ws_options & WRDSO_MAXWORDS)
2568 && wsp->ws_wordi + 1 == wsp->ws_maxwords)) 2568 && wsp->ws_wordi + 1 == wsp->ws_maxwords))
@@ -2623,7 +2623,7 @@ wordsplit_process_list (struct wordsplit *wsp, size_t start)
2623 2623
2624static int 2624static int
2625wordsplit_run (const char *command, size_t length, struct wordsplit *wsp, 2625wordsplit_run (const char *command, size_t length, struct wordsplit *wsp,
2626 int flags, int lvl) 2626 int flags, int lvl)
2627{ 2627{
2628 int rc; 2628 int rc;
2629 size_t start; 2629 size_t start;
@@ -2659,8 +2659,8 @@ wordsplit_run (const char *command, size_t length, struct wordsplit *wsp,
2659} 2659}
2660 2660
2661int 2661int
2662wordsplit_len (const char *command, size_t length, struct wordsplit *wsp, 2662wordsplit_len (const char *command, size_t length, struct wordsplit *wsp,
2663 int flags) 2663 int flags)
2664{ 2664{
2665 return wordsplit_run (command, length, wsp, flags, 0); 2665 return wordsplit_run (command, length, wsp, flags, 0);
2666} 2666}
@@ -2800,4 +2800,3 @@ wordsplit_perror (struct wordsplit *wsp)
2800 wsp->ws_error ("%s", wordsplit_strerror (wsp)); 2800 wsp->ws_error ("%s", wordsplit_strerror (wsp));
2801 } 2801 }
2802} 2802}
2803

Return to:

Send suggestions and report system problems to the System administrator.