Ejemplo n.º 1
0
/* ********************************************************************   */
PFBYTE _ks_realloc(PFBYTE ptr, int num_elements, int size)
{
#if (DISPLAY_MALLOC)
    DEBUG_ERROR("ks_realloc free: ", DINT1, ptr, 0);
#endif

#    if (defined (RTKBCPP))
/*#error: needs to be implemented   */
        ptr = ks_dpmi_alloc((word)(num_elements * size));
#    elif (INCLUDE_BGET)
        ptr = ((PFBYTE)bgetr(ptr, num_elements * size));

#    elif (NACT_OS || __TM1__ && INCLUDE_DE4X5)
#error: needs to be implemented
        ptr2 = ks_malloc(ptr, num_elements * size);
        tc_movebytes(ptr2, ptr, ?);

#    elif (INCLUDE_WINSOCK || INCLUDE_BSDSOCK)
        ptr = realloc(ptr, num_elements * size);

#    elif (defined(SEG_IAR))
        /* protected mode   */
        ptr = realloc(ptr, num_elements * size);
#    elif ( defined(__BORLANDC__) )   /* real mode */
        ptr = _frealloc(ptr, num_elements * size);

#    else
        #error: ks_realloc needs to be implemented
#    endif

    return(ptr);
}
Ejemplo n.º 2
0
HMEM   BMRealloc ( HMEM hv, UINT cb ) {

#ifdef BMHANDLES // {

    LPV  lpv;
    UINT cbOld;

    CVEnterCritSection(icsBm);

    lpv = LpvFromHmem ( hv );
    assert ( LPV );
    cbOld = _fmsize ( LPV );

    if ( cbOld != cb ) {
        LPV lpvNew = _fmalloc ( cb );

    if ( LPV && lpvNew) {
            _fmemcpy ( lpvNew, lpv, min ( cb, cbOld ) );
            _ffree ( LPV );
            LpvFromHmem ( hv ) = lpvNew;
        }
        else {
            hv = hmemNull;
        }
    }

    CVLeaveCritSection(icsBm);

    return hv;

#else // } else !BMHANDLES {

    return (HMEM) _frealloc((VOID FAR *)hv, cb);

#endif // }

}
Ejemplo n.º 3
0
BOOL EnterDeleteForUndo(PPOSITION Pos, ULONG Length, WORD Flags)
	/*Flags: 1=enter as selected, reselect after undo
	 *		 2=remove last undo information, cannot be undone later
	 */
{	LPBYTE   NewBuf = NULL;
	HGLOBAL  NewMem = 0;
	POSITION p;
	ULONG	 Inx;
	ULONG	 ByteCount = CountBytes(Pos);
	ULONG	 OldSize;
	LPUNDO	 Reallocated = NULL;

	if (Flags & 2) {
		if (!LastUndo->Inserted) return (FALSE);
		--LastUndo->Inserted;
		return (TRUE);
	}
	CheckForUndoneToRelease(TRUE);
	EnableUndo();
	if (!LastUndo ||
		(LastUndo->Pos != (ULONG)-1
		 && (LastUndo->Pos != ByteCount - LastUndo->Inserted
			 || (int)(Flags & 1) != ((LastUndo->Flags & UD_SELECT) != 0)
			 || !(LastUndo->Flags & UD_GLOBALMEM
				  && LastUndo->DelFill+Length > 64000))))
		if (!NewUndo()) return (FALSE);
	if (LastUndo->Pos == (ULONG)-1) LastUndo->Pos = ByteCount;
	if (!LastUndo->DelFill) {
		OldSize = 0;
		if (Length > 64000) {
			LastUndo->Flags |= UD_GLOBALMEM;
			NewMem = GlobalAlloc(GMEM_MOVEABLE, Length);
			if (NewMem) NewBuf = GlobalLock(NewMem);
		} else {
			assert(!(LastUndo->Flags & UD_GLOBALMEM));
			LastUndo->Flags &= ~UD_GLOBALMEM;
			Reallocated = (LPUNDO)_frealloc(LastUndo,
											(size_t)(sizeof(UNDO)+Length));
			if (Reallocated == NULL) return (FALSE);
			NewBuf = (LPBYTE)Reallocated + sizeof(UNDO);
		}
	} else {
		if (LastUndo->Flags & UD_GLOBALMEM) {
			OldSize = GlobalSize(LastUndo->DelMem);
			if (LastUndo->DelFill + Length > OldSize) {
				NewMem = GlobalReAlloc(LastUndo->DelMem,
									   LastUndo->DelFill + Length,
									   GMEM_MOVEABLE);
			} else NewMem = LastUndo->DelMem;
			if (NewMem) NewBuf = GlobalLock(NewMem);
		} else {
			Reallocated = (LPUNDO)_frealloc(LastUndo,
											(size_t)(sizeof(UNDO) + Length
														  + LastUndo->DelFill));
			if (Reallocated == NULL) return (FALSE);
			NewBuf = (LPBYTE)Reallocated + sizeof(UNDO);
			OldSize = 0;
		}
	}
	UndoMemUsed -= OldSize;
	if (NewBuf == NULL) {
		if (NewMem) GlobalFree(NewMem);
		return (FALSE);
	}
	if (Reallocated!=NULL && Reallocated!=LastUndo) {
		/*correct any references to this object...*/
		if (NextSequenceUndo == LastUndo) NextSequenceUndo = Reallocated;
		if (Reallocated->Prev != NULL) Reallocated->Prev->Next = Reallocated;
		if (FirstUndo == LastUndo) FirstUndo = Reallocated;
		LastUndo = Reallocated;
	}
	Inx = LastUndo->DelFill;
	if (NewMem) {
		UndoMemUsed += GlobalSize(NewMem);
		LastUndo->DelMem = NewMem;
	} else UndoMemUsed += Length;
	LastUndo->DelFill += Length;
	if (Flags & 1) LastUndo->Flags |= UD_SELECT;
	p = *Pos;
	while (Length) {
		UINT n, c = CharAt(&p);

		if (c == C_EOF) {
			/*should not occur!...*/
			assert(c != C_EOF);		/*!?*/
			LastUndo->DelFill -= Length;
			break;
		}
		if (Length > p.p->Fill - p.i) n = p.p->Fill - p.i;
		else n = (UINT)Length;
		assert(p.p->PageBuf);
		assert(n > 0);
		assert(n <= PAGESIZE);
		assert(p.i+n <= PAGESIZE);
		hmemcpy(NewBuf + Inx, p.p->PageBuf + p.i, n);
		Inx += n;
		p.i += n;
		Length -= n;
	}
	if (NewMem) GlobalUnlock(NewMem);
	return (TRUE);
}