Deleted Added
sdiff udiff text old ( 30531 ) new ( 49637 )
full compact
1#ifndef lint
2static const char rcsid[] =
3 "$Id: show.c,v 1.11 1997/10/08 07:47:38 charnier Exp $";
4#endif
5
6/*
7 * FreeBSD install - a package for the installation and maintainance
8 * of non-core utilities.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Jordan K. Hubbard
20 * 23 Aug 1993
21 *
22 * Various display routines for the info module.
23 *
24 */
25
26#include "lib.h"
27#include "info.h"
28
29void
30show_file(char *title, char *fname)
31{
32 FILE *fp;
33 char line[1024];
34 int n;
35
36 if (!Quiet)
37 printf("%s%s", InfoPrefix, title);
38 fp = fopen(fname, "r");
39 if (!fp)
40 printf("ERROR: show_file: Can't open '%s' for reading!\n", fname);
41 else {
42 while ((n = fread(line, 1, 1024, fp)) != 0)
43 fwrite(line, 1, n, stdout);
44 fclose(fp);
45 }
46 printf("\n"); /* just in case */
47}
48
49void
50show_index(char *title, char *fname)
51{
52 FILE *fp;
53 char line[MAXINDEXSIZE+2];
54
55 if (!Quiet)
56 printf("%s%s", InfoPrefix, title);
57 fp = fopen(fname, "r");
58 if (!fp) {
59 warnx("show_file: can't open '%s' for reading", fname);
60 return;
61 }
62 if(fgets(line, MAXINDEXSIZE+1, fp)) {
63 if(line[MAXINDEXSIZE-1] != '\n')
64 line[MAXINDEXSIZE] = '\n';
65 line[MAXINDEXSIZE+1] = 0;
66 fputs(line, stdout);
67 }
68 fclose(fp);
69}
70
71/* Show a packing list item type. If type is -1, show all */
72void
73show_plist(char *title, Package *plist, plist_t type)
74{
75 PackingList p;
76 Boolean ign = FALSE;
77
78 if (!Quiet)
79 printf("%s%s", InfoPrefix, title);
80 p = plist->head;
81 while (p) {
82 if (p->type != type && type != -1) {
83 p = p->next;
84 continue;
85 }
86 switch(p->type) {
87 case PLIST_FILE:
88 if (ign) {
89 printf(Quiet ? "%s\n" : "File: %s (ignored)\n", p->name);
90 ign = FALSE;
91 }
92 else
93 printf(Quiet ? "%s\n" : "File: %s\n", p->name);
94 break;
95
96 case PLIST_CWD:
97 printf(Quiet ? "@cwd %s\n" : "\tCWD to %s\n", p->name);
98 break;
99
100 case PLIST_SRC:
101 printf(Quiet ? "@srcdir %s\n" : "\tSRCDIR to %s\n", p->name);
102 break;
103
104 case PLIST_CMD:
105 printf(Quiet ? "@exec %s\n" : "\tEXEC '%s'\n", p->name);
106 break;
107
108 case PLIST_UNEXEC:
109 printf(Quiet ? "@unexec %s\n" : "\tUNEXEC '%s'\n", p->name);
110 break;
111
112 case PLIST_CHMOD:
113 printf(Quiet ? "@chmod %s\n" : "\tCHMOD to %s\n",
114 p->name ? p->name : "(clear default)");
115 break;
116
117 case PLIST_CHOWN:
118 printf(Quiet ? "@chown %s\n" : "\tCHOWN to %s\n",
119 p->name ? p->name : "(clear default)");
120 break;
121
122 case PLIST_CHGRP:
123 printf(Quiet ? "@chgrp %s\n" : "\tCHGRP to %s\n",
124 p->name ? p->name : "(clear default)");
125 break;
126
127 case PLIST_COMMENT:
128 printf(Quiet ? "@comment %s\n" : "\tComment: %s\n", p->name);
129 break;
130
131 case PLIST_IGNORE:
132 ign = TRUE;
133 break;
134
135 case PLIST_IGNORE_INST:
136 printf(Quiet ? "@ignore_inst ??? doesn't belong here.\n" :
137 "\tIgnore next file installation directive (doesn't belong)\n");
138 ign = TRUE;
139 break;
140
141 case PLIST_NAME:
142 printf(Quiet ? "@name %s\n" : "\tPackage name: %s\n", p->name);
143 break;
144
145 case PLIST_DISPLAY:
146 printf(Quiet ? "@display %s\n" : "\tInstall message file: %s\n", p->name);
147 break;
148
149 case PLIST_PKGDEP:
150 printf(Quiet ? "@pkgdep %s\n" : "\tPackage depends on: %s\n", p->name);
151 break;
152
153 case PLIST_MTREE:
154 printf(Quiet ? "@mtree %s\n" : "\tPackage mtree file: %s\n", p->name);
155 break;
156
157 case PLIST_DIR_RM:
158 printf(Quiet ? "@dirrm %s\n" : "\tDeinstall directory remove: %s\n", p->name);
159 break;
160
161 default:
162 cleanup(0);
163 errx(2, "unknown command type %d (%s)", p->type, p->name);
164 break;
165 }
166 p = p->next;
167 }
168}
169
170/* Show all files in the packing list (except ignored ones) */
171void
172show_files(char *title, Package *plist)
173{
174 PackingList p;
175 Boolean ign = FALSE;
176 char *dir = ".";
177
178 if (!Quiet)
179 printf("%s%s", InfoPrefix, title);
180 p = plist->head;
181 while (p) {
182 switch(p->type) {
183 case PLIST_FILE:
184 if (!ign)
185 printf("%s/%s\n", dir, p->name);
186 ign = FALSE;
187 break;
188
189 case PLIST_CWD:
190 dir = p->name;
191 break;
192
193 case PLIST_IGNORE:
194 ign = TRUE;
195 break;
196 }
197 p = p->next;
198 }
199}