From 5e1838f562849df00c50746e64d2feaff28967a0 Mon Sep 17 00:00:00 2001 From: erg Date: Wed, 19 Mar 2008 21:43:58 +0000 Subject: [PATCH] Clean up smyrna files: remove unnecessary globals modify libraries not to rely on code in cmd/smyrna remove static declarations from .h files remove unnecessary libraries mark unused code and clean up warnings --- lib/xdot/Makefile.am | 8 +- lib/xdot/xdot.c | 243 ++++++++----------------------------------- lib/xdot/xdot.h | 30 +----- 3 files changed, 48 insertions(+), 233 deletions(-) diff --git a/lib/xdot/Makefile.am b/lib/xdot/Makefile.am index dd745f361..d06cace41 100644 --- a/lib/xdot/Makefile.am +++ b/lib/xdot/Makefile.am @@ -3,13 +3,9 @@ AM_CPPFLAGS = \ -I$(top_srcdir) \ + -I$(top_srcdir)/lib/common \ -I$(top_srcdir)/lib/cgraph \ - -I$(top_srcdir)/lib/cdt \ - -I$(top_srcdir)/lib/glcomp \ - -I$(top_srcdir)/lib/utilities \ - -I$(top_srcdir)/lib/topfish \ - -I$(top_srcdir)/cmd/smyrna \ - $(GTK_CFLAGS) $(GTKGL_CFLAGS) $(GTKGLEXT_CFLAGS) $(GLADE_CFLAGS) $(FREETYPE2_CFLAGS) + -I$(top_srcdir)/lib/cdt if WITH_SMYRNA noinst_HEADERS = xdot.h diff --git a/lib/xdot/xdot.c b/lib/xdot/xdot.c index b2b3d1528..88bf16573 100755 --- a/lib/xdot/xdot.c +++ b/lib/xdot/xdot.c @@ -15,21 +15,14 @@ #include -//#include #include #include #include #include #include #include +#include #include -#include "draw.h" - - - -#define NEW(t) (t*)malloc(sizeof(t)) -#define N_NEW(n,t) (t*)malloc((n)*sizeof(t)) -#define RALLOC(size,ptr,type) ((type*)realloc(ptr,(size)*sizeof(type))) static char* parseFloat (char* s, float* fp) @@ -108,64 +101,64 @@ parseAlign (char* s, xdot_align* ap) return s; } -#ifdef NEWXDOT +#ifdef OLDXDOT static char* -parseOp (xdot_op* op, char* s, drawfunc_t ops[]) +parseOp (xdot_op* op, char* s) { while (isspace(*s)) s++; switch (*s++) { case 'E' : op->kind = xd_filled_ellipse; s = parseRect (s, &op->u.ellipse); - op->drawfunc=ops[xop_ellipse]; + op->drawfunc=DrawEllipse; break; case 'e' : op->kind = xd_unfilled_ellipse; s = parseRect (s, &op->u.ellipse); - op->drawfunc=ops[xop_ellipse]; + op->drawfunc=DrawEllipse; break; case 'P' : op->kind = xd_filled_polygon; s = parsePolyline (s, &op->u.polygon); - op->drawfunc=ops[xop_polygon]; + op->drawfunc=DrawPolygon; break; case 'p' : op->kind = xd_unfilled_polygon; s = parsePolyline (s, &op->u.polygon); - op->drawfunc=ops[xop_polygon]; + op->drawfunc=DrawPolygon; break; case 'b' : op->kind = xd_filled_bezier; s = parsePolyline (s, &op->u.bezier); - op->drawfunc=ops[xop_bezier]; + op->drawfunc=DrawBeziers; break; case 'B' : op->kind = xd_unfilled_bezier; s = parsePolyline (s, &op->u.bezier); - op->drawfunc=ops[xop_bezier]; + op->drawfunc=DrawBeziers; break; case 'c' : op->kind = xd_pen_color; s = parseString (s, &op->u.color); - op->drawfunc=ops[xop_pen_color]; + op->drawfunc=SetPenColor; break; case 'C' : op->kind = xd_fill_color; s = parseString (s, &op->u.color); - op->drawfunc=ops[xop_fill_color]; + op->drawfunc=SetFillColor; break; case 'L' : op->kind = xd_polyline; s = parsePolyline (s, &op->u.polyline); - op->drawfunc=ops[xop_polyline]; + op->drawfunc=DrawPolyline; break; case 'T' : @@ -175,27 +168,27 @@ parseOp (xdot_op* op, char* s, drawfunc_t ops[]) s = parseAlign (s, &op->u.text.align); s = parseInt (s, &op->u.text.width); s = parseString (s, &op->u.text.text); - op->drawfunc=ops[xop_text]; + op->drawfunc=EmbedText; break; case 'F' : op->kind = xd_font; s = parseFloat (s, &op->u.font.size); s = parseString (s, &op->u.font.name); - op->drawfunc=ops[xop_font]; + op->drawfunc=SetFont; break; case 'S' : op->kind = xd_style; s = parseString (s, &op->u.style); - op->drawfunc=ops[xop_style]; + op->drawfunc=SetStyle; break; case 'I' : op->kind = xd_image; s = parseRect (s, &op->u.image.pos); s = parseString (s, &op->u.image.name); - op->drawfunc=ops[xop_image]; + op->drawfunc=InsertImage; break; default : @@ -206,62 +199,62 @@ parseOp (xdot_op* op, char* s, drawfunc_t ops[]) } #else static char* -parseOp (xdot_op* op, char* s) +parseOp (xdot_op* op, char* s, drawfunc_t ops[]) { while (isspace(*s)) s++; switch (*s++) { case 'E' : op->kind = xd_filled_ellipse; s = parseRect (s, &op->u.ellipse); - op->drawfunc=DrawEllipse; + if (ops) op->drawfunc=ops[xop_ellipse]; break; case 'e' : op->kind = xd_unfilled_ellipse; s = parseRect (s, &op->u.ellipse); - op->drawfunc=DrawEllipse; + if (ops) op->drawfunc=ops[xop_ellipse]; break; case 'P' : op->kind = xd_filled_polygon; s = parsePolyline (s, &op->u.polygon); - op->drawfunc=DrawPolygon; + if (ops) op->drawfunc=ops[xop_polygon]; break; case 'p' : op->kind = xd_unfilled_polygon; s = parsePolyline (s, &op->u.polygon); - op->drawfunc=DrawPolygon; + if (ops) op->drawfunc=ops[xop_polygon]; break; case 'b' : op->kind = xd_filled_bezier; s = parsePolyline (s, &op->u.bezier); - op->drawfunc=DrawBeziers; + if (ops) op->drawfunc=ops[xop_bezier]; break; case 'B' : op->kind = xd_unfilled_bezier; s = parsePolyline (s, &op->u.bezier); - op->drawfunc=DrawBeziers; + if (ops) op->drawfunc=ops[xop_bezier]; break; case 'c' : op->kind = xd_pen_color; s = parseString (s, &op->u.color); - op->drawfunc=SetPenColor; + if (ops) op->drawfunc=ops[xop_pen_color]; break; case 'C' : op->kind = xd_fill_color; s = parseString (s, &op->u.color); - op->drawfunc=SetFillColor; + if (ops) op->drawfunc=ops[xop_fill_color]; break; case 'L' : op->kind = xd_polyline; s = parsePolyline (s, &op->u.polyline); - op->drawfunc=DrawPolyline; + if (ops) op->drawfunc=ops[xop_polyline]; break; case 'T' : @@ -271,27 +264,27 @@ parseOp (xdot_op* op, char* s) s = parseAlign (s, &op->u.text.align); s = parseInt (s, &op->u.text.width); s = parseString (s, &op->u.text.text); - op->drawfunc=EmbedText; + if (ops) op->drawfunc=ops[xop_text]; break; case 'F' : op->kind = xd_font; s = parseFloat (s, &op->u.font.size); s = parseString (s, &op->u.font.name); - op->drawfunc=SetFont; + if (ops) op->drawfunc=ops[xop_font]; break; case 'S' : op->kind = xd_style; s = parseString (s, &op->u.style); - op->drawfunc=SetStyle; + if (ops) op->drawfunc=ops[xop_style]; break; case 'I' : op->kind = xd_image; s = parseRect (s, &op->u.image.pos); s = parseString (s, &op->u.image.name); - op->drawfunc=InsertImage; + if (ops) op->drawfunc=ops[xop_image]; break; default : @@ -304,73 +297,43 @@ parseOp (xdot_op* op, char* s) #define XDBSIZE 100 -#ifdef NEWXDOT xdot* -parseXDotF (char* s, drawfunc_t fns[]) +parseXDotF (char* s, drawfunc_t fns[], int sz) { xdot* x; xdot_op op; - xdot_op* ops; + char* ops; int bufsz = XDBSIZE; if (!s) return NULL; x = NEW(xdot); - ops = N_NEW(XDBSIZE, xdot_op); + if (sz <= 0) sz = sizeof(xdot_op); + ops = (char*)gmalloc(XDBSIZE*sz); x->cnt = 0; while ((s = parseOp (&op, s, fns))) { if (x->cnt == bufsz) { bufsz += XDBSIZE; - ops = RALLOC (bufsz, ops, xdot_op); + ops = (char*)grealloc (ops, bufsz*sz); } - ops[x->cnt] = op; + *(xdot_op*)(ops + (x->cnt*sz)) = op; x->cnt++; } if (x->cnt) - x->ops = RALLOC (x->cnt, ops, xdot_op); + x->ops = (xdot_op*)grealloc (ops, x->cnt*sz); else { free (x); x = 0; } + free (x); return x; } xdot* parseXDot (char* s) { - return parseXDotF (s, 0); + return parseXDotF (s, 0, 0); } -#else -xdot* -parseXDot (char* s) -{ - xdot* x; - xdot_op op; - xdot_op* ops; - int bufsz = XDBSIZE; - if (!s) return NULL; - x = NEW(xdot); - ops = N_NEW(XDBSIZE, xdot_op); - - x->cnt = 0; - while ((s = parseOp (&op, s))) { - if (x->cnt == bufsz) { - bufsz += XDBSIZE; - ops = RALLOC (bufsz, ops, xdot_op); - } - ops[x->cnt] = op; - x->cnt++; - } - if (x->cnt) - x->ops = RALLOC (x->cnt, ops, xdot_op); - else { - free (x); - x = 0; - } - return x; -} -#endif - typedef void (*pf)(char*, void*); static void @@ -656,131 +619,11 @@ freeXDot (xdot* x) free (x); } -char* move_xdot(void* obj,xdot* x,int dx,int dy,int dz) -{ - int i=0; - int j=0; - /* int a=0; */ - /* char* pch; */ - /* int pos[MAXIMUM_POS_COUNT]; //maximum pos count hopefully does not exceed 100 */ - if (!x) - return "\0"; - - for (i=0;i < x->cnt ; i ++) - { - switch (x->ops[i].kind) - { - case xd_filled_polygon : - case xd_unfilled_polygon : - case xd_filled_bezier: - case xd_unfilled_bezier: - case xd_polyline: - for (j=0;j < x->ops[i].u.polygon.cnt; j++) - { - x->ops[i].u.polygon.pts[j].x=x->ops[i].u.polygon.pts[j].x-dx; - x->ops[i].u.polygon.pts[j].y=x->ops[i].u.polygon.pts[j].y-dy; - x->ops[i].u.polygon.pts[j].z=x->ops[i].u.polygon.pts[j].z-dz; - } - break; - case xd_filled_ellipse : - case xd_unfilled_ellipse : - x->ops[i].u.ellipse.x=x->ops[i].u.ellipse.x-dx; - x->ops[i].u.ellipse.y=x->ops[i].u.ellipse.y-dy; - // x->ops[i].u.ellipse.z=x->ops[i].u.ellipse.z-dz; - break; - case xd_text: - x->ops[i].u.text.x=x->ops[i].u.text.x-dx; - x->ops[i].u.text.y=x->ops[i].u.text.y-dy; - // x->ops[i].u.text.z=x->ops[i].u.text.z-dz; - break; - case xd_image : - x->ops[i].u.image.pos.x=x->ops[i].u.image.pos.x-dx; - x->ops[i].u.image.pos.y=x->ops[i].u.image.pos.y-dy; - // x->ops[i].u.image.pos.z=x->ops[i].u.image.pos.z-dz; - break; - default : - break; - } - } - view->GLx=view->GLx2; - view->GLy=view->GLy2; - return sprintXDot (x); - - -} -char* offset_spline(xdot* x,float dx,float dy,float headx,float heady) -{ #if 0 - /*int i=0; - Agnode_t* headn,tailn; - Agedge_t* e; - e=x->obj; //assume they are all edges, check function name - headn=aghead(e); - tailn=agtail(e); - - for (i=0; i < x->cnt ; i ++) //more than 1 splines ,possible - { - switch (x->ops[i].kind) - { - case xd_filled_polygon : - case xd_unfilled_polygon : - case xd_filled_bezier: - case xd_unfilled_bezier: - case xd_polyline: - if( ((custom_object_data*)AGDATA((headn)->obj))->Selected==1) && - ((custom_object_data*)AGDATA((tailn)->obj))->Selected==1) ) - { - for (j=0;j < x->ops[i].u.polygon.cnt; j++) - { - - x->ops[i].u.polygon.pts[j].x=x->ops[i].u.polygon.pts[j].x+dx; - x->ops[i].u.polygon.pts[j].y=x->ops[i].u.polygon.pts[j].y+dy; - x->ops[i].u.polygon.pts[j].z=x->ops[i].u.polygon.pts[j].z+dz; - } - } - break; - }*/ -#endif - return 0; -} - - - - -void drawXdot (xdot* xDot,int param) -{ - int id=0; - - for (id=0; id < xDot->cnt ; id ++) { - xDot->ops[id].parentxdot=xDot; - execOp (&xDot->ops[id],param); - - } - if ( ((custom_object_data*)AGDATA(xDot->obj))->Preselected == 1) - select_object (view->g[view->activeGraph],xDot->obj); - ((custom_object_data*)AGDATA(xDot->obj))->Preselected =0; -} -void execOp (xdot_op* op,int param) +static void +execOp (xdot_op* op,int param) { - op->drawfunc(op,param); + op->drawfunc(op,param); } +#endif - -void drawXdotwithattr(void* p,char* attr,int param) -{ - xdot* xDot; - if((xDot=parseXDot (agget(p, attr)))) { - xDot->obj=p; - drawXdot(xDot,param); - freeXDot (xDot); - } -} -void drawXdotwithattrs(void* e,int param) -{ - drawXdotwithattr(e,"_draw_",param); - drawXdotwithattr(e,"_ldraw_",param); - drawXdotwithattr(e,"_hdraw_",param); - drawXdotwithattr(e,"_tdraw_",param); - drawXdotwithattr(e,"_hldraw_",param); - drawXdotwithattr(e,"_tldraw_",param); -} diff --git a/lib/xdot/xdot.h b/lib/xdot/xdot.h index f7a551edb..3ce24cbcc 100755 --- a/lib/xdot/xdot.h +++ b/lib/xdot/xdot.h @@ -19,14 +19,7 @@ #ifdef _WIN32 #include #endif -#include #include "cgraph.h" -#define MAXIMUM_POS_COUNT 100 -typedef struct _TextTexture { - GLuint name; - GLsizei size; - GLvoid *texels; -} TextTexture; typedef enum { xd_left, xd_center, xd_right @@ -45,15 +38,11 @@ typedef struct { xdot_point* pts; } xdot_polyline; - typedef struct { int x, y; xdot_align align; int width; char* text; - GLuint name; - GLsizei size; - GLvoid *texels; } xdot_text; typedef struct { @@ -85,7 +74,7 @@ typedef enum { typedef struct _xdot_op xdot_op; typedef void (*drawfunc_t)(xdot_op*, int); -struct _xdot_op{ +struct _xdot_op { xdot_kind kind; union { xdot_rect ellipse; /* xd_filled_ellipse, xd_unfilled_ellipse */ @@ -99,30 +88,17 @@ struct _xdot_op{ char* style; /* xd_style */ } u; drawfunc_t drawfunc; - void* parentxdot; //points to owner xdot }; -void execOp (xdot_op* op,int param); typedef struct { int cnt; - xdot_op* ops; - void* obj; //cgraph object, used for selection - int selectionflag; //used for rectangular selection (not x) if -1 cannot be selected + xdot_op* ops; } xdot; /* ops are indexed by xop_kind */ -#ifdef NEWXDOT -extern xdot* parseXDotF (char*, drawfunc_t ops[]); -#endif +extern xdot* parseXDotF (char*, drawfunc_t ops[], int sz); extern xdot* parseXDot (char*); extern char* sprintXDot (xdot*); extern void fprintXDot (FILE*, xdot*); extern void freeXDot (xdot*); -extern void drawXdot (xdot*,int param); -extern Agnode_t* createNode(char* label,xdot_point); -extern char* move_xdot(void* obj,xdot* x,int dx,int dy,int dz); -extern char* offset_spline(xdot* x,float dx,float dy,float headx,float heady); -void drawXdotwithattrs(void* e,int param); -void drawXdotwithattr(void* p,char* attr,int param); -extern int select_object (Agraph_t* g,void* obj); #endif -- 2.40.0