Esempio n. 1
0
bool ObjInit( char *fname ) {
//***************************

    owl_client_funcs    funcs = {
        (int (*)( owl_client_file, const char *, uint ))write,
        (long (*)( owl_client_file ))tell,
        (long (*)( owl_client_file, long, int ))lseek,
        MemAlloc,
        MemFree
    };
    char                name[ _MAX_FNAME ];
    owl_format          obj_format;

    SectionInit();
    _splitpath( fname, NULL, NULL, name, NULL );
    if( !objectDefined ) {
        _makepath( objName, NULL, NULL, name, OBJ_EXT );
    } else {
        char    tmpName[ _MAX_PATH2 ];
        char    *tmpNode;
        char    *tmpDir;
        char    *tmpFname;
        char    *tmpExt;
        _splitpath2( objName, tmpName, &tmpNode, &tmpDir, &tmpFname, &tmpExt );
        if( *tmpExt == 0 )
            tmpExt = OBJ_EXT;
        if( *tmpFname == 0 )
            tmpFname = name;
        _makepath( objName, tmpNode, tmpDir, tmpFname, tmpExt );
    }
    objectDefined = FALSE;      // so that the /fo applies only to the 1st obj
    _makepath( errorFilename, NULL, NULL, name, ".err" );
    objFile = open( objName, O_CREAT | O_TRUNC | O_BINARY | O_WRONLY, PMODE_RW );
    if( objFile == -1 ) {
        AsOutMessage( stderr, UNABLE_TO_CREATE, objName );
        fputc( '\n', stderr );
        return( FALSE );
    }
    ErrorFile = fopen( errorFilename, "wt" );
    OwlHandle = OWLInit( &funcs, OBJ_OWL_CPU );
    obj_format = ( _IsOption( OBJ_COFF ) ? OWL_FORMAT_COFF : OWL_FORMAT_ELF );
    OwlFile = OWLFileInit( OwlHandle, fname, (owl_client_file)(pointer_int)objFile, obj_format, OWL_FILE_OBJECT );
    ObjSwitchSection( AS_SECTION_TEXT );
    CurrAlignment = 0;
    return( TRUE );
}
Esempio n. 2
0
void main( int argc, char *argv[] ) {

    char                buffer[ BUFFER_SIZE ];
    owl_handle          owl;
    owl_file_handle     file;
    owl_string_table    *table;
    owl_client_funcs    funcs = { NULL, NULL, NULL, malloc, free };
    char                *t_buff;

    owl = OWLInit( &funcs, OWL_CPU_PPC );
    file = OWLFileInit( owl, "test", NULL, OWL_FORMAT_ELF, OWL_FILE_OBJECT );
    table = OWLStringInit( file );
    while( fgets( buffer, BUFFER_SIZE, stdin ) != NULL ) {
        addStrings( table, buffer );
        OWLStringDump( table );
    }
    t_buff = malloc( OWLStringTableSize( table ) + 1 );
    OWLStringEmit( table, t_buff );
    write( STDOUT_FILENO, t_buff, OWLStringTableSize( table ) );
    free( t_buff );
    OWLStringFini( table );
    OWLFileFini( file );
    OWLFini( owl );
}