handle extra kmaps
fixed numerous bugs in kmaptoqe.c: handle \ syntax and report errors. disable HebrewIsraeli.kmap and Kana.kmap because of partial support
This commit is contained in:
parent
500161856e
commit
71f55ca730
5 changed files with 161 additions and 72 deletions
17
Makefile
17
Makefile
|
|
@ -289,7 +289,7 @@ ligtoqe$(EXE): ligtoqe.c
|
|||
$(HOST_CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
ifdef BUILD_ALL
|
||||
ligatures: unifont.lig ligtoqe$(EXE)
|
||||
ligatures: ligtoqe$(EXE) unifont.lig
|
||||
./ligtoqe unifont.lig $@
|
||||
endif
|
||||
|
||||
|
|
@ -299,11 +299,14 @@ endif
|
|||
KMAPS=Arabic.kmap ArmenianEast.kmap ArmenianWest.kmap Chinese-CJ.kmap \
|
||||
Cyrillic.kmap Czech.kmap DE-RU.kmap Danish.kmap Dutch.kmap \
|
||||
Esperanto.kmap Ethiopic.kmap French.kmap Georgian.kmap German.kmap \
|
||||
Greek.kmap GreekMono.kmap Guarani.kmap Hebrew.kmap HebrewIsraeli.kmap \
|
||||
Greek.kmap GreekMono.kmap Guarani.kmap Hebrew.kmap \
|
||||
Hungarian.kmap \
|
||||
KOI8_R.kmap Kana.kmap Lithuanian.kmap Mnemonic.kmap Polish.kmap \
|
||||
KOI8_R.kmap Lithuanian.kmap Mnemonic.kmap Polish.kmap \
|
||||
Russian.kmap SGML.kmap TeX.kmap Troff.kmap VNtelex.kmap \
|
||||
Vietnamese.kmap XKB_iso8859-4.kmap
|
||||
Vietnamese.kmap XKB_iso8859-4.kmap \
|
||||
DanishAlternate.kmap GreekBible.kmap Polytonic.kmap Spanish.kmap \
|
||||
Thai.kmap VietnameseTelex.kmap Welsh.kmap
|
||||
# HebrewIsraeli.kmap Kana.kmap
|
||||
# Hangul.kmap Hangul2.kmap Hangul3.kmap Unicode2.kmap
|
||||
#KMAPS_DIR=$(prefix)/share/yudit/data
|
||||
KMAPS_DIR=kmap
|
||||
|
|
@ -313,7 +316,7 @@ kmaptoqe$(EXE): kmaptoqe.c
|
|||
$(HOST_CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
ifdef BUILD_ALL
|
||||
kmaps: kmaptoqe$(EXE) $(KMAPS)
|
||||
kmaps: kmaptoqe$(EXE) $(KMAPS) Makefile
|
||||
./kmaptoqe $@ $(KMAPS)
|
||||
endif
|
||||
|
||||
|
|
@ -337,10 +340,10 @@ jistoqe$(EXE): jistoqe.c
|
|||
$(HOST_CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
ifdef BUILD_ALL
|
||||
charsetmore.c: cptoqe$(EXE) $(CP)
|
||||
charsetmore.c: cptoqe$(EXE) $(CP) Makefile
|
||||
./cptoqe $(CP) > $@
|
||||
|
||||
charsetjis.def: jistoqe$(EXE) $(JIS)
|
||||
charsetjis.def: jistoqe$(EXE) $(JIS) Makefile
|
||||
./jistoqe $(JIS) > $@
|
||||
endif
|
||||
|
||||
|
|
|
|||
27
input.c
27
input.c
|
|
@ -178,11 +178,13 @@ the_end:
|
|||
}
|
||||
|
||||
static int input_method_fd;
|
||||
static size_t input_method_size;
|
||||
static void *input_method_map;
|
||||
|
||||
static void load_input_methods(void)
|
||||
{
|
||||
char buf[MAX_FILENAME_SIZE], *q;
|
||||
long file_size;
|
||||
char buf[MAX_FILENAME_SIZE];
|
||||
size_t file_size;
|
||||
int fd, offset;
|
||||
const unsigned char *file_ptr, *p;
|
||||
InputMethod *m;
|
||||
|
|
@ -198,13 +200,17 @@ static void load_input_methods(void)
|
|||
file_size = lseek(fd, 0, SEEK_END);
|
||||
file_ptr = mmap(NULL, file_size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
if ((void*)file_ptr == (void*)MAP_FAILED) {
|
||||
// XXX: allocate a buffer and read the file in memory
|
||||
fail:
|
||||
// XXX: print error message
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (memcmp(file_ptr, "kmap", 4) != 0)
|
||||
if (memcmp(file_ptr, "kmap", 4) != 0) {
|
||||
munmap((void*)file_ptr, file_size);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
p = file_ptr + 4;
|
||||
for (;;) {
|
||||
|
|
@ -216,25 +222,22 @@ static void load_input_methods(void)
|
|||
if (m) {
|
||||
m->data = file_ptr + offset;
|
||||
m->input_match = kmap_input;
|
||||
q = buf;
|
||||
while (*p != '\0') {
|
||||
if (q < buf + sizeof(buf) - 1)
|
||||
*q++ = *p;
|
||||
p++;
|
||||
}
|
||||
*q = '\0';
|
||||
p++;
|
||||
m->name = strdup(buf);
|
||||
m->name = (const char*)p;
|
||||
register_input_method(m);
|
||||
}
|
||||
p += strlen((const char *)p);
|
||||
}
|
||||
|
||||
input_method_fd = fd;
|
||||
input_method_map = (void *)file_ptr;
|
||||
input_method_size = file_size;
|
||||
}
|
||||
|
||||
static void unload_input_methods(void)
|
||||
{
|
||||
if (input_method_fd >= 0) {
|
||||
munmap((void*)input_method_map, input_method_size);
|
||||
input_method_map = NULL;
|
||||
close(input_method_fd);
|
||||
input_method_fd = -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
"E-=0x20AC", // € = EURO SIGN
|
||||
"Ct=0x00A2", // ¢ = CENT SIGN
|
||||
"L-=0x00A3", // £ = POUND SIGN
|
||||
"Y-=00A5", // = YEN SIGN
|
||||
"Y-=0x00A5", // = YEN SIGN
|
||||
|
||||
"-: = 0xf7", // ÷ = DIVISION SIGN
|
||||
"S$=0x00A7", // § = SECTION SIGN
|
||||
|
|
|
|||
BIN
kmaps
BIN
kmaps
Binary file not shown.
187
kmaptoqe.c
187
kmaptoqe.c
|
|
@ -25,12 +25,16 @@
|
|||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifndef countof
|
||||
#define countof(a) ((int)(sizeof(a) / sizeof((a)[0])))
|
||||
#endif
|
||||
|
||||
//#define TEST
|
||||
|
||||
#define NB_MAX 15000
|
||||
|
||||
typedef struct InputEntry {
|
||||
unsigned char input[10];
|
||||
unsigned char input[20];
|
||||
int len;
|
||||
int output;
|
||||
} InputEntry;
|
||||
|
|
@ -54,7 +58,7 @@ static int sort_func(const void *a1, const void *b1)
|
|||
const InputEntry *b = b1;
|
||||
int val;
|
||||
|
||||
if (is_chinese_cj) {
|
||||
if (gen_table) {
|
||||
val = a->input[0] - b->input[0];
|
||||
if (val != 0)
|
||||
return val;
|
||||
|
|
@ -155,6 +159,51 @@ static void gen_map(void)
|
|||
put_byte(0);
|
||||
}
|
||||
|
||||
static void putcp(int c, int *sp)
|
||||
{
|
||||
switch (c) {
|
||||
case '=':
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
goto x2;
|
||||
case '\\':
|
||||
case '"':
|
||||
case '-':
|
||||
case '+':
|
||||
printf("\\%c", c);
|
||||
*sp = 0;
|
||||
break;
|
||||
default:
|
||||
if (c >= 256) {
|
||||
if (!*sp)
|
||||
printf(" ");
|
||||
printf("0x%04X ", c);
|
||||
*sp = 1;
|
||||
break;
|
||||
} else
|
||||
if (c <= 0x20 || c >= 0x7F) {
|
||||
x2:
|
||||
if (!*sp)
|
||||
printf(" ");
|
||||
printf("0x%02X ", c);
|
||||
*sp = 1;
|
||||
break;
|
||||
} else {
|
||||
printf("%c", c);
|
||||
*sp = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int dump_kmap(const char *filename)
|
||||
{
|
||||
FILE *f;
|
||||
|
|
@ -184,7 +233,7 @@ static int dump_kmap(const char *filename)
|
|||
kmap_offsets[nb_kmaps] = off;
|
||||
for (i = 0;; i++) {
|
||||
c = getc(f);
|
||||
if (c == EOF || i >= (int)sizeof(kmap_names[nb_kmaps])) {
|
||||
if (c == EOF || i >= countof(kmap_names[nb_kmaps])) {
|
||||
fprintf(stderr, "%s: invalid map name\n", filename);
|
||||
fclose(f);
|
||||
return 1;
|
||||
|
|
@ -216,9 +265,7 @@ static int dump_kmap(const char *filename)
|
|||
pos++;
|
||||
nb_starts = c & 0x7F;
|
||||
is_chinese_cj = c >> 7;
|
||||
gen_table = !strcmp(kmap_names[n], "Chinese_CJ") ||
|
||||
!strcmp(kmap_names[n], "TeX") ||
|
||||
!strcmp(kmap_names[n], "SGML");
|
||||
gen_table = (nb_starts > 0);
|
||||
|
||||
printf(" nb_starts=%d, is_chinese_cj=%d\n",
|
||||
nb_starts, is_chinese_cj);
|
||||
|
|
@ -243,7 +290,7 @@ static int dump_kmap(const char *filename)
|
|||
x = 0;
|
||||
|
||||
if (1) {
|
||||
int len, flag, k, s, last = 0;
|
||||
int len, flag, k, s, last = 0, sp;
|
||||
|
||||
s = 0;
|
||||
for (k = 0;; k++) {
|
||||
|
|
@ -251,6 +298,7 @@ static int dump_kmap(const char *filename)
|
|||
|
||||
input = inputs[k].input;
|
||||
len = 0;
|
||||
sp = 1;
|
||||
|
||||
nextc:
|
||||
c = getc(f);
|
||||
|
|
@ -274,7 +322,7 @@ static int dump_kmap(const char *filename)
|
|||
if (len == 0) {
|
||||
printf(" \"");
|
||||
if (gen_table) {
|
||||
printf("%c", table_val[s]);
|
||||
putcp(table_val[s], &sp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -286,9 +334,7 @@ static int dump_kmap(const char *filename)
|
|||
c |= getc(f) << 0;
|
||||
pos += 2;
|
||||
input[len++] = c;
|
||||
if (len > 1)
|
||||
printf(" ");
|
||||
printf("0x%04X", c);
|
||||
putcp(c, &sp);
|
||||
if (flag) {
|
||||
last += 1;
|
||||
goto nextk;
|
||||
|
|
@ -307,25 +353,7 @@ static int dump_kmap(const char *filename)
|
|||
}
|
||||
if (c >= 0x20) {
|
||||
input[len++] = c;
|
||||
switch (c) {
|
||||
case ' ':
|
||||
case '=':
|
||||
case 0x7f:
|
||||
case '0'...'9':
|
||||
if (len > 1)
|
||||
printf(" ");
|
||||
printf("0x%02X", c);
|
||||
break;
|
||||
case '\\':
|
||||
case '"':
|
||||
case '-':
|
||||
case '+':
|
||||
printf("\\%c", c);
|
||||
break;
|
||||
default:
|
||||
printf("%c", c);
|
||||
break;
|
||||
}
|
||||
putcp(c, &sp);
|
||||
if (flag) {
|
||||
last += 1;
|
||||
goto nextk;
|
||||
|
|
@ -333,9 +361,12 @@ static int dump_kmap(const char *filename)
|
|||
goto nextc;
|
||||
}
|
||||
nextk:
|
||||
if (is_chinese_cj)
|
||||
printf(" 0x20");
|
||||
printf(" = 0x%04X\",\n", last);
|
||||
if (is_chinese_cj) {
|
||||
putcp(' ', &sp);
|
||||
}
|
||||
if (!sp)
|
||||
printf(" ");
|
||||
printf("= 0x%04X\",\n", last);
|
||||
}
|
||||
}
|
||||
if (pos == kmap_offsets[n])
|
||||
|
|
@ -368,10 +399,50 @@ static int dump_kmap(const char *filename)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline void skipspaces(char **pp) {
|
||||
while (isspace((unsigned char)**pp))
|
||||
++*pp;
|
||||
}
|
||||
|
||||
static int getcp(char *p, char **pp)
|
||||
{
|
||||
if (*p == '\0') {
|
||||
return -1;
|
||||
} else
|
||||
if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
|
||||
return strtoul(p, pp, 0);
|
||||
} else
|
||||
if (*p == '\\') {
|
||||
p++;
|
||||
if (*p == 't') {
|
||||
*pp = p + 1;
|
||||
return '\t';
|
||||
} else
|
||||
if (p[0] >= '0' && p[0] <= '3'
|
||||
&& p[1] >= '0' && p[1] <= '7'
|
||||
&& p[2] >= '0' && p[2] <= '7') {
|
||||
*pp = p + 3;
|
||||
return ((p[0] - '0') << 6) | ((p[1] - '0') << 3) |
|
||||
((p[2] - '0') << 0);
|
||||
} else {
|
||||
*pp = p + 1;
|
||||
return *p;
|
||||
}
|
||||
} else
|
||||
if ((*p & 0xe0) == 0xc0 && (p[1] & 0xc0) == 0x80) {
|
||||
/* UTF-8 character */
|
||||
*pp = p + 2;
|
||||
return ((*p - 0xc0) << 6) | ((p[1] - 0x80) << 0);
|
||||
} else {
|
||||
*pp = p + 1;
|
||||
return *p;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *filename;
|
||||
int i, j, k, col, line_num;
|
||||
int i, j, k, col, line_num, len;
|
||||
FILE *f;
|
||||
char line[1024], *p;
|
||||
unsigned char *q;
|
||||
|
|
@ -421,7 +492,9 @@ int main(int argc, char **argv)
|
|||
/* special compression for CJ */
|
||||
is_chinese_cj = !strcmp(name, "Chinese_CJ");
|
||||
gen_table = !strcmp(name, "Chinese_CJ") ||
|
||||
!strcmp(name, "TeX") || !strcmp(name, "SGML");
|
||||
!strcmp(name, "TeX") ||
|
||||
!strcmp(name, "Troff") ||
|
||||
!strcmp(name, "SGML");
|
||||
|
||||
col = 0;
|
||||
nb_inputs = 0;
|
||||
|
|
@ -431,34 +504,44 @@ int main(int argc, char **argv)
|
|||
break;
|
||||
line_num++;
|
||||
p = line;
|
||||
if (*p == '/')
|
||||
skipspaces(&p);
|
||||
if (*p == '\0' || *p == '/' || *p == '#')
|
||||
continue;
|
||||
while (*p != '\0' && *p != '\"') p++;
|
||||
if (*p != '\"')
|
||||
continue;
|
||||
goto invalid;
|
||||
p++;
|
||||
len = 0;
|
||||
q = inputs[nb_inputs].input;
|
||||
for (;;) {
|
||||
while (isspace(*p))
|
||||
p++;
|
||||
if (*p == '=')
|
||||
skipspaces(&p);
|
||||
if (*p == '=' && p[1] != '=')
|
||||
break;
|
||||
if (p[0] == '0' && p[1] == 'x') {
|
||||
c = strtoul(p, &p, 0);
|
||||
} else {
|
||||
c = *p++;
|
||||
}
|
||||
c = getcp(p, &p);
|
||||
if (c < 0)
|
||||
goto invalid;
|
||||
if (c >= 256) {
|
||||
fprintf(stderr, "%s:%d: Invalid char %x %c\n",
|
||||
filename, line_num, c, c);
|
||||
fprintf(stderr, "%s:%d: Invalid char 0x%x\n",
|
||||
filename, line_num, c);
|
||||
goto skip;
|
||||
}
|
||||
// BUG! no handling of '\\'
|
||||
*q++ = c;
|
||||
if (len >= countof(inputs[nb_inputs].input))
|
||||
goto invalid;
|
||||
q[len++] = c;
|
||||
}
|
||||
inputs[nb_inputs].len = q - inputs[nb_inputs].input;
|
||||
inputs[nb_inputs].len = len;
|
||||
p++;
|
||||
inputs[nb_inputs].output = strtoul(p, NULL, 0);
|
||||
skipspaces(&p);
|
||||
c = getcp(p, &p);
|
||||
skipspaces(&p);
|
||||
if (c < 0 || *p != '"')
|
||||
goto invalid;
|
||||
inputs[nb_inputs].output = c;
|
||||
nb_inputs++;
|
||||
continue;
|
||||
invalid:
|
||||
fprintf(stderr, "%s:%d: Invalid mapping: %s\n",
|
||||
filename, line_num, line);
|
||||
skip:;
|
||||
}
|
||||
|
||||
qsort(inputs, nb_inputs, sizeof(InputEntry), sort_func);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue