-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkproject_version.mata
82 lines (71 loc) · 1.55 KB
/
mkproject_version.mata
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
mata:
mata set matastrict on
real rowvector mpversion::parse_version(string scalar toparse)
{
string rowvector verspl
real rowvector result
verspl = tokens(toparse, ".")
if (cols(verspl)!= 5){
where_err()
errprintf("{p}A version has the form #.#.#{p_end}")
exit(198)
}
result = strtoreal(verspl[(1,3,5)])
if (anyof(result, .)){
where_err()
errprintf("{p}A version has the form #.#.#{p_end}")
exit(198)
}
toonew(result)
return(result)
}
void mpversion::header_version(string scalar value)
{
reading.fversion = parse_version(value)
}
void mpversion::where_err()
{
string scalar errmsg
errmsg = "{p}A problem occured when reading " + reading.fn +
" on line " + strofreal(reading.lnr) + "{p_end}"
errprintf(errmsg)
}
real scalar mpversion::lt(real rowvector a, real rowvector b)
{
real scalar i
if (cols(a) != 3 | cols(b) != 3) {
errprintf("{p}a and b need to have three columns{p_end}")
exit(198)
}
for(i=1; i<=3; i++) {
if (a[i] < b[i]) {
return(1)
}
if (a[1] > b[i]) {
return(0)
}
}
return(0)
}
void mpversion::new()
{
current_version = (2,1,3)
}
void mpversion::toonew(real rowvector val)
{
string scalar rmsg
if (cols(val)!=3) {
where_err()
errprintf("{p}val needs to have three columns{p_end}")
exit(198)
}
if (lt(current_version,val)) {
where_err()
rmsg = "{p}current version of mkproject is " +
invtokens(strofreal(current_version),".") +
" and it cannot handle versions larger than that{p_end}"
errprintf(rmsg)
exit(198)
}
}
end