From 83232eb556ec436f01af42b28a43e6f780f57af2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 7 Jun 2020 10:10:51 +0200 Subject: [PATCH] remove legacy filereader code --- src/kernel/save.c | 1 - src/orderfile.c | 1 - src/util/CMakeLists.txt | 2 - src/util/filereader.c | 198 ---------------------------------------- src/util/filereader.h | 14 --- 5 files changed, 216 deletions(-) delete mode 100644 src/util/filereader.c delete mode 100644 src/util/filereader.h diff --git a/src/kernel/save.c b/src/kernel/save.c index 4d9574a61..b401256ae 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -43,7 +43,6 @@ #include #include #include -#include #include #include #include diff --git a/src/orderfile.c b/src/orderfile.c index a42d5ee69..0f0c951a2 100644 --- a/src/orderfile.c +++ b/src/orderfile.c @@ -11,7 +11,6 @@ #include "util/message.h" #include "util/language.h" #include "util/log.h" -#include "util/filereader.h" #include "util/param.h" #include "util/parser.h" #include "util/password.h" diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 19bf70b12..eeb16df1a 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -6,7 +6,6 @@ SET(_TEST_FILES base36.test.c # crmessage.test.c # dice.test.c -# filereader.test.c functions.test.c # goodies.test.c keyword.test.c @@ -35,7 +34,6 @@ SET(_FILES base36.c crmessage.c dice.c -filereader.c functions.c goodies.c keyword.c diff --git a/src/util/filereader.c b/src/util/filereader.c deleted file mode 100644 index 5973c8f1c..000000000 --- a/src/util/filereader.c +++ /dev/null @@ -1,198 +0,0 @@ -#include -#include "filereader.h" - -#include -#include - -#include -#include -#include - -#define COMMENT_CHAR ';' -#define CONTINUE_CHAR '\\' -#define MAXLINE 4096*16 -static char lbuf[MAXLINE]; -static char fbuf[MAXLINE]; - -static void unicode_warning(const char *bp) -{ - log_warning("invalid sequence in UTF-8 string: %s\n", bp); -} - -static int eatwhite(const char *ptr, size_t * total_size) -{ - int ret = 0; - - *total_size = 0; - - while (*ptr) { - wint_t wc; - size_t size = 0; - ret = unicode_utf8_decode(&wc, ptr, &size); - if (ret != 0) - break; - if (!iswspace(wc)) - break; - *total_size += size; - ptr += size; - } - return ret; -} - -static const char *getbuf_utf8(FILE * F) -{ - bool cont = false; - char quote = 0; - bool comment = false; - char *cp = fbuf; - char *tail = lbuf + MAXLINE - 2; - - tail[1] = '@'; /* if this gets overwritten by fgets then the line was very long. */ - do { - const char *bp = fgets(lbuf, MAXLINE, F); - size_t white; - if (bp == NULL) { - return NULL; - } - - eatwhite(bp, &white); /* decoding errors will get caught later on, don't have to check */ - bp += white; - - comment = (comment && cont); - quote = (quote && cont); - - if (tail[1] == 0) { - /* we read the maximum number of bytes! */ - if (tail[0] != '\n') { - /* it wasn't enough space to finish the line, eat the rest */ - for (;;) { - tail[1] = '@'; - bp = fgets(lbuf, MAXLINE, F); - if (bp == NULL) - return NULL; - if (tail[1]) { - /* read enough this time to end the line */ - break; - } - } - comment = false; - cont = false; - bp = NULL; - continue; - } - else { - tail[1] = '@'; - } - } - cont = false; - while (*bp && cp < fbuf + MAXLINE) { - wint_t wc; - size_t size; - int ret; - - if (!quote) { - while (*bp == COMMENT_CHAR) { - /* comment begins. we need to keep going, to look for CONTINUE_CHAR */ - comment = true; - ++bp; - } - } - - if (*bp == '\n' || *bp == '\r') { - /* line breaks, shmine breaks */ - break; - } - - if (*bp == '"' || *bp == '\'') { - if (quote == *bp) { - quote = 0; - if (!comment && cp < fbuf + MAXLINE) - *cp++ = *bp; - ++bp; - continue; - } - else if (!quote) { - quote = *bp++; - if (!comment && cp < fbuf + MAXLINE) - *cp++ = quote; - continue; - } - } - - ret = unicode_utf8_decode(&wc, bp, &size); - - if (ret != 0) { - unicode_warning(bp); - break; - } - - if (iswspace(wc)) { - if (!quote) { - bp += size; - ret = eatwhite(bp, &size); - bp += size; - if (!comment && *bp && *bp != COMMENT_CHAR && cp < fbuf + MAXLINE) - *(cp++) = ' '; - if (ret != 0) { - unicode_warning(bp); - break; - } - } - else if (!comment) { - if (cp + size <= fbuf + MAXLINE) { - while (size--) { - *(cp++) = *(bp++); - } - } - else - bp += size; - } - else { - bp += size; - } - } - else if (iswcntrl(wc)) { - if (!comment && cp < fbuf + MAXLINE) { - *cp++ = '?'; - } - bp += size; - } - else { - if (*bp == CONTINUE_CHAR) { - const char *handle_end; - eatwhite(bp + 1, &white); - handle_end = bp + 1 + white; - if (*handle_end == '\0') { - bp = handle_end; - cont = true; - continue; - } - if (!comment && cp < fbuf + MAXLINE) - *cp++ = *bp++; - else - ++bp; - } - else { - if (!comment && cp + size <= fbuf + MAXLINE) { - while (size--) { - *(cp++) = *(bp++); - } - } - else { - bp += size; - } - } - } - } - if (cp == fbuf + MAXLINE) { - --cp; - } - *cp = 0; - } while (cont || cp == fbuf); - return fbuf; -} - -const char *getbuf(FILE * F) -{ - return getbuf_utf8(F); -} diff --git a/src/util/filereader.h b/src/util/filereader.h deleted file mode 100644 index 53c24f697..000000000 --- a/src/util/filereader.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef UTIL_FILEREADER_H -#define UTIL_FILEREADER_H - -#include -#ifdef __cplusplus -extern "C" { -#endif - - const char *getbuf(FILE *); - -#ifdef __cplusplus -} -#endif -#endif