Skip to content

Commit 4f93253

Browse files
authored
Merge pull request #11 from olli4/master
Add support for Windows-style carriage return line feed in input files
2 parents 5a40ade + 6763091 commit 4f93253

File tree

12 files changed

+5256
-5256
lines changed

12 files changed

+5256
-5256
lines changed

SIPNEToptsIn/frontend.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ int main(int argc, char *argv[]) {
153153

154154
// do each run, output to fileName#.out
155155
runNum = 1;
156-
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0)) {
156+
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0) && (strcmp(line, "\r\n") != 0)) {
157157
// get next set of parameter values and do next run
158158
sprintf(outFile, "%s%d.out", argv[optind + 3], runNum);
159159
out = openFile(outFile, "w");
@@ -201,7 +201,7 @@ int main(int argc, char *argv[]) {
201201

202202
for (k = 0; k < 2; k++) {
203203
runNum = 1;
204-
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0)) {
204+
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0) && (strcmp(line, "\r\n") != 0)) {
205205
// get next set of parameter values and do next run
206206
if (numToSkip > 0) {
207207
strtok(line, " \t"); // read and ignore first value

SIPNETparamsChange/frontend.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ int main(int argc, char *argv[]) {
151151

152152
// do each run, output to fileName#.out
153153
runNum = 1;
154-
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0)) {
154+
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0) && (strcmp(line, "\r\n") != 0)) {
155155
// get next set of parameter values and do next run
156156
sprintf(outFile, "%s%d.out", argv[optind + 3], runNum);
157157
out = openFile(outFile, "w");
@@ -199,7 +199,7 @@ int main(int argc, char *argv[]) {
199199

200200
for (k = 0; k < 2; k++) {
201201
runNum = 1;
202-
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0)) {
202+
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0) && (strcmp(line, "\r\n") != 0)) {
203203
// get next set of parameter values and do next run
204204
if (numToSkip > 0) {
205205
strtok(line, " \t"); // read and ignore first value

SIPNETparamsChange/parameterSort.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int main(int argc, char *argv[])
3333

3434
while( (fgets(line,256,fileIn) != NULL) | (counter<NUM_PARAMS) ) {
3535

36-
if ( (strncmp(line,"*",1)!=0) & (strncmp(line,"\n",1)!=0) ) {
36+
if ( (strncmp(line,"*",1)!=0) & (strncmp(line,"\n",1)!=0) & (strncmp(line,"\r",1)!=0) ) {
3737
strcpy(paramList[counter],line);
3838

3939
//if (counter==NUM_PARAMETERS-1) strcat(niwots[counter],"\n");

Sites/Niwot/niwot.out

Lines changed: 5237 additions & 5237 deletions
Large diffs are not rendered by default.

frontend.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,24 +185,24 @@ int main(int argc, char *argv[]) {
185185

186186
// first find number of changeable parameters:
187187
fgets(line, sizeof(line), pChange);
188-
strtok(line, " \t\n"); // read and ignore first token -- split on space, tab & newline
188+
strtok(line, " \t\n\r"); // read and ignore first token -- split on space, tab, newline & carriage return
189189
numChangeableParams = 1; // assume at least one changeableParam
190-
while (strtok(NULL, " \t\n") != NULL) // now count # of remaining tokens (i.e. # of parameter names)
190+
while (strtok(NULL, " \t\n\r") != NULL) // now count # of remaining tokens (i.e. # of parameter names)
191191
numChangeableParams++;
192192

193193
// now allocate space for array and find the param indices:
194194
indices = (int *)malloc(numChangeableParams * sizeof(int));
195195
rewind(pChange);
196196
fgets(line, sizeof(line), pChange);
197-
paramName = strtok(line, " \t\n"); // get the first item
197+
paramName = strtok(line, " \t\n\r"); // get the first item
198198
for (i = 0; i < numChangeableParams; i++) {
199199
indices[i] = locateParam(spatialParams, paramName);
200200
if (indices[i] == -1) {
201201
printf("Invalid parameter '%s'\n", paramName);
202202
printf("Please fix first line of %s and re-run\n", mcParamFile);
203203
exit(1);
204204
}
205-
paramName = strtok(NULL, " \t\n"); /* get the next item (note: the last time this is called, we'll have paramName = NULL;
205+
paramName = strtok(NULL, " \t\n\r"); /* get the next item (note: the last time this is called, we'll have paramName = NULL;
206206
that's okay, because we just ignore it */
207207
}
208208

@@ -212,7 +212,7 @@ int main(int argc, char *argv[]) {
212212

213213
runNum = 1;
214214
out = NULL;
215-
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0)) {
215+
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0) && (strcmp(line, "\r\n") != 0)) {
216216
// get next set of parameter values and do next run
217217

218218
if (doMainOutput) {
@@ -268,7 +268,7 @@ int main(int argc, char *argv[]) {
268268

269269
for (k = 0; k < 2; k++) {
270270
runNum = 1;
271-
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0)) {
271+
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0) && (strcmp(line, "\r\n") != 0)) {
272272
// get next set of parameter values and do next run
273273
if (numToSkip > 0) {
274274
strtok(line, " \t"); // read and ignore first value

frontendGirdle.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ int main(int argc, char *argv[]) {
154154

155155
// do each run, output to fileName#.out
156156
runNum = 1;
157-
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0)) {
157+
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0) && (strcmp(line, "\r\n") != 0)) {
158158
// get next set of parameter values and do next run
159159
sprintf(outFile, "%s%d.out", argv[optind + 3], runNum);
160160
out = openFile(outFile, "w");
@@ -202,7 +202,7 @@ int main(int argc, char *argv[]) {
202202

203203
for (k = 0; k < 2; k++) {
204204
runNum = 1;
205-
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0)) {
205+
while((fgets(line, sizeof(line), pChange) != NULL) && (strcmp(line, "\n") != 0) && (strcmp(line, "\r\n") != 0)) {
206206
// get next set of parameter values and do next run
207207
if (numToSkip > 0) {
208208
strtok(line, " \t"); // read and ignore first value

namelistInput.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void readNamelistInputs(NamelistInputs *namelistInputs, const char *fileName) {
126126

127127

128128
strcpy(allSeparators, SEPARATORS);
129-
strcat(allSeparators, "\n");
129+
strcat(allSeparators, "\n\r");
130130
infile = openFile(fileName, "r");
131131

132132
while(fgets(line, sizeof(line), infile) != NULL) { // while not EOF or error

paramchange.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ int countLines(char *fileName) {
534534

535535
f = openFile(fileName, "r");
536536
numLines = 0;
537-
while ((fgets(line, sizeof(line), f) != NULL) && (strcmp(line, "\n") != 0)) // read & ignore
537+
while ((fgets(line, sizeof(line), f) != NULL) && (strcmp(line, "\n") != 0) && (strcmp(line, "\r\n") != 0)) // read & ignore
538538
numLines++;
539539

540540
fclose(f);

spatialParams.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ void initializeOneSpatialParam(SpatialParams *spatialParams, char *name, double
198198
spatialParamFile is open and file pointer points to 2nd line (after the numLocs line)
199199
*/
200200
void readSpatialParams(SpatialParams *spatialParams, FILE *paramFile, FILE *spatialParamFile) {
201-
const char *SEPARATORS = " \t\n"; // characters that can separate values in parameter files
201+
const char *SEPARATORS = " \t\n\r"; // characters that can separate values in parameter files
202202
const char *COMMENT_CHARS = "!"; // comment characters (ignore everything after this on a line)
203203

204204
char line[256];

transpose.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <stdlib.h>
1313
#include "util.h"
1414

15-
#define SEPARATORS " \t\n" // valid separators between items on a line
15+
#define SEPARATORS " \t\n\r" // valid separators between items on a line
1616

1717

1818
void usage(char *progName) {

txttobin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int main(int argc, char *argv[]) {
6161
numPerLine = 0;
6262

6363
status = strtok(line, " \t");
64-
while (status != NULL && strcmp(status, "\n") != 0) { // more tokens that aren't "\n"
64+
while (status != NULL && strcmp(status, "\n") != 0 && strcmp(status, "\r\n") != 0) { // more tokens that aren't "\n"
6565
numPerLine++;
6666
status = strtok(NULL, " \t"); // find next token, if it exists
6767
}

util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ int stripComment(char *line, const char *commentChars) {
197197
}
198198

199199
// determine length without any leading blanks
200-
lenTrim = strlen(line) - strspn(line, " \t\n");
200+
lenTrim = strlen(line) - strspn(line, " \t\n\r");
201201
return (lenTrim == 0);
202202
}
203203

0 commit comments

Comments
 (0)