Beispiel #1
0
bool config_skip_section(struct config *conf, struct config_line *line)
{
    if (line->type != CONFIG_LINE_TYPE_SECTION)
        return false;

    return find_section_end(conf);
}
Beispiel #2
0
bool config_skip_section(config_t *conf, config_line_t *line)
{
    if (conf->error_message)
        return false;
    if (line->type != CONFIG_LINE_TYPE_SECTION)
        return false;
    return find_section_end(conf, line, 0);
}
Beispiel #3
0
struct config *config_isolate_section(struct config *current_conf,
    struct config_line *current_line)
{
    struct lexer *lexer;
    struct config *isolated;
    const char *pos;

    if (current_line->type != CONFIG_LINE_TYPE_SECTION)
        return NULL;

    isolated = malloc(sizeof(*isolated));
    if (!isolated)
        return NULL;

    memcpy(isolated, current_conf, sizeof(*isolated));
    strbuf_init(&isolated->parser.strbuf);

    isolated->mapped.addr = NULL;
    isolated->mapped.sz = 0;

    lexer = &isolated->parser.lexer;
    pos = lexer->pos;
    lexer->start = lexer->pos;

    pos = isolated->parser.lexer.pos;
    if (!find_section_end(isolated)) {
        strbuf_free(&isolated->parser.strbuf);
        free(isolated);

        config_error(current_conf,
            "Could not find section end while trying to isolate");

        return NULL;
    }

    lexer->end = lexer->pos;
    lexer->start = lexer->pos = pos;

    return isolated;
}
Beispiel #4
0
bool config_isolate_section(config_t *current_conf,
    config_line_t *current_line, config_t *isolated)
{
    long startpos, endpos;
    bool r = false;

    *isolated = *current_conf;

    if (current_conf->error_message)
        return false;
    if (current_line->type != CONFIG_LINE_TYPE_SECTION)
        return false;

    startpos = ftell(current_conf->file);
    if (startpos < 0)
        return false;
    if (!find_section_end(current_conf, current_line, 0))
        goto resetpos;
    endpos = ftell(current_conf->file);
    if (endpos < 0)
        goto resetpos;

    if (!config_open(isolated, current_conf->path))
        goto resetpos;
    if (fseek(isolated->file, startpos, SEEK_SET) < 0)
        goto resetpos;

    isolated->isolated.end = endpos;
    r = true;

resetpos:
    if (fseek(current_conf->file, startpos, SEEK_SET) < 0) {
        config_error(current_conf, "Could not reset file position");
        return false;
    }
    if (!r)
        config_error(current_conf, "Unknown error while isolating section");
    return r;
}
Beispiel #5
0
static bool find_section_end(config_t *config, config_line_t *line, int recursion_level)
{
    if (recursion_level > 10) {
        config_error(config, "Recursion level too deep");
        return false;
    }

    while (config_read_line(config, line)) {
        switch (line->type) {
        case CONFIG_LINE_TYPE_LINE:
            continue;
        case CONFIG_LINE_TYPE_SECTION:
            if (!find_section_end(config, line, recursion_level + 1))
                return false;
            break;
        case CONFIG_LINE_TYPE_SECTION_END:
            return true;
        }
    }

    return false;
}
Beispiel #6
0
static void next_token()
{
	if(tok[0] || tt==string_)
    {
		num_tokens++;
		tokens[num_tokens-1] = tokens[num_tokens-2]
			+ strlen(tokens[num_tokens-2]) + 1;
		tok[0] = 0;
    }
	
	// get to the next token, ignoring spaces, newlines,
	// useless chars, comments etc
	
	while(1)
    {
		// empty whitespace
		if(*rover && (*rover==' ' || *rover<32))
		{
			while((*rover==' ' || *rover<32) && *rover) rover++;
		}
		// end-of-script?
		if(!*rover)
		{
			if(tokens[0][0])
			{
			/*
			C_Printf("%s %i %i\n", tokens[0],
			rover-current_script->data, current_script->len);
				*/
				// line contains text, but no semicolon: an error
				script_error("missing ';'\n");
			}
			// empty line, end of command-list
			return;
		}
		// 11/8 comments moved to new preprocessor
		
		break;  // otherwise
    }
	
	if(num_tokens>1 && *rover == '(' && tokentype[num_tokens-2] == name_)
		tokentype[num_tokens-2] = function;
	
	if(*rover == '{' || *rover == '}')
    {
		if(*rover == '{')
		{
			bracetype = bracket_open;
			current_section = find_section_start(rover);
		}
		else            // closing brace
		{
			bracetype = bracket_close;
			current_section = find_section_end(rover);
		}
		if(!current_section)
		{
			I_Error("section not found!\n");
			return;
		}
    }
	else if(*rover == ':')  // label
    {
		// ignore the label : reset
		num_tokens = 1;
		tokens[0][0] = 0; tt = name_;
		rover++;        // ignore
    }
	else if(*rover == '\"')
    {
		tt = string_;
		if(tokentype[num_tokens-2] == string_)
			num_tokens--;   // join strings
		rover++;
    }
	else
    {
		tt = isop(*rover) ? operator_ : isnum(*rover) ? number : name_;
    }
}