Index: ossp-pkg/sio/al.c RCS File: /v/ossp/cvs/ossp-pkg/sio/Attic/al.c,v rcsdiff -q -kk '-r1.6' '-r1.7' -u '/v/ossp/cvs/ossp-pkg/sio/Attic/al.c,v' 2>/dev/null --- al.c 2002/10/14 15:26:04 1.6 +++ al.c 2002/10/14 15:41:37 1.7 @@ -615,8 +615,14 @@ } /* + * this is the central function to manipulate assembly lists * + * cut arbitrary spans from list into a destination buffer (or drop it) + * insert (destructive move) content from another list into the cut * + * this is analog to perls splice function, except that + * -> the output is not stored in the target buffer but is appended + * -> the replacement data is moved and not copied. * */ al_rc_t al_splice(al_t *al, size_t off, size_t n, al_t *nal, al_t *tal) @@ -889,6 +895,32 @@ if (rc != AL_ERR_EOF) return rc; + + return AL_OK; +} + +/* + * full list traversal with data copy to target assembly list + * + * traversal context is kept on stack (XXX ?) + */ +al_rc_t al_copy(al_t *al, size_t off, size_t n, al_t *tal) +{ + al_rc_t rc; + al_tx_t tx; /* XXX - private tx structure on stack */ + al_chunk_t *view; + size_t step; + + rc = al_traverse(al, off, n, AL_FORWARD, &tx); + if (rc != AL_OK) return rc; + + while ((rc = al_traverse_next(al, &tx, &view)) == AL_OK) { + step = AL_CHUNK_LEN(view); + al_append_bytes(tal, AL_CHUNK_PTR(view,0), step); + } + + if (rc != AL_ERR_EOF) + return rc; return AL_OK; } Index: ossp-pkg/sio/al.h RCS File: /v/ossp/cvs/ossp-pkg/sio/Attic/al.h,v rcsdiff -q -kk '-r1.3' '-r1.4' -u '/v/ossp/cvs/ossp-pkg/sio/Attic/al.h,v' 2>/dev/null --- al.h 2002/10/14 13:34:25 1.3 +++ al.h 2002/10/14 15:41:37 1.4 @@ -36,6 +36,7 @@ al_rc_t al_traverse_cb(al_t *al, size_t off, size_t n, al_td_t dir, al_rc_t (*cb)(al_chunk_t *, void *), void *u); al_rc_t al_flatten(al_t *al, size_t off, size_t n, char *dst, size_t *lenp); +al_rc_t al_copy(al_t *al, size_t off, size_t n, al_t *tal); size_t al_bytes(const al_t *al); size_t al_chunk_len(al_chunk_t *alc); Index: ossp-pkg/sio/al_test.c RCS File: /v/ossp/cvs/ossp-pkg/sio/Attic/al_test.c,v rcsdiff -q -kk '-r1.4' '-r1.5' -u '/v/ossp/cvs/ossp-pkg/sio/Attic/al_test.c,v' 2>/dev/null --- al_test.c 2002/10/14 15:26:04 1.4 +++ al_test.c 2002/10/14 15:41:37 1.5 @@ -100,7 +100,7 @@ int main() { al_rc_t rc; - al_t *al, *al2, *al3; + al_t *al, *al2, *al3, *al4; char baf[] = "Mittendrin\n"; int i; @@ -122,15 +122,17 @@ DUMP("BUFFER",al2); DUMP("REPLACEMENT", al3); -#if 1 rc = al_splice(al, al_bytes(al)-500, 500, al3, al2); -#endif printf("splice result: %d (%s)\n\n",rc,al_error(rc)); checklen("SPLICED",al); checklen("BUFFER",al2); checklen("REPLACEMENT",al3); + al_create(&al4); + rc = al_copy(al, al_bytes(al)-42, 38, al4); + printf("copy result: %d (%s)\n\n",rc,al_error(rc)); + DUMP("SPLICED",al); print("SPLICED", al); @@ -153,5 +155,13 @@ al_destroy(al); + + DUMP("COPY", al4); + print("COPY", al4); + + printf("free COPY\n"); + fflush(stdout); + al_destroy(al4); + return 0; }