(file) Return to VersionUtil.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / General

  1 kavita.gupta 1.1 //%LICENSE////////////////////////////////////////////////////////////////
  2                  //
  3                  // Licensed to The Open Group (TOG) under one or more contributor license
  4                  // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5                  // this work for additional information regarding copyright ownership.
  6                  // Each contributor licenses this file to you under the OpenPegasus Open
  7                  // Source License; you may not use this file except in compliance with the
  8                  // License.
  9                  //
 10                  // Permission is hereby granted, free of charge, to any person obtaining a
 11                  // copy of this software and associated documentation files (the "Software"),
 12                  // to deal in the Software without restriction, including without limitation
 13                  // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14                  // and/or sell copies of the Software, and to permit persons to whom the
 15                  // Software is furnished to do so, subject to the following conditions:
 16                  //
 17                  // The above copyright notice and this permission notice shall be included
 18                  // in all copies or substantial portions of the Software.
 19                  //
 20                  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21                  // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 kavita.gupta 1.1 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23                  // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24                  // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25                  // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26                  // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27                  //
 28                  //////////////////////////////////////////////////////////////////////////
 29                  //
 30                  //%/////////////////////////////////////////////////////////////////////////////
 31                  
 32                  #include <Pegasus/Common/Config.h>
 33                  #include "VersionUtil.h"
 34                  
 35                  PEGASUS_NAMESPACE_BEGIN
 36                  
 37                  //
 38                  // Returns true if v1 has a higher or same version, else return false.
 39                  //
 40                  Boolean VersionUtil::isVersionGreaterOrEqual(
 41                      const String& v1,
 42                      Uint32 majorV2,
 43 kavita.gupta 1.1     Uint32 minorV2,
 44                      Uint32 updateV2)
 45                  {
 46                      Uint32 minorV1 = PEG_NOT_FOUND;
 47                      Uint32 majorV1 = PEG_NOT_FOUND;
 48                      Uint32 updateV1 = PEG_NOT_FOUND;
 49                  
 50                      int result;
 51                      char dummychar;
 52                      result = sscanf((const char*)v1.getCString(),
 53                          "%d.%d.%d%c",
 54                          &majorV1,
 55                          &minorV1,
 56                          &updateV1,
 57                          &dummychar);
 58                  
 59                      if (result != 3)
 60                      {
 61                          return false;
 62                      }
 63                  
 64 kavita.gupta 1.1     return ((majorV1 > majorV2) ||
 65                              ((majorV1 == majorV2) &&
 66                               ((minorV1 > minorV2) ||
 67                                ((minorV1 == minorV2) && (updateV1 >= updateV2)))));
 68                  }
 69                  
 70 kavita.gupta 1.2 Boolean VersionUtil::parseVersion(
 71                      const String& version,
 72                      Sint32& iMajor,
 73                      Sint32& iMinor,
 74                      Sint32& iUpdate)
 75                  {
 76                      const char CHAR_PERIOD = '.';
 77                  
 78                      if (!version.size())
 79                      {
 80                          return true;
 81                      }
 82                  
 83                      iMajor = 0;
 84                      iMinor = 0;
 85                      iUpdate = 0;
 86                  
 87                      Uint32 indexM = 0;
 88                      Uint32 sizeM = PEG_NOT_FOUND;
 89                      Uint32 indexN = PEG_NOT_FOUND;
 90                      Uint32 sizeN = PEG_NOT_FOUND;
 91 kavita.gupta 1.2     Uint32 indexU = PEG_NOT_FOUND;
 92                  
 93                      // If "V" specified as first character, ignore it
 94                      if ((version[0] == 'V') || (version[0] == 'v'))
 95                      {
 96                          indexM = 1;
 97                      }
 98                  
 99                      // Find the M, N, and U version fields delimited by '.' characters
100                  
101                      indexN = version.find(indexM, CHAR_PERIOD);
102                  
103                      if (indexN != PEG_NOT_FOUND)
104                      {
105                          sizeM = indexN++ - indexM;
106                  
107                          indexU = version.find(indexN, CHAR_PERIOD);
108                          if (indexU != PEG_NOT_FOUND)
109                          {
110                              sizeN = indexU++ - indexN;
111                          }
112 kavita.gupta 1.2     }
113                  
114                      // Parse the major version
115                      char dummyChar;
116                      int numConversions = sscanf(
117                          version.subString(indexM, sizeM).getCString(),
118                          "%u%c",
119                          &iMajor,
120                          &dummyChar);
121                  
122                      if (numConversions != 1)
123                      {
124                          return false;
125                      }
126                  
127                      // Parse the minor version
128                      if (indexN != PEG_NOT_FOUND)
129                      {
130                          numConversions = sscanf(
131                              version.subString(indexN, sizeN).getCString(),
132                              "%u%c",
133 kavita.gupta 1.2             &iMinor,
134                              &dummyChar);
135                  
136                          if (numConversions != 1)
137                          {
138                              return false;
139                          }
140                      }
141                  
142                      // Parse the update version
143                      if (indexU != PEG_NOT_FOUND)
144                      {
145                          numConversions = sscanf(
146                              version.subString(indexU).getCString(),
147                              "%u%c",
148                              &iUpdate,
149                              &dummyChar);
150                  
151                          if (numConversions != 1)
152                          {
153                              return false;
154 kavita.gupta 1.2         }
155                      }
156                  
157                      return true;
158                  }
159 kavita.gupta 1.1 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2