From: ellson Date: Tue, 18 Oct 2005 18:35:13 +0000 (+0000) Subject: extract color.h from types.h X-Git-Tag: LAST_LIBGRAPH~32^2~7300 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ede18e900076a377908b7daade95ee4883e6437b;p=graphviz extract color.h from types.h --- diff --git a/lib/common/Makefile.am b/lib/common/Makefile.am index 252404787..eab1a2a83 100644 --- a/lib/common/Makefile.am +++ b/lib/common/Makefile.am @@ -9,9 +9,9 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/lib/graph \ -I$(top_srcdir)/lib/cdt @GD_INCLUDES@ @EXPAT_INCLUDES@ @Z_INCLUDES@ -pkginclude_HEADERS = logic.h geom.h const.h macros.h types.h globals.h \ - htmllex.h htmltable.h pointset.h render.h renderprocs.h \ - utils.h colortbl.h +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 noinst_LTLIBRARIES = libcommon.la if !DISABLE_CODEGENS diff --git a/lib/common/Makefile.old b/lib/common/Makefile.old index 0aef2071f..40f68da26 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 + renderprocs.h types.h utils.h geom.h logic.h color.h arith.h OBJS = args.o arrows.o gdusershape.o mapgen.o psgen.o svgusershape.o \ colxlate.o globals.o mifgen.o psusershape.o timing.o \ diff --git a/lib/common/colxlate.c b/lib/common/colxlate.c index ad0ea4776..c12a6feaf 100644 --- a/lib/common/colxlate.c +++ b/lib/common/colxlate.c @@ -14,15 +14,16 @@ * AT&T Research, Florham Park NJ * **********************************************************/ -#include "render.h" -#include "gvplugin.h" -#include "gvcint.h" -#include "gvcproc.h" -#include "colortbl.h" +#include +#include +#include #include -static void hsv2rgb(double h, double s, double v, double *r, double *g, - double *b) +#include "color.h" +#include "colortbl.h" + +static void hsv2rgb(double h, double s, double v, + double *r, double *g, double *b) { int i; double f, p, q, t; @@ -75,8 +76,8 @@ static void hsv2rgb(double h, double s, double v, double *r, double *g, } } -static void rgb2hsv(double r, double g, double b, double *h, double *s, - double *v) +static void rgb2hsv(double r, double g, double b, + double *h, double *s, double *v) { double rgbmin, rgbmax; @@ -121,7 +122,7 @@ static void rgb2cmyk(double r, double g, double b, double *c, double *m, *y -= *k; } -static int colorcmpf(void *p0, void *p1) +static int colorcmpf(const void *p0, const void *p1) { /* fast comparison of first character */ int i = (((hsbcolor_t *) p0)->name[0] - ((hsbcolor_t *) p1)->name[0]); @@ -132,40 +133,47 @@ static int colorcmpf(void *p0, void *p1) char *canontoken(char *str) { - static unsigned char canon[SMALLBUF]; - unsigned char c; - unsigned char *p = (unsigned char *) str; - unsigned char *q = canon; - int i = SMALLBUF; + static unsigned char *canon; + static int allocated; + unsigned char c, *p, *q; + int len; - while ((c = *p++) && (--i)) { + p = (unsigned char *) str; + len = strlen(str); + if (len >= allocated) { + allocated = len + 1 + 10; + canon = realloc(canon, allocated); + if (!canon) + return NULL; + } + q = (unsigned char *) canon; + while ((c = *p++)) { if (isalnum(c) == FALSE) continue; if (isupper(c)) c = tolower(c); *q++ = c; } - if (c) - agerr(AGWARN, "color value '%s' truncated\n", str); *q = '\0'; - return (char *) canon; + return (char*)canon; } -void colorxlate(char *str, color_t * color, color_type_t target_type) +int colorxlate(char *str, color_t * color, color_type_t target_type) { static hsbcolor_t *last; - hsbcolor_t fake; - unsigned char canon[SMALLBUF]; + static unsigned char *canon; + static int allocated; unsigned char *p, *q; - char *missedcolor; - unsigned char ch; + hsbcolor_t fake; + unsigned char c; double H, S, V, R, G, B; double C, M, Y, K; unsigned int r, g, b, a; - int i; + int len, rc; color->type = target_type; + rc = COLOR_OK; for (; *str == ' '; str++); /* skip over any leading whitespace */ p = (unsigned char *) str; @@ -217,20 +225,26 @@ void colorxlate(char *str, color_t * color, color_type_t target_type) case COLOR_INDEX: break; } - return; + return rc; } /* test for hsv value such as: ".6,.5,.3" */ - if (((ch = *p) == '.') || isdigit(ch)) { + if (((c = *p) == '.') || isdigit(c)) { + len = strlen((char*)p); + if (len >= allocated) { + allocated = len + 1 + 10; + canon = realloc(canon, allocated); + if (! canon) { + rc = COLOR_MALLOC_FAIL; + return rc; + } + } q = canon; - i = SMALLBUF; - while ((ch = *p++) && (--i)) { - if (ch == ',') - ch = ' '; - *q++ = ch; + while ((c = *p++)) { + if (c == ',') + c = ' '; + *q++ = c; } - if (ch) - agerr(AGWARN, "color value '%s' truncated\n", str); *q = '\0'; if (sscanf((char *) canon, "%lf%lf%lf", &H, &S, &V) == 3) { @@ -278,12 +292,14 @@ void colorxlate(char *str, color_t * color, color_type_t target_type) case COLOR_INDEX: break; } - return; + return rc; } } /* test for known color name (generic, not renderer specific known names) */ fake.name = canontoken(str); + if (!fake.name) + return COLOR_MALLOC_FAIL; if ((last == NULL) || (last->name[0] != fake.name[0]) || (strcmp(last->name, fake.name))) { @@ -291,7 +307,7 @@ void colorxlate(char *str, color_t * color, color_type_t target_type) (void *) color_lib, sizeof(color_lib) / sizeof(hsbcolor_t), sizeof(fake), - (bsearch_cmpf) colorcmpf); + colorcmpf); } if (last != NULL) { switch (target_type) { @@ -346,15 +362,11 @@ void colorxlate(char *str, color_t * color, color_type_t target_type) case COLOR_INDEX: break; } - return; + return rc; } /* if we're still here then we failed to find a valid color spec */ - missedcolor = malloc(strlen(str) + 16); - sprintf(missedcolor, "color %s", str); - if (emit_once(missedcolor)) - agerr(AGWARN, "%s is not a known color. Using black.\n", str); - free(missedcolor); + rc = COLOR_UNKNOWN; switch (target_type) { case HSV_DOUBLE: color->u.HSV[0] = color->u.HSV[1] = color->u.HSV[2] = 0.0; @@ -381,5 +393,5 @@ void colorxlate(char *str, color_t * color, color_type_t target_type) case COLOR_INDEX: break; } - return; + return rc; } diff --git a/lib/common/geom.c b/lib/common/geom.c index 196167f2a..f8aeef29b 100644 --- a/lib/common/geom.c +++ b/lib/common/geom.c @@ -18,8 +18,6 @@ * no specific dependance on graphs */ #include -#include "logic.h" -#include "pathplan.h" #include "geom.h" point pointof(int x, int y) diff --git a/lib/common/geom.h b/lib/common/geom.h index c606a9e3a..1d30a2bb8 100644 --- a/lib/common/geom.h +++ b/lib/common/geom.h @@ -17,11 +17,11 @@ /* geometric functions (e.g. on points and boxes) with application to, but * no specific dependance on graphs */ +#include "arith.h" + #ifndef GV_GEOM_H #define GV_GEOM_H -#include "pathplan.h" - #ifdef __cplusplus extern "C" { #endif @@ -29,45 +29,14 @@ extern "C" { typedef struct { int x, y; } point; typedef struct pointf_s { double x, y; } pointf; + +/* tell pathplan/pathgeom.h */ #define HAVE_POINTF_S typedef struct { point LL, UR; } box; typedef struct { pointf LL, UR; } boxf; -#ifdef MIN -#undef MIN -#endif -#define MIN(a,b) ((a)<(b)?(a):(b)) - -#ifdef MAX -#undef MAX -#endif -#define MAX(a,b) ((a)>(b)?(a):(b)) - -#ifdef ABS -#undef ABS -#endif -#define ABS(a) ((a) >= 0 ? (a) : -(a)) - -#ifndef MAXINT -#define MAXINT ((int)(~(unsigned)0 >> 1)) -#endif -#ifndef MAXSHORT -#define MAXSHORT (0x7fff) -#endif -#ifndef MAXDOUBLE -#define MAXDOUBLE 1.7976931348623157e+308 -#endif -#ifndef MAXFLOAT -#define MAXFLOAT ((float)3.40282347e+38) -#endif - -#ifdef BETWEEN -#undef BETWEEN -#endif -#define BETWEEN(a,b,c) (((a) <= (b)) && ((b) <= (c))) - /* true if point p is inside box b */ #define INSIDE(p,b) (BETWEEN((b).LL.x,(p).x,(b).UR.x) && BETWEEN((b).LL.y,(p).y,(b).UR.y)) /* true if boxes b0 and b1 overlap */ @@ -80,11 +49,6 @@ typedef struct { pointf LL, UR; } boxf; /* expand box b0 as needed to enclose box b1 */ #define EXPANDBB(b0, b1) (b0.LL.x = MIN(b0.LL.x, b1.LL.x), b0.LL.y = MIN(b0.LL.y, b1.LL.y), b0.UR.x = MAX(b0.UR.x, b1.UR.x), b0.UR.y = MAX(b0.UR.y, b1.UR.y)) -#define ROUND(f) ((f>=0)?(int)(f + .5):(int)(f - .5)) -#define RADIANS(deg) ((deg)/180.0 * PI) -#define DEGREES(rad) ((rad)/PI * 180.0) - -#define SQR(v) ((v) * (v)) #define DIST2(p1,p2) (SQR((p1.x) - (p2.x))) + (SQR((p1.y) - (p2.y))) #define DIST(p1,p2) (sqrt(DIST2((p1),(p2)))) diff --git a/lib/common/render.h b/lib/common/render.h index 0454b89f4..1f5add85c 100644 --- a/lib/common/render.h +++ b/lib/common/render.h @@ -49,9 +49,6 @@ #include #endif -#include "logic.h" -#include "geom.h" -#include "pathplan.h" #include "macros.h" #include "const.h" #include "types.h" diff --git a/lib/common/renderprocs.h b/lib/common/renderprocs.h index 7252e284f..3e5d20316 100644 --- a/lib/common/renderprocs.h +++ b/lib/common/renderprocs.h @@ -42,8 +42,6 @@ extern "C" { splineInfo *); extern char *canontoken(char *str); extern char* charsetToStr (int c); - extern void colorxlate(char *str, color_t * color, - color_type_t target_type); extern point coord(node_t * n); extern void do_graph_label(graph_t * sg); extern void graph_init(graph_t * g, boolean use_rankdir); diff --git a/lib/common/types.h b/lib/common/types.h index db52d9654..acede7b6f 100644 --- a/lib/common/types.h +++ b/lib/common/types.h @@ -17,6 +17,10 @@ #ifndef GV_TYPES_H #define GV_TYPES_H +#include "geom.h" +#include "pathplan.h" +#include "color.h" + #ifdef __cplusplus extern "C" { #endif @@ -292,29 +296,6 @@ extern "C" { unsigned char sides; /* sides of node exposed to field */ } field_t; - typedef struct hsbcolor_t { - char *name; - unsigned char h, s, b; - } hsbcolor_t; - -/* possible representations of color in color_t */ - typedef enum { HSV_DOUBLE, RGBA_BYTE, RGBA_WORD, CMYK_BYTE, - RGBA_DOUBLE, COLOR_STRING, COLOR_INDEX } color_type_t; - -/* color_t can hold a color spec in a choice or representations */ - typedef struct color_s { - union { - double RGBA[4]; - double HSV[3]; - unsigned char rgba[4]; - unsigned char cmyk[4]; - int rrggbbaa[4]; - char *string; - int index; - } u; - color_type_t type; - } color_t; - typedef struct nlist_t { node_t **list; int size; diff --git a/lib/common/utils.h b/lib/common/utils.h index 8396edbfa..3359e7d6a 100644 --- a/lib/common/utils.h +++ b/lib/common/utils.h @@ -18,15 +18,6 @@ extern "C" { #endif - -/* extern char *pathget(char *, char *, char *); */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "geom.h" - #ifndef HAVE_STRCASECMP extern int strcasecmp(const char *s1, const char *s2); #endif diff --git a/lib/gvc/gvconfig.c b/lib/gvc/gvconfig.c index 2b3079935..9a76bac86 100644 --- a/lib/gvc/gvconfig.c +++ b/lib/gvc/gvconfig.c @@ -29,12 +29,13 @@ #include #endif -#include "logic.h" #include "geom.h" -#include "macros.h" +#include "color.h" + #include "const.h" #include "types.h" #include "graph.h" + #include "gvplugin.h" #include "gvcint.h" #include "gvcproc.h" diff --git a/lib/gvc/gvcontext.c b/lib/gvc/gvcontext.c index 7bf67158e..ae732d6df 100644 --- a/lib/gvc/gvcontext.c +++ b/lib/gvc/gvcontext.c @@ -29,11 +29,11 @@ #include #include -#include "logic.h" #include "geom.h" -#include "macros.h" + #include "types.h" #include "graph.h" + #include "gvplugin.h" #include "gvcint.h" #include "gvcproc.h" diff --git a/lib/gvc/gvdevice.c b/lib/gvc/gvdevice.c index a0df29f30..0c95b5272 100644 --- a/lib/gvc/gvdevice.c +++ b/lib/gvc/gvdevice.c @@ -27,11 +27,10 @@ #include #include -#include "logic.h" #include "geom.h" + #include "const.h" #include "types.h" -#include "macros.h" #include "gvplugin_device.h" #include "gvplugin.h" diff --git a/lib/gvc/gvjobs.c b/lib/gvc/gvjobs.c index d7d263e83..e0fbb347e 100644 --- a/lib/gvc/gvjobs.c +++ b/lib/gvc/gvjobs.c @@ -21,9 +21,10 @@ #include #include -#include "logic.h" #include "geom.h" + #include "types.h" + #include "gvplugin.h" #include "gvcint.h" #include "gvcproc.h" diff --git a/lib/gvc/gvlayout.c b/lib/gvc/gvlayout.c index 16ede4ae5..d52b603f2 100644 --- a/lib/gvc/gvlayout.c +++ b/lib/gvc/gvlayout.c @@ -25,11 +25,10 @@ #include -#include "logic.h" #include "geom.h" + #include "const.h" #include "types.h" -#include "macros.h" #include "graph.h" #include "cdt.h" diff --git a/lib/gvc/gvplugin.c b/lib/gvc/gvplugin.c index 18051aac1..c87f78ac0 100644 --- a/lib/gvc/gvplugin.c +++ b/lib/gvc/gvplugin.c @@ -26,11 +26,11 @@ #include #endif -#include "logic.h" #include "geom.h" + #include "types.h" -#include "macros.h" #include "graph.h" + #include "gvplugin.h" #include "gvcint.h" #include "gvcproc.h" diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index d2205289e..f5ab323a8 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -29,12 +29,12 @@ #include #include -#include "logic.h" #include "geom.h" +#include "pathplan.h" +#include "color.h" #include "const.h" #include "types.h" #include "macros.h" -#include "geom.h" #include "globals.h" #include "graph.h" #include "cdt.h" @@ -44,15 +44,12 @@ #include "gvcint.h" #include "gvcproc.h" +extern int emit_once(char *str); + #ifndef DISABLE_CODEGENS extern codegen_t PS_CodeGen; #endif -/* FIXME - need these but without rest of crap in common/ */ -extern void colorxlate(char *str, color_t * color, - color_type_t target_type); -extern char *canontoken(char *str); - int gvrender_select(GVJ_t * job, char *str) { GVC_t *gvc = job->gvc; @@ -197,6 +194,7 @@ static void gvrender_resolve_color(gvrender_features_t * features, char *name, color_t * color) { char *tok; + int rc; color->u.string = name; color->type = COLOR_STRING; @@ -204,7 +202,19 @@ static void gvrender_resolve_color(gvrender_features_t * features, if (!features->knowncolors || (bsearch(&tok, features->knowncolors, features->sz_knowncolors, sizeof(char *), gvrender_comparestr)) == NULL) { /* if tok was not found in known_colors */ - colorxlate(name, color, features->color_type); + rc = colorxlate(name, color, features->color_type); + if (rc != COLOR_OK) { + if (rc == COLOR_UNKNOWN) { + char *missedcolor = malloc(strlen(name) + 16); + sprintf(missedcolor, "color %s", name); + if (emit_once(missedcolor)) + agerr(AGWARN, "%s is not a known color.\n", name); + free(missedcolor); + } + else { + agerr(AGERR, "error in colxlate()\n"); + } + } } } diff --git a/lib/gvc/gvtextlayout.c b/lib/gvc/gvtextlayout.c index c6f5b5eb0..9365cf2c7 100644 --- a/lib/gvc/gvtextlayout.c +++ b/lib/gvc/gvtextlayout.c @@ -24,11 +24,10 @@ #include -#include "logic.h" #include "geom.h" + #include "const.h" #include "types.h" -#include "macros.h" #include "gvplugin_textlayout.h" #include "gvplugin.h" diff --git a/lib/gvc/gvusershape.c b/lib/gvc/gvusershape.c index 4ce4fadb4..6beaaad0b 100644 --- a/lib/gvc/gvusershape.c +++ b/lib/gvc/gvusershape.c @@ -37,11 +37,11 @@ #include -#include "logic.h" #include "geom.h" + +#include "macros.h" #include "const.h" #include "types.h" -#include "macros.h" #include "cdt.h" #include "graph.h" diff --git a/plugin/dot_layout/gvlayout_dot_layout.c b/plugin/dot_layout/gvlayout_dot_layout.c index 9555d01aa..6b2564d86 100644 --- a/plugin/dot_layout/gvlayout_dot_layout.c +++ b/plugin/dot_layout/gvlayout_dot_layout.c @@ -21,10 +21,8 @@ #include -#include "logic.h" #include "geom.h" -#include "macros.h" -#include "const.h" + #include "types.h" #include "gvplugin_layout.h" diff --git a/plugin/neato_layout/gvlayout_neato_layout.c b/plugin/neato_layout/gvlayout_neato_layout.c index ecd92864d..bbc600f5f 100644 --- a/plugin/neato_layout/gvlayout_neato_layout.c +++ b/plugin/neato_layout/gvlayout_neato_layout.c @@ -26,10 +26,8 @@ #include -#include "logic.h" #include "geom.h" -#include "macros.h" -#include "const.h" + #include "types.h" #include "gvplugin_layout.h"