jshn: support using characters in elements that do not conform to shell variable restrictions
This commit is contained in:
parent
dee81b4f79
commit
a1a97eb11e
2 changed files with 16 additions and 7 deletions
15
jshn.c
15
jshn.c
|
@ -150,14 +150,19 @@ static char *get_keys(const char *prefix)
|
|||
return getenv(keys);
|
||||
}
|
||||
|
||||
static void get_var(const char *prefix, const char *name, char **var, char **type)
|
||||
static void get_var(const char *prefix, const char **name, char **var, char **type)
|
||||
{
|
||||
char *tmpname;
|
||||
char *tmpname, *varname;
|
||||
|
||||
tmpname = alloca(strlen(prefix) + 1 + strlen(name) + 1 + sizeof("TYPE_"));
|
||||
sprintf(tmpname, "TYPE_%s_%s", prefix, name);
|
||||
tmpname = alloca(strlen(prefix) + 1 + strlen(*name) + 1 + sizeof("TYPE_"));
|
||||
sprintf(tmpname, "TYPE_%s_%s", prefix, *name);
|
||||
*var = getenv(tmpname + 5);
|
||||
*type = getenv(tmpname);
|
||||
|
||||
memcpy(tmpname, "NAME", 4);
|
||||
varname = getenv(tmpname);
|
||||
if (varname)
|
||||
*name = varname;
|
||||
}
|
||||
|
||||
static json_object *jshn_add_objects(json_object *obj, const char *prefix, bool array);
|
||||
|
@ -167,7 +172,7 @@ static void jshn_add_object_var(json_object *obj, bool array, const char *prefix
|
|||
json_object *new;
|
||||
char *var, *type;
|
||||
|
||||
get_var(prefix, name, &var, &type);
|
||||
get_var(prefix, &name, &var, &type);
|
||||
if (!var || !type)
|
||||
return;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue