summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorknarf <knarf@17b73243-c579-4c4c-a9d2-2d5706c11dac>2011-01-06 16:55:02 +0000
committerknarf <knarf@17b73243-c579-4c4c-a9d2-2d5706c11dac>2011-01-06 16:55:02 +0000
commitafddb4800c5bebd1d3b97a4e3529921a2a1c9bc5 (patch)
treef2bb6a594d6cf73f1d454c0c3a9c716c60679fb1 /src/util
parent18fc4c55ce4333defc443a2e0a9c64f6e55db607 (diff)
from Ian Hinder:
Correctly load parameter files with DOS line-endings Before this commit, when a parameter file with DOS line-endings was used, certain features of Cactus did not work correctly. For example, setting an output directory of $parfile would create an output directory named "$parfile" instead of expanding the parameter filename. This commit converts any CR-LF sequences to LF immediately after the parameter file is loaded. git-svn-id: http://svn.cactuscode.org/flesh/trunk@4663 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/util')
-rw-r--r--src/util/ParseFile.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/util/ParseFile.c b/src/util/ParseFile.c
index 34e4f02a..7ccb9b20 100644
--- a/src/util/ParseFile.c
+++ b/src/util/ParseFile.c
@@ -42,6 +42,7 @@ static void CheckBuf(int, int);
static void removeSpaces(char *stripMe);
static char *ReadFile(FILE *file, unsigned long *filesize);
static char *ParseDefines(char *buffer, unsigned long *buffersize);
+static char *convert_crlf_to_lf(const char *buffer);
int ParseBuffer(char *buffer,
int (*set_function)(const char *, const char *, int),
tFleshConfig *ConfigData);
@@ -127,8 +128,16 @@ int ParseFile(FILE *ifp,
int retval;
unsigned long buffersize;
char *buffer = ReadFile(ifp, &buffersize);
+ char *buffer2 = NULL;
if (!buffer)
return 1;
+
+ /* Ensure Unix line endings */
+ buffer2 = convert_crlf_to_lf(buffer);
+ free(buffer);
+ buffer = buffer2;
+ buffersize = strlen(buffer);
+
buffer = ParseDefines(buffer, &buffersize);
/* ParseBuffer can get confused with detecting the end of the buffer
(when in a comment or in a string), and may overrun. Therefore
@@ -235,6 +244,33 @@ static void removeSpaces(char *stripMe)
free(s);
}
+/* Convert string CRLF line endings to LF */
+char *convert_crlf_to_lf(const char *buffer)
+{
+ int dropped = 0;
+ int len = strlen(buffer);
+ char *buffer2 = malloc(len+1);
+ assert(buffer2);
+ char *to = buffer2;
+ const char *p = NULL;
+
+ for (p = buffer; p < buffer+len+1; p++)
+ {
+ int is_crlf = (*p == '\r' && p < buffer + len && *(p+1) == '\n');
+ if (!is_crlf)
+ {
+ *to = *p;
+ to++;
+ }
+ else
+ {
+ dropped++;
+ }
+ }
+
+ return buffer2;
+}
+
/* #define TEST_ParseFile */