00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _GRAPH_H
00020 #define _GRAPH_H 1
00021
00022 #if _PACKAGE_ast
00023 #include <ast.h>
00024 #else
00025 #include <sys/types.h>
00026 #include <stdlib.h>
00027 #endif
00028 #include <stdio.h>
00029 #include "cdt.h"
00030
00031 #ifdef __cplusplus
00032 extern "C" {
00033 #endif
00034
00035 #define TAIL_ID "tailport"
00036 #define HEAD_ID "headport"
00037
00038 typedef struct Agraph_t Agraph_t;
00039 typedef struct Agnode_t Agnode_t;
00040 typedef struct Agedge_t Agedge_t;
00041 typedef struct Agdict_t Agdict_t;
00042 typedef struct Agsym_t Agsym_t;
00043 typedef struct Agdata_t Agdata_t;
00044 typedef struct Agproto_t Agproto_t;
00045
00046 typedef char *(*gets_f) (char *ubuf, int n, FILE * fp);
00047
00048 #define AGFLAG_DIRECTED (1<<0)
00049 #define AGFLAG_STRICT (1<<1)
00050 #define AGFLAG_METAGRAPH (1<<2)
00051
00052 #define AGRAPH 0
00053 #define AGRAPHSTRICT (AGRAPH | AGFLAG_STRICT)
00054 #define AGDIGRAPH AGFLAG_DIRECTED
00055 #define AGDIGRAPHSTRICT (AGDIGRAPH | AGFLAG_STRICT)
00056 #define AGMETAGRAPH (AGFLAG_DIRECTED | AGFLAG_STRICT | AGFLAG_METAGRAPH)
00057
00058 #define AG_IS_DIRECTED(g) ((g)->kind & AGFLAG_DIRECTED)
00059 #define AG_IS_STRICT(g) ((g)->kind & AGFLAG_STRICT)
00060 #define AG_IS_METAGRAPH(g) ((g)->kind & AGFLAG_METAGRAPH)
00061 #define aginit() aginitlib(sizeof(Agraph_t),sizeof(Agnode_t),sizeof(Agedge_t))
00062
00063 struct Agraph_t {
00064 int tag:4;
00065 int kind:4;
00066 int handle:24;
00067 char **attr;
00068 char *didset;
00069 char *name;
00070 Agdata_t *univ;
00071 Dict_t *nodes, *inedges, *outedges;
00072 Agraph_t *root;
00073 Agnode_t *meta_node;
00074 Agproto_t *proto;
00075 Agraphinfo_t u;
00076 };
00077
00078 struct Agnode_t {
00079 int tag:4;
00080 int pad:4;
00081 int handle:24;
00082 char **attr;
00083 char *didset;
00084 char *name;
00085 int id;
00086 Agraph_t *graph;
00087 Agnodeinfo_t u;
00088 };
00089
00090 struct Agedge_t {
00091 int tag:4;
00092 int printkey:4;
00093 int handle:24;
00094 char **attr;
00095 char *didset;
00096 Agnode_t *head, *tail;
00097 int id;
00098 Agedgeinfo_t u;
00099 };
00100
00101 struct Agdata_t {
00102 Dict_t *node_dict;
00103 Agdict_t *nodeattr;
00104 Agdict_t *edgeattr;
00105 Agdict_t *globattr;
00106 int max_node_id, max_edge_id;
00107 };
00108
00109 struct Agsym_t {
00110 char *name, *value;
00111 int index;
00112 unsigned char printed;
00113 unsigned char fixed;
00114 };
00115
00116 struct Agdict_t {
00117 char *name;
00118 Dict_t *dict;
00119 Agsym_t **list;
00120 };
00121
00122 struct Agproto_t {
00123 Agnode_t *n;
00124 Agedge_t *e;
00125 Agproto_t *prev;
00126 };
00127
00128 #if _PACKAGE_ast
00129 _BEGIN_EXTERNS_
00130 #if _BLD_graph && defined(__EXPORT__)
00131 #define extern __EXPORT__
00132 #endif
00133 #if !_BLD_graph && defined(__IMPORT__) && 0
00134 #define extern __IMPORT__
00135 #endif
00136 #endif
00137 extern char *agstrcanon(char *, char *);
00138 extern char *agcanonical(char *);
00139 extern int aghtmlstr(char *s);
00140 extern char *agget(void *, char *);
00141 extern char *agxget(void *, int);
00142 extern int agset(void *, char *, char *);
00143 extern int agsafeset(void *, char *, char *, char*);
00144 extern int agxset(void *, int, char *);
00145 extern int agindex(void *, char *);
00146
00147 extern void aginitlib(int, int, int);
00148 extern Agraph_t *agopen(char *, int);
00149 extern Agraph_t *agsubg(Agraph_t *, char *);
00150 extern Agraph_t *agfindsubg(Agraph_t *, char *);
00151 extern void agclose(Agraph_t *);
00152 extern Agraph_t *agread(FILE *);
00153 extern Agraph_t *agread_usergets(FILE *, gets_f);
00154 extern void agreadline(int);
00155 extern void agsetfile(char *);
00156 extern Agraph_t *agmemread(char *);
00157 extern int agwrite(Agraph_t *, FILE *);
00158 extern int agerrors(void);
00159 extern Agraph_t *agprotograph(void);
00160 extern Agraph_t *agusergraph(Agnode_t *);
00161 extern int agnnodes(Agraph_t *);
00162 extern int agnedges(Agraph_t *);
00163
00164 extern void aginsert(Agraph_t *, void *);
00165 extern void agdelete(Agraph_t *, void *);
00166 extern int agcontains(Agraph_t *, void *);
00167
00168 extern Agnode_t *agnode(Agraph_t *, char *);
00169 extern Agsym_t *agnodeattr(Agraph_t *, char *, char *);
00170 extern Agnode_t *agfindnode(Agraph_t *, char *);
00171 extern Agnode_t *agfstnode(Agraph_t *);
00172 extern Agnode_t *agnxtnode(Agraph_t *, Agnode_t *);
00173 extern Agnode_t *aglstnode(Agraph_t *);
00174 extern Agnode_t *agprvnode(Agraph_t *, Agnode_t *);
00175
00176 extern Agedge_t *agedge(Agraph_t *, Agnode_t *, Agnode_t *);
00177 extern Agsym_t *agedgeattr(Agraph_t *, char *, char *);
00178 extern Agedge_t *agfindedge(Agraph_t *, Agnode_t *, Agnode_t *);
00179 extern Agedge_t *agfstedge(Agraph_t *, Agnode_t *);
00180 extern Agedge_t *agnxtedge(Agraph_t *, Agedge_t *, Agnode_t *);
00181 extern Agedge_t *agfstin(Agraph_t *, Agnode_t *);
00182 extern Agedge_t *agnxtin(Agraph_t *, Agedge_t *);
00183 extern Agedge_t *agfstout(Agraph_t *, Agnode_t *);
00184 extern Agedge_t *agnxtout(Agraph_t *, Agedge_t *);
00185
00186 extern Agsym_t *agraphattr(Agraph_t *, char *, char *);
00187 extern Agsym_t *agnodeattr(Agraph_t *, char *, char *);
00188 extern Agsym_t *agedgeattr(Agraph_t *, char *, char *);
00189 extern Agsym_t *agfindattr(void *, char *);
00190 extern int agcopyattr(void *, void *);
00191
00192 typedef enum { AGWARN, AGERR, AGMAX, AGPREV } agerrlevel_t;
00193 extern agerrlevel_t agerrno;
00194 extern void agseterr(agerrlevel_t);
00195 extern char *aglasterr(void);
00196 extern int agerr(agerrlevel_t level, char *fmt, ...);
00197 extern void agerrorf(char *fmt, ...);
00198 extern void agwarningf(char *fmt, ...);
00199
00200 extern char *agstrdup(char *);
00201 extern void agstrfree(char *);
00202
00203 typedef enum { AGNODE = 1, AGEDGE, AGGRAPH } agobjkind_t;
00204 #define agobjkind(p) ((agobjkind_t)(((Agraph_t*)(p))->tag))
00205
00206 #define agmetanode(g) ((g)->meta_node)
00207
00208 #undef extern
00209 #if _PACKAGE_ast
00210 _END_EXTERNS_
00211 #endif
00212 #ifdef __cplusplus
00213 }
00214 #endif
00215 #endif