main.c revision 383
1178481Sjb#ifndef lint 2178481Sjbstatic char *rcsid = "$Header: /usr1/cvs/jkh/pkg_install/info/main.c,v 1.5 1993/09/04 05:06:41 jkh Exp $"; 3178481Sjb#endif 4178481Sjb 5178481Sjb/* 6178481Sjb * 7178481Sjb * FreeBSD install - a package for the installation and maintainance 8178481Sjb * of non-core utilities. 9178481Sjb * 10178481Sjb * Redistribution and use in source and binary forms, with or without 11178481Sjb * modification, are permitted provided that the following conditions 12178481Sjb * are met: 13178481Sjb * 1. Redistributions of source code must retain the above copyright 14178481Sjb * notice, this list of conditions and the following disclaimer. 15178481Sjb * 2. Redistributions in binary form must reproduce the above copyright 16178481Sjb * notice, this list of conditions and the following disclaimer in the 17178481Sjb * documentation and/or other materials provided with the distribution. 18178481Sjb * 19178481Sjb * Jordan K. Hubbard 20178481Sjb * 18 July 1993 21178481Sjb * 22178481Sjb * This is the add module. 23178481Sjb * 24178481Sjb */ 25178481Sjb 26178481Sjb#include "lib.h" 27178481Sjb#include "info.h" 28178481Sjb 29178481Sjbstatic char Options[] = "acdfikrpIvhl:"; 30178481Sjb 31178481Sjbint Flags = 0; 32178481SjbBoolean AllInstalled = FALSE; 33178481Sjbchar *InfoPrefix = ""; 34178481Sjbchar *PlayPen = NULL; 35178481Sjb 36178481Sjbint 37178481Sjbmain(int argc, char **argv) 38178481Sjb{ 39178481Sjb int ch; 40178481Sjb char **pkgs, **start; 41178481Sjb char *prog_name = argv[0]; 42178481Sjb 43178481Sjb pkgs = start = argv; 44178481Sjb while ((ch = getopt(argc, argv, Options)) != EOF) 45178481Sjb switch(ch) { 46178481Sjb case 'a': 47178481Sjb AllInstalled = TRUE; 48178481Sjb break; 49178481Sjb 50178481Sjb case 'v': 51178481Sjb Verbose = TRUE; 52178481Sjb /* Reasonable definition of 'everything' */ 53178481Sjb Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL | 54178481Sjb SHOW_DEINSTALL | SHOW_REQUIRE; 55178481Sjb break; 56178481Sjb 57178481Sjb case 'I': 58178481Sjb Flags |= SHOW_INDEX; 59178481Sjb break; 60178481Sjb 61178481Sjb case 'p': 62178481Sjb Flags |= SHOW_PREFIX; 63178481Sjb break; 64178481Sjb 65178481Sjb case 'c': 66178481Sjb Flags |= SHOW_COMMENT; 67178481Sjb break; 68178481Sjb 69178481Sjb case 'd': 70178481Sjb Flags |= SHOW_DESC; 71178481Sjb break; 72178481Sjb 73178481Sjb case 'f': 74178546Sjb Flags |= SHOW_PLIST; 75178481Sjb break; 76178481Sjb 77178481Sjb case 'i': 78178481Sjb Flags |= SHOW_INSTALL; 79178481Sjb break; 80178481Sjb 81178481Sjb case 'k': 82178481Sjb Flags |= SHOW_DEINSTALL; 83178481Sjb break; 84178481Sjb 85178481Sjb case 'r': 86178481Sjb Flags |= SHOW_REQUIRE; 87178481Sjb break; 88178481Sjb 89178481Sjb case 'l': 90178481Sjb InfoPrefix = optarg; 91178546Sjb break; 92178481Sjb 93178481Sjb case 't': 94178481Sjb PlayPen = optarg; 95178481Sjb break; 96178481Sjb 97178481Sjb case 'h': 98178481Sjb case '?': 99178481Sjb default: 100178481Sjb usage(prog_name, NULL); 101178481Sjb break; 102178481Sjb } 103178481Sjb 104178481Sjb argc -= optind; 105178481Sjb argv += optind; 106178481Sjb 107178481Sjb /* Set some reasonable defaults */ 108178481Sjb if (!Flags) 109178481Sjb Flags = SHOW_COMMENT | SHOW_DESC; 110178481Sjb 111178481Sjb /* Get all the remaining package names, if any */ 112178481Sjb while (*argv) 113178481Sjb *pkgs++ = *argv++; 114178481Sjb 115178481Sjb /* If no packages, yelp */ 116178481Sjb if (pkgs == start && !AllInstalled) 117178481Sjb usage(prog_name, "Missing package name(s)"); 118178481Sjb *pkgs = NULL; 119178481Sjb return pkg_perform(start); 120178481Sjb} 121178481Sjb 122178481Sjbvoid 123178481Sjbusage(const char *name, const char *fmt, ...) 124178481Sjb{ 125178481Sjb va_list args; 126178481Sjb 127178481Sjb va_start(args, fmt); 128178481Sjb if (fmt) { 129178481Sjb fprintf(stderr, "%s: ", name); 130178481Sjb vfprintf(stderr, fmt, args); 131178481Sjb fprintf(stderr, "\n\n"); 132178481Sjb } 133178481Sjb va_end(args); 134178481Sjb fprintf(stderr, "Usage: %s [args] pkg [ .. pkg ]\n", name); 135178481Sjb fprintf(stderr, "Where args are one or more of:\n\n"); 136178481Sjb fprintf(stderr, "-a show all installed packages (if any)\n"); 137178481Sjb fprintf(stderr, "-I print 'index' of packages\n"); 138178481Sjb fprintf(stderr, "-c print `one line comment'\n"); 139178481Sjb fprintf(stderr, "-d print description\n"); 140178481Sjb fprintf(stderr, "-f show packing list\n"); 141178481Sjb fprintf(stderr, "-i show install script\n"); 142178481Sjb fprintf(stderr, "-k show deinstall script\n"); 143178481Sjb fprintf(stderr, "-r show requirements script\n"); 144178481Sjb fprintf(stderr, "-p show prefix\n"); 145178481Sjb fprintf(stderr, "-l <str> Prefix each info catagory with <str>\n"); 146178481Sjb fprintf(stderr, "-v show all information\n"); 147178481Sjb fprintf(stderr, "-t temp use temp as template for mktemp()\n"); 148178481Sjb fprintf(stderr, "\n[no args = -c -d]\n"); 149178481Sjb exit(1); 150178481Sjb} 151178481Sjb