Skip to content

Commit

Permalink
IdTech1Converter|HexLex: Handle MAPINFO syntax errors with de::Error
Browse files Browse the repository at this point in the history
Also disabled code interacting with the DED db, so that the plugin can
be built without error.
  • Loading branch information
danij-deng committed Jul 27, 2014
1 parent 99ed35f commit 443d71d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 11 deletions.
5 changes: 5 additions & 0 deletions doomsday/plugins/idtech1converter/include/hexlex.h
Expand Up @@ -33,6 +33,11 @@ namespace idtech1 {
*/
class HexLex
{
public:
/// Base error for syntax errors at the level of lexical analysis (e.g.,
/// a non-terminated string constant). @ingroup errors
DENG2_ERROR(SyntaxError);

public:
/**
* Construct a new lexer and optionally prepare a script for parsing.
Expand Down
11 changes: 6 additions & 5 deletions doomsday/plugins/idtech1converter/src/hexlex.cpp
Expand Up @@ -32,7 +32,8 @@ namespace idtech1 {

void HexLex::checkOpen()
{
if(!_script) Con_Error("HexLex: No script to parse!");
if(_script) return;
throw Error("HexLex::checkOpen", "No script to parse!");
}

bool HexLex::atEnd()
Expand All @@ -43,8 +44,7 @@ bool HexLex::atEnd()

void HexLex::syntaxError(char const *message)
{
Con_Error("HexLex: SyntaxError in \"%s\" on line #%i.\n%s",
F_PrettyPath(Str_Text(&_sourcePath)), _lineNumber, message);
throw SyntaxError("HexLex", String("%1\nIn \"").arg(message) + NativePath(Str_Text(&_sourcePath)).pretty() + "\" on line #" + String::number(_lineNumber));
}

HexLex::HexLex(ddstring_s const *script, ddstring_s const *sourcePath)
Expand Down Expand Up @@ -219,8 +219,9 @@ ddouble HexLex::readNumber()
ddouble number = strtod(Str_Text(&_token), &stopper);
if(*stopper != 0)
{
Con_Error("HexLex: Non-numeric constant '%s' in \"%s\" on line #%i",
Str_Text(&_token), F_PrettyPath(Str_Text(&_sourcePath)), _lineNumber);
return 0;
//Con_Error("HexLex: Non-numeric constant '%s' in \"%s\" on line #%i",
// Str_Text(&_token), F_PrettyPath(Str_Text(&_sourcePath)), _lineNumber);
}

return number;
Expand Down
56 changes: 50 additions & 6 deletions doomsday/plugins/idtech1converter/src/mapinfotranslator.cpp
Expand Up @@ -33,6 +33,50 @@ HexDefs hexDefs;

namespace internal {

static de::Uri composeMapUri(uint episode, uint map)
{
de::String mapId;
#if __JDOOM64__
mapId = de::String("map%1").arg(map+1, 2, 10, QChar('0'));
DENG2_UNUSED(episode);
#elif __JDOOM__
if(gameModeBits & GM_ANY_DOOM2)
mapId = de::String("map%1").arg(map+1, 2, 10, QChar('0'));
else
mapId = de::String("e%1m%2").arg(episode+1).arg(map+1);
#elif __JHERETIC__
mapId = de::String("e%1m%2").arg(episode+1).arg(map+1);
#else
mapId = de::String("map%1").arg(map+1, 2, 10, QChar('0'));
DENG2_UNUSED(episode);
#endif
return de::Uri("Maps", mapId);
}

static uint mapNumberFor(de::Uri const &mapUri)
{
String path = mapUri.path();
if(!path.isEmpty())
{
#if __JDOOM__ || __JHERETIC__
# if __JDOOM__
if(gameModeBits & (GM_ANY_DOOM | ~GM_DOOM_CHEX))
# endif
{
if(path.at(0).toLower() == 'e' && path.at(2).toLower() == 'm')
{
return path.substr(3).toInt() - 1;
}
}
#endif
if(path.beginsWith("map", Qt::CaseInsensitive))
{
return path.substr(3).toInt() - 1;
}
}
return 0;
}

static inline String defaultSkyMaterial()
{
#ifdef __JHEXEN__
Expand All @@ -56,8 +100,8 @@ static void setMusicCDTrack(char const *musicId, int track)
{
LOG_RES_VERBOSE("setMusicCDTrack: musicId=%s, track=%i") << musicId << track;

int cdTrack = track;
Def_Set(DD_DEF_MUSIC, Def_Get(DD_DEF_MUSIC, musicId, 0), DD_CD_TRACK, &cdTrack);
//int cdTrack = track;
//Def_Set(DD_DEF_MUSIC, Def_Get(DD_DEF_MUSIC, musicId, 0), DD_CD_TRACK, &cdTrack);
}

} // namespace internal
Expand Down Expand Up @@ -393,7 +437,7 @@ DENG2_PIMPL(MapInfoParser)
{
throw ParseError(String("Invalid map number '%1' on line #%2").arg(mapNumber).arg(lexer.lineNumber()));
}
mapUri = G_ComposeMapUri(0, mapNumber - 1);
mapUri = composeMapUri(0, mapNumber - 1);
}

// Lookup an existing map info from the database.
Expand All @@ -413,7 +457,7 @@ DENG2_PIMPL(MapInfoParser)
info->set("map", mapUri.compose());

// Attempt to extract the "warp translation" number.
info->set("warpTrans", G_MapNumberFor(mapUri));
info->set("warpTrans", mapNumberFor(mapUri));
}

// Map title must follow the number.
Expand All @@ -423,11 +467,11 @@ DENG2_PIMPL(MapInfoParser)
if(!title.compareWithoutCase("lookup"))
{
title = Str_Text(lexer.readString());
char *found = 0;
/*char *found = 0;
if(Def_Get(DD_DEF_TEXT, title.toUtf8().constData(), &found) >= 0)
{
title = String(found);
}
}*/
}
info->set("title", title);
}
Expand Down

0 comments on commit 443d71d

Please sign in to comment.