home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cidsam.zip / CHKLVL.C < prev    next >
C/C++ Source or Header  |  1993-06-28  |  4KB  |  98 lines

  1.                   /*********************************/
  2.                   /*              NOTE             */
  3.                   /*                               */
  4.                   /* This sample code has been     */
  5.                   /* provided by IBM.  It is not   */
  6.                   /* warranted for any particular  */
  7.                   /* use or purpose.               */
  8.                   /*                               */
  9.                   /* IBM releases this code into   */
  10.                   /* the public domain.  You may   */
  11.                   /* use it, modify it, or         */
  12.                   /* incorporate it into other     */
  13.                   /* products without restriction. */
  14.                   /*********************************/
  15. /* Check the IBMLVL.INI file for the application and level.  Return 2 if */
  16. /* a later level of the application is installed.  Return 1 if the same  */
  17. /* level is installed.  Return 0 if an earlier level or no level is      */
  18. /* installed.
  19. /*                                                                       */
  20. /* Command line syntax is                                                */
  21. /*      chklvl product release.version                                   */
  22. /* Example:                                                              */
  23. /*      chklvl IBM_UPM 2.00                                              */
  24. /*                                                                       */
  25.  /*********************************************************************/
  26. #pragma page (1)
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #define INCL_WIN
  31. #include <os2.h>
  32.  
  33. char *srelease = "RELEASE";
  34. char *sversion = "VERSION";
  35. #define STRSIZE 20
  36.  
  37. int main(int argc, char **argv)
  38. {
  39.    HAB   hab;
  40.    HINI  hini;
  41.    USHORT rc;
  42.    ULONG bufsize = STRSIZE;
  43.    char cInstRelease[STRSIZE];   /* should be plenty big enough */
  44.    char cInstVersion[STRSIZE];
  45.    int iInstRelease, iInstVersion;
  46.    int iTestRelease, iTestVersion;
  47.    ULONG lenfound, instchk, testchk;
  48.    char *p;
  49.  
  50.    if (argc < 4)
  51.      {
  52.         printf("Usage: getcfcfg inifile product version.release\n");
  53.         return(0);
  54.      }
  55.  
  56.    p = argv[3];
  57.    iTestRelease = atoi(p);
  58.    for (; *p && *p != '.'; p++);
  59.    if (*p)
  60.      p++;
  61.    iTestVersion = atoi(p);
  62.    rc = 0;
  63.    hab = WinInitialize(0);
  64.    hini = PrfOpenProfile(hab, argv[1]);
  65.    if (hini)
  66.      {
  67.         lenfound = PrfQueryProfileString(hini, argv[2], srelease, NULL,
  68.                                         cInstRelease, (ULONG)bufsize);
  69.         if (lenfound > 0)
  70.           {
  71.             strcpy(cInstVersion, "00");
  72.             lenfound = PrfQueryProfileString(hini, argv[2], sversion, NULL,
  73.                                             cInstVersion, (ULONG)bufsize);
  74.             printf("Version %s.%s of %s is installed.\n",
  75.                              cInstRelease,
  76.                                 cInstVersion,
  77.                                      argv[2]);
  78.             iInstRelease = atoi(cInstRelease);
  79.             iInstVersion = atoi(cInstVersion);
  80.             testchk = iTestRelease * 100 + iTestVersion;
  81.             instchk = iInstRelease * 100 + iInstVersion;
  82.             if (instchk > testchk)
  83.               rc = 2;
  84.             else
  85.               if (instchk == testchk)
  86.                 rc = 1;
  87.           }
  88.         else
  89.           printf("%s is not in profile %s\n", argv[2], argv[1]);
  90.         PrfCloseProfile(hini);
  91.      }
  92.  
  93.    if (hab)
  94.      WinTerminate(hab);
  95.  
  96.    return(rc);
  97. }
  98.