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