Update of /cvsroot/com0com/com0com/setup
In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv27116
Modified Files:
msg.cpp msg.h
Log Message:
Added
ConsoleWrite()
IsConsoleOpen()
SetOutputFile()
GetOutputFile()
Index: msg.h
===================================================================
RCS file: /cvsroot/com0com/com0com/setup/msg.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** msg.h 23 Oct 2006 12:04:23 -0000 1.2
--- msg.h 21 Nov 2006 11:34:55 -0000 1.3
***************
*** 20,23 ****
--- 20,30 ----
*
* $Log$
+ * Revision 1.3 2006/11/21 11:34:55 vfrolov
+ * Added
+ * ConsoleWrite()
+ * IsConsoleOpen()
+ * SetOutputFile()
+ * GetOutputFile()
+ *
* Revision 1.2 2006/10/23 12:04:23 vfrolov
* Added SetTitle()
***************
*** 26,30 ****
* Initial revision
*
- *
*/
--- 33,36 ----
***************
*** 37,41 ****
--- 43,51 ----
void Trace(const char *pFmt, ...);
void ConsoleWriteRead(char *pReadBuf, int lenReadBuf, const char *pFmt, ...);
+ void ConsoleWrite(const char *pFmt, ...);
+ BOOL IsConsoleOpen();
void SetTitle(const char *pTitle);
+ void SetOutputFile(const char *pFile);
+ const char *GetOutputFile();
#endif /* _C0C_MSG_H_ */
Index: msg.cpp
===================================================================
RCS file: /cvsroot/com0com/com0com/setup/msg.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** msg.cpp 23 Oct 2006 12:04:23 -0000 1.3
--- msg.cpp 21 Nov 2006 11:34:55 -0000 1.4
***************
*** 20,23 ****
--- 20,30 ----
*
* $Log$
+ * Revision 1.4 2006/11/21 11:34:55 vfrolov
+ * Added
+ * ConsoleWrite()
+ * IsConsoleOpen()
+ * SetOutputFile()
+ * GetOutputFile()
+ *
* Revision 1.3 2006/10/23 12:04:23 vfrolov
* Added SetTitle()
***************
*** 35,38 ****
--- 42,46 ----
#include "utils.h"
+ char *pOutputFile = NULL;
char title[80] = "";
***************
*** 45,48 ****
--- 53,58 ----
static int (* pShowMsg)(LPCSTR pText, UINT type) = ShowMsgDefault;
///////////////////////////////////////////////////////////////
+ static BOOL isConsoleOpen = FALSE;
+
static void ConsoleWriteReadDefault(LPSTR pReadBuf, DWORD lenReadBuf, LPCSTR pText)
{
***************
*** 53,56 ****
--- 63,67 ----
handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTitle(title);
+ isConsoleOpen = TRUE;
}
***************
*** 74,77 ****
--- 85,116 ----
{
pConsole(NULL, 0, pText);
+
+ if (!pOutputFile || !pText)
+ return;
+
+ HANDLE hFile = CreateFile(
+ pOutputFile,
+ GENERIC_WRITE,
+ FILE_SHARE_READ,
+ NULL,
+ OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (hFile != INVALID_HANDLE_VALUE) {
+ SetFilePointer(hFile, 0, NULL, FILE_END);
+
+ LPCSTR p;
+
+ for (p = pText ; *p ; p++) {
+ DWORD not_used;
+
+ if (*p == '\n')
+ WriteFile(hFile, "\r", sizeof(*p), ¬_used, NULL);
+ WriteFile(hFile, p, sizeof(*p), ¬_used, NULL);
+ }
+
+ CloseHandle(hFile);
+ }
}
***************
*** 182,185 ****
--- 221,243 ----
}
///////////////////////////////////////////////////////////////
+ void ConsoleWrite(const char *pFmt, ...)
+ {
+ char buf[1024];
+ va_list va;
+
+ va_start(va, pFmt);
+
+ VSNPRINTF(buf, sizeof(buf)/sizeof(buf[0]), pFmt, va);
+
+ va_end(va);
+
+ pConsole(NULL, 0, buf);
+ }
+ ///////////////////////////////////////////////////////////////
+ BOOL IsConsoleOpen()
+ {
+ return isConsoleOpen;
+ }
+ ///////////////////////////////////////////////////////////////
void SetTitle(const char *pTitle)
{
***************
*** 187,188 ****
--- 245,266 ----
}
///////////////////////////////////////////////////////////////
+ void SetOutputFile(const char *pFile)
+ {
+ if (pOutputFile) {
+ LocalFree(pOutputFile);
+ pOutputFile = NULL;
+ }
+
+ if (pFile) {
+ pOutputFile = (char *)LocalAlloc(LPTR, (lstrlen(pFile) + 1)*sizeof(*pFile));
+
+ if (pOutputFile)
+ lstrcpy(pOutputFile, pFile);
+ }
+ }
+ ///////////////////////////////////////////////////////////////
+ const char *GetOutputFile()
+ {
+ return pOutputFile;
+ }
+ ///////////////////////////////////////////////////////////////
|