Skip to content

Instantly share code, notes, and snippets.

@asumagic
Created June 6, 2020 22:30
Show Gist options
  • Save asumagic/a05c18e7975793f93e93dbd946d63642 to your computer and use it in GitHub Desktop.
Save asumagic/a05c18e7975793f93e93dbd946d63642 to your computer and use it in GitHub Desktop.
#include <cstdlib>
#include <cstdio>
int StringEqualUntil(const char* s1, const char* s2, int n)
{
int c1, c2;
while (1)
{
c1 = *s1++;
c2 = *s2++;
if (!n--)
{
return 0;
} // strings are equal until end point
if (c1 != c2)
{
if (c1 >= 'a' && c1 <= 'z')
{
c1 -= ('a' - 'A');
}
if (c2 >= 'a' && c2 <= 'z')
{
c2 -= ('a' - 'A');
}
if (c1 != c2)
{
return - 1;
} // strings not equal
}
if (!c1)
{
return 0;
} // strings are equal
}
return - 1;
}
int MakeBuildNumber(char* date)
{
static const char* mon[12] =
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
char mond[12] =
{
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
int m = 0;
int d = 0;
int y = 0;
int b;
for (m = 0; m < 11; m++)
{
if (StringEqualUntil(&date[0], mon[m], 3) == 0)
{
break;
}
d += mond[m];
}
d += atoi(&date[4]) - 1;
y = atoi(&date[7]) - 1900;
b = d + (int)((y - 1) *365.25);
if (((y % 4) == 0) && m > 1)
{
b += 1;
}
b -= 40284; // Apr 17 2011
return b;
}
int main()
{
char date[] = __DATE__;
int buildnum = MakeBuildNumber( date );
printf("%d\n", buildnum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment