main.c revision 62775
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 62775 2000-07-07 13:06:32Z sobomax $"; 29#endif 30 31static char Options[] = "acdDe:fhiIkl:LmpqrRst: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 'l': 120 InfoPrefix = optarg; 121 break; 122 123 case 'q': 124 Quiet = TRUE; 125 break; 126 127 case 't': 128 strcpy(PlayPen, optarg); 129 break; 130 131 case 'e': 132 CheckPkg = optarg; 133 break; 134 135 case 'h': 136 case '?': 137 default: 138 usage(); 139 break; 140 } 141 } 142 143 argc -= optind; 144 argv += optind; 145 146 /* Set some reasonable defaults */ 147 if (!Flags) 148 Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY; 149 150 /* Get all the remaining package names, if any */ 151 while (*argv) { 152 while ((pkgs_split = rindex(*argv, (int)'/')) != NULL) { 153 *pkgs_split++ = '\0'; 154 /* 155 * If character after the '/' is alphanumeric, then we've found the 156 * package name. Otherwise we've come across a trailing '/' and 157 * need to continue our quest. 158 */ 159 if (isalpha(*pkgs_split)) { 160 *argv = pkgs_split; 161 break; 162 } 163 } 164 *pkgs++ = *argv++; 165 } 166 167 /* If no packages, yelp */ 168 if (pkgs == start && !AllInstalled && !CheckPkg) 169 warnx("missing package name(s)"), usage(); 170 *pkgs = NULL; 171 return pkg_perform(start); 172} 173 174static void 175usage() 176{ 177 fprintf(stderr, "%s\n%s\n%s\n", 178 "usage: pkg_info [-cdDfikrRpLqImv] [-e package] [-l prefix]", 179 " [-t template] [pkg-name ...]", 180 " pkg_info -a [flags]"); 181 exit(1); 182} 183