main.c revision 411
1#ifndef lint
2static char *rcsid = "$Header: /usr1/cvs/jkh/pkg_install/info/main.c,v 1.5 1993/09/04 05:06:41 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[] = "acde:fikrpLqIvhl:";
30
31int	Flags		= 0;
32Boolean AllInstalled	= FALSE;
33Boolean Quiet		= FALSE;
34char *InfoPrefix	= "";
35char *PlayPen		= NULL;
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;
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 'f':
76	    Flags |= SHOW_PLIST;
77	    break;
78
79	case 'i':
80	    Flags |= SHOW_INSTALL;
81	    break;
82
83	case 'k':
84	    Flags |= SHOW_DEINSTALL;
85	    break;
86
87	case 'r':
88	    Flags |= SHOW_REQUIRE;
89	    break;
90
91	case 'L':
92	    Flags |= SHOW_FILES;
93	    break;
94
95	case 'l':
96	    InfoPrefix = optarg;
97	    break;
98
99	case 'q':
100	    Quiet = TRUE;
101	    break;
102
103	case 't':
104	    PlayPen = optarg;
105	    break;
106
107	case 'e':
108	    CheckPkg = optarg;
109	    break;
110
111	case 'h':
112	case '?':
113	default:
114	    usage(prog_name, NULL);
115	    break;
116	}
117
118    argc -= optind;
119    argv += optind;
120
121    /* Set some reasonable defaults */
122    if (!Flags)
123	Flags = SHOW_COMMENT | SHOW_DESC;
124
125    /* Get all the remaining package names, if any */
126    while (*argv)
127	*pkgs++ = *argv++;
128
129    /* If no packages, yelp */
130    if (pkgs == start && !AllInstalled && !CheckPkg)
131	usage(prog_name, "Missing package name(s)");
132    *pkgs = NULL;
133    return pkg_perform(start);
134}
135
136void
137usage(const char *name, const char *fmt, ...)
138{
139    va_list args;
140
141    va_start(args, fmt);
142    if (fmt) {
143	fprintf(stderr, "%s: ", name);
144	vfprintf(stderr, fmt, args);
145	fprintf(stderr, "\n\n");
146    }
147    va_end(args);
148    fprintf(stderr, "Usage: %s [args] pkg [ .. pkg ]\n", name);
149    fprintf(stderr, "Where args are one or more of:\n\n");
150    fprintf(stderr, "-a         show all installed packages (if any)\n");
151    fprintf(stderr, "-I         print 'index' of packages\n");
152    fprintf(stderr, "-c         print `one line comment'\n");
153    fprintf(stderr, "-d         print description\n");
154    fprintf(stderr, "-f         show packing list\n");
155    fprintf(stderr, "-i         show install script\n");
156    fprintf(stderr, "-k         show deinstall script\n");
157    fprintf(stderr, "-r         show requirements script\n");
158    fprintf(stderr, "-p         show prefix\n");
159    fprintf(stderr, "-l <str>   Prefix each info catagory with <str>\n");
160    fprintf(stderr, "-v         show all information\n");
161    fprintf(stderr, "-t temp    use temp as template for mktemp()\n");
162    fprintf(stderr, "\n[no args = -c -d]\n");
163    exit(1);
164}
165