libalpm
Arch Linux Package Manager Library
|
00001 /* 00002 * vercmp.c 00003 * 00004 * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org> 00005 * Copyright (c) 2002-2005 by Judd Vinet <jvinet@zeroflux.org> 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #include <stdlib.h> 00022 #include <stdio.h> /* printf */ 00023 #include <string.h> 00024 00025 #define BASENAME "vercmp" 00026 00027 /* forward declaration, comes from version.o in libalpm source that is linked 00028 * in directly so we don't have any library deps */ 00029 int alpm_pkg_vercmp(const char *a, const char *b); 00030 00031 static void usage(void) 00032 { 00033 fprintf(stderr, "usage: %s <ver1> <ver2>\n\n", BASENAME); 00034 fprintf(stderr, "output values:\n"); 00035 fprintf(stderr, " < 0 : if ver1 < ver2\n"); 00036 fprintf(stderr, " 0 : if ver1 == ver2\n"); 00037 fprintf(stderr, " > 0 : if ver1 > ver2\n"); 00038 } 00039 00040 int main(int argc, char *argv[]) 00041 { 00042 const char *s1 = ""; 00043 const char *s2 = ""; 00044 int ret; 00045 00046 if(argc == 1) { 00047 usage(); 00048 return 2; 00049 } 00050 if(argc > 1 && 00051 (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0 00052 || strcmp(argv[1], "--usage") == 0)) { 00053 usage(); 00054 return 0; 00055 } 00056 if(argc > 2) { 00057 s2 = argv[2]; 00058 } 00059 if(argc > 1) { 00060 s1 = argv[1]; 00061 } 00062 00063 ret = alpm_pkg_vercmp(s1, s2); 00064 printf("%d\n", ret); 00065 return EXIT_SUCCESS; 00066 }