From 149e2fb9a29c9cc730f71f0d548d844ccba1c253 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Sun, 10 Jul 2022 18:19:30 -0500 Subject: [PATCH] Replace stdlib string functions with gargoyle equivalents --- include/gargoyle/twine.h | 1 + src/gargoyle.c | 5 ++--- src/twine.c | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/gargoyle/twine.h b/include/gargoyle/twine.h index c52311a..ff542ed 100644 --- a/include/gargoyle/twine.h +++ b/include/gargoyle/twine.h @@ -6,6 +6,7 @@ uint8_t gargoyle_cmp(const char *s1, const char *s2, uint16_t len, gargoyle_flag_type flags); char *gargoyle_cpy(char *dst, const char *src, uint16_t len, gargoyle_flag_type flags); +const char *gargoyle_idx(const char *haystack, char needle); uint8_t gargoyle_is_eql(char lhs, char rhs); uint8_t gargoyle_is_sep(char tok); diff --git a/src/gargoyle.c b/src/gargoyle.c index 3fc7d50..faa34d2 100644 --- a/src/gargoyle.c +++ b/src/gargoyle.c @@ -3,7 +3,6 @@ #include #include #include -#include uint8_t gargoyle_digest_argv(uint16_t optc, struct gargoyle_optn *optv, int *argc, char ***argv, struct gargoyle_err *err, gargoyle_flag_type flags) { if(!(flags & GARGOYLE_FLG_GREED)) { @@ -36,7 +35,7 @@ uint8_t gargoyle_digest_argv(uint16_t optc, struct gargoyle_optn *optv, int *arg if(!optn) { if(flags & GARGOYLE_FLG_STRCT) { - char *eql = index(brand, '='); + const char *eql = gargoyle_idx(brand, '='); GARGOYLE_MK_ERR(err, GARGOYLE_ERR_UNKNOWN_OPTN, "unknown option '--%.*s'", (int) (eql - brand), brand); return err->code; } else { @@ -150,7 +149,7 @@ uint8_t gargoyle_digest_envh(uint16_t optc, struct gargoyle_optn *optv, const ch if(!optn) { if(flags & GARGOYLE_FLG_STRCT) { - char *eql = index(brand, '='); + const char *eql = gargoyle_idx(brand, '='); GARGOYLE_MK_ERR(err, GARGOYLE_ERR_UNKNOWN_OPTN, "unknown variable '%.*s'", (int) (eql - brand), brand); return err->code; } else { diff --git a/src/twine.c b/src/twine.c index a77f07b..dfe050d 100644 --- a/src/twine.c +++ b/src/twine.c @@ -1,6 +1,7 @@ #include #include #include +#include uint8_t gargoyle_cmp(const char *s1, const char *s2, uint16_t len, gargoyle_flag_type flags) { while(*s1 && *s2 && len) { @@ -38,6 +39,16 @@ char *gargoyle_cpy(char *dst, const char *src, uint16_t len, gargoyle_flag_type return dst; } +const char *gargoyle_idx(const char *haystack, char needle) { + for(; haystack; haystack += 1) { + if(*haystack == needle) { + return haystack; + } + } + + return NULL; +} + uint8_t gargoyle_is_eql(char lhs, char rhs) { return tolower(lhs) == tolower(rhs); }