OSSP CVS Repository

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

Check-in Number: 1409
Date: 2001-Dec-08 17:02:15 (local)
2001-Dec-08 16:02:15 (UTC)
User:simons
Branch:
Comment: Added support for variables as operands in index specifications.
Tickets:
Inspections:
Files:
ossp-pkg/var/var.c      1.39 -> 1.40     29 inserted, 8 deleted
ossp-pkg/var/var.pod      1.10 -> 1.11     1 inserted, 0 deleted
ossp-pkg/var/var_test.c      1.18 -> 1.19     7 inserted, 1 deleted

ossp-pkg/var/var.c 1.39 -> 1.40

--- var.c        2001/12/04 14:25:06     1.39
+++ var.c        2001/12/08 16:02:15     1.40
@@ -432,7 +432,9 @@
 static int command(const char *, const char *, const var_config_t *,
                    const char_class_t, var_cb_t, void *, int, tokenbuf_t *);
 static int num_exp(const char *begin, const char *end, int current_index,
-                   int* result, const var_config_t *config);
+                   int* result, const var_config_t *config,
+                   const char_class_t nameclass,
+                   var_cb_t lookup, void* lookup_context);
 
 static int text(const char *begin, const char *end, char varinit,
                 char escape)
@@ -508,11 +510,16 @@
     }
 
 static int num_exp_read_operand(const char *begin, const char *end, int current_index,
-                                int* result, const var_config_t *config)
+                                int* result, const var_config_t *config,
+                                const char_class_t nameclass,
+                                var_cb_t lookup, void* lookup_context)
     {
     const char* p = begin;
+    tokenbuf_t tmp;
     int rc;
 
+    tokenbuf_init(&tmp);
+
     if (begin == end)
         return VAR_ERR_INCOMPLETE_INDEX_SPEC;
 
@@ -520,7 +527,7 @@
 
     if (*p == '(')
         {
-        rc = num_exp(++p, end, current_index, result, config);
+        rc = num_exp(++p, end, current_index, result, config, nameclass, lookup, lookup_context);
         if (rc < 0)
             return rc;
         p += rc;
@@ -530,6 +537,18 @@
             return VAR_ERR_UNCLOSED_BRACKET_IN_INDEX;
         ++p;
         }
+    else if (*p == config->varinit)
+        {
+        rc = variable(p, end, config, nameclass, lookup, lookup_context, 1, &tmp);
+        if (rc < 0)
+            return rc;
+        p += rc;
+
+        rc = num_exp(tmp.begin, tmp.end, current_index, result, config, nameclass, lookup, lookup_context);
+        tokenbuf_free(&tmp);
+        if (rc < 0)
+            return rc;
+        }
     else if (config->current_index && *p == config->current_index)
         {
         ++p;
@@ -567,7 +586,9 @@
     }
 
 static int num_exp(const char *begin, const char *end, int current_index,
-                   int* result, const var_config_t *config)
+                   int* result, const var_config_t *config,
+                   const char_class_t nameclass,
+                   var_cb_t lookup, void* lookup_context)
     {
     const char* p = begin;
     char operator;
@@ -577,7 +598,7 @@
     if (begin == end)
         return VAR_ERR_INCOMPLETE_INDEX_SPEC;
 
-    rc = num_exp_read_operand(p, end, current_index, result, config);
+    rc = num_exp_read_operand(p, end, current_index, result, config, nameclass, lookup, lookup_context);
     if (rc < 0)
         return rc;
     p += rc;
@@ -590,7 +611,7 @@
             {
             operator = *p++;
             printf("Operator is '%c'\n", operator);
-            rc = num_exp(p, end, current_index, &right, config);
+            rc = num_exp(p, end, current_index, &right, config, nameclass, lookup, lookup_context);
             if (rc < 0)
                 return rc;
             p += rc;
@@ -607,7 +628,7 @@
             printf("Operator is '%c'\n", operator);
 
 
-            rc = num_exp_read_operand(p, end, current_index, &right, config);
+            rc = num_exp_read_operand(p, end, current_index, &right, config, nameclass, lookup, lookup_context);
             if (rc < 0)
                 return rc;
             p += rc;
@@ -708,7 +729,7 @@
         printf("Found START-INDEX: %s\n", p);
         ++p;
 
-        rc = num_exp(p, end, 0, &index, config);
+        rc = num_exp(p, end, 0, &index, config, nameclass, lookup, lookup_context);
         if (rc < 0)
             goto error_return;
         if (rc == 0)


ossp-pkg/var/var.pod 1.10 -> 1.11

--- var.pod      2001/12/04 13:37:55     1.10
+++ var.pod      2001/12/08 16:02:15     1.11
@@ -639,6 +639,7 @@
  operand    : ('+'|'-')? NUMBER
             | CURR-INDEX
             | '(' num-exp ')'
+            | variable
 
  START-DELIM: '{'
 


ossp-pkg/var/var_test.c 1.18 -> 1.19

--- var_test.c   2001/12/08 15:31:06     1.18
+++ var_test.c   2001/12/08 16:02:15     1.19
@@ -74,6 +74,8 @@
         { "ARRAY",  1, "entry1" },
         { "ARRAY",  2, "entry2" },
         { "ARRAY",  3, "entry3" },
+        { "NUMBER", 0, "+2" },
+        { "NUMEXP", 0, "((16)%5)" },
         { NULL,     0, NULL }
         };
 
@@ -135,7 +137,11 @@
         { "${ARRAY[(5+(3+4)*2)/9]}",      "entry2",                                        },
         { "${ARRAY[+1--2]}",              "entry3"                                         },
         { "${ARRAY[-1]}",                 "4"                                              },
-        { "${HOME[-1]}",                  "22"                                             }
+        { "${HOME[-1]}",                  "22"                                             },
+        { "${ARRAY[$NUMBER]}",            "entry2"                                         },
+        { "${ARRAY[$NUMEXP]}",            "entry1"                                         },
+        { "${ARRAY[$NUMEXP-1]}",          "entry0"                                         },
+        { "${ARRAY[${ARRAY[-1]}-1]}",     "entry3"                                         }
     };
     char *tmp;
     size_t tmp_len;

CVSTrac 2.0.1