docproc.c 15.5 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7 8 9 10 11 12
/*
 *	docproc is a simple preprocessor for the template files
 *      used as placeholders for the kernel internal documentation.
 *	docproc is used for documentation-frontend and
 *      dependency-generator.
 *	The two usages have in common that they require
 *	some knowledge of the .tmpl syntax, therefore they
 *	are kept together.
 *
 *	documentation-frontend
 *		Scans the template file and call kernel-doc for
 *		all occurrences of ![EIF]file
13 14 15 16
 *		Beforehand each referenced file is scanned for
 *		any symbols that are exported via these macros:
 *			EXPORT_SYMBOL(), EXPORT_SYMBOL_GPL(), &
 *			EXPORT_SYMBOL_GPL_FUTURE()
Linus Torvalds's avatar
Linus Torvalds committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 *		This is used to create proper -function and
 *		-nofunction arguments in calls to kernel-doc.
 *		Usage: docproc doc file.tmpl
 *
 *	dependency-generator:
 *		Scans the template file and list all files
 *		referenced in a format recognized by make.
 *		Usage:	docproc depend file.tmpl
 *		Writes dependency information to stdout
 *		in the following format:
 *		file.tmpl src.c	src2.c
 *		The filenames are obtained from the following constructs:
 *		!Efilename
 *		!Ifilename
 *		!Dfilename
 *		!Ffilename
33
 *		!Pfilename
Linus Torvalds's avatar
Linus Torvalds committed
34 35 36
 *
 */

37
#define _GNU_SOURCE
Linus Torvalds's avatar
Linus Torvalds committed
38 39 40 41 42 43
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <limits.h>
44
#include <errno.h>
45
#include <getopt.h>
Linus Torvalds's avatar
Linus Torvalds committed
46 47
#include <sys/types.h>
#include <sys/wait.h>
48
#include <time.h>
Linus Torvalds's avatar
Linus Torvalds committed
49 50 51 52 53 54 55 56 57 58 59 60

/* exitstatus is used to keep track of any failing calls to kernel-doc,
 * but execution continues. */
int exitstatus = 0;

typedef void DFL(char *);
DFL *defaultline;

typedef void FILEONLY(char * file);
FILEONLY *internalfunctions;
FILEONLY *externalfunctions;
FILEONLY *symbolsonly;
61
FILEONLY *findall;
Linus Torvalds's avatar
Linus Torvalds committed
62

63
typedef void FILELINE(char * file, char * line);
Linus Torvalds's avatar
Linus Torvalds committed
64 65
FILELINE * singlefunctions;
FILELINE * entity_system;
66
FILELINE * docsection;
Linus Torvalds's avatar
Linus Torvalds committed
67 68 69 70 71 72

#define MAXLINESZ     2048
#define MAXFILES      250
#define KERNELDOCPATH "scripts/"
#define KERNELDOC     "kernel-doc"
#define DOCBOOK       "-docbook"
73
#define RST           "-rst"
74
#define LIST          "-list"
Linus Torvalds's avatar
Linus Torvalds committed
75 76
#define FUNCTION      "-function"
#define NOFUNCTION    "-nofunction"
77
#define NODOCSECTIONS "-no-doc-sections"
78
#define SHOWNOTFOUND  "-show-not-found"
Linus Torvalds's avatar
Linus Torvalds committed
79

80 81 82 83 84 85 86 87 88 89
enum file_format {
	FORMAT_AUTO,
	FORMAT_DOCBOOK,
	FORMAT_RST,
};

static enum file_format file_format = FORMAT_AUTO;

#define KERNELDOC_FORMAT	(file_format == FORMAT_RST ? RST : DOCBOOK)

90
static char *srctree, *kernsrctree;
91

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
static char **all_list = NULL;
static int all_list_len = 0;

static void consume_symbol(const char *sym)
{
	int i;

	for (i = 0; i < all_list_len; i++) {
		if (!all_list[i])
			continue;
		if (strcmp(sym, all_list[i]))
			continue;
		all_list[i] = NULL;
		break;
	}
}

109
static void usage (void)
Linus Torvalds's avatar
Linus Torvalds committed
110
{
111
	fprintf(stderr, "Usage: docproc [{--docbook|--rst}] {doc|depend} file\n");
Linus Torvalds's avatar
Linus Torvalds committed
112 113 114
	fprintf(stderr, "Input is read from file.tmpl. Output is sent to stdout\n");
	fprintf(stderr, "doc: frontend when generating kernel documentation\n");
	fprintf(stderr, "depend: generate list of files referenced within file\n");
115 116
	fprintf(stderr, "Environment variable SRCTREE: absolute path to sources.\n");
	fprintf(stderr, "                     KBUILD_SRC: absolute path to kernel source tree.\n");
Linus Torvalds's avatar
Linus Torvalds committed
117 118 119
}

/*
120
 * Execute kernel-doc with parameters given in svec
Linus Torvalds's avatar
Linus Torvalds committed
121
 */
122
static void exec_kernel_doc(char **svec)
Linus Torvalds's avatar
Linus Torvalds committed
123 124 125 126 127 128
{
	pid_t pid;
	int ret;
	char real_filename[PATH_MAX + 1];
	/* Make sure output generated so far are flushed */
	fflush(stdout);
129
	switch (pid=fork()) {
Linus Torvalds's avatar
Linus Torvalds committed
130 131 132 133 134
		case -1:
			perror("fork");
			exit(1);
		case  0:
			memset(real_filename, 0, sizeof(real_filename));
135 136
			strncat(real_filename, kernsrctree, PATH_MAX);
			strncat(real_filename, "/" KERNELDOCPATH KERNELDOC,
Linus Torvalds's avatar
Linus Torvalds committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
					PATH_MAX - strlen(real_filename));
			execvp(real_filename, svec);
			fprintf(stderr, "exec ");
			perror(real_filename);
			exit(1);
		default:
			waitpid(pid, &ret ,0);
	}
	if (WIFEXITED(ret))
		exitstatus |= WEXITSTATUS(ret);
	else
		exitstatus = 0xff;
}

/* Types used to create list of all exported symbols in a number of files */
struct symbols
{
	char *name;
};

struct symfile
{
	char *filename;
	struct symbols *symbollist;
	int symbolcnt;
};

struct symfile symfilelist[MAXFILES];
int symfilecnt = 0;

167
static void add_new_symbol(struct symfile *sym, char * symname)
Linus Torvalds's avatar
Linus Torvalds committed
168 169
{
	sym->symbollist =
170
	  realloc(sym->symbollist, (sym->symbolcnt + 1) * sizeof(char *));
Linus Torvalds's avatar
Linus Torvalds committed
171 172 173 174
	sym->symbollist[sym->symbolcnt++].name = strdup(symname);
}

/* Add a filename to the list */
175
static struct symfile * add_new_file(char * filename)
Linus Torvalds's avatar
Linus Torvalds committed
176 177 178 179
{
	symfilelist[symfilecnt++].filename = strdup(filename);
	return &symfilelist[symfilecnt - 1];
}
180

Linus Torvalds's avatar
Linus Torvalds committed
181
/* Check if file already are present in the list */
182
static struct symfile * filename_exist(char * filename)
Linus Torvalds's avatar
Linus Torvalds committed
183 184 185 186 187 188 189 190 191 192 193 194
{
	int i;
	for (i=0; i < symfilecnt; i++)
		if (strcmp(symfilelist[i].filename, filename) == 0)
			return &symfilelist[i];
	return NULL;
}

/*
 * List all files referenced within the template file.
 * Files are separated by tabs.
 */
195 196 197 198
static void adddep(char * file)		   { printf("\t%s", file); }
static void adddep2(char * file, char * line)     { line = line; adddep(file); }
static void noaction(char * line)		   { line = line; }
static void noaction2(char * file, char * line)   { file = file; line = line; }
Linus Torvalds's avatar
Linus Torvalds committed
199 200

/* Echo the line without further action */
201
static void printline(char * line)               { printf("%s", line); }
Linus Torvalds's avatar
Linus Torvalds committed
202 203

/*
204 205
 * Find all symbols in filename that are exported with EXPORT_SYMBOL &
 * EXPORT_SYMBOL_GPL (& EXPORT_SYMBOL_GPL_FUTURE implicitly).
Linus Torvalds's avatar
Linus Torvalds committed
206 207
 * All symbols located are stored in symfilelist.
 */
208
static void find_export_symbols(char * filename)
Linus Torvalds's avatar
Linus Torvalds committed
209 210 211 212 213 214 215
{
	FILE * fp;
	struct symfile *sym;
	char line[MAXLINESZ];
	if (filename_exist(filename) == NULL) {
		char real_filename[PATH_MAX + 1];
		memset(real_filename, 0, sizeof(real_filename));
216
		strncat(real_filename, srctree, PATH_MAX);
217
		strncat(real_filename, "/", PATH_MAX - strlen(real_filename));
Linus Torvalds's avatar
Linus Torvalds committed
218 219 220 221
		strncat(real_filename, filename,
				PATH_MAX - strlen(real_filename));
		sym = add_new_file(filename);
		fp = fopen(real_filename, "r");
222
		if (fp == NULL)	{
Linus Torvalds's avatar
Linus Torvalds committed
223 224
			fprintf(stderr, "docproc: ");
			perror(real_filename);
225
			exit(1);
Linus Torvalds's avatar
Linus Torvalds committed
226
		}
227
		while (fgets(line, MAXLINESZ, fp)) {
228 229
			char *p;
			char *e;
230
			if (((p = strstr(line, "EXPORT_SYMBOL_GPL")) != NULL) ||
231
			    ((p = strstr(line, "EXPORT_SYMBOL")) != NULL)) {
Linus Torvalds's avatar
Linus Torvalds committed
232 233 234
				/* Skip EXPORT_SYMBOL{_GPL} */
				while (isalnum(*p) || *p == '_')
					p++;
235
				/* Remove parentheses & additional whitespace */
Linus Torvalds's avatar
Linus Torvalds committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
				while (isspace(*p))
					p++;
				if (*p != '(')
					continue; /* Syntax error? */
				else
					p++;
				while (isspace(*p))
					p++;
				e = p;
				while (isalnum(*e) || *e == '_')
					e++;
				*e = '\0';
				add_new_symbol(sym, p);
			}
		}
		fclose(fp);
	}
}

/*
 * Document all external or internal functions in a file.
 * Call kernel-doc with following parameters:
258
 * kernel-doc [-docbook|-rst] -nofunction function_name1 filename
259
 * Function names are obtained from all the src files
Linus Torvalds's avatar
Linus Torvalds committed
260 261 262 263
 * by find_export_symbols.
 * intfunc uses -nofunction
 * extfunc uses -function
 */
264
static void docfunctions(char * filename, char * type)
Linus Torvalds's avatar
Linus Torvalds committed
265 266 267 268 269 270 271 272
{
	int i,j;
	int symcnt = 0;
	int idx = 0;
	char **vec;

	for (i=0; i <= symfilecnt; i++)
		symcnt += symfilelist[i].symbolcnt;
273
	vec = malloc((2 + 2 * symcnt + 3) * sizeof(char *));
Linus Torvalds's avatar
Linus Torvalds committed
274 275 276 277 278
	if (vec == NULL) {
		perror("docproc: ");
		exit(1);
	}
	vec[idx++] = KERNELDOC;
279
	vec[idx++] = KERNELDOC_FORMAT;
280
	vec[idx++] = NODOCSECTIONS;
Linus Torvalds's avatar
Linus Torvalds committed
281 282 283 284
	for (i=0; i < symfilecnt; i++) {
		struct symfile * sym = &symfilelist[i];
		for (j=0; j < sym->symbolcnt; j++) {
			vec[idx++]     = type;
285
			consume_symbol(sym->symbollist[j].name);
Linus Torvalds's avatar
Linus Torvalds committed
286 287 288 289 290
			vec[idx++] = sym->symbollist[j].name;
		}
	}
	vec[idx++]     = filename;
	vec[idx] = NULL;
291 292 293 294
	if (file_format == FORMAT_RST)
		printf(".. %s\n", filename);
	else
		printf("<!-- %s -->\n", filename);
Linus Torvalds's avatar
Linus Torvalds committed
295 296 297 298
	exec_kernel_doc(vec);
	fflush(stdout);
	free(vec);
}
299 300
static void intfunc(char * filename) {	docfunctions(filename, NOFUNCTION); }
static void extfunc(char * filename) { docfunctions(filename, FUNCTION);   }
Linus Torvalds's avatar
Linus Torvalds committed
301 302

/*
303
 * Document specific function(s) in a file.
Linus Torvalds's avatar
Linus Torvalds committed
304 305 306
 * Call kernel-doc with the following parameters:
 * kernel-doc -docbook -function function1 [-function function2]
 */
307
static void singfunc(char * filename, char * line)
Linus Torvalds's avatar
Linus Torvalds committed
308 309
{
	char *vec[200]; /* Enough for specific functions */
310 311
	int i, idx = 0;
	int startofsym = 1;
Linus Torvalds's avatar
Linus Torvalds committed
312
	vec[idx++] = KERNELDOC;
313
	vec[idx++] = KERNELDOC_FORMAT;
314
	vec[idx++] = SHOWNOTFOUND;
Linus Torvalds's avatar
Linus Torvalds committed
315

316 317 318 319 320 321 322 323 324 325 326 327 328
	/* Split line up in individual parameters preceded by FUNCTION */
	for (i=0; line[i]; i++) {
		if (isspace(line[i])) {
			line[i] = '\0';
			startofsym = 1;
			continue;
		}
		if (startofsym) {
			startofsym = 0;
			vec[idx++] = FUNCTION;
			vec[idx++] = &line[i];
		}
	}
329
	for (i = 0; i < idx; i++) {
330 331
		if (strcmp(vec[i], FUNCTION))
			continue;
332 333
		consume_symbol(vec[i + 1]);
	}
Linus Torvalds's avatar
Linus Torvalds committed
334 335 336 337 338
	vec[idx++] = filename;
	vec[idx] = NULL;
	exec_kernel_doc(vec);
}

339 340 341 342 343
/*
 * Insert specific documentation section from a file.
 * Call kernel-doc with the following parameters:
 * kernel-doc -docbook -function "doc section" filename
 */
344
static void docsect(char *filename, char *line)
345
{
346 347
	/* kerneldoc -docbook -show-not-found -function "section" file NULL */
	char *vec[7];
348 349 350 351 352 353
	char *s;

	for (s = line; *s; s++)
		if (*s == '\n')
			*s = '\0';

354 355 356 357
	if (asprintf(&s, "DOC: %s", line) < 0) {
		perror("asprintf");
		exit(1);
	}
358 359 360
	consume_symbol(s);
	free(s);

361
	vec[0] = KERNELDOC;
362
	vec[1] = KERNELDOC_FORMAT;
363 364 365 366 367
	vec[2] = SHOWNOTFOUND;
	vec[3] = FUNCTION;
	vec[4] = line;
	vec[5] = filename;
	vec[6] = NULL;
368 369 370
	exec_kernel_doc(vec);
}

371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
static void find_all_symbols(char *filename)
{
	char *vec[4]; /* kerneldoc -list file NULL */
	pid_t pid;
	int ret, i, count, start;
	char real_filename[PATH_MAX + 1];
	int pipefd[2];
	char *data, *str;
	size_t data_len = 0;

	vec[0] = KERNELDOC;
	vec[1] = LIST;
	vec[2] = filename;
	vec[3] = NULL;

	if (pipe(pipefd)) {
		perror("pipe");
		exit(1);
	}

	switch (pid=fork()) {
		case -1:
			perror("fork");
			exit(1);
		case  0:
			close(pipefd[0]);
			dup2(pipefd[1], 1);
			memset(real_filename, 0, sizeof(real_filename));
			strncat(real_filename, kernsrctree, PATH_MAX);
			strncat(real_filename, "/" KERNELDOCPATH KERNELDOC,
					PATH_MAX - strlen(real_filename));
			execvp(real_filename, vec);
			fprintf(stderr, "exec ");
			perror(real_filename);
			exit(1);
		default:
			close(pipefd[1]);
			data = malloc(4096);
			do {
				while ((ret = read(pipefd[0],
						   data + data_len,
						   4096)) > 0) {
					data_len += ret;
					data = realloc(data, data_len + 4096);
				}
			} while (ret == -EAGAIN);
			if (ret != 0) {
				perror("read");
				exit(1);
			}
			waitpid(pid, &ret ,0);
	}
	if (WIFEXITED(ret))
		exitstatus |= WEXITSTATUS(ret);
	else
		exitstatus = 0xff;

	count = 0;
	/* poor man's strtok, but with counting */
	for (i = 0; i < data_len; i++) {
		if (data[i] == '\n') {
			count++;
			data[i] = '\0';
		}
	}
	start = all_list_len;
	all_list_len += count;
	all_list = realloc(all_list, sizeof(char *) * all_list_len);
	str = data;
	for (i = 0; i < data_len && start != all_list_len; i++) {
		if (data[i] == '\0') {
			all_list[start] = str;
			str = data + i + 1;
			start++;
		}
	}
}

449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
/*
 * Terminate s at first space, if any. If there was a space, return pointer to
 * the character after that. Otherwise, return pointer to the terminating NUL.
 */
static char *chomp(char *s)
{
	while (*s && !isspace(*s))
		s++;

	if (*s)
		*s++ = '\0';

	return s;
}

464 465 466
/* Return pointer to directive content, or NULL if not a directive. */
static char *is_directive(char *line)
{
467
	if (file_format == FORMAT_DOCBOOK && line[0] == '!')
468
		return line + 1;
469 470
	else if (file_format == FORMAT_RST && !strncmp(line, ".. !", 4))
		return line + 4;
471 472 473 474

	return NULL;
}

Linus Torvalds's avatar
Linus Torvalds committed
475 476 477 478 479 480
/*
 * Parse file, calling action specific functions for:
 * 1) Lines containing !E
 * 2) Lines containing !I
 * 3) Lines containing !D
 * 4) Lines containing !F
481
 * 5) Lines containing !P
482 483
 * 6) Lines containing !C
 * 7) Default lines - lines not matching the above
Linus Torvalds's avatar
Linus Torvalds committed
484
 */
485
static void parse_file(FILE *infile)
Linus Torvalds's avatar
Linus Torvalds committed
486 487
{
	char line[MAXLINESZ];
488
	char *p, *s;
489
	while (fgets(line, MAXLINESZ, infile)) {
490 491
		p = is_directive(line);
		if (!p) {
492 493 494 495
			defaultline(line);
			continue;
		}

496
		switch (*p++) {
497
		case 'E':
498
			chomp(p);
499
			externalfunctions(p);
500 501
			break;
		case 'I':
502
			chomp(p);
503
			internalfunctions(p);
504 505
			break;
		case 'D':
506
			chomp(p);
507
			symbolsonly(p);
508 509 510
			break;
		case 'F':
			/* filename */
511
			s = chomp(p);
512 513 514
			/* function names */
			while (isspace(*s))
				s++;
515
			singlefunctions(p, s);
516 517 518
			break;
		case 'P':
			/* filename */
519
			s = chomp(p);
520 521 522
			/* DOC: section name */
			while (isspace(*s))
				s++;
523
			docsection(p, s);
524 525
			break;
		case 'C':
526
			chomp(p);
527
			if (findall)
528
				findall(p);
529 530
			break;
		default:
Linus Torvalds's avatar
Linus Torvalds committed
531 532 533 534 535 536
			defaultline(line);
		}
	}
	fflush(stdout);
}

537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
/*
 * Is this a RestructuredText template?  Answer the question by seeing if its
 * name ends in ".rst".
 */
static int is_rst(const char *file)
{
	char *dot = strrchr(file, '.');

	return dot && !strcmp(dot + 1, "rst");
}

enum opts {
	OPT_DOCBOOK,
	OPT_RST,
	OPT_HELP,
};
Linus Torvalds's avatar
Linus Torvalds committed
553 554 555

int main(int argc, char *argv[])
{
556
	const char *subcommand, *filename;
Linus Torvalds's avatar
Linus Torvalds committed
557
	FILE * infile;
558
	int i;
559 560 561 562

	srctree = getenv("SRCTREE");
	if (!srctree)
		srctree = getcwd(NULL, 0);
563
	kernsrctree = getenv("KBUILD_SRC");
564
	if (!kernsrctree || !*kernsrctree)
565
		kernsrctree = srctree;
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600

	for (;;) {
		int c;
		struct option opts[] = {
			{ "docbook",	no_argument, NULL, OPT_DOCBOOK },
			{ "rst",	no_argument, NULL, OPT_RST },
			{ "help",	no_argument, NULL, OPT_HELP },
			{}
		};

		c = getopt_long_only(argc, argv, "", opts, NULL);
		if (c == -1)
			break;

		switch (c) {
		case OPT_DOCBOOK:
			file_format = FORMAT_DOCBOOK;
			break;
		case OPT_RST:
			file_format = FORMAT_RST;
			break;
		case OPT_HELP:
			usage();
			return 0;
		default:
		case '?':
			usage();
			return 1;
		}
	}

	argc -= optind;
	argv += optind;

	if (argc != 2) {
Linus Torvalds's avatar
Linus Torvalds committed
601 602 603
		usage();
		exit(1);
	}
604

605 606 607 608 609
	subcommand = argv[0];
	filename = argv[1];

	if (file_format == FORMAT_AUTO)
		file_format = is_rst(filename) ? FORMAT_RST : FORMAT_DOCBOOK;
610

Linus Torvalds's avatar
Linus Torvalds committed
611
	/* Open file, exit on error */
612
	infile = fopen(filename, "r");
613 614
	if (infile == NULL) {
		fprintf(stderr, "docproc: ");
615
		perror(filename);
616 617
		exit(2);
	}
Linus Torvalds's avatar
Linus Torvalds committed
618

619
	if (strcmp("doc", subcommand) == 0) {
620 621 622 623 624 625
		if (file_format == FORMAT_RST) {
			time_t t = time(NULL);
			printf(".. generated from %s by docproc %s\n",
			       filename, ctime(&t));
		}

Linus Torvalds's avatar
Linus Torvalds committed
626 627
		/* Need to do this in two passes.
		 * First pass is used to collect all symbols exported
628
		 * in the various files;
Linus Torvalds's avatar
Linus Torvalds committed
629
		 * Second pass generate the documentation.
630
		 * This is required because some functions are declared
Linus Torvalds's avatar
Linus Torvalds committed
631 632 633 634 635 636 637 638
		 * and exported in different files :-((
		 */
		/* Collect symbols */
		defaultline       = noaction;
		internalfunctions = find_export_symbols;
		externalfunctions = find_export_symbols;
		symbolsonly       = find_export_symbols;
		singlefunctions   = noaction2;
639
		docsection        = noaction2;
640
		findall           = find_all_symbols;
Linus Torvalds's avatar
Linus Torvalds committed
641 642 643 644 645 646 647 648 649
		parse_file(infile);

		/* Rewind to start from beginning of file again */
		fseek(infile, 0, SEEK_SET);
		defaultline       = printline;
		internalfunctions = intfunc;
		externalfunctions = extfunc;
		symbolsonly       = printline;
		singlefunctions   = singfunc;
650
		docsection        = docsect;
651
		findall           = NULL;
Linus Torvalds's avatar
Linus Torvalds committed
652 653

		parse_file(infile);
654 655 656 657 658 659 660

		for (i = 0; i < all_list_len; i++) {
			if (!all_list[i])
				continue;
			fprintf(stderr, "Warning: didn't use docs for %s\n",
				all_list[i]);
		}
661
	} else if (strcmp("depend", subcommand) == 0) {
Linus Torvalds's avatar
Linus Torvalds committed
662 663
		/* Create first part of dependency chain
		 * file.tmpl */
664
		printf("%s\t", filename);
Linus Torvalds's avatar
Linus Torvalds committed
665 666 667 668 669
		defaultline       = noaction;
		internalfunctions = adddep;
		externalfunctions = adddep;
		symbolsonly       = adddep;
		singlefunctions   = adddep2;
670
		docsection        = adddep2;
671
		findall           = adddep;
Linus Torvalds's avatar
Linus Torvalds committed
672 673
		parse_file(infile);
		printf("\n");
674
	} else {
675
		fprintf(stderr, "Unknown option: %s\n", subcommand);
Linus Torvalds's avatar
Linus Torvalds committed
676 677 678 679 680 681
		exit(1);
	}
	fclose(infile);
	fflush(stdout);
	return exitstatus;
}