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