-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain.cpp
341 lines (301 loc) · 10.7 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
// Include the appropriate directives.
#include <ui_win.hpp>
#ifdef COMMENT
#undef COMMENT
#endif
#define USE_HELP_CONTEXTS
#define USE_WINDOW_DIALER
#define USE_DIALOG_DEMO
#include <direct.hpp>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#include "dialer.hpp"
#include "kconnect.hpp"
#include "kwinmgr.hpp"
#ifdef WIN32
extern "C" {
//#define OS2
//#define NT
#include "ckcdeb.h"
#include "ckoetc.h"
#ifndef NODIAL
#define TAPI_CURRENT_VERSION 0x00010004
#include <tapi.h>
#include <mcx.h>
#include "ktapi.h"
#endif /* NODIAL */
extern HWND hwndConsole;
#ifdef printf
#undef printf
#endif
}
#else /* WIN32 */
#define _stat stat
#ifndef S_IFDIR
#define _S_IFDIR S_IFDIR
#endif
#endif /* WIN32 */
K_CONNECTOR *connector = NULL ;
UIW_TOOL_BAR *toolbar = NULL ;
UID_TIMER * timer = NULL ;
/* Dialer 1.37 = Kermit 95 2.1.3
* Dialer 1.38 = Kermit 95 3.0 (open source) beta 4
* Updated the SSH settings
* Dialer 1.39 = Kermit 95 3.0 (open source) beta 7
* reimplemented GUI menu/tool/statusbar checkboxes from 2.1.3
*/
ZIL_UINT8 kd_major = 1, kd_minor = 39;
ZIL_ICHAR * pathname = "";
ZIL_UINT8 TapiAvail = 0;
ZIL_UINT8 StartMenu = 0;
ZIL_UINT8 Desktop = 0;
int UI_APPLICATION::Main(void)
{
pathname = argv[0] ;
setbuf(stdout,NULL);
printf("Main()\n");
printf("Checking OS Version\n");
#ifdef WIN32
OSVERSIONINFO osverinfo ;
osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO) ;
GetVersionEx( &osverinfo ) ;
printf("PlatformID = %d\n",osverinfo.dwPlatformId);
printf("MajorVersion = %d\n",osverinfo.dwMajorVersion);
printf("MinorVersion = %d\n",osverinfo.dwMinorVersion);
printf("BuildNumber = %d\n",osverinfo.dwBuildNumber);
if ( osverinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ||
osverinfo.dwPlatformId == VER_PLATFORM_WIN32_NT &&
osverinfo.dwMajorVersion >= 4 ) {
StartMenu = 1;
Desktop = 1;
}
HWND hwnd = FindWindow(NULL, "Kermit 95 Dialer");
if ( hwnd ) {
if ( IsIconic(hwnd) )
ShowWindow(hwnd, SW_SHOWNORMAL);
else
SetForegroundWindow( hwnd );
return(0);
}
#else /* WIN32 */
Desktop = 1;
#endif /* WIN32 */
// Fix linkers that don't look for main in the .LIBs.
UI_APPLICATION::LinkMain();
printf("Deleting windowManager\n");
delete windowManager ;
printf("Creating new WINDOW_MANAGER\n");
windowManager = new K_WINDOW_MANAGER(display, eventManager ) ;
/* Check TMP,TEMP,K95TMP */
char * p = NULL;
printf("Checking TMP,TEMP,K95TMP\n");
p = getenv("K95TMP");
if ( p ) {
struct _stat Stat;
int rc = stat(p,&Stat);
if ( rc && errno == ENOENT ) {
printf("WARNING: K95TMP = %s which does not exist.\n",p);
ZAF_MESSAGE_WINDOW * MessageBox =
new ZAF_MESSAGE_WINDOW( "Error", "EXCLAMATION",
ZIL_MSG_OK, ZIL_MSG_OK,
"K95TMP = %s. Must point to an subdirectory that exists.",
p) ;
MessageBox->Control();
delete MessageBox ;
return(1);
}
if ( !(Stat.st_mode & _S_IFDIR) ) {
printf("WARNING: K95TMP = %s which is a file.\n",p);
ZAF_MESSAGE_WINDOW * MessageBox =
new ZAF_MESSAGE_WINDOW( "Error", "EXCLAMATION",
ZIL_MSG_OK, ZIL_MSG_OK,
"K95TMP = %s. Must point to an subdirectory not a file.",
p) ;
MessageBox->Control();
delete MessageBox ;
return(1);
}
#ifdef WIN32
if ( osverinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) {
if ( strlen(p) == 3 && p[1] == ':' && p[2] == '\\' ) {
printf("WARNING: K95TMP = %s\n",p);
ZAF_MESSAGE_WINDOW * MessageBox =
new ZAF_MESSAGE_WINDOW( "Error", "EXCLAMATION",
ZIL_MSG_OK, ZIL_MSG_OK,
"K95TMP = %s. Must point to a subdirectory.",
p) ;
MessageBox->Control();
delete MessageBox ;
return(1);
}
}
#endif /* WIN32 */
}
p = getenv("TEMP");
if ( p ) {
struct _stat Stat;
int rc = stat(p,&Stat);
if ( rc && errno == ENOENT ) {
printf("WARNING: TEMP = %s which does not exist.\n",p);
ZAF_MESSAGE_WINDOW * MessageBox =
new ZAF_MESSAGE_WINDOW( "Error", "EXCLAMATION",
ZIL_MSG_OK, ZIL_MSG_OK,
"TEMP = %s. Must point to an subdirectory that exists.",
p) ;
MessageBox->Control();
delete MessageBox ;
return(1);
}
if ( !(Stat.st_mode & _S_IFDIR) ) {
printf("WARNING: TEMP = %s which is a file.\n",p);
ZAF_MESSAGE_WINDOW * MessageBox =
new ZAF_MESSAGE_WINDOW( "Error", "EXCLAMATION",
ZIL_MSG_OK, ZIL_MSG_OK,
"TEMP = %s. Must point to an subdirectory not a file.",
p) ;
MessageBox->Control();
delete MessageBox ;
return(1);
}
#ifdef WIN32
if ( osverinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) {
if ( strlen(p) == 3 && p[1] == ':' && p[2] == '\\' ) {
printf("WARNING: TEMP = %s\n",p);
ZAF_MESSAGE_WINDOW * MessageBox =
new ZAF_MESSAGE_WINDOW( "Error", "EXCLAMATION",
ZIL_MSG_OK, ZIL_MSG_OK,
"TEMP = %s. Must point to a subdirectory.",
p) ;
MessageBox->Control();
delete MessageBox ;
return(1);
}
}
#endif /* WIN32 */
}
p = getenv("TMP");
if ( p ) {
struct _stat Stat;
int rc = stat(p,&Stat);
if ( rc && errno == ENOENT ) {
printf("WARNING: TMP = %s which does not exist.\n",p);
ZAF_MESSAGE_WINDOW * MessageBox =
new ZAF_MESSAGE_WINDOW( "Error", "EXCLAMATION",
ZIL_MSG_OK, ZIL_MSG_OK,
"TMP = %s. Must point to an subdirectory that exists.",
p) ;
MessageBox->Control();
delete MessageBox ;
return(1);
}
if ( !(Stat.st_mode & _S_IFDIR) ) {
printf("WARNING: TMP = %s which is a file.\n",p);
ZAF_MESSAGE_WINDOW * MessageBox =
new ZAF_MESSAGE_WINDOW( "Error", "EXCLAMATION",
ZIL_MSG_OK, ZIL_MSG_OK,
"TMP = %s. Must point to an subdirectory not a file.",
p) ;
MessageBox->Control();
delete MessageBox ;
return(1);
}
#ifdef WIN32
if ( osverinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) {
if ( strlen(p) == 3 && p[1] == ':' && p[2] == '\\' ) {
printf("WARNING: TMP = %s\n",p);
ZAF_MESSAGE_WINDOW * MessageBox =
new ZAF_MESSAGE_WINDOW( "Error", "EXCLAMATION",
ZIL_MSG_OK, ZIL_MSG_OK,
"TMP = %s. Must point to a subdirectory.",
p) ;
MessageBox->Control();
delete MessageBox ;
return(1);
}
}
#endif /* WIN32 */
}
printf("Creating defaultStorage object for dialer.dat\n");
// Open general storage file which contains windows.
UI_WINDOW_OBJECT::defaultStorage = new ZIL_STORAGE_READ_ONLY("dialer.dat");
// Check to see if the default storage was allocated.
if (UI_WINDOW_OBJECT::defaultStorage->storageError)
{
delete UI_WINDOW_OBJECT::defaultStorage;
printf("Unable to allocate defaultStorage\n");
ZAF_MESSAGE_WINDOW * MessageBox =
new ZAF_MESSAGE_WINDOW( "Error", "EXCLAMATION",
ZIL_MSG_OK, ZIL_MSG_OK,
"Unable to allocate storage for dialer.dat") ;
MessageBox->Control();
delete MessageBox ;
return(-1);
}
if ( UI_WINDOW_OBJECT::errorSystem )
delete UI_WINDOW_OBJECT::errorSystem ;
printf("Adding ERROR_SYSTEM\n");
UI_WINDOW_OBJECT::errorSystem = new UI_ERROR_SYSTEM ;
// Create the service manager (level 0).
printf("Creating SERVICE_MANAGER\n");
_serviceManager = new ZAF_SERVICE_MANAGER;
// Create and add base services (level 1).
printf("Adding DIRECTORY_SERVICE\n");
*_serviceManager
+ new ZAF_DIRECTORY_SERVICE;
if ( UI_WINDOW_OBJECT::helpSystem )
delete UI_WINDOW_OBJECT::helpSystem ;
printf("Adding HELP_SYSTEM\n");
UI_WINDOW_OBJECT::helpSystem =
new UI_HELP_SYSTEM( "dialer.dat", windowManager, HELP_MENU ) ;
#ifdef WIN32
#ifndef NODIAL
printf("Checking TAPI\n");
if ((TapiAvail = cktapiinit(hInstance)) != 0) {
printf("TAPI available\n");
cktapiopen();
printf("TAPI Open\n");
}
#endif /* NODIAL */
#endif /* WIN32 */
printf("Creating connector\n");
connector = new K_CONNECTOR ;
printf("Connector created\n");
#ifdef WIN32
if ( argc == 4 && !strcmp(argv[1],"-k")) {
connector->_hwndNextConnect = (HWND) atoi(argv[2]);
connector->_dwNextConnectPid = atoi(argv[3]);
}
#endif
timer = new UID_TIMER( D_ON, 1000 ) ;
*eventManager + timer ;
UI_EVENT event( S_ADD_OBJECT );
event.windowObject = connector ;
timer->Event( event ) ;
// Add the control windows.
*windowManager + connector ;
windowManager->screenID = connector->screenID ;
#ifdef WIN32
#ifndef NODIAL
if (TapiAvail) {
hwndConsole = connector->screenID;
}
#endif
#endif
// Process user responses.
printf("Entering Control() loop\n");
UI_APPLICATION::Control();
#ifdef WIN32
#ifndef NODIAL
if ( TapiAvail ) {
printf("Closing TAPI\n");
cktapiclose();
}
#endif /* NODIAL */
#endif /* WIN32 */
// Clean up and return success.
delete UI_WINDOW_OBJECT::defaultStorage;
delete _serviceManager;
printf("Done\n");
return (0);
}