ftepp.cpp
/* need to leave the last token up */
need to leave the last token up
need to leave the last token up
static bool ftepp_macro_call_params(ftepp_t *ftepp, macroparam **out_params)
{
    macroparam *params = nullptr;
    pptoken    *ptok;
    macroparam  mp;
    size_t      parens = 0;
    size_t      i;
    if (!ftepp_skipallwhite(ftepp))
        return false;
    while (ftepp->token != ')') {
        mp.tokens = nullptr;
        if (!ftepp_skipallwhite(ftepp))
            return false;
        while (parens || ftepp->token != ',') {
            if (ftepp->token == '(')
                ++parens;
            else if (ftepp->token == ')') {
                if (!parens)
                    break;
                --parens;
            }
            ptok = pptoken_make(ftepp);
            vec_push(mp.tokens, ptok);
            if (ftepp_next(ftepp) >= TOKEN_EOF) {
                ftepp_error(ftepp, "unexpected end of file in macro call");
                goto on_error;
            }
        }
        vec_push(params, mp);
        mp.tokens = nullptr;
        if (ftepp->token == ')')
            break;
        if (ftepp->token != ',') {
            ftepp_error(ftepp, "expected closing paren or comma in macro call");
            goto on_error;
        }
        if (ftepp_next(ftepp) >= TOKEN_EOF) {
            ftepp_error(ftepp, "unexpected end of file in macro call");
            goto on_error;
        }
    }
    *out_params = params;
    return true;
on_error:
    if (mp.tokens)
        macroparam_clean(&mp);
    for (i = 0; i < vec_size(params); ++i)
        macroparam_clean(&params[i]);
    vec_free(params);
    return false;
}
static bool ftepp_macro_call_params ( ftepp_t * ftepp , macroparam * * out_params ) { macroparam * params = nullptr ; pptoken * ptok ; macroparam mp ; size_t parens = 0 ; size_t i ; if ( ! ftepp_skipallwhite ( ftepp ) ) return false ; while ( ftepp -> token != ' ' ) { mp . tokens = nullptr ; if ( ! ftepp_skipallwhite ( ftepp ) ) return false ; while ( parens || ftepp -> token != ' ' ) { if ( ftepp -> token == ' ' ) ++ parens ; else if ( ftepp -> token == ' ' ) { if ( ! parens ) break ; -- parens ; } ptok = pptoken_make ( ftepp ) ; vec_push ( mp . tokens , ptok ) ; if ( ftepp_next ( ftepp ) >= TOKEN_EOF ) { ftepp_error ( ftepp , " " ) ; goto on_error ; } } vec_push ( params , mp ) ; mp . tokens = nullptr ; if ( ftepp -> token == ' ' ) break ; if ( ftepp -> token != ' ' ) { ftepp_error ( ftepp , " " ) ; goto on_error ; } if ( ftepp_next ( ftepp ) >= TOKEN_EOF ) { ftepp_error ( ftepp , " " ) ; goto on_error ; } } * out_params = params ; return true ; on_error : if ( mp . tokens ) macroparam_clean ( & mp ) ; for ( i = 0 ; i < vec_size ( params ) ; ++ i ) macroparam_clean ( & params [ i ] ) ; vec_free ( params ) ; return false ; }
need to leave the last token up
need to leave the last token up