#include #include #include "main.h" static unsigned char ascii_[94][14]; static unsigned char *kanji_[94][94]; const unsigned char *ascii(int c) { return c <= 0x20 || 0x7f <= c ? NULL : ascii_[c - 0x21]; } const unsigned char *kanji(int c1, int c2) { return c1 <= 0xa0 || 0xff <= c1 || c2 <= 0xa0 || 0xff <= c2 ? NULL : kanji_[c1 - 0xa1][c2 - 0xa1]; } #define h(x) ('0' <= (x) && (x) <= '9' ? (x) - '0' : (x) - 'a' + 10) int load_ascii(const char *filename) { FILE *fp; int c; int i, j; if ((fp = fopen(filename, "rb")) == NULL) { return 0; } while ((c = fgetc(fp)) != EOF) { error_if(c <= 0x20 || 0x7f <= c); i = c - 0x21; for (j = 13; j >= 0; --j) { c = fgetc(fp); ascii_[i][j] = h(c) << 4; c = fgetc(fp); ascii_[i][j] |= h(c); } error_if(fgetc(fp) != '\n'); } error_if(fclose(fp) == EOF); return 1; } int load_kanji(const char *filename) { FILE *fp; int c; int i, j, k; if ((fp = fopen(filename, "rb")) == NULL) { return 0; } while ((c = fgetc(fp)) != EOF) { error_if(c <= 0xa0 || 0xff <= c); i = c - 0xa1; c = fgetc(fp); error_if(c <= 0xa0 || 0xff <= c); j = c - 0xa1; if (kanji_[i][j]) { free(kanji_[i][j]); } error_if((kanji_[i][j] = malloc(28)) == NULL); for (k = 13; k >= 0; --k) { c = fgetc(fp); kanji_[i][j][k * 2] = h(c) << 4; c = fgetc(fp); kanji_[i][j][k * 2] |= h(c); c = fgetc(fp); kanji_[i][j][k * 2 + 1] = h(c) << 4; c = fgetc(fp); kanji_[i][j][k * 2 + 1] |= h(c); } error_if((c = fgetc(fp)) != '\n'); } error_if(fclose(fp) == EOF); return 1; }