OSSP CVS Repository

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

ossp-pkg/var/var.c 1.90 -> 1.91

--- var.c        2002/07/05 20:17:16     1.90
+++ var.c        2003/02/10 15:37:15     1.91
@@ -51,7 +51,7 @@
 
 /* unique library identifier */
 const char var_id[] = "OSSP var";
-        
+
 /* support for OSSP ex based exception throwing */
 #ifdef WITH_EX
 #include "ex.h"
@@ -113,13 +113,13 @@
 */
 
 /* minimal output-independent vprintf(3) variant which supports %{c,s,d,%} only */
-static int 
+static int
 var_mvxprintf(
-    int (*output)(void *ctx, const char *buffer, size_t bufsize), void *ctx, 
+    int (*output)(void *ctx, const char *buffer, size_t bufsize), void *ctx,
     const char *format, va_list ap)
 {
     /* sufficient integer buffer: <available-bits> x log_10(2) + safety */
-    char ibuf[((sizeof(int)*8)/3)+10]; 
+    char ibuf[((sizeof(int)*8)/3)+10];
     char *cp;
     char c;
     int d;
@@ -190,9 +190,9 @@
 } var_mvsnprintf_cb_t;
 
 /* output callback function for var_mvsnprintf() */
-static int 
+static int
 var_mvsnprintf_cb(
-    void *_ctx, 
+    void *_ctx,
     const char *buffer, size_t bufsize)
 {
     var_mvsnprintf_cb_t *ctx = (var_mvsnprintf_cb_t *)_ctx;
@@ -206,9 +206,9 @@
 }
 
 /* minimal vsnprintf(3) variant which supports %{c,s,d} only */
-static int 
+static int
 var_mvsnprintf(
-    char *buffer, size_t bufsize, 
+    char *buffer, size_t bufsize,
     const char *format, va_list ap)
 {
     int n;
@@ -218,7 +218,7 @@
         return -1;
     if (buffer != NULL && bufsize == 0)
         return -1;
-    if (buffer == NULL) 
+    if (buffer == NULL)
         /* just determine output length */
         n = var_mvxprintf(NULL, NULL, format, ap);
     else {
@@ -274,7 +274,7 @@
     size_t buffer_size;
 } tokenbuf_t;
 
-static void 
+static void
 tokenbuf_init(
     tokenbuf_t *buf)
 {
@@ -284,7 +284,7 @@
     return;
 }
 
-static int 
+static int
 tokenbuf_isundef(
     tokenbuf_t *buf)
 {
@@ -293,7 +293,7 @@
     return 0;
 }
 
-static int 
+static int
 tokenbuf_isempty(
     tokenbuf_t *buf)
 {
@@ -302,7 +302,7 @@
     return 0;
 }
 
-static void 
+static void
 tokenbuf_set(
     tokenbuf_t *buf, const char *begin, const char *end, size_t buffer_size)
 {
@@ -312,7 +312,7 @@
     return;
 }
 
-static void 
+static void
 tokenbuf_move(
     tokenbuf_t *src, tokenbuf_t *dst)
 {
@@ -323,7 +323,7 @@
     return;
 }
 
-static int 
+static int
 tokenbuf_assign(
     tokenbuf_t *buf, const char *data, size_t len)
 {
@@ -339,7 +339,7 @@
     return 1;
 }
 
-static int 
+static int
 tokenbuf_append(
     tokenbuf_t *output, const char *data, size_t len)
 {
@@ -396,14 +396,14 @@
     return 1;
 }
 
-static int 
+static int
 tokenbuf_merge(
     tokenbuf_t *output, tokenbuf_t *input)
 {
     return tokenbuf_append(output, input->begin, input->end - input->begin);
 }
 
-static void 
+static void
 tokenbuf_free(
     tokenbuf_t *buf)
 {
@@ -420,7 +420,7 @@
 **
 */
 
-static void 
+static void
 expand_range(
     char a, char b, char_class_t class)
 {
@@ -431,7 +431,7 @@
     return;
 }
 
-static var_rc_t 
+static var_rc_t
 expand_character_class(
     const char *desc, char_class_t class)
 {
@@ -462,7 +462,7 @@
 **
 */
 
-static int 
+static int
 expand_isoct(
     char c)
 {
@@ -472,7 +472,7 @@
         return 0;
 }
 
-static var_rc_t 
+static var_rc_t
 expand_octal(
     const char **src, char **dst, const char *end)
 {
@@ -480,8 +480,8 @@
 
     if (end - *src < 3)
         return VAR_ERR_INCOMPLETE_OCTAL;
-    if (   !expand_isoct(**src) 
-        || !expand_isoct((*src)[1]) 
+    if (   !expand_isoct(**src)
+        || !expand_isoct((*src)[1])
         || !expand_isoct((*src)[2]))
         return VAR_ERR_INVALID_OCTAL;
 
@@ -502,7 +502,7 @@
     return VAR_OK;
 }
 
-static int 
+static int
 expand_ishex(
     char c)
 {
@@ -513,7 +513,7 @@
         return 0;
 }
 
-static var_rc_t 
+static var_rc_t
 expand_simple_hex(
     const char **src, char **dst, const char *end)
 {
@@ -521,7 +521,7 @@
 
     if (end - *src < 2)
         return VAR_ERR_INCOMPLETE_HEX;
-    if (   !expand_ishex(**src) 
+    if (   !expand_ishex(**src)
         || !expand_ishex((*src)[1]))
         return VAR_ERR_INVALID_HEX;
 
@@ -547,7 +547,7 @@
     return VAR_OK;
 }
 
-static var_rc_t 
+static var_rc_t
 expand_grouped_hex(
     const char **src, char **dst, const char *end)
 {
@@ -564,7 +564,7 @@
     return VAR_OK;
 }
 
-static var_rc_t 
+static var_rc_t
 expand_hex(
     const char **src, char **dst, const char *end)
 {
@@ -577,7 +577,7 @@
         return expand_simple_hex(src, dst, end);
 }
 
-/* 
+/*
 **
 **  ==== RECURSIVE-DESCEND VARIABLE EXPANSION PARSER ====
 **
@@ -589,7 +589,7 @@
 static int parse_name   (var_t *var, var_parse_t *ctx, const char *begin, const char *end);
 
 /* parse pattern text */
-static int 
+static int
 parse_pattern(
     var_t *var, var_parse_t *ctx,
     const char *begin, const char *end)
@@ -608,7 +608,7 @@
 }
 
 /* parse substitution text */
-static int 
+static int
 parse_substext(
     var_t *var, var_parse_t *ctx,
     const char *begin, const char *end)
@@ -627,7 +627,7 @@
 }
 
 /* parse expression text */
-static int 
+static int
 parse_exptext(
     var_t *var, var_parse_t *ctx,
     const char *begin, const char *end)
@@ -649,7 +649,7 @@
 }
 
 /* parse opertion argument text */
-static int 
+static int
 parse_opargtext(
     var_t *var, var_parse_t *ctx,
     const char *begin, const char *end)
@@ -667,7 +667,7 @@
     return (p - begin);
 }
 
-static int 
+static int
 parse_opargtext_or_variable(
     var_t *var, var_parse_t *ctx,
     const char *begin, const char *end,
@@ -714,7 +714,7 @@
 }
 
 /* parse expression or variable */
-static int 
+static int
 parse_exptext_or_variable(
     var_t *var, var_parse_t *ctx,
     const char *begin, const char *end,
@@ -765,7 +765,7 @@
 }
 
 /* parse substitution text or variable */
-static int 
+static int
 parse_substext_or_variable(
     var_t *var, var_parse_t *ctx,
     const char *begin, const char *end,
@@ -816,13 +816,13 @@
 }
 
 /* parse class description */
-static int 
+static int
 parse_class_description(
     var_t *var, var_parse_t *ctx,
     tokenbuf_t *src, tokenbuf_t *dst)
 {
     unsigned char c, d;
-    const char *p; 
+    const char *p;
 
     p = src->begin;
     while (p != src->end) {
@@ -844,12 +844,12 @@
 }
 
 /* parse regex replace part */
-static int 
+static int
 parse_regex_replace(
     var_t *var, var_parse_t *ctx,
-    const char *data, 
+    const char *data,
     tokenbuf_t *orig,
-    regmatch_t *pmatch, 
+    regmatch_t *pmatch,
     tokenbuf_t *expanded)
 {
     const char *p;
@@ -901,10 +901,10 @@
 }
 
 /* operation: transpose */
-static int 
+static int
 op_transpose(
     var_t *var, var_parse_t *ctx,
-    tokenbuf_t *data, 
+    tokenbuf_t *data,
     tokenbuf_t *search,
     tokenbuf_t *replace)
 {
@@ -956,12 +956,12 @@
 }
 
 /* operation: search & replace */
-static int 
+static int
 op_search_and_replace(
     var_t *var, var_parse_t *ctx,
-    tokenbuf_t *data, 
+    tokenbuf_t *data,
     tokenbuf_t *search,
-    tokenbuf_t *replace, 
+    tokenbuf_t *replace,
     tokenbuf_t *flags)
 {
     tokenbuf_t tmp;
@@ -1042,7 +1042,7 @@
         }
 
         /* compile the pattern. */
-        rc = regcomp(&preg, tmp.begin, 
+        rc = regcomp(&preg, tmp.begin,
                      (  REG_EXTENDED
                       | (multiline ? REG_NEWLINE : 0)
                       | (case_insensitive ? REG_ICASE : 0)));
@@ -1065,8 +1065,8 @@
                 tokenbuf_append(&tmp, p, mydata.end - p);
                 break;
             }
-            else if (   multiline 
-                     && (p + pmatch[0].rm_so) == mydata.end 
+            else if (   multiline
+                     && (p + pmatch[0].rm_so) == mydata.end
                      && (pmatch[0].rm_eo - pmatch[0].rm_so) == 0) {
                 /* special case: found empty pattern (usually /^/ or /$/ only)
                    in multi-line at end of data (after the last newline) */
@@ -1115,7 +1115,7 @@
                     }
                     p++;
                 }
-                /* append prolog string and stop processing if we 
+                /* append prolog string and stop processing if we
                    do not perform the search & replace globally */
                 if (!global) {
                     if (!tokenbuf_append(&tmp, p, mydata.end - p)) {
@@ -1138,12 +1138,12 @@
 }
 
 /* operation: offset substring */
-static int 
+static int
 op_offset(
     var_t *var, var_parse_t *ctx,
-    tokenbuf_t *data, 
+    tokenbuf_t *data,
     int num1,
-    int num2, 
+    int num2,
     int isrange)
 {
     tokenbuf_t res;
@@ -1180,11 +1180,11 @@
 }
 
 /* operation: padding */
-static int 
+static int
 op_padding(
     var_t *var, var_parse_t *ctx,
-    tokenbuf_t *data, 
-    int width, 
+    tokenbuf_t *data,
+    int width,
     tokenbuf_t *fill,
     char position)
 {
@@ -1281,7 +1281,7 @@
 }
 
 /* parse an integer number ("123") */
-static int 
+static int
 parse_integer(
     var_t *var, var_parse_t *ctx,
     const char *begin, const char *end,
@@ -1303,7 +1303,7 @@
 }
 
 /* parse an operation (":x...") */
-static int 
+static int
 parse_operation(
     var_t *var, var_parse_t *ctx,
     const char *begin, const char *end,
@@ -1585,7 +1585,7 @@
             const char *val_ptr;
             size_t val_len;
             const char *out_ptr;
-            size_t out_len; 
+            size_t out_len;
             size_t out_size;
             tokenbuf_t args;
 
@@ -1658,10 +1658,10 @@
 }
 
 /* parse numerical expression operand */
-static int 
+static int
 parse_numexp_operand(
     var_t *var, var_parse_t *ctx,
-    const char *begin, const char *end, 
+    const char *begin, const char *end,
     int *result, int *failed)
 {
     const char *p;
@@ -1721,7 +1721,7 @@
         }
     }
     /* parse relative index mark ("#") */
-    else if (   var->syntax.index_mark != NUL 
+    else if (   var->syntax.index_mark != NUL
              && *p == var->syntax.index_mark) {
         p++;
         *result = ctx->index_this;
@@ -1762,10 +1762,10 @@
 }
 
 /* parse numerical expression ("x+y") */
-static int 
+static int
 parse_numexp(
     var_t *var, var_parse_t *ctx,
-    const char *begin, const char *end, 
+    const char *begin, const char *end,
     int *result, int *failed)
 {
     const char *p;
@@ -1837,7 +1837,7 @@
 }
 
 /* parse variable name ("abc") */
-static int 
+static int
 parse_name(
     var_t *var, var_parse_t *ctx,
     const char *begin, const char *end)
@@ -1851,7 +1851,7 @@
 }
 
 /* lookup a variable value through the callback function */
-static int 
+static int
 lookup_value(
     var_t *var, var_parse_t *ctx,
     const char  *var_ptr, size_t  var_len, int     var_idx,
@@ -1862,13 +1862,13 @@
 
     /* pass through to original callback */
     rc = (*var->cb_value_fct)(var, var->cb_value_ctx,
-                              var_ptr, var_len, var_idx, 
+                              var_ptr, var_len, var_idx,
                               val_ptr, val_len, val_size);
 
     /* convert undefined variable into empty variable if relative
        lookups are counted. This is the case inside an active loop
        construct if no limits are given. There the parse_input()
-       has to proceed until all variables have undefined values. 
+       has to proceed until all variables have undefined values.
        This trick here allows it to determine this case. */
     if (ctx->rel_lookup_flag && rc == VAR_ERR_UNDEFINED_VARIABLE) {
         ctx->rel_lookup_cnt--;
@@ -1883,7 +1883,7 @@
 }
 
 /* parse complex variable construct ("${name...}") */
-static int 
+static int
 parse_variable_complex(
     var_t *var, var_parse_t *ctx,
     const char *begin, const char *end,
@@ -1940,7 +1940,7 @@
         }
     } while (rc > 0);
 
-    /* we must have the complete expanded variable name now, 
+    /* we must have the complete expanded variable name now,
        so make sure we really do. */
     if (name.begin == name.end) {
         if (ctx->force_expand) {
@@ -2056,7 +2056,7 @@
 }
 
 /* parse variable construct ("$name" or "${name...}") */
-static int 
+static int
 parse_variable(
     var_t *var, var_parse_t *ctx,
     const char *begin, const char *end,
@@ -2078,7 +2078,7 @@
     if (p == end)
         return VAR_ERR_INCOMPLETE_VARIABLE_SPEC;
 
-    /* parse a simple variable name. 
+    /* parse a simple variable name.
        (if this fails, we're try to parse a complex variable construct) */
     rc = parse_name(var, ctx, p, end);
     if (rc < 0)
@@ -2103,7 +2103,7 @@
 }
 
 /* parse loop construct limits ("[...]{b,s,e}") */
-static var_rc_t 
+static var_rc_t
 parse_looplimits(
     var_t *var, var_parse_t *ctx,
     const char *begin, const char *end,
@@ -2200,14 +2200,14 @@
 }
 
 /* parse plain text */
-static int 
+static int
 parse_text(
     var_t *var, var_parse_t *ctx,
     const char *begin, const char *end)
 {
     const char *p;
 
-    /* parse until delim_init (variable construct) 
+    /* parse until delim_init (variable construct)
        or index_open (loop construct) is found */
     for (p = begin; p != end; p++) {
         if (*p == var->syntax.escape) {
@@ -2218,7 +2218,7 @@
         else if (*p == var->syntax.delim_init)
             break;
         else if (   var->syntax.index_open != NUL
-                 && (   *p == var->syntax.index_open 
+                 && (   *p == var->syntax.index_open
                      || *p == var->syntax.index_close))
             break;
     }
@@ -2226,7 +2226,7 @@
 }
 
 /* expand input in general */
-static var_rc_t 
+static var_rc_t
 parse_input(
     var_t *var, var_parse_t *ctx,
     const char *begin, const char *end,
@@ -2247,8 +2247,8 @@
 
     do {
         /* try to parse a loop construct */
-        if (   p != end 
-            && var->syntax.index_open != NUL 
+        if (   p != end
+            && var->syntax.index_open != NUL
             && *p == var->syntax.index_open) {
             p++;
 
@@ -2268,24 +2268,24 @@
                or there is a stop limit known and it is still not reached */
             re_loop:
             for (i = start;
-                 (   (   open_stop 
-                      && (   loop_limit_length < 0 
-                          || rel_lookup_cnt > ctx->rel_lookup_cnt)) 
-                  || (   !open_stop 
+                 (   (   open_stop
+                      && (   loop_limit_length < 0
+                          || rel_lookup_cnt > ctx->rel_lookup_cnt))
+                  || (   !open_stop
                       && i <= stop)                                );
                  i += step) {
 
                 /* remember current output end for restoring */
                 output_backup = (output->end - output->begin);
 
-                /* open temporary context for recursion */ 
+                /* open temporary context for recursion */
                 ctx = var_parse_push(ctx, &myctx);
                 ctx->force_expand    = 1;
                 ctx->rel_lookup_flag = 1;
                 ctx->index_this      = i;
 
                 /* recursive parse input through ourself */
-                rc = parse_input(var, ctx, p, end, 
+                rc = parse_input(var, ctx, p, end,
                                  output, recursion_level+1);
 
                 /* retrieve info and close temporary context */
@@ -2304,7 +2304,7 @@
 
                 /* try to parse loop construct limit specification */
                 if (loop_limit_length < 0) {
-                    rc2 = parse_looplimits(var, ctx, p+rc+1, end, 
+                    rc2 = parse_looplimits(var, ctx, p+rc+1, end,
                                            &start, &step, &stop, &open_stop);
                     if (rc2 < 0)
                         goto error_return;
@@ -2357,7 +2357,7 @@
             tokenbuf_free(&result);
             p += rc;
             continue;
-        }    
+        }
         tokenbuf_free(&result);
         if (rc < 0)
             goto error_return;
@@ -2387,14 +2387,14 @@
     return rc;
 }
 
-/* 
+/*
 **
 **  ==== APPLICATION PROGRAMMING INTERFACE (API) ====
 **
 */
 
 /* create variable expansion context */
-var_rc_t 
+var_rc_t
 var_create(
     var_t **pvar)
 {
@@ -2411,7 +2411,7 @@
 }
 
 /* destroy variable expansion context */
-var_rc_t 
+var_rc_t
 var_destroy(
     var_t *var)
 {
@@ -2422,10 +2422,10 @@
 }
 
 /* configure variable expansion context */
-var_rc_t 
+var_rc_t
 var_config(
-    var_t *var, 
-    var_config_t mode, 
+    var_t *var,
+    var_config_t mode,
     ...)
 {
     va_list ap;
@@ -2450,7 +2450,7 @@
             var->syntax.name_chars  = NULL; /* unused internally */
             if ((rc = expand_character_class(s->name_chars, var->syntax_nameclass)) != VAR_OK)
                 return VAR_RC(rc);
-            if (   var->syntax_nameclass[(int)var->syntax.delim_init] 
+            if (   var->syntax_nameclass[(int)var->syntax.delim_init]
                 || var->syntax_nameclass[(int)var->syntax.delim_open]
                 || var->syntax_nameclass[(int)var->syntax.delim_close]
                 || var->syntax_nameclass[(int)var->syntax.escape])
@@ -2483,11 +2483,11 @@
 }
 
 /* perform unescape operation on a buffer */
-var_rc_t 
+var_rc_t
 var_unescape(
-    var_t *var, 
-    const char *src, size_t srclen, 
-    char *dst, size_t dstlen, 
+    var_t *var,
+    const char *src, size_t srclen,
+    char *dst, size_t dstlen,
     int all)
 {
     const char *end;
@@ -2523,8 +2523,8 @@
                     break;
                 case '0': case '1': case '2': case '3': case '4':
                 case '5': case '6': case '7': case '8': case '9':
-                    if (   end - src >= 3 
-                        && isdigit((int)src[1]) 
+                    if (   end - src >= 3
+                        && isdigit((int)src[1])
                         && isdigit((int)src[2])) {
                         if ((rc = expand_octal(&src, &dst, end)) != 0)
                             return VAR_RC(rc);
@@ -2545,11 +2545,11 @@
 }
 
 /* perform expand operation on a buffer */
-var_rc_t 
+var_rc_t
 var_expand(
-    var_t *var, 
-    const char *src_ptr, size_t src_len, 
-    char **dst_ptr, size_t *dst_len, 
+    var_t *var,
+    const char *src_ptr, size_t src_len,
+    char **dst_ptr, size_t *dst_len,
     int force_expand)
 {
     var_parse_t ctx;
@@ -2573,7 +2573,7 @@
 
     /* post-processing */
     if (rc >= 0) {
-        /* always NUL-terminate output for convinience reasons 
+        /* always NUL-terminate output for convinience reasons
            but do not count the NUL-terminator in the length */
         if (!tokenbuf_append(&output, "\0", 1)) {
             tokenbuf_free(&output);
@@ -2598,10 +2598,10 @@
 }
 
 /* format and expand a string */
-var_rc_t 
+var_rc_t
 var_formatv(
-    var_t *var, 
-    char **dst_ptr, int force_expand, 
+    var_t *var,
+    char **dst_ptr, int force_expand,
     const char *fmt, va_list ap)
 {
     var_rc_t rc;
@@ -2642,10 +2642,10 @@
 }
 
 /* format and expand a string */
-var_rc_t 
+var_rc_t
 var_format(
-    var_t *var, 
-    char **dst_ptr, int force_expand, 
+    var_t *var,
+    char **dst_ptr, int force_expand,
     const char *fmt, ...)
 {
     var_rc_t rc;

CVSTrac 2.0.1