From c03cb2c97ad8a1c68a3aaff0de8fb96056b26635 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Wed, 28 Dec 2016 12:03:17 +0200 Subject: [PATCH] Added support for long lines in config file Single line key-value pair can now exceed 255 characters Long path names and additional command line parameters (macOS only) are no longer cut off --- src/configfile.cpp | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/configfile.cpp b/src/configfile.cpp index ccc6f8e79..d56e74e9a 100644 --- a/src/configfile.cpp +++ b/src/configfile.cpp @@ -643,15 +643,21 @@ bool FConfigFile::ReadConfig (void *file) { continue; } - // Remove white space at end of line - endpt = start + strlen (start) - 1; - while (endpt > start && *endpt <= ' ') + // Do not process tail of long line + const bool longline = 255 == strlen(readbuf) && '\n' != readbuf[254]; + if (!longline) { - endpt--; + // Remove white space at end of line + endpt = start + strlen (start) - 1; + while (endpt > start && *endpt <= ' ') + { + endpt--; + } + // Remove line feed '\n' character + endpt[1] = 0; + if (endpt <= start) + continue; // Nothing here } - endpt[1] = 0; - if (endpt <= start) - continue; // Nothing here if (*start == '[') { // Section header @@ -687,6 +693,31 @@ bool FConfigFile::ReadConfig (void *file) { ReadMultiLineValue (file, section, start, whiteprobe + 3); } + else if (longline) + { + const FString key = start; + FString value = whiteprobe; + + while (ReadLine (readbuf, READBUFFERSIZE, file) != NULL) + { + const size_t endpos = (0 == readbuf[0]) ? 0 : (strlen(readbuf) - 1); + const bool endofline = '\n' == readbuf[endpos]; + + if (endofline) + { + readbuf[endpos] = 0; + } + + value += readbuf; + + if (endofline) + { + break; + } + } + + NewConfigEntry (section, key.GetChars(), value.GetChars()); + } else { NewConfigEntry (section, start, whiteprobe);