| 333 |
dpurdie |
1 |
/* $XConsortium: pr.c /main/18 1995/12/08 18:26:47 gildea $ */
|
|
|
2 |
/*
|
|
|
3 |
|
|
|
4 |
Copyright (c) 1993, 1994 X Consortium
|
|
|
5 |
|
|
|
6 |
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
7 |
of this software and associated documentation files (the "Software"), to deal
|
|
|
8 |
in the Software without restriction, including without limitation the rights
|
|
|
9 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
10 |
copies of the Software, and to permit persons to whom the Software is
|
|
|
11 |
furnished to do so, subject to the following conditions:
|
|
|
12 |
|
|
|
13 |
The above copyright notice and this permission notice shall be included in
|
|
|
14 |
all copies or substantial portions of the Software.
|
|
|
15 |
|
|
|
16 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
17 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
18 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
19 |
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
20 |
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
21 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
22 |
|
|
|
23 |
Except as contained in this notice, the name of the X Consortium shall not be
|
|
|
24 |
used in advertising or otherwise to promote the sale, use or other dealings
|
|
|
25 |
in this Software without prior written authorization from the X Consortium.
|
|
|
26 |
|
|
|
27 |
$Source: /cvsroot/device/DEVL/UTILS/MKDEPEND/pr.c,v $
|
|
|
28 |
$Revision: 1.4 $ $Date: 2004/11/03 05:09:12 $ $State: Exp $
|
|
|
29 |
$Author: ayoung $ $Locker: $
|
|
|
30 |
|
|
|
31 |
*/
|
|
|
32 |
|
|
|
33 |
#include "def.h"
|
|
|
34 |
|
|
|
35 |
extern struct inclist inclist[ MAXFILES ],
|
|
|
36 |
*inclistp;
|
|
|
37 |
extern char **systemdirs;
|
|
|
38 |
extern char *objprefixs[ MAXPREFIXS ];
|
|
|
39 |
extern char *objsuffix;
|
|
|
40 |
extern int width;
|
|
|
41 |
extern boolean printed;
|
|
|
42 |
extern boolean verbose;
|
|
|
43 |
extern boolean opt_basename;
|
|
|
44 |
extern int embeddedwhite;
|
|
|
45 |
extern boolean show_where_not;
|
|
|
46 |
|
|
|
47 |
void
|
|
|
48 |
add_include(filep, file, file_red, include, dot, failOK)
|
|
|
49 |
struct filepointer *filep;
|
|
|
50 |
struct inclist *file, *file_red;
|
|
|
51 |
char *include;
|
|
|
52 |
boolean dot;
|
|
|
53 |
{
|
|
|
54 |
register struct inclist *newfile;
|
|
|
55 |
register struct filepointer *content;
|
|
|
56 |
|
|
|
57 |
/*
|
|
|
58 |
* First decide what the pathname of this include file really is.
|
|
|
59 |
*/
|
|
|
60 |
#ifdef MSDOS
|
|
|
61 |
{
|
|
|
62 |
char *p = include;
|
|
|
63 |
do {
|
|
|
64 |
if ((p = strchr(p, '\\')) != NULL)
|
|
|
65 |
*p = '/';
|
|
|
66 |
} while (p && *p);
|
|
|
67 |
}
|
|
|
68 |
#endif
|
|
|
69 |
newfile = inc_path(file->i_file, include, dot);
|
|
|
70 |
if (newfile == NULL) {
|
|
|
71 |
if (failOK)
|
|
|
72 |
return;
|
|
|
73 |
if (file != file_red)
|
|
|
74 |
warning("%s (reading %s, line %d): ",
|
|
|
75 |
file_red->i_file, file->i_file, filep->f_line);
|
|
|
76 |
else
|
|
|
77 |
warning("%s, line %d: ", file->i_file, filep->f_line);
|
|
|
78 |
warning1("cannot find include file \"%s\"\n", include);
|
|
|
79 |
show_where_not = TRUE;
|
|
|
80 |
newfile = inc_path(file->i_file, include, dot);
|
|
|
81 |
show_where_not = FALSE;
|
|
|
82 |
if (mflags & MFLAG_GENERATED) {
|
|
|
83 |
warning1("assumed as generated \"%s\"\n", include);
|
|
|
84 |
newfile = newinclude(include, include);
|
|
|
85 |
newfile->i_flags |= SEARCHED;
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
if (newfile) {
|
|
|
90 |
included_by(file, newfile);
|
|
|
91 |
if (!(newfile->i_flags & SEARCHED)) {
|
|
|
92 |
newfile->i_flags |= SEARCHED;
|
|
|
93 |
content = getfile(newfile->i_file);
|
|
|
94 |
find_includes(content, newfile, file_red, 0, failOK);
|
|
|
95 |
freefile(content);
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
void
|
|
|
102 |
recursive_pr_include(head, file, base)
|
|
|
103 |
register struct inclist *head;
|
|
|
104 |
register char *file, *base;
|
|
|
105 |
{
|
|
|
106 |
register int i;
|
|
|
107 |
|
|
|
108 |
if (head->i_flags & MARKED)
|
|
|
109 |
return;
|
|
|
110 |
head->i_flags |= MARKED;
|
|
|
111 |
if (head->i_file != file)
|
|
|
112 |
pr(head, file, base);
|
|
|
113 |
for (i=0; i<head->i_listlen; i++)
|
|
|
114 |
recursive_pr_include(head->i_list[ i ], file, base);
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
static int
|
|
|
119 |
pr_space( const char *str, char *buf )
|
|
|
120 |
{
|
|
|
121 |
int len = 0;
|
|
|
122 |
|
|
|
123 |
if (embeddedwhite == BS_ESCAPE) {
|
|
|
124 |
const char *c; /* escape spaces */
|
|
|
125 |
char *b = buf;
|
|
|
126 |
|
|
|
127 |
for (c = str; *c; *c++) {
|
|
|
128 |
if (*c == ' ')
|
|
|
129 |
*b++ = '\\', len++;
|
|
|
130 |
*b++ = *c;
|
|
|
131 |
}
|
|
|
132 |
*b = '\0';
|
|
|
133 |
|
|
|
134 |
} else if (embeddedwhite == BS_QUOTE) {
|
|
|
135 |
sprintf(buf, "\"%s\"", str);
|
|
|
136 |
len = 2;
|
|
|
137 |
|
|
|
138 |
} else if (embeddedwhite == BS_URL) {
|
|
|
139 |
const char *c;
|
|
|
140 |
char *b = buf;
|
|
|
141 |
|
|
|
142 |
for (c = str; *c; *c++) {
|
|
|
143 |
if ( *c >= 127 ||
|
|
|
144 |
strchr( "$&+,;=?@ \"<>{}|^~[]`", *c ) )
|
|
|
145 |
{ /* convert */
|
|
|
146 |
*b++ = '%';
|
|
|
147 |
(void) sprintf( b, "%-2.2X", *c );
|
|
|
148 |
b += 2;
|
|
|
149 |
len += 2;
|
|
|
150 |
} else { /* quote */
|
|
|
151 |
*b++ = *c;
|
|
|
152 |
}
|
|
|
153 |
}
|
|
|
154 |
*b = '\0';
|
|
|
155 |
|
|
|
156 |
} else { /* unknown/ignore */
|
|
|
157 |
static int spacewarning;
|
|
|
158 |
|
|
|
159 |
if (embeddedwhite == BS_UNKNOWN && !spacewarning) {
|
|
|
160 |
warning1( "embedded spaces encountered within paths, specify -W option\n");
|
|
|
161 |
spacewarning++;
|
|
|
162 |
}
|
|
|
163 |
strcpy(buf, str);
|
|
|
164 |
}
|
|
|
165 |
return (len);
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
|
|
|
169 |
static int
|
|
|
170 |
pr_object(const char *prefix, const char *file)
|
|
|
171 |
{
|
|
|
172 |
static char buf[ MAX_PATH*3 ], sbuf[ MAX_PATH*3 ];
|
|
|
173 |
int len = 0;
|
|
|
174 |
|
|
|
175 |
sprintf(buf, "\n%s%s%s:", prefix?prefix:"", file, objsuffix);
|
|
|
176 |
len = strlen( buf );
|
|
|
177 |
|
|
|
178 |
if (strchr(buf, ' ') || embeddedwhite == BS_URL) {
|
|
|
179 |
if (embeddedwhite == BS_JUNK)
|
|
|
180 |
return -1; /* junk */
|
|
|
181 |
len += pr_space( (const char *)buf, sbuf );
|
|
|
182 |
fwrite(sbuf, len, 1, stdout);
|
|
|
183 |
} else {
|
|
|
184 |
fwrite(buf, len, 1, stdout);
|
|
|
185 |
}
|
|
|
186 |
return len;
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
void
|
|
|
190 |
pr(ip, file, base)
|
|
|
191 |
register struct inclist *ip;
|
|
|
192 |
char *file, *base;
|
|
|
193 |
{
|
|
|
194 |
static char *lastfile;
|
|
|
195 |
static int current_len;
|
|
|
196 |
static char buf[ MAX_PATH*3 ];
|
|
|
197 |
const char *t_base;
|
|
|
198 |
register int len, plen, i;
|
|
|
199 |
boolean spaces;
|
|
|
200 |
|
|
|
201 |
/*
|
|
|
202 |
* mask system directories
|
|
|
203 |
*/
|
|
|
204 |
if (mflags & MFLAG_NOSYSTEM) {
|
|
|
205 |
char **pp;
|
|
|
206 |
for (pp = systemdirs; *pp; pp++) {
|
|
|
207 |
if (strncmp(*pp, ip->i_file, strlen(*pp)) == 0)
|
|
|
208 |
return;
|
|
|
209 |
(void) strcpy(buf, *pp);
|
|
|
210 |
remove_dotdot(buf);
|
|
|
211 |
if (strncmp(buf, ip->i_file, strlen(buf)) == 0)
|
|
|
212 |
return;
|
|
|
213 |
}
|
|
|
214 |
}
|
|
|
215 |
|
|
|
216 |
/*
|
|
|
217 |
* dump file
|
|
|
218 |
*/
|
|
|
219 |
printed = TRUE;
|
|
|
220 |
len = strlen(ip->i_file)+1;
|
|
|
221 |
spaces = strchr(ip->i_file, ' ') ? TRUE : FALSE;
|
|
|
222 |
|
|
|
223 |
if (spaces && embeddedwhite == BS_JUNK)
|
|
|
224 |
return; /* junk */
|
|
|
225 |
|
|
|
226 |
buf[0] = ' ';
|
|
|
227 |
if (spaces || embeddedwhite == BS_URL) {
|
|
|
228 |
len += pr_space( ip->i_file, buf+1 );
|
|
|
229 |
} else {
|
|
|
230 |
strcpy( buf+1, ip->i_file );
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
if (opt_basename &&
|
|
|
234 |
((t_base = strrchr(base, '/')) != NULL||
|
|
|
235 |
(t_base = strrchr(base, '\\')) != NULL))
|
|
|
236 |
t_base++;
|
|
|
237 |
else t_base = base;
|
|
|
238 |
|
|
|
239 |
if (objprefixs[1]) {
|
|
|
240 |
/*
|
|
|
241 |
* Multiple objprefix's.
|
|
|
242 |
*/
|
|
|
243 |
for (i = 0; i < MAXPREFIXS && objprefixs[i]; i++) {
|
|
|
244 |
if ((plen = pr_object( objprefixs[i], t_base )) == -1)
|
|
|
245 |
return; /*junk*/
|
|
|
246 |
|
|
|
247 |
if (plen >= 41) {
|
|
|
248 |
fputs("\t", stdout);
|
|
|
249 |
} else {
|
|
|
250 |
while (plen < 41) {
|
|
|
251 |
fputs("\t", stdout);
|
|
|
252 |
plen = ((plen-1) >> 3 << 3) + 9;
|
|
|
253 |
}
|
|
|
254 |
}
|
|
|
255 |
fwrite(buf+1, len-1, 1, stdout);
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
} else {
|
|
|
259 |
/*
|
|
|
260 |
* None or one, objprefix's.
|
|
|
261 |
*/
|
|
|
262 |
if (current_len + len > width || file != lastfile) {
|
|
|
263 |
/*
|
|
|
264 |
* Line length exceeded or new file.
|
|
|
265 |
*/
|
|
|
266 |
if ((plen = pr_object( objprefixs[0], t_base )) == -1)
|
|
|
267 |
return; /*junk*/
|
|
|
268 |
current_len = plen;
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
fwrite(buf, len, 1, stdout);
|
|
|
272 |
current_len += len;
|
|
|
273 |
lastfile = file;
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
/*
|
|
|
277 |
* If verbose is set, then print out what this file includes.
|
|
|
278 |
*/
|
|
|
279 |
if (! verbose || ip->i_list == NULL || ip->i_flags & NOTIFIED)
|
|
|
280 |
return;
|
|
|
281 |
ip->i_flags |= NOTIFIED;
|
|
|
282 |
lastfile = NULL;
|
|
|
283 |
printf("\n# %s includes:", ip->i_file);
|
|
|
284 |
for (i=0; i<ip->i_listlen; i++)
|
|
|
285 |
printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
|
|
|
286 |
}
|
|
|
287 |
|