]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/pkg_install/version/main.c
This commit was generated by cvs2svn to compensate for changes in r174993,
[FreeBSD/FreeBSD.git] / usr.sbin / pkg_install / version / main.c
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$");
23
24 #include "lib.h"
25 #include "version.h"
26 #include <err.h>
27
28 static char Options[] = "dIhl:L:qs:XtTO:ov";
29
30 char    *LimitChars = NULL;
31 char    *PreventChars = NULL;
32 char    *MatchName = NULL;
33 char    *LookUpOrigin = NULL;
34 Boolean RegexExtended = FALSE;
35 Boolean UseINDEXOnly = FALSE;
36 Boolean ShowOrigin = FALSE;
37
38 static void usage(void);
39
40 int
41 main(int argc, char **argv)
42 {
43     int ch, cmp = 0;
44
45     if (argc == 4 && !strcmp(argv[1], "-t")) {
46         cmp = version_cmp(argv[2], argv[3]);
47         printf(cmp > 0 ? ">\n" : (cmp < 0 ? "<\n" : "=\n"));
48         exit(0);
49     }
50     else if (argc == 4 && !strcmp(argv[1], "-T")) {
51         cmp = version_match(argv[3], argv[2]);
52         exit(cmp == 1 ? 0 : 1);
53     }
54     else while ((ch = getopt(argc, argv, Options)) != -1) {
55         switch(ch) {
56         case 'v':
57             Verbose++;
58             break;
59
60         case 'I':
61             UseINDEXOnly = TRUE;
62             break;
63
64         case 'l':
65             LimitChars = optarg;
66             break;
67
68         case 'L':
69             PreventChars = optarg;
70             break;
71
72         case 'q':
73             Quiet = TRUE;
74             break;
75
76         case 's':
77             MatchName = optarg;
78             break;
79
80         case 'O':
81             LookUpOrigin = optarg;
82             break;
83
84         case 'o':
85             ShowOrigin = TRUE;
86             break;
87
88         case 't':
89             errx(2, "Invalid -t usage.");
90             break;
91
92         case 'T':
93             errx(2, "Invalid -T usage.");
94             break;
95
96         case 'X':
97             RegexExtended = TRUE;
98             break;
99
100         case 'h':
101         case '?':
102         default:
103             usage();
104             break;
105         }
106     }
107
108     argc -= optind;
109     argv += optind;
110
111     return pkg_perform(argv);
112 }
113
114 static void
115 usage()
116 {
117     fprintf(stderr, "%s\n%s\n%s\n",
118         "usage: pkg_version [-hIoqv] [-l limchar] [-L limchar] [[-X] -s string] [-O origin] [index]",
119         "       pkg_version -t v1 v2",
120         "       pkg_version -T name pattern");
121     exit(1);
122 }