Discard too long lines in dictionary file (#14)

* Discard too long lines in dictionary file

* Discard too long lines in dictionary file: add warning and test
This commit is contained in:
Bartek Fabiszewski 2017-11-27 12:19:26 +01:00 committed by phajdan
parent a8d50da0cc
commit 73dd2967c8
6 changed files with 39 additions and 4 deletions

View File

@ -439,10 +439,24 @@ for (k = 0; k < 2; k++) {
if (k == 0 || nextlevel) { if (k == 0 || nextlevel) {
while (fgets(buf, sizeof(buf), f) != NULL) { while (fgets(buf, sizeof(buf), f) != NULL) {
/* discard lines that don't fit in buffer */
if (!feof(f) && strchr(buf, '\n') == NULL) {
int c;
while ((c = fgetc(f)) != '\n' && c != EOF);
/* issue warning if not a comment */
if (buf[0] != '%') {
fprintf(stderr, "Warning: skipping too long pattern (more than %lu chars)\n", sizeof(buf));
}
continue;
}
if (strncmp(buf, "NEXTLEVEL", 9) == 0) { if (strncmp(buf, "NEXTLEVEL", 9) == 0) {
nextlevel = 1; nextlevel = 1;
break; break;
} else if (buf[0] != '%') hnj_hyphen_load_line(buf, dict[k], hashtab); } else if (buf[0] != '%') {
hnj_hyphen_load_line(buf, dict[k], hashtab);
}
} }
} else if (k == 1) { } else if (k == 1) {
/* default first level: hyphen and ASCII apostrophe */ /* default first level: hyphen and ASCII apostrophe */

View File

@ -11,6 +11,7 @@ alt4.test \
alt5.test \ alt5.test \
alt6.test \ alt6.test \
alt7.test \ alt7.test \
longlines.test \
compound.test \ compound.test \
compound2.test \ compound2.test \
compound3.test \ compound3.test \
@ -50,6 +51,9 @@ alt6.word \
alt7.hyph \ alt7.hyph \
alt7.pat \ alt7.pat \
alt7.word \ alt7.word \
longlines.hyph \
longlines.pat \
longlines.word \
alt.hyph \ alt.hyph \
alt.pat \ alt.pat \
alt.word \ alt.word \
@ -105,6 +109,7 @@ alt4.test \
alt5.test \ alt5.test \
alt6.test \ alt6.test \
alt7.test \ alt7.test \
longlines.test \
alt.test \ alt.test \
basealt2.test \ basealt2.test \
basealt.test \ basealt.test \

1
tests/longlines.hyph Normal file
View File

@ -0,0 +1 @@
a=bc=d

10
tests/longlines.pat Normal file
View File

@ -0,0 +1,10 @@
ISO8859-1
LEFTHYPHENMIN 1
RIGHTHYPHENMIN 1
% Check whether characters over MAX_CHARS are not treated as new line
% This test is valid as long as MAX_CHARS is 100
%
% Following pattern should result in a=bc=d hyphenation
a1b2c1d
% and should not be overriden by pattern from too long comment (over MAX_CHARS characters)
%|------------------------------ this part is 100 characters long --------------------------------|a8b9c8d

4
tests/longlines.test Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
DIR="`dirname $0`"
NAME="`basename $0 .test`"
$DIR/test.sh $NAME.pat $NAME.word $NAME.hyph

1
tests/longlines.word Normal file
View File

@ -0,0 +1 @@
abcd