#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
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
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
{
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 =
}
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)