Esempio n. 1
0
int main( int argc, char *argv[] )
{
    int         c;

    dumpheap();
    if( argc < 2 ) {
        printf( "Usage: testpp filename\n" );
        exit( 1 );
    }
    if( argv[2] != NULL ) {
        PreProcChar = argv[2][0];
    }
    if( PP_Init( argv[1], PPFLAG_EMIT_LINE, NULL ) != 0 ) {
        printf( "Unable to open '%s'\n", argv[1] );
        exit( 1 );
    }
    for( ;; ) {
        c = PP_Char();
        if( c == EOF )
            break;
        putchar( c );
    }
    dumpheap();
    PP_Fini();
    dumpheap();
    return( 0 );
}
Esempio n. 2
0
static int Pass1( void )
/**********************/
{
    int     noerror;

    noerror = RcPass1IoInit();
    if( noerror ) {
        if( !CmdLineParms.PreprocessOnly ) {
            SetDefLang();
            if( CmdLineParms.TargetOS == RC_TARGET_OS_OS2 ) {
                ParseInitOS2();
                ParseOS2();
            } else {
                ParseInit();
                Parse();
            }
            WriteDependencyRes();
        } else {
            CreatePreprocFile();
        }
        PP_Fini();
        RcPass1IoShutdown();
        noerror = !ErrorHasOccured;
    }

    return( noerror );
} /* Pass1 */
Esempio n. 3
0
extern void RcFatalError( unsigned int errornum, ... )
/****************************************************/
{
    va_list             arglist;

    va_start( arglist, errornum );
    errornum = checkForTmpFiles( errornum, arglist );
    va_end( arglist );

    va_start( arglist, errornum );
    RcMsgV( errornum, SEV_FATAL_ERR, arglist );
    va_end( arglist );

    if( IsTmpFile( CurrResFile.filename ) ) {
        ResCloseFile( CurrResFile.handle );
        remove( CurrResFile.filename );
        UnregisterTmpFile( CurrResFile.filename );
    }
    CloseAllFiles();
    PP_Fini();
#ifdef WR_COMPILED
    longjmp( RC_Dead_env, 1 );
#elif defined DLL_COMPILE
    longjmp( DLL_JumpPt, 1 );
#else
    exit( -1 );
#endif
}
Esempio n. 4
0
extern int RcPass1IoInit( void )
/******************************/
/* Open the two files for input and output. The input stream starts at the */
/* top   infilename   and continues as the directives in the file indicate */
/* Returns false if there is a problem opening one of the files. */
{
    int         error;
    char       *includepath = NULL;

    if( !CmdLineParms.IgnoreINCLUDE ) {
        if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN16 ) {
            includepath = RcGetEnv( "WINDOWS_INCLUDE" );
        } else if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN32 ) {
            includepath = RcGetEnv( "NT_INCLUDE" );
        } else if( CmdLineParms.TargetOS == RC_TARGET_OS_OS2 ) {
            includepath = RcGetEnv( "OS2_INCLUDE" );
        }
        if( includepath != NULL ) {
            PP_AddIncludePath( includepath );
        }
        includepath = RcGetEnv( "INCLUDE" );
        if( includepath != NULL ) {
            PP_AddIncludePath( includepath );
        }
    }
    if( !CmdLineParms.NoPreprocess ) {
        if( PreprocessInputFile() ) {
            return( FALSE );
        }
    }
    RcIoTextInputInit();
    error = RcIoPushInputFile( CmdLineParms.InFileName );
    if( error )
        return( FALSE );

    if( !CmdLineParms.PreprocessOnly ) {
        error = Pass1InitRes();
    }
    if( error )  {
        PP_Fini();
        RcIoTextInputShutdown();
        return( FALSE );
    }

    return( TRUE );
}
Esempio n. 5
0
int main( int argc, char *argv[] )
{
    if( argc < 2 ) {
        cprintf( "Usage: mkmk filename\r\n" );
        exit( 1 );
    }
    if( argv[2] != NULL ) {
        PreProcChar = argv[2][0];
    }
    if( PP_Init( argv[1], PPFLAG_DEPENDENCIES, NULL ) != 0 ) {
        cprintf( "Unable to open '%s'\r\n", argv[1] );
        exit( 1 );
    }
    // call PP_Define here to predefine any desired macros
    PP_Dependency_List( MkMkDependency );
    PP_Fini();
    return( 0 );
}
Esempio n. 6
0
extern void RcFatalError( unsigned int errornum, ... )
/****************************************************/
{
    va_list             arglist;

    va_start( arglist, errornum );
    errornum = checkForTmpFiles( errornum, arglist );
    va_end( arglist );

    va_start( arglist, errornum );
    RcMsgV( errornum, SEV_FATAL_ERR, arglist );
    va_end( arglist );

    if( IsTmpFile( CurrResFile.filename ) ) {
        ResCloseFile( CurrResFile.handle );
        remove( CurrResFile.filename );
        UnregisterTmpFile( CurrResFile.filename );
    }
#if !defined( WRDLL )
    CloseAllFiles();
#endif
    PP_Fini();
    RCSuicide( -1 );
}
Esempio n. 7
0
static char *WRELoadSymbols( WRHashTable **table, char *file_name, bool prompt )
{
    char                *name;
    int                 c;
    unsigned            flags;
    char                *inc_path;
    WREGetFileStruct    gf;
    unsigned            pp_count;
    unsigned            busy_count;
    char                busy_str[2];
    bool                ret;
    bool                ok;

    name = NULL;

    ok = (table != NULL);

    if( ok ) {
        WRESetStatusText( NULL, "", FALSE );
        WRESetStatusByID( WRE_LOADINGSYMBOLS, -1 );
    }

    if( ok ) {
        if( file_name == NULL || prompt ) {
            gf.file_name = file_name;
            gf.title = WRESymLoadTitle;
            gf.filter = WRESymSaveFilter;
            gf.save_ext = FALSE;
            name = WREGetOpenFileName( &gf );
        } else {
            name = WREStrDup( file_name );
        }
        ok = (name != NULL);
    }

    WRESetWaitCursor( TRUE );

    if( ok ) {
        flags = PPFLAG_IGNORE_INCLUDE | PPFLAG_EMIT_LINE;
        inc_path = NULL;
        ret = setjmp( SymEnv );
        if( ret ) {
            PP_Fini();
            WREDisplayErrorMsg( WRE_SYMOUTOFMEM );
            ok = false;
        }
    }

    if( ok ) {
        ok = !PP_Init( name, flags, inc_path );
        if( !ok ) {
            WREDisplayErrorMsg( WRE_NOLOADHEADERFILE );
        }
    }

    if( ok ) {
        pp_count = 0;
        busy_count = 0;
        busy_str[1] = '\0';
        do {
            pp_count++;
            c = PP_Char();
            if( pp_count == MAX_PP_CHARS ) {
                busy_count++;
                busy_str[0] = WREBusyChars[busy_count % 4];
                WRESetStatusText( NULL, busy_str, TRUE );
                pp_count = 0;
            }
        } while( c != EOF );
        if( *table == NULL ) {
            *table = WRInitHashTable();
        }
        WREAddSymbols( *table );
        WRMakeHashTableClean( *table );
        PP_Fini();
        WRESetStatusText( NULL, " ", TRUE );
    }

    if( !ok ) {
        if( name != NULL ) {
            WRMemFree( name );
            name = NULL;
        }
    }

    WRESetWaitCursor( FALSE );

    WRESetStatusReadyText();

    return( name );
}
Esempio n. 8
0
int main( int argc, char **argv )
//*******************************
{
    static char *fname;

#ifndef __WATCOMC__
    _argv = argv;
    _argc = argc;
#endif
    MemInit();
    if( !AsMsgInit() ) {
        return( EXIT_FAILURE );
    }
    if( argc == 1 ) {
        Banner();
        Usage();
    } else if( OptionsInit( --argc, ++argv ) ) {
        Banner();
        if( _IsOption( PRINT_HELP ) ) {
            Usage();
            *argv = NULL;
        } else if( !*argv ) {
            AsOutMessage( stderr, AS_MSG_ERROR );
            AsOutMessage( stderr, NO_FILENAME_SPECIFIED );
            fputc( '\n', stderr );
        }
        while( *argv ) {
            fname = MakeAsmFilename( *argv );
            if( PP_Init( fname, PPFLAG_ASM_COMMENT | PPFLAG_EMIT_LINE, NULL ) != 0 ) {
                AsOutMessage( stderr, UNABLE_TO_OPEN, fname );
                fputc( '\n', stderr );
            } else {
                OptionsPPDefine();
                SymInit();
                InsInit();
                DirInit();
                if( ObjInit( fname ) ) {
                    if( setjmp( AsmParse ) == 0 ) {
                        ErrorCountsReset();
                        DoReport = TRUE;
                        if( !yyparse() ) {
                            CurrLineno--;    // This is the total # of lines
                            ObjRelocsFini(); // Must be done before ErrorReport
                            // and other finis
                        } else {
                            DoReport = FALSE;
                        }
                    } else { // AbortParse() was invoked
                        DoReport = FALSE;
                    }
                    ErrorReport();
                    AsLexerFini();
                    ObjFini();
                }
                DirFini();
                InsFini();
                SymFini();
            }
            PP_Fini();
            ++argv;
        }
    }
    OptionsFini();
    AsMsgFini();
    MemFini();
    return( ExitStatus );
}
Esempio n. 9
0
char *WLoadSymbols( WRHashTable **table, char *file_name, HWND parent, bool prompt )
{
    char                *name;
    int                 c;
    unsigned            flags;
    char                *inc_path;
    WGetFileStruct      gf;
    bool                ret;
    bool                ok;

    name = NULL;

    ok = (table != NULL);

    if( ok ) {
        if( file_name == NULL || prompt ) {
            gf.file_name = file_name;
            gf.title = AllocRCString( W_LOADSYMTITLE );
            gf.filter = AllocRCString( W_SYMFILTER );
            WMassageFilter( gf.filter );
            name = WGetOpenFileName( parent, &gf );
            if( gf.title != NULL ) {
                FreeRCString( gf.title );
            }
            if( gf.filter != NULL ) {
                FreeRCString( gf.filter );
            }
        } else {
            name = WStrDup( file_name );
        }
        ok = (name != NULL);
    }

    WSetWaitCursor( parent, TRUE );

    if( ok ) {
        flags = PPFLAG_IGNORE_INCLUDE | PPFLAG_EMIT_LINE;
        inc_path = NULL;
        ret = setjmp( SymEnv ) != 0;
        if( ret ) {
            PP_Fini();
            WDisplayErrorMsg( W_SYMOUTOFMEM );
            ok = false;
        }
    }

    if( ok ) {
        ok = !PP_Init( name, flags, inc_path );
        if( !ok ) {
            WDisplayErrorMsg( W_NOOPENSYMFILE );
        }
    }

    if( ok ) {
        do {
            c = PP_Char();
        } while( c != EOF );
        if( *table == NULL ) {
            *table = WRInitHashTable();
        }
        addSymbols( *table );
        WRMakeHashTableClean( *table );
        PP_Fini();
    }

    if( !ok ) {
        if( name != NULL ) {
            WRMemFree( name );
            name = NULL;
        }
    }

    WSetWaitCursor( parent, FALSE );

    return( name );
}
Esempio n. 10
0
static bool scanEnvVarOrFile( const char *name )
/**********************************************/
{
    /*
     * Pass nofilenames and analysis of getenv(name) into argc and argv
     * to doScanParams. Return view on usability of data. (true is usable.)
     *
     * Recursion is supported but circularity is rejected.
     */
    typedef struct VarInfo {
        struct VarInfo      *next;
        char                *name;
        char                **argv; /* points into buf */
        char                buf[1]; /* dynamic array */
    } VarInfo;

    int                 argc;
    VarInfo             *info;
    static VarInfo      *stack = NULL;  // Needed to detect recursion.
    size_t              argvsize;
    size_t              argbufsize;
    const char          *optstring;
    size_t              varlen;         // size to hold name copy.
    bool                result;         // doScanParams Result.
    char                fbuf[512];

    optstring = PP_GetEnv( name );
    if( optstring == NULL ) {
        FILE *fh;

        fh = fopen( name, "rt" );
        if( fh == NULL ) {
//            RcWarning( ERR_ENV_VAR_NOT_FOUND, name );
            return( true );
        }
        fgets( fbuf, sizeof( fbuf ), fh );
        fclose( fh );
        optstring = fbuf;
    }
    // This used to cause stack overflow: set foo=@foo && wrc @foo.
    for( info = stack; info != NULL; info = info->next ) {
#if defined( __UNIX__ )
        if( strcmp( name, info->name ) == 0 ) {     // Case-sensitive
#else
        if( stricmp( name, info->name ) == 0 ) {    // Case-insensitive
#endif
//            RcFatalError( ERR_RCVARIABLE_RECURSIVE, name );
        }
    }
    argc = ParseVariable( optstring, NULL, NULL );  // count parameters.
    argbufsize = strlen( optstring ) + 1 + argc;    // inter-parameter spaces map to 0
    argvsize = argc * sizeof( char * );             // sizeof argv[argc+1]
    varlen = strlen( name ) + 1;                    // Copy taken to detect recursion.
    info = malloc( sizeof( *info ) + argbufsize + argvsize + varlen );
    info->next = stack;
    stack = info;                                   // push info on stack
    info->argv = (char **)info->buf;
    ParseVariable( optstring, info->argv, info->buf + argvsize );
    info->name = info->buf + argvsize + argbufsize;
    strcpy( info->name, name );
    result = doScanParams( argc, info->argv );

    stack = info->next;                             // pop stack
    free( info );
    return( result );
}

static bool doScanParams( int argc, char *argv[] )
/************************************************/
{
    const char  *arg;
    int         switchchar;
    bool        contok;         /* continue with main execution */
    int         currarg;

    contok = true;
    switchchar = _dos_switch_char();
    for( currarg = 0; currarg < argc && contok; currarg++ ) {
        arg = argv[currarg];
        if( *arg == switchchar || *arg == '-' ) {
            contok = ScanOptionsArg( arg + 1 ) && contok;
        } else if( *arg == '@' ) {
            contok = scanEnvVarOrFile( arg + 1 ) && contok;
        } else if( *arg == '?' ) {
            wcpp_quit( usageMsg, NULL );
//            contok = false;
        } else {
            filenames = realloc( (void *)filenames, ( nofilenames + 1 ) * sizeof( char * ) );
            filenames[nofilenames++] = my_strdup( arg );
        }
    }
    return( contok );
}

int main( int argc, char *argv[] )
{
    int         ch;
    int         i;
    int         j;
    int         rc;
    FILE        *fo;

    if( argc < 2 ) {
        wcpp_quit( usageMsg, "No filename specified\n" );
    } else if( argc == 2 ) {
        if( !strcmp( argv[1], "?" ) ) {
            wcpp_quit( usageMsg, NULL );
        }
    }

    PP_IncludePathInit();

    rc = EXIT_FAILURE;
    if( doScanParams( argc - 1, argv + 1 ) && nofilenames != 0 ) {
        PP_Init( '#' );
        fo = stdout;
        if( out_filename != NULL ) {
            fo = fopen( out_filename, "wb" );
        }
        rc = EXIT_SUCCESS;
        for( i = 0; i < nofilenames; ++i ) {
            if( PP_FileInit( filenames[i], flags, NULL ) != 0 ) {
                fprintf( stderr, "Unable to open '%s'\n", filenames[i] );
                rc = EXIT_FAILURE;
                break;
            }
            for( j = 0; j < numdefs; j++ ) {
                PP_Define( defines[j] );
            }
            for( ;; ) {
                ch = PP_Char();
                if( ch == EOF )
                    break;
#ifndef __UNIX__
                if( ch == '\n' )
                    fputc( '\r', fo );
#endif
                fputc( ch, fo );
            }
            PP_FileFini();
        }
        if( fo == stdout ) {
            fflush( fo );
        } else if( fo != NULL ) {
            fclose( fo );
        }
        PP_Fini();
    }

    if( out_filename != NULL ) {
        free( out_filename );
    }
    for( i = 0; i < nofilenames; ++i ) {
        free( filenames[i] );
    }
    free( (void *)filenames );
    for( i = 0; i < numdefs; i++ ) {
        free( defines[i] );
    }
    free( (void *)defines );

    PP_IncludePathFini();

    if( rc == EXIT_FAILURE && nofilenames == 0 ) {
        wcpp_quit( usageMsg, "No filename specified\n" );
    }

    return( rc );
}