main.c revision 140061
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 140061 2005-01-11 11:23:59Z ru $");
23
24#include "lib.h"
25#include "version.h"
26#include <err.h>
27
28static char Options[] = "dhl:L:qs:XtTv";
29
30char	*LimitChars = NULL;
31char	*PreventChars = NULL;
32char	*MatchName = NULL;
33Boolean RegexExtended = FALSE;
34
35static void usage __P((void));
36
37int
38main(int argc, char **argv)
39{
40    int ch, cmp = 0;
41
42    if (argc == 4 && !strcmp(argv[1], "-t")) {
43	cmp = version_cmp(argv[2], argv[3]);
44	printf(cmp > 0 ? ">\n" : (cmp < 0 ? "<\n" : "=\n"));
45	exit(0);
46    }
47    else if (argc == 4 && !strcmp(argv[1], "-T")) {
48	cmp = version_match(argv[3], argv[2]);
49	exit(cmp == 1 ? 0 : 1);
50    }
51    else while ((ch = getopt(argc, argv, Options)) != -1) {
52	switch(ch) {
53	case 'v':
54	    Verbose = TRUE;
55	    break;
56
57	case 'l':
58	    LimitChars = optarg;
59	    break;
60
61	case 'L':
62	    PreventChars = optarg;
63	    break;
64
65	case 'q':
66	    Quiet = TRUE;
67	    break;
68
69	case 's':
70	    MatchName = optarg;
71	    break;
72
73	case 't':
74	    errx(2, "Invalid -t usage.");
75	    break;
76
77	case 'T':
78	    errx(2, "Invalid -T usage.");
79	    break;
80
81	case 'X':
82	    RegexExtended = TRUE;
83	    break;
84
85	case 'h':
86	case '?':
87	default:
88	    usage();
89	    break;
90	}
91    }
92
93    argc -= optind;
94    argv += optind;
95
96    return pkg_perform(argv);
97}
98
99static void
100usage()
101{
102    fprintf(stderr, "%s\n%s\n%s\n",
103	"usage: pkg_version [-hqv] [-l limchar] [-L limchar] [[-X] -s string] [index]",
104	"       pkg_version -t v1 v2",
105	"       pkg_version -T name pattern");
106    exit(1);
107}
108