home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 21 / CD_ASCQ_21_040595.iso / dos / prg / c / freedos3 / source / jh_utils / reboot.c < prev    next >
C/C++ Source or Header  |  1995-01-07  |  2KB  |  81 lines

  1. /*********************************************************************
  2.  * This program reboots the computer, either a cold or warm boot.
  3.  *
  4.  * Much of the code was written by Mike O'Carroll,
  5.  * lena!mike@relay.EU.net, and later adapted by James Hall for use in
  6.  * Free-DOS.
  7.  *
  8.  * Since no copyright was placed on the original code, I am assuming
  9.  * that this entire program is in the public domain.
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include "getopt.h"
  14. #include "freedos.h"
  15.  
  16. #define COLD 0            /* for cold restart */
  17. #define WARM 0x1234        /* for warm restart */
  18.  
  19. #define BOOT_SEG        0xffffL
  20. #define BOOT_OFF        0x0000L
  21. #define BOOT_ADR        ((BOOT_SEG << 16) | BOOT_OFF)
  22.  
  23. #define DOS_SEG         0x0040L
  24. #define RESET_FLAG      0x0072L
  25. #define RESET_ADR       ((DOS_SEG << 16) | RESET_FLAG)
  26.  
  27.  
  28. void usage (void);
  29.  
  30.  
  31. main (int argc, char **argv)
  32. {
  33.   int c, magic = COLD;
  34.   void ((far * fp) ()) = (void (far *) ()) BOOT_ADR;
  35.  
  36.   /* Scan the command line */
  37.  
  38.   while ((c = getopt (argc, argv, "cCwW?")) != EOF)
  39.     {
  40.       switch (c)
  41.     {
  42.     case 'c':
  43.     case 'C':
  44.       magic = COLD;
  45.       break;
  46.  
  47.     case 'w':
  48.     case 'W':
  49.       magic = WARM;
  50.       break;
  51.  
  52.     default:
  53.       usage ();
  54.       break;
  55.     }
  56.     }
  57.  
  58.   if (optind < argc)
  59.     usage ();
  60.  
  61.   /* Reboot */
  62.  
  63.   *(int far *) RESET_ADR = magic;
  64.   (*fp) ();
  65.  
  66.   /* Never gets here, but keeps compiler happy */
  67.  
  68.   exit (0);
  69. }
  70.  
  71.  
  72. void 
  73. usage (void)
  74. {
  75.   printp ("REBOOT", "Reboots the computer.. either a cold or warm boot.");
  76.   printu ("REBOOT", "[/W | /C]");
  77.   printo ("/W", "Warm boot");
  78.   printo ("/C", "Cold boot");
  79.   exit (1);
  80. }
  81.