Graphviz  2.29.20120524.0446
lib/graph/libgraph.h
Go to the documentation of this file.
00001 /* $Id$ $Revision$ */
00002 /* vim:set shiftwidth=4 ts=8: */
00003 
00004 /*************************************************************************
00005  * Copyright (c) 2011 AT&T Intellectual Property 
00006  * All rights reserved. This program and the accompanying materials
00007  * are made available under the terms of the Eclipse Public License v1.0
00008  * which accompanies this distribution, and is available at
00009  * http://www.eclipse.org/legal/epl-v10.html
00010  *
00011  * Contributors: See CVS logs. Details at http://www.graphviz.org/
00012  *************************************************************************/
00013 
00014 #ifdef __cplusplus
00015 extern "C" {
00016 #endif
00017 
00018 
00019 #ifndef _LIBGRAPH_H
00020 #define _LIBGRAPH_H 1
00021 
00022 #if _PACKAGE_ast
00023 #include    <ast.h>
00024 #else
00025 #include <stdarg.h>
00026 #include <stdlib.h>
00027 #include <string.h>
00028 #if !defined(MSWIN32) && !defined(WIN32)
00029 #include <unistd.h>
00030 #endif
00031 #endif
00032 #include <ctype.h>
00033 
00034 
00035 #ifndef EXTERN
00036 #define EXTERN extern
00037 #endif
00038 
00039 #ifndef NIL
00040 #define NIL(t)  ((t)0)
00041 #endif
00042 
00043     void ag_yyerror(char *);
00044     int ag_yylex(void);
00045 
00046     typedef struct Agraphinfo_t {
00047         char notused;
00048     } Agraphinfo_t;
00049     typedef struct Agnodeinfo_t {
00050         char notused;
00051     } Agnodeinfo_t;
00052     typedef struct Agedgeinfo_t {
00053         char notused;
00054     } Agedgeinfo_t;
00055 
00056 #ifndef _BLD_graph
00057 #define _BLD_graph 1
00058 #endif
00059 
00060 #ifdef HAVE_CONFIG_H
00061 #include "config.h"
00062 #endif
00063 
00064 #include "graph.h"
00065 
00066 #ifdef HAVE_STDINT_H
00067 #include <stdint.h>
00068 #endif
00069 #ifdef HAVE_INTTYPES_H
00070 #include <inttypes.h>
00071 #endif
00072 
00073 #ifdef offsetof
00074 #undef offsetof
00075 #endif
00076 #ifdef HAVE_INTPTR_T
00077 #define offsetof(typ,fld)  ((intptr_t)(&(((typ*)0)->fld)))
00078 #else
00079 #define offsetof(typ,fld)  ((int)(&(((typ*)0)->fld)))
00080 #endif
00081 
00082 #ifndef NOT
00083 #define NOT(v)          (!(v))
00084 #endif
00085 #ifndef FALSE
00086 #define FALSE           0
00087 #endif
00088 #ifndef TRUE
00089 #define TRUE            NOT(FALSE)
00090 #endif
00091 #define NEW(t)           (t*)calloc(1,sizeof(t))
00092 #define N_NEW(n,t)       (t*)calloc((n),sizeof(t))
00093 #define ALLOC(size,ptr,type) (ptr? (type*)realloc(ptr,(size)*sizeof(type)):(type*)malloc((size)*sizeof(type)))
00094 #define MIN(a,b)        ((a)<(b)?(a):(b))
00095 #define MAX(a,b)        ((a)>(b)?(a):(b))
00096 #define SMALLBUF        128
00097 
00098 #define ISALNUM(c) ((isalnum(c)) || ((c) == '_') || (!isascii(c)))
00099 
00100 #define NOPRINT         0
00101 #define MULTIPLE    1
00102 #define MUSTPRINT       2
00103 
00104 #define ISEMPTYSTR(s)   (((s) == NULL) || (*(s) == '\0'))
00105 #define NULL_FN(t)              (t(*)())0
00106 #define ZFREE(p)                if (p) free(p);
00107 
00108 #define TAG_NODE                        1
00109 #define TAG_EDGE                        2
00110 #define TAG_GRAPH                       3
00111 #define TAG_OF(p)                       (((Agraph_t*)(p))->tag)
00112 
00113 #define AGFLAG_STRICT           (1<<1)
00114 #define AGFLAG_METAGRAPH        (1<<2)
00115 #define METAGRAPH                       (AGFLAG_DIRECTED | AGFLAG_STRICT | AGFLAG_METAGRAPH)
00116 
00117 #define KEY_ID                          "key"
00118 #define KEYX                            0
00119 #define TAILX                           1
00120 #define HEADX                           2
00121 
00122     EXTERN struct AG_s {
00123         int graph_nbytes, node_nbytes, edge_nbytes;
00124         Agraph_t *proto_g, *parsed_g;
00125         char *edge_op;
00126         char *linebuf;
00127         short syntax_errors;
00128         unsigned char accepting_state, init_called;
00129         char * (*fgets) (char *s, int size, FILE *stream);
00130         size_t (*fwrite) (const void *ptr, size_t size, size_t nmemb, FILE *stream);
00131         int (*ferror) (FILE *stream);
00132     } AG;
00133 
00134 /* follow structs used in graph parser */
00135     typedef struct objport_t {
00136         void *obj;
00137         char *port;
00138     } objport_t;
00139 
00140     typedef struct objlist_t {
00141         objport_t data;
00142         struct objlist_t *link;
00143     } objlist_t;
00144 
00145     typedef struct objstack_t {
00146         Agraph_t *subg;
00147         objlist_t *list, *last;
00148         int in_edge_stmt;
00149         struct objstack_t *link;
00150     } objstack_t;
00151 
00152     Agdict_t *agdictof(void *);
00153     Agnode_t *agidnode(Agraph_t *, int);
00154     Agdict_t *agNEWdict(char *);
00155     Agedge_t *agNEWedge(Agraph_t *, Agnode_t *, Agnode_t *, Agedge_t *);
00156     Agnode_t *agNEWnode(Agraph_t *, char *, Agnode_t *);
00157     Agsym_t *agNEWsym(Agdict_t *, char *, char *);
00158     int agcmpid(Dt_t *, int *, int *, Dtdisc_t *);
00159     int agcmpin(Dt_t *, Agedge_t *, Agedge_t *, Dtdisc_t *);
00160     int agcmpout(Dt_t *, Agedge_t *, Agedge_t *, Dtdisc_t *);
00161     void agcopydict(Agdict_t *, Agdict_t *);
00162     void agDELedge(Agraph_t *, Agedge_t *);
00163     void agDELnode(Agraph_t *, Agnode_t *);
00164     void agerror(char *);
00165     void agFREEdict(Agraph_t *, Agdict_t *);
00166     void agFREEedge(Agedge_t *);
00167     void agFREEnode(Agnode_t *);
00168     void agINSedge(Agraph_t *, Agedge_t *);
00169     void agINSgraph(Agraph_t *, Agraph_t *);
00170     void agINSnode(Agraph_t *, Agnode_t *);
00171     int aglex(void);
00172     void aglexinit(FILE *, gets_f mygets);
00173     int agparse(void);
00174     void agpopproto(Agraph_t *);
00175     void agpushproto(Agraph_t *);
00176     int agtoken(char *);
00177     int aglinenumber(void);
00178     void agwredge(Agraph_t *, FILE *, Agedge_t *, int);
00179     void agwrnode(Agraph_t *, FILE *, Agnode_t *, int, int);
00180     extern Dtdisc_t agNamedisc, agNodedisc, agOutdisc, agIndisc,
00181         agEdgedisc;
00182 
00183 #endif
00184 
00185 #ifdef __cplusplus
00186 }
00187 #endif