1 ///////////////////////////////////////////////////////////////////////////////
2 //Telnet Win32 : an ANSI telnet client.
3 //Copyright (C) 1998-2000 Paul Brannan
4 //Copyright (C) 1998 I.Ioannou
5 //Copyright (C) 1997 Brad Johnson
7 //This program is free software; you can redistribute it and/or
8 //modify it under the terms of the GNU General Public License
9 //as published by the Free Software Foundation; either version 2
10 //of the License, or (at your option) any later version.
12 //This program is distributed in the hope that it will be useful,
13 //but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 //GNU General Public License for more details.
17 //You should have received a copy of the GNU General Public License
18 //along with this program; if not, write to the Free Software
19 //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 ///////////////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////////////////
28 // Module: tnerror.cpp
30 // Contents: error reporting
34 // Revisions: June 15, 1998 Paul Brannan <pbranna@clemson.edu>
35 // May 15, 1998 Paul Brannan
36 // 5.April.1997 jbj@nounname.com
37 // 5.Dec.1996 jbj@nounname.com
40 // 02.Apr.1995 igor.milavec@uni-lj.si
43 ///////////////////////////////////////////////////////////////////////////////
46 #include "ttelhndl.h" // Paul Brannan 5/25/98
47 #include "tnconfig.h" // Paul Brannan 5/25/98
53 #ifndef LANG_USER_DEFAULT
54 #define LANG_USER_DEFAULT 400
57 // This has been moved to tnconfig.cpp
58 // int Telnet_Redir = 0;
59 // Telnet_Redir is set to the value of the environment variable TELNET_REDIR
62 int printit(const char * it
){
64 if (!ini
.get_output_redir()) {
66 GetStdHandle(STD_OUTPUT_HANDLE
), // handle of a console screen buffer
67 it
, // address of buffer to write from
68 strlen(it
), // number of characters to write
69 &numwritten
, // address of number of characters written
72 // FIX ME!!! We need to tell the console that the cursor has moved.
73 // Does this mean making Console global?
74 // Paul Brannan 6/14/98
78 GetStdHandle(STD_OUTPUT_HANDLE
), // handle of a console screen buffer
79 it
, // address of buffer to write from
80 strlen(it
), // number of characters to write
81 &numwritten
, // address of number of characters written
82 NULL
// no overlapped I/O
88 int printm(LPTSTR szModule
, BOOL fSystem
, DWORD dwMessageId
, ...)
94 hModule
= LoadLibrary(szModule
);
97 va_start(Ellipsis
, dwMessageId
);
99 LPTSTR pszMessage
= 0;
102 dwMessage
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
103 FORMAT_MESSAGE_FROM_SYSTEM
, hModule
, dwMessageId
,
104 LANG_USER_DEFAULT
, (LPTSTR
)&pszMessage
, 128, &Ellipsis
);
106 // we will use a string table.
108 if(LoadString(0, dwMessageId
, szString
, sizeof(szString
)))
109 dwMessage
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
110 FORMAT_MESSAGE_FROM_STRING
, szString
, dwMessageId
,
111 LANG_USER_DEFAULT
, (LPTSTR
)&pszMessage
, 256, &Ellipsis
);
117 FreeLibrary(hModule
);
121 Result
= printit(pszMessage
);
122 LocalFree(pszMessage
);
129 void LogErrorConsole(LPTSTR szError
)
131 DWORD dwLastError
= GetLastError();
133 const int cbLastError
= 1024;
134 TCHAR szLastError
[cbLastError
];
135 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
, 0, dwLastError
, LANG_USER_DEFAULT
,
136 szLastError
, cbLastError
, 0);
138 LPTSTR lpszStrings
[2];
139 lpszStrings
[0] = szError
;
140 lpszStrings
[1] = szLastError
;
142 const int cbErrorString
= 1024;
143 TCHAR szErrorString
[cbErrorString
];
144 FormatMessage(FORMAT_MESSAGE_FROM_HMODULE
| FORMAT_MESSAGE_ARGUMENT_ARRAY
,
145 0, MSG_ERROR
, LANG_USER_DEFAULT
,
146 szErrorString
, cbErrorString
, (va_list*)lpszStrings
);
150 char* szTime
= ctime(&dwTime
);
153 // printf("E %s %s", szTime + 11, szErrorString);
155 buf
= new char [ 3 + strlen(szTime
) - 11 + strlen(szErrorString
) + 5 ];
156 sprintf( buf
,"E %s %s", szTime
+ 11, szErrorString
);
162 void LogWarningConsole(DWORD dwEvent
, LPTSTR szWarning
)
164 DWORD dwLastError
= GetLastError();
166 const int cbLastError
= 1024;
167 TCHAR szLastError
[cbLastError
];
168 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
, 0, dwLastError
, LANG_USER_DEFAULT
,
169 szLastError
, cbLastError
, 0);
171 LPTSTR lpszStrings
[2];
172 lpszStrings
[0] = szWarning
;
173 lpszStrings
[1] = szLastError
;
175 const int cbWarningString
= 1024;
176 TCHAR szWarningString
[cbWarningString
];
177 FormatMessage(FORMAT_MESSAGE_FROM_HMODULE
| FORMAT_MESSAGE_ARGUMENT_ARRAY
,
178 0, dwEvent
, LANG_USER_DEFAULT
,
179 szWarningString
, cbWarningString
, (va_list*)lpszStrings
);
183 char* szTime
= ctime(&dwTime
);
186 // printf("W %s %s", szTime + 11, szWarningString);
188 buf
= new char [ 3 + strlen(szTime
) - 11 + strlen(szWarningString
) + 5 ];
189 sprintf(buf
,"W %s %s", szTime
+ 11, szWarningString
);
196 void LogInfoConsole(DWORD dwEvent
, LPTSTR szInformation
)
198 LPTSTR lpszStrings
[1];
199 lpszStrings
[0] = szInformation
;
201 const int cbInfoString
= 1024;
202 TCHAR szInfoString
[cbInfoString
];
203 FormatMessage(FORMAT_MESSAGE_FROM_HMODULE
| FORMAT_MESSAGE_ARGUMENT_ARRAY
,
204 0, dwEvent
, LANG_USER_DEFAULT
,
205 szInfoString
, cbInfoString
, (va_list*)lpszStrings
);
209 char* szTime
= ctime(&dwTime
);
212 // printf("I %s %s", szTime + 11, szInfoString);
214 buf
= new char [ 3 + strlen(szTime
) - 11 + strlen(szInfoString
) + 5 ];
215 sprintf(buf
,"I %s %s", szTime
+ 11, szInfoString
);