comparison vidix/pci_db2c.awk @ 30037:bd46aa50b605

cosmetics: Use a consistent formattting style; tabs to spaces.
author diego
date Sun, 20 Dec 2009 14:43:50 +0000
parents 835d6e5e5de0
children d1c5b275d3f9
comparison
equal deleted inserted replaced
30036:955a1dc5f68c 30037:bd46aa50b605
23 # with MPlayer; if not, write to the Free Software Foundation, Inc., 23 # with MPlayer; if not, write to the Free Software Foundation, Inc.,
24 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 25
26 BEGIN { 26 BEGIN {
27 27
28 if(ARGC != 3) { 28 if (ARGC != 3) {
29 # check for arguments: 29 # check for arguments:
30 print "Usage ./pci_db2c.awk pci.db (and make sure pci.db file exists first)"; 30 print "Usage ./pci_db2c.awk pci.db (and make sure pci.db file exists first)";
31 exit(1); 31 exit(1);
32 } 32 }
33 in_file = ARGV[1]; 33 in_file = ARGV[1];
34 with_pci_db = ARGV[2]; 34 with_pci_db = ARGV[2];
35 vendor_file = "vidix/pci_vendors.h"; 35 vendor_file = "vidix/pci_vendors.h";
36 ids_file = "vidix/pci_ids.h" 36 ids_file = "vidix/pci_ids.h"
37 name_file = "vidix/pci_names.c" 37 name_file = "vidix/pci_names.c"
38 name_h_file = "vidix/pci_names.h" 38 name_h_file = "vidix/pci_names.h"
39 dev_ids_file = "vidix/pci_dev_ids.c" 39 dev_ids_file = "vidix/pci_dev_ids.c"
40 line=0; 40 line = 0;
41 # print out head lines 41 # print out head lines
42 print_head(vendor_file); 42 print_head(vendor_file);
43 print_head(ids_file); 43 print_head(ids_file);
44 print_head(name_file); 44 print_head(name_file);
45 print_head(name_h_file); 45 print_head(name_h_file);
46 print_head(dev_ids_file); 46 print_head(dev_ids_file);
47 print_includes(dev_ids_file); 47 print_includes(dev_ids_file);
48 print "#ifndef MPLAYER_PCI_VENDORS_H" >vendor_file 48 print "#ifndef MPLAYER_PCI_VENDORS_H" > vendor_file
49 print "#define MPLAYER_PCI_VENDORS_H">vendor_file 49 print "#define MPLAYER_PCI_VENDORS_H" > vendor_file
50 print "" >vendor_file 50 print "" > vendor_file
51 print "#ifndef MPLAYER_PCI_IDS_H" >ids_file 51 print "#ifndef MPLAYER_PCI_IDS_H" > ids_file
52 print "#define MPLAYER_PCI_IDS_H">ids_file 52 print "#define MPLAYER_PCI_IDS_H" > ids_file
53 print "" >ids_file 53 print "" > ids_file
54 print "#include \"pci_vendors.h\"">ids_file 54 print "#include \"pci_vendors.h\"" > ids_file
55 print "" >ids_file 55 print "" > ids_file
56 56
57 print "#ifndef MPLAYER_PCI_NAMES_H" >name_h_file 57 print "#ifndef MPLAYER_PCI_NAMES_H" > name_h_file
58 print "#define MPLAYER_PCI_NAMES_H">name_h_file 58 print "#define MPLAYER_PCI_NAMES_H" > name_h_file
59 print "" >name_h_file 59 print "" > name_h_file
60 print_name_struct(name_h_file); 60 print_name_struct(name_h_file);
61 print "#include <stddef.h>">name_file 61 print "#include <stddef.h>" > name_file
62 print "#include \"pci_names.h\"">name_file 62 print "#include \"pci_names.h\"" > name_file
63 if (with_pci_db) { 63 if (with_pci_db) {
64 print "#include \"pci_dev_ids.c\"">name_file 64 print "#include \"pci_dev_ids.c\"" > name_file
65 print "">name_file 65 print "" > name_file
66 print "static struct vendor_id_s vendor_ids[] = {">name_file 66 print "static struct vendor_id_s vendor_ids[] = {" > name_file
67 } 67 }
68 first_pass=1; 68 first_pass = 1;
69 init_name_db(); 69 init_name_db();
70 while(getline <in_file) 70 while (getline < in_file) {
71 { 71 # count up lines
72 # count up lines 72 line++;
73 line++; 73 n = split($0, field, "[\t]");
74 n=split($0, field, "[\t]"); 74 name_field = kill_double_quoting(field[3])
75 name_field = kill_double_quoting(field[3]) 75 if (field[1] == "v" && length(field[3]) > 0 && field[4] == "0") {
76 if(field[1] == "v" && length(field[3])>0 && field[4] == "0") 76 init_device_db()
77 { 77 svend_name = get_short_vendor_name(field[3])
78 init_device_db() 78 printf("#define VENDOR_%s\t", svend_name) > vendor_file;
79 svend_name = get_short_vendor_name(field[3]) 79 if (length(svend_name) < 9) printf("\t") > vendor_file;
80 printf("#define VENDOR_%s\t", svend_name) >vendor_file; 80 printf("0x%s /*%s*/\n", field[2], name_field) > vendor_file;
81 if(length(svend_name) < 9) printf("\t") >vendor_file; 81 if (with_pci_db) printf("{ 0x%s, \"%s\", dev_lst_%s },\n", field[2], name_field, field[2]) > name_file;
82 printf("0x%s /*%s*/\n",field[2], name_field) >vendor_file; 82 printf("/* Vendor: %s: %s */\n", field[2], name_field) > ids_file
83 if (with_pci_db) printf("{ 0x%s, \"%s\", dev_lst_%s },\n",field[2], name_field, field[2]) >name_file; 83 if (first_pass == 1) first_pass = 0;
84 printf("/* Vendor: %s: %s */\n", field[2], name_field) > ids_file 84 else print "{ 0xFFFF, NULL }\n};" > dev_ids_file;
85 if(first_pass == 1) { first_pass=0; } 85 printf("static const struct device_id_s dev_lst_%s[] = {\n", field[2])> dev_ids_file
86 else { print "{ 0xFFFF, NULL }\n};" >dev_ids_file; } 86 }
87 printf("static const struct device_id_s dev_lst_%s[]={\n", field[2])>dev_ids_file 87 if (field[1] == "d" && length(field[3]) > 0 && field[4] == "0") {
88 } 88 sdev_name = get_short_device_name(field[3])
89 if(field[1] == "d" && length(field[3])>0 && field[4] == "0") 89 full_name = sprintf("#define DEVICE_%s_%s", svend_name, sdev_name);
90 { 90 printf("%s\t", full_name) > ids_file
91 sdev_name = get_short_device_name(field[3]) 91 if (length(full_name) < 9) printf("\t") > ids_file;
92 full_name = sprintf("#define DEVICE_%s_%s", svend_name, sdev_name); 92 if (length(full_name) < 17) printf("\t") > ids_file;
93 printf("%s\t", full_name) >ids_file 93 if (length(full_name) < 25) printf("\t") > ids_file;
94 if(length(full_name) < 9) printf("\t") >ids_file; 94 if (length(full_name) < 32) printf("\t") > ids_file;
95 if(length(full_name) < 17) printf("\t") >ids_file; 95 if (length(full_name) < 40) printf("\t") > ids_file;
96 if(length(full_name) < 25) printf("\t") >ids_file; 96 if (length(full_name) < 48) printf("\t") > ids_file;
97 if(length(full_name) < 32) printf("\t") >ids_file; 97 printf("0x%s /*%s*/\n", substr(field[2], 5), name_field) > ids_file
98 if(length(full_name) < 40) printf("\t") >ids_file; 98 printf("{ 0x%s, \"%s\" },\n", substr(field[2], 5), name_field) > dev_ids_file
99 if(length(full_name) < 48) printf("\t") >ids_file; 99 }
100 printf("0x%s /*%s*/\n", substr(field[2], 5), name_field) >ids_file 100 if (field[1] == "s" && length(field[3]) > 0 && field[4] == "0") {
101 printf("{ 0x%s, \"%s\" },\n", substr(field[2], 5), name_field) >dev_ids_file 101 subdev_name = get_short_subdevice_name(field[3])
102 } 102 full_name = sprintf("#define SUBDEVICE_%s_%s", svend_name, subdev_name)
103 if(field[1] == "s" && length(field[3])>0 && field[4] == "0") 103 printf("\t%s\t", full_name) > ids_file
104 { 104 if (length(full_name) < 9) printf("\t") > ids_file;
105 subdev_name = get_short_subdevice_name(field[3]) 105 if (length(full_name) < 17) printf("\t") > ids_file;
106 full_name = sprintf("#define SUBDEVICE_%s_%s", svend_name, subdev_name) 106 if (length(full_name) < 25) printf("\t") > ids_file;
107 printf("\t%s\t", full_name) >ids_file 107 if (length(full_name) < 32) printf("\t") > ids_file;
108 if(length(full_name) < 9) printf("\t") >ids_file; 108 if (length(full_name) < 40) printf("\t") > ids_file;
109 if(length(full_name) < 17) printf("\t") >ids_file; 109 printf("0x%s /*%s*/\n", substr(field[2], 9), name_field) > ids_file
110 if(length(full_name) < 25) printf("\t") >ids_file; 110 }
111 if(length(full_name) < 32) printf("\t") >ids_file;
112 if(length(full_name) < 40) printf("\t") >ids_file;
113 printf("0x%s /*%s*/\n", substr(field[2], 9), name_field) >ids_file
114 }
115 } 111 }
116 #print "Total lines parsed:", line; 112 #print "Total lines parsed:", line;
117 print "">vendor_file 113 print "" > vendor_file
118 print "#endif /* MPLAYER_PCI_VENDORS_H */">vendor_file 114 print "#endif /* MPLAYER_PCI_VENDORS_H */" > vendor_file
119 print "">ids_file 115 print "" > ids_file
120 print "#endif /* MPLAYER_PCI_IDS_H */">ids_file 116 print "#endif /* MPLAYER_PCI_IDS_H */" > ids_file
121 print "">name_h_file 117 print "" > name_h_file
122 print "#endif /* MPLAYER_PCI_NAMES_H */">name_h_file 118 print "#endif /* MPLAYER_PCI_NAMES_H */" > name_h_file
123 if (with_pci_db) print "};">name_file 119 if (with_pci_db) print "};" > name_file
124 print "{ 0xFFFF, NULL }" >dev_ids_file; 120 print "{ 0xFFFF, NULL }" > dev_ids_file;
125 print "};">dev_ids_file 121 print "};" > dev_ids_file
126 print_func_bodies(name_file); 122 print_func_bodies(name_file);
127 } 123 }
128 124
129 function print_includes(out_file) 125 function print_includes(out_file)
130 { 126 {
131 print "#include <stdlib.h>" >out_file; 127 print "#include <stdlib.h>" > out_file;
132 print "#include \"pci_names.h\"" >out_file; 128 print "#include \"pci_names.h\"" > out_file;
133 return; 129 return;
134 } 130 }
135 131
136 function print_head( out_file) 132 function print_head(out_file)
137 { 133 {
138 print "/*" >out_file; 134 print "/*" > out_file;
139 printf(" * File: %s\n", out_file) >out_file; 135 printf(" * File: %s\n", out_file) > out_file;
140 printf(" * This file was generated automatically. Don't modify it.\n") >out_file; 136 printf(" * This file was generated automatically. Don't modify it.\n") > out_file;
141 print "*/" >out_file; 137 print "*/" > out_file;
142 return; 138 return;
143 } 139 }
144 140
145 function print_name_struct(out_file) 141 function print_name_struct(out_file)
146 { 142 {
147 print "">out_file 143 print "" > out_file
148 print "struct device_id_s" >out_file 144 print "struct device_id_s" > out_file
149 print "{" >out_file 145 print "{" > out_file
150 print "\tunsigned short\tid;" >out_file 146 print "\tunsigned short\tid;" > out_file
151 print "\tconst char *\tname;" >out_file 147 print "\tconst char *\tname;" > out_file
152 print "};" >out_file 148 print "};" > out_file
153 print "">out_file 149 print "" > out_file
154 print "struct vendor_id_s" >out_file 150 print "struct vendor_id_s" > out_file
155 print "{" >out_file 151 print "{" > out_file
156 print "\tunsigned short\tid;" >out_file 152 print "\tunsigned short\tid;" > out_file
157 print "\tconst char *\tname;" >out_file 153 print "\tconst char *\tname;" > out_file
158 print "\tconst struct device_id_s *\tdev_list;" >out_file 154 print "\tconst struct device_id_s *\tdev_list;" > out_file
159 print "};" >out_file 155 print "};" > out_file
160 print "const char *pci_vendor_name(unsigned short id);">out_file 156 print "const char *pci_vendor_name(unsigned short id);" > out_file
161 print "const char *pci_device_name(unsigned short vendor_id, unsigned short device_id);">out_file 157 print "const char *pci_device_name(unsigned short vendor_id, unsigned short device_id);" > out_file
162 print "">out_file 158 print "" > out_file
163 return 159 return
164 } 160 }
165 161
166 function print_func_bodies(out_file) 162 function print_func_bodies(out_file)
167 { 163 {
168 print "">out_file 164 print "" > out_file
169 print "const char *pci_vendor_name(unsigned short id)" >out_file 165 print "const char *pci_vendor_name(unsigned short id)" > out_file
170 print "{" >out_file 166 print "{" > out_file
171 if (with_pci_db) { 167 if (with_pci_db) {
172 print " unsigned i;" >out_file 168 print " unsigned i;" > out_file
173 print " for(i=0;i<sizeof(vendor_ids)/sizeof(struct vendor_id_s);i++)">out_file 169 print " for (i = 0; i < sizeof(vendor_ids) / sizeof(struct vendor_id_s); i++)" > out_file
174 print " {" >out_file 170 print " {" > out_file
175 print "\tif(vendor_ids[i].id == id) return vendor_ids[i].name;" >out_file 171 print "\tif (vendor_ids[i].id == id) return vendor_ids[i].name;" > out_file
176 print " }" >out_file 172 print " }" > out_file
177 } 173 }
178 print " return NULL;" >out_file 174 print " return NULL;" > out_file
179 print "}">out_file 175 print "}" > out_file
180 print "" >out_file 176 print "" > out_file
181 print "const char *pci_device_name(unsigned short vendor_id, unsigned short device_id)" >out_file 177 print "const char *pci_device_name(unsigned short vendor_id, unsigned short device_id)" > out_file
182 print "{" >out_file 178 print "{" > out_file
183 if (with_pci_db) { 179 if (with_pci_db) {
184 print " unsigned i, j;" >out_file 180 print " unsigned i, j;" > out_file
185 print " for(i=0;i<sizeof(vendor_ids)/sizeof(struct vendor_id_s);i++)">out_file 181 print " for (i = 0; i < sizeof(vendor_ids) / sizeof(struct vendor_id_s); i++)" > out_file
186 print " {" >out_file 182 print " {" > out_file
187 print "\tif(vendor_ids[i].id == vendor_id)" >out_file 183 print "\tif (vendor_ids[i].id == vendor_id)" > out_file
188 print "\t{" >out_file 184 print "\t{" > out_file
189 print "\t j=0;" >out_file 185 print "\t j = 0;" > out_file
190 print "\t while(vendor_ids[i].dev_list[j].id != 0xFFFF)" >out_file 186 print "\t while (vendor_ids[i].dev_list[j].id != 0xFFFF)" > out_file
191 print "\t {">out_file 187 print "\t {" > out_file
192 print "\t\tif(vendor_ids[i].dev_list[j].id == device_id) return vendor_ids[i].dev_list[j].name;">out_file 188 print "\t\tif (vendor_ids[i].dev_list[j].id == device_id) return vendor_ids[i].dev_list[j].name;" > out_file
193 print "\t\tj++;">out_file 189 print "\t\tj++;" > out_file
194 print "\t };">out_file 190 print "\t };" > out_file
195 print "\t break;" >out_file 191 print "\t break;" > out_file
196 print "\t}" >out_file 192 print "\t}" > out_file
197 print " }" >out_file 193 print " }" > out_file
198 } 194 }
199 print " return NULL;">out_file 195 print " return NULL;" > out_file
200 print "}">out_file 196 print "}" > out_file
201 return 197 return
202 } 198 }
203 199
204 function kill_double_quoting(fld) 200 function kill_double_quoting(fld)
205 { 201 {
206 n=split(fld,phrases, "[\"]"); 202 n = split(fld, phrases, "[\"]");
207 new_fld = phrases[1] 203 new_fld = phrases[1]
208 for(i=2;i<=n;i++) new_fld = sprintf("%s\\\"%s", new_fld, phrases[i]) 204 for (i = 2; i <= n; i++) new_fld = sprintf("%s\\\"%s", new_fld, phrases[i])
209 return new_fld 205 return new_fld
210 } 206 }
211 207
212 function init_name_db() 208 function init_name_db()
213 { 209 {
214 vendor_names[1]="" 210 vendor_names[1] = ""
215 } 211 }
216 212
217 function init_device_db() 213 function init_device_db()
218 { 214 {
219 # delete device_names 215 # delete device_names
220 for( i in device_names ) delete device_names[i]; 216 for (i in device_names) delete device_names[i];
221 device_names[1]="" 217 device_names[1] = ""
222 # delete subdevice_names 218 # delete subdevice_names
223 for( i in subdevice_names ) delete subdevice_names[i]; 219 for (i in subdevice_names) delete subdevice_names[i];
224 subdevice_names[1] = "" 220 subdevice_names[1] = ""
225 } 221 }
226 222
227 function get_short_vendor_name(from) 223 function get_short_vendor_name(from)
228 { 224 {
229 n=split(from, name, "[ ]"); 225 n = split(from, name, "[ ]");
230 new_name = toupper(name[1]); 226 new_name = toupper(name[1]);
231 if(length(new_name)<3) new_name = sprintf("%s_%s", new_name, toupper(name[2])); 227 if (length(new_name) < 3) new_name = sprintf("%s_%s", new_name, toupper(name[2]));
232 n=split(new_name, name, "[^0-9A-Za-z]"); 228 n = split(new_name, name, "[^0-9A-Za-z]");
233 svendor = name[1]; 229 svendor = name[1];
234 for(i=2;i<=n;i++) svendor=sprintf("%s%s%s", svendor, length(name[i])?"_":"", name[i]); 230 for (i = 2; i <= n; i++) svendor = sprintf("%s%s%s", svendor, length(name[i]) ? "_" : "", name[i]);
235 new_name = svendor; 231 new_name = svendor;
236 vend_suffix = 2; 232 vend_suffix = 2;
237 # check for unique 233 # check for unique
238 while(new_name in vendor_names) 234 while (new_name in vendor_names) {
239 { 235 new_name = sprintf("%s%u", svendor, vend_suffix)
240 new_name = sprintf("%s%u", svendor, vend_suffix) 236 vend_suffix = vend_suffix + 1;
241 vend_suffix = vend_suffix + 1; 237 }
242 } 238 # Add new name in array of vendor's names
243 # Add new name in array of vendor's names 239 vendor_names[new_name] = new_name
244 vendor_names[new_name] = new_name 240 return new_name;
245 return new_name;
246 } 241 }
247 242
248 function get_short_device_name(from_name) 243 function get_short_device_name(from_name)
249 { 244 {
250 n=split(from_name, name, "[ ]"); 245 n = split(from_name, name, "[ ]");
251 new_name = toupper(name[1]); 246 new_name = toupper(name[1]);
252 if(length(name[2])) new_name = sprintf("%s_%s", new_name, toupper(name[2])); 247 if (length(name[2])) new_name = sprintf("%s_%s", new_name, toupper(name[2]));
253 if(length(name[3])) new_name = sprintf("%s_%s", new_name, toupper(name[3])); 248 if (length(name[3])) new_name = sprintf("%s_%s", new_name, toupper(name[3]));
254 n=split(new_name, name, "[^0-9A-Za-z]"); 249 n = split(new_name, name, "[^0-9A-Za-z]");
255 sdevice = name[1]; 250 sdevice = name[1];
256 for(i=2;i<=n;i++) sdevice=sprintf("%s%s%s", sdevice, length(name[i])?"_":"", name[i]); 251 for (i = 2; i <= n; i++) sdevice = sprintf("%s%s%s", sdevice, length(name[i]) ? "_" : "", name[i]);
257 new_name = sdevice; 252 new_name = sdevice;
258 dev_suffix = 2; 253 dev_suffix = 2;
259 # check for unique 254 # check for unique
260 while(new_name in device_names) 255 while (new_name in device_names) {
261 { 256 new_name = sprintf("%s%u", sdevice, dev_suffix)
262 new_name = sprintf("%s%u", sdevice, dev_suffix) 257 dev_suffix = dev_suffix + 1;
263 dev_suffix = dev_suffix + 1; 258 }
264 } 259 # Add new name in array of device names
265 # Add new name in array of device names 260 device_names[new_name] = new_name
266 device_names[new_name] = new_name 261 return new_name;
267 return new_name;
268 } 262 }
269 263
270 function get_short_subdevice_name(from_name) 264 function get_short_subdevice_name(from_name)
271 { 265 {
272 n=split(from_name, name, "[ ]"); 266 n = split(from_name, name, "[ ]");
273 new_name = toupper(name[1]); 267 new_name = toupper(name[1]);
274 if(length(name[2])) new_name = sprintf("%s_%s", new_name, toupper(name[2])); 268 if (length(name[2])) new_name = sprintf("%s_%s", new_name, toupper(name[2]));
275 if(length(name[3])) new_name = sprintf("%s_%s", new_name, toupper(name[3])); 269 if (length(name[3])) new_name = sprintf("%s_%s", new_name, toupper(name[3]));
276 n=split(new_name, name, "[^0-9A-Za-z]"); 270 n = split(new_name, name, "[^0-9A-Za-z]");
277 ssdevice = name[1]; 271 ssdevice = name[1];
278 for(i=2;i<=n;i++) ssdevice=sprintf("%s%s%s", ssdevice, length(name[i])?"_":"", name[i]); 272 for (i = 2; i <= n; i++) ssdevice = sprintf("%s%s%s", ssdevice, length(name[i]) ? "_" : "", name[i]);
279 new_name = ssdevice; 273 new_name = ssdevice;
280 sdev_suffix = 2; 274 sdev_suffix = 2;
281 # check for unique 275 # check for unique
282 while(new_name in subdevice_names) 276 while (new_name in subdevice_names) {
283 { 277 new_name = sprintf("%s%u", ssdevice, sdev_suffix)
284 new_name = sprintf("%s%u", ssdevice, sdev_suffix) 278 sdev_suffix = sdev_suffix + 1;
285 sdev_suffix = sdev_suffix + 1; 279 }
286 } 280 # Add new name in array of subdevice names
287 # Add new name in array of subdevice names 281 subdevice_names[new_name] = new_name
288 subdevice_names[new_name] = new_name 282 return new_name;
289 return new_name; 283 }
290 }