]> cygwin.com Git - cygwin-apps/setup.git/commitdiff
* setup.c (optionprompt): allow multi-column, clean up message
authorDJ Delorie <dj@redhat.com>
Fri, 19 May 2000 00:05:25 +0000 (00:05 +0000)
committerDJ Delorie <dj@redhat.com>
Fri, 19 May 2000 00:05:25 +0000 (00:05 +0000)
about more options, be more robust about user input.
(getdownloadsource): make the mirror URL a macro.
(main): do mounts after done prompting user.

ChangeLog
setup.c

index a447b3b428b7c5a0ac1f84e64eb19731e88f7aec..cedac5e024a94ce73c962d8035d2a97c6d905614 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2000-05-18  DJ Delorie  <dj@cygnus.com>
+
+       * 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 <cgf@cygnus.com>
 
        * setup.c (cleanup): Inverse order of deletion stands a better chance
diff --git a/setup.c b/setup.c
index d8ea765ee9cd8531c12eef2f537d6916a77bdbef..3eec3807fcd1400c1447b6ece3af61b1b480a903 100644 (file)
--- a/setup.c
+++ b/setup.c
 #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; n<options->count; 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; c<ncols; c++)
+           {
+             int i = n + base + c * SCREEN_LINES;
+             if (i < options->count)
+               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)
This page took 0.036882 seconds and 5 git commands to generate.