Replace stdlib string functions with gargoyle equivalents

This commit is contained in:
Nick Chambers 2022-07-10 18:19:30 -05:00
parent 941af4e4cd
commit 149e2fb9a2
3 changed files with 14 additions and 3 deletions

View File

@ -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);

View File

@ -3,7 +3,6 @@
#include <gargoyle/sleuth.h>
#include <gargoyle/twine.h>
#include <stddef.h>
#include <strings.h>
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 {

View File

@ -1,6 +1,7 @@
#include <ctype.h>
#include <gargoyle/codex.h>
#include <gargoyle/twine.h>
#include <stddef.h>
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);
}