WmResParse.c 139 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * (c) Copyright 1989, 1990, 1991, 1992, 1993, 1994 OPEN SOFTWARE FOUNDATION, INC.
  25. * ALL RIGHTS RESERVED
  26. */
  27. /*
  28. * Motif Release 1.2.4
  29. */
  30. /*
  31. * (c) Copyright 1987, 1988, 1989, 1990, 1993, 1994 Hewlett-Packard Company
  32. * (c) Copyright 1993, 1994 International Business Machines Corp.
  33. * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  34. * (c) Copyright 1993, 1994 Novell, Inc.
  35. */
  36. /*
  37. * (c) Copyright 1987, 1988 DIGITAL EQUIPMENT CORPORATION */
  38. /*
  39. * (c) Copyright 1988 MASSACHUSETTS INSTITUTE OF TECHNOLOGY */
  40. /*
  41. * Included Files:
  42. */
  43. #include "WmGlobal.h"
  44. #include "WmResNames.h"
  45. #include <Dt/UserMsg.h>
  46. #include <Dt/Connect.h>
  47. #include <Tt/tt_c.h>
  48. #include "WmParse.h"
  49. #include "WmParseP.h"
  50. #include "WmPanelP.h"
  51. #include "WmResource.h"
  52. #include <codelibs/shellutils.h> /* shellscan */
  53. #include <Xm/VirtKeysP.h>
  54. #include <Xm/XmPrivate.h> /* _XmVirtKeysLoadFileBindings,
  55. * _XmVirtKeysLoadFallbackBindings */
  56. #include <X11/cursorfont.h>
  57. #include <X11/keysym.h>
  58. #include <X11/Xatom.h>
  59. #include <ctype.h>
  60. #include <locale.h>
  61. #include <stdlib.h>
  62. #include <Xm/XmP.h> /* for XmeGetHomeDirName */
  63. #include <signal.h>
  64. /* maximum string lengths */
  65. #define MAX_KEYSYM_STRLEN 100
  66. #define MAX_EVENTTYPE_STRLEN 20
  67. #define MAX_MODIFIER_STRLEN 20
  68. #define MAX_CONTEXT_STRLEN 20
  69. #define MAX_GROUP_STRLEN 20
  70. #define min(a,b) ((a)>(b) ? (b) : (a))
  71. #define MAXLINE (MAXWMPATH+1)
  72. #define MBBSIZ 4096
  73. #define PARSE_MENU_ITEMS(pSD, mSpec) ParseMenuItems(pSD)
  74. /*
  75. * include extern functions
  76. */
  77. #include "WmResParse.h"
  78. #include "WmWrkspace.h"
  79. #include "WmError.h"
  80. #include "WmFunction.h"
  81. #include "WmImage.h"
  82. #include "WmXSMP.h"
  83. # include <errno.h>
  84. # ifdef X_NOT_STDC_ENV
  85. extern int errno;
  86. # endif
  87. # define HOME_DT_WMRC "/.dt/dtwmrc"
  88. # define LANG_DT_WMRC "/dtwmrc"
  89. # define SYS_DT_WMRC CDE_CONFIGURATION_TOP "/sys.dtwmrc"
  90. /*
  91. * Global Variables And Tables:
  92. */
  93. static char cfileName[MAXWMPATH+1];
  94. #ifndef NO_MESSAGE_CATALOG
  95. char * pWarningStringFile;
  96. char * pWarningStringLine;
  97. #else
  98. char pWarningStringFile[] = "%s: %s on line %d of configuration file %s\n";
  99. char pWarningStringLine[] = "%s: %s on line %d of specification string\n";
  100. #endif
  101. #define cfileP (wmGD.pWmPB->pFile)
  102. #define parseP (wmGD.pWmPB->pchNext)
  103. #define line (wmGD.pWmPB->pchLine)
  104. #define linec (wmGD.pWmPB->lineNumber)
  105. typedef struct {
  106. char *name;
  107. unsigned int mask;
  108. } MaskTableEntry;
  109. static MaskTableEntry modifierStrings[] = {
  110. {"none", None},
  111. {"ctrl", ControlMask},
  112. {"shift", ShiftMask},
  113. {"alt", Mod1Mask},
  114. {"meta", Mod1Mask},
  115. {"lock", LockMask},
  116. {"mod1", Mod1Mask},
  117. {"mod2", Mod2Mask},
  118. {"mod3", Mod3Mask},
  119. {"mod4", Mod4Mask},
  120. {"mod5", Mod5Mask},
  121. {NULL, 0},
  122. };
  123. #define ALT_INDEX 3
  124. #define META_INDEX 4
  125. typedef struct {
  126. char *event;
  127. unsigned int eventType;
  128. Boolean (*parseProc)();
  129. unsigned int closure;
  130. Boolean fClick;
  131. } EventTableEntry;
  132. static String GetNetworkFileName (char *pchFile);
  133. FILE *FopenConfigFile (void);
  134. void SaveMenuAccelerators (WmScreenData *pSD, MenuSpec *newMenuSpec);
  135. static void ParseMenuSet (WmScreenData *pSD, unsigned char *lineP);
  136. MenuItem *ParseMwmMenuStr (WmScreenData *pSD, unsigned char *menuStr);
  137. static MenuItem *ParseMenuItems (WmScreenData *pSD);
  138. static Boolean ParseWmLabel (WmScreenData *pSD, MenuItem *menuItem,
  139. unsigned char *string);
  140. static void ParseWmMnemonic (unsigned char **linePP, MenuItem *menuItem);
  141. static Boolean ParseWmAccelerator (unsigned char **linePP, MenuItem *menuItem);
  142. int ParseWmFunction (unsigned char **linePP, unsigned int res_spec,
  143. WmFunction *pWmFunction);
  144. static Boolean ParseWmFuncNoArg (unsigned char **linePP, WmFunction wmFunction,
  145. String *pArgs);
  146. void FreeMenuItem (MenuItem *menuItem);
  147. static Boolean ParseWmFuncGrpArg (unsigned char **linePP,
  148. WmFunction wmFunction, GroupArg *pGroup);
  149. static Boolean ParseWmFuncNbrArg (unsigned char **linePP,
  150. WmFunction wmFunction,
  151. unsigned long *pNumber);
  152. void ParseButtonStr (WmScreenData *pSD, unsigned char *buttonStr);
  153. static void ParseButtonSet (WmScreenData *pSD, unsigned char *lineP);
  154. static Boolean ParseContext (unsigned char **linePP, Context *context,
  155. Context *subContext);
  156. void
  157. ParseKeyStr (WmScreenData *pSD, unsigned char *keyStr);
  158. static void ParseKeySet (WmScreenData *pSD, unsigned char *lineP);
  159. Boolean ParseBtnEvent (unsigned char **linePP,
  160. unsigned int *eventType,
  161. unsigned int *button,
  162. unsigned int *state,
  163. Boolean *fClick);
  164. Boolean ParseKeyEvent (unsigned char **linePP, unsigned int *eventType,
  165. KeyCode *keyCode, unsigned int *state);
  166. static Boolean ParseEvent (unsigned char **linePP, EventTableEntry *table,
  167. unsigned int *eventType, unsigned int *detail,
  168. unsigned int *state, Boolean *fClick);
  169. static Boolean ParseModifiers(unsigned char **linePP, unsigned int *state);
  170. static Boolean LookupModifier (unsigned char *name, unsigned int *valueP);
  171. static Boolean ParseEventType (unsigned char **linePP, EventTableEntry *table,
  172. unsigned int *eventType, Cardinal *ix);
  173. static Boolean ParseImmed (unsigned char **linePP, unsigned int closure,
  174. unsigned int *detail);
  175. static Boolean ParseKeySym (unsigned char **linePP, unsigned int closure,
  176. unsigned int *detail);
  177. static unsigned int StrToNum(unsigned char *str);
  178. static unsigned int StrToHex(unsigned char *str);
  179. static unsigned int StrToOct(unsigned char *str);
  180. void ScanAlphanumeric (unsigned char **linePP);
  181. void ScanWhitespace(unsigned char **linePP);
  182. void ToLower (char *string);
  183. void
  184. PWarning (char *message);
  185. static void ProcessAccelText (unsigned char *startP, unsigned char *endP,
  186. unsigned char *destP);
  187. void ProcessCommandLine (int argc, char *argv[]);
  188. static void ParseScreensArgument (int argc, char *argv[], int *pArgnum,
  189. unsigned char *lineP);
  190. void ProcessMotifBindings (void);
  191. static void ParseIncludeSet (WmScreenData *pSD, unsigned char *lineP);
  192. static void ConfigStackInit (char *pchFileName);
  193. static FILE *ConfigStackPush (unsigned char *pchFileName);
  194. static void ConfigStackPop (void);
  195. Boolean ParseWmFuncActionArg (unsigned char **linePP,
  196. WmFunction wmFunction, String *pArgs);
  197. static void PreprocessConfigFile (void);
  198. static EventTableEntry buttonEvents[] = {
  199. {"btn1down", ButtonPress, ParseImmed, SELECT_BUTTON, FALSE},
  200. {"btn1up", ButtonRelease, ParseImmed, SELECT_BUTTON, FALSE},
  201. {"btn1click", ButtonRelease, ParseImmed, SELECT_BUTTON, TRUE},
  202. {"btn1click2", ButtonPress, ParseImmed, SELECT_BUTTON, TRUE},
  203. {"btn2down", ButtonPress, ParseImmed, DMANIP_BUTTON, FALSE},
  204. {"btn2up", ButtonRelease, ParseImmed, DMANIP_BUTTON, FALSE},
  205. {"btn2click", ButtonRelease, ParseImmed, DMANIP_BUTTON, TRUE},
  206. {"btn2click2", ButtonPress, ParseImmed, DMANIP_BUTTON, TRUE},
  207. {"btn3down", ButtonPress, ParseImmed, BMENU_BUTTON, FALSE},
  208. {"btn3up", ButtonRelease, ParseImmed, BMENU_BUTTON, FALSE},
  209. {"btn3click", ButtonRelease, ParseImmed, BMENU_BUTTON, TRUE},
  210. {"btn3click2", ButtonPress, ParseImmed, BMENU_BUTTON, TRUE},
  211. {"btn4down", ButtonPress, ParseImmed, Button4, FALSE},
  212. {"btn4up", ButtonRelease, ParseImmed, Button4, FALSE},
  213. {"btn4click", ButtonRelease, ParseImmed, Button4, TRUE},
  214. {"btn4click2", ButtonPress, ParseImmed, Button4, TRUE},
  215. {"btn5down", ButtonPress, ParseImmed, Button5, FALSE},
  216. {"btn5up", ButtonRelease, ParseImmed, Button5, FALSE},
  217. {"btn5click", ButtonRelease, ParseImmed, Button5, TRUE},
  218. {"btn5click2", ButtonPress, ParseImmed, Button5, TRUE},
  219. { NULL, 0, (Boolean(*)())NULL, 0, FALSE}
  220. };
  221. static EventTableEntry keyEvents[] = {
  222. {"key", KeyPress, ParseKeySym, 0, FALSE},
  223. { NULL, 0, (Boolean(*)())NULL, 0, FALSE}
  224. };
  225. typedef struct _ConfigFileStackEntry {
  226. char *fileName;
  227. char *tempName;
  228. char *cppName;
  229. char *wmgdConfigFile;
  230. long offset;
  231. DtWmpParseBuf *pWmPB;
  232. struct _ConfigFileStackEntry *pIncluder;
  233. } ConfigFileStackEntry;
  234. static ConfigFileStackEntry *pConfigStack = NULL;
  235. static ConfigFileStackEntry *pConfigStackTop = NULL;
  236. unsigned int buttonModifierMasks[] = {
  237. 0,
  238. SELECT_BUTTON_MASK,
  239. DMANIP_BUTTON_MASK,
  240. BMENU_BUTTON_MASK,
  241. Button4Mask,
  242. Button5Mask
  243. };
  244. /*
  245. * FUNCTION PARSER TABLE (function names must be in alphabetic order)
  246. */
  247. typedef struct {
  248. char * funcName;
  249. Context greyedContext;
  250. unsigned int resource;
  251. long mgtMask;
  252. WmFunction wmFunction;
  253. Boolean (*parseProc)();
  254. } FunctionTableEntry;
  255. /*
  256. * NOTE: New functions MUST be added in ALPHABETICAL order. A binary search
  257. * is used to find the correct function name.
  258. */
  259. FunctionTableEntry functionTable[] = {
  260. {"f.action", 0,
  261. CRS_ANY,
  262. 0,
  263. F_Action,
  264. ParseWmFuncActionArg},
  265. {"f.beep", 0,
  266. CRS_ANY,
  267. 0,
  268. F_Beep,
  269. ParseWmFuncNoArg},
  270. {"f.circle_down", F_SUBCONTEXT_IB_IICON|F_SUBCONTEXT_IB_WICON,
  271. CRS_ANY,
  272. 0,
  273. F_Circle_Down,
  274. ParseWmFuncGrpArg},
  275. {"f.circle_up", F_SUBCONTEXT_IB_IICON|F_SUBCONTEXT_IB_WICON,
  276. CRS_ANY,
  277. 0,
  278. F_Circle_Up,
  279. ParseWmFuncGrpArg},
  280. {"f.create_workspace", 0,
  281. CRS_ANY,
  282. 0,
  283. F_CreateWorkspace,
  284. ParseWmFuncNoArg},
  285. {"f.delete_workspace", 0,
  286. CRS_ANY,
  287. 0,
  288. F_DeleteWorkspace,
  289. ParseWmFuncNoArg},
  290. {"f.exec", 0,
  291. CRS_ANY,
  292. 0,
  293. F_Exec,
  294. ParseWmFuncStrArg},
  295. {"f.focus_color", F_SUBCONTEXT_IB_IICON|F_SUBCONTEXT_IB_WICON,
  296. CRS_ANY,
  297. 0,
  298. F_Focus_Color,
  299. ParseWmFuncNoArg},
  300. {"f.focus_key", F_SUBCONTEXT_IB_IICON|F_SUBCONTEXT_IB_WICON,
  301. CRS_ANY,
  302. 0,
  303. F_Focus_Key,
  304. ParseWmFuncNoArg},
  305. {"f.goto_workspace", 0,
  306. CRS_ANY,
  307. 0,
  308. F_Goto_Workspace,
  309. ParseWmFuncStrArg},
  310. {"f.help", 0,
  311. CRS_ANY,
  312. 0,
  313. F_Help,
  314. ParseWmFuncStrArg}, /* [helpvolume && helptopic] */
  315. {"f.help_mode", 0,
  316. CRS_ANY,
  317. 0,
  318. F_Help_Mode,
  319. ParseWmFuncNoArg}, /* for now */
  320. {"f.kill", F_CONTEXT_ROOT,
  321. CRS_ANY,
  322. MWM_FUNC_CLOSE,
  323. F_Kill,
  324. ParseWmFuncNoArg},
  325. {"f.lower", F_SUBCONTEXT_IB_IICON|F_SUBCONTEXT_IB_WICON,
  326. CRS_ANY,
  327. 0,
  328. F_Lower,
  329. ParseWmFuncMaybeStrArg},
  330. {"f.marquee_selection",
  331. F_CONTEXT_WINDOW|F_CONTEXT_ICON|F_SUBCONTEXT_IB_IICON,
  332. CRS_ANY,
  333. 0,
  334. F_Marquee_Selection,
  335. ParseWmFuncNoArg},
  336. {"f.maximize", F_CONTEXT_ROOT|F_CONTEXT_MAXIMIZE|
  337. F_SUBCONTEXT_IB_WICON,
  338. CRS_ANY,
  339. MWM_FUNC_MAXIMIZE,
  340. F_Maximize,
  341. ParseWmFuncNoArg},
  342. {"f.menu", 0,
  343. CRS_ANY,
  344. 0,
  345. F_Menu,
  346. ParseWmFuncStrArg},
  347. {"f.minimize", F_CONTEXT_ICON|F_CONTEXT_ROOT|F_SUBCONTEXT_IB_IICON,
  348. CRS_ANY,
  349. MWM_FUNC_MINIMIZE,
  350. F_Minimize,
  351. ParseWmFuncNoArg},
  352. {"f.move", F_CONTEXT_ROOT,
  353. CRS_ANY,
  354. MWM_FUNC_MOVE,
  355. F_Move,
  356. ParseWmFuncNoArg},
  357. {"f.next_cmap", 0,
  358. CRS_ANY,
  359. 0,
  360. F_Next_Cmap,
  361. ParseWmFuncNoArg},
  362. {"f.next_key", 0,
  363. CRS_ANY,
  364. 0,
  365. F_Next_Key,
  366. ParseWmFuncGrpArg},
  367. {"f.next_workspace", 0,
  368. CRS_ANY,
  369. 0,
  370. F_Next_Workspace,
  371. ParseWmFuncNoArg},
  372. {"f.nop", F_CONTEXT_ROOT|F_CONTEXT_ICON|F_CONTEXT_WINDOW|
  373. F_SUBCONTEXT_IB_WICON | F_SUBCONTEXT_IB_IICON,
  374. CRS_ANY,
  375. 0,
  376. F_Nop,
  377. ParseWmFuncNoArg},
  378. {"f.normalize", F_CONTEXT_ROOT|F_CONTEXT_NORMAL|F_SUBCONTEXT_IB_WICON,
  379. CRS_ANY,
  380. 0,
  381. F_Normalize,
  382. ParseWmFuncNoArg},
  383. {"f.normalize_and_raise",
  384. F_CONTEXT_ROOT|F_CONTEXT_NORMAL,
  385. CRS_ANY,
  386. 0,
  387. F_Normalize_And_Raise,
  388. ParseWmFuncMaybeStrArg},
  389. {"f.occupy_all", F_CONTEXT_ICONBOX|F_CONTEXT_ROOT,
  390. CRS_ANY,
  391. DtWM_FUNC_OCCUPY_WS,
  392. F_AddToAllWorkspaces,
  393. ParseWmFuncNoArg},
  394. {"f.pack_icons", 0,
  395. CRS_ANY,
  396. 0,
  397. F_Pack_Icons,
  398. ParseWmFuncNoArg},
  399. {"f.pass_keys", 0,
  400. CRS_ANY,
  401. 0,
  402. F_Pass_Key,
  403. ParseWmFuncNoArg},
  404. {"f.post_wmenu", 0,
  405. CRS_BUTTON|CRS_KEY,
  406. 0,
  407. F_Post_SMenu,
  408. ParseWmFuncNoArg},
  409. {"f.prev_cmap", 0,
  410. CRS_ANY,
  411. 0,
  412. F_Prev_Cmap,
  413. ParseWmFuncNoArg},
  414. {"f.prev_key", 0,
  415. CRS_ANY,
  416. 0,
  417. F_Prev_Key,
  418. ParseWmFuncGrpArg},
  419. {"f.prev_workspace", 0,
  420. CRS_ANY,
  421. 0,
  422. F_Prev_Workspace,
  423. ParseWmFuncNoArg},
  424. {"f.quit_mwm", F_CONTEXT_ICON|F_CONTEXT_WINDOW,
  425. CRS_ANY,
  426. 0,
  427. F_Quit_Mwm,
  428. ParseWmFuncNoArg},
  429. {"f.raise", F_SUBCONTEXT_IB_IICON|F_SUBCONTEXT_IB_WICON,
  430. CRS_ANY,
  431. 0,
  432. F_Raise,
  433. ParseWmFuncMaybeStrArg},
  434. {"f.raise_lower", F_CONTEXT_ROOT |
  435. F_SUBCONTEXT_IB_IICON|F_SUBCONTEXT_IB_WICON,
  436. CRS_ANY,
  437. 0,
  438. F_Raise_Lower,
  439. ParseWmFuncNoArg},
  440. {"f.refresh", 0,
  441. CRS_ANY,
  442. 0,
  443. F_Refresh,
  444. ParseWmFuncNoArg},
  445. {"f.refresh_win", F_CONTEXT_ICON|F_CONTEXT_ROOT,
  446. CRS_ANY,
  447. 0,
  448. F_Refresh_Win,
  449. ParseWmFuncNoArg},
  450. {"f.remove", F_CONTEXT_ROOT,
  451. CRS_ANY,
  452. DtWM_FUNC_OCCUPY_WS,
  453. F_Remove,
  454. ParseWmFuncNoArg},
  455. {"f.resize", F_CONTEXT_ICON|F_CONTEXT_ROOT|
  456. F_SUBCONTEXT_IB_IICON|F_SUBCONTEXT_IB_WICON,
  457. CRS_ANY,
  458. MWM_FUNC_RESIZE,
  459. F_Resize,
  460. ParseWmFuncNoArg},
  461. {"f.restart", F_CONTEXT_ICON|F_CONTEXT_WINDOW,
  462. CRS_ANY,
  463. 0,
  464. F_Restart,
  465. ParseWmFuncStrArg},
  466. {"f.restore", F_CONTEXT_ROOT|F_CONTEXT_NORMAL|F_SUBCONTEXT_IB_WICON,
  467. CRS_ANY,
  468. 0,
  469. F_Restore,
  470. ParseWmFuncNoArg},
  471. {"f.restore_and_raise",
  472. F_CONTEXT_ROOT|F_CONTEXT_NORMAL,
  473. CRS_ANY,
  474. 0,
  475. F_Restore_And_Raise,
  476. ParseWmFuncNoArg},
  477. {"f.screen", 0,
  478. CRS_ANY,
  479. 0,
  480. F_Screen,
  481. ParseWmFuncStrArg},
  482. {"f.send_msg", F_CONTEXT_ROOT,
  483. CRS_ANY,
  484. 0,
  485. F_Send_Msg,
  486. ParseWmFuncNbrArg},
  487. {"f.separator", 0,
  488. CRS_MENU,
  489. 0,
  490. F_Separator,
  491. ParseWmFuncNoArg},
  492. {"f.set_behavior", 0,
  493. CRS_ANY,
  494. 0,
  495. F_Set_Behavior,
  496. ParseWmFuncNoArg},
  497. {"f.set_context", 0,
  498. CRS_ANY,
  499. 0,
  500. F_Set_Context,
  501. ParseWmFuncNbrArg},
  502. {"f.title", 0,
  503. CRS_MENU,
  504. 0,
  505. F_Title,
  506. ParseWmFuncNoArg},
  507. {"f.toggle_frontpanel", 0,
  508. CRS_ANY,
  509. 0,
  510. F_Toggle_Front_Panel,
  511. ParseWmFuncNoArg},
  512. {"f.version", 0,
  513. CRS_ANY,
  514. 0,
  515. F_Version,
  516. ParseWmFuncNoArg},
  517. #ifdef OLD
  518. {"f.workspace_presence",F_CONTEXT_ICON|F_CONTEXT_ROOT|F_CONTEXT_ICONBOX|
  519. F_SUBCONTEXT_IB_IICON|F_SUBCONTEXT_IB_WICON,
  520. #endif /* OLD */
  521. {"f.workspace_presence", F_CONTEXT_ROOT|F_CONTEXT_ICONBOX|
  522. F_SUBCONTEXT_IB_WICON,
  523. CRS_ANY,
  524. DtWM_FUNC_OCCUPY_WS,
  525. F_Workspace_Presence,
  526. ParseWmFuncNoArg},
  527. #if defined(DEBUG)
  528. {"f.zz_debug", 0,
  529. CRS_ANY,
  530. 0,
  531. F_ZZ_Debug,
  532. ParseWmFuncStrArg},
  533. #endif /* DEBUG */
  534. };
  535. /*
  536. * NOTE: New functions MUST be added in ALPHABETICAL order. A binary search
  537. * is used to find the correct function name.
  538. */
  539. #define WMFUNCTIONTABLESIZE (sizeof(functionTable)/sizeof(functionTable[0]))
  540. /*
  541. * Be sure to update these define, whenever adding/deleting a function.
  542. */
  543. int F_ACTION_INDEX;
  544. int F_EXEC_INDEX;
  545. int F_NOP_INDEX;
  546. /******************************<->*************************************
  547. *
  548. * void GetFunctionTableValues (int *execIndex, int *nopIndex,
  549. * int *actionIndex)
  550. *
  551. * Description:
  552. * -----------
  553. * This routine dynamically computes the size of the functionTable[],
  554. * and the indices for key functions, such as f.exec, f.action, and
  555. * f.nop
  556. *
  557. * Inputs:
  558. * ------
  559. * We are setting the values of F_EXEC_INDEX, F_ACTION_INDEX,
  560. * and F_NOP_INDEX on a global level. The addresses
  561. * for same are passed in.
  562. *
  563. * Outputs:
  564. * -------
  565. *
  566. * Comments:
  567. * --------
  568. * This routine calls smaller routines for efficiency sake.
  569. *
  570. ******************************<->***********************************/
  571. void
  572. GetFunctionTableValues (int *execIndex, int *nopIndex,
  573. int *actionIndex)
  574. {
  575. GetExecIndex (WMFUNCTIONTABLESIZE, execIndex);
  576. GetActionIndex (WMFUNCTIONTABLESIZE, actionIndex);
  577. GetNopIndex (WMFUNCTIONTABLESIZE, nopIndex);
  578. } /* END OF FUNCTION GetFunctionTableValues */
  579. /******************************<->*************************************
  580. *
  581. *
  582. * Description:
  583. * -----------
  584. *
  585. * Inputs:
  586. * ------
  587. * Outputs:
  588. * -------
  589. *
  590. * Comments:
  591. * --------
  592. *
  593. ******************************<->***********************************/
  594. void
  595. GetExecIndex (int tableSize, int *execIndex)
  596. {
  597. int i;
  598. for (i = 0; i < (tableSize); i++)
  599. {
  600. if (!(strcmp ("f.exec", functionTable[i].funcName)))
  601. {
  602. *execIndex = i;
  603. return;
  604. }
  605. else
  606. {
  607. *execIndex = 0;
  608. }
  609. }
  610. } /* END OF FUNCTION GetExecIndex */
  611. /******************************<->*************************************
  612. *
  613. *
  614. * Description:
  615. * -----------
  616. *
  617. * Inputs:
  618. * ------
  619. * Outputs:
  620. * -------
  621. *
  622. * Comments:
  623. * --------
  624. *
  625. ******************************<->***********************************/
  626. void
  627. GetActionIndex (int tableSize, int *actionIndex)
  628. {
  629. int i;
  630. for (i = 0; i < (tableSize); i++)
  631. {
  632. if (!(strcmp ("f.action", functionTable[i].funcName)))
  633. {
  634. *actionIndex = i;
  635. return;
  636. }
  637. else
  638. {
  639. *actionIndex = 0;
  640. }
  641. }
  642. } /* END OF FUNCTION GetActionIndex */
  643. /******************************<->*************************************
  644. *
  645. *
  646. * Description:
  647. * -----------
  648. *
  649. * Inputs:
  650. * ------
  651. * Outputs:
  652. * -------
  653. *
  654. * Comments:
  655. * --------
  656. *
  657. ******************************<->***********************************/
  658. void
  659. GetNopIndex (int tableSize, int *nopIndex)
  660. {
  661. int i;
  662. for (i = 0; i < (tableSize); i++)
  663. {
  664. if (!(strcmp ("f.nop", functionTable[i].funcName)))
  665. {
  666. *nopIndex = i;
  667. return;
  668. }
  669. else
  670. {
  671. *nopIndex = 0;
  672. }
  673. }
  674. } /* END OF FUNCTION GetNopIndex */
  675. /*************************************<->*************************************
  676. *
  677. * void
  678. * WmDtGetHelpArgs ()
  679. *
  680. *
  681. * Description:
  682. * -----------
  683. * Get Help Args
  684. *
  685. * Inputs:
  686. * ------
  687. *
  688. * Outputs:
  689. * -------
  690. *
  691. *
  692. * Comments:
  693. * --------
  694. * None.
  695. *
  696. *************************************<->***********************************/
  697. void
  698. WmDtGetHelpArgs(char *args,
  699. unsigned char* volume,
  700. unsigned char* topic,
  701. int *argsCount)
  702. {
  703. unsigned char *string;
  704. unsigned char *lineP;
  705. cfileP = NULL;
  706. linec = 0;
  707. parseP = (unsigned char*) args;
  708. if(GetNextLine () != NULL)
  709. {
  710. *argsCount = 0;
  711. lineP = line;
  712. if ((string = GetSmartSMString (&lineP)) != NULL)
  713. {
  714. *argsCount = *argsCount + 1;
  715. strcpy ((char*)topic, (char*)string);
  716. }
  717. if ((string = GetSmartSMString (&lineP)) != NULL)
  718. {
  719. *argsCount = *argsCount + 1;
  720. strcpy ((char*)volume, (char *)string);
  721. }
  722. }
  723. } /* END OF FUNCTION WmDtGetHelpArgs */
  724. /******************************<->*************************************
  725. *
  726. * void
  727. * ParseDtSessionHints (pSD, property)
  728. *
  729. *
  730. * Description:
  731. * -----------
  732. * This function parses a DtSessionHints string and returns a list of
  733. * DtSessionItems array. The string should have the syntax:
  734. *
  735. *
  736. *
  737. * Inputs:
  738. * ------
  739. * line = (global) line buffer
  740. * pSD->rootWindow = default root window of display
  741. *
  742. *
  743. * Outputs:
  744. * -------
  745. * Return =
  746. *
  747. *
  748. * Comments:
  749. * --------
  750. * None.
  751. *
  752. *************************************<->***********************************/
  753. void
  754. ParseDtSessionHints (WmScreenData *pSD, unsigned char *property)
  755. {
  756. cfileP = NULL;
  757. linec = 0;
  758. parseP = property;
  759. ParseSessionItems (pSD);
  760. } /* END OF FUNCTION ParseDtSessionHints */
  761. /*************************************<->*************************************
  762. *
  763. * FindDtSessionMatch(commandArgc, commandArgv, pCD, pSD, pWorkSpaceList,
  764. * clientMachine)
  765. *
  766. * Description:
  767. * -----------
  768. * Try to find a match for this client in the session hints.
  769. * Set up client-session data.
  770. *
  771. *
  772. * Inputs:
  773. * ------
  774. * commandArgc - argument count
  775. * commandArgv - WM_COMMAND argument vector
  776. * pCD - pointer to client data
  777. * pSD - pointer to screen data
  778. * pWorkspaceList - pointer to a list of workspaces (to be returned)
  779. * clientMachine - string for -host option in session hints
  780. *
  781. * Outputs:
  782. * -------
  783. * *pCD - client data (may be modified)
  784. * FindDtSessionMatch - returns True if a match for this client
  785. * was found in the session hints.
  786. * *pWorkspaceList - list of workspaces this client should be put
  787. * into. (needs to be freed)
  788. *
  789. *
  790. * Comments:
  791. * --------
  792. * Various pieces of client state (in pCD) are reset when a match
  793. * is found.
  794. *
  795. * The caller must free *pWorkspaceList when done.
  796. *
  797. *************************************<->***********************************/
  798. Boolean FindDtSessionMatch(int commandArgc, char **commandArgv,
  799. ClientData *pCD, WmScreenData *pSD,
  800. char **pWorkSpaceList, char *clientMachine)
  801. {
  802. int count;
  803. int relCount;
  804. int argNum;
  805. SessionGeom *sessionGeom;
  806. for (count = 0; count < pSD->totalSessionItems; count++)
  807. {
  808. if (!pSD->pDtSessionItems[count].processed &&
  809. pSD->pDtSessionItems[count].commandArgc == commandArgc)
  810. {
  811. if ((clientMachine) &&
  812. (pSD->pDtSessionItems[count].clientMachine) &&
  813. (strcmp(clientMachine,
  814. pSD->pDtSessionItems[count].clientMachine)))
  815. {
  816. /*
  817. * This item has clientMachine string but the
  818. * clientMachine does not match.
  819. */
  820. continue;
  821. }
  822. for (argNum = 0; argNum < commandArgc ; argNum++)
  823. {
  824. if(strcmp(commandArgv[argNum],
  825. pSD->pDtSessionItems[count].commandArgv[argNum]))
  826. {
  827. /*
  828. * One mismatch and we quit looking at this item.
  829. * Decrement argNum so a mismatch on the last item
  830. * will not look like a match below when comparing
  831. * argNum == commandArgc
  832. */
  833. argNum--;
  834. break;
  835. }
  836. }
  837. if (argNum == commandArgc)
  838. {
  839. /*
  840. * Made it through all strings so this is a match
  841. */
  842. pSD->pDtSessionItems[count].processed = True;
  843. pSD->remainingSessionItems --;
  844. pCD->clientFlags |= SM_LAUNCHED;
  845. /*
  846. * Free strings malloc'd for commandArgv for this item
  847. */
  848. for (relCount = 0; relCount < commandArgc; relCount++)
  849. {
  850. XtFree(pSD->pDtSessionItems[count].commandArgv[relCount]);
  851. }
  852. XtFree((char *)pSD->pDtSessionItems[count].commandArgv);
  853. if(pSD->pDtSessionItems[count].clientState)
  854. {
  855. pCD->clientState =
  856. pSD->pDtSessionItems[count].clientState;
  857. pCD->clientFlags |= SM_CLIENT_STATE;
  858. }
  859. if(pSD->pDtSessionItems[count].sessionGeom)
  860. {
  861. sessionGeom = pSD->pDtSessionItems[count].sessionGeom;
  862. if (sessionGeom->flags & XValue)
  863. {
  864. pCD->clientX = sessionGeom->clientX;
  865. pCD->clientFlags |= SM_X;
  866. }
  867. if (sessionGeom->flags & YValue)
  868. {
  869. pCD->clientY = sessionGeom->clientY;
  870. pCD->clientFlags |= SM_Y;
  871. }
  872. if (sessionGeom->flags & WidthValue)
  873. {
  874. pCD->clientWidth = sessionGeom->clientWidth;
  875. pCD->clientFlags |= SM_WIDTH;
  876. }
  877. if (sessionGeom->flags & HeightValue)
  878. {
  879. pCD->clientHeight = sessionGeom->clientHeight;
  880. pCD->clientFlags |= SM_HEIGHT;
  881. }
  882. /*
  883. * Free SessionGeom malloc'd space for this item
  884. */
  885. XtFree((char *)pSD->pDtSessionItems[count].sessionGeom);
  886. }
  887. if(pSD->pDtSessionItems[count].clientMachine)
  888. {
  889. /*
  890. * Free clientMachine malloc'd space for this item
  891. */
  892. XtFree((char *)
  893. pSD->pDtSessionItems[count].clientMachine);
  894. pSD->pDtSessionItems[count].clientMachine = NULL;
  895. }
  896. if(pSD->pDtSessionItems[count].workspaces)
  897. {
  898. /*
  899. * The caller is responsible for freeing this
  900. * data.
  901. */
  902. *pWorkSpaceList = pSD->pDtSessionItems[count].workspaces;
  903. }
  904. if(pSD->remainingSessionItems == 0)
  905. {
  906. /*
  907. * Free the whole pSD->pDtSessionHints structure
  908. */
  909. XtFree((char *)pSD->pDtSessionItems);
  910. }
  911. return (True);
  912. }
  913. } /* not processed and argc's are the same */
  914. } /* for */
  915. return (False);
  916. } /* END OF FUNCTION FindDtSessionMatch */
  917. /*************************************<->*************************************
  918. *
  919. * void
  920. * ParseSessionItems (pSD)
  921. *
  922. *
  923. * Description:
  924. * -----------
  925. * Parse session items
  926. *
  927. * Inputs:
  928. * ------
  929. * pSD = pointer to screen data
  930. * cfileP = (global) file pointer to NULL
  931. * line = (global) line buffer
  932. * linec = (global) line count
  933. * parseP = (global) parse string pointer if cfileP == NULL
  934. * pSD->rootWindow = default root window of display
  935. *
  936. * Outputs:
  937. * -------
  938. * linec = (global) line count incremented
  939. * parseP = (global) parse string pointer if cfileP == NULL
  940. *
  941. *
  942. * Comments:
  943. * --------
  944. * None.
  945. *
  946. *************************************<->***********************************/
  947. void
  948. ParseSessionItems (WmScreenData *pSD)
  949. {
  950. unsigned char *string;
  951. unsigned char *lineP;
  952. int count;
  953. /*
  954. * Parse property string
  955. */
  956. if(GetNextLine () != NULL)
  957. {
  958. pSD->totalSessionItems = atoi((char *)line);
  959. pSD->remainingSessionItems = pSD->totalSessionItems;
  960. }
  961. if((pSD->totalSessionItems < 1) ||
  962. !GetSessionHintsInfo(pSD, pSD->totalSessionItems))
  963. {
  964. /*
  965. * No items or couldn't allocate space
  966. */
  967. return;
  968. }
  969. count = 0;
  970. while ((count < pSD->totalSessionItems) && (GetNextLine () != NULL))
  971. {
  972. lineP = line;
  973. while ((string = GetSmartSMString (&lineP)) != NULL)
  974. {
  975. if (!strcmp((char *)string, "-geometry"))
  976. {
  977. /*
  978. * Parse geometry if it is present
  979. */
  980. string = GetSmartSMString(&lineP);
  981. ParseSessionGeometry (pSD, count, string);
  982. }
  983. else if (!strcmp((char *)string, "-state"))
  984. {
  985. /*
  986. * Parse the state if it is present
  987. */
  988. string = GetSmartSMString(&lineP);
  989. ParseSessionClientState (pSD, count, string);
  990. }
  991. else if (!strcmp((char *)string, "-workspaces"))
  992. {
  993. /*
  994. * Parse the workspaces string if it is present
  995. */
  996. string = GetSmartSMString(&lineP);
  997. ParseSessionWorkspaces (pSD, count, string);
  998. }
  999. else if (!strcmp((char *)string, "-cmd"))
  1000. {
  1001. /*
  1002. * Parse the command string if it is present
  1003. */
  1004. string = GetSmartSMString(&lineP);
  1005. ParseSessionCommand (pSD, count, &string);
  1006. }
  1007. else if (!strcmp((char *)string, "-host"))
  1008. {
  1009. /*
  1010. * Parse the host string if it is present
  1011. */
  1012. string = GetSmartSMString(&lineP);
  1013. ParseSessionHost (pSD, count, string);
  1014. }
  1015. } /* while GetSmartSMString */
  1016. count++;
  1017. } /* while GetNextLine */
  1018. } /* END OF FUNCTION ParseSessionItems */
  1019. /*************************************<->*************************************
  1020. *
  1021. * ParseSessionClientState (pSD, count, string);
  1022. *
  1023. * Description:
  1024. * -----------
  1025. * Inputs:
  1026. * ------
  1027. * Outputs:
  1028. * -------
  1029. * Comments:
  1030. * --------
  1031. *
  1032. *************************************<->***********************************/
  1033. void ParseSessionClientState (WmScreenData *pSD, int count,
  1034. unsigned char *string)
  1035. {
  1036. if(!strcmp((char *)string, "NormalState"))
  1037. {
  1038. pSD->pDtSessionItems[count].clientState = NORMAL_STATE;
  1039. }
  1040. else if(!strcmp((char *)string, "IconicState"))
  1041. {
  1042. pSD->pDtSessionItems[count].clientState = MINIMIZED_STATE;
  1043. }
  1044. } /* END OF FUNCTION ParseSessionClientState */
  1045. /*************************************<->*************************************
  1046. *
  1047. * ParseSessionGeometry (pSD, count, string)
  1048. *
  1049. * Description:
  1050. * -----------
  1051. * Inputs:
  1052. * ------
  1053. * Outputs:
  1054. * -------
  1055. * Comments:
  1056. * --------
  1057. *
  1058. *************************************<->***********************************/
  1059. void ParseSessionGeometry (WmScreenData *pSD, int count,
  1060. unsigned char *string)
  1061. {
  1062. SessionGeom *pTmpSessionGeom;
  1063. int mask /* = 0 */;
  1064. int X, Y, width, height;
  1065. X = Y = width = height = 0;
  1066. /*
  1067. * XParseGeometry
  1068. */
  1069. mask = XParseGeometry((char *)string, &X, &Y, (unsigned int *)&width,
  1070. (unsigned int *)&height);
  1071. if (mask)
  1072. {
  1073. /*
  1074. * Allocate space for the geometry structure
  1075. */
  1076. if ((pTmpSessionGeom =
  1077. (SessionGeom *)XtMalloc (sizeof (SessionGeom))) == NULL)
  1078. {
  1079. Warning (((char *)GETMESSAGE(60, 1, "Insufficient memory for session geometry item")));
  1080. return;
  1081. }
  1082. pTmpSessionGeom->flags = mask;
  1083. pTmpSessionGeom->clientX = X;
  1084. pTmpSessionGeom->clientY = Y;
  1085. pTmpSessionGeom->clientWidth = width;
  1086. pTmpSessionGeom->clientHeight = height;
  1087. pSD->pDtSessionItems[count].sessionGeom = pTmpSessionGeom;
  1088. }
  1089. } /* END OF FUNCTION ParseSessionGeometry */
  1090. /*************************************<->*************************************
  1091. *
  1092. * void
  1093. * ParseSessionWorkspaces (pSD, count, string)
  1094. *
  1095. * Description:
  1096. * -----------
  1097. * Inputs:
  1098. * ------
  1099. * Outputs:
  1100. * -------
  1101. * Comments:
  1102. * --------
  1103. *
  1104. *************************************<->***********************************/
  1105. void ParseSessionWorkspaces (WmScreenData *pSD, int count,
  1106. unsigned char *string)
  1107. {
  1108. /*
  1109. * Allocate space for the workspaces string
  1110. */
  1111. if ((pSD->pDtSessionItems[count].workspaces =
  1112. (String)XtMalloc ((unsigned int) (strlen((char *)string) + 1))) == NULL)
  1113. {
  1114. Warning (((char *)GETMESSAGE(60, 2, "Insufficient memory for workspaces list in session item")));
  1115. return;
  1116. }
  1117. strcpy(pSD->pDtSessionItems[count].workspaces, (char *)string);
  1118. } /* END OF FUNCTION ParseSessionWorkspaces */
  1119. /*************************************<->*************************************
  1120. *
  1121. * void
  1122. * ParseSessionCommand (pSD, count, string)
  1123. *
  1124. * Description:
  1125. * -----------
  1126. * Inputs:
  1127. * ------
  1128. * Outputs:
  1129. * -------
  1130. * Comments:
  1131. * --------
  1132. *
  1133. *************************************<->***********************************/
  1134. void ParseSessionCommand (WmScreenData *pSD, int count,
  1135. unsigned char **commandString)
  1136. {
  1137. #define ARG_AMT 100
  1138. int xindex;
  1139. unsigned char **argv;
  1140. int argc = 0;
  1141. int iSizeArgv;
  1142. unsigned char *string;
  1143. argv = (unsigned char **) XtMalloc (ARG_AMT * sizeof(char *));
  1144. iSizeArgv = ARG_AMT;
  1145. while ((string = GetSmartSMString (commandString)) != NULL)
  1146. {
  1147. /*
  1148. * Get pointers to strings in command line and count them
  1149. */
  1150. argv[argc] = string;
  1151. argc ++;
  1152. if (argc >= iSizeArgv)
  1153. {
  1154. iSizeArgv += ARG_AMT;
  1155. argv = (unsigned char **)
  1156. XtRealloc ((char *)argv, (iSizeArgv * sizeof(char *)));
  1157. }
  1158. }
  1159. if ((pSD->pDtSessionItems[count].commandArgv =
  1160. (char **)XtMalloc ((argc) * sizeof(char * ))) == NULL)
  1161. {
  1162. /*
  1163. * Allocate space for saved argv
  1164. */
  1165. Warning (((char *)GETMESSAGE(60, 3, "Insufficient memory for commandArgv array")));
  1166. }
  1167. else
  1168. {
  1169. pSD->pDtSessionItems[count].commandArgc = argc;
  1170. for (xindex = 0; xindex < argc ; xindex++)
  1171. {
  1172. if ((pSD->pDtSessionItems[count].commandArgv[xindex] =
  1173. (String) XtMalloc
  1174. ((unsigned int) (strlen((char *)argv[xindex]) + 1))) == NULL)
  1175. {
  1176. /*
  1177. * Allocate space for the next command segment.
  1178. */
  1179. Warning (((char *)GETMESSAGE(60, 4, "Insufficient memory for commandArgv item")));
  1180. }
  1181. else
  1182. {
  1183. strcpy(pSD->pDtSessionItems[count].commandArgv[xindex],
  1184. (char *)argv[xindex]);
  1185. }
  1186. }
  1187. }
  1188. XtFree ((char *) argv);
  1189. } /* END OF FUNCTION ParseSessionCommand */
  1190. /*************************************<->*************************************
  1191. *
  1192. * void
  1193. * ParseSessionHost (pSD, count, string)
  1194. *
  1195. * Description:
  1196. * -----------
  1197. * Inputs:
  1198. * ------
  1199. * Outputs:
  1200. * -------
  1201. * Comments:
  1202. * --------
  1203. *
  1204. *************************************<->***********************************/
  1205. void ParseSessionHost (WmScreenData *pSD, int count,
  1206. unsigned char *string)
  1207. {
  1208. /*
  1209. * Allocate space for the workspaces string
  1210. */
  1211. if ((pSD->pDtSessionItems[count].clientMachine =
  1212. (String)XtMalloc ((unsigned int) (strlen((char *)string) + 1))) ==
  1213. NULL)
  1214. {
  1215. Warning (((char *)GETMESSAGE(60, 38,
  1216. "Insufficient memory for host name in session item")));
  1217. return;
  1218. }
  1219. strcpy(pSD->pDtSessionItems[count].clientMachine, (char *)string);
  1220. } /* END OF FUNCTION ParseSessionHost */
  1221. /*************************************<->*************************************
  1222. *
  1223. * GetSessionHintsInfo (pSD, numItems)
  1224. *
  1225. * Description:
  1226. * -----------
  1227. * Inputs:
  1228. * ------
  1229. * Outputs:
  1230. * -------
  1231. * Comments:
  1232. * --------
  1233. *
  1234. *************************************<->***********************************/
  1235. Boolean GetSessionHintsInfo (WmScreenData *pSD, long numItems)
  1236. {
  1237. if ((pSD->pDtSessionItems =
  1238. (DtSessionItem *)XtMalloc (numItems * sizeof (DtSessionItem)))
  1239. == NULL)
  1240. {
  1241. Warning (((char *)GETMESSAGE(60, 5, "Insufficient memory for Dt Session Hints")));
  1242. return(False);
  1243. }
  1244. memset ((char *)pSD->pDtSessionItems, 0,
  1245. numItems * sizeof (DtSessionItem));
  1246. return(True);
  1247. } /* END OF FUNCTION GetSessionHintsInfo */
  1248. /*************************************<->*************************************
  1249. *
  1250. * PeekAhead (currentChar, currentLev)
  1251. *
  1252. *
  1253. * Description:
  1254. * -----------
  1255. * Returns a new level value if this is a new nesting level of quoted string
  1256. * Otherwise it returns a zero
  1257. *
  1258. *
  1259. * Inputs:
  1260. * ------
  1261. * currentChar = current position in the string
  1262. * currentLev = current level of nesting
  1263. *
  1264. *
  1265. * Outputs:
  1266. * -------
  1267. * Returns either a new level of nesting or zero if the character is copied in
  1268. *
  1269. *
  1270. * Comments:
  1271. * --------
  1272. *
  1273. *************************************<->***********************************/
  1274. unsigned int PeekAhead(unsigned char *currentChar,
  1275. unsigned int currentLev)
  1276. {
  1277. Boolean done = False;
  1278. unsigned int tmpLev = 1;
  1279. unsigned int chlen;
  1280. while (((chlen = mblen ((char *)currentChar, MB_CUR_MAX)) > 0) &&
  1281. (chlen == 1) && ((*currentChar == '"') || (*currentChar == '\\'))
  1282. && (done == False))
  1283. {
  1284. currentChar++;
  1285. if(((chlen = mblen ((char *)currentChar, MB_CUR_MAX)) > 0) && (chlen == 1) &&
  1286. ((*currentChar == '"') || (*currentChar == '\\')))
  1287. {
  1288. tmpLev++;
  1289. if(*currentChar == '"')
  1290. {
  1291. done = True;
  1292. }
  1293. else
  1294. {
  1295. currentChar++;
  1296. }
  1297. }
  1298. }
  1299. /*
  1300. * Figure out if this is truly a new level of nesting - else ignore it
  1301. * This section probably could do some error checking and return -1
  1302. * If so, change type of routine from unsigned int to int
  1303. */
  1304. if(done == True)
  1305. {
  1306. return(tmpLev);
  1307. }
  1308. else
  1309. {
  1310. return(0);
  1311. }
  1312. } /* END OF FUNCTION PeekAhead */
  1313. /*************************************<->*************************************
  1314. *
  1315. * SyncModifierStrings (fileName)
  1316. *
  1317. * Description:
  1318. * -----------
  1319. * This function updates modifierStrings table so that Mwm uses the correct
  1320. * modifier to keysym mapping. Specifically, fix up the Alt and Meta bindings.
  1321. *
  1322. * Inputs:
  1323. * ------
  1324. * fileName
  1325. *
  1326. * Outputs:
  1327. * -------
  1328. * fileName
  1329. *
  1330. * Comments:
  1331. * --------
  1332. *
  1333. *************************************<->***********************************/
  1334. void SyncModifierStrings(void)
  1335. {
  1336. XModifierKeymap *map;
  1337. int i, j, k = 0;
  1338. map = XGetModifierMapping (DISPLAY);
  1339. for (i = 0; i < 8; i++)
  1340. {
  1341. for (j = 0; j < map->max_keypermod; j++)
  1342. {
  1343. if (map->modifiermap[k])
  1344. {
  1345. KeySym ks = XKeycodeToKeysym(DISPLAY, map->modifiermap[k], 0);
  1346. char *nm = XKeysymToString(ks);
  1347. /* Compare, ignoring the trailing '_L' or '_R' in keysym */
  1348. if (nm && !strncmp("Alt", nm, 3))
  1349. {
  1350. modifierStrings[ALT_INDEX].mask = (1<<i);
  1351. }
  1352. else if (nm && !strncmp("Meta", nm, 4))
  1353. {
  1354. modifierStrings[META_INDEX].mask = (1<<i);
  1355. }
  1356. }
  1357. k++;
  1358. }
  1359. }
  1360. XFreeModifiermap(map);
  1361. }
  1362. /*************************************<->*************************************
  1363. *
  1364. * ProcessWmFile ()
  1365. *
  1366. *
  1367. * Description:
  1368. * -----------
  1369. * This function reads the mwm resource description file and processes the
  1370. * resources that are described.
  1371. *
  1372. *
  1373. * Inputs:
  1374. * ------
  1375. * wmGD.bitmapDirectory = bitmapDirectory resource value
  1376. * pSD->buttonBindings = buttonBindings resource value
  1377. * wmGD.configFile = configuration file resource value
  1378. * pSD->keyBindings = keyBindings resource value
  1379. * wmGD.rootWindow = default root window of display
  1380. * HOME = environment variable for home directory
  1381. * functionTable = window manager function parse table
  1382. *
  1383. *
  1384. * Outputs:
  1385. * -------
  1386. * wmGD.buttonSpecs = list of button binding specifications
  1387. * wmGD.keySpecs = list of key binding specification
  1388. * wmGD.menuSpecs = list of menu specifications
  1389. * *wmGD.acceleratorMenuSpecs = initialized array of (MenuSpec *)
  1390. * wmGD.acceleratorMenuCount = 0
  1391. *
  1392. *
  1393. * Comments:
  1394. * --------
  1395. * If there are more than MAXLINE characters on a line the excess characters
  1396. * are truncated.
  1397. *
  1398. *************************************<->***********************************/
  1399. #define MENU_SPEC "menu"
  1400. #define BUTTON_SPEC "buttons"
  1401. #define KEY_SPEC "keys"
  1402. #define FRONT_PANEL_SPEC DTWM_FP_PANEL_OLD
  1403. #define DROP_EFFECTS_SPEC DTWM_FP_DROP_EFFECTS
  1404. #define PANEL_SPEC DTWM_FP_PANEL
  1405. #define BOX_SPEC DTWM_FP_BOX
  1406. #define CONTROL_SPEC DTWM_FP_CONTROL
  1407. #define INCLUDE_SPEC DTWM_FP_INCLUDE
  1408. #define ANIMATION_SPEC DTWM_FP_ANIMATION
  1409. #define SWITCH_SPEC DTWM_FP_SWITCH
  1410. void ProcessWmFile (WmScreenData *pSD, Boolean bNested)
  1411. {
  1412. unsigned char *lineP;
  1413. unsigned char *string;
  1414. unsigned int n;
  1415. MenuSpec *menuSpec;
  1416. if (!bNested)
  1417. {
  1418. /*
  1419. * Initialize global data values that are set based on data in
  1420. * the mwm resource description file.
  1421. */
  1422. pSD->buttonSpecs = NULL;
  1423. pSD->keySpecs = NULL;
  1424. pSD->menuSpecs = NULL;
  1425. /**** hhhhhhhhhhhh ******/
  1426. GetFunctionTableValues (&F_EXEC_INDEX, &F_NOP_INDEX, &F_ACTION_INDEX);
  1427. /*
  1428. * Find and parse the default system menu string, if it exists.
  1429. */
  1430. cfileP = NULL;
  1431. linec = 0;
  1432. if (((parseP = (unsigned char *) builtinSystemMenu) != NULL) &&
  1433. (GetNextLine () != NULL))
  1434. {
  1435. lineP = line;
  1436. ParseMenuSet (pSD, lineP);
  1437. }
  1438. linec = 0;
  1439. if (((parseP = (unsigned char *) builtinRootMenu) != NULL) &&
  1440. (GetNextLine () != NULL))
  1441. {
  1442. lineP = line;
  1443. ParseMenuSet (pSD, lineP);
  1444. }
  1445. if (wmGD.useFrontPanel && !wmGD.dtSD &&
  1446. (XDefaultScreen (wmGD.display) == pSD->screen))
  1447. {
  1448. wmGD.dtSD = pSD; /* only one per display */
  1449. }
  1450. /*
  1451. * Find and associate a stream with the window manager resource
  1452. * description file.
  1453. */
  1454. if ((cfileP = FopenConfigFile ()) == NULL)
  1455. {
  1456. if (!wmGD.useStandardBehavior)
  1457. Warning (((char *)GETMESSAGE(60, 6, "Cannot open configuration file")));
  1458. return;
  1459. }
  1460. } /* end if (!bNested) */
  1461. /*
  1462. * Parse the information in the configuration file.
  1463. * If there are more than MAXLINE characters on a line the excess are
  1464. * truncated.
  1465. */
  1466. linec = 0;
  1467. while ((GetNextLine () != NULL)) /* not EOF nor read error */
  1468. {
  1469. lineP = line;
  1470. if ((*line == '!') || (string = GetString (&lineP)) == NULL)
  1471. /* empty or comment line */
  1472. {
  1473. continue;
  1474. }
  1475. ToLower ((char *)string);
  1476. if (!strcmp ((char *)string, MENU_SPEC))
  1477. {
  1478. ParseMenuSet (pSD, lineP);
  1479. }
  1480. else if (!strcmp ((char *) string, BUTTON_SPEC))
  1481. {
  1482. ParseButtonSet (pSD, lineP);
  1483. }
  1484. else if (!strcmp ((char *) string, KEY_SPEC))
  1485. {
  1486. ParseKeySet (pSD, lineP);
  1487. }
  1488. else if (!strcmp ((char *)string, INCLUDE_SPEC))
  1489. {
  1490. ParseIncludeSet (pSD, lineP);
  1491. }
  1492. }
  1493. fclose (cfileP);
  1494. /*
  1495. * Create and initialize the pSD->acceleratorMenuSpecs array.
  1496. * This assumes we create pointers to MenuSpecs within ProcessWmFile().
  1497. * Set pSD->acceleratorMenuCount to 0.
  1498. */
  1499. /* count the number of menu specifications */
  1500. n = 0;
  1501. menuSpec = pSD->menuSpecs;
  1502. while (menuSpec)
  1503. {
  1504. n++;
  1505. menuSpec = menuSpec->nextMenuSpec;
  1506. }
  1507. /* allocate the array and initialize to zeros */
  1508. pSD->acceleratorMenuSpecs = NULL;
  1509. if (n)
  1510. {
  1511. pSD->acceleratorMenuSpecs =
  1512. (MenuSpec **) XtCalloc (n, sizeof (MenuSpec *));
  1513. if (pSD->acceleratorMenuSpecs == NULL)
  1514. {
  1515. Warning (((char *)GETMESSAGE(60, 7, "Insufficient memory for menu accelerators")));
  1516. }
  1517. }
  1518. pSD->acceleratorMenuCount = 0;
  1519. } /* END OF FUNCTION ProcessWmFile */
  1520. /**** This function stolen from Xt/Intrinsic.c ****/
  1521. /* The implementation of this routine is operating system dependent */
  1522. static char *ExtractLocaleName(String lang)
  1523. {
  1524. #ifdef hpux /* hpux-specific parsing of the locale string */
  1525. #define MAXLOCALE 64 /* buffer size of locale name */
  1526. char *start;
  1527. char *end;
  1528. int len;
  1529. static char buf[MAXLOCALE];
  1530. /* If lang has a substring ":<category>;", extract <category>
  1531. * from the first such occurrence as the locale name.
  1532. */
  1533. start = lang;
  1534. if (start = strchr (lang, ':')) {
  1535. start++;
  1536. if (end = strchr (start, ';')) {
  1537. len = end - start;
  1538. strncpy(buf, start, len);
  1539. *(buf + len) = '\0';
  1540. lang = buf;
  1541. }
  1542. }
  1543. #endif /* hpux */
  1544. return lang;
  1545. }
  1546. #define RC_CONFIG_SUBDIR "/config/"
  1547. #define RC_DEFAULT_CONFIG_SUBDIR "/config/C"
  1548. /*************************************<->*************************************
  1549. *
  1550. * FopenConfigFile ()
  1551. *
  1552. *
  1553. * Description:
  1554. * -----------
  1555. * This function searches for, opens, and associates a stream with the mwm
  1556. * resource description file,
  1557. *
  1558. *
  1559. * Inputs:
  1560. * ------
  1561. * wmGD.configFile = configuration file resource value.
  1562. * HOME = environment variable for home directory
  1563. *
  1564. *
  1565. * Outputs:
  1566. * -------
  1567. * Return = If successful, a pointer to the FILE structure associated with
  1568. * the configuration file. Otherwise, NULL.
  1569. *
  1570. *
  1571. * Comments:
  1572. * --------
  1573. * None.
  1574. *
  1575. *************************************<->***********************************/
  1576. FILE *FopenConfigFile (void)
  1577. {
  1578. char *LANG, *LANGp;
  1579. FILE *fileP;
  1580. char *homeDir = XmeGetHomeDirName();
  1581. Boolean stackPushed;
  1582. /*
  1583. * Get the LANG environment variable
  1584. * make copy since another call to getenv will blast the value.
  1585. */
  1586. LANGp = setlocale(LC_CTYPE, NULL);
  1587. /*
  1588. * setlocale not guaranteed to return $LANG -- extract
  1589. * something usable.
  1590. */
  1591. LANGp = ExtractLocaleName (LANGp);
  1592. if ((LANGp == NULL) || (strlen(LANGp) == 0))
  1593. {
  1594. LANG = NULL;
  1595. }
  1596. else
  1597. {
  1598. if ((LANG = (char *) XtMalloc(strlen(LANGp) +1)) == NULL)
  1599. {
  1600. PWarning (((char *)GETMESSAGE(60, 41, "Insufficient memory to get LANG environment variable.")));
  1601. return(NULL);
  1602. }
  1603. strcpy(LANG, LANGp);
  1604. }
  1605. /*
  1606. * To get a name for the file first look at the value of the configFile
  1607. * resource. Interpret "~/.." as relative to the user's home directory.
  1608. * Use the LANG variable if set and .mwmrc is in $HOME/$LANG/.mwmrc
  1609. */
  1610. if (pConfigStackTop && pConfigStackTop->tempName)
  1611. {
  1612. fileP = fopen (pConfigStackTop->tempName, "r");
  1613. return (fileP);
  1614. }
  1615. stackPushed = (pConfigStackTop && (pConfigStackTop != pConfigStack));
  1616. fileP = NULL;
  1617. cfileName[0] = '\0';
  1618. if ((wmGD.configFile != NULL) && (wmGD.configFile[0] != '\0'))
  1619. /* pointer to nonNULL string */
  1620. {
  1621. if ((wmGD.configFile[0] == '~') && (wmGD.configFile[1] == '/'))
  1622. /* handle "~/..." */
  1623. {
  1624. strcpy (cfileName, homeDir);
  1625. if (LANG != NULL)
  1626. {
  1627. strncat(cfileName, "/", MAXWMPATH-strlen(cfileName));
  1628. strncat(cfileName, LANG, MAXWMPATH-strlen(cfileName));
  1629. }
  1630. strncat(cfileName, &(wmGD.configFile[1]), MAXWMPATH-strlen(cfileName));
  1631. if ((fileP = fopen (cfileName, "r")) != NULL)
  1632. {
  1633. if (LANG != NULL) {
  1634. XtFree(LANG);
  1635. LANG = NULL;
  1636. }
  1637. }
  1638. else
  1639. {
  1640. /*
  1641. * Just try $HOME/.mwmrc
  1642. */
  1643. strcpy (cfileName, homeDir);
  1644. strncat(cfileName, &(wmGD.configFile[1]),
  1645. MAXWMPATH-strlen(cfileName));
  1646. if ((fileP = fopen (cfileName, "r")) != NULL)
  1647. {
  1648. if (LANG != NULL) {
  1649. XtFree(LANG);
  1650. LANG = NULL;
  1651. }
  1652. }
  1653. }
  1654. }
  1655. else
  1656. /* relative to current directory or absolute */
  1657. {
  1658. char *pch;
  1659. pch = (char *) GetNetworkFileName (wmGD.configFile);
  1660. if ((fileP = fopen (pch, "r")) != NULL)
  1661. {
  1662. strncpy (cfileName, pch, MAXWMPATH);
  1663. }
  1664. XtFree (pch);
  1665. if ((fileP == NULL) && !stackPushed)
  1666. {
  1667. if ((fileP = fopen (wmGD.configFile, "r")) != NULL)
  1668. {
  1669. if (LANG != NULL) {
  1670. XtFree(LANG);
  1671. LANG = NULL;
  1672. }
  1673. return(fileP);
  1674. }
  1675. }
  1676. else if ((fileP == NULL) && stackPushed)
  1677. {
  1678. strcpy (cfileName, wmGD.configFile);
  1679. }
  1680. }
  1681. }
  1682. if ((fileP == NULL) && !stackPushed)
  1683. {
  1684. /*
  1685. * The configFile resource didn't do it for us.
  1686. * First try HOME_MWMRC, then try SYS_MWMRC .
  1687. */
  1688. #define HOME_MWMRC "/.mwmrc"
  1689. #define SLASH_MWMRC "/system.mwmrc"
  1690. strcpy (cfileName, homeDir);
  1691. if (MwmBehavior)
  1692. {
  1693. /*
  1694. *
  1695. * Looking for $HOME/$LANG/.mwmrc
  1696. * --or--if $LANG is NULL
  1697. * Looking for $HOME/.mwmrc
  1698. *
  1699. */
  1700. if (LANG != NULL)
  1701. {
  1702. strncat(cfileName, "/", MAXWMPATH-strlen(cfileName));
  1703. strncat(cfileName, LANG, MAXWMPATH-strlen(cfileName));
  1704. }
  1705. strncat(cfileName, HOME_MWMRC, MAXWMPATH - strlen(cfileName));
  1706. }
  1707. else
  1708. {
  1709. /*
  1710. *
  1711. * Looking for $HOME/.dt/$LANG/dtwmrc
  1712. *
  1713. * --or--if $LANG is NULL--
  1714. *
  1715. * Looking for $HOME/.dt/dtwmrc
  1716. *
  1717. */
  1718. strncat(cfileName, "/.dt/", MAXWMPATH-strlen(cfileName));
  1719. if (LANG != NULL)
  1720. {
  1721. strncat(cfileName, LANG, MAXWMPATH-strlen(cfileName));
  1722. }
  1723. strncat(cfileName, LANG_DT_WMRC, MAXWMPATH - strlen(cfileName));
  1724. }
  1725. if ((fileP = fopen (cfileName, "r")) != NULL)
  1726. {
  1727. if (LANG != NULL) {
  1728. XtFree(LANG);
  1729. LANG = NULL;
  1730. }
  1731. }
  1732. else
  1733. {
  1734. /*
  1735. * Just try $HOME/.mwmrc
  1736. */
  1737. strcpy (cfileName, homeDir);
  1738. if (MwmBehavior)
  1739. {
  1740. /*
  1741. * Just try $HOME/.mwmrc
  1742. */
  1743. strncat(cfileName, HOME_MWMRC, MAXWMPATH - strlen(cfileName));
  1744. }
  1745. else
  1746. {
  1747. /*
  1748. * Just try $HOME/.dt/dtwmrc
  1749. */
  1750. strncat(cfileName, HOME_DT_WMRC, MAXWMPATH - strlen(cfileName));
  1751. }
  1752. if ((fileP = fopen (cfileName, "r")) != NULL)
  1753. {
  1754. if (LANG != NULL) {
  1755. XtFree(LANG);
  1756. LANG = NULL;
  1757. }
  1758. }
  1759. }
  1760. }
  1761. #define DTLIBDIR CDE_INSTALLATION_TOP
  1762. #define DTADMINDIR CDE_CONFIGURATION_TOP
  1763. #define SLASH_DT_WMRC "/sys.dtwmrc"
  1764. if ((fileP == NULL) && !stackPushed)
  1765. {
  1766. /*
  1767. * No home-based config file. Try the admin directory.
  1768. */
  1769. strcpy(cfileName, DTADMINDIR);
  1770. strncat(cfileName, RC_CONFIG_SUBDIR, MAXWMPATH-strlen(cfileName));
  1771. strncat(cfileName, LANG, MAXWMPATH-strlen(cfileName));
  1772. strncat(cfileName, SLASH_DT_WMRC, MAXWMPATH - strlen(cfileName));
  1773. if (((fileP = fopen (cfileName, "r")) == NULL) && LANG && *LANG)
  1774. {
  1775. /* Try it with no LANG */
  1776. strcpy(cfileName, DTADMINDIR);
  1777. strncat(cfileName, RC_CONFIG_SUBDIR, MAXWMPATH-strlen(cfileName));
  1778. strncat(cfileName, SLASH_DT_WMRC, MAXWMPATH - strlen(cfileName));
  1779. }
  1780. if ((fileP = fopen (cfileName, "r")) != NULL)
  1781. {
  1782. XtFree(LANG);
  1783. LANG = NULL;
  1784. }
  1785. }
  1786. if ((fileP == NULL) && !stackPushed)
  1787. {
  1788. #ifndef LIBDIR
  1789. #define LIBDIR "/usr/lib/X11"
  1790. #endif
  1791. if (LANG != NULL)
  1792. {
  1793. if (MwmBehavior)
  1794. {
  1795. strcpy(cfileName, LIBDIR);
  1796. strncat(cfileName, "/", MAXWMPATH-strlen(cfileName));
  1797. strncat(cfileName, LANG, MAXWMPATH-strlen(cfileName));
  1798. strncat(cfileName, SLASH_MWMRC, MAXWMPATH - strlen(cfileName));
  1799. }
  1800. else
  1801. {
  1802. strcpy(cfileName, DTLIBDIR);
  1803. strncat(cfileName, RC_CONFIG_SUBDIR, MAXWMPATH-strlen(cfileName));
  1804. strncat(cfileName, LANG, MAXWMPATH-strlen(cfileName));
  1805. strncat(cfileName, SLASH_DT_WMRC, MAXWMPATH - strlen(cfileName));
  1806. }
  1807. if ((fileP = fopen (cfileName, "r")) != NULL)
  1808. {
  1809. XtFree(LANG);
  1810. LANG = NULL;
  1811. }
  1812. }
  1813. if ((fileP == NULL) && !stackPushed)
  1814. {
  1815. if (MwmBehavior)
  1816. {
  1817. strcpy(cfileName, LIBDIR);
  1818. strncat(cfileName, SLASH_MWMRC, MAXWMPATH - strlen(cfileName));
  1819. fileP = fopen (cfileName, "r");
  1820. }
  1821. else
  1822. {
  1823. strcpy(cfileName, DTLIBDIR);
  1824. strncat(cfileName, RC_DEFAULT_CONFIG_SUBDIR,
  1825. MAXWMPATH - strlen(cfileName));
  1826. strncat(cfileName, SLASH_DT_WMRC, MAXWMPATH - strlen(cfileName));
  1827. fileP = fopen (cfileName, "r");
  1828. }
  1829. }
  1830. }
  1831. if (!fileP)
  1832. {
  1833. char *pch;
  1834. /*
  1835. * handle "<host>:<path>" form of file name
  1836. */
  1837. pch = (char *) GetNetworkFileName (cfileName);
  1838. if ((fileP = fopen (cfileName, "r")) != NULL)
  1839. {
  1840. strncpy (cfileName, pch, MAXWMPATH);
  1841. XtFree (pch);
  1842. }
  1843. /*
  1844. * Either not "<host>:<path>" form or there was a
  1845. * problem up above. This is the last attempt to
  1846. * open something.
  1847. */
  1848. if (!fileP)
  1849. {
  1850. fileP = fopen (cfileName, "r");
  1851. }
  1852. }
  1853. if (!pConfigStack)
  1854. {
  1855. ConfigStackInit (cfileName);
  1856. }
  1857. if (wmGD.cppCommand && *wmGD.cppCommand)
  1858. {
  1859. /*
  1860. * Run the file through the C-preprocessor
  1861. */
  1862. PreprocessConfigFile ();
  1863. if (pConfigStackTop && pConfigStackTop->cppName)
  1864. {
  1865. if(fileP) {
  1866. fclose(fileP);
  1867. }
  1868. /* open the result */
  1869. fileP = fopen (pConfigStackTop->cppName, "r");
  1870. }
  1871. }
  1872. if (LANG != NULL)
  1873. {
  1874. XtFree(LANG);
  1875. LANG = NULL;
  1876. }
  1877. return (fileP);
  1878. } /* END OF FUNCTION FopenConfigFile */
  1879. /*************************************<->*************************************
  1880. *
  1881. * SaveMenuAccelerators (pSD, newMenuSpec)
  1882. *
  1883. *
  1884. * Description:
  1885. * -----------
  1886. * This function saves the MenuSpec pointer in pSD->acceleratorMenuSpecs.
  1887. *
  1888. *
  1889. * Inputs:
  1890. * ------
  1891. * newMenuSpec = pointer to MenuSpec to be saved.
  1892. * pSD->acceleratorMenuSpecs =
  1893. * pSD->acceleratorMenuCount =
  1894. *
  1895. *
  1896. * Outputs:
  1897. * -------
  1898. * pSD->acceleratorMenuSpecs = possibly updated
  1899. * pSD->acceleratorMenuCount = possibly updated
  1900. *
  1901. *
  1902. * Comments:
  1903. * --------
  1904. * We assume only MenuSpecs created within ProcessWmFile() are to be saved.
  1905. * Otherwise, we may cause override the limits of pSD->acceleratorMenuSpecs.
  1906. *
  1907. *************************************<->***********************************/
  1908. void SaveMenuAccelerators (WmScreenData *pSD, MenuSpec *newMenuSpec)
  1909. {
  1910. MenuSpec **pMenuSpec;
  1911. pMenuSpec = pSD->acceleratorMenuSpecs;
  1912. if (pMenuSpec == NULL)
  1913. return;
  1914. while ((*pMenuSpec != NULL) && (*pMenuSpec != newMenuSpec))
  1915. {
  1916. pMenuSpec++;
  1917. }
  1918. if (*pMenuSpec == NULL)
  1919. {
  1920. *pMenuSpec = newMenuSpec;
  1921. pSD->acceleratorMenuCount++;
  1922. }
  1923. } /* END OF FUNCTION SaveMenuAccelerators */
  1924. /*************************************<->*************************************
  1925. *
  1926. * ParseMenuSet (pSD, lineP)
  1927. *
  1928. *
  1929. * Description:
  1930. * -----------
  1931. * Menu pane specification found. Parse the following syntax:
  1932. *
  1933. * v
  1934. * Menu menu_pane_name
  1935. * {
  1936. * label [mnemonic] [accelerator] function
  1937. * label [mnemonic] [accelerator] function
  1938. * ...
  1939. * label [mnemonic] [accelerator] function
  1940. * }
  1941. *
  1942. *
  1943. * Inputs:
  1944. * ------
  1945. * cfileP = (global) file pointer to fopened configuration file or NULL
  1946. * lineP = pointer to menu name in line buffer
  1947. * line = (global) line buffer
  1948. * linec = (global) line count
  1949. * parseP = (global) parse string pointer if cfileP == NULL
  1950. * pSD->rootWindow = default root window of display
  1951. * wmGD.bitmapDirectory = bitmapDirectory resource value
  1952. * HOME = environment variable for home directory
  1953. *
  1954. *
  1955. * Outputs:
  1956. * -------
  1957. * linec = (global) line count incremented
  1958. * parseP = (global) parse string pointer if cfileP == NULL
  1959. * pSD->menuSpecs = list of menu specifications
  1960. *
  1961. *
  1962. * Comments:
  1963. * --------
  1964. * Skips unnamed menu specifications.
  1965. * This means custom menu specifications can be distinguished by NULL name.
  1966. *
  1967. *************************************<->***********************************/
  1968. static void ParseMenuSet (WmScreenData *pSD, unsigned char *lineP)
  1969. {
  1970. unsigned char *string;
  1971. MenuSpec *menuSpec;
  1972. /*
  1973. * If menu name is NULL then skip this pane specification.
  1974. */
  1975. if ((string = GetString (&lineP)) == NULL)
  1976. {
  1977. return;
  1978. }
  1979. /*
  1980. * Allocate space for the menu specification structure.
  1981. */
  1982. if ((menuSpec = (MenuSpec *)XtMalloc (sizeof (MenuSpec))) == NULL)
  1983. {
  1984. PWarning (((char *)GETMESSAGE(60, 9, "Insufficient memory for menu")));
  1985. return;
  1986. }
  1987. menuSpec->currentContext = 0;
  1988. menuSpec->menuWidget = NULL;
  1989. menuSpec->whichButton = SELECT_BUTTON; /* Button1 selection default */
  1990. menuSpec->menuItems = NULL;
  1991. menuSpec->accelContext = 0;
  1992. menuSpec->accelKeySpecs = NULL;
  1993. menuSpec->nextMenuSpec = NULL;
  1994. /*
  1995. * Allocate and fill space for the menu name.
  1996. */
  1997. if ((menuSpec->name =
  1998. (String)XtMalloc ((unsigned int) (strlen ((char *)string) + 1)))
  1999. == NULL)
  2000. {
  2001. PWarning (((char *)GETMESSAGE(60, 10, "Insufficient memory for menu")));
  2002. XtFree ((char *)menuSpec);
  2003. return;
  2004. }
  2005. strcpy (menuSpec->name, (char *)string);
  2006. /*
  2007. * Add the empty structure to the head of the menu specification list.
  2008. */
  2009. menuSpec->nextMenuSpec = pSD->menuSpecs;
  2010. pSD->menuSpecs = menuSpec;
  2011. /*
  2012. * Require leading '{' on the next line.
  2013. */
  2014. while ((GetNextLine () != NULL)) /* not EOF nor read error */
  2015. {
  2016. lineP = line;
  2017. ScanWhitespace(&lineP);
  2018. if ((lineP == NULL) || (*line == '!') || (*lineP == '\0') || (*lineP == '#'))
  2019. /* ignore empty or comment line */
  2020. {
  2021. continue;
  2022. }
  2023. if (*lineP == '{')
  2024. /* found '{' */
  2025. {
  2026. break;
  2027. }
  2028. /* not a '{' */
  2029. PWarning (((char *)GETMESSAGE(60, 11, "Expected '{' after menu name")));
  2030. return;
  2031. }
  2032. /*
  2033. * Found leading "{" or EOF.
  2034. * Parse menu item specifications until "}" or EOF found.
  2035. */
  2036. menuSpec->menuItems = PARSE_MENU_ITEMS (pSD, menuSpec);
  2037. } /* END OF FUNCTION ParseMenuSet */
  2038. /*************************************<->*************************************
  2039. *
  2040. * MenuItem *
  2041. * ParseMwmMenuStr (pSD, menuStr)
  2042. *
  2043. *
  2044. * Description:
  2045. * -----------
  2046. * This function parses a WMW_MENU string and returns a list of
  2047. * MenuItems structures. The string should have the syntax:
  2048. *
  2049. * label [mnemonic] [accelerator] function
  2050. * label [mnemonic] [accelerator] function
  2051. * ...
  2052. * label [mnemonic] [accelerator] function
  2053. *
  2054. *
  2055. * Inputs:
  2056. * ------
  2057. * line = (global) line buffer
  2058. * pSD->rootWindow = default root window of display
  2059. * wmGD.bitmapDirectory = bitmapDirectory resource value
  2060. * HOME = environment variable for home directory
  2061. * functionTable = window manager function parse table
  2062. *
  2063. *
  2064. * Outputs:
  2065. * -------
  2066. * Return = list of MenuItem structures or NULL
  2067. *
  2068. *
  2069. * Comments:
  2070. * --------
  2071. * None.
  2072. *
  2073. *************************************<->***********************************/
  2074. MenuItem *ParseMwmMenuStr (WmScreenData *pSD, unsigned char *menuStr)
  2075. {
  2076. cfileP = NULL;
  2077. linec = 0;
  2078. parseP = menuStr;
  2079. return (PARSE_MENU_ITEMS (pSD, NULL));
  2080. } /* END OF FUNCTION ParseMwmMenuStr */
  2081. /*************************************<->*************************************
  2082. *
  2083. * static MenuItem *
  2084. * ParseMenuItems (pSD, menuSpec)
  2085. *
  2086. *
  2087. * Description:
  2088. * -----------
  2089. * Parse menu item specifications:
  2090. *
  2091. * label [mnemonic] [accelerator] function
  2092. * label [mnemonic] [accelerator] function
  2093. * ...
  2094. * label [mnemonic] [accelerator] function
  2095. * [}]
  2096. *
  2097. *
  2098. * Inputs:
  2099. * ------
  2100. * pSD = pointer to screen data
  2101. * cfileP = (global) file pointer to fopened configuration file or NULL
  2102. * line = (global) line buffer
  2103. * linec = (global) line count
  2104. * parseP = (global) parse string pointer if cfileP == NULL
  2105. * pSD->rootWindow = default root window of display
  2106. * wmGD.bitmapDirectory = bitmapDirectory resource value
  2107. * HOME = environment variable for home directory
  2108. *
  2109. *
  2110. * Outputs:
  2111. * -------
  2112. * linec = (global) line count incremented
  2113. * parseP = (global) parse string pointer if cfileP == NULL
  2114. * Return = list of MenuItem structures or NULL
  2115. *
  2116. *
  2117. * Comments:
  2118. * --------
  2119. * None.
  2120. *
  2121. *************************************<->***********************************/
  2122. static MenuItem *ParseMenuItems (WmScreenData *pSD)
  2123. {
  2124. unsigned char *string;
  2125. unsigned char *lineP;
  2126. MenuItem *firstMenuItem;
  2127. MenuItem *lastMenuItem;
  2128. MenuItem *menuItem;
  2129. int ix;
  2130. /*
  2131. * Parse "label [mnemonic] [accelerator] function" or
  2132. * "<client command>[.<client command>]*"
  2133. * lines until "}" or EOF found.
  2134. */
  2135. firstMenuItem = lastMenuItem = NULL;
  2136. while ((GetNextLine () != NULL))
  2137. {
  2138. lineP = line;
  2139. if ((*line == '!') || (*line == '#') || (string = GetString (&lineP)) == NULL)
  2140. /* ignore empty or comment lines */
  2141. {
  2142. continue;
  2143. }
  2144. if (*string == '}') /* finished with menu set. */
  2145. {
  2146. break;
  2147. }
  2148. /*
  2149. * Allocate space for the menu item structure.
  2150. */
  2151. if ((menuItem = (MenuItem *)XtMalloc (sizeof (MenuItem))) == NULL)
  2152. {
  2153. PWarning (((char *)GETMESSAGE(60, 12, "Insufficient memory for menu item")));
  2154. continue;
  2155. }
  2156. menuItem->nextMenuItem = NULL;
  2157. menuItem->wmFunction = (WmFunction)NULL;
  2158. menuItem->wmFuncArgs = NULL;
  2159. {
  2160. /*
  2161. * Parse the menu item label.
  2162. */
  2163. if (!ParseWmLabel (pSD, menuItem, string))
  2164. {
  2165. XtFree ((char *)menuItem);
  2166. continue;
  2167. }
  2168. }
  2169. /*
  2170. * Parse any menu function mnemonic.
  2171. */
  2172. ParseWmMnemonic (&lineP, menuItem);
  2173. /*
  2174. * Parse any menu function accelerator.
  2175. */
  2176. if (!ParseWmAccelerator (&lineP, menuItem))
  2177. {
  2178. XtFree ((char *)menuItem);
  2179. continue;
  2180. }
  2181. /*
  2182. * Parse the menu function name if this is not a client
  2183. * command. If it is a client command, then the wmFunction
  2184. * field should already be set, as well as the ix variable,
  2185. * but we do want to search for a menu item name that occupies
  2186. * the same place as the function does for normal menu items.
  2187. */
  2188. ix = ParseWmFunction (&lineP, CRS_MENU, &menuItem->wmFunction);
  2189. /*
  2190. * Determine context sensitivity and applicability mask.
  2191. */
  2192. menuItem->greyedContext = functionTable[ix].greyedContext;
  2193. menuItem->mgtMask = functionTable[ix].mgtMask;
  2194. if ((menuItem->wmFunction == F_Toggle_Front_Panel) &&
  2195. ((wmGD.useFrontPanel == False) ||
  2196. (wmGD.dtSD != pSD)))
  2197. {
  2198. /*
  2199. * disallow this function if there's no front
  2200. * panel on this screen.
  2201. */
  2202. menuItem->greyedContext |= (F_CONTEXT_ALL |
  2203. F_SUBCONTEXT_IB_WICON |
  2204. F_SUBCONTEXT_IB_IICON);
  2205. }
  2206. /*
  2207. * Apply the function argument parser.
  2208. */
  2209. if (!(*(functionTable [ix].parseProc))
  2210. (&lineP, menuItem->wmFunction, &menuItem->wmFuncArgs))
  2211. {
  2212. FreeMenuItem (menuItem);
  2213. continue; /* skip this menu item */
  2214. }
  2215. /*
  2216. * Add this item to the menu specification.
  2217. */
  2218. if (lastMenuItem != NULL) /* not first */
  2219. {
  2220. lastMenuItem->nextMenuItem = menuItem;
  2221. }
  2222. else
  2223. {
  2224. firstMenuItem = menuItem;
  2225. }
  2226. lastMenuItem = menuItem;
  2227. }
  2228. return (firstMenuItem);
  2229. } /* END OF FUNCTION ParseMenuItems */
  2230. /*************************************<->*************************************
  2231. *
  2232. * ParseWmLabel (pSD, menuItem, string)
  2233. *
  2234. *
  2235. * Description:
  2236. * -----------
  2237. * Parse a menu label string.
  2238. *
  2239. *
  2240. * Inputs:
  2241. * ------
  2242. * pSD = pointer to screen data
  2243. * menuItem = pointer to MenuItem structure
  2244. * string = label string
  2245. *
  2246. *
  2247. * Outputs:
  2248. * -------
  2249. * menuItem->label
  2250. * menuItem->labelType
  2251. * menuItem->labelBitmapCache
  2252. * Return = boolean, FALSE iff insufficient memory
  2253. *
  2254. *
  2255. * Comments:
  2256. * --------
  2257. * We have two label types: XmSTRING and XmPIXMAP
  2258. * We allocate and fill the label field with string and set the type to
  2259. * XmSTRING. If string = "@<bitmap_file>", and <bitmap_file> contains a
  2260. * with which to build a label image we save the bitmap in the MenuItem
  2261. * structure and set the type to XmPIXMAP.
  2262. *
  2263. *************************************<->***********************************/
  2264. static Boolean ParseWmLabel (WmScreenData *pSD, MenuItem *menuItem,
  2265. unsigned char *string)
  2266. {
  2267. /*
  2268. * Allocate the label field and copy string.
  2269. */
  2270. if ((menuItem->label = (String)
  2271. XtMalloc ((unsigned int)(strlen ((char *)string) + 1))) == NULL)
  2272. {
  2273. PWarning (((char *)GETMESSAGE(60, 13, "Insufficient memory for menu item")));
  2274. return (FALSE);
  2275. }
  2276. strcpy (menuItem->label, (char *)string);
  2277. menuItem->labelType = XmSTRING;
  2278. if (*string == '@')
  2279. /*
  2280. * Here: string = "@<bitmap file>"
  2281. * Try to find the label bitmap in the bitmap cache or read the label
  2282. * bitmap file.
  2283. */
  2284. {
  2285. string++; /* skip "@" */
  2286. if ((menuItem->labelBitmapIndex = GetBitmapIndex (pSD,
  2287. (char *)string, True)) >= 0)
  2288. {
  2289. menuItem->labelType = XmPIXMAP;
  2290. }
  2291. }
  2292. return (TRUE);
  2293. } /* END OF FUNCTION ParseWmLabel */
  2294. /*************************************<->*************************************
  2295. *
  2296. * ParseWmMnemonic (linePP, menuItem)
  2297. *
  2298. *
  2299. * Description:
  2300. * -----------
  2301. * Parse an optional menu function mnemonic.
  2302. *
  2303. *
  2304. * Inputs:
  2305. * ------
  2306. * linePP = pointer to current line buffer pointer.
  2307. * menuItem = pointer to MenuItem structure
  2308. *
  2309. *
  2310. * Outputs:
  2311. * -------
  2312. * linePP = pointer to revised line buffer pointer.
  2313. * menuItem->mnemonic = valid mnemonic character or NULL.
  2314. *
  2315. *
  2316. * Comments:
  2317. * --------
  2318. * None.
  2319. *
  2320. *************************************<->***********************************/
  2321. static void ParseWmMnemonic (unsigned char **linePP, MenuItem *menuItem)
  2322. {
  2323. unsigned char *lineP = *linePP;
  2324. unsigned char *mnemonic;
  2325. /*
  2326. * Skip leading white space.
  2327. */
  2328. ScanWhitespace (&lineP);
  2329. menuItem->mnemonic = (KeySym)NULL;
  2330. if (*lineP == '_')
  2331. /*
  2332. * We have a mnemonic specification.
  2333. * Get the next string (we only use the first character).
  2334. * If no string exists, the labelType is not XmSTRING, or does not contain
  2335. * the first character, then skip the string and return.
  2336. * Otherwise, accept the first character as a mnemonic.
  2337. */
  2338. {
  2339. KeySym ks;
  2340. lineP++;
  2341. mnemonic = GetString(&lineP);
  2342. if (menuItem->labelType == XmSTRING &&
  2343. mnemonic != NULL &&
  2344. (ks = XStringToKeysym((char *)mnemonic)) != NoSymbol &&
  2345. strchr(menuItem->label, (char)(ks & 0xff)) != NULL)
  2346. {
  2347. menuItem->mnemonic = ks;
  2348. }
  2349. else
  2350. {
  2351. PWarning (((char *)GETMESSAGE(60, 14, "Invalid mnemonic specification")));
  2352. }
  2353. }
  2354. *linePP = lineP; /* consume any string */
  2355. } /* END OF FUNCTION ParseWmMnemonic */
  2356. /*************************************<->*************************************
  2357. *
  2358. * ParseWmAccelerator (linePP, menuItem)
  2359. *
  2360. *
  2361. * Description:
  2362. * -----------
  2363. * Parse an optional menu function accelerator.
  2364. *
  2365. *
  2366. * Inputs:
  2367. * ------
  2368. * linePP = pointer to current line buffer pointer.
  2369. * menuItem = pointer to MenuItem structure
  2370. *
  2371. *
  2372. * Outputs:
  2373. * -------
  2374. * linePP = pointer to revised line buffer pointer.
  2375. * menuItem->accelText = pointer to an accelerator string or NULL.
  2376. *
  2377. *
  2378. * Comments:
  2379. * --------
  2380. * None.
  2381. *
  2382. *************************************<->***********************************/
  2383. static Boolean ParseWmAccelerator (unsigned char **linePP, MenuItem *menuItem)
  2384. {
  2385. unsigned char *lineP;
  2386. String string;
  2387. unsigned int eventType;
  2388. unsigned int state;
  2389. KeyCode keycode;
  2390. Boolean status;
  2391. menuItem->accelState = 0;
  2392. menuItem->accelKeyCode = 0;
  2393. menuItem->accelText = NULL;
  2394. status = TRUE;
  2395. /*
  2396. * If linePP contains NULL, then abort.
  2397. */
  2398. if (*linePP == (unsigned char *) NULL) return(FALSE);
  2399. /*
  2400. * Skip leading white space.
  2401. */
  2402. ScanWhitespace (linePP);
  2403. lineP = *linePP;
  2404. /*
  2405. * If the second character is not ".", and an accelerator specification
  2406. * exists, then process and save the specification string.
  2407. */
  2408. if ((*lineP != '\0') && /* something follows */
  2409. (*lineP != '!') && /* skip if we have the ! WmFunction */
  2410. (*lineP != 'f') &&
  2411. (*(lineP+1) != '.')) /* skip if we have f.xxx WmFunction */
  2412. {
  2413. if (ParseKeyEvent(&lineP, &eventType, &keycode, &state))
  2414. {
  2415. if ((string = (String) XtMalloc
  2416. ((unsigned int) (lineP - *linePP + 1))) == NULL)
  2417. {
  2418. PWarning (((char *)GETMESSAGE(60, 15, "Insufficient memory for accelerator specification")));
  2419. status = FALSE;
  2420. }
  2421. else
  2422. /*
  2423. * Save the accelerator state and keycode.
  2424. * Process and save the accelerator text.
  2425. */
  2426. {
  2427. ProcessAccelText (*linePP, lineP, (unsigned char *) string);
  2428. menuItem->accelState = state;
  2429. menuItem->accelKeyCode = keycode;
  2430. menuItem->accelText = string;
  2431. }
  2432. }
  2433. else
  2434. {
  2435. PWarning (((char *)GETMESSAGE(60, 16, "Invalid accelerator specification")));
  2436. status = FALSE;
  2437. }
  2438. *linePP = lineP; /* consume the specification */
  2439. }
  2440. return (status);
  2441. } /* END OF FUNCTION ParseWmAccelerator */
  2442. /*************************************<->*************************************
  2443. *
  2444. * int
  2445. * ParseWmFunction (linePP, res_spec, pWmFunction)
  2446. *
  2447. *
  2448. * Description:
  2449. * -----------
  2450. * Parse a button, key, or menu function name and return its function table
  2451. * index.
  2452. *
  2453. *
  2454. * Inputs:
  2455. * ------
  2456. * linePP = pointer to current line buffer pointer.
  2457. * res_spec = resource specification type (key, button, or menu).
  2458. * pWmFunction = pointer to window manager function destination.
  2459. * functionTable = window manager function parse table
  2460. *
  2461. *
  2462. * Outputs:
  2463. * -------
  2464. * linePP = pointer to revised line buffer pointer.
  2465. * pWmFunction = pointer to parsed window manager function.
  2466. * Return = function table index of parsed function.
  2467. *
  2468. *
  2469. * Comments:
  2470. * --------
  2471. * Uses F_Nop if the function name or resource type is invalid.
  2472. *
  2473. *************************************<->***********************************/
  2474. int ParseWmFunction (unsigned char **linePP, unsigned int res_spec,
  2475. WmFunction *pWmFunction)
  2476. {
  2477. unsigned char *lineP = *linePP;
  2478. unsigned char *string;
  2479. int low, mid, high, cmp;
  2480. /*
  2481. * Skip leading white space.
  2482. */
  2483. ScanWhitespace (&lineP);
  2484. /*
  2485. * Have function string (may be NULL or a comment).
  2486. * Handle the special case of '!'
  2487. */
  2488. if (*lineP == '!')
  2489. {
  2490. *linePP = ++lineP;
  2491. *pWmFunction = F_Exec;
  2492. return (F_EXEC_INDEX);
  2493. }
  2494. /*
  2495. * Identify the function corresponding to the specified name.
  2496. * Try binary search of the window manager function parse table.
  2497. * Assume f.nop if the function and resource type cannot be matched.
  2498. * This handles NULL and comment strings, bad function names, and functions
  2499. * in inappropriate resource sets.
  2500. */
  2501. string = GetString (&lineP);
  2502. *linePP = lineP;
  2503. if (string != NULL)
  2504. {
  2505. ToLower ((char *)string);
  2506. low = 0;
  2507. high = WMFUNCTIONTABLESIZE - 1;
  2508. while (low <= high)
  2509. {
  2510. mid = (low + high)/2;
  2511. cmp = strcmp (functionTable[mid].funcName, (char *)string);
  2512. if (!cmp)
  2513. /*
  2514. * Function name match
  2515. * Require proper resource type for the function.
  2516. */
  2517. {
  2518. if (res_spec & functionTable[mid].resource)
  2519. {
  2520. *pWmFunction = functionTable[mid].wmFunction;
  2521. return (mid);
  2522. }
  2523. /* invalid resource: use F_Nop */
  2524. break;
  2525. }
  2526. /*
  2527. * Function name mismatch
  2528. */
  2529. if (cmp > 0)
  2530. {
  2531. high = mid - 1;
  2532. }
  2533. else
  2534. {
  2535. low = mid + 1;
  2536. }
  2537. }
  2538. }
  2539. /*
  2540. * Not found: assume f.nop
  2541. */
  2542. *pWmFunction = F_Nop;
  2543. return (F_NOP_INDEX);
  2544. } /* END OF FUNCTION ParseWmFunction */
  2545. /*************************************<->*************************************
  2546. *
  2547. * ParseWmFuncMaybeStrArg (linePP, wmFunction, pArgs)
  2548. *
  2549. *
  2550. * Description:
  2551. * -----------
  2552. * Parses a window manager function with a null or string argument.
  2553. *
  2554. *
  2555. * Inputs:
  2556. * ------
  2557. * linePP = pointer to current line buffer pointer.
  2558. * wmFunction = function (not used).
  2559. * pArgs = pointer to argument destination.
  2560. *
  2561. *
  2562. * Outputs:
  2563. * -------
  2564. * linePP = pointer to revised line buffer pointer.
  2565. * pArgs = pointer to parsed argument string.
  2566. * Return = FALSE iff insufficient memory
  2567. *
  2568. *
  2569. * Comments:
  2570. * --------
  2571. * Only used to parse arguments for F_Lower, F_Raise, and F_Raise_Lower.
  2572. * If it is used for any other function, be sure to change FreeMenuItem ()
  2573. * accordingly.
  2574. *
  2575. *************************************<->***********************************/
  2576. Boolean ParseWmFuncMaybeStrArg (unsigned char **linePP,
  2577. WmFunction wmFunction, String *pArgs)
  2578. {
  2579. unsigned char *string = *linePP;
  2580. unsigned int len;
  2581. ScanWhitespace (&string);
  2582. /*
  2583. if (*lineP == '-')
  2584. {
  2585. *linePP = ++lineP;
  2586. return (ParseWmFuncStrArg (linePP, wmFunction, pArgs));
  2587. }
  2588. */
  2589. #if 0
  2590. else if (*lineP == '"' && *(lineP+1) == '-')
  2591. {
  2592. /* kill off '-' */
  2593. strcpy ((char *) (lineP+1), (char *) (lineP+2));
  2594. return (ParseWmFuncStrArg (linePP, wmFunction, pArgs));
  2595. }
  2596. #endif
  2597. if ((len = strlen ((char *)string)) != 0)
  2598. {
  2599. if ((*pArgs = (String)XtMalloc (len + 1)) == NULL)
  2600. {
  2601. PWarning (((char *)GETMESSAGE(60, 17, "Insufficient memory")));
  2602. return (FALSE);
  2603. }
  2604. strcpy (*pArgs, (char *)string);
  2605. return (TRUE);
  2606. }
  2607. else
  2608. /* Do ParseWmFuncNoArg () */
  2609. {
  2610. *pArgs = NULL;
  2611. return (TRUE);
  2612. }
  2613. } /* END OF FUNCTION ParseWmFuncMaybeStrArg */
  2614. /*************************************<->*************************************
  2615. *
  2616. * ParseWmFuncNoArg (linePP, wmFunction, pArgs)
  2617. *
  2618. *
  2619. * Description:
  2620. * -----------
  2621. * Parses a window manager function null argument.
  2622. *
  2623. *
  2624. * Inputs:
  2625. * ------
  2626. * linePP = pointer to current line buffer pointer.
  2627. * wmFunction = function (not used).
  2628. * pArgs = pointer to argument destination.
  2629. *
  2630. *
  2631. * Outputs:
  2632. * -------
  2633. * linePP = unchanged
  2634. * pArgs = NULL
  2635. * Return = TRUE
  2636. *
  2637. *
  2638. * Comments:
  2639. * --------
  2640. * None.
  2641. *
  2642. *************************************<->***********************************/
  2643. static Boolean ParseWmFuncNoArg (unsigned char **linePP, WmFunction wmFunction,
  2644. String *pArgs)
  2645. {
  2646. *pArgs = NULL;
  2647. return (TRUE);
  2648. } /* END OF FUNCTION ParseWmFuncNoArg */
  2649. /*************************************<->*************************************
  2650. *
  2651. * ParseWmFuncStrArg (linePP, wmFunction, pArgs)
  2652. *
  2653. *
  2654. * Description:
  2655. * -----------
  2656. * Parses a window manager function string argument.
  2657. *
  2658. *
  2659. * Inputs:
  2660. * ------
  2661. * linePP = pointer to current line buffer pointer.
  2662. * wmFunction = function for which the argument string is intended.
  2663. * pArgs = pointer to argument string destination.
  2664. *
  2665. *
  2666. * Outputs:
  2667. * -------
  2668. * linePP = pointer to revised line buffer pointer.
  2669. * pArgs = pointer to parsed argument string.
  2670. * Return = FALSE iff insufficient memory
  2671. *
  2672. *
  2673. * Comments:
  2674. * --------
  2675. * Insures that an argument for F_Exec() ends in '&' .
  2676. * Only used to parse arguments for F_Exec, F_Menu, F_Lower, F_Raise,
  2677. * F_Raise_Lower, and F_Screen. If it is used for any other function, be
  2678. * sure to change FreeMenuItem () accordingly.
  2679. *
  2680. *************************************<->***********************************/
  2681. Boolean ParseWmFuncStrArg (unsigned char **linePP,
  2682. WmFunction wmFunction, String *pArgs)
  2683. {
  2684. unsigned char *string;
  2685. unsigned int len;
  2686. char *p;
  2687. wchar_t last;
  2688. char delim;
  2689. wchar_t wdelim;
  2690. int lastlen;
  2691. if ((string = GetString (linePP)) != NULL)
  2692. /* nonNULL string argument */
  2693. {
  2694. len = strlen ((char *)string);
  2695. if ((*pArgs = (String)XtMalloc (len + 2)) == NULL)
  2696. {
  2697. PWarning (((char *)GETMESSAGE(60, 17, "Insufficient memory")));
  2698. return (FALSE);
  2699. }
  2700. strcpy (*pArgs, (char *)string);
  2701. /*
  2702. * Insure that an argument for F_Exec ends in '&' .
  2703. */
  2704. if (wmFunction == F_Exec)
  2705. {
  2706. lastlen = 0;
  2707. p = *pArgs;
  2708. while (*p &&
  2709. ((len = mblen(p, MB_CUR_MAX)) > 0))
  2710. {
  2711. mbtowc(&last, p, MB_CUR_MAX);
  2712. lastlen = len;
  2713. p += len;
  2714. }
  2715. delim = '&';
  2716. mbtowc(&wdelim, &delim, MB_CUR_MAX);
  2717. if (lastlen == 1 && last != wdelim)
  2718. {
  2719. *p++ = '&';
  2720. *p = '\0';
  2721. }
  2722. }
  2723. }
  2724. else
  2725. /* NULL string argument */
  2726. {
  2727. *pArgs = NULL;
  2728. }
  2729. return (TRUE);
  2730. } /* END OF FUNCTION ParseWmFuncStrArg */
  2731. /*************************************<->*************************************
  2732. *
  2733. * FreeMenuItem (menuItem)
  2734. *
  2735. *
  2736. * Description:
  2737. * -----------
  2738. * This procedure destroys a MenuItem structure.
  2739. *
  2740. *
  2741. * Inputs:
  2742. * ------
  2743. * menuItem = to be destroyed.
  2744. *
  2745. *
  2746. * Outputs:
  2747. * -------
  2748. * None.
  2749. *
  2750. *
  2751. * Comments:
  2752. * --------
  2753. * Assumes that ParseWmFuncStrArg () has parsed a menu item's function
  2754. * argument only for F_Exec, F_Menu, F_Lower, F_Raise, F_Raise_Lower, and
  2755. * F_Screen. If it is used for other functions, be sure to include them here!
  2756. *
  2757. *************************************<->***********************************/
  2758. void FreeMenuItem (MenuItem *menuItem)
  2759. {
  2760. if (menuItem->label != NULL)
  2761. {
  2762. XtFree ((char *)menuItem->label);
  2763. }
  2764. if (menuItem->accelText != NULL)
  2765. {
  2766. XtFree ((char *)menuItem->accelText);
  2767. }
  2768. /*
  2769. * If menuItem->wmFuncArgs is nonNULL, we assume that it is a string that
  2770. * was malloc'ed in ParseWmFuncStrArg () and we free it now.
  2771. */
  2772. if ((menuItem->wmFuncArgs != NULL) &&
  2773. ((menuItem->wmFunction == F_Exec) ||
  2774. (menuItem->wmFunction == F_Menu) ||
  2775. (menuItem->wmFunction == F_Lower) ||
  2776. (menuItem->wmFunction == F_Raise) ||
  2777. (menuItem->wmFunction == F_Raise_Lower) ||
  2778. (menuItem->wmFunction == F_Screen)))
  2779. {
  2780. XtFree ((char *)menuItem->wmFuncArgs);
  2781. }
  2782. XtFree ((char *)menuItem);
  2783. } /* END OF FUNCTION FreeMenuItem */
  2784. /*************************************<->*************************************
  2785. *
  2786. * ParseWmFuncGrpArg (linePP, wmFunction, pGroup)
  2787. *
  2788. *
  2789. * Description:
  2790. * -----------
  2791. * Parses a window manager function group argument.
  2792. *
  2793. *
  2794. * Inputs:
  2795. * ------
  2796. * linePP = pointer to current line buffer pointer.
  2797. * wmFunction = function for which the group argument is intended.
  2798. * pGroup = pointer to group argument destination.
  2799. *
  2800. *
  2801. * Outputs:
  2802. * -------
  2803. * linePP = pointer to revised line buffer pointer.
  2804. * pGroup = pointer to parsed group argument.
  2805. * Return = FALSE iff invalid group argument.
  2806. *
  2807. *
  2808. * Comments:
  2809. * --------
  2810. * The only valid nonNULL arguments are "icon", "window", and "transient".
  2811. *
  2812. *************************************<->***********************************/
  2813. static Boolean ParseWmFuncGrpArg (unsigned char **linePP,
  2814. WmFunction wmFunction, GroupArg *pGroup)
  2815. {
  2816. unsigned char *lineP = *linePP;
  2817. unsigned char *startP;
  2818. unsigned char grpStr[MAX_GROUP_STRLEN+1];
  2819. int len;
  2820. /*
  2821. * Parse groups while each is followed by "|".
  2822. */
  2823. *pGroup = 0;
  2824. while (1)
  2825. {
  2826. /*
  2827. * Skip whitespace and find next group string.
  2828. */
  2829. ScanWhitespace (&lineP);
  2830. startP = lineP;
  2831. ScanAlphanumeric (&lineP);
  2832. if (startP == lineP)
  2833. /* Group missing => use default or complain */
  2834. {
  2835. if (*pGroup)
  2836. {
  2837. PWarning (((char *)GETMESSAGE(60, 18, "Missing group specification")));
  2838. return (FALSE);
  2839. }
  2840. else
  2841. {
  2842. *pGroup = F_GROUP_DEFAULT;
  2843. break;
  2844. }
  2845. }
  2846. /*
  2847. * Found a group string; compare it with valid groups.
  2848. */
  2849. len = min (lineP - startP, MAX_GROUP_STRLEN);
  2850. (void) strncpy ((char *)grpStr, (char *)startP, len);
  2851. grpStr[len] = '\0';
  2852. ToLower ((char *)grpStr);
  2853. if (!strcmp ("icon", (char *)grpStr))
  2854. {
  2855. *pGroup |= F_GROUP_ICON;
  2856. }
  2857. else if (!strcmp ("window", (char *)grpStr))
  2858. {
  2859. *pGroup |= F_GROUP_WINDOW;
  2860. }
  2861. else if (!strcmp ("transient", (char *)grpStr))
  2862. {
  2863. *pGroup |= F_GROUP_TRANSIENT;
  2864. }
  2865. else
  2866. /* Unknown group name */
  2867. {
  2868. PWarning (((char *)GETMESSAGE(60, 19, "Invalid group specification")));
  2869. return (FALSE);
  2870. }
  2871. /*
  2872. * Continue processing until the line is exhausted.
  2873. * Skip any '|' .
  2874. */
  2875. ScanWhitespace (&lineP);
  2876. if (lineP == NULL || *lineP == '\0')
  2877. {
  2878. break;
  2879. }
  2880. else if (*lineP == '|')
  2881. {
  2882. lineP++;
  2883. }
  2884. }
  2885. *linePP = lineP;
  2886. return (TRUE);
  2887. } /* END OF FUNCTION ParseWmFuncGrpArg */
  2888. /*************************************<->*************************************
  2889. *
  2890. * ParseWmFuncNbrArg (linePP, wmFunction, pNumber)
  2891. *
  2892. *
  2893. * Description:
  2894. * -----------
  2895. * Parses a window manager function number argument.
  2896. *
  2897. *
  2898. * Inputs:
  2899. * ------
  2900. * linePP = pointer to current line buffer pointer.
  2901. * wmFunction = function
  2902. * pNumber = pointer to number argument destination.
  2903. *
  2904. *
  2905. * Outputs:
  2906. * -------
  2907. * linePP = pointer to revised line buffer pointer.
  2908. * pNumber = pointer to parsed number argument.
  2909. * Return = FALSE iff invalid number argument.
  2910. *
  2911. *
  2912. * Comments:
  2913. * --------
  2914. * None.
  2915. *
  2916. *************************************<->***********************************/
  2917. static Boolean ParseWmFuncNbrArg (unsigned char **linePP,
  2918. WmFunction wmFunction,
  2919. unsigned long *pNumber)
  2920. {
  2921. int val;
  2922. val = StrToNum (GetString (linePP));
  2923. if (val == -1)
  2924. {
  2925. PWarning (((char *)GETMESSAGE(60, 20, "Invalid number specification")));
  2926. *pNumber = 0;
  2927. return (FALSE);
  2928. }
  2929. *pNumber = val;
  2930. return (TRUE);
  2931. } /* END OF FUNCTION ParseWmFuncNbrArg */
  2932. /*************************************<->*************************************
  2933. *
  2934. * ParseButtonStr ()
  2935. *
  2936. *
  2937. * Description:
  2938. * -----------
  2939. * This function parses a button set specification string:
  2940. *
  2941. * bindings_name
  2942. * {
  2943. * button context function
  2944. * button context function
  2945. * ...
  2946. * button context function
  2947. * }
  2948. *
  2949. *
  2950. *
  2951. * Inputs:
  2952. * ------
  2953. * pSD->buttonBindings = buttonBindings resource value
  2954. * functionTable = window manager function parse table
  2955. *
  2956. *
  2957. * Outputs:
  2958. * -------
  2959. * pSD->buttonSpecs = list of button binding specifications.
  2960. *
  2961. *
  2962. * Comments:
  2963. * --------
  2964. * The button set specification name must match pSD->buttonBindings.
  2965. *
  2966. *************************************<->***********************************/
  2967. void ParseButtonStr (WmScreenData *pSD, unsigned char *buttonStr)
  2968. {
  2969. unsigned char *lineP;
  2970. cfileP = NULL;
  2971. linec = 0;
  2972. if (((parseP = buttonStr) != NULL) && (GetNextLine () != NULL))
  2973. {
  2974. lineP = line;
  2975. ParseButtonSet (pSD, lineP);
  2976. }
  2977. } /* END OF FUNCTION ParseButtonStr */
  2978. /*************************************<->*************************************
  2979. *
  2980. * ParseButtonSet (pSD, lineP)
  2981. *
  2982. *
  2983. * Description:
  2984. * -----------
  2985. * Button set specification found. Parse the following syntax:
  2986. *
  2987. * v
  2988. * Buttons bindings_name
  2989. * {
  2990. * button context function
  2991. * button context function
  2992. * ...
  2993. * button context function
  2994. * }
  2995. *
  2996. *
  2997. * Inputs:
  2998. * ------
  2999. * cfileP = (global) file pointer to fopened configuration file or NULL
  3000. * line = (global) line buffer
  3001. * lineP = pointer to current character in line buffer
  3002. * pSD->buttonBindings = buttonBindings resource value
  3003. *
  3004. *
  3005. * Outputs:
  3006. * -------
  3007. * lineP = pointer to current character in line buffer
  3008. * pSD->buttonSpecs = list of button binding specifications.
  3009. *
  3010. *
  3011. * Comments:
  3012. * --------
  3013. * Skips unnamed button binding set and sets with names that don't match
  3014. * the buttonBindings resource.
  3015. * Skips bad button binding specifications.
  3016. *
  3017. *************************************<->***********************************/
  3018. static void ParseButtonSet (WmScreenData *pSD, unsigned char *lineP)
  3019. {
  3020. unsigned char *string;
  3021. ButtonSpec *buttonSpec;
  3022. ButtonSpec *lastButtonSpec;
  3023. int ix;
  3024. /*
  3025. * Parse the button set bindings from the configuration file.
  3026. * If either the button set name or buttonBindings resource is NULL or
  3027. * they don't match, then skip this button specification.
  3028. */
  3029. if (((string = GetString (&lineP)) == NULL) ||
  3030. (pSD->buttonBindings == NULL) ||
  3031. strcmp ((char *)string, pSD->buttonBindings))
  3032. {
  3033. return;
  3034. }
  3035. /*
  3036. * Require leading '{' on the next line.
  3037. */
  3038. while ((GetNextLine () != NULL)) /* not EOF nor read error */
  3039. {
  3040. lineP = line;
  3041. ScanWhitespace(&lineP);
  3042. if ((lineP == NULL) || (*line == '!') || (*lineP == '\0') || (*lineP == '#'))
  3043. /* ignore empty or comment line */
  3044. {
  3045. continue;
  3046. }
  3047. if (*lineP == '{')
  3048. /* found '{' */
  3049. {
  3050. break;
  3051. }
  3052. /* not a '{' */
  3053. PWarning (((char *)GETMESSAGE(60, 21, "Expected '{' after button set name")));
  3054. return;
  3055. }
  3056. /*
  3057. * Found leading "{" or EOF.
  3058. * Prepare to accumulate button bindings by finding the end of
  3059. * the button specification list.
  3060. * lastButtonSpec will be NULL only if no prior bindings exist.
  3061. */
  3062. lastButtonSpec = pSD->buttonSpecs;
  3063. if (lastButtonSpec != NULL)
  3064. {
  3065. while (lastButtonSpec->nextButtonSpec != NULL)
  3066. {
  3067. lastButtonSpec = (lastButtonSpec->nextButtonSpec);
  3068. }
  3069. }
  3070. /*
  3071. * Parse "button context function" until "}" or EOF found.
  3072. * Skips bad button binding specifications.
  3073. */
  3074. while ((GetNextLine () != NULL)) /* not EOF nor read error */
  3075. {
  3076. lineP = line;
  3077. ScanWhitespace(&lineP);
  3078. if ((lineP == NULL) || (*line == '!') || (*lineP == '\0') || (*lineP == '#'))
  3079. /* ignore empty or comment lines */
  3080. {
  3081. continue;
  3082. }
  3083. if (*lineP == '}') /* finished with button set */
  3084. {
  3085. break;
  3086. }
  3087. /*
  3088. * Allocate space for the button binding specification.
  3089. */
  3090. if ((buttonSpec = (ButtonSpec *)XtMalloc (sizeof (ButtonSpec))) == NULL)
  3091. {
  3092. PWarning (((char *)GETMESSAGE(60, 22, "Insufficient memory for button specification")));
  3093. continue;
  3094. }
  3095. buttonSpec->wmFunction = (WmFunction)NULL;
  3096. buttonSpec->wmFuncArgs = NULL;
  3097. buttonSpec->nextButtonSpec = NULL;
  3098. /*
  3099. * Parse the button specification "button".
  3100. */
  3101. lineP = line;
  3102. if (!ParseBtnEvent(&lineP,
  3103. &buttonSpec->eventType,
  3104. &buttonSpec->button,
  3105. &buttonSpec->state,
  3106. &buttonSpec->click))
  3107. {
  3108. PWarning (((char *)GETMESSAGE(60, 23, "Invalid button specification")));
  3109. XtFree ((char *)buttonSpec);
  3110. continue; /* skip this button specification */
  3111. }
  3112. /*
  3113. * Parse the button context.
  3114. */
  3115. if (!ParseContext(&lineP, &buttonSpec->context,
  3116. &buttonSpec->subContext))
  3117. {
  3118. PWarning (((char *)GETMESSAGE(60, 24, "Invalid button context")));
  3119. XtFree ((char *)buttonSpec);
  3120. continue; /* skip this button specification */
  3121. }
  3122. /*
  3123. * Parse the button function and any arguments.
  3124. */
  3125. ix = ParseWmFunction (&lineP, CRS_BUTTON, &buttonSpec->wmFunction);
  3126. /*
  3127. * remove any subContexts that don't apply to this function
  3128. */
  3129. if ((functionTable[ix].greyedContext & F_SUBCONTEXT_IB_IICON) &&
  3130. (buttonSpec->subContext & F_SUBCONTEXT_IB_IICON))
  3131. {
  3132. buttonSpec->subContext &= ~F_SUBCONTEXT_IB_IICON;
  3133. }
  3134. if ((functionTable[ix].greyedContext & F_SUBCONTEXT_IB_WICON) &&
  3135. (buttonSpec->subContext & F_SUBCONTEXT_IB_WICON))
  3136. {
  3137. buttonSpec->subContext &= ~F_SUBCONTEXT_IB_WICON;
  3138. }
  3139. /*
  3140. * Map Button3 menus to BMenu virtual button
  3141. */
  3142. if (buttonSpec->button == Button3 &&
  3143. (buttonSpec->wmFunction == F_Menu ||
  3144. buttonSpec->wmFunction == F_Post_SMenu)) {
  3145. buttonSpec->button = wmGD.bMenuButton;
  3146. }
  3147. /*
  3148. * Apply the function argument parser.
  3149. */
  3150. if (!(*(functionTable [ix].parseProc))
  3151. (&lineP, buttonSpec->wmFunction, &buttonSpec->wmFuncArgs))
  3152. {
  3153. XtFree ((char *)buttonSpec);
  3154. continue; /* skip this button specification */
  3155. }
  3156. /*
  3157. * Add the button specification to the button specification list.
  3158. */
  3159. if (lastButtonSpec != NULL)
  3160. /* a prior specification exists */
  3161. {
  3162. lastButtonSpec->nextButtonSpec = buttonSpec;
  3163. }
  3164. else
  3165. {
  3166. pSD->buttonSpecs = buttonSpec;
  3167. }
  3168. lastButtonSpec = buttonSpec;
  3169. }
  3170. } /* END OF FUNCTION ParseButtonSet */
  3171. /*************************************<->*************************************
  3172. *
  3173. * ParseContext (linePP, context, subContext)
  3174. *
  3175. *
  3176. * Description:
  3177. * -----------
  3178. * Parses a general context string.
  3179. *
  3180. *
  3181. * Inputs:
  3182. * ------
  3183. * linePP = pointer to current line buffer pointer.
  3184. *
  3185. * Outputs:
  3186. * -------
  3187. * linePP = pointer to revised line buffer pointer.
  3188. * context = context field value
  3189. * subContext = subContext field value
  3190. * Return = (Boolean) true iff valid context string
  3191. *
  3192. *
  3193. * Comments:
  3194. * --------
  3195. * None.
  3196. *
  3197. *************************************<->***********************************/
  3198. static Boolean ParseContext (unsigned char **linePP, Context *context,
  3199. Context *subContext)
  3200. {
  3201. unsigned char *lineP = *linePP;
  3202. unsigned char *startP;
  3203. unsigned char ctxStr[MAX_CONTEXT_STRLEN+1];
  3204. int len;
  3205. /*
  3206. * Parse contexts while each is followed by "|".
  3207. */
  3208. *context = 0;
  3209. *subContext = 0;
  3210. while (1) {
  3211. /*
  3212. * Skip whitespace and find next context string.
  3213. */
  3214. ScanWhitespace (&lineP);
  3215. startP = lineP;
  3216. ScanAlphanumeric (&lineP);
  3217. if (startP == lineP)
  3218. /* ERROR: Context missing */
  3219. {
  3220. return (FALSE);
  3221. }
  3222. /*
  3223. * Found nonNULL string; compare it with valid contexts.
  3224. */
  3225. len = min(lineP - startP, MAX_CONTEXT_STRLEN);
  3226. (void) strncpy ((char *)ctxStr, (char *)startP, len);
  3227. ctxStr[len] = '\0';
  3228. ToLower ((char *)ctxStr);
  3229. if (!strcmp ("root", (char *)ctxStr))
  3230. {
  3231. *context |= F_CONTEXT_ROOT;
  3232. *subContext |= F_SUBCONTEXT_R_ALL;
  3233. }
  3234. else if (!strcmp ("icon", (char *)ctxStr))
  3235. {
  3236. *context |= (F_CONTEXT_ICON |
  3237. F_CONTEXT_ICONBOX |
  3238. F_SUBCONTEXT_IB_IICON |
  3239. F_SUBCONTEXT_IB_WICON );
  3240. *subContext |= (F_SUBCONTEXT_I_ALL |
  3241. F_SUBCONTEXT_IB_IICON |
  3242. F_SUBCONTEXT_IB_WICON );
  3243. }
  3244. else if (!strcmp ("window", (char *)ctxStr))
  3245. {
  3246. *context |= F_CONTEXT_WINDOW;
  3247. *subContext |= F_SUBCONTEXT_W_ALL;
  3248. }
  3249. else if (!strcmp ("frame", (char *)ctxStr))
  3250. {
  3251. *context |= F_CONTEXT_WINDOW;
  3252. *subContext |= F_SUBCONTEXT_W_FRAME;
  3253. }
  3254. else if (!strcmp ("title", (char *)ctxStr))
  3255. {
  3256. *context |= F_CONTEXT_WINDOW;
  3257. *subContext |= F_SUBCONTEXT_W_TITLE;
  3258. }
  3259. else if (!strcmp ("border", (char *)ctxStr))
  3260. {
  3261. *context |= F_CONTEXT_WINDOW;
  3262. *subContext |= F_SUBCONTEXT_W_BORDER;
  3263. }
  3264. else if (!strcmp ("app", (char *)ctxStr))
  3265. {
  3266. *context |= F_CONTEXT_WINDOW;
  3267. *subContext |= F_SUBCONTEXT_W_APP;
  3268. }
  3269. else if (!strcmp ("ifkey", (char *)ctxStr))
  3270. {
  3271. *context |= F_CONTEXT_IFKEY;
  3272. }
  3273. else
  3274. /* Unknown context name */
  3275. {
  3276. return (FALSE);
  3277. }
  3278. /* continue only if followed by '|' */
  3279. ScanWhitespace (&lineP);
  3280. if (*lineP != '|')
  3281. {
  3282. break;
  3283. }
  3284. lineP++;
  3285. }
  3286. *linePP = lineP;
  3287. return (TRUE);
  3288. } /* END OF FUNCTION ParseContext */
  3289. /*************************************<->*************************************
  3290. *
  3291. * ParseKeyStr ()
  3292. *
  3293. *
  3294. * Description:
  3295. * -----------
  3296. * This function parses a key set specification string:
  3297. *
  3298. * bindings_name
  3299. * {
  3300. * key context function
  3301. * key context function
  3302. * ...
  3303. * key context function
  3304. * }
  3305. *
  3306. *
  3307. * Inputs:
  3308. * ------
  3309. * pSD->keyBindings = keyBindings resource value
  3310. * functionTable = window manager function parse table
  3311. *
  3312. *
  3313. * Outputs:
  3314. * -------
  3315. * pSD->keySpecs = list of key binding specification
  3316. *
  3317. *
  3318. * Comments:
  3319. * --------
  3320. * The key set specification name must match pSD->keyBindings.
  3321. *
  3322. *************************************<->***********************************/
  3323. void
  3324. ParseKeyStr (WmScreenData *pSD, unsigned char *keyStr)
  3325. {
  3326. unsigned char *lineP;
  3327. cfileP = NULL;
  3328. linec = 0;
  3329. if (((parseP = keyStr) != NULL) && (GetNextLine () != NULL))
  3330. {
  3331. lineP = line;
  3332. ParseKeySet (pSD, lineP);
  3333. }
  3334. } /* END OF FUNCTION ParseKeyStr */
  3335. /*************************************<->*************************************
  3336. *
  3337. * ParseKeySet (pSD, lineP)
  3338. *
  3339. *
  3340. * Description:
  3341. * -----------
  3342. * Key set specification found. Parse the following syntax:
  3343. *
  3344. * v
  3345. * Keys bindings_name
  3346. * {
  3347. * key context function
  3348. * key context function
  3349. * ...
  3350. * key context function
  3351. * }
  3352. *
  3353. *
  3354. * Inputs:
  3355. * ------
  3356. * cfileP = (global) file pointer to fopened configuration file or NULL
  3357. * line = (global) line buffer
  3358. * lineP = pointer to current character in line buffer
  3359. * pSD->keyBindings = keyBindings resource value
  3360. *
  3361. *
  3362. * Outputs:
  3363. * -------
  3364. * lineP = pointer to current character in line buffer
  3365. * pSD->keySpecs = list of key binding specifications.
  3366. *
  3367. *
  3368. * Comments:
  3369. * --------
  3370. * Skips unnamed key binding set and sets with names that don't match the
  3371. * keyBindings resource.
  3372. * Skips bad key binding specifications.
  3373. *
  3374. *************************************<->***********************************/
  3375. static void ParseKeySet (WmScreenData *pSD, unsigned char *lineP)
  3376. {
  3377. unsigned char *string;
  3378. KeySpec *keySpec;
  3379. KeySpec *lastKeySpec;
  3380. unsigned int eventType;
  3381. int ix;
  3382. Boolean bBadKey;
  3383. /*
  3384. * Parse the key set bindings from the configuration file.
  3385. * If either the key set name or keyBindings resource is NULL or they
  3386. * don't match then skip this key specification.
  3387. */
  3388. if (((string = GetString (&lineP)) == NULL) ||
  3389. (pSD->keyBindings == NULL) ||
  3390. strcmp ((char *)string, pSD->keyBindings))
  3391. {
  3392. return;
  3393. }
  3394. /*
  3395. * Require leading '{' on next line.
  3396. */
  3397. while ((GetNextLine () != NULL)) /* not EOF nor read error */
  3398. {
  3399. lineP = line;
  3400. ScanWhitespace(&lineP);
  3401. if ((lineP == NULL) || (*line == '!') || (*lineP == '\0') || (*lineP == '#'))
  3402. /* ignore empty or comment line */
  3403. {
  3404. continue;
  3405. }
  3406. if (*lineP == '{')
  3407. /* found '{' */
  3408. {
  3409. break;
  3410. }
  3411. /* not a '{' */
  3412. PWarning (((char *)GETMESSAGE(60, 25, "Expected '{' after key set name")));
  3413. return;
  3414. }
  3415. /*
  3416. * Found leading "{" or EOF.
  3417. * Prepare to accumulate key bindings by finding the end of
  3418. * the key specification list.
  3419. * lastKeySpec will be NULL only if no prior bindings exist.
  3420. */
  3421. lastKeySpec = pSD->keySpecs;
  3422. if (lastKeySpec != NULL)
  3423. {
  3424. while (lastKeySpec->nextKeySpec != NULL)
  3425. {
  3426. lastKeySpec = (lastKeySpec->nextKeySpec);
  3427. }
  3428. }
  3429. /*
  3430. * Parse "key context function" until "}" or EOF found.
  3431. * Skip bad key bindings.
  3432. */
  3433. while ((GetNextLine () != NULL)) /* not EOF nor read error */
  3434. {
  3435. lineP = line;
  3436. ScanWhitespace (&lineP);
  3437. if ((lineP == NULL) || (*line == '!') || (*lineP == '\0') || (*lineP == '#'))
  3438. /* ignore empty or comment lines */
  3439. {
  3440. continue;
  3441. }
  3442. if (*lineP == '}') /* finished with key set */
  3443. {
  3444. break;
  3445. }
  3446. /*
  3447. * Allocate space for the key specification.
  3448. */
  3449. if ((keySpec = (KeySpec *)XtMalloc (sizeof (KeySpec))) == NULL)
  3450. {
  3451. PWarning (((char *)GETMESSAGE(60, 26, "Insufficient memory for key specification")));
  3452. continue;
  3453. }
  3454. keySpec->wmFunction = (WmFunction)NULL;
  3455. keySpec->wmFuncArgs = NULL;
  3456. keySpec->nextKeySpec = NULL;
  3457. /*
  3458. * Parse the key specification.
  3459. */
  3460. bBadKey = False;
  3461. if (!ParseKeyEvent(&lineP,
  3462. &eventType,
  3463. &keySpec->keycode,
  3464. &keySpec->state))
  3465. {
  3466. bBadKey = True;
  3467. }
  3468. /*
  3469. * Parse the key context.
  3470. * Here lineP points to the candidate context string.
  3471. */
  3472. if (!ParseContext(&lineP, &keySpec->context,
  3473. &keySpec->subContext))
  3474. {
  3475. if (bBadKey)
  3476. PWarning (((char *)GETMESSAGE(60, 27, "Invalid key specification")));
  3477. PWarning (((char *)GETMESSAGE(60, 28, "Invalid key context")));
  3478. XtFree ((char *)keySpec);
  3479. continue; /* skip this key specification */
  3480. }
  3481. if (bBadKey)
  3482. {
  3483. /*
  3484. * Don't print an error message if this is a "hardware
  3485. * available" binding.
  3486. */
  3487. if (!(keySpec->context & F_CONTEXT_IFKEY))
  3488. PWarning (((char *)GETMESSAGE(60, 27, "Invalid key specification")));
  3489. XtFree ((char *)keySpec);
  3490. continue; /* skip this key specification */
  3491. }
  3492. /*
  3493. * This flag is only used for parsing, clear it so the
  3494. * rest of the program doesn't see it.
  3495. */
  3496. keySpec->context &= ~F_CONTEXT_IFKEY;
  3497. /*
  3498. * Parse the key function and any arguments.
  3499. */
  3500. ix = ParseWmFunction (&lineP, CRS_KEY, &keySpec->wmFunction);
  3501. /*
  3502. * remove any subContexts that don't apply to this function
  3503. */
  3504. if ((functionTable[ix].greyedContext & F_SUBCONTEXT_IB_IICON) &&
  3505. (keySpec->subContext & F_SUBCONTEXT_IB_IICON))
  3506. {
  3507. keySpec->subContext &= ~F_SUBCONTEXT_IB_IICON;
  3508. }
  3509. if ((functionTable[ix].greyedContext & F_SUBCONTEXT_IB_WICON) &&
  3510. (keySpec->subContext & F_SUBCONTEXT_IB_WICON))
  3511. {
  3512. keySpec->subContext &= ~F_SUBCONTEXT_IB_WICON;
  3513. }
  3514. /*
  3515. * Apply the function argument parser.
  3516. */
  3517. if (!(*(functionTable [ix].parseProc))
  3518. (&lineP, keySpec->wmFunction, &keySpec->wmFuncArgs))
  3519. {
  3520. XtFree ((char *)keySpec);
  3521. continue; /* skip this key specification */
  3522. }
  3523. /*
  3524. * Add the key specification to the key specification list.
  3525. */
  3526. if (lastKeySpec != NULL)
  3527. /* a prior specification exists */
  3528. {
  3529. lastKeySpec->nextKeySpec = keySpec;
  3530. }
  3531. else
  3532. {
  3533. pSD->keySpecs = keySpec;
  3534. }
  3535. lastKeySpec = keySpec;
  3536. }
  3537. } /* END OF FUNCTION ParseKeySet */
  3538. /*************************************<->*************************************
  3539. *
  3540. * ParseBtnEvent (linePP, eventType, button, state, fClick)
  3541. *
  3542. *
  3543. * Description:
  3544. * -----------
  3545. * Parse a button event specification.
  3546. *
  3547. *
  3548. * Inputs:
  3549. * ------
  3550. * linePP = pointer to current line buffer pointer
  3551. * buttonEvents = (global) button event parse table
  3552. * modifierStrings = (global) modifier string/mask table
  3553. *
  3554. *
  3555. * Outputs:
  3556. * -------
  3557. * linePP = pointer to revised line buffer pointer.
  3558. * eventType = type of event
  3559. * button = parsed button number
  3560. * state = composite modifier mask
  3561. * fClick = is click?
  3562. *
  3563. * Return = (Boolean) true iff valid button event specification
  3564. *
  3565. *
  3566. * Comments:
  3567. * --------
  3568. * None.
  3569. *
  3570. *************************************<->***********************************/
  3571. Boolean ParseBtnEvent (unsigned char **linePP,
  3572. unsigned int *eventType,
  3573. unsigned int *button,
  3574. unsigned int *state,
  3575. Boolean *fClick)
  3576. {
  3577. if (!ParseEvent (linePP, buttonEvents, eventType, button, state, fClick))
  3578. {
  3579. return (FALSE);
  3580. }
  3581. /*
  3582. * The following is a fix for an X11 deficiency in regards to
  3583. * modifiers in grabs.
  3584. */
  3585. if (*eventType == ButtonRelease)
  3586. {
  3587. /* the button that is going up will always be in the modifiers... */
  3588. *state |= buttonModifierMasks[*button];
  3589. }
  3590. return (TRUE);
  3591. } /* END OF FUNCTION ParseBtnEvent */
  3592. /*************************************<->*************************************
  3593. *
  3594. * ParseKeyEvent (linePP, eventType, keyCode, state)
  3595. *
  3596. *
  3597. * Description:
  3598. * -----------
  3599. * Parse a key event specification.
  3600. *
  3601. *
  3602. * Inputs:
  3603. * ------
  3604. * linePP = pointer to current line buffer pointer
  3605. * keyEvents = (global) key event parse table
  3606. * modifierStrings = (global) modifier string/mask table
  3607. *
  3608. *
  3609. * Outputs:
  3610. * -------
  3611. * linePP = pointer to revised line buffer pointer.
  3612. * eventType = type of event
  3613. * keyCode = parsed KeyCode
  3614. * state = composite modifier mask
  3615. *
  3616. * Return = (Boolean) true iff valid key event specification
  3617. *
  3618. *
  3619. * Comments:
  3620. * --------
  3621. * None.
  3622. *
  3623. *************************************<->***********************************/
  3624. Boolean ParseKeyEvent (unsigned char **linePP, unsigned int *eventType,
  3625. KeyCode *keyCode, unsigned int *state)
  3626. {
  3627. Boolean fClick;
  3628. unsigned int keySym = 0;
  3629. if (!ParseEvent (linePP, keyEvents, eventType, &keySym, state, &fClick))
  3630. {
  3631. return (FALSE);
  3632. }
  3633. /*
  3634. * Here keySym is a KeySym. Convert it to a KeyCode.
  3635. * KeyCode will be set to 0 if keySym is not defined for any KeyCode
  3636. * (e.g. 0x001).
  3637. */
  3638. *keyCode = XKeysymToKeycode(DISPLAY, (KeySym) keySym);
  3639. if (*keyCode == 0)
  3640. {
  3641. if (keySym == XK_F9)
  3642. {
  3643. keySym = XK_KP_F1;
  3644. }
  3645. else if (keySym == XK_F10)
  3646. {
  3647. keySym = XK_KP_F2;
  3648. }
  3649. else if (keySym == XK_F11)
  3650. {
  3651. keySym = XK_KP_F3;
  3652. }
  3653. else if (keySym == XK_F12)
  3654. {
  3655. keySym = XK_KP_F4;
  3656. }
  3657. *keyCode = XKeysymToKeycode(DISPLAY, (KeySym) keySym);
  3658. }
  3659. return (*keyCode != 0);
  3660. } /* END OF FUNCTION ParseKeyEvent */
  3661. /*************************************<->*************************************
  3662. *
  3663. * ParseEvent (linePP, table, eventType, detail, state, fClick)
  3664. *
  3665. *
  3666. * Description:
  3667. * -----------
  3668. * Parse an event specification.
  3669. *
  3670. *
  3671. * Inputs:
  3672. * ------
  3673. * linePP = pointer to current line buffer pointer.
  3674. * table = event parse table
  3675. * modifierStrings = (global) modifier string/mask table
  3676. *
  3677. *
  3678. * Outputs:
  3679. * -------
  3680. * linePP = pointer to revised line buffer pointer.
  3681. * eventType = type of event
  3682. * detail = dependent upon parse table detail procedure and closure
  3683. * state = composite modifier mask
  3684. * fClick = click flag
  3685. *
  3686. * Return = (Boolean) true iff valid event specification
  3687. *
  3688. * Comments:
  3689. * --------
  3690. * None.
  3691. *
  3692. *************************************<->***********************************/
  3693. static Boolean ParseEvent (unsigned char **linePP, EventTableEntry *table,
  3694. unsigned int *eventType, unsigned int *detail,
  3695. unsigned int *state, Boolean *fClick)
  3696. {
  3697. unsigned char *lineP = *linePP;
  3698. Cardinal ix;
  3699. Boolean status;
  3700. /* Parse the modifiers */
  3701. if (!ParseModifiers (&lineP, state) || *lineP != '<')
  3702. {
  3703. return (FALSE);
  3704. }
  3705. lineP++; /* skip '<' */
  3706. /* Parse the event type */
  3707. if (!ParseEventType (&lineP, table, eventType, &ix) || *lineP != '>')
  3708. {
  3709. return (FALSE);
  3710. }
  3711. lineP++; /* skip '>' */
  3712. /*
  3713. * Compute detail and fClick.
  3714. * Status will be False for a invalid KeySym name.
  3715. */
  3716. status = (*(table[ix].parseProc))(&lineP, table[ix].closure, detail);
  3717. *fClick = table[ix].fClick;
  3718. if (status)
  3719. {
  3720. *linePP = lineP;
  3721. }
  3722. return (status);
  3723. } /* END OF FUNCTION ParseEvent */
  3724. /*************************************<->*************************************
  3725. *
  3726. * ParseModifiers(linePP, state)
  3727. *
  3728. *
  3729. * Description:
  3730. * -----------
  3731. * Parses a modifier specification.
  3732. *
  3733. *
  3734. * Inputs:
  3735. * ------
  3736. * linePP = pointer to current line buffer pointer.
  3737. * modifierStrings = (global) modifier string/mask table
  3738. *
  3739. *
  3740. * Outputs:
  3741. * -------
  3742. * linePP = pointer to revised line buffer pointer.
  3743. * state = composite modifier mask
  3744. * Return = (Boolean) true iff valid modifier name
  3745. *
  3746. *
  3747. * Comments:
  3748. * --------
  3749. * If successful, will be followed by NULL or '<'.
  3750. *
  3751. *************************************<->***********************************/
  3752. static Boolean ParseModifiers(unsigned char **linePP, unsigned int *state)
  3753. {
  3754. unsigned char *lineP = *linePP;
  3755. unsigned char *startP;
  3756. unsigned char modStr[MAX_MODIFIER_STRLEN+1];
  3757. Boolean fNot;
  3758. unsigned int maskBit;
  3759. int len;
  3760. *state = 0;
  3761. /*
  3762. * Parse modifiers until the event specifier is encountered.
  3763. */
  3764. ScanWhitespace (&lineP);
  3765. while ((*lineP != '\0') && (*lineP != '<'))
  3766. {
  3767. if (*lineP == '~')
  3768. {
  3769. fNot = TRUE;
  3770. lineP++;
  3771. }
  3772. else
  3773. {
  3774. fNot = FALSE;
  3775. }
  3776. startP = lineP;
  3777. ScanAlphanumeric (&lineP);
  3778. if (startP == lineP)
  3779. /* ERROR: Modifier or '<' missing */
  3780. {
  3781. return (FALSE);
  3782. }
  3783. len = min(lineP - startP, MAX_MODIFIER_STRLEN);
  3784. (void) strncpy ((char *)modStr, (char *)startP, len);
  3785. modStr[len] = '\0';
  3786. if (!LookupModifier (modStr, &maskBit))
  3787. /* Unknown modifier name */
  3788. {
  3789. return (FALSE);
  3790. }
  3791. if (fNot)
  3792. {
  3793. *state &= ~maskBit;
  3794. }
  3795. else
  3796. {
  3797. *state |= maskBit;
  3798. }
  3799. ScanWhitespace(&lineP);
  3800. }
  3801. *linePP = lineP;
  3802. return (TRUE); /* must have '<' or NULL following */
  3803. } /* END OF FUNCTION ParseModifiers */
  3804. /*************************************<->*************************************
  3805. *
  3806. * LookupModifier (name, valueP)
  3807. *
  3808. *
  3809. * Description:
  3810. * -----------
  3811. * Return the modifier mask for the provided modifier name.
  3812. *
  3813. *
  3814. * Inputs:
  3815. * ------
  3816. * name = modifier string
  3817. * modifierStrings = modifier string/mask table
  3818. *
  3819. *
  3820. * Outputs:
  3821. * -------
  3822. * valueP = modifier mask
  3823. * Return = (Boolean) true iff valid modifier name
  3824. *
  3825. *
  3826. * Comments:
  3827. * --------
  3828. * None.
  3829. *
  3830. *************************************<->***********************************/
  3831. static Boolean LookupModifier (unsigned char *name, unsigned int *valueP)
  3832. {
  3833. int i;
  3834. if (name != NULL)
  3835. {
  3836. ToLower ((char *)name);
  3837. for (i=0; modifierStrings[i].name != NULL; i++)
  3838. {
  3839. if (!strcmp (modifierStrings[i].name, (char *)name))
  3840. {
  3841. *valueP = modifierStrings[i].mask;
  3842. return (TRUE);
  3843. }
  3844. }
  3845. }
  3846. return (FALSE);
  3847. } /* END OF FUNCTION LookupModifier */
  3848. /*************************************<->*************************************
  3849. *
  3850. * ParseEventType(linePP, table, eventType, ix)
  3851. *
  3852. *
  3853. * Description:
  3854. * -----------
  3855. * Parses the event type string.
  3856. *
  3857. *
  3858. * Inputs:
  3859. * ------
  3860. * linePP = pointer to current line buffer pointer.
  3861. * table = event parse table
  3862. *
  3863. *
  3864. * Outputs:
  3865. * -------
  3866. * linePP = pointer to revised line buffer pointer.
  3867. * eventType = type of event
  3868. * ix = table index for matched event
  3869. *
  3870. * Return = (Boolean) true iff valid event
  3871. *
  3872. *
  3873. * Comments:
  3874. * --------
  3875. * None.
  3876. *
  3877. *************************************<->***********************************/
  3878. static Boolean ParseEventType (unsigned char **linePP, EventTableEntry *table,
  3879. unsigned int *eventType, Cardinal *ix)
  3880. {
  3881. unsigned char *lineP = *linePP;
  3882. unsigned char *startP = *linePP;
  3883. unsigned char eventTypeStr[MAX_EVENTTYPE_STRLEN+1];
  3884. int len;
  3885. /* Parse out the event string */
  3886. ScanAlphanumeric (&lineP);
  3887. /*
  3888. * Attempt to match the parsed event against our supported event set.
  3889. */
  3890. if (startP != lineP)
  3891. {
  3892. len = min (lineP - startP, MAX_EVENTTYPE_STRLEN);
  3893. (void) strncpy ((char *)eventTypeStr, (char *)startP, len);
  3894. eventTypeStr[len] = '\0';
  3895. ToLower ((char *)eventTypeStr);
  3896. for (len = 0; table[len].event != NULL; len++)
  3897. if (!strcmp (table[len].event, (char *)eventTypeStr))
  3898. {
  3899. *ix = len;
  3900. *eventType = table[*ix].eventType;
  3901. *linePP = lineP;
  3902. return (TRUE);
  3903. }
  3904. }
  3905. /* Unknown event specified */
  3906. return (FALSE);
  3907. } /* END OF FUNCTION ParseEventType */
  3908. /*************************************<->*************************************
  3909. *
  3910. * ParseImmed (linePP, closure, detail)
  3911. *
  3912. *
  3913. * Description:
  3914. * -----------
  3915. * Button event detail procedure.
  3916. *
  3917. *
  3918. * Inputs:
  3919. * ------
  3920. * linePP = not used
  3921. * closure = table entry
  3922. *
  3923. *
  3924. * Outputs:
  3925. * -------
  3926. * detail = pointer to closure
  3927. *
  3928. * Return = TRUE
  3929. *
  3930. *
  3931. * Comments:
  3932. * --------
  3933. * None.
  3934. *
  3935. *************************************<->***********************************/
  3936. static Boolean ParseImmed (unsigned char **linePP, unsigned int closure,
  3937. unsigned int *detail)
  3938. {
  3939. *detail = closure;
  3940. return (TRUE);
  3941. } /* END OF FUNCTION ParseImmed */
  3942. /*************************************<->*************************************
  3943. *
  3944. * ParseKeySym (linePP, closure, detail)
  3945. *
  3946. *
  3947. * Description:
  3948. * -----------
  3949. * Key event detail procedure. Parses a KeySym string.
  3950. *
  3951. *
  3952. * Inputs:
  3953. * ------
  3954. * linePP = pointer to current line buffer pointer
  3955. *
  3956. * closure = not used.
  3957. *
  3958. *
  3959. * Outputs:
  3960. * -------
  3961. * linePP = pointer to revised line buffer pointer
  3962. * detail = pointer to parsed KeySym
  3963. *
  3964. * Return = (Boolean) true iff valid KeySym string
  3965. *
  3966. *
  3967. * Comments:
  3968. * --------
  3969. * None.
  3970. *
  3971. *************************************<->***********************************/
  3972. static Boolean ParseKeySym (unsigned char **linePP, unsigned int closure,
  3973. unsigned int *detail)
  3974. {
  3975. unsigned char *lineP = *linePP;
  3976. unsigned char *startP;
  3977. char keySymName[MAX_KEYSYM_STRLEN+1];
  3978. int len;
  3979. int chlen;
  3980. ScanWhitespace (&lineP);
  3981. startP = lineP;
  3982. while (*lineP &&
  3983. ((chlen = mblen ((char *)lineP, MB_CUR_MAX)) > 0) &&
  3984. ((chlen > 1) ||
  3985. (!isspace (*lineP) && *lineP != ',' && *lineP != ':')))
  3986. {
  3987. /* Skip next character */
  3988. lineP += chlen;
  3989. }
  3990. len = min (lineP - startP, MAX_KEYSYM_STRLEN);
  3991. (void) strncpy (keySymName, (char *)startP, len);
  3992. keySymName[len] = '\0';
  3993. if ((*detail = XStringToKeysym(keySymName)) == NoSymbol &&
  3994. (mblen (keySymName, MB_CUR_MAX) == 1))
  3995. {
  3996. if (!isdigit (keySymName[0]) ||
  3997. ((*detail = StrToNum ((unsigned char *)&keySymName[0])) == -1))
  3998. {
  3999. *detail = NoSymbol;
  4000. return (FALSE);
  4001. }
  4002. }
  4003. *linePP = lineP;
  4004. return (TRUE);
  4005. } /* END OF FUNCTION ParseKeySym */
  4006. /*************************************<->*************************************
  4007. *
  4008. * StrToNum(str)
  4009. *
  4010. *
  4011. * Description:
  4012. * -----------
  4013. * Converts a string to an unsigned hexadecimal, decimal, or octal integer.
  4014. *
  4015. *
  4016. * Inputs:
  4017. * ------
  4018. * str = character string
  4019. *
  4020. *
  4021. * Outputs:
  4022. * -------
  4023. * Return = unsigned integer
  4024. *
  4025. *
  4026. * Comments:
  4027. * --------
  4028. * None.
  4029. *
  4030. *************************************<->***********************************/
  4031. static unsigned int StrToNum(unsigned char *str)
  4032. {
  4033. unsigned char c;
  4034. unsigned int val = 0;
  4035. if (*str == '0')
  4036. {
  4037. str++;
  4038. if (*str == 'x' || *str == 'X')
  4039. {
  4040. return (StrToHex(++str));
  4041. }
  4042. return (StrToOct(str));
  4043. }
  4044. while ((c = *str) != '\0')
  4045. {
  4046. if ('0' <= c && c <= '9')
  4047. {
  4048. val = val*10+c-'0';
  4049. }
  4050. else
  4051. {
  4052. return (-1);
  4053. }
  4054. str++;
  4055. }
  4056. return (val);
  4057. } /* END OF FUNCTION StrToNum */
  4058. /*************************************<->*************************************
  4059. *
  4060. *
  4061. *
  4062. * Description:
  4063. * -----------
  4064. *
  4065. * Inputs:
  4066. * ------
  4067. *
  4068. *
  4069. * Outputs:
  4070. * -------
  4071. *
  4072. * Comments:
  4073. * --------
  4074. * None.
  4075. *
  4076. *************************************<->***********************************/
  4077. static unsigned int StrToHex(unsigned char *str)
  4078. {
  4079. unsigned char c;
  4080. unsigned int val = 0;
  4081. while ((c = *str) != '\0')
  4082. {
  4083. if ('0' <= c && c <= '9')
  4084. {
  4085. val = val*16+c-'0';
  4086. }
  4087. else if ('a' <= c && c <= 'f')
  4088. {
  4089. val = val*16+c-'a'+10;
  4090. }
  4091. else if ('A' <= c && c <= 'F')
  4092. {
  4093. val = val*16+c-'A'+10;
  4094. }
  4095. else
  4096. {
  4097. return (-1);
  4098. }
  4099. str++;
  4100. }
  4101. return (val);
  4102. } /* END OF FUNCTION StrToHex */
  4103. /*************************************<->*************************************
  4104. *
  4105. *
  4106. *
  4107. * Description:
  4108. * -----------
  4109. *
  4110. * Inputs:
  4111. * ------
  4112. *
  4113. *
  4114. * Outputs:
  4115. * -------
  4116. *
  4117. * Comments:
  4118. * --------
  4119. * None.
  4120. *
  4121. *************************************<->***********************************/
  4122. static unsigned int StrToOct(unsigned char *str)
  4123. {
  4124. unsigned char c;
  4125. unsigned int val = 0;
  4126. while ((c = *str) != '\0')
  4127. {
  4128. if ('0' <= c && c <= '7')
  4129. {
  4130. val = val*8+c-'0';
  4131. }
  4132. else
  4133. {
  4134. return (-1);
  4135. }
  4136. str++;
  4137. }
  4138. return (val);
  4139. } /* END OF FUNCTION StrToOct */
  4140. /*************************************<->*************************************
  4141. *
  4142. * ScanAlphanumeric (linePP)
  4143. *
  4144. *
  4145. * Description:
  4146. * -----------
  4147. * Scan string until a non-alphanumeric character is encountered.
  4148. *
  4149. *
  4150. * Inputs:
  4151. * ------
  4152. * linePP = nonNULL pointer to current line buffer pointer
  4153. *
  4154. *
  4155. * Outputs:
  4156. * -------
  4157. * linePP = nonNULL pointer to revised line buffer pointer
  4158. *
  4159. *
  4160. * Comments:
  4161. * --------
  4162. * Assumes linePP is nonNULL
  4163. *
  4164. *************************************<->***********************************/
  4165. void ScanAlphanumeric (unsigned char **linePP)
  4166. {
  4167. int chlen;
  4168. while (*linePP &&
  4169. ((chlen = mblen ((char *) *linePP, MB_CUR_MAX)) > 0) &&
  4170. ((chlen > 1) || isalnum (**linePP)))
  4171. {
  4172. (*linePP) += chlen;
  4173. }
  4174. } /* END OF FUNCTION ScanAlphanumeric */
  4175. /*************************************<->*************************************
  4176. *
  4177. * PWarning (message)
  4178. *
  4179. *
  4180. * Description:
  4181. * -----------
  4182. * This function lists a resource description parse message to stderr.
  4183. *
  4184. *
  4185. * Inputs:
  4186. * ------
  4187. * message = pointer to a message string
  4188. * cfileP = (global) file pointer to fopened configuration file or NULL
  4189. * linec = (global) line counter
  4190. *
  4191. *************************************<->***********************************/
  4192. void
  4193. PWarning (char *message)
  4194. {
  4195. char pch[MAXWMPATH+1];
  4196. String sMessage;
  4197. char *pchFile;
  4198. sMessage = XtNewString ((String) message);
  4199. if (cfileP != NULL)
  4200. {
  4201. if (pConfigStackTop->fileName)
  4202. {
  4203. pchFile = pConfigStackTop->fileName;
  4204. }
  4205. else
  4206. {
  4207. pchFile = wmGD.configFile;
  4208. }
  4209. sprintf (pch, pWarningStringFile,
  4210. GETMESSAGE(20,1,"Workspace Manager"),
  4211. sMessage, linec, pchFile);
  4212. }
  4213. else
  4214. {
  4215. sprintf (pch, pWarningStringLine,
  4216. GETMESSAGE(20,1,"Workspace Manager"),
  4217. sMessage, linec);
  4218. }
  4219. _DtSimpleError (wmGD.mwmName, DtIgnore, NULL, pch, NULL);
  4220. XtFree (sMessage);
  4221. } /* END OF FUNCTION PWarning */
  4222. /*
  4223. * Key substitution table entry
  4224. */
  4225. typedef struct _keySubs
  4226. {
  4227. unsigned char * pchFrom;
  4228. int lenFrom;
  4229. unsigned char * pchTo;
  4230. } KeySub;
  4231. /*************************************<->*************************************
  4232. *
  4233. * InitKeySubs (ppKeySubs, pNumKeySubs)
  4234. *
  4235. *
  4236. * Description:
  4237. * -----------
  4238. * Initialize key label substitutions used in acclerator text
  4239. *
  4240. *
  4241. * Inputs:
  4242. * ------
  4243. * ppKeySubs = ptr to key substitution table ptr
  4244. * pNumKeySubs = ptr to number of key substitutions
  4245. *
  4246. *
  4247. * Outputs:
  4248. * -------
  4249. * *ppKeySubs = ptr to key substitution table
  4250. * *pNumKeySubs = number of substitutions found
  4251. *
  4252. * Comments:
  4253. * --------
  4254. * *ppKeySubs is allocated with XtMalloc in a complicated way.
  4255. * If this ever needs to be freed, a function to free it needs to
  4256. * be written.
  4257. *
  4258. *************************************<->***********************************/
  4259. static void InitKeySubs (
  4260. KeySub **ppKeySubs,
  4261. int *pNumKeySubs)
  4262. {
  4263. int numKS;
  4264. KeySub *pKS;
  4265. KeySub *pKSret;
  4266. unsigned char *pch0;
  4267. unsigned char *pch1;
  4268. int len;
  4269. int chlen;
  4270. pch0 = (unsigned char *)GETMESSAGE(60, 40, "");
  4271. if ((pch0 == NULL) || (*pch0 == '\0'))
  4272. {
  4273. *ppKeySubs = NULL;
  4274. *pNumKeySubs = 0;
  4275. return;
  4276. }
  4277. pKSret = NULL;
  4278. numKS = 0;
  4279. while (*pch0 != '\0')
  4280. {
  4281. ScanWhitespace (&pch0);
  4282. if (*pch0 == '\0') break;
  4283. /*
  4284. * allocate space for next key sub
  4285. */
  4286. if (pKSret == NULL)
  4287. {
  4288. pKSret = (KeySub *) XtMalloc (1*sizeof(KeySub));
  4289. }
  4290. else
  4291. {
  4292. pKSret = (KeySub *) XtRealloc ((char *)pKSret,
  4293. (numKS+1)*sizeof(KeySub));
  4294. }
  4295. pKS = &pKSret[numKS];
  4296. /* get "from" string */
  4297. pch1 = pch0;
  4298. while (*pch1 && ((chlen = mblen ((char *)pch1, MB_CUR_MAX)) > 0))
  4299. {
  4300. if ((chlen == 1) && (*pch1 == ' '))
  4301. {
  4302. break;
  4303. }
  4304. pch1 += chlen;
  4305. }
  4306. pKS->lenFrom = pch1 - pch0;
  4307. if (pKS->lenFrom < 1)
  4308. {
  4309. /*
  4310. * no "from" string
  4311. */
  4312. break;
  4313. }
  4314. pKS->pchFrom = (unsigned char *) XtMalloc (1+pKS->lenFrom);
  4315. memcpy (pKS->pchFrom, pch0, pKS->lenFrom);
  4316. pKS->pchFrom[pKS->lenFrom] = '\0';
  4317. /* get "to" string */
  4318. ScanWhitespace (&pch1);
  4319. pch0 = pch1;
  4320. while (*pch1 && ((chlen = mblen ((char *)pch1, MB_CUR_MAX)) > 0))
  4321. {
  4322. if ((chlen == 1) && (*pch1 == ' '))
  4323. {
  4324. break;
  4325. }
  4326. pch1 += chlen;
  4327. }
  4328. len = pch1 - pch0;
  4329. if (len < 1)
  4330. {
  4331. /*
  4332. * Invalid format, "from" string with no "to" string.
  4333. */
  4334. break;
  4335. }
  4336. pKS->pchTo = (unsigned char *) XtMalloc (1+len);
  4337. memcpy (pKS->pchTo, pch0, len);
  4338. pKS->pchTo[len] = '\0';
  4339. /* advance cursor */
  4340. pch0 = pch1;
  4341. /* got one, bump the counter */
  4342. numKS++;
  4343. }
  4344. *ppKeySubs = pKSret;
  4345. *pNumKeySubs = numKS;
  4346. }
  4347. /*************************************<->*************************************
  4348. *
  4349. * ProcessAccelText (startP, endP, destP)
  4350. *
  4351. *
  4352. * Description:
  4353. * -----------
  4354. * Process accelerator text and copy into string.
  4355. *
  4356. *
  4357. * Inputs:
  4358. * ------
  4359. * startP = pointer to start of valid accelerator specification
  4360. * endP = pointer past end of accelerator specification
  4361. * destP = pointer to destination buffer
  4362. *
  4363. *
  4364. * Outputs:
  4365. * -------
  4366. * Destination buffer has processed accelerator text.
  4367. *
  4368. * Comments:
  4369. * --------
  4370. * None.
  4371. *
  4372. *************************************<->***********************************/
  4373. static void ProcessAccelText (unsigned char *startP, unsigned char *endP,
  4374. unsigned char *destP)
  4375. {
  4376. int chlen;
  4377. static Boolean bAccelInit = False;
  4378. static KeySub *pKeySub;
  4379. static int numKeySubs;
  4380. unsigned char * pchFirst;
  4381. unsigned char * pchSub;
  4382. int lenSub;
  4383. int i;
  4384. if (!bAccelInit)
  4385. {
  4386. InitKeySubs (&pKeySub, &numKeySubs);
  4387. bAccelInit = True;
  4388. }
  4389. /*
  4390. * Copy modifiers
  4391. */
  4392. ScanWhitespace (&startP);
  4393. while (*startP != '<')
  4394. {
  4395. if (*startP == '~')
  4396. {
  4397. *destP++ = *startP++;
  4398. }
  4399. pchFirst = startP;
  4400. while (*startP &&
  4401. (((chlen = mblen ((char *)startP, MB_CUR_MAX)) > 1)
  4402. || isalnum (*startP)))
  4403. {
  4404. while (chlen--)
  4405. {
  4406. startP++;
  4407. }
  4408. }
  4409. /* find substitution */
  4410. pchSub = NULL;
  4411. lenSub = 0;
  4412. for (i=0; i<numKeySubs; i++)
  4413. {
  4414. if ((pKeySub[i].lenFrom == startP-pchFirst) &&
  4415. (!strncasecmp ((char *)pKeySub[i].pchFrom, (char *)pchFirst,
  4416. pKeySub[i].lenFrom)))
  4417. {
  4418. pchSub = pKeySub[i].pchTo;
  4419. lenSub = strlen((char *)pchSub);
  4420. break;
  4421. }
  4422. }
  4423. if ((pchSub != NULL) && (lenSub > 0))
  4424. {
  4425. memcpy (destP, pchSub, lenSub);
  4426. destP += lenSub;
  4427. }
  4428. else
  4429. {
  4430. memcpy (destP, pchFirst, startP-pchFirst);
  4431. destP += startP-pchFirst;
  4432. }
  4433. *destP++ = '+';
  4434. ScanWhitespace (&startP);
  4435. }
  4436. /*
  4437. * Skip the key event type.
  4438. */
  4439. startP++; /* skip '<' */
  4440. while (*startP != '>')
  4441. {
  4442. startP += mblen ((char *)startP, MB_CUR_MAX);
  4443. }
  4444. startP++; /* skip '>' */
  4445. /*
  4446. * Copy the KeySym string.
  4447. */
  4448. ScanWhitespace (&startP);
  4449. while (startP != endP)
  4450. {
  4451. *destP++ = *startP++;
  4452. }
  4453. *destP = '\0';
  4454. } /* END OF FUNCTION ProcessAccelText */
  4455. /*************************************<->*************************************
  4456. *
  4457. * ProcessCommandLine (argc, argv)
  4458. *
  4459. *
  4460. * Description:
  4461. * -----------
  4462. * This function looks for and processes mwm options in the command line
  4463. *
  4464. * Inputs:
  4465. * ------
  4466. * argc = argument count.
  4467. * argv = argument vector.
  4468. *
  4469. *
  4470. * Outputs:
  4471. * -------
  4472. * Changes global data to based on command line options recognized
  4473. *
  4474. *
  4475. *************************************<->***********************************/
  4476. #define SCREENS_OPT "-screens"
  4477. #define MULTI_SCREEN_OPT "-multiscreen"
  4478. void ProcessCommandLine (int argc, char *argv[])
  4479. {
  4480. unsigned char *string;
  4481. int argnum;
  4482. unsigned char *lineP;
  4483. for (argnum = 1; argnum < argc; argnum++)
  4484. {
  4485. lineP = (unsigned char *) argv[argnum];
  4486. if ((string = GetString (&lineP)) == NULL)
  4487. /* empty or comment line */
  4488. {
  4489. continue;
  4490. }
  4491. if (!strcmp((char *)string, MULTI_SCREEN_OPT))
  4492. {
  4493. wmGD.multiScreen = True;
  4494. wmGD.numScreens = ScreenCount (DISPLAY);
  4495. }
  4496. else if (!strcmp((char *)string, SCREENS_OPT))
  4497. {
  4498. argnum++; /* skip to next arg */
  4499. ParseScreensArgument (argc, argv, &argnum, lineP);
  4500. }
  4501. }
  4502. } /* END OF FUNCTION ProcessCommandLine */
  4503. /*************************************<->*************************************
  4504. *
  4505. * ParseScreensArgument (argc, argv, pArgnum, lineP)
  4506. *
  4507. *
  4508. * Description:
  4509. * -----------
  4510. * This function processes the ``-screens'' command line argument
  4511. *
  4512. * Inputs:
  4513. * ------
  4514. * argc = argument count.
  4515. * argv = argument vector.
  4516. * pArgnum = pointer to argument number where processing left off
  4517. * lineP = pointer into argv[*pArgnum] where processing left off
  4518. *
  4519. *
  4520. * Outputs:
  4521. * -------
  4522. * Changes global data to based on command line options recognized
  4523. * + wmGD.screenNames
  4524. * + wmGD.numScreens
  4525. * Assumes default screenNames are already in place
  4526. *
  4527. *************************************<->***********************************/
  4528. static void ParseScreensArgument (int argc, char *argv[], int *pArgnum,
  4529. unsigned char *lineP)
  4530. {
  4531. unsigned char *string;
  4532. int sNum = 0;
  4533. int lastLen;
  4534. int nameCount = 0;
  4535. for (; (*pArgnum < argc) && (sNum < ScreenCount(DISPLAY));
  4536. (*pArgnum)++, sNum++)
  4537. {
  4538. lineP = (unsigned char *)argv[*pArgnum];
  4539. if (*argv[*pArgnum] == '"')
  4540. {
  4541. /*
  4542. * if Quote, use GetString to strip it
  4543. */
  4544. if ((string = GetString (&lineP)) == NULL)
  4545. /* empty or comment line */
  4546. {
  4547. continue;
  4548. }
  4549. }
  4550. else
  4551. {
  4552. string = (unsigned char *)argv[*pArgnum];
  4553. if (*string == '-')
  4554. {
  4555. /* another option, end of screens names */
  4556. break;
  4557. }
  4558. }
  4559. if (!(wmGD.screenNames[sNum] = (unsigned char *)
  4560. XtRealloc ((char*)wmGD.screenNames[sNum],
  4561. 1 + strlen((char *)string))))
  4562. {
  4563. Warning (((char *)GETMESSAGE(60, 31, "Insufficient memory for screen names")));
  4564. ExitWM(WM_ERROR_EXIT_VALUE);
  4565. }
  4566. else
  4567. {
  4568. strcpy((char *)wmGD.screenNames[sNum], (char *)string);
  4569. nameCount++;
  4570. }
  4571. }
  4572. (*pArgnum)--;
  4573. /*
  4574. * remaining screens (if any) get first name specified
  4575. */
  4576. if (nameCount > 0)
  4577. {
  4578. lastLen = 1 + strlen((char *)wmGD.screenNames[0]);
  4579. for (; sNum < ScreenCount(DISPLAY); sNum++)
  4580. {
  4581. if (!(wmGD.screenNames[sNum] = (unsigned char *)
  4582. XtRealloc ((char*)wmGD.screenNames[sNum], lastLen)))
  4583. {
  4584. Warning (((char *)GETMESSAGE(60, 32, "Insufficient memory for screen names")));
  4585. ExitWM(WM_ERROR_EXIT_VALUE);
  4586. }
  4587. else
  4588. {
  4589. strcpy((char *)wmGD.screenNames[sNum],
  4590. (char *)wmGD.screenNames[0]);
  4591. }
  4592. }
  4593. }
  4594. } /* END OF FUNCTION ParseScreensArgument */
  4595. /*************************************<->*************************************
  4596. *
  4597. * ProcessMotifBindings ()
  4598. *
  4599. *
  4600. * Description:
  4601. * -----------
  4602. * This function is used retrieve the motif input bindings
  4603. * and put them into a property on the root window.
  4604. *
  4605. *
  4606. *************************************<->***********************************/
  4607. void ProcessMotifBindings (void)
  4608. {
  4609. char fileName[MAXWMPATH+1];
  4610. char *bindings = NULL;
  4611. char *homeDir = XmeGetHomeDirName();
  4612. /*
  4613. * Look in the user's home directory for .motifbind
  4614. */
  4615. strcpy (fileName, homeDir);
  4616. strncat(fileName, "/", MAXWMPATH-strlen(fileName));
  4617. strncat(fileName, MOTIF_BINDINGS_FILE, MAXWMPATH-strlen(fileName));
  4618. XDeleteProperty (DISPLAY, RootWindow (DISPLAY, 0),
  4619. XInternAtom (DISPLAY, "_MOTIF_BINDINGS", False));
  4620. XDeleteProperty (DISPLAY, RootWindow (DISPLAY, 0),
  4621. XInternAtom (DISPLAY, "_MOTIF_DEFAULT_BINDINGS", False));
  4622. if (_XmVirtKeysLoadFileBindings (fileName, &bindings) == True) {
  4623. XChangeProperty (DISPLAY, RootWindow(DISPLAY, 0),
  4624. XInternAtom (DISPLAY, "_MOTIF_BINDINGS", False),
  4625. XA_STRING, 8, PropModeReplace,
  4626. (unsigned char *)bindings, strlen(bindings));
  4627. }
  4628. else {
  4629. _XmVirtKeysLoadFallbackBindings (DISPLAY, &bindings);
  4630. }
  4631. XtFree (bindings);
  4632. } /* END OF FUNCTION ProcessMotifBindings */
  4633. /*************************************<->*************************************
  4634. *
  4635. * void
  4636. * ParseWmFunctionArg (linePP, ix, wmFunc, ppArg, sClientName)
  4637. *
  4638. *
  4639. * Description:
  4640. * -----------
  4641. * Parse the function arguments for a window manager function.
  4642. *
  4643. *
  4644. * Inputs:
  4645. * ------
  4646. * linePP = pointer to line buffer pointer (contains string arg).
  4647. * ix = window manager function index (returned by ParseWmFunction)
  4648. * pWmFunction = pointer to window manager function destination.
  4649. * ppArg = ptr to argument pointer.
  4650. * sClientName = string name of client
  4651. *
  4652. *
  4653. * Outputs:
  4654. * -------
  4655. * *ppArg = arg to pass to window manager function when invoking.
  4656. * Return = true on succes, false on some kind of parse error
  4657. *
  4658. *
  4659. * Comments:
  4660. * --------
  4661. * functionTable (window manager function table) is indexed with ix
  4662. * to get parsing info.
  4663. *
  4664. * This function may malloc memory for the returned arg.
  4665. *
  4666. * The sClientName is needed for starting some hpterm-based push_recall
  4667. * clients. It needs to be passed into the action so the hpterm gets
  4668. * named appropriately.
  4669. *
  4670. *************************************<->***********************************/
  4671. Boolean
  4672. ParseWmFunctionArg (
  4673. unsigned char **linePP,
  4674. int ix,
  4675. WmFunction wmFunc,
  4676. void **ppArg,
  4677. String sClientName,
  4678. String sTitle)
  4679. {
  4680. unsigned char *lineP = *linePP;
  4681. Boolean bValidArg = True;
  4682. unsigned char *str = NULL;
  4683. /*
  4684. * If this is (possibly) a string argument, put it
  4685. * in quotes so that it will be parsed properly.
  4686. */
  4687. if ((functionTable[ix].parseProc == ParseWmFuncStrArg) ||
  4688. (functionTable[ix].parseProc == ParseWmFuncMaybeStrArg))
  4689. {
  4690. if (lineP && *lineP != '"')
  4691. {
  4692. /*
  4693. * not in quotes, repackage it, escaping the appropriate
  4694. * characters.
  4695. */
  4696. str = _DtWmParseMakeQuotedString (lineP);
  4697. if (str)
  4698. {
  4699. lineP = str;
  4700. }
  4701. }
  4702. }
  4703. /*
  4704. * Apply the function argument parser.
  4705. */
  4706. if ((functionTable[ix].wmFunction != wmFunc) ||
  4707. !(*(functionTable [ix].parseProc)) (&lineP, wmFunc, ppArg))
  4708. {
  4709. bValidArg = False;
  4710. }
  4711. /*
  4712. * Add the exec parms if this is an f.action
  4713. */
  4714. if ((wmFunc == F_Action) && ppArg && *ppArg)
  4715. {
  4716. WmActionArg *pAP = (WmActionArg *) *ppArg;
  4717. int totLen = 0;
  4718. /*
  4719. * allocate more than enough string space to copy
  4720. * strings and intervening spaces.
  4721. */
  4722. if (sClientName && *sClientName)
  4723. {
  4724. /* length of: "name=" + sClientName + NULL */
  4725. totLen += 5 + strlen(sClientName) + 1;
  4726. }
  4727. if (sTitle && *sTitle)
  4728. {
  4729. /* length of: "," + "title=" + sTitle + NULL */
  4730. totLen += 1 + 6 + strlen(sTitle) + 1;
  4731. }
  4732. if (totLen > 0)
  4733. {
  4734. pAP->szExecParms = (String) XtMalloc (totLen);
  4735. /* start with empty string */
  4736. pAP->szExecParms[0] = '\0';
  4737. if (sClientName && *sClientName)
  4738. {
  4739. strcat (pAP->szExecParms, "name=");
  4740. strcat (pAP->szExecParms, sClientName);
  4741. }
  4742. if (sTitle && *sTitle)
  4743. {
  4744. if (pAP->szExecParms[0] != '\0')
  4745. {
  4746. strcat (pAP->szExecParms, ",");
  4747. }
  4748. strcat (pAP->szExecParms, "title=");
  4749. strcat (pAP->szExecParms, sTitle);
  4750. }
  4751. }
  4752. }
  4753. if (str)
  4754. {
  4755. XtFree ((char *) str);
  4756. }
  4757. return (bValidArg);
  4758. } /* END OF FUNCTION ParseWmFunctionArg */
  4759. /*************************************<->*************************************
  4760. *
  4761. * SystemCmd (pchCmd)
  4762. *
  4763. *
  4764. * Description:
  4765. * -----------
  4766. * This function fiddles with our signal handling and calls the
  4767. * system() function to invoke a unix command.
  4768. *
  4769. *
  4770. * Inputs:
  4771. * ------
  4772. * pchCmd = string with the command we want to exec.
  4773. *
  4774. * Outputs:
  4775. * -------
  4776. *
  4777. *
  4778. * Comments:
  4779. * --------
  4780. * The system() command is touchy about the SIGCLD behavior. Restore
  4781. * the default SIGCLD handler during the time we run system().
  4782. *
  4783. *************************************<->***********************************/
  4784. void
  4785. SystemCmd (char *pchCmd)
  4786. {
  4787. struct sigaction sa;
  4788. struct sigaction osa;
  4789. (void) sigemptyset(&sa.sa_mask);
  4790. sa.sa_flags = 0;
  4791. sa.sa_handler = SIG_DFL;
  4792. (void) sigaction (SIGCHLD, &sa, &osa);
  4793. system (pchCmd);
  4794. (void) sigaction (SIGCHLD, &osa, (struct sigaction *) 0);
  4795. }
  4796. /*************************************<->*************************************
  4797. *
  4798. * DeleteTempConfigFileIfAny ()
  4799. *
  4800. *
  4801. * Description:
  4802. * -----------
  4803. * This function deletes the temporary config file used to process
  4804. * old dtwmrc syntax.
  4805. *
  4806. *
  4807. * Inputs:
  4808. * ------
  4809. *
  4810. *
  4811. * Outputs:
  4812. * -------
  4813. *
  4814. *
  4815. * Comments:
  4816. * --------
  4817. *
  4818. *************************************<->***********************************/
  4819. void
  4820. DeleteTempConfigFileIfAny (void)
  4821. {
  4822. char pchCmd[MAXWMPATH+1];
  4823. if (pConfigStackTop->tempName)
  4824. {
  4825. strcpy (pchCmd, "/bin/rm ");
  4826. strcat (pchCmd, pConfigStackTop->tempName);
  4827. SystemCmd (pchCmd);
  4828. XtFree ((char *) pConfigStackTop->tempName);
  4829. pConfigStackTop->tempName = NULL;
  4830. }
  4831. if (pConfigStackTop->cppName)
  4832. {
  4833. strcpy (pchCmd, "/bin/rm ");
  4834. strcat (pchCmd, pConfigStackTop->cppName);
  4835. SystemCmd (pchCmd);
  4836. XtFree ((char *) pConfigStackTop->cppName);
  4837. pConfigStackTop->cppName = NULL;
  4838. }
  4839. }
  4840. /*************************************<->*************************************
  4841. *
  4842. * ParseIncludeSet (pSD, lineP)
  4843. *
  4844. *
  4845. * Description:
  4846. * -----------
  4847. *
  4848. *
  4849. * Inputs:
  4850. * ------
  4851. * cfileP = (global) file pointer to fopened configuration file or NULL
  4852. * lineP = pointer to line buffer
  4853. * line = (global) line buffer
  4854. * linec = (global) line count
  4855. * parseP = (global) parse string pointer if cfileP == NULL
  4856. * pSD->rootWindow = default root window of display
  4857. *
  4858. * Outputs:
  4859. * -------
  4860. * linec = (global) line count incremented
  4861. * parseP = (global) parse string pointer if cfileP == NULL
  4862. *
  4863. *
  4864. * Comments:
  4865. * --------
  4866. *
  4867. *************************************<->***********************************/
  4868. static void ParseIncludeSet (WmScreenData *pSD, unsigned char *lineP)
  4869. {
  4870. unsigned char *string;
  4871. unsigned char *pchName;
  4872. /*
  4873. * Require leading '{' on the next line.
  4874. */
  4875. while ((GetNextLine () != NULL)) /* not EOF nor read error */
  4876. {
  4877. lineP = line;
  4878. ScanWhitespace(&lineP);
  4879. if ((lineP == NULL) || (*line == '!') || (*lineP == '\0') || (*lineP == '#'))
  4880. /* ignore empty or comment line */
  4881. {
  4882. continue;
  4883. }
  4884. if (*lineP == '{')
  4885. /* found '{' */
  4886. {
  4887. break;
  4888. }
  4889. /* not a '{' */
  4890. PWarning (((char *)GETMESSAGE(60, 37, "Expected '{'")));
  4891. return;
  4892. }
  4893. /*
  4894. * Found leading "{" or EOF.
  4895. * Parse include files until "}" or EOF found.
  4896. */
  4897. while ((GetNextLine () != NULL))
  4898. {
  4899. lineP = line;
  4900. if ((*line == '!') || (string = GetString (&lineP)) == NULL)
  4901. /* ignore empty or comment lines */
  4902. {
  4903. continue;
  4904. }
  4905. if (*string == '}') /* finished with set. */
  4906. {
  4907. break;
  4908. }
  4909. pchName = _DtWmParseFilenameExpand (string);
  4910. if (pchName && ConfigStackPush (pchName))
  4911. {
  4912. ProcessWmFile (pSD, True /* nested */);
  4913. ConfigStackPop ();
  4914. XtFree ((char *) pchName);
  4915. }
  4916. }
  4917. }
  4918. /*************************************<->*************************************
  4919. *
  4920. * ConfigStackInit (pchFileName)
  4921. *
  4922. *
  4923. * Description:
  4924. * -----------
  4925. * Initializes the config file processing stack
  4926. *
  4927. * Inputs:
  4928. * ------
  4929. * pchFileName = name of new file to start parsing
  4930. *
  4931. * Outputs:
  4932. * -------
  4933. *
  4934. *
  4935. * Comments:
  4936. * --------
  4937. *
  4938. *************************************<->***********************************/
  4939. static void ConfigStackInit (char *pchFileName)
  4940. {
  4941. pConfigStack = XtNew (ConfigFileStackEntry);
  4942. if (pConfigStack)
  4943. {
  4944. pConfigStackTop = pConfigStack;
  4945. pConfigStackTop->fileName = XtNewString (pchFileName);
  4946. pConfigStackTop->tempName = NULL;
  4947. pConfigStackTop->cppName = NULL;
  4948. pConfigStackTop->offset = 0;
  4949. pConfigStackTop->pWmPB = wmGD.pWmPB;
  4950. pConfigStackTop->wmgdConfigFile = wmGD.configFile;
  4951. pConfigStackTop->pIncluder = NULL;
  4952. }
  4953. else
  4954. {
  4955. sprintf ((char *)wmGD.tmpBuffer,
  4956. (char *)GETMESSAGE(60,36,"Insufficient memory to process included file: %s"),
  4957. pchFileName);
  4958. Warning ((char *)wmGD.tmpBuffer);
  4959. }
  4960. }
  4961. /*************************************<->*************************************
  4962. *
  4963. * ConfigStackPush (pchFileName)
  4964. *
  4965. *
  4966. * Description:
  4967. * -----------
  4968. * Open an included config file
  4969. *
  4970. * Inputs:
  4971. * ------
  4972. * pchFileName = name of new file to start parsing
  4973. * wmGD.pWmPB = global parse buffer (pickle this)
  4974. *
  4975. * Outputs:
  4976. * -------
  4977. * wmGD.pWmPB = global parse buffer (new one for new file)
  4978. * return = FILE * to open file or NULL
  4979. *
  4980. *
  4981. * Comments:
  4982. * --------
  4983. *
  4984. *************************************<->***********************************/
  4985. static FILE *
  4986. ConfigStackPush (unsigned char *pchFileName)
  4987. {
  4988. ConfigFileStackEntry *pEntry;
  4989. FILE *pNewFile = NULL;
  4990. pEntry = XtNew (ConfigFileStackEntry);
  4991. if (pEntry)
  4992. {
  4993. /* save off state of current config file */
  4994. pConfigStackTop->offset = ftell (cfileP);
  4995. pConfigStackTop->pWmPB = wmGD.pWmPB;
  4996. fclose (cfileP);
  4997. /* set up state of new config file */
  4998. pEntry->fileName = XtNewString ((char *)pchFileName);
  4999. pEntry->tempName = NULL;
  5000. pEntry->cppName = NULL;
  5001. pEntry->wmgdConfigFile = (String) pEntry->fileName;
  5002. /* set globals for new config file */
  5003. wmGD.pWmPB = _DtWmParseNewBuf ();
  5004. wmGD.configFile = pEntry->wmgdConfigFile;
  5005. /* put new entry onto stack */
  5006. pEntry->pIncluder = pConfigStackTop;
  5007. pConfigStackTop = pEntry;
  5008. /* open the file */
  5009. pNewFile = cfileP = FopenConfigFile();
  5010. if (!pNewFile)
  5011. {
  5012. /* file open failed! back out */
  5013. ConfigStackPop ();
  5014. }
  5015. }
  5016. else
  5017. {
  5018. sprintf ((char *)wmGD.tmpBuffer,
  5019. (char *)GETMESSAGE(60,36,"Insufficient memory to process included file: %s"),
  5020. pchFileName);
  5021. Warning ((char *)wmGD.tmpBuffer);
  5022. }
  5023. return (pNewFile);
  5024. }
  5025. /*************************************<->*************************************
  5026. *
  5027. * ConfigStackPop ()
  5028. *
  5029. *
  5030. * Description:
  5031. * -----------
  5032. *
  5033. *
  5034. * Inputs:
  5035. * ------
  5036. * pchFileName = name of new file to start parsing
  5037. * wmGD.pWmPB = global parse buffer (pickle this)
  5038. *
  5039. * Outputs:
  5040. * -------
  5041. * wmGD.pWmPB = global parse buffer (new one for new file)
  5042. *
  5043. *
  5044. * Comments:
  5045. * --------
  5046. * assumes cfileP is closed already
  5047. *
  5048. *************************************<->***********************************/
  5049. static void ConfigStackPop (void)
  5050. {
  5051. ConfigFileStackEntry *pPrev;
  5052. char pchCmd[MAXWMPATH+1];
  5053. if (pConfigStackTop != pConfigStack)
  5054. {
  5055. pPrev = pConfigStackTop->pIncluder;
  5056. _DtWmParseDestroyBuf (wmGD.pWmPB);
  5057. if (pConfigStackTop->tempName)
  5058. {
  5059. XtFree (pConfigStackTop->tempName);
  5060. }
  5061. if (pConfigStackTop->cppName)
  5062. {
  5063. strcpy (pchCmd, "/bin/rm ");
  5064. strcat (pchCmd, pConfigStackTop->cppName);
  5065. SystemCmd (pchCmd);
  5066. XtFree ((char *) pConfigStackTop->cppName);
  5067. pConfigStackTop->cppName = NULL;
  5068. }
  5069. if (pConfigStackTop->fileName)
  5070. {
  5071. XtFree (pConfigStackTop->fileName);
  5072. }
  5073. wmGD.pWmPB = pPrev->pWmPB;
  5074. wmGD.configFile = pPrev->wmgdConfigFile;
  5075. if (pPrev->tempName)
  5076. {
  5077. cfileP = fopen (pPrev->tempName, "r");
  5078. }
  5079. else if (pPrev->cppName)
  5080. {
  5081. cfileP = fopen (pPrev->cppName, "r");
  5082. }
  5083. else
  5084. {
  5085. cfileP = fopen (pPrev->fileName, "r");
  5086. }
  5087. if (cfileP)
  5088. {
  5089. fseek (cfileP, pPrev->offset, 0);
  5090. }
  5091. else
  5092. {
  5093. char msg[MAXWMPATH+1];
  5094. sprintf(msg, ((char *)GETMESSAGE(60, 39,
  5095. "Could not reopen configuration file %s")),
  5096. pPrev->fileName);
  5097. Warning (msg);
  5098. }
  5099. XtFree ((char *)pConfigStackTop);
  5100. pConfigStackTop = pPrev;
  5101. }
  5102. }
  5103. /*************************************<->*************************************
  5104. *
  5105. * ParseWmFuncActionArg (linePP, wmFunction, pArgs)
  5106. *
  5107. *
  5108. * Description:
  5109. * -----------
  5110. * Parses a window manager f.action argument
  5111. *
  5112. *
  5113. * Inputs:
  5114. * ------
  5115. * linePP = pointer to current line buffer pointer.
  5116. * wmFunction = function for which the argument string is intended.
  5117. * pArgs = pointer to argument destination.
  5118. *
  5119. *
  5120. * Outputs:
  5121. * -------
  5122. * linePP = pointer to revised line buffer pointer.
  5123. * pArgs = pointer to parsed argument.
  5124. * Return = FALSE iff insufficient memory
  5125. *
  5126. *
  5127. * Comments:
  5128. * --------
  5129. *
  5130. *************************************<->***********************************/
  5131. Boolean ParseWmFuncActionArg (unsigned char **linePP,
  5132. WmFunction wmFunction, String *pArgs)
  5133. {
  5134. #define WM_ACTION_ARG_INCREMENT 5
  5135. #define WM_ACTION_ARG_PAD 256
  5136. unsigned char *string;
  5137. char *pch;
  5138. WmActionArg *pAP;
  5139. int iArgSz;
  5140. pAP = XtNew (WmActionArg);
  5141. if (pAP && (string = GetString (linePP)) != NULL)
  5142. {
  5143. /* Got action name */
  5144. pAP->actionName = XtNewString ((char *) string);
  5145. /* Get action arguments, if any */
  5146. if ((pAP->aap = (DtActionArg *)
  5147. XtMalloc (WM_ACTION_ARG_INCREMENT * sizeof (DtActionArg))))
  5148. {
  5149. iArgSz = WM_ACTION_ARG_INCREMENT;
  5150. pAP->numArgs = 0;
  5151. while ((string = GetString (linePP)) != NULL)
  5152. {
  5153. if ((pAP->aap[pAP->numArgs].u.file.name = (char *)
  5154. XtMalloc(1 + strlen((char *)string))))
  5155. {
  5156. pAP->aap[pAP->numArgs].argClass = DtACTION_FILE;
  5157. /* format the action argument */
  5158. pch = pAP->aap[pAP->numArgs].u.file.name;
  5159. /*
  5160. * Expand environment variable
  5161. */
  5162. if (string[0] == '$')
  5163. {
  5164. string = (unsigned char *) getenv ((char *)&string[1]);
  5165. if (!string)
  5166. {
  5167. break;
  5168. }
  5169. else
  5170. {
  5171. /*
  5172. * Make sure there's room for the new
  5173. * string.
  5174. */
  5175. pch = (char *)
  5176. XtRealloc (pch, (1+strlen((char *)string)));
  5177. pAP->aap[pAP->numArgs].u.file.name = pch;
  5178. }
  5179. }
  5180. /* !!! No host name processing is done!!! */
  5181. strcpy (pch, (char *)string);
  5182. pAP->numArgs++;
  5183. if (pAP->numArgs == iArgSz)
  5184. {
  5185. /* need to increase our array space */
  5186. iArgSz += WM_ACTION_ARG_INCREMENT;
  5187. pAP->aap = (DtActionArg *)
  5188. XtRealloc((char *)pAP->aap,
  5189. (iArgSz * sizeof (DtActionArg)));
  5190. if (!pAP->aap)
  5191. {
  5192. break; /* out of memory */
  5193. }
  5194. }
  5195. }
  5196. else
  5197. {
  5198. break; /* out of memory */
  5199. }
  5200. }
  5201. }
  5202. pAP->szExecParms = NULL;
  5203. *pArgs = (String) pAP;
  5204. }
  5205. else
  5206. /* NULL string argument */
  5207. {
  5208. *pArgs = NULL;
  5209. }
  5210. return (TRUE);
  5211. } /* END OF FUNCTION ParseWmFuncActionArg */
  5212. /*************************************<->*************************************
  5213. *
  5214. * PreprocessConfigFile (pSD)
  5215. *
  5216. *
  5217. * Description:
  5218. * -----------
  5219. * This function runs the configuration file through the C
  5220. * preprocessor
  5221. *
  5222. *
  5223. * Inputs:
  5224. * ------
  5225. * pSD = ptr to screen data
  5226. *
  5227. * Outputs:
  5228. * -------
  5229. *
  5230. *
  5231. * Comments:
  5232. * --------
  5233. *
  5234. *************************************<->***********************************/
  5235. static void
  5236. PreprocessConfigFile (void)
  5237. {
  5238. #define CPP_NAME_SIZE ((L_tmpnam)+1)
  5239. char pchCmd[MAXWMPATH+1];
  5240. if (wmGD.cppCommand && *wmGD.cppCommand)
  5241. {
  5242. /*
  5243. * Generate a temp file name.
  5244. */
  5245. pConfigStackTop->cppName = XtMalloc (CPP_NAME_SIZE * sizeof(char));
  5246. if (pConfigStackTop->cppName)
  5247. {
  5248. (void) tmpnam (pConfigStackTop->cppName);
  5249. /*
  5250. * Build up the command line.
  5251. */
  5252. strcpy (pchCmd, wmGD.cppCommand);
  5253. strcat (pchCmd, " ");
  5254. strcat (pchCmd, pConfigStackTop->fileName);
  5255. strcat (pchCmd, " ");
  5256. strcat (pchCmd, pConfigStackTop->cppName);
  5257. /*
  5258. * Run the config file through the converter program
  5259. * and send the output to a temp file.
  5260. */
  5261. SystemCmd (pchCmd);
  5262. }
  5263. }
  5264. }
  5265. /*************************************<->*************************************
  5266. *
  5267. * GetNetworkFileName (char *pchFile)
  5268. *
  5269. *
  5270. * Description:
  5271. * -----------
  5272. * This function returns a local representation for a network
  5273. * file.
  5274. *
  5275. *
  5276. * Inputs:
  5277. * ------
  5278. * pchFile - pointer to file name of form [<host>:]<path>
  5279. *
  5280. * Return:
  5281. * -------
  5282. * String - ptr to allocated string of local file name. If input
  5283. * is not a network file, the a copy of pchFile is returned.
  5284. *
  5285. *
  5286. * Comments:
  5287. * --------
  5288. * returned file name should be freed with XtFree().
  5289. *
  5290. *************************************<->***********************************/
  5291. static String
  5292. GetNetworkFileName (char *pchFile)
  5293. {
  5294. char *pch;
  5295. char *host_part;
  5296. char *file_part;
  5297. char *netfile;
  5298. char *sName = NULL;
  5299. char *pchName = NULL;
  5300. int count;
  5301. char **pchTok;
  5302. String sReturn = NULL;
  5303. char *homeDir;
  5304. int len;
  5305. pch = strchr (pchFile, ':');
  5306. if (pch)
  5307. {
  5308. /*
  5309. * Expand special chars and find matching file.
  5310. */
  5311. pchTok = (char **)shellscan (pchFile, &count, 0);
  5312. if ((count == 1) || (count == 2))
  5313. {
  5314. /* one match found */
  5315. host_part = pchTok[0];
  5316. }
  5317. else if (count > 2)
  5318. {
  5319. /* several matches found, pick one */
  5320. host_part = pchTok[1];
  5321. }
  5322. else
  5323. {
  5324. host_part = NULL;
  5325. }
  5326. if (host_part != NULL)
  5327. {
  5328. pch = strchr (host_part, ':');
  5329. if (pch)
  5330. {
  5331. /*
  5332. * copy the string so we don't munge data
  5333. * inside shellscan
  5334. */
  5335. host_part = sName = XtNewString ((String) host_part);
  5336. pch = strchr (sName, ':');
  5337. /*
  5338. * separate the host and file parts of the
  5339. * file name
  5340. */
  5341. *pch = '\0';
  5342. file_part = pch+1;
  5343. }
  5344. else
  5345. {
  5346. /*
  5347. * The colon went away. Hmm...
  5348. */
  5349. file_part = host_part;
  5350. host_part = NULL;
  5351. }
  5352. if ((mblen(file_part, MB_CUR_MAX) == 1) &&
  5353. (mblen(file_part+1, MB_CUR_MAX) == 1) &&
  5354. (*file_part == '~') &&
  5355. (*(file_part+1) == '/'))
  5356. {
  5357. /*
  5358. * Replace '~' with $HOME
  5359. */
  5360. homeDir = XmeGetHomeDirName();
  5361. len = strlen (host_part) + 1 +
  5362. strlen (homeDir) + strlen (file_part) + 1;
  5363. pch = (char *) XtMalloc (len);
  5364. strcpy (pch, sName);
  5365. host_part = pch;
  5366. pch += strlen (pch) + 1;
  5367. strcpy (pch, homeDir);
  5368. strcat (pch, file_part+1);
  5369. file_part = pch;
  5370. XtFree (sName);
  5371. sName = host_part;
  5372. }
  5373. }
  5374. else
  5375. {
  5376. /*
  5377. * shellscan had a problem with the file name.
  5378. * just operate on the name as-is.
  5379. * temporarily replace ':' with a NULL
  5380. */
  5381. host_part = sName = XtNewString ((String) pchFile);
  5382. pch = strchr (sName, ':');
  5383. *pch = '\0';
  5384. host_part = pchFile;
  5385. file_part = pch+1;
  5386. }
  5387. /* convert to canonical host/file name */
  5388. netfile = (char *)
  5389. tt_host_file_netfile (host_part, file_part);
  5390. if (tt_pointer_error (netfile) == TT_OK)
  5391. {
  5392. /* convert to local file name equivalent */
  5393. pchName = tt_netfile_file (netfile);
  5394. if (tt_pointer_error (pchName) == TT_OK)
  5395. {
  5396. sReturn = XtNewString ((String) pchName);
  5397. tt_free ((char *)pchName);
  5398. }
  5399. tt_free (netfile);
  5400. }
  5401. if (sName)
  5402. {
  5403. XtFree ((char *)sName);
  5404. }
  5405. }
  5406. if (sReturn == NULL)
  5407. {
  5408. if ((mblen(pchFile, MB_CUR_MAX) == 1) &&
  5409. (mblen(pchFile+1, MB_CUR_MAX) == 1) &&
  5410. (*pchFile == '~') &&
  5411. (*(pchFile+1) == '/'))
  5412. {
  5413. /*
  5414. * Replace '~' with $HOME
  5415. */
  5416. homeDir = XmeGetHomeDirName();
  5417. len = strlen (homeDir) + strlen (pchFile) + 1;
  5418. sReturn = (char *) XtMalloc (len);
  5419. strcpy (sReturn, homeDir);
  5420. strcat (sReturn, pchFile+1);
  5421. }
  5422. else
  5423. {
  5424. sReturn = XtNewString ((String) pchFile);
  5425. }
  5426. }
  5427. return (sReturn);
  5428. }
  5429. /**************************** eof ***************************/