ltrim & rtrim, to be tested

This commit is contained in:
Tonton Th 2019-10-30 11:58:18 +01:00
parent d721ea674c
commit 5bb5ae987f
2 changed files with 70 additions and 0 deletions

60
files/ffuncs.c Normal file
View File

@ -0,0 +1,60 @@
/*
* various functions
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#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;
}
/* --------------------------------------------------------------------- */

10
files/ffuncs.h Normal file
View File

@ -0,0 +1,10 @@
/*
* various functions
*/
void dump(unsigned char *ptr);
char *rtrim(char *src);
char *ltrim(char *src);
/* --------------------------------------------------------------------- */