Index: ossp-pkg/lmtp2nntp/Makefile.in RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Makefile.in,v rcsdiff -q -kk '-r1.37' '-r1.38' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Makefile.in,v' 2>/dev/null --- 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@ Index: ossp-pkg/lmtp2nntp/lmtp2nntp_config.c RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/lmtp2nntp_config.c,v rcsdiff -q -kk '-r1.3' '-r1.4' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/lmtp2nntp_config.c,v' 2>/dev/null --- 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; Index: ossp-pkg/lmtp2nntp/lmtp2nntp_map.c RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp_map.c,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp_map.c,v' | diff -u - /dev/null -L'ossp-pkg/lmtp2nntp/lmtp2nntp_map.c' 2>/dev/null --- ossp-pkg/lmtp2nntp/lmtp2nntp_map.c +++ /dev/null 2025-04-04 18:08:12.000000000 +0200 @@ -1,21 +0,0 @@ - -#include "lmtp2nntp_map.h" - -enum { - VAR_INLINE = 1<<0, -}; - -typedef struct { - char *name; - var_type_t type; - union { - void *p; - char c; - short s; - int i; - long l; - float f; - double d; - } data; -} var_object_t; - Index: ossp-pkg/lmtp2nntp/lmtp2nntp_map.h RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp_map.h,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp_map.h,v' | diff -u - /dev/null -L'ossp-pkg/lmtp2nntp/lmtp2nntp_map.h' 2>/dev/null --- ossp-pkg/lmtp2nntp/lmtp2nntp_map.h +++ /dev/null 2025-04-04 18:08:12.000000000 +0200 @@ -1,17 +0,0 @@ - -enum { - VAR_TYPE_PTR = 1<<1, - VAR_TYPE_CHAR = 1<<2, - VAR_TYPE_SHORT = 1<<3, - VAR_TYPE_INT = 1<<4, - VAR_TYPE_LONG = 1<<5, - VAR_TYPE_FLOAT = 1<<6, - VAR_TYPE_DOUBLE = 1<<7 -}; - -var_rc_t var_create (var_t *var); -var_rc_t var_destroy (var_t *var); -var_rc_t var_reg (var_t *var, const char *name, int type, void *storage); -var_rc_t var_set (var_t *var, const char *name, ...); -var_rc_t var_get (var_t *var, const char *name, ...); - Index: ossp-pkg/lmtp2nntp/lmtp2nntp_val.c RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp_val.c,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp_val.c,v' | diff -u /dev/null - -L'ossp-pkg/lmtp2nntp/lmtp2nntp_val.c' 2>/dev/null --- ossp-pkg/lmtp2nntp/lmtp2nntp_val.c +++ - 2025-04-04 18:08:12.547485117 +0200 @@ -0,0 +1,214 @@ + +#include "lmtp2nntp_val.h" +#include "lmtp2nntp_lh.h" +#include +#include +#include + + +/* 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; +} + Index: ossp-pkg/lmtp2nntp/lmtp2nntp_val.h RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp_val.h,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp_val.h,v' | diff -u /dev/null - -L'ossp-pkg/lmtp2nntp/lmtp2nntp_val.h' 2>/dev/null --- ossp-pkg/lmtp2nntp/lmtp2nntp_val.h +++ - 2025-04-04 18:08:12.550220766 +0200 @@ -0,0 +1,31 @@ + +#include + +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); +