Leaked source code of windows server 2003
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.

869 lines
19 KiB

  1. /* GIDE.C */
  2. //#define WINVER 0x0300
  3. #define USECOMM /* added to be compatible with new windows.h (12/91) and wintric.h */
  4. /* last rellease of 3.1 SDK switched back to using NOCOMM in windows.h */
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include "windows.h"
  8. //#include "winstric.h" /* added for win 3.1 compatibility 1/92 */
  9. #include "gidei.h"
  10. #include "vars.h"
  11. #include "gide.h"
  12. #include "kbd.h"
  13. #include "mou.h"
  14. #include "tables.h"
  15. #include "dialogs.h"
  16. #include "sk_ex.h"
  17. #include "w95trace.h"
  18. typedef struct tagAliasTable {
  19. char *Alias;
  20. BYTE Code;
  21. } ALIASTABLE;
  22. long AtoL(char *Str);
  23. extern void initClear(void);
  24. BOOL bGIDEIokay = TRUE; /* general flag for error in processing */
  25. int nFrameCnt = 0; /* keep track of framming errors */
  26. char cInBuffer[2]; /* buffer for receiving characters */
  27. //char cInBuffer[7]; /* buffer for receiving characters, size increased */
  28. //short cInBuffer_count =0; /* count of chars. returned in ReadComm */
  29. //int intct = 0; /* counter for looping thru cInBuffer_count */
  30. //char cOutStr[2] = {0,0}; /* single char output string */
  31. void handleFatalError(void)
  32. {
  33. SkEx_SendBeep();
  34. SkEx_SendBeep();
  35. initClear();
  36. return;
  37. }
  38. void handleErrorReport(void)
  39. {
  40. SkEx_SendBeep();
  41. initClear();
  42. return;
  43. }
  44. int aliasForGideiCode(unsigned char *cTempPtr)
  45. {
  46. struct aliasTable *tablePtr;
  47. int found;
  48. found = FALSE;
  49. for (tablePtr=gideiAliasTable;(tablePtr->aliasName[0] != '\x0') && (!found);tablePtr++)
  50. if (strcmp(cAliasString,tablePtr->aliasName) == 0) {
  51. found = TRUE;
  52. *cTempPtr = tablePtr->gideiCode;
  53. }
  54. return (found);
  55. }
  56. int aliasUsedInStandard(unsigned char *cTempPtr)
  57. {
  58. struct aliasTable *tablePtr;
  59. int found;
  60. unsigned char iCode;
  61. if (aliasPtr == keyAliasTable) {
  62. if (lstrlenA(cAliasString) == 1) {
  63. /* use ASCII table */
  64. if ((iCode = asciiTable[cAliasString[0]].gideiCode1) == NOCODE) return(FALSE);
  65. if ((iCode == control_Code) || (iCode == shift_Code))
  66. iCode = asciiTable[cAliasString[0]].gideiCode2;
  67. *cTempPtr = iCode;
  68. return(TRUE);
  69. }
  70. }
  71. found = FALSE;
  72. for (tablePtr=aliasPtr;(tablePtr->aliasName[0] != '\x0') && (!found);tablePtr++)
  73. if (lstrcmpA(cAliasString,tablePtr->aliasName) == 0) {
  74. found = TRUE;
  75. *cTempPtr = tablePtr->gideiCode;
  76. }
  77. return (found);
  78. }
  79. /****************************************************************************
  80. FUNCTION: pushCommandVector
  81. PURPOSE: push CommandVector on to vectorStack
  82. COMMENTS:
  83. ****************************************************************************/
  84. int pushCommandVector(void)
  85. {
  86. if (stackPointer < MAXVECTORSTACK) {
  87. aliasStack[stackPointer] = aliasPtr;
  88. vectorStack[stackPointer++] = commandVector;
  89. return(TRUE);
  90. }
  91. else return(FALSE);
  92. }
  93. /****************************************************************************
  94. FUNCTION: popCommandVector
  95. PURPOSE: pop CommandVector from vectorStack
  96. COMMENTS:
  97. *****************************************************************************/
  98. int popCommandVector(void)
  99. {
  100. if (stackPointer > 0) {
  101. aliasPtr = aliasStack[--stackPointer];
  102. commandVector = vectorStack[stackPointer];
  103. return(TRUE);
  104. }
  105. else return(FALSE);
  106. }
  107. /****************************************************************************
  108. FUNCTION: restoreCommandVector
  109. PURPOSE: restore CommandVector from vectorStack but does not update
  110. stack pointer.
  111. COMMENTS:
  112. *****************************************************************************/
  113. int restoreCommandVector(void)
  114. {
  115. if (stackPointer > 0) {
  116. aliasPtr = aliasStack[--stackPointer];
  117. commandVector = vectorStack[stackPointer];
  118. ++stackPointer;
  119. return(TRUE);
  120. }
  121. else return(FALSE);
  122. }
  123. /****************************************************************************/
  124. int storeByte(unsigned char *bytePtr)
  125. {
  126. if ((spos+1==rpos) || (spos+1==CODEBUFFERLEN && !rpos)) return notOKstatus;
  127. buf[spos++] = *bytePtr;
  128. if (spos==CODEBUFFERLEN) spos = 0;
  129. return okStatus;
  130. }
  131. int retrieveByte(unsigned char *bytePtr)
  132. {
  133. if (rpos==CODEBUFFERLEN) rpos = 0;
  134. if (rpos==spos) return notOKstatus;
  135. ++rpos;
  136. *bytePtr = buf[rpos-1];
  137. return okStatus;
  138. }
  139. /****************************************************************************
  140. FUNCTION: noOpRoutine
  141. PURPOSE: "Do nothing" routine
  142. COMMENTS:
  143. ****************************************************************************/
  144. void noOpRoutine(unsigned char cJunk)
  145. {
  146. return;
  147. }
  148. void processGen(unsigned char c)
  149. {
  150. return;
  151. }
  152. void processComm(unsigned char c)
  153. {
  154. return;
  155. }
  156. /****************************************************************************
  157. FUNCTION: processCommand
  158. PURPOSE: Determine which command is active. Then set commandVector to
  159. point to appropriate routine.
  160. COMMENTS:
  161. ****************************************************************************/
  162. void processCommand(unsigned char cGideiCode)
  163. {
  164. switch(cGideiCode) {
  165. case KBDEXPANSIONCODE:
  166. commandVector = processKbd;
  167. aliasPtr = kbdAliasTable;
  168. beginOK = TRUE;
  169. break;
  170. case MOUEXPANSIONCODE:
  171. commandVector = processMou;
  172. aliasPtr = mouseAliasTable;
  173. beginOK = TRUE;
  174. break;
  175. case GENCODE:
  176. commandVector = processGen;
  177. aliasPtr = genAliasTable;
  178. beginOK = TRUE;
  179. break;
  180. case COMMCODE:
  181. commandVector = processComm;
  182. aliasPtr = commAliasTable;
  183. beginOK = TRUE;
  184. break;
  185. case KBDLOCKCODE:
  186. commandVector = processKbdLock;
  187. aliasPtr = keyAliasTable;
  188. beginOK = TRUE;
  189. break;
  190. case KBDRELCODE:
  191. commandVector = processKbdRel;
  192. aliasPtr = keyAliasTable;
  193. beginOK = TRUE;
  194. break;
  195. case KBDPRESSCODE:
  196. commandVector = processKbdPress;
  197. aliasPtr = keyAliasTable;
  198. beginOK = TRUE;
  199. break;
  200. case KBDCOMBINECODE:
  201. commandVector = processKbdCombine;
  202. aliasPtr = keyAliasTable;
  203. beginOK = TRUE;
  204. break;
  205. case KBDHOLDCODE:
  206. commandVector = processKbdHold;
  207. aliasPtr = keyAliasTable;
  208. beginOK = TRUE;
  209. break;
  210. case MOULOCKCODE:
  211. commandVector = processMouLock;
  212. aliasPtr = mouButtonAliasTable;
  213. beginOK = TRUE;
  214. break;
  215. case MOURELCODE:
  216. commandVector = processMouRel;
  217. aliasPtr = mouButtonAliasTable;
  218. beginOK = TRUE;
  219. break;
  220. case MOUCLICKCODE:
  221. commandVector = processMouClick;
  222. aliasPtr = mouButtonAliasTable;
  223. beginOK = TRUE;
  224. break;
  225. case MOUDOUBLECLICKCODE:
  226. commandVector = processMouDoubleClick;
  227. aliasPtr = mouButtonAliasTable;
  228. beginOK = TRUE;
  229. break;
  230. case MOUMOVECODE:
  231. commandVector = processMouMove;
  232. aliasPtr = nullTable;
  233. beginOK = TRUE;
  234. break;
  235. case MOUGOTOCODE:
  236. commandVector = processMouGoto;
  237. aliasPtr = nullTable;
  238. beginOK = TRUE;
  239. break;
  240. case MOURESETCODE:
  241. commandVector = processMouReset;
  242. aliasPtr = nullTable;
  243. beginOK = TRUE;
  244. break;
  245. case MOUANCHORCODE:
  246. commandVector = processMouAnchor;
  247. aliasPtr = nullTable;
  248. beginOK = TRUE;
  249. break;
  250. case BAUDRATECODE:
  251. commandVector = processBaudrate;
  252. aliasPtr = baudrateAliasTable;
  253. beginOK = TRUE;
  254. break;
  255. case UNKNOWNCODE:
  256. handleErrorReport();
  257. commandVector = noOpRoutine;
  258. beginOK = TRUE;
  259. default:
  260. if (cGideiCode >= LOWESTGIDEICODE) handleFatalError();
  261. else {
  262. handleErrorReport();
  263. commandVector = noOpRoutine;
  264. beginOK = TRUE;
  265. }
  266. break;
  267. }
  268. return;
  269. }
  270. void processBytes(unsigned char iGideiCode)
  271. {
  272. (*commandVector)(iGideiCode);
  273. if (!(--blockCount))
  274. {
  275. passAll = FALSE;
  276. codeVector = processGideiCode;
  277. }
  278. }
  279. void processBlock(unsigned char iGideiCode)
  280. {
  281. if (blockCount--) (*commandVector)(iGideiCode);
  282. else {
  283. passAll = FALSE;
  284. if (iGideiCode == TERMCODE) codeVector = processGideiCode;
  285. else handleFatalError();
  286. }
  287. }
  288. void processGideiBlockCount(unsigned char iGideiCode)
  289. {
  290. blockCount = iGideiCode;
  291. codeVector = processBlock;
  292. passAll = TRUE;
  293. }
  294. void processGideiClear(unsigned char iGideiCode)
  295. {
  296. if (iGideiCode == TERMCODE) initClear();
  297. else handleFatalError();
  298. }
  299. void processGideiEnd(unsigned char iGideiCode)
  300. {
  301. if (iGideiCode == TERMCODE) {
  302. if (!popCommandVector()) handleFatalError();
  303. else {
  304. if (restoreCommandVector()) {
  305. beginOK = TRUE;
  306. codeVector = processGideiCode;
  307. }
  308. else {
  309. commandVector = processCommand;
  310. codeVector = processCharMode;
  311. serialVector = charHandler;
  312. beginOK = FALSE;
  313. }
  314. lastCode = iGideiCode;
  315. }
  316. }
  317. else handleFatalError();
  318. }
  319. /****************************************************************************
  320. FUNCTION: processCOMMbaudrate(Code)
  321. PURPOSE: Processes the baudrate commands.
  322. COMMENTS:
  323. ****************************************************************************/
  324. void processBaudrate(unsigned char Code)
  325. {
  326. static int SetBaud = 0;
  327. switch(Code)
  328. {
  329. case TERMCODE:
  330. if (SetBaud != 0) /* valid one set */
  331. SkEx_SendBeep();
  332. break;
  333. case BAUD300CODE:
  334. SetBaud = ID_BAUD_300;
  335. SkEx_SetBaud(300);
  336. break;
  337. case BAUD600CODE:
  338. SetBaud = ID_BAUD_600;
  339. SkEx_SetBaud(600);
  340. break;
  341. case BAUD1200CODE:
  342. SetBaud = ID_BAUD_1200;
  343. SkEx_SetBaud(1200);
  344. break;
  345. case BAUD2400CODE:
  346. SetBaud = ID_BAUD_2400;
  347. SkEx_SetBaud(2400);
  348. break;
  349. case BAUD4800CODE:
  350. SetBaud = ID_BAUD_4800;
  351. SkEx_SetBaud(4800);
  352. break;
  353. case BAUD9600CODE:
  354. SetBaud = ID_BAUD_9600;
  355. SkEx_SetBaud(9600);
  356. break;
  357. case BAUD19200CODE:
  358. SetBaud = ID_BAUD_19200;
  359. SkEx_SetBaud(19200);
  360. break;
  361. case BAUD110CODE:
  362. SetBaud = ID_BAUD_110;
  363. SkEx_SetBaud(110);
  364. break;
  365. case BAUD14400CODE:
  366. SetBaud = ID_BAUD_14400;
  367. SkEx_SetBaud(14400);
  368. break;
  369. case BAUD38400CODE:
  370. SetBaud = ID_BAUD_38400;
  371. SkEx_SetBaud(38400);
  372. break;
  373. case BAUD56000CODE:
  374. SetBaud = ID_BAUD_56000;
  375. SkEx_SetBaud(56000);
  376. break;
  377. case BAUD57600CODE:
  378. SetBaud = ID_BAUD_57600;
  379. SkEx_SetBaud(57600);
  380. break;
  381. case BAUD115200CODE:
  382. SetBaud = ID_BAUD_115200;
  383. SkEx_SetBaud(115200);
  384. break;
  385. default:
  386. handleErrorReport();
  387. break;
  388. }
  389. }
  390. /****************************************************************************
  391. FUNCTION: processGideiCode
  392. PURPOSE:
  393. COMMENTS:
  394. *****************************************************************************/
  395. void processGideiCode(unsigned char iGideiCode)
  396. {
  397. if (waitForClear) {
  398. if (iGideiCode == CLEARCODE) codeVector = processGideiClear;
  399. else handleFatalError();
  400. return;
  401. }
  402. switch (iGideiCode) {
  403. case BEGINCODE:
  404. if (beginOK) {
  405. if (pushCommandVector()) lastCode = iGideiCode;
  406. else handleFatalError();
  407. }
  408. else handleFatalError();
  409. break;
  410. case ENDCODE:
  411. if (lastCode == TERMCODE) {
  412. codeVector = processGideiEnd;
  413. beginOK = FALSE;
  414. lastCode = iGideiCode;
  415. }
  416. else handleFatalError();
  417. break;
  418. case CLEARCODE:
  419. codeVector = processGideiClear;
  420. lastCode = iGideiCode;
  421. break;
  422. case TERMCODE:
  423. (*commandVector)(iGideiCode);
  424. if (!restoreCommandVector()) {
  425. commandVector = processCommand;
  426. codeVector = processCharMode;
  427. serialVector = charHandler;
  428. beginOK = FALSE;
  429. }
  430. else
  431. beginOK = TRUE;
  432. lastCode = iGideiCode;
  433. break;
  434. case BLKTRANSCODE:
  435. codeVector = processGideiBlockCount;
  436. (*commandVector)(iGideiCode);
  437. lastCode = iGideiCode;
  438. break;
  439. case BYTECODE:
  440. codeVector = processBytes;
  441. blockCount = 1;
  442. passAll = TRUE;
  443. (*commandVector)(iGideiCode);
  444. lastCode = iGideiCode;
  445. break;
  446. case INTEGERCODE:
  447. codeVector = processBytes;
  448. blockCount = 2;
  449. passAll = TRUE;
  450. (*commandVector)(iGideiCode);
  451. lastCode = iGideiCode;
  452. break;
  453. case LONGCODE:
  454. codeVector = processBytes;
  455. blockCount = 4;
  456. passAll = TRUE;
  457. (*commandVector)(iGideiCode);
  458. lastCode = iGideiCode;
  459. break;
  460. case DOUBLECODE:
  461. codeVector = processBytes;
  462. blockCount = 8;
  463. passAll = TRUE;
  464. (*commandVector)(iGideiCode);
  465. lastCode = iGideiCode;
  466. break;
  467. default:
  468. (*commandVector)(iGideiCode);
  469. lastCode = iGideiCode;
  470. break;
  471. }
  472. }
  473. /****************************************************************************
  474. FUNCTION: processCharMode
  475. PURPOSE: Handles processing of ASCII characters in Character Mode
  476. COMMENTS:
  477. ***************************************************************************/
  478. void processCharMode(unsigned char ucSerialByte)
  479. {
  480. unsigned char tempKeyCode;
  481. if (ucSerialByte == ESCAPE) {
  482. codeVector = processGideiCode;
  483. return;
  484. }
  485. if (waitForClear) {
  486. handleFatalError();
  487. return;
  488. }
  489. if ( ucSerialByte > 127 ) // Are We processing an Extended Code
  490. {
  491. sendExtendedKey(ucSerialByte); // Yes - Send Code
  492. return; // Exit
  493. }
  494. if ((tempKeyCode = (asciiTable[ucSerialByte]).gideiCode1) == NOCODE) {
  495. handleErrorReport();
  496. tempList.len = 0;
  497. return;
  498. }
  499. if ((!inLockList(tempKeyCode)) && (!inHoldList(tempKeyCode)))
  500. tempList.list[tempList.len++] = tempKeyCode;
  501. if ((tempKeyCode = asciiTable[ucSerialByte].gideiCode2) != NOCODE) {
  502. if ((!inLockList(tempKeyCode)) && (!inHoldList(tempKeyCode)))
  503. tempList.list[tempList.len++] = tempKeyCode;
  504. }
  505. sendCombineList();
  506. keyHoldList.len = tempList.len = 0;
  507. return;
  508. }
  509. /****************************************************************************
  510. FUNCTION: executeAlias()
  511. PURPOSE: Takes the alias string, convert to code, and then does
  512. proper processing.
  513. COMMENTS:
  514. *****************************************************************************/
  515. void executeAlias(void)
  516. {
  517. static unsigned char *cTempPtr;
  518. static int iTemp;
  519. cTempPtr = cAliasString;
  520. if (lstrlenA(cAliasString) > MAXALIASLEN) *cTempPtr = UNKNOWNCODE;
  521. else
  522. {
  523. if (!aliasForGideiCode(cTempPtr))
  524. {
  525. CharLowerA(cAliasString);
  526. if (!aliasUsedInStandard(cTempPtr))
  527. {
  528. /* Must be a number. But is it an ASCII coded number
  529. or ASCII coded GIDEI code */
  530. switch (cAliasString[0])
  531. {
  532. case '0':
  533. case '+':
  534. case '-':
  535. iTemp = AtoL(cAliasString);
  536. *cTempPtr = INTEGERCODE;
  537. storeByte(cTempPtr);
  538. cTempPtr = (unsigned char*) &iTemp;
  539. storeByte(cTempPtr++);
  540. break;
  541. default:
  542. /* must be a ASCII coded GIDEI code */
  543. iTemp = AtoL(cAliasString);
  544. if ((unsigned)iTemp > 255) *cTempPtr = UNKNOWNCODE;
  545. else *cTempPtr = (unsigned char) iTemp;
  546. break;
  547. }
  548. }
  549. }
  550. }
  551. storeByte(cTempPtr);
  552. return;
  553. }
  554. /****************************************************************************
  555. FUNCTION: processAlias(ucSerialByte)
  556. PURPOSE: This routine builds up the alias string and then passes
  557. control onto executeAlias.
  558. COMMENTS:
  559. *****************************************************************************/
  560. void processAlias(unsigned char ucSerialByte)
  561. {
  562. static unsigned char tempCode, *codePtr;
  563. static unsigned char sbtemp[2];
  564. codePtr = &tempCode;
  565. switch (ucSerialByte) {
  566. case ESCAPE:
  567. cAliasString[0] = '\0';
  568. break;
  569. case TAB:
  570. case LINEFEED:
  571. case VERTICALTAB:
  572. case FORMFEED:
  573. case RETURN:
  574. case SPACE:
  575. if (!lstrlenA(cAliasString)) break; /* if previous character was a */
  576. /* delimiter then eat white space */
  577. case COMMA:
  578. case PERIOD:
  579. if (lstrlenA(cAliasString)) executeAlias();
  580. else
  581. {
  582. tempCode = DEFAULTCODE;
  583. storeByte(codePtr);
  584. }
  585. if (ucSerialByte == '.')
  586. {
  587. tempCode = TERMCODE;
  588. storeByte(codePtr);
  589. }
  590. cAliasString[0] = '\0';
  591. for (;retrieveByte(codePtr);) (*codeVector)(tempCode);
  592. break;
  593. default:
  594. /* just add the char to the string */
  595. if ((ucSerialByte >= ' ') && (ucSerialByte <= '~'))
  596. {
  597. if (lstrlenA(cAliasString) < MAXALIASLEN+1) /*make sure room */
  598. {
  599. sbtemp[0] = ucSerialByte;
  600. sbtemp[1] = 0;
  601. lstrcatA(cAliasString,sbtemp);
  602. } else
  603. {
  604. DBPRINTF(TEXT("processAlias: no room\r\n"));
  605. }
  606. }
  607. else
  608. {
  609. handleFatalError(); /* not an alias */
  610. }
  611. }
  612. return;
  613. }
  614. /****************************************************************************
  615. FUNCTION: passAllCodes
  616. PURPOSE: Just keeps the GIDEI hierarchy consistant
  617. COMMENTS:
  618. ****************************************************************************/
  619. void passAllCodes(unsigned char cGideiCode)
  620. {
  621. (*codeVector)(cGideiCode);
  622. return;
  623. }
  624. /****************************************************************************
  625. FUNCTION: determineFormat
  626. PURPOSE: Figure out what Escape Sequence form (i.e. Alias, Code, KEI, etc)
  627. COMMENTS:
  628. ****************************************************************************/
  629. void determineFormat(unsigned char ucSerialByte)
  630. {
  631. static char cStuffStr[7], *cPtr;
  632. switch (ucSerialByte)
  633. {
  634. case COMMA:
  635. serialVector = processAlias;
  636. aliasPtr = commandsAliasTable;
  637. break;
  638. case ESC:
  639. break;
  640. default:
  641. if ((ucSerialByte >= ' ') && (ucSerialByte <= '~')) /* KEI Implied Press */
  642. {
  643. serialVector = processAlias;
  644. aliasPtr = commandsAliasTable;
  645. for (cPtr = strcpy(cStuffStr,"press,"); *cPtr != '\0'; cPtr++) processAlias(*cPtr);
  646. processAlias(ucSerialByte);
  647. }
  648. else
  649. {
  650. serialVector = passAllCodes;
  651. (*codeVector)(ucSerialByte);
  652. }
  653. break;
  654. }
  655. return;
  656. }
  657. /****************************************************************************
  658. FUNCTION: charHandler
  659. PURPOSE: If ESCAPE then set up new vectors. Also processes the char
  660. COMMENTS:
  661. ****************************************************************************/
  662. void charHandler(unsigned char ucSerialByte)
  663. {
  664. if (ucSerialByte == ESC) {
  665. serialVector = determineFormat;
  666. commandVector = processCommand;
  667. beginOK = TRUE;
  668. }
  669. (*codeVector)(ucSerialByte);
  670. return;
  671. }
  672. BOOL serialKeysBegin(unsigned char c)
  673. {
  674. static char junk[2];
  675. junk[0] = c;
  676. junk[1] = '\0';
  677. if (!passAll) {
  678. if (c == '\0')
  679. {
  680. SkEx_SendBeep();
  681. if ((++nullCount) >= 3) {
  682. initClear();
  683. SkEx_SendBeep();
  684. SkEx_SendBeep();
  685. SkEx_SendBeep();
  686. }
  687. }
  688. }
  689. (*serialVector)(c);
  690. return(TRUE);
  691. }
  692. long AtoL(char *s)
  693. {
  694. long num = 0;
  695. long sign = 1L;
  696. while(*s == ' ' || *s == '\t')
  697. s++;
  698. if( *s == '-' )
  699. {
  700. sign = -1L;
  701. s++;
  702. }
  703. else if( *s == '+' )
  704. {
  705. s++;
  706. }
  707. while('0' <= *s && *s <= '9')
  708. {
  709. num = 10 * num + *s - '0';
  710. s++;
  711. }
  712. return( sign * num );
  713. }