summaryrefslogtreecommitdiff
path: root/sexp.h
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2002-09-28 15:54:57 +0200
committerNiels Möller <nisse@lysator.liu.se>2002-09-28 15:54:57 +0200
commit7f88bfbee14bf1a8a0dd01d4f3ac21204a22ac31 (patch)
treebf9fb55c6f02027224c0642d8d83a5b4324b9014 /sexp.h
parent4460c97ebff0b3260a200a1bf881c3859e26a050 (diff)
downloadnettle-7f88bfbee14bf1a8a0dd01d4f3ac21204a22ac31.tar.gz
New files, implementing an sexp-parser.
Rev: src/nettle/sexp.c:1.1 Rev: src/nettle/sexp.h:1.1
Diffstat (limited to 'sexp.h')
-rw-r--r--sexp.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/sexp.h b/sexp.h
new file mode 100644
index 00000000..b751b0c2
--- /dev/null
+++ b/sexp.h
@@ -0,0 +1,87 @@
+/* sexp.h
+ *
+ * Parsing s-expressions.
+ */
+
+/* nettle, low-level cryptographics library
+ *
+ * Copyright (C) 2002 Niels Möller
+ *
+ * The nettle library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * The nettle library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the nettle library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#ifndef NETTLE_SEXP_H_INCLUDED
+#define NETTLE_SEXP_H_INCLUDED
+
+#include <inttypes.h>
+
+enum sexp_type
+ { SEXP_START, SEXP_ATOM, SEXP_LIST, SEXP_END };
+
+struct sexp_iterator
+{
+ unsigned length;
+ const uint8_t *buffer;
+ unsigned pos;
+ unsigned level;
+
+ enum sexp_type type;
+
+ unsigned display_length;
+ const uint8_t *display;
+
+ unsigned atom_length;
+ const uint8_t *atom;
+};
+
+struct sexp_assoc_key
+{
+ unsigned length;
+ const uint8_t *name;
+};
+
+/* Initializes the iterator. You have to call next to get to the first
+ * element. */
+void
+sexp_iterator_init(struct sexp_iterator *iterator,
+ unsigned length, const uint8_t *input);
+
+/* All these functions return 1 on success, 0 on failure */
+int
+sexp_iterator_next(struct sexp_iterator *iterator);
+
+/* Current element must be a list. */
+int
+sexp_iterator_enter_list(struct sexp_iterator *iterator);
+
+/* Skips the rest of the current list */
+int
+sexp_iterator_exit_list(struct sexp_iterator *iterator);
+
+/* Current element must be a list. Looks up element of type
+ *
+ * (key rest...)
+ *
+ * For a matching key, the corersponding iterator is initialized
+ * pointing at the start of REST.
+ */
+int
+sexp_iterator_assoc(struct sexp_iterator *iterator,
+ unsigned nkeys,
+ const struct sexp_assoc_key *keys,
+ struct sexp_iterator *values);
+
+#endif /* NETTLE_SEXP_H_INCLUDED */