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.
20 * $FreeBSD: src/usr.sbin/pkg_install/info/main.c,v 1.22.2.14 2002/08/20 06:35:08 obrien Exp $
21 * $DragonFly: src/usr.sbin/pkg_install/info/Attic/main.c,v 1.3 2003/11/03 19:31:39 eirikn Exp $
28 static char Options[] = "acdDe:fgGhiIkl:LmoO:pqrRst:vVW:x";
31 match_t MatchType = MATCH_GLOB;
32 Boolean Quiet = FALSE;
33 char *InfoPrefix = (char *)(uintptr_t)"";
34 char PlayPen[FILENAME_MAX];
35 char *CheckPkg = NULL;
36 char *LookUpOrigin = NULL;
37 struct which_head *whead;
39 static void usage(void);
42 main(int argc, char **argv)
48 whead = malloc(sizeof(struct which_head));
55 MatchType = MATCH_ALL;
58 else while ((ch = getopt(argc, argv, Options)) != -1) {
61 MatchType = MATCH_ALL;
66 /* Reasonable definition of 'everything' */
67 Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL |
68 SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE;
80 Flags |= SHOW_COMMENT;
88 Flags |= SHOW_DISPLAY;
100 MatchType = MATCH_EXACT;
104 Flags |= SHOW_INSTALL;
108 Flags |= SHOW_DEINSTALL;
112 Flags |= SHOW_REQUIRE;
132 Flags |= SHOW_ORIGIN;
136 LookUpOrigin = strdup(optarg);
137 if (LookUpOrigin == NULL)
142 Flags |= SHOW_FMTREV;
154 strlcpy(PlayPen, optarg, sizeof(PlayPen));
158 MatchType = MATCH_REGEX;
167 struct which_entry *entp;
169 entp = calloc(1, sizeof(struct which_entry));
173 strlcpy(entp->file, optarg, PATH_MAX);
175 TAILQ_INSERT_TAIL(whead, entp, next);
190 /* Set some reasonable defaults */
192 Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY;
194 /* Get all the remaining package names, if any */
197 * Don't try to apply heuristics if arguments are regexs or if
198 * the argument refers to an existing file.
200 if (MatchType != MATCH_REGEX && !isfile(*argv))
201 while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) {
202 *pkgs_split++ = '\0';
204 * If character after the '/' is alphanumeric or shell
205 * metachar, then we've found the package name. Otherwise
206 * we've come across a trailing '/' and need to continue our
209 if (isalpha(*pkgs_split) || ((MatchType == MATCH_GLOB) && \
210 strpbrk(pkgs_split, "*?[]") != NULL)) {
218 /* If no packages, yelp */
219 if (pkgs == start && MatchType != MATCH_ALL && !CheckPkg &&
220 TAILQ_EMPTY(whead) && LookUpOrigin == NULL)
221 warnx("missing package name(s)"), usage();
223 return pkg_perform(start);
229 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
230 "usage: pkg_info [-cdDfGiIkLmopqrRsvVx] [-e package] [-l prefix]",
231 " [-t template] [pkg-name ...]",
232 " pkg_info [-q] -W filename",
233 " pkg_info [-q] -O origin",
234 " pkg_info -a [flags]");