summaryrefslogtreecommitdiff
path: root/sys/src/cmd/usb/usbd/mkdev
blob: 284a396cd5c83a6b74c47240cbbbb2cbf6176138 (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
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/rc
rfork e

DB=usbdb
HDR=../lib/usb.h

subs=`{	grep '^	Cl.*' $HDR | 
		sed -e 's/.*Cl([a-z]+)[ 	]+=[ 	]+([0-9]+).*/-e s.\1,.\2,./' |
		tr A-Z a-z
}
cat<<EOF
/* machine generated. do not edit */
#include <u.h>
#include <libc.h>
#include <thread.h>
#include "usb.h"
#include "usbd.h"

EOF

awk '
/^#|^$/	{ next }
collect && /^[^ \t]/{
	collect = 0;
}
$0 ~ /^(embed|auto)/{
	section = $0;
	collect = 1;
	next;
}
collect {
	if(section ~ "embed"){
		printf("extern int %smain(Dev*, int, char**);\n", $1);
	}
}
' $DB
cat <<EOF

Devtab devtab[] = {
	/* device, entrypoint, {csp, csp, csp csp}, vid, did */
EOF

awk '
/^#|^$/	{ next }
collect && /^[^ \t]/{
	collect = 0;
}
$0 ~ /^(embed|auto)/{
	section = $0;
	collect = 1;
	next;
}
collect {
	printf("	{\"%s\"", $1);
	if(section ~ "embed"){
		fns[nfns++] = $1;
		printf(",\t%smain", $1);
	} else
		printf(", nil");
	printf(",\t{");
	ncsp = 0;
	vid="-1";
	did="-1";
	args="";
	for(i = 2; i <= NF; i++)
		if($i ~ "^args="){
			sub("args=", "", $i);
			for(j = i; j <= NF; j++)
				if(j > i)
					args = args  " " $j;
				else
					args = $j
		}
	for(i = 2; i <= NF; i++){
		if($i ~ "^csp="){
			ncsp++;
			sub("csp=", "", $i);
			printf("%s, ", $i);
		} else
		if($i ~ "^subclass="){
			ncsp++;
			sub("subclass=", "", $i);
			printf("DSC|%s, ", $i);
		} else
		if($i ~ "^class="){
			ncsp++;
			sub("class=", "", $i);
			printf("DCL|%s, ", $i);
		} else
		if($i ~ "^proto="){
			ncsp++;
			sub("proto=", "", $i);
			printf("DPT|%s, ", $i);
		} else
		if($i ~ "^vid="){
			sub("vid=", "", $i);
			vid=$i
		} else
		if($i ~ "did="){
			sub("did=", "", $i);
			did=$i
		}
	}
	for(i = ncsp; i < 4; i++)
		printf("0, ");
	printf("}, %s, %s, \"%s\"},\n", vid, did, args);
}
' $DB | sed $subs

cat <<EOF
	{nil, nil,	{0, 0, 0, 0, }, -1, -1, nil},
};

/* end of machine generated */
EOF