44#define MIN(a,b) ((a)<(b)?(a):(b))
45#define MAX(a,b) ((a)>(b)?(a):(b))
52#define BITS_PER_BYTE 8
55 return (
void*)(intptr_t)i;
59 return (
long long)(intptr_t)p;
62static int iofread(
void *chan,
char *buf,
int bufsize)
66 return (
int)
read(fileno(fp), buf, bufsize);
71 return fputs(
str, chan);
131 if (sscanf(pt,
"%lf,%lf,%lf,%lf", &x, &y, &u, &v) == 4) {
133 p = strchr(p + 1,
',');
135 size_t len = (size_t)(p - pt);
156 if (sscanf(pt,
"%lf,%lf", &x, &y) == 2) {
159 size_t len = (size_t)(p - pt);
188 if (sscanf(
ps,
"%lf,%lf", &p[0], &p[1]) == 2) {
196#if defined(DEBUG) && DEBUG > 1
197static char *symName(
Expr_t * ex,
int op)
203 int bytes = vsnprintf(
NULL, 0,
"<unknown (%d)>", op);
205 fprintf(stderr,
"%s: vsnprintf failure\n", __func__);
210 char *
s =
vmalloc(ex->ve, (
size_t)bytes + 1);
214 snprintf(
s, (
size_t)bytes + 1,
"<unknown (%d)>", op);
236 while ((c = *args++)) {
290 exerror(
"null reference %s in expression %s.%s",
297 switch (
ref->symbol->index) {
315 if (!objp && !(objp =
state->curobj)) {
316 exerror(
"Current object $ not defined");
325 if (!objp && !(objp =
state->curobj)) {
326 exerror(
"Current object $ not defined");
332 exerror(
"tail of non-edge %p", objp);
335 exerror(
"%s : illegal reference",
ref->symbol->name);
349 unsigned char* p = name;
362 exerror(
"Cannot assign to pseudo-graph attribute %s", name);
366 exerror(
"Cannot assign to pseudo-node attribute %s", name);
370 exerror(
"Cannot assign to pseudo-edge attribute %s", name);
386 return agxset(objp, gsym, val);
424 if (sym->
lex ==
ID) {
425 switch (sym->
index) {
452 exerror(
"indegree of non-node");
460 exerror(
"outdegree of non-node");
477 exerror(
"x coordinate of non-node");
486 exerror(
"x coordinate of non-node");
494 exerror(
"parent of non-graph");
505 exerror(
"n_edges of non-graph");
513 exerror(
"n_nodes of non-graph");
521 exerror(
"directed of non-graph");
529 exerror(
"strict of non-graph");
544 "Using value of uninitialized %s attribute \"%s\" of \"%s\"",
559 if (n >=
state->argc) {
560 exerror(
"program references ARGV[%d] - undefined", n);
563 return (
state->argv[n]);
611 exerror(
"Unknown kind \"%s\" passed to %s()", k, fn);
623 char* fn = (name ?
"nxtAttr" :
"fstAttr");
630 exerror(
"Third argument \"%s\" in nxtAttr() must be the name of an existing attribute", name);
638 if (sym)
return sym->
name;
662 void *env,
int elt,
Exdisc_t * disc)
680 switch (sym->
index) {
682 gp =
openG(args[0].
string,
xargs(args[1].
string));
838 objp =
int2ptr(args[1].integer);
861 objp =
int2ptr(args[0].integer);
863 exerror(
"NULL object passed to kindOf()");
865 }
else switch (
AGTYPE(objp)) {
1000 gp =
int2ptr(args[0].integer);
1001 np =
int2ptr(args[1].integer);
1013 ep =
int2ptr(args[0].integer);
1023 gp =
int2ptr(args[0].integer);
1024 ep =
int2ptr(args[1].integer);
1036 np =
int2ptr(args[0].integer);
1046 gp =
int2ptr(args[0].integer);
1047 np =
int2ptr(args[1].integer);
1059 ep =
int2ptr(args[0].integer);
1069 gp =
int2ptr(args[0].integer);
1070 ep =
int2ptr(args[1].integer);
1082 np =
int2ptr(args[0].integer);
1092 gp =
int2ptr(args[0].integer);
1093 np =
int2ptr(args[1].integer);
1105 ep =
int2ptr(args[0].integer);
1106 np =
int2ptr(args[1].integer);
1119 gp =
int2ptr(args[0].integer);
1120 ep =
int2ptr(args[1].integer);
1121 np =
int2ptr(args[2].integer);
1136 gp =
int2ptr(args[0].integer);
1137 objp =
int2ptr(args[1].integer);
1145 gp =
int2ptr(args[0].integer);
1146 objp =
int2ptr(args[1].integer);
1154 gp =
int2ptr(args[0].integer);
1156 gp =
cloneG(gp, args[1].
string);
1164 objp =
int2ptr(args[0].integer);
1165 objp1 =
int2ptr(args[1].integer);
1166 if (!(objp && objp1)) {
1173 gp =
int2ptr(args[0].integer);
1183 gp =
int2ptr(args[0].integer);
1191 gp =
int2ptr(args[0].integer);
1203 gp =
int2ptr(args[0].integer);
1224 gp =
int2ptr(args[0].integer);
1233 gp =
int2ptr(args[0].integer);
1242 gp =
int2ptr(args[0].integer);
1243 objp =
int2ptr(args[1].integer);
1253 }
else if (objp ==
state->curobj) {
1260 gp =
int2ptr(args[0].integer);
1268 gp =
int2ptr(args[0].integer);
1277 gp =
int2ptr(args[0].integer);
1286 v.
integer = atoi(args[0].
string);
1292 v.
floating = sqrt(args[0].floating);
1295 v.
floating = cos(args[0].floating);
1298 v.
floating = sin(args[0].floating);
1301 v.
floating = atan2(args[0].floating, args[1].floating);
1304 v.
floating = exp(args[0].floating);
1307 v.
floating = pow(args[0].floating, args[1].floating);
1310 v.
floating = log(args[0].floating);
1313 v.
floating =
MIN(args[0].floating, args[1].floating);
1316 v.
floating =
MAX(args[0].floating, args[1].floating);
1319 v.
integer = system(args[0].
string);
1323 objp =
int2ptr(args[0].integer);
1324 char *name = args[1].
string;
1326 exerror(
"NULL object passed to aget()/hasAttr()");
1329 exerror(
"NULL name passed to aget()/hasAttr()");
1334 if (sym->
index == F_hasattr)
1341 "Using value of %s uninitialized attribute \"%s\" of \"%s\" in aget()",
1351 objp =
int2ptr(args[0].integer);
1356 char* name = args[1].
string;
1357 char* value = args[2].
string;
1372 gp =
int2ptr(args[0].integer);
1375 char* name = args[2].
string;
1376 char* value = args[3].
string;
1398 gp =
int2ptr(args[0].integer);
1409 exerror(
"NULL graph passed to fstAttr()");
1416 gp =
int2ptr(args[0].integer);
1419 char* name = args[2].
string;
1428 else if (sym->
index == F_isattr) {
1431 else if (sym->
index == F_nxtattr) {
1449 gp =
int2ptr(args[0].integer);
1461 v.
string =
colorx(pgm, args[0].
string, args[1].
string);
1464 if (args[0].
string) {
1466 v.
integer = strcmp(args[0].
string,args[1].
string);
1469 }
else if (args[1].
string)
1490 v.
integer = strlen(args[0].
string);
1499 const size_t m =
match(args[0].
string, args[1].
string);
1521 switch (sym->
index) {
1541 switch (sym->
index) {
1581 objp =
state->curobj;
1584 exerror(
"current object $ not defined as reference for %s",
1591 if (
lookup(pgm, objp, sym, &v)) {
1604#define MINTYPE (LAST_M+1)
1633 }
else if (MINNAME <= sym->index && sym->
index <=
MAXNAME) {
1634 switch (sym->
index) {
1643 error(1,
"unexpected value %lld assigned to %s : ignored",
1652 error(1,
"cannot set $tvroot, node %s not in $G : ignored",
1662 error(1,
"cannot set $tvnext, node %s not in $G : ignored",
1669 state->name_used = 0;
1677 objp =
state->curobj;
1680 exerror(
"current object $ undefined in expression %s",
1693#define haveGraph (1 <= codePhase && codePhase <= 4)
1694#define haveTarget (2 <= codePhase && codePhase <= 4)
1695#define inWalk (2 <= codePhase && codePhase <= 3)
1711 switch (sym->
type) {
1734 exerror(
"unknown dynamic type %" PRIdMAX
" of symbol %s",
1741 switch (sym->
index) {
1748 (
"keyword %s cannot be used in BEGIN/END statements",
1754 (
"keyword %s cannot be used in BEGIN/BEG_G/END statements",
1768 (
"undeclared, unmodified names like \"%s\" cannot be\nused in BEGIN and END statements",
1774 exerror(
"unexpected symbol in typeChk: name %s, lex %" PRIdMAX, sym->
name,
1775 (intmax_t)sym->
lex);
1782 if (!(dom & intype))
1819 switch (sym->
index) {
1896 if (l->
type == T_tvtyp) {
1900 if (r->
type != T_tvtyp)
1946 if (r && r->
type == T_tvtyp)
2006 if (!strcmp(sfx,
"flat")) {
2008 }
else if (!strcmp(sfx,
"ne")) {
2010 }
else if (!strcmp(sfx,
"en")) {
2012 }
else if (!strcmp(sfx,
"bfs")) {
2014 }
else if (!strcmp(sfx,
"dfs")) {
2016 }
else if (!strcmp(sfx,
"fwd")) {
2018 }
else if (!strcmp(sfx,
"rev")) {
2020 }
else if (!strcmp(sfx,
"postdfs")) {
2022 }
else if (!strcmp(sfx,
"postfwd")) {
2024 }
else if (!strcmp(sfx,
"postrev")) {
2026 }
else if (!strcmp(sfx,
"prepostdfs")) {
2028 }
else if (!strcmp(sfx,
"prepostfwd")) {
2030 }
else if (!strcmp(sfx,
"prepostrev")) {
2033 exerror(
"illegal string \"%s\" for type tvtype_t",
s);
2035 exerror(
"illegal string \"%s\" for type tvtype_t",
s);
2076 s =
"TV_prepostdfs";
2079 s =
"TV_prepostfwd";
2082 s =
"TV_prepostrev";
2085 exerror(
"Unexpected value %lld for type tvtype_t", v);
2104 if (x->
type == T_tvtyp) {
2137 if (
type == T_obj && x->
type <= T_obj)
2144 }
else if (x->
type == T_obj) {
2161 if (!objp ||
isedge(objp))
2167 if (x->
type == T_tvtyp) {
2180 exerror(
"Integer value %lld not legal for type tvtype_t",
2188 if (
type == T_tvtyp) {
2198 if (!arg && ret == 0)
2208 if (
type <= T_obj) {
2230 "could not create libexp discipline: out of memory");
2263 const char *
lbl,
const char *sfx,
int kind) {
2268 FILE *sf = tmpfile();
2286 src =
"<command line>";
2313 size_t cnt,
const char *
lbl)
2319 for (
size_t i = 0; i <
cnt; i++) {
2337 if (!cs[i].action) {
2355 static const char PREFIX[] =
"_begin_g_";
2370 static const char PREFIX[] =
"_nd";
2386 static const char PREFIX[] =
"_eg";
2408 return (rv | bp->
walks);
2417 return "\n$O = $G;\ninduce($O);\n";
2419 return "\n$O = $G;\n";
2422 return "\ninduce($O);\n";
2432 const char *endg_sfx =
NULL;
2441 "could not create compiled program: out of memory");
2470 for (
size_t i = 0; i < inp->
n_blocks; bp++, i++) {
2480 p->
flags = useflags;
2522 for (
size_t i = 0; i < p->
n_blocks; i++) {
2617 root =
sameG(t, h,
"openEdge",
"tail and head nodes");
2621 if (!
sameG(g, root,
"openEdge",
"subgraph and nodes"))
Agedge_t * isEdge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *key)
int indexOf(char *s1, char *s2)
char * colorx(Expr_t *ex, char *incolor, char *fmt)
Agraph_t * sameG(void *p1, void *p2, char *fn, char *msg)
Agraph_t * freadFile(Expr_t *ex, long long fd)
Agobj_t * cloneO(Agraph_t *g, Agobj_t *obj)
size_t match(char *str, char *pat)
int deleteObj(Agraph_t *g, Agobj_t *obj)
int writeFile(Agraph_t *g, char *f)
int fwriteFile(Expr_t *ex, Agraph_t *g, long long fd)
long rindexOf(char *s1, char *s2)
int sfioWrite(Agraph_t *g, FILE *fp)
char * toLower(Expr_t *pgm, char *src)
Agraph_t * cloneG(Agraph_t *g, char *name)
int lockGraph(Agraph_t *g, int v)
char * toHtml(Agraph_t *g, char *arg)
int compare(Agobj_t *l, Agobj_t *r)
Agobj_t * copy(Agraph_t *g, Agobj_t *obj)
Agraph_t * readFile(char *f)
Agraph_t * compOf(Agraph_t *g, Agnode_t *n)
char * toUpper(Expr_t *pgm, char *src)
char * readLine(Expr_t *ex, long long fd)
int closeFile(Expr_t *ex, long long fd)
static void agxbfree(agxbuf *xb)
free any malloced resources
static size_t agxbput(agxbuf *xb, const char *s)
append string s into xb
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
static int agxbputc(agxbuf *xb, char c)
add character to buffer
static char * agxbuse(agxbuf *xb)
static char * agxbdisown(agxbuf *xb)
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
static void addNode(block_t *bp, Agnode_t *n)
abstract graph C library, Cgraph API
static char * deparse(Expr_t *ex, Exnode_t *n, agxbuf *xb)
static tctype typeChkExp(Exref_t *ref, Exid_t *sym)
static char * getDfltAttr(Agraph_t *gp, char *k, char *name)
Agedge_t * openEdge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *key)
static int lookup(Expr_t *pgm, Agobj_t *objp, Exid_t *sym, Extype_t *v)
static Agdesc_t xargs(char *args)
static tctype typeChk(tctype intype, Exid_t *sym)
static int strToTvtype(char *s)
static int iofread(void *chan, char *buf, int bufsize)
Agraph_t * openG(char *name, Agdesc_t desc)
static char * getArg(int n, Gpr_t *state)
Agraph_t * openSubg(Agraph_t *g, char *name)
static char * tvtypeToStr(long long v)
int walksGraph(comp_block *p)
static int stringOf(Expr_t *prog, Exnode_t *x, int arg)
static Agobj_t * deref(Expr_t *pgm, Exnode_t *x, Exref_t *ref, Agobj_t *objp, Gpr_t *state)
static int binary(Exnode_t *l, Exnode_t *ex, Exnode_t *r, int arg)
static char * bbOf(Expr_t *pgm, char *pt, bool getll)
void freeCompileProg(comp_prog *p)
static Exdisc_t * initDisc(Gpr_t *state)
static Extype_t getval(Expr_t *pgm, Exnode_t *node, Exid_t *sym, Exref_t *ref, void *env, int elt, Exdisc_t *disc)
int usesGraph(comp_prog *p)
Agnode_t * openNode(Agraph_t *g, char *name)
static char * typeName(long op)
Agraph_t * readG(FILE *fp)
static char * xyOf(Expr_t *pgm, char *pt, bool getx)
static char * kindToStr(int kind)
static char * nameOf(Expr_t *ex, Agobj_t *obj, agxbuf *tmps)
static int setDfltAttr(Agraph_t *gp, char *k, char *name, char *value)
static Extype_t refval(Expr_t *pgm, Exnode_t *node, Exid_t *sym, Exref_t *ref)
static const char * doFlags(int flags)
static long long ptr2int(const void *p)
static int setattr(Agobj_t *objp, char *name, char *val)
static Exnode_t * compile(Expr_t *prog, char *src, char *input, int line, const char *lbl, const char *sfx, int kind)
static void assignable(Agobj_t *objp, unsigned char *name)
static int convert(Exnode_t *x, long type, int arg)
static int setval(Expr_t *pgm, Exnode_t *x, Exid_t *sym, Exref_t *ref, void *env, Extype_t v)
static char * nxtAttr(Agraph_t *gp, char *k, char *name)
static Extype_t keyval(Extype_t v, long type)
static int ioflush(void *chan)
static Agiodisc_t gprIoDisc
static char * kindOf(Agobj_t *objp)
static void * int2ptr(long long i)
static void checkGuard(Exnode_t *gp, char *src, int line)
static int toKind(char *k, char *fn)
comp_prog * compileProg(parse_prog *inp, Gpr_t *state, int flags)
static case_stmt * mkStmts(Expr_t *prog, char *src, case_info *sp, size_t cnt, const char *lbl)
static int ioputstr(void *chan, const char *str)
static int isedge(Agobj_t *obj)
static int posOf(Agnode_t *np, int idx, double *v)
static int mkBlock(comp_block *bp, Expr_t *prog, char *src, parse_block *inp, size_t i)
void error(int level, const char *s,...)
void errorf(void *handle, void *discipline, int level, const char *s,...)
void setErrorLine(int line)
void setErrorFileLine(char *src, int line)
int exdump(Expr_t *ex, Exnode_t *node, agxbuf *xb)
void exerror(const char *format,...)
char * exstring(Expr_t *ex, char *s)
void * exstralloc(Expr_t *ex, size_t sz)
Exnode_t * exexpr(Expr_t *ex, const char *name, Exid_t *sym, int type)
static NORETURN void graphviz_exit(int status)
Expr_t * exopen(Exdisc_t *disc)
int exisAssign(Exnode_t *)
void(* Exerror_f)(Expr_t *, Exdisc_t *, int, const char *,...)
Exnode_t * exnoncast(Exnode_t *)
void exclose(Expr_t *, int)
int excomp(Expr_t *p, const char *name, int line, FILE *fp, char *prefix)
Extype_t exzero(long int)
static char * typenames[]
static double len(glCompPoint p)
gvprbinding * findBinding(Gpr_t *state, char *fname)
bool validTVT(long long c)
static int cnt(Dict_t *d, Dtlink_t **set)
int agnedges(Agraph_t *g)
int agdegree(Agraph_t *g, Agnode_t *n, int in, int out)
int agnnodes(Agraph_t *g)
size_t graphviz_node_induce(Agraph_t *g, Agraph_t *edgeset)
Agsym_t * agattrsym(void *obj, char *name)
looks up a string attribute for a graph object given as an argument
Agsym_t * agattr(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up attributes of a graph
Agsym_t * agnxtattr(Agraph_t *g, int kind, Agsym_t *attr)
permits traversing the list of attributes of a given type
int agxset(void *obj, Agsym_t *sym, const char *value)
char * agxget(void *obj, Agsym_t *sym)
Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
Agedge_t * agnxtin(Agraph_t *g, Agedge_t *e)
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Agedge_t * agnxtedge(Agraph_t *g, Agedge_t *e, Agnode_t *n)
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Agedge_t * agfstedge(Agraph_t *g, Agnode_t *n)
Agedge_t * agfstin(Agraph_t *g, Agnode_t *n)
int agisdirected(Agraph_t *g)
int agisstrict(Agraph_t *g)
Agraph_t * agopen(char *name, Agdesc_t desc, Agdisc_t *disc)
creates a new graph with the given name and kind
Agraph_t * agread(void *chan, Agdisc_t *disc)
constructs a new graph
Agdesc_t Agdirected
directed
Agnode_t * agnode(Agraph_t *g, char *name, int createflag)
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Agnode_t * agfstnode(Agraph_t *g)
Agraph_t * agraphof(void *obj)
char * agnameof(void *)
returns a string descriptor for the object.
#define AGID(obj)
returns the unique integer ID associated with the object
#define AGTYPE(obj)
returns AGRAPH, AGNODE, or AGEDGE depending on the type of the object
int agcontains(Agraph_t *, void *obj)
returns non-zero if obj is a member of (sub)graph
Agraph_t * agroot(void *obj)
Agrec_t * aggetrec(void *obj, const char *name, int move_to_front)
find record in circular list and do optional move-to-front and lock
void aginit(Agraph_t *g, int kind, const char *rec_name, int rec_size, int move_to_front)
attach new records to objects of specified kind
void * agbindrec(void *obj, const char *name, unsigned int recsize, int move_to_front)
attaches a new record of the given size to the object
int aghtmlstr(const char *)
Agraph_t * agparent(Agraph_t *g)
Agraph_t * agfstsubg(Agraph_t *g)
Agraph_t * agnxtsubg(Agraph_t *subg)
Agraph_t * agsubg(Agraph_t *g, char *name, int cflag)
static void addEdge(edge_t *de, edge_t *e)
static void copyAttr(graph_t *g, graph_t *dg, char *attr)
static FILE * openFile(const char *argv0, const char *name, const char *mode)
static char * canon(graph_t *g, char *s)
#define PRISIZE_T
PRIu64 alike for printing size_t
static int label(Agnode_t *n, int nodecnt, int *edgecnt)
static bool startswith(const char *s, const char *prefix)
does the string s begin with the string prefix?
a generic header of Agraph_s, Agnode_s and Agedge_s
Extype_t(* reff)(Expr_t *, Exnode_t *, Exid_t *, Exref_t *)
Extype_t(* keyf)(Extype_t, long)
int(* convertf)(Exnode_t *, long, int)
int(* binaryf)(Exnode_t *, Exnode_t *, Exnode_t *, int)
Extype_t(* getf)(Expr_t *, Exnode_t *, Exid_t *, Exref_t *, void *, int, Exdisc_t *)
int(* stringof)(Expr_t *, Exnode_t *, int)
int(* setf)(Expr_t *, Exnode_t *, Exid_t *, Exref_t *, void *, Extype_t)
struct _parse_block * next
struct Exdata_u::@87 constant
struct Exdata_u::@90 variable
void * vmalloc(Vmalloc_t *vm, size_t size)