While greatly modifying my MUD's skill list, I tired quickly of
rewriting the spells[] string array to reflect the defines I was making
in spells.h. I'm sure I'm not the first.
Hence, something to scratch that itch. I wrote a Perl script that
writes to a new file, spells.writeout, an automatically generated
spells[] array that can be easily cut and pasted into spell_parser.c.
No more mismatch errors! :)
I hope this proves useful to someone.
Daniel Houghton AKA Garadon
--8<--
#!/usr/bin/perl
# spellwriteout.pl
# Daniel Houghton
# March 8, 1998
# Purpose: Scan Phase ]['s spells.h for defines of skill numbers, writing
# out a formatted spells[] array to match it.
$debug = 0;
open (SPELLSH, "< spells.h");
# Skip all lines previous to the first sphere.
while ($linein = <SPELLSH>) {
last if ($linein =~ /\#define\s+SPELL\_RESERVED\_DBC/);
}
while ($linein = <SPELLSH>) {
# Quit out if we have the last skill number.
if (($linein =~ /^\s*\#define\s+TOP_SPELL_DEFINE\s+(\d+)/)) {
$last_skill_num = $1 + 1;
last;
}
if (($linein =~ /^\s*\#define\s+SKILL\_(\w+)\s+(\d+)/) ||
($linein =~ /^\s*\#define\s+SPELL\_(\w+)\s+(\d+)/)) {
$skillname = $1;
$skillnum = $2;
$skillname =~ tr/A-Z/a-z/;
$skillname =~ tr/\_/ /;
$spells[$skillnum] = $skillname;
}
}
close (SPELLSH);
open (SPELLOUT, "> ./spells.writeout");
if ($debug) {
print SPELLOUT "last_skill_num: $last_skill_num\n";
print SPELLOUT"@spells\n\n\n\n\n";
}
print SPELLOUT "char *spells[] =\n{\n",
" \"\!RESERVED\!\", /* 0 - reserved */";
for ($i = 1; $i < $last_skill_num; ++$i, $i) {
if ($spells[$i]) {
print SPELLOUT "\n";
print SPELLOUT " \"$spells[$i]\"\,";
print SPELLOUT "\t\t\/\* $i \*\/" unless ($i % 5);
$lastunused = 0; # A toggle used to choose formatting on the next line.
} else {
print SPELLOUT "\n " unless ($lastunused);
print SPELLOUT "\"\!UNUSED$i\!\"\, ";
unless ($i % 5) {
print SPELLOUT " \/\* $i \*\/";
$lastunused = 0;
} else {
$lastunused = 1;
}
}
}
print SPELLOUT "\n \"\\n\"\n};\n\n"; # close out the spells array.
close (SPELLOUT);
+------------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
| http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
+------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST