summaryrefslogtreecommitdiff
path: root/demo/util.c
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2023-10-04 00:36:34 -0600
committerAlejandro Soto <alejandro@34project.org>2023-10-04 00:36:38 -0600
commitb3555efa723d0b7101ea6989dc04492eca6b8745 (patch)
tree65217cf306fe30225cbd88653bdec96ef9275513 /demo/util.c
parent3de42a19661a3d6d24de46ca2920b06e1dc88fe0 (diff)
demo: implement cli input
Diffstat (limited to 'demo/util.c')
-rw-r--r--demo/util.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/demo/util.c b/demo/util.c
index 457a32c..99566bd 100644
--- a/demo/util.c
+++ b/demo/util.c
@@ -1,3 +1,7 @@
+#include <stddef.h>
+
+#include "demo.h"
+
int strcmp(const char *s1, const char *s2)
{
while (*s1 && *s1 == *s2)
@@ -5,3 +9,24 @@ int strcmp(const char *s1, const char *s2)
return (int)*(const unsigned char *)s1 - (int)*(const unsigned char *)s2;
}
+
+char *strtok_input(char **tokens)
+{
+ char *start = *tokens;
+ while (*start && *start == ' ')
+ ++start;
+
+ if (!*start) {
+ *tokens = start;
+ return NULL;
+ }
+
+ char *end = start + 1;
+ while (*end && *end != ' ')
+ ++end;
+
+ *tokens = *end ? end + 1 : end;
+ *end = '\0';
+
+ return start;
+}