42#define ND_relrank(n) (((Agnodeinfo_t*)((n)->base.data))->relrank)
43#define ND_x(n) (((Agnodeinfo_t*)((n)->base.data))->x)
57static int cmpf(
const void *x,
const void *y) {
62#pragma GCC diagnostic push
63#pragma GCC diagnostic ignored "-Wcast-qual"
68#pragma GCC diagnostic pop
72 if (relrank0 < relrank1)
74 if (relrank0 > relrank1)
82 if (sscanf(p,
"%lf %lf %lf", v, v + 1, v + 2) != 3 && p[0]) {
84 sscanf(
agxbuse(&buf),
"%lf %lf %lf", v, v + 1, v + 2);
91static char *
useString =
"Usage: gvcolor [-?] <files>\n\
93If no files are specified, stdin is used\n";
101static void init(
int argc,
char *argv[])
106 while ((c = getopt(argc, argv,
":?")) != -1) {
109 if (optopt ==
'\0' || optopt ==
'?')
112 fprintf(stderr,
"gvcolor: option -%c unrecognized\n",
118 fprintf(stderr,
"gvcolor: unexpected error\n");
135 double x, y, maxrank = 0.0;
136 double sum[
NC], d, lowsat, highsat;
140 "graph must be run through 'dot' before 'gvcolor'\n");
146 if ((p =
agget(g,
"Defcolor")))
149 if ((p =
agget(g,
"rankdir")) && p[0] ==
'L')
151 if ((p =
agget(g,
"flow")) && p[0] ==
'b')
153 if ((p =
agget(g,
"saturation"))) {
154 if (sscanf(p,
"%lf,%lf", &lowsat, &highsat) == 2) {
164 size_t nnodes = (size_t)nn;
169 if ((p =
agget(n,
"color")))
172 sscanf(p,
"%lf,%lf", &x, &y);
177 for (i = 0; i < nnodes; i++) {
184 for (i = 0; i < nnodes; i++) {
189 for (j = 0; j <
NC; j++)
190 if (
ND_x(n)[j] != 0.0)
195 for (j = 0; j <
NC; j++)
205 for (j = 0; j <
NC; j++) {
207 sum[j] +=
ND_x(v)[j];
214 for (j = 0; j <
NC; j++)
219 for (i = 0; i < nnodes; i++) {
226 for (j = 0; j <
NC; j++)
245 snprintf(buf,
sizeof(buf),
"%f %f %f", h,
s, b);
246 agset(n,
"color", buf);
static void agxbfree(agxbuf *xb)
free any malloced resources
static WUR char * agxbuse(agxbuf *xb)
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
abstract graph C library, Cgraph API
void colorxlate(char *str, agxbuf *buf)
static NORETURN void graphviz_exit(int status)
static int cnt(Dict_t *d, Dtlink_t **set)
int agnnodes(Agraph_t *g)
Agsym_t * agattr(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up attributes of a graph
int agset(void *obj, char *name, const char *value)
char * agget(void *obj, char *name)
Agedge_t * agnxtedge(Agraph_t *g, Agedge_t *e, Agnode_t *n)
Agedge_t * agfstedge(Agraph_t *g, Agnode_t *n)
int agclose(Agraph_t *g)
deletes a graph, freeing its associated storage
int agwrite(Agraph_t *g, void *chan)
Return 0 on success, EOF on failure.
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Agnode_t * agfstnode(Agraph_t *g)
void aginit(Agraph_t *g, int kind, const char *rec_name, int rec_size, int move_to_front)
attach new records to objects of specified kind
static void init(int argc, char *argv[])
static int cmpf(const void *x, const void *y)
static void color(Agraph_t *g)
static void setcolor(char *p, double *v)
static const char * usage
Agraph_t * nextGraph(ingraph_state *sp)
ingraph_state * newIngraph(ingraph_state *sp, char **files)
supports user-supplied data
implementation of Agrec_t