xref: /inferno-os/emu/port/mkdevc (revision e09f600591d16a8badf8678ab7606eb00bca98c2)
1 $AWK '
2 BEGIN{
3 		if(ARGC < 2)
4 			exit
5 }
6 
7 /^$/{
8 		next;
9 }
10 /^#/{
11 		next;
12 }
13 collect && /^[^ \t]/{
14 		collect = 0;
15 }
16 collect && section ~ "dev"{
17 		dev[ndev++] = $1;
18 }
19 collect && section ~ "ip"{
20 		ip[nip++] = $1;
21 }
22 collect && section ~ "link"{
23 		link[nlink++] = $1;
24 }
25 collect && section ~ "mod"{
26 		mod[nmod++] = $1;
27 }
28 collect && section ~ "misc"{
29 		misc[nmisc++] = $1;
30 }
31 collect && section ~ "port"{
32 		port[nport++] = $0;
33 }
34 collect && section ~ "code"{
35 		code[ncode++] = $0;
36 }
37 $0 ~ /^[^ \t]/{
38 		if($0 ~ "(code|dev|ip|lib|link|mod|misc|port|root)"){
39 			section = $0;
40 			collect = 1;
41 		}
42 		next;
43 }
44 
45 END{
46 		if(ARGC < 2)
47 			exit "usage"
48 
49 		printf "#include \"dat.h\"\n"
50 		printf "#include \"fns.h\"\n"
51 		printf "#include \"error.h\"\n"
52 		printf "#include \"interp.h\"\n\n\n"
53 		printf "#include \"%s.root.h\"\n\n", ARGV[1];
54 
55 		nildev = 8;
56 		printf "ulong ndevs = %s;\n\n", ndev+nildev
57 		for(i = 0; i < ndev; i++)
58 			printf "extern Dev %sdevtab;\n", dev[i];
59 		printf "Dev* devtab[]={\n"
60 		for(i = 0; i < ndev; i++)
61 			printf "\t&%sdevtab,\n", dev[i];
62 		for(i = 0; i < nildev; i++)
63 			printf("\tnil,\n");
64 		printf "\tnil,\n};\n\n";
65 
66 
67 		for(i = 0; i < nlink; i++)
68 			printf "extern void %slink(void);\n", link[i];
69 
70 		printf "void links(void){\n";
71 		for(i = 0; i < nlink; i++)
72 			printf "\t%slink();\n", link[i];
73 		printf "}\n\n";
74 
75 		for(i = 0; i < nmod; i++)
76 			printf "extern void %smodinit(void);\n", mod[i];
77 		printf "void modinit(void){\n";
78 		for(i = 0; i < nmod; i++)
79 			printf "\t%smodinit();\n",mod[i];
80 		printf "}\n\n";
81 
82 		if(nip){
83 			printf "#include \"../ip/ip.h\"\n";
84 			for(i = 0; i < nip; i++)
85 				printf "extern void %sinit(Fs*);\n", ip[i];
86 			printf "void (*ipprotoinit[])(Fs*) = {\n";
87 			for(i = 0; i < nip; i++)
88 				printf "\t%sinit,\n", ip[i];
89 			printf "\tnil,\n};\n\n";
90 		}
91 
92 		for(i = 0; i < ncode; i++)
93 			printf "%s\n", code[i];
94 
95 		printf "char* conffile = \"%s\";\n", ARGV[1];
96 		printf "ulong kerndate = KERNDATE;\n";
97 
98 		exit
99 }' $*
100