annotate libdha/pci_db2c.awk @ 18377:b16b28d0b695

yet another Compile fix
author gpoirier
date Mon, 01 May 2006 21:12:12 +0000
parents e391c5c9da23
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4071
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
1 # This file converts given pci.db to "C" source and header files
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
2 # For latest version of pci ids see: http://pciids.sf.net
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
3 # Copyright 2002 Nick Kurshev
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
4 #
4113
1b61c1c982ae Solaris compatibility
nick
parents: 4071
diff changeset
5 # Usage: awk -f pci_db2c.awk pci.db
4071
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
6 #
4118
e391c5c9da23 Fix typo and some updates.
atmos4
parents: 4113
diff changeset
7 # Tested with Gawk v 3.0.x and Mawk 1.3.3
e391c5c9da23 Fix typo and some updates.
atmos4
parents: 4113
diff changeset
8 # But it should work with standard Awk implementations (hopefully).
e391c5c9da23 Fix typo and some updates.
atmos4
parents: 4113
diff changeset
9 # (Nobody tested it with Nawk, but it should work, too).
4071
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
10 #
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
11
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
12 BEGIN {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
13
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
14 if(ARGC != 2) {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
15 # check for arguments:
4118
e391c5c9da23 Fix typo and some updates.
atmos4
parents: 4113
diff changeset
16 print "Usage awk -f pci_db2c.awk pci.db (and make sure pci.db file exists first)";
4071
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
17 exit(1);
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
18 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
19 in_file = ARGV[1];
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
20 vendor_file = "pci_vendors.h";
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
21 ids_file = "pci_ids.h"
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
22 name_file = "pci_names.c"
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
23 name_h_file = "pci_names.h"
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
24 dev_ids_file = "pci_dev_ids.c"
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
25 line=0;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
26 # print out head lines
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
27 print_head(vendor_file);
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
28 print_head(ids_file);
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
29 print_head(name_file);
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
30 print_head(name_h_file);
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
31 print_head(dev_ids_file);
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
32 print "#ifndef PCI_VENDORS_INCLUDED" >vendor_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
33 print "#define PCI_VENDORS_INCLUDED 1">vendor_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
34 print "" >vendor_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
35 print "#ifndef PCI_IDS_INCLUDED" >ids_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
36 print "#define PCI_IDS_INCLUDED 1">ids_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
37 print "" >ids_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
38 print "#include \"pci_vendors.h\"">ids_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
39 print "" >ids_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
40
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
41 print "#ifndef PCI_NAMES_INCLUDED" >name_h_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
42 print "#define PCI_NAMES_INCLUDED 1">name_h_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
43 print "" >name_h_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
44 print_name_struct(name_h_file);
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
45 print "#include <stddef.h>">name_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
46 print "#include \"pci_names.h\"">name_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
47 print "#include \"pci_dev_ids.c\"">name_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
48 print "">name_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
49 print "static struct vendor_id_s vendor_ids[] = {">name_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
50 first_pass=1;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
51 init_name_db();
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
52 while(getline <in_file)
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
53 {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
54 # count up lines
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
55 line++;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
56 n=split($0, field, "[\t]");
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
57 name_field = kill_double_quoting(field[3])
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
58 if(field[1] == "v" && length(field[3])>0 && field[4] == "0")
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
59 {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
60 init_device_db()
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
61 svend_name = get_short_vendor_name(field[3])
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
62 printf("#define VENDOR_%s\t", svend_name) >vendor_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
63 if(length(svend_name) < 9) printf("\t") >vendor_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
64 printf("0x%s /*%s*/\n",field[2], name_field) >vendor_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
65 printf("{ 0x%s, \"%s\", dev_lst_%s },\n",field[2], name_field, field[2]) >name_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
66 printf("/* Vendor: %s: %s */\n", field[2], name_field) > ids_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
67 if(first_pass == 1) { first_pass=0; }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
68 else { print "{ 0xFFFF, NULL }\n};" >dev_ids_file; }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
69 printf("static const struct device_id_s dev_lst_%s[]={\n", field[2])>dev_ids_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
70 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
71 if(field[1] == "d" && length(field[3])>0 && field[4] == "0")
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
72 {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
73 sdev_name = get_short_device_name(field[3])
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
74 full_name = sprintf("#define DEVICE_%s_%s", svend_name, sdev_name);
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
75 printf("%s\t", full_name) >ids_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
76 if(length(full_name) < 9) printf("\t") >ids_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
77 if(length(full_name) < 17) printf("\t") >ids_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
78 if(length(full_name) < 25) printf("\t") >ids_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
79 if(length(full_name) < 32) printf("\t") >ids_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
80 if(length(full_name) < 40) printf("\t") >ids_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
81 if(length(full_name) < 48) printf("\t") >ids_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
82 printf("0x%s /*%s*/\n", substr(field[2], 5), name_field) >ids_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
83 printf("{ 0x%s, \"%s\" },\n", substr(field[2], 5), name_field) >dev_ids_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
84 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
85 if(field[1] == "s" && length(field[3])>0 && field[4] == "0")
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
86 {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
87 subdev_name = get_short_subdevice_name(field[3])
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
88 full_name = sprintf("#define SUBDEVICE_%s_%s", svend_name, subdev_name)
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
89 printf("\t%s\t", full_name) >ids_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
90 if(length(full_name) < 9) printf("\t") >ids_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
91 if(length(full_name) < 17) printf("\t") >ids_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
92 if(length(full_name) < 25) printf("\t") >ids_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
93 if(length(full_name) < 32) printf("\t") >ids_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
94 if(length(full_name) < 40) printf("\t") >ids_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
95 printf("0x%s /*%s*/\n", substr(field[2], 9), name_field) >ids_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
96 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
97 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
98 print "Total lines parsed:", line;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
99 print "">vendor_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
100 print "#endif/*PCI_VENDORS_INCLUDED*/">vendor_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
101 print "">ids_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
102 print "#endif/*PCI_IDS_INCLUDED*/">ids_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
103 print "">name_h_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
104 print "#endif/*PCI_NAMES_INCLUDED*/">name_h_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
105 print "};">name_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
106 print "{ 0xFFFF, NULL }" >dev_ids_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
107 print "};">dev_ids_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
108 print_func_bodies(name_file);
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
109 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
110
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
111 function print_head( out_file)
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
112 {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
113 print "/*" >out_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
114 printf(" * File: %s\n", out_file) >out_file;
4113
1b61c1c982ae Solaris compatibility
nick
parents: 4071
diff changeset
115 printf(" * This file was generated automatically. Don't modify it.\n") >out_file;
4071
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
116 print "*/" >out_file;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
117 return;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
118 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
119
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
120 function print_name_struct(out_file)
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
121 {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
122 print "#ifdef __cplusplus" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
123 print "extern \"C\" {" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
124 print "#endif" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
125 print "">out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
126 print "struct device_id_s" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
127 print "{" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
128 print "\tunsigned short\tid;" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
129 print "\tconst char *\tname;" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
130 print "};" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
131 print "">out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
132 print "struct vendor_id_s" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
133 print "{" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
134 print "\tunsigned short\tid;" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
135 print "\tconst char *\tname;" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
136 print "\tconst struct device_id_s *\tdev_list;" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
137 print "};" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
138 print "extern const char *pci_vendor_name(unsigned short id);">out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
139 print "extern const char *pci_device_name(unsigned short vendor_id, unsigned short device_id);">out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
140 print "">out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
141 print "#ifdef __cplusplus" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
142 print "}" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
143 print "#endif" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
144 return
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
145 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
146
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
147 function print_func_bodies(out_file)
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
148 {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
149 print "">out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
150 print "const char *pci_vendor_name(unsigned short id)" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
151 print "{" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
152 print " unsigned i;" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
153 print " for(i=0;i<sizeof(vendor_ids)/sizeof(struct vendor_id_s);i++)">out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
154 print " {" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
155 print "\tif(vendor_ids[i].id == id) return vendor_ids[i].name;" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
156 print " }" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
157 print " return NULL;" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
158 print "}">out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
159 print "" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
160 print "const char *pci_device_name(unsigned short vendor_id, unsigned short device_id)" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
161 print "{" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
162 print " unsigned i, j;" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
163 print " for(i=0;i<sizeof(vendor_ids)/sizeof(struct vendor_id_s);i++)">out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
164 print " {" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
165 print "\tif(vendor_ids[i].id == vendor_id)" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
166 print "\t{" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
167 print "\t j=0;" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
168 print "\t while(vendor_ids[i].dev_list[j].id != 0xFFFF)" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
169 print "\t {">out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
170 print "\t\tif(vendor_ids[i].dev_list[j].id == device_id) return vendor_ids[i].dev_list[j].name;">out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
171 print "\t\tj++;">out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
172 print "\t };">out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
173 print "\t break;" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
174 print "\t}" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
175 print " }" >out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
176 print " return NULL;">out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
177 print "}">out_file
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
178 return
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
179 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
180
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
181 function kill_double_quoting(fld)
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
182 {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
183 n=split(fld,phrases, "[\"]");
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
184 new_fld = phrases[1]
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
185 for(i=2;i<=n;i++) new_fld = sprintf("%s\\\"%s", new_fld, phrases[i])
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
186 return new_fld
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
187 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
188
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
189 function init_name_db()
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
190 {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
191 vendor_names[1]=""
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
192 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
193
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
194 function init_device_db()
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
195 {
4113
1b61c1c982ae Solaris compatibility
nick
parents: 4071
diff changeset
196 # delete device_names
1b61c1c982ae Solaris compatibility
nick
parents: 4071
diff changeset
197 for( i in device_names ) delete device_names[i];
4071
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
198 device_names[1]=""
4113
1b61c1c982ae Solaris compatibility
nick
parents: 4071
diff changeset
199 # delete subdevice_names
1b61c1c982ae Solaris compatibility
nick
parents: 4071
diff changeset
200 for( i in subdevice_names ) delete subdevice_names[i];
4071
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
201 subdevice_names[1] = ""
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
202 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
203
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
204 function get_short_vendor_name(from)
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
205 {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
206 n=split(from, name, "[ ]");
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
207 new_name = toupper(name[1]);
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
208 if(length(new_name)<3) new_name = sprintf("%s_%s", new_name, toupper(name[2]));
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
209 n=split(new_name, name, "[^0-9A-Za-z]");
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
210 svendor = name[1];
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
211 for(i=2;i<=n;i++) svendor=sprintf("%s%s%s", svendor, length(name[i])?"_":"", name[i]);
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
212 new_name = svendor;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
213 vend_suffix = 2;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
214 # check for unique
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
215 while(new_name in vendor_names)
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
216 {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
217 new_name = sprintf("%s%u", svendor, vend_suffix)
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
218 vend_suffix = vend_suffix + 1;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
219 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
220 # Add new name in array of vendor's names
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
221 vendor_names[new_name] = new_name
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
222 return new_name;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
223 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
224
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
225 function get_short_device_name(from_name)
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
226 {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
227 n=split(from_name, name, "[ ]");
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
228 new_name = toupper(name[1]);
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
229 if(length(name[2])) new_name = sprintf("%s_%s", new_name, toupper(name[2]));
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
230 if(length(name[3])) new_name = sprintf("%s_%s", new_name, toupper(name[3]));
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
231 n=split(new_name, name, "[^0-9A-Za-z]");
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
232 sdevice = name[1];
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
233 for(i=2;i<=n;i++) sdevice=sprintf("%s%s%s", sdevice, length(name[i])?"_":"", name[i]);
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
234 new_name = sdevice;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
235 dev_suffix = 2;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
236 # check for unique
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
237 while(new_name in device_names)
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
238 {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
239 new_name = sprintf("%s%u", sdevice, dev_suffix)
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
240 dev_suffix = dev_suffix + 1;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
241 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
242 # Add new name in array of device names
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
243 device_names[new_name] = new_name
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
244 return new_name;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
245 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
246
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
247 function get_short_subdevice_name(from_name)
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
248 {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
249 n=split(from_name, name, "[ ]");
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
250 new_name = toupper(name[1]);
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
251 if(length(name[2])) new_name = sprintf("%s_%s", new_name, toupper(name[2]));
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
252 if(length(name[3])) new_name = sprintf("%s_%s", new_name, toupper(name[3]));
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
253 n=split(new_name, name, "[^0-9A-Za-z]");
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
254 ssdevice = name[1];
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
255 for(i=2;i<=n;i++) ssdevice=sprintf("%s%s%s", ssdevice, length(name[i])?"_":"", name[i]);
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
256 new_name = ssdevice;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
257 sdev_suffix = 2;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
258 # check for unique
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
259 while(new_name in subdevice_names)
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
260 {
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
261 new_name = sprintf("%s%u", ssdevice, sdev_suffix)
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
262 sdev_suffix = sdev_suffix + 1;
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
263 }
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
264 # Add new name in array of subdevice names
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
265 subdevice_names[new_name] = new_name
9e77ea7212a2 Preliminary version
nick
parents:
diff changeset
266 return new_name;
4113
1b61c1c982ae Solaris compatibility
nick
parents: 4071
diff changeset
267 }