--- var_test.c 2001/12/08 15:14:33 1.17
+++ var_test.c 2001/12/08 15:31:06 1.18
@@ -15,19 +15,44 @@
size_t *buffer_size)
{
const struct variable* vars = context;
- size_t i;
+ size_t i, counter, length;
+ static char buf[((sizeof(int)*8)/3)+10]; /* sufficient size: <#bits> x log_10(2) + safety */
- 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 && vars[i].index == index) {
- *data = vars[i].data;
- *data_len = strlen(*data);
- *buffer_size = 0;
- return 1;
+ if (index >= 0)
+ {
+ for (i = 0; vars[i].name; ++i)
+ {
+ if (strncmp(varname, vars[i].name, name_len) == 0 && vars[i].index == index)
+ {
+ *data = vars[i].data;
+ *data_len = strlen(*data);
+ *buffer_size = 0;
+ return 1;
+ }
+ }
+ }
+ else
+ {
+ for (i = 0; vars[i].name; ++i)
+ {
+ if (strncmp(varname, vars[i].name, name_len) == 0)
+ {
+ printf("Found variable at index %d.\n", i);
+ counter = 1;
+ length = strlen(vars[i].data);
+ while (vars[i + counter].data && strncmp(varname, vars[i + counter].name, name_len) == 0)
+ ++counter;
+ if (counter == 1)
+ sprintf(buf, "%d", length);
+ else
+ sprintf(buf, "%d", counter);
+ *data = buf;
+ *data_len = strlen(buf);
+ *buffer_size = 0;
+ return 1;
+ }
+ }
}
- }
return 0;
}
@@ -108,7 +133,9 @@
{ "${ARRAY[5+4*2-1]}", "${ARRAY[5+4*2-1]}", },
{ "${ARRAY[(5+(3+4)*2)%16]}", "entry3", },
{ "${ARRAY[(5+(3+4)*2)/9]}", "entry2", },
- { "${ARRAY[+1--2]}", "entry3" }
+ { "${ARRAY[+1--2]}", "entry3" },
+ { "${ARRAY[-1]}", "4" },
+ { "${HOME[-1]}", "22" }
};
char *tmp;
size_t tmp_len;
|