From 5bb5ae987f7dcab00c62edda31d9ce310b7e6f39 Mon Sep 17 00:00:00 2001 From: tth Date: Wed, 30 Oct 2019 11:58:18 +0100 Subject: [PATCH] ltrim & rtrim, to be tested --- files/ffuncs.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ files/ffuncs.h | 10 +++++++++ 2 files changed, 70 insertions(+) create mode 100644 files/ffuncs.c create mode 100644 files/ffuncs.h diff --git a/files/ffuncs.c b/files/ffuncs.c new file mode 100644 index 0000000..064b19a --- /dev/null +++ b/files/ffuncs.c @@ -0,0 +1,60 @@ +/* + * various functions + */ + +#include +#include +#include +#include +#include + +#include "ffuncs.h" + +/* --------------------------------------------------------------------- */ +extern int verbosity; + +/* --------------------------------------------------------------------- */ +void dump(unsigned char *ptr) +{ +int foo; + +for (foo=0; foo<24; foo++) fprintf(stderr, "%02x ", ptr[foo]); +fputs("\n", stderr); +for (foo=0; foo<24; foo++) fprintf(stderr, "%c ", + isgraph(ptr[foo])?ptr[foo]:' '); +fputs("\n", stderr); + +} +/* --------------------------------------------------------------------- */ +char *rtrim(char *src) +{ +int foo = strlen(src)-1; + +for (foo; src[foo]==' '|| src[foo]=='\t'; foo--) { + src[foo] = '\0'; + } + +return src; +} +/* --------------------------------------------------------------------- */ +char *ltrim(char *src) +{ +int foo, bar; +char *tmp; + +tmp = alloca(strlen(src)); + +for (foo=0; src[foo]==' ' || src[foo]=='\t'; foo++); + +bar = 0; +while (src[foo]!='\0') { + tmp[bar]=src[foo]; + foo++; + bar++; + } + +strcpy(src,tmp); + +return src; +} +/* --------------------------------------------------------------------- */ diff --git a/files/ffuncs.h b/files/ffuncs.h new file mode 100644 index 0000000..06dbcee --- /dev/null +++ b/files/ffuncs.h @@ -0,0 +1,10 @@ +/* + * various functions + */ + +void dump(unsigned char *ptr); + +char *rtrim(char *src); +char *ltrim(char *src); + +/* --------------------------------------------------------------------- */