main.c revision 98766
198766Smarkm/* 298766Smarkm * FreeBSD install - a package for the installation and maintainance 398766Smarkm * of non-core utilities. 498766Smarkm * 598766Smarkm * Redistribution and use in source and binary forms, with or without 698766Smarkm * modification, are permitted provided that the following conditions 798766Smarkm * are met: 898766Smarkm * 1. Redistributions of source code must retain the above copyright 998766Smarkm * notice, this list of conditions and the following disclaimer. 1098766Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1198766Smarkm * notice, this list of conditions and the following disclaimer in the 1298766Smarkm * documentation and/or other materials provided with the distribution. 1398766Smarkm * 1498766Smarkm * Jeremy D. Lea. 1598766Smarkm * 11 May 2002 1698766Smarkm * 1798766Smarkm * This is the version module. Based on pkg_version.pl by Bruce A. Mah. 1898766Smarkm * 1998766Smarkm */ 2098766Smarkm 2198766Smarkm#include <sys/cdefs.h> 2298766Smarkm__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/version/main.c 98766 2002-06-24 16:03:24Z markm $"); 2398766Smarkm 2498766Smarkm#include "lib.h" 2598766Smarkm#include "version.h" 2698766Smarkm#include <err.h> 2798766Smarkm 2898766Smarkmstatic char Options[] = "dhl:L:s:tv"; 2998766Smarkm 3098766Smarkmchar *LimitChars = NULL; 3198766Smarkmchar *PreventChars = NULL; 3298766Smarkmchar *MatchName = NULL; 3398766Smarkm 3498766Smarkmstatic void usage __P((void)); 3598766Smarkm 3698766Smarkmint 3798766Smarkmmain(int argc, char **argv) 3898766Smarkm{ 3998766Smarkm int ch, cmp = 0; 4098766Smarkm 4198766Smarkm if (argc == 4 && !strcmp(argv[1], "-t")) { 4298766Smarkm cmp = version_cmp(argv[2], argv[3]); 4398766Smarkm printf(cmp > 0 ? ">\n" : (cmp < 0 ? "<\n" : "=\n")); 4498766Smarkm exit(0); 4598766Smarkm } 4698766Smarkm else while ((ch = getopt(argc, argv, Options)) != -1) { 4798766Smarkm switch(ch) { 4898766Smarkm case 'v': 4998766Smarkm Verbose = TRUE; 5098766Smarkm break; 5198766Smarkm 5298766Smarkm case 'l': 5398766Smarkm LimitChars = optarg; 5498766Smarkm break; 5598766Smarkm 5698766Smarkm case 'L': 5798766Smarkm PreventChars = optarg; 5898766Smarkm break; 5998766Smarkm 6098766Smarkm case 's': 6198766Smarkm MatchName = optarg; 6298766Smarkm break; 6398766Smarkm 6498766Smarkm case 't': 6598766Smarkm errx(2, "Invalid -t usage."); 6698766Smarkm break; 6798766Smarkm 6898766Smarkm case 'h': 6998766Smarkm case '?': 7098766Smarkm default: 7198766Smarkm usage(); 7298766Smarkm break; 7398766Smarkm } 7498766Smarkm } 7598766Smarkm 7698766Smarkm argc -= optind; 7798766Smarkm argv += optind; 7898766Smarkm 7998766Smarkm return pkg_perform(argv); 8098766Smarkm} 8198766Smarkm 8298766Smarkmstatic void 8398766Smarkmusage() 8498766Smarkm{ 8598766Smarkm fprintf(stderr, "%s\n%s\n", 8698766Smarkm "usage: pkg_version [-hv] [-l limchar] [-L limchar] [-s string] index", 8798766Smarkm " pkg_version -t v1 v2"); 8898766Smarkm exit(1); 8998766Smarkm} 90