--- var_test.c 2001/12/04 13:35:58 1.16
+++ var_test.c 2001/12/08 15:14:33 1.17
@@ -5,6 +5,7 @@
struct variable {
const char *name;
+ const unsigned int index;
const char *data;
};
@@ -16,11 +17,11 @@
const struct variable* vars = context;
size_t i;
- if (0 && index != 0)
+ if (index < 0)
return VAR_ERR_ARRAY_LOOKUPS_ARE_UNSUPPORTED;
for (i = 0; vars[i].name; ++i) {
- if (strncmp(varname, vars[i].name, name_len) == 0) {
+ if (strncmp(varname, vars[i].name, name_len) == 0 && vars[i].index == index) {
*data = vars[i].data;
*data_len = strlen(*data);
*buffer_size = 0;
@@ -38,13 +39,17 @@
int main(int argc, char **argv)
{
const struct variable vars[] = {
- { "HOME", "/home/regression-tests" },
- { "OSTYPE", "regression-os" },
- { "TERM", "regression-term" },
- { "FOO", "os" },
- { "BAR", "type" },
- { "EMPTY", "" },
- { NULL, NULL }
+ { "HOME", 0, "/home/regression-tests" },
+ { "OSTYPE", 0, "regression-os" },
+ { "TERM", 0, "regression-term" },
+ { "FOO", 0, "os" },
+ { "BAR", 0, "type" },
+ { "EMPTY", 0, "" },
+ { "ARRAY", 0, "entry0" },
+ { "ARRAY", 1, "entry1" },
+ { "ARRAY", 2, "entry2" },
+ { "ARRAY", 3, "entry3" },
+ { NULL, 0, NULL }
};
const struct test_case tests[] = {
@@ -99,10 +104,11 @@
{ "${HOME:s/\\x65/\\x45/g}", "/homE/rEgrEssion-tEsts" },
{ "${HOME:s/(s*)/x\\1X/g}", "xXxXxXxXxXxXxXxXxXxXxXxssXxXxXxXxXxXxXxsXxXxsX" },
{ "${HOME:s/./\\\\/g}", "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" },
+ { "${ARRAY[1]}", "entry1", },
{ "${ARRAY[5+4*2-1]}", "${ARRAY[5+4*2-1]}", },
- { "${ARRAY[5+(3+4)*2]}", "${ARRAY[5+(3+4)*2]}" },
- { "${ARRAY[(5+(3+4)*2)]}", "${ARRAY[(5+(3+4)*2)]}" },
- { "${ARRAY[+4--3]}", "${ARRAY[+4--3]}" }
+ { "${ARRAY[(5+(3+4)*2)%16]}", "entry3", },
+ { "${ARRAY[(5+(3+4)*2)/9]}", "entry2", },
+ { "${ARRAY[+1--2]}", "entry3" }
};
char *tmp;
size_t tmp_len;
|