#include "precomp.h" #pragma hdrstop /*++ Copyright (c) 1991 Microsoft Corporation Module Name: inf_rt2.c Abstract: INF file runtime field interpreter. A given string is interpreted as a tokenized field and an output buffer containing the result is constructed. Author: Ted Miller (tedm) 10-Spetember-1991 --*/ /* Input stuff */ LPBYTE Interpret_Inputp; #define GETTOKEN() (*Interpret_Inputp++) #define PEEKTOKEN() (*Interpret_Inputp) #define UNGETTOKEN(t) (*(--Interpret_Inputp) = t) #define VERIFY_SIZE(s) \ if ( SpaceLeftInFieldBuffer < (s) ) { \ GrowBuffer(s); \ } /* end input stuff */ /* Output stuff */ #define MAX_FIELD_LENGTH 4096 PUCHAR InterpretedFieldBuffer; UINT SpaceLeftInFieldBuffer; UINT BufferSize; PUCHAR Interpret_OutputLoc; /* end output stuff */ SZ Interpret_GetField(VOID); BOOL DoVariable(VOID); BOOL DoListFromSectionNthItem(VOID); BOOL DoFieldAddressor(VOID); BOOL DoAppendItemToList(VOID); BOOL DoNthItemFromList(VOID); BOOL DoLocateItemInList(VOID); BOOL DoList(VOID); BOOL DoString(BYTE StringToken); /* Run time error field */ GRC grcRTLastError = grcOkay; VOID GrowBuffer(UINT Size); SZ APIENTRY InterpretField( SZ Field ) { SZ ReturnString, InputSave = Interpret_Inputp; Interpret_Inputp = Field; ReturnString = Interpret_GetField(); Interpret_Inputp = InputSave; return(ReturnString); } SZ Interpret_GetField( VOID ) { LPSTR OldOutputBuffer = InterpretedFieldBuffer; LPSTR OldInterpretLoc = Interpret_OutputLoc; UINT OldSpaceLeft = SpaceLeftInFieldBuffer; LPSTR ReturnString = NULL; BYTE Token; if((InterpretedFieldBuffer = SAlloc(SpaceLeftInFieldBuffer = MAX_FIELD_LENGTH)) == NULL) { grcRTLastError = grcOutOfMemory; return(NULL); } BufferSize = MAX_FIELD_LENGTH; Interpret_OutputLoc = InterpretedFieldBuffer; VERIFY_SIZE(1); SpaceLeftInFieldBuffer--; // leave space for terminating NUL while((Token = GETTOKEN()) && (Token != TOKEN_COMMA) && (Token != TOKEN_SPACE) && (Token != TOKEN_RIGHT_PAREN) && (Token != TOKEN_LIST_END)) { if(IS_STRING_TOKEN(Token)) { if(!DoString(Token)) { SFree(InterpretedFieldBuffer); goto Cleanup; } } else { switch(Token) { case TOKEN_VARIABLE: if(!DoVariable()) { SFree(InterpretedFieldBuffer); goto Cleanup; } break; case TOKEN_LIST_FROM_SECTION_NTH_ITEM: if(!DoListFromSectionNthItem()) { SFree(InterpretedFieldBuffer); goto Cleanup; } break; case TOKEN_FIELD_ADDRESSOR: if(!DoFieldAddressor()) { SFree(InterpretedFieldBuffer); goto Cleanup; } break; case TOKEN_APPEND_ITEM_TO_LIST: if(!DoAppendItemToList()) { SFree(InterpretedFieldBuffer); goto Cleanup; } break; case TOKEN_NTH_ITEM_FROM_LIST: if(!DoNthItemFromList()) { SFree(InterpretedFieldBuffer); goto Cleanup; } break; case TOKEN_LOCATE_ITEM_IN_LIST: if(!DoLocateItemInList()) { SFree(InterpretedFieldBuffer); goto Cleanup; } break; case TOKEN_LIST_START: if(!DoList()) { SFree(InterpretedFieldBuffer); goto Cleanup; } break; default: #if DBG { char str[100]; wsprintf(str,"Bogus token: %u",Token); MessBoxSzSz("Interpret_GetField",str); } #endif break; } // switch } // if-else } // while /* The following is because we want the routines DoOperator() and DoList() (below) to have access to their terminators. */ if((Token == TOKEN_RIGHT_PAREN) || (Token == TOKEN_LIST_END)) { UNGETTOKEN(Token); } Assert((LONG)SpaceLeftInFieldBuffer >= 0); // space provided for above *Interpret_OutputLoc = NUL; ReturnString = SRealloc(InterpretedFieldBuffer, BufferSize - SpaceLeftInFieldBuffer ); Assert(ReturnString); // buffer was shrinking; Cleanup: Interpret_OutputLoc = OldInterpretLoc; InterpretedFieldBuffer = OldOutputBuffer; SpaceLeftInFieldBuffer = OldSpaceLeft; return(ReturnString); } /* This routine gets the fields of an operator into an rgsz. */ RGSZ DoOperator( UINT FieldCount ) { UINT x; RGSZ rgsz; Assert(FieldCount); if((rgsz = (RGSZ)SAlloc((FieldCount+1)*sizeof(SZ))) == NULL) { grcRTLastError = grcOutOfMemory; return(NULL); } rgsz[FieldCount] = NULL; for(x=0; x= SymbolValueLength) { SpaceLeftInFieldBuffer -= SymbolValueLength; for(x=0; x= x) { SpaceLeftInFieldBuffer -= x; for(n=0; n= n) { SpaceLeftInFieldBuffer -= n; for(x=0; x SpaceLeftInFieldBuffer) { SFree(ListValue); FFreeRgsz(rgsz); grcRTLastError = grcNotOkay; return(FALSE); } ListTemp = ListValue; for(y=0; y ListSize)) { Item = ""; } else { Item = rgszList[n-1]; } x = lstrlen(Item); VERIFY_SIZE(x); if(SpaceLeftInFieldBuffer >= x) { SpaceLeftInFieldBuffer -= x; for(y=0; y= ListLength) { SpaceLeftInFieldBuffer -= ListLength; for(x=0; x= StringLength) { SpaceLeftInFieldBuffer -= StringLength; for(x=0; x