main.c revision 228990
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: head/usr.sbin/pkg_install/version/main.c 228990 2011-12-30 10:58:14Z uqs $"); 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 if (argc == 4 && !strcmp(argv[1], "-t")) { 62 cmp = version_cmp(argv[2], argv[3]); 63 printf(cmp > 0 ? ">\n" : (cmp < 0 ? "<\n" : "=\n")); 64 exit(0); 65 } 66 else if (argc == 4 && !strcmp(argv[1], "-T")) { 67 cmp = version_match(argv[3], argv[2]); 68 exit(cmp == 1 ? 0 : 1); 69 } 70 else while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) { 71 switch(ch) { 72 case 'v': 73 Verbose++; 74 break; 75 76 case 'I': 77 UseINDEXOnly = TRUE; 78 break; 79 80 case 'l': 81 LimitChars = optarg; 82 break; 83 84 case 'L': 85 PreventChars = optarg; 86 break; 87 88 case 'q': 89 Quiet = TRUE; 90 break; 91 92 case 's': 93 MatchName = optarg; 94 break; 95 96 case 'O': 97 LookUpOrigin = optarg; 98 break; 99 100 case 'o': 101 ShowOrigin = TRUE; 102 break; 103 104 case 't': 105 errx(2, "Invalid -t usage."); 106 break; 107 108 case 'T': 109 errx(2, "Invalid -T usage."); 110 break; 111 112 case 'X': 113 RegexExtended = TRUE; 114 break; 115 116 case 'h': 117 default: 118 usage(); 119 break; 120 } 121 } 122 123 argc -= optind; 124 argv += optind; 125 126 return pkg_perform(argv); 127} 128 129static void 130usage(void) 131{ 132 fprintf(stderr, "%s\n%s\n%s\n", 133 "usage: pkg_version [-hIoqv] [-l limchar] [-L limchar] [[-X] -s string] [-O origin] [index]", 134 " pkg_version -t v1 v2", 135 " pkg_version -T name pattern"); 136 exit(1); 137} 138