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' },
64 main(int argc
, char **argv
)
70 whead
= malloc(sizeof(struct which_head
));
77 MatchType
= MATCH_ALL
;
80 else while ((ch
= getopt_long(argc
, argv
, opts
, longopts
, NULL
)) != -1) {
83 MatchType
= MATCH_ALL
;
92 /* Reasonable definition of 'everything' */
93 Flags
= SHOW_COMMENT
| SHOW_DESC
| SHOW_PLIST
| SHOW_INSTALL
|
94 SHOW_DEINSTALL
| SHOW_REQUIRE
| SHOW_DISPLAY
| SHOW_MTREE
;
98 Flags
|= SHOW_PKGNAME
;
106 Flags
|= SHOW_PREFIX
;
110 Flags
|= SHOW_COMMENT
;
118 Flags
|= SHOW_DISPLAY
;
130 MatchType
= MATCH_EXACT
;
134 Flags
|= SHOW_INSTALL
;
138 Flags
|= SHOW_REQUIRE
;
142 Flags
|= SHOW_DEINSTALL
;
150 Flags
|= SHOW_DEPEND
;
170 Flags
|= SHOW_ORIGIN
;
174 LookUpOrigin
= strdup(optarg
);
175 if (LookUpOrigin
== NULL
)
180 Flags
|= SHOW_FMTREV
;
197 strlcpy(PlayPen
, optarg
, sizeof(PlayPen
));
201 MatchType
= MATCH_REGEX
;
205 MatchType
= MATCH_EREGEX
;
214 struct which_entry
*entp
;
216 entp
= calloc(1, sizeof(struct which_entry
));
220 strlcpy(entp
->file
, optarg
, PATH_MAX
);
222 TAILQ_INSERT_TAIL(whead
, entp
, next
);
240 if (Flags
& SHOW_PTREV
) {
242 printf("Package tools revision: ");
243 printf("%d\n", PKG_INSTALL_VERSION
);
247 /* Set some reasonable defaults */
249 Flags
= SHOW_COMMENT
| SHOW_DESC
| SHOW_REQBY
;
251 /* Get all the remaining package names, if any */
254 * Don't try to apply heuristics if arguments are regexs or if
255 * the argument refers to an existing file.
257 if (MatchType
!= MATCH_REGEX
&& MatchType
!= MATCH_EREGEX
&& !isfile(*argv
) && !isURL(*argv
))
258 while ((pkgs_split
= strrchr(*argv
, (int)'/')) != NULL
) {
259 *pkgs_split
++ = '\0';
261 * If character after the '/' is alphanumeric or shell
262 * metachar, then we've found the package name. Otherwise
263 * we've come across a trailing '/' and need to continue our
266 if (isalnum(*pkgs_split
) || ((MatchType
== MATCH_GLOB
) && \
267 strpbrk(pkgs_split
, "*?[]") != NULL
)) {
275 /* If no packages, yelp */
276 if (pkgs
== start
&& MatchType
!= MATCH_ALL
&& !CheckPkg
&&
277 TAILQ_EMPTY(whead
) && LookUpOrigin
== NULL
)
278 warnx("missing package name(s)"), usage();
280 return pkg_perform(start
);
286 fprintf(stderr
, "%s\n%s\n%s\n%s\n%s\n",
287 "usage: pkg_info [-bcdDEfgGiIjkKLmopPqQrRsvVxX] [-e package] [-l prefix]",
288 " [-t template] -a | pkg-name ...",
289 " pkg_info [-qQ] -W filename",
290 " pkg_info [-qQ] -O origin",