From 1343434e1c21f1ad4441339d1b8a30d2ffe9c268 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Sun, 10 Nov 2002 14:38:50 +0100
Subject: [PATCH] * sexp.h (struct sexp_iterator): New field start.

* sexp.c (sexp_iterator_subexpr): New function.
(sexp_iterator_parse): Initialize ITERATOR->start.

Rev: src/nettle/sexp.c:1.11
Rev: src/nettle/sexp.h:1.8
---
 sexp.c | 15 +++++++++++++++
 sexp.h | 10 +++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/sexp.c b/sexp.c
index 2a49fdcf..b35f9cb1 100644
--- a/sexp.c
+++ b/sexp.c
@@ -99,6 +99,8 @@ sexp_iterator_simple(struct sexp_iterator *iterator,
 static int
 sexp_iterator_parse(struct sexp_iterator *iterator)
 {
+  iterator->start = iterator->pos;
+  
   if (EMPTY(iterator))
     {
       if (iterator->level)
@@ -208,6 +210,19 @@ sexp_iterator_exit_list(struct sexp_iterator *iterator)
   return sexp_iterator_parse(iterator);
 }
 
+const uint8_t *
+sexp_iterator_subexpr(struct sexp_iterator *iterator,
+		      unsigned *length)
+{
+  unsigned start = iterator->start;
+  if (!sexp_iterator_next(iterator))
+    return 0;
+
+  *length = iterator->start - start;
+  return iterator->buffer + start;
+}
+
+
 int
 sexp_iterator_check_type(struct sexp_iterator *iterator,
 			 const uint8_t *type)
diff --git a/sexp.h b/sexp.h
index 21e88eaf..72bbae9c 100644
--- a/sexp.h
+++ b/sexp.h
@@ -36,7 +36,9 @@ struct sexp_iterator
 {
   unsigned length;
   const uint8_t *buffer;
-  
+
+  /* Points at the start of the current sub expression. */
+  unsigned start;
   /* If type is SEXP_LIST, pos points at the start of the current
    * element. Otherwise, it points at the end. */
   unsigned pos;
@@ -75,6 +77,12 @@ sexp_iterator_enter_list(struct sexp_iterator *iterator);
 int
 sexp_iterator_exit_list(struct sexp_iterator *iterator);
 
+/* Gets start and length of the current subexpression. Implies
+ * sexp_iterator_next. */
+const uint8_t *
+sexp_iterator_subexpr(struct sexp_iterator *iterator,
+		      unsigned *length);
+
 
 /* Checks the type of the current expression, which should be a list
  *
-- 
GitLab