Author: ek.kato
Date: Wed Jul 11 05:44:14 2007
New Revision: 4707
Modified:
branches/1.4/gtk/compose.c
branches/1.4/qt/immodule-quiminputcontext.h
branches/1.4/qt/immodule-quiminputcontext_compose.cpp
branches/1.4/xim/compose.cpp
branches/1.4/xim/xim.h
Log:
* Port r4705:4706 from trunk.
Modified: branches/1.4/gtk/compose.c
==============================================================================
--- branches/1.4/gtk/compose.c (original)
+++ branches/1.4/gtk/compose.c Wed Jul 11 05:44:14 2007
@@ -134,13 +134,10 @@
}
static int
-nextch(FILE *fp, int *lastch, size_t *remain)
+nextch(FILE *fp, int *lastch)
{
int c;
- if (*remain <= 1)
- return EOF;
-
if (*lastch != 0) {
c = *lastch;
*lastch = 0;
@@ -186,14 +183,15 @@
#endif
static int
-nexttoken(FILE *fp, char *tokenbuf, int *lastch, size_t *remain)
+nexttoken(FILE *fp, char **tokenbuf, int *lastch, size_t *buflen)
{
int c;
int token;
char *p;
int i, j;
+ size_t len = 0;
- while ((c = nextch(fp, lastch, remain)) == ' ' || c == '\t') {
+ while ((c = nextch(fp, lastch)) == ' ' || c == '\t') {
}
switch (c) {
case EOF:
@@ -218,31 +216,36 @@
token = TILDE;
break;
case '"':
- p = tokenbuf;
- while ((c = nextch(fp, lastch, remain)) != '"') {
+ p = *tokenbuf;
+ while ((c = nextch(fp, lastch)) != '"') {
+ if (len >= *buflen - 1) {
+ *buflen += BUFSIZ;
+ *tokenbuf = (char *)realloc(*tokenbuf, *buflen);
+ p = *tokenbuf + len;
+ }
if (c == '\n' || c == EOF) {
putbackch(c, lastch);
token = ERROR;
goto string_error;
} else if (c == '\\') {
- c = nextch(fp, lastch, remain);
+ c = nextch(fp, lastch);
switch (c) {
case '\\':
case '"':
*p++ = c;
- (*remain)--;
+ len++;
break;
case 'n':
*p++ = '\n';
- (*remain)--;
+ len++;
break;
case 'r':
*p++ = '\r';
- (*remain)--;
+ len++;
break;
case 't':
*p++ = '\t';
- (*remain)--;
+ len++;
break;
case '0':
case '1':
@@ -253,21 +256,21 @@
case '6':
case '7':
i = c - '0';
- c = nextch(fp, lastch, remain);
+ c = nextch(fp, lastch);
for (j = 0; j < 2 && c >= '0' && c <= '7'; j++) {
i <<= 3;
i += c - '0';
- c = nextch(fp, lastch, remain);
+ c = nextch(fp, lastch);
}
putbackch(c, lastch);
*p++ = (char)i;
- (*remain)--;
+ len++;
break;
case 'X':
case 'x':
i = 0;
for (j = 0; j < 2; j++) {
- c = nextch(fp, lastch, remain);
+ c = nextch(fp, lastch);
i <<= 4;
if (c >= '0' && c <= '9') {
i += c - '0';
@@ -286,7 +289,7 @@
goto string_error;
}
*p++ = (char)i;
- (*remain)--;
+ len++;
break;
case EOF:
putbackch(c, lastch);
@@ -294,19 +297,19 @@
goto string_error;
default:
*p++ = c;
- (*remain)--;
+ len++;
break;
}
} else {
*p++ = c;
- (*remain)--;
+ len++;
}
}
*p = '\0';
token = STRING;
break;
case '#':
- while ((c = nextch(fp, lastch, remain)) != '\n' && c != EOF) {
+ while ((c = nextch(fp, lastch)) != '\n' && c != EOF) {
}
if (c == '\n') {
token = ENDOFLINE;
@@ -316,19 +319,23 @@
break;
default:
if (isalnum(c) || c == '_' || c == '-') {
- p = tokenbuf;
+ if (len >= *buflen - 1) {
+ *buflen += BUFSIZ;
+ *tokenbuf = (char *)realloc(*tokenbuf, *buflen);
+ }
+ p = *tokenbuf;
*p++ = c;
- (*remain)--;
- c = nextch(fp, lastch, remain);
+ len++;
+ c = nextch(fp, lastch);
while (isalnum(c) || c == '_' || c == '-') {
+ if (len >= *buflen - 1) {
+ *buflen += BUFSIZ;
+ *tokenbuf = (char *)realloc(*tokenbuf, *buflen);
+ p = *tokenbuf + len;
+ }
*p++ = c;
- (*remain)--;
- c = nextch(fp, lastch, remain);
- }
- if (c == '\n' || c == EOF) {
- putbackch(c, lastch);
- token = ERROR;
- goto string_error;
+ len++;
+ c = nextch(fp, lastch);
}
*p = '\0';
putbackch(c, lastch);
@@ -468,7 +475,7 @@
#define SEQUENCE_MAX 10
static int
-parse_compose_line(FILE *fp, char* tokenbuf, size_t *remain)
+parse_compose_line(FILE *fp, char **tokenbuf, size_t *buflen)
{
int token;
unsigned modifier_mask;
@@ -497,7 +504,7 @@
g_get_charset(&encoding);
do {
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
} while (token == ENDOFLINE);
if (token == ENDOFFILE) {
@@ -506,41 +513,42 @@
n = 0;
do {
- if ((token == KEY) && (strcmp("include", tokenbuf) == 0)) {
+ if ((token == KEY) && (strcmp("include", *tokenbuf) == 0)) {
char *filename;
FILE *infp;
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token != KEY && token != STRING)
goto error;
- if ((filename = TransFileName(tokenbuf)) == NULL)
+ if ((filename = TransFileName(*tokenbuf)) == NULL)
goto error;
infp = fopen(filename, "r");
free(filename);
if (infp == NULL)
goto error;
ParseComposeStringFile(infp);
- return (0);
- } else if ((token == KEY) && (strcmp("None", tokenbuf) == 0)) {
+ fclose(infp);
+ return 0;
+ } else if ((token == KEY) && (strcmp("None", *tokenbuf) == 0)) {
modifier = 0;
modifier_mask = AllMask;
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
} else {
modifier_mask = modifier = 0;
exclam = False;
if (token == EXCLAM) {
exclam = True;
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
}
while (token == TILDE || token == KEY) {
tilde = False;
if (token == TILDE) {
tilde = True;
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token != KEY)
goto error;
}
- tmp = modmask(tokenbuf);
+ tmp = modmask(*tokenbuf);
if (!tmp) {
goto error;
}
@@ -550,7 +558,7 @@
} else {
modifier |= tmp;
}
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
}
if (exclam) {
modifier_mask = AllMask;
@@ -562,17 +570,17 @@
goto error;
}
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token != KEY) {
goto error;
}
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token != GREATER) {
goto error;
}
- keysym = XStringToKeysym(tokenbuf);
+ keysym = XStringToKeysym(*tokenbuf);
if (keysym == NoSymbol) {
goto error;
}
@@ -583,33 +591,33 @@
n++;
if (n >= SEQUENCE_MAX)
goto error;
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
} while (token != COLON);
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token == STRING) {
- if ((rhs_string_mb = (char *)malloc(strlen(tokenbuf) + 1)) == NULL)
+ if ((rhs_string_mb = (char *)malloc(strlen(*tokenbuf) + 1)) == NULL)
goto error;
- strcpy(rhs_string_mb, tokenbuf);
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ strcpy(rhs_string_mb, *tokenbuf);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token == KEY) {
- rhs_keysym = XStringToKeysym(tokenbuf);
+ rhs_keysym = XStringToKeysym(*tokenbuf);
if (rhs_keysym == NoSymbol) {
free(rhs_string_mb);
goto error;
}
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
}
if (token != ENDOFLINE && token != ENDOFFILE) {
free(rhs_string_mb);
goto error;
}
} else if (token == KEY) {
- rhs_keysym = XStringToKeysym(tokenbuf);
+ rhs_keysym = XStringToKeysym(*tokenbuf);
if (rhs_keysym == NoSymbol) {
goto error;
}
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token != ENDOFLINE && token != ENDOFFILE) {
goto error;
}
@@ -674,7 +682,7 @@
return n;
error:
while (token != ENDOFLINE && token != ENDOFFILE) {
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
}
return 0;
}
@@ -682,21 +690,19 @@
static void
ParseComposeStringFile(FILE *fp)
{
- char* tbp;
+ char *tbp, *p[1];
struct stat st;
- size_t tb_remain;
+ size_t buflen = BUFSIZ;
- if (fstat(fileno(fp), &st) != -1 &&
- S_ISREG(st.st_mode) &&
- st.st_size > 0 &&
- st.st_size + (size_t)0 < (off_t)0 + (size_t)-1) {
+ if (fstat(fileno(fp), &st) != -1 && S_ISREG(st.st_mode) &&
+ st.st_size > 0) {
- tbp = (char *)malloc(st.st_size);
- tb_remain = st.st_size;
+ tbp = (char *)malloc(buflen);
+ p[0] = tbp;
if (tbp != NULL) {
- while (parse_compose_line(fp, tbp, &tb_remain) >= 0) {
+ while (parse_compose_line(fp, p, &buflen) >= 0) {
}
- free (tbp);
+ free(p[0]);
}
}
}
Modified: branches/1.4/qt/immodule-quiminputcontext.h
==============================================================================
--- branches/1.4/qt/immodule-quiminputcontext.h (original)
+++ branches/1.4/qt/immodule-quiminputcontext.h Wed Jul 11 05:44:14 2007
@@ -136,7 +136,7 @@
static char *TransFileName( char *name );
static void ParseComposeStringFile( FILE *fp );
static void FreeComposeTree( DefTree *top );
- static int parse_compose_line( FILE *fp, char *tokenbuf, size_t *remain );
+ static int parse_compose_line( FILE *fp, char **tokenbuf, size_t *buflen );
static int get_mb_string( char *buf, unsigned int ks );
static const char *get_encoding( void );
static char *get_lang_region( void );
Modified: branches/1.4/qt/immodule-quiminputcontext_compose.cpp
==============================================================================
--- branches/1.4/qt/immodule-quiminputcontext_compose.cpp (original)
+++ branches/1.4/qt/immodule-quiminputcontext_compose.cpp Wed Jul 11
05:44:14 2007
@@ -264,13 +264,10 @@
}
static int
-nextch(FILE *fp, int *lastch, size_t *remain)
+nextch(FILE *fp, int *lastch)
{
int c;
- if (*remain <= 1)
- return EOF;
-
if (*lastch != 0) {
c = *lastch;
*lastch = 0;
@@ -316,14 +313,15 @@
#endif
static int
-nexttoken(FILE *fp, char *tokenbuf, int *lastch, size_t *remain)
+nexttoken(FILE *fp, char **tokenbuf, int *lastch, size_t *buflen)
{
int c;
int token;
char *p;
int i, j;
+ size_t len = 0;
- while ((c = nextch(fp, lastch, remain)) == ' ' || c == '\t') {
+ while ((c = nextch(fp, lastch)) == ' ' || c == '\t') {
}
switch (c) {
case EOF:
@@ -348,31 +346,36 @@
token = TILDE;
break;
case '"':
- p = tokenbuf;
- while ((c = nextch(fp, lastch, remain)) != '"') {
+ p = *tokenbuf;
+ while ((c = nextch(fp, lastch)) != '"') {
+ if (len >= *buflen - 1) {
+ *buflen += BUFSIZ;
+ *tokenbuf = (char *)realloc(*tokenbuf, *buflen);
+ p = *tokenbuf + len;
+ }
if (c == '\n' || c == EOF) {
putbackch(c, lastch);
token = ERROR;
goto string_error;
} else if (c == '\\') {
- c = nextch(fp, lastch, remain);
+ c = nextch(fp, lastch);
switch (c) {
case '\\':
case '"':
*p++ = c;
- (*remain)--;
+ len++;
break;
case 'n':
*p++ = '\n';
- (*remain)--;
+ len++;
break;
case 'r':
*p++ = '\r';
- (*remain)--;
+ len++;
break;
case 't':
*p++ = '\t';
- (*remain)--;
+ len++;
break;
case '0':
case '1':
@@ -383,21 +386,21 @@
case '6':
case '7':
i = c - '0';
- c = nextch(fp, lastch, remain);
+ c = nextch(fp, lastch);
for (j = 0; j < 2 && c >= '0' && c <= '7'; j++) {
i <<= 3;
i += c - '0';
- c = nextch(fp, lastch, remain);
+ c = nextch(fp, lastch);
}
putbackch(c, lastch);
*p++ = (char)i;
- (*remain)--;
+ len++;
break;
case 'X':
case 'x':
i = 0;
for (j = 0; j < 2; j++) {
- c = nextch(fp, lastch, remain);
+ c = nextch(fp, lastch);
i <<= 4;
if (c >= '0' && c <= '9') {
i += c - '0';
@@ -416,7 +419,7 @@
goto string_error;
}
*p++ = (char)i;
- (*remain)--;
+ len++;
break;
case EOF:
putbackch(c, lastch);
@@ -424,19 +427,19 @@
goto string_error;
default:
*p++ = c;
- (*remain)--;
+ len++;
break;
}
} else {
*p++ = c;
- (*remain)--;
+ len++;
}
}
*p = '\0';
token = STRING;
break;
case '#':
- while ((c = nextch(fp, lastch, remain)) != '\n' && c != EOF) {
+ while ((c = nextch(fp, lastch)) != '\n' && c != EOF) {
}
if (c == '\n') {
token = ENDOFLINE;
@@ -446,19 +449,23 @@
break;
default:
if (isalnum(c) || c == '_' || c == '-') {
- p = tokenbuf;
+ if (len >= *buflen - 1) {
+ *buflen += BUFSIZ;
+ *tokenbuf = (char *)realloc(*tokenbuf, *buflen);
+ }
+ p = *tokenbuf;
*p++ = c;
- (*remain)--;
- c = nextch(fp, lastch, remain);
+ len++;
+ c = nextch(fp, lastch);
while (isalnum(c) || c == '_' || c == '-') {
+ if (len >= *buflen - 1) {
+ *buflen += BUFSIZ;
+ *tokenbuf = (char *)realloc(*tokenbuf, *buflen);
+ p = *tokenbuf + len;
+ }
*p++ = c;
- (*remain)--;
- c = nextch(fp, lastch, remain);
- }
- if (c == '\n' || c == EOF) {
- putbackch(c, lastch);
- token = ERROR;
- goto string_error;
+ len++;
+ c = nextch(fp, lastch);
}
*p = '\0';
putbackch(c, lastch);
@@ -622,7 +629,7 @@
#define SEQUENCE_MAX 10
int
-QUimInputContext::parse_compose_line(FILE *fp, char* tokenbuf, size_t *remain)
+QUimInputContext::parse_compose_line(FILE *fp, char **tokenbuf, size_t *buflen)
{
int token;
unsigned modifier_mask;
@@ -651,7 +658,7 @@
QString qs;
do {
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
} while (token == ENDOFLINE);
if (token == ENDOFFILE) {
@@ -660,41 +667,42 @@
n = 0;
do {
- if ((token == KEY) && (strcmp("include", tokenbuf) == 0)) {
+ if ((token == KEY) && (strcmp("include", *tokenbuf) == 0)) {
char *filename;
FILE *infp;
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token != KEY && token != STRING)
goto error;
- if ((filename = TransFileName(tokenbuf)) == NULL)
+ if ((filename = TransFileName(*tokenbuf)) == NULL)
goto error;
infp = fopen(filename, "r");
free(filename);
if (infp == NULL)
goto error;
ParseComposeStringFile(infp);
- return (0);
- } else if ((token == KEY) && (strcmp("None", tokenbuf) == 0)) {
+ fclose(infp);
+ return 0;
+ } else if ((token == KEY) && (strcmp("None", *tokenbuf) == 0)) {
modifier = 0;
modifier_mask = AllMask;
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
} else {
modifier_mask = modifier = 0;
exclam = False;
if (token == EXCLAM) {
exclam = True;
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
}
while (token == TILDE || token == KEY) {
tilde = False;
if (token == TILDE) {
tilde = True;
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token != KEY)
goto error;
}
- tmp = modmask(tokenbuf);
+ tmp = modmask(*tokenbuf);
if (!tmp) {
goto error;
}
@@ -704,7 +712,7 @@
} else {
modifier |= tmp;
}
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
}
if (exclam) {
modifier_mask = AllMask;
@@ -716,17 +724,17 @@
goto error;
}
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token != KEY) {
goto error;
}
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token != GREATER) {
goto error;
}
- keysym = XStringToKeysym(tokenbuf);
+ keysym = XStringToKeysym(*tokenbuf);
if (keysym == NoSymbol) {
goto error;
}
@@ -737,33 +745,33 @@
n++;
if (n >= SEQUENCE_MAX)
goto error;
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
} while (token != COLON);
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token == STRING) {
- if ((rhs_string_mb = (char *)malloc(strlen(tokenbuf) + 1)) == NULL)
+ if ((rhs_string_mb = (char *)malloc(strlen(*tokenbuf) + 1)) == NULL)
goto error;
- strcpy(rhs_string_mb, tokenbuf);
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ strcpy(rhs_string_mb, *tokenbuf);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token == KEY) {
- rhs_keysym = XStringToKeysym(tokenbuf);
+ rhs_keysym = XStringToKeysym(*tokenbuf);
if (rhs_keysym == NoSymbol) {
free(rhs_string_mb);
goto error;
}
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
}
if (token != ENDOFLINE && token != ENDOFFILE) {
free(rhs_string_mb);
goto error;
}
} else if (token == KEY) {
- rhs_keysym = XStringToKeysym(tokenbuf);
+ rhs_keysym = XStringToKeysym(*tokenbuf);
if (rhs_keysym == NoSymbol) {
goto error;
}
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token != ENDOFLINE && token != ENDOFFILE) {
goto error;
}
@@ -824,7 +832,7 @@
return n;
error:
while (token != ENDOFLINE && token != ENDOFFILE) {
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
}
return 0;
}
@@ -847,21 +855,19 @@
void
QUimInputContext::ParseComposeStringFile(FILE *fp)
{
- char* tbp;
+ char *tbp, *p[1];
struct stat st;
- size_t tb_remain;
+ size_t buflen = BUFSIZ;
- if (fstat(fileno(fp), &st) != -1 &&
- S_ISREG(st.st_mode) &&
- st.st_size > 0 &&
- st.st_size + (size_t)0 < (off_t)0 + (size_t)-1) {
+ if (fstat(fileno(fp), &st) != -1 && S_ISREG(st.st_mode) &&
+ st.st_size > 0) {
- tbp = (char *)malloc(st.st_size);
- tb_remain = st.st_size;
+ tbp = (char *)malloc(buflen);
+ p[0] = tbp;
if (tbp != NULL) {
- while (parse_compose_line(fp, tbp, &tb_remain) >= 0) {
+ while (parse_compose_line(fp, p, &buflen) >= 0) {
}
- free (tbp);
+ free(p[0]);
}
}
}
Modified: branches/1.4/xim/compose.cpp
==============================================================================
--- branches/1.4/xim/compose.cpp (original)
+++ branches/1.4/xim/compose.cpp Wed Jul 11 05:44:14 2007
@@ -117,13 +117,10 @@
}
static int
-nextch(FILE *fp, int *lastch, size_t *remain)
+nextch(FILE *fp, int *lastch)
{
int c;
- if (*remain <= 1)
- return EOF;
-
if (*lastch != 0) {
c = *lastch;
*lastch = 0;
@@ -169,14 +166,15 @@
#endif
static int
-nexttoken(FILE *fp, char *tokenbuf, int *lastch, size_t *remain)
+nexttoken(FILE *fp, char **tokenbuf, int *lastch, size_t *buflen)
{
int c;
int token;
char *p;
int i, j;
+ size_t len = 0;
- while ((c = nextch(fp, lastch, remain)) == ' ' || c == '\t') {
+ while ((c = nextch(fp, lastch)) == ' ' || c == '\t') {
}
switch (c) {
case EOF:
@@ -201,31 +199,36 @@
token = TILDE;
break;
case '"':
- p = tokenbuf;
- while ((c = nextch(fp, lastch, remain)) != '"') {
+ p = *tokenbuf;
+ while ((c = nextch(fp, lastch)) != '"') {
+ if (len >= *buflen - 1) {
+ *buflen += BUFSIZ;
+ *tokenbuf = (char *)realloc(*tokenbuf, *buflen);
+ p = *tokenbuf + len;
+ }
if (c == '\n' || c == EOF) {
putbackch(c, lastch);
token = ERROR;
goto string_error;
} else if (c == '\\') {
- c = nextch(fp, lastch, remain);
+ c = nextch(fp, lastch);
switch (c) {
case '\\':
case '"':
*p++ = c;
- (*remain)--;
+ len++;
break;
case 'n':
*p++ = '\n';
- (*remain)--;
+ len++;
break;
case 'r':
*p++ = '\r';
- (*remain)--;
+ len++;
break;
case 't':
*p++ = '\t';
- (*remain)--;
+ len++;
break;
case '0':
case '1':
@@ -236,21 +239,21 @@
case '6':
case '7':
i = c - '0';
- c = nextch(fp, lastch, remain);
+ c = nextch(fp, lastch);
for (j = 0; j < 2 && c >= '0' && c <= '7'; j++) {
i <<= 3;
i += c - '0';
- c = nextch(fp, lastch, remain);
+ c = nextch(fp, lastch);
}
putbackch(c, lastch);
*p++ = (char)i;
- (*remain)--;
+ len++;
break;
case 'X':
case 'x':
i = 0;
for (j = 0; j < 2; j++) {
- c = nextch(fp, lastch, remain);
+ c = nextch(fp, lastch);
i <<= 4;
if (c >= '0' && c <= '9') {
i += c - '0';
@@ -269,7 +272,7 @@
goto string_error;
}
*p++ = (char)i;
- (*remain)--;
+ len++;
break;
case EOF:
putbackch(c, lastch);
@@ -277,19 +280,19 @@
goto string_error;
default:
*p++ = c;
- (*remain)--;
+ len++;
break;
}
} else {
*p++ = c;
- (*remain)--;
+ len++;
}
}
*p = '\0';
token = STRING;
break;
case '#':
- while ((c = nextch(fp, lastch, remain)) != '\n' && c != EOF) {
+ while ((c = nextch(fp, lastch)) != '\n' && c != EOF) {
}
if (c == '\n') {
token = ENDOFLINE;
@@ -299,19 +302,23 @@
break;
default:
if (isalnum(c) || c == '_' || c == '-') {
- p = tokenbuf;
+ if (len >= *buflen - 1) {
+ *buflen += BUFSIZ;
+ *tokenbuf = (char *)realloc(*tokenbuf, *buflen);
+ }
+ p = *tokenbuf;
*p++ = c;
- (*remain)--;
- c = nextch(fp, lastch, remain);
+ len++;
+ c = nextch(fp, lastch);
while (isalnum(c) || c == '_' || c == '-') {
+ if (len >= *buflen - 1) {
+ *buflen += BUFSIZ;
+ *tokenbuf = (char *)realloc(*tokenbuf, *buflen);
+ p = *tokenbuf + len;
+ }
*p++ = c;
- (*remain)--;
- c = nextch(fp, lastch, remain);
- }
- if (c == '\n' || c == EOF) {
- putbackch(c, lastch);
- token = ERROR;
- goto string_error;
+ len++;
+ c = nextch(fp, lastch);
}
*p = '\0';
putbackch(c, lastch);
@@ -451,7 +458,7 @@
#define SEQUENCE_MAX 10
int
-XimIM::parse_compose_line(FILE *fp, char* tokenbuf, size_t *remain)
+XimIM::parse_compose_line(FILE *fp, char **tokenbuf, size_t *buflen)
{
int token;
unsigned modifier_mask;
@@ -479,7 +486,7 @@
const char *encoding = get_encoding();;
do {
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
} while (token == ENDOFLINE);
if (token == ENDOFFILE) {
@@ -488,41 +495,42 @@
n = 0;
do {
- if ((token == KEY) && (strcmp("include", tokenbuf) == 0)) {
+ if ((token == KEY) && (strcmp("include", *tokenbuf) == 0)) {
char *filename;
FILE *infp;
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token != KEY && token != STRING)
goto error;
- if ((filename = TransFileName(tokenbuf)) == NULL)
+ if ((filename = TransFileName(*tokenbuf)) == NULL)
goto error;
infp = fopen(filename, "r");
free(filename);
if (infp == NULL)
goto error;
ParseComposeStringFile(infp);
- return (0);
- } else if ((token == KEY) && (strcmp("None", tokenbuf) == 0)) {
+ fclose(infp);
+ return 0;
+ } else if ((token == KEY) && (strcmp("None", *tokenbuf) == 0)) {
modifier = 0;
modifier_mask = AllMask;
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
} else {
modifier_mask = modifier = 0;
exclam = False;
if (token == EXCLAM) {
exclam = True;
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
}
while (token == TILDE || token == KEY) {
tilde = False;
if (token == TILDE) {
tilde = True;
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token != KEY)
goto error;
}
- tmp = modmask(tokenbuf);
+ tmp = modmask(*tokenbuf);
if (!tmp) {
goto error;
}
@@ -532,7 +540,7 @@
} else {
modifier |= tmp;
}
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
}
if (exclam) {
modifier_mask = AllMask;
@@ -544,17 +552,17 @@
goto error;
}
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token != KEY) {
goto error;
}
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token != GREATER) {
goto error;
}
- keysym = XStringToKeysym(tokenbuf);
+ keysym = XStringToKeysym(*tokenbuf);
if (keysym == NoSymbol) {
goto error;
}
@@ -565,33 +573,33 @@
n++;
if (n >= SEQUENCE_MAX)
goto error;
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
} while (token != COLON);
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token == STRING) {
- if ((rhs_string_mb = (char *)malloc(strlen(tokenbuf) + 1)) == NULL)
+ if ((rhs_string_mb = (char *)malloc(strlen(*tokenbuf) + 1)) == NULL)
goto error;
- strcpy(rhs_string_mb, tokenbuf);
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ strcpy(rhs_string_mb, *tokenbuf);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token == KEY) {
- rhs_keysym = XStringToKeysym(tokenbuf);
+ rhs_keysym = XStringToKeysym(*tokenbuf);
if (rhs_keysym == NoSymbol) {
free(rhs_string_mb);
goto error;
}
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
}
if (token != ENDOFLINE && token != ENDOFFILE) {
free(rhs_string_mb);
goto error;
}
} else if (token == KEY) {
- rhs_keysym = XStringToKeysym(tokenbuf);
+ rhs_keysym = XStringToKeysym(*tokenbuf);
if (rhs_keysym == NoSymbol) {
goto error;
}
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
if (token != ENDOFLINE && token != ENDOFFILE) {
goto error;
}
@@ -659,7 +667,7 @@
return n;
error:
while (token != ENDOFLINE && token != ENDOFFILE) {
- token = nexttoken(fp, tokenbuf, &lastch, remain);
+ token = nexttoken(fp, tokenbuf, &lastch, buflen);
}
return 0;
}
@@ -667,21 +675,19 @@
void
XimIM::ParseComposeStringFile(FILE *fp)
{
- char* tbp;
+ char *tbp, *p[1];
struct stat st;
- size_t tb_remain;
+ size_t buflen = BUFSIZ;
- if (fstat(fileno(fp), &st) != -1 &&
- S_ISREG(st.st_mode) &&
- st.st_size > 0 &&
- st.st_size + (size_t)0 < (off_t)0 + (size_t)-1) {
+ if (fstat(fileno(fp), &st) != -1 && S_ISREG(st.st_mode) &&
+ st.st_size > 0) {
- tbp = (char *)malloc(st.st_size);
- tb_remain = st.st_size;
+ tbp = (char *)malloc(buflen);
+ p[0] = tbp;
if (tbp != NULL) {
- while (parse_compose_line(fp, tbp, &tb_remain) >= 0) {
+ while (parse_compose_line(fp, p, &buflen) >= 0) {
}
- free (tbp);
+ free(p[0]);
}
}
}
Modified: branches/1.4/xim/xim.h
==============================================================================
--- branches/1.4/xim/xim.h (original)
+++ branches/1.4/xim/xim.h Wed Jul 11 05:44:14 2007
@@ -211,7 +211,7 @@
char *TransFileName(char *name);
void ParseComposeStringFile(FILE *fp);
void FreeComposeTree(DefTree *top);
- int parse_compose_line(FILE *fp, char *tokenbuf, size_t *remain);
+ int parse_compose_line(FILE *fp, char **tokenbuf, size_t *buflen);
int get_mb_string(char *buf, KeySym ks);
DefTree *mTreeTop;
};