Пример #1
0
static struct pentry *addPayload(struct config *config, const char **attr)
{
	struct pentry *ret = newPayload(config);
	int i = 0;

	if (ret == NULL)
		die("E: Could not allocate memory for a new payload\n");

	while (attr[i] != NULL) {
		if (!strcmp(attr[i], "type")) {
			if (!strcmp(attr[i + 1], "chain"))
				ret->type = BPT_TYPE_CHAIN;
			else if (!strcmp(attr[i + 1], "chooser"))
				ret->type = BPT_TYPE_CHOOSER;
			else
				die("E: Invalid payload type %s\n",
				    attr[i + 1]);
		} else if (!strcmp(attr[i], "flags"))
			parseFlags(ret, attr[i + 1]);

		i += 2;
	}

	return ret;
}
Пример #2
0
/*
    Create an initialized regular expression object. The pattern should include
    the slash delimiters. For example: /abc/ or /abc/g
 */
EjsRegExp *ejsCreateRegExp(Ejs *ejs, EjsString *pattern)
{
    EjsRegExp   *rp;
    cchar       *errMsg;
    MprChar     *flags;
    int         column, errCode;

    if (pattern->length == 0 || pattern->value[0] != '/') {
        ejsThrowArgError(ejs, "Bad regular expression pattern. Must start with '/'");
        return 0;
    }
    rp = ejsCreateObj(ejs, ESV(RegExp), 0);
    if (rp != 0) {
        /*
            Strip off flags for passing to pcre_compile2
         */
        rp->pattern = sclone(&pattern->value[1]);
        if ((flags = wrchr(rp->pattern, '/')) != 0) {
            rp->options = parseFlags(rp, &flags[1]);
            *flags = 0;
        }
        //  TODO - UNICODE is pattern meant to be 
        rp->compiled = pcre_compile2(rp->pattern, rp->options, &errCode, &errMsg, &column, NULL);
        if (rp->compiled == NULL) {
            ejsThrowArgError(ejs, "Can't compile regular expression '%s'. Error %s at column %d", rp->pattern, errMsg, column);
            return 0;
        }
    }
    return rp;
}
Пример #3
0
PhpProp::PhpProp(const folly::dynamic& d, fbstring cls) :
    m_name(d["name"].asString()),
    m_className(cls),
    m_prop(d),
    m_flags(parseFlags(m_prop["flags"])),
    m_kindOf(kindOfFromDynamic(m_prop["type"])) {
}
Пример #4
0
bool
WayPointFileWinPilot::parseLine(const TCHAR* line, const unsigned linenum,
                                Waypoints &way_points, 
                                const RasterTerrain *terrain)
{
  TCHAR ctemp[255];
  const TCHAR *params[20];
  size_t n_params;

  // If (end-of-file or comment)
  if (line[0] == '\0' || line[0] == 0x1a ||
      _tcsstr(line, _T("**")) == line ||
      _tcsstr(line, _T("*")) == line)
    // -> return without error condition
    return true;

  if (_tcslen(line) >= sizeof(ctemp) / sizeof(ctemp[0]))
    /* line too long for buffer */
    return false;

  GeoPoint location;

  // Get fields
  n_params = extractParameters(line, ctemp, params, 20);
  if (n_params < 6)
    return false;

  // Latitude (e.g. 51:15.900N)
  if (!parseAngle(params[1], location.Latitude, true))
    return false;

  // Longitude (e.g. 00715.900W)
  if (!parseAngle(params[2], location.Longitude, false))
    return false;

  Waypoint new_waypoint(location);
  new_waypoint.FileNum = file_num;

  // Name (e.g. KAMPLI)
  if (!parseString(params[5], new_waypoint.Name))
    return false;

  // Altitude (e.g. 458M)
  /// @todo configurable behaviour
  bool alt_ok = parseAltitude(params[3], new_waypoint.Altitude);
  check_altitude(new_waypoint, terrain, alt_ok);

  if (n_params > 6) {
    // Description (e.g. 119.750 Airport)
    parseString(params[6], new_waypoint.Comment);
  }

  // Waypoint Flags (e.g. AT)
  parseFlags(params[4], new_waypoint.Flags);

  add_waypoint(way_points, new_waypoint);
  return true;
}
Пример #5
0
        Model::EntityDefinition* DefParser::nextDefinition() {
            Token token = m_tokenizer.nextToken();
            while (token.type() != Eof && token.type() != ODefinition)
                token = m_tokenizer.nextToken();
            if (token.type() == Eof)
                return NULL;

            expect(ODefinition, token);
            
            StringList baseClasses;
            ClassInfo classInfo;
            
            token = m_tokenizer.nextToken();
            expect(Word, token);
            classInfo.name = token.data();

            token = m_tokenizer.peekToken();
            expect(OParenthesis | Newline, token);
            if (token.type() == OParenthesis) {
                classInfo.setColor(parseColor());
                
                token = m_tokenizer.peekToken();
                expect(OParenthesis | Question, token);
                if (token.type() == OParenthesis) {
                    classInfo.setSize(parseBounds());
                } else {
                    m_tokenizer.nextToken();
                }
                
                token = m_tokenizer.peekToken();
                if (token.type() == Word) {
                    Model::FlagsPropertyDefinition::Ptr spawnflags = parseFlags();
                    classInfo.properties[spawnflags->name()] = spawnflags;
                }
            }

            expect(Newline, token = m_tokenizer.nextToken());
            parseProperties(classInfo.properties, classInfo.models, baseClasses);
            
            classInfo.setDescription(parseDescription());
            expect(CDefinition, token = m_tokenizer.nextToken());

            Model::EntityDefinition* definition = NULL;
            
            if (classInfo.hasColor) {
                ClassInfo::resolveBaseClasses(m_baseClasses, baseClasses, classInfo);
                if (classInfo.hasSize) { // point definition
                    definition = new Model::PointEntityDefinition(classInfo.name, classInfo.color, classInfo.size, classInfo.description, classInfo.propertyList(), classInfo.models);
                } else {
                    definition = new Model::BrushEntityDefinition(classInfo.name, classInfo.color, classInfo.description, classInfo.propertyList());
                }
            } else { // base definition
                m_baseClasses[classInfo.name] = classInfo;
                definition = nextDefinition();
            }
            
            return definition;
        }
Пример #6
0
PhpFunc::PhpFunc(const folly::dynamic& d,
                 const fbstring& className) :
    m_name(d["name"].asString()),
    m_className(className),
    m_func(d),
    m_desc(getFollyDynamicDefaultString(d, "desc", "")),
    m_returnRef(d.getDefault("ref", "false") == "true"),
    m_returnKindOf(KindOfNull),
    m_returnCppType("void"),
    m_returnPhpType("void"),
    m_minNumParams(0),
    m_numTypeChecks(0) {
  auto returnIt = d.find("return");
  if (returnIt != d.items().end()) {
    auto retNode = returnIt->second;
    auto typeIt = retNode.find("type");
    if (typeIt != retNode.items().end()) {
      auto type = typeIt->second;
      if ((type.isString()) && (type != "void") && (type != "null")) {
        m_returnKindOf = m_returnRef ? KindOfRef : kindOfFromDynamic(type);
        m_returnCppType = typeString(type, true);
        m_returnPhpType = phpTypeFromDataType(m_returnKindOf);
      }
    }
    m_returnDesc = getFollyDynamicDefaultString(retNode, "desc", "");
  }

  auto args = d.find("args");
  if (args == d.items().end() || !args->second.isArray()) {
    throw std::logic_error(
      folly::format("'{0}' must have an array field 'args'", name()).str()
    );
  }
  auto ret = d.find("return");
  if (ret == d.items().end() || !ret->second.isObject() ||
      ret->second.find("type") == ret->second.items().end()) {
    throw std::logic_error(
      folly::format("'{0}' must have an array field 'return', which must have "
                    "a string field 'type'", name()).str()
    );
  }

  bool magic = isMagicMethod();
  for (auto &p : args->second) {
    PhpParam param(p, magic);
    m_params.push_back(param);
    if (!param.hasDefault()) {
      ++m_minNumParams;
    }
    if (param.isCheckedType()) {
      ++m_numTypeChecks;
    }
  }

  m_flags = parseFlags(m_func["flags"]);
}
Пример #7
0
bool
WaypointReaderZander::ParseLine(const TCHAR* line, const unsigned linenum,
                                Waypoints &way_points)
{
    // If (end-of-file or comment)
    if (line[0] == '\0' || line[0] == 0x1a ||
            _tcsstr(line, _T("**")) == line ||
            _tcsstr(line, _T("*")) == line)
        // -> return without error condition
        return true;

    // Determine the length of the line
    size_t len = _tcslen(line);
    // If less then 34 characters -> something is wrong -> cancel
    if (len < 34)
        return false;

    GeoPoint location;

    // Latitude (Characters 13-20 // DDMMSS(N/S))
    if (!parseAngle(line + 13, location.Latitude, true))
        return false;

    // Longitude (Characters 21-29 // DDDMMSS(E/W))
    if (!parseAngle(line + 21, location.Longitude, false))
        return false;

    location.normalize(); // ensure longitude is within -180:180

    Waypoint new_waypoint(location);
    new_waypoint.file_num = file_num;
    new_waypoint.original_id = 0;

    // Name (Characters 0-12)
    if (!parseString(line, new_waypoint.name, 12))
        return false;

    // Altitude (Characters 30-34 // e.g. 1561 (in meters))
    /// @todo configurable behaviour
    if (!parseAltitude(line + 30, new_waypoint.altitude))
        CheckAltitude(new_waypoint);

    // Description (Characters 35-44)
    if (len > 35)
        parseString(line + 35, new_waypoint.comment, 9);

    // Flags (Characters 45-49)
    if (len < 46 || !parseFlags(line + 45, new_waypoint))
        if (len < 36 || !parseFlagsFromDescription(line + 35, new_waypoint))
            new_waypoint.flags.turn_point = true;

    way_points.append(new_waypoint);
    return true;
}
Пример #8
0
void ProgrammeTableParser::startElementParsed(const QString &name)
{
    if (m_x == 0 && name == "div" && attribute("id") == "channelboard") {
        m_x = 1;
    }
    else if (m_x == 1 && name == "tr" && attribute("class") == "infobox") {
        m_x = 2;
        m_currentProgramme = Programme();
    }
    else if (m_x == 2 && name == "td" && attribute("class").startsWith("programtime")) {
        m_x = 3;
        m_parseContent = true;
    }
    else if (m_x == 2 && name == "span" && attribute("id").startsWith("pid")) {
        m_x = 4;
        parseProgrammeId(attribute("id"));
        parseFlags();
        m_parseContent = true;
    }
    else if (m_x == 4 && name == "span") {
        parseFlags();
    }
    else if (m_x == 2 && name == "span" && attribute("class") == "information") {
        m_x = 5;
        m_parseContent = true;
    }
    else if (m_x == 0 && name == "div" && attribute("id") == "toolbarcalendar") {
        m_x = 6;
        m_parseContent = true;
    }

    if (m_x > 0 && name == "table") {
        m_tableDepth++;
//        qDebug() << "<table>" << m_tableDepth;

        if (m_tableDepth == 2) {
            m_dayOfWeek = (m_dayOfWeek + 1) % 7;
        }
    }
}
Пример #9
0
bool
WayPointFileZander::parseLine(const TCHAR* line, const unsigned linenum,
                              Waypoints &way_points,
                              const RasterTerrain *terrain)
{
  // If (end-of-file or comment)
  if (line[0] == '\0' || line[0] == 0x1a ||
      _tcsstr(line, _T("**")) == line ||
      _tcsstr(line, _T("*")) == line)
    // -> return without error condition
    return true;

  // Determine the length of the line
  size_t len = _tcslen(line);
  // If less then 34 characters -> something is wrong -> cancel
  if (len < 34)
    return false;

  GeoPoint location;

  // Latitude (Characters 13-20 // DDMMSS(N/S))
  if (!parseAngle(line + 13, location.Latitude, true))
    return false;

  // Longitude (Characters 21-29 // DDDMMSS(E/W))
  if (!parseAngle(line + 21, location.Longitude, false))
    return false;

  Waypoint new_waypoint(location);
  new_waypoint.FileNum = file_num;

  // Name (Characters 0-12)
  if (!parseString(line, new_waypoint.Name))
    return false;

  // Altitude (Characters 30-34 // e.g. 1561 (in meters))
  /// @todo configurable behaviour
  bool alt_ok = parseAltitude(line + 30, new_waypoint.Altitude);
  check_altitude(new_waypoint, terrain, alt_ok);

  // Description (Characters 35-44)
  if (len > 35)
    parseString(line + 35, new_waypoint.Comment);

  // Flags (Characters 45-49)
  if (len > 45)
    parseFlags(line + 45, new_waypoint.Flags);

  add_waypoint(way_points, new_waypoint);
  return true;
}
Пример #10
0
TextureResource::TextureResource(
              resource_group::ResourceGroup resourceGroup,
        const std::string&                  filePath,
              unsigned                      flags )
    :
    Resource    ( resourceGroup ),
    m_type      ( tex::TEXTURE ),
    m_filePath  ( filePath ),
    m_flags     ( flags ),
    m_clamp     ( false ),
    m_showPixels( false )
{
    parseFlags();
}
Пример #11
0
/*
    Parse a regular expression string. The string should include the slash delimiters and may contain appended flags. 
    For example: /abc/ or /abc/g
 */
PUBLIC EjsRegExp *ejsParseRegExp(Ejs *ejs, EjsString *pattern)
{
    EjsRegExp   *rp;
    cchar       *errMsg;
    char        *cp, *dp;
    wchar       *flags;
    int         column, errCode;

    if (pattern->length == 0 || pattern->value[0] != '/') {
        ejsThrowArgError(ejs, "Bad regular expression pattern. Must start with '/'");
        return 0;
    }
    if ((rp = ejsCreateObj(ejs, ESV(RegExp), 0)) == 0) {
        return 0;
    }
    /*
        Strip off flags for passing to pcre_compile2
     */
    if (pattern->value[0] == '/') {
        rp->pattern = sclone(&pattern->value[1]);
        if ((flags = wrchr(rp->pattern, '/')) != 0) {
            if (flags == rp->pattern) {
                ejsThrowArgError(ejs, "Bad regular expression pattern. Must end with '/'");
                return 0;
            }
            rp->options = parseFlags(rp, &flags[1]);
            *flags = 0;
        }
        /*
            NOTE: we don't expect backquotes to be quoted. That only happens when interpreting literal js code and JSON
         */
        for (dp = cp = rp->pattern; *cp; ) {
            if (*cp == '\\' && cp[1] == '/') {
                cp++;
            }
            *dp++ = *cp++;
        }
        *dp++ = '\0';

    } else {
        rp->pattern = sclone(&pattern->value[1]);
    }
    rp->compiled = pcre_compile2(rp->pattern, rp->options, &errCode, &errMsg, &column, NULL);
    if (rp->compiled == NULL) {
        ejsThrowArgError(ejs, "Cannot compile regular expression '%s'. Error %s at column %d", rp->pattern, errMsg, column);
        return 0;
    }
    return rp;
}
Пример #12
0
void ScriptManager::parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stream) {
	Common::String line = stream.readLine();
	trimCommentsAndWhiteSpace(&line);

	while (!stream.eos() && !line.contains('}')) {
		if (line.matchString("criteria {", true)) {
			parseCriteria(stream, puzzle->criteriaList);
		} else if (line.matchString("results {", true)) {
			parseResults(stream, puzzle->resultActions);
		} else if (line.matchString("flags {", true)) {
			setStateFlags(puzzle->key, parseFlags(stream));
		}

		line = stream.readLine();
		trimCommentsAndWhiteSpace(&line);
	}
}
Пример #13
0
/*
    Create an initialized regular expression object. The pattern should NOT include the slash delimiters. 
 */
PUBLIC EjsRegExp *ejsCreateRegExp(Ejs *ejs, cchar *pattern, cchar *flags)
{
    EjsRegExp   *rp;
    cchar       *errMsg;
    int         column, errCode;

    if ((rp = ejsCreateObj(ejs, ESV(RegExp), 0)) == 0) {
        return 0;
    }
    rp->pattern = sclone(pattern);
    rp->options = parseFlags(rp, (wchar*) flags);
    rp->compiled = pcre_compile2(rp->pattern, rp->options, &errCode, &errMsg, &column, NULL);
    if (rp->compiled == NULL) {
        ejsThrowArgError(ejs, "Cannot compile regular expression '%s'. Error %s at column %d", rp->pattern, errMsg, column);
        return 0;
    }
    return rp;
}
Пример #14
0
static EjsRegExp *regex_Constructor(Ejs *ejs, EjsRegExp *rp, int argc, EjsObj **argv)
{
    cchar       *errMsg;
    int         column, errCode;

    rp->pattern = wclone(ejsToString(ejs, argv[0])->value);
    rp->options = PCRE_JAVASCRIPT_COMPAT;

    if (argc == 2) {
        rp->options |= parseFlags(rp, ejsToString(ejs, argv[1])->value);
    }
    if (rp->compiled) {
        free(rp->compiled);
    }
    if ((rp->compiled = pcre_compile2(rp->pattern, rp->options, &errCode, &errMsg, &column, NULL)) == 0) {
        ejsThrowArgError(ejs, "Cannot compile regular expression '%s'. Error %s at column %d", rp->pattern, errMsg, column);
        return 0;
    }
    return rp;
}
Пример #15
0
PhpClass::PhpClass(const folly::dynamic &c) :
  m_class(c),
  m_idlName(c["name"].asString()),
  m_phpName(toPhpName(m_idlName)),
  m_cppName(toCppName(m_idlName)),
  m_flags(parseFlags(m_class["flags"])),
  m_desc(getFollyDynamicDefaultString(c, "desc", "")) {

  auto ifacesIt = m_class.find("ifaces");
  if (ifacesIt != m_class.items().end()) {
    auto ifaces = ifacesIt->second;
    if (!ifaces.isArray()) {
      throw std::logic_error(
        folly::format("Class {0}.ifaces field must be an array",
          m_idlName).str()
      );
    }
    for (auto &interface : ifaces) {
      m_ifaces.push_back(interface.asString());
    }
  }

  for (auto const& f : c["funcs"]) {
    PhpFunc func(f, getCppName());
    m_methods.push_back(func);
  }

  if (c.find("consts") != c.items().end()) {
    for (auto const& cns : c["consts"]) {
      PhpConst cons(cns, getCppName());
      m_constants.push_back(cons);
    }
  }

  if (c.find("properties") != c.items().end()) {
    for (auto const& prp : c["properties"]) {
      PhpProp prop(prp, getCppName());
      m_properties.push_back(prop);
    }
  }
}
Пример #16
0
TextureResource::TextureResource(
              resource_group::ResourceGroup resourceGroup,
        const std::string&                  filePath,
              unsigned                      frameRate,
              bool                          repeat,
              unsigned                      begin,
              unsigned                      end,
              unsigned                      flags )
    :
    Resource    ( resourceGroup ),
    m_type      ( tex::ANIMATION ),
    m_filePath  ( filePath ),
    m_frameRate ( frameRate ),
    m_repeat    ( repeat ),
    m_begin     ( begin ),
    m_end       ( end ),
    m_flags     ( flags ),
    m_clamp     ( false ),
    m_showPixels( false )
{
    parseFlags();
}
istream& DirectionalLight::read (istream& in)
{
  int numFlags = 1;
  Flag flags[1] = { { (char*)"-n", STRING, false,  MAX_NAME, name }
                  };

  if (parseFlags(in, flags, numFlags) == -1)
  {
    cerr << "ERROR: Directional Light: flag parsing failed!" << endl;
    return in;
  }

  in >> color >> direction;

  direction.normalize();

  if (in.fail())
  {
    cerr << "ERROR: Directional Light: unknown stream failure" << endl;
    return in;
  }

  return in;
}
Пример #18
0
PhpFunc::PhpFunc(const folly::dynamic& d,
                 const fbstring& className) :
    m_idlName(d["name"].asString()),
    m_phpName(toPhpName(m_idlName)),
    m_cppName(toCppName(m_idlName)),
    m_className(className),
    m_func(d),
    m_desc(getFollyDynamicDefaultString(d, "desc", "")),
    m_returnRef(d.getDefault("ref", "false") == "true"),
    m_returnKindOf(KindOfNull),
    m_returnCppType("void"),
    m_returnPhpType("void"),
    m_minNumParams(0),
    m_numTypeChecks(0) {

  if (isMethod() &&
      m_idlName.find_last_of(NAMESPACE_STRING) != std::string::npos) {
    throw std::logic_error(
      folly::format("'{0}' is a method and cannot have a namespace in its name",
                    m_idlName).str()
    );
  }
  auto returnIt = d.find("return");
  if (returnIt != d.items().end()) {
    auto retNode = returnIt->second;
    auto typeIt = retNode.find("type");
    if (typeIt != retNode.items().end()) {
      auto type = typeIt->second;
      if ((type.isString()) && (type != "void") && (type != "null")) {
        m_returnKindOf = m_returnRef ? KindOfRef : kindOfFromDynamic(type);
        m_returnCppType = typeString(type, true);
        m_returnPhpType = phpTypeFromDataType(m_returnKindOf);
      }
    }
    m_returnDesc = getFollyDynamicDefaultString(retNode, "desc", "");
  }

  auto args = d.find("args");
  if (args == d.items().end() || !args->second.isArray()) {
    throw std::logic_error(
      folly::format("'{0}' must have an array field 'args'", m_idlName).str()
    );
  }
  auto ret = d.find("return");
  if (ret == d.items().end() || !ret->second.isObject() ||
      ret->second.find("type") == ret->second.items().end()) {
    throw std::logic_error(
      folly::format("'{0}' must have an array field 'return', which must have "
                    "a string field 'type'", m_idlName).str()
    );
  }

  bool magic = isMagicMethod();

  m_flags = parseFlags(m_func["flags"]);

  ParamMode paramMode = ParamMode::CoerceAndCall;
  if (m_flags & ParamCoerceModeNull) {
    paramMode = ParamMode::ZendNull;
  } else if (m_flags & ParamCoerceModeFalse) {
    paramMode = ParamMode::ZendFalse;
  }

  for (auto &p : args->second) {
    PhpParam param(p, magic, paramMode);
    m_params.push_back(param);
    if (!param.hasDefault()) {
      ++m_minNumParams;
    }
    if (param.isCheckedType()) {
      ++m_numTypeChecks;
    }
  }
}
Пример #19
0
int main(int argc, char *argv[])
{
    int i;
    int numRules = (argc-1)/3; // number of rules 
    int ruleIdx = 0; // index of rule (ptr) in array of rule pointers 
    Ruleptr rules[numRules]; // create an array of rule pointers
    Ruleptr currentRulePtr; // pointer to current rule

    /* Argument checking
     * Ensure correct number and type of arguments
     */

    if(!(strcmp(argv[0],"Subst16") == 0 || strcmp(argv[0], "./Subst16") == 0)) {
	    exit(EXIT_FAILURE);
    }

    if(argc < 4 || (argc-1)%3 > 0) {
        exit(EXIT_FAILURE);
    }

    // initialize rules array
    memset(rules, 0, numRules * sizeof(Ruleptr));

    /* Rule parsing 
     * Creates an array of pointers to rules in order 
     */
	
    for(i = 1; i < argc; i++) {
        if(i % 3 == 1) {
            /* error check for TO, make sure its a string and that it contains valid characters */
            currentRulePtr = malloc(sizeof(Rule)); // create new rule
	        currentRulePtr->FROM = argv[i];          
        }
        else if(i % 3 == 2) {
            /* error check for TO, make sure its a string and that it contains valid characters */
            currentRulePtr->TO = argv[i];
        }
        else if(i % 3 == 0) {
            /* error check for flags - make sure it starts with a dash and has no spaces/odd characters */
            parseFlags(argv[i], currentRulePtr);
            rules[ruleIdx++] = currentRulePtr;
        }
    }

    /* Read from stdin and apply filters */
    int j = 0;
    currentRulePtr = rules[j];
    char *input;
    char *res = NULL;

    while((input = getLine(stdin)) != NULL) {
            if(input[strlen(input)-1] == '\n') input[strlen(input)-1] = '\0';
            res = NULL;

	       j = 0;

            for(int i = 0; i < strlen(input) || j < numRules; i++) {
                res = str_replace(input, currentRulePtr->FROM, currentRulePtr->TO, currentRulePtr->filter);

                if (input && res && strcmp(input, res) == 0) {  // if no change
                    if(currentRulePtr->onFailureRuleIndex < numRules && currentRulePtr->onFailureRuleIndex > -1) {
                        if(currentRulePtr->onFailureRuleIndex > -1) {
                            j = currentRulePtr->onFailureRuleIndex;
                            currentRulePtr = rules[j];
                        }
                    } 
                    // if no Sn or Fm rule specified, go to next rule if it exists
                    else if(currentRulePtr->onFailureRuleIndex == -1 && j+1 < numRules) {
		        currentRulePtr = rules[++j];
			free(res);
                    }
                    else {
                        break;
                    }
                } else if(res) {
                    i = 0; // reset iterator
                    if(currentRulePtr->onSuccessRuleIndex < numRules && currentRulePtr->onSuccessRuleIndex > -1) {
                        if(currentRulePtr->onSuccessRuleIndex > -1) {
                            j = currentRulePtr->onSuccessRuleIndex;
                            currentRulePtr = rules[j];
                        }
                    } 
                    // if no Sn or Fm rule specified, go to next rule if it exists
                    else if(currentRulePtr->onSuccessRuleIndex == -1 && j+1 < numRules) {
                        currentRulePtr = rules[++j];
                    }
                    else {
                        break;
                    }
                    free(input);
                    input = res;
                }

            }

        for(int idx = 0; res && idx < strlen(res); idx++) {
            putchar(res[idx]);
        }
        printf("\n");

        free(res);
        free(input);
    }
    // free rules
    for(int r = 0; r < numRules; r++) {
        free(rules[r]);
    }

    return EXIT_SUCCESS;
}
Пример #20
0
int defineRemote(char * key, char * val, char *val2, struct ir_remote *rem)
{
	if ((strcasecmp("name",key))==0){
		if(rem->name!=NULL) free(rem->name);
		rem->name=s_strdup(val);
		LOGPRINTF(1,"parsing %s remote",val);
		return(1);
	}
#ifdef DYNCODES
	if ((strcasecmp("dyncodes_name",key))==0){
		if(rem->dyncodes_name!=NULL)
		{
			free(rem->dyncodes_name);
		}
		rem->dyncodes_name=s_strdup(val);
		return(1);
	}
#endif
	else if ((strcasecmp("bits",key))==0){
		rem->bits=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("flags",key)==0){
		rem->flags|=parseFlags(val);
		return(1);
	}
	else if (strcasecmp("eps",key)==0){
		rem->eps=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("aeps",key)==0){
		rem->aeps=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("plead",key)==0){
		rem->plead=s_strtolirc_t(val);
		return(1);
	}
	else if (strcasecmp("ptrail",key)==0){
		rem->ptrail=s_strtolirc_t(val);
		return(1);
	}
	else if (strcasecmp("pre_data_bits",key)==0){
		rem->pre_data_bits=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("pre_data",key)==0){
		rem->pre_data=s_strtocode(val);
		return(1);
	}
	else if (strcasecmp("post_data_bits",key)==0){
		rem->post_data_bits=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("post_data",key)==0){
		rem->post_data=s_strtocode(val);
		return(1);
	}
	else if (strcasecmp("gap",key)==0){
		if(val2 != NULL)
		{
			rem->gap2=s_strtoul(val2);
		}
		rem->gap=s_strtoul(val);
		return(val2 != NULL ? 2:1);
	}
	else if (strcasecmp("repeat_gap",key)==0){
		rem->repeat_gap=s_strtoul(val);
		return(1);
	}
	/* obsolete: use toggle_bit_mask instead */
	else if (strcasecmp("toggle_bit",key)==0){
		rem->toggle_bit = s_strtoi(val);
		return 1;
	}
	else if (strcasecmp("toggle_bit_mask",key)==0){
		rem->toggle_bit_mask = s_strtocode(val);
		return 1;
	}
	else if (strcasecmp("toggle_mask",key)==0){
		rem->toggle_mask=s_strtocode(val);
		return(1);
	}
	else if (strcasecmp("rc6_mask",key)==0){
		rem->rc6_mask=s_strtocode(val);
		return(1);
	}
	else if (strcasecmp("ignore_mask",key)==0){
		rem->ignore_mask=s_strtocode(val);
		return(1);
	}
	/* obsolete name */
	else if (strcasecmp("repeat_bit",key)==0){
		rem->toggle_bit=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("suppress_repeat",key)==0){
		rem->suppress_repeat=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("min_repeat",key)==0){
		rem->min_repeat=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("min_code_repeat",key)==0){
		rem->min_code_repeat=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("frequency",key)==0){
		rem->freq=s_strtoui(val);
		return(1);
	}
	else if (strcasecmp("duty_cycle",key)==0){
		rem->duty_cycle=s_strtoui(val);
		return(1);
	}
	else if (strcasecmp("baud",key)==0){
		rem->baud=s_strtoui(val);
		return(1);
	}
	else if (strcasecmp("serial_mode",key)==0){
		if(val[0]<'5' || val[0]>'9')
		{
			logprintf(LOG_ERR,"error in configfile line %d:",
				  line);
			logprintf(LOG_ERR,"bad bit count");
			parse_error=1;
			return 0;
		}
		rem->bits_in_byte=val[0]-'0';
		switch(toupper(val[1]))
		{
		case 'N':
			rem->parity = IR_PARITY_NONE;
			break;
		case 'E':
			rem->parity = IR_PARITY_EVEN;
			break;
		case 'O':
			rem->parity = IR_PARITY_ODD;
			break;
		default:
			logprintf(LOG_ERR,"error in configfile line %d:",
				  line);
			logprintf(LOG_ERR,"unsupported parity mode");
			parse_error=1;
			return 0;
		}
		if(strcmp(val+2, "1.5")==0)
		{
			rem->stop_bits=3;
		}
		else
		{
			rem->stop_bits=s_strtoui(val+2)*2;
		}
		return(1);
	}
	else if (val2!=NULL)
	{
		if (strcasecmp("header",key)==0){
			rem->phead=s_strtolirc_t(val);
			rem->shead=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("three",key)==0){
			rem->pthree=s_strtolirc_t(val);
			rem->sthree=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("two",key)==0){
			rem->ptwo=s_strtolirc_t(val);
			rem->stwo=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("one",key)==0){
			rem->pone=s_strtolirc_t(val);
			rem->sone=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("zero",key)==0){
			rem->pzero=s_strtolirc_t(val);
			rem->szero=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("foot",key)==0){
			rem->pfoot=s_strtolirc_t(val);
			rem->sfoot=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("repeat",key)==0){
			rem->prepeat=s_strtolirc_t(val);
			rem->srepeat=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("pre",key)==0){
			rem->pre_p=s_strtolirc_t(val);
			rem->pre_s=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("post",key)==0){
			rem->post_p=s_strtolirc_t(val);
			rem->post_s=s_strtolirc_t(val2);
			return(2);
		}
	}
	if(val2){
		logprintf(LOG_ERR,"error in configfile line %d:",line);
		logprintf(LOG_ERR,"unknown definiton: \"%s %s %s\"",
			  key, val, val2);
	}else{
		logprintf(LOG_ERR,"error in configfile line %d:",line);
		logprintf(LOG_ERR,"unknown definiton or too few arguments: "
			  "\"%s %s\"",key, val);
	}
	parse_error=1;
	return(0);
}
Пример #21
0
int defineRemote(char * key, char * val, char *val2, struct ir_remote *rem)
{
	if ((strcasecmp("name",key))==0){
		if(rem->name!=NULL) free(rem->name);
		rem->name=s_strdup(val);
		LOGPRINTF(1,"parsing %s remote",val);
		return(1);
	}
	else if ((strcasecmp("bits",key))==0){
		rem->bits=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("flags",key)==0){
		rem->flags|=parseFlags(val);
		return(1);
	}
	else if (strcasecmp("eps",key)==0){
		rem->eps=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("aeps",key)==0){
		rem->aeps=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("plead",key)==0){
		rem->plead=s_strtolirc_t(val);
		return(1);
	}
	else if (strcasecmp("ptrail",key)==0){
		rem->ptrail=s_strtolirc_t(val);
		return(1);
	}
	else if (strcasecmp("pre_data_bits",key)==0){
		rem->pre_data_bits=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("pre_data",key)==0){
		rem->pre_data=s_strtocode(val);
		return(1);
	}
	else if (strcasecmp("post_data_bits",key)==0){
		rem->post_data_bits=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("post_data",key)==0){
		rem->post_data=s_strtocode(val);
		return(1);
	}
	else if (strcasecmp("gap",key)==0){
		rem->gap=s_strtoul(val);
		return(1);
	}
	else if (strcasecmp("repeat_gap",key)==0){
		rem->repeat_gap=s_strtoul(val);
		return(1);
	}
	else if (strcasecmp("toggle_bit",key)==0){
		rem->toggle_bit=s_strtoi(val);
		return(1);
	}
	/* obsolete name */
	else if (strcasecmp("repeat_bit",key)==0){
		rem->toggle_bit=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("min_repeat",key)==0){
		rem->min_repeat=s_strtoi(val);
		return(1);
	}
	else if (strcasecmp("frequency",key)==0){
		rem->freq=s_strtoui(val);
		return(1);
	}
	else if (strcasecmp("duty_cycle",key)==0){
		rem->duty_cycle=s_strtoui(val);
		return(1);
	}
	else if (val2!=NULL)
	{
		if (strcasecmp("header",key)==0){
			rem->phead=s_strtolirc_t(val);
			rem->shead=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("three",key)==0){
			rem->pthree=s_strtolirc_t(val);
			rem->sthree=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("two",key)==0){
			rem->ptwo=s_strtolirc_t(val);
			rem->stwo=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("one",key)==0){
			rem->pone=s_strtolirc_t(val);
			rem->sone=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("zero",key)==0){
			rem->pzero=s_strtolirc_t(val);
			rem->szero=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("foot",key)==0){
			rem->pfoot=s_strtolirc_t(val);
			rem->sfoot=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("repeat",key)==0){
			rem->prepeat=s_strtolirc_t(val);
			rem->srepeat=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("pre",key)==0){
			rem->pre_p=s_strtolirc_t(val);
			rem->pre_s=s_strtolirc_t(val2);
			return(2);
		}
		else if (strcasecmp("post",key)==0){
			rem->post_p=s_strtolirc_t(val);
			rem->post_s=s_strtolirc_t(val2);
			return(2);
		}
	}
	if(val2){
		logprintf(LOG_ERR,"error in configfile line %d:",line);
		logprintf(LOG_ERR,"unknown definiton: \"%s %s %s\"",
			  key, val, val2);
	}else{
		logprintf(LOG_ERR,"error in configfile line %d:",line);
		logprintf(LOG_ERR,"unknown definiton or too few arguments: "
			  "\"%s %s\"",key, val);
	}
	parse_error=1;
	return(0);
}
RegEx::RegEx(istream & is1, ostream & os1, IString & str1):
isAct(is1), osAct(os1), strFlags(str1)
{
   parseFlags();
}
Пример #23
0
/**
 * Creates a new entityclass for given parsed definition
 * @param entityDef parsed definition information to use
 * @return a new entity class or 0 if something was wrong with definition
 */
EntityClass *EntityClassScannerUFO::initFromDefinition (const entityDef_t* definition)
{
	g_debug("Creating entity class for entity definition '%s'\n", definition->classname);

	EntityClass* e = Eclass_Alloc();
	e->free = &Eclass_Free;
	e->m_name = definition->classname;

	for (int idx = 0; idx < definition->numKeyDefs; idx++) {
		const entityKeyDef_t* keydef = &definition->keyDefs[idx];
		const std::string keyName = keydef->name;

		if (keyName == "color") {
			//not using _color as this is a valid attribute flag
			// grab the color, reformat as texture name
			const int r = sscanf(keydef->desc, "%f %f %f", &e->color[0], &e->color[1], &e->color[2]);
			if (r != 3) {
				g_message("Invalid color token given\n");
				return 0;
			}
		} else if (keyName == "size") {
			e->fixedsize = true;
			const int r = sscanf(keydef->desc, "%f %f %f %f %f %f", &e->mins[0], &e->mins[1], &e->mins[2], &e->maxs[0],
					&e->maxs[1], &e->maxs[2]);
			if (r != 6) {
				g_message("Invalid size token given\n");
				return 0;
			}
		} else if (keyName == "description") {
			e->m_comments = keydef->desc;
		} else if (keyName == "spawnflags") {
			if (keydef->flags & ED_ABSTRACT) {
				/* there are two keydefs, abstract holds the valid levelflags, the other one default value and type */
				const char* flags = keydef->desc;
				parseFlags(e, &flags);
			} else {
				parseAttribute(e, keydef);
			}
		} else if (keyName == "classname") {
			/* ignore, read from head */
			continue;
		} else if (keyName == "model") {
			/** @todo what does that modelpath stuff do? it does not read anything from keydef */
			e->m_modelpath = os::standardPath(e->m_modelpath);
			const bool mandatory = (keydef->flags & ED_MANDATORY);
			EntityClass_insertAttribute(*e, "model", EntityClassAttribute("model", "model", mandatory));
		} else {
			/* all other keys are valid attribute keys */
			parseAttribute(e, keydef);
		}
	}

#if 0
	/**
	 * @todo direction and angle are 2 types used for different display
	 * (see entityinspector DirectionAttribute and AngleAttribute)
	 * the problem is that different entities have "angle" property, but different defines what values are valid
	 * which is actually not reflected by this code. Perhaps we should introduce different types for these representations.
	 */
	EntityClassAttribute *angle = e->getAttribute("angle");
	if (angle) {
		if (e->fixedsize) {
			angle->name = _("Yaw Angle");
		} else {
			angle->name = _("Direction");
		}
	}
#endif
	eclass_capture_state(e);

	return e;
}
bool VirtualKeyboardParser::parserCallback_event(ParserNode *node) {
    // if just checking resolutions we're done
    if (_parseMode == kParseCheckResolutions)
        return true;

    String name = node->values["name"];
    if (_mode->events.contains(name))
        return parserError("Event '%s' has already been defined", name.c_str());

    VirtualKeyboard::VKEvent *evt = new VirtualKeyboard::VKEvent();
    evt->name = name;

    String type = node->values["type"];
    if (type.equalsIgnoreCase("key")) {
        if (!node->values.contains("code") || !node->values.contains("ascii")) {
            delete evt;
            return parserError("Key event element must contain code and ascii attributes");
        }
        evt->type = VirtualKeyboard::kVKEventKey;

        KeyState *ks = (KeyState*) malloc(sizeof(KeyState));
        ks->keycode = (KeyCode)atoi(node->values["code"].c_str());
        ks->ascii = atoi(node->values["ascii"].c_str());
        ks->flags = 0;
        if (node->values.contains("modifiers"))
            ks->flags = parseFlags(node->values["modifiers"]);
        evt->data = ks;

    } else if (type.equalsIgnoreCase("modifier")) {
        if (!node->values.contains("modifiers")) {
            delete evt;
            return parserError("Key modifier element must contain modifier attributes");
        }

        evt->type = VirtualKeyboard::kVKEventModifier;
        byte *flags = (byte*) malloc(sizeof(byte));
        *(flags) = parseFlags(node->values["modifiers"]);
        evt->data = flags;

    } else if (type.equalsIgnoreCase("switch_mode")) {
        if (!node->values.contains("mode")) {
            delete evt;
            return parserError("Switch mode event element must contain mode attribute");
        }

        evt->type = VirtualKeyboard::kVKEventSwitchMode;
        String& mode = node->values["mode"];
        char *str = (char*) malloc(sizeof(char) * mode.size() + 1);
        memcpy(str, mode.c_str(), sizeof(char) * mode.size());
        str[mode.size()] = 0;
        evt->data = str;
    } else if (type.equalsIgnoreCase("submit")) {
        evt->type = VirtualKeyboard::kVKEventSubmit;
    } else if (type.equalsIgnoreCase("cancel")) {
        evt->type = VirtualKeyboard::kVKEventCancel;
    } else if (type.equalsIgnoreCase("clear")) {
        evt->type = VirtualKeyboard::kVKEventClear;
    } else if (type.equalsIgnoreCase("delete")) {
        evt->type = VirtualKeyboard::kVKEventDelete;
    } else if (type.equalsIgnoreCase("move_left")) {
        evt->type = VirtualKeyboard::kVKEventMoveLeft;
    } else if (type.equalsIgnoreCase("move_right")) {
        evt->type = VirtualKeyboard::kVKEventMoveRight;
    } else {
        delete evt;
        return parserError("Event type '%s' not known", type.c_str());
    }

    _mode->events[name] = evt;

    return true;
}