From cb1c0a9afb04c0c9c6681af5ea71250419f3bcaa Mon Sep 17 00:00:00 2001 From: twanvl Date: Thu, 29 Mar 2007 18:23:09 +0000 Subject: [PATCH] nicer error messags when aliases don't but should apply git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@242 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/util/io/reader.cpp | 21 +++++++++++++++------ src/util/io/reader.hpp | 7 ++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/util/io/reader.cpp b/src/util/io/reader.cpp index c621a893..0f3f8c29 100644 --- a/src/util/io/reader.cpp +++ b/src/util/io/reader.cpp @@ -32,9 +32,9 @@ Reader::Reader(const String& filename) } void Reader::addAlias(Version end_version, const Char* a, const Char* b) { - if (file_app_version < end_version) { - aliasses[a] = b; - } + Alias& alias = aliasses[a]; + alias.new_key = b; + alias.end_version = end_version; } void Reader::handleAppVersion() { @@ -126,13 +126,22 @@ void Reader::readLine() { void Reader::unknownKey() { // aliasses? - map::const_iterator it = aliasses.find(key); + map::const_iterator it = aliasses.find(key); if (it != aliasses.end()) { - if (aliasses.find(it->second) != aliasses.end()) { + if (aliasses.find(it->second.new_key) != aliasses.end()) { // alias points to another alias, don't follow it, there is the risk of infinite loops + } else if (it->second.end_version <= file_version) { + // alias not used for this version, use in warning + if (indent == expected_indent) { + warning(_("Unexpected key: '") + key + _("' try '") + it->second.new_key + _("'")); + do { + moveNext(); + } while (indent > expected_indent); + return; + } } else { // try this key instead - key = it->second; + key = it->second.new_key; return; } } diff --git a/src/util/io/reader.hpp b/src/util/io/reader.hpp index b4eb1e7c..969c8417 100644 --- a/src/util/io/reader.hpp +++ b/src/util/io/reader.hpp @@ -121,7 +121,12 @@ class Reader { /// Did we just open a block (i.e. not read any more lines of it)? bool just_opened; /// Aliasses for compatability - map aliasses; + struct Alias { + String new_key; + Version end_version; + }; + /// Aliasses for compatability + map aliasses; /// Filename for error messages String filename;