2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
17 * Various display routines for the info module.
19 * $FreeBSD: src/usr.sbin/pkg_install/info/show.c,v 1.37 2003/05/26 17:06:05 lioux Exp $
20 * $DragonFly: src/usr.sbin/pkg_install/info/Attic/show.c,v 1.3 2004/07/30 04:46:13 dillon Exp $
27 #include <sys/types.h>
32 show_file(const char *title
, const char *fname
)
39 printf("%s%s", InfoPrefix
, title
);
40 fp
= fopen(fname
, "r");
41 if (fp
== (FILE *) NULL
)
42 printf("ERROR: show_file: Can't open '%s' for reading!\n", fname
);
45 while ((n
= fread(line
, 1, 1024, fp
)) != 0)
46 fwrite(line
, 1, n
, stdout
);
48 append_nl
= (line
[n
- 1] != '\n'); /* Do we have a trailing \n ? */
52 printf("\n"); /* just in case */
56 show_index(const char *title
, const char *fname
)
59 char line
[MAXINDEXSIZE
+2];
61 strlcpy(line
, "???\n", sizeof(line
));
64 printf("%s%s", InfoPrefix
, title
);
65 fp
= fopen(fname
, "r");
66 if (fp
== (FILE *) NULL
) {
67 warnx("show_file: can't open '%s' for reading", fname
);
69 if(fgets(line
, MAXINDEXSIZE
+ 1, fp
)) {
70 size_t line_length
= strlen(line
);
72 if (line
[line_length
- 1] != '\n') { /* Do we have a trailing \n ? */
73 line
[line_length
] = '\n'; /* Add a trailing \n */
74 line
[line_length
+ 1] = '\0'; /* Terminate string */
82 /* Show a packing list item type. If showall is TRUE, show all */
84 show_plist(const char *title
, Package
*plist
, plist_t type
, Boolean showall
)
90 printf("%s%s", InfoPrefix
, title
);
93 if (p
->type
!= type
&& showall
!= TRUE
) {
100 printf(Quiet
? "%s\n" : "File: %s (ignored)\n", p
->name
);
104 printf(Quiet
? "%s\n" : "File: %s\n", p
->name
);
108 printf(Quiet
? "@cwd %s\n" : "\tCWD to %s\n", p
->name
);
112 printf(Quiet
? "@srcdir %s\n" : "\tSRCDIR to %s\n", p
->name
);
116 printf(Quiet
? "@exec %s\n" : "\tEXEC '%s'\n", p
->name
);
120 printf(Quiet
? "@unexec %s\n" : "\tUNEXEC '%s'\n", p
->name
);
124 printf(Quiet
? "@chmod %s\n" : "\tCHMOD to %s\n",
125 p
->name
? p
->name
: "(clear default)");
129 printf(Quiet
? "@chown %s\n" : "\tCHOWN to %s\n",
130 p
->name
? p
->name
: "(clear default)");
134 printf(Quiet
? "@chgrp %s\n" : "\tCHGRP to %s\n",
135 p
->name
? p
->name
: "(clear default)");
139 printf(Quiet
? "@comment %s\n" : "\tComment: %s\n", p
->name
);
146 case PLIST_IGNORE_INST
:
147 printf(Quiet
? "@ignore_inst ??? doesn't belong here.\n" :
148 "\tIgnore next file installation directive (doesn't belong)\n");
153 printf(Quiet
? "@name %s\n" : "\tPackage name: %s\n", p
->name
);
157 printf(Quiet
? "@display %s\n" : "\tInstall message file: %s\n", p
->name
);
161 printf(Quiet
? "@pkgdep %s\n" : "Dependency: %s\n", p
->name
);
164 case PLIST_DEPORIGIN
:
165 printf(Quiet
? "@comment DEPORIGIN:%s\n" :
166 "\tdependency origin: %s\n", p
->name
);
169 case PLIST_CONFLICTS
:
170 printf(Quiet
? "@conflicts %s\n" : "Conflicts: %s\n", p
->name
);
174 printf(Quiet
? "@mtree %s\n" : "\tPackage mtree file: %s\n", p
->name
);
178 printf(Quiet
? "@dirrm %s\n" : "\tDeinstall directory remove: %s\n", p
->name
);
182 printf(Quiet
? "@option %s\n" :
183 "\tOption \"%s\" controlling package installation behaviour\n",
188 printf(Quiet
? "@comment ORIGIN:%s\n" :
189 "\tPackage origin: %s\n", p
->name
);
194 errx(2, "%s: unknown command type %d (%s)",
195 __func__
, p
->type
, p
->name
);
202 /* Show all files in the packing list (except ignored ones) */
204 show_files(const char *title
, Package
*plist
)
208 const char *dir
= ".";
211 printf("%s%s", InfoPrefix
, title
);
217 printf("%s/%s\n", dir
, p
->name
);
229 /* Silence GCC in the -Wall mode */
237 /* Calculate and show size of all installed package files (except ignored ones) */
239 show_size(const char *title
, Package
*plist
)
243 const char *dir
= ".";
245 char tmp
[FILENAME_MAX
];
246 unsigned long size
= 0;
251 descr
= getbsize(&headerlen
, &blksize
);
253 printf("%s%s", InfoPrefix
, title
);
254 for (p
= plist
->head
; p
!= NULL
; p
= p
->next
) {
258 snprintf(tmp
, FILENAME_MAX
, "%s/%s", dir
, p
->name
);
259 if (!lstat(tmp
, &sb
)) {
262 printf("%lu\t%s\n", (unsigned long) howmany(sb
.st_size
, blksize
), tmp
);
276 /* Silence GCC in the -Wall mode */
282 printf("%lu\t(%s)\n", howmany(size
, blksize
), descr
);
285 printf("%lu\n", howmany(size
, blksize
));
287 printf("%lu\n", size
);
290 /* Show files that don't match the recorded checksum */
292 show_cksum(const char *title
, Package
*plist
)
295 const char *dir
= ".";
296 char tmp
[FILENAME_MAX
];
299 printf("%s%s", InfoPrefix
, title
);
301 for (p
= plist
->head
; p
!= NULL
; p
= p
->next
)
302 if (p
->type
== PLIST_CWD
)
304 else if (p
->type
== PLIST_FILE
) {
305 snprintf(tmp
, FILENAME_MAX
, "%s/%s", dir
, p
->name
);
307 warnx("%s doesn't exist\n", tmp
);
308 else if (p
->next
&& p
->next
->type
== PLIST_COMMENT
&&
309 (strncmp(p
->next
->name
, "MD5:", 4) == 0)) {
310 char *cp
= NULL
, buf
[33];
313 * For packing lists whose version is 1.1 or greater, the md5
314 * hash for a symlink is calculated on the string returned
317 if (issymlink(tmp
) && verscmp(plist
, 1, 0) > 0) {
319 char linkbuf
[FILENAME_MAX
];
321 if ((len
= readlink(tmp
, linkbuf
, FILENAME_MAX
)) > 0)
322 cp
= MD5Data((unsigned char *)linkbuf
, len
, buf
);
323 } else if (isfile(tmp
) || verscmp(plist
, 1, 1) < 0)
324 cp
= MD5File(tmp
, buf
);
328 if (strcmp(cp
, p
->next
->name
+ 4))
329 printf("%s fails the original MD5 checksum\n", tmp
);
331 printf("%s matched the original MD5 checksum\n", tmp
);
337 /* Show an "origin" path (usually category/portname) */
339 show_origin(const char *title
, Package
*plist
)
343 printf("%s%s", InfoPrefix
, title
);
344 printf("%s\n", plist
->origin
!= NULL
? plist
->origin
: "");
347 /* Show revision number of the packing list */
349 show_fmtrev(const char *title
, Package
*plist
)
353 printf("%s%s", InfoPrefix
, title
);
354 printf("%d.%d\n", plist
->fmtver_maj
, plist
->fmtver_mnr
);