示例#1
0
int DoBdiff( const char *srcPath, const char *tgtPath, const char *name )
{
    long        savings;
    foff        buffsize;
    int         i;
//    if( !MsgInit() ) exit( EXIT_FAILURE );
    /* initialize static variables each time */
    SimilarRegions = NULL;
    DiffRegions = NULL;
    HoleRegions = NULL;
    SimilarSize = 0;
    NumHoles = 0;
    NumDiffs = 0;
    DiffSize = 0;
    HolesInRegion = 0;
    HoleHeaders = 0;
    for( i = 0; i < 3; i += 1 ) {
        HoleCount[i] = 0;
    }

    init_diff();

    newName = name;
    EndOld = FileSize( srcPath, &OldCorrection );
    EndNew = FileSize( tgtPath, &NewCorrection );

    buffsize = ( EndOld > EndNew ) ? ( EndOld ) : ( EndNew );
    buffsize += sizeof( PATCH_LEVEL );
    OldFile = ReadIn( srcPath, buffsize, EndOld );
    NewFile = ReadIn( tgtPath, buffsize, EndNew );

    ScanSyncString( SyncString );

    FindRegions();

    if( NumHoles == 0 && DiffSize == 0 && EndOld == EndNew ) {
        printf( "Patch file not created - files are identical\n" );
        MsgFini();
        exit( EXIT_SUCCESS );
    }
    MakeHoleArray();
    SortHoleArray();
    ProcessHoleArray( 0 );
    savings = HolesToDiffs();
    WritePatchFile( "", newName );
    FreeHoleArray();
    VerifyCorrect( tgtPath );

    print_stats( savings );

    MsgFini();
    return ( EXIT_SUCCESS );
}
示例#2
0
void fatal( void )
{
#if defined( __WINDOWS__ )
    WaitForFirst = FALSE;
    MessageLoop();
    CloseShop();
    MsgFini();
    exit( 0 );
#else
    MsgFini();
    _exit( 1 );
#endif
}
示例#3
0
void main( int argc, char **argv )
{
    long        savings;
    foff        buffsize;
    algorithm   alg;

    if( !MsgInit() )
        exit( EXIT_FAILURE );
    alg = ParseArgs( argc, argv );

    EndOld = FileSize( argv[1], &OldCorrection );
    EndNew = FileSize( argv[2], &NewCorrection );

    buffsize = ( EndOld > EndNew ) ? ( EndOld ) : ( EndNew );
    buffsize += sizeof( PATCH_LEVEL );
    OldFile = ReadIn( argv[1], buffsize, EndOld );
    NewFile = ReadIn( argv[2], buffsize, EndNew );

    ScanSyncString( SyncString );

    switch( alg ) {
    case ALG_NOTHING:
        FindRegions();
        break;
#ifdef USE_DBGINFO
    case ALG_ONLY_NEW:
    case ALG_BOTH:
        SymbolicDiff( alg, argv[1], argv[2] );
        break;
#endif
    }

    if( NumHoles == 0 && DiffSize == 0 && EndOld == EndNew ) {
        printf( "Patch file not created - files are identical\n" );
        MsgFini();
        exit( EXIT_SUCCESS );
    }
    MakeHoleArray();
    SortHoleArray();
    ProcessHoleArray( 0 );
    savings = HolesToDiffs();
    WritePatchFile( argv[3], newName );
    FreeHoleArray();
    VerifyCorrect( argv[2] );

    print_stats( savings );

    MsgFini();
    exit( EXIT_SUCCESS );
}
示例#4
0
int MsgInit( void )
{
#if !defined( USE_TEXT_MSGS )
    int         initerror;
    char        name[_MAX_PATH];

    hInstance.handle = NIL_HANDLE;
    if( _cmdname( name ) == NULL ) {
        initerror = 1;
    } else {
        hInstance.filename = name;
        OpenResFile( &hInstance );
        if( hInstance.handle == NIL_HANDLE ) {
            initerror = 1;
        } else {
            initerror = FindResources( &hInstance );
            if( !initerror ) {
                initerror = InitResources( &hInstance );
            }
        }
    }
    MsgShift = WResLanguage() * MSG_LANG_SPACING;
    if( !initerror && !MsgGet( MSG_USE_BASE, name ) ) {
        initerror = 1;
    }
    if( initerror ) {
        write( STDOUT_FILENO, NO_RES_MESSAGE, NO_RES_SIZE );
        MsgFini();
        return( 0 );
    }
#endif
    return( 1 );
}
示例#5
0
void PatchError( int format, ... )
{
    va_list     args;

    va_start( args, format );
    Err( format, args );
    printf( "\n" );
    va_end( args );
    MsgFini();
    exit( EXIT_FAILURE );
}
示例#6
0
void FilePatchError( int format, ... )
{
    va_list     args;
    int         err;

    va_start( args, format );
    err = errno;
    Err( format, args );
    printf( ": %s\n", strerror( err ) );
    va_end( args );
    MsgFini();
    exit( EXIT_FAILURE );
}
示例#7
0
int  main()
/*********/

{
    char                *cmd;
    void               (*parse_object)( void );

#if defined( _M_I86SM ) || defined( _M_I86MM )
    _heapgrow();    /* grow the near heap */
#endif
    if( !MsgInit() ) return( EXIT_FAILURE );
    cmd = AllocMem( CMD_LINE_SIZE );
    getcmd( cmd );
    InitOutput();
    initOptions();
    parseOptions( cmd );
    openFiles();
    InitObj();
    parse_object = InitORL() ? ParseObjectORL : ParseObjectOMF;
    for( ;; ) {
        InitTables();
        ModNameORL = rootName;
        parse_object();
        if( Mod == NULL ) {
            break;
        }
        if( srcReqd ) {
            if( SrcName == NULL ) {
                if( CommentName != NULL ) {
                    SrcName = CommentName;
                } else if( Mod->name != NULL ) {
                    SrcName = Mod->name;
                } else {
                    SrcName = rootName;
                }
            }
            OpenSource();
        }
        DisAssemble();
        if( Source != NULL ) {
            CloseTxt( Source );
        }
        SrcName = NULL;         /* if another module, get name from obj file */
    }
    if( UseORL ) FiniORL();
    CloseBin( ObjFile );
    CloseTxt( Output );
    MsgFini();
    return( 0 );
}
示例#8
0
void Fini( void )
{
    freeSectionList( &Sections );
    freeLabelList( 0 );
    ORLFileScan( ObjFileHnd, NULL, &SectionFini );
    if( Options & PRINT_PUBLICS ) {
        freePublics();
    }
    FreeHashTables();
    FreeServicesUsed();
    CloseFiles();
    MemPrtList();
    MemClose();
    MsgFini();
}
示例#9
0
void Usage( const char *name )
{
    char msgbuf[MAX_RESOURCE_SIZE];
    int i;

    i = MSG_USAGE_FIRST;
    GetMsg( msgbuf, i );
    printf( msgbuf, name );
    for( i = i + 1; i <= MSG_USAGE_LAST; i++ ) {
        GetMsg( msgbuf, i );
        if( msgbuf[0] == '\0' )
            break;
        puts( msgbuf );
    }
    MsgFini();
    exit( EXIT_FAILURE );
}
示例#10
0
int MsgInit( void )
{
    char        name[_MAX_PATH];

    hInstance.handle = NIL_HANDLE;
    if( _cmdname( name ) != NULL && !OpenResFile( &hInstance, name ) ) {
        if( !FindResources( &hInstance ) && !InitResources( &hInstance ) ) {
            MsgShift = _WResLanguage() * MSG_LANG_SPACING;
            if( GetMsg( name, MSG_USAGE_FIRST ) ) {
                return( 1 );
            }
        }
    }
    write( STDOUT_FILENO, NO_RES_MESSAGE, NO_RES_SIZE );
    MsgFini();
    return( 0 );
}
示例#11
0
int main( int argc, char **argv )
/*******************************/
{
    argc = argc;
#ifndef __WATCOMC__
    _argv = argv;
    _argc = argc;
#endif

#else

int main( void )
/**************/
{
    char       *argv[2];
    int        len;
    char       *buff;
#endif

    main_init();
    SwitchChar = _dos_switch_char();
#ifndef __UNIX__
    len = _bgetcmd( NULL, INT_MAX ) + 1;
    buff = malloc( len );
    if( buff != NULL ) {
        argv[0] = buff;
        argv[1] = NULL;
        _bgetcmd( buff, len );
    } else {
        return( -1 );
    }
    do_init_stuff( argv );
#else
    do_init_stuff( &argv[1] );
#endif
    SetMemoryModel();
    WriteObjModule();           // main body: parse the source file
    MsgFini();
    main_fini();
#ifndef __UNIX__
    free( buff );
#endif
    return( Options.error_count ); /* zero if no errors */
}
示例#12
0
int MsgInit( void )
/******************/
{
    char        name[_MAX_PATH];
    char        dummy[MAX_RESOURCE_SIZE];

    hInstance.handle = NIL_HANDLE;
    if( _cmdname( name ) != NULL && !OpenResFile( &hInstance, name ) ) {
        if( !FindResources( &hInstance ) && !InitResources( &hInstance ) ) {
            MsgShift = _WResLanguage() * MSG_LANG_SPACING;
            if( MsgGet( MSG_USAGE_BASE, dummy ) ) {
                return( true );
            }
        }
    }
    write( STDOUT_FILENO, NO_RES_MESSAGE, NO_RES_SIZE );
    MsgFini();
    return( false );
}
示例#13
0
bool MsgInit( void )
{
    char            name[_MAX_PATH];

    hInstance.handle = NIL_HANDLE;
    if( _cmdname( name ) != NULL && !OpenResFile( &hInstance, name ) ) {
        res_failure = false;
        if( !FindResources( &hInstance ) && !InitResources( &hInstance ) ) {
            MsgShift = _WResLanguage() * MSG_LANG_SPACING;
            if( MsgGet( WDIS_LITERAL_BASE, name ) ) {
                return( true );
            }
        }
        MsgFini();
    }
    write( STDOUT_FILENO, NO_RES_MESSAGE, NO_RES_SIZE );
    res_failure = true;
    return( false );
}
示例#14
0
static void cleanupHandler( void )
{
    char *p;

    if( outputFile[0] != '\0' ) {
        if( fileOut != NULL ) {
            ObjWriteClose( fileOut );
            fileOut = NULL;
        }
        for( p = outputFile; p != &outputFile[ _MAX_PATH ]; ++p ) {
            if( *p == '\0' ) {
                unlink( outputFile );
                break;
            }
            if( ! isprint( *p ) ) break;
        }
    }
    MsgFini();
    MemFini();
}
示例#15
0
int MsgInit( void )
/*****************/
{
#ifndef BOOTSTRAP
    static char     name[_MAX_PATH]; // static because address passed outside.

    hInstance.handle = NIL_HANDLE;
    if( _cmdname( name ) != NULL && !OpenResFile( &hInstance, name ) ) {
        if( !FindResources( &hInstance ) && !InitResources( &hInstance ) ) {
            MsgShift = _WResLanguage() * MSG_LANG_SPACING;
            if( MsgGet( MSG_USAGE_BASE, name ) ) {
                return( 1 );
            }
        }
    }
    write( STDOUT_FILENO, NO_RES_MESSAGE, NO_RES_SIZE );
    MsgFini();
    return( 0 );
#else    
    return( 1 );
#endif
}
示例#16
0
void main( int argc, char *argv[] ) {
#pragma on (unreferenced);

    uint        i;
    uint        num_files;
    cmdline_t   *cmd;
    int         multi_module;
    pobj_lib_info pli;

    atexit( cleanupHandler );
    MemInit();
    MsgInit( argv[0] );
    cmd = CmdLineParse();
    init();
    while( cmd->action != NULL ) {
        ActionInit( cmd );
        num_files = cmd->action->num_files;
        i = 0;
        do {
            ActionInfile( cmd, inputFile, i );
            fileIn = ObjReadOpen( inputFile );
            if( fileIn == NULL ) {
                Fatal( MSG_UNABLE_TO_OPEN_FILE, inputFile );
            }
            if( cmd->need_output ) {
                ActionOutfile( cmd, outputFile, i );
                fileOut = ObjWriteOpen( outputFile );
                if( fileOut == NULL ) {
                    Fatal( MSG_UNABLE_TO_OPEN_FILE, outputFile );
                }
            } else {
                fileOut = NULL;
            }
            if( cmd->quiet == 0 ) {
                char    msgbuff[MAX_RESOURCE_SIZE];

                MsgGet( MSG_CONVERTING, msgbuff );
                PrtFmt( msgbuff, inputFile );
                PrtFmt( "\n" );
            }
            pli.is_lib = 0;
            do {
                multi_module = PObj( fileIn, fileOut, &pli );
                prune();
            } while( multi_module );
            ObjReadClose( fileIn );
            if( fileOut != NULL ) {
                ObjWriteClose( fileOut );
                ActionRename( cmd, inputFile, outputFile, i, pli.is_lib,
                    pli.page_len );
            }
            ++i;
        } while( i < num_files );
        ActionFini( cmd );
    }
    fini();
    MsgFini();
    MemFini();
    outputFile[0] = '\0';
    exit( EXIT_SUCCESS );
}
示例#17
0
文件: main.c 项目: tonylazarew/jwasm
int main( int argc, char **argv )
/*******************************/
{
    char    *pEnv;
    int     numArgs = 0;
    int     numFiles = 0;
    int     rc = 0;
#if WILDCARDS
    long    fh; /* _findfirst/next/close() handle, must be long! */
    struct  _finddata_t finfo;
    char    drv[_MAX_DRIVE];
    char    dir[_MAX_DIR];
    char    fname[_MAX_PATH];
#endif

#if 0 //def DEBUG_OUT    /* DebugMsg() cannot be used that early */
    int i;
    for ( i = 1; i < argc; i++ ) {
        printf("argv[%u]=>%s<\n", i, argv[i] );
    }
#endif

    pEnv = getenv( "JWASM" );
    if ( pEnv == NULL )
        pEnv = "";
    argv[0] = pEnv;

#ifndef DEBUG_OUT
    signal(SIGSEGV, genfailure);
#endif

#if CATCHBREAK
    signal(SIGBREAK, genfailure);
#else
    signal(SIGTERM, genfailure);
#endif

    MsgInit();

    while ( 1 ) {
        if ( ParseCmdline( (const char **)argv, &numArgs ) == NULL )
            break;  /* exit if no source file name supplied */
        numFiles++;
        write_logo();
#if WILDCARDS
        if ((fh = _findfirst( Options.names[ASM], &finfo )) == -1 ) {
            DebugMsg(("main: _findfirst(%s) failed\n", Options.names[ASM] ));
            EmitErr( CANNOT_OPEN_FILE, Options.names[ASM], ErrnoStr() );
            break;
        }
        _splitpath( Options.names[ASM], drv, dir, NULL, NULL );
        DebugMsg(("main: _splitpath(%s): drv=\"%s\" dir=\"%s\"\n", Options.names[ASM], drv, dir ));
        do {
            _makepath( fname, drv, dir, finfo.name, NULL );
            DebugMsg(("main: _makepath(\"%s\", \"%s\", \"%s\")=\"%s\"\n", drv, dir, finfo.name, fname ));
            rc = AssembleModule( fname );  /* assemble 1 module */
        } while ( ( _findnext( fh, &finfo ) != -1 ) );
        _findclose( fh );
#else
        rc = AssembleModule( Options.names[ASM] );
#endif
    };
    CmdlineFini();
    if ( numArgs == 0 ) {
        write_logo();
        printf( MsgGetEx( MSG_USAGE ) );
    } else if ( numFiles == 0 )
        EmitError( NO_FILENAME_SPECIFIED );

    MsgFini();
    return( 1 - rc ); /* zero if no errors */
}
示例#18
0
void StartProg( char *cmd, char *prog, char *full_args, char *dos_args )
{

    seg_offset  where;
    int         error_num;
    char        buff[BSIZE];
    Fptr32      fp;
    short       initial_cs;
    int         len;

    cmd = cmd;
    SampleIndex = 0;
    CurrTick  = 0L;

    D32HookTimer( TimerMult );  /* ask for timer - before D32DebugInit!! */
    D32DebugBreakOp(&Break);    /* Get the 1 byte break op */

    error_num = D32DebugInit( &Proc );
    if( error_num == 0 ) {
        strcpy( buff, full_args );
        error_num = D32DebugLoad( prog, buff, &Proc );
    }
    if( error_num != 0 ) {
        Output( MsgArray[MSG_SAMPLE_2-ERR_FIRST_MESSAGE] );
        Output( prog );
        Output( "\r\n" );
        MsgFini();
        exit(1);
    }

    where.offset = 0;
    where.segment = 0;
    WriteCodeLoad( where, ExeName, SAMP_MAIN_LOAD );

    fp.sel = 1;
    fp.off = 0;
    D32Relocate(&fp);
    WriteAddrMap( 1, fp.sel, fp.off );

    initial_cs = Proc.cs;
    for( ;; ) {
        D32DebugRun( &Proc );
        if( SampleIndex > Margin && Proc.cs == initial_cs ) {
            StopAndSave();
        }
        if( Proc.int_id == 8 ) {
            ++InsiderTime;
            RecordSample( Proc.eip, Proc.cs );
            --InsiderTime;
        } else if( Proc.int_id == 3 && (Proc.edx & 0xffff) != 0 ) {
            len = 0;                                    /* this is a mark */
            where.segment = Proc.edx & 0xffff;
            where.offset = Proc.eax;
            for( ;; ) {
                if( !D32AddressCheck( where.segment, where.offset, 1, NULL ) ) break;
                D32DebugRead( where.offset, where.segment, 0, &buff[len], 1 );
                if( len == BSIZE ) break;
                if( buff[len] == '\0' ) break;
                len++;
                where.offset++;
            }
            buff[len] = '\0';
            where.segment = Proc.cs;
            where.offset = Proc.eip;
            WriteMark( buff, where );
            Proc.eip++;
        } else if( Proc.int_id == 3 ) {         /* remember common storage */
            CommonAddr.segment = Proc.ecx & 0xffff;            /* area ... */
            CommonAddr.offset = Proc.ebx;
            Proc.eip++;
        } else {
            break;
        }
    }
    D32UnHookTimer();
    if( Proc.int_id != 0x21 ) {
        Output( MsgArray[MSG_SAMPLE_1-ERR_FIRST_MESSAGE] );
        Output( MsgArray[Exceptions[Proc.int_id]+MSG_EXCEPT_0-ERR_FIRST_MESSAGE] );
        Output( "\r\n" );
    }
    D32DebugTerm();
    report();
}
示例#19
0
static void do_fini_stuff( void )
/*******************************/
{
    MsgFini();
}