OSSP CVS Repository

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

Check-in Number: 1125
Date: 2001-Oct-09 17:34:55 (local)
2001-Oct-09 15:34:55 (UTC)
User:rse
Branch:
Comment: Veto: back-out latest level-related changes. Sorry, Michael, the padding has to be done in l2_ch_prefix.c only.
Tickets:
Inspections:
Files:
ossp-pkg/l2/l2.h.in      1.12 -> 1.13     2 inserted, 2 deleted
ossp-pkg/l2/l2_ch_prefix.c      1.14 -> 1.15     1 inserted, 1 deleted
ossp-pkg/l2/l2_ut_level.c      1.4 -> 1.5     52 inserted, 37 deleted

ossp-pkg/l2/l2.h.in 1.12 -> 1.13

--- l2.h.in      2001/10/09 14:03:04     1.12
+++ l2.h.in      2001/10/09 15:34:55     1.13
@@ -216,8 +216,8 @@
 
 /* utility operations */
 l2_result_t   l2_util_setparams    (l2_param_t p[], const char *fmt, va_list ap);
-l2_result_t   l2_util_l2s          (char *string,       size_t maxlen, l2_level_t  level);
-l2_result_t   l2_util_s2l          (const char *string, size_t maxlen, l2_level_t *level);
+l2_result_t   l2_util_l2s          (char *string,       size_t maxlen, int sep, unsigned int  levelmask);
+l2_result_t   l2_util_s2l          (const char *string, size_t maxlen, int sep, unsigned int *levelmask);
 l2_result_t   l2_util_fmt_string   (l2_context_t *, const char, const char *, char *, size_t, size_t *, va_list *);
 l2_result_t   l2_util_fmt_dump     (l2_context_t *, const char, const char *, char *, size_t, size_t *, va_list *);
 


ossp-pkg/l2/l2_ch_prefix.c 1.14 -> 1.15

--- l2_ch_prefix.c       2001/10/09 14:03:04     1.14
+++ l2_ch_prefix.c       2001/10/09 15:34:55     1.15
@@ -101,7 +101,7 @@
             bSubst = FALSE;
             switch (*(cpSC+1)) {
                 case 'L': {
-                    if ((rv = l2_util_l2s(caBuf, sizeof(caBuf), level)) != L2_OK)
+                    if ((rv = l2_util_l2s(caBuf, sizeof(caBuf), '\0', level)) != L2_OK)
                         return rv;
                     bSubst = TRUE;
                     break;


ossp-pkg/l2/l2_ut_level.c 1.4 -> 1.5

--- l2_ut_level.c        2001/10/09 14:03:04     1.4
+++ l2_ut_level.c        2001/10/09 15:34:55     1.5
@@ -48,36 +48,37 @@
     { 0,                 NULL       }
 };
 
-l2_result_t l2_util_l2s(char *string, size_t maxlen, l2_level_t level)
+l2_result_t l2_util_l2s(char *string, size_t maxlen, int sep, unsigned int levelmask)
 {
-    int len, i, j, l;
+    char hexbuf[2+(sizeof(unsigned int)*2)+1];
+    int len;
+    int i;
+    int l;
 
+    len = maxlen;
     string[0] = '\0';
-    len = i = j = l = 0;
-    for (i = 0; l2s_table[i].level != NULL; i++) { /* loop through levels    */
-        if (level & l2s_table[i].level) {
-            if (j != 0)
-                return L2_ERR_ARG; /* level has matched more than one string */
-            else
-                j = i; /* index the given level to its corresponding string  */
+    for (i = 0; l2s_table[i].level != NULL; i++) {
+        if (levelmask & l2s_table[i].level) {
+            levelmask &= ~(l2s_table[i].level);
+            l = strlen(l2s_table[i].string) + 1;
+            if (len < l)
+                return L2_ERR_MEM;
+            sprintf(string+(maxlen-len), "%s%c", l2s_table[i].string, sep);
+            len -= l;
         }
-
-        l = strlen(l2s_table[i].string);
-        if (l > len) 
-            len = l; /* len is the size of the largest level string          */
     }
-
-    if (len + 1 > maxlen)
-        return L2_ERR_MEM;
-    else
-        sprintf(string, "%s", l2s_table[j].string);
-
-    for (i = 0; string[i] != '\0'; i++) /* process string to dynamically pad */
-    ;                                   /* with spaces in order to line up   */
-    while (i < len){                    /* small level string text with the  */
-        string[i++] = ' ';              /* larger ones                       */
+    if (levelmask != 0) {
+        sprintf(hexbuf, "0x%x", levelmask);
+        l = strlen(hexbuf) + 1;
+        if (len < l)
+            return L2_ERR_MEM;
+        sprintf(string+(maxlen-len), "%s%c", hexbuf, sep);
+        len -= l;
     }
-    string[i] = '\0';                   /* don't forget to put back the EOL  */
+    /* remove trailing comma */
+    if ((maxlen-len) > 0)
+        string[(maxlen-len)-1] = '\0'; 
+
     return L2_OK;
 }
 
@@ -105,26 +106,40 @@
     return 0;
 }
 
-l2_result_t l2_util_s2l(const char *string, size_t maxlen, l2_level_t *level)
+l2_result_t l2_util_s2l(const char *string, size_t maxlen, int sep, unsigned int *levelmask)
 {
+    const char *cpB;
+    const char *cpE;
     int bFound;
     int i;
 
-    *level = 0;
-    bFound = 0;
-    for (i = 0; l2s_table[i].level != NULL; i++) {
-        if (strcasecmp(string, l2s_table[i].string) == 0) {
-            *level = l2s_table[i].level;
-            bFound = 1;
+    *levelmask = 0;
+    cpE = string;
+    while (1) {
+        cpB = cpE;
+        if (cpB >= (string+maxlen))
+            break;
+        if ((int)(*cpB) == sep)
+            cpB++;
+        for (cpE = cpB; cpE < (string+maxlen) && (int)(*cpE) != sep; cpE++)
+            ;
+        if (cpE > (string+maxlen))
             break;
+        bFound = 0;
+        for (i = 0; l2s_table[i].level != NULL; i++) {
+            if (strncasecmp(cpB, l2s_table[i].string, cpE-cpB) == 0) {
+                *levelmask |= l2s_table[i].level;
+                bFound = 1;
+                break;
+            }
         }
-    }
-    if (!bFound) {
-        if (strncasecmp(string, "0x", 2) == 0 && myishexnumber((int)(*(string+2)))) {
-            *level = hexval(string+2, string + strlen(string));
+        if (!bFound) {
+            if ((cpE > cpB+2) && strncasecmp(cpB, "0x", 2) == 0 && myishexnumber((int)(*(cpB+2)))) {
+                *levelmask |= hexval(cpB+2, cpE);
+            }
+            else
+                return L2_ERR_ARG;
         }
-        else
-            return L2_ERR_ARG;
     }
     return L2_OK;
 }

CVSTrac 2.0.1