Fix registration issue in the devfs rc script.
[dragonfly.git] / tools / tools / convert_usb_ids / convert_usb_ids.sh
blobd41f31068fd9e2ce2df448305566289a9bb7e7e6
1 #!/bin/sh
3 # $DragonFly: src/tools/tools/convert_usb_ids/convert_usb_ids.sh,v 1.2 2008/01/15 12:30:44 matthias Exp $
5 ub=usbdevs
7 if [ ! -f $ub ]; then
8 echo "Cannot find $ub. You can get the latest version from FreeBSD"
9 echo "http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/dev/usb/usbdevs"
10 exit 1
13 # Function for USB mass storage tables (see umass.c)
14 umass()
16 i=0
17 while read ip; do
18 # Skip over /* ... */ comments
19 cc=`echo "$ip" | grep "/\*"`
20 if [ -n "$cc" ]; then
21 continue
24 # Assume that an umass entry consists of 3 lines
25 if [ $i -gt 2 ]; then
26 i=0
27 continue
30 # The first line
31 if [ -n "`echo $ip | grep '{'`" ]; then
32 vendor=`echo $ip | awk -F ' ' '{print $2}' | head -1 | \
33 tr -d , | sed -e 's/USB_VENDOR_//g'`
34 product=`echo $ip | awk -F ' ' '{print $3}'| head -1 | \
35 tr -d , | sed -e "s/USB_PRODUCT_${vendor}_//g"`
36 release=`echo $ip | awk -F ' ' '{print $4}'| head -1`
37 #let i=$i + 1 > /dev/null
38 # Second and third line
39 else
40 # Extract protocol line
41 if [ -n "`echo $ip | grep UMASS_PROTO`" ]; then
42 proto=`echo $ip | grep UMASS_PROTO`
44 # Extract quirks
45 if [ $i -eq 2 ]; then
46 quirks=`echo $ip`
48 #let i=$i + 1 > /dev/null
50 if [ -n "$vendor" -a -n "$product" -a -n "$release" ] &&
51 [ -n "$proto" -a -n "$quirks" ]; then
53 # We use another define
54 if [ "$release" = "RID_WILDCARD," ]; then
55 release="WILDCARD_ID,"
58 # Get vendor ID from usbdevs
59 vendor_id=`grep "vendor $vendor" $ub | head -1 | awk '{print $3}'`
61 # Get vendor description from usbdevs
62 vendor_desc=`grep "vendor $vendor" $ub | head -1 | awk '{print $4}'`
64 # Get product ID from usbdevs
65 product_id=`grep "product $vendor $product" $ub | \
66 head -1 | awk '{print $4 }'`
68 # Get full product name from usbdevs
69 product_name=`grep "product $vendor $product" $ub | \
70 head -1 | awk '{print $5,$6,$7 }'`
72 # Output our version of the device id
73 printf "\t"
74 echo "/* $vendor_desc $product_name */"
75 printf "\t"
76 echo -n "{ .vendor = $vendor_id, .product = $product_id, "
77 echo ".release = $release"
78 printf "\t"
79 echo " .proto = $proto"
80 printf "\t"
81 echo " .quirks = $quirks"
82 printf "\t"
83 echo "},"
84 release=
85 vendor=
86 product=
87 quirks=
88 i=10
90 let i=$i + 1 > /dev/null
91 done
94 # Function for non-umass devices
95 nonumass()
97 while read ip; do
98 # Skip lines not beginning with {
99 if [ -z "`echo $ip | grep '{ '`" ]; then
100 continue
103 # Get vendor
104 vendor=`echo $ip | awk -F ' ' '{print $2}' | head -1 | \
105 tr -d , | sed -e 's/USB_VENDOR_//g'`
107 # Get product
108 product=`echo $ip | awk -F ' ' '{print $3}'| head -1 | \
109 tr -d , | sed -e "s/USB_PRODUCT_${vendor}_//g"`
111 # Get possible flag (eg PALM4)
112 dflag=`echo $ip | awk -F ' ' '{print $5}'`
114 # Get vendor ID from usbdevs
115 vendor_id=`grep "vendor $vendor" $ub | head -1 | awk '{print $3}'`
117 # Get vendor description from usbdevs
118 vendor_desc=`grep "vendor $vendor" $ub | head -1 | awk '{print $4}'`
120 # Get product ID from ubsdevs
121 product_id=`grep "product $vendor $product" $ub | \
122 head -1 | awk '{print $4 }'`
124 # Get full name of the product from usbdevs
125 product_name=`grep "product $vendor $product" $ub | \
126 head -1 | awk '{print $5,$6,$7 }'`
128 if [ -n "$vendor_id" -a -n "$vendor_desc" ] &&
129 [ -n "$product_id" -a -n "$product_name" ]; then
130 # More complex entry with a flag
131 if [ "$dflag" != "" ]; then
132 printf "\t"
133 echo "{{ USB_DEVICE($vendor_id, $product_id) }, $dflag }, /* $vendor_desc $product_name */"
134 # Entry without a flag
135 elif [ "$dflag" = "" ]; then
136 printf "\t"
137 echo "{ USB_DEVICE($vendor_id, $product_id) }, /* $vendor_desc $product_name */"
140 done
143 DFLAG=0
144 case "$1" in
145 "-d")
146 DFLAG=1; break;;
147 esac
149 if [ $DFLAG -eq 1 ]; then
150 umass
151 else
152 nonumass
155 exit $?