Example #1
0
File: re.c Project: dank101/4.2BSD
dore() {
	register int line;
	register char *p;
	
	circf = 0;
	line = fline;
	compile(re);
	do {
		if (redir) fnext();
		else fprev();
		p = fbuf;
		while(*p++ != '\n')
			;
		*--p = '\0';
		if (match(fbuf)) goto l1;
	} while (fline != line);
	error("No match");
l1:	*p = '\n';
	fprint();
}
Example #2
0
void create_link_table(struct BAS_PFENTRY *list)
{
  int tsize,inst_size,f_cnt,p_cnt;
  struct BAS_PFENTRY *p;
  w32 bext_table;
  w16 *etab;
  w16 *instr;
  int fnccnt,pccnt;
  
  pccnt=fnccnt=f_cnt=p_cnt=0;
  tsize=2+2+4+2; /*count,count, end markers */
  inst_size=0;
  /* somewhat generously counting */
  p=list;
  while(p)
    {        /*    len +.b+allign+addr */
      tsize+= (((strlen(p->name)+1)>>1)<<1)+2;
      inst_size+=2;
      switch(p->type)
	{
	case X_FUN:
	  f_cnt++;
	  fnccnt+=strlen(p->name);
	  break;
	case X_PROC:
	  p_cnt++;
	  pccnt+=strlen(p->name);
	  break;
	default:
	  fprintf(stderr,"wrong basic extension type %d\n",p->type);
	  return;
	}
      p=p->link;
    }
  
  reg[1]=tsize+inst_size+12+100; /* some pad */
  reg[2]=0;
    
  /*printf("totsize %d, tsize %d, inst_size %d,\n reserve %d\n",reg[1],tsize,inst_size,reg[1]);*/
#if 1
  QLtrap(1,0x18,2000000);
  if (reg[0]) 
    {
      fprintf(stderr,"allocation failed, QDOS error %d\n",reg[0]);
      return;
    }
#endif
#if 1
  bext_table=aReg[0];
  etab=(w16 *)((char*)theROM+aReg[0]);
  instr=(w16 *)((char*)etab+(((tsize+6+10)>>1)<<1));
  
  WW(etab++,mangle_count(pccnt,p_cnt));
  p=ext_list;
  while(p_cnt--)
    {
      fnext(X_PROC,&p);
      build_entry(&etab,p,&instr);
      p=p->link;
    }
  WW(etab++,0);  /* end proc marker */
  
  WW(etab++,mangle_count(fnccnt,f_cnt));
  p=ext_list;
  while(f_cnt--)
    {
      fnext(X_FUN,&p);
      build_entry(&etab,p,&instr);
      p=p->link;
    }
  WW(etab++,0);  /* end fun marker */
  WW(etab++,0);  /* another marker to be sure */
  /*printf("Basic Extensions table at %d\n",bext_table);*/
#endif 
#if 1
  aReg[1]=bext_table;
   
  QLvector(0x110,2000000);   /* and BP.INIT */ 
 
#endif
}
Example #3
0
FormulaParser::Value FormulaParser::eval() {
  int digits = 0;
  bool plus = false;

  EvalStack stack;
  stack.ops.push('{');
  while (int type = fnext()) {
    if (type == tChar && chr == ']') break;
    if (type == tChar && chr == '|') {
      type = fnext();
      if (type == tNum) {
        digits = static_cast<int>(val);
      } else if (type == tChar && chr == '+') {
        plus = true;
      }
      fnext();
    } else if (type == tName) {
      std::vector<std::string> parts;
      bool isfunc = false;
      while (type == tName) {
        parts.push_back(tag);
        size_t prev = pos;
        if ((type = fnext()) != tChar || chr != '.') {
          if (type == tChar && chr == '(') {
            isfunc = true;
          } else {
            pos = prev;
          }
          break;
        }
        type = fnext();
      }
      std::string result = "";
      for (auto& part : parts) {
        if (!result.empty()) result.push_back('.');
        result.append(part);
      }
      if (isfunc) {
        char funcId = getFunction(result);
        OpInfo const& op = opInfo(funcId);
        while (stack.ops.size() && opInfo(stack.ops.top()).rprio >= op.lprio) {
          stack.exec(stack.ops.top());
          stack.ops.pop();
        }
        stack.ops.push(funcId);
        stack.needval = op.rval;
      } else if (!stack.ops.empty() && stack.ops.top() == funcTable) {
        stack.vals.push(AttributeValue(PowerTags::table(result)));
      } else {
        static re::Prog sfid("sf_(\\d+)", -1, re::Prog::CaseInsensitive);
        static re::Prog sftag(R"/(powertag.(\w+)."(.*)")/", -1, re::Prog::CaseInsensitive);
        //static re::Prog lookup(R"(table.(\w+).(\w+))", -1, re::Prog::CaseInsensitive);
        std::vector<std::string> match;
        if (context && sfid.match(result, &match)) {
          stack.vals.emplace(context->get(atoi(match[1].c_str()), values));
        } else if (sftag.match(result, &match)) {
          stack.vals.emplace(PowerTags::get(match[1], match[2], values));
        } else {
          auto it = values.find(result);
          stack.vals.push(it == values.end() ? 0.0 : it->second);
        }
      }
      stack.needval = 0;
    } else if (type == tTag) {
      auto it = values.find(tag);
      if (it != values.end()) {
        prevtag = it->second;
      } else if (context) {
        prevtag = context->get(tag, values);
      } else {
        prevtag = 0.0;
      }
      stack.vals.push(prevtag);
      stack.needval = 0;
    } else if (type == tNum) {
      stack.vals.push(val);
      stack.needval = 0;
    } else if (type == tChar) {
      if (chr == '-' && stack.needval) chr = '~';
      OpInfo const& op = opInfo(chr);
      while (stack.ops.size() && opInfo(stack.ops.top()).rprio >= op.lprio) {
        char top = stack.ops.top();
        stack.exec(top);
        stack.ops.pop();
        if (opInfo(top).rprio == 0) break;
      }
      if (chr != ')') stack.ops.push(chr);
      stack.needval = op.rval;
    }
  }
  OpInfo const& op = opInfo('}');
  while (stack.ops.size() && opInfo(stack.ops.top()).rprio >= op.lprio) {
    stack.exec(stack.ops.top());
    stack.ops.pop();
  }
  AttributeValue res;
  if (stack.vals.size()) res = stack.vals.top();
  return Value(res, digits, plus);
}

std::string FormulaParser::parse() {
  std::string result;
  int newlines = 0;
  while (int type = next()) {
    if ((flags & FormatHTML) && newlines && (type != tChar || chr != '\n')) {
      if (newlines == 1) {
        result.append("<br/>");
      } else {
        result.append("</p><p>");
      }
      newlines = 0;
    }
    switch (type) {
    case tChar:
      if (chr == '[') {
        result.append(eval().format());
      } else if (chr == '|') {
        next(); // 4
        std::string lhs, rhs;
        while (next() == tChar && chr != ':') {
          lhs.push_back(chr);
        }
        while (next() == tChar && chr != ';') {
          rhs.push_back(chr);
        }
        if (prevtag.min != 1 || prevtag.max != 1) {
          result.append(rhs);
        } else {
          result.append(lhs);
        }
      } else if (chr == '\n' && (flags & FormatHTML)) {
        ++newlines;
      } else {
        if (flags & FormatTags) {
          if (chr == ' ' && (result.empty() || result.back() == '\n')) {
            break;
          }
          if (chr == '%') {
            result.push_back('%');
          }
        }
        result.push_back(chr);
      }
      break;
    case tTag:
      if (tag.substr(0, 2) == "/c" || tag.substr(0, 2) == "c:" || pretags.find(tag) != pretags.end()) {
        if (flags & FormatHTML) {
          if (tag.substr(0, 2) == "/c") {
            result.append("</span>");
          } else if (tag.substr(0, 2) == "c:") {
            result.append(fmtstring("<span style=\"color: #%s\">", tag.substr(4).c_str()));
          } else {
            result.append(pretags[tag]);
          }
        } else if ((flags & FormatTags) && tag == "icon:bullet") {
          result.push_back('*');
        }
      } else {
        auto it = values.find(tag);
        if (it != values.end()) {
          prevtag = it->second;
        } else if (context) {
          prevtag = context->get(tag, values);
        } else {
          prevtag = 0.0;
        }
        result.append(Value(prevtag).format());
      }
      break;
    }
Example #4
0
void FormulaParser::endeval() {
  while (int type = fnext()) {
    if (type == tChar && chr == ']') break;
  }
}