Annotation of /branches/mage-next/src/highestver.c
Parent Directory | Revision Log
Revision 2808 -
(hide annotations)
(download)
Wed Sep 3 11:54:26 2014 UTC (9 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1849 byte(s)
Wed Sep 3 11:54:26 2014 UTC (9 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1849 byte(s)
-initialize saved char
1 | niro | 2585 | /* |
2 | * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include <stdlib.h> | ||
19 | #include <stdio.h> /* printf */ | ||
20 | #include <string.h> | ||
21 | #include <ctype.h> | ||
22 | |||
23 | niro | 2807 | #include "package.h" |
24 | niro | 2585 | |
25 | #define BASENAME "highestver" | ||
26 | |||
27 | static void usage(void) | ||
28 | { | ||
29 | fprintf(stderr, "usage: %s <ver1> <ver2> ... <verN>\n", BASENAME); | ||
30 | fprintf(stderr, "prints the highest version.\n"); | ||
31 | } | ||
32 | |||
33 | int main(int argc, char *argv[]) | ||
34 | { | ||
35 | int i; | ||
36 | int ret; | ||
37 | niro | 2808 | char *saved = NULL; |
38 | niro | 2585 | |
39 | if(argc == 1) { | ||
40 | usage(); | ||
41 | return 2; | ||
42 | } | ||
43 | |||
44 | // only one argument given, that is the highest one | ||
45 | if(argc == 2) { | ||
46 | niro | 2629 | saved = strdup(argv[1]); |
47 | niro | 2585 | } |
48 | |||
49 | // fasten things up | ||
50 | if(argc == 3) { | ||
51 | ret = alpm_pkg_vercmp(argv[1], argv[2]); | ||
52 | if(ret < 0) { | ||
53 | niro | 2629 | saved = strdup(argv[2]); |
54 | niro | 2585 | } |
55 | if(ret == 0) { | ||
56 | niro | 2629 | saved = strdup(argv[1]); |
57 | niro | 2585 | } |
58 | if(ret > 0) { | ||
59 | niro | 2629 | saved = strdup(argv[1]); |
60 | niro | 2585 | } |
61 | } | ||
62 | |||
63 | if(argc > 3) { | ||
64 | for(i=1; i < argc; i++) { | ||
65 | if (i == 1) { | ||
66 | niro | 2629 | saved = strdup(argv[i]); |
67 | niro | 2585 | } |
68 | ret = alpm_pkg_vercmp(saved, argv[i+1]); | ||
69 | // retval >0 or 0 means saved i the higher on, no need to strcmp | ||
70 | if(ret < 0) { | ||
71 | niro | 2629 | saved = strdup(argv[i+1]); |
72 | niro | 2585 | } |
73 | } | ||
74 | } | ||
75 | |||
76 | if(strlen(saved) > 0) { | ||
77 | printf("%s\n", saved); | ||
78 | } | ||
79 | |||
80 | niro | 2630 | free(saved); |
81 | niro | 2585 | return EXIT_SUCCESS; |
82 | } |