| 1 |
# Copyright (c) 2006 William Pitcock, et al. |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# Redistribution and use in source and binary forms, with or without |
| 5 |
# modification, are permitted provided that the following conditions |
| 6 |
# are met: |
| 7 |
# |
| 8 |
# 1. Redistributions of source code must retain the above copyright |
| 9 |
# notice, this list of conditions and the following disclaimer. |
| 10 |
# |
| 11 |
# 2. Redistributions in binary form must reproduce the above copyright |
| 12 |
# notice, this list of conditions and the following disclaimer in the |
| 13 |
# documentation and/or other materials provided with the distribution. |
| 14 |
# |
| 15 |
# 3. Neither the name of the authors nor the names of its contributors |
| 16 |
# may be used to endorse or promote products derived from this software |
| 17 |
# without specific prior written permission. |
| 18 |
# |
| 19 |
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND |
| 20 |
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE |
| 23 |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 24 |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 25 |
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 26 |
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 27 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 28 |
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 29 |
# SUCH DAMAGE. |
| 30 |
|
| 31 |
use strict; |
| 32 |
use warnings; |
| 33 |
use utf8; |
| 34 |
|
| 35 |
my @lines = do { open my $fh, "<names/default" or die "names/default: $!"; <$fh> }; |
| 36 |
|
| 37 |
my %begin_sym = ( ); |
| 38 |
my %medial_sym = ( ); |
| 39 |
my %end_sym = ( ); |
| 40 |
my $which = 0; |
| 41 |
|
| 42 |
my $begin_sym_cnt = 0; |
| 43 |
my $medial_sym_cnt = 0; |
| 44 |
my $end_sym_cnt = 0; |
| 45 |
|
| 46 |
my $begin_syms = ""; |
| 47 |
my $medial_syms = ""; |
| 48 |
my $end_syms = ""; |
| 49 |
|
| 50 |
for my $line (@lines) { |
| 51 |
chomp $line; |
| 52 |
|
| 53 |
if ($line =~ /^%/) { |
| 54 |
$which++; |
| 55 |
next; |
| 56 |
} |
| 57 |
|
| 58 |
$begin_sym{$line} = $line if $which == 0; |
| 59 |
$medial_sym{$line} = $line if $which == 1; |
| 60 |
$end_sym{$line} = $line if $which == 2; |
| 61 |
}; |
| 62 |
|
| 63 |
for my $sym (keys %begin_sym) { |
| 64 |
$begin_syms .= "\t\"$sym\",\n"; |
| 65 |
$begin_sym_cnt++; |
| 66 |
}; |
| 67 |
|
| 68 |
for my $sym (keys %medial_sym) { |
| 69 |
$medial_syms .= "\t\"$sym\",\n"; |
| 70 |
$medial_sym_cnt++; |
| 71 |
}; |
| 72 |
|
| 73 |
for my $sym (keys %end_sym) { |
| 74 |
$end_syms .= "\t\"$sym\",\n"; |
| 75 |
$end_sym_cnt++; |
| 76 |
}; |
| 77 |
|
| 78 |
print <<EOF; |
| 79 |
/* Autogenerated by gen_namegen_tab.pl. Do not modify! */ |
| 80 |
#ifndef _NAMEGEN_H |
| 81 |
#define _NAMEGEN_H |
| 82 |
|
| 83 |
const char *begin_sym[] = { |
| 84 |
$begin_syms}; |
| 85 |
|
| 86 |
#define BEGIN_SYM_SZ $begin_sym_cnt |
| 87 |
|
| 88 |
const char *medial_sym[] = { |
| 89 |
$medial_syms}; |
| 90 |
|
| 91 |
#define MEDIAL_SYM_SZ $medial_sym_cnt |
| 92 |
|
| 93 |
const char *end_sym[] = { |
| 94 |
$end_syms}; |
| 95 |
|
| 96 |
#define END_SYM_SZ $end_sym_cnt |
| 97 |
|
| 98 |
#endif |
| 99 |
EOF |