aboutsummaryrefslogtreecommitdiff
path: root/libjava/gnu/gcj/convert/gen-from-JIS.c
blob: c49b8945ec3e0845273b0472c759b3c0a45af6d4 (plain)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* Copyright (C) 1999  Cygnus Solutions

   This file is part of libgcj.

This software is copyrighted work licensed under the terms of the
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
details.  */

#include <stdio.h>
struct chval
{
  unsigned char b1;            /* 1st byte */
  unsigned char b2;            /* 2nd byte */
  unsigned short uc;  /* unicode value */
};

#define MAP(B1, B2, C) { B1, B2, C },

struct chval chtab_0208[] = {
#include "JIS0208.h"
  { 255, 255, 0}
};

struct chval chtab_0212[] = {
#include "JIS0212.h"
  { 255, 255, 0}
};
#undef MAP

struct chval sorted[] = {
#define MAP(B1, B2, C) { B1, B2, C },
#include "JIS0208.h"
#undef MAP
#define MAP(B1, B2, C) { 0x80|B1, B2, C },
#include "JIS0212.h"
#undef MAP
};

struct chval *chtab;

int
compare (void *p1, void *p2)
{
  struct chval *c1 = (struct chval *) p1;
  struct chval *c2 = (struct chval *) p2;
  return (int) c1->uc - (int) c2->uc;
}

int
main(int argc, char** argv)
{
  FILE *out = stdout;
  unsigned min1 = 256, max1 = 0, min2 = 256, max2 = 0, count = 0;
  unsigned short low1_uc = 0xFFFF, high1_uc = 0;
  unsigned short low2_uc = 0xFFFF, high2_uc = 0;
  int i;  int row, col;
  if (strcmp (argv[1], "JIS0208") == 0)
    chtab = chtab_0208;
  else if (strcmp (argv[1], "JIS0212") == 0)
    chtab = chtab_0212;
  else if (strcmp (argv[1], "toJIS") == 0)
    {
      int i;
      int count = sizeof(sorted)/sizeof(struct chval);
      qsort (sorted, count, sizeof(struct chval),
	     compare);
      for (i = 0;  i < count;  i++)
	{
	  fprintf (out, "  0x%04x -> 0x%02x, 0x%02x\n",
		   sorted[i].uc, sorted[i].b1, sorted[i].b2);
	}
      exit(0);
    }
  else
    {
      fprintf (stderr, "bad argument!");
      exit (-1);
    }
  for (i = 0;  chtab[i].b1 != 255; i++)
    {
      if (chtab[i].b1 < min1) min1 = chtab[i].b1;
      if (chtab[i].b2 < min2) min2 = chtab[i].b2;
      if (chtab[i].b1 > max1) max1 = chtab[i].b1;
      if (chtab[i].b2 > max2) max2 = chtab[i].b2;
      count++;
    }
  fprintf(stderr, "1st byte ranges from %d to %d.\n", min1, max1);
  fprintf(stderr, "2nd byte ranges from %d to %d.\n", min2, max2);

  fprintf(out,"/* This file is automatically generated from %s.TXT. */\n",
	  argv[1]);
  fprintf(out, "unsigned short %s_to_Unicode[%d][%d] = {\n",
	  argv[1], max1 - min1 + 1,  max2 - min2 + 1);
  i = 0;
  for (row = min1;  row <= max1;  row++)
    {
      fprintf(out, "/* 1st byte: %d */ { ", row);
      if (row < chtab[i].b1)
	{
	  fprintf(out, "0 }, /* unused row */\n");
	}
      else if (row > chtab[i].b1)
	{
	  fprintf (stderr, "error - char table out of order!\n");
	  exit (-1);
	}
      else
	{
	  fprintf(out, "\n");
	  for (col = min2;  col <= max2;  col++)
	    {
	      if (row == chtab[i].b1 && col == chtab[i].b2)
		{
		  unsigned uc = chtab[i].uc;
		  if (uc < 0x2000)
		    {
		      if (uc > high1_uc)
			high1_uc = uc;
		      if (uc < low1_uc)
			low1_uc = uc;
		    }
		  else
		    {
		      if (uc > high2_uc)
			high2_uc = uc;
		      if (uc < low2_uc)
			low2_uc = uc;
		    }
		  fprintf (out, "  /* 2nd byte: %d */ 0x%04x",
			   chtab[i].b2, uc);
		  i++;
		}
	      else if (row < chtab[i].b1
		  || (row == chtab[i].b1 && col < chtab[i].b2))
		{
		  fprintf (out, "  0");
		}
	      else
		{
		  fprintf (stderr, "error - char table our of order!\n");
		  exit (-1);
		}
	      if (col != max2)
		fprintf (out, ",\n");
	    }
	  fprintf(out, row == max1 ? "}\n" : "},\n");
	}
    }
  fprintf(out, "};\n");
  fprintf(stderr, "total number of characters is %d.\n", count);
  fprintf(stderr, "Range is 0x%04x-0x%04x and 0x%04x-0x%04x.\n",
	  low1_uc, high1_uc, low2_uc, high2_uc);
  return 0;
}