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 85
|
#!/usr/bin/env perl
use warnings;
use strict;
my ($infile, $outfile);
if (-e "command-type.h")
{
$infile = "command-type.h";
$outfile = "cmd-name.h";
}
elsif (-e "../command-type.h")
{
$infile = "../command-type.h";
$outfile = "../cmd-name.h";
}
else
{
die "Can't find 'command-type.h'";
}
unless (open(INFILE, "<$infile"))
{
die "Couldn't open '$infile' for reading: $!\n";
}
unless (open(OUTFILE, ">$outfile"))
{
die "Couldn't open '$outfile' for writing: $!\n";
}
# All set, now get to first command
while (<INFILE>)
{
last if (/^ *CMD_NO_CMD/);
}
unless (/^ *CMD_NO_CMD/)
{
die "Couldn't find CMD_NO_CMD in enum.h\n";
}
print OUTFILE "// Generated by util/cmd-name.pl\n\n";
print OUTFILE "#pragma once\n\n";
while (<INFILE>)
{
# Pass through pre-processor directives
if (/^#/)
{
print OUTFILE $_;
next;
}
s|//.*||; # Strip comments
s/=.*//; # Strip enum assignments
s/\s//g; # Strip whitespace
s/,$//; # Strip comma
next if (/^$/); # Skip blank lines
my $cmd = $_;
unless ($cmd =~ /^CMD_/)
{
die "'$cmd' doesn't start with CMD_\n";
}
# Don't include synthetic keys
last if ($cmd eq "CMD_DISABLE_MORE");
# Skip MIN or MAX enums, since they aren't commands
next if ($cmd =~ /^CMD_(MIN|MAX)_/);
print OUTFILE "{$cmd, \"$cmd\"},\n";
}
# End of array sentinel
print OUTFILE "\n";
print OUTFILE "{CMD_NO_CMD, nullptr}\n";
close (INFILE);
close (OUTFILE);
exit (0);
|