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