Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

946 lines
30 KiB

  1. /*===========================================================================*/
  2. /* Copyright (c) 1987 - 1988, Future Soft Engineering, Inc. */
  3. /* Houston, Texas */
  4. /*===========================================================================*/
  5. #define NOGDICAPMASKS TRUE
  6. #define NOVIRTUALKEYCODES TRUE
  7. #define NOICONS TRUE
  8. #define NOKEYSTATES TRUE
  9. #define NOSYSCOMMANDS TRUE
  10. #define NOATOM TRUE
  11. #define NOCLIPBOARD TRUE
  12. #define NODRAWTEXT TRUE
  13. #define NOMINMAX TRUE
  14. #define NOOPENFILE TRUE
  15. #define NOSCROLL TRUE
  16. #define NOHELP TRUE
  17. #define NOPROFILER TRUE
  18. #define NODEFERWINDOWPOS TRUE
  19. #define NOPEN TRUE
  20. #define NO_TASK_DEFINES TRUE
  21. #define NOLSTRING TRUE
  22. #define WIN31
  23. #include <stdlib.h> /* adding for _searchenv and exit crt -sdj*/
  24. #include <windows.h>
  25. #include <port1632.h>
  26. #include "dcrc.h"
  27. #include "dynacomm.h"
  28. #include "task.h"
  29. #include "video.h" /* mbbx 1.04: per jtfx 1.1 */
  30. #include <ctype.h>
  31. VOID NEAR PASCAL DestroyWindows()
  32. {
  33. if(hdbmyControls)
  34. DestroyWindow(hdbmyControls);
  35. if(hdbXferCtrls)
  36. DestroyWindow(hdbXferCtrls);
  37. if(hTermWnd)
  38. DestroyWindow(hTermWnd);
  39. }
  40. /*---------------------------------------------------------------------------*/
  41. /* WinMain() - entry point from Windows [mbb] */
  42. /*---------------------------------------------------------------------------*/
  43. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, INT cmdShow)
  44. {
  45. CHAR errmsg[115],caption[18];
  46. VOID (APIENTRY *lpfnRegisterPenApp)(WORD, BOOL) = NULL;
  47. // -sdj was unreferenced local var: DWORD tickCount;
  48. readDateTime(startTimer);
  49. trmParams.comDevRef = ITMNOCOM;
  50. if(!initConnectors(TRUE))
  51. return (FALSE);
  52. /* Added 02/2591 w-dougw check that all windows are created. */
  53. if(!initWindows(hInstance, hPrevInstance, cmdShow))
  54. {
  55. LoadString(hInstance,STR_ERRCAPTION,caption,sizeof(caption));
  56. LoadString(hInstance,STR_OUTOFMEMORY,errmsg,79);
  57. MessageBox(NULL,errmsg,caption,MB_ICONHAND|MB_SYSTEMMODAL);
  58. return(FALSE);
  59. }
  60. initDialogs();
  61. if(!setup())
  62. {
  63. LoadString(hInstance,STR_ERRCAPTION,caption,sizeof(caption));
  64. LoadString(hInstance,STR_OUTOFMEMORY,errmsg,79);
  65. MessageBox(NULL,errmsg,caption,MB_ICONHAND|MB_SYSTEMMODAL);
  66. return(FALSE);
  67. }
  68. DEBOUT("Calling: %s\n","readCmdLine()");
  69. readCmdLine(lpszCmdLine); /* mbbx 2.00 ... */
  70. DEBOUT("Outof: %s\n","readCmdLine()");
  71. DEBOUT("Calling: %s\n","PrintFileInit()");
  72. PrintFileInit(); /* jtfterm */
  73. DEBOUT("Outof: %s\n","PrintFileInit()");
  74. /* Register as a good little pen-windows app
  75. */
  76. /* NOTE**** have to confirm that this is the way to go GetSystemMet RC-sdj*/
  77. /* added typecasting of (HANDLE) to param 1 */
  78. if (lpfnRegisterPenApp = (VOID *)GetProcAddress(IntToPtr(GetSystemMetrics(SM_PENWINDOWS)),
  79. "RegisterPenApp"))
  80. (*lpfnRegisterPenApp)(1, TRUE);
  81. DEBOUT("Calling: %s\n","mainProcess()");
  82. mainProcess(); /* now load _WINMAIN segment */
  83. DEBOUT("Outof: %s\n","mainProcess()");
  84. /* Make sure to de-register if you register
  85. */
  86. if (lpfnRegisterPenApp)
  87. (*lpfnRegisterPenApp)(1, FALSE);
  88. PrintFileShutDown(); /* jtfterm */
  89. DestroyWindow(hdbXferCtrls); /* rjs swat */
  90. DestroyWindow(hdbmyControls); /* jtf 3.33 */
  91. DestroyWindow(hItWnd); /* rjs swat */
  92. freeItResources();
  93. exit((int)msg.wParam);
  94. /*ExitProcess((DWORD)msg.wParam); should this be used instead of exit()?-sdj*/
  95. }
  96. /* was
  97. BOOL registerIt(hInstance)
  98. HANDLE hInstance;
  99. */
  100. /*---------------------------------------------------------------------------*/
  101. /* initWndClass() - [mbb] */
  102. /*---------------------------------------------------------------------------*/
  103. BOOL initWndClass() /* mbbx 1.04 ... */
  104. {
  105. WNDCLASS wndClass;
  106. wndClass.style = CS_HREDRAW | CS_VREDRAW;
  107. wndClass.lpfnWndProc = DC_WndProc;
  108. wndClass.cbClsExtra = 0;
  109. wndClass.cbWndExtra = 0;
  110. wndClass.hInstance = hInst;
  111. wndClass.hIcon = (HICON) NULL;
  112. wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  113. wndClass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1); /* mbbx 2.00 ... */
  114. wndClass.lpszMenuName = (LPSTR) szAppName_private;
  115. wndClass.lpszClassName = (LPSTR) szAppName_private;
  116. if(!RegisterClass((LPWNDCLASS) &wndClass)) /* register DYNACOMM class */
  117. return(FALSE);
  118. wndClass.style = CS_DBLCLKS; /* jtf 3.21 | CS_HREDRAW | CS_VREDRAW; */
  119. wndClass.lpfnWndProc = TF_WndProc;
  120. wndClass.hIcon = (HICON) NULL;
  121. wndClass.hCursor = LoadCursor(NULL, IDC_IBEAM);
  122. wndClass.hbrBackground = (HBRUSH) NULL;
  123. wndClass.lpszMenuName = (LPSTR) NULL;
  124. wndClass.lpszClassName = (LPSTR) DC_WNDCLASS;
  125. if(!RegisterClass((LPWNDCLASS) &wndClass)) /* register TERMINAL class */
  126. return(FALSE);
  127. return(TRUE);
  128. }
  129. /*---------------------------------------------------------------------------*/
  130. /* initPort () - Initialize hTE text rectangles and init thePort */
  131. /* thePort is always 0 or an active DC of hTermWnd */
  132. /* portLocks is count of number of un'releasePort'ed getPort calls */
  133. extern BOOL insertionPoint;
  134. VOID initPort ()
  135. {
  136. insertionPoint = TRUE;
  137. thePort = 0;
  138. portLocks = 0;
  139. hTE.active = TRUE;
  140. hTE.selStart = hTE.selEnd = MAXROWCOL;
  141. /* Added 02/22/91 for win 3.1 common dialog interface */
  142. hDevNames = NULL;
  143. hDevMode = NULL;
  144. }
  145. /*---------------------------------------------------------------------------*/
  146. /* initIcon() */
  147. /*---------------------------------------------------------------------------*/
  148. VOID initIcon()
  149. {
  150. // -sdj was unreferenced var: CHAR temp[10];
  151. icon.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(ICO_DYNACOMM));
  152. icon.flash = FALSE;
  153. icon.dx = GetSystemMetrics(SM_CXICON)/16;
  154. icon.dy = GetSystemMetrics(SM_CYICON)/16;
  155. }
  156. /*---------------------------------------------------------------------------*/
  157. /* createWindows() - Determine tube size and create all Windows. */
  158. /*---------------------------------------------------------------------------*/
  159. BOOL createWindows(INT cmdShow)
  160. {
  161. INT ndx;
  162. // -sdj was unreferenced local var: HMENU hSysMenu;
  163. BYTE work[80]; // -sdj was unrefenced var: , work1[80], work2[80];
  164. LoadString(hInst, STR_APPNAME, (LPSTR) work, MINRESSTR);
  165. strcpy(work+strlen(work), " - ");
  166. LoadString(hInst, STR_TERMINAL, (LPSTR) work+strlen(work), MINRESSTR);
  167. //sdj: using the values from the registry instead of hardcoding it
  168. if(!(hItWnd = CreateWindow((LPSTR) szAppName_private,
  169. (LPSTR) work,
  170. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  171. WindowXPosition,
  172. WindowYPosition,
  173. WindowWidth,
  174. WindowHeight, // was hardcoded to: 10,10,400,400, win31:CW_USEDEFAULT, 0, CW_USEDEFAULT, 0
  175. (HWND) NULL,
  176. (HMENU) NULL,
  177. (HANDLE) hInst,
  178. (LPSTR) NULL)))
  179. return(FALSE);
  180. LoadString(hInst, STR_INI_MAXIMIZED, (LPSTR) work, MINRESSTR);
  181. if(!GetProfileInt((LPSTR) szAppName_private, (LPSTR) work, 0) ||
  182. (cmdShow == SW_SHOWMINNOACTIVE) || (cmdShow == SW_SHOWMINIMIZED) || (cmdShow == SW_MINIMIZE))
  183. {
  184. ShowWindow(hItWnd, cmdShow);
  185. }
  186. else
  187. ShowWindow(hItWnd, SW_SHOWMAXIMIZED);
  188. if(!(hdbmyControls = CreateDialog(hInst, getResId(IDDBMYCONTROLS),
  189. hItWnd, dbmyControls)))
  190. return(FALSE);
  191. for(ndx = 0; ndx < DCS_NUMFKEYS; ndx += 1) /* mbbx 2.00: moved from hidemyControls... */
  192. {
  193. fKeyHandles[ndx] = GetDlgItem(hdbmyControls, IDFK1 + ndx);
  194. DEBOUT("createWindows: fKeyHandles[]=%lx from GetDlgItem()\n",fKeyHandles[ndx]);
  195. }
  196. LoadString(hInst, STR_TERMINAL, (LPSTR) work, MINRESSTR);
  197. if(!(hTermWnd = CreateWindow((LPSTR) DC_WNDCLASS,
  198. (LPSTR) work,
  199. /* Removed WS_THICKFRAME jtf 3.21 */
  200. WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_CLIPSIBLINGS | CS_BYTEALIGNWINDOW,
  201. 0, 0, 0, 0,
  202. hItWnd,
  203. (HMENU) NULL,
  204. (HANDLE) hInst,
  205. (LPSTR) NULL)))
  206. return(FALSE);
  207. if(!(hdbXferCtrls = CreateDialog(hInst, getResId(IDDBXFERCTRLS),
  208. hTermWnd, dbmyControls)))
  209. {
  210. return(FALSE);
  211. }
  212. /* mbbx 1.04 */
  213. xferCtlStop = GetDlgItem(hdbXferCtrls, IDSTOP); /* mbbx 2.00: moved from hidemyControls()... */
  214. xferCtlPause = GetDlgItem(hdbXferCtrls, IDPAUSE);
  215. xferCtlScale = GetDlgItem(hdbXferCtrls, IDSCALE);
  216. showXferCtrls(0);
  217. }
  218. /*---------------------------------------------------------------------------*/
  219. /* sizeWindows() - */
  220. /*---------------------------------------------------------------------------*/
  221. VOID sizeWindows()
  222. {
  223. RECT fKeysRect;
  224. RECT ctrlsRect;
  225. RECT termRect;
  226. setDefaultFonts();
  227. GetWindowRect(hdbmyControls, &fKeysRect);
  228. GetWindowRect(fKeyHandles[0], &ctrlsRect); /* mbbx 2.00: fkeys... */
  229. MoveWindow(hdbmyControls, 0, fKeysRect.top, fKeysRect.right,
  230. fKeysHeight = ((ctrlsRect.bottom - ctrlsRect.top) * 2), FALSE);
  231. GetClientRect(hItWnd, &fKeysRect); /* mbbx 2.00: may not init maximized... */
  232. sizeFkeys(MAKELONG(fKeysRect.right, fKeysRect.bottom));
  233. GetWindowRect(hdbXferCtrls, &ctrlsRect); /* mbbx 1.04: fkeys... */
  234. ctrlsHeight = ctrlsRect.bottom - ctrlsRect.top;
  235. initChildSize(&termRect);
  236. MoveWindow(hTermWnd, 0, 0, termRect.right, termRect.bottom, FALSE); /* jtf 3.21 */
  237. }
  238. /*---------------------------------------------------------------------------*/
  239. /* initWindows() - */
  240. /*---------------------------------------------------------------------------*/
  241. BOOL initWindows(HANDLE hInstance, HANDLE hPrevInstance, INT cmdShow)
  242. {
  243. BYTE str[MINRESSTR];
  244. hInst = hInstance;
  245. /* Added 02/26/91 for window existence */
  246. hItWnd = NULL;
  247. hdbmyControls = NULL;
  248. hTermWnd = NULL;
  249. hdbXferCtrls = NULL;
  250. hEdit = NULL;
  251. fKeyHdl = NULL;
  252. LoadString(hInst, STR_APPNAME_PRIVATE, (LPSTR) szAppName_private, 20);
  253. LoadString(hInst, STR_APPNAME, (LPSTR) szAppName, 20);
  254. LoadString(hInst, STR_DEVELOPER, (LPSTR) szMessage, 80);
  255. LoadString(hInst, STR_NOMEMORY,(LPSTR)NoMemStr,sizeof(NoMemStr)); /* rjs msoft ??? */
  256. //sdj: lets try and see if the x,y,width,height are in the win.ini
  257. //sdj: if so use them and save the values in the global variables
  258. //sdj: so that these can be used by the createwindow call during init
  259. //sdj: and can be saved using getwindowrect just before the user exits
  260. //sdj: the terminal app.
  261. //sdj: defaults are 10,10,400,400. win31 had: CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
  262. LoadString(hInst, STR_INI_XPOSITION, (LPSTR) str, MINRESSTR);
  263. WindowXPosition = GetProfileInt((LPSTR) szAppName_private, (LPSTR) str, 10);
  264. LoadString(hInst, STR_INI_YPOSITION, (LPSTR) str, MINRESSTR);
  265. WindowYPosition = GetProfileInt((LPSTR) szAppName_private, (LPSTR) str, 10);
  266. LoadString(hInst, STR_INI_WIDTH, (LPSTR) str, MINRESSTR);
  267. WindowWidth = GetProfileInt((LPSTR) szAppName_private, (LPSTR) str, 400);
  268. LoadString(hInst, STR_INI_HEIGHT, (LPSTR) str, MINRESSTR);
  269. WindowHeight = GetProfileInt((LPSTR) szAppName_private, (LPSTR) str, 400);
  270. setDefaultAttrib(TRUE); /* mbbx 1.04: ...szAppName loaded */
  271. if(!hPrevInstance)
  272. {
  273. if(!initWndClass()) /* mbbx 1.04 ... */
  274. return(FALSE);
  275. }
  276. initPort();
  277. initIcon();
  278. theBrush = GetStockObject (WHITE_BRUSH);
  279. blackBrush = GetStockObject (BLACK_BRUSH);
  280. if(!createWindows(cmdShow))
  281. return(FALSE);
  282. sizeWindows();
  283. maxScreenLine = MAXSCREENLINE; /* rjs moved from size windows */
  284. hMenu = GetMenu(hItWnd);
  285. return(TRUE);
  286. }
  287. /*---------------------------------------------------------------------------*/
  288. /* initDialogs() - Do all dialogbox initialization. [scf] */
  289. /*---------------------------------------------------------------------------*/
  290. VOID initDialogs() /* mbbx: remove ALL of these... */
  291. {
  292. }
  293. /*---------------------------------------------------------------------------*/
  294. /* dbPortInit() - [mbb] */
  295. /*---------------------------------------------------------------------------*/
  296. INT_PTR APIENTRY dbPortInit(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  297. {
  298. #ifdef WIN32
  299. WORD temp_wParam;
  300. #endif
  301. switch(message)
  302. {
  303. case WM_INITDIALOG:
  304. initDlgPos(hDlg);
  305. initComDevSelect(hDlg, ITMCONNECTOR, TRUE);
  306. return(TRUE);
  307. case WM_COMMAND:
  308. switch(GET_WM_COMMAND_ID(wParam, lParam))
  309. {
  310. case IDOK:
  311. break;
  312. case ITMCONNECTOR:
  313. if(GET_WM_COMMAND_CMD(wParam, lParam) == LBN_DBLCLK)
  314. break;
  315. return(TRUE);
  316. }
  317. break;
  318. default:
  319. return(FALSE);
  320. }
  321. trmParams.comPortRef = getComDevSelect(hDlg, ITMCONNECTOR, &trmParams.newDevRef);
  322. trmParams.fResetDevice = TRUE;
  323. #ifdef WIN32
  324. /* code in next block passes address of wParam to function*/
  325. /* so we pass temp variable instead, since we need extract ID from wParam under WIN32*/
  326. temp_wParam = GET_WM_COMMAND_ID(wParam, lParam);
  327. #endif
  328. #ifdef ORGCODE
  329. trmParams.comPortRef = getComDevSelect(hDlg, ITMCONNECTOR, (BYTE *) &wParam);
  330. #else
  331. trmParams.comPortRef = getComDevSelect(hDlg, ITMCONNECTOR, (BYTE *) &temp_wParam);
  332. #endif
  333. resetSerial(&trmParams, TRUE, TRUE, FALSE); /* slc swat */
  334. if(trmParams.comDevRef != trmParams.newDevRef)
  335. {
  336. exitSerial();
  337. return(TRUE);
  338. }
  339. exitSerial();
  340. #ifdef ORGCODE
  341. EndDialog(hDlg, (INT) getComDevSelect(hDlg, ITMCONNECTOR, (BYTE *) &wParam));
  342. #else
  343. if (!(getComDevSelect(hDlg, ITMCONNECTOR, (BYTE *) &temp_wParam)))
  344. {
  345. EndDialog(hDlg,TRUE);
  346. }
  347. else{
  348. EndDialog(hDlg, (INT) getComDevSelect(hDlg, ITMCONNECTOR, (BYTE *) &temp_wParam));
  349. }
  350. #endif
  351. return(TRUE);
  352. }
  353. /*---------------------------------------------------------------------------*/
  354. /* setProfileExtent() - [mbb] */
  355. /*---------------------------------------------------------------------------*/
  356. /* mbbx: 1.01 - moved from itutil1.c */
  357. BOOL NEAR setProfileExtent(BYTE *section, BYTE *extent)
  358. {
  359. BOOL setProfileExtent = FALSE;
  360. BYTE str[80];
  361. BYTE temp[80];
  362. if(!GetProfileString((LPSTR) section, (LPSTR) extent, (LPSTR) NULL_STR, (LPSTR) temp, 80))
  363. {
  364. strcpy(temp, extent);
  365. AnsiLower((LPSTR) temp);
  366. sprintf(str, "%s.exe ^.%s", szAppName_private, temp);
  367. AnsiLower((LPSTR) str);
  368. WriteProfileString((LPSTR) section, (LPSTR) temp, (LPSTR) str);
  369. setProfileExtent = TRUE;
  370. }
  371. return(setProfileExtent);
  372. }
  373. /*---------------------------------------------------------------------------*/
  374. /* initFileDocData() - [mbb] */
  375. /*---------------------------------------------------------------------------*/
  376. BOOL NEAR initFileDocData(FILEDOCTYPE fileType, WORD strResID,BYTE *fileExt,BYTE *szSection) /* mbbx 2.00 ... */
  377. {
  378. BYTE work1[MINRESSTR], work2[80];
  379. LoadString(hInst, strResID, (LPSTR) work1, MINRESSTR);
  380. GetProfileString((LPSTR) szAppName_private, (LPSTR) work1, (LPSTR) NULL_STR, (LPSTR) work2, 80);
  381. getDataPath(fileType, fileDocData[fileType].filePath, work2);
  382. strcpy(fileDocData[fileType].fileExt, fileExt);
  383. if(!getFileType(work2, fileDocData[fileType].fileExt))
  384. strcpy(work2, fileDocData[fileType].fileExt);
  385. strcpy(fileDocData[fileType].fileName, fileDocData[fileType].fileExt+1);
  386. if(work2[strlen(work2)-1] != '*')
  387. return(setProfileExtent(szSection, fileDocData[fileType].fileExt+3));
  388. return(FALSE);
  389. }
  390. /*---------------------------------------------------------------------------*/
  391. /* initProfileData() - [mbb] */
  392. /*---------------------------------------------------------------------------*/
  393. #define DEFBUFFERLINES 100 /* mbbx 1.10... */
  394. VOID initProfileData() /* mbbx: 1.01 ... */
  395. {
  396. BYTE str[MINRESSTR], str2[MINRESSTR], portName[16];
  397. INT ndx;
  398. // -sdj eas unreferenced local var: FARPROC lpdbPortInit;
  399. BOOL notify;
  400. LoadString(hInst, STR_INI_PORT, (LPSTR) str, MINRESSTR);
  401. if(!GetProfileString((LPSTR) szAppName_private, (LPSTR) str, (LPSTR) NULL_STR, (LPSTR) portName, 5))
  402. {
  403. trmParams.comDevRef = ITMNOCOM; /* jtf 3.33 */
  404. trmParams.speed = 1200; /* jtf 3.33 */
  405. trmParams.dataBits = ITMDATA8; /* jtf 3.33 */
  406. trmParams.stopBits = ITMSTOP1; /* jtf 3.33 */
  407. trmParams.parity = ITMNOPARITY; /* jtf 3.33 */
  408. if((ndx = doSettings(IDDBPORTINIT, dbPortInit)) != -1) /* mbbx 2.01.10 ... */
  409. {
  410. LoadString(hInst, (ndx > 0) ? STR_COM : STR_COM_CONNECT, (LPSTR) str2, MINRESSTR);
  411. sprintf(portName, str2, ndx);
  412. WriteProfileString((LPSTR) szAppName_private, (LPSTR) str, (LPSTR) portName);
  413. }
  414. }
  415. LoadString(hInst, STR_INI_SWAP, (LPSTR) str, MINRESSTR);
  416. if((ndx = GetProfileInt((LPSTR) szAppName_private, (LPSTR) str, 0)) > 0)
  417. *taskState.string = (BYTE)sprintf(taskState.string+1, "%d", SetSwapAreaSize(ndx));
  418. LoadString(hInst, STR_INI_INTL, (LPSTR) str, MINRESSTR);
  419. LoadString(hInst, STR_INI_IDATE, (LPSTR) str2, MINRESSTR);
  420. intlData.iDate = GetProfileInt((LPSTR) str, (LPSTR) str2, 0);
  421. LoadString(hInst, STR_INI_SDATE, (LPSTR) str2, MINRESSTR);
  422. GetProfileString((LPSTR) str, (LPSTR) str2, (LPSTR) "/", (LPSTR) intlData.sDate, 2);
  423. LoadString(hInst, STR_INI_ITIME, (LPSTR) str2, MINRESSTR);
  424. intlData.iTime = GetProfileInt((LPSTR) str, (LPSTR) str2, 0);
  425. LoadString(hInst, STR_INI_STIME, (LPSTR) str2, MINRESSTR);
  426. GetProfileString((LPSTR) str, (LPSTR) str2, (LPSTR) ":", (LPSTR) intlData.sTime, 2);
  427. LoadString(hInst, STR_INI_S1159, (LPSTR) str2, MINRESSTR);
  428. GetProfileString((LPSTR) str, (LPSTR) str2, (LPSTR) "AM", (LPSTR) intlData.s1159, 4);
  429. LoadString(hInst, STR_INI_S2359, (LPSTR) str2, MINRESSTR);
  430. GetProfileString((LPSTR) str, (LPSTR) str2, (LPSTR) "PM", (LPSTR) intlData.s2359, 4);
  431. LoadString(hInst, STR_INI_EXTENSIONS, (LPSTR) str, MINRESSTR);
  432. notify = initFileDocData(FILE_NDX_SETTINGS, STR_INI_SETTINGS, SETTINGS_FILE_TYPE, str);
  433. if(initFileDocData(FILE_NDX_TASK, STR_INI_TASK, TASK_FILE_TYPE, str))
  434. notify = TRUE;
  435. if(initFileDocData(FILE_NDX_SCRIPT, STR_INI_SCRIPT, SCRIPT_FILE_TYPE, str))
  436. notify = TRUE;
  437. if(initFileDocData(FILE_NDX_MEMO, STR_INI_MEMO, MEMO_FILE_TYPE, str))
  438. notify = TRUE;
  439. if(initFileDocData(FILE_NDX_DATA, STR_INI_DATA, DATA_FILE_TYPE, str))
  440. notify = TRUE;
  441. if(notify)
  442. #ifdef ORGCODE
  443. SendMessage(0xFFFF, WM_WININICHANGE, 0, (LONG) ((LPSTR) str));
  444. #else
  445. SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, (LPARAM) str);
  446. #endif
  447. }
  448. // sdj: added this code to get the list of comm ports which the serial driver
  449. // sdj: recognized while loading the system.
  450. // sdj: if this number of ports is > 9 then it is set to 9
  451. // sdj: and if this info cannot be retrieved this this is set to 4 as before
  452. void GetNumCommPortsInSystem(LPBYTE pMaxCom)
  453. {
  454. int i,j, nEntries;
  455. DWORD dwSize, dwBufz;
  456. DWORD dwType;
  457. HKEY hkey;
  458. char szSerial[40];
  459. char szCom[40];
  460. char szCom2[40];
  461. char szFormat[200];
  462. BYTE tmp1[TMPNSTR+1];
  463. BYTE tmp2[TMPNSTR+1];
  464. // NT Registry keys to find COM port to Serial Device mapping
  465. char szRegSerialMap[] = "Hardware\\DeviceMap\\SerialComm";
  466. //////////////////////////////////////////////////////////////////////
  467. // Get list of valid COM ports from DEVICEMAP in registry
  468. //////////////////////////////////////////////////////////////////////
  469. *pMaxCom = 0;
  470. i = 0;
  471. if (!RegOpenKeyEx (HKEY_LOCAL_MACHINE, szRegSerialMap,
  472. 0L, KEY_READ, &hkey))
  473. {
  474. dwBufz = sizeof(szSerial);
  475. dwSize = sizeof(szCom);
  476. nEntries = i = 0;
  477. while (!RegEnumValue (hkey, i++, szSerial, &dwBufz,
  478. NULL, &dwType, szCom, &dwSize))
  479. {
  480. if (dwType != REG_SZ)
  481. continue;
  482. ++nEntries;
  483. // arComNumAndName[nEntries].Index = nEntries;
  484. // strcpy(arComNumAndName[nEntries].PortName,szCom);
  485. //
  486. dwSize = sizeof(szCom);
  487. dwBufz = sizeof(szSerial);
  488. if (nEntries > 19) break; // lets not bother with >= 20 entries
  489. }
  490. RegCloseKey (hkey);
  491. *pMaxCom = (BYTE)nEntries;
  492. arComNumAndName[0].Index = (BYTE)nEntries;
  493. }
  494. else
  495. {
  496. // sdj: could not find the list of comm ports in the registry, so
  497. // sdj: stick with the original terminal hardcoded value of com1-4
  498. LoadString(hInst, STR_NOCOMMPORTS, (LPSTR) tmp1, TMPNSTR); /* mbbx 1.00 */
  499. LoadString(hInst, STR_ERRCAPTION, (LPSTR) tmp2, TMPNSTR);
  500. MessageBox(NULL, (LPSTR) tmp1, (LPSTR)tmp2, MB_OK | MB_APPLMODAL);
  501. *pMaxCom = 0;
  502. }
  503. //sdj: if maxcomm is > 9 set it to 9
  504. //
  505. if (*pMaxCom > 9) *pMaxCom = 9;
  506. //
  507. //
  508. strcpy(szCom,"COM%d");
  509. for (i=1,j=1; i<= 9; i++)
  510. {
  511. sprintf(szCom2,szCom,i);
  512. if (QueryDosDevice(szCom2,szFormat,400))
  513. {
  514. arComNumAndName[j].Index = (BYTE)j;
  515. strcpy(arComNumAndName[j].PortName,szCom2);
  516. j++;
  517. }
  518. }
  519. }
  520. /*---------------------------------------------------------------------------*/
  521. /* setup() - Reset all varibles, read settings file & emulation. [scf] */
  522. /*---------------------------------------------------------------------------*/
  523. BOOL setup() /* mbbx 2.00: no cmd line... */
  524. {
  525. // -sdj was unreferenced local var: BYTE path[PATHLEN+1];
  526. // -sdj was unreferenced local var: BYTE tmp1[TMPNSTR+1];
  527. // -sdj was unreferenced local var: INT ndx;
  528. SetRect (&cursorRect, 0, 0, 0, 0);
  529. vScrollShowing = TRUE;
  530. serNdx = 0;
  531. cursorTick = -1l;
  532. cursBlinkOn = FALSE;
  533. cursorOn = TRUE;
  534. activCursor = 1;
  535. prtFlag = FALSE;
  536. useScrap = FALSE;
  537. copiedTable = FALSE;
  538. *fKeyStr = 0; /* mbbx 2.00: fKeySeq... */
  539. fKeyNdx = 1;
  540. scrapSeq = FALSE;
  541. xferFlag = XFRNONE;
  542. xferPaused = FALSE;
  543. xferBreak = FALSE; /* mbbx 2.00: xfer ctrls */
  544. xferEndTimer = 0;
  545. xferWaitEcho = FALSE;
  546. xferViewPause = 0; /* mbbx: auto line count */
  547. xferViewLine = 0;
  548. xferPSChar = 0; /* mbbx 1.02: packet switching */
  549. *strRXErrors =
  550. *strRXBytes =
  551. *strRXFname =
  552. *strRXFork = 0;
  553. taskInit();
  554. keyMapInit(); /* mbbx 1.04: keymap */
  555. debugFlg = FALSE; /* how does this get enabled??? */
  556. mdmOnLine = FALSE;
  557. dialing = FALSE;
  558. answerMode = FALSE;
  559. protectMode = FALSE; /* mbbx: emulation state */
  560. KER_getflag = FALSE;
  561. gotCommEvent = TRUE;
  562. sPort = NULL;
  563. bPortIsGood = FALSE; /* it is not yet opened */
  564. //-sdj for telnet-quit processing
  565. bPortDisconnected = TRUE; /* this will ensure that reads dont
  566. occur before resetserial inits this to
  567. FALSE, it will be set to true by checkcommevent
  568. if for some reason, wait(getlasterror) is not
  569. IO_PENDING */
  570. bgOutStandingWrite = FALSE; /* slc swat */
  571. //MaxComPortNumberInMenu = 5;
  572. /* this will get set to proper
  573. value when the win.ini is
  574. looked at for COMn entries,
  575. but during init, this needs
  576. to be set to > COM1 -sdj:04/21/92 */
  577. GetNumCommPortsInSystem(&MaxComPortNumberInMenu);
  578. if((hemulKeyInfo = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) SIZEOFEMULKEYINFO)) == NULL)
  579. return(FALSE);
  580. initProfileData(); /* mbbx: 1.01 */
  581. hTE.hText = NULL;
  582. DEBOUT("Calling: %s\n","setDefaults()");
  583. setDefaults();
  584. DEBOUT("Outof: %s\n","setDefaults()");
  585. DEBOUT("Calling: %s\n","setFKeyLevel()");
  586. setFKeyLevel(1, FALSE); /* jtfterm */
  587. DEBOUT("Outof: %s\n","setFKeyLevel()");
  588. DEBOUT("Calling: %s\n","termInitSetup()");
  589. termInitSetup(NULL);
  590. DEBOUT("Outof: %s\n","termInitSetup()");
  591. strcpy(szMessage, szAppName);
  592. return(TRUE);
  593. }
  594. /*---------------------------------------------------------------------------*/
  595. /* readCmdLine() - [mbb] */
  596. /*---------------------------------------------------------------------------*/
  597. BOOL fileDocExist(WORD fileType, BYTE *filePath)
  598. {
  599. BOOL fileDocExist;
  600. BYTE savePath[PATHLEN], testPath[PATHLEN];
  601. BYTE OEMname[STR255];
  602. strcpy(savePath, filePath);
  603. getDataPath(fileType, testPath, savePath);
  604. strcat(testPath, savePath);
  605. // JYF -- replace below lines with followin if()
  606. // to remove the use of AnsiToOem()
  607. //
  608. //AnsiToOem((LPSTR) testPath, (LPSTR) OEMname); /* jtf 3.20 */
  609. //if(fileDocExist = fileExist(OEMname)) /* jtf 3.20 */
  610. if (fileDocExist = fileExist(testPath))
  611. strcpy(filePath, testPath);
  612. return(fileDocExist);
  613. }
  614. WORD NEAR getFileDocType(BYTE *filePath)
  615. {
  616. BYTE fileExt[16];
  617. WORD fileType;
  618. *fileExt = 0;
  619. if(!getFileType(filePath, fileExt))
  620. {
  621. forceExtension(filePath, NO_FILE_TYPE+2, FALSE);
  622. if(fileDocExist(FILE_NDX_DATA, filePath) || fileDocExist(FILE_NDX_SETTINGS, filePath))
  623. return(FILE_NDX_SETTINGS); /* jtf 3.11 */
  624. }
  625. for(fileType = FILE_NDX_SETTINGS; fileType <= FILE_NDX_MEMO; fileType += 1)
  626. {
  627. if(*fileExt == 0)
  628. forceExtension(filePath, fileDocData[fileType].fileExt+2, TRUE);
  629. else if((fileType < FILE_NDX_MEMO) && (strcmp(fileDocData[fileType].fileExt+2, fileExt) != 0))
  630. continue;
  631. if(fileDocExist(FILE_NDX_DATA, filePath) || fileDocExist(fileType, filePath) || (*fileExt != 0))
  632. return(fileType);
  633. }
  634. return(FILE_NDX_DATA);
  635. }
  636. BOOL NEAR initTermFile(BYTE *filePath)
  637. {
  638. getDataPath(FILE_NDX_SETTINGS, fileDocData[FILE_NDX_SETTINGS].filePath, filePath);
  639. LoadString(hInst, STR_TERMINAL, (LPSTR) termData.title, MINRESSTR);
  640. /* mbbx 2.00: no forced extents... */
  641. return(termFile(fileDocData[FILE_NDX_SETTINGS].filePath, filePath,
  642. fileDocData[FILE_NDX_SETTINGS].fileExt, termData.title, TF_DEFTITLE));
  643. }
  644. VOID NEAR readCmdLine(LPSTR lpszCmdLine)
  645. {
  646. INT ndx, ndx2;
  647. BYTE filePath[PATHLEN];
  648. BYTE tmpFilePath[PATHLEN];
  649. INT nEditWnd = 0;
  650. BYTE OEMname[STR255]; /* jtf 3.20 */
  651. BYTE work[STR255]; /* jtf 3.28 */
  652. BYTE work1[STR255]; /* jtf 3.28 */
  653. INT testFlag;
  654. saveFileType = FILE_NDX_SETTINGS; /* jtf 3.11 */
  655. AnsiUpper(lpszCmdLine);
  656. for(ndx = 0; lpszCmdLine[ndx] != 0; ) /* mbbx 2.00 ... */
  657. {
  658. while(lpszCmdLine[ndx] == 0x20)
  659. ndx++;
  660. if(lpszCmdLine[ndx] == 0)
  661. break;
  662. for(ndx2 = 0; (filePath[ndx2] = lpszCmdLine[ndx]) != 0; ndx2 += 1)
  663. {
  664. ndx += 1;
  665. if(filePath[ndx2] == 0x20)
  666. {
  667. filePath[ndx2] = 0;
  668. break;
  669. }
  670. }
  671. strcpy(work1,filePath);
  672. if(!activTerm)
  673. initTermFile(filePath);
  674. }
  675. ndx = lstrlen(lpszCmdLine);
  676. while(ndx)
  677. {
  678. ndx--;
  679. if(isspace(lpszCmdLine[ndx]))
  680. lpszCmdLine[ndx] = 0x00;
  681. }
  682. if ((!activTerm) && (lstrlen(lpszCmdLine) > 0))
  683. {
  684. LoadString(hInst, STRERRNOFILE, (LPSTR) work, STR255-1); /* jtf 3.15 */
  685. strcpy(filePath,work1);
  686. forceExtension(filePath, SETTINGS_FILE_TYPE+2, FALSE);
  687. sprintf(work1, work, filePath);
  688. testFlag = MessageBox(GetActiveWindow(), (LPSTR) work1, (LPSTR) szAppName, MB_OKCANCEL);
  689. if (testFlag==IDOK)
  690. {
  691. if (filePath[1]==':')
  692. {
  693. filePath[0]='A';
  694. }
  695. else
  696. {
  697. strcpy(work,filePath);
  698. strcpy(filePath,"A:");
  699. strcpy(filePath+2,work);
  700. }
  701. initTermFile(filePath);
  702. }
  703. }
  704. if(!activTerm) /* mbbx 2.00: term init... */
  705. {
  706. LoadString(hInst, STR_AUTOLOAD, (LPSTR) filePath, PATHLEN); /* jtf 3.17 */
  707. // JYF -- replace below two lines with the following if()
  708. // to remove the use of AnsiToOem()
  709. //
  710. //AnsiToOem((LPSTR) filePath, (LPSTR) OEMname); /* jtf 3.20 */
  711. //if (fileExist(OEMname)) /* jtf 3.20 */
  712. if (fileExist(filePath))
  713. initTermFile(filePath);
  714. else
  715. {
  716. _searchenv( filePath, "PATH", tmpFilePath );
  717. if(strlen(tmpFilePath)>0)
  718. initTermFile(tmpFilePath);
  719. }
  720. if(!activTerm)
  721. {
  722. if((nEditWnd -= 1) >= 0)
  723. termData.flags |= TF_HIDE;
  724. else
  725. saveFileType = FILE_NDX_SETTINGS;
  726. activTerm = TRUE;
  727. resetSerial(&trmParams, TRUE, TRUE,0);
  728. if(!(termData.flags & TF_HIDE))
  729. showTerminal(TRUE, TRUE);
  730. }
  731. }
  732. if(!IsIconic(hItWnd)) /* rjs bugs 015 */
  733. sizeTerm(0L); /* jtf 3.21 */
  734. }
  735. /*---------------------------------------------------------------------------*/
  736. /* freeItResources()- Free up all windows resource b/4 back to DOS executive.*/
  737. /* Internal house keeping. Note: Close that serial port. */
  738. /*---------------------------------------------------------------------------*/
  739. VOID freeItResources()
  740. {
  741. // -sdj was unreferenced local var: INT ndx;
  742. exitSerial();
  743. keyMapCancel(); /* mbbx 1.04: keymap */
  744. DeleteObject(hTE.hFont);
  745. clearFontCache(); /* mbbx 2.00: redundant code... */
  746. GlobalFree(hTE.hText);
  747. GlobalFree(hemulKeyInfo);
  748. }