home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l440 / 2.ddi / CHAP5 / TEST2E.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-24  |  1.9 KB  |  76 lines

  1. /* TEST2E.C -- version to build TSR2E */
  2.  
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <dos.h>
  6.  
  7. #include "put.h"
  8.  
  9. #define MK_FP(seg,ofs) \
  10.     ((void far *)(((unsigned long)(seg) << 16) | (ofs)))
  11.  
  12. extern unsigned foreground_psp;     // in TSREXAMP.C
  13. extern int Send2E(char *command);   // in SEND2E.C
  14.     
  15. static char buf[80];
  16. static int running = 0;
  17.  
  18. typedef enum { SAVE=0, RESTORE } SAVEREST;
  19. typedef void (interrupt far *INTVECT)();
  20.  
  21. void interrupts(int restore)
  22. {
  23.     static INTVECT int_1b, int_23, int_24;
  24.     if (restore)
  25.     {
  26.         _dos_setvect(0x1b, int_1b);
  27.         _dos_setvect(0x23, int_23);
  28.         _dos_setvect(0x24, int_24);
  29.     }
  30.     else
  31.     {
  32.         int_1b = _dos_getvect(0x1b);
  33.         int_23 = _dos_getvect(0x23);
  34.         int_24 = _dos_getvect(0x24);
  35.     }
  36. }
  37.  
  38. void application(void)
  39. {
  40.     // don't run if we are already running
  41.     if (running)
  42.         return;
  43.     running++;
  44.  
  45.     // don't execute INT 2Eh if COMMAND.COM already running
  46.     // see if COMMAND.COM running by checking if current PSP is the
  47.     // same as its own parent
  48.     // THIS TEST IS IMPORTANT!  POPPING UP THIS 2E SHELL WHILE
  49.     // COMMAND.COM IS ALREADY RUNNING CAUSES A CRASH AS SOON AS
  50.     // YOU EXIT!
  51.     if (foreground_psp == 
  52.         *((unsigned far *) MK_FP(foreground_psp, 0x16)))
  53.     {
  54.         put_str("COMMAND.COM already running");
  55.         running--;
  56.         return;
  57.     }
  58.     
  59.     put_str("TSR COMMAND SHELL: type DOS commands, or BYE to quit\r\n");
  60.     for (;;)
  61.     {
  62.         put_str("$ ");
  63.         if (! get_str(buf, 80))
  64.             break;
  65.         // added since printing of book: accept EXIT as well as BYE
  66.         if ((strcmp(buf, "bye") == 0 || strcmp(buf, "BYE") == 0) ||
  67.             (strcmp(buf, "exit") == 0 || strcmp(buf, "EXIT") == 0))
  68.             break;
  69.         interrupts(SAVE);
  70.         Send2E(buf);
  71.         interrupts(RESTORE);
  72.     }
  73.     putstr("Bye");
  74.     running--;
  75. }
  76.