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