From 3cdbfb9281ab41b11154bee7b639fc1cafb4b282 Mon Sep 17 00:00:00 2001 From: erg Date: Wed, 9 Feb 2005 04:52:06 +0000 Subject: [PATCH] Fix error reporting in case libexpat not available; make some formatting changes in utils.c. --- lib/common/htmllex.c | 6 ++++-- lib/common/htmllex.h | 2 +- lib/common/htmlparse.y | 30 +++++++++++++++++++++++++----- lib/common/htmltable.c | 6 ++---- lib/common/htmltable.h | 1 + lib/common/input.c | 2 +- lib/common/utils.c | 26 +++++++++++++------------- 7 files changed, 47 insertions(+), 26 deletions(-) diff --git a/lib/common/htmllex.c b/lib/common/htmllex.c index 461556378..aeb037151 100644 --- a/lib/common/htmllex.c +++ b/lib/common/htmllex.c @@ -546,7 +546,7 @@ static void characterData(void *user, const char *s, int length) } #endif -void initHTMLlexer(char *src, agxbuf * xb) +int initHTMLlexer(char *src, agxbuf * xb) { #ifdef HAVE_LIBEXPAT state.xb = xb; @@ -563,13 +563,15 @@ void initHTMLlexer(char *src, agxbuf * xb) (XML_StartElementHandler) startElement, endElement); XML_SetCharacterDataHandler(state.parser, characterData); + return 0; #else static int first; - if (first) { + if (!first) { agerr(AGWARN, "Not built with libexpat. Table formatting is not available.\n"); first++; } + return 1; #endif } diff --git a/lib/common/htmllex.h b/lib/common/htmllex.h index 4fec016c1..b01221c9f 100644 --- a/lib/common/htmllex.h +++ b/lib/common/htmllex.h @@ -23,7 +23,7 @@ extern "C" { #include - extern void initHTMLlexer(char *, agxbuf *); + extern int initHTMLlexer(char *, agxbuf *); extern int htmllex(); extern int htmllineno(); extern int clearHTMLlexer(); diff --git a/lib/common/htmlparse.y b/lib/common/htmlparse.y index 76bf32103..2152da8f1 100644 --- a/lib/common/htmlparse.y +++ b/lib/common/htmlparse.y @@ -176,7 +176,7 @@ mkText (const char* lastl) lp->just = 'n'; } - dtclear (lines); + if (lines) dtclear (lines); return tp; } @@ -427,11 +427,24 @@ image : T_img T_end_img { $$ = $1; } %% +htmllabel_t* +simpleHTML (char* txt) +{ + htmltxt_t* tobj = mkText (txt); + htmllabel_t* l = mkLabel(tobj,HTML_TEXT); + return l; +} + +/* parseHTML: + * Return parsed label or NULL if failure. + * Set warn to 0 on success; 1 for warning message; 2 if no expat. + */ htmllabel_t* parseHTML (char* txt, int* warn) { unsigned char buf[SMALLBUF]; agxbuf str; + htmllabel_t* l; HTMLstate.tblstack = 0; HTMLstate.lbl = 0; @@ -439,13 +452,20 @@ parseHTML (char* txt, int* warn) agxbinit (&str, SMALLBUF, buf); HTMLstate.str = &str; - initHTMLlexer (txt, &str); - yyparse(); - *warn = clearHTMLlexer (); + if (initHTMLlexer (txt, &str)) {/* failed: no libexpat - give up */ + *warn = 2; + l = NULL; + } + else { + yyparse(); + *warn = clearHTMLlexer (); + l = HTMLstate.lbl; + } dtclose (HTMLstate.lines); + HTMLstate.lines = NULL; agxbfree (&str); - return HTMLstate.lbl; + return l; } diff --git a/lib/common/htmltable.c b/lib/common/htmltable.c index b9c442292..5c7281ca3 100644 --- a/lib/common/htmltable.c +++ b/lib/common/htmltable.c @@ -1418,7 +1418,7 @@ static char *getPenColor(void *obj) } /* make_html_label: - * Return 1 if problem parsing HTML. In this case, use object name. + * Return non-zero if problem parsing HTML. In this case, use object name. */ int make_html_label(textlabel_t * lp, void *obj) { @@ -1432,9 +1432,7 @@ int make_html_label(textlabel_t * lp, void *obj) agxbuf xb; unsigned char buf[SMALLBUF]; agxbinit(&xb, SMALLBUF, buf); - lbl = parseHTML(nameOf(obj, &xb), &rv); - assert(lbl); - rv = 1; + lbl = simpleHTML(nameOf(obj, &xb)); agxbfree(&xb); } diff --git a/lib/common/htmltable.h b/lib/common/htmltable.h index f01e2fe15..b1157b974 100644 --- a/lib/common/htmltable.h +++ b/lib/common/htmltable.h @@ -134,6 +134,7 @@ extern "C" { } pitem; extern htmllabel_t *parseHTML(char *, int *); + extern htmllabel_t *simpleHTML(char *); extern int make_html_label(textlabel_t * lp, void *obj); extern void emit_html_label(GVC_t * gvc, htmllabel_t * lp, diff --git a/lib/common/input.c b/lib/common/input.c index 27225d934..ecda6530f 100644 --- a/lib/common/input.c +++ b/lib/common/input.c @@ -647,7 +647,7 @@ void do_graph_label(graph_t * sg) "fontcolor"), DEFAULT_COLOR), sg); if (html) { - if (make_html_label(GD_label(sg), sg)) + if (make_html_label(GD_label(sg), sg) == 1) agerr(AGPREV, "in label of graph %s\n", sg->name); } diff --git a/lib/common/utils.c b/lib/common/utils.c index 64c5efd57..2497d4bec 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -814,7 +814,7 @@ void common_init_node(node_t * n) late_nnstring(n, N_fontcolor, DEFAULT_COLOR), n->graph); if (html) { - if (make_html_label(ND_label(n), n)) + if (make_html_label(ND_label(n), n) == 1) agerr(AGPREV, "in label of node %s\n", n->name); } ND_shape(n) = @@ -868,15 +868,15 @@ initFontLabelEdgeAttr(edge_t * e, struct fontinfo *fi, static boolean wantClip(edge_t *e, attrsym_t* sym) { - char *str; - boolean rv = TRUE; + char *str; + boolean rv = TRUE; - if (sym) { /* mapbool isn't a good fit, because we want "" to mean TRUE */ - str = agxget(e,sym->index); - if (str && str[0]) rv = mapbool(str); - else rv = TRUE; - } - return rv; + if (sym) { /* mapbool isn't a good fit, because we want "" to mean TRUE */ + str = agxget(e,sym->index); + if (str && str[0]) rv = mapbool(str); + else rv = TRUE; + } + return rv; } /*chkPort: @@ -919,7 +919,7 @@ int common_init_edge(edge_t * e) fi.fontsize, fi.fontname, fi.fontcolor, e->tail->graph); if (html) { - if (make_html_label(ED_label(e), e)) + if (make_html_label(ED_label(e), e) == 1) edgeError(e, "label"); } GD_has_labels(e->tail->graph) |= EDGE_LABEL; @@ -940,7 +940,7 @@ int common_init_edge(edge_t * e) lfi.fontsize, lfi.fontname, lfi.fontcolor, e->tail->graph); if (html) { - if (make_html_label(ED_head_label(e), e)) + if (make_html_label(ED_head_label(e), e) == 1) edgeError(e, "head label"); } GD_has_labels(e->tail->graph) |= HEAD_LABEL; @@ -957,7 +957,7 @@ int common_init_edge(edge_t * e) lfi.fontsize, lfi.fontname, lfi.fontcolor, e->tail->graph); if (html) { - if (make_html_label(ED_tail_label(e), e)) + if (make_html_label(ED_tail_label(e), e) == 1) edgeError(e, "tail label"); } GD_has_labels(e->tail->graph) |= TAIL_LABEL; @@ -1032,7 +1032,7 @@ pointf flip_ptf(pointf p, int rankdir) return p; } -/* invflip_ptf: +/* invflip_pt: * Transform point => * LR - rotate cw by 90 * BT - reflect across x axis -- 2.40.0