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