Replace stdlib string functions with gargoyle equivalents
This commit is contained in:
parent
941af4e4cd
commit
149e2fb9a2
3 changed files with 14 additions and 3 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
uint8_t gargoyle_cmp(const char *s1, const char *s2, uint16_t len, gargoyle_flag_type flags);
|
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);
|
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_eql(char lhs, char rhs);
|
||||||
uint8_t gargoyle_is_sep(char tok);
|
uint8_t gargoyle_is_sep(char tok);
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#include <gargoyle/sleuth.h>
|
#include <gargoyle/sleuth.h>
|
||||||
#include <gargoyle/twine.h>
|
#include <gargoyle/twine.h>
|
||||||
#include <stddef.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) {
|
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)) {
|
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(!optn) {
|
||||||
if(flags & GARGOYLE_FLG_STRCT) {
|
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);
|
GARGOYLE_MK_ERR(err, GARGOYLE_ERR_UNKNOWN_OPTN, "unknown option '--%.*s'", (int) (eql - brand), brand);
|
||||||
return err->code;
|
return err->code;
|
||||||
} else {
|
} else {
|
||||||
|
@ -150,7 +149,7 @@ uint8_t gargoyle_digest_envh(uint16_t optc, struct gargoyle_optn *optv, const ch
|
||||||
|
|
||||||
if(!optn) {
|
if(!optn) {
|
||||||
if(flags & GARGOYLE_FLG_STRCT) {
|
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);
|
GARGOYLE_MK_ERR(err, GARGOYLE_ERR_UNKNOWN_OPTN, "unknown variable '%.*s'", (int) (eql - brand), brand);
|
||||||
return err->code;
|
return err->code;
|
||||||
} else {
|
} else {
|
||||||
|
|
11
src/twine.c
11
src/twine.c
|
@ -1,6 +1,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <gargoyle/codex.h>
|
#include <gargoyle/codex.h>
|
||||||
#include <gargoyle/twine.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) {
|
uint8_t gargoyle_cmp(const char *s1, const char *s2, uint16_t len, gargoyle_flag_type flags) {
|
||||||
while(*s1 && *s2 && len) {
|
while(*s1 && *s2 && len) {
|
||||||
|
@ -38,6 +39,16 @@ char *gargoyle_cpy(char *dst, const char *src, uint16_t len, gargoyle_flag_type
|
||||||
return dst;
|
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) {
|
uint8_t gargoyle_is_eql(char lhs, char rhs) {
|
||||||
return tolower(lhs) == tolower(rhs);
|
return tolower(lhs) == tolower(rhs);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue