From c2ac020fee157d6a3cbebc265f83b510347b0449 Mon Sep 17 00:00:00 2001
From: Etienne Brateau <etienne.brateau@ensiie.fr>
Date: Sat, 15 Dec 2018 17:34:42 +0100
Subject: [PATCH] Clean more code

---
 log/include/log_action.h |   2 -
 log/include/logglobals.h |   7 +-
 log/src/log.c            |  66 +++++++----------
 log/src/loged.c          |   1 -
 log/src/logsimh.c        | 150 +++++++++++++++++++--------------------
 log/src/tool.c           |   2 +-
 psys/include/p2c/newci.h |  14 ++--
 psys/src/newci.c         |  65 ++++++-----------
 8 files changed, 126 insertions(+), 181 deletions(-)

diff --git a/log/include/log_action.h b/log/include/log_action.h
index f4118fb..e2ce105 100644
--- a/log/include/log_action.h
+++ b/log/include/log_action.h
@@ -312,7 +312,6 @@ typedef struct log_action_t
 	short cy_max;
 	/** Area covered bu cyrsor */
 
-	FILE **dumpfile;
 	FILE **tracefile;
 
 	long rndseed; /** Seed for RAND funtion */
@@ -356,7 +355,6 @@ typedef struct log_action_t
 	na_quadword actq1;
 	na_quadword actq2;
 	char genfunc [17];
-	long runstamp;
 } log_action_t;
 
 #endif
diff --git a/log/include/logglobals.h b/log/include/logglobals.h
index 9534f29..2ce5504 100644
--- a/log/include/logglobals.h
+++ b/log/include/logglobals.h
@@ -86,9 +86,6 @@ extern librstrrec *librstrs;
 extern char *gatesname[maxgatesfiles];
 extern char *loghelpname, *lognewsname;   /* Names of system files */
 
-extern long temp1, temp2, temp3, temp4;   /* For use by main program */
-extern char tempch;
-
 extern short zoom;   /* Zooming level */
 extern int ospointflag;   /* Starting point was touched */
 
@@ -188,9 +185,7 @@ extern short refrtimer, refrtimer0;   /* Time until screen is refreshed */
 extern long tabletaddr;
 
 extern char *dumpfname, *tracefname;
-extern FILE *dumpfile, *tracefile;
-
-extern long programmark;
+extern FILE *tracefile;
 
 extern char pushedbackkey, realkey;
 
diff --git a/log/src/log.c b/log/src/log.c
index e75f6d9..c601070 100644
--- a/log/src/log.c
+++ b/log/src/log.c
@@ -218,9 +218,6 @@ librstrrec *librstrs;
 char *gatesname[maxgatesfiles];
 char *loghelpname, *lognewsname;   /* Names of system files */
 
-long temp1, temp2, temp3, temp4;   /* For use by main program */
-char tempch;
-
 short zoom;   /* Zooming level */
 int ospointflag;   /* Starting point was touched */
 
@@ -318,8 +315,6 @@ long tabletaddr;
 char *dumpfname, *tracefname;
 FILE *dumpfile, *tracefile;
 
-long programmark;
-
 char pushedbackkey, realkey;
 
 long EXCP_LINE;   /* Line number of last error */
@@ -487,15 +482,15 @@ void log_setmode(const char *s)
 void strwordx(char *buf, char *wrd)
 {
 	size_t i;
-	char *STR1;
-	char *STR2;
+	char *str1;
+	char *str2;
 
-	STR1 = malloc(strlen(buf) + 1);
-	STR2 = malloc(strlen(buf) + 1);
-	strcpy(STR1, strltrim(strrtrim(strcpy(STR2, buf))));
-	strcpy(buf, STR1);
-	free(STR1);
-	free(STR2);
+	str1 = malloc(strlen(buf) + 1);
+	str2 = malloc(strlen(buf) + 1);
+	strcpy(str1, strltrim(strrtrim(strcpy(str2, buf))));
+	strcpy(buf, str1);
+	free(str1);
+	free(str2);
 
 	if (*buf != '"')
 	{
@@ -12771,7 +12766,7 @@ struct LOC_initialize {
 	na_strlist_t *loadgates, *logmenu;
 	char cmdbuf[81];
 	cnfrec *cnflast;
-} ;
+};
 
 
 static int tryfindfile(char *name, char *path, struct LOC_initialize *LINK)
@@ -16171,15 +16166,11 @@ static void initialize()
 	swtab[5].kind = 'S';
 	strcpy(swtab[6].switch_, "rR");   /* Tool to run */
 	swtab[6].kind = 'M';
-
-	/* Added X display support.  stafford 7/17/91 */
-
 	strcpy(swtab[7].switch_, "xX");   /* XDisplay name */
 	swtab[7].kind = 'M';
 
 	newci_parseswitch(swtab, 8L, V.cmdbuf);
 
-
 	if (*V.cmdbuf != '\0')
 	{
 		if (*V.cmdbuf != '\0')
@@ -16189,9 +16180,6 @@ static void initialize()
 		_Escape(0);
 	}
 
-	/* Added X display support.  stafford 7/17/91 */
-	/* grab the display name off the parsed switches */
-
 	if (swtab[7].used > 0)
 	{
 		m_set_display_name(swtab[7].UU.s);
@@ -16207,8 +16195,6 @@ static void initialize()
 	oldcursortype = normal;
 	cursorflag = false;
 	setscale(0);
-	/*  menupicture := nil;
-		{  errorpicture := nil;  */
 	curlistgroup = 0;
 	messagepos = topmessagepos;
 	resetmessages();
@@ -16264,7 +16250,6 @@ static void initialize()
 	steppingoff = false;
 	vlsi = false;
 	gg.dumpopen = false;
-	gg.dumpfile = &dumpfile;
 	dumpfname = (char *)Malloc(256);
 	*dumpfname = '\0';
 	gg.traceopen = false;
@@ -16780,23 +16765,25 @@ static void shownews()
 
 int main(int argc, char * argv[])
 {
-	long FORLIM;
-	char STR1[81];
+	char str1[81];
+	long temp1;
+	long temp2;
+	char tempch;
 
 	nc_text_in_window = 1;
 	PASCAL_MAIN(argc, argv);
 	tracefile = NULL;
 	dumpfile = NULL;
-	newci_markprogram(&programmark);   /*NEWCI*/
 	gg.initdone = false;
 	entrycapslock = nk_capslock;
 	nk_settransarray(nk_ktcurrent, &curkeytrans);
 	gg.traceopen = false;
 	gg.dumpopen = false;
-	gg.runstamp = timers_sysclock();
 	excpline = -1;
-	for (temp1 = 1; temp1 <= maxgatesfiles; temp1++)
-		libf1[temp1 - 1] = NULL;
+
+	for (long i = 1; i <= maxgatesfiles; i++)
+		libf1[i - 1] = NULL;
+
 	TRY(try40);
 	initialize();
 	printf("\210\f Starting\201\210 LOG\f\200");
@@ -17021,7 +17008,6 @@ int main(int argc, char * argv[])
 				}
 				gg.startpoint = false;
 			}
-			/*        sleep(2);zfprintf(stdout, "z"); fflush(stdout);  **MDG** test */
 		} while (!pigsfly);
 		RECOVER2(try41,_Ltry41);
 		gg.curpage = realcurpage;
@@ -17053,13 +17039,13 @@ int main(int argc, char * argv[])
 	temp2 = P_escapecode;
 	if (excpline == -1)
 		excpline = EXCP_LINE;
-	for (temp4 = 1; temp4 <= maxgatesfiles; temp4++)
+	for (long i = 1; i <= maxgatesfiles; i++)
 	{
-		if (libf1[temp4 - 1] != NULL)
+		if (libf1[i - 1] != NULL)
 		{
-			if (libf1[temp4 - 1]->f != NULL)
-				fclose(libf1[temp4 - 1]->f);
-			libf1[temp4 - 1]->f = NULL;
+			if (libf1[i - 1]->f != NULL)
+				fclose(libf1[i - 1]->f);
+			libf1[i - 1]->f = NULL;
 		}
 	}
 	nk_setcapslock(entrycapslock);
@@ -17080,7 +17066,7 @@ int main(int argc, char * argv[])
 		printf("    Escapecode =  %ld\n", temp2);
 		if (temp2 == -10)
 			printf("    Ioresult   =  %ld = %s\n",
-					temp1, ioresult_message(STR1, temp1));
+					temp1, ioresult_message(str1, temp1));
 		if (excpline != -1)
 			printf("    Line num   =  %ld\n", excpline);
 		printf("\n Probable cause:  ");
@@ -17147,8 +17133,8 @@ int main(int argc, char * argv[])
 			}
 			putchar('\n');
 		}
-		FORLIM = gg.numpages;
-		for (temp1 = 1; temp1 <= FORLIM; temp1++)
+		long for_limit = gg.numpages;
+		for (temp1 = 1; temp1 <= for_limit; temp1++)
 		{
 			printf("Try to save page %ld? ", temp1);
 			do
@@ -17168,10 +17154,8 @@ int main(int argc, char * argv[])
 	TRY(try44);
 	closetools();
 	RECOVER(try44);
-	;
 	ENDTRY(try44);
 	closedumpfiles();
-	newci_releaseprogram(&programmark);   /*NEWCI*/
 	nk_setcapslock(entrycapslock);
 	nk_settransarray(nk_ktstandard, &curkeytrans);
 	showalpha();
diff --git a/log/src/loged.c b/log/src/loged.c
index 2c2e578..1c8cd12 100644
--- a/log/src/loged.c
+++ b/log/src/loged.c
@@ -6746,7 +6746,6 @@ int main(int argc, char * argv[])
   firstpin = 1;
   initscreen();
   gg.host = log_host_loged;
-  gg.runstamp = timers_sysclock();
   gg.traceflag = false;
   gg.traceopen = false;
   gg.dumpopen = false;
diff --git a/log/src/logsimh.c b/log/src/logsimh.c
index 2054386..bcf1c9e 100644
--- a/log/src/logsimh.c
+++ b/log/src/logsimh.c
@@ -147,8 +147,6 @@ static const unarytype unarynot = {
 
 
 
-static long currunstamp;
-
 static log_sigrec *vddsig, *gndsig;
 static long curstamp, currecstamp, viserrorstamp;
 static na_strlist_t *viserrors;
@@ -2241,7 +2239,7 @@ static void chgposs2(long i, long newposs, int newstrong, struct LOC_simplify *L
 		tp = &LINK->tbase;
 		while (*tp != NULL && (*tp)->num < i)
 			tp = &(*tp)->next;
-	
+
 		t = (trailrec *)Malloc(sizeof(trailrec));
 		t->num = i;
 		t->oldposs = WITH->poss;
@@ -2934,21 +2932,21 @@ static void trymoveif(struct LOC_simplstmt *LINK)
 				P_expset(usev2, 0L);
 				builddefvusev(LINK->ip, defv2, usev2, LINK);
 			}
-			
+
 			P_expset(defv1, 0L);
 			P_expset(usev1, 0L);
 			builddefvusev(ip2, defv1, usev1, LINK);
 			ip3 = ip2->UU.U1.next;
 			good1 = true;
 			good2 = true;
-			
+
 			while (ip3 != LINK->ip && (good1 || good2))
 			{
 				checkdefvusev(ip3, defv1, usev1, &good1, LINK);
 				checkdefvusev(ip3, defv2, usev2, &good2, LINK);
 				ip3 = ip3->UU.U1.next;
 			}
-			
+
 			if (good1)
 			{   /*move earlier one later*/
 				*ipp2 = ip2->UU.U1.next;
@@ -2962,7 +2960,7 @@ static void trymoveif(struct LOC_simplstmt *LINK)
 					insertlist(&LINK->ip->UU.U1.arg2, ip2->UU.U1.arg2, LINK);
 					insertlist(&LINK->ip->UU.U1.arg3, ip2->UU.U1.arg3, LINK);
 				}
-				
+
 				if (ip2->UU.U1.next == LINK->ip)
 					LINK->ipp = ipp2;
 				disposetree(&ip2->UU.U1.arg1, LINK->LINK->LINK);
@@ -2983,7 +2981,7 @@ static void trymoveif(struct LOC_simplstmt *LINK)
 					appendlist(&ip2->UU.U1.arg2, LINK->ip->UU.U1.arg2, LINK);
 					appendlist(&ip2->UU.U1.arg3, LINK->ip->UU.U1.arg3, LINK);
 				}
-				
+
 				disposetree(&LINK->ip->UU.U1.arg1, LINK->LINK->LINK);
 				Free(LINK->ip);
 				LINK->ipp = ipp2;
@@ -3016,7 +3014,7 @@ static void tryfactorif(struct LOC_simplstmt *LINK)
 
 	if (!(cmptrees(ip2, ip3, LINK->LINK->LINK) && ip2->opcode != op_iffalse))
 		return;
-	
+
 	ip4 = copytree(ip3, LINK->LINK->LINK);
 	ip4->UU.U1.next = LINK->ip->UU.U1.next;
 	LINK->ip->UU.U1.next = ip4;
@@ -3066,7 +3064,7 @@ static void simplstmt(instrrec **ipbase_, struct LOC_simplify *LINK)
 						simplexpr(&V.ip->UU.U1.arg1, log_none, LINK);
 						break;
 				}
-				
+
 				oldtrail = LINK->tbase;
 				LINK->simplevel++;
 
@@ -3096,7 +3094,7 @@ static void simplstmt(instrrec **ipbase_, struct LOC_simplify *LINK)
 						eattrail(&thentrail, &V);
 						continue;
 					}
-				
+
 					if (thentrail == NULL || thentrail->num > elsetrail->num)
 					{  /*"else" part only*/
 						num = elsetrail->num;
@@ -3108,7 +3106,7 @@ static void simplstmt(instrrec **ipbase_, struct LOC_simplify *LINK)
 						eattrail(&elsetrail, &V);
 						continue;
 					}
-					
+
 					num = thentrail->num;
 					if (num < LINK->LINK->thingvars &&
 							((1L << ((long)V.ip->opcode)) &
@@ -3141,7 +3139,7 @@ static void simplstmt(instrrec **ipbase_, struct LOC_simplify *LINK)
 							default:
 								break;
 						}
-						
+
 						if (thentrail->oldposs == 1L << ((long)log_zero))
 							ip1 = makenot(ip1, LINK->LINK);
 						ip1 = makeinstr1(op_pineq, ip1, LINK->LINK);
@@ -3151,12 +3149,12 @@ static void simplstmt(instrrec **ipbase_, struct LOC_simplify *LINK)
 						insertlist(V.ipp, ip1, &V);
 						V.ipp = &ip1->UU.U1.next;
 					}
-					
+
 					chgposs(num, thentrail->oldposs | elsetrail->oldposs, LINK);
-					
+
 					if (thentrail->oldstrong && elsetrail->oldstrong)
 						LINK->LINK->things[num].strong = true;
-					
+
 					eattrail(&thentrail, &V);
 					eattrail(&elsetrail, &V);
 				}
@@ -3346,7 +3344,7 @@ static void simplstmt(instrrec **ipbase_, struct LOC_simplify *LINK)
 					disposetree(&V.ip->UU.U1.arg2, LINK->LINK);
 					ip1 = V.ip->UU.U1.arg3;
 				}
-				
+
 				*V.ipp = V.ip->UU.U1.next;
 				insertlist(V.ipp, ip1, &V);
 				Free(V.ip);
@@ -4046,7 +4044,7 @@ static void codegen(int genflag_, struct LOC_compilepage *LINK)
 		store(36L, &V);
 		storepnum(LINK->hdef->numppins, true, &V);
 	}
-	
+
 	genlist(LINK->ipbase, &V);
 	if (LINK->pc == 0)
 	{
@@ -4135,11 +4133,11 @@ static void dodump(struct LOC_compilepage *LINK)
 		putc('\n', f);
 	}
 	dasmhdef(f, LINK->hdef, false);
-	
+
 	if (f != NULL)
 		fclose(f);
 	f = NULL;
-	
+
 	if (f != NULL)
 		fclose(f);
 }
@@ -4168,11 +4166,11 @@ static void dowritefile(char *fn_, struct LOC_compilepage *LINK)
 	fprintf(f, "SIMTYPE 16\n\n");
 	dasmhdef(f, LINK->hdef, true);
 	putc('\n', f);
-	
+
 	if (f != NULL)
 		fclose(f);
 	f = NULL;
-	
+
 	if (f != NULL)
 		fclose(f);
 }
@@ -4193,18 +4191,18 @@ static void showstats(struct LOC_compilepage *LINK)
 	if (LINK->simppasscount > 0)
 		sprintf(buf + strlen(buf), " in %ld optimization steps",
 				LINK->simppasscount);
-	
+
 	sprintf(STR2, "%s.", buf);
 	(*WITH->hook.message)(STR2);
 	sprintf(buf, "Gate program is %ld bytes = %ld instructions long",
 			LINK->pc, LINK->instrcount);
 	(*WITH->hook.message)(buf);
 	sprintf(buf, "Program uses %ld state variable", LINK->curpvar);
-	
+
 	if (LINK->curpvar != 1)
 		strcat(buf, "s");
 	sprintf(buf + strlen(buf), " and %ld internal node", LINK->curppin);
-	
+
 	if (LINK->curppin != 1)
 		strcat(buf, "s");
 	sprintf(STR2, "%s.", buf);
@@ -4248,9 +4246,9 @@ static void compilepage(hdefrec *hdef_)
 		cip = (controlinfo *)V.hdef->gcontrol->info;
 	else
 		cip = NULL;
-	
+
 	V.starttime = timers_sysclock();
-	
+
 	if (V.hdef->wantnote)
 	{
 		if (V.hdef->proclen == 0)
@@ -4268,37 +4266,37 @@ static void compilepage(hdefrec *hdef_)
 	}
 	if (V.hdef->pindata != NULL)
 		Free(V.hdef->pindata);
-	
+
 	V.okay = true;
 	V.numports = -1;
-	
+
 	if (vddsig == NULL)
 		(*WITH->hook.getsig)("Vdd", &vddsig);
-	
+
 	if (gndsig == NULL)
 		(*WITH->hook.getsig)("Gnd", &gndsig);
 	V.n = WITH->nbase;
-	
+
 	while (V.n != NULL)
 	{
 		V.n->temp = (na_long)LONG_MIN;
 		V.n = V.n->next;
 	}
-	
+
 	while (V.hdef->depends != NULL)
 	{
 		dep = V.hdef->depends;
 		V.hdef->depends = dep->next;
 		Free(dep);
 	}
-	
+
 	V.inertlist = NULL;
 	V.isverbose = false;
 	wantstats = V.hdef->wantstats;
 	dumpflag = false;
 	*writefile = '\0';
 	V.bigdump = (V.hdef->dumpmode == dump_big);
-	
+
 	if (V.hdef->dumphighlight)
 	{
 		if (V.hdef->dumpmode == dump_write)
@@ -4307,12 +4305,12 @@ static void compilepage(hdefrec *hdef_)
 			dumpflag = true;
 	}
 	V.hdef->optflag = (V.hdef->nextoptflag || V.hdef->optmode == opt_always);
-	
+
 	if (V.hdef->optflag)
 		V.optlevel = V.hdef->optlevel;
 	else
 		V.optlevel = 0;
-	
+
 	V.optdelay = (V.hdef->optdelay && V.optlevel >= 3);
 	V.hdef->nextoptflag = false;
 	V.mybox = V.hdef->defbox;
@@ -4372,7 +4370,7 @@ static void compilepage(hdefrec *hdef_)
 							continue;
 						i++;
 						(*WITH->hook.getsig)(wrd, &sig);
-						
+
 						if ((long)sig->np->temp == LONG_MIN || (long)sig->np->temp == 0)
 							/*newly created*/
 							sig->np->temp = (na_long)(-i);
@@ -4401,12 +4399,12 @@ static void compilepage(hdefrec *hdef_)
 		else
 		{
 			V.gtempl = WITH->gbase[V.hdef->pgnum - 1];
-		
+
 			while (V.gtempl != NULL && (isinstance(V.gtempl) != V.hdef ||
 						!gateinbox(V.mybox, V.gtempl)))
 				V.gtempl = V.gtempl->next;
 			V.hdef->gtempl = V.gtempl;
-			
+
 			if (V.gtempl != NULL)
 			{
 				templs = (log_nrec **)Malloc(V.gtempl->kind->numpins * sizeof(log_nrec *));
@@ -4416,7 +4414,7 @@ static void compilepage(hdefrec *hdef_)
 						&V.hdef->lastsouth, &V.numports);
 				Free(pnumlist);
 				FORLIM = V.numports;
-			
+
 				for (i = 1; i <= FORLIM; i++)
 				{
 					if ((long)templs[i - 1]->temp == LONG_MIN)
@@ -4447,18 +4445,18 @@ static void compilepage(hdefrec *hdef_)
 	}
 
 	V.gcontrol = NULL;
-	
+
 	if (V.isverbose)
 		printf("\f");
 	V.ipbase = NULL;
-	
+
 	if (V.okay)
 	{
 		sprintf(STR3, "Compiling %s", V.hdef->name);
 		showcontrol(V.hdef, STR3);
 		parsegates(&V);
 	}
-	
+
 	if (V.gcontrol != V.hdef->gcontrol && (V.okay || V.gcontrol != NULL))
 	{
 		if (V.hdef->gcontrol != NULL)
@@ -4466,7 +4464,7 @@ static void compilepage(hdefrec *hdef_)
 			cip->hdef = NULL;   /*disconnect old gate*/
 			refrcontrol(V.hdef->gcontrol, 0);
 		}
-		
+
 		V.hdef->gcontrol = V.gcontrol;
 		if (V.gcontrol != NULL)
 		{
@@ -4495,7 +4493,7 @@ static void compilepage(hdefrec *hdef_)
 		V.thingvars = V.curppin + V.numports;
 		V.things = (noderec *)Malloc(V.numthings * sizeof(noderec));
 		FORLIM = V.thingnodes;
-		
+
 		for (i = 0; i < FORLIM; i++)
 		{   /*external nodes*/
 			WITH1 = &V.things[i];
@@ -4513,9 +4511,9 @@ static void compilepage(hdefrec *hdef_)
 			WITH1->defn = NULL;
 			WITH1->loopflag = false;
 		}
-		
+
 		FORLIM = V.thingvars;
-		
+
 		for (i = V.thingnodes; i < FORLIM; i++)
 		{   /*internal nodes*/
 			WITH1 = &V.things[i];
@@ -4533,7 +4531,7 @@ static void compilepage(hdefrec *hdef_)
 			WITH1->loopflag = false;
 		}
 		FORLIM = V.numthings;
-		
+
 		for (i = V.thingvars; i < FORLIM; i++)
 		{   /*state variables*/
 			WITH1 = &V.things[i];
@@ -4610,7 +4608,7 @@ poss := [log_none];   */
 			WITH1->wasused = WITH1->isused;
 			WITH1->isused = 0;
 		}
-		
+
 		V.hasstats = true;
 		extrarpt = 2;
 		do
@@ -4630,7 +4628,7 @@ poss := [log_none];   */
 				else
 					WITH1->nextposs = (1L << ((long)log_none)) |
 						(1L << ((long)log_zero)) | (1L << ((long)log_one));
-				
+
 				WITH1->wasdef = WITH1->isdef;
 				WITH1->isdef = 0;
 				WITH1->wasused = WITH1->isused;
@@ -4654,7 +4652,7 @@ poss := [log_none];   */
 				WITH1->wasstrong = WITH1->strong;
 				WITH1->strong = false;
 			}
-			
+
 			FORLIM = V.numthings;
 			for (i = V.thingvars; i < FORLIM; i++)
 			{
@@ -4668,7 +4666,7 @@ poss := [log_none];   */
 				WITH1->wasused = WITH1->isused;
 				WITH1->isused = 0;
 			}
-			
+
 			if (V.changed)
 				extrarpt = 2;
 			else if (extrarpt > 0)
@@ -4709,10 +4707,10 @@ poss := [log_none];   */
 		codegen(true, &V);   /*actually generate the code*/
 	}
 	V.starttime = timers_sysclock() - V.starttime;
-	
+
 	if (wantstats)
 		showstats(&V);
-	
+
 	if (V.okay)
 	{
 		if (dumpflag)
@@ -4730,7 +4728,7 @@ poss := [log_none];   */
 
 		if (V.isverbose)
 			dasmhdef(stdout, V.hdef, false);
-		
+
 		if (*writefile != '\0') {
 			sprintf(STR1, "Writing to \"%s\"", writefile);
 			showcontrol(V.hdef, STR1);
@@ -4858,11 +4856,11 @@ static void updatehdef(hdefrec *hdef)
 		newstamp = hdef->defreg->regstamp;
 	else
 		newstamp = WITH->pagestamp[j - 1];
-	
+
 	dep = hdef->depends;
 	while (dep != NULL && dep->hdefstamp == dep->hdef->curstamp)
 		dep = dep->next;
-	
+
 	if (hdef->pgnum == j && newstamp == hdef->oldpagestamp && dep == NULL)
 		/*definition moved to a new page?*/
 		return;
@@ -4872,7 +4870,7 @@ static void updatehdef(hdefrec *hdef)
 	hdef->oldpagestamp = newstamp;
 	wasdefined = hdef->defined_;
 	compilepage(hdef);
-	
+
 	if (hdef->defined_ || wasdefined)
 	{
 		WITH->curstamp++;
@@ -4937,7 +4935,7 @@ static void reallocgate(log_grec *g, int clearit)
 			for (i = 0; i < FORLIM; i++)
 				newpins[i] = ii->ginfo.ppins[i];
 			FORLIM = ii->numppins;
-			
+
 			for (i = hdef->numppins; i < FORLIM; i++)
 				(*WITH->hook.switchnode)(&ii->ginfo.ppins[i], NULL);
 			Free(ii->ginfo.ppins);
@@ -4945,7 +4943,7 @@ static void reallocgate(log_grec *g, int clearit)
 		ii->ginfo.ppins = newpins;
 		ii->numppins = hdef->numppins;
 	}
-	
+
 	if (hdef->numpvars != ii->numpvars)
 	{
 		if (ii->numpvars > 0)
@@ -5042,7 +5040,7 @@ static void reconnectgate(log_grec *g_)
 		V.ii->pins = V.g->pin;   /*easy one-to-one mapping*/
 		return;
 	}
-	
+
 	pnum = NULL;
 	examinetemplate(V.g, V.ii->pins, hdef->numports, isgenericinstgate(V.g), &pnum, &lastnorth,
 			&lasteast, &lastsouth, &V.lastwest);
@@ -5076,7 +5074,7 @@ static void updateinstance(log_grec *g)
 		ii->okay = false;
 		return;
 	}
-	
+
 	ii->recstamp = currecstamp;
 	if (ii->attrchg)
 	{  /*circuit has changed*/
@@ -5217,20 +5215,16 @@ void Log_16_inst(log_16_action *act)
 	{
 
 		case act_16_newkind:
-			if (WITH->runstamp != currunstamp)
-			{
-				currunstamp = WITH->runstamp;
-				WITH->curstamp = 0;
-				currecstamp = 0;
-				hdefbase = NULL;
-				viserrorstamp = 0;
-				viserrors = NULL;
-				vddsig = NULL;
-				gndsig = NULL;
-				oldcolorstamp = 0;
-				showstamp = 1;
-				hier_init(act->lact);
-			}
+			WITH->curstamp = 0;
+			currecstamp = 0;
+			hdefbase = NULL;
+			viserrorstamp = 0;
+			viserrors = NULL;
+			vddsig = NULL;
+			gndsig = NULL;
+			oldcolorstamp = 0;
+			showstamp = 1;
+			hier_init(act->lact);
 			break;
 
 		case act_16_new:
@@ -5373,7 +5367,7 @@ void Log_16_inst(log_16_action *act)
 						drawflag = (ii->wasdrawn != NULL);
 					else
 						drawflag = (ii->wasdrawn == NULL || strcmp(ii->wasdrawn, attr1));
-					
+
 					if (drawflag && ii->wasdrawn != NULL)
 					{
 						drawx = 0;
@@ -5384,7 +5378,7 @@ void Log_16_inst(log_16_action *act)
 						m_centerstr((long)drawx, drawy - 4L, NULL, ii->wasdrawn);
 						(*WITH->hook.unhidecursor)();
 					}
-					
+
 					if (attr2)
 						strchange(&ii->wasdrawn, attr1);
 					else
diff --git a/log/src/tool.c b/log/src/tool.c
index 66145bf..d82db46 100644
--- a/log/src/tool.c
+++ b/log/src/tool.c
@@ -69,7 +69,7 @@ log_tool *findtool(char *name_)
 			newci_fixfname(lp->fname, "code", "");
 			if (gg.traceflag)
 				fprintf(tracefile, "Findtool, loading %s\n", lp->fname);
-			newci_loadprogram(lp->fname);
+			//newci_loadprogram(lp->fname); << do nothing
 			RECOVER(try2);
 			if (P_escapecode == -20)
 				_Escape(P_escapecode);
diff --git a/psys/include/p2c/newci.h b/psys/include/p2c/newci.h
index 14527f8..c049b48 100644
--- a/psys/include/p2c/newci.h
+++ b/psys/include/p2c/newci.h
@@ -24,8 +24,8 @@ typedef char *newci_argarr[100001L];
 
 typedef struct newci_parserec {
 	char switch_[4];
-	uchar used;
-	char kind;
+	size_t used;
+	char kind; /* kind of union below */
 	union {
 		long i;
 		double r;
@@ -35,7 +35,7 @@ typedef struct newci_parserec {
 	} UU;
 } newci_parserec;
 
-typedef newci_parserec newci_parsetab[1000000L];
+typedef newci_parserec* newci_parsetab;
 
 typedef struct newci_fshandle {
 	long a;
@@ -82,15 +82,15 @@ vextern FILE **newci_stdterm;
 //extern FILE **newci_stdout ();
 //extern FILE **newci_stderr ();
 //extern void newci_parseargs (char *s);
-extern void newci_parseswitch (newci_parserec *tab, long size, char *bad);
+extern void newci_parseswitch (newci_parserec *tab, size_t size, char *bad);
 extern void newci_eatargument ();
 extern void newci_fixfname (char *s, char *ext, char *home);
 extern void newci_forcefname (char *s, char *ext, char *home);
 //extern void newci_chainprogram (char *name);
-extern void newci_markprogram (long *id);
-extern void newci_loadprogram (char *name);
+//extern void newci_markprogram (long *id);
+//extern void newci_loadprogram (char *name);
 //extern void newci_reloadprogram (char *name);
-extern void newci_releaseprogram (long *id);
+//extern void newci_releaseprogram (long *id);
 //extern void newci_runprogram (char *name);
 //extern void newci_shellrunprogram (char *name, int debugging);
 //extern void newci_basicrunprogram (char *name, int debugging);
diff --git a/psys/src/newci.c b/psys/src/newci.c
index 4722a89..29d7591 100644
--- a/psys/src/newci.c
+++ b/psys/src/newci.c
@@ -17,39 +17,7 @@
 #include <p2c/sysdevs.h>
 
 
-int newci_findprocedure(char *name, _PROCEDURE *start)
-{
-	return(0);
-}
-
-
-int newci_findprogram(char *name)
-{
-	return(0);
-}
-
-
-void newci_loadprogram(char *name)
-{
-	return;
-}
-
-
-void newci_markprogram(long *id)
-{
-	*id = 0;
-	return;
-}
-
-
-void newci_releaseprogram(long *id)
-{
-	*id = 0;
-	return;
-}
-
-
-/*  This procedure should be made to do something real.  */
+/*  This procedure should be made to do something real. */
 void newci_inputstring(char *s, int mode, char *possterm, char *term, int echoterm, long *pos)
 {
 	char buf[1024];
@@ -174,24 +142,30 @@ void newci_eatargument()
 	P_argc--;
 }
 
-void newci_parseswitch(newci_parsetab tab, long size, char *bad)
+void newci_parseswitch(newci_parsetab tab, size_t size, char *bad)
 {
-	int i, j, found, pos = 1;
+	int found;
+	size_t pos = 1;
 
-	for (i = 0; i < size; ++i)
+	for (size_t i = 0; i < size; ++i)
 		tab[i].used = 0;
 	*bad = '\000';
   
-	while ((P_argc > 1) && (P_argv[1][0] == '-'))
+	/* still args and arg start with '-' */
+	while (P_argc > 1 && P_argv[1][0] == '-')
 	{
 		found = 0;
-		for (i = 0; (i < size) && (!found); i++)
+		size_t i;
+		for (i = 0; i < size && !found; i++)
 		{
-    		for (j = 0; (tab[i].switch_[j] != '\0') && (!found); j++)
+    		for (size_t j = 0; tab[i].switch_[j] != '\0' && !found; j++)
+			{
 				if (tab[i].switch_[j] == P_argv[1][1]) 
 					found = 1;
-			if (found) break;
+			}
 		}
+		i--; /* reset i to found index */
+
 		if (!found)
 		{
     		bad[strlen(bad) + 1] = '\0';
@@ -200,20 +174,21 @@ void newci_parseswitch(newci_parsetab tab, long size, char *bad)
 		else
 		{
 			tab[i].used = pos++;
+			
 			switch (toupper(tab[i].kind))
 			{
-				case 'B':
+				case 'B': /* boolean */
 				break;
-				case 'I':
+				case 'I': /* int */
 				tab[i].UU.i = atol(P_argv[1]+2);
 				break;
-				case 'R':
+				case 'R': /* real */
 				sscanf(P_argv[1]+2, "%lf", &tab[i].UU.r);
 				break;
-				case 'S':
+				case 'S': /* string */
 				tab[i].UU.s = P_argv[1]+2;
 				break;
-				case 'M':
+				case 'M': /* multiple */
 				if (P_argc > 2 && !P_argv[1][2])
 				{
 					tab[i].UU.s = P_argv[2];
-- 
GitLab