summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/stdio-frontend.c
diff options
context:
space:
mode:
authorGuillaume Cottenceau <gc@mandriva.com>2000-12-11 17:10:17 +0000
committerGuillaume Cottenceau <gc@mandriva.com>2000-12-11 17:10:17 +0000
commit7e1dcea7f367619fe2fca98d79087a0beed267b4 (patch)
treea0d1adc99d8253a9c2866272709dc1870935e6bd /mdk-stage1/stdio-frontend.c
parent75dbadee24b0bd6b738093b66f8415a630692671 (diff)
downloaddrakx-7e1dcea7f367619fe2fca98d79087a0beed267b4.tar
drakx-7e1dcea7f367619fe2fca98d79087a0beed267b4.tar.gz
drakx-7e1dcea7f367619fe2fca98d79087a0beed267b4.tar.bz2
drakx-7e1dcea7f367619fe2fca98d79087a0beed267b4.tar.xz
drakx-7e1dcea7f367619fe2fca98d79087a0beed267b4.zip
add stdio frontend (get rid of newt+slang -eq reducing binary by 80 kbytes) (40 kbytes for compressed binary)
Diffstat (limited to 'mdk-stage1/stdio-frontend.c')
-rw-r--r--mdk-stage1/stdio-frontend.c172
1 files changed, 172 insertions, 0 deletions
diff --git a/mdk-stage1/stdio-frontend.c b/mdk-stage1/stdio-frontend.c
new file mode 100644
index 000000000..e702a79a7
--- /dev/null
+++ b/mdk-stage1/stdio-frontend.c
@@ -0,0 +1,172 @@
+/*
+ * Guillaume Cottenceau (gc@mandrakesoft.com)
+ *
+ * Copyright 2000 MandrakeSoft
+ *
+ * This software may be freely redistributed under the terms of the GNU
+ * public license.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/*
+ * Portions from Erik Troan (ewt@redhat.com)
+ *
+ * Copyright 1996 Red Hat Software
+ *
+ */
+
+
+/*
+ * Each different frontend must implement all functions defined in frontend.h
+ */
+
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <fcntl.h>
+#include "stage1.h"
+#include "log.h"
+#include "newt.h"
+
+#include "frontend.h"
+
+
+void init_frontend(void)
+{
+ printf("Welcome to Linux-Mandrake (" VERSION ") " __DATE__ " " __TIME__ "\n");
+}
+
+
+void finish_frontend(void)
+{
+}
+
+static char get_char_response(void)
+{
+ unsigned char cmd1, cmd2;
+
+ fflush(stdout);
+ if (read(0, &cmd1, 1) > 0) {
+ fcntl(0, F_SETFL, O_NONBLOCK);
+ while (read(0, &cmd2, 1) > 0);
+ fcntl(0, F_SETFL, 0);
+ }
+
+ return cmd1;
+}
+
+
+void error_message(char *msg)
+{
+ printf("Error! %s", msg);
+ get_char_response();
+ printf("\n");
+}
+
+void wait_message(char *msg, ...)
+{
+ va_list args;
+
+ printf("Please wait: ");
+ va_start(args, msg);
+ vprintf(msg, args);
+ va_end(args);
+
+ fflush(stdout);
+}
+
+void remove_wait_message(void)
+{
+ printf("\n");
+}
+
+
+enum return_type ask_from_list_comments(char *msg, char ** elems, char ** elems_comments, char ** choice)
+{
+ char ** sav_elems = elems;
+ int i, j;
+ unsigned char answ;
+
+ printf("> %s\n(0) Cancel\n", msg);
+ i = 1;
+ while (elems && *elems) {
+ printf("(%d) %s (%s)\n", i, *elems, *elems_comments);
+ i++;
+ elems++;
+ elems_comments++;
+ }
+
+ printf("? ");
+
+ answ = get_char_response();
+
+ j = answ - '0';
+
+ if (j == 0)
+ return RETURN_BACK;
+
+ if (j >= 1 && j < i) {
+ *choice = strdup(sav_elems[j-1]);
+ return RETURN_OK;
+ }
+
+ return RETURN_ERROR;
+}
+
+
+enum return_type ask_from_list(char *msg, char ** elems, char ** choice)
+{
+ char ** sav_elems = elems;
+ int i, j;
+ unsigned char answ;
+
+ printf("> %s\n(0) Cancel\n", msg);
+ i = 1;
+ while (elems && *elems) {
+ printf("(%d) %s\n", i, *elems);
+ i++;
+ elems++;
+ }
+
+ printf("? ");
+
+ answ = get_char_response();
+
+ j = answ - '0';
+
+ if (j == 0)
+ return RETURN_BACK;
+
+ if (j >= 1 && j < i) {
+ *choice = strdup(sav_elems[j-1]);
+ return RETURN_OK;
+ }
+
+ return RETURN_ERROR;
+}
+
+
+enum return_type ask_yes_no(char *msg)
+{
+ unsigned char answ;
+ int j;
+
+ printf("> %s\n(0) Yes\n(1) No\n(2) Back\n? ", msg);
+
+ answ = get_char_response();
+
+ j = answ - '0';
+
+ if (j == 0)
+ return RETURN_OK;
+ else if (j == 2)
+ return RETURN_BACK;
+ else return RETURN_ERROR;
+}