OSSP CVS Repository

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

Check-in Number: 1551
Date: 2002-Jan-15 14:02:20 (local)
2002-Jan-15 13:02:20 (UTC)
User:thl
Branch:
Comment: map renamed to val and basic functionality successfully verified
Tickets:
Inspections:
Files:
ossp-pkg/lmtp2nntp/Makefile.in      1.37 -> 1.38     3 inserted, 3 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_config.c      1.3 -> 1.4     63 inserted, 0 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_map.c      1.1->removed
ossp-pkg/lmtp2nntp/lmtp2nntp_map.h      1.1->removed
ossp-pkg/lmtp2nntp/lmtp2nntp_val.c      added-> 1.1
ossp-pkg/lmtp2nntp/lmtp2nntp_val.h      added-> 1.1

ossp-pkg/lmtp2nntp/Makefile.in 1.37 -> 1.38

--- Makefile.in  2002/01/14 14:49:07     1.37
+++ Makefile.in  2002/01/15 13:02:20     1.38
@@ -44,9 +44,9 @@
 POD2MAN     = pod2man
 
 PROG = lmtp2nntp
-HDRS = lmtp2nntp_global.h lmtp2nntp_daemon.h lmtp2nntp_lmtp.h lmtp2nntp_nntp.h lmtp2nntp_argz.h lmtp2nntp_shpat.h lmtp2nntp_msg.h lmtp2nntp_popt.h lmtp2nntp_config.h lmtp2nntp_lh.h
-SRCS = lmtp2nntp_main.c   lmtp2nntp_daemon.c lmtp2nntp_lmtp.c lmtp2nntp_nntp.c lmtp2nntp_argz.c lmtp2nntp_shpat.c lmtp2nntp_msg.c lmtp2nntp_popt.c lmtp2nntp_config.c lmtp2nntp_lh.c lmtp2nntp_version.c 
-OBJS = lmtp2nntp_main.o   lmtp2nntp_daemon.o lmtp2nntp_lmtp.o lmtp2nntp_nntp.o lmtp2nntp_argz.o lmtp2nntp_shpat.o lmtp2nntp_msg.o lmtp2nntp_popt.o lmtp2nntp_config.o lmtp2nntp_lh.o lmtp2nntp_version.o
+HDRS = lmtp2nntp_global.h lmtp2nntp_daemon.h lmtp2nntp_lmtp.h lmtp2nntp_nntp.h lmtp2nntp_argz.h lmtp2nntp_shpat.h lmtp2nntp_msg.h lmtp2nntp_popt.h lmtp2nntp_val.h lmtp2nntp_config.h lmtp2nntp_lh.h
+SRCS = lmtp2nntp_main.c   lmtp2nntp_daemon.c lmtp2nntp_lmtp.c lmtp2nntp_nntp.c lmtp2nntp_argz.c lmtp2nntp_shpat.c lmtp2nntp_msg.c lmtp2nntp_popt.c lmtp2nntp_val.c lmtp2nntp_config.c lmtp2nntp_lh.c lmtp2nntp_version.c 
+OBJS = lmtp2nntp_main.o   lmtp2nntp_daemon.o lmtp2nntp_lmtp.o lmtp2nntp_nntp.o lmtp2nntp_argz.o lmtp2nntp_shpat.o lmtp2nntp_msg.o lmtp2nntp_popt.o lmtp2nntp_val.o lmtp2nntp_config.o lmtp2nntp_lh.o lmtp2nntp_version.o
 
 SUBDIRS = @SUBDIR_STR@ @SUBDIR_L2@ @SUBDIR_SA@ @SUBDIR_VAR@
 


ossp-pkg/lmtp2nntp/lmtp2nntp_config.c 1.3 -> 1.4

--- lmtp2nntp_config.c   2002/01/14 12:23:21     1.3
+++ lmtp2nntp_config.c   2002/01/15 13:02:20     1.4
@@ -44,6 +44,7 @@
 // #include "lmtp2nntp_shpat.h"
 // #include "lmtp2nntp_daemon.h"
 #include "lmtp2nntp_popt.h"
+#include "lmtp2nntp_val.h"
 
 /* third party (linked in) */
 #include "str.h"
@@ -137,6 +138,37 @@
     ctx->option_childsmax = 10;
 
     {
+        int testint = 10;
+        int testintout = 100;
+        val_rc_t rc;
+        val_t *v;
+
+        if ((rc = val_create(&v)) != VAL_OK)
+            die("val_create");
+
+        printf("DEBUG: testint = %d, testintout = %d\n", testint, testintout);
+
+        if ((rc = val_reg(v, "foo", VAL_TYPE_INT, (void *)&testint)) != VAL_OK)
+            die("val_reg");
+
+        testint++;
+        if ((rc = val_get(v, "foo", &testintout)) != VAL_OK)
+            die("val_get");
+        printf("DEBUG: testint = %d, testintout = %d\n", testint, testintout);
+
+        if ((rc = val_set(v, "foo", 2)) != VAL_OK)
+            die("val_set");
+        if ((rc = val_get(v, "foo", &testintout)) != VAL_OK)
+            die("val_get");
+        printf("DEBUG: testint = %d, testintout = %d\n", testint, testintout);
+
+        if ((rc = val_destroy(v)) != VAL_OK)
+            die("val_destroy");
+
+        return;
+    }
+
+    {
         char c;
         char *cp;
 
@@ -159,6 +191,37 @@
         return;
     }
 
+/* Braindump
+
+    fuer configure
+
+ich brauche eine Tabelle, die alle optionen in langer und kurzer Form
+enthaelt, Angabe ob flag, single- oder multivalue, callbacks fuer die
+syntaxpruefung des human-readable inputs, die conversion ins interne binaryformat sowie rueckwandlung in
+human-readable format. Dazu informationen fuer help.
+ */
+
+/* Braindump
+
+    fuer var
+
+ich brauche eine struktur, aus der man ersehen kann, welche variablen es gibt. 
+    {
+        struct "system.uname.sysname",  varstring, 
+        struct "system.uname.nodename", 
+        struct "system.uname.release", 
+        struct "system.uname.version", 
+        struct "system.uname.machine", 
+        
+        <<< ctx->progname = strdup(argv[0]);
+        <<< foo = ctx->progname;
+
+        >>> rc = varreg("main.progname", &ctx->progname);
+        >>> rc = varset("main.progname", strdup(argv[0])); //equivalent to ctx->progname = strdup(argv[0]);
+        >>> rc = varget("main.progname", &foo);            //equivalent to foo = ctx->progname
+    }
+ */
+
     {
         const char *filename = "example.conf";
         struct stat sb;


ossp-pkg/lmtp2nntp/lmtp2nntp_map.c 1.1 -> 1.2



ossp-pkg/lmtp2nntp/lmtp2nntp_map.h 1.1 -> 1.2



ossp-pkg/lmtp2nntp/lmtp2nntp_val.c -> 1.1

*** /dev/null    Thu Oct 28 06:45:32 2021
--- -    Thu Oct 28 06:47:59 2021
***************
*** 0 ****
--- 1,214 ----
+ 
+ #include "lmtp2nntp_val.h"
+ #include "lmtp2nntp_lh.h"
+ #include <stdlib.h>
+ #include <stdarg.h>
+ #include <string.h>
+ 
+ 
+ /* usually val_object_t.data is a pointer val_object_t.data.p, but VAL_INLINE
+  * signals val_object_t.data is actual data val_object_t.data.[csilfd]
+  */
+ enum {
+     VAL_INLINE      = 1<<31
+ };
+ 
+ typedef struct {
+     char *name;
+     int type;
+     union {
+         void  *p;
+         char   c;
+         short  s;
+         int    i;
+         long   l;
+         float  f;
+         double d;
+     } data;
+ } val_object_t;
+ 
+ struct val_s {
+     lh_t *lh;
+ };
+ 
+ static void *val_unionptr(val_object_t *obj)
+ {
+     void *storage;
+ 
+     switch (obj->type & ~VAL_INLINE) {
+         case VAL_TYPE_PTR:
+             storage = &obj->data.p;
+             break;
+         case VAL_TYPE_CHAR:
+             storage = (void *)&obj->data.c;
+             break;
+         case VAL_TYPE_SHORT:
+             storage = (void *)&obj->data.s;
+             break;
+         case VAL_TYPE_INT:
+             storage = (void *)&obj->data.i;
+             break;
+         case VAL_TYPE_LONG:
+             storage = (void *)&obj->data.l;
+             break;
+         case VAL_TYPE_FLOAT:
+             storage = (void *)&obj->data.f;
+             break;
+         case VAL_TYPE_DOUBLE:
+             storage = (void *)&obj->data.d;
+             break;
+         default:
+             storage = NULL;
+     }
+     return storage;
+ }
+ 
+ val_rc_t val_create(val_t **valp)
+ {
+     val_t *val;
+ 
+     if ((val = (val_t *)malloc(sizeof(val_t))) == NULL)
+         return VAL_MEMORY;
+     if ((val->lh = lh_create()) == NULL)
+         return VAL_LH;
+     *valp = val;
+     return VAL_OK;
+ }
+ 
+ val_rc_t val_destroy(val_t *val)
+ {
+     if (val == NULL)
+         return VAL_MEMORY;
+     lh_destroy(val->lh);
+     free(val);
+     return VAL_OK;
+ }
+ 
+ val_rc_t val_reg(val_t *val, const char *name, int type, void *storage)
+ {
+     val_object_t obj;
+ 
+     if ((obj.name = strdup(name)) == NULL)
+         return VAL_MEMORY;
+     obj.type = type;
+     if (storage == NULL) {
+         obj.type |= VAL_INLINE;
+         obj.data.l = 0;
+     }
+     else
+         obj.data.p = storage;
+ 
+     if (! lh_insert(val->lh, name, strlen(name), &obj, sizeof(obj), 1))
+         return VAL_LH;
+     
+     return VAL_OK;
+ }
+ 
+ val_rc_t val_vset(val_t *val, const char *name, va_list ap)
+ {
+     val_object_t *obj;
+     void *storage;
+     const char *cp;
+ 
+     if ((cp = strchr(name, '.')) != NULL) {
+         if (! lh_lookup(val->lh, name, cp-name, (void **)&obj, NULL))
+             return VAL_LH;
+         return val_vset((val_t *)obj->data.p, cp+1, ap);
+     }
+     if (! lh_lookup(val->lh, name, strlen(name), (void **)&obj, NULL))
+         return VAL_LH;
+     if (obj->type & VAL_INLINE)
+         storage = val_unionptr(obj);
+     else
+         storage = obj->data.p;
+     switch(obj->type & ~VAL_INLINE) {
+         case VAL_TYPE_PTR:
+             *(char **)storage = (char *)va_arg(ap, void *);
+             break;
+         case VAL_TYPE_CHAR:
+             *(char *)storage = (char)va_arg(ap, int);
+             break;
+         case VAL_TYPE_SHORT:
+             *(short *)storage = (short)va_arg(ap, int);
+             break;
+         case VAL_TYPE_INT:
+             *(int *)storage = (int)va_arg(ap, int);
+             break;
+         case VAL_TYPE_LONG:
+             *(long *)storage = (long)va_arg(ap, long);
+             break;
+         case VAL_TYPE_FLOAT:
+             *(float *)storage = (float)va_arg(ap, double);
+             break;
+         case VAL_TYPE_DOUBLE:
+             *(double *)storage = (double)va_arg(ap, double);
+             break;
+     }
+     return VAL_OK;
+ }
+ 
+ val_rc_t val_set(val_t *val, const char *name, ...)
+ {
+     val_rc_t rc;
+     va_list ap;
+ 
+     va_start(ap, name);
+     rc = val_vset(val, name, ap);
+     va_end(ap);
+     return rc;
+ }
+ 
+ val_rc_t val_vget(val_t *val, const char *name, va_list ap)
+ {
+     val_object_t *obj;
+     void *storage;
+     const char *cp;
+ 
+     if ((cp = strchr(name, '.')) != NULL) {
+         if (! lh_lookup(val->lh, name, cp-name, (void **)&obj, NULL))
+             return VAL_LH;
+         return val_vget((val_t *)obj->data.p, cp+1, ap);
+     }
+     if (! lh_lookup(val->lh, name, strlen(name), (void **)&obj, NULL))
+         return VAL_LH;
+     if (obj->type & VAL_INLINE)
+         storage = val_unionptr(obj);
+     else
+         storage = obj->data.p;
+     switch (obj->type & ~VAL_INLINE) {
+         case VAL_TYPE_PTR:
+             *((char **)va_arg(ap, void *)) = *(char **)storage;
+             break;
+         case VAL_TYPE_CHAR:
+             *((char *)va_arg(ap, int *)) = *(char *)storage;
+             break;
+         case VAL_TYPE_SHORT:
+             *((short *)va_arg(ap, int *)) = *(short *)storage;
+             break;
+         case VAL_TYPE_INT:
+             *((int *)va_arg(ap, int *)) = *(int *)storage;
+             break;
+         case VAL_TYPE_LONG:
+             *((long *)va_arg(ap, long *)) = *(long *)storage;
+             break;
+         case VAL_TYPE_FLOAT:
+             *((float *)va_arg(ap, double *)) = *(float *)storage;
+             break;
+         case VAL_TYPE_DOUBLE:
+             *((double *)va_arg(ap, double *)) = *(double *)storage;
+             break;
+     }
+     return VAL_OK;
+ }
+ 
+ val_rc_t val_get(val_t *val, const char *name, ...)
+ {
+     val_rc_t rc;
+     va_list ap;
+ 
+     va_start(ap, name);
+     rc = val_vget(val, name, ap);
+     va_end(ap);
+     return rc;
+ }
+ 


ossp-pkg/lmtp2nntp/lmtp2nntp_val.h -> 1.1

*** /dev/null    Thu Oct 28 06:45:32 2021
--- -    Thu Oct 28 06:47:59 2021
***************
*** 0 ****
--- 1,31 ----
+ 
+ #include <stdarg.h>
+ 
+ enum {
+     VAL_TYPE_PTR    = 1<<0,
+     VAL_TYPE_CHAR   = 1<<1,
+     VAL_TYPE_SHORT  = 1<<2,
+     VAL_TYPE_INT    = 1<<3,
+     VAL_TYPE_LONG   = 1<<4,
+     VAL_TYPE_FLOAT  = 1<<5,
+     VAL_TYPE_DOUBLE = 1<<6
+ };
+ 
+ typedef enum {
+     VAL_OK,
+     VAL_MEMORY,
+     VAL_LH,
+     VAL_UNKNOWN
+ } val_rc_t;
+ 
+ struct val_s;
+ typedef struct val_s val_t;
+ 
+ val_rc_t val_create  (val_t **);
+ val_rc_t val_destroy (val_t *);
+ val_rc_t val_reg     (val_t *, const char *, int, void *);
+ val_rc_t val_set     (val_t *, const char *, ...);
+ val_rc_t val_get     (val_t *, const char *, ...);
+ val_rc_t val_vset    (val_t *, const char *, va_list);
+ val_rc_t val_vget    (val_t *, const char *, va_list);
+ 

CVSTrac 2.0.1