main.c revision 67454
1/* 2 * 3 * FreeBSD install - a package for the installation and maintainance 4 * of non-core utilities. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * Jordan K. Hubbard 16 * 18 July 1993 17 * 18 * This is the info module. 19 * 20 */ 21 22#include <err.h> 23#include "lib.h" 24#include "info.h" 25 26#ifndef lint 27static const char rcsid[] = 28 "$FreeBSD: head/usr.sbin/pkg_install/info/main.c 67454 2000-10-23 07:01:31Z sobomax $"; 29#endif 30 31static char Options[] = "acdDe:fhiIkl:LmopqrRst:v"; 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 char *pkgs_split; 48 49 pkgs = start = argv; 50 if (argc == 1) { 51 AllInstalled = TRUE; 52 Flags = SHOW_INDEX; 53 } 54 else while ((ch = getopt(argc, argv, Options)) != -1) { 55 switch(ch) { 56 case 'a': 57 AllInstalled = TRUE; 58 break; 59 60 case 'v': 61 Verbose = TRUE; 62 /* Reasonable definition of 'everything' */ 63 Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL | 64 SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE; 65 break; 66 67 case 'I': 68 Flags |= SHOW_INDEX; 69 break; 70 71 case 'p': 72 Flags |= SHOW_PREFIX; 73 break; 74 75 case 'c': 76 Flags |= SHOW_COMMENT; 77 break; 78 79 case 'd': 80 Flags |= SHOW_DESC; 81 break; 82 83 case 'D': 84 Flags |= SHOW_DISPLAY; 85 break; 86 87 case 'f': 88 Flags |= SHOW_PLIST; 89 break; 90 91 case 'i': 92 Flags |= SHOW_INSTALL; 93 break; 94 95 case 'k': 96 Flags |= SHOW_DEINSTALL; 97 break; 98 99 case 'r': 100 Flags |= SHOW_REQUIRE; 101 break; 102 103 case 'R': 104 Flags |= SHOW_REQBY; 105 break; 106 107 case 'L': 108 Flags |= SHOW_FILES; 109 break; 110 111 case 'm': 112 Flags |= SHOW_MTREE; 113 break; 114 115 case 's': 116 Flags |= SHOW_SIZE; 117 break; 118 119 case 'o': 120 Flags |= SHOW_ORIGIN; 121 break; 122 123 case 'l': 124 InfoPrefix = optarg; 125 break; 126 127 case 'q': 128 Quiet = TRUE; 129 break; 130 131 case 't': 132 strcpy(PlayPen, optarg); 133 break; 134 135 case 'e': 136 CheckPkg = optarg; 137 break; 138 139 case 'h': 140 case '?': 141 default: 142 usage(); 143 break; 144 } 145 } 146 147 argc -= optind; 148 argv += optind; 149 150 /* Set some reasonable defaults */ 151 if (!Flags) 152 Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY; 153 154 /* Get all the remaining package names, if any */ 155 while (*argv) { 156 while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) { 157 *pkgs_split++ = '\0'; 158 /* 159 * If character after the '/' is alphanumeric, then we've found the 160 * package name. Otherwise we've come across a trailing '/' and 161 * need to continue our quest. 162 */ 163 if (isalpha(*pkgs_split)) { 164 *argv = pkgs_split; 165 break; 166 } 167 } 168 *pkgs++ = *argv++; 169 } 170 171 /* If no packages, yelp */ 172 if (pkgs == start && !AllInstalled && !CheckPkg) 173 warnx("missing package name(s)"), usage(); 174 *pkgs = NULL; 175 return pkg_perform(start); 176} 177 178static void 179usage() 180{ 181 fprintf(stderr, "%s\n%s\n%s\n", 182 "usage: pkg_info [-cdDfikorRpLqImv] [-e package] [-l prefix]", 183 " [-t template] [pkg-name ...]", 184 " pkg_info -a [flags]"); 185 exit(1); 186} 187