source: trunk/src/makedep/pr.c@ 164

Last change on this file since 164 was 164, checked in by bird, 21 years ago

Initial revision

  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1/* $Xorg: pr.c,v 1.4 2001/02/09 02:03:16 xorgcvs Exp $ */
2/*
3
4Copyright (c) 1993, 1994, 1998 The Open Group
5
6Permission to use, copy, modify, distribute, and sell this software and its
7documentation for any purpose is hereby granted without fee, provided that
8the above copyright notice appear in all copies and that both that
9copyright notice and this permission notice appear in supporting
10documentation.
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22Except as contained in this notice, the name of The Open Group shall not be
23used in advertising or otherwise to promote the sale, use or other dealings
24in this Software without prior written authorization from The Open Group.
25
26*/
27/* $XFree86: xc/config/makedepend/pr.c,v 1.4 2001/04/29 23:25:02 tsi Exp $ */
28
29#include "def.h"
30
31extern struct inclist inclist[ MAXFILES ],
32 *inclistp;
33extern char *objprefix;
34extern char *objsuffix;
35extern int width;
36extern boolean printed;
37extern boolean verbose;
38extern boolean show_where_not;
39
40void
41add_include(struct filepointer *filep, struct inclist *file,
42 struct inclist *file_red, char *include, int type,
43 boolean failOK)
44{
45 register struct inclist *newfile;
46 register struct filepointer *content;
47
48 /*
49 * First decide what the pathname of this include file really is.
50 */
51 newfile = inc_path(file->i_file, include, type);
52 if (newfile == NULL) {
53 if (failOK)
54 return;
55 if (file != file_red)
56 warning("%s (reading %s, line %d): ",
57 file_red->i_file, file->i_file, filep->f_line);
58 else
59 warning("%s, line %d: ", file->i_file, filep->f_line);
60 warning1("cannot find include file \"%s\"\n", include);
61 show_where_not = TRUE;
62 newfile = inc_path(file->i_file, include, type);
63 show_where_not = FALSE;
64 }
65
66 if (newfile) {
67 included_by(file, newfile);
68 if (!(newfile->i_flags & SEARCHED)) {
69 newfile->i_flags |= SEARCHED;
70 content = getfile(newfile->i_file);
71 find_includes(content, newfile, file_red, 0, failOK);
72 freefile(content);
73 }
74 }
75}
76
77static void
78pr(struct inclist *ip, char *file, char *base)
79{
80 static char *lastfile;
81 static int current_len;
82 register int len, i;
83 char buf[ BUFSIZ ];
84
85 printed = TRUE;
86 len = strlen(ip->i_file)+1;
87 if (current_len + len > width || file != lastfile) {
88 lastfile = file;
89 sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix,
90 ip->i_file);
91 len = current_len = strlen(buf);
92 }
93 else {
94 buf[0] = ' ';
95 strcpy(buf+1, ip->i_file);
96 current_len += len;
97 }
98 fwrite(buf, len, 1, stdout);
99
100 /*
101 * If verbose is set, then print out what this file includes.
102 */
103 if (! verbose || ip->i_list == NULL || ip->i_flags & NOTIFIED)
104 return;
105 ip->i_flags |= NOTIFIED;
106 lastfile = NULL;
107 printf("\n# %s includes:", ip->i_file);
108 for (i=0; i<ip->i_listlen; i++)
109 printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
110}
111
112void
113recursive_pr_include(struct inclist *head, char *file, char *base)
114{
115 int i;
116
117 if (head->i_flags & MARKED)
118 return;
119 head->i_flags |= MARKED;
120 if (head->i_file != file)
121 pr(head, file, base);
122 for (i=0; i<head->i_listlen; i++)
123 recursive_pr_include(head->i_list[ i ], file, base);
124}
Note: See TracBrowser for help on using the repository browser.