-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenum.pl
More file actions
85 lines (59 loc) · 1.25 KB
/
Copy pathenum.pl
File metadata and controls
85 lines (59 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/perl
=pod
=head1 NAME
enum.pl - Print out C code to define an enum and printable version of the same
=head1 SYNOPSIS
enum.pl I<in-file.txt>
=head1 DESCRIPTION
The I<enum.pl> reads a set of enumeration values from from a file
and outputs a C B<enum> declaration and a list of strings
called B<enum_to_string> which translates that enum to a string.
=head1 EXAMPLES
=head2 INPUT FILE
File I<names.txt>
SAM
JOE
MAC
=head2 COMMAND
enum.pl names.txt
=head2 OUTPUT FILE
enum NAMES {
SAM,
JOE,
MAC,
};
static const char* const names_to_string[] = {
"SAM",
"JOE",
"MAC",
}
=head1 AUTHOR
Steve Oualline, E<lt>oualline@www.oualline.comE<gt>.
=head1 COPYRIGHT
Copyright 2005 Steve Oualline.
This program is distributed under the GPL.
=cut
use strict;
use warnings;
if ($#ARGV != 0) {
print STDERR "Usage is $0 <input file>\n";
exit (8);
}
$ARGV[0] =~ /^([^\.]*)/;
my $enum = $1;
my $ENUM = $enum;
$ENUM =~ tr [a-z] [A-Z];
my @words = <>;
chomp(@words);
print "enum $ENUM {\n";
foreach my $cur_word (@words) {
print " $cur_word,\n";
}
print "};\n";
print <<EOF;
static const char* const ${enum}_to_string[] = {
EOF
foreach my $cur_word (@words) {
print " \"$cur_word\",\n";
}
print "}\n";