]>
Commit | Line | Data |
---|---|---|
d04baaba | 1 | /* |
a86015f7 JSJ |
2 | * vercmp.c - Compare package version numbers using pacman's version |
3 | * comparison logic | |
23229097 | 4 | * |
d2882404 | 5 | * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org> |
d04baaba | 6 | * Copyright (c) 2002-2005 by Judd Vinet <jvinet@zeroflux.org> |
23229097 | 7 | * |
d04baaba JV |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
9781d0d6 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
d04baaba JV |
20 | */ |
21 | ||
04dc87e0 | 22 | #include <stdlib.h> |
f4dbb204 | 23 | #include <stdio.h> /* printf */ |
ae7139ad | 24 | #include <string.h> |
869e81e1 | 25 | |
5c46ba14 DM |
26 | /* forward declaration, comes from version.o in libalpm source that is linked |
27 | * in directly so we don't have any library deps */ | |
eb6af031 DM |
28 | int alpm_pkg_vercmp(const char *a, const char *b); |
29 | ||
0ff2a914 | 30 | static void usage(void) |
2e51e284 | 31 | { |
a86015f7 JSJ |
32 | fprintf(stderr, "vercmp (pacman) v" PACKAGE_VERSION "\n\n" |
33 | "Compare package version numbers using pacman's version comparison logic.\n\n" | |
34 | "Usage: vercmp <ver1> <ver2>\n\n" | |
35 | "Output values:\n" | |
36 | " < 0 : if ver1 < ver2\n" | |
37 | " 0 : if ver1 == ver2\n" | |
38 | " > 0 : if ver1 > ver2\n"); | |
2e51e284 DM |
39 | } |
40 | ||
d04baaba JV |
41 | int main(int argc, char *argv[]) |
42 | { | |
0ff2a914 DM |
43 | const char *s1 = ""; |
44 | const char *s2 = ""; | |
d04baaba JV |
45 | int ret; |
46 | ||
2e51e284 DM |
47 | if(argc == 1) { |
48 | usage(); | |
0303b26b | 49 | return 2; |
2e51e284 DM |
50 | } |
51 | if(argc > 1 && | |
52 | (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0 | |
53 | || strcmp(argv[1], "--usage") == 0)) { | |
54 | usage(); | |
0303b26b | 55 | return 0; |
2e51e284 | 56 | } |
d04baaba | 57 | if(argc > 2) { |
0ff2a914 DM |
58 | s2 = argv[2]; |
59 | } | |
60 | if(argc > 1) { | |
61 | s1 = argv[1]; | |
d04baaba | 62 | } |
23229097 | 63 | |
f8cd4858 | 64 | ret = alpm_pkg_vercmp(s1, s2); |
d04baaba | 65 | printf("%d\n", ret); |
0303b26b | 66 | return EXIT_SUCCESS; |
d04baaba | 67 | } |