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.

806 lines
26 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 <windows.h>
  24. #include <port1632.h>
  25. #include "dcrc.h"
  26. #include "dynacomm.h"
  27. #include "task.h"
  28. #include "video.h"
  29. #include <stdlib.h> /* adding for _searchenv and exit crt -sdj*/
  30. VOID NEAR PASCAL DestroyWindows()
  31. {
  32. if(hdbmyControls)
  33. DestroyWindow(hdbmyControls);
  34. if(hdbXferCtrls)
  35. DestroyWindow(hdbXferCtrls);
  36. if(hTermWnd)
  37. DestroyWindow(hTermWnd);
  38. }
  39. /*---------------------------------------------------------------------------*/
  40. /* WinMain() - entry point from Windows [mbb] */
  41. /*---------------------------------------------------------------------------*/
  42. int APIENTRY WinMain(HANDLE hInst, HANDLE hPrevInst, LPSTR lpCmdLine, INT nCmdShow)
  43. {
  44. CHAR errmsg[115],caption[18];
  45. VOID (APIENTRY *lpfnRegisterPenApp)(WORD, BOOL) = NULL;
  46. readDateTime(startTimer);
  47. trmParams.comDevRef = ITMNOCOM;
  48. if(!initConnectors(TRUE))
  49. return (FALSE);
  50. /* Added 02/2591 w-dougw check that all windows are created. */
  51. if(!initWindows(hInstance, hPrevInstance, cmdShow))
  52. {
  53. LoadString(hInstance,STR_ERRCAPTION,caption,sizeof(caption));
  54. LoadString(hInstance,STR_OUTOFMEMORY,errmsg,79);
  55. MessageBox(NULL,errmsg,caption,MB_ICONHAND|MB_SYSTEMMODAL);
  56. return(FALSE);
  57. }
  58. initDialogs();
  59. if(!setup())
  60. {
  61. LoadString(hInstance,STR_ERRCAPTION,caption,sizeof(caption));
  62. LoadString(hInstance,STR_OUTOFMEMORY,errmsg,79);
  63. MessageBox(NULL,errmsg,caption,MB_ICONHAND|MB_SYSTEMMODAL);
  64. return(FALSE);
  65. }
  66. DEBOUT("Calling: %s\n","readCmdLine()");
  67. readCmdLine(lpszCmdLine);
  68. DEBOUT("Outof: %s\n","readCmdLine()");
  69. DEBOUT("Calling: %s\n","PrintFileInit()");
  70. PrintFileInit(); /* jtfterm */
  71. DEBOUT("Outof: %s\n","PrintFileInit()");
  72. /* Register as a good little pen-windows app
  73. */
  74. /* NOTE**** have to confirm that this is the way to go GetSystemMet RC-sdj*/
  75. /* added typecasting of (HANDLE) to param 1 */
  76. if (lpfnRegisterPenApp = GetProcAddress((HANDLE)GetSystemMetrics(SM_PENWINDOWS),
  77. "RegisterPenApp"))
  78. (*lpfnRegisterPenApp)(1, TRUE);
  79. DEBOUT("Calling: %s\n","mainProcess()");
  80. mainProcess(); /* now load _WINMAIN segment */
  81. DEBOUT("Outof: %s\n","mainProcess()");
  82. /* Make sure to de-register if you register
  83. */
  84. if (lpfnRegisterPenApp)
  85. (*lpfnRegisterPenApp)(1, FALSE);
  86. PrintFileShutDown(); /* jtfterm */
  87. DestroyWindow(hdbXferCtrls); /* rjs swat */
  88. DestroyWindow(hdbmyControls); /* jtf 3.33 */
  89. DestroyWindow(hItWnd); /* rjs swat */
  90. freeItResources();
  91. exit(msg.wParam);
  92. // ExitProcess((DWORD)msg.wParam); should this be used instead of exit()?-sdj
  93. }
  94. /*---------------------------------------------------------------------------*/
  95. /* initWndClass() - [mbb] */
  96. /*---------------------------------------------------------------------------*/
  97. BOOL initWndClass()
  98. {
  99. WNDCLASS wndClass;
  100. wndClass.style = CS_HREDRAW | CS_VREDRAW;
  101. wndClass.lpfnWndProc = DC_WndProc;
  102. wndClass.cbClsExtra = 0;
  103. wndClass.cbWndExtra = 0;
  104. wndClass.hInstance = hInst;
  105. wndClass.hIcon = (HICON) NULL;
  106. wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  107. wndClass.hbrBackground = (HBRUSH)(COLOR_BACKGROUND+1);
  108. wndClass.lpszMenuName = (LPSTR) szAppName_private;
  109. wndClass.lpszClassName = (LPSTR) szAppName_private;
  110. if(!RegisterClass((LPWNDCLASS) &wndClass)) /* register DYNACOMM class */
  111. return(FALSE);
  112. wndClass.style = CS_DBLCLKS; /* jtf 3.21 | CS_HREDRAW | CS_VREDRAW; */
  113. wndClass.lpfnWndProc = TF_WndProc;
  114. wndClass.hIcon = (HICON) NULL;
  115. wndClass.hCursor = LoadCursor(NULL, IDC_IBEAM);
  116. wndClass.hbrBackground = (HBRUSH) NULL;
  117. wndClass.lpszMenuName = (LPSTR) NULL;
  118. wndClass.lpszClassName = (LPSTR) DC_WNDCLASS;
  119. if(!RegisterClass((LPWNDCLASS) &wndClass)) /* register TERMINAL class */
  120. return(FALSE);
  121. return(TRUE);
  122. }
  123. /*---------------------------------------------------------------------------*/
  124. /* initPort () - Initialize hTE text rectangles and init thePort */
  125. /* thePort is always 0 or an active DC of hTermWnd */
  126. /* portLocks is count of number of un'releasePort'ed getPort calls */
  127. extern BOOL insertionPoint;
  128. VOID initPort ()
  129. {
  130. insertionPoint = TRUE;
  131. thePort = 0;
  132. portLocks = 0;
  133. hTE.active = TRUE;
  134. hTE.selStart = hTE.selEnd = MAXROWCOL;
  135. /* Added 02/22/91 for win 3.1 common dialog interface */
  136. hDevNames = NULL;
  137. hDevMode = NULL;
  138. }
  139. /*---------------------------------------------------------------------------*/
  140. /* initIcon() */
  141. /*---------------------------------------------------------------------------*/
  142. VOID APIENTRY nextFlash();
  143. VOID initIcon()
  144. {
  145. CHAR temp[10];
  146. icon.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(ICO_DYNACOMM));
  147. icon.flash = FALSE;
  148. icon.dx = GetSystemMetrics(SM_CXICON)/16;
  149. icon.dy = GetSystemMetrics(SM_CYICON)/16;
  150. }
  151. /*---------------------------------------------------------------------------*/
  152. /* createWindows() - Determine tube size and create all Windows. */
  153. /*---------------------------------------------------------------------------*/
  154. BOOL createWindows(cmdShow)
  155. INT cmdShow;
  156. {
  157. INT ndx;
  158. HMENU hSysMenu;
  159. BYTE work[80], work1[80], work2[80];
  160. LoadString(hInst, STR_APPNAME, (LPSTR) work, MINRESSTR);
  161. strcpy(work+strlen(work), " - ");
  162. LoadString(hInst, STR_TERMINAL, (LPSTR) work+strlen(work), MINRESSTR);
  163. if(!(hItWnd = CreateWindow((LPSTR) szAppName_private,
  164. (LPSTR) work,
  165. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  166. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
  167. (HWND) NULL,
  168. (HMENU) NULL,
  169. (HANDLE) hInst,
  170. (LPSTR) NULL)))
  171. return(FALSE);
  172. LoadString(hInst, STR_INI_MAXIMIZED, (LPSTR) work, MINRESSTR);
  173. if(!GetProfileInt((LPSTR) szAppName_private, (LPSTR) work, 0) ||
  174. (cmdShow == SW_SHOWMINNOACTIVE) || (cmdShow == SW_SHOWMINIMIZED) || (cmdShow == SW_MINIMIZE))
  175. {
  176. ShowWindow(hItWnd, cmdShow);
  177. }
  178. else
  179. ShowWindow(hItWnd, SW_SHOWMAXIMIZED);
  180. if(!(hdbmyControls = CreateDialog(hInst, getResId(IDDBMYCONTROLS),
  181. hItWnd, dbmyControls)))
  182. {
  183. return(FALSE);
  184. }
  185. for(ndx = 0; ndx < DCS_NUMFKEYS; ndx += 1) /* mbbx 2.00: moved from hidemyControls... */
  186. {
  187. fKeyHandles[ndx] = GetDlgItem(hdbmyControls, IDFK1 + ndx);
  188. DEBOUT("createWindows: fKeyHandles[]=%lx from GetDlgItem()\n",fKeyHandles[ndx]);
  189. }
  190. LoadString(hInst, STR_TERMINAL, (LPSTR) work, MINRESSTR);
  191. if(!(hTermWnd = CreateWindow((LPSTR) DC_WNDCLASS,
  192. (LPSTR) work,
  193. /* Removed WS_THICKFRAME jtf 3.21 */
  194. WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_CLIPSIBLINGS | CS_BYTEALIGNWINDOW,
  195. 0, 0, 0, 0,
  196. hItWnd,
  197. (HMENU) NULL,
  198. (HANDLE) hInst,
  199. (LPSTR) NULL)))
  200. return(FALSE);
  201. /* jtf 3.33 hSysMenu = GetSystemMenu(hTermWnd, FALSE);
  202. for(ndx = GetMenuItemCount(hSysMenu)-1; ndx >= 0; ndx -= 1)
  203. {
  204. if(GetMenuString(hSysMenu, ndx, (LPSTR) work, 80, MF_BYPOSITION))
  205. {
  206. sscanf(work, "%s %s", work1, work2);
  207. sprintf(work, "%s\t xxxxCtrl+%s", work1, work2+4);
  208. ChangeMenu(hSysMenu, ndx, (LPSTR) work, GetMenuItemID(hSysMenu, ndx),
  209. MF_CHANGE | MF_BYPOSITION | GetMenuState(hSysMenu, ndx, MF_BYPOSITION));
  210. }
  211. } */
  212. if(!(hdbXferCtrls = CreateDialog(hInst, getResId(IDDBXFERCTRLS),
  213. hTermWnd, dbmyControls)))
  214. return(FALSE);
  215. /* mbbx 1.04 */
  216. xferCtlStop = GetDlgItem(hdbXferCtrls, IDSTOP); /* mbbx 2.00: moved from hidemyControls()... */
  217. xferCtlPause = GetDlgItem(hdbXferCtrls, IDPAUSE);
  218. xferCtlScale = GetDlgItem(hdbXferCtrls, IDSCALE);
  219. showXferCtrls(NULL);
  220. }
  221. /*---------------------------------------------------------------------------*/
  222. /* sizeWindows() - */
  223. /*---------------------------------------------------------------------------*/
  224. VOID sizeWindows()
  225. {
  226. RECT fKeysRect;
  227. RECT ctrlsRect;
  228. RECT termRect;
  229. setDefaultFonts();
  230. GetWindowRect(hdbmyControls, (LPRECT) &fKeysRect);
  231. GetWindowRect(fKeyHandles[0], (LPRECT) &ctrlsRect); /* mbbx 2.00: fkeys... */
  232. MoveWindow(hdbmyControls, 0, fKeysRect.top, fKeysRect.right,
  233. fKeysHeight = ((ctrlsRect.bottom - ctrlsRect.top) * 2), FALSE);
  234. GetClientRect(hItWnd, (LPRECT) &fKeysRect); /* mbbx 2.00: may not init maximized... */
  235. sizeFkeys(MAKELONG(fKeysRect.right, fKeysRect.bottom));
  236. GetWindowRect(hdbXferCtrls, (LPRECT) &ctrlsRect); /* mbbx 1.04: fkeys... */
  237. ctrlsHeight = ctrlsRect.bottom - ctrlsRect.top;
  238. initChildSize(&termRect);
  239. MoveWindow(hTermWnd, 0, 0, termRect.right, termRect.bottom, FALSE); /* jtf 3.21 */
  240. }
  241. /*---------------------------------------------------------------------------*/
  242. /* initWindows() - */
  243. /*---------------------------------------------------------------------------*/
  244. BOOL initWindows(hInstance, hPrevInstance, cmdShow)
  245. HANDLE hInstance;
  246. HANDLE hPrevInstance;
  247. INT cmdShow;
  248. {
  249. hInst = hInstance;
  250. /* Added 02/26/91 for window existence */
  251. hItWnd = NULL;
  252. hdbmyControls = NULL;
  253. hTermWnd = NULL;
  254. hdbXferCtrls = NULL;
  255. hEdit = NULL;
  256. fKeyHdl = NULL;
  257. LoadString(hInst, STR_APPNAME_PRIVATE, (LPSTR) szAppName_private, 20);
  258. LoadString(hInst, STR_APPNAME, (LPSTR) szAppName, 20);
  259. LoadString(hInst, STR_DEVELOPER, (LPSTR) szMessage, 80);
  260. LoadString(hInst, STR_NOMEMORY,(LPSTR)NoMemStr,sizeof(NoMemStr)); /* rjs msoft ??? */
  261. setDefaultAttrib(TRUE); /* mbbx 1.04: ...szAppName loaded */
  262. if(!hPrevInstance)
  263. {
  264. if(!initWndClass()) /* mbbx 1.04 ... */
  265. return(FALSE);
  266. }
  267. initPort();
  268. initIcon();
  269. theBrush = GetStockObject (WHITE_BRUSH);
  270. blackBrush = GetStockObject (BLACK_BRUSH);
  271. if(!createWindows(cmdShow))
  272. return(FALSE);
  273. sizeWindows();
  274. maxScreenLine = MAXSCREENLINE; /* rjs moved from size windows */
  275. hMenu = GetMenu(hItWnd);
  276. return(TRUE);
  277. }
  278. /*---------------------------------------------------------------------------*/
  279. /* initDialogs() - Do all dialogbox initialization. [scf] */
  280. /*---------------------------------------------------------------------------*/
  281. VOID initDialogs() /* mbbx: remove ALL of these... */
  282. {
  283. }
  284. /*---------------------------------------------------------------------------*/
  285. /* dbPortInit() - [mbb] */
  286. /*---------------------------------------------------------------------------*/
  287. BOOL APIENTRY dbPortInit(hDlg, message, wParam, lParam) /* mbbx 2.01.10 ... */
  288. HWND hDlg;
  289. UINT message;
  290. WPARAM wParam;
  291. LONG lParam;
  292. {
  293. #ifdef WIN32
  294. WORD temp_wParam;
  295. #endif
  296. switch(message)
  297. {
  298. case WM_INITDIALOG:
  299. initDlgPos(hDlg);
  300. initComDevSelect(hDlg, ITMCONNECTOR, TRUE);
  301. return(TRUE);
  302. case WM_COMMAND:
  303. switch(GET_WM_COMMAND_ID(wParam, lParam))
  304. {
  305. case IDOK:
  306. break;
  307. case ITMCONNECTOR:
  308. if(GET_WM_COMMAND_CMD(wParam, lParam) == LBN_DBLCLK)
  309. break;
  310. return(TRUE);
  311. }
  312. break;
  313. default:
  314. return(FALSE);
  315. }
  316. trmParams.comPortRef = getComDevSelect(hDlg, ITMCONNECTOR, &trmParams.newDevRef);
  317. trmParams.fResetDevice = TRUE;
  318. #ifdef WIN32
  319. /* code in next block passes address of wParam to function*/
  320. /* so we pass temp variable instead, since we need extract ID from wParam under WIN32*/
  321. temp_wParam = GET_WM_COMMAND_ID(wParam, lParam);
  322. #endif
  323. #ifdef ORGCODE
  324. trmParams.comPortRef = getComDevSelect(hDlg, ITMCONNECTOR, (BYTE *) &wParam);
  325. #else
  326. trmParams.comPortRef = getComDevSelect(hDlg, ITMCONNECTOR, (BYTE *) &temp_wParam);
  327. #endif
  328. resetSerial(&trmParams, TRUE, TRUE, NULL); /* slc swat */
  329. if(trmParams.comDevRef != trmParams.newDevRef)
  330. {
  331. exitSerial();
  332. return(TRUE);
  333. }
  334. exitSerial();
  335. #ifdef ORGCODE
  336. EndDialog(hDlg, (INT) getComDevSelect(hDlg, ITMCONNECTOR, (BYTE *) &wParam));
  337. #else
  338. EndDialog(hDlg, (INT) getComDevSelect(hDlg, ITMCONNECTOR, (BYTE *) &temp_wParam));
  339. #endif
  340. return(TRUE);
  341. }
  342. /*---------------------------------------------------------------------------*/
  343. /* setProfileExtent() - [mbb] */
  344. /*---------------------------------------------------------------------------*/
  345. /* mbbx: 1.01 - moved from itutil1.c */
  346. BOOL NEAR setProfileExtent(section, extent) /* mbbx 2.00: NEAR call... */
  347. BYTE *section;
  348. BYTE *extent;
  349. {
  350. BOOL setProfileExtent = FALSE;
  351. BYTE str[80];
  352. BYTE temp[80];
  353. if(!GetProfileString((LPSTR) section, (LPSTR) extent, (LPSTR) NULL_STR, (LPSTR) temp, 80))
  354. {
  355. strcpy(temp, extent);
  356. AnsiLower((LPSTR) temp);
  357. sprintf(str, "%s.exe ^.%s", szAppName_private, temp);
  358. AnsiLower((LPSTR) str);
  359. WriteProfileString((LPSTR) section, (LPSTR) temp, (LPSTR) str);
  360. setProfileExtent = TRUE;
  361. }
  362. return(setProfileExtent);
  363. }
  364. /*---------------------------------------------------------------------------*/
  365. /* initFileDocData() - [mbb] */
  366. /*---------------------------------------------------------------------------*/
  367. BOOL NEAR initFileDocData(fileType, strResID, fileExt, szSection) /* mbbx 2.00 ... */
  368. FILEDOCTYPE fileType;
  369. WORD strResID;
  370. BYTE *fileExt;
  371. BYTE *szSection;
  372. {
  373. BYTE work1[MINRESSTR], work2[80];
  374. LoadString(hInst, strResID, (LPSTR) work1, MINRESSTR);
  375. GetProfileString((LPSTR) szAppName_private, (LPSTR) work1, (LPSTR) NULL_STR, (LPSTR) work2, 80);
  376. getDataPath(fileType, fileDocData[fileType].filePath, work2);
  377. strcpy(fileDocData[fileType].fileExt, fileExt);
  378. if(!getFileType(work2, fileDocData[fileType].fileExt))
  379. strcpy(work2, fileDocData[fileType].fileExt);
  380. strcpy(fileDocData[fileType].fileName, fileDocData[fileType].fileExt+1);
  381. if(work2[strlen(work2)-1] != '*')
  382. return(setProfileExtent(szSection, fileDocData[fileType].fileExt+3));
  383. return(FALSE);
  384. }
  385. /*---------------------------------------------------------------------------*/
  386. /* initProfileData() - [mbb] */
  387. /*---------------------------------------------------------------------------*/
  388. #define DEFBUFFERLINES 100 /* mbbx 1.10... */
  389. VOID initProfileData() /* mbbx: 1.01 ... */
  390. {
  391. BYTE str[MINRESSTR], str2[MINRESSTR], portName[16];
  392. INT ndx;
  393. FARPROC lpdbPortInit;
  394. BOOL notify;
  395. LoadString(hInst, STR_INI_PORT, (LPSTR) str, MINRESSTR);
  396. if(!GetProfileString((LPSTR) szAppName_private, (LPSTR) str, (LPSTR) NULL_STR, (LPSTR) portName, 5))
  397. {
  398. trmParams.comDevRef = ITMNOCOM; /* jtf 3.33 */
  399. trmParams.speed = 1200; /* jtf 3.33 */
  400. trmParams.dataBits = ITMDATA8; /* jtf 3.33 */
  401. trmParams.stopBits = ITMSTOP1; /* jtf 3.33 */
  402. trmParams.parity = ITMNOPARITY; /* jtf 3.33 */
  403. if((ndx = doSettings(IDDBPORTINIT, dbPortInit)) != -1) /* mbbx 2.01.10 ... */
  404. {
  405. LoadString(hInst, (ndx > 0) ? STR_COM : STR_COM_CONNECT, (LPSTR) str2, MINRESSTR);
  406. sprintf(portName, str2, ndx);
  407. WriteProfileString((LPSTR) szAppName_private, (LPSTR) str, (LPSTR) portName);
  408. }
  409. }
  410. LoadString(hInst, STR_INI_SWAP, (LPSTR) str, MINRESSTR);
  411. if((ndx = GetProfileInt((LPSTR) szAppName_private, (LPSTR) str, 0)) > 0)
  412. *taskState.string = sprintf(taskState.string+1, "%d", SetSwapAreaSize(ndx));
  413. LoadString(hInst, STR_INI_INTL, (LPSTR) str, MINRESSTR);
  414. LoadString(hInst, STR_INI_IDATE, (LPSTR) str2, MINRESSTR);
  415. intlData.iDate = GetProfileInt((LPSTR) str, (LPSTR) str2, 0);
  416. LoadString(hInst, STR_INI_SDATE, (LPSTR) str2, MINRESSTR);
  417. GetProfileString((LPSTR) str, (LPSTR) str2, (LPSTR) "/", (LPSTR) intlData.sDate, 2);
  418. LoadString(hInst, STR_INI_ITIME, (LPSTR) str2, MINRESSTR);
  419. intlData.iTime = GetProfileInt((LPSTR) str, (LPSTR) str2, 0);
  420. LoadString(hInst, STR_INI_STIME, (LPSTR) str2, MINRESSTR);
  421. GetProfileString((LPSTR) str, (LPSTR) str2, (LPSTR) ":", (LPSTR) intlData.sTime, 2);
  422. LoadString(hInst, STR_INI_S1159, (LPSTR) str2, MINRESSTR);
  423. GetProfileString((LPSTR) str, (LPSTR) str2, (LPSTR) "AM", (LPSTR) intlData.s1159, 4);
  424. LoadString(hInst, STR_INI_S2359, (LPSTR) str2, MINRESSTR);
  425. GetProfileString((LPSTR) str, (LPSTR) str2, (LPSTR) "PM", (LPSTR) intlData.s2359, 4);
  426. LoadString(hInst, STR_INI_EXTENSIONS, (LPSTR) str, MINRESSTR);
  427. notify = initFileDocData(FILE_NDX_SETTINGS, STR_INI_SETTINGS, SETTINGS_FILE_TYPE, str);
  428. if(initFileDocData(FILE_NDX_TASK, STR_INI_TASK, TASK_FILE_TYPE, str))
  429. notify = TRUE;
  430. if(initFileDocData(FILE_NDX_SCRIPT, STR_INI_SCRIPT, SCRIPT_FILE_TYPE, str))
  431. notify = TRUE;
  432. if(initFileDocData(FILE_NDX_MEMO, STR_INI_MEMO, MEMO_FILE_TYPE, str))
  433. notify = TRUE;
  434. if(initFileDocData(FILE_NDX_DATA, STR_INI_DATA, DATA_FILE_TYPE, str))
  435. notify = TRUE;
  436. if(notify)
  437. #ifdef ORGCODE
  438. SendMessage(0xFFFF, WM_WININICHANGE, 0, (LONG) ((LPSTR) str));
  439. #else
  440. SendMessage((HWND)0xFFFFFFFF, WM_WININICHANGE, 0, (LONG) ((LPSTR) str));
  441. #endif
  442. }
  443. /*---------------------------------------------------------------------------*/
  444. /* setup() - Reset all varibles, read settings file & emulation. [scf] */
  445. /*---------------------------------------------------------------------------*/
  446. BOOL setup() /* mbbx 2.00: no cmd line... */
  447. {
  448. BYTE path[PATHLEN+1];
  449. BYTE tmp1[TMPNSTR+1];
  450. INT ndx;
  451. SetRect ((LPRECT) &cursorRect, 0, 0, 0, 0);
  452. vScrollShowing = TRUE;
  453. serNdx = 0;
  454. cursorTick = -1l;
  455. cursBlinkOn = FALSE;
  456. cursorOn = TRUE;
  457. activCursor = 1;
  458. prtFlag = FALSE;
  459. useScrap = FALSE;
  460. copiedTable = FALSE;
  461. *fKeyStr = 0; /* mbbx 2.00: fKeySeq... */
  462. fKeyNdx = 1;
  463. scrapSeq = FALSE;
  464. xferFlag = XFRNONE;
  465. xferPaused = FALSE;
  466. xferBreak = FALSE; /* mbbx 2.00: xfer ctrls */
  467. xferEndTimer = 0;
  468. xferWaitEcho = FALSE;
  469. xferViewPause = 0; /* mbbx: auto line count */
  470. xferViewLine = 0;
  471. xferPSChar = 0; /* mbbx 1.02: packet switching */
  472. *strRXErrors =
  473. *strRXBytes =
  474. *strRXFname =
  475. *strRXFork = 0;
  476. taskInit();
  477. keyMapInit(); /* mbbx 1.04: keymap */
  478. debugFlg = FALSE; /* how does this get enabled??? */
  479. mdmOnLine = FALSE;
  480. dialing = FALSE;
  481. answerMode = FALSE;
  482. protectMode = FALSE; /* mbbx: emulation state */
  483. KER_getflag = FALSE;
  484. gotCommEvent = TRUE;
  485. if((hemulKeyInfo = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) SIZEOFEMULKEYINFO)) == NULL)
  486. return(FALSE);
  487. initProfileData(); /* mbbx: 1.01 */
  488. hTE.hText = NULL;
  489. setDefaults();
  490. setFKeyLevel(1, FALSE); /* jtfterm */
  491. termInitSetup(NULL);
  492. strcpy(szMessage, szAppName);
  493. return(TRUE);
  494. }
  495. /*---------------------------------------------------------------------------*/
  496. /* readCmdLine() - [mbb] */
  497. /*---------------------------------------------------------------------------*/
  498. BOOL fileDocExist(fileType, filePath) /* mbbx 2.00: no forced extents... */
  499. WORD fileType;
  500. BYTE *filePath;
  501. {
  502. BOOL fileDocExist;
  503. BYTE savePath[PATHLEN], testPath[PATHLEN];
  504. BYTE OEMname[STR255]; /* jtf 3.20 */
  505. strcpy(savePath, filePath);
  506. getDataPath(fileType, testPath, savePath);
  507. strcpy(testPath+strlen(testPath), savePath);
  508. // JYF -- replace below two line with following if () to
  509. // remove the use of AnsiToOem()
  510. //
  511. //AnsiToOem((LPSTR) testPath, (LPSTR) OEMname); /* jtf 3.20 */
  512. //if(fileDocExist = fileExist(OEMname)) /* jtf 3.20 */
  513. if (fileDocExist = fileExist(testPath))
  514. strcpy(filePath, testPath);
  515. return(fileDocExist);
  516. }
  517. WORD NEAR getFileDocType(filePath) /* mbbx 2.00: no forced extents... */
  518. BYTE *filePath;
  519. {
  520. BYTE fileExt[16];
  521. WORD fileType;
  522. *fileExt = 0;
  523. if(!getFileType(filePath, fileExt))
  524. {
  525. forceExtension(filePath, NO_FILE_TYPE+2, FALSE);
  526. if(fileDocExist(FILE_NDX_DATA, filePath) || fileDocExist(FILE_NDX_SETTINGS, filePath))
  527. return(FILE_NDX_SETTINGS); /* jtf 3.11 */
  528. }
  529. for(fileType = FILE_NDX_SETTINGS; fileType <= FILE_NDX_MEMO; fileType += 1)
  530. {
  531. if(*fileExt == 0)
  532. forceExtension(filePath, fileDocData[fileType].fileExt+2, TRUE);
  533. else if((fileType < FILE_NDX_MEMO) && (strcmp(fileDocData[fileType].fileExt+2, fileExt) != 0))
  534. continue;
  535. if(fileDocExist(FILE_NDX_DATA, filePath) || fileDocExist(fileType, filePath) || (*fileExt != 0))
  536. return(fileType);
  537. }
  538. return(FILE_NDX_DATA);
  539. }
  540. BOOL NEAR initTermFile(filePath) /* mbbx 2.00 ... */
  541. BYTE *filePath;
  542. {
  543. getDataPath(FILE_NDX_SETTINGS, fileDocData[FILE_NDX_SETTINGS].filePath, filePath);
  544. LoadString(hInst, STR_TERMINAL, (LPSTR) termData.title, MINRESSTR);
  545. /* mbbx 2.00: no forced extents... */
  546. return(termFile(fileDocData[FILE_NDX_SETTINGS].filePath, filePath,
  547. fileDocData[FILE_NDX_SETTINGS].fileExt, termData.title, TF_DEFTITLE));
  548. }
  549. VOID NEAR readCmdLine(lpszCmdLine)
  550. LPSTR lpszCmdLine;
  551. {
  552. INT ndx, ndx2;
  553. BYTE filePath[PATHLEN];
  554. BYTE tmpFilePath[PATHLEN];
  555. INT nEditWnd = 0;
  556. BYTE OEMname[STR255]; /* jtf 3.20 */
  557. BYTE work[STR255]; /* jtf 3.28 */
  558. BYTE work1[STR255]; /* jtf 3.28 */
  559. INT testFlag;
  560. saveFileType = FILE_NDX_SETTINGS; /* jtf 3.11 */
  561. AnsiUpper(lpszCmdLine);
  562. for(ndx = 0; lpszCmdLine[ndx] != 0; ) /* mbbx 2.00 ... */
  563. {
  564. while(lpszCmdLine[ndx] == 0x20)
  565. ndx += 1;
  566. if(lpszCmdLine[ndx] == 0)
  567. break;
  568. for(ndx2 = 0; (filePath[ndx2] = lpszCmdLine[ndx]) != 0; ndx2 += 1)
  569. {
  570. ndx += 1;
  571. if(filePath[ndx2] == 0x20)
  572. {
  573. filePath[ndx2] = 0;
  574. break;
  575. }
  576. }
  577. strcpy(work1,filePath);
  578. switch(ndx2 = getFileDocType(filePath)) /* mbbx 2.00: term init... */
  579. {
  580. case FILE_NDX_SETTINGS:
  581. if(!activTerm)
  582. initTermFile(filePath);
  583. break;
  584. }
  585. }
  586. if ((!activTerm) && (lstrlen((LPSTR)lpszCmdLine)>0) )
  587. {
  588. LoadString(hInst, STRERRNOFILE, (LPSTR) work, STR255-1); /* jtf 3.15 */
  589. strcpy(filePath,work1);
  590. forceExtension(filePath, SETTINGS_FILE_TYPE+2, FALSE);
  591. sprintf(work1, work, filePath);
  592. testFlag = MessageBox(GetActiveWindow(), (LPSTR) work1, (LPSTR) szAppName, MB_OKCANCEL);
  593. if (testFlag==IDOK)
  594. {
  595. if (filePath[1]==':')
  596. {
  597. filePath[0]='A';
  598. }
  599. else
  600. {
  601. strcpy(work,filePath);
  602. strcpy(filePath,"A:");
  603. strcpy(filePath+2,work);
  604. }
  605. initTermFile(filePath);
  606. }
  607. }
  608. if(!activTerm) /* mbbx 2.00: term init... */
  609. {
  610. LoadString(hInst, STR_AUTOLOAD, (LPSTR) filePath, PATHLEN); /* jtf 3.17 */
  611. // JYF -- replace below two lines with the following if() to
  612. // remove the use of AnsiToOem()
  613. //
  614. //AnsiToOem((LPSTR) filePath, (LPSTR) OEMname); /* jtf 3.20 */
  615. //if (fileExist(OEMname)) /* jtf 3.20 */
  616. if (fileExist(filePath))
  617. initTermFile(filePath);
  618. else
  619. {
  620. _searchenv( filePath, "PATH", tmpFilePath );
  621. if(strlen(tmpFilePath)>0)
  622. initTermFile(tmpFilePath);
  623. }
  624. if(!activTerm)
  625. {
  626. if((nEditWnd -= 1) >= 0)
  627. termData.flags |= TF_HIDE;
  628. else
  629. saveFileType = FILE_NDX_SETTINGS;
  630. activTerm = TRUE;
  631. resetSerial(&trmParams, TRUE, TRUE,0);
  632. if(!(termData.flags & TF_HIDE))
  633. showTerminal(TRUE, TRUE);
  634. }
  635. }
  636. if(!IsIconic(hItWnd)) /* rjs bugs 015 */
  637. sizeTerm(0L); /* jtf 3.21 */
  638. }
  639. /*---------------------------------------------------------------------------*/
  640. /* freeItResources()- Free up all windows resource b/4 back to DOS executive.*/
  641. /* Internal house keeping. Note: Close that serial port. */
  642. /*---------------------------------------------------------------------------*/
  643. VOID freeItResources()
  644. {
  645. INT ndx;
  646. exitSerial();
  647. keyMapCancel(); /* mbbx 1.04: keymap */
  648. DeleteObject(hTE.hFont);
  649. clearFontCache(); /* mbbx 2.00: redundant code... */
  650. GlobalFree(hTE.hText);
  651. GlobalFree(hemulKeyInfo);
  652. }