Magellan Linux

Contents of /branches/mage-next/src/highestver.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2807 - (show annotations) (download)
Wed Sep 3 11:53:06 2014 UTC (9 years, 7 months ago) by niro
File MIME type: text/plain
File size: 1842 byte(s)
-moved some common package functions to package.c/package.h
1 /*
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 #include "package.h"
24
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 char *saved;
38
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 saved = strdup(argv[1]);
47 }
48
49 // fasten things up
50 if(argc == 3) {
51 ret = alpm_pkg_vercmp(argv[1], argv[2]);
52 if(ret < 0) {
53 saved = strdup(argv[2]);
54 }
55 if(ret == 0) {
56 saved = strdup(argv[1]);
57 }
58 if(ret > 0) {
59 saved = strdup(argv[1]);
60 }
61 }
62
63 if(argc > 3) {
64 for(i=1; i < argc; i++) {
65 if (i == 1) {
66 saved = strdup(argv[i]);
67 }
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 saved = strdup(argv[i+1]);
72 }
73 }
74 }
75
76 if(strlen(saved) > 0) {
77 printf("%s\n", saved);
78 }
79
80 free(saved);
81 return EXIT_SUCCESS;
82 }