]> jfr.im git - irc/quakenet/newserv.git/blame - helpmod2/htopic.c
r657@blue (orig r496): slug | 2006-05-16 00:09:51 +0100
[irc/quakenet/newserv.git] / helpmod2 / htopic.c
CommitLineData
c86edd1d
Q
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include "../lib/sstring.h"
6
7#include "htopic.h"
8
9htopic *htopic_add(htopic** htop, const char* entry, int pos)
10{
11 htopic *tmp;
12
13 for (;*htop && pos;htop = &(*htop)->next, pos--);
14
15 tmp = *htop;
16
17 *htop = malloc(sizeof(htopic));
18 (*htop)->entry = getsstring(entry, strlen(entry));
19 (*htop)->next = tmp;
20
21 return *htop;
22}
23
24htopic *htopic_del(htopic** htop, htopic* target)
25{
26 htopic *tmp;
27 for (;*htop;htop = &(*htop)->next)
28 if (*htop == target)
29 break;
30 if (!*htop)
31 return target;
32 tmp = (*htop)->next;
33 freesstring((*htop)->entry);
34 free(*htop);
35 *htop = tmp;
36
37
38 return NULL;
39}
40
41void htopic_del_all(htopic** htop)
42{
43 while (*htop)
44 htopic_del(htop, *htop);
45}
46
47htopic *htopic_get(htopic *htop, int pos)
48{
49 for (;htop && pos;htop = htop->next,pos--);
50 return htop;
51}
52
53const char *htopic_construct(htopic *htop)
54{
55 static char buffer[512] = "";
56
57 *buffer = '\0';
58
59 for (;htop;htop = htop->next)
60 {
61 strcat(buffer, htop->entry->content);
62 if (htop->next)
63 strcat(buffer, " | ");
64 }
65 return buffer;
66}
67
68int htopic_count(htopic *htop)
69{
70 int count = 0;
71 for (;htop;htop = htop->next)
72 count++;
73 return count;
74}
75
76int htopic_len(htopic *htop)
77{
78 int len = 0;
79
80 if (htopic_count(htop))
81 len+=(htopic_count(htop) - 1) * 3;
82 for (;htop;htop = htop->next)
83 len+=strlen(htop->entry->content);
84
85 return len;
86}
87