Subversion Repositories planix.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#!/bin/rc
2
rfork e
3
 
4
DB=usbdb
5
HDR=../lib/usb.h
6
 
7
subs=`{	grep '^	Cl.*' $HDR | 
8
		sed -e 's/.*Cl([a-z]+)[ 	]+=[ 	]+([0-9]+).*/-e s.\1,.\2,./' |
9
		tr A-Z a-z
10
}
11
cat<<EOF
12
/* machine generated. do not edit */
13
#include <u.h>
14
#include <libc.h>
15
#include <thread.h>
16
#include "usb.h"
17
#include "usbd.h"
18
 
19
EOF
20
 
21
awk '
22
/^#|^$/	{ next }
23
collect && /^[^ \t]/{
24
	collect = 0;
25
}
26
$0 ~ /^(embed|auto)/{
27
	section = $0;
28
	collect = 1;
29
	next;
30
}
31
collect {
32
	if(section ~ "embed"){
33
		printf("extern int %smain(Dev*, int, char**);\n", $1);
34
	}
35
}
36
' $DB
37
cat <<EOF
38
 
39
Devtab devtab[] = {
40
	/* device, entrypoint, {csp, csp, csp csp}, vid, did */
41
EOF
42
 
43
awk '
44
/^#|^$/	{ next }
45
collect && /^[^ \t]/{
46
	collect = 0;
47
}
48
$0 ~ /^(embed|auto)/{
49
	section = $0;
50
	collect = 1;
51
	next;
52
}
53
collect {
54
	printf("	{\"%s\"", $1);
55
	if(section ~ "embed"){
56
		fns[nfns++] = $1;
57
		printf(",\t%smain", $1);
58
	} else
59
		printf(", nil");
60
	printf(",\t{");
61
	ncsp = 0;
62
	vid="-1";
63
	did="-1";
64
	args="";
65
	for(i = 2; i <= NF; i++)
66
		if($i ~ "^args="){
67
			sub("args=", "", $i);
68
			for(j = i; j <= NF; j++)
69
				if(j > i)
70
					args = args  " " $j;
71
				else
72
					args = $j
73
		}
74
	for(i = 2; i <= NF; i++){
75
		if($i ~ "^csp="){
76
			ncsp++;
77
			sub("csp=", "", $i);
78
			printf("%s, ", $i);
79
		} else
80
		if($i ~ "^subclass="){
81
			ncsp++;
82
			sub("subclass=", "", $i);
83
			printf("DSC|%s, ", $i);
84
		} else
85
		if($i ~ "^class="){
86
			ncsp++;
87
			sub("class=", "", $i);
88
			printf("DCL|%s, ", $i);
89
		} else
90
		if($i ~ "^proto="){
91
			ncsp++;
92
			sub("proto=", "", $i);
93
			printf("DPT|%s, ", $i);
94
		} else
95
		if($i ~ "^vid="){
96
			sub("vid=", "", $i);
97
			vid=$i
98
		} else
99
		if($i ~ "did="){
100
			sub("did=", "", $i);
101
			did=$i
102
		}
103
	}
104
	for(i = ncsp; i < 4; i++)
105
		printf("0, ");
106
	printf("}, %s, %s, \"%s\"},\n", vid, did, args);
107
}
108
' $DB | sed $subs
109
 
110
cat <<EOF
111
	{nil, nil,	{0, 0, 0, 0, }, -1, -1, nil},
112
};
113
 
114
/* end of machine generated */
115
EOF