OSSP CVS Repository

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

Check-in Number: 476
Date: 2001-May-19 22:08:30 (local)
2001-May-19 20:08:30 (UTC)
User:rse
Branch:
Comment: the "int l2_channel_configure(l2_channel_t *ch, const char *fmt, ...);" beast was my idea, so it is fair to also provide the necessary tool for implementing the underlying handler functions. Here it is, l2_param_parse().
Tickets:
Inspections:
Files:
ossp-pkg/l2/Makefile.in      1.5 -> 1.6     1 inserted, 0 deleted
ossp-pkg/l2/l2.h      1.2 -> 1.3     47 inserted, 2 deleted
ossp-pkg/l2/l2_p.h      1.2 -> 1.3     19 inserted, 0 deleted
ossp-pkg/l2/l2_param.c      added-> 1.1

ossp-pkg/l2/Makefile.in 1.5 -> 1.6

--- Makefile.in  2001/05/19 19:01:13     1.5
+++ Makefile.in  2001/05/19 20:08:30     1.6
@@ -66,6 +66,7 @@
     l2_log.lo \
     l2_stream.lo \
     l2_channel.lo \
+    l2_param.lo \
     l2_ch_fd.lo \
     l2_ch_file.lo \
     l2_ch_pipe.lo \


ossp-pkg/l2/l2.h 1.2 -> 1.3

--- l2.h 2001/05/11 17:07:52     1.2
+++ l2.h 2001/05/19 20:08:30     1.3
@@ -30,18 +30,33 @@
 #ifndef __L2_H__
 #define __L2_H__
 
+/* include standard environment we are based on */
+#include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
 
+/* counterbalance poor standard environments */ 
+#ifndef NULL
+#define NULL (void *)0
+#endif
+#ifndef FALSE
+#define FALSE (0)
+#endif
+#ifndef TRUE
+#define TRUE (!FALSE)
+#endif
+
 /* forward declarations for opaque data structures */
 union  l2_context_un;
+struct l2_param_st;
 struct l2_stream_st;
 struct l2_channel_st;
 struct l2_handler_st;
 
 /* corresponding data types for data structures */
 typedef union  l2_context_un l2_context_t;
+typedef struct l2_param_st   l2_param_t;
 typedef struct l2_handler_st l2_handler_t;
 typedef struct l2_stream_st  l2_stream_t;
 typedef struct l2_channel_st l2_channel_t;
@@ -64,16 +79,43 @@
     L2_ERROR
 } l2_error_t;
 
-/* context union for callbacks */
+/* context union for storing data */
 union l2_context_un {
+    char    c;
+    short   s;
     int     i;
     long    l;
     float   f;
     double  d;
-    void   *vp;
     char   *cp;
+    void   *vp;
+};
+
+/* list of types for storing data */
+typedef enum {
+    L2_TYPE_CHAR,
+    L2_TYPE_SHORT,
+    L2_TYPE_INT,
+    L2_TYPE_LONG,
+    L2_TYPE_FLOAT,
+    L2_TYPE_DOUBLE,
+    L2_TYPE_CHARPTR,
+    L2_TYPE_VOIDPTR
+} l2_type_t;
+
+/* parameter specification */
+struct l2_param_st {
+    char     *name;
+    l2_type_t type;
+    void     *store;
 };
 
+/* parameter constructors */
+#define L2_PARAM_SET(pa,n,t,s) \
+    pa.name = #n, pa.type = L2_TYPE_##t, pa.store = s
+#define L2_PARAM_END(pa) \
+    pa.name = NULL
+
 /* channel handler specification structure */
 struct l2_handler_st {
     int (*create)   (l2_context_t *ctx);
@@ -108,6 +150,9 @@
 extern l2_handler_t l2_handler_prefix;
 extern l2_handler_t l2_handler_buffer;
 
+/* parameter operations */
+int           l2_param_parse      (l2_param_t p[], const char *fmt, va_list ap);
+
 /* channel operations */
 l2_channel_t *l2_channel_create   (l2_handler_t *h);
 l2_channel_t *l2_channel_stack    (l2_channel_t *ch1, l2_channel_t *ch2);


ossp-pkg/l2/l2_p.h 1.2 -> 1.3

--- l2_p.h       2001/05/17 14:41:30     1.2
+++ l2_p.h       2001/05/19 20:08:30     1.3
@@ -56,5 +56,24 @@
     l2_format_t  *formatters[L2_MAX_FORMATTERS];
 };
 
+/* variable argument handling taking care on argument passing conventions */
+#define _va_type_recv_char    int
+#define _va_type_cast_char    char
+#define _va_type_recv_short   int
+#define _va_type_cast_short   short
+#define _va_type_recv_int     int
+#define _va_type_cast_int     int
+#define _va_type_recv_long    long
+#define _va_type_cast_long    long
+#define _va_type_recv_float   double
+#define _va_type_cast_float   double
+#define _va_type_recv_double  double
+#define _va_type_cast_double  double
+#define _va_type_recv_charptr void *
+#define _va_type_cast_charptr char *
+#define _va_type_recv_voidptr void *
+#define _va_type_cast_voidptr void *
+#define va_get(ap,type) (_va_type_cast_##type)va_arg((ap),_va_type_recv_##type)
+
 #endif /* __L2_P_H__ */
 


ossp-pkg/l2/l2_param.c -> 1.1

*** /dev/null    Sat Nov 23 01:11:26 2024
--- -    Sat Nov 23 01:11:28 2024
***************
*** 0 ****
--- 1,101 ----
+ /*
+ **  L2 - OSSP Logging Library
+ **  Copyright (c) 2001 The OSSP Project (http://www.ossp.org/)
+ **  Copyright (c) 2001 Cable & Wireless Deutschland (http://www.cw.com/de/)
+ **
+ **  This file is part of OSSP L2, a flexible logging library which
+ **  can be found at http://www.ossp.com/pkg/l2/.
+ **
+ **  Permission to use, copy, modify, and distribute this software for
+ **  any purpose with or without fee is hereby granted, provided that
+ **  the above copyright notice and this permission notice appear in all
+ **  copies.
+ **
+ **  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ **  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ **  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ **  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
+ **  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ **  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ **  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ **  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ **  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ **  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ **  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ **  SUCH DAMAGE.
+ **
+ **  l2_param.c: parameter handling
+ **
+ */
+ 
+ #include "l2.h"
+ #include "l2_p.h"
+ 
+ int l2_param_parse(l2_param_t pa[], const char *fmt, va_list ap)
+ {
+     const char *cpB, *cpE;
+     const char *cpC, *cpG;
+     int ok;
+     int i; 
+ 
+     cpE = fmt;
+     while (*cpE != '\0') {
+         /* determine begin of parameter name */
+         cpB = cpE;
+         while (*cpB == ',')
+             cpB++;
+ 
+         /* determine end of parameter name */
+         cpE = cpB;
+         while (*cpE != ',' && *cpE != '\0')
+             cpE++;
+ 
+         /* try to match with configured parameters */
+         ok = FALSE;
+         for (i = 0; pa[i].name != NULL; i++) {
+             cpC = pa[i].name;
+             cpG = cpB;
+             while (*cpC != '\0' && cpG < cpE) {
+                 if (*cpC != *cpG)
+                     break;
+                 cpC++;
+                 cpG++;
+             }
+             if (*cpC == '\0' && cpG == cpE) {
+                 /* parameter matched, so store value */
+                 switch (pa[i].type) {
+                     case L2_TYPE_CHAR:
+                         *(char *)(pa[i].store) = va_get(ap, char); 
+                         break;
+                     case L2_TYPE_SHORT:
+                         *(short *)(pa[i].store) = va_get(ap, short); 
+                         break;
+                     case L2_TYPE_INT:
+                         *(int *)(pa[i].store) = va_get(ap, int); 
+                         break;
+                     case L2_TYPE_LONG:
+                         *(long *)(pa[i].store) = va_get(ap, long); 
+                         break;
+                     case L2_TYPE_FLOAT:
+                         *(float *)(pa[i].store) = va_get(ap, float); 
+                         break;
+                     case L2_TYPE_DOUBLE:
+                         *(double *)(pa[i].store) = va_get(ap, double); 
+                         break;
+                     case L2_TYPE_CHARPTR:
+                         *(char **)(pa[i].store) = va_get(ap, charptr); 
+                         break;
+                     case L2_TYPE_VOIDPTR:
+                         *(void **)(pa[i].store) = va_get(ap, voidptr); 
+                         break;
+                 }
+                 ok = TRUE;
+                 break;
+             }
+         }
+         if (!ok)
+             return L2_ERROR;
+     }
+     return L2_OK;
+ }
+ 

CVSTrac 2.0.1