1 /* 2 * Copyright (c) 1998, 1999 Matthew R. Green 3 * All rights reserved. 4 * Copyright (c) 1998 5 * Perry E. Metzger. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed for the NetBSD Project 18 * by Perry E. Metzger. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 * $NetBSD: rcorder.c,v 1.7 2000/08/04 07:33:55 enami Exp $ 34 * $DragonFly: src/sbin/rcorder/rcorder.c,v 1.1 2003/07/24 06:35:38 dillon Exp $ 35 */ 36 37 #include <sys/types.h> 38 #include <sys/stat.h> 39 40 #include <err.h> 41 #include <stdio.h> 42 #include <stdlib.h> 43 #include <string.h> 44 #include <unistd.h> 45 #include <util.h> 46 47 #include "ealloc.h" 48 #include "sprite.h" 49 #include "hash.h" 50 51 #ifdef DEBUG 52 int debug = 0; 53 # define DPRINTF(args) if (debug) { fflush(stdout); fprintf args; } 54 #else 55 # define DPRINTF(args) 56 #endif 57 58 #define REQUIRE_STR "# REQUIRE:" 59 #define REQUIRE_LEN (sizeof(REQUIRE_STR) - 1) 60 #define REQUIRES_STR "# REQUIRES:" 61 #define REQUIRES_LEN (sizeof(REQUIRES_STR) - 1) 62 #define PROVIDE_STR "# PROVIDE:" 63 #define PROVIDE_LEN (sizeof(PROVIDE_STR) - 1) 64 #define PROVIDES_STR "# PROVIDES:" 65 #define PROVIDES_LEN (sizeof(PROVIDES_STR) - 1) 66 #define BEFORE_STR "# BEFORE:" 67 #define BEFORE_LEN (sizeof(BEFORE_STR) - 1) 68 #define KEYWORD_STR "# KEYWORD:" 69 #define KEYWORD_LEN (sizeof(KEYWORD_STR) - 1) 70 #define KEYWORDS_STR "# KEYWORDS:" 71 #define KEYWORDS_LEN (sizeof(KEYWORDS_STR) - 1) 72 73 int exit_code; 74 int file_count; 75 char **file_list; 76 77 typedef int bool; 78 #define TRUE 1 79 #define FALSE 0 80 typedef bool flag; 81 #define SET TRUE 82 #define RESET FALSE 83 84 Hash_Table provide_hash_s, *provide_hash; 85 86 typedef struct provnode provnode; 87 typedef struct filenode filenode; 88 typedef struct f_provnode f_provnode; 89 typedef struct f_reqnode f_reqnode; 90 typedef struct strnodelist strnodelist; 91 92 struct provnode { 93 flag head; 94 flag in_progress; 95 filenode *fnode; 96 provnode *next, *last; 97 }; 98 99 struct f_provnode { 100 provnode *pnode; 101 f_provnode *next; 102 }; 103 104 struct f_reqnode { 105 Hash_Entry *entry; 106 f_reqnode *next; 107 }; 108 109 struct strnodelist { 110 filenode *node; 111 strnodelist *next; 112 char s[1]; 113 }; 114 115 struct filenode { 116 char *filename; 117 flag in_progress; 118 filenode *next, *last; 119 f_reqnode *req_list; 120 f_provnode *prov_list; 121 strnodelist *keyword_list; 122 }; 123 124 filenode fn_head_s, *fn_head; 125 126 strnodelist *bl_list; 127 strnodelist *keep_list; 128 strnodelist *skip_list; 129 130 void do_file __P((filenode *fnode)); 131 void strnode_add __P((strnodelist **, char *, filenode *)); 132 int skip_ok __P((filenode *fnode)); 133 int keep_ok __P((filenode *fnode)); 134 void satisfy_req __P((f_reqnode *rnode, char *filename)); 135 void crunch_file __P((char *)); 136 void parse_require __P((filenode *, char *)); 137 void parse_provide __P((filenode *, char *)); 138 void parse_before __P((filenode *, char *)); 139 void parse_keywords __P((filenode *, char *)); 140 filenode *filenode_new __P((char *)); 141 void add_require __P((filenode *, char *)); 142 void add_provide __P((filenode *, char *)); 143 void add_before __P((filenode *, char *)); 144 void add_keyword __P((filenode *, char *)); 145 void insert_before __P((void)); 146 Hash_Entry *make_fake_provision __P((filenode *)); 147 void crunch_all_files __P((void)); 148 void initialize __P((void)); 149 void generate_ordering __P((void)); 150 int main __P((int, char *[])); 151 152 int 153 main(argc, argv) 154 int argc; 155 char *argv[]; 156 { 157 int ch; 158 159 while ((ch = getopt(argc, argv, "dk:s:")) != -1) 160 switch (ch) { 161 case 'd': 162 #ifdef DEBUG 163 debug = 1; 164 #else 165 warnx("debugging not compiled in, -d ignored"); 166 #endif 167 break; 168 case 'k': 169 strnode_add(&keep_list, optarg, 0); 170 break; 171 case 's': 172 strnode_add(&skip_list, optarg, 0); 173 break; 174 default: 175 /* XXX should crunch it? */ 176 break; 177 } 178 argc -= optind; 179 argv += optind; 180 181 file_count = argc; 182 file_list = argv; 183 184 DPRINTF((stderr, "parse_args\n")); 185 initialize(); 186 DPRINTF((stderr, "initialize\n")); 187 crunch_all_files(); 188 DPRINTF((stderr, "crunch_all_files\n")); 189 generate_ordering(); 190 DPRINTF((stderr, "generate_ordering\n")); 191 192 exit(exit_code); 193 } 194 195 /* 196 * initialise various variables. 197 */ 198 void 199 initialize() 200 { 201 202 fn_head = &fn_head_s; 203 204 provide_hash = &provide_hash_s; 205 Hash_InitTable(provide_hash, file_count); 206 } 207 208 /* generic function to insert a new strnodelist element */ 209 void 210 strnode_add(listp, s, fnode) 211 strnodelist **listp; 212 char *s; 213 filenode *fnode; 214 { 215 strnodelist *ent; 216 217 ent = emalloc(sizeof *ent + strlen(s)); 218 ent->node = fnode; 219 strcpy(ent->s, s); 220 ent->next = *listp; 221 *listp = ent; 222 } 223 224 /* 225 * below are the functions that deal with creating the lists 226 * from the filename's given and the dependancies and provisions 227 * in each of these files. no ordering or checking is done here. 228 */ 229 230 /* 231 * we have a new filename, create a new filenode structure. 232 * fill in the bits, and put it in the filenode linked list 233 */ 234 filenode * 235 filenode_new(filename) 236 char *filename; 237 { 238 filenode *temp; 239 240 temp = emalloc(sizeof(*temp)); 241 memset(temp, 0, sizeof(*temp)); 242 temp->filename = estrdup(filename); 243 temp->req_list = NULL; 244 temp->prov_list = NULL; 245 temp->keyword_list = NULL; 246 temp->in_progress = RESET; 247 /* 248 * link the filenode into the list of filenodes. 249 * note that the double linking means we can delete a 250 * filenode without searching for where it belongs. 251 */ 252 temp->next = fn_head->next; 253 if (temp->next != NULL) 254 temp->next->last = temp; 255 temp->last = fn_head; 256 fn_head->next = temp; 257 return (temp); 258 } 259 260 /* 261 * add a requirement to a filenode. 262 */ 263 void 264 add_require(fnode, s) 265 filenode *fnode; 266 char *s; 267 { 268 Hash_Entry *entry; 269 f_reqnode *rnode; 270 int new; 271 272 entry = Hash_CreateEntry(provide_hash, s, &new); 273 if (new) 274 Hash_SetValue(entry, NULL); 275 rnode = emalloc(sizeof(*rnode)); 276 rnode->entry = entry; 277 rnode->next = fnode->req_list; 278 fnode->req_list = rnode; 279 } 280 281 /* 282 * add a provision to a filenode. if this provision doesn't 283 * have a head node, create one here. 284 */ 285 void 286 add_provide(fnode, s) 287 filenode *fnode; 288 char *s; 289 { 290 Hash_Entry *entry; 291 f_provnode *f_pnode; 292 provnode *pnode, *head; 293 int new; 294 295 entry = Hash_CreateEntry(provide_hash, s, &new); 296 head = Hash_GetValue(entry); 297 298 /* create a head node if necessary. */ 299 if (head == NULL) { 300 head = emalloc(sizeof(*head)); 301 head->head = SET; 302 head->in_progress = RESET; 303 head->fnode = NULL; 304 head->last = head->next = NULL; 305 Hash_SetValue(entry, head); 306 } 307 #if 0 308 /* 309 * Don't warn about this. We want to be able to support 310 * scripts that do two complex things: 311 * 312 * - Two independent scripts which both provide the 313 * same thing. Both scripts must be executed in 314 * any order to meet the barrier. An example: 315 * 316 * Script 1: 317 * 318 * PROVIDE: mail 319 * REQUIRE: LOGIN 320 * 321 * Script 2: 322 * 323 * PROVIDE: mail 324 * REQUIRE: LOGIN 325 * 326 * - Two interdependent scripts which both provide the 327 * same thing. Both scripts must be executed in 328 * graph order to meet the barrier. An example: 329 * 330 * Script 1: 331 * 332 * PROVIDE: nameservice dnscache 333 * REQUIRE: SERVERS 334 * 335 * Script 2: 336 * 337 * PROVIDE: nameservice nscd 338 * REQUIRE: dnscache 339 */ 340 else if (new == 0) { 341 warnx("file `%s' provides `%s'.", fnode->filename, s); 342 warnx("\tpreviously seen in `%s'.", 343 head->next->fnode->filename); 344 } 345 #endif 346 347 pnode = emalloc(sizeof(*pnode)); 348 pnode->head = RESET; 349 pnode->in_progress = RESET; 350 pnode->fnode = fnode; 351 pnode->next = head->next; 352 pnode->last = head; 353 head->next = pnode; 354 if (pnode->next != NULL) 355 pnode->next->last = pnode; 356 357 f_pnode = emalloc(sizeof(*f_pnode)); 358 f_pnode->pnode = pnode; 359 f_pnode->next = fnode->prov_list; 360 fnode->prov_list = f_pnode; 361 } 362 363 /* 364 * put the BEFORE: lines to a list and handle them later. 365 */ 366 void 367 add_before(fnode, s) 368 filenode *fnode; 369 char *s; 370 { 371 strnodelist *bf_ent; 372 373 bf_ent = emalloc(sizeof *bf_ent + strlen(s)); 374 bf_ent->node = fnode; 375 strcpy(bf_ent->s, s); 376 bf_ent->next = bl_list; 377 bl_list = bf_ent; 378 } 379 380 /* 381 * add a key to a filenode. 382 */ 383 void 384 add_keyword(fnode, s) 385 filenode *fnode; 386 char *s; 387 { 388 389 strnode_add(&fnode->keyword_list, s, fnode); 390 } 391 392 /* 393 * loop over the rest of a REQUIRE line, giving each word to 394 * add_require() to do the real work. 395 */ 396 void 397 parse_require(node, buffer) 398 filenode *node; 399 char *buffer; 400 { 401 char *s; 402 403 while ((s = strsep(&buffer, " \t\n")) != NULL) 404 if (*s != '\0') 405 add_require(node, s); 406 } 407 408 /* 409 * loop over the rest of a PROVIDE line, giving each word to 410 * add_provide() to do the real work. 411 */ 412 void 413 parse_provide(node, buffer) 414 filenode *node; 415 char *buffer; 416 { 417 char *s; 418 419 while ((s = strsep(&buffer, " \t\n")) != NULL) 420 if (*s != '\0') 421 add_provide(node, s); 422 } 423 424 /* 425 * loop over the rest of a BEFORE line, giving each word to 426 * add_before() to do the real work. 427 */ 428 void 429 parse_before(node, buffer) 430 filenode *node; 431 char *buffer; 432 { 433 char *s; 434 435 while ((s = strsep(&buffer, " \t\n")) != NULL) 436 if (*s != '\0') 437 add_before(node, s); 438 } 439 440 /* 441 * loop over the rest of a KEYWORD line, giving each word to 442 * add_keyword() to do the real work. 443 */ 444 void 445 parse_keywords(node, buffer) 446 filenode *node; 447 char *buffer; 448 { 449 char *s; 450 451 while ((s = strsep(&buffer, " \t\n")) != NULL) 452 if (*s != '\0') 453 add_keyword(node, s); 454 } 455 456 /* 457 * given a file name, create a filenode for it, read in lines looking 458 * for provision and requirement lines, building the graphs as needed. 459 */ 460 void 461 crunch_file(filename) 462 char *filename; 463 { 464 FILE *fp; 465 char *buf; 466 int require_flag, provide_flag, before_flag, keywords_flag; 467 enum { BEFORE_PARSING, PARSING, PARSING_DONE } state; 468 filenode *node; 469 char delims[3] = { '\\', '\\', '\0' }; 470 struct stat st; 471 472 if ((fp = fopen(filename, "r")) == NULL) { 473 warn("could not open %s", filename); 474 return; 475 } 476 477 if (fstat(fileno(fp), &st) == -1) { 478 warn("could not stat %s", filename); 479 fclose(fp); 480 return; 481 } 482 483 if (!S_ISREG(st.st_mode)) { 484 #if 0 485 warnx("%s is not a file", filename); 486 #endif 487 fclose(fp); 488 return; 489 } 490 491 node = filenode_new(filename); 492 493 /* 494 * we don't care about length, line number, don't want # for comments, 495 * and have no flags. 496 */ 497 for (state = BEFORE_PARSING; state != PARSING_DONE && 498 (buf = fparseln(fp, NULL, NULL, delims, 0)) != NULL; free(buf)) { 499 require_flag = provide_flag = before_flag = keywords_flag = 0; 500 if (strncmp(REQUIRE_STR, buf, REQUIRE_LEN) == 0) 501 require_flag = REQUIRE_LEN; 502 else if (strncmp(REQUIRES_STR, buf, REQUIRES_LEN) == 0) 503 require_flag = REQUIRES_LEN; 504 else if (strncmp(PROVIDE_STR, buf, PROVIDE_LEN) == 0) 505 provide_flag = PROVIDE_LEN; 506 else if (strncmp(PROVIDES_STR, buf, PROVIDES_LEN) == 0) 507 provide_flag = PROVIDES_LEN; 508 else if (strncmp(BEFORE_STR, buf, BEFORE_LEN) == 0) 509 before_flag = BEFORE_LEN; 510 else if (strncmp(KEYWORD_STR, buf, KEYWORD_LEN) == 0) 511 keywords_flag = KEYWORD_LEN; 512 else if (strncmp(KEYWORDS_STR, buf, KEYWORDS_LEN) == 0) 513 keywords_flag = KEYWORDS_LEN; 514 else { 515 if (state == PARSING) 516 state = PARSING_DONE; 517 continue; 518 } 519 520 state = PARSING; 521 if (require_flag) 522 parse_require(node, buf + require_flag); 523 else if (provide_flag) 524 parse_provide(node, buf + provide_flag); 525 else if (before_flag) 526 parse_before(node, buf + before_flag); 527 else if (keywords_flag) 528 parse_keywords(node, buf + keywords_flag); 529 } 530 fclose(fp); 531 } 532 533 Hash_Entry * 534 make_fake_provision(node) 535 filenode *node; 536 { 537 Hash_Entry *entry; 538 f_provnode *f_pnode; 539 provnode *head, *pnode; 540 static int i = 0; 541 int new; 542 char buffer[30]; 543 544 do { 545 snprintf(buffer, sizeof buffer, "fake_prov_%08d", i++); 546 entry = Hash_CreateEntry(provide_hash, buffer, &new); 547 } while (new == 0); 548 head = emalloc(sizeof(*head)); 549 head->head = SET; 550 head->in_progress = RESET; 551 head->fnode = NULL; 552 head->last = head->next = NULL; 553 Hash_SetValue(entry, head); 554 555 pnode = emalloc(sizeof(*pnode)); 556 pnode->head = RESET; 557 pnode->in_progress = RESET; 558 pnode->fnode = node; 559 pnode->next = head->next; 560 pnode->last = head; 561 head->next = pnode; 562 if (pnode->next != NULL) 563 pnode->next->last = pnode; 564 565 f_pnode = emalloc(sizeof(*f_pnode)); 566 f_pnode->pnode = pnode; 567 f_pnode->next = node->prov_list; 568 node->prov_list = f_pnode; 569 570 return (entry); 571 } 572 573 /* 574 * go through the BEFORE list, inserting requirements into the graph(s) 575 * as required. in the before list, for each entry B, we have a file F 576 * and a string S. we create a "fake" provision (P) that F provides. 577 * for each entry in the provision list for S, add a requirement to 578 * that provisions filenode for P. 579 */ 580 void 581 insert_before() 582 { 583 Hash_Entry *entry, *fake_prov_entry; 584 provnode *pnode; 585 f_reqnode *rnode; 586 strnodelist *bl; 587 int new; 588 589 while (bl_list != NULL) { 590 bl = bl_list->next; 591 592 fake_prov_entry = make_fake_provision(bl_list->node); 593 594 entry = Hash_CreateEntry(provide_hash, bl_list->s, &new); 595 if (new == 1) 596 warnx("file `%s' is before unknown provision `%s'", bl_list->node->filename, bl_list->s); 597 598 for (pnode = Hash_GetValue(entry); pnode; pnode = pnode->next) { 599 if (pnode->head) 600 continue; 601 602 rnode = emalloc(sizeof(*rnode)); 603 rnode->entry = fake_prov_entry; 604 rnode->next = pnode->fnode->req_list; 605 pnode->fnode->req_list = rnode; 606 } 607 608 free(bl_list); 609 bl_list = bl; 610 } 611 } 612 613 /* 614 * loop over all the files calling crunch_file() on them to do the 615 * real work. after we have built all the nodes, insert the BEFORE: 616 * lines into graph(s). 617 */ 618 void 619 crunch_all_files() 620 { 621 int i; 622 623 for (i = 0; i < file_count; i++) 624 crunch_file(file_list[i]); 625 insert_before(); 626 } 627 628 /* 629 * below are the functions that traverse the graphs we have built 630 * finding out the desired ordering, printing each file in turn. 631 * if missing requirements, or cyclic graphs are detected, a 632 * warning will be issued, and we will continue on.. 633 */ 634 635 /* 636 * given a requirement node (in a filename) we attempt to satisfy it. 637 * we do some sanity checking first, to ensure that we have providers, 638 * aren't already satisfied and aren't already being satisfied (ie, 639 * cyclic). if we pass all this, we loop over the provision list 640 * calling do_file() (enter recursion) for each filenode in this 641 * provision. 642 */ 643 void 644 satisfy_req(rnode, filename) 645 f_reqnode *rnode; 646 char *filename; 647 { 648 Hash_Entry *entry; 649 provnode *head; 650 651 entry = rnode->entry; 652 head = Hash_GetValue(entry); 653 654 if (head == NULL) { 655 warnx("requirement `%s' in file `%s' has no providers.", 656 Hash_GetKey(entry), filename); 657 exit_code = 1; 658 return; 659 } 660 661 /* return if the requirement is already satisfied. */ 662 if (head->next == NULL) 663 return; 664 665 /* 666 * if list is marked as in progress, 667 * print that there is a circular dependency on it and abort 668 */ 669 if (head->in_progress == SET) { 670 warnx("Circular dependency on provision `%s' in file `%s'.", 671 Hash_GetKey(entry), filename); 672 exit_code = 1; 673 return; 674 } 675 676 head->in_progress = SET; 677 678 /* 679 * while provision_list is not empty 680 * do_file(first_member_of(provision_list)); 681 */ 682 while (head->next != NULL) 683 do_file(head->next->fnode); 684 } 685 686 int 687 skip_ok(fnode) 688 filenode *fnode; 689 { 690 strnodelist *s; 691 strnodelist *k; 692 693 for (s = skip_list; s; s = s->next) 694 for (k = fnode->keyword_list; k; k = k->next) 695 if (strcmp(k->s, s->s) == 0) 696 return (0); 697 698 return (1); 699 } 700 701 int 702 keep_ok(fnode) 703 filenode *fnode; 704 { 705 strnodelist *s; 706 strnodelist *k; 707 708 for (s = keep_list; s; s = s->next) 709 for (k = fnode->keyword_list; k; k = k->next) 710 if (strcmp(k->s, s->s) == 0) 711 return (1); 712 713 /* an empty keep_list means every one */ 714 return (!keep_list); 715 } 716 717 /* 718 * given a filenode, we ensure we are not a cyclic graph. if this 719 * is ok, we loop over the filenodes requirements, calling satisfy_req() 720 * for each of them.. once we have done this, remove this filenode 721 * from each provision table, as we are now done. 722 */ 723 void 724 do_file(fnode) 725 filenode *fnode; 726 { 727 f_reqnode *r, *r_tmp; 728 f_provnode *p, *p_tmp; 729 provnode *pnode; 730 int was_set; 731 732 DPRINTF((stderr, "do_file on %s.\n", fnode->filename)); 733 734 /* 735 * if fnode is marked as in progress, 736 * print that fnode; is circularly depended upon and abort. 737 */ 738 if (fnode->in_progress == SET) { 739 warnx("Circular dependency on file `%s'.", 740 fnode->filename); 741 was_set = exit_code = 1; 742 } else 743 was_set = 0; 744 745 /* mark fnode */ 746 fnode->in_progress = SET; 747 748 /* 749 * for each requirement of fnode -> r 750 * satisfy_req(r, filename) 751 */ 752 r = fnode->req_list; 753 while (r != NULL) { 754 r_tmp = r; 755 satisfy_req(r, fnode->filename); 756 r = r->next; 757 free(r_tmp); 758 } 759 fnode->req_list = NULL; 760 761 /* 762 * for each provision of fnode -> p 763 * remove fnode from provision list for p in hash table 764 */ 765 p = fnode->prov_list; 766 while (p != NULL) { 767 p_tmp = p; 768 pnode = p->pnode; 769 if (pnode->next != NULL) { 770 pnode->next->last = pnode->last; 771 } 772 if (pnode->last != NULL) { 773 pnode->last->next = pnode->next; 774 } 775 free(pnode); 776 p = p->next; 777 free(p_tmp); 778 } 779 fnode->prov_list = NULL; 780 781 /* do_it(fnode) */ 782 DPRINTF((stderr, "next do: ")); 783 784 /* if we were already in progress, don't print again */ 785 if (was_set == 0 && skip_ok(fnode) && keep_ok(fnode)) 786 printf("%s\n", fnode->filename); 787 788 if (fnode->next != NULL) { 789 fnode->next->last = fnode->last; 790 } 791 if (fnode->last != NULL) { 792 fnode->last->next = fnode->next; 793 } 794 795 DPRINTF((stderr, "nuking %s\n", fnode->filename)); 796 free(fnode->filename); 797 free(fnode); 798 } 799 800 void 801 generate_ordering() 802 { 803 804 /* 805 * while there remain undone files{f}, 806 * pick an arbitrary f, and do_file(f) 807 * Note that the first file in the file list is perfectly 808 * arbitrary, and easy to find, so we use that. 809 */ 810 811 /* 812 * N.B.: the file nodes "self delete" after they execute, so 813 * after each iteration of the loop, the head will be pointing 814 * to something totally different. The loop ends up being 815 * executed only once for every strongly connected set of 816 * nodes. 817 */ 818 while (fn_head->next != NULL) { 819 DPRINTF((stderr, "generate on %s\n", fn_head->next->filename)); 820 do_file(fn_head->next); 821 } 822 } 823