static void *allocMem // ALLOCATE MEMORY ( IDECBHdl hdl // - handle , unsigned long size ) // - size to be allocated { _Verify( hdl == FAKE_HDL, "reAllocMem -- bad handle" ); return malloc( size ); }
static IDEBool getInfo // GET INFORMATION ( IDECBHdl hdl // - handle , IDEInfoType type // - request type , unsigned long wparam // - param(1) , unsigned long lparam ) // - param(2) { IDEBool retn; // - return _Verify( hdl == FAKE_HDL, "getInfo -- bad handle" ); switch( type ) { case IDE_GET_RUN_OPTIONS : _Msg( "getInfo -- GET_RUN_OPTIONS request not implemented" ); retn = FAILED; break; case IDE_GET_SOURCE_FILE : retn = getString( (char*)lparam, source_file ); break; case IDE_GET_TARGET_FILE : retn = getString( (char*)lparam, target_file ); break; default : _Msg( "getInfo -- bad request" ); retn = FAILED; break; } return retn; }
static IDEBool printMessage // PRINT A MESSAGE ( IDECBHdl hdl // - handle , const char *message ) // - message { ErrorInfo err_info; // - error information _Verify( hdl == FAKE_HDL, "printMessage -- bad handle" ); puts( message ); if( ! IDEParseMessage( FAKE_HDL, message, &err_info ) ) { char number[8]; if( err_info.flags & ERRINFO_FILENAME ) { fputs( "info: File: ", stdout ); puts( err_info.filename ); } if( err_info.flags & ERRINFO_LINENUM ) { utoa( err_info.linenum, number, 10 ); fputs( "info: Line: ", stdout ); puts( number ); } if( err_info.flags & ERRINFO_COLUMN ) { utoa( err_info.col, number, 10 ); fputs( "info: Column: ", stdout ); puts( number ); } if( err_info.flags & ERRINFO_HELPINDEX ) { utoa( err_info.help_index, number, 10 ); fputs( "info: Help: ", stdout ); puts( number ); } } return OK; }
static void *reAllocMem // RE-ALLOCATE MEMORY ( IDECBHdl hdl // - handle , void *ptr // - allocated memory , unsigned long size ) // - size to be allocated { _Verify( hdl == FAKE_HDL, "reAllocMem -- bad handle" ); return realloc( ptr, size ); }
static void freeMem // FREE MEMORY ( IDECBHdl hdl // - handle , void *ptr ) // - allocated memory { _Verify( hdl == FAKE_HDL, "reAllocMem -- bad handle" ); if( NULL != ptr ) { free( ptr ); } }
static void saveOptions // SAVE OPTIONS ( void ) { IDEBool retn; // - return opt_written = 0; retn = IDESaveOptions( FAKE_HDL, options, &optionsWriter, &opt_written ); _Verify( retn == OK, "saveOptions -- failed" ); }
static int optionsReader // READ FUN (PASSED TO DLL) ( void *cookie // - magic , void *data // - data to be read , int size ) // - size { _Verify( cookie == &opt_read, "optionsReader -- bad cookie" ); if( opt_written >= opt_read + size ) { memcpy( data, &opt_data[ opt_read ], size ); opt_read += size; } else { size = 0; } return size; }
static int optionsWriter // WRITE FUN (PASSED TO DLL) ( void *cookie // - magic , void *data // - data to be written , int size ) // - size { _Verify( cookie == &opt_written, "optionsWriter -- bad cookie" ); if( sizeof( opt_data ) >= opt_written + size ) { memcpy( &opt_data[ opt_written ], data, size ); opt_written += size; } else { size = 0; } return size; }
static unsigned expandMacro // EXPAND A MACRO ( IDECBHdl hdl // - handle , char *fmtstr // - input string , char *buf // - output buffer , unsigned bufsize ) // - output size { size_t fmt_size; // - size to be formatted _Verify( hdl == FAKE_HDL, "expandMacro -- bad handle" ); fmt_size = strlen( fmtstr ) + 1; if( fmt_size <= bufsize ) { memcpy( buf, fmtstr, fmt_size ); } return fmt_size; }
static void loadOptions // LOAD OPTIONS ( void ) { IDEBool retn; // - return void *loaded; // - loaded options opt_read = 0; retn = IDELoadOptions( FAKE_HDL , &loaded , &optionsReader , &opt_read ); _Verify( retn == OK, "loadOptions -- failed" ); if( retn == OK ) { // IDE would free the option much later // we just zap loaded stuff into our area and free it now strcpy( options, loaded ); IDEFreeOptions( FAKE_HDL, loaded ); } }
RETVAL GetCtrlRoutineAddress(void) { RETVAL rv = EXIT_OK; // must be cleaned up g_hAddrFoundEvent = NULL; // create an event so we know when the async callback has completed g_hAddrFoundEvent = CreateEvent(NULL, TRUE, FALSE, NULL); // no security, manual reset, initially unsignaled, no name if (g_hAddrFoundEvent == NULL) { _HandleLastError(rv, __T("CreateEvent")); } // request that we be called on system signals if (!SetConsoleCtrlHandler(MyHandler, TRUE)) { _HandleLastError(rv, __T("SetConsoleCtrlHandler")); } // generate a signal if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0)) { _HandleLastError(rv, __T("GenerateConsoleCtrlEvent")); } // wait for our handler to be called { DWORD dwWaitResult = WaitForSingleObject(g_hAddrFoundEvent, INFINITE); if (dwWaitResult == WAIT_FAILED) { _HandleLastError(rv, __T("WaitForSingleObject")); } } _Verify(g_dwCtrlRoutineAddr != NULL, rv, error); error: if (g_hAddrFoundEvent != NULL) { if (!CloseHandle(g_hAddrFoundEvent)) { RETVAL rv2 = GetLastError(); _TeardownIfError(rv, rv2, __T("CloseHandle")); } } return rv; }
int main() { char cmd_line[82]; // - command line char const * cmd; // - scanner char code; // - current code IDEBool fatal_error; // - fatality indicator IDEBool retn; // - return code retn = OK; fatal_error = 0; _Verify( IDE_CUR_DLL_VER == IDEGetVersion(), "invalid DLL version" ); IDEInitDLL( FAKE_HDL, &callbacks, &dll_info ); puts( "\n" ); for( ; ; ) { ConsoleReadPrefixed( cmd_line, sizeof( cmd_line ), "FAKEIDE>" ); cmd = scanBlanks( cmd_line ); code = *cmd; cmd = scanBlanks( cmd + 1 ); switch( code ) { case '\0' : continue; case 'q' : break; case 's' : scanString( cmd, source_file ); continue; case 't' : scanString( cmd, target_file ); continue; case 'o' : scanString( cmd, options ); continue; case 'c' : retn = IDERunYourSelf( FAKE_HDL, options, &fatal_error ); continue; case 'r' : loadOptions(); continue; case 'w' : saveOptions(); continue; case '?' : puts( "" ); fputs( "OPTIONS: " , stdout ); puts( options ); fputs( "SOURCE: " , stdout ); puts( source_file ); fputs( "TARGET: " , stdout ); puts( target_file ); fputs( "RETURN: " , stdout ); puts( fmtBool( retn ) ); fputs( "FATAL: " , stdout ); puts( fmtBool( fatal_error ) ); dumpOptions(); puts( "" ); puts( "Enter 'h' for help" ); puts( "" ); continue; case 'h' : puts( "" ); puts( "o options [ set compiler options]" ); puts( "s source file [ set source file]" ); puts( "t target file [ set target file]" ); puts( "c [ do a compile]" ); puts( "w [ write current options ]" ); puts( "r [ read written options ]" ); puts( "" ); puts( "? [ dump IDE data ]" ); puts( "q [ quit ]" ); puts( "h [ display this message ]" ); puts( "" ); continue; default : _Msg( "undecipherable crap entered" ); continue; } break; } IDEFiniDLL( FAKE_HDL ); return 0; }