This feature will enable the possibility to have many cores
configured in a prox config file, and enable/disable them
through variables.
For instance, a [core $var1] section in a config file will
result in [core 1] if $var1 = 1; the whole section and section
content will be ignored if $var1=#
Before this implementation, [#core 1] or [core #] was already
treated as a commented out section (the whole section was
commented). But there was no way to define a variable $var = #
to comment a section through a variable.
Note that in today's implementation any non numerical
(except s, h, t, -) characteter in the [core] section header
(and not only #) will cause the section to be ignored.
It would probably be better to consider # (as maybe N/A and none)
as comments, and everything else as error. This is however not
supported by the change request.
Change-Id: Id4e2b27a1f9b6d595e0b442dcd971ad44a502031
Signed-off-by: Xavier Simonart <xavier.simonart@intel.com>
if (*pend == '\0') {
return NULL;
}
- /* only numeric characters are valid for section index
- (currently, variables not checked!) */
- if (pend[0] != '$') {
- for (len = 0; pend[len] != '\0'; ++len) {
- if (strchr(valid, pend[len]) == NULL) {
- return NULL;
- }
+
+ /* only numeric characters are valid for section index */
+ char val[MAX_CFG_STRING_LEN];
+ if (pend[0] == '$')
+ parse_single_var(val, sizeof(val), pend);
+ else
+ strncpy(val, pend, sizeof(val));
+
+ for (len = 0; val[len] != '\0'; ++len) {
+ if (strchr(valid, val[len]) == NULL) {
+ return NULL;
}
}
return NULL;
}
-static int parse_single_var(char *val, size_t len, const char *name)
+int parse_single_var(char *val, size_t len, const char *name)
{
struct var *match;
{
static char result[MAX_CFG_STRING_LEN];
static char cur_var[MAX_CFG_STRING_LEN];
- char parsed[2048];
+ char parsed[MAX_CFG_STRING_LEN];
size_t name_len = strlen(name);
enum parse_vars_state {NO_VAR, WHOLE_VAR, INLINE_VAR} state = NO_VAR;
size_t result_len = 0;
/* Returns true if running from a virtual machine. */
int is_virtualized(void);
+int parse_single_var(char *val, size_t len, const char *name);
+
#endif /* _PARSE_UTILS_H_ */