Make pkg_info a tad more extensible by using a table to hold the strings
to be printed. Also, don't error out if any unexpected input is read - just log the error, and keep on going. Fix a slight bug along the way - if there was an @option in the package, then pkg_info would die.
This commit is contained in:
parent
5422d07da0
commit
3679178e31
|
@ -1,11 +1,11 @@
|
||||||
/* $NetBSD: show.c,v 1.6 1998/10/09 09:35:39 agc Exp $ */
|
/* $NetBSD: show.c,v 1.7 1998/10/09 11:05:58 agc Exp $ */
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
#if 0
|
#if 0
|
||||||
static const char *rcsid = "from FreeBSD Id: show.c,v 1.11 1997/10/08 07:47:38 charnier Exp";
|
static const char *rcsid = "from FreeBSD Id: show.c,v 1.11 1997/10/08 07:47:38 charnier Exp";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: show.c,v 1.6 1998/10/09 09:35:39 agc Exp $");
|
__RCSID("$NetBSD: show.c,v 1.7 1998/10/09 11:05:58 agc Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -34,148 +34,135 @@ __RCSID("$NetBSD: show.c,v 1.6 1998/10/09 09:35:39 agc Exp $");
|
||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
|
|
||||||
|
/* structure to define entries for the "show table" */
|
||||||
|
typedef struct show_t {
|
||||||
|
plist_t sh_type; /* type of entry */
|
||||||
|
char *sh_quiet; /* message when quiet */
|
||||||
|
char *sh_verbose; /* message when verbose */
|
||||||
|
} show_t;
|
||||||
|
|
||||||
|
/* the entries in this table must be ordered the same as plist_t constants */
|
||||||
|
static show_t showv[] = {
|
||||||
|
{ PLIST_FILE, "%s", "File: %s" },
|
||||||
|
{ PLIST_CWD, "@cwd: %s", "\tCWD to: %s" },
|
||||||
|
{ PLIST_CMD, "@exec %s", "\tEXEC '%s'" },
|
||||||
|
{ PLIST_CHMOD, "@chmod %s", "\tCHMOD to %s" },
|
||||||
|
{ PLIST_CHOWN, "@chown %s", "\tCHOWN to %s" },
|
||||||
|
{ PLIST_CHGRP, "@chgrp %s", "\tCHGRP to %s" },
|
||||||
|
{ PLIST_COMMENT, "@comment %s", "\tComment: %s" },
|
||||||
|
{ PLIST_IGNORE, NULL, NULL },
|
||||||
|
{ PLIST_NAME, "@name %s", "\tPackage name: " },
|
||||||
|
{ PLIST_UNEXEC, "@unexec %s", "\tUNEXEC '%s'" },
|
||||||
|
{ PLIST_SRC, "@srcdir: %s", "\tSRCDIR to: %s" },
|
||||||
|
{ PLIST_DISPLAY, "@display %s", "\tInstall message file: %s" },
|
||||||
|
{ PLIST_PKGDEP, "@pkgdep %s", "\tPackage depends on: %s" },
|
||||||
|
{ PLIST_MTREE, "@mtree %s", "\tPackage mtree file: %s" },
|
||||||
|
{ PLIST_DIR_RM, "@dirrm %s", "\tDeinstall directory remove: %s" },
|
||||||
|
{ PLIST_IGNORE_INST, "@ignore_inst ??? doesn't belong here",
|
||||||
|
"\tIgnore next file installation directive (doesn't belong)" },
|
||||||
|
{ PLIST_OPTION, "@option %s", "\tPackage has option: %s" },
|
||||||
|
{ PLIST_PKGCFL, "@pkgcfl %s", "\tPackage conflicts with: %s" },
|
||||||
|
{ -1, NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
show_file(char *title, char *fname)
|
show_file(char *title, char *fname)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char line[1024];
|
char line[1024];
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (!Quiet)
|
if (!Quiet) {
|
||||||
printf("%s%s", InfoPrefix, title);
|
printf("%s%s", InfoPrefix, title);
|
||||||
fp = fopen(fname, "r");
|
}
|
||||||
if (!fp)
|
if ((fp = fopen(fname, "r")) == (FILE *) NULL) {
|
||||||
printf("ERROR: show_file: Can't open '%s' for reading!\n", fname);
|
printf("ERROR: show_file: Can't open '%s' for reading!\n", fname);
|
||||||
else {
|
} else {
|
||||||
while ((n = fread(line, 1, 1024, fp)) != 0)
|
while ((n = fread(line, 1, 1024, fp)) != 0) {
|
||||||
fwrite(line, 1, n, stdout);
|
fwrite(line, 1, n, stdout);
|
||||||
fclose(fp);
|
}
|
||||||
}
|
(void) fclose(fp);
|
||||||
printf("\n"); /* just in case */
|
}
|
||||||
|
printf("\n"); /* just in case */
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
show_index(char *title, char *fname)
|
show_index(char *title, char *fname)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char line[MAXINDEXSIZE+2];
|
char line[MAXINDEXSIZE+2];
|
||||||
|
|
||||||
if (!Quiet)
|
if (!Quiet) {
|
||||||
printf("%s%s", InfoPrefix, title);
|
printf("%s%s", InfoPrefix, title);
|
||||||
fp = fopen(fname, "r");
|
}
|
||||||
if (!fp) {
|
if ((fp = fopen(fname, "r")) == (FILE *) NULL) {
|
||||||
warnx("show_file: can't open '%s' for reading", fname);
|
warnx("show_file: can't open '%s' for reading", fname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(fgets(line, MAXINDEXSIZE+1, fp)) {
|
if (fgets(line, MAXINDEXSIZE+1, fp)) {
|
||||||
if(line[MAXINDEXSIZE-1] != '\n')
|
if (line[MAXINDEXSIZE-1] != '\n') {
|
||||||
line[MAXINDEXSIZE] = '\n';
|
line[MAXINDEXSIZE] = '\n';
|
||||||
line[MAXINDEXSIZE+1] = 0;
|
}
|
||||||
fputs(line, stdout);
|
line[MAXINDEXSIZE+1] = 0;
|
||||||
}
|
(void) fputs(line, stdout);
|
||||||
fclose(fp);
|
}
|
||||||
|
(void) fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show a packing list item type. If type is PLIST_SHOW_ALL, show all */
|
/* Show a packing list item type. If type is PLIST_SHOW_ALL, show all */
|
||||||
void
|
void
|
||||||
show_plist(char *title, Package *plist, plist_t type)
|
show_plist(char *title, Package *plist, plist_t type)
|
||||||
{
|
{
|
||||||
PackingList p;
|
PackingList p;
|
||||||
Boolean ign = FALSE;
|
Boolean ign;
|
||||||
|
|
||||||
if (!Quiet)
|
if (!Quiet) {
|
||||||
printf("%s%s", InfoPrefix, title);
|
printf("%s%s", InfoPrefix, title);
|
||||||
p = plist->head;
|
}
|
||||||
while (p) {
|
for (ign = FALSE, p = plist->head; p ; p = p->next) {
|
||||||
if (p->type != type && type != PLIST_SHOW_ALL) {
|
if (p->type == type || type == PLIST_SHOW_ALL) {
|
||||||
p = p->next;
|
switch(p->type) {
|
||||||
continue;
|
case PLIST_FILE:
|
||||||
|
printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose, p->name);
|
||||||
|
if (ign) {
|
||||||
|
if (!Quiet) {
|
||||||
|
printf(" (ignored)");
|
||||||
|
}
|
||||||
|
ign = FALSE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PLIST_CHMOD:
|
||||||
|
case PLIST_CHOWN:
|
||||||
|
case PLIST_CHGRP:
|
||||||
|
printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose,
|
||||||
|
p->name ? p->name : "(clear default)");
|
||||||
|
break;
|
||||||
|
case PLIST_IGNORE:
|
||||||
|
ign = TRUE;
|
||||||
|
break;
|
||||||
|
case PLIST_IGNORE_INST:
|
||||||
|
printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose, p->name);
|
||||||
|
ign = TRUE;
|
||||||
|
break;
|
||||||
|
case PLIST_CWD:
|
||||||
|
case PLIST_CMD:
|
||||||
|
case PLIST_SRC:
|
||||||
|
case PLIST_UNEXEC:
|
||||||
|
case PLIST_COMMENT:
|
||||||
|
case PLIST_NAME:
|
||||||
|
case PLIST_DISPLAY:
|
||||||
|
case PLIST_PKGDEP:
|
||||||
|
case PLIST_MTREE:
|
||||||
|
case PLIST_DIR_RM:
|
||||||
|
case PLIST_OPTION:
|
||||||
|
case PLIST_PKGCFL:
|
||||||
|
printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose, p->name);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
warnx("unknown command type %d (%s)", p->type, p->name);
|
||||||
|
}
|
||||||
|
(void) fputc('\n', stdout);
|
||||||
}
|
}
|
||||||
switch(p->type) {
|
|
||||||
case PLIST_FILE:
|
|
||||||
if (ign) {
|
|
||||||
printf(Quiet ? "%s\n" : "File: %s (ignored)\n", p->name);
|
|
||||||
ign = FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
printf(Quiet ? "%s\n" : "File: %s\n", p->name);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_CWD:
|
|
||||||
printf(Quiet ? "@cwd %s\n" : "\tCWD to %s\n", p->name);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_SRC:
|
|
||||||
printf(Quiet ? "@srcdir %s\n" : "\tSRCDIR to %s\n", p->name);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_CMD:
|
|
||||||
printf(Quiet ? "@exec %s\n" : "\tEXEC '%s'\n", p->name);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_UNEXEC:
|
|
||||||
printf(Quiet ? "@unexec %s\n" : "\tUNEXEC '%s'\n", p->name);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_CHMOD:
|
|
||||||
printf(Quiet ? "@chmod %s\n" : "\tCHMOD to %s\n",
|
|
||||||
p->name ? p->name : "(clear default)");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_CHOWN:
|
|
||||||
printf(Quiet ? "@chown %s\n" : "\tCHOWN to %s\n",
|
|
||||||
p->name ? p->name : "(clear default)");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_CHGRP:
|
|
||||||
printf(Quiet ? "@chgrp %s\n" : "\tCHGRP to %s\n",
|
|
||||||
p->name ? p->name : "(clear default)");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_COMMENT:
|
|
||||||
printf(Quiet ? "@comment %s\n" : "\tComment: %s\n", p->name);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_IGNORE:
|
|
||||||
ign = TRUE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_IGNORE_INST:
|
|
||||||
printf(Quiet ? "@ignore_inst ??? doesn't belong here.\n" :
|
|
||||||
"\tIgnore next file installation directive (doesn't belong)\n");
|
|
||||||
ign = TRUE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_NAME:
|
|
||||||
printf(Quiet ? "@name %s\n" : "\tPackage name: %s\n", p->name);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_DISPLAY:
|
|
||||||
printf(Quiet ? "@display %s\n" : "\tInstall message file: %s\n", p->name);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_PKGDEP:
|
|
||||||
printf(Quiet ? "@pkgdep %s\n" : "\tPackage depends on: %s\n", p->name);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_MTREE:
|
|
||||||
printf(Quiet ? "@mtree %s\n" : "\tPackage mtree file: %s\n", p->name);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_DIR_RM:
|
|
||||||
printf(Quiet ? "@dirrm %s\n" : "\tDeinstall directory remove: %s\n", p->name);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PLIST_PKGCFL:
|
|
||||||
printf(Quiet ? "@pkgcfl %s\n" : "\tPackage conflicts with: %s\n", p->name);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
cleanup(0);
|
|
||||||
errx(2, "unknown command type %d (%s)", p->type, p->name);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
p = p->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,32 +170,29 @@ show_plist(char *title, Package *plist, plist_t type)
|
||||||
void
|
void
|
||||||
show_files(char *title, Package *plist)
|
show_files(char *title, Package *plist)
|
||||||
{
|
{
|
||||||
PackingList p;
|
PackingList p;
|
||||||
Boolean ign = FALSE;
|
Boolean ign;
|
||||||
char *dir = ".";
|
char *dir = ".";
|
||||||
|
|
||||||
if (!Quiet)
|
if (!Quiet) {
|
||||||
printf("%s%s", InfoPrefix, title);
|
printf("%s%s", InfoPrefix, title);
|
||||||
p = plist->head;
|
}
|
||||||
while (p) {
|
for (ign = FALSE, p = plist->head; p ; p = p->next) {
|
||||||
switch(p->type) {
|
switch(p->type) {
|
||||||
case PLIST_FILE:
|
case PLIST_FILE:
|
||||||
if (!ign)
|
if (!ign) {
|
||||||
printf("%s/%s\n", dir, p->name);
|
printf("%s/%s\n", dir, p->name);
|
||||||
ign = FALSE;
|
}
|
||||||
break;
|
ign = FALSE;
|
||||||
|
break;
|
||||||
case PLIST_CWD:
|
case PLIST_CWD:
|
||||||
dir = p->name;
|
dir = p->name;
|
||||||
break;
|
break;
|
||||||
|
case PLIST_IGNORE:
|
||||||
case PLIST_IGNORE:
|
ign = TRUE;
|
||||||
ign = TRUE;
|
break;
|
||||||
break;
|
default:
|
||||||
|
break;
|
||||||
default:
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
p = p->next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue