home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / docum / dos-ref.doc / examples / chap5.arj / TEST2E.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-26  |  1.6 KB  |  71 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.     if (foreground_psp == 
  49.         *((unsigned far *) MK_FP(foreground_psp, 0x16)))
  50.     {
  51.         put_str("COMMAND.COM already running");
  52.         running--;
  53.         return;
  54.     }
  55.     
  56.     put_str("TSR COMMAND SHELL: type DOS commands, or BYE to quit\r\n");
  57.     for (;;)
  58.     {
  59.         put_str("$ ");
  60.         if (! get_str(buf, 80))
  61.             break;
  62.         if (strcmp(buf, "bye") == 0 || strcmp(buf, "BYE") == 0)
  63.             break;
  64.         interrupts(SAVE);
  65.         Send2E(buf);
  66.         interrupts(RESTORE);
  67.     }
  68.     putstr("Bye");
  69.     running--;
  70. }
  71.