summaryrefslogtreecommitdiffstats
path: root/scripts/docproc.c
blob: 465a604a33e10d97d0dc56742c740e96abe0a2a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

/*
 *	A simple filter for the templates
 */

int main(int argc, char *argv[])
{
	char buf[1024];
	char *vec[8192];
	char *fvec[200];
	char **svec;
	char type[64];
	int i;
	int vp=2;
	pid_t pid;


	if(chdir(getenv("TOPDIR")))
	{
		perror("chdir");
		exit(1);
	}
	
	/*
	 *	Build the exec array ahead of time.
	 */
	vec[0]="kernel-doc";
	vec[1]="-docbook";
	for(i=1;vp<8189;i++)
	{
		if(argv[i]==NULL)
			break;
		vec[vp++]=type;
		vec[vp++]=argv[i];
	}
	vec[vp++]=buf+2;
	vec[vp++]=NULL;
	
	/*
	 *	Now process the template
	 */
	 
	while(fgets(buf, 1024, stdin))
	{
		if(*buf!='!') {
			printf("%s", buf);
			continue;
		}

		fflush(stdout);
		svec = vec;
		if(buf[1]=='E')
			strcpy(type, "-function");
		else if(buf[1]=='I')
			strcpy(type, "-nofunction");	
		else if(buf[1]=='F') {
			int snarf = 0;
			fvec[0] = "kernel-doc";
			fvec[1] = "-docbook";
			strcpy (type, "-function");
			vp = 2;
			for (i = 2; buf[i]; i++) {
				if (buf[i] == ' ' || buf[i] == '\n') {
					buf[i] = '\0';
					snarf = 1;
					continue;
				}

				if (snarf) {
					snarf = 0;
					fvec[vp++] = type;
					fvec[vp++] = &buf[i];
				}
			}
			fvec[vp++] = &buf[2];
			fvec[vp] = NULL;
			svec = fvec;
		} else
		{
			fprintf(stderr, "Unknown ! escape.\n");
			exit(1);
		}
		switch(pid=fork())
		{
		case -1:
			perror("fork");
			exit(1);
		case  0:
			execvp("scripts/kernel-doc", svec);
			perror("exec scripts/kernel-doc");
			exit(1);
		default:
			waitpid(pid, NULL,0);
		}
	}
	exit(0);
}