Beispiel #1
0
OBJECT ParameterCheck(OBJECT x, OBJECT env)
{ OBJECT link, y, res, prnt_env, par, prnt;
  debug2(DCE, DD, "ParameterCheck(%s, %s)", EchoObject(x), EchoObject(env));
  assert( type(x) == CLOSURE, "ParameterCheck given non-CLOSURE!");

  /* case x is a parameter */
  prnt = SearchEnv(env, enclosing(actual(x)));
  if( prnt == nilobj )
  { debug0(DCE, DD, "ParameterCheck returning nilobj (prnt fail)");
    return nilobj;
  }
  prnt_env = GetEnv(prnt);
  for( link = Down(prnt);  link != prnt;  link = NextDown(link) )
  { Child(par, link);
    if( type(par) == PAR && actual(par) == actual(x) )
    {	assert( Down(par) != par, "ParameterCheck: Down(par)!");
	Child(y, Down(par));
	res = is_word(type(y)) ? CopyObject(y, no_fpos) : nilobj;
	debug1(DCE, DD, "  ParameterCheck returning %s", EchoObject(res));
	return res;
    }
  }

  /* case x is a default parameter */
  y = sym_body(actual(x));
  if( y == nilobj )
  { res = nilobj;
  }
  else if( is_word(type(y)) )
  { res = CopyObject(y, &fpos(y));
  }
  else if( type(y) == CLOSURE && is_par(type(actual(y))) )
  { res = ParameterCheck(y, prnt_env);
  }
  else
  { res = nilobj;
  }
  debug1(DCE, DD, "ParameterCheck returning %s", EchoObject(res));
  return res;
} /* end ParameterCheck */
Beispiel #2
0
int _tmain(int argc, _TCHAR* argv[])
{
	UINT loop_times = 0;
	BOOL loop_endless = FALSE;
	DWORD ms_between_loop = 0;
	BOOL enable_logs = FALSE;
	TCHAR command[CMD_BUF_SIZE] = {0}; 

	if ( ParameterCheck(argc, argv, loop_times, ms_between_loop, enable_logs, command, CMD_BUF_SIZE) )
	{
		loop_endless = ( 0 == loop_times ); 
	}
	else
	{
		PrintUsage(argv[0]);
		return 1;
	}

	HANDLE hLogFile = INVALID_HANDLE_VALUE;

	if( TRUE == enable_logs)
	{
		SYSTEMTIME st;
		GetSystemTime(&st);

		TCHAR logFileName[MAX_PATH] = {0};

		_stprintf_s(logFileName, MAX_PATH - 1, _T("loop_trace_%04d%02d%02d-%d-%02d%02d%02d-%03d.log"),
			st.wYear,st.wMonth,st.wDay,st.wDayOfWeek,st.wHour,st.wMinute,st.wSecond,st.wMilliseconds);

		dbgtprintf(logFileName); 
		dbgtprintf(L"\n"); 


		hLogFile = CreateFile(logFileName,
			GENERIC_READ | GENERIC_WRITE,
			FILE_SHARE_READ,
			NULL,
			CREATE_ALWAYS,
			FILE_ATTRIBUTE_NORMAL,
			NULL);

		if(INVALID_HANDLE_VALUE == hLogFile)
		{
			_tprintf(_T("Failed to Create Log File, st = 0x%x\n"), GetLastError());
			return 1;
		}
		else
		{
			dbgtprintf(TEXT("OK to CreateFile.\n")); 
		}
	}

	while( loop_endless || loop_times > 0 )
	{
		if(!loop_endless)
		{
			--loop_times;
		}

		CHAR printedCommand[CMD_BUF_SIZE] = {0}; 
		
		sprintf_s(printedCommand, CMD_BUF_SIZE - 1, "\n-> %S\n\n",
			command + _tcsnlen(BASE_CMD, CMD_BUF_SIZE) + 1);

		printf(printedCommand);

		if (INVALID_HANDLE_VALUE != hLogFile)
		{
			DWORD dwToWrite = sizeof(CHAR) * strnlen(printedCommand, CMD_BUF_SIZE);
			DWORD dwWritten = 0;
			BOOL bWrite = WriteFile( hLogFile, 
						printedCommand, 
						dwToWrite, 
						&dwWritten, 
						NULL);
			
			if(!bWrite)
			{
				_tprintf(_T("Write to log file error, st=0x%x\n"), GetLastError());
				assert(false);
			}

			assert(dwToWrite == dwWritten);
		}

		ExecuteCommand(command, CMD_BUF_SIZE, enable_logs, hLogFile);

		
		Sleep(ms_between_loop);
	}

	if (INVALID_HANDLE_VALUE != hLogFile)
	{
		CloseHandle(hLogFile);
	}

	return 0;
}