Esempio n. 1
0
static void openFiles( void )
{
    int objhdl;

    objhdl = open( ObjFileName, O_RDONLY | O_BINARY );
    if( objhdl != -1 ) {
        if( ListFileName != NULL ) {
            OutputDest = open( ListFileName, O_WRONLY | O_CREAT | O_TRUNC, PMODE_RW );
            if( OutputDest == -1 )
                openError( ListFileName );
            ChangePrintDest( OutputDest );
        }
        objFileLen = filelength( objhdl );
        if( objFileLen == 0 ) {
            LeaveProgram( RC_OKAY, WHERE_OBJ_ZERO_LEN );
        }
        objFileBuf = MemAlloc( objFileLen );
        objFilePos = 0;
        if( posix_read( objhdl, objFileBuf, objFileLen ) == -1 ) {
            openError( ObjFileName );
        }
        close( objhdl );
    } else {
        openError( ObjFileName );
    }
}
Esempio n. 2
0
void Init( void )
{
    char                cmd_line[ CMD_LINE_LEN ];
    return_val          error;
    char                **list;

    OutputDest = STDOUT_FILENO;
    ChangePrintDest( OutputDest );

    relocSections.first = NULL;
    relocSections.last = NULL;
    if( !MsgInit() ) {
        // MsgInit does its own error message printing
        exit( -1 );
    }
    MemOpen();

    getcmd( cmd_line );
    HandleArgs( cmd_line );

    openFiles();
    initGlobals();
    error = initHashTables();
    if( error == OKAY ) {
        error = initServicesUsed();
        if( error == OKAY ) {
            error = initSectionTables();
            if( error != OKAY ) {
                // free hash tables and services
                MemClose();
                LeaveProgram( error, WHERE_CREATE_SEC_TABLES );
            }
        } else {
            // free hash tables
            CloseFiles();
            FreeHashTables();
            // initServicesUsed does its own error message printing
            exit( error );
        }
    } else {
        CloseFiles();
        MemClose();
        LeaveProgram( error, WHERE_INIT_HASH_TABLES );
    }
    if( Options & PRINT_PUBLICS ) {
        CreatePublicsArray();
    }
    if( IsMasmOutput() ) {
        CommentString = MASM_COMMENT_STRING;
    }
    if( IsIntelx86() ) {
        SkipRefTable = HashTableCreate( RECOGNITION_TABLE_SIZE, HASH_STRING,
                                        (hash_table_comparison_func) stricmp );
        if( SkipRefTable ) {
            list = intelSkipRefList;
            while( *list ) {
                error = HashTableInsert( SkipRefTable, (hash_value) *list,
                                         (hash_data) *list );
                if( error != OKAY ) break;
                list++;
            }
        }
    }

    if( !LabelChar ) {
        if( IsMasmOutput() ) {
            LabelChar = 'L';
        } else {
            LabelChar = 'X';
        }
    }
}