static const char *srt_to_ass(AVCodecContext *avctx, char *out, char *out_end,

                              const char *in, int x1, int y1, int x2, int y2)

{

    char c, *param, buffer[128], tmp[128];

    int len, tag_close, sptr = 1, line_start = 1, an = 0, end = 0;

    SrtStack stack[16];



    stack[0].tag[0] = 0;

    strcpy(stack[0].param[PARAM_SIZE],  "{\\fs}");

    strcpy(stack[0].param[PARAM_COLOR], "{\\c}");

    strcpy(stack[0].param[PARAM_FACE],  "{\\fn}");



    if (x1 >= 0 && y1 >= 0) {

        if (x2 >= 0 && y2 >= 0 && (x2 != x1 || y2 != y1))

            out += snprintf(out, out_end-out,

                            "{\\an1}{\\move(%d,%d,%d,%d)}", x1, y1, x2, y2);

        else

            out += snprintf(out, out_end-out, "{\\an1}{\\pos(%d,%d)}", x1, y1);

    }



    for (; out < out_end && !end && *in; in++) {

        switch (*in) {

        case '\r':

            break;

        case '\n':

            if (line_start) {

                end = 1;

                break;

            }

            while (out[-1] == ' ')

                out--;

            out += snprintf(out, out_end-out, "\\N");

            line_start = 1;

            break;

        case ' ':

            if (!line_start)

                *out++ = *in;

            break;

        case '{':    /* skip all {\xxx} substrings except for {\an%d}

                        and all microdvd like styles such as {Y:xxx} */

            an += sscanf(in, "{\\an%*1u}%c", &c) == 1;

            if ((an != 1 && sscanf(in, "{\\%*[^}]}%n%c", &len, &c) > 0) ||

                sscanf(in, "{%*1[CcFfoPSsYy]:%*[^}]}%n%c", &len, &c) > 0) {

                in += len - 1;

            } else

                *out++ = *in;

            break;

        case '<':

            tag_close = in[1] == '/';

            if (sscanf(in+tag_close+1, "%127[^>]>%n%c", buffer, &len,&c) >= 2) {

                if ((param = strchr(buffer, ' ')))

                    *param++ = 0;

                if ((!tag_close && sptr < FF_ARRAY_ELEMS(stack)) ||

                    ( tag_close && sptr > 0 && !strcmp(stack[sptr-1].tag, buffer))) {

                    int i, j, unknown = 0;

                    in += len + tag_close;

                    if (!tag_close)

                        memset(stack+sptr, 0, sizeof(*stack));

                    if (!strcmp(buffer, "font")) {

                        if (tag_close) {

                            for (i=PARAM_NUMBER-1; i>=0; i--)

                                if (stack[sptr-1].param[i][0])

                                    for (j=sptr-2; j>=0; j--)

                                        if (stack[j].param[i][0]) {

                                            out += snprintf(out, out_end-out,

                                                            stack[j].param[i]);

                                            break;

                                        }

                        } else {

                            while (param) {

                                if (!strncmp(param, "size=", 5)) {

                                    unsigned font_size;

                                    param += 5 + (param[5] == '"');

                                    if (sscanf(param, "%u", &font_size) == 1) {

                                        snprintf(stack[sptr].param[PARAM_SIZE],

                                             sizeof(stack[0].param[PARAM_SIZE]),

                                             "{\\fs%u}", font_size);

                                    }

                                } else if (!strncmp(param, "color=", 6)) {

                                    param += 6 + (param[6] == '"');

                                    snprintf(stack[sptr].param[PARAM_COLOR],

                                         sizeof(stack[0].param[PARAM_COLOR]),

                                         "{\\c&H%X&}",

                                         html_color_parse(avctx, param));

                                } else if (!strncmp(param, "face=", 5)) {

                                    param += 5 + (param[5] == '"');

                                    len = strcspn(param,

                                                  param[-1] == '"' ? "\"" :" ");

                                    av_strlcpy(tmp, param,

                                               FFMIN(sizeof(tmp), len+1));

                                    param += len;

                                    snprintf(stack[sptr].param[PARAM_FACE],

                                             sizeof(stack[0].param[PARAM_FACE]),

                                             "{\\fn%s}", tmp);

                                }

                                if ((param = strchr(param, ' ')))

                                    param++;

                            }

                            for (i=0; i<PARAM_NUMBER; i++)

                                if (stack[sptr].param[i][0])

                                    out += snprintf(out, out_end-out,

                                                    stack[sptr].param[i]);

                        }

                    } else if (!buffer[1] && strspn(buffer, "bisu") == 1) {

                        out += snprintf(out, out_end-out,

                                        "{\\%c%d}", buffer[0], !tag_close);

                    } else {

                        unknown = 1;

                        snprintf(tmp, sizeof(tmp), "</%s>", buffer);

                    }

                    if (tag_close) {

                        sptr--;

                    } else if (unknown && !strstr(in, tmp)) {

                        in -= len + tag_close;

                        *out++ = *in;

                    } else

                        av_strlcpy(stack[sptr++].tag, buffer,

                                   sizeof(stack[0].tag));

                    break;

                }

            }

        default:

            *out++ = *in;

            break;

        }

        if (*in != ' ' && *in != '\r' && *in != '\n')

            line_start = 0;

    }



    out = FFMIN(out, out_end-3);

    while (!strncmp(out-2, "\\N", 2))

        out -= 2;

    while (out[-1] == ' ')

        out--;

    out += snprintf(out, out_end-out, "\r\n");

    return in;

}

static const char *srt_to_ass(AVCodecContext *avctx, char *out, char *out_end,

                              const char *in, int x1, int y1, int x2, int y2)

{

    char c, *param, buffer[128], tmp[128];

    int len, tag_close, sptr = 1, line_start = 1, an = 0, end = 0;

    SrtStack stack[16];



    stack[0].tag[0] = 0;

    strcpy(stack[0].param[PARAM_SIZE],  "{\\fs}");

    strcpy(stack[0].param[PARAM_COLOR], "{\\c}");

    strcpy(stack[0].param[PARAM_FACE],  "{\\fn}");



    if (x1 >= 0 && y1 >= 0) {

        if (x2 >= 0 && y2 >= 0 && (x2 != x1 || y2 != y1))

            out += snprintf(out, out_end-out,

                            "{\\an1}{\\move(%d,%d,%d,%d)}", x1, y1, x2, y2);

        else

            out += snprintf(out, out_end-out, "{\\an1}{\\pos(%d,%d)}", x1, y1);

    }



    for (; out < out_end && !end && *in; in++) {

        switch (*in) {

        case '\r':

            break;

        case '\n':

            if (line_start) {

                end = 1;

                break;

            }

            while (out[-1] == ' ')

                out--;

            out += snprintf(out, out_end-out, "\\N");

            line_start = 1;

            break;

        case ' ':

            if (!line_start)

                *out++ = *in;

            break;

        case '{':    



            an += sscanf(in, "{\\an%*1u}%c", &c) == 1;

            if ((an != 1 && sscanf(in, "{\\%*[^}]}%n%c", &len, &c) > 0) ||

                sscanf(in, "{%*1[CcFfoPSsYy]:%*[^}]}%n%c", &len, &c) > 0) {

                in += len - 1;

            } else

                *out++ = *in;

            break;

        case '<':

            tag_close = in[1] == '/';

            if (sscanf(in+tag_close+1, "%127[^>]>%n%c", buffer, &len,&c) >= 2) {

                if ((param = strchr(buffer, ' ')))

                    *param++ = 0;

                if ((!tag_close && sptr < FF_ARRAY_ELEMS(stack)) ||

                    ( tag_close && sptr > 0 && !strcmp(stack[sptr-1].tag, buffer))) {

                    int i, j, unknown = 0;

                    in += len + tag_close;

                    if (!tag_close)

                        memset(stack+sptr, 0, sizeof(*stack));

                    if (!strcmp(buffer, "font")) {

                        if (tag_close) {

                            for (i=PARAM_NUMBER-1; i>=0; i--)

                                if (stack[sptr-1].param[i][0])

                                    for (j=sptr-2; j>=0; j--)

                                        if (stack[j].param[i][0]) {

                                            out += snprintf(out, out_end-out,

                                                            stack[j].param[i]);

                                            break;

                                        }

                        } else {

                            while (param) {

                                if (!strncmp(param, "size=", 5)) {

                                    unsigned font_size;

                                    param += 5 + (param[5] == '"');

                                    if (sscanf(param, "%u", &font_size) == 1) {

                                        snprintf(stack[sptr].param[PARAM_SIZE],

                                             sizeof(stack[0].param[PARAM_SIZE]),

                                             "{\\fs%u}", font_size);

                                    }

                                } else if (!strncmp(param, "color=", 6)) {

                                    param += 6 + (param[6] == '"');

                                    snprintf(stack[sptr].param[PARAM_COLOR],

                                         sizeof(stack[0].param[PARAM_COLOR]),

                                         "{\\c&H%X&}",

                                         html_color_parse(avctx, param));

                                } else if (!strncmp(param, "face=", 5)) {

                                    param += 5 + (param[5] == '"');

                                    len = strcspn(param,

                                                  param[-1] == '"' ? "\"" :" ");

                                    av_strlcpy(tmp, param,

                                               FFMIN(sizeof(tmp), len+1));

                                    param += len;

                                    snprintf(stack[sptr].param[PARAM_FACE],

                                             sizeof(stack[0].param[PARAM_FACE]),

                                             "{\\fn%s}", tmp);

                                }

                                if ((param = strchr(param, ' ')))

                                    param++;

                            }

                            for (i=0; i<PARAM_NUMBER; i++)

                                if (stack[sptr].param[i][0])

                                    out += snprintf(out, out_end-out,

                                                    stack[sptr].param[i]);

                        }

                    } else if (!buffer[1] && strspn(buffer, "bisu") == 1) {

                        out += snprintf(out, out_end-out,

                                        "{\\%c%d}", buffer[0], !tag_close);

                    } else {

                        unknown = 1;

                        snprintf(tmp, sizeof(tmp), "</%s>", buffer);

                    }

                    if (tag_close) {

                        sptr--;

                    } else if (unknown && !strstr(in, tmp)) {

                        in -= len + tag_close;

                        *out++ = *in;

                    } else

                        av_strlcpy(stack[sptr++].tag, buffer,

                                   sizeof(stack[0].tag));

                    break;

                }

            }

        default:

            *out++ = *in;

            break;

        }

        if (*in != ' ' && *in != '\r' && *in != '\n')

            line_start = 0;

    }



    out = FFMIN(out, out_end-3);

    while (!strncmp(out-2, "\\N", 2))

        out -= 2;

    while (out[-1] == ' ')

        out--;

    out += snprintf(out, out_end-out, "\r\n");

    return in;

}

                                                            stack[j].param[i]);                                                     stack[sptr].param[i]);
static const char *FUNC_0(AVCodecContext *VAR_0, char *VAR_1, char *VAR_2,

                              const char *VAR_3, int VAR_4, int VAR_5, int VAR_6, int VAR_7)

{

    char VAR_8, *VAR_9, VAR_10[128], VAR_11[128];

    int VAR_12, VAR_13, VAR_14 = 1, VAR_15 = 1, VAR_16 = 0, VAR_17 = 0;

    SrtStack stack[16];



    stack[0].tag[0] = 0;

    strcpy(stack[0].VAR_9[PARAM_SIZE],  "{\\fs}");

    strcpy(stack[0].VAR_9[PARAM_COLOR], "{\\VAR_8}");

    strcpy(stack[0].VAR_9[PARAM_FACE],  "{\\fn}");



    if (VAR_4 >= 0 && VAR_5 >= 0) {

        if (VAR_6 >= 0 && VAR_7 >= 0 && (VAR_6 != VAR_4 || VAR_7 != VAR_5))

            VAR_1 += snprintf(VAR_1, VAR_2-VAR_1,

                            "{\\an1}{\\move(%d,%d,%d,%d)}", VAR_4, VAR_5, VAR_6, VAR_7);

        else

            VAR_1 += snprintf(VAR_1, VAR_2-VAR_1, "{\\an1}{\\pos(%d,%d)}", VAR_4, VAR_5);

    }



    for (; VAR_1 < VAR_2 && !VAR_17 && *VAR_3; VAR_3++) {

        switch (*VAR_3) {

        case '\r':

            break;

        case '\n':

            if (VAR_15) {

                VAR_17 = 1;

                break;

            }

            while (VAR_1[-1] == ' ')

                VAR_1--;

            VAR_1 += snprintf(VAR_1, VAR_2-VAR_1, "\\N");

            VAR_15 = 1;

            break;

        case ' ':

            if (!VAR_15)

                *VAR_1++ = *VAR_3;

            break;

        case '{':    



            VAR_16 += sscanf(VAR_3, "{\\VAR_16%*1u}%VAR_8", &VAR_8) == 1;

            if ((VAR_16 != 1 && sscanf(VAR_3, "{\\%*[^}]}%n%VAR_8", &VAR_12, &VAR_8) > 0) ||

                sscanf(VAR_3, "{%*1[CcFfoPSsYy]:%*[^}]}%n%VAR_8", &VAR_12, &VAR_8) > 0) {

                VAR_3 += VAR_12 - 1;

            } else

                *VAR_1++ = *VAR_3;

            break;

        case '<':

            VAR_13 = VAR_3[1] == '/';

            if (sscanf(VAR_3+VAR_13+1, "%127[^>]>%n%VAR_8", VAR_10, &VAR_12,&VAR_8) >= 2) {

                if ((VAR_9 = strchr(VAR_10, ' ')))

                    *VAR_9++ = 0;

                if ((!VAR_13 && VAR_14 < FF_ARRAY_ELEMS(stack)) ||

                    ( VAR_13 && VAR_14 > 0 && !strcmp(stack[VAR_14-1].tag, VAR_10))) {

                    int VAR_18, VAR_19, VAR_20 = 0;

                    VAR_3 += VAR_12 + VAR_13;

                    if (!VAR_13)

                        memset(stack+VAR_14, 0, sizeof(*stack));

                    if (!strcmp(VAR_10, "font")) {

                        if (VAR_13) {

                            for (VAR_18=PARAM_NUMBER-1; VAR_18>=0; VAR_18--)

                                if (stack[VAR_14-1].VAR_9[VAR_18][0])

                                    for (VAR_19=VAR_14-2; VAR_19>=0; VAR_19--)

                                        if (stack[VAR_19].VAR_9[VAR_18][0]) {

                                            VAR_1 += snprintf(VAR_1, VAR_2-VAR_1,

                                                            stack[VAR_19].VAR_9[VAR_18]);

                                            break;

                                        }

                        } else {

                            while (VAR_9) {

                                if (!strncmp(VAR_9, "size=", 5)) {

                                    unsigned VAR_21;

                                    VAR_9 += 5 + (VAR_9[5] == '"');

                                    if (sscanf(VAR_9, "%u", &VAR_21) == 1) {

                                        snprintf(stack[VAR_14].VAR_9[PARAM_SIZE],

                                             sizeof(stack[0].VAR_9[PARAM_SIZE]),

                                             "{\\fs%u}", VAR_21);

                                    }

                                } else if (!strncmp(VAR_9, "color=", 6)) {

                                    VAR_9 += 6 + (VAR_9[6] == '"');

                                    snprintf(stack[VAR_14].VAR_9[PARAM_COLOR],

                                         sizeof(stack[0].VAR_9[PARAM_COLOR]),

                                         "{\\VAR_8&H%X&}",

                                         html_color_parse(VAR_0, VAR_9));

                                } else if (!strncmp(VAR_9, "face=", 5)) {

                                    VAR_9 += 5 + (VAR_9[5] == '"');

                                    VAR_12 = strcspn(VAR_9,

                                                  VAR_9[-1] == '"' ? "\"" :" ");

                                    av_strlcpy(VAR_11, VAR_9,

                                               FFMIN(sizeof(VAR_11), VAR_12+1));

                                    VAR_9 += VAR_12;

                                    snprintf(stack[VAR_14].VAR_9[PARAM_FACE],

                                             sizeof(stack[0].VAR_9[PARAM_FACE]),

                                             "{\\fn%s}", VAR_11);

                                }

                                if ((VAR_9 = strchr(VAR_9, ' ')))

                                    VAR_9++;

                            }

                            for (VAR_18=0; VAR_18<PARAM_NUMBER; VAR_18++)

                                if (stack[VAR_14].VAR_9[VAR_18][0])

                                    VAR_1 += snprintf(VAR_1, VAR_2-VAR_1,

                                                    stack[VAR_14].VAR_9[VAR_18]);

                        }

                    } else if (!VAR_10[1] && strspn(VAR_10, "bisu") == 1) {

                        VAR_1 += snprintf(VAR_1, VAR_2-VAR_1,

                                        "{\\%VAR_8%d}", VAR_10[0], !VAR_13);

                    } else {

                        VAR_20 = 1;

                        snprintf(VAR_11, sizeof(VAR_11), "</%s>", VAR_10);

                    }

                    if (VAR_13) {

                        VAR_14--;

                    } else if (VAR_20 && !strstr(VAR_3, VAR_11)) {

                        VAR_3 -= VAR_12 + VAR_13;

                        *VAR_1++ = *VAR_3;

                    } else

                        av_strlcpy(stack[VAR_14++].tag, VAR_10,

                                   sizeof(stack[0].tag));

                    break;

                }

            }

        default:

            *VAR_1++ = *VAR_3;

            break;

        }

        if (*VAR_3 != ' ' && *VAR_3 != '\r' && *VAR_3 != '\n')

            VAR_15 = 0;

    }



    VAR_1 = FFMIN(VAR_1, VAR_2-3);

    while (!strncmp(VAR_1-2, "\\N", 2))

        VAR_1 -= 2;

    while (VAR_1[-1] == ' ')

        VAR_1--;

    VAR_1 += snprintf(VAR_1, VAR_2-VAR_1, "\r\n");

    return VAR_3;

}

static const char *FUNC_0(AVCodecContext *VAR_0, char *VAR_1, char *VAR_2,
const char *VAR_3, int VAR_4, int VAR_5, int VAR_6, int VAR_7)
{ char VAR_8, *VAR_9, VAR_10[128], VAR_11[128]; int VAR_12, VAR_13, VAR_14 = 1, VAR_15 = 1, VAR_16 = 0, VAR_17 = 0; SrtStack stack[16]; stack[0].tag[0] = 0; strcpy(stack[0].VAR_9[PARAM_SIZE],  "{\\fs}"); strcpy(stack[0].VAR_9[PARAM_COLOR], "{\\VAR_8}"); strcpy(stack[0].VAR_9[PARAM_FACE],  "{\\fn}"); if (VAR_4 >= 0 && VAR_5 >= 0) { if (VAR_6 >= 0 && VAR_7 >= 0 && (VAR_6 != VAR_4 || VAR_7 != VAR_5))
VAR_1 += snprintf(VAR_1, VAR_2-VAR_1,
"{\\an1}{\\move(%d,%d,%d,%d)}", VAR_4, VAR_5, VAR_6, VAR_7); else
VAR_1 += snprintf(VAR_1, VAR_2-VAR_1, "{\\an1}{\\pos(%d,%d)}", VAR_4, VAR_5); } for (; VAR_1 < VAR_2 && !VAR_17 && *VAR_3; VAR_3++) { switch (*VAR_3) { case '\r':
break; case '\n':
if (VAR_15) { VAR_17 = 1; break; } while (VAR_1[-1] == ' ')
VAR_1--; VAR_1 += snprintf(VAR_1, VAR_2-VAR_1, "\\N"); VAR_15 = 1; break; case ' ':
if (!VAR_15)
*VAR_1++ = *VAR_3; break; case '{': VAR_16 += sscanf(VAR_3, "{\\VAR_16%*1u}%VAR_8", &VAR_8) == 1; if ((VAR_16 != 1 && sscanf(VAR_3, "{\\%*[^}]}%n%VAR_8", &VAR_12, &VAR_8) > 0) || sscanf(VAR_3, "{%*1[CcFfoPSsYy]:%*[^}]}%n%VAR_8", &VAR_12, &VAR_8) > 0) { VAR_3 += VAR_12 - 1; } else *VAR_1++ = *VAR_3; break; case '<':
VAR_13 = VAR_3[1] == '/'; if (sscanf(VAR_3+VAR_13+1, "%127[^>]>%n%VAR_8", VAR_10, &VAR_12,&VAR_8) >= 2) { if ((VAR_9 = strchr(VAR_10, ' ')))
*VAR_9++ = 0; if ((!VAR_13 && VAR_14 < FF_ARRAY_ELEMS(stack)) ||
( VAR_13 && VAR_14 > 0 && !strcmp(stack[VAR_14-1].tag, VAR_10))) { int VAR_18, VAR_19, VAR_20 = 0; VAR_3 += VAR_12 + VAR_13; if (!VAR_13)
memset(stack+VAR_14, 0, sizeof(*stack)); if (!strcmp(VAR_10, "font")) { if (VAR_13) { for (VAR_18=PARAM_NUMBER-1; VAR_18>=0; VAR_18--) if (stack[VAR_14-1].VAR_9[VAR_18][0])
for (VAR_19=VAR_14-2; VAR_19>=0; VAR_19--) if (stack[VAR_19].VAR_9[VAR_18][0]) { VAR_1 += snprintf(VAR_1, VAR_2-VAR_1,
stack[VAR_19].VAR_9[VAR_18]); break; } } else { while (VAR_9) { if (!strncmp(VAR_9, "size=", 5)) { unsigned VAR_21; VAR_9 += 5 + (VAR_9[5] == '"'); if (sscanf(VAR_9, "%u", &VAR_21) == 1) { snprintf(stack[VAR_14].VAR_9[PARAM_SIZE],
sizeof(stack[0].VAR_9[PARAM_SIZE]),
"{\\fs%u}", VAR_21); } } else if (!strncmp(VAR_9, "color=", 6)) { VAR_9 += 6 + (VAR_9[6] == '"'); snprintf(stack[VAR_14].VAR_9[PARAM_COLOR],
sizeof(stack[0].VAR_9[PARAM_COLOR]),
"{\\VAR_8&H%X&}", html_color_parse(VAR_0, VAR_9)); } else if (!strncmp(VAR_9, "face=", 5)) { VAR_9 += 5 + (VAR_9[5] == '"'); VAR_12 = strcspn(VAR_9,
VAR_9[-1] == '"' ? "\"" :" "); av_strlcpy(VAR_11, VAR_9,
FFMIN(sizeof(VAR_11), VAR_12+1)); VAR_9 += VAR_12; snprintf(stack[VAR_14].VAR_9[PARAM_FACE],
sizeof(stack[0].VAR_9[PARAM_FACE]),
"{\\fn%s}", VAR_11); } if ((VAR_9 = strchr(VAR_9, ' ')))
VAR_9++; } for (VAR_18=0; VAR_18<PARAM_NUMBER; VAR_18++) if (stack[VAR_14].VAR_9[VAR_18][0])
VAR_1 += snprintf(VAR_1, VAR_2-VAR_1,
stack[VAR_14].VAR_9[VAR_18]); } } else if (!VAR_10[1] && strspn(VAR_10, "bisu") == 1) { VAR_1 += snprintf(VAR_1, VAR_2-VAR_1,
"{\\%VAR_8%d}", VAR_10[0], !VAR_13); } else { VAR_20 = 1; snprintf(VAR_11, sizeof(VAR_11), "</%s>", VAR_10); } if (VAR_13) { VAR_14--; } else if (VAR_20 && !strstr(VAR_3, VAR_11)) { VAR_3 -= VAR_12 + VAR_13; *VAR_1++ = *VAR_3; } else av_strlcpy(stack[VAR_14++].tag, VAR_10,
sizeof(stack[0].tag)); break; } } default:
*VAR_1++ = *VAR_3; break; } if (*VAR_3 != ' ' && *VAR_3 != '\r' && *VAR_3 != '\n')
VAR_15 = 0; } VAR_1 = FFMIN(VAR_1, VAR_2-3); while (!strncmp(VAR_1-2, "\\N", 2))
VAR_1 -= 2; while (VAR_1[-1] == ' ')
VAR_1--; VAR_1 += snprintf(VAR_1, VAR_2-VAR_1, "\r\n"); return VAR_3; }