12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924 |
- SYNCTEX_INLINE static int _synctex_abs(int x) {
- return x>0? x: -x;
- }
- const char * synctex_suffix = ".synctex";
- const char * synctex_suffix_gz = ".gz";
- typedef synctex_node_p(*synctex_node_new_f)(synctex_scanner_p);
- typedef void(*synctex_node_fld_f)(synctex_node_p);
- typedef char *(*synctex_node_str_f)(synctex_node_p);
- typedef struct synctex_tree_model_t {
- int sibling;
- int parent;
- int child;
- int friend;
- int last;
- int next_hbox;
- int arg_sibling;
- int target;
- int size;
- } synctex_tree_model_s;
- typedef const synctex_tree_model_s * synctex_tree_model_p;
- typedef struct synctex_data_model_t {
- int tag;
- int line;
- int column;
- int h;
- int v;
- int width;
- int height;
- int depth;
- int mean_line;
- int weight;
- int h_V;
- int v_V;
- int width_V;
- int height_V;
- int depth_V;
- int name;
- int page;
- int size;
- } synctex_data_model_s;
- typedef const synctex_data_model_s * synctex_data_model_p;
- typedef int (*synctex_int_getter_f)(synctex_node_p);
- typedef struct synctex_tlcpector_t {
- synctex_int_getter_f tag;
- synctex_int_getter_f line;
- synctex_int_getter_f column;
- } synctex_tlcpector_s;
- typedef const synctex_tlcpector_s * synctex_tlcpector_p;
- static int _synctex_int_none(synctex_node_p node) {
- SYNCTEX_UNUSED(node)
- return 0;
- }
- static const synctex_tlcpector_s synctex_tlcpector_none = {
- &_synctex_int_none,
- &_synctex_int_none,
- &_synctex_int_none,
- };
- typedef struct synctex_inspector_t {
- synctex_int_getter_f h;
- synctex_int_getter_f v;
- synctex_int_getter_f width;
- synctex_int_getter_f height;
- synctex_int_getter_f depth;
- } synctex_inspector_s;
- typedef const synctex_inspector_s * synctex_inspector_p;
- static const synctex_inspector_s synctex_inspector_none = {
- &_synctex_int_none,
- &_synctex_int_none,
- &_synctex_int_none,
- &_synctex_int_none,
- &_synctex_int_none,
- };
- typedef float (*synctex_float_getter_f)(synctex_node_p);
- typedef struct synctex_vispector_t {
- synctex_float_getter_f h;
- synctex_float_getter_f v;
- synctex_float_getter_f width;
- synctex_float_getter_f height;
- synctex_float_getter_f depth;
- } synctex_vispector_s;
- static float _synctex_float_none(synctex_node_p node) {
- SYNCTEX_UNUSED(node)
- return 0;
- }
- static const synctex_vispector_s synctex_vispector_none = {
- &_synctex_float_none,
- &_synctex_float_none,
- &_synctex_float_none,
- &_synctex_float_none,
- &_synctex_float_none,
- };
- typedef const synctex_vispector_s * synctex_vispector_p;
- struct synctex_class_t {
- synctex_scanner_p scanner;
- synctex_node_type_t type;
- synctex_node_new_f new;
- synctex_node_fld_f free;
- synctex_node_fld_f log;
- synctex_node_fld_f display;
- synctex_node_str_f abstract;
- synctex_tree_model_p navigator;
- synctex_data_model_p modelator;
- synctex_tlcpector_p tlcpector;
- synctex_inspector_p inspector;
- synctex_vispector_p vispector;
- };
- typedef synctex_node_p synctex_proxy_p;
- typedef synctex_node_p synctex_noxy_p;
- synctex_node_p N__ = NODE;\
- if (N__ && N__->class_->SELECTOR) {\
- (*(N__->class_->SELECTOR))(N__);\
- }\
- } while (synctex_NO)
- static void synctex_node_free(synctex_node_p node) {
- SYNCTEX_MSG_SEND(node,free);
- }
- SYNCTEX_INLINE static synctex_node_p _synctex_new_handle_with_target(synctex_node_p target);
- __synctex_scanner_free_handle(SCANR)
- __synctex_scanner_remove_handle_to(WHAT)
- __synctex_scanner_register_handle_to(NODE)
- printf(SYNCTEX_PRINT_CHARINDEX_FMT SYNCTEX_PRINT_CHARINDEX_WHAT)
- printf(SYNCTEX_PRINT_LINEINDEX_FMT SYNCTEX_PRINT_LINEINDEX_WHAT)
- printf(SYNCTEX_PRINT_CHARINDEX_FMT "\n" SYNCTEX_PRINT_CHARINDEX_WHAT)
- printf(SYNCTEX_PRINT_CHARINDEX_FMT "\n"SYNCTEX_PRINT_LINEINDEX_WHAT)
- NODE->char_index = (synctex_charindex_t)(scanner->reader->charindex_offset+SYNCTEX_CUR-SYNCTEX_START+(CORRECTION)); \
- NODE->line_index = scanner->reader->line_number;
- do { \
- if (!(WHAT)) { \
- printf("! Parameter failure: %s\n",
- } \
- } while (synctex_NO)
- static synctex_bool_t _synctex_tree_has_
- if (node) {\
- if (node->class_->navigator->WHAT>=0) {\
- return synctex_YES; \
- } else {\
- printf("WARNING: NO tree %s for %s\n",
- }\
- }\
- return synctex_NO;\
- }
- static synctex_bool_t _synctex_tree_has_
- return (node && (node->class_->navigator->WHAT>=0));\
- }
- SYNCTEX_INLINE static synctex_node_p __synctex_tree_
- return node->data[node->class_->navigator->WHAT].as_node;\
- }
- DEFINE_SYNCTEX_TREE__GET(WHAT) \
- static synctex_node_p _synctex_tree_
- if (_synctex_tree_has_
- return __synctex_tree_
- }\
- return 0;\
- }
- SYNCTEX_INLINE static synctex_node_p __synctex_tree_reset_
- synctex_node_p old = node->data[node->class_->navigator->WHAT].as_node;\
- node->data[node->class_->navigator->WHAT].as_node=NULL;\
- return old;\
- }
- DEFINE_SYNCTEX_TREE__RESET(WHAT) \
- SYNCTEX_INLINE static synctex_node_p _synctex_tree_reset_
- return _synctex_tree_has_
- __synctex_tree_reset_
- }
- SYNCTEX_INLINE static synctex_node_p __synctex_tree_set_
- synctex_node_p old = __synctex_tree_
- node->data[node->class_->navigator->WHAT].as_node=new_value;\
- return old;\
- }
- DEFINE_SYNCTEX_TREE__SET(WHAT) \
- SYNCTEX_INLINE static synctex_node_p _synctex_tree_set_
- return _synctex_tree_has_
- __synctex_tree_set_
- }
- DEFINE_SYNCTEX_TREE__GET(WHAT) \
- DEFINE_SYNCTEX_TREE__SET(WHAT) \
- DEFINE_SYNCTEX_TREE__RESET(WHAT)
- DEFINE_SYNCTEX_TREE_HAS(WHAT) \
- DEFINE_SYNCTEX_TREE_GET(WHAT) \
- DEFINE_SYNCTEX_TREE_SET(WHAT)
- DEFINE_SYNCTEX_TREE_HAS(WHAT) \
- DEFINE_SYNCTEX_TREE_GET(WHAT) \
- DEFINE_SYNCTEX_TREE_RESET(WHAT)
- DEFINE_SYNCTEX_TREE_HAS(WHAT) \
- DEFINE_SYNCTEX_TREE_GET(WHAT) \
- DEFINE_SYNCTEX_TREE_SET(WHAT) \
- DEFINE_SYNCTEX_TREE_RESET(WHAT)
- DEFINE_SYNCTEX_TREE__GETSETRESET(sibling)
- DEFINE_SYNCTEX_TREE_GETSETRESET(parent)
- DEFINE_SYNCTEX_TREE_GETSETRESET(child)
- DEFINE_SYNCTEX_TREE_GETSETRESET(friend)
- DEFINE_SYNCTEX_TREE_GETSET(last)
- DEFINE_SYNCTEX_TREE_GETSET(next_hbox)
- DEFINE_SYNCTEX_TREE_GETSET(arg_sibling)
- DEFINE_SYNCTEX_TREE_GETSETRESET(target)
- do { node_count = 0; } while(synctex_NO)
- typedef struct synctex_reader_t {
- gzFile file;
- char * output;
- char * synctex;
- char * current;
- char * start;
- char * end;
- size_t min_size;
- size_t size;
- int lastv;
- int line_number;
- SYNCTEX_DECLARE_CHAR_OFFSET
- } synctex_reader_s;
- typedef synctex_reader_s * synctex_reader_p;
- typedef struct {
- synctex_status_t status;
- char * synctex;
- gzFile file;
- synctex_io_mode_t io_mode;
- } synctex_open_s;
- static synctex_open_s __synctex_open_v2(const char * output, synctex_io_mode_t io_mode, synctex_bool_t add_quotes) {
- synctex_open_s open = {SYNCTEX_STATUS_ERROR, NULL, NULL, io_mode};
- char * quoteless_synctex_name = NULL;
- const char * mode = _synctex_get_io_mode_name(open.io_mode);
- size_t size = strlen(output)+strlen(synctex_suffix)+strlen(synctex_suffix_gz)+1;
- if (NULL == (open.synctex = (char *)malloc(size))) {
- _synctex_error("! __synctex_open_v2: Memory problem (1)\n");
- return open;
- }
-
- if (open.synctex != strcpy(open.synctex,output)) {
- _synctex_error("! __synctex_open_v2: Copy problem\n");
- return_on_error:
- free(open.synctex);
- open.synctex = NULL;
- free(quoteless_synctex_name);
- return open;
- }
-
- _synctex_strip_last_path_extension(open.synctex);
- if (!strlen(open.synctex)) {
- goto return_on_error;
- }
-
- if (add_quotes) {
- char * quoted = NULL;
- if (_synctex_copy_with_quoting_last_path_component(open.synctex,"ed,size) || quoted == NULL) {
-
- goto return_on_error;
- }
- quoteless_synctex_name = open.synctex;
- open.synctex = quoted;
- }
-
- if (open.synctex != strcat(open.synctex,synctex_suffix)){
- _synctex_error("! __synctex_open_v2: Concatenation problem (can't add suffix '%s')\n",synctex_suffix);
- goto return_on_error;
- }
-
- if (quoteless_synctex_name && (quoteless_synctex_name != strcat(quoteless_synctex_name,synctex_suffix))){
- free(quoteless_synctex_name);
- quoteless_synctex_name = NULL;
- }
- if (NULL == (open.file = gzopen(open.synctex,mode))) {
-
- if (errno != ENOENT) {
-
- _synctex_error("could not open %s, error %i\n",open.synctex,errno);
- goto return_on_error;
- }
-
- if (open.synctex != strcat(open.synctex,synctex_suffix_gz)){
- _synctex_error("! __synctex_open_v2: Concatenation problem (can't add suffix '%s')\n",synctex_suffix_gz);
- goto return_on_error;
- }
- open.io_mode |= synctex_io_gz_mask;
- mode = _synctex_get_io_mode_name(open.io_mode);
-
- if (quoteless_synctex_name && (quoteless_synctex_name != strcat(quoteless_synctex_name,synctex_suffix_gz))){
- free(quoteless_synctex_name);
- quoteless_synctex_name = NULL;
- }
- if (NULL == (open.file = gzopen(open.synctex,mode))) {
-
- if (errno != ENOENT) {
-
- _synctex_error("Could not open %s, error %i\n",open.synctex,errno);
- }
- goto return_on_error;
- }
- }
-
- if (quoteless_synctex_name) {
- gzclose(open.file);
- if (rename(open.synctex,quoteless_synctex_name)) {
- _synctex_error("Could not rename %s to %s, error %i\n",open.synctex,quoteless_synctex_name,errno);
-
- if (NULL == (open.file = gzopen(open.synctex,mode))) {
-
- if (errno != ENOENT) {
-
- _synctex_error("Could not open again %s, error %i\n",open.synctex,errno);
- }
- goto return_on_error;
- }
- } else {
-
- if (NULL == (open.file = gzopen(quoteless_synctex_name,mode))) {
-
- if (errno != ENOENT) {
-
- _synctex_error("Could not open renamed %s, error %i\n",quoteless_synctex_name,errno);
- }
- goto return_on_error;
- }
-
- free(open.synctex);
- open.synctex = quoteless_synctex_name;
- quoteless_synctex_name = NULL;
- }
- }
-
- open.status = SYNCTEX_STATUS_OK;
- return open;
- }
- static synctex_open_s _synctex_open_v2(const char * output, const char * build_directory, synctex_io_mode_t io_mode, synctex_bool_t add_quotes) {
- synctex_open_s open = __synctex_open_v2(output,io_mode,add_quotes);
- if (open.status == SYNCTEX_STATUS_OK) {
- return open;
- }
- if (build_directory && strlen(build_directory)) {
- char * build_output;
- const char *lpc;
- size_t size;
- synctex_bool_t is_absolute;
- build_output = NULL;
- lpc = _synctex_last_path_component(output);
- size = strlen(build_directory)+strlen(lpc)+2;
- is_absolute = _synctex_path_is_absolute(build_directory);
- if (!is_absolute) {
- size += strlen(output);
- }
- if ((build_output = (char *)_synctex_malloc(size))) {
- if (is_absolute) {
- build_output[0] = '\0';
- } else {
- if (build_output != strcpy(build_output,output)) {
- _synctex_free(build_output);
- return open;
- }
- build_output[lpc-output]='\0';
- }
- if (build_output == strcat(build_output,build_directory)) {
-
- if (!SYNCTEX_IS_PATH_SEPARATOR(build_output[strlen(build_directory)-1])) {
- if (build_output != strcat(build_output,"/")) {
- _synctex_free(build_output);
- return open;
- }
- }
-
- if (build_output != strcat(build_output,lpc)) {
- _synctex_free(build_output);
- return open;
- }
- open = __synctex_open_v2(build_output,io_mode,add_quotes);
- }
- _synctex_free(build_output);
- }
- }
- return open;
- }
- static void synctex_reader_free(synctex_reader_p reader) {
- if (reader) {
- _synctex_free(reader->output);
- _synctex_free(reader->synctex);
- _synctex_free(reader->start);
- gzclose(reader->file);
- _synctex_free(reader);
- }
- }
- static synctex_reader_p synctex_reader_init_with_output_file(synctex_reader_p reader, const char * output, const char * build_directory) {
- if (reader) {
-
- synctex_open_s open = _synctex_open_v2(output,build_directory,0,synctex_ADD_QUOTES);
- if (open.status<SYNCTEX_STATUS_OK) {
- open = _synctex_open_v2(output,build_directory,0,synctex_DONT_ADD_QUOTES);
- if (open.status<SYNCTEX_STATUS_OK) {
- return NULL;
- }
- }
- reader->synctex = open.synctex;
- reader->file = open.file;
-
- if (NULL == (reader->output = (char *)_synctex_malloc(strlen(output)+1))){
- _synctex_error("! synctex_scanner_new_with_output_file: Memory problem (2), reader's output is not reliable.");
- } else if (reader->output != strcpy(reader->output,output)) {
- _synctex_free(reader->output);
- reader->output = NULL;
- _synctex_error("! synctex_scanner_new_with_output_file: Copy problem, reader's output is not reliable.");
- }
- reader->start = reader->end = reader->current = NULL;
- reader->min_size = SYNCTEX_BUFFER_MIN_SIZE;
- reader->size = SYNCTEX_BUFFER_SIZE;
- reader->start = reader->current =
- (char *)_synctex_malloc(reader->size+1);
- if (NULL == reader->start) {
- _synctex_error("! malloc error in synctex_reader_init_with_output_file.");
-
- return reader;
- synctex_reader_free(reader);
- return NULL;
- }
- reader->end = reader->start+reader->size;
-
- reader->charindex_offset = -reader->size;
- }
- return reader;
- }
- struct synctex_scanner_t {
- synctex_reader_p reader;
- SYNCTEX_DECLARE_NODE_COUNT
- SYNCTEX_DECLARE_HANDLE
- char * output_fmt;
- synctex_iterator_p iterator;
- int version;
- struct {
- unsigned has_parsed:1;
- unsigned postamble:1;
- unsigned reserved:sizeof(unsigned)-2;
- } flags;
- int pre_magnification;
- int pre_unit;
- int pre_x_offset;
- int pre_y_offset;
- int count;
- float unit;
- float x_offset;
- float y_offset;
- synctex_node_p input;
- synctex_node_p sheet;
- synctex_node_p form;
- synctex_node_p ref_in_sheet;
- synctex_node_p ref_in_form;
- int number_of_lists;
- synctex_node_r lists_of_friends;
- synctex_class_s class_[synctex_node_number_of_types];
- int display_switcher;
- char * display_prompt;
- };
- synctex_node_p synctex_node_new(synctex_scanner_p scanner, synctex_node_type_t type) {
- return scanner? scanner->class_[type].new(scanner):NULL;
- }
- SYNCTEX_INLINE static void __synctex_scanner_free_handle(synctex_scanner_p scanner) {
- synctex_node_free(scanner->handle);
- }
- SYNCTEX_INLINE static void __synctex_scanner_remove_handle_to(synctex_node_p node) {
- synctex_node_p arg_sibling = NULL;
- synctex_node_p handle = node->class_->scanner->handle;
- while (handle) {
- synctex_node_p sibling;
- if (node == _synctex_tree_target(handle)) {
- sibling = __synctex_tree_reset_sibling(handle);
- if (arg_sibling) {
- __synctex_tree_set_sibling(arg_sibling, sibling);
- } else {
- node->class_->scanner->handle = sibling;
- }
- synctex_node_free(handle);
- break;
- } else {
- sibling = __synctex_tree_sibling(handle);
- }
- arg_sibling = handle;
- handle = sibling;
- }
- }
- SYNCTEX_INLINE static void __synctex_scanner_register_handle_to(synctex_node_p node) {
- synctex_node_p NNN = _synctex_new_handle_with_target(node);
- __synctex_tree_set_sibling(NNN,node->class_->scanner->handle);
- node->class_->scanner->handle = NNN;
- }
- SYNCTEX_INLINE static void _synctex_did_new(synctex_node_p node) {
- printf("NODE CREATED # %i, %s, %p\n",
- (node->class_->scanner->node_count)++,
- synctex_node_isa(node),
- node);
- }
- SYNCTEX_INLINE static void _synctex_will_free(synctex_node_p node) {
- printf("NODE DELETED # %i, %s, %p\n",
- --(node->class_->scanner->node_count),
- synctex_node_isa(node),
- node);
- }
- static void _synctex_free_node(synctex_node_p node) {
- if (node) {
- SYNCTEX_SCANNER_REMOVE_HANDLE_TO(node);
- SYNCTEX_WILL_FREE(node);
- synctex_node_free(__synctex_tree_sibling(node));
- synctex_node_free(_synctex_tree_child(node));
- _synctex_free(node);
- }
- return;
- }
- static void _synctex_free_handle(synctex_node_p handle) {
- if (handle) {
- _synctex_free_handle(__synctex_tree_sibling(handle));
- _synctex_free_handle(_synctex_tree_child(handle));
- _synctex_free(handle);
- }
- return;
- }
- static void _synctex_free_leaf(synctex_node_p node) {
- if (node) {
- SYNCTEX_SCANNER_REMOVE_HANDLE_TO(node);
- SYNCTEX_WILL_FREE(node);
- synctex_node_free(__synctex_tree_sibling(node));
- _synctex_free(node);
- }
- return;
- }
- synctex_node_p synctex_scanner_handle(synctex_scanner_p scanner) {
- return scanner? scanner->handle:NULL;
- }
- typedef struct {
- int integer;
- synctex_status_t status;
- } synctex_is_s;
- static synctex_is_s _synctex_decode_int(synctex_scanner_p scanner);
- static synctex_is_s _synctex_decode_int_opt(synctex_scanner_p scanner, int default_value);
- static synctex_is_s _synctex_decode_int_v(synctex_scanner_p scanner);
- typedef struct {
- char * string;
- synctex_status_t status;
- } synctex_ss_s;
- static synctex_ss_s _synctex_decode_string(synctex_scanner_p scanner);
- SYNCTEX_INLINE static synctex_bool_t __synctex_data_has_
- return (node && (node->class_->modelator->WHAT>=0));\
- }\
- SYNCTEX_INLINE static synctex_bool_t _synctex_data_has_
- if (node && (node->class_->modelator->WHAT<0)) {\
- printf("WARNING: NO %s for %s\n",
- }\
- return __synctex_data_has_
- }
- SYNCTEX_INLINE static synctex_bool_t __synctex_data_has_
- return (node && (node->class_->modelator->WHAT>=0));\
- }\
- SYNCTEX_INLINE static synctex_bool_t _synctex_data_has_
- return __synctex_data_has_
- }
- SYNCTEX_INLINE static synctex_data_p __synctex_data(synctex_node_p node) {
- return node->data+node->class_->navigator->size;
- }
- DEFINE_SYNCTEX_DATA_HAS(WHAT)\
- static int _synctex_data_
- if (_synctex_data_has_
- return __synctex_data(node)[node->class_->modelator->WHAT].as_integer;\
- }\
- return 0;\
- }\
- static int _synctex_data_set_
- int old = 0;\
- if (_synctex_data_has_
- old = __synctex_data(node)[node->class_->modelator->WHAT].as_integer;\
- __synctex_data(node)[node->class_->modelator->WHAT].as_integer=new_value;\
- }\
- return old;\
- }
- static synctex_status_t _synctex_data_decode_
- if (_synctex_data_has_
- synctex_is_s is = _synctex_decode_int(node->class_->scanner);\
- if (is.status == SYNCTEX_STATUS_OK) {\
- _synctex_data_set_
- } \
- return is.status;\
- }\
- return SYNCTEX_STATUS_BAD_ARGUMENT;\
- }
- static synctex_status_t _synctex_data_decode_
- if (_synctex_data_has_
- synctex_is_s is = _synctex_decode_int_v(node->class_->scanner);\
- if (is.status == SYNCTEX_STATUS_OK) {\
- _synctex_data_set_
- } \
- return is.status;\
- }\
- return SYNCTEX_STATUS_BAD_ARGUMENT;\
- }
- DEFINE_SYNCTEX_DATA_HAS(WHAT)\
- static char * _synctex_data_
- if (_synctex_data_has_
- return node->data[node->class_->navigator->size+node->class_->modelator->WHAT].as_string;\
- }\
- return NULL;\
- }\
- static char * _synctex_data_set_
- char * old = "";\
- if (_synctex_data_has_
- old = node->data[node->class_->navigator->size+node->class_->modelator->WHAT].as_string;\
- node->data[node->class_->navigator->size+node->class_->modelator->WHAT].as_string =new_value;\
- }\
- return old;\
- }
- static synctex_status_t _synctex_data_decode_
- if (_synctex_data_has_
- synctex_ss_s ss = _synctex_decode_string(node->class_->scanner);\
- if (ss.status == SYNCTEX_STATUS_OK) {\
- _synctex_data_set_
- } \
- return ss.status;\
- }\
- return SYNCTEX_STATUS_BAD_ARGUMENT;\
- }
- DEFINE_SYNCTEX_DATA_INT_GETSET(WHAT) \
- DEFINE_SYNCTEX_DATA_INT_DECODE(WHAT)
- DEFINE_SYNCTEX_DATA_INT_GETSET(WHAT) \
- DEFINE_SYNCTEX_DATA_INT_DECODE_v(WHAT)
- DEFINE_SYNCTEX_DATA_STR_GETSET(WHAT) \
- DEFINE_SYNCTEX_DATA_STR_DECODE(WHAT)
- DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE(tag)
- DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE(line)
- DEFINE_SYNCTEX_DATA_STR_GETSET_DECODE(name)
- static const synctex_tree_model_s synctex_tree_model_input = {
- synctex_tree_sibling_idx,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- synctex_tree_s_input_max
- };
- static const synctex_data_model_s synctex_data_model_input = {
- synctex_data_input_tag_idx,
- synctex_data_input_line_idx,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- synctex_data_input_name_idx,
- -1,
- synctex_data_input_tln_max
- };
- &_synctex_data_
- static synctex_node_p _synctex_new_input(synctex_scanner_p scanner);
- static void _synctex_free_input(synctex_node_p node);
- static void _synctex_log_input(synctex_node_p node);
- static char * _synctex_abstract_input(synctex_node_p node);
- static void _synctex_display_input(synctex_node_p node);
- static const synctex_tlcpector_s synctex_tlcpector_input = {
- &_synctex_data_tag,
- &_synctex_int_none,
- &_synctex_int_none,
- };
- static synctex_class_s synctex_class_input = {
- NULL,
- synctex_node_type_input,
- &_synctex_new_input,
- &_synctex_free_input,
- &_synctex_log_input,
- &_synctex_display_input,
- &_synctex_abstract_input,
- &synctex_tree_model_input,
- &synctex_data_model_input,
- &synctex_tlcpector_input,
- &synctex_inspector_none,
- &synctex_vispector_none,
- };
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_s_input_max+synctex_data_input_tln_max];
- } synctex_input_s;
- static synctex_node_p _synctex_new_input(synctex_scanner_p scanner) {
- if (scanner) {
- synctex_node_p node = _synctex_malloc(sizeof(synctex_input_s));
- if (node) {
- node->class_ = scanner->class_+synctex_node_type_input;
- SYNCTEX_DID_NEW(node);
- SYNCTEX_IMPLEMENT_CHARINDEX(node,0);
- SYNCTEX_REGISTER_HANDLE_TO(node);
- }
- return node;
- }
- return NULL;
- }
- static void _synctex_free_input(synctex_node_p node){
- if (node) {
- SYNCTEX_SCANNER_REMOVE_HANDLE_TO(node);
- SYNCTEX_WILL_FREE(node);
- synctex_node_free(__synctex_tree_sibling(node));
- _synctex_free(_synctex_data_name(node));
- _synctex_free(node);
- }
- }
- DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE(page)
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_scn_sheet_max+synctex_data_p_sheet_max];
- } synctex_node_sheet_s;
- static synctex_node_p _synctex_new_
- if (scanner) {\
- ++SYNCTEX_CUR;\
- synctex_node_p node = _synctex_malloc(sizeof(synctex_node_
- if (node) {\
- node->class_ = scanner->class_+synctex_node_type_
- SYNCTEX_DID_NEW(node); \
- SYNCTEX_IMPLEMENT_CHARINDEX(node,-1);\
- SYNCTEX_REGISTER_HANDLE_TO(node); \
- }\
- return node;\
- }\
- return NULL;\
- }
- DEFINE_synctex_new_scanned_NODE(sheet)
- static void _synctex_log_sheet(synctex_node_p node);
- static char * _synctex_abstract_sheet(synctex_node_p node);
- static void _synctex_display_sheet(synctex_node_p node);
- static const synctex_tree_model_s synctex_tree_model_sheet = {
- synctex_tree_sibling_idx,
- -1,
- synctex_tree_s_child_idx,
- -1,
- -1,
- synctex_tree_sc_next_hbox_idx,
- -1,
- -1,
- synctex_tree_scn_sheet_max
- };
- static const synctex_data_model_s synctex_data_model_sheet = {
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- synctex_data_sheet_page_idx,
- synctex_data_p_sheet_max
- };
- static synctex_class_s synctex_class_sheet = {
- NULL,
- synctex_node_type_sheet,
- &_synctex_new_sheet,
- &_synctex_free_node,
- &_synctex_log_sheet,
- &_synctex_display_sheet,
- &_synctex_abstract_sheet,
- &synctex_tree_model_sheet,
- &synctex_data_model_sheet,
- &synctex_tlcpector_none,
- &synctex_inspector_none,
- &synctex_vispector_none,
- };
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_sct_form_max+synctex_data_t_form_max];
- } synctex_node_form_s;
- DEFINE_synctex_new_scanned_NODE(form)
- static char * _synctex_abstract_form(synctex_node_p node);
- static void _synctex_display_form(synctex_node_p node);
- static void _synctex_log_form(synctex_node_p node);
- static const synctex_tree_model_s synctex_tree_model_form = {
- synctex_tree_sibling_idx,
- -1,
- synctex_tree_s_child_idx,
- -1,
- -1,
- -1,
- -1,
- synctex_tree_sc_target_idx,
- synctex_tree_sct_form_max
- };
- static const synctex_data_model_s synctex_data_model_form = {
- synctex_data_form_tag_idx,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- synctex_data_t_form_max
- };
- static synctex_class_s synctex_class_form = {
- NULL,
- synctex_node_type_form,
- &_synctex_new_form,
- &_synctex_free_node,
- &_synctex_log_form,
- &_synctex_display_form,
- &_synctex_abstract_form,
- &synctex_tree_model_form,
- &synctex_data_model_form,
- &synctex_tlcpector_none,
- &synctex_inspector_none,
- &synctex_vispector_none,
- };
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_spcfl_vbox_max+synctex_data_box_max];
- } synctex_node_vbox_s;
- DEFINE_synctex_new_scanned_NODE(vbox)
- static char * _synctex_abstract_vbox(synctex_node_p node);
- static void _synctex_display_vbox(synctex_node_p node);
- static void _synctex_log_vbox(synctex_node_p node);
- static const synctex_tree_model_s synctex_tree_model_vbox = {
- synctex_tree_sibling_idx,
- synctex_tree_s_parent_idx,
- synctex_tree_sp_child_idx,
- synctex_tree_spc_friend_idx,
- synctex_tree_spcf_last_idx,
- -1,
- -1,
- -1,
- synctex_tree_spcfl_vbox_max
- };
- DEFINE_SYNCTEX_DATA_INT_GETSET(column)
- static synctex_status_t _synctex_data_decode_column(synctex_node_p node) {
- if (_synctex_data_has_column(node)) {
- synctex_is_s is = _synctex_decode_int_opt(node->class_->scanner,
- SYNCTEX_DFLT_COLUMN);
- if (is.status == SYNCTEX_STATUS_OK) {
- _synctex_data_set_column(node,is.integer);
- }
- return is.status;
- }
- return SYNCTEX_STATUS_BAD_ARGUMENT;
- }
- DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE(h)
- DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE_v(v)
- DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE(width)
- DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE(height)
- DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE(depth)
- SYNCTEX_INLINE static void _synctex_data_set_tlc(synctex_node_p node, synctex_node_p model) {
- _synctex_data_set_tag(node, _synctex_data_tag(model));
- _synctex_data_set_line(node, _synctex_data_line(model));
- _synctex_data_set_column(node, _synctex_data_column(model));
- }
- SYNCTEX_INLINE static void _synctex_data_set_tlchv(synctex_node_p node, synctex_node_p model) {
- _synctex_data_set_tlc(node,model);
- _synctex_data_set_h(node, _synctex_data_h(model));
- _synctex_data_set_v(node, _synctex_data_v(model));
- }
- static const synctex_data_model_s synctex_data_model_box = {
- synctex_data_tag_idx,
- synctex_data_line_idx,
- synctex_data_column_idx,
- synctex_data_h_idx,
- synctex_data_v_idx,
- synctex_data_width_idx,
- synctex_data_height_idx,
- synctex_data_depth_idx,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- synctex_data_box_max
- };
- static const synctex_tlcpector_s synctex_tlcpector_default = {
- &_synctex_data_tag,
- &_synctex_data_line,
- &_synctex_data_column,
- };
- static const synctex_inspector_s synctex_inspector_box = {
- &_synctex_data_h,
- &_synctex_data_v,
- &_synctex_data_width,
- &_synctex_data_height,
- &_synctex_data_depth,
- };
- static float __synctex_node_visible_h(synctex_node_p node);
- static float __synctex_node_visible_v(synctex_node_p node);
- static float __synctex_node_visible_width(synctex_node_p node);
- static float __synctex_node_visible_height(synctex_node_p node);
- static float __synctex_node_visible_depth(synctex_node_p node);
- static synctex_vispector_s synctex_vispector_box = {
- &__synctex_node_visible_h,
- &__synctex_node_visible_v,
- &__synctex_node_visible_width,
- &__synctex_node_visible_height,
- &__synctex_node_visible_depth,
- };
- static synctex_class_s synctex_class_vbox = {
- NULL,
- synctex_node_type_vbox,
- &_synctex_new_vbox,
- &_synctex_free_node,
- &_synctex_log_vbox,
- &_synctex_display_vbox,
- &_synctex_abstract_vbox,
- &synctex_tree_model_vbox,
- &synctex_data_model_box,
- &synctex_tlcpector_default,
- &synctex_inspector_box,
- &synctex_vispector_box,
- };
- static const synctex_tree_model_s synctex_tree_model_hbox = {
- synctex_tree_sibling_idx,
- synctex_tree_s_parent_idx,
- synctex_tree_sp_child_idx,
- synctex_tree_spc_friend_idx,
- synctex_tree_spcf_last_idx,
- synctex_tree_spcfl_next_hbox_idx,
- -1,
- -1,
- synctex_tree_spcfln_hbox_max
- };
- DEFINE_SYNCTEX_DATA_INT_GETSET(mean_line)
- DEFINE_SYNCTEX_DATA_INT_GETSET(weight)
- DEFINE_SYNCTEX_DATA_INT_GETSET(h_V)
- DEFINE_SYNCTEX_DATA_INT_GETSET(v_V)
- DEFINE_SYNCTEX_DATA_INT_GETSET(width_V)
- DEFINE_SYNCTEX_DATA_INT_GETSET(height_V)
- DEFINE_SYNCTEX_DATA_INT_GETSET(depth_V)
- static const synctex_data_model_s synctex_data_model_hbox = {
- synctex_data_tag_idx,
- synctex_data_line_idx,
- synctex_data_column_idx,
- synctex_data_h_idx,
- synctex_data_v_idx,
- synctex_data_width_idx,
- synctex_data_height_idx,
- synctex_data_depth_idx,
- synctex_data_mean_line_idx,
- synctex_data_weight_idx,
- synctex_data_h_V_idx,
- synctex_data_v_V_idx,
- synctex_data_width_V_idx,
- synctex_data_height_V_idx,
- synctex_data_depth_V_idx,
- -1,
- -1,
- synctex_data_hbox_max
- };
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_spcfln_hbox_max+synctex_data_hbox_max];
- } synctex_node_hbox_s;
- DEFINE_synctex_new_scanned_NODE(hbox)
- static void _synctex_log_hbox(synctex_node_p node);
- static char * _synctex_abstract_hbox(synctex_node_p node);
- static void _synctex_display_hbox(synctex_node_p node);
- static synctex_class_s synctex_class_hbox = {
- NULL,
- synctex_node_type_hbox,
- &_synctex_new_hbox,
- &_synctex_free_node,
- &_synctex_log_hbox,
- &_synctex_display_hbox,
- &_synctex_abstract_hbox,
- &synctex_tree_model_hbox,
- &synctex_data_model_hbox,
- &synctex_tlcpector_default,
- &synctex_inspector_box,
- &synctex_vispector_box,
- };
- static const synctex_tree_model_s synctex_tree_model_spf = {
- synctex_tree_sibling_idx,
- synctex_tree_s_parent_idx,
- -1,
- synctex_tree_sp_friend_idx,
- -1,
- -1,
- -1,
- -1,
- synctex_tree_spf_max
- };
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_spf_max+synctex_data_box_max];
- } synctex_node_void_vbox_s;
- DEFINE_synctex_new_scanned_NODE(void_vbox)
- static void _synctex_log_void_box(synctex_node_p node);
- static char * _synctex_abstract_void_vbox(synctex_node_p node);
- static void _synctex_display_void_vbox(synctex_node_p node);
- static synctex_class_s synctex_class_void_vbox = {
- NULL,
- synctex_node_type_void_vbox,
- &_synctex_new_void_vbox,
- &_synctex_free_leaf,
- &_synctex_log_void_box,
- &_synctex_display_void_vbox,
- &_synctex_abstract_void_vbox,
- &synctex_tree_model_spf,
- &synctex_data_model_box,
- &synctex_tlcpector_default,
- &synctex_inspector_box,
- &synctex_vispector_box,
- };
- typedef synctex_node_void_vbox_s synctex_node_void_hbox_s;
- DEFINE_synctex_new_scanned_NODE(void_hbox)
- static char * _synctex_abstract_void_hbox(synctex_node_p node);
- static void _synctex_display_void_hbox(synctex_node_p node);
- static synctex_class_s synctex_class_void_hbox = {
- NULL,
- synctex_node_type_void_hbox,
- &_synctex_new_void_hbox,
- &_synctex_free_leaf,
- &_synctex_log_void_box,
- &_synctex_display_void_hbox,
- &_synctex_abstract_void_hbox,
- &synctex_tree_model_spf,
- &synctex_data_model_box,
- &synctex_tlcpector_default,
- &synctex_inspector_box,
- &synctex_vispector_box,
- };
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_spfa_max+synctex_data_ref_thv_max];
- } synctex_node_ref_s;
- DEFINE_synctex_new_scanned_NODE(ref)
- static void _synctex_log_ref(synctex_node_p node);
- static char * _synctex_abstract_ref(synctex_node_p node);
- static void _synctex_display_ref(synctex_node_p node);
- static const synctex_tree_model_s synctex_tree_model_spfa = {
- synctex_tree_sibling_idx,
- synctex_tree_s_parent_idx,
- -1,
- synctex_tree_sp_friend_idx,
- -1,
- -1,
- synctex_tree_spf_arg_sibling_idx,
- -1,
- synctex_tree_spfa_max
- };
- static const synctex_data_model_s synctex_data_model_ref = {
- synctex_data_tag_idx,
- -1,
- -1,
- synctex_data_ref_h_idx,
- synctex_data_ref_v_idx,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- synctex_data_ref_thv_max
- };
- static synctex_class_s synctex_class_ref = {
- NULL,
- synctex_node_type_ref,
- &_synctex_new_ref,
- &_synctex_free_leaf,
- &_synctex_log_ref,
- &_synctex_display_ref,
- &_synctex_abstract_ref,
- &synctex_tree_model_spfa,
- &synctex_data_model_ref,
- &synctex_tlcpector_none,
- &synctex_inspector_none,
- &synctex_vispector_none,
- };
- static const synctex_data_model_s synctex_data_model_tlchv = {
- synctex_data_tag_idx,
- synctex_data_line_idx,
- synctex_data_column_idx,
- synctex_data_h_idx,
- synctex_data_v_idx,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- synctex_data_tlchv_max
- };
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_spf_max+synctex_data_tlchv_max];
- } synctex_node_tlchv_s;
- static void _synctex_log_tlchv_node(synctex_node_p node);
- typedef synctex_node_tlchv_s synctex_node_math_s;
- DEFINE_synctex_new_scanned_NODE(math)
- static char * _synctex_abstract_math(synctex_node_p node);
- static void _synctex_display_math(synctex_node_p node);
- static synctex_inspector_s synctex_inspector_hv = {
- &_synctex_data_h,
- &_synctex_data_v,
- &_synctex_int_none,
- &_synctex_int_none,
- &_synctex_int_none,
- };
- static synctex_vispector_s synctex_vispector_hv = {
- &__synctex_node_visible_h,
- &__synctex_node_visible_v,
- &_synctex_float_none,
- &_synctex_float_none,
- &_synctex_float_none,
- };
- static synctex_class_s synctex_class_math = {
- NULL,
- synctex_node_type_math,
- &_synctex_new_math,
- &_synctex_free_leaf,
- &_synctex_log_tlchv_node,
- &_synctex_display_math,
- &_synctex_abstract_math,
- &synctex_tree_model_spf,
- &synctex_data_model_tlchv,
- &synctex_tlcpector_default,
- &synctex_inspector_hv,
- &synctex_vispector_hv,
- };
- static const synctex_data_model_s synctex_data_model_tlchvw = {
- synctex_data_tag_idx,
- synctex_data_line_idx,
- synctex_data_column_idx,
- synctex_data_h_idx,
- synctex_data_v_idx,
- synctex_data_width_idx,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- synctex_data_tlchvw_max
- };
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_spf_max+synctex_data_tlchvw_max];
- } synctex_node_kern_s;
- DEFINE_synctex_new_scanned_NODE(kern)
- static void _synctex_log_kern_node(synctex_node_p node);
- static char * _synctex_abstract_kern(synctex_node_p node);
- static void _synctex_display_kern(synctex_node_p node);
- static synctex_inspector_s synctex_inspector_kern = {
- &_synctex_data_h,
- &_synctex_data_v,
- &_synctex_data_width,
- &_synctex_int_none,
- &_synctex_int_none,
- };
- static float __synctex_kern_visible_h(synctex_node_p node);
- static float __synctex_kern_visible_width(synctex_node_p node);
- static synctex_vispector_s synctex_vispector_kern = {
- &__synctex_kern_visible_h,
- &__synctex_node_visible_v,
- &__synctex_kern_visible_width,
- &_synctex_float_none,
- &_synctex_float_none,
- };
- static synctex_class_s synctex_class_kern = {
- NULL,
- synctex_node_type_kern,
- &_synctex_new_kern,
- &_synctex_free_leaf,
- &_synctex_log_kern_node,
- &_synctex_display_kern,
- &_synctex_abstract_kern,
- &synctex_tree_model_spf,
- &synctex_data_model_tlchvw,
- &synctex_tlcpector_default,
- &synctex_inspector_kern,
- &synctex_vispector_kern,
- };
- typedef synctex_node_tlchv_s synctex_node_glue_s;
- DEFINE_synctex_new_scanned_NODE(glue)
- static char * _synctex_abstract_glue(synctex_node_p node);
- static void _synctex_display_glue(synctex_node_p node);
- static synctex_class_s synctex_class_glue = {
- NULL,
- synctex_node_type_glue,
- &_synctex_new_glue,
- &_synctex_free_leaf,
- &_synctex_log_tlchv_node,
- &_synctex_display_glue,
- &_synctex_abstract_glue,
- &synctex_tree_model_spf,
- &synctex_data_model_tlchv,
- &synctex_tlcpector_default,
- &synctex_inspector_hv,
- &synctex_vispector_hv,
- };
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_spf_max+synctex_data_box_max];
- } synctex_node_rule_s;
- DEFINE_synctex_new_scanned_NODE(rule)
- static void _synctex_log_rule(synctex_node_p node);
- static char * _synctex_abstract_rule(synctex_node_p node);
- static void _synctex_display_rule(synctex_node_p node);
- static float __synctex_rule_visible_h(synctex_node_p node);
- static float __synctex_rule_visible_v(synctex_node_p node);
- static float __synctex_rule_visible_width(synctex_node_p node);
- static float __synctex_rule_visible_height(synctex_node_p node);
- static float __synctex_rule_visible_depth(synctex_node_p node);
- static synctex_vispector_s synctex_vispector_rule = {
- &__synctex_rule_visible_h,
- &__synctex_rule_visible_v,
- &__synctex_rule_visible_width,
- &__synctex_rule_visible_height,
- &__synctex_rule_visible_depth,
- };
- static synctex_class_s synctex_class_rule = {
- NULL,
- synctex_node_type_rule,
- &_synctex_new_rule,
- &_synctex_free_leaf,
- &_synctex_log_rule,
- &_synctex_display_rule,
- &_synctex_abstract_rule,
- &synctex_tree_model_spf,
- &synctex_data_model_box,
- &synctex_tlcpector_default,
- &synctex_inspector_box,
- &synctex_vispector_rule,
- };
- typedef synctex_node_tlchv_s synctex_node_boundary_s;
- DEFINE_synctex_new_scanned_NODE(boundary)
- static char * _synctex_abstract_boundary(synctex_node_p node);
- static void _synctex_display_boundary(synctex_node_p node);
- static synctex_class_s synctex_class_boundary = {
- NULL,
- synctex_node_type_boundary,
- &_synctex_new_boundary,
- &_synctex_free_leaf,
- &_synctex_log_tlchv_node,
- &_synctex_display_boundary,
- &_synctex_abstract_boundary,
- &synctex_tree_model_spf,
- &synctex_data_model_tlchv,
- &synctex_tlcpector_default,
- &synctex_inspector_hv,
- &synctex_vispector_hv,
- };
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_spfa_max+synctex_data_tlchv_max];
- } synctex_node_box_bdry_s;
- SYNCTEX_INLINE static synctex_node_p _synctex_new_
- if (scanner) {\
- synctex_node_p node = _synctex_malloc(sizeof(synctex_node_
- if (node) {\
- node->class_ = scanner->class_+synctex_node_type_
- SYNCTEX_DID_NEW(node); \
- }\
- return node;\
- }\
- return NULL;\
- }
- DEFINE_synctex_new_unscanned_NODE(box_bdry)
- static char * _synctex_abstract_box_bdry(synctex_node_p node);
- static void _synctex_display_box_bdry(synctex_node_p node);
- static synctex_class_s synctex_class_box_bdry = {
- NULL,
- synctex_node_type_box_bdry,
- &_synctex_new_box_bdry,
- &_synctex_free_leaf,
- &_synctex_log_tlchv_node,
- &_synctex_display_box_bdry,
- &_synctex_abstract_box_bdry,
- &synctex_tree_model_spfa,
- &synctex_data_model_tlchv,
- &synctex_tlcpector_default,
- &synctex_inspector_hv,
- &synctex_vispector_hv,
- };
- static const synctex_tree_model_s synctex_tree_model_proxy_hbox = {
- synctex_tree_sibling_idx,
- synctex_tree_s_parent_idx,
- synctex_tree_sp_child_idx,
- synctex_tree_spc_friend_idx,
- synctex_tree_spcf_last_idx,
- synctex_tree_spcfl_next_hbox_idx,
- -1,
- synctex_tree_spcfln_target_idx,
- synctex_tree_spcflnt_proxy_hbox_max
- };
- static const synctex_data_model_s synctex_data_model_proxy = {
- -1,
- -1,
- -1,
- synctex_data_proxy_h_idx,
- synctex_data_proxy_v_idx,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- synctex_data_proxy_hv_max
- };
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_spcflnt_proxy_hbox_max+synctex_data_proxy_hv_max];
- } synctex_node_proxy_hbox_s;
- DEFINE_synctex_new_unscanned_NODE(proxy_hbox)
- static void _synctex_log_proxy(synctex_node_p node);
- static char * _synctex_abstract_proxy_hbox(synctex_node_p node);
- static void _synctex_display_proxy_hbox(synctex_node_p node);
- static int _synctex_proxy_tag(synctex_node_p);
- static int _synctex_proxy_line(synctex_node_p);
- static int _synctex_proxy_column(synctex_node_p);
- static synctex_tlcpector_s synctex_tlcpector_proxy = {
- &_synctex_proxy_tag,
- &_synctex_proxy_line,
- &_synctex_proxy_column,
- };
- static int _synctex_proxy_h(synctex_node_p);
- static int _synctex_proxy_v(synctex_node_p);
- static int _synctex_proxy_width(synctex_node_p);
- static int _synctex_proxy_height(synctex_node_p);
- static int _synctex_proxy_depth(synctex_node_p);
- static synctex_inspector_s synctex_inspector_proxy_box = {
- &_synctex_proxy_h,
- &_synctex_proxy_v,
- &_synctex_proxy_width,
- &_synctex_proxy_height,
- &_synctex_proxy_depth,
- };
- static float __synctex_proxy_visible_h(synctex_node_p);
- static float __synctex_proxy_visible_v(synctex_node_p);
- static float __synctex_proxy_visible_width(synctex_node_p);
- static float __synctex_proxy_visible_height(synctex_node_p);
- static float __synctex_proxy_visible_depth(synctex_node_p);
- static synctex_vispector_s synctex_vispector_proxy_box = {
- &__synctex_proxy_visible_h,
- &__synctex_proxy_visible_v,
- &__synctex_proxy_visible_width,
- &__synctex_proxy_visible_height,
- &__synctex_proxy_visible_depth,
- };
- static synctex_class_s synctex_class_proxy_hbox = {
- NULL,
- synctex_node_type_proxy_hbox,
- &_synctex_new_proxy_hbox,
- &_synctex_free_node,
- &_synctex_log_proxy,
- &_synctex_display_proxy_hbox,
- &_synctex_abstract_proxy_hbox,
- &synctex_tree_model_proxy_hbox,
- &synctex_data_model_proxy,
- &synctex_tlcpector_proxy,
- &synctex_inspector_proxy_box,
- &synctex_vispector_proxy_box,
- };
- static const synctex_tree_model_s synctex_tree_model_proxy_vbox = {
- synctex_tree_sibling_idx,
- synctex_tree_s_parent_idx,
- synctex_tree_sp_child_idx,
- synctex_tree_spc_friend_idx,
- synctex_tree_spcf_last_idx,
- -1,
- -1,
- synctex_tree_spcfl_target_idx,
- synctex_tree_spcflt_proxy_vbox_max
- };
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_spcflt_proxy_vbox_max+synctex_data_proxy_hv_max];
- } synctex_node_proxy_vbox_s;
- DEFINE_synctex_new_unscanned_NODE(proxy_vbox)
- static void _synctex_log_proxy(synctex_node_p node);
- static char * _synctex_abstract_proxy_vbox(synctex_node_p node);
- static void _synctex_display_proxy_vbox(synctex_node_p node);
- static synctex_class_s synctex_class_proxy_vbox = {
- NULL,
- synctex_node_type_proxy_vbox,
- &_synctex_new_proxy_vbox,
- &_synctex_free_node,
- &_synctex_log_proxy,
- &_synctex_display_proxy_vbox,
- &_synctex_abstract_proxy_vbox,
- &synctex_tree_model_proxy_vbox,
- &synctex_data_model_proxy,
- &synctex_tlcpector_proxy,
- &synctex_inspector_proxy_box,
- &synctex_vispector_proxy_box,
- };
- static const synctex_tree_model_s synctex_tree_model_proxy = {
- synctex_tree_sibling_idx,
- synctex_tree_s_parent_idx,
- -1,
- synctex_tree_sp_friend_idx,
- -1,
- -1,
- -1,
- synctex_tree_spf_target_idx,
- synctex_tree_spft_proxy_max
- };
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_spft_proxy_max+synctex_data_proxy_hv_max];
- } synctex_node_proxy_s;
- DEFINE_synctex_new_unscanned_NODE(proxy)
- static void _synctex_log_proxy(synctex_node_p node);
- static char * _synctex_abstract_proxy(synctex_node_p node);
- static void _synctex_display_proxy(synctex_node_p node);
- static synctex_vispector_s synctex_vispector_proxy = {
- &__synctex_proxy_visible_h,
- &__synctex_proxy_visible_v,
- &__synctex_proxy_visible_width,
- &_synctex_float_none,
- &_synctex_float_none,
- };
- static synctex_class_s synctex_class_proxy = {
- NULL,
- synctex_node_type_proxy,
- &_synctex_new_proxy,
- &_synctex_free_leaf,
- &_synctex_log_proxy,
- &_synctex_display_proxy,
- &_synctex_abstract_proxy,
- &synctex_tree_model_proxy,
- &synctex_data_model_proxy,
- &synctex_tlcpector_proxy,
- &synctex_inspector_proxy_box,
- &synctex_vispector_proxy,
- };
- static const synctex_tree_model_s synctex_tree_model_proxy_last = {
- synctex_tree_sibling_idx,
- synctex_tree_s_parent_idx,
- -1,
- synctex_tree_sp_friend_idx,
- -1,
- -1,
- synctex_tree_spf_arg_sibling_idx,
- synctex_tree_spfa_target_idx,
- synctex_tree_spfat_proxy_last_max
- };
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_spfat_proxy_last_max+synctex_data_proxy_hv_max];
- } synctex_node_proxy_last_s;
- DEFINE_synctex_new_unscanned_NODE(proxy_last)
- static void _synctex_log_proxy(synctex_node_p node);
- static char * _synctex_abstract_proxy(synctex_node_p node);
- static void _synctex_display_proxy(synctex_node_p node);
- static synctex_class_s synctex_class_proxy_last = {
- NULL,
- synctex_node_type_proxy_last,
- &_synctex_new_proxy,
- &_synctex_free_leaf,
- &_synctex_log_proxy,
- &_synctex_display_proxy,
- &_synctex_abstract_proxy,
- &synctex_tree_model_proxy_last,
- &synctex_data_model_proxy,
- &synctex_tlcpector_proxy,
- &synctex_inspector_proxy_box,
- &synctex_vispector_proxy,
- };
- static const synctex_tree_model_s synctex_tree_model_handle = {
- synctex_tree_sibling_idx,
- synctex_tree_s_parent_idx,
- synctex_tree_sp_child_idx,
- -1,
- -1,
- -1,
- -1,
- synctex_tree_spc_target_idx,
- synctex_tree_spct_handle_max
- };
- static const synctex_data_model_s synctex_data_model_handle = {
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- synctex_data_handle_w_idx,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- synctex_data_handle_w_max
- };
- typedef struct {
- SYNCTEX_DECLARE_CHARINDEX
- synctex_class_p class_;
- synctex_data_u data[synctex_tree_spct_handle_max+synctex_data_handle_w_max];
- } synctex_node_handle_s;
- DEFINE_synctex_new_unscanned_NODE(handle)
- static void _synctex_log_handle(synctex_node_p node);
- static char * _synctex_abstract_handle(synctex_node_p node);
- static void _synctex_display_handle(synctex_node_p node);
- static synctex_class_s synctex_class_handle = {
- NULL,
- synctex_node_type_handle,
- &_synctex_new_handle,
- &_synctex_free_handle,
- &_synctex_log_handle,
- &_synctex_display_handle,
- &_synctex_abstract_handle,
- &synctex_tree_model_handle,
- &synctex_data_model_handle,
- &synctex_tlcpector_proxy,
- &synctex_inspector_proxy_box,
- &synctex_vispector_proxy_box,
- };
- SYNCTEX_INLINE static synctex_node_p _synctex_new_handle_with_target(synctex_node_p target) {
- if (target) {
- synctex_node_p result = _synctex_new_handle(target->class_->scanner);
- if (result) {
- _synctex_tree_set_target(result,target);
- return result;
- }
- }
- return NULL;
- }
- SYNCTEX_INLINE static synctex_node_p _synctex_new_handle_with_child(synctex_node_p child) {
- if (child) {
- synctex_node_p result = _synctex_new_handle(child->class_->scanner);
- if (result) {
- _synctex_tree_set_child(result,child);
- return result;
- }
- }
- return NULL;
- }
- synctex_node_p synctex_node_parent(synctex_node_p node)
- {
- return _synctex_tree_parent(node);
- }
- synctex_node_p synctex_node_parent_sheet(synctex_node_p node)
- {
- while(node && synctex_node_type(node) != synctex_node_type_sheet) {
- node = _synctex_tree_parent(node);
- }
-
- return node;
- }
- synctex_node_p synctex_node_parent_form(synctex_node_p node)
- {
- while(node && synctex_node_type(node) != synctex_node_type_form) {
- node = _synctex_tree_parent(node);
- }
-
- return node;
- }
- SYNCTEX_INLINE static synctex_node_p __synctex_new_proxy_from_ref_to(synctex_node_p ref, synctex_node_p to_node) {
- synctex_node_p proxy = NULL;
- if (!ref || !to_node) {
- return NULL;
- }
- switch(synctex_node_type(to_node)) {
- case synctex_node_type_vbox:
- proxy = _synctex_new_proxy_vbox(ref->class_->scanner);
- break;
- case synctex_node_type_hbox:
- proxy = _synctex_new_proxy_hbox(ref->class_->scanner);
- break;
- default:
- _synctex_error("! __synctex_new_proxy_from_ref_to. Unexpected form child (%s). Please report.", synctex_node_isa(to_node));
- return NULL;
- }
- if (!proxy) {
- _synctex_error("! __synctex_new_proxy_from_ref_to. Internal error. Please report.");
- return NULL;
- }
- _synctex_data_set_h(proxy, _synctex_data_h(ref));
- _synctex_data_set_v(proxy, _synctex_data_v(ref)-_synctex_data_height(to_node));
- _synctex_tree_set_target(proxy,to_node);
- proxy->line_index=to_node?to_node->line_index:0;
- proxy->char_index=to_node?to_node->char_index:0;
- return proxy;
- }
- SYNCTEX_INLINE static synctex_node_p __synctex_new_child_proxy_to(synctex_node_p owner, synctex_node_p to_node) {
- synctex_node_p proxy = NULL;
- synctex_node_p target = to_node;
- if (!owner) {
- return NULL;
- }
- switch(synctex_node_type(target)) {
- case synctex_node_type_vbox:
- if ((proxy = _synctex_new_proxy_vbox(owner->class_->scanner))) {
- exit_standard:
- _synctex_data_set_h(proxy, _synctex_data_h(owner));
- _synctex_data_set_v(proxy, _synctex_data_v(owner));
- exit0:
- _synctex_tree_set_target(proxy,target);
- proxy->line_index=to_node?to_node->line_index:0;
- proxy->char_index=to_node?to_node->char_index:0;
- return proxy;
- };
- break;
- case synctex_node_type_proxy_vbox:
- if ((proxy = _synctex_new_proxy_vbox(owner->class_->scanner))) {
- exit_proxy:
- target = _synctex_tree_target(to_node);
- _synctex_data_set_h(proxy, _synctex_data_h(owner)+_synctex_data_h(to_node));
- _synctex_data_set_v(proxy, _synctex_data_v(owner)+_synctex_data_v(to_node));
- goto exit0;
- };
- break;
- case synctex_node_type_hbox:
- if ((proxy = _synctex_new_proxy_hbox(owner->class_->scanner))) {
- goto exit_standard;
- };
- break;
- case synctex_node_type_proxy_hbox:
- if ((proxy = _synctex_new_proxy_hbox(owner->class_->scanner))) {
- goto exit_proxy;
- };
- break;
- case synctex_node_type_proxy:
- case synctex_node_type_proxy_last:
- if ((proxy = _synctex_new_proxy(owner->class_->scanner))) {
- goto exit_proxy;
- };
- break;
- default:
- if ((proxy = _synctex_new_proxy(owner->class_->scanner))) {
- goto exit_standard;
- };
- break;
- }
- _synctex_error("! __synctex_new_child_proxy_to. "
- "Internal error. "
- "Please report.");
- return NULL;
- }
- SYNCTEX_INLINE static synctex_node_p _synctex_tree_set_sibling(synctex_node_p node, synctex_node_p new_sibling);
- typedef struct synctex_nns_t {
- synctex_node_p first;
- synctex_node_p last;
- synctex_status_t status;
- } synctex_nns_s;
- SYNCTEX_INLINE static synctex_nns_s _synctex_new_child_proxies_to(synctex_node_p owner, synctex_node_p to_node) {
- synctex_nns_s nns = {NULL,NULL,SYNCTEX_STATUS_OK};
- if ((nns.first = nns.last = __synctex_new_child_proxy_to(owner,to_node))) {
- synctex_node_p to_next_sibling = __synctex_tree_sibling(to_node);
- synctex_node_p to_sibling;
- while ((to_sibling = to_next_sibling)) {
- synctex_node_p sibling;
- if ((to_next_sibling = __synctex_tree_sibling(to_sibling))) {
-
- if((sibling = __synctex_new_child_proxy_to(owner,to_sibling))) {
- _synctex_tree_set_sibling(nns.last,sibling);
- nns.last = sibling;
- continue;
- } else {
- _synctex_error("! _synctex_new_child_proxy_to. "
- "Internal error (1). "
- "Please report.");
- nns.status = SYNCTEX_STATUS_ERROR;
- }
- } else if((sibling = _synctex_new_proxy_last(owner->class_->scanner))) {
- _synctex_tree_set_sibling(nns.last,sibling);
- nns.last = sibling;
- _synctex_data_set_h(nns.last, _synctex_data_h(nns.first));
- _synctex_data_set_v(nns.last, _synctex_data_v(nns.first));
- _synctex_tree_set_target(nns.last,to_sibling);
- nns.last->line_index=to_sibling->line_index;
- nns.last->char_index=to_sibling->char_index;
- } else {
- _synctex_error("! _synctex_new_child_proxy_to. "
- "Internal error (2). "
- "Please report.");
- nns.status = SYNCTEX_STATUS_ERROR;
- }
- break;
- }
- }
- return nns;
- }
- static char * _synctex_node_abstract(synctex_node_p node);
- SYNCTEX_INLINE static synctex_node_p synctex_tree_set_friend(synctex_node_p node,synctex_node_p new_friend) {
- synctex_node_p F = new_friend;
- while (F) {
- if (node == F) {
- printf("THIS IS AN ERROR\n");
- F = new_friend;
- while (F) {
- printf("%s\n",_synctex_node_abstract(F));
- if (node == F) {
- return NULL;
- }
- F = _synctex_tree_friend(F);
- }
- return NULL;
- }
- F = _synctex_tree_friend(F);
- }
- return new_friend?_synctex_tree_set_friend(node,new_friend):_synctex_tree_reset_friend(node);
- }
- SYNCTEX_INLINE static synctex_node_p __synctex_node_make_friend(synctex_node_p node, int i) {
- synctex_node_p old = NULL;
- if (i>=0) {
- i = i%(node->class_->scanner->number_of_lists);
- old = synctex_tree_set_friend(node,(node->class_->scanner->lists_of_friends)[i]);
- (node->class_->scanner->lists_of_friends)[i] = node;
- printf("tl(%i)=>",i);
- synctex_node_log(node);
- if (synctex_node_parent_form(node)) {
- printf("! ERROR. No registration expected!\n");
- }
- }
- return old;
- }
- SYNCTEX_INLINE static synctex_node_p __synctex_proxy_make_friend_and_next_hbox(synctex_node_p node) {
- synctex_node_p old = NULL;
- synctex_node_p target = _synctex_tree_target(node);
- if (target) {
- int i = _synctex_data_tag(target)+_synctex_data_line(target);
- old = __synctex_node_make_friend(node,i);
- } else {
- old = __synctex_tree_reset_friend(node);
- }
- if (synctex_node_type(node) == synctex_node_type_proxy_hbox) {
- synctex_node_p sheet = synctex_node_parent_sheet(node);
- if (sheet) {
- _synctex_tree_set_next_hbox(node,_synctex_tree_next_hbox(sheet));
- _synctex_tree_set_next_hbox(sheet,node);
- }
- }
- return old;
- }
- SYNCTEX_INLINE static synctex_node_p __synctex_node_make_friend_tlc(synctex_node_p node) {
- int i = synctex_node_tag(node)+synctex_node_line(node);
- return __synctex_node_make_friend(node,i);
- }
- SYNCTEX_INLINE static void _synctex_node_make_friend_tlc(synctex_node_p node) {
- if (node) {
- __synctex_node_make_friend_tlc(node);
- }
- }
- static synctex_node_p _synctex_node_set_child(synctex_node_p node, synctex_node_p new_child);
- synctex_node_p synctex_node_child(synctex_node_p node) {
- synctex_node_p child = NULL;
- synctex_node_p target = NULL;
- if ((child = _synctex_tree_child(node))) {
- return child;
- } else if ((target = _synctex_tree_target(node))) {
- if ((child = synctex_node_child(target))) {
-
- synctex_nns_s nns = _synctex_new_child_proxies_to(node, child);
- if (nns.first) {
- _synctex_node_set_child(node,nns.first);
- return nns.first;
- } else {
- _synctex_error("! synctex_node_child. Internal inconsistency. Please report.");
- }
- }
- }
- return NULL;
- }
- static synctex_node_p _synctex_node_set_child(synctex_node_p parent, synctex_node_p new_child) {
- if (parent) {
- synctex_node_p old = _synctex_tree_set_child(parent,new_child);
- synctex_node_p last_child = NULL;
- synctex_node_p child;
- if ((child = old)) {
- do {
- _synctex_tree_reset_parent(child);
- } while ((child = __synctex_tree_sibling(child)));
- }
- if ((child = new_child)) {
- do {
- _synctex_tree_set_parent(child,parent);
- last_child = child;
- } while ((child = __synctex_tree_sibling(child)));
- }
- _synctex_tree_set_last(parent,last_child);
- return old;
- }
- return NULL;
- }
- synctex_node_p synctex_node_last_child(synctex_node_p node) {
- return _synctex_tree_last(node);
- }
- synctex_node_p synctex_node_sibling(synctex_node_p node) {
- return node? __synctex_tree_sibling(node): NULL;
- }
- SYNCTEX_INLINE static synctex_node_p _synctex_tree_set_sibling(synctex_node_p node, synctex_node_p new_sibling) {
- if (node == new_sibling) {
- printf("BOF\n");
- }
- synctex_node_p old = node? __synctex_tree_set_sibling(node,new_sibling): NULL;
- _synctex_tree_set_arg_sibling(new_sibling,node);
- return old;
- }
- static synctex_node_p _synctex_node_set_sibling(synctex_node_p node, synctex_node_p new_sibling) {
- if (node && new_sibling) {
- synctex_node_p old = _synctex_tree_set_sibling(node,new_sibling);
- if (_synctex_tree_has_parent(node)) {
- synctex_node_p parent = __synctex_tree_parent(node);
- if (parent) {
- synctex_node_p N = new_sibling;
- while (synctex_YES) {
- if (_synctex_tree_has_parent(N)) {
- __synctex_tree_set_parent(N,parent);
- _synctex_tree_set_last(parent,N);
- N = __synctex_tree_sibling(N);
- continue;
- } else if (N) {
- _synctex_error("! synctex_node_sibling. "
- "Internal inconsistency. "
- "Please report.");
- }
- break;
- }
- }
- }
- return old;
- }
- return NULL;
- }
- synctex_node_p synctex_node_last_sibling(synctex_node_p node) {
- synctex_node_p sibling;
- do {
- sibling = node;
- } while((node = synctex_node_sibling(node)));
- return sibling;
- }
- SYNCTEX_INLINE static synctex_node_p _synctex_node_sibling_or_parents(synctex_node_p node) {
- while (node) {
- synctex_node_p N;
- if ((N = __synctex_tree_sibling(node))) {
- return N;
- } else if ((node = _synctex_tree_parent(node))) {
- if (synctex_node_type(node) == synctex_node_type_sheet) {
- return NULL;
- } else if (synctex_node_type(node) == synctex_node_type_form) {
- return NULL;
- }
- } else {
- return NULL;
- }
- }
- return NULL;
- }
- synctex_node_p synctex_node_next(synctex_node_p node) {
- synctex_node_p N = synctex_node_child(node);
- if (N) {
- return N;
- }
- return _synctex_node_sibling_or_parents(node);
- }
- synctex_node_p synctex_node_arg_sibling(synctex_node_p node) {
- return _synctex_tree_arg_sibling(node);
- synctex_node_p N = _synctex_tree_parent(node);
- if ((N = _synctex_tree_child(N))) {
- do {
- synctex_node_p NN = __synctex_tree_sibling(N);
- if (NN == node) {
- return N;
- }
- N = NN;
- } while (N);
- }
- return N;
- }
- synctex_node_type_t synctex_node_type(synctex_node_p node) {
- return node? node->class_->type: synctex_node_type_none;
- }
- synctex_node_type_t synctex_node_target_type(synctex_node_p node) {
- synctex_node_p target = _synctex_tree_target(node);
- if (target) {
- return (((target)->class_))->type;
- } else if (node) {
- return (((node)->class_))->type;
- }
- return synctex_node_type_none;
- }
- const char * synctex_node_isa(synctex_node_p node) {
- static const char * isa[synctex_node_number_of_types] =
- {"Not a node",
- "input",
- "sheet",
- "form",
- "ref",
- "vbox",
- "void vbox",
- "hbox",
- "void hbox",
- "kern",
- "glue",
- "rule",
- "math",
- "boundary",
- "box_bdry",
- "proxy",
- "last proxy",
- "vbox proxy",
- "hbox proxy",
- "handle"};
- return isa[synctex_node_type(node)];
- }
- void synctex_node_log(synctex_node_p node) {
- SYNCTEX_MSG_SEND(node,log);
- }
- static void _synctex_log_input(synctex_node_p node) {
- if (node) {
- printf("%s:%i,%s(%i)\n",synctex_node_isa(node),
- _synctex_data_tag(node),
- _synctex_data_name(node),
- _synctex_data_line(node));
- printf("SELF:%p\n",(void *)node);
- printf(" SIBLING:%p\n",
- (void *)__synctex_tree_sibling(node));
- }
- }
- static void _synctex_log_sheet(synctex_node_p node) {
- if (node) {
- printf("%s:%i",synctex_node_isa(node),_synctex_data_page(node));
- SYNCTEX_PRINT_CHARINDEX_NL;
- printf("SELF:%p\n",(void *)node);
- printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
- printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
- printf(" CHILD:%p\n",(void *)_synctex_tree_child(node));
- printf(" LEFT:%p\n",(void *)_synctex_tree_friend(node));
- printf(" NEXT_hbox:%p\n",(void *)_synctex_tree_next_hbox(node));
- }
- }
- static void _synctex_log_form(synctex_node_p node) {
- if (node) {
- printf("%s:%i",synctex_node_isa(node),_synctex_data_tag(node));
- SYNCTEX_PRINT_CHARINDEX_NL;
- printf("SELF:%p\n",(void *)node);
- printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
- printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
- printf(" CHILD:%p\n",(void *)_synctex_tree_child(node));
- printf(" LEFT:%p\n",(void *)_synctex_tree_friend(node));
- }
- }
- static void _synctex_log_ref(synctex_node_p node) {
- if (node) {
- printf("%s:%i:%i,%i",
- synctex_node_isa(node),
- _synctex_data_tag(node),
- _synctex_data_h(node),
- _synctex_data_v(node));
- SYNCTEX_PRINT_CHARINDEX_NL;
- printf("SELF:%p\n",(void *)node);
- printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
- printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
- }
- }
- static void _synctex_log_tlchv_node(synctex_node_p node) {
- if (node) {
- printf("%s:%i,%i,%i:%i,%i",
- synctex_node_isa(node),
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_column(node),
- _synctex_data_h(node),
- _synctex_data_v(node));
- SYNCTEX_PRINT_CHARINDEX_NL;
- printf("SELF:%p\n",(void *)node);
- printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
- printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
- printf(" CHILD:%p\n",(void *)_synctex_tree_child(node));
- printf(" LEFT:%p\n",(void *)_synctex_tree_friend(node));
- }
- }
- static void _synctex_log_kern_node(synctex_node_p node) {
- if (node) {
- printf("%s:%i,%i,%i:%i,%i:%i",
- synctex_node_isa(node),
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_column(node),
- _synctex_data_h(node),
- _synctex_data_v(node),
- _synctex_data_width(node));
- SYNCTEX_PRINT_CHARINDEX_NL;
- printf("SELF:%p\n",(void *)node);
- printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
- printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
- printf(" CHILD:%p\n",(void *)_synctex_tree_child(node));
- printf(" LEFT:%p\n",(void *)_synctex_tree_friend(node));
- }
- }
- static void _synctex_log_rule(synctex_node_p node) {
- if (node) {
- printf("%s:%i,%i,%i:%i,%i",
- synctex_node_isa(node),
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_column(node),
- _synctex_data_h(node),
- _synctex_data_v(node));
- printf(":%i",_synctex_data_width(node));
- printf(",%i",_synctex_data_height(node));
- printf(",%i",_synctex_data_depth(node));
- SYNCTEX_PRINT_CHARINDEX_NL;
- printf("SELF:%p\n",(void *)node);
- printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
- printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
- printf(" LEFT:%p\n",(void *)_synctex_tree_friend(node));
- }
- }
- static void _synctex_log_void_box(synctex_node_p node) {
- if (node) {
- printf("%s",synctex_node_isa(node));
- printf(":%i",_synctex_data_tag(node));
- printf(",%i",_synctex_data_line(node));
- printf(",%i",_synctex_data_column(node));
- printf(":%i",_synctex_data_h(node));
- printf(",%i",_synctex_data_v(node));
- printf(":%i",_synctex_data_width(node));
- printf(",%i",_synctex_data_height(node));
- printf(",%i",_synctex_data_depth(node));
- SYNCTEX_PRINT_CHARINDEX_NL;
- printf("SELF:%p\n",(void *)node);
- printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
- printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
- printf(" CHILD:%p\n",(void *)_synctex_tree_child(node));
- printf(" LEFT:%p\n",(void *)_synctex_tree_friend(node));
- }
- }
- static void _synctex_log_vbox(synctex_node_p node) {
- if (node) {
- printf("%s",synctex_node_isa(node));
- printf(":%i",_synctex_data_tag(node));
- printf(",%i",_synctex_data_line(node));
- printf(",%i",_synctex_data_column(node));
- printf(":%i",_synctex_data_h(node));
- printf(",%i",_synctex_data_v(node));
- printf(":%i",_synctex_data_width(node));
- printf(",%i",_synctex_data_height(node));
- printf(",%i",_synctex_data_depth(node));
- SYNCTEX_PRINT_CHARINDEX_NL;
- printf("SELF:%p\n",(void *)node);
- printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
- printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
- printf(" CHILD:%p\n",(void *)_synctex_tree_child(node));
- printf(" LEFT:%p\n",(void *)_synctex_tree_friend(node));
- printf(" NEXT_hbox:%p\n",(void *)_synctex_tree_next_hbox(node));
- }
- }
- static void _synctex_log_hbox(synctex_node_p node) {
- if (node) {
- printf("%s",synctex_node_isa(node));
- printf(":%i",_synctex_data_tag(node));
- printf(",%i~%i*%i",_synctex_data_line(node),_synctex_data_mean_line(node),_synctex_data_weight(node));
- printf(",%i",_synctex_data_column(node));
- printf(":%i",_synctex_data_h(node));
- printf(",%i",_synctex_data_v(node));
- printf(":%i",_synctex_data_width(node));
- printf(",%i",_synctex_data_height(node));
- printf(",%i",_synctex_data_depth(node));
- printf("/%i",_synctex_data_h_V(node));
- printf(",%i",_synctex_data_v_V(node));
- printf(":%i",_synctex_data_width_V(node));
- printf(",%i",_synctex_data_height_V(node));
- printf(",%i",_synctex_data_depth_V(node));
- SYNCTEX_PRINT_CHARINDEX_NL;
- printf("SELF:%p\n",(void *)node);
- printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
- printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
- printf(" CHILD:%p\n",(void *)_synctex_tree_child(node));
- printf(" LEFT:%p\n",(void *)_synctex_tree_friend(node));
- printf(" NEXT_hbox:%p\n",(void *)_synctex_tree_next_hbox(node));
- }
- }
- static void _synctex_log_proxy(synctex_node_p node) {
- if (node) {
- synctex_node_p N = _synctex_tree_target(node);
- printf("%s",synctex_node_isa(node));
- printf(":%i",_synctex_data_h(node));
- printf(",%i",_synctex_data_v(node));
- SYNCTEX_PRINT_CHARINDEX_NL;
- printf("SELF:%p\n",(void *)node);
- printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
- printf(" LEFT:%p\n",(void *)_synctex_tree_friend(node));
- printf(" ->%s\n",_synctex_node_abstract(N));
- }
- }
- static void _synctex_log_handle(synctex_node_p node) {
- if (node) {
- synctex_node_p N = _synctex_tree_target(node);
- printf("%s",synctex_node_isa(node));
- SYNCTEX_PRINT_CHARINDEX_NL;
- printf("SELF:%p\n",(void *)node);
- printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
- printf(" ->%s\n",_synctex_node_abstract(N));
- }
- }
- int synctex_scanner_display_switcher(synctex_scanner_p scanR) {
- return scanR->display_switcher;
- }
- void synctex_scanner_set_display_switcher(synctex_scanner_p scanR, int switcher) {
- scanR->display_switcher = switcher;
- }
- static const char * const _synctex_display_prompt = "................................";
- static char * _synctex_scanner_display_prompt_down(synctex_scanner_p scanR) {
- if (scanR->display_prompt>_synctex_display_prompt) {
- --scanR->display_prompt;
- }
- return scanR->display_prompt;
- }
- static char * _synctex_scanner_display_prompt_up(synctex_scanner_p scanR) {
- if (scanR->display_prompt+1<_synctex_display_prompt+strlen(_synctex_display_prompt)) {
- ++scanR->display_prompt;
- }
- return scanR->display_prompt;
- }
- void synctex_node_display(synctex_node_p node) {
- if (node) {
- synctex_scanner_p scanR = node->class_->scanner;
- if (scanR) {
- if (scanR->display_switcher<0) {
- SYNCTEX_MSG_SEND(node, display);
- } else if (scanR->display_switcher>0 && --scanR->display_switcher>0) {
- SYNCTEX_MSG_SEND(node, display);
- } else if (scanR->display_switcher-->=0) {
- printf("%s Next display skipped. Reset display switcher.\n",node->class_->scanner->display_prompt);
- }
- } else {
- SYNCTEX_MSG_SEND(node, display);
- }
- }
- }
- static char * _synctex_node_abstract(synctex_node_p node) {
- SYNCTEX_PARAMETER_ASSERT(node || node->class_);
- return (node && node->class_->abstract)? node->class_->abstract(node):"none";
- }
- SYNCTEX_INLINE static void _synctex_display_child(synctex_node_p node) {
- synctex_node_p N = _synctex_tree_child(node);
- if (N) {
- _synctex_scanner_display_prompt_down(N->class_->scanner);
- synctex_node_display(N);
- _synctex_scanner_display_prompt_up(N->class_->scanner);
- }
- }
- SYNCTEX_INLINE static void _synctex_display_sibling(synctex_node_p node) {
- synctex_node_display(__synctex_tree_sibling(node));
- }
- static char * _synctex_abstract_input(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"Input:%i:%s(%i)" SYNCTEX_PRINT_CHARINDEX_FMT,
- _synctex_data_tag(node),
- _synctex_data_name(node),
- _synctex_data_line(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- }
- return abstract;
- }
- static void _synctex_display_input(synctex_node_p node) {
- if (node) {
- printf("Input:%i:%s(%i)"
- SYNCTEX_PRINT_CHARINDEX_FMT
- "\n",
- _synctex_data_tag(node),
- _synctex_data_name(node),
- _synctex_data_line(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- synctex_node_display(__synctex_tree_sibling(node));
- }
- }
- static char * _synctex_abstract_sheet(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"{%i...}" SYNCTEX_PRINT_CHARINDEX_FMT,
- _synctex_data_page(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- }
- return abstract;
- }
- static void _synctex_display_sheet(synctex_node_p node) {
- if (node) {
- printf("%s{%i"
- SYNCTEX_PRINT_CHARINDEX_FMT
- "\n",
- node->class_->scanner->display_prompt,
- _synctex_data_page(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- _synctex_display_child(node);
- printf("%s}\n",node->class_->scanner->display_prompt);
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_form(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"<%i...>" SYNCTEX_PRINT_CHARINDEX_FMT,
- _synctex_data_tag(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- SYNCTEX_PRINT_CHARINDEX;
- }
- return abstract;
- }
- static void _synctex_display_form(synctex_node_p node) {
- if (node) {
- printf("%s<%i"
- SYNCTEX_PRINT_CHARINDEX_FMT
- "\n",
- node->class_->scanner->display_prompt,
- _synctex_data_tag(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- _synctex_display_child(node);
- printf("%s>\n",node->class_->scanner->display_prompt);
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_vbox(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"[%i,%i:%i,%i:%i,%i,%i...]"
- SYNCTEX_PRINT_CHARINDEX_FMT,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node),
- _synctex_data_width(node),
- _synctex_data_height(node),
- _synctex_data_depth(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- }
- return abstract;
- }
- static void _synctex_display_vbox(synctex_node_p node) {
- if (node) {
- printf("%s[%i,%i:%i,%i:%i,%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT
- "\n",
- node->class_->scanner->display_prompt,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node),
- _synctex_data_width(node),
- _synctex_data_height(node),
- _synctex_data_depth(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- _synctex_display_child(node);
- printf("%s]\n%slast:%s\n",
- node->class_->scanner->display_prompt,
- node->class_->scanner->display_prompt,
- _synctex_node_abstract(_synctex_tree_last(node)));
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_hbox(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"(%i,%i~%i*%i:%i,%i:%i,%i,%i...)"
- SYNCTEX_PRINT_CHARINDEX_FMT,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_mean_line(node),
- _synctex_data_weight(node),
- _synctex_data_h(node),
- _synctex_data_v(node),
- _synctex_data_width(node),
- _synctex_data_height(node),
- _synctex_data_depth(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- }
- return abstract;
- }
- static void _synctex_display_hbox(synctex_node_p node) {
- if (node) {
- printf("%s(%i,%i~%i*%i:%i,%i:%i,%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT
- "\n",
- node->class_->scanner->display_prompt,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_mean_line(node),
- _synctex_data_weight(node),
- _synctex_data_h(node),
- _synctex_data_v(node),
- _synctex_data_width(node),
- _synctex_data_height(node),
- _synctex_data_depth(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- _synctex_display_child(node);
- printf("%s)\n%slast:%s\n",
- node->class_->scanner->display_prompt,
- node->class_->scanner->display_prompt,
- _synctex_node_abstract(_synctex_tree_last(node)));
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_void_vbox(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"v%i,%i;%i,%i:%i,%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT
- "\n",
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node),
- _synctex_data_width(node),
- _synctex_data_height(node),
- _synctex_data_depth(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- }
- return abstract;
- }
- static void _synctex_display_void_vbox(synctex_node_p node) {
- if (node) {
- printf("%sv%i,%i;%i,%i:%i,%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT
- "\n",
- node->class_->scanner->display_prompt,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node),
- _synctex_data_width(node),
- _synctex_data_height(node),
- _synctex_data_depth(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_void_hbox(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"h%i,%i:%i,%i:%i,%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node),
- _synctex_data_width(node),
- _synctex_data_height(node),
- _synctex_data_depth(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- }
- return abstract;
- }
- static void _synctex_display_void_hbox(synctex_node_p node) {
- if (node) {
- printf("%sh%i,%i:%i,%i:%i,%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT
- "\n",
- node->class_->scanner->display_prompt,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node),
- _synctex_data_width(node),
- _synctex_data_height(node),
- _synctex_data_depth(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_glue(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"glue:%i,%i:%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- }
- return abstract;
- }
- static void _synctex_display_glue(synctex_node_p node) {
- if (node) {
- printf("%sglue:%i,%i:%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT
- "\n",
- node->class_->scanner->display_prompt,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_rule(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"rule:%i,%i:%i,%i:%i,%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node),
- _synctex_data_width(node),
- _synctex_data_height(node),
- _synctex_data_depth(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- }
- return abstract;
- }
- static void _synctex_display_rule(synctex_node_p node) {
- if (node) {
- printf("%srule:%i,%i:%i,%i:%i,%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT
- "\n",
- node->class_->scanner->display_prompt,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node),
- _synctex_data_width(node),
- _synctex_data_height(node),
- _synctex_data_depth(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_math(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"math:%i,%i:%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- }
- return abstract;
- }
- static void _synctex_display_math(synctex_node_p node) {
- if (node) {
- printf("%smath:%i,%i:%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT
- "\n",
- node->class_->scanner->display_prompt,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_kern(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"kern:%i,%i:%i,%i:%i"
- SYNCTEX_PRINT_CHARINDEX_FMT,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node),
- _synctex_data_width(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- }
- return abstract;
- }
- static void _synctex_display_kern(synctex_node_p node) {
- if (node) {
- printf("%skern:%i,%i:%i,%i:%i"
- SYNCTEX_PRINT_CHARINDEX_FMT
- "\n",
- node->class_->scanner->display_prompt,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node),
- _synctex_data_width(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_boundary(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"boundary:%i,%i:%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- }
- return abstract;
- }
- static void _synctex_display_boundary(synctex_node_p node) {
- if (node) {
- printf("%sboundary:%i,%i:%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT
- "\n",
- node->class_->scanner->display_prompt,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_box_bdry(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"box bdry:%i,%i:%i,%i" SYNCTEX_PRINT_CHARINDEX_FMT,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- }
- return abstract;
- }
- static void _synctex_display_box_bdry(synctex_node_p node) {
- if (node) {
- printf("%sbox bdry:%i,%i:%i,%i",
- node->class_->scanner->display_prompt,
- _synctex_data_tag(node),
- _synctex_data_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node));
- SYNCTEX_PRINT_CHARINDEX_NL;
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_ref(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"form ref:%i:%i,%i" SYNCTEX_PRINT_CHARINDEX_FMT,
- _synctex_data_tag(node),
- _synctex_data_h(node),
- _synctex_data_v(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- }
- return abstract;
- }
- static void _synctex_display_ref(synctex_node_p node) {
- if (node) {
- printf("%sform ref:%i:%i,%i",
- node->class_->scanner->display_prompt,
- _synctex_data_tag(node),
- _synctex_data_h(node),
- _synctex_data_v(node));
- SYNCTEX_PRINT_CHARINDEX_NL;
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_proxy(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- synctex_node_p N = _synctex_tree_target(node);
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"%s:%i,%i:%i,%i/%p%s",
- synctex_node_isa(node),
- synctex_node_tag(node),
- synctex_node_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node),
- node,
- _synctex_node_abstract(N));
- }
- return abstract;
- }
- static void _synctex_display_proxy(synctex_node_p node) {
- if (node) {
- synctex_node_p N = _synctex_tree_target(node);
- printf("%s%s:%i,%i:%i,%i",
- node->class_->scanner->display_prompt,
- synctex_node_isa(node),
- synctex_node_tag(node),
- synctex_node_line(node),
- _synctex_data_h(node),
- _synctex_data_v(node));
- if (N) {
- printf("=%i,%i:%i,%i,%i->%s",
- synctex_node_h(node),
- synctex_node_v(node),
- synctex_node_width(node),
- synctex_node_height(node),
- synctex_node_depth(node),
- _synctex_node_abstract(N));
- }
- printf("\n");
- _synctex_display_child(node);
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_proxy_vbox(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,
- "[*%i,%i:%i,%i:%i,%i,%i...*]"
- SYNCTEX_PRINT_CHARINDEX_FMT,
- synctex_node_tag(node),
- synctex_node_line(node),
- synctex_node_h(node),
- synctex_node_v(node),
- synctex_node_width(node),
- synctex_node_height(node),
- synctex_node_depth(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- }
- return abstract;
- }
- static void _synctex_display_proxy_vbox(synctex_node_p node) {
- if (node) {
- printf("%s[*%i,%i:%i,%i:%i,%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT
- "\n",
- node->class_->scanner->display_prompt,
- synctex_node_tag(node),
- synctex_node_line(node),
- synctex_node_h(node),
- synctex_node_v(node),
- synctex_node_width(node),
- synctex_node_height(node),
- synctex_node_depth(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- _synctex_display_child(node);
- printf("%s*]\n%slast:%s\n",
- node->class_->scanner->display_prompt,
- node->class_->scanner->display_prompt,
- _synctex_node_abstract(_synctex_tree_last(node)));
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_proxy_hbox(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"(*%i,%i~%i*%i:%i,%i:%i,%i,%i...*)/%p"
- SYNCTEX_PRINT_CHARINDEX_FMT,
- synctex_node_tag(node),
- synctex_node_line(node),
- synctex_node_mean_line(node),
- synctex_node_weight(node),
- synctex_node_h(node),
- synctex_node_v(node),
- synctex_node_width(node),
- synctex_node_height(node),
- synctex_node_depth(node),
- node
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- }
- return abstract;
- }
- static void _synctex_display_proxy_hbox(synctex_node_p node) {
- if (node) {
- printf("%s(*%i,%i~%i*%i:%i,%i:%i,%i,%i"
- SYNCTEX_PRINT_CHARINDEX_FMT
- "\n",
- node->class_->scanner->display_prompt,
- synctex_node_tag(node),
- synctex_node_line(node),
- synctex_node_mean_line(node),
- synctex_node_weight(node),
- synctex_node_h(node),
- synctex_node_v(node),
- synctex_node_width(node),
- synctex_node_height(node),
- synctex_node_depth(node)
- SYNCTEX_PRINT_CHARINDEX_WHAT);
- _synctex_display_child(node);
- printf("%s*)\n%slast:%s\n",
- node->class_->scanner->display_prompt,
- node->class_->scanner->display_prompt,
- _synctex_node_abstract(_synctex_tree_last(node)));
- _synctex_display_sibling(node);
- }
- }
- static char * _synctex_abstract_handle(synctex_node_p node) {
- static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
- if (node) {
- synctex_node_p N = _synctex_tree_target(node);
- if (N && !N->class_) {
- exit(1);
- }
- snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"%s:%s",
- synctex_node_isa(node),
- (N?_synctex_node_abstract(N):""));
- }
- return abstract;
- }
- static void _synctex_display_handle(synctex_node_p node) {
- if (node) {
- synctex_node_p N = _synctex_tree_target(node);
- printf("%s%s(%i):->%s\n",
- node->class_->scanner->display_prompt,
- synctex_node_isa(node),
- _synctex_data_weight(N),
- _synctex_node_abstract(N));
- _synctex_display_child(node);
- _synctex_display_sibling(node);
- }
- }
- typedef struct {
- size_t size;
- synctex_status_t status;
- } synctex_zs_s;
- static synctex_zs_s _synctex_buffer_get_available_size(synctex_scanner_p scanner, size_t size);
- static synctex_status_t _synctex_next_line(synctex_scanner_p scanner);
- static synctex_status_t _synctex_match_string(synctex_scanner_p scanner, const char * the_string);
- typedef struct synctex_ns_t {
- synctex_node_p node;
- synctex_status_t status;
- } synctex_ns_s;
- static synctex_ns_s __synctex_parse_new_input(synctex_scanner_p scanner);
- static synctex_status_t _synctex_scan_preamble(synctex_scanner_p scanner);
- typedef struct {
- float value;
- synctex_status_t status;
- } synctex_fs_s;
- static synctex_fs_s _synctex_scan_float_and_dimension(synctex_scanner_p scanner);
- static synctex_status_t _synctex_scan_post_scriptum(synctex_scanner_p scanner);
- static synctex_status_t _synctex_scan_postamble(synctex_scanner_p scanner);
- static synctex_status_t _synctex_setup_visible_hbox(synctex_node_p box);
- static synctex_status_t _synctex_scan_content(synctex_scanner_p scanner);
- int synctex_scanner_pre_x_offset(synctex_scanner_p scanner);
- int synctex_scanner_pre_y_offset(synctex_scanner_p scanner);
- const char * synctex_scanner_get_output_fmt(synctex_scanner_p scanner);
- static synctex_zs_s _synctex_buffer_get_available_size(synctex_scanner_p scanner, size_t expected) {
- size_t size = 0;
- if (NULL == scanner) {
- return (synctex_zs_s){0,SYNCTEX_STATUS_BAD_ARGUMENT};
- }
- if (expected>scanner->reader->size){
- expected = scanner->reader->size;
- }
- size = SYNCTEX_END - SYNCTEX_CUR;
- if (expected<=size) {
-
- return (synctex_zs_s){size,SYNCTEX_STATUS_OK};
- }
- if (SYNCTEX_FILE) {
-
- int already_read = 0;
- scanner->reader->charindex_offset += SYNCTEX_CUR - SYNCTEX_START;
- if (size) {
- memmove(SYNCTEX_START, SYNCTEX_CUR, size);
- }
- SYNCTEX_CUR = SYNCTEX_START + size;
-
- already_read = gzread(SYNCTEX_FILE,(void *)SYNCTEX_CUR,(int)(SYNCTEX_BUFFER_SIZE - size));
- if (already_read>0) {
-
- SYNCTEX_END = SYNCTEX_CUR + already_read;
-
- * SYNCTEX_END = '\0';
- SYNCTEX_CUR = SYNCTEX_START;
-
- return (synctex_zs_s){SYNCTEX_END - SYNCTEX_CUR,SYNCTEX_STATUS_OK};
- } else if (0>already_read) {
-
- int errnum = 0;
- const char * error_string = gzerror(SYNCTEX_FILE, &errnum);
- if (Z_ERRNO == errnum) {
-
- _synctex_error("gzread error from the file system (%i)",errno);
- return (synctex_zs_s){0,SYNCTEX_STATUS_ERROR};
- } else if (errnum) {
- _synctex_error("gzread error (%i:%i,%s)",already_read,errnum,error_string);
- return (synctex_zs_s){0,SYNCTEX_STATUS_ERROR};
- }
- }
-
- gzclose(SYNCTEX_FILE);
- SYNCTEX_FILE = NULL;
- SYNCTEX_END = SYNCTEX_CUR;
- SYNCTEX_CUR = SYNCTEX_START;
- * SYNCTEX_END = '\0';
-
- return (synctex_zs_s){SYNCTEX_END - SYNCTEX_CUR,SYNCTEX_STATUS_EOF};
- }
-
- return (synctex_zs_s){size,SYNCTEX_STATUS_EOF};
- }
- static synctex_status_t _synctex_next_line(synctex_scanner_p scanner) {
- synctex_status_t status = SYNCTEX_STATUS_OK;
- if (NULL == scanner) {
- return SYNCTEX_STATUS_BAD_ARGUMENT;
- }
- infinite_loop:
- while(SYNCTEX_CUR<SYNCTEX_END) {
- if (*SYNCTEX_CUR == '\n') {
- ++SYNCTEX_CUR;
- ++scanner->reader->line_number;
- return _synctex_buffer_get_available_size(scanner, 1).status;
- }
- ++SYNCTEX_CUR;
- }
-
- status = _synctex_buffer_get_available_size(scanner, 1).status;
- if (status<=SYNCTEX_STATUS_EOF) {
- return status;
- }
- goto infinite_loop;
- }
- static synctex_status_t _synctex_match_string(synctex_scanner_p scanner, const char * the_string) {
- size_t tested_len = 0;
- size_t remaining_len = 0;
- size_t available = 0;
- synctex_zs_s zs = {0,0};
- if (NULL == scanner || NULL == the_string) {
- return SYNCTEX_STATUS_BAD_ARGUMENT;
- }
- remaining_len = strlen(the_string);
- if (0 == remaining_len) {
- return SYNCTEX_STATUS_BAD_ARGUMENT;
- }
-
- zs = _synctex_buffer_get_available_size(scanner,remaining_len);
- if (zs.status<SYNCTEX_STATUS_EOF) {
- return zs.status;
- }
-
- if (zs.size>=remaining_len) {
-
- if (strncmp((char *)SYNCTEX_CUR,the_string,remaining_len)) {
- return SYNCTEX_STATUS_NOT_OK;
- }
- return_OK:
-
- SYNCTEX_CUR += remaining_len;
- return SYNCTEX_STATUS_OK;
- } else if (strncmp((char *)SYNCTEX_CUR,the_string,zs.size)) {
-
- return SYNCTEX_STATUS_NOT_OK;
- } else if (SYNCTEX_FILE) {
-
- z_off_t offset = 0L;
-
- the_string += zs.size;
-
- remaining_len -= zs.size;
- tested_len += zs.size;
- SYNCTEX_CUR += zs.size;
- if (0 == remaining_len) {
-
- return SYNCTEX_STATUS_OK;
- }
-
- offset = gztell(SYNCTEX_FILE);
-
-
- offset -= SYNCTEX_CUR - SYNCTEX_START;
- more_characters:
-
- zs = _synctex_buffer_get_available_size(scanner,remaining_len);
- if (zs.status<SYNCTEX_STATUS_EOF) {
- return zs.status;
- }
- if (zs.size==0) {
-
- return_NOT_OK:
- if (offset != gzseek(SYNCTEX_FILE,offset,SEEK_SET)) {
-
- _synctex_error("Can't seek file");
- return SYNCTEX_STATUS_ERROR;
- }
-
- SYNCTEX_CUR = SYNCTEX_END;
- return SYNCTEX_STATUS_NOT_OK;
- }
- if (zs.size<remaining_len) {
-
- if (strncmp((char *)SYNCTEX_CUR,the_string,zs.size)) {
-
- goto return_NOT_OK;
- }
-
- the_string += available;
-
- remaining_len -= zs.size;
- tested_len += zs.size;
- SYNCTEX_CUR += zs.size;
- goto more_characters;
- }
-
- if (strncmp((char *)SYNCTEX_CUR,the_string,remaining_len)) {
-
- goto return_NOT_OK;
- }
- goto return_OK;
- } else {
-
- return SYNCTEX_STATUS_EOF;
- }
- }
- static synctex_is_s _synctex_decode_int(synctex_scanner_p scanner) {
- char * ptr = NULL;
- char * end = NULL;
- synctex_zs_s zs = {0,0};
- int result;
- if (NULL == scanner) {
- return (synctex_is_s){0, SYNCTEX_STATUS_BAD_ARGUMENT};
- }
- zs = _synctex_buffer_get_available_size(scanner, SYNCTEX_BUFFER_MIN_SIZE);
- if (zs.status<SYNCTEX_STATUS_EOF) {
- return (synctex_is_s){0,zs.status};
- }
- if (zs.size==0) {
- return (synctex_is_s){0,SYNCTEX_STATUS_NOT_OK};
- }
- ptr = SYNCTEX_CUR;
-
- if (*ptr==':' || *ptr==',') {
- ++ptr;
- --zs.size;
- if (zs.size==0) {
- return (synctex_is_s){0,SYNCTEX_STATUS_NOT_OK};
- }
- }
- result = (int)strtol(ptr, &end, 10);
- if (end>ptr) {
- SYNCTEX_CUR = end;
- return (synctex_is_s){result,SYNCTEX_STATUS_OK};
- }
- return (synctex_is_s){result,SYNCTEX_STATUS_NOT_OK};
- }
- static synctex_is_s _synctex_decode_int_opt(synctex_scanner_p scanner, int default_value) {
- char * ptr = NULL;
- char * end = NULL;
- synctex_zs_s zs = {0, 0};
- if (NULL == scanner) {
- return (synctex_is_s){default_value, SYNCTEX_STATUS_BAD_ARGUMENT};
- }
- zs = _synctex_buffer_get_available_size(scanner, SYNCTEX_BUFFER_MIN_SIZE);
- if (zs.status<SYNCTEX_STATUS_EOF) {
- return (synctex_is_s){default_value,zs.status};
- }
- if (zs.size==0) {
- return (synctex_is_s){default_value,SYNCTEX_STATUS_OK};
- }
- ptr = SYNCTEX_CUR;
-
- if (*ptr==',') {
- int result;
- ++ptr;
- --zs.size;
- if (zs.size==0) {
- return (synctex_is_s){default_value,SYNCTEX_STATUS_NOT_OK};
- }
- result = (int)strtol(ptr, &end, 10);
- if (end>ptr) {
- SYNCTEX_CUR = end;
- return (synctex_is_s){result,SYNCTEX_STATUS_OK};
- }
- return (synctex_is_s){default_value,SYNCTEX_STATUS_NOT_OK};
- }
- return (synctex_is_s){default_value,SYNCTEX_STATUS_OK};
- }
- static synctex_is_s _synctex_decode_int_v(synctex_scanner_p scanner) {
- synctex_is_s is = _synctex_decode_int(scanner);
- if (SYNCTEX_STATUS_OK == is.status) {
- scanner->reader->lastv = is.integer;
- return is;
- }
- is.status = _synctex_match_string(scanner,SYNCTEX_INPUT_COMEQUALS);
- if (is.status<SYNCTEX_STATUS_OK) {
- return is;
- }
- is.integer = scanner->reader->lastv;
- return is;
- }
- static synctex_ss_s _synctex_decode_string(synctex_scanner_p scanner) {
- char * end = NULL;
- size_t len = 0;
- size_t already_len = 0;
- synctex_zs_s zs = {0,0};
- char * string = NULL;
- if (NULL == scanner) {
- return (synctex_ss_s){NULL,SYNCTEX_STATUS_BAD_ARGUMENT};
- }
-
- if (SYNCTEX_CUR>=SYNCTEX_END) {
- more_characters:
- zs = _synctex_buffer_get_available_size(scanner,1);
- if (zs.status < SYNCTEX_STATUS_EOF) {
- return (synctex_ss_s){NULL,zs.status};
- } else if (0 == zs.size) {
- return (synctex_ss_s){NULL,SYNCTEX_STATUS_EOF};
- }
- }
-
-
- end = SYNCTEX_CUR;
-
- while (end<SYNCTEX_END && *end != '\n') {
- ++end;
- }
-
- len = end - SYNCTEX_CUR;
- if (len<UINT_MAX-already_len) {
- if ((string = realloc(string,len+already_len+1)) != NULL) {
- if (memcpy(string+already_len,SYNCTEX_CUR,len)) {
- already_len += len;
- string[already_len]='\0';
- SYNCTEX_CUR += len;
- if (SYNCTEX_CUR==SYNCTEX_END) {
-
- goto more_characters;
- }
-
- len = already_len;
- while (len>0) {
- already_len = len--;
- if (string[len]!=' ') {
- break;
- }
- }
- string[already_len] = '\0';
- return (synctex_ss_s){string,SYNCTEX_STATUS_OK};
- }
- free(string);
- _synctex_error("could not copy memory (1).");
- return (synctex_ss_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- }
- _synctex_error("could not (re)allocate memory (1).");
- return (synctex_ss_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- static synctex_ns_s __synctex_parse_new_input(synctex_scanner_p scanner) {
- synctex_node_p input = NULL;
- synctex_status_t status = SYNCTEX_STATUS_BAD_ARGUMENT;
- synctex_zs_s zs = {0,0};
- if (NULL == scanner) {
- return (synctex_ns_s){NULL,status};
- }
- if ((status=_synctex_match_string(scanner,SYNCTEX_INPUT_MARK))<SYNCTEX_STATUS_OK) {
- return (synctex_ns_s){NULL,status};
- }
-
- if (NULL == (input = _synctex_new_input(scanner))) {
- _synctex_error("Could not create an input node.");
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
-
- if ((status=_synctex_data_decode_tag(input))<SYNCTEX_STATUS_OK) {
- _synctex_error("Bad format of input node.");
- synctex_node_free(input);
- return (synctex_ns_s){NULL,status};
- }
-
- zs = _synctex_buffer_get_available_size(scanner, 1);
- if (zs.status<=SYNCTEX_STATUS_ERROR) {
- return (synctex_ns_s){NULL,status};
- }
- if (0 == zs.size) {
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_EOF};
- }
-
- ++SYNCTEX_CUR;
- --zs.size;
-
- if ((status=_synctex_data_decode_name(input))<SYNCTEX_STATUS_OK) {
- synctex_node_free(input);
- _synctex_next_line(scanner);
- return (synctex_ns_s){NULL,status};
- }
-
- __synctex_tree_set_sibling(input,scanner->input);
- scanner->input = input;
- synctex_node_log(input);
- return (synctex_ns_s){input,_synctex_next_line(scanner)};
- }
- typedef synctex_is_s (*synctex_decoder_t)(synctex_scanner_p);
- static synctex_status_t _synctex_scan_named(synctex_scanner_p scanner,const char * name) {
- synctex_status_t status = 0;
- if (NULL == scanner || NULL == name) {
- return SYNCTEX_STATUS_BAD_ARGUMENT;
- }
- not_found:
- status = _synctex_match_string(scanner,name);
- if (status<SYNCTEX_STATUS_NOT_OK) {
- return status;
- } else if (status == SYNCTEX_STATUS_NOT_OK) {
- status = _synctex_next_line(scanner);
- if (status<SYNCTEX_STATUS_OK) {
- return status;
- }
- goto not_found;
- }
- return SYNCTEX_STATUS_OK;
- }
- static synctex_status_t _synctex_scan_preamble(synctex_scanner_p scanner) {
- synctex_status_t status = 0;
- synctex_is_s is = {0,0};
- synctex_ss_s ss = {NULL,0};
- if (NULL == scanner) {
- return SYNCTEX_STATUS_BAD_ARGUMENT;
- }
- status = _synctex_scan_named(scanner,"SyncTeX Version:");
- if (status<SYNCTEX_STATUS_OK) {
- return status;
- }
- is = _synctex_decode_int(scanner);
- if (is.status<SYNCTEX_STATUS_OK) {
- return is.status;
- }
- status = _synctex_next_line(scanner);
- if (status<SYNCTEX_STATUS_OK) {
- return status;
- }
- scanner->version = is.integer;
-
- do {
- status = __synctex_parse_new_input(scanner).status;
- if (status<SYNCTEX_STATUS_NOT_OK) {
- return status;
- }
- } while(status == SYNCTEX_STATUS_OK);
-
-
- if ((status=_synctex_scan_named(scanner,"Output:"))<SYNCTEX_STATUS_OK) {
- return status;
- }
- if ((ss=_synctex_decode_string(scanner)).status<SYNCTEX_STATUS_OK) {
- return is.status;
- }
- if ((status=_synctex_next_line(scanner))<SYNCTEX_STATUS_OK) {
- return status;
- }
- scanner->output_fmt = ss.string;
- if ((status=_synctex_scan_named(scanner,"Magnification:"))<SYNCTEX_STATUS_OK) {
- return status;
- }
- if ((is=_synctex_decode_int(scanner)).status<SYNCTEX_STATUS_OK) {
- return is.status;
- }
- if ((status=_synctex_next_line(scanner))<SYNCTEX_STATUS_OK) {
- return status;
- }
- scanner->pre_magnification = is.integer;
- if ((status=_synctex_scan_named(scanner,"Unit:"))<SYNCTEX_STATUS_OK) {
- return status;
- }
- if ((is=_synctex_decode_int(scanner)).status<SYNCTEX_STATUS_OK) {
- return is.status;
- }
- if ((status=_synctex_next_line(scanner))<SYNCTEX_STATUS_OK) {
- return status;
- }
- scanner->pre_unit = is.integer;
- if ((status=_synctex_scan_named(scanner,"X Offset:"))<SYNCTEX_STATUS_OK) {
- return status;
- }
- if ((is=_synctex_decode_int(scanner)).status<SYNCTEX_STATUS_OK) {
- return is.status;
- }
- if ((status=_synctex_next_line(scanner))<SYNCTEX_STATUS_OK) {
- return status;
- }
- scanner->pre_x_offset = is.integer;
- if ((status=_synctex_scan_named(scanner,"Y Offset:"))<SYNCTEX_STATUS_OK) {
- return status;
- }
- if ((is=_synctex_decode_int(scanner)).status<SYNCTEX_STATUS_OK) {
- return is.status;
- }
- if ((status=_synctex_next_line(scanner))<SYNCTEX_STATUS_OK) {
- return status;
- }
- scanner->pre_y_offset = is.integer;
- return SYNCTEX_STATUS_OK;
- }
- static synctex_fs_s _synctex_scan_float_and_dimension(synctex_scanner_p scanner) {
- synctex_fs_s fs = {0,0};
- synctex_zs_s zs = {0,0};
- char * endptr = NULL;
- char * loc = setlocale(LC_NUMERIC, NULL);
- if (NULL == scanner) {
- return (synctex_fs_s){0,SYNCTEX_STATUS_BAD_ARGUMENT};
- }
- zs = _synctex_buffer_get_available_size(scanner, SYNCTEX_BUFFER_MIN_SIZE);
- if (zs.status<SYNCTEX_STATUS_EOF) {
- _synctex_error("Problem with float.");
- return (synctex_fs_s){0,zs.status};
- }
- setlocale(LC_NUMERIC, "C");
- fs.value = strtod(SYNCTEX_CUR,&endptr);
- setlocale(LC_NUMERIC, loc);
- if (endptr == SYNCTEX_CUR) {
- _synctex_error("A float was expected.");
- return (synctex_fs_s){0,SYNCTEX_STATUS_ERROR};
- }
- SYNCTEX_CUR = endptr;
- if ((fs.status = _synctex_match_string(scanner,"in")) >= SYNCTEX_STATUS_OK) {
- fs.value *= 72.27f*65536;
- } else if (fs.status<SYNCTEX_STATUS_EOF) {
- report_unit_error:
- _synctex_error("problem with unit.");
- return fs;
- } else if ((fs.status = _synctex_match_string(scanner,"cm")) >= SYNCTEX_STATUS_OK) {
- fs.value *= 72.27f*65536/2.54f;
- } else if (fs.status<SYNCTEX_STATUS_EOF) {
- goto report_unit_error;
- } else if ((fs.status = _synctex_match_string(scanner,"mm")) >= SYNCTEX_STATUS_OK) {
- fs.value *= 72.27f*65536/25.4f;
- } else if (fs.status<SYNCTEX_STATUS_EOF) {
- goto report_unit_error;
- } else if ((fs.status = _synctex_match_string(scanner,"pt")) >= SYNCTEX_STATUS_OK) {
- fs.value *= 65536.0f;
- } else if (fs.status<SYNCTEX_STATUS_EOF) {
- goto report_unit_error;
- } else if ((fs.status = _synctex_match_string(scanner,"bp")) >= SYNCTEX_STATUS_OK) {
- fs.value *= 72.27f/72*65536.0f;
- } else if (fs.status<SYNCTEX_STATUS_EOF) {
- goto report_unit_error;
- } else if ((fs.status = _synctex_match_string(scanner,"pc")) >= SYNCTEX_STATUS_OK) {
- fs.value *= 12.0*65536.0f;
- } else if (fs.status<SYNCTEX_STATUS_EOF) {
- goto report_unit_error;
- } else if ((fs.status = _synctex_match_string(scanner,"sp")) >= SYNCTEX_STATUS_OK) {
- fs.value *= 1.0f;
- } else if (fs.status<SYNCTEX_STATUS_EOF) {
- goto report_unit_error;
- } else if ((fs.status = _synctex_match_string(scanner,"dd")) >= SYNCTEX_STATUS_OK) {
- fs.value *= 1238.0f/1157*65536.0f;
- } else if (fs.status<SYNCTEX_STATUS_EOF) {
- goto report_unit_error;
- } else if ((fs.status = _synctex_match_string(scanner,"cc")) >= SYNCTEX_STATUS_OK) {
- fs.value *= 14856.0f/1157*65536;
- } else if (fs.status<SYNCTEX_STATUS_EOF) {
- goto report_unit_error;
- } else if ((fs.status = _synctex_match_string(scanner,"nd")) >= SYNCTEX_STATUS_OK) {
- fs.value *= 685.0f/642*65536;
- } else if (fs.status<SYNCTEX_STATUS_EOF) {
- goto report_unit_error;
- } else if ((fs.status = _synctex_match_string(scanner,"nc")) >= SYNCTEX_STATUS_OK) {
- fs.value *= 1370.0f/107*65536;
- } else if (fs.status<SYNCTEX_STATUS_EOF) {
- goto report_unit_error;
- }
- return fs;
- }
- static synctex_status_t _synctex_scan_post_scriptum(synctex_scanner_p scanner) {
- synctex_status_t status = 0;
- synctex_fs_s fs = {0,0};
- char * endptr = NULL;
- char * loc = setlocale(LC_NUMERIC, NULL);
- if (NULL == scanner) {
- return SYNCTEX_STATUS_BAD_ARGUMENT;
- }
-
- post_scriptum_not_found:
- status = _synctex_match_string(scanner,"Post scriptum:");
- if (status<SYNCTEX_STATUS_NOT_OK) {
- return status;
- }
- if (status == SYNCTEX_STATUS_NOT_OK) {
- status = _synctex_next_line(scanner);
- if (status<SYNCTEX_STATUS_EOF) {
- return status;
- } else if (status<SYNCTEX_STATUS_OK) {
- return SYNCTEX_STATUS_OK;
- }
- goto post_scriptum_not_found;
- }
-
- next_line:
- status = _synctex_next_line(scanner);
- if (status<SYNCTEX_STATUS_EOF) {
- return status;
- } else if (status<SYNCTEX_STATUS_OK) {
- return SYNCTEX_STATUS_OK;
- }
-
- status = _synctex_match_string(scanner,"Magnification:");
- if (status == SYNCTEX_STATUS_OK ) {
- setlocale(LC_NUMERIC, "C");
- scanner->unit = strtod(SYNCTEX_CUR,&endptr);
- setlocale(LC_NUMERIC, loc);
- if (endptr == SYNCTEX_CUR) {
- _synctex_error("bad magnification in the post scriptum, a float was expected.");
- return SYNCTEX_STATUS_ERROR;
- }
- if (scanner->unit<=0) {
- _synctex_error("bad magnification in the post scriptum, a positive float was expected.");
- return SYNCTEX_STATUS_ERROR;
- }
- SYNCTEX_CUR = endptr;
- goto next_line;
- }
- if (status<SYNCTEX_STATUS_EOF){
- report_record_problem:
- _synctex_error("Problem reading the Post Scriptum records");
- return status;
- }
- status = _synctex_match_string(scanner,"X Offset:");
- if (status == SYNCTEX_STATUS_OK) {
- fs = _synctex_scan_float_and_dimension(scanner);
- if (fs.status<SYNCTEX_STATUS_OK) {
- _synctex_error("Problem with X offset in the Post Scriptum.");
- return fs.status;
- }
- scanner->x_offset = fs.value;
- goto next_line;
- } else if (status<SYNCTEX_STATUS_EOF){
- goto report_record_problem;
- }
- status = _synctex_match_string(scanner,"Y Offset:");
- if (status==SYNCTEX_STATUS_OK) {
- fs = _synctex_scan_float_and_dimension(scanner);
- if (fs.status<SYNCTEX_STATUS_OK) {
- _synctex_error("Problem with Y offset in the Post Scriptum.");
- return fs.status;
- }
- scanner->x_offset = fs.value;
- goto next_line;
- } else if (status<SYNCTEX_STATUS_EOF){
- goto report_record_problem;
- }
- goto next_line;
- }
- static synctex_status_t _synctex_scan_postamble(synctex_scanner_p scanner) {
- synctex_status_t status = 0;
- synctex_is_s is = {0,0};
- if (NULL == scanner) {
- return SYNCTEX_STATUS_BAD_ARGUMENT;
- }
- if (!scanner->flags.postamble && (status=_synctex_match_string(scanner,"Postamble:"))<SYNCTEX_STATUS_OK) {
- return status;
- }
- count_again:
- if ((status=_synctex_next_line(scanner))<SYNCTEX_STATUS_OK) {
- return status;
- }
- if ((status=_synctex_scan_named(scanner,"Count:"))< SYNCTEX_STATUS_EOF) {
- return status;
- } else if (status < SYNCTEX_STATUS_OK) {
- goto count_again;
- }
- if ((is=_synctex_decode_int(scanner)).status<SYNCTEX_STATUS_OK) {
- return is.status;
- }
- if ((status=_synctex_next_line(scanner))<SYNCTEX_STATUS_OK) {
- return status;
- }
- scanner->count = is.integer;
-
- return _synctex_scan_post_scriptum(scanner);
- }
- static synctex_status_t _synctex_setup_visible_hbox(synctex_node_p box) {
- if (box) {
- switch(synctex_node_type(box)) {
- case synctex_node_type_hbox:
- _synctex_data_set_h_V(box,_synctex_data_h(box));
- _synctex_data_set_v_V(box,_synctex_data_v(box));
- _synctex_data_set_width_V(box,_synctex_data_width(box));
- _synctex_data_set_height_V(box,_synctex_data_height(box));
- _synctex_data_set_depth_V(box,_synctex_data_depth(box));
- return SYNCTEX_STATUS_OK;
- default:
- break;
- }
- }
- return SYNCTEX_STATUS_BAD_ARGUMENT;
- }
- static synctex_status_t _synctex_make_hbox_contain_point(synctex_node_p node,synctex_point_s point) {
- int min, max, n;
- if (NULL == node || synctex_node_type(node) != synctex_node_type_hbox) {
- return SYNCTEX_STATUS_BAD_ARGUMENT;
- }
- if ((n = _synctex_data_width_V(node))<0) {
- max = _synctex_data_h_V(node);
- min = max+n;
- if (point.h<min) {
- _synctex_data_set_width_V(node,point.h-max);
- } else if (point.h>max) {
- _synctex_data_set_h_V(node,point.h);
- _synctex_data_set_width_V(node,min-point.h);
- }
- } else {
- min = _synctex_data_h_V(node);
- max = min+n;
- if (point.h<min) {
- _synctex_data_set_h_V(node,point.h);
- _synctex_data_set_width_V(node,max - point.h);
- } else if (point.h>max) {
- _synctex_data_set_width_V(node,point.h - min);
- }
- }
- n = _synctex_data_v_V(node);
- min = n - _synctex_data_height_V(node);
- max = n + _synctex_data_depth_V(node);
- if (point.v<min) {
- _synctex_data_set_height_V(node,n-point.v);
- } else if (point.v>max) {
- _synctex_data_set_depth_V(node,point.v-n);
- }
- return SYNCTEX_STATUS_OK;
- }
- static synctex_status_t _synctex_make_hbox_contain_box(synctex_node_p node,synctex_box_s box) {
- int min, max, n;
- if (NULL == node || synctex_node_type(node) != synctex_node_type_hbox) {
- return SYNCTEX_STATUS_BAD_ARGUMENT;
- }
- if ((n = _synctex_data_width_V(node))<0) {
- max = _synctex_data_h_V(node);
- min = max+n;
- if (box.min.h <min) {
- _synctex_data_set_width_V(node,box.min.h-max);
- } else if (box.max.h>max) {
- _synctex_data_set_h_V(node,box.max.h);
- _synctex_data_set_width_V(node,min-box.max.h);
- }
- } else {
- min = _synctex_data_h_V(node);
- max = min+n;
- if (box.min.h<min) {
- _synctex_data_set_h_V(node,box.min.h);
- _synctex_data_set_width_V(node,max - box.min.h);
- } else if (box.max.h>max) {
- _synctex_data_set_width_V(node,box.max.h - min);
- }
- }
- n = _synctex_data_v_V(node);
- min = n - _synctex_data_height_V(node);
- max = n + _synctex_data_depth_V(node);
- if (box.min.v<min) {
- _synctex_data_set_height_V(node,n-box.min.v);
- } else if (box.max.v>max) {
- _synctex_data_set_depth_V(node,box.max.v-n);
- }
- return SYNCTEX_STATUS_OK;
- }
- (_synctex_data_decode_
- (_synctex_data_decode_
- static synctex_ns_s _synctex_parse_new_sheet(synctex_scanner_p scanner) {
- synctex_node_p node;
- if ((node = _synctex_new_sheet(scanner))) {
- if (
- SYNCTEX_DECODE_FAILED(node,page)) {
- _synctex_error("Bad sheet record.");
- } else if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing end of sheet.");
- } else {
-
- if (scanner->sheet) {
- synctex_node_p last_sheet = scanner->sheet;
- synctex_node_p next_sheet = NULL;
- while ((next_sheet = __synctex_tree_sibling(last_sheet))) {
- last_sheet = next_sheet;
- }
-
- __synctex_tree_set_sibling(last_sheet,node);
- } else {
- scanner->sheet = node;
- }
- return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
- }
- _synctex_free_node(node);
- }
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- static synctex_ns_s _synctex_parse_new_form(synctex_scanner_p scanner) {
- synctex_node_p node;
- if ((node = _synctex_new_form(scanner))) {
- if (
- SYNCTEX_DECODE_FAILED(node,tag)) {
- _synctex_error("Bad sheet record.");
- } else if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing end of form.");
- } else {
-
- if (scanner->form) {
- synctex_node_p last_form = scanner->form;
- synctex_node_p next_form = NULL;
- while ((next_form = __synctex_tree_sibling(last_form))) {
- last_form = next_form;
- }
- __synctex_tree_set_sibling(last_form,node);
- } else {
- scanner->form = node;
- }
- return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
- }
- _synctex_free_node(node);
- }
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- (_synctex_data_has_
- (_synctex_data_has_
- static synctex_status_t _synctex_data_decode_tlchvwhd(synctex_node_p node) {
- return SYNCTEX_SHOULD_DECODE_FAILED(node,tag)
- || SYNCTEX_SHOULD_DECODE_FAILED(node,line)
- || SYNCTEX_SHOULD_DECODE_FAILED(node,column)
- || SYNCTEX_SHOULD_DECODE_FAILED(node,h)
- || SYNCTEX_SHOULD_DECODE_FAILED_V(node,v)
- || SYNCTEX_SHOULD_DECODE_FAILED(node,width)
- || SYNCTEX_SHOULD_DECODE_FAILED(node,height)
- || SYNCTEX_SHOULD_DECODE_FAILED(node,depth);
- }
- static synctex_ns_s _synctex_parse_new_vbox(synctex_scanner_p scanner) {
- synctex_node_p node;
- if ((node = _synctex_new_vbox(scanner))) {
- if (_synctex_data_decode_tlchvwhd(node)) {
- _synctex_error("Bad vbox record.");
- _synctex_next_line(scanner);
- out:
- _synctex_free_node(node);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing end of vbox.");
- goto out;
- }
- return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
- }
- _synctex_next_line(scanner);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- SYNCTEX_INLINE static synctex_node_p __synctex_node_make_friend_tlc(synctex_node_p node);
- static synctex_ns_s _synctex_parse_new_hbox(synctex_scanner_p scanner) {
- synctex_node_p node;
- if ((node = _synctex_new_hbox(scanner))) {
- if (_synctex_data_decode_tlchvwhd(node)) {
- _synctex_error("Bad hbox record.");
- _synctex_next_line(scanner);
- out:
- _synctex_free_node(node);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing end of hbox.");
- goto out;
- }
- if (_synctex_setup_visible_hbox(node)<SYNCTEX_STATUS_OK) {
- _synctex_error("Unexpected error (_synctex_parse_new_hbox).");
- goto out;
- }
- return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
- }
- _synctex_next_line(scanner);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- static synctex_ns_s _synctex_parse_new_void_vbox(synctex_scanner_p scanner) {
- synctex_node_p node;
- if ((node = _synctex_new_void_vbox(scanner))) {
- if (_synctex_data_decode_tlchvwhd(node)) {
- _synctex_error("Bad void vbox record.");
- _synctex_next_line(scanner);
- out:
- _synctex_free_node(node);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing end of container.");
- goto out;
- }
- return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
- }
- _synctex_next_line(scanner);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- static synctex_ns_s _synctex_parse_new_void_hbox(synctex_scanner_p scanner) {
- synctex_node_p node;
- if ((node = _synctex_new_void_hbox(scanner))) {
- if (_synctex_data_decode_tlchvwhd(node)) {
- _synctex_error("Bad void hbox record.");
- _synctex_next_line(scanner);
- out:
- _synctex_free_node(node);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing end of container.");
- goto out;
- }
- return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
- }
- _synctex_next_line(scanner);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- static synctex_ns_s _synctex_parse_new_kern(synctex_scanner_p scanner) {
- synctex_node_p node;
- if ((node = _synctex_new_kern(scanner))) {
- if (_synctex_data_decode_tlchvwhd(node)) {
- _synctex_error("Bad kern record.");
- _synctex_next_line(scanner);
- out:
- _synctex_free_node(node);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing end of container.");
- goto out;
- }
- return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
- }
- _synctex_next_line(scanner);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- static synctex_ns_s _synctex_parse_new_glue(synctex_scanner_p scanner) {
- synctex_node_p node;
- if ((node = _synctex_new_glue(scanner))) {
- if (_synctex_data_decode_tlchvwhd(node)) {
- _synctex_error("Bad glue record.");
- _synctex_next_line(scanner);
- out:
- _synctex_free_node(node);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing end of container.");
- goto out;
- }
- return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
- }
- _synctex_next_line(scanner);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- static synctex_ns_s _synctex_parse_new_rule(synctex_scanner_p scanner) {
- synctex_node_p node;
- if ((node = _synctex_new_rule(scanner))) {
- if (_synctex_data_decode_tlchvwhd(node)) {
- _synctex_error("Bad rule record.");
- _synctex_next_line(scanner);
- out:
- _synctex_free_node(node);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing end of container.");
- goto out;
- }
- return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
- }
- _synctex_next_line(scanner);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- static synctex_ns_s _synctex_parse_new_math(synctex_scanner_p scanner) {
- synctex_node_p node;
- if ((node = _synctex_new_math(scanner))) {
- if (_synctex_data_decode_tlchvwhd(node)) {
- _synctex_error("Bad math record.");
- _synctex_next_line(scanner);
- out:
- _synctex_free_node(node);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing end of container.");
- goto out;
- }
- return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
- }
- _synctex_next_line(scanner);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- static synctex_ns_s _synctex_parse_new_boundary(synctex_scanner_p scanner) {
- synctex_node_p node;
- if ((node = _synctex_new_boundary(scanner))) {
- if (_synctex_data_decode_tlchvwhd(node)) {
- _synctex_error("Bad boundary record.");
- _synctex_next_line(scanner);
- out:
- _synctex_free_node(node);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing end of container.");
- goto out;
- }
- return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
- }
- _synctex_next_line(scanner);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- SYNCTEX_INLINE static synctex_ns_s _synctex_parse_new_ref(synctex_scanner_p scanner) {
- synctex_node_p node;
- if ((node = _synctex_new_ref(scanner))) {
- if (SYNCTEX_DECODE_FAILED(node,tag)
- || SYNCTEX_DECODE_FAILED(node,h)
- || SYNCTEX_DECODE_FAILED_V(node,v)) {
- _synctex_error("Bad form ref record.");
- _synctex_next_line(scanner);
- out:
- _synctex_free_node(node);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing end of container.");
- goto out;
- }
- return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
- }
- _synctex_next_line(scanner);
- return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
- }
- SYNCTEX_INLINE static synctex_point_s _synctex_data_point(synctex_node_p node);
- SYNCTEX_INLINE static synctex_point_s _synctex_data_point_V(synctex_node_p node);
- SYNCTEX_INLINE static synctex_point_s _synctex_data_set_point(synctex_node_p node, synctex_point_s point);
- SYNCTEX_INLINE static synctex_box_s _synctex_data_box(synctex_node_p node);
- SYNCTEX_INLINE static synctex_box_s _synctex_data_xob(synctex_node_p node);
- SYNCTEX_INLINE static synctex_box_s _synctex_data_box_V(synctex_node_p node);
- SYNCTEX_INLINE static synctex_node_p _synctex_input_register_line(synctex_node_p input,synctex_node_p node) {
- if (node && _synctex_data_tag(input) != _synctex_data_tag(node)) {
- input = synctex_scanner_input_with_tag(node->class_->scanner,_synctex_data_tag(node));
- }
- if (_synctex_data_line(node)>_synctex_data_line(input)) {
- _synctex_data_set_line(input,_synctex_data_line(node));
- }
- return input;
- }
- SYNCTEX_INLINE static synctex_node_p _synctex_handle_pop_child(synctex_node_p handle) {
- synctex_node_p child = _synctex_tree_reset_child(handle);
- synctex_node_free(handle);
- return child;
- }
- SYNCTEX_INLINE static void _synctex_handle_set_tlc(synctex_node_p x_handle, synctex_node_p child, synctex_bool_t make_friend) {
- if (x_handle) {
- synctex_node_p sibling = x_handle;
- if (child) {
- synctex_node_p target;
- while ((target = synctex_node_target(sibling))) {
- _synctex_data_set_tlc(target,child);
- if (make_friend) {
- _synctex_node_make_friend_tlc(target);
- }
- if ((sibling = __synctex_tree_sibling(sibling))) {
- continue;
- } else {
- break;
- }
- }
- }
- _synctex_tree_reset_target(x_handle);
- sibling = __synctex_tree_reset_sibling(x_handle);
- synctex_node_free(sibling);
- }
- }
- SYNCTEX_INLINE static void _synctex_handle_make_friend_tlc(synctex_node_p node) {
- while (node) {
- synctex_node_p target = _synctex_tree_reset_target(node);
- _synctex_node_make_friend_tlc(target);
- node = __synctex_tree_sibling(node);
- }
- }
- static synctex_status_t __synctex_parse_sfi(synctex_scanner_p scanner) {
- synctex_status_t status = SYNCTEX_STATUS_OK;
- synctex_zs_s zs = {0,0};
- synctex_ns_s input = SYNCTEX_NS_NULL;
- synctex_node_p sheet = NULL;
- synctex_node_p form = NULL;
- synctex_node_p parent = NULL;
- synctex_node_p child = NULL;
-
- synctex_node_p x_handle = NULL;
- synctex_node_free(x_handle);\
- return STATUS
- synctex_node_p last_k = NULL;
- synctex_node_p last_g = NULL;
- synctex_ns_s ns = SYNCTEX_NS_NULL;
- int form_depth = 0;
- int ignored_form_depth = 0;
- synctex_bool_t try_input = synctex_YES;
- if (!(x_handle = _synctex_new_handle(scanner))) {
- SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
- }
- main_loop:
- status = SYNCTEX_STATUS_OK;
- sheet = form = parent = child = NULL;
- (*SYNCTEX_CUR == SYNCTEX_CHAR_
- if (SYNCTEX_CUR<SYNCTEX_END) {
- if (SYNCTEX_START_SCAN(BEGIN_FORM)) {
- scan_form:
- ns = _synctex_parse_new_form(scanner);
- if (ns.status == SYNCTEX_STATUS_OK) {
- ++form_depth;
- if (_synctex_tree_parent(form)) {
-
- ++ignored_form_depth;
- goto ignore_loop;
- }
- _synctex_tree_set_parent(ns.node,form);
- form = ns.node;
- parent = form;
- child = NULL;
- last_k = last_g = NULL;
- goto content_loop;
- }
- if (form || sheet) {
- last_k = last_g = NULL;
- goto content_loop;
- }
- try_input = synctex_YES;
- goto main_loop;
- } else if (SYNCTEX_START_SCAN(BEGIN_SHEET)) {
- try_input = synctex_YES;
- ns = _synctex_parse_new_sheet(scanner);
- if (ns.status == SYNCTEX_STATUS_OK) {
- sheet = ns.node;
- parent = sheet;
- last_k = last_g = NULL;
- goto content_loop;
- }
- goto main_loop;
- } else if (SYNCTEX_START_SCAN(ANCHOR)) {
- scan_anchor:
- ++SYNCTEX_CUR;
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing anchor.");
- SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
- }
- if (form || sheet) {
- last_k = last_g = NULL;
- goto content_loop;
- }
- try_input = synctex_YES;
- goto main_loop;
- } else if (SYNCTEX_START_SCAN(ANCHOR)) {
- ++SYNCTEX_CUR;
- _synctex_next_line(scanner);
- try_input = synctex_YES;
- goto main_loop;
- } else if (try_input) {
- try_input = synctex_NO;
- do {
- input = __synctex_parse_new_input(scanner);
- } while (input.status == SYNCTEX_STATUS_OK);
- goto main_loop;
- }
- status = _synctex_match_string(scanner,"Postamble:");
- if (status==SYNCTEX_STATUS_OK) {
- scanner->flags.postamble = 1;
- SYNCTEX_RETURN(status);
- }
- status = _synctex_next_line(scanner);
- if (status<SYNCTEX_STATUS_OK) {
- SYNCTEX_RETURN(status);
- }
- }
-
- zs = _synctex_buffer_get_available_size(scanner,1);
- if (zs.size == 0){
- _synctex_error("Uncomplete synctex file, postamble missing.");
- SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
- }
- goto main_loop;
-
- ignore_loop:
- ns = SYNCTEX_NS_NULL;
- if (SYNCTEX_CUR<SYNCTEX_END) {
- if (SYNCTEX_START_SCAN(BEGIN_FORM)) {
- ++ignored_form_depth;
- } else if (SYNCTEX_START_SCAN(END_FORM)) {
- --ignored_form_depth;
- }
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Uncomplete container.");
- SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
- }
- } else {
- zs = _synctex_buffer_get_available_size(scanner,1);
- if (zs.size == 0){
- _synctex_error("Uncomplete synctex file, postamble missing.");
- SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
- }
- }
- if (ignored_form_depth) {
- goto ignore_loop;
- } else {
- last_k = last_g = NULL;
- goto content_loop;
- }
- content_loop:
-
-
- ns = SYNCTEX_NS_NULL;
- synctex_scanner_set_display_switcher(scanner,-1);
- printf("NEW CONTENT LOOP\n");
- synctex_node_display(sheet);
- if (SYNCTEX_CUR<SYNCTEX_END) {
- if (SYNCTEX_START_SCAN(BEGIN_FORM)) {
- goto scan_form;
- } else if (SYNCTEX_START_SCAN(BEGIN_VBOX)) {
- ns = _synctex_parse_new_vbox(scanner);
- if (ns.status == SYNCTEX_STATUS_OK) {
- x_handle = _synctex_new_handle_with_child(x_handle);
- if (child) {
- _synctex_node_set_sibling(child,ns.node);
- } else {
- _synctex_node_set_child(parent,ns.node);
- }
- parent = ns.node;
- child = _synctex_tree_last(parent);
- synctex_node_log(parent);
- input.node = _synctex_input_register_line(input.node,parent);
- last_k = last_g = NULL;
- goto content_loop;
- }
- } else if (SYNCTEX_START_SCAN(END_VBOX)) {
- if (synctex_node_type(parent) == synctex_node_type_vbox) {
- ++SYNCTEX_CUR;
- if (NULL == _synctex_tree_child(parent) && !form) {
-
- _synctex_node_make_friend_tlc(parent);
- }
- child = parent;
- parent = _synctex_tree_parent(child);
- if (!form) {
- _synctex_handle_make_friend_tlc(x_handle);
- }
- x_handle = _synctex_handle_pop_child(x_handle);
- _synctex_handle_set_tlc(x_handle,child,!form);
- synctex_node_log(child);
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Uncomplete container.");
- SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
- }
- last_k = last_g = NULL;
- goto content_loop;
- }
- } else if (SYNCTEX_START_SCAN(BEGIN_HBOX)) {
- synctex_charindex_t char_index = (synctex_charindex_t)(scanner->reader->charindex_offset+SYNCTEX_CUR-SYNCTEX_START);
- synctex_lineindex_t line_index = scanner->reader->line_number;
- ns = _synctex_parse_new_hbox(scanner);
- if (ns.status == SYNCTEX_STATUS_OK) {
- x_handle = _synctex_new_handle_with_child(x_handle);
- if (child) {
- _synctex_node_set_sibling(child,ns.node);
- } else {
- _synctex_node_set_child(parent,ns.node);
- }
- parent = ns.node;
-
- if ((child = _synctex_new_box_bdry(scanner))) {
- child->line_index=line_index;
- child->char_index=char_index;
- _synctex_node_set_child(parent,child);
- _synctex_data_set_tlchv(child,parent);
- if (!form) {
- __synctex_node_make_friend_tlc(child);
- }
- } else {
- _synctex_error("Can't create box bdry record.");
- }
- synctex_node_log(parent);
- input.node = _synctex_input_register_line(input.node,parent);
- last_k = last_g = NULL;
- goto content_loop;
- }
- } else if (SYNCTEX_START_SCAN(END_HBOX)) {
- if (synctex_node_type(parent) == synctex_node_type_hbox) {
- ++SYNCTEX_CUR;
-
- if (form == NULL ) {
- _synctex_tree_set_next_hbox(parent,_synctex_tree_next_hbox(sheet));
- _synctex_tree_set_next_hbox(sheet,parent);
- }
- {
-
- synctex_node_p node = _synctex_tree_child(parent);
- synctex_node_p sibling = NULL;
-
- if (node && (sibling = __synctex_tree_sibling(node))) {
- unsigned int node_weight = 0;
- unsigned int cumulated_line_numbers = 0;
- _synctex_data_set_line(node, _synctex_data_line(sibling));
- node = sibling;
- do {
- if (synctex_node_type(node)==synctex_node_type_hbox) {
- if (_synctex_data_weight(node)) {
- node_weight += _synctex_data_weight(node);
- cumulated_line_numbers += _synctex_data_mean_line(node)*_synctex_data_weight(node);
- } else {
- ++node_weight;
- cumulated_line_numbers += _synctex_data_mean_line(node);
- }
- } else {
- ++node_weight;
- cumulated_line_numbers += synctex_node_line(node);
- }
- } while ((node = __synctex_tree_sibling(node)));
- _synctex_data_set_mean_line(parent,(cumulated_line_numbers + node_weight/2)/node_weight);
- _synctex_data_set_weight(parent,node_weight);
- } else {
- _synctex_data_set_mean_line(parent,_synctex_data_line(parent));
- _synctex_data_set_weight(parent,1);
- }
- if ((sibling = _synctex_new_box_bdry(scanner))) {
- sibling->line_index=child->line_index;
- sibling->char_index=child->char_index;
- _synctex_node_set_sibling(child,sibling);
- {
- synctex_node_p N = child;
- while (synctex_node_type(N) == synctex_node_type_ref) {
- N = _synctex_tree_arg_sibling(N);
- }
- _synctex_data_set_tlc(sibling,N);
- }
- _synctex_data_set_h(sibling,_synctex_data_h_V(parent)+_synctex_data_width_V(parent));
- _synctex_data_set_v(sibling,_synctex_data_v_V(parent));
- child = sibling;
- } else {
- _synctex_error("Can't create box bdry record.");
- }
- sibling = _synctex_tree_child(parent);
- _synctex_data_set_point(sibling,_synctex_data_point_V(parent));
- if (last_k && last_g && (child = synctex_node_child(parent))) {
-
- synctex_node_p next;
- while ((next = __synctex_tree_sibling(child))) {
- if (next == last_k) {
- _synctex_data_set_tlc(last_k,child);
- _synctex_data_set_tlc(last_g,child);
- break;
- }
- child = next;
- }
- }
- child = parent;
- parent = _synctex_tree_parent(child);
- if (!form) {
- _synctex_handle_make_friend_tlc(x_handle);
- }
- x_handle = _synctex_handle_pop_child(x_handle);
- _synctex_handle_set_tlc(x_handle,child,!form);
- _synctex_make_hbox_contain_box(parent, _synctex_data_box_V(child));
- synctex_node_log(child);
- }
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Uncomplete container.");
- SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
- }
- last_k = last_g = NULL;
- goto content_loop;
- }
- } else if (SYNCTEX_START_SCAN(VOID_VBOX)) {
- ns = _synctex_parse_new_void_vbox(scanner);
- if (ns.status == SYNCTEX_STATUS_OK) {
- if (child) {
- _synctex_node_set_sibling(child,ns.node);
- } else {
- _synctex_node_set_child(parent,ns.node);
- }
- child = ns.node;
- _synctex_handle_set_tlc(x_handle, child,!form);
- synctex_node_log(child);
- input.node = _synctex_input_register_line(input.node,child);
- last_k = last_g = NULL;
- goto content_loop;
- }
- } else if (SYNCTEX_START_SCAN(VOID_HBOX)) {
- ns = _synctex_parse_new_void_hbox(scanner);
- if (ns.status == SYNCTEX_STATUS_OK) {
- if (_synctex_data_width(ns.node)<0) {
- printf("Negative width\n");
- }
- if (child) {
- _synctex_node_set_sibling(child,ns.node);
- } else {
- _synctex_node_set_child(parent,ns.node);
- }
- child = ns.node;
- _synctex_handle_set_tlc(x_handle, child,!form);
- _synctex_make_hbox_contain_box(parent,_synctex_data_box(child));
- synctex_node_log(child);
- input.node = _synctex_input_register_line(input.node,child);
- last_k = last_g = NULL;
- goto content_loop;
- }
- } else if (SYNCTEX_START_SCAN(KERN)) {
- ns = _synctex_parse_new_kern(scanner);
-
- if (ns.status == SYNCTEX_STATUS_OK) {
- if (child) {
- _synctex_node_set_sibling(child,ns.node);
- } else {
- _synctex_node_set_child(parent,ns.node);
- }
- child = ns.node;
- if (!form) {
- __synctex_node_make_friend_tlc(child);
- }
- _synctex_handle_set_tlc(x_handle, child,!form);
- _synctex_make_hbox_contain_box(parent,_synctex_data_xob(child));
- synctex_node_log(child);
- input.node = _synctex_input_register_line(input.node,child);
- last_k = child;
- last_g = NULL;
- goto content_loop;
- }
- } else if (SYNCTEX_START_SCAN(GLUE)) {
- ns = _synctex_parse_new_glue(scanner);
- if (ns.status == SYNCTEX_STATUS_OK) {
- if (child) {
- _synctex_node_set_sibling(child,ns.node);
- } else {
- _synctex_node_set_child(parent,ns.node);
- }
- child = ns.node;
- if (!form) {
- __synctex_node_make_friend_tlc(child);
- }
- _synctex_handle_set_tlc(x_handle, child,!form);
- _synctex_make_hbox_contain_point(parent,_synctex_data_point(child));
- synctex_node_log(child);
- input.node = _synctex_input_register_line(input.node,child);
- if (last_k) {
- last_g = child;
- } else {
- last_k = last_g = NULL;
- }
- goto content_loop;
- }
- } else if (SYNCTEX_START_SCAN(RULE)) {
- ns = _synctex_parse_new_rule(scanner);
- if (ns.status == SYNCTEX_STATUS_OK) {
- if (child) {
- _synctex_node_set_sibling(child,ns.node);
- } else {
- _synctex_node_set_child(parent,ns.node);
- }
- child = ns.node;
- if (!form) {
- __synctex_node_make_friend_tlc(child);
- }
- _synctex_handle_set_tlc(x_handle, child,!form);
-
- synctex_node_log(child);
- input.node = _synctex_input_register_line(input.node,child);
- last_k = last_g = NULL;
- goto content_loop;
- }
- } else if (SYNCTEX_START_SCAN(MATH)) {
- ns = _synctex_parse_new_math(scanner);
- if (ns.status == SYNCTEX_STATUS_OK) {
- if (child) {
- _synctex_node_set_sibling(child,ns.node);
- } else {
- _synctex_node_set_child(parent,ns.node);
- }
- child = ns.node;
- if (!form) {
- __synctex_node_make_friend_tlc(child);
- }
- _synctex_handle_set_tlc(x_handle, child,!form);
- _synctex_make_hbox_contain_point(parent,_synctex_data_point(child));
- synctex_node_log(child);
- input.node = _synctex_input_register_line(input.node,child);
- last_k = last_g = NULL;
- goto content_loop;
- }
- } else if (SYNCTEX_START_SCAN(FORM_REF)) {
- synctex_node_display(parent);
- synctex_node_display(child);
- ns = _synctex_parse_new_ref(scanner);
- if (ns.status == SYNCTEX_STATUS_OK) {
- if (child) {
- _synctex_node_set_sibling(child,ns.node);
- } else {
- _synctex_node_set_child(parent,ns.node);
- }
- child = ns.node;
- if (form) {
- if (scanner->ref_in_form) {
- synctex_tree_set_friend(child,scanner->ref_in_form);
- }
- scanner->ref_in_form = child;
- } else {
- if (scanner->ref_in_sheet) {
- synctex_tree_set_friend(child,scanner->ref_in_sheet);
- }
- scanner->ref_in_sheet = child;
- }
- synctex_node_log(child);
- last_k = last_g = NULL;
- goto content_loop;
- }
- } else if (SYNCTEX_START_SCAN(BOUNDARY)) {
- ns = _synctex_parse_new_boundary(scanner);
- if (ns.status == SYNCTEX_STATUS_OK) {
- if (child) {
- _synctex_node_set_sibling(child,ns.node);
- } else {
- _synctex_node_set_child(parent,ns.node);
- }
- if (synctex_node_type(child)==synctex_node_type_box_bdry
- || _synctex_tree_target(x_handle)) {
- child = _synctex_tree_reset_child(x_handle);
- child = _synctex_new_handle_with_child(child);
- __synctex_tree_set_sibling(child, x_handle);
- x_handle = child;
- _synctex_tree_set_target(x_handle,ns.node);
- } else if (!form) {
- __synctex_node_make_friend_tlc(ns.node);
- }
- child = ns.node;
- _synctex_make_hbox_contain_point(parent,_synctex_data_point(child));
- synctex_node_log(child);
- input.node = _synctex_input_register_line(input.node,child);
- last_k = last_g = NULL;
- goto content_loop;
- }
- } else if (SYNCTEX_START_SCAN(CHARACTER)) {
- ++SYNCTEX_CUR;
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing end of container.");
- SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
- }
- last_k = last_g = NULL;
- goto content_loop;
- } else if (SYNCTEX_START_SCAN(ANCHOR)) {
- goto scan_anchor;
- } else if (SYNCTEX_START_SCAN(END_SHEET)) {
- if (sheet && parent == sheet) {
- ++SYNCTEX_CUR;
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing anchor.");
- }
- parent = sheet = NULL;
- goto main_loop;
- }
- } else if (SYNCTEX_START_SCAN(END_FORM)) {
- if (parent == form && form_depth > 0) {
- ++SYNCTEX_CUR;
- --form_depth;
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK
- && (form_depth || sheet)) {
- _synctex_error("Missing end of container.");
- SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
- }
- if ((parent = _synctex_tree_parent(form))) {
- _synctex_tree_reset_parent(form);
- child = form;
- form = parent;
- goto content_loop;
- } else if (sheet) {
- form = NULL;
- parent = sheet;
- child = synctex_node_last_sibling(child);
- goto content_loop;
- }
- goto main_loop;
- }
- }
- _synctex_error("Ignored record <%.20s...>(line %i)\n",SYNCTEX_CUR, scanner->reader->line_number+1);
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Missing end of sheet/form.");
- SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
- }
- last_k = last_g = NULL;
- goto content_loop;
- }
- zs = _synctex_buffer_get_available_size(scanner,1);
- if (zs.size == 0){
- _synctex_error("Uncomplete synctex file, postamble missing.");
- SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
- }
- last_k = last_g = NULL;
- goto content_loop;
- }
- SYNCTEX_INLINE static synctex_ns_s __synctex_replace_ref(synctex_node_p ref) {
- synctex_ns_s ns = {NULL,SYNCTEX_STATUS_OK};
- synctex_node_p parent;
- if ((parent = _synctex_tree_parent(ref))) {
- synctex_node_p sibling = __synctex_tree_reset_sibling(ref);
- synctex_node_p arg_sibling = synctex_node_arg_sibling(ref);
-
- synctex_node_p target = synctex_form_content(ref->class_->scanner, _synctex_data_tag(ref));
-
- if ((ns.node = __synctex_new_proxy_from_ref_to(ref, target))) {
-
- _synctex_node_set_sibling(arg_sibling,ns.node);
-
- _synctex_node_set_sibling(ns.node,sibling);
- if (synctex_node_type(sibling) == synctex_node_type_box_bdry) {
-
- sibling->char_index = arg_sibling->char_index;
- sibling->line_index = arg_sibling->line_index;
- }
- printf("! Ref replacement:\n");
- synctex_node_log(ref);
- synctex_node_display(synctex_node_sibling(ref));
- } else {
- _synctex_tree_set_sibling(arg_sibling,sibling);
- }
- __synctex_tree_reset_parent(ref);
- } else {
- _synctex_error("! Missing parent in __synctex_replace_ref. "
- "Please report.");
- ns.status = SYNCTEX_STATUS_BAD_ARGUMENT;
- }
- return ns;
- }
- SYNCTEX_INLINE static synctex_ns_s _synctex_post_process_ref(synctex_node_p ref) {
- synctex_ns_s ns = {NULL, SYNCTEX_STATUS_OK};
- while (ref) {
- synctex_node_p next_ref = _synctex_tree_reset_friend(ref);
- synctex_ns_s sub_ns = __synctex_replace_ref(ref);
- if (sub_ns.status < ns.status) {
- ns.status = sub_ns.status;
- } else {
-
- synctex_tree_set_friend(sub_ns.node,ns.node);
- ns.node = sub_ns.node;
- }
- synctex_node_free(ref);
- ref = next_ref;
- }
- return ns;
- }
- typedef synctex_node_p (* synctex_processor_f)(synctex_node_p node);
- SYNCTEX_INLINE static synctex_status_t _synctex_post_process_proxy(synctex_node_p proxy, synctex_processor_f f) {
- while(proxy) {
- synctex_node_p next_proxy = _synctex_tree_friend(proxy);
- synctex_node_p halt = __synctex_tree_sibling(proxy);
-
- if (!halt) {
- synctex_node_p parent = _synctex_tree_parent(proxy);
- halt = __synctex_tree_sibling(parent);
- while (!halt && parent) {
- parent = _synctex_tree_parent(parent);
- halt = __synctex_tree_sibling(parent);
- }
- }
- do {
- printf("POST PROCESSING %s\n",_synctex_node_abstract(proxy));
- {
- int i,j = 0;
- for (i=0;i<proxy->class_->scanner->number_of_lists;++i) {
- synctex_node_p N = proxy->class_->scanner->lists_of_friends[i];
- do {
- if (N==proxy) {
- ++j;
- printf("%s",_synctex_node_abstract(N));
- }
- } while ((N = _synctex_tree_friend(N)));
- }
- if (j) {
- printf("\nBeforehand %i match\n",j);
- }
- }
- f(proxy);
- {
- int i,j = 0;
- for (i=0;i<proxy->class_->scanner->number_of_lists;++i) {
- synctex_node_p N = proxy->class_->scanner->lists_of_friends[i];
- do {
- if (N==proxy) {
- ++j;
- printf("%s",_synctex_node_abstract(N));
- }
- } while ((N = _synctex_tree_friend(N)));
- }
- if (j) {
- printf("\n%i match\n",j);
- }
- }
-
- proxy = synctex_node_next(proxy);
- if (proxy) {
- int i,j = 0;
- for (i=0;i<proxy->class_->scanner->number_of_lists;++i) {
- synctex_node_p N = proxy->class_->scanner->lists_of_friends[i];
- do {
- if (N==proxy) {
- ++j;
- printf("%s",_synctex_node_abstract(N));
- }
- } while ((N = _synctex_tree_friend(N)));
- }
- if (j) {
- printf("\nnext %i match\n",j);
- }
- }
- } while (proxy && proxy != halt);
- proxy = next_proxy;
- }
- return SYNCTEX_STATUS_OK;
- }
- SYNCTEX_INLINE static synctex_status_t _synctex_post_process(synctex_scanner_p scanner) {
- synctex_status_t status = SYNCTEX_STATUS_OK;
- synctex_ns_s ns = {NULL,SYNCTEX_STATUS_NOT_OK};
- printf("! entering _synctex_post_process.\n");
- synctex_node_display(scanner->sheet);
- synctex_node_display(scanner->form);
-
- ns = _synctex_post_process_ref(scanner->ref_in_form);
- scanner->ref_in_form = NULL;
- if (ns.status<status) {
- status = ns.status;
- }
- printf("! ref replaced in form _synctex_post_process.\n");
- synctex_node_display(scanner->form);
-
- ns.status = _synctex_post_process_proxy(ns.node,&_synctex_tree_reset_friend);
- if (ns.status<status) {
- status = ns.status;
- }
-
- ns = _synctex_post_process_ref(scanner->ref_in_sheet);
- if (ns.status<status) {
- status = ns.status;
- }
- scanner->ref_in_sheet = NULL;
- printf("! ref replaced in sheet _synctex_post_process.\n");
- synctex_node_display(scanner->sheet);
- {
- int i;
- for (i=0;i<scanner->number_of_lists;++i) {
- synctex_node_p P = ns.node;
- do {
- synctex_node_p N = scanner->lists_of_friends[i];
- do {
- if (P == N) {
- printf("Already registered.\n");
- synctex_node_display(N);
- break;
- }
- } while ((N = _synctex_tree_friend(N)));
- } while((P = _synctex_tree_friend(P)));
- }
- }
- {
- int i;
- for (i=0;i<scanner->number_of_lists;++i) {
- synctex_node_p P = scanner->lists_of_friends[i];
- int j = 0;
- while (P) {
- ++j;
- synctex_node_log(P);
- P = _synctex_tree_friend(P);
- }
- if (j) {
- printf("friends %i -> # %i\n",i,j);
- }
- }
- }
- ns.status = _synctex_post_process_proxy(ns.node,&__synctex_proxy_make_friend_and_next_hbox);
- if (ns.status<status) {
- status = ns.status;
- }
- printf("! exiting _synctex_post_process.\n");
- synctex_node_display(scanner->sheet);
- synctex_node_display(scanner->form);
- printf("! display all.\n");
- synctex_node_display(scanner->sheet);
- synctex_node_display(scanner->form);
- return status;
- }
- static synctex_status_t _synctex_scan_content(synctex_scanner_p scanner) {
- scanner->reader->lastv = -1;
- synctex_status_t status = 0;
- if (NULL == scanner) {
- return SYNCTEX_STATUS_BAD_ARGUMENT;
- }
-
- content_not_found:
- status = _synctex_match_string(scanner,"Content:");
- if (status<SYNCTEX_STATUS_EOF) {
- return status;
- }
- if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
- _synctex_error("Uncomplete Content.");
- return SYNCTEX_STATUS_ERROR;
- }
- if (status == SYNCTEX_STATUS_NOT_OK) {
- goto content_not_found;
- }
- status = __synctex_parse_sfi(scanner);
- if (status == SYNCTEX_STATUS_OK) {
- status = _synctex_post_process(scanner);
- }
- return status;
- }
- synctex_scanner_p synctex_scanner_new() {
- synctex_scanner_p scanner =(synctex_scanner_p)_synctex_malloc(sizeof(synctex_scanner_s));
- if (scanner) {
- if (!(scanner->reader = _synctex_malloc(sizeof(synctex_reader_s)))) {
- _synctex_free(scanner);
- return NULL;
- }
- scanner->class_[synctex_node_type_
- (scanner->class_[synctex_node_type_
- DEFINE_synctex_scanner_class(input);
- DEFINE_synctex_scanner_class(sheet);
- DEFINE_synctex_scanner_class(form);
- DEFINE_synctex_scanner_class(hbox);
- DEFINE_synctex_scanner_class(void_hbox);
- DEFINE_synctex_scanner_class(vbox);
- DEFINE_synctex_scanner_class(void_vbox);
- DEFINE_synctex_scanner_class(kern);
- DEFINE_synctex_scanner_class(glue);
- DEFINE_synctex_scanner_class(rule);
- DEFINE_synctex_scanner_class(math);
- DEFINE_synctex_scanner_class(boundary);
- DEFINE_synctex_scanner_class(box_bdry);
- DEFINE_synctex_scanner_class(ref);
- DEFINE_synctex_scanner_class(proxy_hbox);
- DEFINE_synctex_scanner_class(proxy_vbox);
- DEFINE_synctex_scanner_class(proxy);
- DEFINE_synctex_scanner_class(proxy_last);
- DEFINE_synctex_scanner_class(handle);
-
- scanner->number_of_lists = 1024;
- scanner->lists_of_friends = (synctex_node_r)_synctex_malloc(scanner->number_of_lists*sizeof(synctex_node_p));
- if (NULL == scanner->lists_of_friends) {
- synctex_scanner_free(scanner);
- _synctex_error("malloc:2");
- return NULL;
- }
- scanner->display_switcher = 100;
- scanner->display_prompt = (char *)_synctex_display_prompt+strlen(_synctex_display_prompt)-1;
- }
- return scanner;
- }
- synctex_scanner_p synctex_scanner_new_with_output_file(const char * output, const char * build_directory, int parse) {
- synctex_scanner_p scanner = synctex_scanner_new();
- if (NULL == scanner) {
- _synctex_error("malloc problem");
- return NULL;
- }
- if ((scanner->reader = synctex_reader_init_with_output_file(scanner->reader, output, build_directory))) {
- return parse? synctex_scanner_parse(scanner):scanner;
- }
- _synctex_error("No file?");
- return NULL;
- }
- int synctex_scanner_free(synctex_scanner_p scanner) {
- int node_count = 0;
- if (scanner) {
- if (SYNCTEX_FILE) {
- gzclose(SYNCTEX_FILE);
- SYNCTEX_FILE = NULL;
- }
- synctex_node_free(scanner->sheet);
- synctex_node_free(scanner->form);
- synctex_node_free(scanner->input);
- synctex_reader_free(scanner->reader);
- SYNCTEX_SCANNER_FREE_HANDLE(scanner);
- synctex_iterator_free(scanner->iterator);
- free(scanner->output_fmt);
- free(scanner->lists_of_friends);
- node_count = scanner->node_count;
- free(scanner);
- }
- return node_count;
- }
- synctex_scanner_p synctex_scanner_parse(synctex_scanner_p scanner) {
- synctex_status_t status = 0;
- if (!scanner || scanner->flags.has_parsed) {
- return scanner;
- }
- scanner->flags.has_parsed=1;
- scanner->pre_magnification = 1000;
- scanner->pre_unit = 8192;
- scanner->pre_x_offset = scanner->pre_y_offset = 578;
-
- scanner->x_offset = scanner->y_offset = 6.027e23f;
- scanner->reader->line_number = 1;
-
- SYNCTEX_START = (char *)malloc(SYNCTEX_BUFFER_SIZE+1);
- if (NULL == SYNCTEX_START) {
- _synctex_error("! malloc error in synctex_scanner_parse.");
- bailey:
- return scanner;
- synctex_scanner_free(scanner);
- return NULL;
- }
- synctex_scanner_set_display_switcher(scanner, 1000);
- SYNCTEX_END = SYNCTEX_START+SYNCTEX_BUFFER_SIZE;
-
- *SYNCTEX_END = '\0';
- SYNCTEX_CUR = SYNCTEX_END;
- scanner->reader->charindex_offset = -SYNCTEX_BUFFER_SIZE;
- status = _synctex_scan_preamble(scanner);
- if (status<SYNCTEX_STATUS_OK) {
- _synctex_error("Bad preamble\n");
- goto bailey;
- }
- status = _synctex_scan_content(scanner);
- if (status<SYNCTEX_STATUS_OK) {
- _synctex_error("Bad content\n");
- goto bailey;
- }
- status = _synctex_scan_postamble(scanner);
- if (status<SYNCTEX_STATUS_OK) {
- _synctex_error("Bad postamble. Ignored\n");
- }
- synctex_scanner_set_display_switcher(scanner, 100);
- synctex_node_display(scanner->sheet);
- synctex_node_display(scanner->form);
- synctex_scanner_set_display_switcher(scanner, 1000);
-
- free((void *)SYNCTEX_START);
- SYNCTEX_START = SYNCTEX_CUR = SYNCTEX_END = NULL;
- gzclose(SYNCTEX_FILE);
- SYNCTEX_FILE = NULL;
-
-
- if (scanner->pre_unit<=0) {
- scanner->pre_unit = 8192;
- }
- if (scanner->pre_magnification<=0) {
- scanner->pre_magnification = 1000;
- }
- if (scanner->unit <= 0) {
-
- scanner->unit = scanner->pre_unit / 65781.76;
- } else {
-
- scanner->unit *= scanner->pre_unit / 65781.76;
- }
- scanner->unit *= scanner->pre_magnification / 1000.0;
- if (scanner->x_offset > 6e23) {
-
- scanner->x_offset = scanner->pre_x_offset * (scanner->pre_unit / 65781.76);
- scanner->y_offset = scanner->pre_y_offset * (scanner->pre_unit / 65781.76);
- } else {
-
- scanner->x_offset /= 65781.76f;
- scanner->y_offset /= 65781.76f;
- }
- return scanner;
- }
- int synctex_scanner_pre_x_offset(synctex_scanner_p scanner){
- return scanner?scanner->pre_x_offset:0;
- }
- int synctex_scanner_pre_y_offset(synctex_scanner_p scanner){
- return scanner?scanner->pre_y_offset:0;
- }
- int synctex_scanner_x_offset(synctex_scanner_p scanner){
- return scanner?scanner->x_offset:0;
- }
- int synctex_scanner_y_offset(synctex_scanner_p scanner){
- return scanner?scanner->y_offset:0;
- }
- float synctex_scanner_magnification(synctex_scanner_p scanner){
- return scanner?scanner->unit:1;
- }
- void synctex_scanner_display(synctex_scanner_p scanner) {
- if (NULL == scanner) {
- return;
- }
- printf("The scanner:\noutput:%s\noutput_fmt:%s\nversion:%i\n",scanner->reader->output,scanner->output_fmt,scanner->version);
- printf("pre_unit:%i\nx_offset:%i\ny_offset:%i\n",scanner->pre_unit,scanner->pre_x_offset,scanner->pre_y_offset);
- printf("count:%i\npost_magnification:%f\npost_x_offset:%f\npost_y_offset:%f\n",
- scanner->count,scanner->unit,scanner->x_offset,scanner->y_offset);
- printf("The input:\n");
- synctex_node_display(scanner->input);
- if (scanner->count<1000) {
- printf("The sheets:\n");
- synctex_node_display(scanner->sheet);
- printf("The friends:\n");
- if (scanner->lists_of_friends) {
- int i = scanner->number_of_lists;
- synctex_node_p node;
- while(i--) {
- printf("Friend index:%i\n",i);
- node = (scanner->lists_of_friends)[i];
- while(node) {
- printf("%s:%i,%i\n",
- synctex_node_isa(node),
- _synctex_data_tag(node),
- _synctex_data_line(node)
- );
- node = _synctex_tree_friend(node);
- }
- }
- }
- } else {
- printf("SyncTeX Warning: Too many objects\n");
- }
- }
- const char * synctex_scanner_get_name(synctex_scanner_p scanner,int tag) {
- synctex_node_p input = NULL;
- if (NULL == scanner) {
- return NULL;
- }
- if ((input = scanner->input)) {;
- do {
- if (tag == _synctex_data_tag(input)) {
- return (_synctex_data_name(input));
- }
- } while((input = __synctex_tree_sibling(input)));
- }
- return NULL;
- }
- const char * synctex_node_get_name(synctex_node_p node) {
- if (node) {
- return synctex_scanner_get_name(node->class_->scanner,_synctex_data_tag(node));
- }
- return NULL;
- }
- static int _synctex_scanner_get_tag(synctex_scanner_p scanner,const char * name);
- static int _synctex_scanner_get_tag(synctex_scanner_p scanner,const char * name) {
- synctex_node_p input = NULL;
- if (NULL == scanner) {
- return 0;
- }
- if ((input = scanner->input)) {
- do {
- if (_synctex_is_equivalent_file_name(name,(_synctex_data_name(input)))) {
- return _synctex_data_tag(input);
- }
- } while((input = __synctex_tree_sibling(input)));
- }
-
- name = _synctex_base_name(name);
- if ((input = scanner->input)) {
- do {
- if (_synctex_is_equivalent_file_name(name,_synctex_base_name(_synctex_data_name(input)))) {
- synctex_node_p other_input = input;
- while((other_input = __synctex_tree_sibling(other_input))) {
- if (_synctex_is_equivalent_file_name(name,_synctex_base_name(_synctex_data_name(other_input)))
- && (strlen(_synctex_data_name(input))!=strlen(_synctex_data_name(other_input))
- || strncmp(_synctex_data_name(other_input),_synctex_data_name(input),strlen(_synctex_data_name(input))))) {
-
- return 0;
- }
- }
- return _synctex_data_tag(input);
- }
- } while((input = __synctex_tree_sibling(input)));
- }
- return 0;
- }
- int synctex_scanner_get_tag(synctex_scanner_p scanner,const char * name) {
- size_t char_index = strlen(name);
- if ((scanner = synctex_scanner_parse(scanner)) && (0 < char_index)) {
-
- char_index -= 1;
- if (!SYNCTEX_IS_PATH_SEPARATOR(name[char_index])) {
-
- int result = _synctex_scanner_get_tag(scanner,name);
- if (result) {
- return result;
- } else {
-
- const char * relative = name;
- const char * ptr = scanner->reader->output;
- while((strlen(relative) > 0) && (strlen(ptr) > 0) && (*relative == *ptr))
- {
- relative += 1;
- ptr += 1;
- }
-
- while(relative > name) {
- if (SYNCTEX_IS_PATH_SEPARATOR(*(relative-1))) {
- break;
- }
- relative -= 1;
- }
- if ((relative > name) && (result = _synctex_scanner_get_tag(scanner,relative))) {
- return result;
- }
- if (SYNCTEX_IS_PATH_SEPARATOR(name[0])) {
-
- while(0<char_index) {
- char_index -= 1;
- if (SYNCTEX_IS_PATH_SEPARATOR(name[char_index])
- && (result = _synctex_scanner_get_tag(scanner,name+char_index+1))) {
- return result;
- }
- }
- }
- }
- return result;
- }
- }
- return 0;
- }
- synctex_node_p synctex_scanner_input(synctex_scanner_p scanner) {
- return scanner?scanner->input:NULL;
- }
- synctex_node_p synctex_scanner_input_with_tag(synctex_scanner_p scanner, int tag) {
- synctex_node_p input = scanner?scanner->input:NULL;
- while (_synctex_data_tag(input)!=tag) {
- if ((input = __synctex_tree_sibling(input))) {
- continue;
- }
- break;
- }
- return input;
- }
- const char * synctex_scanner_get_output_fmt(synctex_scanner_p scanner) {
- return NULL != scanner && scanner->output_fmt?scanner->output_fmt:"";
- }
- const char * synctex_scanner_get_output(synctex_scanner_p scanner) {
- return NULL != scanner && scanner->reader->output?scanner->reader->output:"";
- }
- const char * synctex_scanner_get_synctex(synctex_scanner_p scanner) {
- return NULL != scanner && scanner->reader->synctex?scanner->reader->synctex:"";
- }
- int synctex_node_
- return (node && node->class_->inspector->WHAT)? \
- node->class_->inspector->WHAT(node): 0; \
- }
- static int _synctex_proxy_
- synctex_node_p target = _synctex_tree_target(proxy); \
- if (target) { \
- return _synctex_data_
- } else { \
- return proxy? _synctex_data_
- } \
- }
- static int _synctex_proxy_
- synctex_node_p target = _synctex_tree_target(proxy); \
- return target? synctex_node_
- }
- SYNCTEX_DEFINE_NODE_HVWHD(h)
- SYNCTEX_DEFINE_NODE_HVWHD(v)
- SYNCTEX_DEFINE_NODE_HVWHD(width)
- SYNCTEX_DEFINE_NODE_HVWHD(height)
- SYNCTEX_DEFINE_NODE_HVWHD(depth)
- SYNCTEX_DEFINE_PROXY_TLCWVD(tag)
- SYNCTEX_DEFINE_PROXY_TLCWVD(line)
- SYNCTEX_DEFINE_PROXY_TLCWVD(column)
- SYNCTEX_DEFINE_PROXY_HV(h)
- SYNCTEX_DEFINE_PROXY_HV(v)
- SYNCTEX_DEFINE_PROXY_TLCWVD(width)
- SYNCTEX_DEFINE_PROXY_TLCWVD(height)
- SYNCTEX_DEFINE_PROXY_TLCWVD(depth)
- SYNCTEX_INLINE static synctex_bool_t _synctex_node_is_box(synctex_node_p node) {
- return node &&
- (node->class_->type == synctex_node_type_hbox
- || node->class_->type == synctex_node_type_void_hbox
- || node->class_->type == synctex_node_type_vbox
- || node->class_->type == synctex_node_type_void_vbox
- || _synctex_node_is_box(_synctex_tree_target(node)));
- }
- SYNCTEX_INLINE static synctex_bool_t _synctex_node_is_handle(synctex_node_p node) {
- return node &&
- (node->class_->type == synctex_node_type_handle);
- }
- SYNCTEX_INLINE static synctex_node_p _synctex_node_or_handle_target(synctex_node_p node) {
- return _synctex_node_is_handle(node)?
- _synctex_tree_target(node):node;
- }
- SYNCTEX_INLINE static synctex_bool_t _synctex_node_is_hbox(synctex_node_p node) {
- return node &&
- (node->class_->type == synctex_node_type_hbox
- || node->class_->type == synctex_node_type_void_hbox
- || _synctex_node_is_hbox(_synctex_tree_target(node)));
- }
- int synctex_node_box_h(synctex_node_p node) {
- if (_synctex_node_is_box(node) || (node = _synctex_tree_parent(node))) {
- return synctex_node_h(node);
- }
- return 0;
- }
- int synctex_node_box_v(synctex_node_p node) {
- if (_synctex_node_is_box(node) || (node = _synctex_tree_parent(node))) {
- return synctex_node_v(node);
- }
- return 0;
- }
- int synctex_node_box_width(synctex_node_p node) {
- if (_synctex_node_is_box(node) || (node = _synctex_tree_parent(node))) {
- return synctex_node_width(node);
- }
- return 0;
- }
- int synctex_node_box_height(synctex_node_p node) {
- if (_synctex_node_is_box(node) || (node = _synctex_tree_parent(node))) {
- return synctex_node_height(node);
- }
- return 0;
- }
- int synctex_node_box_depth(synctex_node_p node) {
- if (_synctex_node_is_box(node) || (node = _synctex_tree_parent(node))) {
- return synctex_node_depth(node);
- }
- return 0;
- }
- int synctex_node_hbox_h(synctex_node_p node) {
- switch(synctex_node_type(node)) {
- case synctex_node_type_hbox:
- return _synctex_data_h_V(node);
- case synctex_node_type_proxy_hbox:
- return _synctex_data_h(node)+synctex_node_hbox_h(_synctex_tree_target(node));
- default:
- return 0;
- }
- }
- int synctex_node_hbox_v(synctex_node_p node) {
- switch(synctex_node_type(node)) {
- case synctex_node_type_hbox:
- return _synctex_data_v_V(node);
- case synctex_node_type_proxy_hbox:
- return _synctex_data_v(node)+synctex_node_hbox_v(_synctex_tree_target(node));
- default:
- return 0;
- }
- }
- int synctex_node_hbox_width(synctex_node_p node) {
- synctex_node_p target = _synctex_tree_target(node);
- if (target) {
- node = target;
- }
- return synctex_node_type(node) == synctex_node_type_hbox?
- _synctex_data_width_V(node): 0;
- }
- int synctex_node_hbox_height(synctex_node_p node) {
- synctex_node_p target = _synctex_tree_target(node);
- if (target) {
- node = target;
- }
- return synctex_node_type(node) == synctex_node_type_hbox?
- _synctex_data_height_V(node): 0;
- }
- int synctex_node_hbox_depth(synctex_node_p node) {
- synctex_node_p target = _synctex_tree_target(node);
- if (target) {
- node = target;
- }
- return synctex_node_type(node) == synctex_node_type_hbox?
- _synctex_data_depth_V(node): 0;
- }
- (s)*node->class_->scanner->unit
- ((d)*node->class_->scanner->unit+node->class_->scanner->x_offset)
- ((d)*node->class_->scanner->unit+node->class_->scanner->y_offset)
- static float __synctex_node_visible_h(synctex_node_p node) {
- return SYNCTEX_VISIBLE_DISTANCE_h(node,synctex_node_h(node));
- }
- static float __synctex_node_visible_v(synctex_node_p node) {
- return SYNCTEX_VISIBLE_DISTANCE_v(node,synctex_node_v(node));
- }
- static float __synctex_node_visible_width(synctex_node_p node) {
- return SYNCTEX_VISIBLE_SIZE(node,synctex_node_width(node));
- }
- static float __synctex_node_visible_height(synctex_node_p node) {
- return SYNCTEX_VISIBLE_SIZE(node,synctex_node_height(node));
- }
- static float __synctex_node_visible_depth(synctex_node_p node) {
- return SYNCTEX_VISIBLE_SIZE(node,synctex_node_depth(node));
- }
- static float __synctex_proxy_visible_h(synctex_node_p node) {
- return SYNCTEX_VISIBLE_DISTANCE_h(node,synctex_node_h(node));
- }
- static float __synctex_proxy_visible_v(synctex_node_p node) {
- return SYNCTEX_VISIBLE_DISTANCE_v(node,synctex_node_v(node));
- }
- static float __synctex_proxy_visible_width(synctex_node_p node) {
- synctex_node_p target = _synctex_tree_target(node);
- return __synctex_node_visible_width(target);
- }
- static float __synctex_proxy_visible_height(synctex_node_p node) {
- synctex_node_p target = _synctex_tree_target(node);
- return __synctex_node_visible_height(target);
- }
- static float __synctex_proxy_visible_depth(synctex_node_p node) {
- synctex_node_p target = _synctex_tree_target(node);
- return __synctex_node_visible_depth(target);
- }
- static float __synctex_kern_visible_h(synctex_noxy_p noxy) {
- int h = _synctex_data_h(noxy);
- int width = _synctex_data_width(noxy);
- return SYNCTEX_VISIBLE_DISTANCE_h(noxy, width>0?h-width:h);
- }
- static float __synctex_kern_visible_width(synctex_noxy_p noxy) {
- int width = _synctex_data_width(noxy);
- return SYNCTEX_VISIBLE_SIZE(noxy, width>0?width:-width);
- }
- static float __synctex_rule_visible_h(synctex_noxy_p noxy) {
- int h = _synctex_data_h(noxy);
- int width = _synctex_data_width(noxy);
- return SYNCTEX_VISIBLE_DISTANCE_h(noxy, width>0?h:h-width);
- }
- static float __synctex_rule_visible_width(synctex_noxy_p noxy) {
- int width = _synctex_data_width(noxy);
- return SYNCTEX_VISIBLE_SIZE(noxy, width>0?width:-width);
- }
- static float __synctex_rule_visible_v(synctex_noxy_p noxy) {
- return __synctex_node_visible_v(noxy);
- }
- static float __synctex_rule_visible_height(synctex_noxy_p noxy) {
- return __synctex_node_visible_height(noxy);
- }
- static float __synctex_rule_visible_depth(synctex_noxy_p noxy) {
- return __synctex_node_visible_depth(noxy);
- }
- float synctex_node_visible_h(synctex_node_p node){
- return node? node->class_->vispector->h(node): 0;
- }
- float synctex_node_visible_v(synctex_node_p node){
- return node? node->class_->vispector->v(node): 0;
- }
- float synctex_node_visible_width(synctex_node_p node){
- return node? node->class_->vispector->width(node): 0;
- }
- float synctex_node_visible_height(synctex_node_p node){
- return node? node->class_->vispector->height(node): 0;
- }
- float synctex_node_visible_depth(synctex_node_p node){
- return node? node->class_->vispector->depth(node): 0;
- }
- SYNCTEX_INLINE static int _synctex_node_
- synctex_node_p target = _synctex_tree_target(node); \
- if (target) { \
- return _synctex_data_
- } else if (_synctex_data_has_
- return _synctex_data_
- } else { \
- return _synctex_data_
- } \
- }
- SYNCTEX_DEFINE_V(h)
- SYNCTEX_DEFINE_V(v)
- SYNCTEX_DEFINE_V(width)
- SYNCTEX_DEFINE_V(height)
- SYNCTEX_DEFINE_V(depth)
- SYNCTEX_INLINE static synctex_point_s _synctex_data_point(synctex_node_p node) {
- return (synctex_point_s){synctex_node_h(node),synctex_node_v(node)};
- }
- SYNCTEX_INLINE static synctex_point_s _synctex_data_point_V(synctex_node_p node) {
- return (synctex_point_s){_synctex_node_h_V(node),_synctex_node_v_V(node)};
- }
- SYNCTEX_INLINE static synctex_point_s _synctex_data_set_point(synctex_node_p node, synctex_point_s point) {
- synctex_point_s old = _synctex_data_point(node);
- _synctex_data_set_h(node,point.h);
- _synctex_data_set_v(node,point.v);
- return old;
- }
- SYNCTEX_INLINE static synctex_box_s _synctex_data_box(synctex_node_p node) {
- synctex_box_s box = {{0,0},{0,0}};
- int n;
- n = synctex_node_width(node);
- if (n<0) {
- box.max.h = synctex_node_h(node);
- box.min.h = box.max.h + n;
- } else {
- box.min.h = synctex_node_h(node);
- box.max.h = box.min.h + n;
- }
- n = synctex_node_v(node);
- box.min.v = n - synctex_node_height(node);
- box.max.v = n + synctex_node_depth(node);
- return box;
- }
- SYNCTEX_INLINE static synctex_box_s _synctex_data_xob(synctex_node_p node) {
- synctex_box_s box = {{0,0},{0,0}};
- int n;
- n = synctex_node_width(node);
- if (n>0) {
- box.max.h = synctex_node_h(node);
- box.min.h = box.max.h - n;
- } else {
- box.min.h = synctex_node_h(node);
- box.max.h = box.min.h - n;
- }
- n = synctex_node_v(node);
- box.min.v = n - synctex_node_height(node);
- box.max.v = n + synctex_node_depth(node);
- return box;
- }
- SYNCTEX_INLINE static synctex_box_s _synctex_data_box_V(synctex_node_p node) {
- synctex_box_s box = {{0,0},{0,0}};
- int n;
- n = _synctex_node_width_V(node);
- if (n<0) {
- box.max.h = _synctex_node_h_V(node);
- box.min.h = box.max.h + n;
- } else {
- box.min.h = _synctex_node_h_V(node);
- box.max.h = box.min.h + n;
- }
- n = _synctex_node_v_V(node);
- box.min.v = n - _synctex_node_height_V(node);
- box.max.v = n + _synctex_node_depth_V(node);
- return box;
- }
- static synctex_node_p _synctex_node_box_visible(synctex_node_p node) {
- if ((node = _synctex_node_or_handle_target(node))) {
- int mean = 0;
- int bound = 1500000/(node->class_->scanner->pre_magnification/1000.0);
- synctex_node_p parent = NULL;
-
- node = _synctex_node_or_handle_target(node);
- if (!_synctex_node_is_box(node)) {
- if ((parent = _synctex_tree_parent(node))) {
- node = parent;
- } else if ((node = _synctex_tree_target(node))) {
- if (!_synctex_node_is_box(node)) {
- if ((parent = _synctex_tree_parent(node))) {
- node = parent;
- } else {
- return NULL;
- }
- }
- }
- }
- parent = node;
- mean = synctex_node_mean_line(node);
- while ((parent = _synctex_tree_parent(parent))) {
- if (_synctex_node_is_hbox(parent)) {
- if (_synctex_abs(mean-synctex_node_mean_line(parent))>1) {
- return node;
- } else if (synctex_node_width(parent)>bound) {
- return parent;
- } else if (synctex_node_height(parent)+synctex_node_depth(parent)>bound) {
- return parent;
- }
- node = parent;
- }
- }
- }
- return node;
- }
- float synctex_node_box_visible_h(synctex_node_p node) {
- return SYNCTEX_VISIBLE_DISTANCE_h(node,_synctex_node_h_V(_synctex_node_box_visible(node)));
- }
- float synctex_node_box_visible_v(synctex_node_p node) {
- return SYNCTEX_VISIBLE_DISTANCE_v(node,_synctex_node_v_V(_synctex_node_box_visible(node)));
- }
- float synctex_node_box_visible_width(synctex_node_p node) {
- return SYNCTEX_VISIBLE_SIZE(node,_synctex_node_width_V(_synctex_node_box_visible(node)));
- }
- float synctex_node_box_visible_height(synctex_node_p node) {
- return SYNCTEX_VISIBLE_SIZE(node,_synctex_node_height_V(_synctex_node_box_visible(node)));
- }
- float synctex_node_box_visible_depth(synctex_node_p node) {
- return SYNCTEX_VISIBLE_SIZE(node,_synctex_node_depth_V(_synctex_node_box_visible(node)));
- }
- int synctex_node_page(synctex_node_p node){
- synctex_node_p parent = NULL;
- while((parent = _synctex_tree_parent(node))) {
- node = parent;
- }
- if (synctex_node_type(node) == synctex_node_type_sheet) {
- return _synctex_data_page(node);
- }
- return -1;
- }
- SYNCTEX_INLINE static int _synctex_node_target_page(synctex_node_p node){
- return synctex_node_page(_synctex_tree_target(node));
- }
- synctex_charindex_t synctex_node_charindex(synctex_node_p node) {
- synctex_node_p target = _synctex_tree_target(node);
- return target? SYNCTEX_CHARINDEX(target):(node?SYNCTEX_CHARINDEX(node):0);
- }
- int synctex_node_tag(synctex_node_p node) {
- return node? node->class_->tlcpector->tag(node): -1;
- }
- int synctex_node_line(synctex_node_p node) {
- return node? node->class_->tlcpector->line(node): -1;
- }
- int synctex_node_column(synctex_node_p node) {
- return node? node->class_->tlcpector->column(node): -1;
- }
- int synctex_node_mean_line(synctex_node_p node) {
- synctex_node_p other = _synctex_tree_target(node);
- if (other) {
- node = other;
- }
- if (_synctex_data_has_mean_line(node)) {
- return _synctex_data_mean_line(node);
- }
- if ((other = synctex_node_parent(node))) {
- if (_synctex_data_has_mean_line(other)) {
- return _synctex_data_mean_line(other);
- }
- }
- return synctex_node_line(node);
- }
- int synctex_node_weight(synctex_node_p node) {
- synctex_node_p target = _synctex_tree_target(node);
- if (target) {
- node = target;
- }
- return node?(synctex_node_type(node)==synctex_node_type_hbox?_synctex_data_weight(node):0):-1;
- }
- int synctex_node_child_count(synctex_node_p node) {
- synctex_node_p target = _synctex_tree_target(node);
- if (target) {
- node = target;
- }
- return node?(synctex_node_type(node)==synctex_node_type_hbox?_synctex_data_weight(node):0):-1;
- }
- synctex_node_p synctex_sheet(synctex_scanner_p scanner,int page) {
- if (scanner) {
- synctex_node_p sheet = scanner->sheet;
- while(sheet) {
- if (page == _synctex_data_page(sheet)) {
- return sheet;
- }
- sheet = __synctex_tree_sibling(sheet);
- }
- if (page == 0) {
- return scanner->sheet;
- }
- }
- return NULL;
- }
- synctex_node_p synctex_form(synctex_scanner_p scanner,int tag) {
- if (scanner) {
- synctex_node_p form = scanner->form;
- while(form) {
- if (tag == _synctex_data_tag(form)) {
- return form;
- }
- form = __synctex_tree_sibling(form);
- }
- if (tag == 0) {
- return scanner->form;
- }
- }
- return NULL;
- }
- synctex_node_p synctex_sheet_content(synctex_scanner_p scanner,int page) {
- if (scanner) {
- return _synctex_tree_child(synctex_sheet(scanner,page));
- }
- return NULL;
- }
- synctex_node_p synctex_form_content(synctex_scanner_p scanner,int tag) {
- if (scanner) {
- return _synctex_tree_child(synctex_form(scanner,tag));
- }
- return NULL;
- }
- SYNCTEX_INLINE static synctex_node_p _synctex_scanner_friend(synctex_scanner_p scanner,int i) {
- if (i>=0) {
- i = _synctex_abs(i)%(scanner->number_of_lists);
- return (scanner->lists_of_friends)[i];
- }
- return NULL;
- }
- SYNCTEX_INLINE static synctex_bool_t _synctex_nodes_are_friend(synctex_node_p left, synctex_node_p right) {
- return synctex_node_tag(left) == synctex_node_tag(right) && synctex_node_line(left) == synctex_node_line(right);
- }
- typedef struct {
- int count;
- synctex_node_p node;
- } synctex_counted_node_s;
- SYNCTEX_INLINE static synctex_counted_node_s _synctex_vertically_sorted_v2(synctex_node_p sibling) {
-
- synctex_counted_node_s result = {0, NULL};
- synctex_node_p h = NULL;
- synctex_node_p next_h = NULL;
- synctex_node_p parent = NULL;
- int weight = 0;
- synctex_node_p N = NULL;
- h = sibling;
- do {
- N = _synctex_tree_target(h);
- parent = _synctex_tree_parent(N);
- _synctex_data_set_weight(parent, 0);
- } while((h = _synctex_tree_child(h)));
-
- h = sibling;
- do {
- N = _synctex_tree_target(h);
- parent = _synctex_tree_parent(N);
- weight = _synctex_data_weight(parent);
- if (weight==0) {
- N = _synctex_tree_child(parent);
- do {
- if (_synctex_nodes_are_friend(N,sibling)) {
- ++ weight;
- }
- } while ((N = __synctex_tree_sibling(N)));
- _synctex_data_set_weight(h,weight);
- _synctex_data_set_weight(parent,weight);
- }
- } while((h = _synctex_tree_child(h)));
-
- h = _synctex_tree_reset_child(sibling);
- result.node = sibling;
- weight = 0;
- while((h)) {
- N = result.node;
- if (_synctex_data_weight(h)>_synctex_data_weight(N)) {
- next_h = _synctex_tree_set_child(h,N);
- result.node = h;
- } else if (_synctex_data_weight(h) == 0) {
- ++ weight;
- next_h = _synctex_tree_reset_child(h);
- synctex_node_free(h);
- } else {
- synctex_node_p next_N = NULL;
- while((next_N = _synctex_tree_child(N))) {
- N = next_N;
- if (_synctex_data_weight(h)<_synctex_data_weight(next_N)) {
- continue;
- }
- break;
- }
- next_h = _synctex_tree_set_child(h,_synctex_tree_set_child(N,h));
- }
- h = next_h;
- };
- h = result.node;
- weight = 0;
- do {
- ++weight;
- } while((h = _synctex_tree_child(h)));
- result.count = 1;
- h = result.node;
- while((next_h = _synctex_tree_child(h))) {
- if (_synctex_data_weight(next_h)==0) {
- _synctex_tree_reset_child(h);
- weight = 1;
- h = next_h;
- while((h = _synctex_tree_child(h))) {
- ++weight;
- }
- synctex_node_free(next_h);
- break;
- }
- ++result.count;
- h = next_h;
- }
- return result;
- }
- SYNCTEX_INLINE static synctex_bool_t _synctex_point_in_box_v2(synctex_point_p hitP, synctex_node_p node);
- typedef struct {
- synctex_node_p node;
- int distance;
- } synctex_nd_s;
- typedef synctex_nd_s * synctex_nd_p;
- typedef struct {
- synctex_nd_s l;
- synctex_nd_s r;
- } synctex_nd_lr_s;
- static synctex_node_p _synctex_eq_deepest_container_v2(synctex_point_p hitP, synctex_node_p node);
- SYNCTEX_INLINE static synctex_nd_lr_s _synctex_eq_get_closest_children_in_box_v2(synctex_point_p hitP, synctex_node_p node);
- static synctex_nd_s __synctex_closest_deep_child_v2(synctex_point_p hitP, synctex_node_p node);
- SYNCTEX_INLINE static synctex_node_p _synctex_smallest_container_v2(synctex_node_p node, synctex_node_p other_node);
- static int _synctex_point_node_distance_v2(synctex_point_p hitP, synctex_node_p node);
- static synctex_nd_s _synctex_eq_closest_child_v2(synctex_point_p hitP, synctex_node_p node);
- struct synctex_iterator_t {
- synctex_node_p seed;
- synctex_node_p top;
- synctex_node_p next;
- int count0;
- int count;
- };
- SYNCTEX_INLINE static synctex_iterator_p _synctex_iterator_new(synctex_node_p result, int count) {
- synctex_iterator_p iterator;
- if ((iterator = _synctex_malloc(sizeof(synctex_iterator_s)))) {
- iterator->seed = iterator->top = iterator->next = result;
- iterator->count0 = iterator->count = count;
- }
- return iterator;
- };
- void synctex_iterator_free(synctex_iterator_p iterator) {
- if (iterator) {
- synctex_node_free(iterator->seed);
- _synctex_free(iterator);
- }
- }
- synctex_bool_t synctex_iterator_has_next(synctex_iterator_p iterator) {
- return iterator?iterator->count>0:0;
- }
- int synctex_iterator_count(synctex_iterator_p iterator) {
- return iterator? iterator->count: 0;
- }
- synctex_node_p synctex_iterator_next_result(synctex_iterator_p iterator) {
- if (iterator && iterator->count>0) {
- synctex_node_p N = iterator->next;
- if(!(iterator->next = _synctex_tree_child(N))) {
- iterator->next = iterator->top = __synctex_tree_sibling(iterator->top);
- }
- --iterator->count;
- return _synctex_tree_target(N);
- }
- return NULL;
- }
- int synctex_iterator_reset(synctex_iterator_p iterator) {
- if (iterator) {
- iterator->next = iterator->top = iterator->seed;
- return iterator->count = iterator->count0;
- }
- return 0;
- }
- synctex_iterator_p synctex_iterator_new_edit(synctex_scanner_p scanner,int page,float h,float v){
- if (scanner) {
- synctex_node_p sheet = NULL;
- synctex_point_s hit;
- synctex_node_p node = NULL;
- synctex_nd_lr_s nds = {{NULL,0},{NULL,0}};
- if (NULL == (scanner = synctex_scanner_parse(scanner)) || 0 >= scanner->unit) {
- return NULL;
- }
-
- sheet = synctex_sheet(scanner,page);
- if (NULL == sheet) {
- return NULL;
- }
-
-
- hit = (synctex_point_s)
- {(h-scanner->x_offset)/scanner->unit,
- (v-scanner->y_offset)/scanner->unit};
-
- if ((node = _synctex_tree_next_hbox(sheet))) {
- do {
- if (_synctex_point_in_box_v2(&hit,node)) {
-
- synctex_node_p next = node;
- printf("--- We are lucky\n");
-
- while ((next = _synctex_tree_next_hbox(next))) {
- if (_synctex_point_in_box_v2(&hit,next)) {
- node = _synctex_smallest_container_v2(next,node);
- }
- }
-
- node = _synctex_eq_deepest_container_v2(&hit, node);
- nds = _synctex_eq_get_closest_children_in_box_v2(&hit, node);
- end:
- if (nds.r.node && nds.l.node) {
- if ((_synctex_data_tag(nds.r.node)!=_synctex_data_tag(nds.l.node))
- || (_synctex_data_line(nds.r.node)!=_synctex_data_line(nds.l.node))
- || (_synctex_data_column(nds.r.node)!=_synctex_data_column(nds.l.node))) {
- if (_synctex_data_line(nds.r.node)<_synctex_data_line(nds.l.node)) {
- node = nds.r.node;
- nds.r.node = nds.l.node;
- nds.l.node = node;
- } else if (_synctex_data_line(nds.r.node)==_synctex_data_line(nds.l.node)) {
- if (nds.l.distance>nds.r.distance) {
- node = nds.r.node;
- nds.r.node = nds.l.node;
- nds.l.node = node;
- }
- }
- if((node = _synctex_new_handle_with_target(nds.l.node))) {
- synctex_node_p other_handle;
- if((other_handle = _synctex_new_handle_with_target(nds.r.node))) {
- _synctex_tree_set_sibling(node,other_handle);
- return _synctex_iterator_new(node,2);
- }
- return _synctex_iterator_new(node,1);
- }
- return NULL;
- }
-
- if (nds.l.distance>nds.r.distance) {
- nds.l.node = nds.r.node;
- }
- nds.r.node = NULL;
- } else if (nds.r.node) {
- nds.l = nds.r;
- } else if (!nds.l.node) {
- nds.l.node = node;
- }
- if((node = _synctex_new_handle_with_target(nds.l.node))) {
- return _synctex_iterator_new(node,1);
- }
- return 0;
- }
- } while ((node = _synctex_tree_next_hbox(node)));
-
- }
-
- if ((node = _synctex_tree_child(sheet))) {
- printf("--- We are not lucky\n");
- nds.l = __synctex_closest_deep_child_v2(&hit, node);
- printf("Edit query best: %i\n", nds.l.distance);
- goto end;
- }
- }
- return NULL;
- }
- static synctex_node_p _synctex_display_query_v2(synctex_node_p target, int tag, int line, synctex_bool_t exclude_box) {
- synctex_node_p first_handle = NULL;
-
- if (target == NULL) {
- return first_handle;
- }
- do {
- int page;
- if ((exclude_box
- && _synctex_node_is_box(target))
- || (tag != synctex_node_tag(target))
- || (line != synctex_node_line(target))) {
- continue;
- }
-
- first_handle = _synctex_new_handle_with_target(target);
- if (first_handle == NULL) {
- return first_handle;
- }
-
- page = synctex_node_page(target);
-
- while ((target = _synctex_tree_friend(target))) {
- synctex_node_p result = NULL;
- if ((exclude_box
- && _synctex_node_is_box(target))
- || (tag != synctex_node_tag(target))
- || (line != synctex_node_line(target))) {
- continue;
- }
-
- result = _synctex_new_handle_with_target(target);
- if (NULL == result ) {
- return first_handle;
- }
-
- if (synctex_node_page(target) == page) {
- __synctex_tree_set_child(result, first_handle);
- first_handle = result;
- } else {
-
- __synctex_tree_set_sibling(first_handle, result);
- while ((target = _synctex_tree_friend(target))) {
- synctex_node_p same_page_node;
- if ((exclude_box
- && _synctex_node_is_box(target))
- || (tag != synctex_node_tag(target))
- || (line != synctex_node_line(target))) {
- continue;
- }
-
- result = _synctex_new_handle_with_target(target);
- if (NULL == result) {
- return first_handle;
- }
- same_page_node = first_handle;
- page = synctex_node_page(target);
- ;
- do {
- if (_synctex_node_target_page(same_page_node) == page) {
-
- _synctex_tree_set_child(result,_synctex_tree_set_child(same_page_node,result));
- } else if ((same_page_node = __synctex_tree_sibling(same_page_node))) {
- continue;
- } else {
-
- __synctex_tree_set_sibling(result,first_handle);
- first_handle = result;
- }
- break;
- } while (synctex_YES);
- }
- return first_handle;
- }
- }
- } while ((target = _synctex_tree_friend(target)));
- return first_handle;
- }
- synctex_iterator_p synctex_iterator_new_display(synctex_scanner_p scanner,const char * name,int line,int column, int page_hint) {
- SYNCTEX_UNUSED(column)
- if (scanner) {
- int tag = synctex_scanner_get_tag(scanner,name);
- int max_line = 0;
- int line_offset = 1;
- int try_count = 100;
- synctex_node_p node = NULL;
- synctex_node_p result = NULL;
- if (tag == 0) {
- printf("SyncTeX Warning: No tag for %s\n",name);
- return NULL;
- }
- node = synctex_scanner_input_with_tag(scanner, tag);
- max_line = _synctex_data_line(node);
-
- if (line>max_line) {
- line = max_line;
- }
- while(try_count--) {
- if (line<=max_line) {
-
- synctex_node_p friend = _synctex_scanner_friend(scanner,tag+line);
- if ((node = friend)) {
- result = _synctex_display_query_v2(node,tag,line,synctex_YES);
- if (!result) {
-
- node = friend;
- result = _synctex_display_query_v2(node,tag,line,synctex_NO);
- }
-
-
- if (result) {
-
- synctex_node_p next_sibling = __synctex_tree_reset_sibling(result);
- int best_match = abs(page_hint-_synctex_node_target_page(result));
- synctex_node_p sibling;
- int match;
- synctex_counted_node_s cn = _synctex_vertically_sorted_v2(result);
- int count = cn.count;
- result = cn.node;
- while((sibling = next_sibling)) {
-
- next_sibling = __synctex_tree_reset_sibling(sibling);
- cn = _synctex_vertically_sorted_v2(sibling);
- count += cn.count;
- sibling = cn.node;
- match = abs(page_hint-_synctex_node_target_page(sibling));
- if (match<best_match) {
-
- __synctex_tree_set_sibling(sibling,result);
- result = sibling;
- best_match = match;
- } else {
- __synctex_tree_set_sibling(sibling,__synctex_tree_sibling(result));
- __synctex_tree_set_sibling(result,sibling);
- }
- }
- return _synctex_iterator_new(result,count);
- }
- }
- break;
- line += line_offset;
- line_offset=line_offset<0?-(line_offset-1):-(line_offset+1);
- if (line <= 0) {
- line += line_offset;
- line_offset=line_offset<0?-(line_offset-1):-(line_offset+1);
- }
- }
- }
- }
- return NULL;
- }
- synctex_status_t synctex_display_query(synctex_scanner_p scanner,const char * name,int line,int column, int page_hint) {
- if (scanner) {
- synctex_iterator_free(scanner->iterator);
- scanner->iterator = synctex_iterator_new_display(scanner, name,line,column, page_hint);
- return synctex_iterator_count(scanner->iterator);
- }
- return SYNCTEX_STATUS_ERROR;
- }
- synctex_status_t synctex_edit_query(synctex_scanner_p scanner,int page,float h,float v) {
- if (scanner) {
- synctex_iterator_free(scanner->iterator);
- scanner->iterator = synctex_iterator_new_edit(scanner, page, h, v);
- return synctex_iterator_count(scanner->iterator);
- }
- return SYNCTEX_STATUS_ERROR;
- }
- synctex_node_p synctex_scanner_next_result(synctex_scanner_p scanner) {
- return scanner? synctex_iterator_next_result(scanner->iterator): NULL;
- }
- synctex_status_t synctex_scanner_reset_result(synctex_scanner_p scanner) {
- return scanner? synctex_iterator_reset(scanner->iterator): SYNCTEX_STATUS_ERROR;
- }
- synctex_node_p synctex_node_target(synctex_node_p node) {
- return _synctex_tree_target(node);
- }
- static synctex_nd_s _synctex_point_h_ordered_distance_v2
- (synctex_point_p hit, synctex_node_p node) {
- synctex_nd_s nd = {node,INT_MAX};
- if (node) {
- int min,med,max,width;
- switch(synctex_node_type(node)) {
-
- case synctex_node_type_vbox:
- case synctex_node_type_void_vbox:
- case synctex_node_type_void_hbox:
-
- width = _synctex_data_width(node);
- min = _synctex_data_h(node);
- max = min + (width>0?width:-width);
-
- if (hit->h<min) {
- nd.distance = min - hit->h;
- } else if (hit->h>max) {
- nd.distance = max - hit->h;
- } else {
- nd.distance = 0;
- }
- break;
- case synctex_node_type_proxy_vbox:
-
- width = synctex_node_width(node);
- min = synctex_node_h(node);
- max = min + (width>0?width:-width);
-
- if (hit->h<min) {
- nd.distance = min - hit->h;
- } else if (hit->h>max) {
- nd.distance = max - hit->h;
- } else {
- nd.distance = 0;
- }
- break;
- case synctex_node_type_hbox:
- case synctex_node_type_proxy_hbox:
-
- width = synctex_node_hbox_width(node);
- min = synctex_node_hbox_h(node);
- max = min + (width>0?width:-width);
-
- if (hit->h<min) {
- nd.distance = min - hit->h;
- } else if (hit->h>max) {
- nd.distance = max - hit->h;
- } else {
- nd.distance = 0;
- }
- break;
- case synctex_node_type_kern:
-
- max = _synctex_data_width(node);
- if (max<0) {
- min = _synctex_data_h(node);
- max = min - max;
- } else {
- min = -max;
- max = _synctex_data_h(node);
- min += max;
- }
- med = (min+max)/2;
-
- if (hit->h<min) {
- nd.distance = min - hit->h + 1;
- } else if (hit->h>max) {
- nd.distance = max - hit->h - 1;
- } else if (hit->h>med) {
-
- nd.distance = max - hit->h + 1;
- } else {
- nd.distance = min - hit->h - 1;
- }
- break;
- case synctex_node_type_rule:
- case synctex_node_type_glue:
- case synctex_node_type_math:
- case synctex_node_type_boundary:
- case synctex_node_type_box_bdry:
- nd.distance = _synctex_data_h(node) - hit->h;
- break;
- case synctex_node_type_ref:
- nd.node = synctex_node_child(node);
- nd = _synctex_point_h_ordered_distance_v2(hit,nd.node);
- break;
- case synctex_node_type_proxy:
- case synctex_node_type_proxy_last:
- {
-
- synctex_point_s otherHit = *hit;
- otherHit.h -= _synctex_data_h(node);
- otherHit.v -= _synctex_data_v(node);
- nd.node = _synctex_tree_target(node);
- nd = _synctex_point_h_ordered_distance_v2(&otherHit,nd.node);
- nd.node = node;
- }
- default:
- break;
- }
- }
- return nd;
- }
- static synctex_nd_s _synctex_point_v_ordered_distance_v2
- (synctex_point_p hit, synctex_node_p node) {
- synctex_nd_s nd = {node, INT_MAX};
- int min,max,depth,height;
- switch(synctex_node_type(node)) {
-
- case synctex_node_type_vbox:
- case synctex_node_type_void_vbox:
- case synctex_node_type_void_hbox:
-
- min = synctex_node_v(node);
- max = min + _synctex_abs(_synctex_data_depth(node));
- min -= _synctex_abs(_synctex_data_height(node));
-
- if (hit->v<min) {
- nd.distance = min - hit->v;
- } else if (hit->v>max) {
- nd.distance = max - hit->v;
- } else {
- nd.distance = 0;
- }
- break;
- case synctex_node_type_proxy_vbox:
-
- min = synctex_node_v(node);
- max = min + _synctex_abs(synctex_node_depth(node));
- min -= _synctex_abs(synctex_node_height(node));
-
- if (hit->v<min) {
- nd.distance = min - hit->v;
- } else if (hit->v>max) {
- nd.distance = max - hit->v;
- } else {
- nd.distance = 0;
- }
- break;
- case synctex_node_type_hbox:
- case synctex_node_type_proxy_hbox:
-
- min = synctex_node_hbox_v(node);
- depth = synctex_node_hbox_depth(node);
- max = min + (depth>0?depth:-depth);
- height = synctex_node_hbox_height(node);
- min -= (height>0?height:-height);
-
- if (hit->v<min) {
- nd.distance = min - hit->v;
- } else if (hit->v>max) {
- nd.distance = max - hit->v;
- } else {
- nd.distance = 0;
- }
- break;
- case synctex_node_type_rule:
- case synctex_node_type_kern:
- case synctex_node_type_glue:
- case synctex_node_type_math:
- min = _synctex_data_v(node);
- max = min + _synctex_abs(_synctex_data_depth(_synctex_tree_parent(node)));
- min -= _synctex_abs(_synctex_data_height(_synctex_tree_parent(node)));
-
- if (hit->v<min) {
- nd.distance = min - hit->v;
- } else if (hit->v>max) {
- nd.distance = max - hit->v;
- } else {
- nd.distance = 0;
- }
- break;
- case synctex_node_type_ref:
- nd.node = synctex_node_child(node);
- nd = _synctex_point_v_ordered_distance_v2(hit,nd.node);
- break;
- case synctex_node_type_proxy:
- case synctex_node_type_proxy_last:
- {
- synctex_point_s otherHit = *hit;
- otherHit.h -= _synctex_data_h(node);
- otherHit.v -= _synctex_data_v(node);
- nd.node = _synctex_tree_target(node);
- nd = _synctex_point_v_ordered_distance_v2(&otherHit,nd.node);
- nd.node = node;
- }
- default: break;
- }
- return nd;
- }
- SYNCTEX_INLINE static synctex_node_p _synctex_smallest_container_v2(synctex_node_p node, synctex_node_p other_node) {
- long total_height, other_total_height;
- unsigned long area, other_area;
- long width = synctex_node_hbox_width(node);
- long other_width = synctex_node_hbox_width(other_node);
- if (width<0) {
- width = -width;
- }
- if (other_width<0) {
- other_width = -other_width;
- }
- total_height = _synctex_abs(synctex_node_hbox_depth(node)) + _synctex_abs(synctex_node_hbox_height(node));
- other_total_height = _synctex_abs(synctex_node_hbox_depth(other_node)) + _synctex_abs(synctex_node_hbox_height(other_node));
- area = total_height*width;
- other_area = other_total_height*other_width;
- if (area<other_area) {
- return node;
- }
- if (area>other_area) {
- return other_node;
- }
- if (_synctex_abs(_synctex_data_width(node))>_synctex_abs(_synctex_data_width(other_node))) {
- return node;
- }
- if (_synctex_abs(_synctex_data_width(node))<_synctex_abs(_synctex_data_width(other_node))) {
- return other_node;
- }
- if (total_height<other_total_height) {
- return node;
- }
- if (total_height>other_total_height) {
- return other_node;
- }
- return node;
- }
- SYNCTEX_INLINE static synctex_bool_t _synctex_point_in_box_v2(synctex_point_p hit, synctex_node_p node) {
- if (node) {
- if (0 == _synctex_point_h_ordered_distance_v2(hit,node).distance
- && 0 == _synctex_point_v_ordered_distance_v2(hit,node).distance) {
- return synctex_YES;
- }
- }
- return synctex_NO;
- }
- static int _synctex_distance_to_box_v2(synctex_point_p hit,synctex_box_p box) {
-
- if (hit->v<box->min.v) {
-
- if (hit->h<box->min.h) {
-
- return box->min.v - hit->v + box->min.h - hit->h;
- } else if (hit->h<=box->max.h) {
-
- return box->min.v - hit->v;
- } else {
-
- return box->min.v - hit->v + hit->h - box->max.h;
- }
- } else if (hit->v<=box->max.v) {
-
- if (hit->h<box->min.h) {
-
- return box->min.h - hit->h;
- } else if (hit->h<=box->max.h) {
-
- return 0;
- } else {
-
- return hit->h - box->max.h;
- }
- } else {
-
- if (hit->h<box->min.h) {
-
- return hit->v - box->max.v + box->min.h - hit->h;
- } else if (hit->h<=box->max.h) {
-
- return hit->v - box->max.v;
- } else {
-
- return hit->v - box->max.v + hit->h - box->max.h;
- }
- }
- }
- static int _synctex_point_node_distance_v2(synctex_point_p hit, synctex_node_p node) {
- int d = INT_MAX;
- if (node) {
- synctex_box_s box = {{0,0},{0,0}};
- int dd = INT_MAX;
- switch(synctex_node_type(node)) {
- case synctex_node_type_vbox:
- box.min.h = _synctex_data_h(node);
- box.max.h = box.min.h + _synctex_abs(_synctex_data_width(node));
- box.min.v = synctex_node_v(node);
- box.max.v = box.min.v + _synctex_abs(_synctex_data_depth(node));
- box.min.v -= _synctex_abs(_synctex_data_height(node));
- return _synctex_distance_to_box_v2(hit,&box);
- case synctex_node_type_proxy_vbox:
- box.min.h = synctex_node_h(node);
- box.max.h = box.min.h + _synctex_abs(synctex_node_width(node));
- box.min.v = synctex_node_v(node);
- box.max.v = box.min.v + _synctex_abs(synctex_node_depth(node));
- box.min.v -= _synctex_abs(synctex_node_height(node));
- return _synctex_distance_to_box_v2(hit,&box);
- case synctex_node_type_hbox:
- case synctex_node_type_proxy_hbox:
- box.min.h = synctex_node_hbox_h(node);
- box.max.h = box.min.h + _synctex_abs(synctex_node_hbox_width(node));
- box.min.v = synctex_node_hbox_v(node);
- box.max.v = box.min.v + _synctex_abs(synctex_node_hbox_depth(node));
- box.min.v -= _synctex_abs(synctex_node_hbox_height(node));
- return _synctex_distance_to_box_v2(hit,&box);
- case synctex_node_type_void_vbox:
- case synctex_node_type_void_hbox:
-
- box.min.h = _synctex_data_h(node);
- box.max.h = box.min.h;
- box.min.v = _synctex_data_v(node);
- box.max.v = box.min.v + _synctex_abs(_synctex_data_depth(node));
- box.min.v -= _synctex_abs(_synctex_data_height(node));
- d = _synctex_distance_to_box_v2(hit,&box);
- box.min.h = box.min.h + _synctex_abs(_synctex_data_width(node));
- box.max.h = box.min.h;
- dd = _synctex_distance_to_box_v2(hit,&box);
- return d<dd ? d:dd;
- case synctex_node_type_kern:
- box.min.h = _synctex_data_h(node);
- box.max.h = box.min.h;
- box.max.v = _synctex_data_v(node);
- box.min.v = box.max.v - _synctex_abs(_synctex_data_height(_synctex_tree_parent(node)));
- d = _synctex_distance_to_box_v2(hit,&box);
- box.min.h -= _synctex_data_width(node);
- box.max.h = box.min.h;
- dd = _synctex_distance_to_box_v2(hit,&box);
- return d<dd ? d:dd;
- case synctex_node_type_glue:
- case synctex_node_type_math:
- case synctex_node_type_boundary:
- case synctex_node_type_box_bdry:
- box.min.h = _synctex_data_h(node);
- box.max.h = box.min.h;
- box.max.v = _synctex_data_v(node);
- box.min.v = box.max.v - _synctex_abs(_synctex_data_height(_synctex_tree_parent(node)));
- return _synctex_distance_to_box_v2(hit,&box);
- case synctex_node_type_proxy:
- case synctex_node_type_proxy_last:
- {
- synctex_point_s otherHit = *hit;
- otherHit.h -= _synctex_data_h(node);
- otherHit.v -= _synctex_data_v(node);
- return _synctex_point_node_distance_v2(&otherHit, _synctex_tree_target(node));
- }
- default: break;
- }
- }
- return d;
- }
- static synctex_node_p _synctex_eq_deepest_container_v2(synctex_point_p hit, synctex_node_p node) {
- if (node) {
-
- synctex_node_p child;
- if ((child = synctex_node_child(node))) {
-
-
- do {
- if ((_synctex_point_in_box_v2(hit,child))) {
- synctex_node_p deep = _synctex_eq_deepest_container_v2(hit,child);
- if (deep) {
-
- return deep;
- }
- }
- } while((child = synctex_node_sibling(child)));
-
- if (synctex_node_type(node) == synctex_node_type_vbox
- || synctex_node_type(node) == synctex_node_type_proxy_vbox) {
-
- if ((child = _synctex_tree_child(node))) {
- synctex_nd_s best = SYNCTEX_ND_0;
- do {
- if (_synctex_tree_child(child)) {
- int d = _synctex_point_node_distance_v2(hit,child);
- if (d <= best.distance) {
- best = (synctex_nd_s){child, d};
- }
- }
- } while((child = __synctex_tree_sibling(child)));
- if (best.node) {
- return best.node;
- }
- }
- }
- if (_synctex_point_in_box_v2(hit,node)) {
- return node;
- }
- }
- }
- return NULL;
- }
- static synctex_nd_s _synctex_eq_deepest_container_v3(synctex_point_p hit, synctex_node_p node) {
- if (node) {
- synctex_node_p child = NULL;
- if ((child = synctex_node_child(node))) {
-
-
- do {
- synctex_nd_s deep = _synctex_eq_deepest_container_v3(hit, child);
- if (deep.node) {
-
- return deep;
- }
- } while((child = synctex_node_sibling(child)));
-
- if (synctex_node_type(node) == synctex_node_type_vbox
- || synctex_node_type(node) == synctex_node_type_proxy_vbox) {
- if ((child = synctex_node_child(node))) {
- synctex_nd_s best = SYNCTEX_ND_0;
- do {
- if (synctex_node_child(child)) {
- int d = _synctex_point_node_distance_v2(hit,child);
- if (d < best.distance) {
- best = (synctex_nd_s){child,d};
- }
- }
- } while((child = synctex_node_sibling(child)));
- if (best.node) {
- return best;
- }
- }
- }
-
- if (_synctex_point_in_box_v2(hit,node)) {
- return (synctex_nd_s){node, 0};
- }
- }
- }
- return SYNCTEX_ND_0;
- }
- SYNCTEX_INLINE static synctex_nd_lr_s __synctex_eq_get_closest_children_in_hbox_v2(synctex_point_p hitP, synctex_node_p node) {
- synctex_nd_s childd = SYNCTEX_ND_0;
- synctex_nd_lr_s nds = {SYNCTEX_ND_0,SYNCTEX_ND_0};
- if ((childd.node = synctex_node_child(node))) {
- synctex_nd_s nd = SYNCTEX_ND_0;
- do {
- childd = _synctex_point_h_ordered_distance_v2(hitP,childd.node);
- if (childd.distance > 0) {
-
- if (nds.r.distance > childd.distance) {
- nds.r = childd;
- } else if (nds.r.distance == childd.distance && nds.r.node) {
- if (_synctex_data_tag(nds.r.node) == _synctex_data_tag(childd.node)
- && (_synctex_data_line(nds.r.node) > _synctex_data_line(childd.node)
- || (_synctex_data_line(nds.r.node) == _synctex_data_line(childd.node)
- && _synctex_data_column(nds.r.node) > _synctex_data_column(childd.node)))) {
- nds.r = childd;
- }
- }
- } else if (childd.distance == 0) {
-
- if (_synctex_tree_child(childd.node)) {
- return _synctex_eq_get_closest_children_in_box_v2(hitP, childd.node);
- }
- nds.l = childd;
- } else {
- childd.distance = -childd.distance;
- if (nds.l.distance > childd.distance) {
- nds.l = childd;
- } else if (nds.l.distance == childd.distance && nds.l.node) {
- if (_synctex_data_tag(nds.l.node) == _synctex_data_tag(childd.node)
- && (_synctex_data_line(nds.l.node) > _synctex_data_line(childd.node)
- || (_synctex_data_line(nds.l.node) == _synctex_data_line(childd.node)
- && _synctex_data_column(nds.l.node) > _synctex_data_column(childd.node)))) {
- nds.l = childd;
- }
- }
- }
- } while((childd.node = synctex_node_sibling(childd.node)));
- if (nds.l.node) {
-
- if ((nd = _synctex_eq_deepest_container_v3(hitP,nds.l.node)).node) {
- nds.l = nd;
- }
- if((nd = __synctex_closest_deep_child_v2(hitP,nds.l.node)).node) {
- nds.l.node = nd.node;
- }
- }
- if (nds.r.node) {
-
- if ((nd = _synctex_eq_deepest_container_v3(hitP,nds.r.node)).node) {
- nds.r = nd;
- }
- if((nd = __synctex_closest_deep_child_v2(hitP,nds.r.node)).node) {
- nds.r.node = nd.node;
- }
- }
- }
- return nds;
- }
- SYNCTEX_INLINE static synctex_nd_lr_s __synctex_eq_get_closest_children_in_hbox_v3(synctex_point_p hitP, synctex_node_p nodeP) {
- synctex_nd_s nd = SYNCTEX_ND_0;
- synctex_nd_lr_s nds = {SYNCTEX_ND_0,SYNCTEX_ND_0};
- if ((nd.node = _synctex_tree_child(nodeP))) {
- do {
- nd = _synctex_point_h_ordered_distance_v2(hitP,nd.node);
- if (nd.distance > 0) {
-
- if (nds.r.distance > nd.distance) {
- nds.r = nd;
- } else if (nds.r.distance == nd.distance && nds.r.node) {
- if (_synctex_data_tag(nds.r.node) == _synctex_data_tag(nd.node)
- && (_synctex_data_line(nds.r.node) > _synctex_data_line(nd.node)
- || (_synctex_data_line(nds.r.node) == _synctex_data_line(nd.node)
- && _synctex_data_column(nds.r.node) > _synctex_data_column(nd.node)))) {
- nds.r = nd;
- }
- }
- } else if (nd.distance == 0) {
-
- nds.l = nd;
- } else {
- nd.distance = -nd.distance;
- if (nds.l.distance > nd.distance) {
- nds.l = nd;
- } else if (nds.l.distance == nd.distance && nds.l.node) {
- if (_synctex_data_tag(nds.l.node) == _synctex_data_tag(nd.node)
- && (_synctex_data_line(nds.l.node) > _synctex_data_line(nd.node)
- || (_synctex_data_line(nds.l.node) == _synctex_data_line(nd.node)
- && _synctex_data_column(nds.l.node) > _synctex_data_column(nd.node)))) {
- nds.l = nd;
- }
- }
- }
- } while((nd.node = __synctex_tree_sibling(nd.node)));
- if (nds.l.node) {
-
- if ((nd.node = _synctex_eq_deepest_container_v2(hitP,nds.l.node))) {
- nds.l.node = nd.node;
- }
- if((nd = _synctex_eq_closest_child_v2(hitP,nds.l.node)).node) {
- nds.l.node = nd.node;
- }
- }
- if (nds.r.node) {
-
- if ((nd.node = _synctex_eq_deepest_container_v2(hitP,nds.r.node))) {
- nds.r.node = nd.node;
- }
- if((nd = _synctex_eq_closest_child_v2(hitP,nds.r.node)).node) {
- nds.r.node = nd.node;
- }
- }
- }
- return nds;
- }
- SYNCTEX_INLINE static synctex_nd_lr_s __synctex_eq_get_closest_children_in_vbox_v2(synctex_point_p hitP, synctex_node_p nodeP) {
- SYNCTEX_UNUSED(nodeP)
- synctex_nd_lr_s nds = {SYNCTEX_ND_0,SYNCTEX_ND_0};
- synctex_nd_s nd = SYNCTEX_ND_0;
- if ((nd.node = synctex_node_child(nd.node))) {
- do {
- nd = _synctex_point_v_ordered_distance_v2(hitP,nd.node);
-
- if (nd.distance > 0) {
-
- if (nds.r.distance > nd.distance) {
- nds.r = nd;
- } else if (nds.r.distance == nd.distance && nds.r.node) {
- if (_synctex_data_tag(nds.r.node) == _synctex_data_tag(nd.node)
- && (_synctex_data_line(nds.r.node) > _synctex_data_line(nd.node)
- || (_synctex_data_line(nds.r.node) == _synctex_data_line(nd.node)
- && _synctex_data_column(nds.r.node) > _synctex_data_column(nd.node)))) {
- nds.r = nd;
- }
- }
- } else if (nd.distance == 0) {
- nds.l = nd;
- } else {
- nd.distance = -nd.distance;
- if (nds.l.distance > nd.distance) {
- nds.l = nd;
- } else if (nds.l.distance == nd.distance && nds.l.node) {
- if (_synctex_data_tag(nds.l.node) == _synctex_data_tag(nd.node)
- && (_synctex_data_line(nds.l.node) > _synctex_data_line(nd.node)
- || (_synctex_data_line(nds.l.node) == _synctex_data_line(nd.node)
- && _synctex_data_column(nds.l.node) > _synctex_data_column(nd.node)))) {
- nds.l = nd;
- }
- }
- }
- } while((nd.node = synctex_node_sibling(nd.node)));
- if (nds.l.node) {
- if ((nd.node = _synctex_eq_deepest_container_v2(hitP,nds.l.node))) {
- nds.l.node = nd.node;
- }
- if((nd = _synctex_eq_closest_child_v2(hitP,nds.l.node)).node) {
- nds.l.node = nd.node;
- }
- }
- if (nds.r.node) {
- if ((nd.node = _synctex_eq_deepest_container_v2(hitP,nds.r.node))) {
- nds.r.node = nd.node;
- }
- if((nd = _synctex_eq_closest_child_v2(hitP,nds.r.node)).node) {
- nds.r.node = nd.node;
- }
- }
- }
- return nds;
- }
- static synctex_nd_s __synctex_closest_deep_child_v2(synctex_point_p hitP, synctex_node_p node) {
- synctex_nd_s best = SYNCTEX_ND_0;
- synctex_node_p child = NULL;
- if ((child = synctex_node_child(node))) {
- printf("Closest deep child on box at line %i\n",
- SYNCTEX_LINEINDEX(node));
- do {
- synctex_node_display(child);
- synctex_nd_s nd = SYNCTEX_ND_0;
- if (_synctex_node_is_box(child)) {
- nd = __synctex_closest_deep_child_v2(hitP,child);
- } else {
- nd = (synctex_nd_s) {child, _synctex_point_node_distance_v2(hitP,child)};
- }
- if (nd.distance < best.distance ||(nd.distance == best.distance
- && synctex_node_type(nd.node) != synctex_node_type_kern)) {
- if(nd.node) {
- printf("New best %i<=%i line %i\n",nd.distance,
- best.distance,SYNCTEX_LINEINDEX(nd.node));
- }
- best = nd;
- }
- } while((child = synctex_node_sibling(child)));
- if(best.node) {
- printf("Found new best %i line %i\n",best.distance,SYNCTEX_LINEINDEX(best.node));
- }
- }
- return best;
- }
- static synctex_nd_s _synctex_eq_closest_child_v2(synctex_point_p hitP, synctex_node_p node) {
- synctex_nd_s nd = SYNCTEX_ND_0;
- if (_synctex_node_is_box(node)) {
- nd = __synctex_closest_deep_child_v2(hitP, node);
- if (_synctex_node_is_box(nd.node)) {
- synctex_node_p child = NULL;
- if ((child = synctex_node_child(nd.node))) {
- synctex_nd_s best = {child,_synctex_point_node_distance_v2(hitP,child)};
- while((child = synctex_node_sibling(child))) {
- int d = _synctex_point_node_distance_v2(hitP,child);
- if (d < best.distance) {
- best = (synctex_nd_s){child,d};
- } else if (d == best.distance && synctex_node_type(child) != synctex_node_type_kern) {
- best.node = child;
- }
- }
- return best;
- }
- }
- return nd;
- }
- return SYNCTEX_ND_0;
- }
- SYNCTEX_INLINE static synctex_nd_lr_s _synctex_eq_get_closest_children_in_box_v2(synctex_point_p hitP, synctex_node_p node) {
- synctex_nd_lr_s nds = {SYNCTEX_ND_0,SYNCTEX_ND_0};
- if(_synctex_tree_has_child(node)) {
- if (node->class_->type==synctex_node_type_hbox ||
- node->class_->type==synctex_node_type_proxy_hbox) {
- return __synctex_eq_get_closest_children_in_hbox_v2(hitP,node);
- } else {
- return __synctex_eq_get_closest_children_in_vbox_v2(hitP,node);
- }
- }
- return nds;
- }
- typedef int (*synctex_print_f)(synctex_updater_p, const char * , ...);
- typedef void (*synctex_close_f)(synctex_updater_p);
- typedef union {
- gzFile as_gzFile;
- FILE * as_FILE_p;
- void * as_ptr;
- } syncex_file_u;
- struct synctex_updater_t {
- syncex_file_u file;
- synctex_print_f print;
- synctex_close_f close;
- int length;
- };
- static int _synctex_updater_print(synctex_updater_p updater, const char * format, ...) {
- int result = 0;
- if (updater) {
- va_list va;
- va_start(va, format);
- result = vfprintf(updater->file.as_FILE_p,
- format,
- va);
- va_end(va);
- }
- return result;
- }
- static int vasprintf(char **ret,
- const char *format,
- va_list ap)
- {
- int len;
- len = _vsnprintf(NULL, 0, format, ap);
- if (len < 0) return -1;
- *ret = malloc(len + 1);
- if (!*ret) return -1;
- _vsnprintf(*ret, len+1, format, ap);
- (*ret)[len] = '\0';
- return len;
- }
- static int _synctex_updater_print_gz(synctex_updater_p updater, const char * format, ...) {
- int result = 0;
- if (updater) {
- char * buffer;
- va_list va;
- va_start(va, format);
- if (vasprintf(&buffer, format, va) < 0) {
- _synctex_error("Out of memory...");
- } else if ((result = (int)strlen(buffer))) {
- result = gzwrite(updater->file.as_gzFile, buffer, (unsigned)result);
- }
- va_end(va);
- free(buffer);
- }
- return result;
- }
- static void _synctex_updater_close(synctex_updater_p updater) {
- if (updater) {
- fclose(updater->file.as_FILE_p);
- }
- }
- static void _synctex_updater_close_gz(synctex_updater_p updater) {
- if (updater) {
- gzclose(updater->file.as_gzFile);
- }
- }
- synctex_updater_p synctex_updater_new_with_output_file(const char * output, const char * build_directory) {
- synctex_updater_p updater = NULL;
- const char * mode = NULL;
- synctex_open_s open;
-
- updater = (synctex_updater_p)_synctex_malloc(sizeof(synctex_updater_s));
- if (NULL == updater) {
- _synctex_error("! synctex_updater_new_with_file: malloc problem");
- return NULL;
- }
- open = _synctex_open_v2(output,build_directory,0,synctex_ADD_QUOTES);
- if (open.status < SYNCTEX_STATUS_OK) {
- open = _synctex_open_v2(output,build_directory,0,synctex_DONT_ADD_QUOTES);
- if (open.status < SYNCTEX_STATUS_OK) {
- return_on_error:
- _synctex_free(updater);
- return updater = NULL;
- }
- }
-
- gzclose(open.file);
- updater->file.as_ptr = NULL;
- mode = _synctex_get_io_mode_name(open.io_mode|synctex_io_append_mask);
- if (open.io_mode&synctex_io_gz_mask) {
- if (NULL == (updater->file.as_FILE_p = fopen(open.synctex,mode))) {
- no_write_error:
- _synctex_error("! synctex_updater_new_with_file: Can't append to %s",open.synctex);
- free(open.synctex);
- goto return_on_error;
- }
- updater->print = &_synctex_updater_print;
- updater->close = &_synctex_updater_close;
- } else {
- if (NULL == (updater->file.as_gzFile = gzopen(open.synctex,mode))) {
- goto no_write_error;
- }
- updater->print = &_synctex_updater_print_gz;
- updater->close = &_synctex_updater_close_gz;
- }
- printf("SyncTeX: updating %s...",open.synctex);
- _synctex_free(open.synctex);
- return updater;
- }
- void synctex_updater_append_magnification(synctex_updater_p updater, char * magnification){
- if (NULL==updater) {
- return;
- }
- if (magnification && strlen(magnification)) {
- updater->length +=
- updater->print(updater,"Magnification:%s\n",magnification);
- }
- }
- void synctex_updater_append_x_offset(synctex_updater_p updater, char * x_offset){
- if (NULL==updater) {
- return;
- }
- if (x_offset && strlen(x_offset)) {
- updater->length += updater->print(updater,"X Offset:%s\n",x_offset);
- }
- }
- void synctex_updater_append_y_offset(synctex_updater_p updater, char * y_offset){
- if (NULL==updater) {
- return;
- }
- if (y_offset && strlen(y_offset)) {
- updater->length += updater->print(updater,"Y Offset:%s\n",y_offset);
- }
- }
- void synctex_updater_free(synctex_updater_p updater){
- if (NULL==updater) {
- return;
- }
- if (updater->length>0) {
- updater->print(updater,"!%i\n",updater->length);
- }
- updater->close(updater);
- _synctex_free(updater);
- printf("... done.\n");
- return;
- }
- static synctex_node_p _synctex_node_next(synctex_node_p node) {
- synctex_node_p N = _synctex_tree_child(node);
- if (N) {
- return N;
- }
- return _synctex_node_sibling_or_parents(node);
- }
- static int _synctex_input_copy_name(synctex_node_p input, char * name) {
- char * copy = _synctex_malloc(strlen(name)+1);
- memcpy(copy,name,strlen(name)+1);
- _synctex_data_set_name(input,copy);
- return 0;
- }
- int synctex_test_setup_scanner_sheets_421(synctex_scanner_p scanner) {
- int TC = 0;
- synctex_node_p sheet = synctex_node_new(scanner,synctex_node_type_sheet);
- _synctex_data_set_page(sheet,4);
- SYNCTEX_TEST_BODY(TC, _synctex_data_page(sheet)==4,"");
- synctex_node_free(scanner->sheet);
- scanner->sheet = sheet;
- sheet = synctex_node_new(scanner,synctex_node_type_sheet);
- _synctex_data_set_page(sheet,2);
- SYNCTEX_TEST_BODY(TC, _synctex_data_page(sheet)==2,"");
- __synctex_tree_set_sibling(sheet, scanner->sheet);
- scanner->sheet = sheet;
- sheet = synctex_node_new(scanner,synctex_node_type_sheet);
- _synctex_data_set_page(sheet,1);
- SYNCTEX_TEST_BODY(TC, _synctex_data_page(sheet)==1,"");
- __synctex_tree_set_sibling(sheet, scanner->sheet);
- scanner->sheet = sheet;
- return TC;
- }
- int synctex_test_input(synctex_scanner_p scanner) {
- int TC = 0;
- synctex_node_p input = synctex_node_new(scanner,synctex_node_type_input);
- _synctex_data_set_tag(input,421);
- SYNCTEX_TEST_BODY(TC, _synctex_data_tag(input)==421,"");
- _synctex_data_set_tag(input,124);
- SYNCTEX_TEST_BODY(TC, _synctex_data_tag(input)==124,"");
- _synctex_data_set_line(input,421);
- SYNCTEX_TEST_BODY(TC, _synctex_data_line(input)==421,"");
- _synctex_data_set_line(input,214);
- SYNCTEX_TEST_BODY(TC, _synctex_data_line(input)==214,"");
- _synctex_data_set_line(input,214);
- SYNCTEX_TEST_BODY(TC, _synctex_data_line(input)==214,"");
- _synctex_input_copy_name(input,"214");
- SYNCTEX_TEST_BODY(TC, 0==memcmp(_synctex_data_name(input),"214",4),"");
- _synctex_input_copy_name(input,"421421");
- SYNCTEX_TEST_BODY(TC,
- 0==memcmp(_synctex_data_name(input),
- "421421",
- 4),
- "");
- synctex_node_free(input);
- return TC;
- }
- int synctex_test_proxy(synctex_scanner_p scanner) {
- int TC = 0;
- synctex_node_p proxy = synctex_node_new(scanner,synctex_node_type_proxy);
- synctex_node_p target = synctex_node_new(scanner,synctex_node_type_rule);
- _synctex_tree_set_target(proxy,target);
- _synctex_data_set_tag(target,421);
- SYNCTEX_TEST_BODY(TC, _synctex_data_tag(target)==421,"");
- SYNCTEX_TEST_BODY(TC, synctex_node_tag(target)==421,"");
- SYNCTEX_TEST_BODY(TC, synctex_node_tag(proxy)==421,"");
- synctex_node_free(proxy);
- synctex_node_free(target);
- return TC;
- }
- int synctex_test_handle(synctex_scanner_p scanner) {
- int TC = 0;
- synctex_node_p handle = synctex_node_new(scanner,synctex_node_type_handle);
- synctex_node_p proxy = synctex_node_new(scanner, synctex_node_type_proxy);
- synctex_node_p target = synctex_node_new(scanner,synctex_node_type_rule);
- _synctex_tree_set_target(handle,target);
- _synctex_data_set_tag(target,421);
- SYNCTEX_TEST_BODY(TC, _synctex_data_tag(target)==421,"");
- SYNCTEX_TEST_BODY(TC, synctex_node_tag(target)==421,"");
- SYNCTEX_TEST_BODY(TC, synctex_node_tag(handle)==421,"");
- _synctex_data_set_line(target,214);
- SYNCTEX_TEST_BODY(TC, _synctex_data_line(target)==214,"");
- SYNCTEX_TEST_BODY(TC, synctex_node_line(target)==214,"");
- SYNCTEX_TEST_BODY(TC, synctex_node_line(handle)==214,"");
- _synctex_data_set_column(target,142);
- SYNCTEX_TEST_BODY(TC, _synctex_data_column(target)==142,"");
- SYNCTEX_TEST_BODY(TC, synctex_node_column(target)==142,"");
- SYNCTEX_TEST_BODY(TC, synctex_node_column(handle)==142,"");
- _synctex_tree_set_target(proxy,target);
- _synctex_tree_set_target(handle,proxy);
- _synctex_data_set_tag(target,412);
- SYNCTEX_TEST_BODY(TC, _synctex_data_tag(target)==412,"");
- SYNCTEX_TEST_BODY(TC, synctex_node_tag(target)==412,"");
- SYNCTEX_TEST_BODY(TC, synctex_node_tag(handle)==412,"");
- _synctex_data_set_line(target,124);
- SYNCTEX_TEST_BODY(TC, _synctex_data_line(target)==124,"");
- SYNCTEX_TEST_BODY(TC, synctex_node_line(target)==124,"");
- SYNCTEX_TEST_BODY(TC, synctex_node_line(handle)==124,"");
- _synctex_data_set_column(target,241);
- SYNCTEX_TEST_BODY(TC, _synctex_data_column(target)==241,"");
- SYNCTEX_TEST_BODY(TC, synctex_node_column(target)==241,"");
- SYNCTEX_TEST_BODY(TC, synctex_node_column(handle)==241,"");
- synctex_node_free(handle);
- synctex_node_free(proxy);
- synctex_node_free(target);
- return TC;
- }
- int synctex_test_setup_scanner_input(synctex_scanner_p scanner) {
- int TC = 0;
- synctex_node_p input = synctex_node_new(scanner,synctex_node_type_input);
- _synctex_data_set_tag(input,4);
- _synctex_input_copy_name(input,"21");
- _synctex_data_set_line(input,421);
- synctex_node_free(scanner->input);
- scanner->input = input;
- SYNCTEX_TEST_BODY(TC, _synctex_data_tag(input)==4,"");
- SYNCTEX_TEST_BODY(TC, strcmp(_synctex_data_name(input),"21")==0,"");
- SYNCTEX_TEST_BODY(TC, _synctex_data_line(input)==421,"");
- return TC;
- }
- int synctex_test_setup_nodes(synctex_scanner_p scanner, synctex_node_r nodes) {
- int TC = 0;
- int n;
- for (n=0;n<synctex_node_number_of_types;++n) {
- nodes[n] = synctex_node_new(scanner,n);
- SYNCTEX_TEST_BODY(TC, nodes[n]!=NULL,"");
- }
- return TC;
- }
- int synctex_test_teardown_nodes(synctex_scanner_p scanner, synctex_node_r nodes) {
- int n;
- for (n=0;n<synctex_node_number_of_types;++n) {
- synctex_node_free(nodes[n]);
- nodes[n]=NULL;
- }
- return 1;
- }
- int synctex_test_tree(synctex_scanner_p scanner) {
- int TC = 0;
- synctex_node_p nodes1[synctex_node_number_of_types];
- synctex_node_p nodes2[synctex_node_number_of_types];
- synctex_node_p nodes3[synctex_node_number_of_types];
- int i,j;
- TC += synctex_test_setup_nodes(scanner,nodes1);
- TC += synctex_test_setup_nodes(scanner,nodes2);
- TC += synctex_test_setup_nodes(scanner,nodes3);
-
- for (i=0;i<synctex_node_number_of_types;++i) {
- for (j=0;j<synctex_node_number_of_types;++j) {
- _synctex_tree_set_sibling(nodes1[i],nodes2[i]);
- SYNCTEX_TEST_BODY(TC, nodes2[i]==synctex_node_sibling(nodes1[i]),"");
- }
- }
- synctex_test_teardown_nodes(scanner,nodes3);
- synctex_test_teardown_nodes(scanner,nodes2);
- synctex_test_teardown_nodes(scanner,nodes1);
- return TC;
- }
- int synctex_test_page(synctex_scanner_p scanner) {
- int TC = synctex_test_setup_scanner_sheets_421(scanner);
- synctex_node_p sheet = scanner->sheet;
- synctex_node_p node = synctex_node_new(scanner,synctex_node_type_rule);
- _synctex_data_set_tag(node,4);
- _synctex_data_set_line(node,21);
- synctex_node_free(_synctex_node_set_child(sheet,node));
- SYNCTEX_TEST_BODY(TC, synctex_node_page(node)==synctex_node_page(sheet),"");
- return TC;
- }
- int synctex_test_display_query(synctex_scanner_p scanner) {
- int TC = synctex_test_setup_scanner_sheets_421(scanner);
- synctex_node_p sheet = scanner->sheet;
- synctex_node_p node = synctex_node_new(scanner,synctex_node_type_rule);
- _synctex_data_set_tag(node,4);
- _synctex_data_set_line(node,21);
- synctex_node_free(_synctex_node_set_child(sheet,node));
- SYNCTEX_TEST_BODY(TC, node==synctex_node_child(sheet),"");
- __synctex_node_make_friend_tlc(node);
- SYNCTEX_TEST_BODY(TC, _synctex_scanner_friend(scanner, 25)==node,"");
- sheet = __synctex_tree_sibling(sheet);
- node = synctex_node_new(scanner,synctex_node_type_rule);
- _synctex_data_set_tag(node,4);
- _synctex_data_set_line(node,21);
- synctex_node_free(_synctex_node_set_child(sheet,node));
- SYNCTEX_TEST_BODY(TC, node==synctex_node_child(sheet),"");
- __synctex_node_make_friend_tlc(node);
- SYNCTEX_TEST_BODY(TC, _synctex_scanner_friend(scanner, 25)==node,"");
- sheet = __synctex_tree_sibling(sheet);
- node = synctex_node_new(scanner,synctex_node_type_rule);
- _synctex_data_set_tag(node,4);
- _synctex_data_set_line(node,21);
- synctex_node_free(_synctex_node_set_child(sheet,node));
- SYNCTEX_TEST_BODY(TC, node==synctex_node_child(sheet),"");
- __synctex_node_make_friend_tlc(node);
- SYNCTEX_TEST_BODY(TC, (_synctex_scanner_friend(scanner, 25)==node),"");
- synctex_test_setup_scanner_input(scanner);
- scanner->flags.has_parsed = synctex_YES;
- SYNCTEX_TEST_BODY(TC, (synctex_display_query(scanner,"21",21,4,-1)==3),"");
- return TC;
- }
- typedef struct {
- int s;
- char n[25];
- } synctex_test_sn_s;
- synctex_test_sn_s synctex_test_tmp_sn(char * content) {
- synctex_test_sn_s sn = {0, "/tmp/test.XXXXXX.synctex"};
- FILE *sfp;
- int fd = mkstemps(sn.n,8);
- if (fd < 0) {
- fprintf(stderr, "%s: %s\n", sn.n, strerror(errno));
- sn.s = -1;
- return sn;
- }
- if ((sfp = fdopen(fd, "w+")) == NULL) {
- unlink(sn.n);
- close(fd);
- fprintf(stderr, "%s: %s\n", sn.n, strerror(errno));
- sn.s = -2;
- return sn;
- }
- sn.s = fputs(content,sfp);
- printf("temp:%s\n%i\n",sn.n,sn.s);
- fclose(sfp);
- if (sn.s==0) {
- sn.s = -2;
- unlink(sn.n);
- }
- return sn;
- }
- int synctex_test_sheet_1() {
- int TC = 0;
- char * content =
- "SyncTeX Version:1 \n"
- "Input:1:./1.tex \n"
- "Output:pdf \n"
- "Magnification:100000000 \n"
- "Unit:1 \n"
- "X Offset:0 \n"
- "Y Offset:0 \n"
- "Content: \n"
- "{1 \n"
- "[1,10:20,350:330,330,0 \n"
- "] \n"
- "} \n"
- "Postamble:\n";
- synctex_test_sn_s sn = synctex_test_tmp_sn(content);
- if (sn.s>0) {
- synctex_scanner_p scanner = synctex_scanner_new_with_output_file(sn.n, NULL, synctex_YES);
- synctex_node_p node = synctex_scanner_handle(scanner);
- printf("Created nodes:\n");
- while (node) {
- printf("%s\n",_synctex_node_abstract(node));
- node = synctex_node_next(node);
- }
- synctex_scanner_free(scanner);
- unlink(sn.n);
- } else {
- ++TC;
- }
- return TC;
- }
- int synctex_test_sheet_2() {
- int TC = 0;
- char * content =
- "SyncTeX Version:1 \n"
- "Input:1:./1.tex \n"
- "Output:pdf \n"
- "Magnification:100000000 \n"
- "Unit:1 \n"
- "X Offset:0 \n"
- "Y Offset:0 \n"
- "Content: \n"
- "{1 \n"
- "(1,10:20,350:330,330,0 \n"
- ") \n"
- "} \n"
- "Postamble:\n";
- synctex_test_sn_s sn = synctex_test_tmp_sn(content);
- if (sn.s>0) {
- synctex_scanner_p scanner = synctex_scanner_new_with_output_file(sn.n, NULL, synctex_YES);
- synctex_node_p node = synctex_scanner_handle(scanner);
- printf("Created nodes:\n");
- while (node) {
- printf("%s\n",_synctex_node_abstract(node));
- node = _synctex_node_next(node);
- }
- TC += synctex_scanner_free(scanner);
- unlink(sn.n);
- } else {
- ++TC;
- }
- return TC;
- }
- int synctex_test_charindex() {
- int TC = 0;
- char * content =
- "SyncTeX Version:1 \n"
- "Input:1:./1.tex \n"
- "Output:pdf \n"
- "Magnification:100000000 \n"
- "Unit:1 \n"
- "X Offset:0 \n"
- "Y Offset:0 \n"
- "Content: \n"
- "{1 \n"
- "[1,10:20,350:330,330,0 \n"
- "(1,58:20,100:250,10,5 \n"
- "f1000:50,100 \n"
- ") \n"
- "] \n"
- "} \n"
- "Postamble:\n";
- synctex_test_sn_s sn = synctex_test_tmp_sn(content);
- if (sn.s>0) {
- synctex_scanner_p scanner = synctex_scanner_new_with_output_file(sn.n, NULL, synctex_YES);
- synctex_node_p node = synctex_scanner_handle(scanner);
- printf("Created nodes:\n");
- while (node) {
- printf("%s\n",_synctex_node_abstract(node));
- node = synctex_node_next(node);
- }
- TC += synctex_scanner_free(scanner);
- unlink(sn.n);
- } else {
- ++TC;
- }
- return TC;
- }
- int synctex_test_form() {
- int TC = 0;
- char * content =
- "SyncTeX Version:1 \n"
- "Input:1:./1.tex \n"
- "Output:pdf \n"
- "Magnification:100000000 \n"
- "Unit:1 \n"
- "X Offset:0 \n"
- "Y Offset:0 \n"
- "Content: \n"
- "{1 \n"
- "[1,10:20,350:330,330,0 \n"
- "(1,58:20,100:250,10,5 \n"
- "f1000:50,100 \n"
- ") \n"
- "] \n"
- "} \n"
- "<1000 \n"
- "(1,63:0,0:100,8,3 \n"
- ") \n"
- "> \n"
- "Postamble:\n";
- synctex_test_sn_s sn = synctex_test_tmp_sn(content);
- if (sn.s>0) {
- synctex_scanner_p scanner = synctex_scanner_new_with_output_file(sn.n, NULL, synctex_YES);
- synctex_node_p node = synctex_scanner_handle(scanner);
- while (node) {
- printf("%s\n",_synctex_node_abstract(node));
- node = _synctex_node_next(node);
- }
- TC += synctex_scanner_free(scanner);
- unlink(sn.n);
- } else {
- ++TC;
- }
- return TC;
- }
|