Commit | Line | Data |
---|---|---|
0683223a MW |
1 | /* -*-c-*- |
2 | * | |
0683223a MW |
3 | * Compare version numbers using the Debian algorithm |
4 | * | |
5 | * (c) 2007 Straylight/Edgeware | |
6 | */ | |
7 | ||
d4efbcd9 | 8 | /*----- Licensing notice --------------------------------------------------* |
0683223a MW |
9 | * |
10 | * This file is part of the mLib utilities library. | |
11 | * | |
12 | * mLib is free software; you can redistribute it and/or modify | |
13 | * it under the terms of the GNU Library General Public License as | |
14 | * published by the Free Software Foundation; either version 2 of the | |
15 | * License, or (at your option) any later version. | |
d4efbcd9 | 16 | * |
0683223a MW |
17 | * mLib is distributed in the hope that it will be useful, |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | * GNU Library General Public License for more details. | |
d4efbcd9 | 21 | * |
0683223a MW |
22 | * You should have received a copy of the GNU Library General Public |
23 | * License along with mLib; if not, write to the Free | |
24 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |
25 | * MA 02111-1307, USA. | |
26 | */ | |
27 | ||
28 | #ifndef MLIB_VERSIONCMP_H | |
29 | #define MLIB_VERSIONCMP_H | |
30 | ||
31 | #ifdef __cplusplus | |
32 | extern "C" { | |
33 | #endif | |
34 | ||
35 | /*----- Functions provided ------------------------------------------------*/ | |
36 | ||
37 | /* --- @versioncmp@ --- * | |
38 | * | |
39 | * Arguments: @const char *va, *vb@ = two version strings | |
40 | * | |
41 | * Returns: Less than, equal to, or greater than zero, according to | |
42 | * whether @va@ is less than, equal to, or greater than @vb@. | |
43 | * | |
44 | * Use: Compares version number strings. | |
45 | * | |
46 | * The algorithm is an extension of the Debian version | |
47 | * comparison algorithm. A version number consists of three | |
48 | * components: | |
49 | * | |
50 | * [EPOCH :] MAIN [- SUB] | |
51 | * | |
52 | * The MAIN part may contain colons or hyphens if there is an | |
53 | * EPOCH or SUB, respectively. Version strings are compared | |
54 | * componentwise: first epochs, then main parts, and finally | |
55 | * subparts. | |
56 | * | |
57 | * The component comparison is done as follows. First, the | |
58 | * initial subsequence of nondigit characters is extracted from | |
59 | * each string, and these are compared lexicographically, using | |
60 | * ASCII ordering, except that letters precede non-letters. If | |
61 | * both are the same, an initial sequence of digits is extracted | |
62 | * from the remaining parts of the version strings, and these | |
63 | * are compared numerically (an empty sequence being considered | |
64 | * to have the value zero). This process is repeated until we | |
65 | * have a winner or until both strings are exhausted. | |
66 | */ | |
67 | ||
68 | extern int versioncmp(const char */*va*/, const char */*vb*/); | |
69 | ||
70 | /*----- That's all, folks -------------------------------------------------*/ | |
71 | ||
72 | #ifdef __cplusplus | |
73 | } | |
74 | #endif | |
75 | ||
76 | #endif |