1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595 |
- /*
- * Copyright 2021
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * SPDX-License-Identifier: GPL-3.0+
- * License-Filename: LICENSE
- */
- /* dphl.* is about Dot Parsing Html Labels */
- #include "config.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <strings.h>
- #include <limits.h>
- #include <math.h>
- #include <errno.h>
- #include "splay-tree.h"
- #include "main.h"
- #include "dp.h"
- #include "dphl.h"
- #include "dpmisc.h"
- #include "dphlparser.h"
- #include "dot.tab.h"
- #include "dpus.h"
- #include "dpmem.h"
- /* max unsigned long value from html "&#nnn;" or "&#xnn;" */
- #define UNICODE_MAX 0x10FFFFul
- /* resulting parts of html label */
- static struct hlpart *hlinf = NULL;
- /* data for <table> */
- static struct tabledata *curtable = NULL;
- /* data for <table> */
- static splay_tree tablestack = NULL;
- /* data for <td> */
- static struct tddata *curtd = NULL;
- /* data for <td> */
- static splay_tree tdstack = NULL;
- /* data for <tr> */
- static struct trdata *curtr = NULL;
- /* data for <tr> */
- static splay_tree trstack = NULL;
- /* data for <font> */
- static struct fontdata *curfont = NULL;
- /* data for <font> */
- static struct fontldata *fontlist = NULL;
- static struct fontldata *fontlistend = NULL;
- /* data for <font> */
- static splay_tree fontstack = NULL;
- /* data for <br> */
- static struct brdata *curbr = NULL;
- /* data for <img> */
- static struct imgdata *curimg = NULL;
- /* data */
- static char *curdata = NULL;
- /* <s> strike-through */
- static int curs = 0;
- /* <sup> superscript text */
- static int cursup = 0;
- /* <sub> subscript text */
- static int cursub = 0;
- /* <o> overline text */
- static int curo = 0;
- /* <u> underline text */
- static int curu = 0;
- /* <b> bold text */
- static int curb = 0;
- /* <i> italic text */
- static int curi = 0;
- /* at error clear parsed info data */
- static void dphl_clearhlinfo(void);
- /* parse html label of one node, return 0 if oke */
- int htmlparse(struct dpnode *node)
- {
- int lexonly = 0;
- int i = 0;
- int token = 0;
- char *p = NULL;
- int c = 0;
- int status = 0;
- /* no parser errors */
- memset(dp_errmsg, 0, 256);
- /* check for <> to be sure for a good string */
- /* use of <> in a <!-- comment --> can cause errors */
- p = node->label;
- while (*p) {
- if (*p == '<') {
- c++;
- } else if (*p == '>') {
- c--;
- } else {
- /* nop */
- }
- p++;
- }
- /* check for mis-match <> */
- if (c != 0) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): non-matching '<' and '>' in html string\n", __func__);
- return (1);
- }
- /* test mode to only lex () */
- if (lexonly) {
- html_lex_init(1 /* debug */ , node->label, node->yylineno);
- printf("html %s(): lexing string \"%s\"\n", __func__, node->label);
- for (i = 0; i < 100; i++) {
- token = html_lex();
- printf("%s(%d): token %d [%s]\n", __func__, i, token, hlylval.string);
- if (token == 0 || token == EOF) {
- break;
- }
- }
- html_lex_deinit();
- printf("error message is: \"%s\"\n", dp_errmsg);
- return (0);
- }
- /*
- * run the parser on the html string
- */
- /* where to build the data structures */
- hlinf = (struct hlpart *)dp_calloc(1, sizeof(struct hlpart));
- /* unknown mode yet */
- hlinf->mode = 0; /* or (-1); */
- html_lex_init(yydebug /* debug */ , node->label, node->yylineno);
- status = hlyparse();
- /* check for error message */
- if (dphl_chk_err()) {
- status++;
- }
- html_lex_deinit();
- if (yydebug || 0) {
- printf("html %s(): %d status from html parser '%s'\n", __func__, status, dp_errmsg);
- }
- if (status) {
- /* at error clear all data */
- dphl_clearhlinfo();
- } else {
- /* parsed oke and convert parsed data */
- /* todo verify() then at error clear all data */
- /* set the resulted parsed data as structures */
- node->hlinfo = hlinf;
- if (yydebug || 0) {
- printf("%s(): node %d \"%s\" \"%s\" mode=%d il=%p tl=%p\n", __func__, node->nr, node->name, node->label,
- hlinf->mode, (void *)hlinf->il, (void *)hlinf->tl);
- }
- if (hlinf->mode == 0) {
- /* item mode should not have tables data */
- if (hlinf->tl) {
- printf("%s(): node \"%s\" \"%s\" mode=%d il=%p tl=%p shouldnothappen tl\n", __func__, node->name,
- node->label, hlinf->mode, (void *)hlinf->il, (void *)hlinf->tl);
- }
- } else if (hlinf->mode == 1) {
- /* table mode should not have item data */
- if (hlinf->il) {
- printf("%s(): node \"%s\" \"%s\" mode=%d il=%p tl=%p shouldnothappen il\n", __func__, node->name,
- node->label, hlinf->mode, (void *)hlinf->il, (void *)hlinf->tl);
- }
- } else {
- /* hlinf->mode == -1 does happen todo */
- printf("%s(): node \"%s\" \"%s\" mode=%d il=%p tl=%p shouldnothappen wrong mode\n", __func__, node->name,
- node->label, hlinf->mode, (void *)hlinf->il, (void *)hlinf->tl);
- }
- }
- return (status);
- }
- /* at error clear parsed info data */
- static void dphl_clearhlinfo(void)
- {
- struct ilist *pil = NULL;
- struct ilist *pilnext = NULL;
- if (hlinf == NULL) { /* no data */
- return;
- }
- /* item data to free */
- if (hlinf->il) {
- pil = hlinf->il;
- while (pil) {
- pilnext = pil->next;
- if (pil->items) {
- pil->items = (struct item *)dp_free(pil->items);
- }
- pil = (struct ilist *)dp_free(pil);
- if (pil) {
- }
- pil = pilnext;
- }
- hlinf->il = NULL;
- hlinf->ilend = NULL;
- }
- /* table data to free */
- if (hlinf->tl) {
- /* todo */
- hlinf->tl = NULL;
- hlinf->tlend = NULL;
- }
- /* final free */
- hlinf = (struct hlpart *)dp_free(hlinf);
- if (hlinf) {
- }
- return;
- }
- /* add data to items */
- static struct item *dphl_makeitem(char *str, char *alt, int opt, struct tabledata *newtable)
- {
- struct item *item = NULL;
- char *msg = NULL;
- item = (struct item *)dp_calloc(1, sizeof(struct item));
- msg = str;
- /* preset item */
- item->text = str; /* text to display */
- item->atext = alt; /* modified text to display */
- item->fontname = NULL; /* optional font */
- item->fontsize = (-1); /* optional pointsize */
- item->fontcolor = (-1); /* optional color of text */
- item->ncolor = (-1); /* optional background color from <td> or <table> */
- item->table = NULL; /* optional <table> in <td> */
- /* the bitflags are all 0 */
- /* check if a <br> */
- if (opt == 1) {
- item->bitflags.br = 1;
- }
- /* check if a <hr> */
- if (opt == 2) {
- item->bitflags.hr = 1;
- }
- /* check if a <vr> */
- if (opt == 3) {
- item->bitflags.vr = 1;
- }
- /* check if a <table> */
- if (opt == 5) {
- item->bitflags.table = 1;
- /* this is the <table> in the <td> */
- item->table = newtable;
- msg = (char *)"<table> in <td>";
- }
- /* check if str has html chars */
- if (alt) {
- item->bitflags.at = 1;
- }
- /* set italic bitflags etc. */
- if (curb) {
- /* <b> italic */
- item->bitflags.b = 1;
- }
- if (curi) {
- /* <i> italic */
- item->bitflags.i = 1;
- }
- if (curo) {
- /* <o> overline */
- item->bitflags.o = 1;
- }
- if (curu) {
- /* <u> underline */
- item->bitflags.u = 1;
- }
- if (curs) {
- /* <s> strike-through */
- item->bitflags.s = 1;
- }
- if (cursub) {
- /* <sub> subscript */
- item->bitflags.sub = 1;
- }
- if (cursup) {
- /* <sup> superscript */
- item->bitflags.sup = 1;
- }
- if (curimg) {
- /* <img> image */
- item->bitflags.img = 1;
- }
- /* add extra optional data in table mode */
- if (hlinf->mode) {
- /* <table> settings */
- if (curtable) {
- if (curtable->color < 0) {
- /* not specified */
- } else {
- item->fontcolor = curtable->color;
- }
- if (curtable->bgcolor < 0) {
- /* not specified */
- } else {
- item->ncolor = curtable->bgcolor;
- }
- }
- /* <td> settings override curtable settings */
- if (curtd) {
- if (curtd->color < 0) {
- /* not specified */
- } else {
- item->fontcolor = curtd->color;
- }
- if (curtd->bgcolor < 0) {
- /* not specified */
- } else {
- if (yydebug || 0) {
- printf("%s(): setting background color 0x%x for \"%s\"\n", __func__, curtd->bgcolor, msg);
- }
- item->ncolor = curtd->bgcolor;
- }
- }
- }
- /* if there is a optional font */
- if (curfont) {
- /* fontname */
- if (curfont->face == NULL) {
- /* not specified */
- } else {
- item->fontname = curfont->face;
- }
- /* fontsize */
- if (curfont->pointsize < 0) {
- /* not specified */
- } else {
- item->fontsize = curfont->pointsize;
- }
- /* fontcolor */
- if (curfont->color < 0) {
- /* not specified */
- } else {
- item->fontcolor = curfont->color;
- }
- }
- return (item);
- }
- /* add data to items */
- static void dphl_itemitems(char *str, char *alt, int opt)
- {
- struct ilist *il = NULL;
- /* if opt is set it is br=1 */
- if (hlinf == NULL) {
- /* shouldnohappen */
- return;
- }
- il = (struct ilist *)dp_calloc(1, sizeof(struct ilist));
- /* set linkage to data */
- il->items = dphl_makeitem(str, alt, opt, NULL);
- if (il->items == NULL) {
- /* shouldnothappen */
- return;
- }
- /* link the new data field */
- if (hlinf->il == NULL) {
- hlinf->il = il;
- hlinf->ilend = il;
- } else {
- hlinf->ilend->next = il;
- hlinf->ilend = il;
- }
- return;
- }
- /* add data to tables */
- static void dphl_itemtables(char *str, char *alt, int opt)
- {
- struct ilist *il = NULL;
- /* if opt is set it is br=1, hr=2, vr=3, img=4 */
- if (hlinf == NULL) {
- /* shouldnothappen */
- return;
- }
- if (hlinf->mode == 0) {
- /* shouldnothappen */
- return;
- }
- if (curtable == NULL) {
- /* shouldnothappen */
- printf("%s(): nil curtable\n", __func__);
- return;
- }
- if (curtd == NULL) {
- /* shouldnothappen */
- printf("%s(): nil curtd\n", __func__);
- return;
- }
- il = (struct ilist *)dp_calloc(1, sizeof(struct ilist));
- /* set linkage to data */
- il->items = dphl_makeitem(str, alt, opt, NULL);
- curtd->table = curtable;
- if (curtd->il == NULL) {
- curtd->il = il;
- curtd->ilend = il;
- } else {
- curtd->ilend->next = il;
- curtd->ilend = il;
- }
- return;
- }
- /* put char in buffer */
- static int dplh_putc_utf8(unsigned long cp, char *buffer)
- {
- unsigned char *bytes = (unsigned char *)buffer;
- if (cp <= 0x007Ful) {
- bytes[0] = (unsigned char)cp;
- return (1);
- }
- if (cp <= 0x07FFul) {
- bytes[1] = (unsigned char)((2 << 6) | (cp & 0x3F));
- bytes[0] = (unsigned char)((6 << 5) | (cp >> 6));
- return (2);
- }
- if (cp <= 0xFFFFul) {
- bytes[2] = (unsigned char)((2 << 6) | (cp & 0x3F));
- bytes[1] = (unsigned char)((2 << 6) | ((cp >> 6) & 0x3F));
- bytes[0] = (unsigned char)((14 << 4) | (cp >> 12));
- return (3);
- }
- if (cp <= 0x10FFFFul) {
- bytes[3] = (unsigned char)((2 << 6) | (cp & 0x3F));
- bytes[2] = (unsigned char)((2 << 6) | ((cp >> 6) & 0x3F));
- bytes[1] = (unsigned char)((2 << 6) | ((cp >> 12) & 0x3F));
- bytes[0] = (unsigned char)((30 << 3) | (cp >> 18));
- return (4);
- }
- return (0);
- }
- /* html chars */
- static struct mi {
- const char *key;
- const char *data;
- } entdata[] = {
- { "Æ", "Æ" },
- { "Á", "Á" },
- { "Â", "Â" },
- { "À", "À" },
- { "Α", "Α" },
- { "Å", "Å" },
- { "Ã", "Ã" },
- { "Ä", "Ä" },
- { "Β", "Β" },
- { "Ç", "Ç" },
- { "Χ", "Χ" },
- { "‡", "‡" },
- { "Δ", "Δ" },
- { "Ð", "Ð" },
- { "É", "É" },
- { "Ê", "Ê" },
- { "È", "È" },
- { "Ε", "Ε" },
- { "Η", "Η" },
- { "Ë", "Ë" },
- { "Γ", "Γ" },
- { "Í", "Í" },
- { "Î", "Î" },
- { "Ì", "Ì" },
- { "Ι", "Ι" },
- { "Ï", "Ï" },
- { "Κ", "Κ" },
- { "Λ", "Λ" },
- { "Μ", "Μ" },
- { "Ñ", "Ñ" },
- { "Ν", "Ν" },
- { "Œ", "Œ" },
- { "Ó", "Ó" },
- { "Ô", "Ô" },
- { "Ò", "Ò" },
- { "Ω", "Ω" },
- { "Ο", "Ο" },
- { "Ø", "Ø" },
- { "Õ", "Õ" },
- { "Ö", "Ö" },
- { "Φ", "Φ" },
- { "Π", "Π" },
- { "″", "″" },
- { "Ψ", "Ψ" },
- { "Ρ", "Ρ" },
- { "Š", "Š" },
- { "Σ", "Σ" },
- { "Þ", "Þ" },
- { "Τ", "Τ" },
- { "Θ", "Θ" },
- { "Ú", "Ú" },
- { "Û", "Û" },
- { "Ù", "Ù" },
- { "Υ", "Υ" },
- { "Ü", "Ü" },
- { "Ξ", "Ξ" },
- { "Ý", "Ý" },
- { "Ÿ", "Ÿ" },
- { "Ζ", "Ζ" },
- { "á", "á" },
- { "â", "â" },
- { "´", "´" },
- { "æ", "æ" },
- { "à", "à" },
- { "ℵ", "ℵ" },
- { "α", "α" },
- { "&", "&" },
- { "∧", "∧" },
- { "∠", "∠" },
- { "'", "'" },
- { "å", "å" },
- { "≈", "≈" },
- { "ã", "ã" },
- { "ä", "ä" },
- { "„", "„" },
- { "β", "β" },
- { "¦", "¦" },
- { "•", "•" },
- { "∩", "∩" },
- { "ç", "ç" },
- { "¸", "¸" },
- { "¢", "¢" },
- { "χ", "χ" },
- { "ˆ", "ˆ" },
- { "♣", "♣" },
- { "≅", "≅" },
- { "©", "©" },
- { "↵", "↵" },
- { "∪", "∪" },
- { "¤", "¤" },
- { "⇓", "⇓" },
- { "†", "†" },
- { "↓", "↓" },
- { "°", "°" },
- { "δ", "δ" },
- { "♦", "♦" },
- { "÷", "÷" },
- { "é", "é" },
- { "ê", "ê" },
- { "è", "è" },
- { "∅", "∅" },
- { " ", "\xE2\x80\x83" },
- { " ", "\xE2\x80\x82" },
- { "ε", "ε" },
- { "≡", "≡" },
- { "η", "η" },
- { "ð", "ð" },
- { "ë", "ë" },
- { "€", "€" },
- { "∃", "∃" },
- { "ƒ", "ƒ" },
- { "∀", "∀" },
- { "½", "½" },
- { "¼", "¼" },
- { "¾", "¾" },
- { "⁄", "⁄" },
- { "γ", "γ" },
- { "≥", "≥" },
- { ">", ">" },
- { "⇔", "⇔" },
- { "↔", "↔" },
- { "♥", "♥" },
- { "…", "…" },
- { "í", "í" },
- { "î", "î" },
- { "¡", "¡" },
- { "ì", "ì" },
- { "ℑ", "ℑ" },
- { "∞", "∞" },
- { "∫", "∫" },
- { "ι", "ι" },
- { "¿", "¿" },
- { "∈", "∈" },
- { "ï", "ï" },
- { "κ", "κ" },
- { "⇐", "⇐" },
- { "λ", "λ" },
- { "⟨", "〈" },
- { "«", "«" },
- { "←", "←" },
- { "⌈", "⌈" },
- { "“", "“" },
- { "≤", "≤" },
- { "⌊", "⌊" },
- { "∗", "∗" },
- { "◊", "◊" },
- { "‎", "\xE2\x80\x8E" },
- { "‹", "‹" },
- { "‘", "‘" },
- { "<", "<" },
- { "¯", "¯" },
- { "—", "—" },
- { "µ", "µ" },
- { "·", "·" },
- { "−", "−" },
- { "μ", "μ" },
- { "∇", "∇" },
- { " ", "\xC2\xA0" },
- { "–", "–" },
- { "≠", "≠" },
- { "∋", "∋" },
- { "¬", "¬" },
- { "∉", "∉" },
- { "⊄", "⊄" },
- { "ñ", "ñ" },
- { "ν", "ν" },
- { "ó", "ó" },
- { "ô", "ô" },
- { "œ", "œ" },
- { "ò", "ò" },
- { "‾", "‾" },
- { "ω", "ω" },
- { "ο", "ο" },
- { "⊕", "⊕" },
- { "∨", "∨" },
- { "ª", "ª" },
- { "º", "º" },
- { "ø", "ø" },
- { "õ", "õ" },
- { "⊗", "⊗" },
- { "ö", "ö" },
- { "¶", "¶" },
- { "∂", "∂" },
- { "‰", "‰" },
- { "⊥", "⊥" },
- { "φ", "φ" },
- { "π", "π" },
- { "ϖ", "ϖ" },
- { "±", "±" },
- { "£", "£" },
- { "′", "′" },
- { "∏", "∏" },
- { "∝", "∝" },
- { "ψ", "ψ" },
- { """, "\"" },
- { "⇒", "⇒" },
- { "√", "√" },
- { "⟩", "〉" },
- { "»", "»" },
- { "→", "→" },
- { "⌉", "⌉" },
- { "”", "”" },
- { "ℜ", "ℜ" },
- { "®", "®" },
- { "⌋", "⌋" },
- { "ρ", "ρ" },
- { "‏", "\xE2\x80\x8F" },
- { "›", "›" },
- { "’", "’" },
- { "‚", "‚" },
- { "š", "š" },
- { "⋅", "⋅" },
- { "§", "§" },
- { "­", "\xC2\xAD" },
- { "σ", "σ" },
- { "ς", "ς" },
- { "∼", "∼" },
- { "♠", "♠" },
- { "⊂", "⊂" },
- { "⊆", "⊆" },
- { "∑", "∑" },
- { "¹", "¹" },
- { "²", "²" },
- { "³", "³" },
- { "⊃", "⊃" },
- { "⊇", "⊇" },
- { "ß", "ß" },
- { "τ", "τ" },
- { "∴", "∴" },
- { "θ", "θ" },
- { "ϑ", "ϑ" },
- { " ", "\xE2\x80\x89" },
- { "þ", "þ" },
- { "˜", "˜" },
- { "×", "×" },
- { "™", "™" },
- { "⇑", "⇑" },
- { "ú", "ú" },
- { "↑", "↑" },
- { "û", "û" },
- { "ù", "ù" },
- { "¨", "¨" },
- { "ϒ", "ϒ" },
- { "υ", "υ" },
- { "ü", "ü" },
- { "℘", "℘" },
- { "ξ", "ξ" },
- { "ý", "ý" },
- { "¥", "¥" },
- { "ÿ", "ÿ" },
- { "ζ", "ζ" },
- { "‍", "\xE2\x80\x8D" },
- { "‌", "\xE2\x80\x8C" }
- };
- /* search compare */
- static int entcmp(const void *key, const void *value)
- {
- struct mi *mi1 = (struct mi *)key;
- struct mi *mi2 = (struct mi *)value;
- return (strcasecmp(mi1->key, mi2->key));
- }
- /* translate html chars like "&" into "&" */
- static char *dplh_htrans(char *str)
- {
- struct mi thekey = { NULL, NULL };
- char *ret = NULL;
- int blen = 0; /* buffer length */
- char *buf = NULL; /* output buffer */
- char *ebuf = NULL; /* entity buffer */
- char *p = NULL;
- char *q = NULL;
- char *tmpp = NULL;
- char *tmpq = NULL;
- int nc = 0;
- unsigned long cp = 0;
- char *tail = NULL;
- struct mi *entity = NULL;
- int elen = 0;
- /* check str */
- if (str == NULL) {
- return (NULL);
- }
- if (strlen(str) == 0) {
- return (NULL);
- }
- if (strchr(str, '&') == NULL) {
- return (NULL);
- }
- if (strchr(str, ';') == NULL) {
- /* parse error */
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): missing ';' in `%s' for html char in html string at line %d\n", __func__, str, hllineno);
- return (NULL);
- }
- /* if only "&;" */
- if (strlen(str) < 3) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): too short `%s' for html char in html string at line %d\n", __func__, str, hllineno);
- return (NULL);
- }
- /* create buffers for modified string */
- blen = strlen(str) + 1;
- buf = (char *)dp_calloc(1, blen);
- ebuf = (char *)dp_calloc(1, blen);
- /* scan str and replace or copy chars */
- p = str;
- q = buf;
- while (*p) {
- /* check for start of a html char */
- if (*p == '&') {
- /* copy to entity buf */
- memset(ebuf, 0, blen);
- tmpp = p;
- tmpq = ebuf;
- while (*tmpp) {
- /* check for end of entity */
- if (*tmpp == ';') {
- /* put the final ';' in ebuf */
- *tmpq = *tmpp;
- break;
- } else {
- /* copy chars */
- *tmpq = *tmpp;
- tmpp++;
- tmpq++;
- }
- }
- /* check end of str */
- if (*tmpp == 0) {
- /* parse error */
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): missing ';' in `%s' for html char in html string at line %d\n", __func__, ebuf, hllineno);
- /* stop parsing string */
- break;
- }
- /* check for &; */
- if (strlen(ebuf) < 3) {
- /* parse error */
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): empty entity `%s' for html char in html string at line %d\n", __func__, ebuf, hllineno);
- /* stop parsing string */
- break;
- }
- /* check if has dec or hex value */
- if (strchr(ebuf, '#')) {
- errno = 0;
- tail = NULL;
- /* dec or hex entity with 'x' or 'X' */
- if (strchr(ebuf, 'x') || strchr(ebuf, 'X')) {
- /* hex entity as "€" */
- cp = strtoul((char *)(ebuf + 3), (char **)(&tail), 16);
- } else {
- /* decimal entity as " " */
- cp = strtoul((char *)(ebuf + 2), (char **)(&tail), 10);
- }
- /* check for errors */
- if (errno || (*tail != ';') || (cp > UNICODE_MAX)) {
- /* parse error */
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): bad value `%s' for html char in html string at line %d\n", __func__, ebuf, hllineno);
- /* stop parsing string */
- break;
- } else {
- /* cp is always a positive number, unsigned but it can be 0 */
- if (cp == 0) {
- printf
- ("html %s(): zero value `%s' for html char terminates early html string at line %d\n",
- __func__, ebuf, hllineno);
- /* stop parsing string */
- break;
- }
- /* oke */
- nc = dplh_putc_utf8(cp, q);
- /* a duff device to update q */
- /* this fall-thru is intentional but gcc may warn */
- /* also gcc does detect these specific comments below to suppress a warning */
- switch (nc) {
- case 4:
- q++;
- /* FALLTHRU */
- case 3:
- q++;
- /* FALLTHRU */
- case 2:
- q++;
- /* FALLTHRU */
- case 1:
- q++;
- /* FALLTHRU */
- default:
- break;
- }
- }
- } else {
- /* textual entity as "&" is in ebuf */
- thekey.key = ebuf;
- entity = (struct mi *)
- bsearch(&thekey, entdata, (sizeof(entdata) / sizeof(entdata[0])), sizeof(struct mi), entcmp);
- if (entity == NULL) {
- /* parse error */
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): bad value `%s' for html char in html string at line %d\n", __func__, ebuf, hllineno);
- /* stop parsing string */
- } else {
- elen = strlen(entity->data);
- /* there is enough room in buf because replacements are shorter */
- memcpy(q, entity->data, elen);
- q = q + elen;
- }
- }
- /* now skip p past the entity */
- while (*p) {
- if (*p == ';') {
- p++;
- break;
- }
- p++;
- }
- } else {
- /* regular char to copy */
- *q = *p;
- p++;
- q++;
- }
- }
- /* check for error */
- if (dphl_chk_err()) {
- ret = NULL;
- } else {
- ret = dp_uniqstr(buf);
- }
- buf = (char *)dp_free(buf);
- if (buf) {
- }
- ebuf = (char *)dp_free(ebuf);
- if (ebuf) {
- }
- return (ret);
- }
- /* unknown attribute */
- void dphl_attr_huh(char *tag, char *attr, char *value)
- {
- printf("html %s(): at tag %s unknown attribute %s=\"%s\" skipped in html string at line %d\n", __func__, tag, attr, value,
- hllineno);
- fflush(stdout);
- return;
- }
- /* check for error message */
- int dphl_chk_err(void)
- {
- int ret = 0;
- if (strlen(dp_errmsg)) {
- /* there is a error message, fflush std */
- fflush(stdout);
- fflush(stderr);
- ret = 1;
- } else {
- ret = 0;
- }
- return (ret);
- }
- /* return 1 if string is only spaces */
- static int dphl_isws(char *str)
- {
- int ret = 1;
- char *p = NULL;
- p = str;
- while (*p) {
- /* keep scanning when spaces */
- if (*p == ' ') {
- } else if (*p == '\n') {
- } else if (*p == '\t') {
- } else if (*p == '\r') {
- } else if (*p == '\f') {
- } else {
- ret = 0;
- break;
- }
- p++;
- }
- return (ret);
- }
- /* check data before/after <table></table> */
- void dphl_tabledata(char *str)
- {
- /* check if spaces */
- if (dphl_isws(str) == 0) {
- printf("html %s(): skipped `%s' around <table></table> tag in html string at line %d\n", __func__, str, hllineno);
- }
- return;
- }
- /* check align="value"
- * for <br> "center|left|right"
- * for <table> "center|left|right"
- * for <td> "center|left|right|text"
- */
- int dphl_chk_align(char *str, int mode)
- {
- int status = 0;
- int val = 0;
- int err = 0;
- if (strcasecmp(str, "center") == 0) {
- val = DP_ALIGNC;
- } else if (strcasecmp(str, "left") == 0) {
- val = DP_ALIGNL;
- } else if (strcasecmp(str, "right") == 0) {
- val = DP_ALIGNR;
- } else {
- /* only <td> */
- if (mode == T_TD) {
- if (strcasecmp(str, "text") == 0) {
- val = DP_ALIGNT;
- } else {
- status = 1;
- }
- } else {
- status = 1;
- }
- }
- /* check error status */
- if (status) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): unknown value `%s' for align in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- /* value is oke for align */
- if (mode == T_TD) {
- /* <td> align */
- if (curtd->align == -1) {
- curtd->align = val;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> align */
- if (curtable->align == -1) {
- curtable->align = val;
- } else {
- err = 1;
- }
- } else if (mode == T_BR) {
- /* <br> align */
- if (curbr->align == -1) {
- curbr->align = val;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for align in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- return (0);
- }
- /*
- * for <td> "center|left|right"
- */
- int dphl_chk_balign(char *str)
- {
- int status = 0;
- int val = 0;
- if (strcasecmp(str, "center") == 0) {
- val = DP_ALIGNC;
- } else if (strcasecmp(str, "left") == 0) {
- val = DP_ALIGNL;
- } else if (strcasecmp(str, "right") == 0) {
- val = DP_ALIGNR;
- } else {
- status = 1;
- }
- /* check error status */
- if (status) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): unknown value `%s' for balign in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- /* value is oke for <td> balign */
- if (curtd->balign == -1) {
- curtd->balign = val;
- } else {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for balign in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- return (0);
- }
- /* check bgcolor value */
- int dphl_chk_bgcolor(char *str, int mode)
- {
- struct dpcolor *c = NULL;
- int pe = 0;
- int es = 0;
- int il = 0;
- int rgb = 0;
- int err = 0;
- /* get color without colorscheme number */
- c = dp_getcolor(0, 0, str);
- pe = c->pe;
- es = c->es;
- il = c->islist;
- rgb = c->color;
- c = (struct dpcolor *)dp_free((void *)c);
- if (c) {
- }
- if (es) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for bgAcolor in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- if (pe) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for bgcolor in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- if (il) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): color-list value `%s' for bgcolor in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- if (mode == T_TD) {
- /* <td> bgcolor */
- if (curtd->bgcolor == -1) {
- curtd->bgcolor = rgb;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> bgcolor */
- if (curtable->bgcolor == -1) {
- curtable->bgcolor = rgb;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for bgcolor in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- return (0);
- }
- /* check border value */
- int dphl_chk_border(char *str, int mode)
- {
- int n = 0;
- int ival = 0;
- int pe = 0;
- int es = 0;
- int err = 0;
- struct dpinum *num = NULL;
- if (*str == '-') {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for border in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- num = dp_getinum(str);
- n = num->number;
- pe = num->pe;
- es = num->es;
- num = (struct dpinum *)dp_free((void *)num);
- if (num) {
- }
- if (es) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for border in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- if (pe) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for border in html string at line %d\n", __func__, str, hllineno);
- return (1);
- }
- ival = n;
- if (ival < 0) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for border in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- if (ival > 255) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): too high value `%s' for border (max is 255) in html string at line %d\n",
- __func__, str, hllineno);
- return (1);
- }
- /* ival is the size */
- /* size 0 is allowed */
- if (mode == T_TD) {
- /* <td> border */
- if (curtd->border == -1) {
- curtd->border = ival;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> border */
- if (curtable->border == -1) {
- curtable->border = ival;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for border in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- return (0);
- }
- /* check cellborder value in <table> */
- int dphl_chk_cellborder(char *str)
- {
- int n = 0;
- int ival = 0;
- int pe = 0;
- int es = 0;
- struct dpinum *num = NULL;
- if (*str == '-') {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for cellborder in html string at line %d\n",
- __func__, str, hllineno);
- return (1);
- }
- num = dp_getinum(str);
- n = num->number;
- pe = num->pe;
- es = num->es;
- num = (struct dpinum *)dp_free((void *)num);
- if (num) {
- }
- if (es) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for cellborder in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- if (pe) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for cellborder in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- ival = n;
- if (ival < 0) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for cellborder in html string at line %d\n",
- __func__, str, hllineno);
- return (1);
- }
- if (ival > 255) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): too high value `%s' for cellborder (max is 255) in html string at line %d\n", __func__, str, hllineno);
- return (1);
- }
- /* ival is the size */
- /* size 0 is allowed */
- /* <table> cellborder */
- if (curtable->cellborder == -1) {
- curtable->cellborder = ival;
- } else {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for cellborder in html string at line %d\n",
- __func__, str, hllineno);
- return (1);
- }
- return (0);
- }
- /* check cellpadding value, default is 2 px */
- int dphl_chk_cellpadding(char *str, int mode)
- {
- int n = 0;
- int ival = 0;
- int pe = 0;
- int es = 0;
- int err = 0;
- struct dpinum *num = NULL;
- if (*str == '-') {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for cellpadding in html string at line %d\n",
- __func__, str, hllineno);
- return (1);
- }
- num = dp_getinum(str);
- n = num->number;
- pe = num->pe;
- es = num->es;
- num = (struct dpinum *)dp_free((void *)num);
- if (num) {
- }
- if (es) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for cellpadding in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- if (pe) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for cellpadding in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- ival = n;
- if (ival < 0) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for cellpadding in html string at line %d\n",
- __func__, str, hllineno);
- return (1);
- }
- if (ival > 255) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): too high value `%s' for cellpadding (max is 255) in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- /* ival is the size */
- /* size 0 is allowed */
- if (mode == T_TD) {
- /* <td> cellpadding */
- if (curtd->cellpadding == -1) {
- curtd->cellpadding = ival;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> cellpadding */
- if (curtable->cellpadding == -1) {
- curtable->cellpadding = ival;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for cellpadding in html string at line %d\n",
- __func__, str, hllineno);
- return (1);
- }
- return (0);
- }
- /* check cellspacing value default is 2 px */
- /* cellspacing="0.5" is used in dot data, parse fp number */
- int dphl_chk_cellspacing(char *str, int mode)
- {
- int ival = 0;
- double dval = 0.0;
- int pe = 0;
- int es = 0;
- int err = 0;
- struct dpnum *num = NULL;
- if (*str == '-') {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for cellspacing in html string at line %d\n",
- __func__, str, hllineno);
- return (1);
- }
- num = dp_getnum(str);
- dval = num->number;
- pe = num->pe;
- es = num->es;
- num = (struct dpnum *)dp_free((void *)num);
- if (num) {
- }
- if (es) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for cellspacing in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- if (pe) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for cellspacing in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- if (dval < 0) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for cellspacing in html string at line %d\n",
- __func__, str, hllineno);
- return (1);
- }
- if (dval > INT_MAX) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): too high value `%s' for cellspacing in html string at line %d\n",
- __func__, str, hllineno);
- return (1);
- }
- dval = round(dval);
- ival = (int)dval;
- if (ival > 127) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): too high value `%s' for cellspacing (max is 127) in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- /* ival is the spacing */
- /* size 0 is allowed */
- if (mode == T_TD) {
- /* <td> cellspacing */
- if (curtd->cellspacing == -1) {
- curtd->cellspacing = ival;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> cellspacing */
- if (curtable->cellspacing == -1) {
- curtable->cellspacing = ival;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for cellspacing in html string at line %d\n",
- __func__, str, hllineno);
- return (1);
- }
- return (0);
- }
- /* check color value */
- int dphl_chk_color(char *str, int mode)
- {
- struct dpcolor *c = NULL;
- int pe = 0;
- int es = 0;
- int il = 0;
- int rgb = 0;
- int err = 0;
- /* get color without colorscheme number */
- c = dp_getcolor(0, 0, str);
- pe = c->pe;
- es = c->es;
- il = c->islist;
- rgb = c->color;
- c = (struct dpcolor *)dp_free((void *)c);
- if (c) {
- }
- if (es) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for color in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- if (pe) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for color in html string at line %d\n", __func__, str, hllineno);
- return (1);
- }
- if (il) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): color-list value `%s' for color in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- if (mode == T_TD) {
- /* <td> color */
- if (curtd->color == -1) {
- curtd->color = rgb;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> color */
- if (curtable->color == -1) {
- curtable->color = rgb;
- } else {
- err = 1;
- }
- } else if (mode == T_FONT) {
- /* <font> color */
- if (curfont->color == -1) {
- curfont->color = rgb;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for color in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- return (0);
- }
- /* check columns value in <table> */
- int dphl_chk_columns(char *str)
- {
- /* only '*' is allowed */
- if (strlen(str) != 1) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for columns in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- if (*str != '*') {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for columns in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- /* <table> columns */
- if (curtable->columns == NULL) {
- curtable->columns = str;
- } else {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for columns in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- return (0);
- }
- /* check colspan value in <td> */
- int dphl_chk_colspan(char *str)
- {
- int n = 0;
- int ival = 0;
- int pe = 0;
- int es = 0;
- struct dpinum *num = NULL;
- if (*str == '-') {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for colspan in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- num = dp_getinum(str);
- n = num->number;
- pe = num->pe;
- es = num->es;
- num = (struct dpinum *)dp_free((void *)num);
- if (num) {
- }
- if (es) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for colspan in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- if (pe) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for colspan in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- ival = n;
- if (ival < 0) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for colspan in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- if (ival == 0) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): zero value `%s' for colspan in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- if (ival > 65535) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): too high value `%s' for colspan (max is 65535) in html string at line %d\n", __func__, str, hllineno);
- return (1);
- }
- /* ival is the size */
- /* size 0 is not allowed */
- /* <td> colspan */
- if (curtd->colspan == -1) {
- curtd->colspan = ival;
- } else {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for colspan in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- /* todo */
- if (curtd->colspan > 1) {
- printf("%s(): colspan=%d is not yet implemented in this version\n", __func__, curtd->colspan);
- }
- return (0);
- }
- /* check face value for font - the fontname */
- int dphl_chk_face(char *str)
- {
- if (strlen(str) == 0) {
- /* "" is same as not specified */
- return (0);
- }
- /* <font> face */
- if (curfont->face == NULL) {
- curfont->face = str;
- } else {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for font face in html string\n", __func__, str);
- return (1);
- }
- return (0);
- }
- /* check fixedsize value */
- int dphl_chk_fixedsize(char *str, int mode)
- {
- int val = 0;
- int err = 0;
- if (strlen(str) == 0) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for fixedsize in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- if (strcasecmp(str, "true") == 0) {
- val = DP_TRUE;
- } else if (strcasecmp(str, "false") == 0) {
- val = DP_FALSE;
- } else {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): bad value `%s' for fixedsize instead of true/false in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- if (mode == T_TD) {
- /* <td> fixedsize */
- if (curtd->fixedsize == -1) {
- curtd->fixedsize = val;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> fixedsize */
- if (curtable->fixedsize == -1) {
- curtable->fixedsize = val;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): multiple value `%s' for fixedsize in html string at line %d\n", __func__, str, hllineno);
- return (1);
- }
- return (0);
- }
- /* check gradientangle value */
- int dphl_chk_gradientangle(char *str, int mode)
- {
- int n = 0;
- int ival = 0;
- int pe = 0;
- int es = 0;
- int err = 0;
- struct dpinum *num = NULL;
- if (*str == '-') {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for gradientangle in html string at line %d\n",
- __func__, str, hllineno);
- return (1);
- }
- num = dp_getinum(str);
- n = num->number;
- pe = num->pe;
- es = num->es;
- num = (struct dpinum *)dp_free((void *)num);
- if (num) {
- }
- if (es) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for gradientangle in html string at line %d\n",
- __func__, str, hllineno);
- return (1);
- }
- if (pe) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for gradientangle in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- ival = n;
- if (ival < 0) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for gradientangle in html string at line %d\n",
- __func__, str, hllineno);
- return (1);
- }
- if (ival > 360) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): value `%s' for gradientangle is > 360 degrees in html string at line %d\n", __func__, str, hllineno);
- return (1);
- }
- /* ival is the size */
- /* size 0 is allowed ... 360 */
- if (mode == T_TD) {
- /* <td> gradientangle */
- if (curtd->gradientangle == -1) {
- curtd->gradientangle = ival;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> gradientangle */
- if (curtable->gradientangle == -1) {
- curtable->gradientangle = ival;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for gradientangle in html string at line %d\n",
- __func__, str, hllineno);
- return (1);
- }
- return (0);
- }
- /* check height value */
- int dphl_chk_height(char *str, int mode)
- {
- int n = 0;
- int ival = 0;
- int pe = 0;
- int es = 0;
- int err = 0;
- struct dpinum *num = NULL;
- if (*str == '-') {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for height in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- num = dp_getinum(str);
- n = num->number;
- pe = num->pe;
- es = num->es;
- num = (struct dpinum *)dp_free((void *)num);
- if (num) {
- }
- if (es) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for height in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- if (pe) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for height in html string at line %d\n", __func__, str, hllineno);
- return (1);
- }
- ival = n;
- if (ival < 0) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for height in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- if (ival > 65535) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): too high value `%s' for height (max is 65535) in html string at line %d\n", __func__, str, hllineno);
- return (1);
- }
- /* ival is the size */
- /* size 0 is allowed */
- if (mode == T_TD) {
- /* <td> height */
- if (curtd->height == -1) {
- curtd->height = ival;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> height */
- if (curtable->height == -1) {
- curtable->height = ival;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for height in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- return (0);
- }
- /* check href value */
- int dphl_chk_href(char *str, int mode)
- {
- int err = 0;
- if (strlen(str) == 0) {
- /* href="" is oke */
- return (0);
- }
- /* twice href is not allowed */
- if (mode == T_TD) {
- /* <td> href */
- if (curtd->href == NULL) {
- curtd->href = str;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> href */
- if (curtable->href == NULL) {
- curtable->href = str;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for href in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- return (0);
- }
- /* check id value */
- int dphl_chk_id(char *str, int mode)
- {
- int err = 0;
- if (strlen(str) == 0) {
- /* id="" is oke */
- return (0);
- }
- /* twice id is not allowed */
- if (mode == T_TD) {
- /* <td> id */
- if (curtd->id == NULL) {
- curtd->id = str;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> id */
- if (curtable->id == NULL) {
- curtable->id = str;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for id in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- return (0);
- }
- /* check port value */
- int dphl_chk_port(char *str, int mode)
- {
- int err = 0;
- if (strlen(str) == 0) {
- /* port="" is oke */
- return (0);
- }
- /* twice port is not allowed */
- /* check portname and compass point here todo */
- if (mode == T_TD) {
- /* <td> port */
- if (curtd->port == NULL) {
- curtd->port = str;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> port */
- if (curtable->port == NULL) {
- curtable->port = str;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for port in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- return (0);
- }
- /* check point-size value for font */
- int dphl_chk_pointsize(char *str)
- {
- int ival = 0;
- int pe = 0;
- int es = 0;
- double dnum = 0.0;
- struct dpnum *num = NULL;
- if (*str == '-') {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for point-size in html string\n", __func__, str);
- return (1);
- }
- num = dp_getnum(str);
- dnum = num->number;
- pe = num->pe;
- es = num->es;
- num = (struct dpnum *)dp_free((void *)num);
- if (num) {
- }
- if (es) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for point-size in html string\n", __func__, str);
- return (1);
- }
- if (pe) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for point-size in html string\n", __func__, str);
- return (1);
- }
- if (dnum < 0) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for point-size in html string\n", __func__, str);
- return (1);
- }
- if (dnum > 255) {
- printf("%s(): limiting too high pointsize %f to 255\n", __func__, dnum);
- dnum = 255;
- }
- ival = (int)dnum;
- /* ival is the font pointsize */
- /* pointsize 0 is allowed */
- /* <font> point-size */
- if (curfont->pointsize == -1) {
- curfont->pointsize = ival;
- } else {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for point-size in html string\n", __func__, str);
- return (1);
- }
- return (0);
- }
- /* check rows value in <table> */
- int dphl_chk_rows(char *str)
- {
- /* only a single '*' is allowed */
- if (strlen(str) != 1) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for rows in html string at line %d\n", __func__, str, hllineno);
- return (1);
- }
- if (*str != '*') {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for rows in html string at line %d\n", __func__, str, hllineno);
- return (1);
- }
- if (curtable->rows == NULL) {
- curtable->rows = str;
- } else {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for rows in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- return (0);
- }
- /* check rowspan value in <td> */
- int dphl_chk_rowspan(char *str)
- {
- int n = 0;
- int ival = 0;
- int pe = 0;
- int es = 0;
- struct dpinum *num = NULL;
- if (*str == '-') {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for rowspan in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- num = dp_getinum(str);
- n = num->number;
- pe = num->pe;
- es = num->es;
- num = (struct dpinum *)dp_free((void *)num);
- if (num) {
- }
- if (es) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for rowspan in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- if (pe) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for rowspan in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- ival = n;
- if (ival < 0) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for rowspan in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- if (ival == 0) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): zero value `%s' for rowspan in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- if (ival > 65535) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): too high value `%s' for rowspan (max is 65535) in html string at line %d\n", __func__, str, hllineno);
- return (1);
- }
- /* ival is the size */
- /* size 0 is not allowed */
- /* <td> rowspan */
- if (curtd->rowspan == -1) {
- curtd->rowspan = ival;
- } else {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for rowspan in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- /* todo */
- if (curtd->rowspan > 1) {
- printf("%s(): rowspan=%d is not yet implemented in this version\n", __func__, curtd->rowspan);
- }
- return (0);
- }
- /* check scale value for img */
- int dphl_chk_scale(char *str)
- {
- int status = 0;
- int val = 0;
- if (strcasecmp(str, "false") == 0) {
- val = DP_IMGF;
- } else if (strcasecmp(str, "true") == 0) {
- val = DP_IMGT;
- } else if (strcasecmp(str, "width") == 0) {
- val = DP_IMGW;
- } else if (strcasecmp(str, "height") == 0) {
- val = DP_IMGH;
- } else if (strcasecmp(str, "both") == 0) {
- val = DP_IMGB;
- } else {
- status = 1;
- }
- /* check error status */
- if (status) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): unknown value `%s' for img scale in html string\n", __func__, str);
- return (1);
- }
- /* <img> scale */
- if (curimg->scale == -1) {
- curimg->scale = val;
- } else {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): unknown value `%s' for img scale in html string\n", __func__, str);
- return (1);
- }
- return (0);
- }
- /* check sides value */
- int dphl_chk_sides(char *str, int mode)
- {
- int err = 0;
- char *p = NULL;
- if (strlen(str) == 0) {
- /* sides="" is oke */
- return (0);
- }
- /* twice sides is not allowed */
- /* check sides letters ltrb in string */
- p = str;
- err = 0;
- while (*p) {
- if (*p == 'l' || *p == 't' || *p == 'r' || *p == 'b' || *p == 'L' || *p == 'T' || *p == 'R' || *p == 'B') {
- /* oke */
- } else {
- err = 1;
- break;
- }
- p++;
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for sides in html string at line %d\n", __func__, str, hllineno);
- return (1);
- }
- if (mode == T_TD) {
- /* <td> sides */
- if (curtd->sides == NULL) {
- curtd->sides = str;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> sides */
- if (curtable->sides == NULL) {
- curtable->sides = str;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for sides in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- return (0);
- }
- /* check src value for img */
- int dphl_chk_src(char *str)
- {
- /* there must be something set as image source */
- if (strlen(str) == 0) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for img src in html string\n", __func__, str);
- return (1);
- }
- /* <img> src */
- if (curimg->src == NULL) {
- curimg->src = str;
- } else {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for img src in html string\n", __func__, str);
- return (1);
- }
- return (0);
- }
- /* check style value
- * dot uses strtok() at multiple places and that has a problem
- * that empty args are not detected, so a string like "invis,,,,," is valid
- * todo: solution can be own strtok() which returns "" at empty string
- * and then issue warning on a unusual string. see below.
- */
- int dphl_chk_style(char *str, int mode)
- {
- int rounded = 0;
- int radial = 0;
- int invis = 0;
- int dotted = 0;
- int dashed = 0;
- int err = 0;
- char *ptr = NULL;
- char *res = NULL;
- int once = 0;
- if (strlen(str) == 0) {
- /* style="" is oke */
- return (0);
- }
- /* twice style is not allowed */
- /* check style args in string todo */
- if (mode == T_TD) {
- /* <td> style */
- if (curtd->style == NULL) {
- curtd->style = str;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> style */
- if (curtable->style == NULL) {
- curtable->style = str;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for style in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- /* check style string */
- if (strlen(str)) {
- err = 0;
- ptr = (char *)dp_calloc(1, strlen(str) + 1);
- strcat(ptr, str);
- /* this does not detect strings like " ,,,,," */
- once = 0;
- /* strsep() is replacement for old strtok() todo */
- res = strtok(ptr, " ,");
- while (res) {
- once = 1;
- if (strcasecmp(res, "rounded") == 0) {
- rounded = 1;
- } else if (strcasecmp(res, "radial") == 0) {
- radial = 1;
- } else if (strcasecmp(res, "solid") == 0) {
- dotted = 1;
- dashed = 1;
- } else if (strcasecmp(res, "invis") == 0) {
- invis = 1;
- } else if (strcasecmp(res, "invisible") == 0) {
- invis = 1;
- } else if (strcasecmp(res, "dotted") == 0) {
- dotted = 1;
- } else if (strcasecmp(res, "dashed") == 0) {
- dashed = 1;
- } else {
- err = 1;
- }
- res = strtok(NULL, " ,");
- }
- ptr = (char *)dp_free((void *)ptr);
- if (ptr) {
- }
- if (once == 0) {
- /* strtok did not detect valid tokens as in a string like ",, ,," */
- err = 1;
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for style in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- }
- /* set the options */
- if (mode == T_TD) {
- curtd->stylerounded = rounded; /* style options */
- curtd->styleradial = radial; /* style options */
- curtd->styleinvis = invis; /* style options */
- curtd->styledotted = dotted; /* style options */
- curtd->styledashed = dashed; /* style options */
- } else if (mode == T_TABLE) {
- curtable->stylerounded = rounded; /* style options */
- curtable->styleradial = radial; /* style options */
- curtable->styleinvis = invis; /* style options */
- curtable->styledotted = dotted; /* style options */
- curtable->styledashed = dashed; /* style options */
- } else {
- /* shouldnothappen */
- }
- return (0);
- }
- /* check target value */
- int dphl_chk_target(char *str, int mode)
- {
- int err = 0;
- if (strlen(str) == 0) {
- /* target="" is oke */
- return (0);
- }
- /* twice target is not allowed */
- /* check target args in string todo */
- if (mode == T_TD) {
- /* <td> target */
- if (curtd->target == NULL) {
- curtd->target = str;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> target */
- if (curtable->target == NULL) {
- curtable->target = str;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for target in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- return (0);
- }
- /* check title value */
- int dphl_chk_title(char *str, int mode)
- {
- int err = 0;
- if (strlen(str) == 0) {
- /* title="" is oke */
- return (0);
- }
- /* twice title is not allowed */
- if (mode == T_TD) {
- /* <td> title or tooltip */
- if (curtd->title == NULL) {
- curtd->title = str;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> title or tooltip */
- if (curtable->title == NULL) {
- curtable->title = str;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for title in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- return (0);
- }
- /* check valign value */
- int dphl_chk_valign(char *str, int mode)
- {
- int status = 0;
- int val = 0;
- int err = 0;
- if (strcasecmp(str, "middle") == 0) {
- val = DP_VALIGNM;
- } else if (strcasecmp(str, "bottom") == 0) {
- val = DP_VALIGNB;
- } else if (strcasecmp(str, "top") == 0) {
- val = DP_VALIGNT;
- } else {
- status = 1;
- }
- /* check error status */
- if (status) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): unknown value `%s' for valign in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- /* twice valign is not allowed */
- if (mode == T_TD) {
- /* <td> valign */
- if (curtd->valign == -1) {
- curtd->valign = val;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> valign */
- if (curtable->valign == -1) {
- curtable->valign = val;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for valign in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- return (0);
- }
- /* check width value */
- int dphl_chk_width(char *str, int mode)
- {
- int n = 0;
- int ival = 0;
- int pe = 0;
- int es = 0;
- int err = 0;
- struct dpinum *num = NULL;
- if (*str == '-') {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for width in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- num = dp_getinum(str);
- n = num->number;
- pe = num->pe;
- es = num->es;
- num = (struct dpinum *)dp_free((void *)num);
- if (num) {
- }
- if (es) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): empty value `%s' for width in html string at line %d\n", __func__, str,
- hllineno);
- return (1);
- }
- if (pe) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): bad value `%s' for width in html string at line %d\n", __func__, str, hllineno);
- return (1);
- }
- ival = n;
- if (ival < 0) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): negative value `%s' for width in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- if (ival > 65535) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1),
- "html %s(): too high value `%s' for width (max is 65535) in html string at line %d\n", __func__, str, hllineno);
- return (1);
- }
- /* ival is the size */
- /* size 0 is allowed */
- if (mode == T_TD) {
- /* <td> width */
- if (curtd->width == -1) {
- curtd->width = ival;
- } else {
- err = 1;
- }
- } else if (mode == T_TABLE) {
- /* <table> width */
- if (curtable->width == -1) {
- curtable->width = ival;
- } else {
- err = 1;
- }
- } else {
- /* shouldnothappen */
- }
- if (err) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): multiple value `%s' for width in html string at line %d\n", __func__,
- str, hllineno);
- return (1);
- }
- return (0);
- }
- /* reset <br> newline */
- void dphl_rbr(void)
- {
- if (curbr) {
- curbr = (struct brdata *)dp_free((void *)curbr);
- if (curbr) {
- }
- }
- curbr = (struct brdata *)dp_calloc(1, sizeof(struct brdata));
- curbr->align = (-1); /* ="center|left|right" */
- return;
- }
- /* end <br> newline */
- void dphl_ebr(void)
- {
- if (hlinf == NULL) {
- /* shouldnothappen */
- return;
- }
- /* only at first data token
- * or at <br>
- */
- if (hlinf->mode < 0) {
- /* check for <table> token */
- if (curtable == NULL) {
- /* mode=items */
- hlinf->mode = 0;
- } else {
- /* mode=tables */
- hlinf->mode = 1;
- /* shouldnothappen */
- }
- }
- /* add <br> */
- if (hlinf->mode) {
- /* add <br> to tables */
- dphl_itemtables(NULL, NULL, 1);
- } else {
- /* add <br> to items */
- dphl_itemitems(NULL, NULL, 1);
- }
- return;
- }
- /* reset <i> italic text */
- void dphl_ri(void)
- {
- curi++;
- return;
- }
- /* end </i> */
- void dphl_ei(void)
- {
- if (curi) {
- curi--;
- }
- return;
- }
- /* reset <b> bold text */
- void dphl_rb(void)
- {
- curb++;
- return;
- }
- /* end </b> */
- void dphl_eb(void)
- {
- if (curb) {
- curb--;
- }
- return;
- }
- /* reset <u> underline text */
- void dphl_ru(void)
- {
- curu++;
- return;
- }
- /* end </u> */
- void dphl_eu(void)
- {
- if (curu) {
- curu--;
- }
- return;
- }
- /* reset <o> overline text */
- void dphl_ro(void)
- {
- curo++;
- return;
- }
- /* end </o> */
- void dphl_eo(void)
- {
- if (curo) {
- curo--;
- }
- return;
- }
- /* reset <sub> subscript text */
- void dphl_rsub(void)
- {
- cursub++;
- if (cursup) {
- printf("html %s(): turning superscript <sup> off because of subscript <sub> tag in html string at line %d\n",
- __func__, hllineno);
- }
- /* force superscript off */
- cursup = 0;
- return;
- }
- /* end </sub> */
- void dphl_esub(void)
- {
- if (cursub) {
- cursub--;
- }
- return;
- }
- /* reset <sup> superscript text */
- void dphl_rsup(void)
- {
- cursup++;
- if (cursub) {
- printf("html %s(): turning subscript <sub> off because of superscript <sup> tag in html string at line %d\n",
- __func__, hllineno);
- }
- /* force subscript off */
- cursub = 0;
- return;
- }
- /* end </sup> */
- void dphl_esup(void)
- {
- if (cursup) {
- cursup--;
- }
- return;
- }
- /* reset <s> strike-through text */
- void dphl_rs(void)
- {
- curs++;
- return;
- }
- /* end </s> */
- void dphl_es(void)
- {
- if (curs) {
- curs--;
- }
- return;
- }
- /* reset <vr/> vertical-ruler */
- void dphl_rvr(void)
- {
- /* set token <vr> is opt 3 */
- dphl_itemtables(NULL, NULL, 3);
- return;
- }
- /* reset <hr/> horizontal-ruler */
- void dphl_rhr(void)
- {
- /* set token <hr> is opt 2 */
- dphl_itemtables(NULL, NULL, 2);
- return;
- }
- /* reset <img> image-data */
- void dphl_rimg(void)
- {
- if (curimg) {
- curimg = (struct imgdata *)dp_free((void *)curimg);
- if (curimg) {
- }
- }
- curimg = (struct imgdata *)dp_calloc(1, sizeof(struct imgdata));
- curimg->scale = (-1); /* ="false|true|width|height|both" */
- curimg->src = NULL; /* ="imagename" */
- return;
- }
- /* end <img>
- * there should be a image source be set now.
- */
- void dphl_eimg(void)
- {
- if (curimg == NULL) {
- /* shouldnothappen */
- return;
- }
- if (curimg->src == NULL) {
- memset(dp_errmsg, 0, 256);
- snprintf(dp_errmsg, (256 - 1), "html %s(): no image name set in src in <img> tag in html string at line %d\n",
- __func__, hllineno);
- } else {
- /* ignore src="" as image name */
- if (strlen(curimg->src) != 0) {
- /* set token <img> is opt 4 */
- dphl_itemtables(NULL, NULL, 4);
- }
- }
- curimg = (struct imgdata *)dp_free((void *)curimg);
- if (curimg) {
- }
- return;
- }
- /* font on stack */
- static void dphl_pushfont(void)
- {
- splay_tree_node spn = NULL;
- int val = 0;
- /* data for <font> */
- if (fontstack == NULL) {
- fontstack = splay_tree_new(splay_tree_compare_ints, NULL, NULL);
- if (fontstack == NULL) {
- return;
- }
- }
- if (splay_tree_has_data(fontstack) == 0) {
- /* first entry */
- splay_tree_insert(fontstack, (splay_tree_key) 0, (splay_tree_value) curfont);
- return;
- }
- spn = splay_tree_max(fontstack);
- /* current highest */
- val = (int)spn->key;
- /* incr. index in stack */
- val++;
- /* next entry */
- splay_tree_insert(fontstack, (splay_tree_key) val, (splay_tree_value) curfont);
- return;
- }
- /* font off stack */
- static void dphl_pullfont(void)
- {
- splay_tree_node spn = NULL;
- int val = 0;
- /* data for <font> */
- if (fontstack == NULL) {
- curfont = NULL;
- return;
- }
- if (splay_tree_has_data(fontstack) == 0) {
- /* no data in tree */
- fontstack = splay_tree_delete(fontstack);
- curfont = NULL;
- return;
- }
- spn = splay_tree_max(fontstack);
- /* current highest */
- val = (int)spn->key;
- /* restore highest fontdata */
- curfont = (struct fontdata *)spn->value;
- /* delete highest entry */
- splay_tree_remove(fontstack, (splay_tree_key) val);
- return;
- }
- /* reset <font> */
- void dphl_rfont(void)
- {
- struct fontdata *curfont2 = NULL;
- struct fontldata *curfontl = NULL;
- curfontl = (struct fontldata *)dp_calloc(1, sizeof(struct fontldata));
- /* fresh table data */
- curfont2 = (struct fontdata *)dp_calloc(1, sizeof(struct fontdata));
- curfontl->fd = curfont2;
- /* preset <font> */
- curfont2->color = (-1); /* ="colorname" */
- curfont2->face = NULL; /* ="fontname" */
- curfont2->pointsize = (-1); /* ="int-number" */
- /* link in curfont */
- if (fontlist == NULL) {
- fontlist = curfontl;
- fontlistend = curfontl;
- } else {
- fontlistend->next = curfontl;
- fontlistend = curfontl;
- }
- /* push old curfont if any */
- if (curfont) {
- dphl_pushfont();
- }
- curfont = curfont2;
- return;
- }
- /* end <font> */
- void dphl_efont(void)
- {
- /* pull font */
- dphl_pullfont();
- return;
- }
- /* table on stack */
- static void dphl_pushtable(void)
- {
- splay_tree_node spn = NULL;
- int val = 0;
- /* data for <table> */
- if (tablestack == NULL) {
- tablestack = splay_tree_new(splay_tree_compare_ints, NULL, NULL);
- if (tablestack == NULL) {
- return;
- }
- }
- if (splay_tree_has_data(tablestack) == 0) {
- /* first entry */
- splay_tree_insert(tablestack, (splay_tree_key) 0, (splay_tree_value) curtable);
- return;
- }
- spn = splay_tree_max(tablestack);
- /* current highest */
- val = (int)spn->key;
- /* incr. index in stack */
- val++;
- /* next entry */
- splay_tree_insert(tablestack, (splay_tree_key) val, (splay_tree_value) curtable);
- return;
- }
- /* table off stack */
- static void dphl_pulltable(void)
- {
- splay_tree_node spn = NULL;
- int val = 0;
- /* data for <table> */
- if (tablestack == NULL) {
- curtable = NULL;
- return;
- }
- if (splay_tree_has_data(tablestack) == 0) {
- /* no data in tree */
- tablestack = splay_tree_delete(tablestack);
- curtable = NULL;
- return;
- }
- spn = splay_tree_max(tablestack);
- /* current highest */
- val = (int)spn->key;
- /* restore highest tabledata */
- curtable = (struct tabledata *)spn->value;
- /* delete highest entry */
- splay_tree_remove(tablestack, (splay_tree_key) val);
- return;
- }
- /* at new <table> to current <td> */
- static void dphl_addtableitem(struct tabledata *newtable)
- {
- struct ilist *il = NULL;
- if (yydebug || 0) {
- printf("%s(): setting new <table> in current <td> items\n", __func__);
- }
- /* if opt is set it is br=1, hr=2, vr=3, img=4, table=5 */
- if (hlinf == NULL) {
- /* shouldnothappen */
- return;
- }
- if (hlinf->mode == 0) {
- /* shouldnothappen */
- return;
- }
- if (curtable == NULL) {
- /* shouldnothappen */
- printf("%s(): nil curtable\n", __func__);
- return;
- }
- if (curtd == NULL) {
- /* shouldnothappen */
- printf("%s(): nil curtd\n", __func__);
- return;
- }
- if (curtr == NULL) {
- /* shouldnothappen */
- printf("%s(): nil curtr\n", __func__);
- return;
- }
- il = (struct ilist *)dp_calloc(1, sizeof(struct ilist));
- /* set linkage to data */
- il->items = dphl_makeitem( /* str */ NULL, /* alt */ NULL, /* opt */ 5, newtable);
- /* <td> belongs to this <table> */
- curtd->table = curtable;
- /* indicate in <td> this is a <table> */
- curtd->istab = 1;
- /* indicate in <tr> there is a <td> with a <table> statement */
- curtr->hastab = 1;
- if (curtd->il == NULL) {
- curtd->il = il;
- curtd->ilend = il;
- } else {
- curtd->ilend->next = il;
- curtd->ilend = il;
- }
- return;
- }
- /* reset <table> at start */
- void dphl_rtable(void)
- {
- struct tlist *tli = NULL; /* list of table items */
- struct tabledata *curtable2 = NULL;
- struct tableldata *curtablel = NULL;
- if (hlinf->mode < 1) {
- /* mode=tables */
- hlinf->mode = 1;
- if (hlinf->il) {
- /* todo, clear no il and ilend items */
- printf("%s(): switch to <table> mode and hlinf->il=%p to clear\n", __func__, (void *)hlinf->il);
- }
- }
- curtablel = (struct tableldata *)dp_calloc(1, sizeof(struct tableldata));
- tli = (struct tlist *)dp_calloc(1, sizeof(struct tlist));
- /* fresh table data */
- curtable2 = (struct tabledata *)dp_calloc(1, sizeof(struct tabledata));
- curtablel->tabdata = curtable2;
- /* set as table item */
- tli->titem = curtablel;
- /* preset <table> */
- curtable2->align = (-1); /* ="center|left|right" */
- if (curtable) {
- curtable2->bgcolor = curtable->bgcolor; /* ="colorname" */
- } else {
- curtable2->bgcolor = (-1); /* ="colorname" */
- }
- if (curtd) {
- curtable2->bgcolor = curtd->bgcolor; /* ="colorname" */
- } else {
- curtable2->bgcolor = (-1); /* ="colorname" */
- }
- curtable2->border = (-1); /* ="int-value" */
- curtable2->cellborder = (-1); /* ="int-value" */
- curtable2->cellpadding = (-1); /* ="int-value" */
- curtable2->cellspacing = (-1); /* ="int-value" */
- /* todo see above for fontcolor */
- curtable2->color = (-1); /* ="colorname" */
- curtable2->columns = NULL; /* ="string" */
- curtable2->fixedsize = (-1); /* ="true|false" */
- curtable2->gradientangle = (-1); /* ="int-value" */
- curtable2->height = (-1); /* ="int-value" */
- curtable2->href = NULL; /* ="string" */
- curtable2->id = NULL; /* ="string" */
- curtable2->port = NULL; /* ="string" */
- curtable2->rows = NULL; /* ="string" */
- curtable2->sides = NULL; /* ="string" */
- curtable2->style = NULL; /* ="string" */
- curtable2->stylerounded = (-1); /* style options */
- curtable2->styleradial = (-1); /* style options */
- curtable2->styleinvis = (-1); /* style options */
- curtable2->styledotted = (-1); /* style options */
- curtable2->styledashed = (-1); /* style options */
- curtable2->target = NULL; /* ="string" */
- curtable2->title = NULL; /* ="string" */
- curtable2->valign = (-1); /* ="middle|bottom|top" */
- curtable2->width = (-1); /* ="int-value" */
- curtable2->table = curtable; /* rooted on this table or 0 */
- /* not at first <table> entry */
- if (curtd) {
- dphl_addtableitem(curtable2);
- }
- /* push old curtable if any */
- if (curtable) {
- dphl_pushtable();
- }
- /* first entry if 0 */
- if (curtable == NULL) {
- /* add to main hlinf */
- if (hlinf->tl == NULL) {
- hlinf->tl = tli;
- hlinf->tlend = tli;
- } else {
- hlinf->tlend->next = tli;
- hlinf->tlend = tli;
- }
- } else {
- if (yydebug || 0) {
- printf("%s(): add to sub %p ", __func__, (void *)tli);
- }
- /* add as sub table entry */
- if (curtable->tl == NULL) {
- curtable->tl = tli;
- curtable->tlend = tli;
- } else {
- curtable->tlend->next = tli;
- curtable->tlend = tli;
- }
- }
- if (yydebug || 0) {
- printf("hlinf->tl=%p\n table from %p to %p", (void *)hlinf->tl, (void *)curtable, (void *)curtable2);
- }
- curtable = curtable2;
- return;
- }
- /* end <table> */
- void dphl_etable(void)
- {
- /* pull curtable if any */
- dphl_pulltable();
- return;
- }
- /* td on stack */
- static void dphl_pushtd(void)
- {
- splay_tree_node spn = NULL;
- int val = 0;
- /* data for <td> */
- if (tdstack == NULL) {
- tdstack = splay_tree_new(splay_tree_compare_ints, NULL, NULL);
- if (tdstack == NULL) {
- return;
- }
- }
- if (splay_tree_has_data(tdstack) == 0) {
- /* first entry */
- splay_tree_insert(tdstack, (splay_tree_key) 0, (splay_tree_value) curtd);
- return;
- }
- spn = splay_tree_max(tdstack);
- /* current highest */
- val = (int)spn->key;
- /* incr. index in stack */
- val++;
- /* next entry */
- splay_tree_insert(tdstack, (splay_tree_key) val, (splay_tree_value) curtd);
- return;
- }
- /* td off stack */
- static void dphl_pulltd(void)
- {
- splay_tree_node spn = NULL;
- int val = 0;
- /* data for <td> */
- if (tdstack == NULL) {
- curtd = NULL;
- return;
- }
- if (splay_tree_has_data(tdstack) == 0) {
- /* no data in tree */
- tdstack = splay_tree_delete(tdstack);
- curtd = NULL;
- return;
- }
- spn = splay_tree_max(tdstack);
- /* current highest */
- val = (int)spn->key;
- /* restore highest tddata */
- curtd = (struct tddata *)spn->value;
- /* delete highest entry */
- splay_tree_remove(tdstack, (splay_tree_key) val);
- return;
- }
- /* reset <td> table data */
- void dphl_rtd(void)
- {
- struct tddata *curtd2 = NULL;
- struct tdldata *curtdl = NULL;
- if (curtr == NULL) {
- /* shouldnothappen */
- printf("%s(): nil tr\n", __func__);
- return;
- }
- curtdl = (struct tdldata *)dp_calloc(1, sizeof(struct tdldata));
- /* fresh table data */
- curtd2 = (struct tddata *)dp_calloc(1, sizeof(struct tddata));
- /* push old curtd if any */
- if (curtd) {
- dphl_pushtd();
- }
- /* preset <td> */
- curtd2->align = (-1); /* ="center|left|right|text" */
- curtd2->balign = (-1); /* ="center|left|right" */
- curtd2->bgcolor = (-1); /* ="colorname" */
- curtd2->border = (-1); /* ="int-value" */
- curtd2->cellpadding = (-1); /* ="int-value" */
- curtd2->cellspacing = (-1); /* ="int-value" */
- curtd2->color = (-1); /* ="colorname" */
- curtd2->colspan = (-1); /* ="int-value" */
- curtd2->fixedsize = (-1); /* ="true|false" */
- curtd2->gradientangle = (-1); /* ="int-value" */
- curtd2->height = (-1); /* ="int-value" */
- curtd2->href = NULL; /* ="string" */
- curtd2->id = NULL; /* ="string" */
- curtd2->port = NULL; /* ="string" */
- curtd2->rowspan = (-1); /* ="int-value" */
- curtd2->sides = NULL; /* ="string" */
- curtd2->style = NULL; /* ="string" */
- curtd2->stylerounded = (-1); /* style options */
- curtd2->styleradial = (-1); /* style options */
- curtd2->styleinvis = (-1); /* style options */
- curtd2->styledotted = (-1); /* style options */
- curtd2->styledashed = (-1); /* style options */
- curtd2->target = NULL; /* ="string" */
- curtd2->title = NULL; /* ="string" */
- curtd2->valign = (-1); /* ="middle|bottom|top" */
- curtd2->width = (-1); /* ="int-value" */
- curtd = curtd2;
- curtdl->tdd = curtd;
- if (curtr->td == NULL) {
- /* td items in tr */
- curtr->td = curtdl;
- curtr->tdend = curtdl;
- } else {
- curtr->tdend->next = curtdl;
- curtr->tdend = curtdl;
- }
- return;
- }
- /* end <td>
- * code is 0 for text item or new table data
- * code is 1 for image data
- * code is 2 for <tr><td></td></tr>
- */
- void dphl_etd(int code)
- {
- /* curdata has data, with curtd settings */
- if (code == 2) {
- /* this can indicate there is something wrong in generated grph data */
- printf("%s(): <td> with no items found\n", __func__);
- }
- /* pull curtd if any */
- dphl_pulltd();
- return;
- }
- /* tr on stack */
- static void dphl_pushtr(void)
- {
- splay_tree_node spn = NULL;
- int val = 0;
- /* data for <tr> */
- if (trstack == NULL) {
- trstack = splay_tree_new(splay_tree_compare_ints, NULL, NULL);
- }
- if (splay_tree_has_data(trstack) == 0) {
- /* first entry */
- splay_tree_insert(trstack, (splay_tree_key) 0, (splay_tree_value) curtr);
- return;
- }
- spn = splay_tree_max(trstack);
- /* current highest */
- val = (int)spn->key;
- /* incr. index in stack */
- val++;
- /* next entry */
- splay_tree_insert(trstack, (splay_tree_key) val, (splay_tree_value) curtr);
- return;
- }
- /* tr off stack */
- static void dphl_pulltr(void)
- {
- splay_tree_node spn = NULL;
- int val = 0;
- /* data for <tr> */
- if (trstack == NULL) {
- curtr = NULL;
- return;
- }
- if (splay_tree_has_data(trstack) == 0) {
- /* no data in tree */
- trstack = splay_tree_delete(trstack);
- curtr = NULL;
- return;
- }
- spn = splay_tree_max(trstack);
- /* current highest */
- val = (int)spn->key;
- /* restore highest trdata */
- curtr = (struct trdata *)spn->value;
- /* delete highest entry */
- splay_tree_remove(trstack, (splay_tree_key) val);
- return;
- }
- /* reset <tr> */
- void dphl_rtr(void)
- {
- struct trdata *tri = NULL;
- struct trlist *trl = NULL;
- if (curtable == NULL) {
- /* shouldnothappen */
- printf("%s(): nil curtable\n", __func__);
- return;
- }
- trl = (struct trlist *)dp_calloc(1, sizeof(struct trlist));
- tri = (struct trdata *)dp_calloc(1, sizeof(struct trdata));
- trl->tritem = tri;
- tri->table = curtable;
- if (curtable->tr == NULL) {
- curtable->tr = trl;
- curtable->trend = trl;
- } else {
- curtable->trend->next = trl;
- curtable->trend = trl;
- }
- if (curtr) {
- dphl_pushtr();
- }
- curtr = tri;
- return;
- }
- /* end </tr> */
- void dphl_etr(void)
- {
- /* pull curtr if any */
- dphl_pulltr();
- return;
- }
- /* gets data part */
- void dphl_data(char *str)
- {
- char *altstr = NULL;
- if (yydebug || 0) {
- printf("html %s(): data is \"%s\"\n", __func__, str);
- }
- if (str == NULL) {
- /* shouldnothappen */
- return;
- }
- /* translate html chars if any */
- if (strchr(str, '&')) {
- /* this can set error status */
- altstr = dplh_htrans(str);
- if (yydebug || 0) {
- printf("%s(): translated html char is \"%s\"\n", __func__, altstr);
- }
- if (dphl_chk_err()) {
- return;
- }
- }
- curdata = str;
- if (hlinf == NULL) {
- /* shouldnothappen */
- return;
- }
- /* only at first data token
- * or at <br>
- */
- if (hlinf->mode < 0) {
- /* check for <table> token */
- if (curtable == NULL) {
- /* mode=items */
- hlinf->mode = 0;
- } else {
- /* mode=tables */
- hlinf->mode = 1;
- }
- }
- /* add to items or tables */
- if (hlinf->mode == 0) {
- dphl_itemitems(str, altstr, 0);
- } else {
- dphl_itemtables(str, altstr, 0);
- }
- return;
- }
- /* free mem used by html label parsing, node hlinfo data is cleared later in dp_clearall() */
- void dphl_freemem(void)
- {
- struct fontldata *fptr = NULL;
- struct fontldata *fptrnext = NULL;
- /* data for <br> */
- if (curbr) {
- curbr = (struct brdata *)dp_free((void *)curbr);
- if (curbr) {
- }
- }
- /* data for <img> */
- if (curimg) {
- curimg = (struct imgdata *)dp_free((void *)curimg);
- if (curimg) {
- }
- }
- /* <table> data */
- if (tablestack) {
- tablestack = splay_tree_delete(tablestack);
- }
- /* <td> data */
- if (tdstack) {
- tdstack = splay_tree_delete(tdstack);
- }
- /* <tr> data */
- if (trstack) {
- trstack = splay_tree_delete(trstack);
- }
- /* <font> data */
- fptr = fontlist;
- while (fptr) {
- fptrnext = fptr->next;
- if (fptr->fd) {
- fptr->fd = (struct fontdata *)dp_free((void *)fptr->fd);
- if (fptr->fd) {
- }
- }
- fptr = (struct fontldata *)dp_free((void *)fptr);
- if (fptr) {
- }
- fptr = fptrnext;
- }
- fontlist = NULL;
- fontlistend = NULL;
- /* <font> data */
- if (fontstack) {
- fontstack = splay_tree_delete(fontstack);
- }
- /* data */
- curdata = NULL;
- /* <s> strike-through */
- curs = 0;
- /* <sup> superscript text */
- cursup = 0;
- /* <sub> subscript text */
- cursub = 0;
- /* <o> overline text */
- curo = 0;
- /* <u> underline text */
- curu = 0;
- /* <b> bold text */
- curb = 0;
- /* <i> italic text */
- curi = 0;
- return;
- }
- /* end */
|