From: erg Date: Wed, 11 Aug 2010 16:10:38 +0000 (+0000) Subject: Add html() function to create HTML-like strings X-Git-Tag: LAST_LIBGRAPH~32^2~1231 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=192f34b9e015a0f85558a7bec17ea11764a43391;p=graphviz Add html() function to create HTML-like strings --- diff --git a/cmd/gvpr/gvpr.1 b/cmd/gvpr/gvpr.1 index 9ab0ffd35..32306c9f1 100644 --- a/cmd/gvpr/gvpr.1 +++ b/cmd/gvpr/gvpr.1 @@ -663,6 +663,15 @@ returns a version of \fIs\fP with the alphabetic characters converted to lower-c returns a version of \fIs\fP appropriate to be used as an identifier in a dot file. .TP +\fBhtml\fP(\fIg\fP : \fBgraph_t\fP, \fIs\fP : \fBstring\fP) : \fBstring\fP +returns a ``magic'' version of \fIs\fP as an HTML string. This will typically be +used to attach an HTML-like label to a graph object. Note that the returned string +lives in \fIg\fP. In particular, it will be freed when \fIg\fP is closed, and to +act as an HTML string, it has to be used with an object of \fIg\fP. In addition, +note that the +angle bracket quotes should not be part of \fIs\fP. These will be added if +\fIg\fP is written in concrete DOT format. +.TP \fBxOf\fP(\fIs\fP : \fBstring\fP) : \fBstring\fP returns the string "\fIx\fP" if \fIs\fP has the form "\fIx\fP,\fIy\fP", where both \fIx\fP and \fIy\fP are numeric. @@ -1073,7 +1082,7 @@ Computes the degrees of nodes with edges. Colon\(hyseparated list of directories to be searched to find the file specified by the \-f option. .SH BUGS AND WARNINGS -Scripts should be careful deleting nodes during \fBN{}\fP and \fBE{}\fp +Scripts should be careful deleting nodes during \fBN{}\fP and \fBE{}\fP blocks using BFS and DFS traversals as these rely on stacks and queues of nodes. .PP diff --git a/lib/gvpr/actions.c b/lib/gvpr/actions.c index 7071e5efb..ada9b74f6 100644 --- a/lib/gvpr/actions.c +++ b/lib/gvpr/actions.c @@ -793,6 +793,14 @@ char *toUpper(Expr_t * pgm, char *s, Sfio_t* tmps) return exstring(pgm, sfstruse(tmps)); } +/* toHtml: + * Create a string marked as HTML + */ +char *toHtml(Agraph_t* g, char *arg) +{ + return agstrdup_html (g, arg); +} + /* canon: * Canonicalize a string for printing. */ @@ -806,6 +814,7 @@ char *canon(Expr_t * pgm, char *arg) return p; } + #include #ifdef WIN32 #include "compat.h" diff --git a/lib/gvpr/actions.h b/lib/gvpr/actions.h index f38051163..adc9fe729 100644 --- a/lib/gvpr/actions.h +++ b/lib/gvpr/actions.h @@ -48,6 +48,7 @@ extern "C" { extern int closeFile(Expr_t *, int); extern char *readLine(Expr_t *, int); extern char *canon(Expr_t * pgm, char *); + extern char *toHtml(Agraph_t*, char *); extern char *toLower(Expr_t * pgm, char *, Sfio_t*); extern char *toUpper(Expr_t * pgm, char *, Sfio_t*); extern int deleteObj(Agraph_t * g, Agobj_t * obj); diff --git a/lib/gvpr/compile.c b/lib/gvpr/compile.c index a7f888158..a85911fb0 100644 --- a/lib/gvpr/compile.c +++ b/lib/gvpr/compile.c @@ -1379,6 +1379,15 @@ getval(Expr_t * pgm, Exnode_t * node, Exid_t * sym, Exref_t * ref, case F_canon: v.string = canon(pgm, args[0].string); break; + case F_html: + gp = INT2PTR(Agraph_t *, args[0].integer); + if (gp) { + v.string = toHtml(gp, args[1].string); + } else { + error(ERROR_WARNING, "NULL graph passed to html()"); + v.string = 0; + } + break; case F_tolower: v.string = toLower(pgm, args[0].string, state->tmp); break; diff --git a/lib/gvpr/gprdata b/lib/gvpr/gprdata index 230a6b737..cf1d4bb4f 100644 --- a/lib/gvpr/gprdata +++ b/lib/gvpr/gprdata @@ -99,6 +99,7 @@ F_xof "xOf" FUNCTION S|A(1,S) F_yof "yOf" FUNCTION S|A(1,S) F_llof "llOf" FUNCTION S|A(1,S) F_urof "urOf" FUNCTION S|A(1,S) +F_html "html" FUNCTION S|A(1,G)|A(2,S) F_canon "canon" FUNCTION S|A(1,S) F_get "aget" FUNCTION S|A(1,O)|A(2,S) F_set "aset" FUNCTION I|A(1,O)|A(2,S)|A(3,S)