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
|
#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;
if (argc < 1) {
fprintf(stderr, "Error: Missing arguments!\n");
return 0;
}
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
*/
|