Skip to content

Commit

Permalink
DIRECTOR: Lingo: Implement 'contains' and 'starts' string operators
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Aug 3, 2016
1 parent 8084989 commit da408c0
Show file tree
Hide file tree
Showing 9 changed files with 715 additions and 579 deletions.
4 changes: 3 additions & 1 deletion engines/director/director.cpp
Expand Up @@ -134,7 +134,9 @@ Common::Error DirectorEngine::run() {
put z1\n\
put chars(\"Macromedia\", 6, 6)\n\
put chars(\"Macromedia\", 6, 10)\n\
put chars(\"Macromedia\", 6, 15)\n\
put chars(\"Macromedia\", -1, 15)\n\
if z1 contains \"Me\xafW\" then put \"Contains\"\n\
else put \"Doesn't contain\"\n\
", kMovieScript, 2);

_lingo->executeScript(kMovieScript, 2);
Expand Down
46 changes: 46 additions & 0 deletions engines/director/lingo/lingo-code.cpp
Expand Up @@ -311,6 +311,52 @@ void Lingo::c_concat() {
g_lingo->push(d1);
}

void Lingo::c_contains() {
Datum d2 = g_lingo->pop();
Datum d1 = g_lingo->pop();

d1.toString();
d2.toString();

Common::String *s1 = g_lingo->toLowercaseMac(d1.u.s);
Common::String *s2 = g_lingo->toLowercaseMac(d2.u.s);

int res = s1->contains(*s2) ? 1 : 0;

delete d1.u.s;
delete d2.u.s;
delete s1;
delete s2;

d1.type = INT;
d1.u.i = res;

g_lingo->push(d1);
}

void Lingo::c_starts() {
Datum d2 = g_lingo->pop();
Datum d1 = g_lingo->pop();

d1.toString();
d2.toString();

Common::String *s1 = g_lingo->toLowercaseMac(d1.u.s);
Common::String *s2 = g_lingo->toLowercaseMac(d2.u.s);

int res = s1->hasPrefix(*s2) ? 1 : 0;

delete d1.u.s;
delete d2.u.s;
delete s1;
delete s2;

d1.type = INT;
d1.u.i = res;

g_lingo->push(d1);
}

void Lingo::c_and() {
Datum d2 = g_lingo->pop();
Datum d1 = g_lingo->pop();
Expand Down
782 changes: 400 additions & 382 deletions engines/director/lingo/lingo-gr.cpp

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions engines/director/lingo/lingo-gr.h
Expand Up @@ -84,7 +84,9 @@
tAND = 300,
tOR = 301,
tNOT = 302,
tCONCAT = 303
tCONCAT = 303,
tCONTAINS = 304,
tSTARTS = 305
};
#endif
/* Tokens. */
Expand Down Expand Up @@ -134,6 +136,8 @@
#define tOR 301
#define tNOT 302
#define tCONCAT 303
#define tCONTAINS 304
#define tSTARTS 305



Expand All @@ -149,7 +153,7 @@ typedef union YYSTYPE
int narg; /* number of arguments */
}
/* Line 1529 of yacc.c. */
#line 153 "engines/director/lingo/lingo-gr.hpp"
#line 157 "engines/director/lingo/lingo-gr.hpp"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
Expand Down
5 changes: 4 additions & 1 deletion engines/director/lingo/lingo-gr.y
Expand Up @@ -77,7 +77,8 @@ using namespace Director;
%token tDOWN tELSE tNLELSIF tEND tEXIT tFRAME tGLOBAL tGO tIF tINTO tLOOP tMACRO
%token tMCI tMCIWAIT tMOVIE tNEXT tOF tPREVIOUS tPUT tREPEAT tSET tTHEN tTO
%token tWITH tWHILE tNLELSE
%token tGE tLE tGT tLT tEQ tNEQ tAND tOR tNOT tCONCAT
%token tGE tLE tGT tLT tEQ tNEQ tAND tOR tNOT
%token tCONCAT tCONTAINS tSTARTS

%type<code> asgn begin elseif elsestmtoneliner end expr if repeatwhile repeatwith stmtlist
%type<s> gotoframe gotomovie
Expand Down Expand Up @@ -339,6 +340,8 @@ expr: INT {
| tNOT expr %prec UNARY { g_lingo->code1(g_lingo->c_not); }
| expr '&' expr { g_lingo->code1(g_lingo->c_ampersand); }
| expr tCONCAT expr { g_lingo->code1(g_lingo->c_concat); }
| expr tCONTAINS expr { g_lingo->code1(g_lingo->c_contains); }
| expr tSTARTS expr { g_lingo->code1(g_lingo->c_starts); }
| '+' expr %prec UNARY { $$ = $2; }
| '-' expr %prec UNARY { $$ = $2; g_lingo->code1(g_lingo->c_negate); }
| '(' expr ')' { $$ = $2; }
Expand Down

0 comments on commit da408c0

Please sign in to comment.