dpif.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593
  1. /*
  2. * Copyright 2021
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. * These are the four essential freedoms with GNU GPL software:
  18. * 1: freedom to run the program, for any purpose
  19. * 2: freedom to study how the program works, and change it to make it do what you wish
  20. * 3: freedom to redistribute copies to help your Free Software friends
  21. * 4: freedom to distribute copies of your modified versions to your Free Software friends
  22. * , ,
  23. * / \
  24. * ((__-^^-,-^^-__))
  25. * `-_---' `---_-'
  26. * `--|o` 'o|--'
  27. * \ ` /
  28. * ): :(
  29. * :o_o:
  30. * "-"
  31. *
  32. * SPDX-License-Identifier: GPL-3.0+
  33. * License-Filename: LICENSE
  34. */
  35. /*
  36. * the dp*.c files are about DotParsing
  37. * and dpif.c is the interface to the rest of the program
  38. */
  39. #include "config.h"
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <time.h>
  44. #include <zlib.h>
  45. #include "splay-tree.h"
  46. #include "main.h"
  47. #include "hier.h"
  48. #include "dp.h"
  49. #include "dpun.h"
  50. #include "dpus.h"
  51. #include "dpif.h"
  52. #include "dpmisc.h"
  53. #include "lex.yy.h"
  54. #include "uniqstr.h"
  55. #include "uniqgraph.h"
  56. #include "dot.tab.h"
  57. #include "dpmem.h"
  58. #include "dphl.h"
  59. /* change \n \r \l \N chars */
  60. static char *dolabel(struct dpnode *node, char *str)
  61. {
  62. char *ret = NULL;
  63. char *res = NULL;
  64. char *res2 = NULL;
  65. char *p = NULL;
  66. char *p2 = NULL;
  67. char *q = NULL;
  68. int len = 0;
  69. int nn = 0;
  70. char *nname = NULL;
  71. if (str == NULL) {
  72. return (NULL);
  73. }
  74. len = strlen(str);
  75. if (len == 0) {
  76. /* fixme todo at "" return " " */
  77. return (" ");
  78. }
  79. if (len < 2) {
  80. return (uniqstr(str));
  81. }
  82. res = (char *)dp_calloc(1, (len + 1));
  83. p = str;
  84. q = res;
  85. while (*p) {
  86. if (*p == '\\') {
  87. if (*(p + 1) == 'n') {
  88. (*q) = '\n';
  89. q++;
  90. p++;
  91. p++;
  92. } else if (*(p + 1) == 'l') {
  93. (*q) = '\n';
  94. q++;
  95. p++;
  96. p++;
  97. } else if (*(p + 1) == 'r') {
  98. (*q) = '\n';
  99. q++;
  100. p++;
  101. p++;
  102. } else if (*(p + 1) == 'N') {
  103. /* first only count number of \N */
  104. nn++;
  105. (*q) = (*p);
  106. p++;
  107. q++;
  108. } else {
  109. (*q) = (*p);
  110. p++;
  111. q++;
  112. }
  113. } else {
  114. /* regular char */
  115. (*q) = (*p);
  116. p++;
  117. q++;
  118. }
  119. }
  120. /* translate \N nn times */
  121. if (nn) {
  122. if (node) {
  123. if (node->name == NULL) {
  124. /* shouldnothappen */
  125. printf("%s(): node %d name is (char *)0 and label is \"%s\"\n", __func__, node->nr, str);
  126. nname = "<nil-node-name>";
  127. } else {
  128. nname = node->name;
  129. }
  130. res2 = (char *)dp_calloc(1, ((len + 1) + (nn * strlen(nname))));
  131. /* substitute \N with node name */
  132. p = res;
  133. q = res2;
  134. while (*p) {
  135. if (*p == '\\') {
  136. if (*(p + 1) == 'N') {
  137. p2 = node->name;
  138. if (yydebug || 0) {
  139. printf("%s(): node name to substitute is \"%s\"\n", __func__, node->name);
  140. }
  141. while ((*p2)) {
  142. (*q) = (*p2);
  143. p2++;
  144. q++;
  145. }
  146. p++;
  147. p++;
  148. } else {
  149. (*q) = (*p);
  150. p++;
  151. q++;
  152. }
  153. } else {
  154. (*q) = (*p);
  155. p++;
  156. q++;
  157. }
  158. }
  159. ret = uniqstr(res2);
  160. res2 = dp_free(res2);
  161. if (res2) {
  162. }
  163. res = dp_free(res);
  164. if (res) {
  165. }
  166. } else {
  167. /* no node. then no node name. */
  168. ret = uniqstr(res);
  169. res = dp_free(res);
  170. if (res) {
  171. }
  172. }
  173. } else {
  174. /* no \N chars replaced */
  175. ret = uniqstr(res);
  176. res = dp_free(res);
  177. if (res) {
  178. }
  179. }
  180. return (ret);
  181. }
  182. /* */
  183. static void prrl(struct gml_rl *info, int prrlind)
  184. {
  185. int i = 0;
  186. if (info == NULL) {
  187. return;
  188. }
  189. for (i = 0; i < prrlind; i++) {
  190. printf(" ");
  191. }
  192. printf("hd=%d dir=%d `%s' `%s' nparts=%d\n", info->hd, info->dir, info->port, info->label, info->nparts);
  193. for (i = 0; i < info->nparts; i++) {
  194. prrlind++;
  195. prrl(info->parts[i], (prrlind + 1));
  196. prrlind--;
  197. }
  198. return;
  199. }
  200. /* copy record label data */
  201. static struct gml_rl *rlcopy(struct dppart *info)
  202. {
  203. struct gml_rl *nrec = NULL;
  204. int i = 0;
  205. if (info == NULL) {
  206. return (NULL);
  207. }
  208. nrec = (struct gml_rl *)dp_calloc(1, sizeof(struct gml_rl));
  209. /* number of sub parts can be 0 */
  210. nrec->hd = info->hd;
  211. nrec->nparts = info->ndpparts;
  212. nrec->dir = info->dir;
  213. nrec->port = uniqstr(info->id);
  214. nrec->label = uniqstr(info->lp);
  215. /* copy sub parts if any */
  216. if (info->ndpparts) {
  217. nrec->parts = (struct gml_rl **)dp_calloc(1, info->ndpparts * sizeof(struct gml_rl *));
  218. for (i = 0; i < info->ndpparts; i++) {
  219. nrec->parts[i] = rlcopy(info->parts[i]);
  220. }
  221. }
  222. return (nrec);
  223. }
  224. /* check number of elements actually */
  225. static void rlcheck(struct gml_rl *info)
  226. {
  227. int i = 0;
  228. int count = 0;
  229. count = 0;
  230. /* null value can happen */
  231. if (info == NULL) {
  232. return;
  233. }
  234. for (i = 0; i < info->nparts; i++) {
  235. if (info->parts[i]) {
  236. count++;
  237. rlcheck(info->parts[i]);
  238. }
  239. }
  240. info->nparts = count;
  241. return;
  242. }
  243. /* add subgraphs */
  244. static void sp_addsg_r(struct dpgraph *sg)
  245. {
  246. struct dpglink *eg = NULL;
  247. struct dpgraph *cursg = NULL;
  248. struct gml_graph *rg = NULL;
  249. struct gml_graph *cg = NULL;
  250. struct gml_glist *gl = NULL;
  251. if (sg == NULL) {
  252. return;
  253. }
  254. eg = sg->dpsubg;
  255. while (eg) {
  256. cursg = eg->sg;
  257. /* recurse into current subgraph */
  258. sp_addsg_r(cursg);
  259. if (cursg) {
  260. /* get graph of rooted-on and current subgraph */
  261. rg = uniqgraph(cursg->rootedon->nr);
  262. cg = uniqgraph(cursg->nr);
  263. if (rg && cg) {
  264. if (yydebug || 0) {
  265. printf
  266. ("%s(): subgraph %d `%s' is rooted on subgraph %d `%s'\n",
  267. __func__, cursg->nr, cursg->graphname, cursg->rootedon->nr, cursg->rootedon->graphname);
  268. }
  269. gl = dp_calloc(1, sizeof(struct gml_glist));
  270. /* set current graph as subgraph */
  271. gl->sg = cg;
  272. /* link the list of subgraphs */
  273. if (rg->subglist == NULL) {
  274. rg->subglist = gl;
  275. rg->subglistend = gl;
  276. } else {
  277. rg->subglistend->next = gl;
  278. rg->subglistend = gl;
  279. }
  280. } else {
  281. /* both rg and cg must be found */
  282. printf("%s(): rg=%p cg=%p shouldnothappen\n", __func__, (void *)rg, (void *)cg);
  283. }
  284. }
  285. eg = eg->next;
  286. }
  287. return;
  288. }
  289. /* create subgraphs */
  290. static void sp_crsg_r(struct dpgraph *sg)
  291. {
  292. struct dpglink *eg = NULL;
  293. struct dpgraph *cursg = NULL;
  294. int ttype = 0;
  295. char *stype = NULL;
  296. if (sg == NULL) {
  297. return;
  298. }
  299. eg = sg->dpsubg;
  300. while (eg) {
  301. cursg = eg->sg;
  302. /* recurse into current subgraph */
  303. sp_crsg_r(cursg);
  304. if (cursg) {
  305. switch (cursg->type) {
  306. case DP_SG_ROOT: /* 0 root graph type */
  307. stype = "root-subgraph";
  308. ttype = SG_ROOT;
  309. break;
  310. case DP_SG_CO: /* 1 compound subgraph {} */
  311. stype = "compound-subgraph";
  312. ttype = SG_COMPOUND;
  313. break;
  314. case DP_SG_NM: /* 2 named subgrph */
  315. stype = "named-subgraph";
  316. ttype = SG_SUBG;
  317. break;
  318. case DP_SG_CL: /* 3 cluster subgraph */
  319. stype = "cluster-subgraph";
  320. ttype = SG_CLUSTER;
  321. break;
  322. case DP_SG_NN: /* 4 no name subgraph */
  323. stype = "unnamed-subgraph";
  324. ttype = SG_SUBG;
  325. break;
  326. default:
  327. /* shouldnothappen */
  328. stype = "unknown";
  329. ttype = 0;
  330. break;
  331. }
  332. if (yydebug || 0) {
  333. printf("%s(): creating subgraph %d `%s' `%s' type %d %s\n",
  334. __func__, cursg->nr, cursg->graphname, cursg->label, ttype, stype);
  335. }
  336. create_sg(cursg->nr, uniqstr(cursg->graphname), uniqstr(cursg->label), ttype);
  337. }
  338. eg = eg->next;
  339. }
  340. return;
  341. }
  342. /* copy 1 html item */
  343. static struct gml_hitem *hlimakecopy(struct item *item, struct dpnode *node)
  344. {
  345. struct gml_hitem *ret = NULL;
  346. ret = dp_calloc(1, sizeof(struct gml_hitem));
  347. ret->text = NULL; /* text to display */
  348. ret->fontname = NULL; /* optional font */
  349. ret->fontsize = (-1); /* optional pointsize */
  350. ret->fontcolor = (-1); /* optional color of text */
  351. ret->ncolor = (-1); /* optional background color from <td> or <table> */
  352. /* set modified text if any */
  353. if (item->atext) {
  354. ret->text = uniqstr(item->atext);
  355. } else {
  356. ret->text = uniqstr(item->text);
  357. }
  358. if (yydebug || 0) {
  359. printf("%s(): copy \"%s\" bgcolor 0x%x\n", __func__, ret->text, item->ncolor);
  360. }
  361. /* set original text */
  362. ret->otext = uniqstr(item->text);
  363. /* set fontname if specified */
  364. if (item->fontname == NULL) {
  365. /* not specified */
  366. if (node->bitflags0.fontnameset) {
  367. ret->fontname = uniqstr(node->fontname);
  368. } else {
  369. /* not specified */
  370. ret->fontname = NULL;
  371. }
  372. } else {
  373. ret->fontname = uniqstr(item->fontname);
  374. }
  375. /* set fontsize if specified */
  376. if (item->fontsize < 0) {
  377. /* not specified */
  378. if (node->bitflags0.fontsizeset) {
  379. ret->fontsize = (int)node->fontsize;
  380. } else {
  381. /* not specified */
  382. ret->fontsize = 0;
  383. }
  384. } else {
  385. ret->fontsize = item->fontsize;
  386. }
  387. /* set fontcolor if specified */
  388. if (item->fontcolor < 0) {
  389. /* not specified */
  390. if (node->bitflags0.fontcolorset) {
  391. ret->fontcolor = node->fontcolor;
  392. } else {
  393. /* not specified default to black font color */
  394. ret->fontcolor = 0;
  395. }
  396. } else {
  397. ret->fontcolor = item->fontcolor;
  398. }
  399. /* set background color */
  400. if (item->ncolor < 0) {
  401. /* not specified */
  402. if (node->bitflags0.fcolorset) {
  403. /* fillcolor of node */
  404. ret->ncolor = node->fcolor;
  405. } else {
  406. /* not specified default white background color */
  407. ret->ncolor = 0x00ffffff;
  408. }
  409. } else {
  410. ret->ncolor = item->ncolor;
  411. }
  412. /* copy bitflags */
  413. if (item->bitflags.at) {
  414. /* set if str has a '&' */
  415. ret->bitflags.at = 1;
  416. }
  417. if (item->bitflags.br) {
  418. /* set if str is a <br/> token */
  419. ret->bitflags.br = 1;
  420. }
  421. if (item->bitflags.img) {
  422. /* set if str is a <img> */
  423. ret->bitflags.img = 1;
  424. }
  425. if (item->bitflags.b) {
  426. /* set if str is <b> bold */
  427. ret->bitflags.b = 1;
  428. }
  429. if (item->bitflags.i) {
  430. /* set if str is <i> italic */
  431. ret->bitflags.i = 1;
  432. }
  433. if (item->bitflags.u) {
  434. /* set if str is <u> underline */
  435. ret->bitflags.u = 1;
  436. }
  437. if (item->bitflags.o) {
  438. /* set if str is <o> overline */
  439. ret->bitflags.o = 1;
  440. }
  441. if (item->bitflags.s) {
  442. /* set if str is <s> strike-through */
  443. ret->bitflags.s = 1;
  444. }
  445. if (item->bitflags.sub) {
  446. /* set if str is <sub> subscript */
  447. ret->bitflags.sub = 1;
  448. }
  449. if (item->bitflags.sup) {
  450. /* set if str is <sup> superscript */
  451. ret->bitflags.sup = 1;
  452. }
  453. if (item->bitflags.hr) {
  454. /* set if str is a <hr> token */
  455. ret->bitflags.hr = 1;
  456. }
  457. if (item->bitflags.vr) {
  458. /* set if str is a <vr> token */
  459. ret->bitflags.vr = 1;
  460. }
  461. if (item->bitflags.table) {
  462. /* set if str is a <table> token */
  463. ret->bitflags.table = 1;
  464. if (item->table) {
  465. /* get the copied <table> */
  466. ret->table = item->table->alt;
  467. if (yydebug || 0) {
  468. printf("%s(): got table %p\n", __func__, (void *)ret->table);
  469. }
  470. } else {
  471. /* shouldnothappen */
  472. printf("%s(): nil table\n", __func__);
  473. }
  474. }
  475. return (ret);
  476. }
  477. /* */
  478. static void hlicopy_pr(struct gml_hl *h, struct dpnode *node)
  479. {
  480. struct gml_hilist *hil = NULL;
  481. struct gml_hitem *ph = NULL;
  482. int i = 1;
  483. if (h == NULL) { /* shouldnothappen */
  484. return;
  485. }
  486. if (node == NULL) { /* shoulnothappen */
  487. return;
  488. }
  489. printf("%s(): items in node \"%s\" \"%s\":\n", __func__, node->name, node->label);
  490. hil = h->il;
  491. while (hil) {
  492. ph = hil->items;
  493. if (ph) {
  494. printf(" item %d \"%s\"\n", i, ph->text);
  495. } else {
  496. printf(" item %d nil string\n", i);
  497. }
  498. i++;
  499. hil = hil->next;
  500. }
  501. printf("%s(): end of items in node \"%s\"\n", __func__, node->name);
  502. return;
  503. }
  504. /* copy html items list */
  505. static struct gml_hl *hlicopy(struct dpnode *node)
  506. {
  507. struct gml_hl *ret = NULL;
  508. struct ilist *il = NULL;
  509. struct gml_hilist *hil = NULL;
  510. struct hlpart *pp = NULL;
  511. if (node == NULL) {
  512. return (NULL);
  513. }
  514. ret = dp_calloc(1, sizeof(struct gml_hl));
  515. ret->mode = 0;
  516. pp = node->hlinfo;
  517. if (pp == NULL) {
  518. /* shouldnothappen */
  519. printf("%s(): nil hlinfo for node \"%s\"\n", __func__, node->name);
  520. return (ret);
  521. }
  522. il = pp->il;
  523. while (il) {
  524. if (il->items == NULL) {
  525. /* shouldnothappen */
  526. printf("%s(): nil item in node \"%s\" \"%s\"\n", __func__, node->name, node->label);
  527. } else {
  528. hil = dp_calloc(1, sizeof(struct gml_hilist));
  529. /* create copy of html item */
  530. hil->items = hlimakecopy(il->items, node);
  531. /* link in */
  532. if (ret->il == NULL) {
  533. ret->il = hil;
  534. ret->ilend = hil;
  535. } else {
  536. ret->ilend->next = hil;
  537. ret->ilend = hil;
  538. }
  539. }
  540. il = il->next;
  541. }
  542. /* print the item data */
  543. if (yydebug || 0) {
  544. hlicopy_pr(ret, node);
  545. }
  546. return (ret);
  547. }
  548. /* zzz */
  549. /* copy html tables list */
  550. static struct gml_htlist *hltcopy_r(struct tlist *tl, struct gml_htlist *htl, struct dpnode *node)
  551. {
  552. struct trlist *trptr = NULL;
  553. struct tlist *tlptr = NULL; /* list of table items */
  554. struct tdldata *tdptr = NULL; /* td items in tr */
  555. struct ilist *ilptr = NULL;
  556. struct gml_titem *tinew = NULL;
  557. struct gml_htlist *tlnew = NULL; /* list of sub table items */
  558. struct gml_tritemlist *tritemlistnew = NULL;
  559. struct gml_tritem *tritemnew = NULL;
  560. struct gml_tditem *tditemnew = NULL;
  561. struct gml_hilist *hilistnew = NULL;
  562. int numtr = 0;
  563. int numtd = 0;
  564. if (htl == NULL) {
  565. return (NULL);
  566. }
  567. if (tl->titem == NULL) {
  568. return (NULL);
  569. }
  570. if (tl->titem->tabdata == NULL) {
  571. return (NULL);
  572. }
  573. /* new gml table data */
  574. tinew = dp_calloc(1, sizeof(struct gml_titem));
  575. /* set the alt tbel in dp table data */
  576. tl->titem->tabdata->alt = tinew;
  577. htl->titem = tinew;
  578. /* first copy sub tables if any */
  579. if (tl->titem->tabdata->tl) {
  580. tlptr = tl->titem->tabdata->tl;
  581. while (tlptr) {
  582. /* */
  583. tlnew = (struct gml_htlist *)dp_calloc(1, sizeof(struct gml_htlist));
  584. tlnew = hltcopy_r(tlptr, tlnew, node);
  585. if (tlnew == NULL) { /* shouldnothappen */
  586. return (NULL);
  587. }
  588. if (tlnew->titem) {
  589. /* */
  590. if (htl->titem->tl == NULL) {
  591. htl->titem->tl = tlnew;
  592. htl->titem->tlend = tlnew;
  593. } else {
  594. htl->titem->tlend->next = tlnew;
  595. htl->titem->tlend = tlnew;
  596. }
  597. }
  598. tlptr = tlptr->next;
  599. }
  600. }
  601. /* copy the <tr> data if any */
  602. if (tl->titem->tabdata->tr) {
  603. numtr = 0;
  604. trptr = tl->titem->tabdata->tr;
  605. while (trptr) {
  606. tritemlistnew = dp_calloc(1, sizeof(struct gml_tritemlist));
  607. /* if there are <tr> items */
  608. if (trptr->tritem) {
  609. /* are there <td> in <tr> */
  610. if (trptr->tritem->td) {
  611. tritemnew = dp_calloc(1, sizeof(struct gml_tritem));
  612. tritemlistnew->tritem = tritemnew;
  613. /* set if <tr> has a <td> with a <table> */
  614. tritemnew->hastab = trptr->tritem->hastab;
  615. numtd = 0;
  616. tdptr = trptr->tritem->td;
  617. while (tdptr) {
  618. /* if actual <td> data */
  619. if (tdptr->tdd) {
  620. /* a <td> can have no items as in <td></td> then do not copy data */
  621. /* il list in <td> */
  622. if (tdptr->tdd->il) {
  623. tditemnew = dp_calloc(1, sizeof(struct gml_tditem));
  624. /* set if <td> is a <table> */
  625. tditemnew->istab = tdptr->tdd->istab;
  626. /* copy the il data */
  627. ilptr = tdptr->tdd->il;
  628. while (ilptr) {
  629. hilistnew = dp_calloc(1, sizeof(struct gml_hilist));
  630. hilistnew->items = hlimakecopy(ilptr->items, node);
  631. if (yydebug || 0) {
  632. printf("%s(): copy item \"%s\" bgcolor 0x%x\n",
  633. __func__, ilptr->items->text, ilptr->items->ncolor);
  634. }
  635. /* set which <table> this item is part of */
  636. hilistnew->items->rootedon = tinew;
  637. if (tditemnew->il == NULL) {
  638. tditemnew->il = hilistnew;
  639. tditemnew->ilend = hilistnew;
  640. } else {
  641. tditemnew->ilend->next = hilistnew;
  642. tditemnew->ilend = hilistnew;
  643. }
  644. ilptr = ilptr->next;
  645. }
  646. /* */
  647. /* set <table> of this <td> */
  648. tditemnew->rootedon = tinew;
  649. /* set data from input */
  650. tditemnew->bgcolor = tdptr->tdd->bgcolor; /* ="colorname" */
  651. tditemnew->border = tdptr->tdd->border; /* ="int-value" */
  652. tditemnew->cellpadding = tdptr->tdd->cellpadding; /* ="int-value" */
  653. tditemnew->cellspacing = tdptr->tdd->cellspacing; /* ="int-value" */
  654. tditemnew->color = tdptr->tdd->color; /* ="colorname" */
  655. tditemnew->colspan = tdptr->tdd->colspan; /* ="int-value" */
  656. tditemnew->height = tdptr->tdd->height; /* ="int-value" */
  657. tditemnew->rowspan = tdptr->tdd->rowspan; /* ="int-value" */
  658. tditemnew->width = tdptr->tdd->width; /* ="int-value" */
  659. /* */
  660. if (tritemnew->tdi == NULL) {
  661. tritemnew->tdi = tditemnew;
  662. tritemnew->tdiend = tditemnew;
  663. } else {
  664. tritemnew->tdiend->next = tditemnew;
  665. tritemnew->tdiend = tditemnew;
  666. }
  667. /* */
  668. numtd++;
  669. }
  670. }
  671. /* */
  672. tdptr = tdptr->next;
  673. }
  674. /* */
  675. if (yydebug || 0) {
  676. printf("%s(): %d <td> in <tr>\n", __func__, numtd);
  677. }
  678. /* set number of <td> in this <tr> */
  679. tritemnew->numtd = numtd;
  680. /* set <table> of this <tr> */
  681. tritemnew->rootedon = tinew;
  682. /* */
  683. }
  684. }
  685. /* */
  686. if (htl->titem->tr == NULL) {
  687. htl->titem->tr = tritemlistnew;
  688. htl->titem->trend = tritemlistnew;
  689. } else {
  690. htl->titem->trend->next = tritemlistnew;
  691. htl->titem->trend = tritemlistnew;
  692. }
  693. /* */
  694. numtr++; /* update count of <tr> in this <table> */
  695. trptr = trptr->next;
  696. }
  697. htl->titem->numtr = numtr;
  698. }
  699. /* copy input parms from <table> */
  700. htl->titem->bgcolor = tl->titem->tabdata->bgcolor; /* background color */
  701. htl->titem->color = tl->titem->tabdata->color; /* fontcolor */
  702. htl->titem->cellborder = tl->titem->tabdata->cellborder; /* ="int-value" */
  703. htl->titem->cellpadding = tl->titem->tabdata->cellpadding; /* ="int-value" */
  704. htl->titem->cellspacing = tl->titem->tabdata->cellspacing; /* ="int-value" */
  705. htl->titem->height = tl->titem->tabdata->height; /* ="int-value" */
  706. htl->titem->width = tl->titem->tabdata->width; /* ="int-value" */
  707. return (htl);
  708. }
  709. /* copy html tables list */
  710. static struct gml_hl *hltcopy(struct dpnode *node)
  711. {
  712. struct gml_hl *ret = NULL;
  713. struct tlist *tl = NULL; /* list of table items */
  714. struct gml_htlist *tlnew = NULL; /* list of sub table items */
  715. struct gml_htlist *tlnew2 = NULL; /* list of sub table items */
  716. if (node->hlinfo == NULL) {
  717. /* shouldnothappen */
  718. return (NULL);
  719. }
  720. if (node->hlinfo->tl == NULL) {
  721. /* shouldnothappen */
  722. return (NULL);
  723. }
  724. ret = dp_calloc(1, sizeof(struct gml_hl));
  725. /* this is table data */
  726. ret->mode = 1;
  727. /* scan the tables */
  728. tl = node->hlinfo->tl;
  729. if (yydebug || 0) {
  730. printf("%s(): node \"%s\" node->hlinfo=%p node->hlinfo->tl=%p\n", __func__, node->name, (void *)node->hlinfo, (void *)tl);
  731. }
  732. while (tl) {
  733. tlnew = dp_calloc(1, sizeof(struct gml_htlist));
  734. tlnew2 = hltcopy_r(tl, tlnew, node);
  735. if (tlnew2) {
  736. if (ret->tl == NULL) {
  737. ret->tl = tlnew2;
  738. ret->tlend = tlnew2;
  739. } else {
  740. ret->tlend->next = tlnew2;
  741. ret->tlend = tlnew2;
  742. }
  743. } else {
  744. /* shouldnothappen */
  745. tlnew = dp_free(tlnew);
  746. if (tlnew) {
  747. }
  748. }
  749. tl = tl->next;
  750. }
  751. return (ret);
  752. }
  753. /* */
  754. static void dpif_pr_out_sp(int ind)
  755. {
  756. int i = 0;
  757. for (i = 0; i < ind; i++) {
  758. printf(" ");
  759. }
  760. return;
  761. }
  762. /* */
  763. static void dpif_pr_out_t_r(struct gml_htlist *tl, int ind, int tabnum)
  764. {
  765. struct gml_htlist *tlptr = NULL; /* list of table items */
  766. struct gml_htlist *tlptrnext = NULL; /* list of table items */
  767. int nts = 0;
  768. if (tl == NULL) {
  769. /* shouldnothappen */
  770. return;
  771. }
  772. nts = tabnum;
  773. dpif_pr_out_sp(ind);
  774. printf("<table>[%d]\n", tabnum);
  775. if (tl->titem == NULL) {
  776. printf("%s(): tl->titem is nil\n", __func__);
  777. /* shouldnothappen */
  778. return;
  779. }
  780. if (0) {
  781. printf("%s(): tl->titem->tl=%p\n", __func__, (void *)tl->titem->tl);
  782. }
  783. /* sub tables if any */
  784. if (tl->titem->tl) {
  785. tlptr = tl->titem->tl;
  786. while (tlptr) {
  787. tlptrnext = tlptr->next;
  788. dpif_pr_out_t_r(tlptr, (ind + 2), nts);
  789. nts++;
  790. tlptr = tlptrnext;
  791. }
  792. }
  793. /* <tr> data if any */
  794. if (tl->titem->tr) {
  795. dpif_pr_out_sp(ind);
  796. printf("has %d <tr>\n", tl->titem->numtr);
  797. }
  798. return;
  799. }
  800. /* print list data if any */
  801. static void dpif_pr_out_tl(struct gml_hl *hl, struct dpnode *node)
  802. {
  803. struct gml_htlist *tlptr; /* list of table items */
  804. struct gml_htlist *tlptrnext; /* list of table items */
  805. printf("%s(): copied table data of node\"%s\" with hl=%p\n", __func__, node->name, (void *)hl);
  806. if (hl == NULL) {
  807. return;
  808. }
  809. if (hl->tl == NULL) {
  810. printf("%s(): html table data is nil at node \"%s\"\n", __func__, node->name);
  811. return;
  812. }
  813. tlptr = hl->tl;
  814. while (tlptr) {
  815. tlptrnext = tlptr->next;
  816. dpif_pr_out_t_r(tlptr, 0, 1);
  817. tlptr = tlptrnext;
  818. }
  819. printf("%s(): end copied table data of node\"%s\"\n", __func__, node->name);
  820. return;
  821. }
  822. /* */
  823. static void dpif_pr_in_sp(int ind)
  824. {
  825. int i = 0;
  826. for (i = 0; i < ind; i++) {
  827. printf(" ");
  828. }
  829. return;
  830. }
  831. /* */
  832. static void dpif_pr_in_1il(struct ilist *ildata, int ind, int tinum)
  833. {
  834. char *iltext = NULL;
  835. if (ildata == NULL) {
  836. return;
  837. }
  838. dpif_pr_in_sp(ind);
  839. printf("<item>[%d]\n", tinum);
  840. if (ildata->items == NULL) {
  841. printf("%s(): ildata->items is nil\n", __func__);
  842. return;
  843. }
  844. if (ildata->items->text == NULL) {
  845. if (ildata->items->bitflags.br) {
  846. /* set if str is a <br/> token */
  847. iltext = "<br/>";
  848. } else if (ildata->items->bitflags.img) {
  849. /* set if str is a <img> */
  850. iltext = "<img>";
  851. } else if (ildata->items->bitflags.i) {
  852. /* set if str is <i> italic */
  853. iltext = "<i>";
  854. } else if (ildata->items->bitflags.u) {
  855. /* set if str is <u> underline */
  856. iltext = "<u>";
  857. } else if (ildata->items->bitflags.o) {
  858. /* set if str is <o> overline */
  859. iltext = "<o>";
  860. } else if (ildata->items->bitflags.s) {
  861. /* set if str is <s> strike-through */
  862. iltext = "<s>";
  863. } else if (ildata->items->bitflags.sub) {
  864. /* set if str is <sub> subscript */
  865. iltext = "<sub>";
  866. } else if (ildata->items->bitflags.sup) {
  867. /* set if str is <sup> superscript */
  868. iltext = "<sump>";
  869. } else if (ildata->items->bitflags.hr) {
  870. /* set if str is a <hr> token */
  871. iltext = "<hr>";
  872. } else if (ildata->items->bitflags.vr) {
  873. /* set if str is a <vr> token */
  874. iltext = "<vr>";
  875. } else if (ildata->items->bitflags.b) {
  876. /* set if str is <b> bold */
  877. iltext = "<b>";
  878. } else if (ildata->items->bitflags.table) {
  879. /* set if str is <table> */
  880. iltext = "<table>";
  881. } else {
  882. iltext = "unknown ildata->items->bitflags";
  883. }
  884. } else {
  885. iltext = ildata->items->text;
  886. }
  887. dpif_pr_in_sp(ind + 2);
  888. printf("\"%s\"\n", iltext);
  889. return;
  890. }
  891. /* free ilist */
  892. static void dpif_pr_in_il(struct tdldata *td, int ind, int tdnum)
  893. {
  894. struct ilist *ilptr = NULL; /* text items in td or 0 */
  895. struct ilist *ilptrnext = NULL; /* text items in td or 0 */
  896. int nti = 0;
  897. if (td == NULL) {
  898. return;
  899. }
  900. dpif_pr_in_sp(ind);
  901. printf("<td>[%d]\n", tdnum);
  902. if (td->tdd == NULL) {
  903. printf("%s(): td->tdd is nil\n", __func__);
  904. return;
  905. }
  906. if (td->tdd->il == NULL) {
  907. printf("%s(): td->tdd->il is nil\n", __func__);
  908. }
  909. nti++;
  910. ilptr = td->tdd->il;
  911. while (ilptr) {
  912. ilptrnext = ilptr->next;
  913. /* print 1 il */
  914. dpif_pr_in_1il(ilptr, (ind + 2), nti);
  915. ilptr = ilptrnext;
  916. }
  917. return;
  918. }
  919. /* free <tr> */
  920. static void dpif_pr_in_tr(struct trlist *tr, int ind, int trnum)
  921. {
  922. struct tdldata *tdlptr = NULL; /* td items in tr */
  923. struct tdldata *tdlptrnext = NULL;
  924. int ntd = 0;
  925. if (tr == NULL) {
  926. return;
  927. }
  928. dpif_pr_in_sp(ind);
  929. printf("<tr>[%d]\n", trnum);
  930. if (tr->tritem == NULL) {
  931. printf("%s(): tr->tritem is nil\n", __func__);
  932. return;
  933. }
  934. if (tr->tritem->td == NULL) {
  935. printf("%s(): tr->tritem->td is nil\n", __func__);
  936. return;
  937. }
  938. ntd++;
  939. /* <td> data */
  940. tdlptr = tr->tritem->td;
  941. while (tdlptr) {
  942. tdlptrnext = tdlptr->next;
  943. dpif_pr_in_il(tdlptr, (ind + 2), ntd);
  944. ntd++;
  945. tdlptr = tdlptrnext;
  946. }
  947. return;
  948. }
  949. /* */
  950. static void dpif_pr_in_t_r(struct tlist *tl, int ind, int tabnum)
  951. {
  952. struct tlist *tlptr = NULL; /* list of table items */
  953. struct tlist *tlptrnext = NULL; /* list of table items */
  954. struct trlist *trptr = NULL; /* tr items */
  955. struct trlist *trptrnext = NULL; /* end tr items */
  956. int ntr = 0;
  957. int nts = 0;
  958. if (tl == NULL) {
  959. /* shouldnothappen */
  960. return;
  961. }
  962. nts = tabnum;
  963. dpif_pr_in_sp(ind);
  964. printf("<table>[%d]\n", tabnum);
  965. if (tl->titem == NULL) {
  966. printf("%s(): tl->titem is nil\n", __func__);
  967. /* shouldnothappen */
  968. return;
  969. }
  970. if (tl->titem->tabdata == NULL) {
  971. printf("%s(): tl->titem->tabdata is nil\n", __func__);
  972. return;
  973. }
  974. /* sub tables if any */
  975. if (tl->titem->tabdata->tl) {
  976. tlptr = tl->titem->tabdata->tl;
  977. while (tlptr) {
  978. tlptrnext = tlptr->next;
  979. dpif_pr_in_t_r(tlptr, (ind + 2), nts);
  980. nts++;
  981. tlptr = tlptrnext;
  982. }
  983. }
  984. /* <tr> data */
  985. if (tl->titem->tabdata->tr == NULL) {
  986. printf("%s(): tl->titem->tabdata->tr is nil\n", __func__);
  987. return;
  988. }
  989. ntr++;
  990. trptr = tl->titem->tabdata->tr;
  991. while (trptr) {
  992. trptrnext = trptr->next;
  993. dpif_pr_in_tr(trptr, (ind + 2), ntr);
  994. ntr++;
  995. trptr = trptrnext;
  996. }
  997. return;
  998. }
  999. /* print list data if any */
  1000. static void dpif_pr_in_tl(struct dpnode *node)
  1001. {
  1002. struct tlist *tlptr; /* list of table items */
  1003. struct tlist *tlptrnext; /* list of table items */
  1004. if (node->hlinfo == NULL) {
  1005. return;
  1006. }
  1007. if (node->hlinfo->tl == NULL) {
  1008. printf("%s(): input html table data is nil at node \"%s\"\n", __func__, node->name);
  1009. return;
  1010. }
  1011. printf("%s(): input html table data from node \"%s\" is:\n", __func__, node->name);
  1012. tlptr = node->hlinfo->tl;
  1013. while (tlptr) {
  1014. tlptrnext = tlptr->next;
  1015. dpif_pr_in_t_r(tlptr, 0, 1);
  1016. tlptr = tlptrnext;
  1017. }
  1018. printf("%s(): input html table data end from node \"%s\"\n", __func__, node->name);
  1019. return;
  1020. }
  1021. /* return node name with rand() chars */
  1022. static char *dp_randnname(void)
  1023. {
  1024. char *ret = NULL;
  1025. char buf[9];
  1026. int i = 0;
  1027. int count = 0;
  1028. int rn = 0;
  1029. struct dpnode *n = NULL;
  1030. for (count = 0; count < 10; count++) {
  1031. memset(buf, 0, 9);
  1032. for (i = 0; i < 8; i++) {
  1033. rn = (rand() & 0x07);
  1034. if (rand() & 0x01) {
  1035. buf[i] = ('a' + rn);
  1036. } else {
  1037. buf[i] = ('0' + rn);
  1038. }
  1039. }
  1040. n = dpuniqnode(buf);
  1041. if (n == NULL) {
  1042. break;
  1043. }
  1044. }
  1045. if (n) {
  1046. return (NULL);
  1047. }
  1048. ret = dp_uniqstr(buf);
  1049. return (ret);
  1050. }
  1051. /* parse dot file, 0 return if oke. */
  1052. int dotparse(struct gml_graph *g, gzFile f, char *fname, char *argv0)
  1053. {
  1054. struct dpnlink *nss = NULL;
  1055. struct dpnode *node = NULL;
  1056. struct dpelink *es = NULL;
  1057. struct dpedge *edge = NULL;
  1058. struct gml_rl *rl = NULL;
  1059. struct gml_hl *hl = NULL;
  1060. struct gml_graph *ro = NULL;
  1061. int foundsource = 0;
  1062. int foundtarget = 0;
  1063. int foundid = 0;
  1064. char *nodelabel = NULL;
  1065. char *nodename = NULL;
  1066. int ncolor = 0;
  1067. int nbcolor = 0;
  1068. char *elabel = NULL;
  1069. int econstraint = 0;
  1070. int status = 0;
  1071. int ecolor = 0;
  1072. int style = 0;
  1073. int bgcolor = 0x00ffffff; /* default white node background */
  1074. int fontcolor = 0; /* default black text color */
  1075. char *fc = NULL;
  1076. char *tc = NULL;
  1077. int nr = 0;
  1078. int ishtml = 0;
  1079. int nodehasrootname = 0;
  1080. if (g) {
  1081. }
  1082. if (fname) {
  1083. }
  1084. yydebug = 0;
  1085. /* optional turn on debug */
  1086. if (argv0) {
  1087. if (strcmp(argv0, "gml4gtkd") == 0) {
  1088. yydebug = 1;
  1089. }
  1090. }
  1091. /* static buffer for parser error message */
  1092. memset(parsermessage, 0, 256);
  1093. memset(dp_errmsg, 0, 256);
  1094. dp_lex_init(f, yydebug);
  1095. /* run bison */
  1096. status = yyparse();
  1097. if (yydebug || 0) {
  1098. printf("%s(): status %d `%s' for dot file `%s'\n", __func__, status, dp_errmsg, fname);
  1099. fflush(stdout);
  1100. }
  1101. dp_lex_deinit();
  1102. if (strlen(dp_errmsg)) {
  1103. strncpy(parsermessage, dp_errmsg, (256 - 1));
  1104. /* set error status */
  1105. status = 1;
  1106. dp_clearall();
  1107. fflush(stdout);
  1108. fflush(stderr);
  1109. return (status);
  1110. }
  1111. /* check data parsed and handle record labels */
  1112. status = dp_datachk();
  1113. if (status) {
  1114. strncpy(parsermessage, dp_errmsg, (256 - 1));
  1115. /* set error status */
  1116. status = 1;
  1117. dp_clearall();
  1118. fflush(stdout);
  1119. fflush(stderr);
  1120. return (status);
  1121. }
  1122. /* create copy of subgraphs */
  1123. sp_crsg_r(dp_groot);
  1124. /* add subgraphs to root graph */
  1125. sp_addsg_r(dp_groot);
  1126. /* list with all nodes */
  1127. nss = dp_anodes;
  1128. while (nss) {
  1129. /* get node data */
  1130. node = nss->n;
  1131. /* graph where node is located */
  1132. ro = uniqgraph(nss->n->root->nr);
  1133. /* count how many nodes have a subgraph with actual name */
  1134. if (ro->label) {
  1135. if (strlen(ro->label)) {
  1136. nodehasrootname++;
  1137. }
  1138. }
  1139. /* node number as in gml graph
  1140. * node->nr;
  1141. * using -1 does not apply the gml id check
  1142. */
  1143. foundid = (-1);
  1144. nodename = node->name;
  1145. /* check if html label */
  1146. if (nss->n->htmllabel) {
  1147. ishtml = 1;
  1148. } else {
  1149. ishtml = 0;
  1150. /* translate \n \r \l \N chars */
  1151. nodelabel = dolabel(nss->n, nss->n->label);
  1152. }
  1153. /* node fill color white and bordercolor black */
  1154. ncolor = 0x00ffffff;
  1155. nbcolor = 0;
  1156. fontcolor = 0;
  1157. /* color for text label */
  1158. if (node->bitflags0.fontcolorset) {
  1159. fontcolor = node->fontcolor;
  1160. }
  1161. if (node->bitflags0.fcolorset || node->bitflags0.colorset) {
  1162. if (node->bitflags1.filled) {
  1163. /* style is filled */
  1164. if (node->bitflags0.fcolorset && node->bitflags0.colorset) {
  1165. ncolor = node->fcolor;
  1166. nbcolor = node->color;
  1167. } else if (node->bitflags0.fcolorset && node->bitflags0.colorset == 0) {
  1168. ncolor = node->fcolor;
  1169. nbcolor = 0;
  1170. } else if (node->bitflags0.fcolorset == 0 && node->bitflags0.colorset) {
  1171. ncolor = node->color;
  1172. nbcolor = node->color;
  1173. } else {
  1174. ncolor = 0x00a9a9a9;
  1175. nbcolor = 0;
  1176. }
  1177. } else {
  1178. /* not style is filled */
  1179. if (node->bitflags0.fcolorset && node->bitflags0.colorset) {
  1180. ncolor = 0x00ffffff;
  1181. nbcolor = node->color;
  1182. } else if (node->bitflags0.fcolorset && node->bitflags0.colorset == 0) {
  1183. ncolor = 0x00ffffff;
  1184. nbcolor = 0;
  1185. } else if (node->bitflags0.fcolorset == 0 && node->bitflags0.colorset) {
  1186. ncolor = 0x00ffffff;
  1187. nbcolor = node->color;
  1188. } else {
  1189. ncolor = 0x00ffffff;
  1190. nbcolor = 0;
  1191. }
  1192. }
  1193. } else {
  1194. /* no colors specified, but style=filled, then grey node */
  1195. if (node->bitflags1.filled) {
  1196. ncolor = 0x00a9a9a9;
  1197. nbcolor = 0;
  1198. }
  1199. }
  1200. /* record or html data */
  1201. rl = NULL;
  1202. hl = NULL;
  1203. /* this is a html label */
  1204. if (ishtml == 1 && nss->n->hlinfo == NULL) {
  1205. /* shouldnothappen */
  1206. printf("%s(): ishtml is 1 but ns->n->hlinfo=%p for node \"%s\"\n", __func__, (void *)nss->n->hlinfo, nss->n->name);
  1207. }
  1208. if (nss->n->hlinfo) {
  1209. if (yydebug || 0) {
  1210. printf("%s(): before-copy node \"%s\" mode=%d hlinfo=%p il=%p tl=%p\n", __func__,
  1211. node->name, nss->n->hlinfo->mode, (void *)nss->n->hlinfo,
  1212. (void *)nss->n->hlinfo->il, (void *)nss->n->hlinfo->tl);
  1213. }
  1214. /* this is a html label */
  1215. if (ishtml == 0) {
  1216. /* shouldnothappen */
  1217. printf("%s(): ishtml is 0 but ns->n->hlinfo=%p\n", __func__, (void *)nss->n->hlinfo);
  1218. }
  1219. /* create copy of html items or tables */
  1220. if (nss->n->hlinfo->mode == 0) {
  1221. /* html items list */
  1222. hl = hlicopy(nss->n);
  1223. ishtml = 1;
  1224. } else if (nss->n->hlinfo->mode == 1) {
  1225. /* html tables list rooted on basis */
  1226. /* print input html table data */
  1227. if (yydebug || 0) {
  1228. dpif_pr_in_tl(nss->n);
  1229. }
  1230. /* html tables not-yet supported */
  1231. hl = hltcopy(nss->n);
  1232. if (yydebug || 0) {
  1233. dpif_pr_out_tl(hl, nss->n);
  1234. }
  1235. if (nss->n->name == NULL) {
  1236. /* shouldnothappen */
  1237. nss->n->name = uniqstr("nil-node-name");
  1238. }
  1239. } else {
  1240. printf("%s(): wrong html mode %d for node \"%s\"\n", __func__, nss->n->hlinfo->mode, nss->n->name);
  1241. }
  1242. } else if (nss->n->labelinfo) {
  1243. /* this is a record label */
  1244. if (nss->n->shape == DPSHAPE_RECORD || nss->n->shape == DPSHAPE_MRECORD) {
  1245. /* can also be html label */
  1246. if (ishtml) {
  1247. /* todo copy html info in record hape */
  1248. if (nss->n->labelinfo) {
  1249. }
  1250. printf("%s(): html in record node not yet supported ns->n->labelinfo=%p\n", __func__,
  1251. (void *)nss->n->labelinfo);
  1252. } else {
  1253. if (nss->n->labelinfo) {
  1254. rl = rlcopy(nss->n->labelinfo);
  1255. rlcheck(rl);
  1256. }
  1257. }
  1258. } else {
  1259. /* this is not a record shape */
  1260. if (nss->n->labelinfo) {
  1261. printf("%s(): ns->n->labelinfo=%p should be 0\n", __func__, (void *)nss->n->labelinfo);
  1262. }
  1263. rl = NULL;
  1264. }
  1265. } else {
  1266. /* not html label, not record label, but other label */
  1267. }
  1268. /* print record label data */
  1269. if (yydebug) {
  1270. if (rl) {
  1271. printf("%s(): record label data for node \"%s\" is:\n", __func__, nss->n->name);
  1272. prrl(rl, 0);
  1273. printf("%s(): end of record label data for node \"%s\"\n", __func__, nss->n->name);
  1274. }
  1275. /* if html, print html label */
  1276. }
  1277. /* uniq node number starting at 1 */
  1278. maingraph->nodenum++;
  1279. nr = maingraph->nodenum;
  1280. add_new_node(g, ro, nr, foundid, nodename, nodelabel, ncolor, nbcolor, rl, hl, fontcolor, ishtml);
  1281. /* free dphl data at html label if any */
  1282. if (hl) {
  1283. dphl_freemem();
  1284. }
  1285. /* to next node. */
  1286. nss = nss->next;
  1287. }
  1288. /* all edges */
  1289. es = dp_aedges;
  1290. /* ishtml is set if edge label is a html label
  1291. * todo not implemented yet
  1292. */
  1293. ishtml = 0;
  1294. while (es) {
  1295. edge = es->e;
  1296. /* graph where edge is located */
  1297. ro = uniqgraph(es->e->rootedon->nr);
  1298. if (edge->dir == DP_DIR_BACK) {
  1299. /* backward edge */
  1300. foundsource = edge->tn->nr;
  1301. foundtarget = edge->fn->nr;
  1302. } else {
  1303. /* regular edge */
  1304. foundsource = edge->fn->nr;
  1305. foundtarget = edge->tn->nr;
  1306. }
  1307. /* update in/outdegree of nodes */
  1308. if (edge->dir == DP_DIR_BACK) {
  1309. /* backward edge */
  1310. edge->fn->indegree++;
  1311. edge->tn->outdegree++;
  1312. } else {
  1313. /* regular edge */
  1314. edge->fn->outdegree++;
  1315. edge->tn->indegree++;
  1316. }
  1317. if (edge->bitflags0.constraint) {
  1318. econstraint = 1;
  1319. } else {
  1320. econstraint = 0;
  1321. }
  1322. /* econstraint is normally 1 */
  1323. /* todo html record label support for edge label
  1324. * parse label here in components and copy data
  1325. * add as param in add_new_edge()
  1326. */
  1327. /* transform \n \l \r chars */
  1328. elabel = dolabel(NULL, edge->label);
  1329. /* check if html <> string */
  1330. if (elabel) {
  1331. if (strlen(elabel)) {
  1332. /* todo edge html labels */
  1333. elabel = uniqstr(elabel);
  1334. } else {
  1335. /* edgelabel "" is same as no-edge-label */
  1336. elabel = NULL;
  1337. }
  1338. }
  1339. /* at self-edge the edge color is put in the node ecolor
  1340. * if(edge->fn==edge->tn) this is a self-edge
  1341. */
  1342. ecolor = edge->ecolor;
  1343. /* edge line style */
  1344. style = edge->style;
  1345. fc = uniqstr(edge->fcompass);
  1346. tc = uniqstr(edge->tcompass);
  1347. /* in hier.c copy to the layouter */
  1348. add_new_edge(g, ro, foundsource, foundtarget, elabel, ecolor, style, fc, tc, econstraint, ishtml);
  1349. es = es->next;
  1350. }
  1351. /* todo this is a way to add graph name but should be different */
  1352. if (1) {
  1353. /* add artificial node for starter nodes when the rooted
  1354. * subgraph cluster has a label and add edge to startnode.
  1355. * this is needed for gcc rtl/tree/ipa data
  1356. */
  1357. if (nodehasrootname) {
  1358. /* init rand() */
  1359. srand((unsigned int)time(NULL));
  1360. /* list with all nodes */
  1361. nss = dp_anodes;
  1362. while (nss) {
  1363. /* get node data */
  1364. node = nss->n;
  1365. /* check the starter nodes */
  1366. if ((node->indegree == 0) && (node->outdegree != 0)) {
  1367. if (node->root) {
  1368. if (node->root->label) {
  1369. if (strlen(node->root->label)) {
  1370. /* todo html label for subgraph labels */
  1371. if (yydebug || 0) {
  1372. printf
  1373. ("%s(): node \"%s\" is rooted in cluster with label \"%s\" and adding artificial node\n",
  1374. __func__, node->name, node->root->label);
  1375. }
  1376. /* this node is a starter node with cluster label
  1377. * now add artifical node with cluster label
  1378. * add edge from artificial node to this node
  1379. */
  1380. /* graph where node is located */
  1381. ro = uniqgraph(node->root->nr);
  1382. /* node name with rand() chars */
  1383. nodename = dp_randnname();
  1384. if (yydebug || 0) {
  1385. printf
  1386. ("%s(): generating artificial startnode \"%s\" to point to node \"%s\"\n",
  1387. __func__, nodename, node->name);
  1388. }
  1389. /* set cluster label as node label */
  1390. nodelabel = dolabel(NULL, node->root->label);
  1391. /* node fill color white and bordercolor black */
  1392. ncolor = 0x00ffffff;
  1393. nbcolor = 0;
  1394. fontcolor = 0;
  1395. /* record or html data is currently not supported in cluster labels */
  1396. rl = NULL;
  1397. hl = NULL;
  1398. ishtml = 0;
  1399. /* uniq node number starting at 1 */
  1400. maingraph->nodenum++;
  1401. nr = maingraph->nodenum;
  1402. /* node number as in gml graph
  1403. * using -1 does not apply the gml id check.
  1404. */
  1405. foundid = (-1);
  1406. add_new_node(g, ro, nr, foundid, nodename, nodelabel, ncolor, nbcolor, rl, hl, fontcolor, ishtml);
  1407. /* add edge from artifical node to startnode */
  1408. /* regular edge */
  1409. foundsource = maingraph->nodenum;
  1410. foundtarget = node->nr;
  1411. econstraint = 1;
  1412. elabel = NULL;
  1413. ishtml = 0;
  1414. ecolor = 0;
  1415. style = 0;
  1416. fc = NULL;
  1417. tc = NULL;
  1418. /* graph where edge is located */
  1419. ro = uniqgraph(node->root->nr);
  1420. add_new_edge(g, ro, foundsource, foundtarget, elabel, ecolor, style, fc, tc, econstraint, ishtml);
  1421. }
  1422. }
  1423. }
  1424. }
  1425. nss = nss->next;
  1426. }
  1427. }
  1428. } /* if(1) */
  1429. /* background r/g/b of drawing */
  1430. if (dp_groot) {
  1431. bgcolor = dp_groot->bgcolor;
  1432. bgcr = (bgcolor & 0x00ff0000) >> 16;
  1433. bgcg = (bgcolor & 0x0000ff00) >> 8;
  1434. bgcb = (bgcolor & 0x000000ff);
  1435. } else {
  1436. /* white */
  1437. bgcr = 0xff;
  1438. bgcg = 0xff;
  1439. bgcb = 0xff;
  1440. }
  1441. /* */
  1442. dp_clearall();
  1443. fflush(stdout);
  1444. fflush(stderr);
  1445. return (status);
  1446. }
  1447. /* end */