void ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in)

{

    char *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}");



    for (; !end && *in; in++) {

        switch (*in) {

        case '\r':

            break;

        case '\n':

            if (line_start) {

                end = 1;

                break;

            }

            rstrip_spaces_buf(dst);

            av_bprintf(dst, "\\N");

            line_start = 1;

            break;

        case ' ':

            if (!line_start)

                av_bprint_chars(dst, *in, 1);

            break;

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

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

            len = 0;

            an += sscanf(in, "{\\an%*1u}%n", &len) >= 0 && len > 0;

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

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

                in += len - 1;

            } else

                av_bprint_chars(dst, *in, 1);

            break;

        case '<':

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

            len = 0;

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

                const char *tagname = buffer;

                while (*tagname == ' ')

                    tagname++;

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

                    *param++ = 0;

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

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

                    int i, j, unknown = 0;

                    in += len + tag_close;

                    if (!tag_close)

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

                    if (!strcmp(tagname, "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]) {

                                            av_bprintf(dst, "%s", 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(log_ctx, 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])

                                    av_bprintf(dst, "%s", stack[sptr].param[i]);

                        }

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

                        av_bprintf(dst, "{\\%c%d}", tagname[0], !tag_close);

                    } else {

                        unknown = 1;

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

                    }

                    if (tag_close) {

                        sptr--;

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

                        in -= len + tag_close;

                        av_bprint_chars(dst, *in, 1);

                    } else

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

                                   sizeof(stack[0].tag));

                    break;

                }

            }

        default:

            av_bprint_chars(dst, *in, 1);

            break;

        }

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

            line_start = 0;

    }



    while (dst->len >= 2 && !strncmp(&dst->str[dst->len - 2], "\\N", 2))

        dst->len -= 2;

    dst->str[dst->len] = 0;

    rstrip_spaces_buf(dst);

}

void ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in)

{

    char *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}");



    for (; !end && *in; in++) {

        switch (*in) {

        case '\r':

            break;

        case '\n':

            if (line_start) {

                end = 1;

                break;

            }

            rstrip_spaces_buf(dst);

            av_bprintf(dst, "\\N");

            line_start = 1;

            break;

        case ' ':

            if (!line_start)

                av_bprint_chars(dst, *in, 1);

            break;

        case '{':    



            len = 0;

            an += sscanf(in, "{\\an%*1u}%n", &len) >= 0 && len > 0;

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

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

                in += len - 1;

            } else

                av_bprint_chars(dst, *in, 1);

            break;

        case '<':

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

            len = 0;

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

                const char *tagname = buffer;

                while (*tagname == ' ')

                    tagname++;

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

                    *param++ = 0;

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

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

                    int i, j, unknown = 0;

                    in += len + tag_close;

                    if (!tag_close)

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

                    if (!strcmp(tagname, "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]) {

                                            av_bprintf(dst, "%s", 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(log_ctx, 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])

                                    av_bprintf(dst, "%s", stack[sptr].param[i]);

                        }

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

                        av_bprintf(dst, "{\\%c%d}", tagname[0], !tag_close);

                    } else {

                        unknown = 1;

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

                    }

                    if (tag_close) {

                        sptr--;

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

                        in -= len + tag_close;

                        av_bprint_chars(dst, *in, 1);

                    } else

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

                                   sizeof(stack[0].tag));

                    break;

                }

            }

        default:

            av_bprint_chars(dst, *in, 1);

            break;

        }

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

            line_start = 0;

    }



    while (dst->len >= 2 && !strncmp(&dst->str[dst->len - 2], "\\N", 2))

        dst->len -= 2;

    dst->str[dst->len] = 0;

    rstrip_spaces_buf(dst);

}

void ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in)
void FUNC_0(void *VAR_0, AVBPrint *VAR_1, const char *VAR_2)

{

    char *VAR_3, VAR_4[128], VAR_5[128];

    int VAR_6, VAR_7, VAR_8 = 1, VAR_9 = 1, VAR_10 = 0, VAR_11 = 0;

    SrtStack stack[16];



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

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

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

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



    for (; !VAR_11 && *VAR_2; VAR_2++) {

        switch (*VAR_2) {

        case '\r':

            break;

        case '\n':

            if (VAR_9) {

                VAR_11 = 1;

                break;

            }

            rstrip_spaces_buf(VAR_1);

            av_bprintf(VAR_1, "\\N");

            VAR_9 = 1;

            break;

        case ' ':

            if (!VAR_9)

                av_bprint_chars(VAR_1, *VAR_2, 1);

            break;

        case '{':    



            VAR_6 = 0;

            VAR_10 += sscanf(VAR_2, "{\\VAR_10%*1u}%n", &VAR_6) >= 0 && VAR_6 > 0;

            if ((VAR_10 != 1 && (VAR_6 = 0, sscanf(VAR_2, "{\\%*[^}]}%n", &VAR_6) >= 0 && VAR_6 > 0)) ||

                (VAR_6 = 0, sscanf(VAR_2, "{%*1[CcFfoPSsYy]:%*[^}]}%n", &VAR_6) >= 0 && VAR_6 > 0)) {

                VAR_2 += VAR_6 - 1;

            } else

                av_bprint_chars(VAR_1, *VAR_2, 1);

            break;

        case '<':

            VAR_7 = VAR_2[1] == '/';

            VAR_6 = 0;

            if (sscanf(VAR_2+VAR_7+1, "%127[^>]>%n", VAR_4, &VAR_6) >= 1 && VAR_6 > 0) {

                const char *VAR_12 = VAR_4;

                while (*VAR_12 == ' ')

                    VAR_12++;

                if ((VAR_3 = strchr(VAR_12, ' ')))

                    *VAR_3++ = 0;

                if ((!VAR_7 && VAR_8 < FF_ARRAY_ELEMS(stack)) ||

                    ( VAR_7 && VAR_8 > 0 && !strcmp(stack[VAR_8-1].tag, VAR_12))) {

                    int VAR_13, VAR_14, VAR_15 = 0;

                    VAR_2 += VAR_6 + VAR_7;

                    if (!VAR_7)

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

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

                        if (VAR_7) {

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

                                if (stack[VAR_8-1].VAR_3[VAR_13][0])

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

                                        if (stack[VAR_14].VAR_3[VAR_13][0]) {

                                            av_bprintf(VAR_1, "%s", stack[VAR_14].VAR_3[VAR_13]);

                                            break;

                                        }

                        } else {

                            while (VAR_3) {

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

                                    unsigned VAR_16;

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

                                    if (sscanf(VAR_3, "%u", &VAR_16) == 1) {

                                        snprintf(stack[VAR_8].VAR_3[PARAM_SIZE],

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

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

                                    }

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

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

                                    snprintf(stack[VAR_8].VAR_3[PARAM_COLOR],

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

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

                                         html_color_parse(VAR_0, VAR_3));

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

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

                                    VAR_6 = strcspn(VAR_3,

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

                                    av_strlcpy(VAR_5, VAR_3,

                                               FFMIN(sizeof(VAR_5), VAR_6+1));

                                    VAR_3 += VAR_6;

                                    snprintf(stack[VAR_8].VAR_3[PARAM_FACE],

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

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

                                }

                                if ((VAR_3 = strchr(VAR_3, ' ')))

                                    VAR_3++;

                            }

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

                                if (stack[VAR_8].VAR_3[VAR_13][0])

                                    av_bprintf(VAR_1, "%s", stack[VAR_8].VAR_3[VAR_13]);

                        }

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

                        av_bprintf(VAR_1, "{\\%c%d}", VAR_12[0], !VAR_7);

                    } else {

                        VAR_15 = 1;

                        snprintf(VAR_5, sizeof(VAR_5), "</%s>", VAR_12);

                    }

                    if (VAR_7) {

                        VAR_8--;

                    } else if (VAR_15 && !strstr(VAR_2, VAR_5)) {

                        VAR_2 -= VAR_6 + VAR_7;

                        av_bprint_chars(VAR_1, *VAR_2, 1);

                    } else

                        av_strlcpy(stack[VAR_8++].tag, VAR_12,

                                   sizeof(stack[0].tag));

                    break;

                }

            }

        default:

            av_bprint_chars(VAR_1, *VAR_2, 1);

            break;

        }

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

            VAR_9 = 0;

    }



    while (VAR_1->VAR_6 >= 2 && !strncmp(&VAR_1->str[VAR_1->VAR_6 - 2], "\\N", 2))

        VAR_1->VAR_6 -= 2;

    VAR_1->str[VAR_1->VAR_6] = 0;

    rstrip_spaces_buf(VAR_1);

}

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