xref: /aoo41x/main/soltools/mkdepend/pr.c (revision cdf0e10c)
1 /* $XConsortium: pr.c,v 1.17 94/04/17 20:10:38 gildea Exp $ */
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 */
28 
29 #include "def.h"
30 #include <string.h>
31 void pr( struct inclist *ip, char *file,char *base);
32 
33 extern struct	inclist	inclist[ MAXFILES ],
34 			*inclistp;
35 extern char	*objprefix;
36 extern char	*objsuffix;
37 extern int	width;
38 extern boolean	printed;
39 extern boolean	verbose;
40 extern boolean	show_where_not;
41 
add_include(filep,file,file_red,include,dot,failOK,incCollection,symbols)42 void add_include(filep, file, file_red, include, dot, failOK, incCollection, symbols)
43 	struct filepointer	*filep;
44 	struct inclist	*file, *file_red;
45 	char	*include;
46 	boolean	dot;
47 	boolean	failOK;
48     struct IncludesCollection* incCollection;
49 	struct symhash  *symbols;
50 {
51 	register struct inclist	*newfile;
52 	register struct filepointer	*content;
53 
54 	/*
55 	 * First decide what the pathname of this include file really is.
56 	 */
57 	newfile = inc_path(file->i_file, include, dot, incCollection);
58 	if (newfile == NULL) {
59 		if (failOK)
60 		    return;
61 		if (file != file_red)
62 			warning("%s (reading %s, line %d): ",
63 				file_red->i_file, file->i_file, filep->f_line);
64 		else
65 			warning("%s, line %d: ", file->i_file, filep->f_line);
66 		warning1("cannot find include file \"%s\"\n", include);
67 		show_where_not = TRUE;
68 		newfile = inc_path(file->i_file, include, dot, incCollection);
69 		show_where_not = FALSE;
70 	}
71 
72 	if (newfile) {
73 
74 		/* Only add new dependency files if they don't have "/usr/include" in them. */
75 		if (!(newfile && newfile->i_file && strstr(newfile->i_file, "/usr/"))) {
76 			included_by(file, newfile);
77 		}
78 
79 		if (!newfile->i_searched) {
80 			newfile->i_searched = TRUE;
81 			content = getfile(newfile->i_file);
82 			find_includes(content, newfile, file_red, 0, failOK, incCollection, symbols);
83 			freefile(content);
84 		}
85 	}
86 }
87 
recursive_pr_include(head,file,base)88 void recursive_pr_include(head, file, base)
89 	register struct inclist	*head;
90 	register char	*file, *base;
91 {
92 	register int	i;
93 
94 	if (head->i_marked)
95 		return;
96 	head->i_marked = TRUE;
97 	if (head->i_file != file)
98 		pr(head, file, base);
99 	for (i=0; i<head->i_listlen; i++)
100 		recursive_pr_include(head->i_list[ i ], file, base);
101 }
102 
pr(ip,file,base)103 void pr(ip, file, base)
104 	register struct inclist  *ip;
105 	char	*file, *base;
106 {
107 	static char	*lastfile;
108 	static int	current_len;
109 	register int	len, i;
110 	char	buf[ BUFSIZ ];
111 
112 	printed = TRUE;
113 	len = strlen(ip->i_file)+1;
114 	if (current_len + len > width || file != lastfile) {
115 		lastfile = file;
116 		sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix,
117 			ip->i_file);
118 		len = current_len = strlen(buf);
119 	}
120 	else {
121 		buf[0] = ' ';
122 		strcpy(buf+1, ip->i_file);
123 		current_len += len;
124 	}
125 	fwrite(buf, len, 1, stdout);
126 
127 	/*
128 	 * If verbose is set, then print out what this file includes.
129 	 */
130 	if (! verbose || ip->i_list == NULL || ip->i_notified)
131 		return;
132 	ip->i_notified = TRUE;
133 	lastfile = NULL;
134 	printf("\n# %s includes:", ip->i_file);
135 	for (i=0; i<ip->i_listlen; i++)
136 		printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
137 }
138