diff options
author | Simon Howard | 2008-09-07 21:03:09 +0000 |
---|---|---|
committer | Simon Howard | 2008-09-07 21:03:09 +0000 |
commit | 37865c5d5b53fd0427b6f22d0a13f830a74c3064 (patch) | |
tree | 53b6ce6a086fbc3ece55cfb91e372c7c67d1bb36 | |
parent | cf7b4fab6313cd2162cb0bd3f28596fbdc2fffd3 (diff) | |
download | chocolate-doom-37865c5d5b53fd0427b6f22d0a13f830a74c3064.tar.gz chocolate-doom-37865c5d5b53fd0427b6f22d0a13f830a74c3064.tar.bz2 chocolate-doom-37865c5d5b53fd0427b6f22d0a13f830a74c3064.zip |
Move dehacked code to doom/. Split dehacked string replacement code into
common code and remove dependencies on deh_main.h.
Subversion-branch: /branches/raven-branch
Subversion-revision: 1210
-rw-r--r-- | src/Makefile.am | 14 | ||||
-rw-r--r-- | src/deh_str.c (renamed from src/deh_text.c) | 116 | ||||
-rw-r--r-- | src/deh_str.h | 46 | ||||
-rw-r--r-- | src/doom/Makefile.am | 18 | ||||
-rw-r--r-- | src/doom/deh_ammo.c (renamed from src/deh_ammo.c) | 0 | ||||
-rw-r--r-- | src/doom/deh_cheat.c (renamed from src/deh_cheat.c) | 0 | ||||
-rw-r--r-- | src/doom/deh_defs.h (renamed from src/deh_defs.h) | 0 | ||||
-rw-r--r-- | src/doom/deh_frame.c (renamed from src/deh_frame.c) | 0 | ||||
-rw-r--r-- | src/doom/deh_io.c (renamed from src/deh_io.c) | 0 | ||||
-rw-r--r-- | src/doom/deh_io.h (renamed from src/deh_io.h) | 0 | ||||
-rw-r--r-- | src/doom/deh_main.c (renamed from src/deh_main.c) | 0 | ||||
-rw-r--r-- | src/doom/deh_main.h (renamed from src/deh_main.h) | 15 | ||||
-rw-r--r-- | src/doom/deh_mapping.c (renamed from src/deh_mapping.c) | 0 | ||||
-rw-r--r-- | src/doom/deh_mapping.h (renamed from src/deh_mapping.h) | 0 | ||||
-rw-r--r-- | src/doom/deh_misc.c (renamed from src/deh_misc.c) | 0 | ||||
-rw-r--r-- | src/doom/deh_misc.h (renamed from src/deh_misc.h) | 0 | ||||
-rw-r--r-- | src/doom/deh_ptr.c (renamed from src/deh_ptr.c) | 0 | ||||
-rw-r--r-- | src/doom/deh_sound.c (renamed from src/deh_sound.c) | 0 | ||||
-rw-r--r-- | src/doom/deh_text.c | 126 | ||||
-rw-r--r-- | src/doom/deh_thing.c (renamed from src/deh_thing.c) | 0 | ||||
-rw-r--r-- | src/doom/deh_weapon.c (renamed from src/deh_weapon.c) | 0 | ||||
-rw-r--r-- | src/i_pcsound.c | 2 | ||||
-rw-r--r-- | src/i_sdlmusic.c | 2 | ||||
-rw-r--r-- | src/i_sdlsound.c | 2 | ||||
-rw-r--r-- | src/i_system.c | 2 | ||||
-rw-r--r-- | src/i_video.c | 2 | ||||
-rw-r--r-- | src/m_config.c | 2 | ||||
-rw-r--r-- | src/m_misc.c | 2 | ||||
-rw-r--r-- | src/net_client.c | 1 | ||||
-rw-r--r-- | src/s_sound.c | 2 | ||||
-rw-r--r-- | src/v_video.c | 2 |
31 files changed, 222 insertions, 132 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index a91de106..9e751dd9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -61,19 +61,7 @@ z_zone.c z_zone.h # source files needed for FEATURE_DEHACKED FEATURE_DEHACKED_SOURCE_FILES= \ -deh_ammo.c \ -deh_cheat.c \ -deh_defs.h \ -deh_frame.c \ -deh_io.c deh_io.h \ -deh_main.c deh_main.h \ -deh_mapping.c deh_mapping.h \ -deh_misc.c deh_misc.h \ -deh_ptr.c \ -deh_sound.c \ -deh_text.c \ -deh_thing.c \ -deh_weapon.c +deh_str.c deh_str.h # source files needed for FEATURE_MULTIPLAYER diff --git a/src/deh_text.c b/src/deh_str.c index 853e30e4..d2cc3ae6 100644 --- a/src/deh_text.c +++ b/src/deh_str.c @@ -24,23 +24,21 @@ // //----------------------------------------------------------------------------- +#include <stdlib.h> #include <string.h> #include "doomtype.h" +#include "deh_str.h" #include "z_zone.h" -#include "deh_defs.h" -#include "deh_io.h" -#include "deh_main.h" - typedef struct { char *from_text; char *to_text; } deh_substitution_t; -static deh_substitution_t **hash_table; +static deh_substitution_t **hash_table = NULL; static int hash_table_entries; static int hash_table_length = -1; @@ -91,6 +89,17 @@ char *DEH_String(char *s) return s; } +static void InitHashTable(void) +{ + // init hash table + + hash_table_entries = 0; + hash_table_length = 16; + hash_table = Z_Malloc(sizeof(deh_substitution_t *) * hash_table_length, + PU_STATIC, NULL); + memset(hash_table, 0, sizeof(deh_substitution_t *) * hash_table_length); +} + static void DEH_AddToHashtable(deh_substitution_t *sub); static void IncreaseHashtable(void) @@ -150,105 +159,22 @@ static void DEH_AddToHashtable(deh_substitution_t *sub) ++hash_table_entries; } -// Given a string length, find the maximum length of a -// string that can replace it. - -static int TXT_MaxStringLength(int len) -{ - // Enough bytes for the string and the NUL terminator - - len += 1; - - // All strings in doom.exe are on 4-byte boundaries, so we may be able - // to support a slightly longer string. - // Extend up to the next 4-byte boundary - - len += (4 - (len % 4)) % 4; - - // Less one for the NUL terminator. - - return len - 1; -} - -static void DEH_TextInit(void) -{ - // init hash table - - hash_table_entries = 0; - hash_table_length = 16; - hash_table = Z_Malloc(sizeof(deh_substitution_t *) * hash_table_length, - PU_STATIC, NULL); - memset(hash_table, 0, sizeof(deh_substitution_t *) * hash_table_length); -} - -static void *DEH_TextStart(deh_context_t *context, char *line) +void DEH_AddStringReplacement(char *from_text, char *to_text) { deh_substitution_t *sub; - int fromlen, tolen; - int i; - - if (sscanf(line, "Text %i %i", &fromlen, &tolen) != 2) - { - DEH_Warning(context, "Parse error on section start"); - return NULL; - } - - // Only allow string replacements that are possible in Vanilla Doom. - // Chocolate Doom is unforgiving! - - if (!deh_allow_long_strings && tolen > TXT_MaxStringLength(fromlen)) - { - DEH_Error(context, "Replacement string is longer than the maximum " - "possible in doom.exe"); - return NULL; - } - - sub = Z_Malloc(sizeof(deh_substitution_t), PU_STATIC, NULL); - sub->from_text = Z_Malloc(fromlen + 1, PU_STATIC, NULL); - sub->to_text = Z_Malloc(tolen + 1, PU_STATIC, NULL); - // read in the "from" text + // Initialise the hash table if this is the first time - for (i=0; i<fromlen; ++i) + if (hash_table_length < 0) { - int c; - - c = DEH_GetChar(context); - - sub->from_text[i] = c; + InitHashTable(); } - sub->from_text[fromlen] = '\0'; - - // read in the "to" text + sub = Z_Malloc(sizeof(*sub), PU_STATIC, 0); - for (i=0; i<tolen; ++i) - { - int c; - - c = DEH_GetChar(context); - - sub->to_text[i] = c; - } - sub->to_text[tolen] = '\0'; + sub->from_text = from_text; + sub->to_text = to_text; DEH_AddToHashtable(sub); - - return NULL; -} - -static void DEH_TextParseLine(deh_context_t *context, char *line, void *tag) -{ - // not used } -deh_section_t deh_section_text = -{ - "Text", - DEH_TextInit, - DEH_TextStart, - DEH_TextParseLine, - NULL, - NULL, -}; - diff --git a/src/deh_str.h b/src/deh_str.h new file mode 100644 index 00000000..986536de --- /dev/null +++ b/src/deh_str.h @@ -0,0 +1,46 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright(C) 2005 Simon Howard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +//----------------------------------------------------------------------------- +// +// Dehacked string replacements +// +//----------------------------------------------------------------------------- + +#ifndef DEH_STR_H +#define DEH_STR_H + +#include "doomfeatures.h" + +// Used to do dehacked text substitutions throughout the program + +#ifdef FEATURE_DEHACKED + +char *DEH_String(char *s); +void DEH_AddStringReplacement(char *from_text, char *to_text); + +#else + +#define DEH_String(x) (x) + +#endif + +#endif /* #ifndef DEH_STR_H */ + diff --git a/src/doom/Makefile.am b/src/doom/Makefile.am index 4d95266e..3e142f93 100644 --- a/src/doom/Makefile.am +++ b/src/doom/Makefile.am @@ -60,5 +60,21 @@ st_lib.c st_lib.h \ st_stuff.c st_stuff.h \ wi_stuff.c wi_stuff.h -libdoom_a_SOURCES=$(SOURCE_FILES) +FEATURE_DEHACKED_SOURCE_FILES = \ +deh_ammo.c \ +deh_cheat.c \ +deh_defs.h \ +deh_frame.c \ +deh_io.c deh_io.h \ +deh_main.c deh_main.h \ +deh_mapping.c deh_mapping.h \ +deh_misc.c deh_misc.h \ +deh_ptr.c \ +deh_sound.c \ +deh_text.c \ +deh_thing.c \ +deh_weapon.c + +libdoom_a_SOURCES = $(SOURCE_FILES) \ + $(FEATURE_DEHACKED_SOURCE_FILES) diff --git a/src/deh_ammo.c b/src/doom/deh_ammo.c index eb26ef75..eb26ef75 100644 --- a/src/deh_ammo.c +++ b/src/doom/deh_ammo.c diff --git a/src/deh_cheat.c b/src/doom/deh_cheat.c index d4ea9113..d4ea9113 100644 --- a/src/deh_cheat.c +++ b/src/doom/deh_cheat.c diff --git a/src/deh_defs.h b/src/doom/deh_defs.h index a6650544..a6650544 100644 --- a/src/deh_defs.h +++ b/src/doom/deh_defs.h diff --git a/src/deh_frame.c b/src/doom/deh_frame.c index 3972f8df..3972f8df 100644 --- a/src/deh_frame.c +++ b/src/doom/deh_frame.c diff --git a/src/deh_io.c b/src/doom/deh_io.c index 77cc40a1..77cc40a1 100644 --- a/src/deh_io.c +++ b/src/doom/deh_io.c diff --git a/src/deh_io.h b/src/doom/deh_io.h index 061a5a0e..061a5a0e 100644 --- a/src/deh_io.h +++ b/src/doom/deh_io.h diff --git a/src/deh_main.c b/src/doom/deh_main.c index 9d528b0a..9d528b0a 100644 --- a/src/deh_main.c +++ b/src/doom/deh_main.c diff --git a/src/deh_main.h b/src/doom/deh_main.h index 388c56de..8a0587ff 100644 --- a/src/deh_main.h +++ b/src/doom/deh_main.h @@ -30,6 +30,7 @@ #include "doomtype.h" #include "doomfeatures.h" #include "md5.h" +#include "deh_str.h" // These are the limits that dehacked uses (from dheinit.h in the dehacked // source). If these limits are exceeded, it does not generate an error, but @@ -45,20 +46,6 @@ boolean DEH_ParseAssignment(char *line, char **variable_name, char **value); void DEH_Checksum(md5_digest_t digest); -// deh_text.c: -// -// Used to do dehacked text substitutions throughout the program - -#ifdef FEATURE_DEHACKED - -char *DEH_String(char *s); - -#else - -#define DEH_String(x) (x) - -#endif - extern boolean deh_allow_long_strings; extern boolean deh_allow_long_cheats; diff --git a/src/deh_mapping.c b/src/doom/deh_mapping.c index b215b128..b215b128 100644 --- a/src/deh_mapping.c +++ b/src/doom/deh_mapping.c diff --git a/src/deh_mapping.h b/src/doom/deh_mapping.h index 4862dec9..4862dec9 100644 --- a/src/deh_mapping.h +++ b/src/doom/deh_mapping.h diff --git a/src/deh_misc.c b/src/doom/deh_misc.c index b57d0ef0..b57d0ef0 100644 --- a/src/deh_misc.c +++ b/src/doom/deh_misc.c diff --git a/src/deh_misc.h b/src/doom/deh_misc.h index a589b104..a589b104 100644 --- a/src/deh_misc.h +++ b/src/doom/deh_misc.h diff --git a/src/deh_ptr.c b/src/doom/deh_ptr.c index 87daf7d8..87daf7d8 100644 --- a/src/deh_ptr.c +++ b/src/doom/deh_ptr.c diff --git a/src/deh_sound.c b/src/doom/deh_sound.c index b28154d9..b28154d9 100644 --- a/src/deh_sound.c +++ b/src/doom/deh_sound.c diff --git a/src/doom/deh_text.c b/src/doom/deh_text.c new file mode 100644 index 00000000..caac59a3 --- /dev/null +++ b/src/doom/deh_text.c @@ -0,0 +1,126 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright(C) 2005 Simon Howard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +//----------------------------------------------------------------------------- +// +// Parses Text substitution sections in dehacked files +// +//----------------------------------------------------------------------------- + +#include <string.h> + +#include "doomtype.h" + +#include "z_zone.h" + +#include "deh_defs.h" +#include "deh_io.h" +#include "deh_main.h" + +// Given a string length, find the maximum length of a +// string that can replace it. + +static int TXT_MaxStringLength(int len) +{ + // Enough bytes for the string and the NUL terminator + + len += 1; + + // All strings in doom.exe are on 4-byte boundaries, so we may be able + // to support a slightly longer string. + // Extend up to the next 4-byte boundary + + len += (4 - (len % 4)) % 4; + + // Less one for the NUL terminator. + + return len - 1; +} + +static void *DEH_TextStart(deh_context_t *context, char *line) +{ + char *from_text, *to_text; + int fromlen, tolen; + int i; + + if (sscanf(line, "Text %i %i", &fromlen, &tolen) != 2) + { + DEH_Warning(context, "Parse error on section start"); + return NULL; + } + + // Only allow string replacements that are possible in Vanilla Doom. + // Chocolate Doom is unforgiving! + + if (!deh_allow_long_strings && tolen > TXT_MaxStringLength(fromlen)) + { + DEH_Error(context, "Replacement string is longer than the maximum " + "possible in doom.exe"); + return NULL; + } + + from_text = Z_Malloc(fromlen + 1, PU_STATIC, NULL); + to_text = Z_Malloc(tolen + 1, PU_STATIC, NULL); + + // read in the "from" text + + for (i=0; i<fromlen; ++i) + { + int c; + + c = DEH_GetChar(context); + + from_text[i] = c; + } + + from_text[fromlen] = '\0'; + + // read in the "to" text + + for (i=0; i<tolen; ++i) + { + int c; + + c = DEH_GetChar(context); + + to_text[i] = c; + } + to_text[tolen] = '\0'; + + DEH_AddStringReplacement(from_text, to_text); + + return NULL; +} + +static void DEH_TextParseLine(deh_context_t *context, char *line, void *tag) +{ + // not used +} + +deh_section_t deh_section_text = +{ + "Text", + NULL, + DEH_TextStart, + DEH_TextParseLine, + NULL, + NULL, +}; + diff --git a/src/deh_thing.c b/src/doom/deh_thing.c index 5400ae60..5400ae60 100644 --- a/src/deh_thing.c +++ b/src/doom/deh_thing.c diff --git a/src/deh_weapon.c b/src/doom/deh_weapon.c index 7ffa159a..7ffa159a 100644 --- a/src/deh_weapon.c +++ b/src/doom/deh_weapon.c diff --git a/src/i_pcsound.c b/src/i_pcsound.c index 620acf39..ad82180c 100644 --- a/src/i_pcsound.c +++ b/src/i_pcsound.c @@ -27,7 +27,7 @@ #include "doomtype.h" -#include "deh_main.h" +#include "deh_str.h" #include "s_sound.h" #include "sounds.h" diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c index 2e4562ab..2ac207d1 100644 --- a/src/i_sdlmusic.c +++ b/src/i_sdlmusic.c @@ -34,7 +34,7 @@ #include "memio.h" #include "mus2mid.h" -#include "deh_main.h" +#include "deh_str.h" #include "m_misc.h" #include "s_sound.h" #include "w_wad.h" diff --git a/src/i_sdlsound.c b/src/i_sdlsound.c index 6f765be4..5c6dd5f7 100644 --- a/src/i_sdlsound.c +++ b/src/i_sdlsound.c @@ -38,7 +38,7 @@ #include <samplerate.h> #endif -#include "deh_main.h" +#include "deh_str.h" #include "i_system.h" #include "s_sound.h" #include "m_argv.h" diff --git a/src/i_system.c b/src/i_system.c index 218acc59..c3b3211e 100644 --- a/src/i_system.c +++ b/src/i_system.c @@ -38,7 +38,7 @@ #include <unistd.h> #endif -#include "deh_main.h" +#include "deh_str.h" #include "doomtype.h" #include "doomstat.h" #include "m_argv.h" diff --git a/src/i_video.c b/src/i_video.c index dc4a249e..4c70c48c 100644 --- a/src/i_video.c +++ b/src/i_video.c @@ -33,7 +33,7 @@ #include "icon.c" #include "config.h" -#include "deh_main.h" +#include "deh_str.h" #include "doomtype.h" #include "doomkeys.h" #include "i_joystick.h" diff --git a/src/m_config.c b/src/m_config.c index bea255d2..bb8d5020 100644 --- a/src/m_config.c +++ b/src/m_config.c @@ -32,7 +32,7 @@ #include <errno.h> #include "config.h" -#include "deh_main.h" +#include "deh_str.h" #include "doomtype.h" #include "doomkeys.h" #include "doomfeatures.h" diff --git a/src/m_misc.c b/src/m_misc.c index 88519b3c..db62fd42 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -45,7 +45,7 @@ #include "doomtype.h" #include "doomstat.h" -#include "deh_main.h" +#include "deh_str.h" #include "i_swap.h" #include "i_system.h" diff --git a/src/net_client.c b/src/net_client.c index 26cd2133..f85f2b94 100644 --- a/src/net_client.c +++ b/src/net_client.c @@ -29,6 +29,7 @@ #include "doomtype.h" #include "doomstat.h" #include "deh_main.h" +#include "deh_str.h" #include "g_game.h" #include "i_system.h" #include "i_timer.h" diff --git a/src/s_sound.c b/src/s_sound.c index f3f6bf1f..26bbb5fd 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -29,7 +29,7 @@ #include "i_system.h" #include "doomfeatures.h" -#include "deh_main.h" +#include "deh_str.h" #include "doomstat.h" #include "doomtype.h" diff --git a/src/v_video.c b/src/v_video.c index bea0171c..918e64e1 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -34,7 +34,7 @@ #include "doomtype.h" #include "doomdata.h" -#include "deh_main.h" +#include "deh_str.h" #include "m_bbox.h" #include "i_swap.h" #include "i_video.h" |