summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ldmicro/includes/ldmicro.h1
-rw-r--r--ldmicro/iolist.cpp1
-rw-r--r--ldmicro/ldinterpret.c14
-rw-r--r--ldmicro/loadsave.cpp14
4 files changed, 30 insertions, 0 deletions
diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h
index 8c52775..df785b2 100644
--- a/ldmicro/includes/ldmicro.h
+++ b/ldmicro/includes/ldmicro.h
@@ -730,6 +730,7 @@ BOOL CanUndo(void);
// loadsave.cpp
BOOL LoadProjectFromFile(char *filename);
BOOL SaveProjectToFile(char *filename);
+void ManageLineEnding(char* line);
// iolist.cpp
int GenerateIoList(int prevSel);
diff --git a/ldmicro/iolist.cpp b/ldmicro/iolist.cpp
index 65a14fc..e53f535 100644
--- a/ldmicro/iolist.cpp
+++ b/ldmicro/iolist.cpp
@@ -353,6 +353,7 @@ BOOL LoadIoListFromFile(FILE *f)
char name[MAX_NAME_LEN];
int pin;
while(fgets(line, sizeof(line), f)) {
+ ManageLineEnding(line);
if(strcmp(line, "END\n")==0) {
return TRUE;
}
diff --git a/ldmicro/ldinterpret.c b/ldmicro/ldinterpret.c
index a37ff09..da7a50e 100644
--- a/ldmicro/ldinterpret.c
+++ b/ldmicro/ldinterpret.c
@@ -107,6 +107,17 @@ int HexDigit(int c)
}
return 0;
}
+
+void ManageLineEnding(char* line)
+{
+ int charlen = strlen(line) - 2;
+ if(line[charlen] == '\r')
+ {
+ line[charlen++] = '\n';
+ line[charlen] = '\0';
+ }
+}
+
void LoadProgram(char *fileName)
{
int pc;
@@ -121,6 +132,7 @@ void LoadProgram(char *fileName)
}
if(!fgets(line, sizeof(line), f)) BadFormat();
+ ManageLineEnding(line);
if(strcmp(line, "$$LDcode\n")!=0) BadFormat();
for(pc = 0; ; pc++) {
@@ -128,6 +140,7 @@ void LoadProgram(char *fileName)
BYTE *b;
if(!fgets(line, sizeof(line), f)) BadFormat();
+ ManageLineEnding(line);
if(strcmp(line, "$$bits\n")==0) break;
if(strlen(line) != sizeof(BinOp)*2 + 1) BadFormat();
@@ -143,6 +156,7 @@ void LoadProgram(char *fileName)
SpecialAddrForA = -1;
SpecialAddrForXosc = -1;
while(fgets(line, sizeof(line), f)) {
+ ManageLineEnding(line);
if(memcmp(line, "a,", 2)==0) {
SpecialAddrForA = atoi(line+2);
}
diff --git a/ldmicro/loadsave.cpp b/ldmicro/loadsave.cpp
index a1895a5..b07ec4b 100644
--- a/ldmicro/loadsave.cpp
+++ b/ldmicro/loadsave.cpp
@@ -235,6 +235,7 @@ static ElemSubcktParallel *LoadParallelFromFile(FILE *f)
for(;;) {
if(!fgets(line, sizeof(line), f)) return NULL;
+ ManageLineEnding(line);
char *s = line;
while(isspace(*s)) s++;
@@ -275,6 +276,7 @@ static ElemSubcktSeries *LoadSeriesFromFile(FILE *f)
for(;;) {
if(!fgets(line, sizeof(line), f)) return NULL;
+ ManageLineEnding(line);
char *s = line;
@@ -305,6 +307,16 @@ static ElemSubcktSeries *LoadSeriesFromFile(FILE *f)
}
}
+void ManageLineEnding(char* line)
+{
+ int charlen = strlen(line) - 2;
+ if(line[charlen] == '\r')
+ {
+ line[charlen++] = '\n';
+ line[charlen] = '\0';
+ }
+}
+
//-----------------------------------------------------------------------------
// Load a project from a saved project description files. This describes the
// program, the target processor, plus certain configuration settings (cycle
@@ -323,6 +335,7 @@ BOOL LoadProjectFromFile(char *filename)
int crystal, cycle, baud;
while(fgets(line, sizeof(line), f)) {
+ ManageLineEnding(line);
if(strcmp(line, "IO LIST\n")==0) {
if(!LoadIoListFromFile(f)) {
fclose(f);
@@ -359,6 +372,7 @@ BOOL LoadProjectFromFile(char *filename)
int rung;
for(rung = 0;;) {
if(!fgets(line, sizeof(line), f)) break;
+ ManageLineEnding(line);
if(strcmp(line, "RUNG\n")!=0) goto failed;