main.c revision 148435
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 148435 2005-07-27 07:55:12Z krion $");
23
24#include "lib.h"
25#include "version.h"
26#include <err.h>
27
28static char Options[] = "dIhl:L:qs:XtTO:ov";
29
30char	*LimitChars = NULL;
31char	*PreventChars = NULL;
32char	*MatchName = NULL;
33char	*LookUpOrigin = NULL;
34Boolean RegexExtended = FALSE;
35Boolean UseINDEXOnly = FALSE;
36Boolean ShowOrigin = FALSE;
37
38static void usage __P((void));
39
40int
41main(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 = TRUE;
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
114static void
115usage()
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}
123