dtkcmds.c 247 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $TOG: dtkcmds.c /main/13 1997/07/14 18:16:01 samborn $ */
  24. /* Copyright (c) 1991, 1992 UNIX System Laboratories, Inc. */
  25. /* All Rights Reserved */
  26. /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF */
  27. /* UNIX System Laboratories, Inc. */
  28. /* The copyright notice above does not evidence any */
  29. /* actual or intended publication of such source code. */
  30. /* X includes */
  31. #include "name.h"
  32. #include "shell.h"
  33. #include <signal.h>
  34. #include <fcntl.h>
  35. #include <X11/X.h>
  36. #include <X11/Intrinsic.h>
  37. #include <X11/IntrinsicP.h>
  38. #include <X11/CoreP.h>
  39. #include <X11/StringDefs.h>
  40. #include <Xm/XmStrDefs.h>
  41. #include <setjmp.h>
  42. #include <string.h>
  43. #include <ctype.h>
  44. #include <Xm/Xm.h>
  45. #include <Xm/Protocols.h>
  46. #include <Dt/Service.h>
  47. #include <Dt/Wsm.h>
  48. #include <Dt/HourGlass.h>
  49. #include <Dt/Help.h>
  50. #include <Dt/Action.h>
  51. #include <Dt/Dts.h>
  52. #include <Dt/Print.h>
  53. #include <Dt/Session.h>
  54. #include <Tt/tttk.h>
  55. #include <Tt/tt_c.h>
  56. #include "XtCvtrs.h"
  57. #include "hash.h"
  58. #include "stdio.h"
  59. #include "defs.h"
  60. #include "dtksh.h"
  61. #include "xmksh.h"
  62. #include "dtkcmds.h"
  63. #include "xmcvt.h"
  64. #include "widget.h"
  65. #include "extra.h"
  66. #include "xmwidgets.h"
  67. #include "msgs.h"
  68. #include "xmcmds.h"
  69. #include <locale.h>
  70. extern Namval_t *sh_assignok(Namval_t *np,int add);
  71. static void PendingDestroy(
  72. Widget w,
  73. wtab_t *wtab,
  74. caddr_t callData) ;
  75. static Boolean WtabDestroy(
  76. caddr_t callData) ;
  77. static int _CreateWidget(
  78. Widget (*func)(),
  79. int argc,
  80. char *argv[]) ;
  81. static int _DTKSH_XtDestroyWidget(
  82. Widget w) ;
  83. static int do_single_widget_arg_func(
  84. int (*func)(),
  85. int argc,
  86. char **argv) ;
  87. static void mainloopsighandler(
  88. int sig) ;
  89. static int XtCallCallbacks_usage(
  90. char *arg0) ;
  91. static void RegisterCmdStr(
  92. char type,
  93. long id,
  94. char *cmd) ;
  95. static void RemoveCmdStr(
  96. char type,
  97. long id) ;
  98. static int do_RootWindowCmd(
  99. int (*func)(),
  100. int argc,
  101. char *argv[]) ;
  102. static int cvtfontstruct(
  103. char *name,
  104. XFontStruct **fn) ;
  105. static int CatchNonFatalFontError(
  106. Display *display,
  107. XErrorEvent *event) ;
  108. static int cvtfont(
  109. Display *display,
  110. char *name,
  111. Font *fn) ;
  112. static int cvtcolor(
  113. char *name,
  114. Pixel *pix) ;
  115. static int invokeXDrawFunction(
  116. int function,
  117. int argc,
  118. char *argv[]) ;
  119. static int XtAddInputUsage(
  120. char *arg0) ;
  121. static void DestroyInputRecord(
  122. XtInputId id) ;
  123. static int FindInputRecord(
  124. XtInputId id) ;
  125. static Boolean ProcessInput(
  126. inputrec_t * inp,
  127. int source,
  128. XtInputId id,
  129. Boolean eofFound) ;
  130. static int VerifyString_usage(
  131. char *arg0) ;
  132. static int XtSetSensitive_usage(
  133. char *arg0) ;
  134. static int GetDisplayHandle(
  135. int argc,
  136. char **argv,
  137. Widget (*func)());
  138. static int RegisterTranslations(
  139. void (*func)(),
  140. int argc,
  141. char *argv[]) ;
  142. static int LocateEHRecord(
  143. wtab_t *w,
  144. char *ksh_cmd) ;
  145. static int GetWorkspaceList(
  146. char *usageMsg,
  147. Boolean getOccupied,
  148. int argc,
  149. char *argv[]) ;
  150. static int DtTurnOnOrOffHourGlass(
  151. void (*func)(),
  152. int argc,
  153. char *argv[]) ;
  154. static int WsmCommonProc(
  155. int argc,
  156. char *argv[],
  157. void (*func)());
  158. static int ttdt_SaveOrRevert(
  159. Tt_status (*func)(),
  160. int argc,
  161. char *argv[] ) ;
  162. static int message_DestroyOrReply(
  163. Tt_status (*func)(),
  164. int argc,
  165. char *argv[] );
  166. static int message_FailOrReject(
  167. Tt_status (*func)(),
  168. int argc,
  169. char *argv[] );
  170. static Tt_message TtFileCB(
  171. Tt_message msg,
  172. Tttk_op op,
  173. char * pathName,
  174. void * clientData,
  175. int sameEuidEgid,
  176. int sameProcId ) ;
  177. static int tt_netfile_handler(
  178. int paramCount,
  179. char * (*func)(),
  180. char * usageMsg,
  181. int argc,
  182. char *argv[] ) ;
  183. static Namval_t * CreateEmptyNameValuePair(
  184. Namval_t *np,
  185. char *name,
  186. Namfun_t *fp) ;
  187. static Namval_t * ProcessIntValue(
  188. int value,
  189. Namval_t *np,
  190. char *name,
  191. Namfun_t *fp,
  192. char *format,
  193. Namfun_t *fp_new) ;
  194. static Namval_t * ProcessStringValue(
  195. char *value,
  196. Namval_t *np,
  197. char *name,
  198. Namfun_t *fp) ;
  199. static Namval_t * ProcessBooleanIntValue(
  200. int value,
  201. Namval_t *np,
  202. char *name,
  203. Namfun_t *fp,
  204. Namfun_t *fp_new) ;
  205. static Namval_t * ProcessTraversalDirection(
  206. XmTraversalDirection dir,
  207. Namval_t *np,
  208. char *name,
  209. Namfun_t *fp) ;
  210. static Namval_t * ProcessSelectionType(
  211. char selType,
  212. Namval_t *np,
  213. char *name,
  214. Namfun_t *fp) ;
  215. static Namval_t * ProcessIntTable(
  216. int *table,
  217. int count,
  218. Namval_t *np,
  219. char *name,
  220. Namfun_t *fp) ;
  221. static Namval_t * ProcessXmStringTable(
  222. XmString *table,
  223. int count,
  224. Namval_t *np,
  225. char *name,
  226. Namfun_t *fp) ;
  227. static Namval_t * ProcessWidgetHandle(
  228. Widget handle,
  229. Namval_t *np,
  230. char *name,
  231. Namfun_t *fp) ;
  232. static Namval_t * ProcessXmStringValue(
  233. XmString xmstring,
  234. Namval_t *np,
  235. char *name,
  236. Namfun_t *fp) ;
  237. static Namval_t * ProcessHyperType(
  238. int hyperType,
  239. Namval_t *np,
  240. char *name,
  241. Namfun_t *fp) ;
  242. static void InitEventTables( void ) ;
  243. static Namval_t * ProcessCallbackEvent(
  244. XEvent *event,
  245. Namval_t *np,
  246. char *name,
  247. Namfun_t *fp) ;
  248. static Namval_t * _IntProcessCallbackReason(
  249. struct named_integer *table,
  250. XmAnyCallbackStruct *cbData,
  251. Namval_t *np,
  252. char *name,
  253. Namfun_t *fp) ;
  254. static Namval_t * ProcessCallbackReason(
  255. XmAnyCallbackStruct *cbData,
  256. Namval_t *np,
  257. char *name,
  258. Namfun_t *fp) ;
  259. static Namval_t * ProcessHelpCallbackReason(
  260. XmAnyCallbackStruct *cbData,
  261. Namval_t *np,
  262. char *name,
  263. Namfun_t *fp) ;
  264. static void _DtActionInvokeUsage( void ) ;
  265. static void DtkReloadHandler(
  266. XtPointer clientData ) ;
  267. static Namfun_t * CloneDiscipline(
  268. Namdisc_t * discipline );
  269. static void FreeDiscipline(
  270. Namfun_t * discipline );
  271. static Namdisc_t * CheckClassDisciplines(
  272. WidgetClass class,
  273. char *cbname) ;
  274. void SetTextDoit(
  275. Namval_t *np,
  276. char *name,
  277. Namfun_t *fp);
  278. void SetTextStartPos(
  279. Namval_t *np,
  280. char *name,
  281. Namfun_t *fp);
  282. void SetTextEndPos(
  283. Namval_t *np,
  284. char *name,
  285. Namfun_t *fp);
  286. void SetTextPtr(
  287. Namval_t *np,
  288. char *name,
  289. Namfun_t *fp);
  290. void SetTextLen(
  291. Namval_t *np,
  292. char *name,
  293. Namfun_t *fp);
  294. void SetTextFormat(
  295. Namval_t *np,
  296. char *name,
  297. Namfun_t *fp);
  298. void SetTextWCSptr(
  299. Namval_t *np,
  300. char *name,
  301. Namfun_t *fp);
  302. void SetTextWCSlen(
  303. Namval_t *np,
  304. char *name,
  305. Namfun_t *fp);
  306. #define CLEAR_AREA 0
  307. #define CLEAR_WINDOW 1
  308. #define DRAW_ARC 2
  309. #define DRAW_IMAGE_STRING 3
  310. #define DRAW_LINE 4
  311. #define DRAW_LINES 5
  312. #define DRAW_POINT 6
  313. #define DRAW_POINTS 7
  314. #define DRAW_RECTANGLE 8
  315. #define DRAW_SEGMENTS 9
  316. #define DRAW_STRING 10
  317. #define FILL_ARC 11
  318. #define FILL_POLYGON 12
  319. #define FILL_RECTANGLE 13
  320. #define COPY_AREA 14
  321. #define WORKPROC_CMDS 0
  322. #define TIMEOUT_CMDS 1
  323. #define MAXARGS 4096
  324. #define SLISTITEMSIZE 16
  325. Widget Toplevel;
  326. Boolean invalidFont;
  327. /* List of all name/value pairs created during handling of a callback */
  328. Namval_t *** npTable = NULL;
  329. int npTableSize = 0;
  330. int * npListSizes = NULL;
  331. int nestingLevel = -1;
  332. static Namdisc_t transDiscipline ={0, NULL, NULL, NULL, NULL,
  333. (Namval_t *(*)())transCreateDisc, NULL, NULL};
  334. static Namdisc_t ehDiscipline = {0, NULL, NULL, NULL, NULL,
  335. (Namval_t *(*)())ehCreateDisc, NULL, NULL};
  336. static Namdisc_t dftDiscipline = {0, NULL, NULL, NULL, NULL,
  337. (Namval_t *(*)())dftCreateDisc, NULL, NULL};
  338. static Namdisc_t nopDiscipline = {0, NULL, NULL, NULL, NULL,
  339. (Namval_t *(*)())nopCreateDisc, NULL, NULL};
  340. static Namdisc_t text_doit_disc = {0, (void (*)())SetTextDoit, NULL, NULL, NULL,
  341. NULL, NULL, NULL};
  342. static Namdisc_t text_startpos_disc = {0, (void (*)())SetTextStartPos, NULL,
  343. NULL, NULL,NULL, NULL, NULL};
  344. static Namdisc_t text_endpos_disc = {0, (void (*)())SetTextEndPos, NULL, NULL,
  345. NULL, NULL, NULL, NULL};
  346. static Namdisc_t text_ptr_disc = {0, (void (*)())SetTextPtr, NULL, NULL, NULL,
  347. NULL, NULL, NULL};
  348. static Namdisc_t text_len_disc = {0, (void (*)())SetTextLen, NULL, NULL, NULL,
  349. NULL, NULL, NULL};
  350. static Namdisc_t text_format_disc = {0, (void (*)())SetTextFormat, NULL, NULL,
  351. NULL, NULL, NULL, NULL};
  352. static Namdisc_t text_wcsptr_disc = {0, (void (*)())SetTextWCSptr, NULL, NULL,
  353. NULL, NULL, NULL, NULL};
  354. static Namdisc_t text_wcslen_disc = {0, (void (*)())SetTextWCSlen, NULL, NULL,
  355. NULL, NULL, NULL, NULL};
  356. static const XtActionsRec Ksh_actions[] = {
  357. { "ksh_eval", Translation_ksh_eval }
  358. };
  359. static dtksh_client_data_t ** cbDataTable = NULL;
  360. static int cbDataTableSize = 0;
  361. static dtksh_event_handler_data_t ** ehDataTable = NULL;
  362. static int ehDataTableSize = 0;
  363. static char * str_XtRString = XtRString;
  364. char str_s_eq_s[] = "%s=%s";
  365. char str_s_eq[] = "%s=";
  366. char str_nill[] = "";
  367. typedef struct
  368. {
  369. int state;
  370. Window icon;
  371. } WmStateData;
  372. typedef struct
  373. {
  374. long id;
  375. char * cmd;
  376. } CommandString;
  377. CommandString * workProcCmds = NULL;
  378. int workProcCmdsSize = 0;
  379. CommandString * timeOutCmds = NULL;
  380. int timeOutCmdsSize = 0;
  381. typedef struct {
  382. char * ksh_cmd;
  383. Tt_pattern * patterns;
  384. } Ttdt_file_cb_data;
  385. Ttdt_file_cb_data ** fileCBList = 0;
  386. int sizeFileCBList = 0;
  387. typedef struct {
  388. char * fieldName;
  389. char * representation;
  390. Cardinal valueOffset;
  391. Cardinal valueSize;
  392. } EventEntryTable;
  393. typedef struct {
  394. char * eventType;
  395. EventEntryTable * table;
  396. } XEventTable;
  397. /* Keeps track of file input generated by XtAddInput() */
  398. typedef struct {
  399. Boolean inUse;
  400. XtInputId id;
  401. inputrec_t * inp;
  402. } InputRecord;
  403. InputRecord * activeInputs = NULL;
  404. int numActiveInputs = 0;
  405. /*
  406. * When we are notified that a widget is being destroyed (through the
  407. * widget's destroy callback, it is not yet safe for us to remove all
  408. * internal knowledge of that widget, because the shell script may have
  409. * also added a destroy callback, which gets call AFTER ours. Therefore,
  410. * all we can do is mark the widget as 'pending destroy', and add a
  411. * workproc; the workproc will then take care of removing the widget.
  412. */
  413. static Boolean workProcAdded = False;
  414. static void
  415. PendingDestroy(
  416. Widget w,
  417. wtab_t *wtab,
  418. caddr_t callData )
  419. {
  420. wtab->mask |= DT_PENDING_DESTROY;
  421. if (!workProcAdded)
  422. {
  423. workProcAdded = True;
  424. XtAddWorkProc((XtWorkProc)WtabDestroy, NULL);
  425. }
  426. }
  427. static Boolean
  428. WtabDestroy(
  429. caddr_t callData )
  430. {
  431. int i;
  432. for (i = 0; i < NumW; i++)
  433. {
  434. if ((W[i]->type == TAB_WIDGET) && (W[i]->mask & DT_PENDING_DESTROY))
  435. {
  436. XtFree(W[i]->wname);
  437. XtFree(W[i]->widid);
  438. if (W[i]->envar) {
  439. char *val = env_get(W[i]->envar);
  440. /*
  441. * Blank out the environment variable holding the
  442. * widget handle, but only if it still holds the
  443. * handle! This guards against the possibility that
  444. * the user has re-used the same variable for another
  445. * widget later.
  446. */
  447. if (val && W[i]->widid && strcmp(val, W[i]->widid) == 0) {
  448. env_blank(W[i]->envar);
  449. }
  450. XtFree(W[i]->envar);
  451. }
  452. W[i]->type = TAB_EMPTY;
  453. Wtab_free++;
  454. }
  455. }
  456. workProcAdded = False;
  457. return(True);
  458. }
  459. wtab_t *
  460. set_up_w(
  461. Widget wid,
  462. wtab_t *parent,
  463. char *var,
  464. char *name,
  465. classtab_t *class )
  466. {
  467. char widid[8];
  468. static wtab_t *w;
  469. get_new_wtab(&w, widid);
  470. if (var) {
  471. env_set_var(var, widid);
  472. w->envar = strdup(var);
  473. } else {
  474. w->envar = strdup("none");
  475. }
  476. w->type = TAB_WIDGET;
  477. w->wname = name ? strdup(name) : strdup(XtName(wid));
  478. w->wclass = class;
  479. w->parent = parent;
  480. w->widid = strdup(widid);
  481. w->w = wid;
  482. w->mask = 0;
  483. XtAddCallback(wid, XtNdestroyCallback, (XtCallbackProc)PendingDestroy,
  484. (caddr_t)w);
  485. return(w);
  486. }
  487. static short Needfree[MAXARGS];
  488. void
  489. parse_args(
  490. char *arg0,
  491. int argc,
  492. char **argv,
  493. wtab_t *w,
  494. wtab_t *parent,
  495. classtab_t *class,
  496. int *n,
  497. Arg *args,
  498. int * pargc,
  499. char ** pargv ,
  500. Boolean postponePixmaps )
  501. {
  502. int i;
  503. char *colon, *resource, *val, *p;
  504. XtArgVal argval;
  505. int freeflag, len;
  506. char * errmsg;
  507. int conversionResult;
  508. if (pargc)
  509. (*pargc) = 0;
  510. *n = 0;
  511. for (i = 0; i < argc; i++) {
  512. if (i >= MAXARGS) {
  513. errmsg = strdup(GETMESSAGE(
  514. "Too many resource parameters have been specified; skipping '%s'"));
  515. printerrf(arg0, errmsg,
  516. argv[*n], NULL, NULL, NULL, NULL, NULL,
  517. NULL, NULL);
  518. free(errmsg);
  519. continue;
  520. }
  521. if ((colon = strchr(argv[i], ':')) == NULL)
  522. {
  523. errmsg = strdup(GETMESSAGE(
  524. "Bad resource specification; should be of the form 'name:value' : %s"));
  525. printerrf(arg0, errmsg,
  526. argv[i], NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  527. free(errmsg);
  528. continue;
  529. }
  530. val = &colon[1];
  531. len = colon - argv[i];
  532. resource = XtMalloc(len + 1);
  533. strncpy(resource, argv[i], len);
  534. resource[len] = '\0';
  535. /*
  536. * The following special check fixes a bug in Xt, where the
  537. * string defined for the XmNwaitForWm resource does not
  538. * follow the naming conventions, and is set to "waitforwm".
  539. * In dtksh, users expect the naming conventions to be
  540. * followed, and this breaks for this one resource.
  541. */
  542. if (strcmp(resource, "waitForWm") == 0)
  543. strcpy(resource, XmNwaitForWm);
  544. if ((conversionResult = ConvertStringToType(arg0, w, parent,
  545. class, resource, val, &argval, &freeflag,
  546. postponePixmaps)) == CONVERT_SUCCEEDED)
  547. {
  548. XtSetArg(args[*n], resource, argval);
  549. /*
  550. * The following is a memory leak, but it allows us to
  551. * comply with what Xt has spec'ed as the required
  552. * behavior of the geometry string (It is a bogus
  553. * requirement!). The Xt Shell widget does not make
  554. * a copy of the incoming 'geometry' string, but
  555. * instead, simply keeps a pointer to the string
  556. * passed-in by the application. For dtksh, this is
  557. * a problem, because we would typically free up the
  558. * string right away. This hack causes us to not free
  559. * up the string.
  560. */
  561. if (strcmp(resource, XmNgeometry) == 0)
  562. Needfree[*n] = False;
  563. else
  564. Needfree[*n] = freeflag;
  565. (*n)++;
  566. }
  567. else if (conversionResult == CONVERT_POSTPONED)
  568. {
  569. /*
  570. * Postpone processing this resource until after the
  571. * the widget has been created, or, in the case of a
  572. * pixmap resource, until any new colors have been set.
  573. */
  574. if (pargc)
  575. {
  576. pargv[*pargc] = argv[i];
  577. (*pargc)++;
  578. }
  579. XtFree(resource);
  580. }
  581. else
  582. {
  583. XtFree(resource);
  584. }
  585. }
  586. }
  587. void
  588. free_args(
  589. int n,
  590. Arg *args )
  591. {
  592. int i;
  593. /*
  594. * Free up argument pointers
  595. */
  596. for (i = 0; i < n; i++) {
  597. XtFree(args[i].name);
  598. if (Needfree[i]) {
  599. XtFree((String)args[i].value);
  600. }
  601. }
  602. }
  603. int
  604. do_XtInitialize(
  605. int argc,
  606. char *argv[] )
  607. {
  608. int ret;
  609. char *dtkdb_hook;
  610. char * errmsg;
  611. int * lockedFds;
  612. if (Toplevel != NULL)
  613. {
  614. errmsg = strdup(GETMESSAGE(
  615. "The toolkit has already been initialized"));
  616. printerr(argv[0], errmsg, NULL);
  617. free(errmsg);
  618. return(1);
  619. }
  620. if (argc < 4) {
  621. errmsg =strdup(GETMESSAGE(
  622. "Usage: XtInitialize variable applicationName applicationClass [args ...]"));
  623. printerr(str_nill, errmsg, NULL);
  624. free(errmsg);
  625. return(1);
  626. }
  627. lockedFds = LockKshFileDescriptors();
  628. ret = toolkit_initialize(argc, argv);
  629. UnlockKshFileDescriptors(lockedFds);
  630. XtAddActions((XtActionList)Ksh_actions, XtNumber(Ksh_actions));
  631. if ((dtkdb_hook = env_get("DTKDB_HOOK")) != NULL) {
  632. ksh_eval(dtkdb_hook);
  633. }
  634. return(ret);
  635. }
  636. static int
  637. _CreateWidget(
  638. Widget (*func)(),
  639. int argc,
  640. char *argv[] )
  641. {
  642. Widget widget;
  643. classtab_t *class;
  644. char *arg0 = argv[0];
  645. wtab_t *w, *pw, *wtab;
  646. char *wname, *wclass, *parentid, *var;
  647. Arg args[MAXARGS];
  648. int i;
  649. int n;
  650. char * errmsg;
  651. int pargc;
  652. char ** pargv;
  653. if (argc < 5) {
  654. errmsg = strdup(GETMESSAGE(
  655. "Usage: %s variable name class parent [arg:val ...]"));
  656. printerrf(str_nill, errmsg,
  657. argv[0], NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  658. free(errmsg);
  659. return(1);
  660. }
  661. var = argv[1];
  662. wname = argv[2];
  663. wclass = argv[3];
  664. parentid = argv[4];
  665. pw = str_to_wtab(argv[0], parentid);
  666. if (pw == NULL) {
  667. errmsg = strdup(GetSharedMsg(DT_NO_PARENT));
  668. printerr(argv[0], errmsg, NULL);
  669. free(errmsg);
  670. return(1);
  671. }
  672. argv += 5;
  673. argc -= 5;
  674. if ((class = str_to_class(arg0, wclass)) == NULL) {
  675. return(1);
  676. }
  677. pargc = 0;
  678. if (argc > 0) {
  679. pargv = (char **)XtMalloc(sizeof(char *) * argc);
  680. }
  681. else {
  682. pargv = NULL;
  683. }
  684. n = 0;
  685. parse_args(arg0, argc, argv, NULL, pw, class, &n, args, &pargc, pargv,
  686. True);
  687. widget = func(wname, class->class, pw->w, args, n);
  688. if (widget != NULL) {
  689. wtab = set_up_w(widget, pw, var, wname, class);
  690. /* Process any postponed resources */
  691. if (pargc > 0)
  692. {
  693. free_args(n, args);
  694. n = 0;
  695. parse_args(arg0, pargc, pargv, wtab, pw, class, &n,
  696. args, NULL, NULL, False);
  697. XtSetValues(widget, args, n);
  698. }
  699. } else {
  700. errmsg = strdup(GetSharedMsg(DT_WIDGET_CREATE_FAILED));
  701. printerrf(argv[0], errmsg, wname,
  702. NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  703. free(errmsg);
  704. env_blank(argv[1]);
  705. }
  706. free_args(n, args);
  707. XtFree((char *)pargv);
  708. return(0);
  709. }
  710. int
  711. do_XtCreateApplicationShell(
  712. int argc,
  713. char *argv[] )
  714. {
  715. Widget widget;
  716. classtab_t *class;
  717. char *arg0 = argv[0];
  718. wtab_t *w, *wtab;
  719. char *wname, *wclass, *var;
  720. Arg args[MAXARGS];
  721. int i;
  722. int n;
  723. char * errmsg;
  724. int pargc;
  725. char ** pargv;
  726. if (argc < 4) {
  727. errmsg=strdup(GETMESSAGE(
  728. "Usage: XtCreateApplicationShell variable name class [arg:val ...]"));
  729. printerr(str_nill, errmsg, NULL);
  730. free(errmsg);
  731. return(1);
  732. }
  733. var = argv[1];
  734. wname = argv[2];
  735. wclass = argv[3];
  736. argv += 4;
  737. argc -= 4;
  738. if ((class = str_to_class(arg0, wclass)) == NULL) {
  739. return(1);
  740. }
  741. pargc = 0;
  742. if (argc > 0) {
  743. pargv = (char **)XtMalloc(sizeof(char *) * argc);
  744. }
  745. else {
  746. pargv = NULL;
  747. }
  748. n = 0;
  749. parse_args(arg0, argc, argv, NULL, NULL, class, &n, args, &pargc,
  750. pargv, True);
  751. widget = XtCreateApplicationShell(wname, class->class, args, n);
  752. if (widget != NULL) {
  753. wtab = set_up_w(widget, NULL, var, wname, class);
  754. /* Process any postponed resources */
  755. if (pargc > 0)
  756. {
  757. free_args(n, args);
  758. n = 0;
  759. parse_args(arg0, pargc, pargv, wtab, NULL, class,
  760. &n, args, NULL, NULL, False);
  761. XtSetValues(widget, args, n);
  762. }
  763. } else {
  764. errmsg = strdup(GetSharedMsg(DT_WIDGET_CREATE_FAILED));
  765. printerrf(argv[0], errmsg, wname,
  766. NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  767. free(errmsg);
  768. env_blank(argv[1]);
  769. }
  770. free_args(n, args);
  771. XtFree((char *)pargv);
  772. return(0);
  773. }
  774. int
  775. do_XtCreatePopupShell(
  776. int argc,
  777. char *argv[] )
  778. {
  779. return(_CreateWidget(XtCreatePopupShell, argc, argv));
  780. }
  781. int
  782. do_XtCreateManagedWidget(
  783. int argc,
  784. char *argv[] )
  785. {
  786. return(_CreateWidget(XtCreateManagedWidget, argc, argv));
  787. }
  788. int
  789. do_XtCreateWidget(
  790. int argc,
  791. char *argv[] )
  792. {
  793. return(_CreateWidget(XtCreateWidget, argc, argv));
  794. }
  795. int
  796. do_XtPopup(
  797. int argc,
  798. char *argv[] )
  799. {
  800. wtab_t *w;
  801. XtGrabKind grab;
  802. char * errmsg;
  803. if (argc != 3)
  804. {
  805. errmsg=strdup(GETMESSAGE(
  806. "Usage: XtPopup widget GrabNone|GrabNonexclusive|GrabExclusive"));
  807. printerr(str_nill, errmsg, NULL);
  808. free(errmsg);
  809. return(1);
  810. }
  811. w = str_to_wtab(argv[0], argv[1]);
  812. if (w == NULL)
  813. return(1);
  814. else
  815. {
  816. grab = XtGrabNone;
  817. if (argc < 3 || strcmp(argv[2], "GrabNone") == 0)
  818. grab = XtGrabNone;
  819. else if (strcmp(argv[2], "GrabNonexclusive") == 0)
  820. grab = XtGrabNonexclusive;
  821. else if (strcmp(argv[2], "GrabExclusive") == 0)
  822. grab = XtGrabExclusive;
  823. else
  824. {
  825. errmsg=strdup(GETMESSAGE(
  826. "The grab type '%s' is not recognized; using 'GrabNone'"));
  827. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  828. NULL, NULL);
  829. free(errmsg);
  830. }
  831. XtPopup(w->w, grab);
  832. }
  833. return(0);
  834. }
  835. static int
  836. _DTKSH_XtDestroyWidget(
  837. Widget w )
  838. {
  839. XtDestroyWidget(w);
  840. return(1);
  841. }
  842. static int
  843. do_single_widget_arg_func(
  844. int (*func)(),
  845. int argc,
  846. char **argv )
  847. {
  848. wtab_t *w;
  849. int i;
  850. char * errmsg;
  851. if (argc < 2) {
  852. errmsg = strdup(GetSharedMsg(DT_USAGE_WIDGET));
  853. printerrf(str_nill, errmsg, argv[0], NULL, NULL,
  854. NULL, NULL, NULL, NULL, NULL);
  855. free(errmsg);
  856. return(1);
  857. }
  858. for (i = 1; i < argc; i++) {
  859. w = str_to_wtab(argv[0], argv[i]);
  860. if (w != NULL) {
  861. func(w->w);
  862. }
  863. }
  864. return(0);
  865. }
  866. int
  867. do_XtDestroyWidget(
  868. int argc,
  869. char *argv[] )
  870. {
  871. return(do_single_widget_arg_func(_DTKSH_XtDestroyWidget, argc, argv));
  872. }
  873. int
  874. do_single_widget_test_func(
  875. int (*func)(),
  876. int argc,
  877. char **argv )
  878. {
  879. wtab_t *w;
  880. int i;
  881. char * errmsg;
  882. if (argc != 2) {
  883. errmsg=strdup(GetSharedMsg(DT_USAGE_WIDGET));
  884. printerrf(str_nill, errmsg, argv[0], NULL, NULL,
  885. NULL, NULL, NULL, NULL, NULL);
  886. free(errmsg);
  887. return(1);
  888. }
  889. w = str_to_wtab(argv[0], argv[1]);
  890. if (w != NULL) {
  891. return(!func(w->w));
  892. }
  893. return(255);
  894. }
  895. int
  896. do_XtIsSensitive(
  897. int argc,
  898. char *argv[] )
  899. {
  900. return(do_single_widget_test_func((int(*)())XtIsSensitive, argc, argv));
  901. }
  902. /*
  903. * XtIsShell() is a macro, so we can't use do_single_widget_test_func().
  904. */
  905. int
  906. do_XtIsShell(
  907. int argc,
  908. char *argv[] )
  909. {
  910. wtab_t *w;
  911. int i;
  912. char * errmsg;
  913. if (argc != 2)
  914. {
  915. errmsg = strdup(GETMESSAGE("Usage: XtIsShell widget"));
  916. printerr(str_nill, errmsg, NULL);
  917. free(errmsg);
  918. return(1);
  919. }
  920. w = str_to_wtab(argv[0], argv[1]);
  921. if (w != NULL)
  922. return(!XtIsShell(w->w));
  923. return(255);
  924. }
  925. int
  926. do_XtIsManaged(
  927. int argc,
  928. char *argv[] )
  929. {
  930. return(do_single_widget_test_func((int(*)())XtIsManaged, argc, argv));
  931. }
  932. int
  933. do_XtIsRealized(
  934. int argc,
  935. char *argv[] )
  936. {
  937. return(do_single_widget_test_func((int(*)())XtIsRealized, argc, argv));
  938. }
  939. int
  940. do_XtRealizeWidget(
  941. int argc,
  942. char *argv[] )
  943. {
  944. return(do_single_widget_arg_func((int(*)())XtRealizeWidget, argc, argv));
  945. }
  946. int
  947. do_XtUnrealizeWidget(
  948. int argc,
  949. char *argv[] )
  950. {
  951. return(do_single_widget_arg_func((int(*)())XtUnrealizeWidget, argc, argv));
  952. }
  953. /*
  954. * XtMapWidget() is a macro, so can't use do_single_widget_arg_func()
  955. */
  956. int
  957. do_XtMapWidget(
  958. int argc,
  959. char *argv[] )
  960. {
  961. wtab_t *w;
  962. int i;
  963. char * errmsg;
  964. if (argc < 2) {
  965. errmsg = strdup(GETMESSAGE("Usage: XtMapWidget widget"));
  966. printerr(str_nill, errmsg, NULL);
  967. free(errmsg);
  968. return(1);
  969. }
  970. for (i = 1; i < argc; i++) {
  971. w = str_to_wtab(argv[0], argv[i]);
  972. if (w != NULL) {
  973. XtMapWidget(w->w);
  974. }
  975. }
  976. return(0);
  977. }
  978. int
  979. do_XtUnmapWidget(
  980. int argc,
  981. char **argv )
  982. {
  983. wtab_t *w;
  984. int i;
  985. char * errmsg;
  986. if (argc < 2) {
  987. errmsg = strdup(GETMESSAGE("Usage: XtUnmapWidget widget"));
  988. printerr(str_nill, errmsg, NULL);
  989. free(errmsg);
  990. return(1);
  991. }
  992. for (i = 1; i < argc; i++) {
  993. w = str_to_wtab(argv[0], argv[i]);
  994. if (w != NULL) {
  995. XtUnmapWidget(w->w);
  996. }
  997. }
  998. return(0);
  999. }
  1000. int
  1001. do_XtPopdown(
  1002. int argc,
  1003. char **argv )
  1004. {
  1005. return(do_single_widget_arg_func((int(*)())XtPopdown, argc, argv));
  1006. }
  1007. int
  1008. do_XtMainLoop(
  1009. int argc,
  1010. char **argv )
  1011. {
  1012. /*
  1013. * Required to guarantee that all of the shell script's "echo"
  1014. * requests have been taken care of, before we drop into the
  1015. * the black hole called XtMainLoop.
  1016. */
  1017. fflush(stdout);
  1018. XtMainLoop();
  1019. return(1);
  1020. }
  1021. int
  1022. do_XtDisplay(
  1023. int argc,
  1024. char **argv )
  1025. {
  1026. return(GetDisplayHandle(argc, argv, (Widget (*)())XtDisplay));
  1027. }
  1028. int
  1029. do_XtDisplayOfObject(
  1030. int argc,
  1031. char **argv )
  1032. {
  1033. return(GetDisplayHandle(argc, argv, (Widget (*)())XtDisplayOfObject));
  1034. }
  1035. static int
  1036. GetDisplayHandle(
  1037. int argc,
  1038. char **argv,
  1039. Widget (*func)())
  1040. {
  1041. wtab_t *w;
  1042. char *arg0 = argv[0];
  1043. char * variable = argv[1];
  1044. char buf[128];
  1045. char * errmsg;
  1046. if (argc != 3)
  1047. {
  1048. errmsg = strdup(GETMESSAGE("Usage: %s variable widget"));
  1049. printerrf(str_nill, errmsg, arg0, NULL, NULL, NULL, NULL, NULL,
  1050. NULL, NULL);
  1051. free(errmsg);
  1052. return(1);
  1053. }
  1054. w = str_to_wtab(arg0, argv[2]);
  1055. if (w == NULL)
  1056. return(1);
  1057. sprintf(buf, "0x%lx", (long)(*func)(w->w));
  1058. alt_env_set_var(variable, buf);
  1059. return(0);
  1060. }
  1061. int
  1062. do_XtNameToWidget(
  1063. int argc,
  1064. char *argv[] )
  1065. {
  1066. char *arg0 = argv[0];
  1067. wtab_t * w;
  1068. char * variable = argv[1];
  1069. Widget child;
  1070. classtab_t *ctab;
  1071. char * errmsg;
  1072. if (argc != 4)
  1073. {
  1074. errmsg = strdup(GETMESSAGE(
  1075. "Usage: XtNameToWidget variable referenceWidget names"));
  1076. printerr(str_nill, errmsg, NULL);
  1077. free(errmsg);
  1078. return(1);
  1079. }
  1080. w = str_to_wtab(arg0, argv[2]);
  1081. if (w == NULL) {
  1082. alt_env_set_var(variable, str_nill);
  1083. return(1);
  1084. }
  1085. child = XtNameToWidget(w->w, argv[3]);
  1086. if (child == NULL)
  1087. {
  1088. alt_env_set_var(variable, str_nill);
  1089. return(1);
  1090. }
  1091. w = widget_to_wtab(child);
  1092. if (w == NULL) {
  1093. alt_env_set_var(variable, str_nill);
  1094. return(1);
  1095. }
  1096. /*
  1097. * If the widget class has no resources registered, then this is
  1098. * the first known instance of this widget class, so we need to
  1099. * force the resource list to be loaded. This can frequently
  1100. * occur if a Motif convenience function is used, which creates
  1101. * a 'hidden' parent.
  1102. */
  1103. ctab = w->wclass;
  1104. if (ctab->res == NULL)
  1105. (void)str_to_class(arg0, ctab->cname);
  1106. alt_env_set_var(variable, w->widid);
  1107. return(0);
  1108. }
  1109. int
  1110. do_XtScreen(
  1111. int argc,
  1112. char **argv )
  1113. {
  1114. wtab_t *w;
  1115. char *arg0 = argv[0];
  1116. char * variable = argv[1];
  1117. char buf[128];
  1118. char * errmsg;
  1119. if (argc != 3)
  1120. {
  1121. errmsg = strdup(GETMESSAGE("Usage: XtScreen variable widget"));
  1122. printerr(str_nill, errmsg, NULL);
  1123. free(errmsg);
  1124. return(1);
  1125. }
  1126. w = str_to_wtab(arg0, argv[2]);
  1127. if (w == NULL)
  1128. return(1);
  1129. sprintf(buf, "0x%lx", (long)XtScreen(w->w));
  1130. alt_env_set_var(variable, buf);
  1131. return(0);
  1132. }
  1133. int
  1134. do_XtWindow(
  1135. int argc,
  1136. char **argv )
  1137. {
  1138. wtab_t *w;
  1139. char *arg0 = argv[0];
  1140. char * variable = argv[1];
  1141. char buf[128];
  1142. char * errmsg;
  1143. if (argc != 3)
  1144. {
  1145. errmsg = strdup(GETMESSAGE("Usage: XtWindow variable widget"));
  1146. printerr(str_nill, errmsg, NULL);
  1147. free(errmsg);
  1148. return(1);
  1149. }
  1150. w = str_to_wtab(arg0, argv[2]);
  1151. if (w == NULL)
  1152. return(1);
  1153. sprintf(buf, "0x%lx", (long)XtWindow(w->w));
  1154. alt_env_set_var(variable, buf);
  1155. return(0);
  1156. }
  1157. static int
  1158. XtCallCallbacks_usage(
  1159. char *arg0 )
  1160. {
  1161. char * errmsg;
  1162. errmsg = strdup(GETMESSAGE(
  1163. "Usage: XtCallCallbacks widget callbackName"));
  1164. printerr(str_nill, errmsg, NULL);
  1165. free(errmsg);
  1166. return(1);
  1167. }
  1168. int
  1169. do_XtCallCallbacks(
  1170. int argc,
  1171. char **argv )
  1172. {
  1173. wtab_t *w;
  1174. char *arg0 = argv[0];
  1175. if (argc != 3)
  1176. return(XtCallCallbacks_usage(arg0));
  1177. w = str_to_wtab(argv[0], argv[1]);
  1178. if (w == NULL)
  1179. return(1);
  1180. else
  1181. XtCallCallbacks(w->w, argv[2], NULL);
  1182. return(0);
  1183. }
  1184. int
  1185. do_XtHasCallbacks(
  1186. int argc,
  1187. char **argv )
  1188. {
  1189. wtab_t *w;
  1190. char *arg0 = argv[0];
  1191. char * msg = "";
  1192. char * variable = argv[1];
  1193. XtCallbackStatus callbackStatus;
  1194. XrmValue fval, tval;
  1195. char * errmsg;
  1196. if (argc != 4)
  1197. {
  1198. errmsg = strdup(GETMESSAGE(
  1199. "Usage: XtHasCallbacks variable widget callbackName"));
  1200. printerr(str_nill, errmsg, NULL);
  1201. free(errmsg);
  1202. return(1);
  1203. }
  1204. w = str_to_wtab(argv[0], argv[2]);
  1205. if (w == NULL)
  1206. return(1);
  1207. else
  1208. callbackStatus = XtHasCallbacks(w->w, argv[3]);
  1209. switch (callbackStatus)
  1210. {
  1211. case XtCallbackNoList:
  1212. {
  1213. msg = "CallbackNoList";
  1214. break;
  1215. }
  1216. case XtCallbackHasNone:
  1217. {
  1218. msg = "CallbackHasNone";
  1219. break;
  1220. }
  1221. case XtCallbackHasSome:
  1222. {
  1223. msg = "CallbackHasSome";
  1224. break;
  1225. }
  1226. }
  1227. alt_env_set_var(variable, msg);
  1228. return(0);
  1229. }
  1230. int
  1231. do_XtAddCallback(
  1232. int argc,
  1233. char **argv )
  1234. {
  1235. char * errmsg;
  1236. if (argc != 4)
  1237. {
  1238. errmsg = strdup(GETMESSAGE(
  1239. "Usage: XtAddCallback widget callbackName ksh-command"));
  1240. printerr(str_nill, errmsg, NULL);
  1241. free(errmsg);
  1242. return(1);
  1243. }
  1244. return(AddOneCallback(argv[0], argv[1], argv[2], argv[3], NULL));
  1245. }
  1246. /*
  1247. * This function is used to add both regular Xt Callbacks, and
  1248. * Motif WMProtocol callback.
  1249. */
  1250. int
  1251. AddOneCallback(
  1252. char *cmd,
  1253. char *widget,
  1254. char *cbName,
  1255. char *kshcmd,
  1256. char *propAtomStr )
  1257. {
  1258. wtab_t *w;
  1259. dtksh_client_data_t *cdata;
  1260. char * p;
  1261. Atom propAtom;
  1262. char * errmsg;
  1263. w = str_to_wtab(cmd, widget);
  1264. if (w == NULL)
  1265. return(1);
  1266. if (propAtomStr)
  1267. {
  1268. propAtom = (Atom)strtoul(propAtomStr, &p, 0);
  1269. if (p == propAtomStr)
  1270. {
  1271. errmsg = strdup(GetSharedMsg(DT_BAD_ATOM));
  1272. printerrf(cmd, errmsg, propAtomStr, NULL, NULL, NULL, NULL, NULL,
  1273. NULL, NULL);
  1274. free(errmsg);
  1275. return(1);
  1276. }
  1277. }
  1278. else
  1279. propAtom = None;
  1280. cdata = GetNewCBData(kshcmd, w, cbName, propAtom);
  1281. if (strcmp(cmd, "XtAddCallback") == 0)
  1282. XtAddCallback(w->w, cbName, (XtCallbackProc)stdCB, (XtPointer)cdata);
  1283. else
  1284. {
  1285. XmAddWMProtocolCallback(w->w, propAtom, (XtCallbackProc)stdCB,
  1286. (XtPointer)cdata);
  1287. }
  1288. return(0);
  1289. }
  1290. int
  1291. do_XtRemoveCallback(
  1292. int argc,
  1293. char **argv )
  1294. {
  1295. char * errmsg;
  1296. if (argc != 4)
  1297. {
  1298. errmsg = strdup(GETMESSAGE(
  1299. "Usage: XtRemoveCallback widget callbackName ksh-command"));
  1300. printerr(str_nill, errmsg, NULL);
  1301. free(errmsg);
  1302. return(1);
  1303. }
  1304. return(RemoveOneCallback (argv[0], argv[1], argv[2], argv[3], NULL, NULL));
  1305. }
  1306. /*
  1307. * This function is used to delete both regular Xt Callbacks, and
  1308. * Motif WMProtocol callback.
  1309. */
  1310. int
  1311. RemoveOneCallback(
  1312. char *cmd,
  1313. char *widget,
  1314. char *cbName,
  1315. char *kshcmd,
  1316. char *propAtomStr,
  1317. char *handleStr )
  1318. {
  1319. wtab_t *w;
  1320. dtksh_client_data_t *cdata;
  1321. int i;
  1322. Atom propAtom;
  1323. char * p;
  1324. DtWsmCBContext handle;
  1325. char * errmsg;
  1326. w = str_to_wtab(cmd, widget);
  1327. if (w == NULL)
  1328. return(1);
  1329. if (propAtomStr)
  1330. {
  1331. propAtom = (Atom)strtoul(propAtomStr, &p, 0);
  1332. if (p == propAtomStr)
  1333. {
  1334. errmsg = strdup(GetSharedMsg(DT_BAD_ATOM));
  1335. printerrf(cmd, errmsg, propAtomStr, NULL, NULL, NULL, NULL, NULL,
  1336. NULL, NULL);
  1337. free(errmsg);
  1338. return(1);
  1339. }
  1340. }
  1341. else
  1342. propAtom = None;
  1343. if (handleStr)
  1344. {
  1345. handle = (DtWsmCBContext)strtoul(handleStr, &p, 0);
  1346. if (p == handleStr)
  1347. {
  1348. errmsg = strdup(GETMESSAGE(
  1349. "The following is an invalid callback handle: %s"));
  1350. printerrf(cmd, errmsg, handleStr, NULL, NULL, NULL, NULL, NULL,
  1351. NULL, NULL);
  1352. free(errmsg);
  1353. return(1);
  1354. }
  1355. }
  1356. else
  1357. handle = NULL;
  1358. /* Locate the matching table entry */
  1359. if ((i = LocateCBRecord (w, cbName, kshcmd, propAtom, handle)) >= 0)
  1360. {
  1361. cdata = cbDataTable[i];
  1362. if (strcmp(cmd, "XtRemoveCallback") == 0)
  1363. XtRemoveCallback(w->w, cbName, (XtCallbackProc)stdCB,(XtPointer)cdata);
  1364. else if (strcmp(cmd, "XmRemoveWMProtocolCallback") == 0)
  1365. {
  1366. XmRemoveWMProtocolCallback(w->w, propAtom, (XtCallbackProc)stdCB,
  1367. (XtPointer)cdata);
  1368. }
  1369. else
  1370. {
  1371. DtWsmRemoveWorkspaceCallback(handle);
  1372. }
  1373. if (--(cdata->refCount) <= 0)
  1374. {
  1375. XtFree(cdata->ksh_cmd);
  1376. XtFree(cdata->cbname);
  1377. XtFree((XtPointer)cdata);
  1378. cbDataTable[i] = NULL;
  1379. return(0);
  1380. }
  1381. return(0);
  1382. }
  1383. errmsg = strdup(GETMESSAGE(
  1384. "The specified callback is not registered"));
  1385. printerr(cmd, errmsg, NULL);
  1386. free(errmsg);
  1387. return(1);
  1388. }
  1389. int
  1390. do_XtAddEventHandler(
  1391. int argc,
  1392. char **argv )
  1393. {
  1394. wtab_t *w;
  1395. char *arg0 = argv[0];
  1396. dtksh_event_handler_data_t *ehdata;
  1397. Boolean nonMaskable;
  1398. EventMask eventMask;
  1399. XrmValue fval, tval;
  1400. char * errmsg;
  1401. if (argc != 5)
  1402. {
  1403. errmsg=strdup(GETMESSAGE(
  1404. "Usage: XtAddEventHandler widget mask nonMaskable ksh-command"));
  1405. printerr(str_nill, errmsg, NULL);
  1406. free(errmsg);
  1407. return(1);
  1408. }
  1409. w = str_to_wtab(arg0, argv[1]);
  1410. if (w == NULL)
  1411. return(1);
  1412. fval.addr = argv[3];
  1413. fval.size = strlen(argv[3]);
  1414. XtConvert(Toplevel, XtRString, &fval, XtRBoolean, &tval);
  1415. if (tval.size != 0)
  1416. nonMaskable = *((Boolean *)(tval.addr));
  1417. else
  1418. return(1);
  1419. fval.addr = argv[2];
  1420. fval.size = strlen(argv[2]);
  1421. XtConvert(Toplevel, XtRString, &fval, "EventMask", &tval);
  1422. if (tval.size != 0)
  1423. eventMask = *((EventMask *)(tval.addr));
  1424. else
  1425. return(1);
  1426. if ((eventMask == 0) && (nonMaskable == False))
  1427. return(1);
  1428. ehdata = GetNewEHData(argv[4], w, eventMask, nonMaskable);
  1429. XtAddEventHandler(w->w, eventMask, nonMaskable, (XtEventHandler)stdEH,
  1430. (XtPointer)ehdata);
  1431. return(0);
  1432. }
  1433. int
  1434. do_XtRemoveEventHandler(
  1435. int argc,
  1436. char **argv )
  1437. {
  1438. wtab_t *w;
  1439. char *arg0 = argv[0];
  1440. dtksh_event_handler_data_t *ehdata;
  1441. int i;
  1442. Boolean nonMaskable;
  1443. EventMask eventMask;
  1444. XrmValue fval, tval;
  1445. char * errmsg;
  1446. if (argc != 5)
  1447. {
  1448. errmsg =strdup(GETMESSAGE(
  1449. "Usage: XtRemoveEventHandler widget mask nonMaskable ksh-command"));
  1450. printerr(str_nill, errmsg, NULL);
  1451. free(errmsg);
  1452. return(1);
  1453. }
  1454. w = str_to_wtab(arg0, argv[1]);
  1455. if (w == NULL)
  1456. return(1);
  1457. /* Locate the matching table entry */
  1458. if ((i = LocateEHRecord (w, argv[4])) >= 0)
  1459. {
  1460. ehdata = ehDataTable[i];
  1461. fval.addr = argv[3];
  1462. fval.size = strlen(argv[3]);
  1463. XtConvert(Toplevel, XtRString, &fval, XtRBoolean, &tval);
  1464. if (tval.size != 0)
  1465. {
  1466. nonMaskable = *((Boolean *)(tval.addr));
  1467. /* See if non-maskable event processing has been turned off */
  1468. if (nonMaskable)
  1469. ehdata->nonMaskable = False;
  1470. }
  1471. else
  1472. return(1);
  1473. fval.addr = argv[2];
  1474. fval.size = strlen(argv[2]);
  1475. XtConvert(Toplevel, XtRString, &fval, "EventMask", &tval);
  1476. if (tval.size != 0)
  1477. {
  1478. eventMask = *((EventMask *)(tval.addr));
  1479. /* Disable the specified set of events */
  1480. ehdata->eventMask &= ~eventMask;
  1481. }
  1482. else
  1483. return(1);
  1484. XtRemoveEventHandler (w->w, eventMask, nonMaskable, (XtEventHandler)stdEH,
  1485. (XtPointer)ehdata);
  1486. if ((ehdata->eventMask == 0) && (ehdata->nonMaskable == False))
  1487. {
  1488. /* It is now safe to remove this entry */
  1489. XtFree(ehdata->ksh_cmd);
  1490. XtFree((XtPointer)ehdata);
  1491. ehDataTable[i] = NULL;
  1492. return(0);
  1493. }
  1494. return(0);
  1495. }
  1496. errmsg = strdup(GETMESSAGE(
  1497. "The specified event handler is not registered"));
  1498. printerr(arg0, errmsg, NULL);
  1499. free(errmsg);
  1500. return(1);
  1501. }
  1502. int
  1503. do_XtGetValues(
  1504. int argc,
  1505. char **argv )
  1506. {
  1507. int i, j;
  1508. int n;
  1509. char *arg0 = argv[0];
  1510. char *val, *p, *str;
  1511. Arg args[MAXARGS];
  1512. char *envar[MAXARGS];
  1513. wtab_t *w;
  1514. char * errmsg;
  1515. if (argc < 3) {
  1516. errmsg = strdup(GETMESSAGE(
  1517. "Usage: XtGetValues widget resource:variable ..."));
  1518. printerr(str_nill, errmsg, NULL);
  1519. free(errmsg);
  1520. return(1);
  1521. }
  1522. w = str_to_wtab(argv[0], argv[1]);
  1523. argv += 2;
  1524. argc -= 2;
  1525. if (w == NULL) {
  1526. return(1);
  1527. }
  1528. /*
  1529. * Arguments are of the form:
  1530. *
  1531. * resource:envar
  1532. */
  1533. for (i = 0, n = 0; i < argc; i++) {
  1534. if ((p = strchr(argv[i], ':')) == NULL) {
  1535. errmsg=strdup(GETMESSAGE(
  1536. "The following resource parameter is incorrectly formed: %s"));
  1537. printerrf(arg0, errmsg, argv[i],
  1538. NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  1539. free(errmsg);
  1540. continue;
  1541. }
  1542. *p = '\0';
  1543. /*
  1544. * The following special check fixes a bug in Xt, where the
  1545. * string defined for the XmNwaitForWm resource does not
  1546. * follow the naming conventions, and is set to "waitforwm".
  1547. * In dtksh, users expect the naming conventions to be
  1548. * followed, and this breaks for this one resource.
  1549. */
  1550. if (strcmp(argv[n], "waitForWm") == 0)
  1551. args[n].name = strdup(XmNwaitForWm);
  1552. else
  1553. args[n].name = strdup(argv[n]);
  1554. envar[n] = &p[1];
  1555. *p = ':';
  1556. args[n].value = (XtArgVal)stakalloc(256);
  1557. n++;
  1558. }
  1559. XtGetValues(w->w, args, n);
  1560. for (i = 0; i < n; i++) {
  1561. if (ConvertTypeToString(arg0, w->wclass, w, w->parent, args[i].name, args[i].value, &str) != FAIL) {
  1562. env_set_var(envar[i], str);
  1563. }
  1564. else
  1565. env_blank(envar[i]);
  1566. XtFree(args[i].name);
  1567. }
  1568. return(0);
  1569. }
  1570. int
  1571. do_XtSetValues(
  1572. int argc,
  1573. char **argv )
  1574. {
  1575. int n;
  1576. char *arg0 = argv[0];
  1577. Arg args[MAXARGS];
  1578. wtab_t *w;
  1579. char * errmsg;
  1580. int pargc;
  1581. char ** pargv;
  1582. if (argc < 3) {
  1583. errmsg = strdup(GETMESSAGE(
  1584. "Usage: XtSetValues widget arg:val ..."));
  1585. printerr(str_nill, errmsg, NULL);
  1586. free(errmsg);
  1587. return(1);
  1588. }
  1589. w = str_to_wtab(argv[0], argv[1]);
  1590. argv += 2;
  1591. argc -= 2;
  1592. if (w == NULL) {
  1593. return(1);
  1594. } else {
  1595. pargc = 0;
  1596. pargv = (char **)XtMalloc(sizeof(char *) * argc);
  1597. n = 0;
  1598. parse_args(arg0, argc, argv, w, w->parent, w->wclass, &n, args,
  1599. &pargc, pargv, True);
  1600. if (n > 0)
  1601. XtSetValues(w->w, args, n);
  1602. /* Process any postponed resources */
  1603. if (pargc > 0)
  1604. {
  1605. free_args(n, args);
  1606. n = 0;
  1607. parse_args(arg0, pargc, pargv, w, w->parent,
  1608. w->wclass, &n, args, NULL, NULL, False);
  1609. XtSetValues(w->w, args, n);
  1610. }
  1611. free_args(n, args);
  1612. XtFree((char *)pargv);
  1613. }
  1614. return(0);
  1615. }
  1616. /*
  1617. * When a timeout or work proc is added, the memory allocated for the
  1618. * clientData (i.e. the command string) will be lost, unless we provide
  1619. * a means of associating the string with the workproc/timeout id, and
  1620. * then free up the memory when the workproc/timeout is removed. The
  1621. * following two functions implement such a mechanism. This prevents
  1622. * a memory leak from occurring.
  1623. */
  1624. static void
  1625. RegisterCmdStr(
  1626. char type,
  1627. long id,
  1628. char *cmd )
  1629. {
  1630. CommandString **table;
  1631. int * tableSize;
  1632. if (type == WORKPROC_CMDS)
  1633. {
  1634. table = &workProcCmds;
  1635. tableSize = &workProcCmdsSize;
  1636. }
  1637. else
  1638. {
  1639. table = &timeOutCmds;
  1640. tableSize = &timeOutCmdsSize;
  1641. }
  1642. (*tableSize)++;
  1643. *table = (CommandString *)XtRealloc((char *)*table,
  1644. sizeof(CommandString) * (*tableSize));
  1645. (*table)[(*tableSize)-1].id = id;
  1646. (*table)[(*tableSize)-1].cmd = cmd;
  1647. }
  1648. static void
  1649. RemoveCmdStr(
  1650. char type,
  1651. long id )
  1652. {
  1653. CommandString **table;
  1654. int * tableSize;
  1655. int i, j;
  1656. if (type == WORKPROC_CMDS)
  1657. {
  1658. table = &workProcCmds;
  1659. tableSize = &workProcCmdsSize;
  1660. }
  1661. else
  1662. {
  1663. table = &timeOutCmds;
  1664. tableSize = &timeOutCmdsSize;
  1665. }
  1666. for (i = 0; i < (*tableSize); i++)
  1667. {
  1668. if (id == (*table)[i].id)
  1669. {
  1670. XtFree((*table)[i].cmd);
  1671. (*tableSize)--;
  1672. for (j = i; j < (*tableSize); j++)
  1673. (*table)[j] = (*table)[j+1];
  1674. *table = (CommandString *)XtRealloc((char *) (*table),
  1675. sizeof(CommandString) * (*tableSize));
  1676. break;
  1677. }
  1678. }
  1679. }
  1680. int
  1681. do_XtAddWorkProc(
  1682. int argc,
  1683. char *argv[] )
  1684. {
  1685. char *variable;
  1686. char *cmd;
  1687. char buf[256];
  1688. XtWorkProcId id;
  1689. char * errmsg;
  1690. if (argc != 3)
  1691. {
  1692. errmsg = strdup(GETMESSAGE(
  1693. "Usage: XtAddWorkProc variable command"));
  1694. printerr(str_nill, errmsg, NULL);
  1695. free(errmsg);
  1696. return(1);
  1697. }
  1698. variable = argv[1];
  1699. cmd = strdup((char *)argv[2]);
  1700. id = XtAddWorkProc((XtWorkProc)stdWorkProcCB, (XtPointer)cmd);
  1701. RegisterCmdStr(WORKPROC_CMDS, (long)id, cmd);
  1702. sprintf(buf, "0x%lx", (long)id);
  1703. alt_env_set_var(variable, buf);
  1704. return(0);
  1705. }
  1706. int
  1707. do_XtRemoveWorkProc(
  1708. int argc,
  1709. char *argv[] )
  1710. {
  1711. XtWorkProcId id;
  1712. char *p;
  1713. char * errmsg;
  1714. if (argc != 2)
  1715. {
  1716. errmsg = strdup(GETMESSAGE("Usage: XtRemoveWorkProc workProcId"));
  1717. printerr(str_nill, errmsg, NULL);
  1718. free(errmsg);
  1719. return(1);
  1720. }
  1721. id = strtoul(argv[1], &p, 16);
  1722. if (p == argv[1])
  1723. {
  1724. errmsg=strdup(GETMESSAGE(
  1725. "The workProcId parameter must be a hex number: %s"));
  1726. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL, NULL,
  1727. NULL, NULL);
  1728. free(errmsg);
  1729. return(1);
  1730. }
  1731. XtRemoveWorkProc(id);
  1732. RemoveCmdStr(WORKPROC_CMDS, (long)id);
  1733. return(0);
  1734. }
  1735. int
  1736. do_XtAddTimeOut(
  1737. int argc,
  1738. char *argv[] )
  1739. {
  1740. unsigned long milliseconds = 0;
  1741. wtab_t *w;
  1742. char *variable;
  1743. char *cmd;
  1744. char buf[256];
  1745. XtIntervalId id;
  1746. char * errmsg;
  1747. if (argc != 4)
  1748. {
  1749. errmsg = strdup(GETMESSAGE(
  1750. "Usage: XtAddTimeOut variable milliseconds command"));
  1751. printerr(str_nill, errmsg, NULL);
  1752. free(errmsg);
  1753. return(1);
  1754. }
  1755. variable = argv[1];
  1756. if ((milliseconds = atol(argv[2])) <= 0)
  1757. {
  1758. errmsg = strdup(GETMESSAGE(
  1759. "The milliseconds parameter must be greater than zero"));
  1760. printerr(argv[0], errmsg, NULL);
  1761. free(errmsg);
  1762. alt_env_set_var(variable, str_nill);
  1763. return(1);
  1764. }
  1765. cmd = strdup((char *)argv[3]);
  1766. id = XtAddTimeOut(milliseconds, (XtTimerCallbackProc)stdTimerCB,
  1767. (XtPointer)cmd);
  1768. RegisterCmdStr(TIMEOUT_CMDS, (long)id, cmd);
  1769. sprintf(buf, "0x%lx", (long)id);
  1770. alt_env_set_var(variable, buf);
  1771. return(0);
  1772. }
  1773. int
  1774. do_XtRemoveTimeOut(
  1775. int argc,
  1776. char *argv[] )
  1777. {
  1778. XtIntervalId id;
  1779. char *p;
  1780. char * errmsg;
  1781. if (argc != 2)
  1782. {
  1783. errmsg = strdup(GETMESSAGE("Usage: XtRemoveTimeOut intervalId"));
  1784. printerr(str_nill, errmsg, NULL);
  1785. free(errmsg);
  1786. return(1);
  1787. }
  1788. id = strtoul(argv[1], &p, 16);
  1789. if (p == argv[1]) {
  1790. errmsg = strdup(GETMESSAGE(
  1791. "The intervalId parameter must be a hex number: %s"));
  1792. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL, NULL,
  1793. NULL, NULL);
  1794. free(errmsg);
  1795. return(1);
  1796. }
  1797. XtRemoveTimeOut(id);
  1798. RemoveCmdStr(TIMEOUT_CMDS, (long)id);
  1799. return(0);
  1800. }
  1801. int
  1802. do_XtUnmanageChildren(
  1803. int argc,
  1804. char *argv[] )
  1805. {
  1806. return(do_managelist_func(argc, argv, (int (*)())XtUnmanageChildren));
  1807. }
  1808. int
  1809. do_XtManageChildren(
  1810. int argc,
  1811. char *argv[] )
  1812. {
  1813. return(do_managelist_func(argc, argv, (int (*)())XtManageChildren));
  1814. }
  1815. int
  1816. do_managelist_func(
  1817. int argc,
  1818. char *argv[],
  1819. int (*func)() )
  1820. {
  1821. wtab_t *w;
  1822. int i;
  1823. Widget widgets[MAXARGS];
  1824. Cardinal nwidgets;
  1825. char * errmsg;
  1826. if (argc < 2) {
  1827. errmsg = strdup(GETMESSAGE("Usage: %s widget ..."));
  1828. printerrf(str_nill, errmsg, argv[0], NULL, NULL,
  1829. NULL, NULL, NULL, NULL, NULL);
  1830. free(errmsg);
  1831. return(1);
  1832. }
  1833. for (nwidgets = 0, i = 1; i < argc && nwidgets < MAXARGS; i++) {
  1834. w = str_to_wtab(argv[0], argv[i]);
  1835. if (w != NULL) {
  1836. widgets[nwidgets++] = w->w;
  1837. }
  1838. }
  1839. func(widgets, nwidgets);
  1840. return(0);
  1841. }
  1842. int
  1843. do_XtIsSubclass(
  1844. int argc,
  1845. char *argv[] )
  1846. {
  1847. wtab_t *w;
  1848. int i;
  1849. char * errmsg;
  1850. if (argc != 3)
  1851. {
  1852. errmsg = strdup(GETMESSAGE(
  1853. "Usage: XtIsSubclass widget class"));
  1854. printerr(str_nill, errmsg, NULL);
  1855. free(errmsg);
  1856. return(1);
  1857. }
  1858. w = str_to_wtab(argv[0], argv[1]);
  1859. if (w != NULL)
  1860. {
  1861. for (i = 0; C[i].cname; i++)
  1862. {
  1863. if (strcmp(argv[2], C[i].cname) == 0)
  1864. return(!XtIsSubclass(w->w, C[i].class));
  1865. }
  1866. }
  1867. errmsg = strdup(GETMESSAGE(
  1868. "%s is not a valid widget class name"));
  1869. printerrf(str_nill, errmsg, argv[2], NULL, NULL,
  1870. NULL, NULL, NULL, NULL, NULL);
  1871. free(errmsg);
  1872. return(255);
  1873. }
  1874. int
  1875. do_XtClass(
  1876. int argc,
  1877. char *argv[] )
  1878. {
  1879. wtab_t *w;
  1880. int i;
  1881. char * errmsg;
  1882. WidgetClass class;
  1883. if (argc != 3)
  1884. {
  1885. errmsg = strdup(GETMESSAGE(
  1886. "Usage: XtClass variable widget"));
  1887. printerr(str_nill, errmsg, NULL);
  1888. free(errmsg);
  1889. return(1);
  1890. }
  1891. w = str_to_wtab(argv[0], argv[2]);
  1892. if (w != NULL)
  1893. {
  1894. class = XtClass(w->w);
  1895. for (i = 0; C[i].cname; i++)
  1896. {
  1897. if (C[i].class == class)
  1898. {
  1899. alt_env_set_var(argv[1], C[i].cname);
  1900. return(0);
  1901. }
  1902. }
  1903. }
  1904. alt_env_set_var(argv[1], str_nill);
  1905. return(255);
  1906. }
  1907. #define PARSE_POINTLIST (-1)
  1908. #define PARSE_SEGMENTLIST (-2)
  1909. #define PARSE_AREA (-3)
  1910. GC Standard_GC;
  1911. int
  1912. create_standard_gc(
  1913. Display *display,
  1914. Window drawable )
  1915. {
  1916. Standard_GC = XCreateGC(display, drawable, 0, NULL);
  1917. return(0);
  1918. }
  1919. int
  1920. do_XBell(
  1921. int argc,
  1922. char *argv[] )
  1923. {
  1924. int volume;
  1925. Display * display;
  1926. char * p;
  1927. char * errmsg;
  1928. if (argc != 3)
  1929. {
  1930. errmsg=strdup(GETMESSAGE("Usage: XBell display volume"));
  1931. printerr(str_nill, errmsg, NULL);
  1932. free(errmsg);
  1933. return(1);
  1934. }
  1935. else
  1936. volume = atoi(argv[2]);
  1937. display = (Display *)strtoul(argv[1], &p, 0);
  1938. if (p == argv[1])
  1939. {
  1940. errmsg = strdup(GetSharedMsg(DT_BAD_DISPLAY));
  1941. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL, NULL,
  1942. NULL, NULL);
  1943. free(errmsg);
  1944. return(1);
  1945. }
  1946. if (volume < -100)
  1947. volume = -100;
  1948. else if (volume > 100)
  1949. volume = 100;
  1950. XBell(display, volume);
  1951. return(0);
  1952. }
  1953. static int
  1954. do_RootWindowCmd(
  1955. int (*func)(),
  1956. int argc,
  1957. char *argv[] )
  1958. {
  1959. Screen * screen;
  1960. char * p;
  1961. char buf[128];
  1962. char * errmsg;
  1963. if (argc != 3)
  1964. {
  1965. errmsg = strdup(GETMESSAGE("Usage: %s variable screen"));
  1966. printerrf(str_nill, errmsg, argv[0], NULL, NULL, NULL, NULL, NULL,
  1967. NULL, NULL);
  1968. free(errmsg);
  1969. return(1);
  1970. }
  1971. screen = (Screen *)strtoul(argv[2], &p, 0);
  1972. if (p == argv[2])
  1973. {
  1974. errmsg = strdup(GETMESSAGE("The screen parameter is invalid: %s"));
  1975. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  1976. NULL, NULL);
  1977. free(errmsg);
  1978. return(1);
  1979. }
  1980. sprintf(buf, "%ld", (long)(*func)(screen));
  1981. alt_env_set_var(argv[1], buf);
  1982. return(0);
  1983. }
  1984. int
  1985. do_XRootWindowOfScreen(
  1986. int argc,
  1987. char *argv[] )
  1988. {
  1989. return(do_RootWindowCmd((int (*)())XRootWindowOfScreen, argc, argv));
  1990. }
  1991. int
  1992. do_XWidthOfScreen(
  1993. int argc,
  1994. char *argv[] )
  1995. {
  1996. return(do_RootWindowCmd(XWidthOfScreen, argc, argv));
  1997. }
  1998. int
  1999. do_XHeightOfScreen(
  2000. int argc,
  2001. char *argv[] )
  2002. {
  2003. return(do_RootWindowCmd(XHeightOfScreen, argc, argv));
  2004. }
  2005. int
  2006. do_XDefineCursor(
  2007. int argc,
  2008. char *argv[] )
  2009. {
  2010. Cursor cursor;
  2011. Display * display;
  2012. Window window;
  2013. char * p;
  2014. char * errmsg;
  2015. if (argc != 4)
  2016. {
  2017. errmsg = strdup(GETMESSAGE(
  2018. "Usage: XDefineCursor display window cursorId"));
  2019. printerr(str_nill, errmsg, NULL);
  2020. free(errmsg);
  2021. return(1);
  2022. }
  2023. display = (Display *)strtoul(argv[1], &p, 0);
  2024. if (p == argv[1])
  2025. {
  2026. errmsg = strdup(GetSharedMsg(DT_BAD_DISPLAY));
  2027. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL, NULL,
  2028. NULL, NULL);
  2029. free(errmsg);
  2030. return(1);
  2031. }
  2032. window = (Window)strtoul(argv[2], &p, 0);
  2033. if (p == argv[2])
  2034. {
  2035. errmsg = strdup(GetSharedMsg(DT_BAD_WINDOW));
  2036. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  2037. NULL, NULL);
  2038. free(errmsg);
  2039. return(1);
  2040. }
  2041. cursor = (Cursor)strtoul(argv[3], &p, 0);
  2042. if (p == argv[3])
  2043. {
  2044. errmsg = strdup(GETMESSAGE(
  2045. "The cursorId parameter is invalid: %s"));
  2046. printerrf(argv[0], errmsg, argv[3], NULL, NULL, NULL, NULL, NULL,
  2047. NULL, NULL);
  2048. free(errmsg);
  2049. return(1);
  2050. }
  2051. XDefineCursor(display, window, cursor);
  2052. return(0);
  2053. }
  2054. int
  2055. do_XUndefineCursor(
  2056. int argc,
  2057. char *argv[] )
  2058. {
  2059. Display * display;
  2060. Window window;
  2061. char * p;
  2062. char * errmsg;
  2063. if (argc != 3)
  2064. {
  2065. errmsg = strdup(GETMESSAGE(
  2066. "Usage: XUndefineCursor display window"));
  2067. printerr(str_nill, errmsg, NULL);
  2068. free(errmsg);
  2069. return(1);
  2070. }
  2071. display = (Display *)strtoul(argv[1], &p, 0);
  2072. if (p == argv[1])
  2073. {
  2074. errmsg = strdup(GetSharedMsg(DT_BAD_DISPLAY));
  2075. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL, NULL,
  2076. NULL, NULL);
  2077. free(errmsg);
  2078. return(1);
  2079. }
  2080. window = (Window)strtoul(argv[2], &p, 0);
  2081. if (p == argv[2])
  2082. {
  2083. errmsg = strdup(GetSharedMsg(DT_BAD_WINDOW));
  2084. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  2085. NULL, NULL);
  2086. free(errmsg);
  2087. return(1);
  2088. }
  2089. XUndefineCursor(display, window);
  2090. return(0);
  2091. }
  2092. int
  2093. do_XtRemoveAllCallbacks(
  2094. int argc,
  2095. char *argv[] )
  2096. {
  2097. wtab_t *w;
  2098. int i;
  2099. char * errmsg;
  2100. if (argc != 3) {
  2101. errmsg = strdup(GETMESSAGE(
  2102. "Usage: XtRemoveAllCallbacks widget callbackName"));
  2103. printerr(str_nill, errmsg, NULL);
  2104. free(errmsg);
  2105. return(1);
  2106. }
  2107. w = str_to_wtab(argv[0], argv[1]);
  2108. if (w != NULL) {
  2109. XtRemoveAllCallbacks(w->w, argv[2]);
  2110. return(0);
  2111. } else
  2112. return(1);
  2113. }
  2114. static int
  2115. cvtfontstruct(
  2116. char *name,
  2117. XFontStruct **fn )
  2118. {
  2119. XrmValue fval, tval;
  2120. fval.addr = name;
  2121. fval.size = strlen(name);
  2122. XtConvert(Toplevel, XtRString, &fval, XtRFontStruct, &tval);
  2123. if (tval.size != 0) {
  2124. *fn = ((XFontStruct **)(tval.addr))[0];
  2125. return(SUCCESS);
  2126. } else
  2127. return(FAIL);
  2128. }
  2129. static int
  2130. CatchNonFatalFontError(
  2131. Display *display,
  2132. XErrorEvent *event )
  2133. {
  2134. invalidFont = True;
  2135. }
  2136. static int
  2137. cvtfont(
  2138. Display *display,
  2139. char *name,
  2140. Font *fn )
  2141. {
  2142. int (*oldHandler)();
  2143. invalidFont = False;
  2144. oldHandler = XSetErrorHandler(CatchNonFatalFontError);
  2145. *fn = XLoadFont(display, name);
  2146. XSync(display, False);
  2147. XSetErrorHandler(oldHandler);
  2148. if (!invalidFont)
  2149. return(SUCCESS);
  2150. else
  2151. return(FAIL);
  2152. }
  2153. static int
  2154. cvtcolor(
  2155. char *name,
  2156. Pixel *pix )
  2157. {
  2158. XrmValue fval, tval;
  2159. fval.addr = name;
  2160. fval.size = strlen(name);
  2161. XtConvert(Toplevel, XtRString, &fval, XtRPixel, &tval);
  2162. if (tval.size != 0) {
  2163. *pix = ((Pixel *)(tval.addr))[0];
  2164. return(SUCCESS);
  2165. } else
  2166. return(FAIL);
  2167. }
  2168. int
  2169. do_XTextWidth(
  2170. int argc,
  2171. char *argv[] )
  2172. {
  2173. XFontStruct *fn;
  2174. char *s;
  2175. char buf[128];
  2176. char * errmsg;
  2177. if (argc != 4)
  2178. {
  2179. errmsg = strdup(GETMESSAGE(
  2180. "Usage: XTextWidth variable fontName string"));
  2181. printerr(str_nill, errmsg, NULL);
  2182. free(errmsg);
  2183. return(1);
  2184. }
  2185. if (cvtfontstruct(argv[2], &fn) != SUCCESS)
  2186. {
  2187. errmsg = strdup(GetSharedMsg(DT_BAD_FONT));
  2188. printerrf(argv[0], errmsg, argv[2], NULL,
  2189. NULL, NULL, NULL, NULL, NULL, NULL);
  2190. free(errmsg);
  2191. return(1);
  2192. }
  2193. s = argv[3];
  2194. sprintf(buf, "%ld", (long)XTextWidth(fn, s, strlen(s)));
  2195. alt_env_set_var(argv[1], buf);
  2196. return(0);
  2197. }
  2198. #define MAXDRAWARGS 6
  2199. #define LINE_ARGS 1
  2200. #define POLYGON_ARGS 2
  2201. static int
  2202. invokeXDrawFunction(
  2203. int function,
  2204. int argc,
  2205. char *argv[] )
  2206. {
  2207. char * functionName = argv[0];
  2208. Display * display;
  2209. Window drawable;
  2210. Window destination = 0;
  2211. int srcX = 0, srcY = 0;
  2212. int destX = 0, destY = 0;
  2213. unsigned int width = 0, height = 0;
  2214. char *s;
  2215. char *sp;
  2216. int i;
  2217. int mode, parse = 0;
  2218. int text = FALSE;
  2219. int (*func)() = NULL;
  2220. int argtype = 0;
  2221. int polymode = 0;
  2222. int coordmode;
  2223. GC gc = NULL;
  2224. int p[MAXDRAWARGS];
  2225. int returnVal = 0;
  2226. Boolean unknownOption;
  2227. Boolean userSpecifiedGC = False;
  2228. char * errmsg;
  2229. if (argc < 3)
  2230. {
  2231. errmsg = strdup(GETMESSAGE(
  2232. "Usage: %s display drawable [args ...]"));
  2233. printerrf(str_nill, errmsg, functionName, NULL, NULL, NULL, NULL, NULL,
  2234. NULL, NULL);
  2235. free(errmsg);
  2236. return(1);
  2237. }
  2238. display = (Display *)strtoul(argv[1], &sp, 0);
  2239. if (sp == argv[1])
  2240. {
  2241. errmsg = strdup(GetSharedMsg(DT_BAD_DISPLAY));
  2242. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL, NULL,
  2243. NULL, NULL);
  2244. free(errmsg);
  2245. return(1);
  2246. }
  2247. drawable = (Window)strtoul(argv[2], &sp, 0);
  2248. if (sp == argv[2])
  2249. {
  2250. errmsg = strdup(GETMESSAGE(
  2251. "The drawable parameter is invalid: %s"));
  2252. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  2253. NULL, NULL);
  2254. free(errmsg);
  2255. return(1);
  2256. }
  2257. if (function == COPY_AREA)
  2258. {
  2259. parse = 0;
  2260. func = XCopyArea;
  2261. destination = (Window)strtoul(argv[3], &sp, 0);
  2262. if (sp == argv[3])
  2263. {
  2264. errmsg = strdup(GETMESSAGE(
  2265. "The destination parameter is invalid: %s"));
  2266. printerrf(argv[0], errmsg, argv[3], NULL, NULL, NULL, NULL, NULL,
  2267. NULL, NULL);
  2268. free(errmsg);
  2269. return(1);
  2270. }
  2271. srcX = atoi(argv[4]);
  2272. srcY = atoi(argv[5]);
  2273. width = atoi(argv[6]);
  2274. height = atoi(argv[7]);
  2275. destX = atoi(argv[8]);
  2276. destY = atoi(argv[9]);
  2277. argc -= 7;
  2278. argv += 7;
  2279. }
  2280. else if (function == DRAW_RECTANGLE)
  2281. {
  2282. parse = 4;
  2283. func = XDrawRectangle;
  2284. }
  2285. else if (function == FILL_RECTANGLE)
  2286. {
  2287. parse = 4;
  2288. func = XFillRectangle;
  2289. }
  2290. else if (function == FILL_POLYGON)
  2291. {
  2292. parse = PARSE_POINTLIST;
  2293. func = XFillPolygon;
  2294. argtype = POLYGON_ARGS;
  2295. polymode = Complex;
  2296. coordmode = CoordModeOrigin;
  2297. if (argc > 3)
  2298. {
  2299. while (argv[3][0] == '-')
  2300. {
  2301. if (strcmp(argv[3], "-Complex") == 0)
  2302. polymode = Complex;
  2303. else if (strcmp(argv[3], "-Convex") == 0)
  2304. polymode = Convex;
  2305. else if (strcmp(argv[3], "-Nonconvex") == 0)
  2306. polymode = Nonconvex;
  2307. else if (strcmp(argv[3], "-CoordModeOrigin") == 0)
  2308. coordmode = CoordModeOrigin;
  2309. else if (strcmp(argv[3], "-CoordModePrevious") == 0)
  2310. coordmode = CoordModePrevious;
  2311. else
  2312. break;
  2313. argc--;
  2314. argv++;
  2315. }
  2316. }
  2317. }
  2318. else if (function == DRAW_LINE)
  2319. {
  2320. parse = 4;
  2321. func = XDrawLine;
  2322. }
  2323. else if (function == DRAW_SEGMENTS)
  2324. {
  2325. parse = PARSE_SEGMENTLIST;
  2326. func = XDrawSegments;
  2327. }
  2328. else if (function == DRAW_LINES)
  2329. {
  2330. parse = PARSE_POINTLIST;
  2331. func = XDrawLines;
  2332. argtype = LINE_ARGS;
  2333. coordmode = CoordModeOrigin;
  2334. if (argc > 3)
  2335. {
  2336. while (argv[3][0] == '-')
  2337. {
  2338. if (strcmp(argv[3], "-CoordModeOrigin") == 0)
  2339. coordmode = CoordModeOrigin;
  2340. else if (strcmp(argv[3], "-CoordModePrevious") == 0)
  2341. coordmode = CoordModePrevious;
  2342. else
  2343. break;
  2344. argc--;
  2345. argv++;
  2346. }
  2347. }
  2348. }
  2349. else if (function == DRAW_STRING)
  2350. {
  2351. parse = 2;
  2352. text = TRUE;
  2353. func = XDrawString;
  2354. }
  2355. else if (function == DRAW_IMAGE_STRING)
  2356. {
  2357. parse = 2;
  2358. text = TRUE;
  2359. func = XDrawImageString;
  2360. }
  2361. else if (function == DRAW_ARC)
  2362. {
  2363. parse = 6;
  2364. func = XDrawArc;
  2365. }
  2366. else if (function == FILL_ARC)
  2367. {
  2368. parse = 6;
  2369. func = XFillArc;
  2370. }
  2371. else if (function == DRAW_POINT)
  2372. {
  2373. parse = 2;
  2374. func = XDrawPoint;
  2375. }
  2376. else if (function == DRAW_POINTS)
  2377. {
  2378. parse = PARSE_POINTLIST;
  2379. func = XDrawPoints;
  2380. argtype = LINE_ARGS;
  2381. coordmode = CoordModeOrigin;
  2382. if (argc > 3)
  2383. {
  2384. while (argv[3][0] == '-')
  2385. {
  2386. if (strcmp(argv[3], "-CoordModeOrigin") == 0)
  2387. coordmode = CoordModeOrigin;
  2388. else if (strcmp(argv[3], "-CoordModePrevious") == 0)
  2389. coordmode = CoordModePrevious;
  2390. else
  2391. break;
  2392. argc--;
  2393. argv++;
  2394. }
  2395. }
  2396. }
  2397. else if (function == CLEAR_WINDOW)
  2398. {
  2399. parse = 0;
  2400. func = XClearWindow;
  2401. }
  2402. else if (function == CLEAR_AREA)
  2403. {
  2404. parse = PARSE_AREA;
  2405. func = XClearArea;
  2406. }
  2407. if (Standard_GC == NULL)
  2408. create_standard_gc(display, drawable);
  2409. while (argc > 4 && argv[3][0] == '-')
  2410. {
  2411. if (gc == NULL)
  2412. gc = XCreateGC(display, drawable, 0, NULL);
  2413. if (strcmp(argv[3], "-gc") == 0)
  2414. {
  2415. XFreeGC(display, gc);
  2416. gc = (GC) atol(argv[4]);
  2417. userSpecifiedGC = True;
  2418. }
  2419. else if (strcmp(argv[3], "-foreground") == 0)
  2420. {
  2421. Pixel pix;
  2422. if (cvtcolor(argv[4], &pix) == SUCCESS)
  2423. XSetForeground(display, gc, pix);
  2424. }
  2425. else if (strcmp(argv[3], "-background") == 0)
  2426. {
  2427. Pixel pix;
  2428. if (cvtcolor(argv[4], &pix) == SUCCESS)
  2429. XSetBackground(display, gc, pix);
  2430. }
  2431. else if (strcmp(argv[3], "-font") == 0)
  2432. {
  2433. Font fn;
  2434. if (cvtfont(display, argv[4], &fn) == SUCCESS)
  2435. XSetFont(display, gc, fn);
  2436. else
  2437. {
  2438. errmsg = strdup(GetSharedMsg(DT_BAD_FONT));
  2439. printerrf(functionName, errmsg, argv[4], NULL, NULL, NULL,
  2440. NULL, NULL, NULL, NULL);
  2441. free(errmsg);
  2442. returnVal = 1;
  2443. }
  2444. }
  2445. else if (strcmp(argv[3], "-line_width") == 0)
  2446. {
  2447. XGCValues v;
  2448. v.line_width = atoi(argv[4]);
  2449. XChangeGC(display, gc, GCLineWidth, &v);
  2450. }
  2451. else if (strcmp(argv[3], "-function") == 0)
  2452. {
  2453. XGCValues v;
  2454. long f;
  2455. unknownOption = False;
  2456. if (strcmp(argv[4], "xor") == 0)
  2457. f = GXxor;
  2458. else if (strcmp(argv[4], "or") == 0)
  2459. f = GXor;
  2460. else if (strcmp(argv[4], "clear") == 0)
  2461. f = GXclear;
  2462. else if (strcmp(argv[4], "and") == 0)
  2463. f = GXand;
  2464. else if (strcmp(argv[4], "copy") == 0)
  2465. f = GXcopy;
  2466. else if (strcmp(argv[4], "noop") == 0)
  2467. f = GXnoop;
  2468. else if (strcmp(argv[4], "nor") == 0)
  2469. f = GXnor;
  2470. else if (strcmp(argv[4], "nand") == 0)
  2471. f = GXnand;
  2472. else if (strcmp(argv[4], "set") == 0)
  2473. f = GXset;
  2474. else if (strcmp(argv[4], "invert") == 0)
  2475. f = GXinvert;
  2476. else if (strcmp(argv[4], "equiv") == 0)
  2477. f = GXequiv;
  2478. else if (strcmp(argv[4], "andReverse") == 0)
  2479. f = GXandReverse;
  2480. else if (strcmp(argv[4], "orReverse") == 0)
  2481. f = GXorReverse;
  2482. else if (strcmp(argv[4], "copyInverted") == 0)
  2483. f = GXcopyInverted;
  2484. else
  2485. {
  2486. errmsg = strdup(GETMESSAGE(
  2487. "Unrecognized graphics function name: %s"));
  2488. printerrf(functionName, errmsg, argv[4],
  2489. NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  2490. free(errmsg);
  2491. returnVal = 1;
  2492. unknownOption = True;
  2493. }
  2494. if (!unknownOption)
  2495. {
  2496. v.function = f;
  2497. XChangeGC(display, gc, GCFunction, &v);
  2498. }
  2499. }
  2500. else if (strcmp(argv[3], "-line_style") == 0)
  2501. {
  2502. XGCValues v;
  2503. long f;
  2504. unknownOption = False;
  2505. if (strcmp(argv[4], "LineSolid") == 0)
  2506. f = LineSolid;
  2507. else if (strcmp(argv[4], "LineDoubleDash") == 0)
  2508. f = LineDoubleDash;
  2509. else if (strcmp(argv[4], "LineOnOffDash") == 0)
  2510. f = LineOnOffDash;
  2511. else {
  2512. errmsg = strdup(GETMESSAGE("Unrecognized line style: %s"));
  2513. printerrf(functionName, errmsg,
  2514. argv[4], NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  2515. free(errmsg);
  2516. returnVal = 1;
  2517. unknownOption = True;
  2518. }
  2519. if (!unknownOption)
  2520. {
  2521. v.line_style = f;
  2522. XChangeGC(display, gc, GCLineStyle, &v);
  2523. }
  2524. }
  2525. else
  2526. {
  2527. errmsg = strdup(GETMESSAGE("Unrecognized drawing option: %s"));
  2528. printerrf(functionName, errmsg, argv[3], NULL, NULL,
  2529. NULL, NULL, NULL, NULL, NULL);
  2530. free(errmsg);
  2531. returnVal = 1;
  2532. }
  2533. argv += 2;
  2534. argc -= 2;
  2535. }
  2536. if (gc == NULL)
  2537. gc = Standard_GC;
  2538. argc -= 3;
  2539. argv += 3;
  2540. if (parse == PARSE_POINTLIST)
  2541. {
  2542. XPoint *points = (XPoint *)malloc(sizeof(XPoint )*(argc/2+1));
  2543. int npoints = 0;
  2544. for (i = 0; i < argc-1; i += 2, npoints++)
  2545. {
  2546. points[npoints].x = atoi(argv[i]);
  2547. points[npoints].y = atoi(argv[i+1]);
  2548. }
  2549. switch (argtype)
  2550. {
  2551. case POLYGON_ARGS:
  2552. {
  2553. (*func)(display, drawable, gc, points, argc/2, polymode, coordmode);
  2554. break;
  2555. }
  2556. case LINE_ARGS:
  2557. {
  2558. (*func)(display, drawable, gc, points, argc/2, coordmode);
  2559. break;
  2560. }
  2561. }
  2562. free(points);
  2563. argc -= 2*npoints;
  2564. argv += 2*npoints;
  2565. }
  2566. else if (parse == PARSE_SEGMENTLIST)
  2567. {
  2568. XSegment *segments;
  2569. int nsegments = 0;
  2570. segments = (XSegment *)malloc(sizeof(XSegment )*(argc/4+1));
  2571. for (i = 0; i < argc-1; i += 4, nsegments++)
  2572. {
  2573. segments[nsegments].x1 = atoi(argv[i]);
  2574. segments[nsegments].y1 = atoi(argv[i+1]);
  2575. segments[nsegments].x2 = atoi(argv[i+2]);
  2576. segments[nsegments].y2 = atoi(argv[i+3]);
  2577. }
  2578. (*func)(display, drawable, gc, segments, argc/4);
  2579. free(segments);
  2580. argc -= 4*nsegments;
  2581. argv += 4*nsegments;
  2582. }
  2583. else if (parse == PARSE_AREA)
  2584. {
  2585. Boolean exposures = False;
  2586. XrmValue fval, tval;
  2587. for (i = 0; i < 4 && argc > 0; i++)
  2588. {
  2589. p[i] = atoi(argv[0]);
  2590. argc --;
  2591. argv ++;
  2592. }
  2593. if (argc > 0)
  2594. {
  2595. fval.addr = argv[0];
  2596. fval.size = strlen(argv[0]);
  2597. XtConvert(Toplevel, XtRString, &fval, XtRBoolean, &tval);
  2598. if (tval.size != 0)
  2599. exposures = *((Boolean *)(tval.addr));
  2600. argc --;
  2601. argv ++;
  2602. }
  2603. (*func)(display, drawable, p[0], p[1], p[2], p[3], exposures);
  2604. }
  2605. else
  2606. {
  2607. while (argc >= parse)
  2608. {
  2609. for (i = 0; i < parse && i < argc; i++)
  2610. p[i] = atoi(argv[i]);
  2611. if (text)
  2612. {
  2613. (*func)(display, drawable, gc,
  2614. p[0], p[1], argv[i], strlen(argv[i]));
  2615. argc--;
  2616. argv++;
  2617. }
  2618. else if (func == XClearWindow)
  2619. (*func)(display, drawable);
  2620. else if (func == XCopyArea)
  2621. {
  2622. (*func)(display, drawable, destination, gc,
  2623. srcX, srcY, width, height, destX, destY);
  2624. }
  2625. else
  2626. {
  2627. (*func)(display, drawable, gc,
  2628. p[0], p[1], p[2], p[3], p[4], p[5]);
  2629. }
  2630. argc -= parse;
  2631. argv += parse;
  2632. if (parse == 0)
  2633. break;
  2634. }
  2635. }
  2636. if ((gc != Standard_GC) && !userSpecifiedGC)
  2637. XFreeGC(display, gc);
  2638. if (argc != 0)
  2639. {
  2640. errmsg = strdup(GETMESSAGE(
  2641. "There were left over points which were ignored"));
  2642. printerr(functionName, errmsg, NULL);
  2643. free(errmsg);
  2644. returnVal = 1;
  2645. }
  2646. return(returnVal);
  2647. }
  2648. #undef LINE_ARGS
  2649. #undef POLYGON_ARGS
  2650. int
  2651. do_XDrawArc(
  2652. int argc,
  2653. char *argv[] )
  2654. {
  2655. invokeXDrawFunction(DRAW_ARC, argc, argv);
  2656. }
  2657. int
  2658. do_XDrawImageString(
  2659. int argc,
  2660. char *argv[] )
  2661. {
  2662. invokeXDrawFunction(DRAW_IMAGE_STRING, argc, argv);
  2663. }
  2664. int
  2665. do_XDrawLine(
  2666. int argc,
  2667. char *argv[] )
  2668. {
  2669. invokeXDrawFunction(DRAW_LINE, argc, argv);
  2670. }
  2671. int
  2672. do_XDrawLines(
  2673. int argc,
  2674. char *argv[] )
  2675. {
  2676. invokeXDrawFunction(DRAW_LINES, argc, argv);
  2677. }
  2678. int
  2679. do_XDrawPoint(
  2680. int argc,
  2681. char *argv[] )
  2682. {
  2683. invokeXDrawFunction(DRAW_POINT, argc, argv);
  2684. }
  2685. int
  2686. do_XDrawPoints(
  2687. int argc,
  2688. char *argv[] )
  2689. {
  2690. invokeXDrawFunction(DRAW_POINTS, argc, argv);
  2691. }
  2692. int
  2693. do_XDrawRectangle(
  2694. int argc,
  2695. char *argv[] )
  2696. {
  2697. invokeXDrawFunction(DRAW_RECTANGLE, argc, argv);
  2698. }
  2699. int
  2700. do_XCopyArea(
  2701. int argc,
  2702. char *argv[] )
  2703. {
  2704. char * errmsg;
  2705. if (argc < 10)
  2706. {
  2707. errmsg = strdup(GETMESSAGE(
  2708. "Usage: XCopyArea display source dest sourceX sourceY width height destX destY [args ...]"));
  2709. printerr(str_nill, errmsg, NULL);
  2710. free(errmsg);
  2711. return(1);
  2712. }
  2713. invokeXDrawFunction(COPY_AREA, argc, argv);
  2714. }
  2715. int
  2716. do_XDrawSegments(
  2717. int argc,
  2718. char *argv[] )
  2719. {
  2720. invokeXDrawFunction(DRAW_SEGMENTS, argc, argv);
  2721. }
  2722. int
  2723. do_XDrawString(
  2724. int argc,
  2725. char *argv[] )
  2726. {
  2727. invokeXDrawFunction(DRAW_STRING, argc, argv);
  2728. }
  2729. int
  2730. do_XFillArc(
  2731. int argc,
  2732. char *argv[] )
  2733. {
  2734. invokeXDrawFunction(FILL_ARC, argc, argv);
  2735. }
  2736. int
  2737. do_XFillPolygon(
  2738. int argc,
  2739. char *argv[] )
  2740. {
  2741. invokeXDrawFunction(FILL_POLYGON, argc, argv);
  2742. }
  2743. int
  2744. do_XFillRectangle(
  2745. int argc,
  2746. char *argv[] )
  2747. {
  2748. invokeXDrawFunction(FILL_RECTANGLE, argc, argv);
  2749. }
  2750. int
  2751. do_XClearArea(
  2752. int argc,
  2753. char *argv[] )
  2754. {
  2755. invokeXDrawFunction(CLEAR_AREA, argc, argv);
  2756. }
  2757. int
  2758. do_XClearWindow(
  2759. int argc,
  2760. char *argv[] )
  2761. {
  2762. invokeXDrawFunction(CLEAR_WINDOW, argc, argv);
  2763. }
  2764. int
  2765. ConvertTypeToString(
  2766. char *arg0,
  2767. classtab_t *class,
  2768. wtab_t *w,
  2769. wtab_t *parent,
  2770. char *resource,
  2771. XtArgVal val,
  2772. char **ret )
  2773. {
  2774. char *from_type;
  2775. XtResourceList res;
  2776. XrmValue fr_val, to_val;
  2777. char *nam;
  2778. char * errmsg;
  2779. if ((nam = hashget((Hash_table_t*)class->res, resource)) == NULL) {
  2780. /* If we didn't find it in this widget's class record,
  2781. * see if the parent is a constraint widget class, and
  2782. * if so then see if we can find the class there.
  2783. */
  2784. if (parent == NULL || parent->wclass == NULL ||
  2785. parent->wclass->con == NULL ||
  2786. (nam = hashget((Hash_table_t*)parent->wclass->con, resource))
  2787. == NULL)
  2788. {
  2789. errmsg = strdup(GetSharedMsg(DT_UNDEF_RESOURCE));
  2790. printerrf(arg0, errmsg,
  2791. (char *)(class->cname), resource, NULL, NULL,
  2792. NULL, NULL, NULL, NULL);
  2793. free(errmsg);
  2794. return(FAIL);
  2795. }
  2796. }
  2797. res = (XtResourceList)nam;
  2798. /*
  2799. * unfortunately, we have to have a special case for String
  2800. * type resources, since their size may vary.
  2801. */
  2802. if (strcmp(res->resource_type, str_XtRString) == 0) {
  2803. *ret = ((String *)val)[0];
  2804. return(0);
  2805. }
  2806. fr_val.size = res->resource_size;
  2807. fr_val.addr = (caddr_t)val;
  2808. to_val.size = 0;
  2809. to_val.addr = NULL;
  2810. XtConvert(
  2811. w ? w->w : Toplevel,
  2812. res->resource_type, /* from type */
  2813. &fr_val, /* from value */
  2814. str_XtRString, /* to type */
  2815. &to_val /* the converted value */
  2816. );
  2817. if ((to_val.addr) || (strcmp(res->resource_type, XmRXmString) == 0)) {
  2818. *ret = to_val.addr;
  2819. } else {
  2820. errmsg=strdup(GETMESSAGE(
  2821. "Unable to convert resource type '%s' to 'String'"));
  2822. printerrf(arg0, errmsg,
  2823. res->resource_type, NULL, NULL, NULL, NULL, NULL,
  2824. NULL, NULL);
  2825. free(errmsg);
  2826. return(FAIL);
  2827. }
  2828. return(SUCCESS);
  2829. }
  2830. wtab_t *DTKSHConversionWidget;
  2831. classtab_t *DTKSHConversionClass;
  2832. char *DTKSHConversionResource;
  2833. int
  2834. ConvertStringToType(
  2835. char *arg0,
  2836. wtab_t *w,
  2837. wtab_t *parent,
  2838. classtab_t *class,
  2839. char *resource,
  2840. char *val,
  2841. XtArgVal *ret,
  2842. int *freeit,
  2843. Boolean postponePixmaps )
  2844. {
  2845. char *to_type;
  2846. XtResourceList res;
  2847. XrmValue fr_val, to_val;
  2848. char *nam;
  2849. char * errmsg;
  2850. DTKSHConversionClass = class; /* needed by callback converter */
  2851. DTKSHConversionResource = resource; /* needed by callback converter */
  2852. DTKSHConversionWidget = w; /* needed by callback converter */
  2853. if ((nam = hashget((Hash_table_t*)class->res, resource)) == NULL) {
  2854. /* If we didn't find it in this widget's class record,
  2855. * see if the parent is a constraint widget class, and
  2856. * if so then see if we can find the class there.
  2857. */
  2858. if (parent == NULL || parent->wclass == NULL ||
  2859. parent->wclass->con == NULL ||
  2860. (nam = hashget((Hash_table_t*)parent->wclass->con,
  2861. resource)) == NULL)
  2862. {
  2863. errmsg = strdup(GetSharedMsg(DT_UNDEF_RESOURCE));
  2864. printerrf(arg0, errmsg,
  2865. (char *)(class->cname), resource, NULL,
  2866. NULL, NULL, NULL, NULL, NULL);
  2867. free(errmsg);
  2868. return(CONVERT_FAILED);
  2869. }
  2870. }
  2871. res = (XtResourceList)nam;
  2872. /*
  2873. * Unfortunately, because String types can be variable in size,
  2874. * we have to handle this as a special case.
  2875. */
  2876. if (strcmp(res->resource_type, str_XtRString) == 0) {
  2877. *ret = (XtArgVal)strdup(val);
  2878. *freeit = TRUE;
  2879. return(CONVERT_SUCCEEDED);
  2880. }
  2881. fr_val.size = strlen(val) + 1;
  2882. fr_val.addr = (caddr_t)val;
  2883. to_val.size = 0;
  2884. to_val.addr = NULL;
  2885. /*
  2886. * Hook to allow us to postpone processing of certain classes of
  2887. * resources. In particular, Dimension based resources can't be
  2888. * converted until the widget exists, nor can gadget pixmap resources.
  2889. * Any other pixmap resource needs to be postponed until after any
  2890. * color changes have taken effect, otherwise the string to pixmap
  2891. * converter uses the existing colors, instead of the new colors.
  2892. */
  2893. if (toolkit_special_resource(arg0, res, w, parent,
  2894. class, resource, val, ret,
  2895. freeit, postponePixmaps)) {
  2896. return(CONVERT_POSTPONED);
  2897. }
  2898. XtConvert(
  2899. w ? w->w : Toplevel,
  2900. str_XtRString, /* from type */
  2901. &fr_val, /* from value */
  2902. res->resource_type, /* to type */
  2903. &to_val /* the converted value */
  2904. );
  2905. if (to_val.size && to_val.addr) {
  2906. switch(to_val.size) {
  2907. case sizeof(char):
  2908. *ret = ((char *)to_val.addr)[0];
  2909. *freeit = FALSE;
  2910. break;
  2911. case sizeof(short):
  2912. *ret = (XtArgVal)((short *)to_val.addr)[0];
  2913. *freeit = FALSE;
  2914. break;
  2915. case sizeof(int):
  2916. *ret = (XtArgVal)((int *)to_val.addr)[0];
  2917. *freeit = FALSE;
  2918. break;
  2919. default:
  2920. /*
  2921. * Deal with sizeof(long) != sizeof(int) here.
  2922. * Bit of a cheat but it's a simple change.
  2923. */
  2924. if (to_val.size == sizeof(long)) {
  2925. *ret = (XtArgVal)((long *)to_val.addr)[0];
  2926. *freeit = FALSE;
  2927. break;
  2928. }
  2929. /*
  2930. * There is a possibility that some
  2931. * coverters will return malloc'ed space and this
  2932. * is really unnecessary and will leak memory. About
  2933. * the only way to handle this is to handle such types as
  2934. * special cases. Maybe we need a hash table that
  2935. * contains the names of types that need the malloc?
  2936. * The X specs should really have some mechanism for
  2937. * knowing when to free the results of a conversion.
  2938. */
  2939. *ret = (XtArgVal)XtMalloc(to_val.size);
  2940. memcpy((char *)ret, to_val.addr, to_val.size);
  2941. *freeit = TRUE;
  2942. }
  2943. } else {
  2944. errmsg=strdup(GETMESSAGE(
  2945. "Unable to convert resource type 'String' to type '%s'"));
  2946. printerrf(arg0, errmsg,
  2947. res->resource_type, NULL, NULL, NULL, NULL, NULL,
  2948. NULL, NULL);
  2949. free(errmsg);
  2950. return(CONVERT_FAILED);
  2951. }
  2952. return(CONVERT_SUCCEEDED);
  2953. }
  2954. static int
  2955. XtAddInputUsage(
  2956. char *arg0 )
  2957. {
  2958. char * errmsg;
  2959. errmsg=strdup(GETMESSAGE(
  2960. "Usage: XtAddInput variable [-r] fileDescriptor kshCommand"));
  2961. printerr(str_nill, errmsg, NULL);
  2962. free(errmsg);
  2963. return(1);
  2964. }
  2965. int
  2966. do_XtAddInput(
  2967. int argc,
  2968. char *argv[] )
  2969. {
  2970. int i, j;
  2971. int fd;
  2972. char *arg0 = argv[0];
  2973. char *variable;
  2974. char *cmd;
  2975. inputrec_t *inp;
  2976. XtInputId id;
  2977. char buf[256];
  2978. char * errmsg;
  2979. unsigned char modeFlags = LINE_INPUT_MODE;
  2980. if (argc < 4)
  2981. return(XtAddInputUsage(arg0));
  2982. variable = argv[1];
  2983. argv+=2;
  2984. argc-=2;
  2985. if (strcmp(argv[0], "-r") == 0)
  2986. {
  2987. /* Raw mode; the registered handler will take care of reading input */
  2988. modeFlags = RAW_INPUT_MODE;
  2989. argv++;
  2990. argc--;
  2991. }
  2992. if (argc != 2)
  2993. return(XtAddInputUsage(arg0));
  2994. fd = atoi(argv[0]);
  2995. argv++;
  2996. argc--;
  2997. inp = (inputrec_t *)XtMalloc(sizeof(inputrec_t));
  2998. if (modeFlags & RAW_INPUT_MODE)
  2999. {
  3000. /* Raw mode; the registered handler will do all buffering */
  3001. inp->lnbufsize = 0;
  3002. inp->lnbuf = NULL;
  3003. }
  3004. else
  3005. {
  3006. inp->lnbufsize = LINESIZE;
  3007. inp->lnbuf = XtMalloc(inp->lnbufsize);
  3008. }
  3009. inp->fd = fd;
  3010. inp->flags = modeFlags;
  3011. inp->lnend = 0;
  3012. inp->cmd = strdup(argv[0]);
  3013. inp->lastCharIsBackslash = False;
  3014. inp->lineWasTouched = False;
  3015. id = XtAddInput(fd, (XtPointer)XtInputReadMask,
  3016. (XtInputCallbackProc)stdInputCB, (caddr_t)inp);
  3017. /*
  3018. * Save a record of this input, so that we can destroy the buffer
  3019. * information when the input handler is unregistered.
  3020. */
  3021. for (i = 0; i < numActiveInputs; i++)
  3022. {
  3023. if (activeInputs[i].inUse == False)
  3024. break;
  3025. }
  3026. if ( i >= numActiveInputs)
  3027. {
  3028. /* Grow the array */
  3029. numActiveInputs += 5;
  3030. activeInputs = (InputRecord *)XtRealloc((char *)activeInputs,
  3031. sizeof(InputRecord) * numActiveInputs);
  3032. for (j = i; j < numActiveInputs; j++)
  3033. {
  3034. activeInputs[j].inUse = False;
  3035. activeInputs[j].inp = NULL;
  3036. activeInputs[j].id = 0;
  3037. }
  3038. }
  3039. activeInputs[i].inUse = True;
  3040. activeInputs[i].id = id;
  3041. activeInputs[i].inp = inp;
  3042. sprintf(buf, "0x%lx", (long)id);
  3043. alt_env_set_var(variable, buf);
  3044. return(0);
  3045. }
  3046. int
  3047. do_XtRemoveInput(
  3048. int argc,
  3049. char *argv[] )
  3050. {
  3051. XtInputId id;
  3052. char *p;
  3053. char * errmsg;
  3054. if (argc != 2)
  3055. {
  3056. errmsg = strdup(GETMESSAGE("Usage: XtRemoveInput inputId"));
  3057. printerr(str_nill, errmsg, NULL);
  3058. free(errmsg);
  3059. return(1);
  3060. }
  3061. id = strtoul(argv[1], &p, 16);
  3062. if (p == argv[1])
  3063. {
  3064. errmsg = strdup(GETMESSAGE(
  3065. "The inputId parameter must be a hex number: %s"));
  3066. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL,
  3067. NULL, NULL, NULL);
  3068. free(errmsg);
  3069. return(1);
  3070. }
  3071. DestroyInputRecord(id);
  3072. return(0);
  3073. }
  3074. /*
  3075. * This function will attempt to remove the indicated input source. If,
  3076. * however, the source is busy (i.e. the XtRemoveInput() request came
  3077. * from within the input handler), then we will simply mark the input
  3078. * source as 'pending destroy', and will allow stdInputCB to do the
  3079. * actual removing when it is safe.
  3080. */
  3081. static void
  3082. DestroyInputRecord(
  3083. XtInputId id )
  3084. {
  3085. inputrec_t * inp;
  3086. int entryIndex;
  3087. if ((entryIndex = FindInputRecord(id)) >= 0)
  3088. {
  3089. inp = activeInputs[entryIndex].inp;
  3090. if (inp->flags & INPUT_SOURCE_BUSY)
  3091. inp->flags |= INPUT_SOURCE_PENDING_DELETE;
  3092. else
  3093. {
  3094. /* It's ok to delete the source now */
  3095. XtRemoveInput(id);
  3096. activeInputs[entryIndex].inUse = False;
  3097. activeInputs[entryIndex].id = 0;
  3098. activeInputs[entryIndex].inp = NULL;
  3099. XtFree(inp->lnbuf);
  3100. XtFree((char *)inp);
  3101. }
  3102. }
  3103. }
  3104. static int
  3105. FindInputRecord(
  3106. XtInputId id )
  3107. {
  3108. int i;
  3109. for (i = 0; i < numActiveInputs; i++)
  3110. {
  3111. if ((activeInputs[i].inUse) && (activeInputs[i].id == id))
  3112. return(i);
  3113. }
  3114. return(-1);
  3115. }
  3116. /*
  3117. * This function will initialize some environment variables, and then
  3118. * invoke the handler registered for this input source. If will return
  3119. * 'True' if the handler called XtRemoveInput on this source; if this
  3120. * has happened, then the 'inp' structure MUST NOT be touched again,
  3121. * since it will have been freed up.
  3122. */
  3123. static Boolean
  3124. ProcessInput(
  3125. inputrec_t * inp,
  3126. int source,
  3127. XtInputId id,
  3128. Boolean eofFound )
  3129. {
  3130. Namval_t * sourceVar = nv_search("INPUT_SOURCE", sh.var_tree, NV_ADD);
  3131. Namval_t * idVar = nv_search("INPUT_ID", sh.var_tree, NV_ADD);
  3132. Namval_t * eofVar = nv_search("INPUT_EOF", sh.var_tree, NV_ADD);
  3133. Namval_t * lineVar = nv_search("INPUT_LINE", sh.var_tree, NV_ADD);
  3134. char strBuf[25];
  3135. /* Initialize the environment variables */
  3136. sprintf(strBuf, "%d", source);
  3137. nv_putval(sourceVar, strBuf, NV_RDONLY);
  3138. sprintf(strBuf, "0x%lx", (long)id);
  3139. nv_putval(idVar, strBuf, NV_RDONLY);
  3140. sprintf(strBuf, "%s", (eofFound ? "true" : "false"));
  3141. nv_putval(eofVar, strBuf, NV_RDONLY);
  3142. if ((inp->flags & RAW_INPUT_MODE) || (inp->lnend == 0))
  3143. {
  3144. strBuf[0] = '\0';
  3145. nv_putval(lineVar, strBuf, NV_RDONLY);
  3146. }
  3147. else
  3148. nv_putval(lineVar, inp->lnbuf, NV_RDONLY);
  3149. /* Invoke the registered handler */
  3150. inp->flags |= INPUT_SOURCE_BUSY;
  3151. ksh_eval(inp->cmd);
  3152. inp->flags &= ~INPUT_SOURCE_BUSY;
  3153. /* Clean up the environment variables */
  3154. nv_newattr(sourceVar, 0, 0);
  3155. nv_close(sourceVar);
  3156. nv_newattr(idVar, 0, 0);
  3157. nv_close(idVar);
  3158. nv_newattr(eofVar, 0, 0);
  3159. nv_close(eofVar);
  3160. nv_newattr(lineVar, 0, 0);
  3161. nv_close(lineVar);
  3162. /* If the handler removed the input source, then process it now */
  3163. if (inp->flags & INPUT_SOURCE_PENDING_DELETE)
  3164. {
  3165. DestroyInputRecord(id);
  3166. return(True);
  3167. }
  3168. return(False);
  3169. }
  3170. void
  3171. Translation_ksh_eval(
  3172. Widget w,
  3173. XEvent *event,
  3174. String *params,
  3175. Cardinal *num_params )
  3176. {
  3177. char buf[128];
  3178. int i;
  3179. Namval_t * np;
  3180. Namval_t * np2;
  3181. wtab_t *wtab = NULL;
  3182. Namfun_t * clonedDisc;
  3183. if (w != NULL)
  3184. wtab = widget_to_wtab(w);
  3185. nestingLevel++;
  3186. np2 = GetNameValuePair("TRANSLATION_WIDGET");
  3187. nv_newattr(np2, 0, 0);
  3188. nv_putval(np2, (wtab ? wtab->widid : "Unknown"), NV_RDONLY);
  3189. nv_newattr(np2, NV_RDONLY, 0);
  3190. np = GetNameValuePair("TRANSLATION_EVENT");
  3191. nv_newattr(np, 0, 0);
  3192. sprintf(buf, "0x%lx", (long)event);
  3193. nv_putval(np, buf, NV_RDONLY);
  3194. nv_newattr(np, NV_RDONLY, 0);
  3195. clonedDisc = CloneDiscipline(&transDiscipline);
  3196. nv_stack(np, clonedDisc);
  3197. for (i = 0; i < *num_params; i++)
  3198. ksh_eval(params[i]);
  3199. /* Remove the discipline for the hierarchical variables */
  3200. nv_stack(np, NULL);
  3201. FreeDiscipline(clonedDisc);
  3202. /* Free up all of the name/value pairs we created */
  3203. FreeNestedVariables();
  3204. nestingLevel--;
  3205. }
  3206. void
  3207. RestorePriorEnvVarValues(
  3208. Namval_t *np1,
  3209. char *value1,
  3210. Namval_t *np2,
  3211. char *value2 )
  3212. {
  3213. if (value1 && np1)
  3214. {
  3215. nv_newattr(np1, 0, 0);
  3216. nv_putval(np1, value1, NV_RDONLY);
  3217. nv_newattr(np1, NV_RDONLY, 0);
  3218. }
  3219. if (value2 && np2)
  3220. {
  3221. nv_newattr(np2, 0, 0);
  3222. nv_putval(np2, value2, NV_RDONLY);
  3223. nv_newattr(np2, NV_RDONLY, 0);
  3224. }
  3225. }
  3226. /*
  3227. * stdCB() is the central routine from which all callback
  3228. * functions are dispatched (specified by clientData). The
  3229. * variables "CB_WIDGET" and "CB_CALL_DATA" will be placed in
  3230. * the environment to represent the CallBackWidget handle.
  3231. */
  3232. void
  3233. stdCB(
  3234. void *widget,
  3235. caddr_t clientData,
  3236. caddr_t callData )
  3237. {
  3238. char buf[128];
  3239. dtksh_client_data_t *cdata = (dtksh_client_data_t *)clientData;
  3240. Namval_t * np;
  3241. Namval_t * np2;
  3242. WidgetClass class;
  3243. Namdisc_t * discipline = NULL;
  3244. int i;
  3245. char * oldCB_WIDGET_value = NULL;
  3246. char * oldCB_CALL_DATA_value = NULL;
  3247. char * ptr;
  3248. Namfun_t * clonedDisc;
  3249. /*
  3250. * The wtab_t entry of the cdata need not be filled in since
  3251. * it could have been set via direct resource setting at widget
  3252. * creation time, and the converter for string to callback would
  3253. * not have had access to this information (since the widget
  3254. * was not created yet.
  3255. * Thus, we set it here. Note that this will happen at most
  3256. * one time, since we are modifying the cdata structure.
  3257. */
  3258. if (cdata->w == NULL)
  3259. cdata->w = widget_to_wtab(widget);
  3260. nestingLevel++;
  3261. np2 = GetNameValuePair("CB_WIDGET");
  3262. nv_newattr(np2, 0, 0);
  3263. if (ptr = nv_getval(np2))
  3264. oldCB_WIDGET_value = strdup(ptr);
  3265. nv_putval(np2, (cdata->w ? cdata->w->widid : "Unknown"), NV_RDONLY);
  3266. nv_newattr(np2, NV_RDONLY, 0);
  3267. /* Certain callbacks don't pass structures as the calldata */
  3268. if ((cdata->cbname) &&
  3269. ((strcmp(cdata->cbname, XmNpopupCallback) == 0) ||
  3270. (strcmp(cdata->cbname, XmNpopdownCallback) == 0)))
  3271. {
  3272. /* The calldata indicates the grab type */
  3273. XtGrabKind * grabKind = (XtGrabKind *)callData;
  3274. switch (*grabKind)
  3275. {
  3276. case XtGrabNonexclusive:
  3277. {
  3278. strcpy(buf, "GrabNonexclusive");
  3279. break;
  3280. }
  3281. case XtGrabExclusive:
  3282. {
  3283. strcpy(buf, "GrabExclusive");
  3284. break;
  3285. }
  3286. default:
  3287. {
  3288. strcpy(buf, "GrabNone");
  3289. break;
  3290. }
  3291. }
  3292. }
  3293. else
  3294. sprintf(buf, "0x%lx", (long)callData);
  3295. np = GetNameValuePair("CB_CALL_DATA");
  3296. nv_newattr(np, 0, 0);
  3297. if (ptr = nv_getval(np))
  3298. oldCB_CALL_DATA_value = strdup(ptr);
  3299. nv_putval(np, buf, NV_RDONLY);
  3300. nv_newattr(np, NV_RDONLY, 0);
  3301. /*
  3302. * Add a discipline for hierarchical variables.
  3303. * Need to add a different discipline, based on the callback type,
  3304. * since the fields within the callback structure differ depending
  3305. * upon the type of callback and the widget. NOTE: the WMProtocol
  3306. * callback will use the default discipline.
  3307. */
  3308. if (cdata->cbname)
  3309. {
  3310. if ((strcmp(cdata->cbname, XmNpopupCallback) == 0) ||
  3311. (strcmp(cdata->cbname, XmNpopdownCallback) == 0) ||
  3312. (strcmp(cdata->cbname, XmNdestroyCallback) == 0))
  3313. {
  3314. discipline = &nopDiscipline;
  3315. }
  3316. else if (strcmp(cdata->cbname, XmNhelpCallback) == 0)
  3317. discipline = &dftDiscipline;
  3318. else
  3319. {
  3320. class = XtClass(cdata->w->w);
  3321. while (class)
  3322. {
  3323. if (discipline = CheckClassDisciplines(class, cdata->cbname))
  3324. break;
  3325. class = class->core_class.superclass;
  3326. }
  3327. }
  3328. }
  3329. /*
  3330. * If a discipline was found, then use it; otherwise, we MUST set up
  3331. * a default discipline; otherwise, any hierarchical variables
  3332. * referenced by the user are not under our control, thus never getting
  3333. * freed up, and then also preventing future disciplines from getting
  3334. * called when they should have.
  3335. */
  3336. if (discipline)
  3337. clonedDisc = CloneDiscipline(discipline);
  3338. else
  3339. clonedDisc = CloneDiscipline(&dftDiscipline);
  3340. nv_stack(np, clonedDisc);
  3341. ksh_eval((char *)cdata->ksh_cmd);
  3342. /* We may be nested, so restore old CB_WIDGET & CB_CALL_DATA values */
  3343. RestorePriorEnvVarValues(np2, oldCB_WIDGET_value, np, oldCB_CALL_DATA_value);
  3344. XtFree(oldCB_WIDGET_value);
  3345. XtFree(oldCB_CALL_DATA_value);
  3346. /* Remove the discipline for the hierarchical variables */
  3347. nv_stack(np, NULL);
  3348. FreeDiscipline(clonedDisc);
  3349. /* Free up all of the name/value pairs we created */
  3350. FreeNestedVariables();
  3351. nestingLevel--;
  3352. return;
  3353. }
  3354. /*
  3355. * This is the callback handler for the 'workspace changed' callback.
  3356. */
  3357. void
  3358. stdWSCB(
  3359. void *widget,
  3360. Atom atom,
  3361. caddr_t clientData )
  3362. {
  3363. char buf[128];
  3364. dtksh_client_data_t *cdata = (dtksh_client_data_t *)clientData;
  3365. Namval_t * np;
  3366. Namval_t * np2;
  3367. int i;
  3368. char * oldCB_WIDGET_value = NULL;
  3369. char * oldCB_CALL_DATA_value = NULL;
  3370. char * ptr;
  3371. Namfun_t * clonedDisc;
  3372. nestingLevel++;
  3373. np2 = GetNameValuePair("CB_WIDGET");
  3374. nv_newattr(np2, 0, 0);
  3375. if (ptr = nv_getval(np2))
  3376. oldCB_WIDGET_value = strdup(ptr);
  3377. nv_putval(np2, cdata->w->widid, NV_RDONLY);
  3378. nv_newattr(np2, NV_RDONLY, 0);
  3379. np = GetNameValuePair("CB_CALL_DATA");
  3380. nv_newattr(np, 0, 0);
  3381. sprintf(buf, "0x%lx", (long)atom);
  3382. if (ptr = nv_getval(np))
  3383. oldCB_CALL_DATA_value = strdup(ptr);
  3384. nv_putval(np, buf, NV_RDONLY);
  3385. nv_newattr(np, NV_RDONLY, 0);
  3386. clonedDisc = CloneDiscipline(&nopDiscipline);
  3387. nv_stack(np, clonedDisc);
  3388. ksh_eval((char *)cdata->ksh_cmd);
  3389. /* We may be nested, so restore old CB_WIDGET & CB_CALL_DATA values */
  3390. RestorePriorEnvVarValues(np2, oldCB_WIDGET_value, np, oldCB_CALL_DATA_value);
  3391. XtFree(oldCB_WIDGET_value);
  3392. XtFree(oldCB_CALL_DATA_value);
  3393. /* Remove the discipline for the hierarchical variables */
  3394. nv_stack(np, NULL);
  3395. FreeDiscipline(clonedDisc);
  3396. /* Free up all of the name/value pairs we created */
  3397. FreeNestedVariables();
  3398. nestingLevel--;
  3399. }
  3400. void
  3401. stdInputCB(
  3402. inputrec_t *inp,
  3403. int *source,
  3404. XtInputId *id )
  3405. {
  3406. char buf[LINESIZE];
  3407. char cmdbuf[LINESIZE];
  3408. int cmd;
  3409. char *p;
  3410. int i, n, j;
  3411. char * errmsg;
  3412. int len;
  3413. /* If in 'raw' mode, then simply let the handler do all the work */
  3414. if (inp->flags & RAW_INPUT_MODE)
  3415. {
  3416. ProcessInput(inp, *source, *id, False);
  3417. return;
  3418. }
  3419. /* try to read some input from the fd */
  3420. if ((n = read(inp->fd, buf, sizeof(buf)-1)) <= 0)
  3421. {
  3422. /* EOF; notify handler, passing in any remaining buffered data */
  3423. if ((inp->lnend > 0) || (inp->lineWasTouched))
  3424. {
  3425. /* Force one call with the data, and a 2nd with the EOF */
  3426. inp->lnbuf[inp->lnend] = '\0';
  3427. ProcessInput(inp, *source, *id, False);
  3428. }
  3429. inp->lastCharIsBackslash = False;
  3430. inp->lineWasTouched = False;
  3431. inp->lnbuf[0] = '\0';
  3432. inp->lnend = 0;
  3433. ProcessInput(inp, *source, *id, True);
  3434. return;
  3435. }
  3436. /*
  3437. * Go through appending to current line, execute line if you
  3438. * get an unquoted newline. Strip off the newline, so that
  3439. * we are consistent with the ksh 'read' command, remove
  3440. * escaped newlines, and do backslash processing.
  3441. */
  3442. for (i = 0; i < n; )
  3443. {
  3444. #ifdef NLS16
  3445. len = mblen(buf+i, MB_CUR_MAX);
  3446. #else
  3447. len = 1;
  3448. #endif
  3449. inp->lineWasTouched = True;
  3450. if ((inp->lnend + len) >= (inp->lnbufsize-1))
  3451. {
  3452. /* Grow the input buffer */
  3453. inp->lnbufsize += (n + LINESIZE + 5);
  3454. inp->lnbuf = XtRealloc(inp->lnbuf, inp->lnbufsize);
  3455. }
  3456. /* Perform backslash processing */
  3457. if ((len == 1) && (buf[i] == '\\') && (!inp->lastCharIsBackslash))
  3458. {
  3459. /* Skip this character; the next character will be treated specially */
  3460. inp->lastCharIsBackslash = True;
  3461. i++;
  3462. continue;
  3463. }
  3464. /*
  3465. * If the previous character has been a backslash, then the current
  3466. * character gets placed into the buffer without any special
  3467. * processing; the exception is the newline character, which gets
  3468. * dumped.
  3469. */
  3470. if ((len == 1) && (buf[i] == '\n'))
  3471. {
  3472. /*
  3473. * If the newline is escaped, then drop it, and continue.
  3474. * Otherwise, process the line.
  3475. */
  3476. i++;
  3477. if (inp->lastCharIsBackslash)
  3478. {
  3479. inp->lastCharIsBackslash = False;
  3480. continue;
  3481. }
  3482. inp->lnbuf[inp->lnend] = '\0';
  3483. if (ProcessInput(inp, *source, *id, False))
  3484. {
  3485. /* The handler called XtRemoveInput() on this source; abort */
  3486. return;
  3487. }
  3488. inp->lnend = 0;
  3489. inp->lineWasTouched = False;
  3490. }
  3491. else
  3492. {
  3493. /* Simply copy the next character into the buffer */
  3494. inp->lastCharIsBackslash = False;
  3495. for (j = 0; j < len; j++)
  3496. inp->lnbuf[inp->lnend++] = buf[i++];
  3497. }
  3498. }
  3499. }
  3500. int
  3501. stdWorkProcCB(
  3502. char *clientData )
  3503. {
  3504. int retcode;
  3505. int i;
  3506. retcode = ksh_eval((char *)clientData);
  3507. if (retcode != 0)
  3508. {
  3509. /* This is tricky, because we do not have the workproc id */
  3510. for (i = 0; i < workProcCmdsSize; i++)
  3511. {
  3512. if (clientData == workProcCmds[i].cmd)
  3513. {
  3514. RemoveCmdStr(WORKPROC_CMDS, (long)workProcCmds[i].id);
  3515. break;
  3516. }
  3517. }
  3518. }
  3519. return(retcode);
  3520. }
  3521. void
  3522. stdTimerCB(
  3523. char *clientData,
  3524. long *id )
  3525. {
  3526. ksh_eval((char *)clientData);
  3527. RemoveCmdStr(TIMEOUT_CMDS, (long)*id);
  3528. return;
  3529. }
  3530. int
  3531. do_XFlush(
  3532. int argc,
  3533. char *argv[] )
  3534. {
  3535. char *p;
  3536. Display * display;
  3537. char * errmsg;
  3538. if (argc != 2)
  3539. {
  3540. errmsg = strdup(GETMESSAGE("Usage: XFlush display"));
  3541. printerr(str_nill, errmsg, NULL);
  3542. free(errmsg);
  3543. return(1);
  3544. }
  3545. display = (Display *)strtoul(argv[1], &p, 0);
  3546. if (p == argv[1])
  3547. {
  3548. errmsg = strdup(GetSharedMsg(DT_BAD_DISPLAY));
  3549. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL, NULL,
  3550. NULL, NULL);
  3551. free(errmsg);
  3552. return(1);
  3553. }
  3554. XFlush(display);
  3555. return(0);
  3556. }
  3557. int
  3558. do_XSync(
  3559. int argc,
  3560. char *argv[] )
  3561. {
  3562. Boolean discard;
  3563. XrmValue fval, tval;
  3564. char *p;
  3565. Display * display;
  3566. char * errmsg;
  3567. if (argc != 3)
  3568. {
  3569. errmsg = strdup(GETMESSAGE("Usage: XSync display discard"));
  3570. printerr(str_nill, errmsg, NULL);
  3571. free(errmsg);
  3572. return(1);
  3573. }
  3574. display = (Display *)strtoul(argv[1], &p, 0);
  3575. if (p == argv[1])
  3576. {
  3577. errmsg = strdup(GetSharedMsg(DT_BAD_DISPLAY));
  3578. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL, NULL,
  3579. NULL, NULL);
  3580. free(errmsg);
  3581. return(1);
  3582. }
  3583. fval.addr = argv[2];
  3584. fval.size = strlen(argv[2]);
  3585. XtConvert(Toplevel, XtRString, &fval, XtRBoolean, &tval);
  3586. if (tval.size != 0)
  3587. discard = *((Boolean *)(tval.addr));
  3588. else
  3589. return(1);
  3590. XSync(display, discard);
  3591. return(0);
  3592. }
  3593. int
  3594. do_XRaiseWindow(
  3595. int argc,
  3596. char *argv[] )
  3597. {
  3598. Boolean discard;
  3599. XrmValue fval, tval;
  3600. wtab_t *w;
  3601. char *p;
  3602. Display * display;
  3603. Window window;
  3604. char * errmsg;
  3605. if (argc != 3)
  3606. {
  3607. errmsg = strdup(GETMESSAGE("Usage: XRaiseWindow display window"));
  3608. printerr(str_nill, errmsg, NULL);
  3609. free(errmsg);
  3610. return(1);
  3611. }
  3612. display = (Display *)strtoul(argv[1], &p, 0);
  3613. if (p == argv[1])
  3614. {
  3615. errmsg = strdup(GetSharedMsg(DT_BAD_DISPLAY));
  3616. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL, NULL,
  3617. NULL, NULL);
  3618. free(errmsg);
  3619. return(1);
  3620. }
  3621. window = (Window)strtoul(argv[2], &p, 0);
  3622. if (p == argv[2])
  3623. {
  3624. errmsg = strdup(GetSharedMsg(DT_BAD_WINDOW));
  3625. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  3626. NULL, NULL);
  3627. free(errmsg);
  3628. return(1);
  3629. }
  3630. XRaiseWindow(display, window);
  3631. return(0);
  3632. }
  3633. static int
  3634. XtSetSensitive_usage(
  3635. char *arg0 )
  3636. {
  3637. char * errmsg;
  3638. errmsg = strdup(GETMESSAGE("Usage: %s widget [True|False]"));
  3639. printerrf(str_nill, errmsg, arg0, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  3640. free(errmsg);
  3641. return(1);
  3642. }
  3643. int
  3644. do_XtSetSensitive(
  3645. int argc,
  3646. char *argv[] )
  3647. {
  3648. wtab_t *w;
  3649. Boolean boolean;
  3650. XrmValue fval, tval;
  3651. if (argc != 3)
  3652. return(XtSetSensitive_usage(argv[0]));
  3653. fval.addr = argv[2];
  3654. fval.size = strlen(argv[2]);
  3655. XtConvert(Toplevel, XtRString, &fval, XtRBoolean, &tval);
  3656. if (tval.size != 0)
  3657. boolean = *((Boolean *)(tval.addr));
  3658. else
  3659. return(1);
  3660. w = str_to_wtab(argv[0], argv[1]);
  3661. if (w != NULL)
  3662. XtSetSensitive(w->w, boolean);
  3663. else
  3664. return(1);
  3665. return(0);
  3666. }
  3667. static int
  3668. RegisterTranslations(
  3669. void (*func)(),
  3670. int argc,
  3671. char *argv[] )
  3672. {
  3673. wtab_t *w;
  3674. XtTranslations translationTable;
  3675. XrmValue fval, tval;
  3676. char * errmsg;
  3677. if (argc != 3)
  3678. {
  3679. errmsg = strdup(GETMESSAGE("Usage: %s widget translations"));
  3680. printerrf(str_nill, errmsg, argv[0], NULL, NULL,
  3681. NULL, NULL, NULL, NULL, NULL);
  3682. free(errmsg);
  3683. return(1);
  3684. }
  3685. w = str_to_wtab(argv[0], argv[1]);
  3686. if (w == NULL)
  3687. return(1);
  3688. fval.addr = argv[2];
  3689. fval.size = strlen(argv[2]);
  3690. XtConvert(Toplevel, XtRString, &fval, XtRTranslationTable, &tval);
  3691. if (tval.size != 0)
  3692. translationTable = *((XtTranslations *)(tval.addr));
  3693. else
  3694. return(1);
  3695. (*func)(w->w, translationTable);
  3696. return(0);
  3697. }
  3698. int
  3699. do_XtOverrideTranslations(
  3700. int argc,
  3701. char **argv )
  3702. {
  3703. return(RegisterTranslations(XtOverrideTranslations, argc, argv));
  3704. }
  3705. int
  3706. do_XtAugmentTranslations(
  3707. int argc,
  3708. char **argv )
  3709. {
  3710. return(RegisterTranslations(XtAugmentTranslations, argc, argv));
  3711. }
  3712. int
  3713. do_XtUninstallTranslations(
  3714. int argc,
  3715. char *argv[] )
  3716. {
  3717. wtab_t *w;
  3718. XtTranslations * translationTable;
  3719. XrmValue fval, tval;
  3720. char * errmsg;
  3721. if (argc != 2)
  3722. {
  3723. errmsg = strdup(GETMESSAGE(
  3724. "Usage: XtUninstallTranslations widget"));
  3725. printerr(str_nill, errmsg, NULL);
  3726. free(errmsg);
  3727. return(1);
  3728. }
  3729. w = str_to_wtab(argv[0], argv[1]);
  3730. if (w == NULL)
  3731. return(1);
  3732. XtUninstallTranslations(w->w);
  3733. return(0);
  3734. }
  3735. int
  3736. do_XtParent(
  3737. int argc,
  3738. char **argv )
  3739. {
  3740. char *arg0 = argv[0];
  3741. char * wname;
  3742. wtab_t *wtab;
  3743. classtab_t *ctab;
  3744. char buf[128];
  3745. char * errmsg;
  3746. if (argc != 3 ) {
  3747. errmsg = strdup(GETMESSAGE("Usage: XtParent variable widget"));
  3748. printerr(str_nill, errmsg, NULL);
  3749. free(errmsg);
  3750. return(1);
  3751. }
  3752. wname = argv[2];
  3753. wtab = str_to_wtab(arg0, wname);
  3754. if (wtab == NULL) {
  3755. return(1);
  3756. }
  3757. if (wtab->parent == NULL) {
  3758. wtab = widget_to_wtab(XtParent(wtab->w));
  3759. if (wtab == NULL)
  3760. return(1);
  3761. /*
  3762. * If the widget class has no resources registered, then this is
  3763. * the first known instance of this widget class, so we need to
  3764. * force the resource list to be loaded. This can frequently
  3765. * occur if a Motif convenience function is used, which creates
  3766. * a 'hidden' parent.
  3767. */
  3768. ctab = wtab->wclass;
  3769. if (ctab->res == NULL)
  3770. (void)str_to_class(arg0, ctab->cname);
  3771. } else
  3772. wtab = wtab->parent;
  3773. sprintf(buf, "%s", wtab->widid);
  3774. alt_env_set_var(argv[1], buf);
  3775. return(0);
  3776. }
  3777. int
  3778. do_XtLastTimestampProcessed(
  3779. int argc,
  3780. char **argv )
  3781. {
  3782. char *arg0 = argv[0];
  3783. Display * display;
  3784. char * p;
  3785. char buf[128];
  3786. char * errmsg;
  3787. if (argc != 3 ) {
  3788. errmsg = strdup(GETMESSAGE(
  3789. "Usage: XtLastTimestampProcessed variable display"));
  3790. printerr(str_nill, errmsg, NULL);
  3791. free(errmsg);
  3792. return(1);
  3793. }
  3794. display = (Display *)strtoul(argv[2], &p, 0);
  3795. if (p == argv[2])
  3796. {
  3797. errmsg = strdup(GetSharedMsg(DT_BAD_DISPLAY));
  3798. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  3799. NULL, NULL);
  3800. free(errmsg);
  3801. return(1);
  3802. }
  3803. sprintf(buf, "%ld", (long)XtLastTimestampProcessed(display));
  3804. alt_env_set_var(argv[1], buf);
  3805. return(0);
  3806. }
  3807. /**********************************************/
  3808. /*
  3809. * The following two functions work for both standard Xt callbacks
  3810. * (which are identified by a callback name) and WM protocol callbacks
  3811. * (which are identified by a property atom). That is why both of
  3812. * these parameters are passed in. It is usually the case that only
  3813. * one of the 'cbname' and 'propAtom' parameters are used; the unused
  3814. * one should be set to NULL (cbname) or None (propAtom).
  3815. */
  3816. dtksh_client_data_t *
  3817. GetNewCBData(
  3818. char *ksh_cmd,
  3819. wtab_t *w,
  3820. char *cbname,
  3821. Atom propAtom )
  3822. {
  3823. dtksh_client_data_t * cdata;
  3824. int i;
  3825. int j;
  3826. /* Can we reuse an existing entry? */
  3827. if ((i = LocateCBRecord (w, cbname, ksh_cmd, propAtom, NULL)) >= 0)
  3828. {
  3829. cdata = cbDataTable[i];
  3830. cdata->refCount++;
  3831. return(cdata);
  3832. }
  3833. /* Look for an open slot */
  3834. for (i = 0; i < cbDataTableSize; i++)
  3835. {
  3836. if (cbDataTable[i] == NULL)
  3837. break;
  3838. }
  3839. if (i >= cbDataTableSize)
  3840. {
  3841. /* Need to enlarge the table */
  3842. cbDataTableSize += 10;
  3843. cbDataTable = (dtksh_client_data_t **)
  3844. XtRealloc((XtPointer)cbDataTable,
  3845. sizeof(dtksh_client_data_t *) * cbDataTableSize);
  3846. for (j = i; j < cbDataTableSize; j++)
  3847. cbDataTable[j] = NULL;
  3848. }
  3849. cdata = (dtksh_client_data_t *)XtMalloc(sizeof(dtksh_client_data_t));
  3850. if (ksh_cmd)
  3851. cdata->ksh_cmd = strdup(ksh_cmd);
  3852. else
  3853. cdata->ksh_cmd = NULL;
  3854. cdata->w = w;
  3855. if (cbname)
  3856. cdata->cbname = strdup(cbname);
  3857. else
  3858. cdata->cbname = NULL;
  3859. cdata->propAtom = propAtom;
  3860. cdata->handle = NULL;
  3861. cdata->refCount = 1;
  3862. cbDataTable[i] = cdata;
  3863. return(cdata);
  3864. }
  3865. int
  3866. LocateCBRecord(
  3867. wtab_t *w,
  3868. char *cbname,
  3869. char *ksh_cmd,
  3870. Atom propAtom,
  3871. DtWsmCBContext handle )
  3872. {
  3873. int i;
  3874. /* Locate the matching table entry */
  3875. for (i = 0; i < cbDataTableSize; i++)
  3876. {
  3877. if (cbDataTable[i])
  3878. {
  3879. if ((((cbname == NULL) && (cbDataTable[i]->cbname == NULL)) ||
  3880. (((cbname != NULL) && (cbDataTable[i]->cbname != NULL)) &&
  3881. (strcmp(cbDataTable[i]->cbname, cbname) == 0))) &&
  3882. (cbDataTable[i]->w == w) &&
  3883. (strcmp(cbDataTable[i]->ksh_cmd, ksh_cmd) == 0) &&
  3884. (cbDataTable[i]->propAtom == propAtom) &&
  3885. (cbDataTable[i]->handle == (XtPointer)handle))
  3886. {
  3887. return(i);
  3888. }
  3889. }
  3890. }
  3891. return(-1);
  3892. }
  3893. /**********************************************/
  3894. void
  3895. stdEH(
  3896. void *widget,
  3897. caddr_t clientData,
  3898. XEvent *event,
  3899. Boolean *continueToDispatch )
  3900. {
  3901. char buf[128];
  3902. dtksh_event_handler_data_t *ehdata;
  3903. int i;
  3904. Namval_t * np;
  3905. Namval_t * np2;
  3906. Namfun_t * clonedDisc;
  3907. ehdata = (dtksh_event_handler_data_t *)clientData;
  3908. nestingLevel++;
  3909. np2 = GetNameValuePair("EH_WIDGET");
  3910. nv_newattr(np2, 0, 0);
  3911. nv_putval(np2, ehdata->w->widid, NV_RDONLY);
  3912. nv_newattr(np2, NV_RDONLY, 0);
  3913. np = GetNameValuePair("EH_EVENT");
  3914. nv_newattr(np, 0, 0);
  3915. sprintf(buf, "0x%lx", (long)event);
  3916. nv_putval(np, buf, NV_RDONLY);
  3917. clonedDisc = CloneDiscipline(&ehDiscipline);
  3918. nv_stack(np, clonedDisc);
  3919. ksh_eval((char *)ehdata->ksh_cmd);
  3920. /* Remove the discipline for the hierarchical variables */
  3921. nv_stack(np, NULL);
  3922. FreeDiscipline(clonedDisc);
  3923. /* Free up all of the name/value pairs we created */
  3924. FreeNestedVariables();
  3925. nestingLevel--;
  3926. }
  3927. /*
  3928. * For a given widget, if the ksh-cmd is the same as one already
  3929. * registered for this widget, then we will merge them into a
  3930. * single event handler (by merging the event masks), as is done
  3931. * by Xt anyways.
  3932. */
  3933. dtksh_event_handler_data_t *
  3934. GetNewEHData(
  3935. char *ksh_cmd,
  3936. wtab_t *w,
  3937. EventMask eventMask,
  3938. Boolean nonMaskable )
  3939. {
  3940. dtksh_event_handler_data_t * ehdata;
  3941. int i;
  3942. int j;
  3943. /* Can we merge with an existing entry? */
  3944. if ((i = LocateEHRecord (w, ksh_cmd)) >= 0)
  3945. {
  3946. ehdata = ehDataTable[i];
  3947. if (nonMaskable)
  3948. ehdata->nonMaskable = True;
  3949. ehdata->eventMask |= eventMask;
  3950. return(ehdata);
  3951. }
  3952. /* Look for an open slot */
  3953. for (i = 0; i < ehDataTableSize; i++)
  3954. {
  3955. if (ehDataTable[i] == NULL)
  3956. break;
  3957. }
  3958. if (i >= ehDataTableSize)
  3959. {
  3960. /* Need to enlarge the table */
  3961. ehDataTableSize += 10;
  3962. ehDataTable = (dtksh_event_handler_data_t **)
  3963. XtRealloc((XtPointer)ehDataTable,
  3964. sizeof(dtksh_event_handler_data_t *) * ehDataTableSize);
  3965. for (j = i; j < ehDataTableSize; j++)
  3966. ehDataTable[j] = NULL;
  3967. }
  3968. ehdata = (dtksh_event_handler_data_t *)
  3969. XtMalloc(sizeof(dtksh_event_handler_data_t));
  3970. if (ksh_cmd)
  3971. ehdata->ksh_cmd = strdup(ksh_cmd);
  3972. else
  3973. ehdata->ksh_cmd = NULL;
  3974. ehdata->w = w;
  3975. ehdata->eventMask = eventMask;
  3976. ehdata->nonMaskable = nonMaskable;
  3977. ehDataTable[i] = ehdata;
  3978. return(ehdata);
  3979. }
  3980. static int
  3981. LocateEHRecord(
  3982. wtab_t *w,
  3983. char *ksh_cmd )
  3984. {
  3985. int i;
  3986. /* Locate the matching event handler table entry */
  3987. for (i = 0; i < ehDataTableSize; i++)
  3988. {
  3989. if (ehDataTable[i])
  3990. {
  3991. if ((ehDataTable[i]->w == w) &&
  3992. (strcmp(ehDataTable[i]->ksh_cmd, ksh_cmd) == 0))
  3993. {
  3994. return(i);
  3995. }
  3996. }
  3997. }
  3998. return(-1);
  3999. }
  4000. int
  4001. do_DtSessionRestorePath(
  4002. int argc,
  4003. char *argv[] )
  4004. {
  4005. wtab_t *w;
  4006. char * path;
  4007. Boolean status;
  4008. char * errmsg;
  4009. if (argc != 4)
  4010. {
  4011. errmsg = strdup(GETMESSAGE(
  4012. "Usage: DtSessionRestorePath widget pathVariable saveFile"));
  4013. printerr(str_nill, errmsg, NULL);
  4014. free(errmsg);
  4015. return(1);
  4016. }
  4017. w = str_to_wtab(argv[0], argv[1]);
  4018. if (w == NULL)
  4019. return(1);
  4020. status = DtSessionRestorePath(w->w, &path, argv[3]);
  4021. if (status)
  4022. alt_env_set_var(argv[2], path);
  4023. else
  4024. alt_env_set_var(argv[2], str_nill);
  4025. return (!status);
  4026. }
  4027. int
  4028. do_DtSessionSavePath(
  4029. int argc,
  4030. char *argv[] )
  4031. {
  4032. wtab_t *w;
  4033. char * path;
  4034. char * file;
  4035. Boolean status;
  4036. char * errmsg;
  4037. if (argc != 4)
  4038. {
  4039. errmsg = strdup(GETMESSAGE(
  4040. "Usage: DtSessionSavePath widget pathVariable fileVariable"));
  4041. printerr(str_nill, errmsg, NULL);
  4042. free(errmsg);
  4043. return(1);
  4044. }
  4045. w = str_to_wtab(argv[0], argv[1]);
  4046. if (w == NULL)
  4047. return(1);
  4048. status = DtSessionSavePath(w->w, &path, &file);
  4049. if (status)
  4050. {
  4051. env_set_var(argv[2], path);
  4052. env_set_var(argv[3], file);
  4053. }
  4054. else
  4055. {
  4056. env_blank(argv[2]);
  4057. env_blank(argv[3]);
  4058. }
  4059. return (!status);
  4060. }
  4061. int
  4062. do_DtShellIsIconified(
  4063. int argc,
  4064. char *argv[] )
  4065. {
  4066. wtab_t *w;
  4067. Boolean status;
  4068. Atom actual_type;
  4069. int actual_format;
  4070. unsigned long nitems;
  4071. unsigned long leftover;
  4072. WmStateData * wm_state;
  4073. Atom wmStateAtom;
  4074. char * errmsg;
  4075. if (argc != 2)
  4076. {
  4077. errmsg = strdup(GETMESSAGE("Usage: DtShellIsIconified widget"));
  4078. printerr(str_nill, errmsg, NULL);
  4079. free(errmsg);
  4080. return(1);
  4081. }
  4082. w = str_to_wtab(argv[0], argv[1]);
  4083. if (w == NULL)
  4084. return(1);
  4085. wmStateAtom = XmInternAtom (XtDisplay(w->w), "WM_STATE", False);
  4086. /* Getting the WM_STATE property to see if iconified or not */
  4087. XGetWindowProperty(XtDisplay(w->w), XtWindow (w->w),
  4088. wmStateAtom, 0L, (long) LINESIZE, False,
  4089. wmStateAtom, &actual_type, &actual_format,
  4090. &nitems, &leftover, (unsigned char **) &wm_state);
  4091. return (wm_state->state != IconicState);
  4092. }
  4093. int
  4094. do_DtSetStartupCommand(
  4095. int argc,
  4096. char *argv[] )
  4097. {
  4098. wtab_t *w;
  4099. Atom commandAtom;
  4100. char * errmsg;
  4101. if (argc != 3)
  4102. {
  4103. errmsg = strdup(GETMESSAGE(
  4104. "Usage: DtSetStartupCommand widget command"));
  4105. printerr(str_nill, errmsg, NULL);
  4106. free(errmsg);
  4107. return(1);
  4108. }
  4109. w = str_to_wtab(argv[0], argv[1]);
  4110. if (w == NULL)
  4111. return(1);
  4112. commandAtom = XA_WM_COMMAND;
  4113. XChangeProperty(XtDisplay(w->w), XtWindow(w->w), commandAtom,
  4114. XA_STRING, 8, PropModeReplace,
  4115. (unsigned char *)argv[2], strlen(argv[2])+1);
  4116. XSync(XtDisplay(w->w), False);
  4117. return(0);
  4118. }
  4119. /* This only works if the widget is not yet realized */
  4120. int
  4121. do_DtSetIconifyHint(
  4122. int argc,
  4123. char *argv[] )
  4124. {
  4125. wtab_t *w;
  4126. Boolean state;
  4127. XrmValue fval, tval;
  4128. XWMHints *wmhints;
  4129. Arg args[5];
  4130. char * errmsg;
  4131. if (argc != 3)
  4132. {
  4133. errmsg = strdup(GETMESSAGE(
  4134. "Usage: DtSetIconifyHint widget boolean"));
  4135. printerr(str_nill, errmsg, NULL);
  4136. free(errmsg);
  4137. return(1);
  4138. }
  4139. w = str_to_wtab(argv[0], argv[1]);
  4140. if (w == NULL)
  4141. return(1);
  4142. fval.addr = argv[2];
  4143. fval.size = strlen(argv[2]);
  4144. XtConvert(Toplevel, XtRString, &fval, XtRBoolean, &tval);
  4145. if (tval.size != 0)
  4146. state = *((Boolean *)(tval.addr));
  4147. else
  4148. return(1);
  4149. if (state)
  4150. {
  4151. /* add the iconify hint to the current shell */
  4152. XtSetArg(args[0], XmNinitialState, IconicState);
  4153. XtSetValues(w->w, args, 1);
  4154. }
  4155. else
  4156. {
  4157. /* Remove the iconify hint from the current shell */
  4158. wmhints = XGetWMHints(XtDisplay(w->w), XtWindow(w->w));
  4159. wmhints->flags |= IconWindowHint;
  4160. wmhints->initial_state = NormalState;
  4161. XSetWMHints(XtDisplay(w->w), XtWindow(w->w), wmhints);
  4162. }
  4163. return(0);
  4164. }
  4165. int
  4166. do_DtWsmAddWorkspaceFunctions(
  4167. int argc,
  4168. char *argv[] )
  4169. {
  4170. return(WsmCommonProc(argc, argv, (void (*)())DtWsmAddWorkspaceFunctions));
  4171. }
  4172. int
  4173. do_DtWsmRemoveWorkspaceFunctions(
  4174. int argc,
  4175. char *argv[] )
  4176. {
  4177. return(WsmCommonProc(argc, argv, (void (*)())DtWsmRemoveWorkspaceFunctions));
  4178. }
  4179. static int
  4180. WsmCommonProc(
  4181. int argc,
  4182. char *argv[],
  4183. void (*func)())
  4184. {
  4185. wtab_t *w;
  4186. Display * display;
  4187. Window window;
  4188. char * p;
  4189. char buf[256];
  4190. char * errmsg;
  4191. if (argc != 3)
  4192. {
  4193. errmsg = strdup(GetSharedMsg(DT_USAGE_DISPLAY_WINDOW));
  4194. printerrf(str_nill, errmsg, argv[0], NULL, NULL, NULL, NULL,
  4195. NULL, NULL, NULL);
  4196. free(errmsg);
  4197. return(1);
  4198. }
  4199. display = (Display *)strtoul(argv[1], &p, 0);
  4200. if (p == argv[1])
  4201. {
  4202. errmsg = strdup(GetSharedMsg(DT_BAD_DISPLAY));
  4203. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL, NULL,
  4204. NULL, NULL);
  4205. free(errmsg);
  4206. return(1);
  4207. }
  4208. window = (Window)strtoul(argv[2], &p, 0);
  4209. if (p == argv[2])
  4210. {
  4211. errmsg = strdup(GetSharedMsg(DT_BAD_WINDOW));
  4212. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  4213. NULL, NULL);
  4214. free(errmsg);
  4215. return(1);
  4216. }
  4217. (*func)(display, window);
  4218. return (0);
  4219. }
  4220. int
  4221. do_DtWsmGetCurrentWorkspace(
  4222. int argc,
  4223. char *argv[] )
  4224. {
  4225. wtab_t *w;
  4226. Display * display;
  4227. Window rootWindow;
  4228. char * p;
  4229. Atom atom;
  4230. char buf[256];
  4231. char * errmsg;
  4232. if (argc != 4)
  4233. {
  4234. errmsg = strdup(GetSharedMsg(DT_USAGE_DISPLAY_ROOT_VAR));
  4235. printerrf(str_nill, errmsg, argv[0], NULL, NULL, NULL, NULL, NULL,
  4236. NULL, NULL);
  4237. free(errmsg);
  4238. return(1);
  4239. }
  4240. display = (Display *)strtoul(argv[1], &p, 0);
  4241. if (p == argv[1])
  4242. {
  4243. errmsg = strdup(GetSharedMsg(DT_BAD_DISPLAY));
  4244. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL, NULL,
  4245. NULL, NULL);
  4246. free(errmsg);
  4247. env_blank(argv[3]);
  4248. return(1);
  4249. }
  4250. rootWindow = (Window)strtoul(argv[2], &p, 0);
  4251. if (p == argv[2])
  4252. {
  4253. errmsg = strdup(GETMESSAGE(
  4254. "The rootWindow parameter is invalid: %s"));
  4255. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  4256. NULL, NULL);
  4257. free(errmsg);
  4258. env_blank(argv[3]);
  4259. return(1);
  4260. }
  4261. DtWsmGetCurrentWorkspace(display, rootWindow, &atom);
  4262. sprintf(buf, "%ld", (long)atom);
  4263. env_set_var(argv[3], buf);
  4264. return (0);
  4265. }
  4266. int
  4267. do_DtWsmSetCurrentWorkspace(
  4268. int argc,
  4269. char *argv[] )
  4270. {
  4271. wtab_t *w;
  4272. char * p;
  4273. Atom atom;
  4274. Status result;
  4275. char * errmsg;
  4276. if (argc != 3)
  4277. {
  4278. errmsg = strdup(GETMESSAGE(
  4279. "Usage: DtWsmSetCurrentWorkspace widget atom"));
  4280. printerr(str_nill, errmsg, NULL);
  4281. free(errmsg);
  4282. return(1);
  4283. }
  4284. w = str_to_wtab(argv[0], argv[1]);
  4285. if (w == NULL)
  4286. return(1);
  4287. atom = (Atom)strtoul(argv[2], &p, 0);
  4288. if (p == argv[2])
  4289. {
  4290. errmsg = strdup(GETMESSAGE("The workspace atom is invalid: %s"));
  4291. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  4292. NULL, NULL);
  4293. free(errmsg);
  4294. return(1);
  4295. }
  4296. result = DtWsmSetCurrentWorkspace(w->w, atom);
  4297. if (result == DT_SVC_SUCCESS)
  4298. return (0);
  4299. else
  4300. return (1);
  4301. }
  4302. static int
  4303. GetWorkspaceList(
  4304. char *usageMsg,
  4305. Boolean getOccupied,
  4306. int argc,
  4307. char *argv[] )
  4308. {
  4309. wtab_t *w;
  4310. char * p;
  4311. Display * display;
  4312. Window root;
  4313. unsigned long numWS;
  4314. Atom * wsList;
  4315. char * buf;
  4316. char atom[128];
  4317. int result;
  4318. int i;
  4319. char * errmsg;
  4320. if (argc != 4)
  4321. {
  4322. printerrf(str_nill, usageMsg, argv[0], NULL, NULL, NULL, NULL, NULL,
  4323. NULL, NULL);
  4324. return(1);
  4325. }
  4326. display = (Display *)strtoul(argv[1], &p, 0);
  4327. if (p == argv[1])
  4328. {
  4329. errmsg = strdup(GetSharedMsg(DT_BAD_DISPLAY));
  4330. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL, NULL,
  4331. NULL, NULL);
  4332. free(errmsg);
  4333. env_blank(argv[3]);
  4334. return(1);
  4335. }
  4336. root = (Window)strtoul(argv[2], &p, 0);
  4337. if (p == argv[2])
  4338. {
  4339. errmsg = strdup(GetSharedMsg(DT_BAD_WINDOW));
  4340. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  4341. NULL, NULL);
  4342. free(errmsg);
  4343. env_blank(argv[3]);
  4344. return(1);
  4345. }
  4346. if (getOccupied)
  4347. result = DtWsmGetWorkspacesOccupied(display, root, &wsList, &numWS);
  4348. else
  4349. result = DtWsmGetWorkspaceList(display, root, &wsList, (int *)&numWS);
  4350. if (result == Success)
  4351. {
  4352. buf = XtMalloc(1);
  4353. buf[0] = '\0';
  4354. for (i = 0; i < numWS; i++)
  4355. {
  4356. sprintf(atom, "%ld", (long)wsList[i]);
  4357. buf = XtRealloc(buf, strlen(buf) + strlen(atom) + 2);
  4358. if (i != 0)
  4359. strcat(buf, ",");
  4360. strcat(buf, atom);
  4361. }
  4362. env_set_var(argv[3], buf);
  4363. XtFree(buf);
  4364. XFree (wsList);
  4365. return (0);
  4366. }
  4367. else
  4368. {
  4369. env_blank(argv[3]);
  4370. return (1);
  4371. }
  4372. }
  4373. int
  4374. do_DtWsmGetWorkspaceList(
  4375. int argc,
  4376. char *argv[] )
  4377. {
  4378. char * errmsg;
  4379. int retVal;
  4380. errmsg = strdup(GetSharedMsg(DT_USAGE_DISPLAY_ROOT_VAR));
  4381. retVal = GetWorkspaceList(errmsg, False, argc, argv);
  4382. free(errmsg);
  4383. return(retVal);
  4384. }
  4385. int
  4386. do_DtWsmGetWorkspacesOccupied(
  4387. int argc,
  4388. char *argv[] )
  4389. {
  4390. char * errmsg;
  4391. int retVal;
  4392. errmsg = strdup(GetSharedMsg(DT_USAGE_DISPLAY_WINDOW_VAR));
  4393. retVal = GetWorkspaceList(errmsg, True, argc, argv);
  4394. free(errmsg);
  4395. return(retVal);
  4396. }
  4397. int
  4398. do_DtWsmSetWorkspacesOccupied(
  4399. int argc,
  4400. char *argv[] )
  4401. {
  4402. char * p;
  4403. Display * display;
  4404. Window window;
  4405. unsigned long numWS;
  4406. Atom * wsList;
  4407. char * buf;
  4408. int i;
  4409. char * nextAtom;
  4410. char * errmsg;
  4411. if (argc != 4)
  4412. {
  4413. errmsg = strdup(GETMESSAGE(
  4414. "Usage: DtWsmSetWorkspacesOccupied display window workspaceList"));
  4415. printerr(str_nill, errmsg, NULL);
  4416. free(errmsg);
  4417. return(1);
  4418. }
  4419. display = (Display *)strtoul(argv[1], &p, 0);
  4420. if (p == argv[1])
  4421. {
  4422. errmsg = strdup(GetSharedMsg(DT_BAD_DISPLAY));
  4423. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL, NULL,
  4424. NULL, NULL);
  4425. free(errmsg);
  4426. return(1);
  4427. }
  4428. window = (Window)strtoul(argv[2], &p, 0);
  4429. if (p == argv[2])
  4430. {
  4431. errmsg = strdup(GetSharedMsg(DT_BAD_WINDOW));
  4432. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  4433. NULL, NULL);
  4434. free(errmsg);
  4435. return(1);
  4436. }
  4437. numWS = 0;
  4438. p = argv[3];
  4439. /* Strip leading spaces */
  4440. while (*p == ' ')
  4441. p++;
  4442. nextAtom = strtok(p, ",");
  4443. wsList = (Atom *)XtMalloc(1);
  4444. wsList[0] = '\0';
  4445. while (nextAtom)
  4446. {
  4447. if (strlen(nextAtom) > 0)
  4448. {
  4449. wsList = (Atom *)XtRealloc((char *)wsList, sizeof(Atom) * (numWS + 1));
  4450. wsList[numWS] = atol(nextAtom);
  4451. numWS++;
  4452. nextAtom = strtok(NULL, ",");
  4453. }
  4454. }
  4455. DtWsmSetWorkspacesOccupied(display, window, wsList, numWS);
  4456. XtFree ((char *)wsList);
  4457. return (0);
  4458. }
  4459. int
  4460. do_DtWsmGetCurrentBackdropWindow(
  4461. int argc,
  4462. char *argv[] )
  4463. {
  4464. char * p;
  4465. Display * display;
  4466. Window rootWindow, returnedWin;
  4467. char * errmsg;
  4468. if (argc != 4)
  4469. {
  4470. errmsg = strdup(GetSharedMsg(DT_USAGE_DISPLAY_ROOT_VAR));
  4471. printerrf(str_nill, errmsg, argv[0], NULL, NULL, NULL, NULL, NULL,
  4472. NULL, NULL);
  4473. free(errmsg);
  4474. return(1);
  4475. }
  4476. display = (Display *)strtoul(argv[1], &p, 0);
  4477. if (p == argv[1])
  4478. {
  4479. errmsg = strdup(GetSharedMsg(DT_BAD_DISPLAY));
  4480. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL, NULL,
  4481. NULL, NULL);
  4482. free(errmsg);
  4483. env_blank(argv[3]);
  4484. return(1);
  4485. }
  4486. rootWindow = (Window)strtoul(argv[2], &p, 0);
  4487. if (p == argv[2])
  4488. {
  4489. errmsg = strdup(GetSharedMsg(DT_BAD_WINDOW));
  4490. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  4491. NULL, NULL);
  4492. free(errmsg);
  4493. env_blank(argv[3]);
  4494. return(1);
  4495. }
  4496. returnedWin = DtWsmGetCurrentBackdropWindow(display, rootWindow);
  4497. if (returnedWin != None)
  4498. {
  4499. char buf[128];
  4500. sprintf(buf, "%d", (int)returnedWin);
  4501. env_set_var(argv[3], buf);
  4502. return (0);
  4503. }
  4504. else
  4505. {
  4506. env_blank(argv[3]);
  4507. return (1);
  4508. }
  4509. }
  4510. int
  4511. do_DtWsmOccupyAllWorkspaces(
  4512. int argc,
  4513. char *argv[] )
  4514. {
  4515. return(WsmCommonProc(argc, argv, (void (*)())DtWsmOccupyAllWorkspaces));
  4516. }
  4517. int
  4518. do__DtGetHourGlassCursor(
  4519. int argc,
  4520. char *argv[] )
  4521. {
  4522. char * p;
  4523. Display * display;
  4524. Cursor cursor;
  4525. char buf[128];
  4526. char * errmsg;
  4527. if (argc != 3)
  4528. {
  4529. errmsg = strdup(GETMESSAGE(
  4530. "Usage: _DtGetHourGlassCursor variable display"));
  4531. printerr(str_nill, errmsg, NULL);
  4532. free(errmsg);
  4533. return(1);
  4534. }
  4535. display = (Display *)strtoul(argv[2], &p, 0);
  4536. if (p == argv[2])
  4537. {
  4538. errmsg = strdup(GetSharedMsg(DT_BAD_DISPLAY));
  4539. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  4540. NULL, NULL);
  4541. free(errmsg);
  4542. alt_env_set_var(argv[1], str_nill);
  4543. return(1);
  4544. }
  4545. cursor = _DtGetHourGlassCursor(display);
  4546. sprintf(buf, "%d", cursor);
  4547. alt_env_set_var(argv[1], buf);
  4548. return (0);
  4549. }
  4550. static int
  4551. DtTurnOnOrOffHourGlass(
  4552. void (*func)(),
  4553. int argc,
  4554. char *argv[] )
  4555. {
  4556. char * p;
  4557. Cursor cursor;
  4558. char buf[128];
  4559. wtab_t *w;
  4560. char * errmsg;
  4561. if (argc != 2)
  4562. {
  4563. errmsg = strdup(GetSharedMsg(DT_USAGE_WIDGET));
  4564. printerrf(str_nill, errmsg, argv[0], NULL, NULL, NULL, NULL,
  4565. NULL, NULL, NULL);
  4566. free(errmsg);
  4567. return(1);
  4568. }
  4569. w = str_to_wtab(argv[0], argv[1]);
  4570. if (w == NULL)
  4571. return(1);
  4572. (*func)(w->w);
  4573. return (0);
  4574. }
  4575. int
  4576. do__DtTurnOnHourGlass(
  4577. int argc,
  4578. char *argv[] )
  4579. {
  4580. return(DtTurnOnOrOffHourGlass(_DtTurnOnHourGlass, argc, argv));
  4581. }
  4582. int
  4583. do__DtTurnOffHourGlass(
  4584. int argc,
  4585. char *argv[] )
  4586. {
  4587. return(DtTurnOnOrOffHourGlass(_DtTurnOffHourGlass, argc, argv));
  4588. }
  4589. int
  4590. do_DtWsmAddCurrentWorkspaceCallback(
  4591. int argc,
  4592. char **argv )
  4593. {
  4594. wtab_t *w;
  4595. dtksh_client_data_t *cdata;
  4596. char * p;
  4597. Atom propAtom;
  4598. DtWsmCBContext handle;
  4599. char buf[128];
  4600. char * errmsg;
  4601. if (argc != 4)
  4602. {
  4603. errmsg = strdup(GETMESSAGE(
  4604. "Usage: DtWsmAddCurrentWorkspaceCallback variable widget ksh-command"));
  4605. printerr(str_nill, errmsg, NULL);
  4606. free(errmsg);
  4607. return(1);
  4608. }
  4609. w = str_to_wtab(argv[0], argv[2]);
  4610. if (w == NULL)
  4611. {
  4612. alt_env_set_var(argv[1], str_nill);
  4613. return(1);
  4614. }
  4615. /* Always force a new entry */
  4616. cdata = GetNewCBData(NULL, NULL, NULL, None);
  4617. cdata->w = w;
  4618. cdata->ksh_cmd = strdup(argv[3]);
  4619. handle = DtWsmAddCurrentWorkspaceCallback(w->w,
  4620. (DtWsmWsChangeProc)stdWSCB, (XtPointer)cdata);
  4621. cdata->handle = (XtPointer)handle;
  4622. sprintf(buf, "%ld", (long)handle);
  4623. alt_env_set_var(argv[1], buf);
  4624. return(0);
  4625. }
  4626. int
  4627. do_DtWsmRemoveWorkspaceCallback(
  4628. int argc,
  4629. char **argv )
  4630. {
  4631. char * errmsg, *p;
  4632. dtksh_client_data_t *cdata = (dtksh_client_data_t *)NULL;
  4633. DtWsmCBContext handle;
  4634. int i;
  4635. if (argc != 2)
  4636. {
  4637. errmsg = strdup(GETMESSAGE(
  4638. "Usage: DtWsmRemoveWorkspaceCallback handle"));
  4639. printerr(str_nill, errmsg, NULL);
  4640. free(errmsg);
  4641. return(1);
  4642. }
  4643. handle = (DtWsmCBContext)strtoul(argv[1], &p, 0);
  4644. if (p != argv[1])
  4645. {
  4646. for(i = 0; i < cbDataTableSize; i++)
  4647. {
  4648. if(cbDataTable[i] != (dtksh_client_data_t *)NULL)
  4649. {
  4650. if(cbDataTable[i]->handle == handle)
  4651. {
  4652. cdata = cbDataTable[i];
  4653. break;
  4654. }
  4655. }
  4656. }
  4657. }
  4658. if(cdata == (dtksh_client_data_t *)NULL)
  4659. {
  4660. errmsg = strdup(GETMESSAGE(
  4661. "The following is an invalid callback handle: %s"));
  4662. printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL, NULL, NULL,
  4663. NULL, NULL);
  4664. free(errmsg);
  4665. return(1);
  4666. }
  4667. return(RemoveOneCallback (argv[0], cdata->w->widid, NULL, cdata->ksh_cmd,
  4668. NULL, argv[1]));
  4669. }
  4670. /*****************************************************************************/
  4671. /*****************************************************************************/
  4672. int
  4673. do_DtDbLoad(
  4674. int argc,
  4675. char *argv[] )
  4676. {
  4677. char * errmsg;
  4678. if (argc != 1)
  4679. {
  4680. errmsg = strdup(GETMESSAGE("Usage: DtDbLoad"));
  4681. printerr(str_nill, errmsg, NULL);
  4682. free(errmsg);
  4683. return(1);
  4684. }
  4685. DtDbLoad();
  4686. return (0);
  4687. }
  4688. /* Only a single handler is allowed */
  4689. static char * reloadNotifyCommand = NULL;
  4690. /*
  4691. * This is our internal 'ReloadNotify' callback; it simply interprets
  4692. * the ksh command specified by the shell script.
  4693. */
  4694. static void
  4695. DtkReloadHandler(
  4696. XtPointer clientData )
  4697. {
  4698. ksh_eval((char *)reloadNotifyCommand);
  4699. }
  4700. /*
  4701. * This command registers a ksh-command string, which will be executed
  4702. * whenever a 'ReloadNotify' message is received. Subsequent calls to
  4703. * this command will simply replace the previous ksh-command witht the
  4704. * new one.
  4705. */
  4706. int
  4707. do_DtDbReloadNotify(
  4708. int argc,
  4709. char *argv[] )
  4710. {
  4711. char * errmsg;
  4712. static Boolean firstTime = True;
  4713. if (argc != 2)
  4714. {
  4715. errmsg = strdup(GETMESSAGE("Usage: DtDbReloadNotify ksh-command"));
  4716. printerr(str_nill, errmsg, NULL);
  4717. free(errmsg);
  4718. return(1);
  4719. }
  4720. if (firstTime)
  4721. {
  4722. firstTime = False;
  4723. DtDbReloadNotify((DtDbReloadCallbackProc)DtkReloadHandler, NULL);
  4724. }
  4725. XtFree(reloadNotifyCommand);
  4726. reloadNotifyCommand = strdup(argv[1]);
  4727. return (0);
  4728. }
  4729. /*
  4730. * This command is a boolean command, which returns 'True' if the
  4731. * specified name correlates to a defined action.
  4732. */
  4733. int
  4734. do_DtActionExists(
  4735. int argc,
  4736. char *argv[] )
  4737. {
  4738. char * errmsg;
  4739. if (argc != 2)
  4740. {
  4741. errmsg = strdup(GETMESSAGE("Usage: DtActionExists actionName"));
  4742. printerr(str_nill, errmsg, NULL);
  4743. free(errmsg);
  4744. return(1);
  4745. }
  4746. if (DtActionExists(argv[1]))
  4747. return(0);
  4748. return(255);
  4749. }
  4750. /*
  4751. * This command returns the label associated with an action. If the
  4752. * action is not defined, or if there is no label, then an empty string
  4753. * is returned.
  4754. */
  4755. int
  4756. do_DtActionLabel(
  4757. int argc,
  4758. char *argv[] )
  4759. {
  4760. char * errmsg;
  4761. char * label;
  4762. if (argc != 3)
  4763. {
  4764. errmsg = strdup(GETMESSAGE(
  4765. "Usage: DtActionLabel variable actionName"));
  4766. printerr(str_nill, errmsg, NULL);
  4767. free(errmsg);
  4768. return(1);
  4769. }
  4770. if (label = DtActionLabel(argv[2]))
  4771. {
  4772. alt_env_set_var(argv[1], label);
  4773. XtFree(label);
  4774. }
  4775. else
  4776. alt_env_set_var(argv[1], str_nill);
  4777. return (0);
  4778. }
  4779. /*
  4780. * This command returns the description associated with an action. If the
  4781. * action is not defined, or if there is no description, then an empty string
  4782. * is returned.
  4783. */
  4784. int
  4785. do_DtActionDescription(
  4786. int argc,
  4787. char *argv[] )
  4788. {
  4789. char * errmsg;
  4790. char * description;
  4791. if (argc != 3)
  4792. {
  4793. errmsg = strdup(GETMESSAGE(
  4794. "Usage: DtActionDescription variable actionName"));
  4795. printerr(str_nill, errmsg, NULL);
  4796. free(errmsg);
  4797. return(1);
  4798. }
  4799. if (description = DtActionDescription(argv[2]))
  4800. {
  4801. alt_env_set_var(argv[1], description);
  4802. XtFree(description);
  4803. }
  4804. else
  4805. alt_env_set_var(argv[1], str_nill);
  4806. return (0);
  4807. }
  4808. static void
  4809. _DtActionInvokeUsage( void )
  4810. {
  4811. char * errmsg;
  4812. errmsg = strdup(GETMESSAGE(
  4813. "Usage: DtActionInvoke widget actionName termParms execHost contextDir useIndicator ksh-command [\"FILE\" fileName] ..."));
  4814. printerr(str_nill, errmsg, NULL);
  4815. free(errmsg);
  4816. }
  4817. /*
  4818. * This command provides the shell script with the mechanism for requesting
  4819. * that an action be invoked. It accepts a variable list of arguments,
  4820. * which can currently only be of type 'ARG_FILE'.
  4821. */
  4822. int
  4823. do_DtActionInvoke(
  4824. int argc,
  4825. char *argv[] )
  4826. {
  4827. wtab_t *w;
  4828. char * termParms = (char *)NULL;
  4829. char * execHost = (char *)NULL;
  4830. char * contextDir = (char *)NULL;
  4831. Boolean useIndicator;
  4832. int aac;
  4833. DtActionArg *aap = (DtActionArg *)NULL;
  4834. XrmValue fval, tval;
  4835. int i;
  4836. int idx;
  4837. int * lockedFds;
  4838. /*
  4839. * Either there must be no file args (so argc == 8), or if there are
  4840. * file args, then there must be 2 components for each argument.
  4841. * This check must change when/if we support arguments other than files.
  4842. */
  4843. if ((argc < 8) || (((argc - 8) % 2) != 0))
  4844. {
  4845. _DtActionInvokeUsage();
  4846. return(1);
  4847. }
  4848. w = str_to_wtab(argv[0], argv[1]);
  4849. if (w == (wtab_t *)NULL)
  4850. return(1);
  4851. /* Get true/false value for useIndicator */
  4852. fval.addr = argv[6];
  4853. fval.size = strlen(argv[6]);
  4854. XtConvert(Toplevel, XtRString, &fval, XtRBoolean, &tval);
  4855. if (tval.size != 0)
  4856. useIndicator = *((Boolean *)(tval.addr));
  4857. else
  4858. return(1);
  4859. if (argv[3] && (strlen(argv[3]) > 0))
  4860. termParms = argv[3];
  4861. if (argv[4] && (strlen(argv[4]) > 0))
  4862. execHost = argv[4];
  4863. if (argv[5] && (strlen(argv[5]) > 0))
  4864. contextDir = argv[5];
  4865. /*
  4866. * Parse the optional file arguments
  4867. * This will have to change when/if we support arguments other than files.
  4868. */
  4869. if ((aac = (argc - 8) / 2) > 0)
  4870. {
  4871. aap = (DtActionArg *)XtMalloc(sizeof(DtActionArg) * aac);
  4872. for (i = 8; i < argc; i+=2 )
  4873. {
  4874. if(strcmp(argv[i], "FILE") != 0)
  4875. {
  4876. _DtActionInvokeUsage();
  4877. XtFree((char *)aap);
  4878. return(1);
  4879. }
  4880. idx = (i - 8) / 2;
  4881. aap[idx].argClass = DtACTION_FILE;
  4882. aap[idx].u.file.name = argv[i + 1];
  4883. }
  4884. }
  4885. /* Force fd above the range reserved by ksh for the user (0 - 9) */
  4886. lockedFds = LockKshFileDescriptors();
  4887. /*
  4888. * Force callback to NULL until we have code in place to support it.
  4889. */
  4890. DtActionInvoke(w->w, argv[2], aap, aac, termParms, execHost,
  4891. contextDir, useIndicator, NULL,
  4892. (XtPointer)NULL);
  4893. UnlockKshFileDescriptors(lockedFds);
  4894. XtFree((char *)aap);
  4895. return (0);
  4896. }
  4897. /*****************************************************************************/
  4898. /*****************************************************************************/
  4899. int
  4900. do_DtDtsLoadDataTypes(
  4901. int argc,
  4902. char *argv[] )
  4903. {
  4904. char * errmsg;
  4905. if (argc != 1)
  4906. {
  4907. errmsg = strdup(GETMESSAGE("Usage: DtDtsLoadDataTypes"));
  4908. printerr(str_nill, errmsg, NULL);
  4909. free(errmsg);
  4910. return(1);
  4911. }
  4912. DtDtsLoadDataTypes();
  4913. return (0);
  4914. }
  4915. int
  4916. do_DtDtsFileToDataType(
  4917. int argc,
  4918. char *argv[] )
  4919. {
  4920. char * errmsg;
  4921. char * datatype;
  4922. if (argc != 3)
  4923. {
  4924. errmsg = strdup(GETMESSAGE(
  4925. "Usage: DtDtsFileToDataType variable fileName"));
  4926. printerr(str_nill, errmsg, NULL);
  4927. free(errmsg);
  4928. return(1);
  4929. }
  4930. if (datatype = DtDtsFileToDataType(argv[2]))
  4931. {
  4932. alt_env_set_var(argv[1], datatype);
  4933. DtDtsFreeDataType(datatype);
  4934. }
  4935. else
  4936. alt_env_set_var(argv[1], str_nill);
  4937. return (0);
  4938. }
  4939. int
  4940. do_DtDtsFileToAttributeValue(
  4941. int argc,
  4942. char *argv[] )
  4943. {
  4944. char * errmsg;
  4945. char * attribute;
  4946. if (argc != 4)
  4947. {
  4948. errmsg = strdup(GETMESSAGE(
  4949. "Usage: DtDtsFileToAttributeValue variable fileName attrName"));
  4950. printerr(str_nill, errmsg, NULL);
  4951. free(errmsg);
  4952. return(1);
  4953. }
  4954. if (attribute = DtDtsFileToAttributeValue(argv[2], argv[3]))
  4955. {
  4956. alt_env_set_var(argv[1], attribute);
  4957. DtDtsFreeAttributeValue(attribute);
  4958. }
  4959. else
  4960. alt_env_set_var(argv[1], str_nill);
  4961. return (0);
  4962. }
  4963. int
  4964. do_DtDtsFileToAttributeList(
  4965. int argc,
  4966. char *argv[] )
  4967. {
  4968. char * errmsg;
  4969. char * attributeList;
  4970. DtDtsAttribute ** attributes;
  4971. int i;
  4972. if (argc != 3)
  4973. {
  4974. errmsg = strdup(GETMESSAGE(
  4975. "Usage: DtDtsFileToAttributeList variable fileName"));
  4976. printerr(str_nill, errmsg, NULL);
  4977. free(errmsg);
  4978. return(1);
  4979. }
  4980. if (attributes = DtDtsFileToAttributeList(argv[2]))
  4981. {
  4982. attributeList = XtMalloc(1);
  4983. attributeList[0] = '\0';
  4984. for (i = 0; attributes[i]; i++)
  4985. {
  4986. attributeList = XtRealloc(attributeList,
  4987. strlen(attributeList) +
  4988. strlen(attributes[i]->name) + 3);
  4989. if (i != 0)
  4990. strcat(attributeList, " ");
  4991. strcat(attributeList, attributes[i]->name);
  4992. }
  4993. alt_env_set_var(argv[1], attributeList);
  4994. DtDtsFreeAttributeList(attributes);
  4995. XtFree(attributeList);
  4996. }
  4997. else
  4998. alt_env_set_var(argv[1], str_nill);
  4999. return (0);
  5000. }
  5001. int
  5002. do_DtDtsDataTypeToAttributeValue(
  5003. int argc,
  5004. char *argv[] )
  5005. {
  5006. char * errmsg;
  5007. char * attribute;
  5008. char * optName;
  5009. if ((argc != 4) && (argc != 5))
  5010. {
  5011. errmsg = strdup(GETMESSAGE(
  5012. "Usage: DtDtsDataTypeToAttributeValue variable dataType attrName optName"));
  5013. printerr(str_nill, errmsg, NULL);
  5014. free(errmsg);
  5015. return(1);
  5016. }
  5017. if ((argc == 4) || (strlen(argv[4]) == 0))
  5018. optName = NULL;
  5019. else
  5020. optName = argv[4];
  5021. if (attribute = DtDtsDataTypeToAttributeValue(argv[2], argv[3], optName))
  5022. {
  5023. alt_env_set_var(argv[1], attribute);
  5024. DtDtsFreeAttributeValue(attribute);
  5025. }
  5026. else
  5027. alt_env_set_var(argv[1], str_nill);
  5028. return (0);
  5029. }
  5030. int
  5031. do_DtDtsDataTypeToAttributeList(
  5032. int argc,
  5033. char *argv[] )
  5034. {
  5035. char * errmsg;
  5036. char * attributeList;
  5037. DtDtsAttribute ** attributes;
  5038. int i;
  5039. char * optName;
  5040. if ((argc != 3) && (argc != 4))
  5041. {
  5042. errmsg = strdup(GETMESSAGE(
  5043. "Usage: DtDtsDataTypeToAttributeList variable dataType optName"));
  5044. printerr(str_nill, errmsg, NULL);
  5045. free(errmsg);
  5046. return(1);
  5047. }
  5048. if ((argc == 3) || (strlen(argv[3]) == 0))
  5049. optName = NULL;
  5050. else
  5051. optName = argv[3];
  5052. if (attributes = DtDtsDataTypeToAttributeList(argv[2], optName))
  5053. {
  5054. attributeList = XtMalloc(1);
  5055. attributeList[0] = '\0';
  5056. for (i = 0; attributes[i]; i++)
  5057. {
  5058. attributeList = XtRealloc(attributeList,
  5059. strlen(attributeList) +
  5060. strlen(attributes[i]->name) + 3);
  5061. if (i != 0)
  5062. strcat(attributeList, " ");
  5063. strcat(attributeList, attributes[i]->name);
  5064. }
  5065. alt_env_set_var(argv[1], attributeList);
  5066. DtDtsFreeAttributeList(attributes);
  5067. XtFree(attributeList);
  5068. }
  5069. else
  5070. alt_env_set_var(argv[1], str_nill);
  5071. return (0);
  5072. }
  5073. int
  5074. do_DtDtsFindAttribute(
  5075. int argc,
  5076. char *argv[] )
  5077. {
  5078. char * errmsg;
  5079. char * dataTypeList;
  5080. char ** dataTypes;
  5081. int i;
  5082. if (argc != 4)
  5083. {
  5084. errmsg = strdup(GETMESSAGE(
  5085. "Usage: DtDtsFindAttribute variable name value"));
  5086. printerr(str_nill, errmsg, NULL);
  5087. free(errmsg);
  5088. return(1);
  5089. }
  5090. if (dataTypes = DtDtsFindAttribute(argv[2], argv[3]))
  5091. {
  5092. dataTypeList = XtMalloc(1);
  5093. dataTypeList[0] = '\0';
  5094. for (i = 0; dataTypes[i]; i++)
  5095. {
  5096. dataTypeList = XtRealloc(dataTypeList,
  5097. strlen(dataTypeList) +
  5098. strlen(dataTypes[i]) + 3);
  5099. if (i != 0)
  5100. strcat(dataTypeList, " ");
  5101. strcat(dataTypeList, dataTypes[i]);
  5102. }
  5103. alt_env_set_var(argv[1], dataTypeList);
  5104. DtDtsFreeDataTypeNames(dataTypes);
  5105. XtFree(dataTypeList);
  5106. }
  5107. else
  5108. alt_env_set_var(argv[1], str_nill);
  5109. return (0);
  5110. }
  5111. int
  5112. do_DtDtsDataTypeNames(
  5113. int argc,
  5114. char *argv[] )
  5115. {
  5116. char * errmsg;
  5117. char * dataTypeList;
  5118. char ** dataTypes;
  5119. int i;
  5120. if (argc != 2)
  5121. {
  5122. errmsg = strdup(GETMESSAGE("Usage: DtDtsDataTypeNames variable"));
  5123. printerr(str_nill, errmsg, NULL);
  5124. free(errmsg);
  5125. return(1);
  5126. }
  5127. if (dataTypes = DtDtsDataTypeNames())
  5128. {
  5129. dataTypeList = XtMalloc(1);
  5130. dataTypeList[0] = '\0';
  5131. for (i = 0; dataTypes[i]; i++)
  5132. {
  5133. dataTypeList = XtRealloc(dataTypeList,
  5134. strlen(dataTypeList) +
  5135. strlen(dataTypes[i]) + 3);
  5136. if (i != 0)
  5137. strcat(dataTypeList, " ");
  5138. strcat(dataTypeList, dataTypes[i]);
  5139. }
  5140. alt_env_set_var(argv[1], dataTypeList);
  5141. DtDtsFreeDataTypeNames(dataTypes);
  5142. XtFree(dataTypeList);
  5143. }
  5144. else
  5145. alt_env_set_var(argv[1], str_nill);
  5146. return (0);
  5147. }
  5148. int
  5149. do_DtDtsSetDataType(
  5150. int argc,
  5151. char *argv[] )
  5152. {
  5153. char * errmsg;
  5154. char * savedDataType;
  5155. Boolean override;
  5156. if (argc != 5)
  5157. {
  5158. errmsg = strdup(GETMESSAGE(
  5159. "Usage: DtDtsSetDataType variable fileName dataType override"));
  5160. printerr(str_nill, errmsg, NULL);
  5161. free(errmsg);
  5162. return(1);
  5163. }
  5164. /* Since XtInitialize may not have been called, can't use XtConvert */
  5165. if (DtCompareISOLatin1(argv[4], "true"))
  5166. override = True;
  5167. else if (DtCompareISOLatin1(argv[4], "false"))
  5168. override = False;
  5169. else
  5170. return(1);
  5171. if (savedDataType = DtDtsSetDataType(argv[2], argv[3], override))
  5172. {
  5173. alt_env_set_var(argv[1], savedDataType);
  5174. DtDtsFreeDataType(savedDataType);
  5175. }
  5176. else
  5177. alt_env_set_var(argv[1], str_nill);
  5178. return (0);
  5179. }
  5180. int
  5181. do_DtDtsDataTypeIsAction(
  5182. int argc,
  5183. char *argv[] )
  5184. {
  5185. char * errmsg;
  5186. if (argc != 2)
  5187. {
  5188. errmsg = strdup(GETMESSAGE(
  5189. "Usage: DtDtsDataTypeIsAction dataType"));
  5190. printerr(str_nill, errmsg, NULL);
  5191. free(errmsg);
  5192. return(1);
  5193. }
  5194. if (DtDtsDataTypeIsAction(argv[1]))
  5195. return(0);
  5196. return(255);
  5197. }
  5198. /*****************************************************************************/
  5199. /*****************************************************************************/
  5200. /*
  5201. * This command will attempt to open a ToolTalk communications channel.
  5202. */
  5203. int
  5204. do_ttdt_open(
  5205. int argc,
  5206. char *argv[] )
  5207. {
  5208. char * errmsg;
  5209. char * procId;
  5210. Boolean sendStarted;
  5211. XrmValue toVal;
  5212. Cardinal nargs;
  5213. char * statusString;
  5214. char buf[25];
  5215. int ttfd;
  5216. int * lockedFds;
  5217. Tt_status ttStatus;
  5218. if (argc != 8)
  5219. {
  5220. errmsg = strdup(GETMESSAGE(
  5221. "Usage: ttdt_open variable status variable2 toolname vendor version sendStarted"));
  5222. printerr(str_nill, errmsg, NULL);
  5223. free(errmsg);
  5224. return(1);
  5225. }
  5226. /* Convert "true" or "false" to 1 or 0 */
  5227. DtkshCvtStringToBool(argv[7], &toVal);
  5228. if (toVal.size != 0)
  5229. sendStarted = *((Boolean *)(toVal.addr));
  5230. else
  5231. return(1);
  5232. /* Force fd above the range reserved by ksh for the user (0 - 9) */
  5233. lockedFds = LockKshFileDescriptors();
  5234. procId = ttdt_open(&ttfd, argv[4], argv[5], argv[6], (int)sendStarted);
  5235. UnlockKshFileDescriptors(lockedFds);
  5236. /* Get the ttStatus and the asssociated string */
  5237. ttStatus = tt_ptr_error(procId);
  5238. DtkshCvtTtStatusToString(ttStatus, &toVal);
  5239. if (toVal.size && toVal.addr)
  5240. statusString = toVal.addr;
  5241. else
  5242. statusString = str_nill;
  5243. env_set_var(argv[2], statusString);
  5244. if (ttStatus == TT_OK)
  5245. env_set_var(argv[1], procId);
  5246. else
  5247. {
  5248. env_set_var(argv[1], str_nill);
  5249. ttfd = -1;
  5250. }
  5251. sprintf(buf, "%d", ttfd);
  5252. env_set_var(argv[3], buf);
  5253. tt_free(procId);
  5254. return (0);
  5255. }
  5256. /*
  5257. * This command is used to close a ToolTalk connection.
  5258. */
  5259. int
  5260. do_ttdt_close(
  5261. int argc,
  5262. char *argv[] )
  5263. {
  5264. char * errmsg;
  5265. Boolean sendStopped;
  5266. XrmValue fval, tval;
  5267. Tt_status ttStatus;
  5268. char * statusString;
  5269. char * procId;
  5270. char * newProcId;
  5271. if (argc != 5)
  5272. {
  5273. errmsg = strdup(GETMESSAGE(
  5274. "Usage: ttdt_close status procId newProcId sendStopped"));
  5275. printerr(str_nill, errmsg, NULL);
  5276. free(errmsg);
  5277. return(1);
  5278. }
  5279. /* Need to treat "" equal to a NULL pointer here */
  5280. if (strlen(argv[2]) == 0)
  5281. procId = NULL;
  5282. else
  5283. procId = argv[2];
  5284. /* Need to treat "" equal to a NULL pointer here */
  5285. if (strlen(argv[3]) == 0)
  5286. newProcId = NULL;
  5287. else
  5288. newProcId = argv[3];
  5289. DtkshCvtStringToBool(argv[4], &tval);
  5290. if (tval.size != 0)
  5291. sendStopped = *((Boolean *)(tval.addr));
  5292. else
  5293. return(1);
  5294. ttStatus = ttdt_close(procId, newProcId, (int)sendStopped);
  5295. /* Map the ttStatus into a string */
  5296. DtkshCvtTtStatusToString(ttStatus, &tval);
  5297. if (tval.size && tval.addr)
  5298. statusString = tval.addr;
  5299. else
  5300. statusString = str_nill;
  5301. env_set_var(argv[1], statusString);
  5302. return (0);
  5303. }
  5304. /*
  5305. * This is the alternate input handler command for ToolTalk. Shell scripts
  5306. * will invoke it from their alternate input handlers, passing in all of
  5307. * the required parameters. This input handler will cause ToolTalk events
  5308. * to be received and dispatched.
  5309. */
  5310. int
  5311. do_tttk_Xt_input_handler(
  5312. int argc,
  5313. char *argv[] )
  5314. {
  5315. char * errmsg;
  5316. int source;
  5317. XtInputId fid;
  5318. char * p;
  5319. if (argc != 4)
  5320. {
  5321. errmsg = strdup(GETMESSAGE(
  5322. "Usage: tttk_Xt_input_handler procId source id"));
  5323. printerr(str_nill, errmsg, NULL);
  5324. free(errmsg);
  5325. return(1);
  5326. }
  5327. source = strtoul(argv[2], &p, 0);
  5328. if (p == argv[2])
  5329. {
  5330. errmsg=strdup(GETMESSAGE(
  5331. "The source parameter must be an integer: %s"));
  5332. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  5333. NULL, NULL);
  5334. free(errmsg);
  5335. return(1);
  5336. }
  5337. fid = strtoul(argv[3], &p, 0);
  5338. if (p == argv[3])
  5339. {
  5340. errmsg = strdup(GETMESSAGE(
  5341. "The id parameter must be a hex number: %s"));
  5342. printerrf(argv[0], errmsg, argv[3], NULL, NULL, NULL, NULL, NULL,
  5343. NULL, NULL);
  5344. free(errmsg);
  5345. return(1);
  5346. }
  5347. tttk_Xt_input_handler(argv[1], &source, &fid);
  5348. return (0);
  5349. }
  5350. int
  5351. do_ttdt_session_join(
  5352. int argc,
  5353. char *argv[] )
  5354. {
  5355. char * errmsg;
  5356. Boolean join;
  5357. char * sessId;
  5358. XrmValue fval, tval;
  5359. Tt_status ttStatus;
  5360. char * statusString;
  5361. char buf[25];
  5362. Widget widget;
  5363. wtab_t *w;
  5364. Tt_pattern * patterns;
  5365. if (argc != 6)
  5366. {
  5367. errmsg = strdup(GETMESSAGE(
  5368. "Usage: ttdt_session_join variable status sessId shellWidgetHandle join"
  5369. ));
  5370. printerr(str_nill, errmsg, NULL);
  5371. free(errmsg);
  5372. return(1);
  5373. }
  5374. DtkshCvtStringToBool(argv[5], &tval);
  5375. if (tval.size != 0)
  5376. join = *((Boolean *)(tval.addr));
  5377. else
  5378. return(1);
  5379. /* Need to treat "" equal to a NULL pointer here */
  5380. if (strlen(argv[3]) == 0)
  5381. sessId = NULL;
  5382. else
  5383. sessId = argv[3];
  5384. /* Need to treat "" equal to a NULL pointer here */
  5385. if (strlen(argv[4]) == 0)
  5386. widget = NULL;
  5387. else
  5388. {
  5389. w = str_to_wtab(argv[0], argv[4]);
  5390. if (w == NULL)
  5391. return(1);
  5392. widget = w->w;
  5393. }
  5394. patterns = ttdt_session_join(sessId, NULL, widget, NULL, (int)join);
  5395. ttStatus = tt_ptr_error(patterns);
  5396. /* Map the ttStatus into a string */
  5397. DtkshCvtTtStatusToString(ttStatus, &tval);
  5398. if (tval.size && tval.addr)
  5399. statusString = tval.addr;
  5400. else
  5401. statusString = str_nill;
  5402. env_set_var(argv[2], statusString);
  5403. if (ttStatus == TT_OK)
  5404. {
  5405. sprintf(buf, "%ld", (long)patterns);
  5406. env_set_var(argv[1], buf);
  5407. }
  5408. else
  5409. env_set_var(argv[1], str_nill);
  5410. return (0);
  5411. }
  5412. int
  5413. do_ttdt_session_quit(
  5414. int argc,
  5415. char *argv[] )
  5416. {
  5417. char * errmsg;
  5418. Boolean quit;
  5419. char * sessId;
  5420. XrmValue fval, tval;
  5421. Tt_status ttStatus;
  5422. char * statusString;
  5423. Tt_pattern * patterns;
  5424. char * p;
  5425. if (argc != 5)
  5426. {
  5427. errmsg = strdup(GETMESSAGE(
  5428. "Usage: ttdt_session_quit status sessId sessPatterns quit"));
  5429. printerr(str_nill, errmsg, NULL);
  5430. free(errmsg);
  5431. return(1);
  5432. }
  5433. DtkshCvtStringToBool(argv[4], &tval);
  5434. if (tval.size != 0)
  5435. quit = *((Boolean *)(tval.addr));
  5436. else
  5437. return(1);
  5438. /* Need to treat "" equal to a NULL pointer here */
  5439. if (strlen(argv[2]) == 0)
  5440. sessId = NULL;
  5441. else
  5442. sessId = argv[2];
  5443. /* Need to treat "" equal to a NULL pointer here */
  5444. if (strlen(argv[3]) == 0)
  5445. patterns = NULL;
  5446. else
  5447. {
  5448. patterns = (Tt_pattern *)strtoul(argv[3], &p, 0);
  5449. if (p == argv[3])
  5450. {
  5451. errmsg=strdup(GETMESSAGE(
  5452. "The sessPatterns parameter is invalid: %s"));
  5453. printerrf(argv[0], errmsg, argv[3], NULL, NULL, NULL, NULL, NULL,
  5454. NULL, NULL);
  5455. free(errmsg);
  5456. return(1);
  5457. }
  5458. }
  5459. ttStatus = ttdt_session_quit(sessId, patterns, (int)quit);
  5460. /* Map the ttStatus into a string */
  5461. DtkshCvtTtStatusToString(ttStatus, &tval);
  5462. if (tval.size && tval.addr)
  5463. statusString = tval.addr;
  5464. else
  5465. statusString = str_nill;
  5466. env_set_var(argv[1], statusString);
  5467. return (0);
  5468. }
  5469. int
  5470. do_ttdt_file_event(
  5471. int argc,
  5472. char *argv[] )
  5473. {
  5474. char * errmsg;
  5475. XrmValue fval, tval;
  5476. Tt_status ttStatus;
  5477. char * statusString;
  5478. Boolean send;
  5479. Tt_pattern * patterns;
  5480. Tttk_op op;
  5481. char * p;
  5482. if (argc != 5)
  5483. {
  5484. errmsg = strdup(GETMESSAGE(
  5485. "Usage: ttdt_file_event status op patterns send"));
  5486. printerr(str_nill, errmsg, NULL);
  5487. free(errmsg);
  5488. return(1);
  5489. }
  5490. fval.addr = argv[2];
  5491. fval.size = strlen(argv[2]);
  5492. XtConvert(Toplevel, XtRString, &fval, "TtOp", &tval); /* XXX */
  5493. if (tval.size != 0)
  5494. op = *((Tttk_op *)(tval.addr));
  5495. else
  5496. return(1);
  5497. /* Need to treat "" equal to a NULL pointer here */
  5498. if (strlen(argv[3]) == 0)
  5499. patterns = NULL;
  5500. else
  5501. {
  5502. patterns = (Tt_pattern *)strtoul(argv[3], &p, 0);
  5503. if (p == argv[3])
  5504. {
  5505. errmsg = strdup(GetSharedMsg(DT_BAD_PATTERN));
  5506. printerrf(argv[0], errmsg, argv[3], NULL, NULL, NULL, NULL, NULL,
  5507. NULL, NULL);
  5508. free(errmsg);
  5509. return(1);
  5510. }
  5511. }
  5512. DtkshCvtStringToBool(argv[4], &tval);
  5513. if (tval.size != 0)
  5514. send = *((Boolean *)(tval.addr));
  5515. else
  5516. return(1);
  5517. ttStatus = ttdt_file_event(NULL, op, patterns, (int)send);
  5518. /* Map the ttStatus into a string */
  5519. DtkshCvtTtStatusToString(ttStatus, &tval);
  5520. if (tval.size && tval.addr)
  5521. statusString = tval.addr;
  5522. else
  5523. statusString = str_nill;
  5524. env_set_var(argv[1], statusString);
  5525. return (0);
  5526. }
  5527. /*
  5528. * This is the internal callback invoked by tooltalk, whenever a message
  5529. * is received for a file the user joined (using ttdt_file_join). We
  5530. * need to set up some environment variables, and then interpret the
  5531. * ksh-cmd supplied by the shell script.
  5532. */
  5533. static Tt_message
  5534. TtFileCB(
  5535. Tt_message msg,
  5536. Tttk_op op,
  5537. char * pathName,
  5538. void * clientData,
  5539. int sameEuidEgid,
  5540. int sameProcId )
  5541. {
  5542. Ttdt_file_cb_data *cdata = (Ttdt_file_cb_data *)clientData;
  5543. long int results;
  5544. char strBuf[25];
  5545. Namval_t * msgVar;
  5546. Namval_t * opVar;
  5547. Namval_t * pathVar;
  5548. Namval_t * sameProcVar;
  5549. Namval_t * sameEuidVar;
  5550. XrmValue fval, tval;
  5551. int ttmark = tt_mark();;
  5552. /* Initialize the environment variables */
  5553. msgVar = nv_search("DT_TT_MSG", sh.var_tree, NV_ADD);
  5554. sprintf(strBuf, "%ld", (long)msg);
  5555. nv_putval(msgVar, strBuf, NV_RDONLY);
  5556. opVar = nv_search("DT_TT_OP", sh.var_tree, NV_ADD);
  5557. fval.addr = (caddr_t)&op;
  5558. fval.size = sizeof(op);
  5559. XtConvert(Toplevel, "TtOp", &fval, XtRString, &tval); /* XXX?? */
  5560. if (tval.size && tval.addr)
  5561. nv_putval(opVar, (char *)tval.addr, NV_RDONLY);
  5562. else
  5563. nv_putval(opVar, str_nill, NV_RDONLY);
  5564. pathVar = nv_search("DT_TT_PATHNAME", sh.var_tree, NV_ADD);
  5565. nv_putval(pathVar, pathName, NV_RDONLY);
  5566. sameProcVar = nv_search("DT_TT_SAME_PROCID", sh.var_tree, NV_ADD);
  5567. if (sameProcId)
  5568. nv_putval(sameProcVar, "True", NV_RDONLY);
  5569. else
  5570. nv_putval(sameProcVar, "False", NV_RDONLY);
  5571. sameEuidVar = nv_search("DT_TT_SAME_EUID_EGID", sh.var_tree, NV_ADD);
  5572. if (sameProcId)
  5573. nv_putval(sameEuidVar, "True", NV_RDONLY);
  5574. else
  5575. nv_putval(sameEuidVar, "False", NV_RDONLY);
  5576. /* Interpret the registered command */
  5577. results = ksh_eval((char *)cdata->ksh_cmd);
  5578. /* Clean up the environment variables */
  5579. nv_newattr(msgVar, 0, 0);
  5580. nv_close(msgVar);
  5581. nv_newattr(opVar, 0, 0);
  5582. nv_close(opVar);
  5583. nv_newattr(pathVar, 0, 0);
  5584. nv_close(pathVar);
  5585. nv_newattr(sameProcVar, 0, 0);
  5586. nv_close(sameProcVar);
  5587. nv_newattr(sameEuidVar, 0, 0);
  5588. nv_close(sameEuidVar);
  5589. tt_release(ttmark);
  5590. return((Tt_message)results);
  5591. }
  5592. int
  5593. do_ttdt_file_join(
  5594. int argc,
  5595. char *argv[] )
  5596. {
  5597. char * errmsg;
  5598. XrmValue fval, tval;
  5599. Tt_status ttStatus;
  5600. char * statusString;
  5601. Boolean join;
  5602. Tt_scope scope;
  5603. Tt_pattern * patterns;
  5604. Ttdt_file_cb_data * cData;
  5605. char buf[30];
  5606. int i, j;
  5607. if (argc != 7)
  5608. {
  5609. errmsg = strdup(GETMESSAGE(
  5610. "Usage: ttdt_file_join variable status pathName scope join ksh-command"));
  5611. printerr(str_nill, errmsg, NULL);
  5612. free(errmsg);
  5613. return(1);
  5614. }
  5615. DtkshCvtStringToBool(argv[5], &tval);
  5616. if (tval.size != 0)
  5617. join = *((Boolean *)(tval.addr));
  5618. else
  5619. return(1);
  5620. fval.addr = argv[4];
  5621. fval.size = strlen(argv[4]);
  5622. XtConvert(Toplevel, XtRString, &fval, "TtScope", &tval); /* XXX ??? */
  5623. if (tval.size != 0)
  5624. scope = *((Tt_scope *)(tval.addr));
  5625. else
  5626. return(1);
  5627. cData = (Ttdt_file_cb_data *)XtMalloc(sizeof(Ttdt_file_cb_data));
  5628. patterns = ttdt_file_join(argv[3], scope, (int)join, TtFileCB, cData);
  5629. ttStatus = tt_ptr_error(patterns);
  5630. /* Map the ttStatus into a string */
  5631. DtkshCvtTtStatusToString(ttStatus, &tval);
  5632. if (tval.size && tval.addr)
  5633. statusString = tval.addr;
  5634. else
  5635. statusString = str_nill;
  5636. env_set_var(argv[2], statusString);
  5637. /*
  5638. * If the request failed, then no callback was added, so we can free
  5639. * up the client data; otherwise, we need to finish filling in the
  5640. * client data, and then saving it in our storage array, so that we
  5641. * can later free it when ttdt_file_quit() is called.
  5642. */
  5643. if (ttStatus == TT_OK)
  5644. {
  5645. sprintf(buf, "%ld", (long)patterns);
  5646. env_set_var(argv[1], buf);
  5647. cData->ksh_cmd = strdup(argv[6]);
  5648. cData->patterns = patterns;
  5649. /* Add clientData to our storage array */
  5650. for (i = 0; i < sizeFileCBList; i++)
  5651. {
  5652. if (fileCBList[i] == NULL)
  5653. break;
  5654. }
  5655. if (i >= sizeFileCBList)
  5656. {
  5657. /* Grow the array */
  5658. sizeFileCBList += 10;
  5659. fileCBList = (Ttdt_file_cb_data **)XtRealloc((char *)fileCBList,
  5660. sizeof(Ttdt_file_cb_data *) * sizeFileCBList);
  5661. for (j = i; j < sizeFileCBList; j++)
  5662. fileCBList[j] = NULL;
  5663. }
  5664. fileCBList[i] = cData;
  5665. }
  5666. else
  5667. {
  5668. XtFree((char *)cData);
  5669. env_set_var(argv[1], str_nill);
  5670. }
  5671. return (0);
  5672. }
  5673. int
  5674. do_ttdt_file_quit(
  5675. int argc,
  5676. char *argv[] )
  5677. {
  5678. char * errmsg;
  5679. XrmValue fval, tval;
  5680. Tt_status ttStatus;
  5681. char * statusString;
  5682. Boolean quit;
  5683. Tt_pattern * patterns;
  5684. char * p;
  5685. int i;
  5686. if (argc != 4)
  5687. {
  5688. errmsg = strdup(GETMESSAGE(
  5689. "Usage: ttdt_file_quit status patterns quit"));
  5690. printerr(str_nill, errmsg, NULL);
  5691. free(errmsg);
  5692. return(1);
  5693. }
  5694. /* Need to treat "" equal to a NULL pointer here */
  5695. if (strlen(argv[2]) == 0)
  5696. patterns = NULL;
  5697. else
  5698. {
  5699. patterns = (Tt_pattern *)strtoul(argv[2], &p, 0);
  5700. if (p == argv[2])
  5701. {
  5702. errmsg = strdup(GetSharedMsg(DT_BAD_PATTERN));
  5703. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  5704. NULL, NULL);
  5705. free(errmsg);
  5706. return(1);
  5707. }
  5708. }
  5709. DtkshCvtStringToBool(argv[3], &tval);
  5710. if (tval.size != 0)
  5711. quit = *((Boolean *)(tval.addr));
  5712. else
  5713. return(1);
  5714. ttStatus = ttdt_file_quit(patterns, (int)quit);
  5715. /* Remove this entry from our list of file callbacks */
  5716. for (i = 0; i < sizeFileCBList; i++)
  5717. {
  5718. if (fileCBList[i] && (fileCBList[i]->patterns == patterns))
  5719. {
  5720. XtFree(fileCBList[i]->ksh_cmd);
  5721. XtFree((char *)fileCBList[i]);
  5722. fileCBList[i] = NULL;
  5723. break;
  5724. }
  5725. }
  5726. /* Map the ttStatus into a string */
  5727. DtkshCvtTtStatusToString(ttStatus, &tval);
  5728. if (tval.size && tval.addr)
  5729. statusString = tval.addr;
  5730. else
  5731. statusString = str_nill;
  5732. env_set_var(argv[1], statusString);
  5733. return (0);
  5734. }
  5735. int
  5736. do_ttdt_Get_Modified(
  5737. int argc,
  5738. char *argv[] )
  5739. {
  5740. char * errmsg;
  5741. XrmValue fval, tval;
  5742. Tt_scope scope;
  5743. int timeout;
  5744. char * p;
  5745. if (argc != 4)
  5746. {
  5747. errmsg = strdup(GETMESSAGE(
  5748. "Usage: ttdt_Get_Modified pathName scope timeout"));
  5749. printerr(str_nill, errmsg, NULL);
  5750. free(errmsg);
  5751. return(1);
  5752. }
  5753. fval.addr = argv[2];
  5754. fval.size = strlen(argv[2]);
  5755. XtConvert(Toplevel, XtRString, &fval, "TtScope", &tval); /* XXX ?? */
  5756. if (tval.size != 0)
  5757. scope = *((Tt_scope *)(tval.addr));
  5758. else
  5759. return(1);
  5760. timeout = strtoul(argv[3], &p, 0);
  5761. if (p == argv[3])
  5762. {
  5763. errmsg = strdup(GetSharedMsg(DT_BAD_TIMEOUT));
  5764. printerrf(argv[0], errmsg, argv[3], NULL, NULL, NULL, NULL, NULL,
  5765. NULL, NULL);
  5766. free(errmsg);
  5767. return(1);
  5768. }
  5769. if (ttdt_Get_Modified(NULL, argv[1], scope,
  5770. XtWidgetToApplicationContext(Toplevel), timeout))
  5771. {
  5772. return(0);
  5773. }
  5774. return(255);
  5775. }
  5776. /*
  5777. * Common function for ttdt_Save and ttdt_Revert commands.
  5778. */
  5779. static int
  5780. ttdt_SaveOrRevert(
  5781. Tt_status (*func)(),
  5782. int argc,
  5783. char *argv[] )
  5784. {
  5785. char * errmsg;
  5786. XrmValue fval, tval;
  5787. Tt_scope scope;
  5788. int timeout;
  5789. char * p;
  5790. Tt_status ttStatus;
  5791. char * statusString;
  5792. if (argc != 5)
  5793. {
  5794. errmsg = strdup(GETMESSAGE(
  5795. "Usage: %s status pathName scope timeout"));
  5796. printerrf(str_nill, errmsg, argv[0], NULL, NULL, NULL, NULL, NULL,
  5797. NULL, NULL);
  5798. free(errmsg);
  5799. return(1);
  5800. }
  5801. fval.addr = argv[3];
  5802. fval.size = strlen(argv[3]);
  5803. XtConvert(Toplevel, XtRString, &fval, "TtScope", &tval); /* XXX ?? */
  5804. if (tval.size != 0)
  5805. scope = *((Tt_scope *)(tval.addr));
  5806. else
  5807. return(1);
  5808. timeout = strtoul(argv[4], &p, 0);
  5809. if (p == argv[4])
  5810. {
  5811. errmsg = strdup(GetSharedMsg(DT_BAD_TIMEOUT));
  5812. printerrf(argv[0], errmsg, argv[4], NULL, NULL, NULL, NULL, NULL,
  5813. NULL, NULL);
  5814. free(errmsg);
  5815. return(1);
  5816. }
  5817. ttStatus = (*func)(NULL, argv[2], scope,
  5818. XtWidgetToApplicationContext(Toplevel), timeout);
  5819. /* Map the ttStatus into a string */
  5820. DtkshCvtTtStatusToString(ttStatus, &tval);
  5821. if (tval.size && tval.addr)
  5822. statusString = tval.addr;
  5823. else
  5824. statusString = str_nill;
  5825. env_set_var(argv[1], statusString);
  5826. return(0);
  5827. }
  5828. int
  5829. do_ttdt_Save(
  5830. int argc,
  5831. char *argv[] )
  5832. {
  5833. return(ttdt_SaveOrRevert(ttdt_Save, argc, argv ));
  5834. }
  5835. int
  5836. do_ttdt_Revert(
  5837. int argc,
  5838. char *argv[] )
  5839. {
  5840. return(ttdt_SaveOrRevert(ttdt_Revert, argc, argv ));
  5841. }
  5842. int
  5843. do_tt_error_pointer(
  5844. int argc,
  5845. char *argv[] )
  5846. {
  5847. char * errmsg;
  5848. XrmValue fval, tval;
  5849. Tt_status ttStatus;
  5850. void * errPtr;
  5851. char buf[25];
  5852. if (argc != 3)
  5853. {
  5854. errmsg = strdup(GETMESSAGE(
  5855. "Usage: tt_error_pointer variable ttStatus"));
  5856. printerr(str_nill, errmsg, NULL);
  5857. free(errmsg);
  5858. return(1);
  5859. }
  5860. /* Map the string into a ttStatus */
  5861. DtkshCvtStringToTtStatus(argv[2], &tval);
  5862. if (tval.size != 0)
  5863. ttStatus = *((Tt_status *)(tval.addr));
  5864. else
  5865. return(1);
  5866. errPtr = tt_error_pointer(ttStatus);
  5867. sprintf(buf, "%ld", (long)errPtr);
  5868. alt_env_set_var(argv[1], buf);
  5869. return (0);
  5870. }
  5871. static int
  5872. message_DestroyOrReply(
  5873. Tt_status (*func)(),
  5874. int argc,
  5875. char *argv[] )
  5876. {
  5877. char * errmsg;
  5878. XrmValue fval, tval;
  5879. Tt_status ttStatus;
  5880. char * statusString;
  5881. Tt_message message;
  5882. char * p;
  5883. if (argc != 3)
  5884. {
  5885. errmsg = strdup(GETMESSAGE("Usage: %s status msg"));
  5886. printerrf(str_nill, errmsg, argv[0], NULL, NULL, NULL, NULL, NULL,
  5887. NULL, NULL);
  5888. free(errmsg);
  5889. return(1);
  5890. }
  5891. message = (Tt_message)strtoul(argv[2], &p, 0);
  5892. if (p == argv[2])
  5893. {
  5894. errmsg = strdup(GetSharedMsg(DT_BAD_MESSAGE));
  5895. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  5896. NULL, NULL);
  5897. free(errmsg);
  5898. return(1);
  5899. }
  5900. ttStatus = (*func)(message);
  5901. /* Map the ttStatus into a string */
  5902. DtkshCvtTtStatusToString(ttStatus, &tval);
  5903. if (tval.size && tval.addr)
  5904. statusString = tval.addr;
  5905. else
  5906. statusString = str_nill;
  5907. env_set_var(argv[1], statusString);
  5908. return (0);
  5909. }
  5910. int
  5911. do_tttk_message_destroy(
  5912. int argc,
  5913. char *argv[] )
  5914. {
  5915. return(message_DestroyOrReply(tttk_message_destroy, argc, argv));
  5916. }
  5917. int
  5918. do_tt_message_reply(
  5919. int argc,
  5920. char *argv[] )
  5921. {
  5922. return(message_DestroyOrReply(tt_message_reply, argc, argv));
  5923. }
  5924. static int
  5925. message_FailOrReject(
  5926. Tt_status (*func)(),
  5927. int argc,
  5928. char *argv[] )
  5929. {
  5930. char * errmsg;
  5931. XrmValue fval, tval;
  5932. Tt_status ttStatus;
  5933. char * statusString;
  5934. Tt_message message;
  5935. char * msgStatusString;
  5936. Boolean destroy;
  5937. char * p;
  5938. if (argc != 6)
  5939. {
  5940. errmsg = strdup(GETMESSAGE(
  5941. "Usage: %s status msg msgStatus msgStatusString destroy"));
  5942. printerrf(str_nill, errmsg, argv[0], NULL, NULL, NULL, NULL, NULL,
  5943. NULL, NULL);
  5944. free(errmsg);
  5945. return(1);
  5946. }
  5947. message = (Tt_message)strtoul(argv[2], &p, 0);
  5948. if (p == argv[2])
  5949. {
  5950. errmsg = strdup(GetSharedMsg(DT_BAD_MESSAGE));
  5951. printerrf(argv[0], errmsg, argv[2], NULL, NULL, NULL, NULL, NULL,
  5952. NULL, NULL);
  5953. free(errmsg);
  5954. return(1);
  5955. }
  5956. /* Map the string into a ttStatus */
  5957. DtkshCvtStringToTtStatus(argv[3], &tval);
  5958. if (tval.size != 0)
  5959. ttStatus = *((Tt_status *)(tval.addr));
  5960. else
  5961. return(1);
  5962. /* Need to treat "" equal to a NULL pointer here */
  5963. if (strlen(argv[4]) == 0)
  5964. msgStatusString = NULL;
  5965. else
  5966. msgStatusString = argv[4];
  5967. /* Convert the boolean value */
  5968. DtkshCvtStringToBool(argv[5], &tval);
  5969. if (tval.size != 0)
  5970. destroy = *((Boolean *)(tval.addr));
  5971. else
  5972. return(1);
  5973. ttStatus = (*func)(message, ttStatus, msgStatusString, destroy);
  5974. /* Map the ttStatus into a string */
  5975. DtkshCvtTtStatusToString(ttStatus, &tval);
  5976. if (tval.size && tval.addr)
  5977. statusString = tval.addr;
  5978. else
  5979. statusString = str_nill;
  5980. env_set_var(argv[1], statusString);
  5981. return (0);
  5982. }
  5983. int
  5984. do_tttk_message_reject(
  5985. int argc,
  5986. char *argv[] )
  5987. {
  5988. return(message_FailOrReject(tttk_message_reject, argc, argv));
  5989. }
  5990. int
  5991. do_tttk_message_fail(
  5992. int argc,
  5993. char *argv[] )
  5994. {
  5995. return(message_FailOrReject(tttk_message_fail, argc, argv));
  5996. }
  5997. static int
  5998. tt_netfile_handler(
  5999. int paramCount,
  6000. char * (*func)(),
  6001. char * usageMsg,
  6002. int argc,
  6003. char *argv[] )
  6004. {
  6005. XrmValue fval, tval;
  6006. Tt_status ttStatus;
  6007. char * statusString;
  6008. char * convertedName;
  6009. Cardinal cargc;
  6010. XrmValue cargv[1];
  6011. if (argc != paramCount)
  6012. {
  6013. printerr(str_nill, usageMsg, NULL);
  6014. return(1);
  6015. }
  6016. if (paramCount == 4)
  6017. convertedName = (char *)(*func)(argv[3]);
  6018. else
  6019. convertedName = (char *)(*func)(argv[3], argv[4]);
  6020. /*
  6021. * Map the ttStatus into a string. Note that we can't call the XtConvert
  6022. * function, since a shell script may not have called XtInitialize.
  6023. */
  6024. ttStatus = tt_ptr_error(convertedName);
  6025. DtkshCvtTtStatusToString(ttStatus, &tval);
  6026. if (ttStatus == TT_OK)
  6027. env_set_var(argv[1], convertedName);
  6028. else
  6029. env_set_var(argv[1], str_nill);
  6030. if (tval.size && tval.addr)
  6031. statusString = tval.addr;
  6032. else
  6033. statusString = str_nill;
  6034. env_set_var(argv[2], statusString);
  6035. tt_free(convertedName);
  6036. return (0);
  6037. }
  6038. int
  6039. do_tt_file_netfile(
  6040. int argc,
  6041. char *argv[] )
  6042. {
  6043. char * usageMsg;
  6044. int results;
  6045. usageMsg = strdup(GETMESSAGE(
  6046. "Usage: tt_file_netfile variable status filename"));
  6047. results = tt_netfile_handler(4, tt_file_netfile, usageMsg, argc, argv);
  6048. XtFree(usageMsg);
  6049. return(results);
  6050. }
  6051. int
  6052. do_tt_netfile_file(
  6053. int argc,
  6054. char *argv[] )
  6055. {
  6056. char * usageMsg;
  6057. int results;
  6058. usageMsg = strdup(GETMESSAGE(
  6059. "Usage: tt_netfile_file variable status netfilename"));
  6060. results = tt_netfile_handler(4, tt_netfile_file, usageMsg, argc, argv);
  6061. XtFree(usageMsg);
  6062. return(results);
  6063. }
  6064. int
  6065. do_tt_host_file_netfile(
  6066. int argc,
  6067. char *argv[] )
  6068. {
  6069. char * usageMsg;
  6070. int results;
  6071. usageMsg = strdup(GETMESSAGE(
  6072. "Usage: tt_host_file_netfile variable status host filename"));
  6073. results = tt_netfile_handler(5, tt_host_file_netfile, usageMsg, argc, argv);
  6074. XtFree(usageMsg);
  6075. return(results);
  6076. }
  6077. int
  6078. do_tt_host_netfile_file(
  6079. int argc,
  6080. char *argv[] )
  6081. {
  6082. char * usageMsg;
  6083. int results;
  6084. usageMsg = strdup(GETMESSAGE(
  6085. "Usage: tt_host_netfile_file variable status host netfilename"));
  6086. results = tt_netfile_handler(5, tt_host_netfile_file, usageMsg, argc, argv);
  6087. XtFree(usageMsg);
  6088. return(results);
  6089. }
  6090. /*****************************************************************************/
  6091. /*****************************************************************************/
  6092. /*
  6093. * Starting with the class of the widget, check to see if it defines the
  6094. * indicated callback; if not, then keep checking its superclasses.
  6095. */
  6096. static Namdisc_t *
  6097. CheckClassDisciplines(
  6098. WidgetClass class,
  6099. char *cbname )
  6100. {
  6101. int i = 0;
  6102. int j = 0;
  6103. while (C[i].cname)
  6104. {
  6105. if (C[i].class == class)
  6106. {
  6107. if (C[i].disciplines)
  6108. {
  6109. while(C[i].disciplines[j].callbackName)
  6110. {
  6111. if (strcmp(cbname, C[i].disciplines[j].callbackName) == 0)
  6112. return(C[i].disciplines[j].discipline);
  6113. j++;
  6114. }
  6115. }
  6116. }
  6117. i++;
  6118. }
  6119. return(NULL);
  6120. }
  6121. /*****************************************************************************/
  6122. /*****************************************************************************/
  6123. /*
  6124. * The following collection of functions deal with handling the dynamic
  6125. * setting of an environment variable, when referenced by the shell script.
  6126. * All of the environment variables are based off of the CB_CALL_DATA
  6127. * environment variable, which is set before the shell script's callback
  6128. * is invoked. After the shell script's callback returns, any dynamically
  6129. * created environment variable are removed; thus, the scope is only
  6130. * within the context of the callback.
  6131. *
  6132. * If the shell script attempts to reference a subfield of the CB_CALL_DATA,
  6133. * and if the parent has not yet been reference, then the 'name' passed to
  6134. * the discipline function will contain all of the previously unreferenced
  6135. * portions of the environment variable name. As an example, if the shell
  6136. * script referenced ${CB_CALL_DATA.EVENT.TYPE} , and the "EVENT" portion
  6137. * has not yet been referenced, then the incoming name will be "EVENT.TYPE".
  6138. * This is why all of the discipline functions below use "strtok()"; this
  6139. * allows us to break up the name into each token, and to then initialize
  6140. * the token. Any unrecognized tokens are set to the string "". In the
  6141. * above example, a new name/value pair will be created for both the
  6142. * "EVENT" and the "TYPE" portions, and the returned name/value pair will
  6143. * be for the "TYPE" portion, since it was the terminal portion of the
  6144. * reference.
  6145. */
  6146. static struct named_integer CallbackReasons[] = {
  6147. { "CR_NONE", XmCR_NONE },
  6148. { "CR_HELP", XmCR_HELP },
  6149. { "CR_VALUE_CHANGED", XmCR_VALUE_CHANGED },
  6150. { "CR_INCREMENT", XmCR_INCREMENT },
  6151. { "CR_DECREMENT", XmCR_DECREMENT },
  6152. { "CR_PAGE_INCREMENT", XmCR_PAGE_INCREMENT },
  6153. { "CR_PAGE_DECREMENT", XmCR_PAGE_DECREMENT },
  6154. { "CR_TO_TOP", XmCR_TO_TOP },
  6155. { "CR_TO_BOTTOM", XmCR_TO_BOTTOM },
  6156. { "CR_DRAG", XmCR_DRAG },
  6157. { "CR_ACTIVATE", XmCR_ACTIVATE },
  6158. { "CR_ARM", XmCR_ARM },
  6159. { "CR_DISARM", XmCR_DISARM },
  6160. { "CR_MAP", XmCR_MAP },
  6161. { "CR_UNMAP", XmCR_UNMAP },
  6162. { "CR_FOCUS", XmCR_FOCUS },
  6163. { "CR_LOSING_FOCUS", XmCR_LOSING_FOCUS },
  6164. { "CR_MODIFYING_TEXT_VALUE", XmCR_MODIFYING_TEXT_VALUE },
  6165. { "CR_MOVING_INSERT_CURSOR", XmCR_MOVING_INSERT_CURSOR },
  6166. { "CR_EXECUTE", XmCR_EXECUTE },
  6167. { "CR_SINGLE_SELECT", XmCR_SINGLE_SELECT },
  6168. { "CR_MULTIPLE_SELECT", XmCR_MULTIPLE_SELECT },
  6169. { "CR_EXTENDED_SELECT", XmCR_EXTENDED_SELECT },
  6170. { "CR_BROWSE_SELECT", XmCR_BROWSE_SELECT },
  6171. { "CR_DEFAULT_ACTION", XmCR_DEFAULT_ACTION },
  6172. { "CR_CLIPBOARD_DATA_REQUEST", XmCR_CLIPBOARD_DATA_REQUEST },
  6173. { "CR_CLIPBOARD_DATA_DELETE", XmCR_CLIPBOARD_DATA_DELETE },
  6174. { "CR_CASCADING", XmCR_CASCADING },
  6175. { "CR_OK", XmCR_OK },
  6176. { "CR_CANCEL", XmCR_CANCEL },
  6177. { "CR_APPLY", XmCR_APPLY },
  6178. { "CR_NO_MATCH", XmCR_NO_MATCH },
  6179. { "CR_COMMAND_ENTERED", XmCR_COMMAND_ENTERED },
  6180. { "CR_COMMAND_CHANGED", XmCR_COMMAND_CHANGED },
  6181. { "CR_EXPOSE", XmCR_EXPOSE },
  6182. { "CR_RESIZE", XmCR_RESIZE },
  6183. { "CR_INPUT", XmCR_INPUT },
  6184. { "CR_GAIN_PRIMARY", XmCR_GAIN_PRIMARY },
  6185. { "CR_LOSE_PRIMARY", XmCR_LOSE_PRIMARY },
  6186. { "CR_CREATE", XmCR_CREATE },
  6187. { "CR_TEAR_OFF_ACTIVATE", XmCR_TEAR_OFF_ACTIVATE },
  6188. { "CR_TEAR_OFF_DEACTIVATE", XmCR_TEAR_OFF_DEACTIVATE },
  6189. { "CR_OBSCURED_TRAVERSAL", XmCR_OBSCURED_TRAVERSAL },
  6190. { "CR_PROTOCOLS", 6666 },
  6191. { NULL, 0 },
  6192. };
  6193. static struct named_integer HelpCallbackReasons[] = {
  6194. { "HELP_CR_CLOSE", DtCR_HELP_CLOSE },
  6195. { "HELP_CR_LINK_ACTIVATE", DtCR_HELP_LINK_ACTIVATE },
  6196. { NULL, 0 },
  6197. };
  6198. /*
  6199. * Create a new name/value pair (if necessary), and add it to the list of
  6200. * name/value pairs which must be cleaned up when we are done.
  6201. */
  6202. Namval_t *
  6203. GetNameValuePair(
  6204. char *name )
  6205. {
  6206. Namval_t * np2;
  6207. Namval_t** list;
  6208. int i;
  6209. if (((np2 = nv_search(name, sh.var_tree, 0)) == NULL) ||
  6210. (nestingLevel == 0))
  6211. {
  6212. /* Add to the list only the first time referenced */
  6213. if (nestingLevel + 1 > npTableSize)
  6214. {
  6215. npTable = (Namval_t ***)XtRealloc((char *)npTable,
  6216. sizeof(Namval_t **) * (nestingLevel+1));
  6217. npListSizes = (int *)XtRealloc((char *)npListSizes,
  6218. sizeof(int) * (nestingLevel+1));
  6219. for (i = npTableSize; i < (nestingLevel + 1); i++)
  6220. {
  6221. npTable[i] = NULL;
  6222. npListSizes[i] = 0;
  6223. }
  6224. npTableSize = nestingLevel + 1;
  6225. }
  6226. np2 = nv_search(name, sh.var_tree, NV_ADD);
  6227. (npListSizes[nestingLevel])++;
  6228. list = npTable[nestingLevel] = (Namval_t **)XtRealloc(
  6229. (char *)npTable[nestingLevel],
  6230. sizeof(Namval_t *) * npListSizes[nestingLevel]);
  6231. list[npListSizes[nestingLevel] - 1] = np2;
  6232. /*
  6233. * I _think_ this works OK, because I _think_ the subshell code will
  6234. * automatically clean up the "extra" Namval_t it might create here.
  6235. * As long as we clean up the original, I don't think we leak here.
  6236. */
  6237. if(sh.subshell)
  6238. np2 = sh_assignok(np2, 1);
  6239. }
  6240. return(np2);
  6241. }
  6242. /*
  6243. * Free only those environment variables created at this nesting level.
  6244. */
  6245. void
  6246. FreeNestedVariables( void )
  6247. {
  6248. Namval_t** list;
  6249. int i;
  6250. if ((nestingLevel < 0) || (nestingLevel >= npTableSize))
  6251. return;
  6252. list = npTable[nestingLevel];
  6253. for (i = 0; i < npListSizes[nestingLevel]; i++)
  6254. {
  6255. nv_newattr(list[i], 0, 0);
  6256. nv_stack(list[i], NULL);
  6257. nv_close(list[i]);
  6258. }
  6259. XtFree((char *)list);
  6260. npTable[nestingLevel] = NULL;
  6261. npListSizes[nestingLevel] = 0;
  6262. }
  6263. /*
  6264. * Create an empty name/value pair.
  6265. * THIS FUNCTION ASSUMES THAT THE CALLER HAS DONE THE INITIAL strtok()
  6266. * CALL, SO THAT WE CAN DO THE REMAINING ONES, TO INITIALIZE ALL REMAINING
  6267. * TOKENS.
  6268. */
  6269. static Namval_t *
  6270. CreateEmptyNameValuePair(
  6271. Namval_t *np,
  6272. char *name,
  6273. Namfun_t *fp )
  6274. {
  6275. Namval_t * np2;
  6276. char buf[128];
  6277. np2 = GetNameValuePair(name);
  6278. buf[0] = '\0';
  6279. nv_putval(np2, buf, NV_RDONLY);
  6280. if (name = strtok(NULL, "."))
  6281. return(CreateEmptyNameValuePair(np, name, fp));
  6282. else
  6283. return(np2);
  6284. }
  6285. static Namval_t *
  6286. ProcessIntValue(
  6287. int value,
  6288. Namval_t *np,
  6289. char *name,
  6290. Namfun_t *fp,
  6291. char *format,
  6292. Namfun_t *fp_new)
  6293. {
  6294. Namval_t * np2;
  6295. char buf[128];
  6296. np2 = GetNameValuePair(name);
  6297. sprintf(buf, format, value);
  6298. nv_stack(np2, NULL);
  6299. nv_putval(np2, buf, NV_RDONLY);
  6300. if (fp_new)
  6301. nv_stack(np2, fp_new);
  6302. if (name = strtok(NULL, "."))
  6303. np2 = CreateEmptyNameValuePair(np, name, fp);
  6304. return(np2);
  6305. }
  6306. static Namval_t *
  6307. ProcessStringValue(
  6308. char *value,
  6309. Namval_t *np,
  6310. char *name,
  6311. Namfun_t *fp )
  6312. {
  6313. Namval_t * np2;
  6314. np2 = GetNameValuePair(name);
  6315. if (value)
  6316. nv_putval(np2, value, NV_RDONLY);
  6317. else
  6318. nv_putval(np2, str_nill, NV_RDONLY);
  6319. if (name = strtok(NULL, "."))
  6320. np2 = CreateEmptyNameValuePair(np, name, fp);
  6321. return(np2);
  6322. }
  6323. static Namval_t *
  6324. ProcessBooleanIntValue(
  6325. int value,
  6326. Namval_t *np,
  6327. char *name,
  6328. Namfun_t *fp,
  6329. Namfun_t *fp_new )
  6330. {
  6331. Namval_t * np2;
  6332. char buf[128];
  6333. np2 = GetNameValuePair(name);
  6334. if (value)
  6335. strcpy(buf, "true");
  6336. else
  6337. strcpy(buf, "false");
  6338. /*
  6339. * Any old disciplies MUST be cleared, before setting value. If this
  6340. * is not done, then excessive looping occurs, and the value will not
  6341. * be correct, the next time you retrieve it.
  6342. */
  6343. nv_stack(np2, NULL);
  6344. nv_putval(np2, buf, NV_RDONLY);
  6345. if (fp_new)
  6346. nv_stack(np2, fp_new);
  6347. if (name = strtok(NULL, "."))
  6348. np2 = CreateEmptyNameValuePair(np, name, fp);
  6349. return(np2);
  6350. }
  6351. static Namval_t *
  6352. ProcessTraversalDirection(
  6353. XmTraversalDirection dir,
  6354. Namval_t *np,
  6355. char *name,
  6356. Namfun_t *fp )
  6357. {
  6358. Namval_t * np2;
  6359. char buf[128];
  6360. XrmValue f, t;
  6361. char * value;
  6362. np2 = GetNameValuePair(name);
  6363. f.addr = (caddr_t)&dir;
  6364. f.size = sizeof(XmTraversalDirection);
  6365. t.addr = NULL;
  6366. t.size = 0;
  6367. XtConvert(Toplevel, "TraversalDirection", &f, XtRString, &t);
  6368. if (t.size && t.addr)
  6369. value = t.addr;
  6370. else
  6371. value = str_nill;
  6372. strcpy(buf, value);
  6373. nv_putval(np2, buf, NV_RDONLY);
  6374. if (name = strtok(NULL, "."))
  6375. np2 = CreateEmptyNameValuePair(np, name, fp);
  6376. return(np2);
  6377. }
  6378. static Namval_t *
  6379. ProcessSelectionType(
  6380. char selType,
  6381. Namval_t *np,
  6382. char *name,
  6383. Namfun_t *fp )
  6384. {
  6385. Namval_t * np2;
  6386. char buf[128];
  6387. XrmValue f, t;
  6388. char * value;
  6389. int tmpSelType = (int)selType;
  6390. np2 = GetNameValuePair(name);
  6391. f.addr = (caddr_t)&tmpSelType;
  6392. f.size = sizeof(int);
  6393. t.addr = NULL;
  6394. t.size = 0;
  6395. XtConvert(Toplevel, "ListSelectionType", &f, XtRString, &t);
  6396. if (t.size && t.addr)
  6397. value = t.addr;
  6398. else
  6399. value = str_nill;
  6400. strcpy(buf, value);
  6401. nv_putval(np2, buf, NV_RDONLY);
  6402. if (name = strtok(NULL, "."))
  6403. np2 = CreateEmptyNameValuePair(np, name, fp);
  6404. return(np2);
  6405. }
  6406. static Namval_t *
  6407. ProcessIntTable(
  6408. int *table,
  6409. int count,
  6410. Namval_t *np,
  6411. char *name,
  6412. Namfun_t *fp )
  6413. {
  6414. Namval_t * np2;
  6415. char * buf;
  6416. char buf2[25];
  6417. int i;
  6418. buf = XtMalloc(1);
  6419. buf[0] = '\0';
  6420. np2 = GetNameValuePair(name);
  6421. if (count > 0)
  6422. {
  6423. for (i = 0; i < count; i++)
  6424. {
  6425. sprintf(buf2, "%d", table[i]);
  6426. buf = XtRealloc(buf, strlen(buf) + strlen(buf2) + (i == 0 ? 1 : 2));
  6427. if (i != 0)
  6428. strcat(buf, ",");
  6429. strcat(buf, buf2);
  6430. }
  6431. }
  6432. nv_putval(np2, buf, NV_RDONLY);
  6433. XtFree (buf);
  6434. if (name = strtok(NULL, "."))
  6435. np2 = CreateEmptyNameValuePair(np, name, fp);
  6436. return(np2);
  6437. }
  6438. static Namval_t *
  6439. ProcessXmStringTable(
  6440. XmString *table,
  6441. int count,
  6442. Namval_t *np,
  6443. char *name,
  6444. Namfun_t *fp )
  6445. {
  6446. Namval_t * np2;
  6447. char * buf;
  6448. int i;
  6449. np2 = GetNameValuePair(name);
  6450. buf = _CvtXmStringTableToString(table, count);
  6451. nv_putval(np2, buf, NV_RDONLY);
  6452. if (name = strtok(NULL, "."))
  6453. np2 = CreateEmptyNameValuePair(np, name, fp);
  6454. return(np2);
  6455. }
  6456. static Namval_t *
  6457. ProcessWidgetHandle(
  6458. Widget handle,
  6459. Namval_t *np,
  6460. char *name,
  6461. Namfun_t *fp )
  6462. {
  6463. Namval_t * np2;
  6464. char buf[128];
  6465. wtab_t * w;
  6466. np2 = GetNameValuePair(name);
  6467. w = widget_to_wtab(handle);
  6468. strcpy(buf, w ? w->widid : "Unknown");
  6469. nv_putval(np2, buf, NV_RDONLY);
  6470. if (name = strtok(NULL, "."))
  6471. np2 = CreateEmptyNameValuePair(np, name, fp);
  6472. return(np2);
  6473. }
  6474. static Namval_t *
  6475. ProcessXmStringValue(
  6476. XmString xmstring,
  6477. Namval_t *np,
  6478. char *name,
  6479. Namfun_t *fp )
  6480. {
  6481. Namval_t * np2;
  6482. char buf[128];
  6483. wtab_t * w;
  6484. char * value;
  6485. np2 = GetNameValuePair(name);
  6486. if ((value = XmStringToString(xmstring)) == NULL)
  6487. value = str_nill;
  6488. nv_putval(np2, value, NV_RDONLY);
  6489. if (name = strtok(NULL, "."))
  6490. np2 = CreateEmptyNameValuePair(np, name, fp);
  6491. return(np2);
  6492. }
  6493. static Namval_t *
  6494. ProcessHyperType(
  6495. int hyperType,
  6496. Namval_t *np,
  6497. char *name,
  6498. Namfun_t *fp )
  6499. {
  6500. Namval_t * np2;
  6501. char buf[128];
  6502. wtab_t * w;
  6503. XrmValue f, t;
  6504. char * value;
  6505. np2 = GetNameValuePair(name);
  6506. f.addr = (caddr_t)&hyperType;
  6507. f.size = sizeof(long);
  6508. t.addr = NULL;
  6509. t.size = 0;
  6510. XtConvert(Toplevel, "HelpHyperType", &f, XtRString, &t);
  6511. if (t.addr)
  6512. value = t.addr;
  6513. else
  6514. value = str_nill;
  6515. strcpy(buf, value);
  6516. nv_putval(np2, buf, NV_RDONLY);
  6517. if (name = strtok(NULL, "."))
  6518. np2 = CreateEmptyNameValuePair(np, name, fp);
  6519. return(np2);
  6520. }
  6521. static XEventTable eventTable[] = {
  6522. {"XANY", NULL},
  6523. {"XBUTTON", NULL},
  6524. {"XEXPOSE", NULL},
  6525. {"XNOEXPOSE", NULL},
  6526. {"XGRAPHICSEXPOSE", NULL},
  6527. {"XKEY", NULL},
  6528. {"XMOTION", NULL},
  6529. {NULL, NULL},
  6530. };
  6531. static EventEntryTable xanyTable[] = {
  6532. {"TYPE", "XE_EventType", XtOffsetOf(XEvent, xany.type), sizeof(int)},
  6533. {"SERIAL", "XE_IntValue", XtOffsetOf(XEvent, xany.serial),
  6534. sizeof(unsigned long)},
  6535. {"SEND_EVENT", "X_Bool", XtOffsetOf(XEvent, xany.send_event),
  6536. sizeof(Boolean)},
  6537. {"DISPLAY", "XE_HexValue", XtOffsetOf(XEvent, xany.display),
  6538. sizeof(Display *)},
  6539. {"WINDOW", "XE_Window", XtOffsetOf(XEvent, xany.window),
  6540. sizeof(Window)},
  6541. {NULL, NULL, 0, 0},
  6542. };
  6543. static EventEntryTable xbuttonTable[] = {
  6544. {"TYPE", "XE_EventType", XtOffsetOf(XEvent, xbutton.type), sizeof(int)},
  6545. {"SERIAL", "XE_IntValue", XtOffsetOf(XEvent, xbutton.serial),
  6546. sizeof(unsigned long)},
  6547. {"SEND_EVENT", "X_Bool", XtOffsetOf(XEvent, xbutton.send_event),
  6548. sizeof(Bool)},
  6549. {"DISPLAY", "XE_HexValue", XtOffsetOf(XEvent, xbutton.display),
  6550. sizeof(Display *)},
  6551. {"WINDOW", "XE_Window", XtOffsetOf(XEvent, xbutton.window),
  6552. sizeof(Window)},
  6553. {"ROOT", "XE_Window", XtOffsetOf(XEvent, xbutton.root),
  6554. sizeof(Window)},
  6555. {"SUBWINDOW", "XE_Window", XtOffsetOf(XEvent, xbutton.subwindow),
  6556. sizeof(Window)},
  6557. {"TIME", "XE_IntValue", XtOffsetOf(XEvent, xbutton.time),
  6558. sizeof(unsigned int)},
  6559. {"X", "XE_IntValue", XtOffsetOf(XEvent, xbutton.x),
  6560. sizeof(int)},
  6561. {"Y", "XE_IntValue", XtOffsetOf(XEvent, xbutton.y),
  6562. sizeof(int)},
  6563. {"X_ROOT", "XE_IntValue", XtOffsetOf(XEvent, xbutton.x_root),
  6564. sizeof(int)},
  6565. {"Y_ROOT", "XE_IntValue", XtOffsetOf(XEvent, xbutton.y_root),
  6566. sizeof(int)},
  6567. {"STATE", "XE_ModifierState", XtOffsetOf(XEvent, xbutton.state),
  6568. sizeof(unsigned int)},
  6569. {"BUTTON", "XE_Button", XtOffsetOf(XEvent, xbutton.button),
  6570. sizeof(unsigned int)},
  6571. {"SAME_SCREEN", "X_Bool", XtOffsetOf(XEvent, xbutton.same_screen),
  6572. sizeof(Bool)},
  6573. {NULL, NULL, 0, 0},
  6574. };
  6575. static EventEntryTable xexposeTable[] = {
  6576. {"TYPE", "XE_EventType", XtOffsetOf(XEvent, xexpose.type), sizeof(int)},
  6577. {"SERIAL", "XE_IntValue", XtOffsetOf(XEvent, xexpose.serial),
  6578. sizeof(unsigned long)},
  6579. {"SEND_EVENT", "X_Bool", XtOffsetOf(XEvent, xexpose.send_event),
  6580. sizeof(Bool)},
  6581. {"DISPLAY", "XE_HexValue", XtOffsetOf(XEvent, xexpose.display),
  6582. sizeof(Display *)},
  6583. {"WINDOW", "XE_Window", XtOffsetOf(XEvent, xexpose.window),
  6584. sizeof(Window)},
  6585. {"X", "XE_IntValue", XtOffsetOf(XEvent, xexpose.x),
  6586. sizeof(int)},
  6587. {"Y", "XE_IntValue", XtOffsetOf(XEvent, xexpose.y),
  6588. sizeof(int)},
  6589. {"WIDTH", "XE_IntValue", XtOffsetOf(XEvent, xexpose.width),
  6590. sizeof(int)},
  6591. {"HEIGHT", "XE_IntValue", XtOffsetOf(XEvent, xexpose.height),
  6592. sizeof(int)},
  6593. {"COUNT", "XE_IntValue", XtOffsetOf(XEvent, xexpose.count),
  6594. sizeof(int)},
  6595. {NULL, NULL, 0, 0},
  6596. };
  6597. static EventEntryTable xnoExposeTable[] = {
  6598. {"TYPE", "XE_EventType", XtOffsetOf(XEvent, xnoexpose.type), sizeof(int)},
  6599. {"SERIAL", "XE_IntValue", XtOffsetOf(XEvent, xnoexpose.serial),
  6600. sizeof(unsigned long)},
  6601. {"SEND_EVENT", "X_Bool", XtOffsetOf(XEvent, xnoexpose.send_event),
  6602. sizeof(Bool)},
  6603. {"DISPLAY", "XE_HexValue", XtOffsetOf(XEvent, xnoexpose.display),
  6604. sizeof(Display *)},
  6605. {"DRAWABLE", "XE_Window", XtOffsetOf(XEvent, xnoexpose.drawable),
  6606. sizeof(Window)},
  6607. {"MAJOR_CODE", "XE_IntValue", XtOffsetOf(XEvent, xnoexpose.major_code),
  6608. sizeof(int)},
  6609. {"MINOR_CODE", "XE_IntValue", XtOffsetOf(XEvent, xnoexpose.minor_code),
  6610. sizeof(int)},
  6611. {NULL, NULL, 0, 0},
  6612. };
  6613. static EventEntryTable xgraphicsExposeTable[] = {
  6614. {"TYPE", "XE_EventType",
  6615. XtOffsetOf(XEvent, xgraphicsexpose.type), sizeof(int)},
  6616. {"SERIAL", "XE_IntValue", XtOffsetOf(XEvent, xgraphicsexpose.serial),
  6617. sizeof(unsigned long)},
  6618. {"SEND_EVENT", "X_Bool", XtOffsetOf(XEvent, xgraphicsexpose.send_event),
  6619. sizeof(Bool)},
  6620. {"DISPLAY", "XE_HexValue", XtOffsetOf(XEvent, xgraphicsexpose.display),
  6621. sizeof(Display *)},
  6622. {"DRAWABLE", "XE_Window", XtOffsetOf(XEvent, xgraphicsexpose.drawable),
  6623. sizeof(Window)},
  6624. {"X", "XE_IntValue", XtOffsetOf(XEvent, xgraphicsexpose.x),
  6625. sizeof(int)},
  6626. {"Y", "XE_IntValue", XtOffsetOf(XEvent, xgraphicsexpose.y),
  6627. sizeof(int)},
  6628. {"WIDTH", "XE_IntValue", XtOffsetOf(XEvent, xgraphicsexpose.width),
  6629. sizeof(int)},
  6630. {"HEIGHT", "XE_IntValue", XtOffsetOf(XEvent, xgraphicsexpose.height),
  6631. sizeof(int)},
  6632. {"COUNT", "XE_IntValue", XtOffsetOf(XEvent, xgraphicsexpose.count),
  6633. sizeof(int)},
  6634. {"MAJOR_CODE", "XE_IntValue",
  6635. XtOffsetOf(XEvent, xgraphicsexpose.major_code),
  6636. sizeof(int)},
  6637. {"MINOR_CODE", "XE_IntValue", XtOffsetOf(XEvent, xgraphicsexpose.minor_code),
  6638. sizeof(int)},
  6639. {NULL, NULL, 0, 0},
  6640. };
  6641. static EventEntryTable xkeyTable[] = {
  6642. {"TYPE", "XE_EventType", XtOffsetOf(XEvent, xkey.type), sizeof(int)},
  6643. {"SERIAL", "XE_IntValue", XtOffsetOf(XEvent, xkey.serial),
  6644. sizeof(unsigned long)},
  6645. {"SEND_EVENT", "X_Bool", XtOffsetOf(XEvent, xkey.send_event),
  6646. sizeof(Bool)},
  6647. {"DISPLAY", "XE_HexValue", XtOffsetOf(XEvent, xkey.display),
  6648. sizeof(Display *)},
  6649. {"WINDOW", "XE_Window", XtOffsetOf(XEvent, xkey.window),
  6650. sizeof(Window)},
  6651. {"ROOT", "XE_Window", XtOffsetOf(XEvent, xkey.root),
  6652. sizeof(Window)},
  6653. {"SUBWINDOW", "XE_Window", XtOffsetOf(XEvent, xkey.subwindow),
  6654. sizeof(Window)},
  6655. {"TIME", "XE_IntValue", XtOffsetOf(XEvent, xkey.time),
  6656. sizeof(unsigned int)},
  6657. {"X", "XE_IntValue", XtOffsetOf(XEvent, xkey.x),
  6658. sizeof(int)},
  6659. {"Y", "XE_IntValue", XtOffsetOf(XEvent, xkey.y),
  6660. sizeof(int)},
  6661. {"X_ROOT", "XE_IntValue", XtOffsetOf(XEvent, xkey.x_root),
  6662. sizeof(int)},
  6663. {"Y_ROOT", "XE_IntValue", XtOffsetOf(XEvent, xkey.y_root),
  6664. sizeof(int)},
  6665. {"STATE", "XE_ModifierState", XtOffsetOf(XEvent, xkey.state),
  6666. sizeof(unsigned int)},
  6667. {"KEYCODE", "XE_IntValue", XtOffsetOf(XEvent, xkey.keycode),
  6668. sizeof(unsigned int)},
  6669. {"SAME_SCREEN", "X_Bool", XtOffsetOf(XEvent, xkey.same_screen),
  6670. sizeof(Bool)},
  6671. {NULL, NULL, 0, 0},
  6672. };
  6673. static EventEntryTable xmotionTable[] = {
  6674. {"TYPE", "XE_EventType", XtOffsetOf(XEvent, xmotion.type), sizeof(int)},
  6675. {"SERIAL", "XE_IntValue", XtOffsetOf(XEvent, xmotion.serial),
  6676. sizeof(unsigned long)},
  6677. {"SEND_EVENT", "X_Bool", XtOffsetOf(XEvent, xmotion.send_event),
  6678. sizeof(Bool)},
  6679. {"DISPLAY", "XE_HexValue", XtOffsetOf(XEvent, xmotion.display),
  6680. sizeof(Display *)},
  6681. {"WINDOW", "XE_Window", XtOffsetOf(XEvent, xmotion.window),
  6682. sizeof(Window)},
  6683. {"ROOT", "XE_Window", XtOffsetOf(XEvent, xmotion.root),
  6684. sizeof(Window)},
  6685. {"SUBWINDOW", "XE_Window", XtOffsetOf(XEvent, xmotion.subwindow),
  6686. sizeof(Window)},
  6687. {"TIME", "XE_IntValue", XtOffsetOf(XEvent, xmotion.time),
  6688. sizeof(unsigned int)},
  6689. {"X", "XE_IntValue", XtOffsetOf(XEvent, xmotion.x),
  6690. sizeof(int)},
  6691. {"Y", "XE_IntValue", XtOffsetOf(XEvent, xmotion.y),
  6692. sizeof(int)},
  6693. {"X_ROOT", "XE_IntValue", XtOffsetOf(XEvent, xmotion.x_root),
  6694. sizeof(int)},
  6695. {"Y_ROOT", "XE_IntValue", XtOffsetOf(XEvent, xmotion.y_root),
  6696. sizeof(int)},
  6697. {"STATE", "XE_ModifierState", XtOffsetOf(XEvent, xmotion.state),
  6698. sizeof(unsigned int)},
  6699. {"IS_HINT", "XE_MotionHint", XtOffsetOf(XEvent, xmotion.is_hint),
  6700. sizeof(char)},
  6701. {"SAME_SCREEN", "X_Bool", XtOffsetOf(XEvent, xmotion.same_screen),
  6702. sizeof(Bool)},
  6703. {NULL, NULL, 0, 0},
  6704. };
  6705. /*
  6706. * The order in which the structures are initialized IS important; they
  6707. * must be done in the same order as they are defined in the eventTable
  6708. * structure.
  6709. */
  6710. static void
  6711. InitEventTables( void )
  6712. {
  6713. int i = 0;
  6714. eventTable[i++].table = xanyTable;
  6715. eventTable[i++].table = xbuttonTable;
  6716. eventTable[i++].table = xexposeTable;
  6717. eventTable[i++].table = xnoExposeTable;
  6718. eventTable[i++].table = xgraphicsExposeTable;
  6719. eventTable[i++].table = xkeyTable;
  6720. eventTable[i++].table = xmotionTable;
  6721. }
  6722. static Namval_t *
  6723. ProcessCallbackEvent(
  6724. XEvent *event,
  6725. Namval_t *np,
  6726. char *name,
  6727. Namfun_t *fp )
  6728. {
  6729. Namval_t * np2;
  6730. char buf[128];
  6731. static Boolean initialized = False;
  6732. int i = 0;
  6733. int j = 0;
  6734. EventEntryTable * table;
  6735. XrmValue fval, tval;
  6736. char * ptr;
  6737. if (!initialized)
  6738. {
  6739. InitEventTables();
  6740. initialized = True;
  6741. }
  6742. np2 = GetNameValuePair(name);
  6743. sprintf(buf, "0x%lx", (long)event);
  6744. nv_putval(np2, buf, NV_RDONLY);
  6745. if (name = strtok(NULL, "."))
  6746. {
  6747. if (event == NULL)
  6748. np2 = CreateEmptyNameValuePair(np, name, fp);
  6749. else
  6750. {
  6751. np2 = GetNameValuePair(name);
  6752. if (strcmp(name, "TYPE") == 0)
  6753. {
  6754. fval.addr = (caddr_t)&(event->type);
  6755. fval.size = sizeof(long);
  6756. XtConvert(Toplevel, "XE_EventType", &fval, XtRString, &tval);
  6757. if (tval.size != 0)
  6758. ptr = (char *)(tval.addr);
  6759. else
  6760. ptr = str_nill;
  6761. nv_putval(np2, ptr, NV_RDONLY);
  6762. }
  6763. else
  6764. {
  6765. while (eventTable[i].eventType)
  6766. {
  6767. if (strcmp(eventTable[i].eventType, name) == 0)
  6768. {
  6769. sprintf(buf, "0x%lx", (long)event);
  6770. nv_putval(np2, buf, NV_RDONLY);
  6771. if (name = strtok(NULL, "."))
  6772. {
  6773. np2 = GetNameValuePair(name);
  6774. table = eventTable[i].table;
  6775. while (table[j].fieldName)
  6776. {
  6777. if (strcmp(table[j].fieldName, name) == 0)
  6778. {
  6779. if (table[j].valueSize == sizeof(char))
  6780. {
  6781. fval.addr = (caddr_t) ((char *)
  6782. ((char *)event+table[j].valueOffset));
  6783. fval.size = sizeof(char);
  6784. }
  6785. else if (table[j].valueSize == sizeof(short))
  6786. {
  6787. fval.addr = (caddr_t) ((short *)
  6788. ((char *)event+table[j].valueOffset));
  6789. fval.size = sizeof(short);
  6790. }
  6791. else if (table[j].valueSize == sizeof(int))
  6792. {
  6793. fval.addr = (caddr_t) ((int *)
  6794. ((char *)event+table[j].valueOffset));
  6795. fval.size = sizeof(int);
  6796. }
  6797. else if (table[j].valueSize == sizeof(long))
  6798. {
  6799. fval.addr = (caddr_t) ((long *)
  6800. ((char *)event+table[j].valueOffset));
  6801. fval.size = sizeof(long);
  6802. }
  6803. XtConvert(Toplevel, table[j].representation,
  6804. &fval, XtRString, &tval);
  6805. if (tval.size != 0)
  6806. ptr = (char *)(tval.addr);
  6807. else
  6808. ptr = str_nill;
  6809. nv_putval(np2, ptr, NV_RDONLY);
  6810. break;
  6811. }
  6812. j++;
  6813. }
  6814. if (table[j].fieldName == NULL)
  6815. nv_putval(np2, str_nill, NV_RDONLY);
  6816. break;
  6817. }
  6818. }
  6819. i++;
  6820. }
  6821. if (eventTable[i].eventType == NULL)
  6822. nv_putval(np2, str_nill, NV_RDONLY);
  6823. }
  6824. if (name = strtok(NULL, "."))
  6825. np2 = CreateEmptyNameValuePair(np, name, fp);
  6826. }
  6827. }
  6828. return(np2);
  6829. }
  6830. static Namval_t *
  6831. _IntProcessCallbackReason(
  6832. struct named_integer *table,
  6833. XmAnyCallbackStruct *cbData,
  6834. Namval_t *np,
  6835. char *name,
  6836. Namfun_t *fp )
  6837. {
  6838. Namval_t * np2;
  6839. char buf[128];
  6840. /*
  6841. * We won't use an Xt converter here (even though we could), because
  6842. * we want to be able to handle the case where the callback reason
  6843. * is one we don't know about.
  6844. */
  6845. np2 = GetNameValuePair(name);
  6846. while (table->name)
  6847. {
  6848. if (table->value == cbData->reason)
  6849. {
  6850. nv_putval(np2, table->name, NV_RDONLY);
  6851. if (name = strtok(NULL, "."))
  6852. np2 = CreateEmptyNameValuePair(np, name, fp);
  6853. return(np2);
  6854. }
  6855. table++;
  6856. }
  6857. /*
  6858. * fdt: someday, allow for an expandable table, which can be
  6859. * added to by the shell script; useful when loading new widgets.
  6860. */
  6861. /* Unknown callback reason; simply return the integer value */
  6862. sprintf(buf, "%d", cbData->reason);
  6863. nv_putval(np2, buf, NV_RDONLY);
  6864. if (name = strtok(NULL, "."))
  6865. np2 = CreateEmptyNameValuePair(np, name, fp);
  6866. return(np2);
  6867. }
  6868. static Namval_t *
  6869. ProcessCallbackReason(
  6870. XmAnyCallbackStruct *cbData,
  6871. Namval_t *np,
  6872. char *name,
  6873. Namfun_t *fp )
  6874. {
  6875. return(_IntProcessCallbackReason(CallbackReasons, cbData, np, name, fp));
  6876. }
  6877. /*
  6878. * This requires a separate handler, due to the fact that the help
  6879. * callback reasons overlap the standard Motif callback reasons!!
  6880. */
  6881. static Namval_t *
  6882. ProcessHelpCallbackReason(
  6883. XmAnyCallbackStruct *cbData,
  6884. Namval_t *np,
  6885. char *name,
  6886. Namfun_t *fp )
  6887. {
  6888. return(_IntProcessCallbackReason(HelpCallbackReasons, cbData, np, name, fp));
  6889. }
  6890. /*
  6891. * Certain classes of callbacks do not return a structure as the calldata.
  6892. * Examples are the destroyCallback, popupCallback, popdownCallback and
  6893. * the workspace changed callback. Since the calldata is a value, and not
  6894. * a structure, any references to subfields are invalid.
  6895. */
  6896. Namval_t *
  6897. nopCreateDisc(
  6898. Namval_t *np,
  6899. char *name,
  6900. int flags,
  6901. Namfun_t *fp )
  6902. {
  6903. Namval_t * np2;
  6904. char * token;
  6905. char * dupName = strdup(name);
  6906. token = strtok(dupName, ".");
  6907. np2 = CreateEmptyNameValuePair(np, token, fp);
  6908. XtFree(dupName);
  6909. fp->last = Empty;
  6910. return(np2);
  6911. }
  6912. /*
  6913. * This function creates a new name/value pair (representing an environment
  6914. * variable) when it is referenced. If the name/value pair already exists,
  6915. * then it is simply reused. We keep track of all the name/value pairs
  6916. * we create, so that they can be destroyed when callback processing has
  6917. * completed. This handles the XmAnyCallbackStruct.
  6918. */
  6919. Namval_t *
  6920. dftCreateDisc(
  6921. Namval_t *np,
  6922. char *name,
  6923. int flags,
  6924. Namfun_t *fp )
  6925. {
  6926. Namval_t * np2;
  6927. char buf[128];
  6928. XmAnyCallbackStruct * cbData;
  6929. char * cbDataAddrStr;
  6930. char * p;
  6931. char * token;
  6932. char * dupName = strdup(name);
  6933. cbDataAddrStr = nv_getv(np, fp);
  6934. cbData = (XmAnyCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  6935. token = strtok(dupName, ".");
  6936. /* cbData can be NULL if invoked from XtCallCallbacks */
  6937. if (cbData == NULL)
  6938. np2 = CreateEmptyNameValuePair(np, token, fp);
  6939. else if (strcmp(token, "REASON") == 0)
  6940. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData, np, token, fp);
  6941. else if (strcmp(token, "EVENT") == 0)
  6942. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  6943. else
  6944. np2 = CreateEmptyNameValuePair(np, token, fp);
  6945. XtFree(dupName);
  6946. fp->last = Empty;
  6947. return(np2);
  6948. }
  6949. /*
  6950. * This is the discipline handler for an event handler.
  6951. * It only knows how to reference the event structure.
  6952. */
  6953. Namval_t *
  6954. ehCreateDisc(
  6955. Namval_t *np,
  6956. char *name,
  6957. int flags,
  6958. Namfun_t *fp )
  6959. {
  6960. Namval_t * np2;
  6961. char buf[128];
  6962. XEvent * event;
  6963. char * eventAddrStr;
  6964. char * p;
  6965. char * token;
  6966. char * tmpBuf;
  6967. eventAddrStr = nv_getv(np, fp);
  6968. event = (XEvent *)strtoul(eventAddrStr, &p, 0);
  6969. tmpBuf = XtMalloc(strlen(name) + strlen("EH_EVENT") + 2);
  6970. sprintf(tmpBuf, "%s.%s", "EH_EVENT", name);
  6971. token = strtok(tmpBuf, ".");
  6972. np2 = ProcessCallbackEvent(event, np, token, fp);
  6973. XtFree(tmpBuf);
  6974. fp->last = Empty;
  6975. return(np2);
  6976. }
  6977. /*
  6978. * This is the discipline handler for the translation handler.
  6979. * It only knows how to reference the event structure.
  6980. */
  6981. Namval_t *
  6982. transCreateDisc(
  6983. Namval_t *np,
  6984. char *name,
  6985. int flags,
  6986. Namfun_t *fp )
  6987. {
  6988. Namval_t * np2;
  6989. char buf[128];
  6990. XEvent * event;
  6991. char * eventAddrStr;
  6992. char * p;
  6993. char * token;
  6994. char * tmpBuf;
  6995. eventAddrStr = nv_getv(np, fp);
  6996. event = (XEvent *)strtoul(eventAddrStr, &p, 0);
  6997. tmpBuf = XtMalloc(strlen(name) + strlen("TRANSLATION_EVENT") + 2);
  6998. sprintf(tmpBuf, "%s.%s", "TRANSLATION_EVENT", name);
  6999. token = strtok(tmpBuf, ".");
  7000. np2 = ProcessCallbackEvent(event, np, token, fp);
  7001. XtFree(tmpBuf);
  7002. fp->last = Empty;
  7003. return(np2);
  7004. }
  7005. /*
  7006. * This is the 'create' discipline function for the scale widget.
  7007. * This handles the XmScaleCallbackStruct.
  7008. */
  7009. Namval_t *
  7010. scaleCreateDisc(
  7011. Namval_t *np,
  7012. char *name,
  7013. int flags,
  7014. Namfun_t *fp )
  7015. {
  7016. char * cbDataAddrStr;
  7017. XmScaleCallbackStruct * cbData;
  7018. char * p;
  7019. char * token;
  7020. char * dupName = strdup(name);
  7021. Namval_t * np2;
  7022. cbDataAddrStr = nv_getv(np, fp);
  7023. cbData = (XmScaleCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7024. token = strtok(dupName, ".");
  7025. /* cbData can be NULL if invoked from XtCallCallbacks */
  7026. if (cbData == NULL)
  7027. np2 = CreateEmptyNameValuePair(np, token, fp);
  7028. else if (strcmp(token, "REASON") == 0)
  7029. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData, np, token, fp);
  7030. else if (strcmp(token, "EVENT") == 0)
  7031. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7032. else if (strcmp(token, "VALUE") == 0)
  7033. np2 = ProcessIntValue((int)cbData->value, np, token, fp, "%d", NULL);
  7034. else
  7035. np2 = CreateEmptyNameValuePair(np, token, fp);
  7036. XtFree(dupName);
  7037. fp->last = Empty;
  7038. return(np2);
  7039. }
  7040. /*
  7041. * This is the 'create' discipline function for the arrow widget.
  7042. * This handles the XmArrowButtonCallbackStruct.
  7043. */
  7044. Namval_t *
  7045. arrowCreateDisc(
  7046. Namval_t *np,
  7047. char *name,
  7048. int flags,
  7049. Namfun_t *fp )
  7050. {
  7051. char * cbDataAddrStr;
  7052. XmArrowButtonCallbackStruct * cbData;
  7053. char * p;
  7054. char * token;
  7055. char * dupName = strdup(name);
  7056. Namval_t * np2;
  7057. cbDataAddrStr = nv_getv(np, fp);
  7058. cbData = (XmArrowButtonCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7059. token = strtok(dupName, ".");
  7060. /* cbData can be NULL if invoked from XtCallCallbacks */
  7061. if (cbData == NULL)
  7062. np2 = CreateEmptyNameValuePair(np, token, fp);
  7063. else if (strcmp(token, "REASON") == 0)
  7064. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData, np, token, fp);
  7065. else if (strcmp(token, "EVENT") == 0)
  7066. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7067. else if (strcmp(token, "CLICK_COUNT") == 0)
  7068. {
  7069. if (cbData->reason == XmCR_ACTIVATE)
  7070. {
  7071. np2 = ProcessIntValue((int)cbData->click_count, np, token, fp, "%d",
  7072. NULL);
  7073. }
  7074. else
  7075. np2 = CreateEmptyNameValuePair(np, token, fp);
  7076. }
  7077. else
  7078. np2 = CreateEmptyNameValuePair(np, token, fp);
  7079. XtFree(dupName);
  7080. fp->last = Empty;
  7081. return(np2);
  7082. }
  7083. /*
  7084. * This is the 'create' discipline function for the comboBox widget.
  7085. * This handles the XmComboBoxCallbackStruct.
  7086. */
  7087. Namval_t *
  7088. comboCreateDisc(
  7089. Namval_t *np,
  7090. char *name,
  7091. int flags,
  7092. Namfun_t *fp )
  7093. {
  7094. char * cbDataAddrStr;
  7095. XmComboBoxCallbackStruct * cbData;
  7096. char * p;
  7097. char * token;
  7098. char * dupName = strdup(name);
  7099. Namval_t * np2;
  7100. cbDataAddrStr = nv_getv(np, fp);
  7101. cbData = (XmComboBoxCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7102. token = strtok(dupName, ".");
  7103. /* cbData can be NULL if invoked from XtCallCallbacks */
  7104. if (cbData == NULL)
  7105. np2 = CreateEmptyNameValuePair(np, token, fp);
  7106. else if (strcmp(token, "REASON") == 0)
  7107. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData,
  7108. np, token, fp);
  7109. else if (strcmp(token, "EVENT") == 0)
  7110. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7111. else if (strcmp(token, "ITEM_OR_TEXT") == 0)
  7112. np2 = ProcessXmStringValue(cbData->item_or_text, np, token, fp);
  7113. else if (strcmp(token, "ITEM_POSITION") == 0)
  7114. {
  7115. np2 = ProcessIntValue((int)cbData->item_position, np, token, fp, "%d",
  7116. NULL);
  7117. }
  7118. else
  7119. np2 = CreateEmptyNameValuePair(np, token, fp);
  7120. XtFree(dupName);
  7121. fp->last = Empty;
  7122. return(np2);
  7123. }
  7124. /*
  7125. * This is the 'create' discipline function for the command widget.
  7126. * This handles the XmCommandCallbackStruct.
  7127. */
  7128. Namval_t *
  7129. cmdCreateDisc(
  7130. Namval_t *np,
  7131. char *name,
  7132. int flags,
  7133. Namfun_t *fp )
  7134. {
  7135. char * cbDataAddrStr;
  7136. XmCommandCallbackStruct * cbData;
  7137. char * p;
  7138. char * token;
  7139. char * dupName = strdup(name);
  7140. Namval_t * np2;
  7141. int len;
  7142. cbDataAddrStr = nv_getv(np, fp);
  7143. cbData = (XmCommandCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7144. token = strtok(dupName, ".");
  7145. /* cbData can be NULL if invoked from XtCallCallbacks */
  7146. if (cbData == NULL)
  7147. np2 = CreateEmptyNameValuePair(np, token, fp);
  7148. else if (strcmp(token, "REASON") == 0)
  7149. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData, np, token, fp);
  7150. else if (strcmp(token, "EVENT") == 0)
  7151. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7152. else if (strcmp(token, "VALUE") == 0)
  7153. np2 = ProcessXmStringValue(cbData->value, np, token, fp);
  7154. else if (strcmp(token, "LENGTH") == 0)
  7155. {
  7156. if ((p = XmStringToString(cbData->value)) == NULL)
  7157. len = 0;
  7158. else
  7159. len = strlen(p);
  7160. np2 = ProcessIntValue((int)len, np, token, fp, "%d", NULL);
  7161. }
  7162. else
  7163. np2 = CreateEmptyNameValuePair(np, token, fp);
  7164. XtFree(dupName);
  7165. fp->last = Empty;
  7166. return(np2);
  7167. }
  7168. /*
  7169. * This is the 'create' discipline function for the drawingArea widget.
  7170. * This handles the XmDrawingAreaCallbackStruct.
  7171. */
  7172. Namval_t *
  7173. dAreaCreateDisc(
  7174. Namval_t *np,
  7175. char *name,
  7176. int flags,
  7177. Namfun_t *fp )
  7178. {
  7179. char * cbDataAddrStr;
  7180. XmDrawingAreaCallbackStruct * cbData;
  7181. char * p;
  7182. char * token;
  7183. char * dupName = strdup(name);
  7184. Namval_t * np2;
  7185. cbDataAddrStr = nv_getv(np, fp);
  7186. cbData = (XmDrawingAreaCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7187. token = strtok(dupName, ".");
  7188. /* cbData can be NULL if invoked from XtCallCallbacks */
  7189. if (cbData == NULL)
  7190. np2 = CreateEmptyNameValuePair(np, token, fp);
  7191. else if (strcmp(token, "REASON") == 0)
  7192. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData, np, token, fp);
  7193. else if (strcmp(token, "EVENT") == 0)
  7194. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7195. else if (strcmp(token, "WINDOW") == 0)
  7196. np2 = ProcessIntValue((int)cbData->window, np, token, fp, "0x%x", NULL);
  7197. else
  7198. np2 = CreateEmptyNameValuePair(np, token, fp);
  7199. XtFree(dupName);
  7200. fp->last = Empty;
  7201. return(np2);
  7202. }
  7203. /*
  7204. * This is the 'create' discipline function for the drawnButton widget.
  7205. * This handles the XmDrawnButtonCallbackStruct.
  7206. */
  7207. Namval_t *
  7208. dbtnCreateDisc(
  7209. Namval_t *np,
  7210. char *name,
  7211. int flags,
  7212. Namfun_t *fp )
  7213. {
  7214. char * cbDataAddrStr;
  7215. XmDrawnButtonCallbackStruct * cbData;
  7216. char * p;
  7217. char * token;
  7218. char * dupName = strdup(name);
  7219. Namval_t * np2;
  7220. cbDataAddrStr = nv_getv(np, fp);
  7221. cbData = (XmDrawnButtonCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7222. token = strtok(dupName, ".");
  7223. /* cbData can be NULL if invoked from XtCallCallbacks */
  7224. if (cbData == NULL)
  7225. np2 = CreateEmptyNameValuePair(np, token, fp);
  7226. else if (strcmp(token, "REASON") == 0)
  7227. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData, np, token, fp);
  7228. else if (strcmp(token, "EVENT") == 0)
  7229. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7230. else if (strcmp(token, "WINDOW") == 0)
  7231. np2 = ProcessIntValue((int)cbData->window, np, token, fp, "0x%x", NULL);
  7232. else if (strcmp(token, "CLICK_COUNT") == 0)
  7233. {
  7234. if (cbData->reason == XmCR_ACTIVATE)
  7235. {
  7236. np2 = ProcessIntValue((int)cbData->click_count, np, token, fp, "%d",
  7237. NULL);
  7238. }
  7239. else
  7240. np2 = CreateEmptyNameValuePair(np, token, fp);
  7241. }
  7242. else
  7243. np2 = CreateEmptyNameValuePair(np, token, fp);
  7244. XtFree(dupName);
  7245. fp->last = Empty;
  7246. return(np2);
  7247. }
  7248. /*
  7249. * This is the 'create' discipline function for the file selection widget.
  7250. * This handles the XmFileSelectionBoxCallbackStruct.
  7251. */
  7252. Namval_t *
  7253. fselCreateDisc(
  7254. Namval_t *np,
  7255. char *name,
  7256. int flags,
  7257. Namfun_t *fp )
  7258. {
  7259. char * cbDataAddrStr;
  7260. XmFileSelectionBoxCallbackStruct * cbData;
  7261. char * p;
  7262. char * token;
  7263. char * dupName = strdup(name);
  7264. Namval_t * np2;
  7265. int len;
  7266. cbDataAddrStr = nv_getv(np, fp);
  7267. cbData = (XmFileSelectionBoxCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7268. token = strtok(dupName, ".");
  7269. /* cbData can be NULL if invoked from XtCallCallbacks */
  7270. if (cbData == NULL)
  7271. np2 = CreateEmptyNameValuePair(np, token, fp);
  7272. else if (strcmp(token, "REASON") == 0)
  7273. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData, np, token, fp);
  7274. else if (strcmp(token, "EVENT") == 0)
  7275. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7276. else if (strcmp(token, "VALUE") == 0)
  7277. np2 = ProcessXmStringValue(cbData->value, np, token, fp);
  7278. else if (strcmp(token, "LENGTH") == 0)
  7279. {
  7280. if ((p = XmStringToString(cbData->value)) == NULL)
  7281. len = 0;
  7282. else
  7283. len = strlen(p);
  7284. np2 = ProcessIntValue(len, np, token, fp, "%d", NULL);
  7285. }
  7286. else if (strcmp(token, "MASK") == 0)
  7287. np2 = ProcessXmStringValue(cbData->mask, np, token, fp);
  7288. else if (strcmp(token, "MASK_LENGTH") == 0)
  7289. {
  7290. if ((p = XmStringToString(cbData->mask)) == NULL)
  7291. len = 0;
  7292. else
  7293. len = strlen(p);
  7294. np2 = ProcessIntValue(len, np, token, fp, "%d", NULL);
  7295. }
  7296. else if (strcmp(token, "DIR") == 0)
  7297. np2 = ProcessXmStringValue(cbData->dir, np, token, fp);
  7298. else if (strcmp(token, "DIR_LENGTH") == 0)
  7299. {
  7300. if ((p = XmStringToString(cbData->dir)) == NULL)
  7301. len = 0;
  7302. else
  7303. len = strlen(p);
  7304. np2 = ProcessIntValue(len, np, token, fp, "%d", NULL);
  7305. }
  7306. else if (strcmp(token, "PATTERN") == 0)
  7307. np2 = ProcessXmStringValue(cbData->pattern, np, token, fp);
  7308. else if (strcmp(token, "PATTERN_LENGTH") == 0)
  7309. {
  7310. if ((p = XmStringToString(cbData->pattern)) == NULL)
  7311. len = 0;
  7312. else
  7313. len = strlen(p);
  7314. np2 = ProcessIntValue(len, np, token, fp, "%d", NULL);
  7315. }
  7316. else
  7317. np2 = CreateEmptyNameValuePair(np, token, fp);
  7318. XtFree(dupName);
  7319. fp->last = Empty;
  7320. return(np2);
  7321. }
  7322. /*
  7323. * This is the 'create' discipline function for the list widget.
  7324. * This handles the XmListCallbackStruct.
  7325. */
  7326. Namval_t *
  7327. listCreateDisc(
  7328. Namval_t *np,
  7329. char *name,
  7330. int flags,
  7331. Namfun_t *fp )
  7332. {
  7333. char * cbDataAddrStr;
  7334. XmListCallbackStruct * cbData;
  7335. char * p;
  7336. char * token;
  7337. char * dupName = strdup(name);
  7338. Namval_t * np2;
  7339. int len;
  7340. cbDataAddrStr = nv_getv(np, fp);
  7341. cbData = (XmListCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7342. token = strtok(dupName, ".");
  7343. /* cbData can be NULL if invoked from XtCallCallbacks */
  7344. if (cbData == NULL)
  7345. np2 = CreateEmptyNameValuePair(np, token, fp);
  7346. else if (strcmp(token, "REASON") == 0)
  7347. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData, np, token, fp);
  7348. else if (strcmp(token, "EVENT") == 0)
  7349. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7350. else if (strcmp(token, "ITEM") == 0)
  7351. np2 = ProcessXmStringValue(cbData->item, np, token, fp);
  7352. else if (strcmp(token, "ITEM_LENGTH") == 0)
  7353. {
  7354. if ((p = XmStringToString(cbData->item)) == NULL)
  7355. len = 0;
  7356. else
  7357. len = strlen(p);
  7358. np2 = ProcessIntValue(len, np, token, fp, "%d", NULL);
  7359. }
  7360. else if (strcmp(token, "ITEM_POSITION") == 0)
  7361. {
  7362. np2 = ProcessIntValue((int)cbData->item_position, np, token, fp, "%d",
  7363. NULL);
  7364. }
  7365. else if (strcmp(token, "SELECTED_ITEMS") == 0)
  7366. {
  7367. if ((cbData->reason == XmCR_DEFAULT_ACTION) ||
  7368. (cbData->reason == XmCR_MULTIPLE_SELECT) ||
  7369. (cbData->reason == XmCR_EXTENDED_SELECT))
  7370. {
  7371. np2 = ProcessXmStringTable(cbData->selected_items,
  7372. cbData->selected_item_count,
  7373. np, token, fp);
  7374. }
  7375. else
  7376. np2 = CreateEmptyNameValuePair(np, token, fp);
  7377. }
  7378. else if (strcmp(token, "SELECTED_ITEM_COUNT") == 0)
  7379. {
  7380. if ((cbData->reason == XmCR_DEFAULT_ACTION) ||
  7381. (cbData->reason == XmCR_MULTIPLE_SELECT) ||
  7382. (cbData->reason == XmCR_EXTENDED_SELECT))
  7383. {
  7384. np2 = ProcessIntValue((int)cbData->selected_item_count, np, token,
  7385. fp, "%d", NULL);
  7386. }
  7387. else
  7388. np2 = CreateEmptyNameValuePair(np, token, fp);
  7389. }
  7390. else if (strcmp(token, "SELECTED_ITEM_POSITIONS") == 0)
  7391. {
  7392. if ((cbData->reason == XmCR_DEFAULT_ACTION) ||
  7393. (cbData->reason == XmCR_MULTIPLE_SELECT) ||
  7394. (cbData->reason == XmCR_EXTENDED_SELECT))
  7395. {
  7396. np2 = ProcessIntTable(cbData->selected_item_positions,
  7397. cbData->selected_item_count,
  7398. np, token, fp);
  7399. }
  7400. else
  7401. np2 = CreateEmptyNameValuePair(np, token, fp);
  7402. }
  7403. else if (strcmp(token, "SELECTION_TYPE") == 0)
  7404. {
  7405. if (cbData->reason == XmCR_EXTENDED_SELECT)
  7406. np2 = ProcessSelectionType(cbData->selection_type, np, token, fp);
  7407. else
  7408. np2 = CreateEmptyNameValuePair(np, token, fp);
  7409. }
  7410. else
  7411. np2 = CreateEmptyNameValuePair(np, token, fp);
  7412. XtFree(dupName);
  7413. fp->last = Empty;
  7414. return(np2);
  7415. }
  7416. /*
  7417. * This is the 'create' discipline function for the pushbutton widget.
  7418. * This handles the XmPushButtonCallbackStruct.
  7419. */
  7420. Namval_t *
  7421. pbtnCreateDisc(
  7422. Namval_t *np,
  7423. char *name,
  7424. int flags,
  7425. Namfun_t *fp )
  7426. {
  7427. char * cbDataAddrStr;
  7428. XmPushButtonCallbackStruct * cbData;
  7429. char * p;
  7430. char * token;
  7431. char * dupName = strdup(name);
  7432. Namval_t * np2;
  7433. cbDataAddrStr = nv_getv(np, fp);
  7434. cbData = (XmPushButtonCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7435. token = strtok(dupName, ".");
  7436. /* cbData can be NULL if invoked from XtCallCallbacks */
  7437. if (cbData == NULL)
  7438. np2 = CreateEmptyNameValuePair(np, token, fp);
  7439. else if (strcmp(token, "REASON") == 0)
  7440. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData, np, token, fp);
  7441. else if (strcmp(token, "EVENT") == 0)
  7442. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7443. else if (strcmp(token, "CLICK_COUNT") == 0)
  7444. {
  7445. if (cbData->reason == XmCR_ACTIVATE)
  7446. {
  7447. np2 = ProcessIntValue((int)cbData->click_count, np, token, fp, "%d",
  7448. NULL);
  7449. }
  7450. else
  7451. np2 = CreateEmptyNameValuePair(np, token, fp);
  7452. }
  7453. else
  7454. np2 = CreateEmptyNameValuePair(np, token, fp);
  7455. XtFree(dupName);
  7456. fp->last = Empty;
  7457. return(np2);
  7458. }
  7459. /*
  7460. * This is the 'create' discipline function for the rowcolumn widget.
  7461. * This handles the XmRowColumnCallbackStruct.
  7462. */
  7463. Namval_t *
  7464. rcCreateDisc(
  7465. Namval_t *np,
  7466. char *name,
  7467. int flags,
  7468. Namfun_t *fp )
  7469. {
  7470. char * cbDataAddrStr;
  7471. XmRowColumnCallbackStruct * cbData;
  7472. char * p;
  7473. char * token;
  7474. char * dupName = strdup(name);
  7475. Namval_t * np2;
  7476. cbDataAddrStr = nv_getv(np, fp);
  7477. cbData = (XmRowColumnCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7478. token = strtok(dupName, ".");
  7479. /* cbData can be NULL if invoked from XtCallCallbacks */
  7480. if (cbData == NULL)
  7481. np2 = CreateEmptyNameValuePair(np, token, fp);
  7482. else if (strcmp(token, "REASON") == 0)
  7483. {
  7484. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData, np, token,
  7485. fp);
  7486. }
  7487. else if (strcmp(token, "EVENT") == 0)
  7488. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7489. else if ((strcmp(token, "WIDGET") == 0) &&
  7490. (cbData->reason == XmCR_ACTIVATE))
  7491. {
  7492. np2 = ProcessWidgetHandle(cbData->widget, np, token, fp);
  7493. }
  7494. else if ((strcmp(token, "DATA") == 0) && (cbData->reason == XmCR_ACTIVATE))
  7495. np2 = ProcessIntValue((int)((long)cbData->data), np, token, fp, "0x%x", NULL);
  7496. else if ((strcmp(token, "CALLBACKSTRUCT") == 0) &&
  7497. (cbData->reason == XmCR_ACTIVATE))
  7498. {
  7499. np2 = ProcessIntValue((int)((long)cbData->callbackstruct), np, token,fp,"0x%x",
  7500. NULL);
  7501. }
  7502. else
  7503. np2 = CreateEmptyNameValuePair(np, token, fp);
  7504. XtFree(dupName);
  7505. fp->last = Empty;
  7506. return(np2);
  7507. }
  7508. /*
  7509. * This is the 'create' discipline function for the scrollbar widget.
  7510. * This handles the XmScrollBarCallbackStruct.
  7511. */
  7512. Namval_t *
  7513. sbarCreateDisc(
  7514. Namval_t *np,
  7515. char *name,
  7516. int flags,
  7517. Namfun_t *fp )
  7518. {
  7519. char * cbDataAddrStr;
  7520. XmScrollBarCallbackStruct * cbData;
  7521. char * p;
  7522. char * token;
  7523. char * dupName = strdup(name);
  7524. Namval_t * np2;
  7525. cbDataAddrStr = nv_getv(np, fp);
  7526. cbData = (XmScrollBarCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7527. token = strtok(dupName, ".");
  7528. /* cbData can be NULL if invoked from XtCallCallbacks */
  7529. if (cbData == NULL)
  7530. np2 = CreateEmptyNameValuePair(np, token, fp);
  7531. else if (strcmp(token, "REASON") == 0)
  7532. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData, np, token, fp);
  7533. else if (strcmp(token, "EVENT") == 0)
  7534. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7535. else if (strcmp(token, "VALUE") == 0)
  7536. np2 = ProcessIntValue((int)cbData->value, np, token, fp, "%d", NULL);
  7537. else if (strcmp(token, "PIXEL") == 0)
  7538. {
  7539. if ((cbData->reason == XmCR_TO_BOTTOM) || (cbData->reason == XmCR_TO_TOP))
  7540. np2 = ProcessIntValue((int)cbData->pixel, np, token,fp,"%d", NULL);
  7541. else
  7542. np2 = CreateEmptyNameValuePair(np, token, fp);
  7543. }
  7544. else
  7545. np2 = CreateEmptyNameValuePair(np, token, fp);
  7546. XtFree(dupName);
  7547. fp->last = Empty;
  7548. return(np2);
  7549. }
  7550. /*
  7551. * This is the 'create' discipline function for the scrolledwindow widget.
  7552. * This handles the XmTraverseObsuredCallbackStruct.
  7553. */
  7554. Namval_t *
  7555. swinCreateDisc(
  7556. Namval_t *np,
  7557. char *name,
  7558. int flags,
  7559. Namfun_t *fp )
  7560. {
  7561. char * cbDataAddrStr;
  7562. XmTraverseObscuredCallbackStruct * cbData;
  7563. char * token;
  7564. char * p;
  7565. char * dupName = strdup(name);
  7566. Namval_t * np2;
  7567. cbDataAddrStr = nv_getv(np, fp);
  7568. cbData = (XmTraverseObscuredCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7569. token = strtok(dupName, ".");
  7570. /* cbData can be NULL if invoked from XtCallCallbacks */
  7571. if (cbData == NULL)
  7572. np2 = CreateEmptyNameValuePair(np, token, fp);
  7573. else if (strcmp(token, "REASON") == 0)
  7574. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData, np, token, fp);
  7575. else if (strcmp(token, "EVENT") == 0)
  7576. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7577. else if (strcmp(token, "TRAVERSAL_DESTINATION") == 0)
  7578. np2 = ProcessWidgetHandle(cbData->traversal_destination, np, token, fp);
  7579. else if (strcmp(token, "DIRECTION") == 0)
  7580. np2 = ProcessTraversalDirection(cbData->direction, np, token, fp);
  7581. else
  7582. np2 = CreateEmptyNameValuePair(np, token, fp);
  7583. XtFree(dupName);
  7584. fp->last = Empty;
  7585. return(np2);
  7586. }
  7587. /*
  7588. * This is the 'create' discipline function for the selection box widget.
  7589. * This handles the XmSelectionBoxCallbackStruct.
  7590. */
  7591. Namval_t *
  7592. sboxCreateDisc(
  7593. Namval_t *np,
  7594. char *name,
  7595. int flags,
  7596. Namfun_t *fp )
  7597. {
  7598. char * cbDataAddrStr;
  7599. XmSelectionBoxCallbackStruct * cbData;
  7600. char * p;
  7601. char * token;
  7602. char * dupName = strdup(name);
  7603. Namval_t * np2;
  7604. int len;
  7605. cbDataAddrStr = nv_getv(np, fp);
  7606. cbData = (XmSelectionBoxCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7607. token = strtok(dupName, ".");
  7608. /* cbData can be NULL if invoked from XtCallCallbacks */
  7609. if (cbData == NULL)
  7610. np2 = CreateEmptyNameValuePair(np, token, fp);
  7611. else if (strcmp(token, "REASON") == 0)
  7612. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData, np, token, fp);
  7613. else if (strcmp(token, "EVENT") == 0)
  7614. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7615. else if (strcmp(token, "VALUE") == 0)
  7616. np2 = ProcessXmStringValue(cbData->value, np, token, fp);
  7617. else if (strcmp(token, "LENGTH") == 0)
  7618. {
  7619. if ((p = XmStringToString(cbData->value)) == NULL)
  7620. len = 0;
  7621. else
  7622. len = strlen(p);
  7623. np2 = ProcessIntValue(len, np, token, fp, "%d", NULL);
  7624. }
  7625. else
  7626. np2 = CreateEmptyNameValuePair(np, token, fp);
  7627. XtFree(dupName);
  7628. fp->last = Empty;
  7629. return(np2);
  7630. }
  7631. /*
  7632. * This is the 'create' discipline function for the toggle widget.
  7633. * This handles the XmToggleButtonCallbackStruct.
  7634. */
  7635. Namval_t *
  7636. tbtnCreateDisc(
  7637. Namval_t *np,
  7638. char *name,
  7639. int flags,
  7640. Namfun_t *fp )
  7641. {
  7642. char * cbDataAddrStr;
  7643. XmToggleButtonCallbackStruct * cbData;
  7644. char * p;
  7645. char * token;
  7646. char * dupName = strdup(name);
  7647. Namval_t * np2;
  7648. cbDataAddrStr = nv_getv(np, fp);
  7649. cbData = (XmToggleButtonCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7650. token = strtok(dupName, ".");
  7651. /* cbData can be NULL if invoked from XtCallCallbacks */
  7652. if (cbData == NULL)
  7653. np2 = CreateEmptyNameValuePair(np, token, fp);
  7654. else if (strcmp(token, "REASON") == 0)
  7655. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData, np, token, fp);
  7656. else if (strcmp(token, "EVENT") == 0)
  7657. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7658. else if (strcmp(token, "SET") == 0)
  7659. np2 = ProcessBooleanIntValue((int)cbData->set, np, token, fp, NULL);
  7660. else
  7661. np2 = CreateEmptyNameValuePair(np, token, fp);
  7662. XtFree(dupName);
  7663. fp->last = Empty;
  7664. return(np2);
  7665. }
  7666. /*
  7667. * This is one ofthe 'create' discipline function for the text widget.
  7668. * This handles the XmTextVerifyCallbackStruct. If a subfield can
  7669. * be altered by a shell script (i.e. CB_CALL_DATA.TEXT.PTR), then
  7670. * we must assign a discipline to the 'PTR' environment variable,
  7671. * so that we will be notified when the assignment occurs, and thus
  7672. * can update the real callback structure.
  7673. */
  7674. Namval_t *
  7675. textCreateDisc(
  7676. Namval_t *np,
  7677. char *name,
  7678. int flags,
  7679. Namfun_t *fp )
  7680. {
  7681. char * cbDataAddrStr;
  7682. XmTextVerifyCallbackStruct * cbData;
  7683. char * p;
  7684. char * token;
  7685. XrmValue f, t;
  7686. char * value;
  7687. char buf[25];
  7688. char * dupName = strdup(name);
  7689. Namval_t * np2;
  7690. cbDataAddrStr = nv_getv(np, fp);
  7691. cbData = (XmTextVerifyCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7692. token = strtok(dupName, ".");
  7693. /* cbData can be NULL if invoked from XtCallCallbacks */
  7694. if (cbData == NULL)
  7695. np2 = CreateEmptyNameValuePair(np, token, fp);
  7696. else if (strcmp(token, "REASON") == 0)
  7697. np2 = ProcessCallbackReason((XmAnyCallbackStruct *)cbData, np, token, fp);
  7698. else if (strcmp(token, "EVENT") == 0)
  7699. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7700. else if (strcmp(token, "DOIT") == 0)
  7701. {
  7702. static Namfun_t * disc = NULL;
  7703. if (disc == NULL)
  7704. disc = CloneDiscipline(&text_doit_disc);
  7705. np2 = ProcessBooleanIntValue((int)cbData->doit, np, token, fp, disc);
  7706. }
  7707. else if (strcmp(token, "CURRINSERT") == 0)
  7708. np2 = ProcessIntValue((int)cbData->currInsert, np, token, fp, "%d", NULL);
  7709. else if (strcmp(token, "NEWINSERT") == 0)
  7710. np2 = ProcessIntValue((int)cbData->newInsert, np, token, fp, "%d", NULL);
  7711. else if (strcmp(token, "STARTPOS") == 0)
  7712. {
  7713. static Namfun_t * disc = NULL;
  7714. if (disc == NULL)
  7715. disc = CloneDiscipline(&text_startpos_disc);
  7716. if ((cbData->reason == XmCR_LOSING_FOCUS) ||
  7717. (cbData->reason == XmCR_MODIFYING_TEXT_VALUE))
  7718. {
  7719. np2 = ProcessIntValue((int)cbData->startPos, np, token, fp,"%d", disc);
  7720. }
  7721. else
  7722. np2 = CreateEmptyNameValuePair(np, token, fp);
  7723. }
  7724. else if (strcmp(token, "ENDPOS") == 0)
  7725. {
  7726. static Namfun_t * disc = NULL;
  7727. if (disc == NULL)
  7728. disc = CloneDiscipline(&text_endpos_disc);
  7729. if ((cbData->reason == XmCR_LOSING_FOCUS) ||
  7730. (cbData->reason == XmCR_MODIFYING_TEXT_VALUE))
  7731. {
  7732. np2 = ProcessIntValue((int)cbData->endPos, np, token, fp, "%d", disc);
  7733. }
  7734. else
  7735. np2 = CreateEmptyNameValuePair(np, token, fp);
  7736. }
  7737. else if (strcmp(token, "TEXT") == 0)
  7738. {
  7739. if (cbData->reason == XmCR_MODIFYING_TEXT_VALUE)
  7740. {
  7741. np2 = GetNameValuePair(token);
  7742. sprintf(buf, "0x%lx", (long)cbData->text);
  7743. nv_putval(np2, buf, NV_RDONLY);
  7744. /* Need to handle the substructure fields */
  7745. if (token = strtok(NULL, "."))
  7746. {
  7747. np2 = GetNameValuePair(token);
  7748. if (strcmp(token, "PTR") == 0)
  7749. {
  7750. static Namfun_t * disc = NULL;
  7751. if (disc == NULL)
  7752. disc = CloneDiscipline(&text_ptr_disc);
  7753. /* Any old disciplies MUST be cleared, before setting value */
  7754. nv_stack(np2, NULL);
  7755. if (cbData->text->ptr)
  7756. nv_putval(np2, cbData->text->ptr, NV_RDONLY);
  7757. else
  7758. nv_putval(np2, str_nill, NV_RDONLY);
  7759. nv_stack(np2, disc);
  7760. }
  7761. else if (strcmp(token, "LENGTH") == 0)
  7762. {
  7763. static Namfun_t * disc = NULL;
  7764. if (disc == NULL)
  7765. disc = CloneDiscipline(&text_len_disc);
  7766. /* Any old disciplies MUST be cleared, before setting value */
  7767. sprintf(buf, "%d", cbData->text->length);
  7768. nv_stack(np2, NULL);
  7769. nv_putval(np2, buf, NV_RDONLY);
  7770. nv_stack(np2, disc);
  7771. }
  7772. else if (strcmp(token, "FORMAT") == 0)
  7773. {
  7774. static Namfun_t * disc = NULL;
  7775. if (disc == NULL)
  7776. disc = CloneDiscipline(&text_format_disc);
  7777. f.addr = (caddr_t)&(cbData->text->format);
  7778. f.size = sizeof(XmTextFormat);
  7779. t.addr = NULL;
  7780. t.size = 0;
  7781. XtConvert(Toplevel, "TextFormat", &f, XtRString, &t);
  7782. /* Any old disciplies MUST be cleared, before setting value */
  7783. if (t.size && t.addr)
  7784. value = t.addr;
  7785. else
  7786. value = str_nill;
  7787. nv_stack(np2, NULL);
  7788. nv_putval(np2, value, NV_RDONLY);
  7789. nv_stack(np2, disc);
  7790. }
  7791. else
  7792. nv_putval(np2, str_nill, NV_RDONLY);
  7793. /* No deeper nesting is supported */
  7794. if (token = strtok(NULL, "."))
  7795. np2 = CreateEmptyNameValuePair(np, token, fp);
  7796. }
  7797. }
  7798. else
  7799. np2 = CreateEmptyNameValuePair(np, token, fp);
  7800. }
  7801. else
  7802. np2 = CreateEmptyNameValuePair(np, token, fp);
  7803. XtFree(dupName);
  7804. fp->last = Empty;
  7805. return(np2);
  7806. }
  7807. /*
  7808. * This is one ofthe 'create' discipline function for the text widget.
  7809. * This handles the XmTextVerifyCallbackStructWcs.
  7810. */
  7811. Namval_t *
  7812. textCreateDisc2(
  7813. Namval_t *np,
  7814. char *name,
  7815. int flags,
  7816. Namfun_t *fp )
  7817. {
  7818. char * cbDataAddrStr;
  7819. XmTextVerifyCallbackStructWcs * cbData;
  7820. char * p;
  7821. char * token;
  7822. Namval_t * np2;
  7823. char * nameCopy = strdup(name);
  7824. char * dupName = strdup(name);
  7825. char buf[25];
  7826. cbDataAddrStr = nv_getv(np, fp);
  7827. cbData = (XmTextVerifyCallbackStructWcs *)strtoul(cbDataAddrStr, &p, 0);
  7828. token = strtok(dupName, ".");
  7829. /* cbData can be NULL if invoked from XtCallCallbacks */
  7830. if (cbData == NULL)
  7831. np2 = CreateEmptyNameValuePair(np, token, fp);
  7832. else if (strcmp(token, "TEXT") == 0)
  7833. {
  7834. np2 = GetNameValuePair(token);
  7835. sprintf(buf, "0x%lx", (long)cbData->text);
  7836. nv_putval(np2, buf, NV_RDONLY);
  7837. /* Need to handle the substructure fields */
  7838. if (token = strtok(NULL, "."))
  7839. {
  7840. np2 = GetNameValuePair(token);
  7841. if (strcmp(token, "WCSPTR") == 0)
  7842. {
  7843. static Namfun_t * disc = NULL;
  7844. if (disc == NULL)
  7845. disc = CloneDiscipline(&text_wcsptr_disc);
  7846. /* Any old disciplies MUST be cleared, before setting value */
  7847. nv_stack(np2, NULL);
  7848. if (cbData->text->wcsptr)
  7849. {
  7850. wchar_t * wcBuf;
  7851. char * mbBuf;
  7852. int mbBufSize;
  7853. int count, i;
  7854. /*
  7855. * It appears that the wchar string coming in is NOT NULL
  7856. * terminated; we must make our own copy, before calling
  7857. * wcstombs().
  7858. */
  7859. wcBuf = (wchar_t *)XtMalloc((cbData->text->length + 1) *
  7860. sizeof(wchar_t));
  7861. for ( i = 0; i < cbData->text->length; i++)
  7862. wcBuf[i] = cbData->text->wcsptr[i];
  7863. wcBuf[i] = 0;
  7864. mbBufSize = ((cbData->text->length + 1) * sizeof(wchar_t));
  7865. mbBuf = XtMalloc(mbBufSize);
  7866. count = wcstombs(mbBuf, wcBuf, mbBufSize - sizeof(wchar_t));
  7867. if (count >= 0)
  7868. {
  7869. mbBuf[count] = '\0';
  7870. nv_putval(np2, mbBuf, NV_RDONLY);
  7871. }
  7872. else
  7873. nv_putval(np2, str_nill, NV_RDONLY);
  7874. XtFree(mbBuf);
  7875. XtFree((char *)wcBuf);
  7876. }
  7877. else
  7878. nv_putval(np2, str_nill, NV_RDONLY);
  7879. nv_stack(np2, disc);
  7880. }
  7881. else if (strcmp(token, "LENGTH") == 0)
  7882. {
  7883. static Namfun_t * disc = NULL;
  7884. if (disc == NULL)
  7885. disc = CloneDiscipline(&text_wcslen_disc);
  7886. /* Any old disciplies MUST be cleared, before setting value */
  7887. sprintf(buf, "%d", cbData->text->length);
  7888. nv_stack(np2, NULL);
  7889. nv_putval(np2, buf, NV_RDONLY);
  7890. nv_stack(np2, disc);
  7891. }
  7892. else
  7893. nv_putval(np2, str_nill, NV_RDONLY);
  7894. /* No deeper nesting is supported */
  7895. if (token = strtok(NULL, "."))
  7896. np2 = CreateEmptyNameValuePair(np, token, fp);
  7897. }
  7898. }
  7899. else
  7900. np2 = textCreateDisc(np, nameCopy, flags, fp);
  7901. XtFree(nameCopy);
  7902. XtFree(dupName);
  7903. fp->last = Empty;
  7904. return(np2);
  7905. }
  7906. /*
  7907. * This is the 'create' discipline function for the help widget.
  7908. * This handles the DtHelpDialogCallbackStruct.
  7909. */
  7910. Namval_t *
  7911. helpCreateDisc(
  7912. Namval_t *np,
  7913. char *name,
  7914. int flags,
  7915. Namfun_t *fp )
  7916. {
  7917. char * cbDataAddrStr;
  7918. DtHelpDialogCallbackStruct * cbData;
  7919. char * p;
  7920. char * token;
  7921. char * dupName = strdup(name);
  7922. Namval_t * np2;
  7923. cbDataAddrStr = nv_getv(np, fp);
  7924. cbData = (DtHelpDialogCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  7925. token = strtok(dupName, ".");
  7926. /* cbData can be NULL if invoked from XtCallCallbacks */
  7927. if (cbData == NULL)
  7928. np2 = CreateEmptyNameValuePair(np, token, fp);
  7929. else if (strcmp(token, "REASON") == 0)
  7930. {
  7931. /*
  7932. * Can't use the normal callback reason function, since the help
  7933. * callback reasons are not unique! They overlap with the normal
  7934. * callback reasons.
  7935. */
  7936. np2 = ProcessHelpCallbackReason((XmAnyCallbackStruct *)cbData, np,
  7937. token, fp);
  7938. }
  7939. else if (strcmp(token, "EVENT") == 0)
  7940. {
  7941. if (cbData->event)
  7942. np2 = ProcessCallbackEvent(cbData->event, np, token, fp);
  7943. else
  7944. np2 = CreateEmptyNameValuePair(np, token, fp);
  7945. }
  7946. else if (strcmp(token, "LOCATIONID") == 0)
  7947. {
  7948. if (cbData->reason == DtCR_HELP_LINK_ACTIVATE)
  7949. np2 = ProcessStringValue(cbData->locationId, np, token, fp);
  7950. else
  7951. np2 = CreateEmptyNameValuePair(np, token, fp);
  7952. }
  7953. else if (strcmp(token, "HELPVOLUME") == 0)
  7954. {
  7955. if (cbData->reason == DtCR_HELP_LINK_ACTIVATE)
  7956. np2 = ProcessStringValue(cbData->helpVolume, np, token, fp);
  7957. else
  7958. np2 = CreateEmptyNameValuePair(np, token, fp);
  7959. }
  7960. else if (strcmp(token, "SPECIFICATION") == 0)
  7961. {
  7962. if (cbData->reason == DtCR_HELP_LINK_ACTIVATE)
  7963. np2 = ProcessStringValue(cbData->specification, np, token, fp);
  7964. else
  7965. np2 = CreateEmptyNameValuePair(np, token, fp);
  7966. }
  7967. else if (strcmp(token, "HYPERTYPE") == 0)
  7968. {
  7969. if (cbData->reason == DtCR_HELP_LINK_ACTIVATE)
  7970. np2 = ProcessHyperType(cbData->hyperType, np, token, fp);
  7971. else
  7972. np2 = CreateEmptyNameValuePair(np, token, fp);
  7973. }
  7974. else
  7975. np2 = CreateEmptyNameValuePair(np, token, fp);
  7976. XtFree(dupName);
  7977. fp->last = Empty;
  7978. return(np2);
  7979. }
  7980. /*
  7981. * This is the 'DtPrintSetupProc' discipline function for the DtPrintSetupBox
  7982. * widget. It handles the DtPrintSetupData struct with the exception of the
  7983. * print_display and print_screen members.
  7984. */
  7985. Namval_t *
  7986. dtPrintSetupProcDisc(
  7987. Namval_t *np,
  7988. char *name,
  7989. int flags,
  7990. Namfun_t *fp )
  7991. {
  7992. char * cbDataAddrStr;
  7993. DtPrintSetupData * cbData;
  7994. char * p;
  7995. char * token;
  7996. char * dupName = strdup(name);
  7997. Namval_t * np2;
  7998. cbDataAddrStr = nv_getv(np, fp);
  7999. cbData = (DtPrintSetupData *)strtoul(cbDataAddrStr, &p, 0);
  8000. token = strtok(dupName, ".");
  8001. if (cbData == NULL)
  8002. np2 = CreateEmptyNameValuePair(np, token, fp);
  8003. else if (strcmp(token, "PRINTER_NAME") == 0)
  8004. np2 = ProcessStringValue(cbData->printer_name, np, token, fp);
  8005. else if (strcmp(token, "DESTINATION") == 0)
  8006. np2 = ProcessIntValue(cbData->destination, np, token, fp, "%d", NULL);
  8007. else if (strcmp(token, "DEST_INFO") == 0)
  8008. np2 = ProcessStringValue(cbData->dest_info, np, token, fp);
  8009. else
  8010. np2 = CreateEmptyNameValuePair(np, token, fp);
  8011. XtFree(dupName);
  8012. fp->last = Empty;
  8013. return(np2);
  8014. }
  8015. /****************************************************************************
  8016. *
  8017. * The following functions are used to create and free a copy of a
  8018. * discipline structure. We register a discipline when we want to
  8019. * be notified that the shell script has referenced one of our special
  8020. * environment variables. This gives us the ability to dynamically
  8021. * assign the value they will receive. This is used during callback,
  8022. * translation and event handling (i.e. CB_CALL_DATA, etc). We need
  8023. * to duplicate the discipline structure due to how ksh handles these
  8024. * structures; it stores each successive one in a linked list. Typically,
  8025. * this is not a problem. However, because callbacks can become nested
  8026. * (From within one callback, the script does something which causes another
  8027. * callback to fire), if the same discipline structure gets passed in twice,
  8028. * when it gets added to the linked list, the original 'next' pointer gets
  8029. * trashed; the typical result is that the next time one of the special
  8030. * environment variables is referenced, dtksh goes into an infinite loop.
  8031. * The solution appears to be to 'clone' the discipline, thus creating
  8032. * a unique structure each time, and preventing the 'next' pointer from
  8033. * getting trashed.
  8034. *
  8035. **************************************************************************/
  8036. static Namfun_t *
  8037. CloneDiscipline(
  8038. Namdisc_t * discipline )
  8039. {
  8040. Namfun_t * clonedDisc;
  8041. clonedDisc = (Namfun_t *)XtMalloc(sizeof(Namfun_t));
  8042. clonedDisc->disc = discipline;
  8043. clonedDisc->next = NULL;
  8044. return(clonedDisc);
  8045. }
  8046. static void
  8047. FreeDiscipline(
  8048. Namfun_t * discipline )
  8049. {
  8050. XtFree((char *)discipline);
  8051. }
  8052. void
  8053. SetTextDoit(
  8054. Namval_t *np,
  8055. char *name,
  8056. Namfun_t *fp )
  8057. {
  8058. XrmValue fval, tval;
  8059. Boolean doit = True;
  8060. char * cbDataAddrStr;
  8061. XmTextVerifyCallbackStruct * cbData;
  8062. char * p;
  8063. Namval_t *cbDataNp;
  8064. /* Convert from string to a boolean */
  8065. fval.addr = name;
  8066. fval.size = strlen(name);
  8067. XtConvert(Toplevel, XtRString, &fval, XtRBoolean, &tval);
  8068. if (tval.size != 0)
  8069. doit = *((Boolean *)(tval.addr));
  8070. if (cbDataNp = nv_open("CB_CALL_DATA", sh.var_tree, 0))
  8071. {
  8072. cbDataAddrStr = nv_getv(cbDataNp, NULL);
  8073. cbData=(XmTextVerifyCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  8074. cbData->doit = doit;
  8075. }
  8076. }
  8077. void
  8078. SetTextStartPos(
  8079. Namval_t *np,
  8080. char *name,
  8081. Namfun_t *fp )
  8082. {
  8083. char * cbDataAddrStr;
  8084. XmTextVerifyCallbackStruct * cbData;
  8085. char * p;
  8086. Namval_t *cbDataNp;
  8087. if (cbDataNp = nv_open("CB_CALL_DATA", sh.var_tree, 0))
  8088. {
  8089. cbDataAddrStr = nv_getv(cbDataNp, NULL);
  8090. cbData=(XmTextVerifyCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  8091. cbData->startPos = strtoul(name, &p, 0);
  8092. }
  8093. }
  8094. void
  8095. SetTextEndPos(
  8096. Namval_t *np,
  8097. char *name,
  8098. Namfun_t *fp )
  8099. {
  8100. char * cbDataAddrStr;
  8101. XmTextVerifyCallbackStruct * cbData;
  8102. char * p;
  8103. Namval_t *cbDataNp;
  8104. if (cbDataNp = nv_open("CB_CALL_DATA", sh.var_tree, 0))
  8105. {
  8106. cbDataAddrStr = nv_getv(cbDataNp, NULL);
  8107. cbData=(XmTextVerifyCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  8108. cbData->endPos = strtoul(name, &p, 0);
  8109. }
  8110. }
  8111. void
  8112. SetTextPtr(
  8113. Namval_t *np,
  8114. char *name,
  8115. Namfun_t *fp )
  8116. {
  8117. char * cbDataAddrStr;
  8118. XmTextVerifyCallbackStruct * cbData;
  8119. char * p;
  8120. Namval_t *cbDataNp;
  8121. static char * staticBuf = NULL;
  8122. if (cbDataNp = nv_open("CB_CALL_DATA", sh.var_tree, 0))
  8123. {
  8124. cbDataAddrStr = nv_getv(cbDataNp, NULL);
  8125. cbData=(XmTextVerifyCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  8126. /* fdt
  8127. * MOTIF BUG ALERT!!
  8128. * Motif will not currently free the original buffer,
  8129. * but will instead free our buffer.
  8130. *
  8131. * XtFree(staticBuf);
  8132. */
  8133. staticBuf = strdup(name);
  8134. cbData->text->ptr = staticBuf;
  8135. }
  8136. }
  8137. void
  8138. SetTextLen(
  8139. Namval_t *np,
  8140. char *name,
  8141. Namfun_t *fp )
  8142. {
  8143. char * cbDataAddrStr;
  8144. XmTextVerifyCallbackStruct * cbData;
  8145. char * p;
  8146. Namval_t *cbDataNp;
  8147. if (cbDataNp = nv_open("CB_CALL_DATA", sh.var_tree, 0))
  8148. {
  8149. cbDataAddrStr = nv_getv(cbDataNp, NULL);
  8150. cbData=(XmTextVerifyCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  8151. cbData->text->length = strtoul(name, &p, 0);
  8152. }
  8153. }
  8154. void
  8155. SetTextFormat(
  8156. Namval_t *np,
  8157. char *name,
  8158. Namfun_t *fp )
  8159. {
  8160. XrmValue fval, tval;
  8161. Boolean doit = True;
  8162. char * cbDataAddrStr;
  8163. XmTextVerifyCallbackStruct * cbData;
  8164. char * p;
  8165. Namval_t *cbDataNp;
  8166. /* Convert from string to format type */
  8167. fval.addr = name;
  8168. fval.size = strlen(name);
  8169. XtConvert(Toplevel, XtRString, &fval, "TextFormat", &tval);
  8170. if (tval.size && tval.addr &&
  8171. (cbDataNp = nv_open("CB_CALL_DATA", sh.var_tree, 0)))
  8172. {
  8173. cbDataAddrStr = nv_getv(cbDataNp, NULL);
  8174. cbData=(XmTextVerifyCallbackStruct *)strtoul(cbDataAddrStr, &p, 0);
  8175. cbData->text->format = *((int *)(tval.addr));
  8176. }
  8177. }
  8178. void
  8179. SetTextWCSptr(
  8180. Namval_t *np,
  8181. char *name,
  8182. Namfun_t *fp )
  8183. {
  8184. char * cbDataAddrStr;
  8185. XmTextVerifyCallbackStructWcs * cbData;
  8186. char * p;
  8187. Namval_t *cbDataNp;
  8188. static wchar_t * wcBuf = NULL;
  8189. int count;
  8190. if (cbDataNp = nv_open("CB_CALL_DATA", sh.var_tree, 0))
  8191. {
  8192. cbDataAddrStr = nv_getv(cbDataNp, NULL);
  8193. cbData=(XmTextVerifyCallbackStructWcs *)strtoul(cbDataAddrStr, &p, 0);
  8194. /* fdt
  8195. * MOTIF BUG ALERT!!
  8196. * Motif will not currently free the original buffer,
  8197. * but will instead free our buffer.
  8198. *
  8199. * XtFree(wcBuf);
  8200. */
  8201. wcBuf = (wchar_t *)XtMalloc((strlen(name) + 1) * sizeof(wchar_t));
  8202. count = mbstowcs(wcBuf, name, strlen(name)+1);
  8203. cbData->text->wcsptr = wcBuf;
  8204. }
  8205. }
  8206. void
  8207. SetTextWCSlen(
  8208. Namval_t *np,
  8209. char *name,
  8210. Namfun_t *fp )
  8211. {
  8212. char * cbDataAddrStr;
  8213. XmTextVerifyCallbackStructWcs * cbData;
  8214. char * p;
  8215. Namval_t *cbDataNp;
  8216. if (cbDataNp = nv_open("CB_CALL_DATA", sh.var_tree, 0))
  8217. {
  8218. cbDataAddrStr = nv_getv(cbDataNp, NULL);
  8219. cbData=(XmTextVerifyCallbackStructWcs *)strtoul(cbDataAddrStr, &p, 0);
  8220. cbData->text->length = strtoul(name, &p, 0);
  8221. }
  8222. }
  8223. /*
  8224. * stdPrintSetupProc() is the central routine from which the DtPrintSetupBox
  8225. * widget's DtPrintSetupProc resources are dispatched.
  8226. * The variable "CB_WIDGET" will be placed in the environment to represent
  8227. * the CallBackWidget handle. Because DtPrintSetupProc doesn't work the
  8228. * same way as a callback, we had to fudge this to work by storing the command
  8229. * string inside the widget's wtab_t->info field. This is pretty nasty and
  8230. * non-generic, but there does not appear to be a good solution.
  8231. *
  8232. * The call_data is made available through the CD_CALL_DATA variable.
  8233. *
  8234. * If a new DtPrintSetupProc resource needs to be supported, the list of
  8235. * hardcoded procs and associated information have to be updated, as follows:
  8236. * - add a #define of the resource in dtksh.h
  8237. * - add a new member in the ProcInfo_t to store that command in dtksh.h.
  8238. * - add a new function called std<resource_name> which calls
  8239. * stdPrintSetupProc().
  8240. * - add a new case to set the command to the above function for the new
  8241. * resource in DtkshCvtStringToPrintSetupProc().
  8242. * - add a new case in the switch statement this function to account for
  8243. * the new resource.
  8244. *
  8245. */
  8246. void
  8247. stdPrintSetupProc(
  8248. int proctype,
  8249. void *widget,
  8250. DtPrintSetupData *callData)
  8251. {
  8252. wtab_t *w;
  8253. ProcInfo_t *pinfo;
  8254. char buf[128];
  8255. Namval_t *np;
  8256. Namval_t *np2;
  8257. WidgetClass class;
  8258. Namdisc_t *discipline = NULL;
  8259. char *oldCB_WIDGET_value = NULL;
  8260. char *oldCB_CALL_DATA_value = NULL;
  8261. char *ptr;
  8262. Namfun_t *clonedDisc;
  8263. w = widget_to_wtab((Widget)widget);
  8264. if (w == NULL)
  8265. return;
  8266. pinfo = (ProcInfo_t *) w->info;
  8267. if (pinfo == NULL)
  8268. return;
  8269. nestingLevel++;
  8270. np2 = GetNameValuePair("CB_WIDGET");
  8271. nv_newattr(np2, 0, 0);
  8272. if (ptr = nv_getval(np2))
  8273. oldCB_WIDGET_value = strdup(ptr);
  8274. nv_putval(np2, w->widid, NV_RDONLY);
  8275. nv_newattr(np2, NV_RDONLY, 0);
  8276. sprintf(buf, "0x%lx", (long)callData);
  8277. np = GetNameValuePair("CB_CALL_DATA");
  8278. nv_newattr(np, 0, 0);
  8279. if (ptr = nv_getval(np))
  8280. oldCB_CALL_DATA_value = strdup(ptr);
  8281. nv_putval(np, buf, NV_RDONLY);
  8282. nv_newattr(np, NV_RDONLY, 0);
  8283. /* look up the discipline for DtPrintSetupProc */
  8284. class = XtClass(w->w);
  8285. while (class) {
  8286. if (discipline = CheckClassDisciplines(class, DtRPrintSetupProc))
  8287. break;
  8288. class = class->core_class.superclass;
  8289. }
  8290. /*
  8291. * If a discipline was found, then use it; otherwise, we MUST set up
  8292. * a default discipline; otherwise, any hierarchical variables
  8293. * referenced by the user are not under our control, thus never getting
  8294. * freed up, and then also preventing future disciplines from getting
  8295. * called when they should have.
  8296. */
  8297. if (discipline)
  8298. clonedDisc = CloneDiscipline(discipline);
  8299. else
  8300. clonedDisc = CloneDiscipline(&dftDiscipline);
  8301. nv_stack(np, clonedDisc);
  8302. switch (proctype) {
  8303. case PRINTER_INFO_PROC:
  8304. ksh_eval(pinfo->printerInfoProcCommand);
  8305. break;
  8306. case SELECT_FILE_PROC:
  8307. ksh_eval(pinfo->selectFileProcCommand);
  8308. break;
  8309. case SELECT_PRINTER_PROC:
  8310. ksh_eval(pinfo->selectPrinterProcCommand);
  8311. break;
  8312. case SETUP_PROC:
  8313. ksh_eval(pinfo->setupProcCommand);
  8314. break;
  8315. case VERIFY_PRINTER_PROC:
  8316. ksh_eval(pinfo->verifyPrinterProcCommand);
  8317. break;
  8318. }
  8319. /* We may be nested, so restore old CB_WIDGET & CB_CALL_DATA values */
  8320. RestorePriorEnvVarValues(np2, oldCB_WIDGET_value, np, oldCB_CALL_DATA_value);
  8321. XtFree(oldCB_WIDGET_value);
  8322. XtFree(oldCB_CALL_DATA_value);
  8323. /* Remove the discipline for the hierarchical variables */
  8324. nv_stack(np, NULL);
  8325. FreeDiscipline(clonedDisc);
  8326. /* Free up all of the name/value pairs we created */
  8327. FreeNestedVariables();
  8328. nestingLevel--;
  8329. return;
  8330. }
  8331. void
  8332. stdPrinterInfoProc(
  8333. void *widget,
  8334. DtPrintSetupData *callData)
  8335. {
  8336. stdPrintSetupProc(PRINTER_INFO_PROC, widget, callData);
  8337. return;
  8338. }
  8339. void
  8340. stdSelectFileProc(
  8341. void *widget,
  8342. DtPrintSetupData *callData)
  8343. {
  8344. stdPrintSetupProc(SELECT_FILE_PROC, widget, callData);
  8345. return;
  8346. }
  8347. void
  8348. stdSelectPrinterProc(
  8349. void *widget,
  8350. DtPrintSetupData *psd)
  8351. {
  8352. stdPrintSetupProc(SELECT_PRINTER_PROC, widget, psd);
  8353. return;
  8354. }
  8355. void
  8356. stdSetupProc(
  8357. void *widget,
  8358. DtPrintSetupData *callData)
  8359. {
  8360. stdPrintSetupProc(SETUP_PROC, widget, callData);
  8361. return;
  8362. }
  8363. void
  8364. stdVerifyPrinterProc(
  8365. void *widget,
  8366. DtPrintSetupData *callData)
  8367. {
  8368. stdPrintSetupProc(VERIFY_PRINTER_PROC, widget, callData);
  8369. return;
  8370. }
  8371. void dtksh_init()
  8372. {
  8373. ADDBUILTIN("XtMainLoop", do_XtMainLoop);
  8374. ADDBUILTIN("DtLoadWidget", do_DtLoadWidget);
  8375. ADDBUILTIN("DtWidgetInfo", do_DtWidgetInfo);
  8376. ADDBUILTIN("XBell", do_XBell);
  8377. ADDBUILTIN("XRootWindowOfScreen", do_XRootWindowOfScreen);
  8378. ADDBUILTIN("XWidthOfScreen", do_XWidthOfScreen);
  8379. ADDBUILTIN("XHeightOfScreen", do_XHeightOfScreen);
  8380. ADDBUILTIN("XDefineCursor", do_XDefineCursor);
  8381. ADDBUILTIN("XUndefineCursor", do_XUndefineCursor);
  8382. ADDBUILTIN("XFlush", do_XFlush);
  8383. ADDBUILTIN("XSync", do_XSync);
  8384. ADDBUILTIN("XRaiseWindow", do_XRaiseWindow);
  8385. ADDBUILTIN("XtInitialize", do_XtInitialize);
  8386. ADDBUILTIN("XtIsSensitive", do_XtIsSensitive);
  8387. ADDBUILTIN("XtIsShell", do_XtIsShell);
  8388. ADDBUILTIN("XtIsRealized", do_XtIsRealized);
  8389. ADDBUILTIN("XtIsManaged", do_XtIsManaged);
  8390. ADDBUILTIN("XtCreateManagedWidget", do_XtCreateManagedWidget);
  8391. ADDBUILTIN("XtCreateApplicationShell", do_XtCreateApplicationShell);
  8392. ADDBUILTIN("XtCreateWidget", do_XtCreateWidget);
  8393. ADDBUILTIN("XtDestroyWidget", do_XtDestroyWidget);
  8394. ADDBUILTIN("XtSetValues", do_XtSetValues);
  8395. ADDBUILTIN("XtSetSensitive", do_XtSetSensitive);
  8396. ADDBUILTIN("XtAugmentTranslations", do_XtAugmentTranslations);
  8397. ADDBUILTIN("XtOverrideTranslations", do_XtOverrideTranslations);
  8398. ADDBUILTIN("XtUninstallTranslations", do_XtUninstallTranslations);
  8399. ADDBUILTIN("XtAddCallback", do_XtAddCallback);
  8400. ADDBUILTIN("XtRemoveCallback", do_XtRemoveCallback);
  8401. ADDBUILTIN("XtRemoveAllCallbacks", do_XtRemoveAllCallbacks);
  8402. ADDBUILTIN("XtCallCallbacks", do_XtCallCallbacks);
  8403. ADDBUILTIN("XtHasCallbacks", do_XtHasCallbacks);
  8404. ADDBUILTIN("XtAddEventHandler", do_XtAddEventHandler);
  8405. ADDBUILTIN("XtRemoveEventHandler", do_XtRemoveEventHandler);
  8406. ADDBUILTIN("XtGetValues", do_XtGetValues);
  8407. ADDBUILTIN("XtCreatePopupShell", do_XtCreatePopupShell);
  8408. ADDBUILTIN("XtPopup", do_XtPopup);
  8409. ADDBUILTIN("XtPopdown", do_XtPopdown);
  8410. ADDBUILTIN("XtMapWidget", do_XtMapWidget);
  8411. ADDBUILTIN("XtUnmapWidget", do_XtUnmapWidget);
  8412. ADDBUILTIN("XtManageChild", do_XtManageChildren);
  8413. ADDBUILTIN("XtManageChildren", do_XtManageChildren);
  8414. ADDBUILTIN("XtIsSubclass", do_XtIsSubclass);
  8415. ADDBUILTIN("XtClass", do_XtClass);
  8416. ADDBUILTIN("XtUnmanageChild", do_XtUnmanageChildren);
  8417. ADDBUILTIN("XtUnmanageChildren", do_XtUnmanageChildren);
  8418. ADDBUILTIN("XtAddTimeOut", do_XtAddTimeOut);
  8419. ADDBUILTIN("XtRemoveTimeOut", do_XtRemoveTimeOut);
  8420. ADDBUILTIN("XtAddInput", do_XtAddInput);
  8421. ADDBUILTIN("XtRemoveInput", do_XtRemoveInput);
  8422. ADDBUILTIN("XtAddWorkProc", do_XtAddWorkProc);
  8423. ADDBUILTIN("XtRemoveWorkProc", do_XtRemoveWorkProc);
  8424. ADDBUILTIN("XtRealizeWidget", do_XtRealizeWidget);
  8425. ADDBUILTIN("XtUnrealizeWidget", do_XtUnrealizeWidget);
  8426. ADDBUILTIN("DtSessionRestorePath", do_DtSessionRestorePath);
  8427. ADDBUILTIN("DtSessionSavePath", do_DtSessionSavePath);
  8428. ADDBUILTIN("DtShellIsIconified", do_DtShellIsIconified);
  8429. ADDBUILTIN("DtSetStartupCommand", do_DtSetStartupCommand);
  8430. ADDBUILTIN("DtSetIconifyHint", do_DtSetIconifyHint);
  8431. ADDBUILTIN("DtWsmAddWorkspaceFunctions", do_DtWsmAddWorkspaceFunctions);
  8432. ADDBUILTIN("DtWsmRemoveWorkspaceFunctions", do_DtWsmRemoveWorkspaceFunctions);
  8433. ADDBUILTIN("DtWsmGetCurrentWorkspace", do_DtWsmGetCurrentWorkspace);
  8434. ADDBUILTIN("DtWsmSetCurrentWorkspace", do_DtWsmSetCurrentWorkspace);
  8435. ADDBUILTIN("DtWsmGetWorkspaceList", do_DtWsmGetWorkspaceList);
  8436. ADDBUILTIN("DtWsmGetWorkspacesOccupied", do_DtWsmGetWorkspacesOccupied);
  8437. ADDBUILTIN("DtWsmSetWorkspacesOccupied", do_DtWsmSetWorkspacesOccupied);
  8438. ADDBUILTIN("DtWsmGetCurrentBackdropWindow", do_DtWsmGetCurrentBackdropWindow);
  8439. ADDBUILTIN("DtWsmOccupyAllWorkspaces", do_DtWsmOccupyAllWorkspaces);
  8440. ADDBUILTIN("DtGetHourGlassCursor", do__DtGetHourGlassCursor);
  8441. ADDBUILTIN("DtTurnOnHourGlass", do__DtTurnOnHourGlass);
  8442. ADDBUILTIN("DtTurnOffHourGlass", do__DtTurnOffHourGlass);
  8443. ADDBUILTIN("_DtGetHourGlassCursor", do__DtGetHourGlassCursor);
  8444. ADDBUILTIN("_DtTurnOnHourGlass", do__DtTurnOnHourGlass);
  8445. ADDBUILTIN("_DtTurnOffHourGlass", do__DtTurnOffHourGlass);
  8446. ADDBUILTIN("DtWsmAddCurrentWorkspaceCallback", do_DtWsmAddCurrentWorkspaceCallback);
  8447. ADDBUILTIN("DtWsmRemoveWorkspaceCallback", do_DtWsmRemoveWorkspaceCallback);
  8448. ADDBUILTIN("DtDbLoad", do_DtDbLoad);
  8449. ADDBUILTIN("DtDbReloadNotify", do_DtDbReloadNotify);
  8450. ADDBUILTIN("DtActionExists", do_DtActionExists);
  8451. ADDBUILTIN("DtActionLabel", do_DtActionLabel);
  8452. ADDBUILTIN("DtActionDescription", do_DtActionDescription);
  8453. ADDBUILTIN("DtActionInvoke", do_DtActionInvoke);
  8454. ADDBUILTIN("DtDtsLoadDataTypes", do_DtDtsLoadDataTypes);
  8455. ADDBUILTIN("DtDtsFileToDataType", do_DtDtsFileToDataType);
  8456. ADDBUILTIN("DtDtsFileToAttributeValue", do_DtDtsFileToAttributeValue);
  8457. ADDBUILTIN("DtDtsFileToAttributeList", do_DtDtsFileToAttributeList);
  8458. ADDBUILTIN("DtDtsDataTypeToAttributeValue", do_DtDtsDataTypeToAttributeValue);
  8459. ADDBUILTIN("DtDtsDataTypeToAttributeList", do_DtDtsDataTypeToAttributeList);
  8460. ADDBUILTIN("DtDtsFindAttribute", do_DtDtsFindAttribute);
  8461. ADDBUILTIN("DtDtsDataTypeNames", do_DtDtsDataTypeNames);
  8462. ADDBUILTIN("DtDtsSetDataType", do_DtDtsSetDataType);
  8463. ADDBUILTIN("DtDtsDataTypeIsAction", do_DtDtsDataTypeIsAction);
  8464. ADDBUILTIN("ttdt_open", do_ttdt_open);
  8465. ADDBUILTIN("ttdt_close", do_ttdt_close);
  8466. ADDBUILTIN("tttk_Xt_input_handler", do_tttk_Xt_input_handler);
  8467. ADDBUILTIN("ttdt_session_join", do_ttdt_session_join);
  8468. ADDBUILTIN("ttdt_session_quit", do_ttdt_session_quit);
  8469. ADDBUILTIN("ttdt_file_event", do_ttdt_file_event);
  8470. ADDBUILTIN("ttdt_file_join", do_ttdt_file_join);
  8471. ADDBUILTIN("ttdt_file_quit", do_ttdt_file_quit);
  8472. ADDBUILTIN("ttdt_Get_Modified", do_ttdt_Get_Modified);
  8473. ADDBUILTIN("ttdt_Save", do_ttdt_Save);
  8474. ADDBUILTIN("ttdt_Revert", do_ttdt_Revert);
  8475. ADDBUILTIN("tt_error_pointer", do_tt_error_pointer);
  8476. ADDBUILTIN("tttk_message_destroy", do_tttk_message_destroy);
  8477. ADDBUILTIN("tttk_message_reject", do_tttk_message_reject);
  8478. ADDBUILTIN("tttk_message_fail", do_tttk_message_fail);
  8479. ADDBUILTIN("tt_file_netfile", do_tt_file_netfile);
  8480. ADDBUILTIN("tt_netfile_file", do_tt_netfile_file);
  8481. ADDBUILTIN("tt_host_file_netfile", do_tt_host_file_netfile);
  8482. ADDBUILTIN("tt_host_netfile_file", do_tt_host_netfile_file);
  8483. ADDBUILTIN("tt_message_reply", do_tt_message_reply);
  8484. ADDBUILTIN("XClearArea", do_XClearArea);
  8485. ADDBUILTIN("XClearWindow", do_XClearWindow);
  8486. ADDBUILTIN("XCopyArea", do_XCopyArea);
  8487. ADDBUILTIN("XDrawArc", do_XDrawArc);
  8488. ADDBUILTIN("XDrawImageString", do_XDrawImageString);
  8489. ADDBUILTIN("XDrawLine", do_XDrawLine);
  8490. ADDBUILTIN("XDrawLines", do_XDrawLines);
  8491. ADDBUILTIN("XDrawPoint", do_XDrawPoint);
  8492. ADDBUILTIN("XDrawPoints", do_XDrawPoints);
  8493. ADDBUILTIN("XDrawRectangle", do_XDrawRectangle);
  8494. ADDBUILTIN("XDrawSegments", do_XDrawSegments);
  8495. ADDBUILTIN("XDrawString", do_XDrawString);
  8496. ADDBUILTIN("XFillArc", do_XFillArc);
  8497. ADDBUILTIN("XFillPolygon", do_XFillPolygon);
  8498. ADDBUILTIN("XFillRectangle", do_XFillRectangle);
  8499. ADDBUILTIN("XTextWidth", do_XTextWidth);
  8500. ADDBUILTIN("XtDisplay", do_XtDisplay);
  8501. ADDBUILTIN("XtDisplayOfObject", do_XtDisplayOfObject);
  8502. ADDBUILTIN("XtNameToWidget", do_XtNameToWidget);
  8503. ADDBUILTIN("XtScreen", do_XtScreen);
  8504. ADDBUILTIN("XtWindow", do_XtWindow);
  8505. ADDBUILTIN("XtParent", do_XtParent);
  8506. ADDBUILTIN("XtLastTimestampProcessed", do_XtLastTimestampProcessed);
  8507. ADDBUILTIN("catopen", do_catopen);
  8508. ADDBUILTIN("catgets", do_catgets);
  8509. ADDBUILTIN("catclose", do_catclose);
  8510. ADDBUILTIN("XmCreateArrowButton", do_XmCreateArrowButton);
  8511. ADDBUILTIN("XmCreateArrowButtonGadget", do_XmCreateArrowButtonGadget);
  8512. ADDBUILTIN("XmCreateBulletinBoard", do_XmCreateBulletinBoard);
  8513. ADDBUILTIN("XmCreateBulletinBoardDialog", do_XmCreateBulletinBoardDialog);
  8514. ADDBUILTIN("XmCreateCascadeButton", do_XmCreateCascadeButton);
  8515. ADDBUILTIN("XmCreateCascadeButtonGadget", do_XmCreateCascadeButtonGadget);
  8516. ADDBUILTIN("XmCreateComboBox", do_XmCreateComboBox);
  8517. ADDBUILTIN("XmCreateCommand", do_XmCreateCommand);
  8518. ADDBUILTIN("XmCreateDialogShell", do_XmCreateDialogShell);
  8519. ADDBUILTIN("XmCreateDrawingArea", do_XmCreateDrawingArea);
  8520. ADDBUILTIN("XmCreateDrawnButton", do_XmCreateDrawnButton);
  8521. ADDBUILTIN("XmCreateErrorDialog", do_XmCreateErrorDialog);
  8522. ADDBUILTIN("XmCreateFileSelectionBox", do_XmCreateFileSelectionBox);
  8523. ADDBUILTIN("XmCreateFileSelectionDialog", do_XmCreateFileSelectionDialog);
  8524. ADDBUILTIN("XmCreateForm", do_XmCreateForm);
  8525. ADDBUILTIN("XmCreateFormDialog", do_XmCreateFormDialog);
  8526. ADDBUILTIN("XmCreateFrame", do_XmCreateFrame);
  8527. ADDBUILTIN("XmCreateInformationDialog", do_XmCreateInformationDialog);
  8528. ADDBUILTIN("XmCreateLabel", do_XmCreateLabel);
  8529. ADDBUILTIN("XmCreateLabelGadget", do_XmCreateLabelGadget);
  8530. ADDBUILTIN("XmCreateList", do_XmCreateList);
  8531. ADDBUILTIN("XmCreateMainWindow", do_XmCreateMainWindow);
  8532. ADDBUILTIN("XmCreateMenuBar", do_XmCreateMenuBar);
  8533. ADDBUILTIN("XmCreateMenuShell", do_XmCreateMenuShell);
  8534. ADDBUILTIN("XmCreateMessageBox", do_XmCreateMessageBox);
  8535. ADDBUILTIN("XmCreateOptionMenu", do_XmCreateOptionMenu);
  8536. ADDBUILTIN("XmCreatePanedWindow", do_XmCreatePanedWindow);
  8537. ADDBUILTIN("XmCreatePopupMenu", do_XmCreatePopupMenu);
  8538. ADDBUILTIN("XmCreatePromptDialog", do_XmCreatePromptDialog);
  8539. ADDBUILTIN("XmCreatePulldownMenu", do_XmCreatePulldownMenu);
  8540. ADDBUILTIN("XmCreatePushButton", do_XmCreatePushButton);
  8541. ADDBUILTIN("XmCreatePushButtonGadget", do_XmCreatePushButtonGadget);
  8542. ADDBUILTIN("XmCreateQuestionDialog", do_XmCreateQuestionDialog);
  8543. ADDBUILTIN("XmCreateRadioBox", do_XmCreateRadioBox);
  8544. ADDBUILTIN("XmCreateRowColumn", do_XmCreateRowColumn);
  8545. ADDBUILTIN("XmCreateScale", do_XmCreateScale);
  8546. ADDBUILTIN("XmCreateScrollBar", do_XmCreateScrollBar);
  8547. ADDBUILTIN("XmCreateScrolledList", do_XmCreateScrolledList);
  8548. ADDBUILTIN("XmCreateScrolledText", do_XmCreateScrolledText);
  8549. ADDBUILTIN("XmCreateScrolledWindow", do_XmCreateScrolledWindow);
  8550. ADDBUILTIN("XmCreateSelectionBox", do_XmCreateSelectionBox);
  8551. ADDBUILTIN("XmCreateSelectionDialog", do_XmCreateSelectionDialog);
  8552. ADDBUILTIN("XmCreateSeparator", do_XmCreateSeparator);
  8553. ADDBUILTIN("XmCreateSeparatorGadget", do_XmCreateSeparatorGadget);
  8554. ADDBUILTIN("XmCreateText", do_XmCreateText);
  8555. ADDBUILTIN("XmCreateTextField", do_XmCreateTextField);
  8556. ADDBUILTIN("XmCreateToggleButton", do_XmCreateToggleButton);
  8557. ADDBUILTIN("XmCreateToggleButtonGadget", do_XmCreateToggleButtonGadget);
  8558. ADDBUILTIN("XmCreateWarningDialog", do_XmCreateWarningDialog);
  8559. ADDBUILTIN("XmCreateWorkArea", do_XmCreateWorkArea);
  8560. ADDBUILTIN("XmCreateWorkingDialog", do_XmCreateWorkingDialog);
  8561. ADDBUILTIN("DtCreateHelpDialog", do_DtCreateHelpDialog);
  8562. ADDBUILTIN("DtCreateHelpQuickDialog", do_DtCreateHelpQuickDialog);
  8563. ADDBUILTIN("DtCreatePrintSetupBox", do_DtCreatePrintSetupBox);
  8564. ADDBUILTIN("DtCreatePrintSetupDialog", do_DtCreatePrintSetupDialog);
  8565. ADDBUILTIN("DtCreatePDMJobSetup", do_DtCreatePDMJobSetup);
  8566. ADDBUILTIN("DtHelpReturnSelectedWidgetId", do_DtHelpReturnSelectedWidgetId);
  8567. ADDBUILTIN("DtHelpSetCatalogName", do_DtHelpSetCatalogName);
  8568. ADDBUILTIN("DtHelpQuickDialogGetChild", do_DtHelpQuickDialogGetChild);
  8569. ADDBUILTIN("XmCommandAppendValue", do_XmCommandAppendValue);
  8570. ADDBUILTIN("XmCommandError", do_XmCommandError);
  8571. ADDBUILTIN("XmCommandSetValue", do_XmCommandSetValue);
  8572. ADDBUILTIN("XmCommandGetChild", do_XmCommandGetChild);
  8573. ADDBUILTIN("XmMessageBoxGetChild", do_XmMessageBoxGetChild);
  8574. ADDBUILTIN("XmFileSelectionBoxGetChild", do_XmFileSelectionBoxGetChild);
  8575. ADDBUILTIN("XmSelectionBoxGetChild", do_XmSelectionBoxGetChild);
  8576. ADDBUILTIN("XmMainWindowSetAreas", do_XmMainWindowSetAreas);
  8577. ADDBUILTIN("XmMainWindowSep1", do_XmMainWindowSep1);
  8578. ADDBUILTIN("XmMainWindowSep2", do_XmMainWindowSep2);
  8579. ADDBUILTIN("XmMainWindowSep3", do_XmMainWindowSep3);
  8580. ADDBUILTIN("XmProcessTraversal", do_XmProcessTraversal);
  8581. ADDBUILTIN("XmInternAtom", do_XmInternAtom);
  8582. ADDBUILTIN("XmGetAtomName", do_XmGetAtomName);
  8583. ADDBUILTIN("XmGetColors", do_XmGetColors);
  8584. ADDBUILTIN("XmUpdateDisplay", do_XmUpdateDisplay);
  8585. ADDBUILTIN("XmAddWMProtocols", do_XmAddWMProtocols);
  8586. ADDBUILTIN("XmRemoveWMProtocols", do_XmRemoveWMProtocols);
  8587. ADDBUILTIN("XmAddWMProtocolCallback", do_XmAddWMProtocolCallback);
  8588. ADDBUILTIN("XmRemoveWMProtocolCallback", do_XmRemoveWMProtocolCallback);
  8589. ADDBUILTIN("XmMenuPosition", do_XmMenuPosition);
  8590. ADDBUILTIN("XmScaleGetValue", do_XmScaleGetValue);
  8591. ADDBUILTIN("XmScaleSetValue", do_XmScaleSetValue);
  8592. ADDBUILTIN("XmScrollBarGetValues", do_XmScrollBarGetValues);
  8593. ADDBUILTIN("XmScrollBarSetValues", do_XmScrollBarSetValues);
  8594. ADDBUILTIN("XmScrollVisible", do_XmScrollVisible);
  8595. ADDBUILTIN("XmToggleButtonGetState", do_XmToggleButtonGetState);
  8596. ADDBUILTIN("XmToggleButtonGadgetGetState", do_XmToggleButtonGadgetGetState);
  8597. ADDBUILTIN("XmToggleButtonSetState", do_XmToggleButtonSetState);
  8598. ADDBUILTIN("XmToggleButtonGadgetSetState", do_XmToggleButtonGadgetSetState);
  8599. ADDBUILTIN("XmIsTraversable", do_XmIsTraversable);
  8600. ADDBUILTIN("XmOptionButtonGadget", do_XmOptionButtonGadget);
  8601. ADDBUILTIN("XmOptionLabelGadget", do_XmOptionLabelGadget);
  8602. ADDBUILTIN("XmGetVisibility", do_XmGetVisibility);
  8603. ADDBUILTIN("XmGetTearOffControl", do_XmGetTearOffControl);
  8604. ADDBUILTIN("XmGetTabGroup", do_XmGetTabGroup);
  8605. ADDBUILTIN("XmGetPostedFromWidget", do_XmGetPostedFromWidget);
  8606. ADDBUILTIN("XmGetFocusWidget", do_XmGetFocusWidget);
  8607. ADDBUILTIN("XmFileSelectionDoSearch", do_XmFileSelectionDoSearch);
  8608. ADDBUILTIN("XmListAddItem", do_XmListAddItem);
  8609. ADDBUILTIN("XmListAddItemUnselected", do_XmListAddItemUnselected);
  8610. ADDBUILTIN("XmListAddItems", do_XmListAddItems);
  8611. ADDBUILTIN("XmListAddItemsUnselected", do_XmListAddItemsUnselected);
  8612. ADDBUILTIN("XmListDeleteAllItems", do_XmListDeleteAllItems);
  8613. ADDBUILTIN("XmListDeleteItem", do_XmListDeleteItem);
  8614. ADDBUILTIN("XmListDeleteItems", do_XmListDeleteItems);
  8615. ADDBUILTIN("XmListDeleteItemsPos", do_XmListDeleteItemsPos);
  8616. ADDBUILTIN("XmListDeletePos", do_XmListDeletePos);
  8617. ADDBUILTIN("XmListDeletePositions", do_XmListDeletePositions);
  8618. ADDBUILTIN("XmListDeselectAllItems", do_XmListDeselectAllItems);
  8619. ADDBUILTIN("XmListDeselectItem", do_XmListDeselectItem);
  8620. ADDBUILTIN("XmListDeselectPos", do_XmListDeselectPos);
  8621. ADDBUILTIN("XmListGetKbdItemPos", do_XmListGetKbdItemPos);
  8622. ADDBUILTIN("XmListGetSelectedPos", do_XmListGetSelectedPos);
  8623. ADDBUILTIN("XmListGetMatchPos", do_XmListGetMatchPos);
  8624. ADDBUILTIN("XmListItemExists", do_XmListItemExists);
  8625. ADDBUILTIN("XmListItemPos", do_XmListItemPos);
  8626. ADDBUILTIN("XmListPosSelected", do_XmListPosSelected);
  8627. ADDBUILTIN("XmListPosToBounds", do_XmListPosToBounds);
  8628. ADDBUILTIN("XmListReplaceItemsPos", do_XmListReplaceItemsPos);
  8629. ADDBUILTIN("XmListReplaceItemsPosUnselected", do_XmListReplaceItemsPosUnselected);
  8630. ADDBUILTIN("XmListSelectItem", do_XmListSelectItem);
  8631. ADDBUILTIN("XmListSelectPos", do_XmListSelectPos);
  8632. ADDBUILTIN("XmListSetAddMode", do_XmListSetAddMode);
  8633. ADDBUILTIN("XmListSetBottomItem", do_XmListSetBottomItem);
  8634. ADDBUILTIN("XmListSetBottomPos", do_XmListSetBottomPos);
  8635. ADDBUILTIN("XmListSetHorizPos", do_XmListSetHorizPos);
  8636. ADDBUILTIN("XmListSetItem", do_XmListSetItem);
  8637. ADDBUILTIN("XmListSetKbdItemPos", do_XmListSetKbdItemPos);
  8638. ADDBUILTIN("XmListSetPos", do_XmListSetPos);
  8639. ADDBUILTIN("XmListUpdateSelectedList", do_XmListUpdateSelectedList);
  8640. ADDBUILTIN("XmTextDisableRedisplay", do_XmTextDisableRedisplay);
  8641. ADDBUILTIN("XmTextEnableRedisplay", do_XmTextEnableRedisplay);
  8642. ADDBUILTIN("XmTextGetTopCharacter", do_XmTextGetTopCharacter);
  8643. ADDBUILTIN("XmTextSetTopCharacter", do_XmTextSetTopCharacter);
  8644. ADDBUILTIN("XmTextScroll", do_XmTextScroll);
  8645. ADDBUILTIN("XmTextFindString", do_XmTextFindString);
  8646. ADDBUILTIN("XmTextGetBaseline", do_XmTextGetBaseline);
  8647. ADDBUILTIN("XmTextGetEditable", do_XmTextGetEditable);
  8648. ADDBUILTIN("XmTextGetInsertionPosition", do_XmTextGetInsertionPosition);
  8649. ADDBUILTIN("XmTextGetLastPosition", do_XmTextGetLastPosition);
  8650. ADDBUILTIN("XmTextGetMaxLength", do_XmTextGetMaxLength);
  8651. ADDBUILTIN("XmTextGetSelection", do_XmTextGetSelection);
  8652. ADDBUILTIN("XmTextGetSelectionPosition", do_XmTextGetSelectionPosition);
  8653. ADDBUILTIN("XmTextGetString", do_XmTextGetString);
  8654. ADDBUILTIN("XmTextInsert", do_XmTextInsert);
  8655. ADDBUILTIN("XmTextPosToXY", do_XmTextPosToXY);
  8656. ADDBUILTIN("XmTextRemove", do_XmTextRemove);
  8657. ADDBUILTIN("XmTextReplace", do_XmTextReplace);
  8658. ADDBUILTIN("XmTextSetEditable", do_XmTextSetEditable);
  8659. ADDBUILTIN("XmTextSetHighlight", do_XmTextSetHighlight);
  8660. ADDBUILTIN("XmTextSetInsertionPosition", do_XmTextSetInsertionPosition);
  8661. ADDBUILTIN("XmTextSetMaxLength", do_XmTextSetMaxLength);
  8662. ADDBUILTIN("XmTextSetSelection", do_XmTextSetSelection);
  8663. ADDBUILTIN("XmTextSetString", do_XmTextSetString);
  8664. ADDBUILTIN("XmTextShowPosition", do_XmTextShowPosition);
  8665. ADDBUILTIN("XmTextXYToPos", do_XmTextXYToPos);
  8666. ADDBUILTIN("XmTextClearSelection", do_XmTextClearSelection);
  8667. ADDBUILTIN("XmTextCopy", do_XmTextCopy);
  8668. ADDBUILTIN("XmTextCut", do_XmTextCut);
  8669. ADDBUILTIN("XmTextPaste", do_XmTextPaste);
  8670. ADDBUILTIN("XmTextSetAddMode", do_XmTextSetAddMode);
  8671. ADDBUILTIN("XmTextFieldGetBaseline", do_XmTextGetBaseline);
  8672. ADDBUILTIN("XmTextFieldGetEditable", do_XmTextGetEditable);
  8673. ADDBUILTIN("XmTextFieldGetInsertionPosition", do_XmTextGetInsertionPosition);
  8674. ADDBUILTIN("XmTextFieldGetLastPosition", do_XmTextGetLastPosition);
  8675. ADDBUILTIN("XmTextFieldGetMaxLength", do_XmTextGetMaxLength);
  8676. ADDBUILTIN("XmTextFieldGetSelection", do_XmTextGetSelection);
  8677. ADDBUILTIN("XmTextFieldGetSelectionPosition", do_XmTextGetSelectionPosition);
  8678. ADDBUILTIN("XmTextFieldGetString", do_XmTextGetString);
  8679. ADDBUILTIN("XmTextFieldInsert", do_XmTextInsert);
  8680. ADDBUILTIN("XmTextFieldPosToXY", do_XmTextPosToXY);
  8681. ADDBUILTIN("XmTextFieldRemove", do_XmTextRemove);
  8682. ADDBUILTIN("XmTextFieldReplace", do_XmTextReplace);
  8683. ADDBUILTIN("XmTextFieldSetEditable", do_XmTextSetEditable);
  8684. ADDBUILTIN("XmTextFieldSetHighlight", do_XmTextSetHighlight);
  8685. ADDBUILTIN("XmTextFieldSetInsertionPosition", do_XmTextSetInsertionPosition);
  8686. ADDBUILTIN("XmTextFieldSetMaxLength", do_XmTextSetMaxLength);
  8687. ADDBUILTIN("XmTextFieldSetSelection", do_XmTextSetSelection);
  8688. ADDBUILTIN("XmTextFieldSetString", do_XmTextSetString);
  8689. ADDBUILTIN("XmTextFieldShowPosition", do_XmTextShowPosition);
  8690. ADDBUILTIN("XmTextFieldXYToPos", do_XmTextXYToPos);
  8691. ADDBUILTIN("XmTextFieldClearSelection", do_XmTextClearSelection);
  8692. ADDBUILTIN("XmTextFieldCopy", do_XmTextCopy);
  8693. ADDBUILTIN("XmTextFieldCut", do_XmTextCut);
  8694. ADDBUILTIN("XmTextFieldPaste", do_XmTextPaste);
  8695. ADDBUILTIN("XmTextFieldSetAddMode", do_XmTextSetAddMode);
  8696. }