int get_frame_filename(char *buf, int buf_size,

                       const char *path, int number)

{

    const char *p;

    char *q, buf1[20];

    int nd, len, c, percentd_found;



    q = buf;

    p = path;

    percentd_found = 0;

    for(;;) {

        c = *p++;

        if (c == '\0')

            break;

        if (c == '%') {

            do {

                nd = 0;

                while (isdigit(*p)) {

                    nd = nd * 10 + *p++ - '0';

                }

                c = *p++;

                if (c == '*' && nd > 0) {

                    // The nd field is actually the modulus

                    number = number % nd;

                    c = *p++;

                    nd = 0;

                }

            } while (isdigit(c));



            switch(c) {

            case '%':

                goto addchar;

            case 'd':

                if (percentd_found)

                    goto fail;

                percentd_found = 1;

                snprintf(buf1, sizeof(buf1), "%0*d", nd, number);

                len = strlen(buf1);

                if ((q - buf + len) > buf_size - 1)

                    goto fail;

                memcpy(q, buf1, len);

                q += len;

                break;

            default:

                goto fail;

            }

        } else {

        addchar:

            if ((q - buf) < buf_size - 1)

                *q++ = c;

        }

    }

    if (!percentd_found)

        goto fail;

    *q = '\0';

    return 0;

 fail:

    *q = '\0';

    return -1;

}

int get_frame_filename(char *buf, int buf_size,

                       const char *path, int number)

{

    const char *p;

    char *q, buf1[20];

    int nd, len, c, percentd_found;



    q = buf;

    p = path;

    percentd_found = 0;

    for(;;) {

        c = *p++;

        if (c == '\0')

            break;

        if (c == '%') {

            do {

                nd = 0;

                while (isdigit(*p)) {

                    nd = nd * 10 + *p++ - '0';

                }

                c = *p++;

                if (c == '*' && nd > 0) {

                    

                    number = number % nd;

                    c = *p++;

                    nd = 0;

                }

            } while (isdigit(c));



            switch(c) {

            case '%':

                goto addchar;

            case 'd':

                if (percentd_found)

                    goto fail;

                percentd_found = 1;

                snprintf(buf1, sizeof(buf1), "%0*d", nd, number);

                len = strlen(buf1);

                if ((q - buf + len) > buf_size - 1)

                    goto fail;

                memcpy(q, buf1, len);

                q += len;

                break;

            default:

                goto fail;

            }

        } else {

        addchar:

            if ((q - buf) < buf_size - 1)

                *q++ = c;

        }

    }

    if (!percentd_found)

        goto fail;

    *q = '\0';

    return 0;

 fail:

    *q = '\0';

    return -1;

}

int FUNC_0(char *VAR_0, int VAR_1,

                       const char *VAR_2, int VAR_3)

{

    const char *VAR_4;

    char *VAR_5, VAR_6[20];

    int VAR_7, VAR_8, VAR_9, VAR_10;



    VAR_5 = VAR_0;

    VAR_4 = VAR_2;

    VAR_10 = 0;

    for(;;) {

        VAR_9 = *VAR_4++;

        if (VAR_9 == '\0')

            break;

        if (VAR_9 == '%') {

            do {

                VAR_7 = 0;

                while (isdigit(*VAR_4)) {

                    VAR_7 = VAR_7 * 10 + *VAR_4++ - '0';

                }

                VAR_9 = *VAR_4++;

                if (VAR_9 == '*' && VAR_7 > 0) {

                    

                    VAR_3 = VAR_3 % VAR_7;

                    VAR_9 = *VAR_4++;

                    VAR_7 = 0;

                }

            } while (isdigit(VAR_9));



            switch(VAR_9) {

            case '%':

                goto addchar;

            case 'd':

                if (VAR_10)

                    goto fail;

                VAR_10 = 1;

                snprintf(VAR_6, sizeof(VAR_6), "%0*d", VAR_7, VAR_3);

                VAR_8 = strlen(VAR_6);

                if ((VAR_5 - VAR_0 + VAR_8) > VAR_1 - 1)

                    goto fail;

                memcpy(VAR_5, VAR_6, VAR_8);

                VAR_5 += VAR_8;

                break;

            default:

                goto fail;

            }

        } else {

        addchar:

            if ((VAR_5 - VAR_0) < VAR_1 - 1)

                *VAR_5++ = VAR_9;

        }

    }

    if (!VAR_10)

        goto fail;

    *VAR_5 = '\0';

    return 0;

 fail:

    *VAR_5 = '\0';

    return -1;

}

int FUNC_0(char *VAR_0, int VAR_1,
const char *VAR_2, int VAR_3)
{ const char *VAR_4; char *VAR_5, VAR_6[20]; int VAR_7, VAR_8, VAR_9, VAR_10; VAR_5 = VAR_0; VAR_4 = VAR_2; VAR_10 = 0; for(;;) { VAR_9 = *VAR_4++; if (VAR_9 == '\0')
break; if (VAR_9 == '%') { do { VAR_7 = 0; while (isdigit(*VAR_4)) { VAR_7 = VAR_7 * 10 + *VAR_4++ - '0'; } VAR_9 = *VAR_4++; if (VAR_9 == '*' && VAR_7 > 0) { VAR_3 = VAR_3 % VAR_7; VAR_9 = *VAR_4++; VAR_7 = 0; } } while (isdigit(VAR_9)); switch(VAR_9) { case '%':
goto addchar; case 'd':
if (VAR_10)
goto fail; VAR_10 = 1; snprintf(VAR_6, sizeof(VAR_6), "%0*d", VAR_7, VAR_3); VAR_8 = strlen(VAR_6); if ((VAR_5 - VAR_0 + VAR_8) > VAR_1 - 1)
goto fail; memcpy(VAR_5, VAR_6, VAR_8); VAR_5 += VAR_8; break; default:
goto fail; } } else { addchar:
if ((VAR_5 - VAR_0) < VAR_1 - 1)
*VAR_5++ = VAR_9; } } if (!VAR_10)
goto fail; *VAR_5 = '\0'; return 0; fail:
*VAR_5 = '\0'; return -1; }