OSSP CVS Repository

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

Check-in Number: 2916
Date: 2002-Nov-28 16:12:40 (local)
2002-Nov-28 15:12:40 (UTC)
User:mlelstv
Branch:
Comment: new al_setlabel method to modify the data label within an assembly line.

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

Tickets:
Inspections:
Files:
ossp-pkg/sio/al.c      1.36 -> 1.37     82 inserted, 0 deleted
ossp-pkg/sio/al.h      1.14 -> 1.15     2 inserted, 1 deleted
ossp-pkg/sio/al.pod      1.14 -> 1.15     7 inserted, 0 deleted
ossp-pkg/sio/al_test.c      1.16 -> 1.17     7 inserted, 1 deleted

ossp-pkg/sio/al.c 1.36 -> 1.37

--- al.c 2002/11/19 17:02:17     1.36
+++ al.c 2002/11/28 15:12:40     1.37
@@ -818,6 +818,88 @@
 }
 
 /*
+ *
+ */
+al_rc_t
+al_setlabel(al_t *al, size_t off, size_t n, al_label_t label)
+{
+    al_rc_t rc;
+    al_chunk_t *cur, *splitbuf;
+    size_t skip, len;
+
+    /* argument sanity check(s) */
+    if (al == NULL || n < 0)
+        return AL_RC(AL_ERR_ARG);
+
+    /*
+     * seek to beginning, return EOF when seek position does not exist
+     * EOD must be a valid seek position so that we can append data
+     */
+    rc = al_seek(al, off, &cur, &skip);
+    if (rc != AL_OK)
+        return AL_RC(rc);
+
+    /*
+     * seek to EOD, nothing to label
+     */
+    if (cur == NULL)
+        return AL_OK;
+
+    /*
+     * if first chunk doesn't need relabeling
+     * then skip it, adjust seek size
+     *
+     * else if offset is not at chunk start
+     * then split chunk at offset, continue
+     * with second half
+     */
+    if (AL_SAME_LABEL(cur, label)) {
+        len = AL_CHUNK_LEN(cur) - skip;
+        n = n < len ? 0 : n - len;
+        cur = NEXT(cur, chunks);
+    } else if (skip > 0) {
+        rc = split_chunk(al, cur, skip, &splitbuf);
+        if (rc != AL_OK)
+            return AL_RC(rc);
+        INSERT(al,chunks,cur,splitbuf);
+    }
+
+    /*
+     * for all remaining chunks and bytes
+     *
+     * if chunk doesn't need relabeling
+     * then skip it, adjust size
+     *
+     * else if chunk isn't covered in total
+     * then split chunk at end offset and
+     * process first half
+     */
+    while (n > 0 && cur != NULL) {
+        len = AL_CHUNK_LEN(cur);
+        if (AL_SAME_LABEL(cur, label)) {
+            n = n < len ? 0 : n - len;
+        } else {
+            if (n < len) {
+                /*
+                 * split last chunk at end offset
+                 */
+                rc = split_chunk(al, cur, n, &splitbuf);
+                if (rc != AL_OK)
+                    return AL_RC(rc);
+                INSERT(al,chunks,cur,splitbuf);
+                cur = splitbuf;
+                len = AL_CHUNK_LEN(cur);
+            }
+            AL_CHUNK_LABEL(cur) = label;
+            n   -= len;
+        }
+        cur  = NEXT(cur, chunks);
+    }
+
+    return AL_OK;
+}
+
+/*
  * assembly line traversal requires a context. It needs to be
  * malloced to keep its inner structure private
  */


ossp-pkg/sio/al.h 1.14 -> 1.15

--- al.h 2002/10/23 16:49:29     1.14
+++ al.h 2002/11/28 15:12:40     1.15
@@ -68,9 +68,10 @@
 al_rc_t al_traverse     (al_t *al, size_t off, size_t n, al_td_t dir, al_label_t label, al_tx_t *tx);
 al_rc_t al_traverse_next(al_t *al, al_tx_t *tx, al_chunk_t **alcp);
 al_rc_t al_traverse_end (al_t *al, al_tx_t *tx, int final);
-al_rc_t al_traverse_cb  (al_t *al, size_t off, size_t n, al_td_t dir, al_label_t, al_rc_t (*cb)(al_chunk_t *, void *), void *u);
+al_rc_t al_traverse_cb  (al_t *al, size_t off, size_t n, al_td_t dir, al_label_t label, al_rc_t (*cb)(al_chunk_t *, void *), void *u);
 al_rc_t al_copy         (al_t *al, size_t off, size_t n, al_label_t label, al_t *tal);
 al_rc_t al_splice       (al_t *al, size_t off, size_t n, al_t *nal, al_t *tal);
+al_rc_t al_setlabel     (al_t *al, size_t off, size_t n, al_label_t label);
 al_rc_t al_flatten      (al_t *al, size_t off, size_t n, al_td_t dir, al_label_t label, char *dst, size_t *lenp);
 al_rc_t al_firstlabel   (al_t *al, size_t off, size_t n, al_td_t dir, al_label_t label, al_label_t *labelp);
 


ossp-pkg/sio/al.pod 1.14 -> 1.15

--- al.pod       2002/11/07 15:28:52     1.14
+++ al.pod       2002/11/28 15:12:40     1.15
@@ -59,6 +59,7 @@
 al_prepend_bytes,
 al_attach_buffer,
 al_splice,
+al_setlabel,
 al_bytes.
 
 =item B<Traversal Operations>:
@@ -270,6 +271,12 @@
 The buffer now holds the string "HelloGoodbye\n".
 The insertion is empty.
 
+=item al_rc_t B<al_setlabel>(al_t *I<al>, size_t I<off>, size_t I<n>, al_label_t *label);
+
+I<off> and I<n> are byte counts that define a span of bytes within the
+source assembly line I<al>. These bytes are tagged with I<label>, any
+existing label for these bytes is overwritten.
+
 =item size_t B<al_bytes>(const al_t *I<al>);
 
 Returns the number of bytes stored in the assembly line.


ossp-pkg/sio/al_test.c 1.16 -> 1.17

--- al_test.c    2002/11/05 14:52:24     1.16
+++ al_test.c    2002/11/28 15:12:40     1.17
@@ -90,7 +90,7 @@
 
 #define DUMP(tag,al) do {\
 printf("+DUMP(%s)\n",tag);\
-al_traverse_cb(al, 0, al_bytes(al), AL_FORWARD, LABEL, printchunk, NULL);\
+al_traverse_cb(al, 0, al_bytes(al), AL_FORWARD, NULL, printchunk, NULL);\
 printf("-DUMP(%s)\n\n",tag);\
 } while (0)
 
@@ -178,6 +178,12 @@
     al_create(&al4);
     rc = al_copy(al, al_bytes(al)-42, 38, LABEL, al4);
     printf("copy result: %d (%s)\n\n",rc,al_error(rc));
+    checklen("SPLICED",al);
+    checklen("COPY",al4);
+
+    rc = al_setlabel(al4, 5, 9, LABEL2);
+    printf("setlabel result: %d (%s)\n\n",rc,al_error(rc));
+    checklen("COPY",al4);
 
     DUMP("SPLICED",al);
     print("SPLICED", al);

CVSTrac 2.0.1