diff --git a/Makefile b/Makefile index 334a912b17d748f88add51a121f058f268fe14a1..82414712913a62d76c644b4ef95be5723433b0b4 100644 --- a/Makefile +++ b/Makefile @@ -117,7 +117,8 @@ TOOLOBJ = $(SIMOBJ) $(TARGET_DIR)/logspc.o $(TARGET_DIR)/logntk.o \ $(TARGET_DIR)/page.o $(TARGET_DIR)/gate.o \ $(TARGET_DIR)/screen.o $(TARGET_DIR)/node.o \ $(TARGET_DIR)/tool.o $(TARGET_DIR)/utils.o \ - $(TARGET_DIR)/pagewriter.o $(TARGET_DIR)/pagereader.o + $(TARGET_DIR)/pagewriter.o $(TARGET_DIR)/pagereader.o \ + $(TARGET_DIR)/configreader.o $(TARGET_DIR)/ana/%.o: $(SRC_DIR)/ana/%.c diff --git a/include/configreader.h b/include/configreader.h new file mode 100644 index 0000000000000000000000000000000000000000..271805e2718ea57eb1d21b3a03cfd58338926c88 --- /dev/null +++ b/include/configreader.h @@ -0,0 +1,12 @@ +#ifndef CONFIGREADER_H +#define CONFIGREADER_H + +#include "pagereader.h" + +void beginfatal(struct LOC_initialize *LINK); +void endfatal(struct LOC_initialize *LINK); +void sethomedirname(char *dir_, struct LOC_initialize *LINK); +void addgatesfile(char *fn_, struct LOC_initialize *LINK); +void readcnf(char *fn, struct LOC_initialize* LINK); + +#endif diff --git a/include/log.h b/include/log.h index 507c3b68b640a6781b13e13302d6e8b9679c4281..488ce3f8fb47e8bbff13e4f47a3016d3b56d3e45 100644 --- a/include/log.h +++ b/include/log.h @@ -11,6 +11,7 @@ void pen(); void report(short num, char *s); void log_setmode(const char *s); void strwordx(char *buf, char *wrd); +long getint(char *s, long def); void sortshints(short *x, short *y); long glowcol(log_nrec *n, long def); void resetmessages(); @@ -26,6 +27,9 @@ short getsignal(int d, char *n_); void setscale(short s); char *colorname(char *Result, short c); void scroll(); +void doimmedcnffunction(); +void doimmedfunction(); +void docnffunction(); void trykbd(); void confirmsimtype(log_nrec *n); void scancn(cnrec *cn, struct LOC_checkcombine *LINK); diff --git a/src/configreader.c b/src/configreader.c new file mode 100644 index 0000000000000000000000000000000000000000..995ed7ef24b7e57ccddee6864ae6e94dc3eab821 --- /dev/null +++ b/src/configreader.c @@ -0,0 +1,384 @@ +#include "configreader.h" + +#include "graphics/newci.h" +#include "graphics/newcrt.h" +#include "utils/strings.h" +#include "log.h" +#include "screen.h" +#include "utils.h" +#include "tool.h" + + +static void removepath(char *name) +{ + char *cp = (char *)strrchr(name, '/'); + if (cp) + strcpy_overlap(name, cp + 1); +} + +void beginfatal(struct LOC_initialize *LINK) +{ + if (P_escapecode == -20) + _Escape(P_escapecode); + clearshowalpha(); + nc_printf("\n\n%c", chryellow); +} + +void endfatal(struct LOC_initialize *LINK) +{ + nc_printf("%c Program aborted.\n", chrgreen); + _Escape(0); +} + + +void sethomedirname(char *dir_, struct LOC_initialize *LINK) +{ + char dir[256]; + char *ep; + + if (dir_[0] == '~') + { + ep = tilde_expand(dir_); + strncpy(dir, ep, 256); + Free(ep); + } + else + { + strncpy(dir, dir_, 256); + } + strcpy(gg.homedirname, dir); + if (dir[strlen(dir) - 1] != ':' && dir[strlen(dir) - 1] != '/') + strcat(gg.homedirname, "/"); +} + +void addgatesfile(char *fn_, struct LOC_initialize *LINK) +{ + char fn[256]; + strlist_t *l1; + + strcpy(fn, fn_); + newci_fixfname(fn, "gate", ""); + if (!locatefile(fn, LINK)) + *fn = '\0'; + if (*fn != '\0' && strlist_find(gatefilenames, fn) == NULL) + l1 = strlist_append(&gatefilenames, fn); +} + +void readcnf(char *fn_, struct LOC_initialize *LINK) +{ + char fn[256]; + int flag; + long cnflin; + FILE *tx; + char txbuf[256], txarg[256], txarg2[256]; + int erasegates, eraseload, erasemenu; + strlist_t *l1, *l2; + log_tool *tp; + cnfrec *cnfp; + char *TEMP; + + strcpy(fn, fn_); + tx = NULL; + erasegates = true; + eraseload = true; + erasemenu = true; + flag = false; + if (!strcmp(fn, "*")) + { + strcpy(fn, P_argv[0]); + removepath(fn); + strcat(fn, ".cnf"); + if (!locatefile(fn, LINK)) + { + strcpy(fn, "log.cnf"); + if (!locatefile(fn, LINK)) + *fn = '\0'; + + } + } + else + { + newci_fixfname(fn, "cnf", ""); + if (!locatefile(fn, LINK)) + *fn = '\0'; + } + if (*fn != '\0') + { + TRY(try32); + if (tx != NULL) + tx = freopen(fn, "r", tx); + else + tx = fopen(fn, "r"); + + if (tx == NULL) { + P_escapecode = -10; + P_ioresult = FileNotFound; + goto _Ltry32; + } + flag = true; + RECOVER2(try32,_Ltry32); + if (P_escapecode == -20) + _Escape(P_escapecode); + + ENDTRY(try32); + } + cnflin = 0; + if (flag) + { + TRY(try33); + while (!P_eof(tx)) + { + cnflin++; + fgets(txbuf, 256, tx); + TEMP = (char *)strchr(txbuf, '\n'); + if (TEMP != NULL) + *TEMP = 0; + + strcomment(txbuf, "{}"); + getword(txbuf, LINK->cmdbuf); + if (!strcmp(LINK->cmdbuf, "BOBCAT")) + { + if (nc_gType() != nc_g300) + *txbuf = '\0'; + + getword(txbuf, LINK->cmdbuf); + } + else if (!strcmp(LINK->cmdbuf, "CHIPMUNK")) + { + if (nc_gType() == nc_g300) + *txbuf = '\0'; + + getword(txbuf, LINK->cmdbuf); + } + if (!strcmp(LINK->cmdbuf, "LOG:")) + getword(txbuf, LINK->cmdbuf); + + strcpy(gg.func, LINK->cmdbuf); + strcpy(gg.funcarg, txbuf); + if (*LINK->cmdbuf != '\0') + { + doimmedcnffunction(); + docnffunction(); + } + if (*LINK->cmdbuf == '\0' || strcmp(gg.func, LINK->cmdbuf)) + continue; + if (strends(LINK->cmdbuf, ":") && strlen(LINK->cmdbuf) > 1) + { + if (*txbuf == '\0') + continue; + + LINK->cmdbuf[strlen(LINK->cmdbuf) - 1] = '\0'; + cnfp = (cnfrec *)Malloc(sizeof(cnfrec)); + cnfp->next = NULL; + if (LINK->cnflast == NULL) + cnfbase = cnfp; + else + LINK->cnflast->next = cnfp; + + cnfp->next = NULL; + strcpy(cnfp->tool, LINK->cmdbuf); + strcpy(cnfp->s, txbuf); + LINK->cnflast = cnfp; + continue; + } + if (!strcmp(LINK->cmdbuf, "INCLUDE")) + { + do + { + strwordx(txbuf, txarg); + if (*txarg != '\0') + readcnf(txarg, LINK); + } + while (*txarg != '\0'); + + continue; + } + if (!strcmp(LINK->cmdbuf, "HOME")) + { + sethomedirname(txbuf, LINK); + continue; + } + if (!strcmp(LINK->cmdbuf, "GATES")) + { + strwordx(txbuf, txarg); + if (!strcmp(txarg, "+")) + strwordx(txbuf, txarg); + else + { + if (erasegates) + strlist_empty(&gatefilenames); + } + erasegates = false; + while (*txarg != '\0') + { + addgatesfile(txarg, LINK); + strwordx(txbuf, txarg); + } + continue; + } + if (!strcmp(LINK->cmdbuf, "HELP")) + { + if (locatefile(txbuf, LINK)) + strcpy(loghelpname, txbuf); + + continue; + } + if (!strcmp(LINK->cmdbuf, "NEWS")) + { + if (locatefile(txbuf, LINK)) + strcpy(lognewsname, txbuf); + + continue; + } + if (!strcmp(LINK->cmdbuf, "TABLET")) + { + tabletaddr = getint(txbuf, tabletaddr); + continue; + } + if (!strcmp(LINK->cmdbuf, "MENU")) + { + getword(txbuf, txarg); + if (!strcmp(txarg, "+")) + getword(txbuf, txarg); + else + { + if (erasemenu) + strlist_empty(&LINK->logmenu); + } + erasemenu = false; + while (*txarg != '\0') + { + l1 = strlist_append(&LINK->logmenu, txarg); + getword(txbuf, txarg); + } + + continue; + } + if (!strcmp(LINK->cmdbuf, "GET") || !strcmp(LINK->cmdbuf, "LOAD")) + { + getword(txbuf, txarg); + if (!strcmp(txarg, "+")) + getword(txbuf, txarg); + else + { + if (eraseload) + strlist_empty(&LINK->loadgates); + } + eraseload = false; + while (*txarg != '\0') + { + l1 = strlist_append(&LINK->loadgates, txarg); + getword(txbuf, txarg); + } + continue; + } + if (!strcmp(LINK->cmdbuf, "GETGROUP")) + { + getword(txbuf, txarg); + if (!strcmp(txarg, "+")) + getword(txbuf, txarg); + else + { + if (eraseload) + strlist_empty(&LINK->loadgates); + } + eraseload = false; + l1 = strlist_append(&LINK->loadgates, ""); + l1->value = (na_long)NULL; + while (*txarg != '\0') + { + l2 = strlist_append((strlist_t **)(&l1->value), txarg); + getword(txbuf, txarg); + } + continue; + } + if (!strcmp(LINK->cmdbuf, "TOOL")) + { + getword(txbuf, txarg); + if (*txarg == '\0') + continue; + + tp = gg.toolbase; + while (tp != NULL && strcmp(tp->name, txarg)) + tp = tp->next; + + if (tp != NULL) + continue; + + newtool(&tp, txarg); + strwordx(txbuf, txarg); + if (*txarg != '\0') + strcpy(tp->comment, txarg); + + getword(txbuf, txarg); + continue; + } + if (!strcmp(LINK->cmdbuf, "COMMAND")) + { + getword(txbuf, txarg2); + if (*txarg2 == '\0') + continue; + + do + { + getword(txbuf, txarg); + if (*txarg != '\0') + { + l1 = strlist_add(&commandlist, txarg); + *(char **)((char **)(&l1->value)) = strdup(txarg2); + } + } + while (*txarg != '\0'); + + continue; + } + if (!strcmp(LINK->cmdbuf, "SIGNALS") || !strcmp(LINK->cmdbuf, "NODES")) + { + LINK->j = getint(txbuf, 0L); + if (LINK->j < 1) + { + P_escapecode = -1; + goto _Ltry33; + } + gg.maxsignal = LINK->j; + continue; + } + if (!strcmp(LINK->cmdbuf, "DO")) + { + l2 = strlist_append(&thingstodo, gg.funcarg); + continue; + } + if (!strcmp(LINK->cmdbuf, "UNDO")) + strlist_empty(&thingstodo); + else if (strcmp(LINK->cmdbuf, "CTOLERANCE") && + strcmp(LINK->cmdbuf, "CLOCK") && + strcmp(LINK->cmdbuf, "SCOPE") && + strcmp(LINK->cmdbuf, "AUTO") && + strcmp(LINK->cmdbuf, "POST") && + strcmp(LINK->cmdbuf, "PRINTER") && + strcmp(LINK->cmdbuf, "HELPIX") && + strcmp(LINK->cmdbuf, "GATESIX") && + strcmp(LINK->cmdbuf, "PLOTTER") && + strcmp(LINK->cmdbuf, "SIMMODE")) + { + P_escapecode = -1; + goto _Ltry33; + } + } + RECOVER2(try33,_Ltry33); + if (P_escapecode == -20) + _Escape(P_escapecode); + + if (P_escapecode != 0) + { + beginfatal(LINK); + nc_printf("Error in line %ld of configuration file \"%s\"\n", cnflin, fn); + endfatal(LINK); + } + ENDTRY(try33); + } + if (tx != NULL) + fclose(tx); + + /*obsolete*/ +} diff --git a/src/log.c b/src/log.c index f3f889f4f5acb119f774c2b9b64c6f4963ad3efe..06a4c66593394189574d9cdc4f5d459d0cf86ccc 100644 --- a/src/log.c +++ b/src/log.c @@ -74,6 +74,8 @@ #include "pagewriter.h" #include "pagereader.h" +#include "configreader.h" + char *GetChipmunkPath(); enum cursors; @@ -458,7 +460,7 @@ void strwordx(char *buf, char *wrd) strcpy_overlap(buf, buf + i); } -static long getint(char *s, long def) +long getint(char *s, long def) { char w[10]; long i, j, sign; @@ -2646,7 +2648,7 @@ void scroll() } -static void doimmedcnffunction() +void doimmedcnffunction() { char STR1[256], STR2[256]; @@ -2829,7 +2831,7 @@ static void doimmedcnffunction() } -static void doimmedfunction() +void doimmedfunction() { log_tool *tp; char cmd[256]; @@ -12537,7 +12539,7 @@ static long getcolorname(char *w_) return Result; } -static void docnffunction() +void docnffunction() { char arg[256]; long i, j, k; @@ -13281,379 +13283,6 @@ static void inithooks() #define rtn "INITIALIZE" -static void beginfatal(struct LOC_initialize *LINK) -{ - if (P_escapecode == -20) - _Escape(P_escapecode); - clearshowalpha(); - nc_printf("\n\n%c", chryellow); -} - -static void endfatal(struct LOC_initialize *LINK) -{ - nc_printf("%c Program aborted.\n", chrgreen); - _Escape(0); -} - -static void addgatesfile(char *fn_, struct LOC_initialize *LINK) -{ - char fn[256]; - strlist_t *l1; - - strcpy(fn, fn_); - newci_fixfname(fn, "gate", ""); - if (!locatefile(fn, LINK)) - *fn = '\0'; - if (*fn != '\0' && strlist_find(gatefilenames, fn) == NULL) - l1 = strlist_append(&gatefilenames, fn); -} - -static void sethomedirname(char *dir_, struct LOC_initialize *LINK) -{ - char dir[256]; - char *ep; - - if (dir_[0] == '~') - { - ep = tilde_expand(dir_); - strncpy(dir, ep, 256); - Free(ep); - } - else - { - strncpy(dir, dir_, 256); - } - strcpy(gg.homedirname, dir); - if (dir[strlen(dir) - 1] != ':' && dir[strlen(dir) - 1] != '/') - strcat(gg.homedirname, "/"); -} - -static void removepath(char *name) -{ - char *cp = (char *)strrchr(name, '/'); - if (cp) - strcpy_overlap(name, cp + 1); -} - -static void readcnf(char *fn_, struct LOC_initialize *LINK) -{ - char fn[256]; - int flag; - long cnflin; - FILE *tx; - char txbuf[256], txarg[256], txarg2[256]; - int erasegates, eraseload, erasemenu; - strlist_t *l1, *l2; - log_tool *tp; - cnfrec *cnfp; - char *TEMP; - - strcpy(fn, fn_); - tx = NULL; - erasegates = true; - eraseload = true; - erasemenu = true; - flag = false; - if (!strcmp(fn, "*")) - { - strcpy(fn, P_argv[0]); - removepath(fn); - strcat(fn, ".cnf"); - if (!locatefile(fn, LINK)) - { - strcpy(fn, "log.cnf"); - if (!locatefile(fn, LINK)) - *fn = '\0'; - - } - } - else - { - newci_fixfname(fn, "cnf", ""); - if (!locatefile(fn, LINK)) - *fn = '\0'; - } - if (*fn != '\0') - { - TRY(try32); - if (tx != NULL) - tx = freopen(fn, "r", tx); - else - tx = fopen(fn, "r"); - - if (tx == NULL) { - P_escapecode = -10; - P_ioresult = FileNotFound; - goto _Ltry32; - } - flag = true; - RECOVER2(try32,_Ltry32); - if (P_escapecode == -20) - _Escape(P_escapecode); - - ENDTRY(try32); - } - cnflin = 0; - if (flag) - { - TRY(try33); - while (!P_eof(tx)) - { - cnflin++; - fgets(txbuf, 256, tx); - TEMP = (char *)strchr(txbuf, '\n'); - if (TEMP != NULL) - *TEMP = 0; - - strcomment(txbuf, "{}"); - getword(txbuf, LINK->cmdbuf); - if (!strcmp(LINK->cmdbuf, "BOBCAT")) - { - if (nc_gType() != nc_g300) - *txbuf = '\0'; - - getword(txbuf, LINK->cmdbuf); - } - else if (!strcmp(LINK->cmdbuf, "CHIPMUNK")) - { - if (nc_gType() == nc_g300) - *txbuf = '\0'; - - getword(txbuf, LINK->cmdbuf); - } - if (!strcmp(LINK->cmdbuf, "LOG:")) - getword(txbuf, LINK->cmdbuf); - - strcpy(gg.func, LINK->cmdbuf); - strcpy(gg.funcarg, txbuf); - if (*LINK->cmdbuf != '\0') - { - doimmedcnffunction(); - docnffunction(); - } - if (*LINK->cmdbuf == '\0' || strcmp(gg.func, LINK->cmdbuf)) - continue; - if (strends(LINK->cmdbuf, ":") && strlen(LINK->cmdbuf) > 1) - { - if (*txbuf == '\0') - continue; - - LINK->cmdbuf[strlen(LINK->cmdbuf) - 1] = '\0'; - cnfp = (cnfrec *)Malloc(sizeof(cnfrec)); - cnfp->next = NULL; - if (LINK->cnflast == NULL) - cnfbase = cnfp; - else - LINK->cnflast->next = cnfp; - - cnfp->next = NULL; - strcpy(cnfp->tool, LINK->cmdbuf); - strcpy(cnfp->s, txbuf); - LINK->cnflast = cnfp; - continue; - } - if (!strcmp(LINK->cmdbuf, "INCLUDE")) - { - do - { - strwordx(txbuf, txarg); - if (*txarg != '\0') - readcnf(txarg, LINK); - } - while (*txarg != '\0'); - - continue; - } - if (!strcmp(LINK->cmdbuf, "HOME")) - { - sethomedirname(txbuf, LINK); - continue; - } - if (!strcmp(LINK->cmdbuf, "GATES")) - { - strwordx(txbuf, txarg); - if (!strcmp(txarg, "+")) - strwordx(txbuf, txarg); - else - { - if (erasegates) - strlist_empty(&gatefilenames); - } - erasegates = false; - while (*txarg != '\0') - { - addgatesfile(txarg, LINK); - strwordx(txbuf, txarg); - } - continue; - } - if (!strcmp(LINK->cmdbuf, "HELP")) - { - if (locatefile(txbuf, LINK)) - strcpy(loghelpname, txbuf); - - continue; - } - if (!strcmp(LINK->cmdbuf, "NEWS")) - { - if (locatefile(txbuf, LINK)) - strcpy(lognewsname, txbuf); - - continue; - } - if (!strcmp(LINK->cmdbuf, "TABLET")) - { - tabletaddr = getint(txbuf, tabletaddr); - continue; - } - if (!strcmp(LINK->cmdbuf, "MENU")) - { - getword(txbuf, txarg); - if (!strcmp(txarg, "+")) - getword(txbuf, txarg); - else - { - if (erasemenu) - strlist_empty(&LINK->logmenu); - } - erasemenu = false; - while (*txarg != '\0') - { - l1 = strlist_append(&LINK->logmenu, txarg); - getword(txbuf, txarg); - } - - continue; - } - if (!strcmp(LINK->cmdbuf, "GET") || !strcmp(LINK->cmdbuf, "LOAD")) - { - getword(txbuf, txarg); - if (!strcmp(txarg, "+")) - getword(txbuf, txarg); - else - { - if (eraseload) - strlist_empty(&LINK->loadgates); - } - eraseload = false; - while (*txarg != '\0') - { - l1 = strlist_append(&LINK->loadgates, txarg); - getword(txbuf, txarg); - } - continue; - } - if (!strcmp(LINK->cmdbuf, "GETGROUP")) - { - getword(txbuf, txarg); - if (!strcmp(txarg, "+")) - getword(txbuf, txarg); - else - { - if (eraseload) - strlist_empty(&LINK->loadgates); - } - eraseload = false; - l1 = strlist_append(&LINK->loadgates, ""); - l1->value = (na_long)NULL; - while (*txarg != '\0') - { - l2 = strlist_append((strlist_t **)(&l1->value), txarg); - getword(txbuf, txarg); - } - continue; - } - if (!strcmp(LINK->cmdbuf, "TOOL")) - { - getword(txbuf, txarg); - if (*txarg == '\0') - continue; - - tp = gg.toolbase; - while (tp != NULL && strcmp(tp->name, txarg)) - tp = tp->next; - - if (tp != NULL) - continue; - - newtool(&tp, txarg); - strwordx(txbuf, txarg); - if (*txarg != '\0') - strcpy(tp->comment, txarg); - - getword(txbuf, txarg); - continue; - } - if (!strcmp(LINK->cmdbuf, "COMMAND")) - { - getword(txbuf, txarg2); - if (*txarg2 == '\0') - continue; - - do - { - getword(txbuf, txarg); - if (*txarg != '\0') - { - l1 = strlist_add(&commandlist, txarg); - *(char **)((char **)(&l1->value)) = strdup(txarg2); - } - } - while (*txarg != '\0'); - - continue; - } - if (!strcmp(LINK->cmdbuf, "SIGNALS") || !strcmp(LINK->cmdbuf, "NODES")) - { - LINK->j = getint(txbuf, 0L); - if (LINK->j < 1) - { - P_escapecode = -1; - goto _Ltry33; - } - gg.maxsignal = LINK->j; - continue; - } - if (!strcmp(LINK->cmdbuf, "DO")) - { - l2 = strlist_append(&thingstodo, gg.funcarg); - continue; - } - if (!strcmp(LINK->cmdbuf, "UNDO")) - strlist_empty(&thingstodo); - else if (strcmp(LINK->cmdbuf, "CTOLERANCE") && - strcmp(LINK->cmdbuf, "CLOCK") && - strcmp(LINK->cmdbuf, "SCOPE") && - strcmp(LINK->cmdbuf, "AUTO") && - strcmp(LINK->cmdbuf, "POST") && - strcmp(LINK->cmdbuf, "PRINTER") && - strcmp(LINK->cmdbuf, "HELPIX") && - strcmp(LINK->cmdbuf, "GATESIX") && - strcmp(LINK->cmdbuf, "PLOTTER") && - strcmp(LINK->cmdbuf, "SIMMODE")) - { - P_escapecode = -1; - goto _Ltry33; - } - } - RECOVER2(try33,_Ltry33); - if (P_escapecode == -20) - _Escape(P_escapecode); - - if (P_escapecode != 0) - { - beginfatal(LINK); - nc_printf("Error in line %ld of configuration file \"%s\"\n", cnflin, fn); - endfatal(LINK); - } - ENDTRY(try33); - } - if (tx != NULL) - fclose(tx); - - /*obsolete*/ -} - /** @brief Initialize all variables. Read basic gates from library. Clear catalog screen.