Example #1
0
WFCB_p WeightLessDepthParse(Scanner_p in, OCB_p ocb, ProofState_p
		      state)
{
   ClausePrioFun prio_fun;
   int           fweight, vweight;
   double        max_term_multiplier, max_literal_multiplier,
                 pos_multiplier, term_depth_multiplier;
   
   AcceptInpTok(in, OpenBracket);
   prio_fun = ParsePrioFun(in);
   AcceptInpTok(in, Comma);
   fweight = ParseInt(in);
   AcceptInpTok(in, Comma);
   vweight = ParseInt(in);
   AcceptInpTok(in, Comma);
   max_term_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   max_literal_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   pos_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   term_depth_multiplier = ParseFloat(in);
   AcceptInpTok(in, CloseBracket);   
   
   return WeightLessDepthInit(prio_fun, fweight, vweight, ocb,
			      max_term_multiplier, max_literal_multiplier,
			      pos_multiplier, term_depth_multiplier);
}
Example #2
0
SystemPath SystemPath::Parse(const char * const str)
{
	assert(str);

	// syspath = '('? [+-]? [0-9]+ [, +-] [0-9]+ [, +-] [0-9]+ ')'?
	// with whitespace allowed between tokens

	const char *s = str;

	int x, y, z;

	while (isspace(*s)) { ++s; }
	if (*s == '(') { ++s; }

	x = ParseInt(s); // note: ParseInt (actually, strtol) skips leading whitespace itself

	while (isspace(*s)) { ++s; }
	if (*s == ',' || *s == '.') { ++s; }

	y = ParseInt(s);

	while (isspace(*s)) { ++s; }
	if (*s == ',' || *s == '.') { ++s; }

	z = ParseInt(s);

	while (isspace(*s)) { ++s; }
	if (*s == ')') { ++s; }
	while (isspace(*s)) { ++s; }

	if (*s) // extra unexpected text after the system path
		throw SystemPath::ParseFailure();
	else
		return SystemPath(x, y, z);
}
Example #3
0
WFCB_p TPTPTypeWeightParse(Scanner_p in, OCB_p ocb, ProofState_p
			   state)
{
   ClausePrioFun prio_fun;
   int           fweight, vweight;
   double        max_term_multiplier, max_literal_multiplier,
                 pos_multiplier, conjecture_multiplier,
                 hypothesis_multiplier;
   
   AcceptInpTok(in, OpenBracket);
   prio_fun = ParsePrioFun(in);
   AcceptInpTok(in, Comma);
   fweight = ParseInt(in);
   AcceptInpTok(in, Comma);
   vweight = ParseInt(in);
   AcceptInpTok(in, Comma);
   max_term_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   max_literal_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   pos_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   conjecture_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   hypothesis_multiplier = ParseFloat(in);
   AcceptInpTok(in, CloseBracket);   

   return TPTPTypeWeightInit(prio_fun, fweight, vweight, ocb,
			     max_term_multiplier,
			     max_literal_multiplier, pos_multiplier,
			     conjecture_multiplier,
			     hypothesis_multiplier);
}
Example #4
0
    bool ParseIndexTrio( IndexTrio& trio )
    {
        SkipSpace();

        if (!IsDigitOrSign(*m_line))
        {
            return false;
        }

        trio.iPos = ParseInt();
        
        if (*(m_line++) != '/')
        {
            return true;
        }

        // look for iTex
        if (*m_line != '/')
        {
            trio.iTex = ParseInt();

            if (*(m_line++) != '/')
            {
                return true;
            }
        }

        // look for iNorm
        if (IsDigitOrSign(*m_line))
        {
            trio.iNorm = ParseInt();
        }
        return true;
    }
Example #5
0
void EvalMid(const void *data, qCtx *ctx, qStr *out, qArgAry *args) {
	if (args->Count() >= 2) {
		CStr tmp   = (*args)[0];
		int  index = ParseInt((*args)[1]);
		if (args->Count() >= 3) {
			int len = ParseInt((*args)[2]);
			if (abs(index) < tmp.Length()) {
				if (index >= 0) {
					out->PutS(tmp.SafeP() + index, min(tmp.Length()-index, len));
				} else {
					out->PutS(tmp.SafeP() + max(tmp.Length() + index - abs(len), 0), min(tmp.Length(), len));
				}
			}
		} else {
			if (abs(index) < tmp.Length()) {
				if (index >= 0) {
					out->PutS(tmp.SafeP() + index, tmp.Length()-index);
				} else {
					out->PutS(tmp.SafeP(), tmp.Length() + index);
				}
			}

		}
	}
}
Example #6
0
WFCB_p ClauseOrientWeightParse(Scanner_p in, OCB_p ocb, ProofState_p
				state)
{
   ClausePrioFun prio_fun;
   int fweight, vweight;
   double pos_multiplier, max_literal_multiplier,
      unorientable_literal_multiplier;

   AcceptInpTok(in, OpenBracket);
   prio_fun = ParsePrioFun(in);
   AcceptInpTok(in, Comma);
   fweight = ParseInt(in);
   AcceptInpTok(in, Comma);
   vweight = ParseInt(in);
   AcceptInpTok(in, Comma);
   unorientable_literal_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   max_literal_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   pos_multiplier = ParseFloat(in);
   AcceptInpTok(in, CloseBracket);
   
   return ClauseOrientWeightInit(prio_fun, fweight, vweight, ocb,
				 unorientable_literal_multiplier,
				 max_literal_multiplier,
				 pos_multiplier);
}
Example #7
0
SDL_Color ParseColor(String const& str) {
	auto parts = SplitString(str, ',');
	int r = ParseInt(parts[0]);
	int g = ParseInt(parts[1]);
	int b = ParseInt(parts[2]);
	int a = parts.size() > 3 ? ParseInt(parts[3]) : 0xff;
	return { r, g, b, a };
}
Example #8
0
int _Route_ParseRouteName(const char *Name, void *Addr, int *SubnetBits, int *Metric)
{
	 int	type, addrlen;
	 int	ofs = 0, ilen;
	
	ENTER("sName pAddr pSubnetBits pMetric", Name, Addr, SubnetBits, Metric);

	ilen = ParseInt(Name, &type);
	if(ilen == 0) {
		LOG("Type failed to parse");
		LEAVE_RET('i', -1);
	}
	ofs += ilen;
	
	if(Name[ofs] != ':')	LEAVE_RET('i', -1);
	ofs ++;

	addrlen = IPStack_GetAddressSize(type);
	if( Addr )
	{
		if( UnHex(Addr, addrlen, Name + ofs) != addrlen )
			return -1;
	}
	ofs += addrlen*2;
	
	if(Name[ofs] != ':')	LEAVE_RET('i', -1);
	ofs ++;

	ilen = ParseInt(Name+ofs, SubnetBits);
	if(ilen == 0) {
		LOG("Subnet failed to parse");
		LEAVE_RET('i', -1);
	}
	ofs += ilen;
	
	if(Name[ofs] != ':')	LEAVE_RET('i', -1);
	ofs ++;

	ilen = ParseInt(Name+ofs, Metric);
	if(ilen == 0) {
		LOG("Metric failed to parse");
		LEAVE_RET('i', -1);
	}
	ofs += ilen;
	
	if(Name[ofs] != '\0')	LEAVE_RET('i', -1);

	LEAVE('i', type);
	return type;
}
Example #9
0
static double ParseDouble(const char *sz)
{
	bool bNegate = false;
	double dVal = 0.0;
	int iExp = 0;

	while (*sz == ' ') sz++;
	if (*sz == '+') {
		sz++;
	} else if (*sz == '-') {
		bNegate = true;
		sz++;
	}

	for (; *sz && (*sz >= '0') && (*sz <= '9'); sz++)
		dVal = dVal*10.0f + (*sz - '0');

	if (*sz == '.') {
		sz++;
		for (; *sz && (*sz >= '0') && (*sz <= '9'); sz++) {
			dVal = dVal*10.0f + (*sz - '0');
			iExp--;
		}		
	}

	if ((*sz == 'e') || (*sz == 'E') || (*sz == '^')) {
		sz++;
		iExp += ParseInt(sz);
	}
	if (bNegate) dVal = - dVal;

	return dVal * pow(10.0, iExp);
}
Example #10
0
void EvalXTCPRecv(const void *obj, qCtx *ctx, qStr *out, qArgAry *args)
{
    Sock *s = (Sock *) obj;

    int len;
    char *line = NULL;
    if (args->Count() > 0)  {
        len = ParseInt((*args)[0]);
        len = s->Read(len);
        line = s->GetBuf();
    } else {
        len = s->ReadLine(&line);
    }

    if (len > 0)
        out->PutS(line, len);
    else if (len < 0 ) {
        if (len == Sock::ERR_TIMEOUT) {
            ctx->ThrowF(out, 702, "Timeout while waiting to read data from host %s:%d, %y", s->GetHost(), s->GetPort());
        } else {
            ctx->ThrowF(out, 702, "Error while reading data from host %s:%d, %y", s->GetHost(), s->GetPort(), GetLastError());
        }
    }

}
Example #11
0
void EvalFmt(const void *data, qCtx *ctx, qStr *out, qArgAry *args) {
	CStr val = (*args)[0];

	ColFmt col; 
	memset(&col, 0, sizeof(col));

	col.dec = args->Count() > 1 ? ParseInt((*args)[1]) : 2;

	if (args->Count() > 2) {
		CStr dch = (*args)[2];
		col.dch = (dch.IsEmpty()) ? 0 : *dch;
	} else
		col.dch = '.';

	if (args->Count() > 3) {
		CStr tho = (*args)[3];
		col.tho = (tho.IsEmpty()) ? 0 : *tho;
	} else
		col.tho = ',';

	CStr res(256);
	double dval;
	const char *p = CTabFmt::NumFmt(col, val.SafeP(), res.GetBuffer(), 256, &dval);
	out->PutS(p);
}
Example #12
0
CmdArgs ParseArgs(int argc, char *argv[]) {
  CmdArgs ret;

  optind = 1; // reset parsing

  int c, long_index;
  while ((c = getopt_long(argc, argv, "", long_opts, &long_index)) != -1) {
    if (c != 0) continue;

    if (!strcmp("config", long_opts[long_index].name)) {
      ret.config_file = optarg;
    }
    else if (!strcmp("stats-interval", long_opts[long_index].name)) {
      unsigned long stats_interval;
      if (!ParseInt(optarg, stats_interval)) {
        std::stringstream error_msg;
        error_msg << "Invalid stats-interval. Used \"" << optarg << '"';
        throw std::invalid_argument(error_msg.str());
      }
      ret.stats_interval = stats_interval;
    }
  }

  return ret;
}
Example #13
0
void EvalThrow(const void *data, qCtx *ctx, qStr *out, qArgAry *args) 
{
	VALID_ARGC("throw", 2, 2);
	if (args->Count()>1) {
		ctx->Throw(out, ParseInt((*args)[0]), (*args)[1]);
	}
}
Example #14
0
void EvalSubExpr(const void *data, qCtx *ctx, qStr *out, qArgAry *args) {
	CRegX *myRx = (CRegX *)data;
	int myIndex = ParseInt((*args)[0]);
	const char *sp; const char *ep;
	if (myIndex >=0 && myRx->GetMatchInfo(sp, ep, myIndex))
		out->PutS(sp, ep-sp);
}
Example #15
0
static bool ParseBool(char *s, char *e, bool *bOut)
{
    str::TrimWsEnd(s, e);
    size_t len = e - s;
    if (4 == len && str::EqNI(s, "true", 4)) {
        *bOut = true;
        return true;
    }
    if (5 == len && str::EqNI(s, "false", 5)) {
        *bOut = false;
        return true;
    }
    int64_t i;
    if (!ParseInt(s, e, &i))
        return false;
    if (0 == i) {
        *bOut = false;
        return true;
    }
    if (1 == i) {
        *bOut = true;
        return true;
    }
    return false;
}
Example #16
0
void EvalDir(const void *data, qCtx *ctx, qStr *out, qArgAry *args)
{
	VALID_ARGC("dir", 2, 3);

	CStr path = (*args)[0];

	if (!path) {
		ctx->ThrowF(out, 601, "Empty directory path is invalid");
		return;
	}

	if (!safe_fcheck(ctx, path, 'r')) {
		ctx->ThrowF(out, 601, "Failed to open directory. %y", GetLastError());
		return;
	}

	CStr body = args->GetAt(1);
	int mask = 0;
	if (args->Count() > 2) {
		mask = ParseInt((*args)[2]);
	}

	if (!mask)
		mask = -1;

	ScanDir(path, mask, body, ctx, out);
}
Example #17
0
void RawParser::ParseCompBlock(int nDstComp)
{
	do {
		if (!ParseToken(sz)) return;
	} while (*sz != '{');

	DWORD nComp = 0;
	for (; nComp < nComps; nComp++)
		if (Comps[nComp].nDstComp == nDstComp)
			break;
	if (nComps == 4) {
		do {
			if (!ParseToken(sz)) return;
		} while (*sz != '}');
		return;
	}
	if (nComp == nComps) nComps++;

	Comps[nComp].nDstComp = nDstComp;

	while (!EndOfScript()) {

		// Get command token
		bool bMore;
		if (!ParseToken(sz, &bMore)) return;

		if (*sz == '}') return;				// End of block?

		// Handle commands
		if        (_strcmpi(sz, "file") == 0) {

			if (bMore) ParseFileString(Comps[nComp].szFile, &bMore);

		} else if (_strcmpi(sz, "start") == 0) {

			if (bMore) ParseInt(Comps[nComp].nStart, &bMore);

		} else if (_strcmpi(sz, "delta") == 0) {

			if (bMore) ParseInt(Comps[nComp].nDelta, &bMore);

		}

		// Remove any unparsed command parameters
		while (bMore) ParseToken(sz, &bMore);
	}
}
Example #18
0
void Data::loadNBest(const string &file, bool oneBest)
{
  TRACE_ERR("loading nbest from " << file << endl);
  util::FilePiece in(file.c_str());

  ScoreStats scoreentry;
  string sentence, feature_str, alignment;
  int sentence_index;

  while (true) {
    try {
      StringPiece line = in.ReadLine();
      if (line.empty()) continue;
      // adding statistics for error measures
      scoreentry.clear();

      util::TokenIter<util::MultiCharacter> it(line, util::MultiCharacter("|||"));

      sentence_index = ParseInt(*it);
      if (oneBest && m_score_data->exists(sentence_index)) continue;
      ++it;
      sentence = it->as_string();
      ++it;
      feature_str = it->as_string();
      ++it;

      if (it) {
        ++it;                             // skip model score.

        if (it) {
          alignment = it->as_string(); //fifth field (if present) is either phrase or word alignment
          ++it;
          if (it) {
            alignment = it->as_string(); //sixth field (if present) is word alignment
          }
        }
      }
      //TODO check alignment exists if scorers need it

      if (m_scorer->useAlignment()) {
        sentence += "|||";
        sentence += alignment;
      }
      m_scorer->prepareStats(sentence_index, sentence, scoreentry);

      m_score_data->add(scoreentry, sentence_index);

      // examine first line for name of features
      if (!existsFeatureNames()) {
        InitFeatureMap(feature_str);
      }
      AddFeatures(feature_str, sentence_index);
    } catch (util::EndOfFileException &e) {
      PrintUserTime("Loaded N-best lists");
      break;
    }
  }
}
Example #19
0
void EvalDup(const void *data, qCtx *ctx, qStr *out, qArgAry *args) {
	if (args->Count() >= 2) {
		CStr str = (*args)[0];
		int dup;
		for (dup = ParseInt((*args)[1]); dup > 0; --dup) {
			out->PutS(str);
		}
	}
}
Example #20
0
void EvalSkipTokens(int *skip, qCtx *ctx, qStr *out, qArgAry *args)
{
	if (args->Count() >= 0) {
		int tmp = ParseInt((*args)[0]);
		if (tmp >= 0) {
			*skip = tmp;
		}
	}
}
Example #21
0
void EvalSqlTimeout(const void *data, qCtx *ctx, qStr *out, qArgAry *args)
{
	CDbLib *dbLib = GetDbLib(ctx);
	if (args->GetAt(0)) {
		int val = ParseInt((*args)[0]);
		dbLib->SetTimeout(val);
	} else {
		out->PutN(dbLib->GetTimeout());
	}
}
Example #22
0
// sha hash
void EvalSha(const void *data, qCtx *ctx, qStr *pStream, qArgAry *args)
{
	if (args->Count() > 0) {
		CStr out = HEX_encode(SHA1_string((*args)[0]));
		if (args->Count() > 1)
			pStream->PutS(out, max(0,min(ParseInt((*args)[1]), out.Length())));
		else 
			pStream->PutS(out);
	}
}
Example #23
0
bool
DataNode::GetAttribute(const TCHAR *name, unsigned &value) const
{
  const TCHAR *val = GetAttribute(name);
  if (val == NULL)
    return false;

  value = ParseInt(val);
  return true;
}
Example #24
0
void EvalSafeUID(const void *data, qCtx *ctx, qStr *out, qArgAry *args) {
	if (args->Count()>0) {
		if (!ctx->GetSafeMode()) {
			int uid = ParseInt((*args)[0]);
			ctx->SetSafeUID(uid);
		}
	}	
	int uid = ctx->GetSafeUID();
	out->PutN(uid);
}
Example #25
0
bool
ConstDataNode::GetAttribute(const TCHAR *name, bool &value) const
{
  const TCHAR *val = GetAttribute(name);
  if (val == nullptr)
    return false;

  value = ParseInt(val) > 0;
  return true;
}
Example #26
0
void PadParams(qCtx *ctx, qArgAry *args, CStr &str, int &pad, CStr &fill, int &len)
{
	str = (*args)[0];
	pad = (args->Count() > 1) ? ParseInt((*args)[1]) : 0;
	
	if (args->Count() > 2)
		fill = (*args)[2];
	else
		fill = " ";
	len = fill.Length();
}
EffectValueOrRange SpellParser::ParseValueOrRange(const CString& cszText)
{
   EffectValueOrRange valueOrRange;

   int iPosDash = cszText.Find(_T('-'));
   int iPosPercent = cszText.Find(_T('%'));
   if (iPosDash > 0) // at 0 it is the sign value
   {
      valueOrRange.SetRange(iPosPercent != -1,
         ParseInt(cszText.Left(iPosDash)),
         ParseInt(cszText.Mid(iPosDash+1)));
   }
   else
   {
      valueOrRange.SetValue(iPosPercent != -1,
         ParseInt(cszText));
   }

   return valueOrRange;
}
Example #28
0
bool
DataNode::GetAttribute(const TCHAR *name, int &value) const
{
  tstring val;
  if (GetAttribute(name, val)) {
    value = ParseInt(val.c_str());
    return true;
  } else {
    return false;
  }
}
Example #29
0
    int ExpectNextInt() {
        const char *p = ExpectNext();
        assert(p != NULL);

        char *endptr;
        int result = ParseInt(p, &endptr);
        if (p == endptr)
            UsageError();

        return result;
    }
Example #30
0
int SIMPLEAPI ParseInt(const wchar_t* psz, int iDefault)
{
	if (IsEmptyString(psz))
		return iDefault;

	int iVal;
	if (!ParseInt(psz, &iVal))
		return iDefault;

	return iVal;
}