Ticket #94: pci-clean

File pci-clean, 1.9 KB (added by johndrinkwater, 18 years ago)

First revision of the PCI header cleaner

Line 
1# Clean PCI header script
2#
3# Copyright 2006, Haiku.
4# Distributed under the terms of the MIT License.
5#
6# Authors:
7# John Drinkwater, john@nextraweb.com
8#
9# Use with http://pcidatabase.com/pci_c_header.php
10# run as: sed -f pci-clean pci-input > pci-output
11
12#s/[^:]\/\/.*$// # strip comments
13#/^ /d
14#/^$/d
15s/[^][A-Za-z0-9 "{}_,;=#!*()'.:+@/\t&\-]//g # strip unknown characters
16#s/[^[:alnum:][:punct:][:space:]]//g is this cleaner ?
17s/&#[[:xdigit:]]*;//g # remove unicode ..
18/, ,/d # IDs were in escaped unicode! we`ve already removed them, so delete
19/"", ""/d # for entries with no information, just remove
20s/[é]//g # remove UTF prefixes, and other junk
21s/???//g # replace filler with something cleaner
22s/(?)//g # remove “Whats this” uncertanty
23s/0X\([[:xdigit:]]\)/0x\1/g # some lines dont have clean xs
24s/0\*\([[:xdigit:]]\)/0x\1/g # some lines dont have clean xs
25s/0x /0x/g # clean redunant space
26#/x[A-Fa-f0-9]*O[A-Fa-f0-9]*/y/O/0/ # Greedy. Todo: find a better replacement ?
27/x[[:xdigit:]]*O[[:xdigit:]]*/ { # cull stupid people
28 s/O/0/ # Only does the first..
29}
30/0x[[:xdigit:]]\{5,8\}/d # a weird ID, remove. Todo: improve
31s/0xIBM\([[:xdigit:]]\{4\}\)/0x\1/g # stupid ID. Todo: delete { wait for pcidatabase }
32 # clean ##(#(#)) IDs into 0x((0)0)##
33s/^\([^"]*\)[^x"[:xdigit:]]\([[:xdigit:]]\{4\}\),/\1 0x\2,/g
34s/^\([^"]*\)[^x"[:xdigit:]]\([[:xdigit:]]\{3\}\),/\1 0x0\2,/g
35s/^\([^"]*\)[^x"[:xdigit:]]\([[:xdigit:]]\{2\}\),/\1 0x00\2,/g
36 # clean 0x### IDs into 0x0###
37s/0x\([[:xdigit:]]\{3\}\),/0x0\1,/g
38
39# mostly clean.. now we just strip the lines that dont obey!
40
41 # look at device table..
42/\t{ 0x[[:xdigit:]]\{4\}, [^"]/ {
43 # because devices classes shouldn't be looked at
44
45 s/0x\([[:xdigit:]]\{2\}\),/0x00\1,/g # make it all 4 width
46 /, 0x[A-Fa-f0-9]\{4\},/!d # check device IDs are OK
47}
48