| 801 | } |
| 802 | |
| 803 | static int parse_script(void *log, char *script, int script_len, |
| 804 | struct sbg_script *rscript) |
| 805 | { |
| 806 | struct sbg_parser sp = { |
| 807 | .log = log, |
| 808 | .script = script, |
| 809 | .end = script + script_len, |
| 810 | .cursor = script, |
| 811 | .line_no = 1, |
| 812 | .err_msg = "", |
| 813 | .scs = { |
| 814 | /* default values */ |
| 815 | .start_ts = AV_NOPTS_VALUE, |
| 816 | .sample_rate = 44100, |
| 817 | .opt_fade_time = 60 * AV_TIME_BASE, |
| 818 | }, |
| 819 | }; |
| 820 | int r; |
| 821 | |
| 822 | lex_space(&sp); |
| 823 | while (sp.cursor < sp.end) { |
| 824 | r = parse_options(&sp); |
| 825 | if (r < 0) |
| 826 | goto fail; |
| 827 | if (!r && !lex_line_end(&sp)) |
| 828 | break; |
| 829 | } |
| 830 | while (sp.cursor < sp.end) { |
| 831 | r = parse_named_def(&sp); |
| 832 | if (!r) |
| 833 | r = parse_time_sequence(&sp, 0); |
| 834 | if (!r) |
| 835 | r = lex_line_end(&sp) ? 1 : AVERROR_INVALIDDATA; |
| 836 | if (r < 0) |
| 837 | goto fail; |
| 838 | } |
| 839 | *rscript = sp.scs; |
| 840 | return 1; |
| 841 | fail: |
| 842 | free_script(&sp.scs); |
| 843 | if (!*sp.err_msg) |
| 844 | if (r == AVERROR_INVALIDDATA) |
| 845 | snprintf(sp.err_msg, sizeof(sp.err_msg), "syntax error"); |
| 846 | if (log && *sp.err_msg) { |
| 847 | const char *ctx = sp.cursor; |
| 848 | const char *ectx = av_x_if_null(memchr(ctx, '\n', sp.end - sp.cursor), |
| 849 | sp.end); |
| 850 | int lctx = ectx - ctx; |
| 851 | const char *quote = "\""; |
| 852 | if (lctx > 0 && ctx[lctx - 1] == '\r') |
| 853 | lctx--; |
| 854 | if (lctx == 0) { |
| 855 | ctx = "the end of line"; |
| 856 | lctx = strlen(ctx); |
| 857 | quote = ""; |
| 858 | } |
| 859 | av_log(log, AV_LOG_ERROR, "Error line %d: %s near %s%.*s%s.\n", |
| 860 | sp.line_no, sp.err_msg, quote, lctx, ctx, quote); |
no test coverage detected