Esempio n. 1
0
oexINT CLog::Log( oexCSTR x_pFile, oexINT x_nLine, oexCSTR8 x_pFunction, oexINT x_uLevel, oexCSTR x_pErr, oexINT x_nErr, oexUINT x_uSkip )
{_STT();
	// Ensure valid reporting level
	if ( x_uLevel < m_uLevel )
		return x_nErr;

	// Log count
	if ( 1 == oexIncrement( &m_lInLog ) )
	{
		_oexTRY
		{
			// Create log file if needed
			if ( !m_file.IsOpen() )
				if ( !OpenLogFile() )
				{	oexDecrement( &m_lInLog );
					return x_nErr;
				} // end if

			if ( !oexCHECK_PTR( x_pFile ) )
				x_pFile = oexT( "???" );

			if ( !oexCHECK_PTR( x_pFunction ) )
				x_pFunction = "???";

			CStr sLevel;
			oexCSTR pLevel = oexT( "" );
			if ( eHalt == x_uLevel )
				pLevel = oexT( "Halt" );
			else if ( eError == x_uLevel )
				pLevel = oexT( "Error" );
			else if ( eWarning == x_uLevel )
				pLevel = oexT( "Warning" );
			else if ( eNotice == x_uLevel )
				pLevel = oexT( "Notice" );
			else
				pLevel = sLevel.Mks( (int)x_uLevel ).Ptr();

			CStr sLog;

			// Add file / line number
			oexUINT uThreadId = oexGetCurThreadId();
#if defined( oexFULL_FILENAME_IN_LOG )
			sLog << x_pFile << oexT( ":(" ) << x_nLine << oexT( ")" )
#else
			sLog << oexGetFileName( x_pFile ) << oexT( ":(" ) << x_nLine << oexT( ")" )
#endif
				 << oexFmt( oexT( " : Thread %u (0x%x)" ), uThreadId, uThreadId ) << oexNL;

			// Write out the time
#if defined( OEX_NANOSECONDS )
			sLog << oexLocalTimeStr( oexT( " -> Local: %Y/%c/%d - %g:%m:%s.%l.%u.%n" oexNL8 ) );
#else
			sLog << oexLocalTimeStr( oexT( " -> Local Time  : %Y/%c/%d - %g:%m:%s.%l.%u" oexNL8 ) );
#endif

#if defined( OEXLIB_STACK_TRACING )
			CStackTrace::CStack *p = oexSt().GetStack();
			if ( p )
			{
				sLog << oexT(         " -> Thread Name : " ) << p->GetName() << oexNL;
			
				// +++ This really doesn't make a lot of sense in the log file, more for stack tracing
//				sLog << oexT(         " -> Tag         : " ) << p->GetTag() << oexNL;
//				sLog << oexFmt( oexT( " -> CheckPoint  : %d (0x%x)" oexNL8 ), p->GetCheckpoint(), p->GetCheckpoint() );

			} // end if
#endif
			// Add function name if available
			if ( x_pFunction && *x_pFunction )
				sLog << oexT(         " -> Function    : " ) << oexMbToStrPtr( x_pFunction ) << oexT( "()" oexNL8 );

			// Add error level
			sLog << oexT(             " -> Level       : " ) << pLevel;

			// Add system error info
			if ( x_nErr )
				sLog << CStr().Print( oexT( " : 0x%X (%d) : " ), x_nErr, x_nErr )
					 << os::CTrace::GetErrorMsg( x_nErr ).RTrim( oexT( "\r\n" ) );

			sLog << oexNL;

			// Write out the user error string if available
			if ( oexCHECK_PTR( x_pErr ) )
				sLog << oexT( " -> " oexNL8 " -> " ) << CStr( x_pErr ).Replace( oexNL, oexT( "" oexNL8 " -> " ) ) << oexNL;

#if defined( oexBACKTRACE_IN_LOG )
			// Write out the backtrace
			sLog << oexT( " -> " )
				 << os::CTrace::GetBacktrace( x_uSkip ).Replace( oexNL, oexT( "" oexNL8 " -> " ) )
				 << oexNL;
#endif

			// Just to space things out
			sLog << oexNL;

			// Write out the string to the file
			m_file.Write( oexStrToMb( sLog ) );

#if defined( oexPRINT_LOGS )

		// Print if user wants to see this level
		if ( oexPRINT_LOGS <= x_uLevel )
			oexEcho( sLog.Ptr() );
#endif

		}
		_oexCATCH_ALL()
		{
		} // end catch

	} // end if
Esempio n. 2
0
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPreviousInst, LPSTR lpCmdLine, int nCmdShow) {
  WNDCLASS wndClass;

  wndClass.style = CS_HREDRAW | CS_VREDRAW;
  wndClass.lpfnWndProc = WndProc;
  wndClass.cbClsExtra = 0;
  wndClass.cbWndExtra = 0;
  wndClass.hInstance = hInstance;
  wndClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));
  wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  wndClass.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
  wndClass.lpszMenuName = NULL;
  wndClass.lpszClassName = "FOnline";

  if (!RegisterClass(&wndClass)) {
    char* msg = FormatLastWin32Error();
    ReportErrorMessage("Win32 error.", "Could not register window class: %s", msg);
    free(msg);
    return -1;
  }

  if (!OpenLogFile("FOnlineClient.log")) {
    ReportErrorMessage("IO error.", "Could not open log file.");
    return -1;
  }

  LoadSettings();

  size_t modeWidth = screen_width[opt_screen_mode];
  size_t modeHeight = screen_height[opt_screen_mode];

  HWND hWnd = CreateWindow(
    "FOnline",
    "Fallout Online",
    WS_OVERLAPPEDWINDOW & (~WS_MAXIMIZEBOX) & (~WS_SIZEBOX) & (~WS_SYSMENU),
    0,0,modeWidth + 5, modeHeight + 25,
    NULL,
    NULL,
    hInstance,
    NULL
  );

  if (hWnd == NULL) {
    char* msg = FormatLastWin32Error();
    ReportErrorMessage("Win32 error.", "Could not create window: %s", msg);
    free(msg);
    return -1;
  }

  ShowWindow(hWnd, SW_SHOWNORMAL);
  UpdateWindow(hWnd);

  FONLINE_LOG("Starting FOnline...\n");

  srand(GetTickCount());

  engine = new FOnlineEngine;

  if (!engine->Init(hWnd)) {
    FONLINE_LOG("Could not initialize the engine.\n");
    DestroyWindow(hWnd);
    return 0;
  }

  MSG msg;
  while(!cmn_Quit) {
    if(!cmn_lost) {
      if(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      } else {
        engine->Render();

        if (opt_sleep) Sleep(opt_sleep);
      }
    } else {
      GetMessage(&msg, NULL, NULL, NULL);
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }
  }
  FONLINE_LOG("\nFOnline Closed\n");
  CloseLogFile();

  delete engine;

  //SimpleLeakDetector::PrintAllLeaks();

  _CrtDumpMemoryLeaks();
  return 0;
}
void Chapter1Test::Test1_7() {
  ofstream fout;
  OpenLogFile(fout,"test1_7.html","Problem 1.7: compress a string by counting consecutive chars");


  vector<vector<int> > matrix, expected;
  stringstream input;

  tools.GenerateNewMatrix(matrix, {0}, 0, 0);
  tools.GenerateNewMatrix(expected, {0}, 0, 0);
  input.str("");
  tools.PrintMatrix2File(matrix, input);
  sol.prob1_7(matrix);
  TestMatrix(fout, input.str(), matrix, expected);

  tools.GenerateNewMatrix(matrix, {1}, 1, 1);
  tools.GenerateNewMatrix(expected, {1}, 1, 1);
  input.str("");
  tools.PrintMatrix2File(matrix, input);
  sol.prob1_7(matrix);
  TestMatrix(fout, input.str(), matrix, expected);

  tools.GenerateNewMatrix(matrix, {1,2,3,4,0,6,7}, 7, 1);
  tools.GenerateNewMatrix(expected, {0,0,0,0,0,0,0}, 7, 1);
  input.str("");
  tools.PrintMatrix2File(matrix, input);
  sol.prob1_7(matrix);
  TestMatrix(fout, input.str(), matrix, expected);

  tools.GenerateNewMatrix(matrix, {1,2,3,4,0,6,7}, 1, 7);
  tools.GenerateNewMatrix(expected, {0,0,0,0,0,0,0}, 1, 7);
  input.str("");
  tools.PrintMatrix2File(matrix, input);
  sol.prob1_7(matrix);
  TestMatrix(fout, input.str(), matrix, expected);

  tools.GenerateNewMatrix(matrix, {1,2,3,4}, 2, 2);
  tools.GenerateNewMatrix(expected, {1,2,3,4}, 2, 2);
  input.str("");
  tools.PrintMatrix2File(matrix, input);
  sol.prob1_7(matrix);
  TestMatrix(fout, input.str(), matrix, expected);

  tools.GenerateNewMatrix(matrix, {1,2,3,0}, 2, 2);
  tools.GenerateNewMatrix(expected, {1,0,0,0}, 2, 2);
  input.str("");
  tools.PrintMatrix2File(matrix, input);
  sol.prob1_7(matrix);
  TestMatrix(fout, input.str(), matrix, expected);

  tools.GenerateNewMatrix(matrix, {0,0,0,0,0,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25}, 5, 5);
  tools.GenerateNewMatrix(expected, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 5, 5);
  input.str("");
  tools.PrintMatrix2File(matrix, input);
  sol.prob1_7(matrix);
  TestMatrix(fout, input.str(), matrix, expected);

  tools.GenerateNewMatrix(matrix, {0,2,3,4,5,6,7,8,0,10,0,0,13,14,15,16,0,18,19,0,21,22,23,24,25}, 5, 5);
  tools.GenerateNewMatrix(expected, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,23,0,0}, 5, 5);
  input.str("");
  tools.PrintMatrix2File(matrix, input);
  sol.prob1_7(matrix);
  TestMatrix(fout, input.str(), matrix, expected);

  CloseLogFile(fout);
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
	int opt;
	struct option longopts[] = {
			{"help", 0, NULL, 'h'},
			{"version", 0, NULL, 'v'},
			{"about", 0, NULL, 'a'},
			{"error", 1, NULL, 'e'},
			{"log", 1, NULL, 'l'},
			{"output", 1, NULL, 'o'},
			{"test0", 1, NULL, '0'},
			{"test1", 1, NULL, '1'},
			{"test2", 1, NULL, '2'},
			{"test3", 1, NULL, '3'},
			{"test4", 1, NULL, '4'},
			{0, 0, 0, 0}
    };
	simulator_ *simulator = NULL;
	char *outFileName = NULL;
	FILE *outFile = stdout;
	double R, dc, Z0, Td, loss;
	double *data;
	char **variables;
	int numPoints, numVariables, i;
	double pulseD[7] = { 0, 10, 10e-9, 2e-9, 3e-9, 5e-9, 20e-9 };
	double *pulse[7] = { &pulseD[0], &pulseD[1], &pulseD[2], &pulseD[3],
			&pulseD[4], &pulseD[5], &pulseD[6] };
	double gaussD[7] = { 0, 3.3, 2e-9, 1e-9, 0.5e-9, 5e-9, 12e-9 };
	double *gauss[7] = { &gaussD[0], &gaussD[1], &gaussD[2], &gaussD[3],
			&gaussD[4], &gaussD[5], &gaussD[6] };

	/* Process the command line options */
	while((opt = getopt_long(argc,argv,"hvae:l:01234o:",longopts,NULL)) != -1) {
		switch(opt) {
		case '0':
			/* Create a new simulator object */
			simulator = simulatorNew(simulator);
			ExitFailureIf(simulator == NULL);

			R = 10;
			dc = 10;
			ExitFailureIf(simulatorAddResistor(simulator, "R1", "n1", "0", &R));
			ExitFailureIf(simulatorAddSource(simulator, "V1", "n1", "0",'v',
					&dc, 0x0, NULL));
			ExitFailureIf(simulatorRunOperatingPoint(simulator,
					&data, &variables, &numPoints, &numVariables));

			print(outFile, data, variables, numVariables);

			/* Destroy the Scripter Object */
			if(simulatorDestroy(&simulator)) {
				Warn("Failed to close simulator");
			}
			free(data);
			free(variables);
			break;
		case '1':
			/* Create a new simulator object */
			simulator = simulatorNew(simulator);
			ExitFailureIf(simulator == NULL);

			R = 10; Z0 = 50; Td = 15e-9; loss = 0.2;
			ExitFailureIf(simulatorAddResistor(simulator, "R1", "n1", "n2", &R));
			ExitFailureIf(simulatorAddSource(simulator, "V1", "n1", "0",'v',
					NULL, 'p', pulse));
			ExitFailureIf(simulatorAddTLine(simulator, "T2", "n2", "0", "n3",
					"0", &Z0, &Td, &loss));
			ExitFailureIf(simulatorRunTransient(simulator,
					0.1e-9, 50e-9, 0.0, 0,
					&data, &variables, &numPoints, &numVariables));

			plot(outFile, data, variables, numPoints, numVariables);

			/* Destroy the Scripter Object */
			if(simulatorDestroy(&simulator)) {
				Warn("Failed to close simulator");
			}
			free(data);
			free(variables);
			break;
		case '2':
			/* Create a new simulator object */
			simulator = simulatorNew(simulator);
			ExitFailureIf(simulator == NULL);

			R = 10; Z0 = 50; Td = 15e-9; loss = 0.2;
			ExitFailureIf(simulatorAddResistor(simulator, "R1", "n1", "n2", &R));
			ExitFailureIf(simulatorAddSource(simulator, "V1", "n1", "0",'v',
					NULL, 'p', pulse));
			ExitFailureIf(simulatorAddTLine(simulator, "T2", "n2", "0", "n3",
					"0", &Z0, &Td, &loss));
			for(i = 0; i < 100; i++) {
				ExitFailureIf(simulatorRunTransient(simulator,
					0.1e-9, 50e-9, 0.0, 0,
					&data, &variables, &numPoints, &numVariables));
			}

			//plot(outFile, data, variables, numPoints, numVariables);

			/* Destroy the Scripter Object */
			if(simulatorDestroy(&simulator)) {
				Warn("Failed to close simulator");
			}
			free(data);
			free(variables);
			break;
		case '3':
			/* Create a new simulator object */
			simulator = simulatorNew(simulator);
			ExitFailureIf(simulator == NULL);

			double L0[4] = {231.832e-9, 38.1483e-9, 38.1483e-9, 231.819e-9};
			double *L0p = L0;
			double C0[4] = {156.163e-12, -8.60102e-12,-8.60102e-12, 156.193e-12};
			double *C0p = C0;
			double R0[4] = {0.861113, 0, 0, 0.861113};
			double *R0p = R0;
			double G0[4] = {0,0,0,0};
			double *G0p = G0;
			double Rs[4] = {0.368757e-3, 0,0, 0.368757e-3};
			double *Rsp = Rs;
			double Gd[4] = {0,0,0,0};
			double *Gdp = Gd;
			char *nodes[6] = {"1", "3", "0", "2", "4", "0"};
			int M = 9;
			double len = 0.0265;
			double fgd = 1e100;
			double fK = 1e9;

			ExitFailureIf(simulatorAddResistor(simulator, "R1", "n1", "n2", &R));
			ExitFailureIf(simulatorAddSource(simulator, "V1", "n1", "0",'v',
					NULL, 'p', pulse));
			ExitFailureIf(simulatorAddTLineW(simulator,
					"T1", nodes, 6, &M, &len, &L0p, &C0p, &R0p, &G0p, &Rsp,
					&Gdp, &fgd, &fK));

			/* Destroy the Scripter Object */
			if(simulatorDestroy(&simulator)) {
				Warn("Failed to close simulator");
			}
			//free(data);
			//free(variables);
			break;
		case '4':
			/* Create a new simulator object */
			simulator = simulatorNew(simulator);
			ExitFailureIf(simulator == NULL);

			ExitFailureIf(simulatorAddSource(simulator, "V1", "n1", "0",'v',
					NULL, 'g', gauss));
			ExitFailureIf(simulatorRunTransient(simulator,
					0.01e-9, 50e-9, 0.0, 0,
					&data, &variables, &numPoints, &numVariables));

			plot(outFile, data, variables, numPoints, numVariables);

			/* Destroy the Scripter Object */
			if(simulatorDestroy(&simulator)) {
				Warn("Failed to close simulator");
			}
			free(data);
			free(variables);
			break;
		case 'a':
		case 'v': version(); ExitSuccess;
		case 'o':
			outFileName = optarg;
			outFile = fopen(outFileName, "wb");
			ExitFailureIf(outFile == NULL, "Failed to open %s for output",
					outFileName);
			break;
		case 'e': OpenErrorFile(optarg); break;
		case 'l': OpenLogFile(optarg); break;
		case 'h': help(); ExitSuccess;
		case '?': ExitFailure("Unkown option");
		case ':': ExitFailure("Option needs a value");
		default:  help(); ExitFailure("Invalid option");
		}
	}


	if(outFileName != NULL) {
		fclose(outFile);
	}

	CloseErrorFile;
	CloseLogFile;
	ExitSuccess;
}