%{ #include #include #include #include "configrc.yacc.h" #include "configrc.h" static unsigned int *get_rc_item_ptr(char *rc_item); static struct rc_item_t tmp; static int lineno = 1; static char linebuf[512]; extern YYSTYPE yylval; %} %% [\t ] ; /* ignore whitespace */ \n.* { strcpy(linebuf, yytext + 1);/* save the next line */ lineno++ ; yyless (1); /* give back all but the \n to rescan */ } = { return EQUAL; } \[beginrc\] { return BEGIN_RC;}; \[endrc\] { return END_RC; }; frame_start | frame_end | frame_width | frame_height | bits_per_second | target_percentage | window_size | initial_qp | min_qp | max_qp | force_kf | no_ref_last | no_ref_gf | no_ref_arf | frame_rate | intra_period | intra_idr_period | ip_period | quality | refresh_entropy_probs | copy_buffer_to_golden | copy_buffer_to_alternate | refresh_last | refresh_golden_frame | refresh_alternate_frame | bits_per_second0 | bits_per_second1 | bits_per_second2 | temporal_layer_id { yylval.rc_item = (struct rc_item_t *)malloc(sizeof(struct rc_item_t)); yylval.rc_item->rc_item_name = strdup(yytext); yylval.rc_item->rc_item_ptr = get_rc_item_ptr(yytext); return KEYWORD; } ([0-9]+)|(0x[a-fA-F0-9]+) { yylval.expr = strtoul(yytext,NULL,0);return NUMBER;} . ; %% void yyerror(char *msg) { printf("%s at '%s' in line %d:\n%s\n", msg, yytext, lineno, linebuf); } #define UPDATE_FIELD(field) \ if (!strcmp(#field, rc_item)) { \ last_rcparam->mask |= RC_MASK_##field; \ return &last_rcparam->field; \ } static unsigned int *get_rc_item_ptr(char *rc_item) { if (!strcmp("frame_start", rc_item)) return &last_rcparam->frame_start; if (!strcmp("frame_end", rc_item)) return &last_rcparam->frame_end; UPDATE_FIELD(frame_width); UPDATE_FIELD(frame_height); UPDATE_FIELD(bits_per_second); UPDATE_FIELD(target_percentage); UPDATE_FIELD(window_size); UPDATE_FIELD(initial_qp); UPDATE_FIELD(min_qp); UPDATE_FIELD(force_kf); UPDATE_FIELD(no_ref_last); UPDATE_FIELD(no_ref_gf); UPDATE_FIELD(no_ref_arf); UPDATE_FIELD(frame_rate); UPDATE_FIELD(intra_period); UPDATE_FIELD(intra_idr_period); UPDATE_FIELD(ip_period); UPDATE_FIELD(quality); UPDATE_FIELD(refresh_entropy_probs); UPDATE_FIELD(copy_buffer_to_golden); UPDATE_FIELD(copy_buffer_to_alternate); UPDATE_FIELD(refresh_last); UPDATE_FIELD(refresh_golden_frame); UPDATE_FIELD(refresh_alternate_frame); UPDATE_FIELD(bits_per_second0); UPDATE_FIELD(bits_per_second1); UPDATE_FIELD(bits_per_second2); UPDATE_FIELD(temporal_layer_id); printf("Unsupported RC field %s\n", rc_item); return NULL; } #define PRINT_FIELD(field) \ if (rc_param->mask & RC_MASK_##field) \ printf("\t%s=%d\n", #field, rc_param->field) void print_rcparam(struct rc_param_t *rc_param) { PRINT_FIELD(frame_width); PRINT_FIELD(frame_height); PRINT_FIELD(bits_per_second); PRINT_FIELD(target_percentage); PRINT_FIELD(window_size); PRINT_FIELD(initial_qp); PRINT_FIELD(min_qp); PRINT_FIELD(force_kf); PRINT_FIELD(no_ref_last); PRINT_FIELD(no_ref_gf); PRINT_FIELD(no_ref_arf); PRINT_FIELD(frame_rate); PRINT_FIELD(intra_period); PRINT_FIELD(intra_idr_period); PRINT_FIELD(ip_period); PRINT_FIELD(quality); PRINT_FIELD(refresh_entropy_probs); PRINT_FIELD(copy_buffer_to_golden); PRINT_FIELD(copy_buffer_to_alternate); PRINT_FIELD(refresh_last); PRINT_FIELD(refresh_golden_frame); PRINT_FIELD(refresh_alternate_frame); PRINT_FIELD(bits_per_second0); PRINT_FIELD(bits_per_second1); PRINT_FIELD(bits_per_second2); PRINT_FIELD(temporal_layer_id); return; }