SemOffset SemStartResource( void ) /********************************/ { if( StopInvoked ) { RcFatalError( ERR_STOP_REQUESTED ); } if (CurrResFile.IsWatcomRes) { return( ResTell( CurrResFile.handle ) ); } else { /* open a temporary file and trade handles with the RES file */ RcTmpFileName( MSFormatTmpFile ); MSFormatHandle = CurrResFile.handle; CurrResFile.handle = MResOpenNewFile( MSFormatTmpFile ); if (CurrResFile.handle == -1) { CurrResFile.handle = MSFormatHandle; ResCloseFile( CurrResFile.handle ); remove( CurrResFile.filename ); RcFatalError( ERR_OPENING_TMP, MSFormatTmpFile, LastWresErrStr() ); } else { RegisterTmpFile( MSFormatTmpFile ); CurrResFile.filename = MSFormatTmpFile; } /* The start position should be 0 but to be safe call ResTell */ return( ResTell( CurrResFile.handle ) ); } }
bool InitRcMsgs( void ) { bool error; char testbuf[1]; #if defined( IDE_PGM ) || !defined( __WATCOMC__ ) char imageName[_MAX_PATH]; #else char *imageName; #endif #if defined( IDE_PGM ) _cmdname( imageName ); #elif !defined( __WATCOMC__ ) get_dllname( imageName, sizeof( imageName ) ); #else imageName = _LpDllName; #endif /* * swap open functions so this file handle is not buffered. * This makes it easier for layer0 to fool WRES into thinking * that the resource information starts at offset 0 */ error = RCOpenResFile( &Instance, imageName ); MsgShift = _WResLanguage() * MSG_LANG_SPACING; if( !error && !GetRcMsg( USAGE_MSG_FIRST, testbuf, sizeof( testbuf ) ) ) { error = true; } if( error ) { RcFatalError( ERR_RCSTR_NOT_FOUND ); } return( true ); }
int RcIoGetChar( void ) /*********************/ { bool isempty; bool error; if( IsEmptyFileStack( InStack ) ) { return( EOF ); } if( InStack.NextChar >= InStack.EofChar ) { /* we have reached the end of the buffer */ if( InStack.NextChar >= InStack.Buffer + InStack.BufferSize ) { /* try to read next buffer */ error = ReadBuffer( &(InStack) ); if( error ) { /* this error is reported in ReadBuffer so just terminate */ RcFatalError( ERR_NO_MSG ); } } if( InStack.NextChar >= InStack.EofChar ) { /* this is a real EOF */ /* unstack one file */ isempty = RcIoPopTextInputFile(); if( isempty ) { return( EOF ); } else { /* if we are still at the EOF char, there has been an error */ if( InStack.NextChar >= InStack.EofChar ) { /* this error is reported in ReadBuffer so just terminate */ RcFatalError( ERR_NO_MSG ); } else { /* return \n which will end the current token properly */ /* if it it is not a string and end it with a runaway */ /* string error for strings */ return( '\n' ); } } } } return( GetLogChar( &InStack ) ); } /* RcIoGetChar */
int InitRcMsgs( void ) { int error; WResFileID (* oldopen)(const char *, int, ...); char testbuf[1]; #if defined( IDE_PGM ) || !defined( __WATCOMC__ ) char imageName[_MAX_PATH]; #else char *imageName; #endif #if defined( IDE_PGM ) _cmdname( imageName ); #elif !defined( __WATCOMC__ ) get_dllname( imageName, sizeof( imageName ) ); #else imageName = _LpDllName; #endif /* * swap open functions so this file handle is not buffered. * This makes it easier for layer0 to fool WRES into thinking * that the resource information starts at offset 0 */ oldopen = WResRtns.open; WResRtns.open = open; error = OpenResFile( &Instance, imageName ); WResRtns.open = oldopen; if( !error ) { RegisterOpenFile( Instance.handle ); error = FindResources( &Instance ); if( !error ) { error = InitResources( &Instance ); } if( error ) { CloseResFile( &Instance ); UnRegisterOpenFile( Instance.handle ); } } MsgShift = _WResLanguage() * MSG_LANG_SPACING; if( !error && !GetRcMsg( USAGE_MSG_FIRST, testbuf, sizeof( testbuf ) ) ) { error = TRUE; } if( error ) { RcFatalError( ERR_RCSTR_NOT_FOUND ); } return( 1 ); }
void *RcMemMalloc( size_t size ) /******************************/ { void * ptr; #ifdef RC_USE_TRMEM ptr = _trmem_alloc( size, _trmem_guess_who(), RcMemHandle ); #else ptr = RCMemLayer1Malloc( size ); #endif if (ptr == NULL) { RcFatalError( ERR_OUT_OF_MEMORY ); } return( ptr ); }
void * RcMemRealloc( void * old_ptr, size_t newsize ) /***************************************************/ { void * ptr; #ifdef RC_USE_TRMEM ptr = _trmem_realloc( old_ptr, newsize, _trmem_guess_who(), RcMemHandle ); #else ptr = RCMemLayer1Realloc( old_ptr, newsize ); #endif if (ptr == NULL && newsize != 0) { RcFatalError( ERR_OUT_OF_MEMORY ); } return( ptr ); }
extern void *RCMemLayer1Malloc( size_t size ) /*******************************************/ { unsigned char *mem; BigMemList *memptr; HeapHandle *handle; HeapId *idptr; unsigned char heapindex; unsigned long headersize; heapindex = RCMemGetHeapIndex( size ); if( heapindex == BIGLIST_ID ) { headersize = sizeof( BigMemList ) + sizeof( HeapId ); #ifdef RCMEM_DEBUG memptr = malloc( size + headersize + 1 ); #else memptr = malloc( size + headersize ); #endif if( memptr == NULL ) { RcFatalError( ERR_OUT_OF_MEMORY ); } memptr->size = size; memptr->next = BigList; idptr = (HeapId *)( (char *)memptr + sizeof( BigMemList ) ); idptr->id = BIGLIST_ID; #ifdef RCMEM_DEBUG *((unsigned char *)memptr + size + headersize ) = RCMEM_ENDBYTE; #endif mem = (unsigned char *)memptr + headersize; BigList = memptr; } else { handle = Heaps[ heapindex ]; #ifdef RCMEM_DEBUG mem = RCMemLayer0Malloc( handle, size + sizeof( HeapId ) ); #else mem = RCMemLayer0Malloc( handle ); #endif ((HeapId *)mem)->id = heapindex; mem += sizeof( HeapId ); } return( mem ); }
extern void RCMemLayer1Free( void *mem ) /**************************************/ { char *blockptr; HeapId *heapid; if( mem == NULL ) { return; } blockptr = (char *)mem - sizeof( HeapId ); heapid = (HeapId *)blockptr; if( heapid->id == BIGLIST_ID ) { FreeBigListNode( mem, TRUE ); } else if( heapid->id < NUM_HEAPS ) { RCMemLayer0Free( blockptr, Heaps[ heapid->id ] ); } else { RcFatalError( ERR_INTERNAL, INTERR_MEM_FREE_FAILED ); } }
static void FreeBigListNode( void *mem, char freemem ) /****************************************************/ { BigMemList *travptr; BigMemList *prevnode; unsigned char *memptr; unsigned long headersize; headersize = sizeof( BigMemList ) + sizeof( HeapId ); memptr = (unsigned char *)BigList + headersize; travptr = BigList->next; if( memptr == mem ) { if( freemem ) { free( BigList ); } BigList = travptr; return; } travptr = BigList; prevnode = BigList; while( travptr != NULL ) { memptr = (unsigned char *)travptr + headersize; if( memptr == mem ) { prevnode->next = travptr->next; #ifdef RCMEM_DEBUG if( *(memptr + travptr->size ) != RCMEM_ENDBYTE ) { RcFprintf( stderr, NULL, "(%x) Memory Overrun (biglist)\n", mem ); } #endif if( freemem ) { free( travptr ); } break; } prevnode = travptr; travptr = travptr->next; } if( travptr == NULL ) { RcFatalError( ERR_INTERNAL, INTERR_MEM_FREE_FAILED ); } }
extern void *RCMemLayer1Realloc( void *mem, size_t size ) /*******************************************************/ { char *blockptr; BigMemList *newbigptr; void *newnode; HeapId *heapid; HeapId *idptr; BigMemList *reallocptr; unsigned long reallocsize; unsigned short headersize; #ifdef RCMEM_DEBUG DebugMemInfo *debugmem; #endif if( mem == NULL ) { // emulate realloc() behaviour return( RCMemLayer1Malloc( size ) ); } blockptr = (char *)mem - sizeof( HeapId ); heapid = (HeapId *)blockptr; if( heapid->id == BIGLIST_ID ) { reallocptr = (BigMemList *)( (char *)heapid - sizeof( BigMemList ) ); if( reallocptr->size < size ) { FreeBigListNode( mem, FALSE ); headersize = sizeof( BigMemList ) + sizeof( HeapId ); reallocsize = size + headersize; #ifdef RCMEM_DEBUG reallocsize++; #endif newnode = realloc( reallocptr, reallocsize ); if( newnode == NULL ) { RcFatalError( ERR_OUT_OF_MEMORY ); } newbigptr = (BigMemList *)newnode; newbigptr->next = BigList; newbigptr->size = size; idptr = (HeapId *)( (char *)newbigptr + sizeof( BigMemList ) ); idptr->id = BIGLIST_ID; BigList = newbigptr; #ifdef RCMEM_DEBUG *((unsigned char *)newbigptr + headersize + size ) = RCMEM_ENDBYTE; #endif return( (char *)newbigptr + headersize ); } } else if( heapid->id < NUM_HEAPS ) { if( size + sizeof( HeapId ) > HeapSizes[ heapid->id ] ) { newnode = RCMemLayer1Malloc( size ); memcpy( newnode, mem, HeapSizes[ heapid->id ] - sizeof( HeapId ) ); RCMemLayer1Free( mem ); return( newnode ); } #ifdef RCMEM_DEBUG else { debugmem = (DebugMemInfo *)((char *)blockptr - sizeof( DebugMemInfo ) ); debugmem->size = size + sizeof( HeapId ); *((unsigned char *)mem + size) = RCMEM_ENDBYTE; } #endif } else { RcFatalError( ERR_INTERNAL, INTERR_MEM_REALLOC_FAILED ); } return( mem ); }
static YYTOKENTYPE scanCPPDirective( ScanValue *value ) /******************************************************/ /* This function takes the correct action for the #line directive and returns */ /* the token following the preprocessor stuff. It uses Scan to do it's */ /* scanning. DON'T call this function from within Scan or the functions it */ /* calls unless you are very careful about recurtion. */ { YYTOKENTYPE token; int linenum; if( StopInvoked ) { RcFatalError( ERR_STOP_REQUESTED ); } /* get the "line" or "pragma" directive */ token = scanDFA( value ); if( token != Y_NAME ) { RcFatalError( ERR_INVALID_CPP ); } if( stricmp( value->string.string, "line" ) == 0 ) { RESFREE( value->string.string ); /* get the line number */ token = scanDFA( value ); if( token != Y_INTEGER ) { RcFatalError( ERR_INVALID_CPP_LINE ); } RESFREE( value->intinfo.str ); value->intinfo.str = NULL; linenum = value->intinfo.val; /* get the filename if there is one */ token = scanDFA( value ); if( token == Y_STRING ) { RcIoSetLogicalFileInfo( linenum, value->string.string ); if( AddDependency( value->string.string ) ) { ErrorHasOccured = true; } RESFREE( value->string.string ); token = scanDFA( value ); } else { RcIoSetLogicalFileInfo( linenum, NULL ); } } else if( stricmp( value->string.string, "pragma" ) == 0 ) { RESFREE( value->string.string ); token = Y_POUND_PRAGMA; } else if( stricmp( value->string.string, "error" ) == 0 ) { char buf[80]; unsigned i; i = 0; while( LookAhead != '\n' && LookAhead != EOF ) { buf[i] = LookAhead; i ++; GetNextChar(); } buf[i] = '\0'; RcFatalError( ERR_TEXT_FROM_CPP, buf ); } else { RcFatalError( ERR_INVALID_CPP ); } return( token ); } /* scanCPPDirective */
static void CheckParms( void ) /****************************/ { char *defext; CheckExtension( CmdLineParms.InFileName, "rc" ); CheckPass2Only(); /* was an EXE file name given */ if( CmdLineParms.InExeFileName[0] == '\0' ) { if (CmdLineParms.NoResFile) { strncpy( CmdLineParms.InExeFileName, CmdLineParms.InFileName, _MAX_PATH ); } else { MakeFileName( CmdLineParms.InFileName, CmdLineParms.InExeFileName, "exe" ); } } else { CheckExtension( CmdLineParms.InExeFileName, "exe" ); } /* was an output RES file name given */ if( CmdLineParms.PreprocessOnly ) { defext = "lst"; } else { defext = "res"; } if( CmdLineParms.OutResFileName[0] == '\0' ) { MakeFileName( CmdLineParms.InFileName, CmdLineParms.OutResFileName, defext ); } else { CheckExtension( CmdLineParms.OutResFileName, defext ); } /* was an output EXE file name given */ if( CmdLineParms.OutExeFileName[0] == '\0' ) { strncpy( CmdLineParms.OutExeFileName, CmdLineParms.InExeFileName, _MAX_PATH ); } else { CheckExtension( CmdLineParms.OutExeFileName, "exe" ); } /* check for the existance of the input files */ if (! (CmdLineParms.Pass2Only && CmdLineParms.NoResFile) ) { if( access( CmdLineParms.InFileName, F_OK ) != 0 ) { RcFatalError( ERR_CANT_FIND_FILE, CmdLineParms.InFileName ); } } if( !CmdLineParms.Pass1Only && !CmdLineParms.PreprocessOnly ) { if( access( CmdLineParms.InExeFileName, F_OK ) != 0 ) { RcFatalError( ERR_CANT_FIND_FILE, CmdLineParms.InExeFileName ); } } if( CmdLineParms.GenAutoDep && CmdLineParms.MSResFormat ) { RcFatalError( ERR_OPT_NOT_VALID_TOGETHER, "-ad", "-zm" ); } if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN32 ) { switch( CmdLineParms.MBCharSupport ) { case DB_SIMPLIFIED_CHINESE: strcpy( CmdLineParms.CodePageFile, "936.uni" ); break; case DB_TRADITIONAL_CHINESE: strcpy( CmdLineParms.CodePageFile, "950.uni" ); break; case DB_KANJI: strcpy( CmdLineParms.CodePageFile, "kanji.uni" ); break; case DB_WANSUNG_KOREAN: strcpy( CmdLineParms.CodePageFile, "949.uni" ); break; } } if( CmdLineParms.PreprocessOnly && CmdLineParms.NoPreprocess ) { RcFatalError( ERR_OPT_NOT_VALID_TOGETHER, "-o", "-zn" ); } } /* CheckParms */
void PP_OutOfMemory( void ) /*************************/ { RcFatalError( ERR_OUT_OF_MEMORY ); }