1cdf0e10cSrcweir /* $XConsortium: pr.c,v 1.17 94/04/17 20:10:38 gildea Exp $ */
2cdf0e10cSrcweir /*
3cdf0e10cSrcweir
4cdf0e10cSrcweir Copyright (c) 1993, 1994 X Consortium
5cdf0e10cSrcweir
6cdf0e10cSrcweir Permission is hereby granted, free of charge, to any person obtaining a copy
7cdf0e10cSrcweir of this software and associated documentation files (the "Software"), to deal
8cdf0e10cSrcweir in the Software without restriction, including without limitation the rights
9cdf0e10cSrcweir to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10cdf0e10cSrcweir copies of the Software, and to permit persons to whom the Software is
11cdf0e10cSrcweir furnished to do so, subject to the following conditions:
12cdf0e10cSrcweir
13cdf0e10cSrcweir The above copyright notice and this permission notice shall be included in
14cdf0e10cSrcweir all copies or substantial portions of the Software.
15cdf0e10cSrcweir
16cdf0e10cSrcweir THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17cdf0e10cSrcweir IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18cdf0e10cSrcweir FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19cdf0e10cSrcweir X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20cdf0e10cSrcweir AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21cdf0e10cSrcweir CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22cdf0e10cSrcweir
23cdf0e10cSrcweir Except as contained in this notice, the name of the X Consortium shall not be
24cdf0e10cSrcweir used in advertising or otherwise to promote the sale, use or other dealings
25cdf0e10cSrcweir in this Software without prior written authorization from the X Consortium.
26cdf0e10cSrcweir
27cdf0e10cSrcweir */
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "def.h"
30cdf0e10cSrcweir #include <string.h>
31cdf0e10cSrcweir void pr( struct inclist *ip, char *file,char *base);
32cdf0e10cSrcweir
33cdf0e10cSrcweir extern struct inclist inclist[ MAXFILES ],
34cdf0e10cSrcweir *inclistp;
35cdf0e10cSrcweir extern char *objprefix;
36cdf0e10cSrcweir extern char *objsuffix;
37cdf0e10cSrcweir extern int width;
38cdf0e10cSrcweir extern boolean printed;
39cdf0e10cSrcweir extern boolean verbose;
40cdf0e10cSrcweir extern boolean show_where_not;
41cdf0e10cSrcweir
add_include(filep,file,file_red,include,dot,failOK,incCollection,symbols)42cdf0e10cSrcweir void add_include(filep, file, file_red, include, dot, failOK, incCollection, symbols)
43cdf0e10cSrcweir struct filepointer *filep;
44cdf0e10cSrcweir struct inclist *file, *file_red;
45cdf0e10cSrcweir char *include;
46cdf0e10cSrcweir boolean dot;
47cdf0e10cSrcweir boolean failOK;
48cdf0e10cSrcweir struct IncludesCollection* incCollection;
49cdf0e10cSrcweir struct symhash *symbols;
50cdf0e10cSrcweir {
51cdf0e10cSrcweir register struct inclist *newfile;
52cdf0e10cSrcweir register struct filepointer *content;
53cdf0e10cSrcweir
54cdf0e10cSrcweir /*
55cdf0e10cSrcweir * First decide what the pathname of this include file really is.
56cdf0e10cSrcweir */
57cdf0e10cSrcweir newfile = inc_path(file->i_file, include, dot, incCollection);
58cdf0e10cSrcweir if (newfile == NULL) {
59cdf0e10cSrcweir if (failOK)
60cdf0e10cSrcweir return;
61cdf0e10cSrcweir if (file != file_red)
62cdf0e10cSrcweir warning("%s (reading %s, line %d): ",
63cdf0e10cSrcweir file_red->i_file, file->i_file, filep->f_line);
64cdf0e10cSrcweir else
65cdf0e10cSrcweir warning("%s, line %d: ", file->i_file, filep->f_line);
66cdf0e10cSrcweir warning1("cannot find include file \"%s\"\n", include);
67cdf0e10cSrcweir show_where_not = TRUE;
68cdf0e10cSrcweir newfile = inc_path(file->i_file, include, dot, incCollection);
69cdf0e10cSrcweir show_where_not = FALSE;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir
72cdf0e10cSrcweir if (newfile) {
73cdf0e10cSrcweir
74cdf0e10cSrcweir /* Only add new dependency files if they don't have "/usr/include" in them. */
75cdf0e10cSrcweir if (!(newfile && newfile->i_file && strstr(newfile->i_file, "/usr/"))) {
76cdf0e10cSrcweir included_by(file, newfile);
77cdf0e10cSrcweir }
78cdf0e10cSrcweir
79cdf0e10cSrcweir if (!newfile->i_searched) {
80cdf0e10cSrcweir newfile->i_searched = TRUE;
81cdf0e10cSrcweir content = getfile(newfile->i_file);
82cdf0e10cSrcweir find_includes(content, newfile, file_red, 0, failOK, incCollection, symbols);
83cdf0e10cSrcweir freefile(content);
84cdf0e10cSrcweir }
85cdf0e10cSrcweir }
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
recursive_pr_include(head,file,base)88cdf0e10cSrcweir void recursive_pr_include(head, file, base)
89cdf0e10cSrcweir register struct inclist *head;
90cdf0e10cSrcweir register char *file, *base;
91cdf0e10cSrcweir {
92cdf0e10cSrcweir register int i;
93cdf0e10cSrcweir
94cdf0e10cSrcweir if (head->i_marked)
95cdf0e10cSrcweir return;
96cdf0e10cSrcweir head->i_marked = TRUE;
97cdf0e10cSrcweir if (head->i_file != file)
98cdf0e10cSrcweir pr(head, file, base);
99cdf0e10cSrcweir for (i=0; i<head->i_listlen; i++)
100cdf0e10cSrcweir recursive_pr_include(head->i_list[ i ], file, base);
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
pr(ip,file,base)103cdf0e10cSrcweir void pr(ip, file, base)
104cdf0e10cSrcweir register struct inclist *ip;
105cdf0e10cSrcweir char *file, *base;
106cdf0e10cSrcweir {
107cdf0e10cSrcweir static char *lastfile;
108cdf0e10cSrcweir static int current_len;
109cdf0e10cSrcweir register int len, i;
110*e932034bSJim Jagielski char buf[ OURBUFSIZ ];
111cdf0e10cSrcweir
112cdf0e10cSrcweir printed = TRUE;
113cdf0e10cSrcweir len = strlen(ip->i_file)+1;
114cdf0e10cSrcweir if (current_len + len > width || file != lastfile) {
115cdf0e10cSrcweir lastfile = file;
116cdf0e10cSrcweir sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix,
117cdf0e10cSrcweir ip->i_file);
118cdf0e10cSrcweir len = current_len = strlen(buf);
119cdf0e10cSrcweir }
120cdf0e10cSrcweir else {
121cdf0e10cSrcweir buf[0] = ' ';
122cdf0e10cSrcweir strcpy(buf+1, ip->i_file);
123cdf0e10cSrcweir current_len += len;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir fwrite(buf, len, 1, stdout);
126cdf0e10cSrcweir
127cdf0e10cSrcweir /*
128cdf0e10cSrcweir * If verbose is set, then print out what this file includes.
129cdf0e10cSrcweir */
130cdf0e10cSrcweir if (! verbose || ip->i_list == NULL || ip->i_notified)
131cdf0e10cSrcweir return;
132cdf0e10cSrcweir ip->i_notified = TRUE;
133cdf0e10cSrcweir lastfile = NULL;
134cdf0e10cSrcweir printf("\n# %s includes:", ip->i_file);
135cdf0e10cSrcweir for (i=0; i<ip->i_listlen; i++)
136cdf0e10cSrcweir printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
137cdf0e10cSrcweir }
138