main.c revision 285830
1/* 2 * FreeBSD install - a package for the installation and maintenance 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: releng/10.2/usr.sbin/pkg_install/version/main.c 241830 2012-10-22 02:12:20Z eadler $"); 23 24 25#include <getopt.h> 26#include <err.h> 27 28#include "lib.h" 29#include "version.h" 30 31char *LimitChars = NULL; 32char *PreventChars = NULL; 33char *MatchName = NULL; 34char *LookUpOrigin = NULL; 35Boolean RegexExtended = FALSE; 36Boolean UseINDEXOnly = FALSE; 37Boolean ShowOrigin = FALSE; 38 39static void usage(void); 40 41static char opts[] = "dIhl:L:qs:XtTO:ov"; 42static struct option longopts[] = { 43 { "extended", no_argument, NULL, 'X' }, 44 { "help", no_argument, NULL, 'h' }, 45 { "match", required_argument, NULL, 's' }, 46 { "no-status", required_argument, NULL, 'L' }, 47 { "origin", required_argument, NULL, 'O' }, 48 { "quiet", no_argument, NULL, 'q' }, 49 { "show-origin",no_argument, NULL, 'o' }, 50 { "status", required_argument, NULL, 'l' }, 51 { "index-only", no_argument, NULL, 'I' }, 52 { "verbose", no_argument, NULL, 'v' }, 53 { NULL, 0, NULL, 0 } 54}; 55 56int 57main(int argc, char **argv) 58{ 59 int ch, cmp = 0; 60 61 warnpkgng(); 62 if (argc == 4 && !strcmp(argv[1], "-t")) { 63 cmp = version_cmp(argv[2], argv[3]); 64 printf(cmp > 0 ? ">\n" : (cmp < 0 ? "<\n" : "=\n")); 65 exit(0); 66 } 67 else if (argc == 4 && !strcmp(argv[1], "-T")) { 68 cmp = version_match(argv[3], argv[2]); 69 exit(cmp == 1 ? 0 : 1); 70 } 71 else while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) { 72 switch(ch) { 73 case 'v': 74 Verbose++; 75 break; 76 77 case 'I': 78 UseINDEXOnly = TRUE; 79 break; 80 81 case 'l': 82 LimitChars = optarg; 83 break; 84 85 case 'L': 86 PreventChars = optarg; 87 break; 88 89 case 'q': 90 Quiet = TRUE; 91 break; 92 93 case 's': 94 MatchName = optarg; 95 break; 96 97 case 'O': 98 LookUpOrigin = optarg; 99 break; 100 101 case 'o': 102 ShowOrigin = TRUE; 103 break; 104 105 case 't': 106 errx(2, "Invalid -t usage."); 107 break; 108 109 case 'T': 110 errx(2, "Invalid -T usage."); 111 break; 112 113 case 'X': 114 RegexExtended = TRUE; 115 break; 116 117 case 'h': 118 default: 119 usage(); 120 break; 121 } 122 } 123 124 argc -= optind; 125 argv += optind; 126 127 return pkg_perform(argv); 128} 129 130static void 131usage(void) 132{ 133 fprintf(stderr, "%s\n%s\n%s\n", 134 "usage: pkg_version [-hIoqv] [-l limchar] [-L limchar] [[-X] -s string] [-O origin] [index]", 135 " pkg_version -t v1 v2", 136 " pkg_version -T name pattern"); 137 exit(1); 138} 139