1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* $XConsortium: pr.c,v 1.17 94/04/17 20:10:38 gildea Exp $ */
5 Copyright (c) 1993, 1994 X Consortium
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 Except as contained in this notice, the name of the X Consortium shall not be
25 used in advertising or otherwise to promote the sale, use or other dealings
26 in this Software without prior written authorization from the X Consortium.
33 #include <sal/types.h>
35 static size_t pr( struct inclist
*ip
, char *file
,char *base
);
39 void add_include(struct filepointer
*filep
, struct inclist
*file
, struct inclist
*file_red
, char *include
, boolean dot
, boolean failOK
, struct IncludesCollection
* incCollection
, struct symhash
*symbols
)
41 struct inclist
*newfile
;
42 struct filepointer
*content
;
45 * First decide what the pathname of this include file really is.
47 newfile
= inc_path(file
->i_file
, include
, dot
, incCollection
);
48 if (newfile
== NULL
) {
52 warning("%s (reading %s, line %d): ",
53 file_red
->i_file
, file
->i_file
, filep
->f_line
);
55 warning("%s, line %d: ", file
->i_file
, filep
->f_line
);
56 warning1("cannot find include file \"%s\"\n", include
);
57 show_where_not
= TRUE
;
58 newfile
= inc_path(file
->i_file
, include
, dot
, incCollection
);
59 show_where_not
= FALSE
;
65 /* Only add new dependency files if they don't have "/usr/include" in them. */
66 if (!(newfile
->i_file
&& strstr(newfile
->i_file
, "/usr/"))) {
67 included_by(file
, newfile
);
70 if (!newfile
->i_searched
) {
71 newfile
->i_searched
= TRUE
;
72 content
= getfile(newfile
->i_file
);
73 // coverity[tainted_data] - this is a build time tool
74 find_includes(content
, newfile
, file_red
, 0, failOK
, incCollection
, symbols
);
79 static void pr_dummy(struct inclist
const *ip
)
81 fwrite(ip
->i_file
, strlen(ip
->i_file
), 1, stdout
);
82 fwrite(" :\n\n", 4, 1, stdout
);
85 void recursive_pr_dummy(struct inclist
*head
, char *file
)
89 if (head
->i_marked
== 2)
91 head
->i_marked
= 2; // it's a large boolean...
92 if (head
->i_file
!= file
)
94 for (i
=0; i
<head
->i_listlen
; i
++)
95 recursive_pr_dummy(head
->i_list
[ i
], file
);
99 void recursive_pr_include(struct inclist
*head
, char *file
, char *base
)
105 head
->i_marked
= TRUE
;
106 if (head
->i_file
!= file
)
107 pr(head
, file
, base
);
108 for (i
=0; i
<head
->i_listlen
; i
++)
109 recursive_pr_include(head
->i_list
[ i
], file
, base
);
112 size_t pr(struct inclist
*ip
, char *file
, char *base
)
115 static char *lastfile
;
120 len
= (int)strlen(ip
->i_file
)+4;
121 if (file
!= lastfile
) {
123 SAL_WNODEPRECATED_DECLARATIONS_PUSH
/* sprintf (macOS 13 SDK) */
124 sprintf(buf
, "\n%s%s%s: \\\n %s", objprefix
, base
, objsuffix
,
126 SAL_WNODEPRECATED_DECLARATIONS_POP
127 len
= (int)strlen(buf
);
134 strcpy(buf
+4, ip
->i_file
);
136 ret
= fwrite(buf
, len
, 1, stdout
);
139 * If verbose is set, then print out what this file includes.
141 if (! verbose
|| ip
->i_list
== NULL
|| ip
->i_notified
)
143 ip
->i_notified
= TRUE
;
145 printf("\n# %s includes:", ip
->i_file
);
146 for (i
=0; i
<ip
->i_listlen
; i
++)
147 printf("\n#\t%s", ip
->i_list
[ i
]->i_incstring
);
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */