]>
Commit | Line | Data |
---|---|---|
ce4d5ce0 | 1 | /* VCG description handler for Bison. |
4613f49b | 2 | |
a737b216 | 3 | Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. |
ce4d5ce0 AD |
4 | |
5 | This file is part of Bison, the GNU Compiler Compiler. | |
6 | ||
7 | Bison is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | Bison is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with Bison; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #include "system.h" | |
17ee7397 PE |
23 | |
24 | #include <quotearg.h> | |
25 | ||
ce4d5ce0 AD |
26 | #include "vcg.h" |
27 | #include "vcg_defaults.h" | |
08a946e0 | 28 | |
e5fb6710 AD |
29 | /* Return an unambiguous printable representated, for NAME, suitable |
30 | for C strings. Use slot 2 since the user may use slots 0 and 1. | |
31 | */ | |
32 | ||
08a946e0 AD |
33 | static char const * |
34 | quote (char const *name) | |
35 | { | |
e5fb6710 | 36 | return quotearg_n_style (2, c_quoting_style, name); |
08a946e0 AD |
37 | } |
38 | ||
ce4d5ce0 AD |
39 | |
40 | /* Initialize a graph with the default values. */ | |
41 | void | |
17ee7397 | 42 | new_graph (graph *g) |
ce4d5ce0 AD |
43 | { |
44 | g->title = G_TITLE; | |
45 | g->label = G_LABEL; | |
3e3da797 | 46 | |
ce4d5ce0 AD |
47 | g->infos[0] = G_INFOS1; |
48 | g->infos[1] = G_INFOS2; | |
49 | g->infos[2] = G_INFOS3; | |
3e3da797 | 50 | |
ce4d5ce0 AD |
51 | g->color = G_COLOR; |
52 | g->textcolor = G_TEXTCOLOR; | |
53 | g->bordercolor = G_BORDERCOLOR; | |
3e3da797 | 54 | |
ce4d5ce0 AD |
55 | g->width = G_WIDTH; |
56 | g->height = G_HEIGHT; | |
57 | g->borderwidth = G_BORDERWIDTH; | |
58 | g->x = G_X; | |
59 | g->y = G_Y; | |
60 | g->folding = G_FOLDING; | |
61 | g->shrink = G_SHRINK; | |
17ee7397 | 62 | g->expand = G_EXPAND; |
ce4d5ce0 AD |
63 | |
64 | g->textmode = G_TEXTMODE; | |
65 | g->shape = G_SHAPE; | |
3e3da797 | 66 | |
342b8b6e AD |
67 | g->vertical_order = G_VERTICAL_ORDER; |
68 | g->horizontal_order = G_HORIZONTAL_ORDER; | |
69 | ||
ce4d5ce0 AD |
70 | g->xmax = G_XMAX; /* Not output. */ |
71 | g->ymax = G_YMAX; /* Not output. */ | |
3e3da797 | 72 | |
ce4d5ce0 AD |
73 | g->xbase = G_XBASE; |
74 | g->ybase = G_YBASE; | |
75 | ||
76 | g->xspace = G_XSPACE; | |
77 | g->yspace = G_YSPACE; | |
78 | g->xlspace = G_XLSPACE; /* Not output. */ | |
3e3da797 | 79 | |
ce4d5ce0 AD |
80 | g->xraster = G_XRASTER; |
81 | g->yraster = G_YRASTER; | |
82 | g->xlraster = G_XLRASTER; | |
83 | ||
84 | g->hidden = G_HIDDEN; /* No default value. */ | |
85 | ||
86 | g->classname = G_CLASSNAME; /* No class name association. */ | |
3e3da797 | 87 | |
ce4d5ce0 AD |
88 | g->layoutalgorithm = G_LAYOUTALGORITHM; |
89 | g->layout_downfactor = G_LAYOUT_DOWNFACTOR; | |
90 | g->layout_upfactor = G_LAYOUT_UPFACTOR; | |
91 | g->layout_nearfactor = G_LAYOUT_NEARFACTOR; | |
92 | g->layout_splinefactor = G_LAYOUT_SPLINEFACTOR; | |
3e3da797 | 93 | |
ce4d5ce0 AD |
94 | g->late_edge_labels = G_LATE_EDGE_LABELS; |
95 | g->display_edge_labels = G_DISPLAY_EDGE_LABELS; | |
96 | g->dirty_edge_labels = G_DIRTY_EDGE_LABELS; | |
97 | g->finetuning = G_FINETUNING; | |
98 | g->ignore_singles = G_IGNORE_SINGLES; | |
ce4d5ce0 AD |
99 | g->priority_phase = G_PRIORITY_PHASE; |
100 | g->manhattan_edges = G_MANHATTAN_EDGES; | |
101 | g->smanhattan_edges = G_SMANHATTAN_EDGES; | |
102 | g->near_edges = G_NEAR_EDGES; | |
3e3da797 | 103 | |
ce4d5ce0 | 104 | g->orientation = G_ORIENTATION; |
17ee7397 | 105 | g->node_alignment = G_NODE_ALIGNMENT; |
ce4d5ce0 AD |
106 | g->port_sharing = G_PORT_SHARING; |
107 | g->arrow_mode = G_ARROW_MODE; | |
108 | g->treefactor = G_TREEFACTOR; | |
109 | g->spreadlevel = G_SPREADLEVEL; | |
110 | g->crossing_weight = G_CROSSING_WEIGHT; | |
111 | g->crossing_phase2 = G_CROSSING_PHASE2; | |
112 | g->crossing_optimization = G_CROSSING_OPTIMIZATION; | |
113 | g->view = G_VIEW; | |
114 | ||
115 | g->edges = G_EDGES; | |
116 | g->nodes = G_NODES; | |
117 | g->splines = G_SPLINES; | |
118 | ||
119 | g->bmax = G_BMAX; | |
120 | g->cmin = G_CMIN; | |
121 | g->cmax = G_CMAX; | |
122 | g->pmin = G_PMIN; | |
123 | g->pmax = G_PMAX; | |
124 | g->rmin = G_RMIN; | |
125 | g->rmax = G_RMAX; | |
126 | g->smax = G_SMAX; | |
3e3da797 | 127 | |
ce4d5ce0 AD |
128 | g->node_list = G_NODE_LIST; |
129 | g->edge_list = G_EDGE_LIST; | |
3e3da797 | 130 | |
17ee7397 PE |
131 | new_edge (&g->edge); |
132 | new_node (&g->node); | |
ce4d5ce0 AD |
133 | } |
134 | ||
17ee7397 | 135 | /* Initialize a node with the default values. */ |
ce4d5ce0 | 136 | void |
17ee7397 | 137 | new_node (node *n) |
ce4d5ce0 | 138 | { |
17ee7397 PE |
139 | n->title = N_TITLE; |
140 | n->label = N_LABEL; | |
3e3da797 | 141 | |
17ee7397 PE |
142 | n->locx = N_LOCX; /* Default unspcified. */ |
143 | n->locy = N_LOCY; /* Default unspcified. */ | |
3e3da797 | 144 | |
17ee7397 PE |
145 | n->vertical_order = N_VERTICAL_ORDER; /* Default unspcified. */ |
146 | n->horizontal_order = N_HORIZONTAL_ORDER; /* Default unspcified. */ | |
3e3da797 | 147 | |
17ee7397 PE |
148 | n->width = N_WIDTH; /* We assume that we can't define it now. */ |
149 | n->height = N_HEIGHT; /* Also. */ | |
3e3da797 | 150 | |
17ee7397 PE |
151 | n->shrink = N_SHRINK; |
152 | n->expand = N_EXPAND; | |
3e3da797 | 153 | |
17ee7397 | 154 | n->folding = N_FOLDING; /* No explicit default value. */ |
3e3da797 | 155 | |
17ee7397 PE |
156 | n->shape = N_SHAPE; |
157 | n->textmode = N_TEXTMODE; | |
158 | n->borderwidth = N_BORDERWIDTH; | |
3e3da797 | 159 | |
17ee7397 PE |
160 | n->color = N_COLOR; |
161 | n->textcolor = N_TEXTCOLOR; | |
162 | n->bordercolor = N_BORDERCOLOR; | |
3e3da797 | 163 | |
17ee7397 PE |
164 | n->infos[0] = N_INFOS1; |
165 | n->infos[1] = N_INFOS2; | |
166 | n->infos[2] = N_INFOS3; | |
3e3da797 | 167 | |
17ee7397 | 168 | n->next = N_NEXT; |
ce4d5ce0 AD |
169 | } |
170 | ||
17ee7397 | 171 | /* Initialize an edge with the default values. */ |
ce4d5ce0 | 172 | void |
17ee7397 | 173 | new_edge (edge *e) |
ce4d5ce0 | 174 | { |
17ee7397 | 175 | e->type = E_EDGE_TYPE; |
ce4d5ce0 | 176 | |
17ee7397 PE |
177 | e->sourcename = E_SOURCENAME; |
178 | e->targetname = E_TARGETNAME; | |
179 | e->label = E_LABEL; | |
ce4d5ce0 | 180 | |
17ee7397 PE |
181 | e->linestyle = E_LINESTYLE; |
182 | e->thickness = E_THICKNESS; | |
ce4d5ce0 | 183 | |
17ee7397 | 184 | e->class = E_CLASS; |
ce4d5ce0 | 185 | |
17ee7397 PE |
186 | e->color = E_COLOR; |
187 | e->textcolor = E_TEXTCOLOR; | |
188 | e->arrowcolor = E_ARROWCOLOR; | |
189 | e->backarrowcolor = E_BACKARROWCOLOR; | |
ce4d5ce0 | 190 | |
17ee7397 PE |
191 | e->arrowsize = E_ARROWSIZE; |
192 | e->backarrowsize = E_BACKARROWSIZE; | |
193 | e->arrowstyle = E_ARROWSTYLE; | |
ce4d5ce0 | 194 | |
17ee7397 | 195 | e->backarrowstyle = E_BACKARROWSTYLE; |
ce4d5ce0 | 196 | |
17ee7397 | 197 | e->priority = E_PRIORITY; |
ce4d5ce0 | 198 | |
17ee7397 | 199 | e->anchor = E_ANCHOR; |
ce4d5ce0 | 200 | |
17ee7397 | 201 | e->horizontal_order = E_HORIZONTAL_ORDER; |
ce4d5ce0 | 202 | |
17ee7397 | 203 | e->next = E_NEXT; |
ce4d5ce0 AD |
204 | } |
205 | ||
206 | /*----------------------------------------------. | |
207 | | Get functions. | | |
208 | | Return string corresponding to an enum value. | | |
209 | `----------------------------------------------*/ | |
210 | ||
211 | static const char * | |
a737b216 | 212 | get_color_str (enum color color) |
ce4d5ce0 | 213 | { |
a737b216 | 214 | switch (color) |
ce4d5ce0 | 215 | { |
3e3da797 AD |
216 | case white: return "white"; |
217 | case blue: return "blue"; | |
218 | case red: return "red"; | |
219 | case green: return "green"; | |
220 | case yellow: return "yellow"; | |
221 | case magenta: return "magenta"; | |
222 | case cyan: return "cyan"; | |
223 | case darkgrey: return "darkgrey"; | |
224 | case darkblue: return "darkblue"; | |
225 | case darkred: return "darkred"; | |
226 | case darkgreen: return "darkgreen"; | |
227 | case darkyellow: return "darkyellow"; | |
228 | case darkmagenta: return "darkmagenta"; | |
229 | case darkcyan: return "darkcyan"; | |
230 | case gold: return "gold"; | |
231 | case lightgrey: return "lightgrey"; | |
232 | case lightblue: return "lightblue"; | |
233 | case lightred: return "lightred"; | |
234 | case lightgreen: return "lightgreen"; | |
235 | case lightyellow: return "lightyellow"; | |
236 | case lightmagenta: return "lightmagenta"; | |
237 | case lightcyan: return "lightcyan"; | |
238 | case lilac: return "lilac"; | |
239 | case turquoise: return "turquoise"; | |
240 | case aquamarine: return "aquamarine"; | |
241 | case khaki: return "khaki"; | |
242 | case purple: return "purple"; | |
243 | case yellowgreen: return "yellowgreen"; | |
244 | case pink: return "pink"; | |
245 | case orange: return "orange"; | |
246 | case orchid: return "orchid"; | |
247 | case black: return "black"; | |
4344c500 | 248 | default: abort (); return NULL; |
ce4d5ce0 | 249 | } |
ce4d5ce0 AD |
250 | } |
251 | ||
252 | static const char * | |
a737b216 | 253 | get_textmode_str (enum textmode textmode) |
ce4d5ce0 | 254 | { |
a737b216 | 255 | switch (textmode) |
ce4d5ce0 | 256 | { |
3e3da797 AD |
257 | case centered: return "center"; |
258 | case left_justify: return "left_justify"; | |
259 | case right_justify: return "right_justify"; | |
4344c500 | 260 | default: abort (); return NULL; |
ce4d5ce0 | 261 | } |
ce4d5ce0 AD |
262 | } |
263 | ||
264 | static const char * | |
a737b216 | 265 | get_shape_str (enum shape shape) |
ce4d5ce0 | 266 | { |
a737b216 | 267 | switch (shape) |
ce4d5ce0 | 268 | { |
3e3da797 AD |
269 | case box: return "box"; |
270 | case rhomb: return "rhomb"; | |
271 | case ellipse: return "ellipse"; | |
272 | case triangle: return "triangle"; | |
4344c500 | 273 | default: abort (); return NULL; |
ce4d5ce0 | 274 | } |
ce4d5ce0 AD |
275 | } |
276 | ||
277 | static const char * | |
a737b216 | 278 | get_layoutalgorithm_str (enum layoutalgorithm layoutalgorithm) |
ce4d5ce0 | 279 | { |
a737b216 | 280 | switch (layoutalgorithm) |
ce4d5ce0 | 281 | { |
3e3da797 AD |
282 | case normal: return "normal"; |
283 | case maxdepth: return "maxdepth"; | |
284 | case mindepth: return "mindepth"; | |
285 | case maxdepthslow: return "maxdepthslow"; | |
286 | case mindepthslow: return "mindepthslow"; | |
287 | case maxdegree: return "maxdegree"; | |
288 | case mindegree: return "mindegree"; | |
289 | case maxindegree: return "maxindegree"; | |
290 | case minindegree: return "minindegree"; | |
291 | case maxoutdegree: return "maxoutdegree"; | |
292 | case minoutdegree: return "minoutdegree"; | |
293 | case minbackward: return "minbackward"; | |
294 | case dfs: return "dfs"; | |
295 | case tree: return "tree"; | |
4344c500 | 296 | default: abort (); return NULL; |
ce4d5ce0 | 297 | } |
ce4d5ce0 AD |
298 | } |
299 | ||
300 | static const char * | |
a737b216 | 301 | get_decision_str (enum decision decision) |
ce4d5ce0 | 302 | { |
a737b216 | 303 | switch (decision) |
ce4d5ce0 | 304 | { |
3e3da797 AD |
305 | case no: return "no"; |
306 | case yes: return "yes"; | |
4344c500 | 307 | default: abort (); return NULL; |
ce4d5ce0 | 308 | } |
ce4d5ce0 AD |
309 | } |
310 | ||
311 | static const char * | |
a737b216 | 312 | get_orientation_str (enum orientation orientation) |
ce4d5ce0 | 313 | { |
a737b216 | 314 | switch (orientation) |
ce4d5ce0 | 315 | { |
3e3da797 AD |
316 | case top_to_bottom: return "top_to_bottom"; |
317 | case bottom_to_top: return "bottom_to_top"; | |
318 | case left_to_right: return "left_to_right"; | |
319 | case right_to_left: return "right_to_left"; | |
4344c500 | 320 | default: abort (); return NULL; |
ce4d5ce0 | 321 | } |
ce4d5ce0 AD |
322 | } |
323 | ||
324 | static const char * | |
a737b216 | 325 | get_node_alignment_str (enum alignment alignment) |
ce4d5ce0 | 326 | { |
a737b216 | 327 | switch (alignment) |
ce4d5ce0 | 328 | { |
3e3da797 AD |
329 | case center: return "center"; |
330 | case top: return "top"; | |
331 | case bottom: return "bottom"; | |
4344c500 | 332 | default: abort (); return NULL; |
ce4d5ce0 | 333 | } |
ce4d5ce0 AD |
334 | } |
335 | ||
336 | static const char * | |
a737b216 | 337 | get_arrow_mode_str (enum arrow_mode arrow_mode) |
ce4d5ce0 | 338 | { |
a737b216 | 339 | switch (arrow_mode) |
ce4d5ce0 | 340 | { |
3e3da797 AD |
341 | case fixed: return "fixed"; |
342 | case free_a: return "free"; | |
4344c500 | 343 | default: abort (); return NULL; |
ce4d5ce0 | 344 | } |
ce4d5ce0 AD |
345 | } |
346 | ||
347 | static const char * | |
a737b216 | 348 | get_crossing_type_str (enum crossing_type crossing_type) |
ce4d5ce0 | 349 | { |
a737b216 | 350 | switch (crossing_type) |
ce4d5ce0 | 351 | { |
3e3da797 AD |
352 | case bary: return "bary"; |
353 | case median: return "median"; | |
354 | case barymedian: return "barymedian"; | |
355 | case medianbary: return "medianbary"; | |
4344c500 | 356 | default: abort (); return NULL; |
3e3da797 | 357 | } |
ce4d5ce0 AD |
358 | } |
359 | ||
360 | static const char * | |
a737b216 | 361 | get_view_str (enum view view) |
ce4d5ce0 | 362 | { |
a737b216 | 363 | switch (view) |
ce4d5ce0 | 364 | { |
3e3da797 AD |
365 | case normal_view: return "normal_view"; |
366 | case cfish: return "cfish"; | |
367 | case pfish: return "pfish"; | |
368 | case fcfish: return "fcfish"; | |
369 | case fpfish: return "fpfish"; | |
4344c500 | 370 | default: abort (); return NULL; |
ce4d5ce0 | 371 | } |
ce4d5ce0 AD |
372 | } |
373 | ||
374 | static const char * | |
a737b216 | 375 | get_linestyle_str (enum linestyle linestyle) |
ce4d5ce0 | 376 | { |
a737b216 | 377 | switch (linestyle) |
ce4d5ce0 | 378 | { |
3e3da797 AD |
379 | case continuous: return "continuous"; |
380 | case dashed: return "dashed"; | |
381 | case dotted: return "dotted"; | |
382 | case invisible: return "invisible"; | |
4344c500 | 383 | default: abort (); return NULL; |
3e3da797 | 384 | } |
ce4d5ce0 AD |
385 | } |
386 | ||
387 | static const char * | |
a737b216 | 388 | get_arrowstyle_str (enum arrowstyle arrowstyle) |
ce4d5ce0 | 389 | { |
a737b216 | 390 | switch (arrowstyle) |
ce4d5ce0 | 391 | { |
3e3da797 AD |
392 | case solid: return "solid"; |
393 | case line: return "line"; | |
394 | case none: return "none"; | |
4344c500 | 395 | default: abort (); return NULL; |
ce4d5ce0 | 396 | } |
ce4d5ce0 AD |
397 | } |
398 | ||
17ee7397 PE |
399 | /*------------------------------. |
400 | | Add functions. | | |
401 | | Edge and nodes into a graph. | | |
402 | `------------------------------*/ | |
ce4d5ce0 AD |
403 | |
404 | void | |
17ee7397 | 405 | add_node (graph *g, node *n) |
ce4d5ce0 | 406 | { |
17ee7397 PE |
407 | n->next = g->node_list; |
408 | g->node_list = n; | |
ce4d5ce0 AD |
409 | } |
410 | ||
411 | void | |
17ee7397 | 412 | add_edge (graph *g, edge *e) |
ce4d5ce0 | 413 | { |
17ee7397 PE |
414 | e->next = g->edge_list; |
415 | g->edge_list = e; | |
ce4d5ce0 AD |
416 | } |
417 | ||
342b8b6e | 418 | void |
17ee7397 | 419 | add_classname (graph *g, int val, const char *name) |
342b8b6e | 420 | { |
17ee7397 | 421 | struct classname *classname; |
08a946e0 | 422 | |
4613f49b | 423 | MALLOC (classname, 1); |
342b8b6e AD |
424 | classname->no = val; |
425 | classname->name = name; | |
426 | classname->next = g->classname; | |
427 | g->classname = classname; | |
428 | } | |
429 | ||
430 | void | |
17ee7397 | 431 | add_infoname (graph *g, int integer, const char *str) |
342b8b6e | 432 | { |
17ee7397 | 433 | struct infoname *infoname; |
08a946e0 | 434 | |
4613f49b | 435 | MALLOC (infoname, 1); |
342b8b6e | 436 | infoname->integer = integer; |
17ee7397 | 437 | infoname->chars = str; |
342b8b6e AD |
438 | infoname->next = g->infoname; |
439 | g->infoname = infoname; | |
440 | } | |
441 | ||
442 | /* Build a colorentry struct and add it to the list. */ | |
443 | void | |
17ee7397 | 444 | add_colorentry (graph *g, int color_idx, int red_cp, |
342b8b6e AD |
445 | int green_cp, int blue_cp) |
446 | { | |
17ee7397 | 447 | struct colorentry *ce; |
08a946e0 | 448 | |
4613f49b | 449 | MALLOC (ce, 1); |
342b8b6e AD |
450 | ce->color_index = color_idx; |
451 | ce->red_cp = red_cp; | |
452 | ce->green_cp = green_cp; | |
453 | ce->blue_cp = blue_cp; | |
454 | ce->next = g->colorentry; | |
455 | g->colorentry = ce; | |
456 | } | |
457 | ||
ce4d5ce0 AD |
458 | /*-------------------------------------. |
459 | | Open and close functions (formatted) | | |
460 | `-------------------------------------*/ | |
461 | ||
462 | void | |
17ee7397 | 463 | open_edge (edge *e, FILE *fout) |
ce4d5ce0 | 464 | { |
17ee7397 | 465 | switch (e->type) |
ce4d5ce0 AD |
466 | { |
467 | case normal_edge: | |
342b8b6e | 468 | fputs ("\tedge: {\n", fout); |
ce4d5ce0 AD |
469 | break; |
470 | case back_edge: | |
342b8b6e | 471 | fputs ("\tbackedge: {\n", fout); |
ce4d5ce0 AD |
472 | break; |
473 | case near_edge: | |
342b8b6e | 474 | fputs ("\tnearedge: {\n", fout); |
ce4d5ce0 AD |
475 | break; |
476 | case bent_near_edge: | |
342b8b6e | 477 | fputs ("\tbentnearedge: {\n", fout); |
3e3da797 | 478 | break; |
ce4d5ce0 | 479 | default: |
342b8b6e | 480 | fputs ("\tedge: {\n", fout); |
3e3da797 | 481 | } |
ce4d5ce0 AD |
482 | } |
483 | ||
484 | void | |
17ee7397 | 485 | close_edge (FILE *fout) |
ce4d5ce0 | 486 | { |
342b8b6e | 487 | fputs ("\t}\n", fout); |
ce4d5ce0 AD |
488 | } |
489 | ||
490 | void | |
17ee7397 | 491 | open_node (FILE *fout) |
ce4d5ce0 | 492 | { |
342b8b6e | 493 | fputs ("\tnode: {\n", fout); |
ce4d5ce0 AD |
494 | } |
495 | ||
496 | void | |
17ee7397 | 497 | close_node (FILE *fout) |
3e3da797 | 498 | { |
342b8b6e | 499 | fputs ("\t}\n", fout); |
ce4d5ce0 AD |
500 | } |
501 | ||
502 | void | |
17ee7397 | 503 | open_graph (FILE *fout) |
ce4d5ce0 | 504 | { |
342b8b6e | 505 | fputs ("graph: {\n", fout); |
ce4d5ce0 AD |
506 | } |
507 | ||
508 | void | |
17ee7397 | 509 | close_graph (graph *g, FILE *fout) |
ce4d5ce0 | 510 | { |
342b8b6e | 511 | fputc ('\n', fout); |
ce4d5ce0 | 512 | |
342b8b6e | 513 | /* FIXME: Unallocate nodes and edges if required. */ |
ce4d5ce0 | 514 | { |
17ee7397 | 515 | node *n; |
3e3da797 | 516 | |
17ee7397 | 517 | for (n = g->node_list; n; n = n->next) |
ce4d5ce0 | 518 | { |
342b8b6e | 519 | open_node (fout); |
17ee7397 | 520 | output_node (n, fout); |
342b8b6e | 521 | close_node (fout); |
ce4d5ce0 AD |
522 | } |
523 | } | |
3e3da797 | 524 | |
342b8b6e | 525 | fputc ('\n', fout); |
3e3da797 | 526 | |
ce4d5ce0 | 527 | { |
17ee7397 | 528 | edge *e; |
3e3da797 | 529 | |
17ee7397 | 530 | for (e = g->edge_list; e; e = e->next) |
3e3da797 | 531 | { |
17ee7397 PE |
532 | open_edge (e, fout); |
533 | output_edge (e, fout); | |
342b8b6e | 534 | close_edge (fout); |
ce4d5ce0 AD |
535 | } |
536 | } | |
3e3da797 | 537 | |
342b8b6e | 538 | fputs ("}\n", fout); |
3e3da797 AD |
539 | } |
540 | ||
ce4d5ce0 | 541 | /*-------------------------------------------. |
342b8b6e | 542 | | Output functions (formatted) in file FOUT | |
ce4d5ce0 AD |
543 | `-------------------------------------------*/ |
544 | ||
545 | void | |
17ee7397 | 546 | output_node (node *n, FILE *fout) |
ce4d5ce0 | 547 | { |
17ee7397 PE |
548 | if (n->title != N_TITLE) |
549 | fprintf (fout, "\t\ttitle:\t%s\n", quote (n->title)); | |
550 | if (n->label != N_LABEL) | |
551 | fprintf (fout, "\t\tlabel:\t%s\n", quote (n->label)); | |
ce4d5ce0 | 552 | |
17ee7397 PE |
553 | if ((n->locx != N_LOCX) && (n->locy != N_LOCY)) |
554 | fprintf (fout, "\t\tloc { x: %d y: %d }\t\n", n->locx, n->locy); | |
3e3da797 | 555 | |
17ee7397 PE |
556 | if (n->vertical_order != N_VERTICAL_ORDER) |
557 | fprintf (fout, "\t\tvertical_order:\t%d\n", n->vertical_order); | |
558 | if (n->horizontal_order != N_HORIZONTAL_ORDER) | |
559 | fprintf (fout, "\t\thorizontal_order:\t%d\n", n->horizontal_order); | |
3e3da797 | 560 | |
17ee7397 PE |
561 | if (n->width != N_WIDTH) |
562 | fprintf (fout, "\t\twidth:\t%d\n", n->width); | |
563 | if (n->height != N_HEIGHT) | |
564 | fprintf (fout, "\t\theight:\t%d\n", n->height); | |
3e3da797 | 565 | |
17ee7397 PE |
566 | if (n->shrink != N_SHRINK) |
567 | fprintf (fout, "\t\tshrink:\t%d\n", n->shrink); | |
568 | if (n->expand != N_EXPAND) | |
569 | fprintf (fout, "\t\texpand:\t%d\n", n->expand); | |
3e3da797 | 570 | |
17ee7397 PE |
571 | if (n->folding != N_FOLDING) |
572 | fprintf (fout, "\t\tfolding:\t%d\n", n->folding); | |
3e3da797 | 573 | |
17ee7397 | 574 | if (n->textmode != N_TEXTMODE) |
342b8b6e | 575 | fprintf (fout, "\t\ttextmode:\t%s\n", |
17ee7397 | 576 | get_textmode_str (n->textmode)); |
3e3da797 | 577 | |
17ee7397 PE |
578 | if (n->shape != N_SHAPE) |
579 | fprintf (fout, "\t\tshape:\t%s\n", get_shape_str (n->shape)); | |
3e3da797 | 580 | |
17ee7397 PE |
581 | if (n->borderwidth != N_BORDERWIDTH) |
582 | fprintf (fout, "\t\tborderwidth:\t%d\n", n->borderwidth); | |
3e3da797 | 583 | |
17ee7397 PE |
584 | if (n->color != N_COLOR) |
585 | fprintf (fout, "\t\tcolor:\t%s\n", get_color_str (n->color)); | |
586 | if (n->textcolor != N_TEXTCOLOR) | |
342b8b6e | 587 | fprintf (fout, "\t\ttextcolor:\t%s\n", |
17ee7397 PE |
588 | get_color_str (n->textcolor)); |
589 | if (n->bordercolor != N_BORDERCOLOR) | |
342b8b6e | 590 | fprintf (fout, "\t\tbordercolor:\t%s\n", |
17ee7397 | 591 | get_color_str (n->bordercolor)); |
3e3da797 | 592 | |
08a946e0 AD |
593 | { |
594 | int i; | |
595 | for (i = 0; i < 3; ++i) | |
17ee7397 | 596 | if (n->infos[i]) |
08a946e0 | 597 | fprintf (fout, "\t\tinfo%d:\t%s\n", |
17ee7397 | 598 | i, quote (n->infos[i])); |
08a946e0 | 599 | } |
ce4d5ce0 AD |
600 | } |
601 | ||
602 | void | |
17ee7397 | 603 | output_edge (edge *e, FILE *fout) |
ce4d5ce0 | 604 | { |
600cad3b MA |
605 | /* FIXME: SOURCENAME and TARGETNAME are mandatory |
606 | so it has to be fatal not to give these informations. */ | |
17ee7397 PE |
607 | if (e->sourcename != E_SOURCENAME) |
608 | fprintf (fout, "\t\tsourcename:\t%s\n", quote (e->sourcename)); | |
609 | if (e->targetname != E_TARGETNAME) | |
610 | fprintf (fout, "\t\ttargetname:\t%s\n", quote (e->targetname)); | |
3e3da797 | 611 | |
17ee7397 PE |
612 | if (e->label != E_LABEL) |
613 | fprintf (fout, "\t\tlabel:\t%s\n", quote (e->label)); | |
ce4d5ce0 | 614 | |
17ee7397 | 615 | if (e->linestyle != E_LINESTYLE) |
08a946e0 | 616 | fprintf (fout, "\t\tlinestyle:\t%s\n", |
17ee7397 | 617 | quote (get_linestyle_str (e->linestyle))); |
3e3da797 | 618 | |
17ee7397 PE |
619 | if (e->thickness != E_THICKNESS) |
620 | fprintf (fout, "\t\tthickness:\t%d\n", e->thickness); | |
621 | if (e->class != E_CLASS) | |
622 | fprintf (fout, "\t\tclass:\t%d\n", e->class); | |
ce4d5ce0 | 623 | |
17ee7397 PE |
624 | if (e->color != E_COLOR) |
625 | fprintf (fout, "\t\tcolor:\t%s\n", get_color_str (e->color)); | |
626 | if (e->color != E_TEXTCOLOR) | |
342b8b6e | 627 | fprintf (fout, "\t\ttextcolor:\t%s\n", |
17ee7397 PE |
628 | get_color_str (e->textcolor)); |
629 | if (e->arrowcolor != E_ARROWCOLOR) | |
342b8b6e | 630 | fprintf (fout, "\t\tarrowcolor:\t%s\n", |
17ee7397 PE |
631 | get_color_str (e->arrowcolor)); |
632 | if (e->backarrowcolor != E_BACKARROWCOLOR) | |
342b8b6e | 633 | fprintf (fout, "\t\tbackarrowcolor:\t%s\n", |
17ee7397 | 634 | get_color_str (e->backarrowcolor)); |
ce4d5ce0 | 635 | |
17ee7397 PE |
636 | if (e->arrowsize != E_ARROWSIZE) |
637 | fprintf (fout, "\t\tarrowsize:\t%d\n", e->arrowsize); | |
638 | if (e->backarrowsize != E_BACKARROWSIZE) | |
639 | fprintf (fout, "\t\tbackarrowsize:\t%d\n", e->backarrowsize); | |
3e3da797 | 640 | |
17ee7397 | 641 | if (e->arrowstyle != E_ARROWSTYLE) |
342b8b6e | 642 | fprintf (fout, "\t\tarrowstyle:\t%s\n", |
17ee7397 PE |
643 | get_arrowstyle_str (e->arrowstyle)); |
644 | if (e->backarrowstyle != E_BACKARROWSTYLE) | |
342b8b6e | 645 | fprintf (fout, "\t\tbackarrowstyle:\t%s\n", |
17ee7397 PE |
646 | get_arrowstyle_str (e->backarrowstyle)); |
647 | ||
648 | if (e->priority != E_PRIORITY) | |
649 | fprintf (fout, "\t\tpriority:\t%d\n", e->priority); | |
650 | if (e->anchor != E_ANCHOR) | |
651 | fprintf (fout, "\t\tanchor:\t%d\n", e->anchor); | |
652 | if (e->horizontal_order != E_HORIZONTAL_ORDER) | |
653 | fprintf (fout, "\t\thorizontal_order:\t%d\n", e->horizontal_order); | |
ce4d5ce0 AD |
654 | } |
655 | ||
656 | void | |
17ee7397 | 657 | output_graph (graph *g, FILE *fout) |
ce4d5ce0 | 658 | { |
17ee7397 PE |
659 | if (g->title) |
660 | fprintf (fout, "\ttitle:\t%s\n", quote (g->title)); | |
661 | if (g->label) | |
662 | fprintf (fout, "\tlabel:\t%s\n", quote (g->label)); | |
3e3da797 | 663 | |
08a946e0 AD |
664 | { |
665 | int i; | |
666 | for (i = 0; i < 3; ++i) | |
17ee7397 PE |
667 | if (g->infos[i]) |
668 | fprintf (fout, "\tinfo%d:\t%s\n", i, quote (g->infos[i])); | |
08a946e0 | 669 | } |
3e3da797 | 670 | |
17ee7397 PE |
671 | if (g->color != G_COLOR) |
672 | fprintf (fout, "\tcolor:\t%s\n", get_color_str (g->color)); | |
673 | if (g->textcolor != G_TEXTCOLOR) | |
674 | fprintf (fout, "\ttextcolor:\t%s\n", get_color_str (g->textcolor)); | |
675 | if (g->bordercolor != G_BORDERCOLOR) | |
342b8b6e | 676 | fprintf (fout, "\tbordercolor:\t%s\n", |
17ee7397 | 677 | get_color_str (g->bordercolor)); |
3e3da797 | 678 | |
17ee7397 PE |
679 | if (g->width != G_WIDTH) |
680 | fprintf (fout, "\twidth:\t%d\n", g->width); | |
681 | if (g->height != G_HEIGHT) | |
682 | fprintf (fout, "\theight:\t%d\n", g->height); | |
683 | if (g->borderwidth != G_BORDERWIDTH) | |
684 | fprintf (fout, "\tborderwidth:\t%d\n", g->borderwidth); | |
3e3da797 | 685 | |
17ee7397 PE |
686 | if (g->x != G_X) |
687 | fprintf (fout, "\tx:\t%d\n", g->x); | |
688 | if (g->y != G_Y) | |
689 | fprintf (fout, "\ty:\t%d\n", g->y); | |
ce4d5ce0 | 690 | |
17ee7397 PE |
691 | if (g->folding != G_FOLDING) |
692 | fprintf (fout, "\tfolding:\t%d\n", g->folding); | |
ce4d5ce0 | 693 | |
17ee7397 PE |
694 | if (g->shrink != G_SHRINK) |
695 | fprintf (fout, "\tshrink:\t%d\n", g->shrink); | |
696 | if (g->expand != G_EXPAND) | |
697 | fprintf (fout, "\texpand:\t%d\n", g->expand); | |
3e3da797 | 698 | |
17ee7397 | 699 | if (g->textmode != G_TEXTMODE) |
342b8b6e | 700 | fprintf (fout, "\ttextmode:\t%s\n", |
17ee7397 PE |
701 | get_textmode_str (g->textmode)); |
702 | ||
703 | if (g->shape != G_SHAPE) | |
704 | fprintf (fout, "\tshape:\t%s\n", get_shape_str (g->shape)); | |
705 | ||
706 | if (g->vertical_order != G_VERTICAL_ORDER) | |
707 | fprintf (fout, "\tvertical_order:\t%d\n", g->vertical_order); | |
708 | if (g->horizontal_order != G_HORIZONTAL_ORDER) | |
709 | fprintf (fout, "\thorizontal_order:\t%d\n", g->horizontal_order); | |
710 | ||
711 | if (g->xmax != G_XMAX) | |
712 | fprintf (fout, "\txmax:\t%d\n", g->xmax); | |
713 | if (g->ymax != G_YMAX) | |
714 | fprintf (fout, "\tymax:\t%d\n", g->ymax); | |
715 | ||
716 | if (g->xbase != G_XBASE) | |
717 | fprintf (fout, "\txbase:\t%d\n", g->xbase); | |
718 | if (g->ybase != G_YBASE) | |
719 | fprintf (fout, "\tybase:\t%d\n", g->ybase); | |
720 | ||
721 | if (g->xspace != G_XSPACE) | |
722 | fprintf (fout, "\txspace:\t%d\n", g->xspace); | |
723 | if (g->yspace != G_YSPACE) | |
724 | fprintf (fout, "\tyspace:\t%d\n", g->yspace); | |
725 | if (g->xlspace != G_XLSPACE) | |
726 | fprintf (fout, "\txlspace:\t%d\n", g->xlspace); | |
727 | ||
728 | if (g->xraster != G_XRASTER) | |
729 | fprintf (fout, "\txraster:\t%d\n", g->xraster); | |
730 | if (g->yraster != G_YRASTER) | |
731 | fprintf (fout, "\tyraster:\t%d\n", g->yraster); | |
732 | if (g->xlraster != G_XLRASTER) | |
733 | fprintf (fout, "\txlraster:\t%d\n", g->xlraster); | |
734 | ||
735 | if (g->hidden != G_HIDDEN) | |
736 | fprintf (fout, "\thidden:\t%d\n", g->hidden); | |
08a946e0 AD |
737 | |
738 | /* FIXME: Unallocate struct list if required. | |
342b8b6e | 739 | Maybe with a little function. */ |
17ee7397 | 740 | if (g->classname != G_CLASSNAME) |
ce4d5ce0 | 741 | { |
17ee7397 | 742 | struct classname *ite; |
3e3da797 | 743 | |
17ee7397 | 744 | for (ite = g->classname; ite; ite = ite->next) |
342b8b6e AD |
745 | fprintf (fout, "\tclassname %d :\t%s\n", ite->no, ite->name); |
746 | } | |
747 | ||
17ee7397 | 748 | if (g->infoname != G_INFONAME) |
342b8b6e | 749 | { |
17ee7397 | 750 | struct infoname *ite; |
342b8b6e | 751 | |
17ee7397 PE |
752 | for (ite = g->infoname; ite; ite = ite->next) |
753 | fprintf (fout, "\tinfoname %d :\t%s\n", ite->integer, ite->chars); | |
342b8b6e AD |
754 | } |
755 | ||
17ee7397 | 756 | if (g->colorentry != G_COLORENTRY) |
342b8b6e | 757 | { |
17ee7397 | 758 | struct colorentry *ite; |
08a946e0 | 759 | |
17ee7397 | 760 | for (ite = g->colorentry; ite; ite = ite->next) |
08a946e0 AD |
761 | { |
762 | fprintf (fout, "\tcolorentry %d :\t%d %d %d\n", | |
763 | ite->color_index, | |
342b8b6e AD |
764 | ite->red_cp, |
765 | ite->green_cp, | |
766 | ite->blue_cp); | |
08a946e0 | 767 | } |
ce4d5ce0 | 768 | } |
3e3da797 | 769 | |
17ee7397 | 770 | if (g->layoutalgorithm != G_LAYOUTALGORITHM) |
342b8b6e | 771 | fprintf (fout, "\tlayoutalgorithm:\t%s\n", |
17ee7397 PE |
772 | get_layoutalgorithm_str (g->layoutalgorithm)); |
773 | ||
774 | if (g->layout_downfactor != G_LAYOUT_DOWNFACTOR) | |
775 | fprintf (fout, "\tlayout_downfactor:\t%d\n", g->layout_downfactor); | |
776 | if (g->layout_upfactor != G_LAYOUT_UPFACTOR) | |
777 | fprintf (fout, "\tlayout_upfactor:\t%d\n", g->layout_upfactor); | |
778 | if (g->layout_nearfactor != G_LAYOUT_NEARFACTOR) | |
779 | fprintf (fout, "\tlayout_nearfactor:\t%d\n", g->layout_nearfactor); | |
780 | if (g->layout_splinefactor != G_LAYOUT_SPLINEFACTOR) | |
342b8b6e | 781 | fprintf (fout, "\tlayout_splinefactor:\t%d\n", |
17ee7397 | 782 | g->layout_splinefactor); |
3e3da797 | 783 | |
17ee7397 | 784 | if (g->late_edge_labels != G_LATE_EDGE_LABELS) |
342b8b6e | 785 | fprintf (fout, "\tlate_edge_labels:\t%s\n", |
17ee7397 PE |
786 | get_decision_str (g->late_edge_labels)); |
787 | if (g->display_edge_labels != G_DISPLAY_EDGE_LABELS) | |
342b8b6e | 788 | fprintf (fout, "\tdisplay_edge_labels:\t%s\n", |
17ee7397 PE |
789 | get_decision_str (g->display_edge_labels)); |
790 | if (g->dirty_edge_labels != G_DIRTY_EDGE_LABELS) | |
342b8b6e | 791 | fprintf (fout, "\tdirty_edge_labels:\t%s\n", |
17ee7397 PE |
792 | get_decision_str (g->dirty_edge_labels)); |
793 | if (g->finetuning != G_FINETUNING) | |
342b8b6e | 794 | fprintf (fout, "\tfinetuning:\t%s\n", |
17ee7397 PE |
795 | get_decision_str (g->finetuning)); |
796 | if (g->ignore_singles != G_IGNORE_SINGLES) | |
342b8b6e | 797 | fprintf (fout, "\tignore_singles:\t%s\n", |
17ee7397 | 798 | get_decision_str (g->ignore_singles)); |
17ee7397 | 799 | if (g->priority_phase != G_PRIORITY_PHASE) |
342b8b6e | 800 | fprintf (fout, "\tpriority_phase:\t%s\n", |
17ee7397 PE |
801 | get_decision_str (g->priority_phase)); |
802 | if (g->manhattan_edges != G_MANHATTAN_EDGES) | |
342b8b6e AD |
803 | fprintf (fout, |
804 | "\tmanhattan_edges:\t%s\n", | |
17ee7397 PE |
805 | get_decision_str (g->manhattan_edges)); |
806 | if (g->smanhattan_edges != G_SMANHATTAN_EDGES) | |
342b8b6e AD |
807 | fprintf (fout, |
808 | "\tsmanhattan_edges:\t%s\n", | |
17ee7397 PE |
809 | get_decision_str (g->smanhattan_edges)); |
810 | if (g->near_edges != G_NEAR_EDGES) | |
342b8b6e | 811 | fprintf (fout, "\tnear_edges:\t%s\n", |
17ee7397 | 812 | get_decision_str (g->near_edges)); |
3e3da797 | 813 | |
17ee7397 | 814 | if (g->orientation != G_ORIENTATION) |
342b8b6e | 815 | fprintf (fout, "\torientation:\t%s\n", |
17ee7397 | 816 | get_orientation_str (g->orientation)); |
3e3da797 | 817 | |
17ee7397 PE |
818 | if (g->node_alignment != G_NODE_ALIGNMENT) |
819 | fprintf (fout, "\tnode_alignment:\t%s\n", | |
820 | get_node_alignment_str (g->node_alignment)); | |
3e3da797 | 821 | |
17ee7397 | 822 | if (g->port_sharing != G_PORT_SHARING) |
342b8b6e | 823 | fprintf (fout, "\tport_sharing:\t%s\n", |
17ee7397 | 824 | get_decision_str (g->port_sharing)); |
3e3da797 | 825 | |
17ee7397 | 826 | if (g->arrow_mode != G_ARROW_MODE) |
342b8b6e | 827 | fprintf (fout, "\tarrow_mode:\t%s\n", |
17ee7397 | 828 | get_arrow_mode_str (g->arrow_mode)); |
3e3da797 | 829 | |
17ee7397 PE |
830 | if (g->treefactor != G_TREEFACTOR) |
831 | fprintf (fout, "\ttreefactor:\t%f\n", g->treefactor); | |
832 | if (g->spreadlevel != G_SPREADLEVEL) | |
833 | fprintf (fout, "\tspreadlevel:\t%d\n", g->spreadlevel); | |
3e3da797 | 834 | |
17ee7397 | 835 | if (g->crossing_weight != G_CROSSING_WEIGHT) |
342b8b6e | 836 | fprintf (fout, "\tcrossing_weight:\t%s\n", |
17ee7397 PE |
837 | get_crossing_type_str (g->crossing_weight)); |
838 | if (g->crossing_phase2 != G_CROSSING_PHASE2) | |
342b8b6e | 839 | fprintf (fout, "\tcrossing_phase2:\t%s\n", |
17ee7397 PE |
840 | get_decision_str (g->crossing_phase2)); |
841 | if (g->crossing_optimization != G_CROSSING_OPTIMIZATION) | |
342b8b6e | 842 | fprintf (fout, "\tcrossing_optimization:\t%s\n", |
17ee7397 PE |
843 | get_decision_str (g->crossing_optimization)); |
844 | ||
845 | if (g->view != G_VIEW) | |
846 | fprintf (fout, "\tview:\t%s\n", get_view_str (g->view)); | |
847 | ||
848 | if (g->edges != G_EDGES) | |
849 | fprintf (fout, "\tedges:\t%s\n", get_decision_str (g->edges)); | |
850 | ||
851 | if (g->nodes != G_NODES) | |
852 | fprintf (fout,"\tnodes:\t%s\n", get_decision_str (g->nodes)); | |
853 | ||
854 | if (g->splines != G_SPLINES) | |
855 | fprintf (fout, "\tsplines:\t%s\n", get_decision_str (g->splines)); | |
856 | ||
857 | if (g->bmax != G_BMAX) | |
858 | fprintf (fout, "\tbmax:\t%d\n", g->bmax); | |
859 | if (g->cmin != G_CMIN) | |
860 | fprintf (fout, "\tcmin:\t%d\n", g->cmin); | |
861 | if (g->cmax != G_CMAX) | |
862 | fprintf (fout, "\tcmax:\t%d\n", g->cmax); | |
863 | if (g->pmin != G_PMIN) | |
864 | fprintf (fout, "\tpmin:\t%d\n", g->pmin); | |
865 | if (g->pmax != G_PMAX) | |
866 | fprintf (fout, "\tpmax:\t%d\n", g->pmax); | |
867 | if (g->rmin != G_RMIN) | |
868 | fprintf (fout, "\trmin:\t%d\n", g->rmin); | |
869 | if (g->rmax != G_RMAX) | |
870 | fprintf (fout, "\trmax:\t%d\n", g->rmax); | |
871 | if (g->smax != G_SMAX) | |
872 | fprintf (fout, "\tsmax:\t%d\n", g->smax); | |
ce4d5ce0 | 873 | } |