214 wchar_t *name_p;
215 Name alias;
216
217 /*
218 * To avoid recursive search through VPATH when exists(alias) is called
219 */
220 vpath_defined = false;
221
222 Wstring wcb(getvar(vpath_name));
223 Wstring wcb1(target);
224
225 vpath = wcb.get_string();
226
227 while (*vpath != (int) nul_char) {
228 name_p = file_name;
229 while ((*vpath != (int) colon_char) &&
230 (*vpath != (int) nul_char)) {
231 *name_p++ = *vpath++;
232 }
233 *name_p++ = (int) slash_char;
234 (void) wscpy(name_p, wcb1.get_string());
235 alias = GETNAME(file_name, FIND_LENGTH);
236 if (exists(alias) != file_doesnt_exist) {
237 target->stat.is_file = true;
238 target->stat.mode = alias->stat.mode;
239 target->stat.size = alias->stat.size;
240 target->stat.is_dir = alias->stat.is_dir;
241 target->stat.time = alias->stat.time;
242 maybe_append_prop(target, vpath_alias_prop)->
243 body.vpath_alias.alias = alias;
244 target->has_vpath_alias_prop = true;
245 vpath_defined = true;
246 return alias->stat.time;
247 }
248 while ((*vpath != (int) nul_char) &&
249 ((*vpath == (int) colon_char) || iswspace(*vpath))) {
250 vpath++;
251 }
252 }
253 /*
254 * Restore vpath_defined
307 Wstring vps;
308
309 /* A directory is only read once unless we need to expand wildcards. */
310 if (pattern == NULL) {
311 if (dir->has_read_dir) {
312 return 0;
313 }
314 dir->has_read_dir = true;
315 }
316 /* Check if VPATH is active and setup list if it is. */
317 if (vpath_defined && (dir == dot)) {
318 vps.init(getvar(vpath_name));
319 vpath = vps.get_string();
320 }
321
322 /*
323 * Prepare the string where we build the full name of the
324 * files in the directory.
325 */
326 if ((dir->hash.length > 1) || (wcb.get_string()[0] != (int) period_char)) {
327 (void) wscpy(file_name, wcb.get_string());
328 MBSTOWCS(wcs_buffer, "/");
329 (void) wscat(file_name, wcs_buffer);
330 file_name_p = file_name + wslen(file_name);
331 }
332
333 /* Open the directory. */
334 vpath_loop:
335 dir_fd = opendir(dir->string_mb);
336 if (dir_fd == NULL) {
337 return 0;
338 }
339
340 /* Read all the directory entries. */
341 while ((dp = readdir(dir_fd)) != NULL) {
342 /* We ignore "." and ".." */
343 if ((dp->d_fileno == 0) ||
344 ((dp->d_name[0] == (int) period_char) &&
345 ((dp->d_name[1] == 0) ||
346 ((dp->d_name[1] == (int) period_char) &&
347 (dp->d_name[2] == 0))))) {
348 continue;
349 }
350 /*
351 * Build the full name of the file using whatever
352 * path supplied to the function.
353 */
354 MBSTOWCS(tmp_wcs_buffer, dp->d_name);
355 (void) wscpy(file_name_p, tmp_wcs_buffer);
356 file = enter_file_name(file_name, library);
357 if ((pattern != NULL) && amatch(tmp_wcs_buffer, pattern)) {
358 /*
359 * If we are expanding a wildcard pattern, we
360 * enter the file as a dependency for the target.
361 */
362 if (debug_level > 0){
363 WCSTOMBS(mbs_buffer, pattern);
364 (void) printf(gettext("'%s: %s' due to %s expansion\n"),
365 line->body.line.target->string_mb,
366 file->string_mb,
367 mbs_buffer);
368 }
369 enter_dependency(line, file, false);
370 result++;
371 } else {
372 /*
373 * If the file has an SCCS/s. file,
374 * we will detect that later on.
375 */
376 file->stat.has_sccs = NO_SCCS;
377 /*
378 * If this is an s. file, we also enter it as if it
379 * existed in the plain directory.
380 */
381 if ((dp->d_name[0] == 's') &&
382 (dp->d_name[1] == (int) period_char)) {
383
384 MBSTOWCS(tmp_wcs_buffer, dp->d_name + 2);
385 plain_file_name_p = plain_file_name;
386 (void) wscpy(plain_file_name_p, tmp_wcs_buffer);
387 plain_file = GETNAME(plain_file_name, FIND_LENGTH);
388 plain_file->stat.is_file = true;
389 plain_file->stat.has_sccs = HAS_SCCS;
390 /*
391 * Enter the s. file as a dependency for the
392 * plain file.
393 */
394 maybe_append_prop(plain_file, sccs_prop)->
395 body.sccs.file = file;
396 MBSTOWCS(tmp_wcs_buffer, dp->d_name + 2);
397 if ((pattern != NULL) &&
398 amatch(tmp_wcs_buffer, pattern)) {
399 if (debug_level > 0) {
400 WCSTOMBS(mbs_buffer, pattern);
401 (void) printf(gettext("'%s: %s' due to %s expansion\n"),
402 line->body.line.target->
403 string_mb,
404 plain_file->string_mb,
405 mbs_buffer);
406 }
419 p = vpath;
420 while ((*vpath != (int) colon_char) &&
421 (*vpath != (int) nul_char)) {
422 vpath++;
423 }
424 if (vpath > p) {
425 dir = GETNAME(p, vpath - p);
426 goto vpath_loop;
427 }
428 }
429 /*
430 * look into SCCS directory only if it's not svr4. For svr4 dont do that.
431 */
432
433 /*
434 * Now read the SCCS directory.
435 * Files in the SCSC directory are considered to be part of the set of
436 * files in the plain directory. They are also entered in their own right.
437 * Prepare the string where we build the true name of the SCCS files.
438 */
439 (void) wsncpy(plain_file_name,
440 file_name,
441 file_name_p - file_name);
442 plain_file_name[file_name_p - file_name] = 0;
443 plain_file_name_p = plain_file_name + wslen(plain_file_name);
444
445 if(!svr4) {
446
447 if (sccs_dir_path != NULL) {
448 wchar_t tmp_wchar;
449 wchar_t path[MAXPATHLEN];
450 char mb_path[MAXPATHLEN];
451
452 if (file_name_p - file_name > 0) {
453 tmp_wchar = *file_name_p;
454 *file_name_p = 0;
455 WCSTOMBS(mbs_buffer, file_name);
456 (void) sprintf(mb_path, "%s/%s/SCCS",
457 sccs_dir_path,
458 mbs_buffer);
459 *file_name_p = tmp_wchar;
460 } else {
461 (void) sprintf(mb_path, "%s/SCCS", sccs_dir_path);
462 }
463 MBSTOWCS(path, mb_path);
464 (void) wscpy(file_name, path);
465 } else {
466 MBSTOWCS(wcs_buffer, "SCCS");
467 (void) wscpy(file_name_p, wcs_buffer);
468 }
469 } else {
470 MBSTOWCS(wcs_buffer, ".");
471 (void) wscpy(file_name_p, wcs_buffer);
472 }
473 /* Internalize the constructed SCCS dir name. */
474 (void) exists(dir = GETNAME(file_name, FIND_LENGTH));
475 /* Just give up if the directory file doesnt exist. */
476 if (!dir->stat.is_file) {
477 return result;
478 }
479 /* Open the directory. */
480 dir_fd = opendir(dir->string_mb);
481 if (dir_fd == NULL) {
482 return result;
483 }
484 MBSTOWCS(wcs_buffer, "/");
485 (void) wscat(file_name, wcs_buffer);
486 file_name_p = file_name + wslen(file_name);
487
488 while ((dp = readdir(dir_fd)) != NULL) {
489 if ((dp->d_fileno == 0) ||
490 ((dp->d_name[0] == (int) period_char) &&
491 ((dp->d_name[1] == 0) ||
492 ((dp->d_name[1] == (int) period_char) &&
493 (dp->d_name[2] == 0))))) {
494 continue;
495 }
496 /* Construct and internalize the true name of the SCCS file. */
497 MBSTOWCS(wcs_buffer, dp->d_name);
498 (void) wscpy(file_name_p, wcs_buffer);
499 file = GETNAME(file_name, FIND_LENGTH);
500 file->stat.is_file = true;
501 file->stat.has_sccs = NO_SCCS;
502 /*
503 * If this is an s. file, we also enter it as if it
504 * existed in the plain directory.
505 */
506 if ((dp->d_name[0] == 's') &&
507 (dp->d_name[1] == (int) period_char)) {
508
509 MBSTOWCS(wcs_buffer, dp->d_name + 2);
510 (void) wscpy(plain_file_name_p, wcs_buffer);
511 plain_file = GETNAME(plain_file_name, FIND_LENGTH);
512 plain_file->stat.is_file = true;
513 plain_file->stat.has_sccs = HAS_SCCS;
514 /* if sccs dependency is already set,skip */
515 if(plain_file->prop) {
516 Property sprop = get_prop(plain_file->prop,sccs_prop);
517 if(sprop != NULL) {
518 if (sprop->body.sccs.file) {
519 goto try_pattern;
520 }
521 }
522 }
523
524 /*
525 * Enter the s. file as a dependency for the
526 * plain file.
527 */
528 maybe_append_prop(plain_file, sccs_prop)->
529 body.sccs.file = file;
530 try_pattern:
|
214 wchar_t *name_p;
215 Name alias;
216
217 /*
218 * To avoid recursive search through VPATH when exists(alias) is called
219 */
220 vpath_defined = false;
221
222 Wstring wcb(getvar(vpath_name));
223 Wstring wcb1(target);
224
225 vpath = wcb.get_string();
226
227 while (*vpath != (int) nul_char) {
228 name_p = file_name;
229 while ((*vpath != (int) colon_char) &&
230 (*vpath != (int) nul_char)) {
231 *name_p++ = *vpath++;
232 }
233 *name_p++ = (int) slash_char;
234 (void) wcscpy(name_p, wcb1.get_string());
235 alias = GETNAME(file_name, FIND_LENGTH);
236 if (exists(alias) != file_doesnt_exist) {
237 target->stat.is_file = true;
238 target->stat.mode = alias->stat.mode;
239 target->stat.size = alias->stat.size;
240 target->stat.is_dir = alias->stat.is_dir;
241 target->stat.time = alias->stat.time;
242 maybe_append_prop(target, vpath_alias_prop)->
243 body.vpath_alias.alias = alias;
244 target->has_vpath_alias_prop = true;
245 vpath_defined = true;
246 return alias->stat.time;
247 }
248 while ((*vpath != (int) nul_char) &&
249 ((*vpath == (int) colon_char) || iswspace(*vpath))) {
250 vpath++;
251 }
252 }
253 /*
254 * Restore vpath_defined
307 Wstring vps;
308
309 /* A directory is only read once unless we need to expand wildcards. */
310 if (pattern == NULL) {
311 if (dir->has_read_dir) {
312 return 0;
313 }
314 dir->has_read_dir = true;
315 }
316 /* Check if VPATH is active and setup list if it is. */
317 if (vpath_defined && (dir == dot)) {
318 vps.init(getvar(vpath_name));
319 vpath = vps.get_string();
320 }
321
322 /*
323 * Prepare the string where we build the full name of the
324 * files in the directory.
325 */
326 if ((dir->hash.length > 1) || (wcb.get_string()[0] != (int) period_char)) {
327 (void) wcscpy(file_name, wcb.get_string());
328 MBSTOWCS(wcs_buffer, "/");
329 (void) wcscat(file_name, wcs_buffer);
330 file_name_p = file_name + wcslen(file_name);
331 }
332
333 /* Open the directory. */
334 vpath_loop:
335 dir_fd = opendir(dir->string_mb);
336 if (dir_fd == NULL) {
337 return 0;
338 }
339
340 /* Read all the directory entries. */
341 while ((dp = readdir(dir_fd)) != NULL) {
342 /* We ignore "." and ".." */
343 if ((dp->d_fileno == 0) ||
344 ((dp->d_name[0] == (int) period_char) &&
345 ((dp->d_name[1] == 0) ||
346 ((dp->d_name[1] == (int) period_char) &&
347 (dp->d_name[2] == 0))))) {
348 continue;
349 }
350 /*
351 * Build the full name of the file using whatever
352 * path supplied to the function.
353 */
354 MBSTOWCS(tmp_wcs_buffer, dp->d_name);
355 (void) wcscpy(file_name_p, tmp_wcs_buffer);
356 file = enter_file_name(file_name, library);
357 if ((pattern != NULL) && amatch(tmp_wcs_buffer, pattern)) {
358 /*
359 * If we are expanding a wildcard pattern, we
360 * enter the file as a dependency for the target.
361 */
362 if (debug_level > 0){
363 WCSTOMBS(mbs_buffer, pattern);
364 (void) printf(gettext("'%s: %s' due to %s expansion\n"),
365 line->body.line.target->string_mb,
366 file->string_mb,
367 mbs_buffer);
368 }
369 enter_dependency(line, file, false);
370 result++;
371 } else {
372 /*
373 * If the file has an SCCS/s. file,
374 * we will detect that later on.
375 */
376 file->stat.has_sccs = NO_SCCS;
377 /*
378 * If this is an s. file, we also enter it as if it
379 * existed in the plain directory.
380 */
381 if ((dp->d_name[0] == 's') &&
382 (dp->d_name[1] == (int) period_char)) {
383
384 MBSTOWCS(tmp_wcs_buffer, dp->d_name + 2);
385 plain_file_name_p = plain_file_name;
386 (void) wcscpy(plain_file_name_p, tmp_wcs_buffer);
387 plain_file = GETNAME(plain_file_name, FIND_LENGTH);
388 plain_file->stat.is_file = true;
389 plain_file->stat.has_sccs = HAS_SCCS;
390 /*
391 * Enter the s. file as a dependency for the
392 * plain file.
393 */
394 maybe_append_prop(plain_file, sccs_prop)->
395 body.sccs.file = file;
396 MBSTOWCS(tmp_wcs_buffer, dp->d_name + 2);
397 if ((pattern != NULL) &&
398 amatch(tmp_wcs_buffer, pattern)) {
399 if (debug_level > 0) {
400 WCSTOMBS(mbs_buffer, pattern);
401 (void) printf(gettext("'%s: %s' due to %s expansion\n"),
402 line->body.line.target->
403 string_mb,
404 plain_file->string_mb,
405 mbs_buffer);
406 }
419 p = vpath;
420 while ((*vpath != (int) colon_char) &&
421 (*vpath != (int) nul_char)) {
422 vpath++;
423 }
424 if (vpath > p) {
425 dir = GETNAME(p, vpath - p);
426 goto vpath_loop;
427 }
428 }
429 /*
430 * look into SCCS directory only if it's not svr4. For svr4 dont do that.
431 */
432
433 /*
434 * Now read the SCCS directory.
435 * Files in the SCSC directory are considered to be part of the set of
436 * files in the plain directory. They are also entered in their own right.
437 * Prepare the string where we build the true name of the SCCS files.
438 */
439 (void) wcsncpy(plain_file_name,
440 file_name,
441 file_name_p - file_name);
442 plain_file_name[file_name_p - file_name] = 0;
443 plain_file_name_p = plain_file_name + wcslen(plain_file_name);
444
445 if(!svr4) {
446
447 if (sccs_dir_path != NULL) {
448 wchar_t tmp_wchar;
449 wchar_t path[MAXPATHLEN];
450 char mb_path[MAXPATHLEN];
451
452 if (file_name_p - file_name > 0) {
453 tmp_wchar = *file_name_p;
454 *file_name_p = 0;
455 WCSTOMBS(mbs_buffer, file_name);
456 (void) sprintf(mb_path, "%s/%s/SCCS",
457 sccs_dir_path,
458 mbs_buffer);
459 *file_name_p = tmp_wchar;
460 } else {
461 (void) sprintf(mb_path, "%s/SCCS", sccs_dir_path);
462 }
463 MBSTOWCS(path, mb_path);
464 (void) wcscpy(file_name, path);
465 } else {
466 MBSTOWCS(wcs_buffer, "SCCS");
467 (void) wcscpy(file_name_p, wcs_buffer);
468 }
469 } else {
470 MBSTOWCS(wcs_buffer, ".");
471 (void) wcscpy(file_name_p, wcs_buffer);
472 }
473 /* Internalize the constructed SCCS dir name. */
474 (void) exists(dir = GETNAME(file_name, FIND_LENGTH));
475 /* Just give up if the directory file doesnt exist. */
476 if (!dir->stat.is_file) {
477 return result;
478 }
479 /* Open the directory. */
480 dir_fd = opendir(dir->string_mb);
481 if (dir_fd == NULL) {
482 return result;
483 }
484 MBSTOWCS(wcs_buffer, "/");
485 (void) wcscat(file_name, wcs_buffer);
486 file_name_p = file_name + wcslen(file_name);
487
488 while ((dp = readdir(dir_fd)) != NULL) {
489 if ((dp->d_fileno == 0) ||
490 ((dp->d_name[0] == (int) period_char) &&
491 ((dp->d_name[1] == 0) ||
492 ((dp->d_name[1] == (int) period_char) &&
493 (dp->d_name[2] == 0))))) {
494 continue;
495 }
496 /* Construct and internalize the true name of the SCCS file. */
497 MBSTOWCS(wcs_buffer, dp->d_name);
498 (void) wcscpy(file_name_p, wcs_buffer);
499 file = GETNAME(file_name, FIND_LENGTH);
500 file->stat.is_file = true;
501 file->stat.has_sccs = NO_SCCS;
502 /*
503 * If this is an s. file, we also enter it as if it
504 * existed in the plain directory.
505 */
506 if ((dp->d_name[0] == 's') &&
507 (dp->d_name[1] == (int) period_char)) {
508
509 MBSTOWCS(wcs_buffer, dp->d_name + 2);
510 (void) wcscpy(plain_file_name_p, wcs_buffer);
511 plain_file = GETNAME(plain_file_name, FIND_LENGTH);
512 plain_file->stat.is_file = true;
513 plain_file->stat.has_sccs = HAS_SCCS;
514 /* if sccs dependency is already set,skip */
515 if(plain_file->prop) {
516 Property sprop = get_prop(plain_file->prop,sccs_prop);
517 if(sprop != NULL) {
518 if (sprop->body.sccs.file) {
519 goto try_pattern;
520 }
521 }
522 }
523
524 /*
525 * Enter the s. file as a dependency for the
526 * plain file.
527 */
528 maybe_append_prop(plain_file, sccs_prop)->
529 body.sccs.file = file;
530 try_pattern:
|