1 /* $NetBSD: show.c,v 1.3 2012/02/21 18:36:16 wiz Exp $ */
10 __RCSID("$NetBSD: show.c,v 1.3 2012/02/21 18:36:16 wiz 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
, "", "\tFile: "},
81 {PLIST_CWD
, "@cwd ", "\tCWD to: "},
82 {PLIST_CMD
, "@exec ", "\tEXEC ''"},
83 {PLIST_CHMOD
, "@chmod ", "\tCHMOD to "},
84 {PLIST_CHOWN
, "@chown ", "\tCHOWN to "},
85 {PLIST_CHGRP
, "@chgrp ", "\tCHGRP to "},
86 {PLIST_COMMENT
, "@comment ", "\tComment: "},
87 {PLIST_IGNORE
, "@ignore", "Ignore next file:"},
88 {PLIST_NAME
, "@name ", "\tPackage name: "},
89 {PLIST_UNEXEC
, "@unexec ", "\tUNEXEC ''"},
90 {PLIST_SRC
, "@src: ", "\tSRC to: "},
91 {PLIST_DISPLAY
, "@display ", "\tInstall message file: "},
92 {PLIST_PKGDEP
, "@pkgdep ", "\tPackage depends on: "},
93 {PLIST_DIR_RM
, "@dirrm ", "\tObsolete deinstall directory removal hint: "},
94 {PLIST_OPTION
, "@option ", "\tPackage has option: "},
95 {PLIST_PKGCFL
, "@pkgcfl ", "\tPackage conflicts with: "},
96 {PLIST_BLDDEP
, "@blddep ", "\tPackage depends exactly on: "},
97 {PLIST_PKGDIR
, "@pkgdir ", "\tManaged directory: "},
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
) {
167 Quiet
? showv
[p
->type
].sh_quiet
:
168 showv
[p
->type
].sh_verbose
, p
->name
);
171 printf(" (ignored)");
180 Quiet
? showv
[p
->type
].sh_quiet
:
181 showv
[p
->type
].sh_verbose
,
182 p
->name
? p
->name
: "(clear default)");
185 printf("%s", Quiet
? showv
[p
->type
].sh_quiet
:
186 showv
[p
->type
].sh_verbose
);
203 Quiet
? showv
[p
->type
].sh_quiet
:
204 showv
[p
->type
].sh_verbose
,
205 p
->name
? p
->name
: "(null)");
208 warnx("unknown command type %d (%s)", p
->type
, p
->name
);
210 (void) fputc('\n', stdout
);
216 * Show all files in the packing list (except ignored ones)
219 show_files(const char *title
, package_t
*plist
)
223 const char *dir
= ".";
226 printf("%s%s", InfoPrefix
, title
);
228 for (ign
= FALSE
, p
= plist
->head
; p
; p
= p
->next
) {
232 printf("%s%s%s\n", dir
,
233 (strcmp(dir
, "/") == 0) ? "" : "/", p
->name
);
250 * Show dependencies (packages this pkg requires)
253 show_depends(const char *title
, package_t
*plist
)
259 for (p
= plist
->head
; p
&& nodepends
; p
= p
->next
) {
272 printf("%s%s", InfoPrefix
, title
);
274 for (p
= plist
->head
; p
; p
= p
->next
) {
277 printf("%s\n", p
->name
);
288 * Show exact dependencies (packages this pkg was built with)
291 show_bld_depends(const char *title
, package_t
*plist
)
297 for (p
= plist
->head
; p
&& nodepends
; p
= p
->next
) {
310 printf("%s%s", InfoPrefix
, title
);
312 for (p
= plist
->head
; p
; p
= p
->next
) {
315 printf("%s\n", p
->name
);
327 * Show entry for pkg_summary.txt file.
330 show_summary(struct pkg_meta
*meta
, package_t
*plist
, const char *binpkgfile
)
332 static const char *bi_vars
[] = {
353 for (p
= plist
->head
; p
; p
= p
->next
) {
356 printf("PKGNAME=%s\n", p
->name
);
359 printf("DEPENDS=%s\n", p
->name
);
362 printf("CONFLICTS=%s\n", p
->name
);
370 print_string_as_var("COMMENT", meta
->meta_comment
);
371 if (meta
->meta_size_pkg
)
372 print_string_as_var("SIZE_PKG", meta
->meta_size_pkg
);
374 if (meta
->meta_build_info
)
375 var_copy_list(meta
->meta_build_info
, bi_vars
);
377 warnx("Build information missing");
379 if (binpkgfile
!= NULL
&& stat(binpkgfile
, &st
) == 0) {
382 base
= strrchr(binpkgfile
, '/');
387 printf("FILE_NAME=%s\n", base
);
388 printf("FILE_SIZE=%" MY_PRIu64
"\n", (uint64_t)st
.st_size
);
392 print_string_as_var("DESCRIPTION", meta
->meta_desc
);
397 * Print the contents of file fname as value of variable var to stdout.
400 print_string_as_var(const char *var
, const char *str
)
404 while ((eol
= strchr(str
, '\n')) != NULL
) {
405 printf("%s=%.*s\n", var
, (int)(eol
- str
), str
);
409 printf("%s=%s\n", var
, str
);
415 show_list(lpkg_head_t
*pkghead
, const char *title
)
420 printf("%s%s", InfoPrefix
, title
);
422 while ((lpp
= TAILQ_FIRST(pkghead
)) != NULL
) {
423 TAILQ_REMOVE(pkghead
, lpp
, lp_link
);