Пример #1
0
bool is_track(char * line)
{
    size_t length = get_line_length(line);

    char * bookmark = line;

    if (is_upper_case_letter(line[0]))
        bookmark += 2;
    else
        return false;

    int first_part_count = 0;
    int second_part_count = 0;
    int third_part_count = 0;

    while(bookmark < line + length && is_code(bookmark))
    {
        bookmark += 6;
        first_part_count++;
    }

    while(bookmark != NULL && bookmark < line + length && is_fraction(bookmark))
    {
        bookmark += 6;
        second_part_count++;
    }

    while(bookmark != NULL && bookmark < line + length && is_code(bookmark))
    {
        bookmark += 6;
        third_part_count++;
    }

    return (first_part_count       &&
            second_part_count == 4 &&
            third_part_count);
}
Пример #2
0
struct value_iface_t * st_new_duration_literal(
    char *string,
    const struct st_location_t *string_location,
    struct parser_t *parser)
{
    char *work_buffer;
    enum duration_part_t part_type;
    double part_content;
    char defined = 0x00;
    char fractions = 0x00;
    unsigned parts_defined = 0;
    struct duration_t duration;
    
    strip_underscores(string);
    if(find_start(string, &(work_buffer)) == ESSTEE_ERROR)
    {
	parser->errors->internal_error( /* Flex returning wrong type of string */
	    parser->errors,
	    __FILE__,
	    __FUNCTION__,
	    __LINE__);
	    
	goto error_free_resources;
    }
	
    while((part_type = next_duration_part(&(work_buffer), &(part_content), string_location, parser)) != PLITERALS_NOTHING)
    {
	switch(part_type)
	{
	case PLITERALS_ERROR:
	    goto error_free_resources;
			
	case PLITERALS_D:
	    duration.d = part_content;
	    defined |= (1 << 0);
	    fractions |= is_fraction(part_content, 0);
	    parts_defined++;
	    break;

	case PLITERALS_H:
	    duration.h = part_content;
	    defined |= (1 << 1);
	    fractions |= is_fraction(part_content, 1);
	    parts_defined++;
	    break;

	case PLITERALS_M:
	    duration.m = part_content;
	    defined |= (1 << 2);
	    fractions |= is_fraction(part_content, 2);
	    parts_defined++;
	    break;

	case PLITERALS_S:
	    duration.s = part_content;
	    defined |= (1 << 3);
	    fractions |= is_fraction(part_content, 3);
	    parts_defined++;
	    break;

	case PLITERALS_MS:
	    duration.ms = part_content;
	    defined |= (1 << 4);
	    fractions |= is_fraction(part_content, 4);
	    parts_defined++;
	    break;

	default:
	    parser->errors->internal_error(
		parser->errors,
		__FILE__,
		__FUNCTION__,
		__LINE__);

	    goto error_free_resources;
	}
    }

    if(defined == 0)
    {
	parser->errors->internal_error( /* Flex returning wrong type of string (empty) */
	    parser->errors,
	    __FILE__,
	    __FUNCTION__,
	    __LINE__);

	goto error_free_resources;
    }
    else if(fractions > defined || (parts_defined > 1 && fractions == defined))
    {
	parser->errors->new_issue_at(
	    parser->errors,
	    "only the last duration part may contain a fraction",
	    ESSTEE_IO_ERROR,
	    1,
	    string_location);
	    
	goto error_free_resources;
    }
    
    free(string);
    return st_new_typeless_duration_value(duration.d,
					  duration.h,
					  duration.m,
					  duration.s,
					  duration.ms,
					  CONSTANT_VALUE,
					  parser->config,
					  parser->errors);

error_free_resources:
    free(string);
    return NULL;
}