aboutsummaryrefslogtreecommitdiff
path: root/src/sdl/warp-buf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sdl/warp-buf.c')
-rw-r--r--src/sdl/warp-buf.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/sdl/warp-buf.c b/src/sdl/warp-buf.c
new file mode 100644
index 0000000..5168c7f
--- /dev/null
+++ b/src/sdl/warp-buf.c
@@ -0,0 +1,52 @@
+#include <stdbool.h>
+#include "warp-buf.h"
+
+void
+warp_buf_clear(
+ warp_buf_t * const buf
+) {
+ buf->len = 0;
+ buf->dst = 0;
+}
+
+bool
+warp_buf_has_num(
+ const warp_buf_t * const buf
+) {
+ return buf->len > 0;
+}
+
+void
+warp_buf_push_num(
+ warp_buf_t * const buf,
+ const size_t num
+) {
+ buf->dst = buf->dst * 10 + num;
+ buf->len++;
+}
+
+void
+warp_buf_pop_num(
+ warp_buf_t * const buf
+) {
+ if (buf->len > 0) {
+ buf->len--;
+ buf->dst /= 10;
+ }
+}
+
+bool
+warp_buf_get(
+ const warp_buf_t * const buf,
+ size_t * const r
+) {
+ if (!buf->len) {
+ return false;
+ }
+
+ if (r) {
+ *r = buf->dst;
+ }
+
+ return true;
+}