home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / drives / drives.c next >
Text File  |  1987-05-11  |  3KB  |  148 lines

  1. /*
  2.  * List the status of the various drives that PC-DOS knows about.
  3.  *
  4.  * Characteristics that are checked for are:
  5.  *    - does DOS know about the drive
  6.  *    - does the drive support removable media
  7.  *    - is the drive redirected to a network device
  8.  *    - what network device is a drive directed to
  9.  *
  10.  *
  11.  *
  12.  * version 1.0  5may87 mgm - initial release
  13.  *         1.1         mgm - added pc.h in the includes.
  14.  *
  15.  */
  16.  
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <dos.h>
  20. #include <pc.h>
  21.  
  22.  
  23. #define HELLO  "DRIVES  version 1.1"
  24.  
  25. char lbuf[128];
  26. char nbuf[128];
  27.  
  28. char *prns[] = { "prn", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", NULL } ;
  29.  
  30.  
  31. void main (argc, argv)
  32.    int argc;
  33.    char *argv[];
  34. {
  35.    int i;
  36.    int rc;
  37.    char dbuf[5];
  38.  
  39.  
  40.    cprintf ("%s\n\n", HELLO);
  41.  
  42.    for (i = 1; i < 27; i++) {           /* check disk drive status */
  43.  
  44.       rc = isnetdc (i);                 /* network drive? */
  45.       switch (rc) {
  46.  
  47.          case 0:
  48.             cprintf ("   %c:  local drive", i - 1 + 'A');
  49.             if (0 == isfixmed (i))
  50.                cprintf (", removable media");
  51.             cprintf (".\n");
  52.             break;
  53.  
  54.          case 1:
  55.             sprintf (dbuf, "%c:", i - 1 + 'A');
  56.             rc = getredir (dbuf, lbuf, nbuf);
  57.             if (rc == 0) cprintf ("   %s  network drive, redirected to: %s.\n",
  58.                                 lbuf, nbuf);
  59.             break;
  60.  
  61.          default:
  62.             break;
  63.  
  64.       } /* switch (rc) */
  65.  
  66.    } /* for... */
  67.  
  68.  
  69.    if (isnet () && isneton ()) {
  70.  
  71.       cprintf ("\n");
  72.  
  73.       for (i = 0; prns[i] != NULL; i++) {  /* loop through printer table */
  74.  
  75.          rc = getredir (prns[i], lbuf, nbuf);
  76.          if (rc == 0)
  77.             cprintf ("   %s redirected to: %s.\n", lbuf, nbuf);
  78.  
  79.       } /* for ... */
  80.  
  81.    } /* if (isnet... */
  82.  
  83.  
  84.    exit (0);
  85.  
  86. } /* main () */
  87.  
  88.  
  89. /******************************************************************************
  90.  * Does the device in question support removable media?
  91.  *  returns:  0 - removable
  92.  *            1 - fixed
  93.  *         0x0F - error
  94.  */
  95. int isfixmed (drv)
  96.    int drv;
  97. {
  98.    union REGS reg;
  99.  
  100.    reg.h.ah = 0x44;
  101.    reg.h.al = 0x08;
  102.    reg.h.bl = drv;
  103.  
  104.    intdos (®, ®);
  105.  
  106.    return (reg.x.ax);
  107.  
  108. } /* int isfixmed */
  109.  
  110.  
  111.  
  112. /******************************************************************************
  113.  * obtain the redirection for a network device
  114.  */
  115. int getredir (devnam, lclbuf, netbuf)
  116.    char *devnam;
  117.    char *lclbuf;
  118.    char *netbuf;
  119. {
  120.    int i;
  121.    int rc;
  122.    int rdtype;
  123.    int parm;
  124.    char lname[128];
  125.  
  126.    extern int _OSERR;
  127.  
  128.    _OSERR = 0;
  129.    rc = -1;
  130.    for (i = 0; _OSERR != 18; i++) {     /* loop through redirection table */
  131.  
  132.       rdtype = pcngdr (i, lname, netbuf, &parm);
  133.  
  134.       if (rdtype == 4 || rdtype == 3) {       /* disk: 4, printer: 3 */
  135.          if (0 == stricmp (lname, devnam)) {
  136.             strcpy (lclbuf, lname);
  137.             rc = 0;
  138.             break;
  139.          } /* if (0 == stricmp... */
  140.       } /* if (rdtype */
  141.  
  142.    } /* for... */
  143.  
  144.    return (rc);
  145.  
  146. } /* int getredir () */
  147.  
  148.