kent@ssbell.IMD.Sterling.COM (Kent Landfield) (01/15/90)
Submitted-by: wsl.dec.com!mikey (Mike Yang) Posting-number: Volume 5, Issue 63 Archive-name: xrooms/part13 #! /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 13 (of 14)." # Contents: ./lib/appstate.c ./lib/names.c # Wrapped by kent@ssbell on Sun Jan 14 21:58:22 1990 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f './lib/appstate.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'./lib/appstate.c'\" else echo shar: Extracting \"'./lib/appstate.c'\" \(24990 characters\) sed "s/^X//" >'./lib/appstate.c' <<'END_OF_FILE' X X /*\ X * $Header: appstate.c,v 5.0 90/01/10 06:53:09 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 asDebug X#include "utils.h" X#include "appstatestr.h" X X/***====================================================================***/ X Xstatic unsigned asScreenWidth= AS_DFLT_SCREEN_WIDTH; Xstatic unsigned asScreenHeight= AS_DFLT_SCREEN_HEIGHT; Xstatic AppStateRec asDefaultRealRec= { X asAllValues, asNoValue, asNoValue, asInactive, 0, 0, 0, 0 X}; Xstatic AppStateRec asDefaultProfileRec= { X asWinStateValue, asNoValue, asNoValue, asIconic, 0, 0, 0, 0 X}; X AppStatePtr asDefaultReal= &asDefaultRealRec; X AppStatePtr asDefaultProfile= &asDefaultProfileRec; X X/***====================================================================***/ X/*** DEBUGGING FUNCTIONS ***/ X/***====================================================================***/ X Xchar * XasWinStateText(winState) XWinState winState; X{ X switch (winState) { X case asInactive: return("inactive"); X case asWithdrawn: return("withdrawn"); X case asNormal: return("normal"); X case asIconic: return("iconic"); X } X return("unknown"); X} X X/***====================================================================***/ X Xchar * XasText(pState) XAppStatePtr pState; X{ Xstatic int bufIndex; Xstatic char asBuf[2][64]; Xstatic char xBuf[12],yBuf[12],widthBuf[12],heightBuf[12]; Xstatic char *stateBuf; Xchar *buf; X X if ((pState==NullAppState)||(!ASHasAny(pState))) X return("[ ]"); X X buf= asBuf[bufIndex]; X bufIndex= !bufIndex; X X if (ASHasWinState(pState)) X stateBuf= asWinStateText(pState->winState); X else stateBuf= ""; X X if (ASHasWholeGeom(pState)) { X sprintf(buf,"[ %s%s =%dx%d%c%d%c%d ",stateBuf, X (ASHasWinState(pState)&& X ASWinStateBolted(pState)?"!":""), X pState->width,pState->height, X (ASHasNegativeX(pState)?'-':'+'),pState->x, X (ASHasNegativeY(pState)?'-':'+'),pState->y); X } X else if (ASHasAnyGeom(pState)) { X if (ASHasWidth(pState)) sprintf(widthBuf,"%d",pState->width); X else widthBuf[0]= '\0'; X X if (ASHasHeight(pState)) sprintf(heightBuf,"x%d",pState->height); X else heightBuf[0]= '\0'; X X if (ASHasX(pState)) { X if (ASHasNegativeX(pState)) sprintf(xBuf,"-%d",pState->x); X else sprintf(xBuf,"+%d",pState->x); X } X else if (ASHasY(pState)) sprintf(xBuf,"+"); X else xBuf[0]= '\0'; X X if (ASHasY(pState)) { X if (ASHasNegativeY(pState)) sprintf(yBuf,"-%d",pState->y); X else sprintf(yBuf,"+%d",pState->y); X } X else yBuf[0]= '\0'; X X sprintf(buf,"[ %s%s =%s%s%s%s ",stateBuf, X ((ASWinStateBolted(pState)&& X ASHasWinState(pState))?"!":""), X widthBuf,heightBuf,xBuf,yBuf); X } X else { X sprintf(buf,"[ %s%s ",stateBuf,((ASWinStateBolted(pState)&& X ASHasWinState(pState))?"!":"")); X } X if (ASHasAnyGeom(pState)&&ASAnyGeomBolted(pState)) { X char bolts[12]; X int i= 0; X bolts[i++]= ' '; X if (ASXBolted(pState)) bolts[i++]= 'x'; X if (ASYBolted(pState)) bolts[i++]= 'y'; X if (ASWidthBolted(pState)) bolts[i++]= 'w'; X if (ASHeightBolted(pState)) bolts[i++]= 'h'; X bolts[i++]= '!'; X bolts[i++]= NUL; X strcat(buf,bolts); X } X strcat(buf," ]"); X return(buf); X} X X/***====================================================================***/ X/*** FUNCTIONS FOR DEALING WITH NEGATIVE SPECIFICATIONS OF X AND Y ***/ X/***====================================================================***/ X Xvoid XasSetScreenSize(width,height) Xunsigned width; Xunsigned height; X{ X uFLAG_ENTRY2(LOW_ENTRY_BIT,"asSetScreenSize(%d,%d)\n",width,height); X asScreenWidth= width; X asScreenHeight= height; X uFLAG_VOIDRETURN; X} X X/***====================================================================***/ X XBoolean XasChangeProfileFlags(pReal,pProf,newFlags) XAppStatePtr pReal; XAppStatePtr pProf; Xunsigned newFlags; X{ Xint x,y; Xunsigned w,h; X X uENTRY3("asChangeProfileFlags(%s,%s,0x%x)\n",pReal,pProf,newFlags); X if ((!ASLegalRealState(pReal))||(pProf==NullAppState)|| X (!ASLegalProfileState(pProf))) { X uRETURN(False); X } X X if ((newFlags&asAllValues)==asNoValue) X pProf->flags= 0; X else if (pProf->flags!=newFlags) { X if (!ASHasWinState(pProf)) X pProf->winState= pReal->winState; X w= (ASHasWidth(pProf)? pProf->width: pReal->width); X h= (ASHasHeight(pProf)? pProf->height: pReal->height); X if (ASHasX(pProf)) { X if (ASHasNegativeX(pProf)) x= asScreenWidth-pProf->x-w; X else x= pProf->x; X } X else x= pReal->x; X if (ASHasY(pProf)) { X if (ASHasNegativeY(pProf)) y= asScreenHeight-pProf->y-h; X else y= pProf->y; X } X else y= pReal->y; X X pProf->flags= newFlags; X if (ASHasNegativeX(pProf)) pProf->x= asScreenWidth-x-w; X else pProf->x= x; X if (ASHasNegativeY(pProf)) pProf->y= asScreenHeight-y-h; X else pProf->y= y; X pProf->width= w; X pProf->height= h; X } X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XasGetScreenValues(pReal,pProf,pX,pY,pWidth,pHeight) XAppStatePtr pReal,pProf; Xint *pX,*pY; Xunsigned *pWidth,*pHeight; X{ Xint x,y; Xunsigned w,h; X X uENTRY6("asGetScreenValues(%s,%s,0x%x,0x%x,0x%x,0x%x)\n", X asText(pReal),asText(pProf), X pX,pY,pWidth,pHeight); X if (ASLegalRealState(pReal)&&ASLegalProfileState(pProf)) { X w= (ASHasWidth(pProf)? pProf->width: pReal->width); X h= (ASHasHeight(pProf)? pProf->height: pReal->height); X if (ASHasX(pProf)) { X if (ASHasNegativeX(pProf)) x= asScreenWidth-pProf->x-w; X else x= pProf->x; X } X else x= pReal->x; X if (ASHasY(pProf)) { X if (ASHasNegativeY(pProf)) y= asScreenHeight-pProf->y-h; X else y= pProf->y; X } X else y= pReal->y; X if (pX!=(int *)NULL) *pX= x; X if (pY!=(int *)NULL) *pY= y; X if (pWidth!=(unsigned *)NULL) *pWidth= w; X if (pHeight!=(unsigned *)NULL) *pHeight= h; X uRETURN(True); X } X uRETURN(False); X} X X/***====================================================================***/ X/*** FUNCTIONS TO CREATE AND DESTROY APPLICATION STATES ***/ X/***====================================================================***/ X XAppStatePtr XasCreate(flags, winState, x, y, width, height) Xunsigned flags; XWinState winState; Xint x,y; Xunsigned width,height; X{ XAppStatePtr pState; X X uENTRY6("asCreate(0x%x,%s,%d,%d,%d,%d)\n",flags,asWinStateText(winState), X x,y,width,height); X pState= uTypedAlloc(AppStateRec); X if (pState!=NullAppState) { X pState->flags= (flags&asLegalFlags); X pState->bolts= asNoValue; X pState->looseBolts= asNoValue; X pState->winState= winState; X pState->x= x; X pState->y= y; X pState->width= width; X pState->height= height; X } X uRETURN(pState); X} X X/***====================================================================***/ X XAppStatePtr XasDupFully(pState) XAppStatePtr pState; X{ XAppStatePtr pNew; X X uENTRY1("asDupFully(%s)\n",asText(pState)); X pNew= uTypedAlloc(AppStateRec); X X if (pNew!=NullAppState) { X if (pState==NullAppState) { X pNew->flags= asNoValue; X } X else { X *pNew= *pState; X } X } X uRETURN(pNew); X} X X/***====================================================================***/ X XAppStatePtr XasDupReal(pReal,flags) XAppStatePtr pReal; Xunsigned flags; X{ XAppStatePtr pNew; X X uENTRY2("asDupReal(%s,0x%x)\n",asText(pReal),flags); X if (!ASLegalRealState(pReal)) { X uRETURN(NullAppState); X } X pNew= uTypedAlloc(AppStateRec); X if (pNew!=NullAppState) { X *pNew= *pReal; X pNew->flags= flags; X if (ASHasNegativeX(pNew)) X pNew->x= asScreenWidth-pNew->x-pNew->width; X if (ASHasNegativeY(pNew)) X pNew->y= asScreenHeight-pNew->y-pNew->height; X } X uRETURN(pNew); X} X X/***====================================================================***/ X Xvoid XasDestroy(pState) XAppStatePtr pState; X{ X uENTRY1("asDestroy(%s)\n",asText(pState)); X if (pState!=NullAppState) { X (void)uFree((Opaque)pState); X } X uVOIDRETURN; X} X X/***====================================================================***/ X/*** FUNCTIONS TO COPY, CONVERT, AND MODIFY APPLICATION STATES ***/ X/***====================================================================***/ X XBoolean XasCopyFully(pFrom, pInto) XAppStatePtr pFrom, pInto; X{ X uENTRY2("asCopyFully(%s,%s)\n",asText(pFrom),asText(pInto)); X if (pInto==NullAppState) { X uRETURN(False); X } X else if (pFrom==NullAppState) { X pInto->flags= asNoValue; X } X else *pInto= *pFrom; X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XasCopySelected(pFrom, pInto, flags) XAppStatePtr pFrom, pInto; Xunsigned flags; X{ X uENTRY3("asCopySelected(%s,%s,0x%x)\n",asText(pFrom),asText(pInto),flags); X if (pInto==NullAppState) { X uRETURN(False); X } X if (pFrom!=NullAppState) { X flags&= pFrom->flags; X if (flags&asWinStateValue) { X pInto->winState= pFrom->winState; X pInto->flags|= asWinStateValue; X } X if (flags&asXValue) { X pInto->flags|= asXValue; X pInto->x= pFrom->x; X if (flags&asXNegative) { X if (ASHasNegativeX(pFrom)) pInto->flags|= asXNegative; X else pInto->flags&= ~asXNegative; X } X } X if (flags&asYValue) { X pInto->flags|= asYValue; X pInto->y= pFrom->y; X if (flags&asYNegative) { X if (ASHasNegativeY(pFrom)) pInto->flags|= asYNegative; X else pInto->flags&= ~asYNegative; X } X } X if (flags&asWidthValue) { X pInto->width= pFrom->width; X pInto->flags|= asWidthValue; X } X if (flags&asHeightValue) { X pInto->height= pFrom->height; X pInto->flags|= asHeightValue; X } X } X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XasCopyRealToProfile(pRealFrom,pProfInto) XAppStatePtr pRealFrom,pProfInto; X{ X uENTRY2("asCopyRealToProfile(%s,%s)\n",asText(pRealFrom), X asText(pProfInto)); X if ((!ASLegalRealState(pRealFrom))||(pProfInto==NullAppState)|| X (!ASLegalProfileState(pProfInto))) { X uRETURN(False); X } X if ((!ASWinStateBolted(pProfInto))&& X (pRealFrom->winState!=asInactive)&&(pRealFrom->winState!=asWithdrawn)) { X pProfInto->winState=pRealFrom->winState; X } X if (!ASWidthBolted(pProfInto)) X pProfInto->width= pRealFrom->width; X if (!ASHeightBolted(pProfInto)) X pProfInto->height= pRealFrom->height; X if ((!ASXBolted(pProfInto))&&(ASHasX(pProfInto))) { X int w= (ASHasWidth(pProfInto)?pProfInto->width:pRealFrom->width); X if (ASHasNegativeX(pProfInto)) X pProfInto->x= asScreenWidth-w-pRealFrom->x; X else pProfInto->x= pRealFrom->x; X } X if ((!ASYBolted(pProfInto))&&(ASHasY(pProfInto))) { X int h= (ASHasHeight(pProfInto)?pProfInto->height:pRealFrom->height); X if (ASHasNegativeY(pProfInto)) X pProfInto->y= asScreenHeight-h-pRealFrom->y; X else pProfInto->y= pRealFrom->y; X } X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XasCopyProfileToReal(pProfFrom,pRealInto) XAppStatePtr pProfFrom,pRealInto; X{ X uENTRY2("asCopyProfileToReal(%s,%s)\n",asText(pProfFrom), X asText(pRealInto)); X if ((!ASLegalProfileState(pProfFrom))||(!ASLegalRealState(pRealInto))) { X uRETURN(False); X } X if (ASHasWinState(pProfFrom)) X pRealInto->winState= pProfFrom->winState; X if (ASHasWidth(pProfFrom)) pRealInto->width= pProfFrom->width; X if (ASHasHeight(pProfFrom)) pRealInto->height= pProfFrom->height; X if (ASHasX(pProfFrom)) { X if (ASHasNegativeX(pProfFrom)) X pRealInto->x= asScreenWidth-pProfFrom->x-pRealInto->width; X else pRealInto->x= pProfFrom->x; X } X if (ASHasY(pProfFrom)) { X if (ASHasNegativeY(pProfFrom)) X pRealInto->y= asScreenHeight-pProfFrom->y-pRealInto->height; X else pRealInto->y= pProfFrom->y; X } X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XasChangeSelected(pState, which, winState, x, y, width, height) Xregister AppStatePtr pState; Xunsigned which; XWinState winState; Xint x,y; Xunsigned width,height; X{ X uENTRY7("asChangeSelected(%s,0x%x,%s,%d,%d,%d,%d)\n",asText(pState),which, X asWinStateText(winState), X x,y,width,height); X if (pState==NullAppState) { X uRETURN(False); X } X X if (which&asWinStateValue) pState->winState= winState; X if (which&asXValue) { X pState->x= x; X if (which&asXNegative) pState->flags|= asXNegative; X else pState->flags&= (~asXNegative); X } X if (which&asYValue) { X pState->y= y; X if (which&asYNegative) pState->flags|= asYNegative; X else pState->flags&= (~asYNegative); X } X if (which&asWidthValue) pState->width= width; X if (which&asHeightValue) pState->height= height; X pState->flags|= (which&asAllValues); X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XasChangeAll(pState, flags, winState, x, y, width, height) Xregister AppStatePtr pState; Xunsigned flags; XWinState winState; Xint x,y; Xunsigned width,height; X{ X uENTRY7("asChangeAll(%s,0x%x,%s,%d,%d,%d,%d)\n",asText(pState),flags, X asWinStateText(winState), X x,y,width,height); X if (pState==NullAppState) { X uRETURN(False); X } X X pState->flags= (flags&asLegalFlags); X pState->winState= winState; X pState->x= x; X pState->y= y; X pState->width= width; X pState->height= height; X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XasBolt(pState,which) XAppStatePtr pState; Xunsigned which; X{ X uENTRY2("asBolt(%s,0x%x)\n",asText(pState),which); X if (pState!=NullAppState) { X pState->bolts|= (which&asAllValues); X pState->looseBolts&= ~(which&asAllValues); X uRETURN(True); X } X uRETURN(False); X} X X/***====================================================================***/ X XBoolean XasUnbolt(pState,which) XAppStatePtr pState; Xunsigned which; X{ X uENTRY2("asUnbolt(%s,0x%x)\n",asText(pState),which); X if (pState!=NullAppState) { X pState->bolts&= ~(which&asAllValues); X pState->looseBolts&= ~(which&asAllValues); X uRETURN(True); X } X uRETURN(False); X} X X/***====================================================================***/ X XBoolean XasLoosenBolts(pState,which) XAppStatePtr pState; Xunsigned which; X{ X uENTRY2("asLoosenBolt(%s,0x%x)\n",asText(pState),which); X if (pState!=NullAppState) { X which&= pState->bolts; X pState->bolts&= ~(which&asAllValues); X pState->looseBolts|= (which&asAllValues); X uRETURN(True); X } X uRETURN(False); X} X X/***====================================================================***/ X XBoolean XasTightenBolts(pState,which) XAppStatePtr pState; Xunsigned which; X{ X uENTRY2("asTightenBolts(%s,0x%x)\n",asText(pState),which); X if (pState!=NullAppState) { X which&= pState->looseBolts; X pState->bolts|= (which&asAllValues); X pState->looseBolts&= ~(which&asAllValues); X uRETURN(True); X } X uRETURN(False); X} X X/***====================================================================***/ X XBoolean XasSetBolts(pState,which) XAppStatePtr pState; Xunsigned which; X{ X uENTRY2("asSetBolts(%s,0x%x)\n",asText(pState),which); X if (pState!=NullAppState) { X pState->bolts= which&asAllValues; X pState->looseBolts&= ~(which&asAllValues); X } X uRETURN(False); X} X X/***====================================================================***/ X XBoolean XasSetLooseBolts(pState,which) XAppStatePtr pState; Xunsigned which; X{ X uENTRY2("asSetLooseBolts(%s,0x%x)\n",asText(pState),which); X which&= asAllValues; X if (pState!=NullAppState) { X pState->bolts|= pState->looseBolts; X pState->looseBolts= which; X pState->bolts&= ~which; X } X uRETURN(False); X} X X/***====================================================================***/ X/*** FUNCTIONS TO GET INFORMATION ABOUT APPLICATION STATES ***/ X/***====================================================================***/ X Xunsigned XasValues(pState, pWinState, pX, pY, pWidth, pHeight) Xregister AppStatePtr pState; XWinState *pWinState; Xint *pX,*pY; Xunsigned *pWidth,*pHeight; X{ Xunsigned flags; X X uFLAG_ENTRY6(LOW_ENTRY_BIT,"asValues(%s,0x%x,0x%x,0x%x,0x%x,0x%x)\n", X asText(pState),pWinState,pX,pY,pWidth,pHeight); X if (pState==NullAppState) { X uFLAG_RETURN(asNoValue); X } X X flags= pState->flags; X if ((pWinState!=(WinState *)NULL)&&(ASHasWinState(pState))) X *pWinState= pState->winState; X if ((pX!=(int *)NULL)&&ASHasX(pState)) { X if (ASHasWidth(pState)&&(ASHasNegativeX(pState))) { X *pX= asScreenWidth-pState->x-pState->width; X flags&= (~asXNegative); X } X else *pX= pState->x; X } X if ((pY!=(int *)NULL)&&ASHasY(pState)) { X if (ASHasHeight(pState)&&(ASHasNegativeY(pState))) { X *pY= asScreenHeight-pState->y-pState->height; X flags&= (~asYNegative); X } X else *pY= pState->y; X } X if ((pWidth!=(unsigned *)NULL)&&ASHasWidth(pState)) X *pWidth= pState->width; X if ((pHeight!=(unsigned *)NULL)&&ASHasHeight(pState)) X *pHeight= pState->height; X uFLAG_RETURN(flags); X} X X/***====================================================================***/ X XWinState XasWinState(pState) XAppStatePtr pState; X{ X X uFLAG_ENTRY1(LOW_ENTRY_BIT,"asWinState(%s)\n",asText(pState)); X if ((pState!=NullAppState)&&(ASHasWinState(pState))) { X uFLAG_RETURN(pState->winState); X } X uFLAG_RETURN(asInactive); X} X X/***====================================================================***/ X Xunsigned XasFlags(pState) XAppStatePtr pState; X{ X uFLAG_ENTRY1(LOW_ENTRY_BIT,"asFlags(%s)\n",asText(pState)); X if (pState!=NullAppState) { X uFLAG_RETURN(pState->flags); X } X uFLAG_RETURN(asNoValue); X} X X/***====================================================================***/ X Xunsigned XasBolts(pState) XAppStatePtr pState; X{ X uFLAG_ENTRY1(LOW_ENTRY_BIT,"asBolts(%s)\n",asText(pState)); X if (pState!=NullAppState) { X uFLAG_RETURN(pState->bolts); X } X uFLAG_RETURN(asNoValue); X} X X/***====================================================================***/ X Xunsigned XasLooseBolts(pState) XAppStatePtr pState; X{ X uFLAG_ENTRY1(LOW_ENTRY_BIT,"asLooseBolts(%s)\n",asText(pState)); X if (pState!=NullAppState) { X uFLAG_RETURN(pState->looseBolts); X } X uFLAG_RETURN(asNoValue); X} X X/***====================================================================***/ X/*** FUNCTIONS TO COMPARE GEOMETRIES ***/ X/***====================================================================***/ X XBoolean XasRealMatchesProfile(pReal,pProf) XAppStatePtr pReal; XAppStatePtr pProf; X{ XBoolean match; X X uFLAG_ENTRY2(LOW_ENTRY_BIT,"asRealMatchesProfile(%s,%s)\n",asText(pReal), X asText(pProf)); X match= asSelectedRealMatchProfile(pReal,pProf,asAllValues); X uFLAG_RETURN(match); X} X X/***====================================================================***/ X XBoolean XasSelectedRealMatchProfile(pReal,pProf,which) XAppStatePtr pReal; XAppStatePtr pProf; Xunsigned which; X{ XBoolean match; X X uENTRY3("asSelectedRealMatchProfile(%s,%s,0x%x)\n",asText(pReal), X asText(pProf),which); X if ((!ASLegalRealState(pReal))||(!ASLegalProfileState(pProf))) { X uRETURN(False); X } X which&= pProf->flags; X match= True; X if (pProf!=NullAppState) { X if ((which&asWinStateValue)&& X (pReal->winState!=asInactive)&&(pReal->winState!=asWithdrawn)&& X (pReal->winState!=pProf->winState)) X match= False; X else if (((which&asWidthValue)&&(pProf->width!=pReal->width))|| X ((which&asHeightValue)&&(pProf->height!=pReal->height))) X match= False; X else { X if (which&asXValue) { X if (ASHasNegativeX(pProf)) { X int w= (ASHasWidth(pProf)?pProf->width:pReal->width); X if ((asScreenWidth-pProf->x-w)!=pReal->x) X match= False; X } X else if (pProf->x!=pReal->x) X match= False; X } X if (match&&(which&asYValue)) { X if (ASHasNegativeY(pProf)) { X int h= (ASHasHeight(pProf)?pProf->height:pReal->height); X if ((asScreenHeight-pProf->y-h)!=pReal->y) X match= False; X } X else if (pProf->y!=pReal->y) X match= False; X } X } X } X uRETURN(match); X} X X/***====================================================================***/ X XBoolean XasProfileCorrectWRTReal(pProf,pReal) XAppStatePtr pProf; XAppStatePtr pReal; X{ XBoolean match; X X uFLAG_ENTRY2(LOW_ENTRY_BIT,"asProfileCorrectWRTReal(%s,%s)\n",asText(pProf), X asText(pReal)); X match= asSelectedProfileCorrectWRTReal(pProf,pReal,asAllValues); X uFLAG_RETURN(match); X} X X/***====================================================================***/ X XBoolean XasSelectedProfileCorrectWRTReal(pProf,pReal,which) XAppStatePtr pProf; XAppStatePtr pReal; Xunsigned which; X{ XBoolean match; X X uENTRY3("asSelectedProfileCorrectWRTReal(%s,%s,0x%x)\n",asText(pProf), X asText(pReal),which); X if (!ASLegalRealState(pReal)) { X uRETURN(False); X } X match= True; X which&= pProf->flags; X if (pProf!=NullAppState) { X if ((which&asWinStateValue)&&(!ASWinStateBolted(pProf))&& X (pReal->winState!=asInactive)&&(pReal->winState!=asWithdrawn)&& X (pReal->winState!=pProf->winState)) X match= False; X else if (((which&asWidthValue)&&(!ASWidthBolted(pProf))&& X (pProf->width!=pReal->width))|| X ((which&asHeightValue)&&(!ASHeightBolted(pProf))&& X (pProf->height!=pReal->height))) X match= False; X else if ((which&asXValue)&&(!ASXBolted(pProf))) { X if (ASHasNegativeX(pProf)) { X int w= (ASHasWidth(pProf)?pProf->width:pReal->width); X if ((asScreenWidth-pProf->x-w)!=pReal->x) X match= False; X } X else if (pProf->x!=pReal->x) X match= False; X } X else if ((which&asYValue)&&(!ASYBolted(pProf))) { X if (ASHasNegativeY(pProf)) { X int h= (ASHasHeight(pProf)?pProf->height:pReal->height); X if ((asScreenHeight-pProf->y-h)!=pReal->y) X match= False; X } X else if (pProf->y!=pReal->y) X match= False; X } X } X uRETURN(match); X} X X/***====================================================================***/ X XBoolean XasFullySame(pState1,pState2) XAppStatePtr pState1; XAppStatePtr pState2; X{ XBoolean match= True; X X uFLAG_ENTRY2(LOW_ENTRY_BIT,"asFullySame(%s,%s)\n",asText(pState1), X asText(pState2)); X match= asSelectedSame(pState1,pState2,asAllValues); X uFLAG_RETURN(match); X} X X/***====================================================================***/ X XBoolean XasSelectedSame(pState1,pState2,which) XAppStatePtr pState1; XAppStatePtr pState2; Xunsigned which; X{ XBoolean match= True; X X uENTRY3("asSelectedSame(%s,%s,0x%x)\n",asText(pState1),asText(pState2), X which); X if (pState1!=pState2) { X if ((pState1==NullAppState)||(pState2==NullAppState)) X match= False; X else if ((asFlags(pState1)&which)!=(asFlags(pState2)&which)) X match= False; X else { X which&= asFlags(pState1); X if (((which&asWinStateValue)&& X (pState1->winState!=pState2->winState))|| X ((which&asXValue)&&(pState1->x!=pState2->x))|| X ((which&asYValue)&&(pState1->y!=pState2->y))|| X ((which&asWidthValue)&&(pState1->width!=pState2->width))|| X ((which&asHeightValue)&&(pState1->height!=pState2->height))) X match= False; X } X } X uRETURN(match); X} X X/***====================================================================***/ X/*** FUNCTIONS TO DETERMINE OTHER USEFUL THINGS ABOUT GEOMETRIES ***/ X/***====================================================================***/ X XBoolean XasLegalReal(pState) XAppStatePtr pState; X{ XBoolean ok; X X uFLAG_ENTRY1(LOW_ENTRY_BIT,"asLegalReal(%s)\n",asText(pState)); X ok= ASLegalRealState(pState); X uFLAG_RETURN(ok); X} X X/***====================================================================***/ X XBoolean XasLegalProfile(pState) XAppStatePtr pState; X{ XBoolean ok; X X uFLAG_ENTRY1(LOW_ENTRY_BIT,"asLegalProfile(%s)\n",asText(pState)); X ok= ASLegalProfileState(pState); X uFLAG_RETURN(ok); X} X/***====================================================================***/ X XBoolean XasDontCare(pState) XAppStatePtr pState; X{ XBoolean ok; X X uFLAG_ENTRY1(LOW_ENTRY_BIT,"asDontCare(%s)\n",asText(pState)); X ok= ASDontCareState(pState); X uFLAG_RETURN(ok); X} END_OF_FILE if test 24990 -ne `wc -c <'./lib/appstate.c'`; then echo shar: \"'./lib/appstate.c'\" unpacked with wrong size! fi # end of './lib/appstate.c' fi if test -f './lib/names.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'./lib/names.c'\" else echo shar: Extracting \"'./lib/names.c'\" \(28216 characters\) sed "s/^X//" >'./lib/names.c' <<'END_OF_FILE' X X /*\ X * $Header: names.c,v 5.0 90/01/10 06:53:38 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 namesDebug X#include "utils.h" X#include <ctype.h> X X#include "namesstr.h" X Xint namesIndentSize= 4; Xchar *npJoinText= ""; X X/***====================================================================***/ X X/* ARGSUSED */ Xvoid XnpDestroyStatement(pStmt) XNPStatementPtr pStmt; X{ X uWarning("memory leak. npDestroyStatement not implemented yet\n"); X return; X} X X/***====================================================================***/ X Xstatic void XnpIndent(file,level) XFILE *file; Xint level; X{ X uENTRY2("npIndent(0x%x,%d)\n",file,level); X level*= namesIndentSize; X while (level>0) { X putc(' ',file); X level--; X } X uVOIDRETURN; X} X X/***====================================================================***/ X Xvoid XnpWriteBlock(file,indent,pBlock) XFILE *file; Xint indent; XNPStatementPtr pBlock; X{ XBoolean needBraces; X X uENTRY3("npWriteBlock(0x%x,%d,0%x)\n",file,indent,pBlock); X needBraces= pBlock->pNext!=NullNPStatement; X if (needBraces) { X fprintf(file,"{\n"); X npWriteStatement(file,indent+1,pBlock); X npIndent(file,indent); X fprintf(file,"}\n"); X } X else { X npWriteStatement(file,indent,pBlock); X } X uVOIDRETURN; X} X X/***====================================================================***/ X Xvoid XnpWriteStringExpr(file,pStringExpr) XFILE *file; XNPStringExprPtr pStringExpr; X{ Xextern void npWriteBoolExpr(); X X uENTRY2("npWriteStringExpr(0x%x,0%x)\n",file,pStringExpr); X if (pStringExpr->type==NPStringConstant) { X fprintf(file,"\"%s\"",pStringExpr->u.constant); X } X else if (pStringExpr->type==NPIdentifier) { X fprintf(file,"%s",pStringExpr->u.constant); X } X else if (pStringExpr->type==NPPropertyName) { X fprintf(file,"<%s>",pStringExpr->u.constant); X } X else if (pStringExpr->type==NPStringConcat) { X npWriteStringExpr( file, pStringExpr->u.concat.pLeft ); X fprintf(file," + "); X npWriteStringExpr( file, pStringExpr->u.concat.pRight ); X } X else if (pStringExpr->type==NPStringConditional) { X fprintf(file, "( "); X npWriteBoolExpr(file, pStringExpr->u.conditional.pCondition); X fprintf(file, " ? "); X npWriteStringExpr(file, pStringExpr->u.conditional.pTrue); X if (pStringExpr->u.conditional.pFalse!=NullNPStringExpr) { X fprintf(file, " : "); X npWriteStringExpr(file, pStringExpr->u.conditional.pFalse); X } X fprintf(file, " ) "); X } X uVOIDRETURN; X} X X/***====================================================================***/ X Xvoid XnpWriteBoolExpr(file,pBoolExpr) XFILE *file; XNPBoolExprPtr pBoolExpr; X{ X uENTRY2("npWriteBoolExpr(0x%x,0%x)\n",file,pBoolExpr); X if (pBoolExpr->invert) fprintf(file,"! "); X npWriteStringExpr(file,pBoolExpr->left); X if (pBoolExpr->right!=NullNPStringExpr) { X fprintf(file," == "); X npWriteStringExpr(file,pBoolExpr->right); X } X uVOIDRETURN; X} X X/***====================================================================***/ X Xvoid XnpWriteCases(file,indent,pCases) XFILE *file; Xint indent; XNPCasePtr pCases; X{ X uENTRY3("npWriteCases(0x%x,%d,0x%x)\n",file,indent,pCases); X while (pCases!=NullNPCase) { X npIndent(file,indent); X fprintf(file,"case "); X npWriteStringExpr(file,pCases->pattern); X fprintf(file,": "); X npWriteBlock(file,indent,pCases->statement); X pCases= pCases->pNext; X } X uVOIDRETURN; X} X X/***====================================================================***/ X Xvoid XnpWriteStatement(file,indent,pStatement) XFILE *file; Xint indent; XNPStatementPtr pStatement; X{ X X uENTRY3("npWriteStatement(0x%x,%d,0x%x)\n",file,indent,pStatement); X while (pStatement!=NullNPStatement) { X npIndent(file,indent); X switch (pStatement->what) { X case NPIfStatement: X fprintf(file,"if ( "); X npWriteBoolExpr(file,pStatement->u.ifS.condition); X fprintf(file," ) "); X npWriteBlock(file,indent,pStatement->u.ifS.thenClause); X if (pStatement->u.ifS.elseClause!=NullNPStatement) { X putc('\n',file); X npIndent(file,indent); X fprintf(file,"else "); X npWriteBlock(file,indent,pStatement->u.ifS.elseClause); X } X break; X case NPSwitchStatement: X fprintf(file,"switch ( "); X npWriteStringExpr(file,pStatement->u.switchS.string); X npIndent(file,indent); X fprintf(file," ) {\n"); X npWriteCases(file,indent+1,pStatement->u.switchS.cases); X if (pStatement->u.switchS.dfltCase!=NullNPStatement) { X npIndent(file,indent+1); X fprintf(file,"default: "); X npWriteBlock(file,indent+1,pStatement->u.switchS.dfltCase); X } X npIndent(file,indent); X fprintf(file,"}\n"); X break; X case NPUseStatement: X fprintf(file,"use "); X npWriteStringExpr(file,pStatement->u.pUseExpr); X fprintf(file,"\n"); X break; X case NPClassStatement: X fprintf(file,"class "); X npWriteStringExpr(file,pStatement->u.pClassExpr); X fprintf(file,"\n"); X break; X case NPAssignStatement: X npWriteStringExpr(file,pStatement->u.assignS.pLHS); X fprintf(file," %s ",pStatement->u.assignS.append?"+=":"="); X npWriteStringExpr(file,pStatement->u.assignS.pValue); X fprintf(file,"\n"); X break; X case NPIgnoreStatement: X fprintf(file,"ignore\n"); X break; X case NPComment: X fprintf(file,"# %s\n",uStringText(pStatement->u.comment)); X break; X } X pStatement= pStatement->pNext; X } X X uVOIDRETURN; X} X X/***====================================================================***/ X XNPStringExprPtr XnpStringTerminal(type,strValue) Xunsigned type; Xchar *strValue; X{ XNPStringExprPtr pExpr= NullNPStringExpr; X X uENTRY2("npStringTerminal(0x%x,%s)\n",type,uStringText(strValue)); X if (strValue!=NullString) { X pExpr= uTypedAlloc(NPStringExprRec); X if (pExpr!=NullNPStringExpr) { X pExpr->type= type; X pExpr->u.constant= strValue; X } X else { X uWarning("Allocation failure in npStringTerminal\n"); X } X } X uRETURN(pExpr); X} X X/***====================================================================***/ X XNPStringExprPtr XnpStringConcat(pLeft, pRight) XNPStringExprPtr pLeft; XNPStringExprPtr pRight; X{ XNPStringExprPtr pExpr; X X uENTRY2("npStringConcat(0x%x,0x%x)\n",pLeft,pRight); X if ((pLeft==NullNPStringExpr)||(pRight==NullNPStringExpr)) { X uRETURN(NullNPStringExpr); X } X pExpr= uTypedAlloc(NPStringExprRec); X if (pExpr!=NullNPStringExpr) { X pExpr->type= NPStringConcat; X pExpr->u.concat.pLeft= pLeft; X pExpr->u.concat.pRight= pRight; X } X uRETURN(pExpr); X} X X/***====================================================================***/ X XNPStringExprPtr XnpStringConditional(pCond, pTrue, pFalse) XNPBoolExprPtr pCond; XNPStringExprPtr pTrue; XNPStringExprPtr pFalse; X{ XNPStringExprPtr pExpr; X X uENTRY3("npStringConditional(0x%x,0x%x,0x%x)\n",pCond,pTrue,pFalse); X if ((pCond==NullNPBoolExpr)||(pTrue==NullNPStringExpr)) { X uRETURN(NullNPStringExpr); X } X pExpr= uTypedAlloc(NPStringExprRec); X if (pExpr!=NullNPStringExpr) { X pExpr->type= NPStringConditional; X pExpr->u.conditional.pCondition= pCond; X pExpr->u.conditional.pTrue= pTrue; X pExpr->u.conditional.pFalse= pFalse; X } X uRETURN(pExpr); X} X X/***====================================================================***/ X XNPBoolExprPtr XnpUnaryExpr(invert, pStrExpr) XBoolean invert; XNPStringExprPtr pStrExpr; X{ XNPBoolExprPtr pExpr= NullNPBoolExpr; X X uENTRY2("npUnaryExpr(%s,0x%x)\n",booleanText(invert),pStrExpr); X if (pStrExpr!=NullNPStringExpr) { X pExpr= uTypedAlloc(NPBoolExprRec); X if (pExpr!=NullNPBoolExpr) { X pExpr->invert= invert; X pExpr->left= pStrExpr; X pExpr->right= NullNPStringExpr; X } X } X uRETURN(pExpr); X} X X/***====================================================================***/ X XNPBoolExprPtr XnpEquals(pLeft, pRight) XNPStringExprPtr pLeft; XNPStringExprPtr pRight; X{ XNPBoolExprPtr pExpr= NullNPBoolExpr; X X uENTRY2("npEquals(%s,0x%x)\n",pLeft,pRight); X if ((pLeft!=NullNPStringExpr)&&(pRight!=NullNPStringExpr)) { X pExpr= uTypedAlloc(NPBoolExprRec); X if (pExpr!=NullNPBoolExpr) { X pExpr->invert= False; X pExpr->left= pLeft; X pExpr->right= pRight; X } X } X uRETURN(pExpr); X} X X/***====================================================================***/ X XNPStatementPtr XnpIfStatement( pCond, thenClause, elseClause ) XNPBoolExprPtr pCond; XNPStatementPtr thenClause; XNPStatementPtr elseClause; X{ XNPStatementPtr pStatement= NullNPStatement; X X uENTRY3("npIfStatement(0x%x,0x%x,0x%x)\n",pCond,thenClause,elseClause); X if ((pCond!=NullNPBoolExpr)&&(thenClause!=NullNPStatement)) { X pStatement= uTypedAlloc(NPStatementRec); X if (pStatement!=NullNPStatement) { X pStatement->what= NPIfStatement; X pStatement->u.ifS.condition= pCond; X pStatement->u.ifS.thenClause= thenClause; X pStatement->u.ifS.elseClause= elseClause; X pStatement->pNext= NullNPStatement; X } X } X uRETURN(pStatement); X} X X/***====================================================================***/ X XNPCasePtr XnpCase( pPattern, pStatement ) XNPStringExprPtr pPattern; XNPStatementPtr pStatement; X{ XNPCasePtr pCase= NullNPCase; X X uENTRY2("npCase(0x%x,0x%x)\n",pPattern,pStatement); X pCase= uTypedAlloc(NPCaseRec); X if (pCase!=NullNPCase) { X pCase->pattern= pPattern; X pCase->statement= pStatement; X pCase->pNext= NullNPCase; X } X uRETURN(pCase); X} X X/***====================================================================***/ X Xvoid XnpAppendCase( pOnto, pAdded ) XNPCasePtr pOnto; XNPCasePtr pAdded; X{ XNPCasePtr pNext; X X uENTRY2("npAppendCase(0x%x,0x%x)\n",pOnto,pAdded); X if ((pOnto!=NullNPCase)&&(pAdded!=NullNPCase)) { X pNext= pOnto; X while (pNext->pNext!=NullNPCase) { X pNext= pNext->pNext; X } X pNext->pNext= pAdded; X } X uVOIDRETURN; X} X X/***====================================================================***/ X XNPStatementPtr XnpSwitchStatement( pStrExpr, pCases, pDfltCase ) XNPStringExprPtr pStrExpr; XNPCasePtr pCases; XNPStatementPtr pDfltCase; X{ XNPStatementPtr pStatement= NullNPStatement; X X uENTRY3("npSwitchStatement(0x%x,0x%x,0x%x)\n",pStrExpr,pCases, X pDfltCase); X if ((pStrExpr!=NullNPStringExpr)&&(pCases!=NullNPCase)) { X pStatement= uTypedAlloc(NPStatementRec); X if (pStatement!=NullNPStatement) { X pStatement->what= NPSwitchStatement; X pStatement->u.switchS.string= pStrExpr; X pStatement->u.switchS.cases= pCases; X pStatement->u.switchS.dfltCase= pDfltCase; X pStatement->pNext= NullNPStatement; X } X } X uRETURN(pStatement); X} X X/***====================================================================***/ X XNPStatementPtr XnpUseStatement( pNameExpr ) XNPStringExprPtr pNameExpr; X{ XNPStatementPtr pStatement= NullNPStatement; X X uENTRY1("npUseStatement(0x%x)\n",pNameExpr); X if (pNameExpr!=NullNPStringExpr) { X pStatement= uTypedAlloc(NPStatementRec); X if (pStatement!=NullNPStatement) { X pStatement->what= NPUseStatement; X pStatement->u.pUseExpr= pNameExpr; X pStatement->pNext= NullNPStatement; X } X } X uRETURN(pStatement); X} X X/***====================================================================***/ X XNPStatementPtr XnpAssignStatement( pLHSExpr, pValueExpr, append ) XNPStringExprPtr pLHSExpr; XNPStringExprPtr pValueExpr; XBoolean append; X{ XNPStatementPtr pStatement= NullNPStatement; X X uENTRY3("npAssignStatement(0x%x,0x%x,%s)\n",pLHSExpr,pValueExpr, X booleanText(append)); X if ((pLHSExpr!=NullNPStringExpr)&&(pValueExpr!=NullNPStringExpr)) { X pStatement= uTypedAlloc(NPStatementRec); X if (pStatement!=NullNPStatement) { X pStatement->what= NPAssignStatement; X pStatement->u.assignS.append= append; X pStatement->u.assignS.pLHS= pLHSExpr; X pStatement->u.assignS.pValue= pValueExpr; X pStatement->pNext= NullNPStatement; X } X } X uRETURN(pStatement); X} X X/***====================================================================***/ X XNPStatementPtr XnpClassStatement( pClassExpr ) XNPStringExprPtr pClassExpr; X{ XNPStatementPtr pStatement= NullNPStatement; X X uENTRY1("npClassStatement(0x%x)\n",pClassExpr); X if (pClassExpr!=NullNPStringExpr) { X pStatement= uTypedAlloc(NPStatementRec); X if (pStatement!=NullNPStatement) { X pStatement->what= NPClassStatement; X pStatement->u.pClassExpr= pClassExpr; X pStatement->pNext= NullNPStatement; X } X } X uRETURN(pStatement); X} X X/***====================================================================***/ X XNPStatementPtr XnpComment(str) Xchar *str; X{ XNPStatementPtr pStatement= NullNPStatement; X X uENTRY1("npComment(%s)\n",uStringText(str)); X pStatement= uTypedAlloc(NPStatementRec); X if (pStatement!=NullNPStatement) { X pStatement->what= NPComment; X pStatement->u.comment= str; X pStatement->pNext= NullNPStatement; X } X uRETURN(pStatement); X} X X/***====================================================================***/ X XNPStatementPtr XnpIgnoreStatement() X{ XNPStatementPtr pStatement= NullNPStatement; X X uENTRY("npIgnoreStatement()\n"); X pStatement= uTypedAlloc(NPStatementRec); X if (pStatement!=NullNPStatement) { X pStatement->what= NPIgnoreStatement; X pStatement->pNext= NullNPStatement; X } X uRETURN(pStatement); X} X X/***====================================================================***/ X Xvoid XnpInsertStatement( pAfter, pAdded ) XNPStatementPtr pAfter; XNPStatementPtr pAdded; X{ XNPStatementPtr pNext; X X uENTRY2("npInsertStatement(0x%x,0x%x)\n",pAfter,pAdded); X if ((pAfter!=NullNPStatement)&&(pAdded!=NullNPStatement)) { X pNext= pAfter->pNext; X pAfter->pNext= pAdded; X if (pNext!=NullNPStatement) { X while (pAdded->pNext!=NullNPStatement) { X pAdded= pAdded->pNext; X } X pAdded->pNext= pNext; X } X } X uVOIDRETURN; X} X X/***====================================================================***/ X Xvoid XnpAppendStatement( pOnto, pAdded ) XNPStatementPtr pOnto; XNPStatementPtr pAdded; X{ XNPStatementPtr pNext; X X uENTRY2("npInsertStatement(0x%x,0x%x)\n",pOnto,pAdded); X if ((pOnto!=NullNPStatement)&&(pAdded!=NullNPStatement)) { X pNext= pOnto; X while (pNext->pNext!=NullNPStatement) { X pNext= pNext->pNext; X } X pNext->pNext= pAdded; X } X uVOIDRETURN; X} X X/***====================================================================***/ X Xextern void _npEvalStatement(/* */); X Xstatic void X_npSetMatch(pState,match) XNPStatePtr pState; Xchar *match; X{ X uENTRY2("_npSetMatch(0x%x,%s)\n",pState,uStringText(match)); X if (pState->lastMatchString!=NullString) X (void)uFree((Opaque)pState->lastMatchString); X pState->lastMatchString= match; X if (match==NullString) pState->lastMatchSubStrings.nMatches= 0; X else { X pState->lastMatchSubStrings.nMatches= 1; X pState->lastMatchSubStrings.matchLengths[0]= strlen(match); X pState->lastMatchSubStrings.matchStrings[0]= match; X } X uVOIDRETURN; X} X X/***====================================================================***/ X Xstatic char * X_npConstructName(rule,pState) Xchar *rule; XNPStatePtr pState; X{ Xchar buf[MAX_NAME_LEN+1]; Xchar *match,*rtrn; Xint matchLen,matchNum; Xint len; XRXMatchesPtr pMatches; X X uENTRY2("_npConstructName(%s,0x%x)\n",uStringText(rule),pState); X len= 0; X pMatches= &pState->lastMatchSubStrings; X if (rule!=NullString) { X while ((*rule)&&(len<MAX_NAME_LEN)) { X if ((*rule=='\\')&&isdigit((*(rule+1)))) { X matchNum= *(rule+1)-'0'-1; X rule+= 2; X if (matchNum<pMatches->nMatches) { X matchLen= pMatches->matchLengths[matchNum]; X match= pMatches->matchStrings[matchNum]; X while ((matchLen>0)&&(len<MAX_NAME_LEN)) { X buf[len]= *match; X len++; match++; matchLen--; X } X } X } X else { X buf[len]= *rule; X len++; rule++; X } X } X buf[len]= NUL; X } X if (len>0) rtrn= uStringDup(buf); X else rtrn= NullString; X uRETURN(rtrn); X} X X/***====================================================================***/ X Xextern Boolean _npEvalStringExpr(); Xextern Boolean _npEvalBoolExpr(); X Xstatic Boolean X_npEvalStringConcat(pLeft,pRight,pState,ppValue) XNPStringExprPtr pLeft; XNPStringExprPtr pRight; XNPStatePtr pState; Xchar **ppValue; X{ Xchar *str,*left,*right; XBoolean leftOk,rightOk; XBoolean allOk; X X uENTRY4("_npEvalStringConcat(0x%x,0x%x,0x%x,0x%x)\n",pLeft,pRight,pState, X ppValue); X X str= left= right= NullString; X allOk= True; X X leftOk= _npEvalStringExpr(pLeft,pState,&left); X rightOk= _npEvalStringExpr(pRight,pState,&right); X if (leftOk&&rightOk) { X str= (char *)uAlloc((unsigned)(strlen(left)+strlen(npJoinText)+ X strlen(right)+1)); X if (str!=NullString) { X sprintf(str,"%s%s%s",left,npJoinText,right); X } X else { X uWarning("Allocation failure in _npEvalStringConcat\n"); X allOk= False; X } X (void)uFree((Opaque)left); (void)uFree((Opaque)right); X } X else if (leftOk) str= left; X else if (rightOk) str= right; X else allOk= False; X if (ppValue!=(char **)NULL) X *ppValue= str; X uRETURN(allOk); X} X X/***====================================================================***/ X Xstatic Boolean X_npEvalStringConditional(pCond,pTrue,pFalse,pState,ppValue) XNPBoolExprPtr pCond; XNPStringExprPtr pTrue; XNPStringExprPtr pFalse; XNPStatePtr pState; Xchar **ppValue; X{ XBoolean ok; X X uENTRY5("_npEvalStringConditional(0x%x,0x%x,0x%x,0x%x)\n",pCond, X pTrue,pFalse,pState,ppValue); X X if (_npEvalBoolExpr(pCond,pState)) { X char *rule; X if (_npEvalStringExpr(pTrue,pState,&rule)) { X *ppValue= _npConstructName(rule,pState); X if (rule!=NullString) X (void)uFree((Opaque)rule); X ok= True; X } X else { X _npSetMatch(pState,NullString); X ok= False; X } X } X else { X _npSetMatch(pState,NullString); X ok= _npEvalStringExpr(pFalse,pState,ppValue); X } X uRETURN(ok); X} X X/***====================================================================***/ X XBoolean X_npEvalStringExpr(pExpr,pState,ppValue) XNPStringExprPtr pExpr; XNPStatePtr pState; Xchar **ppValue; X{ XBoolean exists= True; Xchar *str= NullString; X X uENTRY3("_npEvalStringExpr(0x%x,0x%x,0x%x)\n",pExpr,pState,ppValue); X switch (pExpr->type) { X case NPStringConstant: X str= uStringDup(pExpr->u.constant); X break; X case NPIdentifier: X case NPPropertyName: X if (pState->ResolveFunc) { X exists= (*pState->ResolveFunc)(pState->OSPrivate,pExpr->type, X pExpr->u.constant,&str); X } X else exists= False; X break; X case NPStringConcat: X exists= _npEvalStringConcat(pExpr->u.concat.pLeft, X pExpr->u.concat.pRight, X pState,&str); X break; X case NPStringConditional: X exists= _npEvalStringConditional(pExpr->u.conditional.pCondition, X pExpr->u.conditional.pTrue, X pExpr->u.conditional.pFalse, X pState,&str); X break; X X } X if (ppValue) *ppValue= str; X uRETURN(exists); X} X X/***====================================================================***/ X XBoolean X_npEvalBoolExpr(pExpr,pState) XNPBoolExprPtr pExpr; XNPStatePtr pState; X{ XBoolean ok; Xchar *leftStr= NullString; Xchar *rightStr= NullString; X X uENTRY2("_npEvalBoolExpr(0x%x,0x%x)\n",pExpr,pState); X ok= _npEvalStringExpr(pExpr->left,pState,&leftStr); X if (pExpr->right!=NullNPStringExpr) { X if (leftStr==NullString) ok= False; X ok= ok&&_npEvalStringExpr(pExpr->right,pState,&rightStr)&& X (rightStr!=NullString); X ok= ok&®exMatch(rightStr,leftStr,&pState->lastMatchSubStrings); X if ((!ok)&&(pState->lastMatchString!=NullString)) { X (void)_npSetMatch(pState,NullString); X } X else leftStr= NullString; X } X else if ((leftStr!=NullString)&&(strlen(leftStr)>0)) { X (void)_npSetMatch(pState,leftStr); X leftStr= NullString; X } X else ok= False; X if (leftStr!=NullString) uFree((Opaque)leftStr); X if (rightStr!=NullString) uFree((Opaque)rightStr); X if (pExpr->invert) ok= !ok; X uRETURN(ok); X} X X/***====================================================================***/ X Xstatic void X_npEvalAssignStatement(pAssign,pState) XNPAssignStatementPtr pAssign; XNPStatePtr pState; X{ Xchar *value= NullString; X X uENTRY2("_npEvalAssignStatement(0x%x,0x%x)\n",pAssign,pState); X if (_npEvalStringExpr(pAssign->pValue,pState,&value)) { X if (pState->ChangeFunc) { X (*pState->ChangeFunc)(pState->OSPrivate, X pAssign->pLHS->type,pAssign->pLHS->u.constant, X value,pAssign->append); X } X } X if (value!=NullString) (void)uFree((Opaque)value); X uVOIDRETURN; X} X X/***====================================================================***/ X Xstatic void X_npEvalUseStatement(pUseExpr,pState) XNPStringExprPtr pUseExpr; XNPStatePtr pState; X{ Xchar *rule= NullString; X X uENTRY2("_npEvalUseStatement(0x%x,0x%x)\n",pUseExpr,pState); X if (_npEvalStringExpr(pUseExpr,pState,&rule)) { X pState->resultName= _npConstructName(rule,pState); X pState->done= True; X if (rule!=NullString) X (void)uFree((Opaque)rule); X } X uVOIDRETURN; X} X X/***====================================================================***/ X Xstatic void X_npEvalClassStatement(pClassExpr,pState) XNPStringExprPtr pClassExpr; XNPStatePtr pState; X{ Xchar *rule= NullString; Xchar *result= NullString; X X uENTRY2("_npEvalClassStatement(0x%x,0x%x)\n",pClassExpr,pState); X if (_npEvalStringExpr(pClassExpr,pState,&rule)) { X result= _npConstructName(rule,pState); X if (result!=NullString) { X if (pState->resultClass!=NullString) { X (void)uFree((Opaque)pState->resultClass); X } X pState->resultClass= result; X } X if (rule!=NullString) X (void)uFree((Opaque)rule); X } X uVOIDRETURN; X} X X/***====================================================================***/ X Xstatic void X_npEvalCase(str,pCase,pState) Xchar *str; XNPCasePtr pCase; XNPStatePtr pState; X{ Xchar *pattern; XBoolean ok= True; X X uENTRY3("_npEvalCase(%s,0x%x,0x%x)\n",uStringText(str),pCase,pState); X if (str!=NullString) { X if (pCase->pattern!=NullNPStringExpr) { X _npSetMatch(pState,NullString); X ok= _npEvalStringExpr(pCase->pattern,pState,&pattern)&& X (pattern!=NullString); X ok= ok&®exMatch(pattern,str,&pState->lastMatchSubStrings); X if (pattern!=NullString) X (void)uFree((Opaque)pattern); X } X if (ok) X (void)_npEvalStatement(pCase->statement,pState); X } X uVOIDRETURN; X} X X/***====================================================================***/ X Xstatic void X_npEvalSwitchStatement(pSwitch,pState) XNPSwitchStatementPtr pSwitch; XNPStatePtr pState; X{ Xchar *str= NullString; XNPCasePtr pCase; X X uENTRY2("_npEvalSwitchStatement(0x%x,0x%x)\n",pSwitch,pState); X if (_npEvalStringExpr(pSwitch->string,pState,&str)) { X pCase= pSwitch->cases; X while ((pCase!=NullNPCase)&&(!pState->done)) { X (void)_npEvalCase(str,pCase,pState); X pCase= pCase->pNext; X } X if ((!pState->done)&&(pSwitch->dfltCase!=NullNPStatement)) { X (void)_npSetMatch(pState,str); X (void)_npEvalStatement(pSwitch->dfltCase,pState); X } X } X if (str!=NullString) { X (void)uFree((Opaque)str); X } X (void)_npSetMatch(pState,NullString); X uVOIDRETURN; X} X X/***====================================================================***/ X Xstatic void X_npEvalIfStatement(pIf,pState) XNPIfStatementPtr pIf; XNPStatePtr pState; X{ X uENTRY2("_npEvalIfStatement(0x%x,0x%x)\n",pIf,pState); X if (_npEvalBoolExpr(pIf->condition,pState)) X _npEvalStatement(pIf->thenClause,pState); X else if (pIf->elseClause!=NullNPStatement) X _npEvalStatement(pIf->elseClause,pState); X _npSetMatch(pState,NullString); X uVOIDRETURN; X} X X/***====================================================================***/ X Xvoid X_npEvalStatement(pStatement,pState) XNPStatementPtr pStatement; XNPStatePtr pState; X{ X uENTRY2("_npEvalStatement(0x%x,0x%x)\n",pStatement,pState); X while ((pStatement!=NullNPStatement)&&(!pState->done)) { X switch (pStatement->what) { X case NPIfStatement: X _npEvalIfStatement(&pStatement->u.ifS,pState); X break; X case NPSwitchStatement: X _npEvalSwitchStatement(&pStatement->u.switchS,pState); X break; X case NPUseStatement: X _npEvalUseStatement(pStatement->u.pUseExpr,pState); X break; X case NPClassStatement: X _npEvalClassStatement(pStatement->u.pClassExpr,pState); X break; X case NPAssignStatement: X _npEvalAssignStatement(&pStatement->u.assignS,pState); X break; X case NPIgnoreStatement: X pState->done= True; X pState->resultName= NullString; X pState->resultClass= NullString; X break; X case NPComment: X break; X } X pStatement= pStatement->pNext; X } X uVOIDRETURN; X} X X/***====================================================================***/ X XBoolean XnpEvalBoolExpr(pExpr,ppMatch,ResolveFunc,ChangeFunc,OSPrivate) XNPBoolExprPtr pExpr; Xchar **ppMatch; XNameResolveFunc ResolveFunc; XChangeNamedFunc ChangeFunc; XOpaque OSPrivate; X{ XNPStateRec state; XBoolean ok; X X uENTRY5("npEvalBoolExpr(0x%x,0x%x,0x%x,0x%x,0x%x)\n",pExpr,ppMatch, X ResolveFunc,ChangeFunc,OSPrivate); X state.done= False; X state.resultName= NullString; X state.resultClass= NullString; X state.lastMatchString= NullString; X bzero(&state.lastMatchString,sizeof(RXMatchesRec)); X state.ResolveFunc= ResolveFunc; X state.ChangeFunc= ChangeFunc; X state.OSPrivate= OSPrivate; X ok= _npEvalBoolExpr(pExpr,&state); X if (ok&&(ppMatch!=(char **)NULL)) { X *ppMatch= state.lastMatchString; X } X else _npSetMatch(&state,NullString); X uRETURN(ok); X} X X/***====================================================================***/ X XBoolean XnpEvalStringExpr(pExpr,ppRtrn,ResolveFunc,ChangeFunc,OSPrivate) XNPStringExprPtr pExpr; Xchar **ppRtrn; XNameResolveFunc ResolveFunc; XChangeNamedFunc ChangeFunc; XOpaque OSPrivate; X{ XNPStateRec state; XBoolean ok; X X uENTRY5("npEvalStringExpr(0x%x,0x%x,0x%x,0x%x,0x%x)\n",pExpr,ppRtrn, X ResolveFunc,ChangeFunc,OSPrivate); X state.done= False; X state.resultName= NullString; X state.resultClass= NullString; X state.lastMatchString= NullString; X bzero(&state.lastMatchString,sizeof(RXMatchesRec)); X state.ResolveFunc= ResolveFunc; X state.ChangeFunc= ChangeFunc; X state.OSPrivate= OSPrivate; X ok= _npEvalStringExpr(pExpr,&state,ppRtrn); X _npSetMatch(&state,NullString); X uRETURN(ok); X} X X/***====================================================================***/ X XBoolean XnpEvaluate(pStatement,ppName,ppClass,ResolveFunc,ChangeFunc,OSPrivate) XNPStatementPtr pStatement; Xchar **ppName; Xchar **ppClass; XNameResolveFunc ResolveFunc; XChangeNamedFunc ChangeFunc; XOpaque OSPrivate; X{ XNPStateRec state; X X uENTRY6("npEvaluate(0x%x,0x%x,0x%x,0x%x,0x%x,0x%x)\n",pStatement, X ppName,ppClass,ResolveFunc,ChangeFunc,OSPrivate); X state.done= False; X state.resultName= NullString; X state.resultClass= NullString; X state.lastMatchString= NullString; X bzero(&state.lastMatchString,sizeof(RXMatchesRec)); X state.ResolveFunc= ResolveFunc; X state.ChangeFunc= ChangeFunc; X state.OSPrivate= OSPrivate; X (void)_npEvalStatement(pStatement,&state); X if (ppName) { X *ppName= state.resultName; X } X else if (state.resultName!=NullString) { X uFree((Opaque)state.resultName); X } X _npSetMatch(&state,NullString); X if (ppClass) { X *ppClass= state.resultClass; X } X else if (state.resultClass!=NullString) { X uFree((Opaque)state.resultClass); X } X uRETURN(state.done); X} X END_OF_FILE if test 28216 -ne `wc -c <'./lib/names.c'`; then echo shar: \"'./lib/names.c'\" unpacked with wrong size! fi # end of './lib/names.c' fi echo shar: End of archive 13 \(of 14\). cp /dev/null ark13isdone 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