$(o)/lib/shell/config: $(o)/lib/shell/config.o $(LIBSH)
$(o)/lib/shell/logger: $(o)/lib/shell/logger.o $(LIBSH)
+
+TESTS+=$(addprefix $(o)/lib/shell/,config.test)
uns flags;
struct cf_item cf;
union value value;
+ uns index;
};
struct section {
byte *def = pos, *d = def;
while (*pos != ';' && *pos != '}' && !Cspace(*pos))
{
- if (*pos == '\'')
+ if (*pos == '\'' )
{
pos++;
while (*pos != '\'')
else if (*pos == '"')
{
pos++;
+ byte *start = d;
uns esc = 0;
while (*pos != '"' || esc)
{
die("Unterminated string");
if (*pos == '\\')
esc ^= 1;
+ else
+ esc = 0;
*d++ = *pos++;
}
pos++;
+ *d = 0;
+ d = str_unesc(start, start);
}
else
*d++ = *pos++;
byte *buf = mp_alloc(pool, len + 1);
memcpy(buf, def, len);
buf[len] = 0;
- str_unesc(buf, buf);
switch (item->cf.type)
#define TRY(x) do{byte *_err=(x); if (_err) die(_err); }while(0)
{
break;
default:
ASSERT(0);
-#undef TRY
+#undef TRY
}
}
}
if (!ptr)
printf("CF_%s_%s='", path.ptr, name);
else
- printf("CF_%s_%s[${#CF_%s_%s[*]}]='", path.ptr, name, path.ptr, name);
+ printf("CF_%s_%s[%u]='", path.ptr, name, item->index++);
switch (item->cf.type)
{
case CT_INT:
--- /dev/null
+# Tests for configuration parser
+
+Run: obj/lib/shell/config -C/dev/null -S 'sec1{int1=23; long1=1234567812345678; long2=4321; str1="s1"; str2="s2"}' 'sec1 {#int1; ##long1; -str1; str2; #int2=123; ##long2=1234}; sec2{str3}'
+Out: CF_sec1_int1='23'
+ CF_sec1_long1='1234567812345678'
+ CF_sec1_str2='s2'
+ CF_sec1_int2='123'
+ CF_sec1_long2='4321'
+ CF_sec2_str3=''
+
+Run: obj/lib/shell/config -C/dev/null -S 'sec1{list1 1 a1 b1; list1:clear; list1 2 a2 b2 3 a3 b3}' 'sec1 {@list1 {#int1; str1; -str2}}'
+Out: CF_sec1_list1_int1[0]='2'
+ CF_sec1_list1_str1[0]='a2'
+ CF_sec1_list1_int1[1]='3'
+ CF_sec1_list1_str1[1]='a3'
+
+Run: obj/lib/shell/config -C/dev/null -S 'sec1{list1 {str1=1; list2=a b c}; list1 {str1=2; list2=d e}}' 'sec1 {@list1 {str1; @list2{str2}}}'
+Out: CF_sec1_list1_str1[0]='1'
+ CF_sec1_list1_list2_str2[0]='a'
+ CF_sec1_list1_list2_str2[1]='b'
+ CF_sec1_list1_list2_str2[2]='c'
+ CF_sec1_list1_str1[1]='2'
+ CF_sec1_list1_list2_str2[3]='d'
+ CF_sec1_list1_list2_str2[4]='e'
+
+Run: obj/lib/shell/config -C/dev/null 'sec{str=a'\''b"c'\''d"\\e'\''f"g}'
+Out: CF_sec_str='ab"cd\e'\''fg'