OSSP CVS Repository

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

Check-in Number: 1121
Date: 2001-Oct-09 16:03:04 (local)
2001-Oct-09 14:03:04 (UTC)
User:ms
Branch:
Comment: Corrected prefix functionality, because channel write operations do not take level masks as input.
Tickets:
Inspections:
Files:
ossp-pkg/l2/l2.h.in      1.11 -> 1.12     2 inserted, 2 deleted
ossp-pkg/l2/l2_ch_prefix.c      1.13 -> 1.14     1 inserted, 1 deleted
ossp-pkg/l2/l2_ut_level.c      1.3 -> 1.4     37 inserted, 52 deleted

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

--- l2.h.in      2001/09/27 07:16:25     1.11
+++ l2.h.in      2001/10/09 14:03:04     1.12
@@ -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, 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_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_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.13 -> 1.14

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


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

--- l2_ut_level.c        2001/09/13 12:19:45     1.3
+++ l2_ut_level.c        2001/10/09 14:03:04     1.4
@@ -48,37 +48,36 @@
     { 0,                 NULL       }
 };
 
-l2_result_t l2_util_l2s(char *string, size_t maxlen, int sep, unsigned int levelmask)
+l2_result_t l2_util_l2s(char *string, size_t maxlen, l2_level_t level)
 {
-    char hexbuf[2+(sizeof(unsigned int)*2)+1];
-    int len;
-    int i;
-    int l;
+    int len, i, j, l;
 
-    len = maxlen;
     string[0] = '\0';
-    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;
+    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  */
         }
+
+        l = strlen(l2s_table[i].string);
+        if (l > len) 
+            len = l; /* len is the size of the largest level string          */
     }
-    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;
-    }
-    /* remove trailing comma */
-    if ((maxlen-len) > 0)
-        string[(maxlen-len)-1] = '\0'; 
 
+    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                       */
+    }
+    string[i] = '\0';                   /* don't forget to put back the EOL  */
     return L2_OK;
 }
 
@@ -106,40 +105,26 @@
     return 0;
 }
 
-l2_result_t l2_util_s2l(const char *string, size_t maxlen, int sep, unsigned int *levelmask)
+l2_result_t l2_util_s2l(const char *string, size_t maxlen, l2_level_t *level)
 {
-    const char *cpB;
-    const char *cpE;
     int bFound;
     int i;
 
-    *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))
+    *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;
             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 ((cpE > cpB+2) && strncasecmp(cpB, "0x", 2) == 0 && myishexnumber((int)(*(cpB+2)))) {
-                *levelmask |= hexval(cpB+2, cpE);
-            }
-            else
-                return L2_ERR_ARG;
+    }
+    if (!bFound) {
+        if (strncasecmp(string, "0x", 2) == 0 && myishexnumber((int)(*(string+2)))) {
+            *level = hexval(string+2, string + strlen(string));
         }
+        else
+            return L2_ERR_ARG;
     }
     return L2_OK;
 }

CVSTrac 2.0.1