示例#1
0
static FILE *PP_Open( const char *filename )
{
    FILE        *handle;
    FILELIST    *prev_file;
    size_t      len;

    handle = fopen( filename, "rb" );
    if( handle != NULL ) {
        prev_file = PP_File;
        PP_File = (FILELIST *)PP_Malloc( sizeof( FILELIST ) );
        if( PP_File == NULL ) {
            PP_OutOfMemory();
            fclose( handle );
            handle = NULL;
            PP_File = prev_file;
        } else {
            PP_File->prev_file = prev_file;
            PP_File->handle    = handle;
            PP_File->prev_bufptr  = PPBufPtr;
            len = strlen( filename ) + 1;
            PP_File->filename  = PP_Malloc( len );
            memcpy( PP_File->filename, filename, len );
            PP_File->linenum   = 1;
            PPBufPtr = PP_File->buffer;
            *PPBufPtr = '\0';                   // indicate buffer empty
        }
    }
    return( handle );
}
示例#2
0
int PP_Open( const char *filename )
{
    int         handle;
    FILELIST    *prev_file;

    handle = open( filename, O_RDONLY | O_BINARY );
    if( handle != -1 ) {
        prev_file = PP_File;
        PP_File = (FILELIST *)PP_Malloc( sizeof( FILELIST ) );
        if( PP_File == NULL ) {
            PP_OutOfMemory();
            close( handle );
            handle = -1;
            PP_File = prev_file;
        } else {
            PP_File->prev_file = prev_file;
            PP_File->handle    = handle;
            PP_File->prev_bufptr  = PPBufPtr;
            PP_File->filename  = doStrDup( filename );
            PP_File->linenum   = 1;
            PPBufPtr = PP_File->buffer;
            *PPBufPtr = '\0';                   // indicate buffer empty
        }
    }
    return( handle );
}
示例#3
0
void *PP_Malloc( size_t size )
{
    void        *p;

    p = WRMemAlloc( size );
    if( p == NULL ) {
        PP_OutOfMemory();
    }
    return( p );
}
示例#4
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();
    }
}
示例#5
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();
    }
}