From: erg Date: Wed, 18 Aug 2010 17:35:17 +0000 (+0000) Subject: Fix bug in scanning - flex rules accepted \. when it should only accept \ after X-Git-Tag: LAST_LIBGRAPH~32^2~1229 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c8517f19483190107497a51f66140590314851b3;p=graphviz Fix bug in scanning - flex rules accepted \. when it should only accept \ after checking for \newline and \"; make cgraph canonical string same as graph - in particular, don't put in escaped newlines in the middle of words. --- diff --git a/lib/cgraph/cghdr.h b/lib/cgraph/cghdr.h index 2ee4053d9..a5134a143 100644 --- a/lib/cgraph/cghdr.h +++ b/lib/cgraph/cghdr.h @@ -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 '%' diff --git a/lib/cgraph/scan.l b/lib/cgraph/scan.l index 25448e106..ed4cc20ad 100644 --- a/lib/cgraph/scan.l +++ b/lib/cgraph/scan.l @@ -183,7 +183,7 @@ ID ({NAME}|{NUMBER}) ["] BEGIN(INITIAL); endstr(); return (T_qatom); [\\]["] addstr ("\""); [\\][\n] line_num++; /* ignore escaped newlines */ -([^"\\]*|[\\].) addstr(yytext); +([^"\\]*|[\\]) addstr(yytext); [<] BEGIN(hstring); html_nest = 1; beginstr(); [>] html_nest--; if (html_nest) addstr(yytext); else {BEGIN(INITIAL); endstr_html(); return (T_qatom);} [<] html_nest++; addstr(yytext); diff --git a/lib/cgraph/write.c b/lib/cgraph/write.c index 4281be2ca..b6bf2ec78 100644 --- a/lib/cgraph/write.c +++ b/lib/cgraph/write.c @@ -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++ = '\"';