file include follower

Gary Perlman gsp at ulysses.UUCP
Tue May 29 22:11:47 AEST 1984


Maybe this should only go to net.sources, but it is pretty small.
I found it under a log.
I hope this is useful to all the people who have asked for it.
	Gary Perlman	BTL MH 5D-105	(201) 582-3624	ulysses!gsp

#include <stdio.h>
#include <ctype.h>
main (argc, argv) char **argv;
	{
	while (--argc) include (*++argv, 0);
	}

include (file, depth)
	{
	int 	indent;
	FILE	*ioptr;
	for (indent = 0; indent < depth; indent++) putchar ('\t');
	if (ioptr = fopen (file, "r"))
		{
		char	line[BUFSIZ];
		register char *lptr;
		printf ("%s\n", file);
		while (fgets (lptr = line, BUFSIZ, ioptr))
			if (*line == '#')
				{
				lptr++;
				while (isspace (*lptr)) lptr++;
				if (!strncmp (lptr, "include", 7))
					{
					int 	matcher;
					char	*eptr;
					lptr += 7;
					while (isspace (*lptr)) lptr++;
					matcher = *lptr++;
					if (matcher == '<') matcher = '>';
					for (eptr = lptr; *eptr && *eptr != matcher; eptr++);
					*eptr = NULL;
					if (matcher == '>')
						{
						char	fullname[BUFSIZ];
						sprintf (fullname, "/usr/include/%s", lptr);
						lptr = fullname;
						}
					include (lptr, depth+1);
					}
				}
		fclose (ioptr);
		}
	else printf ("%s: can't open!\n", file);
	}



More information about the Comp.unix mailing list