+
+# parse pcitable, add any more ids for the devices
+line_num= 0
+for line in pcitable_file:
+ line_num= line_num+1
+
+ # skip blank lines, or lines that begin with # (comments)
+ line= string.strip(line)
+ if len(line) == 0:
+ continue
+
+ if line[0] == "#":
+ continue
+
+ line_parts= string.split(line)
+ if line_parts is None or len(line_parts) < 4:
+ sys.stderr.write( "Skipping line %d in pcitable (incorrect format)\n" %
+ line_num )
+ continue
+
+ # vendor id is always the first field, device the second. also,
+ # strip off first two chars (the 0x)
+ vendor_id= string.lower(line_parts[0][2:])
+ device_id= string.lower(line_parts[1][2:])
+
+ full_id= "%s:%s" % (vendor_id, device_id)
+
+ # if the first char of the third field is a double quote, the third field
+ # is a module, else if the first char of the third field is a 0 (zero),
+ # the fifth field is the module name.
+ # it would nice if there was any easy way to split a string on spaces,
+ # but recognize quoted strings, so they wouldn't be split up. that is
+ # the reason for this wierd check
+ if line_parts[2][0] == '"':
+ module= line_parts[2]
+ elif line_parts[2][0] == '0':
+ module= line_parts[4]
+ else:
+ sys.stderr.write( "Skipping line %d in pcitable (incorrect format)\n" %
+ line_num )
+ continue
+
+ # remove the first and last char of module (quote marks)
+ module= module[1:]
+ module= module[:len(module)-1]
+
+ # now add it if we don't already have this module -> id mapping
+ if all_modules.has_key(module):
+ if full_id not in all_modules[module]:
+ all_modules[module].append( full_id )
+ else:
+ # don't add any modules from pcitable that we don't already know about
+ pass
+
+