FormatCCDF.c 135 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475
  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 libraries 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 *Period = ".";
  298. static const char *Slash = "/";
  299. static const FormatVariables DefVars = {
  300. True, /* int last_was_space; */
  301. False, /* int last_was_mb; */
  302. False, /* int last_was_nl; */
  303. NULL, /* char *rd_buf; */
  304. NULL, /* char *rd_ptr; */
  305. NULL, /* char *fmt_buf; */
  306. NULL, /* char *my_path; */
  307. NULL, /* char *vol_name; */
  308. NULL, /* char *topic_id; */
  309. NULL, /* char *topic_char_set; */
  310. NULL, /* char *topic_lang; */
  311. 0, /* int rd_size; */
  312. 0, /* int rd_flag; */
  313. 1, /* int topic_mb_max; */
  314. 1, /* int cur_mb_max; */
  315. 0, /* int fmt_buf_max; */
  316. 0, /* int fmt_size; */
  317. 0, /* int cell_cnt; */
  318. NULL, /* BufFilePtr my_file; */
  319. { /* SegList my_list; */
  320. 0, /* int cnt; */
  321. 0, /* int max; */
  322. NULL, /* _DtCvSegment *list; */
  323. }, /* SegList my_list; */
  324. NULL, /* _DtCvLinkDb my_links; */
  325. NULL, /* _FrmtUiInfo ui_info; */
  326. };
  327. static const SegList InitList =
  328. {
  329. 0, /* int cnt; */
  330. 0, /* int max; */
  331. NULL, /* _DtCvSegment *list; */
  332. };
  333. static const _DtCvContainer DefContainer =
  334. {
  335. NULL, /* char *id; */
  336. NULL, /* char *justify_char; */
  337. _DtCvDYNAMIC, /* _DtCvFrmtOption type; */
  338. _DtCvBORDER_NONE, /* _DtCvFrmtOption border; */
  339. _DtCvJUSTIFY_LEFT, /* _DtCvFrmtOption justify; */
  340. _DtCvJUSTIFY_TOP, /* _DtCvFrmtOption vjustify; */
  341. _DtCvJUSTIFY_LEFT_MARGIN,/* _DtCvFrmtOption orient; */
  342. _DtCvJUSTIFY_TOP, /* _DtCvFrmtOption vorient; */
  343. _DtCvWRAP_NONE, /* _DtCvFrmtOption flow; */
  344. 10000, /* int percent; */
  345. 0, /* _DtCvUnit leading; */
  346. 0, /* _DtCvUnit fmargin; */
  347. 0, /* _DtCvUnit lmargin; */
  348. 0, /* _DtCvUnit rmargin; */
  349. 0, /* _DtCvUnit tmargin; */
  350. 1, /* _DtCvUnit bmargin; */
  351. {0, NULL}, /* _DtCvLine bdr_info; */
  352. NULL, /* _DtCvSegment seg_list; */
  353. };
  354. static const FrmtPrivateInfo DefPrivInfo =
  355. {
  356. (char) False, /* char top_block; */
  357. (char) False, /* char dup_flag; */
  358. 0, /* int sdl_type; */
  359. 0, /* void *match_info; */
  360. NULL, /* void *id_info; */
  361. NULL, /* void *tmp_info; */
  362. };
  363. /******************************************************************************
  364. *
  365. * Private Functions
  366. *
  367. *****************************************************************************/
  368. /******************************************************************************
  369. * Function: int CreateMarker (
  370. *
  371. * Parameters:
  372. * cur_vars Specifies the current setting of
  373. * formatting variables.
  374. * id_string The id string for the marker.
  375. *
  376. * Returns: 0 if successful, -1 if failure.
  377. *
  378. * Purpose: To create a marker id.
  379. *
  380. *****************************************************************************/
  381. static int
  382. CreateMarker (
  383. FormatVariables *cur_vars,
  384. char *id_string)
  385. {
  386. int result;
  387. /*
  388. * make sure there is room for the marker segment
  389. */
  390. result = CheckSegList(cur_vars);
  391. if (-1 != result)
  392. {
  393. int cnt = cur_vars->my_list.cnt;
  394. _DtCvSegment *list = cur_vars->my_list.list;
  395. /*
  396. * now make a mark segment here.
  397. */
  398. list[cnt].type = _DtCvSetTypeToMarker(list[cnt].type);
  399. _DtCvIdOfMarkerSeg(&list[cnt]) = id_string;
  400. cur_vars->my_list.cnt++;
  401. }
  402. return result;
  403. }
  404. /******************************************************************************
  405. * Function: void GetMbLen (
  406. *
  407. * Parameters:
  408. * cur_vars Specifies the current setting of
  409. * formatting variables.
  410. * font_str Specifies the CCDF string for a
  411. * CHARACTERSET change. The string is
  412. * modified by this routine.
  413. * lang_ptr Returns the language and territory
  414. * value. The caller owns this memory.
  415. * set_ptr Returns the code set of the language.
  416. * The caller owns this memory.
  417. *
  418. * Returns: Nothing
  419. *
  420. * Purpose: 1) To decompose the font_string into a language and code set
  421. * portions.
  422. * 2) To set the mb_cur_len variable in cur_vars.
  423. *
  424. *****************************************************************************/
  425. static void
  426. GetMbLen (
  427. FormatVariables *cur_vars,
  428. char *font_str,
  429. char **lang_ptr,
  430. char **set_ptr)
  431. {
  432. int i;
  433. char *ptr;
  434. char *langPart = NULL;
  435. char *codePart = NULL;
  436. char *mLang = 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 separate 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. goto done;
  457. }
  458. /*
  459. * old CCDF volume
  460. */
  461. if (font_str == NULL || *font_str == '\0') codePart = strdup("UTF-8");
  462. else codePart = strdup(font_str);
  463. mLang = _DtHelpGetLocale();
  464. if (_DtHelpCeStrrchr(mLang, Period, MB_CUR_MAX, &ptr) == 0)
  465. {
  466. *ptr = '\0';
  467. if (mLang != NULL && *mLang != '\0')
  468. {
  469. langPart = strdup(mLang);
  470. goto done;
  471. }
  472. }
  473. langPart = strdup("C");
  474. done:
  475. cur_vars->cur_mb_max = MB_CUR_MAX;
  476. /*
  477. * now set the return variables
  478. */
  479. if (lang_ptr != NULL)
  480. *lang_ptr = langPart;
  481. else
  482. free(langPart);
  483. if (set_ptr != NULL)
  484. *set_ptr = codePart;
  485. else
  486. free(codePart);
  487. free(mLang);
  488. }
  489. /******************************************************************************
  490. * Function: int ReturnLinkWinHint (int ccdf_type)
  491. *
  492. * Parameters:
  493. *
  494. * Returns:
  495. *
  496. * errno Values:
  497. *
  498. * Purpose:
  499. *****************************************************************************/
  500. static int
  501. ReturnLinkWinHint (
  502. int ccdf_type)
  503. {
  504. int winHint = _DtCvWindowHint_CurrentWindow;
  505. if (ccdf_type == CCDF_LINK_JUMP_NEW)
  506. winHint = _DtCvWindowHint_NewWindow;
  507. else if (ccdf_type == CCDF_LINK_DEFINITION)
  508. winHint = _DtCvWindowHint_PopupWindow;
  509. return winHint;
  510. }
  511. /******************************************************************************
  512. * Function: int ReturnLinkType (int ccdf_type, char *spec)
  513. *
  514. * Parameters:
  515. *
  516. * Returns:
  517. *
  518. * errno Values:
  519. *
  520. * Purpose:
  521. *****************************************************************************/
  522. static int
  523. ReturnLinkType (
  524. int ccdf_type,
  525. char *spec)
  526. {
  527. int trueType = _DtCvLinkType_SameVolume;
  528. switch(ccdf_type)
  529. {
  530. case CCDF_LINK_JUMP_NEW:
  531. case CCDF_LINK_JUMP_REUSE:
  532. case CCDF_LINK_DEFINITION:
  533. if (strchr(spec, ' ') != NULL)
  534. trueType = _DtCvLinkType_CrossLink;
  535. break;
  536. case CCDF_LINK_EXECUTE:
  537. trueType = _DtCvLinkType_Execute;
  538. break;
  539. case CCDF_LINK_MAN_PAGE:
  540. trueType = _DtCvLinkType_ManPage;
  541. break;
  542. case CCDF_LINK_APP_DEFINE:
  543. trueType = _DtCvLinkType_AppDefine;
  544. break;
  545. }
  546. return trueType;
  547. }
  548. /******************************************************************************
  549. * Function: int CheckSegList (FormatVariables *cur_vars)
  550. *
  551. * Parameters:
  552. *
  553. * Returns: 0 for success, -1 for errors.
  554. *
  555. * errno Values:
  556. * CEErrorReported
  557. *
  558. * Purpose: Check the global variable 'SegCount' against 'SegMax' and
  559. * realloc/malloc more memory for the global variable 'SegList'
  560. * if necessary. If memory is realloc'ed/malloc'ed, the entry
  561. * 'para_entry->seg_list' is set to 'SegList'.
  562. *
  563. *****************************************************************************/
  564. static int
  565. CheckSegList (
  566. FormatVariables *cur_vars )
  567. {
  568. if (cur_vars->my_list.cnt >= cur_vars->my_list.max)
  569. {
  570. cur_vars->my_list.list = AllocateSegments (cur_vars->my_list.list,
  571. cur_vars->my_list.max,
  572. (cur_vars->my_list.max + GROW_SIZE));
  573. if (NULL == cur_vars->my_list.list)
  574. return -1;
  575. cur_vars->my_list.max += GROW_SIZE;
  576. }
  577. return 0;
  578. }
  579. /******************************************************************************
  580. * Function: static _DtCvSegment *AllocateSegments (_DtCvSegment p_seg,
  581. * int original_size, int new_size)
  582. *
  583. * Parameters:
  584. * p_seg Specifies a pointer to the old list
  585. * of _DtCvSegments.
  586. * original_size Specifies the current size of 'p_seg'.
  587. * new_size Specifies the new size of 'p_seg'.
  588. *
  589. * Returns: A pointer to the new list of structures.
  590. * A NULL indicates an error.
  591. *
  592. * Purpose: (Re)Allocates _DtCvSegment structures and initializes
  593. * them to the default segment which is type _DtCvNOOP
  594. * and the container values set to default values.
  595. *
  596. *****************************************************************************/
  597. static _DtCvSegment *
  598. AllocateSegments (
  599. _DtCvSegment *p_seg,
  600. int original_size,
  601. int new_size )
  602. {
  603. FrmtPrivateInfo *priv = NULL;
  604. if (NULL != p_seg)
  605. {
  606. int count = 0;
  607. /*
  608. * reallocate the segments.
  609. */
  610. p_seg = (_DtCvSegment *) realloc ((void *) p_seg,
  611. (sizeof(_DtCvSegment) * new_size));
  612. /*
  613. * reallocate the private formatting information.
  614. */
  615. priv = p_seg->client_use;
  616. priv = (FrmtPrivateInfo *) realloc ((void *) priv,
  617. sizeof(FrmtPrivateInfo) * new_size);
  618. if (NULL == priv)
  619. {
  620. free(p_seg);
  621. p_seg = NULL;
  622. return NULL;
  623. }
  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 'UTF-8' 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 'UTF-8' 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 (_FrmtUiInfo *ui_info)
  4334. *
  4335. * Parameters:
  4336. *
  4337. * Returns: NULL if unsuccessful.
  4338. *
  4339. * errno Values:
  4340. *
  4341. * Purpose:
  4342. *
  4343. ******************************************************************************/
  4344. VarHandle
  4345. __DtHelpCeSetUpVars(
  4346. _FrmtUiInfo *ui_info)
  4347. {
  4348. FormatVariables *newVars;
  4349. newVars = (FormatVariables *) malloc (sizeof(FormatVariables));
  4350. *newVars = DefVars;
  4351. newVars->ui_info = ui_info;
  4352. newVars->topic_mb_max = MB_CUR_MAX;
  4353. newVars->cur_mb_max = newVars->topic_mb_max;
  4354. return ((VarHandle) newVars);
  4355. } /* End __DtHelpCeSetUpVars */
  4356. /******************************************************************************
  4357. * Function: int __DtHelpCeProcessString (char *in_string, int seg_type,
  4358. * char **font_attr)
  4359. *
  4360. * Parameters:
  4361. *
  4362. * Returns: 0 if successful, -1 if errors.
  4363. *
  4364. * errno Values:
  4365. *
  4366. * Purpose:
  4367. *
  4368. ******************************************************************************/
  4369. int
  4370. __DtHelpCeProcessString(
  4371. VarHandle var_handle,
  4372. BufFilePtr my_file,
  4373. _DtCvFrmtOption frmt_type,
  4374. char *scan_string,
  4375. char *in_string,
  4376. int in_size,
  4377. int fnt_flag,
  4378. int ret_on_nl,
  4379. _DtHelpFontHints *font_attr )
  4380. {
  4381. int done = 0;
  4382. FormatVariables *myVars = (FormatVariables *) var_handle;
  4383. SegList oldList = myVars->my_list;
  4384. myVars->rd_buf = in_string;
  4385. myVars->rd_size = in_size;
  4386. myVars->rd_ptr = in_string;
  4387. myVars->my_file = my_file;
  4388. if (my_file == NULL)
  4389. myVars->rd_flag = 0;
  4390. else
  4391. myVars->rd_flag = strlen(in_string);
  4392. while (!done)
  4393. {
  4394. if (True == ret_on_nl)
  4395. myVars->my_list = InitList;
  4396. done = Parse (CCDF_FONT_CMD, NormalState, myVars,
  4397. 0, frmt_type,
  4398. font_attr,
  4399. -1, scan_string, (CCDF_FONT_CMD | CCDF_OCTAL_CMD), ret_on_nl,
  4400. fnt_flag);
  4401. if (done != -1 && True == ret_on_nl)
  4402. {
  4403. TerminateSegList (&(myVars->my_list), True);
  4404. if (NULL != myVars->my_list.list)
  4405. {
  4406. done = CheckList (&oldList, 1, GROW_SIZE);
  4407. if (-1 != done)
  4408. {
  4409. _DtCvSegment *newSeg = NextAvailSeg(oldList);
  4410. newSeg->type = _DtCvSetTypeToContainer(newSeg->type);
  4411. _DtCvContainerListOfSeg(newSeg) = myVars->my_list.list;
  4412. _DtCvContainerTypeOfSeg(newSeg) = _DtCvDYNAMIC;
  4413. oldList.cnt++;
  4414. TerminateSegList(&oldList, False);
  4415. }
  4416. }
  4417. }
  4418. }
  4419. if (False == ret_on_nl)
  4420. oldList = myVars->my_list;
  4421. myVars->my_list = oldList;
  4422. return done;
  4423. } /* End __DtHelpCeProcessString */
  4424. /*****************************************************************************
  4425. * Function: int __DtHelpCeGetParagraphList (
  4426. *
  4427. * Parameters:
  4428. *
  4429. * Returns: 0 if successful, -1 if errors.
  4430. *
  4431. * errno Values:
  4432. *
  4433. * Purpose: _DtHelpFormatGetParagraphList places a terminator on the
  4434. * last segment in the current paragraph and returns the
  4435. * segment list included in the topic information structure.
  4436. *
  4437. * If make_cont is true, the segment list is first included
  4438. * in a container with the specified type.
  4439. *
  4440. *****************************************************************************/
  4441. int
  4442. __DtHelpCeGetParagraphList (
  4443. VarHandle var_handle,
  4444. int make_cont,
  4445. _DtCvFrmtOption type,
  4446. _DtCvTopicPtr *ret_handle)
  4447. {
  4448. int result = -1;
  4449. FormatVariables *myVars = (FormatVariables *) var_handle;
  4450. _DtCvTopicInfo *topicHandle;
  4451. /*
  4452. * check the parameters.
  4453. */
  4454. if (ret_handle == NULL || myVars == NULL)
  4455. {
  4456. errno = EINVAL;
  4457. return -1;
  4458. }
  4459. TerminateSegList(&(myVars->my_list), True);
  4460. topicHandle = (_DtCvTopicInfo *) malloc (sizeof(_DtCvTopicInfo));
  4461. if (topicHandle != NULL)
  4462. {
  4463. result = 0;
  4464. if (True == make_cont)
  4465. {
  4466. _DtCvSegment *myCont = AllocateSegments(NULL, 0, 1);
  4467. if (NULL != myCont)
  4468. {
  4469. myCont->type = _DtCvSetTypeToContainer(myCont->type);
  4470. _DtCvContainerTypeOfSeg(myCont) = type;
  4471. _DtCvContainerListOfSeg(myCont) = myVars->my_list.list;
  4472. myVars->my_list.list = myCont;
  4473. myVars->my_list.cnt = 1;
  4474. myVars->my_list.max = 1;
  4475. }
  4476. else
  4477. result = -1;
  4478. }
  4479. topicHandle->id_str = NULL;
  4480. topicHandle->seg_list = myVars->my_list.list;
  4481. topicHandle->mark_list = NULL;
  4482. topicHandle->link_data = myVars->my_links;
  4483. *ret_handle = (_DtCvTopicPtr) topicHandle;
  4484. }
  4485. if (myVars->fmt_buf != NULL)
  4486. free(myVars->fmt_buf);
  4487. return result;
  4488. }
  4489. /******************************************************************************
  4490. * Function: int _DtHelpCeFrmtCcdfTopic (_DtHelpVolumeHdl volume, char *filename,
  4491. * int offset, char *id_string,
  4492. * _DtCvTopicPtr *ret_handle)
  4493. *
  4494. * Parameters:
  4495. * volume Specifies the Help Volume the information
  4496. * is associated with.
  4497. * filename Specifies the file containing the Help Topic
  4498. * desired.
  4499. * offset Specifies the offset into 'filename' to
  4500. * the Help Topic desired.
  4501. * id_string Specifies the location id to look for or NULL.
  4502. * ret_handle Returns a handle to the topic information
  4503. * including the number of paragraphs and the
  4504. * id match segment.
  4505. *
  4506. * Returns: 0 if successful, -1 if errors
  4507. *
  4508. * errno Values:
  4509. *
  4510. * Purpose: _DtHelpCeFrmtCcdfTopic formats Help Files with formatting
  4511. * information into a Canvas Engine structure.
  4512. *
  4513. ******************************************************************************/
  4514. int
  4515. _DtHelpCeFrmtCcdfTopic(
  4516. _DtHelpVolumeHdl volume,
  4517. char *filename,
  4518. int offset,
  4519. char *id_string,
  4520. _FrmtUiInfo *ui_info,
  4521. _DtCvTopicPtr *ret_handle )
  4522. {
  4523. int result = -1;
  4524. char *ptr;
  4525. FormatVariables variables;
  4526. /*
  4527. * Check the parameters
  4528. */
  4529. if (volume == NULL || filename == NULL || offset < 0 || ret_handle == NULL)
  4530. {
  4531. errno = EINVAL;
  4532. return -1;
  4533. }
  4534. /*
  4535. * get the current file path.
  4536. */
  4537. variables = DefVars;
  4538. variables.topic_id = id_string;
  4539. if (volume)
  4540. {
  4541. variables.vol_name = _DtHelpCeGetVolumeName(volume);
  4542. variables.my_path = strdup (variables.vol_name);
  4543. if (variables.my_path == NULL)
  4544. return -1;
  4545. result = _DtHelpCeStrrchr (variables.my_path, Slash, MB_CUR_MAX, &ptr);
  4546. if (result == -1)
  4547. ptr = strrchr (variables.my_path, '/');
  4548. if (ptr)
  4549. *ptr = '\0';
  4550. }
  4551. /*
  4552. * open the file and seek to the correct place.
  4553. */
  4554. result = _DtHelpCeFileOpenAndSeek (filename, offset, -1,
  4555. &(variables.my_file), NULL);
  4556. if (result != -1)
  4557. {
  4558. /*
  4559. * Initialize the X variables.
  4560. */
  4561. result = Format (&variables, ui_info, id_string, ret_handle);
  4562. _DtHelpCeBufFileClose (variables.my_file, True);
  4563. }
  4564. if (variables.fmt_buf != NULL)
  4565. free (variables.fmt_buf);
  4566. if (variables.my_path != NULL)
  4567. free (variables.my_path);
  4568. return result;
  4569. } /* End _DtHelpCeFrmtCcdfTopic */
  4570. /******************************************************************************
  4571. * Function: int _DtHelpCeFrmtCcdfPathAndChildren (
  4572. * _DtHelpVolumeHdl volume,
  4573. * _DtCvTopicPtr *ret_handle)
  4574. *
  4575. * Parameters:
  4576. * ret_handle Returns a handle to the topic information
  4577. * including the number of paragraphs and the
  4578. * id match segment.
  4579. *
  4580. * Returns: 0 if successful, -1 if errors, 1 if there the path is empty.
  4581. *
  4582. * errno Values:
  4583. *
  4584. * Purpose: _DtHelpCeFormatCcdfToc formats Table of Contents for
  4585. * a CCDF Help File.
  4586. *
  4587. ******************************************************************************/
  4588. int
  4589. _DtHelpCeFrmtCcdfPathAndChildren(
  4590. _DtHelpVolumeHdl volume,
  4591. char *loc_id,
  4592. _FrmtUiInfo *ui_info,
  4593. _DtCvTopicPtr *ret_handle )
  4594. {
  4595. int result = 0;
  4596. int pathCnt;
  4597. char *ptr;
  4598. char **pathHead;
  4599. char readBuf[BUFF_SIZE];
  4600. FormatVariables myVars;
  4601. _DtHelpFontHints fontAttrs;
  4602. _DtHelpCeCopyDefFontAttrList (&fontAttrs);
  4603. fontAttrs.pointsz = 10;
  4604. fontAttrs.weight = _DtHelpFontWeightMedium;
  4605. fontAttrs.style = _DtHelpFontStyleSanSerif;
  4606. /*
  4607. * Check the parameters
  4608. */
  4609. if (volume == NULL || ret_handle == NULL)
  4610. {
  4611. errno = EINVAL;
  4612. return -1;
  4613. }
  4614. readBuf[0] = '\0';
  4615. myVars = DefVars;
  4616. if (InitStructure (&myVars, ui_info, readBuf, BUFF_SIZE) == -1)
  4617. return -1;
  4618. /*
  4619. * get the list of topics in the volume.
  4620. */
  4621. pathCnt = _DtHelpCeGetCcdfIdPath(volume, loc_id, &pathHead);
  4622. if (pathCnt == -1)
  4623. return -1;
  4624. /*
  4625. * Check to see if this topic is in the topic list.
  4626. * I.e. if a count of 1 is returned this should match the
  4627. * top topic, otherwise this is an hidden topic.
  4628. */
  4629. if (pathCnt == 1)
  4630. {
  4631. if (_DtHelpCeGetCcdfTopTopic(volume, &ptr) == -1)
  4632. result = -1;
  4633. else if (_DtCvStrCaseCmpLatin1(ptr, *pathHead) != 0)
  4634. result = 1;
  4635. }
  4636. /*
  4637. * if result is non-zero, we had problems or this is a hidden topic
  4638. */
  4639. if (result == 0)
  4640. {
  4641. fontAttrs.slant = _DtHelpFontSlantRoman;
  4642. myVars.topic_id = loc_id;
  4643. myVars.vol_name = _DtHelpCeGetVolumeName(volume);
  4644. myVars.my_path = strdup (myVars.vol_name);
  4645. if (myVars.my_path == NULL)
  4646. return -1;
  4647. if (-1 == _DtHelpCeStrrchr (myVars.my_path, Slash, MB_CUR_MAX, &ptr))
  4648. ptr = strrchr (myVars.my_path, '/');
  4649. if (ptr)
  4650. *ptr = '\0';
  4651. result = FormatExpandedToc(volume, loc_id, pathHead,
  4652. &myVars, fontAttrs, 0);
  4653. _DtCvFreeArray((void **) pathHead);
  4654. }
  4655. if (result != -1)
  4656. result = __DtHelpCeGetParagraphList (&myVars, False, _DtCvDYNAMIC,
  4657. ret_handle);
  4658. /*
  4659. * check for an empty path.
  4660. */
  4661. if (-1 != result && NULL == ((_DtCvTopicInfo *) *ret_handle)->seg_list)
  4662. result = 1;
  4663. if (myVars.my_path != NULL)
  4664. free(myVars.my_path);
  4665. return result;
  4666. } /* End _DtHelpCeFrmtCcdfPathAndChildren */
  4667. /******************************************************************************
  4668. * Function: int _DtHelpCeGetCcdfTitleChunks (
  4669. * _DtHelpVolumeHdl volume,
  4670. * _DtCvTopicPtr *ret_handle)
  4671. *
  4672. * Parameters:
  4673. * ret_handle Returns a handle to the topic information
  4674. * including the number of paragraphs and the
  4675. * id match segment.
  4676. *
  4677. * Returns: 0 if successful, -1 if errors
  4678. *
  4679. * errno Values:
  4680. *
  4681. * Purpose: _DtHelpCeFormatCcdfToc formats Table of Contents for
  4682. * a CCDF Help File.
  4683. *
  4684. ******************************************************************************/
  4685. int
  4686. _DtHelpCeGetCcdfTitleChunks(
  4687. _DtHelpVolumeHdl volume,
  4688. char *loc_id,
  4689. _FrmtUiInfo *ui_info,
  4690. void ***ret_chunks)
  4691. {
  4692. long type = 0;
  4693. int result = 0;
  4694. int offset;
  4695. char *fileName;
  4696. char *ptr;
  4697. char readBuf[BUFF_SIZE];
  4698. _DtCvSegment *titleSeg;
  4699. _DtCvSegment *list = NULL;
  4700. FormatVariables myVars;
  4701. _DtHelpFontHints fontAttrs;
  4702. _DtHelpCeLockInfo lockInfo;
  4703. /*
  4704. * Check the parameters
  4705. */
  4706. if (volume == NULL || ret_chunks == NULL)
  4707. {
  4708. errno = EINVAL;
  4709. return -1;
  4710. }
  4711. /*
  4712. * init the return value
  4713. */
  4714. *ret_chunks = NULL;
  4715. /*
  4716. * get the topic in the volume.
  4717. */
  4718. if (_DtHelpCeLockVolume(volume, &lockInfo) != 0)
  4719. return -1;
  4720. if (_DtHelpCeFindId(volume, loc_id, -1, &fileName, &offset) == False)
  4721. {
  4722. _DtHelpCeUnlockVolume(lockInfo);
  4723. return -1;
  4724. }
  4725. _DtHelpCeCopyDefFontAttrList (&fontAttrs);
  4726. myVars = DefVars;
  4727. if (InitStructure (&myVars, ui_info, readBuf, BUFF_SIZE) == -1)
  4728. {
  4729. _DtHelpCeUnlockVolume(lockInfo);
  4730. return -1;
  4731. }
  4732. /*
  4733. * initialize my variables.
  4734. */
  4735. myVars.topic_id = loc_id;
  4736. myVars.vol_name = _DtHelpCeGetVolumeName(volume);
  4737. myVars.my_path = strdup (myVars.vol_name);
  4738. if (myVars.my_path == NULL)
  4739. {
  4740. _DtHelpCeUnlockVolume(lockInfo);
  4741. return -1;
  4742. }
  4743. if (-1 == _DtHelpCeStrrchr (myVars.my_path, Slash, MB_CUR_MAX, &ptr))
  4744. ptr = strrchr (myVars.my_path, '/');
  4745. if (ptr)
  4746. *ptr = '\0';
  4747. result = FormatCCDFTitle(&myVars, fontAttrs, fileName,
  4748. offset, 0, (1 << _CEFONT_SIZE), True);
  4749. free(fileName);
  4750. if (-1 != result && 0 < myVars.my_list.cnt)
  4751. {
  4752. titleSeg = &(myVars.my_list.list[myVars.my_list.cnt - 1]);
  4753. list = _DtCvContainerListOfSeg(titleSeg);
  4754. }
  4755. if (result != -1 && NULL != list)
  4756. {
  4757. _DtCvSegment *pSeg = list;
  4758. while (-1 != result && NULL != pSeg)
  4759. {
  4760. /*
  4761. * create the types and add the informatio to the array.
  4762. */
  4763. type = DT_HELP_CE_FONT_PTR | DT_HELP_CE_STRING;
  4764. if (_DtCvIsSegNewLine(pSeg))
  4765. type |= DT_HELP_CE_NEWLINE;
  4766. if (_DtCvIsSegString(pSeg))
  4767. {
  4768. *ret_chunks = (void **) _DtCvAddPtrToArray(*ret_chunks,
  4769. (void *) type);
  4770. if (NULL != *ret_chunks)
  4771. *ret_chunks = (void **) _DtCvAddPtrToArray(*ret_chunks,
  4772. (void *) _DtCvFontOfStringSeg(pSeg));
  4773. if (NULL != *ret_chunks)
  4774. {
  4775. if (_DtCvIsSegWideChar(pSeg))
  4776. {
  4777. offset = _DtCvStrLen(_DtCvStringOfStringSeg(pSeg), 1)
  4778. * MB_CUR_MAX + 1;
  4779. ptr = (char *) malloc (sizeof(char) * offset);
  4780. if (NULL != ptr)
  4781. wcstombs(ptr,
  4782. (wchar_t *)_DtCvStringOfStringSeg(pSeg),
  4783. offset);
  4784. }
  4785. else
  4786. ptr = strdup((char *) _DtCvStringOfStringSeg(pSeg));
  4787. if (NULL != ptr)
  4788. *ret_chunks = (void **)_DtCvAddPtrToArray(
  4789. *ret_chunks, (void *) ptr);
  4790. }
  4791. if (NULL == *ret_chunks || NULL == ptr)
  4792. result = -1;
  4793. }
  4794. /*
  4795. * go to the next segment
  4796. */
  4797. pSeg = pSeg->next_seg;
  4798. }
  4799. }
  4800. else
  4801. {
  4802. char buf[128];
  4803. char *idStr;
  4804. int idLen = strlen (loc_id) + 9;
  4805. /*
  4806. * create the location id string.
  4807. */
  4808. idStr = (char *) malloc (idLen);
  4809. if (NULL != idStr)
  4810. {
  4811. /*
  4812. * format the location id
  4813. */
  4814. strcpy (idStr, "...(");
  4815. strcat (idStr, loc_id);
  4816. strcat (idStr, ")...");
  4817. /*
  4818. * format the language and codeset
  4819. */
  4820. strcpy(buf, _DtHelpFontHintsLang(fontAttrs));
  4821. strcat(buf, ".");
  4822. strcpy(buf, _DtHelpFontHintsCharSet(fontAttrs));
  4823. /*
  4824. * creat a chunk table
  4825. */
  4826. *ret_chunks = (void **) _DtCvAddPtrToArray(*ret_chunks,
  4827. (void *) (DT_HELP_CE_CHARSET | DT_HELP_CE_STRING));
  4828. if (NULL != *ret_chunks)
  4829. *ret_chunks = (void **) _DtCvAddPtrToArray(*ret_chunks,
  4830. (void *) strdup(buf));
  4831. if (NULL != *ret_chunks)
  4832. *ret_chunks = (void **) _DtCvAddPtrToArray(*ret_chunks,
  4833. (void *) idStr);
  4834. }
  4835. }
  4836. if (NULL != *ret_chunks)
  4837. *ret_chunks = (void **) _DtCvAddPtrToArray(*ret_chunks,
  4838. (void *) DT_HELP_CE_END);
  4839. /*
  4840. * free the list
  4841. */
  4842. if (0 < myVars.my_list.cnt)
  4843. _DtHelpFreeSegments(myVars.my_list.list, _DtCvFALSE,
  4844. ui_info->destroy_region,
  4845. ui_info->client_data);
  4846. /*
  4847. * free the link database
  4848. */
  4849. _DtLinkDbDestroy(myVars.my_links);
  4850. /*
  4851. * free memory
  4852. */
  4853. if (myVars.my_path != NULL)
  4854. free(myVars.my_path);
  4855. if (myVars.fmt_buf != NULL)
  4856. free(myVars.fmt_buf);
  4857. _DtHelpCeUnlockVolume(lockInfo);
  4858. /*
  4859. * indicate an error if problems.
  4860. */
  4861. result = 0;
  4862. if (NULL == *ret_chunks)
  4863. result = -1;
  4864. return result;
  4865. } /* End _DtHelpCeGetCcdfTitleChunks */
  4866. /******************************************************************************
  4867. * Function: int _DtHelpCeGetCcdfVolTitleChunks (
  4868. * _DtHelpVolumeHdl volume,
  4869. * void ***ret_chunks)
  4870. *
  4871. * Parameters:
  4872. * ret_chunks Returns a ptr to the title information chunks
  4873. * The title chunks are stored in allocated memory
  4874. * that is owned by the caller and should be
  4875. * freed when no longer needed.
  4876. * id match segment.
  4877. *
  4878. * Returns: 0 if successful, -1 if errors
  4879. *
  4880. * errno Values:
  4881. *
  4882. * Purpose: _DtHelpCeFormatCcdfVolTitleChunks formats volume title for
  4883. * a CCDF Help File.
  4884. *
  4885. ******************************************************************************/
  4886. int
  4887. _DtHelpCeGetCcdfVolTitleChunks(
  4888. _DtHelpVolumeHdl volume,
  4889. _FrmtUiInfo *ui_info,
  4890. void ***ret_chunks)
  4891. {
  4892. char *charSet;
  4893. char *titleStr;
  4894. /*
  4895. * get the title of the volume (we own the memory).
  4896. */
  4897. charSet = _DtHelpCeGetCcdfVolLocale(volume);
  4898. if (charSet == NULL)
  4899. charSet = strdup("C.UTF-8");
  4900. titleStr = _DtHelpCeGetCcdfVolTitle(volume);
  4901. if (titleStr != NULL)
  4902. {
  4903. *ret_chunks = (void **) malloc(sizeof(void *) * 4);
  4904. if (*ret_chunks == NULL)
  4905. return -1;
  4906. (*ret_chunks)[0] = (void *) (DT_HELP_CE_CHARSET | DT_HELP_CE_STRING);
  4907. (*ret_chunks)[1] = (void *) strdup(charSet);
  4908. (*ret_chunks)[2] = (void *) strdup(titleStr);
  4909. (*ret_chunks)[3] = (void *) DT_HELP_CE_END;
  4910. }
  4911. else
  4912. {
  4913. free(charSet);
  4914. if (_DtHelpCeGetCcdfTitleChunks(volume, "_title",
  4915. ui_info, ret_chunks) != 0
  4916. &&
  4917. _DtHelpCeGetCcdfTitleChunks(volume, "_hometopic",
  4918. ui_info, ret_chunks) != 0)
  4919. return -1;
  4920. }
  4921. return 0;
  4922. } /* End _DtHelpCeGetCcdfVolTitleChunks */