From: Robert Collins Date: Fri, 30 Nov 2001 12:25:00 +0000 (+0000) Subject: 2001-11-30 Robert Collins X-Git-Tag: cygnus_cvs_20020108_pre~18 X-Git-Url: https://cygwin.com/git/?a=commitdiff_plain;h=4fe323f9c8c2f88e83976f5929d5ae263bbf22c0;p=cygwin-apps%2Fsetup.git 2001-11-30 Robert Collins * Makefile.in (OBJS): Remove category_list - it's not needed. * README: More wishlist updates. * category.cc (Category::Category): Initialise new members. (Categorycmp): New function. * category.h (Category): New member key for template use. * category_list.cc: Remove. * category_list.h: Remove. (Categorycmp): New function prototype. * choose.cc: Remove category_list - not needed. (set_action): Only show the 'source' option when the source is actually available. (add_required): Fix recursion limiter to 5. (fill_missing_category): Use list access. (default_trust): Ditto. (pick_line::paint): Ditto. (_view::init_headers): Ditto. (_view::insert_pkg): Ditto. (_view::insert_category): Ditto. (_view::click): Ditto. (set_view_mode): Ditto. (do_choose): Ditto. * cygpackage.h: Remove category_list - not needed. * geturl.cc (get_url_to_string): Fix null byte insertion. * inipatse.y: Remove category_list - not needed. (categories): Use list access. * package_db.cc: Ditto. * package_db.h: Remove category_list - not needed. (packagedb): Use the list template for categories. * package_meta.cc (add_category): Ditto. * package_meta.h (CategoryPackage): Link to the category as well. (packagemeta): Use a list of CategoryPackages instead of Categories for more memory efficient cross-referencing. --- diff --git a/ChangeLog b/ChangeLog index 844b872e..e5b0ccf8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,38 @@ +2001-11-30 Robert Collins + + * Makefile.in (OBJS): Remove category_list - it's not needed. + * README: More wishlist updates. + * category.cc (Category::Category): Initialise new members. + (Categorycmp): New function. + * category.h (Category): New member key for template use. + * category_list.cc: Remove. + * category_list.h: Remove. + (Categorycmp): New function prototype. + * choose.cc: Remove category_list - not needed. + (set_action): Only show the 'source' option when the source is actually + available. + (add_required): Fix recursion limiter to 5. + (fill_missing_category): Use list access. + (default_trust): Ditto. + (pick_line::paint): Ditto. + (_view::init_headers): Ditto. + (_view::insert_pkg): Ditto. + (_view::insert_category): Ditto. + (_view::click): Ditto. + (set_view_mode): Ditto. + (do_choose): Ditto. + * cygpackage.h: Remove category_list - not needed. + * geturl.cc (get_url_to_string): Fix null byte insertion. + * inipatse.y: Remove category_list - not needed. + (categories): Use list access. + * package_db.cc: Ditto. + * package_db.h: Remove category_list - not needed. + (packagedb): Use the list template for categories. + * package_meta.cc (add_category): Ditto. + * package_meta.h (CategoryPackage): Link to the category as well. + (packagemeta): Use a list of CategoryPackages instead of Categories + for more memory efficient cross-referencing. + 2001-11-30 Robert Collins * package_db.cc (packagedb::flush): Write a canonical version for all packages diff --git a/Makefile.in b/Makefile.in index 9ce84a09..99171f10 100644 --- a/Makefile.in +++ b/Makefile.in @@ -85,7 +85,6 @@ OBJS = \ archive_tar_file.o \ autoload.o \ category.o \ - category_list.o \ choose.o \ compress.o \ compress_bz.o \ diff --git a/README b/README index a7d64b35..ff2e3dc5 100644 --- a/README +++ b/README @@ -3,7 +3,7 @@ net releases. TODO: * Src tickbox /source only can be confusing. -* file magic detection. +* file magic detection. - partially complete. * support rpm/deb files for reading the package from. (To allow the maintainers the use of rpm/deb tools to create packages.) * make a librar(y|ies) for setup and cygcheck to use containing 1) Something to translate POSIX -> native. Currently called "cygpath" @@ -14,15 +14,15 @@ TODO: 4) Something to parse a tar file name into package/version or altenatively, return that information from 2) 5) Something to return a list of files associated with a package. -* Make skip only ever appear for non-installed packages. - - +* When installing and enough packages default to visible, te RH scrollbar is + sometimes hidden. + + WISHLIST: * rsync:// support * Some way to download *all* the source * When clicking on a category that is showing a partial list (auto added items due to dependencies) show the full list rather than minising. * continue downloading past errors, present log of failures at end - * skip sould be followed by the from the radio buttons, not by prev. * incremental/recoverable download capability. * build-depends * FTP control connections should be closed when we are awaiting user input. @@ -59,3 +59,5 @@ recently completed * View mdoe caption on the right hand of the screen * Downloading from the internet should allow redownloading already present files. (This happens via the reinstall/redo already - perhaps this is "done".) + * Make skip only ever appear for non-installed packages. + * skip sould be followed by the from the radio buttons, not by prev. diff --git a/category.cc b/category.cc index da4cdb4d..aec9b8fd 100644 --- a/category.cc +++ b/category.cc @@ -22,7 +22,7 @@ /* normal members */ -Category::Category ():next (0), name (0), packages (0) +Category::Category ():next (0), name (0), key (0), packages (0) { } @@ -32,4 +32,11 @@ packages (0) { /* FIXME: search the global category list for name, and reuse that pointer */ name = strdup (categoryname); + key = name; +} + +int +Categorycmp (Category & a, Category & b) +{ + return strcasecmp (a.name, b.name); } diff --git a/category.h b/category.h index d1e774ed..542dc2c4 100644 --- a/category.h +++ b/category.h @@ -28,8 +28,10 @@ public: Category *next; /* the next category in the list */ const char *name; /* the category */ + const char *key; /* always == name */ CategoryPackage *packages; /* the packages in this category */ }; +int Categorycmp (Category &, Category &); #endif /* _CATEGORY_H_ */ diff --git a/category_list.cc b/category_list.cc deleted file mode 100755 index 2918af39..00000000 --- a/category_list.cc +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 - * - */ - -/* categories for packages */ - -#include -#include - -#include "category_list.h" -#include "category.h" - -CategoryList::CategoryList ():_categories (0), ncategories (0), -categoriesspace (0) -{ -} - -Category & CategoryList::register_category (const char *catname) -{ - Category * - tempcat = - getcategorybyname (catname); - if (!tempcat) - { - if (ncategories == categoriesspace) - { - Category ** - newcategories = (Category **) - realloc (_categories, - sizeof (Category *) * (categoriesspace + 20)); - if (!newcategories) - { - //die - exit (100); - } - _categories = newcategories; - if (categoriesspace == 0) - _categories[0] = 0; - categoriesspace += 20; - } - tempcat = new Category (catname); - size_t n; - for (n = 0; - n < ncategories - && strcasecmp (_categories[n]->name, tempcat->name) < 0; n++); - /* insert at n */ - if (n) - _categories[n - 1]->next = tempcat; - if (n < ncategories) - tempcat->next = _categories[n]; - memmove (&_categories[n + 1], &_categories[n], - (ncategories - n) * sizeof (Category *)); - _categories[n] = tempcat; - ncategories++; - } - return *tempcat; -} - -Category * -CategoryList::getcategorybyname (const char *name) -{ - for (size_t n = 0; n < ncategories; n++) - if (strcasecmp (_categories[n]->name, name) == 0) - return _categories[n]; - return 0; -} diff --git a/category_list.h b/category_list.h deleted file mode 100755 index f51c5f47..00000000 --- a/category_list.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 - * - */ - -/* a list categories for packages */ - -#ifndef _CATEGORY_LIST_H_ -#define _CATEGORY_LIST_H_ - -class Category; - -class CategoryList -{ -public: - Category & register_category (const char *name); - Category *getcategorybyname (const char *name); - int categories () - { - return ncategories; - }; - Category *getfirstcategory () - { - return *_categories; - }; - CategoryList (); -private: - Category ** _categories; - size_t ncategories; - size_t categoriesspace; -}; - - -#endif /* _CATEGORY_LIST_H_ */ diff --git a/choose.cc b/choose.cc index e7efad41..0ac1779f 100644 --- a/choose.cc +++ b/choose.cc @@ -48,7 +48,6 @@ static const char *cvsid = #include "io_stream.h" #include "choose.h" #include "category.h" -#include "category_list.h" #include "package_db.h" #include "package_meta.h" @@ -97,7 +96,7 @@ static struct _header cat_headers[] = { {0, 0, 0, 0} }; -static int add_required (packagemeta & pkg, size_t depth=0); +static int add_required (packagemeta & pkg, size_t depth = 0); static void set_view_mode (HWND h, views mode); #define pkgtrustp(pkg,t) (packageversion *)(t==TRUST_PREV ? pkg->prev : t == TRUST_CURR ? pkg->curr : pkg->exp) @@ -176,9 +175,9 @@ 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 || pkg->desired->binpicked) + && (pkg->desired->src.Cached () || pkg->desired->src.sites.number ())) { - /* FIXME: is source available */ /* source only this file */ pkg->desired = pkg->installed; pkg->desired->binpicked = 0; @@ -243,7 +242,7 @@ add_required (packagemeta & pkg, size_t depth = 0) dp = pkg.desired->required; packagedb db; /* cheap test for too much recursion */ - if (depth > db.npackages ()) + if (depth > 5) return 0; while (dp) { @@ -539,8 +538,8 @@ fill_missing_category () packagedb db; for (packagemeta * pkg = db.getfirstpackage (); pkg; pkg = db.getnextpackage ()) - if (!pkg->Categories ().categories ()) - pkg->add_category (db.categories.register_category ("Misc")); + if (!pkg->Categories.number ()) + pkg->add_category (db.categories.registerbykey ("Misc")); } static void @@ -551,8 +550,9 @@ default_trust (HWND h, trusts trust) for (packagemeta * pkg = db.getfirstpackage (); pkg; pkg = db.getnextpackage ()) { - if (pkg->installed || pkg->Categories ().getcategorybyname ("Base") - || pkg->Categories ().getcategorybyname ("Misc")) + if (pkg->installed + || pkg->Categories.getbykey (db.categories.registerbykey ("Base")) + || pkg->Categories.getbykey (db.categories.registerbykey ("Misc"))) { pkg->desired = pkgtrustp (pkg, trust); if (pkg->desired) @@ -628,10 +628,10 @@ pick_line::paint (HDC hdc, int x, int y, int row, int show_cat) bitmap_dc, 0, 0, SRCCOPY); /* shows "first" category - do we want to show any? */ - if (pkg->Categories ().getfirstcategory () && show_cat) + if (pkg->Categories.number () && show_cat) TextOut (hdc, x + chooser->headers[chooser->cat_col].x, r, - pkg->Categories ().getfirstcategory ()->name, - strlen (pkg->Categories ().getfirstcategory ()->name)); + pkg->Categories.getnth (1)->key.name, + strlen (pkg->Categories.getnth (1)->key.name)); if (!pkg->SDesc ()) s = pkg->name; @@ -775,9 +775,8 @@ _view::init_headers (HDC dc) note_width (headers, dc, pkg->versions.getnth (n)->Canonical_version (), NEW_COL_SIZE_SLOP, new_col); - for (Category * cat = db.categories.getfirstcategory (); cat; - cat = cat->next) - note_width (headers, dc, cat->name, 0, cat_col); + for (size_t n = 1; n <= db.categories.number (); n++) + note_width (headers, dc, db.categories.getnth (n)->name, 0, cat_col); if (!pkg->SDesc ()) note_width (headers, dc, pkg->name, 0, pkg_col); else @@ -811,7 +810,7 @@ _view::insert_pkg (packagemeta & pkg) { lines = (pick_line *) calloc (db.npackages () + - db.categories.categories (), + db.categories.number (), sizeof (pick_line)); nlines = 0; insert_at (0, line); @@ -822,9 +821,9 @@ _view::insert_pkg (packagemeta & pkg) else { // assert (lines); /* protect against a coding change in future */ - for (Category * cat = pkg.Categories ().getfirstcategory (); cat; - cat = cat->next) + for (size_t x = 1; x <= pkg.Categories.number (); x++) { + Category & cat = pkg.Categories.getnth (x)->key; /* insert the package under this category in the list. If this category is not visible, add it */ int n = 0; @@ -832,7 +831,7 @@ _view::insert_pkg (packagemeta & pkg) { /* this should be a generic call to list_sort_cmp */ if (lines[n].get_category () - && cat->name == lines[n].get_category ()->name) + && !strcasecmp (cat.name, lines[n].get_category ()->name)) { insert_under (n, line); n = nlines; @@ -842,7 +841,7 @@ _view::insert_pkg (packagemeta & pkg) if (n == nlines) { /* the category wasn't visible - insert at the end */ - insert_category (cat, CATEGORY_COLLAPSED); + insert_category (&cat, CATEGORY_COLLAPSED); insert_pkg (pkg); } } @@ -858,17 +857,17 @@ _view::insert_category (Category * cat, int collapsed) { packagedb db; lines = - (pick_line *) malloc ((db.npackages () + db.categories.categories ()) + (pick_line *) malloc ((db.npackages () + db.categories.number ()) * sizeof (pick_line)); memset (lines, '\0', (db.npackages () + - db.categories.categories ()) * sizeof (pick_line)); + db.categories.number ()) * sizeof (pick_line)); nlines = 0; insert_at (0, line); if (!collapsed) for (CategoryPackage * catpkg = cat->packages; catpkg; catpkg = catpkg->next) - insert_pkg (catpkg->pkg); + insert_pkg (*catpkg->pkg); } else { @@ -883,7 +882,7 @@ _view::insert_category (Category * cat, int collapsed) if (!collapsed) for (CategoryPackage * catpkg = cat->packages; catpkg; catpkg = catpkg->next) - insert_pkg (catpkg->pkg); + insert_pkg (*catpkg->pkg); n = nlines; } else if (lines[n].get_category () == cat) @@ -898,7 +897,7 @@ _view::insert_category (Category * cat, int collapsed) if (!collapsed) for (CategoryPackage * catpkg = cat->packages; catpkg; catpkg = catpkg->next) - insert_pkg (catpkg->pkg); + insert_pkg (*catpkg->pkg); } } } @@ -1013,7 +1012,7 @@ _view::click (int row, int x) lines[row].get_category ()->packages; catpkg; catpkg = catpkg->next) { - packagemeta & pkg = catpkg->pkg; + packagemeta & pkg = *catpkg->pkg; int n = row + 1; pick_line line; line.set_line (&pkg); @@ -1074,8 +1073,9 @@ set_view_mode (HWND h, views mode) case VIEW_PACKAGE: for (packagemeta * pkg = db.getfirstpackage (); pkg; pkg = db.getnextpackage ()) - if ((!pkg->desired && pkg->installed) || (pkg->desired && (pkg->desired->srcpicked - || pkg->desired->binpicked))) + if ((!pkg->desired && pkg->installed) + || (pkg->desired + && (pkg->desired->srcpicked || pkg->desired->binpicked))) chooser->insert_pkg (*pkg); break; case VIEW_PACKAGE_FULL: @@ -1085,9 +1085,9 @@ set_view_mode (HWND h, views mode) break; case VIEW_CATEGORY: /* start collapsed. TODO: make this a chooser flag */ - for (Category * cat = db.categories.getfirstcategory (); cat; - cat = cat->next) - chooser->insert_category (cat, CATEGORY_COLLAPSED); + for (size_t n = 1; n <= db.categories.number (); n++) + chooser->insert_category (db.categories.getnth (n), + CATEGORY_COLLAPSED); break; default: break; @@ -1519,27 +1519,23 @@ do_choose (HINSTANCE h) " src?=%s", pkg->name, action, trust, installed, pkg->desired && pkg->desired->srcpicked ? "yes" : "no"); - if (pkg->Categories ().categories ()) + if (pkg->Categories.number ()) { /* List categories the package belongs to */ int categories_len = 0; - Category *cp; - for (cp = pkg->Categories ().getfirstcategory (); cp; cp = cp->next) - if (cp->name) - categories_len += strlen (cp->name) + 2; + for (size_t n = 1; n <= pkg->Categories.number (); n++) + categories_len += + strlen (pkg->Categories.getnth (n)->key.name) + 2; if (categories_len > 0) { char *categories = (char *) malloc (categories_len); - strcpy (categories, - pkg->Categories ().getfirstcategory ()->name); - for (cp = pkg->Categories ().getfirstcategory ()->next; cp; - cp = cp->next) - if (cp->name) - { - strcat (categories, ", "); - strcat (categories, cp->name); - } + strcpy (categories, pkg->Categories.getnth (1)->key.name); + for (size_t n = 2; n <= pkg->Categories.number (); n++) + { + strcat (categories, ", "); + strcat (categories, pkg->Categories.getnth (n)->key.name); + } log (LOG_BABBLE, " categories=%s", categories); free (categories); } diff --git a/cygpackage.h b/cygpackage.h index 5e306894..f1445319 100644 --- a/cygpackage.h +++ b/cygpackage.h @@ -20,8 +20,6 @@ #ifndef _CYGPACKAGE_H_ #define _CYGPACKAGE_H_ -#include "category_list.h" - class cygpackage:public packageversion { public: diff --git a/geturl.cc b/geturl.cc index 0144996f..2e985ce9 100644 --- a/geturl.cc +++ b/geturl.cc @@ -215,24 +215,24 @@ get_url_to_string (char *_url) if (n->file_size) max_bytes = n->file_size; - io_stream_memory * membuf = new io_stream_memory (); - + io_stream_memory *membuf = new io_stream_memory (); + int total_bytes = 1; /* for the NUL terminator */ progress (0); while (1) { char buf[2048]; - ssize_t rlen,wlen; + ssize_t rlen, wlen; rlen = n->read (buf, 2048); if (rlen > 0) - { - wlen = membuf->write (buf, rlen); - if (wlen != rlen) - /* FIXME: Show an error message */ - break; - total_bytes += rlen; - progress (total_bytes); - } + { + wlen = membuf->write (buf, rlen); + if (wlen != rlen) + /* FIXME: Show an error message */ + break; + total_bytes += rlen; + progress (total_bytes); + } else break; } @@ -247,10 +247,10 @@ get_url_to_string (char *_url) log (LOG_BABBLE, "get_url_to_string(): malloc failed for rv!"); return 0; } - + ssize_t rlen; - rlen = membuf->read (rv, total_bytes); - rv [total_bytes] = '\0'; + rlen = membuf->read (rv, total_bytes - 1); + rv[total_bytes - 1] = '\0'; if (n) delete n; if (membuf) diff --git a/iniparse.y b/iniparse.y index e9f1b216..b2a7be34 100644 --- a/iniparse.y +++ b/iniparse.y @@ -23,7 +23,6 @@ #include "win32.h" #include "package_db.h" #include "category.h" -#include "category_list.h" #include "ini.h" #include "iniparse.h" #include "filemanip.h" @@ -139,9 +138,9 @@ requires ; categories - : STRING { cp->add_category (db.categories.register_category ($1)); + : STRING { cp->add_category (db.categories.registerbykey ($1)); } categories - | STRING { cp->add_category (db.categories.register_category ($1)); } + | STRING { cp->add_category (db.categories.registerbykey ($1)); } ; %% diff --git a/package_db.cc b/package_db.cc index 0c609234..8645ae3c 100644 --- a/package_db.cc +++ b/package_db.cc @@ -245,15 +245,11 @@ packagemeta & packagedb::registerpackage (char const *pkgname) packagemeta ** packagedb::packages = 0; -size_t - packagedb::packagecount = - 0; -size_t - packagedb::packagespace = - 0; +size_t packagedb::packagecount = 0; +size_t packagedb::packagespace = 0; int packagedb::installeddbread = 0; -CategoryList - packagedb::categories = - CategoryList (); +list < Category, char const *, + strcasecmp > + packagedb::categories; diff --git a/package_db.h b/package_db.h index 08a183b2..64300270 100644 --- a/package_db.h +++ b/package_db.h @@ -16,7 +16,10 @@ #ifndef _PACKAGE_DB_H_ #define _PACKAGE_DB_H_ -class CategoryList; +/* required to parse this file */ +#include "list.h" +//class CategoryList; +class Category; class packagemeta; class io_stream; @@ -39,7 +42,7 @@ public: return packagecount; }; /* all seen categories */ - static CategoryList categories; + static list < Category, char const *, strcasecmp > categories; private: /* this gets sorted */ static packagemeta **packages; diff --git a/package_meta.cc b/package_meta.cc index cb9477b1..37d3f2dd 100644 --- a/package_meta.cc +++ b/package_meta.cc @@ -144,13 +144,8 @@ void packagemeta::add_category (Category & cat) { /* add a new record for the package list */ - /* TODO: alpabetical inserts ? */ - categories.register_category (cat.name); - - CategoryPackage *templink = new CategoryPackage (*this); - /* tell the category we are linking from we exist */ - templink->next = cat.packages; - cat.packages = templink; + CategoryPackage & catpack = Categories.registerbykey (cat); + catpack.pkg = this; } char const * diff --git a/package_meta.h b/package_meta.h index 8af4390c..68c6e31d 100644 --- a/package_meta.h +++ b/package_meta.h @@ -18,22 +18,26 @@ class packageversion; class packagemeta; +class category; /* Required to parse this completely */ -#include "category_list.h" #include "list.h" #include "strings.h" +#include "category.h" /* For cleanliness this may need to be put in its own file later. */ class CategoryPackage { public: - CategoryPackage (packagemeta & package):next (0), pkg (package) + CategoryPackage (Category & cat):key (cat), pkg (0) { + next = cat.packages; + cat.packages = this; }; + Category & key; CategoryPackage *next; /* The next package pointer in the list */ - packagemeta & pkg; + packagemeta *pkg; }; @@ -85,13 +89,8 @@ public: /* what categories does this package belong in. Note that if multiple versions * of a package disagree.... the first one read in will take precedence. */ - CategoryList & Categories () - { - return categories; - }; - /* Add a known category to this objects category list. - */ void add_category (Category &); + list < CategoryPackage, Category &, Categorycmp > Categories; list < packageversion, char const *, strcasecmp > versions; /* which one is installed. */ @@ -109,8 +108,6 @@ public: /* Now for the user stuff :] */ /* What version does the user want ? */ packageversion *desired; -private: - CategoryList categories; }; #endif /* _PACKAGE_META_H_ */