- help_dict_user = irc_dictionary_create(strcasecmp);\r
-}\r
-\r
-/* cache_file()\r
- *\r
- * inputs - file to cache, files "shortname", flags to set\r
- * outputs - pointer to file cached, else NULL\r
- * side effects -\r
- */\r
-struct cachefile *\r
-cache_file(const char *filename, const char *shortname, int flags)\r
-{\r
- FILE *in;\r
- struct cachefile *cacheptr;\r
- struct cacheline *lineptr;\r
- char line[BUFSIZE];\r
- char *p;\r
-\r
- if((in = fopen(filename, "r")) == NULL)\r
- return NULL;\r
-\r
-\r
- cacheptr = rb_malloc(sizeof(struct cachefile));\r
-\r
- rb_strlcpy(cacheptr->name, shortname, sizeof(cacheptr->name));\r
- cacheptr->flags = flags;\r
-\r
- /* cache the file... */\r
- while(fgets(line, sizeof(line), in) != NULL)\r
- {\r
- if((p = strpbrk(line, "\r\n")) != NULL)\r
- *p = '\0';\r
-\r
- if(!EmptyString(line))\r
- {\r
- lineptr = rb_malloc(sizeof(struct cacheline));\r
- rb_strlcpy(lineptr->data, line, sizeof(lineptr->data));\r
- rb_dlinkAddTail(lineptr, &lineptr->linenode, &cacheptr->contents);\r
- }\r
- else\r
- rb_dlinkAddTailAlloc(emptyline, &cacheptr->contents);\r
- }\r
-\r
- fclose(in);\r
- return cacheptr;\r
-}\r
-\r
-void\r
-cache_links(void *unused)\r
-{\r
- struct Client *target_p;\r
- rb_dlink_node *ptr;\r
- rb_dlink_node *next_ptr;\r
- char *links_line;\r
-\r
- RB_DLINK_FOREACH_SAFE(ptr, next_ptr, links_cache_list.head)\r
- {\r
- rb_free(ptr->data);\r
- rb_free_rb_dlink_node(ptr);\r
- }\r
-\r
- links_cache_list.head = links_cache_list.tail = NULL;\r
- links_cache_list.length = 0;\r
-\r
- RB_DLINK_FOREACH(ptr, global_serv_list.head)\r
- {\r
- target_p = ptr->data;\r
-\r
- /* skip ourselves (done in /links) and hidden servers */\r
- if(IsMe(target_p) ||\r
- (IsHidden(target_p) && !ConfigServerHide.disable_hidden))\r
- continue;\r
-\r
- /* if the below is ever modified, change LINKSLINELEN */\r
- links_line = rb_malloc(LINKSLINELEN);\r
- rb_snprintf(links_line, LINKSLINELEN, "%s %s :1 %s",\r
- target_p->name, me.name, \r
- target_p->info[0] ? target_p->info : \r
- "(Unknown Location)");\r
-\r
- rb_dlinkAddTailAlloc(links_line, &links_cache_list);\r
- }\r
-}\r
-\r
-/* free_cachefile()\r
- *\r
- * inputs - cachefile to free\r
- * outputs -\r
- * side effects - cachefile and its data is free'd\r
- */\r
-void\r
-free_cachefile(struct cachefile *cacheptr)\r
-{\r
- rb_dlink_node *ptr;\r
- rb_dlink_node *next_ptr;\r
-\r
- if(cacheptr == NULL)\r
- return;\r
-\r
- RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head)\r
- {\r
- if(ptr->data != emptyline)\r
- rb_free(ptr->data);\r
- }\r
-\r
- rb_free(cacheptr);\r
-}\r
-\r
+ 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
+ * outputs - pointer to file cached, else NULL
+ * side effects -
+ */
+struct cachefile *
+cache_file(const char *filename, const char *shortname, int flags)
+{
+ FILE *in;
+ struct cachefile *cacheptr;
+ struct cacheline *lineptr;
+ char line[BUFSIZE];
+ char *p;
+
+ if((in = fopen(filename, "r")) == NULL)
+ return NULL;
+
+
+ cacheptr = rb_malloc(sizeof(struct cachefile));
+
+ rb_strlcpy(cacheptr->name, shortname, sizeof(cacheptr->name));
+ cacheptr->flags = flags;
+
+ /* cache the file... */
+ while(fgets(line, sizeof(line), in) != NULL)
+ {
+ if((p = strpbrk(line, "\r\n")) != NULL)
+ *p = '\0';
+
+ if(!EmptyString(line))
+ {
+ lineptr = rb_malloc(sizeof(struct cacheline));
+ rb_strlcpy(lineptr->data, line, sizeof(lineptr->data));
+ rb_dlinkAddTail(lineptr, &lineptr->linenode, &cacheptr->contents);
+ }
+ else
+ rb_dlinkAddTailAlloc(emptyline, &cacheptr->contents);
+ }
+
+ fclose(in);
+ return cacheptr;
+}
+
+void
+cache_links(void *unused)
+{
+ struct Client *target_p;
+ rb_dlink_node *ptr;
+ rb_dlink_node *next_ptr;
+ char *links_line;
+
+ RB_DLINK_FOREACH_SAFE(ptr, next_ptr, links_cache_list.head)
+ {
+ rb_free(ptr->data);
+ rb_free_rb_dlink_node(ptr);
+ }
+
+ links_cache_list.head = links_cache_list.tail = NULL;
+ links_cache_list.length = 0;
+
+ RB_DLINK_FOREACH(ptr, global_serv_list.head)
+ {
+ target_p = ptr->data;
+
+ /* skip ourselves (done in /links) and hidden servers */
+ if(IsMe(target_p) ||
+ (IsHidden(target_p) && !ConfigServerHide.disable_hidden))
+ continue;
+
+ /* if the below is ever modified, change LINKSLINELEN */
+ links_line = rb_malloc(LINKSLINELEN);
+ rb_snprintf(links_line, LINKSLINELEN, "%s %s :1 %s",
+ target_p->name, me.name,
+ target_p->info[0] ? target_p->info :
+ "(Unknown Location)");
+
+ rb_dlinkAddTailAlloc(links_line, &links_cache_list);
+ }
+}
+
+/* free_cachefile()
+ *
+ * inputs - cachefile to free
+ * outputs -
+ * side effects - cachefile and its data is free'd
+ */
+void
+free_cachefile(struct cachefile *cacheptr)
+{
+ rb_dlink_node *ptr;
+ rb_dlink_node *next_ptr;
+
+ if(cacheptr == NULL)
+ return;
+
+ RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head)
+ {
+ if(ptr->data != emptyline)
+ rb_free(ptr->data);
+ }
+
+ rb_free(cacheptr);
+}
+