--- /dev/null
+/* Gateway utility
+ * Europagate, 1995
+ *
+ * $Log: strqueue.h,v $
+ * Revision 1.1 1995/03/28 11:42:23 adam
+ * First version of string-queue utility.
+ *
+ */
+
+#ifndef STRQUEUE_H
+#define STRQUEUE_H
+struct str_queue {
+ struct str_entry *first;
+ struct str_entry *last;
+};
+
+struct str_queue *str_queue_mk (void);
+void str_queue_rm (struct str_queue **sq);
+char *str_queue_enq (struct str_queue *sq, const char *msg);
+int str_queue_deq (struct str_queue *sq, char *dst, int max);
+char *str_queue_get (struct str_queue *sq, int index);
+#endif
# Europagate, 1995
#
# $Log: Makefile,v $
-# Revision 1.10 1995/03/27 12:52:18 adam
+# Revision 1.11 1995/03/28 11:42:41 adam
+# First version of string-queue utility.
+#
+# Revision 1.10 1995/03/27 12:52:18 adam
# A little more verbose in marc dump.
#
# Revision 1.9 1995/03/27 08:24:57 adam
TPROG1=iso2709dump
TPROG2=gwdbtest
LIB=../lib/util.a
-PO=iso2709.o iso27dis.o gw-db.o gip.o gips.o gipc.o
+PO=iso2709.o iso27dis.o gw-db.o gip.o gips.o gipc.o strqueue.o
CPP=$(CC) -E
DEFS=$(INCLUDE) -DSTUPID_ISO_DBC=1
--- /dev/null
+/* Gateway utility
+ * Europagate, 1995
+ *
+ * $Log: strqueue.c,v $
+ * Revision 1.1 1995/03/28 11:42:41 adam
+ * First version of string-queue utility.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+
+#include <strqueue.h>
+
+struct str_entry {
+ char *buf;
+ struct str_entry *prev;
+};
+
+struct str_queue *str_queue_mk (void)
+{
+ struct str_queue *sq;
+
+ sq = malloc (sizeof(*sq));
+ if (!sq)
+ return NULL;
+ sq->first = NULL;
+ sq->last = NULL;
+ return sq;
+}
+
+void str_queue_rm (struct str_queue **sq)
+{
+ free (*sq);
+ *sq = NULL;
+}
+
+char *str_queue_enq (struct str_queue *sq, const char *msg)
+{
+ struct str_entry *n;
+
+ assert (sq);
+ assert (msg);
+ n = malloc (sizeof(*n));
+ if (!n)
+ return NULL;
+ n->buf = malloc (strlen(msg)+1);
+ if (!n->buf)
+ {
+ free (n);
+ return NULL;
+ }
+ strcpy (n->buf, msg);
+ n->prev = NULL;
+ if (!sq->first)
+ sq->last = n;
+ else
+ sq->first->prev = n;
+ sq->first = n;
+ return n->buf;
+}
+
+char *str_queue_get (struct str_queue *sq, int index)
+{
+ struct str_entry *n;
+
+ assert (sq);
+ for (n = sq->last; n && index > 0; --index)
+ n = n->prev;
+ if (!n)
+ return NULL;
+ return n->buf;
+}
+
+int str_queue_deq (struct str_queue *sq, char *dst, int max)
+{
+ struct str_entry *n;
+
+ assert (sq);
+ if (!(n = sq->last))
+ return 0;
+ sq->last = n->prev;
+ if (!sq->last)
+ sq->first = NULL;
+ if (dst && max > 1)
+ {
+ strncpy (dst, n->buf, max-1);
+ dst[max-1] = '\0';
+ }
+ free (n->buf);
+ free (n);
+ return 1;
+}