Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
pr.c
Go to the documentation of this file.
1/* $XConsortium: pr.c /main/20 1996/12/04 10:11:41 swick $ */
2/*
3
4Copyright (c) 1993, 1994 X Consortium
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23Except as contained in this notice, the name of the X Consortium shall not be
24used in advertising or otherwise to promote the sale, use or other dealings
25in this Software without prior written authorization from the X Consortium.
26
27*/
28
29#include "def.h"
30
31extern struct inclist inclist[ MAXFILES ],
33extern char *objprefix;
34extern char *objsuffix;
35extern int width;
36extern boolean printed;
37extern boolean verbose;
38extern boolean show_where_not;
39
40extern void included_by(struct inclist *ip, struct inclist *newfile);
41extern int find_includes(struct filepointer *filep, struct inclist *file,
42 struct inclist *file_red, int recursion,
43 boolean failOK);
44extern void freefile(struct filepointer *fp);
45
46extern void ROOT_adddep(char* buf, size_t len);
47extern void ROOT_newFile();
48
49void add_include(struct filepointer *filep, struct inclist *file, struct inclist *file_red, char *include, boolean dot,
50 boolean failOK)
51{
52 register struct inclist *newfile;
53 register struct filepointer *content;
54
55 /*
56 * First decide what the pathname of this include file really is.
57 */
58 newfile = inc_path(file->i_file, include, dot);
59 if (newfile == NULL) {
60 if (failOK)
61 return;
62 if (file != file_red)
63 warning("%s (reading %s, line %d): ",
64 file_red->i_file, file->i_file, filep->f_line);
65 else
66 warning("%s, line %d: ", file->i_file, filep->f_line);
67 warning1("cannot find include file \"%s\"\n", include);
69 newfile = inc_path(file->i_file, include, dot);
71 }
72
73 if (newfile) {
74 included_by(file, newfile);
75 if (!(newfile->i_flags & SEARCHED)) {
76 newfile->i_flags |= SEARCHED;
77 if (strncmp(newfile->i_file, "/usr/include/", 13)) {
78 content = getfile(newfile->i_file);
79 find_includes(content, newfile, file_red, 0, failOK);
80 freefile(content);
81 }
82 }
83 }
84}
85
86void pr(register struct inclist *ip, char *file, char *base, char *dep)
87{
88 static char *lastfile;
89 static int current_len;
90 register int len, i;
91 char buf[ BUFSIZ ];
92 char *ipifile;
93
94 printed = TRUE;
95 len = strlen(ip->i_file) + 1;
96 ipifile = 0;
97 if (len > 2 && ip->i_file[1] == ':') {
98 if (getenv("OSTYPE") && !strcmp(getenv("OSTYPE"), "msys")) {
99 /* windows path */
100 ipifile = malloc(len);
101 strcpy(ipifile, ip->i_file);
102 ipifile[1] = ipifile[0];
103 ipifile[0] = '/';
104 } else {
105#ifdef _MSC_VER
106 /* native Windows */
107 ipifile = malloc(len);
108 strcpy(ipifile, ip->i_file);
109#else
110 /* generic cygwin */
111 ipifile = malloc(len + 11);
112 strcpy(ipifile, "/cygdrive/");
113 ipifile[10] = ip->i_file[0];
114 strcpy(ipifile + 11, ip->i_file + 2);
115 len += 9;
116#endif
117 }
118 } else ipifile = ip->i_file;
119
120 if (current_len + len > width || file != lastfile) {
121 lastfile = file;
122 if (rootBuild)
123 ROOT_newFile();
124 if (dep == 0) {
125 sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix,
126 ipifile);
127 } else {
128 sprintf(buf, "\n%s: %s", dep,
129 ipifile);
130 }
131 len = current_len = strlen(buf);
132 } else {
133 buf[0] = ' ';
134 strcpy(buf + 1, ipifile);
135 current_len += len;
136 }
137 if (len > 2 && ip->i_file[1] == ':')
138 free(ipifile);
139
140 if (rootBuild)
141 ROOT_adddep(buf, len);
142 else
143 if (fwrite(buf, len, 1, stdout) != 1)
144 fprintf(stderr, "pr: fwrite error\n");
145
146 /*
147 * If verbose is set, then print out what this file includes.
148 */
149 if (! verbose || ip->i_list == NULL || ip->i_flags & NOTIFIED)
150 return;
151 ip->i_flags |= NOTIFIED;
152 lastfile = NULL;
153 printf("\n# %s includes:", ip->i_file);
154 for (i = 0; i < ip->i_listlen; i++)
155 printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
156}
157
158void recursive_pr_include(register struct inclist *head, register char *file, register char *base, register char *dep)
159{
160 register int i;
161
162 if (head->i_flags & MARKED)
163 return;
164 head->i_flags |= MARKED;
165 if (head->i_file != file)
166 pr(head, file, base, dep);
167 for (i = 0; i < head->i_listlen; i++)
168 recursive_pr_include(head->i_list[ i ], file, base, dep);
169}
#define NULL
Definition ZInflate.c:15
#define free
Definition civetweb.c:1578
#define malloc
Definition civetweb.c:1575
#define SEARCHED
Definition def.h:103
struct inclist * inc_path(char *, char *, boolean)
Definition include.c:234
#define MAXFILES
Definition def.h:47
void warning1(char *,...)
Definition main.c:772
#define TRUE
Definition def.h:50
#define FALSE
Definition def.h:51
#define NOTIFIED
Definition def.h:101
struct filepointer * getfile(char *)
Definition main.c:525
#define MARKED
Definition def.h:102
int rootBuild
Definition mainroot.cxx:47
void warning(char *,...)
Definition main.c:761
void file()
Definition file.C:11
printf("Client 0: bytes recv = %d, bytes sent = %d\n", s0->GetBytesRecv(), s0->GetBytesSent())
boolean show_where_not
Definition main.c:111
struct inclist * inclistp
Definition include.c:37
void add_include(struct filepointer *filep, struct inclist *file, struct inclist *file_red, char *include, boolean dot, boolean failOK)
Definition pr.c:49
void freefile(struct filepointer *fp)
Definition main.c:556
void pr(register struct inclist *ip, char *file, char *base, char *dep)
Definition pr.c:86
void ROOT_adddep(char *buf, size_t len)
Definition mainroot.cxx:81
void included_by(struct inclist *ip, struct inclist *newfile)
void ROOT_newFile()
Definition mainroot.cxx:56
void recursive_pr_include(register struct inclist *head, register char *file, register char *base, register char *dep)
Definition pr.c:158
int find_includes(struct filepointer *filep, struct inclist *file, struct inclist *file_red, int recursion, boolean failOK)
Definition parse.c:496
int width
Definition main.c:107
boolean verbose
Definition main.c:110
boolean printed
Definition main.c:109
char * objprefix
Definition main.c:103
char * objsuffix
Definition main.c:104
long f_line
Definition def.h:124
Definition def.h:106
int i_listlen
Definition def.h:110
unsigned char i_flags
Definition def.h:116
char * i_incstring
Definition def.h:107
char * i_file
Definition def.h:108
struct inclist ** i_list
Definition def.h:109