aboutsummaryrefslogtreecommitdiff
path: root/client/parse.h
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-05-24 17:47:00 +0200
committerlonkaars <loek@pipeframe.xyz>2024-05-24 17:47:00 +0200
commit1a92ed5075aba4b41fe34422d21a2c66cdf1d4c9 (patch)
treea66d2dae13ab7c214da7b9ccf4701f0b7817c2e5 /client/parse.h
parent31c30df2a24a45c69a7c5c2f594fa3a9a835b1fb (diff)
WIP `send` command
Diffstat (limited to 'client/parse.h')
-rw-r--r--client/parse.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/client/parse.h b/client/parse.h
new file mode 100644
index 0000000..ac06446
--- /dev/null
+++ b/client/parse.h
@@ -0,0 +1,38 @@
+#pragma once
+
+#include <stddef.h>
+
+#define IFS " \t\n"
+
+/**
+ * \brief modify \p token to point to the first token when broken up on \p ifs
+ * and return the remaining data
+ *
+ * \p token will be null-terminated to indicate the end of the first token. A
+ * pointer to the remaining line after the NULL byte is returned, or NULL when
+ * the end of the string has been reached.
+ *
+ * \param token input string
+ * \param ifs string containing field separators
+ *
+ * \return the remaining data after \p token and the first \p ifs
+ */
+char* consume_token(char* token, const char* ifs);
+
+/**
+ * \brief convert string with literals into raw data
+ *
+ * \param str input string containing literals
+ * \param data pointer to \c char* that will store the resulting data
+ * \param size size of \p data
+ *
+ * \return 0 if the string was parsed succesfully, or 1 if the string could not
+ * be parsed succesfully
+ *
+ * \note The pointer that \p data refers to will not be initialized by this
+ * function if parsing fails
+ * \note \p size will contain the index of \p str where the first invalid data
+ * was found if parsing fails
+ */
+int strtodata(const char* str, char** data, size_t* size);
+