kent@ssbell.IMD.Sterling.COM (Kent Landfield) (01/15/90)
Submitted-by: wsl.dec.com!mikey (Mike Yang) Posting-number: Volume 5, Issue 57 Archive-name: xrooms/part07 #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 7 (of 14)." # Contents: ./lib/apps.c ./utils/hash.c ./xrooms/xrSetup.c # ./xrset/xrReq.c # Wrapped by kent@ssbell on Sun Jan 14 21:57:56 1990 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f './lib/apps.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'./lib/apps.c'\" else echo shar: Extracting \"'./lib/apps.c'\" \(12698 characters\) sed "s/^X//" >'./lib/apps.c' <<'END_OF_FILE' X X /*\ X * $Header: apps.c,v 5.2 90/01/11 13:41:55 erik Exp $ X * X * COPYRIGHT 1990 X * DIGITAL EQUIPMENT CORPORATION X * MAYNARD, MASSACHUSETTS X * ALL RIGHTS RESERVED. X * X * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND X * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. X * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE X * FOR ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED X * WARRANTY. X * X * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT X * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN X * ADDITION TO THAT SET FORTH ABOVE. X * X * Permission to use, copy, modify, and distribute this software and its X * documentation for any purpose and without fee is hereby granted, provided X * that the above copyright notice appear in all copies and that both that X * copyright notice and this permission notice appear in supporting X * documentation, and that the name of Digital Equipment Corporation not be X * used in advertising or publicity pertaining to distribution of the X * software without specific, written prior permission. X \*/ X X#define DEBUG_VAR appsDebug X#include "utils.h" X#include "hash.h" X#include "strtbl.h" X#include "rooms.h" X#include "apps.h" X#include "profile.h" X X/***====================================================================***/ X XHashTablePtr pAllApps= NullHashTable; XHashTablePtr pActiveApps= NullHashTable; X Xchar *AppInstanceFormat= "%s-%d"; X X/***====================================================================***/ X Xvoid XDebugPrintApps(name) Xchar *name; X{ XAppPtr pApp; XOpaque astate; X X if (pAllApps!=NullHashTable) { X if (name==NullString) { X uDebug("All Apps:\n"); X uDebugIndent(1); X AppsIterator(AllApps,pApp,astate) { X uDebug("%s (0x%x)\n",appText(pApp),pApp); X appDebugPrint(pApp); X } X AppsEndIterator(astate); X uDebugIndent(-1); X uDebug("ActiveApps:\n"); X uDebugIndent(1); X AppsIterator(ActiveApps,pApp,astate) { X uDebug("%s (0x%x)\n",appText(pApp),pApp); X } X AppsEndIterator(astate); X uDebugIndent(-1); X } X else { X StringToken token; X if (stGetTokenIfExists(name,&token)) { X AppPtr pApp= (AppPtr)htLookup(pAllApps,(GenKey)token); X if (pApp!=NullApp) { X uDebug("%s (0x%x)\n",appText(pApp),pApp); X appDebugPrint(pApp); X } X else uDebug("App %s doesn't exist\n",stText(token)); X } X else uDebug("token %s undefined\n",uStringText(name)); X } X } X else { X uDebug("No apps defined\n"); X } X return; X} X X/***====================================================================***/ X XAppPtr XLookupApp(name) XStringToken name; X{ XAppPtr pApp= NullApp; X X uENTRY1("LookupApp(%s)\n",stText(name)); X if (pAllApps!=NullHashTable) { X pApp= (AppPtr)htLookup(pAllApps,(GenKey)name); X } X uRETURN(pApp); X} X X/***====================================================================***/ X XAppPtr XLookupActiveApp(name) XStringToken name; X{ XAppPtr pApp= NullApp; X X uENTRY1("LookupActiveApp(%s)\n",stText(name)); X if (pActiveApps!=NullHashTable) { X pApp= (AppPtr)htLookup(pActiveApps,(GenKey)name); X } X uRETURN(pApp); X} X X/***====================================================================***/ X XAppPtr XGetApp(name,onlyInactive) XStringToken name; XBoolean onlyInactive; X{ XAppPtr pApp; Xchar *oldName; Xchar *tmpBuf= NullString; Xint count= 1; XBoolean done; X X uENTRY2("GetApp(%s,%s)\n",stText(name),booleanText(onlyInactive)); X X if (pAllApps==NullHashTable) { X pAllApps= htCreate((unsigned)71,genIntegerKeyType, X genPointerDataType); X } X if ((pAllApps==NullHashTable)||(name==NullStringToken)) { X uRETURN(NullApp); X } X X done= False; X do { X pApp= (AppPtr)htLookup(pAllApps,(GenKey)name); X if (pApp!=NullApp) { X if (onlyInactive&&appIsActive(pApp)) { X if (tmpBuf==NullString) { X oldName= stGetString(name); X tmpBuf= (char *)uTmpAlloc(strlen(oldName)+24); X if (tmpBuf==NullString) { X uRETURN(NullApp); X } X } X sprintf(tmpBuf,AppInstanceFormat,oldName,count++); X name= stGetToken(tmpBuf); X } X else { X done= True; X } X } X else { X pApp= appCreate(name,NullAppState,NullAppState); X if (pApp!=NullApp) { X (void)htAdd(pAllApps,(GenKey)name,(GenData)pApp); X (void)profileForApp(name); X } X else { X uWarning("Couldn't create app %s\n",stText(name)); X } X done= True; X } X } while (!done); X X if (tmpBuf!=NullString) { X uTmpFree(NullString); X } X uRETURN(pApp); X} X X/***====================================================================***/ X X/* ARGSUSED */ Xstatic Boolean X_CreateAppRooms(pApp,roomName,pState,pArg) XAppPtr pApp; XStringToken roomName; XAppStatePtr pState; XOpaque pArg; X{ X uENTRY4("_CreateAppRooms(%s,%s,%s,0x%x)\n",appText(pApp),stText(roomName), X asText(pState),pArg); X (void)CreateRoom(roomName); X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XAppActivated(pApp, pRealState) XAppPtr pApp; XAppStatePtr pRealState; X{ XBoolean permanent; XOpaque rstate; XRoomPtr pRoom; X X uENTRY2("AppActivated(%s,%s)\n",appText(pApp),asText(pRealState)); X if ((pApp==NullApp)||(!asLegalReal(pRealState))|| X (asWinState(pRealState)==asInactive)|| X (pAllApps==NullHashTable)) { X uRETURN(False); X } X if (appIsActive(pApp)) { X uRETURN(False); X } X X if (pActiveApps==NullHashTable) { X pActiveApps=htCreate((unsigned)51,genIntegerKeyType,genPointerDataType); X if (pActiveApps==NullHashTable) { X uRETURN(False); X } X } X X if (permanent=appIsPermanent(pApp)) { X (void)appIterate(pApp,_CreateAppRooms,(Opaque)NULL); X } X (void)appSetCurrent(pApp,pRealState,True); X if (!permanent) { X RoomPtr pRoom= GetCurrentRoom(); X AppStatePtr pState; X if (asWinState(pRealState)==asNormal) { X pState= appSetDefault(pApp,pRealState,False); X if (pRoom!=NullRoom) { X appSetRoomState(pApp,roomName(pRoom),pRealState,False); X } X if (pState!=NullAppState) { X asChangeSelected(pState,asWinStateValue,asIconic,0,0, X (unsigned)0,(unsigned)0); X } X } X else if (asWinState(pRealState)==asIconic) { X pState= appSetDefault(pApp,pRealState,False); X } X else if (asWinState(pRealState)==asWithdrawn) { X pState= asDupFully(pRealState); X if (pState!=NullAppState) { X asChangeSelected(pState,asWinStateValue,asIconic,0,0, X (unsigned)0,(unsigned)0); X appSetDefault(pApp,pState,False); X asDestroy(pState); X } X } X } X (void)htAdd(pActiveApps,(GenKey)appName(pApp),(GenData)pApp); X X RoomsIterator(pRoom,rstate) { X roomManageApp(pRoom,pApp); X } X RoomsEndIterator(rstate); X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XAppDeactivated(pApp) XAppPtr pApp; X{ XOpaque rstate; XRoomPtr pRoom; XAppPtr pOldApp; X X uENTRY1("_AppDeactivated(%s)\n",appText(pApp)); X if ((pApp==NullApp)||(pActiveApps==NullHashTable)) { X uRETURN(False); X } X if (!appIsActive(pApp)) { X uRETURN(False); X } X (void)appSetCurrent(pApp,asDefaultReal,True); X X RoomsIterator(pRoom,rstate) { X roomUnmanageApp(pRoom,pApp); X } X RoomsEndIterator(rstate); X X pOldApp= (AppPtr)htRemove(pActiveApps,(GenKey)appName(pApp)); X if (pOldApp!=pApp) { X uInternalError("deactivated %s(0x%x), expected %s(0x%x)\n", X appText(pOldApp),pOldApp, X appText(pApp),pApp); X uRETURN(False); X } X if (!appIsPermanent(pApp)) { X pOldApp= (AppPtr)htRemove(pAllApps,(GenKey)appName(pApp)); X if (pOldApp!=pApp) { X uInternalError("destroyed %s(0x%x), expected %s(0x%x)\n", X appText(pOldApp),pOldApp, X appText(pApp),pApp); X } X profileForAppDestroy(appName(pApp)); X appDestroy(pApp); X } X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XSetAppRoomState(pApp, pRoom, pNewState) XAppPtr pApp; XRoomPtr pRoom; XAppStatePtr pNewState; X{ X X uENTRY3("SetAppRoomState(%s,%s,%s)\n",appText(pApp),roomText(pRoom), X asText(pNewState)); X if (pRoom==NullRoom) X pRoom= GetCurrentRoom(); X if ((pApp==NullApp)||(pNewState==NullAppState)||(pRoom==NullRoom)|| X (!asLegalReal(pNewState))) { X uRETURN(False); X } X if (!appIsActive(pApp)) { X if(appSetRoomState(pApp,roomName(pRoom),pNewState,False)==NullAppState){ X uRETURN(False); X } X } X else { X Boolean ok= roomChangeAppLocalState(pRoom,pApp,pNewState); X uRETURN(ok); X } X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XSetAppPermanence(pApp,permanent) XAppPtr pApp; XBoolean permanent; X{ XBoolean ok= True; X X uENTRY2("SetAppPermanence(%s,%s)\n",appText(pApp),booleanText(permanent)); X if (pApp==NullApp) { X uRETURN(False); X } X if ((permanent)&&(!appIsPermanent(pApp))) { X ok= profileForApp(appName(pApp)); X ok= appSetPermanence(pApp,True)&&ok; X } X else if ((!permanent)&&(appIsPermanent(pApp))) { X ok= appSetPermanence(pApp,False); X } X uRETURN(ok); X} X X/***====================================================================***/ X XBoolean XAppStateChanged(pApp, pNewState) XAppPtr pApp; XAppStatePtr pNewState; X{ XRoomPtr pRoom; X X uENTRY2("AppStateChanged(%s,%s)\n",appText(pApp),asText(pNewState)); X if ((pApp==NullApp)||(pNewState==NullAppState)|| X (asWinState(pNewState)==asInactive)) { X uRETURN(False); X } X if (!appIsActive(pApp)) { X uRETURN(False); X } X X if (appSetCurrent(pApp,pNewState,True)!=NullAppState) { X if (asWinState(pNewState)!=asWithdrawn) { X pRoom= GetCurrentRoom(); X if (pRoom!=NullRoom) { X (void)roomAppRealStateChanged(pRoom,pApp,pNewState); X } X } X uRETURN(True); X } X uRETURN(False); X} X X/***====================================================================***/ X Xstatic AppsIterFunc appsIterFunc; X Xstatic Boolean X_AppsIterator(row,keyIn,dataIn,arg) Xunsigned row; XGenKey keyIn; XGenData dataIn; XOpaque arg; X{ XStringToken key= (StringToken)keyIn; XAppPtr pApp= (AppPtr)dataIn; XBoolean ok; X X uENTRY4("_AppsIterator(%d,%s,%s,0x%x)\n",row,stText(key),appText(pApp),arg); X ok= (*appsIterFunc)(arg,pApp); X uRETURN(ok); X} X Xvoid XAppsIterate(func,arg) XAppsIterFunc func; XOpaque arg; X{ X uENTRY2("AppsIterate(0x%x,0x%x)\n",func,arg); X if ((func==NULL)||(pAllApps==NullHashTable)) { X uVOIDRETURN; X } X appsIterFunc= func; X (void)htIterate(pAllApps,_AppsIterator,arg); X uVOIDRETURN; X} X Xvoid XActiveAppsIterate(func,arg) XAppsIterFunc func; XOpaque arg; X{ X uENTRY2("AppsIterate(0x%x,0x%x)\n",func,arg); X if ((func==NULL)||(pActiveApps==NullHashTable)) { X uVOIDRETURN; X } X appsIterFunc= func; X (void)htIterate(pActiveApps,_AppsIterator,arg); X uVOIDRETURN; X} X X/***====================================================================***/ X Xstruct appsIterState { X HashTablePtr pTbl; X Opaque tblState; X} iState; X XBoolean X_AppsInitIter(which,pOutState) Xunsigned which; XOpaque *pOutState; X{ XBoolean ok= False; XHashTablePtr pTbl; XOpaque tblState; Xstruct appsIterState *pState; X X uENTRY2("_AppsInitIter(%d,0x%x)\n",which,pOutState); X if ((which==ActiveApps)&&(pActiveApps!=NullHashTable)) { X pTbl= pActiveApps; X ok= _htInitIter(pActiveApps,&tblState); X } X else if ((which==AllApps)&&(pAllApps!=NullHashTable)) { X pTbl= pAllApps; X ok= _htInitIter(pAllApps,&tblState); X } X if (ok) { X if (iState.pTbl==NullHashTable) X pState= &iState; X else pState= uTypedAlloc(struct appsIterState); X if (pState!=(struct appsIterState *) NULL) { X pState->pTbl= pTbl; X pState->tblState= tblState; X *pOutState= (Opaque)pState; X } X else ok= False; X } X if (!ok) X *pOutState= (Opaque)NULL; X uRETURN(ok); X} X X/***====================================================================***/ X XBoolean X_AppsIterNext(pInState, ppApp) XOpaque pInState; XAppPtr *ppApp; X{ XBoolean ok= False; XGenKey key; XGenData data; Xstruct appsIterState *pState= (struct appsIterState *)pInState; X X uENTRY2("_AppsIterNext(0x%x,0x%x)\n",pInState,ppApp); X if (pInState!=(Opaque)NULL) { X ok= _htIterNext(pState->pTbl,pState->tblState,&key,&data); X if (ok) { X *ppApp= (AppPtr)data; X } X else *ppApp= NullApp; X } X uRETURN(ok); X} X X/***====================================================================***/ X Xvoid XAppsEndIterator(state) XOpaque state; X{ Xstruct appsIterState *pState= (struct appsIterState *)state; X X uENTRY1("AppsEndIterator(0x%x)\n",state); X if (state!=(Opaque)NULL) { X htEndIterator(pState->pTbl,pState->tblState); X pState->pTbl= NullHashTable; X pState->tblState= (Opaque)NULL; X if (pState!=&iState) { X (void)uFree((Opaque)pState); X } X } X uVOIDRETURN; X} END_OF_FILE if test 12698 -ne `wc -c <'./lib/apps.c'`; then echo shar: \"'./lib/apps.c'\" unpacked with wrong size! fi # end of './lib/apps.c' fi if test -f './utils/hash.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'./utils/hash.c'\" else echo shar: Extracting \"'./utils/hash.c'\" \(13112 characters\) sed "s/^X//" >'./utils/hash.c' <<'END_OF_FILE' X X /*\ X * $Header: hash.c,v 5.0 90/01/10 06:50:45 erik Exp $ X * X * COPYRIGHT 1990 X * DIGITAL EQUIPMENT CORPORATION X * MAYNARD, MASSACHUSETTS X * ALL RIGHTS RESERVED. X * X * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND X * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. X * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE X * FOR ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED X * WARRANTY. X * X * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT X * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN X * ADDITION TO THAT SET FORTH ABOVE. X * X * Permission to use, copy, modify, and distribute this software and its X * documentation for any purpose and without fee is hereby granted, provided X * that the above copyright notice appear in all copies and that both that X * copyright notice and this permission notice appear in supporting X * documentation, and that the name of Digital Equipment Corporation not be X * used in advertising or publicity pertaining to distribution of the X * software without specific, written prior permission. X \*/ X X#define DEBUG_VAR hashDebug X X#include "utils.h" X#include "hashstr.h" X X/***====================================================================***/ X X#define _htHash(pt,k) ((pt)->hashFunc?(*(pt)->hashFunc)(k):(unsigned)(k)) X#define _htCompareKey(pt,k1,k2) (_genCompareKey((pt)->keyType,k1,k2)) X#define _htStoreKey(pt,k) (_genStoreKey((pt)->keyType,k)) X#define _htRemoveKey(pt,k) _genRemoveKey((pt)->keyType,k) X#define _htNullKey(pt) (_genNullKey((pt)->keyType)) X X#define _htStoreData(pt,d) (_genStoreData((pt)->dataType,d)) X#define _htReplaceData(pt,nd,pod) (_genReplaceData((pt)->dataType,nd,pod)) X#define _htRemoveData(pt,d) (_genRemoveData((pt)->dataType,d)) X#define _htNullData(pt) (_genNullData((pt)->dataType)) X X/***====================================================================***/ X XHashTablePtr XhtCreate(size,keyType,dataType) Xunsigned size; XGenKeyDescPtr keyType; XGenDataDescPtr dataType; X{ XHashTablePtr pTbl; X X uENTRY3("htCreate(%d,0x%x,0x%x)\n",size,keyType,dataType); X X if (size<1) uRETURN(NULL); X if (keyType==NULL) keyType= genDefaultKeyType; X if (dataType==NULL) dataType= genDefaultDataType; X X uASSERT("htCreate",((keyType!=NULL)&&(dataType!=NULL))) X X pTbl= uTypedAlloc(HashTableRec); X if (pTbl!=NULL) { X pTbl->hashFunc= keyType->dfltHash; X pTbl->keyType= keyType; X pTbl->dataType= dataType; X X pTbl->nStored= 0; X pTbl->nBuckets= size; X pTbl->ppBuckets= uTypedCalloc(size,HashBucketPtr); X if (pTbl->ppBuckets==NULL) { X uFree((Opaque)pTbl); X uRETURN(NULL); X } X } X uRETURN(pTbl); X} X X/***====================================================================***/ X Xvoid XhtDestroy(pTbl) XHashTablePtr pTbl; X{ Xint i; XHashBucketPtr pBkt,pNext; X X uENTRY1("htDestroy(0x%x)\n",pTbl); X X if ((pTbl==NULL)||(pTbl->ppBuckets==NULL)) X uVOIDRETURN; X X if (pTbl->nStored>0) { X for (i=0;i<pTbl->nBuckets;i++) { X pBkt= pTbl->ppBuckets[i]; X pTbl->ppBuckets[i]= NULL; X while (pBkt!=NULL) { X pNext= pBkt->next; X _htRemoveKey(pTbl,pBkt->key); X (void)_htRemoveData(pTbl,pBkt->data); X pBkt->next= NULL; X uFree((Opaque)pBkt); X pTbl->nStored--; X pBkt= pNext; X } X } X } X uASSERT("htDestroy",pTbl->nStored==0); X uFree((Opaque)pTbl->ppBuckets); X pTbl->ppBuckets= NULL; X uFree((Opaque)pTbl); X uVOIDRETURN; X} X X/***====================================================================***/ X XGenData XhtAdd(pTbl,key,data) XHashTablePtr pTbl; XGenKey key; XGenData data; X{ Xunsigned index; XHashBucketPtr pBkt; X X uENTRY3("htAdd(0x%x,0x%x,0x%x)\n",pTbl,key,data); X X if (pTbl==NULL) { X uRETURN((GenData)NULL); X } X X uASSERT("htAdd",pTbl->nBuckets>0); X X index= _htHash(pTbl,key)%pTbl->nBuckets; X X pBkt= pTbl->ppBuckets[index]; X X while (pBkt!=NULL) { /* search through bucket list for match */ X if (_htCompareKey(pTbl,key,pBkt->key)==Equal) break; X pBkt= pBkt->next; X } X X if (pBkt==NULL) { /* no matching bucket, add */ X pBkt= uTypedAlloc(HashBucketRec); X if (pBkt==NULL) { /* alloc failed */ X uRETURN(pTbl->dataType->null); X } X pBkt->key= _htStoreKey(pTbl,key); X pBkt->data= _htStoreData(pTbl,data); X pBkt->next= pTbl->ppBuckets[index]; X pTbl->ppBuckets[index]= pBkt; X pTbl->nStored++; X uRETURN(_htNullData(pTbl)); X } X else { /* matching bucket, replace */ X GenData oldData= pBkt->data; X X pBkt->data= _htReplaceData(pTbl,data,&oldData); X uRETURN(oldData); X } X} X X/***====================================================================***/ X XGenData XhtLookup(pTbl,key) XHashTablePtr pTbl; XGenKey key; X{ Xunsigned index; XHashBucketPtr pBkt; X X uENTRY2("htLookup(0x%x,0x%x)\n",pTbl,key); X X if (pTbl==NULL) { X uRETURN((GenData)NULL); X } X X uASSERT("htLookup",pTbl->nBuckets>0); X X index= _htHash(pTbl,key)%pTbl->nBuckets; X X pBkt= pTbl->ppBuckets[index]; X X while (pBkt!=NULL) { /* search through bucket list for match */ X if (_htCompareKey(pTbl,key,pBkt->key)==Equal) break; X pBkt= pBkt->next; X } X if (pBkt!=NULL) { X uRETURN(pBkt->data); X } X uRETURN(_htNullData(pTbl)); X} X X/***====================================================================***/ X XGenData XhtRemove(pTbl,key) XHashTablePtr pTbl; XGenKey key; X{ Xunsigned index; XHashBucketPtr pBkt,pLast; XGenData oldData; X X uENTRY2("htRemove(0x%x,0x%x)\n",pTbl,key); X if (pTbl==NULL) X uRETURN((GenData)NULL); X X uASSERT("htRemove",pTbl->nBuckets>0); X X index= _htHash(pTbl,key)%pTbl->nBuckets; X X pBkt= pTbl->ppBuckets[index]; X X pLast= (HashBucketPtr)NULL; X while (pBkt!=NULL) { /* search through bucket list for match */ X if (_htCompareKey(pTbl,key,pBkt->key)==Equal) break; X pLast= pBkt; X pBkt= pBkt->next; X } X if (pBkt!=NULL) { X _htRemoveKey(pTbl,pBkt->key); X oldData= _htRemoveData(pTbl,pBkt->data); X if (pLast) pLast->next= pBkt->next; X else pTbl->ppBuckets[index]= pBkt->next; X pBkt->next= NULL; X uFree((Opaque)pBkt); X pTbl->nStored--; X uRETURN(oldData); X } X uRETURN(_htNullData(pTbl)); X} X X/***====================================================================***/ X Xint XhtSize(pTbl) XHashTablePtr pTbl; X{ X uENTRY1("htSize(0x%x)\n",pTbl); X uRETURN(pTbl->nBuckets); X} X X/***====================================================================***/ X Xint XhtNumStored(pTbl) XHashTablePtr pTbl; X{ X uENTRY1("htNumStored(0x%x)\n",pTbl); X uRETURN(pTbl->nStored); X} X X/***====================================================================***/ X XBoolean XhtResize(pTbl,newSize) XHashTablePtr pTbl; Xint newSize; X{ Xint i,newI,nMoved; XHashBucketPtr *ppNewBuckets; XHashBucketPtr pBkt,pNext; X X uENTRY2("htResize(0x%x,%d)\n",pTbl,newSize); X X if ((pTbl==NULL)||(newSize<1)) X uRETURN(False); X if (pTbl->nBuckets==newSize) X uRETURN(True); X X uASSERT("htResize",pTbl->nBuckets>0); X X ppNewBuckets= uTypedCalloc(newSize,HashBucketPtr); X if (ppNewBuckets==NULL) X uRETURN(False); X X for (nMoved=i=0;i<pTbl->nBuckets;i++) { X pBkt= pTbl->ppBuckets[i]; X while (pBkt) { X pNext= pBkt->next; X newI= _htHash(pTbl,pBkt->key)%newSize; X pBkt->next= ppNewBuckets[newI]; X ppNewBuckets[newI]= pBkt; X pBkt= pNext; X nMoved++; X } X pTbl->ppBuckets[i]= NULL; X } X uASSERT("htResize",nMoved==pTbl->nStored); X uFree((Opaque)pTbl->ppBuckets); X pTbl->nBuckets= newSize; X pTbl->ppBuckets= ppNewBuckets; X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XhtConvertKeys(pTbl, cvtFunc, newKeyType) XHashTablePtr pTbl; XKeyConvertFunc cvtFunc; XGenKeyDescPtr newKeyType; X{ Xint i,newI,nChanged; XHashBucketPtr *ppNewBuckets; XHashBucketPtr pBkt,pNext; XGenKey oldKey; X X uENTRY3("htConvertKeys(0x%x,0x%x,0x%x)\n",pTbl,cvtFunc,newKeyType); X if ((pTbl==NULL)||(cvtFunc==NULL)) X uRETURN(False); X X if (newKeyType==NULL) X newKeyType= genDefaultKeyType; X X if (pTbl->keyType==newKeyType) X uRETURN(True); X X uASSERT("htConvertKeys",pTbl->nBuckets>0); X X ppNewBuckets= uTypedCalloc(pTbl->nBuckets,HashBucketPtr); X if (ppNewBuckets==NULL) X uRETURN(False); X X pTbl->keyType= newKeyType; X for (nChanged=i=0;i<pTbl->nBuckets;i++) { X pBkt= pTbl->ppBuckets[i]; X while (pBkt) { X pNext= pBkt->next; X oldKey= pBkt->key; X pBkt->key= (*cvtFunc)(oldKey); X newI= _htHash(pTbl,pBkt->key)%pTbl->nBuckets; X pBkt->next= ppNewBuckets[newI]; X ppNewBuckets[newI]= pBkt; X pBkt= pNext; X nChanged++; X } X pTbl->ppBuckets[i]= NULL; X } X uASSERT("htConvertKeys",nChanged==pTbl->nStored); X uFree((Opaque)pTbl->ppBuckets); X pTbl->ppBuckets= ppNewBuckets; X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XhtConvertData( pTbl, cvtFunc, newDataType ) XHashTablePtr pTbl; XDataConvertFunc cvtFunc; XGenDataDescPtr newDataType; X{ Xint i,nChanged; XHashBucketPtr pBkt; X X uENTRY3("htConvertData(0x%x,0x%x,0x%x)\n",pTbl,cvtFunc,newDataType); X if ((pTbl==NULL)||(cvtFunc==NULL)) X uRETURN(False); X X if (newDataType==NULL) X newDataType= genDefaultDataType; X X if (pTbl->dataType==newDataType) X uRETURN(True); X X uASSERT("htConvertData",pTbl->nBuckets>0); X X pTbl->dataType= newDataType; X for (nChanged=i=0;i<pTbl->nBuckets;i++) { X pBkt= pTbl->ppBuckets[i]; X while (pBkt!=NULL) { X pBkt->data= (*cvtFunc)(pBkt->data); X pBkt= pBkt->next; X nChanged++; X } X } X uASSERT("htConvertData",nChanged==pTbl->nStored); X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XhtChangeHashFunc(pTbl, newHash) XHashTablePtr pTbl; XHashFunc newHash; X{ Xint i,newI,nChanged; XHashBucketPtr pBkt,pNext; XHashBucketPtr *ppNewBuckets; X X uENTRY2("htChangeHashFunc(0x%x,0x%x)\n",pTbl,newHash); X if (pTbl==NULL) X uRETURN(False); X X if (newHash==NULL) X newHash= pTbl->keyType->dfltHash; X X if (pTbl->hashFunc==newHash) X uRETURN(True); X X uASSERT("htChangeHashFunc",pTbl->nBuckets>0); X X ppNewBuckets= uTypedCalloc(pTbl->nBuckets,HashBucketPtr); X if (ppNewBuckets==NULL) X uRETURN(False); X X pTbl->hashFunc= newHash; X for (nChanged=i=0;i<pTbl->nBuckets;i++) { X pBkt= pTbl->ppBuckets[i]; X while (pBkt) { X pNext= pBkt->next; X newI= _htHash(pTbl,pBkt->key)%pTbl->nBuckets; X pBkt->next= ppNewBuckets[newI]; X ppNewBuckets[newI]= pBkt; X pBkt= pNext; X nChanged++; X } X } X uASSERT("htChangeHashFunc",nChanged==pTbl->nStored); X uFree((Opaque)pTbl->ppBuckets); X pTbl->ppBuckets= ppNewBuckets; X uRETURN(True); X} X X/***====================================================================***/ X Xvoid XhtIterate(pTbl, pFunc, arg) XHashTablePtr pTbl; XHashIterFunc pFunc; XOpaque arg; X{ XHashBucketPtr pBkt; Xint i,nSeen; X X uENTRY3("htIterate(0x%x,0x%x,0x%x)\n",pTbl,pFunc,arg); X if ((!pTbl)||(!pFunc)) X uVOIDRETURN; X X for (nSeen=i=0;i<pTbl->nBuckets;i++) { X pBkt= pTbl->ppBuckets[i]; X while (pBkt) { X if (!(*pFunc)(i,pBkt->key,pBkt->data,arg)) { X uVOIDRETURN; X } X pBkt= pBkt->next; X nSeen++; X } X } X uASSERT("htIterate",nSeen==pTbl->nStored); X uVOIDRETURN; X} X X/***====================================================================***/ X Xstatic struct htIterState { X int index; X HashBucketPtr pBkt; X} iState= { -1, NULL }; X XBoolean X_htInitIter(pTbl, pOutState) XHashTablePtr pTbl; XOpaque *pOutState; X{ Xstruct htIterState *pState; X X uENTRY2("_htInitIter(0x%x,0x%x)\n",pTbl,pOutState); X if ((pTbl!=NullHashTable)&&(pTbl->nStored>0)) { X if (iState.index== -1) pState= &iState; X else pState= uTypedAlloc(struct htIterState); X if (pState!=NULL) { X pState->index= 0; X pState->pBkt= NULL; X *pOutState= (Opaque)pState; X uRETURN(True); X } X } X *pOutState= (Opaque)NULL; X uRETURN(False); X} X X/***====================================================================***/ X XBoolean X_htIterNext(pTbl, pInState, pKey, pData) XHashTablePtr pTbl; XOpaque pInState; XGenKey *pKey; XGenData *pData; X{ Xunsigned i; Xstruct htIterState *pState= (struct htIterState *)pInState; X X uENTRY4("_htIterNext(0x%x,0x%x,0x%x,0x%x)\n",pTbl,pState,pKey,pData); X if ((pTbl!=NullHashTable)&&(pInState!=(Opaque)NULL)) { X if (pState->pBkt!=NULL) { X pState->pBkt= pState->pBkt->next; X } X if (pState->pBkt==NULL) { X for (i= pState->index;i<pTbl->nBuckets;i++) { X if (pTbl->ppBuckets[i]!=NULL) { X pState->pBkt= pTbl->ppBuckets[i]; X pState->index= i+1; X break; X } X } X } X if (pState->pBkt!=NULL){ X *pKey= pState->pBkt->key; X *pData= pState->pBkt->data; X uRETURN(True); X } X } X uRETURN(False); X} X X/***====================================================================***/ X Xvoid XhtEndIterator(pTbl, state) XHashTablePtr pTbl; XOpaque state; X{ Xstruct htIterState *pState= (struct htIterState *)state; X X uENTRY2("htEndIterator(0x%x,%d)\n",pTbl,state); X if (state!=(Opaque)NULL) { X pState->index= -1; X if (pState!=&iState) { X (void)uFree((Opaque)pState); X } X } X uVOIDRETURN; X} END_OF_FILE if test 13112 -ne `wc -c <'./utils/hash.c'`; then echo shar: \"'./utils/hash.c'\" unpacked with wrong size! fi # end of './utils/hash.c' fi if test -f './xrooms/xrSetup.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'./xrooms/xrSetup.c'\" else echo shar: Extracting \"'./xrooms/xrSetup.c'\" \(12133 characters\) sed "s/^X//" >'./xrooms/xrSetup.c' <<'END_OF_FILE' X X /*\ X * $Header: xrSetup.c,v 5.2 90/01/11 15:18:32 erik Exp $ X * X * COPYRIGHT 1990 X * DIGITAL EQUIPMENT CORPORATION X * MAYNARD, MASSACHUSETTS X * ALL RIGHTS RESERVED. X * X * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND X * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. X * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE X * FOR ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED X * WARRANTY. X * X * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT X * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN X * ADDITION TO THAT SET FORTH ABOVE. X * X * Permission to use, copy, modify, and distribute this software and its X * documentation for any purpose and without fee is hereby granted, provided X * that the above copyright notice appear in all copies and that both that X * copyright notice and this permission notice appear in supporting X * documentation, and that the name of Digital Equipment Corporation not be X * used in advertising or publicity pertaining to distribution of the X * software without specific, written prior permission. X \*/ X X#include <X11/Intrinsic.h> X#include <X11/StringDefs.h> X X#define OPAQUE_DEFINED X#define BOOLEAN_DEFINED X#define DEBUG_VAR xrSetupDebug X#include "utils.h" X#include "strtbl.h" X#include "rooms.h" X#include "nameprof.h" X#include "xrDebug.h" X#include "xrApp.h" X#include "xrProfile.h" X#include "xrNames.h" X#include "xrXUtils.h" X#include "xrUI.h" X#include "xrGen.h" X#include "xrooms.h" X X/***====================================================================***/ X Xstatic void XxrUsage() X{ X uInformation("no usage line yet\n"); X exit(0); X} X X/***====================================================================***/ X Xstatic XrmOptionDescRec commandOptions[] = { X {"-allrooms", "allRooms", XrmoptionNoArg, "on" }, X {"-appstransient", "appsTransient",XrmoptionNoArg, "on" }, X {"-appspermanent", "appsTransient",XrmoptionNoArg, "off"}, X {"-autorooms", "allRooms", XrmoptionNoArg, "off"}, X {"-backup", "backupConfig", XrmoptionNoArg, "on" }, X {"-config", "config", XrmoptionSepArg, (caddr_t) NULL}, X {"-confirm", "confirmBox", XrmoptionNoArg, "on" }, X {"-debug", "debugFlags", XrmoptionSepArg, (caddr_t)NULL}, X {"-debugxrooms", "debugXrooms", XrmoptionSepArg, (caddr_t)0}, X {"-dfltroom", "defaultRoom", XrmoptionSepArg, (caddr_t) NULL}, X {"-dxwm", "useDxwm", XrmoptionNoArg, "on"}, X {"-fakeroot", "findFakeRoot", XrmoptionNoArg, "on"}, X {"-fakestate", "findFakeState",XrmoptionNoArg, "on"}, X {"-icccm", "nonICCCM", XrmoptionNoArg, "off"}, X {"-iconifyfirst", "iconifyFirst", XrmoptionNoArg,"on"}, X {"-iconifylast", "iconifyLast", XrmoptionNoArg,"off"}, X {"-ignoreappnames", "useAppNames", XrmoptionNoArg, "off"}, X {"-namelookup", "nameLookup", XrmoptionSepArg, (caddr_t)NULL}, X {"-setupmode", "allowSetupMode",XrmoptionNoArg, "on"}, X {"-noconfirm", "confirmBox", XrmoptionNoArg, "off" }, X {"-nogeometries", "useGeometries",XrmoptionNoArg, "off"}, X {"-nonicccm", "nonICCCM", XrmoptionNoArg, "on" }, X {"-noappnameatom", "appNameAtom", XrmoptionNoArg, (caddr_t)NULL}, X {"-nosetupmode", "allowSetupMode",XrmoptionNoArg, "off"}, X {"-notransients", "manageTransients",XrmoptionNoArg, "off" }, X {"-noversion", "printVersion", XrmoptionNoArg, "off" }, X {"-nowarnings", "printWarnings", XrmoptionNoArg, "off" }, X {"-nowithdrawn", "manageWithdrawn", XrmoptionNoArg, "off" }, X {"-realroot", "findFakeRoot", XrmoptionNoArg, "off" }, X {"-reopenforgeom", "reopenForGeom",XrmoptionNoArg, "on"}, X {"-appnameatom", "appNameAtom", XrmoptionSepArg, (caddr_t)NULL}, X {"-saverooms", "saveRooms", XrmoptionNoArg, "on" }, X {"-saveapps", "saveRooms", XrmoptionNoArg, "off" }, X {"-transients", "manageTransients", XrmoptionNoArg, "on" }, X {"-unmapforgeom", "unmapForGeom", XrmoptionNoArg, "on" }, X {"-unmapforstate", "unmapForState",XrmoptionNoArg, "on" }, X {"-useappnames", "useAppNames", XrmoptionNoArg, "on" }, X {"-useiconnames", "useWindowNames",XrmoptionNoArg, "off" }, X {"-usewinnames", "useWindowNames",XrmoptionNoArg, "on" }, X {"-version", "printVersion", XrmoptionNoArg, "on" }, X {"-warnings", "printWarnings", XrmoptionNoArg, "on" }, X {"-withdrawn", "manageWithdrawn", XrmoptionNoArg, "on" }, X#ifdef UI_ARGS X UI_ARGS X#endif X}; X X/***====================================================================***/ X Xtypedef struct xrLegalArgValues { X String debugSettings; X Boolean printVersion; X Boolean printWarnings; X Boolean allowSetupMode; X X Boolean showAllRooms; X String defaultRoom; X Boolean confirmBox; X X Boolean iconifyFirst; X X Boolean dxwm; X Boolean dfltAppsTransient; X Boolean geometries; X Boolean nonICCCM; X Boolean reopenForGeom; X Boolean unmapForGeom; X Boolean unmapForState; X Boolean manageTransients; X Boolean manageWithdrawn; X X Boolean useAppNames; X Boolean useWindowNames; X char *appNameAtom; X X Boolean backupConfig; X String configFile; X Boolean saveRoomProfiles; X X String nameLookupFunc; X X Boolean findFakeRoot; X Boolean findFakeState; X#ifdef UI_FIELDS X UI_FIELDS X#endif X} xrLegalArgValuesRec,*xrLegalArgValuesPtr; X X#define xrOffset(f) XtOffset(xrLegalArgValuesPtr,f) X X/***====================================================================***/ X Xstatic XtResource resources[] = { X {"allowSetupMode", "AllowSetupMode", XtRBoolean, sizeof(Boolean), X xrOffset(allowSetupMode), XtRImmediate, (caddr_t)True}, X {"allRooms", "AllRooms", XtRBoolean, sizeof(Boolean), X xrOffset(showAllRooms), XtRImmediate, (caddr_t)True}, X {"appNameAtom", "AppNameAtom", XtRString, sizeof(char *), X xrOffset(appNameAtom), XtRString, (caddr_t) "_XROOMS_APP_NAME" }, X {"appsTransient", "AppsTransient", XtRBoolean, sizeof(Boolean), X xrOffset(dfltAppsTransient), XtRImmediate, (caddr_t)True}, X {"backupConfig", "BackupConfigFile", XtRBoolean, sizeof(Boolean), X xrOffset(backupConfig), XtRImmediate, (caddr_t)False}, X {"confirmBox", "ConfirmBox", XtRBoolean, sizeof(Boolean), X xrOffset(confirmBox), XtRImmediate, (caddr_t) True}, X {"config", "ConfigFile", XtRString, sizeof (char *), X xrOffset(configFile), XtRString, (caddr_t) NULL}, X {"debugFlags", "DebugFlags", XtRString, sizeof(char *), X xrOffset(debugSettings), XtRString, (caddr_t) NULL}, X {"defaultRoom", "DefaultRoom", XtRString, sizeof(char *), X xrOffset(defaultRoom), XtRString, (caddr_t) "Main"}, X {"findFakeRoot", "FindFakeRoot", XtRBoolean, sizeof(Boolean), X xrOffset(findFakeRoot), XtRImmediate, (caddr_t) False}, X {"findFakeState", "FindFakeState", XtRBoolean, sizeof(Boolean), X xrOffset(findFakeState), XtRImmediate, (caddr_t) False}, X {"iconifyFirst", "IconifyFirst", XtRBoolean, sizeof(Boolean), X xrOffset(iconifyFirst), XtRImmediate, (caddr_t) True}, X {"manageTransients", "ManageTransients", XtRBoolean, sizeof(Boolean), X xrOffset(manageTransients), XtRImmediate, (caddr_t) False}, X {"manageWithdrawn", "ManageWithdrawn", XtRBoolean, sizeof(Boolean), X xrOffset(manageWithdrawn), XtRImmediate, (caddr_t) False}, X {"nameLookup", "NameLookup", XtRString, sizeof(char *), X xrOffset(nameLookupFunc), XtRString, (caddr_t) "ChooseAppName" }, X {"nonICCCM", "NonICCCM", XtRBoolean, sizeof(Boolean), X xrOffset(nonICCCM), XtRImmediate, (caddr_t)False}, X {"printVersion", "PrintVersion", XtRBoolean, sizeof(Boolean), X xrOffset(printVersion), XtRImmediate, (caddr_t)False}, X {"printWarnings", "PrintWarnings", XtRBoolean, sizeof(Boolean), X xrOffset(printWarnings), XtRImmediate, (caddr_t)False}, X {"reopenForGeom", "ReopenForGeom", XtRBoolean, sizeof(Boolean), X xrOffset(reopenForGeom), XtRImmediate, (caddr_t) False}, X {"saveRooms", "SaveRooms", XtRBoolean, sizeof(Boolean), X xrOffset(saveRoomProfiles), XtRImmediate,(caddr_t)True}, X {"unmapForGeom", "UnmapForGeom", XtRBoolean, sizeof(Boolean), X xrOffset(unmapForGeom), XtRImmediate, (caddr_t) False}, X {"unmapForState", "UnmapForState", XtRBoolean, sizeof(Boolean), X xrOffset(unmapForState), XtRImmediate, (caddr_t) False}, X {"useAppNames", "UseAppNames", XtRBoolean, sizeof(Boolean), X xrOffset(useAppNames), XtRImmediate, (caddr_t) True}, X {"useDxwm", "UseDXWM", XtRBoolean, sizeof(Boolean), X xrOffset(dxwm), XtRImmediate, (caddr_t) False}, X {"useGeometries", "UseGeometries", XtRBoolean, sizeof(Boolean), X xrOffset(geometries), XtRImmediate, (caddr_t) True}, X {"useWindowNames", "UseWindowNames", XtRBoolean, sizeof(Boolean), X xrOffset(useWindowNames), XtRImmediate, (caddr_t) False}, X#ifdef UI_RESOURCES X UI_RESOURCES(xrLegalArgValuesPtr) X#endif X}; X X/***====================================================================***/ X XxrInitializePackages(pRes) XxrLegalArgValuesPtr pRes; X{ X uENTRY1("xrInitializePackages(0x%x)\n",pRes); X X stInit((unsigned)750,(unsigned)20,False,(Opaque)NULL); X asSetScreenSize((unsigned)WidthOfScreen(xroomsScrn), X (unsigned)HeightOfScreen(xroomsScrn)); X SetDefaultRoomFinder(xruiFindDefaultRoom); X X xraInit(); X xrnInit(); X X if (pRes->debugSettings!=NullString) X xrDebugSettings(pRes->debugSettings); X X roomIconifyFirst= pRes->iconifyFirst; X xroomsSetupMode= pRes->allowSetupMode; X if (pRes->showAllRooms) X roomDefaultVisibility= roomAlways|roomVisible; X else roomDefaultVisibility= roomWhenActive|roomWhenNonEmpty; X xroomsPrintWarnings= pRes->printWarnings; X X if (pRes->printVersion) { X uInformation("xrooms version %d.%02d.%02d [%s]\n", X xroomsMajorVersion,xroomsMinorVersion, X xroomsLocalVersion,xroomsCompileStamp); X } X X xruiDefaultRoom= pRes->defaultRoom; X xruiConfirmExit= pRes->confirmBox; X X xraDfltAppsTransient= pRes->dfltAppsTransient; X xraUseGeometries= pRes->geometries; X xraNonICCCM= pRes->nonICCCM; X xraReopenForGeom= pRes->reopenForGeom; X xraUnmapForGeom= pRes->unmapForGeom; X xraUnmapForState= pRes->unmapForState; X xraManageTransients= pRes->manageTransients; X xraManageWithdrawn= pRes->manageWithdrawn; X X xrpfBackupConfig= pRes->backupConfig; X xrpfConfigFile= pRes->configFile; X xrpfSaveRoomProfiles= pRes->saveRoomProfiles; X X xrnUseAppNames= pRes->useAppNames; X xrnUseWindowNames= pRes->useWindowNames; X if ((pRes->appNameAtom!=NullString)&&(strlen(pRes->appNameAtom)>0)) X xrnAppNameAtom= XInternAtom(xroomsDpy,pRes->appNameAtom,False); X else xrnAppNameAtom= None; X X if (pRes->nameLookupFunc!=NullString) { X nprDefaultName= stGetToken(pRes->nameLookupFunc); X xrnNameLookup= nprDefaultName; X } X X xruFindFakeRoot= pRes->findFakeRoot; X xruFindFakeState= pRes->findFakeState; X X if (pRes->dxwm) { X xraNonICCCM= True; X xruFindFakeRoot= True; X xruFindFakeState= True; X xraReopenForGeom= True; X roomIconifyFirst= False; X } X X UI_SETTINGS(pRes); X uVOIDRETURN; X} X X/***====================================================================***/ X Xstatic xrLegalArgValuesRec xrResources; X XBoolean XxrInitialize(argc, argv) Xint argc; Xchar **argv; X{ XWidget topLevel; X X uENTRY2("xrInitialize(%d,0x%x)\n",argc,argv); X if ((argc==2)&&(uStringEqual(argv[1],"-help"))) { X xrUsage(); X /* NOTREACHED */ X } X topLevel = XtInitialize("xrooms", "XRooms", X commandOptions, XtNumber(commandOptions), X &argc, argv); X if (topLevel==(Widget)NULL) { X uRETURN(False); X } X XtGetApplicationResources(topLevel,&xrResources, X resources,XtNumber(resources), X NULL, (Cardinal) 0); X xroomsDpy= XtDisplay(topLevel); X xroomsScrn= XtScreen(topLevel); X X WM_STATE= XInternAtom(xroomsDpy, "WM_STATE", False); X WM_CHANGE_STATE= XInternAtom(xroomsDpy, "WM_CHANGE_STATE", False); X WM_MOVED= XInternAtom(xroomsDpy, "WM_MOVED", False); X XSetErrorHandler(xruIgnoreErrors); X X xrInitializePackages(&xrResources); X X xroomsRealRoot= RootWindowOfScreen(xroomsScrn); X xroomsRoot= xruFindRoot(); X X xrgenInit(xroomsDpy); X xruiInit(topLevel); X uRETURN(True); X} X END_OF_FILE if test 12133 -ne `wc -c <'./xrooms/xrSetup.c'`; then echo shar: \"'./xrooms/xrSetup.c'\" unpacked with wrong size! fi # end of './xrooms/xrSetup.c' fi if test -f './xrset/xrReq.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'./xrset/xrReq.c'\" else echo shar: Extracting \"'./xrset/xrReq.c'\" \(12331 characters\) sed "s/^X//" >'./xrset/xrReq.c' <<'END_OF_FILE' X X /*\ X * $Header: xrReq.c,v 5.0 90/01/10 07:02:47 erik Exp $ X * X * COPYRIGHT 1990 X * DIGITAL EQUIPMENT CORPORATION X * MAYNARD, MASSACHUSETTS X * ALL RIGHTS RESERVED. X * X * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND X * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. X * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE X * FOR ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED X * WARRANTY. X * X * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT X * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN X * ADDITION TO THAT SET FORTH ABOVE. X * X * Permission to use, copy, modify, and distribute this software and its X * documentation for any purpose and without fee is hereby granted, provided X * that the above copyright notice appear in all copies and that both that X * copyright notice and this permission notice appear in supporting X * documentation, and that the name of Digital Equipment Corporation not be X * used in advertising or publicity pertaining to distribution of the X * software without specific, written prior permission. X \*/ X X#define DEBUG_VAR xrreqDebug X#include "utils.h" X#include "strtbl.h" X#include <X11/Xproto.h> X#include <X11/Xatom.h> X#undef True X#undef False X#include "xrReq.h" X X Xint xrreqTimeout= 5; X X/***====================================================================***/ X XStringToken XxrreqGetCurrent(dpy, root) XDisplay *dpy; XWindow root; X{ XStringToken token; Xchar *str; XAtom actualType,*pRtrn; Xint actualFormat,nItems,bytesAfter; X X uENTRY2("xrreqGetCurrent(0x%x,0x%x)\n",dpy,root); X if (XGetWindowProperty(dpy,root,ROOMS_CURRENT,0,1,False,XA_ATOM, X &actualType,&actualFormat,&nItems,&bytesAfter, X (char *)&pRtrn)==Success) { X if ((actualType==XA_ATOM)&&(nItems==1)) { X str= XGetAtomName(dpy,*pRtrn); X XFree(pRtrn); X token= stGetToken(str); X XFree(str); X uRETURN(token); X } X } X uRETURN(NullStringToken); X} X X/***====================================================================***/ X XBoolean XxrreqGetAllRooms(dpy, root, pNRooms, pRooms) XDisplay *dpy; XWindow root; Xint *pNRooms; XStringToken *pRooms; X{ X X uENTRY4("xrreqGetAllRooms(0x%x,0x%x,0x%x,0x%x)\n",dpy,root,pNRooms,pRooms); X uWarning("xrreqGetAllRooms not implemented yet\n"); X uRETURN(False); X} X X/***==================================================================***/ X X Xstatic void XnoPropertyChange() X{ X uFatalError("Xrooms does not appear to be running (timeout)\n"); X} X Xchar * XxrreqGetReply(dpy,root,win) XDisplay *dpy; XWindow root; XWindow win; X{ XXEvent event; Xchar *str= NullString; XBoolean done= False; XAtom actualType,actualFormat,nItems,bytesAfter; X X uENTRY3("xrreqGetReply(0x%x,0x%x,0x%x)\n",dpy,root,win); X#ifndef NO_TIMEOUTS X if (xrreqTimeout>0) X uSetTimeout(xrreqTimeout,0,noPropertyChange); X#endif X while (!done) { X XWindowEvent(dpy,win,PropertyChangeMask,&event); X if ((event.type==PropertyNotify)&& X (event.xproperty.state==PropertyNewValue)&& X (event.xproperty.atom==ROOMS_RETURN)) { X#ifndef NO_TIMEOUTS X if (xrreqTimeout>0) X uClearTimeout(); X#endif X XGetWindowProperty(dpy,win,ROOMS_RETURN,0,10000,True,XA_STRING, X &actualType,&actualFormat,&nItems,&bytesAfter,&str); X XDestroyWindow(dpy,win); X done= True; X } X } X uRETURN(str); X} X X/***==================================================================***/ X XWindow XxrreqGetArgWindow(dpy,root) XDisplay *dpy; XWindow root; X{ XWindow win; XXSetWindowAttributes xswa; X X uENTRY2("xrreqGetArgWindow(0x%x,0x%x)\n",dpy,root); X xswa.override_redirect= True; X xswa.event_mask= PropertyChangeMask; X win= XCreateWindow(dpy,root,0,0,1,1,0,CopyFromParent,InputOutput, X CopyFromParent,CWOverrideRedirect|CWEventMask,&xswa); X if (win==None) { X uFatalError("Couldn't create argument window\n"); X /* NOTREACHED */ X } X uRETURN(win); X} X X/***====================================================================***/ X Xchar * XxrreqStringRequest(dpy,root,req,len,arg) XDisplay *dpy; XWindow root; Xunsigned req; Xint len; Xchar *arg; X{ XxrRequestRec xreq; Xchar *argstr; Xchar *reply; X X uENTRY5("xrreqStringRequest(0x%x,0x%x,0x%x,%d,%s)\n",dpy,root,req,len,arg); X if (arg!=NullString) { X xreq.request= req; X xreq.size= (len+3)/4; X xreq.win= xrreqGetArgWindow(dpy,root); X argstr= (char *)uAlloc(xreq.size); X if (argstr!=NullString) { X bcopy(arg,argstr,len); X XGrabServer(dpy); X if (XChangeProperty(dpy,root,ROOMS_REQUEST,XA_INTEGER,32, X PropModeAppend,&xreq,3)==Success) { X XChangeProperty(dpy,xreq.win,ROOMS_ARGUMENT,XA_STRING,8, X PropModeAppend,argstr,xreq.size*4); X } X XUngrabServer(dpy); X XFlush(dpy); X uFree(argstr); X } X reply= xrreqGetReply(dpy,root,xreq.win); X uRETURN(reply); X } X uRETURN(NullString); X} X X/***==================================================================***/ X XBoolean XxrreqIssueSetState(dpy,root,pArgs) XDisplay *dpy; XWindow root; XxrSetStateArgsPtr pArgs; X{ XBoolean ok; Xint len; Xchar buf[1024],*rtrn; X X uENTRY3("xrreqIssueSetState(0x%x,0x%x,0x%x)\n",dpy,root,pArgs); X if (pArgs->whichPart==0) { X if (pArgs->whichApp==XR_QUERY_APP) X pArgs->whichPart= XR_QUERY_PARTS; X else if (pArgs->toWhat=='P') X pArgs->whichPart= XR_WINSTATE_PART|XR_POSITION_PART; X else pArgs->whichPart= XR_GEOM_PARTS; X } X X buf[0]= pArgs->doWhat; X buf[1]= pArgs->toWhat; X X if (pArgs->whichPart&XR_WINSTATE_PART) buf[2]= '+'; X else buf[2]= '!'; X if (pArgs->whichPart&XR_X_PART) { X if (pArgs->whichPart&XR_X_NEGATIVE) buf[3]= '-'; X else buf[3]= '+'; X } X else if (pArgs->whichPart&XR_QUERY_PARTS) buf[3]= '?'; X else buf[3]= '!'; X X if (pArgs->whichPart&XR_Y_PART) { X if (pArgs->whichPart&XR_Y_NEGATIVE) buf[4]= '-'; X else buf[4]= '+'; X } X else if (pArgs->whichPart&XR_QUERY_PARTS) buf[4]= '?'; X else buf[4]= '!'; X X if (pArgs->whichPart&XR_WIDTH_PART) buf[5]= '+'; X else if (pArgs->whichPart&XR_QUERY_PARTS) buf[5]= '?'; X else buf[5]= '!'; X X if (pArgs->whichPart&XR_HEIGHT_PART) buf[6]= '+'; X else if (pArgs->whichPart&XR_QUERY_PARTS) buf[6]= '?'; X else buf[6]= '!'; X X switch (pArgs->whichState) { X case XR_QUERY_STATE: buf[7]= '?'; break; X case XR_LOCAL_STATE: buf[7]= 'L'; break; X case XR_DFLT_STATE: buf[7]= 'D'; break; X case XR_ALL_STATES: buf[7]= 'A'; break; X case XR_VISIBLE_STATE: X default: buf[7]= 'V'; break; X } X X if ((pArgs->whichApp==XR_NAMED_APP)&&(pArgs->appName==NullString)) X pArgs->whichApp= XR_QUERY_APP; X len= 9; X switch (pArgs->whichApp) { X case XR_LAST_APP: buf[8]= 'L'; break; X case XR_ALL_APPS: buf[8]= 'A'; break; X case XR_ACTIVE_APPS: buf[8]= 'V'; break; X case XR_NAMED_APP: buf[8]= 'N'; X strcpy(&buf[9],pArgs->appName); X len+= strlen(pArgs->appName)+1; X break; X case XR_QUERY_APP: X default: X xrreqTimeout= 30; /* XXX Hack */ X buf[8]= '?'; break; X } X X if ((pArgs->whichRoom==XR_NAMED_ROOM)&&(pArgs->roomName==NullString)) X pArgs->whichRoom= XR_QUERY_ROOM; X switch (pArgs->whichRoom) { X case XR_QUERY_ROOM: buf[len++]= '?'; break; X case XR_LAST_ROOM: buf[len++]= 'L'; break; X case XR_ALL_ROOMS: buf[len++]= 'A'; break; X case XR_VISIBLE_ROOMS: buf[len++]= 'V'; break; X case XR_NAMED_ROOM: buf[len++]= 'N'; X strcpy(&buf[len],pArgs->roomName); X len+= strlen(pArgs->roomName)+1; X break; X default: X case XR_CURRENT_ROOM: buf[len++]= 'C'; break; X } X rtrn= xrreqStringRequest(dpy,root,XR_RQ_SET_STATE,len,buf); X ok= ((rtrn!=NullString)&&(rtrn[0]=='t')); X uRETURN(ok); X} X X/***====================================================================***/ X XBoolean XxrreqIssueRemember(dpy,root,pArgs) XDisplay *dpy; XWindow root; XxrRememberArgsPtr pArgs; X{ XBoolean ok; Xchar buf[264],*rtrn; X X uENTRY3("xrreqIssueRemember(0x%x,0x%x,0x%x)\n",dpy,root,pArgs); X if (pArgs->remember) buf[0]= 'R'; X else buf[0]= 'F'; X X switch (pArgs->whichApp) { X case XR_LAST_APP: buf[1]= 'L'; buf[2]= NUL; break; X case XR_ALL_APPS: buf[1]= 'A'; buf[2]= NUL; break; X case XR_ACTIVE_APPS: buf[1]= 'V'; buf[2]= NUL; break; X case XR_NAMED_APP: buf[1]= 'N'; X strcpy(&buf[2],pArgs->appName); X break; X case XR_QUERY_APP: X default: buf[1]= '?'; buf[2]= NUL; break; X } X rtrn= xrreqStringRequest(dpy,root,XR_RQ_REMEMBER,strlen(buf),buf); X ok= ((rtrn!=NullString)&&(rtrn[0]=='t')); X uRETURN(ok); X} X X/***====================================================================***/ X XBoolean XxrreqIssueVisibility(dpy,root,pArgs) XDisplay *dpy; XWindow root; XxrVisibilityArgsPtr pArgs; X{ XBoolean ok; Xchar buf[264],*rtrn; X X uENTRY3("xrreqIssueVisibility(0x%x,0x%x,0x%x)\n",dpy,root,pArgs); X if (pArgs->visibility&XR_ROOM_ALWAYS) buf[0]= 'A'; X else buf[0]= 'a'; X if (pArgs->visibility&XR_ROOM_WHEN_NON_EMPTY) buf[1]= 'N'; X else buf[1]= 'n'; X if (pArgs->visibility&XR_ROOM_WHEN_ACTIVE) buf[2]= 'A'; X else buf[2]= 'a'; X if (pArgs->visibility&XR_ROOM_VISIBLE) buf[3]= 'V'; X else buf[3]= 'H'; X if (pArgs->checkAuto) buf[4]= '+'; X else buf[4]= '-'; X if (pArgs->createRoom) buf[5]= 'C'; X else buf[5]= 'c'; X X switch (pArgs->whichRoom) { X case XR_LAST_ROOM: buf[6]= 'L'; buf[7]= NUL; break; X case XR_ALL_ROOMS: buf[6]= 'A'; buf[7]= NUL; break; X case XR_VISIBLE_ROOMS: buf[6]= 'V'; buf[7]= NUL; break; X case XR_NAMED_ROOM: buf[6]= 'N'; X strcpy(&buf[7],pArgs->roomName); X break; X case XR_CURRENT_ROOM: X case XR_QUERY_ROOM: X default: buf[6]= 'C'; buf[7]= NUL; break; X } X rtrn= xrreqStringRequest(dpy,root,XR_RQ_SET_VISIBILITY,strlen(buf),buf); X ok= ((rtrn!=NullString)&&(rtrn[0]=='t')); X uRETURN(ok); X} X X/***====================================================================***/ X XBoolean XxrreqIssueLoad(dpy,root,fileName) XDisplay *dpy; XWindow root; Xchar *fileName; X{ XBoolean ok; Xchar *rtrn,*buf; Xint szBuf,bufIndex,ch; XFILE *file; X X uENTRY3("xrreqIssueLoad(0x%x,0x%x,%s)\n",dpy,root,uStringText(fileName)); X if (fileName!=NullString) { X file= fopen(fileName,"r"); X if (file==NULL) { X uWarning("Can't open \"%s\" to read\n",uStringText(fileName)); X uRETURN(False); X } X } X else file= stdin; X X szBuf= 500; X bufIndex= 0; X buf= (char *)uAlloc(szBuf); X while (((ch=getc(file))!=EOF)&&(buf!=NullString)) { X if (bufIndex==szBuf) { X szBuf*= 2; X buf= (char *)uRealloc(buf,szBuf); X } X if (buf!=NullString) { X buf[bufIndex++]= ch; X } X } X if (buf!=NullString) { X buf[bufIndex++]= NUL; X if (bufIndex>1) { X rtrn= xrreqStringRequest(dpy,root,XR_RQ_LOAD_PROFILE,bufIndex,buf); X ok= ((rtrn!=NullString)&&(rtrn[0]=='t')); X } X else { X uError("Profile is too short\n"); X ok= False; X } X uFree(buf); X } X else { X uError("allocation failure in xrreqIssueLoad\n"); X } X uRETURN(ok); X} X X/***====================================================================***/ X Xchar * XxrreqIssueGetAppName(dpy,root,which,name) XDisplay *dpy; XWindow root; Xunsigned which; Xchar *name; X{ XBoolean ok; Xchar buf[264]; Xint len=1; Xchar *str,*appName; X X uENTRY4("xrreqIssueGetAppName(0x%x,0x%x,0x%x,%s)\n",dpy,root,which, X uStringText(name)); X if ((which==XR_NAMED_APP)&&(name==NullString)) X which= XR_QUERY_APP; X switch (which) { X case XR_LAST_APP: buf[0]= 'L'; break; X case XR_ALL_APPS: buf[0]= 'A'; break; X case XR_ACTIVE_APPS: buf[0]= 'V'; break; X case XR_NAMED_APP: buf[0]= 'N'; X strcpy(&buf[1],name); X len+= strlen(name)+1; X break; X case XR_QUERY_APP: X default: buf[0]= '?'; break; X } X str= xrreqStringRequest(dpy,root,XR_RQ_APP_NAME,len,buf); X if (str!=NullString) { X if (str[0]=='t') { X appName= uStringDup(&str[1]); X } X else appName= NullString; X uFree(str); X } X else appName= NullString; X uRETURN(appName); X} X X/***====================================================================***/ X XBoolean XxrreqIssueDebug(dpy,root,str) XDisplay *dpy; XWindow root; Xchar *str; X{ XBoolean ok; Xchar *rtrn; X X uENTRY3("xrreqIssueDebug(0x%x,0x%x,%s)\n",dpy,root,uStringText(str)); X rtrn= xrreqStringRequest(dpy,root,XR_RQ_DEBUG,strlen(str),str); X ok= ((rtrn!=NullString)&&(rtrn[0]=='t')); X uRETURN(ok); X} X END_OF_FILE if test 12331 -ne `wc -c <'./xrset/xrReq.c'`; then echo shar: \"'./xrset/xrReq.c'\" unpacked with wrong size! fi # end of './xrset/xrReq.c' fi echo shar: End of archive 7 \(of 14\). cp /dev/null ark7isdone MISSING="" for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 14 archives. rm -f ark[1-9]isdone ark[1-9][0-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0