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.

452 lines
13 KiB

  1. /*===========================================================================*/
  2. /* Copyright (c) 1987 - 1988, Future Soft Engineering, Inc. */
  3. /* Houston, Texas */
  4. /*===========================================================================*/
  5. #define NOLSTRING TRUE /* jtf win3 mod */
  6. #include <windows.h>
  7. #include "port1632.h"
  8. #include "dcrc.h"
  9. #include "dynacomm.h"
  10. #include "task.h"
  11. /*---------------------------------------------------------------------------*/
  12. /* getScrCh() - [scf]*/
  13. /*---------------------------------------------------------------------------*/
  14. BOOL getScrCh ()
  15. {
  16. BOOL result;
  17. if (textIndex < textLength)
  18. {
  19. rdCH[1] = textPtr[textIndex];
  20. textIndex++;
  21. result = TRUE;
  22. }
  23. else
  24. result = FALSE;
  25. return TRUE;
  26. }
  27. /*---------------------------------------------------------------------------*/
  28. /* stripLeadingSpaces() - [scf]*/
  29. /*---------------------------------------------------------------------------*/
  30. VOID stripLeadingSpaces ()
  31. {
  32. INT i;
  33. BYTE whiteSpace[20];
  34. sprintf (whiteSpace," %c%c",CHFILL,TAB);
  35. i = outBuf[0] - 1;
  36. while (strchr (whiteSpace, outBuf[i]))
  37. {
  38. outBuf[i] = CR;
  39. outBuf[0]--;
  40. i--;
  41. }
  42. }
  43. /*---------------------------------------------------------------------------*/
  44. /* getChxmit() - Get xmit char. from clipBoard or file. [scf]*/
  45. /*---------------------------------------------------------------------------*/
  46. BOOL getChxmit()
  47. {
  48. BOOL result = FALSE;
  49. INT err;
  50. STRING str[2];
  51. BYTE whiteSpace[20];
  52. DWORD charsRead;
  53. if(!trmParams.xWordWrap || (xferFlag == XFRTYP) || (scrapSeq && copiedTable))
  54. {
  55. if(scrapSeq)
  56. {
  57. if(getScrCh())
  58. result = TRUE;
  59. }
  60. else
  61. {
  62. charsRead = _lread((int)xferRefNo, (LPSTR)(&rdCH[1]), ioCnt);
  63. if(charsRead == (DWORD)ioCnt)
  64. result = TRUE;
  65. else if(charsRead != 0)
  66. {
  67. if(charsRead != (DWORD)-1)
  68. charsRead = 0;
  69. else
  70. result = TRUE;
  71. }
  72. else
  73. result = FALSE;
  74. }
  75. outBufSeq = FALSE;
  76. return(result);
  77. }
  78. if(!outBufSeq)
  79. {
  80. repeat
  81. {
  82. if(scrapSeq)
  83. {
  84. if(getScrCh())
  85. err = ioCnt;
  86. else
  87. err = ioCnt + 1;
  88. }
  89. else
  90. {
  91. err = _lread(xferRefNo, (LPSTR)(&rdCH[1]), ioCnt);
  92. }
  93. if(err == ioCnt)
  94. {
  95. str[0] = 0x01; str[1] = rdCH[1];
  96. concat (outBuf, str, outBuf);
  97. outBufCol++;
  98. if (rdCH[1] == CR)
  99. outBufCol = 0;
  100. else if (rdCH[1] == LF)
  101. outBufCol--;
  102. else if(outBufCol > trmParams.xWrapCol) /* WRN as outBufCol is BOOL*/
  103. { /* and xWrapCol is INT */
  104. xferBytes++;
  105. str[1] = LF;
  106. concat (outBuf, outBuf, str);
  107. xferBytes++;
  108. str[1] = CR;
  109. concat (outBuf, outBuf, str);
  110. outBufSeq = TRUE;
  111. stripLeadingSpaces ();
  112. outBufCol = (INT) outBuf[0];
  113. }
  114. sprintf(whiteSpace," %c%c%c%c",TAB,CHFILL,CR,LF);
  115. if (strchr(whiteSpace,rdCH[1]))
  116. outBufSeq = TRUE;
  117. }
  118. else
  119. if (*outBuf == 0)
  120. return result;
  121. else
  122. outBufSeq = TRUE;
  123. }
  124. until(outBufSeq);
  125. }
  126. if(outBufSeq)
  127. {
  128. ioCnt = 1;
  129. result = TRUE;
  130. rdCH[1] = outBuf[outBuf[0]];
  131. if (*outBuf > 1)
  132. outBuf[0]--;
  133. else
  134. {
  135. outBufSeq = FALSE;
  136. outBuf[0] = 0;
  137. }
  138. }
  139. return(result);
  140. }
  141. /*---------------------------------------------------------------------------*/
  142. /* xferFile() - Transfer & Receive text file handling. [scf] [mbb] */
  143. /*---------------------------------------------------------------------------*/
  144. /* NOTE: xferFile no longer masks off the high order bit of the
  145. chars sent -- I don't see how they could have gotten SET in the first place
  146. whether they came from a file or the clipboard. [mbbx 1.02] */
  147. VOID xferFile()
  148. {
  149. BOOL breakXfer;
  150. int ndx;
  151. breakXfer = (xferPaused || xferStopped);
  152. if(xferEndTimer > 0)
  153. if(xferEndTimer > tickCount()) /* WRN xferEndTimer is LONG and */
  154. breakXfer = TRUE; /* and GetCurrentTime returns DWORD*/
  155. else /* but was same in 3.0 too -sdj */
  156. xferEndTimer = 0;
  157. if(xferWaitEcho)
  158. breakXfer = TRUE;
  159. while(!breakXfer)
  160. {
  161. rxEventLoop();
  162. ioCnt = 1;
  163. if((xferViewPause == 0) && /* mbbx: auto line count */
  164. (((xferFlag == XFRTYP) ) ||
  165. ((xferFlag == XFRSND) && !trmParams.xWordWrap && /* mbbx 1.03: lineWrap -> xWordWrap */
  166. (xferTxtType == XFRNORMAL))))
  167. {
  168. if((ioCnt = YIELDCHARS) > xferBytes)
  169. ioCnt = xferBytes;
  170. }
  171. if(xferBytes > 0)
  172. {
  173. if(getChxmit())
  174. {
  175. for(ndx = 1; ndx <= ioCnt; ndx++)
  176. {
  177. /* mbbx 1.10: set rdCh[0] to LF if appending LF's... */
  178. if(((theChar = rdCH[ndx]) != CR) || (rdCH[0] != CR)) /* mbbx 1.02: CR CR LF -> CR */
  179. {
  180. rdCH[0] = theChar; /* mbbx 1.02: save char... */
  181. if((theChar != LF) || (xferSndLF != -1)) /* mbbx: strip LF's */
  182. {
  183. if(xferFlag == XFRTYP)
  184. modemInp(theChar, FALSE);
  185. else
  186. modemWr(theChar);
  187. }
  188. if (xferStopped)
  189. break; /* jtf 3.30 */
  190. if(((theChar == CR) && (xferSndLF != 0)) || ((theChar == LF) && (xferSndLF == 0)))
  191. {
  192. if(xferSndLF == 1) /* mbbx: append LF's */
  193. {
  194. if(xferFlag == XFRTYP)
  195. modemInp(LF, FALSE);
  196. else
  197. modemWr(LF);
  198. rdCH[0] = LF; /* mbbx 1.10: last char sent = LF */
  199. }
  200. if(xferViewPause > 0)
  201. {
  202. if(++xferViewLine >= xferViewPause)
  203. {
  204. xferViewLine = 0;
  205. termCleanUp();
  206. xferPauseResume(TRUE, FALSE); /* mbbx 2.00: xfer ctrls... */
  207. }
  208. }
  209. }
  210. }
  211. else
  212. theChar = 0; /* mbbx 1.10: avoid 2 line waits on CR CR LF */
  213. xferBytes -= 1;
  214. if(!scrapSeq)
  215. updateProgress(FALSE);
  216. }
  217. }
  218. else
  219. xferBytes = 0;
  220. }
  221. if((theChar == CR) || (xferBytes == 0) || (ioCnt > 1) || xferPaused ||
  222. (xferTxtType == XFRCHAR) || scrapSeq)
  223. break; /* mbbx: DO NOT set breakXfer !!! */
  224. }
  225. if(xferBytes == 0)
  226. {
  227. if(scrapSeq)
  228. {
  229. scrapSeq = FALSE;
  230. GlobalUnlock(tEScrapHandle);
  231. tEScrapHandle = GlobalFree(tEScrapHandle);
  232. if(!IsIconic(hItWnd))
  233. SetCursor(LoadCursor(NULL, IDC_ARROW));
  234. xferBytes = 1L; /* Need so pasting during a Rcv. Text doesn't terminate */
  235. }
  236. else
  237. {
  238. termCleanUp(); /* mbbx: finish term update */
  239. xferEnd();
  240. }
  241. }
  242. if(((xferFlag == XFRSND) || scrapSeq) && !breakXfer)
  243. {
  244. if(xferTxtType == XFRCHAR)
  245. {
  246. if(xferChrType == XFRCHRDELAY)
  247. xferEndTimer = tickCount() + (xferChrDelay * 6);
  248. else
  249. {
  250. xferWaitEcho = TRUE;
  251. xferCharEcho = theChar; /* jtf 3.30 allow ansi text & 0x7f; */
  252. }
  253. }
  254. else if((xferTxtType == XFRLINE) && (theChar == CR))
  255. {
  256. if (xferLinType == XFRLINDELAY)
  257. xferEndTimer = tickCount() + (xferLinDelay * 6);
  258. else
  259. xferWaitEcho = TRUE;
  260. }
  261. }
  262. }
  263. /*---------------------------------------------------------------------------*/
  264. /* termSpecial() - [scf]*/
  265. /*---------------------------------------------------------------------------*/
  266. VOID termSpecial()
  267. {
  268. RECT buttonRect;
  269. HDC hButtonDC;
  270. BOOL breakTerm;
  271. BOOL breakKey; /* jtf 3.20 */
  272. /* mbbx: these WERE static vars */
  273. STRING execStr[STR255];
  274. INT execNdx;
  275. INT brkLen;
  276. LONG finalTicks;
  277. breakKey = FALSE; /* jtf 3.20 */
  278. breakTerm = FALSE;
  279. if(useScrap)
  280. {
  281. if((textPtr = GlobalLock (tEScrapHandle)) != NULL)
  282. xferBytes = textLength = (LONG) lstrlen(textPtr);
  283. else
  284. xferBytes = textLength = 0;
  285. textIndex = 0;
  286. useScrap = FALSE;
  287. scrapSeq = TRUE;
  288. xferSndLF = (trmParams.outCRLF ? 0 : -1); /* mbbx 1.10: CUA */
  289. *outBuf = 0;
  290. if(trmParams.xWordWrap && !copiedTable)
  291. {
  292. outBufCol = 0;
  293. outBufSeq = FALSE;
  294. xferBlkSize = 1;
  295. }
  296. xferTxtType = (TTXTTYPE) (trmParams.xTxtType - ITMSTD);
  297. xferChrType = (TCHRTYPE) (trmParams.xChrType - ITMCHRDELAY);
  298. xferLinType = (TLINTYPE) (trmParams.xLinType - ITMLINDELAY);
  299. xferChrDelay = trmParams.xChrDelay;
  300. xferLinDelay = trmParams.xLinDelay;
  301. if (!IsIconic (hItWnd))
  302. SetCursor (LoadCursor (NULL, IDC_WAIT));
  303. }
  304. /* WRN fKeyNdx is INT and *fKeyStr is BYTE -sdj */
  305. if(fKeyNdx <= *fKeyStr) /* mbbx 2.00: dc terminal... */
  306. {
  307. if((theChar = fKeyStr[fKeyNdx++]) == '^')
  308. {
  309. if((fKeyNdx <= *fKeyStr) && ((theChar = fKeyStr[fKeyNdx++]) == '$'))
  310. theChar = 0xFF;
  311. else if(theChar != '^')
  312. {
  313. if(theChar == '~')
  314. theChar = '^'; /* NOTE: must use ^~ to send 0x1E */
  315. if(((theChar >= 'A') && (theChar <= '_')) || ((theChar >= 'a') && (theChar <= 'z')))
  316. theChar &= 0x1F;
  317. else
  318. theChar = fKeyStr[(--fKeyNdx)-1];
  319. }
  320. }
  321. if(theChar != 0xFF)
  322. {
  323. sendKeyInput(theChar); /* mbbx: per slc request */
  324. }
  325. else /* special ctrl strings... */
  326. {
  327. if(((theChar = fKeyStr[fKeyNdx++]) >= 'a') && (theChar <= 'z'))
  328. theChar -= 0x20;
  329. while((fKeyNdx <= *fKeyStr) && (fKeyStr[fKeyNdx] == ' '))
  330. fKeyNdx++;
  331. switch(theChar)
  332. {
  333. case 'L': /* ^$L - level */
  334. setFKeyLevel(fKeyStr[fKeyNdx++] - '0', FALSE); /* mbbx 2.00: bReset */
  335. break;
  336. case 'C': /* mbbx 2.00: ^$C - call... */
  337. dialPhone();
  338. break;
  339. case 'H': /* mbbx 2.00: ^$H - hangup... */
  340. hangUpPhone();
  341. break;
  342. case 'B': /* ^$B - break */
  343. breakKey = TRUE; /* jtf 3.20 */
  344. case 'D': /* mbbx 1.04: ^$D - delay */
  345. brkLen = 2;
  346. if(((theChar = fKeyStr[fKeyNdx]) >= '0') && (theChar <= '9'))
  347. {
  348. brkLen = theChar - '0';
  349. if(((theChar = fKeyStr[++fKeyNdx]) >= '0') && (theChar <= '9'))
  350. {
  351. fKeyNdx += 1;
  352. brkLen = (brkLen * 10) + (theChar - '0');
  353. }
  354. }
  355. if(breakKey) /* jtf 3.20 */
  356. modemSendBreak(brkLen);
  357. else
  358. delay(brkLen*60, &finalTicks); /* mbbx 1.04: ^$D <secs> */
  359. break;
  360. }
  361. }
  362. }
  363. if(!breakTerm)
  364. {
  365. switch(xferFlag)
  366. {
  367. case XFRSND:
  368. case XFRTYP:
  369. if(!gbXferActive)
  370. {
  371. gbXferActive = TRUE;
  372. xferFile();
  373. gbXferActive = FALSE;
  374. }
  375. break;
  376. case XFRRCV:
  377. if(!gbXferActive)
  378. {
  379. gbXferActive = TRUE;
  380. if(xferBytes == 0) /* stop button was clicked */
  381. xferEnd();
  382. gbXferActive = FALSE;
  383. }
  384. break;
  385. default:
  386. if(!gbXferActive)
  387. {
  388. gbXferActive = TRUE;
  389. if(scrapSeq)
  390. xferFile();
  391. gbXferActive = FALSE;
  392. }
  393. break;
  394. }
  395. }
  396. if(!breakTerm)
  397. rdModem(FALSE);
  398. }