summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@mirocom.org>2026-05-23 01:34:59 -0400
committerIan Moffett <ian@mirocom.org>2026-05-23 01:34:59 -0400
commita356913c397265bc8d9454b0c5dc43c8c898e1b5 (patch)
tree6e524b8a89f0df732673db9378569d04e69c7f4d
parenta371b6ebb05b15a36a5ed2f39105c20e0cd02787 (diff)
build: Add headers
Signed-off-by: Ian Moffett <ian@mirocom.org>
-rw-r--r--.gitignore2
-rw-r--r--include/cescal/readbuf.h49
-rw-r--r--include/cescal/state.h40
3 files changed, 90 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 9c442d3..bed2f9b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
-cescal
+/cescal
*.o
*.d
diff --git a/include/cescal/readbuf.h b/include/cescal/readbuf.h
new file mode 100644
index 0000000..8c7e601
--- /dev/null
+++ b/include/cescal/readbuf.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2026, Chloe M.
+ * Provided under the BSD-3 clause
+ */
+
+#ifndef CESCAL_READBUF_H
+#define CESCAL_READBUF_H 1
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stddef.h>
+
+#define READBUF_CAP 128
+
+/*
+ * Represents a read buffer that reduces system call
+ * overhead.
+ *
+ * @buf: Read buffer
+ * @size: Total populated size of offer
+ * @tail: Tail pointer from start of buffer
+ */
+struct readbuf {
+ char buf[READBUF_CAP];
+ size_t size;
+ size_t tail;
+};
+
+/*
+ * Initialize a read buffer
+ *
+ * @rb: Readbuffer to initialize
+ *
+ * Returns zero on success
+ */
+int readbuf_init(struct readbuf *rb);
+
+/*
+ * Read from a read buffer and populate if needed
+ *
+ * @rb: Target readbuffer
+ * @fd: File descriptor to read from
+ *
+ * Returns the character read on success, '\0' on
+ * failure.
+ */
+char readbuf_read(struct readbuf *rb, int fd);
+
+#endif /* !CESCAL_READBUF_H */
diff --git a/include/cescal/state.h b/include/cescal/state.h
new file mode 100644
index 0000000..c604270
--- /dev/null
+++ b/include/cescal/state.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2026, Chloe M.
+ * Provided under the BSD-3 clause
+ */
+
+#ifndef CESCAL_STATE_H
+#define CESCAL_STATE_H 1
+
+#include <stdint.h>
+#include "cescal/readbuf.h"
+
+/*
+ * Compiler state machine
+ *
+ * @in_fd: Input file descriptor
+ * @rb: Read buffer
+ */
+struct cescal_state {
+ int in_fd;
+ struct readbuf rb;
+};
+
+/*
+ * Initialize the compiler state machine
+ *
+ * @state: Compiler state machine
+ * @pathname: Path of input source file
+ *
+ * Returns zero on success
+ */
+int state_init(struct cescal_state *state, const char *pathname);
+
+/*
+ * Close the compiler state machine
+ *
+ * @state: Compiler state machine to close
+ */
+void state_close(struct cescal_state *state);
+
+#endif /* !CESCAL_STATE_H */