From 1c527635393b7bc090eb9833f302b329f8aacd23 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Fri, 6 Mar 2015 01:43:48 +0100 Subject: [PATCH] replaced 'file_identifier' tag by informal file header comment --- src/files.c | 11 ++--------- src/libgame/setup.c | 45 ++++++++++++++++----------------------------- src/libgame/setup.h | 5 +---- 3 files changed, 19 insertions(+), 42 deletions(-) diff --git a/src/files.c b/src/files.c index ff600579..e17322d6 100644 --- a/src/files.c +++ b/src/files.c @@ -8437,7 +8437,6 @@ void LoadSetup() { char *player_name_new; - checkSetupFileHashIdentifier(setup_file_hash, filename,getCookie("SETUP")); decodeSetupFileHash(setup_file_hash); freeSetupFileHash(setup_file_hash); @@ -8474,7 +8473,6 @@ void LoadSetup_EditorCascade() if (setup_file_hash) { - checkSetupFileHashIdentifier(setup_file_hash, filename,getCookie("SETUP")); decodeSetupFileHash_EditorCascade(setup_file_hash); freeSetupFileHash(setup_file_hash); @@ -8497,9 +8495,7 @@ void SaveSetup() return; } - fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER, - getCookie("SETUP"))); - fprintf(file, "\n"); + fprintFileHeader(file, SETUP_FILENAME); /* global setup */ si = setup; @@ -8572,12 +8568,9 @@ void SaveSetup_EditorCascade() return; } - fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER, - getCookie("SETUP"))); - fprintf(file, "\n"); + fprintFileHeader(file, EDITORCASCADE_FILENAME); seci = setup.editor_cascade; - fprintf(file, "\n"); for (i = 0; i < NUM_EDITOR_CASCADE_SETUP_TOKENS; i++) fprintf(file, "%s\n", getSetupLine(editor_cascade_setup_tokens, "", i)); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 69e25fa9..aa97093c 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -30,7 +30,6 @@ #include "hash.h" -#define USE_FILE_IDENTIFIERS FALSE /* do not use identifiers anymore */ #define ENABLE_UNUSED_CODE FALSE /* for currently unused functions */ #define NUM_LEVELCLASS_DESC 8 @@ -1475,6 +1474,17 @@ char *getCookie(char *file_type) return cookie; } +void fprintFileHeader(FILE *file, char *basename) +{ + char *prefix = "# "; + char *sep1 = "="; + + fprintf_line_with_prefix(file, prefix, sep1, 77); + fprintf(file, "%s%s\n", prefix, basename); + fprintf_line_with_prefix(file, prefix, sep1, 77); + fprintf(file, "\n"); +} + int getFileVersionFromCookieString(const char *cookie) { const char *ptr_cookie1, *ptr_cookie2; @@ -1522,6 +1532,7 @@ boolean checkCookieString(const char *cookie, const char *template) return TRUE; } + /* ------------------------------------------------------------------------- */ /* setup file list and hash handling functions */ /* ------------------------------------------------------------------------- */ @@ -2104,19 +2115,6 @@ SetupFileHash *loadSetupFileHash(char *filename) return setup_file_hash; } -void checkSetupFileHashIdentifier(SetupFileHash *setup_file_hash, - char *filename, char *identifier) -{ -#if USE_FILE_IDENTIFIERS - char *value = getHashEntry(setup_file_hash, TOKEN_STR_FILE_IDENTIFIER); - - if (value == NULL) - Error(ERR_WARN, "config file '%s' has no file identifier", filename); - else if (!checkCookieString(value, identifier)) - Error(ERR_WARN, "config file '%s' has wrong file identifier", filename); -#endif -} - /* ========================================================================= */ /* setup file stuff */ @@ -2820,9 +2818,6 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first, leveldir_new->subdir = getStringCopy(directory_name); - checkSetupFileHashIdentifier(setup_file_hash, filename, - getCookie("LEVELINFO")); - /* set all structure fields according to the token/value pairs */ ldi = *leveldir_new; for (i = 0; i < NUM_LEVELINFO_TOKENS; i++) @@ -3450,8 +3445,7 @@ static void SaveUserLevelInfo() token_value_position = TOKEN_VALUE_POSITION_SHORT; - fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER, - getCookie("LEVELINFO"))); + fprintFileHeader(file, LEVELINFO_FILENAME); ldi = *level_info; for (i = 0; i < NUM_LEVELINFO_TOKENS; i++) @@ -3609,9 +3603,6 @@ void LoadLevelSetup_LastSeries() if (leveldir_current == NULL) leveldir_current = getFirstValidTreeInfoEntry(leveldir_first); - checkSetupFileHashIdentifier(level_setup_hash, filename, - getCookie("LEVELSETUP")); - freeSetupFileHash(level_setup_hash); } else @@ -3645,8 +3636,7 @@ static void SaveLevelSetup_LastSeries_Ext(boolean deactivate_last_level_series) return; } - fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER, - getCookie("LEVELSETUP"))); + fprintFileHeader(file, LEVELSETUP_FILENAME); if (deactivate_last_level_series) fprintf(file, "# %s\n# ", "the following level set may have caused a problem and was deactivated"); @@ -3781,9 +3771,6 @@ void LoadLevelSetup_SeriesInfo() } END_HASH_ITERATION(hash, itr) - checkSetupFileHashIdentifier(level_setup_hash, filename, - getCookie("LEVELSETUP")); - freeSetupFileHash(level_setup_hash); } else @@ -3816,8 +3803,8 @@ void SaveLevelSetup_SeriesInfo() return; } - fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER, - getCookie("LEVELSETUP"))); + fprintFileHeader(file, LEVELSETUP_FILENAME); + fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_LAST_PLAYED_LEVEL, level_nr_str)); fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_HANDICAP_LEVEL, diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 090584b5..c2f0692e 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -81,9 +81,6 @@ #define TYPE_ENTER_OR_LEAVE (TYPE_ENTER | TYPE_LEAVE) -/* cookie token for file identifier and version number */ -#define TOKEN_STR_FILE_IDENTIFIER "file_identifier" - struct TokenInfo { int type; @@ -280,6 +277,7 @@ void InitUserDataDirectory(void); void SetFilePermissions(char *, int); char *getCookie(char *); +void fprintFileHeader(FILE *, char *); int getFileVersionFromCookieString(const char *); boolean checkCookieString(const char *, const char *); @@ -300,7 +298,6 @@ char *getHashEntry(SetupFileHash *, char *); void setHashEntry(SetupFileHash *, char *, char *); char *removeHashEntry(SetupFileHash *, char *); SetupFileHash *loadSetupFileHash(char *); -void checkSetupFileHashIdentifier(SetupFileHash *, char *, char *); void setSetupInfo(struct TokenInfo *, int, char *); char *getSetupValue(int, void *); char *getSetupLine(struct TokenInfo *, char *, int); -- 2.34.1