-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
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 \
* AT&T Research, Florham Park NJ *
**********************************************************/
-#include "render.h"
-#include "gvplugin.h"
-#include "gvcint.h"
-#include "gvcproc.h"
-#include "colortbl.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <ctype.h>
-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;
}
}
-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;
*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]);
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;
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) {
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))) {
(void *) color_lib,
sizeof(color_lib) /
sizeof(hsbcolor_t), sizeof(fake),
- (bsearch_cmpf) colorcmpf);
+ colorcmpf);
}
if (last != NULL) {
switch (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;
case COLOR_INDEX:
break;
}
- return;
+ return rc;
}
* no specific dependance on graphs */
#include <stdio.h>
-#include "logic.h"
-#include "pathplan.h"
#include "geom.h"
point pointof(int x, int y)
/* 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
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 */
/* 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))))
#include <string.h>
#endif
-#include "logic.h"
-#include "geom.h"
-#include "pathplan.h"
#include "macros.h"
#include "const.h"
#include "types.h"
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);
#ifndef GV_TYPES_H
#define GV_TYPES_H
+#include "geom.h"
+#include "pathplan.h"
+#include "color.h"
+
#ifdef __cplusplus
extern "C" {
#endif
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;
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
#include <glob.h>
#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"
#include <stdio.h>
#include <stdlib.h>
-#include "logic.h"
#include "geom.h"
-#include "macros.h"
+
#include "types.h"
#include "graph.h"
+
#include "gvplugin.h"
#include "gvcint.h"
#include "gvcproc.h"
#include <stdio.h>
#include <string.h>
-#include "logic.h"
#include "geom.h"
+
#include "const.h"
#include "types.h"
-#include "macros.h"
#include "gvplugin_device.h"
#include "gvplugin.h"
#include <stdio.h>
#include <stdlib.h>
-#include "logic.h"
#include "geom.h"
+
#include "types.h"
+
#include "gvplugin.h"
#include "gvcint.h"
#include "gvcproc.h"
#include <stdio.h>
-#include "logic.h"
#include "geom.h"
+
#include "const.h"
#include "types.h"
-#include "macros.h"
#include "graph.h"
#include "cdt.h"
#include <ltdl.h>
#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"
#include <stdlib.h>
#include <string.h>
-#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"
#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;
char *name, color_t * color)
{
char *tok;
+ int rc;
color->u.string = name;
color->type = COLOR_STRING;
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");
+ }
+ }
}
}
#include <stdio.h>
-#include "logic.h"
#include "geom.h"
+
#include "const.h"
#include "types.h"
-#include "macros.h"
#include "gvplugin_textlayout.h"
#include "gvplugin.h"
#include <stdio.h>
-#include "logic.h"
#include "geom.h"
+
+#include "macros.h"
#include "const.h"
#include "types.h"
-#include "macros.h"
#include "cdt.h"
#include "graph.h"
#include <stdio.h>
-#include "logic.h"
#include "geom.h"
-#include "macros.h"
-#include "const.h"
+
#include "types.h"
#include "gvplugin_layout.h"
#include <stdio.h>
-#include "logic.h"
#include "geom.h"
-#include "macros.h"
-#include "const.h"
+
#include "types.h"
#include "gvplugin_layout.h"