FormatCCDF.c 135 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these librararies and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $TOG: FormatCCDF.c /main/23 1999/10/14 15:06:28 mgreess $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: FormatCCDF.c
  28. **
  29. ** Project: Unix Desktop Help
  30. **
  31. ** Description: This code formats an file in CCDF (Cache Creek
  32. ** Distribution Format) into internal format.
  33. **
  34. ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
  35. **
  36. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  37. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  38. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  39. ** (c) Copyright 1993, 1994 Novell, Inc.
  40. **
  41. **
  42. **
  43. ****************************************************************************
  44. ************************************<+>*************************************/
  45. /*
  46. * system includes
  47. */
  48. #include <ctype.h>
  49. #include <errno.h>
  50. #include <fcntl.h>
  51. #if defined(sun)
  52. #include <sys/utsname.h>
  53. #endif
  54. #include <limits.h>
  55. #include <string.h>
  56. #include <stdlib.h>
  57. #include <unistd.h>
  58. #include <stdio.h>
  59. #include <X11/Xlib.h>
  60. #include <X11/Xresource.h>
  61. #ifdef X_NOT_STDC_ENV
  62. extern int errno;
  63. #endif
  64. /*
  65. * Canvas Engine includes
  66. */
  67. #include "CanvasP.h"
  68. #include "CanvasSegP.h"
  69. #include "LinkMgrP.h"
  70. /*
  71. * private includes
  72. */
  73. #include "bufioI.h"
  74. #include "Access.h"
  75. #include "AccessI.h"
  76. #include "AccessP.h"
  77. #include "AccessCCDFI.h"
  78. #include "CanvasError.h"
  79. #include "CleanUpI.h"
  80. #include "CvStringI.h"
  81. #include "CvtToArrayP.h"
  82. #include "FontAttrI.h"
  83. #include "FormatUtilI.h"
  84. #include "FormatCCDFI.h"
  85. #include "CCDFUtilI.h"
  86. #include "HelpXlate.h"
  87. #include "StringFuncsI.h"
  88. extern char *_DtHelpGetLocale(void);
  89. #ifdef NLS16
  90. #endif
  91. /******************************************************************************
  92. * Private variables and defines.
  93. *****************************************************************************/
  94. #define BUFF_SIZE 1024
  95. #define GROW_SIZE 10
  96. #define INFO_GROW 256
  97. #define CCDF_LINK_JUMP_REUSE 0
  98. #define CCDF_LINK_JUMP_NEW 1
  99. #define CCDF_LINK_DEFINITION 2
  100. #define CCDF_LINK_EXECUTE 3
  101. #define CCDF_LINK_MAN_PAGE 4
  102. #define CCDF_LINK_APP_DEFINE 5
  103. #define IsTypeHyperText(x) (((x) & _DtCvHYPER_TEXT) ? 1 : 0)
  104. #define IsTypeNewLine(x) (((x) & _DtCvNEW_LINE) ? 1 : 0)
  105. #define NextAvailSeg(x) (NULL != x.list ? &(x.list[x.cnt]) : NULL)
  106. /******************************************************************************
  107. * Private structures
  108. ******************************************************************************/
  109. typedef struct _segList {
  110. int cnt;
  111. int max;
  112. _DtCvSegment *list;
  113. } SegList;
  114. typedef struct _formatVariables {
  115. int last_was_space;
  116. int last_was_mb;
  117. int last_was_nl;
  118. char *rd_buf;
  119. char *rd_ptr;
  120. char *fmt_buf;
  121. char *my_path;
  122. char *vol_name;
  123. char *topic_id;
  124. char *topic_char_set;
  125. char *topic_lang;
  126. int rd_size;
  127. int rd_flag;
  128. int topic_mb_max;
  129. int cur_mb_max;
  130. int fmt_buf_max;
  131. int fmt_size;
  132. int cell_cnt;
  133. BufFilePtr my_file;
  134. SegList my_list;
  135. _DtCvLinkDb my_links;
  136. _FrmtUiInfo *ui_info;
  137. } FormatVariables;
  138. enum _processState
  139. {
  140. NormalState,
  141. LabelBody
  142. };
  143. typedef enum _processState ProcessState;
  144. /******************************************************************************
  145. * Private Function Declarations
  146. ******************************************************************************/
  147. static _DtCvSegment *AllocateSegments(
  148. _DtCvSegment *p_seg,
  149. int original_size,
  150. int new_size );
  151. static int AppendCharToInfo(
  152. FormatVariables *cur_vars,
  153. char **src );
  154. static int AppendOctalToInfo(
  155. FormatVariables *cur_vars,
  156. char *src );
  157. static int AppendSpaceToInfo (
  158. FormatVariables *cur_vars,
  159. char **src,
  160. _DtCvFrmtOption type );
  161. static int AppendToInfo (
  162. FormatVariables *cur_vars,
  163. char **src,
  164. const char *scan_string );
  165. static int ChangeFont(
  166. int whichOne,
  167. unsigned long seg_flags,
  168. _DtCvFrmtOption frmt_type,
  169. _DtHelpFontHints *font_attr,
  170. int linkspec,
  171. FormatVariables *cur_vars,
  172. ProcessState cur_state,
  173. int flags,
  174. int ret_on_nl,
  175. int fnt_flag);
  176. static int CheckIdString(
  177. FormatVariables *cur_vars,
  178. ProcessState cur_state,
  179. unsigned long seg_flags,
  180. _DtCvFrmtOption frmt_type,
  181. _DtHelpFontHints *font_attr,
  182. int linkspec,
  183. int flags,
  184. int ret_on_nl,
  185. int fnt_flag);
  186. static int CheckSaveSegment (
  187. unsigned long seg_flags,
  188. _DtHelpFontHints *font_attr,
  189. int link_spec,
  190. FormatVariables *cur_vars );
  191. static int CreateSaveGraphic (
  192. FormatVariables *cur_vars,
  193. int type,
  194. char *file_name,
  195. int link_spec );
  196. static int CheckSegList (
  197. FormatVariables *cur_vars);
  198. static int Format(
  199. FormatVariables *cur_vars,
  200. _FrmtUiInfo *ui_info,
  201. char *id_string,
  202. _DtCvTopicPtr *ret_handle);
  203. static int GetNextBuffer (
  204. FormatVariables *cur_vars);
  205. static int GetStringParameter(
  206. FormatVariables *cur_vars,
  207. _DtCvValue flag,
  208. _DtCvValue eat_escape,
  209. _DtCvValue ignore_quotes,
  210. _DtCvValue less_test,
  211. char **ret_string );
  212. static int GetValueParameter(
  213. FormatVariables *cur_vars,
  214. _DtCvValue flag,
  215. int *ret_value );
  216. static int InitStructure(
  217. FormatVariables *cur_vars,
  218. _FrmtUiInfo *ui_info,
  219. char *rd_buf,
  220. int rd_size);
  221. static int Parse(
  222. int cur_cmd,
  223. ProcessState cur_state,
  224. FormatVariables *cur_vars,
  225. unsigned long seg_flags,
  226. _DtCvFrmtOption frmt_type,
  227. _DtHelpFontHints *font_attr,
  228. int linkspec,
  229. const char *scan_string,
  230. int allowed,
  231. int ret_on_nl,
  232. int fnt_flag);
  233. static int ProcessFigureCmd(
  234. FormatVariables *cur_vars,
  235. ProcessState cur_state,
  236. _DtCvFrmtOption frmt_type,
  237. _DtHelpFontHints *font_attr,
  238. int ret_on_nl,
  239. int fnt_flag);
  240. static int ProcessHypertext(
  241. FormatVariables *cur_vars,
  242. ProcessState cur_state,
  243. unsigned long seg_flags,
  244. _DtCvFrmtOption frmt_type,
  245. _DtHelpFontHints *font_attr,
  246. int flags,
  247. int ret_on_nl,
  248. int fnt_flag);
  249. static int ProcessInLine(
  250. FormatVariables *cur_vars,
  251. int seg_type,
  252. int link_spec );
  253. static int ProcessLabelCmd(
  254. FormatVariables *cur_vars,
  255. unsigned long seg_flags,
  256. _DtCvFrmtOption frmt_type,
  257. _DtHelpFontHints *font_attr,
  258. int link_spec,
  259. int flags,
  260. int ret_on_nl,
  261. int fnt_flag,
  262. _DtCvSegment **ret_list);
  263. static int ProcessParagraph (
  264. FormatVariables *cur_vars,
  265. ProcessState cur_state,
  266. int fnt_flag);
  267. static int SaveNewLine(
  268. FormatVariables *cur_vars,
  269. int cur_cmd,
  270. _DtHelpFontHints *font_attr,
  271. int link_spec );
  272. static int SaveStringAsSegments (
  273. FormatVariables *cur_vars,
  274. unsigned long seg_flags,
  275. _DtHelpFontHints *font_attr,
  276. int link_spec);
  277. static int SkipToNextToken (
  278. FormatVariables *cur_vars,
  279. _DtCvValue flag );
  280. static void TerminateSegList (
  281. SegList *list,
  282. int flag);
  283. static int SegmentSave(
  284. FormatVariables *cur_vars,
  285. unsigned long seg_type,
  286. _DtHelpFontHints *font_attr,
  287. char *string,
  288. int str_size,
  289. int num_chars,
  290. int link_spec);
  291. /******** End Public Function Declarations ********/
  292. /******************************************************************************
  293. * Private variables
  294. *****************************************************************************/
  295. static const char *Specials = "<\n\\ ";
  296. static const char *SpaceString = " ";
  297. static const char *CString = "C";
  298. static const char *Period = ".";
  299. static const char *Slash = "/";
  300. static const FormatVariables DefVars = {
  301. True, /* int last_was_space; */
  302. False, /* int last_was_mb; */
  303. False, /* int last_was_nl; */
  304. NULL, /* char *rd_buf; */
  305. NULL, /* char *rd_ptr; */
  306. NULL, /* char *fmt_buf; */
  307. NULL, /* char *my_path; */
  308. NULL, /* char *vol_name; */
  309. NULL, /* char *topic_id; */
  310. NULL, /* char *topic_char_set; */
  311. NULL, /* char *topic_lang; */
  312. 0, /* int rd_size; */
  313. 0, /* int rd_flag; */
  314. 1, /* int topic_mb_max; */
  315. 1, /* int cur_mb_max; */
  316. 0, /* int fmt_buf_max; */
  317. 0, /* int fmt_size; */
  318. 0, /* int cell_cnt; */
  319. NULL, /* BufFilePtr my_file; */
  320. { /* SegList my_list; */
  321. 0, /* int cnt; */
  322. 0, /* int max; */
  323. NULL, /* _DtCvSegment *list; */
  324. }, /* SegList my_list; */
  325. NULL, /* _DtCvLinkDb my_links; */
  326. NULL, /* _FrmtUiInfo ui_info; */
  327. };
  328. static const SegList InitList =
  329. {
  330. 0, /* int cnt; */
  331. 0, /* int max; */
  332. NULL, /* _DtCvSegment *list; */
  333. };
  334. static const _DtCvContainer DefContainer =
  335. {
  336. NULL, /* char *id; */
  337. NULL, /* char *justify_char; */
  338. _DtCvDYNAMIC, /* _DtCvFrmtOption type; */
  339. _DtCvBORDER_NONE, /* _DtCvFrmtOption border; */
  340. _DtCvJUSTIFY_LEFT, /* _DtCvFrmtOption justify; */
  341. _DtCvJUSTIFY_TOP, /* _DtCvFrmtOption vjustify; */
  342. _DtCvJUSTIFY_LEFT_MARGIN,/* _DtCvFrmtOption orient; */
  343. _DtCvJUSTIFY_TOP, /* _DtCvFrmtOption vorient; */
  344. _DtCvWRAP_NONE, /* _DtCvFrmtOption flow; */
  345. 10000, /* int percent; */
  346. 0, /* _DtCvUnit leading; */
  347. 0, /* _DtCvUnit fmargin; */
  348. 0, /* _DtCvUnit lmargin; */
  349. 0, /* _DtCvUnit rmargin; */
  350. 0, /* _DtCvUnit tmargin; */
  351. 1, /* _DtCvUnit bmargin; */
  352. {0, NULL}, /* _DtCvLine bdr_info; */
  353. NULL, /* _DtCvSegment seg_list; */
  354. };
  355. static const FrmtPrivateInfo DefPrivInfo =
  356. {
  357. (char) False, /* char top_block; */
  358. (char) False, /* char dup_flag; */
  359. 0, /* int sdl_type; */
  360. 0, /* void *match_info; */
  361. NULL, /* void *id_info; */
  362. NULL, /* void *tmp_info; */
  363. };
  364. /******************************************************************************
  365. *
  366. * Private Functions
  367. *
  368. *****************************************************************************/
  369. /******************************************************************************
  370. * Function: int CreateMarker (
  371. *
  372. * Parameters:
  373. * cur_vars Specifies the current setting of
  374. * formatting variables.
  375. * id_string The id string for the marker.
  376. *
  377. * Returns: 0 if successful, -1 if failure.
  378. *
  379. * Purpose: To create a marker id.
  380. *
  381. *****************************************************************************/
  382. static int
  383. CreateMarker (
  384. FormatVariables *cur_vars,
  385. char *id_string)
  386. {
  387. int result;
  388. /*
  389. * make sure there is room for the marker segment
  390. */
  391. result = CheckSegList(cur_vars);
  392. if (-1 != result)
  393. {
  394. int cnt = cur_vars->my_list.cnt;
  395. _DtCvSegment *list = cur_vars->my_list.list;
  396. /*
  397. * now make a mark segment here.
  398. */
  399. list[cnt].type = _DtCvSetTypeToMarker(list[cnt].type);
  400. _DtCvIdOfMarkerSeg(&list[cnt]) = id_string;
  401. cur_vars->my_list.cnt++;
  402. }
  403. return result;
  404. }
  405. /******************************************************************************
  406. * Function: void GetMbLen (
  407. *
  408. * Parameters:
  409. * cur_vars Specifies the current setting of
  410. * formatting variables.
  411. * font_str Specifies the CCDF string for a
  412. * CHARACTERSET change. The string is
  413. * modified by this routine.
  414. * lang_ptr Returns the language and territory
  415. * value. The caller owns this memory.
  416. * set_ptr Returns the code set of the language.
  417. * The caller owns this memory.
  418. *
  419. * Returns: Nothing
  420. *
  421. * Purpose: 1) To decompose the font_string into a language and code set
  422. * portions.
  423. * 2) To set the mb_cur_len variable in cur_vars.
  424. *
  425. *****************************************************************************/
  426. static void
  427. GetMbLen (
  428. FormatVariables *cur_vars,
  429. char *font_str,
  430. char **lang_ptr,
  431. char **set_ptr)
  432. {
  433. int i;
  434. char *ptr;
  435. char *langPart = NULL;
  436. char *codePart = NULL;
  437. /*
  438. * strip spaces
  439. */
  440. while (*font_str == ' ')
  441. font_str++;
  442. for (i = strlen(font_str) - 1; i > -1 && font_str[i] == ' '; i--)
  443. font_str[i] = '\0';
  444. /*
  445. * check for locale.codeset
  446. */
  447. if (_DtHelpCeStrchr(font_str, ".", 1, &ptr) == 0)
  448. {
  449. /*
  450. * make font_str two seperate strings by replacing
  451. * the dot with a end of line.
  452. */
  453. *ptr++ = '\0';
  454. langPart = strdup(font_str);
  455. codePart = strdup(ptr);
  456. }
  457. /*
  458. * old CCDF volume
  459. */
  460. else
  461. {
  462. _DtHelpCeXlateOpToStdLocale(DtLCX_OPER_CCDF, font_str,
  463. NULL, &langPart, &codePart);
  464. /*
  465. * if the language is not specified for the code set,
  466. * get the environment's.
  467. */
  468. if (strcmp(langPart, "?") == 0)
  469. {
  470. free(langPart);
  471. langPart = _DtHelpGetLocale();
  472. if (langPart == NULL || *langPart == '\0')
  473. langPart = strdup((char *) CString);
  474. else if (_DtHelpCeStrrchr(langPart, "_", MB_CUR_MAX, &ptr) == 0)
  475. *ptr = '\0';
  476. else if (_DtHelpCeStrrchr(langPart, Period, MB_CUR_MAX, &ptr) == 0)
  477. *ptr = '\0';
  478. }
  479. }
  480. cur_vars->cur_mb_max = _DtHelpCeGetMbLen(langPart, codePart);
  481. /*
  482. * now set the return variables
  483. */
  484. if (lang_ptr != NULL)
  485. *lang_ptr = langPart;
  486. else
  487. free(langPart);
  488. if (set_ptr != NULL)
  489. *set_ptr = codePart;
  490. else
  491. free(codePart);
  492. }
  493. /******************************************************************************
  494. * Function: int ReturnLinkWinHint (int ccdf_type)
  495. *
  496. * Parameters:
  497. *
  498. * Returns:
  499. *
  500. * errno Values:
  501. *
  502. * Purpose:
  503. *****************************************************************************/
  504. static int
  505. ReturnLinkWinHint (
  506. int ccdf_type)
  507. {
  508. int winHint = _DtCvWindowHint_CurrentWindow;
  509. if (ccdf_type == CCDF_LINK_JUMP_NEW)
  510. winHint = _DtCvWindowHint_NewWindow;
  511. else if (ccdf_type == CCDF_LINK_DEFINITION)
  512. winHint = _DtCvWindowHint_PopupWindow;
  513. return winHint;
  514. }
  515. /******************************************************************************
  516. * Function: int ReturnLinkType (int ccdf_type, char *spec)
  517. *
  518. * Parameters:
  519. *
  520. * Returns:
  521. *
  522. * errno Values:
  523. *
  524. * Purpose:
  525. *****************************************************************************/
  526. static int
  527. ReturnLinkType (
  528. int ccdf_type,
  529. char *spec)
  530. {
  531. int trueType = _DtCvLinkType_SameVolume;
  532. switch(ccdf_type)
  533. {
  534. case CCDF_LINK_JUMP_NEW:
  535. case CCDF_LINK_JUMP_REUSE:
  536. case CCDF_LINK_DEFINITION:
  537. if (strchr(spec, ' ') != NULL)
  538. trueType = _DtCvLinkType_CrossLink;
  539. break;
  540. case CCDF_LINK_EXECUTE:
  541. trueType = _DtCvLinkType_Execute;
  542. break;
  543. case CCDF_LINK_MAN_PAGE:
  544. trueType = _DtCvLinkType_ManPage;
  545. break;
  546. case CCDF_LINK_APP_DEFINE:
  547. trueType = _DtCvLinkType_AppDefine;
  548. break;
  549. }
  550. return trueType;
  551. }
  552. /******************************************************************************
  553. * Function: int CheckSegList (FormatVariables *cur_vars)
  554. *
  555. * Parameters:
  556. *
  557. * Returns: 0 for success, -1 for errors.
  558. *
  559. * errno Values:
  560. * CEErrorReported
  561. *
  562. * Purpose: Check the global variable 'SegCount' against 'SegMax' and
  563. * realloc/malloc more memory for the global variable 'SegList'
  564. * if necessary. If memory is realloc'ed/malloc'ed, the entry
  565. * 'para_entry->seg_list' is set to 'SegList'.
  566. *
  567. *****************************************************************************/
  568. static int
  569. CheckSegList (
  570. FormatVariables *cur_vars )
  571. {
  572. if (cur_vars->my_list.cnt >= cur_vars->my_list.max)
  573. {
  574. cur_vars->my_list.list = AllocateSegments (cur_vars->my_list.list,
  575. cur_vars->my_list.max,
  576. (cur_vars->my_list.max + GROW_SIZE));
  577. if (NULL == cur_vars->my_list.list)
  578. return -1;
  579. cur_vars->my_list.max += GROW_SIZE;
  580. }
  581. return 0;
  582. }
  583. /******************************************************************************
  584. * Function: static _DtCvSegment *AllocateSegments (_DtCvSegment p_seg,
  585. * int original_size, int new_size)
  586. *
  587. * Parameters:
  588. * p_seg Specifies a pointer to the old list
  589. * of _DtCvSegments.
  590. * original_size Specifies the current size of 'p_seg'.
  591. * new_size Specifies the new size of 'p_seg'.
  592. *
  593. * Returns: A pointer to the new list of structures.
  594. * A NULL indicates an error.
  595. *
  596. * Purpose: (Re)Allocates _DtCvSegment structures and initializes
  597. * them to the default segment which is type _DtCvNOOP
  598. * and the container values set to default values.
  599. *
  600. *****************************************************************************/
  601. static _DtCvSegment *
  602. AllocateSegments (
  603. _DtCvSegment *p_seg,
  604. int original_size,
  605. int new_size )
  606. {
  607. FrmtPrivateInfo *priv = NULL;
  608. if (NULL != p_seg)
  609. {
  610. int count = 0;
  611. /*
  612. * reallocate the segments.
  613. */
  614. p_seg = (_DtCvSegment *) realloc ((void *) p_seg,
  615. (sizeof(_DtCvSegment) * new_size));
  616. /*
  617. * reallocate the private formatting information.
  618. */
  619. priv = p_seg->client_use;
  620. priv = (FrmtPrivateInfo *) realloc ((void *) priv,
  621. sizeof(FrmtPrivateInfo) * new_size);
  622. if (NULL == priv)
  623. return NULL;
  624. /*
  625. * reattach the private information with their segments.
  626. */
  627. while (count < original_size)
  628. p_seg[count++].client_use = priv++;
  629. }
  630. else
  631. p_seg = _DtHelpAllocateSegments (new_size);
  632. if (NULL != p_seg)
  633. {
  634. /*
  635. * want to 'empty' the type.
  636. */
  637. while (original_size < new_size)
  638. {
  639. /*
  640. * if we went through _DtHelpAllocateSegments, then the
  641. * priv pointer will be NULL. But that's okay since the
  642. * _DtHelpAllocateSegments routine will initalized the
  643. * variables for us. The only reason we have to do it
  644. * is if we've reallocated the list.
  645. */
  646. if (NULL != priv)
  647. {
  648. *priv = DefPrivInfo;
  649. p_seg[original_size ].client_use = priv++;
  650. p_seg[original_size ].type = _DtCvNOOP;
  651. p_seg[original_size ].link_idx = -1;
  652. p_seg[original_size ].next_seg = NULL;
  653. p_seg[original_size ].next_disp = NULL;
  654. }
  655. p_seg[original_size++].handle.container = DefContainer;
  656. }
  657. }
  658. return p_seg;
  659. }
  660. /******************************************************************************
  661. * Function: static int CheckList (
  662. * FormatVariables cur_vars, int count, int grow)
  663. *
  664. * Parameters:
  665. * cur_vars Specifies a structure containing the list
  666. * of _DtCvSegments.
  667. * count Specifies the amount needed.
  668. * grow Specifies the amount to grow by.
  669. *
  670. * Returns: 0 if successful, -1 if failure.
  671. *
  672. * Purpose: Makes sure there is 'grow' size number of segments
  673. * available. If not, it calls AllocateSegments to 'grow'
  674. * the segment list. cur_vars->seg_list is set to the new
  675. * pointer, cur_vars->seg_max indicates the maximum number
  676. * of segments in the list.
  677. *
  678. *****************************************************************************/
  679. static int
  680. CheckList (
  681. SegList *seg_list,
  682. int count,
  683. int grow )
  684. {
  685. /*
  686. * what's the new count?
  687. */
  688. count += seg_list->cnt;
  689. /*
  690. * is it larger than the current max?
  691. */
  692. if (count > seg_list->max)
  693. {
  694. /*
  695. * grow the list by the indicated amount.
  696. */
  697. grow += seg_list->max;
  698. /*
  699. * check to see if it is enough. If not, force the grow value
  700. * to be the required count.
  701. */
  702. if (count > grow)
  703. grow = count;
  704. /*
  705. * (re)allocate
  706. */
  707. seg_list->list = AllocateSegments(seg_list->list, seg_list->max, grow);
  708. /*
  709. * return an code if no list allocated.
  710. */
  711. if (NULL == seg_list->list)
  712. return -1;
  713. /*
  714. * set the max count
  715. */
  716. seg_list->max = grow;
  717. }
  718. return 0;
  719. }
  720. /******************************************************************************
  721. * Function: int SegmentSave (int type,
  722. * char **font_attr, char *string, int linkspec,
  723. * _DtCvSegment *p_seg)
  724. *
  725. * Parameters:
  726. * type Specifies the segment type.
  727. * font_attr Specifies the resource list of quarks for the
  728. * font to associate with the segment.
  729. * string Specifies the string segment.
  730. * link_spec Specifies the link specification for the
  731. * segment.
  732. * p_seg Specifies the _DtCvSegment structure to
  733. * initialize with the data.
  734. *
  735. * Returns: 0 if successful, -1 if errors.
  736. *
  737. * errno Values:
  738. * CEErrorReported
  739. *
  740. * Purpose: Creates a new segment with the given data.
  741. *
  742. *****************************************************************************/
  743. static int
  744. SegmentSave (
  745. FormatVariables *cur_vars,
  746. unsigned long seg_type,
  747. _DtHelpFontHints *font_attr,
  748. char *string,
  749. int str_size,
  750. int num_chars,
  751. int linkspec)
  752. {
  753. int result = 0;
  754. _DtCvSegment *pSeg = NextAvailSeg(cur_vars->my_list);
  755. pSeg->type = _DtCvSetTypeToNoop(seg_type);
  756. pSeg->link_idx = linkspec;
  757. /*
  758. * We use this routine for many things.
  759. * If we want an newline in here, we may not have any data.
  760. */
  761. if (str_size)
  762. {
  763. pSeg->type = _DtCvSetTypeToString(pSeg->type);
  764. /*
  765. * if a wide character representation is required,
  766. * convert to wchar_t
  767. */
  768. if (seg_type & _DtCvWIDE_CHAR)
  769. {
  770. wchar_t *pwcs;
  771. /*
  772. * include the null byte in the multibyte to widechar
  773. * conversion.
  774. */
  775. num_chars++;
  776. /*
  777. * malloc the memory
  778. */
  779. pwcs = (wchar_t *) malloc(sizeof(wchar_t) * num_chars);
  780. if (NULL != pwcs)
  781. {
  782. /* convert */
  783. str_size = mbstowcs(pwcs, string, ((size_t) num_chars));
  784. /* check to see if it converted everything */
  785. if (str_size + 1 == num_chars)
  786. _DtCvStringOfStringSeg(pSeg) = (void *) pwcs;
  787. else
  788. free(pwcs);
  789. }
  790. }
  791. else
  792. _DtCvStringOfStringSeg(pSeg) = (void *) strdup(string);
  793. if (NULL == _DtCvStringOfStringSeg(pSeg))
  794. return -1;
  795. /*
  796. * set the default font. This should really be passed in via
  797. * the format entry point (or the ui_info structure).
  798. */
  799. _DtCvFontOfStringSeg(pSeg) = 0;
  800. /*
  801. * load the font
  802. */
  803. if (NULL != cur_vars->ui_info->load_font)
  804. (*(cur_vars->ui_info->load_font))(
  805. cur_vars->ui_info->client_data,
  806. _DtHelpFontHintsLang(*font_attr),
  807. _DtHelpFontHintsCharSet(*font_attr),
  808. *font_attr,
  809. &(_DtCvFontOfStringSeg(pSeg)));
  810. }
  811. return result;
  812. }
  813. /******************************************************************************
  814. * Function: int SaveStringAsSegments (FormatVariables, int type, char **font_attr,
  815. * int link_spec)
  816. *
  817. * Parameters:
  818. * type Specifies the segment type.
  819. * font_attr Specifies the resource list of quarks for the
  820. * font to associate with the segment.
  821. * link_spec Specifies the link specification for the
  822. * segment.
  823. *
  824. * Returns: 0 if successful, -1 if errors.
  825. *
  826. * errno Values:
  827. *
  828. * Purpose: Saves a segment into the global 'SegList'. This is
  829. * a wrapper around SegmentSave that adds specific
  830. * information relative to this module.
  831. *
  832. *****************************************************************************/
  833. static int
  834. SaveStringAsSegments (
  835. FormatVariables *cur_vars,
  836. unsigned long seg_flags,
  837. _DtHelpFontHints *font_attr,
  838. int link_spec)
  839. {
  840. int len;
  841. int size;
  842. int numChars;
  843. int newLine = False;
  844. char tmpChar;
  845. char *ptr;
  846. seg_flags = _DtCvSetTypeToNoop(seg_flags);
  847. if (cur_vars->cur_mb_max != 1 && cur_vars->fmt_size > 1)
  848. {
  849. if (IsTypeNewLine(seg_flags))
  850. {
  851. newLine = True;
  852. seg_flags = seg_flags & ~(_DtCvNEW_LINE);
  853. }
  854. ptr = cur_vars->fmt_buf;
  855. do
  856. {
  857. /*
  858. * what type of character is this?
  859. */
  860. len = mblen (ptr, cur_vars->cur_mb_max);
  861. /*
  862. * How many of the following characters are of the same size?
  863. */
  864. size = _DtHelpFmtFindBreak (ptr, len, &numChars);
  865. /*
  866. * save off the character that doesn't match
  867. */
  868. tmpChar = ptr[size];
  869. /*
  870. * put in the null byte for the string.
  871. * and set to wide char if not doing multi-byte sequence.
  872. */
  873. ptr[size] = '\0';
  874. if (1 != len)
  875. seg_flags = _DtCvSetTypeToWideChar (seg_flags);
  876. /*
  877. * does this segment get the newline flag?
  878. */
  879. if (True == newLine && size >= cur_vars->fmt_size)
  880. seg_flags = _DtCvSetTypeToNewLine(seg_flags);
  881. /*
  882. * save the segment.
  883. */
  884. if (CheckSegList(cur_vars) == -1 ||
  885. SegmentSave (cur_vars, seg_flags, font_attr, ptr, size,
  886. numChars, link_spec) == -1)
  887. return -1;
  888. /*
  889. * remove the wide char flag
  890. */
  891. seg_flags &= ~(_DtCvWIDE_CHAR);
  892. /*
  893. * Bump the segment list count.
  894. */
  895. cur_vars->my_list.cnt++;
  896. /*
  897. * replace the character that didn't match.
  898. * and bump the pointer to it.
  899. */
  900. ptr[size] = tmpChar;
  901. ptr += size;
  902. cur_vars->fmt_size -= size;
  903. } while (0 < cur_vars->fmt_size);
  904. }
  905. else
  906. {
  907. if (CheckSegList (cur_vars) == -1 ||
  908. SegmentSave (cur_vars, seg_flags, font_attr,
  909. cur_vars->fmt_buf, cur_vars->fmt_size,
  910. cur_vars->fmt_size,
  911. link_spec) == -1)
  912. return -1;
  913. cur_vars->my_list.cnt++;
  914. }
  915. cur_vars->fmt_size = 0;
  916. if (cur_vars->fmt_buf)
  917. cur_vars->fmt_buf[0] = '\0';
  918. return 0;
  919. }
  920. /******************************************************************************
  921. * Function: int CheckSaveSegment (int type, char **font_attr, int link_spec,
  922. * FormatVariables cur_vars)
  923. *
  924. * Parameters:
  925. * type Specifies the segment type.
  926. * font_attr Specifies the resource list of quarks for the
  927. * font to associate with the segment.
  928. * link_spec Specifies the link specification for the
  929. * segment.
  930. *
  931. * Returns: 0 if successful, -1 if errors.
  932. *
  933. * errno Values:
  934. *
  935. * Purpose: Checks 'cur_vars->fmt_size' for a non-zero value. If it is,
  936. * calls SaveSegment.
  937. *
  938. *****************************************************************************/
  939. static int
  940. CheckSaveSegment (
  941. unsigned long seg_flags,
  942. _DtHelpFontHints *font_attr,
  943. int link_spec,
  944. FormatVariables *cur_vars)
  945. {
  946. int result = 0;
  947. if (cur_vars->fmt_size)
  948. result = SaveStringAsSegments (cur_vars, seg_flags, font_attr, link_spec);
  949. return result;
  950. }
  951. /******************************************************************************
  952. * Function: void TerminateSegList (
  953. *
  954. * Parameters:
  955. *
  956. * Returns: 0 if successful, -1 if errors.
  957. *
  958. * Purpose: Links the segments together.
  959. *
  960. *****************************************************************************/
  961. static void
  962. TerminateSegList (
  963. SegList *seg_list,
  964. int flag)
  965. {
  966. int count;
  967. _DtCvSegment *lastDisp = NULL;
  968. _DtCvSegment *pSeg;
  969. if (True == flag && 0 == seg_list->cnt && NULL != seg_list->list)
  970. {
  971. free(seg_list->list);
  972. *seg_list = InitList;
  973. }
  974. /*
  975. * set the next segment and display segment pointers.
  976. */
  977. for (count = 1, pSeg = seg_list->list; count < seg_list->cnt;
  978. count++, pSeg++)
  979. {
  980. /*
  981. * link this segment to the next segment
  982. */
  983. pSeg->next_seg = &(pSeg[1]);
  984. /*
  985. * is this a displayable segment?
  986. * If so, link it into the displayable list.
  987. */
  988. if (_DtCvIsSegNoop(pSeg) || _DtCvIsSegRegion(pSeg)
  989. || _DtCvIsSegString(pSeg))
  990. {
  991. /*
  992. * Is there a displayable segment yet?
  993. * If so, set its next displayable link to this segment.
  994. */
  995. if (NULL != lastDisp)
  996. lastDisp->next_disp = pSeg;
  997. /*
  998. * this segment becomes the last displayable segment.
  999. */
  1000. lastDisp = pSeg;
  1001. }
  1002. else
  1003. lastDisp = NULL;
  1004. }
  1005. if (NULL != pSeg && NULL != lastDisp
  1006. && (_DtCvIsSegNoop(pSeg) || _DtCvIsSegRegion(pSeg)
  1007. || _DtCvIsSegString(pSeg)))
  1008. lastDisp->next_disp = pSeg;
  1009. }
  1010. /******************************************************************************
  1011. * Function: int InitStructure (FormatVariables *cur_vars,
  1012. * char *rd_buf, int rd_size,
  1013. *
  1014. * Parameters:
  1015. * rd_buffer Specifies the buffer all reads use.
  1016. * id_string Specifies the location ID to search for.
  1017. *
  1018. * Returns: 0 if successful, -1 if errors.
  1019. *
  1020. * errno Values:
  1021. *
  1022. * Purpose: Attach formatting information to the structure that gets
  1023. * passed around by, among other things, setting the global
  1024. * variable 'cur_vars->rd_ptr' to 'rd_buffer', and
  1025. * remembering the location id.
  1026. *
  1027. *****************************************************************************/
  1028. static int
  1029. InitStructure(
  1030. FormatVariables *cur_vars,
  1031. _FrmtUiInfo *ui_info,
  1032. char *rd_buf,
  1033. int rd_size)
  1034. {
  1035. cur_vars->ui_info = ui_info;
  1036. cur_vars->rd_size = rd_size;
  1037. cur_vars->rd_buf = rd_buf;
  1038. cur_vars->rd_ptr = cur_vars->rd_buf;
  1039. cur_vars->fmt_size = 0;
  1040. if (cur_vars->fmt_buf)
  1041. cur_vars->fmt_buf[0] = '\0';
  1042. /*
  1043. * allocate the link data base.
  1044. */
  1045. cur_vars->my_links = _DtLinkDbCreate();
  1046. if (NULL == cur_vars->my_links)
  1047. return -1;
  1048. return 0;
  1049. }
  1050. /******************************************************************************
  1051. * Function: int AppendToInfo (FormatVariables *cur_vars,
  1052. * char **src, const char *scan_string)
  1053. *
  1054. * Parameters:
  1055. * src Specifies the source string to read.
  1056. * Returns pointing at a special character,
  1057. * an invalid character or the
  1058. * end of string.
  1059. * scan_string Specifies the special characters to
  1060. * look for in 'src'.
  1061. *
  1062. * Returns: 0 if stopped on a special character.
  1063. * 1 if found the end of string.
  1064. * 2 if found an invalid character.
  1065. * -1 if errors.
  1066. *
  1067. * errno Values:
  1068. *
  1069. * Purpose: Appends onto 'cur_vars->fmt_buf' the number of characters
  1070. * found in 'src' that does not match any character in
  1071. * 'scan_string'.
  1072. *
  1073. * Sets 'cur_vars->last_was_space' to false (assumes that one
  1074. * of the special characters is a space).
  1075. *
  1076. *****************************************************************************/
  1077. static int
  1078. AppendToInfo (
  1079. FormatVariables *cur_vars,
  1080. char **src,
  1081. const char *scan_string )
  1082. {
  1083. int spnResult;
  1084. int size;
  1085. cur_vars->last_was_space = False;
  1086. spnResult = _DtHelpCeStrcspn(*src, scan_string, cur_vars->cur_mb_max,
  1087. &size);
  1088. if (0 < size)
  1089. {
  1090. if (_DtHelpCeAddStrToBuf(src,&(cur_vars->fmt_buf),&(cur_vars->fmt_size),
  1091. &(cur_vars->fmt_buf_max),size,INFO_GROW) == -1)
  1092. return -1;
  1093. cur_vars->last_was_space = False;
  1094. }
  1095. if (spnResult == -1)
  1096. spnResult = 2;
  1097. if (0 == size && 1 == spnResult)
  1098. spnResult = 0;
  1099. return spnResult;
  1100. }
  1101. /******************************************************************************
  1102. * Function: int AppendOctalToInfo (FormatVariables *cur_vars, char *src)
  1103. *
  1104. * Parameters:
  1105. * src Specifies the source string to read.
  1106. *
  1107. * Returns: 0 if successful, -1 if errors.
  1108. *
  1109. * errno Values:
  1110. * CEErrorFormattingValue
  1111. * CEErrorMalloc
  1112. *
  1113. * Purpose: Convert the octal representation pointed to by 'src' and
  1114. * change it into a character byte. The routine only allows
  1115. * a number between the values 1-255.
  1116. *
  1117. * Append the byte onto the global variable 'Info'.
  1118. * Set 'cur_vars->last_was_space' to false.
  1119. *
  1120. *****************************************************************************/
  1121. static int
  1122. AppendOctalToInfo(
  1123. FormatVariables *cur_vars,
  1124. char *src)
  1125. {
  1126. /*
  1127. * must have 0xXX
  1128. */
  1129. if (((int)strlen(src)) < 4 && cur_vars->my_file != NULL)
  1130. {
  1131. if (GetNextBuffer (cur_vars) == -1)
  1132. return -1;
  1133. src = cur_vars->rd_ptr;
  1134. }
  1135. if (_DtHelpCeAddOctalToBuf(src,&(cur_vars->fmt_buf),&(cur_vars->fmt_size),
  1136. &(cur_vars->fmt_buf_max),INFO_GROW) == -1)
  1137. return -1;
  1138. cur_vars->last_was_space = False;
  1139. return 0;
  1140. }
  1141. /******************************************************************************
  1142. * Function: int AppendCharToInfo (FormatVariables *cur_vars, char **src)
  1143. *
  1144. * Parameters:
  1145. * src Specifies the source string to read.
  1146. * Returns pointing at the next character
  1147. * the string.
  1148. *
  1149. * Returns: 0 if successful, -1 if errors.
  1150. *
  1151. * errno Values:
  1152. *
  1153. * Purpose: Appends the character pointed to by 'src' onto the
  1154. * global buffer 'Info', updating the pointers associated
  1155. * with 'Info' accordingly.
  1156. *
  1157. * Sets 'cur_vars->last_was_space' to False;
  1158. *
  1159. *****************************************************************************/ static int
  1160. AppendCharToInfo(
  1161. FormatVariables *cur_vars,
  1162. char **src)
  1163. {
  1164. cur_vars->last_was_space = False;
  1165. return (_DtHelpCeAddCharToBuf (src, &(cur_vars->fmt_buf),
  1166. &(cur_vars->fmt_size),
  1167. &(cur_vars->fmt_buf_max), INFO_GROW));
  1168. }
  1169. /******************************************************************************
  1170. * Function: int AppendSpaceToInfo (char **src, int type)
  1171. *
  1172. * Parameters:
  1173. * src Specifies the source string to read.
  1174. * Returns pointing at the next character
  1175. * the string.
  1176. * type Specifies the type of the segment being
  1177. * processed.
  1178. *
  1179. * Returns: 0 if successful, -1 if errors.
  1180. *
  1181. * errno Values:
  1182. *
  1183. * Purpose: Appends a space onto the global buffer 'Info', if
  1184. * the variable 'cur_vars->last_was_space' is false or the
  1185. * static string flag is set in 'type'.
  1186. *
  1187. * Sets 'cur_vars->last_was_space' to true.
  1188. *
  1189. *****************************************************************************/
  1190. static int
  1191. AppendSpaceToInfo (
  1192. FormatVariables *cur_vars,
  1193. char **src,
  1194. _DtCvFrmtOption type)
  1195. {
  1196. int result = 0;
  1197. char *space = (char *) SpaceString;
  1198. if (!cur_vars->last_was_space || _DtCvLITERAL == type) {
  1199. result = _DtHelpCeAddCharToBuf (&space, &(cur_vars->fmt_buf),
  1200. &(cur_vars->fmt_size),
  1201. &(cur_vars->fmt_buf_max), INFO_GROW);
  1202. cur_vars->last_was_space = True;
  1203. }
  1204. if (src != NULL)
  1205. *src = *src + 1;
  1206. return result;
  1207. }
  1208. /******************************************************************************
  1209. * Function: int FindEndMarker (FormatVariables *cur_vars)
  1210. *
  1211. * Returns: 0 if successful, -1 if errors.
  1212. *
  1213. * errno Values:
  1214. *
  1215. * Purpose: Wrapper around __DtHelpFindEndMarker.
  1216. * Find the '>' token.
  1217. *
  1218. *****************************************************************************/
  1219. static int
  1220. FindEndMarker(
  1221. FormatVariables *cur_vars)
  1222. {
  1223. return (_DtHelpCeGetCcdfEndMark (cur_vars->my_file, cur_vars->rd_buf,
  1224. &(cur_vars->rd_ptr),cur_vars->rd_size,1));
  1225. }
  1226. /******************************************************************************
  1227. * Function: int GetNextBuffer (FormatVariables *cur_vars)
  1228. *
  1229. * Returns: 0 if successful, -1 if errors.
  1230. *
  1231. * errno Values:
  1232. *
  1233. * Purpose: Wrapper around __DtHelpGetNextBuffer.
  1234. * Read the next buffer's worth of information.
  1235. *
  1236. *****************************************************************************/
  1237. static int
  1238. GetNextBuffer (
  1239. FormatVariables *cur_vars)
  1240. {
  1241. cur_vars->rd_flag = _DtHelpCeGetNxtBuf (cur_vars->my_file,
  1242. cur_vars->rd_buf,
  1243. &(cur_vars->rd_ptr),
  1244. cur_vars->rd_size);
  1245. return (cur_vars->rd_flag);
  1246. }
  1247. /******************************************************************************
  1248. * Function: int SaveNewLine (FormatVariables *cur_vars, int cur_type,
  1249. * char **font_attr,
  1250. * int link_spec)
  1251. *
  1252. * Parameters:
  1253. * cur_cmd Specifies the type of segment being processed.
  1254. * font_attr Specifies the list of font quarks associated
  1255. * with the current segment.
  1256. * link_spec Specifies the hypertext link specification
  1257. * associated with the current segment.
  1258. *
  1259. * Returns: 0 if successful, -1 if errors.
  1260. *
  1261. * errno Values:
  1262. *
  1263. * Purpose: Sets the newline flag on a segment and saves it by calling
  1264. * 'SaveStringAsSegments'.
  1265. * If the current segment is non-null, save it with the
  1266. * newline flag set.
  1267. * Otherwise if there are no segments saved, create one with the
  1268. * a type of CE_old_NOOP.
  1269. * Otherwise there are other segments, but the current segment is
  1270. * empty. Look back at the previous segment.
  1271. * If it doesn't have the newline set on it,
  1272. * its newline flag is enabled.
  1273. * Otherwise the previous segment had the newline set, so
  1274. * create another segment just like it with a
  1275. * null length and the newline flag set (if the
  1276. * previous segment is a graphic, create it
  1277. * with a type of CE_old_NOOP).
  1278. *
  1279. *****************************************************************************/
  1280. static int
  1281. SaveNewLine(
  1282. FormatVariables *cur_vars,
  1283. int cur_type,
  1284. _DtHelpFontHints *font_attr,
  1285. int link_spec )
  1286. {
  1287. int result = 0;
  1288. _DtCvSegment *pSeg;
  1289. /*
  1290. * If there is information in the buffer, save it with the newline flag
  1291. */
  1292. if (cur_vars->fmt_size)
  1293. result = SaveStringAsSegments (cur_vars, _DtCvSetTypeToNewLine (cur_type),
  1294. font_attr, link_spec);
  1295. /*
  1296. * check to see if there is any segments. If not create a new one
  1297. * with the type NOOP.
  1298. */
  1299. else if (0 == cur_vars->my_list.cnt)
  1300. result = SaveStringAsSegments (cur_vars, _DtCvSetTypeToNewLine(_DtCvNOOP),
  1301. font_attr, link_spec);
  1302. /*
  1303. * There was not any information in the buffer and we have one or
  1304. * more segments. Try placing the flag on the previous segment.
  1305. */
  1306. else
  1307. {
  1308. pSeg = NextAvailSeg(cur_vars->my_list);
  1309. pSeg--;
  1310. /*
  1311. * Does the previous segment already have a newline flag?
  1312. * If so, create a new NOOP segment with the newline set.
  1313. */
  1314. if (_DtCvIsSegNewLine (pSeg))
  1315. result = SaveStringAsSegments (cur_vars, _DtCvSetTypeToNewLine (_DtCvNOOP),
  1316. font_attr, link_spec);
  1317. else
  1318. pSeg->type = _DtCvSetTypeToNewLine (pSeg->type);
  1319. }
  1320. cur_vars->last_was_space = True;
  1321. return result;
  1322. }
  1323. /******************************************************************************
  1324. * Function: int CreateSaveGraphic (FormatVariables cur_vars,
  1325. * int type,
  1326. * char *file_name, int link_spec )
  1327. *
  1328. * Parameters:
  1329. * type Specifies the type of graphic segment
  1330. * being processed.
  1331. * file_name Specifies the file name of the graphic.
  1332. * link_spec Specifies the hypertext link specification
  1333. * associated with the graphic.
  1334. *
  1335. * Returns: 0 if successful, -1 if errors.
  1336. *
  1337. * Purpose: Save a graphic segment.
  1338. * If 'file_name' is not an absolute path, resolve it to
  1339. * a full path by using the path to the volume.
  1340. *
  1341. *****************************************************************************/
  1342. static int
  1343. CreateSaveGraphic (
  1344. FormatVariables *cur_vars,
  1345. int type,
  1346. char *file_name,
  1347. int link_spec)
  1348. {
  1349. char *fullName;
  1350. _DtCvSegment *cvRegion;
  1351. if (CheckList (&(cur_vars->my_list), 1, 1) == -1)
  1352. return -1;
  1353. /*
  1354. * create the path to the file name
  1355. */
  1356. if (*file_name == '/')
  1357. fullName = strdup (file_name);
  1358. else
  1359. {
  1360. fullName = (char *) malloc (strlen (cur_vars->my_path) +
  1361. strlen (file_name) + 2);
  1362. if (fullName == NULL)
  1363. return -1;
  1364. strcpy (fullName, cur_vars->my_path);
  1365. strcat (fullName, "/");
  1366. strcat (fullName, file_name);
  1367. }
  1368. /*
  1369. * load the graphic into the current segment
  1370. */
  1371. cvRegion = NextAvailSeg(cur_vars->my_list);
  1372. if (NULL != cur_vars->ui_info->load_graphic &&
  1373. (*(cur_vars->ui_info->load_graphic))(
  1374. cur_vars->ui_info->client_data,
  1375. cur_vars->vol_name,
  1376. cur_vars->topic_id,
  1377. fullName,
  1378. NULL,
  1379. NULL,
  1380. &(_DtCvWidthOfRegionSeg(cvRegion)),
  1381. &(_DtCvHeightOfRegionSeg(cvRegion)),
  1382. &(_DtCvInfoOfRegionSeg(cvRegion))) == 0)
  1383. {
  1384. /*
  1385. * set the type and index.
  1386. * and indicate that this segment has been used.
  1387. */
  1388. _DtCvAscentOfRegionSeg(cvRegion) = -1;
  1389. cvRegion->type = _DtCvSetTypeToRegion(type);
  1390. cvRegion->link_idx = link_spec;
  1391. cur_vars->my_list.cnt++;
  1392. }
  1393. /*
  1394. * free the file name path
  1395. */
  1396. free (fullName);
  1397. return 0;
  1398. }
  1399. /******************************************************************************
  1400. * Function: int ChangeFont (int whichOne, int segType,
  1401. * char **font_attr, int linkspec,
  1402. * FormatVariables *cur_vars, int flags)
  1403. *
  1404. * Parameters:
  1405. * whichOne Specifies the index into 'font_attr' to
  1406. * change.
  1407. * segType Specifies the type of segment currently
  1408. * being processed.
  1409. * font_attr Specifies the list of font quarks associated
  1410. * with the current segment.
  1411. * linkspec Specifies the hypertext link specification
  1412. * associated with the segment.
  1413. * flags Specifies the routines flags.
  1414. *
  1415. * Returns: The value returned from 'routine' if successful, -1 if errors.
  1416. *
  1417. * errno Values:
  1418. *
  1419. * Purpose: Saves any segment with the current font type and
  1420. * process the next segment using the new font type.
  1421. *
  1422. *****************************************************************************/
  1423. static int
  1424. ChangeFont(
  1425. int whichOne,
  1426. unsigned long seg_flags,
  1427. _DtCvFrmtOption frmt_type,
  1428. _DtHelpFontHints *font_attr,
  1429. int linkspec,
  1430. FormatVariables *cur_vars,
  1431. ProcessState cur_state,
  1432. int flags,
  1433. int ret_on_nl,
  1434. int fnt_flag)
  1435. {
  1436. int result;
  1437. int oldMb_Len = cur_vars->cur_mb_max;
  1438. char *fontString;
  1439. _DtHelpFontHints oldFontStruct;
  1440. if (CheckSaveSegment (seg_flags, font_attr, linkspec, cur_vars) == -1)
  1441. return -1;
  1442. oldFontStruct = *font_attr;
  1443. if (GetStringParameter(cur_vars, _DtCvTRUE, _DtCvTRUE, _DtCvFALSE,
  1444. _DtCvFALSE, &fontString) == -1)
  1445. return -1;
  1446. /*
  1447. * Is this font change allowed to go through?
  1448. */
  1449. if (!(fnt_flag & (1 << whichOne)))
  1450. {
  1451. switch (whichOne)
  1452. {
  1453. case _CEFONT_SPACING:
  1454. font_attr->spacing = _DtHelpFontSpacingProp;
  1455. if (fontString[0] == 'm')
  1456. font_attr->spacing = _DtHelpFontSpacingMono;
  1457. break;
  1458. case _CEFONT_SIZE:
  1459. font_attr->pointsz = atoi(fontString);
  1460. break;
  1461. case _CEFONT_ANGLE:
  1462. font_attr->slant = _DtHelpFontSlantRoman;
  1463. if (fontString[0] == 'i')
  1464. font_attr->slant = _DtHelpFontSlantItalic;
  1465. break;
  1466. case _CEFONT_WEIGHT:
  1467. font_attr->weight = _DtHelpFontWeightMedium;
  1468. if (fontString[0] == 'b')
  1469. font_attr->weight = _DtHelpFontWeightBold;
  1470. break;
  1471. case _CEFONT_TYPE:
  1472. font_attr->style = _DtHelpFontStyleSanSerif;
  1473. if (*fontString == 's')
  1474. {
  1475. if (fontString[1] == 'e')
  1476. font_attr->style = _DtHelpFontStyleSerif;
  1477. else if (fontString[1] == 'y')
  1478. font_attr->style = _DtHelpFontStyleSymbol;
  1479. }
  1480. break;
  1481. case _CEFONT_CHAR_SET:
  1482. /*
  1483. * Change to the correct mb_len.
  1484. */
  1485. GetMbLen(cur_vars, fontString,
  1486. &(_DtHelpFontHintsLang(*font_attr)),
  1487. &(_DtHelpFontHintsCharSet(*font_attr)));
  1488. break;
  1489. }
  1490. }
  1491. result = FindEndMarker (cur_vars);
  1492. if (!result)
  1493. result = Parse (CCDF_FONT_CMD, cur_state, cur_vars,
  1494. seg_flags, frmt_type,
  1495. font_attr, linkspec,
  1496. Specials, flags, ret_on_nl, fnt_flag);
  1497. /*
  1498. * free the lanugage and code sets strings.
  1499. */
  1500. if (!(fnt_flag & (1 << whichOne)) && whichOne == _CEFONT_CHAR_SET)
  1501. {
  1502. free(_DtHelpFontHintsLang(*font_attr));
  1503. free(_DtHelpFontHintsCharSet(*font_attr));
  1504. }
  1505. /*
  1506. * reset the old quark
  1507. * if necessary, reset the MB_LEN
  1508. */
  1509. *font_attr = oldFontStruct;
  1510. cur_vars->cur_mb_max = oldMb_Len;
  1511. /*
  1512. * free the memory
  1513. */
  1514. free (fontString);
  1515. if (result == -1)
  1516. return -1;
  1517. return 0;
  1518. } /* ChangeFont */
  1519. /******************************************************************************
  1520. * Function: int SkipToNextToken (FormatVariables *cur_vars, int flag)
  1521. *
  1522. * Parameters:
  1523. * flag Specifies whether the routine returns a -1
  1524. * if '>' is the next token.
  1525. *
  1526. * Returns: The value from __DtHelpSkipToNextToken:
  1527. * -1 If problems encountered finding the next token.
  1528. * 0 If no problems encountered finding the next token.
  1529. * 1 If flag is true and the next token is a > character.
  1530. *
  1531. * errno Values:
  1532. *
  1533. * Purpose: Wrapper around __DtHelpSkipToNextToken.
  1534. * Skip the current string and any spaces or newline
  1535. * characters after it.
  1536. *
  1537. *****************************************************************************/
  1538. static int
  1539. SkipToNextToken (
  1540. FormatVariables *cur_vars,
  1541. _DtCvValue flag)
  1542. {
  1543. return (_DtHelpCeSkipToNextCcdfToken (cur_vars->my_file, cur_vars->rd_buf,
  1544. cur_vars->rd_size, 1, &(cur_vars->rd_ptr), flag));
  1545. }
  1546. /******************************************************************************
  1547. * Function: int GetStringParameter (FormatVariables *cur_vars,
  1548. * int flag, int eat_escape,
  1549. * int ignore_quotes, int less_test,
  1550. * char **ret_string)
  1551. *
  1552. * Parameters:
  1553. * flag Specifies whether the routine returns
  1554. * a -1 if '>' is the next token.
  1555. * eat_secape Specifies whether the backslash is not
  1556. * placed in the returned string.
  1557. * True - it is skipped.
  1558. * False - it is saved in 'ret_string'.
  1559. * ignore_quotes Specifies whether quotes are to be included
  1560. * in the returned string.
  1561. * less_test Specifies whether the routine should
  1562. * stop when it finds a '<' character.
  1563. * ret_string Returns the string found.
  1564. * If NULL, throws the information away.
  1565. *
  1566. * Returns: The value from __DtHelpFormatGetStringParameter:
  1567. * -1 If problems encountered.
  1568. * 0 If no problems encountered getting the string.
  1569. * 1 If flag is false and the no string was found.
  1570. *
  1571. * errno Values:
  1572. *
  1573. * Purpose: Wrapper around __DtHelpFormatGetStringParameter.
  1574. * Skip the current string and any spaces or newline
  1575. * characters after it. Get the next quoted/unquoted
  1576. * string after that.
  1577. *
  1578. *****************************************************************************/
  1579. static int
  1580. GetStringParameter(
  1581. FormatVariables *cur_vars,
  1582. _DtCvValue flag,
  1583. _DtCvValue eat_escape,
  1584. _DtCvValue ignore_quotes,
  1585. _DtCvValue less_test,
  1586. char **ret_string)
  1587. {
  1588. return (_DtHelpCeGetCcdfStrParam (cur_vars->my_file,
  1589. cur_vars->rd_buf, cur_vars->rd_size, cur_vars->cur_mb_max,
  1590. &(cur_vars->rd_ptr),
  1591. flag, eat_escape, ignore_quotes, less_test, ret_string));
  1592. }
  1593. /******************************************************************************
  1594. * Function: int GetValueParameter (FormatVariables *cur_vars,
  1595. * int flag, int *ret_value)
  1596. *
  1597. * Parameters:
  1598. * flag Specifies whether the routine returns
  1599. * a -2 if '>' is the next token.
  1600. * ret_value Returns the atoi conversion
  1601. * of the string found.
  1602. *
  1603. * Returns: The value from __DtHelpFormatGetValueParameter:
  1604. * -1 If problems encountered.
  1605. * 0 If no problems encountered getting the string.
  1606. * -2 If flag is true and the next token is a >
  1607. * character.
  1608. *
  1609. * errno Values:
  1610. *
  1611. * Purpose: Wrapper around __DtHelpFormatGetValueParameter.
  1612. * Skip the current string and any spaces or newline
  1613. * characters after it. Process the next string as
  1614. * a numeric value.
  1615. *
  1616. *****************************************************************************/
  1617. static int
  1618. GetValueParameter(
  1619. FormatVariables *cur_vars,
  1620. _DtCvValue flag,
  1621. int *ret_value )
  1622. {
  1623. return (_DtHelpCeGetCcdfValueParam (cur_vars->my_file, cur_vars->rd_buf,
  1624. cur_vars->rd_size,
  1625. &(cur_vars->rd_ptr), flag, cur_vars->cur_mb_max,
  1626. ret_value));
  1627. }
  1628. /******************************************************************************
  1629. * Function: int GetParagraphParameters (FormatVariables *cur_vars,
  1630. * int seg_type, int graphic_type,
  1631. * char **label, char **file_name,
  1632. * char **link_string, int *link_type,
  1633. * char **description)
  1634. *
  1635. * Parameters:
  1636. * seg_type Specifies the default type for the segment.
  1637. * Returns the new type for the segment.
  1638. * graphic_type Specifies the default type for a graphic
  1639. * if a justified graphic is
  1640. * encountered in the paragraph options.
  1641. * Returns the new type for a graphic
  1642. * if a justified graphic was
  1643. * encountered in the paragraph options.
  1644. * label Returns the label if one is specified
  1645. * in the paragraph options.
  1646. * file_name Returns the file name of a graphic if
  1647. * one is specified in the paragraph
  1648. * options.
  1649. * link_string Returns the hypertext specification if one
  1650. * is specified in the paragraph options.
  1651. * link_type Returns the hypertext link type if one is
  1652. * specified.
  1653. * description Returns the hypertext description if one
  1654. * is specified.
  1655. *
  1656. * Returns: 0 if successfult, -1 if errors.
  1657. *
  1658. * errno Values:
  1659. *
  1660. * Purpose: Wrapper around __DtHelpParagraphGetOptions.
  1661. * Process the options found in <PARAGRAPH> syntax.
  1662. * Test to see if the id specified in the <PARAGRAPH>
  1663. * is the one we are looking at.
  1664. *
  1665. *****************************************************************************/
  1666. static int
  1667. GetParagraphParameters(
  1668. FormatVariables *cur_vars,
  1669. _DtCvSegment *para,
  1670. _DtCvFrmtOption *frmt_type,
  1671. _DtCvFrmtOption *gpos,
  1672. char **glink,
  1673. int *glinktype,
  1674. _DtCvUnit *gspace,
  1675. char **ret_label,
  1676. char **file_name,
  1677. char **description)
  1678. {
  1679. int done = False;
  1680. int result = 0;
  1681. int optionCount = 0;
  1682. int value;
  1683. char *tmpString = NULL;
  1684. /*
  1685. * initialize string variables if valid addresses
  1686. */
  1687. *ret_label = NULL;
  1688. *file_name = NULL;
  1689. *glink = NULL;
  1690. *description = NULL;
  1691. *gpos = _DtCvJUSTIFY_LEFT;
  1692. *glinktype = -1;
  1693. *gspace = 0;
  1694. while (False == done && result != -1)
  1695. {
  1696. if (SkipToNextToken (cur_vars, _DtCvFALSE) == -1)
  1697. return -1;
  1698. switch (_DtCvToLower(*(cur_vars->rd_ptr)))
  1699. {
  1700. /*
  1701. * end of paragraph spec
  1702. */
  1703. case '>':
  1704. (cur_vars->rd_ptr)++;
  1705. done = True;
  1706. break;
  1707. /*
  1708. * after value
  1709. */
  1710. case 'a':
  1711. if (GetValueParameter (cur_vars, _DtCvFALSE, &value) == -1)
  1712. return -1;
  1713. _DtCvContainerBMarginOfSeg(para) = 0;
  1714. if (value > 0 && 0 < cur_vars->ui_info->line_height)
  1715. _DtCvContainerBMarginOfSeg(para) = value *
  1716. (cur_vars->ui_info->line_height / 2);
  1717. break;
  1718. /*
  1719. * before value
  1720. */
  1721. case 'b':
  1722. if (GetValueParameter (cur_vars, _DtCvFALSE, &value) == -1)
  1723. return -1;
  1724. _DtCvContainerTMarginOfSeg(para) = 0;
  1725. if (value > 0 && 0 < cur_vars->ui_info->line_height)
  1726. _DtCvContainerTMarginOfSeg(para) = value *
  1727. (cur_vars->ui_info->line_height / 2);
  1728. break;
  1729. /*
  1730. * description [string | "string" | 'string']
  1731. */
  1732. case 'd':
  1733. result = GetStringParameter(cur_vars, _DtCvTRUE, _DtCvTRUE,
  1734. _DtCvFALSE, _DtCvFALSE, description);
  1735. break;
  1736. /*
  1737. * firstindent value
  1738. */
  1739. case 'f':
  1740. if (GetValueParameter (cur_vars, _DtCvFALSE, &value) == -1)
  1741. return -1;
  1742. _DtCvContainerFMarginOfSeg(para) =
  1743. value * cur_vars->ui_info->avg_char;
  1744. break;
  1745. /*
  1746. * glink [string | "string" | 'string']
  1747. * gpos value_string
  1748. * graphic string
  1749. * gspace value
  1750. * gtypelink value
  1751. */
  1752. case 'g':
  1753. /*
  1754. * to determine what token this is we must look at the
  1755. * second character.
  1756. */
  1757. (cur_vars->rd_ptr)++;
  1758. /*
  1759. * do we need to read more?
  1760. */
  1761. if (*(cur_vars->rd_ptr) == '\0'
  1762. && GetNextBuffer(cur_vars) == -1)
  1763. return -1;
  1764. /*
  1765. * check for the next permutation
  1766. */
  1767. switch (_DtCvToLower(*(cur_vars->rd_ptr)))
  1768. {
  1769. /*
  1770. * glink [string | "string" | 'string']
  1771. */
  1772. case 'l':
  1773. result = GetStringParameter(cur_vars, _DtCvTRUE,
  1774. _DtCvTRUE, _DtCvFALSE, _DtCvFALSE, glink);
  1775. break;
  1776. /*
  1777. * gpos value_string
  1778. */
  1779. case 'p':
  1780. result = GetStringParameter(cur_vars, _DtCvTRUE,
  1781. _DtCvTRUE, _DtCvFALSE, _DtCvFALSE, &tmpString);
  1782. if (-1 != result && _DtCvToLower (*tmpString) == 'r')
  1783. *gpos = _DtCvJUSTIFY_RIGHT;
  1784. if (tmpString)
  1785. free (tmpString);
  1786. break;
  1787. /*
  1788. * graphic string
  1789. */
  1790. case 'r':
  1791. result = GetStringParameter(cur_vars, _DtCvTRUE,
  1792. _DtCvTRUE, _DtCvFALSE, _DtCvFALSE, file_name);
  1793. break;
  1794. /*
  1795. * gspace value
  1796. */
  1797. case 's':
  1798. if (GetValueParameter(cur_vars,_DtCvFALSE,&value) == -1
  1799. || value < 0)
  1800. return -1;
  1801. *gspace = value * cur_vars->ui_info->avg_char;
  1802. break;
  1803. /*
  1804. * gtypelink value
  1805. */
  1806. case 't':
  1807. if (GetValueParameter(cur_vars,_DtCvFALSE,glinktype) == -1
  1808. || *glinktype < 0)
  1809. return -1;
  1810. break;
  1811. }
  1812. break;
  1813. /*
  1814. * id string
  1815. */
  1816. case 'i':
  1817. /*
  1818. * get the id string
  1819. */
  1820. if (GetStringParameter(cur_vars, _DtCvTRUE, _DtCvTRUE,
  1821. _DtCvFALSE, _DtCvFALSE, &tmpString) == -1)
  1822. return -1;
  1823. _DtCvContainerIdOfSeg(para) = tmpString;
  1824. break;
  1825. /*
  1826. * label [string | "string" | 'string']
  1827. * leftindent value
  1828. */
  1829. case 'l':
  1830. /*
  1831. * to determine what token this is we must look at the
  1832. * second and possibly the third characters.
  1833. */
  1834. (cur_vars->rd_ptr)++;
  1835. /*
  1836. * do we need to read more?
  1837. */
  1838. if (*(cur_vars->rd_ptr) == '\0'
  1839. && GetNextBuffer(cur_vars) == -1)
  1840. return -1;
  1841. /*
  1842. * check for the next permutation
  1843. */
  1844. if (_DtCvToLower(*(cur_vars->rd_ptr)) == 'a')
  1845. {
  1846. /*
  1847. * label
  1848. */
  1849. if (GetStringParameter(cur_vars, _DtCvTRUE, _DtCvFALSE,
  1850. _DtCvFALSE, _DtCvFALSE, &tmpString) == -1)
  1851. return -1;
  1852. /*
  1853. * If we got a label process it.
  1854. */
  1855. if (ret_label == NULL || *ret_label)
  1856. {
  1857. /*
  1858. * we've already processed a label!
  1859. * ignore this one!
  1860. */
  1861. if (tmpString)
  1862. free (tmpString);
  1863. }
  1864. else
  1865. *ret_label = tmpString;
  1866. }
  1867. else if (_DtCvToLower(*(cur_vars->rd_ptr)) == 'e')
  1868. {
  1869. /*
  1870. * leftindent
  1871. */
  1872. if (GetValueParameter (cur_vars, _DtCvFALSE, &value) == -1)
  1873. return -1;
  1874. _DtCvContainerLMarginOfSeg(para) =
  1875. value * cur_vars->ui_info->avg_char;
  1876. }
  1877. else
  1878. result = -1;
  1879. break;
  1880. /*
  1881. * nowrap
  1882. */
  1883. case 'n':
  1884. _DtCvContainerTypeOfSeg(para) = _DtCvLITERAL;
  1885. *frmt_type = _DtCvLITERAL;
  1886. break;
  1887. /*
  1888. * rightindent value
  1889. */
  1890. case 'r':
  1891. if (GetValueParameter (cur_vars, _DtCvFALSE, &value) == -1)
  1892. return -1;
  1893. _DtCvContainerRMarginOfSeg(para) =
  1894. value * cur_vars->ui_info->avg_char;
  1895. break;
  1896. /*
  1897. * wrap
  1898. */
  1899. case 'w':
  1900. _DtCvContainerTypeOfSeg(para) = _DtCvDYNAMIC;
  1901. *frmt_type = _DtCvDYNAMIC;
  1902. break;
  1903. /*
  1904. * Found an option we don't understand.
  1905. */
  1906. default:
  1907. result = -1;
  1908. }
  1909. optionCount++;
  1910. }
  1911. /*
  1912. * adjust the first margin to correctly indicate the offset from the
  1913. * left margin. In the old CCDF, the first margin indicated left plus
  1914. * and additional indent. For the new Canvas Engine, it is suppose
  1915. * to be an addition on top of the left margin.
  1916. */
  1917. _DtCvContainerFMarginOfSeg(para) = _DtCvContainerLMarginOfSeg(para) -
  1918. _DtCvContainerFMarginOfSeg(para);
  1919. if (-1 == result)
  1920. optionCount = 0;
  1921. return (optionCount - 1);
  1922. } /* End GetParagraphParameters */
  1923. /******************************************************************************
  1924. * Function: int FlowingParagraph (
  1925. *
  1926. * Parameters:
  1927. *
  1928. * Returns:
  1929. *
  1930. * errno Values:
  1931. *
  1932. * Purpose: Process the <PARAGRAPH> specification.
  1933. *
  1934. *****************************************************************************/
  1935. static int
  1936. FlowingParagraph(
  1937. FormatVariables *cur_vars,
  1938. ProcessState cur_state,
  1939. _DtCvFrmtOption frmt_flags,
  1940. int allowed,
  1941. int link_idx,
  1942. int ret_on_nl,
  1943. int fnt_flag,
  1944. _DtCvFrmtOption gpos,
  1945. _DtCvUnit gspace,
  1946. char *file_name,
  1947. _DtHelpFontHints *font_attr)
  1948. {
  1949. int type = 0;
  1950. int result = -1;
  1951. _DtCvSegment *graphSeg;
  1952. _DtCvSegment *bodySeg;
  1953. SegList flowList = InitList;
  1954. /*
  1955. * reset current list
  1956. */
  1957. cur_vars->my_list = InitList;
  1958. /*
  1959. * create two containers.
  1960. */
  1961. if (0 == CheckList(&(flowList), 2, 2))
  1962. {
  1963. /*
  1964. * point to the containers for the graphic and body.
  1965. */
  1966. graphSeg = flowList.list;
  1967. bodySeg = flowList.list;
  1968. bodySeg++;
  1969. /*
  1970. * set the bottom margins to zero.
  1971. */
  1972. graphSeg->type = _DtCvSetTypeToContainer(graphSeg->type);
  1973. bodySeg->type = _DtCvSetTypeToContainer(bodySeg->type);
  1974. _DtCvContainerBMarginOfSeg(graphSeg) = 0;
  1975. _DtCvContainerBMarginOfSeg(bodySeg) = 0;
  1976. /*
  1977. * so the first segment is the container for the graphic.
  1978. * set the controller flag and values.
  1979. */
  1980. graphSeg->type = _DtCvSetTypeToController(graphSeg->type);
  1981. _DtCvContainerFlowOfSeg(graphSeg) = _DtCvWRAP;
  1982. _DtCvContainerPercentOfSeg(graphSeg) = 0;
  1983. _DtCvContainerOrientOfSeg(graphSeg) = gpos;
  1984. if (_DtCvJUSTIFY_LEFT == gpos)
  1985. {
  1986. _DtCvContainerJustifyOfSeg(graphSeg) = gpos;
  1987. _DtCvContainerRMarginOfSeg(graphSeg) = gspace;
  1988. }
  1989. else
  1990. {
  1991. _DtCvContainerJustifyOfSeg(graphSeg) = gpos;
  1992. _DtCvContainerLMarginOfSeg(graphSeg) = gspace;
  1993. }
  1994. /*
  1995. * mark the first segment as used.
  1996. */
  1997. flowList.cnt++;
  1998. /*
  1999. * check for hypertext link.
  2000. */
  2001. if (link_idx > -1)
  2002. type = _DtCvHYPER_TEXT;
  2003. /*
  2004. * re-set the segment list and create the graphic.
  2005. */
  2006. if (0 == CreateSaveGraphic(cur_vars, type, file_name, link_idx))
  2007. {
  2008. /*
  2009. * so the first segment in cur_vars is a region.
  2010. * attach it to the graphic container.
  2011. */
  2012. _DtCvContainerListOfSeg(graphSeg) = cur_vars->my_list.list;
  2013. /*
  2014. * now process the following information as the body of
  2015. * the paragraph as the list for the non-controller
  2016. * container.
  2017. */
  2018. cur_vars->my_list = InitList;
  2019. if (-1 != Parse (CCDF_PARAGRAPH_CMD, cur_state, cur_vars,
  2020. 0, frmt_flags,
  2021. font_attr, -1,
  2022. Specials, allowed,
  2023. ret_on_nl, fnt_flag))
  2024. {
  2025. /*
  2026. * establish the links between the segments
  2027. */
  2028. TerminateSegList(&(cur_vars->my_list), True);
  2029. /*
  2030. * if there was a segment list generated,
  2031. * attach the it to the non-controller
  2032. * container and mark it as used.
  2033. */
  2034. if (NULL != cur_vars->my_list.list)
  2035. {
  2036. _DtCvContainerListOfSeg(bodySeg) = cur_vars->my_list.list;
  2037. flowList.cnt++;
  2038. }
  2039. result = 0;
  2040. }
  2041. }
  2042. }
  2043. cur_vars->my_list = flowList;
  2044. TerminateSegList(&(cur_vars->my_list), True);
  2045. return result;
  2046. }
  2047. /******************************************************************************
  2048. * Function: int ProcessParagraph (
  2049. *
  2050. * Parameters:
  2051. *
  2052. * Returns:
  2053. *
  2054. * errno Values:
  2055. *
  2056. * Purpose: Process the <PARAGRAPH> specification.
  2057. *
  2058. *****************************************************************************/
  2059. static int
  2060. ProcessParagraph(
  2061. FormatVariables *cur_vars,
  2062. ProcessState cur_state,
  2063. int fnt_flag)
  2064. {
  2065. int result = 0;
  2066. int labelFnd = False;
  2067. int allowed = ~(CCDF_TOPIC_CMD | CCDF_TITLE_CMD | CCDF_ABBREV_CMD);
  2068. int oldMbLenMax = cur_vars->cur_mb_max;
  2069. int glinktype = -1;
  2070. int linkIndex = -1;
  2071. _DtCvUnit gspace = 0;
  2072. char *glinkSpec = NULL;
  2073. char *label = NULL;
  2074. char *fileName = NULL;
  2075. char *description = NULL;
  2076. char numChar[16];
  2077. ProcessState myState = NormalState;
  2078. _DtCvFrmtOption gpos;
  2079. _DtCvFrmtOption frmtType = _DtCvDYNAMIC;
  2080. _DtCvSegment *paraSeg;
  2081. _DtCvSegment *labelSeg = NULL;
  2082. _DtCvSegment *col1 = NULL;
  2083. _DtCvSegment *col2 = NULL;
  2084. _DtCvSegment **childList;
  2085. SegList oldList;
  2086. SegList tableList = InitList;
  2087. _DtHelpFontHints fontAttrs;
  2088. /*
  2089. * remember the old font list.
  2090. * initialize the font quark list
  2091. * and use the char set specified for this topic.
  2092. */
  2093. _DtHelpCeCopyDefFontAttrList (&fontAttrs);
  2094. cur_vars->cur_mb_max = cur_vars->topic_mb_max;
  2095. _DtHelpFontHintsLang(fontAttrs) = cur_vars->topic_lang;
  2096. _DtHelpFontHintsCharSet(fontAttrs) = cur_vars->topic_char_set;
  2097. /*
  2098. * Make next segment in my parent's list for a container for this
  2099. * paragraph.
  2100. */
  2101. if (-1 == CheckSegList(cur_vars))
  2102. return -1;
  2103. /*
  2104. * remember the parent list
  2105. * make sure the defaults are set
  2106. */
  2107. oldList = cur_vars->my_list;
  2108. paraSeg = NextAvailSeg(cur_vars->my_list);
  2109. paraSeg->handle.container = DefContainer;
  2110. paraSeg->type = _DtCvSetTypeToContainer(paraSeg->type);
  2111. _DtCvContainerLeadingOfSeg(paraSeg) = cur_vars->ui_info->leading;
  2112. cur_vars->my_list = InitList;
  2113. /*
  2114. * get the parameters on the paragraph
  2115. * and set the default for the bottom.
  2116. */
  2117. result = GetParagraphParameters (cur_vars, paraSeg, &frmtType,
  2118. &gpos, &glinkSpec, &glinktype, &gspace,
  2119. &label, &fileName, &description);
  2120. /*
  2121. * for lists, we will inherit our parent's bottom margin
  2122. * when we return to the loop processing the list. Therefore,
  2123. * set our bottom margin to zero if we are part of a label body.
  2124. */
  2125. if (0 == result && LabelBody == cur_state)
  2126. _DtCvContainerBMarginOfSeg(paraSeg) = 0;
  2127. else if (result > 0)
  2128. result = 0;
  2129. /*
  2130. * check for a label specification. Either as a 'label' parameter
  2131. * or a the <LABEL> command.
  2132. */
  2133. if (-1 != result)
  2134. {
  2135. /*
  2136. * check for the parameter
  2137. */
  2138. if (NULL != label)
  2139. {
  2140. FormatVariables oldVars = *cur_vars;
  2141. cur_vars->rd_buf = label;
  2142. cur_vars->rd_flag = 0;
  2143. cur_vars->rd_ptr = label;
  2144. cur_vars->my_file = NULL;
  2145. result = Parse (CCDF_LABEL_CMD, NormalState, cur_vars,
  2146. 0, frmtType,
  2147. &fontAttrs, -1,
  2148. Specials,
  2149. (CCDF_FONT_CMD | CCDF_OCTAL_CMD),
  2150. False, fnt_flag);
  2151. if (result != -1)
  2152. result = CheckSaveSegment (_DtCvSTRING, &fontAttrs,
  2153. -1, cur_vars);
  2154. TerminateSegList(&(cur_vars->my_list), True);
  2155. cur_vars->rd_buf = oldVars.rd_buf;
  2156. cur_vars->rd_flag = oldVars.rd_flag;
  2157. cur_vars->rd_ptr = oldVars.rd_ptr;
  2158. cur_vars->my_file = oldVars.my_file;
  2159. cur_vars->last_was_space = True;
  2160. labelSeg = cur_vars->my_list.list;
  2161. cur_vars->my_list = InitList;
  2162. labelFnd = True;
  2163. }
  2164. /*
  2165. * check for the command.
  2166. */
  2167. else if (0 == _DtHelpCeCheckNextCcdfCmd("lab", cur_vars->my_file,
  2168. cur_vars->rd_buf,
  2169. cur_vars->rd_size, 1,
  2170. &(cur_vars->rd_ptr)))
  2171. {
  2172. result = ProcessLabelCmd(cur_vars, 0, frmtType,
  2173. &fontAttrs, -1,
  2174. allowed, False, fnt_flag,
  2175. &labelSeg);
  2176. labelFnd = True;
  2177. }
  2178. /*
  2179. * if a label was processed, create the containers for it.
  2180. */
  2181. if (-1 != result && True == labelFnd)
  2182. {
  2183. /*
  2184. * set the correct state.
  2185. */
  2186. myState = LabelBody;
  2187. /*
  2188. * create containers for the label and it's body
  2189. */
  2190. result = CheckList(&tableList, 2, 2);
  2191. if (-1 != result)
  2192. {
  2193. /*
  2194. * set the top and bottom margins on both the child
  2195. * containers (so they are the same) to reflect
  2196. * the list's before/after values.
  2197. */
  2198. /*
  2199. * set the pointer to the first column
  2200. * overwrite the left and right margin values.
  2201. */
  2202. col1 = NextAvailSeg(tableList);
  2203. col1->type = _DtCvSetTypeToContainer(col1->type);
  2204. _DtCvContainerTMarginOfSeg(col1) =
  2205. _DtCvContainerTMarginOfSeg(paraSeg);
  2206. _DtCvContainerBMarginOfSeg(col1) =
  2207. _DtCvContainerBMarginOfSeg(paraSeg);
  2208. _DtCvContainerLMarginOfSeg(col1) = 0;
  2209. _DtCvContainerRMarginOfSeg(col1) = cur_vars->ui_info->avg_char;
  2210. tableList.cnt++;
  2211. /*
  2212. * set the pointer for the second column
  2213. * and set the top/bottom values.
  2214. */
  2215. col2 = NextAvailSeg(tableList);
  2216. col2->type = _DtCvSetTypeToContainer(col2->type);
  2217. _DtCvContainerTMarginOfSeg(col2) =
  2218. _DtCvContainerTMarginOfSeg(paraSeg);
  2219. _DtCvContainerBMarginOfSeg(col2) =
  2220. _DtCvContainerBMarginOfSeg(paraSeg);
  2221. tableList.cnt++;
  2222. /*
  2223. * create an id for this label
  2224. */
  2225. sprintf(numChar, "%d", cur_vars->cell_cnt++);
  2226. _DtCvContainerIdOfSeg(col1) = (char *) malloc (
  2227. strlen("&CCDF_RES_") + strlen(numChar) + 1);
  2228. if (NULL != _DtCvContainerIdOfSeg(col1))
  2229. {
  2230. /*
  2231. * copy over the id and attach the list.
  2232. */
  2233. strcpy(_DtCvContainerIdOfSeg(col1), "&CCDF_RES_");
  2234. strcat(_DtCvContainerIdOfSeg(col1), numChar);
  2235. _DtCvContainerListOfSeg(col1) = labelSeg;
  2236. /*
  2237. * set the id for the second column.
  2238. */
  2239. sprintf(numChar, "%d", cur_vars->cell_cnt++);
  2240. _DtCvContainerIdOfSeg(col2) = (char *) malloc (
  2241. strlen("&CCDF_RES_") + strlen(numChar) + 1);
  2242. if (NULL != _DtCvContainerIdOfSeg(col2))
  2243. {
  2244. strcpy(_DtCvContainerIdOfSeg(col2), "&CCDF_RES_");
  2245. strcat(_DtCvContainerIdOfSeg(col2), numChar);
  2246. }
  2247. else
  2248. result = -1;
  2249. }
  2250. else
  2251. result = -1;
  2252. }
  2253. }
  2254. }
  2255. /*
  2256. * disallow labels from here on out. Either one was found and processed
  2257. * or not.
  2258. */
  2259. allowed &= (~(CCDF_LABEL_CMD));
  2260. /*
  2261. * Now check and process the graphic specification.
  2262. */
  2263. if (-1 != result)
  2264. {
  2265. /*
  2266. * initialize the segment list for the children of the paragraph.
  2267. */
  2268. cur_vars->my_list = InitList;
  2269. /*
  2270. * check for a graphic in the specification.
  2271. * If so, then we need to create, as the list for the
  2272. * paragraph container, two containers; one container
  2273. * that is a controller and has the graphic and the
  2274. * other contains the rest of the content of the
  2275. * paragraph.
  2276. *
  2277. * First, create the link index for the graphic.
  2278. */
  2279. if (NULL != glinkSpec)
  2280. {
  2281. /*
  2282. * but if there isn't a graphic, throw away the link
  2283. * specifications since they are useless!
  2284. */
  2285. if (NULL != fileName && strlen (glinkSpec))
  2286. {
  2287. linkIndex = _DtLinkDbAddLink (cur_vars->my_links,
  2288. NULL,
  2289. glinkSpec,
  2290. ReturnLinkType(glinktype, glinkSpec),
  2291. ReturnLinkWinHint(glinktype),
  2292. description);
  2293. /*
  2294. * had problems creating the link index, bail
  2295. */
  2296. if (linkIndex == -1)
  2297. result = -1;
  2298. }
  2299. }
  2300. /*
  2301. * now create the graphic and process the graphic body..
  2302. * or just process the rest of the paragraph....
  2303. */
  2304. if (0 == result)
  2305. {
  2306. if (NULL != fileName)
  2307. result = FlowingParagraph(cur_vars,
  2308. myState,
  2309. frmtType,
  2310. allowed, linkIndex,
  2311. False, fnt_flag,
  2312. gpos, gspace, fileName,
  2313. &fontAttrs);
  2314. else
  2315. {
  2316. result = Parse (CCDF_PARAGRAPH_CMD, myState, cur_vars,
  2317. 0, frmtType,
  2318. &fontAttrs, -1,
  2319. Specials, allowed,
  2320. False, fnt_flag);
  2321. if (-1 != result)
  2322. {
  2323. /*
  2324. * establish the links
  2325. */
  2326. TerminateSegList (&(cur_vars->my_list), True);
  2327. }
  2328. }
  2329. }
  2330. if (-1 != result)
  2331. {
  2332. char **colW;
  2333. _DtCvFrmtOption *colJ;
  2334. if (True == labelFnd)
  2335. {
  2336. char *colW1 = "1"; /* default bulletted list */
  2337. char *colW2 = "99,0,98"; /* default bulletted list */
  2338. char *ids;
  2339. /*
  2340. * set the body of the label in it's container.
  2341. */
  2342. _DtCvContainerListOfSeg(col2) = cur_vars->my_list.list;
  2343. /*
  2344. * figure out which column widths should be used.
  2345. */
  2346. if (14 * cur_vars->ui_info->avg_char
  2347. == _DtCvContainerLMarginOfSeg(paraSeg))
  2348. {
  2349. /* Labeled lists */
  2350. colW1 = "20,20,10";
  2351. colW2 = "80,10,20";
  2352. }
  2353. else if (3 * cur_vars->ui_info->avg_char
  2354. == _DtCvContainerLMarginOfSeg(paraSeg))
  2355. /* Ordered lists */
  2356. colW1 = "1,98,0";
  2357. else if (0 == _DtCvContainerLMarginOfSeg(paraSeg))
  2358. /* Plain lists */
  2359. colW1 = "0";
  2360. /*
  2361. * create the column width strings.
  2362. */
  2363. colW = NULL;
  2364. colW = (char **) _DtCvAddPtrToArray((void **) colW,
  2365. ((void *) strdup(colW1)));
  2366. if (NULL != colW)
  2367. colW = (char **) _DtCvAddPtrToArray((void **) colW,
  2368. ((void *) strdup (colW2)));
  2369. /*
  2370. * create the array for column justification.
  2371. */
  2372. colJ = (_DtCvFrmtOption *) malloc (sizeof(_DtCvFrmtOption) * 2);
  2373. if (NULL != colJ)
  2374. {
  2375. colJ[0] = _DtCvJUSTIFY_LEFT;
  2376. colJ[1] = _DtCvJUSTIFY_LEFT;
  2377. }
  2378. /*
  2379. * set this segment's type to a table and fill in all
  2380. * the relevant information.
  2381. */
  2382. paraSeg->type = _DtCvTABLE;
  2383. _DtCvNumColsOfTableSeg(paraSeg) = 2;
  2384. _DtCvColWOfTableSeg(paraSeg) = colW;
  2385. _DtCvColJustifyOfTableSeg(paraSeg) = colJ;
  2386. _DtCvJustifyCharsOfTableSeg(paraSeg) = NULL;
  2387. /*
  2388. * now create the list of ids in this table.
  2389. */
  2390. ids = (char *) malloc (
  2391. strlen(_DtCvContainerIdOfSeg(col1)) +
  2392. strlen(_DtCvContainerIdOfSeg(col2)) + 2);
  2393. if (NULL != ids)
  2394. {
  2395. strcpy(ids, _DtCvContainerIdOfSeg(col1));
  2396. strcat(ids, " ");
  2397. strcat(ids, _DtCvContainerIdOfSeg(col2));
  2398. }
  2399. _DtCvCellIdsOfTableSeg(paraSeg) = NULL;
  2400. _DtCvCellIdsOfTableSeg(paraSeg) = (char **)
  2401. _DtCvAddPtrToArray(
  2402. (void **) _DtCvCellIdsOfTableSeg(paraSeg),
  2403. (void *) ids);
  2404. /*
  2405. * now create the list of cells in the table.
  2406. */
  2407. _DtCvCellsOfTableSeg(paraSeg) = NULL;
  2408. _DtCvCellsOfTableSeg(paraSeg) = (_DtCvSegment **)
  2409. _DtCvAddPtrToArray(
  2410. (void **) _DtCvCellsOfTableSeg(paraSeg),
  2411. (void *) col1);
  2412. if (NULL != _DtCvCellsOfTableSeg(paraSeg))
  2413. _DtCvCellsOfTableSeg(paraSeg) = (_DtCvSegment **)
  2414. _DtCvAddPtrToArray(
  2415. (void **) _DtCvCellsOfTableSeg(paraSeg),
  2416. (void *) col2);
  2417. if (NULL == colW || NULL == colJ || NULL == ids
  2418. || NULL == _DtCvCellIdsOfTableSeg(paraSeg)
  2419. || NULL == _DtCvCellsOfTableSeg(paraSeg))
  2420. result = -1;
  2421. }
  2422. else
  2423. {
  2424. _DtCvSegment *pSeg;
  2425. /*
  2426. * attach the list to my container.
  2427. */
  2428. _DtCvContainerListOfSeg(paraSeg) = cur_vars->my_list.list;
  2429. /*
  2430. * consolidate any table children I have.
  2431. */
  2432. for (pSeg = cur_vars->my_list.list, labelSeg = NULL;
  2433. -1 != result && NULL != pSeg;
  2434. pSeg = pSeg->next_seg)
  2435. {
  2436. if (_DtCvIsSegTable(pSeg))
  2437. {
  2438. if (NULL != labelSeg)
  2439. {
  2440. /*
  2441. * bypass this segment since it will no
  2442. * longer be 'used' by consolidating it
  2443. * with another label set.
  2444. */
  2445. labelSeg->next_seg = pSeg->next_seg;
  2446. /*
  2447. * free the other justification and width info.
  2448. */
  2449. free((void *) _DtCvColJustifyOfTableSeg(pSeg));
  2450. colW = _DtCvColWOfTableSeg(pSeg);
  2451. free(*colW++);
  2452. free(*colW);
  2453. free(_DtCvColWOfTableSeg(pSeg));
  2454. /*
  2455. * add the segments to the list
  2456. */
  2457. childList = _DtCvCellsOfTableSeg(pSeg);
  2458. _DtCvCellsOfTableSeg(labelSeg) = (_DtCvSegment **)
  2459. _DtCvAddPtrToArray(
  2460. (void **) _DtCvCellsOfTableSeg(labelSeg),
  2461. *childList);
  2462. childList++;
  2463. if (NULL != _DtCvCellsOfTableSeg(labelSeg))
  2464. _DtCvCellsOfTableSeg(labelSeg) = (_DtCvSegment **)
  2465. _DtCvAddPtrToArray(
  2466. (void **)_DtCvCellsOfTableSeg(labelSeg),
  2467. *childList);
  2468. free((void *) _DtCvCellsOfTableSeg(pSeg));
  2469. /*
  2470. * add the ids to the list
  2471. */
  2472. _DtCvCellIdsOfTableSeg(labelSeg) = (char **)
  2473. _DtCvAddPtrToArray(
  2474. (void **)_DtCvCellIdsOfTableSeg(labelSeg),
  2475. (void *)(*(_DtCvCellIdsOfTableSeg(pSeg))));
  2476. free((void *) _DtCvCellIdsOfTableSeg(pSeg));
  2477. if (NULL == _DtCvCellIdsOfTableSeg(labelSeg)
  2478. || NULL == _DtCvCellsOfTableSeg(labelSeg))
  2479. result = -1;
  2480. }
  2481. else
  2482. {
  2483. /*
  2484. * this segment becomes the segment holding
  2485. * the consolidated table.
  2486. */
  2487. labelSeg = pSeg;
  2488. }
  2489. }
  2490. else
  2491. labelSeg = NULL;
  2492. }
  2493. }
  2494. }
  2495. }
  2496. /*
  2497. * restore the font MB_CUR_MAX
  2498. */
  2499. cur_vars->cur_mb_max = oldMbLenMax;
  2500. /*
  2501. * free all the strings
  2502. */
  2503. if (label != NULL)
  2504. free (label);
  2505. if (fileName != NULL)
  2506. free (fileName);
  2507. /*
  2508. * free the linkSpec and description,
  2509. */
  2510. if (NULL != description)
  2511. free(description);
  2512. if (NULL != glinkSpec)
  2513. free(glinkSpec);
  2514. if (result == -1)
  2515. return -1;
  2516. oldList.cnt++;
  2517. cur_vars->my_list = oldList;
  2518. cur_vars->last_was_space = True;
  2519. return 0;
  2520. } /* End ProcessParagraph */
  2521. /******************************************************************************
  2522. * Function: int ProcessHypertext (
  2523. * FormatVariables *cur_vars, int segType,
  2524. * char **font_attr, int flags )
  2525. *
  2526. * Parameters:
  2527. * segType Specifies the type of segment currently
  2528. * being processed.
  2529. * font_attr Specifies the list of font quarks to
  2530. * associate with the string.
  2531. * flags Specifies the formatting commands allowed.
  2532. *
  2533. * Returns: 0 if successful, -1 if errors.
  2534. *
  2535. * errno Values:
  2536. *
  2537. * Purpose: Process the <LINK> specification.
  2538. *
  2539. *****************************************************************************/
  2540. static int
  2541. ProcessHypertext(
  2542. FormatVariables *cur_vars,
  2543. ProcessState cur_state,
  2544. unsigned long seg_flags,
  2545. _DtCvFrmtOption frmt_type,
  2546. _DtHelpFontHints *font_attr,
  2547. int flags,
  2548. int ret_on_nl,
  2549. int fnt_flag)
  2550. {
  2551. int result = 0;
  2552. int hyperType;
  2553. int hyperIndex;
  2554. char *description = NULL;
  2555. char *hyperlink = NULL;
  2556. /*
  2557. * is a <LINK> command allowed here?
  2558. */
  2559. if (CCDF_NOT_ALLOW_CMD(flags, CCDF_LINK_CMD))
  2560. return -1;
  2561. /*
  2562. * get the hypertext type
  2563. */
  2564. if (GetValueParameter (cur_vars, _DtCvTRUE, &hyperType) < 0)
  2565. return -1;
  2566. if (hyperType < 0)
  2567. {
  2568. errno = CEErrorHyperType;
  2569. return -1;
  2570. }
  2571. /*
  2572. * get the hypertext link spec.
  2573. */
  2574. result = GetStringParameter(cur_vars, _DtCvTRUE, _DtCvTRUE, _DtCvFALSE,
  2575. _DtCvFALSE, &hyperlink);
  2576. if (0 == result)
  2577. {
  2578. /*
  2579. * See if we have the optional description string
  2580. */
  2581. result = GetStringParameter (cur_vars, _DtCvFALSE, _DtCvTRUE,
  2582. _DtCvFALSE, _DtCvFALSE, &description);
  2583. if (result == 1)
  2584. description = NULL;
  2585. result = _DtLinkDbAddLink (cur_vars->my_links,
  2586. NULL,
  2587. hyperlink,
  2588. ReturnLinkType(hyperType, hyperlink),
  2589. ReturnLinkWinHint(hyperType),
  2590. description);
  2591. if (NULL != description)
  2592. free(description);
  2593. free(hyperlink);
  2594. }
  2595. /*
  2596. * if no problems encountered, start parsing with this
  2597. * hypertext link.
  2598. */
  2599. if (result != -1)
  2600. {
  2601. hyperIndex = result;
  2602. result = FindEndMarker (cur_vars);
  2603. if (!result)
  2604. {
  2605. /*
  2606. * set the hypertext flag and type.
  2607. */
  2608. seg_flags = _DtCvSetTypeToHyperText(seg_flags);
  2609. result = Parse (CCDF_LINK_CMD, cur_state, cur_vars,
  2610. seg_flags, frmt_type,
  2611. font_attr,
  2612. hyperIndex,
  2613. Specials, flags,
  2614. ret_on_nl, fnt_flag);
  2615. }
  2616. }
  2617. /*
  2618. * Don't free the hypertext string or description.
  2619. * It is now owned by the Link List.
  2620. */
  2621. if (result == -1)
  2622. return -1;
  2623. return 0;
  2624. } /* End ProcessHypertext */
  2625. /******************************************************************************
  2626. * Function: int ProcessLabelCmd (
  2627. * FormatVariables *cur_vars, int seg_type,
  2628. * char **font_attr, int link_spec,
  2629. * int flags )
  2630. *
  2631. * Parameters:
  2632. * font_attr Specifies the list of font quarks to
  2633. * associate with the string.
  2634. * link_spec Specifies the hypertext link to associate
  2635. * with the string.
  2636. * flags Specifies the formatting commands allowed.
  2637. *
  2638. * Returns: 0 if successful, -1 if errors.
  2639. *
  2640. * errno Values:
  2641. *
  2642. * Purpose: Process the <LABEL> specification.
  2643. *
  2644. *****************************************************************************/
  2645. static int
  2646. ProcessLabelCmd(
  2647. FormatVariables *cur_vars,
  2648. unsigned long seg_flags,
  2649. _DtCvFrmtOption frmt_type,
  2650. _DtHelpFontHints *font_attr,
  2651. int link_spec,
  2652. int flags,
  2653. int ret_on_nl,
  2654. int fnt_flag,
  2655. _DtCvSegment **ret_list)
  2656. {
  2657. SegList oldList = cur_vars->my_list;
  2658. /*
  2659. * is a <LABEL> command allowed?
  2660. */
  2661. if (CCDF_NOT_ALLOW_CMD(flags, CCDF_LABEL_CMD))
  2662. return -1;
  2663. /*
  2664. * can't have another <LABEL> command inside this one
  2665. */
  2666. flags &= (~(CCDF_LABEL_CMD));
  2667. /*
  2668. * Find the end marker
  2669. */
  2670. if (FindEndMarker (cur_vars) != 0)
  2671. return -1;
  2672. cur_vars->my_list = InitList;
  2673. if (Parse (CCDF_LABEL_CMD, NormalState, cur_vars,
  2674. seg_flags,
  2675. frmt_type,
  2676. font_attr,
  2677. link_spec,
  2678. Specials, flags,
  2679. ret_on_nl, fnt_flag) == -1)
  2680. return -1;
  2681. /*
  2682. * set the links, return the segment list and restore the old list.
  2683. */
  2684. TerminateSegList(&(cur_vars->my_list), True);
  2685. *ret_list = cur_vars->my_list.list;
  2686. cur_vars->my_list = oldList;
  2687. /*
  2688. * Indicate that preceding space on the next text should be ignored
  2689. */
  2690. cur_vars->last_was_space = True;
  2691. return 0;
  2692. } /* End ProcessLabelCmd */
  2693. /******************************************************************************
  2694. * Function: int ProcessFigureCmd (
  2695. * FormatVariables *cur_vars,
  2696. * char **font_attr)
  2697. *
  2698. * Parameters:
  2699. * font_attr Specifies the list of font quarks to
  2700. * associate with the string.
  2701. *
  2702. * Returns: 0 if successful, -1 if errors.
  2703. *
  2704. * errno Values:
  2705. *
  2706. * Purpose: Process the <FIGURE> specification.
  2707. *
  2708. *****************************************************************************/
  2709. static int
  2710. ProcessFigureCmd(
  2711. FormatVariables *cur_vars,
  2712. ProcessState cur_state,
  2713. _DtCvFrmtOption frmt_type,
  2714. _DtHelpFontHints *font_attr,
  2715. int ret_on_nl,
  2716. int fnt_flag)
  2717. {
  2718. int cnt;
  2719. int done = False;
  2720. int result = 0;
  2721. int linkType = CCDF_LINK_JUMP_REUSE;
  2722. int linkIndex = -1;
  2723. int segType = _DtCvREGION;
  2724. char *description = NULL;
  2725. char *idString = NULL;
  2726. char *filename = NULL;
  2727. char *linkspec = NULL;
  2728. _DtCvFrmtOption vertOrientCap = _DtCvJUSTIFY_BOTTOM;
  2729. _DtCvFrmtOption horzOrientCap = _DtCvJUSTIFY_CENTER;
  2730. _DtCvFrmtOption justifyCap = _DtCvJUSTIFY_CENTER;
  2731. _DtCvFrmtOption justifyGraphic = _DtCvJUSTIFY_CENTER;
  2732. _DtCvSegment *figContainer;
  2733. SegList oldList;
  2734. SegList capList;
  2735. SegList figList = InitList;
  2736. /*
  2737. * create a container for this figure (and possibly a caption)
  2738. */
  2739. if (-1 == CheckSegList(cur_vars))
  2740. return -1;
  2741. figContainer = NextAvailSeg(cur_vars->my_list);
  2742. figContainer->handle.container = DefContainer;
  2743. figContainer->type = _DtCvSetTypeToContainer(figContainer->type);
  2744. _DtCvContainerLeadingOfSeg(figContainer) = cur_vars->ui_info->leading;
  2745. /*
  2746. * remember the old list and initialize for the figure.
  2747. */
  2748. oldList = cur_vars->my_list;
  2749. cur_vars->my_list = InitList;
  2750. /*
  2751. * process the parameters of the figure cmd.
  2752. */
  2753. while (!done && result != -1)
  2754. {
  2755. if (SkipToNextToken (cur_vars, _DtCvFALSE) == -1)
  2756. {
  2757. result = -1;
  2758. continue;
  2759. }
  2760. switch (_DtCvToLower(*(cur_vars->rd_ptr)))
  2761. {
  2762. /*
  2763. * end of figure spec
  2764. */
  2765. case '>':
  2766. /*
  2767. * move past the end of token marker
  2768. * and skip the leading blanks in the caption.
  2769. */
  2770. (cur_vars->rd_ptr)++;
  2771. while (result != -1 && !done)
  2772. {
  2773. if (*(cur_vars->rd_ptr) == '\0')
  2774. result = GetNextBuffer (cur_vars);
  2775. else if ((cur_vars->cur_mb_max == 1 ||
  2776. mblen(cur_vars->rd_ptr, cur_vars->cur_mb_max) == 1)
  2777. && *(cur_vars->rd_ptr) == ' ')
  2778. (cur_vars->rd_ptr)++;
  2779. else
  2780. done = True;
  2781. }
  2782. break;
  2783. /*
  2784. * ccenter
  2785. * center
  2786. * cbottom
  2787. * cleft
  2788. * cright
  2789. * ctop
  2790. */
  2791. case 'c':
  2792. /*
  2793. * Go to the next character.
  2794. */
  2795. (cur_vars->rd_ptr)++;
  2796. /*
  2797. * Do we need to read more information?
  2798. */
  2799. if (*(cur_vars->rd_ptr) == '\0' && GetNextBuffer (cur_vars) == -1)
  2800. result = -1;
  2801. if (result != -1)
  2802. {
  2803. /*
  2804. * look at the next charager to determine the token.
  2805. */
  2806. switch (_DtCvToLower(*(cur_vars->rd_ptr)))
  2807. {
  2808. case 'c': /* caption center */
  2809. justifyCap = _DtCvJUSTIFY_CENTER;
  2810. horzOrientCap = _DtCvJUSTIFY_CENTER;
  2811. break;
  2812. case 'e': /* graphic centered */
  2813. justifyGraphic = _DtCvJUSTIFY_CENTER;
  2814. break;
  2815. case 'b': /* caption below graphic */
  2816. vertOrientCap = _DtCvJUSTIFY_BOTTOM;
  2817. break;
  2818. case 'l': /* caption justified left */
  2819. justifyCap = _DtCvJUSTIFY_LEFT;
  2820. horzOrientCap = _DtCvJUSTIFY_LEFT_MARGIN;
  2821. break;
  2822. case 'r': /* caption right justified */
  2823. justifyCap = _DtCvJUSTIFY_RIGHT;
  2824. horzOrientCap = _DtCvJUSTIFY_RIGHT_MARGIN;
  2825. break;
  2826. case 't': /* caption at top */
  2827. vertOrientCap = _DtCvJUSTIFY_TOP;
  2828. break;
  2829. }
  2830. }
  2831. break;
  2832. /*
  2833. * description [string | "string" | 'string']
  2834. */
  2835. case 'd':
  2836. result = GetStringParameter (cur_vars, _DtCvTRUE, _DtCvTRUE,
  2837. _DtCvFALSE, _DtCvFALSE, &description);
  2838. break;
  2839. /*
  2840. * file
  2841. */
  2842. case 'f':
  2843. result = GetStringParameter (cur_vars, _DtCvTRUE, _DtCvTRUE,
  2844. _DtCvFALSE, _DtCvFALSE, &filename);
  2845. break;
  2846. /*
  2847. * id string
  2848. */
  2849. case 'i':
  2850. /*
  2851. * get the id string
  2852. */
  2853. result = GetStringParameter (cur_vars, _DtCvTRUE, _DtCvTRUE,
  2854. _DtCvFALSE, _DtCvFALSE, &idString);
  2855. /*
  2856. * if this figure had an id associated with it, create
  2857. * marker segment for it.
  2858. */
  2859. if (-1 != result && NULL != idString && '\0' != *idString)
  2860. {
  2861. /*
  2862. * create the marker. If there is an error, free the
  2863. * string.
  2864. */
  2865. result = CreateMarker(cur_vars, idString);
  2866. if (-1 == result)
  2867. free (idString);
  2868. }
  2869. break;
  2870. /*
  2871. * left
  2872. * link [string | "string" | 'string']
  2873. */
  2874. case 'l':
  2875. /*
  2876. * Go to the next character.
  2877. */
  2878. (cur_vars->rd_ptr)++;
  2879. /*
  2880. * Do we need to read more information?
  2881. */
  2882. if (*(cur_vars->rd_ptr) == '\0' && GetNextBuffer (cur_vars) == -1)
  2883. result = -1;
  2884. if (result != -1)
  2885. {
  2886. /*
  2887. * look at the next charager to determine the token.
  2888. */
  2889. switch (_DtCvToLower(*(cur_vars->rd_ptr)))
  2890. {
  2891. case 'e':
  2892. justifyGraphic = _DtCvJUSTIFY_LEFT;
  2893. break;
  2894. case 'i':
  2895. segType = _DtCvSetTypeToHyperText (segType);
  2896. result = GetStringParameter (cur_vars, _DtCvTRUE,
  2897. _DtCvTRUE, _DtCvFALSE, _DtCvFALSE,
  2898. &linkspec);
  2899. break;
  2900. default:
  2901. result = -1;
  2902. }
  2903. }
  2904. break;
  2905. /*
  2906. * right
  2907. */
  2908. case 'r':
  2909. justifyGraphic = _DtCvJUSTIFY_RIGHT;
  2910. break;
  2911. /*
  2912. * typelink value
  2913. */
  2914. case 't':
  2915. if (GetValueParameter (cur_vars, _DtCvTRUE, &linkType) == -1)
  2916. result = -1;
  2917. else if (linkType < 0)
  2918. {
  2919. errno = CEErrorHyperType;
  2920. result = -1;
  2921. }
  2922. break;
  2923. default:
  2924. result = -1;
  2925. }
  2926. }
  2927. if (result != -1 && (filename == NULL || strlen(filename) == 0))
  2928. result = -1;
  2929. if (result != -1)
  2930. {
  2931. /*
  2932. * check to see if the hypertext flag is set but we don't
  2933. * have a link specification.
  2934. */
  2935. if (IsTypeHyperText(segType) && !linkspec)
  2936. {
  2937. segType = segType & ~(_DtCvHYPER_TEXT);
  2938. if (NULL != description)
  2939. free (description);
  2940. description = NULL;
  2941. }
  2942. /*
  2943. * do we still have a good hypertext?
  2944. * if so, create a link index for it.
  2945. */
  2946. if (IsTypeHyperText(segType))
  2947. {
  2948. linkIndex = _DtLinkDbAddLink (cur_vars->my_links,
  2949. NULL,
  2950. linkspec,
  2951. ReturnLinkType(linkType, linkspec),
  2952. ReturnLinkWinHint(linkType),
  2953. description);
  2954. if (linkIndex == -1)
  2955. result = -1;
  2956. }
  2957. }
  2958. if (result != -1)
  2959. {
  2960. /*
  2961. * parse the caption. If there is a caption, we will need to
  2962. * wrap it and the figure in containers with the appropriate
  2963. * controller flags set to get the correct layout.
  2964. */
  2965. result = Parse (CCDF_FIGURE_CMD, cur_state, cur_vars,
  2966. 0, frmt_type,
  2967. font_attr, -1,
  2968. Specials,
  2969. (CCDF_NEWLINE_CMD | CCDF_LINK_CMD |
  2970. CCDF_FONT_CMD | CCDF_ID_CMD),
  2971. ret_on_nl, fnt_flag);
  2972. /*
  2973. * save the caption List.
  2974. */
  2975. TerminateSegList(&(cur_vars->my_list), True);
  2976. capList = cur_vars->my_list;
  2977. /*
  2978. * is there a caption? If so, create two segments instead
  2979. * of one.
  2980. */
  2981. cnt = 1;
  2982. if (-1 != result && 0 != capList.cnt)
  2983. cnt = 2;
  2984. /*
  2985. * allocate room for the figure (and caption)
  2986. */
  2987. if (-1 != result)
  2988. result = CheckList(&figList, cnt, cnt);
  2989. if (-1 != result)
  2990. {
  2991. /*
  2992. * process any caption that was specified
  2993. */
  2994. if (0 != capList.cnt)
  2995. {
  2996. _DtCvSegment *pSeg = figList.list;
  2997. /*
  2998. * create a controller for the caption.
  2999. */
  3000. pSeg->type = _DtCvSetTypeToController(
  3001. _DtCvSetTypeToContainer(pSeg->type));
  3002. /*
  3003. * set its orientation and justification.
  3004. */
  3005. _DtCvContainerOrientOfSeg(pSeg) = horzOrientCap;
  3006. _DtCvContainerVOrientOfSeg(pSeg) = vertOrientCap;
  3007. _DtCvContainerJustifyOfSeg(pSeg) = justifyCap;
  3008. _DtCvContainerBMarginOfSeg(pSeg) = 0;
  3009. /*
  3010. * attach the caption to the container.
  3011. */
  3012. _DtCvContainerListOfSeg(pSeg) = capList.list;
  3013. /*
  3014. * indicate this segment has been used.
  3015. */
  3016. figList.cnt++;
  3017. }
  3018. /*
  3019. * now load the graphic into the next available segment
  3020. * allocated for the figure.
  3021. */
  3022. cur_vars->my_list = figList;
  3023. result = CreateSaveGraphic (cur_vars, segType, filename, linkIndex);
  3024. /*
  3025. * if no problems, attach the figure (and caption) to the
  3026. * wrapper container
  3027. */
  3028. if (-1 != result)
  3029. {
  3030. /*
  3031. * set the links
  3032. */
  3033. TerminateSegList(&(cur_vars->my_list), True);
  3034. /*
  3035. * attach the figure (and caption) to the wrapper
  3036. */
  3037. _DtCvContainerListOfSeg(figContainer) = cur_vars->my_list.list;
  3038. /*
  3039. * set the justify to the correct value to act on the
  3040. * figure.
  3041. */
  3042. _DtCvContainerJustifyOfSeg(figContainer) = justifyGraphic;
  3043. /*
  3044. * indicate that this segment has been used
  3045. */
  3046. oldList.cnt++;
  3047. }
  3048. }
  3049. }
  3050. /*
  3051. * restore the segment list.
  3052. * and free memory.
  3053. */
  3054. cur_vars->my_list = oldList;
  3055. free (filename);
  3056. /*
  3057. * don't free the link string or description,
  3058. * the link list owns them now.
  3059. */
  3060. return result;
  3061. } /* End ProcessFigureCmd */
  3062. /******************************************************************************
  3063. * Function: int ProcessInLine (FormatVariables cur_vars,
  3064. * int seg_type, int link_spec )
  3065. *
  3066. * Parameters:
  3067. * seg_type Specifes the type of segment currently
  3068. * being processed.
  3069. * link_spec Specifies the hypertext link associated
  3070. * with this segment.
  3071. *
  3072. * Returns: 0 if successful, -1 if errors.
  3073. *
  3074. * errno Values:
  3075. *
  3076. * Purpose: Process a <GRAPHIC> specification.
  3077. *
  3078. *****************************************************************************/
  3079. static int
  3080. ProcessInLine(
  3081. FormatVariables *cur_vars,
  3082. int seg_type,
  3083. int link_spec )
  3084. {
  3085. int done = False;
  3086. int result = 0;
  3087. char *idString = NULL;
  3088. char *filename = NULL;
  3089. /*
  3090. * process the graphic parameters
  3091. */
  3092. while (!done && result != -1)
  3093. {
  3094. if (SkipToNextToken (cur_vars, _DtCvFALSE) == -1)
  3095. return -1;
  3096. switch (_DtCvToLower(*(cur_vars->rd_ptr)))
  3097. {
  3098. /*
  3099. * end of in line spec
  3100. */
  3101. case '>':
  3102. /*
  3103. * move past the end of token marker
  3104. */
  3105. (cur_vars->rd_ptr)++;
  3106. done = True;
  3107. break;
  3108. /*
  3109. * file
  3110. */
  3111. case 'f':
  3112. result = GetStringParameter (cur_vars, _DtCvTRUE, _DtCvTRUE,
  3113. _DtCvFALSE, _DtCvFALSE, &filename);
  3114. break;
  3115. /*
  3116. * id string
  3117. */
  3118. case 'i':
  3119. /*
  3120. * get the id string
  3121. */
  3122. result = GetStringParameter (cur_vars, _DtCvTRUE, _DtCvTRUE,
  3123. _DtCvFALSE, _DtCvFALSE, &idString);
  3124. /*
  3125. * if this graphic had an id associated with it, create
  3126. * marker segment for it.
  3127. */
  3128. if (-1 != result && NULL != idString && '\0' != *idString)
  3129. {
  3130. /*
  3131. * create the marker. If there is an error, free the
  3132. * string.
  3133. */
  3134. result = CreateMarker(cur_vars, idString);
  3135. if (-1 == result)
  3136. free (idString);
  3137. }
  3138. break;
  3139. default:
  3140. result = -1;
  3141. }
  3142. }
  3143. if (result != -1 && (filename == NULL || strlen(filename) == 0))
  3144. result = -1;
  3145. if (result != -1)
  3146. {
  3147. /*
  3148. * create the graphic.
  3149. */
  3150. result = CreateSaveGraphic (cur_vars,
  3151. _DtCvSetTypeToInLine(seg_type),
  3152. filename, link_spec);
  3153. cur_vars->last_was_space = False;
  3154. }
  3155. free (filename);
  3156. return result;
  3157. } /* End ProcessInLine */
  3158. /******************************************************************************
  3159. * Function: int CheckIdString (
  3160. * FormatVariables *cur_vars, int segType,
  3161. * char **font_attr, int linkspec,
  3162. * int flags)
  3163. *
  3164. * Parameters:
  3165. * segType Specifies the type of segment currently
  3166. * being processed.
  3167. * font_attr Specifies the list of font quarks to
  3168. * associate with the string.
  3169. * linkspec Specifies the hypertext link associated
  3170. * with the segment.
  3171. * flags Specifies the formatting commands allowed.
  3172. *
  3173. * Returns: 0 if successful, -1 if errors.
  3174. *
  3175. * errno Values:
  3176. *
  3177. * Purpose: Create a marker at this location.
  3178. *
  3179. *****************************************************************************/
  3180. static int
  3181. CheckIdString(
  3182. FormatVariables *cur_vars,
  3183. ProcessState cur_state,
  3184. unsigned long seg_flags,
  3185. _DtCvFrmtOption frmt_type,
  3186. _DtHelpFontHints *font_attr,
  3187. int linkspec,
  3188. int flags,
  3189. int ret_on_nl,
  3190. int fnt_flag)
  3191. {
  3192. int result = -1;
  3193. char *ptr = NULL;
  3194. /*
  3195. * is it legal to have a <ID> command at this point?
  3196. */
  3197. if (CCDF_NOT_ALLOW_CMD (flags, CCDF_ID_CMD))
  3198. return -1;
  3199. /*
  3200. * get the id string
  3201. * clear out any current information in the buffer
  3202. * and make sure there is a segment available.
  3203. */
  3204. if (-1 != GetStringParameter (cur_vars, _DtCvTRUE, _DtCvTRUE,
  3205. _DtCvFALSE, _DtCvFALSE, &ptr)
  3206. &&
  3207. -1 != CheckSaveSegment (seg_flags, font_attr, linkspec, cur_vars))
  3208. {
  3209. /*
  3210. * create the marker. If there is an error, free the
  3211. * string.
  3212. */
  3213. result = CreateMarker(cur_vars, ptr);
  3214. if (-1 == result)
  3215. free (ptr);
  3216. /*
  3217. * find the end of the <ID> syntax
  3218. * and parse the data between the begin <ID> and </ID>.
  3219. */
  3220. if (0 == result && -1 != FindEndMarker (cur_vars) &&
  3221. -1 != Parse (CCDF_ID_CMD, cur_state, cur_vars,
  3222. seg_flags, frmt_type,
  3223. font_attr,
  3224. linkspec,
  3225. Specials, flags,
  3226. ret_on_nl, fnt_flag))
  3227. result = 0;
  3228. }
  3229. /*
  3230. * return an error code if necessary
  3231. */
  3232. return result;
  3233. } /* End CheckIdString */
  3234. /******************************************************************************
  3235. * Function: int Parse (int cur_cmd,
  3236. * FormatVariables *cur_vars, int segType,
  3237. * char **font_attr,
  3238. * int linkspec, int allowed)
  3239. *
  3240. * Parameters:
  3241. * cur_cmd Specifies the current formatting command
  3242. * being processed.
  3243. * parent Specifies the parent paragraph.
  3244. * segType Specifies the type of segment currently
  3245. * being processed.
  3246. * font_attr Specifies the list of font quarks to
  3247. * associate with the string.
  3248. * linkspec Specifies the hypertext link associated
  3249. * with the segment.
  3250. * allowed Specifies the formatting commands allowed.
  3251. *
  3252. * Returns:
  3253. * 1 if ran into a </> specification.
  3254. * -1 if errors.
  3255. *
  3256. * errno Values:
  3257. *
  3258. * Purpose: Parse the data.
  3259. *
  3260. *****************************************************************************/
  3261. static int
  3262. Parse(
  3263. int cur_cmd,
  3264. ProcessState cur_state,
  3265. FormatVariables *cur_vars,
  3266. unsigned long seg_flags,
  3267. _DtCvFrmtOption frmt_type,
  3268. _DtHelpFontHints *font_attr,
  3269. int linkspec,
  3270. const char *scan_string,
  3271. int allowed,
  3272. int ret_on_nl,
  3273. int fnt_flag)
  3274. {
  3275. int charSize = 1;
  3276. int leftOver = 0;
  3277. int done = False;
  3278. int fontType = False;
  3279. int cmdType = False;
  3280. char *ptr;
  3281. while (!done)
  3282. {
  3283. if (cur_vars->cur_mb_max != 1)
  3284. charSize = mblen(cur_vars->rd_ptr, cur_vars->cur_mb_max);
  3285. if (charSize == 1)
  3286. {
  3287. /*
  3288. * check to see if a newline was the previous character.
  3289. * If so, it may need to be replaced with a space.
  3290. */
  3291. if (cur_vars->last_was_nl == True &&
  3292. AppendSpaceToInfo(cur_vars, NULL, frmt_type) == -1)
  3293. return -1;
  3294. cur_vars->last_was_nl = False;
  3295. cur_vars->last_was_mb = False;
  3296. switch (*(cur_vars->rd_ptr))
  3297. {
  3298. case '<':
  3299. /*
  3300. * Go to the next character.
  3301. */
  3302. (cur_vars->rd_ptr)++;
  3303. /*
  3304. * determine the cmd
  3305. */
  3306. cmdType = _DtHelpCeGetCcdfCmd (cur_cmd, cur_vars->rd_buf,
  3307. &(cur_vars->rd_ptr),
  3308. cur_vars->my_file,
  3309. cur_vars->rd_size,
  3310. allowed);
  3311. switch (cmdType)
  3312. {
  3313. /*
  3314. * <figure>
  3315. */
  3316. case CCDF_FIGURE_CMD:
  3317. if (CheckSaveSegment(seg_flags, font_attr,
  3318. linkspec, cur_vars) == -1
  3319. ||
  3320. ProcessFigureCmd(cur_vars,
  3321. cur_state,
  3322. frmt_type,
  3323. font_attr,
  3324. ret_on_nl, fnt_flag) == -1)
  3325. return -1;
  3326. break;
  3327. /*
  3328. * <angle>
  3329. * <characterset>
  3330. * <size>
  3331. * <spacing>
  3332. * <type>
  3333. * <weight>
  3334. */
  3335. case CCDF_FONT_CMD:
  3336. fontType = _DtHelpCeGetCcdfFontType (cur_vars->rd_ptr);
  3337. done = ChangeFont(fontType, seg_flags,
  3338. frmt_type,
  3339. font_attr , linkspec,
  3340. cur_vars,
  3341. cur_state,
  3342. allowed,
  3343. ret_on_nl,
  3344. fnt_flag);
  3345. break;
  3346. /*
  3347. * </>
  3348. */
  3349. case CCDF_FORMAT_END:
  3350. if (CheckSaveSegment(seg_flags, font_attr,
  3351. linkspec, cur_vars) == -1 ||
  3352. FindEndMarker (cur_vars) == -1)
  3353. return -1;
  3354. return 1;
  3355. /*
  3356. * <graphic>
  3357. */
  3358. case CCDF_GRAPHIC_CMD:
  3359. /*
  3360. * clear out any information
  3361. * in the buffer and then
  3362. * process the figure.
  3363. */
  3364. if (CheckSaveSegment (seg_flags, font_attr,
  3365. linkspec, cur_vars) == -1
  3366. ||
  3367. ProcessInLine (cur_vars, seg_flags,
  3368. linkspec) == -1)
  3369. done = -1;
  3370. break;
  3371. /*
  3372. * <id>
  3373. */
  3374. case CCDF_ID_CMD:
  3375. done = CheckIdString (cur_vars,
  3376. cur_state,
  3377. seg_flags,
  3378. frmt_type,
  3379. font_attr,
  3380. linkspec,
  3381. allowed,
  3382. ret_on_nl, fnt_flag);
  3383. break;
  3384. /*
  3385. * <link>
  3386. */
  3387. case CCDF_LINK_CMD:
  3388. if (CheckSaveSegment (seg_flags, font_attr,
  3389. linkspec, cur_vars) == -1
  3390. ||
  3391. ProcessHypertext(cur_vars, cur_state,
  3392. seg_flags, frmt_type,
  3393. font_attr, allowed,
  3394. ret_on_nl, fnt_flag) == -1)
  3395. done = -1;
  3396. break;
  3397. /*
  3398. * <newline>
  3399. */
  3400. case CCDF_NEWLINE_CMD:
  3401. if (SaveNewLine (cur_vars, seg_flags, font_attr,
  3402. linkspec) == -1
  3403. ||
  3404. FindEndMarker (cur_vars) == -1)
  3405. done = -1;
  3406. break;
  3407. case CCDF_OCTAL_CMD:
  3408. if (AppendOctalToInfo(cur_vars,
  3409. cur_vars->rd_ptr) == -1
  3410. || FindEndMarker (cur_vars) == -1)
  3411. done = -1;
  3412. break;
  3413. /*
  3414. * <paragraph>
  3415. */
  3416. case CCDF_PARAGRAPH_CMD:
  3417. if (CheckSaveSegment (seg_flags, font_attr,
  3418. linkspec, cur_vars) == -1
  3419. ||
  3420. ProcessParagraph(cur_vars, cur_state,
  3421. fnt_flag) == -1)
  3422. done = -1;
  3423. break;
  3424. /*
  3425. * <label>
  3426. * this should never be hit if the markup is
  3427. * correct. Processing labels is through the
  3428. * the paragraph processor now.
  3429. */
  3430. case CCDF_LABEL_CMD:
  3431. /*
  3432. * unknown command.
  3433. */
  3434. default:
  3435. return -1;
  3436. }
  3437. break;
  3438. case '\n':
  3439. /*
  3440. * Go to the next character
  3441. */
  3442. (cur_vars->rd_ptr)++;
  3443. /*
  3444. * If processing a static segment, we want to
  3445. * keep the author defined end-of-lines.
  3446. *
  3447. * Otherwise, we throw them away.
  3448. */
  3449. if (_DtCvLITERAL == frmt_type || True == ret_on_nl)
  3450. {
  3451. done = SaveStringAsSegments (cur_vars,
  3452. _DtCvSetTypeToNewLine(seg_flags),
  3453. font_attr, linkspec);
  3454. if (ret_on_nl)
  3455. return 0;
  3456. }
  3457. else if (cur_vars->last_was_space == False)
  3458. cur_vars->last_was_nl = True;
  3459. break;
  3460. case '\t':
  3461. /*
  3462. * go past this character.
  3463. */
  3464. (cur_vars->rd_ptr)++;
  3465. /*
  3466. * append 1-8 characters on the end of the buffer.
  3467. */
  3468. _DtHelpCeCountChars(cur_vars->fmt_buf, MB_CUR_MAX,
  3469. &leftOver);
  3470. leftOver = leftOver % 8;
  3471. ptr = ((char *) SpaceString) + leftOver;
  3472. done = _DtHelpCeAddStrToBuf (&ptr,
  3473. &(cur_vars->fmt_buf),
  3474. &(cur_vars->fmt_size),
  3475. &(cur_vars->fmt_buf_max),
  3476. (8 - leftOver),
  3477. INFO_GROW);
  3478. break;
  3479. case '\\':
  3480. /*
  3481. * The author has escaped a character.
  3482. * Increment to the escaped character.
  3483. */
  3484. (cur_vars->rd_ptr)++;
  3485. /*
  3486. * Do we need to read more information?
  3487. */
  3488. if (*(cur_vars->rd_ptr) == '\0' &&
  3489. GetNextBuffer (cur_vars) == -1)
  3490. return -1;
  3491. /*
  3492. * If we didn't read more information or
  3493. * was successful on the read, save the
  3494. * escaped character.
  3495. */
  3496. done = AppendCharToInfo (cur_vars, &(cur_vars->rd_ptr));
  3497. break;
  3498. case ' ':
  3499. /*
  3500. * Put a space in the segment.
  3501. */
  3502. done = AppendSpaceToInfo (cur_vars,
  3503. &(cur_vars->rd_ptr), frmt_type);
  3504. break;
  3505. default:
  3506. /*
  3507. * put the information in the buffer
  3508. */
  3509. if (AppendToInfo (cur_vars, &(cur_vars->rd_ptr),
  3510. scan_string) == -1)
  3511. return -1;
  3512. }
  3513. }
  3514. else if (charSize > 1)
  3515. {
  3516. if ((cur_vars->ui_info->nl_to_space == 1 ||
  3517. (cur_vars->last_was_mb == False
  3518. && cur_vars->last_was_nl == True))
  3519. && AppendSpaceToInfo(cur_vars, NULL, frmt_type) == -1)
  3520. done = -1;
  3521. cur_vars->last_was_nl = False;
  3522. cur_vars->last_was_mb = True;
  3523. if (AppendToInfo (cur_vars, &(cur_vars->rd_ptr), scan_string) == -1)
  3524. return -1;
  3525. }
  3526. else if (charSize < 0)
  3527. {
  3528. /*
  3529. * we have either invalid characters or part of a multi-byte
  3530. * character. Read the next buffer for more info.
  3531. */
  3532. leftOver = strlen (cur_vars->rd_ptr);
  3533. if (leftOver < ((int) MB_CUR_MAX))
  3534. {
  3535. if (GetNextBuffer (cur_vars) == -1)
  3536. done = -1;
  3537. }
  3538. else
  3539. {
  3540. /*
  3541. * In trouble brothers and sisters. We have garbage in the
  3542. * buffer - BAIL OUT!
  3543. */
  3544. done = -1;
  3545. }
  3546. }
  3547. if (!done && *(cur_vars->rd_ptr) == '\0')
  3548. {
  3549. /*
  3550. * We're at the end of the buffer, can we read more?
  3551. */
  3552. if (cur_vars->rd_flag > 0 && GetNextBuffer (cur_vars) == -1)
  3553. return -1;
  3554. if (cur_vars->rd_flag == 0)
  3555. done = True;
  3556. }
  3557. }
  3558. /*
  3559. * DO NOT MODIFY 'done' HERE
  3560. * If you do, the caller is unable to test for return value == 1!!!!
  3561. */
  3562. if (done == -1 ||
  3563. CheckSaveSegment (seg_flags, font_attr, linkspec, cur_vars) == -1)
  3564. return -1;
  3565. return done;
  3566. }
  3567. /*****************************************************************************
  3568. * Function: int ParseTitle (FormatVariables cur_vars)
  3569. *
  3570. * Parameters:
  3571. * cur_vars Specifies the current values for formatting.
  3572. *
  3573. * Returns: 0 if successful, -1 if failure.
  3574. *
  3575. * errno Values:
  3576. *
  3577. * Purpose: ParseTitle gets the data between a <TITLE> and </TITLE>
  3578. * pair; putting it in a controlling container.
  3579. *
  3580. *****************************************************************************/
  3581. static int
  3582. ParseTitle(
  3583. FormatVariables *cur_vars,
  3584. int cont_flag,
  3585. int skip_abbrev,
  3586. int fnt_flag,
  3587. _DtHelpFontHints *fontAttrs)
  3588. {
  3589. int result = -1;
  3590. SegList oldList = cur_vars->my_list;
  3591. /*
  3592. * rest the current segment list
  3593. */
  3594. cur_vars->my_list = InitList;
  3595. /*
  3596. * check for the <TITLE> directive.
  3597. */
  3598. if (_DtHelpCeCheckNextCcdfCmd ("ti", cur_vars->my_file, cur_vars->rd_buf,
  3599. cur_vars->rd_size, 1, &(cur_vars->rd_ptr)) != 0
  3600. || FindEndMarker (cur_vars) != 0)
  3601. return -1;
  3602. /*
  3603. * Parse will return
  3604. * 1 when a </> is found,
  3605. * 0 if the data runs out before we finish parsing,
  3606. * -1 if errors.
  3607. *
  3608. * A return of 1 is required from Parse
  3609. */
  3610. if (1 == Parse (CCDF_TITLE_CMD, NormalState, cur_vars,
  3611. 0, _DtCvDYNAMIC,
  3612. fontAttrs, -1, Specials,
  3613. ~(CCDF_TOPIC_CMD | CCDF_TITLE_CMD | CCDF_ABBREV_CMD |
  3614. CCDF_PARAGRAPH_CMD | CCDF_FIGURE_CMD | CCDF_LABEL_CMD),
  3615. False, fnt_flag))
  3616. {
  3617. /*
  3618. * skip the any abbreviation that might be there
  3619. */
  3620. result = 0;
  3621. if (skip_abbrev)
  3622. result = _DtHelpCeSkipCcdfAbbrev (cur_vars->my_file,
  3623. cur_vars->rd_buf,
  3624. &(cur_vars->rd_ptr), cur_vars->rd_size,
  3625. cur_vars->cur_mb_max);
  3626. /*
  3627. * if we successfully skipped the abbreviation and there is
  3628. * a title - then attach the title body to the controlling
  3629. * container (and make the container a controller).
  3630. */
  3631. if (result != -1 && cur_vars->my_list.list)
  3632. {
  3633. _DtCvSegment *list = oldList.list;
  3634. int cnt = oldList.cnt;
  3635. TerminateSegList (&(cur_vars->my_list), True);
  3636. /*
  3637. * when this segment was allocated, it was initialized
  3638. * to the correct vertical and horizontal orientation
  3639. * for a CCDF title. Simply set the type to container
  3640. * and controller to get it to act properly.
  3641. */
  3642. if (NULL != list)
  3643. {
  3644. list[cnt].type = _DtCvSetTypeToContainer(list[cnt].type);
  3645. if (True == cont_flag)
  3646. list[cnt].type = _DtCvSetTypeToController(list[cnt].type);
  3647. /*
  3648. * attach the title body to the controller container.
  3649. */
  3650. _DtCvContainerListOfSeg(&list[cnt]) = cur_vars->my_list.list;
  3651. /*
  3652. * and count this segment as used.
  3653. */
  3654. oldList.cnt++;
  3655. }
  3656. /*
  3657. * otherwise, a container hasn't been created for this list.
  3658. * but we don't want to loose the information.
  3659. */
  3660. else
  3661. oldList.list = cur_vars->my_list.list;
  3662. }
  3663. }
  3664. /*
  3665. * restore segment usage information.
  3666. */
  3667. cur_vars->my_list = oldList;
  3668. return result;
  3669. }
  3670. /*****************************************************************************
  3671. * Function: int Format (FormatVariables cur_vars, char *id_string,
  3672. *
  3673. * Parameters:
  3674. *
  3675. * Returns:
  3676. *
  3677. * errno Values:
  3678. *
  3679. * Purpose: Format is the top entry point for formating Help Files with
  3680. * formatting information into a form understood by a display area.
  3681. * It will keep calling Parse, until the entire topic is read
  3682. * or an error occurs.
  3683. *
  3684. *****************************************************************************/
  3685. static int
  3686. Format(
  3687. FormatVariables *cur_vars,
  3688. _FrmtUiInfo *ui_info,
  3689. char *id_string,
  3690. _DtCvTopicPtr *ret_topic )
  3691. {
  3692. int result = 0;
  3693. int done = 0;
  3694. char *charSet = NULL;
  3695. char readBuf[BUFF_SIZE];
  3696. _DtHelpFontHints fontAttrs;
  3697. _DtCvTopicInfo *topicHandle;
  3698. SegList myList = InitList;
  3699. /*
  3700. * malloc space for the topic handle.
  3701. */
  3702. topicHandle = (_DtCvTopicInfo *) malloc (sizeof(_DtCvTopicInfo));
  3703. if (topicHandle == NULL)
  3704. return -1;
  3705. /*
  3706. * initialize the font attributes to the default hints
  3707. */
  3708. _DtHelpCeCopyDefFontAttrList (&fontAttrs);
  3709. /*
  3710. * set up the formatting variable structure
  3711. */
  3712. if (InitStructure (cur_vars, ui_info, readBuf, BUFF_SIZE) == -1)
  3713. return -1;
  3714. /*
  3715. * read the first buffer's worth of the topic.
  3716. */
  3717. cur_vars->rd_flag = _DtHelpCeReadBuf (cur_vars->my_file, cur_vars->rd_buf,
  3718. cur_vars->rd_size);
  3719. if (cur_vars->rd_flag == -1)
  3720. return -1;
  3721. /*
  3722. * The first command in the buffer MUST be the <TOPIC> command.
  3723. * It is in a one byte charset.
  3724. */
  3725. if (_DtHelpCeGetCcdfTopicCmd (((void *) NULL), cur_vars->my_file,
  3726. cur_vars->rd_buf, &(cur_vars->rd_ptr),
  3727. cur_vars->rd_size, 1, &charSet) == -1)
  3728. return -1;
  3729. /*
  3730. * change the character set to the returned character set
  3731. * Assume that the charset is 'iso8859' if not specified.
  3732. */
  3733. cur_vars->cur_mb_max = 1;
  3734. if (NULL != charSet)
  3735. GetMbLen(cur_vars, charSet, &(_DtHelpFontHintsLang(fontAttrs)),
  3736. &(_DtHelpFontHintsCharSet(fontAttrs)));
  3737. /*
  3738. * Remember the topic code set and MB_CUR_MAX.
  3739. */
  3740. cur_vars->topic_char_set = _DtHelpFontHintsCharSet(fontAttrs);
  3741. cur_vars->topic_lang = _DtHelpFontHintsLang(fontAttrs);
  3742. cur_vars->topic_mb_max = cur_vars->cur_mb_max;
  3743. /*
  3744. * allocate two segments for the topic - one for the <title>
  3745. * and one for the body of the topic.
  3746. */
  3747. if (0 != CheckList(&(cur_vars->my_list), 2, 2))
  3748. {
  3749. if (NULL != charSet)
  3750. {
  3751. free(_DtHelpFontHintsLang(fontAttrs));
  3752. free(_DtHelpFontHintsCharSet(fontAttrs));
  3753. free(charSet);
  3754. }
  3755. return -1;
  3756. }
  3757. /*
  3758. * get the title and skip the abbreviation.
  3759. */
  3760. if (0 != ParseTitle(cur_vars, True, True, 0, &fontAttrs))
  3761. {
  3762. if (NULL != charSet)
  3763. {
  3764. free(_DtHelpFontHintsLang(fontAttrs));
  3765. free(_DtHelpFontHintsCharSet(fontAttrs));
  3766. free(charSet);
  3767. }
  3768. return -1;
  3769. }
  3770. /*
  3771. * remember this current list since we will be attaching any more
  3772. * information as a child of these segments.
  3773. */
  3774. myList = cur_vars->my_list;
  3775. /*
  3776. * process the rest of the information
  3777. */
  3778. while (0 == result && !done)
  3779. {
  3780. /*
  3781. * reset the segment count before processing the information
  3782. * for this paragraph
  3783. */
  3784. cur_vars->my_list = InitList;
  3785. /*
  3786. * make sure we've got a container for this paragraph
  3787. */
  3788. done = CheckList(&myList, 1, GROW_SIZE);
  3789. /*
  3790. * now process the information while finding paragraphs.
  3791. */
  3792. if (0 == done)
  3793. do {
  3794. done = Parse (CCDF_PARAGRAPH_CMD, NormalState, cur_vars,
  3795. 0, _DtCvDYNAMIC,
  3796. &fontAttrs, -1, Specials,
  3797. ~(CCDF_TOPIC_CMD | CCDF_TITLE_CMD | CCDF_ABBREV_CMD),
  3798. False, 0);
  3799. } while (0 == done);
  3800. /*
  3801. * if no errors, attach the resulting child information to the
  3802. * paragraph container.
  3803. */
  3804. if (done != -1)
  3805. {
  3806. /*
  3807. * clean up the last segment.
  3808. */
  3809. if (cur_vars->my_list.list)
  3810. {
  3811. _DtCvSegment *list = NextAvailSeg(myList);
  3812. TerminateSegList (&(cur_vars->my_list), True);
  3813. /*
  3814. * make it a container.
  3815. */
  3816. list->type = _DtCvSetTypeToContainer(list->type);
  3817. /*
  3818. * attach the information to the container
  3819. */
  3820. _DtCvContainerListOfSeg(list) = cur_vars->my_list.list;
  3821. /*
  3822. * and count this container as used.
  3823. */
  3824. myList.cnt++;
  3825. }
  3826. }
  3827. else
  3828. result = -1;
  3829. }
  3830. /*
  3831. * If we had errors, deallocate the memory.
  3832. */
  3833. if (result == -1)
  3834. _DtHelpFreeSegments(myList.list, _DtCvFALSE, ui_info->destroy_region,
  3835. ui_info->client_data);
  3836. else
  3837. {
  3838. /*
  3839. * Tighten up the paragraph structures if too many allocated.
  3840. */
  3841. if (0 != myList.cnt)
  3842. TerminateSegList (&(myList), True);
  3843. else
  3844. {
  3845. free ((char *) myList.list);
  3846. myList.list = NULL;
  3847. }
  3848. }
  3849. /*
  3850. * return the values, even if they are null and zero.
  3851. */
  3852. if (id_string == NULL)
  3853. topicHandle->id_str = id_string;
  3854. else
  3855. topicHandle->id_str = strdup(id_string);
  3856. topicHandle->seg_list = myList.list;
  3857. topicHandle->mark_list = NULL;
  3858. topicHandle->link_data = cur_vars->my_links;
  3859. *ret_topic = (void *) topicHandle;
  3860. /*
  3861. * free memory
  3862. */
  3863. if (NULL != charSet)
  3864. {
  3865. free(_DtHelpFontHintsLang(fontAttrs));
  3866. free(_DtHelpFontHintsCharSet(fontAttrs));
  3867. free(charSet);
  3868. }
  3869. if (result == -1)
  3870. return -1;
  3871. return 0;
  3872. }
  3873. /*****************************************************************************
  3874. * Function: int FormatCCDFTitle (FormatVariables cur_vars
  3875. *
  3876. * Parameters:
  3877. * cur_vars Specifies the current values for formatting.
  3878. * id_string Specifies the id to look for or NULL.
  3879. * ret_para Returns a pointer to a list of _DtCvSegment
  3880. * structures.
  3881. * ret_num Specifies the number of structures in
  3882. * 'ret_para'.
  3883. * ret_seg Specifies the segment containing 'id_string'
  3884. * or NULL.
  3885. *
  3886. * Returns:
  3887. *
  3888. * errno Values:
  3889. *
  3890. * Purpose: Format is the top entry point for formating Help Files with
  3891. * formatting information into a form understood by a display area.
  3892. * It will keep calling Parse, until the entire topic is read
  3893. * or an error occurs.
  3894. *
  3895. *****************************************************************************/
  3896. static int
  3897. FormatCCDFTitle(
  3898. FormatVariables *cur_vars,
  3899. _DtHelpFontHints fontAttrs,
  3900. char *filename,
  3901. int offset,
  3902. int level,
  3903. int fnt_flags,
  3904. int want_abbrev)
  3905. {
  3906. char *strPtr;
  3907. char *charSet = NULL;
  3908. int result = 0;
  3909. int origCnt = cur_vars->my_list.cnt;
  3910. int len;
  3911. _DtCvSegment *titleSeg;
  3912. _DtCvSegment *list;
  3913. cur_vars->rd_buf[0] = '\0';
  3914. cur_vars->rd_ptr = cur_vars->rd_buf;
  3915. if (_DtHelpCeFileOpenAndSeek(filename, offset, -1,
  3916. &(cur_vars->my_file), NULL) != 0)
  3917. return -1;
  3918. cur_vars->rd_flag = _DtHelpCeReadBuf (cur_vars->my_file, cur_vars->rd_buf,
  3919. cur_vars->rd_size);
  3920. if (cur_vars->rd_flag == -1)
  3921. {
  3922. _DtHelpCeBufFileClose (cur_vars->my_file, True);
  3923. return -1;
  3924. }
  3925. /*
  3926. * The first command in the buffer MUST be the <TOPIC> command.
  3927. * It is in a one byte charset.
  3928. */
  3929. if (_DtHelpCeGetCcdfTopicCmd (((void *) NULL), cur_vars->my_file,
  3930. cur_vars->rd_buf, &(cur_vars->rd_ptr),
  3931. cur_vars->rd_size, 1, &charSet) == -1)
  3932. {
  3933. _DtHelpCeBufFileClose (cur_vars->my_file, True);
  3934. return -1;
  3935. }
  3936. /*
  3937. * change the character set to the returned character set
  3938. * Assume that the charset is 'iso8859' if not specified.
  3939. */
  3940. cur_vars->cur_mb_max = 1;
  3941. if (NULL != charSet)
  3942. GetMbLen(cur_vars, charSet, &(_DtHelpFontHintsLang(fontAttrs)),
  3943. &(_DtHelpFontHintsCharSet(fontAttrs)));
  3944. /*
  3945. * Remember the topic code set and MB_CUR_MAX.
  3946. */
  3947. cur_vars->topic_char_set = _DtHelpFontHintsCharSet(fontAttrs);
  3948. cur_vars->topic_lang = _DtHelpFontHintsLang(fontAttrs);
  3949. cur_vars->topic_mb_max = cur_vars->cur_mb_max;
  3950. /*
  3951. * allocate another segment for this title.
  3952. */
  3953. if (0 != CheckSegList(cur_vars))
  3954. {
  3955. if (NULL != charSet)
  3956. {
  3957. free(_DtHelpFontHintsLang(fontAttrs));
  3958. free(_DtHelpFontHintsCharSet(fontAttrs));
  3959. free(charSet);
  3960. }
  3961. _DtHelpCeBufFileClose(cur_vars->my_file, True);
  3962. return -1;
  3963. }
  3964. /*
  3965. * set the left margin correctly.
  3966. */
  3967. titleSeg = NextAvailSeg(cur_vars->my_list);
  3968. titleSeg->handle.container = DefContainer;
  3969. titleSeg->type = _DtCvSetTypeToContainer(titleSeg->type);
  3970. _DtCvContainerLMarginOfSeg(titleSeg) = level*2*cur_vars->ui_info->avg_char;
  3971. _DtCvContainerBMarginOfSeg(titleSeg) = 0;
  3972. _DtCvContainerTypeOfSeg(titleSeg) = _DtCvLITERAL;
  3973. _DtCvContainerLeadingOfSeg(titleSeg) = cur_vars->ui_info->leading;
  3974. /*
  3975. * Parse the title.
  3976. */
  3977. if (-1 == ParseTitle(cur_vars, False, False, fnt_flags, &fontAttrs))
  3978. {
  3979. if (NULL != charSet)
  3980. {
  3981. free(_DtHelpFontHintsLang(fontAttrs));
  3982. free(_DtHelpFontHintsCharSet(fontAttrs));
  3983. free(charSet);
  3984. }
  3985. _DtHelpCeBufFileClose(cur_vars->my_file, True);
  3986. return -1;
  3987. }
  3988. /*
  3989. * We've parsed the title. see if we want the abbrev.
  3990. */
  3991. /*
  3992. * if the title is null or we want the abbrev,
  3993. * process the abbreviation.
  3994. */
  3995. if (NULL == _DtCvContainerListOfSeg(titleSeg) || want_abbrev)
  3996. {
  3997. SegList titleList = cur_vars->my_list;
  3998. /*
  3999. * reset the buffer to get the abbreviation
  4000. */
  4001. if (cur_vars->fmt_buf != NULL)
  4002. {
  4003. free(cur_vars->fmt_buf);
  4004. cur_vars->fmt_buf = NULL;
  4005. cur_vars->fmt_size = 0;
  4006. cur_vars->fmt_buf_max = 0;
  4007. }
  4008. result = _DtHelpCeGetCcdfAbbrevCmd (cur_vars->my_file, cur_vars->rd_buf,
  4009. cur_vars->rd_size, cur_vars->cur_mb_max,
  4010. &(cur_vars->rd_ptr), &(cur_vars->fmt_buf));
  4011. /*
  4012. * If no errors getting the abbreviation, save it
  4013. */
  4014. if (result != -1)
  4015. {
  4016. /*
  4017. * save the abbreviation
  4018. */
  4019. if (cur_vars->fmt_buf != NULL)
  4020. {
  4021. /*
  4022. * If there was a title, free it
  4023. */
  4024. if (NULL != _DtCvContainerListOfSeg(titleSeg))
  4025. _DtHelpFreeSegments(_DtCvContainerListOfSeg(titleSeg),
  4026. _DtCvFALSE,
  4027. cur_vars->ui_info->destroy_region,
  4028. cur_vars->ui_info->client_data);
  4029. /*
  4030. * save the abbreviation
  4031. */
  4032. cur_vars->my_list = InitList;
  4033. cur_vars->fmt_size = strlen (cur_vars->fmt_buf);
  4034. cur_vars->fmt_buf_max = cur_vars->fmt_size + 1;
  4035. if (cur_vars->fmt_size > 0)
  4036. result = SaveStringAsSegments (cur_vars, 0, &fontAttrs, -1);
  4037. if (result != -1)
  4038. TerminateSegList(&(cur_vars->my_list), True);
  4039. titleSeg->type = _DtCvSetTypeToContainer(titleSeg->type);
  4040. _DtCvContainerListOfSeg(titleSeg) = cur_vars->my_list.list;
  4041. titleList.cnt++;
  4042. }
  4043. }
  4044. /*
  4045. * eliminate this segment if no title or abbrev was found.
  4046. */
  4047. if (NULL == _DtCvContainerListOfSeg(titleSeg))
  4048. {
  4049. titleList.cnt = origCnt;
  4050. _DtCvContainerTypeOfSeg(titleSeg) = _DtCvDYNAMIC;
  4051. }
  4052. /*
  4053. * reset the title list
  4054. */
  4055. cur_vars->my_list = titleList;
  4056. }
  4057. else
  4058. result = _DtHelpCeSkipCcdfAbbrev (cur_vars->my_file, cur_vars->rd_buf,
  4059. &(cur_vars->rd_ptr), cur_vars->rd_size,
  4060. cur_vars->cur_mb_max);
  4061. if (cur_vars->fmt_buf != NULL)
  4062. cur_vars->fmt_buf[0] = '\0';
  4063. cur_vars->fmt_size = 0;
  4064. /*
  4065. * remove the newline from the lists and
  4066. * change all the newlines on the segments into a space.
  4067. */
  4068. for (list = _DtCvContainerListOfSeg(titleSeg);
  4069. NULL != list; list = list->next_seg)
  4070. {
  4071. if (_DtCvIsSegNewLine(list))
  4072. {
  4073. /*
  4074. * clear the newline flag.
  4075. */
  4076. list->type &= ~(_DtCvNEW_LINE);
  4077. /*
  4078. * check to see if the last character of this segment or
  4079. * the first character of the next segment is a space.
  4080. * if not, add one.
  4081. */
  4082. if (NULL != list->next_disp && _DtCvIsSegString(list)
  4083. && _DtCvIsSegRegChar(list))
  4084. {
  4085. /*
  4086. * is the last character of the string a space?
  4087. * if so do nothing.
  4088. */
  4089. len = strlen((char *) _DtCvStringOfStringSeg(list)) - 1;
  4090. if (' ' != ((char *) _DtCvStringOfStringSeg(list))[len])
  4091. {
  4092. /*
  4093. * is the next segment a one byte string?
  4094. * and if so, is the first character a space?
  4095. * if so, do nothing.
  4096. */
  4097. if (_DtCvIsSegString(list->next_disp)
  4098. && _DtCvIsSegRegChar(list->next_disp)
  4099. && ' ' != *((char *)_DtCvStringOfStringSeg(list->next_disp)))
  4100. {
  4101. /*
  4102. * need to add a space to one of these strings.
  4103. */
  4104. len += 3;
  4105. _DtCvStringOfStringSeg(list) = (char *) realloc(
  4106. (void *) _DtCvStringOfStringSeg(list),
  4107. sizeof(char *) * len);
  4108. if (NULL == _DtCvStringOfStringSeg(list))
  4109. return -1;
  4110. strPtr = (char *) _DtCvStrPtr(
  4111. _DtCvStringOfStringSeg(list),
  4112. 0,
  4113. len - 3);
  4114. *strPtr++ = ' ';
  4115. *strPtr = '\0';
  4116. }
  4117. }
  4118. }
  4119. }
  4120. }
  4121. _DtHelpCeBufFileClose (cur_vars->my_file, True);
  4122. /*
  4123. * free memory
  4124. */
  4125. if (NULL != charSet)
  4126. {
  4127. free(_DtHelpFontHintsLang(fontAttrs));
  4128. free(_DtHelpFontHintsCharSet(fontAttrs));
  4129. free(charSet);
  4130. }
  4131. if (result == -1)
  4132. return -1;
  4133. return 0;
  4134. }
  4135. /******************************************************************************
  4136. * Function: int FormatEntryInToc (
  4137. *
  4138. * Parameters:
  4139. *
  4140. * Returns: 0 if successful, -1 if errors
  4141. *
  4142. * errno Values:
  4143. *
  4144. * Purpose:
  4145. *
  4146. ******************************************************************************/
  4147. static int
  4148. FormatEntryInToc(
  4149. _DtHelpVolumeHdl volume,
  4150. char *loc_id,
  4151. FormatVariables *cur_vars,
  4152. _DtHelpFontHints font_attrs,
  4153. int level)
  4154. {
  4155. int result = -1;
  4156. int tocLen = 0;
  4157. int offset;
  4158. int num;
  4159. char *strPtr = NULL;
  4160. _DtCvSegment *pSeg;
  4161. _DtCvSegment *titleSeg;
  4162. SegList titleList;
  4163. /*
  4164. * check to see that there is a segment for this title.
  4165. */
  4166. if (0 != CheckSegList(cur_vars))
  4167. return -1;
  4168. /*
  4169. * The next segment in the list will become the next title.
  4170. * Get a pointer to it for later use.
  4171. */
  4172. titleList = cur_vars->my_list;
  4173. titleSeg = NextAvailSeg(titleList);
  4174. titleSeg->handle.container = DefContainer;
  4175. titleSeg->type = _DtCvSetTypeToContainer(titleSeg->type);
  4176. _DtCvContainerBMarginOfSeg(titleSeg) = 0;
  4177. _DtCvContainerLeadingOfSeg(titleSeg) = cur_vars->ui_info->leading;
  4178. /*
  4179. * Get the file and offset for the topic.
  4180. * and process the topic's title, ignoring most font changes.
  4181. */
  4182. if (True == _DtHelpCeFindId(volume, loc_id, -1, &strPtr, &offset) &&
  4183. -1 != FormatCCDFTitle(cur_vars, font_attrs, strPtr, offset, level,
  4184. ((1<<_CEFONT_SIZE)|(1<<_CEFONT_WEIGHT)|(1<<_CEFONT_ANGLE)|(1<<_CEFONT_TYPE)),
  4185. False))
  4186. {
  4187. /*
  4188. * now create the hypertext link index for the ghostlink.
  4189. */
  4190. num = _DtLinkDbAddLink(cur_vars->my_links, NULL, loc_id,
  4191. _DtCvLinkType_SameVolume,
  4192. _DtCvWindowHint_CurrentWindow,
  4193. NULL);
  4194. /*
  4195. * if a link index was successfully created, process the item.
  4196. */
  4197. if (num != -1)
  4198. {
  4199. result = 0;
  4200. /*
  4201. * check to see if this title had any segments.
  4202. */
  4203. pSeg = _DtCvContainerListOfSeg(titleSeg);
  4204. if (NULL != pSeg)
  4205. {
  4206. while (NULL != pSeg)
  4207. {
  4208. /*
  4209. * If this segment has a hypertext link, remove it.
  4210. */
  4211. if (pSeg->link_idx != -1)
  4212. _DtLinkDbRemoveLink(cur_vars->my_links, pSeg->link_idx);
  4213. /*
  4214. * change the link index and flag to the ghost link.
  4215. */
  4216. pSeg->link_idx = num;
  4217. pSeg->type &= ~(_DtCvHYPER_TEXT);
  4218. pSeg->type = _DtCvSetTypeToGhostLink(pSeg->type);
  4219. /*
  4220. * go to the next segment.
  4221. */
  4222. pSeg = pSeg->next_seg;
  4223. }
  4224. }
  4225. else
  4226. {
  4227. /*
  4228. * no title or abbreviation, so use the location id.
  4229. * allocate room for it and put it between parens.
  4230. */
  4231. tocLen = strlen (loc_id) + 9;
  4232. if (tocLen > cur_vars->fmt_buf_max)
  4233. {
  4234. if (NULL == cur_vars->fmt_buf)
  4235. cur_vars->fmt_buf = (char *) malloc (tocLen);
  4236. else
  4237. cur_vars->fmt_buf = (char *) realloc(
  4238. cur_vars->fmt_buf,
  4239. tocLen);
  4240. cur_vars->fmt_buf_max = tocLen;
  4241. }
  4242. cur_vars->fmt_size = tocLen - 1;
  4243. strcpy (cur_vars->fmt_buf, "...(");
  4244. strcat (cur_vars->fmt_buf, loc_id);
  4245. strcat (cur_vars->fmt_buf, ")...");
  4246. /*
  4247. * don't overwrite the title's
  4248. */
  4249. cur_vars->my_list = InitList;
  4250. /*
  4251. * save the string off and then attach to the title
  4252. * container.
  4253. */
  4254. result = SaveStringAsSegments(cur_vars, _DtCvGHOST_LINK,
  4255. &font_attrs, num);
  4256. if (-1 != result)
  4257. _DtCvContainerListOfSeg(titleSeg) = cur_vars->my_list.list;
  4258. /*
  4259. * restore the title list.
  4260. */
  4261. cur_vars->my_list = titleList;
  4262. }
  4263. }
  4264. }
  4265. if (NULL != strPtr)
  4266. free(strPtr);
  4267. return result;
  4268. } /* End FormatEntryInToc */
  4269. /******************************************************************************
  4270. * Function: int FormatExpandToc (
  4271. * _DtHelpVolumeHdl volume,
  4272. *
  4273. * Purpose:
  4274. ******************************************************************************/
  4275. static int
  4276. FormatExpandedToc(
  4277. _DtHelpVolumeHdl volume,
  4278. char *cur_id,
  4279. char **path_lst,
  4280. FormatVariables *cur_vars,
  4281. _DtHelpFontHints font_attrs,
  4282. int level)
  4283. {
  4284. int result = 0;
  4285. if (*path_lst != NULL)
  4286. {
  4287. font_attrs.weight = _DtHelpFontWeightMedium;
  4288. if (_DtCvStrCaseCmpLatin1(*path_lst, cur_id) == 0)
  4289. font_attrs.weight = _DtHelpFontWeightBold;
  4290. result = FormatEntryInToc(volume, *path_lst, cur_vars,
  4291. font_attrs, level);
  4292. if (result != -1)
  4293. {
  4294. char **children;
  4295. char **childLst;
  4296. int count = _DtHelpCeGetCcdfTopicChildren(volume,
  4297. *path_lst, &children);
  4298. /*
  4299. * if there are children, format them
  4300. */
  4301. level++;
  4302. path_lst++;
  4303. childLst = children;
  4304. font_attrs.weight = _DtHelpFontWeightMedium;
  4305. while (result != -1 && count > 0)
  4306. {
  4307. /*
  4308. * found the next item in the list
  4309. */
  4310. if (*path_lst != NULL &&
  4311. _DtCvStrCaseCmpLatin1(*path_lst, *childLst) == 0)
  4312. result = FormatExpandedToc(volume,
  4313. cur_id, path_lst,
  4314. cur_vars, font_attrs, level);
  4315. else
  4316. result = FormatEntryInToc(volume, *childLst,
  4317. cur_vars, font_attrs, level);
  4318. childLst++;
  4319. count--;
  4320. }
  4321. if (children != NULL)
  4322. _DtCvFreeArray((void **) children);
  4323. }
  4324. }
  4325. return result;
  4326. }
  4327. /******************************************************************************
  4328. *
  4329. * Semi-Public Functions
  4330. *
  4331. *****************************************************************************/
  4332. /******************************************************************************
  4333. * Function: VarHandle *__DtHelpCeSetUpVars (char *rd_buf, grow_size)
  4334. *
  4335. * Parameters:
  4336. *
  4337. * Returns: NULL if unsuccessful.
  4338. *
  4339. * errno Values:
  4340. *
  4341. * Purpose:
  4342. *
  4343. ******************************************************************************/
  4344. VarHandle
  4345. __DtHelpCeSetUpVars(
  4346. char *lang,
  4347. char *code_set,
  4348. _FrmtUiInfo *ui_info)
  4349. {
  4350. FormatVariables *newVars;
  4351. newVars = (FormatVariables *) malloc (sizeof(FormatVariables));
  4352. *newVars = DefVars;
  4353. newVars->ui_info = ui_info;
  4354. newVars->topic_mb_max = _DtHelpCeGetMbLen(lang, code_set);
  4355. newVars->cur_mb_max = newVars->topic_mb_max;
  4356. return ((VarHandle) newVars);
  4357. } /* End __DtHelpCeSetUpVars */
  4358. /******************************************************************************
  4359. * Function: int __DtHelpCeProcessString (char *in_string, int seg_type,
  4360. * char **font_attr)
  4361. *
  4362. * Parameters:
  4363. *
  4364. * Returns: 0 if successful, -1 if errors.
  4365. *
  4366. * errno Values:
  4367. *
  4368. * Purpose:
  4369. *
  4370. ******************************************************************************/
  4371. int
  4372. __DtHelpCeProcessString(
  4373. VarHandle var_handle,
  4374. BufFilePtr my_file,
  4375. _DtCvFrmtOption frmt_type,
  4376. char *scan_string,
  4377. char *in_string,
  4378. int in_size,
  4379. int fnt_flag,
  4380. int ret_on_nl,
  4381. _DtHelpFontHints *font_attr )
  4382. {
  4383. int done = 0;
  4384. FormatVariables *myVars = (FormatVariables *) var_handle;
  4385. SegList oldList = myVars->my_list;
  4386. myVars->rd_buf = in_string;
  4387. myVars->rd_size = in_size;
  4388. myVars->rd_ptr = in_string;
  4389. myVars->my_file = my_file;
  4390. if (my_file == NULL)
  4391. myVars->rd_flag = 0;
  4392. else
  4393. myVars->rd_flag = strlen(in_string);
  4394. while (!done)
  4395. {
  4396. if (True == ret_on_nl)
  4397. myVars->my_list = InitList;
  4398. done = Parse (CCDF_FONT_CMD, NormalState, myVars,
  4399. 0, frmt_type,
  4400. font_attr,
  4401. -1, scan_string, (CCDF_FONT_CMD | CCDF_OCTAL_CMD), ret_on_nl,
  4402. fnt_flag);
  4403. if (done != -1 && True == ret_on_nl)
  4404. {
  4405. TerminateSegList (&(myVars->my_list), True);
  4406. if (NULL != myVars->my_list.list)
  4407. {
  4408. done = CheckList (&oldList, 1, GROW_SIZE);
  4409. if (-1 != done)
  4410. {
  4411. _DtCvSegment *newSeg = NextAvailSeg(oldList);
  4412. newSeg->type = _DtCvSetTypeToContainer(newSeg->type);
  4413. _DtCvContainerListOfSeg(newSeg) = myVars->my_list.list;
  4414. _DtCvContainerTypeOfSeg(newSeg) = _DtCvDYNAMIC;
  4415. oldList.cnt++;
  4416. TerminateSegList(&oldList, False);
  4417. }
  4418. }
  4419. }
  4420. }
  4421. if (False == ret_on_nl)
  4422. oldList = myVars->my_list;
  4423. myVars->my_list = oldList;
  4424. return done;
  4425. } /* End __DtHelpCeProcessString */
  4426. /*****************************************************************************
  4427. * Function: int __DtHelpCeGetParagraphList (
  4428. *
  4429. * Parameters:
  4430. *
  4431. * Returns: 0 if successful, -1 if errors.
  4432. *
  4433. * errno Values:
  4434. *
  4435. * Purpose: _DtHelpFormatGetParagraphList places a terminator on the
  4436. * last segment in the current paragraph and returns the
  4437. * segment list included in the topic information structure.
  4438. *
  4439. * If make_cont is true, the segment list is first included
  4440. * in a container with the specified type.
  4441. *
  4442. *****************************************************************************/
  4443. int
  4444. __DtHelpCeGetParagraphList (
  4445. VarHandle var_handle,
  4446. int make_cont,
  4447. _DtCvFrmtOption type,
  4448. _DtCvTopicPtr *ret_handle)
  4449. {
  4450. int result = -1;
  4451. FormatVariables *myVars = (FormatVariables *) var_handle;
  4452. _DtCvTopicInfo *topicHandle;
  4453. /*
  4454. * check the parameters.
  4455. */
  4456. if (ret_handle == NULL || myVars == NULL)
  4457. {
  4458. errno = EINVAL;
  4459. return -1;
  4460. }
  4461. TerminateSegList(&(myVars->my_list), True);
  4462. topicHandle = (_DtCvTopicInfo *) malloc (sizeof(_DtCvTopicInfo));
  4463. if (topicHandle != NULL)
  4464. {
  4465. result = 0;
  4466. if (True == make_cont)
  4467. {
  4468. _DtCvSegment *myCont = AllocateSegments(NULL, 0, 1);
  4469. if (NULL != myCont)
  4470. {
  4471. myCont->type = _DtCvSetTypeToContainer(myCont->type);
  4472. _DtCvContainerTypeOfSeg(myCont) = type;
  4473. _DtCvContainerListOfSeg(myCont) = myVars->my_list.list;
  4474. myVars->my_list.list = myCont;
  4475. myVars->my_list.cnt = 1;
  4476. myVars->my_list.max = 1;
  4477. }
  4478. else
  4479. result = -1;
  4480. }
  4481. topicHandle->id_str = NULL;
  4482. topicHandle->seg_list = myVars->my_list.list;
  4483. topicHandle->mark_list = NULL;
  4484. topicHandle->link_data = myVars->my_links;
  4485. *ret_handle = (_DtCvTopicPtr) topicHandle;
  4486. }
  4487. if (myVars->fmt_buf != NULL)
  4488. free(myVars->fmt_buf);
  4489. return result;
  4490. }
  4491. /******************************************************************************
  4492. * Function: int _DtHelpCeFrmtCcdfTopic (_DtHelpVolumeHdl volume, char *filename,
  4493. * int offset, char *id_string,
  4494. * _DtCvTopicPtr *ret_handle)
  4495. *
  4496. * Parameters:
  4497. * volume Specifies the Help Volume the information
  4498. * is associated with.
  4499. * filename Specifies the file containing the Help Topic
  4500. * desired.
  4501. * offset Specifies the offset into 'filename' to
  4502. * the Help Topic desired.
  4503. * id_string Specifies the location id to look for or NULL.
  4504. * ret_handle Returns a handle to the topic information
  4505. * including the number of paragraphs and the
  4506. * id match segment.
  4507. *
  4508. * Returns: 0 if successful, -1 if errors
  4509. *
  4510. * errno Values:
  4511. *
  4512. * Purpose: _DtHelpCeFrmtCcdfTopic formats Help Files with formatting
  4513. * information into a Canvas Engine structure.
  4514. *
  4515. ******************************************************************************/
  4516. int
  4517. _DtHelpCeFrmtCcdfTopic(
  4518. _DtHelpVolumeHdl volume,
  4519. char *filename,
  4520. int offset,
  4521. char *id_string,
  4522. _FrmtUiInfo *ui_info,
  4523. _DtCvTopicPtr *ret_handle )
  4524. {
  4525. int result = -1;
  4526. char *ptr;
  4527. FormatVariables variables;
  4528. /*
  4529. * Check the parameters
  4530. */
  4531. if (volume == NULL || filename == NULL || offset < 0 || ret_handle == NULL)
  4532. {
  4533. errno = EINVAL;
  4534. return -1;
  4535. }
  4536. /*
  4537. * get the current file path.
  4538. */
  4539. variables = DefVars;
  4540. variables.topic_id = id_string;
  4541. if (volume)
  4542. {
  4543. variables.vol_name = _DtHelpCeGetVolumeName(volume);
  4544. variables.my_path = strdup (variables.vol_name);
  4545. if (variables.my_path == NULL)
  4546. return -1;
  4547. result = _DtHelpCeStrrchr (variables.my_path, Slash, MB_CUR_MAX, &ptr);
  4548. if (result == -1)
  4549. ptr = strrchr (variables.my_path, '/');
  4550. if (ptr)
  4551. *ptr = '\0';
  4552. }
  4553. /*
  4554. * open the file and seek to the correct place.
  4555. */
  4556. result = _DtHelpCeFileOpenAndSeek (filename, offset, -1,
  4557. &(variables.my_file), NULL);
  4558. if (result != -1)
  4559. {
  4560. /*
  4561. * Initialize the X variables.
  4562. */
  4563. result = Format (&variables, ui_info, id_string, ret_handle);
  4564. _DtHelpCeBufFileClose (variables.my_file, True);
  4565. }
  4566. if (variables.fmt_buf != NULL)
  4567. free (variables.fmt_buf);
  4568. if (variables.my_path != NULL)
  4569. free (variables.my_path);
  4570. return result;
  4571. } /* End _DtHelpCeFrmtCcdfTopic */
  4572. /******************************************************************************
  4573. * Function: int _DtHelpCeFrmtCcdfPathAndChildren (
  4574. * _DtHelpVolumeHdl volume,
  4575. * _DtCvTopicPtr *ret_handle)
  4576. *
  4577. * Parameters:
  4578. * ret_handle Returns a handle to the topic information
  4579. * including the number of paragraphs and the
  4580. * id match segment.
  4581. *
  4582. * Returns: 0 if successful, -1 if errors, 1 if there the path is empty.
  4583. *
  4584. * errno Values:
  4585. *
  4586. * Purpose: _DtHelpCeFormatCcdfToc formats Table of Contents for
  4587. * a CCDF Help File.
  4588. *
  4589. ******************************************************************************/
  4590. int
  4591. _DtHelpCeFrmtCcdfPathAndChildren(
  4592. _DtHelpVolumeHdl volume,
  4593. char *loc_id,
  4594. _FrmtUiInfo *ui_info,
  4595. _DtCvTopicPtr *ret_handle )
  4596. {
  4597. int result = 0;
  4598. int pathCnt;
  4599. char *ptr;
  4600. char **pathHead;
  4601. char readBuf[BUFF_SIZE];
  4602. FormatVariables myVars;
  4603. _DtHelpFontHints fontAttrs;
  4604. _DtHelpCeCopyDefFontAttrList (&fontAttrs);
  4605. fontAttrs.pointsz = 10;
  4606. fontAttrs.weight = _DtHelpFontWeightMedium;
  4607. fontAttrs.style = _DtHelpFontStyleSanSerif;
  4608. /*
  4609. * Check the parameters
  4610. */
  4611. if (volume == NULL || ret_handle == NULL)
  4612. {
  4613. errno = EINVAL;
  4614. return -1;
  4615. }
  4616. readBuf[0] = '\0';
  4617. myVars = DefVars;
  4618. if (InitStructure (&myVars, ui_info, readBuf, BUFF_SIZE) == -1)
  4619. return -1;
  4620. /*
  4621. * get the list of topics in the volume.
  4622. */
  4623. pathCnt = _DtHelpCeGetCcdfIdPath(volume, loc_id, &pathHead);
  4624. if (pathCnt == -1)
  4625. return -1;
  4626. /*
  4627. * Check to see if this topic is in the topic list.
  4628. * I.e. if a count of 1 is returned this should match the
  4629. * top topic, otherwise this is an hidden topic.
  4630. */
  4631. if (pathCnt == 1)
  4632. {
  4633. if (_DtHelpCeGetCcdfTopTopic(volume, &ptr) == -1)
  4634. result = -1;
  4635. else if (_DtCvStrCaseCmpLatin1(ptr, *pathHead) != 0)
  4636. result = 1;
  4637. }
  4638. /*
  4639. * if result is non-zero, we had problems or this is a hidden topic
  4640. */
  4641. if (result == 0)
  4642. {
  4643. fontAttrs.slant = _DtHelpFontSlantRoman;
  4644. myVars.topic_id = loc_id;
  4645. myVars.vol_name = _DtHelpCeGetVolumeName(volume);
  4646. myVars.my_path = strdup (myVars.vol_name);
  4647. if (myVars.my_path == NULL)
  4648. return -1;
  4649. if (-1 == _DtHelpCeStrrchr (myVars.my_path, Slash, MB_CUR_MAX, &ptr))
  4650. ptr = strrchr (myVars.my_path, '/');
  4651. if (ptr)
  4652. *ptr = '\0';
  4653. result = FormatExpandedToc(volume, loc_id, pathHead,
  4654. &myVars, fontAttrs, 0);
  4655. _DtCvFreeArray((void **) pathHead);
  4656. }
  4657. if (result != -1)
  4658. result = __DtHelpCeGetParagraphList (&myVars, False, _DtCvDYNAMIC,
  4659. ret_handle);
  4660. /*
  4661. * check for an empty path.
  4662. */
  4663. if (-1 != result && NULL == ((_DtCvTopicInfo *) *ret_handle)->seg_list)
  4664. result = 1;
  4665. if (myVars.my_path != NULL)
  4666. free(myVars.my_path);
  4667. return result;
  4668. } /* End _DtHelpCeFrmtCcdfPathAndChildren */
  4669. /******************************************************************************
  4670. * Function: int _DtHelpCeGetCcdfTitleChunks (
  4671. * _DtHelpVolumeHdl volume,
  4672. * _DtCvTopicPtr *ret_handle)
  4673. *
  4674. * Parameters:
  4675. * ret_handle Returns a handle to the topic information
  4676. * including the number of paragraphs and the
  4677. * id match segment.
  4678. *
  4679. * Returns: 0 if successful, -1 if errors
  4680. *
  4681. * errno Values:
  4682. *
  4683. * Purpose: _DtHelpCeFormatCcdfToc formats Table of Contents for
  4684. * a CCDF Help File.
  4685. *
  4686. ******************************************************************************/
  4687. int
  4688. _DtHelpCeGetCcdfTitleChunks(
  4689. _DtHelpVolumeHdl volume,
  4690. char *loc_id,
  4691. _FrmtUiInfo *ui_info,
  4692. void ***ret_chunks)
  4693. {
  4694. long type = 0;
  4695. int result = 0;
  4696. int offset;
  4697. char *fileName;
  4698. char *ptr;
  4699. char readBuf[BUFF_SIZE];
  4700. _DtCvSegment *titleSeg;
  4701. _DtCvSegment *list = NULL;
  4702. FormatVariables myVars;
  4703. _DtHelpFontHints fontAttrs;
  4704. _DtHelpCeLockInfo lockInfo;
  4705. /*
  4706. * Check the parameters
  4707. */
  4708. if (volume == NULL || ret_chunks == NULL)
  4709. {
  4710. errno = EINVAL;
  4711. return -1;
  4712. }
  4713. /*
  4714. * init the return value
  4715. */
  4716. *ret_chunks = NULL;
  4717. /*
  4718. * get the topic in the volume.
  4719. */
  4720. if (_DtHelpCeLockVolume(volume, &lockInfo) != 0)
  4721. return -1;
  4722. if (_DtHelpCeFindId(volume, loc_id, -1, &fileName, &offset) == False)
  4723. {
  4724. _DtHelpCeUnlockVolume(lockInfo);
  4725. return -1;
  4726. }
  4727. _DtHelpCeCopyDefFontAttrList (&fontAttrs);
  4728. myVars = DefVars;
  4729. if (InitStructure (&myVars, ui_info, readBuf, BUFF_SIZE) == -1)
  4730. {
  4731. _DtHelpCeUnlockVolume(lockInfo);
  4732. return -1;
  4733. }
  4734. /*
  4735. * initialize my variables.
  4736. */
  4737. myVars.topic_id = loc_id;
  4738. myVars.vol_name = _DtHelpCeGetVolumeName(volume);
  4739. myVars.my_path = strdup (myVars.vol_name);
  4740. if (myVars.my_path == NULL)
  4741. {
  4742. _DtHelpCeUnlockVolume(lockInfo);
  4743. return -1;
  4744. }
  4745. if (-1 == _DtHelpCeStrrchr (myVars.my_path, Slash, MB_CUR_MAX, &ptr))
  4746. ptr = strrchr (myVars.my_path, '/');
  4747. if (ptr)
  4748. *ptr = '\0';
  4749. result = FormatCCDFTitle(&myVars, fontAttrs, fileName,
  4750. offset, 0, (1 << _CEFONT_SIZE), True);
  4751. free(fileName);
  4752. if (-1 != result && 0 < myVars.my_list.cnt)
  4753. {
  4754. titleSeg = &(myVars.my_list.list[myVars.my_list.cnt - 1]);
  4755. list = _DtCvContainerListOfSeg(titleSeg);
  4756. }
  4757. if (result != -1 && NULL != list)
  4758. {
  4759. _DtCvSegment *pSeg = list;
  4760. while (-1 != result && NULL != pSeg)
  4761. {
  4762. /*
  4763. * create the types and add the informatio to the array.
  4764. */
  4765. type = DT_HELP_CE_FONT_PTR | DT_HELP_CE_STRING;
  4766. if (_DtCvIsSegNewLine(pSeg))
  4767. type |= DT_HELP_CE_NEWLINE;
  4768. if (_DtCvIsSegString(pSeg))
  4769. {
  4770. *ret_chunks = (void **) _DtCvAddPtrToArray(*ret_chunks,
  4771. (void *) type);
  4772. if (NULL != *ret_chunks)
  4773. *ret_chunks = (void **) _DtCvAddPtrToArray(*ret_chunks,
  4774. (void *) _DtCvFontOfStringSeg(pSeg));
  4775. if (NULL != *ret_chunks)
  4776. {
  4777. if (_DtCvIsSegWideChar(pSeg))
  4778. {
  4779. offset = _DtCvStrLen(_DtCvStringOfStringSeg(pSeg), 1)
  4780. * MB_CUR_MAX + 1;
  4781. ptr = (char *) malloc (sizeof(char) * offset);
  4782. if (NULL != ptr)
  4783. wcstombs(ptr,
  4784. (wchar_t *)_DtCvStringOfStringSeg(pSeg),
  4785. offset);
  4786. }
  4787. else
  4788. ptr = strdup((char *) _DtCvStringOfStringSeg(pSeg));
  4789. if (NULL != ptr)
  4790. *ret_chunks = (void **)_DtCvAddPtrToArray(
  4791. *ret_chunks, (void *) ptr);
  4792. }
  4793. if (NULL == *ret_chunks || NULL == ptr)
  4794. result = -1;
  4795. }
  4796. /*
  4797. * go to the next segment
  4798. */
  4799. pSeg = pSeg->next_seg;
  4800. }
  4801. }
  4802. else
  4803. {
  4804. char buf[128];
  4805. char *idStr;
  4806. int idLen = strlen (loc_id) + 9;
  4807. /*
  4808. * create the location id string.
  4809. */
  4810. idStr = (char *) malloc (idLen);
  4811. if (NULL != idStr)
  4812. {
  4813. /*
  4814. * format the location id
  4815. */
  4816. strcpy (idStr, "...(");
  4817. strcat (idStr, loc_id);
  4818. strcat (idStr, ")...");
  4819. /*
  4820. * format the language and codeset
  4821. */
  4822. strcpy(buf, _DtHelpFontHintsLang(fontAttrs));
  4823. strcat(buf, ".");
  4824. strcpy(buf, _DtHelpFontHintsCharSet(fontAttrs));
  4825. /*
  4826. * creat a chunk table
  4827. */
  4828. *ret_chunks = (void **) _DtCvAddPtrToArray(*ret_chunks,
  4829. (void *) (DT_HELP_CE_CHARSET | DT_HELP_CE_STRING));
  4830. if (NULL != *ret_chunks)
  4831. *ret_chunks = (void **) _DtCvAddPtrToArray(*ret_chunks,
  4832. (void *) strdup(buf));
  4833. if (NULL != *ret_chunks)
  4834. *ret_chunks = (void **) _DtCvAddPtrToArray(*ret_chunks,
  4835. (void *) idStr);
  4836. }
  4837. }
  4838. if (NULL != *ret_chunks)
  4839. *ret_chunks = (void **) _DtCvAddPtrToArray(*ret_chunks,
  4840. (void *) DT_HELP_CE_END);
  4841. /*
  4842. * free the list
  4843. */
  4844. if (0 < myVars.my_list.cnt)
  4845. _DtHelpFreeSegments(myVars.my_list.list, _DtCvFALSE,
  4846. ui_info->destroy_region,
  4847. ui_info->client_data);
  4848. /*
  4849. * free the link database
  4850. */
  4851. _DtLinkDbDestroy(myVars.my_links);
  4852. /*
  4853. * free memory
  4854. */
  4855. if (myVars.my_path != NULL)
  4856. free(myVars.my_path);
  4857. if (myVars.fmt_buf != NULL)
  4858. free(myVars.fmt_buf);
  4859. _DtHelpCeUnlockVolume(lockInfo);
  4860. /*
  4861. * indicate an error if problems.
  4862. */
  4863. result = 0;
  4864. if (NULL == *ret_chunks)
  4865. result = -1;
  4866. return result;
  4867. } /* End _DtHelpCeGetCcdfTitleChunks */
  4868. /******************************************************************************
  4869. * Function: int _DtHelpCeGetCcdfVolTitleChunks (
  4870. * _DtHelpVolumeHdl volume,
  4871. * void ***ret_chunks)
  4872. *
  4873. * Parameters:
  4874. * ret_chunks Returns a ptr to the title information chunks
  4875. * The title chunks are stored in allocated memory
  4876. * that is owned by the caller and should be
  4877. * freed when no longer needed.
  4878. * id match segment.
  4879. *
  4880. * Returns: 0 if successful, -1 if errors
  4881. *
  4882. * errno Values:
  4883. *
  4884. * Purpose: _DtHelpCeFormatCcdfVolTitleChunks formats volume title for
  4885. * a CCDF Help File.
  4886. *
  4887. ******************************************************************************/
  4888. int
  4889. _DtHelpCeGetCcdfVolTitleChunks(
  4890. _DtHelpVolumeHdl volume,
  4891. _FrmtUiInfo *ui_info,
  4892. void ***ret_chunks)
  4893. {
  4894. char *charSet;
  4895. char *titleStr;
  4896. /*
  4897. * get the title of the volume (we own the memory).
  4898. */
  4899. charSet = _DtHelpCeGetCcdfVolLocale(volume);
  4900. if (charSet == NULL)
  4901. charSet = strdup("C.ISO-8859-1");
  4902. titleStr = _DtHelpCeGetCcdfVolTitle(volume);
  4903. if (titleStr != NULL)
  4904. {
  4905. *ret_chunks = (void **) malloc(sizeof(void *) * 4);
  4906. if (*ret_chunks == NULL)
  4907. return -1;
  4908. (*ret_chunks)[0] = (void *) (DT_HELP_CE_CHARSET | DT_HELP_CE_STRING);
  4909. (*ret_chunks)[1] = (void *) strdup(charSet);
  4910. (*ret_chunks)[2] = (void *) strdup(titleStr);
  4911. (*ret_chunks)[3] = (void *) DT_HELP_CE_END;
  4912. }
  4913. else
  4914. {
  4915. free(charSet);
  4916. if (_DtHelpCeGetCcdfTitleChunks(volume, "_title",
  4917. ui_info, ret_chunks) != 0
  4918. &&
  4919. _DtHelpCeGetCcdfTitleChunks(volume, "_hometopic",
  4920. ui_info, ret_chunks) != 0)
  4921. return -1;
  4922. }
  4923. return 0;
  4924. } /* End _DtHelpCeGetCcdfVolTitleChunks */