[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs Makefile input.c kmaps kmaptoqe.c kmap/S...
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs Makefile input.c kmaps kmaptoqe.c kmap/S... |
Date: |
Tue, 04 Dec 2007 23:08:46 +0000 |
CVSROOT: /cvsroot/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 07/12/04 23:08:46
Modified files:
. : Makefile input.c kmaps kmaptoqe.c
kmap : Spanish.kmap
Log message:
handle extra kmaps
fixed numerous bugs in kmaptoqe.c: handle \ syntax and report errors.
disable HebrewIsraeli.kmap and Kana.kmap because of partial support
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/Makefile?cvsroot=qemacs&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/qemacs/input.c?cvsroot=qemacs&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/qemacs/kmaps?cvsroot=qemacs&rev=1.2
http://cvs.savannah.gnu.org/viewcvs/qemacs/kmaptoqe.c?cvsroot=qemacs&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/qemacs/kmap/Spanish.kmap?cvsroot=qemacs&r1=1.1&r2=1.2
Patches:
Index: Makefile
===================================================================
RCS file: /cvsroot/qemacs/qemacs/Makefile,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- Makefile 3 Dec 2007 16:15:01 -0000 1.12
+++ Makefile 4 Dec 2007 23:08:46 -0000 1.13
@@ -289,7 +289,7 @@
$(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 @@
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 @@
$(HOST_CC) $(CFLAGS) -o $@ $<
ifdef BUILD_ALL
-kmaps: kmaptoqe$(EXE) $(KMAPS)
+kmaps: kmaptoqe$(EXE) $(KMAPS) Makefile
./kmaptoqe $@ $(KMAPS)
endif
@@ -337,10 +340,10 @@
$(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
Index: input.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/input.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- input.c 3 Dec 2007 16:10:39 -0000 1.8
+++ input.c 4 Dec 2007 23:08:46 -0000 1.9
@@ -178,11 +178,13 @@
}
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 @@
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 @@
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;
}
Index: kmaps
===================================================================
RCS file: /cvsroot/qemacs/qemacs/kmaps,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -b -r1.1.1.1 -r1.2
Binary files /tmp/cvsf3r88b and /tmp/cvsc7aS8D differ
Index: kmaptoqe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/kmaptoqe.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- kmaptoqe.c 3 Dec 2007 16:15:01 -0000 1.4
+++ kmaptoqe.c 4 Dec 2007 23:08:46 -0000 1.5
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
input = inputs[k].input;
len = 0;
+ sp = 1;
nextc:
c = getc(f);
@@ -274,7 +322,7 @@
if (len == 0) {
printf(" \"");
if (gen_table) {
- printf("%c", table_val[s]);
+ putcp(table_val[s], &sp);
}
}
@@ -286,9 +334,7 @@
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 @@
}
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 @@
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 @@
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 @@
/* 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 @@
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);
- }
- // BUG! no handling of '\\'
- *q++ = c;
+ fprintf(stderr, "%s:%d: Invalid char 0x%x\n",
+ filename, line_num, c);
+ goto skip;
+ }
+ 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);
Index: kmap/Spanish.kmap
===================================================================
RCS file: /cvsroot/qemacs/qemacs/kmap/Spanish.kmap,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- kmap/Spanish.kmap 4 Dec 2007 09:22:50 -0000 1.1
+++ kmap/Spanish.kmap 4 Dec 2007 23:08:46 -0000 1.2
@@ -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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs Makefile input.c kmaps kmaptoqe.c kmap/S...,
Charlie Gordon <=