2 * FreeBSD install - a package for the installation and maintenance
3 * of non-core utilities.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
17 * This is the version module. Based on pkg_version.pl by Bruce A. Mah.
21 #include <sys/cdefs.h>
22 __FBSDID("$FreeBSD$");
31 char *LimitChars = NULL;
32 char *PreventChars = NULL;
33 char *MatchName = NULL;
34 char *LookUpOrigin = NULL;
35 Boolean RegexExtended = FALSE;
36 Boolean UseINDEXOnly = FALSE;
37 Boolean ShowOrigin = FALSE;
39 static void usage(void);
41 static char opts[] = "dIhl:L:qs:XtTO:ov";
42 static 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' },
57 main(int argc, char **argv)
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"));
67 else if (argc == 4 && !strcmp(argv[1], "-T")) {
68 cmp = version_match(argv[3], argv[2]);
69 exit(cmp == 1 ? 0 : 1);
71 else while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) {
86 PreventChars = optarg;
98 LookUpOrigin = optarg;
106 errx(2, "Invalid -t usage.");
110 errx(2, "Invalid -T usage.");
114 RegexExtended = TRUE;
127 return pkg_perform(argv);
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");