2003-06-05 18:39:54 +04:00
|
|
|
#!/usr/bin/perl -W
|
2003-06-30 16:44:03 +04:00
|
|
|
#
|
2006-11-27 18:35:18 +03:00
|
|
|
# This file is part of NetSurf, http://netsurf-browser.org/
|
2003-06-30 16:44:03 +04:00
|
|
|
# Licensed under the GNU General Public License,
|
|
|
|
# http://www.opensource.org/licenses/gpl-license
|
|
|
|
# Copyright 2003 James Bursa <bursa@users.sourceforge.net>
|
|
|
|
#
|
2002-04-22 13:24:35 +04:00
|
|
|
|
|
|
|
$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";
|
|
|
|
|
2007-01-30 01:27:15 +03:00
|
|
|
print C "#include <strings.h>\n";
|
2002-04-22 13:24:35 +04:00
|
|
|
print C "#include \"$out.h\"\n\n";
|
|
|
|
|
|
|
|
while (<>) {
|
|
|
|
chomp;
|
|
|
|
@enum = split;
|
|
|
|
$name = shift @enum;
|
2002-04-24 21:37:37 +04:00
|
|
|
|
2002-04-22 13:24:35 +04:00
|
|
|
@uc_enum = map uc, @enum;
|
2002-04-24 21:37:37 +04:00
|
|
|
s/-/_/g foreach (@uc_enum);
|
2002-04-22 13:24:35 +04:00
|
|
|
$uc_name = uc $name;
|
|
|
|
|
|
|
|
print H "extern const char * const ${name}_name[];\n";
|
2003-04-04 19:19:32 +04:00
|
|
|
print H "typedef enum {\n ${uc_name}_";
|
|
|
|
print H join ",\n ${uc_name}_", @uc_enum;
|
2005-01-11 22:39:49 +03:00
|
|
|
print H ",\n ${uc_name}_UNKNOWN";
|
|
|
|
print H ",\n ${uc_name}_NOT_SET\n";
|
2002-04-22 13:24:35 +04:00
|
|
|
print H "} $name;\n";
|
2004-05-01 21:48:38 +04:00
|
|
|
print H "$name ${name}_parse(const char * const s, int length);\n\n";
|
2002-04-22 13:24:35 +04:00
|
|
|
|
|
|
|
print C "/**\n * $name\n */\n\n";
|
2003-04-04 19:19:32 +04:00
|
|
|
print C "const char * const ${name}_name[] = {\n \"";
|
|
|
|
print C join "\",\n \"", @enum;
|
2002-04-22 13:24:35 +04:00
|
|
|
print C "\"\n};\n\n";
|
2004-05-01 21:48:38 +04:00
|
|
|
print C "$name ${name}_parse(const char * const s, int length)\n{\n";
|
2002-04-22 13:24:35 +04:00
|
|
|
foreach $x (@enum) {
|
|
|
|
$ux = uc $x;
|
2002-04-24 21:37:37 +04:00
|
|
|
$ux =~ s/-/_/g;
|
2004-05-01 21:48:38 +04:00
|
|
|
$len = length $x;
|
|
|
|
print C " if (length == $len && strncasecmp(s, \"$x\", $len) == 0) return ${uc_name}_$ux;\n";
|
2002-04-22 13:24:35 +04:00
|
|
|
}
|
2003-04-04 19:19:32 +04:00
|
|
|
print C " return ${uc_name}_UNKNOWN;\n}\n\n";
|
2002-04-22 13:24:35 +04:00
|
|
|
}
|