Пример #1
0
/*=============================UNIT-TEST*/
int main(int argc, char** argv) {
	startParsing("ut.dat");
	listItem *p = buildOperationList();
	while((*p).next != NULL) {
		openOperation *t = (openOperation*) (*p).item;
		printf(">%s", (*t).operation);
		if (strcmp((*t).operation, "open") == 0) {
			printf("[%s]", (*t).fileName);
		}
		printf("\n");
		p = (*p).next;
	}
}
Пример #2
0
void BTEditor::buildOperationList(BTDisplay &d, BTSpecialBody *body, std::vector<BTDisplay::selectItem> &list, std::vector<operationList> &ops, int level /*= 0*/)
{
 std::string spaces(level, ' ');
 for (int i = 0; i < body->numOfOperations(false); ++i)
 {
  std::vector<std::string> lines;
  BTSpecialOperation *op = body->getOperation(i);
  std::string words = spaces + op->print();
  d.splitText(words.c_str(), spaces + "\\", lines);
  for (std::vector<std::string>::const_iterator itr(lines.begin()); itr != lines.end(); itr++)
  {
   list.push_back(BTDisplay::selectItem(*itr));
   list.back().value = ops.size();
   if (itr != lines.begin())
    list.back().flags.set(BTSELECTFLAG_UNSELECTABLE);
  }
  ops.push_back(operationList(body, op));
  BTSpecialBody *subBody = dynamic_cast<BTSpecialBody*>(op);
  if (subBody)
  {
   buildOperationList(d, subBody, list, ops, level + 1);
  }
  else
  {
   BTSpecialConditional *conditional = dynamic_cast<BTSpecialConditional*>(op);
   if (conditional)
   {
    buildOperationList(d, conditional->getThenClause(), list, ops, level + 1);
    list.push_back(BTDisplay::selectItem(spaces + "ELSE"));
    list.back().flags.set(BTSELECTFLAG_UNSELECTABLE);
    buildOperationList(d, conditional->getElseClause(), list, ops, level + 1);
   }
  }
 }
 list.push_back(BTDisplay::selectItem(spaces + "<New Operation>"));
 list.back().value = ops.size();
 ops.push_back(operationList(body, NULL));
}
Пример #3
0
void BTEditor::editSpecial(BTDisplay &d, BTSpecial *special)
{
 if (NULL == special)
 {
  special = new BTSpecial;
  levelMap->addSpecial(special);
 }
 BTDisplayConfig *oldConfig = d.getConfig();
 BTDisplayConfig config;
 XMLSerializer parser;
 config.serialize(&parser);
 parser.parse(BTDisplay::applyDisplayDir("data/specialedit.xml").c_str(), true);
 d.setConfig(&config);
 int start(0);
 int current(0);
 BTSpecialBody *body = special->getBody();
 std::vector<operationList> ops;
 std::vector<BTDisplay::selectItem> list(2);
 list[0].name = std::string("Name: ") + special->getName();
 list[1].name = "Flags: " + special->printFlags(false);
 buildOperationList(d, body, list, ops);
 d.addSelection(list.data(), list.size(), start, current);
 int key;
 char extra[6] = {BTKEY_INS, BTKEY_DEL, BTKEY_CTRL_C, BTKEY_CTRL_V, BTKEY_CTRL_X, 0};
 while (27 != (key = d.process(extra)))
 {
  d.clearText();
  if (current == 0)
  {
   std::string name = special->getName();
   d.addReadString("Name: ", 25, name);
   key = d.process();
   if ('\r' == key)
    special->setName(name);
   d.clearText();
   list[0].name = std::string("Name: ") + special->getName();
  }
  else if (current == 1)
  {
   BTSpecialFlagList &lookup = getSpecialFlagList();
   BitField bits = special->getFlag();
   BTDisplay::selectItem lookupItem[lookup.size()];
   for (size_t i = 0; i < lookup.size(); ++i)
   {
    lookupItem[i].name = lookup.getName(i);
    if (bits.isSet(i))
     lookupItem[i].first = '*';
   }
   int lookupStart(0);
   int lookupCurrent(0);
   d.addSelection(lookupItem, lookup.size(), lookupStart, lookupCurrent);
   int key;
   while (27 != (key = d.process()))
   {
    if (bits.toggle(lookupCurrent))
     lookupItem[lookupCurrent].first = '*';
    else
     lookupItem[lookupCurrent].first = 0;
   }
   special->setFlag(bits);
   d.clearText();
   list[1].name = "Flags: " + special->printFlags(false);
  }
  else
  {
   if (BTKEY_INS == key)
   {
    if ((ops[list[current].value].op != NULL) && (ops[list[current].value].parent != NULL))
    {
     ops[list[current].value].parent->insertOperation(ops[list[current].value].op, new BTSpecialCommand(BTSPECIALCOMMAND_NOTHING));
    }
   }
   else if (BTKEY_DEL == key)
   {
    if ((ops[list[current].value].op != NULL) && (ops[list[current].value].parent != NULL))
    {
     ops[list[current].value].parent->eraseOperation(ops[list[current].value].op);
    }
   }
   else if (BTKEY_CTRL_X == key)
   {
    if ((ops[list[current].value].op != NULL) && (ops[list[current].value].parent != NULL))
    {
     if (clipboard)
      delete clipboard;
     clipboard = ops[list[current].value].op->clone();
     ops[list[current].value].parent->eraseOperation(ops[list[current].value].op);
    }
   }
   else if (BTKEY_CTRL_C == key)
   {
    if ((ops[list[current].value].op != NULL) && (ops[list[current].value].parent != NULL))
    {
     if (clipboard)
      delete clipboard;
     clipboard = ops[list[current].value].op->clone();
    }
   }
   else if (BTKEY_CTRL_V == key)
   {
    if ((ops[list[current].value].parent != NULL) && (clipboard))
    {
     if (ops[list[current].value].op)
      ops[list[current].value].parent->insertOperation(ops[list[current].value].op, clipboard->clone());
     else
      ops[list[current].value].parent->addOperation(clipboard->clone());
    }
   }
   else if ('\r' == key)
   {
    BTSpecialOperation *op = editSpecialOperation(d, ops[list[current].value].op);
    if (op)
    {
     if (ops[list[current].value].op)
      ops[list[current].value].parent->replaceOperation(ops[list[current].value].op, op);
     else
      ops[list[current].value].parent->addOperation(op);
    }
   }
  }
  ops.clear();
  list.resize(2);
  buildOperationList(d, body, list, ops);
  d.addSelection(list.data(), list.size(), start, current);
 }
 d.clearText();
 d.setConfig(oldConfig);
}