mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-25 21:46:57 +03:00
a0b6661eb6
svn path=/trunk/netsurf/; revision=3154
47 lines
1.4 KiB
Perl
Executable File
47 lines
1.4 KiB
Perl
Executable File
#!/usr/bin/perl -W
|
|
#
|
|
# This file is part of NetSurf, http://netsurf-browser.org/
|
|
# Licensed under the GNU General Public License,
|
|
# http://www.opensource.org/licenses/gpl-license
|
|
# Copyright 2003 James Bursa <bursa@users.sourceforge.net>
|
|
#
|
|
|
|
$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 <strings.h>\n";
|
|
print C "#include \"$out.h\"\n\n";
|
|
|
|
while (<>) {
|
|
chomp;
|
|
@enum = split;
|
|
$name = shift @enum;
|
|
|
|
@uc_enum = map uc, @enum;
|
|
s/-/_/g foreach (@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";
|
|
print H ",\n ${uc_name}_NOT_SET\n";
|
|
print H "} $name;\n";
|
|
print H "$name ${name}_parse(const char * const s, int length);\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, int length)\n{\n";
|
|
foreach $x (@enum) {
|
|
$ux = uc $x;
|
|
$ux =~ s/-/_/g;
|
|
$len = length $x;
|
|
print C " if (length == $len && strncasecmp(s, \"$x\", $len) == 0) return ${uc_name}_$ux;\n";
|
|
}
|
|
print C " return ${uc_name}_UNKNOWN;\n}\n\n";
|
|
}
|