File: tran.c

package info (click to toggle)
xcingb 2.3.02-5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,492 kB
  • ctags: 877
  • sloc: ansic: 9,779; sh: 1,460; makefile: 299; awk: 12
file content (122 lines) | stat: -rw-r--r-- 2,121 bytes parent folder | download | duplicates (4)
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
/*
	Copyright (C) 1995	Edward Der-Hua Liu, Hsin-Chu, Taiwan
*/

#include <sys/types.h>

extern int printf( const char *format, ...);

void ser_b5(u_char *ch, u_char *tt)
{
	u_short q,r,ofs, oofs;

	tt[2]=0;
	oofs=ofs=((u_short)*ch<<8)|*(ch+1);

	if (ofs==0) {
		*tt=*(tt+1)=0;
		return;
	}
	if (ch[0]==' ' && ch[1]==' ') {
		*tt=*(tt+1)=' ';
		return;
	}

	if (ofs < 0x8800) {
		ofs-=0x8400;
		if (ofs>=5401) ofs+=408; /* useless */ 
		q=ofs/157; r=ofs%157;
		if (r<63)
			*(tt+1)=r+0x40;
		else
			*(tt+1)=(r-63)+0xa1;

		if (q<94)
			*tt=q+0xa1;
		else
			printf("&error ofs:%x\n",oofs);
		return;
	}

	if (ofs > 0xe000) {
		ofs-=0xe000;
		q=ofs/157; r=ofs%157;
		if (r<63)
			*(tt+1)=r+0x40;
		else
			*(tt+1)=(r-63)+0xa1;

		if (q<94)
			*tt=q+0xc6;
		else
			printf("#error ofs:%x\n",oofs);
		return;
	}

	ofs-=0x8800;
	if (ofs>=5401) ofs+=408;
	q=ofs/157; r=ofs%157;
	if (r<63)
		*(tt+1)=r+0x40;
	else
		*(tt+1)=(r-63)+0xa1;

	if (q<94)
		*tt=q+0xa4;
	else
		printf("!error ofs:%x\n",oofs);
}

void b5_ser(u_char *s, u_char *t)
{
u_char lb,hb, tt=0;
u_short ser, b5;

if (s[0]==' ' && s[1]==' ') {
	*t=*(t+1)=' ';
	return;
}
hb=s[0];
lb=s[1];
b5=((u_short)hb<<8)|lb;

if (b5 < (u_short)0xa440) {
	if (lb>=0xa1 && lb<=0xfe) tt=(lb-0xa1)+63;
	else
	if (lb>=0x40 && lb<=0x7e) tt=lb-0x40;
	else printf("err %x\n", b5);
	ser=(u_short)(hb-0xa1)*157+ tt;
	ser+=0x8400;
	t[0]=ser>>8;
	t[1]=ser&255;
	if (t[0]==0x21 && t[1]==0x84)
		printf("#%2x%2x %c%c\n", s[0],s[1], s[0],s[1]);
	return;
}

if (b5 >= 0xc6a1 && b5 <= 0xc8fe) {
	if (lb>=0xa1 && lb<=0xfe) tt=(lb-0xa1)+63;
	else
	if (lb>=0x40 && lb<=0x7e) tt=lb-0x40;
	else printf("err %x\n", b5);
	ser=(u_short)(hb-0xc6)*157+ tt;
	ser+=0xe000;
	t[0]=ser>>8;
	t[1]=ser&255;
	if (t[0]==0x21 && t[1]==0x84)
		printf("$%2x%2x %c%c\n", s[0],s[1], s[0],s[1]);
	return;
}

if (lb>=0xa1 && lb<=0xfe) tt=(lb-0xa1)+63;
else
if (lb>=0x40 && lb<=0x7e) tt=lb-0x40;
else printf("err %x\n", b5);
ser=(u_short)(hb-0xa4)*157+ tt;
if (ser>=5401) ser+=0x8800-408;
else ser+=0x8800;
t[0]=ser>>8;
t[1]=ser&255;
	if (t[0]==0x21 && t[1]==0x84)
		printf("*%2x%2x %c%c\n", s[0],s[1], s[0],s[1]);
}