3 * FreeBSD install - a package for the installation and maintainance
4 * of non-core utilities.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
18 * This is the info module.
22 #include <sys/cdefs.h>
23 __FBSDID("$FreeBSD$");
32 match_t MatchType = MATCH_GLOB;
33 Boolean QUIET = FALSE;
34 Boolean UseBlkSz = FALSE;
35 char *InfoPrefix = (char *)(uintptr_t)"";
36 char PlayPen[FILENAME_MAX];
37 char *CheckPkg = NULL;
38 char *LookUpOrigin = NULL;
39 Boolean KeepPackage = FALSE;
40 struct which_head *whead;
42 static void usage(void);
44 static char opts[] = "abcdDe:EfgGhiIjkKl:LmoO:pPqQrRst:vVW:xX";
45 static struct option longopts[] = {
46 { "all", no_argument, NULL, 'a' },
47 { "blocksize", no_argument, NULL, 'b' },
48 { "exist", required_argument, NULL, 'X' },
49 { "exists", required_argument, NULL, 'X' },
50 { "extended", no_argument, NULL, 'e' },
51 { "help", no_argument, NULL, 'h' },
52 { "keep", no_argument, NULL, 'K' },
53 { "no-glob", no_argument, NULL, 'G' },
54 { "origin", required_argument, NULL, 'O' },
55 { "quiet", no_argument, NULL, 'q' },
56 { "regex", no_argument, NULL, 'x' },
57 { "template", required_argument, NULL, 't' },
58 { "verbose", no_argument, NULL, 'v' },
59 { "version", no_argument, NULL, 'P' },
60 { "which", required_argument, NULL, 'W' },
65 main(int argc, char **argv)
71 whead = malloc(sizeof(struct which_head));
78 MatchType = MATCH_ALL;
81 else while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) {
84 MatchType = MATCH_ALL;
93 /* Reasonable definition of 'everything' */
94 Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL |
95 SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE;
99 Flags |= SHOW_PKGNAME;
107 Flags |= SHOW_PREFIX;
111 Flags |= SHOW_COMMENT;
119 Flags |= SHOW_DISPLAY;
131 MatchType = MATCH_EXACT;
135 Flags |= SHOW_INSTALL;
139 Flags |= SHOW_REQUIRE;
143 Flags |= SHOW_DEINSTALL;
151 Flags |= SHOW_DEPEND;
171 Flags |= SHOW_ORIGIN;
175 LookUpOrigin = strdup(optarg);
176 if (LookUpOrigin == NULL)
181 Flags |= SHOW_FMTREV;
198 strlcpy(PlayPen, optarg, sizeof(PlayPen));
202 MatchType = MATCH_REGEX;
206 MatchType = MATCH_EREGEX;
215 struct which_entry *entp;
217 entp = calloc(1, sizeof(struct which_entry));
221 strlcpy(entp->file, optarg, PATH_MAX);
223 TAILQ_INSERT_TAIL(whead, entp, next);
241 if (Flags & SHOW_PTREV) {
243 printf("Package tools revision: ");
244 printf("%d\n", PKG_INSTALL_VERSION);
248 /* Set some reasonable defaults */
250 Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY;
252 /* Get all the remaining package names, if any */
255 * Don't try to apply heuristics if arguments are regexs or if
256 * the argument refers to an existing file.
258 if (MatchType != MATCH_REGEX && MatchType != MATCH_EREGEX && !isfile(*argv) && !isURL(*argv))
259 while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) {
260 *pkgs_split++ = '\0';
262 * If character after the '/' is alphanumeric or shell
263 * metachar, then we've found the package name. Otherwise
264 * we've come across a trailing '/' and need to continue our
267 if (isalnum(*pkgs_split) || ((MatchType == MATCH_GLOB) && \
268 strpbrk(pkgs_split, "*?[]") != NULL)) {
276 /* If no packages, yelp */
277 if (pkgs == start && MatchType != MATCH_ALL && !CheckPkg &&
278 TAILQ_EMPTY(whead) && LookUpOrigin == NULL)
279 warnx("missing package name(s)"), usage();
281 return pkg_perform(start);
287 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
288 "usage: pkg_info [-bcdDEfgGiIjkKLmopPqQrRsvVxX] [-e package] [-l prefix]",
289 " [-t template] -a | pkg-name ...",
290 " pkg_info [-qQ] -W filename",
291 " pkg_info [-qQ] -O origin",