OSSP CVS Repository

ossp - Difference in ossp-pkg/cfg/cfg_syn.c versions 1.8 and 1.9
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/cfg/cfg_syn.c 1.8 -> 1.9

--- cfg_syn.c    2002/07/05 18:32:37     1.8
+++ cfg_syn.c    2002/07/05 20:49:58     1.9
@@ -29,6 +29,7 @@
 */
 
 #include <stdio.h>
+#include <ctype.h>
 
 #include "cfg.h"
 #include "cfg_grid.h"
@@ -210,32 +211,40 @@
 {
     const char *cp;
     char *out;
-    int n;
+    int plain;
+    char c;
 
-    if (strcspn(token, " \n\r\t\b\f;{}\\\"'") == strlen(token))
-        /* plain text token */
+    plain = 1;
+    for (cp = token; *cp != '\0'; cp++) {
+        if (   !isprint((int)(*cp)) 
+            || strchr(" \n\r\t\b\f;{}\\\"'", (int)(*cp)) != NULL) {
+            plain = 0;
+            break;
+        }
+    }
+    if (plain)
         export_format(ctx, "%s", token);
     else {
         export_format(ctx, "\"");
         cp = token;
-        while (*cp != '\0') {
-            if ((n = strcspn(cp, "\n\r\t\b\f\\\"")) > 0) {
-                export_format(ctx, "%.*s", n, cp);
-                cp += n;
+        while ((c = *cp++) != '\0') {
+            out = NULL;
+            switch (c) {
+                case '\n': out = "\\n";  break;
+                case '\r': out = "\\r";  break;
+                case '\t': out = "\\t";  break;
+                case '\b': out = "\\b";  break;
+                case '\f': out = "\\f";  break;
+                case '\\': out = "\\\\"; break;
+                case '"' : out = "\\\""; break;
             }
-            else {
-                switch (*cp) {
-                    case '\n': out = "\\n";  break;
-                    case '\r': out = "\\r";  break;
-                    case '\t': out = "\\t";  break;
-                    case '\b': out = "\\b";  break;
-                    case '\f': out = "\\f";  break;
-                    case '\\': out = "\\\\"; break;
-                    case '"' : out = "\\\""; break;
-                    default  : out = "";
-                }
+            if (out != NULL)
                 export_format(ctx, "%s", out);
-                cp++;
+            else {
+                if (isprint((int)c))
+                    export_format(ctx, "%c", c);
+                else
+                    export_format(ctx, "\\x%02x", c);
             }
         }
         export_format(ctx, "\"");

CVSTrac 2.0.1