Changeset 181


Ignore:
Timestamp:
1999-03-02T09:39:54+13:00 (25 years ago)
Author:
sjboddie
Message:

Added eq and ne functionality to _If_

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/lib/display.cpp

    r178 r181  
    1212/*
    1313   $Log$
     14   Revision 1.10  1999/03/01 20:39:54  sjboddie
     15   Added eq and ne functionality to _If_
     16
    1417   Revision 1.9  1999/03/01 01:18:09  sjboddie
    1518
     
    981984
    982985void displayclass::expandstring (text_t package, const text_t &inputtext,
    983                 text_t &outputtext, int recursiondepth)
     986                text_t &outputtext, int recursiondepth)
    984987{
    985988  text_t macroname, macropackage, macroargs;
     
    12131216}
    12141217
     1218
     1219// evaluates a boolean expression
     1220// returns false if expr equals "" or "0".
     1221// otherwise returns true *unless* expr is
     1222// format "XXXX" eq/ne "dddd" in which case
     1223// the two quoted strings are compared
     1224bool displayclass::boolexpr (text_t package, const text_t &expr, int recursiondepth) {
     1225
     1226  if (expr.empty()) return false;
     1227
     1228  text_t expexpr;
     1229  if (package.empty()) package = "Global"; 
     1230  expandstring (package, expr, expexpr, recursiondepth);
     1231
     1232  if (expexpr.empty() || expexpr == "0") return false;
     1233  if (expr[0] != '\"') return true;
     1234
     1235  // don't use expexpr while separating quoted parts of
     1236  // expression just in case expanded out macros contain
     1237  // quotes
     1238  text_t::const_iterator here = expr.begin();
     1239  text_t::const_iterator end = expr.end();
     1240
     1241  int quotecount = 0;
     1242  text_t string1, expstring1;
     1243  text_t string2, expstring2;
     1244  text_t op;
     1245  while (here != end) {
     1246    if (*here == '"') quotecount++;
     1247    else if (quotecount == 1) string1.push_back(*here);
     1248    else if ((quotecount == 2) && (*here != ' ') && (*here != '\n'))
     1249      op.push_back(*here);
     1250    else if (quotecount == 3) string2.push_back(*here);
     1251    else if (quotecount == 4) break;
     1252    here ++;
     1253  }
     1254 
     1255  expandstring (package, string1, expstring1, recursiondepth);
     1256  expandstring (package, string2, expstring2, recursiondepth);
     1257
     1258  if (op == "eq")
     1259    if (expstring1 == expstring2) return true;
     1260    else return false;
     1261  else if (op == "ne")
     1262    if (expstring1 != expstring2) return true;
     1263    else return false;
     1264  else
     1265    return true; // any badly formatted string will return true
     1266}
     1267
     1268
    12151269// (recursively) expand out a macro
    12161270// returns true  if the macro was found
     
    12651319      // found a quoted section
    12661320      quote = c;
     1321      aparam.push_back(c);
    12671322
    12681323    } else if (quote!='\0' && c==quote) {
    12691324      // found the end of a quote
    12701325      quote = '\0';
     1326      aparam.push_back(c);
    12711327
    12721328    } else if (quote=='\0' && c==',') {
     
    12881344  }
    12891345
    1290   // I'm only supporting a simple version of _If_ at the moment
    12911346  if (macroname == "If") {
    12921347    // get the condition, then clause and else clause
     
    13151370     
    13161371      // test the expanded string
    1317       if ((tmpoutput.size()) && (tmpoutput != "false") && (tmpoutput != "0")) {
     1372      if (boolexpr (macropackage, *paramcond, recursiondepth+1)) {
     1373    //(tmpoutput.size()) && (tmpoutput != "false") && (tmpoutput != "0")) {
    13181374    // true
    13191375    if (paramthen != paramend)
Note: See TracChangeset for help on using the changeset viewer.