OSSP CVS Repository

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

Check-in Number: 2248
Date: 2002-Jul-05 20:32:37 (local)
2002-Jul-05 18:32:37 (UTC)
User:rse
Branch:
Comment: Add line-continuation support and make export output correctly quote the tokens.
Tickets:
Inspections:
Files:
ossp-pkg/cfg/cfg_syn.c      1.7 -> 1.8     31 inserted, 3 deleted
ossp-pkg/cfg/cfg_syn_scan.l      1.3 -> 1.4     16 inserted, 1 deleted
ossp-pkg/cfg/cfg_test.c      1.3 -> 1.4     1 inserted, 1 deleted
ossp-pkg/cfg/sample2.cfg      1.2 -> 1.3     5 inserted, 2 deleted

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;
 }
 


ossp-pkg/cfg/cfg_syn_scan.l 1.3 -> 1.4

--- cfg_syn_scan.l       2002/07/05 15:11:20     1.3
+++ cfg_syn_scan.l       2002/07/05 18:32:37     1.4
@@ -139,6 +139,9 @@
     }
     *cpStr++ = result;
 }
+<SS_DQ>\\\n[ \t]* {
+    /* no-op */
+}
 <SS_DQ>\\n { *cpStr++ = '\n'; }
 <SS_DQ>\\r { *cpStr++ = '\r'; }
 <SS_DQ>\\t { *cpStr++ = '\t'; }
@@ -167,6 +170,9 @@
     BEGIN(INITIAL);
     return T_STRING;
 }
+<SS_SQ>\\\n[ \t]* {
+    /* no-op */
+}
 <SS_SQ>\\(.|\n) {
     *cpStr++ = yytext[1];
 }
@@ -200,6 +206,9 @@
         *cpStr++ = yytext[1];
     }
 }
+<SS_FQ>\\\n[ \t]* {
+    /* no-op */
+}
 <SS_FQ>[^\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~] {
     char *cp = yytext;
     while (*cp != '\0')
@@ -228,12 +237,18 @@
 "}" { return T_CLOSE; }
 
     /* plain text word */
+\\\n[ \t]* {
+    /* no-op */
+}
 (.|\n) {
     cpStr = caStr;
     *cpStr++ = yytext[0];
     BEGIN(SS_PT);
 }
-<SS_PT>[^ \t\n;{}"']+ {
+<SS_PT>\\\n[ \t]* {
+    /* no-op */
+}
+<SS_PT>[^ \t\n;{}\\"']+ {
     char *cp = yytext;
     while (*cp != '\0')
         *cpStr++ = *cp++;


ossp-pkg/cfg/cfg_test.c 1.3 -> 1.4

--- cfg_test.c   2002/07/05 15:32:42     1.3
+++ cfg_test.c   2002/07/05 18:32:37     1.4
@@ -33,7 +33,7 @@
     else {
         cfg_syn_export(NULL, node, &buf_ptr);
         cfg_syn_destroy(NULL, node);
-        fprintf(stdout, "%s\n", buf_ptr);
+        fprintf(stdout, "%s", buf_ptr);
     }
 
     return 0;


ossp-pkg/cfg/sample2.cfg 1.2 -> 1.3

--- sample2.cfg  2002/07/05 14:33:10     1.2
+++ sample2.cfg  2002/07/05 18:32:37     1.3
@@ -1,11 +1,14 @@
 
 foo;
-bar1 q{ f{o}o } 'foo;' "bar2 bar2b";
+bar1 q{ f{o}o } 'foo;' "bar2 bar2b" "foo\nbar" q(foo
+bar
+quux);
 quux1 { 
     quux1a; 
     quux1b;
 } quux2 {
-    quux2a;
+    q(quu\
+    x2a);
     quux2b;
 };
 

CVSTrac 2.0.1