main.c revision 72174
1327Sjkh/*
2327Sjkh *
3327Sjkh * FreeBSD install - a package for the installation and maintainance
4327Sjkh * of non-core utilities.
5327Sjkh *
6327Sjkh * Redistribution and use in source and binary forms, with or without
7327Sjkh * modification, are permitted provided that the following conditions
8327Sjkh * are met:
9327Sjkh * 1. Redistributions of source code must retain the above copyright
10327Sjkh *    notice, this list of conditions and the following disclaimer.
11327Sjkh * 2. Redistributions in binary form must reproduce the above copyright
12327Sjkh *    notice, this list of conditions and the following disclaimer in the
13327Sjkh *    documentation and/or other materials provided with the distribution.
14327Sjkh *
15327Sjkh * Jordan K. Hubbard
16327Sjkh * 18 July 1993
17327Sjkh *
1831997Shoek * This is the info module.
19327Sjkh *
20327Sjkh */
21327Sjkh
2230221Scharnier#include <err.h>
23327Sjkh#include "lib.h"
24327Sjkh#include "info.h"
25327Sjkh
2655567Sphantom#ifndef lint
2755567Sphantomstatic const char rcsid[] =
2855567Sphantom  "$FreeBSD: head/usr.sbin/pkg_install/info/main.c 72174 2001-02-08 17:44:00Z sobomax $";
2955567Sphantom#endif
30327Sjkh
3172174Ssobomaxstatic char Options[] = "acdDe:fgGhiIkl:LmopqrRst:vx";
3255567Sphantom
33327Sjkhint	Flags		= 0;
3472174Ssobomaxmatch_t	MatchType	= MATCH_GLOB;
35411SjkhBoolean Quiet		= FALSE;
36379Sjkhchar *InfoPrefix	= "";
3711780Sjkhchar PlayPen[FILENAME_MAX];
38392Sjkhchar *CheckPkg		= NULL;
39327Sjkh
4030221Scharnierstatic void usage __P((void));
4130221Scharnier
42327Sjkhint
43327Sjkhmain(int argc, char **argv)
44327Sjkh{
45327Sjkh    int ch;
46327Sjkh    char **pkgs, **start;
4756001Sdan    char *pkgs_split;
48327Sjkh
49327Sjkh    pkgs = start = argv;
5046105Sjkh    if (argc == 1) {
5172174Ssobomax	MatchType = MATCH_ALL;
5246105Sjkh	Flags = SHOW_INDEX;
5346105Sjkh    }
5446105Sjkh    else while ((ch = getopt(argc, argv, Options)) != -1) {
55327Sjkh	switch(ch) {
56327Sjkh	case 'a':
5772174Ssobomax	    MatchType = MATCH_ALL;
58327Sjkh	    break;
59327Sjkh
60327Sjkh	case 'v':
61327Sjkh	    Verbose = TRUE;
62327Sjkh	    /* Reasonable definition of 'everything' */
63327Sjkh	    Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL |
644996Sjkh		SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE;
65327Sjkh	    break;
66327Sjkh
67327Sjkh	case 'I':
68327Sjkh	    Flags |= SHOW_INDEX;
69327Sjkh	    break;
70327Sjkh
71327Sjkh	case 'p':
72327Sjkh	    Flags |= SHOW_PREFIX;
73327Sjkh	    break;
74327Sjkh
75327Sjkh	case 'c':
76327Sjkh	    Flags |= SHOW_COMMENT;
77327Sjkh	    break;
78327Sjkh
79327Sjkh	case 'd':
80327Sjkh	    Flags |= SHOW_DESC;
81327Sjkh	    break;
82327Sjkh
834996Sjkh	case 'D':
844996Sjkh	    Flags |= SHOW_DISPLAY;
854996Sjkh	    break;
864996Sjkh
87327Sjkh	case 'f':
88327Sjkh	    Flags |= SHOW_PLIST;
89327Sjkh	    break;
90327Sjkh
9171965Sjkh	case 'g':
9271965Sjkh	    Flags |= SHOW_CKSUM;
9371965Sjkh	    break;
9471965Sjkh
9572174Ssobomax	case 'G':
9672174Ssobomax	    MatchType = MATCH_EXACT;
9772174Ssobomax	    break;
9872174Ssobomax
99327Sjkh	case 'i':
100327Sjkh	    Flags |= SHOW_INSTALL;
101327Sjkh	    break;
102327Sjkh
103327Sjkh	case 'k':
104327Sjkh	    Flags |= SHOW_DEINSTALL;
105327Sjkh	    break;
106327Sjkh
107327Sjkh	case 'r':
108327Sjkh	    Flags |= SHOW_REQUIRE;
109327Sjkh	    break;
110327Sjkh
1114996Sjkh	case 'R':
1124996Sjkh	    Flags |= SHOW_REQBY;
1134996Sjkh	    break;
1144996Sjkh
115411Sjkh	case 'L':
116411Sjkh	    Flags |= SHOW_FILES;
117411Sjkh	    break;
118411Sjkh
1194996Sjkh	case 'm':
1204996Sjkh	    Flags |= SHOW_MTREE;
1214996Sjkh	    break;
1224996Sjkh
12372174Ssobomax	case 's':
12472174Ssobomax	    Flags |= SHOW_SIZE;
12572174Ssobomax	    break;
12662775Ssobomax
12767454Ssobomax	case 'o':
12867454Ssobomax	    Flags |= SHOW_ORIGIN;
12967454Ssobomax	    break;
13067454Ssobomax
131379Sjkh	case 'l':
132379Sjkh	    InfoPrefix = optarg;
133379Sjkh	    break;
134379Sjkh
135411Sjkh	case 'q':
136411Sjkh	    Quiet = TRUE;
137411Sjkh	    break;
138411Sjkh
139383Sjkh	case 't':
14011780Sjkh	    strcpy(PlayPen, optarg);
141383Sjkh	    break;
142383Sjkh
14372174Ssobomax	case 'x':
14472174Ssobomax	    MatchType = MATCH_REGEX;
14572174Ssobomax	    break;
14672174Ssobomax
147392Sjkh	case 'e':
148392Sjkh	    CheckPkg = optarg;
149392Sjkh	    break;
150392Sjkh
151327Sjkh	case 'h':
152327Sjkh	case '?':
153327Sjkh	default:
15430221Scharnier	    usage();
155327Sjkh	    break;
156327Sjkh	}
15746105Sjkh    }
158327Sjkh
1598857Srgrimes    argc -= optind;
160327Sjkh    argv += optind;
161327Sjkh
162327Sjkh    /* Set some reasonable defaults */
163327Sjkh    if (!Flags)
1644996Sjkh	Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY;
165327Sjkh
166327Sjkh    /* Get all the remaining package names, if any */
16760563Ssteve    while (*argv) {
16872174Ssobomax	/* Don't try to apply heuristics if arguments are regexs */
16972174Ssobomax	if (MatchType != MATCH_REGEX)
17072174Ssobomax	    while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) {
17172174Ssobomax		*pkgs_split++ = '\0';
17272174Ssobomax		/*
17372174Ssobomax		 * If character after the '/' is alphanumeric or shell
17472174Ssobomax		 * metachar, then we've found the package name.  Otherwise
17572174Ssobomax		 * we've come across a trailing '/' and need to continue our
17672174Ssobomax		 * quest.
17772174Ssobomax		 */
17872174Ssobomax		if (isalpha(*pkgs_split) || ((MatchType == MATCH_GLOB) && \
17972174Ssobomax		    strpbrk(pkgs_split, "*?[]") != NULL)) {
18072174Ssobomax		    *argv = pkgs_split;
18172174Ssobomax		    break;
18272174Ssobomax		}
18360563Ssteve	    }
18460563Ssteve	*pkgs++ = *argv++;
18556001Sdan    }
186327Sjkh
187327Sjkh    /* If no packages, yelp */
18872174Ssobomax    if (pkgs == start && MatchType != MATCH_ALL && !CheckPkg)
18930221Scharnier	warnx("missing package name(s)"), usage();
190327Sjkh    *pkgs = NULL;
191327Sjkh    return pkg_perform(start);
192327Sjkh}
193327Sjkh
19430221Scharnierstatic void
19530221Scharnierusage()
196327Sjkh{
19730221Scharnier    fprintf(stderr, "%s\n%s\n%s\n",
19869616Ssobomax	"usage: pkg_info [-cdDfiIkLmopqrRsv] [-e package] [-l prefix]",
19955567Sphantom	"                [-t template] [pkg-name ...]",
20030221Scharnier	"       pkg_info -a [flags]");
201327Sjkh    exit(1);
202327Sjkh}
203