This repository has been archived by the owner on Oct 19, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
support.c
100 lines (83 loc) · 2.25 KB
/
support.c
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Support functions for the ESP Package Manager (EPM).
*
* Copyright 1999-2014 by Michael R Sweet
* Copyright 1999-2006 by Easy Software Products.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/*
* Include necessary headers...
*/
#include "epm.h"
/*
* 'get_vernumber()' - Convert a version string to a number...
*/
int /* O - Version number */
get_vernumber(const char *version) /* I - Version string */
{
int numbers[4], /* Raw version numbers */
nnumbers, /* Number of numbers in version */
temp, /* Temporary version number */
offset; /* Offset for last version number */
const char *ptr; /* Pointer into string */
/*
* Loop through the version number string and construct a version number.
*/
memset(numbers, 0, sizeof(numbers));
for (ptr = version; *ptr && !isdigit(*ptr & 255); ptr ++);
/* Skip leading letters, periods, etc. */
for (offset = 0, temp = 0, nnumbers = 0; *ptr && !isspace(*ptr & 255); ptr ++)
if (isdigit(*ptr & 255))
temp = temp * 10 + *ptr - '0';
else
{
/*
* Add each mini version number (m.n.p) and patch/pre stuff...
*/
if (nnumbers < 4)
{
numbers[nnumbers] = temp;
nnumbers ++;
}
temp = 0;
if (*ptr == '.')
offset = 0;
else if (*ptr == 'p' || *ptr == '-')
{
if (strncmp(ptr, "pre", 3) == 0)
{
ptr += 2;
offset = -20;
}
else
offset = 0;
nnumbers = 3;
}
else if (*ptr == 'b')
{
offset = -50;
nnumbers = 3;
}
else /* if (*ptr == 'a') */
{
offset = -100;
nnumbers = 3;
}
}
if (nnumbers < 4)
numbers[nnumbers] = temp;
/*
* Compute the version number as MMmmPPpp + offset
*/
return (((numbers[0] * 100 + numbers[1]) * 100 + numbers[2]) * 100 +
numbers[3] + offset);
}