main.c revision 207113
172445Sassar/* 272445Sassar * FreeBSD install - a package for the installation and maintainance 372445Sassar * of non-core utilities. 472445Sassar * 572445Sassar * Redistribution and use in source and binary forms, with or without 672445Sassar * modification, are permitted provided that the following conditions 772445Sassar * are met: 872445Sassar * 1. Redistributions of source code must retain the above copyright 972445Sassar * notice, this list of conditions and the following disclaimer. 1072445Sassar * 2. Redistributions in binary form must reproduce the above copyright 1172445Sassar * notice, this list of conditions and the following disclaimer in the 1272445Sassar * documentation and/or other materials provided with the distribution. 1372445Sassar * 1472445Sassar * Jeremy D. Lea. 1572445Sassar * 11 May 2002 1672445Sassar * 1772445Sassar * This is the version module. Based on pkg_version.pl by Bruce A. Mah. 1872445Sassar * 1972445Sassar */ 2072445Sassar 2172445Sassar#include <sys/cdefs.h> 2272445Sassar__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/version/main.c 207113 2010-04-23 11:07:43Z flz $"); 2372445Sassar 2472445Sassar 2572445Sassar#include <getopt.h> 2672445Sassar#include <err.h> 2772445Sassar 2872445Sassar#include <pkg.h> 2972445Sassar#include "version.h" 3072445Sassar 3172445Sassarchar *LimitChars = NULL; 3272445Sassarchar *PreventChars = NULL; 3372445Sassarchar *MatchName = NULL; 3472445Sassarchar *LookUpOrigin = NULL; 3572445SassarBoolean RegexExtended = FALSE; 3672445SassarBoolean UseINDEXOnly = FALSE; 3772445SassarBoolean ShowOrigin = FALSE; 3872445Sassar 3972445Sassarstatic void usage(void); 4072445Sassar 4172445Sassarstatic char opts[] = "dIhl:L:qs:XtTO:ov"; 4272445Sassarstatic struct option longopts[] = { 4372445Sassar { "extended", no_argument, NULL, 'X' }, 4472445Sassar { "help", no_argument, NULL, 'h' }, 4572445Sassar { "match", required_argument, NULL, 's' }, 4672445Sassar { "no-status", required_argument, NULL, 'L' }, 4772445Sassar { "origin", required_argument, NULL, 'O' }, 4872445Sassar { "quiet", no_argument, NULL, 'q' }, 4972445Sassar { "show-origin",no_argument, NULL, 'o' }, 5072445Sassar { "status", required_argument, NULL, 'l' }, 5172445Sassar { "index-only", no_argument, NULL, 'I' }, 5272445Sassar { "verbose", no_argument, NULL, 'v' }, 5372445Sassar { NULL, 0, NULL, 0 } 5472445Sassar}; 5572445Sassar 5672445Sassarint 5772445Sassarmain(int argc, char **argv) 5872445Sassar{ 5972445Sassar int ch, cmp = 0; 6072445Sassar 6172445Sassar pkg_wrap(PKG_INSTALL_VERSION, argv); 6272445Sassar 6372445Sassar if (argc == 4 && !strcmp(argv[1], "-t")) { 6472445Sassar cmp = version_cmp(argv[2], argv[3]); 6572445Sassar printf(cmp > 0 ? ">\n" : (cmp < 0 ? "<\n" : "=\n")); 6672445Sassar exit(0); 6772445Sassar } 6872445Sassar else if (argc == 4 && !strcmp(argv[1], "-T")) { 6972445Sassar cmp = version_match(argv[3], argv[2]); 7072445Sassar exit(cmp == 1 ? 0 : 1); 7172445Sassar } 7272445Sassar else while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) { 7372445Sassar switch(ch) { 7472445Sassar case 'v': 7572445Sassar Verbose++; 7672445Sassar break; 7772445Sassar 7872445Sassar case 'I': 7972445Sassar UseINDEXOnly = TRUE; 8072445Sassar break; 8172445Sassar 8272445Sassar case 'l': 8372445Sassar LimitChars = optarg; 8472445Sassar break; 8572445Sassar 8672445Sassar case 'L': 8772445Sassar PreventChars = optarg; 8872445Sassar break; 8972445Sassar 9072445Sassar case 'q': 9172445Sassar Quiet = TRUE; 9272445Sassar break; 9372445Sassar 9472445Sassar case 's': 9572445Sassar MatchName = optarg; 9672445Sassar break; 9772445Sassar 9872445Sassar case 'O': 9972445Sassar LookUpOrigin = optarg; 10072445Sassar break; 10172445Sassar 10272445Sassar case 'o': 10372445Sassar ShowOrigin = TRUE; 10472445Sassar break; 10572445Sassar 10672445Sassar case 't': 10772445Sassar errx(2, "Invalid -t usage."); 10872445Sassar break; 10972445Sassar 11072445Sassar case 'T': 11172445Sassar errx(2, "Invalid -T usage."); 11272445Sassar break; 11372445Sassar 11472445Sassar case 'X': 11572445Sassar RegexExtended = TRUE; 11672445Sassar break; 11772445Sassar 11872445Sassar case 'h': 11972445Sassar default: 12072445Sassar usage(); 12172445Sassar break; 12272445Sassar } 12372445Sassar } 12472445Sassar 12572445Sassar argc -= optind; 12672445Sassar argv += optind; 12772445Sassar 12872445Sassar return pkg_perform(argv); 12972445Sassar} 13072445Sassar 13172445Sassarstatic void 13272445Sassarusage(void) 13372445Sassar{ 13472445Sassar fprintf(stderr, "%s\n%s\n%s\n", 13572445Sassar "usage: pkg_version [-hIoqv] [-l limchar] [-L limchar] [[-X] -s string] [-O origin] [index]", 13672445Sassar " pkg_version -t v1 v2", 13772445Sassar " pkg_version -T name pattern"); 13872445Sassar exit(1); 13972445Sassar} 14072445Sassar