summaryrefslogtreecommitdiffstats
path: root/tests/check_relpEngineVersion.c
blob: 69b6700a04c2b23a32355373b0e22e3112fced78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

/* only care about first two digits */
void parseVersionNumberFromStr(char *pszIn, long* piMajor, long* piMinor, long* piSubMinor) {
	char *p = pszIn;
	while (*p) { // While there are more characters to process...
		if ( isdigit(*p) || ( (*p=='-'||*p=='+') && isdigit(*(p+1)) )) {
			if (*piMajor == 0) {
				*piMajor = strtol(p, &p, 10); // Read number
			} else if (*piMinor == 0) {
				*piMinor = strtol(p, &p, 10); // Read number
			} else {
				*piSubMinor = strtol(p, &p, 10); // Read number
				return;
			}
		} else {
			p++;
		}
	}
}

int main(int argc __attribute__((unused)), char *argv[]__attribute__((unused)))
{
	long iRelpVerMajor = 0;
	long iRelpVerMinor = 0;
	long iRelpVerSubMinor = 0;
	long iRelpCmpMajor = 0;
	long iRelpCmpMinor = 0;
	long iRelpCmpSubMinor = 0;

#if defined(RELP_VERSION)
	parseVersionNumberFromStr(RELP_VERSION, &iRelpVerMajor, &iRelpVerMinor, &iRelpVerSubMinor);
	if (argc > 1) {
		parseVersionNumberFromStr(argv[1], &iRelpCmpMajor, &iRelpCmpMinor, &iRelpCmpSubMinor);

		// Compare Version numbers
		if (	iRelpVerMajor > iRelpCmpMajor  ||
			(	iRelpVerMajor == iRelpCmpMajor &&
				iRelpVerMinor > iRelpCmpMinor ) ||
			(	iRelpVerMajor == iRelpCmpMajor &&
				iRelpVerMinor == iRelpCmpMinor &&
				iRelpVerSubMinor >= iRelpCmpSubMinor)
			) {
			printf("RELP Version %ld.%ld.%ld OK (Requested Version %ld.%ld.%ld)\n",
				iRelpVerMajor, iRelpVerMinor, iRelpVerSubMinor,
				iRelpCmpMajor, iRelpCmpMinor, iRelpCmpSubMinor);
			return 0;
		} else {
			printf("RELP Version %ld.%ld.%ld NOT OK (Requested Version %ld.%ld.%ld)\n",
				iRelpVerMajor, iRelpVerMinor, iRelpVerSubMinor,
				iRelpCmpMajor, iRelpCmpMinor, iRelpCmpSubMinor);
			return 1;
		}

	} else {
		printf("RELP Version %s\n", RELP_VERSION);
	}
	return 0;
#else
	printf("RELP Version unknown\n");
	return 1;
#endif
}