OSSP CVS Repository

ossp - Check-in [1396]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 1396
Date: 2001-Dec-03 11:51:27 (local)
2001-Dec-03 10:51:27 (UTC)
User:simons
Branch:
Comment: Extended the interface of var_cb_t to support variable arrays. To customize your already existing lookup functions quickly to the new interface, just add the "int index" parameter to the function's prototype and add the lines

    if (index != 0)
        return VAR_ERR_ARRAY_LOOKUPS_ARE_UNSUPPORTED;

to the function itself.

Tickets:
Inspections:
Files:
ossp-pkg/var/var.c      1.36 -> 1.37     6 inserted, 2 deleted
ossp-pkg/var/var.h      1.13 -> 1.14     5 inserted, 1 deleted
ossp-pkg/var/var.pod      1.8 -> 1.9     21 inserted, 2 deleted
ossp-pkg/var/var_test.c      1.14 -> 1.15     4 inserted, 1 deleted

ossp-pkg/var/var.c 1.36 -> 1.37

--- var.c        2001/11/20 15:46:35     1.36
+++ var.c        2001/12/03 10:51:27     1.37
@@ -45,6 +45,9 @@
     '$',                        /* varinit */
     '{',                        /* startdelim */
     '}',                        /* enddelim */
+    '[',                        /* startindex */
+    ']',                        /* endindex */
+    '#',                        /* current_index */
     '\\',                       /* escape */
     "a-zA-Z0-9_"                /* namechars */
 };
@@ -90,6 +93,7 @@
         "submatch referred to in replace string does not exist in search string", /* VAR_ERR_SUBMATCH_OUT_OF_RANGE = -34 */
         "invalid argument",                                                     /* VAR_ERR_INVALID_ARGUMENT = -35 */
         "incomplete quoted pair"                                                /* VAR_ERR_INCOMPLETE_QUOTED_PAIR = -36 */
+        "lookup function does not support variable arrays"                      /* VAR_ERR_ARRAY_LOOKUPS_ARE_UNSUPPORTED = -37 */
     };
 
     rc = 0 - rc;
@@ -561,7 +565,7 @@
 
     /* Use the lookup callback to get the variable's contents. */
 
-    rc = (*lookup) (lookup_context, name.begin, name.end - name.begin,
+    rc = (*lookup) (lookup_context, name.begin, name.end - name.begin, 0,
                     &data, &len, &buffer_size);
     if (rc < 0)
         goto error_return;
@@ -663,7 +667,7 @@
     if (rc < 0)
         return rc;
     if (rc > 0) {
-        rc2 = (*lookup) (lookup_context, p, rc, &data, &len, &buffer_size);
+        rc2 = (*lookup) (lookup_context, p, rc, 0, &data, &len, &buffer_size);
         if (rc2 < 0)
             return rc2;
         if (rc2 == 0) {


ossp-pkg/var/var.h 1.13 -> 1.14

--- var.h        2001/11/19 16:09:44     1.13
+++ var.h        2001/12/03 10:51:27     1.14
@@ -36,6 +36,7 @@
 
 typedef enum {
     VAR_ERR_CALLBACK = -64,
+    VAR_ERR_ARRAY_LOOKUPS_ARE_UNSUPPORTED  = -37,
     VAR_ERR_INCOMPLETE_QUOTED_PAIR = -36,
     VAR_ERR_INVALID_ARGUMENT = -35,
     VAR_ERR_SUBMATCH_OUT_OF_RANGE = -34,
@@ -82,7 +83,7 @@
 /* Prototype for the lookup callback used in var_expand(). */
 
 typedef int (*var_cb_t) (void *context,
-    const char *varname, size_t name_len,
+    const char *varname, size_t name_len, int index,
     const char **data, size_t *data_len,
     size_t *buffer_size);
 
@@ -92,6 +93,9 @@
     char varinit;        /* '$' */
     char startdelim;     /* '{' */
     char enddelim;       /* '}' */
+    char startindex;     /* '[' */
+    char endindex;       /* ']' */
+    char current_index;  /* '#' */
     char escape;         /* '\' */
     char *namechars;     /* 'a-zA-Z0-9_' */
 } var_config_t;


ossp-pkg/var/var.pod 1.8 -> 1.9

--- var.pod      2001/11/20 15:46:35     1.8
+++ var.pod      2001/12/03 10:51:27     1.9
@@ -201,6 +201,9 @@
         char varinit;
         char startdelim;
         char enddelim;
+        char startindex;
+        char endindex;
+        char current_index;
         char escape;
         char *namechars;
     } var_config_t;
@@ -218,6 +221,9 @@
         '$',              /* varinit */
         '{',              /* startdelim */
         '}',              /* enddelim */
+        '[',              /* startindex */
+        ']',              /* endindex */
+        '#',              /* current_index */
         '\\',             /* escape */
         "a-zA-Z0-9_"      /* namechars */
     };
@@ -304,7 +310,7 @@
 function, which adheres to the var_cb_t function interface:
 
     int lookup(void *context,
-               const char *varname, size_t name_len,
+               const char *varname, size_t name_len, int index,
                const char **data, size_t *data_len,
                size_t *buffer_size);
 
@@ -336,6 +342,14 @@
 The "name_len" parameter contains the length of the variable name
 "varname" points to.
 
+=item int index
+
+The contents of this interger determines which entry of a variable
+array to look-up. If the variable specification that led to the
+execution of the lookup function did not contain an index, zero is
+provided per default. If "index" is negative, the callback must return
+the number of entries of the variable array.
+
 =item const char **data
 
 This is a pointer to the location where the callback function should
@@ -409,12 +423,15 @@
 getenv(3) to lookup variables and to return them to var_expand():
 
     int env_lookup(void *context,
-        const char *varname, size_t name_len,
+        const char *varname, size_t name_len, int index,
         const char **data, size_t *data_len,
         size_t *buffer_size)
     {
         char tmp[256];
 
+        if (index != 0)
+            return VAR_ERR_ARRAY_LOOKUPS_ARE_UNSUPPORTED;
+
         if (name_len > sizeof(tmp) - 1) {
         /* Callback can't expand variable names longer than
            sizeof(tmp) characters. */
@@ -841,6 +858,8 @@
 var_unescape() encountered the backslash ('\') as the last character
 of the input buffer.
 
+=item VAR_ERR_ARRAY_LOOKUPS_ARE_UNSUPPORTED
+
 =back
 
 =head1 SO ALSO


ossp-pkg/var/var_test.c 1.14 -> 1.15

--- var_test.c   2001/11/20 15:46:35     1.14
+++ var_test.c   2001/12/03 10:51:27     1.15
@@ -9,13 +9,16 @@
 };
 
 static int var_lookup(void *context,
-    const char *varname, size_t name_len,
+    const char *varname, size_t name_len, int index,
     const char **data, size_t *data_len,
     size_t *buffer_size)
 {
     const struct variable*  vars = context;
     size_t i;
 
+    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) {
             *data = vars[i].data;

CVSTrac 2.0.1