dphl.c 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595
  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. * SPDX-License-Identifier: GPL-3.0+
  18. * License-Filename: LICENSE
  19. */
  20. /* dphl.* is about Dot Parsing Html Labels */
  21. #include "config.h"
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <strings.h>
  26. #include <limits.h>
  27. #include <math.h>
  28. #include <errno.h>
  29. #include "splay-tree.h"
  30. #include "main.h"
  31. #include "dp.h"
  32. #include "dphl.h"
  33. #include "dpmisc.h"
  34. #include "dphlparser.h"
  35. #include "dot.tab.h"
  36. #include "dpus.h"
  37. #include "dpmem.h"
  38. /* max unsigned long value from html "&#nnn;" or "&#xnn;" */
  39. #define UNICODE_MAX 0x10FFFFul
  40. /* resulting parts of html label */
  41. static struct hlpart *hlinf = NULL;
  42. /* data for <table> */
  43. static struct tabledata *curtable = NULL;
  44. /* data for <table> */
  45. static splay_tree tablestack = NULL;
  46. /* data for <td> */
  47. static struct tddata *curtd = NULL;
  48. /* data for <td> */
  49. static splay_tree tdstack = NULL;
  50. /* data for <tr> */
  51. static struct trdata *curtr = NULL;
  52. /* data for <tr> */
  53. static splay_tree trstack = NULL;
  54. /* data for <font> */
  55. static struct fontdata *curfont = NULL;
  56. /* data for <font> */
  57. static struct fontldata *fontlist = NULL;
  58. static struct fontldata *fontlistend = NULL;
  59. /* data for <font> */
  60. static splay_tree fontstack = NULL;
  61. /* data for <br> */
  62. static struct brdata *curbr = NULL;
  63. /* data for <img> */
  64. static struct imgdata *curimg = NULL;
  65. /* data */
  66. static char *curdata = NULL;
  67. /* <s> strike-through */
  68. static int curs = 0;
  69. /* <sup> superscript text */
  70. static int cursup = 0;
  71. /* <sub> subscript text */
  72. static int cursub = 0;
  73. /* <o> overline text */
  74. static int curo = 0;
  75. /* <u> underline text */
  76. static int curu = 0;
  77. /* <b> bold text */
  78. static int curb = 0;
  79. /* <i> italic text */
  80. static int curi = 0;
  81. /* at error clear parsed info data */
  82. static void dphl_clearhlinfo(void);
  83. /* parse html label of one node, return 0 if oke */
  84. int htmlparse(struct dpnode *node)
  85. {
  86. int lexonly = 0;
  87. int i = 0;
  88. int token = 0;
  89. char *p = NULL;
  90. int c = 0;
  91. int status = 0;
  92. /* no parser errors */
  93. memset(dp_errmsg, 0, 256);
  94. /* check for <> to be sure for a good string */
  95. /* use of <> in a <!-- comment --> can cause errors */
  96. p = node->label;
  97. while (*p) {
  98. if (*p == '<') {
  99. c++;
  100. } else if (*p == '>') {
  101. c--;
  102. } else {
  103. /* nop */
  104. }
  105. p++;
  106. }
  107. /* check for mis-match <> */
  108. if (c != 0) {
  109. memset(dp_errmsg, 0, 256);
  110. snprintf(dp_errmsg, (256 - 1), "html %s(): non-matching '<' and '>' in html string\n", __func__);
  111. return (1);
  112. }
  113. /* test mode to only lex () */
  114. if (lexonly) {
  115. html_lex_init(1 /* debug */ , node->label, node->yylineno);
  116. printf("html %s(): lexing string \"%s\"\n", __func__, node->label);
  117. for (i = 0; i < 100; i++) {
  118. token = html_lex();
  119. printf("%s(%d): token %d [%s]\n", __func__, i, token, hlylval.string);
  120. if (token == 0 || token == EOF) {
  121. break;
  122. }
  123. }
  124. html_lex_deinit();
  125. printf("error message is: \"%s\"\n", dp_errmsg);
  126. return (0);
  127. }
  128. /*
  129. * run the parser on the html string
  130. */
  131. /* where to build the data structures */
  132. hlinf = (struct hlpart *)dp_calloc(1, sizeof(struct hlpart));
  133. /* unknown mode yet */
  134. hlinf->mode = 0; /* or (-1); */
  135. html_lex_init(yydebug /* debug */ , node->label, node->yylineno);
  136. status = hlyparse();
  137. /* check for error message */
  138. if (dphl_chk_err()) {
  139. status++;
  140. }
  141. html_lex_deinit();
  142. if (yydebug || 0) {
  143. printf("html %s(): %d status from html parser '%s'\n", __func__, status, dp_errmsg);
  144. }
  145. if (status) {
  146. /* at error clear all data */
  147. dphl_clearhlinfo();
  148. } else {
  149. /* parsed oke and convert parsed data */
  150. /* todo verify() then at error clear all data */
  151. /* set the resulted parsed data as structures */
  152. node->hlinfo = hlinf;
  153. if (yydebug || 0) {
  154. printf("%s(): node %d \"%s\" \"%s\" mode=%d il=%p tl=%p\n", __func__, node->nr, node->name, node->label,
  155. hlinf->mode, (void *)hlinf->il, (void *)hlinf->tl);
  156. }
  157. if (hlinf->mode == 0) {
  158. /* item mode should not have tables data */
  159. if (hlinf->tl) {
  160. printf("%s(): node \"%s\" \"%s\" mode=%d il=%p tl=%p shouldnothappen tl\n", __func__, node->name,
  161. node->label, hlinf->mode, (void *)hlinf->il, (void *)hlinf->tl);
  162. }
  163. } else if (hlinf->mode == 1) {
  164. /* table mode should not have item data */
  165. if (hlinf->il) {
  166. printf("%s(): node \"%s\" \"%s\" mode=%d il=%p tl=%p shouldnothappen il\n", __func__, node->name,
  167. node->label, hlinf->mode, (void *)hlinf->il, (void *)hlinf->tl);
  168. }
  169. } else {
  170. /* hlinf->mode == -1 does happen todo */
  171. printf("%s(): node \"%s\" \"%s\" mode=%d il=%p tl=%p shouldnothappen wrong mode\n", __func__, node->name,
  172. node->label, hlinf->mode, (void *)hlinf->il, (void *)hlinf->tl);
  173. }
  174. }
  175. return (status);
  176. }
  177. /* at error clear parsed info data */
  178. static void dphl_clearhlinfo(void)
  179. {
  180. struct ilist *pil = NULL;
  181. struct ilist *pilnext = NULL;
  182. if (hlinf == NULL) { /* no data */
  183. return;
  184. }
  185. /* item data to free */
  186. if (hlinf->il) {
  187. pil = hlinf->il;
  188. while (pil) {
  189. pilnext = pil->next;
  190. if (pil->items) {
  191. pil->items = (struct item *)dp_free(pil->items);
  192. }
  193. pil = (struct ilist *)dp_free(pil);
  194. if (pil) {
  195. }
  196. pil = pilnext;
  197. }
  198. hlinf->il = NULL;
  199. hlinf->ilend = NULL;
  200. }
  201. /* table data to free */
  202. if (hlinf->tl) {
  203. /* todo */
  204. hlinf->tl = NULL;
  205. hlinf->tlend = NULL;
  206. }
  207. /* final free */
  208. hlinf = (struct hlpart *)dp_free(hlinf);
  209. if (hlinf) {
  210. }
  211. return;
  212. }
  213. /* add data to items */
  214. static struct item *dphl_makeitem(char *str, char *alt, int opt, struct tabledata *newtable)
  215. {
  216. struct item *item = NULL;
  217. char *msg = NULL;
  218. item = (struct item *)dp_calloc(1, sizeof(struct item));
  219. msg = str;
  220. /* preset item */
  221. item->text = str; /* text to display */
  222. item->atext = alt; /* modified text to display */
  223. item->fontname = NULL; /* optional font */
  224. item->fontsize = (-1); /* optional pointsize */
  225. item->fontcolor = (-1); /* optional color of text */
  226. item->ncolor = (-1); /* optional background color from <td> or <table> */
  227. item->table = NULL; /* optional <table> in <td> */
  228. /* the bitflags are all 0 */
  229. /* check if a <br> */
  230. if (opt == 1) {
  231. item->bitflags.br = 1;
  232. }
  233. /* check if a <hr> */
  234. if (opt == 2) {
  235. item->bitflags.hr = 1;
  236. }
  237. /* check if a <vr> */
  238. if (opt == 3) {
  239. item->bitflags.vr = 1;
  240. }
  241. /* check if a <table> */
  242. if (opt == 5) {
  243. item->bitflags.table = 1;
  244. /* this is the <table> in the <td> */
  245. item->table = newtable;
  246. msg = (char *)"<table> in <td>";
  247. }
  248. /* check if str has html chars */
  249. if (alt) {
  250. item->bitflags.at = 1;
  251. }
  252. /* set italic bitflags etc. */
  253. if (curb) {
  254. /* <b> italic */
  255. item->bitflags.b = 1;
  256. }
  257. if (curi) {
  258. /* <i> italic */
  259. item->bitflags.i = 1;
  260. }
  261. if (curo) {
  262. /* <o> overline */
  263. item->bitflags.o = 1;
  264. }
  265. if (curu) {
  266. /* <u> underline */
  267. item->bitflags.u = 1;
  268. }
  269. if (curs) {
  270. /* <s> strike-through */
  271. item->bitflags.s = 1;
  272. }
  273. if (cursub) {
  274. /* <sub> subscript */
  275. item->bitflags.sub = 1;
  276. }
  277. if (cursup) {
  278. /* <sup> superscript */
  279. item->bitflags.sup = 1;
  280. }
  281. if (curimg) {
  282. /* <img> image */
  283. item->bitflags.img = 1;
  284. }
  285. /* add extra optional data in table mode */
  286. if (hlinf->mode) {
  287. /* <table> settings */
  288. if (curtable) {
  289. if (curtable->color < 0) {
  290. /* not specified */
  291. } else {
  292. item->fontcolor = curtable->color;
  293. }
  294. if (curtable->bgcolor < 0) {
  295. /* not specified */
  296. } else {
  297. item->ncolor = curtable->bgcolor;
  298. }
  299. }
  300. /* <td> settings override curtable settings */
  301. if (curtd) {
  302. if (curtd->color < 0) {
  303. /* not specified */
  304. } else {
  305. item->fontcolor = curtd->color;
  306. }
  307. if (curtd->bgcolor < 0) {
  308. /* not specified */
  309. } else {
  310. if (yydebug || 0) {
  311. printf("%s(): setting background color 0x%x for \"%s\"\n", __func__, curtd->bgcolor, msg);
  312. }
  313. item->ncolor = curtd->bgcolor;
  314. }
  315. }
  316. }
  317. /* if there is a optional font */
  318. if (curfont) {
  319. /* fontname */
  320. if (curfont->face == NULL) {
  321. /* not specified */
  322. } else {
  323. item->fontname = curfont->face;
  324. }
  325. /* fontsize */
  326. if (curfont->pointsize < 0) {
  327. /* not specified */
  328. } else {
  329. item->fontsize = curfont->pointsize;
  330. }
  331. /* fontcolor */
  332. if (curfont->color < 0) {
  333. /* not specified */
  334. } else {
  335. item->fontcolor = curfont->color;
  336. }
  337. }
  338. return (item);
  339. }
  340. /* add data to items */
  341. static void dphl_itemitems(char *str, char *alt, int opt)
  342. {
  343. struct ilist *il = NULL;
  344. /* if opt is set it is br=1 */
  345. if (hlinf == NULL) {
  346. /* shouldnohappen */
  347. return;
  348. }
  349. il = (struct ilist *)dp_calloc(1, sizeof(struct ilist));
  350. /* set linkage to data */
  351. il->items = dphl_makeitem(str, alt, opt, NULL);
  352. if (il->items == NULL) {
  353. /* shouldnothappen */
  354. return;
  355. }
  356. /* link the new data field */
  357. if (hlinf->il == NULL) {
  358. hlinf->il = il;
  359. hlinf->ilend = il;
  360. } else {
  361. hlinf->ilend->next = il;
  362. hlinf->ilend = il;
  363. }
  364. return;
  365. }
  366. /* add data to tables */
  367. static void dphl_itemtables(char *str, char *alt, int opt)
  368. {
  369. struct ilist *il = NULL;
  370. /* if opt is set it is br=1, hr=2, vr=3, img=4 */
  371. if (hlinf == NULL) {
  372. /* shouldnothappen */
  373. return;
  374. }
  375. if (hlinf->mode == 0) {
  376. /* shouldnothappen */
  377. return;
  378. }
  379. if (curtable == NULL) {
  380. /* shouldnothappen */
  381. printf("%s(): nil curtable\n", __func__);
  382. return;
  383. }
  384. if (curtd == NULL) {
  385. /* shouldnothappen */
  386. printf("%s(): nil curtd\n", __func__);
  387. return;
  388. }
  389. il = (struct ilist *)dp_calloc(1, sizeof(struct ilist));
  390. /* set linkage to data */
  391. il->items = dphl_makeitem(str, alt, opt, NULL);
  392. curtd->table = curtable;
  393. if (curtd->il == NULL) {
  394. curtd->il = il;
  395. curtd->ilend = il;
  396. } else {
  397. curtd->ilend->next = il;
  398. curtd->ilend = il;
  399. }
  400. return;
  401. }
  402. /* put char in buffer */
  403. static int dplh_putc_utf8(unsigned long cp, char *buffer)
  404. {
  405. unsigned char *bytes = (unsigned char *)buffer;
  406. if (cp <= 0x007Ful) {
  407. bytes[0] = (unsigned char)cp;
  408. return (1);
  409. }
  410. if (cp <= 0x07FFul) {
  411. bytes[1] = (unsigned char)((2 << 6) | (cp & 0x3F));
  412. bytes[0] = (unsigned char)((6 << 5) | (cp >> 6));
  413. return (2);
  414. }
  415. if (cp <= 0xFFFFul) {
  416. bytes[2] = (unsigned char)((2 << 6) | (cp & 0x3F));
  417. bytes[1] = (unsigned char)((2 << 6) | ((cp >> 6) & 0x3F));
  418. bytes[0] = (unsigned char)((14 << 4) | (cp >> 12));
  419. return (3);
  420. }
  421. if (cp <= 0x10FFFFul) {
  422. bytes[3] = (unsigned char)((2 << 6) | (cp & 0x3F));
  423. bytes[2] = (unsigned char)((2 << 6) | ((cp >> 6) & 0x3F));
  424. bytes[1] = (unsigned char)((2 << 6) | ((cp >> 12) & 0x3F));
  425. bytes[0] = (unsigned char)((30 << 3) | (cp >> 18));
  426. return (4);
  427. }
  428. return (0);
  429. }
  430. /* html chars */
  431. static struct mi {
  432. const char *key;
  433. const char *data;
  434. } entdata[] = {
  435. { "&AElig;", "Æ" },
  436. { "&Aacute;", "Á" },
  437. { "&Acirc;", "Â" },
  438. { "&Agrave;", "À" },
  439. { "&Alpha;", "Α" },
  440. { "&Aring;", "Å" },
  441. { "&Atilde;", "Ã" },
  442. { "&Auml;", "Ä" },
  443. { "&Beta;", "Β" },
  444. { "&Ccedil;", "Ç" },
  445. { "&Chi;", "Χ" },
  446. { "&Dagger;", "‡" },
  447. { "&Delta;", "Δ" },
  448. { "&ETH;", "Ð" },
  449. { "&Eacute;", "É" },
  450. { "&Ecirc;", "Ê" },
  451. { "&Egrave;", "È" },
  452. { "&Epsilon;", "Ε" },
  453. { "&Eta;", "Η" },
  454. { "&Euml;", "Ë" },
  455. { "&Gamma;", "Γ" },
  456. { "&Iacute;", "Í" },
  457. { "&Icirc;", "Î" },
  458. { "&Igrave;", "Ì" },
  459. { "&Iota;", "Ι" },
  460. { "&Iuml;", "Ï" },
  461. { "&Kappa;", "Κ" },
  462. { "&Lambda;", "Λ" },
  463. { "&Mu;", "Μ" },
  464. { "&Ntilde;", "Ñ" },
  465. { "&Nu;", "Ν" },
  466. { "&OElig;", "Œ" },
  467. { "&Oacute;", "Ó" },
  468. { "&Ocirc;", "Ô" },
  469. { "&Ograve;", "Ò" },
  470. { "&Omega;", "Ω" },
  471. { "&Omicron;", "Ο" },
  472. { "&Oslash;", "Ø" },
  473. { "&Otilde;", "Õ" },
  474. { "&Ouml;", "Ö" },
  475. { "&Phi;", "Φ" },
  476. { "&Pi;", "Π" },
  477. { "&Prime;", "″" },
  478. { "&Psi;", "Ψ" },
  479. { "&Rho;", "Ρ" },
  480. { "&Scaron;", "Š" },
  481. { "&Sigma;", "Σ" },
  482. { "&THORN;", "Þ" },
  483. { "&Tau;", "Τ" },
  484. { "&Theta;", "Θ" },
  485. { "&Uacute;", "Ú" },
  486. { "&Ucirc;", "Û" },
  487. { "&Ugrave;", "Ù" },
  488. { "&Upsilon;", "Υ" },
  489. { "&Uuml;", "Ü" },
  490. { "&Xi;", "Ξ" },
  491. { "&Yacute;", "Ý" },
  492. { "&Yuml;", "Ÿ" },
  493. { "&Zeta;", "Ζ" },
  494. { "&aacute;", "á" },
  495. { "&acirc;", "â" },
  496. { "&acute;", "´" },
  497. { "&aelig;", "æ" },
  498. { "&agrave;", "à" },
  499. { "&alefsym;", "ℵ" },
  500. { "&alpha;", "α" },
  501. { "&amp;", "&" },
  502. { "&and;", "∧" },
  503. { "&ang;", "∠" },
  504. { "&apos;", "'" },
  505. { "&aring;", "å" },
  506. { "&asymp;", "≈" },
  507. { "&atilde;", "ã" },
  508. { "&auml;", "ä" },
  509. { "&bdquo;", "„" },
  510. { "&beta;", "β" },
  511. { "&brvbar;", "¦" },
  512. { "&bull;", "•" },
  513. { "&cap;", "∩" },
  514. { "&ccedil;", "ç" },
  515. { "&cedil;", "¸" },
  516. { "&cent;", "¢" },
  517. { "&chi;", "χ" },
  518. { "&circ;", "ˆ" },
  519. { "&clubs;", "♣" },
  520. { "&cong;", "≅" },
  521. { "&copy;", "©" },
  522. { "&crarr;", "↵" },
  523. { "&cup;", "∪" },
  524. { "&curren;", "¤" },
  525. { "&dArr;", "⇓" },
  526. { "&dagger;", "†" },
  527. { "&darr;", "↓" },
  528. { "&deg;", "°" },
  529. { "&delta;", "δ" },
  530. { "&diams;", "♦" },
  531. { "&divide;", "÷" },
  532. { "&eacute;", "é" },
  533. { "&ecirc;", "ê" },
  534. { "&egrave;", "è" },
  535. { "&empty;", "∅" },
  536. { "&emsp;", "\xE2\x80\x83" },
  537. { "&ensp;", "\xE2\x80\x82" },
  538. { "&epsilon;", "ε" },
  539. { "&equiv;", "≡" },
  540. { "&eta;", "η" },
  541. { "&eth;", "ð" },
  542. { "&euml;", "ë" },
  543. { "&euro;", "€" },
  544. { "&exist;", "∃" },
  545. { "&fnof;", "ƒ" },
  546. { "&forall;", "∀" },
  547. { "&frac12;", "½" },
  548. { "&frac14;", "¼" },
  549. { "&frac34;", "¾" },
  550. { "&frasl;", "⁄" },
  551. { "&gamma;", "γ" },
  552. { "&ge;", "≥" },
  553. { "&gt;", ">" },
  554. { "&hArr;", "⇔" },
  555. { "&harr;", "↔" },
  556. { "&hearts;", "♥" },
  557. { "&hellip;", "…" },
  558. { "&iacute;", "í" },
  559. { "&icirc;", "î" },
  560. { "&iexcl;", "¡" },
  561. { "&igrave;", "ì" },
  562. { "&image;", "ℑ" },
  563. { "&infin;", "∞" },
  564. { "&int;", "∫" },
  565. { "&iota;", "ι" },
  566. { "&iquest;", "¿" },
  567. { "&isin;", "∈" },
  568. { "&iuml;", "ï" },
  569. { "&kappa;", "κ" },
  570. { "&lArr;", "⇐" },
  571. { "&lambda;", "λ" },
  572. { "&lang;", "〈" },
  573. { "&laquo;", "«" },
  574. { "&larr;", "←" },
  575. { "&lceil;", "⌈" },
  576. { "&ldquo;", "“" },
  577. { "&le;", "≤" },
  578. { "&lfloor;", "⌊" },
  579. { "&lowast;", "∗" },
  580. { "&loz;", "◊" },
  581. { "&lrm;", "\xE2\x80\x8E" },
  582. { "&lsaquo;", "‹" },
  583. { "&lsquo;", "‘" },
  584. { "&lt;", "<" },
  585. { "&macr;", "¯" },
  586. { "&mdash;", "—" },
  587. { "&micro;", "µ" },
  588. { "&middot;", "·" },
  589. { "&minus;", "−" },
  590. { "&mu;", "μ" },
  591. { "&nabla;", "∇" },
  592. { "&nbsp;", "\xC2\xA0" },
  593. { "&ndash;", "–" },
  594. { "&ne;", "≠" },
  595. { "&ni;", "∋" },
  596. { "&not;", "¬" },
  597. { "&notin;", "∉" },
  598. { "&nsub;", "⊄" },
  599. { "&ntilde;", "ñ" },
  600. { "&nu;", "ν" },
  601. { "&oacute;", "ó" },
  602. { "&ocirc;", "ô" },
  603. { "&oelig;", "œ" },
  604. { "&ograve;", "ò" },
  605. { "&oline;", "‾" },
  606. { "&omega;", "ω" },
  607. { "&omicron;", "ο" },
  608. { "&oplus;", "⊕" },
  609. { "&or;", "∨" },
  610. { "&ordf;", "ª" },
  611. { "&ordm;", "º" },
  612. { "&oslash;", "ø" },
  613. { "&otilde;", "õ" },
  614. { "&otimes;", "⊗" },
  615. { "&ouml;", "ö" },
  616. { "&para;", "¶" },
  617. { "&part;", "∂" },
  618. { "&permil;", "‰" },
  619. { "&perp;", "⊥" },
  620. { "&phi;", "φ" },
  621. { "&pi;", "π" },
  622. { "&piv;", "ϖ" },
  623. { "&plusmn;", "±" },
  624. { "&pound;", "£" },
  625. { "&prime;", "′" },
  626. { "&prod;", "∏" },
  627. { "&prop;", "∝" },
  628. { "&psi;", "ψ" },
  629. { "&quot;", "\"" },
  630. { "&rArr;", "⇒" },
  631. { "&radic;", "√" },
  632. { "&rang;", "〉" },
  633. { "&raquo;", "»" },
  634. { "&rarr;", "→" },
  635. { "&rceil;", "⌉" },
  636. { "&rdquo;", "”" },
  637. { "&real;", "ℜ" },
  638. { "&reg;", "®" },
  639. { "&rfloor;", "⌋" },
  640. { "&rho;", "ρ" },
  641. { "&rlm;", "\xE2\x80\x8F" },
  642. { "&rsaquo;", "›" },
  643. { "&rsquo;", "’" },
  644. { "&sbquo;", "‚" },
  645. { "&scaron;", "š" },
  646. { "&sdot;", "⋅" },
  647. { "&sect;", "§" },
  648. { "&shy;", "\xC2\xAD" },
  649. { "&sigma;", "σ" },
  650. { "&sigmaf;", "ς" },
  651. { "&sim;", "∼" },
  652. { "&spades;", "♠" },
  653. { "&sub;", "⊂" },
  654. { "&sube;", "⊆" },
  655. { "&sum;", "∑" },
  656. { "&sup1;", "¹" },
  657. { "&sup2;", "²" },
  658. { "&sup3;", "³" },
  659. { "&sup;", "⊃" },
  660. { "&supe;", "⊇" },
  661. { "&szlig;", "ß" },
  662. { "&tau;", "τ" },
  663. { "&there4;", "∴" },
  664. { "&theta;", "θ" },
  665. { "&thetasym;", "ϑ" },
  666. { "&thinsp;", "\xE2\x80\x89" },
  667. { "&thorn;", "þ" },
  668. { "&tilde;", "˜" },
  669. { "&times;", "×" },
  670. { "&trade;", "™" },
  671. { "&uArr;", "⇑" },
  672. { "&uacute;", "ú" },
  673. { "&uarr;", "↑" },
  674. { "&ucirc;", "û" },
  675. { "&ugrave;", "ù" },
  676. { "&uml;", "¨" },
  677. { "&upsih;", "ϒ" },
  678. { "&upsilon;", "υ" },
  679. { "&uuml;", "ü" },
  680. { "&weierp;", "℘" },
  681. { "&xi;", "ξ" },
  682. { "&yacute;", "ý" },
  683. { "&yen;", "¥" },
  684. { "&yuml;", "ÿ" },
  685. { "&zeta;", "ζ" },
  686. { "&zwj;", "\xE2\x80\x8D" },
  687. { "&zwnj;", "\xE2\x80\x8C" }
  688. };
  689. /* search compare */
  690. static int entcmp(const void *key, const void *value)
  691. {
  692. struct mi *mi1 = (struct mi *)key;
  693. struct mi *mi2 = (struct mi *)value;
  694. return (strcasecmp(mi1->key, mi2->key));
  695. }
  696. /* translate html chars like "&amp;" into "&" */
  697. static char *dplh_htrans(char *str)
  698. {
  699. struct mi thekey = { NULL, NULL };
  700. char *ret = NULL;
  701. int blen = 0; /* buffer length */
  702. char *buf = NULL; /* output buffer */
  703. char *ebuf = NULL; /* entity buffer */
  704. char *p = NULL;
  705. char *q = NULL;
  706. char *tmpp = NULL;
  707. char *tmpq = NULL;
  708. int nc = 0;
  709. unsigned long cp = 0;
  710. char *tail = NULL;
  711. struct mi *entity = NULL;
  712. int elen = 0;
  713. /* check str */
  714. if (str == NULL) {
  715. return (NULL);
  716. }
  717. if (strlen(str) == 0) {
  718. return (NULL);
  719. }
  720. if (strchr(str, '&') == NULL) {
  721. return (NULL);
  722. }
  723. if (strchr(str, ';') == NULL) {
  724. /* parse error */
  725. memset(dp_errmsg, 0, 256);
  726. snprintf(dp_errmsg, (256 - 1),
  727. "html %s(): missing ';' in `%s' for html char in html string at line %d\n", __func__, str, hllineno);
  728. return (NULL);
  729. }
  730. /* if only "&;" */
  731. if (strlen(str) < 3) {
  732. memset(dp_errmsg, 0, 256);
  733. snprintf(dp_errmsg, (256 - 1),
  734. "html %s(): too short `%s' for html char in html string at line %d\n", __func__, str, hllineno);
  735. return (NULL);
  736. }
  737. /* create buffers for modified string */
  738. blen = strlen(str) + 1;
  739. buf = (char *)dp_calloc(1, blen);
  740. ebuf = (char *)dp_calloc(1, blen);
  741. /* scan str and replace or copy chars */
  742. p = str;
  743. q = buf;
  744. while (*p) {
  745. /* check for start of a html char */
  746. if (*p == '&') {
  747. /* copy to entity buf */
  748. memset(ebuf, 0, blen);
  749. tmpp = p;
  750. tmpq = ebuf;
  751. while (*tmpp) {
  752. /* check for end of entity */
  753. if (*tmpp == ';') {
  754. /* put the final ';' in ebuf */
  755. *tmpq = *tmpp;
  756. break;
  757. } else {
  758. /* copy chars */
  759. *tmpq = *tmpp;
  760. tmpp++;
  761. tmpq++;
  762. }
  763. }
  764. /* check end of str */
  765. if (*tmpp == 0) {
  766. /* parse error */
  767. memset(dp_errmsg, 0, 256);
  768. snprintf(dp_errmsg, (256 - 1),
  769. "html %s(): missing ';' in `%s' for html char in html string at line %d\n", __func__, ebuf, hllineno);
  770. /* stop parsing string */
  771. break;
  772. }
  773. /* check for &; */
  774. if (strlen(ebuf) < 3) {
  775. /* parse error */
  776. memset(dp_errmsg, 0, 256);
  777. snprintf(dp_errmsg, (256 - 1),
  778. "html %s(): empty entity `%s' for html char in html string at line %d\n", __func__, ebuf, hllineno);
  779. /* stop parsing string */
  780. break;
  781. }
  782. /* check if has dec or hex value */
  783. if (strchr(ebuf, '#')) {
  784. errno = 0;
  785. tail = NULL;
  786. /* dec or hex entity with 'x' or 'X' */
  787. if (strchr(ebuf, 'x') || strchr(ebuf, 'X')) {
  788. /* hex entity as "&#x80;" */
  789. cp = strtoul((char *)(ebuf + 3), (char **)(&tail), 16);
  790. } else {
  791. /* decimal entity as "&#160;" */
  792. cp = strtoul((char *)(ebuf + 2), (char **)(&tail), 10);
  793. }
  794. /* check for errors */
  795. if (errno || (*tail != ';') || (cp > UNICODE_MAX)) {
  796. /* parse error */
  797. memset(dp_errmsg, 0, 256);
  798. snprintf(dp_errmsg, (256 - 1),
  799. "html %s(): bad value `%s' for html char in html string at line %d\n", __func__, ebuf, hllineno);
  800. /* stop parsing string */
  801. break;
  802. } else {
  803. /* cp is always a positive number, unsigned but it can be 0 */
  804. if (cp == 0) {
  805. printf
  806. ("html %s(): zero value `%s' for html char terminates early html string at line %d\n",
  807. __func__, ebuf, hllineno);
  808. /* stop parsing string */
  809. break;
  810. }
  811. /* oke */
  812. nc = dplh_putc_utf8(cp, q);
  813. /* a duff device to update q */
  814. /* this fall-thru is intentional but gcc may warn */
  815. /* also gcc does detect these specific comments below to suppress a warning */
  816. switch (nc) {
  817. case 4:
  818. q++;
  819. /* FALLTHRU */
  820. case 3:
  821. q++;
  822. /* FALLTHRU */
  823. case 2:
  824. q++;
  825. /* FALLTHRU */
  826. case 1:
  827. q++;
  828. /* FALLTHRU */
  829. default:
  830. break;
  831. }
  832. }
  833. } else {
  834. /* textual entity as "&amp;" is in ebuf */
  835. thekey.key = ebuf;
  836. entity = (struct mi *)
  837. bsearch(&thekey, entdata, (sizeof(entdata) / sizeof(entdata[0])), sizeof(struct mi), entcmp);
  838. if (entity == NULL) {
  839. /* parse error */
  840. memset(dp_errmsg, 0, 256);
  841. snprintf(dp_errmsg, (256 - 1),
  842. "html %s(): bad value `%s' for html char in html string at line %d\n", __func__, ebuf, hllineno);
  843. /* stop parsing string */
  844. } else {
  845. elen = strlen(entity->data);
  846. /* there is enough room in buf because replacements are shorter */
  847. memcpy(q, entity->data, elen);
  848. q = q + elen;
  849. }
  850. }
  851. /* now skip p past the entity */
  852. while (*p) {
  853. if (*p == ';') {
  854. p++;
  855. break;
  856. }
  857. p++;
  858. }
  859. } else {
  860. /* regular char to copy */
  861. *q = *p;
  862. p++;
  863. q++;
  864. }
  865. }
  866. /* check for error */
  867. if (dphl_chk_err()) {
  868. ret = NULL;
  869. } else {
  870. ret = dp_uniqstr(buf);
  871. }
  872. buf = (char *)dp_free(buf);
  873. if (buf) {
  874. }
  875. ebuf = (char *)dp_free(ebuf);
  876. if (ebuf) {
  877. }
  878. return (ret);
  879. }
  880. /* unknown attribute */
  881. void dphl_attr_huh(char *tag, char *attr, char *value)
  882. {
  883. printf("html %s(): at tag %s unknown attribute %s=\"%s\" skipped in html string at line %d\n", __func__, tag, attr, value,
  884. hllineno);
  885. fflush(stdout);
  886. return;
  887. }
  888. /* check for error message */
  889. int dphl_chk_err(void)
  890. {
  891. int ret = 0;
  892. if (strlen(dp_errmsg)) {
  893. /* there is a error message, fflush std */
  894. fflush(stdout);
  895. fflush(stderr);
  896. ret = 1;
  897. } else {
  898. ret = 0;
  899. }
  900. return (ret);
  901. }
  902. /* return 1 if string is only spaces */
  903. static int dphl_isws(char *str)
  904. {
  905. int ret = 1;
  906. char *p = NULL;
  907. p = str;
  908. while (*p) {
  909. /* keep scanning when spaces */
  910. if (*p == ' ') {
  911. } else if (*p == '\n') {
  912. } else if (*p == '\t') {
  913. } else if (*p == '\r') {
  914. } else if (*p == '\f') {
  915. } else {
  916. ret = 0;
  917. break;
  918. }
  919. p++;
  920. }
  921. return (ret);
  922. }
  923. /* check data before/after <table></table> */
  924. void dphl_tabledata(char *str)
  925. {
  926. /* check if spaces */
  927. if (dphl_isws(str) == 0) {
  928. printf("html %s(): skipped `%s' around <table></table> tag in html string at line %d\n", __func__, str, hllineno);
  929. }
  930. return;
  931. }
  932. /* check align="value"
  933. * for <br> "center|left|right"
  934. * for <table> "center|left|right"
  935. * for <td> "center|left|right|text"
  936. */
  937. int dphl_chk_align(char *str, int mode)
  938. {
  939. int status = 0;
  940. int val = 0;
  941. int err = 0;
  942. if (strcasecmp(str, "center") == 0) {
  943. val = DP_ALIGNC;
  944. } else if (strcasecmp(str, "left") == 0) {
  945. val = DP_ALIGNL;
  946. } else if (strcasecmp(str, "right") == 0) {
  947. val = DP_ALIGNR;
  948. } else {
  949. /* only <td> */
  950. if (mode == T_TD) {
  951. if (strcasecmp(str, "text") == 0) {
  952. val = DP_ALIGNT;
  953. } else {
  954. status = 1;
  955. }
  956. } else {
  957. status = 1;
  958. }
  959. }
  960. /* check error status */
  961. if (status) {
  962. memset(dp_errmsg, 0, 256);
  963. snprintf(dp_errmsg, (256 - 1), "html %s(): unknown value `%s' for align in html string at line %d\n", __func__, str,
  964. hllineno);
  965. return (1);
  966. }
  967. /* value is oke for align */
  968. if (mode == T_TD) {
  969. /* <td> align */
  970. if (curtd->align == -1) {
  971. curtd->align = val;
  972. } else {
  973. err = 1;
  974. }
  975. } else if (mode == T_TABLE) {
  976. /* <table> align */
  977. if (curtable->align == -1) {
  978. curtable->align = val;
  979. } else {
  980. err = 1;
  981. }
  982. } else if (mode == T_BR) {
  983. /* <br> align */
  984. if (curbr->align == -1) {
  985. curbr->align = val;
  986. } else {
  987. err = 1;
  988. }
  989. } else {
  990. /* shouldnothappen */
  991. }
  992. if (err) {
  993. memset(dp_errmsg, 0, 256);
  994. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for align in html string at line %d\n", __func__,
  995. str, hllineno);
  996. return (1);
  997. }
  998. return (0);
  999. }
  1000. /*
  1001. * for <td> "center|left|right"
  1002. */
  1003. int dphl_chk_balign(char *str)
  1004. {
  1005. int status = 0;
  1006. int val = 0;
  1007. if (strcasecmp(str, "center") == 0) {
  1008. val = DP_ALIGNC;
  1009. } else if (strcasecmp(str, "left") == 0) {
  1010. val = DP_ALIGNL;
  1011. } else if (strcasecmp(str, "right") == 0) {
  1012. val = DP_ALIGNR;
  1013. } else {
  1014. status = 1;
  1015. }
  1016. /* check error status */
  1017. if (status) {
  1018. memset(dp_errmsg, 0, 256);
  1019. snprintf(dp_errmsg, (256 - 1), "html %s(): unknown value `%s' for balign in html string at line %d\n", __func__,
  1020. str, hllineno);
  1021. return (1);
  1022. }
  1023. /* value is oke for <td> balign */
  1024. if (curtd->balign == -1) {
  1025. curtd->balign = val;
  1026. } else {
  1027. memset(dp_errmsg, 0, 256);
  1028. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for balign in html string at line %d\n", __func__,
  1029. str, hllineno);
  1030. return (1);
  1031. }
  1032. return (0);
  1033. }
  1034. /* check bgcolor value */
  1035. int dphl_chk_bgcolor(char *str, int mode)
  1036. {
  1037. struct dpcolor *c = NULL;
  1038. int pe = 0;
  1039. int es = 0;
  1040. int il = 0;
  1041. int rgb = 0;
  1042. int err = 0;
  1043. /* get color without colorscheme number */
  1044. c = dp_getcolor(0, 0, str);
  1045. pe = c->pe;
  1046. es = c->es;
  1047. il = c->islist;
  1048. rgb = c->color;
  1049. c = (struct dpcolor *)dp_free((void *)c);
  1050. if (c) {
  1051. }
  1052. if (es) {
  1053. memset(dp_errmsg, 0, 256);
  1054. snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for bgAcolor in html string at line %d\n", __func__,
  1055. str, hllineno);
  1056. return (1);
  1057. }
  1058. if (pe) {
  1059. memset(dp_errmsg, 0, 256);
  1060. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for bgcolor in html string at line %d\n", __func__, str,
  1061. hllineno);
  1062. return (1);
  1063. }
  1064. if (il) {
  1065. memset(dp_errmsg, 0, 256);
  1066. snprintf(dp_errmsg, (256 - 1), "html %s(): color-list value `%s' for bgcolor in html string at line %d\n", __func__,
  1067. str, hllineno);
  1068. return (1);
  1069. }
  1070. if (mode == T_TD) {
  1071. /* <td> bgcolor */
  1072. if (curtd->bgcolor == -1) {
  1073. curtd->bgcolor = rgb;
  1074. } else {
  1075. err = 1;
  1076. }
  1077. } else if (mode == T_TABLE) {
  1078. /* <table> bgcolor */
  1079. if (curtable->bgcolor == -1) {
  1080. curtable->bgcolor = rgb;
  1081. } else {
  1082. err = 1;
  1083. }
  1084. } else {
  1085. /* shouldnothappen */
  1086. }
  1087. if (err) {
  1088. memset(dp_errmsg, 0, 256);
  1089. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for bgcolor in html string at line %d\n", __func__,
  1090. str, hllineno);
  1091. return (1);
  1092. }
  1093. return (0);
  1094. }
  1095. /* check border value */
  1096. int dphl_chk_border(char *str, int mode)
  1097. {
  1098. int n = 0;
  1099. int ival = 0;
  1100. int pe = 0;
  1101. int es = 0;
  1102. int err = 0;
  1103. struct dpinum *num = NULL;
  1104. if (*str == '-') {
  1105. memset(dp_errmsg, 0, 256);
  1106. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for border in html string at line %d\n", __func__,
  1107. str, hllineno);
  1108. return (1);
  1109. }
  1110. num = dp_getinum(str);
  1111. n = num->number;
  1112. pe = num->pe;
  1113. es = num->es;
  1114. num = (struct dpinum *)dp_free((void *)num);
  1115. if (num) {
  1116. }
  1117. if (es) {
  1118. memset(dp_errmsg, 0, 256);
  1119. snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for border in html string at line %d\n", __func__, str,
  1120. hllineno);
  1121. return (1);
  1122. }
  1123. if (pe) {
  1124. memset(dp_errmsg, 0, 256);
  1125. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for border in html string at line %d\n", __func__, str, hllineno);
  1126. return (1);
  1127. }
  1128. ival = n;
  1129. if (ival < 0) {
  1130. memset(dp_errmsg, 0, 256);
  1131. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for border in html string at line %d\n", __func__,
  1132. str, hllineno);
  1133. return (1);
  1134. }
  1135. if (ival > 255) {
  1136. memset(dp_errmsg, 0, 256);
  1137. snprintf(dp_errmsg, (256 - 1), "html %s(): too high value `%s' for border (max is 255) in html string at line %d\n",
  1138. __func__, str, hllineno);
  1139. return (1);
  1140. }
  1141. /* ival is the size */
  1142. /* size 0 is allowed */
  1143. if (mode == T_TD) {
  1144. /* <td> border */
  1145. if (curtd->border == -1) {
  1146. curtd->border = ival;
  1147. } else {
  1148. err = 1;
  1149. }
  1150. } else if (mode == T_TABLE) {
  1151. /* <table> border */
  1152. if (curtable->border == -1) {
  1153. curtable->border = ival;
  1154. } else {
  1155. err = 1;
  1156. }
  1157. } else {
  1158. /* shouldnothappen */
  1159. }
  1160. if (err) {
  1161. memset(dp_errmsg, 0, 256);
  1162. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for border in html string at line %d\n", __func__,
  1163. str, hllineno);
  1164. return (1);
  1165. }
  1166. return (0);
  1167. }
  1168. /* check cellborder value in <table> */
  1169. int dphl_chk_cellborder(char *str)
  1170. {
  1171. int n = 0;
  1172. int ival = 0;
  1173. int pe = 0;
  1174. int es = 0;
  1175. struct dpinum *num = NULL;
  1176. if (*str == '-') {
  1177. memset(dp_errmsg, 0, 256);
  1178. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for cellborder in html string at line %d\n",
  1179. __func__, str, hllineno);
  1180. return (1);
  1181. }
  1182. num = dp_getinum(str);
  1183. n = num->number;
  1184. pe = num->pe;
  1185. es = num->es;
  1186. num = (struct dpinum *)dp_free((void *)num);
  1187. if (num) {
  1188. }
  1189. if (es) {
  1190. memset(dp_errmsg, 0, 256);
  1191. snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for cellborder in html string at line %d\n", __func__,
  1192. str, hllineno);
  1193. return (1);
  1194. }
  1195. if (pe) {
  1196. memset(dp_errmsg, 0, 256);
  1197. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for cellborder in html string at line %d\n", __func__,
  1198. str, hllineno);
  1199. return (1);
  1200. }
  1201. ival = n;
  1202. if (ival < 0) {
  1203. memset(dp_errmsg, 0, 256);
  1204. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for cellborder in html string at line %d\n",
  1205. __func__, str, hllineno);
  1206. return (1);
  1207. }
  1208. if (ival > 255) {
  1209. memset(dp_errmsg, 0, 256);
  1210. snprintf(dp_errmsg, (256 - 1),
  1211. "html %s(): too high value `%s' for cellborder (max is 255) in html string at line %d\n", __func__, str, hllineno);
  1212. return (1);
  1213. }
  1214. /* ival is the size */
  1215. /* size 0 is allowed */
  1216. /* <table> cellborder */
  1217. if (curtable->cellborder == -1) {
  1218. curtable->cellborder = ival;
  1219. } else {
  1220. memset(dp_errmsg, 0, 256);
  1221. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for cellborder in html string at line %d\n",
  1222. __func__, str, hllineno);
  1223. return (1);
  1224. }
  1225. return (0);
  1226. }
  1227. /* check cellpadding value, default is 2 px */
  1228. int dphl_chk_cellpadding(char *str, int mode)
  1229. {
  1230. int n = 0;
  1231. int ival = 0;
  1232. int pe = 0;
  1233. int es = 0;
  1234. int err = 0;
  1235. struct dpinum *num = NULL;
  1236. if (*str == '-') {
  1237. memset(dp_errmsg, 0, 256);
  1238. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for cellpadding in html string at line %d\n",
  1239. __func__, str, hllineno);
  1240. return (1);
  1241. }
  1242. num = dp_getinum(str);
  1243. n = num->number;
  1244. pe = num->pe;
  1245. es = num->es;
  1246. num = (struct dpinum *)dp_free((void *)num);
  1247. if (num) {
  1248. }
  1249. if (es) {
  1250. memset(dp_errmsg, 0, 256);
  1251. snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for cellpadding in html string at line %d\n", __func__,
  1252. str, hllineno);
  1253. return (1);
  1254. }
  1255. if (pe) {
  1256. memset(dp_errmsg, 0, 256);
  1257. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for cellpadding in html string at line %d\n", __func__,
  1258. str, hllineno);
  1259. return (1);
  1260. }
  1261. ival = n;
  1262. if (ival < 0) {
  1263. memset(dp_errmsg, 0, 256);
  1264. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for cellpadding in html string at line %d\n",
  1265. __func__, str, hllineno);
  1266. return (1);
  1267. }
  1268. if (ival > 255) {
  1269. memset(dp_errmsg, 0, 256);
  1270. snprintf(dp_errmsg, (256 - 1),
  1271. "html %s(): too high value `%s' for cellpadding (max is 255) in html string at line %d\n", __func__, str,
  1272. hllineno);
  1273. return (1);
  1274. }
  1275. /* ival is the size */
  1276. /* size 0 is allowed */
  1277. if (mode == T_TD) {
  1278. /* <td> cellpadding */
  1279. if (curtd->cellpadding == -1) {
  1280. curtd->cellpadding = ival;
  1281. } else {
  1282. err = 1;
  1283. }
  1284. } else if (mode == T_TABLE) {
  1285. /* <table> cellpadding */
  1286. if (curtable->cellpadding == -1) {
  1287. curtable->cellpadding = ival;
  1288. } else {
  1289. err = 1;
  1290. }
  1291. } else {
  1292. /* shouldnothappen */
  1293. }
  1294. if (err) {
  1295. memset(dp_errmsg, 0, 256);
  1296. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for cellpadding in html string at line %d\n",
  1297. __func__, str, hllineno);
  1298. return (1);
  1299. }
  1300. return (0);
  1301. }
  1302. /* check cellspacing value default is 2 px */
  1303. /* cellspacing="0.5" is used in dot data, parse fp number */
  1304. int dphl_chk_cellspacing(char *str, int mode)
  1305. {
  1306. int ival = 0;
  1307. double dval = 0.0;
  1308. int pe = 0;
  1309. int es = 0;
  1310. int err = 0;
  1311. struct dpnum *num = NULL;
  1312. if (*str == '-') {
  1313. memset(dp_errmsg, 0, 256);
  1314. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for cellspacing in html string at line %d\n",
  1315. __func__, str, hllineno);
  1316. return (1);
  1317. }
  1318. num = dp_getnum(str);
  1319. dval = num->number;
  1320. pe = num->pe;
  1321. es = num->es;
  1322. num = (struct dpnum *)dp_free((void *)num);
  1323. if (num) {
  1324. }
  1325. if (es) {
  1326. memset(dp_errmsg, 0, 256);
  1327. snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for cellspacing in html string at line %d\n", __func__,
  1328. str, hllineno);
  1329. return (1);
  1330. }
  1331. if (pe) {
  1332. memset(dp_errmsg, 0, 256);
  1333. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for cellspacing in html string at line %d\n", __func__,
  1334. str, hllineno);
  1335. return (1);
  1336. }
  1337. if (dval < 0) {
  1338. memset(dp_errmsg, 0, 256);
  1339. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for cellspacing in html string at line %d\n",
  1340. __func__, str, hllineno);
  1341. return (1);
  1342. }
  1343. if (dval > INT_MAX) {
  1344. memset(dp_errmsg, 0, 256);
  1345. snprintf(dp_errmsg, (256 - 1), "html %s(): too high value `%s' for cellspacing in html string at line %d\n",
  1346. __func__, str, hllineno);
  1347. return (1);
  1348. }
  1349. dval = round(dval);
  1350. ival = (int)dval;
  1351. if (ival > 127) {
  1352. memset(dp_errmsg, 0, 256);
  1353. snprintf(dp_errmsg, (256 - 1),
  1354. "html %s(): too high value `%s' for cellspacing (max is 127) in html string at line %d\n", __func__, str,
  1355. hllineno);
  1356. return (1);
  1357. }
  1358. /* ival is the spacing */
  1359. /* size 0 is allowed */
  1360. if (mode == T_TD) {
  1361. /* <td> cellspacing */
  1362. if (curtd->cellspacing == -1) {
  1363. curtd->cellspacing = ival;
  1364. } else {
  1365. err = 1;
  1366. }
  1367. } else if (mode == T_TABLE) {
  1368. /* <table> cellspacing */
  1369. if (curtable->cellspacing == -1) {
  1370. curtable->cellspacing = ival;
  1371. } else {
  1372. err = 1;
  1373. }
  1374. } else {
  1375. /* shouldnothappen */
  1376. }
  1377. if (err) {
  1378. memset(dp_errmsg, 0, 256);
  1379. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for cellspacing in html string at line %d\n",
  1380. __func__, str, hllineno);
  1381. return (1);
  1382. }
  1383. return (0);
  1384. }
  1385. /* check color value */
  1386. int dphl_chk_color(char *str, int mode)
  1387. {
  1388. struct dpcolor *c = NULL;
  1389. int pe = 0;
  1390. int es = 0;
  1391. int il = 0;
  1392. int rgb = 0;
  1393. int err = 0;
  1394. /* get color without colorscheme number */
  1395. c = dp_getcolor(0, 0, str);
  1396. pe = c->pe;
  1397. es = c->es;
  1398. il = c->islist;
  1399. rgb = c->color;
  1400. c = (struct dpcolor *)dp_free((void *)c);
  1401. if (c) {
  1402. }
  1403. if (es) {
  1404. memset(dp_errmsg, 0, 256);
  1405. snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for color in html string at line %d\n", __func__, str,
  1406. hllineno);
  1407. return (1);
  1408. }
  1409. if (pe) {
  1410. memset(dp_errmsg, 0, 256);
  1411. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for color in html string at line %d\n", __func__, str, hllineno);
  1412. return (1);
  1413. }
  1414. if (il) {
  1415. memset(dp_errmsg, 0, 256);
  1416. snprintf(dp_errmsg, (256 - 1), "html %s(): color-list value `%s' for color in html string at line %d\n", __func__,
  1417. str, hllineno);
  1418. return (1);
  1419. }
  1420. if (mode == T_TD) {
  1421. /* <td> color */
  1422. if (curtd->color == -1) {
  1423. curtd->color = rgb;
  1424. } else {
  1425. err = 1;
  1426. }
  1427. } else if (mode == T_TABLE) {
  1428. /* <table> color */
  1429. if (curtable->color == -1) {
  1430. curtable->color = rgb;
  1431. } else {
  1432. err = 1;
  1433. }
  1434. } else if (mode == T_FONT) {
  1435. /* <font> color */
  1436. if (curfont->color == -1) {
  1437. curfont->color = rgb;
  1438. } else {
  1439. err = 1;
  1440. }
  1441. } else {
  1442. /* shouldnothappen */
  1443. }
  1444. if (err) {
  1445. memset(dp_errmsg, 0, 256);
  1446. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for color in html string at line %d\n", __func__,
  1447. str, hllineno);
  1448. return (1);
  1449. }
  1450. return (0);
  1451. }
  1452. /* check columns value in <table> */
  1453. int dphl_chk_columns(char *str)
  1454. {
  1455. /* only '*' is allowed */
  1456. if (strlen(str) != 1) {
  1457. memset(dp_errmsg, 0, 256);
  1458. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for columns in html string at line %d\n", __func__, str,
  1459. hllineno);
  1460. return (1);
  1461. }
  1462. if (*str != '*') {
  1463. memset(dp_errmsg, 0, 256);
  1464. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for columns in html string at line %d\n", __func__, str,
  1465. hllineno);
  1466. return (1);
  1467. }
  1468. /* <table> columns */
  1469. if (curtable->columns == NULL) {
  1470. curtable->columns = str;
  1471. } else {
  1472. memset(dp_errmsg, 0, 256);
  1473. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for columns in html string at line %d\n", __func__,
  1474. str, hllineno);
  1475. return (1);
  1476. }
  1477. return (0);
  1478. }
  1479. /* check colspan value in <td> */
  1480. int dphl_chk_colspan(char *str)
  1481. {
  1482. int n = 0;
  1483. int ival = 0;
  1484. int pe = 0;
  1485. int es = 0;
  1486. struct dpinum *num = NULL;
  1487. if (*str == '-') {
  1488. memset(dp_errmsg, 0, 256);
  1489. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for colspan in html string at line %d\n", __func__,
  1490. str, hllineno);
  1491. return (1);
  1492. }
  1493. num = dp_getinum(str);
  1494. n = num->number;
  1495. pe = num->pe;
  1496. es = num->es;
  1497. num = (struct dpinum *)dp_free((void *)num);
  1498. if (num) {
  1499. }
  1500. if (es) {
  1501. memset(dp_errmsg, 0, 256);
  1502. snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for colspan in html string at line %d\n", __func__, str,
  1503. hllineno);
  1504. return (1);
  1505. }
  1506. if (pe) {
  1507. memset(dp_errmsg, 0, 256);
  1508. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for colspan in html string at line %d\n", __func__, str,
  1509. hllineno);
  1510. return (1);
  1511. }
  1512. ival = n;
  1513. if (ival < 0) {
  1514. memset(dp_errmsg, 0, 256);
  1515. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for colspan in html string at line %d\n", __func__,
  1516. str, hllineno);
  1517. return (1);
  1518. }
  1519. if (ival == 0) {
  1520. memset(dp_errmsg, 0, 256);
  1521. snprintf(dp_errmsg, (256 - 1), "html %s(): zero value `%s' for colspan in html string at line %d\n", __func__, str,
  1522. hllineno);
  1523. return (1);
  1524. }
  1525. if (ival > 65535) {
  1526. memset(dp_errmsg, 0, 256);
  1527. snprintf(dp_errmsg, (256 - 1),
  1528. "html %s(): too high value `%s' for colspan (max is 65535) in html string at line %d\n", __func__, str, hllineno);
  1529. return (1);
  1530. }
  1531. /* ival is the size */
  1532. /* size 0 is not allowed */
  1533. /* <td> colspan */
  1534. if (curtd->colspan == -1) {
  1535. curtd->colspan = ival;
  1536. } else {
  1537. memset(dp_errmsg, 0, 256);
  1538. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for colspan in html string at line %d\n", __func__,
  1539. str, hllineno);
  1540. return (1);
  1541. }
  1542. /* todo */
  1543. if (curtd->colspan > 1) {
  1544. printf("%s(): colspan=%d is not yet implemented in this version\n", __func__, curtd->colspan);
  1545. }
  1546. return (0);
  1547. }
  1548. /* check face value for font - the fontname */
  1549. int dphl_chk_face(char *str)
  1550. {
  1551. if (strlen(str) == 0) {
  1552. /* "" is same as not specified */
  1553. return (0);
  1554. }
  1555. /* <font> face */
  1556. if (curfont->face == NULL) {
  1557. curfont->face = str;
  1558. } else {
  1559. memset(dp_errmsg, 0, 256);
  1560. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for font face in html string\n", __func__, str);
  1561. return (1);
  1562. }
  1563. return (0);
  1564. }
  1565. /* check fixedsize value */
  1566. int dphl_chk_fixedsize(char *str, int mode)
  1567. {
  1568. int val = 0;
  1569. int err = 0;
  1570. if (strlen(str) == 0) {
  1571. memset(dp_errmsg, 0, 256);
  1572. snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for fixedsize in html string at line %d\n", __func__,
  1573. str, hllineno);
  1574. return (1);
  1575. }
  1576. if (strcasecmp(str, "true") == 0) {
  1577. val = DP_TRUE;
  1578. } else if (strcasecmp(str, "false") == 0) {
  1579. val = DP_FALSE;
  1580. } else {
  1581. memset(dp_errmsg, 0, 256);
  1582. snprintf(dp_errmsg, (256 - 1),
  1583. "html %s(): bad value `%s' for fixedsize instead of true/false in html string at line %d\n", __func__, str,
  1584. hllineno);
  1585. return (1);
  1586. }
  1587. if (mode == T_TD) {
  1588. /* <td> fixedsize */
  1589. if (curtd->fixedsize == -1) {
  1590. curtd->fixedsize = val;
  1591. } else {
  1592. err = 1;
  1593. }
  1594. } else if (mode == T_TABLE) {
  1595. /* <table> fixedsize */
  1596. if (curtable->fixedsize == -1) {
  1597. curtable->fixedsize = val;
  1598. } else {
  1599. err = 1;
  1600. }
  1601. } else {
  1602. /* shouldnothappen */
  1603. }
  1604. if (err) {
  1605. memset(dp_errmsg, 0, 256);
  1606. snprintf(dp_errmsg, (256 - 1),
  1607. "html %s(): multiple value `%s' for fixedsize in html string at line %d\n", __func__, str, hllineno);
  1608. return (1);
  1609. }
  1610. return (0);
  1611. }
  1612. /* check gradientangle value */
  1613. int dphl_chk_gradientangle(char *str, int mode)
  1614. {
  1615. int n = 0;
  1616. int ival = 0;
  1617. int pe = 0;
  1618. int es = 0;
  1619. int err = 0;
  1620. struct dpinum *num = NULL;
  1621. if (*str == '-') {
  1622. memset(dp_errmsg, 0, 256);
  1623. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for gradientangle in html string at line %d\n",
  1624. __func__, str, hllineno);
  1625. return (1);
  1626. }
  1627. num = dp_getinum(str);
  1628. n = num->number;
  1629. pe = num->pe;
  1630. es = num->es;
  1631. num = (struct dpinum *)dp_free((void *)num);
  1632. if (num) {
  1633. }
  1634. if (es) {
  1635. memset(dp_errmsg, 0, 256);
  1636. snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for gradientangle in html string at line %d\n",
  1637. __func__, str, hllineno);
  1638. return (1);
  1639. }
  1640. if (pe) {
  1641. memset(dp_errmsg, 0, 256);
  1642. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for gradientangle in html string at line %d\n", __func__,
  1643. str, hllineno);
  1644. return (1);
  1645. }
  1646. ival = n;
  1647. if (ival < 0) {
  1648. memset(dp_errmsg, 0, 256);
  1649. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for gradientangle in html string at line %d\n",
  1650. __func__, str, hllineno);
  1651. return (1);
  1652. }
  1653. if (ival > 360) {
  1654. memset(dp_errmsg, 0, 256);
  1655. snprintf(dp_errmsg, (256 - 1),
  1656. "html %s(): value `%s' for gradientangle is > 360 degrees in html string at line %d\n", __func__, str, hllineno);
  1657. return (1);
  1658. }
  1659. /* ival is the size */
  1660. /* size 0 is allowed ... 360 */
  1661. if (mode == T_TD) {
  1662. /* <td> gradientangle */
  1663. if (curtd->gradientangle == -1) {
  1664. curtd->gradientangle = ival;
  1665. } else {
  1666. err = 1;
  1667. }
  1668. } else if (mode == T_TABLE) {
  1669. /* <table> gradientangle */
  1670. if (curtable->gradientangle == -1) {
  1671. curtable->gradientangle = ival;
  1672. } else {
  1673. err = 1;
  1674. }
  1675. } else {
  1676. /* shouldnothappen */
  1677. }
  1678. if (err) {
  1679. memset(dp_errmsg, 0, 256);
  1680. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for gradientangle in html string at line %d\n",
  1681. __func__, str, hllineno);
  1682. return (1);
  1683. }
  1684. return (0);
  1685. }
  1686. /* check height value */
  1687. int dphl_chk_height(char *str, int mode)
  1688. {
  1689. int n = 0;
  1690. int ival = 0;
  1691. int pe = 0;
  1692. int es = 0;
  1693. int err = 0;
  1694. struct dpinum *num = NULL;
  1695. if (*str == '-') {
  1696. memset(dp_errmsg, 0, 256);
  1697. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for height in html string at line %d\n", __func__,
  1698. str, hllineno);
  1699. return (1);
  1700. }
  1701. num = dp_getinum(str);
  1702. n = num->number;
  1703. pe = num->pe;
  1704. es = num->es;
  1705. num = (struct dpinum *)dp_free((void *)num);
  1706. if (num) {
  1707. }
  1708. if (es) {
  1709. memset(dp_errmsg, 0, 256);
  1710. snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for height in html string at line %d\n", __func__, str,
  1711. hllineno);
  1712. return (1);
  1713. }
  1714. if (pe) {
  1715. memset(dp_errmsg, 0, 256);
  1716. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for height in html string at line %d\n", __func__, str, hllineno);
  1717. return (1);
  1718. }
  1719. ival = n;
  1720. if (ival < 0) {
  1721. memset(dp_errmsg, 0, 256);
  1722. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for height in html string at line %d\n", __func__,
  1723. str, hllineno);
  1724. return (1);
  1725. }
  1726. if (ival > 65535) {
  1727. memset(dp_errmsg, 0, 256);
  1728. snprintf(dp_errmsg, (256 - 1),
  1729. "html %s(): too high value `%s' for height (max is 65535) in html string at line %d\n", __func__, str, hllineno);
  1730. return (1);
  1731. }
  1732. /* ival is the size */
  1733. /* size 0 is allowed */
  1734. if (mode == T_TD) {
  1735. /* <td> height */
  1736. if (curtd->height == -1) {
  1737. curtd->height = ival;
  1738. } else {
  1739. err = 1;
  1740. }
  1741. } else if (mode == T_TABLE) {
  1742. /* <table> height */
  1743. if (curtable->height == -1) {
  1744. curtable->height = ival;
  1745. } else {
  1746. err = 1;
  1747. }
  1748. } else {
  1749. /* shouldnothappen */
  1750. }
  1751. if (err) {
  1752. memset(dp_errmsg, 0, 256);
  1753. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for height in html string at line %d\n", __func__,
  1754. str, hllineno);
  1755. return (1);
  1756. }
  1757. return (0);
  1758. }
  1759. /* check href value */
  1760. int dphl_chk_href(char *str, int mode)
  1761. {
  1762. int err = 0;
  1763. if (strlen(str) == 0) {
  1764. /* href="" is oke */
  1765. return (0);
  1766. }
  1767. /* twice href is not allowed */
  1768. if (mode == T_TD) {
  1769. /* <td> href */
  1770. if (curtd->href == NULL) {
  1771. curtd->href = str;
  1772. } else {
  1773. err = 1;
  1774. }
  1775. } else if (mode == T_TABLE) {
  1776. /* <table> href */
  1777. if (curtable->href == NULL) {
  1778. curtable->href = str;
  1779. } else {
  1780. err = 1;
  1781. }
  1782. } else {
  1783. /* shouldnothappen */
  1784. }
  1785. if (err) {
  1786. memset(dp_errmsg, 0, 256);
  1787. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for href in html string at line %d\n", __func__, str,
  1788. hllineno);
  1789. return (1);
  1790. }
  1791. return (0);
  1792. }
  1793. /* check id value */
  1794. int dphl_chk_id(char *str, int mode)
  1795. {
  1796. int err = 0;
  1797. if (strlen(str) == 0) {
  1798. /* id="" is oke */
  1799. return (0);
  1800. }
  1801. /* twice id is not allowed */
  1802. if (mode == T_TD) {
  1803. /* <td> id */
  1804. if (curtd->id == NULL) {
  1805. curtd->id = str;
  1806. } else {
  1807. err = 1;
  1808. }
  1809. } else if (mode == T_TABLE) {
  1810. /* <table> id */
  1811. if (curtable->id == NULL) {
  1812. curtable->id = str;
  1813. } else {
  1814. err = 1;
  1815. }
  1816. } else {
  1817. /* shouldnothappen */
  1818. }
  1819. if (err) {
  1820. memset(dp_errmsg, 0, 256);
  1821. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for id in html string at line %d\n", __func__, str,
  1822. hllineno);
  1823. return (1);
  1824. }
  1825. return (0);
  1826. }
  1827. /* check port value */
  1828. int dphl_chk_port(char *str, int mode)
  1829. {
  1830. int err = 0;
  1831. if (strlen(str) == 0) {
  1832. /* port="" is oke */
  1833. return (0);
  1834. }
  1835. /* twice port is not allowed */
  1836. /* check portname and compass point here todo */
  1837. if (mode == T_TD) {
  1838. /* <td> port */
  1839. if (curtd->port == NULL) {
  1840. curtd->port = str;
  1841. } else {
  1842. err = 1;
  1843. }
  1844. } else if (mode == T_TABLE) {
  1845. /* <table> port */
  1846. if (curtable->port == NULL) {
  1847. curtable->port = str;
  1848. } else {
  1849. err = 1;
  1850. }
  1851. } else {
  1852. /* shouldnothappen */
  1853. }
  1854. if (err) {
  1855. memset(dp_errmsg, 0, 256);
  1856. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for port in html string at line %d\n", __func__, str,
  1857. hllineno);
  1858. return (1);
  1859. }
  1860. return (0);
  1861. }
  1862. /* check point-size value for font */
  1863. int dphl_chk_pointsize(char *str)
  1864. {
  1865. int ival = 0;
  1866. int pe = 0;
  1867. int es = 0;
  1868. double dnum = 0.0;
  1869. struct dpnum *num = NULL;
  1870. if (*str == '-') {
  1871. memset(dp_errmsg, 0, 256);
  1872. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for point-size in html string\n", __func__, str);
  1873. return (1);
  1874. }
  1875. num = dp_getnum(str);
  1876. dnum = num->number;
  1877. pe = num->pe;
  1878. es = num->es;
  1879. num = (struct dpnum *)dp_free((void *)num);
  1880. if (num) {
  1881. }
  1882. if (es) {
  1883. memset(dp_errmsg, 0, 256);
  1884. snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for point-size in html string\n", __func__, str);
  1885. return (1);
  1886. }
  1887. if (pe) {
  1888. memset(dp_errmsg, 0, 256);
  1889. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for point-size in html string\n", __func__, str);
  1890. return (1);
  1891. }
  1892. if (dnum < 0) {
  1893. memset(dp_errmsg, 0, 256);
  1894. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for point-size in html string\n", __func__, str);
  1895. return (1);
  1896. }
  1897. if (dnum > 255) {
  1898. printf("%s(): limiting too high pointsize %f to 255\n", __func__, dnum);
  1899. dnum = 255;
  1900. }
  1901. ival = (int)dnum;
  1902. /* ival is the font pointsize */
  1903. /* pointsize 0 is allowed */
  1904. /* <font> point-size */
  1905. if (curfont->pointsize == -1) {
  1906. curfont->pointsize = ival;
  1907. } else {
  1908. memset(dp_errmsg, 0, 256);
  1909. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for point-size in html string\n", __func__, str);
  1910. return (1);
  1911. }
  1912. return (0);
  1913. }
  1914. /* check rows value in <table> */
  1915. int dphl_chk_rows(char *str)
  1916. {
  1917. /* only a single '*' is allowed */
  1918. if (strlen(str) != 1) {
  1919. memset(dp_errmsg, 0, 256);
  1920. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for rows in html string at line %d\n", __func__, str, hllineno);
  1921. return (1);
  1922. }
  1923. if (*str != '*') {
  1924. memset(dp_errmsg, 0, 256);
  1925. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for rows in html string at line %d\n", __func__, str, hllineno);
  1926. return (1);
  1927. }
  1928. if (curtable->rows == NULL) {
  1929. curtable->rows = str;
  1930. } else {
  1931. memset(dp_errmsg, 0, 256);
  1932. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for rows in html string at line %d\n", __func__, str,
  1933. hllineno);
  1934. return (1);
  1935. }
  1936. return (0);
  1937. }
  1938. /* check rowspan value in <td> */
  1939. int dphl_chk_rowspan(char *str)
  1940. {
  1941. int n = 0;
  1942. int ival = 0;
  1943. int pe = 0;
  1944. int es = 0;
  1945. struct dpinum *num = NULL;
  1946. if (*str == '-') {
  1947. memset(dp_errmsg, 0, 256);
  1948. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for rowspan in html string at line %d\n", __func__,
  1949. str, hllineno);
  1950. return (1);
  1951. }
  1952. num = dp_getinum(str);
  1953. n = num->number;
  1954. pe = num->pe;
  1955. es = num->es;
  1956. num = (struct dpinum *)dp_free((void *)num);
  1957. if (num) {
  1958. }
  1959. if (es) {
  1960. memset(dp_errmsg, 0, 256);
  1961. snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for rowspan in html string at line %d\n", __func__, str,
  1962. hllineno);
  1963. return (1);
  1964. }
  1965. if (pe) {
  1966. memset(dp_errmsg, 0, 256);
  1967. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for rowspan in html string at line %d\n", __func__, str,
  1968. hllineno);
  1969. return (1);
  1970. }
  1971. ival = n;
  1972. if (ival < 0) {
  1973. memset(dp_errmsg, 0, 256);
  1974. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for rowspan in html string at line %d\n", __func__,
  1975. str, hllineno);
  1976. return (1);
  1977. }
  1978. if (ival == 0) {
  1979. memset(dp_errmsg, 0, 256);
  1980. snprintf(dp_errmsg, (256 - 1), "html %s(): zero value `%s' for rowspan in html string at line %d\n", __func__, str,
  1981. hllineno);
  1982. return (1);
  1983. }
  1984. if (ival > 65535) {
  1985. memset(dp_errmsg, 0, 256);
  1986. snprintf(dp_errmsg, (256 - 1),
  1987. "html %s(): too high value `%s' for rowspan (max is 65535) in html string at line %d\n", __func__, str, hllineno);
  1988. return (1);
  1989. }
  1990. /* ival is the size */
  1991. /* size 0 is not allowed */
  1992. /* <td> rowspan */
  1993. if (curtd->rowspan == -1) {
  1994. curtd->rowspan = ival;
  1995. } else {
  1996. memset(dp_errmsg, 0, 256);
  1997. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for rowspan in html string at line %d\n", __func__,
  1998. str, hllineno);
  1999. return (1);
  2000. }
  2001. /* todo */
  2002. if (curtd->rowspan > 1) {
  2003. printf("%s(): rowspan=%d is not yet implemented in this version\n", __func__, curtd->rowspan);
  2004. }
  2005. return (0);
  2006. }
  2007. /* check scale value for img */
  2008. int dphl_chk_scale(char *str)
  2009. {
  2010. int status = 0;
  2011. int val = 0;
  2012. if (strcasecmp(str, "false") == 0) {
  2013. val = DP_IMGF;
  2014. } else if (strcasecmp(str, "true") == 0) {
  2015. val = DP_IMGT;
  2016. } else if (strcasecmp(str, "width") == 0) {
  2017. val = DP_IMGW;
  2018. } else if (strcasecmp(str, "height") == 0) {
  2019. val = DP_IMGH;
  2020. } else if (strcasecmp(str, "both") == 0) {
  2021. val = DP_IMGB;
  2022. } else {
  2023. status = 1;
  2024. }
  2025. /* check error status */
  2026. if (status) {
  2027. memset(dp_errmsg, 0, 256);
  2028. snprintf(dp_errmsg, (256 - 1), "html %s(): unknown value `%s' for img scale in html string\n", __func__, str);
  2029. return (1);
  2030. }
  2031. /* <img> scale */
  2032. if (curimg->scale == -1) {
  2033. curimg->scale = val;
  2034. } else {
  2035. memset(dp_errmsg, 0, 256);
  2036. snprintf(dp_errmsg, (256 - 1), "html %s(): unknown value `%s' for img scale in html string\n", __func__, str);
  2037. return (1);
  2038. }
  2039. return (0);
  2040. }
  2041. /* check sides value */
  2042. int dphl_chk_sides(char *str, int mode)
  2043. {
  2044. int err = 0;
  2045. char *p = NULL;
  2046. if (strlen(str) == 0) {
  2047. /* sides="" is oke */
  2048. return (0);
  2049. }
  2050. /* twice sides is not allowed */
  2051. /* check sides letters ltrb in string */
  2052. p = str;
  2053. err = 0;
  2054. while (*p) {
  2055. if (*p == 'l' || *p == 't' || *p == 'r' || *p == 'b' || *p == 'L' || *p == 'T' || *p == 'R' || *p == 'B') {
  2056. /* oke */
  2057. } else {
  2058. err = 1;
  2059. break;
  2060. }
  2061. p++;
  2062. }
  2063. if (err) {
  2064. memset(dp_errmsg, 0, 256);
  2065. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for sides in html string at line %d\n", __func__, str, hllineno);
  2066. return (1);
  2067. }
  2068. if (mode == T_TD) {
  2069. /* <td> sides */
  2070. if (curtd->sides == NULL) {
  2071. curtd->sides = str;
  2072. } else {
  2073. err = 1;
  2074. }
  2075. } else if (mode == T_TABLE) {
  2076. /* <table> sides */
  2077. if (curtable->sides == NULL) {
  2078. curtable->sides = str;
  2079. } else {
  2080. err = 1;
  2081. }
  2082. } else {
  2083. /* shouldnothappen */
  2084. }
  2085. if (err) {
  2086. memset(dp_errmsg, 0, 256);
  2087. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for sides in html string at line %d\n", __func__,
  2088. str, hllineno);
  2089. return (1);
  2090. }
  2091. return (0);
  2092. }
  2093. /* check src value for img */
  2094. int dphl_chk_src(char *str)
  2095. {
  2096. /* there must be something set as image source */
  2097. if (strlen(str) == 0) {
  2098. memset(dp_errmsg, 0, 256);
  2099. snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for img src in html string\n", __func__, str);
  2100. return (1);
  2101. }
  2102. /* <img> src */
  2103. if (curimg->src == NULL) {
  2104. curimg->src = str;
  2105. } else {
  2106. memset(dp_errmsg, 0, 256);
  2107. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for img src in html string\n", __func__, str);
  2108. return (1);
  2109. }
  2110. return (0);
  2111. }
  2112. /* check style value
  2113. * dot uses strtok() at multiple places and that has a problem
  2114. * that empty args are not detected, so a string like "invis,,,,," is valid
  2115. * todo: solution can be own strtok() which returns "" at empty string
  2116. * and then issue warning on a unusual string. see below.
  2117. */
  2118. int dphl_chk_style(char *str, int mode)
  2119. {
  2120. int rounded = 0;
  2121. int radial = 0;
  2122. int invis = 0;
  2123. int dotted = 0;
  2124. int dashed = 0;
  2125. int err = 0;
  2126. char *ptr = NULL;
  2127. char *res = NULL;
  2128. int once = 0;
  2129. if (strlen(str) == 0) {
  2130. /* style="" is oke */
  2131. return (0);
  2132. }
  2133. /* twice style is not allowed */
  2134. /* check style args in string todo */
  2135. if (mode == T_TD) {
  2136. /* <td> style */
  2137. if (curtd->style == NULL) {
  2138. curtd->style = str;
  2139. } else {
  2140. err = 1;
  2141. }
  2142. } else if (mode == T_TABLE) {
  2143. /* <table> style */
  2144. if (curtable->style == NULL) {
  2145. curtable->style = str;
  2146. } else {
  2147. err = 1;
  2148. }
  2149. } else {
  2150. /* shouldnothappen */
  2151. }
  2152. if (err) {
  2153. memset(dp_errmsg, 0, 256);
  2154. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for style in html string at line %d\n", __func__,
  2155. str, hllineno);
  2156. return (1);
  2157. }
  2158. /* check style string */
  2159. if (strlen(str)) {
  2160. err = 0;
  2161. ptr = (char *)dp_calloc(1, strlen(str) + 1);
  2162. strcat(ptr, str);
  2163. /* this does not detect strings like " ,,,,," */
  2164. once = 0;
  2165. /* strsep() is replacement for old strtok() todo */
  2166. res = strtok(ptr, " ,");
  2167. while (res) {
  2168. once = 1;
  2169. if (strcasecmp(res, "rounded") == 0) {
  2170. rounded = 1;
  2171. } else if (strcasecmp(res, "radial") == 0) {
  2172. radial = 1;
  2173. } else if (strcasecmp(res, "solid") == 0) {
  2174. dotted = 1;
  2175. dashed = 1;
  2176. } else if (strcasecmp(res, "invis") == 0) {
  2177. invis = 1;
  2178. } else if (strcasecmp(res, "invisible") == 0) {
  2179. invis = 1;
  2180. } else if (strcasecmp(res, "dotted") == 0) {
  2181. dotted = 1;
  2182. } else if (strcasecmp(res, "dashed") == 0) {
  2183. dashed = 1;
  2184. } else {
  2185. err = 1;
  2186. }
  2187. res = strtok(NULL, " ,");
  2188. }
  2189. ptr = (char *)dp_free((void *)ptr);
  2190. if (ptr) {
  2191. }
  2192. if (once == 0) {
  2193. /* strtok did not detect valid tokens as in a string like ",, ,," */
  2194. err = 1;
  2195. }
  2196. if (err) {
  2197. memset(dp_errmsg, 0, 256);
  2198. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for style in html string at line %d\n", __func__,
  2199. str, hllineno);
  2200. return (1);
  2201. }
  2202. }
  2203. /* set the options */
  2204. if (mode == T_TD) {
  2205. curtd->stylerounded = rounded; /* style options */
  2206. curtd->styleradial = radial; /* style options */
  2207. curtd->styleinvis = invis; /* style options */
  2208. curtd->styledotted = dotted; /* style options */
  2209. curtd->styledashed = dashed; /* style options */
  2210. } else if (mode == T_TABLE) {
  2211. curtable->stylerounded = rounded; /* style options */
  2212. curtable->styleradial = radial; /* style options */
  2213. curtable->styleinvis = invis; /* style options */
  2214. curtable->styledotted = dotted; /* style options */
  2215. curtable->styledashed = dashed; /* style options */
  2216. } else {
  2217. /* shouldnothappen */
  2218. }
  2219. return (0);
  2220. }
  2221. /* check target value */
  2222. int dphl_chk_target(char *str, int mode)
  2223. {
  2224. int err = 0;
  2225. if (strlen(str) == 0) {
  2226. /* target="" is oke */
  2227. return (0);
  2228. }
  2229. /* twice target is not allowed */
  2230. /* check target args in string todo */
  2231. if (mode == T_TD) {
  2232. /* <td> target */
  2233. if (curtd->target == NULL) {
  2234. curtd->target = str;
  2235. } else {
  2236. err = 1;
  2237. }
  2238. } else if (mode == T_TABLE) {
  2239. /* <table> target */
  2240. if (curtable->target == NULL) {
  2241. curtable->target = str;
  2242. } else {
  2243. err = 1;
  2244. }
  2245. } else {
  2246. /* shouldnothappen */
  2247. }
  2248. if (err) {
  2249. memset(dp_errmsg, 0, 256);
  2250. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for target in html string at line %d\n", __func__,
  2251. str, hllineno);
  2252. return (1);
  2253. }
  2254. return (0);
  2255. }
  2256. /* check title value */
  2257. int dphl_chk_title(char *str, int mode)
  2258. {
  2259. int err = 0;
  2260. if (strlen(str) == 0) {
  2261. /* title="" is oke */
  2262. return (0);
  2263. }
  2264. /* twice title is not allowed */
  2265. if (mode == T_TD) {
  2266. /* <td> title or tooltip */
  2267. if (curtd->title == NULL) {
  2268. curtd->title = str;
  2269. } else {
  2270. err = 1;
  2271. }
  2272. } else if (mode == T_TABLE) {
  2273. /* <table> title or tooltip */
  2274. if (curtable->title == NULL) {
  2275. curtable->title = str;
  2276. } else {
  2277. err = 1;
  2278. }
  2279. } else {
  2280. /* shouldnothappen */
  2281. }
  2282. if (err) {
  2283. memset(dp_errmsg, 0, 256);
  2284. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for title in html string at line %d\n", __func__,
  2285. str, hllineno);
  2286. return (1);
  2287. }
  2288. return (0);
  2289. }
  2290. /* check valign value */
  2291. int dphl_chk_valign(char *str, int mode)
  2292. {
  2293. int status = 0;
  2294. int val = 0;
  2295. int err = 0;
  2296. if (strcasecmp(str, "middle") == 0) {
  2297. val = DP_VALIGNM;
  2298. } else if (strcasecmp(str, "bottom") == 0) {
  2299. val = DP_VALIGNB;
  2300. } else if (strcasecmp(str, "top") == 0) {
  2301. val = DP_VALIGNT;
  2302. } else {
  2303. status = 1;
  2304. }
  2305. /* check error status */
  2306. if (status) {
  2307. memset(dp_errmsg, 0, 256);
  2308. snprintf(dp_errmsg, (256 - 1), "html %s(): unknown value `%s' for valign in html string at line %d\n", __func__,
  2309. str, hllineno);
  2310. return (1);
  2311. }
  2312. /* twice valign is not allowed */
  2313. if (mode == T_TD) {
  2314. /* <td> valign */
  2315. if (curtd->valign == -1) {
  2316. curtd->valign = val;
  2317. } else {
  2318. err = 1;
  2319. }
  2320. } else if (mode == T_TABLE) {
  2321. /* <table> valign */
  2322. if (curtable->valign == -1) {
  2323. curtable->valign = val;
  2324. } else {
  2325. err = 1;
  2326. }
  2327. } else {
  2328. /* shouldnothappen */
  2329. }
  2330. if (err) {
  2331. memset(dp_errmsg, 0, 256);
  2332. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for valign in html string at line %d\n", __func__,
  2333. str, hllineno);
  2334. return (1);
  2335. }
  2336. return (0);
  2337. }
  2338. /* check width value */
  2339. int dphl_chk_width(char *str, int mode)
  2340. {
  2341. int n = 0;
  2342. int ival = 0;
  2343. int pe = 0;
  2344. int es = 0;
  2345. int err = 0;
  2346. struct dpinum *num = NULL;
  2347. if (*str == '-') {
  2348. memset(dp_errmsg, 0, 256);
  2349. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for width in html string at line %d\n", __func__,
  2350. str, hllineno);
  2351. return (1);
  2352. }
  2353. num = dp_getinum(str);
  2354. n = num->number;
  2355. pe = num->pe;
  2356. es = num->es;
  2357. num = (struct dpinum *)dp_free((void *)num);
  2358. if (num) {
  2359. }
  2360. if (es) {
  2361. memset(dp_errmsg, 0, 256);
  2362. snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for width in html string at line %d\n", __func__, str,
  2363. hllineno);
  2364. return (1);
  2365. }
  2366. if (pe) {
  2367. memset(dp_errmsg, 0, 256);
  2368. snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for width in html string at line %d\n", __func__, str, hllineno);
  2369. return (1);
  2370. }
  2371. ival = n;
  2372. if (ival < 0) {
  2373. memset(dp_errmsg, 0, 256);
  2374. snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for width in html string at line %d\n", __func__,
  2375. str, hllineno);
  2376. return (1);
  2377. }
  2378. if (ival > 65535) {
  2379. memset(dp_errmsg, 0, 256);
  2380. snprintf(dp_errmsg, (256 - 1),
  2381. "html %s(): too high value `%s' for width (max is 65535) in html string at line %d\n", __func__, str, hllineno);
  2382. return (1);
  2383. }
  2384. /* ival is the size */
  2385. /* size 0 is allowed */
  2386. if (mode == T_TD) {
  2387. /* <td> width */
  2388. if (curtd->width == -1) {
  2389. curtd->width = ival;
  2390. } else {
  2391. err = 1;
  2392. }
  2393. } else if (mode == T_TABLE) {
  2394. /* <table> width */
  2395. if (curtable->width == -1) {
  2396. curtable->width = ival;
  2397. } else {
  2398. err = 1;
  2399. }
  2400. } else {
  2401. /* shouldnothappen */
  2402. }
  2403. if (err) {
  2404. memset(dp_errmsg, 0, 256);
  2405. snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for width in html string at line %d\n", __func__,
  2406. str, hllineno);
  2407. return (1);
  2408. }
  2409. return (0);
  2410. }
  2411. /* reset <br> newline */
  2412. void dphl_rbr(void)
  2413. {
  2414. if (curbr) {
  2415. curbr = (struct brdata *)dp_free((void *)curbr);
  2416. if (curbr) {
  2417. }
  2418. }
  2419. curbr = (struct brdata *)dp_calloc(1, sizeof(struct brdata));
  2420. curbr->align = (-1); /* ="center|left|right" */
  2421. return;
  2422. }
  2423. /* end <br> newline */
  2424. void dphl_ebr(void)
  2425. {
  2426. if (hlinf == NULL) {
  2427. /* shouldnothappen */
  2428. return;
  2429. }
  2430. /* only at first data token
  2431. * or at <br>
  2432. */
  2433. if (hlinf->mode < 0) {
  2434. /* check for <table> token */
  2435. if (curtable == NULL) {
  2436. /* mode=items */
  2437. hlinf->mode = 0;
  2438. } else {
  2439. /* mode=tables */
  2440. hlinf->mode = 1;
  2441. /* shouldnothappen */
  2442. }
  2443. }
  2444. /* add <br> */
  2445. if (hlinf->mode) {
  2446. /* add <br> to tables */
  2447. dphl_itemtables(NULL, NULL, 1);
  2448. } else {
  2449. /* add <br> to items */
  2450. dphl_itemitems(NULL, NULL, 1);
  2451. }
  2452. return;
  2453. }
  2454. /* reset <i> italic text */
  2455. void dphl_ri(void)
  2456. {
  2457. curi++;
  2458. return;
  2459. }
  2460. /* end </i> */
  2461. void dphl_ei(void)
  2462. {
  2463. if (curi) {
  2464. curi--;
  2465. }
  2466. return;
  2467. }
  2468. /* reset <b> bold text */
  2469. void dphl_rb(void)
  2470. {
  2471. curb++;
  2472. return;
  2473. }
  2474. /* end </b> */
  2475. void dphl_eb(void)
  2476. {
  2477. if (curb) {
  2478. curb--;
  2479. }
  2480. return;
  2481. }
  2482. /* reset <u> underline text */
  2483. void dphl_ru(void)
  2484. {
  2485. curu++;
  2486. return;
  2487. }
  2488. /* end </u> */
  2489. void dphl_eu(void)
  2490. {
  2491. if (curu) {
  2492. curu--;
  2493. }
  2494. return;
  2495. }
  2496. /* reset <o> overline text */
  2497. void dphl_ro(void)
  2498. {
  2499. curo++;
  2500. return;
  2501. }
  2502. /* end </o> */
  2503. void dphl_eo(void)
  2504. {
  2505. if (curo) {
  2506. curo--;
  2507. }
  2508. return;
  2509. }
  2510. /* reset <sub> subscript text */
  2511. void dphl_rsub(void)
  2512. {
  2513. cursub++;
  2514. if (cursup) {
  2515. printf("html %s(): turning superscript <sup> off because of subscript <sub> tag in html string at line %d\n",
  2516. __func__, hllineno);
  2517. }
  2518. /* force superscript off */
  2519. cursup = 0;
  2520. return;
  2521. }
  2522. /* end </sub> */
  2523. void dphl_esub(void)
  2524. {
  2525. if (cursub) {
  2526. cursub--;
  2527. }
  2528. return;
  2529. }
  2530. /* reset <sup> superscript text */
  2531. void dphl_rsup(void)
  2532. {
  2533. cursup++;
  2534. if (cursub) {
  2535. printf("html %s(): turning subscript <sub> off because of superscript <sup> tag in html string at line %d\n",
  2536. __func__, hllineno);
  2537. }
  2538. /* force subscript off */
  2539. cursub = 0;
  2540. return;
  2541. }
  2542. /* end </sup> */
  2543. void dphl_esup(void)
  2544. {
  2545. if (cursup) {
  2546. cursup--;
  2547. }
  2548. return;
  2549. }
  2550. /* reset <s> strike-through text */
  2551. void dphl_rs(void)
  2552. {
  2553. curs++;
  2554. return;
  2555. }
  2556. /* end </s> */
  2557. void dphl_es(void)
  2558. {
  2559. if (curs) {
  2560. curs--;
  2561. }
  2562. return;
  2563. }
  2564. /* reset <vr/> vertical-ruler */
  2565. void dphl_rvr(void)
  2566. {
  2567. /* set token <vr> is opt 3 */
  2568. dphl_itemtables(NULL, NULL, 3);
  2569. return;
  2570. }
  2571. /* reset <hr/> horizontal-ruler */
  2572. void dphl_rhr(void)
  2573. {
  2574. /* set token <hr> is opt 2 */
  2575. dphl_itemtables(NULL, NULL, 2);
  2576. return;
  2577. }
  2578. /* reset <img> image-data */
  2579. void dphl_rimg(void)
  2580. {
  2581. if (curimg) {
  2582. curimg = (struct imgdata *)dp_free((void *)curimg);
  2583. if (curimg) {
  2584. }
  2585. }
  2586. curimg = (struct imgdata *)dp_calloc(1, sizeof(struct imgdata));
  2587. curimg->scale = (-1); /* ="false|true|width|height|both" */
  2588. curimg->src = NULL; /* ="imagename" */
  2589. return;
  2590. }
  2591. /* end <img>
  2592. * there should be a image source be set now.
  2593. */
  2594. void dphl_eimg(void)
  2595. {
  2596. if (curimg == NULL) {
  2597. /* shouldnothappen */
  2598. return;
  2599. }
  2600. if (curimg->src == NULL) {
  2601. memset(dp_errmsg, 0, 256);
  2602. snprintf(dp_errmsg, (256 - 1), "html %s(): no image name set in src in <img> tag in html string at line %d\n",
  2603. __func__, hllineno);
  2604. } else {
  2605. /* ignore src="" as image name */
  2606. if (strlen(curimg->src) != 0) {
  2607. /* set token <img> is opt 4 */
  2608. dphl_itemtables(NULL, NULL, 4);
  2609. }
  2610. }
  2611. curimg = (struct imgdata *)dp_free((void *)curimg);
  2612. if (curimg) {
  2613. }
  2614. return;
  2615. }
  2616. /* font on stack */
  2617. static void dphl_pushfont(void)
  2618. {
  2619. splay_tree_node spn = NULL;
  2620. int val = 0;
  2621. /* data for <font> */
  2622. if (fontstack == NULL) {
  2623. fontstack = splay_tree_new(splay_tree_compare_ints, NULL, NULL);
  2624. if (fontstack == NULL) {
  2625. return;
  2626. }
  2627. }
  2628. if (splay_tree_has_data(fontstack) == 0) {
  2629. /* first entry */
  2630. splay_tree_insert(fontstack, (splay_tree_key) 0, (splay_tree_value) curfont);
  2631. return;
  2632. }
  2633. spn = splay_tree_max(fontstack);
  2634. /* current highest */
  2635. val = (int)spn->key;
  2636. /* incr. index in stack */
  2637. val++;
  2638. /* next entry */
  2639. splay_tree_insert(fontstack, (splay_tree_key) val, (splay_tree_value) curfont);
  2640. return;
  2641. }
  2642. /* font off stack */
  2643. static void dphl_pullfont(void)
  2644. {
  2645. splay_tree_node spn = NULL;
  2646. int val = 0;
  2647. /* data for <font> */
  2648. if (fontstack == NULL) {
  2649. curfont = NULL;
  2650. return;
  2651. }
  2652. if (splay_tree_has_data(fontstack) == 0) {
  2653. /* no data in tree */
  2654. fontstack = splay_tree_delete(fontstack);
  2655. curfont = NULL;
  2656. return;
  2657. }
  2658. spn = splay_tree_max(fontstack);
  2659. /* current highest */
  2660. val = (int)spn->key;
  2661. /* restore highest fontdata */
  2662. curfont = (struct fontdata *)spn->value;
  2663. /* delete highest entry */
  2664. splay_tree_remove(fontstack, (splay_tree_key) val);
  2665. return;
  2666. }
  2667. /* reset <font> */
  2668. void dphl_rfont(void)
  2669. {
  2670. struct fontdata *curfont2 = NULL;
  2671. struct fontldata *curfontl = NULL;
  2672. curfontl = (struct fontldata *)dp_calloc(1, sizeof(struct fontldata));
  2673. /* fresh table data */
  2674. curfont2 = (struct fontdata *)dp_calloc(1, sizeof(struct fontdata));
  2675. curfontl->fd = curfont2;
  2676. /* preset <font> */
  2677. curfont2->color = (-1); /* ="colorname" */
  2678. curfont2->face = NULL; /* ="fontname" */
  2679. curfont2->pointsize = (-1); /* ="int-number" */
  2680. /* link in curfont */
  2681. if (fontlist == NULL) {
  2682. fontlist = curfontl;
  2683. fontlistend = curfontl;
  2684. } else {
  2685. fontlistend->next = curfontl;
  2686. fontlistend = curfontl;
  2687. }
  2688. /* push old curfont if any */
  2689. if (curfont) {
  2690. dphl_pushfont();
  2691. }
  2692. curfont = curfont2;
  2693. return;
  2694. }
  2695. /* end <font> */
  2696. void dphl_efont(void)
  2697. {
  2698. /* pull font */
  2699. dphl_pullfont();
  2700. return;
  2701. }
  2702. /* table on stack */
  2703. static void dphl_pushtable(void)
  2704. {
  2705. splay_tree_node spn = NULL;
  2706. int val = 0;
  2707. /* data for <table> */
  2708. if (tablestack == NULL) {
  2709. tablestack = splay_tree_new(splay_tree_compare_ints, NULL, NULL);
  2710. if (tablestack == NULL) {
  2711. return;
  2712. }
  2713. }
  2714. if (splay_tree_has_data(tablestack) == 0) {
  2715. /* first entry */
  2716. splay_tree_insert(tablestack, (splay_tree_key) 0, (splay_tree_value) curtable);
  2717. return;
  2718. }
  2719. spn = splay_tree_max(tablestack);
  2720. /* current highest */
  2721. val = (int)spn->key;
  2722. /* incr. index in stack */
  2723. val++;
  2724. /* next entry */
  2725. splay_tree_insert(tablestack, (splay_tree_key) val, (splay_tree_value) curtable);
  2726. return;
  2727. }
  2728. /* table off stack */
  2729. static void dphl_pulltable(void)
  2730. {
  2731. splay_tree_node spn = NULL;
  2732. int val = 0;
  2733. /* data for <table> */
  2734. if (tablestack == NULL) {
  2735. curtable = NULL;
  2736. return;
  2737. }
  2738. if (splay_tree_has_data(tablestack) == 0) {
  2739. /* no data in tree */
  2740. tablestack = splay_tree_delete(tablestack);
  2741. curtable = NULL;
  2742. return;
  2743. }
  2744. spn = splay_tree_max(tablestack);
  2745. /* current highest */
  2746. val = (int)spn->key;
  2747. /* restore highest tabledata */
  2748. curtable = (struct tabledata *)spn->value;
  2749. /* delete highest entry */
  2750. splay_tree_remove(tablestack, (splay_tree_key) val);
  2751. return;
  2752. }
  2753. /* at new <table> to current <td> */
  2754. static void dphl_addtableitem(struct tabledata *newtable)
  2755. {
  2756. struct ilist *il = NULL;
  2757. if (yydebug || 0) {
  2758. printf("%s(): setting new <table> in current <td> items\n", __func__);
  2759. }
  2760. /* if opt is set it is br=1, hr=2, vr=3, img=4, table=5 */
  2761. if (hlinf == NULL) {
  2762. /* shouldnothappen */
  2763. return;
  2764. }
  2765. if (hlinf->mode == 0) {
  2766. /* shouldnothappen */
  2767. return;
  2768. }
  2769. if (curtable == NULL) {
  2770. /* shouldnothappen */
  2771. printf("%s(): nil curtable\n", __func__);
  2772. return;
  2773. }
  2774. if (curtd == NULL) {
  2775. /* shouldnothappen */
  2776. printf("%s(): nil curtd\n", __func__);
  2777. return;
  2778. }
  2779. if (curtr == NULL) {
  2780. /* shouldnothappen */
  2781. printf("%s(): nil curtr\n", __func__);
  2782. return;
  2783. }
  2784. il = (struct ilist *)dp_calloc(1, sizeof(struct ilist));
  2785. /* set linkage to data */
  2786. il->items = dphl_makeitem( /* str */ NULL, /* alt */ NULL, /* opt */ 5, newtable);
  2787. /* <td> belongs to this <table> */
  2788. curtd->table = curtable;
  2789. /* indicate in <td> this is a <table> */
  2790. curtd->istab = 1;
  2791. /* indicate in <tr> there is a <td> with a <table> statement */
  2792. curtr->hastab = 1;
  2793. if (curtd->il == NULL) {
  2794. curtd->il = il;
  2795. curtd->ilend = il;
  2796. } else {
  2797. curtd->ilend->next = il;
  2798. curtd->ilend = il;
  2799. }
  2800. return;
  2801. }
  2802. /* reset <table> at start */
  2803. void dphl_rtable(void)
  2804. {
  2805. struct tlist *tli = NULL; /* list of table items */
  2806. struct tabledata *curtable2 = NULL;
  2807. struct tableldata *curtablel = NULL;
  2808. if (hlinf->mode < 1) {
  2809. /* mode=tables */
  2810. hlinf->mode = 1;
  2811. if (hlinf->il) {
  2812. /* todo, clear no il and ilend items */
  2813. printf("%s(): switch to <table> mode and hlinf->il=%p to clear\n", __func__, (void *)hlinf->il);
  2814. }
  2815. }
  2816. curtablel = (struct tableldata *)dp_calloc(1, sizeof(struct tableldata));
  2817. tli = (struct tlist *)dp_calloc(1, sizeof(struct tlist));
  2818. /* fresh table data */
  2819. curtable2 = (struct tabledata *)dp_calloc(1, sizeof(struct tabledata));
  2820. curtablel->tabdata = curtable2;
  2821. /* set as table item */
  2822. tli->titem = curtablel;
  2823. /* preset <table> */
  2824. curtable2->align = (-1); /* ="center|left|right" */
  2825. if (curtable) {
  2826. curtable2->bgcolor = curtable->bgcolor; /* ="colorname" */
  2827. } else {
  2828. curtable2->bgcolor = (-1); /* ="colorname" */
  2829. }
  2830. if (curtd) {
  2831. curtable2->bgcolor = curtd->bgcolor; /* ="colorname" */
  2832. } else {
  2833. curtable2->bgcolor = (-1); /* ="colorname" */
  2834. }
  2835. curtable2->border = (-1); /* ="int-value" */
  2836. curtable2->cellborder = (-1); /* ="int-value" */
  2837. curtable2->cellpadding = (-1); /* ="int-value" */
  2838. curtable2->cellspacing = (-1); /* ="int-value" */
  2839. /* todo see above for fontcolor */
  2840. curtable2->color = (-1); /* ="colorname" */
  2841. curtable2->columns = NULL; /* ="string" */
  2842. curtable2->fixedsize = (-1); /* ="true|false" */
  2843. curtable2->gradientangle = (-1); /* ="int-value" */
  2844. curtable2->height = (-1); /* ="int-value" */
  2845. curtable2->href = NULL; /* ="string" */
  2846. curtable2->id = NULL; /* ="string" */
  2847. curtable2->port = NULL; /* ="string" */
  2848. curtable2->rows = NULL; /* ="string" */
  2849. curtable2->sides = NULL; /* ="string" */
  2850. curtable2->style = NULL; /* ="string" */
  2851. curtable2->stylerounded = (-1); /* style options */
  2852. curtable2->styleradial = (-1); /* style options */
  2853. curtable2->styleinvis = (-1); /* style options */
  2854. curtable2->styledotted = (-1); /* style options */
  2855. curtable2->styledashed = (-1); /* style options */
  2856. curtable2->target = NULL; /* ="string" */
  2857. curtable2->title = NULL; /* ="string" */
  2858. curtable2->valign = (-1); /* ="middle|bottom|top" */
  2859. curtable2->width = (-1); /* ="int-value" */
  2860. curtable2->table = curtable; /* rooted on this table or 0 */
  2861. /* not at first <table> entry */
  2862. if (curtd) {
  2863. dphl_addtableitem(curtable2);
  2864. }
  2865. /* push old curtable if any */
  2866. if (curtable) {
  2867. dphl_pushtable();
  2868. }
  2869. /* first entry if 0 */
  2870. if (curtable == NULL) {
  2871. /* add to main hlinf */
  2872. if (hlinf->tl == NULL) {
  2873. hlinf->tl = tli;
  2874. hlinf->tlend = tli;
  2875. } else {
  2876. hlinf->tlend->next = tli;
  2877. hlinf->tlend = tli;
  2878. }
  2879. } else {
  2880. if (yydebug || 0) {
  2881. printf("%s(): add to sub %p ", __func__, (void *)tli);
  2882. }
  2883. /* add as sub table entry */
  2884. if (curtable->tl == NULL) {
  2885. curtable->tl = tli;
  2886. curtable->tlend = tli;
  2887. } else {
  2888. curtable->tlend->next = tli;
  2889. curtable->tlend = tli;
  2890. }
  2891. }
  2892. if (yydebug || 0) {
  2893. printf("hlinf->tl=%p\n table from %p to %p", (void *)hlinf->tl, (void *)curtable, (void *)curtable2);
  2894. }
  2895. curtable = curtable2;
  2896. return;
  2897. }
  2898. /* end <table> */
  2899. void dphl_etable(void)
  2900. {
  2901. /* pull curtable if any */
  2902. dphl_pulltable();
  2903. return;
  2904. }
  2905. /* td on stack */
  2906. static void dphl_pushtd(void)
  2907. {
  2908. splay_tree_node spn = NULL;
  2909. int val = 0;
  2910. /* data for <td> */
  2911. if (tdstack == NULL) {
  2912. tdstack = splay_tree_new(splay_tree_compare_ints, NULL, NULL);
  2913. if (tdstack == NULL) {
  2914. return;
  2915. }
  2916. }
  2917. if (splay_tree_has_data(tdstack) == 0) {
  2918. /* first entry */
  2919. splay_tree_insert(tdstack, (splay_tree_key) 0, (splay_tree_value) curtd);
  2920. return;
  2921. }
  2922. spn = splay_tree_max(tdstack);
  2923. /* current highest */
  2924. val = (int)spn->key;
  2925. /* incr. index in stack */
  2926. val++;
  2927. /* next entry */
  2928. splay_tree_insert(tdstack, (splay_tree_key) val, (splay_tree_value) curtd);
  2929. return;
  2930. }
  2931. /* td off stack */
  2932. static void dphl_pulltd(void)
  2933. {
  2934. splay_tree_node spn = NULL;
  2935. int val = 0;
  2936. /* data for <td> */
  2937. if (tdstack == NULL) {
  2938. curtd = NULL;
  2939. return;
  2940. }
  2941. if (splay_tree_has_data(tdstack) == 0) {
  2942. /* no data in tree */
  2943. tdstack = splay_tree_delete(tdstack);
  2944. curtd = NULL;
  2945. return;
  2946. }
  2947. spn = splay_tree_max(tdstack);
  2948. /* current highest */
  2949. val = (int)spn->key;
  2950. /* restore highest tddata */
  2951. curtd = (struct tddata *)spn->value;
  2952. /* delete highest entry */
  2953. splay_tree_remove(tdstack, (splay_tree_key) val);
  2954. return;
  2955. }
  2956. /* reset <td> table data */
  2957. void dphl_rtd(void)
  2958. {
  2959. struct tddata *curtd2 = NULL;
  2960. struct tdldata *curtdl = NULL;
  2961. if (curtr == NULL) {
  2962. /* shouldnothappen */
  2963. printf("%s(): nil tr\n", __func__);
  2964. return;
  2965. }
  2966. curtdl = (struct tdldata *)dp_calloc(1, sizeof(struct tdldata));
  2967. /* fresh table data */
  2968. curtd2 = (struct tddata *)dp_calloc(1, sizeof(struct tddata));
  2969. /* push old curtd if any */
  2970. if (curtd) {
  2971. dphl_pushtd();
  2972. }
  2973. /* preset <td> */
  2974. curtd2->align = (-1); /* ="center|left|right|text" */
  2975. curtd2->balign = (-1); /* ="center|left|right" */
  2976. curtd2->bgcolor = (-1); /* ="colorname" */
  2977. curtd2->border = (-1); /* ="int-value" */
  2978. curtd2->cellpadding = (-1); /* ="int-value" */
  2979. curtd2->cellspacing = (-1); /* ="int-value" */
  2980. curtd2->color = (-1); /* ="colorname" */
  2981. curtd2->colspan = (-1); /* ="int-value" */
  2982. curtd2->fixedsize = (-1); /* ="true|false" */
  2983. curtd2->gradientangle = (-1); /* ="int-value" */
  2984. curtd2->height = (-1); /* ="int-value" */
  2985. curtd2->href = NULL; /* ="string" */
  2986. curtd2->id = NULL; /* ="string" */
  2987. curtd2->port = NULL; /* ="string" */
  2988. curtd2->rowspan = (-1); /* ="int-value" */
  2989. curtd2->sides = NULL; /* ="string" */
  2990. curtd2->style = NULL; /* ="string" */
  2991. curtd2->stylerounded = (-1); /* style options */
  2992. curtd2->styleradial = (-1); /* style options */
  2993. curtd2->styleinvis = (-1); /* style options */
  2994. curtd2->styledotted = (-1); /* style options */
  2995. curtd2->styledashed = (-1); /* style options */
  2996. curtd2->target = NULL; /* ="string" */
  2997. curtd2->title = NULL; /* ="string" */
  2998. curtd2->valign = (-1); /* ="middle|bottom|top" */
  2999. curtd2->width = (-1); /* ="int-value" */
  3000. curtd = curtd2;
  3001. curtdl->tdd = curtd;
  3002. if (curtr->td == NULL) {
  3003. /* td items in tr */
  3004. curtr->td = curtdl;
  3005. curtr->tdend = curtdl;
  3006. } else {
  3007. curtr->tdend->next = curtdl;
  3008. curtr->tdend = curtdl;
  3009. }
  3010. return;
  3011. }
  3012. /* end <td>
  3013. * code is 0 for text item or new table data
  3014. * code is 1 for image data
  3015. * code is 2 for <tr><td></td></tr>
  3016. */
  3017. void dphl_etd(int code)
  3018. {
  3019. /* curdata has data, with curtd settings */
  3020. if (code == 2) {
  3021. /* this can indicate there is something wrong in generated grph data */
  3022. printf("%s(): <td> with no items found\n", __func__);
  3023. }
  3024. /* pull curtd if any */
  3025. dphl_pulltd();
  3026. return;
  3027. }
  3028. /* tr on stack */
  3029. static void dphl_pushtr(void)
  3030. {
  3031. splay_tree_node spn = NULL;
  3032. int val = 0;
  3033. /* data for <tr> */
  3034. if (trstack == NULL) {
  3035. trstack = splay_tree_new(splay_tree_compare_ints, NULL, NULL);
  3036. }
  3037. if (splay_tree_has_data(trstack) == 0) {
  3038. /* first entry */
  3039. splay_tree_insert(trstack, (splay_tree_key) 0, (splay_tree_value) curtr);
  3040. return;
  3041. }
  3042. spn = splay_tree_max(trstack);
  3043. /* current highest */
  3044. val = (int)spn->key;
  3045. /* incr. index in stack */
  3046. val++;
  3047. /* next entry */
  3048. splay_tree_insert(trstack, (splay_tree_key) val, (splay_tree_value) curtr);
  3049. return;
  3050. }
  3051. /* tr off stack */
  3052. static void dphl_pulltr(void)
  3053. {
  3054. splay_tree_node spn = NULL;
  3055. int val = 0;
  3056. /* data for <tr> */
  3057. if (trstack == NULL) {
  3058. curtr = NULL;
  3059. return;
  3060. }
  3061. if (splay_tree_has_data(trstack) == 0) {
  3062. /* no data in tree */
  3063. trstack = splay_tree_delete(trstack);
  3064. curtr = NULL;
  3065. return;
  3066. }
  3067. spn = splay_tree_max(trstack);
  3068. /* current highest */
  3069. val = (int)spn->key;
  3070. /* restore highest trdata */
  3071. curtr = (struct trdata *)spn->value;
  3072. /* delete highest entry */
  3073. splay_tree_remove(trstack, (splay_tree_key) val);
  3074. return;
  3075. }
  3076. /* reset <tr> */
  3077. void dphl_rtr(void)
  3078. {
  3079. struct trdata *tri = NULL;
  3080. struct trlist *trl = NULL;
  3081. if (curtable == NULL) {
  3082. /* shouldnothappen */
  3083. printf("%s(): nil curtable\n", __func__);
  3084. return;
  3085. }
  3086. trl = (struct trlist *)dp_calloc(1, sizeof(struct trlist));
  3087. tri = (struct trdata *)dp_calloc(1, sizeof(struct trdata));
  3088. trl->tritem = tri;
  3089. tri->table = curtable;
  3090. if (curtable->tr == NULL) {
  3091. curtable->tr = trl;
  3092. curtable->trend = trl;
  3093. } else {
  3094. curtable->trend->next = trl;
  3095. curtable->trend = trl;
  3096. }
  3097. if (curtr) {
  3098. dphl_pushtr();
  3099. }
  3100. curtr = tri;
  3101. return;
  3102. }
  3103. /* end </tr> */
  3104. void dphl_etr(void)
  3105. {
  3106. /* pull curtr if any */
  3107. dphl_pulltr();
  3108. return;
  3109. }
  3110. /* gets data part */
  3111. void dphl_data(char *str)
  3112. {
  3113. char *altstr = NULL;
  3114. if (yydebug || 0) {
  3115. printf("html %s(): data is \"%s\"\n", __func__, str);
  3116. }
  3117. if (str == NULL) {
  3118. /* shouldnothappen */
  3119. return;
  3120. }
  3121. /* translate html chars if any */
  3122. if (strchr(str, '&')) {
  3123. /* this can set error status */
  3124. altstr = dplh_htrans(str);
  3125. if (yydebug || 0) {
  3126. printf("%s(): translated html char is \"%s\"\n", __func__, altstr);
  3127. }
  3128. if (dphl_chk_err()) {
  3129. return;
  3130. }
  3131. }
  3132. curdata = str;
  3133. if (hlinf == NULL) {
  3134. /* shouldnothappen */
  3135. return;
  3136. }
  3137. /* only at first data token
  3138. * or at <br>
  3139. */
  3140. if (hlinf->mode < 0) {
  3141. /* check for <table> token */
  3142. if (curtable == NULL) {
  3143. /* mode=items */
  3144. hlinf->mode = 0;
  3145. } else {
  3146. /* mode=tables */
  3147. hlinf->mode = 1;
  3148. }
  3149. }
  3150. /* add to items or tables */
  3151. if (hlinf->mode == 0) {
  3152. dphl_itemitems(str, altstr, 0);
  3153. } else {
  3154. dphl_itemtables(str, altstr, 0);
  3155. }
  3156. return;
  3157. }
  3158. /* free mem used by html label parsing, node hlinfo data is cleared later in dp_clearall() */
  3159. void dphl_freemem(void)
  3160. {
  3161. struct fontldata *fptr = NULL;
  3162. struct fontldata *fptrnext = NULL;
  3163. /* data for <br> */
  3164. if (curbr) {
  3165. curbr = (struct brdata *)dp_free((void *)curbr);
  3166. if (curbr) {
  3167. }
  3168. }
  3169. /* data for <img> */
  3170. if (curimg) {
  3171. curimg = (struct imgdata *)dp_free((void *)curimg);
  3172. if (curimg) {
  3173. }
  3174. }
  3175. /* <table> data */
  3176. if (tablestack) {
  3177. tablestack = splay_tree_delete(tablestack);
  3178. }
  3179. /* <td> data */
  3180. if (tdstack) {
  3181. tdstack = splay_tree_delete(tdstack);
  3182. }
  3183. /* <tr> data */
  3184. if (trstack) {
  3185. trstack = splay_tree_delete(trstack);
  3186. }
  3187. /* <font> data */
  3188. fptr = fontlist;
  3189. while (fptr) {
  3190. fptrnext = fptr->next;
  3191. if (fptr->fd) {
  3192. fptr->fd = (struct fontdata *)dp_free((void *)fptr->fd);
  3193. if (fptr->fd) {
  3194. }
  3195. }
  3196. fptr = (struct fontldata *)dp_free((void *)fptr);
  3197. if (fptr) {
  3198. }
  3199. fptr = fptrnext;
  3200. }
  3201. fontlist = NULL;
  3202. fontlistend = NULL;
  3203. /* <font> data */
  3204. if (fontstack) {
  3205. fontstack = splay_tree_delete(fontstack);
  3206. }
  3207. /* data */
  3208. curdata = NULL;
  3209. /* <s> strike-through */
  3210. curs = 0;
  3211. /* <sup> superscript text */
  3212. cursup = 0;
  3213. /* <sub> subscript text */
  3214. cursub = 0;
  3215. /* <o> overline text */
  3216. curo = 0;
  3217. /* <u> underline text */
  3218. curu = 0;
  3219. /* <b> bold text */
  3220. curb = 0;
  3221. /* <i> italic text */
  3222. curi = 0;
  3223. return;
  3224. }
  3225. /* end */