1 /* $NetBSD: show.c,v 1.30 2009/08/02 17:56:45 joerg Exp $ */
10 __RCSID("$NetBSD: show.c,v 1.30 2009/08/02 17:56:45 joerg Exp $");
13 * FreeBSD install - a package for the installation and maintainance
14 * of non-core utilities.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
28 * Various display routines for the info module.
32 * Copyright (c) 1999-2008 The NetBSD Foundation, Inc.
33 * All rights reserved.
35 * This code is derived from software contributed to The NetBSD Foundation
36 * by Hubert Feyrer <hubert@feyrer.de>.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
47 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
48 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
49 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
50 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
51 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
53 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
54 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
55 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57 * POSSIBILITY OF SUCH DAMAGE.
68 /* Structure to define entries for the "show table" */
69 typedef struct show_t
{
70 pl_ent_t sh_type
; /* type of entry */
71 const char *sh_quiet
; /* message when quiet */
72 const char *sh_verbose
; /* message when verbose */
76 * The entries in this table must be ordered the same as
79 static const show_t showv
[] = {
80 {PLIST_FILE
, "%s", "\tFile: %s"},
81 {PLIST_CWD
, "@cwd %s", "\tCWD to: %s"},
82 {PLIST_CMD
, "@exec %s", "\tEXEC '%s'"},
83 {PLIST_CHMOD
, "@chmod %s", "\tCHMOD to %s"},
84 {PLIST_CHOWN
, "@chown %s", "\tCHOWN to %s"},
85 {PLIST_CHGRP
, "@chgrp %s", "\tCHGRP to %s"},
86 {PLIST_COMMENT
, "@comment %s", "\tComment: %s"},
87 {PLIST_IGNORE
, "@ignore", "Ignore next file:"},
88 {PLIST_NAME
, "@name %s", "\tPackage name: %s"},
89 {PLIST_UNEXEC
, "@unexec %s", "\tUNEXEC '%s'"},
90 {PLIST_SRC
, "@src: %s", "\tSRC to: %s"},
91 {PLIST_DISPLAY
, "@display %s", "\tInstall message file: %s"},
92 {PLIST_PKGDEP
, "@pkgdep %s", "\tPackage depends on: %s"},
93 {PLIST_DIR_RM
, "@dirrm %s", "\tObsolete deinstall directory removal hint: %s"},
94 {PLIST_OPTION
, "@option %s", "\tPackage has option: %s"},
95 {PLIST_PKGCFL
, "@pkgcfl %s", "\tPackage conflicts with: %s"},
96 {PLIST_BLDDEP
, "@blddep %s", "\tPackage depends exactly on: %s"},
97 {PLIST_PKGDIR
, "@pkgdir %s", "\tManaged directory: %s"},
101 static int print_string_as_var(const char *, const char *);
104 show_file(const char *buf
, const char *title
, Boolean separator
)
109 printf("%s%s", InfoPrefix
, title
);
112 if (len
== 0 || buf
[len
- 1] != '\n')
117 if (!Quiet
|| separator
)
122 show_var(const char *buf
, const char *variable
)
129 if ((value
= var_get_memory(buf
, variable
)) != NULL
) {
130 (void) printf("%s\n", value
);
136 show_index(const char *buf
, const char *title
)
141 printf("%s%s", InfoPrefix
, title
);
144 if (len
== 0 || buf
[len
- 1] != '\n')
151 * Show a packing list item type. If type is PLIST_SHOW_ALL, show all
154 show_plist(const char *title
, package_t
*plist
, pl_ent_t type
)
160 printf("%s%s", InfoPrefix
, title
);
162 for (ign
= FALSE
, p
= plist
->head
; p
; p
= p
->next
) {
163 if (p
->type
== type
|| type
== PLIST_SHOW_ALL
) {
166 printf(Quiet
? showv
[p
->type
].sh_quiet
: showv
[p
->type
].sh_verbose
, p
->name
);
169 printf(" (ignored)");
177 printf(Quiet
? showv
[p
->type
].sh_quiet
: showv
[p
->type
].sh_verbose
,
178 p
->name
? p
->name
: "(clear default)");
181 printf(Quiet
? showv
[p
->type
].sh_quiet
: showv
[p
->type
].sh_verbose
);
197 printf(Quiet
? showv
[p
->type
].sh_quiet
: showv
[p
->type
].sh_verbose
, p
->name
);
200 warnx("unknown command type %d (%s)", p
->type
, p
->name
);
202 (void) fputc('\n', stdout
);
208 * Show all files in the packing list (except ignored ones)
211 show_files(const char *title
, package_t
*plist
)
215 const char *dir
= ".";
218 printf("%s%s", InfoPrefix
, title
);
220 for (ign
= FALSE
, p
= plist
->head
; p
; p
= p
->next
) {
224 printf("%s%s%s\n", dir
,
225 (strcmp(dir
, "/") == 0) ? "" : "/", p
->name
);
242 * Show dependencies (packages this pkg requires)
245 show_depends(const char *title
, package_t
*plist
)
251 for (p
= plist
->head
; p
&& nodepends
; p
= p
->next
) {
264 printf("%s%s", InfoPrefix
, title
);
266 for (p
= plist
->head
; p
; p
= p
->next
) {
269 printf("%s\n", p
->name
);
280 * Show exact dependencies (packages this pkg was built with)
283 show_bld_depends(const char *title
, package_t
*plist
)
289 for (p
= plist
->head
; p
&& nodepends
; p
= p
->next
) {
302 printf("%s%s", InfoPrefix
, title
);
304 for (p
= plist
->head
; p
; p
= p
->next
) {
307 printf("%s\n", p
->name
);
319 * Show entry for pkg_summary.txt file.
322 show_summary(struct pkg_meta
*meta
, package_t
*plist
, const char *binpkgfile
)
324 static const char *bi_vars
[] = {
345 for (p
= plist
->head
; p
; p
= p
->next
) {
348 printf("PKGNAME=%s\n", p
->name
);
351 printf("DEPENDS=%s\n", p
->name
);
354 printf("CONFLICTS=%s\n", p
->name
);
362 print_string_as_var("COMMENT", meta
->meta_comment
);
363 print_string_as_var("SIZE_PKG", meta
->meta_size_pkg
);
365 if (meta
->meta_build_info
)
366 var_copy_list(meta
->meta_build_info
, bi_vars
);
368 warnx("Build information missing");
370 if (binpkgfile
!= NULL
&& stat(binpkgfile
, &st
) == 0) {
373 base
= strrchr(binpkgfile
, '/');
378 printf("FILE_NAME=%s\n", base
);
379 printf("FILE_SIZE=%" MY_PRIu64
"\n", (uint64_t)st
.st_size
);
383 print_string_as_var("DESCRIPTION", meta
->meta_desc
);
388 * Print the contents of file fname as value of variable var to stdout.
391 print_string_as_var(const char *var
, const char *str
)
395 while ((eol
= strchr(str
, '\n')) != NULL
) {
396 printf("%s=%.*s\n", var
, (int)(eol
- str
), str
);
400 printf("%s=%s\n", var
, str
);
406 show_list(lpkg_head_t
*pkghead
, const char *title
)
411 printf("%s%s", InfoPrefix
, title
);
413 while ((lpp
= TAILQ_FIRST(pkghead
)) != NULL
) {
414 TAILQ_REMOVE(pkghead
, lpp
, lp_link
);