]> cygwin.com Git - cygwin-apps/setup.git/commitdiff
2001-12-04 Robert Collins <rbtcollins@hotmail.com>
authorRobert Collins <rbtcollins@hotmail.com>
Mon, 3 Dec 2001 22:22:09 +0000 (22:22 +0000)
committerRobert Collins <rbtcollins@hotmail.com>
Mon, 3 Dec 2001 22:22:09 +0000 (22:22 +0000)
        * Makefile.in (OBJS): Add setup_version.o.
        (version.c): Rename to setup_version.
        * choose.cc (set_action): Prevent NULL pointer dereference.
        (package_sort): Remove.
        * fromcwd.cc (canonicalize_version): Moved to version.cc.
        (check_ini): New function for use with find to see if there is a cached setup.ini.
        (do_fromcwd): Check for a cached setup.ini from any mirror site.
        * ini.cc (find_routine): New function, for finding cached setup.ini's.
        (do_local_ini): New function, drives parsing of local ini's.
        (do_remote_ini): New function, drives parsing and caching of remote ini's.
        (do_ini): Move guts to do_remote_ini and do_local_ini.
        * list.h (removebyindex): New method.
        * other.cc (save_dialog): Use new site_list and all_site_list to add the
        new site to the site picklist.
        (dialog_cmd): Only save the dialog when exiting the dialog.
        * res.rc (IDD_SITE): Make IDC_URL_LIST a multiple-selection control.
        * site.cc (site_list_type): Move to site.h
        (site_list): New global, sites chosen by the user.
        (all_site_list): New global, all potential sites.
        (site_list_type::init): New method, parses a mirror.lst URL string into a
        site_list_type object.
        (site_list_type::site_list_type): New method.
        (check_if_enable_next): Examine the control, not a local variable.
        (load_dialog): Select all the user chosen sites by default.
        (save_dialog): Adjust for multiple selection semantics.
        (save_site_url): Save all user chosen sites.
        (dialog_cmd): Don't save the dialog when the listbox recieves a message -
        thats not needed.
        Remove obsolete other_url reference.
        (dialog_proc): Use all_site_list instead of site_list.
        (site_sort): Remove.
        (get_site_list): Remove malloc use - use list template instead.
        Move site_list_type initialisation to site_list_type::init().
        (get_initial_list_idx): Renamed to ...
        (get_saved_sites): this. Also read in multiple sites to the site_list.
        (do_site): Use all_site_list not site_list.
        Log all chosen sites.
        * site.h: New file, defines site related class, functions and variables.
        * state.h: Add comment about use of state.h
        (mirror_site): Remove.
        (other_url): Remove.
        (MIRROR_SITE): Remove.
        * version.cc: New file, for version-handling and related functions.

12 files changed:
ChangeLog
Makefile.in
choose.cc
fromcwd.cc
ini.cc
list.h
other.cc
res.rc
site.cc
site.h [new file with mode: 0644]
state.h
version.cc [new file with mode: 0644]

index 13ad32b8c3a154818f0637e37936f81f5952a29b..17254007f981cacd64ce65d7a4c441403fb97b66 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,49 @@
+2001-12-04  Robert Collins  <rbtcollins@hotmail.com>
+
+       * Makefile.in (OBJS): Add setup_version.o.
+       (version.c): Rename to setup_version.
+       * choose.cc (set_action): Prevent NULL pointer dereference.
+       (package_sort): Remove.
+       * fromcwd.cc (canonicalize_version): Moved to version.cc.
+       (check_ini): New function for use with find to see if there is a cached setup.ini.
+       (do_fromcwd): Check for a cached setup.ini from any mirror site.
+       * ini.cc (find_routine): New function, for finding cached setup.ini's.
+       (do_local_ini): New function, drives parsing of local ini's.
+       (do_remote_ini): New function, drives parsing and caching of remote ini's.
+       (do_ini): Move guts to do_remote_ini and do_local_ini.
+       * list.h (removebyindex): New method.
+       * other.cc (save_dialog): Use new site_list and all_site_list to add the
+       new site to the site picklist.
+       (dialog_cmd): Only save the dialog when exiting the dialog.
+       * res.rc (IDD_SITE): Make IDC_URL_LIST a multiple-selection control.
+       * site.cc (site_list_type): Move to site.h
+       (site_list): New global, sites chosen by the user.
+       (all_site_list): New global, all potential sites.
+       (site_list_type::init): New method, parses a mirror.lst URL string into a 
+       site_list_type object.
+       (site_list_type::site_list_type): New method.
+       (check_if_enable_next): Examine the control, not a local variable.
+       (load_dialog): Select all the user chosen sites by default.
+       (save_dialog): Adjust for multiple selection semantics. 
+       (save_site_url): Save all user chosen sites.
+       (dialog_cmd): Don't save the dialog when the listbox recieves a message - 
+       thats not needed.
+       Remove obsolete other_url reference.
+       (dialog_proc): Use all_site_list instead of site_list.
+       (site_sort): Remove.
+       (get_site_list): Remove malloc use - use list template instead.
+       Move site_list_type initialisation to site_list_type::init().
+       (get_initial_list_idx): Renamed to ...
+       (get_saved_sites): this. Also read in multiple sites to the site_list.
+       (do_site): Use all_site_list not site_list.
+       Log all chosen sites.
+       * site.h: New file, defines site related class, functions and variables.
+       * state.h: Add comment about use of state.h
+       (mirror_site): Remove.
+       (other_url): Remove.
+       (MIRROR_SITE): Remove.
+       * version.cc: New file, for version-handling and related functions.
+
 2001-12-02  Robert Collins  <rbtcollins@hotmail.com>
 
        * Makefile.in: Add filemanip.o to setup.
index 127b9c3996de463135d1c4873fbbcb60304b9da3..0a5bcfad235b7cc14e30b23944601a74d2ba3626 100644 (file)
@@ -131,6 +131,7 @@ OBJS = \
        res.o \
        rfc1738.o \
        root.o \
+       setup_version.o \
        simpsock.o \
        site.o \
        source.o \
@@ -186,12 +187,12 @@ $(ZLIB): zlib/Makefile
 $(BZ2LIB): $(bupdir)/bz2lib/Makefile
        $(MAKE) -C $(@D) $(@F) CC="$(CC)" CFLAGS='$(MINGW_CFLAGS)'
 
-version.c : $(srcdir)/ChangeLog Makefile
+setup_version.c : $(srcdir)/ChangeLog Makefile
        V=`grep '^\$$Revision.*' $(srcdir)/ChangeLog \
        | sed -e 's/\$$Revision:* *//' \
          -e 's/ *$$.*//'` ;\
        echo "const char *version = \"$$V\";" > version.tmp ;\
-       mv version.tmp version.c
+       mv version.tmp setup_version.c
 
 %.o: %.rc
 ifdef VERBOSE
index f5ec06310c1b86cae6400b7bf6820aff32a462b3..5acb6b307cc3b4a13ffd0aced728a560f8901bae 100644 (file)
--- a/choose.cc
+++ b/choose.cc
@@ -176,7 +176,8 @@ set_action (packagemeta * pkg)
   /* are we currently on the radio button selection and installed */
   if (pkg->desired == pkgtrustp (pkg, deftrust) && pkg->installed &&
       (!pkg->desired || pkg->desired->binpicked)
-      && (pkg->desired->src.Cached () || pkg->desired->src.sites.number ()))
+      && (pkg->desired && 
+       (pkg->desired->src.Cached () || pkg->desired->src.sites.number ())))
     {
       /* source only this file */
       pkg->desired = pkg->installed;
@@ -1358,14 +1359,6 @@ scan_downloaded_files ()
   find (".", scan2);
 }
 
-int
-package_sort (const void *va, const void *vb)
-{
-  packagemeta *a = (packagemeta *) va;
-  packagemeta *b = (packagemeta *) vb;
-  return strcasecmp (a->name, b->name);
-}
-
 void
 do_choose (HINSTANCE h)
 {
index 1818f52a4fb44af146fb8585e3264c27f19fdcba..99682928ac31f5cec812a54d251d230c706e57fb 100644 (file)
@@ -47,6 +47,8 @@ static const char *cvsid =
 #include "find.h"
 #include "filemanip.h"
 #include "version.h"
+#include "site.h"
+#include "rfc1738.h"
 
 #include "port.h"
 
@@ -62,34 +64,6 @@ is_test_version (char *v)
   return (i >= 6) ? 1 : 0;
 }
 #endif
-char *
-canonicalize_version (const char *v)
-{
-  static char nv[3][100];
-  static int idx = 0;
-  char *np;
-  const char *dp;
-  int i;
-
-  idx = (idx + 1) % 3;
-  np = nv[idx];
-
-  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[idx];
-}
 
 static void
 found_file (char *path, unsigned int fsize)
@@ -134,12 +108,22 @@ found_file (char *path, unsigned int fsize)
 #endif
 }
 
+static bool found_ini;
+
+static void
+check_ini (char *path, unsigned int fsize)
+{
+  if (fsize && strstr (path, "setup.ini"))
+    found_ini = true;
+}
+
 void
 do_fromcwd (HINSTANCE h)
 {
-  if (_access ("./setup.ini", 0) == 0)
-    {
-      mirror_site = (char *) ".";
+  found_ini = true;
+  find (".", check_ini);
+  if (found_ini)
+  {
       next_dialog = IDD_S_LOAD_INI;
       return;
     }
diff --git a/ini.cc b/ini.cc
index ffccc2636e7299dbe2df8bdef0e8c73ea466dfba..051e64261bbc2eb71c5ece81c372b2d5bcce22fa 100644 (file)
--- a/ini.cc
+++ b/ini.cc
@@ -39,6 +39,9 @@ static const char *cvsid =
 #include "log.h"
 #include "version.h"
 #include "mount.h"
+#include "site.h"
+#include "rfc1738.h"
+#include "find.h"
 
 #include "io_stream.h"
 
@@ -51,40 +54,104 @@ extern int yyparse ();
 static char *error_buf = 0;
 static int error_count = 0;
 
-void
-do_ini (HINSTANCE h)
-{
-  io_stream *ini_file = get_url_to_membuf (concat (MIRROR_SITE, "/setup.ini", 0));
-  dismiss_url_status_dialog ();
+static int local_ini;
 
+static void
+find_routine (char *path, unsigned int fsize)
+{
+  if (!strstr (path, "/setup.ini") )
+    return;
+  io_stream *ini_file = io_stream::open (concat ("file://", local_dir,"/", path, 0), "rb");
   if (!ini_file)
     {
-      note (IDS_SETUPINI_MISSING, MIRROR_SITE);
-      next_dialog = IDD_SITE;
-      return;
+    note (IDS_SETUPINI_MISSING, path);
+    return;
     }
 
+  /* FIXME: only use most recent copy */
   setup_timestamp = 0;
   setup_version = 0;
 
-  ini_init (ini_file, MIRROR_SITE);
+  ini_init (ini_file, concat ("file://", local_dir,"/", path, 0));
 
   /*yydebug = 1; */
 
   if (yyparse () || error_count > 0)
     MessageBox (0, error_buf, error_count == 1 ? "Parse Error" : "Parse Errors", 0);
   else
+    local_ini++;
+}
+
+static int
+do_local_ini ()
+{
+  local_ini = 0;
+  find (local_dir, find_routine);
+  return local_ini; 
+}
+
+static int
+do_remote_ini ()
+{
+  size_t ini_count = 0;
+  for (size_t n = 1; n <= site_list.number (); n++)
     {
-      /* save known-good setup.ini locally */
-      io_stream *inistream = io_stream::open ("file://setup.ini", "wb");
-      if (inistream && 
-         ! ini_file->seek (0, IO_SEEK_SET))
-        {
-         if (io_stream::copy (ini_file, inistream))
-           io_stream::remove ("file://setup.ini");
-         delete ini_file;
-         delete inistream;
+      io_stream *ini_file =
+       get_url_to_membuf (concat (site_list[n]->url, "/setup.ini", 0));
+      dismiss_url_status_dialog ();
+
+      if (!ini_file)
+       {
+         note (IDS_SETUPINI_MISSING, site_list[n]->url);
+         continue;
        }
+
+      /* FIXME: only use most recent copy */
+      setup_timestamp = 0;
+      setup_version = 0;
+
+      ini_init (ini_file, site_list[n]->url);
+
+      /*yydebug = 1; */
+
+      if (yyparse () || error_count > 0)
+       MessageBox (0, error_buf,
+                   error_count == 1 ? "Parse Error" : "Parse Errors", 0);
+      else
+       {
+         /* save known-good setup.ini locally */
+         char const *fp = concat ("file://", local_dir, "/",
+                                  rfc1738_escape_part (site_list[n]->url),
+                                  "/setup.ini", 0);
+         io_stream::mkpath_p (PATH_TO_FILE, fp);
+         io_stream *inistream = io_stream::open (fp, "wb");
+         if (inistream && !ini_file->seek (0, IO_SEEK_SET))
+           {
+             if (io_stream::copy (ini_file, inistream))
+               io_stream::remove (fp);
+             delete ini_file;
+             delete inistream;
+           }
+         free ((void *) fp);
+         ini_count++;
+       }
+    }
+  return ini_count;
+}
+
+void
+do_ini (HINSTANCE h)
+{
+  size_t ini_count = 0;
+  if (source == IDC_SOURCE_CWD)
+    ini_count = do_local_ini ();
+  else
+    ini_count = do_remote_ini ();
+
+  if (ini_count == 0)
+    {
+      next_dialog = source == IDC_SOURCE_CWD ? IDD_S_FROM_CWD : IDD_SITE;
+      return;
     }
 
   if (get_root_dir ())
diff --git a/list.h b/list.h
index 2b1f18204386bbad88205bfd8bd68d35be2bb075..5756caea83863dc1611a7d002b9ee37a1ce52864 100644 (file)
--- a/list.h
+++ b/list.h
@@ -40,6 +40,8 @@ list ():pointerblock (0), _number (0), _space (0)
   T & registerbykey (U);
   /* add an element if one with the same key does not exist */
   T & registerbyobject (T &);
+  /* remove by index */
+  T * removebyindex (size_t);
   size_t number ()
   {
     return _number;
@@ -130,4 +132,18 @@ T & list < T, U, Ucmp >::registerbyobject (T & newobj)
   return *tempT;
 }
 
+template < class T, class U, int Ucmp (U, U) >
+T * list < T, U, Ucmp >::removebyindex (size_t index)
+{
+  if (index && index <= _number)
+    {
+      T * rv = pointerblock[index - 1];
+      /* remove from index - 1 */
+      memmove (&pointerblock[index - 1], &pointerblock[index], (_number - index) * sizeof (T *));
+      _number --;
+      return rv;
+    }
+  return 0;
+}
+
 #endif /* _LIST_H_ */
index f8625c2cd31031e4ef849317d46630dd0ede108b..9a4bd2db1451cf7e5f3724382b52fb9ec1ac2b91 100644 (file)
--- a/other.cc
+++ b/other.cc
@@ -30,10 +30,10 @@ static const char *cvsid =
 #include "state.h"
 #include "msg.h"
 #include "log.h"
+#include "site.h"
 
-/* private shared function, from site.cc */
-void save_site_url (void);
-
+static char * other_url = 0;
+  
 static void
 check_if_enable_next (HWND h)
 {
@@ -51,6 +51,12 @@ static void
 save_dialog (HWND h)
 {
   other_url = eget (h, IDC_OTHER_URL, other_url);
+  site_list_type *newsite = new site_list_type (other_url);
+  site_list_type &listobj = all_site_list.registerbyobject (*newsite);
+  if (&listobj != newsite)
+    /* That site was already registered */
+    delete newsite;
+  site_list.registerbyobject (listobj);
 }
 
 static BOOL
@@ -60,7 +66,7 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
     {
 
     case IDC_OTHER_URL:
-      save_dialog (h);
+      other_url = eget (h, IDC_OTHER_URL, other_url);
       check_if_enable_next (h);
       break;
 
diff --git a/res.rc b/res.rc
index 54b988f90465824661afbaf3bd655f1bf154f129..68886f51105dbc29f6dbcb000c906663daef2cb4 100644 (file)
--- a/res.rc
+++ b/res.rc
@@ -88,9 +88,9 @@ CAPTION "Cygwin Setup"
 FONT 8, "MS Sans Serif"
 BEGIN
     ICON            IDI_CYGWIN,IDC_STATIC,5,5,20,20
-    LTEXT           "Select Download &Site",IDC_STATIC,55,5,135,11
+    LTEXT           "Select Download &Sites",IDC_STATIC,55,5,135,11
     LISTBOX         IDC_URL_LIST,55,20,160,155,LBS_NOINTEGRALHEIGHT | 
-                    WS_VSCROLL | WS_HSCROLL | WS_TABSTOP
+                   LBS_EXTENDEDSEL | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP
     DEFPUSHBUTTON   "&Next -->",IDOK,105,185,45,15
     PUSHBUTTON      "Cancel",IDCANCEL,170,185,45,15
     PUSHBUTTON      "<-- &Back",IDC_BACK,60,185,45,15
diff --git a/site.cc b/site.cc
index e2258bb54b332f8086fd6632223ebb36df4f0c62..66c1175dc58edb8c4cbe74a23c03082c50c88ec9 100644 (file)
--- a/site.cc
+++ b/site.cc
@@ -34,35 +34,75 @@ static const char *cvsid =
 #include "concat.h"
 #include "log.h"
 #include "io_stream.h"
+#include "site.h"
 
 #include "port.h"
 
 #define NO_IDX (-1)
 #define OTHER_IDX (-2)
 
-class site_list_type
-{
-public:
-  char *url;
-  char *displayed_url;
-  char *key;
-};
-
-static site_list_type *site_list = 0;
-static int list_idx = NO_IDX;
+list < site_list_type, const char *, strcasecmp > site_list;
+list < site_list_type, const char *, strcasecmp > all_site_list;
 static int mirror_idx = NO_IDX;
 
+void
+site_list_type::init (char const *newurl)
+{
+  url = _strdup (newurl);
+  displayed_url = _strdup (newurl);
+  char *dot = strchr (displayed_url, '.');
+  if (dot)
+    {
+      dot = strchr (dot, '/');
+      if (dot)
+       *dot = 0;
+    }
+  key = (char *) malloc (2 * strlen (newurl) + 3);
+
+  dot = displayed_url;
+  dot += strlen (dot);
+  char *dp = key;
+  while (dot != displayed_url)
+    {
+      if (*dot == '.' || *dot == '/')
+       {
+         char *sp;
+         if (dot[3] == 0)
+           *dp++ = '~';        /* sort .com/.edu/.org together */
+         for (sp = dot + 1; *sp && *sp != '.' && *sp != '/';)
+           *dp++ = *sp++;
+         *dp++ = ' ';
+       }
+      dot--;
+    }
+  *dp++ = ' ';
+  strcpy (dp, displayed_url);
+}
+
+site_list_type::site_list_type (char const *newurl)
+{
+  init (newurl);
+}
+
 static void
 check_if_enable_next (HWND h)
 {
-  EnableWindow (GetDlgItem (h, IDOK), (mirror_idx != NO_IDX) ? 1 : 0);
+  EnableWindow (GetDlgItem (h, IDOK),
+               SendMessage (GetDlgItem (h, IDC_URL_LIST), LB_GETSELCOUNT, 0,
+                            0) > 0 ? 1 : 0);
 }
 
 static void
 load_dialog (HWND h)
 {
   HWND listbox = GetDlgItem (h, IDC_URL_LIST);
-  SendMessage (listbox, LB_SETCURSEL, list_idx, 0);
+  for (size_t n = 1; n <= site_list.number (); n++)
+    {
+      int index = SendMessage (listbox, LB_FINDSTRING, (WPARAM) - 1,
+                              (LPARAM) site_list[n]->displayed_url);
+      if (index != LB_ERR)
+       SendMessage (listbox, LB_SELITEMRANGE, TRUE, (index << 16) | index);
+    }
   check_if_enable_next (h);
 }
 
@@ -70,38 +110,52 @@ 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_idx = 0;
+  while (site_list.number () > 0)
+    /* we don't delete the object because it's stored in the all_site_list. */
+    site_list.removebyindex (1);
+  int sel_count = SendMessage (listbox, LB_GETSELCOUNT, 0, 0);
+  if (sel_count > 0)
     {
-      mirror_site = 0;
-      mirror_idx = NO_IDX;
-      list_idx = NO_IDX;
+      int sel_buffer[sel_count];
+      int sel_count2 = SendMessage (listbox, LB_GETSELITEMS, sel_count,
+                                   (LPARAM) sel_buffer);
+      if (sel_count != sel_count2)
+       {
+         NEXT (IDD_SITE);
+       }
+      for (int n = 0; n < sel_count; n++)
+       {
+         int mirror =
+           SendMessage (listbox, LB_GETITEMDATA, sel_buffer[n], 0);
+         if (mirror == OTHER_IDX)
+           mirror_idx = OTHER_IDX;
+         else
+           site_list.registerbyobject (*all_site_list[mirror]);
+       }
     }
   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].url;
+      NEXT (IDD_SITE);
     }
 }
 
 void
 save_site_url ()
 {
-  if (!MIRROR_SITE)
-    return;
-
   io_stream *f = io_stream::open ("cygfile:///etc/setup/last-mirror", "wb");
-  if (f)
+  for (size_t n = 1; n <= site_list.number (); n++)
     {
-      char temp[_MAX_PATH];
-      /* TODO: potential buffer overflow. we need snprintf asap. */
-      sprintf (temp, "%s\n", MIRROR_SITE);
-      f->write (temp, strlen (temp));
-      delete f;
+      if (f)
+       {
+         char temp[_MAX_PATH];
+         /* TODO: potential buffer overflow. we need snprintf asap. */
+         // FIXME: write all selected sites
+         sprintf (temp, "%s\n", site_list[n]->url);
+         f->write (temp, strlen (temp));
+       }
     }
+  delete f;
 }
 
 static BOOL
@@ -111,7 +165,6 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
     {
 
     case IDC_URL_LIST:
-      save_dialog (h);
       check_if_enable_next (h);
       break;
 
@@ -121,7 +174,6 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
        NEXT (IDD_OTHER_URL);
       else
        {
-         other_url = 0;
          save_site_url ();
          NEXT (IDD_S_LOAD_INI);
        }
@@ -142,17 +194,17 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
 static BOOL CALLBACK
 dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
 {
-  int i, j;
+  int j;
   HWND listbox;
   switch (message)
     {
     case WM_INITDIALOG:
       listbox = GetDlgItem (h, IDC_URL_LIST);
-      for (i = 0; site_list[i].url; i++)
+      for (size_t i = 1; i <= all_site_list.number (); i++)
        {
          j =
            SendMessage (listbox, LB_ADDSTRING, 0,
-                        (LPARAM) site_list[i].displayed_url);
+                        (LPARAM) all_site_list[i]->displayed_url);
          SendMessage (listbox, LB_SETITEMDATA, j, i);
        }
       j = SendMessage (listbox, LB_ADDSTRING, 0, (LPARAM) "Other URL");
@@ -165,14 +217,6 @@ dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
   return FALSE;
 }
 
-static int
-site_sort (const void *va, const void *vb)
-{
-  site_list_type *a = (site_list_type *) va;
-  site_list_type *b = (site_list_type *) vb;
-  return strcmp (a->key, b->key);
-}
-
 static int
 get_site_list (HINSTANCE h)
 {
@@ -186,18 +230,6 @@ get_site_list (HINSTANCE h)
 
   char *bol, *eol, *nl;
 
-
-  /* null plus account for possibly missing NL plus account for "Other
-     URL" from previous run. */
-  int nmirrors = 3;
-
-  for (bol = mirrors; *bol; bol++)
-    if (*bol == '\n')
-      nmirrors++;
-
-  site_list = (site_list_type *) malloc (nmirrors * sizeof (site_list_type));
-  nmirrors = 0;
-
   nl = mirrors;
   while (*nl)
     {
@@ -215,44 +247,15 @@ get_site_list (HINSTANCE h)
          char *semi = strchr (bol, ';');
          if (semi)
            *semi = 0;
-         site_list[nmirrors].url = _strdup (bol);
-         site_list[nmirrors].displayed_url = _strdup (bol);
-         char *dot = strchr (site_list[nmirrors].displayed_url, '.');
-         if (dot)
-           {
-             dot = strchr (dot, '/');
-             if (dot)
-               *dot = 0;
-           }
-         site_list[nmirrors].key =
-           (char *) malloc (2 * strlen (bol) + 3);
-
-         dot = site_list[nmirrors].displayed_url;
-         dot += strlen (dot);
-         char *dp = site_list[nmirrors].key;
-         while (dot != site_list[nmirrors].displayed_url)
-           {
-             if (*dot == '.' || *dot == '/')
-               {
-                 char *sp;
-                 if (dot[3] == 0)
-                   *dp++ = '~';        /* sort .com/.edu/.org together */
-                 for (sp = dot + 1; *sp && *sp != '.' && *sp != '/';)
-                   *dp++ = *sp++;
-                 *dp++ = ' ';
-               }
-             dot--;
-           }
-         *dp++ = ' ';
-         strcpy (dp, site_list[nmirrors].displayed_url);
-
-         nmirrors++;
+         site_list_type *newsite = new site_list_type (bol);
+         site_list_type & listobj =
+           all_site_list.registerbyobject (*newsite);
+         if (&listobj != newsite)
+           /* That site was already registered */
+           delete newsite;
        }
     }
-  site_list[nmirrors].url = 0;
-  delete[] mirrors;
-
-  qsort (site_list, nmirrors, sizeof (site_list_type), site_sort);
+  delete[]mirrors;
 
   return 0;
 }
@@ -267,43 +270,54 @@ get_site_list (HINSTANCE h)
 #define NOSAVE3_LEN (sizeof ("ftp://gcc.gnu.org/") - 1)
 
 static void
-get_initial_list_idx ()
+get_saved_sites ()
 {
   io_stream *f = io_stream::open ("cygfile:///etc/setup/last-mirror", "rt");
   if (!f)
     return;
 
   char site[1000];
-  char *fg_ret = f->gets (site, 1000);
-  delete f;
-  if (!fg_ret)
-    return;
+  char *fg_ret;
+  while ((fg_ret = f->gets (site, 1000)))
+    {
 
-  char *eos = site + strlen (site) - 1;
-  while (eos >= site && (*eos == '\n' || *eos == '\r'))
-    *eos-- = '\0';
+      char *eos = site + strlen (site) - 1;
+      while (eos >= site && (*eos == '\n' || *eos == '\r'))
+       *eos-- = '\0';
 
-  if (eos < site)
-    return;
+      if (eos < site)
+       continue;
 
-  int i;
-  for (i = 0; site_list[i].url; i++)
-    if (strcmp (site_list[i].url, site) == 0)
-      break;
+      bool found = false;
+      for (size_t i = 1; !found && i <= all_site_list.number (); i++)
+       if (!strcasecmp (site, all_site_list[i]->url))
+         found = true;
 
-  if (!site_list[i].url)
-    {
-      /* Don't default to certain machines ever since they suffer
-         from bandwidth limitations. */
-      if (strnicmp (site, NOSAVE1, NOSAVE1_LEN) == 0
-         || strnicmp (site, NOSAVE2, NOSAVE2_LEN) == 0
-         || strnicmp (site, NOSAVE3, NOSAVE3_LEN) == 0)
-       return;
-      site_list[i].displayed_url = site_list[i].url = _strdup (site);
-      site_list[i + 1].url = 0;
+      if (!found)
+       {
+         /* Don't default to certain machines ever since they suffer
+            from bandwidth limitations. */
+         if (strnicmp (site, NOSAVE1, NOSAVE1_LEN) == 0
+             || strnicmp (site, NOSAVE2, NOSAVE2_LEN) == 0
+             || strnicmp (site, NOSAVE3, NOSAVE3_LEN) == 0)
+           return;
+         site_list_type *newsite = new site_list_type (site);
+         site_list_type & listobj =
+           all_site_list.registerbyobject (*newsite);
+         if (&listobj != newsite)
+           /* That site was already registered - shouldn't happen, but safety first */
+           delete newsite;
+       }
+      /* TODO: make a site_type method to create a serach key on-the-fly from a 
+         URL
+       */
+      found = false;
+      for (size_t i = 1; !found && i <= all_site_list.number (); i++)
+       if (!strcasecmp (site, all_site_list[i]->url))
+         site_list.registerbyobject (*all_site_list[i]);
     }
+  delete f;
 
-  mirror_idx = list_idx = i;
 }
 
 void
@@ -311,19 +325,19 @@ do_site (HINSTANCE h)
 {
   int rv = 0;
 
-  if (site_list == 0)
+  if (all_site_list.number () == 0)
     if (get_site_list (h))
       {
        NEXT (IDD_NET);
        return;
       }
 
-  get_initial_list_idx ();
+  get_saved_sites ();
 
   rv = DialogBox (h, MAKEINTRESOURCE (IDD_SITE), 0, dialog_proc);
   if (rv == -1)
     fatal (IDS_DIALOG_FAILED);
 
-  if (mirror_idx != OTHER_IDX)
-    log (0, "site: %s", mirror_site);
+  for (size_t n = 1; n <= site_list.number (); n++)
+    log (0, "site: %s", site_list[n]->url);
 }
diff --git a/site.h b/site.h
new file mode 100644 (file)
index 0000000..3c1acb8
--- /dev/null
+++ b/site.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2001, Robert Collins.
+ *
+ *     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 Robert Collins <rbtcollins@hotmail.com>
+ *
+ */
+
+#ifndef _SITE_H_
+#define _SITE_H_
+
+/* required to parse this file */
+#include <strings.h>
+#include "list.h"
+
+class site_list_type
+{
+public:
+  site_list_type () : url(0), displayed_url (0), key (0) {};
+  site_list_type (char const *);
+  /* workaround for missing placement new in gcc 2.95 */
+  void init (char const *);
+  ~site_list_type () 
+  {
+    if (url)
+      free (url);
+    if (displayed_url)
+      free (displayed_url);
+    if (key)
+      free (key);
+  };
+  char *url;
+  char *displayed_url;
+  char *key;
+};
+
+/* user chosen sites */
+extern list <site_list_type, const char *, strcasecmp> site_list;
+/* potential sites */
+extern list <site_list_type, const char *, strcasecmp> all_site_list;
+
+void save_site_url ();
+
+#endif /* _SITE_H_ */
diff --git a/state.h b/state.h
index d3fb88cd866d525f1321cbe58fc2627712327a4f..a33bc3ac29b87d899551bc7c68cda19b4534b89a 100644 (file)
--- a/state.h
+++ b/state.h
 /* 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. */
+   the various dialogs and used by the various actions. 
+   Note that this is deprecated. Persistent settings should be accessed
+   via a class that stores them cross-installs, and non-persistent settings
+   directly via the appropriate class. One of the reasons for this is that
+   non-trivial types would require this file to include appropriate headers,
+   making all of setup.exe rebuild for potentially minor changes.
+ */
 
 extern int source;
 
@@ -38,9 +46,4 @@ extern char *net_proxy_passwd;
 extern char *net_ftp_user;
 extern char *net_ftp_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/version.cc b/version.cc
new file mode 100644 (file)
index 0000000..5c0ddff
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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>
+ *
+ */
+
+#if 0
+static const char *cvsid =
+  "\n%%% $Id$\n";
+#endif
+
+#include "win32.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <ctype.h>
+
+#include "port.h"
+char *
+canonicalize_version (const char *v)
+{
+  static char nv[3][100];
+  static int idx = 0;
+  char *np;
+  const char *dp;
+  int i;
+
+  idx = (idx + 1) % 3;
+  np = nv[idx];
+
+  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[idx];
+}
This page took 0.065465 seconds and 5 git commands to generate.