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 TAILSUB_ID "_tailsubport"
00037 #define HEAD_ID "headport"
00038 #define HEADSUB_ID "_headsubport"
00039
00040 typedef struct Agraph_t Agraph_t;
00041 typedef struct Agnode_t Agnode_t;
00042 typedef struct Agedge_t Agedge_t;
00043 typedef struct Agdict_t Agdict_t;
00044 typedef struct Agsym_t Agsym_t;
00045 typedef struct Agdata_t Agdata_t;
00046 typedef struct Agproto_t Agproto_t;
00047
00048 typedef char *(*gets_f) (char *ubuf, int n, FILE * fp);
00049
00050 #define AGFLAG_DIRECTED (1<<0)
00051 #define AGFLAG_STRICT (1<<1)
00052 #define AGFLAG_METAGRAPH (1<<2)
00053
00054 #define AGRAPH 0
00055 #define AGRAPHSTRICT (AGRAPH | AGFLAG_STRICT)
00056 #define AGDIGRAPH AGFLAG_DIRECTED
00057 #define AGDIGRAPHSTRICT (AGDIGRAPH | AGFLAG_STRICT)
00058 #define AGMETAGRAPH (AGFLAG_DIRECTED | AGFLAG_STRICT | AGFLAG_METAGRAPH)
00059
00060 #define AG_IS_DIRECTED(g) ((g)->kind & AGFLAG_DIRECTED)
00061 #define AG_IS_STRICT(g) ((g)->kind & AGFLAG_STRICT)
00062 #define AG_IS_METAGRAPH(g) ((g)->kind & AGFLAG_METAGRAPH)
00063 #define aginit() aginitlib(sizeof(Agraph_t),sizeof(Agnode_t),sizeof(Agedge_t))
00064
00065 struct Agraph_t {
00066 int tag:4;
00067 int kind:4;
00068 int handle:24;
00069 char **attr;
00070 char *name;
00071 Agdata_t *univ;
00072 Dict_t *nodes, *inedges, *outedges;
00073 Agraph_t *root;
00074 Agnode_t *meta_node;
00075 Agproto_t *proto;
00076 Agraphinfo_t u;
00077 };
00078
00079 struct Agnode_t {
00080 int tag:4;
00081 int pad:4;
00082 int handle:24;
00083 char **attr;
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 Agnode_t *head, *tail;
00096 int id;
00097 Agedgeinfo_t u;
00098 };
00099
00100 struct Agdata_t {
00101 Dict_t *node_dict;
00102 Agdict_t *nodeattr;
00103 Agdict_t *edgeattr;
00104 Agdict_t *globattr;
00105 int max_node_id, max_edge_id;
00106 };
00107
00108 struct Agsym_t {
00109 char *name, *value;
00110 int index;
00111 unsigned char printed;
00112 unsigned char fixed;
00113 };
00114
00115 struct Agdict_t {
00116 char *name;
00117 Dict_t *dict;
00118 Agsym_t **list;
00119 };
00120
00121 struct Agproto_t {
00122 Agnode_t *n;
00123 Agedge_t *e;
00124 Agproto_t *prev;
00125 };
00126
00127 #if _PACKAGE_ast
00128 _BEGIN_EXTERNS_
00129 #if _BLD_graph && defined(__EXPORT__)
00130 #define extern __EXPORT__
00131 #endif
00132 #if !_BLD_graph && defined(__IMPORT__) && 0
00133 #define extern __IMPORT__
00134 #endif
00135 #endif
00136 extern char *agstrcanon(char *, char *);
00137 extern int aghtmlstr(char *s);
00138 extern char *agget(void *, char *);
00139 extern char *agxget(void *, int);
00140 extern int agset(void *, char *, char *);
00141 extern int agxset(void *, int, char *);
00142 extern int agindex(void *, char *);
00143
00144 extern void aginitlib(int, int, int);
00145 extern Agraph_t *agopen(char *, int);
00146 extern Agraph_t *agsubg(Agraph_t *, char *);
00147 extern Agraph_t *agfindsubg(Agraph_t *, char *);
00148 extern void agclose(Agraph_t *);
00149 extern Agraph_t *agread(FILE *);
00150 extern Agraph_t *agread_usergets(FILE *, gets_f);
00151 extern void agreadline(int);
00152 extern void agsetfile(char *);
00153 extern Agraph_t *agmemread(char *);
00154 extern int agwrite(Agraph_t *, FILE *);
00155 extern int agerrors(void);
00156 extern Agraph_t *agprotograph();
00157 extern Agraph_t *agusergraph(Agnode_t *);
00158 extern int agnnodes(Agraph_t *);
00159 extern int agnedges(Agraph_t *);
00160
00161 extern void aginsert(Agraph_t *, void *);
00162 extern void agdelete(Agraph_t *, void *);
00163 extern int agcontains(Agraph_t *, void *);
00164
00165 extern Agnode_t *agnode(Agraph_t *, char *);
00166 extern Agsym_t *agnodeattr(Agraph_t *, char *, char *);
00167 extern Agnode_t *agfindnode(Agraph_t *, char *);
00168 extern Agnode_t *agfstnode(Agraph_t *);
00169 extern Agnode_t *agnxtnode(Agraph_t *, Agnode_t *);
00170 extern Agnode_t *aglstnode(Agraph_t *);
00171 extern Agnode_t *agprvnode(Agraph_t *, Agnode_t *);
00172
00173 extern Agedge_t *agedge(Agraph_t *, Agnode_t *, Agnode_t *);
00174 extern Agsym_t *agedgeattr(Agraph_t *, char *, char *);
00175 extern Agedge_t *agfindedge(Agraph_t *, Agnode_t *, Agnode_t *);
00176 extern Agedge_t *agfstedge(Agraph_t *, Agnode_t *);
00177 extern Agedge_t *agnxtedge(Agraph_t *, Agedge_t *, Agnode_t *);
00178 extern Agedge_t *agfstin(Agraph_t *, Agnode_t *);
00179 extern Agedge_t *agnxtin(Agraph_t *, Agedge_t *);
00180 extern Agedge_t *agfstout(Agraph_t *, Agnode_t *);
00181 extern Agedge_t *agnxtout(Agraph_t *, Agedge_t *);
00182
00183 extern Agsym_t *agraphattr(Agraph_t *, char *, char *);
00184 extern Agsym_t *agnodeattr(Agraph_t *, char *, char *);
00185 extern Agsym_t *agedgeattr(Agraph_t *, char *, char *);
00186 extern Agsym_t *agfindattr(void *, char *);
00187
00188 typedef enum { AGWARN, AGERR, AGMAX, AGPREV } agerrlevel_t;
00189 extern agerrlevel_t agerrno;
00190 extern void agseterr(agerrlevel_t);
00191 extern char *aglasterr();
00192 extern int agerr(agerrlevel_t level, char *fmt, ...);
00193 extern void agerrorf(char *fmt, ...);
00194 extern void agwarningf(char *fmt, ...);
00195
00196 typedef enum { AGNODE = 1, AGEDGE, AGGRAPH } agobjkind_t;
00197 #define agobjkind(p) ((agobjkind_t)(((Agraph_t*)(p))->tag))
00198
00199 #define agmetanode(g) ((g)->meta_node)
00200
00201 #undef extern
00202 #if _PACKAGE_ast
00203 _END_EXTERNS_
00204 #endif
00205 #ifdef __cplusplus
00206 }
00207 #endif
00208 #endif