remove the const modifier from function arguments
[liba.git] / src / version.c
blobf3e9ee6baf0cf1637c46be4874802e5213fb39c0
1 #include "a/version.h"
2 #undef a_version_check
4 unsigned int const a_version_major = A_VERSION_MAJOR;
5 unsigned int const a_version_minor = A_VERSION_MINOR;
6 unsigned int const a_version_patch = A_VERSION_PATCH;
7 a_u32 const a_version_tweak = A_VERSION_TWEAK;
9 int a_version_check(unsigned int major, unsigned int minor, unsigned int patch)
11 a_version inner = A_VERSION_C(a_version_major, a_version_minor, a_version_patch);
12 a_version outer = A_VERSION_C(major, minor, patch);
13 return a_version_cmp(&inner, &outer);
16 int a_version_cmp(a_version const *lhs, a_version const *rhs)
18 if (lhs->major < rhs->major) { return -3; }
19 if (lhs->major > rhs->major) { return +3; }
20 if (lhs->minor < rhs->minor) { return -2; }
21 if (lhs->minor > rhs->minor) { return +2; }
22 if (lhs->patch < rhs->patch) { return -1; }
23 if (lhs->patch > rhs->patch) { return +1; }
24 return 0;
27 a_bool a_version_lt(a_version const *lhs, a_version const *rhs)
29 if (lhs->major < rhs->major) { return A_TRUE; }
30 if (lhs->major > rhs->major) { return A_FALSE; }
31 if (lhs->minor < rhs->minor) { return A_TRUE; }
32 if (lhs->minor > rhs->minor) { return A_FALSE; }
33 if (lhs->patch < rhs->patch) { return A_TRUE; }
34 if (lhs->patch > rhs->patch) { return A_FALSE; }
35 return A_FALSE;
38 a_bool a_version_gt(a_version const *lhs, a_version const *rhs)
40 if (lhs->major > rhs->major) { return A_TRUE; }
41 if (lhs->major < rhs->major) { return A_FALSE; }
42 if (lhs->minor > rhs->minor) { return A_TRUE; }
43 if (lhs->minor < rhs->minor) { return A_FALSE; }
44 if (lhs->patch > rhs->patch) { return A_TRUE; }
45 if (lhs->patch < rhs->patch) { return A_FALSE; }
46 return A_FALSE;
49 a_bool a_version_le(a_version const *lhs, a_version const *rhs)
51 if (lhs->major < rhs->major) { return A_TRUE; }
52 if (lhs->major > rhs->major) { return A_FALSE; }
53 if (lhs->minor < rhs->minor) { return A_TRUE; }
54 if (lhs->minor > rhs->minor) { return A_FALSE; }
55 if (lhs->patch < rhs->patch) { return A_TRUE; }
56 if (lhs->patch > rhs->patch) { return A_FALSE; }
57 return A_TRUE;
60 a_bool a_version_ge(a_version const *lhs, a_version const *rhs)
62 if (lhs->major > rhs->major) { return A_TRUE; }
63 if (lhs->major < rhs->major) { return A_FALSE; }
64 if (lhs->minor > rhs->minor) { return A_TRUE; }
65 if (lhs->minor < rhs->minor) { return A_FALSE; }
66 if (lhs->patch > rhs->patch) { return A_TRUE; }
67 if (lhs->patch < rhs->patch) { return A_FALSE; }
68 return A_TRUE;
71 a_bool a_version_eq(a_version const *lhs, a_version const *rhs)
73 return (lhs->major == rhs->major) && (lhs->minor == rhs->minor) && (lhs->patch == rhs->patch);
76 a_bool a_version_ne(a_version const *lhs, a_version const *rhs)
78 return (lhs->major != rhs->major) || (lhs->minor != rhs->minor) || (lhs->patch != rhs->patch);
81 unsigned int a_version_parse(a_version *ctx, char const *ver)
83 union
85 char const *s;
86 char *p;
87 } u = {ver};
88 if (!ver) { return 0; }
89 ctx->major = (unsigned int)strtoul(u.s, &u.p, 0);
90 if (u.s[0] == '.' && u.s[1] >= '0' && u.s[1] <= '9') { ++u.s; }
91 else { goto major; }
92 ctx->minor = (unsigned int)strtoul(u.s, &u.p, 0);
93 if (u.s[0] == '.' && u.s[1] >= '0' && u.s[1] <= '9') { ++u.s; }
94 else { goto minor; }
95 ctx->patch = (unsigned int)strtoul(u.s, &u.p, 0);
96 if (u.s[0] == '.' && u.s[1] >= '0' && u.s[1] <= '9') { ++u.s; }
97 else { goto patch; }
98 ctx->extra = (unsigned int)strtoul(u.s, &u.p, 0);
99 goto extra;
100 major:
101 ctx->minor = 0;
102 minor:
103 ctx->patch = 0;
104 patch:
105 ctx->extra = 0;
106 extra:
107 return (unsigned int)(u.s - ver);