main.c revision 131275
1/* 2 * FreeBSD install - a package for the installation and maintainance 3 * of non-core utilities. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * Jeremy D. Lea. 15 * 11 May 2002 16 * 17 * This is the version module. Based on pkg_version.pl by Bruce A. Mah. 18 * 19 */ 20 21#include <sys/cdefs.h> 22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/version/main.c 131275 2004-06-29 18:54:47Z eik $"); 23 24#include "lib.h" 25#include "version.h" 26#include <err.h> 27 28static char Options[] = "dhl:L:s:XtTv"; 29 30char *LimitChars = NULL; 31char *PreventChars = NULL; 32char *MatchName = NULL; 33Boolean RegexExtended = FALSE; 34 35static void usage __P((void)); 36 37int 38main(int argc, char **argv) 39{ 40 int ch, cmp = 0; 41 42 if (argc == 4 && !strcmp(argv[1], "-t")) { 43 cmp = version_cmp(argv[2], argv[3]); 44 printf(cmp > 0 ? ">\n" : (cmp < 0 ? "<\n" : "=\n")); 45 exit(0); 46 } 47 else if (argc == 4 && !strcmp(argv[1], "-T")) { 48 cmp = version_match(argv[3], argv[2]); 49 exit(cmp == 1 ? 0 : 1); 50 } 51 else while ((ch = getopt(argc, argv, Options)) != -1) { 52 switch(ch) { 53 case 'v': 54 Verbose = TRUE; 55 break; 56 57 case 'l': 58 LimitChars = optarg; 59 break; 60 61 case 'L': 62 PreventChars = optarg; 63 break; 64 65 case 's': 66 MatchName = optarg; 67 break; 68 69 case 't': 70 errx(2, "Invalid -t usage."); 71 break; 72 73 case 'T': 74 errx(2, "Invalid -T usage."); 75 break; 76 77 case 'X': 78 RegexExtended = TRUE; 79 break; 80 81 case 'h': 82 case '?': 83 default: 84 usage(); 85 break; 86 } 87 } 88 89 argc -= optind; 90 argv += optind; 91 92 return pkg_perform(argv); 93} 94 95static void 96usage() 97{ 98 fprintf(stderr, "%s\n%s\n%s\n", 99 "usage: pkg_version [-hv] [-l limchar] [-L limchar] [[-X] -s string] index", 100 " pkg_version -t v1 v2", 101 " pkg_version -T name pattern"); 102 exit(1); 103} 104