feisty meow concerns codebase 2.140
pr.cpp
Go to the documentation of this file.
1/*
2
3Copyright (c) 1993, 1994 X Consortium
4
5Permission is hereby granted, free of charge, to any person obtaining a copy
6of this software and associated documentation files (the "Software"), to deal
7in the Software without restriction, including without limitation the rights
8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9copies of the Software, and to permit persons to whom the Software is
10furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22Except as contained in this notice, the name of the X Consortium shall not be
23used in advertising or otherwise to promote the sale, use or other dealings
24in 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;
37extern char *objprefix;
38extern char *objsuffix;
39extern int width;
40extern bool printed;
41extern bool verbose;
42extern bool show_where_not;
43
44void add_include(filepointer *filep, inclist *file,
45 inclist *file_red, char *include, bool dot, bool failOK)
46{
47 struct inclist *newfile;
48 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);
63fatalerr("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
80void recursive_pr_include(struct inclist *head, char *file,
81 char *base)
82{
83 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
98void pr(struct inclist *ip, char *file, char *base, bool rc_file)
99{
100 static char *lastfile;
101 static int current_len;
102 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
filepointer * getfile(char *file)
Definition makedep.cpp:518
int find_includes(filepointer *filep, inclist *file, inclist *file_red, int recursion, bool failOK)
Definition parse.cpp:40
void freefile(filepointer *fp)
Definition makedep.cpp:547
void included_by(inclist *ip, inclist *newfile)
Definition include.cpp:296
inclist * inc_path(char *file, char *include, bool dot, bool &failure_okay)
Definition include.cpp:58
void warning1(const char *msg, x1, x2, x3, x4, x5, x6, x7, x8, x9)
Definition makedep.cpp:790
void fatalerr(char *msg, x1, x2, x3, x4, x5, x6, x7, x8, x9)
Definition makedep.cpp:749
void warning(const char *msg, x1, x2, x3, x4, x5, x6, x7, x8, x9)
Definition makedep.cpp:770
int width
Definition makedep.cpp:109
bool show_where_not
Definition makedep.cpp:113
void add_include(filepointer *filep, inclist *file, inclist *file_red, char *include, bool dot, bool failOK)
Definition pr.cpp:44
void pr(struct inclist *ip, char *file, char *base, bool rc_file)
Definition pr.cpp:98
void recursive_pr_include(struct inclist *head, char *file, char *base)
Definition pr.cpp:80
bool verbose
Definition makedep.cpp:112
char * objprefix
Definition makedep.cpp:106
bool printed
Definition makedep.cpp:111
char * objsuffix
Definition makedep.cpp:107
long f_line
Definition def.h:122
Definition def.h:101
bool i_searched
Definition def.h:112
int i_listlen
Definition def.h:105
bool i_notified
Definition def.h:110
bool i_marked
Definition def.h:111
char * i_incstring
Definition def.h:102
char * i_file
Definition def.h:103
inclist ** i_list
Definition def.h:104