37 lines
1.1 KiB
Plaintext
37 lines
1.1 KiB
Plaintext
|
#!/usr/bin/perl -W
|
||
|
# $Id: makeenum,v 1.1.1.1 2002/04/22 09:24:34 bursa Exp $
|
||
|
|
||
|
$out = shift or die "usage: makeenum leafname";
|
||
|
|
||
|
open H, ">$out.h" or die "open 'enum.h' failed";
|
||
|
open C, ">$out.c" or die "open 'enum.c' failed";
|
||
|
|
||
|
print C "#include \"$out.h\"\n\n";
|
||
|
|
||
|
while (<>) {
|
||
|
chomp;
|
||
|
@enum = split;
|
||
|
$name = shift @enum;
|
||
|
|
||
|
@uc_enum = map uc, @enum;
|
||
|
$uc_name = uc $name;
|
||
|
|
||
|
print H "extern const char * const ${name}_name[];\n";
|
||
|
print H "typedef enum {\n ${uc_name}_";
|
||
|
print H join ",\n ${uc_name}_", @uc_enum;
|
||
|
print H ",\n ${uc_name}_UNKNOWN\n";
|
||
|
print H "} $name;\n";
|
||
|
print H "$name ${name}_parse(const char * const s);\n\n";
|
||
|
|
||
|
print C "/**\n * $name\n */\n\n";
|
||
|
print C "const char * const ${name}_name[] = {\n \"";
|
||
|
print C join "\",\n \"", @enum;
|
||
|
print C "\"\n};\n\n";
|
||
|
print C "$name ${name}_parse(const char * const s)\n{\n";
|
||
|
foreach $x (@enum) {
|
||
|
$ux = uc $x;
|
||
|
print C " if (strcmp(s, \"$x\") == 0) return ${uc_name}_$ux;\n";
|
||
|
}
|
||
|
print C " return ${uc_name}_UNKNOWN;\n}\n\n";
|
||
|
}
|