]> git.sesse.net Git - rdpsrv/blob - Xserver/config/makedepend/pr.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / config / makedepend / pr.c
1 /* $XConsortium: pr.c /main/20 1996/12/04 10:11:41 swick $ */
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
31 extern struct   inclist inclist[ MAXFILES ],
32                         *inclistp;
33 extern char     *objprefix;
34 extern char     *objsuffix;
35 extern int      width;
36 extern boolean  printed;
37 extern boolean  verbose;
38 extern boolean  show_where_not;
39
40 void
41 add_include(filep, file, file_red, include, dot, failOK)
42         struct filepointer      *filep;
43         struct inclist  *file, *file_red;
44         char    *include;
45         boolean dot;
46 {
47         register struct inclist *newfile;
48         register struct filepointer     *content;
49
50         /*
51          * First decide what the pathname of this include file really is.
52          */
53         newfile = inc_path(file->i_file, include, dot);
54         if (newfile == NULL) {
55                 if (failOK)
56                     return;
57                 if (file != file_red)
58                         warning("%s (reading %s, line %d): ",
59                                 file_red->i_file, file->i_file, filep->f_line);
60                 else
61                         warning("%s, line %d: ", file->i_file, filep->f_line);
62                 warning1("cannot find include file \"%s\"\n", include);
63                 show_where_not = TRUE;
64                 newfile = inc_path(file->i_file, include, dot);
65                 show_where_not = FALSE;
66         }
67
68         if (newfile) {
69                 included_by(file, newfile);
70                 if (!(newfile->i_flags & SEARCHED)) {
71                         newfile->i_flags |= SEARCHED;
72                         content = getfile(newfile->i_file);
73                         find_includes(content, newfile, file_red, 0, failOK);
74                         freefile(content);
75                 }
76         }
77 }
78
79 void
80 pr(ip, file, base)
81         register struct inclist  *ip;
82         char    *file, *base;
83 {
84         static char     *lastfile;
85         static int      current_len;
86         register int    len, i;
87         char    buf[ BUFSIZ ];
88
89         printed = TRUE;
90         len = strlen(ip->i_file)+1;
91         if (current_len + len > width || file != lastfile) {
92                 lastfile = file;
93                 sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix,
94                         ip->i_file);
95                 len = current_len = strlen(buf);
96         }
97         else {
98                 buf[0] = ' ';
99                 strcpy(buf+1, ip->i_file);
100                 current_len += len;
101         }
102         fwrite(buf, len, 1, stdout);
103
104         /*
105          * If verbose is set, then print out what this file includes.
106          */
107         if (! verbose || ip->i_list == NULL || ip->i_flags & NOTIFIED)
108                 return;
109         ip->i_flags |= NOTIFIED;
110         lastfile = NULL;
111         printf("\n# %s includes:", ip->i_file);
112         for (i=0; i<ip->i_listlen; i++)
113                 printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
114 }
115
116 void
117 recursive_pr_include(head, file, base)
118         register struct inclist *head;
119         register char   *file, *base;
120 {
121         register int    i;
122
123         if (head->i_flags & MARKED)
124                 return;
125         head->i_flags |= MARKED;
126         if (head->i_file != file)
127                 pr(head, file, base);
128         for (i=0; i<head->i_listlen; i++)
129                 recursive_pr_include(head->i_list[ i ], file, base);
130 }