OSSP CVS Repository

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

Check-in Number: 1389
Date: 2001-Nov-30 10:44:47 (local)
2001-Nov-30 09:44:47 (UTC)
User:rse
Branch:
Comment: Allow a channel tree specification to be a printf-style string to make the API more powerful and to remove the burden from the application to pre-format the specification in an own buffer.
Tickets:
Inspections:
Files:
ossp-pkg/l2/l2.h.in      1.23 -> 1.24     2 inserted, 1 deleted
ossp-pkg/l2/l2_spec.c      1.3 -> 1.4     26 inserted, 4 deleted
ossp-pkg/l2/l2_test.c      1.47 -> 1.48     1 inserted, 1 deleted

ossp-pkg/l2/l2.h.in 1.23 -> 1.24

--- l2.h.in      2001/11/16 19:53:05     1.23
+++ l2.h.in      2001/11/30 09:44:47     1.24
@@ -229,7 +229,8 @@
 l2_result_t   l2_channel_env        (l2_channel_t *ch, l2_env_t **env);
 
 /* channel tree specification operations */
-l2_result_t   l2_spec               (l2_channel_t **ch, l2_env_t *env, const char *spec);
+l2_result_t   l2_spec               (l2_channel_t **ch, l2_env_t *env, const char *spec, ...);
+l2_result_t   l2_vspec              (l2_channel_t **ch, l2_env_t *env, const char *spec, va_list ap);
 
 /* utility operations */
 l2_result_t   l2_util_setparams     (l2_env_t *env, l2_param_t p[], const char *fmt, va_list ap);


ossp-pkg/l2/l2_spec.c 1.3 -> 1.4

--- l2_spec.c    2001/11/07 16:43:07     1.3
+++ l2_spec.c    2001/11/30 09:44:47     1.4
@@ -40,10 +40,29 @@
 extern int  l2_spec_parse(void *);
 
 /* build a channel tree according to a textual specification */
-l2_result_t l2_spec(l2_channel_t **ch, l2_env_t *env, const char *spec)
+l2_result_t l2_spec(l2_channel_t **ch, l2_env_t *env, const char *spec, ...)
+{
+    va_list ap;
+    l2_result_t rv;
+
+    /* pass-through to va_list-based variant */
+    va_start(ap, spec);
+    rv = l2_vspec(ch, env, spec, ap);
+    va_end(ap);
+
+    return rv;
+}
+
+/* build a channel tree according to a textual specification (va_list variant) */
+l2_result_t l2_vspec(l2_channel_t **ch, l2_env_t *env, const char *spec, va_list ap)
 {
     l2_spec_ctx_t ctx;
     void *yyscan;
+    char *specstr;
+
+    /* on-the-fly create or take over specification string */
+    if ((specstr = l2_util_vasprintf(spec, ap)) == NULL)
+        return L2_ERR_ARG;
 
     /* initialize scanner */
     l2_spec_lex_init(&yyscan);
@@ -52,9 +71,9 @@
     /* establish our own context which is passed 
        through the parser and scanner */
     ctx.yyscan   = yyscan;
-    ctx.inputptr = spec;
-    ctx.inputbuf = spec;
-    ctx.inputlen = strlen(spec);
+    ctx.inputptr = specstr;
+    ctx.inputbuf = specstr;
+    ctx.inputlen = strlen(specstr);
     ctx.env      = env;
     ctx.ch       = NULL;
     ctx.chTmp    = NULL;
@@ -67,6 +86,9 @@
     /* destroy scanner */
     l2_spec_lex_destroy(yyscan);
 
+    /* destroy specification string */
+    free(specstr);
+
     /* provide root/top-level channel as result */
     *ch = ctx.ch;
 


ossp-pkg/l2/l2_test.c 1.47 -> 1.48

--- l2_test.c    2001/11/16 19:40:55     1.47
+++ l2_test.c    2001/11/30 09:44:47     1.48
@@ -94,7 +94,7 @@
            "         remotehost=en1, logpid=1, target=remote)"
            "}";
     fprintf(stderr, "configuring: %s\n", spec);
-    if ((rv = l2_spec(&ch, env, spec)) != L2_OK)
+    if ((rv = l2_spec(&ch, env, "%s", spec)) != L2_OK)
         die(env, rv, "failed to parse specification");
 #else
     /* create noop channel */

CVSTrac 2.0.1