comparison vidix/pci_db2c.awk @ 30052:fb44c9cb05fa

Do not auto-generate the C code to handle PCI vendor and device names. This part of the code does not change so there is no point in generating it.
author diego
date Sun, 20 Dec 2009 21:11:39 +0000
parents e2d509072a62
children fbff89bae6a4
comparison
equal deleted inserted replaced
30051:605c84da5b2c 30052:fb44c9cb05fa
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 dev_ids_c_file = "vidix/pci_dev_ids.c" 35 dev_ids_c_file = "vidix/pci_dev_ids.c"
36 ids_h_file = "vidix/pci_ids.h" 36 ids_h_file = "vidix/pci_ids.h"
37 names_c_file = "vidix/pci_names.c" 37 vendor_ids_h_file = "vidix/pci_vendor_ids.h"
38 vendors_h_file = "vidix/pci_vendors.h"; 38 vendors_h_file = "vidix/pci_vendors.h";
39 # print out head lines 39 # print out head lines
40 print_head(vendors_h_file); 40 print_head(vendors_h_file);
41 print_head(ids_h_file); 41 print_head(ids_h_file);
42 print_head(names_c_file); 42 print_head(vendor_ids_h_file);
43 print_head(dev_ids_c_file); 43 print_head(dev_ids_c_file);
44 print "#include <stdlib.h>" > dev_ids_c_file; 44 print "#include <stdlib.h>" > dev_ids_c_file;
45 print "#include \"pci_names.h\"" > dev_ids_c_file; 45 print "#include \"pci_names.h\"" > dev_ids_c_file;
46 46
47 print_guards_start(vendors_h_file); 47 print_guards_start(vendors_h_file);
48 print_guards_start(ids_h_file); 48 print_guards_start(ids_h_file);
49 print "#include \"pci_vendors.h\"" > ids_h_file 49 print "#include \"pci_vendors.h\"" > ids_h_file
50 print "" > ids_h_file 50 print "" > ids_h_file
51 51
52 print "#include <stddef.h>" > names_c_file 52 print "#include <stddef.h>" > vendor_ids_h_file
53 print "#include \"pci_names.h\"" > names_c_file 53 print "#include \"pci_names.h\"" > vendor_ids_h_file
54 if (with_pci_db) { 54 if (with_pci_db) {
55 print "#include \"pci_dev_ids.c\"" > names_c_file 55 print "#include \"pci_dev_ids.c\"" > vendor_ids_h_file
56 print "" > names_c_file 56 print "" > vendor_ids_h_file
57 print "static struct vendor_id_s vendor_ids[] = {" > names_c_file 57 print "static struct vendor_id_s vendor_ids[] = {" > vendor_ids_h_file
58 } 58 }
59 first_pass = 1; 59 first_pass = 1;
60 init_name_db(); 60 init_name_db();
61 while (getline < in_file) { 61 while (getline < in_file) {
62 n = split($0, field, "[\t]"); 62 n = split($0, field, "[\t]");
65 init_device_db() 65 init_device_db()
66 svend_name = get_short_vendor_name(field[3]) 66 svend_name = get_short_vendor_name(field[3])
67 printf("#define VENDOR_%s\t", svend_name) > vendors_h_file; 67 printf("#define VENDOR_%s\t", svend_name) > vendors_h_file;
68 if (length(svend_name) < 9) printf("\t") > vendors_h_file; 68 if (length(svend_name) < 9) printf("\t") > vendors_h_file;
69 printf("0x%s /*%s*/\n", field[2], name_field) > vendors_h_file; 69 printf("0x%s /*%s*/\n", field[2], name_field) > vendors_h_file;
70 if (with_pci_db) printf("{ 0x%s, \"%s\", dev_lst_%s },\n", field[2], name_field, field[2]) > names_c_file; 70 if (with_pci_db) printf("{ 0x%s, \"%s\", dev_lst_%s },\n", field[2], name_field, field[2]) > vendor_ids_h_file;
71 printf("/* Vendor: %s: %s */\n", field[2], name_field) > ids_h_file 71 printf("/* Vendor: %s: %s */\n", field[2], name_field) > ids_h_file
72 if (first_pass == 1) first_pass = 0; 72 if (first_pass == 1) first_pass = 0;
73 else print "{ 0xFFFF, NULL }\n};" > dev_ids_c_file; 73 else print "{ 0xFFFF, NULL }\n};" > dev_ids_c_file;
74 printf("static const struct device_id_s dev_lst_%s[] = {\n", field[2])> dev_ids_c_file 74 printf("static const struct device_id_s dev_lst_%s[] = {\n", field[2])> dev_ids_c_file
75 } 75 }
98 printf("0x%s /*%s*/\n", substr(field[2], 9), name_field) > ids_h_file 98 printf("0x%s /*%s*/\n", substr(field[2], 9), name_field) > ids_h_file
99 } 99 }
100 } 100 }
101 print_guards_end(vendors_h_file); 101 print_guards_end(vendors_h_file);
102 print_guards_end(ids_h_file); 102 print_guards_end(ids_h_file);
103 if (with_pci_db) print "};" > names_c_file 103 if (with_pci_db) print "};" > vendor_ids_h_file
104 print "{ 0xFFFF, NULL }" > dev_ids_c_file; 104 print "{ 0xFFFF, NULL }" > dev_ids_c_file;
105 print "};" > dev_ids_c_file 105 print "};" > dev_ids_c_file
106 print_func_bodies(names_c_file);
107 } 106 }
108 107
109 function construct_guard_name(out_file) 108 function construct_guard_name(out_file)
110 { 109 {
111 split(out_file, path_components, "/"); 110 split(out_file, path_components, "/");
131 function print_head(out_file) 130 function print_head(out_file)
132 { 131 {
133 printf("/* File: %s\n", out_file) > out_file; 132 printf("/* File: %s\n", out_file) > out_file;
134 printf(" * This file was generated automatically. Don't modify it. */\n") > out_file; 133 printf(" * This file was generated automatically. Don't modify it. */\n") > out_file;
135 print "" > out_file 134 print "" > out_file
136 }
137
138 function print_func_bodies(out_file)
139 {
140 print "" > out_file
141 print "const char *pci_vendor_name(unsigned short id)" > out_file
142 print "{" > out_file
143 if (with_pci_db) {
144 print " unsigned i;" > out_file
145 print " for (i = 0; i < sizeof(vendor_ids) / sizeof(struct vendor_id_s); i++) {" > out_file
146 print " if (vendor_ids[i].id == id)" > out_file
147 print " return vendor_ids[i].name;" > out_file
148 print " }" > out_file
149 }
150 print " return NULL;" > out_file
151 print "}" > out_file
152 print "" > out_file
153 print "const char *pci_device_name(unsigned short vendor_id, unsigned short device_id)" > out_file
154 print "{" > out_file
155 if (with_pci_db) {
156 print " unsigned i, j;" > out_file
157 print " for (i = 0; i < sizeof(vendor_ids) / sizeof(struct vendor_id_s); i++) {" > out_file
158 print " if (vendor_ids[i].id == vendor_id) {" > out_file
159 print " j = 0;" > out_file
160 print " while (vendor_ids[i].dev_list[j].id != 0xFFFF) {" > out_file
161 print " if (vendor_ids[i].dev_list[j].id == device_id)" > out_file
162 print " return vendor_ids[i].dev_list[j].name;" > out_file
163 print " j++;" > out_file
164 print " };" > out_file
165 print " break;" > out_file
166 print " }" > out_file
167 print " }" > out_file
168 }
169 print " return NULL;" > out_file
170 print "}" > out_file
171 } 135 }
172 136
173 function kill_double_quoting(fld) 137 function kill_double_quoting(fld)
174 { 138 {
175 n = split(fld, phrases, "[\"]"); 139 n = split(fld, phrases, "[\"]");