OSSP CVS Repository

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

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

--- cfg_syn.c    2002/07/05 17:21:40     1.7
+++ cfg_syn.c    2002/07/05 18:32:37     1.8
@@ -208,10 +208,38 @@
 
 static void export_token(export_t *ctx, const char *token)
 {
-    if (strcspn(token, " {};\\") != strlen(token))
-        export_format(ctx, "\"%s\"", token);
-    else
+    const char *cp;
+    char *out;
+    int n;
+
+    if (strcspn(token, " \n\r\t\b\f;{}\\\"'") == strlen(token))
+        /* plain text token */
         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;
+            }
+            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 = "";
+                }
+                export_format(ctx, "%s", out);
+                cp++;
+            }
+        }
+        export_format(ctx, "\"");
+    }
     return;
 }
 

CVSTrac 2.0.1