blob: 133c249d5fa15dcd0703e8d8362f0e88e253f5f0 (
plain) (
blame)
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
|
/* $Id: convert.c 1374 2003-11-27 14:11:40Z victor $ */
#include "bbs.h"
/*
* The following code is copied and modified from "autoconvert" with GPL.
*/
#ifdef GB_CONVERT
#include "convert.h"
#define BtoG_bad1 0xa1
#define BtoG_bad2 0xf5
#define GtoB_bad1 0xa1
#define GtoB_bad2 0xbc
char *hzconvert(char *, int *, char *, void (*dbcvrt)());
extern unsigned char GtoB[], BtoG[];
#define c1 (unsigned char)(s[0])
#define c2 (unsigned char)(s[1])
static void g2b(char *s)
{
unsigned int i;
if ((c2 >= 0xa1) && (c2 <= 0xfe)) {
if ((c1 >= 0xa1) && (c1 <= 0xa9)) {
i = ((c1 - 0xa1) * 94 + (c2 - 0xa1)) * 2;
s[0] = GtoB[i++]; s[1] = GtoB[i];
return;
} else if ((c1 >= 0xb0) && (c1 <= 0xf7)) {
i = ((c1 - 0xb0 + 9) * 94 + (c2 - 0xa1)) * 2;
s[0] = GtoB[i++]; s[1] = GtoB[i];
return;
}
}
s[0] = GtoB_bad1; s[1] = GtoB_bad2;
}
static void b2g(char *s)
{
int i;
if ((c1 >= 0xa1) && (c1 <= 0xf9)) {
if ((c2 >= 0x40) && (c2 <= 0x7e)) {
i = ((c1 - 0xa1) * 157 + (c2 - 0x40)) * 2;
s[0] = BtoG[i++]; s[1] = BtoG[i];
return;
} else if ((c2 >= 0xa1) && (c2 <= 0xfe)) {
i = ((c1 - 0xa1) * 157 + (c2 - 0xa1) + 63) * 2;
s[0] = BtoG[i++]; s[1] = BtoG[i];
return;
}
}
s[0] = BtoG_bad1; s[1] = BtoG_bad2;
}
unsigned char *gb2big(unsigned char *s, int plen)
{
unsigned char c = 0;
return hzconvert(s, &plen, &c, g2b);
}
unsigned char *big2gb(unsigned char *s, int plen)
{
unsigned char c = 0;
return hzconvert(s, &plen, &c, b2g);
}
#endif
|