|
|
|
I was also writing something before you published those scripts. My method reads the original enum by tagging like the `ATTR` macros. There's a couple sed scripts, an awk script, and a shell script to tie it together.
|
|
|
|
|
|
|
|
* `pp.sed` - removes preprocessor directives and `#if 0` blocks.
|
|
|
|
```
|
|
|
|
/^[[:blank:]]*#if 0/,/^[[:blank:]]*#endif/d
|
|
|
|
/^[[:blank:]]*#/d
|
|
|
|
```
|
|
|
|
|
|
|
|
* `enum.sed` - grabs enum definitions and permits the opening brace to be on either the same line or the next.
|
|
|
|
```
|
|
|
|
N
|
|
|
|
/^\s*SOCEXPORT\s*([[:alpha:],]\+)\s*\(typedef\s\+\)\{0,1\}enum\s\+[[:alpha:]_][[:alpha:][:digit:]_]*\s*{/,/^\s*}/P
|
|
|
|
D
|
|
|
|
```
|
|
|
|
|
|
|
|
* `gen.awk` - generates the table according to the enums gathered by `enum.sed`.
|
|
|
|
```
|
|
|
|
BEGIN {
|
|
|
|
FS = "[[:space:],]+"
|
|
|
|
}
|
|
|
|
|
|
|
|
/SOCEXPORT/ {
|
|
|
|
open = 1
|
|
|
|
match($0, /enum\s+/);
|
|
|
|
name = substr($0, RSTART + RLENGTH);
|
|
|
|
match(name, /[[:alpha:]_][[:alpha:][:digit:]_]*/);
|
|
|
|
print "Key_value_t " substr(name, RSTART, RLENGTH) "_table[] = {"
|
|
|
|
}
|
|
|
|
|
|
|
|
/SOCEXPORT/,/}/ {
|
|
|
|
if ($1 ~ /}/)
|
|
|
|
print "\t{0}\n};"
|
|
|
|
else if ($1 !~ /(SOCEXPORT|{)/)
|
|
|
|
print "\t{\"" $2 "\"," $2 "},"
|
|
|
|
}
|
|
|
|
|
|
|
|
END {
|
|
|
|
# close an unclosed brace
|
|
|
|
if ($1 !~ /}/ && open)
|
|
|
|
print "\t{0}\n};"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
* `enum.sh` - actually converts enums on its input to tables using the above methods.
|
|
|
|
```
|
|
|
|
sed -f pp.sed | gcc -E -fpreprocessed -P - | sed -f enum.sed -n | awk -f gen.awk
|
|
|
|
```
|
|
|
|
|
|
|
|
Using GCC as a preprocessor gets rid of comments.
|
|
|
|
|
|
|
|
<details>
|
|
|
|
<summary>An example</summary>
|
|
|
|
|
|
|
|
I added <code>SOCEXPORT</code> to the enums in <code>doomstat.h</code>, like so:
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
SOCEXPORT (TABLE) enum TypeOfLevel
|
|
|
|
{
|
|
|
|
TOL_SP = 0x01, ///< Single Player
|
|
|
|
TOL_COOP = 0x02, ///< Cooperative
|
|
|
|
TOL_COMPETITION = 0x04, ///< Competition
|
|
|
|
TOL_RACE = 0x08, ///< Race
|
|
|
|
// Single Player default = 15
|
|
|
|
|
|
|
|
TOL_MATCH = 0x10, ///< Match
|
|
|
|
TOL_TAG = 0x20, ///< Tag
|
|
|
|
// Match/Tag default = 48
|
|
|
|
|
|
|
|
TOL_CTF = 0x40, ///< Capture the Flag
|
|
|
|
// CTF default = 64
|
|
|
|
|
|
|
|
// 0x80 was here
|
|
|
|
|
|
|
|
TOL_2D = 0x0100, ///< 2D
|
|
|
|
TOL_MARIO = 0x0200, ///< Mario
|
|
|
|
TOL_NIGHTS = 0x0400, ///< NiGHTS
|
|
|
|
TOL_ERZ3 = 0x0800, ///< ERZ3
|
|
|
|
TOL_XMAS = 0x1000, ///< Christmas NiGHTS
|
|
|
|
};
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
After running <code>./enum.sh < doomstat.h</code>...
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
Key_value_t GameType_table[] = {
|
|
|
|
{"GT_COOP",GT_COOP},
|
|
|
|
{"GT_COMPETITION",GT_COMPETITION},
|
|
|
|
{"GT_RACE",GT_RACE},
|
|
|
|
{"GT_MATCH",GT_MATCH},
|
|
|
|
{"GT_TEAMMATCH",GT_TEAMMATCH},
|
|
|
|
{"GT_TAG",GT_TAG},
|
|
|
|
{"GT_HIDEANDSEEK",GT_HIDEANDSEEK},
|
|
|
|
{"GT_CTF",GT_CTF},
|
|
|
|
{"GT_FIRSTFREESLOT",GT_FIRSTFREESLOT},
|
|
|
|
{"GT_LASTFREESLOT",GT_LASTFREESLOT},
|
|
|
|
{"NUMGAMETYPES",NUMGAMETYPES},
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
Key_value_t GameTypeRules_table[] = {
|
|
|
|
{"GTR_CAMPAIGN",GTR_CAMPAIGN},
|
|
|
|
{"GTR_RINGSLINGER",GTR_RINGSLINGER},
|
|
|
|
{"GTR_SPECTATORS",GTR_SPECTATORS},
|
|
|
|
{"GTR_LIVES",GTR_LIVES},
|
|
|
|
{"GTR_TEAMS",GTR_TEAMS},
|
|
|
|
{"GTR_FIRSTPERSON",GTR_FIRSTPERSON},
|
|
|
|
{"GTR_POWERSTONES",GTR_POWERSTONES},
|
|
|
|
{"GTR_TEAMFLAGS",GTR_TEAMFLAGS},
|
|
|
|
{"GTR_FRIENDLY",GTR_FRIENDLY},
|
|
|
|
{"GTR_SPECIALSTAGES",GTR_SPECIALSTAGES},
|
|
|
|
{"GTR_EMERALDTOKENS",GTR_EMERALDTOKENS},
|
|
|
|
{"GTR_EMERALDHUNT",GTR_EMERALDHUNT},
|
|
|
|
{"GTR_RACE",GTR_RACE},
|
|
|
|
{"GTR_TAG",GTR_TAG},
|
|
|
|
{"GTR_POINTLIMIT",GTR_POINTLIMIT},
|
|
|
|
{"GTR_TIMELIMIT",GTR_TIMELIMIT},
|
|
|
|
{"GTR_OVERTIME",GTR_OVERTIME},
|
|
|
|
{"GTR_HURTMESSAGES",GTR_HURTMESSAGES},
|
|
|
|
{"GTR_FRIENDLYFIRE",GTR_FRIENDLYFIRE},
|
|
|
|
{"GTR_STARTCOUNTDOWN",GTR_STARTCOUNTDOWN},
|
|
|
|
{"GTR_HIDEFROZEN",GTR_HIDEFROZEN},
|
|
|
|
{"GTR_BLINDFOLDED",GTR_BLINDFOLDED},
|
|
|
|
{"GTR_RESPAWNDELAY",GTR_RESPAWNDELAY},
|
|
|
|
{"GTR_PITYSHIELD",GTR_PITYSHIELD},
|
|
|
|
{"GTR_DEATHPENALTY",GTR_DEATHPENALTY},
|
|
|
|
{"GTR_NOSPECTATORSPAWN",GTR_NOSPECTATORSPAWN},
|
|
|
|
{"GTR_DEATHMATCHSTARTS",GTR_DEATHMATCHSTARTS},
|
|
|
|
{"GTR_SPAWNINVUL",GTR_SPAWNINVUL},
|
|
|
|
{"GTR_SPAWNENEMIES",GTR_SPAWNENEMIES},
|
|
|
|
{"GTR_ALLOWEXIT",GTR_ALLOWEXIT},
|
|
|
|
{"GTR_NOTITLECARD",GTR_NOTITLECARD},
|
|
|
|
{"GTR_CUTSCENES",GTR_CUTSCENES},
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
Key_value_t TypeOfLevel_table[] = {
|
|
|
|
{"TOL_SP",TOL_SP},
|
|
|
|
{"TOL_COOP",TOL_COOP},
|
|
|
|
{"TOL_COMPETITION",TOL_COMPETITION},
|
|
|
|
{"TOL_RACE",TOL_RACE},
|
|
|
|
{"TOL_MATCH",TOL_MATCH},
|
|
|
|
{"TOL_TAG",TOL_TAG},
|
|
|
|
{"TOL_CTF",TOL_CTF},
|
|
|
|
{"TOL_2D",TOL_2D},
|
|
|
|
{"TOL_MARIO",TOL_MARIO},
|
|
|
|
{"TOL_NIGHTS",TOL_NIGHTS},
|
|
|
|
{"TOL_ERZ3",TOL_ERZ3},
|
|
|
|
{"TOL_XMAS",TOL_XMAS},
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
</pre>
|
|
|
|
</details> |
|
|
|
\ No newline at end of file |