/*
 * versioncheck.h: Converting xml-files from the web to cEvents
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */
#ifndef __VERSIONCHECK_H
#define __VERSIONCHECK_H

struct cVersion{
  int major, minor, release, extra, extraversion;
};

cVersion Verfromchar(const char* c){
  cVersion Res;
  char *e;
  int N = sscanf(c, "%i.%i.%i-%a[^-]-%i", &Res.major, &Res.minor, &Res.release, &e, &Res.extraversion);
  if(N == 0)
    Res.major = 0;
  if(N <= 1)
    Res.minor = 0;
  if(N <= 2)
    Res.release = 0;
  if(N <= 3)
    Res.extra = 0;
  if(N <= 4)
    Res.extraversion = 0;
  if(N >= 4){
    if(strcmp(e, "alpha") == 0)
      Res.extra = -3;
    else if(strcmp(e, "beta") == 0)
      Res.extra = -2;
    else if(strcmp(e, "rc") == 0)
      Res.extra = -1;
    else if(strcmp(e, "a") == 0)
      Res.extra = 1;
    else if(strcmp(e, "b") == 0)
      Res.extra = 2;
    else if(strcmp(e, "c") == 0)
      Res.extra = 3;
    else
      Res.extra = 0;
  }
  return Res;
};

bool operator<(cVersion a, cVersion b){
  if(a.major < b.major) return true;
  if(a.major > b.major) return false;
  if(a.minor < b.minor) return true;
  if(a.minor > b.minor) return false;
  if(a.release < b.release) return true;
  if(a.release > b.release) return false;
  if(a.extra < b.extra) return true;
  if(a.extra > b.extra) return false;
  if(a.extraversion < b.extraversion) return true;
  if(a.extraversion > b.extraversion) return false;
  return false;
};

#endif
