Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/source/hebrew.c
1069 views
1
/*
2
* hebrew.c
3
* by crisk
4
*
5
* MS-Windows like Hebrew process routine
6
*
7
* This first started as an ircII script.. the function was
8
* ported almost 1 to 1 from the script, so you can excuse
9
* the extreme mess.
10
*
11
*/
12
13
#include "irc.h"
14
#include "ircaux.h"
15
#define MAIN_SOURCE
16
#include "modval.h"
17
18
#ifdef WANT_HEBREW
19
#include <stdio.h>
20
#include <string.h>
21
22
unsigned char *heb_reverse(char translate, unsigned char *str)
23
{
24
unsigned char tmp1,tmp2;
25
int ind,len,transind;
26
unsigned char *transloc;
27
28
unsigned char *transfrom = "()[]{}";
29
unsigned char *transto = ")(][}{";
30
31
len = strlen(str)-1;
32
33
for (ind=0;ind<((len+1)/2);ind++)
34
{
35
tmp1 = *(str+ind);
36
tmp2 = *(str+len-ind);
37
38
if (translate)
39
{
40
transloc = index(transfrom,tmp1);
41
if (transloc != NULL)
42
{
43
transind = transloc-transfrom;
44
tmp1 = *(transto+transind);
45
}
46
47
transloc = index(transfrom,tmp2);
48
if (transloc != NULL)
49
{
50
transind = transloc-transfrom;
51
tmp2 = *(transto+transind);
52
}
53
}
54
*(str+ind) = tmp2;
55
*(str+len-ind) = tmp1;
56
}
57
58
if (translate)
59
if (len % 2)
60
{
61
ind = (len % 2)+1;
62
transloc = index(transfrom,*(str+ind));
63
if (transloc != NULL)
64
{
65
transind = transloc-transfrom;
66
*(str+ind) = *(transto+transind);
67
}
68
}
69
70
return str;
71
}
72
73
unsigned char *hebrew_process(unsigned char *str)
74
{
75
76
#define hebrew_isheb(x) ((x >= 224) && (x <= 256))
77
#define hebrew_iseng(x) (((x >= 'a') && (x <= 'z')) || ((x >= 'A') && (x <= 'Z')))
78
#define hebrew_isnum(x) ((x >= '0') && (x <= '9'))
79
80
unsigned char *engspecial = "";
81
unsigned char *numrelated = "+-/.,";
82
83
int len;
84
85
unsigned char *result;
86
unsigned char let;
87
unsigned char *tmpstr;
88
unsigned char *tmpbuf;
89
int pos;
90
int p;
91
int mode;
92
int pnum;
93
int pnumplus;
94
int ppp;
95
int j,j2;
96
97
if (!str || !*str)
98
return empty_string;
99
len = strlen(str);
100
101
result = (unsigned char *)new_malloc(len+2);
102
tmpstr = (unsigned char *)new_malloc(len*2);
103
tmpbuf = (unsigned char *)new_malloc(len*2);
104
105
pos = 0;
106
p = 0;
107
pnum = 0;
108
mode = 0;
109
110
while (pos < len)
111
{
112
let = str[pos];
113
pos++;
114
tmpstr[0] = let;
115
tmpstr[1] = '\0';
116
117
if ((hebrew_iseng(let)) || (index(engspecial,let) != NULL))
118
{
119
120
strcat(tmpstr,tmpbuf);
121
122
strcat(tmpstr,result);
123
strcpy(result,tmpstr);
124
tmpbuf[0] = '\0';
125
tmpstr[1] = '\0';
126
127
p = 0;
128
mode = 1;
129
pnum = 0;
130
} else if (hebrew_isheb(let))
131
{
132
if (mode)
133
{
134
strcat(tmpbuf,result);
135
strcpy(result,tmpbuf);
136
}
137
else
138
{
139
tmpbuf = heb_reverse(1,tmpbuf);
140
strcat(tmpbuf,tmpstr);
141
strcpy(tmpstr,tmpbuf);
142
}
143
144
mode = 0;
145
146
for (j=0;j<p;j++)
147
*(tmpbuf+j) = *(result+j);
148
149
for (j2=0;j2<strlen(tmpstr);j2++)
150
*(tmpbuf+j+j2) = *(tmpstr+j2);
151
152
for (j=j;j<=strlen(result);j++)
153
*(tmpbuf+j+j2) = *(result+j);
154
155
*(tmpbuf+j+j2) = '\0';
156
strcpy(result,tmpbuf);
157
tmpbuf[0] = '\0';
158
159
p += strlen(tmpstr);
160
pnum = 0;
161
}
162
else if (hebrew_isnum(let))
163
{
164
if (!mode)
165
{
166
tmpbuf = heb_reverse(1,tmpbuf);
167
pnumplus = 0;
168
169
if (tmpbuf[0] != '\0')
170
{
171
if ((strlen(tmpbuf) == 1) && (index(numrelated,tmpbuf[0])))
172
{
173
strcat(tmpstr,tmpbuf);
174
tmpbuf[0] = '\0';
175
pnumplus = 1;
176
}
177
else
178
{
179
pnum = 0;
180
}
181
}
182
183
strcat(tmpbuf,tmpstr);
184
strcpy(tmpstr,tmpbuf);
185
186
ppp = p-pnum;
187
188
for (j=0;j<ppp;j++)
189
*(tmpbuf+j) = *(result+j);
190
191
for (j2=0;j2<strlen(tmpstr);j2++)
192
*(tmpbuf+j+j2) = *(tmpstr+j2);
193
194
for (j=j;j<=strlen(result);j++)
195
*(tmpbuf+j+j2) = *(result+j);
196
197
*(tmpbuf+j+j2) = '\0';
198
199
strcpy(result,tmpbuf);
200
201
tmpbuf[0] = '\0';
202
203
p += strlen(tmpstr);
204
pnum++;
205
pnum += pnumplus;
206
}
207
else
208
{
209
strcat(tmpstr,tmpbuf);
210
strcat(tmpstr,result);
211
strcpy(result,tmpstr);
212
tmpbuf[0]='\0';
213
p = 0;
214
}
215
}
216
else
217
{
218
strcat(tmpstr,tmpbuf);
219
strcpy(tmpbuf,tmpstr);
220
}
221
}
222
223
mode = 1; /* MS-Hebrew behavior thing */
224
225
if (mode)
226
{
227
strcat(tmpbuf,result);
228
strcpy(result,tmpbuf);
229
}
230
else
231
{
232
tmpbuf = heb_reverse(1,tmpbuf);
233
strcpy(tmpstr,tmpbuf);
234
235
for (j=0;j<p;j++)
236
*(tmpbuf+j) = *(result+j);
237
238
for (j2=0;j2<strlen(tmpstr);j2++)
239
*(tmpbuf+j+j2) = *(tmpstr+j2);
240
241
for (j=j;j<=strlen(result);j++)
242
*(tmpbuf+j+j2) = *(result+j);
243
244
strcpy(result,tmpbuf);
245
}
246
247
result = heb_reverse(0,result);
248
249
strcpy(str,result);
250
251
new_free(&result);
252
new_free(&tmpstr);
253
new_free(&tmpbuf);
254
255
return str;
256
257
}
258
#endif
259
260
261