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