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 ///////////////////////////////////////////////////////////////////////////////
47 #ifndef LANG_USER_DEFAULT
48 #define LANG_USER_DEFAULT 400
51 // This has been moved to tnconfig.cpp
52 // int Telnet_Redir = 0;
53 // Telnet_Redir is set to the value of the environment variable TELNET_REDIR
56 int printit(const char * it
){
58 if (!ini
.get_output_redir()) {
60 GetStdHandle(STD_OUTPUT_HANDLE
), // handle of a console screen buffer
61 it
, // address of buffer to write from
62 strlen(it
), // number of characters to write
63 &numwritten
, // address of number of characters written
66 // FIX ME!!! We need to tell the console that the cursor has moved.
67 // Does this mean making Console global?
68 // Paul Brannan 6/14/98
72 GetStdHandle(STD_OUTPUT_HANDLE
), // handle of a console screen buffer
73 it
, // address of buffer to write from
74 strlen(it
), // number of characters to write
75 &numwritten
, // address of number of characters written
76 NULL
// no overlapped I/O
82 int printm(LPTSTR szModule
, BOOL fSystem
, DWORD dwMessageId
, ...)
88 hModule
= LoadLibrary(szModule
);
91 va_start(Ellipsis
, dwMessageId
);
93 LPTSTR pszMessage
= 0;
96 dwMessage
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
97 FORMAT_MESSAGE_FROM_SYSTEM
, hModule
, dwMessageId
,
98 LANG_USER_DEFAULT
, (LPTSTR
)&pszMessage
, 128, &Ellipsis
);
100 // we will use a string table.
102 if(LoadString(0, dwMessageId
, szString
, sizeof(szString
)))
103 dwMessage
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
104 FORMAT_MESSAGE_FROM_STRING
, szString
, dwMessageId
,
105 LANG_USER_DEFAULT
, (LPTSTR
)&pszMessage
, 256, &Ellipsis
);
111 FreeLibrary(hModule
);
115 Result
= printit(pszMessage
);
116 LocalFree(pszMessage
);
123 void LogErrorConsole(LPTSTR szError
)
125 DWORD dwLastError
= GetLastError();
127 const int cbLastError
= 1024;
128 TCHAR szLastError
[cbLastError
];
129 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
, 0, dwLastError
, LANG_USER_DEFAULT
,
130 szLastError
, cbLastError
, 0);
132 LPTSTR lpszStrings
[2];
133 lpszStrings
[0] = szError
;
134 lpszStrings
[1] = szLastError
;
136 const int cbErrorString
= 1024;
137 TCHAR szErrorString
[cbErrorString
];
138 FormatMessage(FORMAT_MESSAGE_FROM_HMODULE
| FORMAT_MESSAGE_ARGUMENT_ARRAY
,
139 0, MSG_ERROR
, LANG_USER_DEFAULT
,
140 szErrorString
, cbErrorString
, (va_list*)lpszStrings
);
144 char* szTime
= ctime(&dwTime
);
147 // printf("E %s %s", szTime + 11, szErrorString);
149 buf
= new char [ 3 + strlen(szTime
) - 11 + strlen(szErrorString
) + 5 ];
150 sprintf( buf
,"E %s %s", szTime
+ 11, szErrorString
);
156 void LogWarningConsole(DWORD dwEvent
, LPTSTR szWarning
)
158 DWORD dwLastError
= GetLastError();
160 const int cbLastError
= 1024;
161 TCHAR szLastError
[cbLastError
];
162 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
, 0, dwLastError
, LANG_USER_DEFAULT
,
163 szLastError
, cbLastError
, 0);
165 LPTSTR lpszStrings
[2];
166 lpszStrings
[0] = szWarning
;
167 lpszStrings
[1] = szLastError
;
169 const int cbWarningString
= 1024;
170 TCHAR szWarningString
[cbWarningString
];
171 FormatMessage(FORMAT_MESSAGE_FROM_HMODULE
| FORMAT_MESSAGE_ARGUMENT_ARRAY
,
172 0, dwEvent
, LANG_USER_DEFAULT
,
173 szWarningString
, cbWarningString
, (va_list*)lpszStrings
);
177 char* szTime
= ctime(&dwTime
);
180 // printf("W %s %s", szTime + 11, szWarningString);
182 buf
= new char [ 3 + strlen(szTime
) - 11 + strlen(szWarningString
) + 5 ];
183 sprintf(buf
,"W %s %s", szTime
+ 11, szWarningString
);
190 void LogInfoConsole(DWORD dwEvent
, LPTSTR szInformation
)
192 LPTSTR lpszStrings
[1];
193 lpszStrings
[0] = szInformation
;
195 const int cbInfoString
= 1024;
196 TCHAR szInfoString
[cbInfoString
];
197 FormatMessage(FORMAT_MESSAGE_FROM_HMODULE
| FORMAT_MESSAGE_ARGUMENT_ARRAY
,
198 0, dwEvent
, LANG_USER_DEFAULT
,
199 szInfoString
, cbInfoString
, (va_list*)lpszStrings
);
203 char* szTime
= ctime(&dwTime
);
206 // printf("I %s %s", szTime + 11, szInfoString);
208 buf
= new char [ 3 + strlen(szTime
) - 11 + strlen(szInfoString
) + 5 ];
209 sprintf(buf
,"I %s %s", szTime
+ 11, szInfoString
);