From 5523ec69d8d6b71ed4b064aef87cbadca4bd3dc4 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Wed, 23 Jul 2008 21:33:21 +0000 Subject: [PATCH] better scheme for handling '=' infix git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2203 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/command.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/source/src/command.cpp b/source/src/command.cpp index c6bca904..c7f5e79b 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -190,7 +190,7 @@ char *lookup(char *n) // find value of ident reference return n; } -char *parseword(const char *&p) // parse single argument, including expressions +char *parseword(const char *&p, int arg, int &infix) // parse single argument, including expressions { p += strspn(p, " \t\r"); if(p[0]=='/' && p[1]=='/') p += strcspn(p, "\n\0"); @@ -208,6 +208,10 @@ char *parseword(const char *&p) // parse single argument, const char *word = p; p += strcspn(p, "; \t\r\n\0"); if(p-word==0) return NULL; + if(arg==1 && p-word==1) switch(*word) + { + case '=': infix = *word; break; + } char *s = newstring(word, p-word); if(*s=='$') return lookup(s); return s; @@ -248,12 +252,12 @@ char *executeret(const char *p) // all evaluation hap #define setretval(v) { char *rv = v; if(rv) retval = rv; } for(bool cont = true; cont;) // for each ; seperated statement { - int numargs = MAXWORDS; + int numargs = MAXWORDS, infix = 0; loopi(MAXWORDS) // collect all argument values { w[i] = (char *)""; if(i>numargs) continue; - char *s = parseword(p); // parse and evaluate exps + char *s = parseword(p, i, infix); // parse and evaluate exps if(s) w[i] = s; else numargs = i; } @@ -265,6 +269,18 @@ char *executeret(const char *p) // all evaluation hap DELETEA(retval); + if(infix) + { + switch(infix) + { + case '=': + DELETEA(w[1]); + swap(w[0], w[1]); + c = (char *)"alias"; + break; + } + } + ident *id = idents->access(c); if(!id) {