dj(1): iron out Io_bufxapp
This commit is contained in:
parent
7fe122ac3b
commit
f4b97be1f1
30
src/dj.c
30
src/dj.c
@ -75,25 +75,6 @@ Io_bufrpad(struct Io *io, int padding){
|
|||||||
return io;
|
return io;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copies from the buffer in src as much as possible to the free space in the
|
|
||||||
* dest buffer, removing the copied units from src and permuting the remaining
|
|
||||||
* units in the src buffer to the start of the buffer, modifying both the src
|
|
||||||
* and dest bufuse and returning dest. */
|
|
||||||
static struct Io*
|
|
||||||
Io_bufxapp(struct Io *dest, struct Io *src){
|
|
||||||
int n;
|
|
||||||
|
|
||||||
assert(dest != NULL && src != NULL);
|
|
||||||
|
|
||||||
n = MIN(src->bufuse, dest->bs - dest->bufuse);
|
|
||||||
memcpy(dest->buf + dest->bufuse, src->buf, n);
|
|
||||||
dest->bufuse += n;
|
|
||||||
memmove(src->buf, src->buf + n, src->bs - n);
|
|
||||||
src->bufuse -= n;
|
|
||||||
|
|
||||||
return dest;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copies from the buffer in src to the buffer in dest no more than n units,
|
/* Copies from the buffer in src to the buffer in dest no more than n units,
|
||||||
* removing the copied units from src and permuting the remaining units in the
|
* removing the copied units from src and permuting the remaining units in the
|
||||||
* src buffer to the start of the buffer, modifying both the src and dest
|
* src buffer to the start of the buffer, modifying both the src and dest
|
||||||
@ -338,7 +319,16 @@ int main(int argc, char *argv[]){
|
|||||||
int t;
|
int t;
|
||||||
|
|
||||||
if(io[1].bs > io[0].bs){
|
if(io[1].bs > io[0].bs){
|
||||||
Io_bufxapp(&io[1], &io[0]);
|
int n;
|
||||||
|
|
||||||
|
/* copy from ibuf as much as possible to the obuf */
|
||||||
|
memcpy(io[1].buf + io[1].bufuse, io[0].buf,
|
||||||
|
(n = MIN(io[0].bufuse, io[1].bs - io[1].bufuse)));
|
||||||
|
io[1].bufuse += n;
|
||||||
|
/* permute out the copied units */
|
||||||
|
memmove(io[0].buf, io[0].buf + n, io[0].bs - n);
|
||||||
|
io[0].bufuse -= n;
|
||||||
|
|
||||||
if(io[0].bs + io[1].bufuse <= io[1].bs && count != 1)
|
if(io[0].bs + io[1].bufuse <= io[1].bs && count != 1)
|
||||||
continue; /* we could write more */
|
continue; /* we could write more */
|
||||||
}else
|
}else
|
||||||
|
Loading…
Reference in New Issue
Block a user