/* agxbmore;
* Expand buffer to hold at least ssz more bytes.
*/
-int agxbmore(agxbuf * xb, unsigned int ssz)
+int agxbmore(agxbuf * xb, size_t ssz)
{
- int cnt; /* current no. of characters in buffer */
- int size; /* current buffer size */
- int nsize; /* new buffer size */
+ size_t cnt; /* current no. of characters in buffer */
+ size_t size; /* current buffer size */
+ size_t nsize; /* new buffer size */
unsigned char *nbuf; /* new buffer */
size = xb->eptr - xb->buf;
/* agxbput_n:
* Append string s of length n onto xb
*/
-int agxbput_n(agxbuf * xb, const char *s, unsigned int ssz)
+size_t agxbput_n(agxbuf * xb, const char *s, size_t ssz)
{
if (xb->ptr + ssz > xb->eptr)
agxbmore(xb, ssz);
/* agxbput:
* Append string s into xb
*/
-int agxbput(agxbuf * xb, const char *s)
+size_t agxbput(agxbuf * xb, const char *s)
{
- unsigned int ssz = strlen(s);
+ size_t ssz = strlen(s);
return agxbput_n(xb, s, ssz);
}
/* agxbput_n:
* Append string s of length n into xb
*/
- extern int agxbput_n(agxbuf * xb, const char *s, unsigned int n);
+ extern size_t agxbput_n(agxbuf * xb, const char *s, size_t n);
/* agxbput:
* Append string s into xb
*/
- extern int agxbput(agxbuf * xb, const char *s);
+ extern size_t agxbput(agxbuf * xb, const char *s);
/* agxbfree:
* Free any malloced resources.
/* agxbmore:
* Expand buffer to hold at least ssz more bytes.
*/
- extern int agxbmore(agxbuf * xb, int unsigned ssz);
+ extern int agxbmore(agxbuf * xb, size_t ssz);
/* agxbputc:
* Add character to buffer.
void agmarkhtmlstr(char *s);
/* object set management */
-Agnode_t *agfindnode_by_id(Agraph_t * g, unsigned long id);
+Agnode_t *agfindnode_by_id(Agraph_t * g, IDTYPE id);
Dtcompar_f agdictorder(Agraph_t *, Dict_t *, Dtcompar_f);
int agedgecmpf(Dict_t * d, void *arg_e0, void *arg_e1, Dtdisc_t * disc);
int agnamecmpf(Dict_t * d, void *, void *, Dtdisc_t * disc);
/* ID management */
int agmapnametoid(Agraph_t * g, int objtype, char *str,
- unsigned long *result, int allocflag);
-int agallocid(Agraph_t * g, int objtype, unsigned long request);
-void agfreeid(Agraph_t * g, int objtype, unsigned long id);
+ IDTYPE *result, int allocflag);
+int agallocid(Agraph_t * g, int objtype, IDTYPE request);
+void agfreeid(Agraph_t * g, int objtype, IDTYPE id);
char *agprintid(Agobj_t * obj);
int aginternalmaplookup(Agraph_t * g, int objtype, char *str,
- unsigned long *result);
+ IDTYPE *result);
void aginternalmapinsert(Agraph_t * g, int objtype, char *str,
- unsigned long result);
-char *aginternalmapprint(Agraph_t * g, int objtype, unsigned long id);
-int aginternalmapdelete(Agraph_t * g, int objtype, unsigned long id);
+ IDTYPE result);
+char *aginternalmapprint(Agraph_t * g, int objtype, IDTYPE id);
+int aginternalmapdelete(Agraph_t * g, int objtype, IDTYPE id);
void aginternalmapclose(Agraph_t * g);
void agregister(Agraph_t * g, int objtype, void *obj);
#define NILedge NIL(Agedge_t*)
#define NILsym NIL(Agsym_t*)
+/* avoid loss when casting pointer to unsigned long on Win64 */
+typedef uintptr_t IDTYPE;
+
/* forward struct type declarations */
typedef struct Agtag_s Agtag_t;
typedef struct Agobj_s Agobj_t; /* generic object header */
unsigned mtflock:1; /* move-to-front lock, see above */
unsigned attrwf:1; /* attrs written (parity, write.c) */
unsigned seq:(sizeof(unsigned) * 8 - 4); /* sequence no. */
- unsigned long id; /* client ID */
+ IDTYPE id; /* client ID */
};
/* object tags */
struct Agiddisc_s { /* object ID allocator */
void *(*open) (Agraph_t * g, Agdisc_t*); /* associated with a graph */
- long (*map) (void *state, int objtype, char *str, unsigned long *id,
+ long (*map) (void *state, int objtype, char *str, IDTYPE *id,
int createflag);
- long (*alloc) (void *state, int objtype, unsigned long id);
- void (*free) (void *state, int objtype, unsigned long id);
- char *(*print) (void *state, int objtype, unsigned long id);
+ long (*alloc) (void *state, int objtype, IDTYPE id);
+ void (*free) (void *state, int objtype, IDTYPE id);
+ char *(*print) (void *state, int objtype, IDTYPE id);
void (*close) (void *state);
void (*idregister) (void *state, int objtype, void *obj);
};
/* nodes */
extern Agnode_t *agnode(Agraph_t * g, char *name, int createflag);
-extern Agnode_t *agidnode(Agraph_t * g, unsigned long id, int createflag);
+extern Agnode_t *agidnode(Agraph_t * g, IDTYPE id, int createflag);
extern Agnode_t *agsubnode(Agraph_t * g, Agnode_t * n, int createflag);
extern Agnode_t *agfstnode(Agraph_t * g);
extern Agnode_t *agnxtnode(Agraph_t * g, Agnode_t * n);
extern Agedge_t *agedge(Agraph_t * g, Agnode_t * t, Agnode_t * h,
char *name, int createflag);
extern Agedge_t *agidedge(Agraph_t * g, Agnode_t * t, Agnode_t * h,
- unsigned long id, int createflag);
+ IDTYPE id, int createflag);
extern Agedge_t *agsubedge(Agraph_t * g, Agedge_t * e, int createflag);
extern Agedge_t *agfstin(Agraph_t * g, Agnode_t * n);
extern Agedge_t *agnxtin(Agraph_t * g, Agedge_t * e);
/* defintions for subgraphs */
extern Agraph_t *agsubg(Agraph_t * g, char *name, int cflag); /* constructor */
-extern Agraph_t *agidsubg(Agraph_t * g, unsigned long id, int cflag); /* constructor */
+extern Agraph_t *agidsubg(Agraph_t * g, IDTYPE id, int cflag); /* constructor */
extern Agraph_t *agfstsubg(Agraph_t * g), *agnxtsubg(Agraph_t * subg);
extern Agraph_t *agparent(Agraph_t * g);
}
static Agedge_t *agfindedge_by_id(Agraph_t * g, Agnode_t * t, Agnode_t * h,
- unsigned long id)
+ IDTYPE id)
{
Agtag_t tag;
}
static Agedge_t *newedge(Agraph_t * g, Agnode_t * t, Agnode_t * h,
- unsigned long id)
+ IDTYPE id)
{
Agedgepair_t *e2;
Agedge_t *in, *out;
}
Agedge_t *agidedge(Agraph_t * g, Agnode_t * t, Agnode_t * h,
- unsigned long id, int cflag)
+ IDTYPE id, int cflag)
{
Agraph_t *root;
Agedge_t *e;
int cflag)
{
Agedge_t *e;
- unsigned long id;
+ IDTYPE id;
int have_id;
have_id = agmapnametoid(g, AGEDGE, name, &id, FALSE);
/* edge comparison. OBJTYPE(e) == 0 means ID is a wildcard. */
int agedgeidcmpf(Dict_t * d, void *arg_e0, void *arg_e1, Dtdisc_t * disc)
{
- long v;
+ long long v;
Agedge_t *e0, *e1;
NOTUSED(d);
/* edge comparison. for ordered traversal. */
int agedgeseqcmpf(Dict_t * d, void *arg_e0, void *arg_e1, Dtdisc_t * disc)
{
- long v;
+ long long v;
Agedge_t *e0, *e1;
NOTUSED(d);
{
Agraph_t *g;
Agclos_t *clos;
- unsigned long gid;
+ IDTYPE gid;
clos = agclos(arg_disc);
g = clos->disc.mem->alloc(clos->state.mem, sizeof(Agraph_t));
int agraphidcmpf(Dict_t * d, void *arg0, void *arg1, Dtdisc_t * disc)
{
- long v;
+ ptrdiff_t v;
Agraph_t *sg0, *sg1;
sg0 = (Agraph_t *) arg0;
sg1 = (Agraph_t *) arg1;
return g;
}
-static long idmap(void *state, int objtype, char *str, unsigned long *id,
+static long idmap(void *state, int objtype, char *str, IDTYPE *id,
int createflag)
{
char *s;
- static unsigned long ctr = 1;
+ static IDTYPE 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;
+ Agraph_t *g;
+ g = state;
+ if (createflag)
+ s = agstrdup(g, str);
+ else
+ s = agstrbind(g, str);
+ *id = (IDTYPE) s;
} else {
- *id = ctr;
- ctr += 2;
+ *id = ctr;
+ ctr += 2;
}
return TRUE;
}
/* we don't allow users to explicitly set IDs, either */
-static long idalloc(void *state, int objtype, unsigned long request)
+static long idalloc(void *state, int objtype, IDTYPE request)
{
NOTUSED(state);
NOTUSED(objtype);
return FALSE;
}
-static void idfree(void *state, int objtype, unsigned long id)
+static void idfree(void *state, int objtype, IDTYPE id)
{
NOTUSED(objtype);
if (id % 2 == 0)
agstrfree((Agraph_t *) state, (char *) id);
}
-static char *idprint(void *state, int objtype, unsigned long id)
+static char *idprint(void *state, int objtype, IDTYPE id)
{
NOTUSED(state);
NOTUSED(objtype);
/* aux functions incl. support for disciplines with anonymous IDs */
int agmapnametoid(Agraph_t * g, int objtype, char *str,
- unsigned long *result, int createflag)
+ IDTYPE *result, int createflag)
{
int rv;
return rv;
}
-int agallocid(Agraph_t * g, int objtype, unsigned long request)
+int agallocid(Agraph_t * g, int objtype, IDTYPE request)
{
return AGDISC(g, id)->alloc(AGCLOS(g, id), objtype, request);
}
-void agfreeid(Agraph_t * g, int objtype, unsigned long id)
+void agfreeid(Agraph_t * g, int objtype, IDTYPE id)
{
(void) aginternalmapdelete(g, objtype, id);
(AGDISC(g, id)->free) (AGCLOS(g, id), objtype, id);
typedef struct IMapEntry_s {
Dtlink_t namedict_link;
Dtlink_t iddict_link;
- unsigned long id;
+ IDTYPE id;
char *str;
} IMapEntry_t;
p0 = arg_p0;
p1 = arg_p1;
NOTUSED(disc);
- return (p0->id - p1->id);
+ if (p0->id > p1->id)
+ {
+ return 1;
+ }
+ else if (p0->id < p1->id)
+ {
+ return -1;
+ }
+ else
+ {
+ return 0;
+ }
}
/* note, OK to compare pointers into shared string pool
p0 = arg_p0;
p1 = arg_p1;
NOTUSED(disc);
- return (p0->str - p1->str);
+ if (p0->str > p1->str)
+ {
+ return 1;
+ }
+ else if (p0->str < p1->str)
+ {
+ return -1;
+ }
+ else
+ {
+ return 0;
+ }
}
static Dtdisc_t LookupByName = {
};
int aginternalmaplookup(Agraph_t * g, int objtype, char *str,
- unsigned long *result)
+ IDTYPE *result)
{
Dict_t *d;
IMapEntry_t *sym, template;
/* caller GUARANTEES that this is a new entry */
void aginternalmapinsert(Agraph_t * g, int objtype, char *str,
- unsigned long id)
+ IDTYPE id)
{
IMapEntry_t *ent;
Dict_t *d_name_to_id, *d_id_to_name;
dtinsert(d_id_to_name, ent);
}
-static IMapEntry_t *find_isym(Agraph_t * g, int objtype, unsigned long id)
+static IMapEntry_t *find_isym(Agraph_t * g, int objtype, IDTYPE id)
{
Dict_t *d;
IMapEntry_t *isym, itemplate;
return isym;
}
-char *aginternalmapprint(Agraph_t * g, int objtype, unsigned long id)
+char *aginternalmapprint(Agraph_t * g, int objtype, IDTYPE id)
{
IMapEntry_t *isym;
}
-int aginternalmapdelete(Agraph_t * g, int objtype, unsigned long id)
+int aginternalmapdelete(Agraph_t * g, int objtype, IDTYPE id)
{
IMapEntry_t *isym;
#include <cghdr.h>
-Agnode_t *agfindnode_by_id(Agraph_t * g, unsigned long id)
+Agnode_t *agfindnode_by_id(Agraph_t * g, IDTYPE id)
{
Agsubnode_t *sn;
static Agsubnode_t template;
Agnode_t *agfindnode_by_name(Agraph_t * g, char *name)
{
- unsigned long id;
+ IDTYPE id;
if (agmapnametoid(g, AGNODE, name, &id, FALSE))
return agfindnode_by_id(g, id);
/* internal node constructor */
-static Agnode_t *newnode(Agraph_t * g, unsigned long id, unsigned long seq)
+static Agnode_t *newnode(Agraph_t * g, IDTYPE id, unsigned long seq)
{
Agnode_t *n;
}
/* external node constructor - create by id */
-Agnode_t *agidnode(Agraph_t * g, unsigned long id, int cflag)
+Agnode_t *agidnode(Agraph_t * g, IDTYPE id, int cflag)
{
Agraph_t *root;
Agnode_t *n;
{
Agraph_t *root;
Agnode_t *n;
- unsigned long id;
+ IDTYPE id;
root = agroot(g);
/* probe for existing node */
int agrelabel_node(Agnode_t * n, char *newname)
{
Agraph_t *g;
- unsigned long new_id;
+ IDTYPE new_id;
g = agroot(agraphof(n));
if (agfindnode_by_name(g, newname))
int agsubnodeidcmpf(Dict_t * d, void *arg0, void *arg1, Dtdisc_t * disc)
{
- long v;
+ long long v;
Agsubnode_t *sn0, *sn1;
sn0 = (Agsubnode_t *) arg0;
sn1 = (Agsubnode_t *) arg1;
int agrename(Agobj_t * obj, char *newname)
{
Agraph_t *g;
- unsigned long old_id, new_id;
+ IDTYPE old_id, new_id;
switch (AGTYPE(obj)) {
case AGRAPH:
/* this record describes one pending callback on one object */
typedef struct {
Dtlink_t link;
- unsigned long key; /* universal key for main or sub-object */
+ IDTYPE key; /* universal key for main or sub-object */
Agraph_t *g;
Agobj_t *obj;
symlist_t *symlist; /* attributes involved */
return *dict_ref;
}
-static unsigned long genkey(Agobj_t * obj)
+static IDTYPE genkey(Agobj_t * obj)
{
return obj->tag.id;
}
#include <cghdr.h>
-static Agraph_t *agfindsubg_by_id(Agraph_t * g, unsigned long id)
+static Agraph_t *agfindsubg_by_id(Agraph_t * g, IDTYPE id)
{
Agraph_t template;
return (Agraph_t *) dtsearch(g->g_dict, &template);
}
-static Agraph_t *localsubg(Agraph_t * g, unsigned long id)
+static Agraph_t *localsubg(Agraph_t * g, IDTYPE id)
{
Agraph_t *subg;
return agopen1(subg);
}
-Agraph_t *agidsubg(Agraph_t * g, unsigned long id, int cflag)
+Agraph_t *agidsubg(Agraph_t * g, IDTYPE id, int cflag)
{
Agraph_t *subg;
subg = agfindsubg_by_id(g, id);
Agraph_t *agsubg(Agraph_t * g, char *name, int cflag)
{
- unsigned long id;
+ IDTYPE id;
Agraph_t *subg;
if (name && agmapnametoid(g, AGRAPH, name, &id, FALSE)) {
static char *getoutputbuffer(char *str)
{
static char *rv;
- static int len;
- int req;
+ static size_t len = 0;
+ size_t req;
req = MAX(2 * strlen(str) + 2, BUFSIZ);
if (req > len) {