diff options
Diffstat (limited to 'mdk-stage1/stdio-frontend.c')
| -rw-r--r-- | mdk-stage1/stdio-frontend.c | 195 |
1 files changed, 79 insertions, 116 deletions
diff --git a/mdk-stage1/stdio-frontend.c b/mdk-stage1/stdio-frontend.c index a8622bf1c..8c09330b5 100644 --- a/mdk-stage1/stdio-frontend.c +++ b/mdk-stage1/stdio-frontend.c @@ -1,7 +1,7 @@ /* - * Guillaume Cottenceau (gc@mandrakesoft.com) + * Guillaume Cottenceau (gc) * - * Copyright 2000 MandrakeSoft + * Copyright 2000 Mandriva * * This software may be freely redistributed under the terms of the GNU * public license. @@ -26,16 +26,16 @@ #include <fcntl.h> #include <sys/ioctl.h> #include <termios.h> -#include "stage1.h" -#include "log.h" -#include "newt.h" -#include "frontend.h" +#include <probing.h> +#include "frontend.h" +#include "utils.h" -void init_frontend(void) +void init_frontend(char * welcome_msg) { - printf("Welcome to " DISTRIB_NAME " (" VERSION ") " __DATE__ " " __TIME__ "\n"); + printf(welcome_msg); + printf("\n"); } @@ -53,11 +53,12 @@ static void get_any_response(void) while (read(0, &t, 1) > 0); fcntl(0, F_SETFL, 0); } - + static int get_int_response(void) { char s[50]; - int j = 0, i = 0; /* (0) tied to Cancel */ + int j = 0; + unsigned int i = 0; /* (0) tied to Cancel */ fflush(stdout); read(0, &(s[i++]), 1); fcntl(0, F_SETFL, O_NONBLOCK); @@ -75,7 +76,6 @@ static char * get_string_response(char * initial_string) /* I won't use a scanf/%s since I also want the null string to be accepted -- also, I want the initial_string */ char s[500]; int i = 0; - char buf[10]; int b_index = 0; char b; @@ -88,7 +88,7 @@ static char * get_string_response(char * initial_string) strcpy(s, initial_string); i = strlen(s); } - + /* from ncurses/tinfo/lib_raw.c:(cbreak) */ tcgetattr(0, &t); t.c_lflag &= ~ICANON; @@ -107,7 +107,6 @@ static char * get_string_response(char * initial_string) if (read(0, &b, 1) > 0) { if (b_index == 1) { if (b == 91) { - buf[b_index] = b; b_index++; continue; } @@ -130,7 +129,7 @@ static char * get_string_response(char * initial_string) b_index = 0; continue; } - + if (b == 13) break; if (b == 127) { @@ -145,7 +144,6 @@ static char * get_string_response(char * initial_string) i--; } } else if (b == 27) { - buf[b_index] = b; b_index++; } else { printf("%c", b); @@ -166,40 +164,27 @@ static char * get_string_response(char * initial_string) return strdup(s); } -static void blocking_msg(char *type, char *fmt, va_list args) +static void blocking_msg(char *type, char *fmt, va_list ap) { printf(type); - vprintf(fmt, args); + vprintf(fmt, ap); get_any_response(); } -void error_message(char *msg, ...) +void verror_message(char *msg, va_list ap) { - va_list args; - va_start(args, msg); - va_end(args); - blocking_msg("> Error! ", msg, args); - unset_param(MODE_AUTOMATIC); + blocking_msg("> Error! ", msg, ap); } -void info_message(char *msg, ...) +void vinfo_message(char *msg, va_list ap) { - va_list args; - va_start(args, msg); - va_end(args); - if (!IS_AUTOMATIC) - blocking_msg("> Notice: ", msg, args); - else - vlog_message(msg, args); + blocking_msg("> Notice: ", msg, ap); } -void wait_message(char *msg, ...) +void vwait_message(char *msg, va_list ap) { - va_list args; printf("Please wait: "); - va_start(args, msg); - vprintf(msg, args); - va_end(args); + vprintf(msg, ap); fflush(stdout); } @@ -211,116 +196,90 @@ void remove_wait_message(void) static int size_progress; static int actually_drawn; -#define PROGRESS_SIZE 60 -void init_progression(char *msg, int size) +#define PROGRESS_SIZE 45 +void init_progression_raw(char *msg, int size) { int i; size_progress = size; - printf("%s\n", msg); + printf("%s ", msg); if (size) { - printf("["); actually_drawn = 0; for (i=0; i<PROGRESS_SIZE; i++) printf("."); - printf("]\033[G["); /* only works on ANSI-compatibles */ + printf("]\033[G%s [", msg); /* only works on ANSI-compatibles */ fflush(stdout); - } + } else + printf("\n"); } -void update_progression(int current_size) +void update_progression_raw(int current_size) { if (size_progress) { - if (current_size <= size_progress) - while ((int)((current_size*PROGRESS_SIZE)/size_progress) > actually_drawn) { - printf("*"); - actually_drawn++; - } + if (current_size > size_progress) + current_size = size_progress; + while ((int)((current_size*PROGRESS_SIZE)/size_progress) > actually_drawn) { + printf("*"); + actually_drawn++; + } } else - printf("\033[G%d bytes read", current_size); - + printf("\033[GStatus: [%8d] bytes loaded...", current_size); + fflush(stdout); } -void end_progression(void) +void end_progression_raw(void) { if (size_progress) { - update_progression(size_progress); + update_progression_raw(size_progress); printf("]\n"); } else printf(" done.\n"); } -enum return_type ask_from_list_comments(char *msg, char ** elems, char ** elems_comments, char ** choice) +enum return_type ask_from_list_index(char *msg, char ** elems, char ** elems_comments, int *answer) { - char ** sav_elems = elems; - int i, j; - - 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++; + int justify_number = 1; + void print_choice_number(int i) { + char tmp[500]; + snprintf(tmp, sizeof(tmp), "[%%%dd]", justify_number); + printf(tmp, i); } + int i = 1; + int j = 0; - printf("? "); - - j = get_int_response(); - - if (j == 0) - return RETURN_BACK; - - if (j >= 1 && j < i) { - *choice = strdup(sav_elems[j-1]); - return RETURN_OK; - } - - return RETURN_ERROR; -} + if (string_array_length(elems) >= 10) + justify_number = 2; + i = 1; -enum return_type ask_from_list(char *msg, char ** elems, char ** choice) -{ - char ** sav_elems = elems; - int i, j; + printf("> %s\n", msg); + print_choice_number(0); + printf(" Cancel"); - i = 0; while (elems && *elems) { - i++; - elems++; - } - - if (i < 10) { - printf("> %s\n(0) Cancel\n", msg); - for (j=0; j<i; j++) - printf("(%d) %s\n", j+1, sav_elems[j]); - } - else { - printf("> %s\n( 0) Cancel\n", msg); - if (i < 20) - for (j=0; j<i; j++) - printf("(%2d) %s\n", j+1, sav_elems[j]); - else { - if (i < 40) - for (j=0; j<i-1; j += 2) - printf("(%2d) %-34s (%2d) %s\n", j+1, sav_elems[j], j+2, sav_elems[j+1]); - else - for (j=0; j<i-3; j += 4) - printf("(%2d) %-14s (%2d) %-14s (%2d) %-14s (%2d) %s\n", - j+1, sav_elems[j], j+2, sav_elems[j+1], j+3, sav_elems[j+2], j+4, sav_elems[j+3]); - if (j < i) { - while (j < i) { - printf("(%2d) %-14s ", j+1, sav_elems[j]); - j++; - } + if (elems_comments && *elems_comments) { + printf("\n"); + print_choice_number(i); + printf(" %s (%s)", *elems, *elems_comments); + j = 0; + } else { + if (j == 0) printf("\n"); - } + print_choice_number(i); + printf(" %-14s ", *elems); + j++; } + if (j == 4) + j = 0; + + if (elems_comments) + elems_comments++; + i++; + elems++; } - printf("? "); + printf("\n? "); j = get_int_response(); @@ -328,7 +287,7 @@ enum return_type ask_from_list(char *msg, char ** elems, char ** choice) return RETURN_BACK; if (j >= 1 && j <= i) { - *choice = strdup(sav_elems[j-1]); + *answer = j - 1; return RETURN_OK; } @@ -340,7 +299,7 @@ enum return_type ask_yes_no(char *msg) { int j; - printf("> %s\n(0) Yes\n(1) No\n(2) Back\n? ", msg); + printf("> %s\n[0] Yes [1] No [2] Back\n? ", msg); j = get_int_response(); @@ -352,7 +311,7 @@ enum return_type ask_yes_no(char *msg) } -enum return_type ask_from_entries(char *msg, char ** questions, char *** answers, int entry_size, void (*callback_func)(char ** strings)) +enum return_type ask_from_entries(char *msg, char ** questions, char *** answers, int entry_size UNUSED, void (*callback_func)(char ** strings) UNUSED) { int j, i = 0; char ** already_answers = NULL; @@ -366,7 +325,7 @@ enum return_type ask_from_entries(char *msg, char ** questions, char *** answers } if (*answers == NULL) - *answers = (char **) malloc(sizeof(char *) * i); + *answers = (char **) calloc(1, sizeof(char *) * i); else already_answers = *answers; @@ -381,7 +340,7 @@ enum return_type ask_from_entries(char *msg, char ** questions, char *** answers (*answers)[j] = get_string_response(NULL); } - printf("(0) Cancel (1) Accept (2) Re-enter answers\n? "); + printf("[0] Cancel [1] Accept [2] Re-enter answers\n? "); r = get_int_response(); if (r == 0) return RETURN_BACK; @@ -389,3 +348,7 @@ enum return_type ask_from_entries(char *msg, char ** questions, char *** answers return RETURN_OK; } } + + +void suspend_to_console(void) {} +void resume_from_suspend(void) {} |
