Ejemplo n.º 1
0
FILE *PP_Open( const char *filename )
{
    FILE        *handle;
    FILELIST    *prev_file;

    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;
            PP_File->filename  = doStrDup( filename );
            PP_File->linenum   = 1;
            PPBufPtr = PP_File->buffer;
            *PPBufPtr = '\0';                   // indicate buffer empty
        }
    }
    return( handle );
}
Ejemplo n.º 2
0
void PP_Include( char *ptr )
{
    char        *filename;
    char        delim;
    int         incl_type;

    while( *ptr == ' '  ||  *ptr == '\t' ) ++ptr;
    filename = ptr+1;
    if( *ptr == '<' ) {
        delim = '>';
        incl_type = PPINCLUDE_SYS;
    } else if( *ptr == '"' ) {
        delim = '"';
        incl_type = PPINCLUDE_USR;
    } else {
        PP_GenError( "Unrecognized INCLUDE directive" );
        return;
    }
    ++ptr;
    while( *ptr != delim  &&  *ptr != '\0' )
        ++ptr;
    *ptr = '\0';
    if( PP_OpenInclude( filename, incl_type ) == NULL ) {
        filename = doStrDup( filename );        // want to reuse buffer
        PPCharPtr = &PPLineBuf[1];
        sprintf( PPCharPtr, "%cerror Unable to open '%s'\n", PreProcChar, filename );
        PP_Free( filename );
    } else {
        PP_GenLine();
    }
}
Ejemplo n.º 3
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 );
}
Ejemplo n.º 4
0
void PP_RCInclude( char *ptr )
{
    char        *filename;
    int         quoted = 0;

    while( *ptr == ' '  ||  *ptr == '\t' ) ++ptr;
    if( *ptr == '\"' ) {
        ptr++;
        quoted = 1;
    }

    filename = ptr;
    ++ptr;
    if( quoted ) {
        while( *ptr != '\"' ) {
            ptr++;
        }
    } else {
        for( ;; ) {
            if( *ptr == ' ' ) break;
            if( *ptr == '\t' ) break;
            if( *ptr == '\r' ) break;
            if( *ptr == '\n' ) break;
            if( *ptr == '\0' ) break;
            if( *ptr == '\"' ) break;
            ++ptr;
        }
    }
    *ptr = '\0';
    if( PP_OpenInclude( filename, PPINCLUDE_USR ) == NULL ) {
        filename = doStrDup( filename );        // want to reuse buffer
        PPCharPtr = &PPLineBuf[1];
        sprintf( PPCharPtr, "%cerror Unable to open '%s'\n", PreProcChar, filename );
        PP_Free( filename );
    } else {
        PP_GenLine();
    }
}