Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/dll/aim/toc/util.c
1072 views
1
/*
2
* gaim
3
*
4
* Copyright (C) 1998-1999, Mark Spencer <[email protected]>
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19
*
20
*/
21
22
23
/*
24
* Modified by Nadeem Riaz ([email protected])
25
*
26
* Slight changes to better incorporate into libtoc
27
*/
28
29
#include <errno.h>
30
#include <stdio.h>
31
#include <stdlib.h>
32
#include <stdarg.h>
33
#include <sys/time.h>
34
#include <sys/types.h>
35
#include <sys/stat.h>
36
#include <string.h>
37
#include <sys/wait.h>
38
#include "toc.h"
39
40
void set_state(int i)
41
{
42
state = i;
43
}
44
45
int escape_text(char *msg)
46
{
47
char *c, *cpy;
48
int cnt=0;
49
/* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */
50
if (strlen(msg) > BUF_LEN) {
51
fprintf(stderr, "Warning: truncating message to 2048 bytes\n");
52
msg[2047]='\0';
53
}
54
55
cpy = strdup(msg);
56
c = cpy;
57
while(*c) {
58
switch(*c) {
59
case '{':
60
case '}':
61
case '\\':
62
case '"':
63
msg[cnt++]='\\';
64
/* Fall through */
65
default:
66
msg[cnt++]=*c;
67
}
68
c++;
69
}
70
msg[cnt]='\0';
71
free(cpy);
72
return cnt;
73
}
74
75
76
int escape_message(char *msg)
77
{
78
char *c, *cpy;
79
int cnt=0;
80
/* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */
81
if (strlen(msg) > BUF_LEN) {
82
toc_debug_printf("Warning: truncating message to 2048 bytes\n");
83
msg[2047]='\0';
84
}
85
86
cpy = strdup(msg);
87
c = cpy;
88
while(*c) {
89
switch(*c) {
90
case '$':
91
case '[':
92
case ']':
93
case '(':
94
case ')':
95
case '#':
96
msg[cnt++]='\\';
97
/* Fall through */
98
default:
99
msg[cnt++]=*c;
100
}
101
c++;
102
}
103
msg[cnt]='\0';
104
free(cpy);
105
return cnt;
106
}
107
108
char *normalize(char *s)
109
{
110
static char buf[BUF_LEN];
111
char *t, *u;
112
int x=0;
113
114
u = t = malloc(strlen(s) + 1);
115
116
strcpy(t, s);
117
strdown(t);
118
119
while(*t) {
120
if (*t != ' ') {
121
buf[x] = *t;
122
x++;
123
}
124
t++;
125
}
126
buf[x]='\0';
127
free(u);
128
return buf;
129
}
130
131
void strdown(char *s) {
132
while ( *s ) {
133
if ( *s >= 65 && *s <= 90)
134
*s += 32;
135
s++;
136
}
137
}
138
139
void toc_debug_printf(char *fmt, ...)
140
{
141
#ifdef DEBUG_LIB_TOC
142
FILE *fp;
143
char data[MAX_OUTPUT_MSG_LEN];
144
va_list ptr;
145
if ( ! (fp=fopen(TOC_DEBUG_LOG,"a")) ) {
146
perror("ERROR couldn't open debug log file!@$\n");
147
}
148
va_start(ptr, fmt);
149
vsnprintf(data, MAX_OUTPUT_MSG_LEN - 1 , fmt, ptr);
150
va_end(ptr);
151
fprintf(fp,"%s\n",data);
152
fflush(fp);
153
fclose(fp);
154
return;
155
#endif
156
}
157
158
void toc_msg_printf(int type, char *fmt, ...) {
159
char data[MAX_OUTPUT_MSG_LEN];
160
char *args[1];
161
va_list ptr;
162
va_start(ptr, fmt);
163
vsnprintf(data, MAX_OUTPUT_MSG_LEN - 1 , fmt, ptr);
164
va_end(ptr);
165
args[0] = data;
166
use_handler(TOC_HANDLE,type,args);
167
return;
168
}
169
170
char * strip_html(char * text)
171
{
172
int i, j;
173
int visible = 1;
174
char *text2 = malloc(strlen(text) + 1);
175
176
strcpy(text2, text);
177
for (i = 0, j = 0;text2[i]; i++)
178
{
179
if(text2[i]=='<')
180
{
181
visible = 0;
182
continue;
183
}
184
else if(text2[i]=='>')
185
{
186
visible = 1;
187
continue;
188
}
189
if(visible)
190
{
191
text2[j++] = text2[i];
192
}
193
}
194
text2[j] = '\0';
195
return text2;
196
}
197
198
199