OSSP CVS Repository

ossp - Check-in [2578]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2578
Date: 2002-Oct-14 17:41:37 (local)
2002-Oct-14 15:41:37 (UTC)
User:mlelstv
Branch:
Comment: al_copy function, like al_flatten but into a target assembly list

PR: Submitted by: Reviewed by: Approved by: Obtained from:

Tickets:
Inspections:
Files:
ossp-pkg/sio/al.c      1.6 -> 1.7     32 inserted, 0 deleted
ossp-pkg/sio/al.h      1.3 -> 1.4     1 inserted, 0 deleted
ossp-pkg/sio/al_test.c      1.4 -> 1.5     13 inserted, 3 deleted

ossp-pkg/sio/al.c 1.6 -> 1.7

--- 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;
 }


ossp-pkg/sio/al.h 1.3 -> 1.4

--- 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);


ossp-pkg/sio/al_test.c 1.4 -> 1.5

--- 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;
 }

CVSTrac 2.0.1