File indexing completed on 2018-03-02 18:44:43 UTC
view on githubraw file Latest commit bf5846c3 on 2004-02-25 18:19:54 UTC
bf5846c3a1 Ed H*0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071 #include "def.h"
0072
0073 extern struct inclist inclist[ MAXFILES ],
0074 *inclistp;
0075 extern char *includedirs[ ];
0076 extern char *notdotdot[ ];
0077 extern boolean show_where_not;
0078 extern boolean warn_multiple;
0079
0080 struct inclist *inc_path(file, include, dot)
0081 register char *file,
0082 *include;
0083 boolean dot;
0084 {
0085 static char path[ BUFSIZ ];
0086 register char **pp, *p;
0087 register struct inclist *ip;
0088 struct stat st;
0089 boolean found = FALSE;
0090
0091
0092
0093
0094
0095 for (ip = inclist; ip->i_file; ip++)
0096 if ((strcmp(ip->i_incstring, include) == 0) && !ip->i_included_sym)
0097 {
0098 found = TRUE;
0099 break;
0100 }
0101
0102
0103
0104
0105
0106 if (!found && (dot || *include == '/')) {
0107 if (stat(include, &st) == 0) {
0108 ip = newinclude(include, include);
0109 found = TRUE;
0110 }
0111 else if (show_where_not)
0112 warning1("\tnot in %s\n", include);
0113 }
0114
0115
0116
0117
0118
0119 if (!found) {
0120 for (p=file+strlen(file); p>file; p--)
0121 if (*p == '/')
0122 break;
0123 if (p == file)
0124 strcpy(path, include);
0125 else {
0126 strncpy(path, file, (p-file) + 1);
0127 path[ (p-file) + 1 ] = '\0';
0128 strcpy(path + (p-file) + 1, include);
0129 }
0130 remove_dotdot(path);
0131 if (stat(path, &st) == 0) {
0132 ip = newinclude(path, include);
0133 found = TRUE;
0134 }
0135 else if (show_where_not)
0136 warning1("\tnot in %s\n", path);
0137 }
0138
0139
0140
0141
0142
0143 if (!found)
0144 for (pp = includedirs; *pp; pp++) {
0145 sprintf(path, "%s/%s", *pp, include);
0146 remove_dotdot(path);
0147 if (stat(path, &st) == 0) {
0148 ip = newinclude(path, include);
0149 found = TRUE;
0150 break;
0151 }
0152 else if (show_where_not)
0153 warning1("\tnot in %s\n", path);
0154 }
0155
0156 if (!found)
0157 ip = NULL;
0158 return(ip);
0159 }
0160
0161
0162
0163
0164
0165
0166 remove_dotdot(path)
0167 char *path;
0168 {
0169 register char *end, *from, *to, **cp;
0170 char *components[ MAXFILES ],
0171 newpath[ BUFSIZ ];
0172 boolean component_copied;
0173
0174
0175
0176
0177 to = newpath;
0178 if (*path == '/')
0179 *to++ = '/';
0180 *to = '\0';
0181 cp = components;
0182 for (from=end=path; *end; end++)
0183 if (*end == '/') {
0184 while (*end == '/')
0185 *end++ = '\0';
0186 if (*from)
0187 *cp++ = from;
0188 from = end;
0189 }
0190 *cp++ = from;
0191 *cp = NULL;
0192
0193
0194
0195
0196 cp = components;
0197 component_copied = FALSE;
0198 while(*cp) {
0199 if (!isdot(*cp) && !isdotdot(*cp) && isdotdot(*(cp+1))) {
0200 if (issymbolic(newpath, *cp))
0201 goto dont_remove;
0202 cp++;
0203 } else {
0204 dont_remove:
0205 if (component_copied)
0206 *to++ = '/';
0207 component_copied = TRUE;
0208 for (from = *cp; *from; )
0209 *to++ = *from++;
0210 *to = '\0';
0211 }
0212 cp++;
0213 }
0214 *to++ = '\0';
0215
0216
0217
0218
0219 strcpy(path, newpath);
0220 }
0221
0222 isdot(p)
0223 register char *p;
0224 {
0225 if(p && *p++ == '.' && *p++ == '\0')
0226 return(TRUE);
0227 return(FALSE);
0228 }
0229
0230 isdotdot(p)
0231 register char *p;
0232 {
0233 if(p && *p++ == '.' && *p++ == '.' && *p++ == '\0')
0234 return(TRUE);
0235 return(FALSE);
0236 }
0237
0238 issymbolic(dir, component)
0239 register char *dir, *component;
0240 {
0241 #ifdef S_IFLNK
0242 struct stat st;
0243 char buf[ BUFSIZ ], **pp;
0244
0245 sprintf(buf, "%s%s%s", dir, *dir ? "/" : "", component);
0246 for (pp=notdotdot; *pp; pp++)
0247 if (strcmp(*pp, buf) == 0)
0248 return (TRUE);
0249 if (lstat(buf, &st) == 0
0250 && (st.st_mode & S_IFMT) == S_IFLNK) {
0251 *pp++ = copy(buf);
0252 if (pp >= ¬dotdot[ MAXDIRS ])
0253 fatalerr("out of .. dirs, increase MAXDIRS\n");
0254 return(TRUE);
0255 }
0256 #endif
0257 return(FALSE);
0258 }
0259
0260
0261
0262
0263 struct inclist *newinclude(newfile, incstring)
0264 register char *newfile, *incstring;
0265 {
0266 register struct inclist *ip;
0267
0268
0269
0270
0271 ip = inclistp++;
0272 if (inclistp == inclist + MAXFILES - 1)
0273 fatalerr("out of space: increase MAXFILES\n");
0274 ip->i_file = copy(newfile);
0275 ip->i_included_sym = FALSE;
0276 if (incstring == NULL)
0277 ip->i_incstring = ip->i_file;
0278 else
0279 ip->i_incstring = copy(incstring);
0280
0281 return(ip);
0282 }
0283
0284 included_by(ip, newfile)
0285 register struct inclist *ip, *newfile;
0286 {
0287 register i;
0288
0289 if (ip == NULL)
0290 return;
0291
0292
0293
0294
0295
0296
0297 if (ip->i_list == NULL)
0298 ip->i_list = (struct inclist **)
0299 malloc(sizeof(struct inclist *) * ++ip->i_listlen);
0300 else {
0301 for (i=0; i<ip->i_listlen; i++)
0302 if (ip->i_list[ i ] == newfile) {
0303 i = strlen(newfile->i_file);
0304 if (!ip->i_included_sym &&
0305 !(i > 2 &&
0306 newfile->i_file[i-1] == 'c' &&
0307 newfile->i_file[i-2] == '.'))
0308 {
0309
0310
0311
0312 if (warn_multiple)
0313 {
0314 warning("%s includes %s more than once!\n",
0315 ip->i_file, newfile->i_file);
0316 warning1("Already have\n");
0317 for (i=0; i<ip->i_listlen; i++)
0318 warning1("\t%s\n", ip->i_list[i]->i_file);
0319 }
0320 }
0321 return;
0322 }
0323 ip->i_list = (struct inclist **) realloc(ip->i_list,
0324 sizeof(struct inclist *) * ++ip->i_listlen);
0325 }
0326 ip->i_list[ ip->i_listlen-1 ] = newfile;
0327 }
0328
0329 inc_clean ()
0330 {
0331 register struct inclist *ip;
0332
0333 for (ip = inclist; ip < inclistp; ip++) {
0334 ip->i_marked = FALSE;
0335 }
0336 }