main.c revision 84750
1327Sjkh/* 2327Sjkh * 3327Sjkh * FreeBSD install - a package for the installation and maintainance 4327Sjkh * of non-core utilities. 5327Sjkh * 6327Sjkh * Redistribution and use in source and binary forms, with or without 7327Sjkh * modification, are permitted provided that the following conditions 8327Sjkh * are met: 9327Sjkh * 1. Redistributions of source code must retain the above copyright 10327Sjkh * notice, this list of conditions and the following disclaimer. 11327Sjkh * 2. Redistributions in binary form must reproduce the above copyright 12327Sjkh * notice, this list of conditions and the following disclaimer in the 13327Sjkh * documentation and/or other materials provided with the distribution. 14327Sjkh * 15327Sjkh * Jordan K. Hubbard 16327Sjkh * 18 July 1993 17327Sjkh * 1831997Shoek * This is the info module. 19327Sjkh * 20327Sjkh */ 21327Sjkh 22327Sjkh#include "lib.h" 23327Sjkh#include "info.h" 2474699Ssobomax#include <err.h> 25327Sjkh 2655567Sphantom#ifndef lint 2755567Sphantomstatic const char rcsid[] = 2855567Sphantom "$FreeBSD: head/usr.sbin/pkg_install/info/main.c 84750 2001-10-10 08:21:41Z sobomax $"; 2955567Sphantom#endif 30327Sjkh 3184750Ssobomaxstatic char Options[] = "acdDe:fgGhiIkl:LmopqrRst:vVW:x"; 3255567Sphantom 33327Sjkhint Flags = 0; 3472174Ssobomaxmatch_t MatchType = MATCH_GLOB; 35411SjkhBoolean Quiet = FALSE; 3684745Ssobomaxchar *InfoPrefix = (char *)(uintptr_t)""; 3711780Sjkhchar PlayPen[FILENAME_MAX]; 38392Sjkhchar *CheckPkg = NULL; 3974699Ssobomaxstruct which_head *whead; 40327Sjkh 4130221Scharnierstatic void usage __P((void)); 4230221Scharnier 43327Sjkhint 44327Sjkhmain(int argc, char **argv) 45327Sjkh{ 46327Sjkh int ch; 47327Sjkh char **pkgs, **start; 4856001Sdan char *pkgs_split; 49327Sjkh 5074699Ssobomax whead = malloc(sizeof(struct which_head)); 5174699Ssobomax if (whead == NULL) 5274699Ssobomax err(2, NULL); 5374699Ssobomax TAILQ_INIT(whead); 5474699Ssobomax 55327Sjkh pkgs = start = argv; 5646105Sjkh if (argc == 1) { 5772174Ssobomax MatchType = MATCH_ALL; 5846105Sjkh Flags = SHOW_INDEX; 5946105Sjkh } 6046105Sjkh else while ((ch = getopt(argc, argv, Options)) != -1) { 61327Sjkh switch(ch) { 62327Sjkh case 'a': 6372174Ssobomax MatchType = MATCH_ALL; 64327Sjkh break; 65327Sjkh 66327Sjkh case 'v': 67327Sjkh Verbose = TRUE; 68327Sjkh /* Reasonable definition of 'everything' */ 69327Sjkh Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL | 704996Sjkh SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE; 71327Sjkh break; 72327Sjkh 73327Sjkh case 'I': 74327Sjkh Flags |= SHOW_INDEX; 75327Sjkh break; 76327Sjkh 77327Sjkh case 'p': 78327Sjkh Flags |= SHOW_PREFIX; 79327Sjkh break; 80327Sjkh 81327Sjkh case 'c': 82327Sjkh Flags |= SHOW_COMMENT; 83327Sjkh break; 84327Sjkh 85327Sjkh case 'd': 86327Sjkh Flags |= SHOW_DESC; 87327Sjkh break; 88327Sjkh 894996Sjkh case 'D': 904996Sjkh Flags |= SHOW_DISPLAY; 914996Sjkh break; 924996Sjkh 93327Sjkh case 'f': 94327Sjkh Flags |= SHOW_PLIST; 95327Sjkh break; 96327Sjkh 9771965Sjkh case 'g': 9871965Sjkh Flags |= SHOW_CKSUM; 9971965Sjkh break; 10071965Sjkh 10172174Ssobomax case 'G': 10272174Ssobomax MatchType = MATCH_EXACT; 10372174Ssobomax break; 10472174Ssobomax 105327Sjkh case 'i': 106327Sjkh Flags |= SHOW_INSTALL; 107327Sjkh break; 108327Sjkh 109327Sjkh case 'k': 110327Sjkh Flags |= SHOW_DEINSTALL; 111327Sjkh break; 112327Sjkh 113327Sjkh case 'r': 114327Sjkh Flags |= SHOW_REQUIRE; 115327Sjkh break; 116327Sjkh 1174996Sjkh case 'R': 1184996Sjkh Flags |= SHOW_REQBY; 1194996Sjkh break; 1204996Sjkh 121411Sjkh case 'L': 122411Sjkh Flags |= SHOW_FILES; 123411Sjkh break; 124411Sjkh 1254996Sjkh case 'm': 1264996Sjkh Flags |= SHOW_MTREE; 1274996Sjkh break; 1284996Sjkh 12972174Ssobomax case 's': 13072174Ssobomax Flags |= SHOW_SIZE; 13172174Ssobomax break; 13262775Ssobomax 13367454Ssobomax case 'o': 13467454Ssobomax Flags |= SHOW_ORIGIN; 13567454Ssobomax break; 13667454Ssobomax 13784750Ssobomax case 'V': 13884750Ssobomax Flags |= SHOW_FMTREV; 13984750Ssobomax break; 14084750Ssobomax 141379Sjkh case 'l': 142379Sjkh InfoPrefix = optarg; 143379Sjkh break; 144379Sjkh 145411Sjkh case 'q': 146411Sjkh Quiet = TRUE; 147411Sjkh break; 148411Sjkh 149383Sjkh case 't': 15011780Sjkh strcpy(PlayPen, optarg); 151383Sjkh break; 152383Sjkh 15372174Ssobomax case 'x': 15472174Ssobomax MatchType = MATCH_REGEX; 15572174Ssobomax break; 15672174Ssobomax 157392Sjkh case 'e': 158392Sjkh CheckPkg = optarg; 159392Sjkh break; 160392Sjkh 16174699Ssobomax case 'W': 16274699Ssobomax { 16374699Ssobomax struct which_entry *entp; 16474699Ssobomax 16574699Ssobomax entp = calloc(1, sizeof(struct which_entry)); 16674699Ssobomax if (entp == NULL) 16774699Ssobomax err(2, NULL); 16874699Ssobomax 16974699Ssobomax strlcpy(entp->file, optarg, PATH_MAX); 17074699Ssobomax entp->skip = FALSE; 17174699Ssobomax TAILQ_INSERT_TAIL(whead, entp, next); 17274699Ssobomax break; 17374699Ssobomax } 17474699Ssobomax 175327Sjkh case 'h': 176327Sjkh case '?': 177327Sjkh default: 17830221Scharnier usage(); 179327Sjkh break; 180327Sjkh } 18146105Sjkh } 182327Sjkh 1838857Srgrimes argc -= optind; 184327Sjkh argv += optind; 185327Sjkh 186327Sjkh /* Set some reasonable defaults */ 187327Sjkh if (!Flags) 1884996Sjkh Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY; 189327Sjkh 190327Sjkh /* Get all the remaining package names, if any */ 19160563Ssteve while (*argv) { 19272174Ssobomax /* Don't try to apply heuristics if arguments are regexs */ 19372174Ssobomax if (MatchType != MATCH_REGEX) 19472174Ssobomax while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) { 19572174Ssobomax *pkgs_split++ = '\0'; 19672174Ssobomax /* 19772174Ssobomax * If character after the '/' is alphanumeric or shell 19872174Ssobomax * metachar, then we've found the package name. Otherwise 19972174Ssobomax * we've come across a trailing '/' and need to continue our 20072174Ssobomax * quest. 20172174Ssobomax */ 20272174Ssobomax if (isalpha(*pkgs_split) || ((MatchType == MATCH_GLOB) && \ 20372174Ssobomax strpbrk(pkgs_split, "*?[]") != NULL)) { 20472174Ssobomax *argv = pkgs_split; 20572174Ssobomax break; 20672174Ssobomax } 20760563Ssteve } 20860563Ssteve *pkgs++ = *argv++; 20956001Sdan } 210327Sjkh 211327Sjkh /* If no packages, yelp */ 21274699Ssobomax if (pkgs == start && MatchType != MATCH_ALL && !CheckPkg && 21374699Ssobomax TAILQ_EMPTY(whead)) 21430221Scharnier warnx("missing package name(s)"), usage(); 215327Sjkh *pkgs = NULL; 216327Sjkh return pkg_perform(start); 217327Sjkh} 218327Sjkh 21930221Scharnierstatic void 22030221Scharnierusage() 221327Sjkh{ 22230221Scharnier fprintf(stderr, "%s\n%s\n%s\n", 22384750Ssobomax "usage: pkg_info [-cdDfGiIkLmopqrRsvVx] [-e package] [-l prefix]", 22474699Ssobomax " [-t template] [-W filename] [pkg-name ...]", 22530221Scharnier " pkg_info -a [flags]"); 226327Sjkh exit(1); 227327Sjkh} 228