Changeset 2965
- Timestamp:
- 2002-02-13T11:46:47+13:00 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/lib/display.cpp
r1860 r2965 28 28 /* 29 29 $Log$ 30 Revision 1.25 2002/02/12 22:46:47 jrm21 31 Allow nested _If_ macros. We now count '(' and ')' characters, so you can now 32 do _If_(_foo_, _If_(_bar_,FOOBAR,FOONOBAR), _If_(_bar_,NOFOOBAR,NOFOONOBAR) ) 33 inside a macro file. If you want to display a bracket, you can escape it. 34 Previously we had assumed that a ',' marked the end of a toplevel argument. 35 30 36 Revision 1.24 2001/01/25 18:26:44 cs025 31 37 Included CORBA branch for first time … … 1069 1075 text_t::const_iterator ttend = inputtext.end(); 1070 1076 unsigned short c = '\0'; 1077 int openbrackets=0; 1071 1078 1072 1079 if (package.empty()) package = "Global"; 1073 1080 1074 1081 outputtext.clear(); 1075 1076 1082 // use one-character lookahead 1077 1083 if (tthere != ttend) c = (*tthere); … … 1138 1144 { 1139 1145 // found a macro!!!! (maybe) 1140 1141 1146 c = my_ttnextchar (tthere, ttend); // skip the '_' 1142 1147 … … 1145 1150 { 1146 1151 c = my_ttnextchar (tthere, ttend); // skip '(' 1147 1152 openbrackets++; 1148 1153 // have to be careful of quotes 1149 1154 unsigned short quote = '\0'; … … 1161 1166 { 1162 1167 // not in a quote at the moment 1163 if (c == ' )')1168 if (c == '(') 1164 1169 { 1165 // found end of the arguments 1166 c = my_ttnextchar (tthere, ttend); // skip ')' 1167 break; 1168 1170 openbrackets++; 1171 //// macroargs.push_back (c); 1172 //// c = my_ttnextchar (tthere, ttend); 1173 } 1174 else if (c == ')') 1175 { 1176 openbrackets--; 1177 if (openbrackets==0) { 1178 // found end of the arguments 1179 c = my_ttnextchar (tthere, ttend); // skip ')' 1180 break; 1181 } else { 1182 // nested brackets 1183 macroargs.push_back (c); 1184 c = my_ttnextchar (tthere, ttend); 1185 } 1169 1186 } 1170 1187 else if (c == '\'' || c == '\"') … … 1184 1201 if (tthere != ttend) macroargs.push_back (c); 1185 1202 c = my_ttnextchar (tthere, ttend); 1186 } 1203 } // while (tthere != ttend) 1187 1204 } 1188 1205 … … 1225 1242 c = my_ttnextchar (tthere, ttend); 1226 1243 } 1227 } 1244 } // end of while (tthere != ttend) 1228 1245 } 1229 1246 … … 1397 1414 1398 1415 // cerr << "r: " << recursiondepth << "\n"; 1399 1400 1416 // check for deep recursion 1401 1417 if (recursiondepth >= MAXRECURSIONDEPTH) … … 1415 1431 endit = macroparam.end(); 1416 1432 if (hereit != endit) c = (*hereit); 1417 1433 int openbrackets=0; // keep track of bracket level eg _If_(1, _macro_(arg)) 1434 // this allows commas inside brackets (as arguments) 1418 1435 while (hereit != endit) { 1419 1436 // get the next parameter … … 1435 1452 // found a quoted section 1436 1453 quote = c; 1437 //aparam.push_back(c);1454 if (openbrackets>0) aparam.push_back(c); 1438 1455 1439 1456 } else if (quote!='\0' && c==quote) { 1440 1457 // found the end of a quote 1441 1458 quote = '\0'; 1442 //aparam.push_back(c);1443 1444 } else if (quote=='\0' && c==',') {1459 if (openbrackets<0) aparam.push_back(c); 1460 1461 } else if (quote=='\0' && (c==',' || c==')') && openbrackets==0) { 1445 1462 // found the end of a parameter 1446 1463 c = my_ttnextchar (hereit, endit); 1447 1464 break; 1448 1465 1466 } else if (c=='(') { 1467 aparam.push_back(c); 1468 openbrackets++; 1469 } else if (c==')') { 1470 openbrackets--; 1471 aparam.push_back(c); 1449 1472 } else { 1450 1473 // ordinary character … … 1454 1477 c = my_ttnextchar (hereit, endit); 1455 1478 } 1479 1456 1480 1457 1481 // add this parameter to the list … … 1478 1502 // will always output something 1479 1503 outputtext.clear(); 1480 1504 1505 1481 1506 // expand out the first parameter 1482 1507 if (paramcond != paramend) { 1483 text_t tmpoutput; 1484 expandstring (macropackage, *paramcond, tmpoutput, recursiondepth+1); 1485 lc (tmpoutput); 1486 1508 /// text_t tmpoutput; 1509 /// expandstring (macropackage, *paramcond, tmpoutput, recursiondepth+1); 1510 /// lc (tmpoutput); 1487 1511 // test the expanded string 1488 1512 if (boolexpr (macropackage, *paramcond, recursiondepth+1)) { … … 1491 1515 if (paramthen != paramend) 1492 1516 expandstring (macropackage, *paramthen, outputtext, recursiondepth+1); 1493 1494 1517 } else { 1495 1518 // false
Note:
See TracChangeset
for help on using the changeset viewer.