WmResParse.c 139 KB

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