main.c revision 56001
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 56001 2000-01-15 01:15:37Z dan $"; 29#endif 30 31static char Options[] = "acdDe:fhiIkl:LmpqrRt: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 'l': 116 InfoPrefix = optarg; 117 break; 118 119 case 'q': 120 Quiet = TRUE; 121 break; 122 123 case 't': 124 strcpy(PlayPen, optarg); 125 break; 126 127 case 'e': 128 CheckPkg = optarg; 129 break; 130 131 case 'h': 132 case '?': 133 default: 134 usage(); 135 break; 136 } 137 } 138 139 argc -= optind; 140 argv += optind; 141 142 /* Set some reasonable defaults */ 143 if (!Flags) 144 Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY; 145 146 /* Get all the remaining package names, if any */ 147 while (*argv) 148 { 149 if( (pkgs_split = rindex(*argv, (int) '/')) != NULL ) 150 { 151 while( !isalpha(*(pkgs_split+1)) ) 152 { 153 *pkgs_split = '\0'; 154 pkgs_split = rindex(*argv, (int) '/'); 155 } 156 if(pkgs_split != NULL) 157 { 158 pkgs_split++; 159 *pkgs = pkgs_split; 160 pkgs++; 161 } 162 } 163 else 164 { 165 *pkgs = *argv; 166 pkgs++; 167 } 168 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 [-cdDfikrRpLqImv] [-e package] [-l prefix]", 183 " [-t template] [pkg-name ...]", 184 " pkg_info -a [flags]"); 185 exit(1); 186} 187