Example #1
0
static sc_status
OpenLogFile(
	sc_logging_info_t* log, 
	const char* filename)
{
	static const char *replace = "w";
	static const char *append = "a+";
	const char *mode;
	
	if (log && log->stream)
		CloseLogFile(log);
	
	if (filename == NULL)
		filename = SC_DEFAULT_LOG_FILENAME;

	size_t length = strlen(filename) + 1;
	log->filename = scAllocate(log->session, length * sizeof(char));
	snprintf(log->filename, length, "%s", filename);
	
	mode = (log->flags & SC_LOG_APPEND) ? append : replace;
	log->stream = fopen(log->filename, mode);
	if (log->stream == NULL)
	{
		CloseLogFile(log);
		return SC_INVALID_LOG_FILE;
	}
	return SC_SUCCESS;
}
Example #2
0
/* 编译从这开始 */
int main (int argc, char **argv)
{
    int i;

	//share_fs ();

    CurrentHeap = &ProgramHeap;
    argc--; argv++;

#if defined(_LF)
    init_file_layout ();
    init_memory_layout ();
#endif
    CreateLogFile ();

#if 1
    i = ParseCommandLine (argc, argv);
    
    /* 初始化词法分析器 */
    SetupLexer ();
    /* 按照配置文件设置基本类型和默认函数的属性 */
    SetupTypeSystem ();

    for ( ; i < argc; i++ ) {
    
        Compile (argv[i]);
    }
#endif
    CloseLogFile ();
    return (ErrorCount != 0 ? -1 : 0);
}
Example #3
0
//-----------------------------------------------------------------------------
CmWebLog::~CmWebLog(void) {
	pthread_mutex_lock(&WebLog_mutex); // yea, its mine
	--RefCounter;
	if (RefCounter <= 0)
		CloseLogFile();
	pthread_mutex_unlock(&WebLog_mutex);
}
Example #4
0
HRESULT CTaksiLogFile::OpenLogFile( const TCHAR* pszFileName )
{
	CloseLogFile();
	if ( ! sg_Config.m_bDebugLog)
	{
		return HRESULT_FROM_WIN32(ERROR_CANCELLED);
	}

	m_File.AttachHandle( ::CreateFile( pszFileName,            // file to create 
		GENERIC_WRITE,                // open for writing 
		0,                            // do not share 
		NULL,                         // default security 
		OPEN_ALWAYS,                  // append existing else create
		FILE_ATTRIBUTE_NORMAL,        // normal file 
		NULL ));                        // no attr. template 
	if ( ! m_File.IsValidHandle())
	{
		HRESULT hRes = HRes_GetLastErrorDef( HRESULT_FROM_WIN32(ERROR_CANNOT_MAKE));
		return hRes;
	}

	// Append to the end of the file if it exists
	if ( GetLastError() == ERROR_ALREADY_EXISTS )
	{
		SetFilePointer( (HANDLE)m_File, GetFileSize((HANDLE)m_File, NULL), NULL, FILE_BEGIN );
	}

	return S_OK;
}
Example #5
0
//---------------------------------------------------------------------------
void TActionLog::ReflectSettings()
{
  TGuard Guard(FCriticalSection);

  bool ALogging =
    !FClosed && FConfiguration->GetLogActions() && GetEnabled();

  if (ALogging && !FLogging)
  {
    FLogging = true;
    Add(L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    Add(FORMAT(L"<session xmlns=\"http://winscp.net/schema/session/1.0\" name=\"%s\" start=\"%s\">",
      XmlAttributeEscape(FSessionData->GetSessionName()).c_str(), StandardTimestamp().c_str()));
  }
  else if (!ALogging && FLogging)
  {
    if (FInGroup)
    {
      EndGroup();
    }
    // do not try to close the file, if it has not been opened, to avoid recursion
    if (FFile != nullptr)
    {
      Add(L"</session>");
    }
    CloseLogFile();
    FLogging = false;
  }

}
void Chapter1Test::Test1_8() {
  ofstream fout;
  OpenLogFile(fout,"test1_8.html","Problem 1.8: check if s2 is the rotation of s1");


  bool expected(true);
  TestBasic(fout, "", sol.prob1_8("", ""), expected);

  expected = true;
  TestBasic(fout, "abcde, cdeab", sol.prob1_8("abcde", "cdeab"), expected);

  expected = true;
  TestBasic(fout, "abcde, abcde", sol.prob1_8("abcde", "abcde"), expected);

  expected = true;
  TestBasic(fout, "abcdef, cdefab", sol.prob1_8("abcdef", "cdefab"), expected);

  expected = false;
  TestBasic(fout, "abcde, cdaeb", sol.prob1_8("abcde", "cdaeb"), expected);

  expected = false;
  TestBasic(fout, "abcde, abcdef", sol.prob1_8("abcde", "abcdef"), expected);

  CloseLogFile(fout);
}
void Chapter1Test::Test1_2() {
  ofstream fout;
  OpenLogFile(fout,"test1_2.html","Problem 1.2: check if a string has all unique chars");


  char *output(nullptr);
  tools.new_c_str(output, "abcdef");
  char *expected(nullptr);
  tools.new_c_str(expected, "fedcba");
  sol.prob1_2(output);
  TestStaticArray(fout, "abcdef", output, expected,strlen(output), strlen(expected));
  delete []output;
  delete []expected;

  tools.new_c_str(output, "abcde");
  tools.new_c_str(expected, "edcba");
  sol.prob1_2(output);
  TestStaticArray(fout, "abcde", output, expected,strlen(output), strlen(expected));
  delete []output;
  delete []expected;

  tools.new_c_str(output, "");
  tools.new_c_str(expected, "");
  sol.prob1_2(output);
  TestStaticArray(fout, "", output, expected,strlen(output), strlen(expected));
  delete []output;
  delete []expected;

  CloseLogFile(fout);
}
Example #8
0
void CNtlLogSystem::RefreshLogFileFullName()
{
	sSOURCE_INFO* pSourceInfo = NULL;
	sLOG_FILE_INFO* pLogFileInfo = NULL;

	std::map<DWORD, sSOURCE_INFO*>::iterator iterSource;
	for (iterSource = m_mapSource.begin() ; m_mapSource.end() != iterSource ; iterSource++)
	{
		pSourceInfo = iterSource->second;

		if (NULL != pSourceInfo)
		{
			std::map<CNtlString, sLOG_FILE_INFO*>::iterator iterLogFile;
			for (iterLogFile = (pSourceInfo->mapLoggingFileInfo).begin() ; (pSourceInfo->mapLoggingFileInfo).end() != iterLogFile ; iterLogFile++)
			{
				pLogFileInfo = iterLogFile->second;

				if (NULL != pLogFileInfo)
				{
					::EnterCriticalSection(&(pLogFileInfo->lock));

					CloseLogFile(pLogFileInfo);
					OpenLogFile(pLogFileInfo);

					::LeaveCriticalSection(&(pLogFileInfo->lock));
				}
			}
		}
	}
}
void Chapter9Test::Test9_5() {
  ofstream fout;
  OpenLogFile(fout, "test9_5.html", "Problem 9.5: return all permutation of a string");

  vector<string> ret;
  string input;
  // 1.
  ret.clear();
  input = "abc";
  ret = sol.prob9_5(input);
  TestDynamicArray(fout, input, ret, {"bca","acb","bac","abc","cab","cba"});
  // 2.
  ret.clear();
  input = "ab";
  ret = sol.prob9_5(input);
  TestDynamicArray(fout, input, ret, {"ab","ba"});
  // 3.
  ret.clear();
  input = "a";
  ret = sol.prob9_5(input);
  TestDynamicArray(fout, input, ret, {"a"});
  // 4.
  ret.clear();
  input = "";
  ret = sol.prob9_5(input);
  TestDynamicArray(fout, input, ret, {""});
  // 5.
  ret.clear();
  input = "abcd";
  ret = sol.prob9_5(input);
  TestDynamicArray(fout, input, ret, {"abcd","abdc","acbd","acdb","adbc","adcb","bacd","badc","bdac","bdca","bcad","bcda",\
                  "cabd","cadb","cbad","cbda","cdab","cdba","dabc","dacb","dbac","dbca","dcab","dcba"});
  CloseLogFile(fout);
}
/** Event handler for the library USB Connection event. */
void EVENT_USB_Device_Connect(void)
{
	LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);

	/* Close the log file so that the host has exclusive filesystem access */
	CloseLogFile();
}
Example #11
0
File: XT.cpp Project: robessog/OBS
//note to self:  do try not to rely on this too much.
void __cdecl CrashError(const TCHAR *format, ...)
{
    if(!format) return;

    va_list arglist;

    va_start(arglist, format);

    String strOut = FormattedStringva(format, arglist);

    OpenLogFile();
    LogFile.WriteStr(TEXT("\r\nError: "));
    LogFile.WriteAsUTF8(strOut);
    LogFile.WriteStr(TEXT("\r\n"));
    CloseLogFile();

    OSMessageBoxva(format, arglist);

#if defined(_DEBUG) && defined(_WIN32)
    if(bDebugBreak && OSDebuggerPresent())
        ProgramBreak();
#endif

    CriticalExit();
}
Example #12
0
File: XT.cpp Project: robessog/OBS
void STDCALL TraceCrashEnd()
{
    String strStackTrace = TEXT("\r\nException Fault - Stack Trace:");

    for(unsigned int i=0; i<TraceFuncList.Num(); i++)
    {
        if(i) strStackTrace << TEXT(" -> ");
        if(!(i%10)) strStackTrace << TEXT("\r\n    ");
        strStackTrace << TraceFuncList[i];
    }

    if(TraceFuncList.Num() == MAX_STACK_TRACE)
        strStackTrace << TEXT(" -> ...");

    String strOut = FormattedString(TEXT("%s\r\n"), strStackTrace.Array());

    OpenLogFile();
    LogFile.WriteAsUTF8(strOut, strOut.Length());
    LogFile.WriteAsUTF8(TEXT("\r\n"));
    CloseLogFile();

    OSMessageBox(TEXT("Error: Exception fault - More info in the log file.\r\n\r\nMake sure you're using the latest verison, otherwise send your log to [email protected]"));

    TraceFuncList.Clear();
    CriticalExit();
}
void Chapter9Test::Test9_11() {
  ofstream fout;
  OpenLogFile(fout, "test9_11.html", "Problem 9.11: print ways of parenthesizing the expression such that it evaluates to result.");

  vector<string> solution;
  // 1.
  solution = sol.prob9_11("1|1^0^1", 0);
  TestDynamicArray(fout,"1|1^0^1: 0", solution, {"(1|1)^(0^1)",	"((1)|(1^0))^(1)", "((1|1)^(0))^(1)"});
  // 2.
  solution = sol.prob9_11("1|1^0^1", 1);
  TestDynamicArray(fout,"1|1^0^1: 1", solution, {"(1)|((1)^(0^1))",	"(1)|((1^0)^(1))"});
  // 3.
  solution = sol.prob9_11("1^1", 0);
  TestDynamicArray(fout,"1^1: 0", solution, {"1^1"});
  // 4.
  solution = sol.prob9_11("1^1", 1);
  TestDynamicArray(fout,"1^1: 1", solution, {});
  // 5.
  solution = sol.prob9_11("1&1|0^1", 1);
  TestDynamicArray(fout,"1&1|1^0: 1", solution, {"(1)&((1)|(0^1))",	"(1&1)|(0^1)"});
  // 6.
  solution = sol.prob9_11("1&1|0^1", 0);
  TestDynamicArray(fout,"1&1|1^0: 0", solution, {"(1)&((1|0)^(1))",	"((1)&(1|0))^(1)",	"((1&1)|(0))^(1)"});
  // 7.
  solution = sol.prob9_11("1^0|0&1^1|0&0^1", 0);
  size_t zeros(solution.size());
  solution = sol.prob9_11("1^0|0&1^1|0&0^1", 1);
  size_t ones(solution.size());
  TestBasic(fout, "1^0|0&1^1|0&0^1", zeros+ones, 429ul);
  // 8.
  //solution = sol.prob9_11("1&1|0^1&1^0|0&1^1|0&0^1", 0);
  //TestDynamicArray(fout,"1&1|0^1&1^0|0&1^1|0&0^1: 0", solution, {});
  
  CloseLogFile(fout);
}
void Chapter2Test::Test2_1() {
  ofstream fout;
  OpenLogFile(fout,"test2_1.html","Problem 2.1: remove duplicate elements from a list");

  ListNode *head(nullptr);
  ListNode::GenerateListNode({}, 0, head);
  ListNode *expected(nullptr);
  sol.prob2_1(head);
  TestLinkedList(fout, "", head, expected);

  int A[] = {1,2,3,4};
  ListNode::GenerateListNode(A, 4, head);
  ListNode::GenerateListNode(A, 4, expected);
  sol.prob2_1(head);
  TestLinkedList(fout, "1->2->3->4#", head, expected);

  int A1[] = {1,2,2,3,1,4,5,1,2,3,4,5,3,4,5}, B1[] = {1,2,3,4,5};
  ListNode::GenerateListNode(A1, sizeof(A1)/sizeof(A1[0]), head);
  ListNode::GenerateListNode(B1, sizeof(B1)/sizeof(B1[0]), expected);
  stringstream ss;
  ListNode::PrintListNode(head, ss);
  sol.prob2_1(head);
  TestLinkedList(fout, ss.str(), head, expected);

  int A2[] = {1,1,1,1,1}, B2[] = {1};
  ListNode::GenerateListNode(A2, sizeof(A2)/sizeof(A2[0]), head);
  ListNode::GenerateListNode(B2, sizeof(B2)/sizeof(B2[0]), expected);
  ss.str("");
  ListNode::PrintListNode(head, ss);
  sol.prob2_1(head);
  TestLinkedList(fout, ss.str(), head, expected);

  CloseLogFile(fout);
}
void Chapter9Test::Test9_2() {
  ofstream fout;
  OpenLogFile(fout,"test9_2.html", "Problem 9.2: count all possible paths that makes a robot moves from (0, 0) to (X, Y)");

  Chapter9::Maze maze({{Chapter9::Maze::path, Chapter9::Maze::path},{Chapter9::Maze::path,Chapter9::Maze::path}});
  TestBasic(fout, "X = 2, Y = 2", maze.countAllPossiblePaths(), 2ul);
  TestMatrix(fout, "Print Paths", maze.findAllPossiblePaths(), maze.findAllPossiblePaths());
  ;
  maze.GenerateMaze({{0,0,0},{0,0,0},{0,0,0}});
  TestBasic(fout, "X = 3, Y = 3", maze.countAllPossiblePaths(), 6ul);
  TestMatrix(fout, "Print Paths", maze.findAllPossiblePaths(), maze.findAllPossiblePaths());

  maze.GenerateMaze({{0,0,0},{0,1,0},{0,0,0}});
  TestBasic(fout, "X = 3, Y = 3", maze.countAllPossiblePaths(), 2ul);
  TestMatrix(fout, "Print Paths", maze.findAllPossiblePaths(), maze.findAllPossiblePaths());

  maze.GenerateMaze({{0,0,0},{0,0,1},{0,0,0}});
  TestBasic(fout, "X = 3, Y = 3", maze.countAllPossiblePaths(), 3ul);
  TestMatrix(fout, "Print Paths", maze.findAllPossiblePaths(), maze.findAllPossiblePaths());

  maze.GenerateMaze({{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}});
  TestBasic(fout, "X = 3, Y = 3", maze.countAllPossiblePaths(), 20ul);
  TestMatrix(fout, "Print Paths", maze.findAllPossiblePaths(), maze.findAllPossiblePaths());

  maze.GenerateMaze({{0,0,0,0},{0,0,0,1},{0,0,0,0},{0,0,0,0}});
  TestBasic(fout, "X = 3, Y = 3", maze.countAllPossiblePaths(), 16ul);
  TestMatrix(fout, "Print Paths", maze.findAllPossiblePaths(), maze.findAllPossiblePaths());

  CloseLogFile(fout);
}
void Chapter9Test::Test9_10() {
  ofstream fout;
  OpenLogFile(fout, "test9_10.html", "Problem 9.10: implement a method to build the tallest stack");

  vector<size_t> solution;
  double maxHeight(0.0);
  // 1.
  solution.clear();
  maxHeight = sol.prob9_10({3.0,2.0,1.0}, {3.0,2.0,1.0}, {3.0,2.0,1.0}, solution);
  TestDouble(fout, "widths: {3,2,1}, heigths: {3,2,1}, depths: {3,2,1}", maxHeight, 6.0);
  TestDynamicArray(fout, "widths: {3,2,1}, heigths: {3,2,1}, depths: {3,2,1}", solution, {0,1,2});
  // 2.
  solution.clear();
  maxHeight = sol.prob9_10({1.0,3.0,4.0,1.0,7.0,8.0,3.0,3.0,2.0,1.0}, \
  {5.0,2.0,3.0,1.0,8.0,12.0,2.0,3.0,2.0,1.0},\
  {4.0,2.0,6.0,4.0,4.0,12.0,6.0,3.0,2.0,1.0}, solution);
  TestDouble(fout, "widths: {1.0,3.0,4.0,1.0,7.0,8.0,3.0,3.0,2.0,1.0}, heigths: {5.0,2.0,3.0,1.0,8.0,12.0,2.0,3.0,2.0,1.0}, depths: {4.0,2.0,6.0,4.0,4.0,12.0,6.0,3.0,2.0,1.0}", maxHeight, 26.0);
  TestDynamicArray(fout, "widths: {1.0,3.0,4.0,1.0,7.0,8.0,3.0,3.0,2.0,1.0}, heigths: {5.0,2.0,3.0,1.0,8.0,12.0,2.0,3.0,2.0,1.0}, depths: {4.0,2.0,6.0,4.0,4.0,12.0,6.0,3.0,2.0,1.0}", solution, {5,4,7,8,9});
  // 3.
  solution.clear();
  maxHeight = sol.prob9_10({1.0,3.0,4.0,1.0,7.0,8.0,3.0,3.0,2.0,1.0}, \
                           {5.0,2.0,3.0,1.0,8.0,7.0,2.0,3.0,2.0,1.0},\
                           {4.0,2.0,6.0,4.0,4.0,12.0,6.0,3.0,2.0,1.0}, solution);
  TestDouble(fout, "widths: {1.0,3.0,4.0,1.0,7.0,8.0,3.0,3.0,2.0,1.0}, heigths: {5.0,2.0,3.0,1.0,8.0,7.0,2.0,3.0,2.0,1.0}, depths: {4.0,2.0,6.0,4.0,4.0,12.0,6.0,3.0,2.0,1.0}", maxHeight, 14.0);
  TestDynamicArray(fout, "widths: {1.0,3.0,4.0,1.0,7.0,8.0,3.0,3.0,2.0,1.0}, heigths: {5.0,2.0,3.0,1.0,8.0,7.0,2.0,3.0,2.0,1.0}, depths: {4.0,2.0,6.0,4.0,4.0,12.0,6.0,3.0,2.0,1.0}", solution, {4,7,8,9});

  CloseLogFile(fout);
}
Example #17
0
void ExitLogger(void)
{
  /* Trace */
  RL_PRINT("Closing debug log file\n");

  /*Close the log file */
  CloseLogFile(fpdbg);
}
void Chapter1Test::Test1_6() {
  ofstream fout;
  OpenLogFile(fout,"test1_6.html","Problem 1.6: rotate an image by 90 degrees clockwisely");


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

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

  tools.GenerateNewMatrix(img, {1,2,3,4,5,6,7,8,9}, 3, 3);
  tools.GenerateNewMatrix(expected, {7,4,1,8,5,2,9,6,3}, 3, 3);
  input.str("");
  tools.PrintMatrix2File(img, input);
  sol.prob1_6(img);
  TestMatrix(fout, input.str(), img, expected);

  tools.GenerateNewMatrix(img, {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}, 4, 4);
  tools.GenerateNewMatrix(expected, {13,9,5,1,14,10,6,2,15,11,7,3,16,12,8,4}, 4, 4);
  input.str("");
  tools.PrintMatrix2File(img, input);
  sol.prob1_6(img);
  TestMatrix(fout, input.str(), img, expected);

  tools.GenerateNewMatrix(img, {1,2,3,4,5,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, {21,16,11,6,1,22,17,12,7,2,23,18,13,8,3,24,19,14,9,4,25,20,15,10,5}, 5, 5);
  input.str("");
  tools.PrintMatrix2File(img, input);
  sol.prob1_6(img);
  TestMatrix(fout, input.str(), img, expected);

  tools.GenerateNewMatrix(img, {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36}, 6, 6);
  tools.GenerateNewMatrix(expected, {31,25,19,13,7,1,32,26,20,14,8,2,33,27,21,15,9,3,34,28,22,16,10,4,35,29,23,17,11,5,36,30,24,18,12,6}, 6, 6);
  input.str("");
  tools.PrintMatrix2File(img, input);
  sol.prob1_6(img);
  TestMatrix(fout, input.str(), img, expected);

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

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

  CloseLogFile(fout);
}
void Chapter1Test::Test1_4() {
  ofstream fout;
  OpenLogFile(fout,"test1_4.html","Problem 1.4: replace spaces with %20 in a string");


  char *output(nullptr);
  tools.new_c_str_N(output, "",1000);
  char *expected(nullptr);
  tools.new_c_str_N(expected, "",1000);
  sol.prob1_4(output,0);
  TestStaticArray(fout, "",output, expected,strlen(output), strlen(expected));
  delete []output;
  delete []expected;

  tools.new_c_str_N(output, "abcde",1000);
  tools.new_c_str_N(expected, "abcde",1000);
  sol.prob1_4(output,5);
  TestStaticArray(fout, "abcde", output, expected,strlen(output), strlen(expected));
  delete []output;
  delete []expected;

  tools.new_c_str_N(output, "a b cde f ew",1000);
  tools.new_c_str_N(expected, "a%20b%20cde%20f%20ew",1000);
  sol.prob1_4(output, sizeof("a b cde f ew"));
  TestStaticArray(fout, "a b cde f ew", output, expected,strlen(output), strlen(expected));
  delete []output;
  delete []expected;

  tools.new_c_str_N(output, "a b cde f ew ",1000);
  tools.new_c_str_N(expected, "a%20b%20cde%20f%20ew%20",1000);
  sol.prob1_4(output, sizeof("a b cde f ew "));
  TestStaticArray(fout, "a b cde f ew ",output, expected,strlen(output), strlen(expected));
  delete []output;
  delete []expected;

  tools.new_c_str_N(output, "a     b cde f ew ",1000);
  tools.new_c_str_N(expected, "a%20%20%20%20%20b%20cde%20f%20ew%20",1000);
  sol.prob1_4(output, sizeof("a     b cde f ew "));
  TestStaticArray(fout, "a     b cde f ew ", output, expected,strlen(output), strlen(expected));
  delete []output;
  delete []expected;

  tools.new_c_str_N(output, "  a     b cde f ew ",1000);
  tools.new_c_str_N(expected, "%20%20a%20%20%20%20%20b%20cde%20f%20ew%20",1000);
  sol.prob1_4(output, sizeof("  a     b cde f ew "));
  TestStaticArray(fout, "  a     b cde f ew ",output, expected,strlen(output), strlen(expected));
  delete []output;
  delete []expected;

  tools.new_c_str_N(output, "        ",1000);
  tools.new_c_str_N(expected, "%20%20%20%20%20%20%20%20",1000);
  sol.prob1_4(output, sizeof("        "));
  TestStaticArray(fout, "        ", output, expected,strlen(output), strlen(expected));
  delete []output;
  delete []expected;

  CloseLogFile(fout);
}
Example #20
0
/* static */
void Logger::Shutdown()
{
    if (s_initialized)
    {
        DeleteCriticalSection(&s_critSec);
        CloseLogFile();
        s_initialized = false;
    }
}
Example #21
0
BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvreserved )
{
    int Priority;

    switch ( dwReason )
    {
    case DLL_THREAD_ATTACH:
        break;

    case DLL_PROCESS_ATTACH:
        if ( !ClearAndGenerateLogFile( ) )
        {
            return false;
        }
        InitMainVariables( );

        if ( SetPriorityClass( GetCurrentProcess( ), NORMAL_PRIORITY_CLASS ) == 0 )
        {
            Error( "Could not set Class Priority.\n" );
        }
        else
        {
            GlideMsg( OGL_LOG_SEPARATE );
            GlideMsg( "Wrapper Class Priority of %d\n", NORMAL_PRIORITY_CLASS );
        }

        switch ( UserConfig.Priority )
        {
        case 0:     Priority = THREAD_PRIORITY_HIGHEST;         break;
        case 1:     Priority = THREAD_PRIORITY_ABOVE_NORMAL;    break;
        case 2:     Priority = THREAD_PRIORITY_NORMAL;          break;
        case 3:     Priority = THREAD_PRIORITY_BELOW_NORMAL;    break;
        case 4:     Priority = THREAD_PRIORITY_LOWEST;          break;
        case 5:     Priority = THREAD_PRIORITY_IDLE;            break;
        default:    Priority = THREAD_PRIORITY_NORMAL;          break;
        }
        if ( SetThreadPriority( GetCurrentThread(), Priority ) == 0 )
        {
            Error( "Could not set Thread Priority.\n" );
        }
        else
        {
            GlideMsg( "Wrapper Priority of %d\n", UserConfig.Priority );
            GlideMsg( OGL_LOG_SEPARATE );
        }
        break;

    case DLL_THREAD_DETACH:
        break;

    case DLL_PROCESS_DETACH:
        grGlideShutdown( );
        CloseLogFile( );
        break;
    }
    return TRUE;
}
Example #22
0
void FileMedia::Write(ELogMessageType type, ELogMessageLevel nLevel, LPCTSTR pszDate, LPCTSTR pszTime, LPCTSTR pszThreadId, LPCTSTR pszThreadName, LPCTSTR pszModule, LPCTSTR pszMessage)
{
    if (m_bNewFileDaily && m_wLogYear != 0)
    {
        SYSTEMTIME st;
        GetLocalTime(&st);
        if (st.wDay != m_wLogDay || st.wMonth != m_wLogMonth || st.wDay != m_wLogDay)
        {
            CloseLogFile();
            OpenLogFile();
        }
    }

    if (WaitForSingleObject(m_hMutex, 1000) == WAIT_TIMEOUT)
        return;

    // trying to restore access
    if (m_hFile == INVALID_HANDLE_VALUE)
    {
        m_hFile = CreateFile(m_sFilename,
            GENERIC_WRITE,
            FILE_SHARE_READ | FILE_SHARE_WRITE,
            NULL,
            OPEN_ALWAYS,
            FILE_ATTRIBUTE_NORMAL,
            NULL);
        if (m_hFile == INVALID_HANDLE_VALUE)
        {
            VERIFY(ReleaseMutex(m_hMutex));
            return;
        }
    }

    LONG dwDistanceToMoveHigh = 0; // Нужен, чтобы писать в файлы больше 4Гб
    if (SetFilePointer(m_hFile, 0, &dwDistanceToMoveHigh, FILE_END) == INVALID_SET_FILE_POINTER
        && GetLastError() != NO_ERROR)
    {
        _RPT0(_CRT_ERROR, "FileMedia: Can't set file pointer");
        m_hFile.Close();
        VERIFY(ReleaseMutex(m_hMutex));
        return;
    }

    CString output;
    FormatLogMessage(type, nLevel, pszDate, pszTime, pszThreadId, pszThreadName, pszModule, pszMessage, output);
    output += _T("\r\n");

    CStringA outputA = output;

    DWORD dwWritten;
//  VERIFY(WriteFile(m_hFile, (LPCTSTR)output, (DWORD) output.size() * sizeof(TCHAR), &dwWritten, NULL));
    VERIFY(WriteFile(m_hFile, (LPCSTR)outputA, (DWORD) outputA.GetLength() * sizeof(CHAR), &dwWritten, NULL));
    if (m_bFlush)
        VERIFY(FlushFileBuffers(m_hFile));
    VERIFY(ReleaseMutex(m_hMutex));
}
void Chapter2Test::Test2_4() {
  ofstream fout;
  OpenLogFile(fout,"test2_4.html","Problem 2.4: partition a list such that all elements less than x is before it.");

  ListNode *head(nullptr);
  ListNode *expected(nullptr);
  stringstream ss;

  ListNode::GenerateListNode({}, 0, head);
  ListNode::GenerateListNode({}, 0, expected);
  ListNode::PrintListNode(head, ss);
  sol.prob2_4(head,0);
  TestLinkedList(fout, ss.str()+", 0", head, expected);

  ss.str("");
  int A0[] = {1};
  ListNode::GenerateListNode(A0,1, head);
  ListNode::GenerateListNode(A0, 1, expected);
  ListNode::PrintListNode(head, ss);
  sol.prob2_4(head, 10);
  TestLinkedList(fout, ss.str()+", 11", head, expected);

  ss.str("");
  int A2[] = {2,9,3,4,5}, B2[] = {2,3,4,5,9};
  ListNode::GenerateListNode(A2, sizeof(A2)/sizeof(A2[0]), head);
  ListNode::GenerateListNode(B2, sizeof(B2)/sizeof(B2[0]), expected);
  ListNode::PrintListNode(head, ss);
  sol.prob2_4(head,6);
  TestLinkedList(fout, ss.str()+", 6", head, expected);

  ss.str("");
  int A1[] = {2,9,3,4,5}, B1[] = {2,9,3,4,5};
  ListNode::GenerateListNode(A1, sizeof(A1)/sizeof(A1[0]), head);
  ListNode::GenerateListNode(B1, sizeof(B1)/sizeof(B1[0]), expected);
  ListNode::PrintListNode(head, ss);
  sol.prob2_4(head,-10);
  TestLinkedList(fout, ss.str()+", -10", head, expected);

  ss.str("");
  int A3[] = {2,9,3,4,5}, B3[] = {2,9,3,4,5};
  ListNode::GenerateListNode(A3, sizeof(A3)/sizeof(A3[0]), head);
  ListNode::GenerateListNode(B3, sizeof(B3)/sizeof(B3[0]), expected);
  ListNode::PrintListNode(head, ss);
  sol.prob2_4(head,10);
  TestLinkedList(fout, ss.str()+", 10", head, expected);

  ss.str("");
  int A4[] = {2,9,8,15,13,5}, B4[] = {2,8,5,9,15,13};
  ListNode::GenerateListNode(A4, sizeof(A4)/sizeof(A4[0]), head);
  ListNode::GenerateListNode(B4, sizeof(B4)/sizeof(B4[0]), expected);
  ListNode::PrintListNode(head, ss);
  sol.prob2_4(head,8);
  TestLinkedList(fout, ss.str()+", 8", head, expected);

  CloseLogFile(fout);
}
///////////////////////////////////////////////////////////////////
//  DoDeleteLogFileL
//  This function deletes the event log file
///////////////////////////////////////////////////////////////////
void CEventViewer::DoDeleteLogFileL()
    {
    CloseLogFile();
    TInt status = iEventMediator.ClearEventLog();
    LOG(Log::Printf(_L("Log cleared %d\n"), status));
    if (status != KErrNone)
        {
        User::Leave(status);
        }
    }
void Chapter1Test::Test1_1() {
  ofstream fout;
  OpenLogFile(fout,"test1_1.html", "Problem 1.1: reverse a null-terminated string");

  TestBasic(fout, "abcdef", sol.prob1_1("abcdef"), true);
  TestBasic(fout, "abcdefb", sol.prob1_1("abcdefb"), false);
  TestBasic(fout, "", sol.prob1_1(""), true);

  CloseLogFile(fout);
}
Example #26
0
CAntiCheatManager::~CAntiCheatManager()
{
	CloseLogFile();

	CDownloadableResourcePtr res = GetDownloadableResource();
	if (res)
	{
		res->RemoveDataListener(this);
	}
}
void Chapter2Test::Test2_2() {
  ofstream fout;
  OpenLogFile(fout,"test2_2.html","Problem 2.2: find the kth to last element of a sngly linked list");

  ListNode *head(nullptr);
  ListNode *output(nullptr);
  ListNode *expected(nullptr);
  stringstream ss;

  ListNode::GenerateListNode({}, 0, head);
  ListNode::GenerateListNode({}, 0, expected);
  ListNode::PrintListNode(head, ss);
  output = sol.prob2_2(head,0);
  TestLinkedList(fout, ss.str()+",0", output, expected);

  ss.str("");
  ListNode::GenerateListNode({}, 0, head);
  ListNode::GenerateListNode({}, 0, expected);
  ListNode::PrintListNode(head, ss);
  output = sol.prob2_2(head,4);
  TestLinkedList(fout, ss.str()+",4", output, expected);

  ss.str("");
  int A1[] = {1,2,2,3,1,4,5,1,2,3,4,5,3,4,5}, B1[] = {4,5,3,4,5};
  ListNode::GenerateListNode(A1, sizeof(A1)/sizeof(A1[0]), head);
  ListNode::GenerateListNode(B1, sizeof(B1)/sizeof(B1[0]), expected);
  ListNode::PrintListNode(head, ss);
  output = sol.prob2_2(head,4);
  TestLinkedList(fout, ss.str()+",4", output, expected);

  ss.str("");
  int A2[] = {1,2,2,3,1,4,5,1,2,3,4,5,3,4,5}, B2[] = {5};
  ListNode::GenerateListNode(A2, sizeof(A2)/sizeof(A2[0]), head);
  ListNode::GenerateListNode(B2, sizeof(B2)/sizeof(B2[0]), expected);
  ListNode::PrintListNode(head, ss);
  output = sol.prob2_2(head,0);
  TestLinkedList(fout, ss.str()+",0", output, expected);

  ss.str("");
  int A3[] = {1,2,2,3,1,4,5,1,2,3,4,5,3,4,5}, B3[] = {4,5};
  ListNode::GenerateListNode(A3, sizeof(A3)/sizeof(A3[0]), head);
  ListNode::GenerateListNode(B3, sizeof(B3)/sizeof(B3[0]), expected);
  ListNode::PrintListNode(head, ss);
  output = sol.prob2_2(head,1);
  TestLinkedList(fout, ss.str()+",1", output, expected);

  ss.str("");
  int A4[] = {1,2,2,3,1,4,5,1,2,3,4,5,3,4,5};
  ListNode::GenerateListNode(A4, sizeof(A4)/sizeof(A4[0]), head);
  ListNode::PrintListNode(head, ss);
  output = sol.prob2_2(head,10000);
  TestLinkedList(fout, ss.str()+",10000", output, nullptr);

  CloseLogFile(fout);
}
Example #28
0
void CLogger::CreateLogFile()
{
	CloseLogFile();

	if (!m_LogPath.isEmpty())
	{
		m_LogFile = new QFile(QString(m_LogPath).append("/%1Log_%2.txt").arg(m_Name).arg(m_LastDate.toString(Qt::ISODate)));
		m_LogFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append);
		m_LogStream = new QTextStream(m_LogFile);
	}
}
void Chapter9Test::Test9_3() {
  ofstream fout;
  OpenLogFile(fout, "test9_3.html", "Problem 9.3: find magic index in an array");

  TestBasic(fout, "{0,1,2,3,10,39}", sol.prob9_3({0,1,2,3,10,39}), true);
  TestBasic(fout, "{-10,-8,1,3,10,39}", sol.prob9_3({-10,-8,1,3,10,39}), true);
  TestBasic(fout, "{-10,-8,1,4,10,39}", sol.prob9_3({-10,-8,1,4,10,39}), false);
  TestBasic(fout, "{1,3,4,5,5,5,5,5,5,9,10}", sol.prob9_3_duplicate({1,3,4,5,5,5,5,5,5,9,10}), true);
  TestBasic(fout, "{1,3,4,5,5,6,7,8,9,10,11}", sol.prob9_3_duplicate({1,3,4,5,5,6,7,8,9,10,11}), false);

  CloseLogFile(fout);
}
Example #30
0
File: XT.cpp Project: robessog/OBS
void __cdecl LogRaw(const TCHAR *text, UINT len)
{
    if(!text) return;

    if (!len)
        len = slen(text);

    OpenLogFile();
    LogFile.WriteAsUTF8(text, len);
    LogFile.WriteAsUTF8(TEXT("\r\n"));
    CloseLogFile();
}