OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [gnu/] [gcj/] [convert/] [gen-from-JIS.c] - Blame information for rev 756

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 756 jeremybenn
/* Copyright (C) 1999, 2008  Free Software Foundation
2
 
3
   This file is part of libgcj.
4
 
5
This software is copyrighted work licensed under the terms of the
6
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7
details.  */
8
 
9
#include <stdio.h>
10
#include <string.h>
11
#include <stdlib.h>
12
#include "make-trie.h"
13
 
14
struct chval
15
{
16
  unsigned char b1;            /* 1st byte */
17
  unsigned char b2;            /* 2nd byte */
18
  unsigned short uc;  /* unicode value */
19
};
20
 
21
#define MAP(B1, B2, C) { B1, B2, C },
22
 
23
struct chval chtab_0201[] = {
24
#include "JIS0201.h"
25
  { 255, 255, 0}
26
};
27
 
28
struct chval chtab_0208[] = {
29
#include "JIS0208.h"
30
  { 255, 255, 0}
31
};
32
 
33
struct chval chtab_0212[] = {
34
#include "JIS0212.h"
35
  { 255, 255, 0}
36
};
37
#undef MAP
38
 
39
struct chval sorted[] = {
40
#define MAP(B1, B2, C) { B1, B2, C },
41
#include "JIS0208.h"
42
#undef MAP
43
#define MAP(B1, B2, C) { 0x80|B1, B2, C },
44
#include "JIS0212.h"
45
#undef MAP
46
};
47
 
48
struct chval *chtab;
49
 
50
int
51
compare (void *p1, void *p2)
52
{
53
  struct chval *c1 = (struct chval *) p1;
54
  struct chval *c2 = (struct chval *) p2;
55
  return (int) c1->uc - (int) c2->uc;
56
}
57
 
58
int
59
main(int argc, char** argv)
60
{
61
  FILE *out = stdout;
62
  int min1 = 256, max1 = 0, min2 = 256, max2 = 0, count = 0;
63
  int low1_uc = 0xFFFF, high1_uc = 0;
64
  int low2_uc = 0xFFFF, high2_uc = 0;
65
  int i;  int row, col;
66
  if (argc < 2)
67
    {
68
      fprintf (stderr, "missing argument!\n");
69
      exit (-1);
70
    }
71
  if (strcmp (argv[1], "JIS0208") == 0)
72
    chtab = chtab_0208;
73
  else if (strcmp (argv[1], "JIS0212") == 0)
74
    chtab = chtab_0212;
75
  else if (strcmp (argv[1], "toJIS") == 0)
76
    {
77
      int i;
78
      for (i = 0;  chtab_0201[i].b1 != 255;  i++)
79
        {
80
          enter(chtab_0201[i].uc, chtab_0201[i].b2);
81
        }
82
      for (i = 0;  i < 0x20;  i++)
83
        {
84
          enter (i, i);
85
        }
86
      enter (127, 127);
87
      for (i = 0;  chtab_0208[i].b1 != 255;  i++)
88
        {
89
          enter(chtab_0208[i].uc,
90
                (chtab_0208[i].b1 << 8) | chtab_0208[i].b2);
91
        }
92
      for (i = 0;  chtab_0212[i].b1 != 255;  i++)
93
        {
94
          enter(chtab_0212[i].uc,
95
                0x8000 | (chtab_0212[i].b1 << 8) | chtab_0212[i].b2);
96
        }
97
      print_table ("Unicode_to_JIS", stdout);
98
      exit(0);
99
    }
100
  else
101
    {
102
      fprintf (stderr, "bad argument!");
103
      exit (-1);
104
    }
105
  for (i = 0;  chtab[i].b1 != 255; i++)
106
    {
107
      if (chtab[i].b1 < min1) min1 = chtab[i].b1;
108
      if (chtab[i].b2 < min2) min2 = chtab[i].b2;
109
      if (chtab[i].b1 > max1) max1 = chtab[i].b1;
110
      if (chtab[i].b2 > max2) max2 = chtab[i].b2;
111
      count++;
112
    }
113
  fprintf(stderr, "1st byte ranges from %d to %d.\n", min1, max1);
114
  fprintf(stderr, "2nd byte ranges from %d to %d.\n", min2, max2);
115
 
116
  fprintf(out,"/* This file is automatically generated from %s.TXT. */\n",
117
          argv[1]);
118
  fprintf(out,"#pragma GCC java_exceptions\n");
119
  fprintf(out, "unsigned short %s_to_Unicode[%d][%d] = {\n",
120
          argv[1], max1 - min1 + 1,  max2 - min2 + 1);
121
  i = 0;
122
  for (row = min1;  row <= max1;  row++)
123
    {
124
      fprintf(out, "/* 1st byte: %d */ { ", row);
125
      if (row < chtab[i].b1)
126
        {
127
          fprintf(out, "0 }, /* unused row */\n");
128
        }
129
      else if (row > chtab[i].b1)
130
        {
131
          fprintf (stderr, "error - char table out of order!\n");
132
          exit (-1);
133
        }
134
      else
135
        {
136
          fprintf(out, "\n");
137
          for (col = min2;  col <= max2;  col++)
138
            {
139
              if (row == chtab[i].b1 && col == chtab[i].b2)
140
                {
141
                  int uc = chtab[i].uc;
142
                  if (uc < 0x2000)
143
                    {
144
                      if (uc > high1_uc)
145
                        high1_uc = uc;
146
                      if (uc < low1_uc)
147
                        low1_uc = uc;
148
                    }
149
                  else
150
                    {
151
                      if (uc > high2_uc)
152
                        high2_uc = uc;
153
                      if (uc < low2_uc)
154
                        low2_uc = uc;
155
                    }
156
                  fprintf (out, "  /* 2nd byte: %d */ 0x%04x",
157
                           chtab[i].b2, uc);
158
                  i++;
159
                }
160
              else if (row < chtab[i].b1
161
                  || (row == chtab[i].b1 && col < chtab[i].b2))
162
                {
163
                  fprintf (out, "  0");
164
                }
165
              else
166
                {
167
                  fprintf (stderr, "error - char table out of order!\n");
168
                  exit (-1);
169
                }
170
              if (col != max2)
171
                fprintf (out, ",\n");
172
            }
173
          fprintf(out, row == max1 ? "}\n" : "},\n");
174
        }
175
    }
176
  fprintf(out, "};\n");
177
  fprintf(stderr, "total number of characters is %d.\n", count);
178
  fprintf(stderr, "Range is 0x%04x-0x%04x and 0x%04x-0x%04x.\n",
179
          low1_uc, high1_uc, low2_uc, high2_uc);
180
  return 0;
181
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.