xref: /illumos-gate/usr/src/lib/cfgadm_plugins/sbd/sbdgenerr.pl (revision 0ccfe5834c3b867c1b6c273cae02ec8922bc0fd2)
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
28sub trim {
29	my ($line) = @_;
30	$line =~ s#/\*|\*/##g;
31	$line =~ s#^\s+|\s+$##g;
32	return $line;
33}
34
35my $filter = 0;
36my %prefix;
37while ($#ARGV >= 0) {
38	$prefix{$ARGV[0]} = 0;
39	shift @ARGV;
40	$filter = 1;
41}
42
43my $base;
44my $bnd;
45my @text;
46my @sets;
47while (<STDIN>) {
48	my $n = m@^#define\s(E\w\w\w)\w+\s+(\d+)(.*)@;
49	next unless ($n > 0);
50	next unless ($filter == 0 || defined $prefix{$1});
51	my $txt = trim($3);
52	if (length($txt) == 0) {
53		my $l = <STDIN>;
54		$txt = trim($l);
55	}
56
57	$base = $2 if (!defined $base);
58	if (defined $bnd && $2 != $bnd + 1) {
59		push(@sets, { base => $base, bnd => $bnd });
60		$base = $2;
61	}
62	$bnd = $2;
63	push(@text, $txt);
64}
65
66push(@sets, { base => $base, bnd => $bnd });
67
68printf "#include <sys/sbd_ioctl.h>\n";
69
70my $i = 0;
71my $s = 0;
72do {
73	my $set = $sets[$s];
74
75	printf "static char *sbd_t%d[] = {\n", $set->{base};
76	my $n = $set->{bnd} - $set->{base} + 1;
77	while ($n--) {
78		printf "\t\"%s\",\n", $text[$i++];
79	}
80	printf "};\n";
81} while (++$s <= $#sets);
82
83printf "sbd_etab_t sbd_etab[] = {\n";
84$s = 0;
85do {
86	my $set = $sets[$s];
87	printf "\t{ %d, %d, sbd_t%d },\n",
88		$set->{base}, $set->{bnd}, $set->{base};
89} while (++$s <= $#sets);
90printf "};\n";
91printf "int sbd_etab_len = %d;\n", $s;
92