net/if_clone: Panic if the same cloner is attached twice
[dragonfly.git] / tools / tools / convert_usb_ids / convert_usb_ids.sh
1 #!/bin/sh
2 #
3 # $DragonFly: src/tools/tools/convert_usb_ids/convert_usb_ids.sh,v 1.2 2008/01/15 12:30:44 matthias Exp $
4
5 ub=usbdevs
6
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
11 fi
12
13 # Function for USB mass storage tables (see umass.c)
14 umass()
15 {
16         i=0
17         while read ip; do
18                 # Skip over /* ... */ comments
19                 cc=`echo "$ip" | grep "/\*"`
20                 if [ -n "$cc" ]; then
21                         continue
22                 fi
23
24                 # Assume that an umass entry consists of 3 lines
25                 if [ $i -gt 2 ]; then
26                         i=0
27                         continue
28                 fi
29
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`
43                         fi
44                         # Extract quirks
45                         if [ $i -eq 2 ]; then
46                                 quirks=`echo $ip`
47                         fi
48                         #let i=$i + 1 > /dev/null
49                 fi
50                 if [ -n "$vendor" -a -n "$product" -a -n "$release" ] &&
51                         [ -n "$proto" -a -n "$quirks" ]; then
52
53                         # We use another define
54                         if [ "$release" = "RID_WILDCARD," ]; then
55                                 release="WILDCARD_ID,"
56                         fi
57
58                         # Get vendor ID from usbdevs
59                         vendor_id=`grep "vendor $vendor" $ub | head -1 | awk '{print $3}'`
60
61                         # Get vendor description from usbdevs
62                         vendor_desc=`grep "vendor $vendor" $ub | head -1 | awk '{print $4}'`
63
64                         # Get product ID from usbdevs
65                         product_id=`grep "product $vendor $product" $ub | \
66                                 head -1 | awk '{print $4 }'`
67
68                         # Get full product name from usbdevs
69                         product_name=`grep "product $vendor $product" $ub | \
70                                 head -1 | awk '{print $5,$6,$7 }'`
71
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
89                 fi
90                 let i=$i + 1 > /dev/null
91         done
92 }
93
94 # Function for non-umass devices
95 nonumass()
96 {
97         while read ip; do
98                 # Skip lines not beginning with {
99                 if [ -z "`echo $ip | grep '{ '`" ]; then
100                         continue
101                 fi
102
103                 # Get vendor
104                 vendor=`echo $ip | awk -F ' ' '{print $2}' | head -1 | \
105                         tr -d , | sed -e 's/USB_VENDOR_//g'`
106
107                 # Get product
108                 product=`echo $ip | awk -F ' ' '{print $3}'| head -1 | \
109                         tr -d , | sed -e "s/USB_PRODUCT_${vendor}_//g"`
110
111                 # Get possible flag (eg PALM4)
112                 dflag=`echo $ip | awk -F ' ' '{print $5}'`
113
114                 # Get vendor ID from usbdevs
115                 vendor_id=`grep "vendor $vendor" $ub | head -1 | awk '{print $3}'`
116
117                 # Get vendor description from usbdevs
118                 vendor_desc=`grep "vendor $vendor" $ub | head -1 | awk '{print $4}'`
119
120                 # Get product ID from ubsdevs
121                 product_id=`grep "product $vendor $product" $ub | \
122                         head -1 | awk '{print $4 }'`
123
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 }'`
127
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 */"
138                         fi
139                 fi
140         done
141 }
142
143 DFLAG=0
144 case "$1" in
145         "-d")
146                 DFLAG=1; break;;
147 esac
148
149 if [ $DFLAG -eq 1 ]; then
150         umass
151 else
152         nonumass
153 fi
154
155 exit $?