home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / cbgi111 / src / detect.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-18  |  3.0 KB  |  83 lines

  1. /***************************** DETECT.C *********************************/
  2. /*    An "universal" initialization routine that automatically    */
  3. /* "detects" any appropriate user driver.  It does this either by using    */
  4. /* the name of a driver passed to it, or an enviroment variable.    */
  5. /*    The enviroment variable is BGIDRIVER and by placing a line like    */
  6. /*                                    */
  7. /*        SET BGIDRIVER= drivername drivermode            */
  8. /*                                    */
  9. /* in the 'autoexec.bat' this routine will use that to "detect" and    */
  10. /* initialize the driver named 'drivername' in the mode 'drivermade'.    */
  11. /* This selection may be overridden either by specifying a specific    */
  12. /* builtin driver or by passing the name of the driver to detect.    */
  13. /*                                    */
  14. /* int universal_initgraph(                        */
  15. /*    char *driver_name,    Name of user driver to use.        */
  16. /*    int  *driver_no,    Either DETECT (if autodetection is     */
  17. /*                wanted, or the # of the internal    */
  18. /*                driver to use.                */
  19. /*    int  *mode,        Mode to init driver to.            */
  20. /*    char *path        Path containing the driver.        */
  21. /*    );                                */
  22. /*                                    */
  23. /*    This routine either returns zero, or it will return -1 if the    */
  24. /* enviroment variable BGIDRIVER is badly formed.            */
  25. /*                                    */
  26. /*  Copyright 1990 Robert Adsett.  This routine may be freely used as    */
  27. /*  long as an appropriate acknowledgement is made.            */
  28. /*                                    */
  29. /*    V 1.00    18/05/90 R. Adsett  Original Version.            */
  30. /************************************************************************/
  31.  
  32. #include <graphics.h>
  33.  
  34. static int DetectMode;        /* Mode for detect routine to use.    */
  35.  
  36.     /* Autodetect routine, tell kernal to init to' DetectMode'.    */
  37. static int huge Universal_Auto_Detect( void )
  38. {
  39.  
  40. return( DetectMode);
  41. }
  42.  
  43. int universal_initgraph(    /* Initialize to (possible) user driver.*/
  44.     char *driver_name,    /* Name of user driver to use.        */
  45.     int  *driver_no,    /* Either DETECT (if autodetection is     */
  46.                 /*  wanted, or the # of the internal    */
  47.                 /*  driver to use.            */
  48.     int  *mode,        /* Mode to init driver to.        */
  49.     char *path        /* Path containing the driver.        */
  50.     )
  51. {
  52. char new_driver[8];
  53.  
  54. if( *driver_no == DETECT)        /* Auto detect wanted.        */
  55.     {
  56.         /*   If no driver name is provided attempt to get one from the    */
  57.     /* environment.  If there is not one there either, a         */
  58.     /* conventional autodect will be done.  If a driver name is    */
  59.     /* found somewhere it is installed via 'installuserdriver()'.    */
  60.     if( driver_name == NULL)
  61.          {
  62.      if( (driver_name = getenv( "BGIDRIVER")) != NULL)
  63.           {
  64.           if( sscanf( driver_name, "%s %d", new_driver, &DetectMode)
  65.                                                                  != 2)
  66.                {
  67.                return( -1);
  68.                }
  69.               installuserdriver( new_driver, Universal_Auto_Detect);
  70.           }
  71.      }
  72.     else
  73.          {
  74.      DetectMode = *mode;
  75.          installuserdriver( driver_name, Universal_Auto_Detect);
  76.      }
  77.     }
  78. initgraph( driver_no, mode, path);    /* Init.            */
  79. return( 0);
  80. }
  81.  
  82.  
  83.