Ejemplo n.º 1
0
/*
    FIXME: this is an ugly function!
*/
void ActionRename( cmdline_t *cmd, const char *in, const char *out,
    uint file_num, int make_lib, size_t page_size ) {
/***************************************************/
    char        sp_buf[ _MAX_PATH2 ];
    char        sp_buf2[ _MAX_PATH2 ];
    char        *drive;
    char        *dir;
    char        *fname;
    char        *ext;
    char        buf[ _MAX_PATH ];
    const char  *output;
    act_grp_t   *cur;
    int         rc;

/**/myassert( cmd != NULL );
/**/myassert( cmd->need_output );
/**/myassert( cmd->action != NULL );
/**/myassert( file_num < cmd->action->num_files );
    cur = cmd->action;
    output = cur->output;
    if( output == NULL || output[0] == 0 ) {
        /* get the drive and directory of input file */
        _splitpath2( in, sp_buf, &drive, &dir, NULL, NULL );
        fname = "";
        ext = "";
    } else {
        /* split up the output spec */
        _splitpath2( output, sp_buf, &drive, &dir, &fname, &ext );
    }
    /* If the output spec was like '/o=.mbj' or '/o=f:\tmp\.mbj' then
       we have to use the filename and/or the extension from the input. */
    _splitpath2( cur->files[ file_num ], sp_buf2, NULL, NULL,
        ( fname[0] == 0 ) ? &fname : NULL,      /* get filename from input */
        ( ext[0] == 0 ) ? &ext : NULL );        /* get extension from input */
    if( ext[0] == 0 ) {                 /* use default extension if necessary */
        ext = OBJ_EXTENSION;
    }
    _makepath( buf, drive, dir, fname, ext );
    if( make_lib ) {
        if( cur->batch ) {
            PrtFmt( "wlib %s /b/n/p=%u +%s\n", buf, page_size, out );
            PrtFmt( "del %s\n", out );
        } else {
            char pbuf[ sizeof( size_t ) * 3 ];
            StrDec( pbuf, page_size );
#ifdef _M_I86
            _fheapshrink();
#endif
            _nheapshrink();
            rc = (int)spawnlp(P_WAIT,"wlib","wlib",buf,"/b/n/p=",pbuf,"+",out,NULL);
            if( rc < 0 ) {
                Fatal( MSG_DISK_ERROR, "spawnlp( , \"wlib\", ... )" );
            } else if( rc > 0 ) {
                Fatal( MSG_WLIB_ERROR );
            }
            if( unlink( out ) != 0 ) {
                Fatal( MSG_DISK_ERROR, "unlink" );
            }
        }
    } else if( cur->batch ) {
        PrtFmt( "if exist %s del %s\n", buf, buf );
        PrtFmt( "rename %s %s\n", out, buf );
    } else {
        unlink( buf );          /* delete any file of this name */
        if( rename( out, buf ) != 0 ) {
            Fatal( MSG_DISK_ERROR, "rename" );
        }
    }
}
Ejemplo n.º 2
0
int __ExpandDGROUP( unsigned amount )
{
#if defined(__WINDOWS__) || defined(__WARP__) || defined(__NT__) \
  || defined(__CALL21__) || defined(__RDOS__)
    // first try to free any available storage
    _nheapshrink();
    return( __CreateNewNHeap( amount ) );
#else
    mheapptr    p1;
    frlptr      flp;
    unsigned    brk_value;
    tag         *last_tag;
    unsigned    new_brk_value;
    void        _WCNEAR *brk_ret;

  #if defined(__DOS_EXT__)
    if( !__IsCtsNHeap() ) {
        return( __CreateNewNHeap( amount ) );   // Won't slice either
    }
    // Rational non-zero based system should go through.
  #endif
    if( !__heap_enabled )
        return( 0 );
    if( _curbrk == ~1u )
        return( 0 );
    if( __AdjustAmount( &amount ) == 0 )
        return( 0 );
  #if defined(__DOS_EXT__)
    if( _IsPharLap() && !_IsFlashTek() ) {
        _curbrk = SegmentLimit();
    }
  #endif
    new_brk_value = amount + _curbrk;
    if( new_brk_value < _curbrk ) {
        new_brk_value = ~1u;
    }
    brk_ret = __brk( new_brk_value );
    if( brk_ret == (void _WCNEAR *)-1 ) {
        return( 0 );
    }
    brk_value = (unsigned)brk_ret;
    if( brk_value >  /*0xfff8*/ ~7u ) {
        return( 0 );
    }
    if( new_brk_value <= brk_value ) {
        return( 0 );
    }
    amount = new_brk_value - brk_value;
    if( amount - TAG_SIZE > amount ) {
        return( 0 );
    } else {
        amount -= TAG_SIZE;
    }
    for( p1 = __nheapbeg; p1 != NULL; p1 = p1->next ) {
        if( p1->next == NULL )
            break;
        if( (unsigned)p1 <= brk_value && ((unsigned)p1) + p1->len + TAG_SIZE >= brk_value ) {
            break;
        }
    }
    if( (p1 != NULL) && ((brk_value - TAG_SIZE) == (unsigned)( (PTR)p1 + p1->len) ) ) {
        /* we are extending the previous heap block (slicing) */
        /* nb. account for the end-of-heap tag */
        brk_value -= TAG_SIZE;
        amount += TAG_SIZE;
        flp = (frlptr) brk_value;
        /* adjust current entry in heap list */
        p1->len += amount;
        /* fix up end of heap links */
        last_tag = (tag *) ( (PTR)flp + amount );
        last_tag[0] = END_TAG;
    } else {
        if( amount < sizeof( miniheapblkp ) + sizeof( frl ) ) {
        /*  there isn't enough for a heap block (struct miniheapblkp) and
            one free block (frl) */
            return( 0 );
        }
        // Initializing the near heap if __nheapbeg == NULL,
        // otherwise, a new mini-heap is getting linked up
        p1 = (mheapptr)brk_value;
        p1->len = amount;
        flp = __LinkUpNewMHeap( p1 );
        amount = flp->len;
    }
    /* build a block for _nfree() */
    SET_MEMBLK_SIZE_USED( flp, amount );
    ++p1->numalloc;                         /* 28-dec-90 */
    p1->largest_blk = ~0;    /* set to largest value to be safe */
    _nfree( (PTR)flp + TAG_SIZE );
    return( 1 );
#endif
}
Ejemplo n.º 3
0
_WCRTLINK int _nheapmin( void )
    {
        return( _nheapshrink() );
    }