Skip to content

Commit

Permalink
DIRECTOR: Lingo: Implement MCI command parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Aug 3, 2016
1 parent df50e60 commit 75d759c
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
3 changes: 2 additions & 1 deletion engines/director/director.cpp
Expand Up @@ -70,7 +70,8 @@ Common::Error DirectorEngine::run() {

_lingo = new Lingo();

_lingo->parse("mci \"open MM\\T005045a.wav type WaveAudio alias T005045a\"");
_lingo->parse("mci \"open MM\\T005045a.wav type WaveAudio alias T005045a\"\n\
mci \"play T005045a from 22710 to 32872\"");

#if 0
_lingo->parse("set x = 1\n\
Expand Down
97 changes: 96 additions & 1 deletion engines/director/lingo/lingo-funcs.cpp
Expand Up @@ -24,8 +24,103 @@

namespace Director {

enum MCITokenType {
kMCITokenNone,

kMCITokenOpen,
kMCITokenWait,
kMCITokenPlay,

kMCITokenType,
kMCITokenAlias,
kMCITokenBuffer,
kMCITokenFrom,
kMCITokenTo
};

struct MCIToken {
MCITokenType command;
MCITokenType flag;
const char *token;
int pos;
} MCITokens[] = {
{ kMCITokenNone, kMCITokenOpen, "open", 0 },
{ kMCITokenOpen, kMCITokenType, "type", 1 },
{ kMCITokenOpen, kMCITokenAlias, "alias", 2 },
{ kMCITokenOpen, kMCITokenBuffer, "buffer", 3 },

{ kMCITokenNone, kMCITokenPlay, "play", 0 },
{ kMCITokenPlay, kMCITokenFrom, "from", 1 },
{ kMCITokenPlay, kMCITokenTo, "to", 2 },

{ kMCITokenNone, kMCITokenWait, "wait", 0 },

{ kMCITokenNone, kMCITokenNone, 0, 0 }
};

int Lingo::func_mci(Common::String *s) {
warning("STUB: mci(\"%s\")", s->c_str());
Common::String params[5];
MCITokenType command = kMCITokenNone;

s->trim();
s->toLowercase();

MCITokenType state = kMCITokenNone;
Common::String token;
const char *ptr = s->c_str();
int respos = -1;

while (*ptr) {
while (*ptr && *ptr == ' ')
ptr++;

token.clear();

while (*ptr && *ptr != ' ')
token += *ptr++;

switch (state) {
case kMCITokenNone:
{
MCIToken *f = MCITokens;

while (f->token) {
if (command == f->command && token == f->token)
break;

f++;
}

if (command == kMCITokenNone) { // We caught command
command = f->flag; // Switching to processing this command parameters
} else if (f->flag == kMCITokenNone) { // Unmatched token, parsing as filename
if (!params[0].empty())
warning("Duplicate filename in MCI command: %s -> %s", params[0].c_str(), token.c_str());
params[0] = token;
} else {
state = f->flag;
respos = f->pos;
}
break;
}
default:
params[respos] = token;
state = kMCITokenNone;
break;
}

}

switch (command) {
case kMCITokenOpen:
warning("MCI open file: %s, type: %s, alias: %s buffer: %s", params[0].c_str(), params[1].c_str(), params[2].c_str(), params[3].c_str());
break;
case kMCITokenPlay:
warning("MCI play file: %s, from: %s, to: %s", params[0].c_str(), params[1].c_str(), params[2].c_str());
break;
default:
warning("Unhandled MCI command: %s", s->c_str());
}

return 0;
}
Expand Down

0 comments on commit 75d759c

Please sign in to comment.