From d0c15a0c90e183ad183a2ee91ed2426eace8472a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Sun, 6 Oct 2002 23:11:33 +0200 Subject: [PATCH] * sexp.c (sexp_iterator_next): Updated to new sexp_iterator_exit_list. (sexp_iterator_exit_list): Return with iterator pointing to the element after the list. (sexp_iterator_check_type): Call sexp_iterator_next before returning. (sexp_iterator_check_types): Likewise. (sexp_iterator_assoc): Rearranged calls of sexp_iterator_next. Rev: src/nettle/sexp.c:1.7 --- sexp.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/sexp.c b/sexp.c index 03d41224..ba2a8f83 100644 --- a/sexp.c +++ b/sexp.c @@ -120,8 +120,7 @@ sexp_iterator_next(struct sexp_iterator *iterator) if (iterator->type == SEXP_LIST) /* Skip this list */ return sexp_iterator_enter_list(iterator) - && sexp_iterator_exit_list(iterator) - && sexp_iterator_next(iterator); + && sexp_iterator_exit_list(iterator); else { iterator->type = SEXP_LIST; @@ -183,18 +182,14 @@ sexp_iterator_exit_list(struct sexp_iterator *iterator) if (!iterator->level) return 0; - for (;;) - { - if (!sexp_iterator_next(iterator)) - return 0; + while(iterator->type != SEXP_END) + if (!sexp_iterator_next(iterator)) + return 0; - if (iterator->type == SEXP_END) - { - iterator->type = SEXP_START; - iterator->level--; - return 1; - } - } + iterator->type = SEXP_START; + iterator->level--; + + return sexp_iterator_next(iterator); } int @@ -205,7 +200,8 @@ sexp_iterator_check_type(struct sexp_iterator *iterator, && iterator->type == SEXP_ATOM && !iterator->display && strlen(type) == iterator->atom_length - && !memcmp(type, iterator->atom, iterator->atom_length)); + && !memcmp(type, iterator->atom, iterator->atom_length) + && sexp_iterator_next(iterator)); } const uint8_t * @@ -222,9 +218,9 @@ sexp_iterator_check_types(struct sexp_iterator *iterator, if (strlen(types[i]) == iterator->atom_length && !memcmp(types[i], iterator->atom, iterator->atom_length)) - return types[i]; + return sexp_iterator_next(iterator) ? types[i] : NULL; } - return 0; + return NULL; } @@ -285,6 +281,8 @@ sexp_iterator_assoc(struct sexp_iterator *iterator, break; case SEXP_ATOM: /* Just ignore */ + if (!sexp_iterator_next(iterator)) + return 0; break; case SEXP_END: @@ -294,7 +292,5 @@ sexp_iterator_assoc(struct sexp_iterator *iterator, default: abort(); } - if (!sexp_iterator_next(iterator)) - return 0; } } -- GitLab