-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.c
144 lines (133 loc) · 2.83 KB
/
util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
** bsflite - bs-free AIM client
**
** (C) 2003-2007 by Claudio Leite <leitec at leitec dot org>
**
** NO WARRANTY. Read the file COPYING for more details.
**/
#include "bsf.h"
/* PROTO */
char *
simplify_sn(const char *sn)
{
char *temp;
int x, count;
temp = malloc(strlen(sn) + 1);
for (x = 0, count = 0; x < strlen(sn); x++) {
if (sn[x] == ' ')
continue;
temp[count] = tolower(sn[x]);
count++;
}
temp = realloc(temp, count + 1);
temp[count] = 0;
return temp;
}
/**
** This differs from strip_html() in that it ignores \n and \r, and
** turns <BR> into \n, so that prettyprint() works properly.
**/
/* PROTO */
char *
strip_html(const char *message)
{
char *temp;
int x, xnot, y, count, inhtml;
size_t len = strlen(message);
temp = malloc(len + 1);
for (x = 0, count = 0, inhtml = 0; x < len; x++) {
if (message[x] == '<' && inhtml == 0) {
if (x + 10 < len) {
/**
** Convert links into
** [http://url] link text
**/
if (strncasecmp(message + x, "<a href=\"", 9) == 0) {
xnot = x + 9;
for (y = xnot; y < len; y++) {
if (message[y] == '\"') {
/*
* we don't have to
* worry about the
* buffer size,
* because it's
* guaranteed to be
* bigger
*/
memcpy(temp + count, "[", 1);
memcpy(temp + count + 1, message + xnot,
y - xnot);
memcpy(temp + count + 1 + (y - xnot), "] ", 2);
count += y - xnot + 3;
x = y;
break;
}
}
}
}
if (x + 3 < len) {
if (strncasecmp(message + x, "<br>", 4) == 0) {
temp[count] = '\n';
count++;
x += 3;
continue;
}
}
inhtml = 1;
continue;
}
if (inhtml) {
if (message[x] == '>')
inhtml = 0;
continue;
}
if (message[x] == '&') {
if (x + 4 < len) {
if (strncmp(message + x, "&", 5) == 0) {
temp[count] = '&';
count++;
x += 4;
continue;
}
}
if (x + 5 < len) {
if (strncmp(message + x, """, 6) == 0) {
temp[count] = '\"';
count++;
x += 5;
continue;
}
if (strncmp(message + x, " ", 6) == 0) {
temp[count] = ' ';
count++;
x += 5;
continue;
}
}
if (x + 3 < len) {
if (strncmp(message + x, "<", 4) == 0) {
temp[count] = '<';
count++;
x += 3;
continue;
}
}
if (x + 3 < len) {
if (strncmp(message + x, ">", 4) == 0) {
temp[count] = '>';
count++;
x += 3;
continue;
}
}
}
if (message[x] == '\n' || message[x] == '\r')
continue;
else
temp[count] = message[x];
count++;
}
temp = realloc(temp, count + 1);
temp[count] = 0;
return temp;
}