295 changed = true;
296 if(rp->target) {
297 retmem(rp->target);
298 rp->target = NULL;
299 }
300 if(rp->newline) {
301 retmem(rp->newline);
302 rp->newline = NULL;
303 }
304 if(rp->oldline) {
305 retmem(rp->oldline);
306 rp->oldline = NULL;
307 }
308 if(rp->cond_macrostring) {
309 retmem(rp->cond_macrostring);
310 rp->cond_macrostring = NULL;
311 }
312 }
313 }
314
315 #ifdef NSE
316 /*
317 * report_recursive_done()
318 *
319 * Write the .nse_depinfo file.
320 *
321 * Parameters:
322 *
323 * Static variables used:
324 * recursive_list The list of targets
325 * changed Written if report set changed
326 *
327 * Global variables used:
328 * recursive_name The Name ".RECURSIVE", compared against
329 */
330 void
331 report_recursive_done(void)
332 {
333 char *search_dir;
334 char nse_depinfo[MAXPATHLEN];
335 char tmpfile[MAXPATHLEN];
336 FILE *ofp;
337 FILE *ifp;
338 wchar_t *space;
339 wchar_t *data;
340 wchar_t *line;
341 wchar_t *bigger_line;
342 int line_size, line_index;
343 int lock_err;
344 Recursive_make rp;
345
346 if (changed == false) {
347 return;
348 }
349
350 search_dir = getenv(NOCATGETS("NSE_DEP"));
351 if (search_dir == NULL) {
352 return;
353 }
354 (void) sprintf(nse_depinfo, "%s/%s", search_dir, NSE_DEPINFO);
355 (void) sprintf(tmpfile, "%s.%d", nse_depinfo, getpid());
356 ofp = fopen(tmpfile, "w");
357 if (ofp == NULL) {
358 (void) fprintf(stderr,
359 catgets(catd, 1, 116, "Cannot open `%s' for writing\n"),
360 tmpfile);
361 return;
362 }
363 (void) sprintf(nse_depinfo_lockfile,
364 "%s/%s", search_dir, NSE_DEPINFO_LOCK);
365 if (lock_err = file_lock(nse_depinfo,
366 nse_depinfo_lockfile,
367 (int *) &nse_depinfo_locked, 0)) {
368 (void) fprintf(stderr,
369 catgets(catd, 1, 117, "writing .RECURSIVE lines to %s\n"),
370 tmpfile);
371 (void) fprintf(stderr,
372 catgets(catd, 1, 118, "To recover, merge .nse_depinfo.%d with .nse_depinfo\n"),
373 getpid(),
374 catgets(catd, 1, 119, "with .nse_depinfo"));
375 }
376
377 if (nse_depinfo_locked) {
378 ifp = fopen(nse_depinfo, "r");
379 if (ifp != NULL) {
380 /*
381 * Copy all the non-.RECURSIVE lines from
382 * the old file to the new one.
383 */
384 line_size = MAXPATHLEN;
385 line_index = line_size - 1;
386 line = ALLOC_WC(line_size);
387 while (fgetws(line, line_size, ifp) != NULL) {
388 while (wslen(line) == line_index) {
389 if (line[wslen(line) - 1] == '\n') {
390 continue;
391 }
392 bigger_line = ALLOC_WC(2 * line_size);
393 wscpy(bigger_line, line);
394 retmem(line);
395 line = bigger_line;
396 if (fgetws(&line[line_index],
397 line_size, ifp) == NULL)
398 continue;
399 line_index = 2 * line_index;
400 line_size = 2 * line_size;
401 }
402
403 space = wschr(line, (int) space_char);
404 if (space != NULL &&
405 IS_WEQUALN(&space[1],
406 recursive_name->string,
407 (int) recursive_name->hash.length)) {
408 continue;
409 }
410 WCSTOMBS(mbs_buffer, line);
411 (void) fprintf(ofp, "%s", mbs_buffer);
412 }
413 (void) fclose(ifp);
414 }
415 }
416
417 /*
418 * Write out the .RECURSIVE lines.
419 */
420 for (rp = recursive_list; rp != NULL; rp = rp->next) {
421 if (rp->removed) {
422 continue;
423 }
424 if (rp->newline != NULL) {
425 data = rp->newline;
426 } else {
427 data = rp->oldline;
428 }
429 if (data != NULL) {
430 WCSTOMBS(mbs_buffer, data);
431 (void) fprintf(ofp, "%s\n", mbs_buffer);
432 }
433 }
434 (void) fclose(ofp);
435
436 if (nse_depinfo_locked) {
437 (void) rename(tmpfile, nse_depinfo);
438 (void) unlink(nse_depinfo_lockfile);
439 nse_depinfo_locked = false;
440 nse_depinfo_lockfile[0] = '\0';
441 (void) chmod(nse_depinfo, 0666);
442 }
443 }
444 #endif // NSE
445
446 /* gather_recursive_deps()
447 *
448 * Create or update list of recursive targets.
449 */
450 void
451 gather_recursive_deps(void)
452 {
453 Name_set::iterator np, e;
454 String_rec rec;
455 wchar_t rec_buf[STRING_BUFFER_LENGTH];
456 register Property lines;
457 Boolean has_recursive;
458 Dependency dp;
459
460 report_recursive_init();
461
462 /* Go thru all targets and dump recursive dependencies */
463 for (np = hashtab.begin(), e = hashtab.end(); np != e; np++) {
464 if (np->has_recursive_dependency){
|
295 changed = true;
296 if(rp->target) {
297 retmem(rp->target);
298 rp->target = NULL;
299 }
300 if(rp->newline) {
301 retmem(rp->newline);
302 rp->newline = NULL;
303 }
304 if(rp->oldline) {
305 retmem(rp->oldline);
306 rp->oldline = NULL;
307 }
308 if(rp->cond_macrostring) {
309 retmem(rp->cond_macrostring);
310 rp->cond_macrostring = NULL;
311 }
312 }
313 }
314
315
316 /* gather_recursive_deps()
317 *
318 * Create or update list of recursive targets.
319 */
320 void
321 gather_recursive_deps(void)
322 {
323 Name_set::iterator np, e;
324 String_rec rec;
325 wchar_t rec_buf[STRING_BUFFER_LENGTH];
326 register Property lines;
327 Boolean has_recursive;
328 Dependency dp;
329
330 report_recursive_init();
331
332 /* Go thru all targets and dump recursive dependencies */
333 for (np = hashtab.begin(), e = hashtab.end(); np != e; np++) {
334 if (np->has_recursive_dependency){
|