Windows NT 4.0 source code leak
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.

230 lines
6.7 KiB

4 years ago
  1. #include "cmd.h"
  2. //
  3. // console mode at program startup time. Used to reset mode
  4. // after running another process.
  5. //
  6. extern DWORD dwCurInputConMode;
  7. extern DWORD dwCurOutputConMode;
  8. extern int Ctrlc;
  9. VOID ResetCtrlC();
  10. int SigHandFlag = FALSE ;
  11. /* Commands that temporarily change directories, save a ptr to the original
  12. * directory string here so that it can be restored by SigHand() if the
  13. * command is interrupted before it has a chance to do it, itself.
  14. */
  15. TCHAR *SaveDir = NULL ;
  16. unsigned SIGNALcnt = 0;
  17. extern int PipeCnt ; /* M016 - Cnt of active pipes */
  18. extern int LastRetCode ;
  19. extern jmp_buf MainEnv ;
  20. extern jmp_buf CmdJBuf1 ;
  21. extern unsigned long OHTbl[] ; /* M024 - Revised to be bit map */
  22. extern PHANDLE FFhandles; /* @@1 */
  23. extern unsigned FFhndlsaved; /* @@1 */
  24. extern struct sellist *prexxsellist;
  25. extern struct rio *rioCur ; /* M000 */
  26. extern struct batdata *CurBat ;
  27. extern TCHAR *Fvars ; /* M026 */
  28. extern TCHAR **Fsubs ; /* M026 */
  29. extern TCHAR *save_Fvars ; /* @@ */
  30. extern TCHAR **save_Fsubs ; /* @@ */
  31. extern int FvarsSaved; /* @@ */
  32. extern TCHAR InternalError[] ;
  33. extern int EchoFlag ;
  34. extern int EchoSave ; /* M013 - Used to restore echo status */
  35. extern TCHAR ComSpec[] ; /* M008 - For clearing SM shared memory */
  36. extern TCHAR ComSpecStr[] ; /* M026 - Use ComSpec for SM memory */
  37. extern TCHAR *CmdSpec ; /* M026 */
  38. extern TCHAR GotoFlag ;
  39. extern unsigned Heof;
  40. extern struct batdata *CurBat; /* Ptr to current batch data structure */
  41. extern unsigned start_type ; /* Flag to indicate which API started the */
  42. /* program. D64 */
  43. extern BOOL CtrlCSeen;
  44. extern PTCHAR pszTitleCur;
  45. extern BOOLEAN fTitleChanged;
  46. void
  47. Abort( void )
  48. {
  49. DEBUG((SHGRP, MSLVL, "SIGHAND: Aborting Command")) ;
  50. SigCleanUp();
  51. longjmp(MainEnv, 1) ;
  52. CMDexit( FAILURE );
  53. }
  54. void
  55. CtrlCAbort( ) {
  56. struct batdata *bdat;
  57. if (CurBat) {
  58. if (!PromptUser(NULL, MSG_BATCH_TERM)) {
  59. ResetCtrlC();
  60. return;
  61. }
  62. //
  63. // End local environments ( Otherwise we can end up with garbage
  64. // in the main environment if any batch file used the setlocal
  65. // command ).
  66. //
  67. bdat = CurBat;
  68. while ( bdat ) {
  69. EndLocal( bdat );
  70. bdat = bdat->backptr;
  71. }
  72. }
  73. SigCleanUp();
  74. longjmp(MainEnv, 1) ;
  75. }
  76. void
  77. CheckCtrlC (
  78. ) {
  79. if (CtrlCSeen) {
  80. CtrlCAbort();
  81. }
  82. }
  83. void
  84. ExitAbort(
  85. IN ULONG rcExitCode
  86. )
  87. {
  88. SigCleanUp();
  89. longjmp(MainEnv, rcExitCode) ;
  90. CMDexit( FAILURE );
  91. }
  92. /*** SigCleanUp - close files and reset I/O after a signal
  93. *
  94. * Purpose:
  95. * This function is called to finish the cleanup after an int 23 or 24.
  96. * It resets all redirection back to the main level and it closes all
  97. * files except those for stdin, stdout, stderr, stdaux and stdprint.
  98. *
  99. * void SigCleanUp()
  100. *
  101. * Args:
  102. * None.
  103. *
  104. * Returns:
  105. * Nothing.
  106. *
  107. * Notes:
  108. * - M024 * Revised handle closing to be bit map based rather than struct.
  109. *
  110. */
  111. void SigCleanUp() /* M000 - Now void */
  112. {
  113. int i = 0 ; /* Temp variable */
  114. int cnt, cnt2 ;
  115. unsigned long mask;
  116. Heof = FALSE;
  117. #ifndef WIN95_CMD
  118. if (CurBat) {
  119. // 27-May-1993 sudeepb
  120. // Following CmdBatNotification call is a cleanup for the
  121. // same call made from BatProc (in cbatch.c).
  122. CmdBatNotification (CMD_BAT_OPERATION_TERMINATING);
  123. EchoFlag = EchoSave ;
  124. GotoFlag = FALSE ;
  125. eEndlocal((struct cmdnode *) NULL) ;
  126. CurBat = NULL ;
  127. } ;
  128. #endif // WIN95_CMD
  129. if (!FvarsSaved) { /* @WM If already saved, don't save again */
  130. save_Fvars = Fvars; /* @@ */
  131. save_Fsubs = Fsubs; /* @@ */
  132. FvarsSaved = TRUE; /* @@ */
  133. }
  134. Fvars = NULL ; /* M026 - Must kill FOR */
  135. Fsubs = NULL ; /* ...variable subst's */
  136. /* M000 - New method is simpler. If redirection has been done, the highest
  137. * numbered handle resulting from redirection is saved, then the linked
  138. * riodata list is unlinked until the first (main) level of redirection is
  139. * reached at which time ResetRedir is used to reset it. Then all open
  140. * handles from 5 to the highest numbered redirection handle (minimum of
  141. * 19) are freed.
  142. * M014 - Altered this to use actual global pointer when unwinding the
  143. * riodata list to fix bug. Also revised the ->stdio element to conform
  144. * to new data structure. Note that ResetRedir automatically resets the
  145. * rioCur pointer to the last valid riodata structure before returning;
  146. * same as if "rioCur=rioCur->back" was in the while loop.
  147. */
  148. DEBUG((SHGRP, MSLVL, "SCLEANUP: Resetting redirection.")) ;
  149. if (rioCur) {
  150. i = rioCur->stdio ; /* Save highest handle */
  151. while (rioCur)
  152. ResetRedir() ;
  153. } ;
  154. DEBUG((SHGRP, MSLVL, "SCLEANUP: Breaking pipes.")) ;
  155. BreakPipes() ;
  156. DEBUG((SHGRP, MSLVL, "SCLEANUP: Now closing extra handles.")) ;
  157. for (cnt = 0; cnt < 3; cnt++) {
  158. if (OHTbl[cnt]) { /* Any handles to reset? */
  159. mask = 1; /* @@1 */
  160. for (cnt2 = 0; cnt2 < 32; cnt2++, mask <<= 1) { /* @@1 */
  161. if ((OHTbl[cnt] & mask) && /* @@1 */
  162. ((cnt == 0 && cnt2 > 2) || cnt != 0) ) { /* @@1 */
  163. /* Don't close STDIN, STDOUT, STDERR */ /* @@1 */
  164. Cclose(cnt2 + 32*cnt); /* @@1 */
  165. } /* @@1 */
  166. } /* @@1 */
  167. } /* @@1 */
  168. }
  169. /* Close find first handles */ /* @@1 */
  170. while (FFhndlsaved) { /* findclose will dec this @@1 */
  171. findclose(FFhandles[FFhndlsaved - 1]); /* @@1 */
  172. } /* @@1 */
  173. ResetConTitle( pszTitleCur );
  174. ResetConsoleMode();
  175. DEBUG((SHGRP, MSLVL, "SCLEANUP: Returning.")) ;
  176. }