From 6b68f4c863f200dde208f5dd60ada4e0fa00bd39 Mon Sep 17 00:00:00 2001
From: Etienne Brateau <etienne.brateau@ensiie.fr>
Date: Mon, 4 Feb 2019 23:55:30 +0100
Subject: [PATCH] move box funtions into separate file

---
 Makefile         |   2 +-
 include/box.h    |  21 ++++++++
 include/log.h    |   3 +-
 include/logdef.h |   8 +--
 src/box.c        | 132 +++++++++++++++++++++++++++++++++++++++++++++++
 src/gate.c       |   1 +
 src/log.c        | 130 ++--------------------------------------------
 src/loghier.c    |   1 +
 src/logsimh.c    |   1 +
 src/page.c       |   1 +
 src/pagereader.c |   1 +
 src/pagewriter.c |   1 +
 src/screen.c     |   1 +
 13 files changed, 167 insertions(+), 136 deletions(-)
 create mode 100644 include/box.h
 create mode 100644 src/box.c

diff --git a/Makefile b/Makefile
index f2f6a37..3229b77 100644
--- a/Makefile
+++ b/Makefile
@@ -119,7 +119,7 @@ TOOLOBJ = $(SIMOBJ) \
 	  $(TARGET_DIR)/tool.o $(TARGET_DIR)/utils.o		\
 	  $(TARGET_DIR)/pagewriter.o $(TARGET_DIR)/pagereader.o	\
 	  $(TARGET_DIR)/configreader.o $(TARGET_DIR)/attrs.o \
-	  $(TARGET_DIR)/keyboard.o
+	  $(TARGET_DIR)/keyboard.o $(TARGET_DIR)/box.o
 
 
 $(TARGET_DIR)/ana/%.o: $(SRC_DIR)/ana/%.c
diff --git a/include/box.h b/include/box.h
new file mode 100644
index 0000000..da4838b
--- /dev/null
+++ b/include/box.h
@@ -0,0 +1,21 @@
+#ifndef BOX_H
+#define BOX_H
+
+#include <utils/newasm.h>
+
+typedef struct log_brec {
+  short x1, y1, x2, y2;
+  struct log_brec *next;
+  na_long temp;
+  unsigned f7 : 1, f6 : 1, f5 : 1, f4 : 1, f3 : 1, f2 : 1, f1 : 1, f0 : 1;
+} log_brec;   /* Dashed box */
+
+void linkbox(log_brec *b);
+void newbox(log_brec **b);
+void unlinkbox(log_brec *b);
+void dispbox(log_brec **b);
+
+void addboxat(short x1, short y1, short x2, short y2);
+void addbox();
+
+#endif
diff --git a/include/log.h b/include/log.h
index ee0ea4e..a146e7f 100644
--- a/include/log.h
+++ b/include/log.h
@@ -31,7 +31,9 @@ void doimmedfunction();
 void docnffunction();
 void dofunction ();
 void assertfunc (char *name);
+void clearfunc();
 void refrfunc();
+void waitnear();
 void confirmsimtype(log_nrec *n);
 void scancn(cnrec *cn, struct LOC_checkcombine *LINK);
 void addblobs(blobrec **blbase, short x1, short y1, short x2, short y2);
@@ -43,7 +45,6 @@ void prealunit2(double r, short p, char *u, char *s);
 void beginerror();
 void enderror();
 void setvlsimode(int flag);
-void newbox(log_brec **b);
 short readlibrary(char *n);
 void histdelsignals();
 void histaddsignal(log_hnrec **hn, short sig, short y);
diff --git a/include/logdef.h b/include/logdef.h
index 7000ddf..d9bd78e 100644
--- a/include/logdef.h
+++ b/include/logdef.h
@@ -225,13 +225,7 @@ typedef struct log_hnrec {
   struct log_hnrec *next;
 } log_hnrec;   /* History name */
 
-typedef struct log_brec {
-  short x1, y1, x2, y2;
-  struct log_brec *next;
-  na_long temp;
-  unsigned f7 : 1, f6 : 1, f5 : 1, f4 : 1, f3 : 1, f2 : 1, f1 : 1, f0 : 1;
-} log_brec;   /* Dashed box */
-
+typedef struct log_brec log_brec;
 
 typedef enum {
   simst_null, simst_off, simst_notactive, simst_notready, simst_running
diff --git a/src/box.c b/src/box.c
new file mode 100644
index 0000000..d284553
--- /dev/null
+++ b/src/box.c
@@ -0,0 +1,132 @@
+#include "box.h"
+#include "logglobals.h"
+#include "screen.h"
+#include "log.h"
+#include "utils.h"
+#include "keyboard.h"
+
+/// Link box to the current page.
+void linkbox(log_brec *b)
+{
+	b->next = gg.pages[gg.curpage - 1]->bbase;
+	gg.pages[gg.curpage - 1]->bbase = b;
+	stamp(&gg.boxstamp);
+}
+
+/// Creates a Box
+void newbox(log_brec **b)
+{
+	*b = (log_brec *)Malloc(sizeof(log_brec));
+	(*b)->temp = (na_long)0;
+	linkbox(*b);
+}
+
+/// Unlink box from the pages.
+void unlinkbox(log_brec *b)
+{
+	log_brec *b1;
+
+	b1 = gg.pages[gg.curpage - 1]->bbase;
+	while (b1 != NULL && b1->next != b)
+		b1 = b1->next;
+	if (b1 == NULL)
+		gg.pages[gg.curpage - 1]->bbase = b->next;
+	else
+		b1->next = b->next;
+	chpageplace(gg.pages[gg.curpage - 1], b->x1, b->y1, b->x2, b->y2);
+	stamp(&gg.boxstamp);
+}
+
+/// Dispose of a dashed box.
+void dispbox(log_brec **b)
+{
+	unlinkbox(*b);
+	Free(*b);
+}
+
+/// Create a new dashed box.
+void addboxat(short x1, short y1, short x2, short y2)
+{
+	log_brec *b;
+
+	newbox(&b);
+	sortshints(&x1, &x2);
+	sortshints(&y1, &y2);
+	b->x1 = x1;
+	b->y1 = y1;
+	b->x2 = x2;
+	b->y2 = y2;
+	remcursor();
+	clipon();
+	drawboxc(b, gg.color.dashbox);
+	clipoff();
+	chpageplace(gg.pages[gg.curpage - 1], x1, y1, x2, y2);
+	gg.nearbox = b;
+}
+
+
+void addbox()
+{
+	short x1, y1;
+
+	log_setmode("BOX");
+	clearfunc();
+	cursortype = boxcursor;
+	waitnear();
+	do
+	{
+		do
+		{
+			pass();
+			trykbdscroll();
+			pen();
+		} while (!gg.t.dn && gg.stillnear && *gg.func == '\0');
+		gg.posx = gg.gridx;
+		gg.posy = gg.gridy;
+		if (gg.incircuit && gg.stillnear && *gg.func == '\0')
+		{
+			x1 = gg.posx;
+			y1 = gg.posy;
+			do
+			{
+				pen();
+				x1 = gg.gridx;
+				y1 = gg.gridy;
+				m_colormode((long)m_xor);
+				m_color((long)gg.color.dashbox);
+				m_linestyle(1L);
+				rect(gg.posx, gg.posy, x1, y1);
+				m_linestyle(0L);
+				m_colormode((long)m_normal);
+				do
+				{
+					pass();
+					trykbd();
+					pen();
+				} while (gg.gridx == x1 && gg.gridy == y1 && gg.t.depressed && *gg.func == '\0');
+
+				m_colormode((long)m_xor);
+				m_color((long)gg.color.dashbox);
+				m_linestyle(1L);
+				rect(gg.posx, gg.posy, x1, y1);
+				m_linestyle(0L);
+				m_colormode((long)m_normal);
+				scroll();
+			} while (gg.t.depressed || abs(x1 - gg.posx) < 2 || abs(y1 - gg.posy) < 2);
+			sortshints(&gg.posx, &x1);
+			sortshints(&gg.posy, &y1);
+			remcursor();
+			if (gg.incircuit && *gg.func == '\0')
+				addboxat(gg.posx, gg.posy, x1, y1);
+		}
+	} while (gg.incircuit && gg.stillnear && *gg.func == '\0');
+	gg.startpoint = false;
+	log_setmode("");
+	if (gg.t.dn && !gg.incircuit)
+	{
+		gg.t.dn = false;
+		gg.t.depressed = false;
+	}
+	cursortype = normal;
+}
+
diff --git a/src/gate.c b/src/gate.c
index ea6e95b..d9b6d36 100644
--- a/src/gate.c
+++ b/src/gate.c
@@ -13,6 +13,7 @@
 #include "label.h"
 #include "page.h"
 #include "tool.h"
+#include "box.h"
 
 /// Check if inside a gate's "yellow box."
 /** new version by Tim Edwards, Dec 1996 */
diff --git a/src/log.c b/src/log.c
index 3ed0d43..3dfda57 100644
--- a/src/log.c
+++ b/src/log.c
@@ -74,6 +74,7 @@
 #include "utils.h"
 #include "tool.h"
 #include "keyboard.h"
+#include "box.h"
 
 #include "pagewriter.h"
 #include "pagereader.h"
@@ -1754,45 +1755,6 @@ static void clearconflicts(log_tool *tool)
 
 short getsignal (int d, char *n);
 
-/// Link box to the current page.
-static void linkbox(log_brec *b)
-{
-	b->next = gg.pages[gg.curpage - 1]->bbase;
-	gg.pages[gg.curpage - 1]->bbase = b;
-	stamp(&gg.boxstamp);
-}
-
-/// Creates a Box
-void newbox(log_brec **b)
-{
-	*b = (log_brec *)Malloc(sizeof(log_brec));
-	(*b)->temp = (na_long)0;
-	linkbox(*b);
-}
-
-/// Unlink box from the pages.
-static void unlinkbox(log_brec *b)
-{
-	log_brec *b1;
-
-	b1 = gg.pages[gg.curpage - 1]->bbase;
-	while (b1 != NULL && b1->next != b)
-		b1 = b1->next;
-	if (b1 == NULL)
-		gg.pages[gg.curpage - 1]->bbase = b->next;
-	else
-		b1->next = b->next;
-	chpageplace(gg.pages[gg.curpage - 1], b->x1, b->y1, b->x2, b->y2);
-	stamp(&gg.boxstamp);
-}
-
-/// Dispose of a dashed box.
-static void dispbox(log_brec **b)
-{
-	unlinkbox(*b);
-	Free(*b);
-}
-
 
 static void defsimulator(log_action_t *act)
 {
@@ -2281,7 +2243,7 @@ static void readlnpass(char *s, short mode)
 }
 
 
-static void clearfunc()
+void clearfunc()
 {
 	if (doingcnffunction)
 		*gg.func = '\0';
@@ -3237,7 +3199,7 @@ static void checkabort()
 }
 
 
-static void waitnear()
+void waitnear()
 {
 	do
 	{
@@ -8591,92 +8553,6 @@ static void findboxmarker(log_krec *k, short num, short *x1, short *y1, short *x
 	k->y2 = k->vector[i - 1].UU.U99.y2;
 }
 
-/// Create a new dashed box.
-void addboxat(short x1, short y1, short x2, short y2)
-{
-	log_brec *b;
-
-	newbox(&b);
-	sortshints(&x1, &x2);
-	sortshints(&y1, &y2);
-	b->x1 = x1;
-	b->y1 = y1;
-	b->x2 = x2;
-	b->y2 = y2;
-	remcursor();
-	clipon();
-	drawboxc(b, gg.color.dashbox);
-	clipoff();
-	chpageplace(gg.pages[gg.curpage - 1], x1, y1, x2, y2);
-	gg.nearbox = b;
-}
-
-
-static void addbox()
-{
-	short x1, y1;
-
-	log_setmode("BOX");
-	clearfunc();
-	cursortype = boxcursor;
-	waitnear();
-	do
-	{
-		do
-		{
-			pass();
-			trykbdscroll();
-			pen();
-		} while (!gg.t.dn && gg.stillnear && *gg.func == '\0');
-		gg.posx = gg.gridx;
-		gg.posy = gg.gridy;
-		if (gg.incircuit && gg.stillnear && *gg.func == '\0')
-		{
-			x1 = gg.posx;
-			y1 = gg.posy;
-			do
-			{
-				pen();
-				x1 = gg.gridx;
-				y1 = gg.gridy;
-				m_colormode((long)m_xor);
-				m_color((long)gg.color.dashbox);
-				m_linestyle(1L);
-				rect(gg.posx, gg.posy, x1, y1);
-				m_linestyle(0L);
-				m_colormode((long)m_normal);
-				do
-				{
-					pass();
-					trykbd();
-					pen();
-				} while (gg.gridx == x1 && gg.gridy == y1 && gg.t.depressed && *gg.func == '\0');
-
-				m_colormode((long)m_xor);
-				m_color((long)gg.color.dashbox);
-				m_linestyle(1L);
-				rect(gg.posx, gg.posy, x1, y1);
-				m_linestyle(0L);
-				m_colormode((long)m_normal);
-				scroll();
-			} while (gg.t.depressed || abs(x1 - gg.posx) < 2 || abs(y1 - gg.posy) < 2);
-			sortshints(&gg.posx, &x1);
-			sortshints(&gg.posy, &y1);
-			remcursor();
-			if (gg.incircuit && *gg.func == '\0')
-				addboxat(gg.posx, gg.posy, x1, y1);
-		}
-	} while (gg.incircuit && gg.stillnear && *gg.func == '\0');
-	gg.startpoint = false;
-	log_setmode("");
-	if (gg.t.dn && !gg.incircuit)
-	{
-		gg.t.dn = false;
-		gg.t.depressed = false;
-	}
-	cursortype = normal;
-}
-
 
 static void initcolors ();
 
diff --git a/src/loghier.c b/src/loghier.c
index f888350..ba7bfa7 100644
--- a/src/loghier.c
+++ b/src/loghier.c
@@ -31,6 +31,7 @@
 #include <utils/strings.h>
 #include "loghier.h"
 #include "node.h"
+#include "box.h"
 
 
 static log_action_t *lact;
diff --git a/src/logsimh.c b/src/logsimh.c
index 1d721de..95069a2 100644
--- a/src/logsimh.c
+++ b/src/logsimh.c
@@ -39,6 +39,7 @@
 #include <utils/strings.h>
 #include "logsimh.h"
 #include "node.h"
+#include "box.h"
 
 
 /* caged_date="R   lastmoddate = '$X by $U';" */
diff --git a/src/page.c b/src/page.c
index 3a29f82..696c11f 100644
--- a/src/page.c
+++ b/src/page.c
@@ -6,6 +6,7 @@
 #include "utils.h"
 #include "page.h"
 #include "log.h"
+#include "box.h"
 
 void chpage(log_page *page)
 {
diff --git a/src/pagereader.c b/src/pagereader.c
index 7214319..eeca5b5 100644
--- a/src/pagereader.c
+++ b/src/pagereader.c
@@ -10,6 +10,7 @@
 #include "screen.h"
 #include "tool.h"
 #include "utils.h"
+#include "box.h"
 
 void loadfail(char *msg, struct LOC_loadpage *LINK)
 {
diff --git a/src/pagewriter.c b/src/pagewriter.c
index b99bbcc..8acde3d 100644
--- a/src/pagewriter.c
+++ b/src/pagewriter.c
@@ -8,6 +8,7 @@
 #include "screen.h"
 #include "tool.h"
 #include "utils.h"
+#include "box.h"
 
 short countnode(log_nrec *n, struct LOC_savepage *LINK)
 {
diff --git a/src/screen.c b/src/screen.c
index f109633..1dbd8d1 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -41,6 +41,7 @@
 #include "screen.h"
 #include "node.h"
 #include "log.h"
+#include "box.h"
 
 static rablistrec rabtable[rabtabsize];   ///< Positions of rabbits
 
-- 
GitLab