texi2html.pl 624 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395
  1. #! @PERL@ --
  2. # perl
  3. 'di ';
  4. 'ig 00 ';
  5. #+##############################################################################
  6. #
  7. # texi2html: Parse and transform Texinfo documents
  8. #
  9. # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
  10. # 2009, 2010, 2011 Free Software Foundation, Inc.
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 3 of the License,
  15. # or (at your option) any later version.
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. #
  22. # You should have received a copy of the GNU General Public License
  23. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. #
  25. #
  26. # Some error messages come from texinfo (makeinfo), so copyright holder
  27. # is the FSF or the individual who wrote them. All come from before the
  28. # switch of texinfo to GPLv3+.
  29. #
  30. # Originally written by Lionel Cons.
  31. #
  32. #-##############################################################################
  33. # The man page for this program is included at the end of this file and can be
  34. # viewed using the command 'nroff -man texi2html'.
  35. # for POSIX::setlocale and File::Spec
  36. require 5.00405;
  37. # Perl pragma to restrict unsafe constructs
  38. use strict;
  39. # used in case of tests, to revert to "C" locale.
  40. use POSIX qw(setlocale LC_ALL LC_CTYPE);
  41. # used to obtain the name of the current working directory
  42. use Cwd;
  43. # Used to find the parent directory of this script.
  44. use File::Basename;
  45. # used to find a relative path back to the current working directory
  46. use File::Spec;
  47. # to determine the path separator and null file
  48. use Config;
  49. #use encoding::warnings;
  50. # for translations
  51. #use encoding 'utf8';
  52. #use utf8;
  53. #
  54. # According to
  55. # larry.jones@sdrc.com (Larry Jones)
  56. # this pragma is not present in perl5.004_02:
  57. #
  58. # Perl pragma to control optional warnings
  59. # use warnings;
  60. # determine the path separators
  61. my $path_separator = $Config{'path_sep'};
  62. $path_separator = ':' if (!defined($path_separator));
  63. my $quoted_path_separator = quotemeta($path_separator);
  64. #++##########################################################################
  65. #
  66. # NOTE FOR DEBUGGING THIS SCRIPT:
  67. # You can run 'perl -x texi2html.pl' directly, provided you have the script
  68. # in the same directory with, or the environment variable T2H_HOME set to
  69. # the directory containing, the texi2html.pm, T2h_i18n.pm, translations.pl,
  70. # l2h.init, & T2h_l2h.pm files. Ditto makeinfo.pl, if you make it a
  71. # symlink to texi2html.pl.
  72. #
  73. #--##########################################################################
  74. my $T2H_HOME = defined $ENV{T2H_HOME} ? $ENV{T2H_HOME} : dirname $0;
  75. if ($0 =~ /\.pl$/)
  76. {
  77. # Issue a warning in debugging mode if $T2H_HOME is set but isn't
  78. # accessible.
  79. if (!-e $T2H_HOME)
  80. { warn "T2H_HOME ($T2H_HOME) does not exist."; }
  81. elsif (!-d $T2H_HOME)
  82. { warn "T2H_HOME ($T2H_HOME) is not a directory."; }
  83. elsif (!-x $T2H_HOME)
  84. { warn "T2H_HOME ($T2H_HOME) is not accessible."; }
  85. }
  86. # CVS version:
  87. # $Id$
  88. # Homepage:
  89. my $T2H_HOMEPAGE = "http://www.gnu.org/software/texinfo/";
  90. # Version: set in configure.in
  91. my $THISVERSION = '@PACKAGE_VERSION@';
  92. my $THISPROG = '@PACKAGE_NAME@';
  93. my $THISPROG_THISVERSION = "$THISPROG $THISVERSION"; # program name and version
  94. #+++########################################################################
  95. # #
  96. # Paths and file names #
  97. # #
  98. #---########################################################################
  99. # set by configure, prefix for the sysconfdir and so on
  100. my $prefix = '@prefix@';
  101. my $datarootdir;# = '@datarootdir@';
  102. my $sysconfdir;
  103. my $pkgdatadir;
  104. my $datadir;
  105. # We need to eval as $prefix has to be expanded. However when we haven't
  106. # run configure @sysconfdir will be expanded as an array, thus we verify
  107. # whether configure was run or not
  108. if ('@sysconfdir@' ne '@' . 'sysconfdir@')
  109. {
  110. $sysconfdir = eval '"@sysconfdir@"';
  111. }
  112. else
  113. {
  114. $sysconfdir = "/usr/local/etc";
  115. }
  116. if ('@datarootdir@' ne '@' . 'datarootdir@')
  117. {
  118. $datarootdir = eval '"@datarootdir@"';
  119. }
  120. else
  121. {
  122. $datarootdir = "/usr/local/share";
  123. }
  124. if ('@datadir@' ne '@' . 'datadir@')
  125. {
  126. $pkgdatadir = eval '"@datadir@/@PACKAGE@"';
  127. $datadir = eval '"@datadir@"';
  128. }
  129. else
  130. {
  131. $pkgdatadir = "/usr/local/share/texi2html";
  132. $datadir = "/usr/local/share";
  133. }
  134. my $target_prefix = "t_h";
  135. #+++########################################################################
  136. # #
  137. # Constants #
  138. # #
  139. #---########################################################################
  140. my $DEBUG_MENU = 1;
  141. my $DEBUG_INDEX = 2;
  142. my $DEBUG_TEXI = 4;
  143. my $DEBUG_MACROS = 8;
  144. my $DEBUG_FORMATS = 16;
  145. my $DEBUG_ELEMENTS = 32;
  146. my $DEBUG_USER = 64;
  147. my $DEBUG_L2H = 128;
  148. my $VARRE = '[\w\-]+'; # RE for a variable name
  149. my $MAX_LEVEL = 4;
  150. my $MIN_LEVEL = 1;
  151. # all settable variables that are reset between every pass
  152. # FIXME is it really right?
  153. # Yes, for documentlanguage, clickstyle, allowcodebreaks.
  154. # Maybe not for frenchspacing?
  155. my @document_settable_at_commands =
  156. ('everyheading', 'everyfooting', 'evenheading',
  157. 'evenfooting', 'oddheading', 'oddfooting', 'headings',
  158. 'allowcodebreaks', 'frenchspacing', 'exampleindent',
  159. 'firstparagraphindent', 'paragraphindent', 'clickstyle',
  160. 'documentlanguage');
  161. # those are not reset such that they are available between passes.
  162. my @document_global_at_commands = ('contents', 'shortcontents',
  163. 'setcontentsaftertitlepage', 'setshortcontentsaftertitlepage',
  164. 'footnotestyle', 'novalidate', 'kbdinputstyle', 'documentencoding',
  165. 'setfilename', 'today', 'documentdescription',
  166. # the following are not set to anything in the default
  167. # case, and currently not used anywhere
  168. 'everyheadingmarks','everyfootingmarks',
  169. 'evenheadingmarks','oddheadingmarks','evenfootingmarks','oddfootingmarks',
  170. 'fonttextsize', 'pagesizes', 'setchapternewpage'
  171. );
  172. my @command_line_settables = ('FILLCOLUMN', 'SPLIT', 'SPLIT_SIZE',
  173. 'HEADERS',
  174. 'MACRO_EXPAND', 'NUMBER_SECTIONS',
  175. 'NUMBER_FOOTNOTES', 'NODE_FILES',
  176. 'NO_WARN', 'VERBOSE',
  177. 'TRANSLITERATE_FILE_NAMES', 'ERROR_LIMIT', 'ENABLE_ENCODING',
  178. 'FORCE', 'INTERNAL_LINKS', 'OUTFILE', 'SUBDIR', 'OUT',
  179. 'BATCH', 'SILENT'
  180. );
  181. # FIXME TOP_HEADING_AT_BEGINNING seems to be a no-op
  182. my @variable_settables = (
  183. 'DEBUG', 'FRAMES', 'FRAMESET_DOCTYPE', 'DOCTYPE', 'TEST', 'DUMP_TEXI',
  184. 'TOP_FILE', 'TOC_FILE', 'SHOW_MENU', 'USE_NODES', 'TOC_LINKS', 'SHORTEXTN',
  185. 'PREFIX', 'SHORT_REF', 'IDX_SUMMARY', 'DEF_TABLE', 'L2H', 'MONOLITHIC',
  186. 'L2H_L2H', 'L2H_SKIP', 'L2H_TMP', 'L2H_FILE', 'L2H_CLEAN',
  187. 'L2H_HTML_VERSION', 'IGNORE_PREAMBLE_TEXT', 'EXTERNAL_DIR', 'USE_ISO',
  188. 'SPLIT_INDEX', 'IN_ENCODING', 'USE_NLS',
  189. 'VERTICAL_HEAD_NAVIGATION', 'INLINE_CONTENTS', 'NODE_FILE_EXTENSION',
  190. 'NO_CSS', 'INLINE_CSS_STYLE', 'USE_SECTIONS', 'USE_TITLEPAGE_FOR_TITLE',
  191. 'SIMPLE_MENU', 'EXTENSION', 'INLINE_INSERTCOPYING', 'USE_NUMERIC_ENTITY',
  192. 'I18N_PERL_HASH', 'ENABLE_ENCODING_USE_ENTITY', 'ICONS', 'USE_UNICODE',
  193. 'USE_UNIDECODE', 'DATE_IN_HEADER', 'OPEN_QUOTE_SYMBOL',
  194. 'CLOSE_QUOTE_SYMBOL', 'TOP_NODE_UP', 'TOP_NODE_FILE',
  195. 'TOP_NODE_FILE_TARGET', 'SHOW_TITLE', 'WORDS_IN_PAGE',
  196. 'HEADER_IN_TABLE', 'USE_ACCESSKEY', 'USE_REL_REV', 'USE_LINKS',
  197. 'OVERVIEW_LINK_TO_TOC', 'AVOID_MENU_REDUNDANCY', 'NODE_NAME_IN_MENU',
  198. 'NODE_NAME_IN_INDEX', 'USE_SETFILENAME', 'USE_SETFILENAME_EXTENSION',
  199. 'COMPLEX_FORMAT_IN_TABLE',
  200. 'USE_UP_FOR_ADJACENT_NODES', 'TOP_HEADING_AT_BEGINNING',
  201. 'SEPARATE_DESCRIPTION', 'IGNORE_BEFORE_SETFILENAME',
  202. 'COMPLETE_IMAGE_PATHS', 'USE_NODE_TARGET', 'NEW_CROSSREF_STYLE',
  203. 'PROGRAM_NAME_IN_FOOTER', 'NODE_FILENAMES', 'DEFAULT_ENCODING',
  204. 'OUT_ENCODING', 'ENCODING_NAME', 'EXTERNAL_CROSSREF_SPLIT', 'BODYTEXT',
  205. 'CSS_LINES', 'RENAMED_NODES_REDIRECTIONS', 'RENAMED_NODES_FILE',
  206. 'TEXI2DVI', 'DO_ABOUT');
  207. foreach my $var (@document_settable_at_commands, @command_line_settables,
  208. @document_global_at_commands, @variable_settables)
  209. {
  210. $Texi2HTML::GLOBAL{'variable_levels'}->{$var} = 10;
  211. }
  212. #+++########################################################################
  213. # #
  214. # Command name and default format #
  215. # #
  216. #---########################################################################
  217. my $real_command_name = $0;
  218. $real_command_name =~ s/.*\///;
  219. $real_command_name =~ s/\.pl$//;
  220. my %command_format = (
  221. 'texi2html' => 'html',
  222. 'makeinfo' => 'info',
  223. 'texi2any' => 'raw-text',
  224. );
  225. # Config files
  226. my $i18n_dir = 'i18n'; # name of the directory containing the per language files
  227. my $conf_file_name = 'Config' ;
  228. my $texinfo_htmlxref = 'htmlxref.cnf';
  229. # directories for texinfo configuration files
  230. my @language_config_dirs = ('./.texinfo');
  231. push @language_config_dirs, "$ENV{'HOME'}/.texinfo" if (defined($ENV{'HOME'}));
  232. push @language_config_dirs, "$sysconfdir/texinfo" if (defined($sysconfdir));
  233. push @language_config_dirs, "$datadir/texinfo" if (defined($datadir));
  234. my @texinfo_config_dirs = ('.', @language_config_dirs);
  235. my @program_config_dirs;
  236. my @program_init_dirs;
  237. # program name dependent initializations: config directories and default
  238. # format.
  239. sub set_config_init_dirs_output($)
  240. {
  241. my $program_name = shift;
  242. if (!defined($command_format{$program_name}))
  243. {
  244. # user can make any link to set $0, or use --program with an unknown name.
  245. # In that case the default is to use texi2any
  246. $program_name = 'texi2any';
  247. }
  248. my $default_output_format = $command_format{$program_name};
  249. # directories for config files
  250. @program_config_dirs = ('.', "./.$program_name");
  251. push @program_config_dirs, "$ENV{'HOME'}/.$program_name" if (defined($ENV{'HOME'}));
  252. push @program_config_dirs, "$sysconfdir/$program_name" if (defined($sysconfdir));
  253. push @program_config_dirs, "$datadir/$program_name" if (defined($datadir));
  254. # directories for init files
  255. @program_init_dirs = @program_config_dirs;
  256. # common directories for all command names
  257. foreach my $texinfo_config_dir (@language_config_dirs)
  258. {
  259. push @program_init_dirs, "${texinfo_config_dir}/init";
  260. }
  261. $Texi2HTML::Config::DEFAULT_OUTPUT_FORMAT = $default_output_format;
  262. $Texi2HTML::Config::COMMAND_NAME = $program_name;
  263. Texi2HTML::Config::t2h_default_load_format($default_output_format, 0);
  264. }
  265. #+++###########################################################################
  266. # #
  267. # Initialization #
  268. # Some declarations, some functions that are GPL and therefore cannot be in #
  269. # texi2html.pm, some functions that are not to be customized. #
  270. # Pasted content of File $(srcdir)/texi2html.pm: Default initializations #
  271. # #
  272. #---###########################################################################
  273. {
  274. package Texi2HTML::Config;
  275. use Config;
  276. # customization options variables
  277. use vars qw(
  278. @EXPAND
  279. @INCLUDE_DIRS
  280. @PREPEND_DIRS
  281. @CONF_DIRS
  282. @CSS_FILES
  283. @CSS_REFS
  284. $DEFAULT_OUTPUT_FORMAT
  285. $OUTPUT_FORMAT
  286. $COMMAND_NAME
  287. @COMMANDS
  288. );
  289. # customization variables
  290. use vars qw(
  291. $CAPTION_STYLE
  292. $MENU_PRE_STYLE
  293. $MENU_PRE_COMPLEX_FORMAT
  294. $EXAMPLE_INDENT_CELL
  295. $SMALL_EXAMPLE_INDENT_CELL
  296. $SMALL_FONT_SIZE
  297. $SMALL_RULE
  298. $DEFAULT_RULE
  299. $MIDDLE_RULE
  300. $BIG_RULE
  301. $TOP_HEADING
  302. $INDEX_CHAPTER
  303. $AFTER_BODY_OPEN
  304. $PRE_BODY_CLOSE
  305. $EXTRA_HEAD
  306. $UNNUMBERED_SYMBOL_IN_MENU
  307. $MENU_SYMBOL
  308. $MENU_ENTRY_COLON
  309. $INDEX_ENTRY_COLON
  310. $NO_NUMBER_FOOTNOTE_SYMBOL
  311. $NO_BULLET_LIST_STYLE
  312. $NO_BULLET_LIST_ATTRIBUTE
  313. $NO_BULLET_LIST_CLASS
  314. $STDIN_DOCU_NAME
  315. $STDOUT_DOCU_NAME
  316. $BEFORE_OVERVIEW
  317. $AFTER_OVERVIEW
  318. $BEFORE_TOC_LINES
  319. $AFTER_TOC_LINES
  320. %ACTIVE_ICONS
  321. %NAVIGATION_TEXT
  322. %PASSIVE_ICONS
  323. %BUTTONS_NAME
  324. %BUTTONS_GOTO
  325. %BUTTONS_EXAMPLE
  326. %BUTTONS_ACCESSKEY
  327. %BUTTONS_REL
  328. %BUTTONS_TEXT
  329. @T2H_FORMAT_EXPAND
  330. @CHAPTER_BUTTONS
  331. @MISC_BUTTONS
  332. @SECTION_BUTTONS
  333. @SECTION_FOOTER_BUTTONS
  334. @NODE_FOOTER_BUTTONS
  335. @TOP_BUTTONS
  336. @LINKS_BUTTONS
  337. @IMAGE_EXTENSIONS
  338. @INPUT_FILE_SUFFIXES
  339. @TEXI2DVI_ARGUMENTS
  340. );
  341. # I18n
  342. use vars qw(
  343. $I
  344. $LANGUAGES
  345. );
  346. # customizable subroutines references
  347. use vars qw(
  348. $print_section
  349. $one_section
  350. $end_section
  351. $print_Top_header
  352. $print_Top_footer
  353. $print_Top
  354. $print_Toc
  355. $print_Overview
  356. $print_Footnotes
  357. $print_About
  358. $print_misc_header
  359. $print_misc_footer
  360. $print_misc
  361. $print_section_header
  362. $print_section_footer
  363. $print_chapter_header
  364. $print_chapter_footer
  365. $print_element_header
  366. $print_page_head
  367. $print_page_foot
  368. $print_head_navigation
  369. $print_foot_navigation
  370. $print_title
  371. $button_icon_img
  372. $button_formatting
  373. $print_navigation
  374. $about_body
  375. $print_frame
  376. $print_toc_frame
  377. $toc_body
  378. $contents
  379. $internal_links
  380. $shortcontents
  381. $titlepage
  382. $insertcopying
  383. $css_lines
  384. $print_redirection_page
  385. $translate_names
  386. $init_out
  387. $finish_out
  388. $node_file_name
  389. $element_file_name
  390. $node_target_name
  391. $element_target_name
  392. $placed_target_file_name
  393. $inline_contents
  394. $program_string
  395. $preserve_misc_command
  396. $misc_command_line
  397. $misc_command_line_texi
  398. $protect_text
  399. $anchor
  400. $anchor_label
  401. $element_label
  402. $misc_element_label
  403. $def_item
  404. $def
  405. $menu
  406. $menu_command
  407. $menu_link
  408. $menu_description
  409. $menu_comment
  410. $simple_menu_link
  411. $ref_beginning
  412. $info_ref
  413. $book_ref
  414. $external_href
  415. $external_ref
  416. $internal_ref
  417. $table_item
  418. $table_line
  419. $row
  420. $cell
  421. $list_item
  422. $comment
  423. $def_line
  424. $def_line_no_texi
  425. $heading_no_texi
  426. $raw
  427. $raw_no_texi
  428. $heading
  429. $element_heading
  430. $heading_text
  431. $heading_text_preformatted
  432. $paragraph
  433. $preformatted
  434. $empty_preformatted
  435. $foot_line_and_ref
  436. $foot_section
  437. $image
  438. $image_files
  439. $index_entry_label
  440. $index_entry
  441. $index_entry_command
  442. $index_letter
  443. $print_index
  444. $printindex
  445. $index_summary
  446. $summary_letter
  447. $complex_format
  448. $cartouche
  449. $sp
  450. $definition_category
  451. $definition_index_entry
  452. $table_list
  453. $copying_comment
  454. $documentdescription
  455. $index_summary_file_entry
  456. $index_summary_file_end
  457. $index_summary_file_begin
  458. $style
  459. $line_command
  460. $format
  461. $normal_text
  462. $empty_line
  463. $unknown
  464. $unknown_style
  465. $float
  466. $caption_shortcaption
  467. $caption_shortcaption_command
  468. $listoffloats
  469. $listoffloats_entry
  470. $listoffloats_caption
  471. $listoffloats_float_style
  472. $listoffloats_style
  473. $acronym_like
  474. $quotation
  475. $quotation_prepend_text
  476. $paragraph_style_command
  477. $heading_texi
  478. $index_element_heading_texi
  479. $format_list_item_texi
  480. $begin_format_texi
  481. $begin_style_texi
  482. $begin_paragraph_texi
  483. $tab_item_texi
  484. $footnote_texi
  485. $colon_command
  486. $simple_command
  487. $thing_command
  488. $begin_special_region
  489. $end_special_region
  490. $PRE_ABOUT
  491. $AFTER_ABOUT
  492. );
  493. # hash which entries might be redefined by the user
  494. use vars qw(
  495. $complex_format_map
  496. %complex_format_map
  497. %accent_map
  498. %def_map
  499. %format_map
  500. %simple_map
  501. %simple_map_pre
  502. %simple_map_texi
  503. %simple_map_math
  504. %style_map
  505. %style_map_pre
  506. %style_map_math
  507. %style_map_texi
  508. %simple_format_simple_map_texi
  509. %simple_format_style_map_texi
  510. %simple_format_texi_map
  511. %line_command_map
  512. %command_type
  513. %paragraph_style
  514. %stop_paragraph_command
  515. %format_code_style
  516. %region_formats_kept
  517. %texi_formats_map
  518. %things_map
  519. %pre_map
  520. %math_map
  521. %texi_map
  522. %sorting_things_map
  523. %unicode_map
  524. %unicode_diacritical
  525. %transliterate_map
  526. %transliterate_accent_map
  527. %no_transliterate_map
  528. %ascii_character_map
  529. %default_simple_map
  530. %default_things_map
  531. %default_texi_map
  532. %default_style_map
  533. %default_style_map_pre
  534. %default_style_map_texi
  535. %default_simple_format_style_map_texi
  536. %numeric_entity_map
  537. %perl_charset_to_html
  538. %misc_pages_targets
  539. %misc_command
  540. %no_paragraph_commands
  541. %css_map
  542. %format_in_paragraph
  543. %special_list_commands
  544. %accent_letters
  545. %unicode_accents
  546. %special_accents
  547. %inter_item_commands
  548. $def_always_delimiters
  549. $def_in_type_delimiters
  550. $def_argument_separator_delimiters
  551. $warn_var_character_quoted
  552. %colon_command_punctuation_characters
  553. $punctuation_characters
  554. $after_punctuation_characters
  555. @command_handler_setup
  556. @command_handler_init
  557. @command_handler_names
  558. @command_handler_process
  559. @command_handler_output
  560. @command_handler_finish
  561. %command_handler
  562. %special_style
  563. %null_device_file
  564. %language_codes
  565. %region_codes
  566. %deprecated_commands
  567. %output_format_names
  568. %canonical_texinfo_encodings
  569. @text_substitutions_normal
  570. @text_substitutions_texi
  571. @text_substitutions_simple_format
  572. @text_substitutions_pre
  573. %htmlxref_entries
  574. %renamed_nodes
  575. %texi2dvi_formats
  576. );
  577. # deprecated
  578. use vars qw(
  579. $address
  580. %iso_symbols
  581. %simple_map_pre_math
  582. %simple_map_texi_math
  583. );
  584. # subject to change
  585. use vars qw(
  586. %makeinfo_encoding_to_map
  587. %makeinfo_unicode_to_eight_bit
  588. %eight_bit_to_unicode
  589. %t2h_encoding_aliases
  590. );
  591. # FIXME i18n ?
  592. %output_format_names = (
  593. 'info' => 'Info',
  594. 'html' => 'HTML',
  595. 'docbook' => 'Docbook XML',
  596. 'xml' => 'Texinfo XML',
  597. 'plaintext' => 'plain text',
  598. 'raw-text' => 'raw text',
  599. 'dvi' => 'DVI',
  600. 'pdf' => 'Pdf',
  601. 'ps' => 'Postscript'
  602. );
  603. sub load($)
  604. {
  605. my $file = shift;
  606. # If required like other init files, the functions would be redefined
  607. # and the format dependent stuff wouldn't be loaded. Having the
  608. # formats loaded could be worked around, for example there could be
  609. # a variable that, and if the variable is defined a function reference
  610. # should be called right after the require. There is no real
  611. # workaround for having the function redefined, though.
  612. foreach my $output_format (keys(%output_format_names))
  613. {
  614. if ($file =~ /\/$output_format\.pm$/)
  615. {
  616. t2h_default_load_format($output_format, 1);
  617. return 1;
  618. }
  619. }
  620. eval { require($file) ;};
  621. if ($@ ne '')
  622. {
  623. print STDERR "error loading $file: $@\n";
  624. return 0;
  625. }
  626. return 1;
  627. }
  628. # var: variable name
  629. # value: value to set. May be undef.
  630. # level: priority level. If undef, it means reusing the current level
  631. # not_global: if set the change should only concern the current document
  632. sub set_variable($$$;$)
  633. {
  634. my $var = shift;
  635. my $value = shift;
  636. my $level = shift;
  637. my $not_global = shift;
  638. $not_global = 0 if (!$not_global);
  639. my $ref_level = $Texi2HTML::GLOBAL{'variable_levels'}->{$var};
  640. if (!defined($ref_level))
  641. {
  642. # issue with Locale::Messages::dpgettext not already defined
  643. #main::msg_warn(sprintf('Unknown variable %s', $var));
  644. warn (sprintf('Unknown variable %s', $var));
  645. return 0;
  646. }
  647. #print STDERR "$var(".(main::var_to_str($level))."): ".main::var_to_str($value)." not_global $not_global\n";
  648. if (!defined($level) or $level <= $ref_level)
  649. {
  650. $Texi2HTML::THISDOC{'variable_levels'}->{$var} = $level if (defined($level));
  651. if ($not_global)
  652. {
  653. $Texi2HTML::THISDOC{'variables'}->{$var} = $value;
  654. }
  655. else
  656. {
  657. $Texi2HTML::GLOBAL{'variables'}->{$var} = $value;
  658. $Texi2HTML::GLOBAL{'variable_levels'}->{$var} = $level if (defined($level));
  659. }
  660. return 1;
  661. }
  662. return 0;
  663. }
  664. # var: variable name
  665. # level: priority level. If undef, it means reusing the current level
  666. # not_global: only for the current document
  667. sub unset_variable($$;$)
  668. {
  669. my $var = shift;
  670. my $level = shift;
  671. my $not_global = shift;
  672. $not_global = 0 if (!$not_global);
  673. my $ref_level = $Texi2HTML::GLOBAL{'variable_levels'}->{$var};
  674. if (!defined($ref_level))
  675. {
  676. # issue with Locale::Messages::dpgettext not already defined
  677. #main::msg_warn(sprintf('Unknown variable %s', $var));
  678. warn (sprintf('Unknown variable %s', $var));
  679. return 0;
  680. }
  681. #print STDERR "$var(".(main::var_to_str($level))."): ".main::var_to_str($value)." not_global $not_global\n";
  682. if (!defined($level) or $level <= $ref_level)
  683. {
  684. $Texi2HTML::THISDOC{'variable_levels'}->{$var} = $level if (defined($level));
  685. if ($not_global)
  686. {
  687. delete($Texi2HTML::THISDOC{'variables'}->{$var});
  688. }
  689. else
  690. {
  691. delete($Texi2HTML::GLOBAL{'variables'}->{$var});
  692. $Texi2HTML::GLOBAL{'variable_levels'}->{$var} = $level if (defined($level));
  693. }
  694. return 1;
  695. }
  696. return 0;
  697. }
  698. sub set_from_init_file ($$)
  699. {
  700. my $var = shift;
  701. my $value = shift;
  702. my $level = 3;
  703. return set_variable($var, $value, $level);
  704. }
  705. sub set_default ($$)
  706. {
  707. my $var = shift;
  708. my $value = shift;
  709. my $level = 7;
  710. return set_variable($var, $value, $level);
  711. }
  712. sub set_from_document($$)
  713. {
  714. my $var = shift;
  715. my $value = shift;
  716. my $level = 5;
  717. return set_variable($var, $value, $level, 1);
  718. }
  719. sub get_conf($)
  720. {
  721. my $name = shift;
  722. if (defined($Texi2HTML::GLOBAL{'variable_levels'}->{$name}))
  723. { # notice the exists, and not defined. Such that undef is a
  724. # value like any other possible value.
  725. if (exists($Texi2HTML::THISDOC{'variables'}->{$name}))
  726. {
  727. return $Texi2HTML::THISDOC{'variables'}->{$name};
  728. }
  729. else
  730. { # may be undef
  731. return $Texi2HTML::GLOBAL{'variables'}->{$name};
  732. }
  733. }
  734. else
  735. { # no i18n since it may not be set up already (?)
  736. warn (sprintf('get_conf: Unknown variable %s', $name));
  737. return undef;
  738. }
  739. }
  740. # manage expanded sections
  741. sub set_expansion($$)
  742. {
  743. my $region = shift;
  744. my $set = shift;
  745. $set = 1 if (!defined($set));
  746. if ($set)
  747. {
  748. push (@EXPAND, $region) unless (grep {$_ eq $region} @EXPAND);
  749. }
  750. else
  751. {
  752. @EXPAND = grep {$_ ne $region} @EXPAND;
  753. @T2H_FORMAT_EXPAND = grep {$_ ne $region} @T2H_FORMAT_EXPAND;
  754. }
  755. }
  756. # needed in this namespace for translations
  757. $I = \&Texi2HTML::I18n::get_string;
  758. sub gdt($;$$)
  759. {
  760. return &main::gdt(@_);
  761. }
  762. sub __($)
  763. {
  764. return &main::__(@_);
  765. }
  766. sub __p($$)
  767. {
  768. return &main::__p(@_);
  769. }
  770. sub N__($)
  771. {
  772. return $_[0];
  773. }
  774. #
  775. # Function refs covered by the GPL as part of the texi2html.pl original
  776. # code. As such they cannot appear in texi2html.pm which is public
  777. # domain (at least the things coded by me, and, if I'm not wrong also the
  778. # things coded by Olaf -- Pat).
  779. #
  780. sub HTML_DEFAULT_shortcontents($$)
  781. {
  782. my $elements_list = shift;
  783. my $stoc_file = shift;
  784. return unless (get_conf('shortcontents') or get_conf('FRAMES'));
  785. my $ul_class = '';
  786. $ul_class = $NO_BULLET_LIST_CLASS if (get_conf('NUMBER_SECTIONS'));
  787. my @result = ();
  788. foreach my $element (@$elements_list)
  789. {
  790. next if ($element->{'tag'} eq 'top' or $element->{'toc_level'} != 1);
  791. my $dest_for_stoc = $element->{'file'};
  792. my $dest_target_for_stoc = $element->{'target'};
  793. if (get_conf('OVERVIEW_LINK_TO_TOC'))
  794. {
  795. $dest_for_stoc = $Texi2HTML::THISDOC{'toc_file'};
  796. $dest_target_for_stoc = $element->{'tocid'};
  797. }
  798. $dest_for_stoc = '' if ($dest_for_stoc eq $stoc_file);
  799. my $text = $element->{'text'};
  800. my $stoc_entry = "<li>" . &$anchor ($element->{'stocid'}, "$dest_for_stoc#$dest_target_for_stoc",$text);
  801. push(@result, $stoc_entry. "</li>\n");
  802. }
  803. if (@result)
  804. {
  805. unshift @result, html_default_attribute_class('ul', $ul_class) .">\n";
  806. push @result, "</ul>\n";
  807. unshift @result, $BEFORE_OVERVIEW;
  808. push @result, $AFTER_OVERVIEW;
  809. }
  810. return \@result;
  811. }
  812. sub HTML_DEFAULT_contents($$)
  813. {
  814. my $elements_list = shift;
  815. my $toc_file = shift;
  816. return unless (get_conf('contents'));
  817. my $current_level = 0;
  818. my $ul_class = '';
  819. $ul_class = $NO_BULLET_LIST_CLASS if (get_conf('NUMBER_SECTIONS'));
  820. my @result = ();
  821. foreach my $element (@$elements_list)
  822. {
  823. next if ($element->{'tag'} eq 'top');
  824. my $ind = ' ' x $current_level;
  825. my $level = $element->{'toc_level'};
  826. print STDERR "Bug no toc_level for ($element) $element->{'texi'}\n" if (!defined ($level));
  827. if ($level > $current_level)
  828. {
  829. while ($level > $current_level)
  830. {
  831. $current_level++;
  832. my $ln = "\n$ind".html_default_attribute_class('ul', $ul_class).">\n";
  833. $ind = ' ' x $current_level;
  834. push(@result, $ln);
  835. }
  836. }
  837. elsif ($level < $current_level)
  838. {
  839. while ($level < $current_level)
  840. {
  841. $current_level--;
  842. $ind = ' ' x $current_level;
  843. my $line = "</li>\n$ind</ul>";
  844. $line .= "</li>" if ($level == $current_level);
  845. push(@result, "$line\n");
  846. }
  847. }
  848. else
  849. {
  850. push(@result, "</li>\n");
  851. }
  852. my $dest_for_toc = $element->{'file'};
  853. my $dest_for_stoc = $element->{'file'};
  854. my $dest_target_for_stoc = $element->{'target'};
  855. $dest_for_toc = '' if ($dest_for_toc eq $toc_file);
  856. my $text = $element->{'text'};
  857. my $toc_entry = "<li>" . &$anchor ($element->{'tocid'}, "$dest_for_toc#$element->{'target'}",$text);
  858. push (@result, $ind . $toc_entry);
  859. }
  860. while (0 < $current_level)
  861. {
  862. $current_level--;
  863. my $ind = ' ' x $current_level;
  864. push(@result, "</li>\n$ind</ul>\n");
  865. }
  866. if (@result)
  867. {
  868. unshift @result, $BEFORE_TOC_LINES;
  869. push @result, $AFTER_TOC_LINES;
  870. }
  871. return \@result;
  872. }
  873. #$toc_body = \&T2H_GPL_toc_body;
  874. #$style = \&T2H_GPL_style;
  875. #$format = \&T2H_GPL_format;
  876. #$printindex = \&t2h_GPL_default_printindex;
  877. #$summary_letter = \&t2h_default_summary_letter;
  878. sub T2H_GPL_style($$$$$$$$$$)
  879. { # known style
  880. my $style = shift;
  881. my $command = shift;
  882. my $text = shift;
  883. my $args = shift;
  884. my $no_close = shift;
  885. my $no_open = shift;
  886. my $line_nr = shift;
  887. my $state = shift;
  888. my $style_stack = shift;
  889. my $kept_line_nrs = shift;
  890. my $do_quotes = 0;
  891. my $use_attribute = 0;
  892. my $use_begin_end = 0;
  893. my $inline_attribute = 0;
  894. if (ref($style) eq 'HASH')
  895. {
  896. #print STDERR "GPL_STYLE $command ($style)\n";
  897. #print STDERR " @$args\n";
  898. if (ref($style->{'args'}) ne 'ARRAY')
  899. {
  900. print STDERR "BUG: args not an array for command `$command'\n";
  901. }
  902. $do_quotes = $style->{'quote'};
  903. if (defined($style->{'function'}))
  904. {
  905. $text = &{$style->{'function'}}($command, $args, $style_stack, $state, $line_nr, $kept_line_nrs);
  906. }
  907. elsif (@{$style->{'args'}} == 1)
  908. {
  909. if (defined($style->{'inline_attribute'}))
  910. {
  911. $style = $style->{'inline_attribute'};
  912. $use_attribute = 1;
  913. $inline_attribute = 1;
  914. }
  915. elsif (defined($style->{'attribute'}))
  916. {
  917. $style = $style->{'attribute'};
  918. $use_attribute = 1;
  919. }
  920. #$text = $args->[0];
  921. }
  922. }
  923. else
  924. {
  925. if ($style =~ s/^\"//)
  926. { # add quotes
  927. $do_quotes = 1;
  928. }
  929. if ($style =~ s/^\&//)
  930. { # custom
  931. $style = 'Texi2HTML::Config::' . $style;
  932. eval "\$text = &$style(\$text, \$command, \$style_stack)";
  933. }
  934. elsif ($style ne '')
  935. {
  936. $use_attribute = 1;
  937. }
  938. else
  939. { # no style
  940. }
  941. }
  942. if ($use_attribute)
  943. {
  944. my ($attribute_text, $class);
  945. ($style, $class, $attribute_text) = html_default_parse_attribute ($style);
  946. $text = html_default_attribute_class($style, $class) . "$attribute_text>" . "$text" if (!$no_open or $inline_attribute);
  947. $text .= "</$style>" if (!$no_close or $inline_attribute);
  948. if ($do_quotes)
  949. {
  950. $text = get_conf('OPEN_QUOTE_SYMBOL') . "$text" if (!$no_open);
  951. $text .= get_conf('CLOSE_QUOTE_SYMBOL') if (!$no_close);
  952. }
  953. }
  954. if (ref($style) eq 'HASH')
  955. {
  956. if (defined($style->{'begin'}) and !$no_open)
  957. {
  958. $text = $style->{'begin'} . $text;
  959. }
  960. if (defined($style->{'end'}) and !$no_close)
  961. {
  962. $text = $text . $style->{'end'};
  963. }
  964. if (defined($style->{'inline_begin'}))
  965. {
  966. $text = $style->{'inline_begin'} . $text;
  967. }
  968. if (defined($style->{'inline_end'}))
  969. {
  970. $text = $text . $style->{'inline_end'};
  971. }
  972. }
  973. if ($do_quotes and !$use_attribute)
  974. {
  975. $text = get_conf('OPEN_QUOTE_SYMBOL') . "$text" if (!$no_open);
  976. $text .= get_conf('CLOSE_QUOTE_SYMBOL') if (!$no_close);
  977. }
  978. return $text;
  979. }
  980. sub T2H_GPL_format($$$)
  981. {
  982. my $tag = shift;
  983. my $element = shift;
  984. my $text = shift;
  985. return '' if (!defined($element) or ($text !~ /\S/));
  986. return $text if ($element eq '');
  987. my $attribute_text = '';
  988. if ($element =~ /^(\w+)(\s+.*)/)
  989. {
  990. $element = $1;
  991. $attribute_text = $2;
  992. }
  993. return "<${element}$attribute_text>\n" . $text. "</$element>\n";
  994. }
  995. # for each index holds the letters split as determined by SPLIT_INDEX.
  996. my %t2h_default_index_letters_array;
  997. # equivalent of doc_nr, but with files (and hence numbers) added when
  998. # a split index leads to an additional element and a file is created.
  999. my $t2h_default_file_number;
  1000. # this is an increasing number to construct the id for each newly
  1001. # created index element.
  1002. my $t2h_default_index_id_nr;
  1003. # this holds the file name associated with an element file, such
  1004. # as to follow the splitting coming from the main program, and also use
  1005. # the newly generated files.
  1006. my %t2h_default_seen_files;
  1007. # holds the elements and indices that are split to easily set the
  1008. # directions after they are done in the main program.
  1009. my $t2h_default_element_split_printindices;
  1010. # construct a hash of index names holding the letter grouped how they will
  1011. # be split.
  1012. sub t2h_default_init_split_indices()
  1013. {
  1014. push @command_handler_process, \&t2h_default_index_rearrange_directions;
  1015. %t2h_default_index_letters_array = ();
  1016. %t2h_default_seen_files = ();
  1017. $t2h_default_element_split_printindices = undef;
  1018. $t2h_default_index_id_nr = 0;
  1019. $t2h_default_file_number = 0;
  1020. foreach my $index_name(keys %{$Texi2HTML::THISDOC{'index_letters_array'}})
  1021. {
  1022. my $entries_count = 0;
  1023. my @letters = ();
  1024. foreach my $letter_entry (@{$Texi2HTML::THISDOC{'index_letters_array'}->{$index_name}})
  1025. {
  1026. push @letters, $letter_entry;
  1027. $entries_count += scalar(@{$letter_entry->{'entries'}});
  1028. # Don't split if document is not split
  1029. if (get_conf('SPLIT') and get_conf('SPLIT_INDEX') and $entries_count >= get_conf('SPLIT_INDEX'))
  1030. {
  1031. push @{$t2h_default_index_letters_array{$index_name}}, [ @letters ];
  1032. @letters = ();
  1033. $entries_count = 0;
  1034. }
  1035. }
  1036. push @{$t2h_default_index_letters_array{$index_name}}, [ @letters ] if (scalar(@letters));
  1037. }
  1038. }
  1039. sub t2h_default_associate_index_element($$$$)
  1040. {
  1041. my $element = shift;
  1042. my $is_top = shift;
  1043. my $docu_name = shift;
  1044. my $use_node_file = shift;
  1045. my $default_element_file = $element->{'file'};
  1046. # redo the file naming -- the doc_nr part -- in case new elements were
  1047. # inserted upon index split. But respect the default splitting to keep
  1048. # the elements that are associated with the same file in the same file,
  1049. # or the added file.
  1050. if (!$use_node_file or $t2h_default_seen_files{$default_element_file})
  1051. {
  1052. my $file;
  1053. if ($t2h_default_seen_files{$default_element_file})
  1054. {
  1055. $file = $t2h_default_seen_files{$default_element_file};
  1056. }
  1057. else
  1058. {
  1059. if ($is_top eq 'top')
  1060. { # this is the element_top, so we keep docu_top as associated file.
  1061. # this, in fact, is not necessary since the element_top is never
  1062. # associated with another element, but who knows.
  1063. $t2h_default_seen_files{$default_element_file} = $default_element_file;
  1064. }
  1065. else
  1066. {
  1067. $file = "${docu_name}_$t2h_default_file_number";
  1068. $file .= '.' . get_conf('EXTENSION') if
  1069. (defined(get_conf('EXTENSION')));
  1070. $t2h_default_seen_files{$default_element_file} = $file;
  1071. }
  1072. $t2h_default_file_number++;
  1073. }
  1074. $element->{'file'} = $file if (defined($file));
  1075. }
  1076. my $level = $element->{'level'};
  1077. # Even if, without USE_SECTION, output can be split at chapter or
  1078. # section we don't split indices accordingly. We don't want to add
  1079. # more cases where users want split indices, this was a very difficult
  1080. # to maintain feature from the beginning.
  1081. #$level = $element->{'with_section'}->{'level'} if (!defined($level) and
  1082. # defined($element->{'with_section'}));
  1083. # if the element is not the level of splitting, then we don't split.
  1084. # also if 'top' is set we don't split since the formatting is different
  1085. # in that case and the result would be quite unpredictable.
  1086. return if ($element->{'top'} or ((get_conf('SPLIT') ne 'node')
  1087. and (!defined($level) or $level > $Texi2HTML::THISDOC{'split_level'})));
  1088. #print STDERR "Doing printindices for $element $element->{'texi'}, file $element->{'file'} (@{$element->{'place'}})\n";
  1089. # iterate over the @places of the element, which includes associated nodes,
  1090. # associated elements, anchors, footnotes, floats, index entries,
  1091. # printindices (including the element command itself, be it a @node or
  1092. # a sectioning @-command).
  1093. # during the iteration, split printindices that needs it, and reassociate
  1094. # other placed elements with files and elements.
  1095. my $current_element = $element;
  1096. my @places = @{$element->{'place'}};
  1097. @{$element->{'place'}} = ();
  1098. foreach my $place (@places)
  1099. {
  1100. my ($printindex, $printindex_to_split, $index_name);
  1101. # determines if the placed thing is a printindex to be split
  1102. if ($place->{'command'} and $place->{'command'} eq 'printindex')
  1103. {
  1104. $printindex = $place;
  1105. $index_name = $printindex->{'name'};
  1106. # ! empty index
  1107. if (exists($t2h_default_index_letters_array{$index_name}) and
  1108. # split index
  1109. scalar(@{$t2h_default_index_letters_array{$index_name}} > 1)
  1110. # the condition defined($printindex->{'associated_element'} implies
  1111. # that we don't split printindex before first element, otherwise
  1112. # there will be a need to begin document without a first element
  1113. # which would be annoying.
  1114. and defined($printindex->{'associated_element'}))
  1115. {
  1116. $printindex_to_split = 1;
  1117. }
  1118. }
  1119. # this is a non split printindex or any other placed thing.
  1120. if (!$printindex_to_split)
  1121. {
  1122. push @{$current_element->{'place'}}, $place;
  1123. # don't remodify the original element file, it was set right at the
  1124. # beginning of the function.
  1125. $place->{'file'} = $current_element->{'file'} if ($place ne $element);
  1126. # the 'element_ref' has to be reset. Otherwise, $place->{'element_ref'}
  1127. # will appear as a new element and trigger closing the file and
  1128. # opening a new one.
  1129. $place->{'element_ref'} = $current_element if ($place->{'element_ref'} and $current_element ne $element);
  1130. # this resets the element associated with a printindex.
  1131. if ($place->{'associated_element'} and $current_element ne $element)
  1132. {
  1133. $place->{'associated_element'} = $current_element;
  1134. }
  1135. next;
  1136. }
  1137. # now split the index
  1138. my @letter_groups = ();
  1139. my @letters_split = @{$t2h_default_index_letters_array{$index_name}};
  1140. foreach my $letters_split (@letters_split)
  1141. {
  1142. push @letter_groups, {'letters' => [@$letters_split]};
  1143. }
  1144. $letter_groups[0]->{'element'} = $current_element;
  1145. # besides preparing the new elements corresponding with split indices,
  1146. # they are recorded for later directions rearrangements in
  1147. # t2h_default_index_rearrange_directions.
  1148. # this weird construct is there because the element used as a key is
  1149. # converted to a string by perl, losing its meaning as a reference,
  1150. # the reference must be recorded explicitly
  1151. $t2h_default_element_split_printindices->{$element}->{'element'} = $element;
  1152. push @{$t2h_default_element_split_printindices->{$element}->{'printindices'}}, $printindex;
  1153. #print STDERR "Setting $element, $element->{'texi'}, $printindex $printindex->{'name'} as a split element\n";
  1154. foreach my $split_group (@letter_groups)
  1155. {
  1156. my $first_letter = $split_group->{'letters'}->[0]->{'letter'};
  1157. my $last_letter = $split_group->{'letters'}->[-1]->{'letter'};
  1158. if (!$split_group->{'element'})
  1159. { # this is not the first letters group, which is already associated
  1160. # with an element, a new element is done.
  1161. # construct new element name
  1162. my $letters_heading;
  1163. if ($last_letter ne $first_letter)
  1164. {
  1165. $letters_heading = &$normal_text("$first_letter -- $last_letter");
  1166. }
  1167. else
  1168. {
  1169. $letters_heading = &$normal_text("$first_letter");
  1170. }
  1171. my ($name, $simple);
  1172. my $texi = "ADDED ELEMENT $element->{'texi'}: $letters_heading";
  1173. if (!defined($element->{'text'}))
  1174. {
  1175. my $element_heading_texi = &$heading_texi($element->{'tag'}, $element->{'texi'}, $element->{'number'});
  1176. my $index_heading_texi = &$index_element_heading_texi(
  1177. $element_heading_texi,
  1178. $element->{'tag'},
  1179. $element->{'texi'},
  1180. $element->{'number'},
  1181. $first_letter, $last_letter);
  1182. $name = main::substitute_line($index_heading_texi, sprintf(__p("\@sectioning_command index page","\@%s index page"), $element->{'tag'}));
  1183. $simple = main::simple_format(undef,undef,"simple_format \@$element->{'tag'} index page", $index_heading_texi);
  1184. }
  1185. else
  1186. { # should never happen, at this point 'text' is always undefined.
  1187. $name = "$element->{'text'}: $letters_heading";
  1188. $simple = "$element->{'simple_format'}: $letters_heading";
  1189. }
  1190. #file and id
  1191. my $relative_file = $Texi2HTML::THISDOC{'file_base_name'} . '_' . $t2h_default_file_number;
  1192. $t2h_default_file_number++;
  1193. $relative_file .= '.' . get_conf('EXTENSION') if
  1194. (defined(get_conf('EXTENSION')));
  1195. my $id = "index_split-$t2h_default_index_id_nr";
  1196. $t2h_default_index_id_nr++;
  1197. my $new_element = { 'file' => $relative_file, 'id' => $id, 'target' => $id, 'text' => $name, 'texi' => $texi, 'seen' => 1, 'simple_format' => $simple };
  1198. # to avoid crashing when there is a filename collision.
  1199. main::add_file($new_element->{'file'});
  1200. $split_group->{'element'} = $new_element;
  1201. $current_element = $new_element;
  1202. #print STDERR "Added file $new_element->{'file'} ($new_element, $new_element->{'id'}) for $new_element->{'texi'} ($first_letter:$last_letter)\n";
  1203. }
  1204. else
  1205. { # this is the first index split, it is still associated with the element
  1206. #print STDERR "No file added for ($first_letter:$last_letter)\n";
  1207. }
  1208. }
  1209. $t2h_default_seen_files{$default_element_file} = $current_element->{'file'};
  1210. $printindex->{'split_groups'} = \@letter_groups;
  1211. #print STDERR "$index_name processed for $element, $element->{'texi'} (@{$printindex->{'split_groups'}})\n";
  1212. }
  1213. }
  1214. # set directions for added elements now that they are done in the
  1215. # main program for all the other elements.
  1216. sub t2h_default_index_rearrange_directions()
  1217. {
  1218. return if (!defined($t2h_default_element_split_printindices));
  1219. foreach my $element_string (keys(%$t2h_default_element_split_printindices))
  1220. {
  1221. my $element = $t2h_default_element_split_printindices->{$element_string}->{'element'};
  1222. my $current_element = $element;
  1223. #print STDERR " E Processing $element_string,$current_element $current_element->{'texi'}\n";
  1224. foreach my $printindex (@{$t2h_default_element_split_printindices->{$element_string}->{'printindices'}})
  1225. {
  1226. #print STDERR " I Processing $printindex $printindex->{'name'} (@{$printindex->{'split_groups'}})\n";
  1227. foreach my $split_group (@{$printindex->{'split_groups'}})
  1228. {
  1229. my $first_letter = $split_group->{'letters'}->[0]->{'letter'};
  1230. my $last_letter = $split_group->{'letters'}->[-1]->{'letter'};
  1231. my $new_element = $split_group->{'element'};
  1232. next if ($current_element eq $new_element);
  1233. #print STDERR " G Processing ($first_letter:$last_letter) in $element->{'texi'}, index $printindex->{'name'}: $new_element->{'texi'}\n";
  1234. $new_element->{'This'} = $new_element;
  1235. if ($current_element->{'Forward'})
  1236. {
  1237. $current_element->{'Forward'}->{'Back'} = $new_element;
  1238. $new_element->{'Forward'} = $current_element->{'Forward'};
  1239. }
  1240. $current_element->{'Forward'} = $new_element;
  1241. $new_element->{'Back'} = $current_element;
  1242. if ($current_element->{'NodeForward'})
  1243. {
  1244. #print STDERR "F: C($current_element): $current_element->{'texi'}, N($new_element): $new_element->{'texi'} -- C->F: $current_element->{'NodeForward'}->{'texi'}\n";
  1245. $new_element->{'NodeForward'} = $current_element->{'NodeForward'};
  1246. $current_element->{'NodeForward'} = $new_element;
  1247. $new_element->{'NodeBack'} = $current_element;
  1248. }
  1249. foreach my $key ('FastForward', 'FastBack', 'Up', 'tag_level', 'tag',
  1250. 'level', 'node')
  1251. {
  1252. $new_element->{$key} = $element->{$key} if (defined($element->{$key}));
  1253. }
  1254. $new_element->{'this'} = $new_element;
  1255. $new_element->{'element_ref'} = $new_element;
  1256. $current_element = $new_element;
  1257. }
  1258. }
  1259. }
  1260. }
  1261. # not needed to initialize it for a document, since it is reset
  1262. # in index_summary
  1263. my $t2h_symbol_indices = 0;
  1264. # format a letter appearing in a summary for an index. The letter links to
  1265. # the place where the index elements beginning with this letter are (called
  1266. # a letter entry).
  1267. #
  1268. # arguments:
  1269. # letter
  1270. # file where the target letter entry is
  1271. # identifier for the target letter entry
  1272. sub html_default_summary_letter($$$$$$$)
  1273. {
  1274. my $letter = shift;
  1275. my $file = shift;
  1276. my $default_identifier = shift;
  1277. my $index_element_id = shift;
  1278. my $number = shift;
  1279. my $index_element = shift;
  1280. my $index_name = shift;
  1281. return '' if ($letter =~ /^\s*$/);
  1282. my $is_symbol = $letter !~ /^[A-Za-z]/;
  1283. my $identifier = $default_identifier;
  1284. if (get_conf('NEW_CROSSREF_STYLE'))
  1285. {
  1286. if ($is_symbol)
  1287. {
  1288. $t2h_symbol_indices++;
  1289. $identifier = $index_element_id . "_${index_name}_symbol-$t2h_symbol_indices";
  1290. }
  1291. else
  1292. {
  1293. $identifier = $index_element_id . "_${index_name}_letter-${letter}";
  1294. }
  1295. }
  1296. my $result = &$anchor('', $file . '#' . $identifier, '<b>' . &$protect_text($letter) . '</b>', 'class="summary-letter"');
  1297. return $result unless (get_conf('NEW_CROSSREF_STYLE'));
  1298. return ($result, $identifier, $is_symbol);
  1299. }
  1300. # this replaces do_index_page
  1301. # args should be:
  1302. # index_name
  1303. # printindex
  1304. sub t2h_GPL_default_printindex($$)
  1305. {
  1306. my $index_name = shift;
  1307. my $printindex = shift;
  1308. # could be cross verified with argument
  1309. my $identifier_index_nr = 0;
  1310. my @split_letters;
  1311. if (defined($printindex->{'split_groups'}) and scalar(@{$printindex->{'split_groups'}}))
  1312. {
  1313. @split_letters = @{$printindex->{'split_groups'}};
  1314. }
  1315. elsif (defined($Texi2HTML::THISDOC{'index_letters_array'}->{$index_name}) and scalar(@{$Texi2HTML::THISDOC{'index_letters_array'}->{$index_name}}))
  1316. {
  1317. my $element = $printindex->{'associated_element'};
  1318. # this happens for printindex before the first element.
  1319. if (!defined($element))
  1320. {
  1321. $element = {'file' => '', 'id' => "$printindex->{'region'}_printindex"};
  1322. }
  1323. elsif (defined($element->{'element_ref'}))
  1324. {
  1325. $element = $element->{'element_ref'};
  1326. }
  1327. @split_letters = ({ 'letters' => $Texi2HTML::THISDOC{'index_letters_array'}->{$index_name}, 'element' => $element});
  1328. }
  1329. else
  1330. {
  1331. return '';
  1332. }
  1333. foreach my $split_group (@split_letters)
  1334. {
  1335. #do summmary
  1336. my @non_alpha = ();
  1337. my @alpha = ();
  1338. #print STDERR "$index_name @{$split_group->{'letters'}}\n";
  1339. # letter_id could be done once for all instead of for each split_group
  1340. # and outside of t2h_default_summary_letter (or t2h_default_summary_letter
  1341. # could be simplified and inlined
  1342. my %letter_id;
  1343. foreach my $summary_split_group (@split_letters)
  1344. {
  1345. foreach my $letter_entry (@{$summary_split_group->{'letters'}})
  1346. {
  1347. my $letter = $letter_entry->{'letter'};
  1348. my $dest_file = '';
  1349. ####################################### debug
  1350. if (!defined($summary_split_group->{'element'}))
  1351. {
  1352. main::msg_debug ("index $index_name, letter $letter, element for summary_split_group $summary_split_group not defined");
  1353. }
  1354. elsif (!defined($summary_split_group->{'element'}->{'id'}))
  1355. {
  1356. main::msg_debug ("index $index_name, letter $letter, element $summary_split_group->{'element'} `$summary_split_group->{'element'}->{'texi'}', id undef");
  1357. }
  1358. ####################################### end debug
  1359. $dest_file = $summary_split_group->{'element'}->{'file'}
  1360. if ($summary_split_group ne $split_group);
  1361. my $index_element_id = $summary_split_group->{'element'}->{'id'};
  1362. my $default_identifier = $index_element_id . "_$identifier_index_nr";
  1363. #print STDERR "$split_group $summary_split_group $summary_split_group->{'element'} $summary_split_group->{'element'}->{'id'} $identifier_index_nr $index_element_id $default_identifier\n";
  1364. $identifier_index_nr++;
  1365. my ($result, $identifier, $is_symbol) =
  1366. &$summary_letter($letter, $dest_file, $default_identifier, $index_element_id, '', '', $index_name);
  1367. $identifier = $default_identifier if (!defined($identifier));
  1368. $letter_id{$letter} = $identifier;
  1369. $is_symbol = $letter !~ /^[A-Za-z]/ if (!defined($is_symbol));
  1370. if ($result ne '')
  1371. {
  1372. if ($is_symbol)
  1373. {
  1374. push @non_alpha, $result;
  1375. }
  1376. else
  1377. {
  1378. push @alpha, $result;
  1379. }
  1380. }
  1381. }
  1382. }
  1383. my $summary = &$index_summary(\@alpha, \@non_alpha);
  1384. # reset symbols numbering
  1385. $t2h_symbol_indices = 0;
  1386. my $letters_text = '';
  1387. foreach my $letter_entry (@{$split_group->{'letters'}})
  1388. {
  1389. my $letter = $letter_entry->{'letter'};
  1390. my $entries_text = '';
  1391. foreach my $index_entry_ref (@{$letter_entry->{'entries'}})
  1392. {
  1393. my ($text_href, $entry_file, $element_file, $entry_target,
  1394. $entry_element_target, $formatted_entry, $element_href,
  1395. $entry_element_text, $in_region_not_in_output)
  1396. = main::get_index_entry_infos($index_entry_ref, $split_group->{'element'});
  1397. $entries_text .= &$index_entry ($text_href, $formatted_entry, $element_href, $entry_element_text, $entry_file, $element_file, $entry_target, $entry_element_target, $in_region_not_in_output, $index_entry_ref);
  1398. }
  1399. $letters_text .= &$index_letter ($letter, $letter_id{$letter}, $entries_text)
  1400. }
  1401. my $index_text = &$print_index($letters_text, $index_name);
  1402. $split_group->{'text'} = $summary . $index_text . $summary;
  1403. # print STDERR " ---> $index_name @{$split_group->{'letters'}}
  1404. # * elt: $split_group->{'element'}->{'id'}, $split_group->{'element'}->{'file'}, $split_group->{'element'}->{'name'}
  1405. # * directions: B: $split_group->{'element'}->{'Back'}->{'name'}, F: $split_group->{'element'}->{'Forward'}->{'name'}, FB: $split_group->{'element'}->{'FastBack'}->{'name'}, FF: $split_group->{'element'}->{'FastForward'}->{'name'}
  1406. # * text
  1407. #
  1408. #$split_group->{'text'}
  1409. #
  1410. #";
  1411. }
  1412. my $current_page = shift @split_letters;
  1413. if (!scalar(@split_letters))
  1414. {
  1415. return $current_page->{'text'};
  1416. }
  1417. while (1)
  1418. {
  1419. # print the index letters
  1420. push @{$Texi2HTML::THIS_SECTION}, $current_page->{'text'};
  1421. $current_page = shift @split_letters;
  1422. last if (!defined($current_page));
  1423. # there is no need to begin first element if not already done, since
  1424. # the index is not split if not already in an element.
  1425. # end the previous element
  1426. main::finish_element ($Texi2HTML::THISDOC{'FH'}, $Texi2HTML::THIS_ELEMENT, $Texi2HTML::THIS_ELEMENT->{'Forward'}, 0);
  1427. # do the new element beginning
  1428. $Texi2HTML::THIS_ELEMENT = $current_page->{'element'};
  1429. my $new_element = $Texi2HTML::THIS_ELEMENT;
  1430. main::unref_file($new_element->{'file'});
  1431. main::do_element_directions($new_element);
  1432. my $do_page_head = main::open_out_file($new_element->{'file'});
  1433. if ($do_page_head)
  1434. {
  1435. &$print_page_head($Texi2HTML::THISDOC{'FH'});
  1436. &$print_chapter_header($Texi2HTML::THISDOC{'FH'}, $new_element) if get_conf('SPLIT') eq 'chapter';
  1437. &$print_section_header($Texi2HTML::THISDOC{'FH'}, $new_element) if get_conf('SPLIT') eq 'section';
  1438. }
  1439. # almost nothing of this is used in the default html output
  1440. @{$Texi2HTML::THIS_SECTION} = &$element_heading($new_element, $new_element->{'tag'}, $new_element->{'texi'},
  1441. $new_element->{'text'}, 0, 0, $new_element->{'this'}, 1, 0, 0, "\@$new_element->{'tag'} $new_element->{'texi'}",
  1442. $new_element->{'id'}, $new_element);
  1443. }
  1444. return '';
  1445. }
  1446. # leave this within comments, and keep the require statement
  1447. # This way, you can directly run texi2html.pl,
  1448. # if $T2H_HOME/documentlanguages.pl exists.
  1449. #
  1450. # @T2H_DOCUMENT_LANGUAGES@
  1451. require "$T2H_HOME/documentlanguages.pl"
  1452. if ($0 =~ /\.pl$/ &&
  1453. -e "$T2H_HOME/documentlanguages.pl" && -r "$T2H_HOME/documentlanguages.pl");
  1454. # leave this within comments, and keep the require statement
  1455. # This way, you can directly run texi2html.pl, if
  1456. # $T2H_HOME/texi2html.pm exists.
  1457. # @INIT@
  1458. require "$T2H_HOME/texi2html.pm"
  1459. if ($0 =~ /\.pl$/ &&
  1460. -e "$T2H_HOME/texi2html.pm" && -r "$T2H_HOME/texi2html.pm");
  1461. # @INIT_HTML@
  1462. require "$T2H_HOME/formats/html.pm"
  1463. if ($0 =~ /\.pl$/ &&
  1464. -e "$T2H_HOME/formats/html.pm" && -r "$T2H_HOME/formats/html.pm");
  1465. # @INIT_INFO@
  1466. require "$T2H_HOME/formats/info.pm"
  1467. if ($0 =~ /\.pl$/ &&
  1468. -e "$T2H_HOME/formats/info.pm" && -r "$T2H_HOME/formats/info.pm");
  1469. # @INIT_DOCBOOK@
  1470. require "$T2H_HOME/formats/docbook.pm"
  1471. if ($0 =~ /\.pl$/ &&
  1472. -e "$T2H_HOME/formats/docbook.pm" && -r "$T2H_HOME/formats/docbook.pm");
  1473. # @INIT_XML@
  1474. require "$T2H_HOME/formats/xml.pm"
  1475. if ($0 =~ /\.pl$/ &&
  1476. -e "$T2H_HOME/formats/xml.pm" && -r "$T2H_HOME/formats/xml.pm");
  1477. # @INIT_PLAINTEXT@
  1478. require "$T2H_HOME/formats/plaintext.pm"
  1479. if ($0 =~ /\.pl$/ &&
  1480. -e "$T2H_HOME/formats/plaintext.pm" && -r "$T2H_HOME/formats/plaintext.pm");
  1481. my $translation_file = 'translations.pl'; # file containing all the translations
  1482. my $T2H_OBSOLETE_STRINGS;
  1483. # leave this within comments, and keep the require statement
  1484. # This way, you can directly run texi2html.pl,
  1485. # if $T2H_HOME/translations.pl exists.
  1486. #
  1487. # @T2H_TRANSLATIONS_FILE@
  1488. require "$T2H_HOME/$translation_file"
  1489. if ($0 =~ /\.pl$/ &&
  1490. -e "$T2H_HOME/$translation_file" && -r "$T2H_HOME/$translation_file");
  1491. # these are unlikely to be used by users, as they are essentially
  1492. # used to follow the html external refs specification in texinfo
  1493. sub t2h_cross_manual_normal_text($$$$$$$;$)
  1494. {
  1495. my $text = shift;
  1496. my $in_raw_text = shift;
  1497. my $in_preformatted = shift;
  1498. my $in_code =shift;
  1499. my $in_math = shift;
  1500. my $in_simple =shift;
  1501. my $style_stack = shift;
  1502. my $state = shift;
  1503. $text = uc($text) if (in_small_caps($style_stack));
  1504. return $text if (get_conf('USE_UNICODE'));
  1505. return t2h_no_unicode_cross_manual_normal_text($text, 0);
  1506. }
  1507. sub t2h_cross_manual_normal_text_transliterate($$$$$$$;$)
  1508. {
  1509. my $text = shift;
  1510. my $in_raw_text = shift;
  1511. my $in_preformatted = shift;
  1512. my $in_code =shift;
  1513. my $in_math = shift;
  1514. my $in_simple =shift;
  1515. my $style_stack = shift;
  1516. my $state = shift;
  1517. $text = uc($text) if (in_small_caps($style_stack));
  1518. return $text if (get_conf('USE_UNICODE'));
  1519. return t2h_no_unicode_cross_manual_normal_text($text, 1);
  1520. }
  1521. sub t2h_no_unicode_cross_manual_normal_text($$)
  1522. {
  1523. # if there is no unicode support, we do all the transformations here
  1524. my $text = shift;
  1525. my $transliterate = shift;
  1526. my $result = '';
  1527. my $encoding = get_conf('documentencoding');
  1528. if (defined($encoding) and exists($t2h_encoding_aliases{$encoding}))
  1529. {
  1530. $encoding = $t2h_encoding_aliases{$encoding};
  1531. }
  1532. while ($text ne '')
  1533. {
  1534. if ($text =~ s/^([A-Za-z0-9]+)//o)
  1535. {
  1536. $result .= $1;
  1537. }
  1538. elsif ($text =~ s/^ //o)
  1539. {
  1540. $result .= '-';
  1541. }
  1542. elsif ($text =~ s/^(.)//o)
  1543. {
  1544. if (exists($ascii_character_map{$1}))
  1545. {
  1546. $result .= '_' . lc($ascii_character_map{$1});
  1547. }
  1548. else
  1549. {
  1550. my $character = $1;
  1551. my $charcode = uc(sprintf("%02x",ord($1)));
  1552. my $done = 0;
  1553. if (defined($encoding) and exists($eight_bit_to_unicode{$encoding})
  1554. and exists($eight_bit_to_unicode{$encoding}->{$charcode}))
  1555. {
  1556. $done = 1;
  1557. my $unicode_point = $eight_bit_to_unicode{$encoding}->{$charcode};
  1558. if (!$transliterate)
  1559. {
  1560. $result .= '_' . lc($unicode_point);
  1561. }
  1562. elsif (exists($transliterate_map{$unicode_point}))
  1563. {
  1564. $result .= $transliterate_map{$unicode_point};
  1565. }
  1566. elsif (exists($unicode_diacritical{$unicode_point}))
  1567. {
  1568. $result .= '';
  1569. }
  1570. else
  1571. {
  1572. $done = 0;
  1573. }
  1574. }
  1575. if (!$done)
  1576. { # wild guess that work for latin1, and thus, should fail
  1577. $result .= '_' . '00' . lc($charcode);
  1578. }
  1579. }
  1580. }
  1581. else
  1582. {
  1583. msg_debug("Bug: unknown character in cross ref (likely in infinite loop)");
  1584. msg_debug("Text: !!$text!!");
  1585. sleep 1;
  1586. }
  1587. }
  1588. return $result;
  1589. }
  1590. sub t2h_nounicode_cross_manual_accent($$$)
  1591. {
  1592. my $accent = shift;
  1593. my $args = shift;
  1594. my $style_stack = shift;
  1595. my $text = $args->[0];
  1596. if ($accent eq 'dotless')
  1597. {
  1598. if (($text eq 'i') and (!defined($style_stack->[-1]) or (!defined($unicode_accents{$style_stack->[-1]})) or ($style_stack->[-1] eq 'tieaccent')))
  1599. {
  1600. return "_0131";
  1601. }
  1602. #return "\x{}" if ($text eq 'j'); # not found !
  1603. return $text;
  1604. }
  1605. return '_' . lc($unicode_accents{$accent}->{$text})
  1606. if (defined($unicode_accents{$accent}->{$text}));
  1607. return ($text . '_' . lc($unicode_diacritical{$accent}))
  1608. if (defined($unicode_diacritical{$accent}));
  1609. return ascii_accents($text, $accent);
  1610. }
  1611. sub t2h_transliterate_cross_manual_accent($$)
  1612. {
  1613. my $accent = shift;
  1614. my $args = shift;
  1615. my $text = $args->[0];
  1616. if (exists($unicode_accents{$accent}->{$text}) and
  1617. exists ($transliterate_map{$unicode_accents{$accent}->{$text}}))
  1618. {
  1619. return $transliterate_map{$unicode_accents{$accent}->{$text}};
  1620. }
  1621. return $text;
  1622. }
  1623. } # end package Texi2HTML::Config
  1624. # set the defaults based on real command name
  1625. set_config_init_dirs_output($real_command_name);
  1626. use vars qw(
  1627. %value
  1628. %alias
  1629. );
  1630. # variables which might be redefined by the user but aren't likely to be
  1631. # they seem to be in the main namespace
  1632. use vars qw(
  1633. %index_names
  1634. %index_prefix_to_name
  1635. %predefined_index
  1636. %valid_index
  1637. %reference_sec2level
  1638. %code_style_map
  1639. %forbidden_index_name
  1640. );
  1641. # Some global variables are set in the script, and used in the subroutines
  1642. # they are in the Texi2HTML namespace, thus prefixed with Texi2HTML::.
  1643. # see texi2html.pm for details.
  1644. #+++############################################################################
  1645. # #
  1646. # Pasted content of File $(srcdir)/MySimple.pm: Command-line processing #
  1647. # #
  1648. #---############################################################################
  1649. # leave this within comments, and keep the require statement
  1650. # This way, you can directly run texi2html.pl, if $T2H_HOME/MySimple.pm
  1651. # exists.
  1652. # @MYSIMPLE@
  1653. require "$T2H_HOME/MySimple.pm"
  1654. if ($0 =~ /\.pl$/ &&
  1655. -e "$T2H_HOME/MySimple.pm" && -r "$T2H_HOME/MySimple.pm");
  1656. #+++########################################################################
  1657. # #
  1658. # Pasted content of File $(srcdir)/T2h_i18n.pm: Internationalisation #
  1659. # #
  1660. #---########################################################################
  1661. # leave this within comments, and keep the require statement
  1662. # This way, you can directly run texi2html.pl, if $T2H_HOME/T2h_i18n.pm
  1663. # exists.
  1664. {
  1665. # @T2H_I18N@
  1666. require "$T2H_HOME/T2h_i18n.pm"
  1667. if ($0 =~ /\.pl$/ &&
  1668. -e "$T2H_HOME/T2h_i18n.pm" && -r "$T2H_HOME/T2h_i18n.pm");
  1669. }
  1670. #########################################################################
  1671. #
  1672. # latex2html code
  1673. #
  1674. #---######################################################################
  1675. {
  1676. # leave this within comments, and keep the require statement
  1677. # This way, you can directly run texi2html.pl, if $ENV{T2H_HOME}/T2h_l2h.pm
  1678. # exists.
  1679. # @T2H_L2H@
  1680. require "$T2H_HOME/T2h_l2h.pm"
  1681. if ($0 =~ /\.pl$/ &&
  1682. -e "$T2H_HOME/T2h_l2h.pm" && -r "$T2H_HOME/T2h_l2h.pm");
  1683. }
  1684. {
  1685. package Texi2HTML::LaTeX2HTML::Config;
  1686. # latex2html variables
  1687. # These variables are not used. They are here for information only, and
  1688. # an example of config file for latex2html file is included.
  1689. my $ADDRESS;
  1690. my $ANTI_ALIAS;
  1691. my $ANTI_ALIAS_TEXT;
  1692. my $ASCII_MODE;
  1693. my $AUTO_LINK;
  1694. my $AUTO_PREFIX;
  1695. my $CHILDLINE;
  1696. my $DEBUG;
  1697. my $DESTDIR;
  1698. my $DVIPS = 'dvips';
  1699. my $ERROR;
  1700. my $EXTERNAL_FILE;
  1701. my $EXTERNAL_IMAGES;
  1702. my $EXTERNAL_UP_LINK;
  1703. my $EXTERNAL_UP_TITLE;
  1704. my $FIGURE_SCALE_FACTOR;
  1705. my $HTML_VERSION;
  1706. my $IMAGES_ONLY;
  1707. my $INFO;
  1708. my $LINE_WIDTH;
  1709. my $LOCAL_ICONS;
  1710. my $LONG_TITLES;
  1711. my $MATH_SCALE_FACTOR;
  1712. my $MAX_LINK_DEPTH;
  1713. my $MAX_SPLIT_DEPTH;
  1714. my $NETSCAPE_HTML;
  1715. my $NOLATEX;
  1716. my $NO_FOOTNODE;
  1717. my $NO_IMAGES;
  1718. my $NO_NAVIGATION;
  1719. my $NO_SIMPLE_MATH;
  1720. my $NO_SUBDIR;
  1721. my $PAPERSIZE;
  1722. my $PREFIX;
  1723. my $PS_IMAGES;
  1724. my $REUSE;
  1725. my $SCALABLE_FONTS;
  1726. my $SHORTEXTN;
  1727. my $SHORT_INDEX;
  1728. my $SHOW_SECTION_NUMBERS;
  1729. my $SPLIT;
  1730. my $TEXDEFS;
  1731. my $TITLE;
  1732. my $TITLES_LANGUAGE;
  1733. my $TMP;
  1734. my $VERBOSE;
  1735. my $WORDS_IN_NAVIGATION_PANEL_TITLES;
  1736. my $WORDS_IN_PAGE;
  1737. # @T2H_L2H_INIT@
  1738. }
  1739. package main;
  1740. # functions related with configuration variables.
  1741. sub get_conf($)
  1742. {
  1743. my $var = shift;
  1744. return Texi2HTML::Config::get_conf($var);
  1745. }
  1746. sub set_from_cmdline($$)
  1747. {
  1748. my $var = shift;
  1749. my $value = shift;
  1750. my $level = 1;
  1751. return Texi2HTML::Config::set_variable($var, $value, $level);
  1752. }
  1753. sub global_override($$)
  1754. {
  1755. my $var = shift;
  1756. my $value = shift;
  1757. return Texi2HTML::Config::set_variable($var, $value, undef);
  1758. }
  1759. sub document_override($$)
  1760. {
  1761. my $var = shift;
  1762. my $value = shift;
  1763. return Texi2HTML::Config::set_variable($var, $value, undef, 1);
  1764. }
  1765. sub set_from_document($$)
  1766. {
  1767. my $var = shift;
  1768. my $value = shift;
  1769. my $level = 5;
  1770. return Texi2HTML::Config::set_variable($var, $value, $level, 1);
  1771. }
  1772. sub unset_from_document($)
  1773. {
  1774. my $var = shift;
  1775. my $level = 5;
  1776. return Texi2HTML::Config::unset_variable($var, $level, 1);
  1777. }
  1778. # prepare the gettext-like framework. To be noted that Locales::TextDomain
  1779. # canot be used, since it cannot be used dynamically through a reuires.
  1780. # Fortunately, Locales::TextDomain is a thin layer above Locales::Messages.
  1781. Texi2HTML::Config::set_default('USE_NLS', ('@USE_NLS@' eq 'yes' or $0 =~ /\.pl$/));
  1782. my $strings_textdomain = '@PACKAGE@' . '_document';
  1783. $strings_textdomain = 'texi2html_document' if ($strings_textdomain eq '@'.'PACKAGE@' . '_document');
  1784. my $messages_textdomain = '@PACKAGE@';
  1785. $messages_textdomain = 'texi2html' if ($messages_textdomain eq '@'.'PACKAGE@');
  1786. #my $messages_textdomain = 'texinfo';
  1787. if (get_conf('USE_NLS'))
  1788. {
  1789. if ($0 =~ /\.pl$/)
  1790. { # use in-source libintl when testing
  1791. unshift @INC, "$T2H_HOME/lib/libintl-perl/lib";
  1792. }
  1793. elsif ($ENV{T2H_SOURCE_LIBINTL})
  1794. {
  1795. unshift @INC, $ENV{T2H_SOURCE_LIBINTL};
  1796. }
  1797. elsif ('@USE_EXTERNAL_LIBINTL@' ne 'yes')
  1798. {
  1799. unshift @INC, "$pkgdatadir/lib/libintl-perl/lib";
  1800. }
  1801. else
  1802. {
  1803. eval {
  1804. require Locale::Messages;
  1805. };
  1806. if ($@)
  1807. {
  1808. unshift @INC, "$pkgdatadir/lib/libintl-perl/lib";
  1809. }
  1810. }
  1811. # gettext-like translations
  1812. #require Locale::TextDomain;
  1813. require Locale::Messages;
  1814. # we want a reliable way to switch locale, so we don't use the system
  1815. # gettext.
  1816. Locale::Messages->select_package ('gettext_pp');
  1817. if ($0 =~ /\.pl$/)
  1818. {
  1819. # in case of out of source build, the locales directory should
  1820. # be two levels below. $T2H_HOME is in srcdir.
  1821. foreach my $locales_dir ("$T2H_HOME/locales", "../../locales")
  1822. {
  1823. if (-d $locales_dir)
  1824. {
  1825. Locale::Messages::bindtextdomain ($strings_textdomain, $locales_dir);
  1826. last;
  1827. }
  1828. }
  1829. }
  1830. else
  1831. { # match where gettext installs
  1832. Locale::Messages::bindtextdomain ($strings_textdomain, "$datadir/locale");
  1833. }
  1834. # simply bind error messages to the installation directory.
  1835. # Messages should be untranslated for tests.
  1836. Locale::Messages::bindtextdomain ($messages_textdomain, "$datadir/locale");
  1837. }
  1838. sub __($)
  1839. {
  1840. my $msgid = shift;
  1841. return Locale::Messages::dgettext($messages_textdomain, $msgid);
  1842. }
  1843. sub __p($$)
  1844. {
  1845. my $context = shift;
  1846. my $msgid = shift;
  1847. return Locale::Messages::dpgettext($messages_textdomain, $context, $msgid);
  1848. }
  1849. sub N__($)
  1850. {
  1851. return $_[0];
  1852. }
  1853. #
  1854. # flush stdout and stderr after every write
  1855. #
  1856. select(STDERR);
  1857. $| = 1;
  1858. select(STDOUT);
  1859. $| = 1;
  1860. my $I = \&Texi2HTML::I18n::get_string;
  1861. ########################################################################
  1862. #
  1863. # Global variable initialization
  1864. #
  1865. ########################################################################
  1866. #
  1867. # pre-defined indices
  1868. #
  1869. %index_prefix_to_name = ();
  1870. %index_names =
  1871. (
  1872. 'cp' => {'cp' => 0,'c' => 0},
  1873. 'fn' => {'fn' => 1, 'f' => 1},
  1874. 'vr' => {'vr' => 1, 'v' => 1},
  1875. 'ky' => {'ky' => 1, 'k' => 1},
  1876. 'pg' => {'pg' => 1, 'p' => 1},
  1877. 'tp' => {'tp' => 1, 't' => 1}
  1878. );
  1879. foreach my $name(keys(%index_names))
  1880. {
  1881. foreach my $prefix (keys %{$index_names{$name}})
  1882. {
  1883. $forbidden_index_name{$prefix} = 1;
  1884. $index_prefix_to_name{$prefix} = $name;
  1885. }
  1886. }
  1887. foreach my $other_forbidden_index_name ('info','ps','pdf','htm',
  1888. 'log','aux','dvi','texi','txi','texinfo','tex','bib')
  1889. {
  1890. $forbidden_index_name{$other_forbidden_index_name} = 1;
  1891. }
  1892. # commands with ---, -- '' and `` preserved
  1893. # usefull with the old interface
  1894. %code_style_map = (
  1895. 'code' => 1,
  1896. 'command' => 1,
  1897. 'env' => 1,
  1898. 'file' => 1,
  1899. 'kbd' => 1,
  1900. 'option' => 1,
  1901. 'samp' => 1,
  1902. 'verb' => 1,
  1903. );
  1904. my @element_directions = ('Up', 'Forward', 'Back', 'Next', 'Prev',
  1905. 'SectionNext', 'SectionPrev', 'SectionUp', 'FastForward', 'FastBack',
  1906. 'This', 'NodeUp', 'NodePrev', 'NodeNext', 'NodeForward', 'NodeBack',
  1907. 'NextFile', 'PrevFile', 'ToplevelNext', 'ToplevelPrev');
  1908. $::simple_map_ref = \%Texi2HTML::Config::simple_map;
  1909. $::simple_map_math_ref = \%Texi2HTML::Config::simple_map_math;
  1910. #$::simple_map_pre_ref = \%Texi2HTML::Config::simple_map_pre;
  1911. $::simple_map_texi_ref = \%Texi2HTML::Config::simple_map_texi;
  1912. $::style_map_ref = \%Texi2HTML::Config::style_map;
  1913. $::style_map_pre_ref = \%Texi2HTML::Config::style_map_pre;
  1914. $::style_map_math_ref = \%Texi2HTML::Config::style_map_math;
  1915. $::style_map_texi_ref = \%Texi2HTML::Config::style_map_texi;
  1916. $::things_map_ref = \%Texi2HTML::Config::things_map;
  1917. $::pre_map_ref = \%Texi2HTML::Config::pre_map;
  1918. $::texi_map_ref = \%Texi2HTML::Config::texi_map;
  1919. #print STDERR "MAPS: $::simple_map_ref $::simple_map_pre_ref $::simple_map_texi_ref $::style_map_ref $::style_map_pre_ref $::style_map_texi_ref $::things_map_ref $::pre_map_ref $::texi_map_ref\n";
  1920. # delete from hash if we are using the new interface
  1921. foreach my $code (keys(%code_style_map))
  1922. {
  1923. delete ($code_style_map{$code})
  1924. if (ref($::style_map_ref->{$code}) eq 'HASH');
  1925. }
  1926. # no paragraph in these commands
  1927. my %no_paragraph_macro = (
  1928. 'xref' => 1,
  1929. 'ref' => 1,
  1930. 'pxref' => 1,
  1931. 'inforef' => 1,
  1932. 'anchor' => 1,
  1933. );
  1934. #
  1935. # texinfo section names to level
  1936. #
  1937. my %reference_sec2level = (
  1938. 'top', 0,
  1939. 'chapter', 1,
  1940. 'unnumbered', 1,
  1941. 'chapheading', 1,
  1942. 'appendix', 1,
  1943. 'section', 2,
  1944. 'unnumberedsec', 2,
  1945. 'heading', 2,
  1946. 'appendixsec', 2,
  1947. 'subsection', 3,
  1948. 'unnumberedsubsec', 3,
  1949. 'subheading', 3,
  1950. 'appendixsubsec', 3,
  1951. 'subsubsection', 4,
  1952. 'unnumberedsubsubsec', 4,
  1953. 'subsubheading', 4,
  1954. 'appendixsubsubsec', 4,
  1955. );
  1956. # the reverse mapping. There is an entry for each sectioning command.
  1957. # The value is a ref on an array containing at each index the corresponding
  1958. # sectioning command name.
  1959. my %level2sec;
  1960. {
  1961. my $sections = [ ];
  1962. my $appendices = [ ];
  1963. my $unnumbered = [ ];
  1964. my $headings = [ ];
  1965. foreach my $command (keys (%reference_sec2level))
  1966. {
  1967. if ($command =~ /^appendix/)
  1968. {
  1969. $level2sec{$command} = $appendices;
  1970. }
  1971. elsif ($command =~ /^unnumbered/ or $command eq 'top')
  1972. {
  1973. $level2sec{$command} = $unnumbered;
  1974. }
  1975. elsif ($command =~ /section$/ or $command eq 'chapter')
  1976. {
  1977. $level2sec{$command} = $sections;
  1978. }
  1979. else
  1980. {
  1981. $level2sec{$command} = $headings;
  1982. }
  1983. $level2sec{$command}->[$reference_sec2level{$command}] = $command;
  1984. }
  1985. }
  1986. # out of the main hierarchy
  1987. $reference_sec2level{'part'} = 0;
  1988. # this are synonyms
  1989. $reference_sec2level{'appendixsection'} = 2;
  1990. # sec2level{'majorheading'} is also 1 and not 0
  1991. $reference_sec2level{'majorheading'} = 1;
  1992. $reference_sec2level{'chapheading'} = 1;
  1993. $reference_sec2level{'centerchap'} = 1;
  1994. sub stop_paragraph_command($)
  1995. {
  1996. my $command = shift;
  1997. return 1 if ($Texi2HTML::Config::stop_paragraph_command{$command} or defined($reference_sec2level{$command}));
  1998. }
  1999. sub set_no_line_macro($$)
  2000. {
  2001. my $macro = shift;
  2002. my $value = shift;
  2003. $Texi2HTML::Config::no_paragraph_commands{$macro} = $value
  2004. unless defined($Texi2HTML::Config::no_paragraph_commands{$macro});
  2005. }
  2006. # those macros aren't considered as beginning a paragraph
  2007. foreach my $no_line_macro ('alias', 'macro', 'unmacro', 'rmacro',
  2008. 'titlefont', 'include', 'copying', 'end copying', 'tab', 'item',
  2009. 'itemx', '*', 'float', 'end float', 'caption', 'shortcaption', 'cindex',
  2010. 'image')
  2011. {
  2012. set_no_line_macro($no_line_macro, 1);
  2013. }
  2014. # holds all the @-commands that should be at the beginning of a line
  2015. my %begin_line_command = ();
  2016. foreach my $command ('node', 'end')
  2017. {
  2018. $begin_line_command{$command} = $command;
  2019. }
  2020. foreach my $key (keys(%Texi2HTML::Config::misc_command), keys(%reference_sec2level))
  2021. {
  2022. set_no_line_macro($key, 1);
  2023. $begin_line_command{$key} = $key;
  2024. }
  2025. foreach my $misc_not_begin_line('comment', 'c', 'sp', 'refill', 'noindent', 'indent')
  2026. {
  2027. delete $begin_line_command{$misc_not_begin_line};
  2028. }
  2029. # a hash associating a format @thing / @end thing with the type of the format
  2030. # 'complex_format' 'simple_format' 'deff' 'list' 'menu' 'paragraph_format'
  2031. my %format_type = ();
  2032. foreach my $simple_format (keys(%Texi2HTML::Config::format_map))
  2033. {
  2034. $format_type{$simple_format} = 'simple_format';
  2035. }
  2036. foreach my $paragraph_style (keys(%Texi2HTML::Config::paragraph_style))
  2037. {
  2038. $format_type{$paragraph_style} = 'paragraph_format';
  2039. }
  2040. # FIXME $complex_format_map obsoleted in nov 2009
  2041. foreach my $complex_format (keys(%$Texi2HTML::Config::complex_format_map),
  2042. keys(%Texi2HTML::Config::complex_format_map))
  2043. {
  2044. $format_type{$complex_format} = 'complex_format';
  2045. }
  2046. foreach my $table (('table', 'ftable', 'vtable'))
  2047. {
  2048. $format_type{$table} = 'table';
  2049. }
  2050. $format_type{'multitable'} = 'multitable';
  2051. foreach my $def_format (keys(%Texi2HTML::Config::def_map))
  2052. {
  2053. $format_type{$def_format} = 'deff';
  2054. }
  2055. $format_type{'itemize'} = 'list';
  2056. $format_type{'enumerate'} = 'list';
  2057. $format_type{'menu'} = 'menu';
  2058. $format_type{'detailmenu'} = 'menu';
  2059. $format_type{'direntry'} = 'menu';
  2060. $format_type{'cartouche'} = 'cartouche';
  2061. $format_type{'float'} = 'float';
  2062. $format_type{'quotation'} = 'quotation';
  2063. $format_type{'smallquotation'} = 'quotation';
  2064. $format_type{'group'} = 'group';
  2065. my @special_regions = ('titlepage', 'copying', 'documentdescription');
  2066. foreach my $region (@special_regions)
  2067. {
  2068. $format_type{$region} = 'region';
  2069. }
  2070. foreach my $key (keys(%format_type))
  2071. {
  2072. set_no_line_macro($key, 1);
  2073. set_no_line_macro("end $key", 1);
  2074. }
  2075. foreach my $macro (keys(%Texi2HTML::Config::format_in_paragraph))
  2076. {
  2077. set_no_line_macro($macro, 1);
  2078. set_no_line_macro("end $macro", 1);
  2079. }
  2080. foreach my $format (keys(%format_type))
  2081. {
  2082. $begin_line_command{$format} = $format_type{$format};
  2083. }
  2084. # fake format at the bottom of the stack
  2085. $format_type{'noformat'} = '';
  2086. # fake formats are formats used internally within other formats
  2087. # we associate them with a real format, for the error messages
  2088. my %fake_format = (
  2089. 'line' => 'table',
  2090. 'term' => 'table',
  2091. 'item' => 'list or table',
  2092. 'row' => 'multitable row',
  2093. 'cell' => 'multitable cell',
  2094. 'deff_item' => 'definition command',
  2095. 'menu_comment' => 'menu',
  2096. 'menu_description' => 'menu',
  2097. );
  2098. foreach my $key (keys(%fake_format))
  2099. {
  2100. $format_type{$key} = 'fake';
  2101. }
  2102. # raw formats which are expanded especially
  2103. my @raw_regions = ('html', 'tex', 'xml', 'docbook');
  2104. foreach my $format (keys(%Texi2HTML::Config::texi_formats_map), @raw_regions)
  2105. {
  2106. $begin_line_command{$format} = $format;
  2107. }
  2108. foreach my $format (keys(%Texi2HTML::Config::texi_formats_map))
  2109. {
  2110. push @raw_regions, $format if ($Texi2HTML::Config::texi_formats_map{$format} eq 'raw');
  2111. }
  2112. # The css formats are associated with complex format commands, and associated
  2113. # with the 'pre_style' key
  2114. # FIXME $complex_format_map obsoleted in nov 2009
  2115. foreach my $complex_format (keys(%$Texi2HTML::Config::complex_format_map))
  2116. {
  2117. next if (defined($Texi2HTML::Config::complex_format_map->{$complex_format}->{'pre_style'}));
  2118. $Texi2HTML::Config::complex_format_map->{$complex_format}->{'pre_style'} = '';
  2119. $Texi2HTML::Config::complex_format_map->{$complex_format}->{'pre_style'} = $Texi2HTML::Config::css_map{"pre.$complex_format"} if (exists($Texi2HTML::Config::css_map{"pre.$complex_format"}));
  2120. }
  2121. # The css formats are associated with complex format commands, and associated
  2122. # with the 'pre_style' key
  2123. foreach my $complex_format (keys(%Texi2HTML::Config::complex_format_map))
  2124. {
  2125. next if (defined($Texi2HTML::Config::complex_format_map{$complex_format}->{'pre_style'}));
  2126. $Texi2HTML::Config::complex_format_map{$complex_format}->{'pre_style'} = '';
  2127. $Texi2HTML::Config::complex_format_map{$complex_format}->{'pre_style'} = $Texi2HTML::Config::css_map{"pre.$complex_format"} if (exists($Texi2HTML::Config::css_map{"pre.$complex_format"}));
  2128. }
  2129. #+++############################################################################
  2130. # #
  2131. # Argument parsing, initialisation #
  2132. # #
  2133. #---############################################################################
  2134. # shorthand for get_conf('VERBOSE')
  2135. my $T2H_VERBOSE;
  2136. my $T2H_DEBUG;
  2137. #
  2138. # %value hold texinfo variables, see also -D, -U, @set and @clear.
  2139. # we predefine html (the output format) and texi2html (the translator)
  2140. # it is initialized with %value_initial at the beginning of the
  2141. # document parsing and filled and emptied as @set and @clear are
  2142. # encountered
  2143. # FIXME remove html
  2144. my %value_initial =
  2145. (
  2146. # 'html' => 1,
  2147. 'texi2html' => $THISVERSION,
  2148. );
  2149. sub line_warn($$);
  2150. sub document_warn($);
  2151. sub file_line_warn($$;$);
  2152. sub cmdline_warn ($);
  2153. my $T2H_FAILURE_TEXT = sprintf(__("Try `%s --help' for more information.\n"), $real_command_name);
  2154. #print STDERR "" . gdt('test i18n: \' , \a \\ %% %{unknown}a %known % %{known} \\', { 'known' => 'a known string', 'no' => 'nope'}); exit 0;
  2155. sub add_to_texi2dvi_args($;$)
  2156. {
  2157. my $option = shift;
  2158. my $value = shift;
  2159. #print STDERR "$option $value\n";
  2160. push @Texi2HTML::Config::TEXI2DVI_ARGUMENTS, $option;
  2161. push @Texi2HTML::Config::TEXI2DVI_ARGUMENTS, $value if (defined($value));
  2162. }
  2163. # file: file name to locate. It can be a file path.
  2164. # directories: a reference on a array containing a list of directories to
  2165. # search the file in.
  2166. # all_files: if true collect all the files with that name, otherwise stop
  2167. # at first match.
  2168. sub locate_init_file($$$)
  2169. {
  2170. my $file = shift;
  2171. my $directories = shift;
  2172. my $all_files = shift;
  2173. if ($file =~ /^\//)
  2174. {
  2175. return $file if (-e $file and -r $file);
  2176. }
  2177. else
  2178. {
  2179. my @files;
  2180. foreach my $dir (@$directories)
  2181. {
  2182. next unless (-d "$dir");
  2183. if ($all_files)
  2184. {
  2185. push (@files, "$dir/$file") if (-e "$dir/$file" and -r "$dir/$file");
  2186. }
  2187. else
  2188. {
  2189. return "$dir/$file" if (-e "$dir/$file" and -r "$dir/$file");
  2190. }
  2191. }
  2192. return @files if ($all_files);
  2193. }
  2194. return undef;
  2195. }
  2196. # called on -init-file
  2197. sub load_init_file
  2198. {
  2199. # First argument is option
  2200. shift;
  2201. # second argument is value of options
  2202. my $init_file = shift;
  2203. my $file = locate_init_file($init_file, [ @Texi2HTML::Config::CONF_DIRS, @program_init_dirs ], 0);
  2204. if ($file)
  2205. {
  2206. print STDERR "# reading initialization file from $file\n"
  2207. if ($T2H_VERBOSE);
  2208. # require the file in the Texi2HTML::Config namespace
  2209. return (Texi2HTML::Config::load($file));
  2210. }
  2211. else
  2212. {
  2213. document_error ("Can't read init file $init_file");
  2214. return 0;
  2215. }
  2216. }
  2217. sub set_date($)
  2218. {
  2219. my $language = shift;
  2220. if (!get_conf('TEST'))
  2221. {
  2222. print STDERR "# Setting date in $language\n" if ($T2H_DEBUG);
  2223. set_from_document('today', Texi2HTML::I18n::pretty_date($language)); # like "20 September 1993";
  2224. }
  2225. else
  2226. {
  2227. set_from_document('today', 'a sunny day');
  2228. }
  2229. $::things_map_ref->{'today'} = get_conf('today');
  2230. $::pre_map_ref->{'today'} = get_conf('today');
  2231. $::texi_map_ref->{'today'} = get_conf('today');
  2232. }
  2233. sub warn_unknown_language($;$)
  2234. {
  2235. my $lang = shift;
  2236. my $line_nr = shift;
  2237. my $lang_code = $lang;
  2238. my $region_code;
  2239. if ($lang =~ /^([a-z]+)_([A-Z]+)/)
  2240. {
  2241. $lang_code = $1;
  2242. $region_code = $2;
  2243. }
  2244. if (! $Texi2HTML::Config::language_codes{$lang_code})
  2245. {
  2246. msg_warn(sprintf(__("%s is not a valid language code"), $lang_code), $line_nr);
  2247. }
  2248. if (defined($region_code) and ! $Texi2HTML::Config::region_codes{$region_code})
  2249. {
  2250. msg_warn(sprintf(__("%s is not a valid region code"), $region_code), $line_nr);
  2251. }
  2252. }
  2253. # Called on --document-language, at the beginning of each pass and
  2254. # when a @documentlanguage appears
  2255. sub set_document_language ($;$)
  2256. {
  2257. my $lang = shift;
  2258. my $line_nr = shift;
  2259. # Always succeed if using a gettext-like environment
  2260. if (!get_conf('I18N_PERL_HASH'))
  2261. {
  2262. set_date($lang);
  2263. return 1;
  2264. }
  2265. # old framework code
  2266. my @langs = ($lang);
  2267. my $main_lang;
  2268. if ($lang =~ /^([a-z]+)_([A-Z]+)/)
  2269. {
  2270. $main_lang = $1;
  2271. push @langs, $main_lang;
  2272. }
  2273. my @files = locate_init_file("$i18n_dir/$lang.thl", \@program_config_dirs, 1);
  2274. if (! scalar(@files) and defined($main_lang))
  2275. {
  2276. @files = locate_init_file("$i18n_dir/$main_lang.thl", \@program_config_dirs, 1);
  2277. }
  2278. foreach my $file (@files)
  2279. {
  2280. Texi2HTML::Config::load($file);
  2281. }
  2282. foreach my $language (@langs)
  2283. {
  2284. if (Texi2HTML::I18n::set_language($language))
  2285. {
  2286. print STDERR "# using '$language' as document language\n" if ($T2H_VERBOSE);
  2287. set_date($language);
  2288. return 1;
  2289. }
  2290. }
  2291. return 0;
  2292. }
  2293. # manage footnote style
  2294. sub set_footnote_style($$;$)
  2295. {
  2296. my $value = shift;
  2297. my $from_command_line = shift;
  2298. my $line_nr = shift;
  2299. my $command = 'footnotestyle';
  2300. if ($value eq 'end' or $value eq 'separate')
  2301. {
  2302. if ($from_command_line)
  2303. {
  2304. set_from_cmdline($command, $value);
  2305. }
  2306. else
  2307. {
  2308. set_from_document($command, $value);
  2309. }
  2310. }
  2311. elsif ($from_command_line)
  2312. {
  2313. die sprintf(__("%s: --footnote-style arg must be `separate' or `end', not `%s'.\n"), $real_command_name, $value);
  2314. # the T2H_FAILURE_TEXT is output by getOption, seems to catch die
  2315. }
  2316. else
  2317. {
  2318. line_error (sprintf(__("\@%s arg must be `separate' or `end', not `%s'"), $command, $value), $line_nr);
  2319. }
  2320. }
  2321. sub set_output($;$)
  2322. {
  2323. my $output = shift;
  2324. my $from_command_line = shift;
  2325. my $var = 'OUTFILE';
  2326. if ($output =~ m:/$: or -d $output)
  2327. {
  2328. $var = 'SUBDIR';
  2329. }
  2330. if ($from_command_line)
  2331. {
  2332. set_from_cmdline($var, $output);
  2333. set_from_cmdline('OUT', $output);
  2334. add_to_texi2dvi_args('-o', $output);
  2335. }
  2336. else
  2337. {
  2338. set_default($var, $output);
  2339. if (set_default('OUT', $output))
  2340. {
  2341. add_to_texi2dvi_args('-o', $output);
  2342. }
  2343. }
  2344. }
  2345. # used both for command line and @-command argument checking
  2346. sub set_paragraphindent($$;$$)
  2347. {
  2348. my $value = shift;
  2349. my $from_command_line = shift;
  2350. my $line_nr = shift;
  2351. my $pass = shift;
  2352. my $command = 'paragraphindent';
  2353. if ($value =~ /^([0-9]+)$/ or $value eq 'none' or $value eq 'asis')
  2354. {
  2355. if ($from_command_line)
  2356. {
  2357. set_from_cmdline($command, $value)
  2358. }
  2359. else
  2360. {
  2361. set_from_document($command, $value)
  2362. }
  2363. }
  2364. elsif ($from_command_line)
  2365. {
  2366. die sprintf(__("%s: --paragraph-indent arg must be numeric/`none'/`asis', not `%s'.\n"), $real_command_name, $value);
  2367. }
  2368. elsif ($pass == 1)
  2369. {
  2370. line_error (sprintf(__("\@paragraphindent arg must be numeric/`none'/`asis', not `%s'"), $value), $line_nr);
  2371. }
  2372. }
  2373. # find the encoding alias.
  2374. # with encoding support (USE_UNICODE), may return undef if no alias was found.
  2375. # The $line_nr argument should only be set when called from misc_command_texi
  2376. # for @documentencoding, and so the error message should only be echoed at
  2377. # that time.
  2378. sub encoding_alias($;$$)
  2379. {
  2380. my $encoding = shift;
  2381. my $line_nr = shift;
  2382. my $context_string = shift;
  2383. return undef if (!defined($encoding) or $encoding eq '');
  2384. if (get_conf('USE_UNICODE'))
  2385. {
  2386. my $result_encoding = Encode::resolve_alias($encoding);
  2387. if (! $result_encoding)
  2388. {
  2389. line_warn(sprintf(__("unrecognized encoding name `%s'"), $encoding), $line_nr);
  2390. return undef;
  2391. }
  2392. if (defined($Texi2HTML::Config::t2h_encoding_aliases{$result_encoding}))
  2393. {
  2394. $result_encoding = $Texi2HTML::Config::t2h_encoding_aliases{$result_encoding};
  2395. }
  2396. print STDERR "# Using encoding $result_encoding\n" if ($T2H_VERBOSE);
  2397. return $result_encoding;
  2398. }
  2399. else
  2400. {
  2401. if (exists($Texi2HTML::Config::t2h_encoding_aliases{$encoding}))
  2402. {
  2403. $encoding = $Texi2HTML::Config::t2h_encoding_aliases{$encoding};
  2404. return $encoding;
  2405. }
  2406. line_warn(sprintf(__("Encoding %s certainly poorly supported"), $encoding), $line_nr);
  2407. return $encoding;
  2408. }
  2409. }
  2410. # libintl converts between encodings but doesn't decode them into the
  2411. # perl internal format.
  2412. sub encode_i18n_string($$)
  2413. {
  2414. my $string = shift;
  2415. my $encoding = shift;
  2416. if ($encoding ne 'us-ascii' and get_conf('USE_UNICODE')
  2417. and Encode::resolve_alias($encoding))
  2418. {
  2419. return Encode::decode($encoding, $string);
  2420. }
  2421. return $string;
  2422. }
  2423. sub gdt($;$$)
  2424. {
  2425. my $message = shift;
  2426. my $context = shift;
  2427. my $state = shift;
  2428. # FIXME this should be done only once, for @documentencoding
  2429. my $encoding;
  2430. my $input_encoding = get_conf('documentencoding');
  2431. if (defined($input_encoding))
  2432. {
  2433. $encoding = lc($input_encoding);
  2434. }
  2435. if (defined($encoding) and $encoding ne '' and exists($Texi2HTML::Config::t2h_encoding_aliases{$encoding}))
  2436. {
  2437. $encoding = $Texi2HTML::Config::t2h_encoding_aliases{$encoding};
  2438. }
  2439. $encoding = 'us-ascii' if (!defined($encoding) or $encoding eq '');
  2440. return &$I($message, $context, $state) if (get_conf('I18N_PERL_HASH'));
  2441. # if set, use substitute_text instead of substitute_line
  2442. my $allow_paragraph = $state->{'allow_paragraph'};
  2443. # if duplicate is passed, it means that we are in the text and so should
  2444. # use the main state
  2445. if (defined($state) and $state->{'duplicate'} and defined($Texi2HTML::THISDOC{'state'}))
  2446. {
  2447. $state = main::duplicate_formatting_state($Texi2HTML::THISDOC{'state'});
  2448. }
  2449. my $result;
  2450. # taken from libintl perl, copyright Guido. sub __expand. Overall not
  2451. # enough code taken form Guido right now to be copyrightable.
  2452. my $re = join '|', map { quotemeta $_ } keys %$context if (defined($context) and ref($context));
  2453. if (get_conf('USE_NLS'))
  2454. {
  2455. my $saved_LANGUAGE = $ENV{'LANGUAGE'};
  2456. Locale::Messages::textdomain($strings_textdomain);
  2457. Locale::Messages::bind_textdomain_codeset($strings_textdomain, $encoding) if ($encoding ne 'us-ascii');
  2458. Locale::Messages::bind_textdomain_filter($strings_textdomain, \&encode_i18n_string, $encoding);
  2459. my $lang = get_conf('documentlanguage');
  2460. my @langs = ($lang);
  2461. if ($lang =~ /^([a-z]+)_([A-Z]+)/)
  2462. {
  2463. my $main_lang = $1;
  2464. my $region_code = $2;
  2465. push @langs, $main_lang;
  2466. }
  2467. my $locales = '';
  2468. foreach my $language (@langs)
  2469. {
  2470. $locales .= "$language.$encoding:";
  2471. #$locales .= "$language:";
  2472. # always try us-ascii, the charset should always be a subset of
  2473. # all charset, and should resort to @-commands if needed for non
  2474. # ascii characters
  2475. if ($encoding ne 'us-ascii')
  2476. {
  2477. $locales .= "$language.us-ascii:";
  2478. }
  2479. }
  2480. $locales =~ s/:$//;
  2481. #print STDERR "$locales\n";
  2482. Locale::Messages::nl_putenv("LANGUAGE=$locales");
  2483. if (!defined($context) or ref($context))
  2484. {
  2485. $result = Locale::Messages::gettext($message);
  2486. }
  2487. else
  2488. {
  2489. $result = Locale::Messages::pgettext($context, $message);
  2490. }
  2491. Locale::Messages::textdomain($messages_textdomain);
  2492. # old perl complains 'Use of uninitialized value in scalar assignment'
  2493. if (!defined($saved_LANGUAGE))
  2494. {
  2495. delete ($ENV{'LANGUAGE'});
  2496. }
  2497. else
  2498. {
  2499. $ENV{'LANGUAGE'} = $saved_LANGUAGE;
  2500. }
  2501. }
  2502. # now perform the argument substitutions
  2503. if ($state->{'keep_texi'})
  2504. {
  2505. # next line taken from libintl perl, copyright Guido. sub __expand
  2506. $result =~ s/\{($re)\}/defined $context->{$1} ? $context->{$1} : "{$1}"/ge if (defined($re));
  2507. return $result;
  2508. }
  2509. if (defined($re))
  2510. {
  2511. # next line taken from libintl perl, copyright Guido. sub __expand
  2512. $result =~ s/\{($re)\}/\@internal_translation_open_brace\{\}$1\@internal_translation_close_brace\{\}/g;
  2513. foreach my $map (\%Texi2HTML::Config::things_map, \%Texi2HTML::Config::pre_map, \%Texi2HTML::Config::texi_map, \%Texi2HTML::Config::simple_format_texi_map)
  2514. {
  2515. $map->{'internal_translation_open_brace'} = '{';
  2516. $map->{'internal_translation_close_brace'} = '}';
  2517. }
  2518. }
  2519. if ($allow_paragraph)
  2520. {
  2521. delete $state->{'allow_paragraph'};
  2522. $result = substitute_text ($state, undef, __("translation"), ($result));
  2523. }
  2524. else
  2525. {
  2526. $result = substitute_line ($result, __("translation"), $state);
  2527. }
  2528. if (defined($re))
  2529. {
  2530. $result =~ s/\{($re)\}/defined $context->{$1} ? $context->{$1} : "{$1}"/ge;
  2531. foreach my $map (\%Texi2HTML::Config::things_map, \%Texi2HTML::Config::pre_map, \%Texi2HTML::Config::texi_map, \%Texi2HTML::Config::simple_format_texi_map)
  2532. {
  2533. delete $map->{'internal_translation_open_brace'};
  2534. delete $map->{'internal_translation_close_brace'};
  2535. }
  2536. }
  2537. return $result;
  2538. }
  2539. sub unicode_to_protected($)
  2540. {
  2541. my $text = shift;
  2542. my $result = '';
  2543. while ($text ne '')
  2544. {
  2545. if ($text =~ s/^([A-Za-z0-9]+)//o)
  2546. {
  2547. $result .= $1;
  2548. }
  2549. elsif ($text =~ s/^ //o)
  2550. {
  2551. $result .= '-';
  2552. }
  2553. elsif ($text =~ s/^(.)//o)
  2554. {
  2555. my $char = $1;
  2556. if (exists($Texi2HTML::Config::ascii_character_map{$char}))
  2557. {
  2558. $result .= '_' . lc($Texi2HTML::Config::ascii_character_map{$char});
  2559. }
  2560. else
  2561. {
  2562. if (ord($char) <= hex(0xFFFF))
  2563. {
  2564. $result .= '_' . lc(sprintf("%04x",ord($char)));
  2565. }
  2566. else
  2567. {
  2568. $result .= '__' . lc(sprintf("%06x",ord($char)));
  2569. }
  2570. }
  2571. }
  2572. else
  2573. {
  2574. print STDERR "Bug: unknown character in a cross ref (likely in infinite loop)\n";
  2575. print STDERR "Text: !!$text!!\n";
  2576. sleep 1;
  2577. }
  2578. }
  2579. return $result;
  2580. }
  2581. sub unicode_to_transliterate($)
  2582. {
  2583. my $text = shift;
  2584. if (chomp($text))
  2585. {
  2586. print STDERR "Strange: end of line to transliterate: $text\n";
  2587. }
  2588. my $result = '';
  2589. while ($text ne '')
  2590. {
  2591. if ($text =~ s/^([A-Za-z0-9 ]+)//o)
  2592. {
  2593. $result .= $1;
  2594. }
  2595. elsif ($text =~ s/^(.)//o)
  2596. {
  2597. my $char = $1;
  2598. if (exists($Texi2HTML::Config::ascii_character_map{$char}))
  2599. {
  2600. $result .= $char;
  2601. }
  2602. elsif (ord($char) <= hex(0xFFFF) and exists($Texi2HTML::Config::transliterate_map{uc(sprintf("%04x",ord($char)))}))
  2603. {
  2604. $result .= $Texi2HTML::Config::transliterate_map{uc(sprintf("%04x",ord($char)))};
  2605. }
  2606. elsif (ord($char) <= hex(0xFFFF) and exists($Texi2HTML::Config::unicode_diacritical{uc(sprintf("%04x",ord($char)))}))
  2607. {
  2608. $result .= '';
  2609. }
  2610. # in this case, we want to avoid calling unidecode, as we are sure
  2611. # that there is no useful transliteration of the unicode character
  2612. # instead we want to keep it as is.
  2613. # This is the case, for example, for @exclamdown, is corresponds
  2614. # with x00a1, but unidecode transliterates it to a !, we want
  2615. # to avoid that and keep x00a1.
  2616. elsif (ord($char) <= hex(0xFFFF) and exists($Texi2HTML::Config::no_transliterate_map{uc(sprintf("%04x",ord($char)))}))
  2617. {
  2618. $result .= $char;
  2619. }
  2620. else
  2621. {
  2622. if (get_conf('USE_UNIDECODE'))
  2623. {
  2624. $result .= unidecode($char);
  2625. }
  2626. else
  2627. {
  2628. $result .= $char;
  2629. }
  2630. }
  2631. }
  2632. else
  2633. {
  2634. print STDERR "Bug: unknown character in cross ref transliteration (likely in infinite loop)\n";
  2635. print STDERR "Text: !!$text!!\n";
  2636. sleep 1;
  2637. }
  2638. }
  2639. return $result;
  2640. }
  2641. # T2H_OPTIONS is a hash whose keys are the (long) names of valid
  2642. # command-line options and whose values are a hash with the following keys:
  2643. # type ==> one of !|=i|:i|=s|:s (see Getopt::Long for more info)
  2644. # linkage ==> ref to scalar, array, or subroutine (see Getopt::Long for more info)
  2645. # verbose ==> short description of option (displayed by -h)
  2646. # noHelp ==> if 1 -> for "not so important options": only print description on -h 1
  2647. # 2 -> for obsolete options: only print description on -h 2
  2648. my $T2H_OPTIONS;
  2649. $T2H_OPTIONS -> {'macro-expand|E'} =
  2650. {
  2651. 'type' => '=s',
  2652. 'linkage' => sub {set_from_cmdline('MACRO_EXPAND', $_[1]); add_to_texi2dvi_args('-E'); },
  2653. 'verbose' => 'output macro expanded source in <file>',
  2654. };
  2655. $T2H_OPTIONS -> {'ifhtml'} =
  2656. {
  2657. 'type' => '!',
  2658. 'linkage' => sub { Texi2HTML::Config::set_expansion('html', $_[1]); },
  2659. 'verbose' => "expand ifhtml and html sections",
  2660. };
  2661. $T2H_OPTIONS -> {'ifinfo'} =
  2662. {
  2663. 'type' => '!',
  2664. 'linkage' => sub { Texi2HTML::Config::set_expansion('info', $_[1]); },
  2665. 'verbose' => "expand ifinfo",
  2666. };
  2667. $T2H_OPTIONS -> {'ifxml'} =
  2668. {
  2669. 'type' => '!',
  2670. 'linkage' => sub { Texi2HTML::Config::set_expansion('xml', $_[1]); },
  2671. 'verbose' => "expand ifxml and xml sections",
  2672. };
  2673. $T2H_OPTIONS -> {'ifdocbook'} =
  2674. {
  2675. 'type' => '!',
  2676. 'linkage' => sub { Texi2HTML::Config::set_expansion('docbook', $_[1]); },
  2677. 'verbose' => "expand ifdocbook and docbook sections",
  2678. };
  2679. $T2H_OPTIONS -> {'iftex'} =
  2680. {
  2681. 'type' => '!',
  2682. 'linkage' => sub { Texi2HTML::Config::set_expansion('tex', $_[1]); },
  2683. 'verbose' => "expand iftex and tex sections",
  2684. };
  2685. $T2H_OPTIONS -> {'ifplaintext'} =
  2686. {
  2687. 'type' => '!',
  2688. 'linkage' => sub { Texi2HTML::Config::set_expansion('plaintext', $_[1]); },
  2689. 'verbose' => "expand ifplaintext sections",
  2690. };
  2691. $T2H_OPTIONS -> {'I'} =
  2692. {
  2693. 'type' => '=s',
  2694. 'linkage' => sub { add_to_texi2dvi_args('-'.$_[0], $_[1]); push @Texi2HTML::Config::INCLUDE_DIRS, $_[1] },
  2695. 'verbose' => 'append $s to the @include search path',
  2696. };
  2697. $T2H_OPTIONS -> {'conf-dir'} =
  2698. {
  2699. 'type' => '=s',
  2700. 'linkage' => \@Texi2HTML::Config::CONF_DIRS,
  2701. 'verbose' => 'append $s to the init file directories',
  2702. };
  2703. $T2H_OPTIONS -> {'P'} =
  2704. {
  2705. 'type' => '=s',
  2706. 'linkage' => sub {unshift (@Texi2HTML::Config::PREPEND_DIRS, $_[1]);},
  2707. 'verbose' => 'prepend $s to the @include search path',
  2708. };
  2709. $T2H_OPTIONS -> {'number-sections'} =
  2710. {
  2711. 'type' => '!',
  2712. 'linkage' => sub {set_from_cmdline('NUMBER_SECTIONS', $_[1]);},
  2713. 'verbose' => 'output chapter and sectioning numbers.',
  2714. };
  2715. $T2H_OPTIONS -> {'number-footnotes'} =
  2716. {
  2717. 'type' => '!',
  2718. 'linkage' => sub {set_from_cmdline('NUMBER_FOOTNOTES', $_[1]);},
  2719. 'verbose' => 'output footnote numbers.',
  2720. };
  2721. $T2H_OPTIONS -> {'node-files'} =
  2722. {
  2723. 'type' => '!',
  2724. 'linkage' => sub {set_from_cmdline('NODE_FILES', $_[1]);},
  2725. 'verbose' => 'produce one file per node for cross references'
  2726. };
  2727. $T2H_OPTIONS -> {'footnote-style|s'} =
  2728. {
  2729. 'type' => '=s',
  2730. 'linkage' => sub {set_footnote_style ($_[1], 1);},
  2731. 'verbose' => 'output footnotes separate|end',
  2732. };
  2733. $T2H_OPTIONS -> {'split'} =
  2734. {
  2735. 'type' => '=s',
  2736. 'linkage' => sub {set_from_cmdline('SPLIT', $_[1])},
  2737. 'verbose' => 'split document on section|chapter|node else no splitting',
  2738. };
  2739. $T2H_OPTIONS -> {'no-split'} =
  2740. {
  2741. 'type' => '!',
  2742. 'linkage' => sub {set_from_cmdline('SPLIT', ''); set_from_cmdline('SPLIT_SIZE', undef);},
  2743. 'verbose' => 'no splitting of document',
  2744. 'noHelp' => 1,
  2745. };
  2746. $T2H_OPTIONS -> {'headers'} =
  2747. {
  2748. 'type' => '!',
  2749. 'linkage' => sub {
  2750. set_from_cmdline('HEADERS', $_[1]);
  2751. set_from_cmdline('SHOW_MENU', $_[1]);
  2752. Texi2HTML::Config::t2h_default_load_format('plaintext', 1)
  2753. if (!$_[1] and defined($Texi2HTML::Config::OUTPUT_FORMAT) and $Texi2HTML::Config::OUTPUT_FORMAT eq 'info');
  2754. },
  2755. 'verbose' => 'output navigation headers for each section',
  2756. };
  2757. $T2H_OPTIONS -> {'output|out|o'} =
  2758. {
  2759. 'type' => '=s',
  2760. 'linkage' => sub {set_output($_[1], 1);},
  2761. 'verbose' => 'output goes to $s (directory if split)',
  2762. };
  2763. $T2H_OPTIONS -> {'no-validate|no-pointer-validate'} =
  2764. {
  2765. 'type' => '',
  2766. 'linkage' => sub {set_from_cmdline('novalidate',$_[1])},
  2767. 'verbose' => 'suppress node cross-reference validation',
  2768. };
  2769. $T2H_OPTIONS -> {'no-warn'} =
  2770. {
  2771. 'type' => '',
  2772. 'linkage' => sub {set_from_cmdline('NO_WARN', $_[1]);},
  2773. 'verbose' => 'suppress warnings (but not errors).'
  2774. };
  2775. $T2H_OPTIONS -> {'verbose'} = 0;
  2776. $T2H_OPTIONS -> {'verbose|v'} =
  2777. {
  2778. 'type' => '!',
  2779. 'linkage' => sub {set_from_cmdline('VERBOSE', $_[1]); add_to_texi2dvi_args('--verbose'); },
  2780. 'verbose' => 'print progress info to stdout',
  2781. };
  2782. $T2H_OPTIONS -> {'document-language'} =
  2783. {
  2784. 'type' => '=s',
  2785. 'linkage' => sub {
  2786. warn_unknown_language ($_[1]);
  2787. set_from_cmdline('documentlanguage', $_[1])
  2788. },
  2789. 'verbose' => 'use $s as document language',
  2790. };
  2791. $T2H_OPTIONS -> {'D'} =
  2792. {
  2793. 'type' => '=s',
  2794. 'linkage' => sub {$value_initial{$_[1]} = 1;},
  2795. 'verbose' => 'equivalent to Texinfo "@set $s 1"',
  2796. 'noHelp' => 1,
  2797. };
  2798. $T2H_OPTIONS -> {'U'} =
  2799. {
  2800. 'type' => '=s',
  2801. 'linkage' => sub {delete $value_initial{$_[1]};},
  2802. 'verbose' => 'equivalent to Texinfo "@clear $s"',
  2803. 'noHelp' => 1,
  2804. };
  2805. $T2H_OPTIONS -> {'init-file'} =
  2806. {
  2807. 'type' => '=s',
  2808. 'linkage' => \&load_init_file,
  2809. 'verbose' => 'load init file $s'
  2810. };
  2811. $T2H_OPTIONS -> {'set-init-variable'} =
  2812. {
  2813. 'type' => '=s',
  2814. 'linkage' => sub { my $var_val = $_[1];
  2815. if ($var_val =~ s/^(\w+)\s*=?\s*//)
  2816. {
  2817. my $var = $1;
  2818. my $value = $var_val;
  2819. if ($value =~ /^undef$/i)
  2820. {
  2821. $value = undef;
  2822. }
  2823. set_from_cmdline ($var, $value);
  2824. }
  2825. },
  2826. 'verbose' => 'set an init file variable to a value'
  2827. };
  2828. $T2H_OPTIONS -> {'css-include'} =
  2829. {
  2830. 'type' => '=s',
  2831. 'linkage' => \@Texi2HTML::Config::CSS_FILES,
  2832. 'verbose' => 'use css file $s'
  2833. };
  2834. $T2H_OPTIONS -> {'css-ref'} =
  2835. {
  2836. 'type' => '=s',
  2837. 'linkage' => \@Texi2HTML::Config::CSS_REFS,
  2838. 'verbose' => 'generate reference to the CSS URL $s'
  2839. };
  2840. $T2H_OPTIONS -> {'transliterate-file-names'} =
  2841. {
  2842. 'type' => '!',
  2843. 'linkage' => sub {set_from_cmdline('TRANSLITERATE_FILE_NAMES', $_[1]);},
  2844. 'verbose' => 'produce file names in ASCII transliteration',
  2845. };
  2846. $T2H_OPTIONS -> {'error-limit|e'} =
  2847. {
  2848. 'type' => '=i',
  2849. 'linkage' => sub {set_from_cmdline('ERROR_LIMIT', $_[1]);},
  2850. 'verbose' => 'quit after NUM errors (default '.get_conf('ERROR_LIMIT').').',
  2851. };
  2852. $T2H_OPTIONS -> {'split-size'} =
  2853. {
  2854. 'type' => '=s',
  2855. 'linkage' => sub {set_from_cmdline('SPLIT_SIZE', $_[1])},
  2856. 'verbose' => 'split Info files at size s (default '.get_conf('SPLIT_SIZE').').',
  2857. };
  2858. $T2H_OPTIONS -> {'paragraph-indent|p'} =
  2859. {
  2860. 'type' => '=s',
  2861. 'linkage' => sub {set_paragraphindent($_[1], 1);},
  2862. 'verbose' => "indent Info paragraphs by VAL spaces (default ".get_conf('paragraphindent').").
  2863. If VAL is `none', do not indent; if VAL is
  2864. `asis', preserve existing indentation.",
  2865. };
  2866. $T2H_OPTIONS -> {'fill-column|f'} =
  2867. {
  2868. 'type' => '=i',
  2869. 'linkage' => sub {set_from_cmdline('FILLCOLUMN',$_[1]);},
  2870. 'verbose' => "break Info lines at NUM characters (default ".get_conf('FILLCOLUMN').")",
  2871. };
  2872. $T2H_OPTIONS -> {'enable-encoding'} =
  2873. {
  2874. 'type' => '',
  2875. 'linkage' => sub {set_from_cmdline('ENABLE_ENCODING', $_[1]);},
  2876. 'verbose' => 'override --disable-encoding (default in Info).',
  2877. };
  2878. $T2H_OPTIONS -> {'disable-encoding'} =
  2879. {
  2880. 'type' => '',
  2881. 'linkage' => sub {set_from_cmdline('ENABLE_ENCODING', 0);},
  2882. 'verbose' => 'do not output accented and special characters
  2883. in Info output based on @documentencoding.',
  2884. };
  2885. $T2H_OPTIONS -> {'internal-links'} =
  2886. {
  2887. 'type' => '=s',
  2888. 'linkage' => sub {set_from_cmdline('INTERNAL_LINKS', $_[1]);},
  2889. 'verbose' => 'produce list of internal links in FILE.'
  2890. };
  2891. $T2H_OPTIONS -> {'force|F'} =
  2892. { 'type' => '!',
  2893. 'linkage' => sub {set_from_cmdline('FORCE', $_[1]);},
  2894. 'verbose' => 'preserve output even if errors.'
  2895. };
  2896. $T2H_OPTIONS -> {'commands-in-node-names'} =
  2897. {
  2898. 'type' => '!',
  2899. 'verbose' => 'Always set',
  2900. 'noHelp' => 1
  2901. };
  2902. $T2H_OPTIONS -> {'output-indent'} =
  2903. {
  2904. 'type' => '=i',
  2905. 'verbose' => 'This option used to indent XML, it is ignored',
  2906. 'noHelp' => 1
  2907. };
  2908. $T2H_OPTIONS -> {'program'} =
  2909. {
  2910. 'type' => '=s',
  2911. 'linkage' => sub {set_config_init_dirs_output($_[1]);},
  2912. 'verbose' => 'Call as $s, setting corresponding defaults'
  2913. };
  2914. $T2H_OPTIONS -> {'reference-limit' } =
  2915. {
  2916. 'type' => '=i',
  2917. 'verbose' => 'Does nothing, retained for backward compatibility',
  2918. 'noHelp' => 2
  2919. };
  2920. #$T2H_OPTIONS -> {'command'} =
  2921. #{
  2922. # 'type' => '=s',
  2923. # 'linkage' => \@Texi2HTML::Config::COMMANDS,
  2924. # 'verbose' => 'insert CMD in copy of input file'
  2925. #};
  2926. $T2H_OPTIONS -> {'Xopt'} =
  2927. {
  2928. 'type' => '=s',
  2929. 'linkage' => \@Texi2HTML::Config::TEXI2DVI_ARGUMENTS,
  2930. 'verbose' => 'pass argument to the dvi/pdf converter.',
  2931. };
  2932. $T2H_OPTIONS -> {'batch'} =
  2933. {
  2934. 'type' => '',
  2935. 'linkage' => sub {set_from_cmdline('BATCH', $_[1]); add_to_texi2dvi_args('--'.$_[0]);},
  2936. 'noHelp' => 2
  2937. };
  2938. $T2H_OPTIONS -> {'silent|quiet'} =
  2939. {
  2940. 'type' => '',
  2941. 'linkage' => sub {set_from_cmdline('SILENT', $_[1]); add_to_texi2dvi_args('--'.$_[0]);},
  2942. 'noHelp' => 2
  2943. };
  2944. my $call_texi2dvi = 0;
  2945. foreach my $output_format (keys(%Texi2HTML::Config::output_format_names))
  2946. {
  2947. next if (defined($Texi2HTML::Config::DEFAULT_OUTPUT_FORMAT) and $output_format eq $Texi2HTML::Config::DEFAULT_OUTPUT_FORMAT);
  2948. my $linkage;
  2949. if ($Texi2HTML::Config::texi2dvi_formats{$output_format})
  2950. {
  2951. $linkage = sub {add_to_texi2dvi_args('--'.$_[0]); $call_texi2dvi = 1;
  2952. Texi2HTML::Config::t2h_default_load_format($_[0], 1);};
  2953. }
  2954. else
  2955. {
  2956. $linkage = sub {Texi2HTML::Config::t2h_default_load_format($_[0], 1);};
  2957. }
  2958. $T2H_OPTIONS -> {$output_format} =
  2959. {
  2960. 'type' => '',
  2961. 'linkage' => $linkage,
  2962. 'verbose' => "output $Texi2HTML::Config::output_format_names{$output_format} rather than $Texi2HTML::Config::output_format_names{$Texi2HTML::Config::DEFAULT_OUTPUT_FORMAT}.",
  2963. }
  2964. };
  2965. $T2H_OPTIONS -> {$Texi2HTML::Config::DEFAULT_OUTPUT_FORMAT} =
  2966. {
  2967. 'type' => '',
  2968. 'linkage' => sub {Texi2HTML::Config::t2h_default_load_format($_[0], 1);},
  2969. 'verbose' => "output default format.",
  2970. 'noHelp' => 2
  2971. };
  2972. $T2H_OPTIONS -> {'debug'} =
  2973. {
  2974. 'type' => '=i',
  2975. 'linkage' => sub {set_from_cmdline('DEBUG', $_[1]), add_to_texi2dvi_args('--'.$_[0]); },
  2976. 'verbose' => 'output debuging information',
  2977. 'noHelp' => 1,
  2978. };
  2979. ##
  2980. ## obsolete cmd line options
  2981. ##
  2982. my $T2H_OBSOLETE_OPTIONS;
  2983. $T2H_OBSOLETE_OPTIONS -> {'subdir'} =
  2984. {
  2985. 'type' => '=s',
  2986. 'linkage' => sub {set_from_cmdline('SUBDIR', $_[1]);},
  2987. 'verbose' => 'put files in directory $s, not $cwd',
  2988. 'noHelp' => 1,
  2989. };
  2990. # actually a noop, since it is not used anywhere
  2991. $T2H_OBSOLETE_OPTIONS -> {'invisible'} =
  2992. {
  2993. 'type' => '=s',
  2994. 'verbose' => 'Not used',
  2995. 'noHelp' => 2,
  2996. };
  2997. $T2H_OBSOLETE_OPTIONS -> {'toc-links'} =
  2998. {
  2999. 'type' => '!',
  3000. 'linkage' => sub {set_from_cmdline('TOC_LINKS', $_[1]);},
  3001. 'verbose' => 'create links from headings to toc entries',
  3002. 'noHelp' => 1,
  3003. };
  3004. $T2H_OBSOLETE_OPTIONS -> {'short-ext'} =
  3005. {
  3006. 'type' => '!',
  3007. 'linkage' => sub {set_from_cmdline('SHORTEXTN', $_[1]);},
  3008. 'verbose' => 'use "htm" extension for output HTML files',
  3009. 'noHelp' => 1,
  3010. };
  3011. # FIXME this is not that helpful as a message, as reported by
  3012. # Jens Schleusener one could imagine that absolute paths are
  3013. # accepted.
  3014. $T2H_OBSOLETE_OPTIONS -> {'prefix'} =
  3015. {
  3016. 'type' => '=s',
  3017. 'linkage' => sub {set_from_cmdline('PREFIX', $_[1]);},
  3018. 'verbose' => 'use as prefix for output files, instead of <docname>',
  3019. 'noHelp' => 1,
  3020. };
  3021. $T2H_OBSOLETE_OPTIONS -> {'short-ref'} =
  3022. {
  3023. 'type' => '!',
  3024. 'linkage' => sub {set_from_cmdline('SHORT_REF', $_[1]);},
  3025. 'verbose' => 'if set, references are without section numbers',
  3026. 'noHelp' => 1,
  3027. };
  3028. $T2H_OBSOLETE_OPTIONS -> {'idx-sum'} =
  3029. {
  3030. 'type' => '!',
  3031. 'linkage' => sub {set_from_cmdline('IDX_SUMMARY', $_[1]);},
  3032. 'verbose' => 'if set, also output index summary',
  3033. 'noHelp' => 1,
  3034. };
  3035. $T2H_OBSOLETE_OPTIONS -> {'def-table'} =
  3036. {
  3037. 'type' => '!',
  3038. 'linkage' => sub {set_from_cmdline('DEF_TABLE', $_[1]);},
  3039. 'verbose' => 'if set, \@def.. are converted using tables.',
  3040. 'noHelp' => 1,
  3041. };
  3042. $T2H_OBSOLETE_OPTIONS -> {'ignore-preamble-text'} =
  3043. {
  3044. 'type' => '!',
  3045. 'linkage' => sub {set_from_cmdline('IGNORE_PREAMBLE_TEXT', $_[1]);},
  3046. 'verbose' => 'if set, ignore the text before @node and sectioning commands',
  3047. 'noHelp' => 1,
  3048. };
  3049. $T2H_OBSOLETE_OPTIONS -> {'html-xref-prefix'} =
  3050. {
  3051. 'type' => '=s',
  3052. 'linkage' => sub {set_from_cmdline('EXTERNAL_DIR', $_[1]);},
  3053. 'verbose' => '$s is the base dir for external manual references',
  3054. 'noHelp' => 1,
  3055. };
  3056. $T2H_OBSOLETE_OPTIONS -> {'l2h'} =
  3057. {
  3058. 'type' => '!',
  3059. 'linkage' => sub {set_from_cmdline('L2H', $_[1]);},
  3060. 'verbose' => 'if set, uses latex2html for @math and @tex',
  3061. 'noHelp' => 1,
  3062. };
  3063. $T2H_OBSOLETE_OPTIONS -> {'l2h-l2h'} =
  3064. {
  3065. 'type' => '=s',
  3066. 'linkage' => sub {set_from_cmdline('L2H_L2H', $_[1]);},
  3067. 'verbose' => 'program to use for latex2html translation',
  3068. 'noHelp' => 1,
  3069. };
  3070. $T2H_OBSOLETE_OPTIONS -> {'l2h-skip'} =
  3071. {
  3072. 'type' => '!',
  3073. 'linkage' => sub {set_from_cmdline('L2H_SKIP', $_[1]);},
  3074. 'verbose' => 'if set, tries to reuse previously latex2html output',
  3075. 'noHelp' => 1,
  3076. };
  3077. $T2H_OBSOLETE_OPTIONS -> {'l2h-tmp'} =
  3078. {
  3079. 'type' => '=s',
  3080. 'linkage' => sub {set_from_cmdline('L2H_TMP', $_[1]);},
  3081. 'verbose' => 'if set, uses $s as temporary latex2html directory',
  3082. 'noHelp' => 1,
  3083. };
  3084. $T2H_OBSOLETE_OPTIONS -> {'l2h-file'} =
  3085. {
  3086. 'type' => '=s',
  3087. 'linkage' => sub {set_from_cmdline('L2H_FILE', $_[1]);},
  3088. 'verbose' => 'if set, uses $s as latex2html init file',
  3089. 'noHelp' => 1,
  3090. };
  3091. $T2H_OBSOLETE_OPTIONS -> {'l2h-clean'} =
  3092. {
  3093. 'type' => '!',
  3094. 'linkage' => sub {set_from_cmdline('L2H_CLEAN', $_[1]);},
  3095. 'verbose' => 'if set, do not keep intermediate latex2html files for later reuse',
  3096. 'noHelp' => 1,
  3097. };
  3098. $T2H_OBSOLETE_OPTIONS -> {'use-nodes'} =
  3099. {
  3100. 'type' => '!',
  3101. 'linkage' => sub {set_from_cmdline('USE_NODES', $_[1]);},
  3102. 'verbose' => 'use nodes for sectioning',
  3103. 'noHelp' => 1,
  3104. };
  3105. $T2H_OBSOLETE_OPTIONS -> {'monolithic'} =
  3106. {
  3107. 'type' => '!',
  3108. 'linkage' => sub {set_from_cmdline('MONOLITHIC', $_[1]);},
  3109. 'verbose' => 'output only one file including ToC, About...',
  3110. 'noHelp' => 1
  3111. };
  3112. $T2H_OBSOLETE_OPTIONS -> {'top-file'} =
  3113. {
  3114. 'type' => '=s',
  3115. 'linkage' => sub {set_from_cmdline('TOP_FILE', $_[1]);},
  3116. 'verbose' => 'use $s as top file, instead of <docname>.html',
  3117. 'noHelp' => 1,
  3118. };
  3119. $T2H_OBSOLETE_OPTIONS -> {'toc-file'} =
  3120. {
  3121. 'type' => '=s',
  3122. 'linkage' => sub {set_from_cmdline('TOC_FILE', $_[1]);},
  3123. 'verbose' => 'use $s as ToC file, instead of <docname>_toc.html',
  3124. 'noHelp' => 1,
  3125. };
  3126. $T2H_OBSOLETE_OPTIONS -> {'frames'} =
  3127. {
  3128. 'type' => '!',
  3129. 'linkage' => sub {set_from_cmdline('FRAMES', $_[1])},
  3130. 'verbose' => 'output files which use HTML 4.0 frames (experimental)',
  3131. 'noHelp' => 1,
  3132. };
  3133. $T2H_OBSOLETE_OPTIONS -> {'menu'} =
  3134. {
  3135. 'type' => '!',
  3136. 'linkage' => sub {set_from_cmdline('SHOW_MENU', $_[1]);},
  3137. 'verbose' => 'output Texinfo menus',
  3138. 'noHelp' => 1,
  3139. };
  3140. $T2H_OBSOLETE_OPTIONS -> {'iso'} =
  3141. {
  3142. 'type' => 'iso',
  3143. 'linkage' => sub {Texi2HTML::Config::t2h_default_set_iso_symbols ($_[1], 1);},
  3144. 'verbose' => 'if set, entities are used for special symbols (like copyright, etc...) and quotes',
  3145. 'noHelp' => 1,
  3146. };
  3147. $T2H_OBSOLETE_OPTIONS -> {'doctype'} =
  3148. {
  3149. 'type' => '=s',
  3150. 'linkage' => sub {set_from_cmdline('DOCTYPE', $_[1]);},
  3151. 'verbose' => 'document type which is output in header of HTML files',
  3152. 'noHelp' => 1
  3153. };
  3154. $T2H_OBSOLETE_OPTIONS -> {'frameset-doctype'} =
  3155. {
  3156. 'type' => '=s',
  3157. 'linkage' => sub {set_from_cmdline('FRAMESET_DOCTYPE', $_[1]);},
  3158. 'verbose' => 'document type for HTML frameset documents',
  3159. 'noHelp' => 1
  3160. };
  3161. $T2H_OBSOLETE_OPTIONS -> {'test'} =
  3162. {
  3163. 'type' => '!',
  3164. 'linkage' => sub {set_from_cmdline('TEST', $_[1]);},
  3165. 'verbose' => 'use predefined information to avoid differences with reference files',
  3166. 'noHelp' => 1
  3167. };
  3168. $T2H_OBSOLETE_OPTIONS -> {'dump-texi'} =
  3169. {
  3170. 'type' => '!',
  3171. 'linkage' => sub {set_from_cmdline('DUMP_TEXI', $_[1]);},
  3172. 'verbose' => 'dump the output of first pass into a file with extension passfirst and exit',
  3173. 'noHelp' => 1
  3174. };
  3175. $T2H_OBSOLETE_OPTIONS -> {'expand'} =
  3176. {
  3177. 'type' => '=s',
  3178. 'linkage' => sub {Texi2HTML::Config::set_expansion($_[1], 1);},
  3179. 'verbose' => 'Expand <s> section of texinfo source',
  3180. 'noHelp' => 1,
  3181. };
  3182. $T2H_OBSOLETE_OPTIONS -> {'no-expand'} =
  3183. {
  3184. 'type' => '=s',
  3185. 'linkage' => sub {Texi2HTML::Config::set_expansion ($_[1], 0);},
  3186. 'verbose' => 'Don\'t expand the given section of texinfo source',
  3187. };
  3188. $T2H_OBSOLETE_OPTIONS -> {'noexpand'} =
  3189. {
  3190. 'type' => '=s',
  3191. 'linkage' => $T2H_OBSOLETE_OPTIONS->{'no-expand'}->{'linkage'},
  3192. 'verbose' => $T2H_OBSOLETE_OPTIONS->{'no-expand'}->{'verbose'},
  3193. 'noHelp' => 1,
  3194. };
  3195. $T2H_OBSOLETE_OPTIONS -> {'out-file'} =
  3196. {
  3197. 'type' => '=s',
  3198. 'linkage' => sub {set_from_cmdline('OUTFILE', $_[1]); set_from_cmdline('SPLIT', '');},
  3199. 'verbose' => 'if set, all HTML output goes into file $s, obsoleted by "-output" with different semantics',
  3200. 'noHelp' => 2
  3201. };
  3202. $T2H_OBSOLETE_OPTIONS -> {'lang'} =
  3203. {
  3204. 'type' => '=s',
  3205. 'linkage' => sub {set_from_cmdline('documentlanguage', $_[1])},
  3206. 'verbose' => 'obsolete, use "--document-language" instead',
  3207. 'noHelp' => 2
  3208. };
  3209. $T2H_OBSOLETE_OPTIONS -> {'separated-footnotes'} =
  3210. {
  3211. 'type' => '!',
  3212. 'linkage' => sub {my $style = 'separate'; $style = 'end' if !$_[1]; set_footnote_style ($style, 1);},
  3213. 'verbose' => 'obsolete, use "--footnote-style" instead',
  3214. 'noHelp' => 2
  3215. };
  3216. $T2H_OBSOLETE_OPTIONS -> {'Verbose'} =
  3217. {
  3218. 'type' => '!',
  3219. linkage=> sub {set_from_cmdline('VERBOSE', $_[1]);},
  3220. 'verbose' => 'obsolete, use "--verbose" instead',
  3221. 'noHelp' => 2
  3222. };
  3223. $T2H_OBSOLETE_OPTIONS -> {init_file} =
  3224. {
  3225. 'type' => '=s',
  3226. 'linkage' => \&load_init_file,
  3227. 'verbose' => 'obsolete, use "-init-file" instead',
  3228. 'noHelp' => 2
  3229. };
  3230. $T2H_OBSOLETE_OPTIONS -> {l2h_clean} =
  3231. {
  3232. 'type' => '!',
  3233. 'linkage' => sub {set_from_cmdline('L2H_CLEAN', $_[1]);},
  3234. 'verbose' => 'obsolete, use "-l2h-clean" instead',
  3235. 'noHelp' => 2,
  3236. };
  3237. $T2H_OBSOLETE_OPTIONS -> {l2h_l2h} =
  3238. {
  3239. 'type' => '=s',
  3240. 'linkage' => sub {set_from_cmdline('L2H_L2H', $_[1]);},
  3241. 'verbose' => 'obsolete, use "-l2h-l2h" instead',
  3242. 'noHelp' => 2
  3243. };
  3244. $T2H_OBSOLETE_OPTIONS -> {l2h_skip} =
  3245. {
  3246. 'type' => '!',
  3247. 'linkage' => sub {set_from_cmdline('L2H_SKIP', $_[1]);},
  3248. 'verbose' => 'obsolete, use "-l2h-skip" instead',
  3249. 'noHelp' => 2
  3250. };
  3251. $T2H_OBSOLETE_OPTIONS -> {l2h_tmp} =
  3252. {
  3253. 'type' => '=s',
  3254. 'linkage' => sub {set_from_cmdline('L2H_TMP', $_[1]);},
  3255. 'verbose' => 'obsolete, use "-l2h-tmp" instead',
  3256. 'noHelp' => 2
  3257. };
  3258. $T2H_OBSOLETE_OPTIONS -> {out_file} =
  3259. {
  3260. 'type' => '=s',
  3261. 'linkage' => sub {set_from_cmdline('OUTFILE', $_[1]); set_from_cmdline('SPLIT', '');},
  3262. 'verbose' => 'obsolete, use "-out-file" instead',
  3263. 'noHelp' => 2
  3264. };
  3265. $T2H_OBSOLETE_OPTIONS -> {short_ref} =
  3266. {
  3267. 'type' => '!',
  3268. 'linkage' => sub {set_from_cmdline('SHORT_REF', $_[1]);},
  3269. 'verbose' => 'obsolete, use "-short-ref" instead',
  3270. 'noHelp' => 2
  3271. };
  3272. $T2H_OBSOLETE_OPTIONS -> {idx_sum} =
  3273. {
  3274. 'type' => '!',
  3275. 'linkage' => sub {set_from_cmdline('IDX_SUMMARY', $_[1]);},
  3276. 'verbose' => 'obsolete, use "-idx-sum" instead',
  3277. 'noHelp' => 2
  3278. };
  3279. $T2H_OBSOLETE_OPTIONS -> {def_table} =
  3280. {
  3281. 'type' => '!',
  3282. 'linkage' => sub {set_from_cmdline('DEF_TABLE', $_[1]);},
  3283. 'verbose' => 'obsolete, use "-def-table" instead',
  3284. 'noHelp' => 2
  3285. };
  3286. $T2H_OBSOLETE_OPTIONS -> {short_ext} =
  3287. {
  3288. 'type' => '!',
  3289. 'linkage' => sub {set_from_cmdline('SHORTEXTN', $_[1]);},
  3290. 'verbose' => 'obsolete, use "-short-ext" instead',
  3291. 'noHelp' => 2
  3292. };
  3293. $T2H_OBSOLETE_OPTIONS -> {sec_nav} =
  3294. {
  3295. 'type' => '!',
  3296. 'linkage' => sub {set_from_cmdline('HEADERS', $_[1]);},
  3297. 'verbose' => 'obsolete, use "-headers" instead',
  3298. 'noHelp' => 2
  3299. };
  3300. $T2H_OBSOLETE_OPTIONS -> {'sec-nav'} =
  3301. {
  3302. 'type' => '!',
  3303. 'linkage' => sub {set_from_cmdline('HEADERS', $_[1]);},
  3304. 'verbose' => 'obsolete, use "--header" instead',
  3305. 'noHelp' => 2
  3306. };
  3307. $T2H_OBSOLETE_OPTIONS -> {top_file} =
  3308. {
  3309. 'type' => '=s',
  3310. 'linkage' => sub {set_from_cmdline('TOP_FILE', $_[1]);},
  3311. 'verbose' => 'obsolete, use "-top-file" instead',
  3312. 'noHelp' => 2
  3313. };
  3314. $T2H_OBSOLETE_OPTIONS -> {toc_file} =
  3315. {
  3316. 'type' => '=s',
  3317. 'linkage' => sub {set_from_cmdline('TOC_FILE', $_[1]);},
  3318. 'verbose' => 'obsolete, use "-toc-file" instead',
  3319. 'noHelp' => 2
  3320. };
  3321. $T2H_OBSOLETE_OPTIONS -> {glossary} =
  3322. {
  3323. 'type' => '!',
  3324. 'verbose' => "this does nothing",
  3325. 'noHelp' => 2,
  3326. };
  3327. $T2H_OBSOLETE_OPTIONS -> {check} =
  3328. {
  3329. 'type' => '!',
  3330. 'linkage' => sub {exit 0;},
  3331. 'verbose' => "exit without doing anything",
  3332. 'noHelp' => 2,
  3333. };
  3334. $T2H_OBSOLETE_OPTIONS -> {dump_texi} =
  3335. {
  3336. 'type' => '!',
  3337. 'linkage' => sub {set_from_cmdline('DUMP_TEXI', $_[1]);},
  3338. 'verbose' => 'obsolete, use "-dump-texi" instead',
  3339. 'noHelp' => 1
  3340. };
  3341. $T2H_OBSOLETE_OPTIONS -> {frameset_doctype} =
  3342. {
  3343. 'type' => '=s',
  3344. 'linkage' => sub {set_from_cmdline('FRAMESET_DOCTYPE', $_[1]);},
  3345. 'verbose' => 'obsolete, use "-frameset-doctype" instead',
  3346. 'noHelp' => 2
  3347. };
  3348. $T2H_OBSOLETE_OPTIONS -> {use_acc} =
  3349. {
  3350. 'type' => '!',
  3351. 'verbose' => 'obsolete, set to true unconditionnaly',
  3352. 'noHelp' => 2
  3353. };
  3354. $T2H_OBSOLETE_OPTIONS -> {expandinfo} =
  3355. {
  3356. 'type' => '!',
  3357. 'linkage' => sub {push @Texi2HTML::Config::EXPAND, 'info';},
  3358. 'verbose' => 'obsolete, use "--ifinfo" instead',
  3359. 'noHelp' => 2,
  3360. };
  3361. $T2H_OBSOLETE_OPTIONS -> {expandtex} =
  3362. {
  3363. 'type' => '!',
  3364. 'linkage' => sub {push @Texi2HTML::Config::EXPAND, 'tex';},
  3365. 'verbose' => 'obsolete, use "--iftex" instead',
  3366. 'noHelp' => 2,
  3367. };
  3368. $T2H_OBSOLETE_OPTIONS -> {split_node} =
  3369. {
  3370. 'type' => '!',
  3371. 'linkage' => sub{set_from_cmdline('SPLIT', 'section');},
  3372. 'verbose' => 'obsolete, use "-split section" instead',
  3373. 'noHelp' => 2,
  3374. };
  3375. $T2H_OBSOLETE_OPTIONS -> {split_chapter} =
  3376. {
  3377. 'type' => '!',
  3378. 'linkage' => sub{set_from_cmdline('SPLIT', 'chapter');},
  3379. 'verbose' => 'obsolete, use "-split chapter" instead',
  3380. 'noHelp' => 2,
  3381. };
  3382. $T2H_OBSOLETE_OPTIONS -> {no_verbose} =
  3383. {
  3384. 'type' => '!',
  3385. 'linkage' => sub{set_from_cmdline('VERBOSE', 0);},
  3386. 'verbose' => 'obsolete, use -noverbose instead',
  3387. 'noHelp' => 2,
  3388. };
  3389. $T2H_OBSOLETE_OPTIONS -> {output_file} =
  3390. {
  3391. 'type' => '=s',
  3392. 'linkage' => sub {set_from_cmdline('OUTFILE', $_[1]); set_from_cmdline('SPLIT','');},
  3393. 'verbose' => 'obsolete, use --out-file instead',
  3394. 'noHelp' => 2
  3395. };
  3396. $T2H_OBSOLETE_OPTIONS -> {section_navigation} =
  3397. {
  3398. 'type' => '!',
  3399. 'linkage' => sub {set_from_cmdline('HEADERS', $_[1]);},
  3400. 'verbose' => 'obsolete, use --sec-nav instead',
  3401. 'noHelp' => 2,
  3402. };
  3403. # read initialzation from $sysconfdir/texi2htmlrc or $HOME/.texi2htmlrc
  3404. # (this is obsolete). Obsoleted in 1.68 (March 20 2004).
  3405. my @rc_files = ();
  3406. push @rc_files, "$sysconfdir/texi2htmlrc" if defined($sysconfdir);
  3407. push @rc_files, "$ENV{'HOME'}/.texi2htmlrc" if (defined($ENV{'HOME'}));
  3408. foreach my $i (@rc_files)
  3409. {
  3410. if (-e $i and -r $i)
  3411. {
  3412. print STDERR "# reading initialization file from $i\n"
  3413. if ($T2H_VERBOSE);
  3414. print STDERR "Reading config from $i is obsolete, use texi2html/$conf_file_name instead\n";
  3415. Texi2HTML::Config::load($i);
  3416. }
  3417. }
  3418. # read initialization files
  3419. foreach my $file (locate_init_file($conf_file_name, [ reverse(@program_config_dirs) ], 1))
  3420. {
  3421. print STDERR "# reading initialization file from $file\n" if ($T2H_VERBOSE);
  3422. Texi2HTML::Config::load($file);
  3423. }
  3424. #+++############################################################################
  3425. # #
  3426. # parse command-line options
  3427. # #
  3428. #---############################################################################
  3429. # options known by makeinfo (+version, help and if*)
  3430. #my @makeinfo_options = ('error-limit', 'document-language',
  3431. #'force', 'help', 'no-validate', 'no-warn', 'verbose', 'docbook', 'html',
  3432. #'xml', 'plaintext', 'macro-expand', 'headers', 'no-split',
  3433. #'number-sections', 'output', 'disable-encoding', 'enable-encoding',
  3434. #'fill-column', 'footnote-style', 'paragraph-indent', 'split-size',
  3435. #'css-include', 'css-ref', 'internal-links', 'transliterate-file-names',
  3436. #'output-indent', 'number-footnotes', 'D', 'I', 'P', 'U');
  3437. # always used, even though they are not in makeinfo in C.
  3438. # split is in makeinfo in C, as --no-split.
  3439. # 'conf-dir', 'init-file' options have to be taken into account for proper
  3440. # functionning.
  3441. #my @basic_options = ('conf-dir', 'init-file',
  3442. #'split', 'program', 'set-init-variable');
  3443. # --command=CMD insert CMD in copy of input file
  3444. my $makeinfo_help =
  3445. sprintf(__("Usage: %s [OPTION]... TEXINFO-FILE...\n"), $real_command_name)
  3446. ."\n".
  3447. __("Translate Texinfo source documentation to various other formats, by default
  3448. Info files suitable for reading online with Emacs or standalone GNU Info.\n")
  3449. ."\n";
  3450. $makeinfo_help .= sprintf(__("General options:
  3451. --error-limit=NUM quit after NUM errors (default %d).
  3452. --document-language=STR locale to use in translating Texinfo keywords
  3453. for the output document (default C).
  3454. --force preserve output even if errors.
  3455. --help display this help and exit.
  3456. --no-validate suppress node cross-reference validation.
  3457. --no-warn suppress warnings (but not errors).
  3458. --conf-dir=DIR search also for initialization files in DIR.
  3459. --init-file=FILE load FILE to modify the default behaviour.
  3460. --set-init-variable VAR=VAL set configuration variable VAR to VAL.
  3461. -v, --verbose explain what is being done.
  3462. --version display version information and exit.\n"), get_conf('ERROR_LIMIT'))
  3463. ."\n";
  3464. $makeinfo_help .= __("Output format selection (default is to produce Info):
  3465. --docbook output Docbook XML rather than Info.
  3466. --html output HTML rather than Info.
  3467. --xml output Texinfo XML rather than Info.
  3468. --plaintext output plain text rather than Info.\n")
  3469. ."\n";
  3470. $makeinfo_help .= __("General output options:
  3471. -E, --macro-expand=FILE output macro-expanded source to FILE,
  3472. ignoring any \@setfilename.
  3473. --no-headers suppress node separators, Node: lines, and menus
  3474. from Info output (thus producing plain text)
  3475. or from HTML (thus producing shorter output);
  3476. also, write to standard output by default if
  3477. producing Info.
  3478. --split=SPLIT split at SPLIT, where SPLIT may be chapter,
  3479. section or node if output supports splitting.
  3480. --no-split suppress the splitting of Info or HTML output,
  3481. generate only one output file.
  3482. --number-sections output chapter and sectioning numbers.
  3483. -o, --output=FILE output to FILE (or directory if split).
  3484. If not split and FILE is a directory, put the
  3485. resulting files in FILE.\n")
  3486. ."\n";
  3487. $makeinfo_help .= sprintf(__("Options for Info and plain text:
  3488. --disable-encoding do not output accented and special characters
  3489. in Info output based on \@documentencoding.
  3490. --enable-encoding override --disable-encoding (default).
  3491. --fill-column=NUM break Info lines at NUM characters (default %d).
  3492. --footnote-style=STYLE output footnotes in Info according to STYLE:
  3493. `separate' to put them in their own node;
  3494. `end' to put them at the end of the node, in
  3495. which they are defined (this is the default).
  3496. --paragraph-indent=VAL indent Info paragraphs by VAL spaces (default %d).
  3497. If VAL is `none', do not indent; if VAL is
  3498. `asis', preserve existing indentation.
  3499. --split-size=NUM split Info files at size NUM (default %d).\n"),
  3500. get_conf('FILLCOLUMN'), get_conf('paragraphindent'), get_conf('SPLIT_SIZE'))
  3501. ."\n";
  3502. $makeinfo_help .= __("Options for HTML:
  3503. --css-include=FILE include FILE in HTML <style> output;
  3504. read stdin if FILE is -.
  3505. --css-ref=URL generate reference to a CSS file.
  3506. --internal-links=FILE produce list of internal links in FILE.
  3507. --transliterate-file-names
  3508. produce file names in ASCII transliteration.
  3509. --node-files produce redirection files for nodes and
  3510. anchors. Default is set only if split.\n")
  3511. ."\n";
  3512. $makeinfo_help .= __("Options for XML and Docbook:
  3513. --output-indent=VAL does nothing, retained for compatibility.\n")
  3514. ."\n";
  3515. # This is ignored
  3516. #Options for XML and Docbook:
  3517. # --output-indent=VAL indent XML elements by VAL spaces (default 2).
  3518. # If VAL is 0, ignorable whitespace is dropped.
  3519. # Always set and ignored
  3520. # --commands-in-node-names allow \@ commands in node names.
  3521. #
  3522. $makeinfo_help .= __("Input file options:
  3523. --commands-in-node-names does nothing, retained for compatibility.
  3524. -D VAR define the variable VAR, as with \@set.
  3525. -I DIR append DIR to the \@include search path.
  3526. -P DIR prepend DIR to the \@include search path.
  3527. -U VAR undefine the variable VAR, as with \@clear.\n")
  3528. ."\n";
  3529. $makeinfo_help .= __("Conditional processing in input:
  3530. --ifdocbook process \@ifdocbook and \@docbook even if
  3531. not generating Docbook.
  3532. --ifhtml process \@ifhtml and \@html even if not generating HTML.
  3533. --ifinfo process \@ifinfo even if not generating Info.
  3534. --ifplaintext process \@ifplaintext even if not generating plain text.
  3535. --iftex process \@iftex and \@tex; implies --no-split.
  3536. --ifxml process \@ifxml and \@xml.
  3537. --no-ifdocbook do not process \@ifdocbook and \@docbook text.
  3538. --no-ifhtml do not process \@ifhtml and \@html text.
  3539. --no-ifinfo do not process \@ifinfo text.
  3540. --no-ifplaintext do not process \@ifplaintext text.
  3541. --no-iftex do not process \@iftex and \@tex text.
  3542. --no-ifxml do not process \@ifxml and \@xml text.
  3543. Also, for the --no-ifFORMAT options, do process \@ifnotFORMAT text.\n")
  3544. ."\n";
  3545. $makeinfo_help .= __(" The defaults for the \@if... conditionals depend on the output format:
  3546. if generating HTML, --ifhtml is on and the others are off;
  3547. if generating Info, --ifinfo is on and the others are off;
  3548. if generating plain text, --ifplaintext is on and the others are off;
  3549. if generating XML, --ifxml is on and the others are off.\n")
  3550. ."\n";
  3551. $makeinfo_help .= __("Examples:
  3552. makeinfo foo.texi write Info to foo's \@setfilename
  3553. makeinfo --html foo.texi write HTML to \@setfilename
  3554. makeinfo --xml foo.texi write Texinfo XML to \@setfilename
  3555. makeinfo --docbook foo.texi write DocBook XML to \@setfilename
  3556. makeinfo --no-headers foo.texi write plain text to standard output
  3557. makeinfo --html --no-headers foo.texi write html without node lines, menus
  3558. makeinfo --number-sections foo.texi write Info with numbered sections
  3559. makeinfo --no-split foo.texi write one Info file however big\n")
  3560. ."\n";
  3561. $makeinfo_help .= __("Email bug reports to bug-texinfo\@gnu.org,
  3562. general questions and discussion to help-texinfo\@gnu.org.
  3563. Texinfo home page: http://www.gnu.org/software/texinfo/") ."\n";
  3564. # parsing like texi2html:
  3565. my $T2H_USAGE_TEXT = <<EOT;
  3566. Usage: texi2html [OPTIONS] TEXINFO-FILE
  3567. Translates Texinfo source documentation to HTML.
  3568. EOT
  3569. my $options = new Getopt::MySimple;
  3570. $T2H_OPTIONS -> {'help'} = 0;
  3571. $T2H_OPTIONS -> {'help|h'} =
  3572. {
  3573. type => ':i',
  3574. default => '',
  3575. linkage => sub {$options->helpOptions($_[1]);
  3576. print "\nSend bugs and suggestions to <texi2html-bug\@nongnu.org>\n";
  3577. exit (0);},
  3578. verbose => "print help and exit"
  3579. };
  3580. # this avoids getOptions defining twice 'help' and 'version'.
  3581. $T2H_OBSOLETE_OPTIONS->{'help'} = 0;
  3582. $T2H_OBSOLETE_OPTIONS->{'version'} = 0;
  3583. $T2H_OBSOLETE_OPTIONS->{'verbose'} = 0;
  3584. if ($real_command_name eq 'texi2html')
  3585. {
  3586. # some older version of GetOpt::Long don't have
  3587. # Getopt::Long::Configure("pass_through")
  3588. eval {Getopt::Long::Configure("pass_through");};
  3589. my $Configure_failed = $@ && <<EOT;
  3590. **WARNING: Parsing of obsolete command-line options could have failed.
  3591. Consider to use only documented command-line options (run
  3592. 'texi2html --help 2' for a complete list) or upgrade to perl
  3593. version 5.005 or higher.
  3594. EOT
  3595. if (! $options->getOptions($T2H_OPTIONS, $T2H_USAGE_TEXT, "$THISVERSION\n"))
  3596. {
  3597. print STDERR "$Configure_failed" if $Configure_failed;
  3598. die $T2H_FAILURE_TEXT;
  3599. }
  3600. # Now that texi2html can process many files on the command line, this is
  3601. # not a good heuristic anymore. Not a big deal.
  3602. if (@ARGV > 1)
  3603. {
  3604. eval {Getopt::Long::Configure("no_pass_through");};
  3605. if (! $options->getOptions($T2H_OBSOLETE_OPTIONS, $T2H_USAGE_TEXT, "$THISVERSION\n"))
  3606. {
  3607. print STDERR "$Configure_failed" if $Configure_failed;
  3608. die $T2H_FAILURE_TEXT;
  3609. }
  3610. }
  3611. }
  3612. else
  3613. {
  3614. # changes how command lines are parsed, for example -init file.init
  3615. # doesn't work anymore.
  3616. Getopt::Long::Configure("gnu_getopt");
  3617. my $opts;
  3618. my @types;
  3619. foreach my $key (keys(%$T2H_OPTIONS))
  3620. {
  3621. next unless ($T2H_OPTIONS->{$key});
  3622. my $primary = $key;
  3623. $primary =~ s/\|.*//;
  3624. next if ($primary eq 'version' or $primary eq 'help');
  3625. #next if ($real_command_name eq 'makeinfo' and ! grep {$primary eq $_} (@makeinfo_options, @basic_options) and $primary !~ /^if/);
  3626. $opts->{$primary} = $T2H_OPTIONS->{$key}->{'linkage'} if defined($T2H_OPTIONS->{$key}->{'linkage'});
  3627. push @types, "$key$T2H_OPTIONS->{$key}->{'type'}";
  3628. }
  3629. $opts->{'version'} = sub {
  3630. print "$real_command_name (GNU texinfo) $THISVERSION\n\n";
  3631. printf __("Copyright (C) %s Free Software Foundation, Inc.
  3632. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  3633. This is free software: you are free to change and redistribute it.
  3634. There is NO WARRANTY, to the extent permitted by law.\n"), '2008';
  3635. exit 0;
  3636. };
  3637. $opts->{'help'} = sub {
  3638. print "$makeinfo_help";
  3639. exit 0;
  3640. };
  3641. push @types, ('version|V', 'help|h');
  3642. #foreach my $key (sort(keys(%$opts)))
  3643. #{
  3644. # #print STDERR "$key, $opts->{$key}\n";
  3645. # print "$key\n";
  3646. #}
  3647. #print STDERR "@types\n";
  3648. my $result_options = Getopt::Long::GetOptions ($opts, @types);
  3649. }
  3650. if (! $Texi2HTML::THISDOC{'format_from_command_line'} and defined($ENV{'TEXINFO_OUTPUT_FORMAT'}) and $ENV{'TEXINFO_OUTPUT_FORMAT'} ne '')
  3651. {
  3652. if ($Texi2HTML::Config::texi2dvi_formats{$ENV{'TEXINFO_OUTPUT_FORMAT'}})
  3653. {
  3654. add_to_texi2dvi_args("--$ENV{'TEXINFO_OUTPUT_FORMAT'}");
  3655. $call_texi2dvi = 1;
  3656. }
  3657. if (! Texi2HTML::Config::t2h_default_load_format($ENV{'TEXINFO_OUTPUT_FORMAT'}, 0))
  3658. {
  3659. warn sprintf(__("%s: Ignoring unrecognized TEXINFO_OUTPUT_FORMAT value `%s'.\n"), $real_command_name, $ENV{'TEXINFO_OUTPUT_FORMAT'});
  3660. }
  3661. }
  3662. # $T2H_DEBUG and $T2H_VERBOSE are shorthands
  3663. $T2H_DEBUG = get_conf('DEBUG');
  3664. $T2H_VERBOSE = get_conf('VERBOSE');
  3665. #
  3666. # read texi2html extensions (if any)
  3667. # It is obsolete (obsoleted by -init-file). we keep it for backward
  3668. # compatibility.
  3669. my $extensions = 'texi2html.ext'; # extensions in working directory
  3670. if (-f $extensions)
  3671. {
  3672. print STDERR "# reading extensions from $extensions\n" if $T2H_VERBOSE;
  3673. require($extensions);
  3674. }
  3675. my $progdir;
  3676. ($progdir = $0) =~ s/[^\/]+$//;
  3677. if ($progdir && ($progdir ne './'))
  3678. {
  3679. $extensions = "${progdir}texi2html.ext"; # extensions in texi2html directory
  3680. if (-f $extensions)
  3681. {
  3682. print STDERR "# reading extensions from $extensions\n" if $T2H_VERBOSE;
  3683. require($extensions);
  3684. }
  3685. }
  3686. if ($call_texi2dvi)
  3687. {
  3688. if (defined(get_conf('OUT')) and @ARGV > 1)
  3689. {
  3690. die sprintf(__('when generating %s, only one input FILE may be specified with -o'), $Texi2HTML::Config::output_format_names{$Texi2HTML::Config::DEFAULT_OUTPUT_FORMAT});
  3691. }
  3692. print STDERR "".join('|', (get_conf('TEXI2DVI'), @Texi2HTML::Config::TEXI2DVI_ARGUMENTS, @ARGV)) ."\n" if ($T2H_DEBUG or $T2H_VERBOSE);
  3693. exec { get_conf('TEXI2DVI') } (@Texi2HTML::Config::TEXI2DVI_ARGUMENTS, @ARGV);
  3694. }
  3695. #+++############################################################################
  3696. # #
  3697. # evaluation of cmd line options
  3698. # #
  3699. #---############################################################################
  3700. # set the default 'args' entry to normal for each style hash (and each command
  3701. # within)
  3702. my $name_index = -1;
  3703. my @hash_names = ('style_map', 'style_map_pre', 'style_map_texi', 'simple_format_style_map_texi');
  3704. foreach my $hash (\%Texi2HTML::Config::style_map, \%Texi2HTML::Config::style_map_pre, \%Texi2HTML::Config::style_map_texi, \%Texi2HTML::Config::simple_format_style_map_texi)
  3705. {
  3706. $name_index++;
  3707. my $name = $hash_names[$name_index]; # name associated with hash ref
  3708. foreach my $style (keys(%{$hash}))
  3709. {
  3710. next unless (ref($hash->{$style}) eq 'HASH');
  3711. $hash->{$style}->{'args'} = ['normal'] if (!exists($hash->{$style}->{'args'}));
  3712. die "Bug: args not defined, but existing, for $style in $name" if (!defined($hash->{$style}->{'args'}));
  3713. #print STDERR "DEFAULT($name, $hash) add normal as arg for $style ($hash->{$style}), $hash->{$style}->{'args'}\n";
  3714. }
  3715. }
  3716. # setup hashes used for html manual cross references in texinfo
  3717. my %cross_ref_texi_map = %Texi2HTML::Config::default_texi_map;
  3718. my %cross_transliterate_texi_map = %cross_ref_texi_map;
  3719. my %cross_ref_simple_map_texi = %Texi2HTML::Config::default_simple_map;
  3720. $cross_ref_simple_map_texi{"*"} = ' ';
  3721. my %cross_ref_style_map_texi = ();
  3722. my %cross_transliterate_style_map_texi = ();
  3723. Texi2HTML::Config::t2h_default_copy_style_map(\%Texi2HTML::Config::default_style_map_texi, \%cross_ref_style_map_texi);
  3724. Texi2HTML::Config::t2h_default_copy_style_map(\%Texi2HTML::Config::default_style_map_texi, \%cross_transliterate_style_map_texi);
  3725. # Fill in the %style_type hash, a hash associating style @-comand with
  3726. # the type, 'accent', real 'style', 'simple_style', or 'special'.
  3727. # 'simple_style' styles don't extend accross lines.
  3728. my %style_type = ();
  3729. my @simple_styles = ('ctrl', 'w', 'url','uref','indicateurl','email',
  3730. 'titlefont');
  3731. foreach my $style (keys(%Texi2HTML::Config::style_map))
  3732. {
  3733. if (exists $Texi2HTML::Config::command_type{$style})
  3734. {
  3735. $style_type{$style} = $Texi2HTML::Config::command_type{$style};
  3736. next;
  3737. }
  3738. if (ref($Texi2HTML::Config::style_map{$style} eq 'HASH'))
  3739. {
  3740. $style_type{$style} = $Texi2HTML::Config::style_map{$style}->{'type'}
  3741. if (exists($Texi2HTML::Config::style_map{$style}->{'type'}));
  3742. }
  3743. else
  3744. {
  3745. $style_type{$style} = 'simple_style' if (grep {$_ eq $style} @simple_styles);
  3746. }
  3747. $style_type{$style} = 'style' unless (defined($style_type{$style}));
  3748. }
  3749. foreach my $accent (keys(%Texi2HTML::Config::unicode_accents), 'tieaccent', 'dotless')
  3750. {
  3751. if (exists $Texi2HTML::Config::command_type{$accent})
  3752. {
  3753. $style_type{$accent} = $Texi2HTML::Config::command_type{$accent};
  3754. next;
  3755. }
  3756. $style_type{$accent} = 'accent';
  3757. }
  3758. foreach my $special ('footnote', 'ref', 'xref', 'pxref', 'inforef', 'anchor', 'image', 'hyphenation')
  3759. {
  3760. if (exists $Texi2HTML::Config::command_type{$special})
  3761. {
  3762. $style_type{$special} = $Texi2HTML::Config::command_type{$special};
  3763. next;
  3764. }
  3765. $style_type{$special} = 'special';
  3766. }
  3767. push (@Texi2HTML::Config::EXPAND, @Texi2HTML::Config::T2H_FORMAT_EXPAND);
  3768. # correct %Texi2HTML::Config::texi_formats_map based on command line and init
  3769. # variables
  3770. $Texi2HTML::Config::texi_formats_map{'menu'} = 'normal' if (get_conf('SHOW_MENU'));
  3771. foreach my $expanded (@Texi2HTML::Config::EXPAND)
  3772. {
  3773. $Texi2HTML::Config::texi_formats_map{"if$expanded"} = 1 if (exists($Texi2HTML::Config::texi_formats_map{"if$expanded"}));
  3774. next unless (exists($Texi2HTML::Config::texi_formats_map{$expanded}));
  3775. if (grep {$_ eq $expanded} @raw_regions)
  3776. {
  3777. $Texi2HTML::Config::texi_formats_map{$expanded} = 'raw';
  3778. }
  3779. else
  3780. {
  3781. $Texi2HTML::Config::texi_formats_map{$expanded} = 'normal';
  3782. }
  3783. }
  3784. # don't set set_no_line_macro for raw EXPAND formats
  3785. foreach my $key (keys(%Texi2HTML::Config::texi_formats_map))
  3786. {
  3787. unless ($Texi2HTML::Config::texi_formats_map{$key} eq 'raw')
  3788. {
  3789. set_no_line_macro($key, 1);
  3790. set_no_line_macro("end $key", 1);
  3791. }
  3792. }
  3793. # the remaining (not in @EXPAND) raw formats are set as 'raw' such that
  3794. # they are propagated to formatting functions, but
  3795. # they don't start paragraphs or preformatted.
  3796. foreach my $raw (@raw_regions)
  3797. {
  3798. if (!defined($Texi2HTML::Config::texi_formats_map{$raw}))
  3799. {
  3800. $Texi2HTML::Config::texi_formats_map{$raw} = 'raw';
  3801. $Texi2HTML::Config::format_in_paragraph{$raw} = 1;
  3802. set_no_line_macro($raw, 1);
  3803. set_no_line_macro("end $raw", 1);
  3804. }
  3805. }
  3806. # handle ifnot regions
  3807. foreach my $region (keys (%Texi2HTML::Config::texi_formats_map))
  3808. {
  3809. next if ($region =~ /^ifnot/);
  3810. if ($Texi2HTML::Config::texi_formats_map{$region} and $region =~ /^if(\w+)$/)
  3811. {
  3812. $Texi2HTML::Config::texi_formats_map{"ifnot$1"} = 0;
  3813. }
  3814. }
  3815. if ($T2H_VERBOSE)
  3816. {
  3817. print STDERR "# Expanded: ";
  3818. foreach my $text_macro (keys(%Texi2HTML::Config::texi_formats_map))
  3819. {
  3820. print STDERR "$text_macro " if ($Texi2HTML::Config::texi_formats_map{$text_macro});
  3821. }
  3822. print STDERR "\n";
  3823. }
  3824. # The following lines seems to be incorrect. We don't wat to set T2H_DEBUG
  3825. # everytime DUMP_TEXI is set.
  3826. #$T2H_DEBUG |= $DEBUG_TEXI if (get_conf('DUMP_TEXI'));
  3827. # no user provided USE_UNICODE, use configure provided
  3828. if (!defined(get_conf('USE_UNICODE')))
  3829. {
  3830. Texi2HTML::Config::set_default('USE_UNICODE', '@USE_UNICODE@');
  3831. }
  3832. # no user provided nor configured, run time test
  3833. if (get_conf('USE_UNICODE') eq 'unknown' or get_conf('USE_UNICODE') eq '@' .'USE_UNICODE@')
  3834. {
  3835. eval {
  3836. require Encode;
  3837. require Unicode::Normalize;
  3838. Encode->import('encode');
  3839. };
  3840. if ($@)
  3841. {
  3842. Texi2HTML::Config::set_default('USE_UNICODE', 0);
  3843. }
  3844. else
  3845. {
  3846. Texi2HTML::Config::set_default('USE_UNICODE', 1);
  3847. }
  3848. }
  3849. if (get_conf('USE_UNICODE'))
  3850. {
  3851. require Encode;
  3852. require Unicode::Normalize;
  3853. Encode->import('encode');
  3854. # use EastAsianWidth if USE_UNICODE is set
  3855. if ($0 =~ /\.pl$/)
  3856. { # use in-source EastAsianWidth when testing
  3857. unshift @INC, "$T2H_HOME/lib/Unicode-EastAsianWidth/lib";
  3858. }
  3859. elsif ($ENV{T2H_SOURCE_EASTASIANWIDTH})
  3860. {
  3861. unshift @INC, $ENV{T2H_SOURCE_EASTASIANWIDTH};
  3862. }
  3863. elsif ('@USE_EXTERNAL_EASTASIANWIDTH@' ne 'yes')
  3864. {
  3865. unshift @INC, "$pkgdatadir/lib/Unicode-EastAsianWidth/lib";
  3866. }
  3867. else
  3868. {
  3869. eval {
  3870. require Unicode::EastAsianWidth;
  3871. };
  3872. if ($@)
  3873. {
  3874. unshift @INC, "$pkgdatadir/lib/Unicode-EastAsianWidth/lib";
  3875. }
  3876. }
  3877. # unicode east asian character width tables.
  3878. require Unicode::EastAsianWidth;
  3879. }
  3880. if ($0 =~ /\.pl$/)
  3881. {
  3882. unshift @INC, "$T2H_HOME/lib/Text-Unidecode/lib";
  3883. }
  3884. elsif ('@USE_EXTERNAL_UNIDECODE@' ne 'yes')
  3885. {
  3886. unshift @INC, "$pkgdatadir/lib/Text-Unidecode/lib";
  3887. }
  3888. else
  3889. {
  3890. eval {
  3891. require Text::Unidecode;
  3892. };
  3893. if ($@)
  3894. {
  3895. unshift @INC, "$pkgdatadir/lib/Text-Unidecode/lib";
  3896. }
  3897. }
  3898. require Text::Unidecode;
  3899. Text::Unidecode->import('unidecode');
  3900. Texi2HTML::Config::set_default('USE_UNIDECODE', 1);
  3901. print STDERR "# USE_UNICODE ".get_conf('USE_UNICODE').", USE_UNIDECODE ".get_conf('USE_UNIDECODE')." \n"
  3902. if ($T2H_VERBOSE);
  3903. # Construct hashes used for cross references generation
  3904. # Do it now as the user may have changed USE_UNICODE
  3905. foreach my $key (keys(%Texi2HTML::Config::unicode_map))
  3906. {
  3907. if ($Texi2HTML::Config::unicode_map{$key} ne '')
  3908. {
  3909. if (get_conf('USE_UNICODE'))
  3910. {
  3911. my $char_nr = hex($Texi2HTML::Config::unicode_map{$key});
  3912. #$cross_ref_texi_map{$key} = chr(hex($Texi2HTML::Config::unicode_map{$key}));
  3913. #$cross_ref_texi_map{$key} = pack("U0U*",hex($Texi2HTML::Config::unicode_map{$key}));
  3914. if ($char_nr > 126 and $char_nr < 255)
  3915. {
  3916. $cross_ref_texi_map{$key} = Encode::decode("iso-8859-1", chr($char_nr));
  3917. }
  3918. else
  3919. {
  3920. $cross_ref_texi_map{$key} = chr($char_nr);
  3921. }
  3922. # cross_transliterate_texi_map is only used if
  3923. # USE_UNIDECODE is unset and TRANSLITERATE_FILE_NAMES is set
  3924. if (exists ($Texi2HTML::Config::transliterate_map{$Texi2HTML::Config::unicode_map{$key}}))
  3925. {
  3926. $cross_transliterate_texi_map{$key} = $Texi2HTML::Config::transliterate_map{$Texi2HTML::Config::unicode_map{$key}};
  3927. }
  3928. else
  3929. {
  3930. $cross_transliterate_texi_map{$key} = $cross_ref_texi_map{$key};
  3931. }
  3932. }
  3933. else
  3934. {
  3935. $cross_ref_texi_map{$key} = '_' . lc($Texi2HTML::Config::unicode_map{$key});
  3936. # cross_transliterate_texi_map is used if TRANSLITERATE_FILE_NAMES is set
  3937. if (exists ($Texi2HTML::Config::transliterate_map{$Texi2HTML::Config::unicode_map{$key}}))
  3938. {
  3939. $cross_transliterate_texi_map{$key} = $Texi2HTML::Config::transliterate_map{$Texi2HTML::Config::unicode_map{$key}};
  3940. }
  3941. else
  3942. {
  3943. $cross_transliterate_texi_map{$key} = '_' . lc($Texi2HTML::Config::unicode_map{$key});
  3944. }
  3945. }
  3946. }
  3947. }
  3948. if (get_conf('TRANSLITERATE_FILE_NAMES') and (
  3949. (get_conf('USE_UNICODE') and ! get_conf('USE_UNIDECODE'))
  3950. or !get_conf('USE_UNICODE')))
  3951. {
  3952. foreach my $key (keys (%Texi2HTML::Config::transliterate_accent_map))
  3953. {
  3954. $Texi2HTML::Config::transliterate_map{$key} = $Texi2HTML::Config::transliterate_accent_map{$key};
  3955. }
  3956. }
  3957. foreach my $key (keys(%cross_ref_style_map_texi))
  3958. {
  3959. if ($style_type{$key} eq 'accent'
  3960. and (ref($cross_ref_style_map_texi{$key}) eq 'HASH'))
  3961. {
  3962. if (get_conf('USE_UNICODE'))
  3963. {
  3964. $cross_ref_style_map_texi{$key}->{'function'} = \&Texi2HTML::Config::t2h_utf8_accent;
  3965. }
  3966. else
  3967. {
  3968. $cross_ref_style_map_texi{$key}->{'function'} = \&Texi2HTML::Config::t2h_nounicode_cross_manual_accent;
  3969. }
  3970. # this is only used if TRANSLITERATE_FILE_NAMES is set and USE_UNICODE
  3971. # or USE_UNIDECODE is not set
  3972. $cross_transliterate_style_map_texi{$key}->{'function'} = \&Texi2HTML::Config::t2h_transliterate_cross_manual_accent;
  3973. }
  3974. }
  3975. if (get_conf('L2H') and defined($Texi2HTML::Config::OUTPUT_FORMAT) and $Texi2HTML::Config::OUTPUT_FORMAT eq 'html')
  3976. {
  3977. push @Texi2HTML::Config::command_handler_init, \&Texi2HTML::LaTeX2HTML::init;
  3978. push @Texi2HTML::Config::command_handler_process, \&Texi2HTML::LaTeX2HTML::latex2html;
  3979. # do it here once to have something ready for special regions
  3980. push @Texi2HTML::Config::command_handler_process, \&Texi2HTML::LaTeX2HTML::init_from_html;
  3981. # do it here once more in case the file was modified (see mediawiki.pm)
  3982. push @Texi2HTML::Config::command_handler_output, \&Texi2HTML::LaTeX2HTML::init_from_html;
  3983. push @Texi2HTML::Config::command_handler_finish, \&Texi2HTML::LaTeX2HTML::finish;
  3984. $Texi2HTML::Config::command_handler{'math'} =
  3985. { 'init' => \&Texi2HTML::LaTeX2HTML::to_latex,
  3986. 'expand' => \&Texi2HTML::LaTeX2HTML::do_tex
  3987. };
  3988. $Texi2HTML::Config::command_handler{'tex'} =
  3989. { 'init' => \&Texi2HTML::LaTeX2HTML::to_latex,
  3990. 'expand' => \&Texi2HTML::LaTeX2HTML::do_tex
  3991. };
  3992. }
  3993. if (get_conf('ENABLE_ENCODING'))
  3994. {
  3995. if (get_conf('USE_UNICODE'))
  3996. {
  3997. Texi2HTML::Config::t2h_enable_encoding_load();
  3998. }
  3999. else
  4000. { # FIXME: only warn if ENABLE_ENCODING is set on the command line
  4001. #warn "** --enable-encoding requires utf-8 support\n";
  4002. }
  4003. }
  4004. # for all files. This won't be overriden by @documentencoding, this is not
  4005. # what is done in general.
  4006. #Texi2HTML::Config::set_conf('IN_ENCODING', $Texi2HTML::Config::IN_ENCODING);
  4007. #Texi2HTML::Config::set_conf('DOCUMENT_ENCODING', $Texi2HTML::Config::DOCUMENT_ENCODING);
  4008. # APA: There's got to be a better way:
  4009. if (get_conf('TEST'))
  4010. {
  4011. # to generate files similar to reference ones to be able to check for
  4012. # real changes we use these dummy values if -test is given
  4013. $THISPROG = 'texi2html';
  4014. $THISPROG_THISVERSION = 'texi2html';
  4015. setlocale( LC_ALL, "C" );
  4016. }
  4017. $Texi2HTML::GLOBAL{'debug_l2h'} = 1 if ($T2H_DEBUG & $DEBUG_L2H);
  4018. # parse texinfo cnf file for external manual specifications.
  4019. sub prepare_htmlxref($)
  4020. {
  4021. my $input_directory = shift;
  4022. my @htmlxref_dirs = @language_config_dirs;
  4023. if (get_conf('TEST'))
  4024. {
  4025. @htmlxref_dirs = ('./.texinfo');
  4026. }
  4027. if ($input_directory ne '.' and $input_directory ne '')
  4028. {
  4029. unshift @htmlxref_dirs, $input_directory;
  4030. }
  4031. unshift @htmlxref_dirs, '.';
  4032. my @texinfo_htmlxref_files = locate_init_file ($texinfo_htmlxref, \@htmlxref_dirs, 1);
  4033. foreach my $file (@texinfo_htmlxref_files)
  4034. {
  4035. print STDERR "html refs config file: $file\n" if ($T2H_DEBUG);
  4036. unless (open (HTMLXREF, $file))
  4037. {
  4038. document_warn("Cannot open html refs config file ${file}: $!");
  4039. next;
  4040. }
  4041. my $line_nr = 0;
  4042. my %variables;
  4043. while (my $hline = <HTMLXREF>)
  4044. {
  4045. my $line = $hline;
  4046. $line_nr++;
  4047. next if $hline =~ /^\s*#/;
  4048. #$hline =~ s/[#]\s.*//;
  4049. $hline =~ s/^\s*//;
  4050. next if $hline =~ /^\s*$/;
  4051. chomp ($hline);
  4052. if ($hline =~ s/^\s*(\w+)\s*=\s*//)
  4053. {
  4054. # handle variables
  4055. my $var = $1;
  4056. my $re = join '|', map { quotemeta $_ } keys %variables;
  4057. $hline =~ s/\$\{($re)\}/defined $variables{$1} ? $variables{$1} : "\${$1}"/ge;
  4058. $variables{$var} = $hline;
  4059. next;
  4060. }
  4061. my @htmlxref = split /\s+/, $hline;
  4062. my $manual = shift @htmlxref;
  4063. my $split_or_mono = shift @htmlxref;
  4064. #print STDERR "$split_or_mono $Texi2HTML::Config::htmlxref_entries{$split_or_mono} $line_nr\n";
  4065. if (!defined($split_or_mono))
  4066. {
  4067. file_line_warn(__("Missing type"), $file, $line_nr);
  4068. next;
  4069. }
  4070. elsif (!defined($Texi2HTML::Config::htmlxref_entries{$split_or_mono}))
  4071. {
  4072. file_line_warn(sprintf(__("Unrecognized type: %s"), $split_or_mono), $file, $line_nr);
  4073. next;
  4074. }
  4075. my $href = shift @htmlxref;
  4076. next if (exists($Texi2HTML::THISDOC{'htmlxref'}->{$manual}->{$split_or_mono}));
  4077. if (defined($href))
  4078. { # substitute 'variables'
  4079. my $re = join '|', map { quotemeta $_ } keys %variables;
  4080. $href =~ s/\$\{($re)\}/defined $variables{$1} ? $variables{$1} : "\${$1}"/ge;
  4081. $href =~ s/\/*$// if ($split_or_mono ne 'mono');
  4082. }
  4083. $Texi2HTML::THISDOC{'htmlxref'}->{$manual}->{$split_or_mono} = $href;
  4084. }
  4085. close (HTMLXREF);
  4086. }
  4087. }
  4088. if ($T2H_DEBUG)
  4089. {
  4090. foreach my $manual (keys(%{$Texi2HTML::GLOBAL{'htmlxref'}}))
  4091. {
  4092. foreach my $split (keys(%Texi2HTML::Config::htmlxref_entries))
  4093. {
  4094. my $href = 'NO';
  4095. next unless (exists($Texi2HTML::GLOBAL{'htmlxref'}->{$manual}->{$split}));
  4096. $href = $Texi2HTML::GLOBAL{'htmlxref'}->{$manual}->{$split}->{'href'} if
  4097. exists($Texi2HTML::GLOBAL{'htmlxref'}->{$manual}->{$split}->{'href'});
  4098. print STDERR "$manual: $split, href: $href\n";
  4099. }
  4100. }
  4101. }
  4102. # resulting files splitting
  4103. # FIXME we should remove that code
  4104. if (get_conf('SPLIT') =~ /section/i)
  4105. {
  4106. global_override('SPLIT', 'section');
  4107. }
  4108. elsif (get_conf('SPLIT') =~ /node/i)
  4109. {
  4110. global_override('SPLIT', 'node');
  4111. }
  4112. elsif (get_conf('SPLIT') =~ /chapter/i)
  4113. {
  4114. global_override('SPLIT', 'chapter');
  4115. }
  4116. else
  4117. {
  4118. global_override('SPLIT', '');
  4119. }
  4120. global_override('SPLIT_INDEX', 0) unless (get_conf('SPLIT'));
  4121. Texi2HTML::Config::set_default('NODE_FILES', 1) if (!defined(get_conf('NODE_FILES')) and get_conf('SPLIT'));
  4122. Texi2HTML::Config::set_default('NODE_FILENAMES', 1) if ((!defined(get_conf('NODE_FILENAMES')) and get_conf('SPLIT') eq 'node') or get_conf('NODE_FILES'));
  4123. ## Something like backward compatibility. This would make sense to keep
  4124. ## it ad-infinitum since the meaning of --out and --subdir are different.
  4125. #if (get_conf('SPLIT') and defined($Texi2HTML::Config::SUBDIR)
  4126. # and ($Texi2HTML::Config::SUBDIR ne '') and
  4127. # (!defined(get_conf('OUT')) or (get_conf('OUT') eq '')))
  4128. #{
  4129. # set_from_cmdline('OUT', $Texi2HTML::Config::SUBDIR);
  4130. #}
  4131. my %not_split_formats = (
  4132. 'xml' => 1,
  4133. 'info' => 1,
  4134. 'plaintext' => 1,
  4135. 'docbook' => 1
  4136. );
  4137. if (defined($Texi2HTML::Config::OUTPUT_FORMAT) and get_conf('SPLIT') and $not_split_formats{$Texi2HTML::Config::OUTPUT_FORMAT})
  4138. {
  4139. document_warn(sprintf(__('Ignoring splitting for format %s'), $Texi2HTML::Config::OUTPUT_FORMAT));
  4140. global_override('SPLIT', '');
  4141. global_override('FRAMES', 0);
  4142. }
  4143. # FIXME: why is this only done for SUBDIR and if split? Isn't the
  4144. # same issue possible for not split output?
  4145. if (get_conf('SPLIT') and defined(get_conf('SUBDIR')) and (get_conf('SUBDIR') eq '.'))
  4146. {# This is to avoid trouble with latex2html
  4147. global_override('SUBDIR', '');
  4148. }
  4149. @Texi2HTML::Config::INCLUDE_DIRS = split(/$quoted_path_separator/,join($path_separator,@Texi2HTML::Config::INCLUDE_DIRS));
  4150. @Texi2HTML::Config::PREPEND_DIRS = split(/$quoted_path_separator/,join($path_separator,@Texi2HTML::Config::PREPEND_DIRS));
  4151. my @include_dirs_orig = @Texi2HTML::Config::INCLUDE_DIRS;
  4152. @Texi2HTML::Config::CONF_DIRS = split(/$quoted_path_separator/,join($path_separator,@Texi2HTML::Config::CONF_DIRS));
  4153. # extension
  4154. #$Texi2HTML::GLOBAL{'extension'} = get_conf('EXTENSION');
  4155. if (get_conf('SHORTEXTN'))
  4156. {
  4157. #$Texi2HTML::GLOBAL{'extension'} = "htm";
  4158. global_override('EXTENSION', 'htm');
  4159. }
  4160. my $global_pass; # track the phases of processing for debugging output purposes
  4161. #
  4162. # file name business
  4163. #
  4164. my @created_directories = ();
  4165. my $docu_dir; # directory of the document
  4166. my $docu_name; # basename of the document
  4167. my $docu_rdir; # directory for the output
  4168. my $docu_toc; # document's table of contents
  4169. my $docu_stoc; # document's short toc
  4170. my $docu_foot; # document's footnotes
  4171. my $docu_about; # about this document
  4172. my $docu_top; # document top
  4173. my $docu_doc; # document (or document top of split)
  4174. my $docu_frame; # main frame file
  4175. my $docu_toc_frame; # toc frame file
  4176. my $path_to_working_dir; # relative path leading to the working
  4177. # directory from the document directory
  4178. my $docu_doc_file;
  4179. my $docu_toc_file;
  4180. my $docu_stoc_file;
  4181. my $docu_foot_file;
  4182. my $docu_about_file;
  4183. my $docu_top_file;
  4184. my $docu_frame_file;
  4185. my $docu_toc_frame_file;
  4186. sub set_docu_names($$)
  4187. {
  4188. my $docu_base_name = shift;
  4189. my $file_nr = shift;
  4190. if ($docu_base_name =~ /(.*\/)/)
  4191. {
  4192. $docu_dir = $1;
  4193. chop($docu_dir);
  4194. $docu_name = $docu_base_name;
  4195. $docu_name =~ s/.*\///;
  4196. }
  4197. else
  4198. {
  4199. $docu_dir = '.';
  4200. $docu_name = $docu_base_name;
  4201. }
  4202. # AAAA
  4203. if (get_conf('PREFIX') and ($file_nr == 0))
  4204. {
  4205. $docu_name = get_conf('PREFIX');
  4206. }
  4207. elsif ($docu_name eq '-')
  4208. {
  4209. $docu_name = $Texi2HTML::Config::STDIN_DOCU_NAME;
  4210. }
  4211. # subdir
  4212. $docu_rdir = '';
  4213. my $no_file_output;
  4214. if (defined(get_conf('OUTFILE')) and ($file_nr == 0) and ($Texi2HTML::Config::null_device_file{get_conf('OUTFILE')} or get_conf('OUTFILE') eq '-'))
  4215. { # this overrides the setting for this file.
  4216. if (get_conf ('SPLIT'))
  4217. {
  4218. document_override('SPLIT', '');
  4219. document_warn(sprintf(__('Cannot split output %s'), get_conf('OUTFILE')));
  4220. }
  4221. document_override('FRAMES', 0);
  4222. document_override('SPLIT_SIZE', undef);
  4223. $no_file_output = 1;
  4224. $path_to_working_dir = $docu_rdir;
  4225. }
  4226. if (!$no_file_output)
  4227. {
  4228. if (get_conf('SPLIT'))
  4229. {
  4230. if (defined(get_conf('OUT')) and ($file_nr == 0))
  4231. {
  4232. $docu_rdir = get_conf('OUT');
  4233. }
  4234. else
  4235. {
  4236. $docu_rdir = $docu_name;
  4237. }
  4238. if ($docu_rdir ne '')
  4239. {
  4240. $docu_rdir =~ s|/*$||;
  4241. $docu_rdir .= '/';
  4242. }
  4243. }
  4244. else
  4245. {
  4246. my $out_dir;
  4247. # AAAA
  4248. if (defined(get_conf('OUTFILE')) and ($file_nr == 0))
  4249. {
  4250. $out_dir = get_conf('OUTFILE');
  4251. $out_dir =~ s|[^/]*$||;
  4252. }
  4253. # even if the out file is not set by OUT, in case it is not the first
  4254. # file, the subdir directory is still used, if it has been determined.
  4255. elsif (defined(get_conf('SUBDIR')) and get_conf('SUBDIR') ne '')
  4256. {
  4257. $out_dir = get_conf('SUBDIR');
  4258. }
  4259. if (defined($out_dir) and $out_dir =~ m|(.*)/|)
  4260. {# there is a leading directories
  4261. $docu_rdir = "$1/";
  4262. }
  4263. }
  4264. if ($docu_rdir ne '')
  4265. {
  4266. unless (-d $docu_rdir)
  4267. {
  4268. if ( mkdir($docu_rdir, oct(755)))
  4269. {
  4270. print STDERR "# created directory $docu_rdir\n" if ($T2H_VERBOSE);
  4271. push @created_directories, $docu_rdir;
  4272. }
  4273. else
  4274. {
  4275. my $original_rdir = $docu_rdir;
  4276. # as explained in the doc, retry with the extension appended.
  4277. # this is dubious practice, but workaround extension-less info
  4278. # files
  4279. if (get_conf('SPLIT') and get_conf('EXTENSION') and get_conf('EXTENSION') ne '')
  4280. {
  4281. $docu_rdir =~ s/\/*$//;
  4282. $docu_rdir .= '.' . get_conf('EXTENSION') . '/';
  4283. if (! -d $docu_rdir)
  4284. {
  4285. if ( mkdir($docu_rdir, oct(755)))
  4286. {
  4287. print STDERR "# created directory $docu_rdir\n" if ($T2H_VERBOSE);
  4288. push @created_directories, $docu_rdir;
  4289. }
  4290. else
  4291. {
  4292. document_error (sprintf(__("Can't create directories `%s' or `%s': %s"), $original_rdir, $docu_rdir, $!), 1);
  4293. }
  4294. }
  4295. }
  4296. else
  4297. {
  4298. document_error (sprintf(__("Can't create directory `%s': %s"), $docu_rdir, $!), 1);
  4299. }
  4300. }
  4301. }
  4302. print STDERR "# putting result files into directory $docu_rdir\n" if ($T2H_VERBOSE);
  4303. }
  4304. else
  4305. {
  4306. print STDERR "# putting result files into current directory \n" if ($T2H_VERBOSE);
  4307. }
  4308. # We don't use "./" as $docu_rdir when $docu_rdir is the current directory
  4309. # because it is problematic for latex2html. To test writability with -w,
  4310. # however we need a real directory.
  4311. my $result_rdir = $docu_rdir;
  4312. $result_rdir = "." if ($docu_rdir eq '');
  4313. unless (-w $result_rdir)
  4314. {
  4315. if ($docu_rdir eq '')
  4316. {
  4317. document_error(__('current directory not writable'), 1);
  4318. }
  4319. else
  4320. {
  4321. document_error(sprintf(__('%s not writable'), $docu_rdir), 1);
  4322. }
  4323. }
  4324. # relative path leading to the working directory from the document directory
  4325. $path_to_working_dir = $docu_rdir;
  4326. if ($docu_rdir ne '')
  4327. {
  4328. my $cwd = cwd;
  4329. my $docu_path = $docu_rdir;
  4330. $docu_path = $cwd . '/' . $docu_path unless ($docu_path =~ /^\//);
  4331. my @result = ();
  4332. # this code simplify the paths. The cwd is absolute, while in the
  4333. # document path there may be some .., a .. is removed with the
  4334. # previous path element, such that something like
  4335. # /cwd/directory/../somewhere/
  4336. # leads to
  4337. # /cwd/somewhere/
  4338. # with directory/.. removed
  4339. foreach my $element (split /\//, File::Spec->canonpath($docu_path))
  4340. {
  4341. if ($element eq '')
  4342. {
  4343. push @result, '';
  4344. }
  4345. elsif ($element eq '..')
  4346. {
  4347. if (@result and ($result[-1] eq ''))
  4348. {
  4349. print STDERR "Too much .. in absolute file name\n";
  4350. }
  4351. elsif (@result and ($result[-1] ne '..'))
  4352. {
  4353. pop @result;
  4354. }
  4355. else
  4356. {
  4357. push @result, $element;
  4358. }
  4359. }
  4360. else
  4361. {
  4362. push @result, $element;
  4363. }
  4364. }
  4365. $path_to_working_dir = File::Spec->abs2rel($cwd, join ('/', @result));
  4366. # this should not be needed given what canonpath does
  4367. $path_to_working_dir =~ s:/*$::;
  4368. $path_to_working_dir .= '/' unless($path_to_working_dir eq '');
  4369. }
  4370. }
  4371. my $docu_ext = get_conf('EXTENSION');
  4372. $Texi2HTML::THISDOC{'destination_directory'} = $docu_rdir;
  4373. $Texi2HTML::THISDOC{'file_base_name'} = $docu_name;
  4374. $docu_doc = $docu_name . (defined($docu_ext) ? ".$docu_ext" : ""); # document's contents
  4375. if (get_conf('SPLIT') and get_conf('NODE_FILENAMES'))
  4376. {
  4377. if (defined(get_conf('TOP_NODE_FILE')))
  4378. {
  4379. $docu_doc = get_conf('TOP_NODE_FILE');
  4380. if (defined(get_conf('NODE_FILE_EXTENSION')) and get_conf('NODE_FILE_EXTENSION') ne '')
  4381. {
  4382. $docu_doc .= '.' . get_conf('NODE_FILE_EXTENSION');
  4383. }
  4384. }
  4385. }
  4386. if (get_conf('SPLIT'))
  4387. {
  4388. # AAAA
  4389. if (defined(get_conf('TOP_FILE')) and (get_conf('TOP_FILE') ne '') and ($file_nr == 0))
  4390. {
  4391. $docu_top = get_conf('TOP_FILE');
  4392. }
  4393. }
  4394. else
  4395. {
  4396. # AAAA
  4397. if (defined(get_conf('OUTFILE')) and ($file_nr == 0))
  4398. {
  4399. my $out_file = get_conf('OUTFILE');
  4400. if (get_conf('OUT') ne get_conf('OUTFILE'))
  4401. {
  4402. # FIXME output a warning?
  4403. #document_warn(sprintf(__('Not using %s as an out file as it is a directory'), get_conf('OUT')));
  4404. }
  4405. $out_file =~ s|.*/|| unless ($no_file_output);
  4406. $docu_doc = $out_file if ($out_file !~ /^\s*$/);
  4407. }
  4408. }
  4409. if (defined $Texi2HTML::Config::element_file_name)
  4410. {
  4411. my $docu_doc_set = &$Texi2HTML::Config::element_file_name
  4412. (undef, 'doc', $docu_name);
  4413. $docu_doc = $docu_doc_set if (defined($docu_doc_set));
  4414. }
  4415. $docu_top = $docu_doc if (!defined($docu_top));
  4416. if (get_conf('SPLIT') or !get_conf('MONOLITHIC'))
  4417. {
  4418. if (defined $Texi2HTML::Config::element_file_name)
  4419. {
  4420. $docu_toc = &$Texi2HTML::Config::element_file_name
  4421. (undef, 'toc', $docu_name);
  4422. $docu_stoc = &$Texi2HTML::Config::element_file_name
  4423. (undef, 'stoc', $docu_name);
  4424. $docu_foot = &$Texi2HTML::Config::element_file_name
  4425. (undef, 'foot', $docu_name);
  4426. $docu_about = &$Texi2HTML::Config::element_file_name
  4427. (undef, 'about', $docu_name);
  4428. # $docu_top may be overwritten later.
  4429. }
  4430. if (!defined($docu_toc))
  4431. {
  4432. my $default_toc = "${docu_name}_toc";
  4433. $default_toc .= ".$docu_ext" if (defined($docu_ext));
  4434. # AAAA
  4435. if (defined(get_conf('TOC_FILE')) and (get_conf('TOC_FILE') ne '') and ($file_nr == 0))
  4436. {
  4437. $docu_toc = get_conf('TOC_FILE');
  4438. }
  4439. else
  4440. {
  4441. $docu_toc = $default_toc;
  4442. }
  4443. }
  4444. if (!defined($docu_stoc))
  4445. {
  4446. $docu_stoc = "${docu_name}_ovr";
  4447. $docu_stoc .= ".$docu_ext" if (defined($docu_ext));
  4448. }
  4449. if (!defined($docu_foot))
  4450. {
  4451. $docu_foot = "${docu_name}_fot";
  4452. $docu_foot .= ".$docu_ext" if (defined($docu_ext));
  4453. }
  4454. if (!defined($docu_about))
  4455. {
  4456. $docu_about = "${docu_name}_abt";
  4457. $docu_about .= ".$docu_ext" if (defined($docu_ext));
  4458. }
  4459. }
  4460. else
  4461. {
  4462. $docu_toc = $docu_foot = $docu_stoc = $docu_about = $docu_doc;
  4463. }
  4464. # Note that file extension has already been added here.
  4465. if (get_conf('FRAMES'))
  4466. {
  4467. if (defined $Texi2HTML::Config::element_file_name)
  4468. {
  4469. $docu_frame = &$Texi2HTML::Config::element_file_name
  4470. (undef, 'frame', $docu_name);
  4471. $docu_toc_frame = &$Texi2HTML::Config::element_file_name
  4472. (undef, 'toc_frame', $docu_name);
  4473. }
  4474. }
  4475. if (!defined($docu_frame))
  4476. {
  4477. $docu_frame = "${docu_name}_frame";
  4478. $docu_frame .= ".$docu_ext" if (defined($docu_ext));
  4479. }
  4480. if (!defined($docu_toc_frame))
  4481. {
  4482. $docu_toc_frame = "${docu_name}_toc_frame";
  4483. $docu_toc_frame .= ".$docu_ext" if (defined($docu_ext));
  4484. }
  4485. if ($T2H_VERBOSE)
  4486. {
  4487. print STDERR "# Files and directories:\n";
  4488. print STDERR "# rdir($docu_rdir) path_to_working_dir($path_to_working_dir)\n";
  4489. print STDERR "# doc($docu_doc) top($docu_top) toc($docu_toc) stoc($docu_stoc)\n";
  4490. print STDERR "# foot($docu_foot) about($docu_about) frame($docu_toc) toc_frame($docu_toc_frame)\n";
  4491. }
  4492. $docu_doc_file = "$docu_rdir$docu_doc";
  4493. $docu_toc_file = "$docu_rdir$docu_toc";
  4494. $docu_stoc_file = "$docu_rdir$docu_stoc";
  4495. $docu_foot_file = "$docu_rdir$docu_foot";
  4496. $docu_about_file = "$docu_rdir$docu_about";
  4497. $docu_top_file = "$docu_rdir$docu_top";
  4498. $docu_frame_file = "$docu_rdir$docu_frame";
  4499. $docu_toc_frame_file = "$docu_rdir$docu_toc_frame";
  4500. # For use in init files
  4501. $Texi2HTML::THISDOC{'filename'}->{'top'} = $docu_top;
  4502. $Texi2HTML::THISDOC{'filename'}->{'foot'} = $docu_foot;
  4503. $Texi2HTML::THISDOC{'filename'}->{'stoc'} = $docu_stoc;
  4504. $Texi2HTML::THISDOC{'filename'}->{'about'} = $docu_about;
  4505. $Texi2HTML::THISDOC{'filename'}->{'toc'} = $docu_toc;
  4506. $Texi2HTML::THISDOC{'filename'}->{'toc_frame'} = $docu_toc_frame;
  4507. $Texi2HTML::THISDOC{'filename'}->{'frame'} = $docu_frame;
  4508. }
  4509. sub var_to_str($)
  4510. {
  4511. return 'UNDEF' if (!defined($_[0]));
  4512. return $_[0];
  4513. }
  4514. #
  4515. # Common initializations
  4516. #
  4517. sub texinfo_initialization($)
  4518. {
  4519. my $pass = shift;
  4520. # set the translations now. This means at the beginning of each pass.
  4521. # Do it silently, except during the last pass.
  4522. my $lang = get_conf('documentlanguage');
  4523. my $silent_lang = 1 if ($pass != 2);
  4524. if (!set_document_language($lang))
  4525. { # may only fail if not using the default gettext framework
  4526. document_warn ("Translations for '$lang' not found. Using 'en'.") unless ($silent_lang);
  4527. set_document_language('en');
  4528. }
  4529. # All the initialization used the informations still there at the
  4530. # end of the previous pass.
  4531. # Now we reset everything, such that things are used when they happen.
  4532. # also reset the @set/@clear values.
  4533. %value = %value_initial;
  4534. foreach my $init_mac (@document_settable_at_commands)
  4535. {
  4536. unset_from_document($init_mac);
  4537. }
  4538. }
  4539. #+++###########################################################################
  4540. # #
  4541. # Pass texi: read source, handle variable, ignored text, #
  4542. # #
  4543. #---###########################################################################
  4544. #my @lines = (); # whole document
  4545. #my @lines_numbers = (); # line number, originating file associated with
  4546. # whole document
  4547. my $macros = undef; # macros. reference on a hash
  4548. my %info_enclose = (); # macros defined with definfoenclose
  4549. my @floats = (); # floats list
  4550. my %floats = (); # floats by style
  4551. sub initialise_state_texi($)
  4552. {
  4553. my $state = shift;
  4554. $state->{'texi'} = 1; # for substitute_text and close_stack:
  4555. # 1 if pass_texi/scan_texi is to be used
  4556. $state->{'macro_inside'} = 0 unless(defined($state->{'macro_inside'}));
  4557. $state->{'ifvalue_inside'} = 0 unless(defined($state->{'ifvalue_inside'}));
  4558. $state->{'arg_expansion'} = 0 unless(defined($state->{'arg_expansion'}));
  4559. $state->{'files_stack'} = [] unless(defined($state->{'files_stack'}));
  4560. }
  4561. sub pass_texi($)
  4562. {
  4563. my $input_file_name = shift;
  4564. #my $texi_line_number = { 'file_name' => '', 'line_nr' => 0, 'macro' => '' };
  4565. my @lines = (); # whole document
  4566. my @lines_numbers = (); # line number, originating file associated with
  4567. # whole document
  4568. my @first_lines = ();
  4569. my $first_lines = 1; # is it the first lines
  4570. my $state = {};
  4571. # holds the informations about the context
  4572. # to pass it down to the functions
  4573. # FIXME not used, to be used after @setfilename use is clearer
  4574. my @command_line_lines = @Texi2HTML::Config::COMMANDS;
  4575. initialise_state_texi($state);
  4576. my $texi_line_number;
  4577. ($texi_line_number, $state->{'input_spool'}) =
  4578. open_file($input_file_name, '', $state->{'files_stack'});
  4579. my @stack;
  4580. my $text;
  4581. my $cline;
  4582. INPUT_LINE: while (1)
  4583. {
  4584. ($cline, $state->{'input_spool'}) = next_line($texi_line_number, $state->{'files_stack'});
  4585. last if (!defined($cline));
  4586. #
  4587. # remove the lines preceding \input or an @-command
  4588. #
  4589. if ($first_lines)
  4590. {
  4591. if ($cline =~ /^\\input/)
  4592. {
  4593. push @first_lines, $cline;
  4594. $first_lines = 0;
  4595. next;
  4596. }
  4597. if ($cline =~ /^\s*\@/)
  4598. {
  4599. $first_lines = 0;
  4600. }
  4601. else
  4602. {
  4603. push @first_lines, $cline;
  4604. next;
  4605. }
  4606. }
  4607. #print STDERR "PASS_TEXI($texi_line_number->{'line_nr'})$cline";
  4608. my $chomped_line = $cline;
  4609. if (scan_texi ($cline, \$text, \@stack, $state, $texi_line_number) and chomp($chomped_line))
  4610. {
  4611. #print STDERR "==> new page (line_nr $texi_line_number->{'line_nr'},$texi_line_number->{'file_name'},$texi_line_number->{'macro'})\n";
  4612. push (@lines_numbers, { 'file_name' => $texi_line_number->{'file_name'},
  4613. 'line_nr' => $texi_line_number->{'line_nr'},
  4614. 'macro' => $texi_line_number->{'macro'} });
  4615. }
  4616. #dump_stack (\$text, \@stack, $state);
  4617. if ($state->{'bye'})
  4618. {
  4619. #dump_stack(\$text, \@stack, $state);
  4620. # close stack after bye
  4621. #print STDERR "close stack after bye\n";
  4622. close_stack_texi(\$text, \@stack, $state, $texi_line_number);
  4623. #dump_stack(\$text, \@stack, $state);
  4624. }
  4625. next if (@stack);
  4626. $cline = $text;
  4627. $text = '';
  4628. if (!defined($cline))
  4629. {
  4630. msg_debug ("\$cline undefined after scan_texi", $texi_line_number);
  4631. next unless ($state->{'bye'});
  4632. }
  4633. push @lines, split_lines($cline);
  4634. last if ($state->{'bye'});
  4635. }
  4636. # close stack at the end of pass texi
  4637. #print STDERR "close stack at the end of pass texi\n";
  4638. close_stack_texi(\$text, \@stack, $state, $texi_line_number);
  4639. my @end_lines = split_lines($text);
  4640. #push @lines, split_lines($text);
  4641. foreach my $line (split_lines($text))
  4642. {
  4643. push @lines, $line;
  4644. $texi_line_number->{'line_nr'}++;
  4645. push (@lines_numbers, { 'file_name' => $texi_line_number->{'file_name'},
  4646. 'line_nr' => $texi_line_number->{'line_nr'},
  4647. 'macro' => __(' end of file') });
  4648. }
  4649. print STDERR "# end of pass texi\n" if $T2H_VERBOSE;
  4650. return (\@lines, \@first_lines, \@lines_numbers);
  4651. }
  4652. #+++###########################################################################
  4653. # #
  4654. # Pass structure: parse document structure #
  4655. # #
  4656. #---###########################################################################
  4657. sub initialise_state_structure($)
  4658. {
  4659. my $state = shift;
  4660. $state->{'structure'} = 1; # for substitute_text and close_stack:
  4661. # 1 if pass_structure/scan_structure is
  4662. # to be used
  4663. $state->{'menu'} = 0; # number of opened menus
  4664. $state->{'detailmenu'} = 0; # number of opened detailed menus
  4665. $state->{'direntry'} = 0; # number of opened direntry
  4666. $state->{'sectioning_base'} = 0; # current base sectioning level
  4667. $state->{'table_stack'} = [ "no table" ]; # a stack of opened tables/lists
  4668. # seems to be only debug
  4669. if (exists($state->{'region_lines'}) and !defined($state->{'region_lines'}))
  4670. {
  4671. delete ($state->{'region_lines'});
  4672. print STDERR "Bug: state->{'region_lines'} exists but undef.\n";
  4673. }
  4674. }
  4675. # This is a virtual element for things appearing before @node and
  4676. # sectioning commands
  4677. my $element_before_anything;
  4678. #
  4679. # initial counters. Global variables for pass_structure.
  4680. #
  4681. my $document_idx_num;
  4682. my $document_sec_num;
  4683. my $document_head_num;
  4684. my $document_anchor_num;
  4685. # section to level hash taking into account raise and lower sections.
  4686. # Reset at document beginning
  4687. my %sec2level;
  4688. # initial state for the special regions.
  4689. my %region_initial_state;
  4690. my %region_lines;
  4691. my %region_line_nrs;
  4692. # This is a place for index entries, anchors and so on appearing in
  4693. # copying or documentdescription
  4694. my $no_element_associated_place;
  4695. my %nodes; # nodes hash. The key is the texi node name
  4696. my %cross_reference_nodes; # normalized node names arrays
  4697. #
  4698. # _foo: internal variables to track @foo
  4699. # obsolete
  4700. foreach my $key ('_author', '_title', '_subtitle', '_shorttitlepage',
  4701. '_settitle', '_titlefont')
  4702. {
  4703. $value_initial{$key} = ''; # prevent -w warnings
  4704. }
  4705. my @nodes_list; # nodes in document reading order
  4706. # each member is a reference on a hash
  4707. my @sections_list; # sections in reading order
  4708. # each member is a reference on a hash
  4709. my @all_elements; # sectioning elements (nodes and sections)
  4710. # in reading order. Each member is a reference
  4711. # on a hash which also appears in %nodes,
  4712. # @sections_list @nodes_list, @elements_list
  4713. my @headings_list; # headings in reading order.
  4714. my @elements_list; # all the resulting elements in document order
  4715. my %sections; # sections hash. The key is the section number
  4716. my %headings; # headings hash. The key is the heading number
  4717. my $section_top; # @top section
  4718. my $element_top; # Top element
  4719. my $node_top; # Top node
  4720. my $node_first; # First node
  4721. my $element_index; # element with first index
  4722. my $element_chapter_index; # chapter with first index
  4723. my $element_first; # first element
  4724. my $element_last; # last element
  4725. my %special_commands; # hash for the commands specially handled
  4726. # by the user
  4727. # element for content and shortcontent if on a separate page
  4728. my %content_element;
  4729. my %reference_content_element =
  4730. (
  4731. 'contents' => { 'id' => $Texi2HTML::Config::misc_pages_targets{'Contents'},
  4732. 'target' => $Texi2HTML::Config::misc_pages_targets{'Contents'},
  4733. 'contents' => 1, 'texi' => '_contents' },
  4734. 'shortcontents' => {
  4735. 'id' => $Texi2HTML::Config::misc_pages_targets{'Overview'},
  4736. 'target' => $Texi2HTML::Config::misc_pages_targets{'Overview'},
  4737. 'shortcontents' => 1, 'texi' => '_shortcontents' },
  4738. );
  4739. # holds content elements located with @*contents commands
  4740. my %all_content_elements;
  4741. # common code for headings and sections
  4742. sub new_section_heading($$$$)
  4743. {
  4744. my $command = shift;
  4745. my $name = shift;
  4746. my $state = shift;
  4747. my $line_nr = shift;
  4748. $name = trim_comment_spaces ($name, "\@$command", $line_nr);
  4749. $name = normalise_texi_space($name);
  4750. $name = '' if (!defined($name));
  4751. # no increase if in @copying and the like. Also no increase if it is top
  4752. # since top has number 0.
  4753. my $docid;
  4754. my $num;
  4755. my $section_ref = { 'texi' => $name,
  4756. 'level' => $sec2level{$command},
  4757. 'tag' => $command,
  4758. };
  4759. return $section_ref;
  4760. }
  4761. sub scan_line_separators($$$;$)
  4762. {
  4763. my $line = shift;
  4764. my $separators = shift;
  4765. my $context = shift;
  4766. my $line_nr = shift;
  4767. my @command_stack;
  4768. my $result = '';
  4769. while (1)
  4770. {
  4771. # macro_regexp
  4772. if ($line =~ s/^([^{}\@$separators]*)\@(["'~\@\}\{,\.!\?\s\*\-\^`=:\|\/\\])// or $line =~ s/^([^{}\@$separators]*)\@([a-zA-Z][\w-]*)//)
  4773. {
  4774. $result .= $1;
  4775. my $command = $2;
  4776. $command = $alias{$command} if (exists($alias{$command}));
  4777. if (defined($Texi2HTML::Config::misc_command{$command}))
  4778. {
  4779. if ($command ne 'c' and $command ne 'comment')
  4780. { # misc commands other than comments are kept as-is, only
  4781. # comments are removed.
  4782. my ($text, $args);
  4783. ($line, $text, $args) = &$Texi2HTML::Config::preserve_misc_command($line, $command);
  4784. $result .= "\@$command".$text;
  4785. next;
  4786. }
  4787. else
  4788. {
  4789. $line =~ s/.*//;
  4790. return ($result, $line, undef);
  4791. }
  4792. }
  4793. $result .= "\@$command";
  4794. if ($line =~ s/^{//)
  4795. {
  4796. push @command_stack, $command;
  4797. $result .= '{';
  4798. }
  4799. if ($command eq 'verb')
  4800. {
  4801. if ($line =~ s/^(.)//)
  4802. {
  4803. my $char = $1;
  4804. my $verb_char = quotemeta($char);
  4805. if ($line =~ s/^(.*?${verb_char}\})//)
  4806. {
  4807. $result .= $char.$1;
  4808. }
  4809. else
  4810. {
  4811. $line =~ s/^(.*)//;
  4812. $result .= $char . $1;
  4813. return ($result, $line, undef);
  4814. }
  4815. }
  4816. else
  4817. {
  4818. return ($result, $line, undef);
  4819. }
  4820. pop @command_stack;
  4821. }
  4822. }
  4823. elsif ($line =~ s/^([^\{\}$separators]*)([{}])//)
  4824. {
  4825. $result .= $1 . $2;
  4826. my $brace = $2;
  4827. if (@command_stack and $brace eq '}')
  4828. {
  4829. pop @command_stack;
  4830. }
  4831. }
  4832. elsif ($separators ne '' and $line =~ s/^([^${separators}]*)([$separators])//)
  4833. {
  4834. $result .= $1;
  4835. my $separator = $2;
  4836. if (@command_stack)
  4837. {
  4838. $result .= $separator;
  4839. }
  4840. else
  4841. {
  4842. return ($result, $line, $separator);
  4843. }
  4844. }
  4845. else
  4846. {
  4847. $result .= $line;
  4848. $line = '';
  4849. return ($result, $line, undef);
  4850. }
  4851. }
  4852. }
  4853. sub trim_comment_spaces($$;$)
  4854. {
  4855. my $line = shift;
  4856. my $context = shift;
  4857. my $line_nr = shift;
  4858. if(!defined($line))
  4859. {
  4860. msg_debug("trim_comment_spaces: $context: line undef", $line_nr);
  4861. return undef;
  4862. }
  4863. my ($arg, $remaining, $separator) = scan_line_separators ($line, '', $context, $line_nr);
  4864. #msg_debug ("trim_comment_spaces: $context: arg undef. $line", $line_nr) if (!defined($arg));
  4865. #msg_debug ("trim_comment_spaces: $context: $arg !!! $line", $line_nr);
  4866. return $arg if (!defined($arg));
  4867. return trim_around_spaces($arg);
  4868. }
  4869. # argument may be the number of arguments when the commas in the last
  4870. # argument has no specific meaning. When it is undef it means that
  4871. # all the arguments have to be parsed
  4872. sub parse_line_arguments($$$;$)
  4873. {
  4874. my $line = shift;
  4875. my $arg_total_nr = shift;
  4876. my $context = shift;
  4877. my $line_nr = shift;
  4878. my @args;
  4879. my $arg_nr = 0;
  4880. my $remaining = $line;
  4881. while (!defined($arg_total_nr) or $arg_nr < $arg_total_nr -1)
  4882. {
  4883. my ($arg, $separator);
  4884. ($arg, $remaining, $separator) = scan_line_separators($remaining, ',', $context, $line_nr);
  4885. push @args, trim_around_spaces($arg) if (defined($arg));
  4886. return @args if (!defined($separator) or !defined($remaining) or !defined($arg));
  4887. $arg_nr++;
  4888. }
  4889. if (defined($arg_total_nr))
  4890. {
  4891. my ($last_arg, $separator);
  4892. ($last_arg, $remaining, $separator) = scan_line_separators($remaining, '', $context, $line_nr);
  4893. push @args, trim_around_spaces($last_arg) if (defined($last_arg));
  4894. }
  4895. return @args;
  4896. }
  4897. sub pass_structure($$)
  4898. {
  4899. my $texi_lines = shift;
  4900. my $lines_numbers = shift;
  4901. my @doc_lines; # whole document
  4902. my @doc_numbers; # whole document line numbers and file names
  4903. my $state = {};
  4904. # holds the informations about the context
  4905. # to pass it down to the functions
  4906. initialise_state_structure($state);
  4907. $state->{'heading_element'} = $element_before_anything;
  4908. $state->{'current_element'} = $element_before_anything;
  4909. $state->{'place'} = $element_before_anything->{'place'};
  4910. my @stack;
  4911. my $text;
  4912. my $line_nr;
  4913. while (@$texi_lines or $state->{'in_deff_line'})
  4914. {
  4915. my $cline = shift @$texi_lines;
  4916. my $chomped_line = $cline;
  4917. if (@$texi_lines and !chomp($chomped_line))
  4918. {
  4919. $texi_lines->[0] = $cline . $texi_lines->[0];
  4920. next;
  4921. }
  4922. # !defined($cline) may happen if $state->{'in_deff_line'} is true
  4923. # but there is no more line, in case the last end of line is
  4924. # protected
  4925. $line_nr = shift (@$lines_numbers) unless (!defined($cline));
  4926. if ($state->{'in_deff_line'})
  4927. { # line stored in $state->{'in_deff_line'} was protected by @
  4928. # and can be concatenated with the next line
  4929. if (defined($cline))
  4930. {
  4931. $cline = $state->{'in_deff_line'} . $cline;
  4932. }
  4933. else
  4934. {# end of line protected at the very end of the file
  4935. # in that case there is also no line_nr anymore.
  4936. $cline = $state->{'in_deff_line'};
  4937. }
  4938. delete $state->{'in_deff_line'};
  4939. }
  4940. #print STDERR "PASS_STRUCTURE($line_nr->{'line_nr'}. raw:".var_to_str($state->{'raw'}).", verb:".var_to_str($state->{'verb'})."): $cline";
  4941. if (!$state->{'raw'} and !$state->{'verb'})
  4942. {
  4943. my $tag = '';
  4944. if ($cline =~ /^\s*\@(\w+)\b/)
  4945. {
  4946. $tag = $1;
  4947. }
  4948. #
  4949. # analyze the tag
  4950. #
  4951. if ($tag and $tag eq 'node' or (defined($sec2level{$tag}) and ($tag !~ /heading/)) or ($tag eq 'insertcopying' and get_conf('INLINE_INSERTCOPYING')))
  4952. {
  4953. my @added_lines = ($cline);
  4954. my @added_numbers = ($line_nr);
  4955. if ($tag eq 'node' or defined($sec2level{$tag}))
  4956. {# in pass structure node shouldn't appear in formats
  4957. close_stack_structure(\$text, \@stack, $state, $line_nr);
  4958. if (exists($state->{'region_lines'}))
  4959. {
  4960. push @{$region_lines{$state->{'region_lines'}->{'format'}}}, split_lines($text);
  4961. push @doc_lines, split_lines($text) if ($Texi2HTML::Config::region_formats_kept{$state->{'region_lines'}->{'format'}});
  4962. $state->{'region_lines'}->{'number'} = 0;
  4963. close_region($state);
  4964. }
  4965. else
  4966. {
  4967. push @doc_lines, split_lines($text);
  4968. }
  4969. $text = '';
  4970. }
  4971. if ($tag eq 'node')
  4972. {
  4973. my $node_ref;
  4974. my $auto_directions;
  4975. my $node_line = $cline;
  4976. $node_line =~ s/^\@node\s*//;
  4977. my @node_res = parse_line_arguments($node_line, undef, '@node', $line_nr);
  4978. @node_res = normalise_node_array (\@node_res);
  4979. # even for empty nodes, @nodes_res has one element.
  4980. #line_error (sprintf(__("Error scanning %s"), $cline), $line_nr) if (@node_res < 1);
  4981. $auto_directions = 1 if (scalar(@node_res) == 1);
  4982. if (@node_res > 4)
  4983. {
  4984. line_warn(__("Superfluous arguments for node"), $line_nr);
  4985. }
  4986. my ($node, $node_next, $node_prev, $node_up) = @node_res;
  4987. if (defined($node) and ($node ne ''))
  4988. {
  4989. if (exists($nodes{$node}) and defined($nodes{$node})
  4990. and $nodes{$node}->{'seen'})
  4991. {
  4992. line_error (sprintf(__("Node `%s' previously defined %s"), $node, format_line_number($nodes{$node}->{'line_nr'})), $line_nr);
  4993. next;
  4994. }
  4995. elsif ($node =~ /^\(.+\)/)
  4996. {
  4997. line_error (sprintf(__("Syntax for an external node used for `%s'"), $node), $line_nr);
  4998. next;
  4999. }
  5000. else
  5001. {
  5002. if (exists($nodes{$node}) and defined($nodes{$node}))
  5003. { # node appeared in a menu
  5004. $node_ref = $nodes{$node};
  5005. }
  5006. else
  5007. {
  5008. $node_ref = {};
  5009. $nodes{$node} = $node_ref;
  5010. }
  5011. $node_ref->{'node'} = 1;
  5012. $node_ref->{'tag'} = 'node';
  5013. $node_ref->{'tag_level'} = 'node';
  5014. $node_ref->{'texi'} = $node;
  5015. $node_ref->{'seen'} = 1;
  5016. $node_ref->{'automatic_directions'} = $auto_directions;
  5017. $node_ref->{'place'} = [];
  5018. $node_ref->{'current_place'} = [];
  5019. $node_ref->{'line_nr'} = $line_nr;
  5020. merge_element_before_anything($node_ref);
  5021. $node_ref->{'index_names'} = [];
  5022. $state->{'place'} = $node_ref->{'current_place'};
  5023. $state->{'heading_element'} = $node_ref;
  5024. $state->{'current_element'} = $node_ref;
  5025. $state->{'node_ref'} = $node_ref;
  5026. $state->{'menu_in_node'} = 0;
  5027. # makeinfo treats differently case variants of
  5028. # top in nodes and anchors and in refs commands and
  5029. # refs from nodes.
  5030. if ($node =~ /^top$/i)
  5031. {
  5032. if (!defined($node_top))
  5033. {
  5034. $node_top = $node_ref;
  5035. $node_top->{'texi'} = 'Top';
  5036. delete $nodes{$node};
  5037. $nodes{$node_top->{'texi'}} = $node_ref;
  5038. }
  5039. else
  5040. { # All the refs are going to point to the first Top
  5041. line_warn ("Top node already exists", $line_nr);
  5042. }
  5043. }
  5044. unless (@nodes_list)
  5045. {
  5046. $node_first = $node_ref;
  5047. }
  5048. push (@nodes_list, $node_ref);
  5049. push @all_elements, $node_ref;
  5050. }
  5051. }
  5052. else
  5053. {
  5054. line_error ("Empty node", $line_nr);
  5055. next;
  5056. }
  5057. if (defined($node_next) and ($node_next ne ''))
  5058. {
  5059. $node_ref->{'node_next'} = $node_next;
  5060. }
  5061. if (defined($node_prev) and ($node_prev ne ''))
  5062. {
  5063. $node_ref->{'node_prev'} = $node_prev;
  5064. }
  5065. if (defined($node_up) and ($node_up ne ''))
  5066. {
  5067. $node_ref->{'node_up'} = $node_up;
  5068. }
  5069. }
  5070. elsif (defined($sec2level{$tag}))
  5071. { # section
  5072. if ($cline =~ /^\@$tag\s*(.*)$/)
  5073. {
  5074. my $name = $1;
  5075. my $section_ref = new_section_heading($tag, $name, $state, $line_nr);
  5076. $document_sec_num++ if ($tag ne 'top');
  5077. $section_ref->{'sec_num'} = $document_sec_num;
  5078. $section_ref->{'id'} = "SEC$document_sec_num";
  5079. $section_ref->{'seen'} = 1;
  5080. $section_ref->{'index_names'} = [];
  5081. $section_ref->{'current_place'} = [];
  5082. $section_ref->{'place'} = [];
  5083. $section_ref->{'section'} = 1;
  5084. $section_ref->{'line_nr'} = $line_nr;
  5085. if ($tag eq 'top')
  5086. {
  5087. $section_ref->{'number'} = '';
  5088. $section_ref->{'id'} = "SEC_Top";
  5089. $section_ref->{'sec_num'} = 0;
  5090. if (defined($section_top))
  5091. {
  5092. line_error ("\@top already exists", $line_nr);
  5093. $sections{0} = $section_ref;
  5094. }
  5095. else
  5096. {
  5097. $sections{0.1} = $section_ref;
  5098. }
  5099. $section_top = $section_ref;
  5100. }
  5101. else
  5102. {
  5103. $sections{$section_ref->{'sec_num'}} = $section_ref;
  5104. }
  5105. merge_element_before_anything($section_ref);
  5106. if ($state->{'node_ref'})
  5107. {
  5108. $section_ref->{'node_ref'} = $state->{'node_ref'};
  5109. push @{$state->{'node_ref'}->{'sections'}}, $section_ref;
  5110. }
  5111. if ($state->{'node_ref'} and !exists($state->{'node_ref'}->{'with_section'}))
  5112. {
  5113. my $node_ref = $state->{'node_ref'};
  5114. $section_ref->{'with_node'} = $node_ref;
  5115. $section_ref->{'titlefont'} = $node_ref->{'titlefont'};
  5116. $node_ref->{'with_section'} = $section_ref;
  5117. }
  5118. if (! $name and $section_ref->{'level'})
  5119. {
  5120. line_warn (sprintf(__("\@%s requires an argument"), $tag), $line_nr);
  5121. }
  5122. push @sections_list, $section_ref;
  5123. push @all_elements, $section_ref;
  5124. $state->{'heading_element'} = $section_ref;
  5125. $state->{'current_element'} = $section_ref;
  5126. $state->{'place'} = $section_ref->{'current_place'};
  5127. ################# debug
  5128. my $node_ref = "NO NODE";
  5129. my $node_texi ='';
  5130. if ($state->{'node_ref'})
  5131. {
  5132. $node_ref = $state->{'node_ref'};
  5133. $node_texi = $state->{'node_ref'}->{'texi'};
  5134. }
  5135. print STDERR "# pass_structure node($node_ref)$node_texi, tag \@$tag($section_ref->{'level'}) ref $section_ref, num,id $section_ref->{'sec_num'},$section_ref->{'id'}\n $name\n"
  5136. if $T2H_DEBUG & $DEBUG_ELEMENTS;
  5137. ################# end debug
  5138. }
  5139. }
  5140. elsif ($cline =~ /^\@insertcopying\s*/)
  5141. {
  5142. @added_lines = @{$region_lines{'copying'}};
  5143. @added_numbers = @{$region_line_nrs{'copying'}};
  5144. unshift (@$texi_lines, @added_lines);
  5145. unshift (@$lines_numbers, @added_numbers);
  5146. next;
  5147. }
  5148. if (exists($state->{'region_lines'}))
  5149. {
  5150. push @{$region_lines{$state->{'region_lines'}->{'format'}}}, @added_lines;
  5151. if ($Texi2HTML::Config::region_formats_kept{$state->{'region_lines'}->{'format'}})
  5152. { # the region is kept in the document in addition with
  5153. # being put in the appropriate region_lines entry.
  5154. push @doc_lines, @added_lines;
  5155. push @doc_numbers, @added_numbers;
  5156. }
  5157. }
  5158. else
  5159. {
  5160. push @doc_lines, @added_lines;
  5161. push @doc_numbers, @added_numbers;
  5162. }
  5163. next;
  5164. }
  5165. }
  5166. if (scan_structure ($cline, \$text, \@stack, $state, $line_nr))
  5167. {
  5168. if (!exists($state->{'region_lines'}) or $Texi2HTML::Config::region_formats_kept{$state->{'region_lines'}->{'format'}})
  5169. {
  5170. push (@doc_numbers, $line_nr);
  5171. }
  5172. if (exists($state->{'region_lines'}))
  5173. {
  5174. push @{$region_line_nrs{$state->{'region_lines'}->{'format'}}}, $line_nr unless ($state->{'region_lines'}->{'first_line'});
  5175. }
  5176. }
  5177. next if (scalar(@stack) or $state->{'in_deff_line'});
  5178. $cline = $text;
  5179. $text = '';
  5180. next if (!defined($cline));
  5181. if ($state->{'region_lines'})
  5182. {
  5183. # the first line is like @copying, it is not put in the region
  5184. # lines
  5185. push @{$region_lines{$state->{'region_lines'}->{'format'}}}, split_lines($cline) unless ($state->{'region_lines'}->{'first_line'});
  5186. delete $state->{'region_lines'}->{'first_line'};
  5187. push @doc_lines, split_lines($cline) if ($Texi2HTML::Config::region_formats_kept{$state->{'region_lines'}->{'format'}});
  5188. }
  5189. else
  5190. {
  5191. push @doc_lines, split_lines($cline);
  5192. }
  5193. }
  5194. if (@stack)
  5195. {# close stack at the end of pass structure
  5196. close_stack_structure(\$text, \@stack, $state, $line_nr);
  5197. if ($text)
  5198. {
  5199. if (!exists($state->{'region_lines'}) or $Texi2HTML::Config::region_formats_kept{$state->{'region_lines'}->{'format'}})
  5200. {
  5201. push @doc_lines, split_lines($text);
  5202. }
  5203. if (exists($state->{'region_lines'}))
  5204. {
  5205. push @{$region_lines{$state->{'region_lines'}->{'format'}}},
  5206. split_lines($text);
  5207. }
  5208. }
  5209. }
  5210. #line_warn ("Expected $state->{'region_lines'}->{'number'} \@end $state->{'region_lines'}->{'format'}", $line_nr) if (exists($state->{'region_lines'}));
  5211. line_error (sprintf(__("Expected \@end %s"), $state->{'region_lines'}->{'format'}), $line_nr) if (exists($state->{'region_lines'}));
  5212. print STDERR "# end of pass structure\n" if $T2H_VERBOSE;
  5213. # To remove once they are handled
  5214. #print STDERR "No node nor section, texi2html won't be able to place things rightly\n" if ($element_before_anything->{'place'} and @{$element_before_anything->{'place'}});
  5215. return (\@doc_lines, \@doc_numbers);
  5216. }
  5217. # split line at end of line and put each resulting line in an array
  5218. # FIXME there must be a more perlish way to do it... Not a big deal
  5219. # as long as it work
  5220. sub split_lines($)
  5221. {
  5222. my $line = shift;
  5223. my @result = ();
  5224. return @result if (!defined($line));
  5225. my $i = 0;
  5226. while ($line ne '')
  5227. {
  5228. $result[$i] = '';
  5229. $line =~ s/^(.*)//;
  5230. $result[$i] .= $1;
  5231. $result[$i] .= "\n" if ($line =~ s/^\n//);
  5232. #print STDERR "$i: $result[$i]";
  5233. $i++;
  5234. }
  5235. return @result;
  5236. }
  5237. # handle @documentlanguage
  5238. sub do_documentlanguage($$$$)
  5239. {
  5240. my $command = shift;
  5241. my $line = shift;
  5242. my $silent = shift;
  5243. my $line_nr = shift;
  5244. my $language_change_succes = 0;
  5245. if ($line =~ s/\s+(\w+)\s*//)
  5246. {
  5247. my $lang = $1;
  5248. my $prev_lang = get_conf('documentlanguage');
  5249. # This won't be done if the documentlanguage was set on the command line
  5250. if (set_from_document('documentlanguage', $lang))
  5251. {
  5252. warn_unknown_language ($lang, $line_nr) unless ($silent);
  5253. $language_change_succes = set_document_language($lang, $line_nr);
  5254. if (!$language_change_succes)
  5255. { # reset previous documentlanguage. Cannot happen in the default
  5256. # gettext-like framework.
  5257. set_from_document('documentlanguage', $prev_lang);
  5258. line_warn (sprintf(__("Translations for `%s' not found. Reverting to `%s'"),$lang, $prev_lang), $line_nr) unless ($silent);
  5259. }
  5260. }
  5261. # FIXME warn about stuff remaining on the line?
  5262. }
  5263. return $language_change_succes;
  5264. }
  5265. # actions that should be done in more than one pass. In fact most are not
  5266. # to be done in pass_texi. The $pass argument is the number of the pass,
  5267. # 0 for pass_texi, 1 for pass_structure, 2 for pass_text
  5268. sub common_misc_commands($$$$)
  5269. {
  5270. my $command = shift;
  5271. my $line = shift;
  5272. my $pass = shift;
  5273. my $line_nr = shift;
  5274. # for error messages
  5275. my $cline = $line;
  5276. chomp($cline);
  5277. $cline =~ s/^\s*//;
  5278. # track variables
  5279. if ($command eq 'set')
  5280. {
  5281. if ($line =~ /^(\s+)($VARRE)(\s+)(.*)$/)
  5282. {
  5283. $value{$2} = $4;
  5284. }
  5285. else
  5286. {
  5287. line_error (sprintf(__("%c%s requires a name"), ord('@'), $command), $line_nr) if (!$pass);
  5288. }
  5289. }
  5290. elsif ($command eq 'clear')
  5291. {
  5292. if ($line =~ /^(\s+)($VARRE)/)
  5293. {
  5294. delete $value{$2};
  5295. }
  5296. else
  5297. {
  5298. line_error (sprintf(__("%c%s requires a name"), ord('@'), $command), $line_nr) if (!$pass);
  5299. }
  5300. }
  5301. elsif ($command eq 'clickstyle')
  5302. {
  5303. if ($line =~ s/^\s+@([^\s\{\}\@]+)({})?\s*//)
  5304. {
  5305. set_from_document($command, $1);
  5306. # FIXME warn about what remains on the line?
  5307. }
  5308. else
  5309. {
  5310. line_error (sprintf(__("\@%s should only accept a \@-command as argument, not `%s'"), $command, $cline), $line_nr) if ($pass == 1);
  5311. }
  5312. }
  5313. elsif ($command eq 'novalidate')
  5314. {
  5315. set_from_document($command, 1);
  5316. }
  5317. if ($pass)
  5318. { # these commands are only taken into account here in pass_structure 1
  5319. # and pass_text 2
  5320. if ($command eq 'setfilename')
  5321. {
  5322. my $filename = trim_comment_spaces($line, "\@$command");
  5323. $filename = substitute_line($filename, "\@$command",{'code_style' => 1, 'remove_texi' => 1});
  5324. if ($filename ne '')
  5325. {
  5326. set_from_document($command, $filename);
  5327. }
  5328. }
  5329. elsif ($command eq 'paragraphindent')
  5330. {
  5331. if ($line =~ /\s+([\w\-]+)[^\w\-]/)
  5332. {
  5333. set_paragraphindent ($1, 0, $line_nr, $pass);
  5334. }
  5335. else
  5336. {
  5337. set_paragraphindent ($line, 0, $line_nr, $pass);
  5338. }
  5339. }
  5340. elsif ($command eq 'firstparagraphindent')
  5341. {
  5342. if (($line =~ /^\s+(none)[^\w\-]/) or ($line =~ /^\s+(insert)[^\w\-]/))
  5343. {
  5344. set_from_document($command, $1);
  5345. }
  5346. else
  5347. {
  5348. line_error (sprintf(__("\@firstparagraphindent arg must be `none' or `insert', not `%s'"), $cline), $line_nr) if ($pass == 1);
  5349. }
  5350. }
  5351. elsif ($command eq 'exampleindent')
  5352. {
  5353. if ($line =~ /^\s+([0-9]+)/)
  5354. {
  5355. set_from_document($command, $1);
  5356. }
  5357. elsif ($line =~ /^\s+(asis)[^\w\-]/)
  5358. {
  5359. set_from_document($command, $1);
  5360. }
  5361. else
  5362. {
  5363. line_error (sprintf(__("\@exampleindent arg must be numeric/`asis', not `%s'"), $cline), $line_nr) if ($pass == 1);
  5364. }
  5365. }
  5366. elsif ($command eq 'frenchspacing')
  5367. {
  5368. if (($line =~ /^\s+(on)[^\w\-]/) or ($line =~ /^\s+(off)[^\w\-]/))
  5369. {
  5370. set_from_document($command, $1);
  5371. }
  5372. else
  5373. {
  5374. line_error (sprintf(__("Expected \@%s on or off, not `%s'"), $command, $cline), $line_nr) if ($pass == 1);
  5375. }
  5376. }
  5377. elsif ($command eq 'kbdinputstyle')
  5378. {
  5379. if ($line =~ /\s+([a-z]+)/ and ($1 eq 'code' or $1 eq 'example' or $1 eq 'distinct'))
  5380. {
  5381. set_from_document($command, $1);
  5382. }
  5383. else
  5384. {
  5385. line_error (sprintf(__("\@kbdinputstyle arg must be `code'/`example'/`distinct', not `%s'"), $cline), $line_nr) if ($pass == 1);
  5386. }
  5387. }
  5388. elsif (grep {$command eq $_} ('everyheading', 'everyfooting',
  5389. 'evenheading', 'evenfooting', 'oddheading', 'oddfooting'))
  5390. { # FIXME have a _texi and without texi, and without texi,
  5391. # and expand rightly @this*? And use @| to separate, and give
  5392. # an array for user consumption? This should be done for each new
  5393. # chapter, section, and page. What is a page is not necessarily
  5394. # well defined in html, however...
  5395. # @thisfile is the @include file. Should be in $line_nr.
  5396. my $arg = $line;
  5397. $arg =~ s/^\s+//;
  5398. set_from_document($command, $arg);
  5399. }
  5400. elsif ($command eq 'allowcodebreaks')
  5401. {
  5402. if (($line =~ /^\s+(true)[^\w\-]/) or ($line =~ /^\s+(false)[^\w\-]/))
  5403. {
  5404. set_from_document($command, $1);
  5405. }
  5406. else
  5407. {
  5408. line_error (sprintf(__("\@allowcodebreaks arg must be `true' or `false', not `%s'"), $cline), $line_nr) if ($pass == 1);
  5409. }
  5410. }
  5411. elsif ($command eq 'headings')
  5412. {
  5413. my $valid_arg = 0;
  5414. foreach my $possible_arg (('off','on','single','double',
  5415. 'singleafter','doubleafter'))
  5416. {
  5417. if ($line =~ /^\s+($possible_arg)[^\w\-]/)
  5418. {
  5419. $valid_arg = 1;
  5420. set_from_document($command, $possible_arg);
  5421. last;
  5422. }
  5423. }
  5424. unless ($valid_arg)
  5425. {
  5426. line_error (sprintf(__("Bad argument to \@%s: %s"), $command, $cline), $line_nr) if ($pass == 1);
  5427. }
  5428. }
  5429. elsif ($command eq 'documentlanguage')
  5430. {
  5431. if (do_documentlanguage($command, $line, $pass -1, $line_nr))
  5432. {
  5433. &$Texi2HTML::Config::translate_names();
  5434. set_special_names();
  5435. }
  5436. }
  5437. }
  5438. }
  5439. sub misc_command_texi($$$$)
  5440. {
  5441. my $line = shift;
  5442. my $command = shift;
  5443. my $state = shift;
  5444. my $line_nr = shift;
  5445. my $text;
  5446. my $args;
  5447. my $cline = $line;
  5448. if (!$state->{'ignored'} and !$state->{'arg_expansion'})
  5449. {
  5450. if ($command eq 'documentencoding')
  5451. { # FIXME accept more characters, like @?
  5452. if ($cline =~ s/^(\s+)([\w\-]+)//)
  5453. {
  5454. my $encoding = $2;
  5455. line_warn(sprintf(__("Encoding %s is not a canonical texinfo encoding"), $encoding), $line_nr)
  5456. if (!$Texi2HTML::Config::canonical_texinfo_encodings{lc($encoding)});
  5457. if (set_from_document('documentencoding', $encoding))
  5458. {
  5459. my $from_encoding = encoding_alias($encoding, $line_nr);
  5460. set_from_document('IN_ENCODING', $from_encoding)
  5461. if (defined($from_encoding));
  5462. if (defined($from_encoding) and get_conf('USE_UNICODE'))
  5463. {
  5464. foreach my $file (@{$state->{'files_stack'}})
  5465. {
  5466. binmode($file->{'fh'}, ":encoding($from_encoding)");
  5467. }
  5468. }
  5469. }
  5470. #FIXME error if garbage remains on the line?
  5471. }
  5472. else
  5473. {
  5474. line_error(sprintf(__("\@%s arg must be an encoding"), $command), $line_nr);
  5475. }
  5476. }
  5477. elsif ($command eq 'alias')
  5478. {
  5479. if ($line =~ /(\s+)([a-zA-Z][\w-]*)(\s*=\s*)([a-zA-Z][\w-]*)(\s*)/)
  5480. {
  5481. $alias{$2} = $4;
  5482. }
  5483. else
  5484. {
  5485. line_error (sprintf(__("Bad argument to \@%s"), $command), $line_nr);
  5486. }
  5487. }
  5488. elsif ($command eq 'definfoenclose')
  5489. {
  5490. if ($cline =~ s/^\s+([a-z][\w\-]*)\s*,\s*([^\s]+)\s*,\s*([^\s]+)//)
  5491. {
  5492. $info_enclose{$1} = [ $2, $3 ];
  5493. }
  5494. else
  5495. {
  5496. line_error (sprintf(__("Bad argument to \@%s"), $command), $line_nr);
  5497. } # FIXME warn about garbage remaining on the line?
  5498. }
  5499. else
  5500. {
  5501. if ($command eq 'setfilename' and get_conf('USE_SETFILENAME'))
  5502. { # a double setfillename is removed before calling misc_command_texi
  5503. my $filename = trim_comment_spaces($line, "\@$command");
  5504. $filename = substitute_line($filename, "\@$command",{'code_style' => 1, 'remove_texi' => 1}, $line_nr);
  5505. if ($filename ne '')
  5506. {
  5507. set_from_document($command, $filename);
  5508. # remove extension
  5509. $filename =~ s/\.[^\.]*$//;
  5510. init_with_file_name ($filename) if ($filename ne '');
  5511. }
  5512. }
  5513. # in reality, do only set, clear and clickstyle.
  5514. # though we should never go there for clickstyle...
  5515. common_misc_commands($command, $line, 0, $line_nr);
  5516. }
  5517. }
  5518. ($line, $text, $args) = &$Texi2HTML::Config::preserve_misc_command($line, $command);
  5519. return ($line, $text);
  5520. }
  5521. sub new_content_element($)
  5522. {
  5523. my $command = shift;
  5524. $command = 'shortcontents' if ($command ne 'contents');
  5525. my $element;
  5526. foreach my $key (keys(%{$reference_content_element{$command}}))
  5527. {
  5528. $element->{$key} = $reference_content_element{$command}->{$key};
  5529. }
  5530. return $element;
  5531. }
  5532. # handle misc commands and misc command args
  5533. sub misc_command_structure($$$$)
  5534. {
  5535. my $line = shift;
  5536. my $command = shift;
  5537. my $state = shift;
  5538. my $line_nr = shift;
  5539. my $text;
  5540. my $args;
  5541. # for error messages
  5542. my $cline = $line;
  5543. chomp $cline;
  5544. $cline =~ s/^\s*//;
  5545. if ($command eq 'lowersections')
  5546. {
  5547. my ($sec, $level);
  5548. while (($sec, $level) = each %sec2level)
  5549. {
  5550. $sec2level{$sec} = $level + 1 if ($reference_sec2level{$sec} > 0);
  5551. }
  5552. $state->{'sectioning_base'}--;
  5553. }
  5554. elsif ($command eq 'raisesections')
  5555. {
  5556. my ($sec, $level);
  5557. while (($sec, $level) = each %sec2level)
  5558. {
  5559. $sec2level{$sec} = $level - 1 if ($reference_sec2level{$sec} > 0);
  5560. }
  5561. $state->{'sectioning_base'}++;
  5562. }
  5563. elsif (($command eq 'contents') or ($command eq 'summarycontents') or ($command eq 'shortcontents'))
  5564. {
  5565. if ($command ne 'contents')
  5566. {
  5567. $command = 'shortcontents';
  5568. }
  5569. set_from_document($command, 1);
  5570. my $new_content_element = new_content_element($command);
  5571. push @{$state->{'place'}}, $new_content_element;
  5572. push @{$all_content_elements{$command}}, $new_content_element;
  5573. }
  5574. elsif ($command eq 'dircategory')
  5575. {
  5576. my $arg = trim_comment_spaces ($line, "\@$command");
  5577. $Texi2HTML::THISDOC{"${command}_texi"} = $arg;
  5578. $Texi2HTML::THISDOC{$command} = substitute_line($arg, "\@$command");
  5579. }
  5580. elsif (grep {$_ eq $command} ('settitle','shorttitlepage','title'))
  5581. {
  5582. my $arg = trim_comment_spaces($line, "\@$command");
  5583. $Texi2HTML::THISDOC{$command . '_texi'} = $arg;
  5584. $Texi2HTML::THISDOC{$command . '_line_nr'} = $line_nr;
  5585. # FIXME backward compatibility. Obsoleted in nov 2009.
  5586. $value{"_$command"} = $arg;
  5587. if ($command eq 'title')
  5588. { # FIXME This was obsoleted in jun 2007
  5589. $Texi2HTML::THISDOC{"${command}s_texi"} = [ $arg ];
  5590. }
  5591. }
  5592. elsif (grep {$_ eq $command} ('author','subtitle'))
  5593. {
  5594. my $arg = trim_comment_spaces($line, "\@$command");
  5595. if ($state->{'region'} and $state->{'region'} eq 'titlepage')
  5596. {
  5597. $Texi2HTML::THISDOC{$command . '_texi'} .= $arg . "\n";
  5598. push @{$Texi2HTML::THISDOC{"${command}s_texi"}}, $arg;
  5599. push @{$Texi2HTML::THISDOC{"${command}s_line_nr"}}, $line_nr;
  5600. # FIXME backward compatibility. Obsoleted in nov 2009.
  5601. $value{"_$command"} .= $arg . "\n";
  5602. }
  5603. }
  5604. elsif ($command eq 'synindex' || $command eq 'syncodeindex')
  5605. {
  5606. if ($line =~ /^\s+(\w+)\s+(\w+)/)
  5607. {
  5608. my $index_from = $1;
  5609. my $index_to = $2;
  5610. line_error (sprintf(__("Unknown from index `%s' in \@%s"), $index_from, $command), $line_nr)
  5611. unless $index_names{$index_from};
  5612. line_error (sprintf(__("Unknown to index name `%s' in \@%s"), $index_to, $command), $line_nr)
  5613. unless $index_names{$index_to};
  5614. if ($index_names{$index_from} and $index_names{$index_to})
  5615. {
  5616. my $in_code = 0;
  5617. $in_code = 1 if ($command eq 'syncodeindex');
  5618. my $current_to = $index_to;
  5619. while ($current_to ne $index_from and $Texi2HTML::THISDOC{'merged_index'}->{$current_to})
  5620. {
  5621. $current_to = $Texi2HTML::THISDOC{'merged_index'}->{$current_to};
  5622. }
  5623. if ($current_to ne $index_from)
  5624. {
  5625. foreach my $prefix (keys(%{$index_names{$index_from}}))
  5626. {
  5627. $index_names{$current_to}->{$prefix} = $in_code;
  5628. $index_prefix_to_name{$prefix} = $current_to;
  5629. }
  5630. $Texi2HTML::THISDOC{'merged_index'}->{$index_from} = $current_to;
  5631. }
  5632. push @{$Texi2HTML::THISDOC{$command}}, [$index_from,$index_to];
  5633. }
  5634. }
  5635. else
  5636. {
  5637. line_error (sprintf(__("Bad argument to \@%s: %s"), $command, $cline), $line_nr);
  5638. }
  5639. }
  5640. elsif ($command eq 'defindex' || $command eq 'defcodeindex')
  5641. {
  5642. if ($line =~ /^\s+(\w+)\s*$/)
  5643. {
  5644. my $name = $1;
  5645. if ($forbidden_index_name{$name})
  5646. {
  5647. line_error(sprintf(__("Reserved index name %s"),$name), $line_nr);
  5648. }
  5649. else
  5650. {
  5651. my $in_code = 0;
  5652. $in_code = 1 if ($command eq 'defcodeindex');
  5653. # FIXME this leads to spurious error message in hello_nodes
  5654. #if (defined($index_names{$name}))
  5655. #{
  5656. # line_error(sprintf(__("Index `%s' already exists"),$name), $line_nr);
  5657. #}
  5658. $index_names{$name}->{$name} = $in_code;
  5659. $index_prefix_to_name{$name} = $name;
  5660. push @{$Texi2HTML::THISDOC{$command}}, $name;
  5661. }
  5662. }
  5663. else
  5664. {
  5665. line_error (sprintf(__("Bad argument to \@%s: %s"), $command, $cline), $line_nr);
  5666. }
  5667. }
  5668. elsif (grep {$_ eq $command} ('everyheadingmarks','everyfootingmarks',
  5669. 'evenheadingmarks','oddheadingmarks','evenfootingmarks','oddfootingmarks'))
  5670. {
  5671. if (($line =~ /^\s+(top)[^\w\-]/) or ($line =~ /^\s+(bottom)[^\w\-]/))
  5672. {
  5673. set_from_document($command, $1);
  5674. }
  5675. else
  5676. {
  5677. line_error (sprintf(__("\@%s arg must be `top' or `bottom', not `%s'"), $command, $cline), $line_nr);
  5678. }
  5679. }
  5680. elsif ($command eq 'fonttextsize')
  5681. {
  5682. if (($line =~ /^\s+(10)[^\w\-]/) or ($line =~ /^\s+(11)[^\w\-]/))
  5683. {
  5684. set_from_document($command, $1);
  5685. }
  5686. else
  5687. {
  5688. line_error (sprintf(__("Only \@%s 10 or 11 is supported, not `%s'"),$command, $cline), $line_nr);
  5689. }
  5690. }
  5691. elsif ($command eq 'pagesizes')
  5692. {
  5693. if ($line =~ /^\s+(.*)\s*$/)
  5694. {
  5695. set_from_document($command, $1);
  5696. }
  5697. }
  5698. elsif ($command eq 'footnotestyle')
  5699. {
  5700. if ($line =~ /^\s+([a-z]+)[^\w\-]/)
  5701. {
  5702. set_footnote_style ($1, 0, $line_nr);
  5703. }
  5704. else
  5705. {
  5706. set_footnote_style ($line, 0, $line_nr);
  5707. }
  5708. }
  5709. elsif ($command eq 'setchapternewpage')
  5710. {
  5711. if (($line =~ /^\s+(on)[^\w\-]/) or ($line =~ /^\s+(off)[^\w\-]/)
  5712. or ($line =~ /^\s+(odd)[^\w\-]/))
  5713. {
  5714. set_from_document($command, $1);
  5715. }
  5716. else
  5717. {
  5718. line_error (sprintf(__("\@%s arg must be `on', `off' or `odd', not `%s'"), $command, $cline), $line_nr);
  5719. }
  5720. }
  5721. elsif ($command eq 'setcontentsaftertitlepage' or $command eq 'setshortcontentsaftertitlepage')
  5722. {
  5723. set_from_document($command, 1);
  5724. }
  5725. elsif ($command eq 'need')
  5726. { # only a warning
  5727. unless (($line =~ /^\s+([0-9]+(\.[0-9]*)?)[^\w\-]/) or
  5728. ($line =~ /^\s+(\.[0-9]+)[^\w\-]/))
  5729. {
  5730. line_error (sprintf(__("Bad argument to \@%s: %s"), $command, $cline), $line_nr);
  5731. }
  5732. }
  5733. else
  5734. {
  5735. common_misc_commands($command, $line, 1, $line_nr);
  5736. }
  5737. ($text, $line, $args) = &$Texi2HTML::Config::preserve_misc_command($line, $command);
  5738. return ($text, $line);
  5739. }
  5740. sub set_special_names()
  5741. {
  5742. $Texi2HTML::NAME{'About'} = gdt('About This Document');
  5743. $Texi2HTML::NAME{'Contents'} = gdt('Table of Contents');
  5744. $Texi2HTML::NAME{'Overview'} = gdt('Short Table of Contents');
  5745. $Texi2HTML::NAME{'Footnotes'} = gdt('Footnotes');
  5746. $Texi2HTML::NO_TEXI{'About'} = gdt('About This Document', {}, {'remove_texi' => 1} );
  5747. $Texi2HTML::NO_TEXI{'Contents'} = gdt('Table of Contents', {}, {'remove_texi' => 1} );
  5748. $Texi2HTML::NO_TEXI{'Overview'} = gdt('Short Table of Contents', {}, {'remove_texi' => 1} );
  5749. $Texi2HTML::NO_TEXI{'Footnotes'} = gdt('Footnotes', {}, {'remove_texi' => 1} );
  5750. $Texi2HTML::SIMPLE_TEXT{'About'} = gdt('About This Document', {}, {'simple_format' => 1});
  5751. $Texi2HTML::SIMPLE_TEXT{'Contents'} = gdt('Table of Contents',{}, {'simple_format' => 1});
  5752. $Texi2HTML::SIMPLE_TEXT{'Overview'} = gdt('Short Table of Contents', {}, {'simple_format' => 1});
  5753. $Texi2HTML::SIMPLE_TEXT{'Footnotes'} = gdt('Footnotes', {},{'simple_format' => 1});
  5754. }
  5755. sub enter_author_command($$$$$$)
  5756. {
  5757. my $command = shift;
  5758. my $texi = shift;
  5759. my $text = shift;
  5760. my $stack = shift;
  5761. my $state = shift;
  5762. my $line_nr = shift;
  5763. $texi = trim_comment_spaces($texi, "\@$command");
  5764. $text = substitute_line($texi, "\@$command", duplicate_formatting_state($state)) if (!defined($text));
  5765. my $top_format = top_stack($stack, 2);
  5766. if (defined($top_format) and $format_type{$top_format->{'format'}} eq 'quotation')
  5767. {
  5768. push @{$top_format->{'quote_authors'}}, {'author_texi' => $texi, 'author_text' => $text};
  5769. }
  5770. elsif (!$state->{'region'} or $state->{'region'} ne 'titlepage')
  5771. {
  5772. line_warn (sprintf(__("\@%s not meaningful outside `\@titlepage' and `\@quotation' environments"), $command), $line_nr);
  5773. }
  5774. }
  5775. # return the line after removing things according to misc_command map.
  5776. # if the skipped command has an effect it is done here
  5777. # this is used during pass_text
  5778. sub misc_command_text($$$$$$)
  5779. {
  5780. my $line = shift;
  5781. my $command = shift;
  5782. my $stack = shift;
  5783. my $state = shift;
  5784. my $text = shift;
  5785. my $line_nr = shift;
  5786. my ($skipped, $remaining, $args, $result);
  5787. # The strange condition associated with 'keep_texi' is
  5788. # there because for an argument appearing on an @itemize
  5789. # line (we're in 'check_item'), meant to be prepended to an
  5790. # @item we don't want to keep @c or @comment as otherwise it
  5791. # eats the @item line. Other commands could do that too but
  5792. # then the user deserves what he gets.
  5793. if ($state->{'keep_texi'} and
  5794. (!$state->{'check_item'} or ($command ne 'c' and $command ne 'comment')))
  5795. {
  5796. ($remaining, $skipped, $args) = &$Texi2HTML::Config::preserve_misc_command($line, $command);
  5797. add_prev($text, $stack, "\@$command". $skipped);
  5798. return $remaining;
  5799. }
  5800. ($remaining, $skipped, $args) = &$Texi2HTML::Config::preserve_misc_command($line, $command);
  5801. if ($state->{'remove_texi'})
  5802. {
  5803. ($command, $line, $result) = &$Texi2HTML::Config::misc_command_line_texi($command, $line, $args, $stack, $state);
  5804. }
  5805. else
  5806. {
  5807. ($command, $line, $result) = &$Texi2HTML::Config::misc_command_line($command, $line, $args, $stack, $state);
  5808. }
  5809. enter_author_command ($command, $line, $result, $stack, $state, $line_nr) if ($command eq 'author');
  5810. # for error messages
  5811. my $cline = $line;
  5812. $cline =~ s/^\s*//;
  5813. chomp $cline;
  5814. # if it is true the command args are kept so the user can modify how
  5815. # they are skipped and handle them as unknown @-commands. Nowadays, it is
  5816. # not that interesting since using misc_command_line above should do
  5817. # about the same more simply.
  5818. my $keep = $Texi2HTML::Config::misc_command{$command}->{'keep'};
  5819. if ($command eq 'sp')
  5820. {
  5821. my $sp_number;
  5822. if ($line =~ /^\s+(\d+)\s/)
  5823. {
  5824. $sp_number = $1;
  5825. }
  5826. elsif ($line =~ /(\s*)$/)
  5827. {
  5828. $sp_number = '';
  5829. }
  5830. else
  5831. {
  5832. line_error (sprintf(__("\@sp requires a positive numeric argument, not `%s'"), $cline), $line_nr);
  5833. }
  5834. $sp_number = 1 if ($sp_number eq '');
  5835. if (!$state->{'remove_texi'})
  5836. {
  5837. add_prev($text, $stack, &$Texi2HTML::Config::sp($sp_number, $state->{'preformatted'}));
  5838. }
  5839. }
  5840. elsif($command eq 'verbatiminclude' and !$keep)
  5841. {
  5842. if ($line =~ /\s+(.+)/)
  5843. {
  5844. my $arg = $1;
  5845. $arg = trim_around_spaces($arg);
  5846. my $file_name = substitute_line($arg, "\@$command", {'code_style' => 1});
  5847. my $file = locate_include_file($file_name);
  5848. if (defined($file))
  5849. {
  5850. if (!open(VERBINCLUDE, $file))
  5851. {
  5852. line_error (sprintf(__("Cannot read %s: %s"), $file, $!), $line_nr);
  5853. }
  5854. else
  5855. {
  5856. my $verb_text = '';
  5857. while (my $verb_line = <VERBINCLUDE>)
  5858. {
  5859. $verb_text .= $verb_line;
  5860. }
  5861. if ($state->{'remove_texi'})
  5862. {
  5863. add_prev ($text, $stack, &$Texi2HTML::Config::raw_no_texi('verbatiminclude', $verb_text));
  5864. }
  5865. else
  5866. {
  5867. add_prev($text, $stack, &$Texi2HTML::Config::raw('verbatiminclude', $verb_text, $line_nr));
  5868. }
  5869. close VERBINCLUDE;
  5870. }
  5871. }
  5872. else
  5873. {
  5874. line_error (sprintf(__("\@%s: Cannot find %s"), $command, $file_name), $line_nr);
  5875. }
  5876. }
  5877. else
  5878. {
  5879. line_error (sprintf(__("Bad argument to \@%s: %s"), $command, $cline), $line_nr);
  5880. }
  5881. }
  5882. elsif ($command eq 'indent' or $command eq 'noindent')
  5883. {
  5884. $state->{'paragraph_indent'} = $command;
  5885. }
  5886. else
  5887. {
  5888. common_misc_commands($command, $line, 2, $line_nr);
  5889. }
  5890. return ($skipped.$remaining, $result) if ($keep);
  5891. return ($remaining, $result);
  5892. }
  5893. # merge the things appearing before the first @node or sectioning command
  5894. # (held by element_before_anything) with the current element
  5895. # do that only once.
  5896. sub merge_element_before_anything($)
  5897. {
  5898. my $element = shift;
  5899. if (exists($element_before_anything->{'place'}))
  5900. {
  5901. $element->{'current_place'} = $element_before_anything->{'place'};
  5902. delete $element_before_anything->{'place'};
  5903. foreach my $placed_thing (@{$element->{'current_place'}})
  5904. {
  5905. $placed_thing->{'element'} = $element if (exists($placed_thing->{'element'}));
  5906. }
  5907. }
  5908. # this is certainly redundant with the above condition, but cleaner
  5909. # that way
  5910. if (exists($element_before_anything->{'titlefont'}))
  5911. {
  5912. $element->{'titlefont'} = $element_before_anything->{'titlefont'};
  5913. delete $element_before_anything->{'titlefont'};
  5914. }
  5915. }
  5916. # find menu_prev, menu_up... for a node in menu
  5917. sub menu_entry_texi($$$)
  5918. {
  5919. my $node = shift;
  5920. my $state = shift;
  5921. my $line_nr = shift;
  5922. return if ($state->{'direntry'});
  5923. my $node_menu_ref = {};
  5924. if (exists($nodes{$node}))
  5925. {
  5926. $node_menu_ref = $nodes{$node};
  5927. }
  5928. else
  5929. {
  5930. $nodes{$node} = $node_menu_ref;
  5931. $node_menu_ref->{'texi'} = $node;
  5932. $node_menu_ref->{'external_node'} = 1 if ($node =~ /^\(.+\)/);
  5933. }
  5934. return if ($state->{'detailmenu'});
  5935. if ($state->{'node_ref'})
  5936. {
  5937. if ($node_menu_ref->{'menu_up'} and !$node_menu_ref->{'external_node'})
  5938. {
  5939. # This is not an error. This is used a lot in real life manuals
  5940. #line_warn ("Double entry in menu for `$node' (also below `$node_menu_ref->{'menu_up'}->{'texi'}')", $line_nr);
  5941. }
  5942. $node_menu_ref->{'menu_up'} = $state->{'node_ref'};
  5943. $node_menu_ref->{'menu_up_hash'}->{$state->{'node_ref'}->{'texi'}} = 1;
  5944. }
  5945. if ($state->{'prev_menu_node'})
  5946. {
  5947. $node_menu_ref->{'menu_prev'} = $state->{'prev_menu_node'};
  5948. $state->{'prev_menu_node'}->{'menu_next'} = $node_menu_ref;
  5949. }
  5950. elsif ($state->{'node_ref'} and !$state->{'node_ref'}->{'menu_child'})
  5951. {
  5952. $state->{'node_ref'}->{'menu_child'} = $node_menu_ref;
  5953. }
  5954. $state->{'prev_menu_node'} = $node_menu_ref;
  5955. }
  5956. my @index_labels; # array corresponding with @?index commands
  5957. # constructed during pass_structure, used to
  5958. # put labels in pass_text
  5959. my @unknown_index_index_entries; # array of index entries not associated
  5960. # with any index
  5961. sub sorted_line($)
  5962. {
  5963. my $line = shift;
  5964. $::texi_map_ref = \%Texi2HTML::Config::sorting_things_map;
  5965. my $result = remove_texi($line);
  5966. $::texi_map_ref = \%Texi2HTML::Config::texi_map;
  5967. return $result;
  5968. }
  5969. sub prepare_indices()
  5970. {
  5971. #print STDERR "Do splitting of index letters, once.\n";
  5972. foreach my $index_name(keys %{$Texi2HTML::THISDOC{'index_entries_array'}})
  5973. {
  5974. #print STDERR "$Texi2HTML::THISDOC{'index_entries_array'}->{$index_name}) letters\n";
  5975. my %letters_hash;
  5976. foreach my $index_entry (@{$Texi2HTML::THISDOC{'index_entries_array'}->{$index_name}})
  5977. {
  5978. my $key = sorted_line($index_entry->{'texi'});
  5979. $index_entry->{'key'} = $key;
  5980. my $letter = uc(substr($key, 0, 1));
  5981. push @{$letters_hash{$letter}}, $index_entry;
  5982. }
  5983. # use cmp if only letters or only symbols, otherwise symbols before
  5984. # letters
  5985. foreach my $letter (sort {
  5986. ((($a =~ /^[[:alpha:]]/ and $b =~ /^[[:alpha:]]/) or
  5987. ($a !~ /^[[:alpha:]]/ and $b !~ /^[[:alpha:]]/)) && $a cmp $b)
  5988. || ($a =~ /^[[:alpha:]]/ && 1) || -1 } (keys %letters_hash))
  5989. {
  5990. # FIXME sort without uc?
  5991. # This sorts the entries for a given letter
  5992. my @sorted_letter_entries = (sort {uc($a->{'key'}) cmp uc($b->{'key'})} (@{$letters_hash{$letter}}));
  5993. push @{$Texi2HTML::THISDOC{'index_letters_array'}->{$index_name}}, { 'letter' => $letter, 'entries' => \@sorted_letter_entries };
  5994. }
  5995. }
  5996. # generate the keys for index sorting also for the entries not
  5997. # associated with an index.
  5998. foreach my $index_entry_without_index (@unknown_index_index_entries)
  5999. {
  6000. my $key = sorted_line($index_entry_without_index->{'texi'});
  6001. $index_entry_without_index->{'key'} = $key;
  6002. }
  6003. Texi2HTML::Config::t2h_default_init_split_indices();
  6004. }
  6005. # This function is used to construct link names from node names as
  6006. # specified for texinfo
  6007. sub cross_manual_links()
  6008. {
  6009. my @all_index_entries;
  6010. foreach my $index_name (sort(keys(%{$Texi2HTML::THISDOC{'index_entries_array'}})))
  6011. {
  6012. push @all_index_entries, @{$Texi2HTML::THISDOC{'index_entries_array'}->{$index_name}};
  6013. }
  6014. print STDERR "# Doing ".scalar(keys(%nodes))." cross manual links ".
  6015. scalar(@all_index_entries). " index entries\n"
  6016. if ($T2H_DEBUG);
  6017. $::simple_map_texi_ref = \%cross_ref_simple_map_texi;
  6018. $::style_map_texi_ref = \%cross_ref_style_map_texi;
  6019. $::texi_map_ref = \%cross_ref_texi_map;
  6020. my $normal_text_kept = $Texi2HTML::Config::normal_text;
  6021. $Texi2HTML::Config::normal_text = \&Texi2HTML::Config::t2h_cross_manual_normal_text;
  6022. my $style_kept = $Texi2HTML::Config::style;
  6023. $Texi2HTML::Config::style = \&Texi2HTML::Config::T2H_GPL_style;
  6024. foreach my $key (sort(keys(%nodes)))
  6025. {
  6026. my $node = $nodes{$key};
  6027. #print STDERR "CROSS_MANUAL:$key,$node\n";
  6028. if (!defined($node->{'texi'}))
  6029. {
  6030. ###################### debug section
  6031. foreach my $key (keys(%$node))
  6032. {
  6033. #print STDERR "$key:$node->{$key}!!!\n";
  6034. }
  6035. ###################### end debug section
  6036. }
  6037. else
  6038. {
  6039. $node->{'cross_manual_target'} = remove_texi($node->{'texi'});
  6040. if ($node->{'cross_manual_target'} !~ /\S/)
  6041. {
  6042. line_error (sprintf(__("Empty node name after expansion `%s'"), $node->{'texi'}), $node->{'line_nr'});
  6043. $node->{'cross_manual_target'} = 't_0';
  6044. $node->{'cross_manual_file'} = 't_0';
  6045. }
  6046. elsif (get_conf('USE_UNICODE'))
  6047. {
  6048. $node->{'cross_manual_target'} = Unicode::Normalize::NFC($node->{'cross_manual_target'});
  6049. if (get_conf('TRANSLITERATE_FILE_NAMES') and get_conf('USE_UNIDECODE'))
  6050. {
  6051. $node->{'cross_manual_file'} =
  6052. unicode_to_protected(unicode_to_transliterate($node->{'cross_manual_target'}));
  6053. }
  6054. $node->{'cross_manual_target'} =
  6055. unicode_to_protected($node->{'cross_manual_target'});
  6056. }
  6057. #print STDERR "CROSS_MANUAL_TARGET $node->{'cross_manual_target'}\n";
  6058. unless ($node->{'external_node'})
  6059. {
  6060. if (exists($cross_reference_nodes{$node->{'cross_manual_target'}}))
  6061. {
  6062. my $other_node_array = $cross_reference_nodes{$node->{'cross_manual_target'}};
  6063. my $node_seen;
  6064. foreach my $other_node (@{$other_node_array})
  6065. { # find the first node seen for the error message
  6066. $node_seen = $other_node;
  6067. last if ($nodes{$other_node}->{'seen'})
  6068. }
  6069. my $other_node_line_nr = $nodes{$node_seen}->{'line_nr'};
  6070. if (defined($other_node_line_nr))
  6071. {
  6072. msg_error ("Node equivalent with `$node->{'texi'}' already used `$node_seen' ".format_line_number($other_node_line_nr), $node->{'line_nr'});
  6073. }
  6074. else
  6075. {
  6076. msg_error ("Node equivalent with `$node->{'texi'}' already used `$node_seen'", $node->{'line_nr'});
  6077. }
  6078. push @{$other_node_array}, $node->{'texi'};
  6079. }
  6080. else
  6081. {
  6082. push @{$cross_reference_nodes{$node->{'cross_manual_target'}}}, $node->{'texi'};
  6083. }
  6084. }
  6085. }
  6086. }
  6087. if (get_conf('TRANSLITERATE_FILE_NAMES') and
  6088. (!get_conf('USE_UNICODE') or !get_conf('USE_UNIDECODE')))
  6089. {
  6090. $::style_map_texi_ref = \%cross_transliterate_style_map_texi;
  6091. $::texi_map_ref = \%cross_transliterate_texi_map;
  6092. $Texi2HTML::Config::normal_text = \&Texi2HTML::Config::t2h_cross_manual_normal_text_transliterate if (!get_conf('USE_UNICODE'));
  6093. foreach my $key (keys(%nodes))
  6094. {
  6095. my $node = $nodes{$key};
  6096. #print STDERR "TRANSLITERATE:$key,$node\n";
  6097. if (defined($node->{'texi'}))
  6098. {
  6099. $node->{'cross_manual_file'} = remove_texi($node->{'texi'});
  6100. if ($node->{'cross_manual_file'} !~ /\S/)
  6101. {
  6102. $node->{'cross_manual_file'} = 't_0';
  6103. }
  6104. elsif (get_conf('USE_UNICODE'))
  6105. {
  6106. $node->{'cross_manual_file'} = unicode_to_protected(unicode_to_transliterate($node->{'cross_manual_file'}));
  6107. }
  6108. }
  6109. }
  6110. foreach my $entry (@all_index_entries, values(%sections), values(%headings))
  6111. {
  6112. #print STDERR "TRANSLITERATE($entry) $entry->{'texi'}\n";
  6113. $entry->{'cross'} = remove_texi($entry->{'texi'});
  6114. $entry->{'cross'} = unicode_to_protected(unicode_to_transliterate($entry->{'cross'})) if (get_conf('USE_UNICODE'));
  6115. }
  6116. }
  6117. else
  6118. {
  6119. foreach my $entry (@all_index_entries, values(%sections), values(%headings))
  6120. {
  6121. $entry->{'cross'} = remove_texi($entry->{'texi'});
  6122. if (get_conf('USE_UNICODE'))
  6123. {
  6124. $entry->{'cross'} = Unicode::Normalize::NFC($entry->{'cross'});
  6125. if (get_conf('TRANSLITERATE_FILE_NAMES') and get_conf('USE_UNIDECODE')) # USE_UNIDECODE is redundant
  6126. {
  6127. $entry->{'cross'} =
  6128. unicode_to_protected(unicode_to_transliterate($entry->{'cross'}));
  6129. }
  6130. else
  6131. {
  6132. $entry->{'cross'} =
  6133. unicode_to_protected($entry->{'cross'});
  6134. }
  6135. }
  6136. }
  6137. }
  6138. $Texi2HTML::Config::normal_text = $normal_text_kept;
  6139. $Texi2HTML::Config::style = $style_kept;
  6140. $::simple_map_texi_ref = \%Texi2HTML::Config::simple_map_texi;
  6141. $::style_map_texi_ref = \%Texi2HTML::Config::style_map_texi;
  6142. $::texi_map_ref = \%Texi2HTML::Config::texi_map;
  6143. }
  6144. # This function is used to construct a link name from a node name as
  6145. # specified for texinfo
  6146. sub cross_manual_line($;$)
  6147. {
  6148. my $text = shift;
  6149. my $transliterate = shift;
  6150. #print STDERR "cross_manual_line $text\n";
  6151. #print STDERR "remove_texi text ". remove_texi($text)."\n\n\n";
  6152. if ($text !~ /\S/)
  6153. {
  6154. # special case for empty node/ref
  6155. return ('t_0', 't_0');
  6156. }
  6157. $::simple_map_texi_ref = \%cross_ref_simple_map_texi;
  6158. $::style_map_texi_ref = \%cross_ref_style_map_texi;
  6159. $::texi_map_ref = \%cross_ref_texi_map;
  6160. my $normal_text_kept = $Texi2HTML::Config::normal_text;
  6161. $Texi2HTML::Config::normal_text = \&Texi2HTML::Config::t2h_cross_manual_normal_text;
  6162. my $style_kept = $Texi2HTML::Config::style;
  6163. $Texi2HTML::Config::style = \&Texi2HTML::Config::T2H_GPL_style;
  6164. my ($cross_ref_target, $cross_ref_file);
  6165. if (get_conf('USE_UNICODE'))
  6166. {
  6167. $cross_ref_target = Unicode::Normalize::NFC(remove_texi($text));
  6168. if ($transliterate and get_conf('USE_UNIDECODE'))
  6169. {
  6170. $cross_ref_file =
  6171. unicode_to_protected(unicode_to_transliterate($cross_ref_target));
  6172. }
  6173. $cross_ref_target = unicode_to_protected($cross_ref_target);
  6174. }
  6175. else
  6176. {
  6177. $cross_ref_target = remove_texi($text);
  6178. }
  6179. if ($transliterate and
  6180. (!get_conf('USE_UNICODE') or !get_conf('USE_UNIDECODE')))
  6181. {
  6182. $::style_map_texi_ref = \%cross_transliterate_style_map_texi;
  6183. $::texi_map_ref = \%cross_transliterate_texi_map;
  6184. $Texi2HTML::Config::normal_text = \&Texi2HTML::Config::t2h_cross_manual_normal_text_transliterate if (!get_conf('USE_UNICODE'));
  6185. $cross_ref_file = remove_texi($text);
  6186. $cross_ref_file = unicode_to_protected(unicode_to_transliterate($cross_ref_file))
  6187. if (get_conf('USE_UNICODE'));
  6188. }
  6189. $Texi2HTML::Config::normal_text = $normal_text_kept;
  6190. $Texi2HTML::Config::style = $style_kept;
  6191. $::simple_map_texi_ref = \%Texi2HTML::Config::simple_map_texi;
  6192. $::style_map_texi_ref = \%Texi2HTML::Config::style_map_texi;
  6193. $::texi_map_ref = \%Texi2HTML::Config::texi_map;
  6194. #print STDERR "\n\ncross_ref $cross_ref\n";
  6195. unless ($transliterate)
  6196. {
  6197. return $cross_ref_target;
  6198. }
  6199. # print STDERR "$text|$cross_ref_target|$cross_ref_file\n";
  6200. return ($cross_ref_target, $cross_ref_file);
  6201. }
  6202. sub equivalent_nodes($)
  6203. {
  6204. my $name = shift;
  6205. #print STDERR "equivalent_nodes $name\n";
  6206. my $node = normalise_node($name);
  6207. $name = cross_manual_line($node);
  6208. #print STDERR "equivalent_nodes `$node' `$name'\n";
  6209. my @equivalent_nodes = ();
  6210. if (exists($cross_reference_nodes{$name}))
  6211. {
  6212. @equivalent_nodes = grep {$_ ne $node} @{$cross_reference_nodes{$name}};
  6213. }
  6214. return @equivalent_nodes;
  6215. }
  6216. sub find_equivalent_node($)
  6217. {
  6218. my $name = shift;
  6219. my @equivalent_nodes = equivalent_nodes($name);
  6220. my $node_seen;
  6221. foreach my $equivalent_node (@equivalent_nodes)
  6222. {
  6223. if ($nodes{$equivalent_node}->{'seen'})
  6224. {
  6225. $node_seen = $equivalent_node;
  6226. last;
  6227. }
  6228. }
  6229. return $node_seen;
  6230. }
  6231. sub do_place_target_file($$$)
  6232. {
  6233. my $place = shift;
  6234. my $element = shift;
  6235. my $context = shift;
  6236. $place->{'file'} = $element->{'file'} unless defined($place->{'file'});
  6237. $place->{'target'} = $element->{'target'} unless defined($place->{'target'});
  6238. if (defined($Texi2HTML::Config::placed_target_file_name))
  6239. {
  6240. my ($target, $id, $file) = &$Texi2HTML::Config::placed_target_file_name($place, $element, $place->{'target'}, $place->{'id'}, $place->{'file'}, $context);
  6241. $place->{'target'} = $target if (defined($target));
  6242. $place->{'file'} = $file if (defined($file));
  6243. $place->{'id'} = $id if (defined($id));
  6244. }
  6245. }
  6246. sub do_node_target_file($$)
  6247. {
  6248. my $node = shift;
  6249. my $type_of_node = shift;
  6250. my $node_file = &$Texi2HTML::Config::node_file_name($node,$type_of_node);
  6251. $node->{'node_file'} = $node_file if (defined($node_file));
  6252. if (defined($Texi2HTML::Config::node_target_name))
  6253. {
  6254. my ($target,$id) = &$Texi2HTML::Config::node_target_name($node, $node->{'target'}, $node->{'id'}, $type_of_node);
  6255. $node->{'target'} = $target if (defined($target));
  6256. $node->{'id'} = $id if (defined($id));
  6257. }
  6258. }
  6259. sub do_element_targets($;$)
  6260. {
  6261. my $element = shift;
  6262. my $use_node_file = shift;
  6263. my $is_top = '';
  6264. $is_top = 'top' if (defined($element_top) and ($element eq $element_top or (defined($element->{'with_node'}) and $element->{'with_node'} eq $element_top)));
  6265. if (get_conf('SPLIT_INDEX') and get_conf('SPLIT'))
  6266. {
  6267. Texi2HTML::Config::t2h_default_associate_index_element($element, $is_top, $docu_name, $use_node_file);
  6268. }
  6269. if (defined($Texi2HTML::Config::element_file_name))
  6270. {
  6271. my $previous_file_name = $element->{'file'};
  6272. my $filename =
  6273. &$Texi2HTML::Config::element_file_name ($element, $is_top, $docu_name);
  6274. if (defined($filename))
  6275. {
  6276. foreach my $place (@{$element->{'place'}})
  6277. {
  6278. $place->{'file'} = $filename if (defined($place->{'file'}) and ($place->{'file'} eq $previous_file_name));
  6279. }
  6280. $element->{'file'} = $filename;
  6281. if ($is_top)
  6282. { # reset these variables, although they aren't used much, they may be
  6283. # used in file name comparisons
  6284. $docu_top = $filename;
  6285. $docu_top_file = "$docu_rdir$docu_top";
  6286. }
  6287. }
  6288. }
  6289. print STDERR "file !defined for element $element->{'texi'}\n" if (!defined($element->{'file'}));
  6290. if (defined($Texi2HTML::Config::element_target_name))
  6291. {
  6292. my ($target,$id) = &$Texi2HTML::Config::element_target_name($element, $element->{'target'}, $element->{'id'});
  6293. $element->{'target'} = $target if (defined($target));
  6294. $element->{'id'} = $id if (defined($id));
  6295. }
  6296. foreach my $place(@{$element->{'place'}})
  6297. {
  6298. do_place_target_file($place, $element, '');
  6299. }
  6300. }
  6301. sub add_t2h_element($$$)
  6302. {
  6303. my $element = shift;
  6304. my $elements_list = shift;
  6305. my $prev_element = shift;
  6306. push @$elements_list, $element;
  6307. $element->{'element_ref'} = $element;
  6308. $element->{'this'} = $element;
  6309. if (defined($prev_element))
  6310. {
  6311. $element->{'back'} = $prev_element;
  6312. $prev_element->{'forward'} = $element;
  6313. }
  6314. push @{$element->{'place'}}, $element;
  6315. push @{$element->{'place'}}, @{$element->{'current_place'}};
  6316. return $element;
  6317. }
  6318. sub add_t2h_dependent_element ($$)
  6319. {
  6320. my $element = shift;
  6321. my $element_ref = shift;
  6322. $element->{'element_ref'} = $element_ref;
  6323. $element_index = $element_ref if ($element_index and ($element_index eq $element));
  6324. push @{$element_ref->{'place'}}, $element;
  6325. push @{$element_ref->{'place'}}, @{$element->{'current_place'}};
  6326. }
  6327. my %files = (); # keys are files. This is used to avoid reusing an already
  6328. # used file name
  6329. my @opened_files = (); # all the files opened by the program to remove
  6330. # them if FORCE is not set and an error occured
  6331. my %printed_indices = (); # value is true for an index name not empty and
  6332. # printed
  6333. # This is a virtual element used to have the right hrefs for index entries
  6334. # and anchors in footnotes.
  6335. my $footnote_element;
  6336. # find next, prev, up, back, forward, fastback, fastforward
  6337. # find element id and file
  6338. # split index pages
  6339. # associate placed items (items which have links to them) with the right
  6340. # file and id
  6341. # associate nodes with sections
  6342. sub rearrange_elements()
  6343. {
  6344. print STDERR "# find sections levels and toplevel\n"
  6345. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  6346. my $toplevel = 4;
  6347. # correct level if raisesections or lowersections overflowed
  6348. # and find toplevel level
  6349. # use %sections and %headings to modify also the headings
  6350. foreach my $section (values(%sections), values(%headings))
  6351. {
  6352. my $level = $section->{'level'};
  6353. if ($level > $MAX_LEVEL)
  6354. {
  6355. $section->{'level'} = $MAX_LEVEL;
  6356. }
  6357. # second condition is for @top and @part
  6358. elsif ($level < $MIN_LEVEL and ($reference_sec2level{$section->{'tag'}} >= $MIN_LEVEL))
  6359. {
  6360. $section->{'level'} = $MIN_LEVEL;
  6361. }
  6362. else
  6363. {
  6364. $section->{'level'} = $level;
  6365. }
  6366. $section->{'toc_level'} = $section->{'level'};
  6367. # This is for top
  6368. $section->{'toc_level'} = $MIN_LEVEL if ($section->{'level'} < $MIN_LEVEL);
  6369. # find the new tag corresponding with the level of the section
  6370. if ($section->{'tag'} !~ /heading/ and ($level ne $reference_sec2level{$section->{'tag'}}))
  6371. {
  6372. $section->{'tag_level'} = $level2sec{$section->{'tag'}}->[$section->{'level'}];
  6373. }
  6374. else
  6375. {
  6376. $section->{'tag_level'} = $section->{'tag'};
  6377. }
  6378. $toplevel = $section->{'level'} if (($section->{'level'} < $toplevel) and ($section->{'level'} > 0 and ($section->{'tag'} !~ /heading/)));
  6379. print STDERR "# section level $level: $section->{'texi'}\n" if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  6380. }
  6381. print STDERR "# find sections structure, construct section numbers (toplevel=$toplevel)\n"
  6382. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  6383. my $in_appendix = 0;
  6384. # these arrays have an element per sectioning level.
  6385. my @previous_numbers = (); # holds the number of the previous sections
  6386. # at the same and upper levels
  6387. my @previous_sections = (); # holds the ref of the previous sections
  6388. my $previous_toplevel;
  6389. my @pending_parts; # parts yet to be associated with the
  6390. # following element
  6391. foreach my $section (@sections_list)
  6392. {
  6393. ########################### debug
  6394. print STDERR "BUG: node or section_ref defined for section $section->{'texi'}\n"
  6395. if (exists($section->{'node'}) or exists($section->{'section_ref'}));
  6396. print STDERR "Bug level undef for ($section) $section->{'texi'}\n" if (!defined($section->{'level'}));
  6397. ########################### end debug
  6398. # associate with first node if it is a section appearing before
  6399. # the first node
  6400. $section->{'node_ref'} = $nodes_list[0] if ($nodes_list[0] and !$section->{'node_ref'});
  6401. # a part doesn't really make up an element, it is associated with the
  6402. # next sectioning element instead.
  6403. if ($section->{'tag'} eq 'part')
  6404. {
  6405. push @pending_parts, $section;
  6406. }
  6407. elsif (@pending_parts)
  6408. {
  6409. if ($section->{'tag'} ne 'top')
  6410. {
  6411. foreach my $part (@pending_parts)
  6412. {
  6413. $part->{'part_section_ref'} = $section;
  6414. if (!$section->{'with_part'})
  6415. {
  6416. $section->{'with_part'} = $part;
  6417. $part->{'part_with_section'} = $section;
  6418. }
  6419. # if a node is associated with the part, reassociate it with
  6420. # the chapter
  6421. if ($part->{'with_node'} and !$section->{'with_node'})
  6422. {
  6423. $section->{'with_node'} = $part->{'with_node'};
  6424. delete $part->{'with_node'};
  6425. $section->{'with_node'}->{'with_section'} = $section;
  6426. }
  6427. }
  6428. }
  6429. @pending_parts = ();
  6430. }
  6431. # we track the toplevel next and previous because there is no
  6432. # strict child parent relationship between chapters and top. Indeed
  6433. # a chapter may appear before @top, it may be better to consider them
  6434. # on the same toplevel.
  6435. if ($section->{'level'} <= $toplevel)
  6436. {
  6437. $section->{'toplevel'} = 1;
  6438. if (defined($previous_toplevel))
  6439. {
  6440. $previous_toplevel->{'toplevelnext'} = $section;
  6441. $section->{'toplevelprev'} = $previous_toplevel;
  6442. }
  6443. # part is not used as previous_toplevel since toplevel directions
  6444. # are used to move between chapters (and top)
  6445. $previous_toplevel = $section if ($section->{'tag'} ne 'part');
  6446. # In fact this is only useful for toplevel elements appearing
  6447. # before @top, the other have their sectionup reset up below
  6448. # based on the sectioning commands hierarchy.
  6449. if (defined($section_top) and $section ne $section_top)
  6450. {
  6451. $section->{'sectionup'} = $section_top;
  6452. }
  6453. }
  6454. # undef things under that section level
  6455. my $section_level = $section->{'level'};
  6456. for (my $level = $section_level + 1; $level < $MAX_LEVEL + 1 ; $level++)
  6457. {
  6458. $previous_numbers[$level] = undef unless ($section->{'tag'} =~ /unnumbered/ or $section->{'tag'} eq 'centerchap');
  6459. $previous_sections[$level] = undef;
  6460. }
  6461. my $number_set;
  6462. # find number at the current level
  6463. if ($section->{'tag'} =~ /appendix/ and !$in_appendix)
  6464. {
  6465. $previous_numbers[$toplevel] = 'A';
  6466. $in_appendix = 1;
  6467. $number_set = 1 if ($section->{'level'} <= $toplevel);
  6468. $section->{'appendix_beginning'} = 1;
  6469. }
  6470. if (!defined($previous_numbers[$section->{'level'}]) and !$number_set)
  6471. {
  6472. if ($section->{'tag'} =~ /unnumbered/ or $section->{'tag'} eq 'centerchap')
  6473. {
  6474. $previous_numbers[$section->{'level'}] = undef;
  6475. }
  6476. else
  6477. {
  6478. $previous_numbers[$section->{'level'}] = 1;
  6479. }
  6480. }
  6481. elsif ($section->{'tag'} !~ /unnumbered/ and $section->{'tag'} ne 'centerchap' and !$number_set)
  6482. {
  6483. $previous_numbers[$section->{'level'}]++;
  6484. }
  6485. # construct the section number
  6486. $section->{'number'} = '';
  6487. unless ($section->{'tag'} =~ /unnumbered/ or $section->{'tag'} eq 'centerchap' or $section->{'tag'} eq 'top' or $section->{'tag'} eq 'part')
  6488. {
  6489. my $level = $section->{'level'};
  6490. while ($level > $toplevel)
  6491. {
  6492. my $number = $previous_numbers[$level];
  6493. $number = 0 if (!defined($number));
  6494. if ($section->{'number'})
  6495. {
  6496. $section->{'number'} = "$number.$section->{'number'}";
  6497. }
  6498. else
  6499. {
  6500. $section->{'number'} = $number;
  6501. }
  6502. $level--;
  6503. }
  6504. my $toplevel_number = $previous_numbers[$toplevel];
  6505. $toplevel_number = 0 if (!defined($toplevel_number));
  6506. if ($section->{'number'})
  6507. { # not toplevel
  6508. $section->{'number'} = "$toplevel_number.$section->{'number'}";
  6509. }
  6510. else
  6511. { # toplevel
  6512. $section->{'number'} = $toplevel_number;
  6513. if ($section->{'tag'} =~ /appendix/)
  6514. {# i18n
  6515. $section->{'plain_number'} = $section->{'number'};
  6516. $section->{'number'} = "Appendix $section->{'number'}";
  6517. }
  6518. }
  6519. }
  6520. $section->{'plain_number'} = $section->{'number'} if (!defined($section->{'plain_number'}));
  6521. # find the previous section
  6522. if (defined($previous_sections[$section->{'level'}]))
  6523. {
  6524. my $prev_section = $previous_sections[$section->{'level'}];
  6525. $section->{'sectionprev'} = $prev_section;
  6526. $prev_section->{'sectionnext'} = $section;
  6527. }
  6528. # find the up section
  6529. my $level = $section->{'level'} - 1;
  6530. while (!defined($previous_sections[$level]) and ($level >= 0))
  6531. {
  6532. $level--;
  6533. }
  6534. # The second conditions ensures that a @part is stopped by
  6535. # the first @appendix command.
  6536. if (defined($previous_sections[$level])
  6537. and !($section->{'appendix_beginning'} and $previous_sections[$level]->{'tag'} eq 'part' and $previous_sections[$level]->{'part_section_ref'} ne $section))
  6538. {
  6539. # toplevel elements have already their up set to the top element,
  6540. # it is overwriten here for most cases -- this leads to a different
  6541. # sectionup if there are parts, for instance.
  6542. # as a side note, it is not touched upon if the element appears
  6543. # before @top.
  6544. $section->{'sectionup'} = $previous_sections[$level];
  6545. # 'child' is the first child.
  6546. if (!$section->{'sectionup'}->{'child'})
  6547. {
  6548. $section->{'sectionup'}->{'child'} = $section;
  6549. }
  6550. else
  6551. {
  6552. # 'childnext' is the next child of a an element. it may
  6553. # be different from 'sectionnext' when the elemnt are not
  6554. # at the same level, for example
  6555. # @chapter chapter
  6556. # @subsection subsection (certainly wrong)
  6557. # @section section (not next of subsection, but childnext)
  6558. $section->{'sectionup'}->{'section_childs'}->[-1]->{'childnext'} = $section if (defined($section->{'sectionup'}->{'section_childs'}));
  6559. }
  6560. push @{$section->{'sectionup'}->{'section_childs'}}, $section;
  6561. }
  6562. $previous_sections[$section->{'level'}] = $section;
  6563. # This is what is used in the init file.
  6564. $section->{'up'} = $section->{'sectionup'};
  6565. # Not used but documented.
  6566. $section->{'next'} = $section->{'sectionnext'};
  6567. $section->{'prev'} = $section->{'sectionprev'};
  6568. ############################# debug
  6569. my $up = "NO_UP";
  6570. $up = $section->{'sectionup'} if (defined($section->{'sectionup'}));
  6571. print STDERR "# numbering section ($section->{'level'}): $section->{'number'}: (up: $up) $section->{'texi'}\n"
  6572. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  6573. ############################# end debug
  6574. }
  6575. # at that point there are still some node structures that are not
  6576. # in %nodes, (the external nodes, and unknown nodes in case
  6577. # novalidate is true) so we cannot find the id. The consequence is that
  6578. # some node equivalent with another node may not be catched during
  6579. # that pass. We mark the nodes that have directions for unreferenced
  6580. # nodes and make a second pass for these nodes afterwards.
  6581. my @nodes_with_unknown_directions = ();
  6582. my %node_directions = (
  6583. 'node_prev' => 'nodeprev',
  6584. 'node_next' => 'nodenext',
  6585. 'node_up' => 'nodeup');
  6586. # handle nodes
  6587. # the node_prev... are texinfo strings, find the associated node references
  6588. print STDERR "# Resolve nodes directions\n" if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  6589. foreach my $node (@nodes_list)
  6590. {
  6591. foreach my $direction (sort(keys(%node_directions)))
  6592. {
  6593. if (defined($node->{$direction}))
  6594. {
  6595. if ($nodes{$node->{$direction}} and $nodes{$node->{$direction}}->{'seen'})
  6596. {
  6597. $node->{$node_directions{$direction}} = $nodes{$node->{$direction}};
  6598. }
  6599. elsif (($node->{$direction} =~ /^\(.*\)/) or Texi2HTML::Config::get_conf('novalidate'))
  6600. { # ref to an external node
  6601. if (exists($nodes{$node->{$direction}}))
  6602. {
  6603. $node->{$node_directions{$direction}} = $nodes{$node->{$direction}};
  6604. }
  6605. else
  6606. {
  6607. my $node_ref = { 'texi' => $node->{$direction} };
  6608. $node_ref->{'external_node'} = 1 if ($node->{$direction} =~ /^\(.*\)/);
  6609. $nodes{$node->{$direction}} = $node_ref;
  6610. $node->{$node_directions{$direction}} = $node_ref;
  6611. }
  6612. }
  6613. else
  6614. {
  6615. push @nodes_with_unknown_directions, $node;
  6616. }
  6617. }
  6618. }
  6619. }
  6620. # Find cross manual links as explained on the texinfo mailing list
  6621. # The specification is such that cross manual links formatting should
  6622. # be insensitive to the manual split
  6623. cross_manual_links();
  6624. my %direction_texts = (
  6625. 'node_prev' => 'Prev',,
  6626. 'node_next' => 'Next',
  6627. 'node_up' => 'Up'
  6628. );
  6629. # Now it is possible to find the unknown directions that are equivalent
  6630. # (have same node id) than an existing node
  6631. foreach my $node (@nodes_with_unknown_directions)
  6632. {
  6633. foreach my $direction (sort(keys(%node_directions)))
  6634. {
  6635. if (defined($node->{$direction}) and !$node->{$node_directions{$direction}})
  6636. {
  6637. line_error (sprintf(__("%s reference to nonexistent `%s'"),$direction_texts{$direction}, $node->{$direction}), $node->{'line_nr'}); # for `$node->{'texi'}'"
  6638. my $node_seen = find_equivalent_node($node->{$direction});
  6639. if (defined($node_seen))
  6640. {
  6641. document_warn ("---> but equivalent node `$node_seen' found");
  6642. $node->{$node_directions{$direction}} = $nodes{$node_seen};
  6643. }
  6644. }
  6645. }
  6646. }
  6647. # nodes are attached to the section preceding them if not already
  6648. # associated with a section.
  6649. # a @part should never have nodes associated, if it is associated
  6650. # with a chapter, instead the chapter pointed on by part_section_ref is
  6651. # used.
  6652. my $current_section = $sections_list[0];
  6653. $current_section = $current_section->{'part_section_ref'} if ($current_section and $current_section->{'part_section_ref'});
  6654. foreach my $element (@all_elements)
  6655. {
  6656. if ($element->{'node'})
  6657. {
  6658. if ($element->{'with_section'})
  6659. { # the node is associated with a section
  6660. $element->{'section_ref'} = $element->{'with_section'};
  6661. }
  6662. elsif (defined($current_section))
  6663. {# node appearing after a section, but not before another section,
  6664. # or appearing before any section
  6665. $element->{'section_ref'} = $current_section;
  6666. push @{$current_section->{'node_childs'}}, $element;
  6667. }
  6668. }
  6669. else
  6670. {
  6671. $current_section = $element;
  6672. $current_section = $element->{'part_section_ref'} if ($element->{'part_section_ref'});
  6673. }
  6674. }
  6675. print STDERR "# Complete nodes next prev and up based on menus and sections\n"
  6676. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  6677. # set the default id based on the node number
  6678. my $node_nr = 1;
  6679. # find the node* directions
  6680. # find the directions corresponding with sections
  6681. # and set 'up' for the node
  6682. foreach my $node (@nodes_list)
  6683. {
  6684. # first a warning if the node and the equivalent nodes don't
  6685. # appear in menus.
  6686. # Don't warn for the top node, and the first node if there is no
  6687. # top node.
  6688. if ((($node_top and $node ne $node_top) or (!$node_top and $node ne $node_first)) and !$node->{'menu_up'} and get_conf('SHOW_MENU'))
  6689. {
  6690. my @equivalent_nodes = equivalent_nodes($node->{'texi'});
  6691. my $found = 0;
  6692. foreach my $equivalent_node (@equivalent_nodes)
  6693. {
  6694. if (($nodes{$equivalent_node} eq $node_first) or $nodes{$equivalent_node}->{'menu_up'})
  6695. {
  6696. $found = 1;
  6697. last;
  6698. }
  6699. }
  6700. unless ($found)
  6701. { # makeinfo has also
  6702. # "`%s' has no Up field (perhaps incorrect sectioning?)"
  6703. # but it is not useful since the up will always be set if
  6704. # the node appears in a menu so the following error message
  6705. # is enough
  6706. line_warn (sprintf(__("unreferenced node `%s'"), $node->{'texi'}), $node->{'line_nr'});
  6707. }
  6708. }
  6709. # use values deduced from menus to complete missing up, next, prev
  6710. # or from sectioning commands if automatic sectioning
  6711. if (!$node->{'nodeup'})
  6712. {
  6713. if (defined($node_top) and ($node eq $node_top) and $node->{'automatic_directions'})
  6714. { # Top node has a special up, which is (dir) by default
  6715. my $top_nodeup = get_conf('TOP_NODE_UP');
  6716. if (exists($nodes{$top_nodeup}))
  6717. {
  6718. $node->{'nodeup'} = $nodes{$top_nodeup};
  6719. }
  6720. else
  6721. {
  6722. my $node_ref = { 'texi' => $top_nodeup };
  6723. $node_ref->{'external_node'} = 1;
  6724. $nodes{$top_nodeup} = $node_ref;
  6725. $node->{'nodeup'} = $node_ref;
  6726. }
  6727. }
  6728. elsif ($node->{'automatic_directions'})
  6729. {
  6730. if ($node->{'with_section'})
  6731. {
  6732. # ignore the up if it is a @part. If the sectioning is
  6733. # correct, the element is toplevel and will be handled
  6734. # by the next condition.
  6735. if ($node->{'with_section'}->{'sectionup'} and !$node->{'with_section'}->{'sectionup'}->{'part_section_ref'})
  6736. {
  6737. $node->{'nodeup'} = get_node($node->{'with_section'}->{'sectionup'});
  6738. }
  6739. elsif ($node->{'with_section'}->{'toplevel'} and defined($section_top) and ($node->{'with_section'} ne $section_top))
  6740. {
  6741. $node->{'nodeup'} = get_node($section_top);
  6742. }
  6743. print STDERR "# Deducing from section node_up $node->{'nodeup'}->{'texi'} for $node->{'texi'}\n" if ($T2H_DEBUG & $DEBUG_ELEMENTS and defined($node->{'nodeup'}));
  6744. }
  6745. elsif ($node->{'menu_up'})
  6746. {
  6747. $node->{'nodeup'} = $node->{'menu_up'};
  6748. print STDERR "# Deducing from menu node_up $node->{'menu_up'}->{'texi'} for $node->{'texi'}\n" if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  6749. }
  6750. }
  6751. }
  6752. if ($node->{'nodeup'} and !$node->{'nodeup'}->{'external_node'})
  6753. {
  6754. # We detect when the up node has no menu entry for that node, as
  6755. # there may be infinite loops when finding following node (see below)
  6756. unless (defined($node->{'menu_up_hash'}) and ($node->{'menu_up_hash'}->{$node->{'nodeup'}->{'texi'}}))
  6757. {
  6758. line_error(sprintf(__("Node `%s' lacks menu item for `%s' despite being its Up target"), $node->{'nodeup'}->{'texi'}, $node->{'texi'}), $node->{'nodeup'}->{'line_nr'}) if (get_conf('SHOW_MENU'));
  6759. }
  6760. }
  6761. # check that the up is in one of the menus
  6762. if (get_conf('SHOW_MENU') and $node->{'nodeup'} and $node->{'menu_up'})
  6763. {
  6764. my @equivalent_nodes = equivalent_nodes($node->{'nodeup'}->{'texi'});
  6765. my $found = 0;
  6766. foreach my $equivalent_node ($node->{'nodeup'}->{'texi'}, @equivalent_nodes)
  6767. {
  6768. if ($node->{'menu_up_hash'}->{$equivalent_node})
  6769. {
  6770. $found = 1;
  6771. last;
  6772. }
  6773. }
  6774. unless ($found)
  6775. {
  6776. line_warn (sprintf(__("For `%s', up in menu `%s' and up `%s' don't match"), $node->{'texi'}, $node->{'menu_up'}->{'texi'}, $node->{'nodeup'}->{'texi'}), $node->{'line_nr'});
  6777. }
  6778. }
  6779. # Find next node if not already found
  6780. if ($node->{'nodenext'})
  6781. {
  6782. # doing the following would be wrong:
  6783. #$node->{'nodenext'}->{'nodeprev'} = $node if (!defined($node->{'nodenext'}->{'nodeprev'}));
  6784. }
  6785. elsif ($node->{'texi'} eq 'Top' and $node->{'automatic_directions'})
  6786. { # special case as said in the texinfo manual
  6787. if ($node->{'menu_child'})
  6788. {
  6789. $node->{'nodenext'} = $node->{'menu_child'};
  6790. $node->{'menu_child'}->{'nodeprev'} = $node;
  6791. }
  6792. }
  6793. elsif ($node->{'automatic_directions'})
  6794. {
  6795. if (defined($node->{'with_section'}))
  6796. {
  6797. my $next;
  6798. my $warn_for_next_not_in_menu = 1;
  6799. my $section = $node->{'with_section'};
  6800. if ($section->{'sectionnext'})
  6801. {
  6802. $next = get_node($section->{'sectionnext'});
  6803. }
  6804. # we use toplevelnext, mostly for chapters associated with
  6805. # @part. But we don't want to have the @top as prev for
  6806. # a @chapter or the like
  6807. elsif ($section->{'toplevelnext'} and $section->{'toplevelnext'} ne $section_top)
  6808. {
  6809. $next = get_node($section->{'toplevelnext'});
  6810. }
  6811. elsif (get_conf('USE_UP_FOR_ADJACENT_NODES'))
  6812. { # makeinfo don't do that. So this is conditionnal.
  6813. # Also no warning, because it is expected that the
  6814. # next found out with the up is not the next in menu.
  6815. $warn_for_next_not_in_menu = 0;
  6816. while (defined($section->{'sectionup'}) and !defined($section->{'sectionnext'}))
  6817. {
  6818. $section = $section->{'sectionup'};
  6819. }
  6820. if (defined($section->{'sectionnext'}))
  6821. {
  6822. $next = get_node($section->{'sectionnext'});
  6823. }
  6824. }
  6825. if (defined($next) and get_conf('SHOW_MENU') and $warn_for_next_not_in_menu)
  6826. {
  6827. line_warn (sprintf(__("No node following `%s' in menu, but `%s' follows in sectioning"), $node->{'texi'}, $next->{'texi'}), $node->{'line_nr'}) if (!defined($node->{'menu_next'}));
  6828. line_warn (sprintf(__("Node following `%s' in menu `%s' and in sectioning `%s' differ"), $node->{'texi'}, $node->{'menu_next'}->{'texi'}, $next->{'texi'}), $node->{'line_nr'})
  6829. if (defined($node->{'menu_next'}) and $next ne $node->{'menu_next'});
  6830. }
  6831. $node->{'nodenext'} = $next;
  6832. }
  6833. elsif ($node->{'menu_next'})
  6834. {
  6835. $node->{'nodenext'} = $node->{'menu_next'};
  6836. }
  6837. }
  6838. # Find prev node
  6839. if ($node->{'nodeprev'})
  6840. {
  6841. # doing the following would be wrong:
  6842. #$node->{'nodeprev'}->{'nodenext'} = $node if (!defined($node->{'nodeprev'}->{'nodenext'}));
  6843. }
  6844. elsif ($node->{'automatic_directions'})
  6845. {
  6846. if (defined($node->{'with_section'}))
  6847. {
  6848. my $section = $node->{'with_section'};
  6849. if ($section->{'sectionprev'})
  6850. {
  6851. $node->{'nodeprev'} = get_node($section->{'sectionprev'});
  6852. }
  6853. # we use toplevelprev, mostly for chapters associated with
  6854. # @part. But we don't want to have the @top as prev for
  6855. # a @chapter or the like
  6856. elsif ($section->{'toplevelprev'} and $section->{'toplevelprev'} ne $section_top)
  6857. {
  6858. $node->{'nodeprev'} = get_node($section->{'toplevelprev'});
  6859. }
  6860. elsif (get_conf('USE_UP_FOR_ADJACENT_NODES') and defined($section->{'sectionup'}))
  6861. { # makeinfo don't do that
  6862. $node->{'nodeprev'} = get_node($section->{'sectionup'});
  6863. }
  6864. }
  6865. elsif ($node->{'menu_prev'})
  6866. {
  6867. $node->{'nodeprev'} = $node->{'menu_prev'};
  6868. }
  6869. # the prev node is the parent node
  6870. elsif ($node->{'menu_up'} and ($node->{'menu_up'}->{'menu_child'} eq $node) and get_conf('USE_UP_FOR_ADJACENT_NODES'))
  6871. {
  6872. $node->{'nodeprev'} = $node->{'menu_up'};
  6873. }
  6874. }
  6875. # the nodeforward node is the node following in node reading order
  6876. # it is thus first the child, else the next, else the next following
  6877. # the up
  6878. if ($node->{'menu_child'})
  6879. {
  6880. $node->{'nodeforward'} = $node->{'menu_child'};
  6881. }
  6882. elsif ($node->{'automatic_directions'} and defined($node->{'with_section'}) and defined($node->{'with_section'}->{'child'}))
  6883. {
  6884. $node->{'nodeforward'} = get_node($node->{'with_section'}->{'child'});
  6885. }
  6886. elsif (defined($node->{'nodenext'}))
  6887. {
  6888. $node->{'nodeforward'} = $node->{'nodenext'};
  6889. }
  6890. else
  6891. {
  6892. my $up = $node->{'nodeup'};
  6893. my @up_list = ($node);
  6894. # the condition with the up_list avoids infinite loops
  6895. # the last condition stops when the Top node is reached.
  6896. while (defined($up) and not (grep {$up eq $_} @up_list or (($node_top) and ($up eq $node_top))))
  6897. {
  6898. if (defined($up->{'nodenext'}))
  6899. {
  6900. $node->{'nodeforward'} = $up->{'nodenext'};
  6901. last;
  6902. }
  6903. push @up_list, $up;
  6904. $up = $up->{'nodeup'};
  6905. }
  6906. }
  6907. $node->{'nodeforward'}->{'nodeback'} = $node
  6908. if ($node->{'nodeforward'} and not $node->{'nodeforward'}->{'nodeback'});
  6909. # copy the direction of the associated section.
  6910. if (defined($node->{'with_section'}))
  6911. {
  6912. my $section = $node->{'with_section'};
  6913. foreach my $direction ('sectionnext', 'sectionprev', 'sectionup')
  6914. {
  6915. $node->{$direction} = $section->{$direction}
  6916. if (defined($section->{$direction}));
  6917. }
  6918. }
  6919. # 'up' is used in init files. It is almost sectionup, but not
  6920. # exactly, it allows to have something relevant whether elements
  6921. # are nodes or sections -- just like Back and Forward. So it
  6922. # should certainly be kept.
  6923. if (defined($node->{'sectionup'}))
  6924. {
  6925. $node->{'up'} = $node->{'sectionup'};
  6926. }
  6927. elsif (defined($node->{'nodeup'}) and
  6928. (!$node_top or ($node ne $node_top)))
  6929. {
  6930. $node->{'up'} = $node->{'nodeup'};
  6931. }
  6932. # 'next' not used but documented.
  6933. if (defined($node->{'sectionnext'}))
  6934. {
  6935. $node->{'next'} = $node->{'sectionnext'};
  6936. }
  6937. if (defined($node->{'sectionprev'}))
  6938. {
  6939. $node->{'prev'} = $node->{'sectionprev'};
  6940. }
  6941. # default id for nodes. Should be overriden later.
  6942. $node->{'id'} = 'NOD' . $node_nr;
  6943. $node_nr++;
  6944. }
  6945. # do node directions for sections.
  6946. foreach my $section (@sections_list)
  6947. {
  6948. # If the element is not a node, then all the node directions are copied
  6949. # if there is an associated node
  6950. if (defined($section->{'with_node'}))
  6951. {
  6952. $section->{'nodenext'} = $section->{'with_node'}->{'nodenext'};
  6953. $section->{'nodeprev'} = $section->{'with_node'}->{'nodeprev'};
  6954. $section->{'menu_next'} = $section->{'with_node'}->{'menu_next'};
  6955. $section->{'menu_prev'} = $section->{'with_node'}->{'menu_prev'};
  6956. $section->{'menu_child'} = $section->{'with_node'}->{'menu_child'};
  6957. $section->{'menu_up'} = $section->{'with_node'}->{'menu_up'};
  6958. $section->{'nodeup'} = $section->{'with_node'}->{'nodeup'};
  6959. $section->{'nodeforward'} = $section->{'with_node'}->{'nodeforward'};
  6960. $section->{'nodeback'} = $section->{'with_node'}->{'nodeback'};
  6961. }
  6962. }
  6963. my $only_nodes = 0;
  6964. my $only_sections = 0;
  6965. # for legibility
  6966. my $use_nodes = get_conf('USE_NODES');
  6967. my $use_sections = get_conf('USE_SECTIONS');
  6968. $only_nodes = 1 if (
  6969. (!scalar(@sections_list) and
  6970. ($use_nodes or (!$use_sections and !defined($use_nodes))))
  6971. or ($use_nodes and !$use_sections)
  6972. );
  6973. $only_sections = 1 if (!$only_nodes and !$use_nodes and ($use_sections or !defined($use_sections)));
  6974. #print STDERR "USE_NODES $use_nodes, USE_SECTIONS $use_sections. only_nodes: $only_nodes, only_sections $only_sections\n";
  6975. my $prev_element;
  6976. print STDERR "# Build the elements list only_nodes: $only_nodes, only_sections $only_sections\n" if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  6977. foreach my $element (@all_elements)
  6978. {
  6979. if ($element->{'node'})
  6980. {
  6981. if ($element->{'section_ref'} and ($only_sections or (!$only_nodes and $element->{'with_section'})))
  6982. {
  6983. add_t2h_dependent_element ($element, $element->{'section_ref'});
  6984. }
  6985. elsif (!$only_sections)
  6986. {
  6987. $prev_element = add_t2h_element($element, \@elements_list, $prev_element);
  6988. }
  6989. else # $only_section and !$section_ref. This should only
  6990. # happen when there are no sections
  6991. {
  6992. #print STDERR "node $element->{'texi'} not associated with an element\n";
  6993. }
  6994. }
  6995. else
  6996. {
  6997. my $part_element = $element->{'part_section_ref'};
  6998. if (($element->{'node_ref'} or ($part_element and $part_element->{'node_ref'})) and $only_nodes)
  6999. {
  7000. my $element_with_node = $element;
  7001. $element_with_node = $part_element if ($part_element);
  7002. add_t2h_dependent_element ($element, $element_with_node->{'node_ref'});
  7003. }
  7004. elsif (!$only_nodes)
  7005. {
  7006. if ($part_element)
  7007. {
  7008. add_t2h_dependent_element ($element, $part_element);
  7009. }
  7010. else
  7011. {
  7012. $prev_element = add_t2h_element($element, \@elements_list, $prev_element);
  7013. }
  7014. }
  7015. else
  7016. { # no node, and $only_nodes
  7017. #print STDERR "$element->{'tag'} $element->{'texi'} not associated with an element\n";
  7018. }
  7019. }
  7020. }
  7021. # find texi2html specific directions and elements that are not texinfo
  7022. # language features.
  7023. #
  7024. # Maybe Config hooks should be used at that point (up to index
  7025. # preparation)
  7026. #
  7027. # find first, last and top elements
  7028. if (@elements_list)
  7029. {
  7030. $element_first = $elements_list[0];
  7031. print STDERR "# element first: $element_first->{'texi'}\n" if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  7032. # It is the last element before indices split, which may add new
  7033. # elements
  7034. $element_last = $elements_list[-1];
  7035. }
  7036. else
  7037. {
  7038. print STDERR "# \@elements_list is empty\n" if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  7039. }
  7040. print STDERR "# top node: $node_top->{'texi'}\n" if (defined($node_top) and
  7041. ($T2H_DEBUG & $DEBUG_ELEMENTS));
  7042. # Remark: there are many subtle distinctions among the elements that
  7043. # have a flavor of being at top. First there are the texinfo top
  7044. # elements (if present), namely $section_top for the @top element
  7045. # and $node_top for the @node Top element (and both may be associated).
  7046. # Then there is $element_top, set up just below. In addition to
  7047. # $section_top and $node_top, the section associated with $node_top
  7048. # and the first element may be used. $element_top is used to determine
  7049. # file splitting and file names, since it is always associated with
  7050. # $docu_top file.
  7051. # The $element_top may have 'top' set, in case it is a node or @top.
  7052. # In that case, special formatting is done, like using print_Top and
  7053. # similar.
  7054. # Similarly with element_top, some other nodes than $node_top may
  7055. # get associated with the top node filename without being considered
  7056. # as top otherwise (this is done below).
  7057. if (defined($section_top) and $section_top->{'this'})
  7058. {
  7059. # element top is the element with @top.
  7060. $element_top = $section_top;
  7061. }
  7062. elsif (defined($node_top) and $node_top->{'this'})
  7063. {
  7064. # otherwise top node may be the element_top
  7065. $element_top = $node_top;
  7066. }
  7067. elsif (defined($node_top) and defined($node_top->{'with_section'}) and $node_top->{'with_section'}->{'this'})
  7068. {
  7069. # next, the element associated with the @node Top may be
  7070. # the $element_top. In that case $element_top->{'top'} won't be set
  7071. $element_top = $node_top->{'with_section'};
  7072. }
  7073. elsif (defined($element_first))
  7074. {
  7075. # If there is no @top section no top node associated with an element,
  7076. # first element is used
  7077. $element_top = $element_first;
  7078. }
  7079. # Rather arbitrarily, 'top' is set for nodes as top elements
  7080. # and @top. This triggers specific formatting, like calling
  7081. # print_Top and similar things.
  7082. if (defined($element_top))
  7083. {
  7084. $element_top->{'top'} = 1 if ($element_top->{'node'} or $element_top->{'tag'} eq 'top');
  7085. if ($T2H_DEBUG & $DEBUG_ELEMENTS)
  7086. {
  7087. my $element_top_is_node = 'not a node';
  7088. $element_top_is_node = 'node' if ($element_top->{'node'});
  7089. print STDERR "# element top($element_top_is_node): $element_top->{'texi'}\n";
  7090. }
  7091. }
  7092. print STDERR "# find fastback and fastforward\n"
  7093. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  7094. foreach my $element (@elements_list)
  7095. { # nodes are ignored here, although their associated sectioning
  7096. # command may be taken into account.
  7097. my $up = get_top($element);
  7098. next unless (defined($up));
  7099. # take the opportunity to set the first chapter with index
  7100. $element_chapter_index = $up if ($element_index and ($element_index eq $element));
  7101. # fastforward is the next element on same level than the upper parent
  7102. # element.
  7103. if (exists ($up->{'toplevelnext'}))
  7104. {
  7105. $element->{'fastforward'} = $up->{'toplevelnext'}
  7106. }
  7107. # if the element isn't at the highest level, fastback is the
  7108. # highest parent element
  7109. if ($up and ($up ne $element))
  7110. {
  7111. $element->{'fastback'} = $up;
  7112. }
  7113. elsif ($element->{'toplevel'})
  7114. {
  7115. # the element is a top level element, we adjust the next
  7116. # toplevel element fastback
  7117. $element->{'fastforward'}->{'fastback'} = $element if ($element->{'fastforward'});
  7118. }
  7119. }
  7120. # set 'reference_element' which is used each time there is a cross ref
  7121. # to that node (xref and menu entry), to do the href, and also the
  7122. # element heading text.
  7123. # It is the section associated with the node if there are only sections.
  7124. # Since in the default case the target is the node target, even for
  7125. # sections, this, in fact shouldn't lead to a different target, unless
  7126. # the node and the section don't have the same file associated, which could
  7127. # only happen with indices split. The heading text will be different, though.
  7128. # The node name should also always be passed to the formatting functions
  7129. # such that it is always possible for the formatting to chose the node
  7130. # heading over the element heading selected using 'reference_element'.
  7131. if ($only_sections)
  7132. {
  7133. foreach my $node(@nodes_list)
  7134. {
  7135. if ($node->{'with_section'})
  7136. {
  7137. $node->{'reference_element'} = $node->{'with_section'};
  7138. }
  7139. }
  7140. }
  7141. # the symmetric is not done for sections, since there is no crossref
  7142. # to sections in texinfo (only to anchors and nodes), so that when
  7143. # there is a link to an element (in Toc, for instance),
  7144. # there is no reason to want to have the node (though, once again,
  7145. # the href is almost surely the same than what would be with the node,
  7146. # the heading would be different).
  7147. # end texi2html added directions
  7148. # do human readable id
  7149. print STDERR "# find float id\n"
  7150. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  7151. foreach my $float (@floats)
  7152. {
  7153. $float->{'style_id'} = cross_manual_line($float->{'style_texi'});
  7154. my $float_style = { };
  7155. if (exists($floats{$float->{'style_id'}}))
  7156. {
  7157. $float_style = $floats{$float->{'style_id'}};
  7158. }
  7159. else
  7160. {
  7161. $floats{$float->{'style_id'}} = $float_style;
  7162. }
  7163. push @{$float_style->{'floats'}}, $float;
  7164. $float->{'absolute_nr'} = scalar(@{$float_style->{'floats'}});
  7165. my $up = get_top($float->{'element'});
  7166. if (defined($up) and (!defined($float_style->{'current_chapter'}) or ($up->{'texi'} ne $float_style->{'current_chapter'})))
  7167. {
  7168. $float_style->{'current_chapter'} = $up->{'texi'};
  7169. $float_style->{'nr_in_chapter'} = 1;
  7170. }
  7171. else
  7172. {
  7173. $float_style->{'nr_in_chapter'}++;
  7174. }
  7175. if (defined($up) and $up->{'toplevel'} and $up->{'number'} ne '')
  7176. {
  7177. $float->{'chapter_nr'} = $up->{'plain_number'};
  7178. $float->{'nr'} = $float->{'chapter_nr'} . "." . $float_style->{'nr_in_chapter'};
  7179. }
  7180. else
  7181. {
  7182. $float->{'nr'} = $float->{'absolute_nr'};
  7183. }
  7184. }
  7185. print STDERR "# do human-readable index entries id\n"
  7186. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  7187. if (get_conf('NEW_CROSSREF_STYLE'))
  7188. {
  7189. foreach my $entry_region (sort(keys(%{$Texi2HTML::THISDOC{'index_entries_region_array'}})))
  7190. {
  7191. foreach my $index_entry (@{$Texi2HTML::THISDOC{'index_entries_region_array'}->{$entry_region}})
  7192. {
  7193. my $region = '';
  7194. $region = "$index_entry->{'region'}-" if (defined($index_entry->{'region'}) and $index_entry->{'region'} ne '');
  7195. my $index_id = "index-" . $region .$index_entry->{'cross'};
  7196. my $index = 1;
  7197. # $index > 0 should prevent integer overflow, hopefully
  7198. while (exists($cross_reference_nodes{$index_id}) and $index > 0)
  7199. {
  7200. $index_id = "index-" . $region . $index_entry->{'cross'} . "-" .$index;
  7201. $index++;
  7202. }
  7203. $index_entry->{'id'} = $index_id;
  7204. $index_entry->{'target'} = $index_id;
  7205. my $texi_entry = "index-".$region.$index_entry->{'texi'};
  7206. $texi_entry .= "-".$index if ($index > 1);
  7207. push @{$cross_reference_nodes{$index_id}}, $texi_entry;
  7208. }
  7209. }
  7210. }
  7211. if (get_conf('NEW_CROSSREF_STYLE'))
  7212. {
  7213. foreach my $key (keys(%nodes))
  7214. {
  7215. my $node = $nodes{$key};
  7216. next if ($node->{'external_node'});
  7217. $node->{'id'} = node_to_id($node->{'cross_manual_target'});
  7218. # FIXME if NEW_CROSSREF_STYLE false is it done for anchors?
  7219. $node->{'target'} = $node->{'id'};
  7220. }
  7221. }
  7222. # use %sections and %headings to modify also the headings
  7223. foreach my $section (@sections_list, @headings_list)
  7224. {
  7225. if (get_conf('NEW_CROSSREF_STYLE') and ($section->{'cross'} =~ /\S/))
  7226. {
  7227. my $section_cross = $section->{'cross'};
  7228. if (defined($section->{'region'}))
  7229. { # for headings appearing in special regions like @copying...
  7230. $section_cross = "${target_prefix}-$section->{'region'}_$section_cross";
  7231. }
  7232. $section->{'cross_manual_target'} = $section_cross;
  7233. my $index = 1;
  7234. # $index > 0 should prevent integer overflow, hopefully
  7235. while (exists($cross_reference_nodes{$section->{'cross_manual_target'}}) and $index > 0)
  7236. {
  7237. $section->{'cross_manual_target'} = $section_cross . "-" .$index;
  7238. $index++;
  7239. }
  7240. my $texi_entry = $section->{'texi'};
  7241. $texi_entry .= "-".$index if ($index > 1);
  7242. push @{$cross_reference_nodes{$section->{'cross_manual_target'}}}, $texi_entry;
  7243. $section->{'id'} = node_to_id($section->{'cross_manual_target'});
  7244. }
  7245. }
  7246. # use the associated @part as target if there is an associated part.
  7247. # do it separately to be sure that all the parts have an id.
  7248. foreach my $section (values(%sections), values(%headings))
  7249. {
  7250. my $target = $section;
  7251. $target = $section->{'with_part'} if ($section->{'with_part'});
  7252. if (get_conf('USE_NODE_TARGET') and $target->{'with_node'})
  7253. {
  7254. $section->{'target'} = $target->{'with_node'}->{'target'};
  7255. }
  7256. else
  7257. {
  7258. $section->{'target'} = $target->{'id'};
  7259. }
  7260. }
  7261. # construct human readable tocid
  7262. foreach my $section (values(%sections))
  7263. {
  7264. if (get_conf('NEW_CROSSREF_STYLE') and ($section->{'cross'} =~ /\S/))
  7265. {
  7266. foreach my $toc_id (['tocid','toc'], ['stocid', 'stoc'])
  7267. {
  7268. my $id_string = $toc_id->[0];
  7269. my $prefix_string = $toc_id->[1];
  7270. my $cross_string = '-' . $section->{'cross_manual_target'};
  7271. $section->{$id_string} = $prefix_string . $cross_string;
  7272. my $index = 1;
  7273. # $index > 0 should prevent integer overflow, hopefully
  7274. while (exists($cross_reference_nodes{$section->{$id_string}}) and $index > 0)
  7275. {
  7276. $section->{$id_string} = $prefix_string . "-" .$index .$cross_string;
  7277. $index++;
  7278. }
  7279. my $texi_entry = $prefix_string.'-'.$section->{'texi'};
  7280. $texi_entry = $prefix_string .'-'.$index.'-'.$section->{'texi'} if ($index > 1);
  7281. push @{$cross_reference_nodes{$section->{$id_string}}}, $texi_entry;
  7282. }
  7283. }
  7284. }
  7285. if (!get_conf('NEW_CROSSREF_STYLE'))
  7286. {
  7287. my $tocnr = 1;
  7288. foreach my $element (@elements_list)
  7289. {
  7290. $element->{'tocid'} = 'TOC' . $tocnr;
  7291. $tocnr++;
  7292. }
  7293. }
  7294. # Set file names
  7295. # Find node file names and file names for nodes considered as elements
  7296. my $node_as_top;
  7297. if ($node_top)
  7298. {
  7299. $node_as_top = $node_top;
  7300. }
  7301. # following possibilities lead to some node being considered
  7302. # as top for the purpose of setting the file node, but not as node_top
  7303. elsif ($element_top->{'with_node'})
  7304. {
  7305. $node_as_top = $element_top->{'with_node'};
  7306. }
  7307. else
  7308. {
  7309. $node_as_top = $node_first;
  7310. }
  7311. if ($node_as_top)
  7312. {
  7313. do_node_target_file($node_as_top, 'top');
  7314. }
  7315. foreach my $key (keys(%nodes))
  7316. {
  7317. my $node = $nodes{$key};
  7318. next if (defined($node_as_top) and ($node eq $node_as_top));
  7319. do_node_target_file($node,'');
  7320. }
  7321. print STDERR "# split(".get_conf('SPLIT').") and set files\n"
  7322. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  7323. # find document nr and document file for sections and nodes.
  7324. # Split according to Texi2HTML::Config::SPLIT.
  7325. # find file and id for placed elements (anchors, index entries, headings)
  7326. if (get_conf('SPLIT'))
  7327. {
  7328. $Texi2HTML::THISDOC{'split_level'} = $toplevel;
  7329. my $doc_nr = -1;
  7330. if (get_conf('SPLIT') eq 'section')
  7331. {
  7332. $Texi2HTML::THISDOC{'split_level'} = 2 if ($toplevel <= 2);
  7333. }
  7334. my $previous_file;
  7335. my $previous_is_top = 0;
  7336. foreach my $element (@elements_list)
  7337. {
  7338. print STDERR "# Splitting (".get_conf('SPLIT').":$Texi2HTML::THISDOC{'split_level'}) $element->{'texi'}\n" if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  7339. my $new_file = 0;
  7340. if (
  7341. (!defined($previous_file)) or
  7342. (get_conf('SPLIT') eq 'node') or
  7343. (
  7344. defined($element->{'level'}) and ($element->{'level'} <= $Texi2HTML::THISDOC{'split_level'})
  7345. ) or
  7346. (
  7347. !defined($element->{'level'}) and defined($element->{'with_section'}) and ($element->{'with_section'}->{'level'} <= $Texi2HTML::THISDOC{'split_level'})
  7348. ) or
  7349. ( # top file after another file
  7350. (defined($previous_file) and ($element eq $element_top)
  7351. and ($previous_file ne $docu_top))
  7352. ) # element following top element is always considered to be
  7353. # in a different file.
  7354. or ($previous_is_top)
  7355. )
  7356. {
  7357. $new_file = 1;
  7358. $doc_nr++;
  7359. }
  7360. $previous_is_top = 0 if ($previous_is_top);
  7361. $element->{'doc_nr'} = $doc_nr;
  7362. $element->{'file'} = "${docu_name}_$doc_nr"
  7363. . (defined(get_conf('EXTENSION')) ? '.'.get_conf('EXTENSION') : '');
  7364. my $use_node_file = 0;
  7365. if ($element eq $element_top)
  7366. { # the top element
  7367. $element->{'file'} = $docu_top;
  7368. $previous_is_top = 1;
  7369. }
  7370. elsif (get_conf('NODE_FILENAMES'))
  7371. {
  7372. $use_node_file = 1;
  7373. if ($new_file)
  7374. {
  7375. my $node = get_node($element);
  7376. if ($node and defined($node->{'node_file'}))
  7377. {
  7378. $element->{'file'} = $node->{'node_file'};
  7379. }
  7380. elsif ($element->{'cross'} =~ /\S/)
  7381. { # use the canonicalized/transliterated section file name.
  7382. $element->{'file'} = $element->{'cross'}
  7383. . (defined(get_conf('EXTENSION')) ? '.'.get_conf('EXTENSION') : '');
  7384. }
  7385. # The remaining case is for sectioning elements with empty
  7386. # headings and no node associated. They will have a name
  7387. # with numbers, like "${docu_name}_$doc_nr", they may
  7388. # collide with split indices names
  7389. }
  7390. else
  7391. {
  7392. $element->{'file'} = $previous_file;
  7393. }
  7394. }
  7395. $previous_file = $element->{'file'};
  7396. do_element_targets($element, $use_node_file);
  7397. print STDERR "# [$doc_nr] add_file($use_node_file,$new_file,".var_to_str($previous_file).") $element->{'file'} for $element->{'texi'}\n" if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  7398. add_file($element->{'file'});
  7399. }
  7400. }
  7401. else
  7402. { # not split
  7403. add_file($docu_doc);
  7404. foreach my $element(@elements_list)
  7405. {
  7406. $element->{'file'} = $docu_doc;
  7407. $element->{'doc_nr'} = 0;
  7408. do_element_targets($element);
  7409. }
  7410. }
  7411. # 'pathological' cases. No texinfo sectioning element at all or no
  7412. # texi2html sectioning elements
  7413. if (!@elements_list)
  7414. {
  7415. if (@all_elements)
  7416. {
  7417. # in fact this happens only if there is no top element, but still
  7418. # sections, so only if USE_SECTIONS = 0 and there is no node.
  7419. #document_warn ("No elements available for splitting") if (get_conf('SPLIT'));
  7420. foreach my $element (@all_elements)
  7421. {
  7422. #print STDERR "# no \@elements_list. Processing $element->{'texi'}\n";
  7423. $element->{'file'} = $docu_doc;
  7424. $element->{'doc_nr'} = 0;
  7425. push @{$element->{'place'}}, @{$element->{'current_place'}};
  7426. do_element_targets($element, get_conf('NODE_FILENAMES'));
  7427. print STDERR "# no \@elements_list, setting $element->{'file'} for $element->{'texi'}\n" if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  7428. }
  7429. add_file($docu_doc);
  7430. }
  7431. else
  7432. {
  7433. #document_warn ("No elements at all") if (get_conf('SPLIT'));
  7434. $element_before_anything->{'file'} = $docu_doc;
  7435. $element_before_anything->{'doc_nr'} = 0;
  7436. do_element_targets($element_before_anything,get_conf('NODE_FILENAMES'));
  7437. print STDERR "# no element at all, setting $element_before_anything->{'file'} for $element_before_anything->{'texi'}\n" if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  7438. }
  7439. }
  7440. # correct the id and file for the things placed in footnotes
  7441. foreach my $place(@{$footnote_element->{'place'}})
  7442. {
  7443. do_place_target_file ($place, $footnote_element, 'footnotes');
  7444. }
  7445. # if setcontentsaftertitlepage is set, the contents should be associated
  7446. # with the titlepage. That's what is done there.
  7447. push @$no_element_associated_place, $content_element{'contents'}
  7448. if (get_conf('contents') and get_conf('setcontentsaftertitlepage'));
  7449. push @$no_element_associated_place, $content_element{'shortcontents'}
  7450. if (get_conf('shortcontents') and get_conf('setshortcontentsaftertitlepage'));
  7451. # correct the id and file for the things placed in regions (copying...)
  7452. foreach my $place(@$no_element_associated_place)
  7453. {
  7454. #print STDERR "entry $place->{'entry'} texi $place->{'texi'}\n";
  7455. $place->{'element'} = $element_top if (exists($place->{'element'}));
  7456. do_place_target_file ($place, $element_top, 'no_associated_element');
  7457. }
  7458. # determine contents element and files
  7459. foreach my $content_type(keys(%content_element))
  7460. {
  7461. # with set*aftertitlepage, there will always be a href to Contents
  7462. # or Overview pointing to the top element, even if there is no
  7463. # titlepage outputed.
  7464. if (!scalar(@{$all_content_elements{$content_type}}))
  7465. {
  7466. if (get_conf('INLINE_CONTENTS'))
  7467. {
  7468. print STDERR "# No content $content_type\n" if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  7469. $content_element{$content_type} = undef;
  7470. }
  7471. }
  7472. elsif (get_conf('INLINE_CONTENTS') and !get_conf('set' . $content_type .'aftertitlepage'))
  7473. { # use the last element for references in case there is more than one
  7474. $content_element{$content_type} = $all_content_elements{$content_type}->[-1];
  7475. }
  7476. }
  7477. my ($toc_file, $stoc_file);
  7478. $toc_file = $docu_toc;
  7479. $stoc_file = $docu_stoc;
  7480. if (get_conf('INLINE_CONTENTS'))
  7481. {
  7482. $toc_file = $content_element{'contents'}->{'file'} if (defined($content_element{'contents'}));
  7483. $stoc_file = $content_element{'shortcontents'}->{'file'} if (defined($content_element{'shortcontents'}));
  7484. }
  7485. $Texi2HTML::THISDOC{'toc_file'} = $toc_file;
  7486. $Texi2HTML::THISDOC{'stoc_file'} = $stoc_file;
  7487. print STDERR "# find NextFile and PrevFile\n"
  7488. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  7489. foreach my $element (@elements_list)
  7490. {
  7491. my $current_element = $element;
  7492. my $file = $current_element->{'file'};
  7493. my $previous_file;
  7494. while ($current_element->{'back'})
  7495. {
  7496. #print STDERR "Back $current_element->{'texi'}\n";
  7497. $current_element = $current_element->{'back'};
  7498. if ($current_element->{'file'} ne $file)
  7499. {
  7500. $previous_file = $current_element->{'file'};
  7501. last;
  7502. }
  7503. }
  7504. if (defined($previous_file))
  7505. {
  7506. while ($current_element->{'back'})
  7507. {
  7508. if ($current_element->{'back'}->{'file'} ne $previous_file)
  7509. {
  7510. last;
  7511. }
  7512. $current_element = $current_element->{'back'};
  7513. }
  7514. $element->{'prevfile'} = $current_element;
  7515. }
  7516. $current_element = $element;
  7517. while ($current_element->{'forward'})
  7518. {
  7519. #print STDERR "Fwd $current_element->{'texi'}\n";
  7520. $current_element = $current_element->{'forward'};
  7521. if ($current_element->{'file'} ne $file)
  7522. {
  7523. $element->{'nextfile'} = $current_element;
  7524. last;
  7525. }
  7526. }
  7527. }
  7528. # convert directions in direction with first letter in all caps, to be
  7529. # consistent with the convention used in the init file.
  7530. foreach my $element (@elements_list)
  7531. {
  7532. foreach my $direction (@element_directions)
  7533. {
  7534. my $direction_no_caps = $direction;
  7535. $direction_no_caps =~ tr/A-Z/a-z/;
  7536. $element->{$direction} = $element->{$direction_no_caps};
  7537. }
  7538. }
  7539. ########################### debug prints
  7540. foreach my $file (keys(%files))
  7541. {
  7542. last unless ($T2H_DEBUG & $DEBUG_ELEMENTS);
  7543. print STDERR "$file: counter $files{$file}->{'counter'}\n";
  7544. }
  7545. my $output_elements = \@elements_list;
  7546. if (!scalar(@elements_list) and ($T2H_DEBUG & $DEBUG_ELEMENTS))
  7547. {
  7548. print STDERR "No elements_list, no texi2html elements\n";
  7549. $output_elements = \@all_elements;
  7550. }
  7551. foreach my $element ((@$output_elements, $footnote_element))
  7552. {
  7553. last unless ($T2H_DEBUG & $DEBUG_ELEMENTS);
  7554. my $is_toplevel = 'not toplevel';
  7555. $is_toplevel = 'toplevel' if ($element->{'toplevel'});
  7556. print STDERR "$element ";
  7557. if ($element->{'node'})
  7558. {
  7559. print STDERR "node($element->{'id'}, $is_toplevel, doc_nr $element->{'doc_nr'}($element->{'file'})) $element->{'texi'}:\n";
  7560. print STDERR " section_ref: $element->{'section_ref'}->{'texi'}\n" if (defined($element->{'section_ref'}));
  7561. print STDERR " with_section: $element->{'with_section'}->{'texi'}\n" if (defined($element->{'with_section'}));
  7562. }
  7563. elsif ($element->{'footnote'})
  7564. {
  7565. print STDERR "footnotes($element->{'id'}, file $element->{'file'})\n";
  7566. }
  7567. else
  7568. {
  7569. my $number = "UNNUMBERED";
  7570. $number = $element->{'number'} if ($element->{'number'});
  7571. print STDERR "$number ($element->{'id'}, $is_toplevel, level $element->{'level'}-$element->{'toc_level'}, doc_nr $element->{'doc_nr'}($element->{'file'})) $element->{'texi'}:\n";
  7572. print STDERR " with_node: $element->{'with_node'}->{'texi'}\n" if (defined($element->{'with_node'}));
  7573. print STDERR " node_ref: $element->{'node_ref'}->{'texi'}\n" if (defined($element->{'node_ref'}));
  7574. }
  7575. if (!$element->{'footnote'})
  7576. {
  7577. if (!defined($files{$element->{'file'}}))
  7578. {
  7579. die "Bug: files{\$element->{'file'}} undef element $element->{'texi'}, file $element->{'file'}.";
  7580. }
  7581. print STDERR " file: $element->{'file'} $files{$element->{'file'}}, counter $files{$element->{'file'}}->{'counter'}\n";
  7582. }
  7583. print STDERR " level: $element->{'level'}\n" if (defined($element->{'level'}));
  7584. print STDERR " TOP($toplevel) " if ($element->{'top'});
  7585. print STDERR " u: $element->{'up'}->{'texi'}\n" if (defined($element->{'up'}));
  7586. print STDERR " ch: $element->{'child'}->{'texi'}\n" if (defined($element->{'child'}));
  7587. print STDERR " fb: $element->{'fastback'}->{'texi'}\n" if (defined($element->{'fastback'}));
  7588. print STDERR " b: $element->{'back'}->{'texi'}\n" if (defined($element->{'back'}));
  7589. print STDERR " p: $element->{'prev'}->{'texi'}\n" if (defined($element->{'prev'}));
  7590. print STDERR " u: $element->{'sectionup'}->{'texi'}\n" if (defined($element->{'sectionup'}));
  7591. print STDERR " n: $element->{'sectionnext'}->{'texi'}\n" if (defined($element->{'sectionnext'}));
  7592. print STDERR " t_n: $element->{'toplevelnext'}->{'texi'}\n" if (defined($element->{'toplevelnext'}));
  7593. print STDERR " t_p: $element->{'toplevelprev'}->{'texi'}\n" if (defined($element->{'toplevelprev'}));
  7594. print STDERR " n_u: $element->{'nodeup'}->{'texi'}\n" if (defined($element->{'nodeup'}));
  7595. print STDERR " f: $element->{'forward'}->{'texi'}\n" if (defined($element->{'forward'}));
  7596. print STDERR " n_f: $element->{'nodeforward'}->{'texi'}\n" if (defined($element->{'nodeforward'}));
  7597. print STDERR " n_b: $element->{'nodeback'}->{'texi'}\n" if (defined($element->{'nodeback'}));
  7598. print STDERR " m_p: $element->{'menu_prev'}->{'texi'}\n" if (defined($element->{'menu_prev'}));
  7599. print STDERR " m_n: $element->{'menu_next'}->{'texi'}\n" if (defined($element->{'menu_next'}));
  7600. print STDERR " m_u: $element->{'menu_up'}->{'texi'}\n" if (defined($element->{'menu_up'}));
  7601. print STDERR " m_ch: $element->{'menu_child'}->{'texi'}\n" if (defined($element->{'menu_child'}));
  7602. print STDERR " ff: $element->{'fastforward'}->{'texi'}\n" if (defined($element->{'fastforward'}));
  7603. print STDERR " n_f: $element->{'nextfile'}->{'texi'}\n" if (defined($element->{'nextfile'}));
  7604. print STDERR " p_f: $element->{'prevfile'}->{'texi'}\n" if (defined($element->{'prevfile'}));
  7605. my $section_childs = '';
  7606. if (defined($element->{'section_childs'}))
  7607. {
  7608. foreach my $child (@{$element->{'section_childs'}})
  7609. {
  7610. $section_childs .= "$child->{'texi'}|";
  7611. }
  7612. }
  7613. print STDERR " s_chs: $section_childs\n" if ($section_childs ne '');
  7614. my $node_childs = '';
  7615. if (defined($element->{'node_childs'}))
  7616. {
  7617. foreach my $child (@{$element->{'node_childs'}})
  7618. {
  7619. $node_childs .= "$child->{'texi'}|";
  7620. }
  7621. }
  7622. print STDERR " n_chs: $node_childs\n" if ($node_childs ne '');
  7623. if (defined($element->{'menu_up_hash'}))
  7624. {
  7625. print STDERR " parent nodes:\n";
  7626. foreach my $menu_up (keys%{$element->{'menu_up_hash'}})
  7627. {
  7628. print STDERR " $menu_up ($element->{'menu_up_hash'}->{$menu_up})\n";
  7629. }
  7630. }
  7631. print STDERR " places: $element->{'place'}\n";
  7632. foreach my $place(@{$element->{'place'}})
  7633. {
  7634. if (!$place->{'entry'} and !$place->{'float'} and !$place->{'texi'} and !$place->{'contents'} and !$place->{'shortcontents'} and (!defined($place->{'command'} or $place->{'command'} ne 'printindex')))
  7635. {
  7636. print STDERR "BUG: unknown placed stuff ========\n";
  7637. foreach my $key (keys(%$place))
  7638. {
  7639. print STDERR "$key: $place->{$key}\n";
  7640. }
  7641. print STDERR "==================================\n";
  7642. }
  7643. elsif ($place->{'entry'})
  7644. {
  7645. print STDERR " index($place): $place->{'entry'} ($place->{'id'}, $place->{'file'})\n";
  7646. }
  7647. elsif ($place->{'anchor'})
  7648. {
  7649. print STDERR " anchor: $place->{'texi'} ($place->{'id'}, $place->{'file'})\n";
  7650. }
  7651. elsif ($place->{'float'})
  7652. {
  7653. if (defined($place->{'texi'}))
  7654. {
  7655. print STDERR " float($place): $place->{'texi'} ($place->{'id'}, $place->{'file'})\n";
  7656. }
  7657. else
  7658. {
  7659. print STDERR " float($place): NO LABEL ($place->{'id'}, $place->{'file'})\n";
  7660. }
  7661. }
  7662. elsif ($place->{'contents'})
  7663. {
  7664. print STDERR " contents\n";
  7665. }
  7666. elsif ($place->{'shortcontents'})
  7667. {
  7668. print STDERR " shortcontents\n";
  7669. }
  7670. elsif (defined($place->{'command'}) and $place->{'command'} eq 'printindex')
  7671. {
  7672. print STDERR " printindex $place->{'name'}\n";
  7673. }
  7674. else
  7675. {
  7676. print STDERR " heading: $place->{'texi'} ($place->{'id'}, $place->{'file'})\n";
  7677. }
  7678. }
  7679. }
  7680. ########################### end debug prints
  7681. }
  7682. sub add_file($)
  7683. {
  7684. my $file = shift;
  7685. if ($files{$file})
  7686. {
  7687. $files{$file}->{'counter'}++;
  7688. }
  7689. else
  7690. {
  7691. $files{$file} = {
  7692. 'counter' => 1,
  7693. 'relative_foot_num' => 0,
  7694. 'foot_lines' => []
  7695. };
  7696. }
  7697. }
  7698. # find parent element which is a toplevel element
  7699. sub get_top($)
  7700. {
  7701. my $element = shift;
  7702. if ($element->{'node'})
  7703. {
  7704. if (defined($element->{'section_ref'}))
  7705. {
  7706. $element = $element->{'section_ref'};
  7707. }
  7708. else
  7709. {
  7710. return undef;
  7711. }
  7712. }
  7713. return undef if ($element eq $element_before_anything);
  7714. my $up = $element;
  7715. while (!$up->{'toplevel'} and $up->{'tag'} ne 'top')
  7716. {
  7717. if (!defined($up->{'sectionup'}))
  7718. {
  7719. # If there is no section, it is normal not to have toplevel element,
  7720. # and it is also the case if there is a low level element before
  7721. # a top level element
  7722. return undef;
  7723. }
  7724. $up = $up->{'sectionup'};
  7725. }
  7726. return $up;
  7727. }
  7728. sub get_node($)
  7729. {
  7730. my $element = shift;
  7731. return undef if (!defined($element));
  7732. return $element if ($element->{'node'});
  7733. return $element->{'with_node'} if ($element->{'with_node'});
  7734. }
  7735. sub do_section_names($$)
  7736. {
  7737. my $number = shift;
  7738. my $section = shift;
  7739. my $texi = &$Texi2HTML::Config::heading_texi($section->{'tag'}, $section->{'texi'}, $section->{'number'});
  7740. $section->{'text'} = substitute_line($texi, "\@$section->{'tag'}", undef, $section->{'line_nr'});
  7741. # no need for translation since there is no line number it should never
  7742. # appear in error messages.
  7743. $section->{'text_nonumber'} = substitute_line($section->{'texi'}, "\@$section->{'tag'} no number");
  7744. # backward compatibility
  7745. # Removed from doc in nov 2009
  7746. $section->{'name'} = $section->{'text_nonumber'};
  7747. $section->{'no_texi'} = remove_texi($texi);
  7748. $section->{'simple_format'} = simple_format(undef,undef,"\@$section->{'tag'} simple_format", $texi);
  7749. $section->{'heading_texi'} = $texi;
  7750. }
  7751. # get the html names from the texi for all elements
  7752. sub do_names()
  7753. {
  7754. print STDERR "# Doing ". scalar(keys(%nodes)) . " nodes, ".
  7755. scalar(keys(%sections)) . " sections, " .
  7756. scalar(keys(%headings)) . " headings in ". $#elements_list .
  7757. " elements\n" if ($T2H_DEBUG);
  7758. # for nodes and anchors we haven't any state defined
  7759. # This seems right, however, as we don't want @refs or @footnotes
  7760. # or @anchors within nodes, section commands or anchors.
  7761. $global_pass = '2 node names';
  7762. foreach my $node (sort(keys(%nodes)))
  7763. {
  7764. my $texi = &$Texi2HTML::Config::heading_texi($nodes{$node}->{'tag'},
  7765. $nodes{$node}->{'texi'}, undef);
  7766. my $command = 'node';
  7767. $command = $nodes{$node}->{'tag'} if ($nodes{$node}->{'tag'});
  7768. $nodes{$node}->{'text'} = substitute_line ($texi, "\@$command", {'code_style' => 1}, $nodes{$node}->{'line_nr'});
  7769. $nodes{$node}->{'text_nonumber'} = $nodes{$node}->{'text'};
  7770. # backward compatibility -> maybe used to have the name without code_style ?
  7771. # Removed from doc in nov 2009
  7772. $nodes{$node}->{'name'} = substitute_line($texi, "\@$command name");
  7773. $nodes{$node}->{'no_texi'} = remove_texi($texi);
  7774. $nodes{$node}->{'simple_format'} = simple_format(undef, undef, "\@$command simple_format", $texi);
  7775. $nodes{$node}->{'heading_texi'} = $texi;
  7776. ################# debug
  7777. # if $nodes{$node}->{'external_node'} and $nodes{$node}->{'seen'}
  7778. # this is a bug, since there are checks that the node hasn't an
  7779. # external node syntax.
  7780. msg_debug ("$nodes{$node}->{'texi'} is external and was seen", $nodes{$node}->{'line_nr'}) if ($nodes{$node}->{'seen'} and $nodes{$node}->{'external_node'});
  7781. ################# end debug
  7782. }
  7783. $global_pass = '2 section names';
  7784. foreach my $number (keys(%sections))
  7785. {
  7786. do_section_names($number, $sections{$number});
  7787. }
  7788. $global_pass = '2 heading names';
  7789. foreach my $number (keys(%headings))
  7790. {
  7791. do_section_names($number, $headings{$number});
  7792. }
  7793. print STDERR "# Names done\n" if ($T2H_DEBUG);
  7794. }
  7795. #+++############################################################################
  7796. # #
  7797. # Stuff related to Index generation #
  7798. # #
  7799. #---############################################################################
  7800. # called during pass_structure
  7801. sub enter_index_entry($$$$$)
  7802. {
  7803. my $prefix = shift;
  7804. my $line_nr = shift;
  7805. my $entry = shift;
  7806. my $command = shift;
  7807. my $state = shift;
  7808. my $heading_element = $state->{'heading_element'};
  7809. my $current_element = $state->{'current_element'};
  7810. my $place = $state->{'place'};
  7811. my $region = $state->{'region'};
  7812. my $index_name = $index_prefix_to_name{$prefix};
  7813. if (!defined($index_name))
  7814. {
  7815. line_error (sprintf(__("Unknown index `%s'"), $prefix), $line_nr);
  7816. }
  7817. if ($current_element eq $element_before_anything)
  7818. {
  7819. #line_warn ("Index entry before document: \@${prefix}index $entry", $line_nr);
  7820. line_error (sprintf(__("Entry for index `%s' outside of any node"), $index_name), $line_nr);
  7821. }
  7822. $entry = trim_comment_spaces ($entry, "index entry in \@$command", $line_nr);
  7823. # beware that the texinfo could be non empty, but the no_texi be empty.
  7824. # So the $no_texi should be used to determine whether the entry is
  7825. # empty or not.
  7826. my $no_texi = remove_texi($entry);
  7827. my $id;
  7828. # don't add a specific index target if the index entry is in a special
  7829. # region like @copying or the like or the index is not defined
  7830. if (!defined($region))
  7831. {
  7832. $region = 'document';
  7833. # No id if the index is unknown.
  7834. $id = 'IDX' . ++$document_idx_num if (defined($index_name));
  7835. }
  7836. my $target = $id;
  7837. # entry will later be in @code for code-like index entry. texi stays
  7838. # the same.
  7839. my $index_entry = {
  7840. 'entry' => $entry,
  7841. 'texi' => $entry,
  7842. 'in_code' => 0,
  7843. 'element' => $heading_element,
  7844. 'real_element' => $current_element,
  7845. 'prefix' => $prefix,
  7846. 'id' => $id,
  7847. 'target' => $target,
  7848. 'command' => $command,
  7849. 'region' => $state->{'region'},
  7850. 'line_nr' => $line_nr,
  7851. 'index_name' => $index_name
  7852. };
  7853. my $id_text = $id;
  7854. $id_text = 'NO ID' if (!defined($id));
  7855. print STDERR "# in $region enter \@$command ${prefix}index($no_texi) [$entry] with id $id_text ($index_entry)\n"
  7856. if ($T2H_DEBUG & $DEBUG_INDEX);
  7857. $index_entry->{'in_code'} = 1
  7858. if (defined($index_name) and
  7859. defined($index_names{$index_name}) and
  7860. $index_names{$index_name}->{$prefix}
  7861. and $no_texi =~ /\S/);
  7862. $index_entry->{'entry'} = '@code{'.$index_entry->{'entry'}.'}'
  7863. if ($index_entry->{'in_code'});
  7864. push @$place, $index_entry;
  7865. #msg_debug("enter_index_entry: region $region, index_entry $index_entry, \@$command, texi `$entry'", $line_nr);
  7866. # don't add the index entry to the list of index entries used for index
  7867. # entry formatting, if the index entry appears in a region like copying
  7868. # currently this is only used for debugging purposes, since the
  7869. # index entries lists are broken by region now.
  7870. push @index_labels, $index_entry unless (defined($state->{'region'}));
  7871. # these lists are used to retrieve index entries in pass 3
  7872. push @{$Texi2HTML::THISDOC{'index_entries'}->{$region}->{$entry}->{'entries'}}, $index_entry;
  7873. if (defined($index_name))
  7874. {
  7875. # this is used for @printindex
  7876. push @{$Texi2HTML::THISDOC{'index_entries_array'}->{$index_name}}, $index_entry;
  7877. # this is used for targets
  7878. push @{$Texi2HTML::THISDOC{'index_entries_region_array'}->{$region}}, $index_entry;
  7879. }
  7880. else
  7881. {
  7882. push @unknown_index_index_entries, $index_entry;
  7883. }
  7884. }
  7885. # these variables are global, so great care should be taken with
  7886. # state->{'multiple_state'}, ->{'region'}, ->{'region_pass'} and
  7887. # {'outside_document'}.
  7888. my $global_head_num = 0; # heading index. it is global for the main doc,
  7889. # and taken from the state if in multiple_pass.
  7890. my $global_foot_num = 0;
  7891. my $global_relative_foot_num = 0;
  7892. my @foot_lines = (); # footnotes
  7893. my $copying_comment = ''; # comment constructed from text between
  7894. # @copying and @end copying with licence
  7895. my %acronyms_like = (); # acronyms or similar commands associated texts
  7896. # the key are the commands, the values are
  7897. # hash references associating shorthands to
  7898. # texts.
  7899. # detailmenu number of opened detailed menus
  7900. sub fill_state($)
  7901. {
  7902. my $state = shift;
  7903. foreach my $key ('preformatted', 'code_style', 'math_style', 'keep_texi',
  7904. 'keep_nr', 'detailmenu', 'direntry', 'sec_num', 'menu', 'multiple_pass')
  7905. {
  7906. $state->{$key} = 0 unless exists($state->{$key});
  7907. }
  7908. $state->{'paragraph_style'} = [ '' ] unless exists($state->{'paragraph_style'});
  7909. $state->{'preformatted_stack'} = [ '' ] unless exists($state->{'preformatted_stack'});
  7910. $state->{'command_stack'} = [] unless exists($state->{'command_stack'});
  7911. $state->{'quotation_stack'} = [] unless exists($state->{'quotation_stack'});
  7912. # if there is no $state->{'element'} the first element is used
  7913. if ((!$state->{'element'} or $state->{'element'}->{'before_anything'}) and (@elements_list))
  7914. {
  7915. $state->{'element'} = $elements_list[0];
  7916. }
  7917. # this is consistent with what is done in rearrange_elements
  7918. $state->{'element'} = {'file' => $docu_doc, 'texi' => 'VIRTUAL ELEMENT'} if (!$state->{'element'});
  7919. }
  7920. sub do_element_directions ($)
  7921. {
  7922. my $this_element = shift;
  7923. #print STDERR "Doing hrefs for $this_element->{'texi'} First ";
  7924. $Texi2HTML::HREF{'First'} = href($element_first, $this_element->{'file'});
  7925. #print STDERR "Last ";
  7926. $Texi2HTML::HREF{'Last'} = href($element_last, $this_element->{'file'});
  7927. #print STDERR "Index ";
  7928. $Texi2HTML::HREF{'Index'} = href($element_chapter_index, $this_element->{'file'}) if (defined($element_chapter_index));
  7929. #print STDERR "Top ";
  7930. $Texi2HTML::HREF{'Top'} = href($element_top, $this_element->{'file'});
  7931. if (get_conf('INLINE_CONTENTS'))
  7932. {
  7933. $Texi2HTML::HREF{'Contents'} = href($content_element{'contents'}, $this_element->{'file'});
  7934. $Texi2HTML::HREF{'Overview'} = href($content_element{'shortcontents'}, $this_element->{'file'});
  7935. }
  7936. else
  7937. {
  7938. $Texi2HTML::HREF{'Contents'} = file_target_href($Texi2HTML::THISDOC{'toc_file'}, $this_element->{'file'}, $content_element{'contents'}->{'target'}) if (@{$Texi2HTML::TOC_LINES} and defined($content_element{'contents'}));
  7939. $Texi2HTML::HREF{'Overview'} = file_target_href($Texi2HTML::THISDOC{'stoc_file'}, $this_element->{'file'}, $content_element{'shortcontents'}->{'target'}) if (@{$Texi2HTML::OVERVIEW} and defined($content_element{'shortcontents'}));
  7940. }
  7941. if ($Texi2HTML::THISDOC{'do_about'})
  7942. {
  7943. $Texi2HTML::HREF{'About'} = file_target_href($docu_about, $this_element->{'file'}, $Texi2HTML::Config::misc_pages_targets{'About'});
  7944. }
  7945. $Texi2HTML::HREF{'Footnotes'} = file_target_href($docu_foot, $this_element->{'file'}, $Texi2HTML::Config::misc_pages_targets{'Footnotes'});
  7946. foreach my $direction (@element_directions)
  7947. {
  7948. my $elem = $this_element->{$direction};
  7949. $Texi2HTML::NODE{$direction} = undef;
  7950. $Texi2HTML::HREF{$direction} = undef;
  7951. $Texi2HTML::NAME{$direction} = undef;
  7952. #print STDERR "$direction \n";
  7953. next unless (defined($elem));
  7954. if ($elem->{'node'} or $elem->{'external_node'} or !$elem->{'seen'})
  7955. {
  7956. $Texi2HTML::NODE{$direction} = $elem->{'text'};
  7957. }
  7958. elsif ($elem->{'with_node'})
  7959. {
  7960. $Texi2HTML::NODE{$direction} = $elem->{'with_node'}->{'text'};
  7961. }
  7962. if (!$elem->{'seen'})
  7963. {
  7964. $Texi2HTML::HREF{$direction} = do_external_href($elem->{'texi'});
  7965. }
  7966. else
  7967. {
  7968. $Texi2HTML::HREF{$direction} = href($elem, $this_element->{'file'});
  7969. }
  7970. $Texi2HTML::NAME{$direction} = $elem->{'text'};
  7971. $Texi2HTML::NO_TEXI{$direction} = $elem->{'no_texi'};
  7972. $Texi2HTML::SIMPLE_TEXT{$direction} = $elem->{'simple_format'};
  7973. #print STDERR "$direction ($this_element->{'texi'}): \n NO_TEXI: $Texi2HTML::NO_TEXI{$direction}\n NAME $Texi2HTML::NAME{$direction}\n NODE $Texi2HTML::NODE{$direction}\n HREF $Texi2HTML::HREF{$direction}\n\n";
  7974. }
  7975. #print STDERR "\nDone hrefs for $this_element->{'texi'}\n";
  7976. }
  7977. sub open_out_file($)
  7978. {
  7979. my $new_file = shift;
  7980. my $do_page_head = 0;
  7981. # if the filehandle is closed, with fileno undef, open_out
  7982. # is called with the second argument true, which leads to opening
  7983. # the file in append mode, to avoid overwriting the previous
  7984. # file.
  7985. if ($files{$new_file}->{'filehandle'} and defined(fileno($files{$new_file}->{'filehandle'})))
  7986. {
  7987. $Texi2HTML::THISDOC{'FH'} = $files{$new_file}->{'filehandle'};
  7988. }
  7989. else
  7990. {
  7991. my $known_file = 0;
  7992. if ($files{$new_file}->{'filehandle'})
  7993. {
  7994. $known_file = 1;
  7995. document_warn ("The file $new_file was already closed and is reopened");
  7996. }
  7997. $Texi2HTML::THISDOC{'FH'} = open_out("$docu_rdir$new_file", $known_file);
  7998. #print STDERR "OPEN $docu_rdir$file, $Texi2HTML::THISDOC{'FH'}". scalar($Texi2HTML::THISDOC{'FH'})."\n";
  7999. $files{$new_file}->{'filehandle'} = $Texi2HTML::THISDOC{'FH'};
  8000. $do_page_head = !$known_file;
  8001. }
  8002. return $do_page_head;
  8003. }
  8004. sub set_line_nr_in_stack($$$)
  8005. {
  8006. my $state = shift;
  8007. my $stack = shift;
  8008. my $line_nr = shift;
  8009. if ($state->{'keep_texi'} and defined($line_nr))
  8010. {
  8011. my $stack_index = $#$stack;
  8012. while ($stack_index >= 0 and defined($stack->[$stack_index]->{'keep_line_nr'}))
  8013. {
  8014. push @{$stack->[$stack_index]->{'keep_line_nr'}}, $line_nr;
  8015. $stack_index --;
  8016. }
  8017. }
  8018. }
  8019. sub unref_file($)
  8020. {
  8021. my $file = shift;
  8022. $files{$file}->{'counter'}--;
  8023. print STDERR "# Unref file $file, remaining counter $files{$file}->{'counter'}\n"
  8024. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  8025. }
  8026. sub pass_text($$)
  8027. {
  8028. my $doc_lines = shift;
  8029. my $doc_numbers = shift;
  8030. my %state;
  8031. fill_state(\%state);
  8032. my @stack;
  8033. my $text = '';
  8034. my $doc_nr;
  8035. my $in_doc = 0;
  8036. my @text =();
  8037. my $one_section = 1 if (@elements_list <= 1);
  8038. push_state(\%state);
  8039. $global_pass = '3 prepare names';
  8040. set_special_names();
  8041. $footnote_element->{'text'} = $Texi2HTML::NAME{'Footnotes'};
  8042. # We set titlefont only if the titlefont appeared in the top element
  8043. if (defined($element_top->{'titlefont'}))
  8044. {
  8045. $Texi2HTML::THISDOC{'titlefont_texi'} = $element_top->{'titlefont'};
  8046. # backward compatibility obsoleted in nov 2009
  8047. $value{'_titlefont'} = $element_top->{'titlefont'};
  8048. }
  8049. # prepare %Texi2HTML::THISDOC
  8050. $Texi2HTML::THISDOC{'command_stack'} = $state{'command_stack'};
  8051. $Texi2HTML::THISDOC{'top_texi'} = $section_top->{'texi'} if (defined($section_top));
  8052. $Texi2HTML::THISDOC{'fulltitle_texi'} = '';
  8053. foreach my $possible_fulltitle('settitle', 'title', 'shorttitlepage', 'top', 'titlefont')
  8054. {
  8055. if (defined($Texi2HTML::THISDOC{$possible_fulltitle . '_texi'}) and $Texi2HTML::THISDOC{$possible_fulltitle . '_texi'} =~ /\S/)
  8056. {
  8057. $Texi2HTML::THISDOC{'fulltitle_texi'} = $Texi2HTML::THISDOC{$possible_fulltitle . '_texi'};
  8058. last;
  8059. }
  8060. }
  8061. $Texi2HTML::THISDOC{'simpletitle_texi'} = '';
  8062. foreach my $possible_simpletitle('settitle', 'shorttitlepage')
  8063. {
  8064. if (defined($Texi2HTML::THISDOC{$possible_simpletitle . '_texi'}) and $Texi2HTML::THISDOC{$possible_simpletitle . '_texi'} =~ /\S/)
  8065. {
  8066. $Texi2HTML::THISDOC{'simpletitle_texi'} = $Texi2HTML::THISDOC{$possible_simpletitle . '_texi'};
  8067. last;
  8068. }
  8069. }
  8070. foreach my $doc_thing (('shorttitlepage', 'settitle', 'author',
  8071. 'titlefont', 'subtitle', 'title', 'fulltitle', 'simpletitle'))
  8072. {
  8073. my $thing_texi = $Texi2HTML::THISDOC{$doc_thing . '_texi'};
  8074. $Texi2HTML::THISDOC{$doc_thing} = substitute_line($thing_texi, "\@$doc_thing", undef, $Texi2HTML::THISDOC{$doc_thing . '_line_nr'});
  8075. $Texi2HTML::THISDOC{$doc_thing . '_no_texi'} =
  8076. remove_texi($thing_texi);
  8077. $Texi2HTML::THISDOC{$doc_thing . '_simple_format'} =
  8078. simple_format(undef, undef, "simple_format \@$doc_thing", $thing_texi);
  8079. }
  8080. # find the triplet (Top name, Top with texi removed, Top simply formatted)
  8081. # the corresponding href is used a lot but these are only used because
  8082. # they are used in LINKS_BUTTONS...
  8083. my $element_top_Top = [undef,undef,undef];
  8084. my $node_top_Top = [undef,undef,undef];
  8085. # Preferred Top name is the element_top name if it is not the @node Top
  8086. # the @node Top may also be used, but before fulltitle is tried
  8087. if (defined($element_top))
  8088. {
  8089. if ($element_top->{'node'} and $element_top->{'texi'} =~ /^Top$/i)
  8090. {
  8091. $node_top_Top = [ $element_top->{'text'}, $element_top->{'no_texi'}, $element_top->{'simple_format'} ];
  8092. }
  8093. else
  8094. {
  8095. $element_top_Top = [ $element_top->{'text'}, $element_top->{'no_texi'}, $element_top->{'simple_format'} ];
  8096. }
  8097. }
  8098. # FIXME remove fulltitle?
  8099. foreach my $possible_top (
  8100. [substitute_line($Texi2HTML::Config::TOP_HEADING, '$TOP_HEADING'),
  8101. remove_texi($Texi2HTML::Config::TOP_HEADING),
  8102. simple_format(undef, undef, 'simple_format $TOP_HEADING', $Texi2HTML::Config::TOP_HEADING)],
  8103. $element_top_Top,
  8104. [$Texi2HTML::THISDOC{'fulltitle'},
  8105. $Texi2HTML::THISDOC{'fulltitle_no_texi'},
  8106. $Texi2HTML::THISDOC{'fulltitle_simple_format'}],
  8107. $node_top_Top
  8108. )
  8109. {
  8110. if (defined($possible_top->[0]) and $possible_top->[0] =~ /\S/)
  8111. {
  8112. ($Texi2HTML::NAME{'Top'}, $Texi2HTML::NO_TEXI{'Top'}, $Texi2HTML::SIMPLE_TEXT{'Top'}) = @$possible_top;
  8113. print STDERR "RESULTING TOP: ".join('|', @$possible_top)."\n"
  8114. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  8115. last;
  8116. }
  8117. }
  8118. $Texi2HTML::THISDOC{'program'} = $THISPROG;
  8119. $Texi2HTML::THISDOC{'program_and_version'} = $THISPROG_THISVERSION;
  8120. $Texi2HTML::THISDOC{'program_homepage'} = $T2H_HOMEPAGE;
  8121. # titles is for backard compatibility
  8122. foreach my $command (('authors', 'subtitles', 'titles'))
  8123. {
  8124. $Texi2HTML::THISDOC{$command} = [];
  8125. my $i;
  8126. for ($i = 0; $i < $#{$Texi2HTML::THISDOC{$command .'_texi'}} + 1; $i++)
  8127. {
  8128. my $texi_line = $Texi2HTML::THISDOC{$command .'_texi'}->[$i];
  8129. my $command_line_nr = $Texi2HTML::THISDOC{$command .'_line_nr'}->[$i];
  8130. chomp ($texi_line);
  8131. $Texi2HTML::THISDOC{$command}->[$i] = substitute_line($texi_line, "\@$command", undef, $command_line_nr);
  8132. #print STDERR "$command:$i: $Texi2HTML::THISDOC{$command}->[$i]\n";
  8133. }
  8134. }
  8135. $Texi2HTML::THISDOC{'do_about'} = 1 unless (!get_conf('DO_ABOUT') or $one_section or (not get_conf('SPLIT') and not get_conf('HEADERS')));
  8136. $Texi2HTML::NAME{'First'} = $element_first->{'text'};
  8137. $Texi2HTML::NAME{'Last'} = $element_last->{'text'};
  8138. $Texi2HTML::NAME{'Index'} = $element_chapter_index->{'text'} if (defined($element_chapter_index));
  8139. $Texi2HTML::NAME{'Index'} = $Texi2HTML::Config::INDEX_CHAPTER if ($Texi2HTML::Config::INDEX_CHAPTER ne '');
  8140. $Texi2HTML::NO_TEXI{'First'} = $element_first->{'no_texi'};
  8141. $Texi2HTML::NO_TEXI{'Last'} = $element_last->{'no_texi'};
  8142. $Texi2HTML::NO_TEXI{'Index'} = $element_chapter_index->{'no_texi'} if (defined($element_chapter_index));
  8143. $Texi2HTML::SIMPLE_TEXT{'First'} = $element_first->{'simple_format'};
  8144. $Texi2HTML::SIMPLE_TEXT{'Last'} = $element_last->{'simple_format'};
  8145. $Texi2HTML::SIMPLE_TEXT{'Index'} = $element_chapter_index->{'simple_format'} if (defined($element_chapter_index));
  8146. # We do the regions formatting here, even if they never appear.
  8147. # so we should be very carefull to take into accout 'outside_document' to
  8148. # avoid messing with information that has to be set in the main document.
  8149. # FIXME also the error messages will appear even though the corresponding
  8150. # texinfo is never used. Since no state is passed to the do_special_region_lines
  8151. # 'outside_document' will be true. Also 'multiple_pass' is equal to -1
  8152. # for this case.
  8153. $global_pass = '3 prepare regions';
  8154. my ($region_text, $region_no_texi, $region_simple_format);
  8155. ($region_text, $region_no_texi, $region_simple_format) = do_special_region_lines('documentdescription');
  8156. &$Texi2HTML::Config::documentdescription($region_lines{'documentdescription'}, $region_text, $region_no_texi, $region_simple_format);
  8157. # do copyright notice inserted in comment at the beginning of the files
  8158. ($region_text, $region_no_texi, $region_simple_format) = do_special_region_lines('copying');
  8159. $copying_comment = &$Texi2HTML::Config::copying_comment($region_lines{'copying'}, $region_text, $region_no_texi, $region_simple_format);
  8160. $Texi2HTML::THISDOC{'copying_comment'} = $copying_comment;
  8161. # must be after toc_body, but before titlepage
  8162. foreach my $command ('contents', 'shortcontents')
  8163. {
  8164. next if (!defined($content_element{$command}));
  8165. my $toc_lines = &$Texi2HTML::Config::inline_contents(undef, $command, $content_element{$command}, \@sections_list);
  8166. @{$Texi2HTML::THISDOC{'inline_contents'}->{$command}} = @$toc_lines if (defined($toc_lines));
  8167. }
  8168. ($region_text, $region_no_texi, $region_simple_format) = do_special_region_lines('titlepage');
  8169. &$Texi2HTML::Config::titlepage($region_lines{'titlepage'}, $region_text, $region_no_texi, $region_simple_format);
  8170. $global_pass = '3';
  8171. &$Texi2HTML::Config::init_out();
  8172. # FIXME It is not clear whether it should be here or before
  8173. # command_handler_output calls. After, it means that
  8174. # command_handler_output may modify the initializations. Before
  8175. # it allows to look at the values from the preceding pass.
  8176. texinfo_initialization(2);
  8177. foreach my $handler(@Texi2HTML::Config::command_handler_output)
  8178. {
  8179. &$handler;
  8180. }
  8181. ############################################################################
  8182. # print frame and frame toc file
  8183. #
  8184. if (get_conf('FRAMES'))
  8185. {
  8186. my $FH = open_out($docu_frame_file);
  8187. print STDERR "# Creating frame in $docu_frame_file ...\n" if $T2H_VERBOSE;
  8188. &$Texi2HTML::Config::print_frame($FH, $docu_toc_frame_file, $docu_top_file);
  8189. close_out($FH, $docu_frame_file);
  8190. $FH = open_out($docu_toc_frame_file);
  8191. print STDERR "# Creating toc frame in $docu_frame_file ...\n" if $T2H_VERBOSE;
  8192. &$Texi2HTML::Config::print_toc_frame($FH, $Texi2HTML::OVERVIEW);
  8193. close_out($FH, $docu_toc_frame_file);
  8194. }
  8195. ############################################################################
  8196. # Start processing the document
  8197. #
  8198. #my $FH;
  8199. my $line_nr;
  8200. my $current_file;
  8201. my $first_section = 0; # 1 if it is the first section of a page
  8202. my $previous_is_top = 0; # 1 if it is the element following the top element
  8203. my $cline;
  8204. # this is true for the state that goes through the document
  8205. $state{'inside_document'} = 1;
  8206. while (@$doc_lines)
  8207. {
  8208. $cline = shift @$doc_lines;
  8209. my $chomped_line = $cline;
  8210. if (!chomp($chomped_line) and @$doc_lines)
  8211. { # if the line has no end of line it is concatenated with the next
  8212. # this shouldn't happen anymore. And will certainly mess up
  8213. # line counting. Let it be a bug.
  8214. msg_debug ("no end of line line passed in doc_line",$line_nr);
  8215. $doc_lines->[0] = $cline . $doc_lines->[0];
  8216. next;
  8217. }
  8218. $line_nr = shift (@$doc_numbers);
  8219. $Texi2HTML::THISDOC{'line_nr'} = $line_nr;
  8220. print STDERR "BUG: line_nr not defined in pass_text. cline: $cline" if (!defined($line_nr));
  8221. #dump_stack(\$text, \@stack, \%state);
  8222. # make sure the current state from here is $Texi2HTML::THIS_ELEMENT
  8223. # in case it was set by the user.
  8224. $state{'element'} = $Texi2HTML::THIS_ELEMENT if (defined($Texi2HTML::THIS_ELEMENT));
  8225. #print STDERR "PASS_TEXT($line_nr->{'line_nr'})$cline";
  8226. if (!$state{'raw'} and !$state{'verb'})
  8227. {
  8228. my $tag = '';
  8229. $tag = $1 if ($cline =~ /^\@(\w+)/);
  8230. if ($tag eq 'setfilename' and get_conf('IGNORE_BEFORE_SETFILENAME'))
  8231. {
  8232. if (defined($Texi2HTML::THIS_ELEMENT))
  8233. {
  8234. line_warn (sprintf(__("\@%s after the first element"), $tag), $line_nr);
  8235. }
  8236. else
  8237. {
  8238. @{$Texi2HTML::THIS_SECTION} = ();
  8239. }
  8240. }
  8241. if (($tag eq 'node') or (defined($sec2level{$tag}) and ($tag !~ /heading/)))
  8242. {
  8243. # in pass text node and section shouldn't appear in formats
  8244. #print STDERR "close_stack before \@$tag\n";
  8245. #print STDERR "text!$text%" if (! @stack);
  8246. close_stack(\$text, \@stack, \%state, $line_nr);
  8247. msg_debug ("text undef", $line_nr) if (!defined($text));
  8248. push @{$Texi2HTML::THIS_SECTION}, $text if ($text ne '');
  8249. $text = '';
  8250. $state{'sec_num'}++ if ($sec2level{$tag} and ($tag ne 'top'));
  8251. my $new_element;
  8252. my $current_element;
  8253. # handle node and structuring elements
  8254. $current_element = shift (@all_elements);
  8255. ########################## begin debug section
  8256. if (!defined($current_element))
  8257. {
  8258. msg_debug ("No element left for $cline", $line_nr);
  8259. }
  8260. if ($current_element->{'node'})
  8261. {
  8262. print STDERR 'NODE ' . "$current_element->{'texi'}($current_element->{'file'})" if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  8263. print STDERR "($current_element->{'section_ref'}->{'texi'})" if ($current_element->{'section_ref'} and ($T2H_DEBUG & $DEBUG_ELEMENTS));
  8264. }
  8265. else
  8266. {
  8267. print STDERR 'SECTION ' . $current_element->{'texi'} if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  8268. }
  8269. print STDERR ": $cline" if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  8270. ########################## end debug section
  8271. # The element begins a new section if there is no previous
  8272. # or the reference element is not the same
  8273. if (defined($current_element->{'element_ref'}) and (!$Texi2HTML::THIS_ELEMENT or ($current_element->{'element_ref'} ne $Texi2HTML::THIS_ELEMENT)))
  8274. {
  8275. $new_element = $current_element->{'element_ref'};
  8276. ########################### debug
  8277. my $old = 'NO_OLD';
  8278. $old = $Texi2HTML::THIS_ELEMENT->{'texi'} if (defined($Texi2HTML::THIS_ELEMENT));
  8279. print STDERR "NEW: $new_element->{'texi'}, OLD: $old\n" if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  8280. ########################### end debug
  8281. # print the element that just finished
  8282. if ($Texi2HTML::THIS_ELEMENT)
  8283. {
  8284. finish_element($Texi2HTML::THISDOC{'FH'}, $Texi2HTML::THIS_ELEMENT, $new_element, $first_section);
  8285. $first_section = 0;
  8286. $previous_is_top = 0 if (!$Texi2HTML::THIS_ELEMENT->{'top'});
  8287. @{$Texi2HTML::THIS_SECTION} = ();
  8288. }
  8289. else
  8290. {
  8291. print STDERR "# Writing elements:" if ($T2H_VERBOSE);
  8292. if (get_conf('IGNORE_PREAMBLE_TEXT'))
  8293. {
  8294. @{$Texi2HTML::THIS_SECTION} = ();
  8295. }
  8296. # remove empty for the first document lines
  8297. shift @{$Texi2HTML::THIS_SECTION} while (@{$Texi2HTML::THIS_SECTION} and ($Texi2HTML::THIS_SECTION->[0] =~ /^\s*$/));
  8298. my $title = &$Texi2HTML::Config::print_title();
  8299. unshift @{$Texi2HTML::THIS_SECTION}, $title if (defined($title) and $title ne '');
  8300. }
  8301. # begin new element
  8302. $Texi2HTML::THIS_ELEMENT = $new_element;
  8303. $state{'element'} = $Texi2HTML::THIS_ELEMENT;
  8304. do_element_directions($Texi2HTML::THIS_ELEMENT);
  8305. unref_file ($Texi2HTML::THIS_ELEMENT->{'file'});
  8306. #if (!defined($previous_file) or ($Texi2HTML::THIS_ELEMENT->{'file'} ne $previous_file))
  8307. if (!defined($current_file) or ($Texi2HTML::THIS_ELEMENT->{'file'} ne $current_file))
  8308. {
  8309. $current_file = $Texi2HTML::THIS_ELEMENT->{'file'};
  8310. print STDERR "\n" if ($T2H_VERBOSE and !$T2H_DEBUG);
  8311. print STDERR "# Writing to $docu_rdir$current_file " if $T2H_VERBOSE;
  8312. my $do_page_head = open_out_file($current_file);
  8313. if ($Texi2HTML::THIS_ELEMENT->{'top'})
  8314. {
  8315. &$Texi2HTML::Config::print_Top_header($Texi2HTML::THISDOC{'FH'}, $do_page_head);
  8316. $previous_is_top = 1;
  8317. }
  8318. else
  8319. {
  8320. &$Texi2HTML::Config::print_page_head($Texi2HTML::THISDOC{'FH'}) if ($do_page_head);
  8321. &$Texi2HTML::Config::print_chapter_header($Texi2HTML::THISDOC{'FH'}, $Texi2HTML::THIS_ELEMENT) if get_conf('SPLIT') eq 'chapter';
  8322. &$Texi2HTML::Config::print_section_header($Texi2HTML::THISDOC{'FH'}, $Texi2HTML::THIS_ELEMENT) if get_conf('SPLIT') eq 'section';
  8323. }
  8324. $first_section = 1;
  8325. }
  8326. print STDERR "." if ($T2H_VERBOSE);
  8327. print STDERR "\n" if ($T2H_DEBUG);
  8328. }
  8329. my $cmd_line = $cline;
  8330. $cmd_line =~ s/\@$tag\s*//;
  8331. ######################## begin debug
  8332. msg_debug ("Element $current_element current_element->{'tag_level'} not defined", $line_nr)
  8333. if (!defined($current_element->{'tag_level'}));
  8334. msg_debug ("Element $current_element $tag ne ".var_to_str($current_element->{'tag'}), $line_nr)
  8335. if ($tag ne 'node' and (!defined($current_element->{'tag'}) or $tag ne $current_element->{'tag'}));
  8336. msg_debug ("Element $current_element ".var_to_str($current_element->{'tag'})." is not a node, but tag is a node", $line_nr)
  8337. if ($tag eq 'node' and !$current_element->{'node'});
  8338. ######################## end debug
  8339. my $heading_formatted = &$Texi2HTML::Config::element_heading($current_element, $tag, $cmd_line, substitute_line($cmd_line, "\@$tag"), undef, $one_section, $current_element->{'this'}, $first_section, $current_element->{'top'}, $previous_is_top, $cline, $current_element->{'id'}, $new_element);
  8340. push @{$Texi2HTML::THIS_SECTION}, $heading_formatted if (defined($heading_formatted) and ($heading_formatted ne ''));
  8341. next;
  8342. }
  8343. }
  8344. set_line_nr_in_stack(\%state, \@stack, $line_nr);
  8345. scan_line($cline, \$text, \@stack, \%state, $line_nr);
  8346. #print STDERR "after scan_line: $cline";
  8347. #dump_stack(\$text, \@stack, \%state);
  8348. next if (@stack);
  8349. if ($text ne '')
  8350. {
  8351. push @{$Texi2HTML::THIS_SECTION}, $text;
  8352. $text = '';
  8353. }
  8354. }
  8355. # close stack at the end of pass text
  8356. close_stack(\$text, \@stack, \%state, $line_nr);
  8357. if (defined($text))
  8358. {
  8359. push @{$Texi2HTML::THIS_SECTION}, $text;
  8360. }
  8361. print STDERR "\n" if ($T2H_VERBOSE);
  8362. # if no sections, then simply print document as is
  8363. if ($one_section)
  8364. {
  8365. # may happen if there are 0 sections
  8366. if (! defined($Texi2HTML::THISDOC{'FH'}))
  8367. {
  8368. open_out_file($docu_doc);
  8369. &$Texi2HTML::Config::print_page_head($Texi2HTML::THISDOC{'FH'});
  8370. shift @{$Texi2HTML::THIS_SECTION} while (@{$Texi2HTML::THIS_SECTION} and ($Texi2HTML::THIS_SECTION->[0] =~ /^\s*$/));
  8371. my $title = &$Texi2HTML::Config::print_title();
  8372. unshift @{$Texi2HTML::THIS_SECTION}, $title if (defined($title) and $title ne '');
  8373. }
  8374. if (@foot_lines)
  8375. {
  8376. &$Texi2HTML::Config::foot_section (\@foot_lines);
  8377. push @{$Texi2HTML::THIS_SECTION}, @foot_lines;
  8378. }
  8379. print STDERR "# Write the section $Texi2HTML::THIS_ELEMENT->{'texi'}\n" if ($T2H_VERBOSE);
  8380. &$Texi2HTML::Config::one_section($Texi2HTML::THISDOC{'FH'}, $Texi2HTML::THIS_ELEMENT);
  8381. close_out($Texi2HTML::THISDOC{'FH'}, $docu_doc_file);
  8382. # no misc element is done
  8383. return;
  8384. }
  8385. finish_element ($Texi2HTML::THISDOC{'FH'}, $Texi2HTML::THIS_ELEMENT, undef, $first_section);
  8386. ############################################################################
  8387. # Print ToC, Overview, Footnotes
  8388. #
  8389. foreach my $direction (@element_directions)
  8390. {
  8391. $Texi2HTML::HREF{$direction} = undef;
  8392. delete $Texi2HTML::HREF{$direction};
  8393. # it is better to undef in case the references to these hash entries
  8394. # are used, as if deleted, the
  8395. # references are still refering to the old, undeleted element
  8396. # (we could do both)
  8397. $Texi2HTML::NAME{$direction} = undef;
  8398. $Texi2HTML::NO_TEXI{$direction} = undef;
  8399. $Texi2HTML::SIMPLE_TEXT{$direction} = undef;
  8400. $Texi2HTML::NODE{$direction} = undef;
  8401. $Texi2HTML::THIS_ELEMENT = undef;
  8402. }
  8403. my $about_body;
  8404. $about_body = &$Texi2HTML::Config::about_body() if (defined($Texi2HTML::Config::about_body));
  8405. # @foot_lines is emptied in finish_element if footnotestyle separate
  8406. my %misc_page_infos = (
  8407. 'Footnotes' => { 'file' => $docu_foot_file,
  8408. 'relative_file' => $docu_foot,
  8409. 'process' => $Texi2HTML::Config::print_Footnotes,
  8410. 'section' => \@foot_lines },
  8411. 'Contents' => { 'file' => $docu_toc_file,
  8412. 'relative_file' => $docu_toc,
  8413. 'process' => $Texi2HTML::Config::print_Toc,
  8414. 'section' => $Texi2HTML::TOC_LINES },
  8415. 'Overview' => { 'file' => $docu_stoc_file,
  8416. 'relative_file' => $docu_stoc,
  8417. 'process' => $Texi2HTML::Config::print_Overview,
  8418. 'section' => $Texi2HTML::OVERVIEW },
  8419. 'About' => { 'file' => $docu_about_file,
  8420. 'relative_file' => $docu_about,
  8421. 'process' => $Texi2HTML::Config::print_About,
  8422. 'section' => [$about_body] }
  8423. );
  8424. $misc_page_infos{'Footnotes'}->{'do'} = 1 if (@foot_lines);
  8425. $misc_page_infos{'Contents'}->{'do'} = 1 if
  8426. (@{$Texi2HTML::TOC_LINES} and !get_conf('INLINE_CONTENTS') and (!get_conf('setcontentsaftertitlepage') or !get_conf('USE_TITLEPAGE_FOR_TITLE')));
  8427. $misc_page_infos{'Overview'}->{'do'} = 1 if
  8428. (@{$Texi2HTML::OVERVIEW} and !get_conf('INLINE_CONTENTS') and (!get_conf('setshortcontentsaftertitlepage') or !get_conf('USE_TITLEPAGE_FOR_TITLE')));
  8429. $misc_page_infos{'About'}->{'do'} = 1 if ($about_body and $Texi2HTML::THISDOC{'do_about'});
  8430. foreach my $misc_page('Footnotes', 'Contents', 'Overview', 'About')
  8431. {
  8432. next unless ($misc_page_infos{$misc_page}->{'do'});
  8433. my $file = $misc_page_infos{$misc_page}->{'file'};
  8434. my $relative_file = $misc_page_infos{$misc_page}->{'relative_file'};
  8435. print STDERR "# writing $misc_page in $file\n" if $T2H_VERBOSE;
  8436. my $saved_FH;
  8437. my $open_new = 0;
  8438. if ($relative_file ne $docu_doc)
  8439. {
  8440. $saved_FH = $Texi2HTML::THISDOC{'FH'};
  8441. # Use open_out_file not to overwrite a file that the user would have
  8442. # created
  8443. open_out_file ($relative_file);
  8444. print STDERR "# Opening $file for $misc_page\n" if $T2H_VERBOSE;
  8445. $open_new = 1;
  8446. }
  8447. else
  8448. {
  8449. print STDERR "# writing $misc_page in current file\n" if $T2H_VERBOSE;
  8450. }
  8451. foreach my $href_page (keys(%misc_page_infos))
  8452. {
  8453. $Texi2HTML::HREF{$href_page} = file_target_href(
  8454. $misc_page_infos{$href_page}->{'relative_file'}, $relative_file,
  8455. $Texi2HTML::Config::misc_pages_targets{$href_page})
  8456. if ($misc_page_infos{$href_page}->{'do'});
  8457. }
  8458. #print STDERR "Doing hrefs for $misc_page First ";
  8459. $Texi2HTML::HREF{'First'} = href($element_first, $relative_file);
  8460. #print STDERR "Last ";
  8461. $Texi2HTML::HREF{'Last'} = href($element_last, $relative_file);
  8462. #print STDERR "Index ";
  8463. $Texi2HTML::HREF{'Index'} = href($element_chapter_index, $relative_file) if (defined($element_chapter_index));
  8464. #print STDERR "Top ";
  8465. $Texi2HTML::HREF{'Top'} = href($element_top, $relative_file);
  8466. if (get_conf('INLINE_CONTENTS'))
  8467. {
  8468. $Texi2HTML::HREF{'Contents'} = href($content_element{'contents'}, $relative_file);
  8469. $Texi2HTML::HREF{'Overview'} = href($content_element{'shortcontents'}, $relative_file);
  8470. }
  8471. $Texi2HTML::HREF{$misc_page} = '#' . $Texi2HTML::Config::misc_pages_targets{$misc_page};
  8472. $Texi2HTML::HREF{'This'} = $Texi2HTML::HREF{$misc_page};
  8473. $Texi2HTML::NAME{'This'} = $Texi2HTML::NAME{$misc_page};
  8474. $Texi2HTML::NO_TEXI{'This'} = $Texi2HTML::NO_TEXI{$misc_page};
  8475. $Texi2HTML::SIMPLE_TEXT{'This'} = $Texi2HTML::SIMPLE_TEXT{$misc_page};
  8476. $Texi2HTML::THIS_SECTION = $misc_page_infos{$misc_page}->{'section'}
  8477. if defined($misc_page_infos{$misc_page}->{'section'});
  8478. &{$misc_page_infos{$misc_page}->{'process'}}($Texi2HTML::THISDOC{'FH'}, $open_new, $misc_page);
  8479. if ($open_new)
  8480. {
  8481. close_out($Texi2HTML::THISDOC{'FH'}, $file);
  8482. $Texi2HTML::THISDOC{'FH'} = $saved_FH;
  8483. }
  8484. }
  8485. unless (get_conf('SPLIT'))
  8486. {
  8487. &$Texi2HTML::Config::print_page_foot($Texi2HTML::THISDOC{'FH'});
  8488. # this leaves the possibility for external code to close the file
  8489. # without erroring out
  8490. close_out ($Texi2HTML::THISDOC{'FH'}, $docu_doc_file) if (fileno($Texi2HTML::THISDOC{'FH'}));
  8491. }
  8492. pop_state();
  8493. }
  8494. # print section, close file if needed.
  8495. sub finish_element($$$$)
  8496. {
  8497. my $FH = shift;
  8498. my $element = shift;
  8499. my $new_element = shift;
  8500. my $first_section = shift;
  8501. #print STDERR "FINISH_ELEMENT($FH)($element->{'texi'})[$element->{'file'}] counter $files{$element->{'file'}}->{'counter'}\n";
  8502. # handle foot notes
  8503. if (get_conf('SPLIT') and scalar(@foot_lines)
  8504. and (get_conf('footnotestyle') eq 'end')
  8505. and (! $new_element or
  8506. ($element and ($new_element->{'file'} ne $element->{'file'})))
  8507. )
  8508. {
  8509. if ($files{$element->{'file'}}->{'counter'})
  8510. {# there are other elements in that page we are not on its foot
  8511. $files{$element->{'file'}}->{'relative_foot_num'}
  8512. = $global_relative_foot_num;
  8513. push @{$files{$element->{'file'}}->{'foot_lines'}},
  8514. @foot_lines;
  8515. }
  8516. else
  8517. {# we output the footnotes as we are at the file end
  8518. unshift @foot_lines, @{$files{$element->{'file'}}->{'foot_lines'}};
  8519. &$Texi2HTML::Config::foot_section (\@foot_lines);
  8520. push @{$Texi2HTML::THIS_SECTION}, @foot_lines;
  8521. }
  8522. if ($new_element)
  8523. {
  8524. $global_relative_foot_num =
  8525. $files{$new_element->{'file'}}->{'relative_foot_num'};
  8526. }
  8527. @foot_lines = ();
  8528. }
  8529. if ($element->{'top'})
  8530. {
  8531. ############### debug
  8532. #print STDERR "TOP $element->{'texi'}, @{$Texi2HTML::THIS_SECTION}\n";
  8533. die "element->{'top'} $element ne element_top $element_top" if ($element ne $element_top);
  8534. print STDERR "# Doing element top\n"
  8535. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  8536. print STDERR "[Top]" if ($T2H_VERBOSE);
  8537. ############### end debug
  8538. &$Texi2HTML::Config::print_Top($FH, $element->{'titlefont'}, $element);
  8539. my $end_page = 0;
  8540. if (get_conf('SPLIT'))
  8541. {
  8542. if ($files{$element->{'file'}}->{'counter'} == 0)
  8543. {
  8544. $end_page = 1;
  8545. }
  8546. }
  8547. &$Texi2HTML::Config::print_Top_footer($FH, $end_page, $element);
  8548. close_out($FH, $docu_top_file) if ($end_page);
  8549. }
  8550. else
  8551. {
  8552. print STDERR "# do element $element->{'texi'}\n"
  8553. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  8554. &$Texi2HTML::Config::print_section($FH, $first_section, 0, $element);
  8555. ################# debug
  8556. my $new_elem_file = 'NO ELEM => no file';
  8557. $new_elem_file = $new_element->{'file'} if (defined($new_element));
  8558. print STDERR "# FILES new: $new_elem_file old(".fileno($FH)."): $element->{'file'}\n"
  8559. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  8560. ################# end debug
  8561. if (defined($new_element) and ($new_element->{'file'} ne $element->{'file'}))
  8562. {
  8563. print STDERR "# End of section with change in file(".fileno($FH).") $element->{'file'} -> $new_element->{'file'}\n"
  8564. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  8565. if (!$files{$element->{'file'}}->{'counter'})
  8566. {
  8567. &$Texi2HTML::Config::print_chapter_footer($FH, $element) if (get_conf('SPLIT') eq 'chapter');
  8568. &$Texi2HTML::Config::print_section_footer($FH, $element) if (get_conf('SPLIT') eq 'section');
  8569. print STDERR "# Close file(".fileno($FH).") after $element->{'texi'}\n"
  8570. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  8571. &$Texi2HTML::Config::print_page_foot($FH);
  8572. close_out($FH, "$docu_rdir$element->{'file'}");
  8573. }
  8574. else
  8575. {
  8576. print STDERR "# Counter $files{$element->{'file'}}->{'counter'} ne 0, file(".fileno($FH).") $element->{'file'}\n"
  8577. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  8578. }
  8579. }
  8580. elsif (!defined($new_element))
  8581. {
  8582. print STDERR "# End of last section, file(".fileno($FH).") $element->{'file'}, counter $files{$element->{'file'}}->{'counter'}\n"
  8583. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  8584. if (get_conf('SPLIT'))
  8585. { # end of last splitted section
  8586. &$Texi2HTML::Config::print_chapter_footer($FH, $element) if (get_conf('SPLIT') eq 'chapter');
  8587. &$Texi2HTML::Config::print_section_footer($FH, $element) if (get_conf('SPLIT') eq 'section');
  8588. &$Texi2HTML::Config::print_page_foot($FH);
  8589. close_out($FH, "$docu_rdir$element->{'file'}");
  8590. }
  8591. else
  8592. { # end of last unsplit section
  8593. &$Texi2HTML::Config::end_section($FH, 1, $element);
  8594. }
  8595. }
  8596. elsif ($new_element->{'top'})
  8597. {
  8598. print STDERR "# Section followed by Top, file(".fileno($FH).") counter $files{$element->{'file'}}->{'counter'}\n"
  8599. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  8600. &$Texi2HTML::Config::end_section($FH, 1, $element);
  8601. }
  8602. else
  8603. { # end of section followed by another one
  8604. print STDERR "# Section followed by another one, file(".fileno($FH).") counter $files{$element->{'file'}}->{'counter'}\n"
  8605. if ($T2H_DEBUG & $DEBUG_ELEMENTS);
  8606. &$Texi2HTML::Config::end_section($FH, 0, $element);
  8607. }
  8608. }
  8609. }
  8610. # write to files with name the node name for cross manual references.
  8611. sub do_node_files()
  8612. {
  8613. foreach my $key (sort(keys(%nodes)))
  8614. {
  8615. my $node = $nodes{$key};
  8616. next unless ($node->{'node_file'});
  8617. my $redirection_file = $docu_doc;
  8618. $redirection_file = $node->{'file'} if (get_conf('SPLIT'));
  8619. if (!$redirection_file)
  8620. {
  8621. print STDERR "Bug: file for redirection for `$node->{'texi'}' don't exist\n" unless (Texi2HTML::Config::get_conf('novalidate') or !$node->{'seen'});
  8622. next;
  8623. }
  8624. next if ($redirection_file eq $node->{'node_file'});
  8625. my $file = "${docu_rdir}$node->{'node_file'}";
  8626. $Texi2HTML::NODE{'This'} = $node->{'text'};
  8627. $Texi2HTML::NO_TEXI{'This'} = $node->{'no_texi'};
  8628. $Texi2HTML::SIMPLE_TEXT{'This'} = $node->{'simple_format'};
  8629. $Texi2HTML::NAME{'This'} = $node->{'text'};
  8630. my $href_file = $node->{'file'};
  8631. if (!defined($href_file))
  8632. {
  8633. if (Texi2HTML::Config::get_conf('novalidate'))
  8634. {
  8635. $href_file = '';
  8636. }
  8637. else
  8638. {
  8639. msg_debug ("Undefined file for `$node->{'texi'}' in do_node_files");
  8640. }
  8641. }
  8642. $Texi2HTML::HREF{'This'} = "$href_file#$node->{'id'}";
  8643. my $redirect = &$Texi2HTML::Config::print_redirection_page ();
  8644. if (defined($redirect))
  8645. {
  8646. my $NODEFILE = open_out ($file);
  8647. print $NODEFILE "$redirect";
  8648. close $NODEFILE || document_error ("Can't close $file: $!", 1);
  8649. }
  8650. }
  8651. }
  8652. # do redirection files for renamed nodes
  8653. sub do_renamed_node_files()
  8654. {
  8655. foreach my $old_node_name (sort(keys(%Texi2HTML::Config::renamed_nodes)))
  8656. {
  8657. my $new_node_name = $Texi2HTML::Config::renamed_nodes{$old_node_name};
  8658. $old_node_name = normalise_node($old_node_name);
  8659. $new_node_name = normalise_node($new_node_name);
  8660. my $new_node_equivalent_name = find_equivalent_node($new_node_name);
  8661. my ($node_id, $old_node_file);
  8662. if (get_conf('TRANSLITERATE_FILE_NAMES'))
  8663. {
  8664. ($node_id, $old_node_file) = cross_manual_line($old_node_name,1);
  8665. }
  8666. else
  8667. {
  8668. $old_node_file = cross_manual_line($old_node_name);
  8669. }
  8670. my $file = "${docu_rdir}$old_node_file";
  8671. $file .= '.'.get_conf('NODE_FILE_EXTENSION') if (defined(get_conf('NODE_FILE_EXTENSION')));
  8672. if (!defined($old_node_file) or $old_node_file eq '')
  8673. {
  8674. document_error(sprintf(__("File empty for renamed node `%s'"), $old_node_name));
  8675. }
  8676. elsif (!defined($new_node_equivalent_name))
  8677. {
  8678. document_error(sprintf(__("Node to be renamed as, `%s' not found"), $new_node_name));
  8679. }
  8680. elsif (defined($nodes{$old_node_name}))
  8681. {
  8682. document_error(sprintf(__("Node `%s' that is to be renamed exists "), $old_node_name));
  8683. }
  8684. else
  8685. {
  8686. my $new_node = $nodes{$new_node_equivalent_name};
  8687. $Texi2HTML::NODE{'This'} = $new_node->{'text'};
  8688. $Texi2HTML::NO_TEXI{'This'} = $new_node->{'no_texi'};
  8689. $Texi2HTML::SIMPLE_TEXT{'This'} = $new_node->{'simple_format'};
  8690. $Texi2HTML::NAME{'This'} = $new_node->{'text'};
  8691. my $href_file = $new_node->{'file'};
  8692. if (!defined($href_file))
  8693. {
  8694. if (Texi2HTML::Config::get_conf('novalidate'))
  8695. {
  8696. $href_file = '';
  8697. }
  8698. else
  8699. {
  8700. msg_debug ("Undefined file for `$new_node->{'texi'}' in do_node_files for renamed nodes");
  8701. }
  8702. }
  8703. $Texi2HTML::HREF{'This'} = "$href_file#$new_node->{'id'}";
  8704. my $redirect = &$Texi2HTML::Config::print_redirection_page ();
  8705. if (defined($redirect))
  8706. {
  8707. my $NODEFILE = open_out ($file);
  8708. print $NODEFILE "$redirect";
  8709. close $NODEFILE || document_error ("Can't close $file: $!", 1);
  8710. }
  8711. }
  8712. }
  8713. }
  8714. #+++############################################################################
  8715. # #
  8716. # Low level functions #
  8717. # #
  8718. #---############################################################################
  8719. sub locate_include_file($)
  8720. {
  8721. my $file = shift;
  8722. # APA: Don't implicitely search ., to conform with the docs!
  8723. # if file begins with /, ./ or ../ don't search in -I (Karl)
  8724. if ($file =~ m,^(/|\./|\.\./),)
  8725. {
  8726. return "$file" if (-e "$file" && -r "$file");
  8727. return undef;
  8728. }
  8729. foreach my $dir (@Texi2HTML::Config::INCLUDE_DIRS)
  8730. {
  8731. return "$dir/$file" if (-e "$dir/$file" && -r "$dir/$file");
  8732. }
  8733. return undef;
  8734. }
  8735. sub open_file($$$)
  8736. {
  8737. my $name = shift;
  8738. # my $line_number = shift;
  8739. my $macro = shift;
  8740. my $files_stack = shift;
  8741. my $line_number;
  8742. my $input_spool;
  8743. local *FH;
  8744. if (open(*FH, "<$name"))
  8745. {
  8746. my $in_encoding = get_conf('IN_ENCODING');
  8747. if (defined($in_encoding) and get_conf('USE_UNICODE'))
  8748. {
  8749. binmode(*FH, ":encoding($in_encoding)");
  8750. }
  8751. my $file = { 'fh' => *FH,
  8752. 'input_spool' => { 'spool' => [],
  8753. 'macro' => '' },
  8754. 'name' => $name,
  8755. 'line_nr' => 0 };
  8756. unshift(@$files_stack, $file);
  8757. $input_spool = $file->{'input_spool'};
  8758. $line_number->{'file_name'} = $name;
  8759. $line_number->{'line_nr'} = 1;
  8760. $line_number->{'macro'} = $macro;
  8761. }
  8762. else
  8763. {
  8764. document_error ("Can't read file $name: $!", 1);
  8765. }
  8766. return ($line_number, $input_spool);
  8767. }
  8768. my %filehandles = ();
  8769. sub open_out($;$)
  8770. {
  8771. my $file = shift;
  8772. my $append = shift;
  8773. local *FILE;
  8774. if ($file eq '-')
  8775. {
  8776. binmode(STDOUT, ":encoding(".get_conf('OUT_ENCODING').")") if (get_conf('OUT_ENCODING') and get_conf('USE_UNICODE'));
  8777. return \*STDOUT;
  8778. }
  8779. my $mode = '>';
  8780. $mode = '>>' if ($append);
  8781. unless (open(FILE, $mode, $file))
  8782. {
  8783. document_error ("could not open $file for writing: $!", 1);
  8784. }
  8785. push @opened_files, $file;
  8786. if (defined(get_conf('OUT_ENCODING')) and get_conf('USE_UNICODE'))
  8787. {
  8788. if (get_conf('OUT_ENCODING') eq 'utf8' or get_conf('OUT_ENCODING') eq 'utf-8-strict')
  8789. {
  8790. binmode(FILE, ':utf8');
  8791. }
  8792. else
  8793. {
  8794. binmode(FILE, ':bytes');
  8795. }
  8796. # FIXME is it useful when in utf8?
  8797. binmode(FILE, ":encoding(".get_conf('OUT_ENCODING').")");
  8798. }
  8799. $file =~ s/^(\.[\/]+)*//;
  8800. $filehandles{fileno(*FILE)} = $file;
  8801. return *FILE;
  8802. }
  8803. sub close_out($$)
  8804. {
  8805. my $FH = shift;
  8806. my $file = shift;
  8807. return if (defined($file) and $file eq '-');
  8808. $file =~ s/^(\.[\/]+)*//;
  8809. my $fileno = fileno($FH);
  8810. #print STDERR "close_out $file $fileno\n";
  8811. if (!defined($fileno))
  8812. {
  8813. msg_debug("fileno not defined for $file")
  8814. }
  8815. elsif (defined($filehandles{$fileno}) and $filehandles{$fileno} ne $file)
  8816. {
  8817. #msg_debug("filehandles{$fileno} $filehandles{$fileno} and file $file different")
  8818. }
  8819. close ($FH) || document_error ("Error when closing $file: $!");
  8820. }
  8821. sub next_line($$)
  8822. {
  8823. my $line_number = shift;
  8824. my $files_stack = shift;
  8825. my $input_spool;
  8826. while (@$files_stack)
  8827. {
  8828. my $file = $files_stack->[0];
  8829. $line_number->{'file_name'} = $file->{'name'};
  8830. $input_spool = $file->{'input_spool'};
  8831. if (@{$input_spool->{'spool'}})
  8832. {
  8833. $line_number->{'macro'} = $file->{'input_spool'}->{'macro'};
  8834. $line_number->{'line_nr'} = $file->{'line_nr'};
  8835. my $line = shift(@{$input_spool->{'spool'}});
  8836. print STDERR "# unspooling $line" if ($T2H_DEBUG & $DEBUG_MACROS);
  8837. return($line, $input_spool);
  8838. }
  8839. else
  8840. {
  8841. $file->{'input_spool'}->{'macro'} = '';
  8842. $line_number->{'macro'} = '';
  8843. }
  8844. my $fh = $file->{'fh'};
  8845. no strict "refs";
  8846. my $line = <$fh>;
  8847. use strict "refs";
  8848. my $chomped_line = $line;
  8849. $file->{'line_nr'}++ if (defined($line) and chomp($chomped_line));
  8850. $line_number->{'line_nr'} = $file->{'line_nr'};
  8851. # do that right now, before any other treatement
  8852. $line =~ s/\x{7F}.*\s*// if (defined($line));
  8853. return($line, $input_spool) if (defined($line));
  8854. no strict "refs";
  8855. close($fh);
  8856. use strict "refs";
  8857. shift(@$files_stack);
  8858. }
  8859. return(undef, $input_spool);
  8860. }
  8861. sub check_die(;$)
  8862. {
  8863. my $always_die = shift;
  8864. if (!get_conf('FORCE'))
  8865. {
  8866. if (@opened_files == 1)
  8867. {
  8868. warn sprintf(__("%s: Removing output file `%s' due to errors; use --force to preserve.\n"), $real_command_name, $opened_files[0]);
  8869. }
  8870. elsif (@opened_files > 1)
  8871. {
  8872. warn sprintf(__("%s: Removing output files due to errors; use --force to preserve.\n"), $real_command_name);
  8873. }
  8874. foreach my $file (@opened_files)
  8875. {
  8876. unlink ($file);
  8877. }
  8878. foreach my $dir (@created_directories)
  8879. {
  8880. rmdir ($dir);
  8881. }
  8882. }
  8883. if ($always_die or !get_conf('FORCE'))
  8884. {
  8885. exit (1);
  8886. }
  8887. }
  8888. sub file_line_warn($$;$)
  8889. {
  8890. return if (get_conf('NO_WARN'));
  8891. my $text = shift;
  8892. chomp($text);
  8893. my $file = shift;
  8894. my $line_nr = shift;
  8895. if (!defined($line_nr))
  8896. {
  8897. warn "$file: $text\n";
  8898. }
  8899. else
  8900. {
  8901. warn "$file:$line_nr: $text\n";
  8902. }
  8903. }
  8904. sub document_warn ($)
  8905. {
  8906. return if (get_conf('NO_WARN'));
  8907. my $text = shift;
  8908. chomp ($text);
  8909. warn sprintf(__p("warning: warning_message", "warning: %s\n"), $text);
  8910. }
  8911. my $error_nrs = 0;
  8912. sub check_errors()
  8913. {
  8914. $error_nrs ++;
  8915. die __("Too many errors! Gave up.\n") if ($error_nrs >= get_conf('ERROR_LIMIT'));
  8916. }
  8917. sub msg_debug($;$)
  8918. {
  8919. my $text = shift;
  8920. chomp ($text);
  8921. my $line_number = shift;
  8922. if (defined($line_number))
  8923. {
  8924. warn "!! $text " . format_line_number($line_number) . "\n";
  8925. }
  8926. else
  8927. {
  8928. warn "!! $text\n";
  8929. }
  8930. }
  8931. sub cmdline_warn ($)
  8932. {
  8933. my $text = shift;
  8934. chomp ($text);
  8935. warn sprintf(__p("command_name: warning_message", "%s: %s\n"), $real_command_name, $text);
  8936. }
  8937. # seems not to be used
  8938. sub cmdline_error ($)
  8939. {
  8940. my $text = shift;
  8941. #chomp ($text);
  8942. warn sprintf(__p("command_name: error_message", "%s: %s"), $real_command_name, $text);
  8943. }
  8944. sub document_error($;$)
  8945. {
  8946. my $text = shift;
  8947. chomp ($text);
  8948. my $die = shift;
  8949. warn ("$text\n");
  8950. check_die ($die);
  8951. check_errors();
  8952. }
  8953. # echo an error
  8954. sub msg_error($;$)
  8955. {
  8956. my $text = shift;
  8957. my $line_number = shift;
  8958. if (defined($line_number))
  8959. {
  8960. line_error ($text, $line_number);
  8961. }
  8962. else
  8963. {
  8964. document_error ($text);
  8965. }
  8966. }
  8967. # echo a warning
  8968. sub msg_warn($;$$)
  8969. {
  8970. my $text = shift;
  8971. my $line_number = shift;
  8972. my $context_string = shift;
  8973. if (defined($line_number))
  8974. {
  8975. line_warn ($text, $line_number);
  8976. }
  8977. elsif (defined($context_string))
  8978. {
  8979. document_warn ("$text (in $context_string)");
  8980. }
  8981. else
  8982. {
  8983. document_warn ($text);
  8984. }
  8985. }
  8986. # echo a warning associated with a line in the document
  8987. sub line_warn($$)
  8988. {
  8989. return if (get_conf('NO_WARN'));
  8990. my $text = shift;
  8991. chomp ($text);
  8992. my $line_number = shift;
  8993. return if (!defined($line_number));
  8994. my $file = $line_number->{'file_name'};
  8995. # otherwise out of source build fail since the file names are different
  8996. $file =~ s/^.*\/// if (get_conf('TEST'));
  8997. if ($line_number->{'macro'} ne '')
  8998. {
  8999. warn sprintf(__("%s:%d: warning: %s (possibly involving \@%s)\n"), $file, $line_number->{'line_nr'}, $text, $line_number->{'macro'});
  9000. }
  9001. else
  9002. {
  9003. warn sprintf(__("%s:%d: warning: %s\n"), $file, $line_number->{'line_nr'}, $text);
  9004. }
  9005. }
  9006. sub line_error($$)
  9007. {
  9008. my $text = shift;
  9009. chomp ($text);
  9010. my $line_number = shift;
  9011. if (defined($line_number))
  9012. {
  9013. my $file = $line_number->{'file_name'};
  9014. $file =~ s/^.*\/// if (get_conf('TEST'));
  9015. my $macro_text = '';
  9016. $macro_text = " (possibly involving \@$line_number->{'macro'})" if ($line_number->{'macro'} ne '');
  9017. warn "$file:$line_number->{'line_nr'}: $text$macro_text\n";
  9018. check_die();
  9019. }
  9020. check_errors();
  9021. }
  9022. sub format_line_number(;$)
  9023. {
  9024. my $line_number = shift;
  9025. $line_number = $Texi2HTML::THISDOC{'line_nr'} if (!defined($line_number));
  9026. my $macro_text = '';
  9027. #$line_number = undef;
  9028. return '' unless (defined($line_number));
  9029. my $print_filename = ($line_number->{'file_name'} ne $Texi2HTML::THISDOC{'input_file_name'});
  9030. if ($line_number->{'macro'} ne '')
  9031. {
  9032. if ($print_filename)
  9033. {
  9034. return sprintf(__("(in %s l. %d possibly involving \@%s)"), $line_number->{'file_name'}, $line_number->{'line_nr'}, $line_number->{'macro'});
  9035. }
  9036. else
  9037. {
  9038. return sprintf(__("(l. %d possibly involving \@%s)"), $line_number->{'line_nr'}, $line_number->{'macro'});
  9039. }
  9040. }
  9041. elsif ($print_filename)
  9042. {
  9043. return sprintf(__("(in %s l. %d)"), $line_number->{'file_name'}, $line_number->{'line_nr'});
  9044. }
  9045. else
  9046. {
  9047. return sprintf(__("(l. %d)"), $line_number->{'line_nr'});
  9048. }
  9049. }
  9050. # to debug, dump the result of pass_texi and pass_structure in a file
  9051. sub dump_texi($$;$$)
  9052. {
  9053. my $lines = shift;
  9054. my $pass = shift;
  9055. my $numbers = shift;
  9056. my $file = shift;
  9057. $file = "$docu_rdir$docu_name" . ".pass$pass" if (!defined($file));
  9058. my $FH = open_out($file);
  9059. print STDERR "# Dump texi\n" if ($T2H_VERBOSE);
  9060. my $index = 0;
  9061. foreach my $line (@$lines)
  9062. {
  9063. my $number_information = '';
  9064. my $chomped_line = $line;
  9065. # if defined, it means that an output of the file is asked for
  9066. if (defined($numbers))
  9067. {
  9068. my $basefile = $numbers->[$index]->{'file_name'};
  9069. $basefile = 'no file' if (!defined($basefile));
  9070. $basefile =~ s|.*/||;
  9071. my $macro_name = $numbers->[$index]->{'macro'};
  9072. $macro_name = '' if (!defined($macro_name));
  9073. my $line_number = $numbers->[$index]->{'line_nr'};
  9074. $line_number = '' if (!defined($line_number));
  9075. $number_information = "${basefile}($macro_name,$line_number) ";
  9076. }
  9077. print $FH "${number_information}$line";
  9078. $index++ if (chomp($chomped_line));
  9079. }
  9080. close_out ($FH, $file);
  9081. }
  9082. # return next tag on the line
  9083. sub next_tag($)
  9084. {
  9085. my $line = shift;
  9086. # macro_regexp
  9087. if ($line =~ /^\s*\@(["'~\@\}\{,\.!\?\s\*\-\^`=:\|\/\\])/o or $line =~ /^\s*\@([a-zA-Z][\w-]*)/)
  9088. {
  9089. return ($1);
  9090. }
  9091. return '';
  9092. }
  9093. sub next_end_tag($)
  9094. {
  9095. my $line = shift;
  9096. if ($line =~ /^\s*\@end\s+([a-zA-Z][\w-]*)/)
  9097. {
  9098. return $1;
  9099. }
  9100. return '';
  9101. }
  9102. sub next_tag_or_end_tag($)
  9103. {
  9104. my $line = shift;
  9105. my $next_tag = next_tag($line);
  9106. return $next_tag if (defined($next_tag) and $next_tag ne '');
  9107. return next_end_tag($line);
  9108. }
  9109. sub top_stack($;$)
  9110. {
  9111. my $stack = shift;
  9112. my $ignore_para = shift;
  9113. my $index = scalar (@$stack);
  9114. return undef unless ($index);
  9115. return $stack->[-1] unless ($ignore_para);
  9116. if ($ignore_para == 1)
  9117. {
  9118. if (exists($stack->[-1]->{'format'}) and ($stack->[-1]->{'format'} eq 'paragraph' or $stack->[-1]->{'format'} eq 'preformatted'))
  9119. {
  9120. if (exists($stack->[-2]))
  9121. {
  9122. return $stack->[-2];
  9123. }
  9124. else
  9125. {
  9126. return undef;
  9127. }
  9128. }
  9129. else
  9130. {
  9131. return $stack->[-1];
  9132. }
  9133. }
  9134. else
  9135. {
  9136. while ($index and
  9137. (
  9138. (exists($stack->[$index-1]->{'format'})
  9139. and ($stack->[$index-1]->{'format'} eq 'paragraph' or $stack->[$index-1]->{'format'} eq 'preformatted'))
  9140. or (exists($stack->[$index-1]->{'style'}))
  9141. ))
  9142. {
  9143. $index--;
  9144. }
  9145. }
  9146. return undef unless ($index);
  9147. return $stack->[$index-1];
  9148. }
  9149. # return the next element with balanced {}
  9150. sub next_bracketed($$$;$)
  9151. {
  9152. my $line = shift;
  9153. my $command = shift;
  9154. my $line_nr = shift;
  9155. my $report = shift;
  9156. my $opened_braces = 0;
  9157. my $result = '';
  9158. my $spaces;
  9159. #print STDERR "next_bracketed $line";
  9160. if ($line =~ /^(\s*)$/)
  9161. {
  9162. return ('','',$1);
  9163. }
  9164. while ($line !~ /^\s*$/)
  9165. {
  9166. #print STDERR "next_bracketed($opened_braces): $result !!! $line";
  9167. if (!$opened_braces)
  9168. { # beginning of item
  9169. $line =~ s/^(\s*)//;
  9170. $spaces = $1;
  9171. #if ($line =~ s/^([^\{\}\s]+)//)
  9172. if ($line =~ s/^([^\{\}]+?)(\s+)/$2/ or $line =~ s/^([^\{\}]+?)$//)
  9173. {
  9174. $result = $1;
  9175. $result = trim_around_spaces($result);
  9176. return ($result, $line, $spaces);
  9177. }
  9178. elsif ($line =~ s/^([^\{\}]+?)([\{\}])/$2/)
  9179. {
  9180. $result = $1;
  9181. }
  9182. }
  9183. elsif($line =~ s/^([^\{\}]+)//)
  9184. {
  9185. $result .= $1;
  9186. }
  9187. if ($line =~ s/^([\{\}])//)
  9188. {
  9189. my $brace = $1;
  9190. $opened_braces++ if ($brace eq '{');
  9191. $opened_braces-- if ($brace eq '}');
  9192. if ($opened_braces < 0)
  9193. {
  9194. line_error(sprintf(__("Too much '}' in \@%s"), $command), $line_nr) if ($report);
  9195. $opened_braces = 0;
  9196. #next;
  9197. }
  9198. $result .= $brace;
  9199. return ($result, $line, $spaces) if ($opened_braces == 0);
  9200. }
  9201. }
  9202. if ($opened_braces)
  9203. {
  9204. line_error(sprintf(__("Missing `}' on \@%s line"), $command), $line_nr) if ($report);
  9205. return ($result, '', $spaces);
  9206. #return ($result . ( '}' x $opened_braces), '', $spaces);
  9207. }
  9208. msg_debug ("BUG: at the end of next_bracketed", $line_nr);
  9209. return undef;
  9210. }
  9211. # def prams are also split at @-commands if not in brackets
  9212. sub next_def_param($$$;$)
  9213. {
  9214. my $line = shift;
  9215. my $command = shift;
  9216. my $line_nr = shift;
  9217. my $report = shift;
  9218. my ($item, $spaces);
  9219. ($item, $line, $spaces) = next_bracketed($line, $command, $line_nr, $report);
  9220. return ($item, $line, $spaces) if (!defined($item));
  9221. if ($item =~ /^\{/)
  9222. {
  9223. $item =~ s/^\{(.*)\}$/$1/;
  9224. }
  9225. else
  9226. {
  9227. my $delimeter_quoted = quotemeta($Texi2HTML::Config::def_argument_separator_delimiters);
  9228. if ($item =~ s/^([^\@$delimeter_quoted]+)//)
  9229. {
  9230. $line = $item . $line;
  9231. $item = $1;
  9232. }
  9233. elsif ($item =~ s/^([$delimeter_quoted])//)
  9234. {
  9235. $line = $item . $line;
  9236. $item = $1;
  9237. }
  9238. elsif ($item =~ s/^(\@[^\@\{]+)(\@)/$2/)
  9239. {
  9240. $line = $item . $line;
  9241. $item = $1;
  9242. }
  9243. }
  9244. return ($item, $line, $spaces);
  9245. }
  9246. # do a href using file and id and taking care of ommitting file if it is
  9247. # the same
  9248. # element: structuring element to point to
  9249. # file: current file
  9250. sub href($$;$)
  9251. {
  9252. my $element = shift;
  9253. my $file = shift;
  9254. my $line_nr = shift;
  9255. return '' unless defined($element);
  9256. my $href = '';
  9257. msg_debug("Bug: $element->{'texi'}, target undef", $line_nr) if (!defined($element->{'target'}));
  9258. msg_debug("Bug: $element->{'texi'}, file undef", $line_nr) if (!defined($element->{'file'}));
  9259. msg_debug("Bug: file undef in href", $line_nr) if (!defined($file));
  9260. $href .= $element->{'file'} if (defined($element->{'file'}) and $file ne $element->{'file'});
  9261. $href .= "#$element->{'target'}" if (defined($element->{'target'}));
  9262. return $href;
  9263. }
  9264. sub file_target_href($$$)
  9265. {
  9266. my $dest_file = shift;
  9267. my $orig_file = shift;
  9268. my $target = shift;
  9269. my $href = '';
  9270. $href .= $dest_file if (defined($dest_file) and ($dest_file ne $orig_file));
  9271. $href .= "#$target" if (defined($target));
  9272. return $href;
  9273. }
  9274. sub trim_around_spaces($)
  9275. {
  9276. my $text = shift;
  9277. $text =~ s/^\s*//;
  9278. $text =~ s/(\s)\s*$/$1/;
  9279. if ($text =~ /(\@+)\s$/)
  9280. {
  9281. my $arobases = $1;
  9282. if ((length($arobases) % 2) == 0)
  9283. {
  9284. $text =~ s/\s$//;
  9285. }
  9286. }
  9287. else
  9288. {
  9289. $text =~ s/\s$//;
  9290. }
  9291. return $text;
  9292. }
  9293. sub normalise_space($)
  9294. {
  9295. return undef unless (defined ($_[0]));
  9296. my $text = shift;
  9297. $text =~ s/\s+/ /go;
  9298. $text =~ s/ $//;
  9299. $text =~ s/^ //;
  9300. return $text;
  9301. }
  9302. sub normalise_texi_space($)
  9303. {
  9304. return undef unless (defined ($_[0]));
  9305. my $text = shift;
  9306. $text = trim_around_spaces($text);
  9307. $text =~ s/\s+/ /go;
  9308. return $text;
  9309. }
  9310. sub normalise_node($)
  9311. {
  9312. return undef unless (defined ($_[0]));
  9313. my $text = shift;
  9314. $text = normalise_texi_space($text);
  9315. $text =~ s/^top$/Top/i;
  9316. return $text;
  9317. }
  9318. sub normalise_node_array($)
  9319. {
  9320. my $array = shift;
  9321. my @result;
  9322. foreach my $node (@$array)
  9323. {
  9324. push @result, normalise_node($node);
  9325. }
  9326. return @result;
  9327. }
  9328. sub do_anchor_label($$$$)
  9329. {
  9330. my $command = shift;
  9331. #my $anchor = shift;
  9332. my $args = shift;
  9333. my $anchor = $args->[0];
  9334. my $style_stack = shift;
  9335. my $state = shift;
  9336. my $line_nr = shift;
  9337. #msg_debug("do_anchor_label $state->{'region'} m_p $state->{'multiple_pass'} remove $state->{'remove_texi'} `$anchor'", $line_nr);
  9338. $anchor = normalise_node($anchor);
  9339. if ((defined($state->{'multiple_pass'}) and $state->{'multiple_pass'} > 0) or $state->{'outside_document'})
  9340. {
  9341. # no warning when outside of document.
  9342. line_warn(sprintf(__("Anchor `%s' ignored in %s expanded more than once"),$anchor, $state->{'region'}), $line_nr) unless ($state->{'outside_document'} or defined($state->{'expansion'}));
  9343. return '';
  9344. }
  9345. if (!exists($nodes{$anchor}) or !defined($nodes{$anchor}->{'id'}))
  9346. {
  9347. msg_debug("Unknown anchor `$anchor'", $line_nr);
  9348. }
  9349. return &$Texi2HTML::Config::anchor_label($nodes{$anchor}->{'id'}, $anchor, $nodes{$anchor}, $state->{'expansion'});
  9350. }
  9351. sub get_format_command($)
  9352. {
  9353. my $format = shift;
  9354. my $command = '';
  9355. my $format_name = '';
  9356. my $term = 0;
  9357. my $item_nr;
  9358. my $paragraph_number;
  9359. my $enumerate_type;
  9360. my $number;
  9361. $command = $format->{'command'} if (defined($format->{'command'}));
  9362. $format_name = $format->{'format'} if (defined($format->{'format'}));
  9363. return ($format_name,$command,\$format->{'paragraph_number'},$term,
  9364. $format->{'item_nr'}, $format->{'spec'}, $format->{'number'},
  9365. $format->{'stack_at_beginning'});
  9366. }
  9367. sub do_paragraph($$;$)
  9368. {
  9369. my $text = shift;
  9370. my $state = shift;
  9371. my $stack = shift;
  9372. if (!defined ($state->{'paragraph_context'}))
  9373. {
  9374. msg_debug ("paragraph_context undef", $Texi2HTML::THISDOC{'line_nr'});
  9375. dump_stack (undef, $stack, $state);
  9376. }
  9377. my ($format, $paragraph_command, $paragraph_number, $term, $item_nr,
  9378. $enumerate_type, $number, $stack_at_beginning)
  9379. = get_format_command ($state->{'paragraph_context'});
  9380. delete $state->{'paragraph_context'};
  9381. my $indent_style = '';
  9382. if (exists($state->{'paragraph_indent'}))
  9383. {
  9384. $indent_style = $state->{'paragraph_indent'};
  9385. $state->{'paragraph_indent'} = undef;
  9386. delete $state->{'paragraph_indent'};
  9387. }
  9388. my $paragraph_command_formatted;
  9389. $state->{'paragraph_nr'}--;
  9390. (print STDERR "Bug text undef in do_paragraph", return '') unless defined($text);
  9391. my $align = '';
  9392. $align = $state->{'paragraph_style'}->[-1] if ($state->{'paragraph_style'}->[-1]);
  9393. if ($paragraph_command and !exists($Texi2HTML::Config::special_list_commands{$format}->{$paragraph_command}))
  9394. {
  9395. $paragraph_command_formatted = substitute_line("\@$paragraph_command\{\}", "paragraph \@$format \@$paragraph_command", duplicate_formatting_state($state));
  9396. }
  9397. return &$Texi2HTML::Config::paragraph($text, $align, $indent_style, $paragraph_command, $paragraph_command_formatted, $paragraph_number, $format, $item_nr, $enumerate_type, $number,$state->{'command_stack'},$stack_at_beginning);
  9398. }
  9399. sub do_preformatted($$;$)
  9400. {
  9401. my $text = shift;
  9402. my $state = shift;
  9403. my $stack = shift;
  9404. if (!defined ($state->{'preformatted_context'}))
  9405. {
  9406. msg_debug ("preformatted_context undef", $Texi2HTML::THISDOC{'line_nr'});
  9407. dump_stack (undef, $stack, $state);
  9408. }
  9409. my ($format, $leading_command, $preformatted_number, $term, $item_nr,
  9410. $enumerate_type, $number,$stack_at_beginning)
  9411. = get_format_command($state->{'preformatted_context'});
  9412. delete ($state->{'preformatted_context'});
  9413. my $leading_command_formatted;
  9414. my $pre_style = '';
  9415. my $class = '';
  9416. $pre_style = $state->{'preformatted_stack'}->[-1]->{'pre_style'} if ($state->{'preformatted_stack'}->[-1]->{'pre_style'});
  9417. $class = $state->{'preformatted_stack'}->[-1]->{'class'};
  9418. print STDERR "BUG: !state->{'preformatted_stack'}->[-1]->{'class'}\n" unless ($class);
  9419. if (defined($leading_command) and $leading_command ne '' and !exists($Texi2HTML::Config::special_list_commands{$format}->{$leading_command}))
  9420. {
  9421. $leading_command_formatted = substitute_line("\@$leading_command\{\}", "preformatted \@$format \@$leading_command", duplicate_formatting_state($state));
  9422. }
  9423. return &$Texi2HTML::Config::preformatted($text, $pre_style, $class, $leading_command, $leading_command_formatted, $preformatted_number, $format, $item_nr, $enumerate_type, $number,$state->{'command_stack'},$stack_at_beginning);
  9424. }
  9425. sub do_external_href($)
  9426. {
  9427. # node_id is a unique node identifier with only letters, digits, - and _
  9428. # node_xhtml_id is almost the same, but xhtml id can only begin with
  9429. # letters, so a prefix has to be appended
  9430. my $texi_node = shift;
  9431. my $file = '';
  9432. my $node_file = '';
  9433. my $node_id = '';
  9434. my $node_xhtml_id = '';
  9435. #print STDERR "do_external_href $texi_node\n";
  9436. if ($texi_node =~ s/^\((.+?)\)//)
  9437. {
  9438. $file = $1;
  9439. }
  9440. $texi_node = normalise_node($texi_node);
  9441. if ($texi_node ne '')
  9442. {
  9443. if (exists($nodes{$texi_node}) and ($nodes{$texi_node}->{'cross_manual_target'}))
  9444. {
  9445. $node_id = $nodes{$texi_node}->{'cross_manual_target'};
  9446. if (get_conf('TRANSLITERATE_FILE_NAMES'))
  9447. {
  9448. $node_file = $nodes{$texi_node}->{'cross_manual_file'};
  9449. }
  9450. }
  9451. else
  9452. {
  9453. if (get_conf('TRANSLITERATE_FILE_NAMES'))
  9454. {
  9455. ($node_id, $node_file) = cross_manual_line($texi_node,1);
  9456. }
  9457. else
  9458. {
  9459. $node_id = cross_manual_line($texi_node);
  9460. }
  9461. }
  9462. $node_xhtml_id = node_to_id($node_id);
  9463. $node_file = $node_id unless (get_conf('TRANSLITERATE_FILE_NAMES'));
  9464. }
  9465. return &$Texi2HTML::Config::external_href($texi_node, $node_file,
  9466. $node_xhtml_id, $file);
  9467. }
  9468. # transform node for cross ref name to id suitable for xhtml: an xhtml id
  9469. # must begin with a letter.
  9470. sub node_to_id($)
  9471. {
  9472. my $cross_ref_node_name = shift;
  9473. $cross_ref_node_name =~ s/^([0-9_])/g_t$1/;
  9474. return $cross_ref_node_name;
  9475. }
  9476. # return an empty string if the command is not a index command, the prefix
  9477. # if it is one
  9478. sub index_command_prefix($)
  9479. {
  9480. my $command = shift;
  9481. return $1 if ($command =~ /^(\w+?)index/ and ($1 ne 'print') and ($1 ne 'syncode') and ($1 ne 'syn') and ($1 ne 'def') and ($1 ne 'defcode'));
  9482. return '';
  9483. }
  9484. # return 1 if the following tag shouldn't begin a line
  9485. sub no_line($)
  9486. {
  9487. my $line = shift;
  9488. my $next_tag = next_tag($line);
  9489. return 1 if (($line =~ /^\s*$/) or $Texi2HTML::Config::no_paragraph_commands{$next_tag} or
  9490. ($Texi2HTML::Config::no_paragraph_commands{'cindex'} and (index_command_prefix($next_tag) ne '')) or
  9491. (($line =~ /^\@end\s+(\w+)/) and $Texi2HTML::Config::no_paragraph_commands{"end $1"}) or
  9492. ($next_tag =~ /^special_(\w+)_(\d+)$/ and $Texi2HTML::Config::no_paragraph_commands{$1})
  9493. );
  9494. return 0;
  9495. }
  9496. sub no_paragraph($$)
  9497. {
  9498. my $state = shift;
  9499. my $line = shift;
  9500. return ($state->{'paragraph_context'} or $state->{'preformatted'} or $state->{'remove_texi'} or no_line($line) or $state->{'no_paragraph'});
  9501. }
  9502. # We restart the preformatted format which was stopped
  9503. # by the format if in preformatted, and start a paragraph
  9504. # for the text following the end of the format, if needed
  9505. sub begin_paragraph_after_command($$$$)
  9506. {
  9507. my $state = shift;
  9508. my $stack = shift;
  9509. my $command = shift;
  9510. my $text_following = shift;
  9511. #if (($state->{'preformatted'}
  9512. # and !$Texi2HTML::Config::format_in_paragraph{$command})
  9513. if ($state->{'preformatted'}
  9514. or (!no_paragraph($state,$text_following)))
  9515. {
  9516. begin_paragraph($stack, $state);
  9517. }
  9518. }
  9519. # handle raw formatting, ignored regions...
  9520. # called from scan_texi, so only in first pass.
  9521. sub do_text_macro($$$$$)
  9522. {
  9523. my $type = shift;
  9524. my $line = shift;
  9525. my $state = shift;
  9526. my $stack = shift;
  9527. my $line_nr = shift;
  9528. my $value;
  9529. #print STDERR "do_text_macro $type\n";
  9530. if ($Texi2HTML::Config::texi_formats_map{$type} eq 'raw')
  9531. {
  9532. $state->{'raw'} = $type;
  9533. #print STDERR "RAW\n";
  9534. if ($state->{'raw'})
  9535. {
  9536. push @$stack, { 'style' => $type, 'text' => '' };
  9537. }
  9538. }
  9539. elsif ($Texi2HTML::Config::texi_formats_map{$type} eq 'value')
  9540. {
  9541. if (($line =~ s/(\s+)($VARRE)$//) or ($line =~ s/(\s+)($VARRE)(\s)//))
  9542. {
  9543. $value = $1 . $2;
  9544. $value .= $3 if defined($3);
  9545. if ($state->{'ignored'})
  9546. {
  9547. if ($type eq $state->{'ignored'})
  9548. {
  9549. $state->{'ifvalue_inside'}++;
  9550. }
  9551. # if 'ignored' we don't care about the command as long as
  9552. # the nesting is correct
  9553. return ($line,'');
  9554. }
  9555. my $open_ignored_ifvalue = 0;
  9556. if ($type eq 'ifclear')
  9557. {
  9558. if (defined($value{$2}))
  9559. {
  9560. $open_ignored_ifvalue = 1;
  9561. }
  9562. else
  9563. {
  9564. push @{$state->{'text_macro_stack'}}, $type;
  9565. }
  9566. }
  9567. elsif ($type eq 'ifset')
  9568. {
  9569. unless (defined($value{$2}))
  9570. {
  9571. $open_ignored_ifvalue = 1;
  9572. }
  9573. else
  9574. {
  9575. push @{$state->{'text_macro_stack'}}, $type;
  9576. }
  9577. }
  9578. if ($open_ignored_ifvalue)
  9579. {
  9580. $state->{'ignored'} = $type;
  9581. $state->{'ifvalue'} = $type;
  9582. $state->{'ifvalue_inside'} = 1;
  9583. # We add at the top of the stack to be able to close all
  9584. # opened comands when closing the ifset/ifclear (and ignore
  9585. # everything that is in those commands)
  9586. push @$stack, { 'style' => 'ifvalue', 'text' => '' };
  9587. }
  9588. }
  9589. else
  9590. { # we accept a lone @ifset or @ifclear if it is nested in an @if*
  9591. if ($state->{'ifvalue'} and $type eq $state->{'ifvalue'})
  9592. {
  9593. $state->{'ifvalue_inside'}++;
  9594. return ($line,'');
  9595. }
  9596. line_error (sprintf(__("%c%s requires a name"), ord('@'), $type), $line_nr) unless ($state->{'ignored'});
  9597. }
  9598. }
  9599. elsif (not $Texi2HTML::Config::texi_formats_map{$type})
  9600. { # ignored text
  9601. $state->{'ignored'} = $type;
  9602. #print STDERR "IGNORED\n";
  9603. }
  9604. else
  9605. {
  9606. push @{$state->{'text_macro_stack'}}, $type unless($state->{'ignored'}) ;
  9607. }
  9608. my $text = "\@$type";
  9609. $text .= $value if defined($value);
  9610. return ($line, $text);
  9611. }
  9612. # do regions handled specially, for example tex or math going through latex2html
  9613. sub init_special($$)
  9614. {
  9615. my $style = shift;
  9616. my $text = shift;
  9617. if (defined($Texi2HTML::Config::command_handler{$style}) and
  9618. defined($Texi2HTML::Config::command_handler{$style}->{'init'}))
  9619. {
  9620. $special_commands{$style}->{'count'} = 0 if (!defined($special_commands{$style}));
  9621. if ($Texi2HTML::Config::command_handler{$style}->{'init'}($style,$text,
  9622. $special_commands{$style}->{'count'} +1))
  9623. {
  9624. $special_commands{$style}->{'count'}++;
  9625. return "\@special_${style}_".$special_commands{$style}->{'count'}."{}";
  9626. }
  9627. return '';
  9628. }
  9629. }
  9630. sub reset_index_entries($)
  9631. {
  9632. my $region = shift;
  9633. if (defined($Texi2HTML::THISDOC{'index_entries'}->{$region}))
  9634. {
  9635. foreach my $entry (values(%{$Texi2HTML::THISDOC{'index_entries'}->{$region}}))
  9636. {
  9637. if (scalar(@{$entry->{'entries'}}) > 1)
  9638. {
  9639. $entry->{'index'} = 0;
  9640. }
  9641. }
  9642. }
  9643. if (defined($Texi2HTML::THISDOC{'indices_numbers'}->{$region}))
  9644. {
  9645. foreach my $index_name (keys(%{$Texi2HTML::THISDOC{'indices_numbers'}->{$region}}))
  9646. {
  9647. $Texi2HTML::THISDOC{'indices_numbers'}->{$region}->{$index_name} = undef;
  9648. }
  9649. }
  9650. }
  9651. # FIXME we cannot go through the commands too 'often'. The error messages
  9652. # are duplicated and global stuff is changed.
  9653. # -> identify what is global
  9654. # -> use local state
  9655. sub do_special_region_lines($;$$)
  9656. {
  9657. my $region = shift;
  9658. my $state = shift;
  9659. my $line_nr = shift;
  9660. # this case covers something like
  9661. # @copying
  9662. # @insertcopying
  9663. # @end copying
  9664. if (defined($state) and exists($state->{'region'}) and ($region eq $state->{'region'}))
  9665. {
  9666. line_error(sprintf(__("Region %s inside region %s is not allowed"), $region, $state->{'region'}), $line_nr);
  9667. return ('','', '');
  9668. }
  9669. print STDERR "# do_special_region_lines for region $region ['multiple_pass','region_pass']: ($region_initial_state{$region}->{'multiple_pass'}, $region_initial_state{$region}->{'region_pass'})" if ($T2H_DEBUG);
  9670. if (!defined($state))
  9671. {
  9672. $state = {};
  9673. fill_state($state);
  9674. $state->{'outside_document'} = 1;
  9675. print STDERR " outside document\n" if ($T2H_DEBUG);
  9676. }
  9677. elsif (!$state->{'outside_document'})
  9678. {
  9679. $region_initial_state{$region}->{'multiple_pass'}++;
  9680. print STDERR " multiple pass $region_initial_state{$region}->{'multiple_pass'}\n" if ($T2H_DEBUG);
  9681. }
  9682. else
  9683. {
  9684. print STDERR " in $state->{'region'}, outside document\n" if ($T2H_DEBUG);
  9685. }
  9686. return ('','','') unless @{$region_lines{$region}};
  9687. my @result;
  9688. foreach my $context ('normal', 'remove_texi', 'simple_format')
  9689. {
  9690. print STDERR "# $context\n" if ($T2H_DEBUG);
  9691. my $new_state = duplicate_formatting_state($state);
  9692. reset_index_entries($region);
  9693. foreach my $key (keys(%{$region_initial_state{$region}}))
  9694. {
  9695. $new_state->{$key} = $region_initial_state{$region}->{$key};
  9696. }
  9697. $new_state->{'remove_texi'} = 1 if ($context eq 'remove_texi');
  9698. &$Texi2HTML::Config::begin_special_region($region,$new_state,$region_lines{$region})
  9699. if (defined($Texi2HTML::Config::begin_special_region));
  9700. my $line_numbers;
  9701. my $context_string = "$region ($region_initial_state{$region}->{'multiple_pass'}, $region_initial_state{$region}->{'region_pass'})";
  9702. if ($context eq 'normal')
  9703. { # the line numbers are given only for the normal context, therefore
  9704. # there will be error messages only in that case
  9705. $line_numbers = [ @{$region_line_nrs{$region}} ];
  9706. }
  9707. else
  9708. {
  9709. $context_string = "$context $context_string";
  9710. }
  9711. my $result;
  9712. if ($context ne 'simple_format')
  9713. {
  9714. $result = substitute_text($new_state, $line_numbers,
  9715. $context_string, @{$region_lines{$region}});
  9716. }
  9717. else
  9718. {
  9719. $result = simple_format($new_state, $line_numbers,
  9720. $context_string, @{$region_lines{$region}});
  9721. }
  9722. $result = &$Texi2HTML::Config::end_special_region($region,$new_state,$result)
  9723. if (defined($Texi2HTML::Config::end_special_region));
  9724. push @result, $result;
  9725. $region_initial_state{$region}->{'region_pass'}++;
  9726. }
  9727. return @result;
  9728. }
  9729. sub do_insertcopying($$)
  9730. {
  9731. my $state = shift;
  9732. my $line_nr = shift;
  9733. my ($text, $comment, $simple_formatted) = do_special_region_lines('copying', $state, $line_nr);
  9734. return &$Texi2HTML::Config::insertcopying($text, $comment, $simple_formatted);
  9735. }
  9736. sub get_deff_index($$$$)
  9737. {
  9738. my $tag = shift;
  9739. my $line = shift;
  9740. my $line_nr = shift;
  9741. my $warn = shift;
  9742. $tag =~ s/x$//;
  9743. my ($command, $style, $category, $name, $type, $class, $arguments, $args_array, $args_type_array);
  9744. ($command, $style, $category, $name, $type, $class, $arguments, $args_array, $args_type_array) = parse_def($tag, $line, $line_nr, $warn);
  9745. $name = &$Texi2HTML::Config::definition_index_entry($name, $class, $style, $command);
  9746. return ($style, '') if (!defined($name) or ($name =~ /^\s*$/));
  9747. return ($style, $name, $arguments);
  9748. }
  9749. sub parse_def($$$;$)
  9750. {
  9751. my $command = shift;
  9752. my $line = shift;
  9753. my $line_nr = shift;
  9754. my $report = shift;
  9755. my $format = $command;
  9756. if (!ref ($Texi2HTML::Config::def_map{$command}))
  9757. {
  9758. # substitute shortcuts for definition commands
  9759. my $substituted = $Texi2HTML::Config::def_map{$command};
  9760. $substituted =~ s/(\w+)//;
  9761. $format = $1;
  9762. $line = $substituted . $line;
  9763. }
  9764. #print STDERR "PARSE_DEF($command,$format) $line";
  9765. my ($category, $name, $type, $class, $arguments);
  9766. my @arguments = ();
  9767. my @args = @{$Texi2HTML::Config::def_map{$format}};
  9768. my $style = shift @args;
  9769. my @arg_types = ();
  9770. while (@args and $args[0] ne 'arg' and $args[0] ne 'argtype')
  9771. {
  9772. my $arg = shift @args;
  9773. # backward compatibility, it was possible to have a { in front.
  9774. $arg =~ s/^\{//;
  9775. my ($item, $spaces);
  9776. ($item, $line, $spaces) = next_def_param($line, $command, $line_nr, $report);
  9777. last if (!defined($item));
  9778. if ($arg eq 'category')
  9779. {
  9780. $category = $item;
  9781. }
  9782. elsif ($arg eq 'name')
  9783. {
  9784. $name = $item;
  9785. }
  9786. elsif ($arg eq 'type')
  9787. {
  9788. $type = $item;
  9789. }
  9790. elsif ($arg eq 'class')
  9791. {
  9792. $class = $item;
  9793. }
  9794. push @arg_types, $arg;
  9795. push @arguments, $item;
  9796. }
  9797. my $line_remaining = $line;
  9798. $line = '';
  9799. my $arg_and_type = 1;
  9800. foreach my $arg (@args)
  9801. {
  9802. if ($arg eq 'arg')
  9803. {
  9804. $arg_and_type = 0;
  9805. last;
  9806. }
  9807. elsif ($arg eq 'argtype')
  9808. {
  9809. last;
  9810. }
  9811. }
  9812. my $always_delimiter_quoted = quotemeta($Texi2HTML::Config::def_always_delimiters);
  9813. my $in_type_delimiter_quoted = quotemeta($Texi2HTML::Config::def_in_type_delimiters);
  9814. my $after_type = 0;
  9815. while ($line_remaining !~ /^\s*$/)
  9816. {
  9817. my ($item, $spaces);
  9818. ($item, $line_remaining,$spaces) = next_def_param($line_remaining, $command, $line_nr);
  9819. if ($item =~ /^([$always_delimiter_quoted])/ or (!$arg_and_type and $item =~ /^([$in_type_delimiter_quoted].*)/))
  9820. {
  9821. $item = $1;
  9822. push @arg_types, 'delimiter';
  9823. $after_type = 0;
  9824. }
  9825. elsif (!$arg_and_type or $item =~ /^\@/ or $after_type)
  9826. {
  9827. push @arg_types, 'param';
  9828. $after_type = 0;
  9829. }
  9830. elsif ($item =~ /^([$in_type_delimiter_quoted])/)
  9831. {
  9832. push @arg_types, 'delimiter';
  9833. }
  9834. else
  9835. {
  9836. push @arg_types, 'paramtype';
  9837. $after_type = 1;
  9838. }
  9839. $spaces = ' ' if ($spaces);
  9840. $line .= $spaces . $item;
  9841. push @arguments, $spaces .$item;
  9842. }
  9843. #print STDERR "PARSE_DEF (style $style, category $category, name $name, type $type, class $class, line $line)\n";
  9844. return ($format, $style, $category, $name, $type, $class, $line, \@arguments, \@arg_types);
  9845. }
  9846. sub begin_paragraph($$)
  9847. {
  9848. my $stack = shift;
  9849. my $state = shift;
  9850. my $command = { };
  9851. my $top_format = top_format($stack);
  9852. if (defined($top_format))
  9853. {
  9854. $command = $top_format;
  9855. }
  9856. $command->{'stack_at_beginning'} = [ @{$state->{'command_stack'}} ];
  9857. my $paragraph_or_preformatted = 'paragraph';
  9858. if ($state->{'preformatted'})
  9859. {
  9860. $paragraph_or_preformatted = 'preformatted';
  9861. $state->{'preformatted_context'} = $command;
  9862. }
  9863. else
  9864. {
  9865. $state->{'paragraph_context'} = $command;
  9866. $state->{'paragraph_nr'}++;
  9867. }
  9868. push @$stack, {'format' => $paragraph_or_preformatted, 'text' => '' };
  9869. # FIXME give line, and modify line?
  9870. &$Texi2HTML::Config::begin_paragraph_texi($paragraph_or_preformatted,
  9871. $state->{'paragraph_macros'}, $command, $state, $stack)
  9872. if (defined($Texi2HTML::Config::begin_paragraph_texi));
  9873. # if there are macros which weren't closed when the previous
  9874. # paragraph was closed we reopen them here
  9875. push @$stack, @{$state->{'paragraph_macros'}} if $state->{'paragraph_macros'};
  9876. delete $state->{'paragraph_macros'};
  9877. }
  9878. sub parse_format_command($$)
  9879. {
  9880. my $line = shift;
  9881. my $tag = shift;
  9882. my $command = '';
  9883. my $orig_line = $line;
  9884. # macro_regexp
  9885. if ($line =~ s/^\s*\@([A-Za-z][\w-]*)(\{\})?\s*$//)
  9886. {
  9887. $command = $1;
  9888. $command = $alias{$command} if (exists($alias{$command}));
  9889. }
  9890. return ('', $command) if ($line =~ /^\s*$/);
  9891. chomp $line;
  9892. $line = substitute_text ({'keep_nr' => 1, 'keep_texi' => 1, 'check_item' => $tag}, undef, "parse_format_command", $line);
  9893. return ($line, $command);
  9894. }
  9895. sub parse_enumerate($)
  9896. {
  9897. my $line = shift;
  9898. my $spec;
  9899. if ($line =~ /^\s*(\w)\b/ and ($1 ne '_'))
  9900. {
  9901. $spec = $1;
  9902. $line =~ s/^\s*(\w)\s*//;
  9903. }
  9904. return ($line, $spec);
  9905. }
  9906. sub parse_multitable($$)
  9907. {
  9908. my $line = shift;
  9909. my $line_nr = shift;
  9910. # first find the table width
  9911. my $table_width = 0;
  9912. my $fractions;
  9913. my $elements;
  9914. if ($line =~ s/^\s+\@columnfractions\s+//)
  9915. {
  9916. @$fractions = split /\s+/, $line;
  9917. $table_width = scalar(@$fractions);
  9918. foreach my $fraction (@$fractions)
  9919. {
  9920. unless ($fraction =~ /^(\d*\.\d+)|(\d+)\.?$/)
  9921. {
  9922. line_error (sprintf(__("column fraction not a number: %s"), $fraction), $line_nr);
  9923. }
  9924. }
  9925. }
  9926. else
  9927. {
  9928. my $element;
  9929. my $line_orig = $line;
  9930. while ($line !~ /^\s*$/)
  9931. {
  9932. my $spaces;
  9933. ($element, $line, $spaces) = next_bracketed($line, 'multitable', $line_nr, 1);
  9934. if ($element =~ /^\{/)
  9935. {
  9936. $table_width++;
  9937. $element =~ s/^\{//;
  9938. $element =~ s/\}\s*$//;
  9939. push @$elements, $element;
  9940. }
  9941. else
  9942. {
  9943. line_warn (sprintf(__("ignoring stray text `%s' after \@multitable"), $element), $line_nr);
  9944. }
  9945. }
  9946. }
  9947. return ($table_width, $fractions, $elements);
  9948. }
  9949. sub end_format($$$$$)
  9950. {
  9951. my $text = shift;
  9952. my $stack = shift;
  9953. my $state = shift;
  9954. my $format = shift;
  9955. my $line_nr = shift;
  9956. #msg_debug ("END FORMAT $format", $line_nr);
  9957. #dump_stack($text, $stack, $state);
  9958. #sleep 1;
  9959. if ($format_type{$format} eq 'menu')
  9960. {
  9961. $state->{$format}--;
  9962. if ($state->{$format} < 0)
  9963. { # FIXME currently happens, see invalid/not_closed_in_menu.texi
  9964. line_error(sprintf(__("Too many %s closed"), $format), $line_nr);
  9965. #print STDERR "Bug, $format counter negative: $state->{$format}\n";
  9966. #dump_stack($text, $stack, $state);
  9967. #exit 1;
  9968. $state->{$format} = 0;
  9969. }
  9970. close_menu_comment($text, $stack, $state, "\@end $format", $line_nr);
  9971. }
  9972. if ($format_type{$format} eq 'list')
  9973. { # those functions return if they detect an inapropriate context
  9974. add_item($text, $stack, $state, $line_nr); # handle lists
  9975. }
  9976. elsif ($format eq 'multitable')
  9977. {
  9978. add_row($text, $stack, $state, $line_nr); # handle multitable
  9979. }
  9980. elsif ($format_type{$format} eq 'table')
  9981. {
  9982. add_term($text, $stack, $state, $line_nr); # handle table
  9983. add_line($text, $stack, $state, $line_nr); # handle table
  9984. }
  9985. #print STDERR "END_FORMAT\n";
  9986. #dump_stack($text, $stack, $state);
  9987. # set to 1 if there is a mismatch between the closed format and format
  9988. # opened before
  9989. my $format_mismatch = 0;
  9990. # set to 1 in normal menu context after an end menu or detailmenu
  9991. my $begin_menu_comment_after_end_format = 0;
  9992. my $format_ref = pop @$stack;
  9993. ######################### debug
  9994. if (!defined($format_ref->{'text'}))
  9995. {
  9996. push @$stack, $format_ref;
  9997. print STDERR "Bug: text undef in end_format $format\n";
  9998. dump_stack($text, $stack, $state);
  9999. pop @$stack;
  10000. }
  10001. ######################### end debug
  10002. if ($region_lines{$format})
  10003. {
  10004. ######################### debug
  10005. if ($format ne $state->{'region_lines'}->{'format'})
  10006. {
  10007. msg_debug ("Bug: mismatched region `$format' ne `$state->{'region_lines'}->{'format'}'");
  10008. }
  10009. ######################### end debug
  10010. $state->{'region_lines'}->{'number'}--;
  10011. if ($state->{'region_lines'}->{'number'} == 0)
  10012. {
  10013. close_region($state);
  10014. }
  10015. }
  10016. if ($format_type{$format} eq 'table' or $format_type{$format} eq 'list' or $format eq 'multitable')
  10017. {
  10018. if ($format_ref->{'format'} ne $format)
  10019. { # for example vtable closing a table. Cannot be known
  10020. # before if in a cell
  10021. $format_mismatch = 1;
  10022. line_error (sprintf(__("`\@end' expected `%s', but saw `%s'"), $format_ref->{'format'}, $format), $line_nr);
  10023. }
  10024. if (!$format_ref->{'empty_first'} and $format_ref->{'item_nr'} == 0)
  10025. {
  10026. line_warn (sprintf(__("\@%s has text but no \@item"),$format_ref->{'format'}), $line_nr);
  10027. }
  10028. }
  10029. if (defined($Texi2HTML::Config::def_map{$format}))
  10030. {
  10031. close_stack($text, $stack, $state, $line_nr, 'deff_item')
  10032. unless ($format_ref->{'format'} eq 'deff_item');
  10033. add_prev($text, $stack, &$Texi2HTML::Config::def_item($format_ref->{'text'}, $format_ref->{'only_inter_commands'}, $format_ref->{'orig_command'}));
  10034. $format_ref = pop @$stack; # pop deff
  10035. ######################################### debug
  10036. if (!defined($format_ref->{'format'}) or !defined($Texi2HTML::Config::def_map{$format_ref->{'format'}}))
  10037. {
  10038. print STDERR "Bug: not a def* under deff_item\n";
  10039. push (@$stack, $format_ref);
  10040. dump_stack($text, $stack, $state);
  10041. pop @$stack;
  10042. }
  10043. ######################################### end debug
  10044. elsif ($format_ref->{'format'} ne $format)
  10045. {
  10046. $format_mismatch = 1;
  10047. line_error (sprintf(__("`\@end' expected `%s', but saw `%s'"), $format_ref->{'format'}, $format), $line_nr);
  10048. }
  10049. add_prev($text, $stack, &$Texi2HTML::Config::def($format_ref->{'text'}, $format_ref->{'orig_format'}));
  10050. }
  10051. elsif ($format eq 'float')
  10052. {
  10053. unless (defined($state->{'float'}))
  10054. {
  10055. msg_debug("state->{'float'} not defined in float", $line_nr);
  10056. next;
  10057. }
  10058. my ($caption_lines, $shortcaption_lines) = &$Texi2HTML::Config::caption_shortcaption($state->{'float'});
  10059. my ($caption_text, $shortcaption_text);
  10060. my $caption_state = duplicate_formatting_state($state);
  10061. push @{$caption_state->{'command_stack'}}, 'caption';
  10062. $caption_text = substitute_text($caption_state, undef, '@caption in @end float', @$caption_lines) if (defined($caption_lines));
  10063. my $shortcaption_state = duplicate_formatting_state($state);
  10064. push @{$shortcaption_state->{'command_stack'}}, 'shortcaption';
  10065. $shortcaption_text = substitute_text($shortcaption_state, undef, '@shortcaption in @end float', @$shortcaption_lines) if (defined($shortcaption_lines));
  10066. add_prev($text, $stack, &$Texi2HTML::Config::float($format_ref->{'text'}, $state->{'float'}, $caption_text, $shortcaption_text));
  10067. delete $state->{'float'};
  10068. }
  10069. # FIXME $complex_format_map obsoleted in nov 2009
  10070. elsif ((exists ($Texi2HTML::Config::complex_format_map->{$format})
  10071. or exists ($Texi2HTML::Config::complex_format_map{$format}))
  10072. and ($format_type{$format} ne 'menu' or get_conf('SIMPLE_MENU')))
  10073. {
  10074. $state->{'preformatted'}--;
  10075. pop @{$state->{'preformatted_stack'}};
  10076. my $complex_format;
  10077. if (exists ($Texi2HTML::Config::complex_format_map->{$format}))
  10078. {
  10079. $complex_format = $Texi2HTML::Config::complex_format_map->{$format};
  10080. }
  10081. else
  10082. {
  10083. $complex_format = $Texi2HTML::Config::complex_format_map{$format};
  10084. }
  10085. # debug
  10086. if (!defined($complex_format->{'begin'}))
  10087. {
  10088. msg_debug ("Bug undef $format_ref->{'format'}" . "->{'begin'} (for $format...)", $line_nr);
  10089. dump_stack ($text, $stack, $state);
  10090. }
  10091. if ($fake_format{$format_ref->{'format'}} and $format_ref->{'text'} =~ /^\s*$/)
  10092. {
  10093. # discard empty fake formats
  10094. }
  10095. #print STDERR "before $format\n";
  10096. #dump_stack ($text, $stack, $state);
  10097. else
  10098. {
  10099. add_prev($text, $stack, &$Texi2HTML::Config::complex_format($format_ref->{'format'}, $format_ref->{'text'}));
  10100. }
  10101. #print STDERR "after $format\n";
  10102. #dump_stack ($text, $stack, $state);
  10103. }
  10104. elsif ($format_type{$format} eq 'table' or $format_type{$format} eq 'list' or $format eq 'multitable')
  10105. {
  10106. if (exists ($Texi2HTML::Config::format_map{$format}))
  10107. { # table or list has a simple format
  10108. add_prev($text, $stack, end_simple_format($format_ref->{'format'}, $format_ref->{'text'}, $state));
  10109. }
  10110. else
  10111. { # table or list handler defined by the user
  10112. add_prev($text, $stack, &$Texi2HTML::Config::table_list($format_ref->{'format'}, $format_ref->{'text'}, $format_ref->{'command'}, $format_ref->{'formatted_command'}, $format_ref->{'item_nr'}, $format_ref->{'spec'}, $format_ref->{'prepended'}, $format_ref->{'prepended_formatted'}, $format_ref->{'columnfractions'}, $format_ref->{'prototype_row'}, $format_ref->{'prototype_lengths'}, $format_ref->{'max_columns'}));
  10113. }
  10114. }
  10115. elsif ($format_type{$format} eq 'quotation')
  10116. {
  10117. my $quotation_args = pop @{$state->{'quotation_stack'}};
  10118. #add_prev($text, $stack, &$Texi2HTML::Config::quotation($format, $format_ref->{'text'}, $quotation_args->{'text'}, $quotation_args->{'text_texi'}));
  10119. add_prev($text, $stack, &$Texi2HTML::Config::quotation($format, $format_ref->{'text'}, $format_ref->{'argument_text'}, $format_ref->{'argument_texi'}, $format_ref->{'quote_authors'}));
  10120. }
  10121. elsif ($Texi2HTML::Config::paragraph_style{$format})
  10122. {
  10123. if ($state->{'paragraph_style'}->[-1] eq $format)
  10124. {
  10125. pop @{$state->{'paragraph_style'}};
  10126. }
  10127. if ($fake_format{$format_ref->{'format'}} and $format_ref->{'text'} =~ /^\s*$/)
  10128. {
  10129. # discard empty fake formats
  10130. }
  10131. else
  10132. {
  10133. add_prev($text, $stack, &$Texi2HTML::Config::paragraph_style_command($format_ref->{'format'},$format_ref->{'text'}));
  10134. }
  10135. }
  10136. elsif (exists($Texi2HTML::Config::format_map{$format}))
  10137. {
  10138. if ($fake_format{$format_ref->{'format'}} and $format_ref->{'text'} =~ /^\s*$/)
  10139. {
  10140. # discard empty fake formats
  10141. }
  10142. else
  10143. {
  10144. add_prev($text, $stack, end_simple_format($format_ref->{'format'}, $format_ref->{'text'}, $state));
  10145. }
  10146. }
  10147. elsif ($format_type{$format} eq 'cartouche')
  10148. {
  10149. add_prev($text, $stack, &$Texi2HTML::Config::cartouche($format_ref->{'text'},$state->{'command_stack'}));
  10150. }
  10151. elsif ($format_type{$format} eq 'menu')
  10152. {
  10153. # it should be short-circuited if SIMPLE_MENU
  10154. if ($state->{'preformatted'})
  10155. {
  10156. # remove the fake complex style
  10157. $state->{'preformatted'}--;
  10158. pop @{$state->{'preformatted_stack'}};
  10159. }
  10160. # backward compatibility with 1.78 jun 2007
  10161. if (defined($Texi2HTML::Config::menu))
  10162. {
  10163. if ($format eq 'menu')
  10164. {
  10165. add_prev($text, $stack, &$Texi2HTML::Config::menu($format_ref->{'text'}));
  10166. }
  10167. elsif ($format eq 'detailmenu') # detailmenu
  10168. {
  10169. add_prev($text, $stack, $format_ref->{'text'});
  10170. }
  10171. else # direntry
  10172. {
  10173. }
  10174. }
  10175. else
  10176. {
  10177. add_prev($text, $stack, &$Texi2HTML::Config::menu_command($format, $format_ref->{'text'}, $state->{'preformatted'}));
  10178. }
  10179. $begin_menu_comment_after_end_format = 1;
  10180. }
  10181. else
  10182. {
  10183. line_warn(sprintf(__("Unknown format %s"), $format), $line_nr);
  10184. }
  10185. # fake formats are not on the command_stack
  10186. return 1 if ($fake_format{$format_ref->{'format'}});
  10187. # special case for center as it is at the bottom of the stack
  10188. my $removed_from_stack;
  10189. if ($format eq 'center')
  10190. {
  10191. $removed_from_stack = shift @{$state->{'command_stack'}};
  10192. }
  10193. else
  10194. {
  10195. $removed_from_stack = pop @{$state->{'command_stack'}};
  10196. }
  10197. if ($removed_from_stack ne $format and !$format_mismatch)
  10198. {
  10199. #line_error ("Bug: removed_from_stack $removed_from_stack ne format $format", $line_nr);
  10200. # it may not be a bug. Consider, for example a @code{in code
  10201. # @end cartouche
  10202. # The @code is closed when the paragraph is closed by
  10203. # @end cartouche but not really closed since it might have been
  10204. # a multiple paragraph @code. So it is not removed from
  10205. # command_stack but still have disapeared from the stack!
  10206. line_error(sprintf(__("mismatched \@end %s with \@%s"), $format, $removed_from_stack), $line_nr);
  10207. }
  10208. if ($begin_menu_comment_after_end_format and $state->{'menu'})
  10209. {
  10210. begin_format($text, $stack, $state, 'menu_comment', '', $line_nr);
  10211. return 0;
  10212. }
  10213. return 1;
  10214. }
  10215. sub push_complex_format_style($$$$)
  10216. {
  10217. my $command = shift;
  10218. my $complex_format = shift;
  10219. my $state = shift;
  10220. my $line_nr = shift;
  10221. my $class = $command;
  10222. if (!defined($state->{'preformatted_stack'}))
  10223. {
  10224. msg_debug ("'preformatted_stack' not defined in push_complex_format_style", $line_nr);
  10225. }
  10226. $class = $complex_format->{'class'} if (defined($complex_format->{'class'}));
  10227. my $format_style = {'pre_style' =>$complex_format->{'pre_style'}, 'class' => $class, 'command' => $command };
  10228. if (defined($complex_format->{'style'}))
  10229. {
  10230. $format_style->{'style'} = $complex_format->{'style'};
  10231. }
  10232. else
  10233. {
  10234. if ($state->{'preformatted'} and defined($state->{'preformatted_stack'}->[-1]->{'style'}))
  10235. {
  10236. $format_style->{'style'} = $state->{'preformatted_stack'}->[-1]->{'style'};
  10237. }
  10238. my $index = scalar(@{$state->{'preformatted_stack'}}) -1;
  10239. # since preformatted styles are not nested, the preformatted format
  10240. # of the first format with style has to be used
  10241. if ($index > 0)
  10242. {
  10243. while ($index)
  10244. {
  10245. if ($state->{'preformatted_stack'}->[$index]->{'style'})
  10246. {
  10247. $format_style->{'class'} = $state->{'preformatted_stack'}->[$index]->{'class'} if (defined($state->{'preformatted_stack'}->[$index]->{'class'}));
  10248. last;
  10249. }
  10250. $index--;
  10251. }
  10252. }
  10253. }
  10254. $state->{'preformatted'}++;
  10255. push @{$state->{'preformatted_stack'}}, $format_style;
  10256. }
  10257. sub prepare_state_multiple_pass($$)
  10258. {
  10259. my $command = shift;
  10260. my $state = shift;
  10261. my $return_state = {
  10262. 'multiple_pass' => 1,
  10263. 'element' => $state->{'element'},
  10264. 'outside_document' => $state->{'outside_document'},
  10265. 'new_state' => 1
  10266. };
  10267. if (defined($command))
  10268. {
  10269. $return_state->{'expansion'} = $command;
  10270. $return_state->{'command_stack'} = ["$command"];
  10271. }
  10272. else
  10273. {
  10274. msg_debug("prepare_state_multiple_pass command not defined");
  10275. }
  10276. return $return_state;
  10277. }
  10278. sub begin_format($$$$$$);
  10279. sub begin_format($$$$$$)
  10280. {
  10281. my $text = shift;
  10282. my $stack = shift;
  10283. my $state = shift;
  10284. my $macro = shift;
  10285. my $line = shift;
  10286. my $line_nr = shift;
  10287. #msg_debug ("BEGIN FORMAT $macro",$line_nr);
  10288. my $in_term;
  10289. my $top_format = top_stack($stack, 2);
  10290. $in_term = 1 if (defined($top_format->{'format'}) and $top_format->{'format'} eq 'term');
  10291. if ($format_type{$macro} eq 'menu')
  10292. {
  10293. if ($state->{'menu'})
  10294. {
  10295. # there should not be any paragraph/preformatted to close
  10296. # if the comment or the description were closed since they
  10297. # close it
  10298. if (! close_menu_comment($text, $stack, $state, "\@$macro", $line_nr)
  10299. and !close_menu_description($text, $stack, $state, "\@$macro", $line_nr))
  10300. {
  10301. close_paragraph($text, $stack, $state, "\@$macro", $line_nr);
  10302. }
  10303. }
  10304. else
  10305. {
  10306. close_paragraph($text, $stack, $state, "\@$macro", $line_nr);
  10307. }
  10308. $state->{$macro}++;
  10309. }
  10310. elsif (!$in_term)
  10311. {
  10312. close_paragraph($text, $stack, $state, "\@$macro", $line_nr);
  10313. }
  10314. # close def_item if this is a matching @def*x command
  10315. if (defined($Texi2HTML::Config::def_map{$macro}))
  10316. {
  10317. my $top_format = top_format($stack);
  10318. if (defined($top_format) and ("$top_format->{'format'}x" eq $macro))
  10319. {
  10320. # this is a matching @DEFx command.
  10321. my $deff_item = pop @$stack;
  10322. add_prev($text, $stack,
  10323. &$Texi2HTML::Config::def_item($deff_item->{'text'}, $deff_item->{'only_inter_commands'}, $deff_item->{'orig_command'}));
  10324. #print STDERR "DEFx $macro\n";
  10325. }
  10326. elsif ($macro =~ /x$/)
  10327. {
  10328. my $base_def_command = $macro;
  10329. $base_def_command =~ s/x$//;
  10330. line_error(sprintf(__("Must be in `\@%s' environment to use `\@%s'"), $base_def_command, $macro), $line_nr);
  10331. }
  10332. }
  10333. $line = &$Texi2HTML::Config::begin_format_texi($macro, $line, $state)
  10334. unless($fake_format{$macro});
  10335. push (@{$state->{'command_stack'}}, $macro) unless ($fake_format{$macro});
  10336. if ($region_lines{$macro})
  10337. {
  10338. open_region($macro,$state);
  10339. }
  10340. # A deff like macro
  10341. if (defined($Texi2HTML::Config::def_map{$macro}))
  10342. {
  10343. my $top_format = top_format($stack);
  10344. my $orig_command = $macro;
  10345. if (defined($top_format) and ("$top_format->{'format'}x" eq $macro))
  10346. {
  10347. # this is a matching @DEFx command.
  10348. # the @DEFx macro has been put at the top of the
  10349. # command_stack, although there is no real format opening
  10350. pop @{$state->{'command_stack'}};
  10351. $macro =~ s/x$//o;
  10352. #print STDERR "DEFx $macro\n";
  10353. }
  10354. else
  10355. {
  10356. # a new @def.
  10357. $macro =~ s/x$//o;
  10358. # we remove what is on the stack and put it back,
  10359. # to make sure that it is the form without x.
  10360. pop @{$state->{'command_stack'}};
  10361. push @{$state->{'command_stack'}}, $macro;
  10362. #print STDERR "DEF begin $macro\n";
  10363. $top_format = { 'format' => $macro, 'text' => '', 'orig_format' =>$orig_command};
  10364. push @$stack, $top_format;
  10365. }
  10366. #print STDERR "BEGIN_DEFF $macro\n";
  10367. #dump_stack ($text, $stack, $state);
  10368. my ($command, $style, $category, $name, $type, $class, $args_array, $args_type_array);
  10369. ($command, $style, $category, $name, $type, $class, $line, $args_array, $args_type_array) = parse_def($macro, $line, $line_nr);
  10370. my $class_name_texi = &$Texi2HTML::Config::definition_index_entry($name, $class, $style, $command);
  10371. #print STDERR "AFTER parse_def $line";
  10372. my @formatted_args = ();
  10373. my $arguments = '';
  10374. my %formatted_arguments = ();
  10375. my @types = @$args_type_array;
  10376. my $arg_nr = 0;
  10377. my $previous_type;
  10378. foreach my $arg (@$args_array)
  10379. {
  10380. $arg_nr++;
  10381. my $type = shift @types;
  10382. my $substitution_state = duplicate_formatting_state($state);
  10383. # all @def* arguments are in code_style
  10384. $substitution_state->{'code_style'}++;
  10385. push @formatted_args, substitute_line($arg, sprintf(__("\@%s (argument nr %d)"), $macro, $arg_nr), $substitution_state, $line_nr);
  10386. if (grep {$_ eq $type} ('param', 'paramtype', 'delimiter'))
  10387. {
  10388. $arguments .= $formatted_args[-1];
  10389. }
  10390. else
  10391. {
  10392. $formatted_arguments{$type} = $formatted_args[-1];
  10393. }
  10394. $previous_type = $type;
  10395. }
  10396. $name = $formatted_arguments{'name'};
  10397. $category = $formatted_arguments{'category'};
  10398. $type = $formatted_arguments{'type'};
  10399. $class = $formatted_arguments{'class'};
  10400. $name = '' if (!defined($name));
  10401. $category = '' if (!defined($category));
  10402. my $class_category = &$Texi2HTML::Config::definition_category($category, $class, $style, $command);
  10403. my $class_name = &$Texi2HTML::Config::definition_index_entry($name, $class, $style, $command);
  10404. my ($index_entry, $formatted_index_entry, $index_label) = do_index_entry_label($macro, $state, $line_nr, $class_name_texi, $line);
  10405. add_prev($text, $stack, &$Texi2HTML::Config::def_line($class_category, $name, $type, $arguments, $index_label, \@formatted_args, $args_type_array, $args_array, $command, $class_name, $category, $class, $style, $orig_command));
  10406. $line = '';
  10407. push @$stack, { 'format' => 'deff_item', 'text' => '', 'only_inter_commands' => 1, 'format_ref' => $top_format, 'orig_command' => $orig_command};
  10408. begin_paragraph_after_command($state, $stack, $macro, $line);
  10409. }
  10410. # FIXME $complex_format_map obsoleted in nov 2009
  10411. elsif ((exists ($Texi2HTML::Config::complex_format_map->{$macro})
  10412. or exists ($Texi2HTML::Config::complex_format_map{$macro}))
  10413. and ($format_type{$macro} ne 'menu' or get_conf('SIMPLE_MENU')))
  10414. { # handle menu if SIMPLE_MENU. see texi2html.pm
  10415. my $complex_format;
  10416. if (exists ($Texi2HTML::Config::complex_format_map->{$macro}))
  10417. {
  10418. $complex_format = $Texi2HTML::Config::complex_format_map->{$macro};
  10419. }
  10420. else
  10421. {
  10422. $complex_format = $Texi2HTML::Config::complex_format_map{$macro};
  10423. }
  10424. my $format = { 'format' => $macro, 'text' => '', 'pre_style' => $complex_format->{'pre_style'} };
  10425. push_complex_format_style($macro, $complex_format, $state, $line_nr);
  10426. push @$stack, $format;
  10427. begin_paragraph($stack, $state);
  10428. }
  10429. elsif ($Texi2HTML::Config::paragraph_style{$macro})
  10430. {
  10431. push (@$stack, { 'format' => $macro, 'text' => '' });
  10432. begin_paragraph_after_command($state,$stack,$macro,$line) unless ($in_term);
  10433. push @{$state->{'paragraph_style'}}, $macro;
  10434. if ($macro eq 'center')
  10435. {
  10436. # @center may be in a weird state with regard with
  10437. # nesting, so we put it on the bottom of the stack
  10438. pop @{$state->{'command_stack'}};
  10439. unshift @{$state->{'command_stack'}}, $macro;
  10440. # for similar reasons, we may have a bad stack nesting
  10441. # which results in } after a closing.
  10442. # The following isn't really true anymore, I think: for example
  10443. # @center @samp{something @center end of samp}
  10444. # resulted to samp being kept in the 'command_stack'
  10445. }
  10446. }
  10447. elsif ($format_type{$macro} eq 'list' or $format_type{$macro} eq 'table' or $macro eq 'multitable')
  10448. {
  10449. my $format;
  10450. #print STDERR "LIST_TABLE $macro\n";
  10451. #dump_stack($text, $stack, $state);
  10452. if ($macro eq 'itemize' or $format_type{$macro} eq 'table')
  10453. {
  10454. my $command;
  10455. my $prepended;
  10456. ($prepended, $command) = parse_format_command($line,$macro);
  10457. if (($command eq '') and ($macro ne 'itemize'))
  10458. {
  10459. $command = 'asis';
  10460. line_error(sprintf(__("%s requires an argument: the formatter for %citem"), $macro, ord('@')), $line_nr);
  10461. }
  10462. my $prepended_formatted;
  10463. $prepended_formatted = substitute_line($prepended, sprintf(__("prepended for \@%s"), $macro), prepare_state_multiple_pass('item', $state)) if (defined($prepended));
  10464. $format = { 'format' => $macro, 'text' => '', 'command' => $command, 'prepended' => $prepended, 'prepended_formatted' => $prepended_formatted };
  10465. $line = '';
  10466. }
  10467. elsif ($macro eq 'enumerate')
  10468. {
  10469. my $spec;
  10470. ($line, $spec) = parse_enumerate ($line);
  10471. $spec = 1 if (!defined($spec));
  10472. $format = { 'format' => $macro, 'text' => '', 'spec' => $spec };
  10473. }
  10474. elsif ($macro eq 'multitable')
  10475. {
  10476. my ($max_columns, $fractions, $prototype_row) = parse_multitable ($line, $line_nr);
  10477. if (!$max_columns)
  10478. {
  10479. line_warn (__("empty multitable"), $line_nr);
  10480. $max_columns = 0;
  10481. }
  10482. my @prototype_lengths = ();
  10483. if (defined($prototype_row))
  10484. {
  10485. my $prototype_nr = 0;
  10486. foreach my $prototype (@$prototype_row)
  10487. {
  10488. $prototype_nr++;
  10489. push @prototype_lengths, 2+Texi2HTML::Config::t2h_default_string_width(substitute_line($prototype, sprintf(__("\@columnfraction (argument nr %d)"), $prototype_nr), prepare_state_multiple_pass('columnfractions', $state)));
  10490. }
  10491. }
  10492. $format = { 'format' => $macro, 'text' => '', 'max_columns' => $max_columns, 'columnfractions' => $fractions, 'prototype_row' => $prototype_row, 'prototype_lengths' => \@prototype_lengths, 'cell' => 1 };
  10493. }
  10494. $format->{'first'} = 1;
  10495. $format->{'item_nr'} = 0;
  10496. $format->{'paragraph_number'} = 0;
  10497. push @$stack, $format;
  10498. if ($format_type{$macro} eq 'table')
  10499. {
  10500. push @$stack, { 'format' => 'line', 'text' => '', 'format_ref' => $format, 'only_inter_commands' => 1};
  10501. }
  10502. elsif ($macro eq 'multitable')
  10503. {
  10504. push @$stack, { 'format' => 'row', 'text' => '', 'format_ref' => $format, 'item_cmd' => $macro };
  10505. push @$stack, { 'format' => 'cell', 'text' => '', 'format_ref' => $format, 'only_inter_commands' => 1};
  10506. }
  10507. if ($format_type{$macro} eq 'list')
  10508. {
  10509. push @$stack, { 'format' => 'item', 'text' => '', 'format_ref' => $format, 'only_inter_commands' => 1};
  10510. }
  10511. begin_paragraph_after_command($state,$stack,$macro,$line)
  10512. if ($macro ne 'multitable');
  10513. return '' unless ($macro eq 'enumerate');
  10514. }
  10515. elsif ($macro eq 'float' or $format_type{$macro} eq 'quotation')
  10516. {
  10517. push @$stack, {'format' => $macro, 'text' => '' };
  10518. if ($macro eq 'float')
  10519. {
  10520. my @args = parse_line_arguments($line, 2, "\@$macro");
  10521. do_float_line ($macro, \@args, $state->{'style_stack'}, $state, $line_nr);
  10522. }
  10523. elsif ($format_type{$macro} eq 'quotation')
  10524. {
  10525. my @args = parse_line_arguments($line, 1, "\@$macro", $line_nr);
  10526. do_quotation_line ($macro, $stack->[-1], \@args, $state->{'style_stack'}, $state, $line_nr);
  10527. }
  10528. $line = '';
  10529. if ($state->{'preformatted'})
  10530. { # inconditionally begin a preformatted section if needed
  10531. begin_paragraph($stack, $state);
  10532. }
  10533. #dump_stack($text, $stack, $state);
  10534. }
  10535. # keep this one at the end as there are some other formats
  10536. # which are also in format_map
  10537. elsif (defined($Texi2HTML::Config::format_map{$macro}) or ($format_type{$macro} eq 'cartouche'))
  10538. {
  10539. push @$stack, { 'format' => $macro, 'text' => '' };
  10540. $state->{'code_style'}++ if ($Texi2HTML::Config::format_code_style{$macro});
  10541. begin_paragraph_after_command($state,$stack,$macro,$line);
  10542. }
  10543. elsif ($format_type{$macro} eq 'menu')
  10544. {
  10545. # if SIMPLE_MENU we won't get there
  10546. # as the menu is a complex format in that case, so it
  10547. # is handled above
  10548. push @$stack, { 'format' => $macro, 'text' => '' };
  10549. if ($state->{'preformatted'})
  10550. {
  10551. # add a fake complex style in order to have a given pre style
  10552. push_complex_format_style('menu',
  10553. $Texi2HTML::Config::MENU_PRE_COMPLEX_FORMAT, $state, $line_nr);
  10554. begin_paragraph_after_command($state,$stack,$macro,$line);
  10555. }
  10556. else
  10557. {
  10558. begin_format($text, $stack, $state, 'menu_comment', $line, $line_nr);
  10559. }
  10560. }
  10561. # this is useful for @center, and also if there was something on the
  10562. # line after a format that isn't there anymore, like
  10563. # @format @c
  10564. # if @center line is empty we don't remove the end of line
  10565. $line =~ s/^\s*// unless ($macro eq 'center' and $line =~ /^\s*$/);
  10566. return $line;
  10567. }
  10568. sub do_text($;$)
  10569. {
  10570. my $text = shift;
  10571. my $state = shift;
  10572. return $text if ($state->{'keep_texi'});
  10573. my $remove_texi = 1 if ($state->{'remove_texi'} and !$state->{'simple_format'});
  10574. my $preformatted_style = 0;
  10575. if ($state->{'preformatted'})
  10576. {
  10577. $preformatted_style = $state->{'preformatted_stack'}->[-1]->{'style'};
  10578. }
  10579. # disabled since it is too expensive (because do_text is
  10580. # called often) for a warning which rather questionable anyway.
  10581. #if (Texi2HTML::Config::in_cmd($state->{'command_stack'}, 'var') and $text =~ /([$Texi2HTML::Config::warn_var_character_quoted])/)
  10582. #{
  10583. # line_warn (sprintf(__("unlikely character %c in \@var"), ord($1)), $Texi2HTML::THISDOC{'line_nr'});
  10584. #}
  10585. return (&$Texi2HTML::Config::normal_text($text, $remove_texi, $preformatted_style, $state->{'code_style'}, $state->{'math_style'}, $state->{'simple_format'},$state->{'command_stack'}, $state));
  10586. }
  10587. sub end_simple_format($$$)
  10588. {
  10589. my $command = shift;
  10590. my $text = shift;
  10591. my $state = shift;
  10592. my $element = $Texi2HTML::Config::format_map{$command};
  10593. my $result = &$Texi2HTML::Config::format($command, $element, $text);
  10594. $state->{'code_style'}-- if ($Texi2HTML::Config::format_code_style{$command});
  10595. return $result;
  10596. }
  10597. # only get there if not in SIMPLE_MENU and not in preformatted and
  10598. # right in @menu
  10599. sub close_menu_comment($$$$$)
  10600. {
  10601. my $text = shift;
  10602. my $stack = shift;
  10603. my $state = shift;
  10604. my $reason = shift;
  10605. my $line_nr = shift;
  10606. my $top_format = top_stack($stack,2);
  10607. if (defined($top_format->{'format'}) and $top_format->{'format'} eq 'menu_comment')
  10608. { # this is needed to avoid empty menu-comments <tr>...<pre></pre>
  10609. abort_empty_preformatted($stack, $state);
  10610. close_paragraph($text, $stack, $state, $reason, $line_nr);
  10611. end_format($text, $stack, $state, 'menu_comment', $line_nr);
  10612. return 1;
  10613. }
  10614. }
  10615. # never get there if in SIMPLE_MENU
  10616. # the last arg is used only if in description and an empty line may
  10617. # stop it and begin a menu_comment
  10618. sub close_menu_description($$$$$;$)
  10619. {
  10620. my $text = shift;
  10621. my $stack = shift;
  10622. my $state = shift;
  10623. my $reason = shift;
  10624. my $line_nr = shift;
  10625. my $line = shift;
  10626. my $top_format = top_stack($stack,1);
  10627. if (!$state->{'preformatted'})
  10628. {
  10629. $top_format = top_stack($stack);
  10630. }
  10631. if (defined($top_format->{'format'}) and $top_format->{'format'} eq 'menu_description' and (!defined($line) or $line =~ /^\s*$/) )
  10632. {
  10633. close_paragraph($text, $stack, $state, $reason, $line_nr) if ($state->{'preformatted'});
  10634. my $descr = pop(@$stack);
  10635. add_prev($text, $stack, do_menu_description($descr, $state));
  10636. print STDERR "# close_menu: close description\n" if ($T2H_DEBUG & $DEBUG_MENU);
  10637. $state->{'code_style'}-- if ($Texi2HTML::Config::format_code_style{'menu_description'});
  10638. return 1;
  10639. }
  10640. }
  10641. # Format menu link
  10642. # FIXME also pass node and name?
  10643. sub do_menu_link($$$)
  10644. {
  10645. my $state = shift;
  10646. my $line_nr = shift;
  10647. my $menu_entry = shift;
  10648. my $file = $state->{'element'}->{'file'};
  10649. my $node_name = normalise_node($menu_entry->{'node'});
  10650. # normalise_node is used in fact to determine if name is empty.
  10651. # It is not passed down to the function reference.
  10652. my $name = normalise_node($menu_entry->{'name'});
  10653. # there is one substitution with spaces kept, and one with spaces
  10654. # normalized. In every cases nodes are in code_style
  10655. my $node_substitution_state = duplicate_formatting_state($state);
  10656. my $name_substitution_state = duplicate_formatting_state($state);
  10657. my $node_normalized_substitution_state = duplicate_formatting_state($state);
  10658. $node_substitution_state->{'code_style'} = 1;
  10659. $node_normalized_substitution_state->{'code_style'} = 1;
  10660. $name_substitution_state->{'code_style'} = 1 if ($Texi2HTML::Config::format_code_style{'menu_name'});
  10661. my $node_formatted = substitute_line($menu_entry->{'node'}, __("node name in menu"), $node_substitution_state, $line_nr);
  10662. my $node_normalized_formatted = substitute_line($node_name, __("normalized node name in menu"), $node_normalized_substitution_state);
  10663. my $name_formatted;
  10664. my $has_name = 0;
  10665. if (defined($name) and $name ne '')
  10666. {
  10667. $name_formatted = substitute_line($menu_entry->{'name'}, __("menu entry name"), $name_substitution_state, $line_nr);
  10668. $has_name = 1;
  10669. }
  10670. else
  10671. {
  10672. my $node_as_name = $menu_entry->{'node'};
  10673. $node_as_name =~ s/^\s*//;
  10674. $name_formatted = substitute_line($node_as_name, __("node name in menu"), $name_substitution_state);
  10675. }
  10676. my $entry = '';
  10677. my $href;
  10678. my $element;
  10679. if ($state->{'direntry'})
  10680. {
  10681. $href = do_external_href($node_name);
  10682. }
  10683. else
  10684. {
  10685. $element = $nodes{$node_name};
  10686. }
  10687. # menu points to an unknown node
  10688. if (defined($element) and !$element->{'seen'})
  10689. {
  10690. if ($menu_entry->{'node'} =~ /^\s*\(.*\)/o or Texi2HTML::Config::get_conf('novalidate'))
  10691. {
  10692. # menu entry points to another info manual or invalid nodes
  10693. # and novalidate is set
  10694. #$href = $nodes{$node_name}->{'file'};
  10695. $href = do_external_href($node_name);
  10696. }
  10697. else
  10698. {
  10699. line_error (sprintf(__("Menu reference to nonexistent node `%s'"), $node_name), $line_nr);
  10700. # try to find an equivalent node
  10701. my $node_seen = find_equivalent_node($node_name);
  10702. if (defined($node_seen))
  10703. {
  10704. document_warn("---> but equivalent node `$node_seen' found");
  10705. $element = $nodes{$node_seen};
  10706. }
  10707. }
  10708. }
  10709. # the original node or an equivalent node was seen
  10710. if (defined($element) and $element->{'seen'})
  10711. {
  10712. if ($element->{'reference_element'})
  10713. {
  10714. $element = $element->{'reference_element'};
  10715. }
  10716. #print STDERR "SUBHREF in menu for `$element->{'texi'}'\n";
  10717. $href = href($element, $file, $line_nr);
  10718. if (! $element->{'node'})
  10719. {
  10720. $entry = $element->{'text'}; # this is the section/node name
  10721. $entry = "$Texi2HTML::Config::MENU_SYMBOL $entry" if (($entry ne '') and (!defined($element->{'number'}) or ($element->{'number'} =~ /^\s*$/)) and $Texi2HTML::Config::UNNUMBERED_SYMBOL_IN_MENU);
  10722. }
  10723. }
  10724. # save the element used for the href for the description
  10725. $menu_entry->{'menu_reference_element'} = $element;
  10726. return &$Texi2HTML::Config::menu_link($entry, $state, $href, $node_formatted, $name_formatted, $menu_entry->{'ending'}, $has_name, $state->{'command_stack'}, $state->{'preformatted'}, $node_normalized_formatted);
  10727. }
  10728. sub do_menu_description($$)
  10729. {
  10730. my $descr = shift;
  10731. my $state = shift;
  10732. my $text = $descr->{'text'};
  10733. my $menu_entry = $descr->{'menu_entry'};
  10734. my $element = $menu_entry->{'menu_reference_element'};
  10735. ############# debug
  10736. # this is not a bug if element is not defined in direntry
  10737. print STDERR "Bug: !defined(element) in do_menu_description\n" if (!defined($element) and ($state->{'menu'} or $state->{'detailmenu'}));
  10738. ############# end debug
  10739. my $element_text = '';
  10740. $element_text = $element->{'text_nonumber'} if (defined($element));
  10741. return &$Texi2HTML::Config::menu_description($text, duplicate_formatting_state($state),$element_text, $state->{'command_stack'}, $state->{'preformatted'});
  10742. }
  10743. sub do_xref($$$$)
  10744. {
  10745. my $macro = shift;
  10746. my $args = shift;
  10747. my $style_stack = shift;
  10748. my $state = shift;
  10749. my $line_nr = shift;
  10750. my $result = '';
  10751. my @args = @$args;
  10752. my $j;
  10753. for ($j = 0; $j <= $#$args; $j++)
  10754. {
  10755. $args[$j] = normalise_texi_space($args[$j]);
  10756. # print STDERR " ($j)$args[$j]\n";
  10757. }
  10758. #print STDERR "DO_XREF: $macro\n";
  10759. if ($macro eq 'inforef')
  10760. {
  10761. if ((@args < 1) or $args[0] eq '')
  10762. {
  10763. line_error (sprintf(__("First argument to \@%s may not be empty"), $macro), $line_nr);
  10764. return '';
  10765. }
  10766. }
  10767. my $node_texi = $args[0];
  10768. $node_texi = normalise_node($node_texi);
  10769. #print STDERR "XREF: (@args)\n";
  10770. my $i;
  10771. my $new_state = duplicate_formatting_state($state);
  10772. $new_state->{'keep_texi'} = 0;
  10773. $new_state->{'keep_nr'} = 0;
  10774. my $remove_texi = $new_state->{'remove_texi'};
  10775. my @formatted_args;
  10776. for ($i = 0; $i < 5; $i++)
  10777. {
  10778. $args[$i] = '' if (!defined($args[$i]));
  10779. my $in_file_style;
  10780. $in_file_style = 1 if ($i == 2 and $macro eq 'inforef' or $i == 3 and $macro ne 'inforef');
  10781. $new_state->{'code_style'}++ if ($in_file_style or $i == 0);
  10782. $new_state->{'remove_texi'} = 1 if ($in_file_style);
  10783. $formatted_args[$i] = substitute_line($args[$i], sprintf(__("\@%s (argument nr %d)"), $macro, $i), $new_state, $line_nr);
  10784. $new_state->{'code_style'}-- if ($in_file_style or $i == 0);
  10785. $new_state->{'remove_texi'} = $remove_texi if ($in_file_style);
  10786. }
  10787. my ($file_texi, $file);
  10788. if ($macro eq 'inforef')
  10789. {
  10790. $file_texi = $args[2];
  10791. $file = $formatted_args[2];
  10792. }
  10793. else
  10794. {
  10795. $file_texi = $args[3];
  10796. $file = $formatted_args[3];
  10797. }
  10798. # Remark: makeinfo has this odd error message if the file is empty:
  10799. # warning (_("Empty file name for HTML cross reference in `%s'")
  10800. # This seems to be spurious.
  10801. # can be an argument or extracted from the node name
  10802. my $file_arg_or_node_texi = $file_texi;
  10803. my $file_arg_or_node = $file;
  10804. my $node_name;
  10805. # the file in parenthesis is removed from node_without_file_texi if needed
  10806. my $node_without_file_texi = $node_texi;
  10807. # node with file, like (file)node
  10808. my $node_and_file_texi;
  10809. # the file in parenthesis present with the node
  10810. my ($file_of_node_texi, $file_of_node);
  10811. if ($node_without_file_texi =~ s/^\(([^\)]+)\)\s*//)
  10812. {
  10813. $file_of_node_texi = $1;
  10814. $file_of_node = substitute_line($file_of_node_texi, sprintf(__p("\@*ref", "\@%s node file"), $macro), $new_state);
  10815. $node_name = substitute_line($node_without_file_texi, sprintf(__p("\@*ref", "\@%s node name"), $macro), $new_state);
  10816. $file_arg_or_node_texi = $file_of_node_texi if ($file_arg_or_node_texi eq '');
  10817. $file_arg_or_node = $file_of_node if ($file_arg_or_node eq '');
  10818. # the file argument takes precedence
  10819. $node_and_file_texi = "($file_arg_or_node_texi)$node_without_file_texi";
  10820. }
  10821. else
  10822. {
  10823. # normalized node name
  10824. $new_state->{'code_style'}++;
  10825. $node_name = substitute_line($node_without_file_texi, sprintf(__p("\@*ref", "\@%s node name"), $macro), $new_state);
  10826. $new_state->{'code_style'}--;
  10827. if (defined ($file_texi) and $file_texi ne '')
  10828. {
  10829. $node_and_file_texi = "($file_texi)$node_texi";
  10830. }
  10831. }
  10832. my $node_and_file;
  10833. if (defined($node_and_file_texi))
  10834. {
  10835. $node_and_file = substitute_line($node_and_file_texi, sprintf(__p("\@*ref","\@%s node with file name"), $macro), $new_state);
  10836. }
  10837. else
  10838. {
  10839. $node_and_file_texi = $node_texi;
  10840. $node_and_file = $node_name;
  10841. }
  10842. my $cross_ref_texi = $args[1];
  10843. my $cross_ref = $formatted_args[1];
  10844. my ($manual_texi, $section_texi, $manual, $section);
  10845. if ($macro ne 'inforef')
  10846. {
  10847. $manual_texi = $args[4];
  10848. $section_texi = $args[2];
  10849. $manual = $formatted_args[4];
  10850. $section = $formatted_args[2];
  10851. }
  10852. else
  10853. {
  10854. $manual = $section = '';
  10855. }
  10856. #print STDERR "XREF: (@args)\n";
  10857. if (($macro eq 'inforef') or ($file_arg_or_node_texi ne '') or ($manual_texi ne ''))
  10858. {# external ref
  10859. my $href = '';
  10860. if ($file_arg_or_node_texi ne '')
  10861. {
  10862. $href = do_external_href($node_and_file_texi);
  10863. }
  10864. else
  10865. {
  10866. $node_and_file = '';
  10867. }
  10868. #$result = &$Texi2HTML::Config::external_ref($macro, $section_or_node, $manual, $node_and_file, $href, $cross_ref, \@args, \@formatted_args);
  10869. $result = &$Texi2HTML::Config::external_ref($macro, $section, $manual, $file_arg_or_node, $href, $cross_ref, \@args, \@formatted_args, $node_name);
  10870. }
  10871. else
  10872. {
  10873. my $element = $nodes{$node_without_file_texi};
  10874. if ($element and $element->{'seen'})
  10875. {
  10876. if ($element->{'reference_element'})
  10877. {
  10878. $element = $element->{'reference_element'};
  10879. }
  10880. my $file = '';
  10881. if (defined($state->{'element'}))
  10882. {
  10883. $file = $state->{'element'}->{'file'};
  10884. }
  10885. else
  10886. {
  10887. line_warn (sprintf(__("\@%s not in text (in anchor, node, section...)"), $macro), $line_nr);
  10888. # if SPLIT the file is '' which ensures
  10889. # a href with the file name. if ! SPLIT
  10890. # the 2 file will be the same thus there won't be the file name
  10891. $file = $element->{'file'} unless (get_conf('SPLIT'));
  10892. }
  10893. #print STDERR "SUBHREF in ref to node `$node_texi'";
  10894. my $href = href($element, $file, $line_nr);
  10895. my $section_or_cross_ref = $section;
  10896. $section_or_cross_ref = $cross_ref if ($section eq '');
  10897. if ($element->{'float'} and $section_or_cross_ref eq '')
  10898. {
  10899. my $style = substitute_line(&$Texi2HTML::Config::listoffloats_float_style($element->{'style_texi'}, $element), __("\@listoffloats \@float type"));
  10900. $section_or_cross_ref = $style if (defined($style));
  10901. }
  10902. my $name = $section_or_cross_ref;
  10903. my $short_name = $section_or_cross_ref;
  10904. if ($section_or_cross_ref eq '')
  10905. {
  10906. # FIXME maybe one should use 'text' instead of 'text_nonumber'
  10907. # However the real fix would be to have an internal_ref call
  10908. # with more informations
  10909. $name = $element->{'text_nonumber'};
  10910. $short_name = $node_name;
  10911. }
  10912. $result = &$Texi2HTML::Config::internal_ref ($macro, $href, $short_name, $name, $element->{'section'}, \@args, \@formatted_args, $element);
  10913. }
  10914. else
  10915. {
  10916. if (($node_texi eq '') or (! Texi2HTML::Config::get_conf('novalidate')))
  10917. {
  10918. line_error (sprintf(__("\@%s reference to nonexistent node `%s'"), $macro, $node_texi), $line_nr);
  10919. my $text = '';
  10920. for (my $i = 0; $i < @$args -1; $i++)
  10921. {
  10922. $text .= $args->[$i] .',';
  10923. }
  10924. $text .= $args->[-1];
  10925. $result = "\@$macro"."{${text}}";
  10926. }
  10927. else
  10928. {
  10929. #$result = &$Texi2HTML::Config::external_ref($macro, '', '', $node_name, do_external_href($node_texi), $cross_ref, \@args, \@formatted_args);
  10930. $result = &$Texi2HTML::Config::external_ref($macro, '', '', '', do_external_href($node_texi), $cross_ref, \@args, \@formatted_args, $node_name);
  10931. }
  10932. }
  10933. }
  10934. return $result;
  10935. }
  10936. sub do_acronym_like($$$$$)
  10937. {
  10938. my $command = shift;
  10939. my $args = shift;
  10940. my $acronym_texi = shift @$args;
  10941. my $explanation = shift @$args;
  10942. my $style_stack = shift;
  10943. my $state = shift;
  10944. my $line_nr = shift;
  10945. my $explanation_lines;
  10946. my $explanation_text;
  10947. my $explanation_simple_format;
  10948. if (defined($explanation))
  10949. {
  10950. $explanation = trim_around_spaces($explanation);
  10951. $explanation = undef if ($explanation eq '');
  10952. }
  10953. $acronym_texi = trim_around_spaces($acronym_texi);
  10954. return '' if ($acronym_texi eq '');
  10955. my $with_explanation = 0;
  10956. my $normalized_text = cross_manual_line(normalise_node($acronym_texi));
  10957. if (defined($explanation))
  10958. {
  10959. $with_explanation = 1;
  10960. $acronyms_like{$command}->{$normalized_text} = $explanation;
  10961. }
  10962. elsif (exists($acronyms_like{$command}->{$normalized_text}))
  10963. {
  10964. $explanation = $acronyms_like{$command}->{$normalized_text};
  10965. }
  10966. if (defined($explanation))
  10967. {
  10968. @$explanation_lines = map {$_ = $_."\n"} split (/\n/, $explanation);
  10969. my $text = '';
  10970. foreach my $line(@$explanation_lines)
  10971. {
  10972. $line .= ' ' if (chomp ($line));
  10973. $text .= $line
  10974. }
  10975. $text =~ s/ $//;
  10976. $explanation_simple_format = simple_format($state, [ $line_nr ], "simple_format \@$command explanation", $text);
  10977. $explanation_text = substitute_line($text, sprintf(__p("\@abbr or \@acronym", "\@%s explanation"), $command), duplicate_formatting_state($state), $line_nr);
  10978. }
  10979. return &$Texi2HTML::Config::acronym_like($command, $acronym_texi, substitute_line($acronym_texi, "\@$command", duplicate_formatting_state($state), $line_nr),
  10980. $with_explanation, $explanation_lines, $explanation_text, $explanation_simple_format);
  10981. }
  10982. sub do_caption_shortcaption($$$$$$)
  10983. {
  10984. my $command = shift;
  10985. my $args = shift;
  10986. my $text_texi = $args->[0];
  10987. my $style_stack = shift;
  10988. my $state = shift;
  10989. my $line_nr = shift;
  10990. my $kept_line_nrs = shift;
  10991. if (!exists($state->{'float'}))
  10992. {
  10993. line_error(sprintf(__("\@%s not meaningful outside `\@float' environment"), $command), $line_nr);
  10994. return '';
  10995. }
  10996. my $float = $state->{'float'};
  10997. my @texi_lines = map {$_ = $_."\n"} split (/\n/, $text_texi);
  10998. $float->{"${command}_texi"} = \@texi_lines;
  10999. if (defined($kept_line_nrs))
  11000. {
  11001. $float->{"${command}_keep_line_nr"} = [ @$kept_line_nrs ];
  11002. msg_debug ("Empty $kept_line_nrs", $line_nr) unless (@{$kept_line_nrs});
  11003. }
  11004. else
  11005. {
  11006. $float->{"${command}_keep_line_nr"} = [ $line_nr ];
  11007. msg_debug("do_caption_shortcaption $command, $float, kept_line_nrs not defined", $line_nr);
  11008. }
  11009. #print STDERR "GGGGGGG @$kept_line_nrs\n";
  11010. return &$Texi2HTML::Config::caption_shortcaption_command($command,
  11011. substitute_text(prepare_state_multiple_pass($command, $state), $kept_line_nrs, "\@$command in do_caption_shortcaption", @texi_lines), \@texi_lines, $float);
  11012. }
  11013. # function called when a @float is encountered. Don't do any output
  11014. # but prepare $state->{'float'}
  11015. sub do_float_line($$$$$)
  11016. {
  11017. my $command = shift;
  11018. my $args = shift;
  11019. my $style_stack = shift;
  11020. my $state = shift;
  11021. my $line_nr = shift;
  11022. my @args = @$args;
  11023. my $style_texi = shift @args;
  11024. my $label_texi = shift @args;
  11025. $style_texi = undef if (defined($style_texi) and $style_texi=~/^\s*$/);
  11026. $label_texi = undef if (defined($label_texi) and $label_texi=~/^\s*$/);
  11027. $style_texi = normalise_texi_space($style_texi) if (defined($style_texi));
  11028. if (defined($label_texi))
  11029. { # the float is considered as a node as it may be a target for refs.
  11030. # it was entered as a node in the pass_structure and the float
  11031. # line was parsed at that time
  11032. $state->{'float'} = $nodes{normalise_node($label_texi)};
  11033. #msg_debug("float: $state->{'float'}, $state->{'float'}->{'texi'}", $line_nr);
  11034. }
  11035. else
  11036. { # a float without label. It can't be the target for refs.
  11037. $state->{'float'} = { 'float' => 1 };
  11038. if (defined($style_texi))
  11039. {
  11040. $state->{'float'}->{'style_texi'} = $style_texi;
  11041. $state->{'float'}->{'style_id'} =
  11042. cross_manual_line($state->{'float'}->{'style_texi'});
  11043. }
  11044. #print STDERR "float: (no label) $state->{'float'}\n";
  11045. }
  11046. $state->{'float'}->{'style'} = substitute_line($state->{'float'}->{'style_texi'}, __("\@float style"), undef, $line_nr);
  11047. return '';
  11048. }
  11049. sub do_quotation_line($$$$$$)
  11050. {
  11051. my $command = shift;
  11052. my $format_ref = shift;
  11053. my $args = shift;
  11054. my @args = @$args;
  11055. my $text_texi = shift @args;
  11056. my $style_stack = shift;
  11057. my $state = shift;
  11058. my $line_nr = shift;
  11059. my $text;
  11060. $text_texi = undef if (defined($text_texi) and $text_texi=~ /^\s*$/);
  11061. if (defined($text_texi))
  11062. {
  11063. $text_texi = trim_around_spaces($text_texi);
  11064. $text = substitute_line($text_texi, sprintf(__p("\@*quotation", "\@%s argument"), $command), duplicate_formatting_state($state), $line_nr);
  11065. #$text =~ s/\s*$//;
  11066. }
  11067. my $quotation_args = { 'text' => $text, 'text_texi' => $text_texi };
  11068. push @{$state->{'quotation_stack'}}, $quotation_args;
  11069. $format_ref->{'argument_text'} = $text;
  11070. $format_ref->{'argument_texi'} = $text_texi;
  11071. $state->{'prepend_text'} = &$Texi2HTML::Config::quotation_prepend_text($command, $text_texi);
  11072. return '';
  11073. }
  11074. sub do_footnote($$$$$$)
  11075. {
  11076. my $command = shift;
  11077. my $args = shift;
  11078. my $text = $args->[0];
  11079. my $style_stack = shift;
  11080. my $doc_state = shift;
  11081. my $line_nr = shift;
  11082. my $kept_line_nrs = shift;
  11083. $text .= "\n";
  11084. $text = &$Texi2HTML::Config::footnote_texi($text, $doc_state, $style_stack)
  11085. if (defined($Texi2HTML::Config::footnote_texi));
  11086. my $foot_state = duplicate_state($doc_state);
  11087. fill_state($foot_state);
  11088. push @{$foot_state->{'command_stack'}}, 'footnote';
  11089. push_state($foot_state);
  11090. my ($foot_num, $relative_foot_num);
  11091. my $special_place;
  11092. if (!defined($foot_state->{'expansion'}) and !defined($foot_state->{'region'}))
  11093. {
  11094. $foot_num = \$global_foot_num;
  11095. $relative_foot_num = \$global_relative_foot_num;
  11096. }
  11097. else
  11098. {
  11099. $special_place = $foot_state->{'expansion'};
  11100. $special_place = $foot_state->{'region'} if (!defined($special_place));
  11101. $foot_num = \$doc_state->{'foot_num'};
  11102. $relative_foot_num = \$doc_state->{'relative_foot_num'};
  11103. }
  11104. $$foot_num++;
  11105. $$relative_foot_num++;
  11106. my $docid = "DOCF$$foot_num";
  11107. my $footid = "FOOT$$foot_num";
  11108. if (defined($special_place))
  11109. {
  11110. $docid = $target_prefix . $special_place . "_$docid";
  11111. $footid = $target_prefix . $special_place . "_$footid";
  11112. }
  11113. my $from_file = $docu_doc;
  11114. if ($doc_state->{'element'})
  11115. {
  11116. $from_file = $doc_state->{'element'}->{'file'};
  11117. }
  11118. if (get_conf('footnotestyle') eq 'separate')
  11119. {
  11120. $foot_state->{'element'} = $footnote_element;
  11121. }
  11122. $foot_state->{'footnote_number_in_doc'} = $$foot_num;
  11123. $foot_state->{'footnote_number_in_page'} = $$relative_foot_num;
  11124. $foot_state->{'footnote_footnote_id'} = $footid;
  11125. $foot_state->{'footnote_place_id'} = $docid;
  11126. $foot_state->{'footnote_document_file'} = $from_file;
  11127. $foot_state->{'footnote_footnote_file'} = $foot_state->{'element'}->{'file'};
  11128. $foot_state->{'footnote_document_state'} = $doc_state;
  11129. # FIXME use split_lines ? It seems to work like it is now ?
  11130. msg_debug ("No line nnumbers in footnote", $line_nr) if (!defined($kept_line_nrs) or !@$kept_line_nrs);
  11131. my @lines;
  11132. if (defined($text))
  11133. {
  11134. @lines = substitute_text($foot_state, $kept_line_nrs, '@footnote', map {$_ = $_."\n"} split (/\n/, $text));
  11135. }
  11136. my ($foot_lines, $foot_label) = &$Texi2HTML::Config::foot_line_and_ref($$foot_num,
  11137. $$relative_foot_num, $footid, $docid, $from_file, $foot_state->{'element'}->{'file'}, \@lines, $doc_state);
  11138. if ($doc_state->{'outside_document'} or (defined($doc_state->{'multiple_pass'}) and $doc_state->{'multiple_pass'} > 0))
  11139. {
  11140. #print STDERR "multiple_pass $doc_state->{'multiple_pass'}, 'outside_document' $doc_state->{'outside_document'}\n";
  11141. #print STDERR "REGION FOOTNOTE($$foot_num): $doc_state->{'region'} ($doc_state->{'region_pass'})\n";
  11142. $region_initial_state{$doc_state->{'region'}}->{'footnotes'}->{$$foot_num}->{$doc_state->{'region_pass'}} = $foot_lines if (defined($doc_state->{'region'}));
  11143. }
  11144. else
  11145. {
  11146. #print STDERR "GLOBAL FOOTNOTE($$foot_num)\n";
  11147. push(@foot_lines, @{$foot_lines});
  11148. }
  11149. pop_state();
  11150. return $foot_label;
  11151. }
  11152. sub do_image($$$$$)
  11153. {
  11154. # replace images
  11155. my $command = shift;
  11156. my $args = shift;
  11157. my $style_stack = shift;
  11158. my $state = shift;
  11159. my $line_nr = shift;
  11160. my @args;
  11161. foreach my $arg (@$args)
  11162. {
  11163. $arg = trim_around_spaces($arg) if (defined($arg));
  11164. push @args, $arg;
  11165. }
  11166. my $base = substitute_line($args[0], __("\@image base name"),{'code_style' => 1, 'remove_texi' => 1});
  11167. my $base_simple = substitute_line($args[0], __("\@image base name"), {'simple_format' => 1, 'code_style' => 1});
  11168. if ($base eq '')
  11169. {
  11170. line_error ("\@image missing filename argument", $line_nr);
  11171. return '';
  11172. }
  11173. $args[4] = '' if (!defined($args[4]));
  11174. $args[3] = '' if (!defined($args[3]));
  11175. my $image;
  11176. my $extension = substitute_line($args[4], __("\@image extension"), {'code_style' => 1, 'remove_texi' => 1});
  11177. my $extension_simple = substitute_line($args[4], __("\@image extension"), {'simple_format' => 1, 'code_style' => 1});
  11178. my ($file_name, $image_name, $simple_file_name);
  11179. my @file_locations;
  11180. my @file_names = &$Texi2HTML::Config::image_files($base,$extension,$args[0],$args[4]);
  11181. # $image = locate_include_file("$base.$args[4]") if ($args[4] ne '');
  11182. foreach my $file (@file_names)
  11183. {
  11184. my $simple_file = substitute_line($file->[1], __("\@image file name"), {'simple_format' => 1, 'code_style' => 1});
  11185. if ($image = locate_include_file($file->[0]))
  11186. {
  11187. if (!defined($file_name))
  11188. {
  11189. $file_name = $file->[0];
  11190. $image_name = $image;
  11191. $simple_file_name = $simple_file;
  11192. }
  11193. push @file_locations, [$file, $image, $simple_file];
  11194. }
  11195. else
  11196. {
  11197. push @file_locations, [$file, undef, $simple_file];
  11198. }
  11199. }
  11200. $image_name = '' if (!defined($image_name));
  11201. $simple_file_name = '' if (!defined($simple_file_name));
  11202. my $alt;
  11203. if ($args[3] =~ /\S/)
  11204. {
  11205. $alt = substitute_line($args[3], __("\@image alt text"), {'simple_format' => 1}, $line_nr);
  11206. }
  11207. return &$Texi2HTML::Config::image($path_to_working_dir . $image_name,
  11208. $base,
  11209. $state->{'preformatted'}, $file_name, $alt, $args[1], $args[2],
  11210. $args[3], $extension, $path_to_working_dir, $image_name,
  11211. $state->{'paragraph_context'}, \@file_locations, $base_simple,
  11212. $extension_simple, $simple_file_name, $line_nr);
  11213. }
  11214. # usefull if we want to duplicate only the global state, nothing related with
  11215. # formatting
  11216. sub duplicate_state($)
  11217. {
  11218. my $state = shift;
  11219. my $new_state = { 'element' => $state->{'element'},
  11220. 'multiple_pass' => $state->{'multiple_pass'},
  11221. 'region_pass' => $state->{'region_pass'},
  11222. 'region' => $state->{'region'},
  11223. 'expansion' => $state->{'expansion'},
  11224. 'sec_num' => $state->{'sec_num'},
  11225. 'outside_document' => $state->{'outside_document'},
  11226. 'inside_document' => $state->{'inside_document'},
  11227. 'duplicated' => 1
  11228. };
  11229. return $new_state;
  11230. }
  11231. # duplicate global and formatting state.
  11232. sub duplicate_formatting_state($)
  11233. {
  11234. my $state = shift;
  11235. my $new_state = duplicate_state($state);
  11236. # Things passed here should be things that are not emptied/set to 0 by
  11237. # any command. Also they shouldn't need anything to be on the
  11238. # stack. This rules out paragraphs, for example.
  11239. foreach my $format_key ('preformatted', 'code_style', 'keep_texi',
  11240. 'keep_nr', 'preformatted_stack')
  11241. {
  11242. $new_state->{$format_key} = $state->{$format_key};
  11243. }
  11244. # this is needed for preformatted
  11245. my $command_stack = $state->{'command_stack'};
  11246. $command_stack = [] if (!defined($command_stack));
  11247. $new_state->{'command_stack'} = [ @$command_stack ];
  11248. $new_state->{'preformatted_context'} = {'stack_at_beginning' => [ @$command_stack ]};
  11249. $new_state->{'code_style'} = 0 if (!defined($new_state->{'code_style'}));
  11250. return $new_state;
  11251. }
  11252. sub expand_macro($$$$$)
  11253. {
  11254. my $name = shift;
  11255. my $args = shift;
  11256. my $end_line = shift;
  11257. my $line_nr = shift;
  11258. my $state = shift;
  11259. # we dont expand macros when in ignored environment.
  11260. return if ($state->{'ignored'});
  11261. die "Bug end_line not defined" if (!defined($end_line));
  11262. my $index = 0;
  11263. foreach my $arg (@$args)
  11264. { # expand @macros in arguments. It is complicated because we must be
  11265. # carefull not to expand macros in @ignore section or the like, and
  11266. # still keep every single piece of text (including the @ignore macros).
  11267. $args->[$index] = substitute_text({'texi' => 1, 'arg_expansion' => 1}, undef, "expand_macro in $name", split_lines($arg));
  11268. $index++;
  11269. }
  11270. # retrieve the macro definition
  11271. my $macrobody = $macros->{$name}->{'body'};
  11272. my $formal_args = $macros->{$name}->{'args'};
  11273. my $args_index = $macros->{$name}->{'args_index'};
  11274. my $i;
  11275. for ($i=0; $i<=$#$formal_args; $i++)
  11276. {
  11277. $args->[$i] = "" unless (defined($args->[$i]));
  11278. print STDERR "# arg($i): $args->[$i]\n" if ($T2H_DEBUG & $DEBUG_MACROS);
  11279. }
  11280. line_error (sprintf(__("Macro `%s' called with too many args"), $name), $line_nr) if (defined($args->[$i + 1]));
  11281. my $result = '';
  11282. while ($macrobody ne '')
  11283. {
  11284. if ($macrobody =~ s/^([^\\]*)\\//o)
  11285. {
  11286. $result .= $1 if defined($1);
  11287. if ($macrobody =~ s/^\\//)
  11288. {
  11289. $result .= '\\';
  11290. }
  11291. elsif ($macrobody =~ s/^(\@end\sr?macro)$// or $macrobody =~ s/^(\@end\sr?macro\s)// or $macrobody =~ s/^(\@r?macro\s+\w+\s*.*)//)
  11292. { # \ protect @end macro
  11293. $result .= $1;
  11294. }
  11295. elsif ($macrobody =~ s/^([^\\]*)\\//)
  11296. {
  11297. my $arg = $1;
  11298. if (defined($args_index->{$arg}))
  11299. {
  11300. $result .= $args->[$args_index->{$arg}];
  11301. }
  11302. else
  11303. {
  11304. line_error (sprintf(__("\\ in macro expansion followed `%s' instead of parameter name or \\"), $arg), $macros->{$name}->{'line_nr'});
  11305. $result .= '\\' . $arg;
  11306. }
  11307. }
  11308. next;
  11309. }
  11310. $result .= $macrobody;
  11311. last;
  11312. }
  11313. my @result = split(/^/m, $result);
  11314. # for a completly empty macro, $result = '', and the split leads
  11315. # to an empty array, so add back an empty string
  11316. @result = ('') if (!scalar(@result));
  11317. # Add the result of the macro expansion back to the input_spool.
  11318. # Set the macro name if in the outer macro
  11319. if ($state->{'arg_expansion'})
  11320. { # in that case we are in substitute_text for an arg
  11321. unshift @{$state->{'spool'}}, (@result, $end_line);
  11322. }
  11323. else
  11324. {
  11325. #$result[-1].=$end_line;
  11326. #foreach my $res (@result)
  11327. #{
  11328. # print STDERR "RESULT:$res";
  11329. #}
  11330. #print STDERR "#########end->$end_line";
  11331. my $last_line = $result[-1];
  11332. if (chomp($last_line))
  11333. {
  11334. push @result, $end_line;
  11335. }
  11336. else
  11337. {
  11338. $result[-1] .= $end_line;
  11339. }
  11340. unshift @{$state->{'input_spool'}->{'spool'}}, (@result); #, $end_line);
  11341. $state->{'input_spool'}->{'macro'} = $name if ($state->{'input_spool'}->{'macro'} eq '');
  11342. }
  11343. if ($T2H_DEBUG & $DEBUG_MACROS)
  11344. {
  11345. print STDERR "# macro expansion result:\n";
  11346. #print STDERR "$first_line";
  11347. foreach my $line (@result)
  11348. {
  11349. print STDERR "$line";
  11350. }
  11351. print STDERR "# macro expansion result end\n";
  11352. }
  11353. }
  11354. sub do_index_summary_file($$)
  11355. {
  11356. my $name = shift;
  11357. my $docu_name = shift;
  11358. &$Texi2HTML::Config::index_summary_file_begin ($name, $printed_indices{$name}, $docu_name);
  11359. print STDERR "# writing $name index summary for $docu_name\n" if $T2H_VERBOSE;
  11360. foreach my $letter_entries (@{$Texi2HTML::THISDOC{'index_letters_array'}->{$name}})
  11361. {
  11362. #print STDERR "$name: $letter_entries->{'letter'}\n";
  11363. foreach my $entry (@{$letter_entries->{'entries'}})
  11364. {
  11365. #my $entry = $entries->{$key};
  11366. my $indexed_element = $entry->{'element'};
  11367. my $entry_element = $indexed_element;
  11368. $entry_element = $entry_element->{'element_ref'} if (defined($entry_element->{'element_ref'}));
  11369. my $origin_href = $entry->{'file'};
  11370. #print STDERR "$entry $entry->{'entry'}, real elem $indexed_element->{'texi'}, section $entry_element->{'texi'}, real $indexed_element->{'file'}, entry file $entry->{'file'}\n";
  11371. if ($entry->{'target'})
  11372. {
  11373. $origin_href .= '#' . $entry->{'target'};
  11374. }
  11375. else
  11376. {
  11377. $origin_href .= '#' . $indexed_element->{'target'};
  11378. }
  11379. &$Texi2HTML::Config::index_summary_file_entry ($name,
  11380. $entry->{'key'}, $origin_href,
  11381. substitute_line($entry->{'entry'}, "\@$entry->{'command'}"), $entry->{'entry'},
  11382. href($entry_element, ''),
  11383. $entry_element->{'text'},
  11384. $printed_indices{$name},
  11385. $docu_name);
  11386. }
  11387. }
  11388. &$Texi2HTML::Config::index_summary_file_end ($name, $printed_indices{$name}, $docu_name);
  11389. }
  11390. sub get_index_entry_infos($$;$)
  11391. {
  11392. my $entry = shift;
  11393. my $element = shift;
  11394. my $line_nr = shift;
  11395. my $index_heading_element = $entry->{'element'};
  11396. my $entry_heading_element = $index_heading_element;
  11397. my $real_index_element = $entry->{'real_element'};
  11398. if (!defined($entry->{'real_element'}))
  11399. {
  11400. print STDERR "BUG: entry->{'real_element'} not defined\n";
  11401. }
  11402. # we always use the associated element_ref, instead of the original
  11403. # element
  11404. $entry_heading_element = $entry_heading_element->{'element_ref'}
  11405. if (defined($entry_heading_element->{'element_ref'}));
  11406. if ($entry->{'real_element'} eq $element_before_anything)
  11407. {
  11408. $real_index_element = $element_top;
  11409. }
  11410. else
  11411. {
  11412. $real_index_element = $entry->{'real_element'}->{'element_ref'};
  11413. if (!defined($real_index_element))
  11414. { # happens when $USE_NODES = 0 and there are only sections,
  11415. # and vice-versa
  11416. $real_index_element = $entry->{'real_element'};
  11417. }
  11418. }
  11419. my $origin_href = '';
  11420. print STDERR "BUG: entry->{'file'} not defined for `$entry->{'entry'}'\n"
  11421. if (!defined($entry->{'file'}));
  11422. print STDERR "BUG: element->{'file'} not defined for `$entry->{'entry'}', `$element->{'texi'}'\n"
  11423. if (!defined($element->{'file'}));
  11424. $origin_href = $entry->{'file'} if ($entry->{'file'} ne $element->{'file'});
  11425. #print STDERR "$entry $entry->{'entry'}, real heading elem $index_heading_element->{'texi'}, section $entry_element->{'texi'}, real $index_heading_element->{'file'}, entry file $entry->{'file'}\n";
  11426. if (defined($entry->{'target'}))
  11427. {
  11428. $origin_href .= '#' . $entry->{'target'};
  11429. }
  11430. else
  11431. { # this means that the index entry is in a special region like @copying...
  11432. $origin_href .= '#' . $index_heading_element->{'target'};
  11433. }
  11434. #print STDERR "SUBHREF in index entry `$entry->{'entry'}' for `$entry_element->{'texi'}'\n";
  11435. return ($origin_href,
  11436. $entry->{'file'},
  11437. $element->{'file'},
  11438. $entry->{'target'},
  11439. $index_heading_element->{'target'},
  11440. substitute_line($entry->{'entry'}, "\@$entry->{'command'} index infos"),
  11441. href($entry_heading_element, $element->{'file'}, $line_nr),
  11442. $entry_heading_element->{'text'},
  11443. (!$entry->{'seen_in_output'} and defined($entry->{'region'})));
  11444. }
  11445. # remove texi commands, replacing with what seems adequate. see simple_map_texi
  11446. # and texi_map.
  11447. # Doesn't protect html
  11448. sub remove_texi(@)
  11449. {
  11450. return substitute_text ({ 'remove_texi' => 1}, undef, undef, @_);
  11451. }
  11452. # Same as remove texi but protect text and use special maps for @-commands
  11453. sub simple_format($$$@)
  11454. {
  11455. my $state = shift;
  11456. my $line_nrs = shift;
  11457. my $context = shift;
  11458. if (!defined($state))
  11459. {
  11460. $state = {};
  11461. }
  11462. else
  11463. {
  11464. $state = duplicate_formatting_state($state);
  11465. }
  11466. $state->{'remove_texi'} = 1;
  11467. $state->{'simple_format'} = 1;
  11468. $::simple_map_texi_ref = \%Texi2HTML::Config::simple_format_simple_map_texi;
  11469. $::style_map_texi_ref = \%Texi2HTML::Config::simple_format_style_map_texi;
  11470. $::texi_map_ref = \%Texi2HTML::Config::simple_format_texi_map;
  11471. my $text = substitute_text($state, $line_nrs, $context, @_);
  11472. $::simple_map_texi_ref = \%Texi2HTML::Config::simple_map_texi;
  11473. $::style_map_texi_ref = \%Texi2HTML::Config::style_map_texi;
  11474. $::texi_map_ref = \%Texi2HTML::Config::texi_map;
  11475. return $text;
  11476. }
  11477. sub index_entry_command_prefix($$$)
  11478. {
  11479. my $command = shift;
  11480. my $line = shift;
  11481. my $line_nr = shift;
  11482. if ($command =~ /^(v|f)table$/)
  11483. {
  11484. return $1;
  11485. }
  11486. elsif (defined($Texi2HTML::Config::def_map{$command}))
  11487. {
  11488. my ($prefix, $entry, $argument) = get_deff_index($command, $line, undef, 0);
  11489. return $prefix;
  11490. }
  11491. my $prefix = index_command_prefix($command);
  11492. line_error(sprintf(__("No index prefix found for \@%s"),$command),$line_nr) if ($prefix eq '');
  11493. return $prefix;
  11494. }
  11495. sub enter_table_index_entry($$$$)
  11496. {
  11497. my $text = shift;
  11498. my $stack = shift;
  11499. my $state = shift;
  11500. my $line_nr = shift;
  11501. if ($state->{'item'})
  11502. {
  11503. my $item_command = $state->{'item'};
  11504. delete $state->{'item'};
  11505. my $item = pop @$stack;
  11506. if ($state->{'table_stack'}->[-1] =~ /^(v|f)table$/)
  11507. {
  11508. my $index = $1;
  11509. enter_index_entry($index, $line_nr,
  11510. $item->{'text'}, $state->{'table_stack'}->[-1], $state);
  11511. }
  11512. add_prev($text, $stack, "\@$item_command" . $item->{'text'});
  11513. }
  11514. }
  11515. sub end_macro($$$)
  11516. {
  11517. my $state = shift;
  11518. my $end_string = shift;
  11519. my $remaining_on_the_line = shift;
  11520. $state->{'macro_inside'}--;
  11521. return (0, undef) if ($state->{'ignored'});
  11522. if ($state->{'macro_inside'})
  11523. {
  11524. $state->{'macro'}->{'body'} .= $end_string;
  11525. return (0, undef);
  11526. }
  11527. my $macro_text = $state->{'macro'}->{'header'} . $state->{'macro'}->{'body'}.$end_string;
  11528. chomp $state->{'macro'}->{'body'};
  11529. print STDERR "# end macro def. Body:\n$state->{'macro'}->{'body'}"
  11530. if ($T2H_DEBUG & $DEBUG_MACROS);
  11531. $macros->{$state->{'macro'}->{'name'}} = $state->{'macro'} unless ($state->{'arg_expansion'});
  11532. delete $state->{'macro'};
  11533. return (1, $macro_text.$remaining_on_the_line) if ($remaining_on_the_line =~ /^\s*$/);
  11534. return (0, $macro_text);
  11535. }
  11536. sub close_macro_arg($$$)
  11537. {
  11538. my $state = shift;
  11539. my $current_line = shift;
  11540. my $line_nr = shift;
  11541. # balanced } ends the macro call, otherwise it is in the arg
  11542. $state->{'macro_depth'}--;
  11543. if ($state->{'macro_depth'} == 0)
  11544. {
  11545. #print STDERR "BEFORE: $current_line";
  11546. print STDERR "# expanding macro $state->{'macro_name'}\n" if ($T2H_DEBUG & $DEBUG_MACROS);
  11547. #$current_line =
  11548. expand_macro($state->{'macro_name'}, $state->{'macro_args'}, $current_line, $line_nr, $state);
  11549. delete $state->{'macro_name'};
  11550. delete $state->{'macro_depth'};
  11551. delete $state->{'macro_args'};
  11552. #print STDERR "AFTER: $current_line";
  11553. #return $current_line;
  11554. return 1;
  11555. }
  11556. else
  11557. {
  11558. print STDERR "# macro call: closing }\n" if ($T2H_DEBUG & $DEBUG_MACROS);
  11559. add_text('}', \$state->{'macro_args'}->[-1]);
  11560. return undef;
  11561. }
  11562. }
  11563. sub close_style_texi($$$$;$)
  11564. {
  11565. my $style = shift;
  11566. my $text = shift;
  11567. my $stack = shift;
  11568. my $state = shift;
  11569. my $no_close = shift;
  11570. $no_close = 0 if (!defined($no_close));
  11571. my $result;
  11572. if (!defined($style->{'style'}))
  11573. {
  11574. msg_debug("'style' not defined in close_style_texi ($no_close)");
  11575. foreach my $key (keys(%$style))
  11576. {
  11577. print STDERR " --> $key: ".var_to_str($style->{$key})."\n";
  11578. }
  11579. }
  11580. if (($style->{'style'} ne '') and exists($info_enclose{$style->{'style'}}) and !$state->{'arg_expansion'})
  11581. {
  11582. $result = $info_enclose{$style->{'style'}}->[0] . $style->{'text'} . $info_enclose{$style->{'style'}}->[1];
  11583. }
  11584. elsif ($style->{'style'} ne '')
  11585. {
  11586. $result = '@' . $style->{'style'} . '{' . $style->{'text'};
  11587. $result .= '}' unless ($no_close);
  11588. }
  11589. else
  11590. {
  11591. $result = '{' . $style->{'text'};
  11592. # don't close { if we are closing stack as we are not
  11593. # sure this is a { ... } construct. i.e. we are
  11594. # not sure that the user properly closed the matching
  11595. # brace, so we don't close it ourselves
  11596. $result .= '}' unless ($no_close or $state->{'arg_expansion'});
  11597. }
  11598. if ($state->{'ignored'})
  11599. {# ARG_EXPANSION
  11600. print STDERR "# Popped `$style->{'style'}' in ifset/ifclear\n" if ($T2H_DEBUG);
  11601. }
  11602. else
  11603. {
  11604. add_prev ($text, $stack, $result);
  11605. }
  11606. }
  11607. sub close_ignored ($$)
  11608. {
  11609. my $state = shift;
  11610. my $stack = shift;
  11611. if (($state->{'ifvalue_inside'}) and $state->{'ignored'} eq $state->{'ifvalue'})
  11612. {
  11613. if ($state->{'ifvalue_inside'} == 1)
  11614. {# closing still opened @-commands with braces
  11615. pop (@$stack) while (@$stack and $stack->[-1]->{'style'} ne 'ifvalue')
  11616. }
  11617. pop (@$stack);
  11618. $state->{'ifvalue_inside'}--;
  11619. }
  11620. $state->{'ignored'} = undef;
  11621. delete $state->{'ignored'};
  11622. # We are stil in the ignored ifset or ifclear section
  11623. $state->{'ignored'} = $state->{'ifvalue'} if ($state->{'ifvalue_inside'});
  11624. #dump_stack($text, $stack, $state);
  11625. }
  11626. # Called in 2 contexts:
  11627. # * in main document
  11628. # * from substitute_text, called in turn from arg_expansion. In that case
  11629. # 'texi' is true, and so is 'arg_expansion'. In that case constructs are
  11630. # expanded but no action is performed. Therefore $line_nr is not of use.
  11631. sub scan_texi($$$$;$)
  11632. {
  11633. my $scanned_line = shift;
  11634. my $text = shift;
  11635. my $stack = shift;
  11636. my $state = shift;
  11637. my $line_nr = shift;
  11638. die "stack not an array ref" unless (ref($stack) eq "ARRAY");
  11639. my $cline = $scanned_line;
  11640. while(1)
  11641. {
  11642. # scan_texi
  11643. #print STDERR "WHILE(t):$cline";
  11644. #print STDERR "ARG_EXPANSION: $state->{'arg_expansion'}\n" if ($state->{'arg_expansion'});
  11645. #dump_stack($text, $stack, $state);
  11646. #print STDERR "ifvalue_inside $state->{'ifvalue_inside'}\n";
  11647. # first we handle special cases:
  11648. # macro definition: $state->{'macro_inside'}
  11649. # macro arguments: $state->{'macro_name'}
  11650. # raw format: $state->{'raw'}
  11651. # @verb: $state->{'verb'}
  11652. # ignored: $state->{'ignored'}
  11653. # and then the remaining text/macros.
  11654. # in macro definition
  11655. if ($state->{'macro_inside'})
  11656. {
  11657. if ($cline =~ s/^([^\\\@]*\\)//)
  11658. {# protected character or @end macro
  11659. $state->{'macro'}->{'body'} .= $1 unless ($state->{'ignored'});
  11660. if ($cline =~ s/^\\//)
  11661. {
  11662. $state->{'macro'}->{'body'} .= '\\' unless ($state->{'ignored'});
  11663. next;
  11664. }
  11665. # I believe it is correct, although makeinfo don't do that.
  11666. elsif ($cline =~ s/^(\@end\sr?macro)$//o or $cline =~ s/^(\@end\sr?macro\s)//o
  11667. or $cline =~ s/^(\@r?macro\s+\w+\s*.*)//o)
  11668. {
  11669. $state->{'macro'}->{'body'} .= $1 unless ($state->{'ignored'});
  11670. next;
  11671. }
  11672. }
  11673. #if ($cline =~ s/^(.*?)\@end\sr?macro$//o or $cline =~ s/^(.*?)\@end\sr?macro\s+//o)
  11674. if ($cline =~ s/^(\@end\sr?macro)$//o or $cline =~ s/^(\@end\sr?macro\s+)//o)
  11675. {
  11676. my ($no_remaining, $result) = end_macro($state, $1, $cline);
  11677. add_prev ($text, $stack, $result) if (defined($result));
  11678. return 1 if ($no_remaining);
  11679. next;
  11680. }
  11681. elsif($cline =~ /^(\@r?macro\s+\w+\s*.*)/)
  11682. {
  11683. $state->{'macro'}->{'body'} .= $cline unless ($state->{'ignored'});
  11684. $state->{'macro_inside'}++;
  11685. #return;
  11686. return 1;
  11687. }
  11688. elsif ($cline =~ s/^\@(.)//)
  11689. {
  11690. $state->{'macro'}->{'body'} .= '@' . $1 unless ($state->{'ignored'});
  11691. next;
  11692. }
  11693. elsif ($cline =~ s/^\@//)
  11694. {
  11695. $state->{'macro'}->{'body'} .= '@' unless ($state->{'ignored'});
  11696. next;
  11697. }
  11698. else
  11699. {
  11700. $cline =~ s/([^\@\\]*)//;
  11701. if ($state->{'ignored'})
  11702. {
  11703. return if ($cline =~ /^$/);
  11704. next;
  11705. }
  11706. $state->{'macro'}->{'body'} .= $1 if (defined($1));
  11707. if ($cline =~ /^$/)
  11708. {
  11709. $state->{'macro'}->{'body'} .= $cline;
  11710. #return;
  11711. return 1;
  11712. }
  11713. next;
  11714. }
  11715. }
  11716. # in macro arguments parsing/expansion. Here \ { } and , if this is a
  11717. # multi args macro have a signification, the remaining is passed
  11718. # unmodified
  11719. if (defined($state->{'macro_name'}))
  11720. {
  11721. my $special_chars = quotemeta ('\{}');
  11722. my $multi_args = 0;
  11723. my $formal_args = $macros->{$state->{'macro_name'}}->{'args'};
  11724. $multi_args = 1 if ($#$formal_args >= 1);
  11725. $special_chars .= quotemeta(',') if ($multi_args);
  11726. if ($state->{'macro_args'}->[-1] eq '')
  11727. {# remove space at the very beginning
  11728. $cline =~ s/^\s*//o;
  11729. }
  11730. if ($cline =~ s/^([^$special_chars]*)([$special_chars])//)
  11731. {
  11732. $state->{'macro_args'}->[-1] .= $1 if defined($1);
  11733. # \ protects any character in macro arguments
  11734. if ($2 eq '\\')
  11735. {
  11736. print STDERR "# macro call: protected char\n" if ($T2H_DEBUG & $DEBUG_MACROS);
  11737. if ($cline =~ s/^(.)//)
  11738. {
  11739. $state->{'macro_args'}->[-1] .= $1;
  11740. }
  11741. else
  11742. {
  11743. $state->{'macro_args'}->[-1] .= '\\';
  11744. }
  11745. }
  11746. elsif ($2 eq ',')
  11747. { # in texinfo 4.8.90 a comma in braces is protected
  11748. if ($state->{'macro_depth'} > 1)
  11749. {
  11750. $state->{'macro_args'}->[-1] .= ',';
  11751. }
  11752. else
  11753. { # separate args
  11754. print STDERR "# macro call: new arg\n" if ($T2H_DEBUG & $DEBUG_MACROS);
  11755. $cline =~ s/^\s*//o;
  11756. push @{$state->{'macro_args'}}, '';
  11757. }
  11758. }
  11759. elsif ($2 eq '}')
  11760. {
  11761. #my $macro_result_line = close_macro_arg($state, $cline);
  11762. return if (close_macro_arg($state, $cline, $line_nr));
  11763. #if (defined($macro_result_line))
  11764. #{
  11765. # $cline = $macro_result_line;
  11766. # return;
  11767. #}
  11768. }
  11769. elsif ($2 eq '{')
  11770. {
  11771. print STDERR "# macro call: opening {\n" if ($T2H_DEBUG & $DEBUG_MACROS);
  11772. $state->{'macro_depth'}++;
  11773. add_text('{', \$state->{'macro_args'}->[-1]);
  11774. }
  11775. next;
  11776. }
  11777. print STDERR "# macro call: end of line\n" if ($T2H_DEBUG & $DEBUG_MACROS);
  11778. $state->{'macro_args'}->[-1] .= $cline;
  11779. return;
  11780. }
  11781. # in a raw format, verbatim, tex or html
  11782. if ($state->{'raw'})
  11783. {
  11784. my $tag = $state->{'raw'};
  11785. # debugging
  11786. if (! @$stack or ($stack->[-1]->{'style'} ne $tag))
  11787. {
  11788. print STDERR "Bug: raw or special: $tag but not on top of stack\n";
  11789. print STDERR "line: $cline";
  11790. dump_stack($text, $stack, $state);
  11791. exit 1;
  11792. }
  11793. # macro_regexp
  11794. if ($cline =~ /^(.*?)\@end\s([a-zA-Z][\w-]*)/o and ($2 eq $tag))
  11795. {
  11796. $cline =~ s/^(.*?)(\@end\s$tag)//;
  11797. # we add it even if 'ignored', it'll be discarded just below
  11798. # with the @end
  11799. add_prev ($text, $stack, $1);
  11800. my $end = $2;
  11801. my $style = pop @$stack;
  11802. # if 'arg_expansion' and 'ignored' are both true text
  11803. # is ignored.
  11804. add_prev ($text, $stack, $style->{'text'} . $end) unless ($state->{'ignored'});
  11805. delete $state->{'raw'};
  11806. next;
  11807. }
  11808. else
  11809. {# we add it even if 'ignored', it'll be discarded when there is
  11810. # the @end
  11811. add_prev ($text, $stack, $cline);
  11812. last;
  11813. }
  11814. }
  11815. # in a @verb{ .. } macro
  11816. if (defined($state->{'verb'}))
  11817. {
  11818. #dump_stack($text, $stack, $state);
  11819. my $char = quotemeta($state->{'verb'});
  11820. #print STDERR "VERB $char\n";
  11821. if ($cline =~ s/^(.*?)$char\}/\}/)
  11822. {# we add it even if 'ignored', it'll be discarded when closing
  11823. add_prev($text, $stack, $1 . $state->{'verb'});
  11824. $stack->[-1]->{'text'} = $state->{'verb'} . $stack->[-1]->{'text'};
  11825. delete $state->{'verb'};
  11826. next;
  11827. }
  11828. else
  11829. {# we add it even if 'ignored', it'll be discarded when closing
  11830. add_prev($text, $stack, $cline);
  11831. last;
  11832. }
  11833. }
  11834. # In ignored region
  11835. if ($state->{'ignored'})
  11836. {
  11837. #print STDERR "IGNORED(ifvalue($state->{'ifvalue_inside'})): $state->{'ignored'}\n";
  11838. if ($cline =~ /^.*?\@end(\s+)([a-zA-Z]\w+)/)
  11839. {
  11840. if ($2 eq $state->{'ignored'})
  11841. {
  11842. $cline =~ s/^(.*?\@end)(\s+)([a-zA-Z]\w+)//;
  11843. my $end_ignore = $1.$2.$3;
  11844. close_ignored($state, $stack);
  11845. #dump_stack($text, $stack, $state);
  11846. # MACRO_ARG => keep ignored text
  11847. if ($state->{'arg_expansion'})
  11848. {# this may not be very usefull as it'll be remove later
  11849. add_prev ($text, $stack, $end_ignore);
  11850. next;
  11851. }
  11852. return if ($cline =~ /^\s*$/o);
  11853. next;
  11854. }
  11855. }
  11856. add_prev ($text, $stack, $cline) if ($state->{'arg_expansion'});
  11857. # we could theoretically continue for ignored commands other
  11858. # than ifset or ifclear, however it isn't usefull.
  11859. return unless ($state->{'ifvalue_inside'} and ($state->{'ignored'} eq $state->{'ifvalue'}));
  11860. }
  11861. # an @end tag
  11862. # macro_regexp
  11863. if ($cline =~ s/^([^{}@]*)\@end(\s+)([a-zA-Z][\w-]*)//)
  11864. {
  11865. my $leading_text = $1;
  11866. my $space = $2;
  11867. my $end_tag = $3;
  11868. # when 'ignored' we don't open environments that aren't associated
  11869. # with ignored regions, so we don't need to close them.
  11870. next if ($state->{'ignored'});# ARG_EXPANSION
  11871. add_prev($text, $stack, $leading_text);
  11872. if (defined($state->{'text_macro_stack'})
  11873. and @{$state->{'text_macro_stack'}}
  11874. and ($end_tag eq $state->{'text_macro_stack'}->[-1]))
  11875. {
  11876. pop @{$state->{'text_macro_stack'}};
  11877. # we keep menu and titlepage for the following pass
  11878. if (($Texi2HTML::Config::texi_formats_map{$end_tag} eq 'normal') or ($region_lines{$end_tag}) or $state->{'arg_expansion'})
  11879. {
  11880. add_prev($text, $stack, "\@end${space}$end_tag");
  11881. }
  11882. else
  11883. {
  11884. #print STDERR "End $end_tag\n";
  11885. #dump_stack($text, $stack, $state);
  11886. return if ($cline =~ /^\s*$/);
  11887. }
  11888. }
  11889. elsif ($Texi2HTML::Config::texi_formats_map{$end_tag})
  11890. {
  11891. line_error (sprintf(__("Unmatched `%c%s'"), ord('@'), 'end'), $line_nr);
  11892. }
  11893. else # a format that is not handled during the first pass
  11894. {# ARG_EXPANSION
  11895. add_prev($text, $stack, "\@end${space}$end_tag");
  11896. }
  11897. next;
  11898. }
  11899. # macro_regexp
  11900. elsif ($cline =~ s/^([^{}@]*)\@(["'~\@\}\{,\.!\?\s\*\-\^`=:\|\/\\])//o or $cline =~ s/^([^{}@]*)\@([a-zA-Z][\w-]*)//o)
  11901. {# ARG_EXPANSION
  11902. add_prev($text, $stack, $1) unless $state->{'ignored'};
  11903. my $command = $2;
  11904. # FIXME: if it is an alias, it is substituted below, in the
  11905. # diverse add_prev and output of \@$command. Maybe it could be
  11906. # kept and only substituted in the last passes?
  11907. $command = $alias{$command} if (exists($alias{$command}));
  11908. #print STDERR "MACRO $command\n";
  11909. # handle skipped @-commands
  11910. $state->{'bye'} = 1 if ($command eq 'bye' and !$state->{'ignored'} and !$state->{'arg_expansion'});
  11911. # 'ignored' and 'arg_expansion' are handled in misc_command_texi
  11912. # these are the commands in which the @value and @macro
  11913. # and @-commands in general should not be expanded
  11914. if (defined($Texi2HTML::Config::misc_command{$command}) and
  11915. ($command eq 'c' or $command eq 'comment' or $command eq 'set'
  11916. or $command eq 'clear' or $command eq 'bye' or $command eq 'alias'))
  11917. {
  11918. my $cmd_arg;
  11919. ($cline, $cmd_arg) = misc_command_texi($cline, $command, $state,
  11920. $line_nr);
  11921. add_prev ($text, $stack, "\@$command" . $cmd_arg) unless $state->{'ignored'};
  11922. }
  11923. elsif ($command eq 'setfilename' or $command eq 'documentencoding'
  11924. or $command eq 'definfoenclose' or $command eq 'include')
  11925. { # special commands whose arguments will have @macro and
  11926. # @value expanded, and that are processed in this pass
  11927. if ($state->{'ignored'} or ($line_nr->{'file_name'} ne $Texi2HTML::THISDOC{'input_file_name'} and $command eq 'setfilename'))
  11928. { # @setfilename is ignored in @include file as said in the manual
  11929. $cline = '';
  11930. }
  11931. elsif ($state->{'arg_expansion'})
  11932. {
  11933. add_prev($text, $stack, "\@$command" . $cline);
  11934. return;
  11935. }
  11936. else
  11937. {
  11938. $cline =~ s/^(\s+)//;
  11939. my $space = $1;
  11940. # not sure if it happpens at end of line, or with
  11941. # special char following the @-command or only at end of file
  11942. $space = '' if (!defined($space));
  11943. if (!$state->{'line_command'})
  11944. {
  11945. #print STDERR "LINE_COMMAND Start line_command $command, cline $cline";
  11946. $state->{'line_command'} = $command;
  11947. push @$stack, { 'line_command' => $command, 'text' => $space };
  11948. }
  11949. else
  11950. {
  11951. line_error (sprintf(__("\@%s not allowed in argument to \@%s"), $command, $state->{'line_command'}), $line_nr);
  11952. #add_prev($text, $stack, "\@$command" . $space);
  11953. add_prev($text, $stack, $space);
  11954. }
  11955. }
  11956. }
  11957. # pertusus: it seems that value substitution are performed after
  11958. # macro argument expansions: if we have
  11959. # @set comma ,
  11960. # and a call to a macro @macro {arg1 @value{comma} arg2}
  11961. # the macro arg is arg1 , arg2 and the comma don't separate
  11962. # args. Likewise it seems that the @value are not expanded
  11963. # in macro definitions
  11964. elsif ($command =~ /^r?macro$/)
  11965. { # in 'arg_expansion' (ie within another macro call arguments)
  11966. # the macro is parsed as usual, but isn't registered in
  11967. # end_macro.
  11968. if ($cline =~ /^\s+(\w[\w-]*)\s*(.*)/)
  11969. {
  11970. my $name = $1;
  11971. my $args_def = $2;
  11972. unless ($state->{'ignored'} or $state->{'arg_expansion'})
  11973. {
  11974. if (exists($macros->{$name}))
  11975. {
  11976. #line_warn ("macro `$name' already defined " .
  11977. # format_line_number($macros->{$name}->{'line_nr'}) . " redefined", $line_nr);
  11978. line_warn (sprintf(__("macro `%s' previously defined"), $name), $line_nr);
  11979. line_warn (sprintf(__("here is the previous definition of `%s'"), $name), $macros->{$name}->{'line_nr'});
  11980. }
  11981. }
  11982. $state->{'macro_inside'} = 1;
  11983. next if ($state->{'ignored'});
  11984. my @args = ();
  11985. if ($args_def =~ /^\s*{\s*(.*?)\s*}\s*/)
  11986. {
  11987. @args = split(/\s*,\s*/ , $1)
  11988. }
  11989. # keep the context information of the definition
  11990. my $macro = { 'name' => $name };
  11991. $macro->{'line_nr'} = { 'file_name' => $line_nr->{'file_name'},
  11992. 'line_nr' => $line_nr->{'line_nr'}, 'macro' => $line_nr->{'macro'} } if (defined($line_nr));
  11993. $macro->{'args'} = \@args;
  11994. $macro->{'header'} = "\@$command" .$cline;
  11995. my $arg_index = 0;
  11996. my $debug_msg = '';
  11997. foreach my $arg (@args)
  11998. { # when expanding macros, the argument index is retrieved
  11999. # with args_index
  12000. $macro->{'args_index'}->{$arg} = $arg_index;
  12001. $debug_msg .= "$arg($arg_index) ";
  12002. $arg_index++;
  12003. }
  12004. $macro->{'body'} = '';
  12005. $state->{'macro'} = $macro;
  12006. print STDERR "# macro def $name: $debug_msg\n"
  12007. if ($T2H_DEBUG & $DEBUG_MACROS);
  12008. }
  12009. else
  12010. {# it means we have a macro without a name
  12011. line_error (sprintf(__("Macro definition without macro name: %s"), $cline), $line_nr)
  12012. unless ($state->{'ignored'});
  12013. }
  12014. return 1;
  12015. }
  12016. elsif (defined($Texi2HTML::Config::texi_formats_map{$command}))
  12017. {
  12018. my $tag;
  12019. ($cline, $tag) = do_text_macro($command, $cline, $state, $stack, $line_nr);
  12020. # if it is a raw formatting command or a menu command
  12021. # we must keep it for later, unless we are in an 'ignored'.
  12022. # if in 'arg_expansion' we keep everything.
  12023. my $command_kept;
  12024. if ((($state->{'raw'} or ($Texi2HTML::Config::texi_formats_map{$command} eq 'normal') or (exists($region_lines{$command}))) and !$state->{'ignored'}) or $state->{'arg_expansion'})
  12025. {
  12026. add_prev($text, $stack, $tag);
  12027. $command_kept = 1;
  12028. }
  12029. #dump_stack ($text, $stack, $state);
  12030. next if $command_kept;
  12031. return if ($cline =~ /^\s*$/);
  12032. }
  12033. elsif ($command eq 'value')
  12034. {
  12035. if ($cline =~ s/^{($VARRE)}//)
  12036. {
  12037. my $value = $1;
  12038. if ($state->{'arg_expansion'})
  12039. {
  12040. add_prev($text, $stack, "\@$command" .'{'. $value .'}');
  12041. next;
  12042. }
  12043. next if ($state->{'ignored'});
  12044. my $expansion;
  12045. if (defined($value{$value}))
  12046. {
  12047. $expansion = $value{$value}
  12048. }
  12049. else
  12050. {
  12051. $expansion = gdt('@{No value for `{value}\'@}', {'value' => $value}, {'keep_texi'=> 1});
  12052. line_warn (sprintf(__("undefined flag: %s"), $value), $line_nr);
  12053. }
  12054. $cline = $expansion . $cline;
  12055. }
  12056. else
  12057. {
  12058. if ($state->{'arg_expansion'})
  12059. {
  12060. add_prev($text, $stack, "\@$command");
  12061. next;
  12062. }
  12063. next if ($state->{'ignored'});
  12064. line_error (__("Bad syntax for \@value"), $line_nr);
  12065. }
  12066. }
  12067. elsif ($command eq 'unmacro')
  12068. { #FIXME with 'arg_expansion' should it be passed unmodified ?
  12069. if ($state->{'ignored'})
  12070. {
  12071. $cline =~ s/^\s+(\w+)//;
  12072. }
  12073. else
  12074. {
  12075. delete $macros->{$1} if ($cline =~ s/^\s+(\w+)//);
  12076. }
  12077. return if ($cline =~ /^\s*$/);
  12078. $cline =~ s/^\s*//;
  12079. }
  12080. elsif (exists($macros->{$command}))
  12081. {# it must be before the handling of {, otherwise it is considered
  12082. # to be regular texinfo @-command. Maybe it could be placed higher
  12083. # if we want user defined macros to override texinfo @-commands
  12084. # in 'ignored' we parse macro defined args anyway as it removes
  12085. # some text, but we don't expand the macro
  12086. my $ref = $macros->{$command}->{'args'};
  12087. my $args_number = $#$ref +1;
  12088. # we remove any space/new line before the argument
  12089. if ($cline =~ s/^\s*{\s*//)
  12090. { # the macro has args
  12091. $state->{'macro_args'} = [ "" ];
  12092. $state->{'macro_name'} = $command;
  12093. $state->{'macro_depth'} = 1;
  12094. }
  12095. elsif (($args_number >= 2) or ($args_number <1))
  12096. { # no brace -> no arg
  12097. #$cline =
  12098. #line_warn("\@$command defined with $args_number arguments should be invoked with {}", $line_nr);
  12099. line_warn(sprintf(__("\@%s defined with zero or more than one argument should be invoked with {}"), $command), $line_nr)
  12100. if ($args_number >= 2);
  12101. expand_macro ($command, [], $cline, $line_nr, $state);
  12102. return;
  12103. }
  12104. else
  12105. { # macro with one arg on the line
  12106. chomp $cline;
  12107. #$cline =
  12108. expand_macro ($command, [$cline], "\n", $line_nr, $state);
  12109. return;
  12110. }
  12111. }
  12112. elsif ($cline =~ s/^{//)
  12113. {# we add nested commands in a stack. verb is also on the stack
  12114. # but handled specifically.
  12115. # we add it the comands even in 'ignored' as their result is
  12116. # discarded when the closing brace appear, or the ifset or
  12117. # iclear is closed.
  12118. if ($command eq 'verb')
  12119. {
  12120. if ($cline =~ /^$/)
  12121. {
  12122. line_error (sprintf(__("\@%s without associated character"), $command), $line_nr);
  12123. }
  12124. else
  12125. {
  12126. $cline =~ s/^(.)//;
  12127. $state->{'verb'} = $1;
  12128. }
  12129. }
  12130. if ($state->{'line_command'} and $command eq 'verb')
  12131. { # have to close it now to catch if it is not
  12132. # closed at te end of the line. In subsequent passes this
  12133. # is done in scan_line_separator.
  12134. my $result;
  12135. if (defined($state->{'verb'}))
  12136. {
  12137. $result = '@verb{'.$state->{'verb'};
  12138. my $verb_char = quotemeta($state->{'verb'});
  12139. if ($cline =~ s/^(.*?${verb_char}\})//)
  12140. {
  12141. $result .= $1;
  12142. }
  12143. else
  12144. {
  12145. $cline =~ s/^(.*)//;
  12146. $result .= $1;
  12147. }
  12148. delete $state->{'verb'};
  12149. }
  12150. else
  12151. {
  12152. $result = '@verb{'
  12153. }
  12154. add_prev($text, $stack, $result) unless($state->{'ignored'});
  12155. }
  12156. else
  12157. {
  12158. push (@$stack, { 'style' => $command, 'text' => '' });
  12159. }
  12160. }
  12161. else
  12162. {
  12163. $cline = do_unknown(0, $command, $cline, $text, $stack, $state, $line_nr);
  12164. }
  12165. next;
  12166. }
  12167. #elsif(s/^([^{}@]*)\@(.)//o)
  12168. elsif($cline =~ s/^([^{}@]*)\@([^\s\}\{\@]*)//o)
  12169. {# ARG_EXPANSION
  12170. # No need to warn here for @ followed by a character that
  12171. # is not in any @-command and it is done later
  12172. add_prev($text, $stack, $1) unless($state->{'ignored'});
  12173. $cline = do_unknown(0, $2, $cline, $text, $stack, $state, $line_nr);
  12174. next;
  12175. }
  12176. elsif ($cline =~ s/^([^{}]*)([{}])//o)
  12177. {
  12178. # in ignored section we cannot be sure that there is an @-command
  12179. # already opened so we must discard the text.
  12180. # ARG_EXPANSION
  12181. add_prev($text, $stack, $1) unless($state->{'ignored'});
  12182. if ($2 eq '{')
  12183. {
  12184. # this empty style is for a lone brace.
  12185. # we add it even in 'ignored' as it is discarded when the closing
  12186. # brace appear, or the ifset or iclear is closed.
  12187. push @$stack, { 'style' => '', 'text' => '' };
  12188. }
  12189. else
  12190. {
  12191. if (@$stack)
  12192. {
  12193. my $style = pop @$stack;
  12194. close_style_texi($style, $text, $stack, $state);
  12195. #print STDERR "MACRO end $style->{'style'} remaining: $cline";
  12196. next;
  12197. }
  12198. else
  12199. {# ARG_EXPANSION
  12200. # we warn in the last pass that there is a } without open
  12201. add_prev ($text, $stack, '}') unless($state->{'ignored'});
  12202. }
  12203. }
  12204. }
  12205. else
  12206. {# ARG_EXPANSION
  12207. #print STDERR "END_LINE $cline";
  12208. add_prev($text, $stack, $cline) unless($state->{'ignored'});
  12209. if ($state->{'line_command'})
  12210. {
  12211. if (!scalar(@$stack))
  12212. {
  12213. print STDERR "BUG: empty state for $state->{'line_command'}\n";
  12214. return;
  12215. delete $state->{'line_command'};
  12216. }
  12217. while (!defined($stack->[-1]->{'line_command'}))
  12218. {
  12219. my $top = pop @$stack;
  12220. # defer this to later?
  12221. #line_error ("unclosed command in \@$state->{'line_command'}: $top->{'style'}");
  12222. add_prev($text, $stack, "\@$top->{'style'}".'{'.$top->{'text'}.'}');
  12223. }
  12224. my $command = pop @$stack;
  12225. ###################### debug
  12226. if (!defined($command) or !defined($command->{'text'}) or
  12227. !defined($command->{'line_command'}) or ($command->{'line_command'} ne $state->{'line_command'}))
  12228. {
  12229. msg_debug ("BUG: messed $state->{'line_command'} stack", $line_nr);
  12230. delete $state->{'line_command'};
  12231. return;
  12232. }
  12233. ###################### end debug
  12234. else
  12235. {
  12236. delete $state->{'line_command'};
  12237. my $macro = $command->{'line_command'};
  12238. # include are not kept
  12239. if ($macro eq 'include')
  12240. {
  12241. #if (s/^\s+([\/\w.+-]+)//o)
  12242. if ($command->{'text'} =~ s/^(\s+)(.+)//o)
  12243. {
  12244. my $file_name = $2;
  12245. # FIXME scan_line_separators
  12246. $file_name = trim_around_spaces($file_name);
  12247. $file_name = substitute_line($file_name, "\@$macro", {'code_style' => 1, 'remove_texi' => 1});
  12248. my $file = locate_include_file($file_name);
  12249. if (defined($file))
  12250. {
  12251. my ($line_nr_file, $input_spool_file) = open_file($file, $line_nr->{'macro'}, $state->{'files_stack'});
  12252. ($line_nr, $state->{'input_spool'}) = ($line_nr_file, $input_spool_file) if (defined($line_nr_file));
  12253. print STDERR "# including $file\n" if $T2H_VERBOSE;
  12254. }
  12255. else
  12256. {
  12257. line_error (sprintf(__("\@%s: Cannot find %s"), $macro, $file_name), $line_nr);
  12258. }
  12259. }
  12260. else
  12261. {
  12262. line_error (sprintf(__("Bad argument to \@%s: %s"), $macro, $command->{'text'}), $line_nr);
  12263. }
  12264. return;
  12265. }
  12266. else
  12267. { # these are kept (setfilename, documentencoding, definfoenclose)
  12268. if ($macro eq 'setfilename' and get_conf('USE_SETFILENAME'))
  12269. {
  12270. if (defined(get_conf('setfilename')))
  12271. {
  12272. line_error (sprintf(__("\@%s already set"), $macro), $line_nr);
  12273. # the line is removed, because we don't want to reset
  12274. # get_conf('setfilename') between passes, and we don't want
  12275. # the last one to be picked up
  12276. $cline = "\n";
  12277. next;
  12278. }
  12279. }
  12280. my $cmd_arg;
  12281. ($cline, $cmd_arg) = misc_command_texi($command->{'text'},
  12282. $macro, $state, $line_nr);
  12283. add_prev ($text, $stack, "\@$macro" . $cmd_arg);
  12284. next;
  12285. }
  12286. }
  12287. }
  12288. last;
  12289. }
  12290. }
  12291. return undef if ($state->{'ignored'});
  12292. return 1;
  12293. } # end scan_texi
  12294. sub close_structure_command($$$$)
  12295. {
  12296. my $cmd_ref = shift;
  12297. my $state = shift;
  12298. my $unclosed_commands = shift;
  12299. my $line_nr = shift;
  12300. my $result;
  12301. #print STDERR "close_structure_command $cmd_ref->{'style'}\n";
  12302. # If the anchor is in @titlepage or @copying, it is nevertheless only
  12303. # expanded once in pass_structure, during the @copying or @titlepage
  12304. # expansion.
  12305. # It is not true, however if INLINE_INSERTCOPYING is true.
  12306. # See indices/index_special_region.texi tests.
  12307. if ($cmd_ref->{'style'} eq 'anchor')
  12308. {
  12309. my $anchor = $cmd_ref->{'text'};
  12310. $anchor = normalise_node($anchor);
  12311. #print STDERR "Anchor $anchor\n";
  12312. if ($nodes{$anchor})
  12313. {# makeinfo error message are the following:
  12314. # "Anchor `%s' and node `%s' map to the same file name"
  12315. # "This @anchor command ignored; references to it will not work"
  12316. # "Rename this anchor or use the `--no-split' option"
  12317. #
  12318. # "Anchors `%s' and `%s' map to the same file name"
  12319. # "Anchor `%s' and node `%s' map to the same file name"
  12320. # "@anchor command ignored; references to it will not work"
  12321. # "Rename this anchor or use the `--no-split' option"
  12322. line_error (sprintf(__("Anchor `%s' previously defined %s"), $anchor, format_line_number($nodes{$anchor}->{'line_nr'})), $line_nr);
  12323. return '';
  12324. }
  12325. elsif ($anchor =~ /^\(.+\)/)
  12326. {
  12327. line_error (sprintf(__("Syntax for an external node used for `%s'"), $anchor), $line_nr);
  12328. return '';
  12329. }
  12330. $document_anchor_num++;
  12331. $nodes{$anchor} = { 'anchor' => 1, 'seen' => 1, 'texi' => $anchor, 'id' => 'ANC' . $document_anchor_num, 'line_nr' => $line_nr, 'tag' => 'anchor'};
  12332. push @{$state->{'place'}}, $nodes{$anchor};
  12333. }
  12334. elsif ($cmd_ref->{'style'} eq 'footnote')
  12335. {
  12336. if (get_conf('footnotestyle') eq 'separate')
  12337. {
  12338. $state->{'heading_element'} = $state->{'footnote_heading_element'};
  12339. $state->{'place'} = $state->{'footnote_place'};
  12340. }
  12341. }
  12342. elsif ($cmd_ref->{'style'} eq 'caption' or $cmd_ref->{'style'}
  12343. eq 'shortcaption' and $state->{'float'})
  12344. {
  12345. my @texi_lines = map {$_ = $_."\n"} split (/\n/, $cmd_ref->{'text'});
  12346. $state->{'float'}->{$cmd_ref->{'style'} . "_texi"} = \@texi_lines;
  12347. }
  12348. if (($cmd_ref->{'style'} eq 'titlefont') and ($cmd_ref->{'text'} =~ /\S/))
  12349. {
  12350. $state->{'heading_element'}->{'titlefont'} = $cmd_ref->{'text'} unless ((exists($state->{'region'}) and ($state->{'region'} eq 'titlepage')) or defined($state->{'heading_element'}->{'titlefont'})) ;
  12351. }
  12352. if (defined($Texi2HTML::Config::command_handler{$cmd_ref->{'style'}}))
  12353. {
  12354. $result = init_special($cmd_ref->{'style'},$cmd_ref->{'text'});
  12355. if ($unclosed_commands)
  12356. {
  12357. $result .= "\n"; # the end of line is eaten by init_special
  12358. line_error(sprintf(__("No closing brace for specially handled command %s"), $cmd_ref->{'style'}),$line_nr);
  12359. }
  12360. }
  12361. elsif ($cmd_ref->{'style'})
  12362. {
  12363. $result = '@' . $cmd_ref->{'style'} . '{' . $cmd_ref->{'text'};
  12364. $result .= '}' unless ($unclosed_commands);
  12365. }
  12366. else
  12367. {
  12368. $result = '{' . $cmd_ref->{'text'};
  12369. # don't close { if we are closing stack as we are not
  12370. # sure this is a licit { ... } construct.
  12371. $result .= '}' unless ($unclosed_commands);
  12372. }
  12373. return $result;
  12374. }
  12375. sub end_format_structure($$$$$$)
  12376. {
  12377. my $end_tag = shift;
  12378. my $text = shift;
  12379. my $stack = shift;
  12380. my $state = shift;
  12381. my $line_nr = shift;
  12382. my $remaining_on_line = shift;
  12383. if (defined($state->{'text_macro_stack'})
  12384. and @{$state->{'text_macro_stack'}}
  12385. and ($end_tag eq $state->{'text_macro_stack'}->[-1]))
  12386. {
  12387. pop @{$state->{'text_macro_stack'}};
  12388. if (exists($region_lines{$end_tag}))
  12389. { # end a region_line macro, like documentdescription, copying
  12390. print STDERR "Bug: end_tag $end_tag ne $state->{'region_lines'}->{'format'}\n"
  12391. if ($end_tag ne $state->{'region_lines'}->{'format'});
  12392. print STDERR "Bug: end_tag $end_tag ne $state->{'region'}\n"
  12393. if ($end_tag ne $state->{'region'});
  12394. $state->{'region_lines'}->{'number'}--;
  12395. if ($state->{'region_lines'}->{'number'} == 0)
  12396. {
  12397. close_region($state);
  12398. }
  12399. #dump_stack($text, $stack, $state);
  12400. }
  12401. if (($Texi2HTML::Config::texi_formats_map{$end_tag} eq 'normal') or $Texi2HTML::Config::region_formats_kept{$end_tag})
  12402. {
  12403. $state->{$end_tag}-- if ($Texi2HTML::Config::texi_formats_map{$end_tag} eq 'normal');
  12404. add_prev($text, $stack, "\@end $end_tag");
  12405. }
  12406. else
  12407. {
  12408. #print STDERR "End $end_tag\n";
  12409. #dump_stack($text, $stack, $state);
  12410. return 1 if ($remaining_on_line =~ /^\s*$/);
  12411. }
  12412. }
  12413. elsif ($Texi2HTML::Config::texi_formats_map{$end_tag})
  12414. {
  12415. line_error (sprintf(__("Unmatched `%c%s'"), ord('@'), 'end'), $line_nr);
  12416. #dump_stack($text, $stack, $state);
  12417. }
  12418. elsif ($end_tag eq 'detailmenu' or $end_tag eq 'direntry')
  12419. {
  12420. $state->{$end_tag}-- if $state->{$end_tag};
  12421. add_prev($text, $stack, "\@end $end_tag");
  12422. }
  12423. else
  12424. {
  12425. if ($end_tag eq 'float' and $state->{'float'})
  12426. {
  12427. delete $state->{'float'};
  12428. }
  12429. elsif ($end_tag eq $state->{'table_stack'}->[-1])
  12430. {
  12431. enter_table_index_entry($text, $stack, $state, $line_nr);
  12432. pop @{$state->{'table_stack'}};
  12433. }
  12434. #add end tag
  12435. add_prev($text, $stack, "\@end $end_tag");
  12436. }
  12437. return 0;
  12438. }
  12439. sub parse_menu_entry($)
  12440. {
  12441. my $menu_line = shift;
  12442. my ($node, $name, $ending, $remaining);
  12443. return ($node, $name, $ending, $remaining) unless $menu_line =~ s/^\*//;
  12444. my ($before_colon, $separator);
  12445. ($before_colon, $remaining, $separator) = scan_line_separators($menu_line, ':', 'menu entry');
  12446. if (defined($before_colon) and defined($separator))
  12447. {
  12448. if ($remaining =~ s/^://)
  12449. {
  12450. $node = $before_colon;
  12451. $ending = '::';
  12452. }
  12453. elsif ($remaining =~ /\S/)
  12454. {
  12455. my $after_colon;
  12456. $ending = "";
  12457. ($after_colon, $remaining, $separator) = scan_line_separators($remaining, '\t,\.', 'menu entry node');
  12458. # this certainly corresponds with an error in the node.
  12459. # this is considered not to be a menu entry.
  12460. return (undef, $name, $ending, $remaining) if (!defined($after_colon));
  12461. $node = $after_colon;
  12462. while (1)
  12463. {
  12464. if (!defined($separator) or (defined($separator) and $separator ne '.') or (defined($separator) and (!defined($remaining) or $remaining =~ /^\s/)))
  12465. {
  12466. last;
  12467. }
  12468. $node .= $separator;
  12469. my $after_dot;
  12470. ($after_dot, $remaining, $separator) = scan_line_separators($remaining, '\t,\.', 'menu entry node');
  12471. $after_dot = '' if (!defined($after_dot));
  12472. $node .= $after_dot;
  12473. }
  12474. $name = $before_colon;
  12475. $ending = $separator if (defined($separator));
  12476. # only spaces after the :, this is not a menu entry:
  12477. $node = undef if ($node !~ /\S/);
  12478. }
  12479. }
  12480. # remaining may be defined even if $node isn't.
  12481. #print STDERR "\nLLLL $menu_line";
  12482. #print STDERR " --> node:$node, name:$name, ending:$ending -> $remaining";
  12483. return ($node, $name, $ending, $remaining);
  12484. }
  12485. sub scan_structure($$$$;$)
  12486. {
  12487. my $line = shift;
  12488. my $text = shift;
  12489. my $stack = shift;
  12490. my $state = shift;
  12491. my $line_nr = shift;
  12492. die "stack not an array ref" unless (ref($stack) eq "ARRAY");
  12493. my $cline = $line;
  12494. #print STDERR "SCAN_STRUCTURE: $line";
  12495. #dump_stack ($text, $stack, $state);
  12496. if (!$state->{'raw'} and (!exists($state->{'region_lines'})))
  12497. {
  12498. #if (!$state->{'verb'} and $state->{'menu'} and $cline =~ /^\*\s+/o)
  12499. if (!$state->{'verb'} and $state->{'menu'})
  12500. {
  12501. # new menu entry
  12502. my ($node, $name, $ending, $remaining) = parse_menu_entry($cline);
  12503. if (defined($node))
  12504. {
  12505. menu_entry_texi(normalise_node($node), $state, $line_nr);
  12506. }
  12507. }
  12508. }
  12509. while(1)
  12510. {
  12511. # scan structure
  12512. #dump_stack($text, $stack, $state);
  12513. #print STDERR "WHILE(s):$cline";
  12514. # as texinfo 4.5
  12515. # verbatim might begin at another position than beginning
  12516. # of line, and end verbatim might too. To end a verbatim section
  12517. # @end verbatim must have exactly one space between end and verbatim
  12518. # things following end verbatim are not ignored.
  12519. #
  12520. # html might begin at another position than beginning
  12521. # of line, but @end html must begin the line, and have
  12522. # exactly one space. Things following end html are ignored.
  12523. # tex and ignore works like html
  12524. #
  12525. # ifnothtml might begin at another position than beginning
  12526. # of line, and @end ifnothtml might too, there might be more
  12527. # than one space between @end and ifnothtml but nothing more on
  12528. # the line.
  12529. # @end itemize, @end ftable works like @end ifnothtml.
  12530. # except that @item on the same line than @end vtable doesn't work
  12531. #
  12532. # text right after the itemize before an item is displayed.
  12533. # @item might be somewhere in a line.
  12534. # strangely @item on the same line than @end vtable doesn't work
  12535. # there should be nothing else than a command following @itemize...
  12536. #
  12537. # see more examples in formatting directory
  12538. if ($state->{'raw'})
  12539. {
  12540. my $tag = $state->{'raw'};
  12541. ################# debug
  12542. if (! @$stack or ($stack->[-1]->{'style'} ne $tag))
  12543. {
  12544. print STDERR "Bug: raw or special: $tag but not on top of stack\n";
  12545. print STDERR "line: $cline";
  12546. dump_stack($text, $stack, $state);
  12547. exit 1;
  12548. }
  12549. ################# end debug
  12550. if ($tag eq 'macro')
  12551. {
  12552. if ($cline =~ /^\s*\@macro\s+(\w[\w-]*)\s*(.*)/)
  12553. {
  12554. $state->{$tag}++;
  12555. }
  12556. }
  12557. # macro_regexp
  12558. if ($cline =~ /^(.*?)\@end\s([a-zA-Z][\w-]*)/o and ($2 eq $tag))
  12559. {
  12560. $cline =~ s/^(.*?)(\@end\s$tag)//;
  12561. add_prev ($text, $stack, $1);
  12562. my $end_text = $2;
  12563. if ($tag eq 'macro')
  12564. {
  12565. $state->{$tag}--;
  12566. if ($state->{$tag})
  12567. {
  12568. add_prev ($text, $stack, $end_text);
  12569. next;
  12570. }
  12571. }
  12572. delete $state->{'raw'};
  12573. my $style = pop @$stack;
  12574. if (defined($Texi2HTML::Config::command_handler{$tag}))
  12575. { # replace the special region by what init_special give
  12576. if ($style->{'text'} !~ /^\s*$/)
  12577. {
  12578. add_prev ($text, $stack, init_special($style->{'style'}, $style->{'text'}));
  12579. }
  12580. }
  12581. else
  12582. {
  12583. add_prev ($text, $stack, $style->{'text'} . "\@end $tag");
  12584. }
  12585. next;
  12586. }
  12587. else
  12588. {
  12589. add_prev ($text, $stack, $cline);
  12590. return if (defined($Texi2HTML::Config::command_handler{$tag}));
  12591. last;
  12592. }
  12593. }
  12594. if (defined($state->{'verb'}))
  12595. {
  12596. my $char = quotemeta($state->{'verb'});
  12597. if ($cline =~ s/^(.*?)$char\}/\}/)
  12598. {
  12599. add_prev($text, $stack, $1 . $state->{'verb'});
  12600. $stack->[-1]->{'text'} = $state->{'verb'} . $stack->[-1]->{'text'};
  12601. delete $state->{'verb'};
  12602. next;
  12603. }
  12604. else
  12605. {
  12606. add_prev($text, $stack, $cline);
  12607. last;
  12608. }
  12609. }
  12610. # macro_regexp
  12611. if ($cline =~ s/^([^{}@]*)\@end\s+([a-zA-Z][\w-]*)//)
  12612. {
  12613. add_prev($text, $stack, $1);
  12614. my $end_tag = $2;
  12615. #print STDERR "END STRUCTURE $end_tag\n";
  12616. return if (end_format_structure($end_tag, $text, $stack, $state, $line_nr, $cline));
  12617. next;
  12618. }
  12619. # macro_regexp
  12620. elsif ($cline =~ s/^([^{}@]*)\@(["'~\@\}\{,\.!\?\s\*\-\^`=:\|\/\\])//o or $cline =~ s/^([^{}@]*)\@([a-zA-Z][\w-]*)//o)
  12621. {
  12622. add_prev($text, $stack, $1);
  12623. my $macro = $2;
  12624. #print STDERR "MACRO $macro\n";
  12625. $macro = $alias{$macro} if (exists($alias{$macro}));
  12626. if (defined($Texi2HTML::Config::deprecated_commands{$macro}))
  12627. {
  12628. # makeinfo has
  12629. # "%c%s is obsolete; use %c%s instead"
  12630. if ($Texi2HTML::Config::deprecated_commands{$macro} eq '')
  12631. {
  12632. line_warn(sprintf(__("%c%s is obsolete."), ord('@'), $macro), $line_nr);
  12633. }
  12634. else
  12635. {
  12636. line_warn(sprintf(__("%c%s is obsolete; %s"),ord('@'), $macro, __($Texi2HTML::Config::deprecated_commands{$macro})), $line_nr);
  12637. }
  12638. }
  12639. if (defined($Texi2HTML::Config::misc_command{$macro}))
  12640. {
  12641. my $line;
  12642. ($cline, $line) = misc_command_structure($cline, $macro, $state,
  12643. $line_nr);
  12644. add_prev ($text, $stack, "\@$macro".$line);
  12645. next;
  12646. }
  12647. elsif ($macro eq 'printindex' and ($cline =~ /^\s+(\w+)/))
  12648. {
  12649. my $index_name = $1;
  12650. if (!exists($index_names{$index_name}))
  12651. {
  12652. line_error (sprintf(__("Unknown index `%s' in \@printindex"),$index_name), $line_nr);
  12653. }
  12654. my $associated_element;
  12655. if ($state->{'current_element'} eq $element_before_anything)
  12656. {
  12657. line_warn (sprintf(__("Printindex before document beginning: \@printindex %s"), $index_name), $line_nr);
  12658. }
  12659. else
  12660. {
  12661. # $element_index is the first element with index
  12662. $element_index = $state->{'current_element'} unless (defined($element_index));
  12663. $associated_element = $state->{'current_element'};
  12664. }
  12665. my $region = $state->{'region'};
  12666. $region = 'document' if (!defined($region));
  12667. # FIXME use 'index_name' instead of 'name'
  12668. my $printindex = { 'associated_element' => $associated_element, 'name' => $index_name, 'region' => $region, 'command' => 'printindex' };
  12669. # prepare association of the index to the element by
  12670. # putting it in the current place
  12671. push @{$state->{'place'}}, $printindex;
  12672. push @{$Texi2HTML::THISDOC{'indices'}->{$region}->{$index_name}}, $printindex;
  12673. #print STDERR "PRINTINDEX add($printindex) region $region name $index_name, nr ".scalar(@{$Texi2HTML::THISDOC{'indices'}->{$region}->{$index_name}})."\n";
  12674. add_prev ($text, $stack, "\@$macro" . $cline);
  12675. last;
  12676. }
  12677. elsif ($macro eq 'listoffloats')
  12678. {
  12679. add_prev ($text, $stack, "\@$macro" . $cline);
  12680. last;
  12681. }
  12682. elsif ($sec2level{$macro})
  12683. {
  12684. if ($cline =~ /^\s*(.*)$/)
  12685. {
  12686. my $name = $1;
  12687. my $heading_ref = new_section_heading($macro, $name, $state, $line_nr);
  12688. if (exists($state->{'region_lines'}) and $state->{'region_lines'}->{'format'})
  12689. {
  12690. my $region = $state->{'region_lines'}->{'format'};
  12691. $state->{'region_lines'}->{'head_num'}++;
  12692. my $num = $state->{'region_lines'}->{'head_num'};
  12693. $heading_ref->{'id'} = "${target_prefix}${region}_HEAD$num";
  12694. $heading_ref->{'sec_num'} = "${region}_$num";
  12695. $heading_ref->{'region'} = $region;
  12696. $heading_ref->{'region_head_num'} = $num;
  12697. }
  12698. else
  12699. {
  12700. $document_head_num++;
  12701. $heading_ref->{'id'} = "HEAD$document_head_num";
  12702. $heading_ref->{'sec_num'} = $document_head_num;
  12703. }
  12704. # this is only used when there is a index entry after the
  12705. # heading
  12706. $heading_ref->{'target'} = $heading_ref->{'id'};
  12707. $heading_ref->{'heading'} = 1;
  12708. $heading_ref->{'tag_level'} = $macro;
  12709. $heading_ref->{'number'} = '';
  12710. $state->{'heading_element'} = $heading_ref;
  12711. push @{$state->{'place'}}, $heading_ref;
  12712. $headings{$heading_ref->{'sec_num'}} = $heading_ref;
  12713. push @headings_list, $heading_ref;
  12714. }
  12715. add_prev ($text, $stack, "\@$macro" . $cline);
  12716. last;
  12717. }
  12718. elsif (index_command_prefix($macro) ne '')
  12719. { # if we are already in a (v|f)table the construct is quite
  12720. # wrong
  12721. # FIXME should it be discarded?
  12722. if ($state->{'item'})
  12723. {
  12724. line_error(sprintf(__("ignored \@%s already in an \@%s entry"), $macro, $state->{'item'}), $line_nr);
  12725. next;
  12726. }
  12727. my $index_prefix = index_command_prefix($macro);
  12728. enter_index_entry($index_prefix, $line_nr, $cline, $macro, $state);
  12729. add_prev ($text, $stack, "\@$macro" . $cline);
  12730. last;
  12731. }
  12732. elsif (defined($Texi2HTML::Config::texi_formats_map{$macro}))
  12733. {
  12734. my $macro_kept;
  12735. #print STDERR "TEXT_MACRO: $macro\n";
  12736. if ($Texi2HTML::Config::texi_formats_map{$macro} eq 'raw')
  12737. {
  12738. $state->{'raw'} = $macro;
  12739. $state->{$macro}++ if ($macro eq 'macro');
  12740. #print STDERR "RAW\n";
  12741. }
  12742. elsif ($Texi2HTML::Config::texi_formats_map{$macro} eq 'normal')
  12743. {
  12744. if ($macro eq 'menu')
  12745. {
  12746. delete ($state->{'prev_menu_node'});
  12747. if (!$state->{'node_ref'})
  12748. {
  12749. line_error (sprintf(__("\@%s seen before first \@node"), $macro), $line_nr);
  12750. line_error (__("perhaps your \@top node should be wrapped in \@ifnottex rather than \@ifinfo?"), $line_nr);
  12751. }
  12752. if ($state->{'menu_in_node'})
  12753. {
  12754. line_error (sprintf(__("Multiple \@%s"), $macro), $line_nr);
  12755. }
  12756. $state->{'menu_in_node'}++;
  12757. }
  12758. $state->{$macro}++;
  12759. push @{$state->{'text_macro_stack'}}, $macro;
  12760. #print STDERR "MENU (text_macro_stack: @{$state->{'text_macro_stack'}})\n";
  12761. }
  12762. elsif (exists($region_lines{$macro}))
  12763. {
  12764. if (exists($state->{'region_lines'}) and ($state->{'region_lines'}->{'format'} ne $macro))
  12765. {
  12766. line_error(sprintf(__("\@%s not allowed within %s"), $macro, $state->{'region_lines'}->{'format'}), $line_nr);
  12767. next;
  12768. }
  12769. open_region ($macro, $state);
  12770. if ($Texi2HTML::Config::region_formats_kept{$macro})
  12771. {
  12772. add_prev($text, $stack, "\@$macro");
  12773. $macro_kept = 1;
  12774. $state->{'region_lines'}->{'first_line'} = 1;
  12775. }
  12776. push @{$state->{'text_macro_stack'}}, $macro;
  12777. }
  12778. # if it is a raw formatting command or a menu command
  12779. # we must keep it for later
  12780. if (($state->{'raw'} and (!defined($Texi2HTML::Config::command_handler{$macro}))) or ($Texi2HTML::Config::texi_formats_map{$macro} eq 'normal'))
  12781. {
  12782. add_prev($text, $stack, "\@$macro");
  12783. $macro_kept = 1;
  12784. }
  12785. if ($state->{'raw'})
  12786. {
  12787. push @$stack, { 'style' => $macro, 'text' => '' };
  12788. }
  12789. next if $macro_kept;
  12790. #dump_stack ($text, $stack, $state);
  12791. return if ($cline =~ /^\s*$/);
  12792. }
  12793. elsif ($macro eq 'detailmenu' or $macro eq 'direntry')
  12794. {
  12795. if ($macro eq 'detailmenu' and !$state->{'node_ref'})
  12796. {
  12797. line_error (sprintf(__("\@%s seen before first \@node"), $macro), $line_nr);
  12798. }
  12799. add_prev ($text, $stack, "\@$macro" . $cline);
  12800. $state->{$macro}++;
  12801. last;
  12802. }
  12803. elsif ($macro eq 'float')
  12804. {
  12805. my ($style_texi, $label_texi) = parse_line_arguments($cline, 2, "\@$macro", $line_nr);
  12806. $style_texi = normalise_texi_space($style_texi);
  12807. $label_texi = undef if (defined($label_texi) and ($label_texi =~ /^\s*$/));
  12808. if (defined($label_texi))
  12809. { # The float may be a target for refs if it has a label
  12810. my $error_with_label = 1;
  12811. $label_texi = normalise_node($label_texi);
  12812. if (exists($nodes{$label_texi}) and defined($nodes{$label_texi})
  12813. and $nodes{$label_texi}->{'seen'})
  12814. {
  12815. line_error (sprintf(__("Float label `%s' previously defined %s"), $label_texi, format_line_number($nodes{$label_texi}->{'line_nr'})), $line_nr);
  12816. }
  12817. elsif ($label_texi =~ /^\(.+\)/)
  12818. {
  12819. line_error (sprintf(__("Syntax for an external node used for `%s'"), $label_texi), $line_nr);
  12820. }
  12821. else
  12822. {
  12823. $error_with_label = 0;
  12824. my $float = { };
  12825. if (exists($nodes{$label_texi}) and defined($nodes{$label_texi}))
  12826. { # float appeared in a menu
  12827. $float = $nodes{$label_texi};
  12828. }
  12829. else
  12830. {
  12831. $nodes{$label_texi} = $float;
  12832. }
  12833. $float->{'float'} = 1;
  12834. $float->{'tag'} = 'float';
  12835. $float->{'texi'} = $label_texi;
  12836. $float->{'seen'} = 1;
  12837. $float->{'id'} = $label_texi;
  12838. $float->{'target'} = $label_texi;
  12839. #print STDERR "FLOAT: $float $float->{'texi'}, place $state->{'place'}\n";
  12840. push @{$state->{'place'}}, $float;
  12841. $float->{'element'} = $state->{'current_element'};
  12842. $state->{'float'} = $float;
  12843. $float->{'style_texi'} = $style_texi;
  12844. $float->{'line_nr'} = $line_nr;
  12845. push @floats, $float;
  12846. }
  12847. if ($error_with_label)
  12848. {
  12849. while ($cline =~ /,/)
  12850. {
  12851. $cline =~ s/,.*$//;
  12852. }
  12853. }
  12854. }
  12855. add_prev($text, $stack, "\@$macro" . $cline);
  12856. last;
  12857. }
  12858. elsif (defined($Texi2HTML::Config::def_map{$macro}))
  12859. {
  12860. # @ may protect end of line in @def. We reconstruct lines here.
  12861. # in the texinfo manual is said that spaces after @ collapse
  12862. if ($cline =~ /(\@+)\s*$/)
  12863. {
  12864. my $at_at_end_of_line = $1;
  12865. if ((length($at_at_end_of_line) % 2) == 1)
  12866. {
  12867. #print STDERR "Line continue $cline";
  12868. my $def_line = $cline;
  12869. $def_line =~ s/\@\s*$//;
  12870. chomp($def_line);
  12871. $state->{'in_deff_line'} = "\@$macro" .$def_line;
  12872. return;
  12873. }
  12874. }
  12875. #We must enter the index entries
  12876. my ($prefix, $entry, $argument) = get_deff_index($macro, $cline, $line_nr,1);
  12877. # use deffn instead of deffnx for @-command record
  12878. # associated with index entry
  12879. my $idx_macro = $macro;
  12880. $idx_macro =~ s/x$//;
  12881. enter_index_entry($prefix, $line_nr, $entry, $idx_macro, $state)
  12882. if ($prefix);
  12883. $cline =~ s/(.*)//;
  12884. add_prev($text, $stack, "\@$macro" . $1);
  12885. }
  12886. elsif ($macro =~ /^itemx?$/)
  12887. {
  12888. enter_table_index_entry($text, $stack, $state, $line_nr);
  12889. if ($state->{'table_stack'}->[-1] =~ /^(v|f)?table$/)
  12890. {
  12891. $state->{'item'} = $macro;
  12892. push @$stack, { 'format' => 'index_item', 'text' => '', 'command' => $macro };
  12893. }
  12894. else
  12895. {
  12896. add_prev($text, $stack, "\@$macro");
  12897. }
  12898. }
  12899. elsif ($format_type{$macro} and ($format_type{$macro} eq 'table' or $format_type{$macro} eq 'list' or $macro eq 'multitable'))
  12900. { # We must enter the index entries of (v|f)table thus we track
  12901. # in which table we are
  12902. push @{$state->{'table_stack'}}, $macro;
  12903. add_prev($text, $stack, "\@$macro");
  12904. }
  12905. elsif ($cline =~ s/^{//)
  12906. {
  12907. if ($macro eq 'verb')
  12908. {
  12909. if ($cline =~ /^$/)
  12910. {
  12911. # We already warned in pass texi
  12912. }
  12913. else
  12914. {
  12915. $cline =~ s/^(.)//;
  12916. $state->{'verb'} = $1;
  12917. }
  12918. }
  12919. elsif ($macro eq 'footnote' and (get_conf('footnotestyle') eq 'separate'))
  12920. {
  12921. $state->{'footnote_heading_element'} = $state->{'heading_element'};
  12922. $state->{'footnote_place'} = $state->{'place'};
  12923. $state->{'heading_element'} = $footnote_element;
  12924. $state->{'place'} = $footnote_element->{'place'};
  12925. }
  12926. push (@$stack, { 'style' => $macro, 'text' => '' });
  12927. }
  12928. else
  12929. {
  12930. $cline = do_unknown (1, $macro, $cline, $text, $stack, $state, $line_nr);
  12931. }
  12932. next;
  12933. }
  12934. #elsif($cline =~ s/^([^{}@]*)\@(.)//o)
  12935. elsif($cline =~ s/^([^{}@]*)\@([^\s\}\{\@]*)//o)
  12936. {
  12937. add_prev($text, $stack, $1);
  12938. $cline = do_unknown (1, $2, $cline, $text, $stack, $state, $line_nr);
  12939. next;
  12940. }
  12941. elsif ($cline =~ s/^([^{}]*)([{}])//o)
  12942. {
  12943. add_prev($text, $stack, $1);
  12944. if ($2 eq '{')
  12945. {
  12946. push @$stack, { 'style' => '', 'text' => '' };
  12947. }
  12948. else
  12949. {
  12950. if (@$stack)
  12951. {
  12952. my $style = pop @$stack;
  12953. my $result;
  12954. add_prev ($text, $stack,
  12955. close_structure_command($style, $state, 0, $line_nr));
  12956. next;
  12957. }
  12958. else
  12959. {
  12960. # We warn in the last pass
  12961. add_prev ($text, $stack, '}');
  12962. }
  12963. }
  12964. }
  12965. else
  12966. {
  12967. add_prev($text, $stack, $cline);
  12968. # in case of user mistake, with an @-command not closed on an @item line
  12969. close_stack_structure($text, $stack, $state, $line_nr, 1) if ($state->{'item'});
  12970. enter_table_index_entry($text, $stack, $state, $line_nr);
  12971. #print STDERR "END_LINE(s) $cline";
  12972. #dump_stack($text, $stack, $state);
  12973. last;
  12974. }
  12975. }
  12976. return 1;
  12977. } # end scan_structure
  12978. sub check_bad_end_argument ($$$)
  12979. {
  12980. my $command = shift;
  12981. my $line = shift;
  12982. my $line_nr = shift;
  12983. if ($line =~ /^(\S+)/)
  12984. {
  12985. my $symbols = $1;
  12986. line_error (sprintf(__("Bad argument `%s' to `\@%s', using `%s'"), "${command}${symbols}", 'end', $command), $line_nr);
  12987. }
  12988. }
  12989. sub close_style_command($$$$$;$)
  12990. {
  12991. my $text = shift;
  12992. my $stack = shift;
  12993. my $state = shift;
  12994. my $line_nr = shift;
  12995. my $line = shift;
  12996. # not the end of the style, but the paragraph the style is in is closed
  12997. my $no_close = shift;
  12998. my $style = pop @$stack;
  12999. my $command = $style->{'style'};
  13000. my $result;
  13001. if (!defined($command))
  13002. {
  13003. print STDERR "Bug: empty style in pass_text\n";
  13004. return ($result, $command);
  13005. }
  13006. if (ref($::style_map_ref->{$command}) eq 'HASH')
  13007. {
  13008. push (@{$style->{'args'}}, $style->{'text'});
  13009. $style->{'fulltext'} .= $style->{'text'};
  13010. if (!defined($style->{'arg_nr'}))
  13011. {
  13012. msg_debug("Bug: undefined 'arg_nr' for $command", $line_nr);
  13013. }
  13014. #print STDERR "DEBUG $command ($style->{'arg_nr'})\n";
  13015. #my $number = 0;
  13016. #foreach my $arg(@{$style->{'args'}})
  13017. #{
  13018. # print STDERR " $number: $arg\n";
  13019. # $number++;
  13020. #}
  13021. #print STDERR "END DEBUG\n";
  13022. $style->{'text'} = $style->{'fulltext'};
  13023. $state->{'keep_texi'} = 0 if (
  13024. ($::style_map_ref->{$command}->{'args'}->[$style->{'arg_nr'}] eq 'keep')
  13025. and ($state->{'keep_nr'} == 1));
  13026. }
  13027. if ($no_paragraph_macro{$command})
  13028. {
  13029. $state->{'no_paragraph'}--;
  13030. pop @{$state->{'no_paragraph_stack'}};
  13031. }
  13032. if ($::style_map_ref->{$command} and (defined($style_type{$command})) and ((!$no_close and ($style_type{$command} eq 'style')) or ($style_type{$command} eq 'accent')))
  13033. {
  13034. my $style_command = pop @{$state->{'command_stack'}};
  13035. if ($style_command ne $command)
  13036. {
  13037. #line_warn ("Bug: $style_command on 'command_stack', not $command", $line_nr);
  13038. # This can be a bug in case of bad nesting, see bad_style_nesting.texi
  13039. line_warn("Bad nesting of \@$style_command and \@$command", $line_nr);
  13040. push @{$state->{'command_stack'}}, $style_command;
  13041. ############################ debug
  13042. if ($T2H_DEBUG)
  13043. {
  13044. push @$stack, $style;
  13045. print STDERR "Stacks before pop top:\n";
  13046. dump_stack($text, $stack, $state);
  13047. pop @$stack;
  13048. ############################ end debug
  13049. }
  13050. }
  13051. }
  13052. if ($state->{'keep_texi'})
  13053. { # don't expand @-commands in anchor, refs...
  13054. close_arg ($command, $style->{'arg_nr'}, $state);
  13055. $result = '@' . $command . '{' . $style->{'text'} . '}';
  13056. }
  13057. elsif ($::things_map_ref->{$command})
  13058. {
  13059. $result = do_thing_command ($command, $style->{'text'}, $state, $line_nr);
  13060. }
  13061. else
  13062. {
  13063. $result = do_style_command($command, $style->{'text'}, $state, $style->{'args'}, $line_nr, $style->{'no_open'}, $no_close, $style->{'keep_line_nr'});
  13064. if ($state->{'code_style'} < 0)
  13065. {
  13066. msg_debug ("Bug: negative code_style: $state->{'code_style'}, line:$line", $line_nr);
  13067. }
  13068. if ($state->{'math_style'} < 0)
  13069. {
  13070. msg_debug ("Bug: negative math_style: $state->{'math_style'}, line:$line", $line_nr);
  13071. }
  13072. }
  13073. return ($result, $command);
  13074. }
  13075. sub top_stack_is_menu($)
  13076. {
  13077. my $stack = shift;
  13078. my $top_stack = top_stack($stack, 1);
  13079. return 0 if (!$format_type{$top_stack->{'format'}} or $format_type{$top_stack->{'format'}} ne 'menu');
  13080. return 1;
  13081. }
  13082. sub scan_line($$$$;$)
  13083. {
  13084. my $original_line = shift;
  13085. my $text = shift;
  13086. my $stack = shift;
  13087. my $state = shift;
  13088. my $line_nr = shift;
  13089. die "stack not an array ref" unless (ref($stack) eq "ARRAY");
  13090. my $cline = $original_line;
  13091. #msg_debug("SCAN_LINE (@{$state->{'command_stack'}}): $original_line", $line_nr);
  13092. #dump_stack($text, $stack, $state);
  13093. my $new_menu_entry; # true if there is a new menu entry
  13094. # my $menu_description_in_format; # true if we are in a menu description
  13095. # # but in another format section (@table....)
  13096. # this can happen currently with quotations
  13097. if (defined($state->{'prepend_text'}))
  13098. {
  13099. $cline = $state->{'prepend_text'} . $cline;
  13100. $state->{'prepend_text'} = undef;
  13101. delete $state->{'prepend_text'};
  13102. }
  13103. if (!$state->{'raw'} and !$state->{'verb'} and ($state->{'menu'} or $state->{'direntry'}))
  13104. { # new menu entry
  13105. my ($node, $name, $ending, $remaining) = parse_menu_entry($cline);
  13106. if (defined($node))
  13107. {
  13108. $cline = $remaining;
  13109. print STDERR "# Potential menu entry: $node\n" if ($T2H_DEBUG & $DEBUG_MENU);
  13110. $new_menu_entry = 1;
  13111. my $menu_entry = { 'name' => $name, 'node' => $node, 'ending' => $ending };
  13112. # in SIMPLE_MENU case we don't begin a description, description is
  13113. # just some normal (preformatted) text
  13114. if (get_conf('SIMPLE_MENU'))
  13115. {
  13116. add_prev ($text, $stack, do_menu_link($state, $line_nr, $menu_entry));
  13117. #dump_stack($text, $stack, $state);
  13118. }
  13119. else
  13120. {
  13121. # close description and comment, if they are opened.
  13122. #dump_stack($text, $stack, $state);
  13123. if (!close_menu_comment($text, $stack, $state, __("new menu entry"), $line_nr)
  13124. and !close_menu_description($text, $stack, $state, __("new menu entry"), $line_nr)
  13125. and $state->{'preformatted'})
  13126. {
  13127. close_paragraph($text, $stack, $state, __("new menu entry"), $line_nr);
  13128. }
  13129. print STDERR "# New menu entry: $node\n" if ($T2H_DEBUG & $DEBUG_MENU);
  13130. #dump_stack($text, $stack, $state);
  13131. my $fusionned_description = 0;
  13132. # fusionned looks better in preformatted. But some formats
  13133. # want to always distinguish link and description
  13134. if (get_conf('SEPARATE_DESCRIPTION') or !$state->{'preformatted'})
  13135. {
  13136. add_prev ($text, $stack, do_menu_link($state, $line_nr, $menu_entry));
  13137. }
  13138. else
  13139. {
  13140. $fusionned_description = 1;
  13141. }
  13142. push @$stack, {'format' => 'menu_description', 'text' => '', 'menu_entry' => $menu_entry, 'fusionned_description' => $fusionned_description};
  13143. $state->{'code_style'}++ if ($Texi2HTML::Config::format_code_style{'menu_description'});
  13144. if ($fusionned_description)
  13145. {
  13146. begin_paragraph($stack, $state) if $state->{'preformatted'};
  13147. add_prev ($text, $stack, do_menu_link($state, $line_nr, $menu_entry));
  13148. }
  13149. }
  13150. }
  13151. # we may be in a menu entry description, we close it
  13152. # if there is an empty line, so the last arg is $cline.
  13153. # also if right in menu we always open a menu_comment, it
  13154. # means that there was no menu entry seen since the menu beginning.
  13155. if (!$new_menu_entry and (close_menu_description($text, $stack, $state, "end menu description", $line_nr, $cline) or ($stack->[-1]->{'format'} and $format_type{$stack->[-1]->{'format'}} and $format_type{$stack->[-1]->{'format'}} eq 'menu')))
  13156. {
  13157. if ($state->{'preformatted'})
  13158. {
  13159. begin_paragraph($stack, $state);
  13160. }
  13161. else
  13162. {
  13163. # only start a menu_comment if right in menu and not in
  13164. # a format below a menu because if not right
  13165. # in a menu we have no way to distinguish a menu_comment
  13166. # and some normal text in the format.
  13167. # also it is not started in preformatted environment
  13168. begin_format($text, $stack, $state, 'menu_comment', $cline, $line_nr) if ($stack->[-1]->{'format'} and $format_type{$stack->[-1]->{'format'}} and $format_type{$stack->[-1]->{'format'}} eq 'menu');
  13169. }
  13170. }
  13171. }
  13172. my $first_command_on_line;
  13173. my $commands_count = -1;
  13174. unless ($state->{'raw'} or $state->{'verb'} or $state->{'keep_texi'})
  13175. {
  13176. # first the line commands are taken into account
  13177. $first_command_on_line = next_tag($cline);
  13178. if (defined($first_command_on_line) and defined($Texi2HTML::Config::line_command_map{$first_command_on_line}))
  13179. {
  13180. close_paragraph($text, $stack, $state, "\@$first_command_on_line", $line_nr, 1) if (stop_paragraph_command($first_command_on_line));
  13181. my $arg_texi = $cline;
  13182. $arg_texi =~ s/^\s*\@$first_command_on_line\s*//;
  13183. $arg_texi = trim_comment_spaces ($arg_texi, "\@$first_command_on_line", $line_nr);
  13184. my $arg_line = substitute_line($arg_texi, "\@$first_command_on_line", duplicate_formatting_state($state));
  13185. add_prev ($text, $stack, &$Texi2HTML::Config::line_command($first_command_on_line, $arg_line, $arg_texi, $state));
  13186. enter_author_command ($first_command_on_line, $arg_texi, $arg_line, $stack, $state, $line_nr) if ($first_command_on_line eq 'author');
  13187. return '';
  13188. }
  13189. elsif (defined($first_command_on_line) and ($first_command_on_line eq 'contents') or ($first_command_on_line eq 'summarycontents') or ($first_command_on_line eq 'shortcontents'))
  13190. {
  13191. my $element_tag = $first_command_on_line;
  13192. $element_tag = 'shortcontents' if ($element_tag ne 'contents');
  13193. # at that point the content_element is defined for sure since
  13194. # we already saw the tag
  13195. if (get_conf('INLINE_CONTENTS') and !get_conf('set' . $element_tag . 'aftertitlepage'))
  13196. {
  13197. my $content_element = shift (@{$all_content_elements{$element_tag}});
  13198. my $toc_lines = &$Texi2HTML::Config::inline_contents($Texi2HTML::THISDOC{'FH'}, $element_tag, $content_element, \@sections_list);
  13199. add_prev ($text, $stack, join('',@$toc_lines)) if (defined($toc_lines));
  13200. }
  13201. return '' unless (exists($Texi2HTML::Config::misc_command{$first_command_on_line}) and $Texi2HTML::Config::misc_command{$first_command_on_line}->{'keep'});
  13202. }
  13203. # The commands to ignore are ignored now in case after ignoring them
  13204. # there is an empty line, to be able to stop the paragraph
  13205. #my $leading_spaces = '';
  13206. while (1)
  13207. {
  13208. my $next_tag = next_tag($cline);
  13209. close_paragraph($text, $stack, $state, "\@$next_tag", $line_nr, 1) if (stop_paragraph_command($next_tag));
  13210. if (defined($next_tag) and defined($Texi2HTML::Config::misc_command{$next_tag}) and !$Texi2HTML::Config::misc_command{$next_tag}->{'keep'})
  13211. {
  13212. $commands_count++;
  13213. # FIXME reenable when it is possible
  13214. #line_warn (sprintf(__('%s must only appear at the beginning of a line'), $next_tag), $line_nr) if ($commands_count and $begin_line_command{$next_tag});
  13215. $cline =~ s/^(\s*)\@$next_tag//;
  13216. #$leading_spaces .= $1;
  13217. add_prev ($text, $stack, do_text($1, $state));
  13218. my $result;
  13219. ($cline, $result) = misc_command_text($cline, $next_tag, $stack, $state, $text, $line_nr);
  13220. add_prev($text, $stack, $result) if (defined($result));
  13221. }
  13222. else
  13223. {
  13224. last;
  13225. }
  13226. }
  13227. #add_prev ($text, $stack, $leading_spaces);
  13228. return '' if (!defined($cline) or $cline eq '');
  13229. }
  13230. my $top_stack = top_stack($stack);
  13231. if (($top_stack->{'format'} and $top_stack->{'format'} eq 'menu_description') or $state->{'raw'} or $state->{'preformatted'} or $state->{'no_paragraph'} or $state->{'keep_texi'} or $state->{'remove_texi'})
  13232. { # empty lines are left unmodified in these contexts.
  13233. # it is also possible to be in preformatted within a menu_description
  13234. if ($cline =~ /^\s*$/)
  13235. {
  13236. if ($state->{'raw'})
  13237. {
  13238. print STDERR "#within raw $state->{'raw'}(empty line):$cline" if ($T2H_DEBUG & $DEBUG_FORMATS);
  13239. add_prev($text, $stack, $cline);
  13240. }
  13241. else
  13242. {
  13243. add_prev($text, $stack, do_text($cline,$state));
  13244. }
  13245. return;
  13246. }
  13247. }
  13248. else
  13249. {
  13250. if ($cline =~ /^\s*$/)
  13251. {
  13252. if ($state->{'paragraph_context'})
  13253. { # An empty line ends a paragraph
  13254. close_paragraph($text, $stack, $state, __("paragraph end"), $line_nr);
  13255. }
  13256. add_prev($text, $stack, &$Texi2HTML::Config::empty_line($cline,$state));
  13257. return 1;
  13258. }
  13259. else
  13260. {
  13261. if (!no_paragraph($state,$cline))
  13262. { # open a paragraph, unless the line begins with a macro that
  13263. # shouldn't trigger a paragraph opening
  13264. begin_paragraph($stack, $state);
  13265. }
  13266. }
  13267. }
  13268. # we flag specially deff_item and table line that contain only
  13269. # inter_item_command, which typically is be @c, @comment, @*index, such
  13270. # that the formatter can treat those specifically.
  13271. my $top_format = top_stack($stack,2);
  13272. if ($top_format->{'only_inter_commands'} and !$state->{'keep_texi'})
  13273. {
  13274. my $real_format = $top_format->{'format_ref'}->{'format'};
  13275. my $next_tag = next_tag($cline);
  13276. $next_tag = '' if (!defined($next_tag));
  13277. my $next_end_tag = next_end_tag($cline);
  13278. $next_end_tag = '' if (!defined($next_end_tag));
  13279. #msg_debug("$top_format->{'format'} $next_tag, end $next_end_tag :::$cline");
  13280. delete $top_format->{'only_inter_commands'} unless
  13281. (
  13282. $Texi2HTML::Config::inter_item_commands{$next_tag} or
  13283. (index_command_prefix($next_tag) ne '' and $Texi2HTML::Config::inter_item_commands{'cindex'}) or
  13284. ($top_format->{'format'} eq 'deff_item' and "${real_format}x" eq $next_tag) or
  13285. ($top_format->{'format'} ne 'deff_item' and $next_tag =~ /^itemx?$/) or
  13286. ( $next_end_tag eq $real_format )
  13287. );
  13288. #print STDERR "STILL $top_format->{'only_inter_commands'}\n" if ($top_format->{'only_inter_commands'});
  13289. }
  13290. while(1)
  13291. {
  13292. # scan_line
  13293. #print STDERR "WHILE(l): $cline|";
  13294. #msg_debug("Dump stack in scan_line", $line_nr);
  13295. #dump_stack($text, $stack, $state);
  13296. # we're in a raw format (html, tex if !L2H, verbatim)
  13297. if (defined($state->{'raw'}))
  13298. {
  13299. (dump_stack($text, $stack, $state), die "Bug for raw ($state->{'raw'})") if (! @$stack or ! ($stack->[-1]->{'style'} eq $state->{'raw'}));
  13300. if ($state->{'raw'} eq 'macro')
  13301. {
  13302. if ($cline =~ /^\s*\@macro\s+(\w[\w-]*)\s*(.*)/)
  13303. {
  13304. $state->{$state->{'raw'}}++;
  13305. }
  13306. }
  13307. # macro_regexp
  13308. if ($cline =~ /^(.*?)\@end\s([a-zA-Z][\w-]*)/o and ($2 eq $state->{'raw'}))
  13309. # don't protect html, it is done by Texi2HTML::Config::raw if needed
  13310. {
  13311. $cline =~ s/^(.*?)(\@end\s$state->{'raw'})//;
  13312. my $remaining = $1;
  13313. my $end_text = $2;
  13314. if ($state->{'raw'} eq 'macro')
  13315. {
  13316. $state->{$state->{'raw'}}--;
  13317. if ($state->{$state->{'raw'}})
  13318. {
  13319. add_prev ($text, $stack, $remaining.$end_text);
  13320. last;
  13321. }
  13322. }
  13323. check_bad_end_argument ($state->{'raw'}, $cline, $line_nr);
  13324. add_prev ($text, $stack, $remaining);
  13325. my $style = pop @$stack;
  13326. if ($style->{'text'} !~ /^\s*$/)
  13327. {
  13328. if ($state->{'keep_texi'})
  13329. {
  13330. add_prev ($text, $stack, $style->{'text'} . "\@end $state->{'raw'}");
  13331. }
  13332. elsif ($state->{'remove_texi'})
  13333. {
  13334. add_prev ($text, $stack, &$Texi2HTML::Config::raw_no_texi($style->{'style'}, $style->{'text'}));
  13335. }
  13336. else
  13337. {
  13338. add_prev($text, $stack, &$Texi2HTML::Config::raw($style->{'style'}, $style->{'text'}, $line_nr));
  13339. }
  13340. }
  13341. if (!$state->{'keep_texi'} and !$state->{'remove_texi'})
  13342. {
  13343. # reopen preformatted if it was interrupted by the raw format
  13344. # if raw format is html the preformatted wasn't interrupted
  13345. begin_paragraph($stack, $state) if ($state->{'preformatted'} and (!$Texi2HTML::Config::format_in_paragraph{$state->{'raw'}}));
  13346. delete $state->{'raw'};
  13347. return if ($cline =~ /^\s*$/);
  13348. }
  13349. delete $state->{'raw'};
  13350. return if (($cline =~ /^\s*$/) and $state->{'remove_texi'});
  13351. next;
  13352. }
  13353. else
  13354. {
  13355. print STDERR "#within raw $state->{'raw'}:$cline" if ($T2H_DEBUG & $DEBUG_FORMATS);
  13356. add_prev ($text, $stack, $cline);
  13357. last;
  13358. }
  13359. }
  13360. # we are within a @verb
  13361. if (defined($state->{'verb'}))
  13362. {
  13363. my $char = quotemeta($state->{'verb'});
  13364. if ($cline =~ s/^(.*?)$char\}/\}/)
  13365. {
  13366. if ($state->{'keep_texi'})
  13367. {
  13368. add_prev($text, $stack, $1 . $state->{'verb'});
  13369. $stack->[-1]->{'text'} = $state->{'verb'} . $stack->[-1]->{'text'};
  13370. }
  13371. else
  13372. {
  13373. add_prev($text, $stack, do_text($1, $state));
  13374. }
  13375. delete $state->{'verb'};
  13376. next;
  13377. }
  13378. else
  13379. {
  13380. add_prev($text, $stack, $cline);
  13381. last;
  13382. }
  13383. }
  13384. # We handle now the end tags
  13385. # macro_regexp
  13386. if ($cline =~ s/^([^{}@]*)\@end\s+([a-zA-Z][\w-]*)//)
  13387. {
  13388. $commands_count++;
  13389. my $end_tag = $2;
  13390. my $prev_text = $1;
  13391. if ($state->{'keep_texi'})
  13392. {
  13393. add_prev($text, $stack, $prev_text . "\@end $end_tag");
  13394. next;
  13395. }
  13396. elsif ($state->{'remove_texi'})
  13397. {
  13398. add_prev($text, $stack, $prev_text);
  13399. next;
  13400. }
  13401. add_prev($text, $stack, do_text($prev_text, $state));
  13402. #print STDERR "END_MACRO $end_tag\n";
  13403. #dump_stack ($text, $stack, $state);
  13404. # FIXME reenable when it is possible
  13405. #line_warn (sprintf(__('%s must only appear at the beginning of a line'), 'end'), $line_nr) if ($commands_count or !$first_command_on_line);
  13406. # First we test if the stack is not empty.
  13407. # Then we test if the end tag is a format tag.
  13408. # We then close paragraphs and preformatted at top of the stack.
  13409. # We handle the end tag (even when it was not the tag which appears
  13410. # on the top of the stack; in that case we close anything
  13411. # until that element)
  13412. my $top_stack = top_stack($stack);
  13413. if (!$top_stack)
  13414. {
  13415. line_error (sprintf(__("Unmatched `%c%s'"), ord('@'), 'end'), $line_nr);
  13416. add_prev($text, $stack, "\@end $end_tag");
  13417. next;
  13418. }
  13419. if (!$format_type{$end_tag})
  13420. {
  13421. line_warn ("Unknown \@end $end_tag", $line_nr);
  13422. add_prev($text, $stack, "\@end $end_tag");
  13423. next;
  13424. }
  13425. check_bad_end_argument ($end_tag, $cline, $line_nr);
  13426. if (!close_menu_description($text, $stack, $state, "\@end $end_tag", $line_nr))
  13427. {
  13428. close_paragraph($text, $stack, $state, "\@end $end_tag", $line_nr);
  13429. }
  13430. $top_stack = top_stack($stack);
  13431. if (!$top_stack or (!defined($top_stack->{'format'})))
  13432. {
  13433. line_error (sprintf(__("Unmatched `%c%s'"), ord('@'), 'end'), $line_nr);
  13434. add_prev($text, $stack, "\@end $end_tag");
  13435. dump_stack ($text, $stack, $state) if ($T2H_DEBUG);
  13436. next;
  13437. }
  13438. # Warn if the format on top of stack is not compatible with the
  13439. # end tag, and find the end tag.
  13440. unless (
  13441. ($top_stack->{'format'} eq $end_tag)
  13442. or
  13443. (
  13444. $format_type{$end_tag} eq 'menu' and
  13445. $top_stack->{'format'} eq 'menu_comment'
  13446. ) or
  13447. (
  13448. $end_tag eq 'multitable' and $top_stack->{'format'} eq 'cell'
  13449. ) or
  13450. (
  13451. $format_type{$end_tag} eq 'list' and $top_stack->{'format'} eq 'item'
  13452. ) or
  13453. (
  13454. $format_type{$end_tag} eq 'table'
  13455. and
  13456. ($top_stack->{'format'} eq 'term' or $top_stack->{'format'} eq 'line')
  13457. ) or
  13458. (
  13459. defined($Texi2HTML::Config::def_map{$end_tag}) and
  13460. $top_stack->{'format'} eq 'deff_item'
  13461. )
  13462. )
  13463. {
  13464. # this is not the right format. We try to close other
  13465. # formats to find the format we are searching for.
  13466. # First we close paragraphs, as with a wrong $end_format
  13467. # they may not be closed properly.
  13468. #print STDERR " MISMATCH got $top_stack->{'format'} waited \@end $end_tag($top_stack->{'format'})\n";
  13469. #dump_stack ($text, $stack, $state);
  13470. close_paragraph($text, $stack, $state, "\@end $end_tag", $line_nr);
  13471. $top_stack = top_stack($stack);
  13472. if (!$top_stack or (!defined($top_stack->{'format'})))
  13473. {
  13474. line_error (sprintf(__("Unmatched `%c%s'"), ord('@'), 'end'), $line_nr);
  13475. add_prev($text, $stack, "\@end $end_tag");
  13476. # at that point the dump_stack is not very useful, since
  13477. # close_paragraph above may hide interesting info
  13478. dump_stack ($text, $stack, $state) if ($T2H_DEBUG);
  13479. next;
  13480. }
  13481. my $waited_format = $top_stack->{'format'};
  13482. $waited_format = $fake_format{$top_stack->{'format'}} if ($format_type{$top_stack->{'format'}} eq 'fake');
  13483. if ($end_tag ne $waited_format)
  13484. {
  13485. line_error (sprintf(__("`\@end' expected `%s', but saw `%s'"), $waited_format, $end_tag), $line_nr);
  13486. }
  13487. else
  13488. {
  13489. msg_debug ("\@end is $end_tag, was waiting for $top_stack->{'format'}", $line_nr);
  13490. dump_stack ($text, $stack, $state);
  13491. }
  13492. close_stack($text, $stack, $state, $line_nr, $end_tag);
  13493. # FIXME this is too complex
  13494. # an empty preformatted may appear when closing things as
  13495. # when closed, formats reopen the preformatted environment
  13496. # in case there is some text following, but we know it isn't
  13497. # the case here, thus we can close paragraphs.
  13498. close_paragraph($text, $stack, $state, "\@end $end_tag");
  13499. my $new_top_stack = top_stack($stack);
  13500. next unless ($new_top_stack and defined($new_top_stack->{'format'}) and (($new_top_stack->{'format'} eq $end_tag)
  13501. or (($format_type{$new_top_stack->{'format'}} eq 'fake') and ($fake_format{$new_top_stack->{'format'}} eq $format_type{$end_tag}))));
  13502. }
  13503. # We should now be able to handle the format
  13504. if (defined($format_type{$end_tag}))
  13505. {# remove the space or new line following the @end command
  13506. $cline =~ s/\s//;
  13507. if (end_format($text, $stack, $state, $end_tag, $line_nr))
  13508. { # if end_format is false, paragraph is already begun
  13509. begin_paragraph_after_command($state,$stack,$end_tag,$cline);
  13510. }
  13511. }
  13512. next;
  13513. }
  13514. # This is a macro
  13515. #elsif (s/^([^{}@]*)\@([a-zA-Z]\w*|["'~\@\}\{,\.!\?\s\*\-\^`=:\/])//o)
  13516. # macro_regexp
  13517. elsif ($cline =~ s/^([^{},@]*)\@(["'~\@\}\{,\.!\?\s\*\-\^`=:\|\/\\])//o or $cline =~ s/^([^{}@,]*)\@([a-zA-Z][\w-]*)//o)
  13518. {
  13519. my $before_macro = $1;
  13520. my $macro = $2;
  13521. $commands_count++;
  13522. $macro = $alias{$macro} if (exists($alias{$macro}));
  13523. my $punct;
  13524. if (!$state->{'keep_texi'} and $macro eq ':' and $before_macro =~ /(.)$/ and $Texi2HTML::Config::colon_command_punctuation_characters{$1})
  13525. {
  13526. $before_macro =~ s/(.)$//;
  13527. $punct = $1;
  13528. }
  13529. add_prev($text, $stack, do_text($before_macro, $state));
  13530. add_prev($text, $stack, &$Texi2HTML::Config::colon_command($punct)) if (defined($punct));
  13531. #print STDERR "MACRO $macro\n";
  13532. #print STDERR "LINE $cline";
  13533. #dump_stack ($text, $stack, $state);
  13534. # FIXME reenable when it is possible
  13535. #line_warn (sprintf(__('%s must only appear at the beginning of a line'), $macro), $line_nr) if ($begin_line_command{$macro} and ($commands_count or !$first_command_on_line) and !$state->{'keep_texi'});
  13536. close_paragraph($text, $stack, $state, "\@$macro", $line_nr, 1) if (stop_paragraph_command($macro) and !$state->{'keep_texi'});
  13537. if ($macro eq 'listoffloats' or $macro eq 'printindex')
  13538. {
  13539. if ($state->{'keep_texi'})
  13540. {
  13541. if ($cline =~ s/(.*)//o)
  13542. {
  13543. add_prev($text, $stack, "\@$macro" . $1);
  13544. }
  13545. next;
  13546. }
  13547. close_paragraph($text, $stack, $state, "\@$macro", $line_nr);
  13548. return undef if ($state->{'remove_texi'});
  13549. if ($macro eq 'listoffloats')
  13550. {
  13551. # remove possible comments
  13552. my $arg = normalise_texi_space(trim_comment_spaces ($cline, "\@$macro", $line_nr));
  13553. my $style_id = cross_manual_line($arg);
  13554. my $style = substitute_line (&$Texi2HTML::Config::listoffloats_style($arg), __("\@listoffloats type"), undef, $line_nr);
  13555. my $style_no_texi = remove_texi (&$Texi2HTML::Config::listoffloats_style($arg));
  13556. if (exists ($floats{$style_id}))
  13557. {
  13558. my @listoffloats_entries = ();
  13559. foreach my $float (@{$floats{$style_id}->{'floats'}})
  13560. {
  13561. my $float_style = substitute_line(&$Texi2HTML::Config::listoffloats_float_style($arg, $float), __("\@listoffloats \@float type"));
  13562. my ($caption_lines, $caption_or_shortcaption) = &$Texi2HTML::Config::listoffloats_caption($float);
  13563. # we set 'multiple_pass', and 'expansion'
  13564. # such that index entries
  13565. # and anchors are not handled one more time;
  13566. # the caption has already been formatted,
  13567. # and these have been handled at the right place
  13568. # FIXME footnotes?
  13569. my $caption = '';
  13570. $caption = substitute_text(prepare_state_multiple_pass($macro, $state), undef, "\@$caption_or_shortcaption in listoffloats", @$caption_lines) if (defined($caption_or_shortcaption));
  13571. push @listoffloats_entries, &$Texi2HTML::Config::listoffloats_entry($arg, $float, $float_style, $caption, href($float, $state->{'element'}->{'file'}, $line_nr));
  13572. }
  13573. add_prev($text, $stack, &$Texi2HTML::Config::listoffloats($arg, $style, \@listoffloats_entries));
  13574. }
  13575. else
  13576. {
  13577. line_warn (sprintf(__("Requested float type `%s' not previously used"), $arg), $line_nr);
  13578. }
  13579. }
  13580. elsif ($macro eq 'printindex' and $cline =~ s/\s+(\w+)\s*//)
  13581. {
  13582. my $index_name = $1;
  13583. my $region = $state->{'region'};
  13584. $region = 'document' if (!defined($region));
  13585. if (!defined($Texi2HTML::THISDOC{'indices'}->{$region}))
  13586. {
  13587. msg_debug ("\@printindex $index_name THISDOC{'indices'}->{$region} not defined", $line_nr);
  13588. }
  13589. elsif (!defined($Texi2HTML::THISDOC{'indices'}->{$region}->{$index_name}))
  13590. {
  13591. msg_debug ("\@printindex $index_name THISDOC{'indices'}->{$region}->{$index_name} not defined", $line_nr);
  13592. }
  13593. if (!defined($Texi2HTML::THISDOC{'indices_numbers'}->{$region}->{$index_name}))
  13594. {
  13595. $Texi2HTML::THISDOC{'indices_numbers'}->{$region}->{$index_name} = -1;
  13596. }
  13597. $Texi2HTML::THISDOC{'indices_numbers'}->{$region}->{$index_name}++;
  13598. my $printindex = $Texi2HTML::THISDOC{'indices'}->{$region}->{$index_name}->[$Texi2HTML::THISDOC{'indices_numbers'}->{$region}->{$index_name}];
  13599. if (!defined($printindex))
  13600. {
  13601. # this printindex hasn't been seen in the previous pass.
  13602. # rint STDERR "Index $index_name not in sync, number $Texi2HTML::THISDOC{'indices_numbers'}->{$index_name} not defined\n";
  13603. line_warn("\@printindex $index_name expanded more than once may lead to wrong references", $line_nr);
  13604. $printindex = $Texi2HTML::THISDOC{'indices'}->{$region}->{$index_name}->[-1];
  13605. }
  13606. elsif ($printindex->{'name'} ne $index_name)
  13607. {
  13608. print STDERR "BUG: THISDOC{'indices'} $printindex->{'name'} ne $index_name\n";
  13609. }
  13610. #print STDERR "PRINTINDEX use($printindex) region $region, name $index_name number $Texi2HTML::THISDOC{'indices_numbers'}->{$region}->{$index_name}\n";
  13611. add_prev($text, $stack, &$Texi2HTML::Config::printindex($index_name, $printindex));
  13612. }
  13613. else
  13614. {
  13615. $cline =~ s/^\s*//;
  13616. chomp ($cline);
  13617. line_error (sprintf(__("Bad argument to \@%s: %s"), $macro, $cline), $line_nr);
  13618. }
  13619. begin_paragraph ($stack, $state) if ($state->{'preformatted'});
  13620. return undef;
  13621. }
  13622. if (defined($Texi2HTML::Config::misc_command{$macro}))
  13623. {
  13624. # Handle the misc command
  13625. my $result;
  13626. ($cline, $result) = misc_command_text($cline, $macro, $stack, $state, $text, $line_nr);
  13627. add_prev($text, $stack, $result) if (defined($result));
  13628. return unless (defined($cline));
  13629. unless ($Texi2HTML::Config::misc_command{$macro}->{'keep'})
  13630. {
  13631. begin_paragraph($stack, $state) if
  13632. (!no_paragraph($state,$cline));
  13633. next;
  13634. }
  13635. }
  13636. # This is a @macroname{...} construct. We add it on top of stack
  13637. # It will be handled when we encounter the '}'
  13638. # There is a special case for def macros as @deffn{def} is licit
  13639. if (!$Texi2HTML::Config::def_map{$macro} and $cline =~ s/^{//) #}
  13640. {
  13641. if ($macro eq 'verb')
  13642. {
  13643. if ($cline =~ /^$/)
  13644. {
  13645. # Allready warned
  13646. }
  13647. else
  13648. {
  13649. $cline =~ s/^(.)//;
  13650. $state->{'verb'} = $1;
  13651. }
  13652. }
  13653. # currently if remove_texi and anchor/ref/footnote
  13654. # the text within the command is ignored
  13655. # see t2h_remove_command in texi2html.pm
  13656. my $new_command_ref = { 'style' => $macro, 'text' => '', 'arg_nr' => 0, 'line_nr' => $line_nr };
  13657. push (@$stack, $new_command_ref);
  13658. if ($no_paragraph_macro{$macro})
  13659. {
  13660. $state->{'no_paragraph'}++;
  13661. push @{$state->{'no_paragraph_stack'}}, "\@$macro";
  13662. }
  13663. open_arg($macro, 0, $state);
  13664. if ($state->{'keep_texi'})
  13665. {
  13666. $new_command_ref->{'keep_line_nr'} = [ $line_nr ];
  13667. }
  13668. my $real_style_command = 0;
  13669. if (defined($style_type{$macro}) and (($style_type{$macro} eq 'style') or ($style_type{$macro} eq 'accent')))
  13670. {
  13671. push (@{$state->{'command_stack'}}, $macro);
  13672. $real_style_command = 1;
  13673. #print STDERR "# Stacked $macro (@{$state->{'command_stack'}})\n" if ($T2H_DEBUG);
  13674. }
  13675. # FIXME give line, and modify line?
  13676. &$Texi2HTML::Config::begin_style_texi($macro, $state, $stack, $real_style_command, $state->{'remove_texi'})
  13677. if (defined($Texi2HTML::Config::begin_style_texi)
  13678. and !($state->{'keep_texi'}));
  13679. next;
  13680. }
  13681. # special case if we are checking itemize line. In that case
  13682. # we want to make sure that there is no @item on the @itemize
  13683. # line, otherwise it will be added on the front of another @item,
  13684. # leading to an infinite loop...
  13685. if ($state->{'check_item'} and ($macro =~ /^itemx?$/ or $macro eq 'headitem'))
  13686. {
  13687. line_error(sprintf(__("\@%s not allowed in argument to \@%s"), $macro, $state->{'check_item'}), $line_nr);
  13688. next;
  13689. }
  13690. # if we're keeping texi unmodified we can do it now
  13691. if ($state->{'keep_texi'})
  13692. {
  13693. # We treat specially formats accepting {} on command line
  13694. if ($macro eq 'multitable' or defined($Texi2HTML::Config::def_map{$macro}) or defined($sec2level{$macro}) or $macro eq 'macro')
  13695. {
  13696. add_prev($text, $stack, "\@$macro" . $cline);
  13697. $cline = '';
  13698. next;
  13699. }
  13700. add_prev($text, $stack, "\@$macro");
  13701. if ($Texi2HTML::Config::texi_formats_map{$macro} and $Texi2HTML::Config::texi_formats_map{$macro} eq 'raw')
  13702. {
  13703. $state->{'raw'} = $macro;
  13704. $state->{$macro}++ if ($macro eq 'macro');
  13705. push (@$stack, {'style' => $macro, 'text' => ''});
  13706. }
  13707. next;
  13708. }
  13709. # If we are removing texi, the following macros are not removed
  13710. # as is but modified. So they are collected first, as if we were
  13711. # in normal text
  13712. # a raw macro beginning
  13713. if ($Texi2HTML::Config::texi_formats_map{$macro} and $Texi2HTML::Config::texi_formats_map{$macro} eq 'raw')
  13714. {
  13715. if (!$Texi2HTML::Config::format_in_paragraph{$macro})
  13716. { # close paragraph before verbatim (and tex if !L2H)
  13717. close_paragraph($text, $stack, $state, "\@$macro", $line_nr);
  13718. }
  13719. $state->{'raw'} = $macro;
  13720. push (@$stack, {'style' => $macro, 'text' => ''});
  13721. $state->{$macro}++ if ($macro eq 'macro');
  13722. return if ($cline =~ /^\s*$/ or ($macro eq 'macro'));
  13723. next;
  13724. }
  13725. my $simple_macro = 1;
  13726. # An accent macro
  13727. if (exists($Texi2HTML::Config::accent_map{$macro}))
  13728. {
  13729. # the command itself is not in the command stack, since with
  13730. # braces, it is already popped when do_simple is called
  13731. #push (@{$state->{'command_stack'}}, $macro);
  13732. if ($macro =~ /^[a-zA-Z]/)
  13733. {
  13734. $cline =~ s/^\s*//;
  13735. }
  13736. elsif ($cline =~ /^\s/)
  13737. {
  13738. line_warn (sprintf(__("Accent command `\@%s' must not be followed by whitespace"), $macro), $line_nr);
  13739. }
  13740. if ($cline =~ /^\@/)
  13741. {
  13742. line_error (sprintf(__("Use braces to give a command as an argument to \@%s"), $macro), $line_nr);
  13743. }
  13744. if ($cline =~ s/^(\S)//o)
  13745. {
  13746. add_prev($text, $stack, do_style_command($macro, $1, $state, [ $1 ], $line_nr, undef, undef, undef));
  13747. }
  13748. else
  13749. { # The accent is at end of line
  13750. # FIXME warn? And test case? Maybe this is catched
  13751. # above, by "Accent command `@%s' must not be followed by whitespace"
  13752. # for commands with letter.
  13753. add_prev($text, $stack, do_text($macro, $state));
  13754. }
  13755. #pop @{$state->{'command_stack'}};
  13756. }
  13757. # an @-command which should be like @command{}. We handle it...
  13758. elsif ($::things_map_ref->{$macro})
  13759. {
  13760. line_error (sprintf(__("\@%s expected braces"), $macro), $line_nr);
  13761. add_prev($text, $stack, do_thing_command($macro, '', $state, $line_nr));
  13762. }
  13763. # an @-command like @command
  13764. elsif (defined($::simple_map_ref->{$macro}) or ($state->{'math_style'} and defined($::simple_map_math_ref->{$macro})))
  13765. {
  13766. add_prev($text, $stack, do_simple_command($macro, $state, $line_nr));
  13767. }
  13768. else
  13769. {
  13770. $simple_macro = 0;
  13771. }
  13772. if ($simple_macro)
  13773. {# if the macro didn't triggered a paragraph start it might now
  13774. begin_paragraph($stack, $state) if
  13775. ($Texi2HTML::Config::no_paragraph_commands{$macro} and !no_paragraph($state,$cline));
  13776. next;
  13777. }
  13778. # the following macros are modified or ignored if we are
  13779. # removing texi, and they are not handled like macros in normal text
  13780. if ($state->{'remove_texi'})
  13781. {
  13782. # handle specially some macros
  13783. if ((index_command_prefix($macro) ne '') or
  13784. ($macro eq 'itemize') or
  13785. ($format_type{$macro} and ($format_type{$macro} eq 'table' or $format_type{$macro} eq 'quotation'))
  13786. or ($macro eq 'multitable'))
  13787. {
  13788. return;
  13789. }
  13790. elsif ($macro eq 'enumerate')
  13791. {
  13792. my $spec;
  13793. ($cline, $spec) = parse_enumerate ($cline);
  13794. return if ($cline =~ /^\s*$/);
  13795. next;
  13796. }
  13797. elsif (defined($Texi2HTML::Config::def_map{$macro}))
  13798. {
  13799. my ($command, $style, $category, $name, $type, $class, $arguments, $args_array);
  13800. ($command, $style, $category, $name, $type, $class, $arguments, $args_array) = parse_def($macro, $cline, $line_nr);
  13801. # FIXME -- --- ''... lead to simple text in texi2html
  13802. # while they are kept as is in html coments by makeinfo
  13803. $category = remove_texi($category) if (defined($category));
  13804. $name = remove_texi($name) if (defined($name));
  13805. $type = remove_texi($type) if (defined($type));
  13806. $class = remove_texi($class) if (defined($class));
  13807. $arguments = remove_texi($arguments) if (defined($arguments));
  13808. chomp($arguments);
  13809. add_prev($text, $stack, &$Texi2HTML::Config::def_line_no_texi($category, $name, $type, $arguments));
  13810. return;
  13811. }
  13812. elsif (defined($sec2level{$macro}) and $macro =~ /heading/)
  13813. { #FIXME there is certainly more intelligent stuff to do
  13814. my $num;
  13815. if ($state->{'region'})
  13816. {
  13817. $state->{'head_num'}++;
  13818. $num = "$state->{'region'}_$state->{'head_num'}";
  13819. }
  13820. else
  13821. {
  13822. $num = $global_head_num;
  13823. }
  13824. my $heading_element = $headings{$num};
  13825. $cline = trim_comment_spaces ($cline, "\@$macro");
  13826. add_prev($text, $stack, &$Texi2HTML::Config::heading_no_texi($heading_element, $macro, $cline));
  13827. return;
  13828. }
  13829. # ignore other macros
  13830. next;
  13831. }
  13832. # handle the other macros, we are in the context of normal text
  13833. if (defined($sec2level{$macro}) and $macro =~ /heading/)
  13834. {
  13835. #dump_stack($text, $stack, $state);
  13836. my $num;
  13837. if ($state->{'region'})
  13838. {
  13839. $state->{'head_num'}++;
  13840. $num = "$state->{'region'}_$state->{'head_num'}";
  13841. }
  13842. else
  13843. {
  13844. $global_head_num++;
  13845. $num = $global_head_num;
  13846. }
  13847. my $heading_element = $headings{$num};
  13848. $cline = trim_comment_spaces($cline, "\@$macro", $line_nr);
  13849. add_prev($text, $stack, &$Texi2HTML::Config::element_label($heading_element->{'id'}, $heading_element, $macro, $cline));
  13850. add_prev($text, $stack, &$Texi2HTML::Config::heading($heading_element, $macro, $cline, substitute_line($cline, "\@$macro"), $state->{'preformatted'}));
  13851. return;
  13852. }
  13853. elsif (index_command_prefix($macro) ne '')
  13854. {
  13855. my $index_name = index_command_prefix($macro);
  13856. my $entry_texi = trim_comment_spaces($cline, "\@$macro", $line_nr);
  13857. chomp($entry_texi);
  13858. # multiple_pass is not really necessary, since it may be the place
  13859. # where it is expanded once. However, this ensures that things
  13860. # that are ignored with multiple_pass are ignored.
  13861. my $entry_text = substitute_line($entry_texi, "\@$macro", prepare_state_multiple_pass($macro, $state));
  13862. my ($index_entry, $formatted_index_entry, $index_label) = do_index_entry_label($macro,$state,$line_nr, $entry_texi);
  13863. if (defined($index_entry))
  13864. {
  13865. msg_debug ("(bug?) Index out of sync `$index_entry->{'texi'}' ne `$entry_texi'", $line_nr) if ($index_entry->{'texi'} ne $entry_texi);
  13866. }
  13867. add_prev($text, $stack, &$Texi2HTML::Config::index_entry_command($macro, $index_name, $index_label, $entry_texi, $entry_text, $index_entry));
  13868. # it eats the end of line and therefore don't start
  13869. # table entries nor close @center. These should be stopped
  13870. # on the next line, though.
  13871. return;
  13872. }
  13873. elsif ($macro eq 'insertcopying')
  13874. {
  13875. #close_paragraph($text, $stack, $state, $line_nr);
  13876. add_prev($text, $stack, do_insertcopying($state, $line_nr));
  13877. # reopen a preformatted format if it was interrupted by the macro
  13878. begin_paragraph ($stack, $state) if ($state->{'preformatted'});
  13879. return;
  13880. }
  13881. elsif ($macro =~ /^itemx?$/o or ($macro eq 'headitem'))
  13882. {
  13883. #print STDERR "ITEM: $cline";
  13884. #dump_stack($text, $stack, $state);
  13885. abort_empty_preformatted($stack, $state);
  13886. # FIXME let the user be able not to close the paragraph
  13887. close_paragraph($text, $stack, $state, "\@$macro", $line_nr);
  13888. #print STDERR "ITEM after close para: $cline";
  13889. #dump_stack($text, $stack, $state);
  13890. # these functions return the format if in the right context
  13891. my $in_list_enumerate;
  13892. my $format;
  13893. if ($format = add_item($text, $stack, $state, $line_nr))
  13894. { # handle lists
  13895. $in_list_enumerate = 1;
  13896. if ($macro ne 'item')
  13897. {
  13898. line_error (sprintf(__("\@%s not meaningful inside `\@%s' block"), $macro, $format->{'format'}), $line_nr);
  13899. }
  13900. }
  13901. elsif ($format = add_term($text, $stack, $state, $line_nr))
  13902. { # close table term
  13903. }
  13904. elsif ($format = add_line($text, $stack, $state, $line_nr))
  13905. { # close table definition
  13906. }
  13907. if ($format)
  13908. {
  13909. if ($macro eq 'headitem')
  13910. {
  13911. line_error (sprintf(__("\@%s not meaningful inside `\@%s' block"), $macro, $format->{'format'}), $line_nr);
  13912. }
  13913. if (defined($Texi2HTML::Config::tab_item_texi))
  13914. {
  13915. my $resline = &$Texi2HTML::Config::tab_item_texi($macro, $state->{'command_stack'}, $stack, $state, $cline, $line_nr);
  13916. $cline = $resline if (defined($resline));
  13917. }
  13918. if ($in_list_enumerate)
  13919. {
  13920. push (@$stack, { 'format' => 'item', 'text' => '', 'format_ref' => $format, 'item_cmd' => $macro });
  13921. begin_paragraph($stack, $state) if ($state->{'preformatted'} or !no_line($cline));
  13922. }
  13923. else
  13924. {# handle table @item term and restart another one
  13925. # or after table text restart a term
  13926. push (@$stack, { 'format' => 'term', 'text' => '', 'format_ref' => $format, 'item_cmd' => $macro });
  13927. }
  13928. $format->{'texi_line'} = $cline;
  13929. my ($line, $open_command) = &$Texi2HTML::Config::format_list_item_texi($format->{'format'}, $cline, $format->{'prepended'}, $format->{'command'}, $format->{'number'});
  13930. $cline = $line if (defined($line));
  13931. #if ($open_command)
  13932. #{
  13933. # open_arg($format->{'command'},0, $state);
  13934. # $format->{'command_opened'} = 1;
  13935. #}
  13936. $format->{'item_cmd'} = $macro;
  13937. $format->{'texi_line_texi_formatted'} = $cline;
  13938. next;
  13939. }
  13940. $format = add_row ($text, $stack, $state, $line_nr); # handle multitable
  13941. if (!$format)
  13942. { # makeinfo has:
  13943. # "@%s not meaningful inside `@%s' block" for menu/quotation...
  13944. # and, if outside of any format
  13945. # "%c%s found outside of an insertion block"
  13946. # The following error message seems better.
  13947. line_error (sprintf(__("\@%s outside of table or list"), $macro), $line_nr);
  13948. }
  13949. else
  13950. {
  13951. push @$stack, {'format' => 'row', 'text' => '', 'item_cmd' => $macro, 'format_ref' => $format };
  13952. push @$stack, {'format' => 'cell', 'text' => '', 'format_ref' => $format};
  13953. $format->{'cell'} = 1;
  13954. if ($format->{'max_columns'})
  13955. {
  13956. if (defined($Texi2HTML::Config::tab_item_texi))
  13957. {
  13958. my $resline = &$Texi2HTML::Config::tab_item_texi($macro, $state->{'command_stack'}, $stack, $state, $cline, $line_nr);
  13959. $cline = $resline if (defined($resline));
  13960. }
  13961. begin_paragraph_after_command($state,$stack,$macro,$cline);
  13962. }
  13963. else
  13964. {
  13965. line_warn (sprintf(__("\@%s in empty multitable"), $macro), $line_nr);
  13966. }
  13967. }
  13968. next;
  13969. }
  13970. elsif ($macro eq 'tab')
  13971. {
  13972. abort_empty_preformatted($stack, $state);
  13973. # FIXME let the user be able not to close the paragraph?
  13974. close_paragraph($text, $stack, $state, "\@$macro", $line_nr);
  13975. my $format = add_cell ($text, $stack, $state, $line_nr);
  13976. if (!$format)
  13977. {
  13978. line_error(__("ignoring \@tab outside of multitable"), $line_nr);
  13979. }
  13980. else
  13981. {
  13982. push @$stack, {'format' => 'cell', 'text' => '', 'format_ref' => $format};
  13983. if (!$format->{'max_columns'})
  13984. {
  13985. line_warn (__("ignoring \@tab in empty multitable"), $line_nr);
  13986. }
  13987. elsif ($format->{'cell'} > $format->{'max_columns'})
  13988. {
  13989. line_error (sprintf(__("Too many columns in multitable item (max %d)"), $format->{'max_columns'}), $line_nr);
  13990. }
  13991. else
  13992. {
  13993. if (defined($Texi2HTML::Config::tab_item_texi))
  13994. {
  13995. my $resline = &$Texi2HTML::Config::tab_item_texi($macro, $state->{'command_stack'}, $stack, $state, $cline, $line_nr);
  13996. $cline = $resline if (defined($resline));
  13997. }
  13998. }
  13999. }
  14000. begin_paragraph_after_command($state,$stack,$macro,$cline);
  14001. next;
  14002. }
  14003. # Macro opening a format (table, list, deff, example...)
  14004. elsif ($format_type{$macro} and ($format_type{$macro} ne 'fake'))
  14005. {
  14006. my $ignore_center = 0;
  14007. # @center is forbidden in @-command with braces, @*table
  14008. # @item line, @multitable, or another @center
  14009. if ($macro eq 'center' and @$stack)
  14010. {
  14011. my $top_stack = top_stack($stack, 1);
  14012. if (exists($top_stack->{'style'}) or (defined($top_stack->{'format'}) and ($top_stack->{'format'} eq 'term' or $top_stack->{'format'} eq 'cell')) or $state->{'preformatted'} or $state->{'paragraph_style'}->[-1] eq 'center')
  14013. {
  14014. $ignore_center = 1;
  14015. }
  14016. #dump_stack ($text, $stack, $state);
  14017. }
  14018. if ($ignore_center)
  14019. {
  14020. line_error(__("\@center should not appear in another format"), $line_nr);
  14021. }
  14022. else
  14023. {
  14024. $cline = begin_format($text, $stack, $state, $macro, $cline, $line_nr);
  14025. }
  14026. # we keep the end of line for @center, and for formats
  14027. # that have cmd_line opened and need to see the end of line
  14028. next if (($macro eq 'center') or
  14029. (defined($Texi2HTML::Config::def_map{$macro}))
  14030. or ($macro eq 'float') or ($format_type{$macro} eq 'quotation'));
  14031. return if ($cline =~ /^\s*$/);
  14032. next;
  14033. }
  14034. $cline = do_unknown (2, $macro, $cline, $text, $stack, $state, $line_nr);
  14035. next;
  14036. }
  14037. elsif($cline =~ s/^([^{}@,]*)\@([^\s\}\{\@]*)//o)
  14038. { # A macro with a character which shouldn't appear in macro name
  14039. add_prev($text, $stack, do_text($1, $state));
  14040. $cline = do_unknown (2, $2, $cline, $text, $stack, $state, $line_nr);
  14041. next;
  14042. }
  14043. # a brace
  14044. elsif ($cline =~ s/^([^{},]*)([{}])//o)
  14045. {
  14046. my $leading_text = $1;
  14047. my $brace = $2;
  14048. add_prev($text, $stack, do_text($leading_text, $state));
  14049. if (defined($brace) and ($brace eq '{')) #'}'
  14050. {
  14051. add_prev($text, $stack, do_text('{',$state)); #}
  14052. if ($state->{'math_style'})
  14053. {
  14054. $state->{'math_brace'}++;
  14055. }
  14056. else
  14057. {
  14058. unless ($state->{'keep_texi'} or $state->{'remove_texi'})
  14059. {
  14060. line_error (sprintf(__("Misplaced %c"), ord('{')), $line_nr);
  14061. }
  14062. }
  14063. }
  14064. elsif (defined($brace) and ($brace eq '}') and
  14065. (!@$stack or (!defined($stack->[-1]->{'style'}))
  14066. # braces are allowed in math
  14067. or $state->{'math_brace'}))
  14068. {
  14069. if ($state->{'keep_texi'})
  14070. {
  14071. add_prev($text, $stack, '}');
  14072. }
  14073. elsif($state->{'math_style'} and $state->{'math_brace'})
  14074. {
  14075. add_prev($text, $stack, do_text('}',$state));
  14076. $state->{'math_brace'}--;
  14077. }
  14078. else
  14079. {
  14080. line_error (sprintf(__("Misplaced %c"), ord('}')), $line_nr);
  14081. #dump_stack($text, $stack, $state);
  14082. }
  14083. }
  14084. else
  14085. { # A @-command{ ...} is closed
  14086. my ($result, $command) = close_style_command($text, $stack, $state, $line_nr, $cline);
  14087. add_prev($text, $stack, $result);
  14088. if ($Texi2HTML::Config::no_paragraph_commands{$command}
  14089. and !$state->{'keep_texi'} and !no_paragraph($state,$cline))
  14090. {
  14091. begin_paragraph($stack, $state);
  14092. }
  14093. }
  14094. }
  14095. elsif ($cline =~ s/^([^,]*)[,]//o)
  14096. {
  14097. add_prev($text, $stack, do_text($1, $state));
  14098. if (@$stack and defined($stack->[-1]->{'style'})
  14099. and (ref($::style_map_ref->{$stack->[-1]->{'style'}}) eq 'HASH'))
  14100. {
  14101. my $macro = $stack->[-1]->{'style'};
  14102. my $style_args = $::style_map_ref->{$macro}->{'args'};
  14103. if (defined($style_args->[$stack->[-1]->{'arg_nr'} + 1]))
  14104. {
  14105. push (@{$stack->[-1]->{'args'}}, $stack->[-1]->{'text'});
  14106. $stack->[-1]->{'fulltext'} .= $stack->[-1]->{'text'} . do_text(',', $state);
  14107. $stack->[-1]->{'text'} = '';
  14108. close_arg ($macro, $stack->[-1]->{'arg_nr'}, $state);
  14109. $stack->[-1]->{'arg_nr'}++;
  14110. open_arg ($macro, $stack->[-1]->{'arg_nr'}, $state);
  14111. next;
  14112. }
  14113. }
  14114. add_prev($text, $stack, do_text(',', $state));
  14115. }
  14116. else
  14117. { # no macro nor '}', but normal text
  14118. add_prev($text, $stack, do_text($cline, $state));
  14119. # @center/line term is closed at the end of line. When a
  14120. # @-command which
  14121. # keeps the texi as is happens on the @center line, the @center
  14122. # is closed at the end of line appearing after the @-command
  14123. # closing (for example @ref, @footnote).
  14124. last if ($state->{'keep_texi'});
  14125. #print STDERR "END_LINE(l):$cline!!!\n";
  14126. #dump_stack($text, $stack, $state);
  14127. my $maybe_format_to_close = 1;
  14128. my $in_table;
  14129. while ($maybe_format_to_close)
  14130. {
  14131. $maybe_format_to_close = 0;
  14132. #my $top_format = top_stack($stack, 1);
  14133. my $top_format = top_stack($stack, 2);
  14134. # the stack cannot easily be used, because there may be
  14135. # opened commands in paragraphs if the center is in a
  14136. # style command, like
  14137. # @b{
  14138. # bold
  14139. #
  14140. # @center centered bold
  14141. #
  14142. # }
  14143. #
  14144. # Therefore $state->{'paragraph_style'}->[-1] is used.
  14145. #
  14146. # The close_stack until 'center' is needed because
  14147. # of constructs like
  14148. #
  14149. # @center something @table
  14150. #
  14151. # In that case what would be removed from the stack after
  14152. # paragraph closing wold not be the @center. Such construct
  14153. # is certainly incorrect, though.
  14154. #
  14155. # when 'closing_center' is true we don't retry to close
  14156. # the @center line.
  14157. if ($state->{'paragraph_style'}->[-1] eq 'center'
  14158. and !$state->{'closing_center'} and !$state->{'keep_texi'})
  14159. {
  14160. $state->{'closing_center'} = 1;
  14161. close_paragraph($text, $stack, $state, "\@center", $line_nr);
  14162. close_stack($text, $stack, $state, $line_nr, 'center');
  14163. delete $state->{'closing_center'};
  14164. my $center = pop @$stack;
  14165. add_prev($text, $stack, &$Texi2HTML::Config::paragraph_style_command('center',$center->{'text'}));
  14166. my $top_paragraph_style = pop @{$state->{'paragraph_style'}};
  14167. # center is at the bottom of the comand_stack because it
  14168. # may be nested in many way
  14169. my $bottom_command_stack = shift @{$state->{'command_stack'}};
  14170. print STDERR "Bug: closing center, top_paragraph_style: $top_paragraph_style, bottom_command_stack: $bottom_command_stack.\n"
  14171. if ($bottom_command_stack ne 'center' or $top_paragraph_style ne 'center');
  14172. $maybe_format_to_close = 1;
  14173. next;
  14174. }
  14175. # @item line is closed by end of line. In general there should
  14176. # not be a paragraph in a term. However it may currently
  14177. # happen in construct like
  14178. #
  14179. # @table @asis
  14180. # @item @cindex index entry
  14181. # some text still in term, and in paragraph
  14182. # Not in term anymore
  14183. # ....
  14184. #
  14185. if (defined($top_format->{'format'}) and $top_format->{'format'} eq 'term')
  14186. {
  14187. #close_paragraph($text, $stack, $state, $line_nr)
  14188. # if ($state->{'paragraph_context'});
  14189. close_stack($text, $stack, $state, $line_nr, 'term');
  14190. $in_table = add_term($text, $stack, $state, $line_nr);
  14191. if ($in_table)
  14192. {
  14193. $maybe_format_to_close = 1;
  14194. next;
  14195. }
  14196. }
  14197. }
  14198. if ($in_table)
  14199. {
  14200. push (@$stack, { 'format' => 'line', 'text' => '', 'only_inter_commands' => 1, 'format_ref' => $in_table });
  14201. begin_paragraph($stack, $state) if ($state->{'preformatted'});
  14202. }
  14203. last;
  14204. }
  14205. }
  14206. return 1;
  14207. } # end scan_line
  14208. sub open_arg($$$)
  14209. {
  14210. my $macro = shift;
  14211. my $arg_nr = shift;
  14212. my $state = shift;
  14213. if (ref($::style_map_ref->{$macro}) eq 'HASH')
  14214. {
  14215. my $arg = $::style_map_ref->{$macro}->{'args'}->[$arg_nr];
  14216. if ($arg eq 'keep')
  14217. {
  14218. $state->{'keep_nr'}++;
  14219. $state->{'keep_texi'} = 1;
  14220. }
  14221. elsif (!$state->{'keep_texi'})
  14222. {
  14223. if ($arg eq 'code')
  14224. {
  14225. $state->{'code_style'}++;
  14226. }
  14227. elsif ($arg eq 'math')
  14228. {
  14229. $state->{'math_style'}++;
  14230. $state->{'code_style'}++;
  14231. if ($state->{'math_style'} == 1)
  14232. {
  14233. $state->{'math_brace'} = 0;
  14234. }
  14235. }
  14236. }
  14237. }
  14238. elsif ($code_style_map{$macro} and !$state->{'keep_texi'})
  14239. {
  14240. $state->{'code_style'}++;
  14241. }
  14242. }
  14243. sub close_arg($$$)
  14244. {
  14245. my $macro = shift;
  14246. my $arg_nr = shift;
  14247. my $state = shift;
  14248. if (ref($::style_map_ref->{$macro}) eq 'HASH')
  14249. {
  14250. my $arg = $::style_map_ref->{$macro}->{'args'}->[$arg_nr];
  14251. if ($arg eq 'keep')
  14252. {
  14253. $state->{'keep_nr'}--;
  14254. $state->{'keep_texi'} = 0 if ($state->{'keep_nr'} == 0);
  14255. }
  14256. elsif (!$state->{'keep_texi'})
  14257. {
  14258. if ($arg eq 'code')
  14259. {
  14260. $state->{'code_style'}--;
  14261. }
  14262. elsif ($arg eq 'math')
  14263. {
  14264. $state->{'math_style'}--;
  14265. $state->{'code_style'}--;
  14266. }
  14267. }
  14268. #print STDERR "c $arg_nr $macro $arg $state->{'code_style'}\n";
  14269. }
  14270. elsif ($code_style_map{$macro} and !$state->{'keep_texi'})
  14271. {
  14272. $state->{'code_style'}--;
  14273. }
  14274. }
  14275. # add a special style on the top of the stack. This is used for commands
  14276. # that extend until the end of the line. Also add an entry in the @-command
  14277. # hashes for this fakes style.
  14278. #sub open_cmd_line($$$$$)
  14279. #{
  14280. # my $command = shift;
  14281. # my $stack = shift;
  14282. # my $state = shift;
  14283. # my $args = shift;
  14284. # my $function = shift;
  14285. # push @$stack, {'style' => 'cmd_line', 'text' => '', 'arg_nr' => 0};
  14286. # foreach my $hash (\%Texi2HTML::Config::style_map, \%Texi2HTML::Config::style_map_pre, \%Texi2HTML::Config::style_map_texi, \%Texi2HTML::Config::simple_format_style_map_texi)
  14287. # {
  14288. # $hash->{'cmd_line'}->{'args'} = $args;
  14289. # $hash->{'cmd_line'}->{'function'} = $function;
  14290. # }
  14291. # $state->{'no_paragraph'}++;
  14292. # push @{$state->{'no_paragraph_stack'}}, "\@$command line";
  14293. ## $state->{'cmd_line'} = 1;
  14294. # open_arg ('cmd_line', 0, $state);
  14295. #}
  14296. # finish @item line in @*table
  14297. sub add_term($$$$)
  14298. {
  14299. my $text = shift;
  14300. my $stack = shift;
  14301. my $state = shift;
  14302. my $line_nr = shift;
  14303. my $top_format = top_stack($stack,2);
  14304. return unless (defined($top_format->{'format'}) and $top_format->{'format'} eq 'term');
  14305. #print STDERR "ADD_TERM\n";
  14306. my $term = pop @$stack;
  14307. my $format = $stack->[-1];
  14308. $format->{'paragraph_number'} = 0;
  14309. chomp ($term->{'text'});
  14310. my ($index_label, $formatted_index_entry);
  14311. if ($format->{'format'} =~ /^(f|v)/o)
  14312. {
  14313. my $index_entry;
  14314. ($index_entry, $formatted_index_entry, $index_label) = do_index_entry_label($format->{'format'}, $state,$line_nr, $format->{'texi_line'});
  14315. print STDERR "Bug: no index entry for $term->{'text'}\n" unless defined($index_label);
  14316. }
  14317. my $item_result = &$Texi2HTML::Config::table_item($term->{'text'}, $index_label,$format->{'format'},$format->{'command'}, $state->{'command_stack'}, $term->{'item_cmd'}, $formatted_index_entry);
  14318. add_prev($text, $stack, $item_result);
  14319. return $format;
  14320. }
  14321. sub add_row($$$$)
  14322. {
  14323. my $text = shift;
  14324. my $stack = shift;
  14325. my $state = shift;
  14326. my $line_nr = shift;
  14327. my $top_format = top_stack($stack);
  14328. # @center a @item
  14329. # will lead to row not being closed since a close paragraph doesn't
  14330. # end the center.
  14331. return unless (defined($top_format->{'format'}) and $top_format->{'format'} eq 'cell');
  14332. my $cell = $top_format;
  14333. my $format = $stack->[-3];
  14334. print STDERR "Bug under row cell row not a multitable\n" if (!defined($format->{'format'}) or $format->{'format'} ne 'multitable');
  14335. #print STDERR "ADD_ROW $format->{'item_nr'} first: $format->{'first'}\n";
  14336. # dump_stack($text, $stack, $state);
  14337. $format->{'item_nr'}++ unless ($format->{'first'});
  14338. my $empty_first;
  14339. if ($format->{'first'} and $format->{'cell'} == 1 and $stack->[-1]->{'text'} =~ /^\s*$/)
  14340. {
  14341. $empty_first = 1;
  14342. $format->{'empty_first'} = 1;
  14343. }
  14344. if ($format->{'cell'} > $format->{'max_columns'} or $empty_first)
  14345. {
  14346. my $cell = pop @$stack;
  14347. print STDERR "Bug: not a cell ($cell->{'format'}) in multitable\n" if ($cell->{'format'} ne 'cell');
  14348. }
  14349. else
  14350. {
  14351. add_cell($text, $stack, $state);
  14352. }
  14353. my $row = pop @$stack;
  14354. print STDERR "Bug: not a row ($row->{'format'}) in multitable\n" if ($row->{'format'} ne 'row');
  14355. if ($format->{'max_columns'} and !$empty_first)
  14356. {
  14357. # FIXME have the cell count in row and not in table. table could have
  14358. # the whole structure, but cell count doesn't make much sense
  14359. add_prev($text, $stack, &$Texi2HTML::Config::row($row->{'text'}, $row->{'item_cmd'}, $format->{'columnfractions'}, $format->{'prototype_row'}, $format->{'prototype_lengths'}, $format->{'max_columns'}, $cell->{'only_inter_commands'}, $format->{'first'}));
  14360. }
  14361. $format->{'first'} = 0 if ($format->{'first'});
  14362. return $format;
  14363. }
  14364. # FIXME remove and merge, too much double checks and code
  14365. sub add_cell($$$$)
  14366. {
  14367. my $text = shift;
  14368. my $stack = shift;
  14369. my $state = shift;
  14370. my $line_nr = shift;
  14371. my $top_format = top_stack($stack);
  14372. #print STDERR "ADD_CELL\n";
  14373. return unless (defined($top_format) and $top_format->{'format'} eq 'cell');
  14374. # print STDERR "ADD_CELL, really\n";
  14375. my $cell = pop @$stack;
  14376. my $row = top_stack($stack);
  14377. print STDERR "Bug: top_stack of cell not a row\n" if (!defined($row->{'format'}) or ($row->{'format'} ne 'row'));
  14378. my $format = $stack->[-2];
  14379. print STDERR "Bug under cell row not a multitable\n" if (!defined($format->{'format'}) or $format->{'format'} ne 'multitable');
  14380. if ($format->{'first'} and $format->{'cell'} == 1)
  14381. {
  14382. line_warn(__("\@tab before \@item"), $line_nr);
  14383. }
  14384. if ($format->{'cell'} <= $format->{'max_columns'})
  14385. {
  14386. add_prev($text, $stack, &$Texi2HTML::Config::cell($cell->{'text'}, $row->{'item_cmd'}, $format->{'columnfractions'}, $format->{'prototype_row'}, $format->{'prototype_lengths'}, $format->{'max_columns'}, $cell->{'only_inter_commands'}, $format->{'first'}));
  14387. }
  14388. $format->{'cell'}++;
  14389. $format->{'first'} = 0 if ($format->{'first'});
  14390. return $format;
  14391. }
  14392. sub add_line($$$$)
  14393. {
  14394. my $text = shift;
  14395. my $stack = shift;
  14396. my $state = shift;
  14397. my $line_nr = shift;
  14398. my $top_stack = top_stack($stack);
  14399. # if there is something like
  14400. # @center centered @item new item
  14401. # the item isn't opened since it is in @center, and center isn't closed
  14402. # by an @item appearing here (unlike a paragraph).
  14403. # the error message is '@item outside of table or list'.
  14404. # texi2dvi also has issue, but makeinfo is happy, however it
  14405. # produces bad nesting.
  14406. return unless(defined($top_stack->{'format'}) and $top_stack->{'format'} eq 'line');
  14407. #print STDERR "ADD_LINE\n";
  14408. #dump_stack($text, $stack, $state);
  14409. my $line = pop @$stack;
  14410. my $format = $stack->[-1];
  14411. $format->{'paragraph_number'} = 0;
  14412. if ($format->{'first'})
  14413. {
  14414. $format->{'first'} = 0;
  14415. # we must have <dd> or <dt> following <dl> thus we do a
  14416. # &$Texi2HTML::Config::table_line here too, although it could have
  14417. # been a normal paragraph.
  14418. if ($line->{'text'} =~ /\S/o)
  14419. {
  14420. add_prev($text, $stack, &$Texi2HTML::Config::table_line($line->{'text'}, $line->{'only_inter_commands'}, 1));
  14421. $format->{'empty_first'} = 1 if ($line->{'only_inter_commands'});
  14422. }
  14423. else
  14424. {
  14425. $format->{'empty_first'} = 1;
  14426. }
  14427. }
  14428. else
  14429. {
  14430. $format->{'item_nr'}++;
  14431. add_prev($text, $stack, &$Texi2HTML::Config::table_line($line->{'text'}, $line->{'only_inter_commands'}, 0));
  14432. }
  14433. return $format;
  14434. }
  14435. # finish @enumerate or @itemize @item
  14436. sub add_item($$$$)
  14437. {
  14438. my $text = shift;
  14439. my $stack = shift;
  14440. my $state = shift;
  14441. my $line_nr = shift;
  14442. my $top_stack = top_stack($stack);
  14443. return unless (defined($top_stack->{'format'}) and $top_stack->{'format'} eq 'item');
  14444. #print STDERR "ADD_ITEM: \n";
  14445. #dump_stack($text, $stack, $state);
  14446. # as in pre the end of line are kept, we must explicitely abort empty
  14447. # preformatted, close_stack doesn't do that.
  14448. my $item = pop @$stack;
  14449. my $format = $stack->[-1];
  14450. #my $item_command = $item->{'format'};
  14451. my $item_command = $item->{'item_cmd'};
  14452. # first has no associated item, it is more like a 'title'
  14453. $item_command = '' if ($format->{'first'});
  14454. # debug message if it is the first item (much like a title) although
  14455. # there is an item command.
  14456. msg_debug("First in $format->{'format'} but item_cmd defined $item->{'item_cmd'}",$line_nr) if ($format->{'first'} and defined($item->{'item_cmd'}));
  14457. $format->{'paragraph_number'} = 0;
  14458. #dump_stack ($text, $stack, $state);
  14459. # the element following ol or ul must be li. Thus even though there
  14460. # is no @item we put a normal item.
  14461. # don't do an item if it is the first and it is empty
  14462. if (!$format->{'first'} or ($item->{'text'} =~ /\S/o))
  14463. {
  14464. my $formatted_command;
  14465. if (defined($format->{'command'}) and $format->{'command'} ne '')# and exists($::things_map_ref->{$format->{'command'}}))
  14466. {
  14467. $formatted_command = substitute_line("\@$format->{'command'}\{\}", "\@item \@$format->{'command'}", duplicate_formatting_state($state));
  14468. $format->{'formatted_command'} = $formatted_command;
  14469. }
  14470. #chomp($item->{'text'});
  14471. add_prev($text, $stack, &$Texi2HTML::Config::list_item($item->{'text'},$format->{'format'},$format->{'command'}, $formatted_command, $format->{'item_nr'}, $format->{'spec'}, $format->{'number'}, $format->{'prepended'}, $format->{'prepended_formatted'}, $item->{'only_inter_commands'}, $format->{'first'},$item_command));
  14472. }
  14473. else
  14474. {
  14475. $format->{'empty_first'} = 1;
  14476. }
  14477. if ($format->{'first'})
  14478. {
  14479. $format->{'first'} = 0;
  14480. }
  14481. else
  14482. {
  14483. $format->{'item_nr'}++;
  14484. }
  14485. if ($format->{'format'} eq 'enumerate')
  14486. {
  14487. $format->{'number'} = '';
  14488. my $spec = $format->{'spec'};
  14489. if ($spec =~ /^[0-9]$/)
  14490. {
  14491. $format->{'number'} = $spec + $format->{'item_nr'};
  14492. }
  14493. else
  14494. {
  14495. my $base_letter = ord('a');
  14496. $base_letter = ord('A') if (ucfirst($spec) eq $spec);
  14497. my @letter_ords = decompose(ord($spec) - $base_letter + $format->{'item_nr'}, 26);
  14498. foreach my $ord (@letter_ords)
  14499. {# FIXME we go directly to 'ba' after 'z', and not 'aa'
  14500. #because 'ba' is 1,0 and 'aa' is 0,0.
  14501. $format->{'number'} = chr($base_letter + $ord) . $format->{'number'};
  14502. }
  14503. }
  14504. }
  14505. return $format;
  14506. }
  14507. # format ``simple'' macros, that is macros without arg or style macros
  14508. sub do_simple_command($$$)
  14509. {
  14510. my $macro = shift;
  14511. my $state = shift;
  14512. my $line_nr = shift;
  14513. #msg_debug ("DO_SIMPLE $macro $args $arg_nr (@$args)", $line_nr) if (defined($args));
  14514. if ($state->{'remove_texi'})
  14515. {
  14516. #print STDERR "DO_SIMPLE remove_texi $macro\n";
  14517. return $::simple_map_texi_ref->{$macro};
  14518. }
  14519. else
  14520. {
  14521. return &$Texi2HTML::Config::simple_command($macro, $state->{'preformatted'}, $state->{'math_style'}, $line_nr, $state);
  14522. }
  14523. }
  14524. sub do_thing_command($$$$)
  14525. {
  14526. my $macro = shift;
  14527. my $text = shift;
  14528. my $state = shift;
  14529. my $line_nr = shift;
  14530. if ($state->{'remove_texi'})
  14531. {
  14532. return $::texi_map_ref->{$macro}.$text;
  14533. #print STDERR "DO_SIMPLE remove_texi texi_map $macro\n";
  14534. }
  14535. else
  14536. {
  14537. return &$Texi2HTML::Config::thing_command($macro, $text, $state->{'preformatted'}, $state->{'math_style'}, $line_nr, $state);
  14538. }
  14539. }
  14540. sub do_style_command($$$$$$$$)
  14541. {
  14542. my $macro = shift;
  14543. my $text = shift;
  14544. my $state = shift;
  14545. my $args = shift;
  14546. my $line_nr = shift;
  14547. my $no_open = shift;
  14548. my $no_close = shift;
  14549. my $kept_line_nrs = shift;
  14550. my $arg_nr = 0;
  14551. $arg_nr = @$args - 1 if (defined($args));
  14552. if (defined($::style_map_ref->{$macro}))
  14553. {
  14554. my $style;
  14555. my $result;
  14556. if ($state->{'remove_texi'})
  14557. {
  14558. #print STDERR "REMOVE $macro, $style_map_texi_ref->{$macro}, fun $style_map_texi_ref->{$macro}->{'function'} remove cmd " . \&Texi2HTML::Config::t2h_remove_command . " ascii acc " . \&t2h_default_accent;
  14559. $style = $::style_map_texi_ref->{$macro};
  14560. }
  14561. elsif ($state->{'math_style'} and defined($::style_map_math_ref->{$macro}))
  14562. { # FIXME we are still in math when the @math is closed here, since
  14563. # close_arg that does 'math_style'-- is called below.
  14564. $style = $::style_map_math_ref->{$macro};
  14565. }
  14566. elsif ($state->{'preformatted'})
  14567. {
  14568. if ($macro eq 'kbd' and (get_conf('kbdinputstyle') ne 'distinct'))
  14569. {
  14570. $style = $::style_map_pre_ref->{'code'};
  14571. }
  14572. else
  14573. {
  14574. $style = $::style_map_pre_ref->{$macro};
  14575. }
  14576. }
  14577. else
  14578. {
  14579. # kbd is in code_style, so it is 'code_style' > 1
  14580. if ($macro eq 'kbd' and ((get_conf('kbdinputstyle') eq 'code') or ($state->{'code_style'} > 1 and get_conf('kbdinputstyle') eq 'example')))
  14581. {
  14582. $style = $::style_map_ref->{'code'};
  14583. }
  14584. else
  14585. {
  14586. $style = $::style_map_ref->{$macro};
  14587. }
  14588. }
  14589. if ($macro eq 'dotless')
  14590. {
  14591. if (scalar(@$args) ne 1)
  14592. {
  14593. line_error(sprintf(__("%c%s expects a single character `i' or `j' as argument"), ord('@'), $macro), $line_nr);
  14594. }
  14595. elsif ($args->[0] ne 'i' and $args->[0] ne 'j')
  14596. { # FIXME an unformatted arg would have been better. Not a big deal.
  14597. line_error (sprintf(__("%c%s expects `i' or `j' as argument, not `%s'"), ord('@'), $macro, $args->[0]), $line_nr);
  14598. }
  14599. }
  14600. if (defined($style))
  14601. { # known style
  14602. $result = &$Texi2HTML::Config::style($style, $macro, $text, $args, $no_close, $no_open, $line_nr, $state, $state->{'command_stack'}, $kept_line_nrs);
  14603. }
  14604. if (!$no_close)
  14605. {
  14606. close_arg($macro,$arg_nr, $state);
  14607. }
  14608. return $result;
  14609. }
  14610. elsif ($macro =~ /^special_(\w+)_(\d+)$/o)
  14611. {
  14612. my $style = $1;
  14613. my $count = $2;
  14614. msg_debug ("Bug? text in \@$macro not empty", $line_nr) if ($text ne '');
  14615. if (defined($Texi2HTML::Config::command_handler{$style}) and
  14616. defined($Texi2HTML::Config::command_handler{$style}->{'expand'}))
  14617. {
  14618. my $struct_count = 1+ $special_commands{$style}->{'max'} - $special_commands{$style}->{'count'};
  14619. # may happen for text expanded more than once, for example
  14620. # in invalid/tex_in_copying
  14621. if (($count != $struct_count) and $T2H_DEBUG)
  14622. {
  14623. msg_debug ("count $count in \@special $style and structure $struct_count differ", $line_nr);
  14624. }
  14625. $special_commands{$style}->{'count'}--;
  14626. }
  14627. my $result = $Texi2HTML::Config::command_handler{$style}->{'expand'}
  14628. ($style,$count,$state,$text);
  14629. $result = '' if (!defined($result));
  14630. return $result;
  14631. }
  14632. # Unknown macro
  14633. my $result = '';
  14634. my ($done, $result_text, $message) = &$Texi2HTML::Config::unknown_style($macro, $text, $state, $no_close, $no_open);
  14635. if ($done)
  14636. {
  14637. line_warn($message, $line_nr) if (defined($message));
  14638. if (defined($result_text))
  14639. {
  14640. $result = $result_text;
  14641. }
  14642. }
  14643. else
  14644. {
  14645. unless ($no_open)
  14646. { # we warn only if no_open is true, i.e. it is the first time we
  14647. # close the macro for a multiline macro
  14648. line_error (sprintf(__("Unknown command with braces `\@%s'"), $macro), $line_nr);
  14649. $result = do_text("\@${macro}{");
  14650. }
  14651. $result .= $text;
  14652. $result .= do_text('}') unless ($no_close);
  14653. }
  14654. return $result;
  14655. }
  14656. sub do_unknown($$$$$$$)
  14657. {
  14658. my $pass = shift;
  14659. my $macro = shift;
  14660. my $line = shift;
  14661. my $text = shift;
  14662. my $stack = shift;
  14663. my $state = shift;
  14664. my $line_nr = shift;
  14665. #print STDERR "do_unknown[$pass]($macro) ::: $line";
  14666. my ($result_line, $result, $result_text, $message) = &$Texi2HTML::Config::unknown($macro, $line, $pass, $stack,$state);
  14667. if ($result)
  14668. {
  14669. add_prev ($text, $stack, $result_text) if (defined($result_text));
  14670. line_warn($message, $line_nr) if (defined($message));
  14671. # if $state->{'preformatted'}, assume that the preformatted is
  14672. # already opened. Otherwise we may end up opening one each time
  14673. # there is an unknown command.
  14674. begin_paragraph_after_command($state, $stack, $macro, $result_line)
  14675. if (!$state->{'preformatted'});
  14676. return $result_line;
  14677. }
  14678. elsif ($pass == 2)
  14679. {
  14680. if ($Texi2HTML::Config::style_map{$macro})
  14681. {
  14682. line_error (sprintf(__("%c%s expected braces"), ord('@'), $macro), $line_nr);
  14683. }
  14684. elsif ($begin_line_command{$macro})
  14685. {
  14686. line_error (sprintf(__("Unexpected command `%s' here"), $macro), $line_nr);
  14687. }
  14688. else
  14689. {
  14690. line_error (sprintf(__("Unknown command `%s'"), $macro), $line_nr);
  14691. }
  14692. add_prev ($text, $stack, do_text("\@$macro"));
  14693. return $line;
  14694. }
  14695. elsif ($pass == 1)
  14696. {
  14697. add_prev ($text, $stack, "\@$macro");
  14698. return $line;
  14699. }
  14700. elsif ($pass == 0)
  14701. {
  14702. add_prev ($text, $stack, "\@$macro") unless($state->{'ignored'});
  14703. return $line;
  14704. }
  14705. }
  14706. # used only during @macro processing
  14707. sub add_text($@)
  14708. {
  14709. my $string = shift;
  14710. return if (!defined($string));
  14711. foreach my $scalar_ref (@_)
  14712. {
  14713. next unless defined($scalar_ref);
  14714. if (!defined($$scalar_ref))
  14715. {
  14716. $$scalar_ref = $string;
  14717. }
  14718. else
  14719. {
  14720. $$scalar_ref .= $string;
  14721. }
  14722. return;
  14723. }
  14724. }
  14725. sub add_prev ($$$)
  14726. {
  14727. my $text = shift;
  14728. my $stack = shift;
  14729. my $string = shift;
  14730. unless (defined($text) and ref($text) eq "SCALAR")
  14731. {
  14732. die "text not a SCALAR ref: " . ref($text) . "";
  14733. }
  14734. return if (!defined($string));
  14735. if (@$stack)
  14736. {
  14737. $stack->[-1]->{'text'} .= $string;
  14738. return;
  14739. }
  14740. if (!defined($$text))
  14741. {
  14742. $$text = $string;
  14743. }
  14744. else
  14745. {
  14746. $$text .= $string;
  14747. }
  14748. }
  14749. sub close_stack_texi($$$$)
  14750. {
  14751. my $text = shift;
  14752. my $stack = shift;
  14753. my $state = shift;
  14754. my $line_nr = shift;
  14755. return undef unless (@$stack or $state->{'raw'} or $state->{'macro'} or $state->{'macro_name'} or $state->{'ignored'});
  14756. if ($state->{'ignored'})
  14757. {
  14758. line_error (sprintf(__("Reached eof before matching \@end %s"), $state->{'ignored'}), $line_nr);
  14759. close_ignored($state, $stack);
  14760. }
  14761. if ($state->{'macro'})
  14762. {
  14763. my ($no_remaining, $result) = end_macro($state, '@end macro', "\n");
  14764. add_prev ($text, $stack, $result) if (defined($result));
  14765. line_error (sprintf(__("%cend macro not found"), ord('@')), $line_nr);
  14766. }
  14767. elsif ($state->{'macro_name'})
  14768. {
  14769. #line_warn ("closing $state->{'macro_name'} ($state->{'macro_depth'} braces missing)", $line_nr);
  14770. line_error (sprintf(__("\@%s missing close brace"), $state->{'macro_name'}), $line_nr);
  14771. while ($state->{'macro_name'})
  14772. {
  14773. close_macro_arg($state, '', $line_nr);
  14774. }
  14775. }
  14776. elsif ($state->{'verb'})
  14777. {
  14778. # warning in next pass
  14779. #line_warn ("closing \@verb", $line_nr);
  14780. $stack->[-1]->{'text'} = $state->{'verb'} . $stack->[-1]->{'text'};
  14781. delete $state->{'verb'};
  14782. }
  14783. elsif ($state->{'raw'})
  14784. {
  14785. line_error (sprintf(__("Expected \@end %s"), $state->{'raw'}), $line_nr);
  14786. my $style = pop @$stack;
  14787. add_prev ($text, $stack, $style->{'text'} . "\@end $state->{'raw'}");
  14788. delete $state->{'raw'};
  14789. }
  14790. my $stack_level = $#$stack + 1;
  14791. while ($stack_level--)
  14792. {
  14793. my $style = pop(@$stack);
  14794. # would be better in close_stack_structure
  14795. #line_warn ("closing \@-command $style->{'style'}", $line_nr) if ($style->{'style'} ne '');
  14796. close_style_texi($style, $text, $stack, $state, 1);
  14797. }
  14798. #$stack = [ ];
  14799. }
  14800. sub close_stack_structure($$$$;$)
  14801. {
  14802. my $text = shift;
  14803. my $stack = shift;
  14804. my $state = shift;
  14805. my $line_nr = shift;
  14806. my $close_only_item = shift;
  14807. $close_only_item = 0 if (!defined($close_only_item));
  14808. return undef unless (@$stack or $state->{'raw'});
  14809. #print STDERR "close_stack_structure ($close_only_item)\n";
  14810. #dump_stack ($text, $stack, $state);
  14811. my $stack_level = $#$stack + 1;
  14812. my $string = '';
  14813. if ($state->{'verb'})
  14814. {
  14815. $stack->[-1]->{'text'} = $state->{'verb'} . $stack->[-1]->{'text'};
  14816. #$string .= $state->{'verb'};
  14817. }
  14818. while ($stack_level--)
  14819. {
  14820. last if ($close_only_item and defined($stack->[-1]->{'format'}));
  14821. my $top_stack = pop @$stack;
  14822. if ($top_stack->{'format'})
  14823. {
  14824. my $format = $top_stack->{'format'};
  14825. if ($format eq 'index_item')
  14826. {
  14827. enter_table_index_entry($text, $stack, $state, $line_nr);
  14828. }
  14829. elsif (!defined($format_type{$format}) or ($format_type{$format} ne 'fake'))
  14830. {
  14831. end_format_structure($format_type{$format}, $text, $stack, $state, $line_nr, "\n");
  14832. }
  14833. }
  14834. elsif (defined($top_stack->{'style'}))
  14835. {
  14836. add_prev($text, $stack,
  14837. close_structure_command($top_stack, $state, 1, $line_nr));
  14838. }
  14839. }
  14840. #$stack = [ ];
  14841. }
  14842. # This is used in pass 2 and 3.
  14843. sub open_region($$)
  14844. {
  14845. my $command = shift;
  14846. my $state = shift;
  14847. if (!exists($state->{'region_lines'}))
  14848. {
  14849. # FIXME 'format' is badly choosen 'region_name' would be much better
  14850. $state->{'region_lines'}->{'format'} = $command;
  14851. $state->{'region_lines'}->{'number'} = 1;
  14852. $state->{'region_lines'}->{'kept_place'} = $state->{'place'};
  14853. $state->{'place'} = $no_element_associated_place;
  14854. $state->{'region'} = $command;
  14855. $state->{'multiple_pass'}++;
  14856. $state->{'region_pass'} = 1;
  14857. }
  14858. else
  14859. {
  14860. $state->{'region_lines'}->{'number'}++;
  14861. }
  14862. }
  14863. # close region like @insertcopying, titlepage...
  14864. # restore $state and delete the structure
  14865. # This is used in pass 2 and 3.
  14866. sub close_region($)
  14867. {
  14868. my $state = shift;
  14869. $state->{'place'} = $state->{'region_lines'}->{'kept_place'};
  14870. $state->{'multiple_pass'}--;
  14871. delete $state->{'region_lines'}->{'number'};
  14872. delete $state->{'region_lines'}->{'format'};
  14873. delete $state->{'region_lines'}->{'kept_place'};
  14874. delete $state->{'region_lines'};
  14875. delete $state->{'region'};
  14876. delete $state->{'region_pass'};
  14877. }
  14878. # close the stack, closing @-commands and formats left open.
  14879. # if a $format is given if $format is encountered the closing stops
  14880. sub close_stack($$$$;$)
  14881. {
  14882. my $text = shift;
  14883. my $stack = shift;
  14884. my $state = shift;
  14885. my $line_nr = shift;
  14886. my $format = shift;
  14887. #print STDERR "sub_close_stack\n";
  14888. if (@$stack)
  14889. {
  14890. my $stack_level = $#$stack + 1;
  14891. #debugging
  14892. #my $print_format = 'NO FORMAT';
  14893. #$print_format = $format if ($format);
  14894. #msg_debug ("Close_stack: format $print_format", $line_nr);
  14895. while ($stack_level--)
  14896. {
  14897. if ($stack->[$stack_level]->{'format'})
  14898. {
  14899. my $stack_format = $stack->[$stack_level]->{'format'};
  14900. last if (defined($format) and $stack_format eq $format);
  14901. # We silently close paragraphs, preformatted sections and fake formats
  14902. if ($stack_format eq 'paragraph')
  14903. {
  14904. my $paragraph = pop @$stack;
  14905. add_prev ($text, $stack, do_paragraph($paragraph->{'text'}, $state, $stack));
  14906. }
  14907. elsif ($stack_format eq 'preformatted')
  14908. {
  14909. my $paragraph = pop @$stack;
  14910. add_prev ($text, $stack, do_preformatted($paragraph->{'text'}, $state, $stack));
  14911. }
  14912. else
  14913. {
  14914. if ($fake_format{$stack_format})
  14915. {
  14916. warn "# Closing a fake format `$stack_format'\n" if ($T2H_VERBOSE);
  14917. }
  14918. elsif ($stack_format ne 'center')
  14919. { # we don't warn for center
  14920. line_error (sprintf(__("No matching `%cend %s'"), ord('@'), $stack_format), $line_nr);
  14921. #dump_stack ($text, $stack, $state);
  14922. }
  14923. if ($state->{'keep_texi'})
  14924. {
  14925. add_prev($text, $stack, "\@end $stack_format");
  14926. }
  14927. elsif (!$state->{'remove_texi'})
  14928. {
  14929. end_format($text, $stack, $state, $stack_format, $line_nr)
  14930. unless ($format_type{$stack_format} eq 'fake');
  14931. }
  14932. }
  14933. }
  14934. else
  14935. {
  14936. my $style = $stack->[$stack_level]->{'style'};
  14937. ########################## debug
  14938. if (!defined($style))
  14939. {
  14940. print STDERR "Bug: style not defined, on stack\n";
  14941. dump_stack ($text, $stack, $state); # bug
  14942. }
  14943. ########################## end debug
  14944. my $located_line_nr = $line_nr;
  14945. # use the beginning of the @-command for the error message
  14946. # line number if available.
  14947. $located_line_nr = $stack->[$stack_level]->{'line_nr'} if (defined($stack->[$stack_level]->{'line_nr'}));
  14948. # $state->{'verb'} may not be defined if the @verb{ opening
  14949. # is followed by an end of line.
  14950. if ($style eq 'verb' and defined($state->{'verb'}))
  14951. {
  14952. line_error (sprintf(__("\@%s missing closing delimiter sequence: %s}"), $style, $state->{'verb'}), $located_line_nr);
  14953. }
  14954. else
  14955. {
  14956. line_error (sprintf(__("%c%s missing close brace"), ord('@'), $style), $located_line_nr);
  14957. }
  14958. my ($result, $command) = close_style_command($text, $stack, $state, $line_nr, '');
  14959. add_prev($text, $stack, $result) if (defined($result));
  14960. }
  14961. }
  14962. }
  14963. # This tries to avoid cases where the command_stack is not empty
  14964. # for a good reason, for example when doing a @def formatting the
  14965. # outside command_stack is preserved. Also when expanding for
  14966. # example @titleplage or @copying.
  14967. # FIXME sort out which cases it is.
  14968. return if ($format or (defined($state->{'multiple_pass'}) and $state->{'multiple_pass'} > 0) or $state->{'no_paragraph'});
  14969. # The pending style commands are cleared here; And are closed next.
  14970. delete $state->{'paragraph_macros'};
  14971. # go through the command_stack and warn for each opened style format
  14972. # and remove it. Those should be there because there is an opened style
  14973. # that was stopped by a paragraph
  14974. my @command_stack = @{$state->{'command_stack'}};
  14975. @{$state->{'command_stack'}} = ();
  14976. while (@command_stack)
  14977. {
  14978. my $latest_command = pop @command_stack;
  14979. if (defined($style_type{$latest_command}) and $style_type{$latest_command} ne 'special')
  14980. {
  14981. line_error (sprintf(__("%c%s missing close brace"), ord('@'), $latest_command), $line_nr);
  14982. }
  14983. else
  14984. {
  14985. unshift @{$state->{'command_stack'}}, $latest_command;
  14986. }
  14987. }
  14988. }
  14989. # given a stack and a list of formats, return true if the stack contains
  14990. # these formats, first on top
  14991. sub stack_order($@)
  14992. {
  14993. my $stack = shift;
  14994. my $stack_level = $#$stack + 1;
  14995. while (@_)
  14996. {
  14997. my $format = shift;
  14998. while ($stack_level--)
  14999. {
  15000. if ($stack->[$stack_level]->{'format'})
  15001. {
  15002. if ($stack->[$stack_level]->{'format'} eq $format)
  15003. {
  15004. $format = undef;
  15005. last;
  15006. }
  15007. else
  15008. {
  15009. return 0;
  15010. }
  15011. }
  15012. }
  15013. return 0 if ($format);
  15014. }
  15015. return 1;
  15016. }
  15017. sub top_format($)
  15018. {
  15019. my $stack = shift;
  15020. my $stack_level = $#$stack + 1;
  15021. while ($stack_level--)
  15022. {
  15023. if ($stack->[$stack_level]->{'format'} and !$fake_format{$stack->[$stack_level]->{'format'}})
  15024. {
  15025. return $stack->[$stack_level];
  15026. }
  15027. }
  15028. return undef;
  15029. }
  15030. sub close_paragraph($$$$;$$)
  15031. {
  15032. my $text = shift;
  15033. my $stack = shift;
  15034. my $state = shift;
  15035. my $reason = shift;
  15036. my $line_nr = shift;
  15037. my $no_preformatted_closing = shift;
  15038. #print STDERR "CLOSE_PARAGRAPH\n";
  15039. #dump_stack($text, $stack, $state);
  15040. # close until the first format,
  15041. # duplicate stack of styles not closed
  15042. my $new_stack;
  15043. my $stack_level = $#$stack + 1;
  15044. # In general close_paragraph is called because of a end of line, or
  15045. # a format is opened or closed, or there is a @tab or @item and other
  15046. # similar cases. In most cases there is a paragraph to be closed or
  15047. # there are no style opened since most @-commands cause paragraph
  15048. # opening and those that don't should not lead to a style opening.
  15049. #
  15050. # But in term or in @index (and maybe @node, @section, @ref), if
  15051. # there is a command opened it won't be closed, since it is in
  15052. # 'no_paragraph'. But @-commands that trigger close_paragraph should not
  15053. # be called when in those no_paragraph settings.
  15054. if ($state->{'no_paragraph'})
  15055. { # This plays the role of "Multiline command %c%s used improperly"
  15056. line_error(sprintf(__("%s should not appear in %s"), $reason, $state->{'no_paragraph_stack'}->[-1]), $line_nr);
  15057. }
  15058. while ($stack_level--)
  15059. {
  15060. last if ($stack->[$stack_level]->{'format'});
  15061. my $style = $stack->[$stack_level]->{'style'};
  15062. # the !exists($style_type{$style}) condition catches the unknown
  15063. # @-commands: by default they are considered as style commands
  15064. if (!$state->{'no_paragraph'})
  15065. {
  15066. if (!exists($style_type{$style}) or $style_type{$style} eq 'style')
  15067. {
  15068. unshift @$new_stack, { 'style' => $style, 'text' => '', 'no_open' => 1, 'arg_nr' => 0 };
  15069. }
  15070. elsif (($style_type{$style} eq 'simple_style') or ($style_type{$style} eq 'accent'))
  15071. {
  15072. }
  15073. else
  15074. {
  15075. # it shouldn't be possible to have 'special' styles, like
  15076. # images, footnotes, xrefs, anchors, as
  15077. # close_paragraph shouldn't be called with keep_texi
  15078. # and when the arguments are expanded, there is a
  15079. # substitute_line or similar with a new stack.
  15080. msg_debug("BUG: special $style while closing paragraph", $line_nr);
  15081. }
  15082. }
  15083. # if not in a paragraph, the command is simply closed, and not recorded
  15084. # in new_stack.
  15085. my ($result, $command) = close_style_command($text, $stack, $state, $line_nr, '', (!$state->{'no_paragraph'}));
  15086. add_prev($text, $stack, $result) if (defined($result));
  15087. }
  15088. if (!$state->{'paragraph_context'} and !$state->{'preformatted'} and defined($new_stack) and scalar(@$new_stack))
  15089. { # in that case the $new_stack isn't recorded in $state->{'paragraph_macros'}
  15090. # and therefore, it is lost
  15091. msg_debug ("closing paragraph, but not in paragraph/preformatted, and new_stack not empty", $line_nr);
  15092. dump_stack($text, $stack, $state);
  15093. }
  15094. my $top_stack = top_stack($stack);
  15095. if ($top_stack and !defined($top_stack->{'format'}))
  15096. { #debug
  15097. msg_debug("Bug: no format on top stack", $line_nr);
  15098. dump_stack($text, $stack, $state);
  15099. }
  15100. if ($top_stack and ($top_stack->{'format'} eq 'paragraph'))
  15101. {
  15102. my $paragraph = pop @$stack;
  15103. add_prev($text, $stack, do_paragraph($paragraph->{'text'}, $state, $stack));
  15104. $state->{'paragraph_macros'} = $new_stack;
  15105. return 1;
  15106. }
  15107. elsif ($top_stack and ($top_stack->{'format'} eq 'preformatted') and !$no_preformatted_closing)
  15108. {
  15109. my $paragraph = pop @$stack;
  15110. add_prev($text, $stack, do_preformatted($paragraph->{'text'}, $state, $stack));
  15111. $state->{'paragraph_macros'} = $new_stack;
  15112. return 1;
  15113. }
  15114. return;
  15115. }
  15116. sub abort_empty_preformatted($$)
  15117. {
  15118. my $stack = shift;
  15119. my $state = shift;
  15120. if (@$stack and $stack->[-1]->{'format'}
  15121. and ($stack->[-1]->{'format'} eq 'preformatted')
  15122. and ($stack->[-1]->{'text'} !~ /\S/))
  15123. {
  15124. if (defined($Texi2HTML::Config::empty_preformatted))
  15125. {
  15126. return if (&$Texi2HTML::Config::empty_preformatted($stack->[-1]->{'text'}));
  15127. }
  15128. pop @$stack;
  15129. }
  15130. }
  15131. # for debugging
  15132. sub dump_stack($$$)
  15133. {
  15134. my $text = shift;
  15135. my $stack = shift;
  15136. my $state = shift;
  15137. if (defined($$text))
  15138. {
  15139. print STDERR "text: $$text\n";
  15140. }
  15141. else
  15142. {
  15143. print STDERR "text: UNDEF\n";
  15144. }
  15145. my $in_remove = 0;
  15146. my $in_simple_format = 0;
  15147. my $in_keep = 0;
  15148. $in_keep = 1 if ($state->{'keep_texi'});
  15149. if (!$in_keep)
  15150. {
  15151. $in_simple_format = 1 if ($state->{'simple_format'});
  15152. $in_remove = 1 if ($state->{'remove_texi'} and !$in_simple_format);
  15153. }
  15154. print STDERR "state[$state](k${in_keep}s${in_simple_format}r${in_remove}): ";
  15155. foreach my $key (keys(%$state))
  15156. {
  15157. my $value = 'UNDEF';
  15158. $value = $state->{$key} if (defined($state->{$key}));
  15159. print STDERR "$key: $value " if (!ref($value));
  15160. }
  15161. print STDERR "\n";
  15162. my $stack_level = $#$stack + 1;
  15163. while ($stack_level--)
  15164. {
  15165. print STDERR " $stack_level-> ";
  15166. foreach my $key (keys(%{$stack->[$stack_level]}))
  15167. {
  15168. my $value = 'UNDEF';
  15169. $value = $stack->[$stack_level]->{$key} if
  15170. (defined($stack->[$stack_level]->{$key}));
  15171. print STDERR "$key: $value ";
  15172. }
  15173. print STDERR "\n";
  15174. }
  15175. if (defined($state->{'command_stack'}))
  15176. {
  15177. print STDERR "command_stack: ";
  15178. foreach my $style (@{$state->{'command_stack'}})
  15179. {
  15180. print STDERR "($style) ";
  15181. }
  15182. print STDERR "\n";
  15183. }
  15184. if (defined($state->{'region_lines'}))
  15185. {
  15186. print STDERR "region_lines($state->{'region_lines'}->{'number'}): $state->{'region_lines'}->{'format'}\n";
  15187. }
  15188. if (defined($state->{'paragraph_macros'}))
  15189. {
  15190. print STDERR "paragraph_macros: ";
  15191. foreach my $style (@{$state->{'paragraph_macros'}})
  15192. {
  15193. print STDERR "($style->{'style'})";
  15194. }
  15195. print STDERR "\n";
  15196. }
  15197. if (defined($state->{'preformatted_stack'}))
  15198. {
  15199. print STDERR "preformatted_stack: ";
  15200. foreach my $preformatted_style (@{$state->{'preformatted_stack'}})
  15201. {
  15202. if ($preformatted_style eq '')
  15203. {
  15204. print STDERR ".";
  15205. next;
  15206. }
  15207. my $pre_style = '';
  15208. $pre_style = $preformatted_style->{'pre_style'} if (exists $preformatted_style->{'pre_style'});
  15209. my $class = '';
  15210. $class = $preformatted_style->{'class'} if (exists $preformatted_style->{'class'});
  15211. my $style = '';
  15212. $style = $preformatted_style->{'style'} if (exists $preformatted_style->{'style'});
  15213. print STDERR "($pre_style, $class,$style)";
  15214. }
  15215. print STDERR "\n";
  15216. }
  15217. if (defined($state->{'text_macro_stack'}) and @{$state->{'text_macro_stack'}})
  15218. {
  15219. print STDERR "text_macro_stack: (@{$state->{'text_macro_stack'}})\n";
  15220. }
  15221. }
  15222. # for debugging
  15223. sub print_elements($)
  15224. {
  15225. my $elements = shift;
  15226. foreach my $elem(@$elements)
  15227. {
  15228. if ($elem->{'node'})
  15229. {
  15230. print STDERR "node-> $elem ";
  15231. }
  15232. else
  15233. {
  15234. print STDERR "chap=> $elem ";
  15235. }
  15236. foreach my $key (keys(%$elem))
  15237. {
  15238. my $value = "UNDEF";
  15239. $value = $elem->{$key} if (defined($elem->{$key}));
  15240. print STDERR "$key: $value ";
  15241. }
  15242. print STDERR "\n";
  15243. }
  15244. }
  15245. # for debugging
  15246. sub context_string(;$$$)
  15247. {
  15248. my $state = shift;
  15249. my $line_nr = shift;
  15250. my $message = shift;
  15251. $state = $Texi2HTML::THISDOC{'state'}
  15252. if (!defined($state) and defined($Texi2HTML::THISDOC{'state'}));
  15253. $line_nr = $Texi2HTML::THISDOC{'line_nr'}
  15254. if (!defined($line_nr) and defined($Texi2HTML::THISDOC{'line_nr'}));
  15255. my $result = "Pass $global_pass";
  15256. my $line_info = ', no line information';
  15257. $line_info = ' ' .format_line_number($line_nr) if (defined($line_nr));
  15258. $result .= $line_info;
  15259. if (!defined($state))
  15260. {
  15261. $result .= ', no state information';
  15262. }
  15263. else
  15264. {
  15265. $result .= ", context $state->{'context'}" if defined($state->{'context'});
  15266. my $expand = '';
  15267. if ($state->{'keep_texi'})
  15268. {
  15269. $expand .= ' no expansion';
  15270. }
  15271. if ($state->{'remove_texi'})
  15272. {
  15273. $expand .= ' raw';
  15274. }
  15275. if ($state->{'preformatted'})
  15276. {
  15277. $expand .= ' preformatted';
  15278. }
  15279. if ($state->{'code_style'})
  15280. {
  15281. $expand .= " 'code'";
  15282. }
  15283. if ($state->{'simple_format'})
  15284. {
  15285. $expand .= ' simple';
  15286. }
  15287. $expand = ' normal' if (!$expand);
  15288. $result .= ',' . $expand;
  15289. if ($state->{'expansion'})
  15290. {
  15291. $result .= ", \@$state->{'expansion'}";
  15292. }
  15293. if ($state->{'region'})
  15294. {
  15295. $result .= ", region $state->{'region'}";
  15296. }
  15297. if ($state->{'outside_document'})
  15298. {
  15299. $result .= "; out";
  15300. }
  15301. if ($state->{'inside_document'})
  15302. {
  15303. $result .= "; in";
  15304. }
  15305. if ($state->{'multiple_pass'})
  15306. {
  15307. $result .= "; multiple $state->{'multiple_pass'}";
  15308. }
  15309. if ($state->{'new_state'})
  15310. {
  15311. $result .= "; new";
  15312. }
  15313. if ($state->{'duplicated'})
  15314. {
  15315. $result .= "; duplicated";
  15316. }
  15317. }
  15318. $result .= "(in @{$Texi2HTML::THISDOC{'command_stack'}})"
  15319. if (defined ($Texi2HTML::THISDOC{'command_stack'}) and @{$Texi2HTML::THISDOC{'command_stack'}});
  15320. $result .= ' ' .$message if ($message);
  15321. return $result;
  15322. }
  15323. my @states_stack = ();
  15324. sub push_state($)
  15325. {
  15326. my $new_state = shift;
  15327. push @states_stack, $new_state;
  15328. $Texi2HTML::THISDOC{'state'} = $new_state;
  15329. }
  15330. sub pop_state()
  15331. {
  15332. pop @states_stack;
  15333. if (@states_stack)
  15334. {
  15335. $Texi2HTML::THISDOC{'state'} = $states_stack[-1];
  15336. }
  15337. else
  15338. {
  15339. $Texi2HTML::THISDOC{'state'} = undef;
  15340. }
  15341. }
  15342. sub substitute_line($$;$$)
  15343. {
  15344. my $line = shift;
  15345. my $context_string = shift;
  15346. my $state = shift;
  15347. my $line_nr = shift;
  15348. $state = {} if (!defined($state));
  15349. $state->{'no_paragraph'} = 1;
  15350. if (($state->{'inside_document'} or $state->{'outside_document'}) and (!$state->{'duplicated'} and !$state->{'new_state'}))
  15351. {
  15352. msg_debug("substitute_line with main state in: ".var_to_str($context_string), $line_nr);
  15353. }
  15354. push @{$state->{'no_paragraph_stack'}}, $context_string;
  15355. # this is usefull when called from &$I, and also for image files
  15356. return simple_format($state, [ $line_nr ], $context_string, $line) if ($state->{'simple_format'});
  15357. return substitute_text($state, [ $line_nr ], $context_string, $line);
  15358. }
  15359. sub substitute_text($$$@)
  15360. {
  15361. my $state = shift;
  15362. my $line_nrs = shift;
  15363. my $context = shift;
  15364. my @stack = ();
  15365. my $text = '';
  15366. my $result = '';
  15367. my $line_nr;
  15368. if ($state->{'structure'})
  15369. {
  15370. initialise_state_structure($state);
  15371. }
  15372. elsif ($state->{'texi'})
  15373. { # only in arg_expansion
  15374. initialise_state_texi($state);
  15375. msg_bug("substitute_text, 'texi' true but not 'arg_expansion'") if (!$state->{'arg_expansion'});
  15376. }
  15377. else
  15378. {
  15379. #print STDERR "FILL_STATE substitute_text ($state->{'preformatted'}): @_\n";
  15380. if (($state->{'inside_document'} or $state->{'outside_document'}) and (!$state->{'duplicated'} and !$state->{'new_state'}))
  15381. {
  15382. msg_debug("substitute_text with main state in: ".var_to_str($context), $line_nr);
  15383. }
  15384. fill_state($state);
  15385. $state->{'context'} = $context;
  15386. }
  15387. $state->{'spool'} = [];
  15388. #print STDERR "SUBST_TEXT ".var_to_str($context)."\n";
  15389. push_state($state);
  15390. my $line_nrs_kept = $Texi2HTML::THISDOC{'line_nr'};
  15391. $Texi2HTML::THISDOC{'line_nr'} = undef;
  15392. while (@_ or @{$state->{'spool'}} or $state->{'in_deff_line'})
  15393. {
  15394. my $line;
  15395. if ($line_nrs and @{$line_nrs})
  15396. {
  15397. $line_nr = shift @{$line_nrs};
  15398. $Texi2HTML::THISDOC{'line_nr'} = $line_nr;
  15399. }
  15400. if (@{$state->{'spool'}})
  15401. {
  15402. $line = shift @{$state->{'spool'}};
  15403. }
  15404. else
  15405. {
  15406. $line = shift @_;
  15407. }
  15408. # msg_debug ("SUBSTITUTE_TEXT $line", $line_nr) if (defined($line_nr));
  15409. if ($state->{'in_deff_line'})
  15410. {
  15411. if (defined($line))
  15412. {
  15413. $line = $state->{'in_deff_line'} . $line;
  15414. }
  15415. else
  15416. {
  15417. $line = $state->{'in_deff_line'};
  15418. }
  15419. delete $state->{'in_deff_line'};
  15420. }
  15421. else
  15422. {
  15423. next unless (defined($line));
  15424. }
  15425. #{ my $p_line = $line; chomp($p_line); print STDERR "SUBST_TEXT $p_line\n"; }
  15426. if ($state->{'structure'})
  15427. {
  15428. scan_structure ($line, \$text, \@stack, $state);
  15429. }
  15430. elsif ($state->{'texi'})
  15431. {
  15432. scan_texi ($line, \$text, \@stack, $state);
  15433. }
  15434. else
  15435. {
  15436. set_line_nr_in_stack($state, \@stack, $line_nr);
  15437. scan_line($line, \$text, \@stack, $state, $line_nr);
  15438. }
  15439. next if (@stack);
  15440. $result .= $text;
  15441. $text = '';
  15442. }
  15443. if ($line_nrs and @{$line_nrs})
  15444. {
  15445. $line_nr = shift @{$line_nrs};
  15446. $Texi2HTML::THISDOC{'line_nr'} = $line_nr;
  15447. }
  15448. # close stack in substitute_text
  15449. if ($state->{'texi'})
  15450. {
  15451. close_stack_texi(\$text, \@stack, $state, $line_nr);
  15452. }
  15453. elsif ($state->{'structure'})
  15454. {
  15455. close_stack_structure(\$text, \@stack, $state, $line_nr);
  15456. }
  15457. else
  15458. {
  15459. close_stack(\$text, \@stack, $state, $line_nr);
  15460. }
  15461. #print STDERR "SUBST_TEXT end\n";
  15462. pop_state();
  15463. $Texi2HTML::THISDOC{'line_nr'} = $line_nrs_kept;
  15464. return $result . $text;
  15465. }
  15466. sub print_lines($;$)
  15467. {
  15468. my ($fh, $lines) = @_;
  15469. $lines = $Texi2HTML::THIS_SECTION unless $lines;
  15470. my @cnt;
  15471. my $cnt;
  15472. for my $line (@$lines)
  15473. {
  15474. print $fh $line;
  15475. if (get_conf('WORDS_IN_PAGE') and (get_conf('SPLIT') eq 'node'))
  15476. {
  15477. @cnt = split(/\W*\s+\W*/, $line);
  15478. $cnt += scalar(@cnt);
  15479. }
  15480. }
  15481. return $cnt;
  15482. }
  15483. sub do_index_entry_label($$$$;$)
  15484. {
  15485. my $command = shift;
  15486. my $state = shift;
  15487. my $line_nr = shift;
  15488. my $entry_texi = shift;
  15489. # this is only needed for definitions since the whole line is parsed to
  15490. # reuse get_deff_index.
  15491. my $line = shift;
  15492. my $prefix = index_entry_command_prefix($command, $line, $line_nr);
  15493. my $index_name = $index_prefix_to_name{$prefix};
  15494. msg_debug("do_index_entry_label($command): Undefined entry_texi", $line_nr)
  15495. if (!defined($entry_texi));
  15496. $entry_texi = trim_comment_spaces($entry_texi, "index label in \@$command", $line_nr);
  15497. # index entries are not entered in special regions
  15498. my $region = 'document';
  15499. $region = $state->{'region'} if (defined($state->{'region'}));
  15500. my $entry;
  15501. # Can be within a @caption expanded within a listoffloat. In that
  15502. # case the 2 conditions on state are not set.
  15503. if (defined($state->{'region'}) or !defined($state->{'expansion'}))
  15504. {
  15505. # index entry on a line that is not searched for index entries, like
  15506. # a @def* line
  15507. if (!defined($Texi2HTML::THISDOC{'index_entries'}->{$region}) or !defined($Texi2HTML::THISDOC{'index_entries'}->{$region}->{$entry_texi}))
  15508. {
  15509. line_warn(sprintf(__("Index entry not caught: `%s' in %s"), $entry_texi, $region), $line_nr);
  15510. }
  15511. else
  15512. {
  15513. my $entry_ref = $Texi2HTML::THISDOC{'index_entries'}->{$region}->{$entry_texi};
  15514. # ============================ debug
  15515. if (!defined($entry_ref->{'entries'}))
  15516. {
  15517. msg_debug("BUG, not defined: {'index_entries'}->{$region}->{$entry_texi}->{'entries'}", $line_nr);
  15518. }
  15519. # ============================ end debug
  15520. if (scalar(@{$entry_ref->{'entries'}}) > 1)
  15521. {
  15522. if (!defined($entry_ref->{'index'}))
  15523. {
  15524. $entry_ref->{'index'} = 0;
  15525. }
  15526. $entry = $entry_ref->{'entries'}->[$entry_ref->{'index'}];
  15527. $entry_ref->{'index'}++;
  15528. }
  15529. else
  15530. {
  15531. $entry = $entry_ref->{'entries'}->[0];
  15532. }
  15533. $entry->{'seen_in_output'} = 1 if (!$state->{'outside_document'});
  15534. ############################################# debug
  15535. # verify that the old way of getting index entries (in an array) is
  15536. # synchronized with the document
  15537. if (!$state->{'region'})
  15538. {
  15539. my $entry_from_array = shift @index_labels;
  15540. if ($entry_from_array ne $entry)
  15541. {
  15542. msg_debug ("entry `$entry->{'texi'}' ne entry_from_array `$entry_from_array->{'texi'}'", $line_nr);
  15543. }
  15544. if (!defined($entry_from_array))
  15545. {
  15546. mesg_debug ("Not enough index entries !", $line_nr);
  15547. }
  15548. }
  15549. ############################################# end debug
  15550. }
  15551. }
  15552. if (!defined($entry))
  15553. {
  15554. # this can happen for listoffloats and caption without being a user
  15555. # error. Well, in fact, it could be argued that it is indeed a user
  15556. # error, putting an index entry in a snippet that can be expanded
  15557. # more than once and is not strictly associated with a node/section.
  15558. #print STDERR "Entry for index $index_name not gathered in usual places ($region)\n";
  15559. $entry = {
  15560. 'command' => $command,
  15561. 'texi' => $entry_texi,
  15562. 'entry' => $entry_texi,
  15563. 'prefix' => $prefix,
  15564. 'index_name' => $index_name,
  15565. };
  15566. $entry->{'key'} = sorted_line($entry_texi);
  15567. $entry->{'entry'} = '@code{'.$entry->{'entry'}.'}'
  15568. if (defined($index_name) and
  15569. defined($index_names{$index_name}) and
  15570. $index_names{$index_name}->{$prefix}
  15571. and $entry->{'key'} =~ /\S/);
  15572. }
  15573. ###################################### debug
  15574. else
  15575. {
  15576. if ($entry->{'prefix'} ne $prefix)
  15577. {
  15578. msg_debug ("prefix in entry $entry->{'prefix'} ne $prefix from $command", $line_nr);
  15579. }
  15580. }
  15581. if ($command ne $entry->{'command'})
  15582. {
  15583. # happened with bad texinfo with a line like
  15584. # @deffn func aaaa args @defvr c--ategory d--efvr_name
  15585. # now this case is caught above by "Index entry not caught:
  15586. msg_debug ("($region) Waiting for index cmd \@$entry->{'command'} got \@$command", $line_nr);
  15587. }
  15588. if ($entry->{'texi'} ne $entry_texi)
  15589. {
  15590. msg_debug ("Waiting for index `$entry->{'texi'}', got `$entry_texi'", $line_nr);
  15591. }
  15592. my $id = 'no id';
  15593. $id = $entry->{'id'} if (defined($entry->{'id'}));
  15594. print STDERR "(index($index_name) $command) [$entry->{'entry'}] $id\n"
  15595. if ($T2H_DEBUG & $DEBUG_INDEX);
  15596. ###################################### end debug
  15597. #return (undef,'','') if ($state->{'region'});
  15598. if ($entry->{'key'} =~ /^\s*$/)
  15599. {
  15600. line_warn(sprintf(__("Empty index entry for \@%s"), $command), $entry->{'line_nr'});
  15601. }
  15602. my $formatted_entry = substitute_line($entry->{'entry'}, "\@$command", prepare_state_multiple_pass("${command}_index", $state),$entry->{'line_nr'});
  15603. my $formatted_entry_reference = substitute_line($entry->{'texi'}, "\@$command", prepare_state_multiple_pass("${command}_index", $state));
  15604. return ($entry, $formatted_entry, &$Texi2HTML::Config::index_entry_label($entry->{'id'}, $state->{'preformatted'}, $formatted_entry,
  15605. $index_name,
  15606. $command, $entry->{'texi'}, $formatted_entry_reference,
  15607. (!$entry->{'seen_in_output'} and defined($entry->{'region'})),$entry));
  15608. }
  15609. # decompose a decimal number on a given base. The algorithm looks like
  15610. # the division with growing powers (division suivant les puissances
  15611. # croissantes) ?
  15612. sub decompose($$)
  15613. {
  15614. my $number = shift;
  15615. my $base = shift;
  15616. my @result = ();
  15617. return (0) if ($number == 0);
  15618. my $power = 1;
  15619. my $remaining = $number;
  15620. while ($remaining)
  15621. {
  15622. my $factor = $remaining % ($base ** $power);
  15623. $remaining -= $factor;
  15624. push (@result, $factor / ($base ** ($power - 1)));
  15625. $power++;
  15626. }
  15627. return @result;
  15628. }
  15629. # process a css file
  15630. sub process_css_file ($$)
  15631. {
  15632. my $fh =shift;
  15633. my $file = shift;
  15634. my $in_rules = 0;
  15635. my $in_comment = 0;
  15636. my $in_import = 0;
  15637. my $in_string = 0;
  15638. my $rules = [];
  15639. my $imports = [];
  15640. my $line_nr = 0;
  15641. while (my $line = <$fh>)
  15642. {
  15643. $line_nr++;
  15644. #print STDERR "Line: $line";
  15645. if ($in_rules)
  15646. {
  15647. push @$rules, $line;
  15648. next;
  15649. }
  15650. my $text = '';
  15651. while (1)
  15652. {
  15653. #sleep 1;
  15654. #print STDERR "${text}!in_comment $in_comment in_rules $in_rules in_import $in_import in_string $in_string: $line";
  15655. if ($in_comment)
  15656. {
  15657. if ($line =~ s/^(.*?\*\/)//)
  15658. {
  15659. $text .= $1;
  15660. $in_comment = 0;
  15661. }
  15662. else
  15663. {
  15664. push @$imports, $text . $line;
  15665. last;
  15666. }
  15667. }
  15668. elsif (!$in_string and $line =~ s/^\///)
  15669. { # what do '\' do here ?
  15670. if ($line =~ s/^\*//)
  15671. {
  15672. $text .= '/*';
  15673. $in_comment = 1;
  15674. }
  15675. else
  15676. {
  15677. push (@$imports, $text. "\n") if ($text ne '');
  15678. push (@$rules, '/' . $line);
  15679. $in_rules = 1;
  15680. last;
  15681. }
  15682. }
  15683. elsif (!$in_string and $in_import and $line =~ s/^([\"\'])//)
  15684. { # strings outside of import start rules
  15685. $text .= "$1";
  15686. $in_string = quotemeta("$1");
  15687. }
  15688. elsif ($in_string and $line =~ s/^(\\$in_string)//)
  15689. {
  15690. $text .= $1;
  15691. }
  15692. elsif ($in_string and $line =~ s/^($in_string)//)
  15693. {
  15694. $text .= $1;
  15695. $in_string = 0;
  15696. }
  15697. elsif ((! $in_string and !$in_import) and ($line =~ s/^([\\]?\@import)$// or $line =~ s/^([\\]?\@import\s+)//))
  15698. {
  15699. $text .= $1;
  15700. $in_import = 1;
  15701. }
  15702. elsif (!$in_string and $in_import and $line =~ s/^\;//)
  15703. {
  15704. $text .= ';';
  15705. $in_import = 0;
  15706. }
  15707. elsif (($in_import or $in_string) and $line =~ s/^(.)//)
  15708. {
  15709. $text .= $1;
  15710. }
  15711. elsif (!$in_import and $line =~ s/^([^\s])//)
  15712. {
  15713. push (@$imports, $text. "\n") if ($text ne '');
  15714. push (@$rules, $1 . $line);
  15715. $in_rules = 1;
  15716. last;
  15717. }
  15718. elsif ($line =~ s/^(\s)//)
  15719. {
  15720. $text .= $1;
  15721. }
  15722. elsif ($line eq '')
  15723. {
  15724. push (@$imports, $text);
  15725. last;
  15726. }
  15727. }
  15728. }
  15729. #file_line_warn (__("string not closed in css file"), $file) if ($in_string);
  15730. #file_line_warn (__("--css-file ended in comment"), $file) if ($in_comment);
  15731. #file_line_warn (__("\@import not finished in css file"), $file) if ($in_import and !$in_comment and !$in_string);
  15732. warn (sprintf(__("%s:%d: string not closed in css file"), $file, $line_nr)) if ($in_string);
  15733. warn (sprintf(__("%s:%d: --css-file ended in comment"), $file, $line_nr)) if ($in_comment);
  15734. warn (sprintf(__("%s:%d \@import not finished in css file"), $file, $line_nr)) if ($in_import and !$in_comment and !$in_string);
  15735. return ($imports, $rules);
  15736. }
  15737. sub collect_all_css_files()
  15738. {
  15739. my @css_import_lines;
  15740. my @css_rule_lines;
  15741. # process css files
  15742. return ([],[]) if (get_conf('NO_CSS'));
  15743. foreach my $file (@Texi2HTML::Config::CSS_FILES)
  15744. {
  15745. my $css_file_fh;
  15746. my $css_file;
  15747. if ($file eq '-')
  15748. {
  15749. $css_file_fh = \*STDIN;
  15750. $css_file = '-';
  15751. }
  15752. else
  15753. {
  15754. $css_file = locate_include_file ($file);
  15755. unless (defined($css_file))
  15756. {
  15757. document_warn ("css file $file not found");
  15758. next;
  15759. }
  15760. unless (open (CSSFILE, "$css_file"))
  15761. {
  15762. warn (sprintf(__("%s: could not open --css-file %s: %s\n"), $real_command_name, $css_file, $!));
  15763. next;
  15764. }
  15765. $css_file_fh = \*CSSFILE;
  15766. }
  15767. my ($import_lines, $rules_lines);
  15768. ($import_lines, $rules_lines) = process_css_file ($css_file_fh, $css_file);
  15769. push @css_import_lines, @$import_lines;
  15770. push @css_rule_lines, @$rules_lines;
  15771. }
  15772. if ($T2H_DEBUG & $DEBUG_USER)
  15773. {
  15774. if (@css_import_lines)
  15775. {
  15776. print STDERR "# css import lines\n";
  15777. foreach my $line (@css_import_lines)
  15778. {
  15779. print STDERR "$line";
  15780. }
  15781. }
  15782. if (@css_rule_lines)
  15783. {
  15784. print STDERR "# css rule lines\n";
  15785. foreach my $line (@css_rule_lines)
  15786. {
  15787. print STDERR "$line";
  15788. }
  15789. }
  15790. }
  15791. return (\@css_import_lines, \@css_rule_lines);
  15792. }
  15793. sub collect_renamed_nodes()
  15794. {
  15795. # try to set the default if the file exists.
  15796. if (-f $Texi2HTML::THISDOC{'file_base_name'} . '-noderename.cnf')
  15797. {
  15798. set_from_document ('RENAMED_NODES_FILE', $Texi2HTML::THISDOC{'file_base_name'} . '-noderename.cnf');
  15799. }
  15800. if (defined(get_conf('RENAMED_NODES_FILE')))
  15801. {
  15802. my $renamed_nodes_file = get_conf('RENAMED_NODES_FILE');
  15803. if (open(RENAMEDFILE, "<$renamed_nodes_file"))
  15804. {
  15805. my $in_encoding = get_conf('IN_ENCODING');
  15806. if (defined($in_encoding) and get_conf('USE_UNICODE'))
  15807. {
  15808. binmode(RENAMEDFILE, ":encoding($in_encoding)");
  15809. }
  15810. my $renamd_nodes_line_nr = 0;
  15811. my @old_names = ();
  15812. while (<RENAMEDFILE>)
  15813. {
  15814. $renamd_nodes_line_nr++;
  15815. next unless (/\S/);
  15816. next if (/^\s*\@c\b/);
  15817. if (s/^\s*\@\@\{\}\s+(\S)/$1/)
  15818. {
  15819. chomp;
  15820. if (scalar(@old_names))
  15821. {
  15822. foreach my $old_node_name (@old_names)
  15823. {
  15824. $Texi2HTML::Config::renamed_nodes{$old_node_name} = normalise_node($_);
  15825. }
  15826. @old_names = ();
  15827. }
  15828. else
  15829. {
  15830. warn (sprintf(__("%s:%d: no node to be renamed\n"), $renamed_nodes_file, $renamd_nodes_line_nr));
  15831. }
  15832. }
  15833. else
  15834. {
  15835. chomp;
  15836. push @old_names, normalise_node($_);
  15837. }
  15838. }
  15839. if (scalar(@old_names))
  15840. {
  15841. warn (sprintf(__("%s:%d: nodes without a new name at the end of file\n"), $renamed_nodes_file, $renamd_nodes_line_nr));
  15842. }
  15843. close(RENAMEDFILE);
  15844. }
  15845. else
  15846. {
  15847. warn (sprintf(__("Cannot read %s: %s"), $renamed_nodes_file, $!));
  15848. }
  15849. }
  15850. }
  15851. sub init_with_file_name($)
  15852. {
  15853. my $base_file = shift;
  15854. set_docu_names($base_file, $Texi2HTML::THISDOC{'input_file_number'});
  15855. foreach my $handler(@Texi2HTML::Config::command_handler_init)
  15856. {
  15857. &$handler;
  15858. }
  15859. }
  15860. #######################################################################
  15861. #
  15862. # Main processing, process all the files given on the command line
  15863. #
  15864. #######################################################################
  15865. my @input_files = @ARGV;
  15866. # use STDIN if not a tty, like makeinfo does
  15867. @input_files = ('-') if (!scalar(@input_files) and !-t STDIN);
  15868. die sprintf(__("%s: missing file argument.\n"), $real_command_name) .$T2H_FAILURE_TEXT unless (scalar(@input_files) >= 1);
  15869. my $file_number = 0;
  15870. # main processing
  15871. while(@input_files)
  15872. {
  15873. my $input_file_arg = shift(@input_files);
  15874. %Texi2HTML::THISDOC = ();
  15875. $Texi2HTML::THIS_ELEMENT = undef;
  15876. foreach my $global_key (keys(%Texi2HTML::GLOBAL))
  15877. {
  15878. $Texi2HTML::THISDOC{$global_key} = $Texi2HTML::GLOBAL{$global_key};
  15879. }
  15880. # copy the keys, otherwise a modification in THISDOC will also modify
  15881. # the global value. This is an issue for other keys too, but they should
  15882. # not be modified.
  15883. $Texi2HTML::THISDOC{'variables'} = {};
  15884. foreach my $variable (keys(%{$Texi2HTML::GLOBAL{'variables'}}))
  15885. {
  15886. $Texi2HTML::THISDOC{'variables'}->{$variable} = $Texi2HTML::GLOBAL{'variables'}->{$variable};
  15887. }
  15888. my $input_file_name;
  15889. # try to concatenate with different suffixes. The last suffix is ''
  15890. # such that the plain file name is checked.
  15891. foreach my $suffix (@Texi2HTML::Config::INPUT_FILE_SUFFIXES)
  15892. {
  15893. $input_file_name = $input_file_arg.$suffix if (-e $input_file_arg.$suffix);
  15894. }
  15895. # in case no file was found, still set the file name
  15896. $input_file_name = $input_file_arg if (!defined($input_file_name));
  15897. $Texi2HTML::THISDOC{'input_file_name'} = $input_file_name;
  15898. $Texi2HTML::THISDOC{'input_file_number'} = $file_number;
  15899. $Texi2HTML::THISDOC{'input_directory'} = '.';
  15900. if ($input_file_name =~ /(.*\/)/)
  15901. {
  15902. $Texi2HTML::THISDOC{'input_directory'} = $1;
  15903. }
  15904. prepare_htmlxref($Texi2HTML::THISDOC{'input_directory'});
  15905. my $input_file_base = $input_file_name;
  15906. $input_file_base =~ s/\.te?x(i|info)?$//;
  15907. @{$Texi2HTML::TOC_LINES} = (); # table of contents
  15908. @{$Texi2HTML::OVERVIEW} = (); # short table of contents
  15909. # this could be done here, but perl warns that
  15910. # `"Texi2HTML::TITLEPAGE" used only once' and it is reset in
  15911. # &$Texi2HTML::Config::titlepage anyway
  15912. # $Texi2HTML::TITLEPAGE = undef;
  15913. @{$Texi2HTML::THIS_SECTION} = ();
  15914. # the reference to these hashes may be used before this point (for example
  15915. # see makeinfo.pm), so they should be kept as is and the values undef
  15916. # but the key should not be deleted because the ref is on the key.
  15917. foreach my $hash (\%Texi2HTML::HREF, \%Texi2HTML::NAME, \%Texi2HTML::NODE,
  15918. \%Texi2HTML::NO_TEXI, \%Texi2HTML::SIMPLE_TEXT)
  15919. {
  15920. foreach my $key (keys(%$hash))
  15921. {
  15922. $hash->{$key} = undef;
  15923. }
  15924. }
  15925. %region_lines = ();
  15926. %region_line_nrs = ();
  15927. foreach my $region (@special_regions)
  15928. {
  15929. $region_lines{$region} = [];
  15930. $region_line_nrs{$region} = [];
  15931. }
  15932. @created_directories = ();
  15933. $docu_dir = undef; # directory of the document
  15934. $docu_name = undef; # basename of the document
  15935. $docu_rdir = undef; # directory for the output
  15936. $docu_toc = undef; # document's table of contents
  15937. $docu_stoc = undef; # document's short toc
  15938. $docu_foot = undef; # document's footnotes
  15939. $docu_about = undef; # about this document
  15940. $docu_top = undef; # document top
  15941. $docu_doc = undef; # document (or document top of split)
  15942. $docu_frame = undef; # main frame file
  15943. $docu_toc_frame = undef; # toc frame file
  15944. $path_to_working_dir = undef; # relative path leading to the working
  15945. # directory from the document directory
  15946. $docu_doc_file = undef;
  15947. $docu_toc_file = undef;
  15948. $docu_stoc_file = undef;
  15949. $docu_foot_file = undef;
  15950. $docu_about_file = undef;
  15951. $docu_top_file = undef;
  15952. $docu_frame_file = undef;
  15953. $docu_toc_frame_file = undef;
  15954. $global_pass = '0';
  15955. # done before any processing, this is not necessarily
  15956. # the case with command_handler_init
  15957. foreach my $handler(@Texi2HTML::Config::command_handler_setup)
  15958. {
  15959. &$handler;
  15960. }
  15961. if (!get_conf('USE_SETFILENAME'))
  15962. {
  15963. init_with_file_name ($input_file_base);
  15964. }
  15965. @Texi2HTML::Config::INCLUDE_DIRS = @include_dirs_orig;
  15966. my @prependended_include_directories = ('.');
  15967. push @prependended_include_directories, $Texi2HTML::THISDOC{'input_directory'} if ($Texi2HTML::THISDOC{'input_directory'} ne '.');
  15968. unshift(@Texi2HTML::Config::INCLUDE_DIRS, @prependended_include_directories);
  15969. unshift(@Texi2HTML::Config::INCLUDE_DIRS, @Texi2HTML::Config::PREPEND_DIRS);
  15970. # FIXME when to do that?
  15971. ($Texi2HTML::THISDOC{'css_import_lines'}, $Texi2HTML::THISDOC{'css_rule_lines'})
  15972. = collect_all_css_files();
  15973. texinfo_initialization(0);
  15974. print STDERR "# reading from $input_file_name\n" if $T2H_VERBOSE;
  15975. $macros = undef; # macros. reference on a hash
  15976. %info_enclose = (); # macros defined with definfoenclose
  15977. @floats = (); # floats list
  15978. %floats = (); # floats by style
  15979. %nodes = (); # nodes hash. The key is the texi node name
  15980. %cross_reference_nodes = (); # normalized node names arrays
  15981. $global_pass = '1';
  15982. my ($texi_lines, $first_texi_lines, $lines_numbers)
  15983. = pass_texi($input_file_name);
  15984. if (get_conf('USE_SETFILENAME') and !defined($docu_name))
  15985. {
  15986. init_with_file_name ($input_file_base);
  15987. }
  15988. $global_pass = '1 expand macros';
  15989. Texi2HTML::Config::t2h_default_set_out_encoding();
  15990. collect_renamed_nodes() if (get_conf('RENAMED_NODES_REDIRECTIONS'));
  15991. dump_texi($texi_lines, 'texi', $lines_numbers) if (($T2H_DEBUG & $DEBUG_TEXI)
  15992. or get_conf('DUMP_TEXI'));
  15993. if (defined(get_conf('MACRO_EXPAND')))
  15994. {
  15995. my @texi_lines = (@$first_texi_lines, @$texi_lines);
  15996. dump_texi(\@texi_lines, '', undef, get_conf('MACRO_EXPAND'));
  15997. }
  15998. %content_element = ();
  15999. foreach my $command('contents', 'shortcontents')
  16000. {
  16001. $all_content_elements{$command} = [];
  16002. foreach my $key (keys(%{$reference_content_element{$command}}))
  16003. {
  16004. $content_element{$command}->{$key} = $reference_content_element{$command}->{$key};
  16005. }
  16006. }
  16007. %sec2level = %reference_sec2level;
  16008. $element_before_anything =
  16009. {
  16010. 'before_anything' => 1,
  16011. 'place' => [],
  16012. 'texi' => 'VIRTUAL ELEMENT BEFORE ANYTHING',
  16013. };
  16014. $footnote_element =
  16015. {
  16016. 'id' => $Texi2HTML::Config::misc_pages_targets{'Footnotes'},
  16017. 'target' => $Texi2HTML::Config::misc_pages_targets{'Footnotes'},
  16018. 'file' => $docu_foot,
  16019. 'footnote' => 1,
  16020. 'place' => [],
  16021. };
  16022. %region_initial_state = ();
  16023. foreach my $region (@special_regions)
  16024. {
  16025. $region_initial_state{$region} = { };
  16026. }
  16027. # to determine if a command has to be processed the following are interesting
  16028. # (and can be faked):
  16029. # 'region': the name of the special region we are processing
  16030. # 'region_pass': the number of passes in that specific region (both outside
  16031. # of the main document, and in the main document)
  16032. # 'multiple_pass': the number of pass in the formatting of the region in the
  16033. # main document
  16034. # It is set to 0 the first time the region is seen, before
  16035. # it will be -1, for example when doing the
  16036. # copying_comment, the titlepage... before starting with
  16037. # the document itself.
  16038. # 'outside_document': set to 1 if outside of the main document formatting
  16039. foreach my $key (keys(%region_initial_state))
  16040. {
  16041. $region_initial_state{$key}->{'multiple_pass'} = -1;
  16042. $region_initial_state{$key}->{'region_pass'} = 0;
  16043. $region_initial_state{$key}->{'num_head'} = 0;
  16044. $region_initial_state{$key}->{'foot_num'} = 0;
  16045. $region_initial_state{$key}->{'relative_foot_num'} = 0;
  16046. $region_initial_state{$key}->{'region'} = $key;
  16047. }
  16048. @opened_files = (); # all the files opened by the program to remove
  16049. # them if FORCE is not set and an error occured
  16050. texinfo_initialization(1);
  16051. $no_element_associated_place = [];
  16052. $document_idx_num = 0;
  16053. $document_sec_num = 0;
  16054. $document_head_num = 0;
  16055. $document_anchor_num = 0;
  16056. @nodes_list = (); # nodes in document reading order
  16057. # each member is a reference on a hash
  16058. @sections_list = (); # sections in reading order
  16059. # each member is a reference on a hash
  16060. @all_elements = (); # sectioning elements (nodes and sections)
  16061. # in reading order. Each member is a reference
  16062. # on a hash which also appears in %nodes,
  16063. # @sections_list @nodes_list, @elements_list
  16064. @headings_list = (); # headings in reading order.
  16065. @elements_list = (); # all the resulting elements in document order
  16066. %sections = (); # sections hash. The key is the section number
  16067. %headings = (); # headings hash. The key is the heading number
  16068. $section_top = undef; # @top section
  16069. $element_top = undef; # Top element
  16070. $node_top = undef; # Top node
  16071. $node_first = undef; # First node
  16072. $element_index = undef; # element with first index
  16073. $element_chapter_index = undef; # chapter with first index
  16074. $element_first = undef; # first element
  16075. $element_last = undef; # last element
  16076. %special_commands = (); # hash for the commands specially handled
  16077. # by the user
  16078. @index_labels = (); # array corresponding with @?index commands
  16079. # constructed during pass_texi, used to
  16080. # put labels in pass_text
  16081. # right now it is only used for debugging
  16082. # purposes.
  16083. @unknown_index_index_entries = (); # holds index entries not associated
  16084. # with any index
  16085. %{$Texi2HTML::THISDOC{'index_entries_array'}} = (); # holds the index
  16086. # entries in order of appearance in the document
  16087. # for each index name.
  16088. %{$Texi2HTML::THISDOC{'index_letters_array'}} = (); # holds the sorted
  16089. # index letters for each index name. The sorted
  16090. # letters hold the sorted index entries
  16091. $global_pass = 2;
  16092. my ($doc_lines, $doc_numbers) = pass_structure($texi_lines, $lines_numbers);
  16093. foreach my $handler(@Texi2HTML::Config::command_handler_names)
  16094. {
  16095. &$handler;
  16096. }
  16097. if (($T2H_DEBUG & $DEBUG_TEXI) or get_conf('DUMP_TEXI'))
  16098. {
  16099. dump_texi($doc_lines, 'first', $doc_numbers);
  16100. if (defined(get_conf('MACRO_EXPAND') and get_conf('DUMP_TEXI')))
  16101. {
  16102. my @all_doc_lines = (@$first_texi_lines, @$doc_lines);
  16103. #push (@$doc_lines, "\@bye\n");
  16104. dump_texi(\@all_doc_lines, '', undef, get_conf('MACRO_EXPAND') . ".first");
  16105. }
  16106. }
  16107. next if (get_conf('DUMP_TEXI'));
  16108. foreach my $style (keys(%special_commands))
  16109. {
  16110. $special_commands{$style}->{'max'} = $special_commands{$style}->{'count'};
  16111. }
  16112. %files = (); # keys are files. This is used to avoid reusing an already
  16113. # used file name
  16114. %printed_indices = (); # value is true for an index name not empty and
  16115. # printed
  16116. $global_pass = '2 prepare indices';
  16117. prepare_indices();
  16118. $global_pass = '2 element directions';
  16119. rearrange_elements();
  16120. do_names();
  16121. $global_pass = '2-3 user functions';
  16122. #Texi2HTML::LaTeX2HTML::latex2html();
  16123. foreach my $handler(@Texi2HTML::Config::command_handler_process)
  16124. {
  16125. &$handler;
  16126. }
  16127. # maybe do that later to have more elements ready?
  16128. &$Texi2HTML::Config::toc_body(\@sections_list);
  16129. &$Texi2HTML::Config::css_lines($Texi2HTML::THISDOC{'css_import_lines'},
  16130. $Texi2HTML::THISDOC{'css_rule_lines'});
  16131. $global_head_num = 0; # heading index. it is global for the main doc,
  16132. # and taken from the state if in multiple_pass.
  16133. $global_foot_num = 0;
  16134. $global_relative_foot_num = 0;
  16135. @foot_lines = (); # footnotes
  16136. $copying_comment = ''; # comment constructed from text between
  16137. # @copying and @end copying with licence
  16138. %acronyms_like = (); # acronyms or similar commands associated texts
  16139. # the key are the commands, the values are
  16140. # hash references associating shorthands to
  16141. # texts.
  16142. @states_stack = ();
  16143. pass_text($doc_lines, $doc_numbers);
  16144. print STDERR "BUG: " . scalar(@index_labels) . " index entries pending\n"
  16145. if (scalar(@index_labels));
  16146. foreach my $special (keys(%special_commands))
  16147. {
  16148. my $count = $special_commands{$special}->{'count'};
  16149. if (($count != 0) and $T2H_VERBOSE)
  16150. {
  16151. document_warn ("$count special \@$special were not processed.\n");
  16152. }
  16153. }
  16154. if (get_conf('IDX_SUMMARY'))
  16155. {
  16156. foreach my $entry (sort(keys(%index_names)))
  16157. {
  16158. do_index_summary_file($entry, $docu_name);
  16159. }
  16160. }
  16161. if (defined(get_conf('INTERNAL_LINKS')))
  16162. {
  16163. my $FH = open_out(get_conf('INTERNAL_LINKS'));
  16164. &$Texi2HTML::Config::internal_links($FH, \@elements_list, $Texi2HTML::THISDOC{'index_letters_array'});
  16165. close ($FH);
  16166. }
  16167. do_node_files() if (get_conf('NODE_FILES'));
  16168. do_renamed_node_files() if (get_conf('RENAMED_NODES_REDIRECTIONS'));
  16169. #l2h_FinishFromHtml() if (get_conf('L2H'));
  16170. #l2h_Finish() if(get_conf('L2H'));
  16171. #Texi2HTML::LaTeX2HTML::finish();
  16172. foreach my $handler(@Texi2HTML::Config::command_handler_finish)
  16173. {
  16174. &$handler;
  16175. }
  16176. &$Texi2HTML::Config::finish_out();
  16177. print STDERR "# File ($file_number) $input_file_name processed\n" if $T2H_VERBOSE;
  16178. $file_number++;
  16179. }
  16180. print STDERR "# that's all folks\n" if $T2H_VERBOSE;
  16181. exit(0);
  16182. ##############################################################################
  16183. # These next few lines are legal in both Perl and nroff.
  16184. .00 ; # finish .ig
  16185. 'di \" finish diversion--previous line must be blank
  16186. .nr nl 0-1 \" fake up transition to first page again
  16187. .nr % 0 \" start at page 1
  16188. '; __END__ ############# From here on it's a standard manual page ############
  16189. .so @mandir@/man1/texi2html.1