]> jfr.im git - irc/rqf/shadowircd.git/commitdiff
untabify function added to cache.c:
authorValery V Yatsko <redacted>
Sat, 28 Jun 2008 07:22:43 +0000 (11:22 +0400)
committerValery V Yatsko <redacted>
Sat, 28 Jun 2008 07:22:43 +0000 (11:22 +0400)
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

src/cache.c

index 708c99eb7cd0300c98707105def61074822d8897..c72b33378d5569099430045134ca7660426f3b9f 100644 (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