home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / xbase / library / clipper / pwrmake / checkvol.c next >
Encoding:
C/C++ Source or Header  |  1992-07-04  |  3.4 KB  |  149 lines

  1. /*  Program:    CHECKVOL.C
  2.     Author:     Clifford Wiebe
  3.     Date:       Tue  02-19-1991
  4.     Purpose:    Dos allows you to put volume labels on disks,
  5.                 but does not give you any way of using that
  6.                 information.
  7.  
  8.                 The volume label check is not case sensitive,
  9.                 which should reduce the batch file code somewhat.
  10.  
  11.                 This program is given freely to the public domain.
  12.                 If it is of some use to you, great.  I have found
  13.                 this program of great use in creating installation
  14.                 batch files and checking for volume labels before
  15.                 making / restoring backups. No warranty implied or
  16.                 given.
  17.  
  18.         Clifford Wiebe
  19.         CIS: 73670,1377
  20.         Compiled using Turbo C 2.0
  21.  
  22. */
  23.  
  24. /* INCLUDES */
  25. #include <stdio.h>
  26. #include <dos.h>
  27.  
  28.  
  29. /* CONSTANTS */
  30. #define BEEP  7
  31. #define TRUE  1
  32. #define FALSE 0
  33.  
  34. #define NOERROR 0
  35.  
  36. #define NOVOL   1
  37.  
  38. static struct
  39. {
  40.  unsigned char ExtCode;
  41.  char Resl [5];
  42.  unsigned char Code;
  43.  unsigned char OldDrive;
  44.  char OldName[11];
  45.  char Res2[5];
  46.  char NewName [11];
  47.  char Res3[9];
  48. }
  49.  
  50. DirFcb = {'\xff',"",'\x10'},
  51. VolFcb = {'\xff',"",'\x08','\0',"???????????"};
  52.  
  53. static struct
  54.   {
  55. char Res1 [8];
  56. char OldVolid [11];
  57. char Res2 [5];
  58. char NewVolid[11];
  59. char Res3[9];
  60. }
  61.   Dta;
  62.  
  63.  
  64.   int FilError;
  65.   int Length;
  66.  
  67. /* LOCAL FUNCTION PROTOTYPES */
  68.  
  69. char *FilGetVolid (int Drive);
  70. void rtrim(char *Volid, int Length);
  71.  
  72. /* Start of main program            */
  73. main (int argc, char *argv[])
  74. {
  75.    char *Volid;
  76.    char *VolLabel;
  77.    int Drive;
  78.  
  79. if (argc == 1 && argv[1] == "?")
  80. {
  81.     printf("CHECKVOL, 1991\n\n");
  82.     printf("Usage: CHECKVOL [d:]volume\n");
  83.     printf("Returns: ERRORLEVEL 0 if Volume is the same.\n");
  84.     printf("Returns  ERRORLEVEL 1 if Volume is not the same.\n\n");
  85.     printf("ie: Checkvol b:startup\n");
  86.     printf("    if errorlevel 1 echo Disk in Drive B: is not Startup!\n");
  87.     return(0);
  88. }
  89. Drive = toupper(argv[1][0]) - 64;
  90.  
  91. VolLabel = argv[1];
  92. ++VolLabel;
  93. ++VolLabel;
  94. Volid = FilGetVolid(Drive);
  95. rtrim(Volid,11);
  96. if(!stricmp(Volid,VolLabel))
  97.   exit(0);
  98. else
  99.   exit(1);
  100. }
  101.  
  102. /***********************************************************
  103.  
  104. char *FilGetVolid (int Drive)
  105. {
  106.   int ErrorCode;
  107.   _DX = (unsigned int)&Dta;         /* pass address of DTA  */
  108.   _AH = 0x1a;
  109.   geninterrupt( 0x21);
  110.  
  111.   VolFcb.OldDrive = Drive;
  112.   _DX = (unsigned int)&VolFcb;
  113.   _AH = 0x11;
  114.   geninterrupt(0x21);
  115.  
  116.   ErrorCode = _AL;
  117.   if (ErrorCode == 0)
  118.   {
  119.     FilError = NOERROR;
  120.     return (Dta.OldVolid);
  121.   }
  122.   else
  123.   {
  124.     FilError = NOVOL;
  125.     return (NULL);
  126.   }
  127. } /* End of FilGetVolid */
  128.  
  129. /***********************************************************
  130.  
  131. void rtrim(char *String, int Length)
  132.     {
  133.     char *ChPt;
  134.  
  135.     if (Length < 1)
  136.         return;
  137.     ChPt = String + Length - 1; /* points to last character of string */
  138.  
  139.     /* Scan backwards in string until first nonblank, */
  140.     /* non-null character */
  141.     while (ChPt > String && (*ChPt == '\0' || *ChPt == ''))
  142.         --ChPt;
  143.  
  144.     if (*ChPt == '\0' || *ChPt == ' ')      /* string entirely blank/null   */
  145.         *ChPt = '\0';                       /* null at first position       */
  146.     else if (ChPt < String + Length - 1)    /* String  contains nonblank     */
  147.         *(++ChPt) = '\0';                   /* non-null character(s)        */
  148. }
  149.