xref: /titanic_44/usr/src/uts/i86pc/io/dr/sbdgenerr.pl (revision db8b037b5616a366b7dfdc01ef9552f02f9adfdd)
1#!/usr/bin/perl
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright (c) 2000 by Sun Microsystems, Inc.
24# All rights reserved.
25#
26
27sub trim {
28	my ($line) = @_;
29	$line =~ s#/\*|\*/##g;
30	$line =~ s#^\s+|\s+$##g;
31	return $line;
32}
33
34my $filter = 0;
35my %prefix;
36while ($#ARGV >= 0) {
37	$prefix{$ARGV[0]} = 0;
38	shift @ARGV;
39	$filter = 1;
40}
41
42my $base;
43my $bnd;
44my @text;
45my @sets;
46while (<STDIN>) {
47	my $n = m@^#define\s(E\w\w\w)\w+\s+(\d+)(.*)@;
48	next unless ($n > 0);
49	next unless ($filter == 0 || defined $prefix{$1});
50	my $txt = trim($3);
51	if (length($txt) == 0) {
52		my $l = <STDIN>;
53		$txt = trim($l);
54	}
55
56	$base = $2 if (!defined $base);
57	if (defined $bnd && $2 != $bnd + 1) {
58		push(@sets, { base => $base, bnd => $bnd });
59		$base = $2;
60	}
61	$bnd = $2;
62	push(@text, $txt);
63}
64
65push(@sets, { base => $base, bnd => $bnd });
66
67printf "#include <sys/sbd_ioctl.h>\n";
68
69my $i = 0;
70my $s = 0;
71do {
72	my $set = $sets[$s];
73
74	printf "static char *sbd_t%d[] = {\n", $set->{base};
75	my $n = $set->{bnd} - $set->{base} + 1;
76	while ($n--) {
77		printf "\t\"%s\",\n", $text[$i++];
78	}
79	printf "};\n";
80} while (++$s <= $#sets);
81
82printf "sbd_etab_t sbd_etab[] = {\n";
83$s = 0;
84do {
85	my $set = $sets[$s];
86	printf "\t{ %d, %d, sbd_t%d },\n",
87		$set->{base}, $set->{bnd}, $set->{base};
88} while (++$s <= $#sets);
89printf "};\n";
90printf "int sbd_etab_len = %d;\n", $s;
91