]> granicus.if.org Git - graphviz/commitdiff
Fix bug in scanning - flex rules accepted \. when it should only accept \ after
authorerg <devnull@localhost>
Wed, 18 Aug 2010 17:35:17 +0000 (17:35 +0000)
committererg <devnull@localhost>
Wed, 18 Aug 2010 17:35:17 +0000 (17:35 +0000)
checking for \newline and \";
make cgraph canonical string same as graph - in particular, don't put in escaped newlines
in the middle of words.

lib/cgraph/cghdr.h
lib/cgraph/scan.l
lib/cgraph/write.c

index 2ee4053d90d7f761338cf104448c73c7e6bdc446..a5134a143f27cd4a2cd2128abc2ac359fc3ebfad 100644 (file)
@@ -76,7 +76,7 @@
 #define NILsym                         NIL(Agsym_t*)
 #define NILstr                         NIL(char*)
 
-#define MAX_OUTPUTLINE         80
+#define MAX_OUTPUTLINE         128
 #define        SUCCESS                         0
 #define FAILURE                                -1
 #define LOCALNAMEPREFIX                '%'
index 25448e106a7d4e481b87f66ae639ffb346b68ed9..ed4cc20adbc1d20785597dbc227314e4247443c7 100644 (file)
@@ -183,7 +183,7 @@ ID          ({NAME}|{NUMBER})
 <qstring>["]                   BEGIN(INITIAL); endstr(); return (T_qatom);
 <qstring>[\\]["]               addstr ("\"");
 <qstring>[\\][\n]              line_num++; /* ignore escaped newlines */
-<qstring>([^"\\]*|[\\].)       addstr(yytext);
+<qstring>([^"\\]*|[\\])                addstr(yytext);
 [<]                                            BEGIN(hstring); html_nest = 1; beginstr();
 <hstring>[>]                   html_nest--; if (html_nest) addstr(yytext); else {BEGIN(INITIAL); endstr_html(); return (T_qatom);}
 <hstring>[<]                   html_nest++; addstr(yytext);
index 4281be2ca8c1872cdad74ba1c2d424f5ed78a357..b6bf2ec78e934200363b9b58b499498ae6cd2c30 100644 (file)
@@ -60,6 +60,8 @@ static int strcasecmp(const char *s1, const char *s2)
 }
 #endif
 
+#define is_number_char(c) (isdigit(c) || ((c) == '.'))
+
 /* _agstrcanon:
  * Canonicalize ordinary strings. 
  * Assumes buf is large enough to hold output.
@@ -71,6 +73,7 @@ static char *_agstrcanon(char *arg, char *buf)
     int cnt = 0;
     int needs_quotes = FALSE;
     int maybe_num;
+    int backslash_pending = FALSE;
     static const char *tokenlist[]     /* must agree with scan.l */
        = { "node", "edge", "strict", "graph", "digraph", "subgraph",
        NIL(char *)
@@ -83,7 +86,7 @@ static char *_agstrcanon(char *arg, char *buf)
     p = buf;
     *p++ = '\"';
     uc = *(unsigned char *) s++;
-    maybe_num = (isdigit(uc) || (uc == '.'));
+    maybe_num = is_number_char(uc);
     while (uc) {
        if (uc == '\"') {
            *p++ = '\\';
@@ -91,17 +94,28 @@ static char *_agstrcanon(char *arg, char *buf)
        } else {
            if (!ISALNUM(uc))
                needs_quotes = TRUE;
-           else if (maybe_num && (!isdigit(uc) && (uc != '.')))
+           else if (maybe_num && !is_number_char(uc))
                needs_quotes = TRUE;
        }
        *p++ = (char) uc;
        uc = *(unsigned char *) s++;
        cnt++;
-       if (cnt >= MAX_OUTPUTLINE) {
-           *p++ = '\\';
-           *p++ = '\n';
-           needs_quotes = TRUE;
+       
+        if (uc && backslash_pending && !((is_number_char(p[-1]) || isalpha(p[-1])) && (is_number_char(uc) || isalpha(uc)))) {
+            *p++ = '\\';
+            *p++ = '\n';
+            needs_quotes = TRUE;
+            backslash_pending = FALSE;
            cnt = 0;
+        } else if (uc && (cnt >= MAX_OUTPUTLINE)) {
+            if (!((is_number_char(p[-1]) || isalpha(p[-1])) && (is_number_char(uc) || isalpha(uc)))) {
+               *p++ = '\\';
+               *p++ = '\n';
+               needs_quotes = TRUE;
+               cnt = 0;
+            } else {
+                backslash_pending = TRUE;
+            }
        }
     }
     *p++ = '\"';