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:
parent
4b6a4d479c
commit
22b98b1ed1
1 changed files with 29 additions and 0 deletions
29
src/cache.c
29
src/cache.c
|
@ -74,6 +74,35 @@ init_cache(void)
|
||||||
help_dict_user = irc_dictionary_create(strcasecmp);
|
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()
|
/* cache_file()
|
||||||
*
|
*
|
||||||
* inputs - file to cache, files "shortname", flags to set
|
* inputs - file to cache, files "shortname", flags to set
|
||||||
|
|
Loading…
Reference in a new issue