1993-08-26 01:19:55 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* FreeBSD install - a package for the installation and maintainance
|
|
|
|
* of non-core utilities.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* Jordan K. Hubbard
|
|
|
|
* 18 July 1993
|
|
|
|
*
|
1997-12-26 05:29:29 +00:00
|
|
|
* This is the info module.
|
1993-08-26 01:19:55 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2002-04-01 09:39:07 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
#include "lib.h"
|
|
|
|
#include "info.h"
|
2001-03-23 18:45:24 +00:00
|
|
|
#include <err.h>
|
1993-08-26 01:19:55 +00:00
|
|
|
|
2003-03-25 01:22:42 +00:00
|
|
|
static char Options[] = "abcdDe:fgGhiIkl:LmoO:pPqQrRst:vVW:x";
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
int Flags = 0;
|
2001-02-08 17:44:00 +00:00
|
|
|
match_t MatchType = MATCH_GLOB;
|
1993-09-08 01:46:59 +00:00
|
|
|
Boolean Quiet = FALSE;
|
2003-03-25 00:51:41 +00:00
|
|
|
Boolean QUIET = FALSE;
|
2003-03-25 01:22:42 +00:00
|
|
|
Boolean UseBlkSz = FALSE;
|
2001-10-10 06:58:42 +00:00
|
|
|
char *InfoPrefix = (char *)(uintptr_t)"";
|
1995-10-25 15:38:37 +00:00
|
|
|
char PlayPen[FILENAME_MAX];
|
1993-09-05 22:36:54 +00:00
|
|
|
char *CheckPkg = NULL;
|
2002-05-04 14:49:49 +00:00
|
|
|
char *LookUpOrigin = NULL;
|
2001-03-23 18:45:24 +00:00
|
|
|
struct which_head *whead;
|
1993-08-26 01:19:55 +00:00
|
|
|
|
1997-10-08 07:48:21 +00:00
|
|
|
static void usage __P((void));
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ch;
|
|
|
|
char **pkgs, **start;
|
2000-01-15 01:15:37 +00:00
|
|
|
char *pkgs_split;
|
1993-08-26 01:19:55 +00:00
|
|
|
|
2001-03-23 18:45:24 +00:00
|
|
|
whead = malloc(sizeof(struct which_head));
|
|
|
|
if (whead == NULL)
|
|
|
|
err(2, NULL);
|
|
|
|
TAILQ_INIT(whead);
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
pkgs = start = argv;
|
1999-04-27 02:30:27 +00:00
|
|
|
if (argc == 1) {
|
2001-02-08 17:44:00 +00:00
|
|
|
MatchType = MATCH_ALL;
|
1999-04-27 02:30:27 +00:00
|
|
|
Flags = SHOW_INDEX;
|
|
|
|
}
|
|
|
|
else while ((ch = getopt(argc, argv, Options)) != -1) {
|
1993-08-26 01:19:55 +00:00
|
|
|
switch(ch) {
|
|
|
|
case 'a':
|
2001-02-08 17:44:00 +00:00
|
|
|
MatchType = MATCH_ALL;
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
|
2003-03-25 01:22:42 +00:00
|
|
|
case 'b':
|
|
|
|
UseBlkSz = TRUE;
|
|
|
|
break;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
case 'v':
|
|
|
|
Verbose = TRUE;
|
|
|
|
/* Reasonable definition of 'everything' */
|
|
|
|
Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL |
|
1994-12-06 00:51:50 +00:00
|
|
|
SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE;
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'I':
|
|
|
|
Flags |= SHOW_INDEX;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
Flags |= SHOW_PREFIX;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
Flags |= SHOW_COMMENT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
Flags |= SHOW_DESC;
|
|
|
|
break;
|
|
|
|
|
1994-12-06 00:51:50 +00:00
|
|
|
case 'D':
|
|
|
|
Flags |= SHOW_DISPLAY;
|
|
|
|
break;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
case 'f':
|
|
|
|
Flags |= SHOW_PLIST;
|
|
|
|
break;
|
|
|
|
|
2001-02-03 20:56:32 +00:00
|
|
|
case 'g':
|
|
|
|
Flags |= SHOW_CKSUM;
|
|
|
|
break;
|
|
|
|
|
2001-02-08 17:44:00 +00:00
|
|
|
case 'G':
|
|
|
|
MatchType = MATCH_EXACT;
|
|
|
|
break;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
case 'i':
|
|
|
|
Flags |= SHOW_INSTALL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'k':
|
|
|
|
Flags |= SHOW_DEINSTALL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
Flags |= SHOW_REQUIRE;
|
|
|
|
break;
|
|
|
|
|
1994-12-06 00:51:50 +00:00
|
|
|
case 'R':
|
|
|
|
Flags |= SHOW_REQBY;
|
|
|
|
break;
|
|
|
|
|
1993-09-08 01:46:59 +00:00
|
|
|
case 'L':
|
|
|
|
Flags |= SHOW_FILES;
|
|
|
|
break;
|
|
|
|
|
1994-12-06 00:51:50 +00:00
|
|
|
case 'm':
|
|
|
|
Flags |= SHOW_MTREE;
|
|
|
|
break;
|
|
|
|
|
2001-02-08 17:44:00 +00:00
|
|
|
case 's':
|
|
|
|
Flags |= SHOW_SIZE;
|
|
|
|
break;
|
2000-07-07 13:06:32 +00:00
|
|
|
|
2000-10-23 07:01:31 +00:00
|
|
|
case 'o':
|
|
|
|
Flags |= SHOW_ORIGIN;
|
|
|
|
break;
|
|
|
|
|
2002-05-04 14:49:49 +00:00
|
|
|
case 'O':
|
|
|
|
LookUpOrigin = strdup(optarg);
|
|
|
|
if (LookUpOrigin == NULL)
|
|
|
|
err(2, NULL);
|
|
|
|
break;
|
|
|
|
|
2001-10-10 08:21:41 +00:00
|
|
|
case 'V':
|
|
|
|
Flags |= SHOW_FMTREV;
|
|
|
|
break;
|
|
|
|
|
1993-09-03 23:01:17 +00:00
|
|
|
case 'l':
|
|
|
|
InfoPrefix = optarg;
|
|
|
|
break;
|
|
|
|
|
1993-09-08 01:46:59 +00:00
|
|
|
case 'q':
|
|
|
|
Quiet = TRUE;
|
|
|
|
break;
|
|
|
|
|
2003-03-25 00:51:41 +00:00
|
|
|
case 'Q':
|
|
|
|
Quiet = TRUE;
|
|
|
|
QUIET = TRUE;
|
|
|
|
break;
|
|
|
|
|
1993-09-05 04:54:24 +00:00
|
|
|
case 't':
|
2001-10-16 03:04:15 +00:00
|
|
|
strlcpy(PlayPen, optarg, sizeof(PlayPen));
|
1993-09-05 04:54:24 +00:00
|
|
|
break;
|
|
|
|
|
2001-02-08 17:44:00 +00:00
|
|
|
case 'x':
|
|
|
|
MatchType = MATCH_REGEX;
|
|
|
|
break;
|
|
|
|
|
1993-09-05 22:36:54 +00:00
|
|
|
case 'e':
|
|
|
|
CheckPkg = optarg;
|
|
|
|
break;
|
|
|
|
|
2001-03-23 18:45:24 +00:00
|
|
|
case 'W':
|
|
|
|
{
|
|
|
|
struct which_entry *entp;
|
|
|
|
|
|
|
|
entp = calloc(1, sizeof(struct which_entry));
|
|
|
|
if (entp == NULL)
|
|
|
|
err(2, NULL);
|
|
|
|
|
|
|
|
strlcpy(entp->file, optarg, PATH_MAX);
|
|
|
|
entp->skip = FALSE;
|
|
|
|
TAILQ_INSERT_TAIL(whead, entp, next);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-09-09 19:43:30 +00:00
|
|
|
case 'P':
|
|
|
|
Flags = SHOW_PTREV;
|
|
|
|
break;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
case 'h':
|
|
|
|
case '?':
|
|
|
|
default:
|
1997-10-08 07:48:21 +00:00
|
|
|
usage();
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-04-27 02:30:27 +00:00
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
|
1995-05-30 03:57:47 +00:00
|
|
|
argc -= optind;
|
1993-08-26 01:19:55 +00:00
|
|
|
argv += optind;
|
|
|
|
|
2002-09-09 19:43:30 +00:00
|
|
|
if (Flags & SHOW_PTREV) {
|
|
|
|
if (!Quiet)
|
|
|
|
printf("Package tools revision: ");
|
|
|
|
printf("%d\n", PKG_INSTALL_VERSION);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
/* Set some reasonable defaults */
|
|
|
|
if (!Flags)
|
1994-12-06 00:51:50 +00:00
|
|
|
Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY;
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
/* Get all the remaining package names, if any */
|
2000-05-14 19:54:04 +00:00
|
|
|
while (*argv) {
|
2002-05-02 13:09:33 +00:00
|
|
|
/*
|
|
|
|
* Don't try to apply heuristics if arguments are regexs or if
|
|
|
|
* the argument refers to an existing file.
|
|
|
|
*/
|
|
|
|
if (MatchType != MATCH_REGEX && !isfile(*argv))
|
2001-02-08 17:44:00 +00:00
|
|
|
while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) {
|
|
|
|
*pkgs_split++ = '\0';
|
|
|
|
/*
|
|
|
|
* If character after the '/' is alphanumeric or shell
|
|
|
|
* metachar, then we've found the package name. Otherwise
|
|
|
|
* we've come across a trailing '/' and need to continue our
|
|
|
|
* quest.
|
|
|
|
*/
|
|
|
|
if (isalpha(*pkgs_split) || ((MatchType == MATCH_GLOB) && \
|
|
|
|
strpbrk(pkgs_split, "*?[]") != NULL)) {
|
|
|
|
*argv = pkgs_split;
|
|
|
|
break;
|
|
|
|
}
|
2000-05-14 19:54:04 +00:00
|
|
|
}
|
|
|
|
*pkgs++ = *argv++;
|
2000-01-15 01:15:37 +00:00
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
/* If no packages, yelp */
|
2001-03-23 18:45:24 +00:00
|
|
|
if (pkgs == start && MatchType != MATCH_ALL && !CheckPkg &&
|
2002-05-04 14:49:49 +00:00
|
|
|
TAILQ_EMPTY(whead) && LookUpOrigin == NULL)
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("missing package name(s)"), usage();
|
1993-08-26 01:19:55 +00:00
|
|
|
*pkgs = NULL;
|
|
|
|
return pkg_perform(start);
|
|
|
|
}
|
|
|
|
|
1997-10-08 07:48:21 +00:00
|
|
|
static void
|
|
|
|
usage()
|
1993-08-26 01:19:55 +00:00
|
|
|
{
|
2002-05-05 13:44:32 +00:00
|
|
|
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
|
2001-10-10 08:21:41 +00:00
|
|
|
"usage: pkg_info [-cdDfGiIkLmopqrRsvVx] [-e package] [-l prefix]",
|
2002-05-05 13:44:32 +00:00
|
|
|
" [-t template] [pkg-name ...]",
|
|
|
|
" pkg_info [-q] -W filename",
|
|
|
|
" pkg_info [-q] -O origin",
|
1997-10-08 07:48:21 +00:00
|
|
|
" pkg_info -a [flags]");
|
1993-08-26 01:19:55 +00:00
|
|
|
exit(1);
|
|
|
|
}
|