From 75ed74af517e58f68d68bf07aa0d7a8de0a65f4c Mon Sep 17 00:00:00 2001 From: ellson Date: Tue, 18 Oct 2005 18:37:49 +0000 Subject: [PATCH] pull out memory.[ch] from types.h, macros.h, utils.[ch] --- lib/common/Makefile.am | 6 +- lib/common/Makefile.old | 6 +- lib/common/macros.h | 18 ----- lib/common/render.h | 156 ++++++++++++++++++++++++++++++++++----- lib/common/renderprocs.h | 142 ----------------------------------- lib/common/utils.c | 67 +++-------------- lib/common/utils.h | 5 -- lib/gvc/gvusershape.c | 1 - 8 files changed, 156 insertions(+), 245 deletions(-) delete mode 100644 lib/common/renderprocs.h diff --git a/lib/common/Makefile.am b/lib/common/Makefile.am index eab1a2a83..dea7ad6ed 100644 --- a/lib/common/Makefile.am +++ b/lib/common/Makefile.am @@ -10,8 +10,8 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/lib/cdt @GD_INCLUDES@ @EXPAT_INCLUDES@ @Z_INCLUDES@ pkginclude_HEADERS = logic.h arith.h geom.h color.h colortbl.h \ - const.h macros.h types.h globals.h utils.h \ - htmllex.h htmltable.h pointset.h render.h renderprocs.h + const.h macros.h types.h globals.h utils.h memory.h \ + htmllex.h htmltable.h pointset.h render.h noinst_LTLIBRARIES = libcommon.la if !DISABLE_CODEGENS @@ -21,7 +21,7 @@ endif libcommon_la_SOURCES = arrows.c colxlate.c fontmetrics.c \ - args.c gdtextsize.c gdusershape.c \ + args.c gdtextsize.c gdusershape.c memory.c \ globals.c htmllex.c htmlparse.y htmltable.c input.c \ pointset.c postproc.c psusershape.c routespl.c splines.c \ svgusershape.c timing.c labels.c ns.c shapes.c utils.c geom.c \ diff --git a/lib/common/Makefile.old b/lib/common/Makefile.old index 40f68da26..fd3af6d61 100644 --- a/lib/common/Makefile.old +++ b/lib/common/Makefile.old @@ -19,7 +19,7 @@ DEFINES = -DHAVE_CONFIG_H AWKDIR = $(ROOT)/awk HDRS = colortbl.h const.h globals.h macros.h render.h \ - renderprocs.h types.h utils.h geom.h logic.h color.h arith.h + types.h utils.h geom.h logic.h color.h arith.h memory.h OBJS = args.o arrows.o gdusershape.o mapgen.o psgen.o svgusershape.o \ colxlate.o globals.o mifgen.o psusershape.o timing.o \ @@ -27,7 +27,7 @@ OBJS = args.o arrows.o gdusershape.o mapgen.o psgen.o svgusershape.o \ emit.o htmllex.o ns.o shapes.o vrmlgen.o xdgen.o \ figgen.o htmlparse.o output.o splines.o vtxgen.o \ fontmetrics.o htmltable.o picgen.o strcasecmp.o \ - gdgen.o input.o pointset.o strncasecmp.o \ + gdgen.o input.o pointset.o strncasecmp.o memory.o \ gdtextsize.o labels.o postproc.o svggen.o xdgen.o libcommon.a : $(OBJS) @@ -48,7 +48,7 @@ htmllex.o : htmllex.c install: libcommon.a $(MKPATH) $(INCDIR) - $(INSTALL) const.h globals.h macros.h render.h renderprocs.h types.h utils.h geom.h $(INCDIR) + $(INSTALL) const.h globals.h macros.h render.h memory.h logic.h arith.h types.h utils.h geom.h $(INCDIR) $(MKPATH) $(LIBDIR) $(INSTALL) libcommon.a $(LIBDIR) diff --git a/lib/common/macros.h b/lib/common/macros.h index 62015731d..8d84eea9f 100644 --- a/lib/common/macros.h +++ b/lib/common/macros.h @@ -17,24 +17,6 @@ #ifndef GV_MACROS_H #define GV_MACROS_H -#ifdef DMALLOC -#define NEW(t) (t*)calloc(1,sizeof(t)) -#define N_NEW(n,t) (t*)calloc((n),sizeof(t)) -#define GNEW(t) (t*)malloc(sizeof(t)) -#define N_GNEW(n,t) (t*)malloc((n)*sizeof(t)) -#define ALLOC(size,ptr,type) (ptr? (type*)realloc(ptr,(size)*sizeof(type)):(type*)malloc((size)*sizeof(type))) -#define RALLOC(size,ptr,type) ((type*)realloc(ptr,(size)*sizeof(type))) -#define ZALLOC(size,ptr,type,osize) (ptr? (type*)recalloc(ptr,(size)*sizeof(type)):(type*)calloc((size),sizeof(type))) -#else -#define NEW(t) (t*)zmalloc(sizeof(t)) -#define N_NEW(n,t) (t*)zmalloc((n)*sizeof(t)) -#define GNEW(t) (t*)gmalloc(sizeof(t)) -#define N_GNEW(n,t) (t*)gmalloc((n)*sizeof(t)) -#define ALLOC(size,ptr,type) (ptr? (type*)grealloc(ptr,(size)*sizeof(type)):(type*)gmalloc((size)*sizeof(type))) -#define RALLOC(size,ptr,type) ((type*)grealloc(ptr,(size)*sizeof(type))) -#define ZALLOC(size,ptr,type,osize) (ptr? (type*)zrealloc(ptr,size,sizeof(type),osize):(type*)zmalloc((size)*sizeof(type))) -#endif - #define isPinned(n) (ND_pinned(n) == P_PIN) #define hasPos(n) (ND_pinned(n) > 0) #define isFixed(n) (ND_pinned(n) > P_SET) diff --git a/lib/common/render.h b/lib/common/render.h index 1f5add85c..8c128825f 100644 --- a/lib/common/render.h +++ b/lib/common/render.h @@ -14,8 +14,12 @@ * AT&T Research, Florham Park NJ * **********************************************************/ -#ifndef RENDER_H -#define RENDER_H +#ifndef GV_RENDER_H +#define GV_RENDER_H + +#ifdef __cplusplus +extern "C" { +#endif #ifdef HAVE_CONFIG_H #include "config.h" @@ -54,23 +58,141 @@ #include "types.h" #include "graph.h" /* must follow types.h */ #include "globals.h" -#include "renderprocs.h" +#include "memory.h" #include "utils.h" -typedef struct epsf_s { - int macro_id; - point offset; -} epsf_t; + typedef struct epsf_s { + int macro_id; + point offset; + } epsf_t; + + typedef struct { + Dtlink_t link; + char *name; + int macro_id; + point size; + point origin; + char *contents; + int must_inline; + } ps_image_t; + + typedef void (*nodesizefn_t) (Agnode_t *, boolean); + + extern void add_box(path *, box); + extern void arrow_flags(Agedge_t * e, int *sflag, int *eflag); + extern boxf arrow_bb(pointf p, pointf u, double scale, int flag); + extern void arrow_gen(GVJ_t * job, point p, point u, double scale, + int flag); + extern double arrow_length(edge_t * e, int flag); + extern int arrowEndClip(edge_t*, point*, int, int , bezier*, int eflag); + extern int arrowStartClip(edge_t*, point* ps, int, int, bezier*, int sflag); + extern void attach_attrs(Agraph_t *); + extern void beginpath(path *, Agedge_t *, int, pathend_t *, boolean); + extern void bezier_clip(inside_t * inside_context, + boolean(*insidefn) (inside_t * inside_context, + pointf p), pointf * sp, + boolean left_inside); + extern shape_desc *bind_shape(char *name, node_t *); + extern void clip_and_install(edge_t *, edge_t *, point *, int, + splineInfo *); + extern char *canontoken(char *str); + extern char* charsetToStr (int c); + extern point coord(node_t * n); + extern void do_graph_label(graph_t * sg); + extern void graph_init(graph_t * g, boolean use_rankdir); + extern void graph_cleanup(graph_t * g); + extern void dotneato_args_initialize(GVC_t * gvc, int, char **); + extern void dotneato_usage(int); + extern void dotneato_postprocess(Agraph_t *); + extern void dotneato_set_margins(GVC_t * gvc, Agraph_t *); + extern void dotneato_write(GVC_t * gvc, graph_t *g); + extern void dotneato_write_one(GVC_t * gvc, graph_t *g); + extern double elapsed_sec(void); + extern void emit_background(GVJ_t * job, graph_t *g); + extern void emit_clusters(GVJ_t * job, Agraph_t * g, int flags); + extern void emit_edge_graphics(GVJ_t * job, edge_t * e); + extern void emit_graph(GVJ_t * job, graph_t * g); + extern void emit_label(GVJ_t * job, textlabel_t *, void *obj); + extern int emit_once(char *message); + extern void emit_jobs_eof(GVC_t * gvc); + extern void emit_textlines(GVJ_t*, int, textline_t*, pointf, + double, char*, double, char*); + extern void enqueue_neighbors(nodequeue *, Agnode_t *, int); + extern void endpath(path *, Agedge_t *, int, pathend_t *, boolean); + extern void epsf_init(node_t * n); + extern void epsf_free(node_t * n); + extern void extend_attrs(GVJ_t * job, graph_t *g, int s_arrows, int e_arrows); + extern shape_desc *find_user_shape(char *); + extern void free_line(textline_t *); + extern void free_label(textlabel_t *); + extern char *gd_alternate_fontlist(char *font); + extern char *gd_textsize(textline_t * textline, char *fontname, + double fontsz, char **fontpath); + extern void getdouble(graph_t * g, char *name, double *result); + extern splines *getsplinepoints(edge_t * e); + extern void global_def(char *, + Agsym_t * (*fun) (Agraph_t *, char *, char *)); + extern int gvRenderJobs (GVC_t * gvc, graph_t * g); + extern point image_size(graph_t * g, char *shapefile); + extern boolean isPolygon(node_t *); + extern char *strdup_and_subst_graph(char *str, Agraph_t * g); + extern char *strdup_and_subst_node(char *str, Agnode_t * n); + extern char *strdup_and_subst_edge(char *str, Agedge_t * e); + extern char *xml_string(char *s); + extern void makeSelfEdge(path *, edge_t **, int, int, int, int, + splineInfo *); + extern textlabel_t *make_label(int, char *, double, char *, char *, + graph_t *); + extern void map_begin_cluster(graph_t * g); + extern void map_begin_edge(Agedge_t * e); + extern void map_begin_node(Agnode_t * n); + extern void map_edge(Agedge_t *); + extern point map_point(point); + extern bezier *new_spline(edge_t * e, int sz); + extern Agraph_t *next_input_graph(void); + extern void osize_label(textlabel_t *, int *, int *, int *, int *); + extern char **parse_style(char *s); + extern void place_graph_label(Agraph_t *); + extern void place_portlabel(edge_t * e, boolean head_p); + extern char *ps_string(char *s, int); + extern int rank(graph_t * g, int balance, int maxiter); + extern void routesplinesinit(void); + extern point *routesplines(path *, int *); + extern void routesplinesterm(void); + extern int selfRightSpace (edge_t* e); + extern void setup_graph(GVC_t * gvc, graph_t * g); + extern shape_kind shapeOf(node_t *); + extern void shape_clip(node_t * n, point curve[4]); + extern void start_timer(void); + extern double textwidth(textline_t * textline, char *fontname, + double fontsz); + extern void translate_bb(Agraph_t *, int); + extern void use_library(char *); + extern void write_attributed_dot(graph_t *g, FILE *f); + extern void write_canonical_dot(graph_t *g, FILE *f); + extern void write_extended_dot(GVJ_t * job, graph_t *g, FILE *f); + extern void write_plain(GVJ_t * job, graph_t * g, FILE * f); + extern void write_plain_ext(GVJ_t * job, graph_t * g, FILE * f); + +#if defined(_BLD_dot) && defined(_DLL) +# define extern __EXPORT__ +#endif + +#ifndef DISABLE_CODEGENS +#ifndef HAVE_GD_FREETYPE + extern void initDPI(graph_t *); + extern double textheight(int nlines, double fontsz); + extern int builtinFontHt(double fontsz); + extern int builtinFontWd(double fontsz); +#endif + extern codegen_info_t *first_codegen(void); + extern codegen_info_t *next_codegen(codegen_info_t * p); +#endif -typedef struct { - Dtlink_t link; - char *name; - int macro_id; - point size; - point origin; - char *contents; - int must_inline; -} ps_image_t; +#undef extern +#ifdef __cplusplus +} +#endif -#endif /* RENDER_H */ +#endif diff --git a/lib/common/renderprocs.h b/lib/common/renderprocs.h deleted file mode 100644 index 3e5d20316..000000000 --- a/lib/common/renderprocs.h +++ /dev/null @@ -1,142 +0,0 @@ -/* $Id$ $Revision$ */ -/* vim:set shiftwidth=4 ts=8: */ - -/********************************************************** -* This software is part of the graphviz package * -* http://www.graphviz.org/ * -* * -* Copyright (c) 1994-2004 AT&T Corp. * -* and is licensed under the * -* Common Public License, Version 1.0 * -* by AT&T Corp. * -* * -* Information and Software Systems Research * -* AT&T Research, Florham Park NJ * -**********************************************************/ - -#ifndef GV_RENDERPROCS_H -#define GV_RENDERPROCS_H - -#ifdef __cplusplus -extern "C" { -#endif - - typedef void (*nodesizefn_t) (Agnode_t *, boolean); - - extern void add_box(path *, box); - extern void arrow_flags(Agedge_t * e, int *sflag, int *eflag); - extern boxf arrow_bb(pointf p, pointf u, double scale, int flag); - extern void arrow_gen(GVJ_t * job, point p, point u, double scale, - int flag); - extern double arrow_length(edge_t * e, int flag); - extern int arrowEndClip(edge_t*, point*, int, int , bezier*, int eflag); - extern int arrowStartClip(edge_t*, point* ps, int, int, bezier*, int sflag); - extern void attach_attrs(Agraph_t *); - extern void beginpath(path *, Agedge_t *, int, pathend_t *, boolean); - extern void bezier_clip(inside_t * inside_context, - boolean(*insidefn) (inside_t * inside_context, - pointf p), pointf * sp, - boolean left_inside); - extern shape_desc *bind_shape(char *name, node_t *); - extern void clip_and_install(edge_t *, edge_t *, point *, int, - splineInfo *); - extern char *canontoken(char *str); - extern char* charsetToStr (int c); - extern point coord(node_t * n); - extern void do_graph_label(graph_t * sg); - extern void graph_init(graph_t * g, boolean use_rankdir); - extern void graph_cleanup(graph_t * g); - extern void dotneato_args_initialize(GVC_t * gvc, int, char **); - extern void dotneato_usage(int); - extern void dotneato_postprocess(Agraph_t *); - extern void dotneato_set_margins(GVC_t * gvc, Agraph_t *); - extern void dotneato_write(GVC_t * gvc, graph_t *g); - extern void dotneato_write_one(GVC_t * gvc, graph_t *g); - extern double elapsed_sec(void); - extern void emit_background(GVJ_t * job, graph_t *g); - extern void emit_clusters(GVJ_t * job, Agraph_t * g, int flags); - extern void emit_edge_graphics(GVJ_t * job, edge_t * e); - extern void emit_graph(GVJ_t * job, graph_t * g); - extern void emit_label(GVJ_t * job, textlabel_t *, void *obj); - extern int emit_once(char *message); - extern void emit_jobs_eof(GVC_t * gvc); - extern void emit_textlines(GVJ_t*, int, textline_t*, pointf, - double, char*, double, char*); - extern void enqueue_neighbors(nodequeue *, Agnode_t *, int); - extern void endpath(path *, Agedge_t *, int, pathend_t *, boolean); - extern void epsf_init(node_t * n); - extern void epsf_free(node_t * n); - extern void extend_attrs(GVJ_t * job, graph_t *g, int s_arrows, int e_arrows); - extern shape_desc *find_user_shape(char *); - extern void free_line(textline_t *); - extern void free_label(textlabel_t *); - extern char *gd_alternate_fontlist(char *font); - extern char *gd_textsize(textline_t * textline, char *fontname, - double fontsz, char **fontpath); - extern void getdouble(graph_t * g, char *name, double *result); - extern splines *getsplinepoints(edge_t * e); - extern void global_def(char *, - Agsym_t * (*fun) (Agraph_t *, char *, char *)); - extern int gvRenderJobs (GVC_t * gvc, graph_t * g); - extern point image_size(graph_t * g, char *shapefile); - extern boolean isPolygon(node_t *); - extern char *strdup_and_subst_graph(char *str, Agraph_t * g); - extern char *strdup_and_subst_node(char *str, Agnode_t * n); - extern char *strdup_and_subst_edge(char *str, Agedge_t * e); - extern char *xml_string(char *s); - extern void makeSelfEdge(path *, edge_t **, int, int, int, int, - splineInfo *); - extern textlabel_t *make_label(int, char *, double, char *, char *, - graph_t *); - extern void map_begin_cluster(graph_t * g); - extern void map_begin_edge(Agedge_t * e); - extern void map_begin_node(Agnode_t * n); - extern void map_edge(Agedge_t *); - extern point map_point(point); - extern bezier *new_spline(edge_t * e, int sz); - extern Agraph_t *next_input_graph(void); - extern void osize_label(textlabel_t *, int *, int *, int *, int *); - extern char **parse_style(char *s); - extern void place_graph_label(Agraph_t *); - extern void place_portlabel(edge_t * e, boolean head_p); - extern char *ps_string(char *s, int); - extern int rank(graph_t * g, int balance, int maxiter); - extern void routesplinesinit(void); - extern point *routesplines(path *, int *); - extern void routesplinesterm(void); - extern int selfRightSpace (edge_t* e); - extern void setup_graph(GVC_t * gvc, graph_t * g); - extern shape_kind shapeOf(node_t *); - extern void shape_clip(node_t * n, point curve[4]); - extern void start_timer(void); - extern double textwidth(textline_t * textline, char *fontname, - double fontsz); - extern void translate_bb(Agraph_t *, int); - extern void use_library(char *); - extern void write_attributed_dot(graph_t *g, FILE *f); - extern void write_canonical_dot(graph_t *g, FILE *f); - extern void write_extended_dot(GVJ_t * job, graph_t *g, FILE *f); - extern void write_plain(GVJ_t * job, graph_t * g, FILE * f); - extern void write_plain_ext(GVJ_t * job, graph_t * g, FILE * f); - -#if defined(_BLD_dot) && defined(_DLL) -# define extern __EXPORT__ -#endif - -#ifndef DISABLE_CODEGENS -#ifndef HAVE_GD_FREETYPE - extern void initDPI(graph_t *); - extern double textheight(int nlines, double fontsz); - extern int builtinFontHt(double fontsz); - extern int builtinFontWd(double fontsz); -#endif - extern codegen_info_t *first_codegen(void); - extern codegen_info_t *next_codegen(codegen_info_t * p); -#endif - -#undef extern - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/common/utils.c b/lib/common/utils.c index 2fe31fbe6..3204bc38f 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -14,66 +14,21 @@ * AT&T Research, Florham Park NJ * **********************************************************/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include "render.h" -#include "gvplugin.h" -#include "gvcint.h" -#include "gvcproc.h" -#include "agxbuf.h" -#include "utils.h" -#include "htmltable.h" +#include #ifndef MSWIN32 -#include +#include #endif - -void *zmalloc(size_t nbytes) -{ - char *rv = malloc(nbytes); - if (nbytes == 0) - return 0; - if (rv == NULL) { - fprintf(stderr, "out of memory\n"); - abort(); - } - memset(rv, 0, nbytes); - return rv; -} - -void *zrealloc(void *ptr, size_t size, size_t elt, size_t osize) -{ - void *p = realloc(ptr, size * elt); - if (p == NULL && size) { - fprintf(stderr, "out of memory\n"); - abort(); - } - if (osize < size) - memset((char *) p + (osize * elt), '\0', (size - osize) * elt); - return p; -} - -void *gmalloc(size_t nbytes) -{ - char *rv; - if (nbytes == 0) - return (char *)1; /* NB Return an invalid pointer - since nobody seems to check for NULL */ - rv = malloc(nbytes); - if (rv == NULL) { - fprintf(stderr, "out of memory\n"); - abort(); - } - return rv; -} - -void *grealloc(void *ptr, size_t size) -{ - void *p = realloc(ptr, size); - if (p == NULL && size) { - fprintf(stderr, "out of memory\n"); - abort(); - } - return p; -} +#include "types.h" +#include "graph.h" +#include "agxbuf.h" +#include "memory.h" +#include "utils.h" +#include "htmltable.h" /* * a queue of nodes diff --git a/lib/common/utils.h b/lib/common/utils.h index 3359e7d6a..9eee0e953 100644 --- a/lib/common/utils.h +++ b/lib/common/utils.h @@ -25,11 +25,6 @@ extern "C" { extern int strncasecmp(const char *s1, const char *s2, size_t n); #endif - extern void *zmalloc(size_t); - extern void *zrealloc(void *, size_t, size_t, size_t); - extern void *gmalloc(size_t); - extern void *grealloc(void *, size_t); - extern nodequeue *new_queue(int); extern void free_queue(nodequeue *); extern void enqueue(nodequeue *, Agnode_t *); diff --git a/lib/gvc/gvusershape.c b/lib/gvc/gvusershape.c index 6beaaad0b..79d0b029e 100644 --- a/lib/gvc/gvusershape.c +++ b/lib/gvc/gvusershape.c @@ -42,7 +42,6 @@ #include "macros.h" #include "const.h" #include "types.h" -#include "cdt.h" #include "graph.h" #include "gvplugin_usershape.h" -- 2.40.0