From 35c9f612605d43288662b19ad4fa8931abec001b Mon Sep 17 00:00:00 2001
From: "Andrey A. Chernov" <ache@FreeBSD.org>
Date: Thu, 20 Oct 1994 19:30:56 +0000
Subject: [PATCH] remove unneded includes use dialog functions properly move
 alloc_memory early to prevent core dump at stage 3 Change 25x80 to 24x80 Fix
 setenv diagnostic Fix Fatal to call end_dialog()

---
 sbin/sysinstall/main.c       | 10 +++++++---
 sbin/sysinstall/stage0.c     | 11 +++++------
 sbin/sysinstall/stage1.c     | 16 +++++++---------
 sbin/sysinstall/stage2.c     |  3 +--
 sbin/sysinstall/stage3.c     |  9 ++++-----
 sbin/sysinstall/sysinstall.c | 19 +++++++++----------
 sbin/sysinstall/termcap.c    |  2 --
 sbin/sysinstall/utils.c      |  4 ++--
 8 files changed, 35 insertions(+), 39 deletions(-)

diff --git a/sbin/sysinstall/main.c b/sbin/sysinstall/main.c
index 61fe8245d86d..5ce06ce3dd24 100644
--- a/sbin/sysinstall/main.c
+++ b/sbin/sysinstall/main.c
@@ -6,7 +6,7 @@
  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
  * ----------------------------------------------------------------------------
  *
- * $Id: main.c,v 1.3 1994/10/20 06:14:29 phk Exp $
+ * $Id: main.c,v 1.4 1994/10/20 06:48:39 phk Exp $
  *
  */
 
@@ -18,7 +18,6 @@
 #include <fcntl.h>
 
 #include <dialog.h>
-#include <ncurses.h>
 
 #include <sys/ioctl.h>
 
@@ -61,6 +60,8 @@ jmp_buf	jmp_restart;
  *		execl("/sbin/init");
  */
 
+extern int alloc_memory();
+
 int
 main(int argc, char **argv)
 {
@@ -86,6 +87,9 @@ main(int argc, char **argv)
 	/* If we haven't crashed I guess dialog is running ! */
 	dialog_active = 1;
 
+	if (alloc_memory() < 0)
+		Fatal("No memory\n");
+
 	setjmp(jmp_restart);
 
 	if (getenv("STAGE0") || !access("/this_is_boot_flp",R_OK)) {
@@ -112,7 +116,7 @@ main(int argc, char **argv)
 	} else if (getenv("STAGE3")) {
 		stage3();
 	} else {
-		fprintf(stderr,"Must setenv STAGE0 or STAGE3");
+		fprintf(stderr,"Must setenv STAGE0 or STAGE3\n");
 	}
 	return 0;
 }
diff --git a/sbin/sysinstall/stage0.c b/sbin/sysinstall/stage0.c
index 7ba854704335..c5483e88bc5d 100644
--- a/sbin/sysinstall/stage0.c
+++ b/sbin/sysinstall/stage0.c
@@ -6,7 +6,7 @@
  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
  * ----------------------------------------------------------------------------
  *
- * $Id$
+ * $Id: stage0.c,v 1.2 1994/10/20 04:59:56 phk Exp $
  *
  */
 
@@ -15,7 +15,6 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <ncurses.h>
 #include <dialog.h>
 
 #include "sysinstall.h"
@@ -24,11 +23,11 @@ void
 stage0()
 {
 	if (!access(README_FILE, R_OK)) {
-		clear();
-		dialog_textbox("READ ME FIRST", README_FILE, 25, 80);
+		dialog_clear();
+		dialog_textbox("READ ME FIRST", README_FILE, 24, 80);
 	}
 	if (!access(COPYRIGHT_FILE, R_OK)) {
-		clear();
-		dialog_textbox("COPYRIGHT", COPYRIGHT_FILE, 25, 80);
+		dialog_clear();
+		dialog_textbox("COPYRIGHT", COPYRIGHT_FILE, 24, 80);
 	}
 }
diff --git a/sbin/sysinstall/stage1.c b/sbin/sysinstall/stage1.c
index a946aad718b4..035ed86ece6a 100644
--- a/sbin/sysinstall/stage1.c
+++ b/sbin/sysinstall/stage1.c
@@ -20,7 +20,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdarg.h>
-#include <ncurses.h>
 
 #include <sys/types.h>
 #include <sys/errno.h>
@@ -189,7 +188,7 @@ select_disk()
 			AskAbort(scratch);
 			valid = 0;
 		}
-		clear();
+		dialog_clear();
 	} while (!valid);
 	return(atoi(selection) - 1);
 }
@@ -220,12 +219,12 @@ select_partition(int disk)
 			AskAbort(scratch);
 			valid = 0;
 		}
-		clear();
+		dialog_clear();
 		choice = atoi(selection);
 		if (!choice)
 			if (dialog_yesno(TITLE, "Installing to the whole disk will erase all its present data.\n\nAre you sure you want to do this?", 10, 75))
 				valid = 0;
-		clear();
+		dialog_clear();
 	} while (!valid);
 	
 	return(atoi(selection) - 1);
@@ -238,7 +237,6 @@ stage1()
 	int ok = 0;
 	int ready = 0;
 
-	alloc_memory();
 	while (!ready) {
 		ready = 1;
 
@@ -257,7 +255,7 @@ stage1()
 				AskAbort(scratch);
 				if (!dialog_yesno(TITLE, "Are you sure you wish to proceed?",
 									  10, 75)) {
-					clear();
+					dialog_clear();
 					clear_mbr(mbr);
 					ok = 1;
 				}
@@ -267,7 +265,7 @@ stage1()
 		if (custom_install) 
 			if (!dialog_yesno(TITLE, "Do you wish to edit the DOS partition table?",
 								  10, 75)) {
-				clear();
+				dialog_clear();
 				edit_mbr(mbr, &avail_disklabels[inst_disk]);
 			}
 
@@ -281,7 +279,7 @@ stage1()
 				sprintf(scratch, "The DOS partition table is inconsistent.\n\n%s\n\nDo you wish to edit it by hand?", errmsg);
 				if (!dialog_yesno(TITLE, scratch, 10, 75)) {
 					edit_mbr(mbr, &avail_disklabels[inst_disk]);
-					clear();
+					dialog_clear();
 				} else {
 					AskAbort("");
 					ok = 1;
@@ -300,7 +298,7 @@ stage1()
 				AskAbort("");
 				ready = 0;
 			}
-			clear();
+			dialog_clear();
 		}
 	}
 
diff --git a/sbin/sysinstall/stage2.c b/sbin/sysinstall/stage2.c
index 3a7e0e4b49a3..200d3edba603 100644
--- a/sbin/sysinstall/stage2.c
+++ b/sbin/sysinstall/stage2.c
@@ -6,7 +6,7 @@
  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
  * ----------------------------------------------------------------------------
  *
- * $Id: stage2.c,v 1.1 1994/10/20 04:59:58 phk Exp $
+ * $Id: stage2.c,v 1.2 1994/10/20 06:48:40 phk Exp $
  *
  */
 
@@ -18,7 +18,6 @@
 #include <unistd.h>
 
 #include <fcntl.h>
-#include <ncurses.h>
 #include <dialog.h>
 #include <errno.h>
 
diff --git a/sbin/sysinstall/stage3.c b/sbin/sysinstall/stage3.c
index c2996dc66f46..b14c056cd5f2 100644
--- a/sbin/sysinstall/stage3.c
+++ b/sbin/sysinstall/stage3.c
@@ -6,14 +6,13 @@
  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
  * ----------------------------------------------------------------------------
  *
- * $Id$
+ * $Id: stage3.c,v 1.2 1994/10/20 04:59:58 phk Exp $
  *
  */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <dialog.h>
-#include <ncurses.h>
 #include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
@@ -136,9 +135,9 @@ stage3()
 	unlink("/sbin/oinit");
 	TellEm("link /stand/sysinstall /sbin/init");
 	link("/stand/sysinstall", "/sbin/init");
-	clear();
-	refresh();
-	endwin();
+	dialog_clear();
+	dialog_update();
+	end_dialog();
 	close(0);
 	close(1);
 	close(2);
diff --git a/sbin/sysinstall/sysinstall.c b/sbin/sysinstall/sysinstall.c
index 16b263bad41b..a45f603d07b9 100644
--- a/sbin/sysinstall/sysinstall.c
+++ b/sbin/sysinstall/sysinstall.c
@@ -20,7 +20,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdarg.h>
-#include <ncurses.h>
 
 #include <sys/types.h>
 #include <sys/errno.h>
@@ -76,7 +75,7 @@ abort_installation(char *prompt)
 	strcat(scratch,"\n\n Do you wish to abort the installation ?");
 	if (!dialog_yesno("Abort installation ?",scratch,10,75))
 		exit_prompt();
-	clear();
+	dialog_clear();
 }
 
 void
@@ -85,7 +84,7 @@ exit_prompt()
 	sprintf(scratch,"Are you sure you want to exit sysinstall?");
 	if (!dialog_yesno("Exit sysinstall",scratch,10,75))
 		exit_sysinstall();
-	clear();
+	dialog_clear();
 }
 
 int
@@ -257,7 +256,7 @@ select_disk()
 			abort_installation(scratch);
 			valid = 0;
 		}
-		clear();
+		dialog_clear();
 	} while (!valid);
 	return(atoi(selection) - 1);
 }
@@ -288,12 +287,12 @@ select_partition(int disk)
 			abort_installation(scratch);
 			valid = 0;
 		}
-		clear();
+		dialog_clear();
 		choice = atoi(selection);
 		if (!choice)
 			if (dialog_yesno(title, "Installing to the whole disk will erase all its present data.\n\nAre you sure you want to do this?", 10, 75))
 				valid = 0;
-		clear();
+		dialog_clear();
 	} while (!valid);
 	
 	return(atoi(selection) - 1);
@@ -528,7 +527,7 @@ stage1()
 				abort_installation(scratch);
 				if (!dialog_yesno(title, "Are you sure you wish to proceed?",
 									  10, 75)) {
-					clear();
+					dialog_clear();
 					clear_mbr(mbr);
 					ok = 1;
 				}
@@ -538,7 +537,7 @@ stage1()
 		if (custom_install) 
 			if (!dialog_yesno(title, "Do you wish to edit the DOS partition table?",
 								  10, 75)) {
-				clear();
+				dialog_clear();
 				edit_mbr(mbr, &avail_disklabels[inst_disk]);
 			}
 
@@ -552,7 +551,7 @@ stage1()
 				sprintf(scratch, "The DOS partition table is inconsistent.\n\n%s\n\nDo you wish to edit it by hand?", errmsg);
 				if (!dialog_yesno(title, scratch, 10, 75)) {
 					edit_mbr(mbr, &avail_disklabels[inst_disk]);
-					clear();
+					dialog_clear();
 				} else {
 					abort_installation("");
 					ok = 1;
@@ -571,7 +570,7 @@ stage1()
 				abort_installation("");
 				ready = 0;
 			}
-			clear();
+			dialog_clear();
 		}
 	}
 
diff --git a/sbin/sysinstall/termcap.c b/sbin/sysinstall/termcap.c
index a6d7e4998eff..cdb8d5ec7b5c 100644
--- a/sbin/sysinstall/termcap.c
+++ b/sbin/sysinstall/termcap.c
@@ -17,8 +17,6 @@
 #include <unistd.h>
 #include <stdarg.h>
 #include <fcntl.h>
-#include <dialog.h>
-#include <ncurses.h>
 #include <machine/console.h>
 
 #include "sysinstall.h"
diff --git a/sbin/sysinstall/utils.c b/sbin/sysinstall/utils.c
index c5a0382f9201..59f467a60744 100644
--- a/sbin/sysinstall/utils.c
+++ b/sbin/sysinstall/utils.c
@@ -6,7 +6,7 @@
  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
  * ----------------------------------------------------------------------------
  *
- * $Id: utils.c,v 1.2 1994/10/20 05:00:00 phk Exp $
+ * $Id: utils.c,v 1.3 1994/10/20 06:48:40 phk Exp $
  *
  */
 
@@ -16,7 +16,6 @@
 #include <unistd.h>
 #include <string.h>
 #include <dialog.h>
-#include <ncurses.h>
 #include <errno.h>
 
 #include <sys/stat.h>
@@ -51,6 +50,7 @@ Fatal(char *fmt, ...)
 	va_end(ap);
 	dialog_msgbox("Fatal", p, 12, 75, 1);
 	free(p);
+	end_dialog();
 	exit(7);
 }