main.c revision 392
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:fikrpIvhl:";
30
31int	Flags		= 0;
32Boolean AllInstalled	= FALSE;
33char *InfoPrefix	= "";
34char *PlayPen		= NULL;
35char *CheckPkg		= NULL;
36
37int
38main(int argc, char **argv)
39{
40    int ch;
41    char **pkgs, **start;
42    char *prog_name = argv[0];
43
44    pkgs = start = argv;
45    while ((ch = getopt(argc, argv, Options)) != EOF)
46	switch(ch) {
47	case 'a':
48	    AllInstalled = TRUE;
49	    break;
50
51	case 'v':
52	    Verbose = TRUE;
53	    /* Reasonable definition of 'everything' */
54	    Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL |
55		SHOW_DEINSTALL | SHOW_REQUIRE;
56	    break;
57
58	case 'I':
59	    Flags |= SHOW_INDEX;
60	    break;
61
62	case 'p':
63	    Flags |= SHOW_PREFIX;
64	    break;
65
66	case 'c':
67	    Flags |= SHOW_COMMENT;
68	    break;
69
70	case 'd':
71	    Flags |= SHOW_DESC;
72	    break;
73
74	case 'f':
75	    Flags |= SHOW_PLIST;
76	    break;
77
78	case 'i':
79	    Flags |= SHOW_INSTALL;
80	    break;
81
82	case 'k':
83	    Flags |= SHOW_DEINSTALL;
84	    break;
85
86	case 'r':
87	    Flags |= SHOW_REQUIRE;
88	    break;
89
90	case 'l':
91	    InfoPrefix = optarg;
92	    break;
93
94	case 't':
95	    PlayPen = optarg;
96	    break;
97
98	case 'e':
99	    CheckPkg = optarg;
100	    break;
101
102	case 'h':
103	case '?':
104	default:
105	    usage(prog_name, NULL);
106	    break;
107	}
108
109    argc -= optind;
110    argv += optind;
111
112    /* Set some reasonable defaults */
113    if (!Flags)
114	Flags = SHOW_COMMENT | SHOW_DESC;
115
116    /* Get all the remaining package names, if any */
117    while (*argv)
118	*pkgs++ = *argv++;
119
120    /* If no packages, yelp */
121    if (pkgs == start && !AllInstalled && !CheckPkg)
122	usage(prog_name, "Missing package name(s)");
123    *pkgs = NULL;
124    return pkg_perform(start);
125}
126
127void
128usage(const char *name, const char *fmt, ...)
129{
130    va_list args;
131
132    va_start(args, fmt);
133    if (fmt) {
134	fprintf(stderr, "%s: ", name);
135	vfprintf(stderr, fmt, args);
136	fprintf(stderr, "\n\n");
137    }
138    va_end(args);
139    fprintf(stderr, "Usage: %s [args] pkg [ .. pkg ]\n", name);
140    fprintf(stderr, "Where args are one or more of:\n\n");
141    fprintf(stderr, "-a         show all installed packages (if any)\n");
142    fprintf(stderr, "-I         print 'index' of packages\n");
143    fprintf(stderr, "-c         print `one line comment'\n");
144    fprintf(stderr, "-d         print description\n");
145    fprintf(stderr, "-f         show packing list\n");
146    fprintf(stderr, "-i         show install script\n");
147    fprintf(stderr, "-k         show deinstall script\n");
148    fprintf(stderr, "-r         show requirements script\n");
149    fprintf(stderr, "-p         show prefix\n");
150    fprintf(stderr, "-l <str>   Prefix each info catagory with <str>\n");
151    fprintf(stderr, "-v         show all information\n");
152    fprintf(stderr, "-t temp    use temp as template for mktemp()\n");
153    fprintf(stderr, "\n[no args = -c -d]\n");
154    exit(1);
155}
156