// // main.c // // Program entry. Handle's callbacks, program initialization, // and commandline data. // // Copyright (C) 2001 Microsoft Corporation // // Author: a-devjen (Devin Jenson) // #include "tbscript.h" #include #include #include // Max number of characters per message. #define LOG_BUFFER_SIZE 2048 // Set this to TRUE to print all messages to stdout. static BOOL VerbosePrinting = FALSE; // IdleCallback // // When a client does not respond for 30 seconds, a message is sent // to this function. Every 10 seconds after that, an additional // message is sent. Text contains the string in which the script // is "waiting on" which has not been found. void __cdecl IdleCallback(LPARAM lParam, LPCSTR Text, DWORD Seconds) { // Add any custom handler data here. } // PrintMessage // // Whenever a message needs to be printed to the console, this function // will be called. void PrintMessage(MESSAGETYPE eMsgType, LPCSTR lpszFormat, ...) { // Evaluate the message type. switch (eMsgType) { // Do not handle these message types for non-debugging case ALIVE_MESSAGE: case INFO_MESSAGE: if (VerbosePrinting == FALSE) return; // The remaining message types are always used case SCRIPT_MESSAGE: case IDLE_MESSAGE: case ERROR_MESSAGE: case WARNING_MESSAGE: break; } // We probably shouldn't trust the data pointed by lpszFormat __try { va_list arglist; // Allocate a buffer for us char *pszBuffer = (char *)HeapAlloc(GetProcessHeap(), 0, LOG_BUFFER_SIZE); // Validate the buffer if (pszBuffer == NULL) { printf("%s", "ERROR: PrintMessage() Failed - Not enough memory.\n"); return; } // Format the message va_start(arglist, lpszFormat); _vsnprintf(pszBuffer, LOG_BUFFER_SIZE - 1, lpszFormat, arglist); pszBuffer[LOG_BUFFER_SIZE - 1] = '\0'; va_end(arglist); // Print it printf("%s", pszBuffer); // Free the buffer HeapFree(GetProcessHeap(), 0, pszBuffer); } __except (EXCEPTION_EXECUTE_HANDLER) { return; } } // ShowUsage // // Prints a message to stdout the version, title, usage and other info. void ShowUsage(void) { char UsageString[] = "\nTerminal Bench Script (BUILD: " __DATE__ ")\n" "Copyright (C) 2001 Microsoft Corp.\n\n" "Usage:\n\ntbscript.exe