Introduce DTKORNSHELL, analogous to KORNSHELL.
[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 {
64         register struct inclist *newfile;
65         register struct filepointer     *content;
66
67         /*
68          * First decide what the pathname of this include file really is.
69          */
70         newfile = inc_path(file->i_file, include, dot);
71         if (newfile == NULL) {
72                 if (failOK)
73                     return;
74                 if (file != file_red)
75                         warning("%s (reading %s, line %d): ",
76                                 file_red->i_file, file->i_file, filep->f_line);
77                 else
78                         warning("%s, line %d: ", file->i_file, filep->f_line);
79                 warning1("cannot find include file \"%s\"\n", include);
80                 show_where_not = TRUE;
81                 newfile = inc_path(file->i_file, include, dot);
82                 show_where_not = FALSE;
83         }
84
85         if (newfile) {
86                 included_by(file, newfile);
87                 if (!(newfile->i_flags & SEARCHED)) {
88                         newfile->i_flags |= SEARCHED;
89                         content = getfile(newfile->i_file);
90                         find_includes(content, newfile, file_red, 0, failOK);
91                         freefile(content);
92                 }
93         }
94 }
95
96 void
97 pr(ip, file, base)
98         register struct inclist  *ip;
99         char    *file, *base;
100 {
101         static char     *lastfile;
102         static int      current_len;
103         register int    len, i;
104         char    buf[ BUFSIZ ];
105
106         printed = TRUE;
107         len = strlen(ip->i_file)+1;
108         if (current_len + len > width || file != lastfile) {
109                 lastfile = file;
110                 sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix,
111                         ip->i_file);
112                 len = current_len = strlen(buf);
113         }
114         else {
115                 buf[0] = ' ';
116                 strcpy(buf+1, ip->i_file);
117                 current_len += len;
118         }
119         fwrite(buf, len, 1, stdout);
120
121         /*
122          * If verbose is set, then print out what this file includes.
123          */
124         if (! verbose || ip->i_list == NULL || ip->i_flags & NOTIFIED)
125                 return;
126         ip->i_flags |= NOTIFIED;
127         lastfile = NULL;
128         printf("\n# %s includes:", ip->i_file);
129         for (i=0; i<ip->i_listlen; i++)
130                 printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
131 }
132
133 void
134 recursive_pr_include(head, file, base)
135         register struct inclist *head;
136         register char   *file, *base;
137 {
138         register int    i;
139
140         if (head->i_flags & MARKED)
141                 return;
142         head->i_flags |= MARKED;
143         if (head->i_file != file)
144                 pr(head, file, base);
145         for (i=0; i<head->i_listlen; i++)
146                 recursive_pr_include(head->i_list[ i ], file, base);
147 }