/* parseXDotFOn:
* Parse and append additional xops onto a given xdot object.
- * Assume x != NULL.
* Return x.
*/
-xdot *parseXDotFOn (char *s, drawfunc_t fns[], xdot* x)
+xdot *parseXDotFOn (char *s, drawfunc_t fns[], int sz, xdot* x)
{
xdot_op op;
char *ops;
int oldsz, bufsz;
int error;
- int initcnt, sz;
+ int initcnt;
- if (!s || !x)
+ if (!s)
return x;
+ if (!x) {
+ x = NEW(xdot);
+ if (sz <= sizeof(xdot_op))
+ sz = sizeof(xdot_op);
+
+ /* cnt, freefunc, ops, flags zeroed by NEW */
+ x->sz = sz;
+ }
initcnt = x->cnt;
sz = x->sz;
+
if (initcnt == 0) {
bufsz = XDBSIZE;
ops = (char *) calloc(XDBSIZE, sz);
}
else {
free (ops);
+ free (x);
+ x = NULL;
}
return x;
xdot *parseXDotF(char *s, drawfunc_t fns[], int sz)
{
- xdot *x;
-
- if (!s)
- return NULL;
- x = NEW(xdot);
- if (sz <= sizeof(xdot_op))
- sz = sizeof(xdot_op);
-
- /* cnt, freefunc, ops, flags zeroed by NEW */
- x->sz = sz;
-
- x = parseXDotFOn (s, fns, x);
- if (x->cnt == 0) {
- free(x);
- x = NULL;
- }
- return x;
+ return parseXDotFOn (s, fns, sz, NULL);
}
xdot *parseXDot(char *s)
/* ops are indexed by xop_kind */
extern xdot* parseXDotF (char*, drawfunc_t opfns[], int sz);
-extern xdot* parseXDotFOn (char*, drawfunc_t opfns[], xdot*);
+extern xdot* parseXDotFOn (char*, drawfunc_t opfns[], int sz, xdot*);
extern xdot* parseXDot (char*);
extern char* sprintXDot (xdot*);
extern void fprintXDot (FILE*, xdot*);