summary refs log tree commit diff
path: root/ring.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ring.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/ring.c b/ring.c
index 40fb7df..ff83cea 100644
--- a/ring.c
+++ b/ring.c
@@ -38,3 +38,28 @@ void ringWrite(const char *line) {
 	ring.lines[i] = strdup(line);
 	if (!ring.lines[i]) err(EX_OSERR, "strdup");
 }
+
+static struct {
+	char **names;
+	size_t *reads;
+	size_t cap, len;
+} reader;
+
+size_t ringReader(const char *name) {
+	for (size_t i = 0; i < reader.len; ++i) {
+		if (!strcmp(reader.names[i], name)) return i;
+	}
+
+	if (reader.len == reader.cap) {
+		reader.cap = (reader.cap ? reader.cap * 2 : 8);
+		reader.names = realloc(reader.names, sizeof(*reader.names) * reader.cap);
+		if (!reader.names) err(EX_OSERR, "realloc");
+		reader.reads = realloc(reader.reads, sizeof(*reader.reads) * reader.cap);
+		if (!reader.reads) err(EX_OSERR, "realloc");
+	}
+
+	reader.names[reader.len] = strdup(name);
+	if (!reader.names[reader.len]) err(EX_OSERR, "strdup");
+	reader.reads[reader.len] = 0;
+	return reader.len++;
+}