File: jiscode.c

package info (click to toggle)
fkiss 0.33a.patch-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 804 kB
  • ctags: 1,074
  • sloc: ansic: 9,141; sh: 2,924; makefile: 98; sed: 14
file content (80 lines) | stat: -rw-r--r-- 1,851 bytes parent folder | download | duplicates (3)
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
/* $Header: /home/yav/catty/fkiss/RCS/jiscode.c,v 1.3 2000/08/24 02:22:37 yav Exp $
 * JIS code <-> Shift-JIS code
 * written by yav <yav@bigfoot.com>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

char id_jiscode[] = "$Id: jiscode.c,v 1.3 2000/08/24 02:22:37 yav Exp $";

int is_sjis_1st(c)
     int c;
{
  return ((c)>=0x81 && (c)<=0x9f)||((c)>=0xe0 && (c)<=0xfc);
}

int is_sjis_2nd(c)
     int c;
{
  return ((c)>=0x40 && (c)<=0x7e)||((c)>=0x80 && (c)<=0xfc);
}

unsigned short ysjis2jis(c)
     unsigned short c;
{
  unsigned char h, l;
  unsigned short dd;
  
  h = c >> 8;
  l = c & 0xff;
  if (!is_sjis_1st(h) || !is_sjis_2nd(l))
    return 0;
  if (h >= 0xe0)
    h -= 0x40;
  if (l < 0x9f) {
    if (l >= 0x80)
      l -= 1;
    dd = 0xe11f;
  } else {
    dd = 0xe07e;
  }
  return (h << 9) + l - dd;
}


unsigned short yjis2sjis(c)
     unsigned short c;
{
  unsigned short h, l;
  
  l = c & 0xff;
  h = c >> 8;
  if ((h < 0x21)||(h > 0x7e)||(l < 0x21)||(l > 0x7e))
    return 0;
  if ((h & 1) != 0) {
    l += 0x1f;
    if (l >= 0x7f)
      l++;
  } else {
    l += 0x7e;
  }
  h += 0xe1;
  h >>= 1;
  if (h >= 0xa0)
    h += 0x40;
  return (h << 8) + l;
}

/* End of file */