#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
+#include <cgraph/agxbuf.h>
#include <cgraph/alloc.h>
#include <cgraph/prisize_t.h>
#include <cgraph/stack.h>
return cnt;
}
-static int isLegal(char *p)
-{
+static int isLegal(const char *p) {
char c;
while ((c = *p++)) {
/* setPrefix:
*/
-static char*
-setPrefix (char* pfx, size_t* lenp, char* buf, size_t buflen)
-{
- size_t len;
- char* name;
-
+static void setPrefix(agxbuf *xb, const char *pfx) {
if (!pfx || !isLegal(pfx)) {
pfx = "_cc_";
}
- len = strlen(pfx);
- if (len + 25 <= buflen)
- name = buf;
- else {
- name = gv_calloc(len + 25, sizeof(char));
- }
- strcpy(name, pfx);
- *lenp = len;
- return name;
+ agxbput(xb, pfx);
}
/* pccomps:
Agraph_t **pccomps(Agraph_t * g, int *ncc, char *pfx, bool *pinned)
{
size_t c_cnt = 0;
- char buffer[SMALLBUF];
- char *name;
+ agxbuf name = {0};
Agraph_t *out = NULL;
Agnode_t *n;
- size_t len;
size_t bnd = 10;
bool pin = false;
stk_t stk;
*ncc = 0;
return NULL;
}
- name = setPrefix (pfx, &len, buffer, SMALLBUF);
Agraph_t **ccs = gv_calloc(bnd, sizeof(Agraph_t*));
if (MARKED(&stk,n) || !isPinned(n))
continue;
if (!out) {
- sprintf(name + len, "%" PRISIZE_T, c_cnt);
- out = agsubg(g, name,1);
+ setPrefix(&name, pfx);
+ agxbprint(&name, "%" PRISIZE_T, c_cnt);
+ out = agsubg(g, agxbuse(&name),1);
agbindrec(out, "Agraphinfo_t", sizeof(Agraphinfo_t), true); //node custom data
ccs[c_cnt] = out;
c_cnt++;
for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
if (MARKED(&stk,n))
continue;
- sprintf(name + len, "%" PRISIZE_T, c_cnt);
- out = agsubg(g, name,1);
+ setPrefix(&name, pfx);
+ agxbprint(&name, "%" PRISIZE_T, c_cnt);
+ out = agsubg(g, agxbuse(&name), 1);
agbindrec(out, "Agraphinfo_t", sizeof(Agraphinfo_t), true); //node custom data
if (dfs(g, n, out, &stk) == SIZE_MAX) {
error = 1;
}
packerror:
freeStk (&stk);
- if (name != buffer)
- free(name);
+ agxbfree(&name);
if (error) {
*ncc = 0;
for (size_t i=0; i < c_cnt; i++) {
Agraph_t **ccomps(Agraph_t * g, int *ncc, char *pfx)
{
size_t c_cnt = 0;
- char buffer[SMALLBUF];
- char *name;
+ agxbuf name = {0};
Agraph_t *out;
Agnode_t *n;
- size_t len;
size_t bnd = 10;
stk_t stk;
*ncc = 0;
return NULL;
}
- name = setPrefix (pfx, &len, buffer, SMALLBUF);
Agraph_t **ccs = gv_calloc(bnd, sizeof(Agraph_t*));
initStk(&stk, insertFn, markFn);
for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
if (MARKED(&stk,n))
continue;
- sprintf(name + len, "%" PRISIZE_T, c_cnt);
- out = agsubg(g, name,1);
+ setPrefix(&name, pfx);
+ agxbprint(&name, "%" PRISIZE_T, c_cnt);
+ out = agsubg(g, agxbuse(&name), 1);
agbindrec(out, "Agraphinfo_t", sizeof(Agraphinfo_t), true); //node custom data
if (dfs(g, n, out, &stk) == SIZE_MAX) {
freeStk (&stk);
free (ccs);
- if (name != buffer)
- free(name);
+ agxbfree(&name);
*ncc = 0;
return NULL;
}
}
freeStk (&stk);
ccs = gv_recalloc(ccs, bnd, c_cnt, sizeof(Agraph_t*));
- if (name != buffer)
- free(name);
+ agxbfree(&name);
*ncc = (int) c_cnt;
return ccs;
}
{
Agraph_t *dg;
size_t n_cnt, c_cnt, e_cnt;
- char *name;
+ agxbuf name = {0};
Agraph_t *out;
Agraph_t *dout;
Agnode_t *dn;
- char buffer[SMALLBUF];
stk_t stk;
- size_t len;
int sz = (int) sizeof(ccgraphinfo_t);
if (agnnodes(g) == 0) {
/* Bind ccgraphinfo to graph and all subgraphs */
aginit(g, AGNODE, NRECNAME, sizeof(ccgnodeinfo_t), FALSE);
- name = setPrefix (pfx, &len, buffer, SMALLBUF);
-
dg = deriveGraph(g);
size_t ccs_length = (size_t)agnnodes(dg);
for (dn = agfstnode(dg); dn; dn = agnxtnode(dg, dn)) {
if (MARKED(&stk,dn))
continue;
- sprintf(name + len, "%" PRISIZE_T, c_cnt);
- dout = agsubg(dg, name, 1);
- out = agsubg(g, name, 1);
+ setPrefix(&name, pfx);
+ agxbprint(&name, "%" PRISIZE_T, c_cnt);
+ char *name_str = agxbuse(&name);
+ dout = agsubg(dg, name_str, 1);
+ out = agsubg(g, name_str, 1);
agbindrec(out, GRECNAME, sizeof(ccgraphinfo_t), false);
GD_cc_subg(out) = 1;
n_cnt = dfs(dg, dn, dout, &stk);
agclean (g, AGNODE, NRECNAME);
freeStk (&stk);
free(ccs);
- if (name != buffer)
- free(name);
+ agxbfree(&name);
*ncc = 0;
return NULL;
}
agclean (g, AGNODE, NRECNAME);
freeStk (&stk);
ccs = gv_recalloc(ccs, ccs_length, c_cnt, sizeof(Agraph_t*));
- if (name != buffer)
- free(name);
+ agxbfree(&name);
*ncc = (int) c_cnt;
return ccs;
}