]> cygwin.com Git - cygwin-apps/setup.git/commitdiff
* Replace everything with a new GUI version
authorDJ Delorie <dj@redhat.com>
Fri, 7 Jul 2000 00:29:21 +0000 (00:29 +0000)
committerDJ Delorie <dj@redhat.com>
Fri, 7 Jul 2000 00:29:21 +0000 (00:29 +0000)
* zlib/gzio.c: add gzctell() for progress displays

65 files changed:
ChangeLog
Makefile.in
README
choose.cc [new file with mode: 0644]
concat.cc [new file with mode: 0644]
concat.h [new file with mode: 0644]
ctar.c [deleted file]
cygcalls.c [deleted file]
dialog.cc [new file with mode: 0644]
dialog.h [new file with mode: 0644]
diskfull.cc [new file with mode: 0644]
diskfull.h [new file with mode: 0644]
download.cc [new file with mode: 0644]
error.c [deleted file]
find.cc [new file with mode: 0644]
find.h [new file with mode: 0644]
fromcwd.cc [new file with mode: 0644]
geturl.cc [new file with mode: 0644]
geturl.h [new file with mode: 0644]
gzip.exe.gz [deleted file]
ini.cc [new file with mode: 0644]
ini.h [new file with mode: 0644]
inilex.l [new file with mode: 0644]
iniparse.y [new file with mode: 0644]
install.cc [new file with mode: 0644]
main.cc [new file with mode: 0644]
memory.c [deleted file]
mkdir.cc [new file with mode: 0644]
mkdir.h [moved from strarry.h with 53% similarity]
mount.cc [new file with mode: 0644]
mount.h [new file with mode: 0644]
msg.cc [new file with mode: 0644]
msg.h [new file with mode: 0644]
net.cc [new file with mode: 0644]
netio.cc [new file with mode: 0644]
netio.h [new file with mode: 0644]
nio-file.cc [new file with mode: 0644]
nio-file.h [moved from cygcalls.h with 70% similarity]
nio-ie5.cc [new file with mode: 0644]
nio-ie5.h [new file with mode: 0644]
other.cc [new file with mode: 0644]
path.c [deleted file]
pkg.c [deleted file]
port.h [new file with mode: 0644]
res.rc [new file with mode: 0644]
resource.h
root.cc [new file with mode: 0644]
setup.c [deleted file]
setup.dsp [deleted file]
setup.dsw [deleted file]
setup.h [deleted file]
setupres.rc [deleted file]
site.cc [new file with mode: 0644]
source.cc [new file with mode: 0644]
state.cc [new file with mode: 0644]
state.h [new file with mode: 0644]
strarry.c [deleted file]
tar.cc [moved from tar.c with 89% similarity]
tar.exe.gz [deleted file]
tar.h
win32.h [new file with mode: 0644]
xsystem.c [deleted file]
zlib.dsp [deleted file]
zlib/gzio.c
zlib/zlib.h

index d92f196da947198d62e7df001fd5d3ce37079add..da74a9e6c6afcf5497ee650ef471be1c8d73a502 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2000-07-06  DJ Delorie  <dj@cygnus.com>
+
+       * Replace everything with a new GUI version
+       * zlib/gzio.c: add gzctell() for progress displays
+
+2000-06-22  DJ Delorie  <dj@cygnus.com>
+
+       * setup.c (tarx): re-add call to write_pkg()
+
 2000-06-07  DJ Delorie  <dj@cygnus.com>
 
        * cygcalls.c: new, call cygwin1.dll functions directly
index 18db4e6d58fd55f24f501ed39b0eaf96528a9c94..d1604f1ab3f5987096a6235ac157385b64ec3d0a 100644 (file)
 #
 # Makefile for Cygwin installer
 
-SHELL:=@SHELL@
+SHELL := @SHELL@
 
-srcdir:=@srcdir@
-VPATH:=@srcdir@
-prefix:=@prefix@
-exec_prefix:=@exec_prefix@
+srcdir         := @srcdir@
+VPATH          := @srcdir@
+prefix         := @prefix@
+exec_prefix    := @exec_prefix@
 
-bindir:=@bindir@
-etcdir:=$(exec_prefix)/etc
-program_transform_name:=@program_transform_name@
+bindir         := @bindir@
+etcdir         := $(exec_prefix)/etc
 
-INSTALL:=@INSTALL@
-INSTALL_PROGRAM:=@INSTALL_PROGRAM@
-INSTALL_DATA:=@INSTALL_DATA@
+program_transform_name := @program_transform_name@
 
-EXEEXT:=@EXEEXT@
-EXEEXT_FOR_BUILD:=@EXEEXT_FOR_BUILD@
+INSTALL                := @INSTALL@
+INSTALL_PROGRAM        := @INSTALL_PROGRAM@
+INSTALL_DATA   := @INSTALL_DATA@
 
-CC:=@CC@
-CC_FOR_TARGET:=$(CC)
+EXEEXT         := @EXEEXT@
+EXEEXT_FOR_BUILD := @EXEEXT_FOR_BUILD@
 
-CFLAGS:=@CFLAGS@ -nostdinc
-CXXFLAGS:=@CXXFLAGS@ -fno-exceptions -nostdinc++ -fno-rtti
+CC             := @CC@
+CC_FOR_TARGET  := $(CC)
 
-WINDRES:=@WINDRES@
-OBJCOPY:=@OBJCOPY@
+CFLAGS         := @CFLAGS@ -nostdinc
+CXXFLAGS       := @CXXFLAGS@ -fno-exceptions -nostdinc++ -fno-rtti
+
+WINDRES                := @WINDRES@
+OBJCOPY                := @OBJCOPY@
 
 include $(srcdir)/../Makefile.common
 
-MINGW_INCLUDES:=-I$(mingw_source)/include -I$(w32api_include)
+MINGW_INCLUDES := -I. -I$(mingw_source)/include -I$(w32api_include)
+
+MINGW_CXXFLAGS := $(CXXFLAGS) -mno-cygwin $(MINGW_INCLUDES) -mwindows
+MINGW_CFLAGS   := $(CFLAGS) -mno-cygwin $(MINGW_INCLUDES) -mwindows
 
-MINGW_CXXFLAGS:=$(CXXFLAGS) -mno-cygwin $(MINGW_INCLUDES)
-MINGW_CFLAGS:=$(CFLAGS) -mno-cygwin $(MINGW_INCLUDES)
+ZLIB           := zlib/libzcygw.a
+libmingw32.a   := $(mingw_build)/libmingw32.a
+libuser32      := $(w32api_lib)/libuser32.a
+libkernel32    := $(w32api_lib)/libkernel32.a
 
-ZLIB=zlib/libzcygw.a
-libmingw32.a:=$(mingw_build)/libmingw32.a
-libuser32:=$(w32api_lib)/libuser32.a
-libkernel32:=$(w32api_lib)/libkernel32.a
-ALL_DEP_LDLIBS:=$(ZLIB) $(w32api_lib)/libole32.a $(w32api_lib)/libwininet.a \
+ALL_DEP_LDLIBS := $(ZLIB) $(w32api_lib)/libole32.a $(w32api_lib)/libwininet.a \
                $(w32api_lib)/libnetapi32.a $(w32api_lib)/libadvapi32.a \
                $(w32api_lib)/libuuid.a $(libkernel32) $(w32api_lib)/libuser32.a \
                $(libmingw32)
 
-ALL_LDLIBS:=${patsubst $(mingw_build)/lib%.a,-l%,\
+ALL_LDLIBS     := ${patsubst $(mingw_build)/lib%.a,-l%,\
              ${patsubst $(w32api_lib)/lib%.a,-l%,\
                ${filter-out $(libmingw32),\
                  ${filter-out $(libuser32),\
                    ${filter-out $(libkernel32), $(ALL_DEP_LDLIBS)}}}}}
 
-ALL_LDFLAGS:=${filter-out -I%, \
+ALL_LDFLAGS    := ${filter-out -I%, \
               ${filter-out -W%, \
                -B$(w32api_lib)/ -B${mingw_build}/ $(MINGW_CFLAGS) $(LDFLAGS)}}
 
-PROGS:=setup$(EXEEXT)
-
-OBJS:=cygcalls.o error.o memory.o setup.o strarry.o cinstall.o path.o pkg.o tar.o xsystem.o
+PROGS  := setup$(EXEEXT)
+
+OBJS = \
+       choose.o \
+       concat.o \
+       dialog.o \
+       diskfull.o \
+       download.o \
+       find.o \
+       fromcwd.o \
+       geturl.o \
+       ini.o \
+       inilex.o \
+       iniparse.o \
+       install.o \
+       main.o \
+       mkdir.o \
+       mount.o \
+       msg.o \
+       net.o \
+       netio.o \
+       nio-ie5.o \
+       nio-file.o \
+       other.o \
+       res.o \
+       root.o \
+       site.o \
+       source.o \
+       state.o \
+       tar.o \
+       $E
 
-BUNDLED_FILES:=cygwin1.dll.gz
-#             mount.exe.gz cygpath.exe.gz umount.exe.gz
 .SUFFIXES:
 .NOEXPORT:
 
 .PHONY: all install clean realclean
-.PRECIOUS: $(utils_build)/cygpath.exe $(utils_build)/mount.exe $(utils_build)/umount.exe $(cygwin_build)/new-cygwin1.dll
 
 all: Makefile $(PROGS)
 
 setup$(EXEEXT): $(OBJS) $(ALL_DEP_LDLIBS)
 ifdef VERBOSE
-       $(CC) -o $@ ${filter-out $(ALL_DEP_LIBS),$^}
+       $(CC) $(MINGW_CXXFLAGS) -o $@ ${filter-out $(ALL_DEP_LIBS),$^}
 else
        @echo $(CC) ... -o $@ $(OBJS)
-       @$(CC) -o $@ ${filter-out $(ALL_DEP_LIBS),$^} $(ALL_LDFLAGS) $(ALL_LDLIBS)
+       @$(CC) $(MINGW_CXXFLAGS) -o $@ ${filter-out $(ALL_DEP_LIBS),$^} $(ALL_LDFLAGS) $(ALL_LDLIBS)
 endif
        @chmod a-x $@
 
-ctar.exe : ctar.o tar.o $(ALL_DEP_LDLIBS)
-       $(CC) -o $@ ctar.o tar.o $(ALL_LDFLAGS) $(ALL_LDLIBS)
-
-mingw_getopt.o: $(cygwin_source)/getopt.c
-       $(CC) -c -o $@ $(MINGW_CFLAGS) $^
-
 clean:
-       rm -f *.o *.rc $(PROGS) zlib/*.o zlib/*.a *.exe *.gz
+       rm -f *.o *.rc $(PROGS)
+       $(MAKE) -C zlib clean
 
 realclean: clean
        rm -f  Makefile config.cache
@@ -111,33 +133,10 @@ $(libmingw32): $(mingw_build)/Makefile
        @$(MAKE) -C $(@D) $(@F)
 
 $(ZLIB): zlib/Makefile
-       $(MAKE) -C $(@D) $(@F) CFLAGS='$(MINGW_CFLAGS)'
-
-%.exe.gz: %.exe
-       gzip -9nf $?
-
-%.exe: $(utils_build)/%.exe
-       $(OBJCOPY) --strip-unneeded $? $@
-
-$(utils_build)/%.exe: $(utils_build)/Makefile
-       @$(MAKE) -C $(utils_build) $(@F)
-
-%.dll.gz: new-%.dll
-       gzip -9nfc $? > $@
-
-%.dll: $(cygwin_build)/%.dll
-       $(OBJCOPY) --strip-unneeded $? $@
-
-$(cygwin_build)/%.dll: $(cygwin_build)/Makefile
-       @$(MAKE) -C $(@D) $(@F)
-
-cinstall.rc: $(BUNDLED_FILES) $(srcdir)/Makefile.in
-       for f in $(BUNDLED_FILES); do \
-           echo `basename $$f .gz` FILE DISCARDABLE '"'$$f'"'; \
-       done > $@
+       $(MAKE) -C $(@D) $(@F) CC="$(CC)" CFLAGS='$(MINGW_CFLAGS)'
 
 %.o: %.rc
-       $(WINDRES) -o $@ $?
+       $(WINDRES) --include-dir $(srcdir) -o $@ $?
 
 %.o: %.c
 ifdef VERBOSE
@@ -146,3 +145,18 @@ else
        @echo $(CC) -c $(CFLAGS) ... $(?F)
        @$(CC) $(MINGW_CFLAGS) -c -o $@ $?
 endif
+
+%.o: %.cc
+ifdef VERBOSE
+       $(CC) $(MINGW_CXXFLAGS) -c -o $@ $?
+else
+       @echo $(CC) -c $(CXXFLAGS) ... $(?F)
+       @$(CC) $(MINGW_CXXFLAGS) -c -o $@ $?
+endif
+
+iniparse.c iniparse.h : iniparse.y
+       bison -d -o iniparse.c $(srcdir)/iniparse.y
+
+inilex.c : inilex.l iniparse.h
+       flex -8 $(srcdir)/inilex.l
+       mv lex.yy.c inilex.c
diff --git a/README b/README
index fa76ca854722859d26e9987b68356a024bbf350c..7a13a1e434b19aac57c79f42be6df5aea97554d1 100644 (file)
--- a/README
+++ b/README
@@ -1,6 +1,32 @@
 This directory contains the source for the setup program for the cygwin
 net releases.
 
-If you have any problems the initial version of this program was
-written by Ron Parker.  Currently, March 2000, he may be reached at
-rdparker@butlermfg.com.
+
+
+To-Do list:
+
+-- mandatory --
+
+cygwin.bat
+
+install icon
+
+-- future --
+
+install.cc: read old .lst.gz file before overwriting it; remove any
+files in the old install that aren't also in the new install.
+
+add netio subclasses for direct HTTP, FTP and proxy connections
+
+change nio-ie5 to auto-load the wininet DLL
+
+choose.cc: add a dialog to let user choose what to install and
+which versions to install
+
+ini.cc: add field in setup.ini to specify whether package is installed
+by default, or not.
+
+install.cc: scan newly installed files for README files, show list to
+user, let them read them if they want.
+
+main.cc: add splash screen and copyright notice
diff --git a/choose.cc b/choose.cc
new file mode 100644 (file)
index 0000000..b5a924c
--- /dev/null
+++ b/choose.cc
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to let the user choose which packages
+   to install, and which versions of the package when more than one
+   version is provided.  The "trust" level serves as an indication as
+   to which version should be the default choice.  At the moment, all
+   we do is compare with previously installed packages to skip any
+   that are already installed (by setting the action to ACTION_SAME).
+   While the "trust" stuff is supported, it's not really implemented
+   yet.  We always prefer the "current" option.  In the future, this
+   file might have a user dialog added to let the user choose to not
+   install packages, or to install packages that aren't installed by
+   default. */
+
+#include "win32.h"
+#include <stdio.h>
+#include "dialog.h"
+#include "resource.h"
+#include "state.h"
+#include "ini.h"
+#include "concat.h"
+#include "msg.h"
+
+void
+do_choose (HINSTANCE h)
+{
+  int trust_prefs[NTRUST];
+  int i, t;
+
+  /* support this later */
+  trust_level = TRUST_CURR;
+
+  t = 0;
+  for (i=trust_level; i>=0; i--)
+    trust_prefs[t++] = i;
+  for (i=trust_level+1; i<NTRUST; i++)
+    trust_prefs[t++] = i;
+
+  for (i=0; i<npackages; i++)
+    {
+      for (t=0; t<NTRUST; t++)
+       if (package[i].info[t].install)
+         {
+           package[i].trust = t;
+           break;
+         }
+    }
+
+  if (root_dir)
+    {
+      char line[1000], pkg[1000], inst[1000], src[1000];
+      int instsz, srcsz;
+      FILE *db = fopen (concat (root_dir, "/etc/setup/installed.db", 0), "rt");
+      if (db)
+       {
+         while (fgets (line, 1000, db))
+           {
+             src[0] = 0;
+             srcsz = 0;
+             sscanf (line, "%s %s %d %s %d", pkg, inst, &instsz, src, &srcsz);
+
+             for (i=0; i<npackages; i++)
+               {
+                 if (strcmp (package[i].name, pkg) == 0)
+                   {
+                     if (strcmp (package[i].info[package[i].trust].install,
+                                 inst) == 0)
+                       package[i].action = ACTION_SAME;
+                     else
+                       package[i].action = ACTION_UPGRADE;
+                   }
+               }
+           }
+         fclose (db);
+       }
+    }
+
+  for (i=0; i<npackages; i++)
+    if (package[i].action == ACTION_UNKNOWN)
+      package[i].action = ACTION_NEW;
+
+  if (source == IDC_SOURCE_CWD)
+    next_dialog = IDD_S_INSTALL;
+  else
+    next_dialog = IDD_S_DOWNLOAD;
+}
+
diff --git a/concat.cc b/concat.cc
new file mode 100644 (file)
index 0000000..c744be8
--- /dev/null
+++ b/concat.cc
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* See concat.h.  Note that we canonicalize the result, this avoids
+   multiple slashes being interpreted as UNCs. */
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+
+char *
+concat (char *s, ...)
+{
+  int len = strlen(s);
+  char *rv, *arg;
+  va_list v;
+
+  if (!s)
+    return 0;
+
+  va_start (v, s);
+  while (1)
+    {
+      arg = va_arg(v, char *);
+      if (arg == 0)
+       break;
+      len += strlen(arg);
+    }
+  va_end(v);
+
+  rv = (char *) malloc (len+1);
+  strcpy(rv, s);
+  va_start(v, s);
+  while (1)
+  {
+    arg = va_arg(v, char *);
+    if (arg == 0)
+      break;
+    strcat(rv, arg);
+  }
+  va_end(v);
+
+  /* concat is only used for urls and files, so we can safely
+     canonicalize the results */
+  char *d;
+  for (s=rv; *s; s++)
+    if (*s == '\\')
+      *s = '/';
+  for (s=d=rv; *s; s++)
+    {
+      *d++ = *s;
+      /* special case for URLs */
+      if (*s == ':' && s[1] == '/' &&s[2] == '/')
+       {
+         *d++ = *++s;
+         *d++ = *++s;
+       }
+      else if (*s == '/')
+       while (s[1] == '/')
+         s++;
+    }
+  *d = 0;
+
+  return rv;
+}
diff --git a/concat.h b/concat.h
new file mode 100644 (file)
index 0000000..134f48c
--- /dev/null
+++ b/concat.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* Pass a null-terminated list of strings, and it concatenates them
+   into a single string.  Warning - it assumes the result is a file
+   name or URL, and will canonicalize the result accordingly
+   (i.e. replace \ with /, collapse multiple /// to a single /, etc.)  */
+
+char * concat (char *s, ...);
diff --git a/ctar.c b/ctar.c
deleted file mode 100644 (file)
index b17ff4e..0000000
--- a/ctar.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2000, Red Hat, Inc.
- *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     A copy of the GNU General Public License can be found at
- *     http://www.gnu.org/
- *
- * Written by DJ Delorie <dj@cygnus.com>
- *
- */
-
-#include <stdio.h>
-#include "tar.h"
-
-extern int _tar_verbose;
-
-int
-main (int argc, char **argv)
-{
-  char **map = (char **) malloc ((argc+2) * sizeof (char *));
-  int i, j;
-
-  while (argc > 1 && strcmp (argv[1], "-v") == 0)
-    {
-      _tar_verbose ++;
-      argc--;
-      argv++;
-    }
-
-  if (argc < 2)
-    {
-      fprintf (stderr, "Usage: ctar <file.tar.gz> [from to [from to ...]]\n");
-      exit (1);
-    }
-
-  j = 0;
-  for (i = 2; i < argc; i ++)
-    map[j++] = argv[i];
-  map[j++] = 0;
-  map[j++] = 0;
-
-  i = tar_auto (argv[1], map);
-
-  if (i == 1)
-    fprintf (stderr, "ctar: there was an error extracting %s\n", argv[1]);
-  else if (i > 1)
-    fprintf (stderr, "ctar: there were errors extracting %s\n", argv[1]);
-
-  return i;
-}
diff --git a/cygcalls.c b/cygcalls.c
deleted file mode 100644 (file)
index 03dba45..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 2000, Red Hat, Inc.
- *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     A copy of the GNU General Public License can be found at
- *     http://www.gnu.org/
- *
- * Written by DJ Delorie <dj@cygnus.com>
- *
- */
-
-#include <windows.h>
-#include <stdio.h>
-
-static HINSTANCE cygwin_dll = 0;
-static char *cygwin_dll_name = 0;
-
-static void (*cygwin_dll_init_proc) ();
-static int (*mount_proc) (const char *win32_path, const char *posix_path, unsigned flags);
-static int (*umount_proc) (const char *posix_path);
-static int (*cygwin_umount_proc) (const char *posix_path, unsigned flags);
-static FILE * (*setmntent_proc) (const char *, const char *);
-static struct mntent * (*getmntent_proc) (FILE *);
-static int (*endmntent_proc) (FILE *);
-
-static void
-one (void *fp, char *name)
-{
-  int a;
-  *(int *)fp = a = (int) GetProcAddress (cygwin_dll, name);
-  if (!a)
-    {
-      fprintf (stderr, "error: unable to find `%s' in %s\n", name, cygwin_dll_name);
-      exit (1);
-    }
-}
-
-int
-cygcall_load_dll (char *name)
-{
-  /* This forces the dll to use a private "shared" area, avoiding version conflicts */
-  SetEnvironmentVariable("CYGWIN_TESTING", "1");
-
-  cygwin_dll = LoadLibrary (name);
-  if (cygwin_dll == 0)
-    return 1;
-  cygwin_dll_name = name;
-
-  one (&cygwin_dll_init_proc, "cygwin_dll_init");
-  one (&mount_proc, "mount");
-  one (&umount_proc, "umount");
-  one (&cygwin_umount_proc, "cygwin_umount");
-  one (&setmntent_proc, "setmntent");
-  one (&getmntent_proc, "getmntent");
-  one (&endmntent_proc, "endmntent");
-
-  cygwin_dll_init_proc ();
-
-  return 0;
-}
-
-int
-cygcall_unload_dll ()
-{
-  FreeLibrary (cygwin_dll);
-}
-
-int
-mount (const char *win32_path, const char *posix_path, unsigned flags)
-{
-  return mount_proc (win32_path, posix_path, flags);
-}
-
-int
-umount (const char *posix_path)
-{
-  return umount_proc (posix_path);
-}
-
-int
-cygwin_umount (const char *posix_path, unsigned flags)
-{
-  return cygwin_umount_proc (posix_path, flags);
-}
-
-FILE *
-setmntent (const char *__filep, const char *__type)
-{
-  return setmntent_proc (__filep, __type);
-}
-
-struct mntent *
-getmntent (FILE *__filep)
-{
-  return getmntent_proc (__filep);
-}
-
-int
-endmntent (FILE *__filep)
-{
-  return endmntent_proc (__filep);
-}
-
diff --git a/dialog.cc b/dialog.cc
new file mode 100644 (file)
index 0000000..dba1775
--- /dev/null
+++ b/dialog.cc
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to provide common functionality for
+   all the dialogs in the program. */
+
+#include "win32.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "dialog.h"
+#include "msg.h"
+
+char *
+eget (HWND h, int id, char *var)
+{
+  char tmp[4000];
+  if (var)
+    {
+      free (var);
+      var = 0;
+    }
+  if (GetDlgItemText (h, id, tmp, sizeof(tmp)) > 0) 
+    {
+      var = (char *) malloc (strlen(tmp)+1);
+      strcpy (var, tmp);
+    }
+  return var;
+}
+
+int
+eget (HWND h, int id)
+{
+  BOOL s;
+  int r = GetDlgItemInt (h, id, &s, TRUE);
+  return r;
+}
+
+void
+eset (HWND h, int id, char *val)
+{
+  SetDlgItemText (h, id, val);
+}
+
+void
+eset (HWND h, int id, int val)
+{
+  SetDlgItemInt (h, id, (UINT)val, TRUE);
+}
+
+int
+rbget (HWND h, int *ids)
+{
+  int i;
+  for (i=0; ids[i]; i++)
+    if (IsDlgButtonChecked (h, ids[i]) == BST_CHECKED)
+      return ids[i];
+  return 0;
+}
+
+void
+rbset (HWND h, int *ids, int id)
+{
+  int i;
+  for (i=0; ids[i]; i++)
+    CheckDlgButton (h, ids[i], id==ids[i] ? BST_CHECKED : BST_UNCHECKED);
+}
+
+void
+fatal (char *msg)
+{
+  DWORD e = GetLastError();
+  char *buf;
+  FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+                0,
+                e,
+                0,
+                (CHAR *)&buf,
+                0,
+                0);
+  MessageBox (0, buf, msg, 0);
+  ExitProcess (0);
+}
diff --git a/dialog.h b/dialog.h
new file mode 100644 (file)
index 0000000..4d185e0
--- /dev/null
+++ b/dialog.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* global instance for the application; set in main.cc */
+extern HINSTANCE hinstance;
+
+/* used by main.cc to select the next do_* function */
+extern int next_dialog;
+
+#define D(x) void x(HINSTANCE _h)
+
+/* prototypes for all the do_* functions called by main.cc */
+D(do_source);
+D(do_root);
+D(do_net);
+D(do_site);
+D(do_other);
+D(do_choose);
+D(do_ini);
+D(do_fromcwd);
+D(do_download);
+D(do_install);
+
+#undef D
+
+/* end this dialog and select the next.  Pass 0 to exit the program */
+#define NEXT(id) EndDialog(h, 0), next_dialog = id
+
+/* Get the value of an EditText control.  Pass the previously stored
+   value and it will free the memory if needed. */
+char *eget (HWND h, int id, char *var);
+
+/* Same, but convert the value to an integer */
+
+int   eget (HWND h, int id);
+
+/* Set the EditText control to the given string or integer */
+
+void  eset (HWND h, int id, char *var);
+void  eset (HWND h, int id, int var);
+
+/* RadioButtons.  ids is a null-terminated list of IDs.  Get
+   returns the selected ID (or zero), pass an ID to set */
+
+int   rbget (HWND h, int *ids);
+void  rbset (HWND h, int *ids, int id);
+
+/* *This* version of fatal (compare with msg.h) uses GetLastError() to
+   format a suitable error message.  Similar to perror() */
+
+void fatal (char *msg);
diff --git a/diskfull.cc b/diskfull.cc
new file mode 100644 (file)
index 0000000..10bd67c
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to hide the mess needed just to figure
+   out how full a given disk is.  There is an old API that can't
+   handle disks bigger than 2G, and a new API that isn't always
+   available. */
+
+#include "win32.h"
+
+#include "diskfull.h"
+
+typedef   BOOL WINAPI (*GDFS)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER,
+                             PULARGE_INTEGER);
+
+int
+diskfull (char *path)
+{
+  WINAPI GDFS gdfs = 0;
+
+  HINSTANCE k = LoadLibrary ("KERNEL32.DLL");
+  if (k)
+    {
+      gdfs = (GDFS) GetProcAddress (k, "GetDiskFreeSpaceExA");
+
+      if (gdfs)
+       {
+         ULARGE_INTEGER avail, total, free;
+         if (gdfs (path, &avail, &total, &free))
+           {
+             int perc = avail.QuadPart * 100 / total.QuadPart;
+             return 100-perc;
+           }
+       }
+    }
+
+  char root[4];
+  if (path[1] != ':')
+    return 0;
+
+  root[0] = path[0];
+  root[1] = ':';
+  root[2] = '\\';
+  root[3] = 0;
+
+  DWORD junk, free_clusters, total_clusters;
+
+  if (GetDiskFreeSpace (root, &junk, &junk, &free_clusters, &total_clusters))
+    {
+      int perc = free_clusters * 100 / total_clusters;
+      return 100-perc;
+    }
+
+  return 0;
+}
diff --git a/diskfull.h b/diskfull.h
new file mode 100644 (file)
index 0000000..e198a74
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* returns 0..100 (percent) */
+int diskfull (char *path);
diff --git a/download.cc b/download.cc
new file mode 100644 (file)
index 0000000..a4d67fc
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to download all the files we need to
+   do the installation. */
+
+#include "win32.h"
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "resource.h"
+#include "msg.h"
+#include "ini.h"
+#include "dialog.h"
+#include "concat.h"
+#include "geturl.h"
+#include "state.h"
+#include "mkdir.h"
+
+#define pi (package[i].info[package[i].trust])
+
+void
+do_download (HINSTANCE h)
+{
+  int i;
+  if (source == IDC_SOURCE_DOWNLOAD)
+    next_dialog = 0;
+  else
+    next_dialog = IDD_S_INSTALL;
+
+  for (i=0; i<npackages; i++)
+    if (package[i].action != ACTION_SAME)
+      {
+       char *local = pi.install;
+
+       struct stat s;
+       if (stat (local, &s) >= 0)
+         if (s.st_size == pi.install_size)
+           continue;
+
+       mkdir_p (0, local);
+
+       if (get_url_to_file (concat (MIRROR_SITE, "/", pi.install, 0),
+                            concat (local, ".tmp", 0),
+                            pi.install_size))
+         {
+           package[i].action = ACTION_ERROR;
+           continue;
+         }
+       else
+         {
+           stat (concat (local, ".tmp", 0), &s);
+           if (s.st_size == pi.install_size)
+             {
+               rename (concat (local, ".tmp", 0), local);
+             }
+           else
+             {
+               note (IDS_DOWNLOAD_SHORT, local, s.st_size, pi.install_size);
+               package[i].action = ACTION_ERROR;
+             }
+         }
+      }
+
+  dismiss_url_status_dialog ();
+}
diff --git a/error.c b/error.c
deleted file mode 100644 (file)
index b7f782b..0000000
--- a/error.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2000, Red Hat, Inc.
- *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     A copy of the GNU General Public License can be found at
- *     http://www.gnu.org/
- *
- * Written by Ron Parker <parkerrd@hotmail.com>
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <windows.h>
-#include "setup.h"
-
-void
-lowmem ()
-{
-  fputs ("Insufficient memory.\n", stderr);
-  exit (1);
-}
-
-void
-winerror ()
-{
-  LPVOID msgbuf;
-  int lasterr = GetLastError ();
-
-  /* If !lasterr then assume a standard file error happened and was
-     already displayed. */
-  if (lasterr)
-    {
-      FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
-                    | FORMAT_MESSAGE_FROM_SYSTEM
-                    | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, lasterr,
-                    MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
-                    (LPTSTR) & msgbuf, 0, NULL);
-      if (msgbuf)
-       {
-         fprintf (stderr, "%s\n", (char *) msgbuf);
-         LocalFree (msgbuf);
-       }
-      else
-       fprintf (stderr, "Unexpected error #%d\n", lasterr);
-    }
-}
diff --git a/find.cc b/find.cc
new file mode 100644 (file)
index 0000000..dfaef53
--- /dev/null
+++ b/find.cc
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to doa recursive find on a given
+   directory, calling a given function for each file found. */
+
+#include "win32.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "port.h"
+
+static void (*for_each)(char *, unsigned int);
+static char dir[_MAX_PATH], *found_part;
+
+static int
+find_sub ()
+{
+  WIN32_FIND_DATA wfd;
+  HANDLE h;
+  char *end = dir + strlen (dir);
+  int rv = 0;
+
+  *end++ = '/';
+  strcpy (end, "*");
+
+  h = FindFirstFile (dir, &wfd);
+
+  if (h == INVALID_HANDLE_VALUE)
+    return 0;
+
+  do {
+    if (strcmp (wfd.cFileName, ".") == 0
+       || strcmp (wfd.cFileName, "..") == 0)
+      continue;
+
+    strcpy (end, wfd.cFileName);
+
+    if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+      find_sub ();
+    else
+      {
+       for_each (found_part, wfd.nFileSizeLow);
+       rv ++;
+      }
+
+  } while (FindNextFile (h, &wfd));
+
+  FindClose (h);
+  return rv;
+}
+
+int
+find (char *starting_dir, void (*_for_each)(char *, unsigned int))
+{
+  strcpy (dir, starting_dir);
+  for_each = _for_each;
+  found_part = dir + strlen (dir) + 1;
+
+  return find_sub ();
+}
diff --git a/find.h b/find.h
new file mode 100644 (file)
index 0000000..4c38913
--- /dev/null
+++ b/find.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The for_each function is called once for each file found in the
+   starting_dir or any subdir (recursively), passing the relative path
+   (i.e. it doesn't include "starting_dir") and the size of the file
+   (bytes).  find() returns the number of files found.  Directories
+   are scanned but not included in the "found" files. */
+
+extern int find (char *starting_dir, void (*for_each)(char *, unsigned int));
diff --git a/fromcwd.cc b/fromcwd.cc
new file mode 100644 (file)
index 0000000..fd6d09b
--- /dev/null
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to handle the case where we're
+   installing from files that already exist in the current directory.
+   If a setup.ini file is present, we set the mirror site to "." and
+   pretend we're installing from the `internet' ;-) else we have to
+   find all the .tar.gz files, deduce their versions, and try to
+   compare versions in the case where the current directory contains
+   multiple versions of any given package.  We do *not* try to compare
+   versions with already installed packages; we always choose a
+   package in the current directory over one that's already installed
+   (otherwise, why would you have asked to install it?).  Note
+   that we search recursively. */
+
+#include "win32.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <io.h>
+#include <unistd.h>
+#include <ctype.h>
+
+#include "ini.h"
+#include "resource.h"
+#include "concat.h"
+#include "state.h"
+#include "dialog.h"
+#include "msg.h"
+#include "find.h"
+
+#include "port.h"
+
+static int
+is_test_version (char *v)
+{
+  int i;
+  for (i=0; v[i] && isdigit (v[i]); i++) ;
+  return (i >= 6) ? 1 : 0;
+}
+
+static char *canonicalize_version (char *v)
+{
+  static char nv[100];
+  char *np=nv, *dp, *ov = v;
+  int i;
+
+  while (*v)
+    {
+      if (isdigit (*v))
+       {
+         for (dp=v; *dp && isdigit (*dp); dp++) ;
+         for (i=dp-v; i<12; i++)
+           *np++ = '0';
+         while (v < dp)
+           *np++ = *v++;
+       }
+      else
+       *np++ = *v++;
+    }
+  *np++ = 0;
+  return nv;
+}
+
+static void
+found_file (char *path, unsigned int fsize)
+{
+  char base[_MAX_PATH], *ver;
+
+  int l = strlen (path);
+
+  if (strcmp (path + l - 7, ".tar.gz") != 0)
+    return;
+  if (strstr (path, "-src."))
+    return;
+  if (strstr (path, "-patch."))
+    return;
+
+  char *sl = strrchr (path, '/');
+  if (sl)
+    sl ++;
+  else
+    sl = path;
+  strcpy (base, sl);
+  base[strlen(base)-7] = 0; /* remove .tar.gz */
+  for (ver=base; *ver; ver++)
+    if ((*ver == '-' || *ver == '_') && isdigit (ver[1]))
+      {
+       *ver++ = 0;
+       break;
+      }
+
+  Package *p = 0;
+  int i;
+
+  for (i=0; i<npackages; i++)
+    if (strcmp (package[i].name, base) == 0)
+      {
+       p = package + i;
+       break;
+      }
+  if (p == 0)
+      p = new_package (strdup (base));
+
+  char *nv = canonicalize_version (ver);
+  int trust = is_test_version (ver) ? TRUST_TEST : TRUST_CURR;
+  if (!*ver)
+    trust = TRUST_PREV;
+
+  /* See if this version is older than what we have */
+  if (p->info[trust].version)
+    if (strcmp (p->info[trust].version, nv) > 0)
+      return;
+
+  p->info[trust].version = _strdup (nv);
+  p->info[trust].install = _strdup (path);
+  p->info[trust].install_size = fsize;
+}
+
+void
+do_fromcwd (HINSTANCE h)
+{
+  if (_access ("./setup.ini", 0) == 0)
+    {
+      mirror_site = ".";
+      next_dialog = IDD_S_LOAD_INI;
+      return;
+    }
+
+  next_dialog = IDD_S_CHOOSE;
+
+  find (".", found_file);
+
+  return;
+}
diff --git a/geturl.cc b/geturl.cc
new file mode 100644 (file)
index 0000000..6faa8f3
--- /dev/null
+++ b/geturl.cc
@@ -0,0 +1,251 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to act as a pretty interface to
+   netio.cc.  We add a progress dialog and some convenience functions
+   (like collect to string or file */
+
+#include "win32.h"
+#include "commctrl.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include "dialog.h"
+#include "geturl.h"
+#include "resource.h"
+#include "netio.h"
+#include "msg.h"
+
+static int is_showing = 0;
+static HWND gw_dialog = 0;
+static HWND gw_url = 0;
+static HWND gw_rate = 0;
+static HWND gw_progress = 0;
+static HANDLE init_event;
+static int max_bytes = 0;
+
+static BOOL
+dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
+{
+  switch (id)
+    {
+    case IDCANCEL:
+      ExitProcess(0);
+    }
+}
+
+static BOOL CALLBACK
+dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
+{
+  int i, j;
+  HWND listbox;
+  switch (message)
+    {
+    case WM_INITDIALOG:
+      gw_dialog = h;
+      gw_url = GetDlgItem (h, IDC_DLS_URL);
+      gw_rate = GetDlgItem (h, IDC_DLS_RATE);
+      gw_progress = GetDlgItem (h, IDC_DLS_PROGRESS);
+      SetEvent (init_event);
+      return FALSE;
+    case WM_COMMAND:
+      return HANDLE_WM_COMMAND(h, wParam, lParam, dialog_cmd);
+    }
+  return FALSE;
+}
+
+static WINAPI DWORD
+dialog (void *)
+{
+  int rv = 0;
+  MSG m;
+  HANDLE gw_dialog = CreateDialog (hinstance, MAKEINTRESOURCE (IDD_DLSTATUS),
+                                  0, dialog_proc);
+  ShowWindow (gw_dialog, SW_SHOWNORMAL);
+  UpdateWindow (gw_dialog);
+  while (GetMessage (&m, 0, 0, 0) > 0) {
+    TranslateMessage (&m);
+    DispatchMessage (&m);
+  }
+}
+
+static DWORD start_tics;
+
+static void
+init_dialog (char *url, int length)
+{
+  if (gw_dialog == 0)
+    {
+      DWORD tid;
+      HANDLE thread;
+      init_event = CreateEvent (0, 0, 0, 0);
+      thread = CreateThread (0, 0, dialog, 0, 0, &tid);
+      WaitForSingleObject (init_event, 1000);
+      CloseHandle (init_event);
+      SendMessage (gw_progress, PBM_SETRANGE, 0, MAKELPARAM (0, 100));
+      is_showing = 0;
+    }
+  char *sl=url, *cp;
+  for (cp=url; *cp; cp++)
+    if (*cp == '/' || *cp == '\\' || *cp == ':')
+      sl = cp+1;
+  max_bytes = length;
+  SetWindowText (gw_url, sl);
+  SetWindowText (gw_rate, "Connecting...");
+  SendMessage (gw_progress, PBM_SETPOS, (WPARAM) 0, 0);
+  ShowWindow (gw_progress, (length > 0) ? SW_SHOW : SW_HIDE);
+  ShowWindow (gw_dialog, SW_SHOWNORMAL);
+  if (!is_showing)
+    {
+      SetForegroundWindow (gw_dialog);
+      is_showing = 1;
+    }
+  start_tics = GetTickCount();
+}
+
+
+static void
+progress (int bytes)
+{
+  static char buf[100];
+  int kbps;
+  static int last_tics = 0;
+  DWORD tics = GetTickCount();
+  if (tics == start_tics) // to prevent division by zero
+    return;
+  if (tics < last_tics + 200) // to prevent flickering updates
+    return;
+  last_tics = tics;
+
+  kbps = bytes / (tics - start_tics);
+  ShowWindow (gw_progress, (max_bytes > 0) ? SW_SHOW : SW_HIDE);
+  if (max_bytes)
+    {
+      int perc = bytes * 100 / max_bytes;
+      SendMessage (gw_progress, PBM_SETPOS, (WPARAM) perc, 0);
+      sprintf(buf, "%3d %%  (%dk/%dk)  %d kb/s\n",
+             perc, bytes/1000, max_bytes/1000, kbps);
+    }
+  else
+    sprintf(buf, "%d  %d kb/s\n", bytes, kbps);
+
+  SetWindowText (gw_rate, buf);
+}
+
+struct GUBuf {
+  GUBuf *next;
+  int count;
+  char buf[2000];
+};
+
+char *
+get_url_to_string (char *_url)
+{
+  init_dialog (_url, 0);
+  NetIO *n = NetIO::open (_url);
+  if (!n || !n->ok ())
+    {
+      delete n;
+      return 0;
+    }
+
+  if (n->file_size)
+    max_bytes = n->file_size;
+
+  GUBuf *bufs = 0;
+  GUBuf **nextp = &bufs;
+  int total_bytes = 1; /* for the NUL */
+  progress (0);
+  while (1)
+    {
+      GUBuf *b = new GUBuf;
+      *nextp = b;
+      b->next = 0;
+      nextp = &(b->next);
+
+      b->count = n->read (b->buf, sizeof (b->buf));
+      if (b->count <= 0)
+       break;
+      total_bytes += b->count;
+      progress (total_bytes);
+    }
+
+  char *rv = (char *) malloc (total_bytes);
+  char *rvp = rv;
+  while (bufs && bufs->count > 0)
+    {
+      GUBuf *tmp = bufs->next;
+      memcpy (rvp, bufs->buf, bufs->count);
+      rvp += bufs->count;
+      delete bufs;
+      bufs = tmp;
+    }
+  *rvp = 0;
+  return rv;
+}
+
+int
+get_url_to_file (char *_url, char *_filename, int expected_length)
+{
+  init_dialog (_url, expected_length);
+
+  remove (_filename); /* but ignore errors */
+
+  NetIO *n = NetIO::open (_url);
+  if (!n || !n->ok ())
+    {
+      delete n;
+      return 1;
+    }
+
+  FILE *f = fopen(_filename, "wb");
+  if (!f)
+    {
+      char *err = strerror (errno);
+      if (!err)
+       err = "(unknown error)";
+      fatal (IDS_ERR_OPEN_WRITE, _filename, err);
+    }
+
+  if (n->file_size)
+    max_bytes = n->file_size;
+
+  int total_bytes = 0;
+  progress (0);
+  while (1)
+    {
+      char buf[2048];
+      int count;
+      count = n->read (buf, sizeof (buf));
+      if (count <= 0)
+       break;
+      fwrite (buf, 1, count, f);
+      total_bytes += count;
+      progress (total_bytes);
+    }
+
+  fclose (f);
+
+  return 0;
+}
+
+void
+dismiss_url_status_dialog ()
+{
+  ShowWindow (gw_dialog, SW_HIDE);
+  is_showing = 0;
+}
diff --git a/geturl.h b/geturl.h
new file mode 100644 (file)
index 0000000..32a7b3d
--- /dev/null
+++ b/geturl.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* Download files from the Internet.  These pop up a progress dialog;
+   don't forget to dismiss it when you're done downloading for a while */
+
+char  *get_url_to_string (char *_url);
+int    get_url_to_file (char *_url, char *_filename, int expected_size);
+void   dismiss_url_status_dialog ();
diff --git a/gzip.exe.gz b/gzip.exe.gz
deleted file mode 100755 (executable)
index 1f766ca..0000000
Binary files a/gzip.exe.gz and /dev/null differ
diff --git a/ini.cc b/ini.cc
new file mode 100644 (file)
index 0000000..3cfc6dc
--- /dev/null
+++ b/ini.cc
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to get and parse the setup.ini file
+   from the mirror site.  A few support routines for the bison and
+   flex parsers are provided also.  We check to see if this setup.ini
+   is older than the one we used last time, and if so, warn the user. */
+
+#include "win32.h"
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "ini.h"
+#include "resource.h"
+#include "concat.h"
+#include "state.h"
+#include "geturl.h"
+#include "dialog.h"
+#include "msg.h"
+#include "mkdir.h"
+
+unsigned int setup_timestamp = 0;
+
+extern "C" int yyparse ();
+/* extern int yydebug; */
+
+void
+do_ini (HINSTANCE h)
+{
+  char *ini_file = get_url_to_string (concat (MIRROR_SITE, "/setup.ini", 0));
+
+  if (!ini_file)
+    fatal (IDS_SETUPINI_MISSING, MIRROR_SITE);
+
+  ini_init (ini_file);
+
+  setup_timestamp = 0;
+  /*  yydebug = 0;*/
+  yyparse();
+
+  mkdir_p (1, concat (root_dir, "/etc/setup", 0));
+
+  unsigned int old_timestamp = 0;
+  FILE *ots = fopen (concat (root_dir, "/etc/setup/timestamp", 0), "rt");
+  if (ots)
+    {
+      fscanf (ots, "%u", &old_timestamp);
+      fclose (ots);
+      if (old_timestamp && setup_timestamp
+         && (old_timestamp > setup_timestamp))
+       {
+         int yn = yesno (IDS_OLD_SETUPINI);
+         if (yn == IDNO)
+           ExitProcess (0);
+       }
+    }
+  if (setup_timestamp)
+    {
+      FILE *nts = fopen (concat (root_dir, "/etc/setup/timestamp", 0), "wt");
+      if (nts)
+       {
+         fprintf (nts, "%u", setup_timestamp);
+         fclose (nts);
+       }
+    }
+
+  next_dialog = IDD_S_CHOOSE;
+}
+
+extern "C" int yyerror (char *s)
+{
+  MessageBox (0, s, "Parse Error", 0);
+  ExitProcess (0);
+}
+
+extern "C" int fprintf(FILE *f, const char *s, ...);
+
+int
+fprintf(FILE *f, const char *fmt, ...)
+{
+  char buf[1000];
+  int rv;
+  va_list args;
+  va_start (args, fmt);
+  if (f == stderr)
+    {
+      rv = vsprintf (buf, fmt, args);
+      MessageBox (0, buf, "Cygwin Setup", 0);
+    }
+  else
+    {
+      rv = vfprintf (f, fmt, args);
+    }
+  return rv;
+}
diff --git a/ini.h b/ini.h
new file mode 100644 (file)
index 0000000..25c8ee4
--- /dev/null
+++ b/ini.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* When setup.ini is parsed, the information is stored according to
+   the declarations here.  ini.cc (via inilex and iniparse)
+   initializes these structures.  choose.cc sets the action and trust
+   fields.  download.cc downloads any needed files for selected
+   packages (the chosen "install" field).  install.cc installs
+   selected packages. */
+
+#define YYSTYPE char *
+
+/* lowest number must be most trusted, highest least trusted */
+#define TRUST_PREV     0
+#define TRUST_CURR     1
+#define TRUST_TEST     2
+#define NTRUST 3
+
+#define ACTION_UNKNOWN 0
+#define ACTION_SAME    1
+#define ACTION_NEW     2
+#define ACTION_UPGRADE 3
+#define ACTION_ERROR   4
+
+typedef struct {
+  char *name;  /* package name, like "cygwin" */
+  char *sdesc; /* short description (replaces "name" if provided) */
+  char *ldesc; /* long description (multi-line) */
+  int action;  /* ACTION_* - only NEW and UPGRADE get installed */
+  int trust;   /* TRUST_* (selects among info[] below) */
+  struct {
+    char *version;     /* holds canonical version for fromcwd.cc */
+    char *install;     /* file name to install */
+    int install_size;  /* in bytes */
+    char *source;      /* sources for installed binaries */
+    int source_size;   /* in bytes */
+  } info[NTRUST];
+} Package;
+
+extern Package *package;
+extern int npackages;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+Package *new_package (char *name);
+void   ini_init (char *string);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/inilex.l b/inilex.l
new file mode 100644 (file)
index 0000000..88a5cf2
--- /dev/null
+++ b/inilex.l
@@ -0,0 +1,90 @@
+%{
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* tokenize the setup.ini files.  We parse a string which we've
+   previously downloaded.  The program must call ini_init() to specify
+   that string. */
+
+#include <string.h>
+
+#include "ini.h"
+#include "iniparse.h"
+
+#define YY_INPUT(buf,result,max_size) { result = ini_getchar(buf, max_size); }
+
+static int ini_getchar(char *buf, int max_size);
+
+%}
+
+%option noyywrap
+
+%%
+
+\"[^"]*\"              { yylval = strdup (yytext+1);
+                         yylval[strlen (yylval)-1] = 0;
+                         return STRING; }
+
+"setup-timestamp:"     return SETUP_TIMESTAMP;
+"version:"             return VERSION;
+"install:"             return INSTALL;
+"source:"              return SOURCE;
+"sdesc:"               return SDESC;
+"ldesc:"               return LDESC;
+
+"[curr]"               return T_CURR;
+"[test]"               return T_TEST;
+"[prev]"               return T_PREV;
+
+[a-zA-Z0-9_./-]+       { yylval = strdup (yytext);
+                         return STRING; }
+
+[ \t\r]+
+
+\n                     { return yytext[0]; }
+.                      { return yytext[0]; }
+
+%%
+
+static char *input_string = 0;
+static char *end_input_string;
+
+void
+ini_init(char *string)
+{
+  input_string = string;
+  end_input_string = input_string + strlen(input_string);
+}
+
+static int
+ini_getchar(char *buf, int max_size)
+{
+  if (input_string)
+    {
+      int avail = end_input_string - input_string;
+      if (avail == 0)
+       {
+         input_string = end_input_string = 0;
+         return 0;
+       }
+      if (avail > max_size)
+       avail = max_size;
+      memcpy(buf, input_string, avail);
+      input_string += avail;
+      return avail;
+    }
+  else
+    return 0;
+}
diff --git a/iniparse.y b/iniparse.y
new file mode 100644 (file)
index 0000000..b49ac72
--- /dev/null
@@ -0,0 +1,107 @@
+%{
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* Parse the setup.ini files.  inilex.l provides the tokens for this. */
+
+#include <stdlib.h>
+
+#include "ini.h"
+#include "iniparse.h"
+
+static Package *cp;
+static int trust;
+extern unsigned int setup_timestamp;
+
+#define cpt (cp->info+trust)
+
+%}
+
+%token STRING
+%token SETUP_TIMESTAMP VERSION INSTALL SOURCE SDESC LDESC
+%token T_PREV T_CURR T_TEST
+
+%%
+
+whole_file
+ : setup_headers packages
+ ;
+
+setup_headers
+ : setup_header setup_headers
+ | /* empty */
+ ;
+
+setup_header
+ : SETUP_TIMESTAMP STRING '\n' { setup_timestamp = strtoul ($2, 0, 0); }
+ ;
+
+packages
+ : package packages
+ | /* empty */
+ ;
+
+package
+ : '@' STRING '\n'             { new_package($2); }
+   lines
+ | '\n'
+ ;
+
+lines
+ : simple_line '\n' lines
+ | simple_line
+ ;
+
+simple_line
+ : VERSION STRING              { cpt->version = $2; }
+ | SDESC STRING                        { cp->sdesc = $2; }
+ | LDESC STRING                        { cp->ldesc = $2; }
+ | INSTALL STRING STRING       { cpt->install = $2;
+                                 cpt->install_size = atoi($3); }
+ | SOURCE STRING STRING                { cpt->source = $2;
+                                 cpt->source_size = atoi($3); }
+ | T_PREV                      { trust = TRUST_PREV; }
+ | T_CURR                      { trust = TRUST_CURR; }
+ | T_TEST                      { trust = TRUST_TEST; }
+ | /* empty */
+ ;
+
+%%
+
+Package *package = 0;
+int npackages = 0;
+static int maxpackages = 0;
+
+Package *
+new_package (char *name)
+{
+  if (npackages >= maxpackages)
+    {
+      maxpackages += 10;
+      if (package)
+       package = (Package *) realloc (package, maxpackages * sizeof (Package));
+      else
+       package = (Package *) malloc (maxpackages * sizeof (Package));
+    }
+  cp = package + npackages;
+  npackages ++;
+
+  memset (cp, 0, sizeof (Package));
+  cp->name = name;
+
+  trust = TRUST_CURR;
+
+  return cp;
+}
diff --git a/install.cc b/install.cc
new file mode 100644 (file)
index 0000000..f667444
--- /dev/null
@@ -0,0 +1,313 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to intall all the packages selected in
+   the install list (in ini.h).  Note that we use a separate thread to
+   maintain the progress dialog, so we avoid the complexity of
+   handling two tasks in one thread.  We also create or update all the
+   files in /etc/setup/* and create the mount points. */
+
+#include "win32.h"
+#include "commctrl.h"
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include "zlib/zlib.h"
+
+#include "resource.h"
+#include "ini.h"
+#include "dialog.h"
+#include "concat.h"
+#include "geturl.h"
+#include "mkdir.h"
+#include "state.h"
+#include "tar.h"
+#include "diskfull.h"
+#include "msg.h"
+#include "mount.h"
+
+static HWND ins_dialog = 0;
+static HWND ins_pkgname = 0;
+static HWND ins_filename = 0;
+static HWND ins_pprogress = 0;
+static HWND ins_iprogress = 0;
+static HWND ins_diskfull = 0;
+static HANDLE init_event;
+
+static int total_bytes = 0;
+static int total_bytes_sofar = 0;
+static int package_bytes = 0;
+
+static BOOL
+dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
+{
+  switch (id)
+    {
+    case IDCANCEL:
+      ExitProcess(0);
+    }
+}
+
+static BOOL CALLBACK
+dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
+{
+  int i, j;
+  HWND listbox;
+  switch (message)
+    {
+    case WM_INITDIALOG:
+      ins_dialog = h;
+      ins_pkgname = GetDlgItem (h, IDC_INS_PKG);
+      ins_filename = GetDlgItem (h, IDC_INS_FILE);
+      ins_pprogress = GetDlgItem (h, IDC_INS_PPROGRESS);
+      ins_iprogress = GetDlgItem (h, IDC_INS_IPROGRESS);
+      ins_diskfull = GetDlgItem (h, IDC_INS_DISKFULL);
+      SetEvent (init_event);
+      return FALSE;
+    case WM_COMMAND:
+      return HANDLE_WM_COMMAND(h, wParam, lParam, dialog_cmd);
+    }
+  return FALSE;
+}
+
+static WINAPI DWORD
+dialog (void *)
+{
+  int rv = 0;
+  MSG m;
+  HANDLE ins_dialog = CreateDialog (hinstance, MAKEINTRESOURCE (IDD_INSTATUS),
+                                  0, dialog_proc);
+  if (ins_dialog == 0)
+    fatal ("create dialog");
+  ShowWindow (ins_dialog, SW_SHOWNORMAL);
+  UpdateWindow (ins_dialog);
+  while (GetMessage (&m, 0, 0, 0) > 0) {
+    TranslateMessage (&m);
+    DispatchMessage (&m);
+  }
+}
+
+static DWORD start_tics;
+
+static void
+init_dialog ()
+{
+  if (ins_dialog == 0)
+    {
+      DWORD tid;
+      HANDLE thread;
+      init_event = CreateEvent (0, 0, 0, 0);
+      thread = CreateThread (0, 0, dialog, 0, 0, &tid);
+      WaitForSingleObject (init_event, 10000);
+      CloseHandle (init_event);
+      SendMessage (ins_pprogress, PBM_SETRANGE, 0, MAKELPARAM (0, 100));
+      SendMessage (ins_iprogress, PBM_SETRANGE, 0, MAKELPARAM (0, 100));
+      SendMessage (ins_diskfull, PBM_SETRANGE, 0, MAKELPARAM (0, 100));
+    }
+
+  SetWindowText (ins_pkgname, "");
+  SetWindowText (ins_filename, "");
+  SendMessage (ins_pprogress, PBM_SETPOS, (WPARAM) 0, 0);
+  SendMessage (ins_iprogress, PBM_SETPOS, (WPARAM) 0, 0);
+  SendMessage (ins_diskfull, PBM_SETPOS, (WPARAM) 0, 0);
+  ShowWindow (ins_dialog, SW_SHOWNORMAL);
+  SetForegroundWindow (ins_dialog);
+}
+
+static void
+progress (int bytes)
+{
+  int perc;
+
+  if (package_bytes > 0)
+    {
+      perc = bytes * 100 / package_bytes;
+      SendMessage (ins_pprogress, PBM_SETPOS, (WPARAM) perc, 0);
+    }
+
+  if (total_bytes > 0)
+    {
+      perc = (total_bytes_sofar + bytes) * 100 / total_bytes;
+      SendMessage (ins_iprogress, PBM_SETPOS, (WPARAM) perc, 0);
+    }
+
+  int df = diskfull (root_dir);
+  SendMessage (ins_diskfull, PBM_SETPOS, (WPARAM) df, 0);
+}
+
+static void
+badrename (char *o, char *n)
+{
+  char buf[1000];
+  char *err = strerror (errno);
+  if (!err)
+    err = "(unknown error)";
+  note (IDS_ERR_RENAME, o, n, err);
+}
+
+#define pi (package[i].info[package[i].trust])
+
+#define LOOP_PACKAGES \
+  for (i=0; i<npackages; i++) \
+    if (package[i].action == ACTION_NEW \
+       || package[i].action == ACTION_UPGRADE)
+
+void
+do_install (HINSTANCE h)
+{
+  int i, num_installs = 0;
+  next_dialog = 0;
+
+  dismiss_url_status_dialog ();
+
+  init_dialog ();
+
+  total_bytes = 0;
+  total_bytes_sofar = 0;
+
+  LOOP_PACKAGES
+    {
+      total_bytes += pi.install_size;
+    }
+
+  LOOP_PACKAGES
+    {
+      char *local = pi.install, *cp, *fn, *base;
+
+      base = local;
+      for (cp=pi.install; *cp; cp++)
+       if (*cp == '/' || *cp == '\\' || *cp == ':')
+         base = cp+1;
+      SetWindowText (ins_pkgname, base);
+
+      gzFile lst = gzopen (concat (root_dir, "/etc/setup/",
+                                  package[i].name, ".lst.gz", 0),
+                          "wb9");
+
+      package_bytes = pi.install_size;
+
+      tar_open (local);
+      while (fn = tar_next_file ())
+       {
+         char *dest_file;
+
+         while (*fn == '/' || *fn == '\\')
+           fn++;
+
+         if (lst)
+           gzprintf(lst, "%s\n", fn);
+
+         if (strncmp (fn, "usr/bin/", 8) == 0)
+           dest_file = concat(root_dir, "/bin/", fn+8, 0);
+         else if (strncmp (fn, "usr/lib/", 8) == 0)
+           dest_file = concat(root_dir, "/lib/", fn+8, 0);
+         else
+           dest_file = concat(root_dir, "/", fn, 0);
+
+         SetWindowText (ins_filename, dest_file);
+         tar_read_file (dest_file);
+
+         progress (tar_ftell ());
+         num_installs ++;
+       }
+      tar_close ();
+
+      total_bytes_sofar += pi.install_size;
+      progress (0);
+
+      if (lst)
+       gzclose (lst);
+    }
+
+  ShowWindow (ins_dialog, SW_HIDE);
+
+  if (num_installs == 0)
+    {
+      note (IDS_NOTHING_INSTALLED);
+      return;
+    }
+
+  char *odbn = concat (root_dir, "/etc/setup/installed.db", 0);
+  char *ndbn = concat (root_dir, "/etc/setup/installed.db.new", 0);
+  char *sdbn = concat (root_dir, "/etc/setup/installed.db.old", 0);
+
+  mkdir_p (0, ndbn);
+
+  FILE *odb = fopen (odbn, "rt");
+  FILE *ndb = fopen (ndbn, "wb");
+
+  if (!ndb)
+    {
+      char *err = strerror (errno);
+      if (!err)
+       err = "(unknown error)";
+      fatal (IDS_ERR_OPEN_WRITE, ndb, err);
+    }
+
+  if (odb)
+    {
+      char line[1000], pkg[1000];
+      int printit;
+      while (fgets (line, 1000, odb))
+       {
+         printit = 1;
+         sscanf(line, "%s", pkg);
+         LOOP_PACKAGES
+           {
+             if (strcmp (pkg, package[i].name) == 0)
+               {
+                 printit = 0;
+                 break;
+               }
+           }
+         if (printit)
+           fputs (line, ndb);
+       }
+      
+    }
+  LOOP_PACKAGES
+    {
+      fprintf (ndb, "%s %s %d\n", package[i].name,
+              pi.install, pi.install_size);
+    }
+
+  if (odb)
+    fclose (odb);
+  fclose (ndb);
+
+  remove (sdbn);
+  if (odb && rename (odbn, sdbn))
+    badrename (odbn, sdbn);
+
+  remove (odbn);
+  if (rename (ndbn, odbn))
+    badrename (ndbn, odbn);
+
+  remove_mount ("/usr");
+  remove_mount ("/var");
+  remove_mount ("/lib");
+  remove_mount ("/bin");
+  remove_mount ("/etc");
+
+  int istext = (root_text == IDC_ROOT_TEXT) ? 1 : 0;
+
+  create_mount ("/", root_dir, istext);
+  create_mount ("/usr/bin", concat (root_dir, "/bin", 0), istext);
+  create_mount ("/usr/lib", concat (root_dir, "/lib", 0), istext);
+
+  note (IDS_INSTALL_COMPLETE);
+}
diff --git a/main.cc b/main.cc
new file mode 100644 (file)
index 0000000..da14dc3
--- /dev/null
+++ b/main.cc
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* OK, here's how this works.  Each of the steps needed for install -
+   dialogs, downloads, installs - are in their own files and have some
+   "do_*" function (prototype in dialog.h) and a resource id (IDD_* or
+   IDD_S_* in resource.h) for that step.  Each step is responsible for
+   selecting the next step!  See the NEXT macro in dialog.h.  Note
+   that the IDD_S_* ids are fake; those are for steps that don't
+   really have a controlling dialog (some have progress dialogs, but
+   those don't count, although they could).  Replace the IDD_S_* with
+   IDD_* if you create a real dialog for those steps. */
+
+#include "win32.h"
+
+#include <stdio.h>
+#include "resource.h"
+#include "dialog.h"
+#include "state.h"
+#include "msg.h"
+#include "netio.h"
+#include "find.h"
+#include "mount.h"
+
+void netio_test (char *);
+
+int next_dialog;
+
+HINSTANCE hinstance;
+
+int WINAPI
+WinMain(HINSTANCE h,
+       HINSTANCE hPrevInstance,
+       LPSTR command_line,
+       int cmd_show)
+{
+  hinstance = h;
+
+  next_dialog = IDD_SOURCE;
+
+  while (next_dialog)
+    {
+      switch (next_dialog)
+       {
+       case IDD_SOURCE:        do_source(h);   break;
+       case IDD_ROOT:          do_root(h);     break;
+       case IDD_NET:           do_net (h);     break;
+       case IDD_SITE:          do_site(h);     break;
+       case IDD_OTHER_URL:     do_other(h);    break;
+       case IDD_S_LOAD_INI:    do_ini(h);      break;
+       case IDD_S_FROM_CWD:    do_fromcwd(h);  break;
+       case IDD_S_CHOOSE:      do_choose(h);   break;
+       case IDD_S_DOWNLOAD:    do_download(h); break;
+       case IDD_S_INSTALL:     do_install(h);  break;
+
+       default:
+         next_dialog = 0;
+         break;
+       }
+    }
+
+  return 0;
+}
diff --git a/memory.c b/memory.c
deleted file mode 100644 (file)
index e4c8e64..0000000
--- a/memory.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2000, Red Hat, Inc.
- *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     A copy of the GNU General Public License can be found at
- *     http://www.gnu.org/
- *
- * Written by Ron Parker <parkerrd@hotmail.com>
- *
- */
-
-#include <malloc.h>
-#include <string.h>
-#include <windows.h>
-#include "setup.h"
-
-void *
-xmalloc (size_t size)
-{
-  void *mem = malloc (size);
-
-  if (!mem)
-    lowmem ();
-  return mem;
-}
-
-void *
-xrealloc (void *orig, size_t newsize)
-{
-  void *mem = realloc (orig, newsize);
-
-  if (!mem)
-    lowmem ();
-  return mem;
-}
-
-char *
-xstrdup (const char *arg)
-{
-  char *str = strdup (arg);
-
-  if (!str)
-    lowmem ();
-  return str;
-}
diff --git a/mkdir.cc b/mkdir.cc
new file mode 100644 (file)
index 0000000..42d3602
--- /dev/null
+++ b/mkdir.cc
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* see mkdir.h */
+
+#include "win32.h"
+
+#include <stdio.h>
+
+#include "mkdir.h"
+
+int
+mkdir_p (int isadir, char *path)
+{
+  char saved_char, *slash = 0;
+  char *c;
+  DWORD d, gse;
+
+  d = GetFileAttributes (path);
+  if (d != 0xffffffff && d & FILE_ATTRIBUTE_DIRECTORY)
+    return 0;
+
+  if (isadir)
+    {
+      if (CreateDirectory (path, 0))
+       return 0;
+      gse = GetLastError ();
+      if (gse != ERROR_PATH_NOT_FOUND)
+       {
+         if (gse == ERROR_ALREADY_EXISTS)
+           {
+             if (DeleteFileA (path))
+               {
+                 fprintf(stderr, "warning: deleting \"%s\" so I can make a directory there\n",
+                         path);
+                 return mkdir_p (isadir, path);
+               }
+           }
+         return 1;
+       }
+    }
+
+  for (c=path; *c; c++)
+    {
+      if (*c == ':')
+       slash = 0;
+      if (*c == '/' || *c == '\\')
+       slash = c;
+    }
+
+  if (!slash)
+    return 0;
+
+  saved_char = *slash;
+  *slash = 0;
+  if (mkdir_p (1, path))
+    {
+      *slash = saved_char;
+      return 1;
+    }
+  *slash = saved_char;
+
+  if (!isadir)
+    return 0;
+
+  return mkdir_p (isadir, path);
+}
similarity index 53%
rename from strarry.h
rename to mkdir.h
index 0397f361007e9c15184a912e2044e529a5704942..151edc0b7316d1e5c912db50f6b9801232d60530 100644 (file)
--- a/strarry.h
+++ b/mkdir.h
@@ -9,20 +9,13 @@
  *     A copy of the GNU General Public License can be found at
  *     http://www.gnu.org/
  *
- * Written by Ron Parker <parkerrd@hotmail.com>
+ * Written by DJ Delorie <dj@cygnus.com>
  *
  */
 
-/* strarry.h: strarry struct */
-
-#include <stddef.h>
-typedef struct strarry
-{
-  char **array;
-  size_t count;
-  size_t index;
-} SA;
-void sa_init (SA *);           /* Initialize the struct. */
-void sa_add (SA *, const char *);      /* Add a string to the array. */
-void sa_cleanup (SA *);        /* Deallocate all of the memory. */
+/* Create a directory, and any needed parent directories.  If "isadir"
+   is non-zero, "path" is the name of a directory.  If "isadir" is
+   zero, "path" is the name of a *file* that we need a directory
+   for. */
 
+extern int mkdir_p (int isadir, char *path);
diff --git a/mount.cc b/mount.cc
new file mode 100644 (file)
index 0000000..5a0f8ac
--- /dev/null
+++ b/mount.cc
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to hide all the details about accessing
+   Cygwin's mount table.  If the format or location of the mount table
+   changes, this is the file to change to match it. */
+
+#include "win32.h"
+
+#include <stdio.h>
+#include "../cygwin/include/cygwin/version.h"
+#include "../cygwin/include/sys/mount.h"
+
+#include "mount.h"
+#include "msg.h"
+#include "resource.h"
+#include "dialog.h"
+
+
+static char *
+find2 (HKEY rkey, int *istext)
+{
+  char buf[1000];
+  char *retval = 0;
+  HKEY key;
+  DWORD retvallen = 0;
+  DWORD flags = 0;
+  DWORD type;
+
+  sprintf (buf, "Software\\%s\\%s\\%s\\/",
+          CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
+          CYGWIN_INFO_CYGWIN_REGISTRY_NAME,
+          CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME);
+
+  if (RegOpenKeyEx (rkey, buf, 0, KEY_READ, &key) != ERROR_SUCCESS)
+    return 0;
+
+  if (RegQueryValueEx (key, "native", 0, &type, 0, &retvallen)
+      == ERROR_SUCCESS)
+    {
+      retval = new char[retvallen+1];
+      if (RegQueryValueEx (key, "native", 0, &type, (BYTE *)retval, &retvallen)
+         != ERROR_SUCCESS)
+       {
+         delete retval;
+         retval = 0;
+       }
+    }
+
+  retvallen = sizeof (flags);
+  RegQueryValueEx (key, "flags", 0, &type, (BYTE *)&flags, &retvallen);
+
+  RegCloseKey (key);
+
+  if (retval)
+    *istext = (flags & MOUNT_BINARY) ? 0 : 1;
+  return retval;
+}
+
+char *
+find_root_mount (int *istext)
+{
+  char *rv;
+  if (rv = find2 (HKEY_CURRENT_USER, istext))
+    return rv;
+  return find2 (HKEY_LOCAL_MACHINE, istext);
+}
+
+void
+create_mount (char *posix, char *win32, int istext)
+{
+  char buf[1000];
+  char *retval = 0;
+  HKEY key;
+  DWORD retvallen = 0, disposition;
+  DWORD flags;
+
+  remove_mount (posix);
+
+  sprintf (buf, "Software\\%s\\%s\\%s\\%s",
+          CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
+          CYGWIN_INFO_CYGWIN_REGISTRY_NAME,
+          CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME,
+          posix);
+
+  if (RegCreateKeyEx (HKEY_CURRENT_USER, buf, 0, "Cygwin", 0, KEY_ALL_ACCESS,
+                     0, &key, &disposition) != ERROR_SUCCESS)
+    fatal ("mount");
+
+  RegSetValueEx (key, "native", 0, REG_SZ, (BYTE *)win32, strlen (win32)+1);
+  if (istext)
+    flags = 0;
+  else
+    flags = MOUNT_BINARY;
+  RegSetValueEx (key, "flags", 0, REG_DWORD, (BYTE *)&flags, sizeof (flags));
+}
+
+static void
+remove1 (HKEY rkey, char *posix)
+{
+  char buf[1000];
+
+  sprintf (buf, "Software\\%s\\%s\\%s\\%s",
+          CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
+          CYGWIN_INFO_CYGWIN_REGISTRY_NAME,
+          CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME,
+          posix);
+
+  RegDeleteKey (rkey, buf);
+}
+
+void
+remove_mount (char *posix)
+{
+  remove1 (HKEY_LOCAL_MACHINE, posix);
+  remove1 (HKEY_CURRENT_USER, posix);
+}
diff --git a/mount.h b/mount.h
new file mode 100644 (file)
index 0000000..4c0c700
--- /dev/null
+++ b/mount.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* Finds the existing root mount, or returns NULL.  istext is set to
+   nonzero if the existing mount is a text mount, else zero for
+   binary. */
+
+char * find_root_mount (int *istext);
+
+/* Similar to the mount and umount functions, but simplified */
+
+void   create_mount (char *posix, char *win32, int istext);
+void   remove_mount (char *posix);
diff --git a/msg.cc b/msg.cc
new file mode 100644 (file)
index 0000000..8cba9b6
--- /dev/null
+++ b/msg.cc
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to centralize all the message
+   functions. */
+
+#include "win32.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include "dialog.h"
+
+void
+msg(char *fmt, ...)
+{
+  char buf[1000];
+  va_list args;
+  va_start (args, fmt);
+  vsprintf (buf, fmt, args);
+  OutputDebugString (buf);
+}
+
+static int mbox (int type, int id, va_list args)
+{
+  char buf[1000], fmt[1000];
+
+  if (LoadString (hinstance, id, fmt, sizeof(fmt)) <= 0)
+    ExitProcess (0);
+
+  vsprintf (buf, fmt, args);
+  return MessageBox (0, buf, "Cygwin Setup", type);
+}
+
+void
+note (int id, ...)
+{
+  va_list args;
+  va_start (args, id);
+  mbox (0, id, args);
+}
+
+void
+fatal (int id, ...)
+{
+  va_list args;
+  va_start (args, id);
+  mbox (0, id, args);
+  ExitProcess (1);
+}
+
+int
+yesno (int id, ...)
+{
+  va_list args;
+  va_start (args, id);
+  return mbox (MB_YESNO, id, args);
+}
diff --git a/msg.h b/msg.h
new file mode 100644 (file)
index 0000000..ddd3785
--- /dev/null
+++ b/msg.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* This is for "printf"-like debugging.  Messages go to
+   OutputDebugString, which can be seen while debugging under GDB or
+   via a debug message monitor. */
+
+void msg(char *fmt, ...);
+
+/* This pops up a dialog with text from the string table ("id"), which
+   is interpreted like printf.  The program exits when the user
+   presses OK. */
+
+void fatal (int id, ...);
+
+/* Similar, but the program continues when the user presses OK */
+
+void note (int id, ...);
+
+/* returns IDYES or IDNO, otherwise same as note() */
+int yesno (int id, ...);
diff --git a/net.cc b/net.cc
new file mode 100644 (file)
index 0000000..6fb4ee6
--- /dev/null
+++ b/net.cc
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to get the network configuration
+   information from the user. */
+
+#include "win32.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "dialog.h"
+#include "resource.h"
+#include "state.h"
+#include "msg.h"
+
+static int rb[] = { IDC_NET_IE5, IDC_NET_DIRECT, IDC_NET_PROXY, 0 };
+
+static void
+check_if_enable_next (HWND h)
+{
+  int e = 0, p = 0, pu = 0;
+  if (net_method == IDC_NET_IE5)
+    pu = 1;
+  if (net_method == IDC_NET_IE5 || net_method == IDC_NET_DIRECT)
+    e = 1;
+  else if (net_method == IDC_NET_PROXY)
+    {
+      p = pu = 1;
+      if (net_proxy_host && net_proxy_port)
+       e = 1;
+    }
+  if (pu && (net_proxy_user && !net_proxy_passwd
+            || !net_proxy_user && net_proxy_passwd))
+    e = 0;
+  EnableWindow (GetDlgItem (h, IDOK), e);
+  EnableWindow (GetDlgItem (h, IDC_PROXY_HOST), p);
+  EnableWindow (GetDlgItem (h, IDC_PROXY_PORT), p);
+  EnableWindow (GetDlgItem (h, IDC_PROXY_USER), pu);
+  EnableWindow (GetDlgItem (h, IDC_PROXY_PASSWD), pu);
+}
+
+static void
+load_dialog (HWND h)
+{
+  rbset (h, rb, net_method);
+  eset (h, IDC_PROXY_HOST, net_proxy_host);
+  if (net_proxy_port == 0)
+    net_proxy_port = 80;
+  eset (h, IDC_PROXY_PORT, net_proxy_port);
+  eset (h, IDC_PROXY_USER, net_proxy_user);
+  eset (h, IDC_PROXY_PASSWD, net_proxy_passwd);
+  check_if_enable_next (h);
+}
+
+static void
+save_dialog (HWND h)
+{
+  net_method = rbget (h, rb);
+  net_proxy_host = eget (h, IDC_PROXY_HOST, net_proxy_host);
+  net_proxy_port = eget (h, IDC_PROXY_PORT);
+  net_proxy_user = eget (h, IDC_PROXY_USER, net_proxy_user);
+  net_proxy_passwd = eget (h, IDC_PROXY_PASSWD, net_proxy_passwd);
+}
+
+static BOOL
+dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
+{
+  switch (id)
+    {
+
+    case IDC_NET_IE5:
+    case IDC_NET_DIRECT:
+    case IDC_NET_PROXY:
+    case IDC_PROXY_HOST:
+    case IDC_PROXY_PORT:
+    case IDC_PROXY_USER:
+    case IDC_PROXY_PASSWD:
+      save_dialog (h);
+      check_if_enable_next (h);
+      break;
+
+    case IDOK:
+      save_dialog(h);
+      switch (source)
+       {
+       case IDC_SOURCE_NETINST:
+       case IDC_SOURCE_DOWNLOAD:
+         NEXT(IDD_SITE);
+         break;
+       case IDC_SOURCE_CWD:
+         NEXT(0);
+         break;
+       default:
+         msg("source is default? %d\n", source);
+         NEXT(0);
+       }
+      break;
+
+    case IDC_BACK:
+      save_dialog(h);
+      switch (source)
+       {
+       case IDC_SOURCE_DOWNLOAD:
+         NEXT(IDD_SOURCE);
+         break;
+       case IDC_SOURCE_NETINST:
+       case IDC_SOURCE_CWD:
+         NEXT(IDD_ROOT);
+         break;
+       }
+      break;
+
+    case IDCANCEL:
+      NEXT(0);
+      break;
+    }
+}
+
+static BOOL CALLBACK
+dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
+{
+  switch (message)
+    {
+    case WM_INITDIALOG:
+      load_dialog(h);
+      return FALSE;
+    case WM_COMMAND:
+      return HANDLE_WM_COMMAND(h, wParam, lParam, dialog_cmd);
+    }
+  return FALSE;
+}
+
+void
+do_net (HINSTANCE h)
+{
+  int rv = 0;
+  rv = DialogBox (h, MAKEINTRESOURCE (IDD_NET), 0, dialog_proc);
+  if (rv == -1)
+    fatal (IDS_DIALOG_FAILED);
+}
+
diff --git a/netio.cc b/netio.cc
new file mode 100644 (file)
index 0000000..75a8973
--- /dev/null
+++ b/netio.cc
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to coordinate the various access
+   methods known to setup.  To add a new method, create a pair of
+   nio-*.[ch] files and add the logic to NetIO::open here */
+
+#include "win32.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "resource.h"
+#include "state.h"
+#include "msg.h"
+#include "netio.h"
+#include "nio-file.h"
+#include "nio-ie5.h"
+
+#include "port.h"
+
+NetIO::NetIO (char *Purl)
+{
+  char *bp, *ep, c;
+
+  file_size = 0;
+  url = _strdup (Purl);
+  proto = 0;
+  host = 0;
+  port = 0;
+  path = 0;
+
+  bp = url;
+  ep = strstr (bp, "://");
+  if (!ep)
+    {
+      path = url;
+      return;
+    }
+
+  *ep = 0;
+  proto = _strdup (bp);
+  *ep = ':';
+  bp = ep+3;
+
+  ep += strcspn (bp, ":/");
+  c = *ep;
+  *ep = 0;
+  host = _strdup (bp);
+  *ep = c;
+
+  if (*ep == ':')
+    {
+      port = atoi (ep+1);
+      ep = strchr (ep, '/');
+    }
+
+  if (*ep)
+    path = _strdup (ep);
+}
+
+NetIO::~NetIO ()
+{
+  if (url)
+    free (url);
+  if (proto)
+    free (proto);
+  if (host)
+    free (host);
+  if (path)
+    free (path);
+}
+
+int
+NetIO::ok ()
+{
+  return 0;
+}
+
+int
+NetIO::read (char *buf, int nbytes)
+{
+  return 0;
+}
+
+NetIO *
+NetIO::open (char *url)
+{
+  NetIO *rv = 0;
+  enum {http, ftp, file} proto;
+  if (strncmp (url, "http://", 7) == 0)
+    proto = http;
+  else if (strncmp (url, "ftp://", 6) == 0)
+    proto = ftp;
+  else
+    proto = file;
+
+  if (proto == file)
+    rv = new NetIO_File (url);
+  else if (net_method == IDC_NET_IE5)
+    rv = new NetIO_IE5 (url);
+#if 0
+  else if (net_method == IDC_NET_DIRECT)
+    rv = new NetIO_Direct (url);
+  else if (net_method == IDC_NET_PROXY)
+    rv = new NetIO_Proxy (url);
+#endif
+
+  if (!rv->ok ())
+    {
+      delete rv;
+      return 0;
+    }
+
+  return rv;
+}
diff --git a/netio.h b/netio.h
new file mode 100644 (file)
index 0000000..c8fb49a
--- /dev/null
+++ b/netio.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* This is the parent class for all the access methods known to setup
+   (i.e. ways to download files from the internet or other sources */
+
+class NetIO {
+protected:
+  NetIO (char *url);
+public:
+  /* if nonzero, this is the estimated total file size */
+  int file_size;
+  /* broken down url FYI */
+  char *url;
+  char *proto;
+  char *host;
+  int port;
+  char *path;
+  virtual ~NetIO ();
+
+  /* The user calls this function to create a suitable accessor for
+     the given URL.  It uses the network setup state in state.h.  If
+     anything fails, either the return values is NULL or the returned
+     object is !ok() */
+  static NetIO * open (char *url);
+
+  /* If !ok() that means the transfer isn't happening. */
+  virtual int ok ();
+
+  /* Read `nbytes' bytes from the file.  Returns zero when the file
+     is complete. */
+  virtual int read (char *buf, int nbytes);
+};
diff --git a/nio-file.cc b/nio-file.cc
new file mode 100644 (file)
index 0000000..8bc4624
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to manage access to files stored on the
+   local disk (i.e. "downloading" setup.ini).  Called from netio.cc */
+
+#include "win32.h"
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include "netio.h"
+#include "nio-file.h"
+#include "resource.h"
+#include "msg.h"
+
+NetIO_File::NetIO_File (char *Purl)
+  : NetIO (Purl)
+{
+  struct stat s;
+  fd = fopen (path, "rb");
+  if (fd)
+    {
+      stat (path, &s);
+      file_size = s.st_size;
+    }
+  else
+    {
+      char *err = strerror (errno);
+      if (!err)
+       err = "(unknown error)";
+      note (IDS_ERR_OPEN_READ, path, err);
+    }
+}
+
+NetIO_File::~NetIO_File ()
+{
+  if (fd)
+    fclose ((FILE *)fd);
+}
+
+int
+NetIO_File::ok ()
+{
+  return fd ? 1 : 0;
+}
+
+int
+NetIO_File::read (char *buf, int nbytes)
+{
+  return fread (buf, 1, nbytes, (FILE *)fd);
+}
similarity index 70%
rename from cygcalls.h
rename to nio-file.h
index 329e536bbc3b0e220277a14a6c98711b3e245cb5..6d2eb928f90d769f73e0af0295385da603878991 100644 (file)
  *
  */
 
-#include "../cygwin/include/sys/mount.h"
-#include "../cygwin/include/mntent.h"
+/* see nio-file.cc */
 
-/* returns zero on success, nonzero on failure */
-int cygcall_load_dll (char *name); 
-
-int cygcall_unload_dll (); 
+class NetIO_File : public NetIO {
+public:
+  NetIO_File (char *url);
+  void *fd;
+  ~NetIO_File ();
+  virtual int ok ();
+  virtual int read (char *buf, int nbytes);
+};
diff --git a/nio-ie5.cc b/nio-ie5.cc
new file mode 100644 (file)
index 0000000..dde8f5d
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to manage internet downloads using the
+   Internet Explorer version 5 DLLs.  To use this method, the user
+   must already have installed and configured IE5.  This module is
+   called from netio.cc, which is called from geturl.cc */
+
+#include "win32.h"
+
+#include "resource.h"
+#include "state.h"
+#include "dialog.h"
+#include "msg.h"
+#include "netio.h"
+#include "nio-ie5.h"
+
+static HINTERNET internet = 0;
+
+NetIO_IE5::NetIO_IE5 (char *_url)
+  : NetIO (_url)
+{
+  if (internet == 0)
+    internet = InternetOpen ("Cygwin Setup", INTERNET_OPEN_TYPE_PRECONFIG,
+                            NULL, NULL, 0);
+
+  DWORD flags =
+    INTERNET_FLAG_DONT_CACHE |
+    INTERNET_FLAG_KEEP_CONNECTION |
+    INTERNET_FLAG_PRAGMA_NOCACHE |
+    INTERNET_FLAG_RELOAD |
+    INTERNET_FLAG_EXISTING_CONNECT |
+    INTERNET_FLAG_PASSIVE;
+
+  if (net_proxy_user && net_proxy_passwd)
+    {
+      InternetSetOption (internet, INTERNET_OPTION_PROXY_USERNAME,
+                        net_proxy_user, strlen (net_proxy_user));
+      InternetSetOption (internet, INTERNET_OPTION_PROXY_PASSWORD,
+                        net_proxy_passwd, strlen (net_proxy_passwd));
+    }
+
+  connection = InternetOpenUrl (internet, url, NULL, 0, flags, 0);
+
+  if (!connection)
+    {
+      if (GetLastError () == ERROR_INTERNET_EXTENDED_ERROR)
+       {
+         char buf[2000];
+         DWORD e, l=sizeof (buf);
+         InternetGetLastResponseInfo (&e, buf, &l);
+         MessageBox (0, buf, "Internet Error", 0);
+       }
+      else
+       {
+         fatal (url);
+       }
+    }
+}
+
+NetIO_IE5::~NetIO_IE5 ()
+{
+  if (connection)
+    InternetCloseHandle (connection);
+}
+
+int
+NetIO_IE5::ok ()
+{
+  return (connection == NULL) ? 0 : 1;
+}
+
+int
+NetIO_IE5::read (char *buf, int nbytes)
+{
+  DWORD actual;
+  if (InternetReadFile (connection, buf, nbytes, &actual))
+    return actual;
+  return -1;
+}
diff --git a/nio-ie5.h b/nio-ie5.h
new file mode 100644 (file)
index 0000000..4259333
--- /dev/null
+++ b/nio-ie5.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* see nio-ie5.cc */
+
+class NetIO_IE5 : public NetIO {
+  HINTERNET connection;
+public:
+  NetIO_IE5 (char *url);
+  ~NetIO_IE5 ();
+  virtual int ok ();
+  virtual int read (char *buf, int nbytes);
+};
diff --git a/other.cc b/other.cc
new file mode 100644 (file)
index 0000000..674101f
--- /dev/null
+++ b/other.cc
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* This handles the "other URL" option from the mirror site
+   selection. */
+
+#include "win32.h"
+#include <shlobj.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "dialog.h"
+#include "resource.h"
+#include "state.h"
+#include "msg.h"
+
+
+static void
+check_if_enable_next (HWND h)
+{
+  EnableWindow (GetDlgItem (h, IDOK), other_url ? 1 : 0);
+}
+
+static void
+load_dialog (HWND h)
+{
+  eset (h, IDC_OTHER_URL, other_url);
+  check_if_enable_next (h);
+}
+
+static void
+save_dialog (HWND h)
+{
+  other_url = eget (h, IDC_OTHER_URL, other_url);
+}
+
+static BOOL
+dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
+{
+  switch (id)
+    {
+
+    case IDC_OTHER_URL:
+      save_dialog (h);
+      check_if_enable_next (h);
+      break;
+
+    case IDOK:
+      save_dialog(h);
+      NEXT(IDD_S_LOAD_INI);
+      break;
+
+    case IDC_BACK:
+      save_dialog(h);
+      NEXT(IDD_SITE);
+      break;
+
+    case IDCANCEL:
+      NEXT(0);
+      break;
+    }
+}
+
+static BOOL CALLBACK
+dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
+{
+  switch (message)
+    {
+    case WM_INITDIALOG:
+      load_dialog(h);
+      return FALSE;
+    case WM_COMMAND:
+      return HANDLE_WM_COMMAND(h, wParam, lParam, dialog_cmd);
+    }
+  return FALSE;
+}
+
+void
+do_other (HINSTANCE h)
+{
+  int rv = 0;
+  rv = DialogBox (h, MAKEINTRESOURCE (IDD_OTHER_URL), 0, dialog_proc);
+  if (rv == -1)
+    fatal (IDS_DIALOG_FAILED);
+}
+
diff --git a/path.c b/path.c
deleted file mode 100644 (file)
index 183df01..0000000
--- a/path.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright (c) 2000, Red Hat, Inc.
- *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     A copy of the GNU General Public License can be found at
- *     http://www.gnu.org/
- *
- * Written by Ron Parker <parkerrd@hotmail.com>
- *
- */
-
-#include <windows.h>
-#include <wininet.h>
-#include <assert.h>
-#include <ctype.h>
-#include <direct.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <io.h>
-#include <shellapi.h>
-#include <shlguid.h>
-#include <shlobj.h>
-#include <stdio.h>
-#include <time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "setup.h"
-#include "strarry.h"
-#include "zlib/zlib.h"
-
-#if 0
-
-static FILE *cygin = NULL, *cygout = NULL;
-static HANDLE hcygpath = NULL;
-
-void
-exit_cygpath (void)
-{
-  if (cygin)
-    fclose (cygin);
-  if (cygout)
-    fclose (cygout);
-  if (hcygpath)
-    {
-      Sleep (0);
-      if (WaitForSingleObject (hcygpath, 5000) != WAIT_OBJECT_0)
-       {
-         TerminateProcess (hcygpath, 0);
-         WaitForSingleObject (hcygpath, 5000);
-       }
-      CloseHandle (hcygpath);
-    }
-}
-
-static int
-cygpath_pipe (void)
-{
-  int hpipein[2] = {-1, -1};
-  int hpipeout[2] = {-1, -1};
-  char buffer[256];
-  
-  HANDLE hin, hout;
-  if (_pipe (hpipein, 256, O_TEXT) == -1)
-    return 0;
-  if (_pipe (hpipeout, 256, O_TEXT) == -1)
-    return 0;
-
-  hin = (HANDLE) _get_osfhandle (hpipein[1]);
-  hout = (HANDLE) _get_osfhandle (hpipeout[0]);
-  sprintf (buffer, "cygpath -a -o -f - -c %lx", (unsigned long) _get_osfhandle (hpipeout[1]));
-  hcygpath = (HANDLE) xcreate_process (0, hout, hin, hin, buffer);
-  if (!hcygpath)
-    return 0;
-  _close (hpipein[1]);
-  _close (hpipeout[0]);
-  cygin = fdopen (hpipein[0], "rt");
-  cygout = fdopen (hpipeout[1], "wt");
-  setbuf (cygout, NULL);
-  return 1;
-}
-
-char *
-pathcvt (char target, const char *path)
-{
-  char buffer[1024];
-  char *retval;
-
-  if (!cygin && !cygpath_pipe ())
-    return NULL;       /* FIXME - error */
-
-  fprintf (cygout, "-%c %s\n", target, path);
-  retval = fgets (buffer, sizeof (buffer), cygin);
-  if (retval)
-    {
-      char *p = strchr (buffer, '\n');
-      if (p != NULL)
-       *p = '\0';
-      retval = xstrdup (buffer);
-    }
-
-  /* If there is an error try using the original style path anyway. */
-  return retval ? retval : xstrdup (path);
-}
-
-char *
-dtoupath (const char *path)
-{
-  char *retval = pathcvt ('u', path);
-  size_t len = strlen (retval);
-  if (len > 2 && retval[len - 1] == '/')       /* Trim the trailing slash
-                                                  off of a nonroot path. */
-    retval[len - 1] = '\0';
-
-  return retval;
-}
-
-char *
-utodpath (const char *path)
-{
-  char *retval = pathcvt ('w', path);
-  size_t len = strlen (retval);
-  if (len > 3 && retval[len - 1] == '\\')      /* Trim the trailing slash
-                                                  off of a nonroot path. */
-    retval[len - 1] = '\0';
-
-  return retval;
-}
-
-#endif /* 0 */
-
-char *
-pathcat (const char *arg1, const char *arg2)
-{
-  char path[_MAX_PATH];
-  size_t len;
-  char *s, *d;
-
-  strcpy (path, arg1);
-  strcat (path, "\\");
-  strcat (path, arg2);
-
-  for (s=path; *s; s++)
-    if (*s == '/')
-      *s = '\\';
-  for (s=d=path; *s; s++)
-    {
-      *d++ = *s;
-      if (*s == '\\')
-       while (s[1] == '\\')
-         s++;
-    }
-  *d = 0;
-
-  return xstrdup (path);
-}
diff --git a/pkg.c b/pkg.c
deleted file mode 100644 (file)
index da72b37..0000000
--- a/pkg.c
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * Copyright (c) 2000, Red Hat, Inc.
- *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     A copy of the GNU General Public License can be found at
- *     http://www.gnu.org/
- *
- * Written by Christopher Faylor <cgf@redhat.com>
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <windows.h>
-#include "setup.h"
-#include <sys/stat.h>
-
-#define CYGMAJOR "%%% Cygwin dll major: "
-#define CYGMAJOR_LEN (sizeof (CYGMAJOR) - 1)
-#define CYGMINOR "%%% Cygwin dll minor: "
-#define CYGMINOR_LEN (sizeof (CYGMINOR) - 1)
-
-pkg global_pkgstuff[1000];
-
-void
-normalize_version (const char *fn_in, char **prod, char **version)
-{
-  char *p;
-  char *fn, *origfn;
-  char *dot;
-  static char buf1[1024];
-  static char buf2[1024];
-
-  origfn = buf1;
-  strcpy (buf1, fn_in);
-  fn = origfn = buf1;
-
-  if ((p = strstr (fn, ".tar.gz")) != NULL)
-    *p = '\0';
-  else if ((p = strstr (fn, "_tar.gz")) != NULL)
-    *p = '\0';
-
-  while (isalpha (*fn))
-    fn++;
-  if (*fn)
-    *fn++ = '\0';
-
-  *prod = origfn;
-  if (!*fn)
-    {
-      *version = strcpy (buf2, "0000");
-      return;
-    }
-
-  dot = "";
-  buf2[0] = '\0';
-  while (*fn)
-    {
-      int n;
-      fn += strspn (fn, "-_.+,");
-      if (!*fn)
-       break;
-      n = strcspn (fn, "-_.+,");
-      sprintf (strchr (buf2, '\0'), "%s%04.*s", dot, n, fn);
-      fn += n;
-      dot = ".";
-    }
-
-  *version = buf2;
-  return;
-}
-
-static HKEY hkpkg;
-
-static pkg default_pkgs[] =
-{
-  {"diff", "0000"},
-  {"ash", "0000"},
-  {"bash", "0000"},
-  {"binutils", "19990818.0001"},
-  {"bison", "0000"},
-  {"byacc", "0000"},
-  {"bzip", "0000"},
-  {"clear", "0001.0000"},
-  {"dejagnu", "0000"},
-  {"expect", "0000"},
-  {"fileutils", "0000"},
-  {"findutils", "0000"},
-  {"flex", "0000"},
-  {"gawk", "0000"},
-  {"gcc", "0002.0095.0002.0001"},
-  {"gdb", "20000415"},
-  {"gperf", "0000"},
-  {"grep", "0000"},
-  {"groff", "0001.011a.0001"},
-  {"gzip", "0000"},
-  {"less", "0000"},
-  {"m", "0000"},
-  {"make", "0000"},
-  {"man", "0001.005g.0001"},
-  {"patch", "0000"},
-  {"sed", "0000"},
-  {"shellutils", "0000"},
-  {"tar", "0000"},
-  {"tcltk", "0000"},
-  {"termcap", "0000"},
-  {"texinfo", "0000"},
-  {"textutils", "0000"},
-  {"time", "0000"},
-  {NULL, NULL}
-};
-
-pkg *
-use_default_pkgs (pkg *stuff)
-{
-  pkg *def, *stf;
-  int sawend;
-  def = default_pkgs;
-
-  sawend = 0;
-  for (stf = stuff, def = default_pkgs; def->name != NULL; stf++)
-    {
-      if (sawend || !stf->name)
-       {
-         stf->name = xstrdup (def->name);
-         stf->version = xstrdup (def->version);
-         def++;
-         sawend = 1;
-       }
-      (void) write_pkg (NULL, stf->name, stf->version);
-    }
-  stf->name = NULL;
-  stf->version = NULL;
-  return stuff;
-}
-
-pkg *
-find_pkg (pkg *stuff, char *name)
-{
-  int i;
-
-  for (i = 0; stuff[i].name; i++)
-    if (stricmp (stuff[i].name, name) == 0)
-      return stuff + i;
-
-  return NULL;
-}
-
-const char *
-check_for_installed (const char *root, pkg *stuff)
-{
-  char *cygwin = pathcat (root, "bin\\cygwin1.dll");
-  FILE *fp = fopen (cygwin, "rb");
-  char *buf, *bufend;
-  struct _stat st;
-  char *major, *minor;
-  pkg *pkg;
-  static char buf1[256];
-
-  xfree (cygwin);
-
-  if (fp == NULL)
-    return NULL;
-
-  if (_fstat (fileno (fp), &st))
-    goto err;
-
-  buf = xmalloc (st.st_size);
-  if (!buf)
-    goto err;
-
-  if (fread (buf, st.st_size, 1, fp) <= 0)
-    goto err;
-
-  fclose (fp);
-
-  bufend = buf + st.st_size;
-  major = minor = NULL;
-  while (buf < bufend)
-    if ((buf = memchr (buf, '%', bufend - buf)) == NULL)
-       return 0;
-    else if (strncmp (buf, CYGMAJOR, CYGMAJOR_LEN) == 0)
-       major = buf += CYGMAJOR_LEN;
-    else if (strncmp (buf, CYGMINOR, CYGMINOR_LEN) != 0)
-       buf++;
-    else
-       {
-         minor = buf + CYGMINOR_LEN;
-         break;
-       }
-
-  if (!minor)
-    return NULL;
-
-  sprintf (buf1, "%04d.%04d.%04d", atoi (major) / 1000, atoi (major) % 1000, atoi (minor));
-
-  pkg = find_pkg (stuff, "cygwin");
-  if (pkg)
-    xfree (pkg->version);
-  else
-    {
-      pkg = stuff;
-      stuff[1].name = stuff[1].version = NULL;
-    }
-
-  pkg->name = xstrdup ("cygwin");
-  pkg->version = xstrdup (buf1);
-
-  sprintf (buf1, "%d.%d.%d", atoi (major) / 1000, atoi (major) % 1000, atoi (minor));
-
-  return buf1;
-
-err:
-  fclose (fp);
-  return NULL;
-}
-
-#define REGWHERE "SOFTWARE\\Cygnus Solutions\\Cygwin\\Installed Components"
-
-pkg *
-init_pkgs (const char *root, int use_current_user)
-{
-  LONG res;
-  DWORD what;
-  char *p, empty[] = "";
-  char buf[4096];
-  DWORD ty, sz;
-  DWORD nc = 0;
-
-  sprintf (buf, "%s\\%s", REGWHERE, root);
-  for (p = buf + sizeof (REGWHERE); (p = strchr (p, '\\')) != NULL; )
-    *p = '/';
-  
-  res = RegCreateKeyEx (use_current_user ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, buf,
-                       0, empty,  REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkpkg, &what);
-
-  if (res != ERROR_SUCCESS)
-    return NULL;
-
-  for (nc = 0, sz = sizeof (buf);
-       RegEnumValue (hkpkg, nc, buf, &sz, NULL, &ty, NULL, NULL) == ERROR_SUCCESS;
-       nc++, sz = sizeof (buf))
-    {
-      DWORD sz = sizeof (buf);
-      global_pkgstuff[nc].name = xstrdup (buf);
-
-      if (RegQueryValueEx (hkpkg, global_pkgstuff[nc].name, NULL,
-                        &ty, buf, &sz) == ERROR_SUCCESS)
-       global_pkgstuff[nc].version = xstrdup (buf);
-      else
-       global_pkgstuff[nc].version = xstrdup ("");
-    }
-
-  global_pkgstuff[nc].version = global_pkgstuff[nc].name = NULL;
-  return global_pkgstuff;
-}
-
-int
-write_pkg (pkg *pkg, char *name, char *version)
-{
-  if (pkg != NULL && stricmp (pkg->version, version) >= 0)
-    return 0;
-
-  RegSetValueEx (hkpkg, name, 0, REG_SZ, version, strlen (version) + 1);
-  return 1;
-}
-
-int
-newer_pkg (pkg *pkg, char *version)
-{
-  if (pkg != NULL && stricmp (pkg->version, version) >= 0)
-    return 0;
-  return 1;
-}
-
-void
-close_pkgs ()
-{
-  RegCloseKey (hkpkg);
-}
-
-#ifdef check
-int
-main (int argc, char **argv)
-{
-  pkg *stuff = init_pkgs ();
-
-  while (*++argv)
-    {
-      char *stub, *ver;
-      pkg *pkg;
-      normalize_version (*argv, &stub, &ver);
-      printf ("%s = %s, %s\n", *argv, stub, ver);
-      if ((pkg = find_pkg (stuff, stub)) != NULL)
-       printf ("found pkg %s = %s\n", pkg->name, pkg->version);
-      printf ("write_pkg returns %d\n", write_pkg (pkg, stub, ver));
-    }
-  exit (0);
-}
-#endif
diff --git a/port.h b/port.h
new file mode 100644 (file)
index 0000000..c2c019a
--- /dev/null
+++ b/port.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* I prefer building a cygwin version of setup for debugging, as I
+   find that gdb can debug those programs (and the exceptions they
+   cause) better.  This file handles the slight differences between
+   cygwin and mingw. */
+
+#if defined(__CYGWIN__) || defined (__CYGWIN32__)
+
+#define _MAX_PATH MAX_PATH
+
+#define _access access
+#define _strdup strdup
+
+#endif
diff --git a/res.rc b/res.rc
new file mode 100644 (file)
index 0000000..24c324f
--- /dev/null
+++ b/res.rc
@@ -0,0 +1,272 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+
+//Microsoft Developer Studio generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#define APSTUDIO_HIDDEN_SYMBOLS
+#include "windows.h"
+#undef APSTUDIO_HIDDEN_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (U.S.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+#ifdef _WIN32
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+#endif //_WIN32
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_SOURCE DIALOG DISCARDABLE  0, 0, 215, 95
+STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Cygwin Setup"
+FONT 8, "MS Sans Serif"
+BEGIN
+    DEFPUSHBUTTON   "Next -->",IDOK,100,75,45,15,WS_DISABLED
+    PUSHBUTTON      "Cancel",IDCANCEL,165,75,45,15
+    PUSHBUTTON      "<-- Back",IDC_BACK,55,75,45,15,WS_DISABLED
+    ICON            IDI_CYGWIN,-1,5,5,20,20
+    CONTROL         "Download from Internet to Current Directory",
+                    IDC_SOURCE_DOWNLOAD,"Button",BS_AUTORADIOBUTTON,55,15,
+                    152,10
+    CONTROL         "Install from Internet",IDC_SOURCE_NETINST,"Button",
+                    BS_AUTORADIOBUTTON,55,30,75,10
+    CONTROL         "Install from Current Directory",IDC_SOURCE_CWD,"Button",
+                    BS_AUTORADIOBUTTON,55,45,104,10
+END
+
+IDD_ROOT DIALOG DISCARDABLE  0, 0, 215, 95
+STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Cygwin Setup"
+FONT 8, "MS Sans Serif"
+BEGIN
+    DEFPUSHBUTTON   "Next -->",IDOK,100,75,45,15
+    PUSHBUTTON      "Cancel",IDCANCEL,165,75,45,15
+    EDITTEXT        IDC_ROOT_DIR,55,25,127,12,ES_AUTOHSCROLL
+    LTEXT           "Select install root directory",IDC_STATIC,55,15,135,11
+    PUSHBUTTON      "<-- Back",IDC_BACK,55,75,45,15
+    ICON            IDI_CYGWIN,IDC_STATIC,5,5,20,20
+    PUSHBUTTON      "Browse...",IDC_ROOT_BROWSE,55,40,45,15
+    CONTROL         "Text Mounts",IDC_ROOT_TEXT,"Button",BS_AUTORADIOBUTTON,
+                    120,45,55,10
+    CONTROL         "Binary Mounts",IDC_ROOT_BINARY,"Button",
+                    BS_AUTORADIOBUTTON,120,55,61,10
+END
+
+IDD_SITE DIALOG DISCARDABLE  0, 0, 215, 95
+STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Cygwin Setup"
+FONT 8, "MS Sans Serif"
+BEGIN
+    DEFPUSHBUTTON   "Next -->",IDOK,100,75,45,15
+    PUSHBUTTON      "Cancel",IDCANCEL,165,75,45,15
+    LTEXT           "Select Download Site",IDC_STATIC,55,5,135,11
+    PUSHBUTTON      "<-- Back",IDC_BACK,55,75,45,15
+    ICON            IDI_CYGWIN,IDC_STATIC,5,5,20,20
+    LISTBOX         IDC_URL_LIST,55,20,155,51,LBS_NOINTEGRALHEIGHT | 
+                    WS_VSCROLL | WS_HSCROLL | WS_TABSTOP
+END
+
+IDD_OTHER_URL DIALOG DISCARDABLE  0, 0, 215, 95
+STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Cygwin Setup"
+FONT 8, "MS Sans Serif"
+BEGIN
+    DEFPUSHBUTTON   "Next -->",IDOK,100,75,45,15
+    PUSHBUTTON      "Cancel",IDCANCEL,165,75,45,15
+    EDITTEXT        IDC_OTHER_URL,55,25,127,12,ES_AUTOHSCROLL
+    LTEXT           "Select URL to download from",IDC_STATIC,55,15,135,11
+    PUSHBUTTON      "<-- Back",IDC_BACK,55,75,45,15
+    ICON            IDI_CYGWIN,IDC_STATIC,5,5,20,20
+END
+
+IDD_NET DIALOG DISCARDABLE  0, 0, 215, 141
+STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Cygwin Setup"
+FONT 8, "MS Sans Serif"
+BEGIN
+    DEFPUSHBUTTON   "Next -->",IDOK,100,120,45,15,WS_DISABLED
+    PUSHBUTTON      "Cancel",IDCANCEL,165,120,45,15
+    ICON            IDI_CYGWIN,IDC_STATIC,5,5,20,20
+    CONTROL         "Use IE5 Settings",IDC_NET_IE5,"Button",
+                    BS_AUTORADIOBUTTON,55,15,69,10
+    CONTROL         "Direct Connection",IDC_NET_DIRECT,"Button",
+                    BS_AUTORADIOBUTTON | WS_DISABLED,55,30,73,10
+    CONTROL         "Use HTTP/FTP Proxy:",IDC_NET_PROXY,"Button",
+                    BS_AUTORADIOBUTTON | WS_DISABLED,55,45,88,10
+    EDITTEXT        IDC_PROXY_HOST,65,60,80,12,ES_AUTOHSCROLL | WS_DISABLED
+    LTEXT           "Proxy",IDC_STATIC,10,60,50,15,SS_CENTERIMAGE,
+                    WS_EX_RIGHT
+    LTEXT           "Port",IDC_STATIC,155,60,20,15,SS_CENTERIMAGE,
+                    WS_EX_RIGHT
+    EDITTEXT        IDC_PROXY_PORT,180,60,30,12,ES_AUTOHSCROLL | WS_DISABLED
+    EDITTEXT        IDC_PROXY_USER,65,80,145,12,ES_AUTOHSCROLL | WS_DISABLED
+    LTEXT           "Optional User ID",IDC_STATIC,5,80,55,15,SS_CENTERIMAGE,
+                    WS_EX_RIGHT
+    EDITTEXT        IDC_PROXY_PASSWD,65,95,145,12,ES_AUTOHSCROLL | 
+                    WS_DISABLED
+    LTEXT           "Password",IDC_STATIC,10,95,50,15,SS_CENTERIMAGE,
+                    WS_EX_RIGHT
+    PUSHBUTTON      "<-- Back",IDC_BACK,55,120,45,15
+END
+
+IDD_DLSTATUS DIALOG DISCARDABLE  0, 0, 215, 95
+STYLE DS_MODALFRAME | DS_SETFOREGROUND | DS_CENTER | WS_POPUP | WS_VISIBLE | 
+    WS_CAPTION | WS_SYSMENU
+CAPTION "Cygwin Setup"
+FONT 8, "MS Sans Serif"
+BEGIN
+    PUSHBUTTON      "Cancel",IDCANCEL,165,75,45,15
+    LTEXT           "Downloading...",IDC_STATIC,55,15,135,8
+    LTEXT           "(URL)",IDC_DLS_URL,55,30,150,8
+    LTEXT           "(RATE)",IDC_DLS_RATE,55,45,155,8
+    CONTROL         "Progress1",IDC_DLS_PROGRESS,"msctls_progress32",
+                    PBS_SMOOTH | WS_BORDER,55,60,155,10
+    ICON            IDI_CYGWIN,IDC_STATIC,5,5,20,20
+END
+
+IDD_INSTATUS DIALOG DISCARDABLE  0, 0, 215, 95
+STYLE DS_MODALFRAME | DS_SETFOREGROUND | DS_CENTER | WS_POPUP | WS_VISIBLE | 
+    WS_CAPTION | WS_SYSMENU
+CAPTION "Cygwin Setup"
+FONT 8, "MS Sans Serif"
+BEGIN
+    PUSHBUTTON      "Cancel",IDCANCEL,165,75,45,15
+    LTEXT           "Installing...",IDC_STATIC,55,5,135,8
+    LTEXT           "(PKG)",IDC_INS_PKG,55,15,150,8
+    LTEXT           "(FILE)",IDC_INS_FILE,55,25,155,8
+    CONTROL         "Progress1",IDC_INS_DISKFULL,"msctls_progress32",
+                    PBS_SMOOTH | WS_BORDER,55,60,155,10
+    ICON            IDI_CYGWIN,IDC_STATIC,5,5,20,20
+    CONTROL         "Progress1",IDC_INS_IPROGRESS,"msctls_progress32",
+                    PBS_SMOOTH | WS_BORDER,55,50,155,10
+    CONTROL         "Progress1",IDC_INS_PPROGRESS,"msctls_progress32",
+                    PBS_SMOOTH | WS_BORDER,55,40,155,10
+    RTEXT           "Package",IDC_STATIC,5,40,45,8
+    RTEXT           "Total",IDC_STATIC,10,50,40,8
+    RTEXT           "Disk",IDC_STATIC,5,60,45,8
+END
+
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE DISCARDABLE 
+BEGIN
+    "resource.h\0"
+END
+
+2 TEXTINCLUDE DISCARDABLE 
+BEGIN
+    "#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
+    "#include ""windows.h""\r\n"
+    "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
+    "\0"
+END
+
+3 TEXTINCLUDE DISCARDABLE 
+BEGIN
+    "\r\n"
+    "\0"
+END
+
+#endif    // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Icon
+//
+
+// Icon with lowest ID value placed first to ensure application icon
+// remains consistent on all systems.
+IDI_CYGWIN              ICON    DISCARDABLE     "cygwin.ico"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO DISCARDABLE 
+BEGIN
+    IDD_NET, DIALOG
+    BEGIN
+        BOTTOMMARGIN, 95
+    END
+END
+#endif    // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// String Table
+//
+
+STRINGTABLE DISCARDABLE 
+BEGIN
+    IDS_ROOT_SLASH          "Warning: we recommend you do NOT use the root of your hard drive as the cygwin root.  Proceed anyway?"
+    IDS_ROOT_SPACE          "You should not choose a root path that include spaces in directory names.  Proceed anyway?"
+    IDS_MIRROR_LST          "http://sourceware.cygnus.com/cygwin/mirrors.lst"
+    IDS_DIALOG_FAILED       "Unable to create Dialog Box"
+    IDS_CYGWIN_FUNC_MISSING "Error: unable to find function `%s' in %s"
+    IDS_DOWNLOAD_SHORT      "Download error: %s too short (%d, wanted %d)"
+    IDS_ERR_OPEN_WRITE      "Can't open %s for writing: %s"
+    IDS_SETUPINI_MISSING    "Unable to get setup.ini from %s"
+    IDS_OLD_SETUPINI        "This setup.ini is older than the one you used last time you installed cygwin.  Proceed anyway?"
+    IDS_ERR_RENAME          "Cab't rename %s to %s: %s"
+    IDS_NOTHING_INSTALLED   "Nothing needed to be installed"
+    IDS_INSTALL_COMPLETE    "Installation Complete"
+END
+
+STRINGTABLE DISCARDABLE 
+BEGIN
+    IDS_ERR_OPEN_READ       "Can't open %s for reading: %s"
+    IDS_ROOT_ABSOLUTE       "The install directory must be absolute, with both a drive letter and leading slash, like C:\\Cygwin"
+END
+
+#endif    // English (U.S.) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif    // not APSTUDIO_INVOKED
+
index 2d76c7e6e3754da1dea1630c1a25a10cdeb408f9..f29815d7754c81e2f92f3c0b6c526bc38e35a2ba 100644 (file)
@@ -9,22 +9,79 @@
  *     A copy of the GNU General Public License can be found at
  *     http://www.gnu.org/
  *
- * Written by Ron Parker <parkerrd@hotmail.com>
+ * Written by DJ Delorie <dj@cygnus.com>
  *
  */
 
 //{{NO_DEPENDENCIES}}
 // Microsoft Developer Studio generated include file.
-// Used by setupres.rc
+// Used by res.rc
 //
+#define IDS_ROOT_SLASH                  1
+#define IDS_ROOT_SPACE                  2
+#define IDS_CWD_NONEMPTY                3
+#define IDS_MIRROR_LST                  6
+#define IDS_DIALOG_FAILED               7
+#define IDS_CYGWIN_FUNC_MISSING         8
+#define IDS_DOWNLOAD_SHORT              9
+#define IDS_ERR_OPEN_WRITE              10
+#define IDS_SETUPINI_MISSING            11
+#define IDS_OLD_SETUPINI                12
+#define IDS_ERR_RENAME                  13
+#define IDS_NOTHING_INSTALLED           14
+#define IDS_INSTALL_COMPLETE            15
+#define IDS_ERR_OPEN_READ               16
+#define IDS_ROOT_ABSOLUTE               17
+#define IDD_ROOT                        101
+#define IDD_SOURCE                      102
+#define IDD_OTHER_URL                   103
+#define IDD_SITE                        104
+#define IDD_NET                         105
+#define IDD_DLSTATUS                    106
+#define IDD_S_LOAD_INI                  107
+#define IDD_S_FROM_CWD                  108
+#define IDD_S_CHOOSE                    109
+#define IDD_S_DOWNLOAD                  110
+#define IDD_S_INSTALL                   111
+#define IDD_INSTATUS                    112
+#define IDI_CYGWIN                      200
+#define IDC_SOURCE_DOWNLOAD             1000
+#define IDC_SOURCE_NETINST              1001
+#define IDC_SOURCE_CWD                  1002
+#define IDC_ROOT_DIR                    1003
+#define IDC_ROOT_BROWSE                 1004
+#define IDC_ROOT_TEXT                   1005
+#define IDC_ROOT_BINARY                 1006
+#define IDC_URL_LIST                    1007
+#define IDC_SITE_NEXT                   1008
+#define IDC_BACK                        1009
+#define IDC_OTHER_URL                   1010
+#define IDC_NET_IE5                     1011
+#define IDC_NET_DIRECT                  1012
+#define IDC_NET_PROXY                   1013
+#define IDC_PROXY_HOST                  1014
+#define IDC_PROXY_PORT                  1015
+#define IDC_PROXY_USER                  1016
+#define IDC_PROXY_PASSWD                1017
+#define IDC_DLS_PROGRESS                1019
+#define IDC_DLS_URL                     1020
+#define IDC_DLS_RATE                    1021
+#define IDC_INS_PKG                     1022
+#define IDC_INS_FILE                    1023
+#define IDC_INS_DISKFULL                1024
+#define IDC_INS_IPROGRESS               1025
+#define IDC_INS_PPROGRESS               1026
+#define IDC_STATIC                      -1
 
 // Next default values for new objects
-//
+// 
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE        102
-#define _APS_NEXT_COMMAND_VALUE         40001
-#define _APS_NEXT_CONTROL_VALUE         1000
+#define _APS_NO_MFC                     1
+#define _APS_3D_CONTROLS                     1
+#define _APS_NEXT_RESOURCE_VALUE        113
+#define _APS_NEXT_COMMAND_VALUE         40003
+#define _APS_NEXT_CONTROL_VALUE         1027
 #define _APS_NEXT_SYMED_VALUE           101
-#endif /*  */
-#endif /*  */
+#endif
+#endif
diff --git a/root.cc b/root.cc
new file mode 100644 (file)
index 0000000..24874c4
--- /dev/null
+++ b/root.cc
@@ -0,0 +1,214 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to ask the user where they want the
+   root of the installation to be, and to ask whether the user prefers
+   text or binary mounts. */
+
+#include "win32.h"
+#include <shlobj.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "dialog.h"
+#include "resource.h"
+#include "state.h"
+#include "msg.h"
+#include "mount.h"
+
+static int rb[] = { IDC_ROOT_TEXT, IDC_ROOT_BINARY, 0 };
+
+static void
+check_if_enable_next (HWND h)
+{
+  EnableWindow (GetDlgItem (h, IDOK), root_text && root_dir);
+}
+
+static void
+load_dialog (HWND h)
+{
+  rbset (h, rb, root_text);
+  eset (h, IDC_ROOT_DIR, root_dir);
+  check_if_enable_next (h);
+}
+
+static void
+save_dialog (HWND h)
+{
+  root_text = rbget (h, rb);
+  root_dir = eget (h, IDC_ROOT_DIR, root_dir);
+}
+
+static void
+read_mount_table ()
+{
+  int istext;
+  root_dir = find_root_mount (&istext);
+  if (root_dir)
+    {
+      if (istext)
+       root_text = IDC_ROOT_TEXT;
+      else
+       root_text = IDC_ROOT_BINARY;
+    }
+}
+
+static int CALLBACK
+browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data)
+{
+  switch (msg)
+    {
+    case BFFM_INITIALIZED:
+      SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM)root_dir);
+      break;
+    }
+  return 0;
+}
+
+static void
+browse (HWND h)
+{
+  BROWSEINFO bi;
+  CHAR name[MAX_PATH];
+  LPITEMIDLIST pidl;
+  memset (&bi, 0, sizeof (bi));
+  bi.hwndOwner = h;
+  bi.pszDisplayName = name;
+  bi.lpszTitle = "Select an installation root directory";
+  bi.ulFlags = BIF_RETURNONLYFSDIRS;
+  bi.lpfn = browse_cb;
+  pidl = SHBrowseForFolder (&bi);
+  if (pidl)
+    {
+      if (SHGetPathFromIDList (pidl, name))
+       eset (h, IDC_ROOT_DIR, name);
+    }
+}
+
+#define isslash(c) ((c) == '\\' || (c) == '/')
+
+static int
+directory_is_absolute ()
+{
+  if (isalpha (root_dir[0])
+      && root_dir[1] == ':'
+      && (root_dir[2] == '\\' || root_dir[2] == '/'))
+    return 1;
+  return 0;
+}
+
+static int
+directory_is_rootdir ()
+{
+  char *c;
+  for (c = root_dir; *c; c++)
+    if (isslash(c[0]) && c[1] && !isslash(c[1]))
+      return 0;
+  return 1;
+}
+
+static int
+directory_has_spaces ()
+{
+  if (strchr (root_dir, ' '))
+    return 1;
+  return 0;
+}
+
+static BOOL
+dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
+{
+  switch (id)
+    {
+
+    case IDC_ROOT_DIR:
+    case IDC_ROOT_TEXT:
+    case IDC_ROOT_BINARY:
+      save_dialog (h);
+      check_if_enable_next (h);
+      break;
+
+    case IDC_ROOT_BROWSE:
+      browse (h);
+      break;
+
+    case IDOK:
+      save_dialog(h);
+
+      if (! directory_is_absolute ())
+       {
+         note (IDS_ROOT_ABSOLUTE);
+         break;
+       }
+
+      if (directory_is_rootdir ())
+       if (IDNO == yesno (IDS_ROOT_SLASH))
+         break;
+
+      if (directory_has_spaces ())
+       if (IDNO == yesno (IDS_ROOT_SPACE))
+         break;
+
+      switch (source)
+       {
+       case IDC_SOURCE_NETINST:
+         NEXT(IDD_NET);
+         break;
+       case IDC_SOURCE_CWD:
+         NEXT(IDD_S_FROM_CWD);
+         break;
+       default:
+         msg("source is default? %d\n", source);
+         NEXT(0);
+       }
+      break;
+
+    case IDC_BACK:
+      save_dialog(h);
+      NEXT(IDD_SOURCE);
+      break;
+
+    case IDCANCEL:
+      NEXT(0);
+      break;
+    }
+}
+
+static BOOL CALLBACK
+dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
+{
+  switch (message)
+    {
+    case WM_INITDIALOG:
+      load_dialog(h);
+      return FALSE;
+    case WM_COMMAND:
+      return HANDLE_WM_COMMAND(h, wParam, lParam, dialog_cmd);
+    }
+  return FALSE;
+}
+
+void
+do_root (HINSTANCE h)
+{
+  int rv = 0;
+  if (!root_dir)
+    read_mount_table();
+  rv = DialogBox (h, MAKEINTRESOURCE (IDD_ROOT), 0, dialog_proc);
+  if (rv == -1)
+    fatal (IDS_DIALOG_FAILED);
+}
+
diff --git a/setup.c b/setup.c
deleted file mode 100644 (file)
index 4f3aa08..0000000
--- a/setup.c
+++ /dev/null
@@ -1,1910 +0,0 @@
-/*
- * Copyright (c) 2000, Red Hat, Inc.
- *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     A copy of the GNU General Public License can be found at
- *     http://www.gnu.org/
- *
- * Written by Ron Parker <parkerrd@hotmail.com>
- *
- */
-
-#include <windows.h>
-#include <wininet.h>
-#include <assert.h>
-#include <ctype.h>
-#include <direct.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <io.h>
-#include <shellapi.h>
-#include <shlguid.h>
-#include <shlobj.h>
-#include <stdio.h>
-#include <time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdarg.h>
-#include <signal.h>
-#include <process.h>
-
-#include "setup.h"
-#include "strarry.h"
-#include "zlib/zlib.h"
-#include "cygcalls.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 23
-#define SCREEN_COLS 80
-#define COMMAND9X "command.com /E:4096 /c "
-
-#ifndef NFILE_LIST
-#define NFILE_LIST 10000
-#endif
-
-#ifndef NFILE_SLOP
-#define NFILE_SLOP 20
-#endif
-
-char *wd = NULL;
-static char *tarpgm;
-
-static char *tar_map[8];
-
-static int downloaddir (SA *installme, const char *url);
-
-static SA files = {NULL, 0, 0};
-static FILE *logfp = NULL;
-static HANDLE devnull = NULL;
-static HINTERNET session = NULL;
-static SA deleteme = {NULL, 0, 0};
-static pkg *pkgstuff;
-static int updating = 0;
-static int download_only = 0;
-static SA installme = {NULL, 0, 0};
-static HANDLE hMainThread;
-static char *root;
-static int mount_text = 0;
-
-static void
-cleanup (void)
-{
-  int i, j;
-#if 0
-  extern void exit_cygpath (void);
-  exit_cygpath ();
-#endif
-  cygcall_unload_dll ();
-  for (i = deleteme.count; --i >= 0; )
-    for (j = 0; !DeleteFile (deleteme.array[i]) && j < 20; j++)
-      Sleep (1);
-  sa_cleanup (&deleteme);
-}
-
-static void
-cleanup_on_signal (int sig __attribute__ ((unused)))
-{
-  chdir (wd);
-  _chdrive (toupper (*wd) - 'A' + 1);
-  fprintf (stderr, "\n*Exit*\r\n");
-  SuspendThread (hMainThread);
-  cleanup ();
-  /* I have no idea why this is necessary but, without this, code
-     seems to continue executing in the main thread even after
-     the ExitProcess??? */
-  TerminateThread (hMainThread, 1);
-  ExitProcess (1);
-}
-
-#define TARGZ_SIZE (sizeof ("tar.gz") - 1)
-static char *
-istargz (char *fn)
-{
-  size_t len = strlen (fn);
-  static char stem[16384];
-
-  if (len > sizeof (".tar.gz") &&
-      stricmp (fn + (len -= TARGZ_SIZE), "tar.gz") == 0)
-    {
-      char *p;
-      memcpy (stem, fn, len);
-      p = stem + len;
-      if (strchr ("._-", p[-1]))
-       p--;
-      *p = '\0';
-      return stem;
-    }
-
-  return NULL;
-}
-
-void
-warning (const char *fmt, ...)
-{
-  va_list args;
-  va_start (args, fmt);
-  vfprintf (stderr, fmt, args);
-  if (logfp)
-    vfprintf (logfp, fmt, args);
-}
-
-static int
-create_shortcut (const char *target, const char *shortcut)
-{
-  HRESULT hres;
-  IShellLink *sl;
-  char *path, *args;
-
-  if (!SUCCEEDED (CoInitialize (NULL)))
-    return 0;
-
-  hres =
-    CoCreateInstance (&CLSID_ShellLink, NULL,
-                     CLSCTX_INPROC_SERVER, &IID_IShellLink, (LPVOID *) & sl);
-  if (SUCCEEDED (hres))
-    {
-      IPersistFile *pf;
-      int quoted = 0;
-      char *c;
-
-      /* Get the command only. */
-      path = xstrdup (target);
-      for (c = path; quoted || (*c != ' ' && *c); ++c)
-       {
-         if (*c == '\"')
-           quoted = !quoted;
-       }
-      if (*c)
-       {
-         *c = '\0';
-         args = c + 1;
-       }
-      else
-       args = "";
-
-      sl->lpVtbl->SetPath (sl, path);
-      sl->lpVtbl->SetArguments (sl, args);
-      xfree (path);
-
-      hres = sl->lpVtbl->QueryInterface (sl, &IID_IPersistFile, (void **) &pf);
-
-      if (SUCCEEDED (hres))
-       {
-         WCHAR widepath[_MAX_PATH];
-
-         // Ensure that the string is Unicode.
-         MultiByteToWideChar (CP_ACP, 0, shortcut, -1, widepath, MAX_PATH);
-
-         // Save the link by calling IPersistFile::Save.
-         hres = pf->lpVtbl->Save (pf, widepath, TRUE);
-         pf->lpVtbl->Release (pf);
-       }
-      sl->lpVtbl->Release (sl);
-    }
-
-  CoUninitialize ();
-
-  return SUCCEEDED (hres);
-}
-
-BOOL CALLBACK
-output_file (HMODULE h __attribute__ ((unused)),
-            LPCTSTR type __attribute__ ((unused)),
-            LPTSTR name, LONG lparam __attribute__ ((unused)))
-{
-  HRSRC rsrc;
-  HGLOBAL res;
-  char *data;
-  FILE *out = NULL;
-  BOOL retval = FALSE;
-
-  size_t bytes_needed;
-  if ((rsrc = FindResource (NULL, name, "FILE"))
-      && (res = LoadResource (NULL, rsrc))
-      && (data = (char *) LockResource (res)) && (out = fopen (strlwr (name), "w+b")))
-    {
-      gzFile gzf;
-      char *buffer;
-      size_t bytes = SizeofResource (NULL, rsrc);
-
-      if (bytes != fwrite (data, 1, bytes, out))
-       warning ("Unable to write %s: %s", name, _strerror (""));
-
-      bytes_needed = *(int *) ((char *) data + bytes - sizeof (int));
-      buffer = (char *) xmalloc (bytes_needed);
-
-      rewind (out);
-      gzf = gzdopen (_dup (fileno (out)), "rb");
-      if (gzf && (size_t) gzread (gzf, buffer, bytes_needed) == bytes_needed)
-       {
-         if (fseek (out, 0, SEEK_SET)
-             || fwrite (buffer, 1, bytes_needed, out) != bytes_needed)
-           {
-             warning ("Unable to write decompressed file to %s: %s",
-                     name, _strerror (""));
-           }
-         else
-           retval = TRUE;
-       }
-      else
-       {
-         int errnum;
-         const char *msg = gzerror (gzf, &errnum);
-         warning ("bytes_needed = %d, ", bytes_needed);
-         warning ("Unable to decompress %s: Error #%d, %s\n", name,
-                 errnum, msg);
-       }
-      xfree (buffer);
-      if (gzf)
-       gzclose (gzf);
-      fclose (out);
-      sa_add (&deleteme, name);
-    }
-  else
-    {
-      warning ("Unable to write %s: %s", name, _strerror (""));
-    }
-
-  return retval;
-}
-
-/* copied from zlib/gzio.c */
-static int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
-
-/* gzip flag byte */
-#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
-#define HEAD_CRC     0x02 /* bit 1 set: header CRC present */
-#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
-#define COMMENT      0x10 /* bit 4 set: file comment present */
-#define RESERVED     0xE0 /* bits 5..7: reserved */
-
-static char *
-skip_gzip_header(char *data)
-{
-  int method; /* method byte */
-  int flags;  /* flags byte */
-  uInt len;
-  int c;
-
-  c = *data++; /* magic */
-  c = *data++;
-  method = *data++;
-  flags = *data++;
-
-  /* Discard time, xflags and OS code: */
-  data += 6;
-
-  if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
-    len  =  (uInt)*data++;
-    len += ((uInt)*data++)<<8;
-    data += len;
-  }
-  if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
-    while (*data++ != 0) ;
-  }
-  if ((flags & COMMENT) != 0) {   /* skip the .gz file comment */
-    while (*data++ != 0) ;
-  }
-  if ((flags & HEAD_CRC) != 0) {  /* skip the header crc */
-    data += 2;
-  }
-  return data;
-}
-
-static void
-save_resource_as_file (char *resource_name, char *file_name)
-{
-  z_stream z;
-  size_t size;
-  HRSRC rsrc;
-  HGLOBAL res;
-  char *data;
-  char buffer[65536];
-  int zr, i, j;
-  FILE *out;
-
-  rsrc = FindResource (NULL, resource_name, "FILE");
-  if (!rsrc)
-    {
-      fprintf (stderr, "error: cannot find file %s in resources\n", resource_name);
-      exit (1);
-    }
-  res = LoadResource (NULL, rsrc);
-
-  out = fopen (file_name, "wb");
-  if (!out)
-    {
-      fprintf (stderr, "error: unable to write to %s\n", file_name);
-      perror ("the error was");
-      exit (1);
-    }
-
-  memset (&z, 0, sizeof(z));
-  data = (char *) LockResource (res);
-  z.next_in = skip_gzip_header (data);
-  z.avail_in = SizeofResource (NULL, rsrc) - ((char *)z.next_in-data);
-  z.zalloc = Z_NULL;
-  z.zfree = Z_NULL;
-  z.data_type = Z_BINARY;
-  
-  inflateInit2 (&z, -MAX_WBITS);
-
-  zr = Z_OK;
-  while (zr == Z_OK)
-    {
-      z.next_out = buffer;
-      z.avail_out = sizeof (buffer);
-
-      switch (zr = inflate (&z, 0))
-       {
-       case Z_OK:
-       case Z_STREAM_END:
-         i = sizeof (buffer) - z.avail_out;
-         j = fwrite (buffer, 1, i, out);
-         if (j < i)
-           {
-             fprintf (stderr, "error: out of disk space writing to %s\n", file_name);
-             exit (1);
-           }
-         break;
-
-       default:
-         fprintf (stderr, "error decompressing %s: %s\n", resource_name, z.msg);
-         exit (1);
-       }
-    }
-
-  inflateEnd (&z);
-  fclose (out);
-}
-
-static void
-xumount (const char *mountexedir, const char *unixpath)
-{
-  umount (unixpath);
-}
-
-extern FILE * _tar_vfile;
-extern int _tar_verbose;
-
-static int
-tarx (const char *dir, const char *fn)
-{
-  char *path, *dpath;
-  char buffer0[2049];
-  char *buffer = buffer0 + 1;
-  int hpipe[2];
-  HANDLE hin;
-  HANDLE hproc;
-  FILE *fp;
-  unsigned filehere;
-  char *pkgname, *pkgversion;
-  pkg *pkg;
-
-  if (strnicmp (fn, "cygwin-20000301", sizeof ("cygwin-20000301") - 1) == 0)
-    normalize_version ("cygwin-1.1.0.tar.gz", &pkgname, &pkgversion);
-  else
-    normalize_version (fn, &pkgname, &pkgversion);
-  pkg = find_pkg (pkgstuff, pkgname);
-  if (!newer_pkg (pkg, pkgversion))
-    {
-      warning ("Skipped extraction of %s since newer version is installed\n", fn);
-      return 1;
-    }
-
-  printf ("Installing %s\n", fn);
-
-  dpath = pathcat (dir, fn);
-  _tar_vfile = logfp;
-  _tar_verbose = 2;
-  return !tar_auto (dpath, tar_map);
-}
-
-static int
-refmatches (SA *installme, char *ref, char *refend)
-{
-  unsigned i;
-  char *p, *q;
-  char filebuf[4096];
-  if (!installme->count)
-    return 1;
-
-  for (p = ref; (q = strchr (p, '/')) != refend; p = q + 1)
-    continue;
-
-  strcpy (filebuf, p);
-  strchr (filebuf, '\0')[-1] = '\0';
-  for (i = 0; i < installme->count; i++)
-    if (stricmp (installme->array[i], filebuf) == 0)
-      return 1;
-
-  return 0;
-}
-
-static int
-filematches (SA *installme, char *fn)
-{
-  unsigned i;
-
-  if (!installme->count)
-    return 1;
-
-  for (i = 0; i < installme->count; i++)
-    if (strnicmp (installme->array[i], fn, strlen (installme->array[i])) == 0)
-      return 1;
-
-  return 0;
-}
-
-static int
-recurse_dirs (SA *installme, const char *dir)
-{
-  int err = 0;
-  int retval = 0;
-
-  char *pattern = pathcat (dir, "*");
-  if (pattern)
-    {
-      WIN32_FIND_DATA find_data;
-      HANDLE handle;
-
-      handle = FindFirstFile (pattern, &find_data);
-      if (handle != INVALID_HANDLE_VALUE)
-       {
-         /* Recurse through all subdirectories */
-         do
-           {
-             if (strcmp (find_data.cFileName, ".") == 0
-                 || strcmp (find_data.cFileName, "..") == 0
-                 || !filematches (installme, find_data.cFileName))
-               continue;
-
-             if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
-                 /* && strlen(find_data.cFileName) */ )
-               {
-                 char *subdir = pathcat (dir, find_data.cFileName);
-                 if (subdir)
-                   {
-                     if (!recurse_dirs (installme, subdir))
-                       {
-                         xfree (subdir);
-                         err = 1;
-                         break;
-                       }
-
-                     xfree (subdir);
-                   }
-                 else
-                   lowmem ();
-               }
-           }
-         while (FindNextFile (handle, &find_data) && !err);
-         FindClose (handle);
-
-         /* Look for .tar.gz files */
-         if (!err)
-           {
-             xfree (pattern);
-             pattern = pathcat (dir, "*.gz");
-             handle = FindFirstFile (pattern, &find_data);
-             if (handle != INVALID_HANDLE_VALUE)
-               {
-                 int err = 0;
-
-                 do
-                   {
-                     char *bat;
-                     /* Skip source archives and meta-directories */
-                     if (strstr (find_data.cFileName, "-src") != 0
-                         || strcmp (find_data.cFileName, ".") == 0
-                         || strcmp (find_data.cFileName, "..") == 0
-                         || !(bat = istargz (find_data.cFileName))
-                         || !filematches (installme, find_data.cFileName))
-                       {
-                         continue;
-                       }
-
-                     if (!tarx (dir, find_data.cFileName))
-                       {
-                         err = 1;
-                         break;
-                       }
-#ifdef USE_BATFILE
-                     strcat (bat, ".bat");
-                     if (access (bat, 00))
-                       {
-                         sprintf (strchr (bat, '\0'), " \"%s\"", root);
-                         (void) xcreate_process (1, NULL, NULL, NULL, bat);
-                       }
-#endif
-                   }
-                 while (FindNextFile (handle, &find_data));
-                 FindClose (handle);
-               }
-             if (!err)
-               retval = 1;
-           }
-       }
-
-      xfree (pattern);
-    }
-  else
-    lowmem ();
-
-  return retval;
-}
-
-static void
-setpath (const char *element)
-{
-  char *buffer = xmalloc (strlen (element) + 7);
-
-  sprintf (buffer, "PATH=%s", element);
-  putenv (buffer);
-
-  xfree (buffer);
-}
-
-static char *
-prompt (const char *text, const char *def)
-{
-  char buffer[_MAX_PATH];
-
-  printf ((def ? "%s? [%s] " : "%s? "), text, def);
-  fflush (stdout);
-  fgets (buffer, sizeof (buffer), stdin);
-  buffer[strcspn (buffer, "\r\n")] = '\0';
-
-  /* Duplicate the entered value or the default if nothing was entered. */
-  return xstrdup (strlen (buffer) ? buffer : def ? def : "");
-}
-
-static int
-optionprompt (const char *text, SA * options)
-{
-  size_t n, c, ncols, response = -1;
-  char buf[5];
-  size_t base;
-  int maxwidth=0, skip, percol;
-  int screen_lines = SCREEN_LINES;
-
-  for (n=0; n<options->count; n++)
-    {
-      int sl = strlen(options->array[n]);
-      if (maxwidth < sl)
-       maxwidth = sl;
-    }
-
-  ncols = SCREEN_COLS / (maxwidth + 5);
-  skip = (options->count + ncols - 1) / ncols;
-  percol = SCREEN_COLS / ncols;
-
-  if (options->count < ncols * screen_lines)
-    screen_lines = (options->count+ncols-1)/ncols;
-
-  base = 0;
-
-  puts (text);
-
-  while (1)
-    {
-      char *repeat, *enter;
-
-      for (n = 0; n < screen_lines; n++)
-       {
-         if (n + base >= options->count)
-           break;
-         for (c = 0; c < ncols; c++)
-           {
-             unsigned i = n + base + c * screen_lines;
-             if (i < options->count)
-               printf ("%2d. %-*s", i + 1, percol - 5, options->array[i]);
-           }
-         printf ("\n");
-       }
-
-      repeat = enter = "";
-      if (skip > screen_lines)
-       {
-         if (base)
-           repeat = " or `R' to repeat the list";
-         if (base + screen_lines * ncols < options->count)
-           enter = " or [Enter] for more options";
-       }
-
-      printf ("Select an option from 1-%d%s%s: ", options->count, repeat, enter);
-      if (!fgets (buf, sizeof (buf), stdin))
-       {
-         /* This can only mean end-of-file, user has gone away */
-         exit(1);
-       }
-
-      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')
-       {
-         if (base + screen_lines * ncols < options->count)
-           base += screen_lines * ncols;
-       }
-      if (buf[0] == 'r' || buf[0] == 'R')
-       base = 0;
-
-    }
-}
-
-static int
-geturl (const char *url, const char *file, int verbose)
-{
-  DWORD type, size;
-  int authenticated = 0;
-  int retval = 0;
-  static HINTERNET connect;
-  int tries = 20;
-  int is_ftp = strnicmp (url, "ftp", 3) == 0;
-  static int saw_first_ftp = 0;
-  char connect_buffer[1024];
-
-  if (saw_first_ftp)
-    verbose = 0;
-  else if (verbose)
-    {
-      const char *hosthere, *hostend;
-      int n;
-
-      hosthere = strstr (url, "//");
-      if (!hosthere)
-       hosthere = url; /* huh? */
-      else
-       hosthere += 2;
-
-      hostend = strchr (hosthere + 1, '/');
-      if (!hostend)
-       hostend = strchr (hosthere + 1, '\0');
-      n = hostend - hosthere;
-      sprintf (connect_buffer, "Connecting to %.*s...", n, hosthere);
-      fputs (connect_buffer, stdout);
-      fflush (stdout);
-      if (is_ftp)
-       saw_first_ftp = 1;
-    }
-
-  for (tries = 1; tries <= 40; tries++)
-    {
-      DWORD flags = INTERNET_FLAG_DONT_CACHE |
-                   INTERNET_FLAG_KEEP_CONNECTION |
-                   INTERNET_FLAG_PRAGMA_NOCACHE |
-                   INTERNET_FLAG_RELOAD;
-
-      if (is_ftp)
-       flags |=    INTERNET_FLAG_EXISTING_CONNECT |
-                   INTERNET_FLAG_PASSIVE;
-
-      connect = InternetOpenUrl (session, url, NULL, 0, flags, 0);
-      if (connect)
-       break;
-      if (!verbose || tries == 1)
-       /* nothing */;
-      else if (tries > 2)
-       printf ("\r%s(try %d)  \b\b", connect_buffer, tries);
-      else
-       printf ("\r%s(try %d)", connect_buffer, tries);
-    }
-
-  if (!connect)
-    {
-      puts ("\nCouldn't connect to ftp site."); fflush (stdout);
-      winerror ();
-    }
-  else
-    {
-      if (verbose)
-       {
-         if (tries > 1)
-           printf ("\r%s        \r", connect_buffer);
-         printf ("Done.\n"); fflush (stdout);
-       }
-      while (!authenticated)
-       {
-         size = sizeof (type);
-         if (!InternetQueryOption
-             (connect, INTERNET_OPTION_HANDLE_TYPE, &type, &size))
-           {
-             winerror ();
-             return 0;
-           }
-         else
-           switch (type)
-             {
-             case INTERNET_HANDLE_TYPE_HTTP_REQUEST:
-             case INTERNET_HANDLE_TYPE_CONNECT_HTTP:
-               size = sizeof (DWORD);
-               if (!HttpQueryInfo
-                   (connect, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
-                    &type, &size, NULL))
-                 {
-                   winerror ();
-                   return 0;
-                 }
-               else if (type == HTTP_STATUS_PROXY_AUTH_REQ)
-                 {
-                   DWORD len;
-
-                   if (!InternetQueryDataAvailable (connect, &len, 0, 0))
-                     {
-                       winerror ();
-                       return 0;
-                     }
-                   else
-                     {
-                       char *user, *password;
-
-                       /* Have to read any pending data, WININET peculiarity. */
-                       char *buffer = xmalloc (len);
-                       do
-                         {
-                           InternetReadFile (connect, buffer, len, &size);
-                         }
-                       while (size);
-                       xfree (buffer);
-
-                       puts ("Proxy authentication is required.\n");
-
-                       user = prompt ("Proxy username", NULL);
-                       if (!InternetSetOption
-                           (connect, INTERNET_OPTION_PROXY_USERNAME, user,
-                            strlen (user)))
-                         {
-                           xfree (user);
-                           winerror ();
-                           return 0;
-                         }
-                       else
-                         {
-                           xfree (user);
-                           password = prompt ("Proxy password", NULL);
-                           if (!InternetSetOption
-                               (connect, INTERNET_OPTION_PROXY_PASSWORD,
-                                password,
-                                strlen (password))
-                               || !HttpSendRequest (connect, NULL, 0, NULL, 0))
-                             {
-                               xfree (password);
-                               winerror ();
-                               return 0;
-                             }
-                           xfree (password);
-                         }
-                     }
-                 }
-               else if (type != HTTP_STATUS_OK)
-                 {
-                   warning ("Error retrieving \"%s\".\n", url);
-                   return 0;
-                 }
-               else
-                 authenticated = 1;
-               break;
-
-             default:
-               authenticated = 1;
-               break;
-             }
-
-         /* Now that authentication is complete read the file. */
-         if (!InternetQueryDataAvailable (connect, &size, 0, 0))
-           winerror ();
-         else
-           {
-             char status[50];
-             static char *bs[50] = {0};
-             int total = 0;
-             char *buffer;
-             FILE *out;
-             DWORD start_time, cur_time, delta_time;
-
-             if (bs[0] == 0)
-               memset(bs, '\b', sizeof(bs));
-
-             if (size < 1024) /* optimize */
-               size = 1024;
-             buffer = xmalloc (size);
-
-             out = fopen (file, "wb");
-             if (!out)
-               warning ("Unable to open \"%s\" for output: %s\n", file,
-                       _strerror (""));
-             else
-               {
-                 status[0] = 0;
-                 start_time = GetTickCount ();
-                 for (;;)
-                   {
-                     DWORD readbytes;
-
-                     if (!InternetReadFile (connect, buffer, size, &readbytes))
-                       winerror ();
-                     else if (!readbytes)
-                       {
-                         retval = 1;
-                         break;
-                       }
-                     else if (fwrite (buffer, 1, readbytes, out) != readbytes)
-                       {
-                         warning ("Error writing \"%s\": %s\n", file,
-                                 _strerror (""));
-                         break;
-                       }
-                     total += readbytes;
-                     delta_time = GetTickCount () - start_time;
-
-                     if (delta_time > 5000)
-                       {
-                         int kbps = (total+500) / delta_time;
-                         sprintf(status, "  %dk %dk/s", total / 1024, kbps);
-                         printf("%s%.*s", status, strlen(status), bs);
-                       }
-                   }
-                 if (status[0])
-                   printf("%*c%.*s", strlen(status), ' ', strlen(status), bs);
-                 fclose (out);
-               }
-             xfree (buffer);
-           }
-
-         InternetCloseHandle (connect);
-         connect = NULL;
-       }
-    }
-
-  return retval;
-}
-
-static char *
-findhref (char *buffer, char *date __attribute__ ((unused)),
-         size_t *filesize)
-{
-  char *ref = NULL;
-  char *anchor = NULL;
-  char *p;
-  int eatspace;
-  char *q;
-  char digits[20];
-  char *diglast = digits + sizeof (digits) - 1;
-  int len;
-
-  p = buffer;
-  while ((p = strchr (p, '<')) != NULL)
-    {
-      char *q = p;
-      char ch = *++p;
-
-      if (tolower (ch) != 'a')
-       continue;
-
-      ch = *++p;
-      if (!isspace (ch))
-       continue;
-
-      for (++p; isspace (*p); p++)
-       continue;
-
-      if (strnicmp (p, "href=", 5) == 0)
-       {
-         ref = p;
-         anchor = q;
-       }
-    }
-
-  if (!ref)
-    return NULL;
-
-  ref += ref[5] == '"' ? 6 : 5;
-
-  len = strcspn (ref, "\" >");
-
-  ref[len] = '\0';
-  if (!filesize)
-    goto out;
-
-  *filesize = 0;
-
-  if (anchor == buffer || !isspace (anchor[-1]))
-    goto out;
-
-  eatspace = 1;
-  *diglast = '\0';
-  for (p = anchor, q = diglast; --p >= buffer; )
-    if (!isspace (*p))
-      {
-       eatspace = 0;
-       if (isdigit (*p))
-         *--q = *p;
-      }
-    else if (!eatspace)
-      break;
-
-  if (q < diglast)
-    *filesize = atoi (q);
-
-out:
-  if (!*ref)
-    return NULL;
-  /* This effectively disallows using a ';' in a file name.  Hopefully,
-     this will not be an issue. */
-  if ((p = strrchr (ref, ';')) != NULL)
-    *p = '\0';
-  return *ref ? ref : NULL;
-}
-
-static int
-needfile (const char *filename, char *date __attribute__ ((unused)),
-         size_t filesize)
-{
-  struct _stat st;
-
-  if (!filesize || _stat (filename, &st))
-    return 1;  /* file doesn't exist or is somehow not accessible */
-  return (size_t) st.st_size != filesize;
-}
-
-static int
-processdirlisting (SA *installme, const char *urlbase, const char *file)
-{
-  int retval = 0;
-  char buffer[4096];
-  static enum {UNKNOWN, ALWAYS, NEVER} download_when = {UNKNOWN};
-  size_t urllen = strlen (urlbase);
-
-  FILE *in = fopen (file, "rt");
-
-  while (fgets (buffer, sizeof (buffer), in))
-    {
-      size_t filesize;
-      char filedate[80];
-      char *ref = findhref (buffer[0] ? buffer : buffer + 1, filedate, &filesize);
-      char url[256];
-      DWORD urlspace = sizeof (url);
-      char *refend;
-
-      if (!ref || strnicmp (ref, "http:", 5) == 0)
-       continue;
-
-      if (!InternetCombineUrl
-         (urlbase, ref, url, &urlspace,
-          ICU_BROWSER_MODE | ICU_ENCODE_SPACES_ONLY | ICU_NO_META))
-       {
-         warning ("Unable to download from %s", ref);
-         winerror ();
-       }
-      else if (strlen (url) == urllen || strnicmp (urlbase, url, urllen) != 0
-              || strstr (url, "/.") || strstr (url, "./"))
-       continue;
-
-      refend = ref + strlen (ref) - 1;
-      if (*refend == '/')
-       {
-         if (refmatches (installme, ref, refend))
-           retval += downloaddir (installme, url);
-       }
-      else if (istargz (url) && !strstr (url, "-src"))
-       {
-         int download = 0;
-         char *filename = strrchr (url, '/') + 1;
-         char *pkgname, *pkgversion;
-         pkg *pkg;
-
-         if (!filematches (installme, filename))
-           continue;
-
-         retval++;
-
-         if (!download_only)
-           {
-             if (strnicmp (filename, "cygwin-20000301", sizeof ("cygwin-20000301") - 1) == 0)
-               normalize_version ("cygwin-1.1.0.tar.gz", &pkgname, &pkgversion);
-             else
-               normalize_version (filename, &pkgname, &pkgversion);
-             pkg = find_pkg (pkgstuff, pkgname);
-
-             if (!newer_pkg (pkg, pkgversion))
-               {
-                 warning ("Skipped download of %s\n", filename);
-                 continue;
-               }
-           }
-
-         if (download_when == ALWAYS || needfile (filename, filedate, filesize))
-           download = 1;
-         else
-           {
-             char text[_MAX_PATH];
-             char *answer;
-
-             if (download_when == NEVER)
-               answer = xstrdup ("N");
-             else
-               {
-                 sprintf (text, "Replace %s from the Internet (ynAN)", filename);
-                 answer = prompt (text, "y");
-               }
-
-             if (answer)
-               {
-                 switch (*answer)
-                   {
-                   case 'a':
-                   case 'A':
-                     download_when = ALWAYS;
-                     /* purposely fall through */
-                   case 'y':
-                   case 'Y':
-                     download = 1;
-                     break;
-                   case 'N':
-                     download_when = NEVER;
-                     warning ("Skipped download of %s\n", filename);
-                   case 'n':
-                   default:
-                     download = 0;
-                   }
-                 xfree (answer);
-               }
-           }
-
-         if (!download)
-           continue;
-
-         for (;;)              /* file retrieval loop */
-           {
-             int res;
-             warning ("Downloading: %s...", filename);
-             fflush (stdout);
-             res = geturl (url, filename, 0);
-             if ((res && !filesize) || !needfile (filename, filedate, filesize))
-               warning ("Done.\n");
-             else
-               {
-                 for (;;)      /* prompt loop */
-                   {
-                     char a;
-                     char *answer;
-                     if (!res)
-                       warning ("Download failed.\n");
-                     else
-                       fprintf (logfp, "Downloaded file size does not match (%d).\n",
-                                filesize);
-                     answer = prompt (res ? "Downloaded file size does not match (Abort, Retry, Fail)" :
-                                            "Download failed (Abort, Retry, Fail)", "R");
-                     a = toupper (*answer);
-                     xfree (answer);
-                     switch (a)
-                       {
-                       case 'R':
-                         break;        /* try it again */
-                       case 'A':
-                         exit (1);     /* abort program */
-                       case 'F':
-                         warning ("Deleting %s.\n", filename);
-                         _unlink (filename);
-                         goto noget;   /* Keep trying to download the rest */
-                       default:
-                         continue;     /* erroneous response */
-                       }
-
-                     break;    /* from prompt loop */
-                   }
-               }
-
-           noget:
-             break;            /* Leave from file retrieval for loop.
-                                  Either we successfully downloaded the file
-                                  or the user said don't bother. */
-           }
-       }
-    }
-
-  fflush (stdout);
-  fclose (in);
-
-  return retval;
-}
-
-static char *
-tmpfilename ()
-{
-  char *rv = _tempnam (NULL, "su");
-  sa_add (&deleteme, rv);
-  return rv;
-}
-
-static int
-downloaddir (SA *installme, const char *url)
-{
-  int retval = 0;
-  char *file = tmpfilename ();
-
-  if (geturl (url, file, 1))
-    retval = processdirlisting (installme, url, file);
-  _unlink (file);
-  xfree (file);
-
-  return retval;
-}
-
-static HINTERNET
-opensession ()
-{
-  return InternetOpen ("Cygwin Setup", INTERNET_OPEN_TYPE_PRECONFIG, NULL,
-                      NULL, 0);
-}
-
-static int
-downloadfrom (SA *installme, const char *url)
-{
-  int retval = 0;
-  char *file = tmpfilename ();
-
-  if (geturl (url, file, 1))
-    retval = processdirlisting (installme, url, file);
-  _unlink (file);
-
-  xfree (file);
-
-  return retval;
-}
-
-static int
-reverse_sort (const void *arg1, const void *arg2)
-{
-  return -strcmp (*(char **) arg1, *(char **) arg2);
-}
-
-static int
-create_uninstall (const char *folder, const char *shellscut,
-                 const char *shortcut)
-{
-  int retval = 0;
-
-  warning ("Creating the uninstall file...");
-  fflush (stdout);
-  if (files.array)
-    {
-      size_t n;
-      FILE *uninst;
-      char cwd[MAX_PATH];
-      char *uninstfile;
-
-      getcwd (cwd, sizeof (cwd));
-      uninstfile = pathcat (cwd, "uninst.bat");
-      uninst = fopen (uninstfile, "wt");
-
-      if (uninst)
-       {
-         struct _stat st;
-
-         files.array[++files.index] = pathcat (cwd, "bin\\cygwin.bat");
-         files.count = files.index + 1;
-         qsort (files.array, files.count, sizeof (char *), reverse_sort);
-
-         fprintf (uninst,
-                  "@echo off\n" "%c:\n" "cd \"%s\"\n", *cwd, cwd);
-         fprintf (uninst, "bin\\regtool remove '/HKLM/SOFTWARE/Cygnus Solutions/cygwin/Installed Components'\n");
-         for (n = 0; n < files.count; ++n)
-           {
-             char *dpath;
-
-             if (n && !strcmp (files.array[n], files.array[n - 1]))
-               continue;
-
-             dpath = files.array[n];
-
-             if (_stat (dpath, &st) == 0 && st.st_mode & _S_IFDIR)
-               fprintf (uninst, "rmdir \"%s\"\n", dpath);
-             else
-               {
-                 if (access (dpath, 6) != 0)
-                   fprintf (uninst, "attrib -r \"%s\"\n", dpath);
-                 fprintf (uninst, "del \"%s\"\n", dpath);
-               }
-           }
-         fprintf (uninst,
-                  "del \"%s\"\n"
-                  "del \"%s\"\n"
-                  "rmdir \"%s\"\n"
-                  "del %s\n", shortcut, shellscut,
-                  folder, uninstfile);
-         fclose (uninst);
-
-         create_shortcut (uninstfile, shortcut);
-       }
-      sa_cleanup (&files);
-      retval = 1;
-    }
-
-  warning ("Done.\n");
-  return retval;
-}
-
-/* Writes the startup batch file. */
-static int
-do_start_menu (void)
-{
-  FILE *batch;
-  char *batch_name = pathcat (root, "bin\\cygwin.bat");
-  int retval = 0;
-
-  /* Create the batch file for the start menu. */
-  if (batch_name)
-    {
-      batch = fopen (batch_name, "wt");
-      if (batch)
-       {
-         LPITEMIDLIST progfiles;
-         char pfilespath[_MAX_PATH];
-         char *folder;
-         char *bindir = pathcat (root, "bin");
-         char *locbindir = pathcat (root, "usr\\local\\bin");
-
-         fprintf (batch,
-                  "@echo off\n"
-                  "SET MAKE_MODE=unix\n"
-                  "SET PATH=%s;%s;%%PATH%%\n"
-                  "bash\n", bindir, locbindir);
-         fclose (batch);
-         xfree (bindir);
-         xfree (locbindir);
-
-         /* Create a shortcut to the batch file */
-         SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &progfiles);
-         SHGetPathFromIDList (progfiles, pfilespath);
-
-         folder = pathcat (pfilespath, "Cygnus Solutions");
-         if (folder)
-           {
-             char *shortcut;
-             mkdir (folder);   /* Ignore the result, it may exist. */
-
-             shortcut = pathcat (folder, "Cygwin 1.1.0.lnk");
-             if (shortcut)
-               {
-                 char *cmdline;
-                 OSVERSIONINFO verinfo;
-                 verinfo.dwOSVersionInfoSize = sizeof (verinfo);
-
-                 /* If we are running Win9x, build a command line. */
-                 GetVersionEx (&verinfo);
-                 if (verinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
-                   cmdline = xstrdup (batch_name);
-                 else
-                   {
-                     char *pccmd;
-                     char windir[MAX_PATH];
-                     GetWindowsDirectory (windir, sizeof (windir));
-
-                     pccmd = pathcat (windir, COMMAND9X);
-                     cmdline =
-                       xmalloc (strlen (pccmd) + strlen (batch_name) + 1);
-                     strcat (strcpy (cmdline, pccmd), batch_name);
-                     xfree (pccmd);
-                   }
-
-                 if (create_shortcut (cmdline, shortcut)
-                     && (!updating || installme.count))
-                   {
-                     char *uninstscut =
-                       pathcat (folder, "Uninstall Cygwin 1.1.0.lnk");
-                     if (uninstscut)
-                       {
-                         if (create_uninstall (folder, shortcut, uninstscut))
-                           retval = 1;
-                         xfree (uninstscut);
-                       }
-                   }
-                 xfree (cmdline);
-                 xfree (shortcut);
-               }
-             xfree (folder);
-           }
-       }
-      xfree (batch_name);
-    }
-  return retval;
-}
-
-static char *
-getdownloadsource ()
-{
-  char *retval = NULL;
-  char *filename = tmpfilename ();
-
-  /* Initialize session one time and one time only */
-  session = opensession ();
-
-  if (!session)
-    {
-      winerror ();
-      exit (1);
-    }
-
-  if (!geturl (MIRRORFILE, filename, 1))
-    fputs ("Unable to retrieve the list of cygwin mirrors.\n", stderr);
-  else
-    {
-      FILE *in = fopen (filename, "rt");
-
-      if (!in)
-       warning ("Unable to open %s for input.\n", filename);
-      else
-       {
-         size_t option;
-         int ready4urls = 0;
-         char buf[256];
-         SA urls, names;       /* These must stay sync'd. */
-
-         sa_init (&urls);
-         sa_init (&names);
-
-         while (fgets (buf, sizeof (buf), in))
-           {
-             if (!ready4urls)
-               {
-                 if (strstr (buf, "Mirror Sites:"))
-                   ready4urls = 1;
-               }
-             else
-               {
-                 char *ref = findhref (buf, NULL, NULL);
-
-                 if (ref)
-                   {
-                     size_t len = strlen (ref);
-
-                     if (ref[len - 1] == '/')
-                       {
-                         char *name;
-                         char *url = xmalloc (len + 13);
-
-                         strcat (strcpy (url, ref), DOWNLOAD_SUBDIR);
-                         sa_add (&urls, url);
-
-                         /* Get just the sites name. */
-                         name = strstr (url, "//");
-                         if (name)
-                           name += 2;
-                         else
-                           name = url;
-                         *strchr (name, '/') = '\0';
-                         sa_add (&names, name);
-
-                         xfree (url);
-                       }
-                   }
-               }
-           }
-
-         fclose (in);
-         sa_add (&urls, "Other");
-         sa_add (&names, "Other");
-         option =
-           optionprompt ("Select a download location close to you:", &names);
-         if (option == urls.count - 1)
-           retval = prompt ("Download url", NULL);
-         else
-           retval = xstrdup (urls.array[option]);
-
-         sa_cleanup (&urls);
-         sa_cleanup (&names);
-       }
-    }
-  _unlink (filename);
-
-  return retval;
-}
-
-/* Basically a mkdir -p /somedir function. */
-static void
-mkdirp (const char *dir)
-{
-  if (mkdir (dir) == -1 && errno != EEXIST)
-    {
-      char *parent = strdup (dir);
-      char *slash = strrchr (parent, '\\');
-
-      if (slash)
-       {
-         *slash = '\0';
-         mkdirp (parent);
-       }
-
-      xfree (parent);
-
-      mkdir (dir);
-    }
-}
-
-/* This routine assumes that the cwd is the root directory. */
-static int
-mkmount (const char *dospath, const char *unixpath)
-{
-  char *mountd, *fulldospath;
-
-  assert (root != NULL);
-
-  if (dospath[0])
-    {
-      /* Make sure the mount point exists. */
-      mountd = pathcat (root, unixpath);
-      mkdirp (mountd);
-      xfree (mountd);
-      fulldospath = pathcat (root, dospath);
-    }
-  else
-    {
-      fulldospath = xstrdup (root);
-    }
-
-  /* Make sure the target path exists. */
-  mkdirp (fulldospath);
-
-  umount (unixpath);
-  mount (fulldospath, unixpath, mount_text ? 0 : MOUNT_BINARY);
-
-  xfree (fulldospath);
-}
-
-static pkg *
-get_pkg_stuff (int updating)
-{
-  const char *ver, *ans;
-  pkg *pkgstuff = init_pkgs (root, 0);
-
-  if (!updating || !pkgstuff)
-    {
-      extern pkg global_pkgstuff[];
-      (void) check_for_installed (root, global_pkgstuff);
-      return global_pkgstuff;
-    }
-
-  ver = check_for_installed (root, pkgstuff);
-
-  if (pkgstuff->name != NULL)
-    return pkgstuff;
-
-  if (!ver || stricmp (ver, "1.1.0") != 0)
-    return pkgstuff;
-
-  ans = prompt (
-       "\nHmm.  You seem to have a previous cygwin version installed but there is no\n"
-       "package version information in the registry.  This is probably due to the fact\n"
-       "that previous versions of setup.exe did not update this information.\n"
-       "Should I update the registry with default information now", "y");
-  puts ("");
-  if (toupper (*ans) != 'Y')
-    {
-      warning ("Not writing default package information to the registry.\n");
-      puts ("");
-      return pkgstuff;
-    }
-
-  warning ("Writing default package information to the registry.\n");
-  puts ("");
-  return use_default_pkgs (pkgstuff);
-}
-
-static void
-do_tar_map (int i, char *from, char *root, char *to)
-{
-  char *t;
-  tar_map[i] = from;
-  i++;
-  tar_map[i] = (char *) xmalloc (strlen(root) + strlen(to) + 3);
-  t = tar_map[i];
-  strcpy (t, root);
-  if (t[strlen(t)-1] == '/' && to[0] == '/')
-    to ++;
-  strcat (t, to);
-}
-
-static int
-current_directory_not_empty ()
-{
-  WIN32_FIND_DATA find_data;
-  HANDLE h = FindFirstFile ("*", &find_data);
-  int count = 0;
-  if (h != INVALID_HANDLE_VALUE)
-    do
-      {
-       DWORD fa = GetFileAttributes (find_data.cFileName);
-       int len = strlen (find_data.cFileName);
-       if (strcmp (find_data.cFileName, ".") == 0
-           || strcmp (find_data.cFileName, "..") == 0)
-         continue;
-       if (fa & FILE_ATTRIBUTE_DIRECTORY)
-         count ++;
-       if (strcmp (find_data.cFileName+len-7, ".tar.gz") == 0)
-         count ++;
-      } while (FindNextFile (h, &find_data));
-  FindClose (h);
-  return count;
-}
-
-static void
-usage ()
-{
-  printf ("\n");
-  printf ("Usage: setup [-f] [-u] [-d] [package ...]\n");
-  printf ("-f\tforce re-install\n");
-  printf ("-u\tupdate old packages\n");
-  printf ("-d\tdownload to current directory only - no install\n");
-  printf ("`package' lists packages to install/update\n");
-  printf ("\n");
-  exit (1);
-}
-
-
-static char rev[] = "$Revision$ ";
-
-int
-main (int argc, char **argv)
-{
-  int retval = 1;              /* Default to error code */
-  clock_t start;
-  char *logpath = NULL;
-  char *revn, *p;
-  int fd = _open ("nul", _O_WRONLY | _O_BINARY);
-  struct mntent *m;
-  char *defroot;
-  char *update;
-  char *tmp;
-  int done;
-  HKEY cu = NULL, lm = NULL;
-
-  while (argc > 1 && argv[1][0] == '-')
-    {
-      if (stricmp (argv[1], "-f") == 0)
-       updating = 0;
-      else if (stricmp (argv[1], "-u") == 0)
-       updating = 1;
-      else if (stricmp (argv[1], "-d") == 0)
-       download_only = 1;
-      else
-       usage ();
-      argc--;
-      argv++;
-    }
-
-  sa_init (&installme);
-  while (argc > 1)
-    {
-      sa_add (&installme, argv[1]);
-      argc--;
-      argv++;
-    }
-
-  devnull = (HANDLE) _get_osfhandle (fd);
-
-  setbuf (stdout, NULL);
-  SetEnvironmentVariable ("CYGWIN", NULL);
-  revn = strchr (rev, ':');
-  if (!revn || (p = strchr (revn + 2, ' ')) == NULL)
-    revn = "";
-  else
-    {
-      revn--;
-      memcpy (revn, " (v", 3);
-      *p = ')';
-      p[1] = '\0';
-    }
-
-  printf ( "\n\n"
-          "This is the Cygwin setup utility%s,\n"
-          "built on " __DATE__ " " __TIME__ ".  Run \"setup -h\" for command-line help.\n\n", revn);
-  
-  if (!download_only) printf (
-"Use this program to install the latest version of the Cygwin Utilities\n"
-"from the Internet.\n\n"
-"Alternatively, if you already have already downloaded the appropriate files\n"
-"to the current directory (and subdirectories below it), this program can use\n"
-"those as the basis for your installation.\n\n"
-"If you are installing from the Internet, please run this program in an empty\n"
-"temporary directory.\n\n");
-
-  start = clock ();
-  sa_init (&deleteme);
-
-  wd = _getcwd (NULL, 0);
-
-  save_resource_as_file ("cygwin1.dll", "setup-cygwin1.dll");
-  cygcall_load_dll ("setup-cygwin1.dll");
-  sa_add (&deleteme, "setup-cygwin1.dll");
-
-  setmntent (0,0);
-  defroot = 0;
-  while (m = getmntent (0))
-    {
-#if 0
-      printf ("mnt fs=%s dir=%s type=%s opts=%s freq=%d pass=%d\n",
-             m->mnt_fsname, m->mnt_dir, m->mnt_type, m->mnt_opts, m->mnt_freq, m->mnt_passno);
-#endif
-      if (strcmp (m->mnt_dir, "/") == 0)
-       {
-         defroot = xstrdup (m->mnt_fsname);
-         if (strstr (m->mnt_opts, "text"))
-           mount_text = 1;
-       }
-    }
-  if (!defroot)
-    defroot = xstrdup (DEF_ROOT);
-
-
-  setpath (wd);
-  tmp = xmalloc (sizeof ("TMP=") + strlen (wd));
-  sprintf (tmp, "TMP=%s", wd);
-  _putenv (tmp);
-
-  logpath = pathcat (wd, "setup.log");
-  tarpgm = pathcat (wd, "tar.exe");
-
-  if (logpath)
-    logfp = fopen (logpath, "wt");
-
-  if (logfp == NULL)
-    {
-      fprintf (stderr, "Unable to open log file '%s' for writing - %s\n",
-              logpath, _strerror (""));
-      exit (1);
-    }
-
-  /* Begin prompting user for setup requirements. */
-  printf ("Press <enter> to accept the default values.\n");
-
-  if (updating)
-    {
-      printf("\nNote: You have chosen to update an existing installation.\n");
-      printf("You should accept the defaults for the root mount and mode.\n");
-    }
-
-  DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
-                  GetCurrentProcess (), &hMainThread, 0, 0,
-                  DUPLICATE_SAME_ACCESS);
-  atexit (cleanup);
-  signal (SIGINT, cleanup_on_signal);
-
-  if (!download_only)
-    {
-      /* Get the root directory and warn the user if there are any spaces in
-        the path. */
-      for (done = 0; !done;)
-       {
-         root = prompt ("Root directory", defroot);
-         /* convert to windows format */
-         for (p=root; *p; p++)
-           if (*p == '/')
-             *p = '\\';
-         if (strcmpi (root, wd) == 0)
-           {
-             printf ("Please do not use the current directory as the root directory.\n"
-                     "You should run setup.exe from a temporary directory.\n");
-             continue;
-           }
-         if (strchr (root, ' '))
-           {
-             char *temp;
-             temp =
-               prompt
-               ("Using spaces in the root directory path may cause problems."
-                "  Continue anyway", "no");
-             if (toupper (*temp) == 'Y')
-               done = 1;
-             xfree (temp);
-             continue;
-           }
-         if (!isalpha (root[0]) || root[1] != ':' || (root[2] != '\\'))
-           {
-             printf ("The root directory should include a drive letter and leading\n");
-             printf ("slash, like c:\\cygwin or g:\\local\\unix\n");
-             continue;
-           }
-         if (root[3] == '\0' || root[3] == '\\')
-           {
-             char *yesno, y;
-             printf ("We strongly recommend that you DO NOT install Cygwin in the root\n");
-             printf ("of a partition.  This install will put many files in the root if\n");
-             printf ("you choose this option.\n");
-             yesno = prompt ("Are you sure you want to install there", "N");
-             y = yesno[0];
-             free (yesno);
-             if (y != 'y' && y != 'Y')
-               continue;
-           }
-         done = 1;
-       }
-      xfree (defroot);
-
-      done = 0;
-      while (!done)
-       {
-         char *resp = prompt ("Mount mode (T)ext, (B)inary, or (H)elp",
-                              mount_text ? "Text" : "Binary");
-         switch (resp[0])
-           {
-           case 't':
-           case 'T':
-             mount_text = 1;
-             done = 1;
-             break;
-           case 'b':
-           case 'B':
-             mount_text = 0;
-             done = 1;
-             break;
-           case 'h':
-           case 'H':
-           case '?':
-             printf ("\n");
-             printf ("With text mounts, files are converted to/from DOS text format\n");
-             printf ("This is more compatible with MS programs, but some unix programs\n");
-             printf ("may break when they see text files as input.\n");
-             printf ("With binary mounts, files are saved without carriage returns, which\n");
-             printf ("is best for other cygwin programs but may break MS programs\n");
-             printf ("\n");
-             break;
-           }
-       }
-    }
-
-  Sleep (0);
-
-  if (download_only)
-    update = "i";
-  else
-    {
-      pkgstuff = get_pkg_stuff (updating);
-
-      update =
-       prompt ("Install from the current directory (d) or from the Internet (i)", "i");
-    }
-
-  if (toupper (*update) == 'I')
-    {
-      char *dir;
-
-      if (!download_only && current_directory_not_empty ())
-       {
-         char *yns, yn;
-         printf ("\nThe current directory is not empty.  You should run setup in\n");
-         printf ("an empty temporary directory when installing from the\n");
-         printf ("Internet.  *Any* tar.gz file found in this directory *or* any\n");
-         printf ("subdirectory will be installed, not just files setup downloads.\n\n");
-         yns = prompt ("Use this directory anyway? [yn]", "n");
-         yn = yns[0];
-         xfree (yns);
-         if (yn != 'y' && yn != 'Y')
-           exit (1);
-       }
-
-      dir = getdownloadsource ();
-
-      if (!dir)
-       {
-         fprintf (stderr, "Couldn't connect to download site.\n");
-         exit (1);
-       }
-
-      if (!downloadfrom (&installme, dir))
-       {
-         warning ("Error: No files found to download.");
-         if (!installme.count)
-           warning("  Choose another mirror site?\n");
-         else
-           warning ("\n");
-         goto out;
-       }
-      InternetCloseHandle (session);
-      xfree (dir);
-    }
-  xfree (update);
-
-  if (! download_only)
-    {
-
-      /* Create the root directory. */
-      mkdirp (root);           /* Ignore any return value since it may
-                                  already exist. */
-
-      /* Make the root directory the current directory so that recurse_dirs
-        will * extract the packages into the correct path. */
-      if (chdir (root) == -1)
-       {
-         warning ("Unable to make \"%s\" the current directory: %s\n",
-                  root, _strerror (""));
-       }
-      else
-       {
-         FILE *fp;
-
-         _chdrive (toupper (*root) - 'A' + 1);
-
-         do_tar_map (0, "usr/bin/", root, "/bin/");
-         do_tar_map (2, "usr/lib/", root, "/lib/");
-         do_tar_map (4, "", root, "/");
-         tar_map[6] = tar_map[7] = 0;
-
-
-         mkdirp ("var\\run");
-         /* Create /var/run/utmp */
-         fp = fopen ("var\\run\\utmp", "wb");
-         if (fp)
-           fclose (fp);
-
-         files.count = NFILE_LIST;
-         files.array = calloc (sizeof (char *), NFILE_LIST + NFILE_SLOP);
-         files.index = -1;
-
-         /* Extract all of the packages that are stored with setup or in
-            subdirectories of its location */
-         if (recurse_dirs (&installme, wd))
-           {
-             /* bash expects a /tmp */
-             char *tmpdir = pathcat (root, "tmp");
-
-             if (tmpdir && mkdir (tmpdir) == 0)
-               files.array[++files.index] = tmpdir;
-
-             files.array[++files.index] = pathcat (root, "usr\\local");
-             files.array[++files.index] = pathcat (root, "usr\\local\\bin");
-             files.array[++files.index] = pathcat (root, "usr\\local\\lib");
-             files.array[++files.index] = pathcat (root, "usr\\local\\etc");
-             mkdirp (files.array[files.index]);
-             mkdir (files.array[files.index - 1]);
-             mkdir (files.array[files.index - 2]);
-
-             if (do_start_menu ())
-               retval = 0;     /* Everything worked return
-                                  successful code */
-
-             warning ("Creating mount points...");
-             umount ("/usr");
-             umount ("/var");
-             umount ("/lib");
-             umount ("/bin");
-             umount ("/etc");
-             
-             /* Make /bin point to /usr/bin and /lib point to /usr/lib. */
-             mkmount ("", "/");
-             mkmount ("bin", "/usr/bin");
-             mkmount ("lib", "/usr/lib");
-
-           }
-       }
-    }
-
-  xfree (root);
-
-  chdir (wd);
-  _chdrive (toupper (*wd) - 'A' + 1);
-
-out:
-  puts ("");
-  warning ("Installation took %.0f seconds.\n",
-          (double) (clock () - start) / CLK_TCK);
-
-  if (logpath)
-    {
-      fclose (logfp);
-      xfree (logpath);
-    }
-
-  return retval;
-}
diff --git a/setup.dsp b/setup.dsp
deleted file mode 100644 (file)
index 648b26f..0000000
--- a/setup.dsp
+++ /dev/null
@@ -1,130 +0,0 @@
-# Microsoft Developer Studio Project File - Name="setup" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
-\r
-CFG=setup - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE\r
-!MESSAGE NMAKE /f "setup.mak".\r
-!MESSAGE\r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE\r
-!MESSAGE NMAKE /f "setup.mak" CFG="setup - Win32 Debug"\r
-!MESSAGE\r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE\r
-!MESSAGE "setup - Win32 Release" (based on "Win32 (x86) Console Application")\r
-!MESSAGE "setup - Win32 Debug" (based on "Win32 (x86) Console Application")\r
-!MESSAGE\r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "setup - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "Release"\r
-# PROP BASE Intermediate_Dir "Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir "."\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
-# ADD RSC /l 0x409 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wininet.lib /nologo /subsystem:console /machine:I386\r
-\r
-!ELSEIF  "$(CFG)" == "setup - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "Debug"\r
-# PROP BASE Intermediate_Dir "Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir "g:\cygwin-net-485"\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c\r
-# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
-# ADD RSC /l 0x409 /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wininet.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-\r
-!ENDIF\r
-\r
-# Begin Target\r
-\r
-# Name "setup - Win32 Release"\r
-# Name "setup - Win32 Debug"\r
-# Begin Source File\r
-\r
-SOURCE=.\cygpath.exe.gz\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\cygwin1.dll.gz\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\error.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\gzip.exe.gz\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\memory.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\setup.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\setup.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\setupres.rc\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\strarry.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\strarry.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\tar.exe.gz\r
-# End Source File\r
-# End Target\r
-# End Project\r
diff --git a/setup.dsw b/setup.dsw
deleted file mode 100644 (file)
index 7757b83..0000000
--- a/setup.dsw
+++ /dev/null
@@ -1,44 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00\r
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r
-\r
-###############################################################################\r
-\r
-Project: "setup"=.\setup.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-    Begin Project Dependency\r
-    Project_Dep_Name zlib\r
-    End Project Dependency\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Project: "zlib"=.\zlib.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Global:\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<3>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
diff --git a/setup.h b/setup.h
deleted file mode 100644 (file)
index 00eadf2..0000000
--- a/setup.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2000, Red Hat, Inc.
- *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     A copy of the GNU General Public License can be found at
- *     http://www.gnu.org/
- *
- * Written by Ron Parker <parkerrd@hotmail.com>
- *
- */
-
-#include <stddef.h>
-
-/* Package versioning stuff */
-
-typedef struct
-{
-  char *name;
-  char *version;
-} pkg;
-
-pkg *init_pkgs (const char * root, int);
-pkg * find_pkg (pkg *stuff, char *name);
-int write_pkg (pkg *pkg, char *name, char *version);
-int newer_pkg (pkg *pkg, char *version);
-void normalize_version (const char *fn, char **prod, char **version);
-void close_pkgs (void);
-
-pkg *use_default_pkgs (pkg *stuff);
-const char * check_for_installed (const char *root, pkg *stuff);
-
-/* Routines in error.c. */
-void lowmem ();                        /* Report low memory and exit the
-                                  application. */
-void winerror ();              /* Report errors from GetLastError. */
-
-/* Routines in memory.c. */
-void *xmalloc (size_t);                /* Like malloc, but exit on error. */
-void *xrealloc (void *, size_t);       /* Like realloc, but exit on error. */
-char *xstrdup (const char *);  /* Like strdup, but exit on error. */
-
-#define xfree(ptr) free(ptr)
-
-char *pathcat (const char *arg1, const char *arg2);
-char *pathcvt (char target, const char *path);
-char *dtoupath (const char *path);
-char *utodpath (const char *path);
-
-int xsystem (const char *cmd);
-DWORD xcreate_process (int wait, HANDLE in, HANDLE out, HANDLE err, const char *cmd);
diff --git a/setupres.rc b/setupres.rc
deleted file mode 100644 (file)
index de3209d..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-cygwin1.dll             FILE    DISCARDABLE     "cygwin1.dll.gz"
-tar.exe                 FILE    DISCARDABLE     "tar.exe.gz"
-gzip.exe                FILE    DISCARDABLE     "gzip.exe.gz"
-cygpath.exe            FILE    DISCARDABLE     "cygpath.exe.gz"
-mount.exe              FILE    DISCARDABLE     "mount.exe.gz"
diff --git a/site.cc b/site.cc
new file mode 100644 (file)
index 0000000..84c53d6
--- /dev/null
+++ b/site.cc
@@ -0,0 +1,190 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to get the list of mirror sites and ask
+   the user which mirror site they want to download from. */
+
+#include "win32.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "dialog.h"
+#include "resource.h"
+#include "state.h"
+#include "geturl.h"
+#include "msg.h"
+
+#include "port.h"
+
+#define NO_IDX (-1)
+#define OTHER_IDX (-2)
+static char **site_list = 0;
+static int list_idx = NO_IDX;
+static int mirror_idx = NO_IDX;
+
+static void
+check_if_enable_next (HWND h)
+{
+  EnableWindow (GetDlgItem (h, IDOK), (mirror_idx != NO_IDX) ? 1 : 0);
+}
+
+static void
+load_dialog (HWND h)
+{
+  HWND listbox = GetDlgItem (h, IDC_URL_LIST);
+  SendMessage (listbox, LB_SETCURSEL, list_idx, 0);
+  check_if_enable_next (h);
+}
+
+static void
+save_dialog (HWND h)
+{
+  HWND listbox = GetDlgItem (h, IDC_URL_LIST);
+  list_idx = SendMessage (listbox, LB_GETCURSEL, 0, 0);
+  if (list_idx == LB_ERR)
+    {
+      mirror_site = 0;
+      mirror_idx = NO_IDX;
+      list_idx = NO_IDX;
+    }
+  else
+    {
+      mirror_idx = SendMessage (listbox, LB_GETITEMDATA, list_idx, 0);
+      if (mirror_idx == OTHER_IDX)
+       mirror_site = 0;
+      else
+       mirror_site = site_list[mirror_idx];
+    }
+}
+
+static BOOL
+dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
+{
+  switch (id)
+    {
+
+    case IDC_URL_LIST:
+      save_dialog (h);
+      check_if_enable_next (h);
+      break;
+
+    case IDOK:
+      save_dialog(h);
+      if (mirror_idx == OTHER_IDX)
+       NEXT(IDD_OTHER_URL);
+      else
+       NEXT(IDD_S_LOAD_INI);
+      break;
+
+    case IDC_BACK:
+      save_dialog(h);
+      NEXT(IDD_NET);
+      break;
+
+    case IDCANCEL:
+      NEXT(0);
+      break;
+    }
+}
+
+static BOOL CALLBACK
+dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
+{
+  int i, j;
+  HWND listbox;
+  switch (message)
+    {
+    case WM_INITDIALOG:
+      listbox = GetDlgItem (h, IDC_URL_LIST);
+      for (i=0; site_list[i]; i++)
+       {
+         j = SendMessage (listbox, LB_ADDSTRING, 0, (LPARAM)site_list[i]);
+         SendMessage (listbox, LB_SETITEMDATA, j, i);
+       }
+      j = SendMessage (listbox, LB_ADDSTRING, 0, (LPARAM)"Other URL");
+      SendMessage (listbox, LB_SETITEMDATA, j, OTHER_IDX);
+      load_dialog(h);
+      return FALSE;
+    case WM_COMMAND:
+      return HANDLE_WM_COMMAND(h, wParam, lParam, dialog_cmd);
+    }
+  return FALSE;
+}
+
+static int
+get_site_list (HINSTANCE h)
+{
+  char mirror_url[1000];
+  if (LoadString (h, IDS_MIRROR_LST, mirror_url, sizeof(mirror_url)) <= 0)
+    return 1;
+  char *mirrors = get_url_to_string (mirror_url);
+  dismiss_url_status_dialog ();
+  if (!mirrors)
+    return 1;
+
+  char *bol, *eol, *nl;
+
+  int nmirrors = 2; /* null plus account for possibly missing NL */
+  for (bol=mirrors; *bol; bol++)
+    if (*bol == '\n')
+      nmirrors ++;
+
+  site_list = (char **) malloc (nmirrors * sizeof (char *));
+  nmirrors = 0;
+
+  nl = mirrors;
+  while (*nl)
+    {
+      bol = nl;
+      for (eol = bol; *eol && *eol != '\n'; eol++) ;
+      if (*eol)
+       nl = eol+1;
+      else
+       nl = eol;
+      while (eol > bol && eol[-1] == '\r')
+       eol--;
+      *eol = 0;
+      if (bol[0] != '#' && bol[0] > ' ')
+       {
+         site_list[nmirrors] = _strdup (bol);
+         char *semi = strchr (site_list[nmirrors], ';');
+         if (semi)
+           *semi = 0;
+         nmirrors++;
+       }
+    }
+  site_list[nmirrors] = 0;
+
+  return 0;
+}
+
+void
+do_site (HINSTANCE h)
+{
+  int rv = 0;
+
+  if (site_list == 0)
+    if (get_site_list (h))
+      {
+       NEXT(0);
+       return;
+      }
+
+  rv = DialogBox (h, MAKEINTRESOURCE (IDD_SITE), 0, dialog_proc);
+  if (rv == -1)
+    fatal (IDS_DIALOG_FAILED);
+}
+
diff --git a/source.cc b/source.cc
new file mode 100644 (file)
index 0000000..3f9a533
--- /dev/null
+++ b/source.cc
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to manage the dialog box that lets the
+   user choose the source of the install - from the net, from the
+   current directory, or to just download files. */
+
+#include "win32.h"
+#include <stdio.h>
+#include "dialog.h"
+#include "resource.h"
+#include "state.h"
+#include "msg.h"
+
+
+static int rb[] = { IDC_SOURCE_DOWNLOAD, IDC_SOURCE_NETINST, IDC_SOURCE_CWD, 0 };
+
+static void
+check_if_enable_next (HWND h)
+{
+  EnableWindow (GetDlgItem (h, IDOK), source ? 1 : 0);
+}
+
+static void
+load_dialog (HWND h)
+{
+  int i;
+  rbset (h, rb, source);
+  check_if_enable_next (h);
+}
+
+static void
+save_dialog (HWND h)
+{
+  int i;
+  source = rbget (h, rb);
+}
+
+static BOOL
+dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
+{
+  switch (id)
+    {
+
+    case IDC_SOURCE_DOWNLOAD:
+    case IDC_SOURCE_NETINST:
+    case IDC_SOURCE_CWD:
+      save_dialog (h);
+      check_if_enable_next (h);
+      break;
+
+    case IDOK:
+      save_dialog(h);
+      switch (source)
+       {
+       case IDC_SOURCE_DOWNLOAD:
+         NEXT(IDD_NET);
+         break;
+       case IDC_SOURCE_NETINST:
+       case IDC_SOURCE_CWD:
+         NEXT(IDD_ROOT);
+         break;
+       }
+      break;
+
+    case IDC_BACK:
+      save_dialog(h);
+      NEXT(0);
+      break;
+
+    case IDCANCEL:
+      NEXT(0);
+      break;
+    }
+}
+
+static BOOL CALLBACK
+dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
+{
+  switch (message)
+    {
+    case WM_INITDIALOG:
+      load_dialog(h);
+      return FALSE;
+    case WM_COMMAND:
+      return HANDLE_WM_COMMAND(h, wParam, lParam, dialog_cmd);
+    }
+  return FALSE;
+}
+
+void
+do_source (HINSTANCE h)
+{
+  int rv = 0;
+  rv = DialogBox (h, MAKEINTRESOURCE (IDD_SOURCE), 0, dialog_proc);
+  if (rv == -1)
+    fatal (IDS_DIALOG_FAILED);
+}
+
diff --git a/state.cc b/state.cc
new file mode 100644 (file)
index 0000000..23502c2
--- /dev/null
+++ b/state.cc
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* All we do here is instantiate the extern'd variables from state.h */
+
+#define extern
+#include "state.h"
diff --git a/state.h b/state.h
new file mode 100644 (file)
index 0000000..c3344b5
--- /dev/null
+++ b/state.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to contain all the global variables
+   that define the "state" of the install, that is, all the
+   information that the user has provided so far.  These are set by
+   the various dialogs and used by the various actions. */
+
+extern int     source;
+
+extern char *  root_dir;
+extern int     root_text;
+
+extern int     net_method;
+extern char *  net_proxy_host;
+extern int     net_proxy_port;
+extern char *  net_proxy_user;
+extern char *  net_proxy_passwd;
+
+extern char *  mirror_site;
+extern char *  other_url;
+
+extern int     trust_level;
+
+#define MIRROR_SITE (mirror_site ? mirror_site : other_url)
diff --git a/strarry.c b/strarry.c
deleted file mode 100644 (file)
index 9bc1c66..0000000
--- a/strarry.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2000, Red Hat, Inc.
- *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     A copy of the GNU General Public License can be found at
- *     http://www.gnu.org/
- *
- * Written by Ron Parker <parkerrd@hotmail.com>
- *
- */
-
-/* strarry.c: implementation of the strarry struct routines. */
-#include <malloc.h>
-#include <windows.h>
-#include "setup.h"
-#include "strarry.h"
-
-void
-sa_init (SA * array)
-{
-  array->count = 0;
-  array->array = NULL;
-}
-
-void
-sa_add (SA * array, const char *str)
-{
-  array->array = array->count
-    ? xrealloc (array->array, sizeof (char *) * (array->count + 1))
-  : xmalloc (sizeof (char *));
-  array->array[array->count++] = xstrdup (str);
-}
-
-void
-sa_cleanup (SA * array)
-{
-  size_t n = array->count;
-  while (n--)
-    xfree (array->array[n]);
-  xfree (array->array);
-}
diff --git a/tar.c b/tar.cc
similarity index 89%
rename from tar.c
rename to tar.cc
index 5679d8eb431b0396859cde0619e41f2a29cf80f0..267c58ae9e0df45f8dd672161048fe8dbdb904db 100644 (file)
--- a/tar.c
+++ b/tar.cc
  *
  */
 
+/* Built-in tar functionality.  See tar.h for usage. */
+
+#include "win32.h"
 #include <stdio.h>
 #include <stdlib.h>
-#include <windows.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
 #include "zlib/zlib.h"
 #include "tar.h"
+#include "mkdir.h"
+
+#include "port.h"
 
 #define FACTOR (0x19db1ded53ea710LL)
 #define NSPERSEC 10000000LL
@@ -60,12 +68,13 @@ static int  file_length;
 static tar_header_type tar_header;
 static char buf[512];
 
+static int _tar_file_size = 0;
 int _tar_verbose = 0;
 FILE * _tar_vfile = 0;
 #define vp if(_tar_verbose) fprintf
 #define vp2 if(_tar_verbose>1) fprintf
 
-static gzFile *g = 0;
+static gzFile g = 0;
 
 static char *
 xstrdup (char *c)
@@ -80,10 +89,15 @@ xstrdup (char *c)
 int
 tar_open (char *pathname)
 {
+  struct stat s;
   if (_tar_vfile == 0)
     _tar_vfile = stderr;
 
   vp2 (_tar_vfile, "tar: open `%s'\n", pathname);
+  if (stat (pathname, &s) < 0)
+    return 1;
+  _tar_file_size = s.st_size;
+
   g = gzopen (pathname, "rb");
   if (sizeof (tar_header) != 512)
     {
@@ -96,6 +110,12 @@ tar_open (char *pathname)
   return g ? 0 : 1;
 }
 
+int
+tar_ftell ()
+{
+  return gzctell (g);
+}
+
 static void
 skip_file ()
 {
@@ -189,71 +209,6 @@ tar_next_file ()
     }
 }
 
-static char mkdir_last_warn [_MAX_PATH] = { 0 };
-
-static int
-mkdir_p (int isadir, char *path)
-{
-  char saved_char, *slash = 0;
-  char *c;
-  DWORD d, gse;
-
-  vp2 (_tar_vfile, "mkdir_p checking %d %s\n", isadir, path);
-  d = GetFileAttributes (path);
-  if (d != 0xffffffff && d & FILE_ATTRIBUTE_DIRECTORY)
-    {
-      vp2 (_tar_vfile, "mkdir_p it's a directory\n");
-      return 0;
-    }
-
-  if (isadir)
-    {
-      vp2 (_tar_vfile, "mkdir_p mkdir %s\n", path);
-      if (CreateDirectory (path, 0))
-       return 0;
-      gse = GetLastError ();
-      if (gse != ERROR_PATH_NOT_FOUND)
-       {
-         vp2 (_tar_vfile, "mkdir_p returned %d\n", gse);
-         if (gse == ERROR_ALREADY_EXISTS)
-           {
-             if (DeleteFileA (path))
-               {
-                 fprintf(stderr, "warning: deleting \"%s\" so I can make a directory there\n",
-                         path);
-                 return mkdir_p (isadir, path);
-               }
-           }
-         return 1;
-       }
-    }
-
-  for (c=path; *c; c++)
-    {
-      if (*c == ':')
-       slash = 0;
-      if (*c == '/' || *c == '\\')
-       slash = c;
-    }
-
-  if (!slash)
-    return 0;
-
-  saved_char = *slash;
-  *slash = 0;
-  if (mkdir_p (1, path))
-    {
-      *slash = saved_char;
-      return 1;
-    }
-  *slash = saved_char;
-
-  if (!isadir)
-    return 0;
-
-  return mkdir_p (isadir, path);
-}
-
 static void
 fix_time_stamp (char *path)
 {
diff --git a/tar.exe.gz b/tar.exe.gz
deleted file mode 100755 (executable)
index dd07c45..0000000
Binary files a/tar.exe.gz and /dev/null differ
diff --git a/tar.h b/tar.h
index 85d9fb000bc6ce9eb354ae7c320ab0888b9524a8..e299481f07250cc337d7aa8f6da27eb951e7abe2 100644 (file)
--- a/tar.h
+++ b/tar.h
@@ -25,6 +25,9 @@ int   tar_open (char *pathname);
 /* returns pointer to static buf containing name of next file */
 char * tar_next_file ();
 
+/* byte position in [compressed] file */
+int    tar_ftell ();
+
 /* pass adjusted path, returns zero on success, nonzero on failure */
 int    tar_read_file (char *path);
 
@@ -36,6 +39,8 @@ int   tar_close ();
    errors) on failure */
 int    tar_auto (char *pathname, char **map);
 
+int    tar_mkdir_p (int isadir, char *path);
+
 /*
 extern int _tar_verbose;
 extern FILE * _tar_vfile;
diff --git a/win32.h b/win32.h
new file mode 100644 (file)
index 0000000..d6bd11b
--- /dev/null
+++ b/win32.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to limit the number of Win32 headers we
+   actually have to parse.  The Setup program only uses a few of them,
+   so there's no point in parsing them all (even lean-n-mean).  Doing
+   this cuts compile time in half. */
+
+#define _UNION_NAME(x)
+#define _STRUCT_NAME(x)
+#define NOCOMATTRIBUTE
+
+#include <stdarg.h>
+#include <windef.h>
+#include <basetyps.h>
+#include <winbase.h>
+#include <wingdi.h>
+#include <winuser.h>
+#include <wininet.h>
+
+#include <windowsx.h>
diff --git a/xsystem.c b/xsystem.c
deleted file mode 100644 (file)
index 8172792..0000000
--- a/xsystem.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (c) 2000, Red Hat, Inc.
- *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     A copy of the GNU General Public License can be found at
- *     http://www.gnu.org/
- *
- * Written by Ron Parker <parkerrd@hotmail.com>
- *
- */
-
-#include <windows.h>
-#include <wininet.h>
-#include <assert.h>
-#include <ctype.h>
-#include <direct.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <io.h>
-#include <shellapi.h>
-#include <shlguid.h>
-#include <shlobj.h>
-#include <stdio.h>
-#include <time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "setup.h"
-#include "strarry.h"
-
-extern char *pathcat (const char *, const char *);
-
-DWORD
-xcreate_process (int wait, HANDLE in, HANDLE out, HANDLE err, const char *cmd)
-{
-  int retval;
-  char *command;
-  STARTUPINFO si;
-  PROCESS_INFORMATION pi;
-  extern char *wd;
-
-  if (cmd[1] != ':' && strncmp (cmd, "\\\\", 2) != 0)
-    command = pathcat (wd, cmd);
-  else
-    command = xstrdup (cmd);
-
-  memset (&si, 0, sizeof (si));
-  si.cb = sizeof (si);
-
-  si.hStdInput = in ? in : GetStdHandle (STD_INPUT_HANDLE);
-  si.hStdOutput = out ? out : GetStdHandle (STD_OUTPUT_HANDLE);
-  si.hStdError = err ? err : GetStdHandle (STD_ERROR_HANDLE);
-  si.dwFlags = STARTF_USESTDHANDLES;
-
-  retval = CreateProcess (NULL, command, NULL, NULL, TRUE, 0,
-                         NULL, NULL, &si, &pi);
-
-  xfree (command);
-  if (!retval)
-    return 0;
-
-  CloseHandle (pi.hThread);
-
-  if (!wait)
-    retval = (DWORD) pi.hProcess;
-  else
-    {
-      WaitForSingleObject (pi.hProcess, INFINITE);
-      CloseHandle (pi.hProcess);
-    }
-
-  return retval;
-}
-
-int
-xsystem (const char *cmd)
-{
-  return !xcreate_process (1, NULL, NULL, NULL, cmd);
-}
diff --git a/zlib.dsp b/zlib.dsp
deleted file mode 100644 (file)
index 2c58c79..0000000
--- a/zlib.dsp
+++ /dev/null
@@ -1,192 +0,0 @@
-# Microsoft Developer Studio Project File - Name="zlib" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Static Library" 0x0104\r
-\r
-CFG=zlib - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE\r
-!MESSAGE NMAKE /f "zlib.mak".\r
-!MESSAGE\r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE\r
-!MESSAGE NMAKE /f "zlib.mak" CFG="zlib - Win32 Debug"\r
-!MESSAGE\r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE\r
-!MESSAGE "zlib - Win32 Release" (based on "Win32 (x86) Static Library")\r
-!MESSAGE "zlib - Win32 Debug" (based on "Win32 (x86) Static Library")\r
-!MESSAGE\r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "zlib - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "Release"\r
-# PROP BASE Intermediate_Dir "Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir "Release"\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c\r
-# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c\r
-# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
-# ADD RSC /l 0x409 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LIB32=link.exe -lib\r
-# ADD BASE LIB32 /nologo\r
-# ADD LIB32 /nologo\r
-\r
-!ELSEIF  "$(CFG)" == "zlib - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "Debug"\r
-# PROP BASE Intermediate_Dir "Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir "Debug"\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c\r
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c\r
-# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
-# ADD RSC /l 0x409 /i ".." /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LIB32=link.exe -lib\r
-# ADD BASE LIB32 /nologo\r
-# ADD LIB32 /nologo\r
-\r
-!ENDIF\r
-\r
-# Begin Target\r
-\r
-# Name "zlib - Win32 Release"\r
-# Name "zlib - Win32 Debug"\r
-# Begin Group "Source Files"\r
-\r
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\adler32.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\compress.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\crc32.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\deflate.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\gzio.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\infblock.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\infcodes.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\inffast.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\inflate.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\inftrees.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\infutil.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\trees.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\uncompr.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\zutil.c\r
-# End Source File\r
-# End Group\r
-# Begin Group "Header Files"\r
-\r
-# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\deflate.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\infblock.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\infcodes.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\inffast.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\inffixed.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\inftrees.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\infutil.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\trees.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\zconf.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\zlib.h\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\zlib\zutil.h\r
-# End Source File\r
-# End Group\r
-# End Target\r
-# End Project\r
index 2fd53b75f54c910ab47559d975c3c82ddb912a53..7fdf984b0304a553aa774df6713b92a8aa63e7bf 100644 (file)
@@ -211,6 +211,7 @@ int ZEXPORT gzsetparams (file, level, strategy)
     int level;
     int strategy;
 {
+#ifndef NO_DEFLATE
     gz_stream *s = (gz_stream*)file;
 
     if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
@@ -226,6 +227,9 @@ int ZEXPORT gzsetparams (file, level, strategy)
     }
 
     return deflateParams (&(s->stream), level, strategy);
+#else
+    return Z_OK;
+#endif
 }
 
 /* ===========================================================================
@@ -771,6 +775,18 @@ z_off_t ZEXPORT gztell (file)
     return gzseek(file, 0L, SEEK_CUR);
 }
 
+/* ===========================================================================
+     Returns the starting position for the next gzread or gzwrite on the
+   given compressed file. This position represents a number of bytes in the
+   uncompressed data stream.
+*/
+z_off_t ZEXPORT gzctell (file)
+    gzFile file;
+{
+    gz_stream *s = (gz_stream *)file;
+    return ftell(s->file);
+}
+
 /* ===========================================================================
      Returns 1 when EOF has previously been detected reading the given
    input stream, otherwise zero.
index 47a75cf0f9d70b1530b53a20bcc055416ba32662..128d9d602c783d3724f020026cbd3ac36f62c804 100644 (file)
@@ -788,6 +788,11 @@ ZEXTERN z_off_t ZEXPORT    gztell OF((gzFile file));
    gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
 */
 
+ZEXTERN z_off_t ZEXPORT    gzctell OF((gzFile file));
+/*
+   current position of compressed file
+*/
+
 ZEXTERN int ZEXPORT gzeof OF((gzFile file));
 /*
      Returns 1 when EOF has previously been detected reading the given
This page took 0.206737 seconds and 5 git commands to generate.