summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRr422018-06-06 11:48:05 +0530
committerRr422018-06-06 11:48:05 +0530
commit27b5bf49732e586021d6f0edf4d95a8554e599ef (patch)
treee29bb4789aaf2915e98dbe5635bda0e817fbc6f1
parent7dbf07b87362bb883ce7d950371a6e5c1f355dd7 (diff)
downloadLDMicroGtk-27b5bf49732e586021d6f0edf4d95a8554e599ef.tar.gz
LDMicroGtk-27b5bf49732e586021d6f0edf4d95a8554e599ef.tar.bz2
LDMicroGtk-27b5bf49732e586021d6f0edf4d95a8554e599ef.zip
Updated LDMicro core (Tested, functional)
-rw-r--r--ldmicro/ldmicro.cpp28
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.cpp32
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.h1
-rw-r--r--ldmicro/loadsave.cpp409
-rw-r--r--ldmicro/miscutil.cpp2
5 files changed, 229 insertions, 243 deletions
diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp
index 1a4258a..6195e77 100644
--- a/ldmicro/ldmicro.cpp
+++ b/ldmicro/ldmicro.cpp
@@ -1054,16 +1054,13 @@ int main(int argc, char** argv)
{
/// Check if we're running in non-interactive mode; in that case we should
/// load the file, compile, and exit.
- // printf("argc: %d\n", argc);
- // printf("arg[0]: %s\n", argv[0]);
- // printf("arg[1]: %s\n", argv[1]);
- // printf("Compile command check...\n");
+
if(argc >= 2) {
RunningInBatchMode = TRUE;
- // printf("Compile command check...\n");
+
char *err =
"Bad command line arguments: run 'ldmicro /c src.ld dest.hex'";
- // printf("error line gen...\n");
+
if (argc < 4)
{
printf("throwing error...\n");
@@ -1073,7 +1070,7 @@ int main(int argc, char** argv)
char *source = (char*)malloc(strlen(argv[2]) + strlen(argv[3]) + 2);
sprintf(source, "%s %s", argv[2], argv[3]);
- // printf("check source......\n");
+
while(isspace(*source)) {
source++;
}
@@ -1083,7 +1080,7 @@ int main(int argc, char** argv)
free(source);
exit(-1);
}
- // printf("check dest......\n");
+
char *dest = source;
while(!isspace(*dest) && *dest) {
dest++;
@@ -1098,26 +1095,23 @@ int main(int argc, char** argv)
while(isspace(*dest)) {
dest++;
}
- // printf("Source: %s\n", source);
- // printf("Dest.: %s\n", dest);
- // printf("source checked......\n");
- // printf("dest checked......\n");
+
if(*dest == '\0')
{
Error(err);
free(source);
exit(-1);
}
- printf("loading project...\n");
+
if(!LoadProjectFromFile(source)) {
Error("Couldn't open '%s', running non-interactively.\n", source);
free(source);
exit(-1);
}
- // strcpy(CurrentCompileFile, dest);
- // GenerateIoList(-1);
- // CompileProgram(FALSE);
- // exit(0);
+ strcpy(CurrentCompileFile, dest);
+ GenerateIoList(-1);
+ CompileProgram(FALSE);
+ exit(0);
}
// /// ~~~
diff --git a/ldmicro/lib/linuxUI/linuxLD.cpp b/ldmicro/lib/linuxUI/linuxLD.cpp
index 487905c..0b9ed9a 100644
--- a/ldmicro/lib/linuxUI/linuxLD.cpp
+++ b/ldmicro/lib/linuxUI/linuxLD.cpp
@@ -15,7 +15,7 @@ HANDLE HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize)
hHeapRecord.dwSize = dwInitialSize;
hHeapRecord.hHeap = hHeap;
hHeapRecord.dwAllocatedSizeOffset = 0;
- hHeapRecord.HeapID = hHeapRecords.size()+1;
+ hHeapRecord.HeapID = HeapRecords.size()+1;
HeapRecords.push_back(hHeapRecord);
return hHeap;
@@ -23,6 +23,13 @@ HANDLE HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize)
LPVOID HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes)
{
+ if (hHeap == NULL)
+ {
+ printf("Alloc**********NULL HEAP***************\n");
+ LPVOID p = malloc(dwBytes);
+ return p;
+ }
+
auto it = std::find_if(HeapRecords.begin(), HeapRecords.end(), [&hHeap](HEAPRECORD &Record) { return Record.hHeap == hHeap; });
if (it == HeapRecords.end())
@@ -40,9 +47,13 @@ LPVOID HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes)
/// HEAP_ZERO_MEMORY is set by default
DWORD flags = MAP_ANONYMOUS;
- if ( (dwFlags & HEAP_ZERO_MEMORY) == HEAP_ZERO_MEMORY)
- flags = MAP_ANONYMOUS | MAP_UNINITIALIZED;
- //void * memset ( void * ptr, int value, size_t num );
+
+ // if ( !((dwFlags & HEAP_ZERO_MEMORY) == HEAP_ZERO_MEMORY) )
+ // flags = MAP_ANONYMOUS | MAP_UNINITIALIZED;
+
+ /* Use for setting a meamory chunck with some value
+ * void * memset ( void * ptr, int value, size_t num );
+ */
LPVOID p = mmap(hHeap + (*it).dwAllocatedSizeOffset, dwBytes, PROT_EXEC, flags, -1, 0);
if (p == NULL)
@@ -59,15 +70,22 @@ LPVOID HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes)
BOOL HeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem)
{
+ /// if NULL free()
+ if (hHeap == NULL)
+ {
+ printf("free*********NULL HEAP***************\n");
+ free(lpMem);
+ return TRUE;
+ }
auto heap_it = std::find_if(HeapRecords.begin(), HeapRecords.end(), [&hHeap](HEAPRECORD &Record) { return Record.hHeap == hHeap; });
-
+
if (heap_it == HeapRecords.end())
- return NULL;
+ return FALSE;
auto chunck_it = std::find_if((*heap_it).Element.begin(), (*heap_it).Element.end(), [&lpMem](HEAPCHUNCK &Chunck) { return Chunck.Chunck == lpMem; });
if (chunck_it == (*heap_it).Element.end())
- return NULL;
+ return FALSE;
int result = munmap((*chunck_it).Chunck, (*chunck_it).dwSize);
diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h
index 525f6a8..4955361 100644
--- a/ldmicro/lib/linuxUI/linuxLD.h
+++ b/ldmicro/lib/linuxUI/linuxLD.h
@@ -4,6 +4,7 @@
#include "linuxUI.h"
#include <vector>
#include <algorithm>
+#include <sys/mman.h>
/// common windows referances for linux
diff --git a/ldmicro/loadsave.cpp b/ldmicro/loadsave.cpp
index 8ad5178..736d54b 100644
--- a/ldmicro/loadsave.cpp
+++ b/ldmicro/loadsave.cpp
@@ -35,197 +35,185 @@ 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, "");
- // }
- printf("check 1: pass...\n");
+ 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';
-
- // *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");
+ 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;
+
return TRUE;
}
@@ -276,55 +264,44 @@ 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)) {
- // printf("Loop ckeck 2, path 2...\n");
+ } else if(LoadLeafFromFile(s, &any, &which)) {
// got it
- // } 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");
+ } else if(strcmp(s, "END\n")==0) {
+ ret->count = cnt;
+ return ret;
+ } else {
+ return NULL;
+ }
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");
}
}
@@ -336,14 +313,11 @@ 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;
@@ -384,25 +358,24 @@ 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);
- 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?"));
diff --git a/ldmicro/miscutil.cpp b/ldmicro/miscutil.cpp
index 08a4e78..2e0ad54 100644
--- a/ldmicro/miscutil.cpp
+++ b/ldmicro/miscutil.cpp
@@ -160,7 +160,7 @@ void *CheckMalloc(size_t n)
{
ok();
void *p = HeapAlloc(MainHeap, HEAP_ZERO_MEMORY, n);
- return NULL;
+ return p;
}
void CheckFree(void *p)
{