NcLooper/files/ffuncs.c

62 lines
1.2 KiB
C
Raw Normal View History

2019-10-30 21:58:18 +11:00
/*
* various functions
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include "ffuncs.h"
/* --------------------------------------------------------------------- */
2019-11-01 01:47:54 +11:00
2019-10-30 21:58:18 +11:00
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)
{
2019-11-01 01:47:54 +11:00
int foo;
2019-10-30 21:58:18 +11:00
2019-11-01 01:47:54 +11:00
for (foo=strlen(src)-1; src[foo]==' '|| src[foo]=='\t'; foo--) {
2019-10-30 21:58:18 +11:00
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++;
}
2019-11-01 01:47:54 +11:00
strcpy(src, tmp);
2019-10-30 21:58:18 +11:00
return src;
}
/* --------------------------------------------------------------------- */