main.c revision 46105
1#ifndef lint
2static const char rcsid[] =
3	"$Id: main.c,v 1.15 1997/12/26 05:29:29 hoek Exp $";
4#endif
5
6/*
7 *
8 * FreeBSD install - a package for the installation and maintainance
9 * of non-core utilities.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 *
20 * Jordan K. Hubbard
21 * 18 July 1993
22 *
23 * This is the info module.
24 *
25 */
26
27#include <err.h>
28#include "lib.h"
29#include "info.h"
30
31static char Options[] = "acdDe:fikrRpLqImvhl:";
32
33int	Flags		= 0;
34Boolean AllInstalled	= FALSE;
35Boolean Quiet		= FALSE;
36char *InfoPrefix	= "";
37char PlayPen[FILENAME_MAX];
38char *CheckPkg		= NULL;
39
40static void usage __P((void));
41
42int
43main(int argc, char **argv)
44{
45    int ch;
46    char **pkgs, **start;
47
48    pkgs = start = argv;
49    if (argc == 1) {
50	AllInstalled = TRUE;
51	Flags = SHOW_INDEX;
52    }
53    else while ((ch = getopt(argc, argv, Options)) != -1) {
54	switch(ch) {
55	case 'a':
56	    AllInstalled = TRUE;
57	    break;
58
59	case 'v':
60	    Verbose = TRUE;
61	    /* Reasonable definition of 'everything' */
62	    Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL |
63		SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE;
64	    break;
65
66	case 'I':
67	    Flags |= SHOW_INDEX;
68	    break;
69
70	case 'p':
71	    Flags |= SHOW_PREFIX;
72	    break;
73
74	case 'c':
75	    Flags |= SHOW_COMMENT;
76	    break;
77
78	case 'd':
79	    Flags |= SHOW_DESC;
80	    break;
81
82	case 'D':
83	    Flags |= SHOW_DISPLAY;
84	    break;
85
86	case 'f':
87	    Flags |= SHOW_PLIST;
88	    break;
89
90	case 'i':
91	    Flags |= SHOW_INSTALL;
92	    break;
93
94	case 'k':
95	    Flags |= SHOW_DEINSTALL;
96	    break;
97
98	case 'r':
99	    Flags |= SHOW_REQUIRE;
100	    break;
101
102	case 'R':
103	    Flags |= SHOW_REQBY;
104	    break;
105
106	case 'L':
107	    Flags |= SHOW_FILES;
108	    break;
109
110	case 'm':
111	    Flags |= SHOW_MTREE;
112	    break;
113
114	case 'l':
115	    InfoPrefix = optarg;
116	    break;
117
118	case 'q':
119	    Quiet = TRUE;
120	    break;
121
122	case 't':
123	    strcpy(PlayPen, optarg);
124	    break;
125
126	case 'e':
127	    CheckPkg = optarg;
128	    break;
129
130	case 'h':
131	case '?':
132	default:
133	    usage();
134	    break;
135	}
136    }
137
138    argc -= optind;
139    argv += optind;
140
141    /* Set some reasonable defaults */
142    if (!Flags)
143	Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY;
144
145    /* Get all the remaining package names, if any */
146    while (*argv)
147	*pkgs++ = *argv++;
148
149    /* If no packages, yelp */
150    if (pkgs == start && !AllInstalled && !CheckPkg)
151	warnx("missing package name(s)"), usage();
152    *pkgs = NULL;
153    return pkg_perform(start);
154}
155
156static void
157usage()
158{
159    fprintf(stderr, "%s\n%s\n%s\n",
160	"usage: pkg_info [-cdDikrRpLqImv] [-e package] [-l prefix]",
161	"                pkg-name [pkg-name ...]",
162	"       pkg_info -a [flags]");
163    exit(1);
164}
165