File: xlt.c

package info (click to toggle)
enca 1.13-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,440 kB
  • ctags: 1,230
  • sloc: sh: 11,125; ansic: 10,330; xml: 2,926; makefile: 698; perl: 232
file content (49 lines) | stat: -rw-r--r-- 950 bytes parent folder | download | duplicates (9)
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
#include <stdio.h>
#define NO_CHR 0xffff

int
main(int argc, char *argv[])
{
  unsigned int target_map[0x100];
  unsigned int source_map[0x100];
  unsigned char xlt[0x100];
  unsigned int ucs2_map[0x10000];
  FILE *f;

  int i;
  int c;

  f = fopen(argv[1], "r");
  for (i = 0; i < 0x100; i++)
    fscanf(f, "%x", source_map + i);
  fclose(f);

  f = fopen(argv[2], "r");
  for (i = 0; i < 0x100; i++)
    fscanf(f, "%x", target_map + i);
  fclose(f);

  for (i = 0; i < 0x100; i++)
    xlt[i] = (unsigned char)i;

  for (i = 0; i < 0x10000; i++)
    ucs2_map[i] = NO_CHR;

  for (i = 0xff; i >= 0; i--) {
    if (target_map[i] != NO_CHR)
      ucs2_map[target_map[i]] = (unsigned int)i;
  }

  for (i = 0xff; i >= 0; i--) {
    if (source_map[i] != NO_CHR
        && ucs2_map[source_map[i]] != NO_CHR)
      xlt[i] = (unsigned char)ucs2_map[source_map[i]];
  }

  while ((c = getchar()) != EOF)
    putchar(xlt[c]);

  return 0;
}
/* vim: ts=2
 */