From 2a11247d7e0bee677579e6ade5fe6611cfed7bff Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Thu, 10 Jul 2008 21:02:58 +0000 Subject: [PATCH] Add a new enum-level directive: %max "param": * This will add an enumerator to the end of the generated C enum code with "param" as its name (prefixed by the enum's name of course) git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5482 4a71c877-e1ca-e34f-864e-861f7616d084 --- build_tools/code-generators/c_structdef_cg.pm | 10 +++++++++- build_tools/code-generators/db-lang.pl | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/build_tools/code-generators/c_structdef_cg.pm b/build_tools/code-generators/c_structdef_cg.pm index 33fcd36a6..7b706c306 100644 --- a/build_tools/code-generators/c_structdef_cg.pm +++ b/build_tools/code-generators/c_structdef_cg.pm @@ -173,7 +173,15 @@ sub printEnum() $$output .= "\t${$enum}{\"name\"}_${name},\n"; - $$output .= "\n" if @values; + $$output .= "\n" if @values or exists(${${$enum}{"qualifiers"}}{"max"}); + } + + if (exists(${${$enum}{"qualifiers"}}{"max"})) + { + $$output .= "\t/**\n" + . "\t * The number of enumerators in this enum.\n" + . "\t */\n" + . "\t${$enum}{\"name\"}_${${$enum}{\"qualifiers\"}}{\"max\"},\n"; } # Finish printing the enum diff --git a/build_tools/code-generators/db-lang.pl b/build_tools/code-generators/db-lang.pl index c348b46a0..86c0b8319 100755 --- a/build_tools/code-generators/db-lang.pl +++ b/build_tools/code-generators/db-lang.pl @@ -32,6 +32,18 @@ sub parseEnum { push @curComment, substr($1, 1) if $1; } + # Parse struct-level qualifiers + elsif (/^\s*%(.*)\s*$/) + { + die "error: Cannot give enum-level qualifiers after defining fields" if exists($curEnum{"values"}); + + $_ = $1; + + if (/^max\s+\"([^\"]+)\"\s*;$/) + { + ${$curEnum{"qualifiers"}}{"max"} = $1; + } + } elsif (/^\s*(\w+)\s*$/) { my %value = (name=>$1);