NULL is more concise and more widely understood than the Graphviz-specific macro
NIL. We leave the definitions of NIL in case others are using these through the
public API.
char name[10];
/* Create a new graph */
- g = agopen("new_graph", Agdirected,NIL(Agdisc_t *));
+ g = agopen("new_graph", Agdirected,NULL);
/* Add nodes */
for (j = 0; j < NUMNODES; j++) {
#include <glade/glade.h>
#include "gui.h"
#include "menucallbacks.h"
+#include <stddef.h>
#include <string.h>
#include "glcompui.h"
/* #include "topview.h" */
g_print("Cannot open %s\n", filename);
return 0;
}
- g = agread(input_file, NIL(Agdisc_t *));
+ g = agread(input_file, NULL);
fclose (input_file);
if (!g) {
g_print("Cannot read graph in %s\n", filename);
#include "convert.h"
#include <ctype.h>
+#include <stddef.h>
#define SMALLBUF 128
offsetof(namev_t, link),
(Dtmake_f) make_nitem,
(Dtfree_f) free_nitem,
- NIL(Dtcompar_f),
- NIL(Dthash_f),
- NIL(Dtmemory_f),
- NIL(Dtevent_f)
+ NULL,
+ NULL,
+ NULL,
+ NULL
};
typedef struct {
offsetof(idv_t, name),
-1,
offsetof(idv_t, link),
- NIL(Dtmake_f),
+ NULL,
(Dtfree_f) free_iditem,
- NIL(Dtcompar_f),
- NIL(Dthash_f),
- NIL(Dtmemory_f),
- NIL(Dtevent_f)
+ NULL,
+ NULL,
+ NULL,
+ NULL
};
typedef struct {
Dict_t *view;
Agsym_t *sym, *psym;
- view = dtview(dict, NIL(Dict_t *));
+ view = dtview(dict, NULL);
for (sym = (Agsym_t *) dtfirst(dict); sym;
sym = (Agsym_t *) dtnext(dict, sym)) {
if (!isGxlGrammar(sym->name)) {
if (EMPTY(sym->defval)) { /* try to skip empty str (default) */
- if (view == NIL(Dict_t *))
+ if (view == NULL)
continue; /* no parent */
psym = (Agsym_t *) dtsearch(view, sym);
/* assert(psym); */
/* gxl attr; check for special cases like composites */
if (strncmp(sym->name, GXL_COMP, GXL_COMP_LEN) == 0) {
if (EMPTY(sym->defval)) {
- if (view == NIL(Dict_t *))
+ if (view == NULL)
continue;
psym = (Agsym_t *) dtsearch(view, sym);
if (EMPTY(psym->defval))
free(dynbuf);
Level++;
} else {
- Tailport = agattr(g, AGEDGE, "tailport", NIL(char *));
- Headport = agattr(g, AGEDGE, "headport", NIL(char *));
+ Tailport = agattr(g, AGEDGE, "tailport", NULL);
+ Headport = agattr(g, AGEDGE, "headport", NULL);
}
Agraph_t* hscc = getscc(aghead(e));
if (tscc && hscc)
agedge(map, getrep(tscc),
- getrep(hscc), NIL(char *), TRUE);
+ getrep(hscc), NULL, TRUE);
}
}
}
Agraph_t *hscc = getscc(aghead(e));
if (tscc && hscc)
agedge(map, getrep(tscc),
- getrep(hscc), NIL(char *), TRUE);
+ getrep(hscc), NULL, TRUE);
}
}
}
#include <cdt/dthdr.h>
+#include <stddef.h>
/* Close a dictionary
**
/* announce the close event to see if we should continue */
disc = dt->disc;
if(disc->eventf &&
- (ev = (*disc->eventf)(dt,DT_CLOSE,NIL(void*),disc)) < 0)
+ (ev = (*disc->eventf)(dt,DT_CLOSE,NULL,disc)) < 0)
return -1;
if(dt->view) /* turn off viewing */
- dtview(dt,NIL(Dt_t*));
+ dtview(dt,NULL);
if(ev == 0) /* release all allocated data */
- { (void)(*(dt->meth->searchf))(dt,NIL(void*),DT_CLEAR);
+ { (void)(*(dt->meth->searchf))(dt,NULL,DT_CLEAR);
if(dtsize(dt) > 0)
return -1;
(*dt->memoryf)(dt, (void*)dt, 0, disc);
if(disc->eventf)
- (void)(*disc->eventf)(dt, DT_ENDCLOSE, NIL(void*), disc);
+ (void)(*disc->eventf)(dt, DT_ENDCLOSE, NULL, disc);
return 0;
}
#include <cdt/dthdr.h>
+#include <stddef.h>
/* Change discipline.
** dt : dictionary
if(addr)
{ if(size == 0)
{ free(addr);
- return NIL(void*);
+ return NULL;
}
else return realloc(addr,size);
}
- else return size > 0 ? malloc(size) : NIL(void*);
+ else return size > 0 ? malloc(size) : NULL;
}
Dtdisc_t* dtdisc(Dt_t* dt, Dtdisc_t* disc, int type)
UNFLATTEN(dt);
if(old->eventf && (*old->eventf)(dt,DT_DISC,(void*)disc,old) < 0)
- return NIL(Dtdisc_t*);
+ return NULL;
dt->disc = disc;
if(!(dt->memoryf = disc->memoryf) )
dt_renew:
r = dtflatten(dt);
dt->data->type &= ~DT_FLATTEN;
- dt->data->here = NIL(Dtlink_t*);
+ dt->data->here = NULL;
dt->data->size = 0;
if(dt->data->type&(DT_SET|DT_BAG))
{ Dtlink_t **s, **ends;
ends = (s = dt->data->htab) + dt->data->ntab;
while(s < ends)
- *s++ = NIL(Dtlink_t*);
+ *s++ = NULL;
}
/* reinsert them */
#include <cdt/dthdr.h>
+#include <stddef.h>
/* Extract objects of a dictionary.
**
else if(dt->data->type&(DT_SET|DT_BAG))
{ list = dtflatten(dt);
for(ends = (s = dt->data->htab) + dt->data->ntab; s < ends; ++s)
- *s = NIL(Dtlink_t*);
+ *s = NULL;
}
else /*if(dt->data->type&(DT_LIST|DT_STACK|DT_QUEUE))*/
{ list = dt->data->head;
- dt->data->head = NIL(Dtlink_t*);
+ dt->data->head = NULL;
}
dt->data->type &= ~DT_FLATTEN;
dt->data->size = 0;
- dt->data->here = NIL(Dtlink_t*);
+ dt->data->here = NULL;
return list;
}
#include <cdt/dthdr.h>
+#include <stddef.h>
/* Flatten a dictionary into a linked list.
** This may be used when many traversals are likely.
if(dt->data->type&DT_FLATTEN )
return dt->data->here;
- list = last = NIL(Dtlink_t*);
+ list = last = NULL;
if(dt->data->type&(DT_SET|DT_BAG))
{ for(ends = (s = dt->data->htab) + dt->data->ntab; s < ends; ++s)
{ if((t = *s) )
#include <cdt/dthdr.h>
+#include <stddef.h>
/* Hash table.
** dt: dictionary
return;
/* allocate new table */
- olds = dt->data->ntab == 0 ? NIL(Dtlink_t**) : dt->data->htab;
+ olds = dt->data->ntab == 0 ? NULL : dt->data->htab;
if(!(s = (Dtlink_t**)(*dt->memoryf)(dt,olds,n*sizeof(Dtlink_t*),dt->disc)) )
return;
olds = s + dt->data->ntab;
/* rehash elements */
for(hs = s+n-1; hs >= olds; --hs)
- *hs = NIL(Dtlink_t*);
+ *hs = NULL;
for(hs = s; hs < olds; ++hs)
- { for(p = NIL(Dtlink_t*), t = *hs; t; t = r)
+ { for(p = NULL, t = *hs; t; t = r)
{ r = t->right;
if((is = s + HINDEX(n,t->hash)) == hs)
p = t;
goto end_walk;
if(dt->data->size <= 0 || !(type&(DT_CLEAR|DT_FIRST|DT_LAST)) )
- return NIL(void*);
+ return NULL;
ends = (s = dt->data->htab) + dt->data->ntab;
if(type&DT_CLEAR)
{ /* clean out all objects */
for(; s < ends; ++s)
{ t = *s;
- *s = NIL(Dtlink_t*);
+ *s = NULL;
if(!disc->freef && disc->link >= 0)
continue;
while(t)
t = r;
}
}
- dt->data->here = NIL(Dtlink_t*);
+ dt->data->here = NULL;
dt->data->size = 0;
dt->data->loop = 0;
- return NIL(void*);
+ return NULL;
}
else /* computing the first/last object */
- { t = NIL(Dtlink_t*);
+ { t = NULL;
while(s < ends && !t )
t = (type&DT_LAST) ? *--ends : *s++;
if(t && (type&DT_LAST))
dt->data->loop += 1;
dt->data->here = t;
- return t ? _DTOBJ(t,lk) : NIL(void*);
+ return t ? _DTOBJ(t,lk) : NULL;
}
}
/* allow apps to delete an object "actually" in the dictionary */
if(dt->meth->type == DT_BAG && (type&(DT_DELETE|DT_DETACH)) )
{ if(!dtsearch(dt,obj) )
- return NIL(void*);
+ return NULL;
s = dt->data->htab + HINDEX(dt->data->ntab,dt->data->here->hash);
- r = NIL(Dtlink_t*);
- for(p = NIL(Dtlink_t*), t = *s; t; p = t, t = t->right)
+ r = NULL;
+ for(p = NULL, t = *s; t; p = t, t = t->right)
{ if(_DTOBJ(t,lk) == obj) /* delete this specific object */
goto do_delete;
if(t == dt->data->here)
{ if((t = dt->data->here) && _DTOBJ(t,lk) == obj)
{ hsh = t->hash;
s = dt->data->htab + HINDEX(dt->data->ntab,hsh);
- p = NIL(Dtlink_t*);
+ p = NULL;
}
else
{ key = _DTKEY(obj,ky,sz);
hsh = _DTHSH(dt,key,disc,sz);
do_search:
- t = dt->data->ntab <= 0 ? NIL(Dtlink_t*) :
+ t = dt->data->ntab <= 0 ? NULL :
*(s = dt->data->htab + HINDEX(dt->data->ntab,hsh));
- for(p = NIL(Dtlink_t*); t; p = t, t = t->right)
+ for(p = NULL; t; p = t, t = t->right)
{ if(hsh == t->hash)
{ k = _DTOBJ(t,lk); k = _DTKEY(k,ky,sz);
if(_DTCMP(dt,key,k,disc,cmpf,sz) == 0)
if(type&(DT_MATCH|DT_SEARCH|DT_VSEARCH))
{ if(!t)
- return NIL(void*);
+ return NULL;
if(p && (dt->data->type&DT_SET) && dt->data->loop <= 0)
{ /* move-to-front heuristic */
p->right = t->right;
if(disc->makef && (type&DT_INSERT) &&
!(obj = (*disc->makef)(dt,obj,disc)) )
- return NIL(void*);
+ return NULL;
if(lk >= 0)
r = _DTLNK(obj,lk);
else
{ r = (Dtlink_t*)(*dt->memoryf)
- (dt,NIL(void*),sizeof(Dthold_t),disc);
+ (dt,NULL,sizeof(Dthold_t),disc);
if(r)
((Dthold_t*)r)->obj = obj;
else
{ if(disc->makef && disc->freef && (type&DT_INSERT))
(*disc->freef)(dt,obj,disc);
- return NIL(void*);
+ return NULL;
}
}
r->hash = hsh;
(*disc->freef)(dt,obj,disc);
if(disc->link < 0)
(*disc->memoryf)(dt,(void*)r,0,disc);
- return NIL(void*);
+ return NULL;
}
s = dt->data->htab + HINDEX(dt->data->ntab,hsh);
if(t)
p = p->right;
}
else
- { p = NIL(Dtlink_t*);
+ { p = NULL;
for(s -= 1, ends = dt->data->htab; s >= ends; --s)
{ if((p = *s) )
{ while(p->right)
dt->data->loop = 0;
if(dt->data->size > HLOAD(dt->data->ntab) && dt->data->loop <= 0)
dthtab(dt);
- return NIL(void*);
+ return NULL;
}
else
{ dt->data->type |= DT_WALK;
(*disc->freef)(dt,obj,disc);
if(disc->link < 0)
(*dt->memoryf)(dt,(void*)r,0,disc);
- return t ? _DTOBJ(t,lk) : NIL(void*);
+ return t ? _DTOBJ(t,lk) : NULL;
}
}
else /*if(type&(DT_DELETE|DT_DETACH))*/
{ /* take an element out of the dictionary */
do_delete:
if(!t)
- return NIL(void*);
+ return NULL;
else if(p)
p->right = t->right;
else if((p = *s) == t)
#define HINDEX(n,h) ((h)&((n)-1))
#define UNFLATTEN(dt) \
- ((dt->data->type&DT_FLATTEN) ? dtrestore(dt,NIL(Dtlink_t*)) : 0)
+ ((dt->data->type&DT_FLATTEN) ? dtrestore(dt,NULL) : 0)
/* tree rotation/linking functions */
#define rrotate(x,y) ((x)->left = (y)->right, (y)->right = (x))
#include <cdt/dthdr.h>
+#include <stddef.h>
/* List, Deque, Stack, Queue.
**
r = r->left;
dt->data->here = r;
}
- return r ? _DTOBJ(r,lk) : NIL(void*);
+ return r ? _DTOBJ(r,lk) : NULL;
}
else if(type&(DT_DELETE|DT_DETACH))
{ if((dt->data->type&(DT_LIST|DT_DEQUE)) || !(r = dt->data->head))
- return NIL(void*);
+ return NULL;
else goto dt_delete;
}
else if(type&DT_CLEAR)
(*dt->memoryf)(dt,(void*)r,0,disc);
}
}
- dt->data->head = dt->data->here = NIL(Dtlink_t*);
+ dt->data->head = dt->data->here = NULL;
dt->data->size = 0;
- return NIL(void*);
+ return NULL;
}
- else return NIL(void*);
+ else return NULL;
}
if(type&(DT_INSERT|DT_ATTACH))
{ if(disc->makef && (type&DT_INSERT) &&
!(obj = (*disc->makef)(dt,obj,disc)) )
- return NIL(void*);
+ return NULL;
if(lk >= 0)
r = _DTLNK(obj,lk);
else
{ r = (Dtlink_t*)(*dt->memoryf)
- (dt,NIL(void*),sizeof(Dthold_t),disc);
+ (dt,NULL,sizeof(Dthold_t),disc);
if(r)
((Dthold_t*)r)->obj = obj;
else
{ if(disc->makef && disc->freef && (type&DT_INSERT))
(*disc->freef)(dt,obj,disc);
- return NIL(void*);
+ return NULL;
}
}
{ dt->data->head = r;
r->left = r;
}
- r->right = NIL(Dtlink_t*);
+ r->right = NULL;
}
if(dt->data->size >= 0)
}
if(!r)
- return NIL(void*);
+ return NULL;
dt->type |= DT_FOUND;
if(type&(DT_DELETE|DT_DETACH))
t->left = r->left;
}
- dt->data->here = r == dt->data->here ? r->right : NIL(Dtlink_t*);
+ dt->data->here = r == dt->data->here ? r->right : NULL;
dt->data->size -= 1;
obj = _DTOBJ(r,lk);
else if(type&DT_NEXT)
r = r->right;
else if(type&DT_PREV)
- r = r == dt->data->head ? NIL(Dtlink_t*) : r->left;
+ r = r == dt->data->head ? NULL : r->left;
dt->data->here = r;
- return r ? _DTOBJ(r,lk) : NIL(void*);
+ return r ? _DTOBJ(r,lk) : NULL;
}
#ifndef KPVDEL /* to be remove next round */
#include <cdt/dthdr.h>
+#include <stddef.h>
/* Change search method.
**
if(disc->eventf &&
(*disc->eventf)(dt,DT_METH,(void*)meth,disc) < 0)
- return NIL(Dtmethod_t*);
+ return NULL;
dt->data->minp = 0;
list = dtflatten(dt);
if(dt->data->type&(DT_LIST|DT_STACK|DT_QUEUE) )
- dt->data->head = NIL(Dtlink_t*);
+ dt->data->head = NULL;
else if(dt->data->type&(DT_SET|DT_BAG) )
{ if(dt->data->ntab > 0)
(*dt->memoryf)(dt,(void*)dt->data->htab,0,disc);
dt->data->ntab = 0;
- dt->data->htab = NIL(Dtlink_t**);
+ dt->data->htab = NULL;
}
- dt->data->here = NIL(Dtlink_t*);
+ dt->data->here = NULL;
dt->data->type = (dt->data->type&~(DT_METHODS|DT_FLATTEN)) | meth->type;
dt->meth = meth;
if(dt->searchf == oldmeth->searchf)
#include <cdt/dthdr.h>
+#include <stddef.h>
/* Make a new dictionary
**
Dtdata_t* data;
if(!disc || !meth)
- return NIL(Dt_t*);
+ return NULL;
/* allocate space for dictionary */
if(!(dt = malloc(sizeof(Dt_t))))
- return NIL(Dt_t*);
+ return NULL;
/* initialize all absolutely private data */
- dt->searchf = NIL(Dtsearch_f);
- dt->meth = NIL(Dtmethod_t*);
- dt->disc = NIL(Dtdisc_t*);
+ dt->searchf = NULL;
+ dt->meth = NULL;
+ dt->disc = NULL;
dtdisc(dt,disc,0);
dt->type = DT_MALLOC;
dt->nview = 0;
- dt->view = dt->walk = NIL(Dt_t*);
- dt->user = NIL(void*);
+ dt->view = dt->walk = NULL;
+ dt->user = NULL;
if(disc->eventf)
{ /* if shared/persistent dictionary, get existing data */
- data = NIL(Dtdata_t*);
+ data = NULL;
if((e = (*disc->eventf)(dt,DT_OPEN,(void*)(&data),disc)) < 0)
goto err_open;
else if(e > 0)
free(dt);
if(!(dt = (*disc->memoryf)(0, 0, sizeof(Dt_t), disc)) )
- return NIL(Dt_t*);
- dt->searchf = NIL(Dtsearch_f);
- dt->meth = NIL(Dtmethod_t*);
- dt->disc = NIL(Dtdisc_t*);
+ return NULL;
+ dt->searchf = NULL;
+ dt->meth = NULL;
+ dt->disc = NULL;
dtdisc(dt,disc,0);
dt->type = DT_MEMORYF;
dt->nview = 0;
- dt->view = dt->walk = NIL(Dt_t*);
+ dt->view = dt->walk = NULL;
}
}
/* allocate sharable data */
- if(!(data = (Dtdata_t*)(dt->memoryf)(dt,NIL(void*),sizeof(Dtdata_t),disc)) )
+ if(!(data = (Dtdata_t*)(dt->memoryf)(dt,NULL,sizeof(Dtdata_t),disc)) )
{ err_open:
free(dt);
- return NIL(Dt_t*);
+ return NULL;
}
data->type = meth->type;
- data->here = NIL(Dtlink_t*);
- data->htab = NIL(Dtlink_t**);
+ data->here = NULL;
+ data->htab = NULL;
data->ntab = data->size = data->loop = 0;
data->minp = 0;
#include <cdt/dthdr.h>
-
+#include <stddef.h>
/* Renew the object at the current finger.
**
UNFLATTEN(dt);
if(!(e = dt->data->here) || _DTOBJ(e,disc->link) != obj)
- return NIL(void*);
+ return NULL;
if(dt->data->type&(DT_STACK|DT_QUEUE|DT_LIST))
return obj;
}
key = _DTKEY(obj,disc->key,disc->size);
e->hash = _DTHSH(dt,key,disc,disc->size);
- dt->data->here = NIL(Dtlink_t*);
+ dt->data->here = NULL;
}
dt->data->size -= 1;
- return (*dt->meth->searchf)(dt,(void*)e,DT_RENEW) ? obj : NIL(void*);
+ return (*dt->meth->searchf)(dt,(void*)e,DT_RENEW) ? obj : NULL;
}
#include <cdt/dthdr.h>
+#include <stddef.h>
/* Restore dictionary from given tree or list of elements.
** There are two cases. If called from within, list is nil.
dt->data->type &= ~DT_FLATTEN;
if(dt->data->type&(DT_SET|DT_BAG))
- { dt->data->here = NIL(Dtlink_t*);
+ { dt->data->here = NULL;
if(type) /* restoring a flattened dictionary */
{ for(ends = (s = dt->data->htab) + dt->data->ntab; s < ends; ++s)
{ if((t = *s) )
{ *s = list;
list = t->right;
- t->right = NIL(Dtlink_t*);
+ t->right = NULL;
}
}
}
{ if(dt->data->type&(DT_OSET|DT_OBAG))
dt->data->here = list;
else /*if(dt->data->type&(DT_LIST|DT_STACK|DT_QUEUE))*/
- { dt->data->here = NIL(Dtlink_t*);
+ { dt->data->here = NULL;
dt->data->head = list;
}
if(!type)
#include <cdt/dthdr.h>
+#include <stddef.h>
/* Get statistics of a dictionary
**
UNFLATTEN(dt);
ds->dt_n = ds->dt_max = 0;
- ds->dt_count = NIL(int*);
+ ds->dt_count = NULL;
ds->dt_size = dtsize(dt);
ds->dt_meth = dt->data->type&DT_METHODS;
return 0;
if(dt->data->type&(DT_SET|DT_BAG))
- { dthstat(dt->data,ds,NIL(int*));
+ { dthstat(dt->data,ds,NULL);
if(ds->dt_max+1 > Size)
{ if(Size > 0)
free(Count);
}
else if(dt->data->type&(DT_OSET|DT_OBAG))
{ if(dt->data->here)
- { dttstat(ds,dt->data->here,0,NIL(int*));
+ { dttstat(ds,dt->data->here,0,NULL);
if(ds->dt_n+1 > Size)
{ if(Size > 0)
free(Count);
#include <cdt/dthdr.h>
+#include <stddef.h>
/* Ordered set/multiset
** dt: dictionary being searched
root = dt->data->here;
if(!obj)
{ if(!root || !(type&(DT_CLEAR|DT_FIRST|DT_LAST)) )
- return NIL(void*);
+ return NULL;
if(type&DT_CLEAR) /* delete all objects */
{ if(disc->freef || disc->link < 0)
}
dt->data->size = 0;
- dt->data->here = NIL(Dtlink_t*);
- return NIL(void*);
+ dt->data->here = NULL;
+ return NULL;
}
else /* computing largest/smallest element */
{ if(type&DT_LAST)
else
{ turn[n] = cmp;
if(!(t = cmp < 0 ? t->left : t->right) )
- return NIL(void*);
+ return NULL;
}
}
}
else
{ rlink(r,root);
- root = NIL(Dtlink_t*);
+ root = NULL;
break;
}
}
}
else
{ llink(l,root);
- root = NIL(Dtlink_t*);
+ root = NULL;
break;
}
}
}
else if(type&DT_NEXT)
{ root->left = link.right;
- root->right = NIL(Dtlink_t*);
+ root->right = NULL;
link.right = root;
dt_next:
if((root = link.left) )
}
else if(type&DT_PREV)
{ root->right = link.left;
- root->left = NIL(Dtlink_t*);
+ root->left = NULL;
link.left = root;
dt_prev:
if((root = link.right) )
{ if(dt->meth->type&DT_OSET)
goto has_root;
else
- { root->left = NIL(Dtlink_t*);
+ { root->left = NULL;
root->right = link.left;
link.left = root;
goto dt_insert;
(*dt->memoryf)(dt,(void*)me,0,disc);
}
else
- { me->left = NIL(Dtlink_t*);
+ { me->left = NULL;
me->right = link.left;
link.left = me;
dt->data->size += 1;
}
else
{ /* not found, finish up LEFT and RIGHT trees */
- r->left = NIL(Dtlink_t*);
- l->right = NIL(Dtlink_t*);
+ r->left = NULL;
+ l->right = NULL;
if(type&DT_NEXT)
goto dt_next;
r = t;
r->left = link.right;
dt->data->here = link.left;
- return (type&DT_DELETE) ? obj : NIL(void*);
+ return (type&DT_DELETE) ? obj : NULL;
}
else if(type&(DT_INSERT|DT_ATTACH))
{ dt_insert:
root = _DTLNK(obj,lk);
else
{ root = (Dtlink_t*)(*dt->memoryf)
- (dt,NIL(void*),sizeof(Dthold_t),disc);
+ (dt,NULL,sizeof(Dthold_t),disc);
if(root)
((Dthold_t*)root)->obj = obj;
else if(disc->makef && disc->freef &&
goto has_root;
}
else /*if(type&DT_DELETE)*/
- { obj = NIL(void*);
+ { obj = NULL;
goto no_root;
}
}
- return NIL(void*);
+ return NULL;
}
/* make this method available */
#include <cdt/dthdr.h>
+#include <stddef.h>
/* Set a view path from dict to view.
**
if(dt->meth->type & (DT_OBAG|DT_OSET) )
{ if(!(type & (DT_FIRST|DT_LAST|DT_NEXT|DT_PREV)) )
- return NIL(void*);
+ return NULL;
- n = nk = NIL(void*); p = NIL(Dt_t*);
+ n = nk = NULL; p = NULL;
for(d = dt; d; d = d->view)
{ if(!(o = (*d->meth->searchf)(d, obj, type)) )
continue;
/* non-ordered methods */
if(!(type & (DT_NEXT|DT_PREV)) )
- return NIL(void*);
+ return NULL;
if(!dt->walk || obj != _DTOBJ(dt->walk->data->here, dt->walk->disc->link) )
{ for(d = dt; d; d = d->view)
break;
dt->walk = d;
if(!(obj = o) )
- return NIL(void*);
+ return NULL;
}
for(d = dt->walk, obj = (*d->meth->searchf)(d, obj, type);; )
}
if(!(d = dt->walk = d->view) ) /* move on to next dictionary */
- return NIL(void*);
+ return NULL;
else if(type&DT_NEXT)
- obj = (*(d->meth->searchf))(d,NIL(void*),DT_FIRST);
- else obj = (*(d->meth->searchf))(d,NIL(void*),DT_LAST);
+ obj = (*(d->meth->searchf))(d,NULL,DT_FIRST);
+ else obj = (*(d->meth->searchf))(d,NULL,DT_LAST);
}
}
if(view)
{ UNFLATTEN(view);
if(view->meth != dt->meth) /* must use the same method */
- return NIL(Dt_t*);
+ return NULL;
}
/* make sure there won't be a cycle */
for(d = view; d; d = d->view)
if(d == dt)
- return NIL(Dt_t*);
+ return NULL;
/* no more viewing lower dictionary */
if((d = dt->view) )
d->nview -= 1;
- dt->view = dt->walk = NIL(Dt_t*);
+ dt->view = dt->walk = NULL;
if(!view)
{ dt->searchf = dt->meth->searchf;
*************************************************************************/
#include <cgraph/cghdr.h>
+#include <stddef.h>
/*
* dynamic attributes
(int) offsetof(Agsym_t, name), /* use symbol name as key */
-1,
(int) offsetof(Agsym_t, link),
- NIL(Dtmake_f),
+ NULL,
freesym,
- NIL(Dtcompar_f),
- NIL(Dthash_f),
- NIL(Dtmemory_f),
- NIL(Dtevent_f),
+ NULL,
+ NULL,
+ NULL,
+ NULL,
};
static char DataDictName[] = "_AG_datadict";
break;
default:
agerr(AGERR,"agdictof: unknown kind %d\n", kind);
- dict = NIL(Dict_t *);
+ dict = NULL;
break;
} else
- dict = NIL(Dict_t *);
+ dict = NULL;
return dict;
}
Agsym_t *rv;
Dict_t *view;
- view = dtview(dict, NIL(Dict_t *));
+ view = dtview(dict, NULL);
rv = agdictsym(dict, name);
dtview(dict, view);
return rv;
if (data)
rv = agdictsym(data->dict, arg);
else
- rv = NILsym;
+ rv = NULL;
return rv;
}
rec = agbindrec(obj, AgDataRecName, sizeof(Agattr_t), FALSE);
datadict = agdictof(context, AGTYPE(obj));
assert(datadict);
- if (rec->dict == NIL(Dict_t *)) {
+ if (rec->dict == NULL) {
rec->dict = agdictof(agroot(context), AGTYPE(obj));
/* don't malloc(0) */
sz = topdictsize(obj);
Agattr_t *attr;
attr = (Agattr_t *) agattrrec(obj);
- assert(attr != NIL(Agattr_t *));
+ assert(attr != NULL);
if (sym->id >= MINATTR)
attr->str = (char **) AGDISC(g, mem)->resize(AGCLOS(g, mem),
attr->str,
/*
* create or update an existing attribute and return its descriptor.
- * if the new value is NIL(char*), this is only a search, no update.
+ * if the new value is NULL, this is only a search, no update.
* when a new attribute is created, existing graphs/nodes/edges
* receive its default value.
*/
char *rv;
sym = agattrsym(obj, name);
- if (sym == NILsym)
+ if (sym == NULL)
rv = 0; /* note was "", but this provides more info */
else {
data = agattrrec((Agobj_t *) obj);
int rv;
sym = agattrsym(obj, name);
- if (sym == NILsym)
+ if (sym == NULL)
rv = FAILURE;
else
rv = agxset(obj, sym, value);
root = agroot(g);
agapply(root, (Agobj_t *) root, (agobjfn_t) agraphattr_init,
- NIL(Agdisc_t *), TRUE);
+ NULL, TRUE);
for (n = agfstnode(root); n; n = agnxtnode(root, n)) {
agnodeattr_init(g, n);
for (e = agfstout(root, n); e; e = agnxtout(root, e)) {
*************************************************************************/
#include <cgraph/cghdr.h>
+#include <stddef.h>
/*
* provides "compound nodes" on top of base Libgraph.
if (stk->stacksize > 0)
rv = stk->mem[stk->stacksize - 1];
else
- rv.from = rv.to = NILnode;
+ rv.from = rv.to = NULL;
return rv;
}
Agsplice_arg_t splice_arg;
- if ((e == NILedge) || (e->node == target))
+ if (e == NULL || e->node == target)
return FAILURE;
g = agraphof(e);
t = AGTAIL(e);
if (n && g && agassociate(n, subg))
return n;
else
- return NILnode;
+ return NULL;
}
int agassociate(Agnode_t * n, Agraph_t * sub)
dtdelete(g->n_dict, n);
graphrec = agbindrec(g, Descriptor_id, sizeof(*graphrec), FALSE);
- if ((d = graphrec->hidden_node_set) == NIL(Dict_t *)) {
+ if ((d = graphrec->hidden_node_set) == NULL) {
/* use name disc. to permit search for hidden node by name */
d = graphrec->hidden_node_set
= agdtopen(g, &Ag_node_name_disc, Dttree);
g = agraphof(cmpnode);
/* skip operation if node is not compound, or hidden */
- if (agcmpgraph_of(cmpnode) == NILgraph)
+ if (agcmpgraph_of(cmpnode) == NULL)
return FAILURE;
noderec = (Agcmpnode_t *) aggetrec(cmpnode, Descriptor_id, FALSE);
Agnode_t *n;
Agcmpgraph_t *graphrec;
- if ((g != subg)
- && ((n = agsubnode(g, (Agnode_t *) node, FALSE)) == NILnode)) {
+ if (g != subg && (n = agsubnode(g, (Agnode_t *) node, FALSE)) == NULL) {
graphrec = (Agcmpgraph_t *) aggetrec(g, Descriptor_id, FALSE);
if (graphrec
&&
/* skip if this is not a collapsed subgraph */
noderec = (Agcmpnode_t *) aggetrec(cmpnode, Descriptor_id, FALSE);
- if ((noderec == NIL(Agcmpnode_t *) || NOT(noderec->collapsed)))
+ if (noderec == NULL || NOT(noderec->collapsed))
return FAILURE;
/* undo aghide (above) in reverse order. first, expose subgraph */
if (noderec && NOT(noderec->collapsed))
return noderec->subg;
else
- return NILgraph;
+ return NULL;
}
Agnode_t *agcmpnode_of(Agraph_t * g)
if (graphrec)
return graphrec->node;
else
- return NILnode;
+ return NULL;
}
Agnode_t *agfindhidden(Agraph_t * g, char *name)
key.name = name;
return (Agnode_t *) dtsearch(graphrec->hidden_node_set, &key);
} else
- return NILnode;
+ return NULL;
}
*************************************************************************/
#include <cgraph/cghdr.h>
+#include <stddef.h>
#define IN_SET FALSE
#define OUT_SET TRUE
Agedge_t *agfstout(Agraph_t * g, Agnode_t * n)
{
Agsubnode_t *sn;
- Agedge_t *e = NILedge;
+ Agedge_t *e = NULL;
sn = agsubrep(g, n);
if (sn) {
{
Agnode_t *n;
Agsubnode_t *sn;
- Agedge_t *f = NILedge;
+ Agedge_t *f = NULL;
n = AGTAIL(e);
sn = agsubrep(g, n);
Agedge_t *agfstin(Agraph_t * g, Agnode_t * n)
{
Agsubnode_t *sn;
- Agedge_t *e = NILedge;
+ Agedge_t *e = NULL;
sn = agsubrep(g, n);
if (sn) {
{
Agnode_t *n;
Agsubnode_t *sn;
- Agedge_t *f = NILedge;
+ Agedge_t *f = NULL;
n = AGHEAD(e);
sn = agsubrep(g, n);
{
Agedge_t *rv;
rv = agfstout(g, n);
- if (rv == NILedge)
+ if (rv == NULL)
rv = agfstin(g, n);
return rv;
}
if (AGTYPE(e) == AGOUTEDGE) {
rv = agnxtout(g, e);
- if (rv == NILedge) {
+ if (rv == NULL) {
do {
rv = !rv ? agfstin(g, n) : agnxtin(g,rv);
} while (rv && (rv->node == n));
Agedge_t *e, template;
Agsubnode_t *sn;
- if ((t == NILnode) || (h == NILnode))
- return NILedge;
+ if (t == NULL || h == NULL)
+ return NULL;
template.base.tag = key;
template.node = t; /* guess that fan-in < fan-out */
sn = agsubrep(g, h);
Agedge_t *e;
e = agfindedge_by_id(g, t, h, id);
- if ((e == NILedge) && agisundirected(g))
+ if (e == NULL && agisundirected(g))
e = agfindedge_by_id(g, h, t, id);
- if ((e == NILedge) && cflag && ok_to_make_edge(g, t, h)) {
+ if (e == NULL && cflag && ok_to_make_edge(g, t, h)) {
root = agroot(g);
if ((g != root) && ((e = agfindedge_by_id(root, t, h, id)))) {
subedge(g, e); /* old */
int have_id;
have_id = agmapnametoid(g, AGEDGE, name, &my_id, FALSE);
- if (have_id || ((name == NILstr) && (NOT(cflag) || agisstrict(g)))) {
+ if (have_id || (name == NULL && (NOT(cflag) || agisstrict(g)))) {
/* probe for pre-existing edge */
Agtag_t key;
key = Tag;
/* might already exist locally */
e = agfindedge_by_key(g, t, h, key);
- if ((e == NILedge) && agisundirected(g))
+ if (e == NULL && agisundirected(g))
e = agfindedge_by_key(g, h, t, key);
if (e)
return e;
if (cflag) {
e = agfindedge_by_key(agroot(g), t, h, key);
- if ((e == NILedge) && agisundirected(g))
+ if (e == NULL && agisundirected(g))
e = agfindedge_by_key(agroot(g), h, t, key);
if (e) {
subedge(g,e);
agregister(g, AGEDGE, e); /* register new object in external namespace */
}
else
- e = NILedge;
+ e = NULL;
return e;
}
int agdeledge(Agraph_t * g, Agedge_t * e)
{
e = AGMKOUT(e);
- if (agfindedge_by_key(g, agtail(e), aghead(e), AGTAG(e)) == NILedge)
+ if (agfindedge_by_key(g, agtail(e), aghead(e), AGTAG(e)) == NULL)
return FAILURE;
if (g == agroot(g)) {
agrecclose((Agobj_t *) e);
agfreeid(g, AGEDGE, AGID(e));
}
- if (agapply (g, (Agobj_t *) e, (agobjfn_t) agdeledgeimage, NILedge, FALSE) == SUCCESS) {
+ if (agapply (g, (Agobj_t *) e, (agobjfn_t) agdeledgeimage, NULL, FALSE) == SUCCESS) {
if (g == agroot(g))
agfree(g, e);
return SUCCESS;
Agnode_t *t, *h;
Agedge_t *rv;
- rv = NILedge;
+ rv = NULL;
t = agsubnode(g, AGTAIL(e), cflag);
h = agsubnode(g, AGHEAD(e), cflag);
if (t && h) {
rv = agfindedge_by_key(g, t, h, AGTAG(e));
- if (cflag && (rv == NILedge)) {
+ if (cflag && rv == NULL) {
installedge(g, e);
rv = e;
}
if (agmapnametoid(agraphof(t), AGEDGE, name, &id, FALSE))
return agfindedge_by_id(g, t, h, id);
else
- return NILedge;
+ return NULL;
}
#endif
#include <stdio.h> /* SAFE */
#include <cghdr.h> /* SAFE */
+#include <stddef.h>
extern void aagerror(char *);
#ifdef _WIN32
%%
graph : hdr body {freestack(); endgraph();}
- | error {if (G) {freestack(); endgraph(); agclose(G); G = Ag_G_global = NIL(Agraph_t*);}}
+ | error {if (G) {freestack(); endgraph(); agclose(G); G = Ag_G_global = NULL;}}
| /* empty */
;
nodelist : node | nodelist ',' node ;
-node : atom {appendnode($1,NIL(char*),NIL(char*));}
- | atom ':' atom {appendnode($1,$3,NIL(char*));}
+node : atom {appendnode($1,NULL,NULL);}
+ | atom ':' atom {appendnode($1,$3,NULL);}
| atom ':' atom ':' atom {appendnode($1,$3,$5);}
;
attrstmt : attrtype optmacroname attrlist {attrstmt($1,$2);}
- | graphattrdefs {attrstmt(T_graph,NIL(char*));}
+ | graphattrdefs {attrstmt(T_graph,NULL);}
;
attrtype : T_graph {$$ = T_graph;}
;
optmacroname : atom '=' {$$ = $1;}
- | /* empty */ {$$ = NIL(char*); }
+ | /* empty */ {$$ = NULL; }
;
optattr : attrlist | /* empty */ ;
attrassignment : atom '=' atom {appendattr($1,$3);}
;
-attrmacro : '@' atom {appendattr($2,NIL(char*));} /* not yet impl */
+attrmacro : '@' atom {appendattr($2,NULL);} /* not yet impl */
;
graphattrdefs : attrassignment
;
optsubghdr : T_subgraph atom {$$=$2;}
- | T_subgraph {$$=NIL(char*);}
- | /* empty */ {$$=NIL(char*);}
+ | T_subgraph {$$=NULL;}
+ | /* empty */ {$$=NULL;}
;
optseparator : ';' | ',' | /*empty*/ ;
;
%%
-#define NILitem NIL(item*)
-
-
static item *newitem(int tag, void *p0, char *p1)
{
item *rv = agalloc(G,sizeof(item));
{ return newitem(T_atom,name,value); }
static item *cons_list(item *list)
- { return newitem(T_list,list,NIL(char*)); }
+ { return newitem(T_list,list,NULL); }
static item *cons_subg(Agraph_t *subg)
- { return newitem(T_subgraph,subg,NIL(char*)); }
+ { return newitem(T_subgraph,subg,NULL); }
static gstack_t *push(gstack_t *s, Agraph_t *subg) {
gstack_t *rv;
#ifdef NOTDEF
static item *cons_edge(Agedge_t *e)
- { return newitem(T_edge,e,NIL(char*)); }
+ { return newitem(T_edge,e,NULL); }
#endif
static void delete_items(item *ilist)
#ifdef NOTDEF
static void initlist(list_t *list)
{
- list->first = list->last = NILitem;
+ list->first = list->last = NULL;
}
#endif
static void deletelist(list_t *list)
{
delete_items(list->first);
- list->first = list->last = NILitem;
+ list->first = list->last = NULL;
}
#ifdef NOTDEF
{
v->next = list->first;
list->first = v;
- if (list->last == NILitem) list->last = v;
+ if (list->last == NULL) list->last = v;
}
#endif
{
if (list->last) list->last->next = v;
list->last = v;
- if (list->first == NILitem) list->first = v;
+ if (list->first == NULL) list->first = v;
}
{
item *v;
- assert(value != NIL(char*));
+ assert(value != NULL);
v = cons_attr(name,value);
listapp(&(S->attrlist),v);
}
assert(aptr->tag == T_atom); /* signifies unbound attr */
name = aptr->u.name;
if ((kind == AGEDGE) && streq(name,Key)) continue;
- if ((aptr->u.asym = agattr(S->g,kind,name,NIL(char*))) == NILsym)
+ if ((aptr->u.asym = agattr(S->g,kind,name,NULL)) == NULL)
aptr->u.asym = agattr(S->g,kind,name,"");
aptr->tag = T_attr; /* signifies bound attr */
agstrfree(G,name);
if (macroname) nomacros();
/* invoking a macro def */
for (aptr = S->attrlist.first; aptr; aptr = aptr->next)
- if (aptr->str == NIL(char*)) nomacros();
+ if (aptr->str == NULL) nomacros();
switch(tkind) {
case T_graph: kind = AGRAPH; break;
if (S->nodelist.first) {
v = cons_list(S->nodelist.first);
- S->nodelist.first = S->nodelist.last = NILitem;
+ S->nodelist.first = S->nodelist.last = NULL;
}
else {if (S->subg) v = cons_subg(S->subg); S->subg = 0;}
/* else nil append */
bindattrs(AGEDGE);
/* look for "key" pseudo-attribute */
- key = NIL(char*);
+ key = NULL;
for (aptr = S->attrlist.first; aptr; aptr = aptr->next) {
if ((aptr->tag == T_atom) && streq(aptr->u.name,Key))
key = aptr->str;
if (p->tag == T_subgraph) {
subg = p->u.subg;
for (t = agfstnode(subg); t; t = agnxtnode(subg,t))
- edgerhs(agsubnode(S->g,t,FALSE),NIL(char*),p->next,key);
+ edgerhs(agsubnode(S->g,t,FALSE),NULL,p->next,key);
}
else {
for (tptr = p->u.list; tptr; tptr = tptr->next)
if (hlist->tag == T_subgraph) {
subg = hlist->u.subg;
for (head = agfstnode(subg); head; head = agnxtnode(subg,head))
- newedge(tail,tport,agsubnode(S->g,head,FALSE),NIL(char*),key);
+ newedge(tail,tport,agsubnode(S->g,head,FALSE),NULL,key);
}
else {
for (hptr = hlist->u.list; hptr; hptr = hptr->next)
{
Agsym_t *attr;
if (val) {
- if ((attr = agattr(S->g,AGEDGE,name,NIL(char*))) == NILsym)
+ if ((attr = agattr(S->g,AGEDGE,name,NULL)) == NULL)
attr = agattr(S->g,AGEDGE,name,"");
agxset(e,attr,val);
}
{
static Agdesc_t req; /* get rid of warnings */
- if (G == NILgraph) {
+ if (G == NULL) {
SubgraphDepth = 0;
req.directed = directed;
req.strict = strict;
Ag_G_global = G;
}
S = push(S,G);
- agstrfree(NIL(Agraph_t*),name);
+ agstrfree(NULL,name);
}
static void endgraph()
{
aagin = chan;
G = g;
- Ag_G_global = NILgraph;
+ Ag_G_global = NULL;
Disc = (disc? disc : &AgDefaultDisc);
aglexinit(Disc, chan);
aagparse();
- if (Ag_G_global == NILgraph) aglexbad();
+ if (Ag_G_global == NULL) aglexbad();
return Ag_G_global;
}
-Agraph_t *agread(void *fp, Agdisc_t *disc) {return agconcat(NILgraph,fp,disc); }
+Agraph_t *agread(void *fp, Agdisc_t *disc) {return agconcat(NULL,fp,disc); }
*************************************************************************/
#include <cgraph/cghdr.h>
+#include <stddef.h>
Agraph_t *Ag_G_global;
Agnode_t *n, *next_n;
par = agparent(g);
- if (par == NILgraph && AGDISC(g, mem)->close) {
+ if (par == NULL && AGDISC(g, mem)->close) {
/* free entire heap */
agmethod_delete(g, g); /* invoke user callbacks */
agfreeid(g, AGRAPH, AGID(g));
#include <stdio.h>
#include <cgraph/cghdr.h>
#include <inttypes.h>
+#include <stddef.h>
/* a default ID allocator that works off the shared string lib */
if (createflag) {
/* get a new anonymous ID, and store in the internal map */
- rv = (int) AGDISC(g, id)->map(AGCLOS(g, id), objtype, NILstr, result,
+ rv = (int) AGDISC(g, id)->map(AGCLOS(g, id), objtype, NULL, result,
createflag);
if (rv && str)
aginternalmapinsert(g, objtype, str, *result);
*************************************************************************/
#include <cgraph/cghdr.h>
+#include <stddef.h>
typedef struct IMapEntry_s {
Dtlink_t namedict_link;
0, /* object ptr is passed as key */
0, /* size (ignored) */
offsetof(IMapEntry_t, namedict_link),
- NIL(Dtmake_f),
- NIL(Dtfree_f),
+ NULL,
+ NULL,
namecmpf,
- NIL(Dthash_f),
+ NULL,
agdictobjmem,
- NIL(Dtevent_f)
+ NULL
};
static Dtdisc_t LookupById = {
0, /* object ptr is passed as key */
0, /* size (ignored) */
offsetof(IMapEntry_t, iddict_link),
- NIL(Dtmake_f),
- NIL(Dtfree_f),
+ NULL,
+ NULL,
idcmpf,
- NIL(Dthash_f),
+ NULL,
agdictobjmem,
- NIL(Dtevent_f)
+ NULL
};
int aginternalmaplookup(Agraph_t * g, int objtype, char *str,
if (objtype == AGINEDGE)
objtype = AGEDGE;
- if ((d_name_to_id = g->clos->lookup_by_name[objtype]) == NIL(Dict_t *))
+ if ((d_name_to_id = g->clos->lookup_by_name[objtype]) == NULL)
d_name_to_id = g->clos->lookup_by_name[objtype] =
agdtopen(g, &LookupByName, Dttree);
- if ((d_id_to_name = g->clos->lookup_by_id[objtype]) == NIL(Dict_t *))
+ if ((d_id_to_name = g->clos->lookup_by_id[objtype]) == NULL)
d_id_to_name = g->clos->lookup_by_id[objtype] =
agdtopen(g, &LookupById, Dttree);
dtinsert(d_name_to_id, ent);
itemplate.id = id;
isym = (IMapEntry_t *) dtsearch(d, &itemplate);
} else
- isym = NIL(IMapEntry_t *);
+ isym = NULL;
return isym;
}
if ((isym = find_isym(g, objtype, id)))
return isym->str;
- return NILstr;
+ return NULL;
}
for (i = 0; i < 3; i++) {
if (d[i]) {
dtclose(d[i]);
- d[i] = NIL(Dict_t *);
+ d[i] = NULL;
}
}
}
*************************************************************************/
#include <cgraph/cghdr.h>
+#include <stddef.h>
/* memory management discipline and entry points */
static void *memopen(Agdisc_t* disc)
{
- return NIL(void *);
+ return NULL;
}
static void *memalloc(void *heap, size_t request)
void *mem;
mem = AGDISC(g, mem)->alloc(AGCLOS(g, mem), size);
- if (mem == NIL(void *))
+ if (mem == NULL)
agerr(AGERR,"memory allocation failure");
return mem;
}
else
mem =
AGDISC(g, mem)->resize(AGCLOS(g, mem), ptr, oldsize, size);
- if (mem == NIL(void *))
+ if (mem == NULL)
agerr(AGERR,"memory re-allocation failure");
} else
- mem = NIL(void *);
+ mem = NULL;
return mem;
}
*************************************************************************/
#include <cgraph/cghdr.h>
+#include <stddef.h>
Agnode_t *agfindnode_by_id(Agraph_t * g, IDTYPE id)
{
dummy.base.tag.id = id;
template.node = &dummy;
sn = (Agsubnode_t *) dtsearch(g->n_id, &template);
- return sn ? sn->node : NILnode;
+ return sn ? sn->node : NULL;
}
static Agnode_t *agfindnode_by_name(Agraph_t * g, char *name)
if (agmapnametoid(g, AGNODE, name, &id, FALSE))
return agfindnode_by_id(g, id);
else
- return NILnode;
+ return NULL;
}
Agnode_t *agfstnode(Agraph_t * g)
{
Agsubnode_t *sn;
sn = (Agsubnode_t *) dtfirst(g->n_seq);
- return sn ? sn->node : NILnode;
+ return sn ? sn->node : NULL;
}
Agnode_t *agnxtnode(Agraph_t * g, Agnode_t * n)
Agsubnode_t *sn;
sn = agsubrep(g, n);
if (sn) sn = ((Agsubnode_t *) dtnext(g->n_seq, sn));
- return sn ? sn->node : NILnode;
+ return sn ? sn->node : NULL;
}
Agnode_t *aglstnode(Agraph_t * g)
{
Agsubnode_t *sn;
sn = (Agsubnode_t *) dtlast(g->n_seq);
- return sn ? sn->node : NILnode;
+ return sn ? sn->node : NULL;
}
Agnode_t *agprvnode(Agraph_t * g, Agnode_t * n)
Agsubnode_t *sn;
sn = agsubrep(g, n);
if (sn) sn = ((Agsubnode_t *) dtprev(g->n_seq, sn));
- return sn ? sn->node : NILnode;
+ return sn ? sn->node : NULL;
}
Agnode_t *n;
n = agfindnode_by_id(g, id);
- if ((n == NILnode) && cflag) {
+ if (n == NULL && cflag) {
root = agroot(g);
if ((g != root) && ((n = agfindnode_by_id(root, id)))) /*old */
agsubnode(g, n, TRUE); /* insert locally */
installnodetoroot(g, n);
initnode(g, n);
} else
- n = NILnode; /* allocid for new node failed */
+ n = NULL; /* allocid for new node failed */
}
}
/* else return probe result */
return n;
}
- return NILnode;
+ return NULL;
}
/* removes image of node and its edges from graph.
agrecclose((Agobj_t *) n);
agfreeid(g, AGNODE, AGID(n));
}
- if (agapply (g, (Agobj_t *) n, (agobjfn_t) agdelnodeimage, NILnode, FALSE) == SUCCESS) {
+ if (agapply (g, (Agobj_t *) n, (agobjfn_t) agdelnodeimage, NULL, FALSE) == SUCCESS) {
if (g == agroot(g))
agfree(g, n);
return SUCCESS;
if (agfindnode_by_name(g, newname))
return FAILURE;
if (agmapnametoid(g, AGNODE, newname, &new_id, TRUE)) {
- if (agfindnode_by_id(agroot(g), new_id) == NILnode) {
+ if (agfindnode_by_id(agroot(g), new_id) == NULL) {
agfreeid(g, AGNODE, AGID(n));
agapply(g, (Agobj_t *) n, (agobjfn_t) dict_relabel,
(void *) &new_id, FALSE);
Agnode_t *n;
if (agroot(g) != n0->root)
- return NILnode;
+ return NULL;
n = agfindnode_by_id(g, AGID(n0));
- if ((n == NILnode) && cflag) {
+ if (n == NULL && cflag) {
if ((par = agparent(g))) {
n = agsubnode(par, n0, cflag);
installnode(g, n);
*************************************************************************/
#include <cgraph/cghdr.h>
+#include <stddef.h>
int agdelete(Agraph_t * g, void *obj)
{
if (g->clos->callbacks_enabled)
aginitcb(g, obj, g->clos->cb);
else
- agrecord_callback(g, obj, CB_INITIALIZE, NILsym);
+ agrecord_callback(g, obj, CB_INITIALIZE, NULL);
}
void aginitcb(Agraph_t * g, void *obj, Agcbstack_t * cbstack)
{
agobjfn_t fn;
- if (cbstack == NIL(Agcbstack_t *))
+ if (cbstack == NULL)
return;
aginitcb(g, obj, cbstack->prev);
- fn = NIL(agobjfn_t);
+ fn = NULL;
switch (AGTYPE(obj)) {
case AGRAPH:
fn = cbstack->f->graph.ins;
{
agobjupdfn_t fn;
- if (cbstack == NIL(Agcbstack_t *))
+ if (cbstack == NULL)
return;
agupdcb(g, obj, sym, cbstack->prev);
- fn = NIL(agobjupdfn_t);
+ fn = NULL;
switch (AGTYPE(obj)) {
case AGRAPH:
fn = cbstack->f->graph.mod;
if (g->clos->callbacks_enabled)
agdelcb(g, obj, g->clos->cb);
else
- agrecord_callback(g, obj, CB_DELETION, NILsym);
+ agrecord_callback(g, obj, CB_DELETION, NULL);
}
void agdelcb(Agraph_t * g, void *obj, Agcbstack_t * cbstack)
{
agobjfn_t fn;
- if (cbstack == NIL(Agcbstack_t *))
+ if (cbstack == NULL)
return;
agdelcb(g, obj, cbstack->prev);
- fn = NIL(agobjfn_t);
+ fn = NULL;
switch (AGTYPE(obj)) {
case AGRAPH:
fn = cbstack->f->graph.del;
Agraph_t *agroot(void* obj)
{
// fixes CVE-2019-11023 by moving the problem to the caller :-)
- if (obj == 0) return NILgraph;
+ if (obj == 0) return NULL;
switch (AGTYPE(obj)) {
case AGINEDGE:
case AGOUTEDGE:
return ((Agraph_t *) obj)->root;
default: /* actually can't occur if only 2 bit tags */
agerr(AGERR, "agroot of a bad object");
- return NILgraph;
+ return NULL;
}
}
return (Agraph_t *) obj;
default: /* actually can't occur if only 2 bit tags */
agerr(AGERR, "agraphof a bad object");
- return NILgraph;
+ return NULL;
}
}
*************************************************************************/
#include <cgraph/cghdr.h>
+#include <stddef.h>
static char DRName[] = "_AG_pending";
offsetof(pending_cb_t, key), /* sort by 'key' */
sizeof(uint64_t),
0, /* link offset */
- NIL(Dtmake_f),
+ NULL,
freef,
- NIL(Dtcompar_f),
- NIL(Dthash_f)
+ NULL,
+ NULL
};
static Dict_t *dictof(pendingset_t * ds, Agobj_t * obj, int kind)
{
- Dict_t **dict_ref = NIL(Dict_t **);
+ Dict_t **dict_ref = NULL;
dict_ref = 0;
switch (AGTYPE(obj)) {
if (dict_ref == 0)
agerr(AGERR, "pend dictof a bad object");
- if (*dict_ref == NIL(Dict_t *))
+ if (*dict_ref == NULL)
*dict_ref = agdtopen(agraphof(obj), &Disc, Dttree);
return *dict_ref;
}
{
symlist_t *sym, *nsym, *psym;
- psym = NIL(symlist_t *);
+ psym = NULL;
for (sym = handle->symlist; sym; psym = sym, sym = sym->link) {
if (sym->sym == optsym)
break;
- if (sym == NIL(symlist_t *)) {
+ if (sym == NULL) {
nsym = agalloc(agraphof(obj), sizeof(symlist_t));
nsym->sym = optsym;
if (psym)
*************************************************************************/
#include <cgraph/cghdr.h>
+#include <stddef.h>
/*
* run time records
break;
d = d->next;
if (d == first) {
- d = NIL(Agrec_t *);
+ d = NULL;
break;
}
}
NOTUSED(g);
newrec = arg;
firstrec = obj->data;
- if (firstrec == NIL(Agrec_t *))
+ if (firstrec == NULL)
newrec->next = newrec; /* 0 elts */
else {
if (firstrec->next == firstrec) {
obj = arg_obj;
g = agraphof(obj);
rec = aggetrec(obj, recname, FALSE);
- if (rec == NIL(Agrec_t *) && recsize > 0) {
+ if (rec == NULL && recsize > 0) {
rec = agalloc(g, recsize);
rec->name = agstrdup(g, recname);
objputrec(g, obj, rec);
Agrec_t *rec = (Agrec_t *) arg_rec, *newrec;
if (obj->data == rec) {
if (rec->next == rec)
- newrec = NIL(Agrec_t *);
+ newrec = NULL;
else
newrec = rec->next;
set_data(obj, newrec, FALSE);
rec = nrec;
} while (rec != obj->data);
}
- obj->data = NIL(Agrec_t *);
+ obj->data = NULL;
}
*************************************************************************/
#include <cgraph/cghdr.h>
+#include <stddef.h>
/*
* reference counted strings.
offsetof(refstr_t, s), /* key */
-1, /* size */
0, /* link offset */
- NIL(Dtmake_f),
+ NULL,
agdictobjfree,
- NIL(Dtcompar_f),
- NIL(Dthash_f),
+ NULL,
+ NULL,
agdictobjmem,
- NIL(Dtevent_f)
+ NULL
};
static Dict_t *Refdict_default;
dictref = &(g->clos->strdict);
else
dictref = &Refdict_default;
- if (*dictref == NIL(Dict_t *)) {
+ if (*dictref == NULL) {
*dictref = agdtopen(g, &Refstrdisc, Dttree);
HTML_BIT = ((unsigned int) 1) << (sizeof(unsigned int) * 8 - 1);
CNT_BITS = ~HTML_BIT;
if (r)
return r->s;
else
- return NIL(char *);
+ return NULL;
}
char *agstrbind(Agraph_t * g, char *s)
Dict_t *strdict;
size_t sz;
- if (s == NIL(char *))
- return NIL(char *);
+ if (s == NULL)
+ return NULL;
strdict = refdict(g);
r = refsymbind(strdict, s);
if (r)
Dict_t *strdict;
size_t sz;
- if (s == NIL(char *))
- return NIL(char *);
+ if (s == NULL)
+ return NULL;
strdict = refdict(g);
r = refsymbind(strdict, s);
if (r)
refstr_t *r;
Dict_t *strdict;
- if (s == NIL(char *))
+ if (s == NULL)
return FAILURE;
strdict = refdict(g);
*/
}
}
- if (r == NIL(refstr_t *))
+ if (r == NULL)
return FAILURE;
return SUCCESS;
}
#include <cghdr.h>
#include <agxbuf.h>
#include <ctype.h>
+#include <stddef.h>
// #define YY_BUF_SIZE 128000
#define GRAPH_EOF_TOKEN '@' /* lex class must be defined below */
/* this is a workaround for linux flex */
/* buffer for arbitrary length strings (longer than BUFSIZ) */
static char *Sbuf,*Sptr,*Send;
static void beginstr(void) {
- if (Sbuf == NIL(char*)) {
+ if (Sbuf == NULL) {
Sbuf = malloc(BUFSIZ);
Send = Sbuf + BUFSIZ;
}
*************************************************************************/
#include <cgraph/cghdr.h>
+#include <stddef.h>
static Agraph_t *agfindsubg_by_id(Agraph_t * g, IDTYPE id)
{
{
Agraph_t *subg;
subg = agfindsubg_by_id(g, id);
- if ((subg == NILgraph) && cflag && agallocid(g, AGRAPH, id))
+ if (subg == NULL && cflag && agallocid(g, AGRAPH, id))
subg = localsubg(g, id);
return subg;
}
return subg;
}
- return NILgraph;
+ return NULL;
}
Agraph_t *agfstsubg(Agraph_t * g)
*************************************************************************/
#include <cgraph/cghdr.h>
+#include <stddef.h>
static Agraph_t *Ag_dictop_G;
else
return malloc(size);
}
- return NIL(void *);
+ return NULL;
}
void agdictobjfree(Dict_t * dict, void * p, Dtdisc_t * disc)
Ag_dictop_G = g;
d = dtopen(disc, method);
disc->memoryf = memf;
- Ag_dictop_G = NIL(Agraph_t*);
+ Ag_dictop_G = NULL;
return d;
}
Dtmemory_f memf;
Dtdisc_t *disc;
- disc = dtdisc(dict, NIL(Dtdisc_t *), 0);
+ disc = dtdisc(dict, NULL, 0);
memf = disc->memoryf;
disc->memoryf = agdictobjmem;
Ag_dictop_G = g;
if (dtclose(dict))
return 1;
disc->memoryf = memf;
- Ag_dictop_G = NIL(Agraph_t*);
+ Ag_dictop_G = NULL;
return 0;
}
void agdtdisc(Agraph_t * g, Dict_t * dict, Dtdisc_t * disc)
{
- if (disc && (dtdisc(dict, NIL(Dtdisc_t *), 0) != disc)) {
+ if (disc && dtdisc(dict, NULL, 0) != disc) {
dtdisc(dict, disc, 0);
}
/* else unchanged, disc is same as old disc */
* Contributors: See CVS logs. Details at http://www.graphviz.org/
*************************************************************************/
+#include <stddef.h>
#include <stdio.h> /* need sprintf() */
#include <ctype.h>
#include <cgraph/cghdr.h>
int backslash_pending = FALSE;
static const char *tokenlist[] /* must agree with scan.l */
= { "node", "edge", "strict", "graph", "digraph", "subgraph",
- NIL(char *)
+ NULL
};
const char **tok;
Agsym_t *sym, *psym;
if (!top)
- view = dtview(dict, NIL(Dict_t *));
+ view = dtview(dict, NULL);
else
view = 0;
for (sym = (Agsym_t *) dtfirst(dict); sym;
sym = (Agsym_t *) dtnext(dict, sym)) {
if (EMPTY(sym->defval) && !sym->print) { /* try to skip empty str (default) */
- if (view == NIL(Dict_t *))
+ if (view == NULL)
continue; /* no parent */
psym = (Agsym_t *) dtsearch(view, sym);
assert(psym);
kind = "";
if (agisstrict(g))
strict = "strict ";
- Tailport = agattr(g, AGEDGE, TAILPORT_ID, NIL(char *));
- Headport = agattr(g, AGEDGE, HEADPORT_ID, NIL(char *));
+ Tailport = agattr(g, AGEDGE, TAILPORT_ID, NULL);
+ Headport = agattr(g, AGEDGE, HEADPORT_ID, NULL);
}
name = agnameof(g);
sep = " ";
static int has_no_edges(Agraph_t * g, Agnode_t * n)
{
- return ((agfstin(g, n) == NIL(Agedge_t *))
- && (agfstout(g, n) == NIL(Agedge_t *)));
+ return agfstin(g, n) == NULL && agfstout(g, n) == NULL;
}
static int has_no_predecessor_below(Agraph_t * g, Agnode_t * n,
Agdatadict_t *dd;
/* int has_attr; */
- /* has_attr = (agattrrec(g) != NIL(Agattr_t*)); */
+ /* has_attr = agattrrec(g) != NULL; */
CHKRV(write_subgs(g, ofile));
dd = agdatadict(g, FALSE);
#include <circogen/edgelist.h>
#include <circogen/nodeset.h>
#include <circogen/deglist.h>
+#include <stddef.h>
/* The code below lays out a single block on a circle.
*/
clone = agsubg(ing, gname,1);
agbindrec(clone, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); //node custom data
sprintf(gname, "_clone_%d", id++);
- xclone = agopen(gname, ing->desc,NIL(Agdisc_t *));
+ xclone = agopen(gname, ing->desc,NULL);
for (n = agfstnode(ing); n; n = agnxtnode(ing, n)) {
agsubnode(clone,n,1);
xn = agnode(xclone, agnameof(n),1);
#include <neatogen/adjust.h>
#include <pack/pack.h>
#include <neatogen/neatoprocs.h>
+#include <stddef.h>
#include <string.h>
static void circular_init_edge(edge_t * e)
Agedge_t *ep;
Agnode_t *p;
- dg = agopen("derived", Agstrictundirected,NIL(Agdisc_t *));
+ dg = agopen("derived", Agstrictundirected,NULL);
agbindrec (dg, "info", sizeof(Agraphinfo_t), TRUE);
GD_alg(g) = dg; /* store derived graph for closing later */
#include <common/intset.h>
#include <cdt/cdt.h>
#include <cgraph/strcasecmp.h>
+#include <stddef.h>
#define DEFAULT_BORDER 1
#define DEFAULT_CELLPADDING 2
tbl->heights = N_NEW(tbl->rc + 1, int);
tbl->widths = N_NEW(tbl->cc + 1, int);
- rowg = agopen("rowg", dir, NIL(Agdisc_t *));
- colg = agopen("colg", dir, NIL(Agdisc_t *));
+ rowg = agopen("rowg", dir, NULL);
+ colg = agopen("colg", dir, NULL);
/* Only need GD_nlist */
agbindrec(rowg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); // graph custom data
agbindrec(colg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); // graph custom data
#include <xdot/xdot.h>
#include <cgraph/agxbuf.h>
#include <cgraph/strcasecmp.h>
+#include <stddef.h>
static char *usageFmt =
"Usage: %s [-Vv?] [-(GNE)name=val] [-(KTlso)<val>] <dot files>\n";
#ifdef EXPERIMENTAL_MYFGETS
g = agread_usergets(fp, myfgets);
#else
- g = agread(fp,NIL(Agdisc_t*));
+ g = agread(fp,NULL);
#endif
if (g) {
gvg_init(gvc, g, fn, gidx++);
#include <dotgen/dot.h>
#include <math.h>
+#include <stddef.h>
#ifdef ORTHO
#include <ortho/ortho.h>
Agsym_t* sym;
graph_t* auxg;
if (agisdirected(g))
- auxg = agopen ("auxg",Agdirected, NIL(Agdisc_t *));
+ auxg = agopen ("auxg",Agdirected, NULL);
else
- auxg = agopen ("auxg",Agundirected, NIL(Agdisc_t *));
+ auxg = agopen ("auxg",Agundirected, NULL);
agbindrec(auxg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);
agattr(auxg, AGRAPH, "rank", "");
GD_drawing(auxg) = NEW(layout_t);
gvc = job->gvc;
if (!filename) {
- g = agread(stdin,NIL(Agdisc_t *)); // continue processing stdin
+ g = agread(stdin,NULL); // continue processing stdin
}
else {
f = fopen(filename, "r");
if (!f)
return; /* FIXME - need some error handling */
- g = agread(f,NIL(Agdisc_t *));
+ g = agread(f,NULL);
fclose(f);
}
#include "config.h"
+#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
char bufa[100], *buf1, *buf2, bufb[100], *p, *q, *lq, *t;
int api, neededge_loadimage, neededge_device;
- g = agopen("G", Agdirected, NIL(Agdisc_t *));
+ g = agopen("G", Agdirected, NULL);
agattr(g, AGRAPH, "label", "");
agattr(g, AGRAPH, "rankdir", "");
agattr(g, AGRAPH, "rank", "");
#include <neatogen/neato.h>
#include <neatogen/adjust.h>
+#include <stddef.h>
/* For precision, scale up before algorithms, then scale down */
#define SCALE 10
offsetof(nitem, val),
sizeof(int),
offsetof(nitem, link),
- NIL(Dtmake_f),
- NIL(Dtfree_f),
+ NULL,
+ NULL,
(Dtcompar_f) cmpitem,
- NIL(Dthash_f),
- NIL(Dtmemory_f),
- NIL(Dtevent_f)
+ NULL,
+ NULL,
+ NULL
};
static int distY(box * b1, box * b2)
node_t *n;
edge_t *e;
node_t *lastn = NULL;
- graph_t *cg = agopen("cg", Agstrictdirected, NIL(Agdisc_t *));
+ graph_t *cg = agopen("cg", Agstrictdirected, NULL);
agbindrec(cg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); // graph custom data
for (p = (nitem *) dtflatten(list); p;
int lcnt, cnt;
int oldval = -INT_MAX;
node_t *lastn = NULL;
- graph_t *cg = agopen("cg", Agstrictdirected, NIL(Agdisc_t *));
+ graph_t *cg = agopen("cg", Agstrictdirected, NULL);
agbindrec(cg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); // graph custom data
/* count distinct nodes */
* Remaining outedges are immediate right neighbors.
* FIX: Incremental algorithm to construct trans. reduction?
*/
- vg = agopen("vg", Agstrictdirected, NIL(Agdisc_t *));
+ vg = agopen("vg", Agstrictdirected, NULL);
for (p = (nitem *) dtflatten(list); p;
p = (nitem *) dtlink(list, (Dtlink_t *) p)) {
n = agnode(vg, agnameof(p->np), 1); /* FIX */
* Contributors: See CVS logs. Details at http://www.graphviz.org/
*************************************************************************/
-
+#include <stddef.h>
#include <stdio.h>
#include <pathplan/vis.h>
}
}
- if (Left != NIL(ilcoord_t *))
+ if (Left != NULL)
for (j = 0; j <= degree; j++)
Left[j] = Vtemp[j][0];
- if (Right != NIL(ilcoord_t *))
+ if (Right != NULL)
for (j = 0; j <= degree; j++)
Right[j] = Vtemp[degree - j][j];
return (Vtemp[degree][0]);
*************************************************************************/
#include <sfio/sfhdr.h>
+#include <stddef.h>
/* Close a stream. A file stream is synced before closing.
**
int sfclose(Sfio_t * f)
{
int local, ex, rv;
- void *data = NIL(void *);
+ void *data = NULL;
SFMTXSTART(f, -1);
while (f->push) {
Sfio_t *pop;
- if (!(pop = (*_Sfstack) (f, NIL(Sfio_t *))))
+ if (!(pop = (*_Sfstack) (f, NULL)))
SFMTXRETURN(f, -1);
if (sfclose(pop) < 0) {
(*_Sfstack) (f, pop);
rv = 0;
if (f->disc == _Sfudisc) /* closing the ungetc stream */
- f->disc = NIL(Sfdisc_t *);
+ f->disc = NULL;
else if (f->file >= 0) { /* sync file pointer */
f->bits |= SF_ENDING;
rv = sfsync(f);
/* raise discipline exceptions */
if (f->disc
&& (ex =
- SFRAISE(f, local ? SF_NEW : SF_CLOSING, NIL(void *))) != 0)
+ SFRAISE(f, local ? SF_NEW : SF_CLOSING, NULL)) != 0)
SFMTXRETURN(f, ex);
if (!local && f->pool) { /* remove from pool */
}
f->mode |= SF_LOCK;
}
- f->pool = NIL(Sfpool_t *);
+ f->pool = NULL;
}
if (f->data && (!local || (f->flags & SF_STRING) || (f->bits & SF_MMAP))) { /* free buffer */
if (f->flags & SF_MALLOC)
data = (void *) f->data;
- f->data = NIL(uchar *);
+ f->data = NULL;
f->size = -1;
}
/* zap any associated auxiliary buffer */
free(f->rsrv);
- f->rsrv = NIL(Sfrsrv_t *);
+ f->rsrv = NULL;
/* delete any associated sfpopen-data */
if (f->proc)
rv = _sfpclose(f);
if (!local) {
- if (f->disc && (ex = SFRAISE(f, SF_FINAL, NIL(void *))) != 0) {
+ if (f->disc && (ex = SFRAISE(f, SF_FINAL, NULL)) != 0) {
rv = ex;
goto done;
}
if (!(f->flags & SF_STATIC))
free(f);
else {
- f->disc = NIL(Sfdisc_t *);
- f->stdio = NIL(void *);
+ f->disc = NULL;
+ f->stdio = NULL;
f->mode = SF_AVAIL;
}
}
*************************************************************************/
#include <sfio/sfhdr.h>
+#include <stddef.h>
/* Set a new discipline for a stream.
**
Sfseek_f oseekf;
ssize_t n;
- SFMTXSTART(f, NIL(Sfdisc_t *));
+ SFMTXSTART(f, NULL);
if ((f->flags & SF_READ) && f->proc && (f->mode & SF_WRITE)) { /* make sure in read mode to check for read-ahead data */
if (_sfmode(f, SF_READ, 0) < 0)
- SFMTXRETURN(f, NIL(Sfdisc_t *));
+ SFMTXRETURN(f, NULL);
} else if ((f->mode & SF_RDWR) != f->mode && _sfmode(f, 0, 0) < 0)
- SFMTXRETURN(f, NIL(Sfdisc_t *));
+ SFMTXRETURN(f, NULL);
SFLOCK(f, 0);
- rdisc = NIL(Sfdisc_t *);
+ rdisc = NULL;
/* synchronize before switching to a new discipline */
if (!(f->flags & SF_STRING)) {
int rv = 0;
exceptf = disc ? disc->exceptf :
- f->disc ? f->disc->exceptf : NIL(Sfexcept_f);
+ f->disc ? f->disc->exceptf : NULL;
/* check with application for course of action */
if (exceptf) {
/* save old readf, writef, and seekf to see if stream need reinit */
#define GETDISCF(func,iof,type) \
{ for(d = f->disc; d && !d->iof; d = d->disc) ; \
- func = d ? d->iof : NIL(type); \
+ func = d ? d->iof : NULL; \
}
GETDISCF(oreadf, readf, Sfread_f);
GETDISCF(owritef, writef, Sfwrite_f);
if (!(f->flags & SF_STRING)) { /* this stream may have to be reinitialized */
int reinit = 0;
-#define DISCF(dst,iof,type) (dst ? dst->iof : NIL(type))
+#define DISCF(dst,iof,type) (dst ? dst->iof : NULL)
#define REINIT(oiof,iof,type) \
if(!reinit) \
{ for(d = f->disc; d && !d->iof; d = d->disc) ; \
SETLOCAL(f);
f->bits &= (unsigned short)~SF_NULL; /* turn off /dev/null handling */
if ((f->bits & SF_MMAP) || (f->mode & SF_INIT))
- sfsetbuf(f, NIL(void *), (size_t) SF_UNBOUND);
+ sfsetbuf(f, NULL, (size_t) SF_UNBOUND);
else if (f->data == f->tiny)
- sfsetbuf(f, NIL(void *), 0);
+ sfsetbuf(f, NULL, 0);
else {
unsigned short flags = f->flags;
sfsetbuf(f, (void *) f->data, f->size);
*************************************************************************/
#include <sfio/sfhdr.h>
+#include <stddef.h>
/* Function to handle io exceptions.
** Written by Kiem-Phong Vo
SFOPEN(f, 0);
/* pop and close */
- pf = (*_Sfstack) (f, NIL(Sfio_t *));
+ pf = (*_Sfstack) (f, NULL);
if ((ev = sfclose(pf)) < 0) /* can't close, restack */
(*_Sfstack) (f, pf);
*************************************************************************/
#include <sfio/sfhdr.h>
+#include <stddef.h>
#include <stdint.h>
static char *Version = "\n@(#)sfio (AT&T Labs - kpv) 2001-02-01\0\n";
/* set this so that no more buffering is allowed for write streams */
_Sfexiting = 1001;
- sfsync(NIL(Sfio_t *));
+ sfsync(NULL);
for (p = &_Sfpool; p; p = p->next) {
for (n = 0; n < p->n_sf; ++n) {
SFLOCK(f, 0);
/* let application know that we are leaving */
- (void) SFRAISE(f, SF_ATEXIT, NIL(void *));
+ (void) SFRAISE(f, SF_ATEXIT, NULL);
if (f->flags & SF_STRING)
continue;
(void) _sfmode(f, SF_WRITE, 1);
if (((f->bits & SF_MMAP) && f->data) ||
((f->mode & SF_WRITE) && f->next == f->data))
- (void) SFSETBUF(f, NIL(void *), 0);
+ (void) SFSETBUF(f, NULL, 0);
f->mode |= pool;
SFOPEN(f, 0);
if (rsrv && size > 0)
rsrv->slen = 0;
- return size >= 0 ? rsrv : NIL(Sfrsrv_t *);
+ return size >= 0 ? rsrv : NULL;
}
#ifdef SIGPIPE
p->pid = pid;
p->size = p->ndata = 0;
- p->rdata = NIL(uchar *);
+ p->rdata = NULL;
p->file = fd;
p->sigp = (!stdio && pid >= 0 && (f->flags & SF_WRITE)) ? 1 : 0;
if (!(p = f->proc))
return -1;
- f->proc = NIL(Sfproc_t *);
+ f->proc = NULL;
free(p->rdata);
(*_Sfstdsync) (f);
if (f->disc == _Sfudisc && wanted == SF_WRITE &&
- sfclose((*_Sfstack) (f, NIL(Sfio_t *))) < 0) {
+ sfclose((*_Sfstack) (f, NULL)) < 0) {
local = 1;
goto err_notify;
}
f->mode = SF_WRITE | SF_LOCK;
if (f->data == f->tiny) {
- f->endb = f->data = f->next = NIL(uchar *);
+ f->endb = f->data = f->next = NULL;
f->size = 0;
} else
f->endb = (f->next = f->data) + f->size;
*************************************************************************/
#include <sfio/sfhdr.h>
+#include <stddef.h>
/* Fundamental function to create a new stream.
** The argument flags defines the type of stream and the scheme
int sflags;
if (!(flags & SF_RDWR))
- return NIL(Sfio_t *);
+ return NULL;
sflags = 0;
if ((f = oldf)) {
if (flags & SF_EOF) {
- oldf = NIL(Sfio_t *);
+ oldf = NULL;
} else if (f->mode & SF_AVAIL) { /* only allow SF_STATIC to be already closed */
if (!(f->flags & SF_STATIC))
- return NIL(Sfio_t *);
+ return NULL;
sflags = f->flags;
- oldf = NIL(Sfio_t *);
+ oldf = NULL;
} else { /* reopening an open stream, close it first */
sflags = f->flags;
if (((f->mode & SF_RDWR) != f->mode && _sfmode(f, 0, 0) < 0) ||
SFCLOSE(f) < 0)
- return NIL(Sfio_t *);
+ return NULL;
if (f->data
&& ((flags & SF_STRING) || size != (size_t) SF_UNBOUND)) {
if (sflags & SF_MALLOC)
free(f->data);
- f->data = NIL(uchar *);
+ f->data = NULL;
}
if (!f->data)
sflags &= (unsigned short)~SF_MALLOC;
if (f->mode & SF_AVAIL) {
sflags = f->flags;
} else
- f = NIL(Sfio_t *);
+ f = NULL;
}
}
if (!f) {
if (!(f = malloc(sizeof(Sfio_t))))
- return NIL(Sfio_t *);
+ return NULL;
SFCLEAR(f);
}
}
f->mode |= SF_INIT;
if (size != (size_t) SF_UNBOUND) {
f->size = size;
- f->data = size <= 0 ? NIL(uchar *) : (uchar *) buf;
+ f->data = size <= 0 ? NULL : (uchar *) buf;
}
f->endb = f->endr = f->endw = f->next = f->data;
*************************************************************************/
#include <sfio/sfhdr.h>
+#include <stddef.h>
#ifdef _WIN32
#include <io.h>
#endif
int fd, oldfd, oflags, sflags;
/* get the control flags */
- if ((sflags = _sftype(mode, &oflags, NIL(int *))) == 0)
- return NIL(Sfio_t *);
+ if ((sflags = _sftype(mode, &oflags, NULL)) == 0)
+ return NULL;
/* usually used on the standard streams to change control flags */
#ifndef _WIN32
if (f && !file && (f->mode & SF_INIT)) {
- SFMTXSTART(f, NIL(Sfio_t *));
+ SFMTXSTART(f, NULL);
if (f->mode & SF_INIT) { /* paranoia in case another thread snuck in */
if (f->file >= 0 && !(f->flags & SF_STRING) && (oflags &= (O_TEXT | O_BINARY | O_APPEND)) != 0) { /* set the wanted file access control flags */
SFMTXRETURN(f, f);
} else
- SFMTXRETURN(f, NIL(Sfio_t *));
+ SFMTXRETURN(f, NULL);
}
#endif
SF_UNBOUND, -1, sflags);
} else {
if (!file)
- return NIL(Sfio_t *);
+ return NULL;
#if _has_oflags /* open the file */
while ((fd = open(file, oflags, SF_CREATMODE)) < 0
if (fd >= 0) {
if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) {
CLOSE(fd); /* error: file already exists */
- return NIL(Sfio_t *);
+ return NULL;
}
if (oflags & O_TRUNC) { /* truncate file */
int tf;
}
#endif
if (fd < 0)
- return NIL(Sfio_t *);
+ return NULL;
/* we may have to reset the file descriptor to its old value */
oldfd = f ? f->file : -1;
- if ((f = sfnew(f, NIL(char *), (size_t) SF_UNBOUND, fd, sflags))
+ if ((f = sfnew(f, NULL, (size_t) SF_UNBOUND, fd, sflags))
&& oldfd >= 0)
(void) sfsetfd(f, oldfd);
}
*************************************************************************/
#include <sfio/sfhdr.h>
+#include <stddef.h>
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
pbuf.flags = 0;
pbuf.ctlbuf.maxlen = -1;
pbuf.ctlbuf.len = 0;
- pbuf.ctlbuf.buf = NIL(char *);
+ pbuf.ctlbuf.buf = NULL;
pbuf.databuf.maxlen = n;
pbuf.databuf.buf = buf;
pbuf.databuf.len = 0;
FD_ZERO(&rd);
FD_SET(fd, &rd);
if (tm < 0)
- tmp = NIL(struct timeval *);
+ tmp = NULL;
else {
tmp = &tmb;
tmb.tv_sec = tm / SECOND;
tmb.tv_usec = (tm % SECOND) * SECOND;
}
- r = select(fd + 1, &rd, NIL(fd_set *), NIL(fd_set *), tmp);
+ r = select(fd + 1, &rd, NULL, NULL, tmp);
if (r < 0) {
if (errno == EINTR)
return -1;
*************************************************************************/
#include <sfio/sfhdr.h>
+#include <stddef.h>
/* Put out a null-terminated string
**
w += 1;
break;
}
- if ((ps = (uchar *) memccpy(ps, s, '\0', p)) != NIL(uchar *))
+ if ((ps = (uchar *) memccpy(ps, s, '\0', p)) != NULL)
ps -= 1;
else
ps = f->next + p;
*************************************************************************/
#include <sfio/sfhdr.h>
+#include <stddef.h>
/* Set the IO pointer to a specific location in the stream
**
/* throw away ungetc data */
if (f->disc == _Sfudisc)
- (void) sfclose((*_Sfstack) (f, NIL(Sfio_t *)));
+ (void) sfclose((*_Sfstack) (f, NULL));
/* lock the stream for internal manipulations */
SFLOCK(f, local);
* Contributors: See CVS logs. Details at http://www.graphviz.org/
*************************************************************************/
+#include <stddef.h>
+
#if defined(__STDPP__directive) && defined(__STDPP__hide)
__STDPP__directive pragma pp:hide getpagesize
#else
int oflags, init, local;
Stat_t st;
- SFMTXSTART(f, NIL(void *));
+ SFMTXSTART(f, NULL);
GETLOCAL(f, local);
/* cleanup actions already done, don't allow write buffering any more */
if (_Sfexiting && !(f->flags & SF_STRING) && (f->mode & SF_WRITE)) {
- buf = NIL(void *);
+ buf = NULL;
size = 0;
}
if ((init = f->mode & SF_INIT)) {
if (!f->pool && _sfsetpool(f) < 0)
- SFMTXRETURN(f, NIL(void *));
+ SFMTXRETURN(f, NULL);
} else if ((f->mode & SF_RDWR) != SFMODE(f, local)
&& _sfmode(f, 0, local) < 0)
- SFMTXRETURN(f, NIL(void *));
+ SFMTXRETURN(f, NULL);
if (init)
f->mode = (f->mode & SF_RDWR) | SF_LOCK;
/* make sure there is no hidden read data */
if (f->proc && (f->flags & SF_READ) && (f->mode & SF_WRITE) &&
_sfmode(f, SF_READ, local) < 0)
- SFMTXRETURN(f, NIL(void *));
+ SFMTXRETURN(f, NULL);
/* synchronize first */
SFLOCK(f, local);
rv = SFSYNC(f);
SFOPEN(f, local);
if (rv < 0)
- SFMTXRETURN(f, NIL(void *));
+ SFMTXRETURN(f, NULL);
/* turn off the SF_SYNCED bit because buffer is changing */
f->mode &= ~SF_SYNCED;
oflags = f->flags;
if (f->data == f->tiny) {
- f->data = NIL(uchar *);
+ f->data = NULL;
f->size = 0;
}
obuf = f->data;
else if ((ssize_t) (size = _Sfpage) < blksize)
size = blksize;
- buf = NIL(void *);
+ buf = NULL;
}
sf_malloc = 0;
if (size > 0 && !buf && !(f->bits & SF_MMAP)) { /* try to allocate a buffer */
if (obuf && size == (size_t) osize && init) {
buf = (void *) obuf;
- obuf = NIL(uchar *);
+ obuf = NULL;
sf_malloc = (oflags & SF_MALLOC);
}
if (!buf) { /* do allocation */
if (obuf && obuf != f->data && osize > 0 && (oflags & SF_MALLOC)) {
free(obuf);
- obuf = NIL(uchar *);
+ obuf = NULL;
}
_Sfi = f->val = obuf ? osize : 0;
rf = f1;
} else { /* unfreeze the just exposed stream */
f1->mode &= ~SF_PUSH;
- f2->push = NIL(Sfio_t *);
+ f2->push = NULL;
rf = f2;
}
*************************************************************************/
#include <sfio/sfhdr.h>
+#include <stddef.h>
/* Swap two streams. If the second argument is NULL,
** a new stream will be created. Always return the second argument
if (!f1 || (f1->mode & SF_AVAIL)
|| (SFFROZEN(f1) && (f1->mode & SF_PUSH)))
- return NIL(Sfio_t *);
+ return NULL;
if (f2 && SFFROZEN(f2) && (f2->mode & SF_PUSH))
- return NIL(Sfio_t *);
+ return NULL;
if (f1 == f2)
return f2;
} else {
f2 = f1->file == 0 ? sfstdin :
f1->file == 1 ? sfstdout :
- f1->file == 2 ? sfstderr : NIL(Sfio_t *);
+ f1->file == 2 ? sfstderr : NULL;
if ((!f2 || !(f2->mode & SF_AVAIL))) {
if (!(f2 = malloc(sizeof(Sfio_t)))) {
f1->mode = f1mode;
SFOPEN(f1, 0);
- return NIL(Sfio_t *);
+ return NULL;
}
SFCLEAR(f2);
*************************************************************************/
#include <sfio/sfhdr.h>
+#include <stddef.h>
/* Synchronize data in buffers with the file system.
** If f is nil, all streams are sync-ed
GETLOCAL(origf, local);
if (origf->disc == _Sfudisc) /* throw away ungetc */
- (void) sfclose((*_Sfstack) (origf, NIL(Sfio_t *)));
+ (void) sfclose((*_Sfstack) (origf, NULL));
rv = 0;
*************************************************************************/
#include <sfio/sfhdr.h>
+#include <stddef.h>
/* Dealing with $ argument addressing stuffs.
**
int argp, argn, maxp, need[FP_INDEX];
if (type < 0)
- fp = NIL(Fmtpos_t *);
+ fp = NULL;
else if (!(fp = sffmtpos(f, form, args, -1)))
- return NIL(Fmtpos_t *);
+ return NULL;
dollar = 0;
decimal = thousand = 0;
}
flags = dot = 0;
- t_str = NIL(char *);
+ t_str = NULL;
n_str = 0;
size = width = precis = base = -1;
for (n = 0; n < FP_INDEX; ++n)
switch (*form++) {
case 0: /* not balancable, retract */
form = t_str;
- t_str = NIL(char *);
+ t_str = NULL;
n_str = 0;
goto loop_flags;
case LEFTP: /* increasing nested level */
maxp = argp;
if (dollar && fmt == '!')
- return NIL(Fmtpos_t *);
+ return NULL;
if (fp && fp[argp].ft.fmt == 0) {
fp[argp].ft.form = (char *) form;
if (!fp) { /* constructing position array only */
if (!dollar
|| !(fp = malloc((maxp + 1) * sizeof(Fmtpos_t))))
- return NIL(Fmtpos_t *);
+ return NULL;
for (n = 0; n <= maxp; ++n)
fp[n].ft.fmt = 0;
return fp;
}
/* get value for positions */
- for (n = 0, ft = NIL(Sffmt_t *); n <= maxp; ++n) {
+ for (n = 0, ft = NULL; n <= maxp; ++n) {
if (fp[n].ft.fmt == 0) { /* gap: pretend it's a 'd' pattern */
fp[n].ft.fmt = 'd';
fp[n].ft.width = 0;
memcpy(&fp[n].ft, ft, sizeof(Sffmt_t));
if (v < 0) {
memcpy(ft, &savft, sizeof(Sffmt_t));
- ft = NIL(Sffmt_t *);
+ ft = NULL;
}
if (!(fp[n].ft.flags & SFFMT_VALUE))
memcpy(ft, &savft, sizeof(Sffmt_t));
fp[n].argv.ft = ft = va_arg(args, Sffmt_t *);
if (ft->form)
- ft = NIL(Sffmt_t *);
+ ft = NULL;
if (ft)
memcpy(&savft, ft, sizeof(Sffmt_t));
} else if (type > 0) /* from sfvscanf */
*************************************************************************/
#include <sfio/sfhdr.h>
+#include <stddef.h>
char **_sfgetpath(char *path)
{
int n;
if (!(path = getenv(path)))
- return NIL(char **);
+ return NULL;
for (p = path, n = 0;;) { /* count number of directories */
while (*p == ':')
++p;
}
if (n == 0 || !(dirs = malloc((n + 1) * sizeof(char *))))
- return NIL(char **);
+ return NULL;
if (!(p = malloc(strlen(path) + 1))) {
free(dirs);
- return NIL(char **);
+ return NULL;
}
strcpy(p, path);
for (n = 0;; ++n) {
if (*p == ':')
*p++ = 0;
}
- dirs[n] = NIL(char *);
+ dirs[n] = NULL;
return dirs;
}
*************************************************************************/
#include <sfio/sfhdr.h>
+#include <stddef.h>
/* Push back one byte to a given SF_READ stream
**
/* close the unget stream */
if (type != SF_CLOSING)
- (void) sfclose((*_Sfstack) (f, NIL(Sfio_t *)));
+ (void) sfclose((*_Sfstack) (f, NULL));
return 1;
}
/* make a string stream for unget characters */
if (f->disc != _Sfudisc) {
- if (!(uf = sfnew(NIL(Sfio_t *), NIL(char *), (size_t) SF_UNBOUND,
+ if (!(uf = sfnew(NULL, NULL, (size_t) SF_UNBOUND,
-1, SF_STRING | SF_READ))) {
c = -1;
goto done;
#include <inttypes.h>
#include <sfio/sfhdr.h>
+#include <stddef.h>
/* The engine for formatting data
**
}
SFINIT(f);
- tls[1] = NIL(char *);
+ tls[1] = NULL;
- fmstk = NIL(Fmt_t *);
- ft = NIL(Sffmt_t *);
+ fmstk = NULL;
+ ft = NULL;
oform = (char *) form;
va_copy(oargs, args);
- fp = NIL(Fmtpos_t *);
+ fp = NULL;
argn = -1;
loop_fmt:
flags = 0;
size = width = precis = base = n_s = argp = -1;
ssp = _Sfdigits;
- endep = ep = NIL(char *);
+ endep = ep = NULL;
endsp = sp = buf + (sizeof(buf) - 1);
- t_str = NIL(char *);
+ t_str = NULL;
n_str = dot = 0;
loop_flags: /* LOOP FOR \0, %, FLAGS, WIDTH, PRECISION, BASE, TYPE */
switch (*form++) {
case 0: /* not balancable, retract */
form = t_str;
- t_str = NIL(char *);
+ t_str = NULL;
n_str = 0;
goto loop_flags;
case LEFTP: /* increasing nested level */
n_str = fp[n].ft.size;
} else if (ft && ft->extf) {
FMTSET(ft, form, args,
- LEFTP, 0, 0, 0, 0, 0, NIL(char *), 0);
+ LEFTP, 0, 0, 0, 0, 0, NULL, 0);
n = (*ft->extf)
(f, (void *) & argv, ft);
if (n < 0)
if (fp)
v = fp[n].argv.i;
else if (ft && ft->extf) {
- FMTSET(ft, form, args, '.', dot, 0, 0, 0, 0, NIL(char *),
+ FMTSET(ft, form, args, '.', dot, 0, 0, 0, 0, NULL,
0);
if ((*ft->extf) (f, (void *) (&argv), ft) < 0)
goto pop_fmt;
size = fp[n].argv.i;
else if (ft && ft->extf) {
FMTSET(ft, form, args, 'I', sizeof(int), 0, 0, 0, 0,
- NIL(char *), 0);
+ NULL, 0);
if ((*ft->extf) (f, (void *) (&argv), ft) < 0)
goto pop_fmt;
if (ft->flags & SFFMT_VALUE)
form = argv.ft->form;
va_copy(args, argv.ft->args);
argn = -1;
- fp = NIL(Fmtpos_t *);
+ fp = NULL;
} else
- fm->form = NIL(char *);
+ fm->form = NULL;
fm->eventf = argv.ft->eventf;
fm->ft = ft;
pop_fmt:
free(fp);
- fp = NIL(Fmtpos_t *);
+ fp = NULL;
while ((fm = fmstk)) { /* pop the format stack and continue */
if (fm->eventf) {
if (!form || !form[0])
- (*fm->eventf) (f, SF_FINAL, NIL(void *), ft);
+ (*fm->eventf) (f, SF_FINAL, NULL, ft);
else if ((*fm->eventf) (f, SF_DPOP, (void *) form, ft) < 0)
goto loop_fmt;
}
free(fp);
while ((fm = fmstk)) {
if (fm->eventf)
- (*fm->eventf) (f, SF_FINAL, NIL(void *), fm->ft);
+ (*fm->eventf) (f, SF_FINAL, NULL, fm->ft);
fmstk = fm->next;
free(fm);
}
n = f->next - f->data;
if ((d = f->data) == (uchar *) data)
- f->endw = f->endr = f->endb = f->data = NIL(uchar *);
+ f->endw = f->endr = f->endb = f->data = NULL;
f->next = f->data;
if ((((flags = f->flags) & SF_SHARE) && !(flags & SF_PUBLIC)) ||
#include <inttypes.h>
#include <sfio/sfhdr.h>
+#include <stddef.h>
/* The main engine for reading formatted data
**
inp = -1;
- fmstk = NIL(Fmt_t *);
- ft = NIL(Sffmt_t *);
+ fmstk = NULL;
+ ft = NULL;
- fp = NIL(Fmtpos_t *);
+ fp = NULL;
argn = -1;
oform = (char *) form;
va_copy(oargs, args);
base = 10;
size = -1;
width = dot = 0;
- t_str = NIL(char *);
+ t_str = NULL;
n_str = 0;
- value = NIL(void *);
+ value = NULL;
argp = -1;
loop_flags: /* LOOP FOR FLAGS, WIDTH, BASE, TYPE */
switch (*form++) {
case 0: /* not balanceable, retract */
form = t_str;
- t_str = NIL(char *);
+ t_str = NULL;
n_str = 0;
goto loop_flags;
case LEFTP: /* increasing nested level */
n_str = fp[n].ft.size;
} else if (ft && ft->extf) {
FMTSET(ft, form, args,
- LEFTP, 0, 0, 0, 0, 0, NIL(char *), 0);
+ LEFTP, 0, 0, 0, 0, 0, NULL, 0);
n = (*ft->extf)
(f, (void *) & argv, ft);
if (n < 0)
v = fp[n].argv.i;
else if (ft && ft->extf) {
FMTSET(ft, form, args, '.', dot, 0, 0, 0, 0,
- NIL(char *), 0);
+ NULL, 0);
if ((*ft->extf) (f, (void *) (&argv), ft) < 0)
goto pop_fmt;
if (ft->flags & SFFMT_VALUE)
size = fp[n].argv.i;
else if (ft && ft->extf) {
FMTSET(ft, form, args, 'I', sizeof(int), 0, 0, 0, 0,
- NIL(char *), 0);
+ NULL, 0);
if ((*ft->extf) (f, (void *) (&argv), ft) < 0)
goto pop_fmt;
if (ft->flags & SFFMT_VALUE)
form = argv.ft->form;
va_copy(args, argv.ft->args);
argn = -1;
- fp = NIL(Fmtpos_t *);
+ fp = NULL;
} else
- fm->form = NIL(char *);
+ fm->form = NULL;
fm->eventf = argv.ft->eventf;
fm->ft = ft;
if (value) {
*val = '\0';
- argv.d = (double) strtod(accept, NIL(char **));
+ argv.d = (double) strtod(accept, NULL);
}
if (value) {
pop_fmt:
free(fp);
- fp = NIL(Fmtpos_t *);
+ fp = NULL;
while ((fm = fmstk)) { /* pop the format stack and continue */
if (fm->eventf) {
if (!form || !form[0])
- (*fm->eventf) (f, SF_FINAL, NIL(void *), ft);
+ (*fm->eventf) (f, SF_FINAL, NULL, ft);
else if ((*fm->eventf) (f, SF_DPOP, (void *) form, ft) < 0)
goto loop_fmt;
}
free(fp);
while ((fm = fmstk)) {
if (fm->eventf)
- (*fm->eventf) (f, SF_FINAL, NIL(void *), fm->ft);
+ (*fm->eventf) (f, SF_FINAL, NULL, fm->ft);
fmstk = fm->next;
free(fm);
}
*************************************************************************/
#include <sfio/sfhdr.h>
+#include <stddef.h>
/* Write with discipline.
**
/* seek to a rounded boundary within the hole */
if (s >= _Sfpage) {
s = (s / _Sfpage) * _Sfpage;
- if (SFSK(f, (Sfoff_t) s, SEEK_CUR, NIL(Sfdisc_t *)) < 0)
+ if (SFSK(f, (Sfoff_t) s, SEEK_CUR, NULL) < 0)
break;
w += s;
n -= s;