aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-04-20 08:54:21 +0300
committerSergey Poznyakoff <gray@gnu.org>2019-04-20 09:47:40 +0300
commit3e07e3ad30e8a7a091e213eb4df839b7cf7f1e64 (patch)
treea3c83a584f8e2b54e294ff1dfa04a2262459d5a4 /include
parent1498bd570eb001a6b2bc3f1a5074e8b384d6db30 (diff)
downloadgrecs-3e07e3ad30e8a7a091e213eb4df839b7cf7f1e64.tar.gz
grecs-3e07e3ad30e8a7a091e213eb4df839b7cf7f1e64.tar.bz2
Improve variable handling in wordsplit.
Positional variables ($N and ${N}) are recognized. Variable names in curly braces follow the same rules as unadorned ones. This commit also changes memory reallocation strategy in wsplt_assign_var. If ws_envbuf needs to be expanded, new allocation size is selected as 3/2 of the previous allocation, if that size is less than max(size_t).
Diffstat (limited to 'include')
-rw-r--r--include/wordsplit.h16
1 files changed, 11 insertions, 5 deletions
diff --git a/include/wordsplit.h b/include/wordsplit.h
index 1a047f7..3a7ab25 100644
--- a/include/wordsplit.h
+++ b/include/wordsplit.h
@@ -1,5 +1,5 @@
/* wordsplit - a word splitter
- Copyright (C) 2009-2018 Sergey Poznyakoff
+ Copyright (C) 2009-2019 Sergey Poznyakoff
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
@@ -66,9 +66,15 @@ struct wordsplit
const char **ws_env; /* [Input] (WRDSF_ENV, !WRDSF_NOVAR) Array of
environment variables. */
- char **ws_envbuf;
- size_t ws_envidx;
- size_t ws_envsiz;
+ /* Temporary storage for environment variables. It is initialized
+ upon first assignment which occurs during the parsing process
+ (e.g. ${x:=2}). When this happens, all variables from ws_env are
+ moved to ws_envbuf first, and the ws_envbuf address is assigned
+ to ws_env. From this moment on, all variable expansions are served
+ from ws_envbuf. */
+ char **ws_envbuf; /* Storage for variables */
+ size_t ws_envidx; /* Index of first free slot */
+ size_t ws_envsiz; /* Size of the ws_envbuf array */
int (*ws_getvar) (char **ret, const char *var, size_t len, void *clos);
/* [Input] (WRDSF_GETVAR, !WRDSF_NOVAR) Looks up
@@ -197,8 +203,8 @@ struct wordsplit
#define WRDSO_DOTGLOB 0x00000004
#if 0 /* Unused value */
#define WRDSO_ARGV 0x00000008
-/* Keep backslash in unrecognized escape sequences in words */
#endif
+/* Keep backslash in unrecognized escape sequences in words */
#define WRDSO_BSKEEP_WORD 0x00000010
/* Handle octal escapes in words */
#define WRDSO_OESC_WORD 0x00000020

Return to:

Send suggestions and report system problems to the System administrator.