From f4dda8f0e6cc45b63d589d068e9b311388145fb9 Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Fri, 19 May 2000 00:05:25 +0000 Subject: [PATCH] * setup.c (optionprompt): allow multi-column, clean up message about more options, be more robust about user input. (getdownloadsource): make the mirror URL a macro. (main): do mounts after done prompting user. --- ChangeLog | 7 ++++ setup.c | 101 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 66 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index a447b3b4..cedac5e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2000-05-18 DJ Delorie + + * setup.c (optionprompt): allow multi-column, clean up message + about more options, be more robust about user input. + (getdownloadsource): make the mirror URL a macro. + (main): do mounts after done prompting user. + Tue May 2 00:56:41 2000 Christopher Faylor * setup.c (cleanup): Inverse order of deletion stands a better chance diff --git a/setup.c b/setup.c index d8ea765e..3eec3807 100644 --- a/setup.c +++ b/setup.c @@ -36,10 +36,13 @@ #include "strarry.h" #include "zlib/zlib.h" +#define MIRRORFILE "http://sourceware.cygnus.com/cygwin/mirrors.html" + #define CYGNUS_KEY "Software\\Cygnus Solutions" #define DEF_ROOT "C:\\cygwin" #define DOWNLOAD_SUBDIR "latest/" -#define SCREEN_LINES 25 +#define SCREEN_LINES 23 +#define SCREEN_COLS 80 #define COMMAND9X "command.com /E:4096 /c " #ifndef NFILE_LIST @@ -492,58 +495,73 @@ prompt (const char *text, const char *def) static int optionprompt (const char *text, SA * options) { - size_t n, response = -1; + size_t n, c, response = -1; char buf[5]; size_t base; + int maxwidth=0, ncols, skip, percol; - n = 0; - - do + for (n=0; ncount; n++) { - char *or; - enum - { CONTINUE, REPEAT, ALL } - mode; + int sl = strlen(options->array[n]); + if (maxwidth < sl) + maxwidth = sl; + } + ncols = SCREEN_COLS / (maxwidth + 5); + skip = (options->count + ncols - 1) / ncols; + printf("count = %d ncols = %d skip = %d\n", + options->count, ncols, skip); + percol = SCREEN_COLS / ncols; - base = n; - if (!base) - puts (text); + base = 0; - for (n = 0; n < SCREEN_LINES - 2 && (n + base) < options->count; ++n) - printf ("\t%d. %s\n", n + 1, options->array[n + base]); + puts (text); - if ((n + base) < options->count) + while (1) + { + char *repeat, *enter; + + for (n=0; n < SCREEN_LINES; n++) { - mode = CONTINUE; - or = " or [continue]"; + if (n + base >= options->count) + break; + for (c=0; ccount) + printf("%2d. %-*s", i+1, percol-5, options->array[i]); + } + printf("\n"); } - else if (options->count > SCREEN_LINES - 2) + + repeat = enter = ""; + if (skip > SCREEN_LINES) { - mode = REPEAT; - or = " or [repeat]"; + if (base) + repeat = " or `R' to repeat the list"; + if (base + SCREEN_LINES*ncols < options->count) + enter = " or [Enter] for more options"; } - else + + printf ("Select an option from 1-%d%s%s: ", options->count, repeat, enter); + if (!fgets (buf, sizeof (buf), stdin)) { - mode = ALL; - or = ""; + /* This can only mean end-of-file, user has gone away */ + exit(1); } - printf ("Select an option from 1-%d%s: ", n, or); - if (!fgets (buf, sizeof (buf), stdin)) - continue; - if (mode == CONTINUE && (!isalnum (*buf) || strchr ("cC", *buf))) - continue; - else if (mode == REPEAT && (!isalnum (*buf) || strchr ("rR", *buf))) + response = atoi(buf); + if (response >= 1 && response <= options->count) + return response - 1; + + if (buf[0] == 'c' || buf[0] == 'C' || buf[0] == '\r' || buf[0] == '\n') { - n = 0; - continue; + if (base + SCREEN_LINES * ncols < options->count) + base += SCREEN_LINES * ncols; } + if (buf[0] == 'r' || buf[0] == 'R') + base = 0; - response = atoi (buf); } - while (response < 1 || response > n); - - return base + response - 1; } static int @@ -1213,8 +1231,7 @@ getdownloadsource () exit (1); } - if (!geturl ("http://sourceware.cygnus.com/cygwin/mirrors.html", - filename, 1)) + if (!geturl (MIRRORFILE, filename, 1)) fputs ("Unable to retrieve the list of cygwin mirrors.\n", stderr); else { @@ -1517,11 +1534,6 @@ those as the basis for your installation.\n\n" Sleep (0); - /* Create the root directory. */ - mkdirp (root); /* Ignore any return value since it may - already exist. */ - mkmount (wd, "", root, "/", 1); - pkgstuff = get_pkg_stuff (root, updating); update = @@ -1551,6 +1563,11 @@ those as the basis for your installation.\n\n" } xfree (update); + /* Create the root directory. */ + mkdirp (root); /* Ignore any return value since it may + already exist. */ + mkmount (wd, "", root, "/", 1); + /* Make the root directory the current directory so that recurse_dirs will * extract the packages into the correct path. */ if (chdir (root) == -1) -- 2.43.5