From c8f69fe19faf1e7be5542e48366736f3fdc99ba7 Mon Sep 17 00:00:00 2001
From: Etienne Brateau <etienne.brateau@ensiie.fr>
Date: Thu, 24 Jan 2019 01:14:21 +0100
Subject: [PATCH] Fix missing chpage changes

---
 src/log.c        | 16 ++++++++--------
 src/pagereader.c |  6 +++---
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/log.c b/src/log.c
index cd17122..f75e5b6 100644
--- a/src/log.c
+++ b/src/log.c
@@ -5121,7 +5121,7 @@ static void openhoriz()
 
 			if (gg.incircuit && *gg.func == '\0')
 			{
-				chpage(gg.pages[gg.curpage]);
+				chpage(gg.pages[gg.curpage - 1]);
 				vw = gg.pages[gg.curpage - 1]->vwbase;
 				flag = false;
 				while (vw != NULL)
@@ -5290,7 +5290,7 @@ static void openvert()
 			remcursor();
 			if (gg.incircuit && *gg.func == '\0')
 			{
-				chpage(gg.pages[gg.curpage]);
+				chpage(gg.pages[gg.curpage - 1]);
 				hw = gg.pages[gg.curpage - 1]->hwbase;
 				flag = false;
 
@@ -5458,7 +5458,7 @@ static void closehoriz()
 			remcursor();
 			if (gg.incircuit && *gg.func == '\0')
 			{
-				chpage(gg.pages[gg.curpage]);
+				chpage(gg.pages[gg.curpage - 1]);
 				vw = gg.pages[gg.curpage - 1]->vwbase;
 				flag = false;
 				while (vw != NULL)
@@ -5702,7 +5702,7 @@ static void closevert()
 			remcursor();
 			if (gg.incircuit && *gg.func == '\0')
 			{
-				chpage(gg.pages[gg.curpage]);
+				chpage(gg.pages[gg.curpage - 1]);
 				hw = gg.pages[gg.curpage - 1]->hwbase;
 				flag = false;
 				while (hw != NULL)
@@ -8156,7 +8156,7 @@ end;  */
 						}
 					}
 					stamp(attrstamp);
-					chpage(gg.pages[gg.curpage]);
+					chpage(gg.pages[gg.curpage - 1]);
 				}
 				else if (ch == '\b')
 				{
@@ -8246,7 +8246,7 @@ end;  */
 						}
 					}
 					stamp(attrstamp);
-					chpage(gg.pages[gg.curpage]);
+					chpage(gg.pages[gg.curpage - 1]);
 				}
 				else
 				{
@@ -8494,7 +8494,7 @@ end;  */
 						break;
 				}
 				stamp(attrstamp);
-				chpage(gg.pages[gg.curpage]);
+				chpage(gg.pages[gg.curpage - 1]);
 				drawvalue(V.p, false, &V);
 			}
 		} while (!exitflag);
@@ -8888,7 +8888,7 @@ static void setgattr(log_grec *g, short num, char *value_)
 				g1 = g1->next;
 		}
 		if (g1 != NULL)
-			chpage(gg.pages[pg]);
+			chpage(gg.pages[pg - 1]);
 	}
 	gg.acttool = saveacttool;
 }
diff --git a/src/pagereader.c b/src/pagereader.c
index 6d9998b..1e93155 100644
--- a/src/pagereader.c
+++ b/src/pagereader.c
@@ -539,7 +539,7 @@ void loadpage(char *filename_, char *reason_)
 		V.f = NULL;
 		if (V.ip != NULL)
 			Free(V.ip);
-		chpage((int)gg.curpage);
+		chpage(gg.pages[gg.curpage - 1]);
 		gg.pages[gg.curpage - 1]->pagechanged = false;
 		if (curfilename[gg.curpage - 1] == NULL)
 			curfilename[gg.curpage - 1] = (char *)Malloc(256);
@@ -817,7 +817,7 @@ void readpage(char *filename_, char *reason)
 	if (f != NULL)
 		fclose(f);
 	f = NULL;
-	chpage((int)gg.curpage);
+	chpage(gg.pages[gg.curpage - 1]);
 	gg.pages[gg.curpage - 1]->pagechanged = false;
 	if (curfilename[gg.curpage - 1] == NULL)
 		curfilename[gg.curpage - 1] = (char *)Malloc(256);
@@ -1178,5 +1178,5 @@ void loadlog30(FILE **f, short ver)
 		if (TEMP != NULL)
 			*TEMP = 0;
 	}
-	chpage((int)gg.curpage);
+	chpage(gg.pages[gg.curpage - 1]);
 }
-- 
GitLab