--- al.c 2002/10/23 13:59:30 1.30
+++ al.c 2002/10/23 16:49:29 1.31
@@ -579,7 +579,7 @@
al_chunk_t *cur;
/* argument sanity check(s) */
- if (al == NULL || p == NULL || n < 0)
+ if (al == NULL || p == NULL || n <= 0)
return AL_RC(AL_ERR_ARG);
rc = make_buffer(al, p, n, freemem, u, &buf);
@@ -874,12 +874,27 @@
tx->view.end = tx->view.begin + step;
switch (tx->dir) {
+ case AL_FORWARD:
+ case AL_BACKWARD:
+ break;
+ case AL_FORWARD_SPAN:
+ case AL_BACKWARD_SPAN:
+ if (!AL_SAME_LABEL(&tx->view, tx->label)) {
+ tx->togo = 0;
+ return AL_ERR_EOF;
+ }
+ break;
+ }
+
+ switch (tx->dir) {
case AL_FORWARD:
+ case AL_FORWARD_SPAN:
tx->cur = NEXT(tx->cur,chunks);
tx->togo -= step;
tx->skip = 0;
break;
case AL_BACKWARD:
+ case AL_BACKWARD_SPAN:
tx->cur = PREV(tx->cur,chunks);
tx->togo -= step;
tx->skip = 0;
@@ -948,7 +963,7 @@
* traversal context is kept on stack (XXX ?)
*/
al_rc_t
-al_flatten(al_t *al, size_t off, size_t n, al_label_t label,
+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 rc;
@@ -958,20 +973,42 @@
*lenp = 0; /* keep caller on safe side */
- rc = al_traverse(al, off, n, AL_FORWARD, label, &tx);
+ rc = al_traverse(al, off, n, dir, label, &tx);
if (rc != AL_OK)
return AL_RC(rc);
+ switch (dir) {
+ case AL_FORWARD:
+ case AL_FORWARD_SPAN:
+ break;
+ case AL_BACKWARD:
+ case AL_BACKWARD_SPAN:
+ dst += n;
+ break;
+ }
+
total = 0;
- while ((rc = al_traverse_next(al, &tx, &view)) == AL_OK) {
- step = AL_CHUNK_LEN(view);
- if (dst != NULL) {
- memmove(dst, AL_CHUNK_PTR(view, 0), step);
- dst += step;
+ if (dst == NULL) {
+ while ((rc = al_traverse_next(al, &tx, &view)) == AL_OK)
+ total += AL_CHUNK_LEN(view);
+ } else {
+ while ((rc = al_traverse_next(al, &tx, &view)) == AL_OK) {
+ step = AL_CHUNK_LEN(view);
+ switch (dir) {
+ case AL_FORWARD:
+ case AL_FORWARD_SPAN:
+ memmove(dst, AL_CHUNK_PTR(view, 0), step);
+ dst += step;
+ break;
+ case AL_BACKWARD:
+ case AL_BACKWARD_SPAN:
+ dst -= step;
+ memmove(dst, AL_CHUNK_PTR(view, 0), step);
+ break;
+ }
+ total += step;
}
-
- total += step;
}
*lenp = total;
@@ -1014,6 +1051,31 @@
}
/*
+ * traverse assembly line and retrieve first chunk
+ *
+ * traversal context is kept on stack (XXX ?)
+ */
+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 rc;
+ al_tx_t tx; /* XXX - private tx structure on stack */
+ al_chunk_t *view;
+
+ rc = al_traverse(al, off, n, dir, label, &tx);
+ if (rc != AL_OK)
+ return AL_RC(rc);
+
+ if ((rc = al_traverse_next(al, &tx, &view)) == AL_OK)
+ *labelp = AL_CHUNK_LABEL(view);
+
+ al_traverse_end(al, &tx, 1);
+
+ return rc;
+}
+
+/*
* relay macros to caller
*
* al_bytes - total number of bytes in assembly line
|