Sync with src, version 20060424:

Add support for creating summary file containing all information
	about a package repository needed by package managing software.
	This allows better use of remote binary package repositories.

	Discussed on tech-pkg.
This commit is contained in:
dillo 2006-04-24 13:52:04 +00:00
parent 7dd1a3904a
commit 10da79a1a1
15 changed files with 402 additions and 49 deletions

View file

@ -1,4 +1,4 @@
@comment $NetBSD: PLIST,v 1.7 2006/01/06 19:46:26 rillig Exp $
@comment $NetBSD: PLIST,v 1.8 2006/04/24 13:52:04 dillo Exp $
man/cat1/linkfarm.0
man/cat1/pkg_add.0
man/cat1/pkg_admin.0
@ -6,6 +6,7 @@ man/cat1/pkg_create.0
man/cat1/pkg_delete.0
man/cat1/pkg_info.0
man/cat1/pkg_view.0
man/cat5/pkg_summary.0
man/man1/linkfarm.1
man/man1/pkg_add.1
man/man1/pkg_admin.1
@ -13,6 +14,7 @@ man/man1/pkg_create.1
man/man1/pkg_delete.1
man/man1/pkg_info.1
man/man1/pkg_view.1
man/man5/pkg_summary.5
sbin/linkfarm
sbin/pkg_add
sbin/pkg_admin

View file

@ -1,4 +1,4 @@
/* $NetBSD: perform.c,v 1.40 2006/04/06 06:49:30 reed Exp $ */
/* $NetBSD: perform.c,v 1.41 2006/04/24 13:52:04 dillo Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -14,7 +14,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp";
#else
__RCSID("$NetBSD: perform.c,v 1.40 2006/04/06 06:49:30 reed Exp $");
__RCSID("$NetBSD: perform.c,v 1.41 2006/04/24 13:52:04 dillo Exp $");
#endif
#endif
@ -75,26 +75,6 @@ static char *Home;
static lfile_head_t files;
/*
* Some systems such as OpenBSD-3.6 do not provide PRIu64.
* Others such as AIX-4.3.2 have a broken PRIu64 which includes
* a leading "%".
*/
#ifdef NEED_PRI_MACRO
# ifdef PRIu64
# undef PRIu64
# endif
# if SIZEOF_INT == 8
# define PRIu64 "u"
# elif SIZEOF_LONG == 8
# define PRIu64 "lu"
# elif SIZEOF_LONG_LONG == 8
# define PRIu64 "llu"
# else
# error "unable to find a suitable PRIu64"
# endif
#endif
/* used in build information */
enum {
Good,

View file

@ -1,4 +1,4 @@
/* $NetBSD: info.h,v 1.9 2005/11/05 13:20:09 wiz Exp $ */
/* $NetBSD: info.h,v 1.10 2006/04/24 13:52:04 dillo Exp $ */
/* from FreeBSD Id: info.h,v 1.10 1997/02/22 16:09:40 peter Exp */
@ -52,6 +52,7 @@
#define SHOW_ALL_SIZE 0x10000
#define SHOW_BLD_DEPENDS 0x20000
#define SHOW_BI_VAR 0x40000
#define SHOW_SUMMARY 0x80000
enum which {
WHICH_ALL,
@ -78,5 +79,6 @@ extern void show_files(char *, package_t *);
extern void show_depends(char *, package_t *);
extern void show_bld_depends(char *, package_t *);
extern void show_index(char *, char *, char *);
extern void show_summary(package_t *, const char *);
#endif /* _INST_INFO_H_INCLUDE */

View file

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.14 2005/11/05 13:20:09 wiz Exp $ */
/* $NetBSD: main.c,v 1.15 2006/04/24 13:52:04 dillo Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -11,7 +11,7 @@
#if 0
static char *rcsid = "from FreeBSD Id: main.c,v 1.14 1997/10/08 07:47:26 charnier Exp";
#else
__RCSID("$NetBSD: main.c,v 1.14 2005/11/05 13:20:09 wiz Exp $");
__RCSID("$NetBSD: main.c,v 1.15 2006/04/24 13:52:04 dillo Exp $");
#endif
#endif
@ -50,7 +50,7 @@ __RCSID("$NetBSD: main.c,v 1.14 2005/11/05 13:20:09 wiz Exp $");
#include "lib.h"
#include "info.h"
static const char Options[] = ".aBbcDde:fFhIiK:kLl:mNnpQ:qRrsSuvV";
static const char Options[] = ".aBbcDde:fFhIiK:kLl:mNnpQ:qRrsSuvVX";
int Flags = 0;
enum which Which = WHICH_LIST;
@ -68,7 +68,7 @@ static void
usage(void)
{
fprintf(stderr, "%s\n%s\n%s\n%s\n",
"usage: pkg_info [-BbcDdFfhIikLmNnpqRrSsVv] [-e package] [-K pkg_dbdir] [-l prefix]",
"usage: pkg_info [-BbcDdFfhIikLmNnpqRrSsVvX] [-e package] [-K pkg_dbdir] [-l prefix]",
" pkg-name [...]",
" pkg_info [-a | -u] [flags]",
" pkg_info -Q variable pkg-name [pkg-name ...]");
@ -205,6 +205,10 @@ main(int argc, char **argv)
show_version();
/* NOTREACHED */
case 'X':
Flags |= SHOW_SUMMARY;
break;
case 'h':
case '?':
default:

View file

@ -1,4 +1,4 @@
/* $NetBSD: perform.c,v 1.27 2006/04/04 06:28:22 wiz Exp $ */
/* $NetBSD: perform.c,v 1.28 2006/04/24 13:52:05 dillo Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -14,7 +14,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.23 1997/10/13 15:03:53 jkh Exp";
#else
__RCSID("$NetBSD: perform.c,v 1.27 2006/04/04 06:28:22 wiz Exp $");
__RCSID("$NetBSD: perform.c,v 1.28 2006/04/24 13:52:05 dillo Exp $");
#endif
#endif
@ -76,6 +76,7 @@ pkg_do(char *pkg)
int code = 0;
lfile_t *lfp;
int result;
char *binpkgfile = NULL;
if (IS_URL(pkg)) {
if ((cp = fileGetURL(pkg)) != NULL) {
@ -96,6 +97,7 @@ pkg_do(char *pkg)
strlcpy(fname, pkg, sizeof(fname));
}
cp = fname;
binpkgfile = fname;
}
if (cp) {
@ -109,6 +111,8 @@ pkg_do(char *pkg)
*/
char *cp2;
binpkgfile = NULL;
if ((cp2 = fileGetURL(cp)) != NULL) {
strlcpy(fname, cp2, sizeof(fname));
isTMP = TRUE;
@ -131,9 +135,9 @@ pkg_do(char *pkg)
LFILE_ADD(&files, lfp, MTREE_FNAME);
if (Flags & SHOW_BUILD_VERSION)
LFILE_ADD(&files, lfp, BUILD_VERSION_FNAME);
if (Flags & SHOW_BUILD_INFO)
if (Flags & (SHOW_BUILD_INFO|SHOW_SUMMARY))
LFILE_ADD(&files, lfp, BUILD_INFO_FNAME);
if (Flags & SHOW_PKG_SIZE)
if (Flags & (SHOW_PKG_SIZE|SHOW_SUMMARY))
LFILE_ADD(&files, lfp, SIZE_PKG_FNAME);
if (Flags & SHOW_ALL_SIZE)
LFILE_ADD(&files, lfp, SIZE_ALL_FNAME);
@ -232,12 +236,15 @@ pkg_do(char *pkg)
fclose(fp);
/* Start showing the package contents */
if (!Quiet) {
if (!Quiet && !(Flags & SHOW_SUMMARY)) {
printf("%sInformation for %s:\n\n", InfoPrefix, pkg);
if (fexists(PRESERVE_FNAME)) {
printf("*** PACKAGE MAY NOT BE DELETED ***\n");
}
}
if (Flags & SHOW_SUMMARY) {
show_summary(&plist, binpkgfile);
}
if (Flags & SHOW_COMMENT) {
show_file(pkg, "Comment:\n", COMMENT_FNAME, TRUE);
}
@ -305,7 +312,7 @@ pkg_do(char *pkg)
show_file(pkg, "Size in bytes including required pkgs: ",
SIZE_ALL_FNAME, TRUE);
}
if (!Quiet) {
if (!Quiet && !(Flags & SHOW_SUMMARY)) {
if (fexists(PRESERVE_FNAME)) {
printf("*** PACKAGE MAY NOT BE DELETED ***\n\n");
}

View file

@ -1,4 +1,4 @@
.\" $NetBSD: pkg_info.1,v 1.17 2005/11/05 13:20:09 wiz Exp $
.\" $NetBSD: pkg_info.1,v 1.18 2006/04/24 13:52:05 dillo Exp $
.\"
.\" FreeBSD install - a package for the installation and maintenance
.\" of non-core utilities.
@ -17,7 +17,7 @@
.\"
.\" @(#)pkg_info.1
.\"
.Dd November 1, 2005
.Dd April 15, 2006
.Dt PKG_INFO 1
.Os
.Sh NAME
@ -25,7 +25,7 @@
.Nd a utility for displaying information on software packages
.Sh SYNOPSIS
.Nm
.Op Fl BbcDdFfhIikLmNnpqRrSsVv
.Op Fl BbcDdFfhIikLmNnpqRrSsVvX
.Op Fl e Ar package
.Op Fl K Ar pkg_dbdir
.Op Fl l Ar prefix
@ -179,6 +179,13 @@ See also
Print version number and exit.
.It Fl v
Turn on verbose output.
.It Fl X
Print summary information for each package.
The summary format is
described in
.Xr pkg_summary 5 .
Its primary use is to contain all information about the contents of a
(remote) binary package repository needed by package managing software.
.El
.Sh TECHNICAL DETAILS
Package info is either extracted from package files named on the

View file

@ -4,7 +4,7 @@ NNAAMMEE
ppkkgg__iinnffoo -- a utility for displaying information on software packages
SSYYNNOOPPSSIISS
ppkkgg__iinnffoo [--BBbbccDDddFFffhhIIiikkLLmmNNnnppqqRRrrSSssVVvv] [--ee _p_a_c_k_a_g_e] [--KK _p_k_g___d_b_d_i_r]
ppkkgg__iinnffoo [--BBbbccDDddFFffhhIIiikkLLmmNNnnppqqRRrrSSssVVvvXX] [--ee _p_a_c_k_a_g_e] [--KK _p_k_g___d_b_d_i_r]
[--ll _p_r_e_f_i_x] _p_k_g_-_n_a_m_e _._._.
ppkkgg__iinnffoo [--aa | --uu] [flags]
ppkkgg__iinnffoo [--QQ _v_a_r_i_a_b_l_e] _p_k_g_-_n_a_m_e _._._.
@ -115,6 +115,11 @@ DDEESSCCRRIIPPTTIIOONN
--vv Turn on verbose output.
--XX Print summary information for each package. The summary format
is described in pkg_summary(5). Its primary use is to contain
all information about the contents of a (remote) binary package
repository needed by package managing software.
TTEECCHHNNIICCAALL DDEETTAAIILLSS
Package info is either extracted from package files named on the command
line, or from already installed package information in
@ -192,4 +197,4 @@ AAUUTTHHOORRSS
NetBSD wildcard dependency processing, pkgdb, depends displaying,
pkg size display etc.
NetBSD 3.0 November 1, 2005 NetBSD 3.0
NetBSD 3.0 April 15, 2006 NetBSD 3.0

View file

@ -1,4 +1,4 @@
/* $NetBSD: show.c,v 1.9 2005/11/05 13:20:09 wiz Exp $ */
/* $NetBSD: show.c,v 1.10 2006/04/24 13:52:05 dillo Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@ -11,7 +11,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: show.c,v 1.11 1997/10/08 07:47:38 charnier Exp";
#else
__RCSID("$NetBSD: show.c,v 1.9 2005/11/05 13:20:09 wiz Exp $");
__RCSID("$NetBSD: show.c,v 1.10 2006/04/24 13:52:05 dillo Exp $");
#endif
#endif
@ -106,6 +106,8 @@ static const show_t showv[] = {
{-1, NULL, NULL}
};
static int print_file_as_var(const char *, const char *);
void
show_file(char *pkg, char *title, char *fname, Boolean separator)
{
@ -341,3 +343,87 @@ show_bld_depends(char *title, package_t *plist)
printf("\n");
}
/*
* Show entry for pkg_summary.txt file.
*/
void
show_summary(package_t *plist, const char *binpkgfile)
{
static const char *bi_vars[] = {
"PKGPATH",
"CATEGORIES",
"PROVIDES",
"REQUIRES",
"PKG_OPTIONS",
"OPSYS",
"OS_VERSION",
"MACHINE_ARCH",
"LICENSE",
"HOMEPAGE",
"PKGTOOLS_VERSION",
"BUILD_DATE",
NULL
};
plist_t *p;
struct stat st;
for (p = plist->head; p; p = p->next) {
switch (p->type) {
case PLIST_NAME:
printf("PKGNAME=%s\n", p->name);
break;
case PLIST_PKGDEP:
printf("DEPENDS=%s\n", p->name);
break;
case PLIST_PKGCFL:
printf("CONFLICTS=%s\n", p->name);
break;
default:
break;
}
}
print_file_as_var("COMMENT", COMMENT_FNAME);
print_file_as_var("SIZE_PKG", SIZE_PKG_FNAME);
var_copy_list(BUILD_INFO_FNAME, bi_vars);
if (binpkgfile != NULL && stat(binpkgfile, &st) == 0) {
printf("FILE_SIZE=%" PRIu64 "\n", (uint64_t)st.st_size);
/* XXX: DIGETS */
}
print_file_as_var("DESCRIPTION", DESC_FNAME);
putc('\n', stdout);
}
/*
* Print the contents of file fname as value of variable var to stdout.
*/
static int
print_file_as_var(const char *var, const char *fname)
{
FILE *fp;
char *line;
size_t len;
fp = fopen(fname, "r");
if (!fp) {
warn("unable to open %s file", fname);
return -1;
}
while ((line = fgetln(fp, &len)) != (char *) NULL) {
if (line[len - 1] == '\n')
--len;
printf("%s=%.*s\n", var, (int)len, line);
}
fclose(fp);
return 0;
}

View file

@ -1,8 +1,12 @@
# $NetBSD: Makefile.in,v 1.11 2005/11/22 15:44:59 ben Exp $
# $NetBSD: Makefile.in,v 1.12 2006/04/24 13:52:05 dillo Exp $
srcdir= @srcdir@
pkgdbdir= @pkgdbdir@
mandir= @mandir@
man5dir= $(mandir)/man5
cat5dir= $(mandir)/cat5
tar= @tar@
ftp= @ftp@
@ -32,4 +36,7 @@ clean:
rm -f $(OBJS) $(LIB)
install:
@true # do nothing
$(INSTALL) -m 755 -d $(man5dir)
$(INSTALL) -m 755 -d $(cat5dir)
$(INSTALL) -m 444 pkg_summary.5 $(man5dir)/pkg_summary.5
$(INSTALL) -m 444 pkg_summary.cat5 $(cat5dir)/pkg_summary.0

View file

@ -1,4 +1,4 @@
/* $NetBSD: defs.h,v 1.4 2003/09/23 07:13:52 grant Exp $ */
/* $NetBSD: defs.h,v 1.5 2006/04/24 13:52:05 dillo Exp $ */
/*
* Copyright (c) 1999-2000 Alistair G. Crooks. All rights reserved.
@ -96,4 +96,24 @@
to[(size) - 1] = 0; \
} while( /* CONSTCOND */ 0)
/*
* Some systems such as OpenBSD-3.6 do not provide PRIu64.
* Others such as AIX-4.3.2 have a broken PRIu64 which includes
* a leading "%".
*/
#ifdef NEED_PRI_MACRO
# ifdef PRIu64
# undef PRIu64
# endif
# if SIZEOF_INT == 8
# define PRIu64 "u"
# elif SIZEOF_LONG == 8
# define PRIu64 "lu"
# elif SIZEOF_LONG_LONG == 8
# define PRIu64 "llu"
# else
# error "unable to find a suitable PRIu64"
# endif
#endif
#endif /* !DEFS_H_ */

View file

@ -1,4 +1,4 @@
/* $NetBSD: lib.h,v 1.23 2006/04/06 06:49:30 reed Exp $ */
/* $NetBSD: lib.h,v 1.24 2006/04/24 13:52:05 dillo Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@ -322,6 +322,7 @@ int pipe_to_system_end(pipe_to_system_t *);
char *var_get(const char *, const char *);
int var_set(const char *, const char *, const char *);
int var_copy_list(const char *, const char **);
/* automatically installed as dependency */

View file

@ -0,0 +1,102 @@
.\" $NetBSD: pkg_summary.5,v 1.1 2006/04/24 13:52:05 dillo Exp $
.\"
.\" Copyright (c) 2006 The NetBSD Foundation
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived from
.\" this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION AND ITS CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
.\" NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
.\" FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
.\" SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd April 24, 2006
.Dt PKG_SUMMARY 5
.Os
.Sh NAME
.Nm pkg_summary
.Nd summary of binary package repository
.Sh DESCRIPTION
The file
.Nm
contains information about each package in a binary package
repository as a list of variable-value pairs.
The variables describing different packages are separated by one empty
line.
Each line has the format
.Ev VARIABLE=VALUE .
If the value consists of more than one line, each line is prefixed with
.Ev VARIABLE= .
Multi-line variables are guaranteed to be in consecutive lines.
.Pp
The following variables are used:
.Bl -tag -width indent
.It Ev BUILD_DATE
(required) The date and time when the package was built.
.It Ev CATEGORIES
(required) A list of categories which this package fits in, separated by
space.
.It Ev COMMENT
(required) A one-line description of the package.
.It Ev CONFLICTS
(optional) A list of dewey patterns of packages the package conflicts
with, one per line.
If missing, this package has no conflicts.
.It Ev DEPENDS
(optional) A list of dewey patterns of packages the package depends
on, one per line.
If missing, this package has no dependencies.
.It Ev DESCRIPTION
(required) A more detailed description of the package.
.\" DIGEST
.It Ev FILE_SIZE
(optional) The size of the binary package file, in bytes.
.It Ev HOMEPAGE
(required) A URL where more information about the package can be found.
.It Ev LICENSE
(optional) The type of license this package is distributed under.
If empty or missing, it is OSI-approved.
.It Ev MACHINE_ARCH
(required) The architecture on which the package was compiled.
.It Ev OPSYS
(required) The operating system on which the package was compiled.
.It Ev OS_VERSION
(required) The version of the operating system on which the package
was compiled.
.It Ev PKG_OPTIONS
(optional) Any options selected to compile this package.
If missing, the package does not support options.
.It Ev PKGTOOLS_VERSION
(required) The version of the package tools used to create the package.
.It Ev PKGNAME
(required) The name of the package.
.It Ev PKGPATH
(required) The path of the package directory within pkgsrc.
.It Ev PROVIDES
(optional) A list of shared libraries provided by the package,
including major version number, one per line.
If missing, this package does not provide shared libraries.
.It Ev REQUIRES
(optional) A list of shared libraries needed by the package, including
major version number, one per line.
If missing, this package does not require shared libraries.
.It Ev SIZE_PKG
(required) The size of the package when installed, in bytes.
.El

View file

@ -0,0 +1,82 @@
PKG_SUMMARY(5) NetBSD File Formats Manual PKG_SUMMARY(5)
NNAAMMEE
ppkkgg__ssuummmmaarryy -- summary of binary package repository
DDEESSCCRRIIPPTTIIOONN
The file ppkkgg__ssuummmmaarryy contains information about each package in the
binary package repository as a list of variable-value pairs. The vari-
ables describing different packages are separated by one empty line.
Each line has the format VARIABLE=VALUE. If the value consits of more
than one line, each line is prefixed with VARIABLE=. Multi-line variables
are guaranteed to be contained in consecutive lines.
The following variables are used:
CATEGORIES
(required) A list of categories this package belongs in, sepa-
rated by space.
COMMENT
(required) A one-line comment describing the package.
CONFLICTS
(optional) A list of dewey patterns of packages the package con-
flicts with, one per line. If missing, this package has no con-
flicts.
DEPENDS
(optional) A list of dewey patterns of packages the package
depends on, one per line. If missing, this package has no depen-
dencies.
DESCRIPTION
(required) A more detailed description of the package.
FILE_SIZE
(optional) The size of the binary package file, in bytes.
HOMEPAGE
(mandtory) The URL of the package's original home page.
LICENSE
(optional) The type of license this package is distributed under.
If empty or missing, it is OSI-approved.
MACHINE_ARCH
(required) The architecture the package was compiled for.
OPSYS (required) The operating system the package was compiled for.
OS_VERSION
(required) The version of the operating system the package was
compiled for.
PKG_OPTIONS
(optional) Any options selected to compile this package. If
missing, the package does not support options.
PKGTOOLS_VERSION
(required) The version of the package tools used to create the
package.
PKGNAME
(required) The name of the package.
PKGPATH
(required) The path of the package directory within pkgsrc.
PROVIDES
(optional) A list of shared libraries provided by the package,
including major version, one per line. If missing, this package
provides no shared libraries.
REQUIRES
(optional) A list of shared libraries needed by the package,
including major version, one per line. If missing, this package
requires no shared libraries.
SIZE_PKG
(required) The size of the installed package.
NetBSD 3.0 April 15, 2006 NetBSD 3.0

View file

@ -1,4 +1,4 @@
/* $NetBSD: var.c,v 1.3 2006/04/04 06:37:15 wiz Exp $ */
/* $NetBSD: var.c,v 1.4 2006/04/24 13:52:05 dillo Exp $ */
/*-
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@ -40,7 +40,7 @@
#include <sys/cdefs.h>
#endif
#ifndef lint
__RCSID("$NetBSD: var.c,v 1.3 2006/04/04 06:37:15 wiz Exp $");
__RCSID("$NetBSD: var.c,v 1.4 2006/04/24 13:52:05 dillo Exp $");
#endif
#if HAVE_SYS_STAT_H
@ -61,6 +61,44 @@ __RCSID("$NetBSD: var.c,v 1.3 2006/04/04 06:37:15 wiz Exp $");
static const char *var_cmp(const char *, size_t, const char *, size_t);
static void var_print(FILE *, const char *, const char *);
/*
* Copy the specified varibales from the file fname to stdout.
*/
int
var_copy_list(const char *fname, const char **variables)
{
FILE *fp;
char *line;
size_t len;
const char *p;
int i;
fp = fopen(fname, "r");
if (!fp) {
if (errno != ENOENT)
warn("var_copy_list: can't open '%s' for reading",
fname);
return -1;
}
while ((line = fgetln(fp, &len)) != (char *) NULL) {
if (line[len - 1] == '\n')
--len;
for (i=0; variables[i]; i++) {
if ((p=var_cmp(line, len, variables[i],
strlen(variables[i]))) != NULL) {
printf("%.*s\n", (int)len, line);
break;
}
}
}
(void) fclose(fp);
return 0;
}
/*
* Print the value of variable from the file fname to stdout.
*/
char *
var_get(const char *fname, const char *variable)
{
@ -108,6 +146,10 @@ var_get(const char *fname, const char *variable)
return value;
}
/*
* Add given variable with given value to file, overwriting any
* previous occurrence.
*/
int
var_set(const char *fname, const char *variable, const char *value)
{
@ -213,6 +255,9 @@ var_set(const char *fname, const char *variable, const char *value)
return 0;
}
/*
* Check if line contains variable var, return pointer to its value or NULL.
*/
static const char *
var_cmp(const char *line, size_t linelen, const char *var, size_t varlen)
{
@ -240,6 +285,9 @@ var_cmp(const char *line, size_t linelen, const char *var, size_t varlen)
return line;
}
/*
* Print given variable with value to file f.
*/
static void
var_print(FILE *f, const char *variable, const char *value)
{

View file

@ -1,4 +1,4 @@
/* $NetBSD: version.h,v 1.58 2006/04/18 20:41:45 hubertf Exp $ */
/* $NetBSD: version.h,v 1.59 2006/04/24 13:52:05 dillo Exp $ */
/*
* Copyright (c) 2001 Thomas Klausner. All rights reserved.
@ -33,6 +33,6 @@
#ifndef _INST_LIB_VERSION_H_
#define _INST_LIB_VERSION_H_
#define PKGTOOLS_VERSION "20060418"
#define PKGTOOLS_VERSION "20060424"
#endif /* _INST_LIB_VERSION_H_ */