untabify function added to cache.c:

removes tabs from src, replaces with 8 spaces, and returns the length
of the new string.  if the new string would be greater than destlen,
it is truncated to destlen - 1
This commit is contained in:
Valery V Yatsko 2008-06-28 11:22:43 +04:00
parent 4b6a4d479c
commit 22b98b1ed1

View file

@ -74,6 +74,35 @@ init_cache(void)
help_dict_user = irc_dictionary_create(strcasecmp);
}
/*
* removes tabs from src, replaces with 8 spaces, and returns the length
* of the new string. if the new string would be greater than destlen,
* it is truncated to destlen - 1
*/
static size_t
untabify(char *dest, const char *src, size_t destlen)
{
size_t x = 0, i;
const char *s = src;
char *d = dest;
while(*s != '\0' && x < destlen - 1)
{
if(*s == '\t')
{
for(i = 0; i < 8 && x < destlen - 1; i++, x++, d++)
*d = ' ';
s++;
} else
{
*d++ = *s++;
x++;
}
}
*d = '\0';
return x;
}
/* cache_file()
*
* inputs - file to cache, files "shortname", flags to set