/* * Copyright (c) 2006-2011 Pacman Development Team * * 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 of the License, 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. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include /* printf */ #include #include #include "package.h" #define BASENAME "highestver" static void usage(void) { fprintf(stderr, "usage: %s ... \n", BASENAME); fprintf(stderr, "prints the highest version.\n"); } int main(int argc, char *argv[]) { int i; int ret; char *saved = NULL; if(argc == 1) { usage(); return 2; } // only one argument given, that is the highest one if(argc == 2) { saved = strdup(argv[1]); } // fasten things up if(argc == 3) { ret = alpm_pkg_vercmp(argv[1], argv[2]); if(ret < 0) { saved = strdup(argv[2]); } if(ret == 0) { saved = strdup(argv[1]); } if(ret > 0) { saved = strdup(argv[1]); } } if(argc > 3) { for(i=1; i < argc; i++) { if (i == 1) { saved = strdup(argv[i]); } ret = alpm_pkg_vercmp(saved, argv[i+1]); // retval >0 or 0 means saved i the higher on, no need to strcmp if(ret < 0) { saved = strdup(argv[i+1]); } } } if(strlen(saved) > 0) { printf("%s\n", saved); } free(saved); return EXIT_SUCCESS; }