From fa156e55d6e6bc94f99e4f36730c1b6a2fcf6fd1 Mon Sep 17 00:00:00 2001 From: swallace Date: Thu, 5 Jan 1995 01:10:13 +0000 Subject: [PATCH] Added new function show_index() which does a 'smart' display of the index file. Index descriptions are limited to MAXINDEXSIZE (60) chars. Any description beyond that is truncated. Also, only the first line is displayed as well. This allows pkg_info -a -I to be formated in two columns with one line per package for easy reading. Reviewed by: jkh --- usr.sbin/pkg_install/info/info.h | 11 ++++++++++- usr.sbin/pkg_install/info/perform.c | 6 +++--- usr.sbin/pkg_install/info/show.c | 25 ++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/usr.sbin/pkg_install/info/info.h b/usr.sbin/pkg_install/info/info.h index 6feb73e69671..860a27578699 100644 --- a/usr.sbin/pkg_install/info/info.h +++ b/usr.sbin/pkg_install/info/info.h @@ -1,4 +1,4 @@ -/* $Id: info.h,v 1.5 1993/09/08 01:46:56 jkh Exp $ */ +/* $Id: info.h,v 1.6 1994/12/06 00:51:42 jkh Exp $ */ /* * FreeBSD install - a package for the installation and maintainance @@ -23,6 +23,14 @@ #ifndef _INST_INFO_H_INCLUDE #define _INST_INFO_H_INCLUDE +#ifndef MAXINDEXSIZE +#define MAXINDEXSIZE 60 +#endif + +#ifndef MAXNAMESIZE +#define MAXNAMESIZE 20 +#endif + #define SHOW_COMMENT 0x0001 #define SHOW_DESC 0x0002 #define SHOW_PLIST 0x0004 @@ -46,5 +54,6 @@ extern char *CheckPkg; extern void show_file(char *, char *); extern void show_plist(char *, Package *, plist_t); extern void show_files(char *, Package *); +extern void show_index(char *, char *); #endif /* _INST_INFO_H_INCLUDE */ diff --git a/usr.sbin/pkg_install/info/perform.c b/usr.sbin/pkg_install/info/perform.c index a28f2a0f9fd7..bde7b2e49e7f 100644 --- a/usr.sbin/pkg_install/info/perform.c +++ b/usr.sbin/pkg_install/info/perform.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: perform.c,v 1.9 1994/10/14 05:57:49 jkh Exp $"; +static const char *rcsid = "$Id: perform.c,v 1.10 1994/12/06 00:51:45 jkh Exp $"; #endif /* @@ -136,8 +136,8 @@ pkg_do(char *pkg) if (Flags & SHOW_INDEX) { char fname[FILENAME_MAX]; - sprintf(fname, "%s\t", pkg); - show_file(fname, COMMENT_FNAME); + sprintf(fname, "%-19s ", pkg); + show_index(fname, COMMENT_FNAME); } else { /* Start showing the package contents */ diff --git a/usr.sbin/pkg_install/info/show.c b/usr.sbin/pkg_install/info/show.c index 93efd0e94722..e9a6cc8e114a 100644 --- a/usr.sbin/pkg_install/info/show.c +++ b/usr.sbin/pkg_install/info/show.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: show.c,v 1.3 1993/09/08 01:46:59 jkh Exp $"; +static const char *rcsid = "$Id: show.c,v 1.4 1994/12/06 00:51:46 jkh Exp $"; #endif /* @@ -45,6 +45,29 @@ show_file(char *title, char *fname) printf("\n"); /* just in case */ } +void +show_index(char *title, char *fname) +{ + FILE *fp; + char line[MAXINDEXSIZE+2]; + int i,n; + + if (!Quiet) + printf("%s%s", InfoPrefix, title); + fp = fopen(fname, "r"); + if (!fp) { + whinge("show_file: Can't open '%s' for reading.", fname); + return; + } + if(fgets(line, MAXINDEXSIZE+1, fp)) { + if(line[MAXINDEXSIZE-1] != '\n') + line[MAXINDEXSIZE] = '\n'; + line[MAXINDEXSIZE+1] = 0; + fputs(line, stdout); + } + fclose(fp); +} + /* Show a packing list item type. If type is -1, show all */ void show_plist(char *title, Package *plist, plist_t type)