Пример #1
0
int PP_Init2( const char *filename, unsigned flags, const char *include_path, const char *leadbytes )
{
    FILE        *handle;
    int         hash;

    for( hash = 0; hash < HASH_SIZE; hash++ ) {
        PPHashTable[hash] = NULL;
    }
    NestLevel = 0;
    SkipLevel = 0;
    PPFlags = flags;
    memset( MBCharLen, 0, 256 );
    if( leadbytes != NULL ) {
        PP_SetLeadBytes( leadbytes );
    } else if( flags & PPFLAG_DB_KANJI ) {
        SetRange( 0x81, 0x9f, 1 );
        SetRange( 0xe0, 0xfc, 1 );
    } else if( flags & PPFLAG_DB_CHINESE ) {
        SetRange( 0x81, 0xfc, 1 );
    } else if( flags & PPFLAG_DB_KOREAN ) {
        SetRange( 0x81, 0xfd, 1 );
    } else if( flags & PPFLAG_UTF8 ) {
        SetRange( 0xc0, 0xdf, 1 );
        SetRange( 0xe0, 0xef, 2 );
        SetRange( 0xf0, 0xf7, 3 );
        SetRange( 0xf8, 0xfb, 4 );
        SetRange( 0xfc, 0xfd, 5 );
    }
    IncludePath2 = PP_Malloc( 1 );
    *IncludePath2 = '\0';
    IncludePath2 = AddIncludePath( IncludePath2, include_path );
    if( (PPFlags & PPFLAG_IGNORE_INCLUDE) == 0 ) {
        IncludePath2 = AddIncludePath( IncludePath2, PP_GetEnv( "INCLUDE" ) );
    }
    PP_AddMacro( "__LINE__", 8 );
    PP_AddMacro( "__FILE__", 8 );
    PP_AddMacro( "__DATE__", 8 );
    PP_AddMacro( "__TIME__", 8 );
    PP_AddMacro( "__STDC__", 8 );
    PP_TimeInit();

    handle = PP_Open( filename );
    if( handle == NULL )
        return( -1 );
    PP_GenLine();
    PPSavedChar = '\0';
    PPTokenPtr = PPNextTokenPtr;
    return( 0 );
}
Пример #2
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();
    }
}
Пример #3
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();
    }
}