Skip to content

Commit

Permalink
Rewrite vernum function
Browse files Browse the repository at this point in the history
Fixes: #211
  • Loading branch information
floppym authored and skvadrik committed Aug 28, 2018
1 parent ab647f6 commit 348d868
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions re2c/src/conf/msg.cc
Expand Up @@ -102,23 +102,22 @@ void usage()
void vernum ()
{
std::string vernum (PACKAGE_VERSION);
if (vernum[1] == '.')
{
vernum.insert(0, "0");
}
vernum.erase(2, 1);
if (vernum[3] == '.')
{
vernum.insert(2, "0");
}
vernum.erase(4, 1);
if (vernum.length() < 6 || vernum[5] < '0' || vernum[5] > '9')
std::string parts[3];
unsigned p = 0;

for (unsigned i = 0; p < 3 && i < vernum.length (); i++)
{
vernum.insert(4, "0");
if (vernum[i] == '.')
p++;
else
parts[p].push_back (vernum[i]);
}
vernum.resize(6, '0');

printf ("%s\n", vernum.c_str ());
for (p = 0; p < 3; p++)
while (parts[p].length () < 2)
parts[p].insert (0, 1, '0');

printf ("%s%s%s\n", parts[0].c_str (), parts[1].c_str (), parts[2].c_str ());
}

void version ()
Expand Down

0 comments on commit 348d868

Please sign in to comment.