void debug_init() { /* Send all reports to STDOUT */ _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT ); _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT ); _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT ); _CrtMemCheckpoint( &s1 ); /* * Set the debug-heap flag so that freed blocks are kept on the * linked list, to catch any inadvertent use of freed memory */ SET_CRT_DEBUG_FIELD( _CRTDBG_DELAY_FREE_MEM_DF ); /* * Set the debug-heap flag so that memory leaks are reported when * the process terminates. Then, exit. */ SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF ); }
LRESULT CmdWindviConfig (HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl) { #if 0 SET_CRT_DEBUG_FIELD( _CRTDBG_DELAY_FREE_MEM_DF ); SET_CRT_DEBUG_FIELD( _CRTDBG_CHECK_ALWAYS_DF ); #endif DoConfigPSheet(hwnd); return 0; }
int main(int argc, char* argv[]) { program_description * program = 0; int i, errstatus; #if defined(WIN32) /* if _DEBUG is not defined, these macros will result in nothing. */ SETUP_CRTDBG; /* Set the debug-heap flag so that freed blocks are kept on the linked list, to catch any inadvertent use of freed memory */ SET_CRT_DEBUG_FIELD( _CRTDBG_DELAY_FREE_MEM_DF ); #endif redirect_stdout = -1; output_and_cleanup_function = output_and_cleanup; #if 0 extern MKTEXDLL string (* var_lookup)(const_string); var_lookup = getval; #endif mktexinit(argc, argv); for(i = 0; makedesc[i].name; ++i) { if (FILESTRCASEEQ(kpse_program_name, makedesc[i].name)) { program_number = i; progname = makedesc[i].name; program = makedesc+i; break; } } if (!makedesc[i].name) { fprintf(stderr, "This program was incorrectly copied to the name %s\n", argv[0]); return 1; } /* mktex_opt may modify argc and shift argv */ argc = mktex_opt(argc, argv, program); errstatus = program->prog(argc, argv); mt_exit(errstatus); return 0; /* Not reached !!! */ }
// initialize the diagnostics environment. // int diagnostics_init( int _flags, const char* stdout_prefix, const char* stderr_prefix ) { // Check to see if we have already been called // if (diagnostics_initialized) { return ERR_INVALID_PARAM; } diagnostics_initialized = true; // Setup initial values // flags = _flags; strcpy(stdout_log, ""); strcpy(stdout_archive, ""); strcpy(stderr_log, ""); strcpy(stderr_archive, ""); strcpy(boinc_dir, ""); strcpy(boinc_install_dir, ""); boinc_proxy_enabled = 0; strcpy(boinc_proxy, ""); strcpy(symstore, ""); // Check for invalid parameter combinations // if ((flags & BOINC_DIAG_REDIRECTSTDERR) && (flags & BOINC_DIAG_REDIRECTSTDERROVERWRITE)) { return ERR_INVALID_PARAM; } if ((flags & BOINC_DIAG_REDIRECTSTDOUT) && (flags & BOINC_DIAG_REDIRECTSTDOUTOVERWRITE)) { return ERR_INVALID_PARAM; } // Determine where the log files are to be stored // if (flags & BOINC_DIAG_PERUSERLOGFILES) { char user_dir[MAXPATHLEN]; #if defined(_WIN32) snprintf(user_dir, sizeof(user_dir), "%s", getenv("APPDATA")); strncat(user_dir, "/BOINC", sizeof(user_dir) - strlen(user_dir)-1); #elif defined(__APPLE__) snprintf(user_dir, sizeof(user_dir), "%s", getenv("HOME")); strncat(user_dir, "/Library/Application Support/BOINC", sizeof(user_dir) - strlen(user_dir)-1); #else snprintf(user_dir, sizeof(user_dir), "%s", getenv("HOME")); strncat(user_dir, "/.BOINC", sizeof(user_dir) - strlen(user_dir)-1); #endif // Check to see if the directory exists if (!is_dir(user_dir)) { boinc_mkdir(user_dir); } snprintf(stdout_log, sizeof(stdout_log), "%s/%s.txt", user_dir, stdout_prefix); snprintf(stdout_archive, sizeof(stdout_archive), "%s/%s.old", user_dir, stdout_prefix); snprintf(stderr_log, sizeof(stderr_log), "%s/%s.txt", user_dir, stderr_prefix); snprintf(stderr_archive, sizeof(stderr_archive), "%s/%s.old", user_dir, stderr_prefix); } else { snprintf(stdout_log, sizeof(stdout_log), "%s.txt", stdout_prefix); snprintf(stdout_archive, sizeof(stdout_archive), "%s.old", stdout_prefix); snprintf(stderr_log, sizeof(stderr_log), "%s.txt", stderr_prefix); snprintf(stderr_archive, sizeof(stderr_archive), "%s.old", stderr_prefix); } // Archive any old stderr.txt and stdout.txt files, if requested // if (flags & BOINC_DIAG_ARCHIVESTDERR) { boinc_copy(stderr_log, stderr_archive); } if (flags & BOINC_DIAG_ARCHIVESTDOUT) { boinc_copy(stdout_log, stdout_archive); } // Redirect stderr and/or stdout, if requested // if (flags & BOINC_DIAG_REDIRECTSTDERR) { file_size(stderr_log, stderr_file_size); stderr_file = freopen(stderr_log, "a", stderr); if (!stderr_file) { return ERR_FOPEN; } setbuf(stderr_file, 0); } if (flags & BOINC_DIAG_REDIRECTSTDERROVERWRITE) { stderr_file = freopen(stderr_log, "w", stderr); if (!stderr_file) { return ERR_FOPEN; } setbuf(stderr_file, 0); } if (flags & BOINC_DIAG_REDIRECTSTDOUT) { file_size(stdout_log, stdout_file_size); stdout_file = freopen(stdout_log, "a", stdout); if (!stdout_file) { return ERR_FOPEN; } } if (flags & BOINC_DIAG_REDIRECTSTDOUTOVERWRITE) { stdout_file = freopen(stdout_log, "w", stdout); if (!stdout_file) { return ERR_FOPEN; } } #if defined(_WIN32) #if defined(_DEBUG) _CrtSetReportHook(boinc_message_reporting); if (flags & BOINC_DIAG_MEMORYLEAKCHECKENABLED) { SET_CRT_DEBUG_FIELD(_CRTDBG_LEAK_CHECK_DF); } if (flags & BOINC_DIAG_HEAPCHECKENABLED) { if (flags & BOINC_DIAG_HEAPCHECKEVERYALLOC) { SET_CRT_DEBUG_FIELD(_CRTDBG_CHECK_ALWAYS_DF); } else { SET_CRT_DEBUG_FIELD(_CRTDBG_CHECK_EVERY_1024_DF); } } if (flags & BOINC_DIAG_BOINCAPPLICATION) { if (flags & BOINC_DIAG_MEMORYLEAKCHECKENABLED) { _CrtMemCheckpoint(&start_snapshot); } } #endif // defined(_DEBUG) // Initialize the thread list structure // The data for this structure should be set by // boinc_init or boinc_init_graphics. diagnostics_init_thread_list(); diagnostics_init_unhandled_exception_monitor(); diagnostics_init_message_monitor(); #endif // defined(_WIN32) #ifdef ANDROID #define resolve_func(l,x) \ x=(x##_t)dlsym(l,#x); \ if (!x) {\ fprintf(stderr,"Unable to resolve function %s\n",#x); \ unwind_backtrace_signal_arch=NULL; \ } if ((libhandle=dlopen("libcorkscrew.so",RTLD_NOW|RTLD_GLOBAL))) { resolve_func(libhandle,unwind_backtrace_signal_arch); resolve_func(libhandle,acquire_my_map_info_list); resolve_func(libhandle,release_my_map_info_list); resolve_func(libhandle,get_backtrace_symbols); resolve_func(libhandle,free_backtrace_symbols); resolve_func(libhandle,format_backtrace_line); resolve_func(libhandle,load_symbol_table); resolve_func(libhandle,free_symbol_table); resolve_func(libhandle,find_symbol); } else { fprintf(stderr,"stackdumps unavailable\n"); } #endif // ANDROID // Install unhandled exception filters and signal traps. if (BOINC_SUCCESS != boinc_install_signal_handlers()) { return ERR_SIGNAL_OP; } // Store various pieces of inforation for future use. if (flags & BOINC_DIAG_BOINCAPPLICATION) { char buf[256]; char proxy_address[256]; int proxy_port; MIOFILE mf; FILE* p; #ifdef _WIN32 LONG lReturnValue; HKEY hkSetupHive; DWORD dwSize = 0; #endif strcpy(buf, ""); strcpy(proxy_address, ""); proxy_port = 0; #ifndef _USING_FCGI_ p = fopen(INIT_DATA_FILE, "r"); #else p = FCGI::fopen(INIT_DATA_FILE, "r"); #endif if (p) { mf.init_file(p); while(mf.fgets(buf, sizeof(buf))) { if (match_tag(buf, "</app_init_data>")) break; else if (parse_str(buf, "<boinc_dir>", boinc_dir, sizeof(boinc_dir))) continue; else if (parse_str(buf, "<symstore>", symstore, sizeof(symstore))) ; else if (match_tag(buf, "<use_http_proxy/>")) { boinc_proxy_enabled = true; continue; } else if (parse_str(buf, "<http_server_name>", proxy_address, sizeof(proxy_address))) continue; else if (parse_int(buf, "<http_server_port>", proxy_port)) continue; } fclose(p); } if (boinc_proxy_enabled) { int buffer_used = snprintf(boinc_proxy, sizeof(boinc_proxy), "%s:%d", proxy_address, proxy_port); if ((sizeof(boinc_proxy) == buffer_used) || (-1 == buffer_used)) { boinc_proxy[sizeof(boinc_proxy)-1] = '\0'; } } #ifdef _WIN32 // Lookup the location of where BOINC was installed to and store // that for future use. lReturnValue = RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Space Sciences Laboratory, U.C. Berkeley\\BOINC Setup"), 0, KEY_READ, &hkSetupHive ); if (lReturnValue == ERROR_SUCCESS) { // How large does our buffer need to be? dwSize = sizeof(boinc_install_dir); lReturnValue = RegQueryValueEx( hkSetupHive, _T("INSTALLDIR"), NULL, NULL, (LPBYTE)&boinc_install_dir, &dwSize ); } if (hkSetupHive) RegCloseKey(hkSetupHive); #endif } return BOINC_SUCCESS; }
/* ================== WinMain ================== */ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char cwd[MAX_OSPATH]; // int startTime, endTime; SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF ); // _CrtSetBreakAlloc(34804); // should never get a previous instance in Win32 if ( hPrevInstance ) { return 0; } g_wv.hInstance = hInstance; Q_strncpyz( sys_cmdline, lpCmdLine, sizeof( sys_cmdline ) ); // done before Com/Sys_Init since we need this for error output Sys_CreateConsole(); // no abort/retry/fail errors SetErrorMode( SEM_FAILCRITICALERRORS ); // get the initial time base Sys_Milliseconds(); #if 0 // if we find the CD, add a +set cddir xxx command line Sys_ScanForCD(); #endif Sys_InitStreamThread(); Com_Init( sys_cmdline ); QuickMemTest(); _getcwd (cwd, sizeof(cwd)); Com_Printf("Working directory: %s\n", cwd); // hide the early console since we've reached the point where we // have a working graphics subsystems if ( !com_viewlog->integer ) { Sys_ShowConsole( 0, qfalse ); } // main game loop while( 1 ) { // if not running as a game client, sleep a bit if ( g_wv.isMinimized ) { Sleep( 5 ); } #ifdef _DEBUG if (!g_wv.activeApp) { Sleep(50); } #endif // _DEBUG // set low precision every frame, because some system calls // reset it arbitrarily // _controlfp( _PC_24, _MCW_PC ); // startTime = Sys_Milliseconds(); // make sure mouse and joystick are only called once a frame IN_Frame(); // run the game Com_Frame(); // endTime = Sys_Milliseconds(); // totalMsec += endTime - startTime; // countMsec++; } // never gets here }
int main ( int argc, char **argv ) { char commandLine[ MAX_STRING_CHARS ] = { 0 }; // int startTime, endTime; SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF ); // _CrtSetBreakAlloc(34804); Sys_CreateConsole(); // no abort/retry/fail errors SetErrorMode( SEM_FAILCRITICALERRORS ); // get the initial time base Sys_Milliseconds(); Sys_SetBinaryPath( Sys_Dirname( argv[ 0 ] ) ); Sys_SetDefaultInstallPath( DEFAULT_BASEDIR ); // Concatenate the command line for passing to Com_Init for( int i = 1; i < argc; i++ ) { const bool containsSpaces = (strchr(argv[i], ' ') != NULL); if (containsSpaces) Q_strcat( commandLine, sizeof( commandLine ), "\"" ); Q_strcat( commandLine, sizeof( commandLine ), argv[ i ] ); if (containsSpaces) Q_strcat( commandLine, sizeof( commandLine ), "\"" ); Q_strcat( commandLine, sizeof( commandLine ), " " ); } Com_Init( commandLine ); QuickMemTest(); // hide the early console since we've reached the point where we // have a working graphics subsystems if ( !com_viewlog->integer ) { Sys_ShowConsole( 0, qfalse ); } // main game loop while( 1 ) { // if not running as a game client, sleep a bit if ( g_wv.isMinimized ) { Sleep( 5 ); } #ifdef _DEBUG if (!g_wv.activeApp) { Sleep(50); } #endif // _DEBUG // make sure mouse and joystick are only called once a frame IN_Frame(); // run the game Com_Frame(); } }
int AP_Win32App::WinMain(const char * szAppName, HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { if (!g_thread_supported ()) g_thread_init (NULL); bool bShowApp = true; BOOL bInitialized = FALSE; // this is a static function and doesn't have a 'this' pointer. MSG msg; #ifdef _MSC_VER _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG ); _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG ); _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_WNDW); #endif // HACK: load least-common-denominator Rich Edit control // TODO: fix Spell dlg so we don't rely on this // ALT: make it a Preview widget instead HINSTANCE hinstRich = LoadLibraryW(L"riched32.dll"); if (!hinstRich) hinstRich = LoadLibraryW(L"riched20.dll"); UT_return_val_if_fail (hinstRich, 1); AP_Win32App * pMyWin32App; // OLE Stuff if (SUCCEEDED(OleInitialize(NULL))) bInitialized = TRUE; // We put this in a block to force the destruction of Args in the stack { UT_Win32LocaleString scnv; UT_UTF8String sUTFCmdLine; // Load the command line into an XAP_Args class scnv.fromLocale(GetCommandLineW()); sUTFCmdLine=scnv.utf8_str(); XAP_Args XArgs = XAP_Args(sUTFCmdLine.utf8_str()); // Step 1: Initialize our application. pMyWin32App = new AP_Win32App(hInstance, szAppName); AP_Args Args = AP_Args(&XArgs, szAppName, pMyWin32App); Args.parseOptions(); pMyWin32App->initialize(); // Step 2: Handle all non-window args. // process args (calls common arg handler, which then calls platform specific) // As best I understand, it returns true to continue and show window, or // false if no window should be shown (and thus we should simply exit). bool windowlessArgsWereSuccessful = true; if (!Args.doWindowlessArgs(windowlessArgsWereSuccessful)) { pMyWin32App->shutdown(); // properly shutdown the app 1st delete pMyWin32App; return (windowlessArgsWereSuccessful ? 0 : -1); } // Step 3: Create windows as appropriate. // if some args are botched, it returns false and we should // continue out the door. // We used to check for bShowApp here. It shouldn't be needed // anymore, because doWindowlessArgs was supposed to bail already. -PL if (!pMyWin32App->openCmdLineFiles(&Args)) { pMyWin32App->shutdown(); // properly shutdown the app 1st delete pMyWin32App; return 0; } } // // This block is controlled by the Structured Exception Handle // if any crash happens here we will recover it and save the file (cross fingers) // try { UT_uint32 iHeight = 0, iWidth = 0, t_flag =0; UT_sint32 iPosX = 0, iPosY = 0; if (!((XAP_App::getApp()->getGeometry(&iPosX,&iPosY,&iWidth,&iHeight,&t_flag)) && ((iWidth > 0) && (iHeight > 0))) ) XAP_App::getApp()->getDefaultGeometry(iWidth,iHeight,t_flag); if ((t_flag & PREF_FLAG_GEOMETRY_MAXIMIZED)==PREF_FLAG_GEOMETRY_MAXIMIZED) iCmdShow = SW_SHOWMAXIMIZED; if (bShowApp) { // display the windows for(UT_sint32 i = 0; i < pMyWin32App->m_vecFrames.getItemCount(); i++) { AP_Win32Frame * curFrame = (AP_Win32Frame*)pMyWin32App->m_vecFrames[i]; UT_continue_if_fail(curFrame); HWND hwnd = curFrame->getTopLevelWindow(); ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); } // do dispatch loop while(UT_GetMessage(&msg, NULL, 0, 0)) { // TranslateMessage is not called because AbiWord // has its own way of decoding keyboard accelerators if (pMyWin32App->handleModelessDialogMessage(&msg)) continue; TranslateMessage(&msg); UT_DispatchMessage(&msg); // Check for idle condition while( !UT_Win32Idle::_isEmpty() && !PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE) ) { // Fire idle functions when no pending messages UT_Win32Idle::_fireall(); } } } // Un-init OLE if (bInitialized) OleUninitialize(); FreeLibrary(hinstRich); // unload all loaded plugins (remove some of the memory leaks shown at shutdown :-) XAP_ModuleManager::instance().unloadAllPlugins(); // Step 4: Destroy the App. It should take care of deleting all frames. pMyWin32App->shutdown(); delete pMyWin32App; }// end of thes block is controlled by the Exception Handler // // If an exception happens, with "catch" the block // and then the save it into disk // catch (...) { #ifdef DEBUG throw; #endif AP_Win32App *pApp = (AP_Win32App *) XAP_App::getApp(); UT_return_val_if_fail (pApp,1); // first of all, try to save the current prefs (so that any log entries are dumped // onto disk -- this allows us to save useful info for dbg purposes) we will enclose // this inside of a try/catch block, so that in the (unlikely) case something goes // badly wrong when writing the prefs file, we still get chance to save the open // documents try { if(pApp->getPrefs()) { pApp->getPrefs()->savePrefsFile(); } } catch(...) { // do nothing } IEFileType abiType = IE_Imp::fileTypeForSuffix(".abw"); for (UT_sint32 i = 0; i < pApp->m_vecFrames.getItemCount(); i++) { AP_Win32Frame * curFrame = (AP_Win32Frame*)pApp->m_vecFrames[i]; UT_continue_if_fail(curFrame); // again, we want to catch any exception thrown while saving individual documents, // in order to run through the whole loop try { if (NULL == curFrame->getFilename()) curFrame->backup(".abw.saved", abiType); else curFrame->backup(".saved", abiType); } catch(...) { // do nothing } } // Tell the user was has just happened AP_Win32Frame * curFrame = (AP_Win32Frame*)pApp->m_vecFrames[0]; if (curFrame) { curFrame->showMessageBox(AP_STRING_ID_MSG_Exception,XAP_Dialog_MessageBox::b_O, XAP_Dialog_MessageBox::a_OK); } }// end of except SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF ); return msg.wParam; }
// initialize the diagnostics environment. // int diagnostics_init( int _flags, const char* stdout_prefix, const char* stderr_prefix ) { // Check to see if we have already been called if (diagnostics_initialized) { return ERR_INVALID_PARAM; } diagnostics_initialized = true; // Setup initial values flags = _flags; snprintf(stdout_log, sizeof(stdout_log), "%s.txt", stdout_prefix); snprintf(stdout_archive, sizeof(stdout_archive), "%s.old", stdout_prefix); snprintf(stderr_log, sizeof(stderr_log), "%s.txt", stderr_prefix); snprintf(stderr_archive, sizeof(stderr_archive), "%s.old", stderr_prefix); strcpy(boinc_dir, ""); strcpy(boinc_install_dir, ""); boinc_proxy_enabled = 0; strcpy(boinc_proxy, ""); strcpy(symstore, ""); // Check for invalid parameter combinations if ((flags & BOINC_DIAG_REDIRECTSTDERR) && (flags & BOINC_DIAG_REDIRECTSTDERROVERWRITE)) { return ERR_INVALID_PARAM; } if ((flags & BOINC_DIAG_REDIRECTSTDOUT) && (flags & BOINC_DIAG_REDIRECTSTDOUTOVERWRITE)) { return ERR_INVALID_PARAM; } // Archive any old stderr.txt and stdout.txt files, if requested if (flags & BOINC_DIAG_ARCHIVESTDERR) { boinc_copy(stderr_log, stderr_archive); } if (flags & BOINC_DIAG_ARCHIVESTDOUT) { boinc_copy(stdout_log, stdout_archive); } // Redirect stderr and/or stdout, if requested // if (flags & BOINC_DIAG_REDIRECTSTDERR) { file_size(stderr_log, stderr_file_size); stderr_file = freopen(stderr_log, "a", stderr); if (!stderr_file) { return ERR_FOPEN; } setbuf(stderr_file, 0); } if (flags & BOINC_DIAG_REDIRECTSTDERROVERWRITE) { stderr_file = freopen(stderr_log, "w", stderr); if (!stderr_file) { return ERR_FOPEN; } setbuf(stderr_file, 0); } if (flags & BOINC_DIAG_REDIRECTSTDOUT) { file_size(stdout_log, stdout_file_size); stdout_file = freopen(stdout_log, "a", stdout); if (!stdout_file) { return ERR_FOPEN; } } if (flags & BOINC_DIAG_REDIRECTSTDOUTOVERWRITE) { stdout_file = freopen(stdout_log, "w", stdout); if (!stdout_file) { return ERR_FOPEN; } } #if defined(_WIN32) #if defined(_DEBUG) _CrtSetReportHook(boinc_message_reporting); if (flags & BOINC_DIAG_MEMORYLEAKCHECKENABLED) { SET_CRT_DEBUG_FIELD(_CRTDBG_LEAK_CHECK_DF); } if (flags & BOINC_DIAG_HEAPCHECKENABLED) { if (flags & BOINC_DIAG_HEAPCHECKEVERYALLOC) { SET_CRT_DEBUG_FIELD(_CRTDBG_CHECK_ALWAYS_DF); } else { SET_CRT_DEBUG_FIELD(_CRTDBG_CHECK_EVERY_1024_DF); } } if (flags & BOINC_DIAG_BOINCAPPLICATION) { if (flags & BOINC_DIAG_MEMORYLEAKCHECKENABLED) { _CrtMemCheckpoint(&start_snapshot); } } #endif // defined(_DEBUG) // Initialize the thread list structure // The data for this structure should be set by // boinc_init or boinc_init_graphics. diagnostics_init_thread_list(); diagnostics_init_unhandled_exception_monitor(); diagnostics_init_message_monitor(); #endif // defined(_WIN32) // Install unhandled exception filters and signal traps. if (BOINC_SUCCESS != boinc_install_signal_handlers()) { return ERR_SIGNAL_OP; } // Store various pieces of inforation for future use. if (flags & BOINC_DIAG_BOINCAPPLICATION) { char buf[256]; char proxy_address[256]; int proxy_port; MIOFILE mf; FILE* p; #ifdef _WIN32 LONG lReturnValue; HKEY hkSetupHive; DWORD dwSize = 0; #endif strcpy(buf, ""); strcpy(proxy_address, ""); proxy_port = 0; #ifndef _USING_FCGI_ p = fopen(INIT_DATA_FILE, "r"); #else p = FCGI::fopen(INIT_DATA_FILE, "r"); #endif if (p) { mf.init_file(p); while(mf.fgets(buf, sizeof(buf))) { if (match_tag(buf, "</app_init_data>")) break; else if (parse_str(buf, "<boinc_dir>", boinc_dir, 256)) continue; else if (parse_str(buf, "<symstore>", symstore, 256)) continue; else if (match_tag(buf, "<use_http_proxy/>")) { boinc_proxy_enabled = true; continue; } else if (parse_str(buf, "<http_server_name>", proxy_address, 256)) continue; else if (parse_int(buf, "<http_server_port>", proxy_port)) continue; } fclose(p); } if (boinc_proxy_enabled) { int buffer_used = snprintf(boinc_proxy, sizeof(boinc_proxy), "%s:%d", proxy_address, proxy_port); if ((sizeof(boinc_proxy) == buffer_used) || (-1 == buffer_used)) { boinc_proxy[sizeof(boinc_proxy)-1] = '\0'; } } #ifdef _WIN32 // Lookup the location of where BOINC was installed to and store // that for future use. lReturnValue = RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Space Sciences Laboratory, U.C. Berkeley\\BOINC Setup"), 0, KEY_READ, &hkSetupHive ); if (lReturnValue == ERROR_SUCCESS) { // How large does our buffer need to be? dwSize = sizeof(boinc_install_dir); lReturnValue = RegQueryValueEx( hkSetupHive, _T("INSTALLDIR"), NULL, NULL, (LPBYTE)&boinc_install_dir, &dwSize ); } if (hkSetupHive) RegCloseKey(hkSetupHive); #endif } return BOINC_SUCCESS; }
int main(int argc, char* argv[]) { const int NUM_OBJECTS = 40; // Number of objects in test set, must be > FRAC_OBJECTS for this test const int FRAC_OBJECTS = 4; const float MAX_WORLDSIZE = 10.0f; const float FRAC_WORLDSIZE = MAX_WORLDSIZE / 2; // typedef the RTree useage just for conveniance with iteration typedef RTree<SomeThing*, float, 3> SomeThingTree; ASSERT( NUM_OBJECTS > FRAC_OBJECTS ); int index; // general purpose counter, declared here because MSVC 6 is not ansi compliant with 'for' loops. SomeThing* thingArray[NUM_OBJECTS * 2]; // Store objects in another container to test with, sized larger than we need memset(thingArray, 0, sizeof(thingArray)); // Nullify array, size is known here // Create intance of RTree SomeThingTree tree; // Add some nodes int counter = 0; for( index = 0; index < NUM_OBJECTS; ++index ) { SomeThing* newThing = new SomeThing; newThing->m_creationCounter = counter++; newThing->m_min = Vec3(RandFloat(-MAX_WORLDSIZE, MAX_WORLDSIZE), RandFloat(-MAX_WORLDSIZE, MAX_WORLDSIZE), RandFloat(-MAX_WORLDSIZE, MAX_WORLDSIZE)); Vec3 extent = Vec3(RandFloat(0, FRAC_WORLDSIZE), RandFloat(0, FRAC_WORLDSIZE), RandFloat(0, FRAC_WORLDSIZE)); newThing->m_max = newThing->m_min + extent; thingArray[counter-1] = newThing; tree.Insert(newThing->m_min.v, newThing->m_max.v, newThing); printf("inserting %d\n", newThing->m_creationCounter); } printf("tree count = %d\n", tree.Count()); int numToDelete = NUM_OBJECTS / FRAC_OBJECTS; int numToStep = FRAC_OBJECTS; // Delete some nodes for( index = 0; index < NUM_OBJECTS; index += numToStep ) { SomeThing* curThing = thingArray[index]; if(curThing) { tree.Remove(curThing->m_min.v, curThing->m_max.v, curThing); printf("removing %d\n", curThing->m_creationCounter); delete curThing; thingArray[index] = NULL; } } printf("tree count = %d\n", tree.Count()); // Add some more nodes for( index = 0; index < numToDelete; ++index ) { SomeThing* newThing = new SomeThing; newThing->m_creationCounter = counter++; newThing->m_min = Vec3(RandFloat(-MAX_WORLDSIZE, MAX_WORLDSIZE), RandFloat(-MAX_WORLDSIZE, MAX_WORLDSIZE), RandFloat(-MAX_WORLDSIZE, MAX_WORLDSIZE)); Vec3 extent = Vec3(RandFloat(0, FRAC_WORLDSIZE), RandFloat(0, FRAC_WORLDSIZE), RandFloat(0, FRAC_WORLDSIZE)); newThing->m_max = newThing->m_min + extent; thingArray[counter-1] = newThing; tree.Insert(newThing->m_min.v, newThing->m_max.v, newThing); printf("inserting %d\n", newThing->m_creationCounter); } printf("tree count = %d\n", tree.Count()); Vec3 searchMin(0,0,0); Vec3 searchMax(FRAC_WORLDSIZE, FRAC_WORLDSIZE, FRAC_WORLDSIZE); tree.Search(searchMin.v, searchMax.v, &QueryResultCallback, NULL); // NOTE: Even better than just dumping text, it would be nice to render the // tree contents and search result for visualization. // List values. Iterator is NOT delete safe SomeThingTree::Iterator it; for( tree.GetFirst(it); !tree.IsNull(it); tree.GetNext(it) ) { SomeThing* curThing = tree.GetAt(it); if(BoxesIntersect(searchMin, searchMax, curThing->m_min, curThing->m_max)) { printf("brute found %d\n", curThing->m_creationCounter); } } // Delete our nodes, NOTE, we are NOT deleting the tree nodes, just our data // of course the tree will now contain invalid pointers that must not be used any more. for( tree.GetFirst(it); !tree.IsNull(it); tree.GetNext(it) ) { SomeThing* removeElem = tree.GetAt(it); if(removeElem) { printf("deleting %d\n", removeElem->m_creationCounter); delete removeElem; } } // Remove all contents (This would have happened automatically during destructor) tree.RemoveAll(); if(SomeThing::s_outstandingAllocs > 0) { printf("Memory leak!\n"); printf("s_outstandingAllocs = %d\n", SomeThing::s_outstandingAllocs); } else { printf("No memory leaks detected by app\n"); } // Wait for keypress on exit so we can read console output getchar(); #ifdef WIN32 // Use CRT Debug facility to dump memory leaks on app exit SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF ); #endif //WIN32 return 0; }
int main(int argc, char **argv) { #ifdef WIN32 // Send all reports to STDOUT _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT ); _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT ); _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT ); // enable the options SET_CRT_DEBUG_FIELD( _CRTDBG_DELAY_FREE_MEM_DF ); SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF ); #endif printf("int %d, short int %d, char %d, double %d, float %d, node %d\n",sizeof(int),sizeof(short int), sizeof(char), sizeof(double), sizeof(float), sizeof(svm_node)); char input_file_name[FILENAME_LEN]; char model_file_name[FILENAME_LEN]; const char *error_msg; parse_command_line(argc, argv, input_file_name, model_file_name); read_problem(input_file_name); param.modelFile = model_file_name; printf ("Finish reading input files!\n"); error_msg = svm_check_parameter(&prob,¶m); #ifdef WIN32 assert(_CrtCheckMemory()); #endif if(error_msg) { fprintf(stderr,"Error: %s\n",error_msg); exit(1); } double duration; double start = getRunTime(); if(cross_validation) { do_cross_validation(); } else { printf("kernel: %d\n",param.kernel_type); model = svm_train(&prob,¶m); double finish = getRunTime(); duration = (double)(finish - start); #ifdef WIN32 assert(_CrtCheckMemory()); #endif svm_save_model(model_file_name,model); svm_destroy_model(model); } printf("CPU Time = %f second\n", duration); FILE* fModel = fopen(model_file_name, "a+t"); // append mode fprintf(fModel, "CPU Time = %f second\n", duration); fclose(fModel); svm_destroy_param(¶m); free(prob.y); free(prob.x); free(x_space); #ifdef WIN32 assert(_CrtCheckMemory()); #endif return 0; }
void main() { TestMXML(); SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF ); }