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.

214 lines
7.0 KiB

  1. /* File: cloop.hh (created 12/27/93, JKH)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 1 $
  7. * $Date: 10/05/98 12:39p $
  8. */
  9. // These constants are used to turn on various types of debug display
  10. //#define DBG_NORMAL
  11. //#define DBG_YIELD
  12. //#define DBG_OUT
  13. #if defined(DBG_NORMAL)
  14. #define DEBUGSTR
  15. #define DBGOUT_NORMAL(s,a1,a2,a3,a4,a5) DbgOutStr(s,a1,a2,a3,a4,a5)
  16. #else
  17. #define DBGOUT_NORMAL(s,a1,a2,a3,a4,a5)
  18. #endif
  19. #if defined(DBG_YIELD)
  20. #define DEBUGSTR
  21. #define DBGOUT_YIELD(s,a1,a2,a3,a4,a5) DbgOutStr(s,a1,a2,a3,a4,a5)
  22. #else
  23. #define DBGOUT_YIELD(s,a1,a2,a3,a4,a5)
  24. #endif
  25. /* --- Constants --- */
  26. #define STD_BLOCKSIZE 512
  27. #define CLOOP_TRACKING_DELAY 1000L
  28. #define SF_CLOOP_SENDCRLF 0x200
  29. #define SF_CLOOP_EXPAND 0x201
  30. #define SF_CLOOP_LOCALECHO 0x202
  31. #define SF_CLOOP_LINEWAIT 0x203
  32. #define SF_CLOOP_WAITCHAR 0x204
  33. #define SF_CLOOP_EXTABSOUT 0x205
  34. #define SF_CLOOP_TABSIZEOUT 0x206
  35. #define SF_CLOOP_LINEDELAY 0x207
  36. #define SF_CLOOP_CHARDELAY 0x208
  37. #define SF_CLOOP_ADDLF 0x209
  38. #define SF_CLOOP_ASCII7 0x20A
  39. #define SF_CLOOP_ECHOPLEX 0x20B
  40. //Removed. Moved to emulator settings. 0x20C now available.
  41. //#define SF_CLOOP_WRAPLINES 0x20C
  42. #define SF_CLOOP_SHOWHEX 0x20D
  43. #define SF_CLOOP_TABSIZEIN 0x20E
  44. #define SF_CLOOP_DBCS 0x20F
  45. // Values for the usOptions field in ST_CLOOP_OUT
  46. // The first three are defined in cloop.h because they can be
  47. // used in the options arguments of CLoopSend()
  48. // #define CLOOP_KEYS 0x0001
  49. // #define CLOOP_ALLOCATED 0x0002
  50. // #define CLOOP_SHARED 0x0004
  51. #define CLOOP_CHARACTERS 0x0008
  52. #define CLOOP_TEXTFILE 0x0010
  53. #define CLOOP_OPENFILE 0x0020
  54. #define CLOOP_TEXTDSP 0x0040
  55. #define CLOOP_STDSIZE 0x8000
  56. // offsets into event array for blocking
  57. #define EVENT_CONTROL 0
  58. #define EVENT_RCV 1
  59. #define EVENT_SEND 2
  60. /* --- Typedefs --- */
  61. // Support for queued output routines
  62. typedef struct s_cloop_out ST_CLOOP_OUT;
  63. typedef struct s_func_chain ST_FCHAIN;
  64. typedef struct s_cloop_settings ST_CLOOP_SETTINGS;
  65. typedef struct s_cloop ST_CLOOP;
  66. /* --- Structure definitions --- */
  67. struct s_cloop_out
  68. {
  69. ST_CLOOP_OUT *pstNext;
  70. unsigned uOptions; // keys/chars? allocated? shared?
  71. HGLOBAL hdlShared; // shared mem handle
  72. TCHAR *puchData; // address of data block
  73. TCHAR *puchLimit; // first addr. past data block
  74. TCHAR *puchHead; // where data is added to block
  75. TCHAR *puchTail; // where data is removed from block
  76. unsigned long ulBytes; // size of file being sent
  77. TCHAR chLastChar; // last byte out
  78. };
  79. struct s_func_chain
  80. {
  81. ST_FCHAIN *pstNext; // pointer to next in chain
  82. ST_FCHAIN *pstPrior; // pointer to prior in chain
  83. ST_CLOOP *pstParent; // handle of owning CLoop
  84. CHAINFUNC pfFunc; // function to call
  85. void *pvUserData; // data supplied by caller when registered
  86. };
  87. // Structure to hold user-settable values
  88. struct s_cloop_settings
  89. {
  90. // for sending:
  91. int fSendCRLF; // TRUE to add LF to CR when sent
  92. int fExpandBlankLines; // TRUE to expand blank lines with space
  93. int fLocalEcho; // TRUE to echo typed chars.
  94. int fLineWait; // TRUE to wait for mcWaitChar
  95. TCHAR chWaitChar; // Char to wait for after sending line
  96. int fExpandTabsOut;
  97. int nTabSizeOut; // Default outgoing tab alignment
  98. int nLineDelay; // Delay in msecs. after each line
  99. int nCharDelay; // Delay in msecs. after each char.
  100. // for receiving
  101. int fAddLF; // TRUE to append LF to rcvd. CR
  102. int fASCII7; // TRUE to strip high bit on input
  103. int fEchoplex; // TRUE to echo rmt. chars.
  104. int fShowHex; // TRUE to show hex val. for ctrl chars.
  105. int nTabSizeIn; // Default incoming tab alignment
  106. };
  107. // CLOOP Handle definition structure
  108. struct s_cloop
  109. {
  110. HSESSION hSession; // Parent session
  111. HEMU hEmu; // Emulator handle for quick ref.
  112. HCOM hCom; // Com handle for quick ref.
  113. unsigned afControl; // Bits that control CLoop actions
  114. unsigned afRcvBlocked; // Bits to inhibit receiving
  115. unsigned afSndBlocked; // Bits to inhibit sending
  116. int nRcvBlkCnt; // Script receive block count
  117. int fRcvBlkOverride; // Override for receive block count
  118. int fSuppressDsp; // TRUE to suppress display of data
  119. int nPriorityCount; // Keeps track of how often we yield
  120. // Receive delay control to implement cursor tracking
  121. int fDataReceived; // TRUE when new data received
  122. HTIMER htimerRcvDelay; // Timer to catch delay in data
  123. HTIMER htimerCharDelay; // Timer for char&line delays
  124. TIMERCALLBACK pfRcvDelay; // Call back when rcv. delay timer fires
  125. TIMERCALLBACK pfCharDelay; // Call back when char delay timer fires
  126. // send control
  127. ST_CLOOP_OUT *pstFirstOutBlock; // End of output chain to send from
  128. ST_CLOOP_OUT *pstLastOutBlock; // End of output chain to add to
  129. unsigned long ulOutCount; // # of chars or keys awaiting output
  130. HANDLE hOutFile; // handle of file being sent
  131. KEY_T keyLastKey;
  132. KEY_T keyHoldKey;
  133. // Send display window control
  134. int fTextDisplay;
  135. HWND hwndDsp;
  136. HGLOBAL hDisplayBlock; // Memory from GlobalAlloc for DDE link
  137. unsigned long ulTotalSend;
  138. unsigned long ulSentSoFar;
  139. HTIMER hTimerTextDsp;
  140. long lTimeStarted;
  141. TIMERCALLBACK pfTimerProc;
  142. // function chaining
  143. ST_FCHAIN *pstRmtChain; // Chain of functions to call with
  144. ST_FCHAIN *pstRmtChainNext; // with each input char. from rmt.
  145. int fRmtChain; // Quick test if anything is in chain
  146. // User settings
  147. ST_CLOOP_SETTINGS stOrigSettings; // Settings as stored in file
  148. ST_CLOOP_SETTINGS stWorkSettings; // Settings in current use
  149. // for learning
  150. LPVOID lpLearn; // A generic handle
  151. // Translation table pointers
  152. TCHAR *panFltrIn; // Translation table - incoming data
  153. TCHAR *panFltrOut; // Translation table - outgoing data
  154. TCHAR *panFltrInHold; // Holding place for the pointer
  155. TCHAR *panFltrOutHold; // Holding place for the pointer
  156. // Engine thread handle
  157. HANDLE hEngineThread;
  158. // Synchronization objects
  159. CRITICAL_SECTION csect;
  160. HANDLE ahEvents[3]; // 0=loop control,
  161. // 1=receive control
  162. // 2=send control
  163. // added for MBCS input support
  164. int fDoMBCS; // Enables MBCS processing
  165. TCHAR cLeadByte; // If this is non-zero, then the last
  166. // character was a lead byte and we are
  167. // building a multi-byte character
  168. TCHAR cLocalEchoLeadByte; // Ditto
  169. };
  170. /* --- Internal function prototypes --- */
  171. DWORD WINAPI CLoop(LPVOID pvData);
  172. void CLoopCharIn(ST_CLOOP *pstCLoop, ECHAR chIn);
  173. void CALLBACK CLoopRcvDelayProc(void *pvData, long lSince);
  174. void CALLBACK CLoopCharDelayProc(void *pvData, long lSince);
  175. int CLoopGetNextOutput(ST_CLOOP * const pstCLoop, KEY_T * const pkKey);
  176. ST_CLOOP_OUT *CLoopNewOutBlock(ST_CLOOP *pstCLoop, const size_t sizetData);
  177. void CLoopRemoveFirstOutBlock(ST_CLOOP * const pstCLoop);