Esempio n. 1
0
void PP_Define( const char *ptr )
{
    MACRO_ENTRY *me;
    const char  *macro_name;
    char        *p;
    const char  *p2;
    size_t      len;
    size_t      len1;
    bool        white_space;
    ppt_token   token;

    macro_name = PP_SkipWhiteSpace( ptr, &white_space );
    ptr = PP_ScanName( macro_name );
    me = PP_AddMacro( macro_name, ptr - macro_name );
    if( me != NULL ) {
        p = NULL;
        me->parmcount = 0;
        len = 0;
        if( *ptr == '(' ) {
            me->parmcount = 1;
            ptr++;
            for( ;; ) {
                ptr = PP_SkipWhiteSpace( ptr, &white_space );
                if( *ptr == '\0' || *ptr == ')' )
                    break;
                macro_name = ptr;
                ptr = PP_ScanName( macro_name );
                len1 = ptr - macro_name;
                p = resize_macro_buf( p, len + len1 );
                memcpy( p + len, macro_name, len1 );
                len += len1;
                me->parmcount++;
                ptr = PP_SkipWhiteSpace( ptr, &white_space );
                if( *ptr != ',' )
                    break;
                ++ptr;
                p = resize_macro_buf( p, len + 1 );
                p[len++] = '\0';                        // mark end of parm
            }
            if( *ptr == ')' ) {
                ++ptr;
                if( me->parmcount != 1 ) {
                    p = resize_macro_buf( p, len + 1 );
                    p[len++] = '\0';                    // mark end of macro parms
                }
            }
        }
        ptr = PP_SkipWhiteSpace( ptr, &white_space );
        for( ; *ptr != '\0' && *ptr != '\n'; ) {
            p2 = PP_ScanToken( ptr, &token );
            len1 = p2 - ptr;
            p = resize_macro_buf( p, len + len1 );
            memcpy( p + len, ptr, len1 );
            len += len1;
            ptr = PP_SkipWhiteSpace( p2, &white_space );
            if( *ptr == '\0' || *ptr == '\n' )
                break;
            if( white_space ) {
                p = resize_macro_buf( p, len + 1 );
                p[len++] = ' ';
            }
        }
        p = resize_macro_buf( p, len + 1 );
        p[len++] = '\0';
        me->replacement_list = PP_Malloc( len );
        memcpy( me->replacement_list, p, len );
    } else {
        PP_OutOfMemory();
    }
}
Esempio n. 2
0
void PP_Define( char *ptr )
{
    MACRO_ENTRY *me;
    char        *macro_name;
    char        *rep_list;
    char        *p;
    char        *p2;
    size_t      len;
    char        c;
    char        white_space;
    char        token;

    macro_name = PP_SkipWhiteSpace( ptr, &white_space );
    ptr = PP_ScanName( macro_name );
    c = *ptr;
    *ptr = '\0';
    me = PP_AddMacro( macro_name );
    if( me != NULL ) {
        me->parmcount = 0;
        *ptr = c;
        rep_list = ptr;
        p = rep_list;
        if( c == '(' ) {
            me->parmcount = 1;
            ptr++;
            for( ;; ) {
                ptr = PP_SkipWhiteSpace( ptr, &white_space );
                if( *ptr == '\0' ) break;
                if( *ptr == ')'  ) break;
                while( PP_Class( *ptr ) != 0 ) {        // collect name
                    *p++ = *ptr++;
                }
                me->parmcount++;
                ptr = PP_SkipWhiteSpace( ptr, &white_space );
                if( *ptr != ',' ) break;
                *p++ = '\0';            // mark end of parm
                ++ptr;
            }
            if( *ptr == ')' ) {
                ++ptr;
                if( me->parmcount != 1 ) {
                    *p++ = '\0';        // mark end of macro parms
                }
            }
        }
        ptr = PP_SkipWhiteSpace( ptr, &white_space );
        for( ;; ) {
            if( *ptr == '\0' ) break;
            if( *ptr == '\n' ) break;
            p2 = PP_ScanToken( ptr, &token );
            while( ptr != p2 )
                *p++ = *ptr++;
            ptr = PP_SkipWhiteSpace( ptr, &white_space );
            if( *ptr == '\0' ) break;
            if( *ptr == '\n' ) break;
            if( white_space )  *p++ = ' ';
        }
        *p++ = '\0';
        if( *rep_list != '\0' ) {
            len = p - rep_list;
            me->replacement_list = PP_Malloc( len );
            memcpy( me->replacement_list, rep_list, len );
        }
    } else {
        PP_OutOfMemory();
    }
}