00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "def.h"
00030
00031 extern struct inclist inclist[ MAXFILES ],
00032 *inclistp;
00033 extern char *objprefix;
00034 extern char *objsuffix;
00035 extern int width;
00036 extern boolean printed;
00037 extern boolean verbose;
00038 extern boolean show_where_not;
00039
00040 extern void included_by(struct inclist *ip, struct inclist *newfile);
00041 extern int find_includes(struct filepointer *filep, struct inclist *file,
00042 struct inclist *file_red, int recursion,
00043 boolean failOK);
00044 extern void freefile(struct filepointer *fp);
00045
00046 extern void ROOT_adddep(char* buf, size_t len);
00047 extern void ROOT_newFile();
00048
00049 void
00050 add_include(filep, file, file_red, include, dot, failOK)
00051 struct filepointer *filep;
00052 struct inclist *file, *file_red;
00053 char *include;
00054 boolean dot, failOK;
00055 {
00056 register struct inclist *newfile;
00057 register struct filepointer *content;
00058
00059
00060
00061
00062 newfile = inc_path(file->i_file, include, dot);
00063 if (newfile == NULL) {
00064 if (failOK)
00065 return;
00066 if (file != file_red)
00067 warning("%s (reading %s, line %d): ",
00068 file_red->i_file, file->i_file, filep->f_line);
00069 else
00070 warning("%s, line %d: ", file->i_file, filep->f_line);
00071 warning1("cannot find include file \"%s\"\n", include);
00072 show_where_not = TRUE;
00073 newfile = inc_path(file->i_file, include, dot);
00074 show_where_not = FALSE;
00075 }
00076
00077 if (newfile) {
00078 included_by(file, newfile);
00079 if (!(newfile->i_flags & SEARCHED)) {
00080 newfile->i_flags |= SEARCHED;
00081 content = getfile(newfile->i_file);
00082 find_includes(content, newfile, file_red, 0, failOK);
00083 freefile(content);
00084 }
00085 }
00086 }
00087
00088 void
00089 pr(ip, file, base, dep)
00090 register struct inclist *ip;
00091 char *file, *base, *dep;
00092 {
00093 static char *lastfile;
00094 static int current_len;
00095 register int len, i;
00096 char buf[ BUFSIZ ];
00097 char *ipifile;
00098
00099 printed = TRUE;
00100 len = strlen(ip->i_file) + 1;
00101 ipifile = 0;
00102 if (len > 2 && ip->i_file[1] == ':') {
00103 if (getenv("OSTYPE") && !strcmp(getenv("OSTYPE"), "msys")) {
00104
00105 ipifile = malloc(len);
00106 strcpy(ipifile, ip->i_file);
00107 ipifile[1] = ipifile[0];
00108 ipifile[0] = '/';
00109 } else {
00110
00111 ipifile = malloc(len + 11);
00112 strcpy(ipifile, "/cygdrive/");
00113 ipifile[10] = ip->i_file[0];
00114 strcpy(ipifile + 11, ip->i_file + 2);
00115 len += 9;
00116 }
00117 } else ipifile = ip->i_file;
00118
00119 if (current_len + len > width || file != lastfile) {
00120 lastfile = file;
00121 if (rootBuild)
00122 ROOT_newFile();
00123 if (dep == 0) {
00124 sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix,
00125 ipifile);
00126 } else {
00127 sprintf(buf, "\n%s: %s", dep,
00128 ipifile);
00129 }
00130 len = current_len = strlen(buf);
00131 } else {
00132 buf[0] = ' ';
00133 strcpy(buf + 1, ipifile);
00134 current_len += len;
00135 }
00136 if (len > 2 && ip->i_file[1] == ':')
00137 free(ipifile);
00138
00139 if (rootBuild)
00140 ROOT_adddep(buf, len);
00141 else
00142 if (fwrite(buf, len, 1, stdout) != 1)
00143 fprintf(stderr, "pr: fwrite error\n");
00144
00145
00146
00147
00148 if (! verbose || ip->i_list == NULL || ip->i_flags & NOTIFIED)
00149 return;
00150 ip->i_flags |= NOTIFIED;
00151 lastfile = NULL;
00152 printf("\n# %s includes:", ip->i_file);
00153 for (i = 0; i < ip->i_listlen; i++)
00154 printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
00155 }
00156
00157 void
00158 recursive_pr_include(head, file, base, dep)
00159 register struct inclist *head;
00160 register char *file, *base;
00161 register char *dep;
00162 {
00163 register int i;
00164
00165 if (head->i_flags & MARKED)
00166 return;
00167 head->i_flags |= MARKED;
00168 if (head->i_file != file)
00169 pr(head, file, base, dep);
00170 for (i = 0; i < head->i_listlen; i++)
00171 recursive_pr_include(head->i_list[ i ], file, base, dep);
00172 }