/* canon: * Canonicalize a string which may not have been allocated using agstrdup. */ static char* canon (graph_t *g, char* s) { #ifndef WITH_CGRAPH char* ns = agstrdup (s); char* cs = agcanonStr (ns); agstrfree (ns); #else char* ns = agstrdup (g, s); char* cs = agcanonStr (ns); agstrfree (g, ns); #endif return cs; }
/* canon: * Canonicalize a string which may not have been allocated using agstrdup. */ static char* canon (graph_t *g, char* s) { char* ns = agstrdup (g, s); char* cs = agcanonStr (ns); agstrfree (g, ns); return cs; }
/* * Generic object newindex metamethod handler. * Lua Stack: ud, key, value */ int object_newindex_handler(lua_State *L) { char sskey[16], *skey; if ((!lua_isstring(L, 2)) || (!lua_isstring(L, 3))){ gr_object_t *ud = toobject(L, 1, NULL, STRICT); skey = agget(ud->p.p, ".attrib"); if (!skey || (strlen(skey) == 0)){ /* Let's create an attrib table on the fly if none exists */ sprintf(sskey, "%p", ud->p.p); skey = agstrdup(sskey); agset(ud->p.p, ".attrib", skey); lua_pushstring(L, skey); /* ud, key, value, skey */ lua_newtable(L); /* ud, key, value, skey, stab */ lua_rawset(L, LUA_REGISTRYINDEX); /* ud, key, value, */ } lua_pushstring(L, skey); /* ud, key, value, skey */ lua_rawget(L, LUA_REGISTRYINDEX); /* ud, key, value, stab */ lua_pushvalue(L, 2); /* ud, key, value, stab, key */ lua_pushvalue(L, 3); /* ud, key, value, stab, key, value */ lua_rawset(L, -3); /* ud, key, value, stab */ lua_pop(L, -1); /* ud, key, value */ return 0; } return setval(L); }
Agsym_t *agNEWsym(Agdict_t * dict, char *name, char *value) { Agsym_t *a; int i; a = NEW(Agsym_t); a->name = agstrdup(name); a->value = agstrdup(value); a->printed = TRUE; i = a->index = dtsize(dict->dict); dict->list = ALLOC(i + 2, dict->list, Agsym_t *); dict->list[i++] = a; dict->list[i++] = NULL; dtinsert(dict->dict, a); return a; }
static void obj_init_attr(void *obj, Agsym_t * attr) { int i; Agraph_t *gobj; /* generic object */ gobj = (Agraph_t *) obj; i = attr->index; gobj->attr = ALLOC(i + 1, gobj->attr, char *); gobj->attr[i] = agstrdup(attr->value); }
/*-------------------------------------------------------------------------*\ * Method: n.rename(self, name) * Renames a graph. Null name will assign an auto-name 'node@ID'. * Returns old name. * Example: * oldname, err = n:rename("NODENEWNAME") or n:rename() \*-------------------------------------------------------------------------*/ static int gr_rename(lua_State *L) { char sbuf[32]; gr_node_t *ud = tonode(L, 1, STRICT); char *name = (char *) lua_tostring(L, 2); char *oldname = agnameof(ud->n); if (!name){ sprintf(sbuf, "node@%d", AGID(ud->n)); agrename(ud->n, agstrdup(sbuf)); free(ud->name); ud->name = strdup(sbuf); } else { agrename(ud->n, agstrdup(name)); free(ud->name); ud->name = strdup(name); } lua_pushstring(L, oldname); agstrfree(oldname); return 1; }
int agxset(void *obj, int index, char *buf) { char **p; if (index >= 0) { p = ((Agraph_t *) obj)->attr; agstrfree(p[index]); p[index] = agstrdup(buf); return 0; } else return -1; }
/* concat: */ static char* concat (char* s1, char* s2) { char* s; char buf[BUFSIZ]; char* sym; int len = strlen(s1) + strlen(s2) + 1; if (len <= BUFSIZ) sym = buf; else sym = (char*)malloc(len); strcpy(sym,s1); strcat(sym,s2); s = agstrdup (sym); if (sym != buf) free (sym); return s; }
static long myiddisc_map(void *state, int objtype, char *str, unsigned long *id, int createflag) { gctx_t *gctx = (gctx_t *)state; ictx_t *ictx = gctx->ictx; char *s; if (str) { if (createflag) s = agstrdup(gctx->g, str); else s = agstrbind(gctx->g, str); *id = (unsigned long) s; } else { *id = ictx->ctr; /* counter maintained in per-interp space, so that ids are unique across all graphs in the interp */ ictx->ctr += 2; } return TRUE; }
static long idmap(void *state, int objtype, char *str, unsigned long *id, int createflag) { char *s; static unsigned long ctr = 1; NOTUSED(objtype); if (str) { Agraph_t *g; g = state; if (createflag) s = agstrdup(g, str); else s = agstrbind(g, str); *id = (unsigned long) s; } else { *id = ctr; ctr += 2; } return TRUE; }
static void addRevEdge(Agraph_t * g, Agedge_t * e) { Agedge_t *reve; char *tmps; char **attrs; extern char *agstrdup(char *); attrs = g->proto->e->attr; g->proto->e->attr = e->attr; tmps = e->attr[0]; e->attr[0] = ""; reve = agedge(g, e->head, e->tail); e->attr[0] = tmps; g->proto->e->attr = attrs; /* copy key attribute, and reverse head and tail port attributes */ reve->attr[0] = agstrdup(tmps); tmps = reve->attr[1]; reve->attr[1] = reve->attr[2]; reve->attr[2] = tmps; }
char *agnameof(void *obj) { Agraph_t *g; char *rv; char buf[32]; /* perform internal lookup first */ g = agraphof(obj); if ((rv = aginternalmapprint(g, AGTYPE(obj), AGID(obj)))) return rv; if (AGDISC(g, id)->print) { if ((rv = AGDISC(g, id)->print(AGCLOS(g, id), AGTYPE(obj), AGID(obj)))) return rv; } if (AGTYPE(obj) != AGEDGE) sprintf(buf, "%c%ld", LOCALNAMEPREFIX, AGID(obj)); else buf[0] = 0; return agstrdup(g, buf); }
void GVNode::renameGVNode(QString name) { QString temp(gv_node->name); agstrfree(gv_node->name); gv_node->name = agstrdup(name.toUtf8().data()); }