first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / tools / dependency_tool / pr.cpp
1 /*
2
3 Copyright (c) 1993, 1994  X Consortium
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 Except as contained in this notice, the name of the X Consortium shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from the X Consortium.
25
26 */
27
28 #ifdef __WIN32__
29   #pragma warning(disable : 4996)
30 #endif
31
32 #include "def.h"
33
34 #include <string.h>
35
36 extern struct  inclist  inc_list[ MAXFILES ], *inclistp;
37 extern char  *objprefix;
38 extern char  *objsuffix;
39 extern int  width;
40 extern bool  printed;
41 extern bool  verbose;
42 extern bool  show_where_not;
43
44 void add_include(filepointer *filep, inclist  *file,
45     inclist  *file_red, char  *include, bool dot, bool failOK)
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, failOK);
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 fatalerr("cannot find include file \"%s\"\n", include);
64     show_where_not = true;
65     newfile = inc_path(file->i_file, include, dot, failOK);
66     show_where_not = false;
67   }
68
69   if (newfile) {
70     included_by(file, newfile);
71     if (!newfile->i_searched) {
72       newfile->i_searched = true;
73       content = getfile(newfile->i_file);
74       find_includes(content, newfile, file_red, 0, failOK);
75       freefile(content);
76     }
77   }
78 }
79
80 void recursive_pr_include(register struct inclist  *head, register char  *file,
81     register char  *base)
82 {
83   register int  i;
84
85   if (head->i_marked)
86     return;
87   head->i_marked = true;
88   if (head->i_file != file) {
89     bool rc_file = false;
90     if ((strlen(file) >= 3) && !strcmp(file + strlen(file) - 3, ".rc"))
91       rc_file = true;
92     pr(head, file, base, rc_file);
93   }
94   for (i=0; i<head->i_listlen; i++)
95     recursive_pr_include(head->i_list[ i ], file, base);
96 }
97
98 void pr(register struct inclist *ip, char *file, char *base, bool rc_file)
99 {
100   static char  *lastfile;
101   static int  current_len;
102   register int  len, i;
103   char  buf[ BUFSIZ ];
104
105   printed = true;
106   len = int(strlen(ip->i_file)+1);
107   if (current_len + len > width || file != lastfile) {
108     lastfile = file;
109     char *temp_suff = objsuffix;
110     if (rc_file) temp_suff = (char *)".res";
111     sprintf(buf, "\n%s%s%s: %s ", objprefix, base, temp_suff, ip->i_file);
112     len = current_len = int(strlen(buf));
113   }
114   else {
115     strcpy(buf, ip->i_file);
116 //printf("ip->file=%s\n", ip->i_file);
117     char tmp[2] = { ' ', '\0' };
118 //printf("tmp=%s\n", tmp);
119     strcat(buf, tmp);
120 //printf("buf=%s\n", buf);
121     current_len += len;
122   }
123   fwrite(buf, len, 1, stdout);
124
125   // If verbose is set, then print out what this file includes.
126   if (! verbose || ip->i_list == NULL || ip->i_notified)
127     return;
128   ip->i_notified = true;
129   lastfile = NULL;
130   printf("\n# %s includes:", ip->i_file);
131   for (i=0; i<ip->i_listlen; i++)
132     printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
133 }
134