summaryrefslogtreecommitdiff
path: root/ldmicro/loadsave.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ldmicro/loadsave.cpp')
-rw-r--r--ldmicro/loadsave.cpp420
1 files changed, 223 insertions, 197 deletions
diff --git a/ldmicro/loadsave.cpp b/ldmicro/loadsave.cpp
index 2dc4d68..8ad5178 100644
--- a/ldmicro/loadsave.cpp
+++ b/ldmicro/loadsave.cpp
@@ -35,199 +35,197 @@ static ElemSubcktSeries *LoadSeriesFromFile(FILE *f);
//-----------------------------------------------------------------------------
static BOOL LoadLeafFromFile(char *line, void **any, int *which)
{
+ printf("----------------------------------------------------------\n");
+ printf("LoadLeafFromFile...\n");
ElemLeaf *l = AllocLeaf();
+ printf("AllocLeaf: pass...\n");
int x;
+ printf("check 1...\n");
+ // char* testStr = new char[300];
+ // int testI = 0;
+ l->d.contacts.negated = false;
+ printf("line: %s--\n", line);
+ // sscanf("CONTACTS Xbutton 1", "CONTACTS %s %d", testStr, &testI);
+ sscanf(line, "CONTACTS %s %d", l->d.contacts.name, &l->d.contacts.negated);
+ printf("check 1: checking...\n");
if(memcmp(line, "COMMENT", 7)==0) {
- char *s = line + 8;
- int i = 0;
- while(*s && *s != '\n') {
- if(*s == '\\') {
- if(s[1] == 'n') {
- l->d.comment.str[i++] = '\n';
- s++;
- } else if(s[1] == 'r') {
- l->d.comment.str[i++] = '\r';
- s++;
- } else if(s[1] == '\\') {
- l->d.comment.str[i++] = '\\';
- s++;
- } else {
- // that is odd
- }
- } else {
- l->d.comment.str[i++] = *s;
- }
- s++;
- }
- l->d.comment.str[i++] = '\0';
- *which = ELEM_COMMENT;
- } else if(sscanf(line, "CONTACTS %s %d", l->d.contacts.name,
- &l->d.contacts.negated)==2)
- {
- *which = ELEM_CONTACTS;
- } else if(sscanf(line, "COIL %s %d %d %d", l->d.coil.name,
- &l->d.coil.negated, &l->d.coil.setOnly, &l->d.coil.resetOnly)==4)
- {
- *which = ELEM_COIL;
- } else if(memcmp(line, "PLACEHOLDER", 11)==0) {
- *which = ELEM_PLACEHOLDER;
- } else if(memcmp(line, "SHORT", 5)==0) {
- *which = ELEM_SHORT;
- } else if(memcmp(line, "OPEN", 4)==0) {
- *which = ELEM_OPEN;
- } else if(memcmp(line, "MASTER_RELAY", 12)==0) {
- *which = ELEM_MASTER_RELAY;
- } else if(sscanf(line, "SHIFT_REGISTER %s %d", l->d.shiftRegister.name,
- &(l->d.shiftRegister.stages))==2)
- {
- *which = ELEM_SHIFT_REGISTER;
- } else if(memcmp(line, "OSR", 3)==0) {
- *which = ELEM_ONE_SHOT_RISING;
- } else if(memcmp(line, "OSF", 3)==0) {
- *which = ELEM_ONE_SHOT_FALLING;
- } else if((sscanf(line, "TON %s %d", l->d.timer.name,
- &l->d.timer.delay)==2))
- {
- *which = ELEM_TON;
- } else if((sscanf(line, "TOF %s %d", l->d.timer.name,
- &l->d.timer.delay)==2))
- {
- *which = ELEM_TOF;
- } else if((sscanf(line, "RTO %s %d", l->d.timer.name,
- &l->d.timer.delay)==2))
- {
- *which = ELEM_RTO;
- } else if((sscanf(line, "CTD %s %d", l->d.counter.name,
- &l->d.counter.max)==2))
- {
- *which = ELEM_CTD;
- } else if((sscanf(line, "CTU %s %d", l->d.counter.name,
- &l->d.counter.max)==2))
- {
- *which = ELEM_CTU;
- } else if((sscanf(line, "CTC %s %d", l->d.counter.name,
- &l->d.counter.max)==2))
- {
- *which = ELEM_CTC;
- } else if(sscanf(line, "RES %s", l->d.reset.name)==1) {
- *which = ELEM_RES;
- } else if(sscanf(line, "MOVE %s %s", l->d.move.dest, l->d.move.src)==2) {
- *which = ELEM_MOVE;
- } else if(sscanf(line, "ADD %s %s %s", l->d.math.dest, l->d.math.op1,
- l->d.math.op2)==3)
- {
- *which = ELEM_ADD;
- } else if(sscanf(line, "SUB %s %s %s", l->d.math.dest, l->d.math.op1,
- l->d.math.op2)==3)
- {
- *which = ELEM_SUB;
- } else if(sscanf(line, "MUL %s %s %s", l->d.math.dest, l->d.math.op1,
- l->d.math.op2)==3)
- {
- *which = ELEM_MUL;
- } else if(sscanf(line, "DIV %s %s %s", l->d.math.dest, l->d.math.op1,
- l->d.math.op2)==3)
- {
- *which = ELEM_DIV;
- } else if(sscanf(line, "EQU %s %s", l->d.cmp.op1, l->d.cmp.op2)==2) {
- *which = ELEM_EQU;
- } else if(sscanf(line, "NEQ %s %s", l->d.cmp.op1, l->d.cmp.op2)==2) {
- *which = ELEM_NEQ;
- } else if(sscanf(line, "GRT %s %s", l->d.cmp.op1, l->d.cmp.op2)==2) {
- *which = ELEM_GRT;
- } else if(sscanf(line, "GEQ %s %s", l->d.cmp.op1, l->d.cmp.op2)==2) {
- *which = ELEM_GEQ;
- } else if(sscanf(line, "LEQ %s %s", l->d.cmp.op1, l->d.cmp.op2)==2) {
- *which = ELEM_LEQ;
- } else if(sscanf(line, "LES %s %s", l->d.cmp.op1, l->d.cmp.op2)==2) {
- *which = ELEM_LES;
- } else if(sscanf(line, "READ_ADC %s", l->d.readAdc.name)==1) {
- *which = ELEM_READ_ADC;
- } else if(sscanf(line, "SET_PWM %s %d", l->d.setPwm.name,
- &(l->d.setPwm.targetFreq))==2)
- {
- *which = ELEM_SET_PWM;
- } else if(sscanf(line, "UART_RECV %s", l->d.uart.name)==1) {
- *which = ELEM_UART_RECV;
- } else if(sscanf(line, "UART_SEND %s", l->d.uart.name)==1) {
- *which = ELEM_UART_SEND;
- } else if(sscanf(line, "PERSIST %s", l->d.persist.var)==1) {
- *which = ELEM_PERSIST;
- } else if(sscanf(line, "FORMATTED_STRING %s %d", l->d.fmtdStr.var,
- &x)==2)
- {
- if(strcmp(l->d.fmtdStr.var, "(none)")==0) {
- strcpy(l->d.fmtdStr.var, "");
- }
-
- char *p = line;
- int i;
- for(i = 0; i < 3; i++) {
- while(!isspace(*p)) p++;
- while( isspace(*p)) p++;
- }
- for(i = 0; i < x; i++) {
- l->d.fmtdStr.string[i] = atoi(p);
- if(l->d.fmtdStr.string[i] < 32) {
- l->d.fmtdStr.string[i] = 'X';
- }
- while(!isspace(*p) && *p) p++;
- while( isspace(*p) && *p) p++;
- }
- l->d.fmtdStr.string[i] = '\0';
+ // char *s = line + 8;
+ // int i = 0;
+ // while(*s && *s != '\n') {
+ // if(*s == '\\') {
+ // if(s[1] == 'n') {
+ // l->d.comment.str[i++] = '\n';
+ // s++;
+ // } else if(s[1] == 'r') {
+ // l->d.comment.str[i++] = '\r';
+ // s++;
+ // } else if(s[1] == '\\') {
+ // l->d.comment.str[i++] = '\\';
+ // s++;
+ // } else {
+ // // that is odd
+ // }
+ // } else {
+ // l->d.comment.str[i++] = *s;
+ // }
+ // s++;
+ // }
+ // l->d.comment.str[i++] = '\0';
+ // *which = ELEM_COMMENT;
+ }// else if(sscanf(line, "CONTACTS %s %d", l->d.contacts.name, &l->d.contacts.negated)==2)
+ //{
+ // *which = ELEM_CONTACTS;
+ //} else if(sscanf(line, "COIL %s %d %d %d", l->d.coil.name, &l->d.coil.negated, &l->d.coil.setOnly, &l->d.coil.resetOnly)==4)
+ // {
+ // *which = ELEM_COIL;
+ // } else if(memcmp(line, "PLACEHOLDER", 11)==0) {
+ // *which = ELEM_PLACEHOLDER;
+ // } else if(memcmp(line, "SHORT", 5)==0) {
+ // *which = ELEM_SHORT;
+ // } else if(memcmp(line, "OPEN", 4)==0) {
+ // *which = ELEM_OPEN;
+ // } else if(memcmp(line, "MASTER_RELAY", 12)==0) {
+ // *which = ELEM_MASTER_RELAY;
+ // } else if(sscanf(line, "SHIFT_REGISTER %s %d", l->d.shiftRegister.name, &(l->d.shiftRegister.stages))==2)
+ // {
+ // *which = ELEM_SHIFT_REGISTER;
+ // } else if(memcmp(line, "OSR", 3)==0) {
+ // *which = ELEM_ONE_SHOT_RISING;
+ // } else if(memcmp(line, "OSF", 3)==0) {
+ // *which = ELEM_ONE_SHOT_FALLING;
+ // } else if((sscanf(line, "TON %s %d", l->d.timer.name, &l->d.timer.delay)==2))
+ // {
+ // *which = ELEM_TON;
+ // } else if((sscanf(line, "TOF %s %d", l->d.timer.name, &l->d.timer.delay)==2))
+ // {
+ // *which = ELEM_TOF;
+ // } else if((sscanf(line, "RTO %s %d", l->d.timer.name, &l->d.timer.delay)==2))
+ // {
+ // *which = ELEM_RTO;
+ // } else if((sscanf(line, "CTD %s %d", l->d.counter.name, &l->d.counter.max)==2))
+ // {
+ // *which = ELEM_CTD;
+ // } else if((sscanf(line, "CTU %s %d", l->d.counter.name, &l->d.counter.max)==2))
+ // {
+ // *which = ELEM_CTU;
+ // } else if((sscanf(line, "CTC %s %d", l->d.counter.name, &l->d.counter.max)==2))
+ // {
+ // *which = ELEM_CTC;
+ // } else if(sscanf(line, "RES %s", l->d.reset.name)==1) {
+ // *which = ELEM_RES;
+ // } else if(sscanf(line, "MOVE %s %s", l->d.move.dest, l->d.move.src)==2) {
+ // *which = ELEM_MOVE;
+ // } else if(sscanf(line, "ADD %s %s %s", l->d.math.dest, l->d.math.op1, l->d.math.op2)==3)
+ // {
+ // *which = ELEM_ADD;
+ // } else if(sscanf(line, "SUB %s %s %s", l->d.math.dest, l->d.math.op1, l->d.math.op2)==3)
+ // {
+ // *which = ELEM_SUB;
+ // } else if(sscanf(line, "MUL %s %s %s", l->d.math.dest, l->d.math.op1, l->d.math.op2)==3)
+ // {
+ // *which = ELEM_MUL;
+ // } else if(sscanf(line, "DIV %s %s %s", l->d.math.dest, l->d.math.op1, l->d.math.op2)==3)
+ // {
+ // *which = ELEM_DIV;
+ // } else if(sscanf(line, "EQU %s %s", l->d.cmp.op1, l->d.cmp.op2)==2) {
+ // *which = ELEM_EQU;
+ // } else if(sscanf(line, "NEQ %s %s", l->d.cmp.op1, l->d.cmp.op2)==2) {
+ // *which = ELEM_NEQ;
+ // } else if(sscanf(line, "GRT %s %s", l->d.cmp.op1, l->d.cmp.op2)==2) {
+ // *which = ELEM_GRT;
+ // } else if(sscanf(line, "GEQ %s %s", l->d.cmp.op1, l->d.cmp.op2)==2) {
+ // *which = ELEM_GEQ;
+ // } else if(sscanf(line, "LEQ %s %s", l->d.cmp.op1, l->d.cmp.op2)==2) {
+ // *which = ELEM_LEQ;
+ // } else if(sscanf(line, "LES %s %s", l->d.cmp.op1, l->d.cmp.op2)==2) {
+ // *which = ELEM_LES;
+ // } else if(sscanf(line, "READ_ADC %s", l->d.readAdc.name)==1) {
+ // *which = ELEM_READ_ADC;
+ // } else if(sscanf(line, "SET_PWM %s %d", l->d.setPwm.name, &(l->d.setPwm.targetFreq))==2)
+ // {
+ // *which = ELEM_SET_PWM;
+ // } else if(sscanf(line, "UART_RECV %s", l->d.uart.name)==1) {
+ // *which = ELEM_UART_RECV;
+ // } else if(sscanf(line, "UART_SEND %s", l->d.uart.name)==1) {
+ // *which = ELEM_UART_SEND;
+ // } else if(sscanf(line, "PERSIST %s", l->d.persist.var)==1) {
+ // *which = ELEM_PERSIST;
+ // } else if(sscanf(line, "FORMATTED_STRING %s %d", l->d.fmtdStr.var, &x)==2)
+ // {
+ // if(strcmp(l->d.fmtdStr.var, "(none)")==0) {
+ // strcpy(l->d.fmtdStr.var, "");
+ // }
+ printf("check 1: pass...\n");
- *which = ELEM_FORMATTED_STRING;
- } else if(sscanf(line, "LOOK_UP_TABLE %s %s %d %d", l->d.lookUpTable.dest,
- l->d.lookUpTable.index, &(l->d.lookUpTable.count),
- &(l->d.lookUpTable.editAsString))==4)
- {
- char *p = line;
- int i;
- // First skip over the parts that we already sscanf'd.
- for(i = 0; i < 5; i++) {
- while((!isspace(*p)) && *p)
- p++;
- while(isspace(*p) && *p)
- p++;
- }
- // Then copy over the look-up table entries.
- for(i = 0; i < l->d.lookUpTable.count; i++) {
- l->d.lookUpTable.vals[i] = atoi(p);
- while((!isspace(*p)) && *p)
- p++;
- while(isspace(*p) && *p)
- p++;
- }
- *which = ELEM_LOOK_UP_TABLE;
- } else if(sscanf(line, "PIECEWISE_LINEAR %s %s %d",
- l->d.piecewiseLinear.dest, l->d.piecewiseLinear.index,
- &(l->d.piecewiseLinear.count))==3)
- {
char *p = line;
int i;
- // First skip over the parts that we already sscanf'd.
- for(i = 0; i < 4; i++) {
- while((!isspace(*p)) && *p)
- p++;
- while(isspace(*p) && *p)
- p++;
- }
- // Then copy over the piecewise linear points.
- for(i = 0; i < l->d.piecewiseLinear.count*2; i++) {
- l->d.piecewiseLinear.vals[i] = atoi(p);
- while((!isspace(*p)) && *p)
- p++;
- while(isspace(*p) && *p)
- p++;
- }
- *which = ELEM_PIECEWISE_LINEAR;
- } else {
- // that's odd; nothing matched
- CheckFree(l);
- return FALSE;
- }
- *any = l;
+ // for(i = 0; i < 3; i++) {
+ // while(!isspace(*p)) p++;
+ // while( isspace(*p)) p++;
+ // }
+ // for(i = 0; i < x; i++) {
+ // l->d.fmtdStr.string[i] = atoi(p);
+ // if(l->d.fmtdStr.string[i] < 32) {
+ // l->d.fmtdStr.string[i] = 'X';
+ // }
+ // while(!isspace(*p) && *p) p++;
+ // while( isspace(*p) && *p) p++;
+ // }
+ // l->d.fmtdStr.string[i] = '\0';
+
+ // *which = ELEM_FORMATTED_STRING;
+ // } else if(sscanf(line, "LOOK_UP_TABLE %s %s %d %d", l->d.lookUpTable.dest,
+ // l->d.lookUpTable.index, &(l->d.lookUpTable.count),
+ // &(l->d.lookUpTable.editAsString))==4)
+ // {
+ // char *p = line;
+ // int i;
+ // // First skip over the parts that we already sscanf'd.
+ // for(i = 0; i < 5; i++) {
+ // while((!isspace(*p)) && *p)
+ // p++;
+ // while(isspace(*p) && *p)
+ // p++;
+ // }
+ // // Then copy over the look-up table entries.
+ // for(i = 0; i < l->d.lookUpTable.count; i++) {
+ // l->d.lookUpTable.vals[i] = atoi(p);
+ // while((!isspace(*p)) && *p)
+ // p++;
+ // while(isspace(*p) && *p)
+ // p++;
+ // }
+ // *which = ELEM_LOOK_UP_TABLE;
+ // } else if(sscanf(line, "PIECEWISE_LINEAR %s %s %d",
+ // l->d.piecewiseLinear.dest, l->d.piecewiseLinear.index,
+ // &(l->d.piecewiseLinear.count))==3)
+ // {
+ // char *p = line;
+ // int i;
+ // // First skip over the parts that we already sscanf'd.
+ // for(i = 0; i < 4; i++) {
+ // while((!isspace(*p)) && *p)
+ // p++;
+ // while(isspace(*p) && *p)
+ // p++;
+ // }
+ // // Then copy over the piecewise linear points.
+ // for(i = 0; i < l->d.piecewiseLinear.count*2; i++) {
+ // l->d.piecewiseLinear.vals[i] = atoi(p);
+ // while((!isspace(*p)) && *p)
+ // p++;
+ // while(isspace(*p) && *p)
+ // p++;
+ // }
+ // *which = ELEM_PIECEWISE_LINEAR;
+ // } else {
+ // // that's odd; nothing matched
+ // CheckFree(l);
+ // return FALSE;
+ // }
+ // *any = l;
+ printf("----------------------------------------------------------\n");
return TRUE;
}
@@ -278,35 +276,55 @@ static ElemSubcktParallel *LoadParallelFromFile(FILE *f)
//-----------------------------------------------------------------------------
static ElemSubcktSeries *LoadSeriesFromFile(FILE *f)
{
+ printf("LoadSeriesFromFile...\n");
char line[512];
void *any;
int which;
ElemSubcktSeries *ret = AllocSubcktSeries();
+ printf("AllocSubcktSeries: pass...\n");
int cnt = 0;
for(;;) {
+ printf("Loop ckeck 1...\n");
if(!fgets(line, sizeof(line), f)) return NULL;
+ printf("Loop ckeck 1: pass...\n");
char *s = line;
+
+ printf("Sub loop...\n");
while(isspace(*s)) s++;
+ printf("Sub loop, s: %s...\n", s);
+ printf("Sub loop: pass...\n");
+ printf("Loop ckeck 2...\n");
+ printf("condition: %d\n", LoadLeafFromFile(s, &any, &which));
if(strcmp(s, "PARALLEL\n")==0) {
+ printf("Loop ckeck 2, path 1...\n");
which = ELEM_PARALLEL_SUBCKT;
any = LoadParallelFromFile(f);
+ printf("LoadParallelFromFile: pass...\n");
if(!any) return NULL;
- } else if(LoadLeafFromFile(s, &any, &which)) {
+ } //else if(LoadLeafFromFile(s, &any, &which)) {
+ // printf("Loop ckeck 2, path 2...\n");
// got it
- } else if(strcmp(s, "END\n")==0) {
- ret->count = cnt;
- return ret;
- } else {
- return NULL;
- }
+ // } else if(strcmp(s, "END\n")==0) {
+ // printf("Loop ckeck 2, path 3...\n");
+ // ret->count = cnt;
+ // return ret;
+ // } else {
+ // printf("Loop ckeck 2, path 4...\n");
+ // return NULL;
+ // }
+ printf("Loop ckeck 2: pass...\n");
+
ret->contents[cnt].which = which;
ret->contents[cnt].d.any = any;
cnt++;
+
+ printf("Loop ckeck 3...\n");
if(cnt >= MAX_ELEMENTS_IN_SUBCKT) return NULL;
+ printf("Loop ckeck 3: pass...\n");
}
}
@@ -318,11 +336,14 @@ static ElemSubcktSeries *LoadSeriesFromFile(FILE *f)
//-----------------------------------------------------------------------------
BOOL LoadProjectFromFile(char *filename)
{
+ printf("LoadProjectFromFile...\n");
FreeEntireProgram();
+ printf("Prog. freed...\n");
strcpy(CurrentCompileFile, "");
FILE *f = fopen(filename, "r");
if(!f) return FALSE;
+ printf("File opened...\n");
char line[512];
int crystal, cycle, baud;
@@ -363,20 +384,25 @@ BOOL LoadProjectFromFile(char *filename)
int rung;
for(rung = 0;;) {
+ printf("Loop check 1...\n");
if(!fgets(line, sizeof(line), f)) break;
+ printf("Loop check 2...\n");
if(strcmp(line, "RUNG\n")!=0) goto failed;
Prog.rungs[rung] = LoadSeriesFromFile(f);
- if(!Prog.rungs[rung]) goto failed;
+ printf("Loop check 3...\n");
+ if(!Prog.rungs[rung])
+ goto failed;
+ printf("Loop check pass: all...\n");
rung++;
}
- Prog.numRungs = rung;
+ // Prog.numRungs = rung;
- fclose(f);
+ // fclose(f);
return TRUE;
failed:
- fclose(f);
+ // fclose(f);
NewProgram();
Error(_("File format error; perhaps this program is for a newer version "
"of LDmicro?"));