summaryrefslogtreecommitdiffstats
path: root/intl
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-05-31 09:45:25 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-05-31 09:45:25 +0200
commit2d4ff8df91414b42974c72b2870f5c6e9ad397a8 (patch)
tree15b23dc6494a147e723cfdb3765be1568cf6c113 /intl
parentf4b8be889cb7ee31a62af5660f36aaa192599009 (diff)
parent14eb8dc7bee8670e39d1199591d335579601f2ad (diff)
downloadUXP-2d4ff8df91414b42974c72b2870f5c6e9ad397a8.tar
UXP-2d4ff8df91414b42974c72b2870f5c6e9ad397a8.tar.gz
UXP-2d4ff8df91414b42974c72b2870f5c6e9ad397a8.tar.lz
UXP-2d4ff8df91414b42974c72b2870f5c6e9ad397a8.tar.xz
UXP-2d4ff8df91414b42974c72b2870f5c6e9ad397a8.zip
Merge branch 'master' into Basilisk-release
Diffstat (limited to 'intl')
-rw-r--r--intl/hyphenation/glue/hnjalloc.h6
-rw-r--r--intl/hyphenation/glue/hnjstdio.cpp51
-rw-r--r--intl/hyphenation/hyphen/hyphen.c22
3 files changed, 60 insertions, 19 deletions
diff --git a/intl/hyphenation/glue/hnjalloc.h b/intl/hyphenation/glue/hnjalloc.h
index fec3a4bc9..5cee1be1b 100644
--- a/intl/hyphenation/glue/hnjalloc.h
+++ b/intl/hyphenation/glue/hnjalloc.h
@@ -31,6 +31,8 @@
#define fopen(path,mode) hnjFopen(path,mode)
#define fclose(file) hnjFclose(file)
#define fgets(buf,count,file) hnjFgets(buf,count,file)
+#define feof(file) hnjFeof(file)
+#define fgetc(file) hnjFgetc(file)
typedef struct hnjFile_ hnjFile;
@@ -44,6 +46,10 @@ int hnjFclose(hnjFile* f);
char* hnjFgets(char* s, int n, hnjFile* f);
+int hnjFeof(hnjFile* f);
+
+int hnjFgetc(hnjFile* f);
+
#ifdef __cplusplus
}
#endif
diff --git a/intl/hyphenation/glue/hnjstdio.cpp b/intl/hyphenation/glue/hnjstdio.cpp
index 660ebaf13..5be8b7c1d 100644
--- a/intl/hyphenation/glue/hnjstdio.cpp
+++ b/intl/hyphenation/glue/hnjstdio.cpp
@@ -22,6 +22,7 @@ struct hnjFile_ {
char mBuffer[BUFSIZE];
uint32_t mCurPos;
uint32_t mLimit;
+ bool mEOF;
};
// replacement for fopen()
@@ -58,6 +59,7 @@ hnjFopen(const char* aURISpec, const char* aMode)
f->mStream = instream;
f->mCurPos = 0;
f->mLimit = 0;
+ f->mEOF = false;
return f;
}
@@ -79,6 +81,27 @@ hnjFclose(hnjFile* f)
return result;
}
+// replacement for fgetc()
+int
+hnjFgetc(hnjFile* f)
+{
+ if (f->mCurPos >= f->mLimit) {
+ f->mCurPos = 0;
+
+ nsresult rv = f->mStream->Read(f->mBuffer, BUFSIZE, &f->mLimit);
+ if (NS_FAILED(rv)) {
+ f->mLimit = 0;
+ }
+
+ if (f->mLimit == 0) {
+ f->mEOF = true;
+ return EOF;
+ }
+ }
+
+ return f->mBuffer[f->mCurPos++];
+}
+
// replacement for fgets()
// (not a full reimplementation, but sufficient for libhyphen's needs)
char*
@@ -88,24 +111,15 @@ hnjFgets(char* s, int n, hnjFile* f)
int i = 0;
while (i < n - 1) {
- if (f->mCurPos < f->mLimit) {
- char c = f->mBuffer[f->mCurPos++];
- s[i++] = c;
- if (c == '\n' || c == '\r') {
- break;
- }
- continue;
- }
-
- f->mCurPos = 0;
+ int c = hnjFgetc(f);
- nsresult rv = f->mStream->Read(f->mBuffer, BUFSIZE, &f->mLimit);
- if (NS_FAILED(rv)) {
- f->mLimit = 0;
- return nullptr;
+ if (c == EOF) {
+ break;
}
- if (f->mLimit == 0) {
+ s[i++] = c;
+
+ if (c == '\n' || c == '\r') {
break;
}
}
@@ -117,3 +131,10 @@ hnjFgets(char* s, int n, hnjFile* f)
s[i] = '\0'; // null-terminate the returned string
return s;
}
+
+
+int
+hnjFeof(hnjFile* f)
+{
+ return f->mEOF ? EOF : 0;
+} \ No newline at end of file
diff --git a/intl/hyphenation/hyphen/hyphen.c b/intl/hyphenation/hyphen/hyphen.c
index 9a132d026..9f2b7112c 100644
--- a/intl/hyphenation/hyphen/hyphen.c
+++ b/intl/hyphenation/hyphen/hyphen.c
@@ -438,11 +438,25 @@ for (k = 0; k < 2; k++) {
}
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) {
- nextlevel = 1;
- break;
- } else if (buf[0] != '%') hnj_hyphen_load_line(buf, dict[k], hashtab);
+ nextlevel = 1;
+ break;
+ } else if (buf[0] != '%') {
+ hnj_hyphen_load_line(buf, dict[k], hashtab);
+ }
}
} else if (k == 1) {
/* default first level: hyphen and ASCII apostrophe */