#include "functions.hh"

#include <vector>
#include <sstream>
#include <iostream>

void mkver(std::string s, std::vector<int>& v)
{
  size_t pos=0;
  while ((pos=s.find(".", pos))!=std::string::npos)
    s[pos]=' ';
  std::istringstream ss(s);
  int i=-1;
  ss >> i;
  while (i>=0)
    {
      v.push_back(i);
      i=-1;
      ss >> i;
    }
}

int
vercmp(std::string v1s, std::string v2s)
{
  std::vector<int> v1, v2;
  mkver(v1s, v1);
  mkver(v2s, v2);
  for (size_t i=0; i<v1.size() && i<v2.size(); i++)
    {
      if (v1[i]>v2[i])
	return 1;
      else if (v2[i]>v1[i])
	return -1;
    }
  if (v1.size()>v2.size())
    return 1;
  else if (v2.size()>v1.size())
    return -1;
  return 0;
}
