File: convert_isapnp_ids

package info (click to toggle)
alsa-driver 1.0.13-5etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 20,108 kB
  • ctags: 50,477
  • sloc: ansic: 319,881; sh: 32,930; makefile: 2,015; python: 1,527; perl: 1,316; xml: 896; awk: 66
file content (98 lines) | stat: -rwxr-xr-x 2,206 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/awk -f
#
# convert_isapnp_ids
# Copyright (c) 2003 by Jaroslav Kysela <perex@suse.cz>
# 
# This scripts converts PnP ID tables from new form:
#
# static struct pnp_card_device_id variable[] __devinitdata = {
#	{ .id = "ALS0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
#	{ .id = "", } /* end */
# };
#
# MODULE_DEVICE_TABLE(pnp_card, snd_als100_pnpids);
#
# to old form:
#
# static struct isapnp_card_id snd_opl3sa2_pnpids[] __devinitdata = {
#	{ ISAPNP_CARD_ID('A', 'L', 'S', 0x0001),
#	  .devs = {
#		ISAPNP_DEVICE_ID('@', '@', '@', 0x0001),
#		ISAPNP_DEVICE_ID('@', 'X', '@', 0x0001),
#		ISAPNP_DEVICE_ID('@', 'H', '@', 0x0001),
#	  }
#       },
#       { ISAPNP_CARD_END, }
# };
#
# ISAPNP_CARD_TABLE(variable);

function getstructname(line)
{
	split($line, a, " ")
	split(a[4], b, "[")
	return b[1]
}

function printdata(id, prefix,   h, l)
{
	h = "0x"
	l = substr(id, 4, 4)
	if (match(l, "^XXXX") != 0) {
		l = "ISAPNP_ANY_ID"
		h = ""
	}
	print prefix "('" substr(id, 1, 1) "', '" \
			  substr(id, 2, 1) "', '" \
			  substr(id, 3, 1) "', " \
			  h l "),"
}

function dataline(line,   a, b, idx, num)
{
	num = split($line, a, ",")
	split(a[1], b, "\"")
	printdata(b[2], "\t{ ISAPNP_CARD_ID")
	print "\t  .devs = {"
	for (idx = 2; idx < num; idx = idx + 1) {
		split(a[idx], b, "\"")
		if (b[2] != "") {
			printdata(b[2], "\t\tISAPNP_DEVICE_ID")
		}
	}
	print "\t  }"
	print "\t},"
}

/^static struct pnp_card_device_id/ {
	print "/*"
	print " * This file is autogenerated by the alsa-driver/utils/convert_isapnp_ids script..."
	print " * DO NOT EDIT!!!"
	print " * Source file: " ARGV[1]
	print " */"
	print ""
	print "#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)"
	print ""
	structname = getstructname($0)
	print "static struct isapnp_card_id " structname "_old[] __devinitdata = {"
	getline
	while (match($0, "^};") == 0) {
		if (match($0, ".id[ \t]*=[ \t]\"\"")) {
			print "\t{ ISAPNP_CARD_END, }"
		} else {
			if (match($0, "^# [0-9]+") == 0) {
				if (match($0, /\{.*\}/)) {
					dataline($0)
				} else {
					print $0
				}
			}
		}
		getline
	}
	print "};"
	print ""
	print "ISAPNP_CARD_TABLE(" structname "_old);"
	print ""
	print "#endif /* 2.5.0 */"
}