63 char *
s = strstr(
s1, s2);
64 return s ==
NULL ? -1 : (int)(
s -
s1);
71 size_t len1 = strlen(
s1);
72 size_t len2 = strlen(s2);
75 assert(len1 <= LONG_MAX);
80 p =
s1 + (len1 - len2);
82 if (strncmp(p, s2, len2) == 0)
106 const int skind =
AGTYPE(src);
107 const int tkind =
AGTYPE(tgt);
114 tsym =
agattr_text(tgtg, tkind, sym->name, sym->defval);
115 char *val =
agxget(src, sym);
141 if (kind !=
AGRAPH && !g) {
142 exerror(
"NULL graph with non-graph object in copy()");
182static int cmppair1(
const void *key,
const void *candidate) {
185 if ((uintptr_t)k > (uintptr_t)c->
key)
187 if ((uintptr_t)k < (uintptr_t)c->
key)
194 bsearch(e, emap->
base,
LIST_SIZE(emap),
sizeof(emap->base[0]), cmppair1);
229 exerror(
"edge (%s,%s)[%s] not found in cloned graph %s",
233 exerror(
"edge (%s,%s) not found in cloned graph %s",
250static int cmppair(
const void *k1,
const void *k2) {
252 return cmppair1(key1->
key, k2);
262 const size_t n_edges = (size_t)
agnedges(src);
277 exerror(
"error cloning edge (%s,%s)[%s] from graph %s",
281 exerror(
"error cloning edge (%s,%s) from graph %s",
301 if (!name || *name ==
'\0')
326 if (kind !=
AGRAPH && !g) {
327 exerror(
"NULL graph with non-graph object in clone()");
366#define CCMARKED(n) (((nData(n))->iu.integer) & 2)
367#define CCMARK(n) (((nData(n))->iu.integer) |= 2)
368#define CCUNMARK(n) (((nData(n))->iu.integer) &= ~2)
398 snprintf(name,
sizeof(name),
"_cc_%d",
id++);
411 root =
sameG(t, h,
"isEdge",
"tail and head node");
420 return agedge(g, t, h, key, 0);
427 if (!
sameG(gp, np,
"addNode", 0))
436 if (!
sameG(gp, ep,
"addEdge", 0))
460 else if (v == 0 && oldv) {
521 exerror(
"NULL string passed to writeG");
524 FILE *fp = fopen(f,
"w");
526 exwarn(
"Could not open %s for writing in writeG", f);
541 exerror(
"NULL string passed to readG");
544 FILE *fp = fopen(f,
"r");
546 exwarn(
"Could not open %s for reading in readG", f);
559 exerror(
"fwriteG: %lld: invalid descriptor", fd);
569 exerror(
"freadG: %lld: invalid descriptor", fd);
583 exerror(
"openF: no available descriptors");
596 if (0 <= fd && fd <= 2) {
597 exerror(
"closeF: cannot close standard stream %lld", fd);
601 exerror(
"closeG: %lld: invalid descriptor", fd);
605 exerror(
"closeF: stream %lld not open", fd);
608 rv = fclose(ex->
file[fd]);
624 exerror(
"readL: %lld: invalid descriptor", fd);
629 while ((c = getc(sp)) > 0 && c !=
'\n')
646 }
else if (r ==
NULL) {
661 else if (lkind < rkind)
670 const size_t len = strlen(src);
676 for (
size_t i = 0; i <
len; ++i) {
687 const size_t len = strlen(src);
693 for (
size_t i = 0; i <
len; ++i) {
722#define COLORPROCS_API static UNUSED
724#include "../common/colxlate.c"
733 if (*fmt ==
'\0' || *incolor ==
'\0')
737 if (!strcmp(fmt,
"RGBA"))
741 }
else if (*fmt ==
'H') {
743 if (!strcmp(fmt,
"HSVA"))
Agedge_t * isEdge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *key)
int indexOf(char *s1, char *s2)
return index of leftmost string s2 in string s1, or -1
int openFile(Expr_t *ex, const char *fname, const char *mode)
static const char * kinds(Agobj_t *obj)
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)
return index of pattern pat in string str, or SIZE_MAX
int deleteObj(Agraph_t *g, Agobj_t *obj)
int writeFile(Agraph_t *g, char *f)
static Agedge_t * mapEdge(emap_t *emap, Agedge_t *e)
int fwriteFile(Expr_t *ex, Agraph_t *g, long long fd)
long rindexOf(char *s1, char *s2)
return index of rightmost string s2 in string s1, or -1
int sfioWrite(Agraph_t *g, FILE *fp)
static void cloneGraph(Agraph_t *tgt, Agraph_t *src)
clone node, edge and subgraph structure from src to tgt
Agraph_t * sameG(void *obj1, void *obj2, char *fn, char *msg)
char * toLower(Expr_t *pgm, char *src)
convert characters to lowercase
Agraph_t * cloneG(Agraph_t *g, char *name)
int lockGraph(Agraph_t *g, int v)
char * canon(Expr_t *pgm, char *arg)
canonicalize a string for printing
int copyAttr(Agobj_t *src, Agobj_t *tgt)
static void cc_dfs(Agraph_t *g, Agraph_t *comp, Agnode_t *n)
char * toHtml(Agraph_t *g, char *arg)
create a string marked as HTML
Agnode_t * addNode(Agraph_t *gp, Agnode_t *np, int doAdd)
static Agraph_t * cloneSubg(Agraph_t *tgt, Agraph_t *g, emap_t *emap)
clone subgraph sg in tgt
int compare(Agobj_t *l, Agobj_t *r)
lexicographic ordering of objects
Agobj_t * copy(Agraph_t *g, Agobj_t *obj)
Agraph_t * readFile(char *f)
Agraph_t * compOf(Agraph_t *g, Agnode_t *n)
return connected component of node
char * colorx(Expr_t *ex, const char *incolor, char *fmt)
RGB, RGBA, HSV, HSVA.
Agedge_t * addEdge(Agraph_t *gp, Agedge_t *ep, int doAdd)
char * toUpper(Expr_t *pgm, char *src)
convert characters to uppercase
static int cmppair(const void *k1, const void *k2)
char * readLine(Expr_t *ex, long long fd)
int closeFile(Expr_t *ex, long long fd)
Helpers for dealing with agstrcanon
static size_t agstrcanon_bytes(const char *str)
how many bytes are needed to canonicalize the given string
Dynamically expanding string buffers.
static void agxbfree(agxbuf *xb)
free any malloced resources
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
static WUR char * agxbuse(agxbuf *xb)
static int agxbputc(agxbuf *xb, char c)
add character to buffer
Memory allocation wrappers that exit on failure.
int strgrpmatch(char *, char *, size_t *, int, int)
void colorxlate(char *str, agxbuf *buf)
Agedge_t * openEdge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *key)
Agraph_t * openG(char *name, Agdesc_t desc)
Agraph_t * openSubg(Agraph_t *g, char *name)
Agnode_t * openNode(Agraph_t *g, char *name)
Agraph_t * readG(FILE *fp)
void exwarn(const char *format,...)
void exerror(const char *format,...)
char * exstring(Expr_t *ex, char *s)
void * exstralloc(Expr_t *ex, size_t sz)
static double len(glCompPoint p)
int agnedges(Agraph_t *g)
Agsym_t * agattr_text(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up text attributes of a graph
Agsym_t * agattrsym(void *obj, char *name)
looks up a string attribute for a graph object given as an argument
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 * agsubedge(Agraph_t *g, Agedge_t *e, int createflag)
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)
int agclose(Agraph_t *g)
deletes a graph, freeing its associated storage
int agwrite(Agraph_t *g, void *chan)
Return 0 on success, EOF on failure.
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)
Agnode_t * agsubnode(Agraph_t *g, Agnode_t *n, int createflag)
Agnode_t * agidnode(Agraph_t *g, IDTYPE id, int createflag)
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 agdelete(Agraph_t *g, void *obj)
deletes object. Equivalent to agclose, agdelnode, and agdeledge for obj being a graph,...
Agraph_t * agroot(void *obj)
int aghtmlstr(const char *)
char * agstrcanon(char *, char *)
int agstrfree(Agraph_t *, const char *, bool is_html)
char * agstrdup_html(Agraph_t *, const char *)
returns a pointer to a reference-counted HTML-like copy of the argument string, creating one if neces...
Agraph_t * agfstsubg(Agraph_t *g)
Agraph_t * agnxtsubg(Agraph_t *subg)
replacements for ctype.h functions
static char gv_toupper(int c)
static char gv_tolower(int c)
static void color(Agraph_t *g)
textitem scanner parser str
type-generic dynamically expanding list
#define LIST_APPEND(list,...)
#define LIST_RESERVE(list, capacity)
#define LIST_SORT(list, cmp)
NEATOPROCS_API void s1(graph_t *, node_t *)
static double cg(SparseMatrix A, const double *precond, size_t n, int dim, double *x0, double *rhs, double tol, double maxit)
platform abstraction for case-insensitive string functions
a generic header of Agraph_s, Agnode_s and Agedge_s
Agclos_t * clos
shared resources
bool locked
is the lock currently taken?
bool zombie
was a deletion request recorded while locked?
abstraction for squashing compiler warnings for unused symbols