dtudcfonted: Resolve CID 86280
[oweals/cde.git] / cde / config / makedepend / pr.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $TOG: pr.c /main/21 1998/02/06 11:10:30 kaleb $ */
24 /*
25
26 Copyright (c) 1993, 1994, 1998 The Open Group
27
28 All Rights Reserved.
29
30 The above copyright notice and this permission notice shall be included in
31 all copies or substantial portions of the Software.
32
33 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
36 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
37 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
38 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
40 Except as contained in this notice, the name of The Open Group shall not be
41 used in advertising or otherwise to promote the sale, use or other dealings
42 in this Software without prior written authorization from The Open Group.
43
44 */
45
46 #include "def.h"
47
48 extern struct   inclist inclist[ MAXFILES ],
49                         *inclistp;
50 extern char     *objprefix;
51 extern char     *objsuffix;
52 extern int      width;
53 extern boolean  printed;
54 extern boolean  verbose;
55 extern boolean  show_where_not;
56
57 void
58 add_include(filep, file, file_red, include, dot, failOK)
59         struct filepointer      *filep;
60         struct inclist  *file, *file_red;
61         char    *include;
62         boolean dot;
63         boolean failOK;
64 {
65         register struct inclist *newfile;
66         register struct filepointer     *content;
67
68         /*
69          * First decide what the pathname of this include file really is.
70          */
71         newfile = inc_path(file->i_file, include, dot);
72         if (newfile == NULL) {
73                 if (failOK)
74                     return;
75                 if (file != file_red)
76                         warning("%s (reading %s, line %d): ",
77                                 file_red->i_file, file->i_file, filep->f_line);
78                 else
79                         warning("%s, line %d: ", file->i_file, filep->f_line);
80                 warning1("cannot find include file \"%s\"\n", include);
81                 show_where_not = TRUE;
82                 newfile = inc_path(file->i_file, include, dot);
83                 show_where_not = FALSE;
84         }
85
86         if (newfile) {
87                 included_by(file, newfile);
88                 if (!(newfile->i_flags & SEARCHED)) {
89                         newfile->i_flags |= SEARCHED;
90                         content = getfile(newfile->i_file);
91                         find_includes(content, newfile, file_red, 0, failOK);
92                         freefile(content);
93                 }
94         }
95 }
96
97 void
98 pr(ip, file, base)
99         register struct inclist  *ip;
100         char    *file, *base;
101 {
102         static char     *lastfile;
103         static int      current_len;
104         register int    len, i;
105         char    buf[ BUFSIZ ];
106
107         printed = TRUE;
108         len = strlen(ip->i_file)+1;
109         if (current_len + len > width || file != lastfile) {
110                 lastfile = file;
111                 snprintf(buf, BUFSIZ, "\n%s%s%s: %s", objprefix, base,
112                                 objsuffix, ip->i_file);
113                 len = current_len = strlen(buf);
114         }
115         else {
116                 buf[0] = ' ';
117                 strncpy(buf+1, ip->i_file, BUFSIZ - 1);
118                 current_len += len;
119         }
120         fwrite(buf, len, 1, stdout);
121
122         /*
123          * If verbose is set, then print out what this file includes.
124          */
125         if (! verbose || ip->i_list == NULL || ip->i_flags & NOTIFIED)
126                 return;
127         ip->i_flags |= NOTIFIED;
128         lastfile = NULL;
129         printf("\n# %s includes:", ip->i_file);
130         for (i=0; i<ip->i_listlen; i++)
131                 printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
132 }
133
134 void
135 recursive_pr_include(head, file, base)
136         register struct inclist *head;
137         register char   *file, *base;
138 {
139         register int    i;
140
141         if (head->i_flags & MARKED)
142                 return;
143         head->i_flags |= MARKED;
144         if (head->i_file != file)
145                 pr(head, file, base);
146         for (i=0; i<head->i_listlen; i++)
147                 recursive_pr_include(head->i_list[ i ], file, base);
148 }