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