Code:
pawd test_oust_paws( obj_paws *obj )
{
obj->action = "oust from";
if ( obj->ud )
{
pawd len = obj->leng;
pawc *txt = obj->text;
pawc *nxt = PawAllocObj( len );
if ( nxt )
{
pawd err = -1;
pawd pos = abs(rand() % len);
pawc num = sprintf( nxt, "%.*s", pos, txt + pos );
obj->oustCB( obj->ud, pos, NULL, len );
err = text_testall( obj, txt, nxt, num );
PawAlloc( nxt, 0 );
return err;
}
puts("Couldn't allocate memory for temporary string");
return -1;
}
printf("Object does not exist, cannot oust %s\n", obj->type );
return -1;
}
...
void* test__pawMakeMemoryN( void *ud, pawd pos, paws str, pawd dig )
{
(void)pos;
pawMEM Mem = pawMakeMemoryN( str, dig );
if ( Mem )
((obj_paws*)ud)->text = PawTopOfMemory( Mem );
return Mem;
}
void* test__pawCramMemoryX( void *ud, pawd pos, paws str, pawd len )
{
pawzd was = paws_len(PawTopOfMemory( ud ));
return pawCramMemoryX( ud, pos, str, len, was );
}
void* test__pawOustMemoryz( void *ud, pawd pos, paws str, pawd len )
{ (void)str; pawOustMemoryz( ud, 0, len - pos ); return NULL; }
void* test__pawJoinMemoryX( void *ud, pawd pos, paws str, pawd dig )
{ return pawJoinMemoryX( ud, str, dig, pos ); }
void* test__pawVoidMemory( void *ud ) { return pawVoidMemory( ud ); }
void* test__pawMakeBuffern( void *ud, pawd pos, paws str, pawd dig )
{
(void)pos;
pawBUF Buf = pawMakeBuffern( 1, str, dig );
if ( Buf )
((obj_paws*)ud)->text = PawTopOfBuffer( Buf );
return Buf;
}
void* test__pawCramBuffern( void *ud, pawd pos, paws str, pawd dig )
{ return pawCramBuffern( ud, pos, str, dig ); }
void* test__pawOustBufferc( void *ud, pawd pos, paws str, pawd len )
{ (void)str; pawOustBufferc( ud, 0, len - pos ); return NULL; }
void* test__pawJoinBuffern( void *ud, pawd pos, paws str, pawd dig )
{ (void)pos; return pawJoinBuffern( ud, str, dig ); }
void* test__pawVoidBuffer(void*ud) { return pawVoidBuffer(ud); }
pawd test_pawVoidMemory() { return test_void_object( &memtest ); }
pawd test_pawMakeMemoryN()
{
memtest.voidCB = test__pawVoidMemory;
memtest.makeCB = test__pawMakeMemoryN;
memtest.cramCB = test__pawCramMemoryX;
memtest.oustCB = test__pawOustMemoryz;
memtest.joinCB = test__pawJoinMemoryX;
return test_make_paws( &memtest );
}
pawd test_pawCramMemoryX() { return test_cram_paws( &memtest ); }
pawd test_pawOustMemoryz() { return test_oust_paws( &memtest ); }
pawd test_pawJoinMemoryX() { return test_join_paws( &memtest ); }
pawd test_pawVoidBuffer() { return test_void_object( &buftest ); }
pawd test_pawMakeBuffern()
{
buftest.voidCB = test__pawVoidBuffer;
buftest.makeCB = test__pawMakeBuffern;
buftest.cramCB = test__pawCramBuffern;
buftest.oustCB = test__pawOustBufferc;
buftest.joinCB = test__pawJoinBuffern;
return test_make_paws( &buftest );
}
pawd test_pawCramBuffern() { return test_cram_paws( &buftest ); }
pawd test_pawOustBufferc() { return test_oust_paws( &buftest ); }
pawd test_pawJoinBuffern() { return test_join_paws( &buftest ); }
...
PAW_API void pawOustBufferi( pawBUF Buf, pawd pos )
{ pawOustBufferr( Buf, pos, pos + 1 ); }
PAW_API void pawOustBufferc( pawBUF Buf, pawd pos, pawd num )
{ pawOustBufferr( Buf, pos, pos + num ); }
PAW_API void pawOustBufferr( pawBUF Buf, pawd pos, pawd end )
{
if
(
PawInRange( 0, pos, Buf->num )
&& PawInRange( pos, end, Buf->num )
)
{
pawOustMemoryr( Buf->Mem, Buf->div * pos, Buf->div * end );
Buf->num -= (end - pos);
}
}
...
PAW_API void pawOustMemoryz( pawMEM Mem, pawzd pos, pawzd cap )
{ pawOustMemoryr( Mem, pos, pos + cap ); }
PAW_API void pawOustMemoryr( pawMEM Mem, pawzd pos, pawzd end )
{
pawzd cap = Mem->cap;
if ( PawInRange( 0, pos, cap ) && PawInRange( pos, end, cap ) )
{
pawzd mov = cap - end;
pawhhu *top = PawTopOfMemory( Mem );
paw_mov( top + pos, top + end, mov );
paw_set( top + pos + mov, 0, end - pos );
}
}