root/core/versions.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. get_val
  2. parse_version
  3. cmp_chdk_version
  4. chk_api_version

   1 #include "stdlib.h"
   2 
   3 //==========================================================
   4 _chdk_version_t chdk_version;
   5 
   6 //==========================================================
   7 static const char* get_val(const char *s, short *v)
   8 {
   9     if (s && *s)
  10     {
  11         *v = strtol(s, (char**)&s, 0);
  12         if (s && (*s == '.')) s++;
  13     }
  14     return s;
  15 }
  16 
  17 // Convert version strings into _chdk_version_t structure
  18 void parse_version(_chdk_version_t *ver, const char *build, const char *rev)
  19 {
  20     memset(ver, 0, sizeof(_chdk_version_t));
  21     build = get_val(build, &ver->major);
  22     build = get_val(build, &ver->minor);
  23     build = get_val(build, &ver->maintenance);
  24     get_val(build, &ver->revision);
  25     get_val(rev, &ver->revision);
  26 }
  27 
  28 // Compare two chdk versions
  29 // Returns 0 if equal, -1 if ver1 < ver2, 1 if ver1 > ver2
  30 int cmp_chdk_version(_chdk_version_t ver1, _chdk_version_t ver2)
  31 {
  32     if (ver1.major       < ver2.major)       return -1;
  33     if (ver1.major       > ver2.major)       return  1;
  34     if (ver1.minor       < ver2.minor)       return -1;
  35     if (ver1.minor       > ver2.minor)       return  1;
  36     if (ver1.maintenance < ver2.maintenance) return -1;
  37     if (ver1.maintenance > ver2.maintenance) return  1;
  38     if (ver1.revision    < ver2.revision)    return -1;
  39     if (ver1.revision    > ver2.revision)    return  1;
  40     return 0;
  41 }
  42 
  43 // Check requested api version against built api version
  44 // Returns 1 if requested version is compatible, 0 otherwise
  45 int chk_api_version(_version_t api_ver, _version_t req_ver)
  46 {
  47     if (req_ver.major == 0)     // Request match against ANY API
  48         return 1;
  49     // Compatible only if built API major version is the same, and minor is same or later
  50     if ((api_ver.major == req_ver.major) && (api_ver.minor >= req_ver.minor))
  51         return 1;
  52     return 0;
  53 
  54 }
  55 
  56 //==========================================================

/* [<][>][^][v][top][bottom][index][help] */