main.c revision 98766
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 98766 2002-06-24 16:03:24Z markm $"); 23 24#include "lib.h" 25#include "version.h" 26#include <err.h> 27 28static char Options[] = "dhl:L:s:tv"; 29 30char *LimitChars = NULL; 31char *PreventChars = NULL; 32char *MatchName = NULL; 33 34static void usage __P((void)); 35 36int 37main(int argc, char **argv) 38{ 39 int ch, cmp = 0; 40 41 if (argc == 4 && !strcmp(argv[1], "-t")) { 42 cmp = version_cmp(argv[2], argv[3]); 43 printf(cmp > 0 ? ">\n" : (cmp < 0 ? "<\n" : "=\n")); 44 exit(0); 45 } 46 else while ((ch = getopt(argc, argv, Options)) != -1) { 47 switch(ch) { 48 case 'v': 49 Verbose = TRUE; 50 break; 51 52 case 'l': 53 LimitChars = optarg; 54 break; 55 56 case 'L': 57 PreventChars = optarg; 58 break; 59 60 case 's': 61 MatchName = optarg; 62 break; 63 64 case 't': 65 errx(2, "Invalid -t usage."); 66 break; 67 68 case 'h': 69 case '?': 70 default: 71 usage(); 72 break; 73 } 74 } 75 76 argc -= optind; 77 argv += optind; 78 79 return pkg_perform(argv); 80} 81 82static void 83usage() 84{ 85 fprintf(stderr, "%s\n%s\n", 86 "usage: pkg_version [-hv] [-l limchar] [-L limchar] [-s string] index", 87 " pkg_version -t v1 v2"); 88 exit(1); 89} 90