OSSP CVS Repository

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

Check-in Number: 2918
Date: 2002-Nov-28 17:11:49 (local)
2002-Nov-28 16:11:49 (UTC)
User:mlelstv
Branch:
Comment: new al_spanlabel method

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

Tickets:
Inspections:
Files:
ossp-pkg/sio/al.c      1.37 -> 1.38     58 inserted, 0 deleted
ossp-pkg/sio/al.h      1.15 -> 1.16     1 inserted, 0 deleted
ossp-pkg/sio/al.pod      1.15 -> 1.16     10 inserted, 1 deleted
ossp-pkg/sio/al_test.c      1.17 -> 1.18     5 inserted, 0 deleted

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

--- al.c 2002/11/28 15:12:40     1.37
+++ al.c 2002/11/28 16:11:49     1.38
@@ -1186,6 +1186,64 @@
 }
 
 /*
+ * traverse assembly line forward and search first chunk
+ * that matches label and continue search until end of
+ * span of same label
+ *
+ * return offset to first byte in *offp
+ * return size of span to last byte in *spanp
+ *
+ * traversal context is kept on stack (XXX ?)
+ */
+al_rc_t
+al_spanlabel(al_t *al, size_t off, size_t n, al_label_t label,
+             size_t *offp, size_t *spanp)
+{
+    al_rc_t rc;
+    al_tx_t tx;                /* XXX - private tx structure on stack */
+    al_chunk_t *view;
+    size_t len, total, start;
+    int have_first;
+
+    /*
+     * we need to track absolute traversal position,
+     * so we have to see all chunks.. no filtering
+     * allowed
+     */
+    rc = al_traverse(al, off, n, AL_FORWARD, NULL, &tx);
+    if (rc != AL_OK)
+        return AL_RC(rc);
+
+    have_first = 0;
+    start      = 0;
+    total      = 0;
+    while ((rc = al_traverse_next(al, &tx, &view)) == AL_OK) {
+        len = AL_CHUNK_LEN(view);
+        if (AL_SAME_LABEL(view, label)) {
+            if (!have_first) {
+                start      = total;
+                have_first = 1;
+            }
+        } else if (have_first)
+            break;
+        total += len;
+    }
+
+    al_traverse_end(al, &tx, 1);
+
+    if (rc != AL_OK && rc != AL_ERR_EOF)
+        return AL_RC(rc);
+
+    if (!have_first)
+        return AL_RC(AL_ERR_EOF);
+
+    *offp   = off + start;
+    *spanp  = total - start;
+
+    return AL_OK;
+}
+
+/*
  * relay macros to caller
  *
  * al_bytes      - total number of bytes in assembly line


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

--- al.h 2002/11/28 15:12:40     1.15
+++ al.h 2002/11/28 16:11:49     1.16
@@ -74,6 +74,7 @@
 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);
+al_rc_t al_spanlabel    (al_t *al, size_t off, size_t n, al_label_t label, size_t *offp, size_t *spanp);
 
 size_t     al_bytes      (const al_t *al);
 size_t     al_chunk_len  (al_chunk_t *alc);


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

--- al.pod       2002/11/28 15:12:40     1.15
+++ al.pod       2002/11/28 16:11:49     1.16
@@ -75,7 +75,8 @@
 
 al_flatten,
 al_copy,
-al_firstlabel.
+al_firstlabel,
+al_spanlabel.
 
 =item B<Chunk Operations>:
 
@@ -392,6 +393,14 @@
 within the defined span is stored in I<labelp>, otherwise B<al_firstlabel>
 returns an error.
 
+=item al_rc_t B<al_spanlabel>(al_t *I<al>, size_t I<off>, size_t I<n>, al_label_t *I<label>, size_t *<offp>, size_t *<spanp>);
+
+I<off> and I<n> are byte counts that define a span of bytes within the
+assembly line I<al>. This span is searched for data tagged with the I<label>.
+The absolute byte offset of the first byte matching the label and the
+length of the span of the same label is returned in I<offp> and I<spanp>
+respectively.
+
 =back
 
 =head2 Chunk Operations


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

--- al_test.c    2002/11/28 15:12:40     1.17
+++ al_test.c    2002/11/28 16:11:49     1.18
@@ -149,6 +149,7 @@
     al_t *al, *al2, *al3, *al4;
     char baf[] = "Mittendrin\n";
     int i;
+    size_t off, span;
 
     al_create(&al);
     al_create(&al2);
@@ -185,6 +186,10 @@
     printf("setlabel result: %d (%s)\n\n",rc,al_error(rc));
     checklen("COPY",al4);
 
+    rc = al_spanlabel(al4, 8, al_bytes(al), LABEL, &off, &span);
+    printf("spanlabel result: %d (%s)\n\n",rc,al_error(rc));
+    printf("offset = %d, span = %d\n",off,span);
+
     DUMP("SPLICED",al);
     print("SPLICED", al);
 

CVSTrac 2.0.1