OSSP CVS Repository

ossp - Difference in ossp-pkg/var/var_test.c versions 1.38 and 1.39
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/var/var_test.c 1.38 -> 1.39

--- var_test.c   2002/02/28 20:27:05     1.38
+++ var_test.c   2002/03/04 11:53:27     1.39
@@ -30,9 +30,55 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <ctype.h>
 
 #include "var.h"
 
+static var_rc_t 
+var_operation(
+    var_t *var, void *ctx,
+    const char  *op_ptr, size_t op_len,
+    const char  *arg_ptr, size_t arg_len,
+    const char  *val_ptr, size_t val_len,
+    char **out_ptr, size_t *out_len, size_t *out_size)
+{
+    int i;
+
+    fprintf(stderr, "op=<%s>(%d) arg=<%s>(%d) val=<%s>(%d)\n", 
+            op_ptr, op_len, arg_ptr, arg_len, val_ptr, val_len);
+    if (val_ptr == NULL) {
+        *out_ptr = "";
+        *out_len = 0;
+        *out_size = 0;
+        return VAR_OK;
+    }
+    if (op_len == 6 && strncmp(op_ptr, "return", 6) == 0) {
+        *out_ptr = malloc(arg_len);
+        *out_len = arg_len;
+        *out_size = arg_len;
+        memcpy(*out_ptr, arg_ptr, arg_len);
+        return VAR_OK;
+    }
+    else if (op_len == 5 && strncmp(op_ptr, "upper", 5) == 0) {
+        *out_ptr = malloc(val_len);
+        *out_len = val_len;
+        *out_size = val_len;
+        for (i = 0; i < val_len; i++)
+            (*out_ptr)[i] = (char)toupper((int)(val_ptr[i]));
+        return VAR_OK;
+    }
+    else if (op_len == 5 && strncmp(op_ptr, "lower", 5) == 0) {
+        *out_ptr = malloc(val_len);
+        *out_len = val_len;
+        *out_size = val_len;
+        for (i = 0; i < val_len; i++)
+            (*out_ptr)[i] = (char)tolower((int)(val_ptr[i]));
+        return VAR_OK;
+    }
+    else 
+        return VAR_ERR_UNDEFINED_OPERATION;
+}
+
 struct variable {
     const char *name;
     const unsigned int idx;
@@ -177,6 +223,9 @@
         { "-[${ARRAY[#]}:]{1,$NUMBER}-",  "-entry1:entry2:-"                               },
         { "-[${ARRAY[#]}:]{1,3,5}-",      "-entry1::-"                                     },
         { "${MULTILINE:s/^/ | /g}",       " | line1\n | line2\n"                           },
+        { "${HOME:%upper}",               "/HOME/REGRESSION-TESTS"                         },
+        { "${HOME:%upper:%lower}",        "/home/regression-tests"                         },
+        { "${EMPTY:%return($HOME)}",      "/home/regression-tests"                         },
         {
         "[${ARRAY}:${ARRAY[#]}-]",
         "entry0:entry0-entry0:entry1-entry0:entry2-entry0:entry3-"
@@ -215,6 +264,11 @@
         var_strerror(NULL, rc, &err);
         printf("unable to configure variable expansion context: %s (%d)\n", err, rc);
         return 1;
+    }
+    if ((rc = var_config(var, VAR_CONFIG_CB_OPERATION, var_operation, NULL)) != VAR_OK) {
+        var_strerror(NULL, rc, &err);
+        printf("unable to configure variable expansion context: %s (%d)\n", err, rc);
+        return 1;
     }
 
     for (i = 0; i < sizeof(tests)/sizeof(struct test_case); ++i) {

CVSTrac 2.0.1