]> cygwin.com Git - cygwin-apps/setup.git/commitdiff
2002-02-19 Robert Collins <rbtcollins@hotmail.com>
authorRobert Collins <rbtcollins@hotmail.com>
Mon, 18 Feb 2002 12:35:23 +0000 (12:35 +0000)
committerRobert Collins <rbtcollins@hotmail.com>
Mon, 18 Feb 2002 12:35:23 +0000 (12:35 +0000)
* Makefile.in (OBJS): Add new object.
* PickCategoryLine.cc (PickCategoryLine::paint): Print a "+" before the name.
* PickCategoryLine.h (PickCategoryLine::bucket): Use the String class.
* PickLine.h (Pickline::key): Change to a String to help plug leaks.
(PickLine::Pickline): Accept a String for the key.
* PickPackageLine.cc (PickPackageLine::paint): Convert all char use to Strings.
* PickPackageLine.h (PickPackageLine::PickPackageLine): The key is automatically
initialisednow.
* PickView.cc (PickView::note_width): Convert all char * use to Strings.
(PickView::init_header): Move category length checking out of the inner loop for
efficiency.
Convert all char use to Strings.
* PickView.h: Include the String++ header.
(PickView::note_width): Update the prototype.
* String++.cc: New file, implements a reference counting string class.
* String++.h: New file, declares a reference counting string class.
* archive.cc: Include String++ instead of concat.
(archive::extract_file): Convert char * usage to Strings.
* archive.h: Inlude the String++ header.
(archive::extract_file): Update prototype.
(archive::next_file_name): Convert to a String.
(archive::linktarget): Ditto.
* archive_tar.cc (archive_tar::next_file_name): Convert to String usage.
(archive_tar::linktarget): Ditto.
* arhive_tar.h: Update the copyright.
Explicitly include the relevant headers.
(tar_map_result_type): Convert to String usage.
(archive_tar::next_file_name): Update prototype.
(archive_tar::linktarget): Ditto.
* category.cc (Category::Category): Update initialisers.
Convert to String usage.
(Categorycmp): Update to String usage.
* category.h: Include the String++ header.
(Category::Category): Update to String usage.
(Category::name): Ditto.
(Category::key): Ditto.
* choose.cc: Remove concat.h, it's not needed.
(scan2): Update to String usage.
(do_choose): Ditto.
* cygpackage.cc: Update includes for use of String class.
(cygpackage::cygpackage): Update for String usage.
(cygpackage::set_canonical_version): Ditto.
(cygpackage::destroy): Ditto.
(cygpackage::getfirstfile): Ditto.
(cygpackage::getnextfile): Ditto.
(cygpackage::Name): Ditto.
(cygpackage::Vendor_version): Ditto.
(cygpackage::Package_version): Ditto.
(cygpackage::Canonical_version): Ditto.
(cygpackage::set_sdesc): Ditto.
(cygpackage::set_ldesc): Ditto.
* cygpackage.h: Include String++.h for parsing this file.
(cygpackage::cygpackage): Update for String usage.
(cygpackage::set_canonical_version): Ditto.
(cygpackage::destroy): Ditto.
(cygpackage::getfirstfile): Ditto.
(cygpackage::getnextfile): Ditto.
(cygpackage::Name): Ditto.
(cygpackage::Vendor_version): Ditto.
(cygpackage::Package_version): Ditto.
(cygpackage::Canonical_version): Ditto.
(cygpackage::set_sdesc): Ditto.
(cygpackage::set_ldesc): Ditto.
(cygpackage::name): Ditto.
(cygpackage::vendor): Ditto.
(cygpackage::packagev): Ditto.
(cygpackage::canonical): Ditto.
(cygpackage::fn): Ditto.
(cygpackage::sdesc): Ditto.
(cygpackage::ldesc): Ditto.
* desktop.cc: Update includes for use of String class.
(batname): Update for String usage.
(iconname): Ditto.
(make_link): Ditto.
(start)menu): Ditto.
(desktop_icon): Ditto.
(make_cygwin_bat): Ditto.
(make_etc_profile): Ditto.
(uexists): Ditto.
(make_passwd_group): Ditto.
(save_icon): Ditto.
(check_desktop): Ditto.
(check_startmenu): Ditto.
* dialog.cc (eget): Update for String usage.
(egetString): New function.
(eset): New variant for Strings.
* dialog.h: Include String++.h for parsing this file.
(egetString): New function.
(eset): New variant for Strings.
* diskfull.cc (diskfull): Update for String usage.
* diskfull.h: Include String++.h for parsing this file.
(diskfull): Update for String usage.
* download.cc: Update includes for use of String class.
(check_for_cached): Update for String usage.
(download_one): Ditto.
* filemanip.cc (get_file_size): Ditto.
(base): Ditto.
(parse_filename): Ditto.
(backslash): Ditto.
* filemanip.h: Include String++.h for parsing this file.
(fileparse): Update for String usage.
(base): Ditto.
(parse_filename): Ditto.
Don't consider '_' to be a separator.
(backslash): Ditto.
* find.cc: Update includes for use of String class.
(find_sub): Make more flexible.
(find): Update for String usage.
* find.h (find): Use Strings.
* fromcwd.cc (found_file): Update for String usage.
* geturl.cc: Ditto.
(init_dialog): Ditto.
(get_url_to_membuf): Ditto.
(get_url_to_string): Ditto.
(get_url_to_file): Ditto.
* geturl.h: Ditto.
(get_url_to_membuf): Ditto.
(get_url_to_string): Ditto.
(get_url_to_file): Ditto.
* hash.h: Ditto.
(add_subdirs): Ditto.
* ini.cc: Update includes for String usage.
(find_routine): Update for String usage.
(do_remote_ini): Ditto.
(do_ini_thread): Ditto.
* ini.h (ini_init): Ditto.
* inilex.l: Update includes for String usage.
(ini_init): Update for String usage.
* iniparse.y: Ditto.
(add_correct_version): Ditto.
* install.cc: Update includes for String usage.
(install_one_source): Update for String usage.
(uninstall_one): Ditto.
(replace_one): Ditto.
(install_one_source): Ditto.
(do_install_thread): Ditto.
* io_stream.cc: Update includes for String usage.
(io_stream::open): Update for String usage.
(io_stream::mkpath_p): Ditto.
(io_stream::remove): Ditto.
(io_stream::mklink): Ditto.
(io_stream::move_copy): Ditto.
(io_stream::move): Ditto.
(io_stream::exists): Ditto.
* io_stream.h: Update includes to allow correct parsing.
(io_stream::open): Update for String usage.
(io_stream::mkpath_p): Ditto.
(io_stream::remove): Ditto.
(io_stream::mklink): Ditto.
(io_stream::move_copy): Ditto.
(io_stream::move): Ditto.
(io_stream::exists): Ditto.
* io_stream_cygfile.cc: Update includes for String usage.
(get_root_dir_now): Update for String usage.
(io_stream_cygfile::io_stream_cygfile): Ditto.
(io_stream_cygfile::~io_stream_cygfile): Ditto.
(io_stream_cygfile::exists): Ditto.
(io_stream_cygfile::remove): Ditto.
(io_stream_cygfile::mklink): Ditto.
(cygmkdir_p): Ditto.
(io_stream_cygfile::set_mtime): Ditto.
(io_stream_cygfile::move): Ditto.
(io_stream_cygfile::get_size): Ditto.
* io_stream_cygfile.h: Update includes for String usage.
(io_stream_cygfile::io_stream_cygfile): Update for String usage.
(io_stream_cygfile::~io_stream_cygfile): Ditto.
(io_stream_cygfile::exists): Ditto.
(io_stream_cygfile::remove): Ditto.
(io_stream_cygfile::mklink): Ditto.
(cygmkdir_p): Ditto.
(io_stream_cygfile::set_mtime): Ditto.
(io_stream_cygfile::move): Ditto.
(io_stream_cygfile::get_size): Ditto.
(io_stream_cygfile::fname): Ditto.
(io_stream_cygfile::lmode): Ditto.
* io_stream_file.cc: Update includes for String usage.
(io_stream_file::io_stream_file): Update for String usage.
(io_stream_file::~io_stream_file): Ditto.
(io_stream_file::exists): Ditto.
(io_stream_file::remove): Ditto.
(io_stream_file::mklink): Ditto.
(io_stream_file::set_mtime): Ditto.
(io_stream_file::move): Ditto.
(io_stream_file::get_size): Ditto.
* io_stream_file.h: Update includes for String usage.
* io_stream_file.cc: Update includes for String usage.
(io_stream_file::io_stream_file): Update for String usage.
(io_stream_file::~io_stream_file): Ditto.
(io_stream_file::exists): Ditto.
(io_stream_file::remove): Ditto.
(io_stream_file::mklink): Ditto.
(io_stream_file::set_mtime): Ditto.
(io_stream_file::move): Ditto.
(io_stream_file::get_size): Ditto.
(io_stream_file::fname): Ditto.
(io_stream_file::lmode): Ditto.
* localdir.cc: Update includes for String usage.
(save_local_dir): Update for String usage.
(check_if_enable_next): Ditto.
(load_dialog): Ditto.
(browse_cb): Ditto.
(LocalDirPage::OnInit): Ditto.
(LocalDirPage::OnNext): Ditto.
* log.cc: Update includes for String usage.
(struct LogEnt): Update for String usage.
(log): Ditto.
(log_save): Ditto.
(exit_setup): Ditto.
* log.h: Update includes for String usage.
(log_level): Update for String usage.
(log): Ditto.
(log_save): Ditto.
* main.cc (WinMain): Update for String usage.
* mklink2.c (make_link_2): Update for String usage.
* mklink2.h (make_link_2): Update for String usage.
* mount.cc: Update includes for String usage.
(mount_table): Update for String usage.
(find2): Ditto.
(create_mount): Ditto.
(remove1): Ditto.
(remove_mount): Ditto.
(read_mounts): Ditto.
(set_root_dir): Ditto.
(get_root_dir): Ditto.
(path_prefix_p): Ditto.
(cygpath): Ditto.
* mount.h: Update includes for String usage.
(create_mount): Update for String usage.
(remove_mount): Ditto.
(cygpath): Ditto.
(set_root_dir): Ditto.
(get_root_dir): Ditto.
* msg.cc (mbox): Ditto.
* net.cc (NetPage::OnNext): Ditto.
* package_db.cc (packagedb::flush): Ditto.
(packagedb::packages): Ditto.
(packagedb::categories): Ditto.
* package_db.h: Update includes for String usage.
(packagedb::packages): Update for String usage.
(packagedb::categories): Ditto.
* package_meta.cc: Update includes for String usage.
(hash::add_subdirs): Update for String usage.
(packagemeta::uninstall): Ditto.
(packagemeta::SDesc): Ditto.
(packagemeta::action_caption): Ditto.
* package_meta.h: Update includes for String usage.
(packagemeta::packagemeta): Update for String usage.
(packagemeta::~packagemeta): Ditto.
(packagemeta::uninstall): Ditto.
(packagemeta::SDesc): Ditto.
(packagemeta::action_caption): Ditto.
(package_source.cc site::site): Ditto.
(packagesource::set_canonical): Ditto.
(packagesource::set_cached): Ditto.
* package_source.h: Update includes for String usage.
(site::site): Update for String usage.
(packagesource::set_canonical): Ditto.
(packagesource::set_cached): Ditto.
(packagesource::packagesource): Ditto.
(packagesource::sites): Ditto.
(packagesource::cached): Ditto.
* package_version.h: Update includes for String usage.
(Dependency): Update for String usage.
(packageversion): Ditto.
* postinstall.cc: Update includes for String usage.
(do_postinstall): Update for String usage.
* res.rc (IDD_LOCAL_DIR): Fix typo again!
* rfc1738.cc (rfc1738_escape_part): Update for String usage.
* rfc1738.h: Update includes for String usage.
(rfc1738_escape_part): Update for String usage.
* root.cc: Update includes for String usage.
(check_if_enable_next): Update for String usage.
(save_dialog): Ditto.
(browse_cb): Ditto.
(directory_is_absolute): Ditto.
(directory_is_rootdir): Ditto.
(directory_has_spaces): Ditto.
(RootPage::OnInit): Ditto.
(RootPage::OnNext): Ditto.
* script.cc: Update includes for String usage.
(init_run_script): Update for String usage.
(run): Ditto.
(run_script): Ditto.
(try_run_script): Ditto.
* script.h: Update includes for String usage.
(run_script): Update for String usage.
(try_run_script): Ditto.
* site.cc site_list): Ditto.
(all_site_list): Ditto.
(other_url): Eliminate.
(site_list_type::init): Update for String usage.
(site_list_type::site_list_type): Ditto.
(get_site_list): Ditto.
(get_saved_sites): Ditto.
(do_download_site_info_thread): Ditto.
(SitePage::OnNext): Ditto.
(SitePage::OnActivate): Ditto.
(SitePage::PopulateListBox): Ditto.
(SitePage::OnMessageCmd): Handle empty url's.
* site.h: Update includes for String usage.
(site_list_type::site_list_type): Update for String usage.
(site_list_type::init): Ditto.
(site_list_type::~site_list_type): Ditto.
(site_list_type::url): Ditto.
(site_list_type::displayed_url): Ditto.
(site_list_type::key): Ditto.
* source.cc (SourcePage::OnDeactivate): Ditto.
* state.h: Update includes for String usage.
(local_dir): Update for String usage.
(trust_level): Remove.
* version.cc: Update includes for String usage.
(canonicalize_version): Update for String usage.
* version.h: Update includes for String usage.
(canonicalize_version): Update for String usage.

75 files changed:
ChangeLog
Makefile.in
PickCategoryLine.cc
PickCategoryLine.h
PickLine.h
PickPackageLine.cc
PickPackageLine.h
PickView.cc
PickView.h
String++.cc [new file with mode: 0644]
String++.h [new file with mode: 0644]
archive.cc
archive.h
archive_tar.cc
archive_tar.h
category.cc
category.h
choose.cc
cygpackage.cc
cygpackage.h
desktop.cc
dialog.cc
dialog.h
diskfull.cc
diskfull.h
download.cc
filemanip.cc
filemanip.h
find.cc
find.h
fromcwd.cc
geturl.cc
geturl.h
hash.h
ini.cc
ini.h
inilex.l
iniparse.y
install.cc
io_stream.cc
io_stream.h
io_stream_cygfile.cc
io_stream_cygfile.h
io_stream_file.cc
io_stream_file.h
localdir.cc
log.cc
log.h
main.cc
mklink2.c
mklink2.h
mount.cc
mount.h
msg.cc
net.cc
package_db.cc
package_db.h
package_meta.cc
package_meta.h
package_source.cc
package_source.h
package_version.h
postinstall.cc
res.rc
rfc1738.cc
rfc1738.h
root.cc
script.cc
script.h
site.cc
site.h
source.cc
state.h
version.cc
version.h

index d3496d80a41b815f4a8f1ac0696853d5fa67002a..ea0bdb4cd5ec1cc0befbdcea124edb3b20cd9273 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,320 @@
+2002-02-19  Robert Collins  <rbtcollins@hotmail.com>
+
+       * Makefile.in (OBJS): Add new object.
+       * PickCategoryLine.cc (PickCategoryLine::paint): Print a "+" before the name.
+       * PickCategoryLine.h (PickCategoryLine::bucket): Use the String class.
+       * PickLine.h (Pickline::key): Change to a String to help plug leaks.
+       (PickLine::Pickline): Accept a String for the key.
+       * PickPackageLine.cc (PickPackageLine::paint): Convert all char use to Strings.
+       * PickPackageLine.h (PickPackageLine::PickPackageLine): The key is automatically
+       initialisednow.
+       * PickView.cc (PickView::note_width): Convert all char * use to Strings.
+       (PickView::init_header): Move category length checking out of the inner loop for
+       efficiency.
+       Convert all char use to Strings.
+       * PickView.h: Include the String++ header.
+       (PickView::note_width): Update the prototype.
+       * String++.cc: New file, implements a reference counting string class.
+       * String++.h: New file, declares a reference counting string class.
+       * archive.cc: Include String++ instead of concat.
+       (archive::extract_file): Convert char * usage to Strings.
+       * archive.h: Inlude the String++ header.
+       (archive::extract_file): Update prototype.
+       (archive::next_file_name): Convert to a String.
+       (archive::linktarget): Ditto.
+       * archive_tar.cc (archive_tar::next_file_name): Convert to String usage.
+       (archive_tar::linktarget): Ditto.
+       * arhive_tar.h: Update the copyright.
+       Explicitly include the relevant headers.
+       (tar_map_result_type): Convert to String usage.
+       (archive_tar::next_file_name): Update prototype.
+       (archive_tar::linktarget): Ditto.
+       * category.cc (Category::Category): Update initialisers.
+       Convert to String usage.
+       (Categorycmp): Update to String usage.
+       * category.h: Include the String++ header.
+       (Category::Category): Update to String usage.
+       (Category::name): Ditto.
+       (Category::key): Ditto.
+       * choose.cc: Remove concat.h, it's not needed.
+       (scan2): Update to String usage.
+       (do_choose): Ditto.
+       * cygpackage.cc: Update includes for use of String class.
+       (cygpackage::cygpackage): Update for String usage.
+       (cygpackage::set_canonical_version): Ditto.
+       (cygpackage::destroy): Ditto.
+       (cygpackage::getfirstfile): Ditto.
+       (cygpackage::getnextfile): Ditto.
+       (cygpackage::Name): Ditto.
+       (cygpackage::Vendor_version): Ditto.
+       (cygpackage::Package_version): Ditto.
+       (cygpackage::Canonical_version): Ditto.
+       (cygpackage::set_sdesc): Ditto.
+       (cygpackage::set_ldesc): Ditto.
+       * cygpackage.h: Include String++.h for parsing this file.
+       (cygpackage::cygpackage): Update for String usage.
+       (cygpackage::set_canonical_version): Ditto.
+       (cygpackage::destroy): Ditto.
+       (cygpackage::getfirstfile): Ditto.
+       (cygpackage::getnextfile): Ditto.
+       (cygpackage::Name): Ditto.
+       (cygpackage::Vendor_version): Ditto.
+       (cygpackage::Package_version): Ditto.
+       (cygpackage::Canonical_version): Ditto.
+       (cygpackage::set_sdesc): Ditto.
+       (cygpackage::set_ldesc): Ditto.
+       (cygpackage::name): Ditto.
+       (cygpackage::vendor): Ditto.
+       (cygpackage::packagev): Ditto.
+       (cygpackage::canonical): Ditto.
+       (cygpackage::fn): Ditto.
+       (cygpackage::sdesc): Ditto.
+       (cygpackage::ldesc): Ditto.
+       * desktop.cc: Update includes for use of String class.
+       (batname): Update for String usage.
+       (iconname): Ditto.
+       (make_link): Ditto.
+       (start)menu): Ditto.
+       (desktop_icon): Ditto.
+       (make_cygwin_bat): Ditto.
+       (make_etc_profile): Ditto.
+       (uexists): Ditto.
+       (make_passwd_group): Ditto.
+       (save_icon): Ditto.
+       (check_desktop): Ditto.
+       (check_startmenu): Ditto.
+       * dialog.cc (eget): Update for String usage.
+       (egetString): New function.
+       (eset): New variant for Strings.
+       * dialog.h: Include String++.h for parsing this file.
+       (egetString): New function.
+       (eset): New variant for Strings.
+       * diskfull.cc (diskfull): Update for String usage.
+       * diskfull.h: Include String++.h for parsing this file.
+       (diskfull): Update for String usage.
+       * download.cc: Update includes for use of String class.
+       (check_for_cached): Update for String usage.
+       (download_one): Ditto.
+       * filemanip.cc (get_file_size): Ditto.
+       (base): Ditto.
+       (parse_filename): Ditto.
+       (backslash): Ditto.
+       * filemanip.h: Include String++.h for parsing this file.
+       (fileparse): Update for String usage.
+       (base): Ditto.
+       (parse_filename): Ditto.
+       Don't consider '_' to be a separator.
+       (backslash): Ditto.
+       * find.cc: Update includes for use of String class.
+       (find_sub): Make more flexible.
+       (find): Update for String usage.
+       * find.h (find): Use Strings.
+       * fromcwd.cc (found_file): Update for String usage.
+       * geturl.cc: Ditto.
+       (init_dialog): Ditto.
+       (get_url_to_membuf): Ditto.
+       (get_url_to_string): Ditto.
+       (get_url_to_file): Ditto.
+       * geturl.h: Ditto.
+       (get_url_to_membuf): Ditto.
+       (get_url_to_string): Ditto.
+       (get_url_to_file): Ditto.
+       * hash.h: Ditto.
+       (add_subdirs): Ditto.
+       * ini.cc: Update includes for String usage.
+       (find_routine): Update for String usage.
+       (do_remote_ini): Ditto.
+       (do_ini_thread): Ditto.
+       * ini.h (ini_init): Ditto.
+       * inilex.l: Update includes for String usage.
+       (ini_init): Update for String usage.
+       * iniparse.y: Ditto.
+       (add_correct_version): Ditto.
+       * install.cc: Update includes for String usage.
+       (install_one_source): Update for String usage.
+       (uninstall_one): Ditto.
+       (replace_one): Ditto.
+       (install_one_source): Ditto.
+       (do_install_thread): Ditto.
+       * io_stream.cc: Update includes for String usage.
+       (io_stream::open): Update for String usage.
+       (io_stream::mkpath_p): Ditto.
+       (io_stream::remove): Ditto.
+       (io_stream::mklink): Ditto.
+       (io_stream::move_copy): Ditto.
+       (io_stream::move): Ditto.
+       (io_stream::exists): Ditto.
+       * io_stream.h: Update includes to allow correct parsing.
+       (io_stream::open): Update for String usage.
+       (io_stream::mkpath_p): Ditto.
+       (io_stream::remove): Ditto.
+       (io_stream::mklink): Ditto.
+       (io_stream::move_copy): Ditto.
+       (io_stream::move): Ditto.
+       (io_stream::exists): Ditto.
+       * io_stream_cygfile.cc: Update includes for String usage.
+       (get_root_dir_now): Update for String usage.
+       (io_stream_cygfile::io_stream_cygfile): Ditto.
+       (io_stream_cygfile::~io_stream_cygfile): Ditto.
+       (io_stream_cygfile::exists): Ditto.
+       (io_stream_cygfile::remove): Ditto.
+       (io_stream_cygfile::mklink): Ditto.
+       (cygmkdir_p): Ditto.
+       (io_stream_cygfile::set_mtime): Ditto.
+       (io_stream_cygfile::move): Ditto.
+       (io_stream_cygfile::get_size): Ditto.
+       * io_stream_cygfile.h: Update includes for String usage.
+       (io_stream_cygfile::io_stream_cygfile): Update for String usage.
+       (io_stream_cygfile::~io_stream_cygfile): Ditto.
+       (io_stream_cygfile::exists): Ditto.
+       (io_stream_cygfile::remove): Ditto.
+       (io_stream_cygfile::mklink): Ditto.
+       (cygmkdir_p): Ditto.
+       (io_stream_cygfile::set_mtime): Ditto.
+       (io_stream_cygfile::move): Ditto.
+       (io_stream_cygfile::get_size): Ditto.
+       (io_stream_cygfile::fname): Ditto.
+       (io_stream_cygfile::lmode): Ditto.
+       * io_stream_file.cc: Update includes for String usage.
+       (io_stream_file::io_stream_file): Update for String usage.
+       (io_stream_file::~io_stream_file): Ditto.
+       (io_stream_file::exists): Ditto.
+       (io_stream_file::remove): Ditto.
+       (io_stream_file::mklink): Ditto.
+       (io_stream_file::set_mtime): Ditto.
+       (io_stream_file::move): Ditto.
+       (io_stream_file::get_size): Ditto.
+       * io_stream_file.h: Update includes for String usage.
+       * io_stream_file.cc: Update includes for String usage.
+       (io_stream_file::io_stream_file): Update for String usage.
+       (io_stream_file::~io_stream_file): Ditto.
+       (io_stream_file::exists): Ditto.
+       (io_stream_file::remove): Ditto.
+       (io_stream_file::mklink): Ditto.
+       (io_stream_file::set_mtime): Ditto.
+       (io_stream_file::move): Ditto.
+       (io_stream_file::get_size): Ditto.
+       (io_stream_file::fname): Ditto.
+       (io_stream_file::lmode): Ditto.
+       * localdir.cc: Update includes for String usage.
+       (save_local_dir): Update for String usage.
+       (check_if_enable_next): Ditto.
+       (load_dialog): Ditto.
+       (browse_cb): Ditto.
+       (LocalDirPage::OnInit): Ditto.
+       (LocalDirPage::OnNext): Ditto.
+       * log.cc: Update includes for String usage.
+       (struct LogEnt): Update for String usage.
+       (log): Ditto.
+       (log_save): Ditto.
+       (exit_setup): Ditto.
+       * log.h: Update includes for String usage.
+       (log_level): Update for String usage.
+       (log): Ditto.
+       (log_save): Ditto.
+       * main.cc (WinMain): Update for String usage.
+       * mklink2.c (make_link_2): Update for String usage.
+       * mklink2.h (make_link_2): Update for String usage.
+       * mount.cc: Update includes for String usage.
+       (mount_table): Update for String usage.
+       (find2): Ditto.
+       (create_mount): Ditto.
+       (remove1): Ditto.
+       (remove_mount): Ditto.
+       (read_mounts): Ditto.
+       (set_root_dir): Ditto.
+       (get_root_dir): Ditto.
+       (path_prefix_p): Ditto.
+       (cygpath): Ditto.
+       * mount.h: Update includes for String usage.
+       (create_mount): Update for String usage.
+       (remove_mount): Ditto.
+       (cygpath): Ditto.
+       (set_root_dir): Ditto.
+       (get_root_dir): Ditto.
+       * msg.cc (mbox): Ditto.
+       * net.cc (NetPage::OnNext): Ditto.
+       * package_db.cc (packagedb::flush): Ditto.
+       (packagedb::packages): Ditto.
+       (packagedb::categories): Ditto.
+       * package_db.h: Update includes for String usage.
+       (packagedb::packages): Update for String usage.
+       (packagedb::categories): Ditto.
+       * package_meta.cc: Update includes for String usage.
+       (hash::add_subdirs): Update for String usage.
+       (packagemeta::uninstall): Ditto.
+       (packagemeta::SDesc): Ditto.
+       (packagemeta::action_caption): Ditto.
+       * package_meta.h: Update includes for String usage.
+       (packagemeta::packagemeta): Update for String usage.
+       (packagemeta::~packagemeta): Ditto.
+       (packagemeta::uninstall): Ditto.
+       (packagemeta::SDesc): Ditto.
+       (packagemeta::action_caption): Ditto.
+       (package_source.cc site::site): Ditto.
+       (packagesource::set_canonical): Ditto.
+       (packagesource::set_cached): Ditto.
+       * package_source.h: Update includes for String usage.
+       (site::site): Update for String usage.
+       (packagesource::set_canonical): Ditto.
+       (packagesource::set_cached): Ditto.
+       (packagesource::packagesource): Ditto.
+       (packagesource::sites): Ditto.
+       (packagesource::cached): Ditto.
+       * package_version.h: Update includes for String usage.
+       (Dependency): Update for String usage.
+       (packageversion): Ditto.
+       * postinstall.cc: Update includes for String usage.
+       (do_postinstall): Update for String usage.
+       * res.rc (IDD_LOCAL_DIR): Fix typo again!
+       * rfc1738.cc (rfc1738_escape_part): Update for String usage.
+       * rfc1738.h: Update includes for String usage.
+       (rfc1738_escape_part): Update for String usage.
+       * root.cc: Update includes for String usage.
+       (check_if_enable_next): Update for String usage.
+       (save_dialog): Ditto.
+       (browse_cb): Ditto.
+       (directory_is_absolute): Ditto.
+       (directory_is_rootdir): Ditto.
+       (directory_has_spaces): Ditto.
+       (RootPage::OnInit): Ditto.
+       (RootPage::OnNext): Ditto.
+       * script.cc: Update includes for String usage.
+       (init_run_script): Update for String usage.
+       (run): Ditto.
+       (run_script): Ditto.
+       (try_run_script): Ditto.
+       * script.h: Update includes for String usage.
+       (run_script): Update for String usage.
+       (try_run_script): Ditto.
+       * site.cc site_list): Ditto.
+       (all_site_list): Ditto.
+       (other_url): Eliminate.
+       (site_list_type::init): Update for String usage.
+       (site_list_type::site_list_type): Ditto.
+       (get_site_list): Ditto.
+       (get_saved_sites): Ditto.
+       (do_download_site_info_thread): Ditto.
+       (SitePage::OnNext): Ditto.
+       (SitePage::OnActivate): Ditto.
+       (SitePage::PopulateListBox): Ditto.
+       (SitePage::OnMessageCmd): Handle empty url's.
+       * site.h: Update includes for String usage.
+       (site_list_type::site_list_type): Update for String usage.
+       (site_list_type::init): Ditto.
+       (site_list_type::~site_list_type): Ditto.
+       (site_list_type::url): Ditto.
+       (site_list_type::displayed_url): Ditto.
+       (site_list_type::key): Ditto.
+       * source.cc (SourcePage::OnDeactivate): Ditto.
+       * state.h: Update includes for String usage.
+       (local_dir): Update for String usage.
+       (trust_level): Remove.
+       * version.cc: Update includes for String usage.
+       (canonicalize_version): Update for String usage.
+       * version.h: Update includes for String usage.
+       (canonicalize_version): Update for String usage.
+       
 2002-02-15  Christopher Faylor  <cgf@redhat.com>
 
        * filemanip.c (parse_filename): Revert previous change.
index 040ddf1cbb7979f8f2327565b304585abd557926..a0a3bd2c30ad8ec216540dd4268733052a528595 100644 (file)
@@ -152,6 +152,7 @@ OBJS = \
        source.o \
        splash.o \
        state.o \
+       String++.o \
        threebar.o \
        version.o \
        win32.o \
index d6159ddf5adf3eceefde6a85d498460bb2688efd..91e2bbbc06e7160b93c69cb05a9e20571c04fda0 100644 (file)
@@ -33,13 +33,14 @@ PickCategoryLine::paint (HDC hdc, int x, int y, int row, int show_cat)
   if (show_label)
     {
       int by = r + theView.tm.tmHeight - 11;
+      String temp=(String("+ ") +cat.name);
       TextOut (hdc,
               x + theView.headers[theView.cat_col].x + HMARGIN / 2 +
-              depth * 8, r, cat.name, strlen (cat.name));
+              depth * 8, r, temp.cstr_oneuse(), temp.size());
       if (!labellength)
        {
          SIZE s;
-         GetTextExtentPoint32 (hdc, cat.name, strlen (cat.name), &s);
+         GetTextExtentPoint32 (hdc, temp.cstr_oneuse(), temp.size(), &s);
          labellength = s.cx;
        }
       SelectObject (theView.bitmap_dc, theView.bm_spin);
index 8d96edb048528204c7ac626614b791b803d285c9..5e968dc5d005126222114b5d87f356342c54c061 100644 (file)
@@ -82,7 +82,7 @@ private:
   size_t depth;
   PickCategoryLine (PickCategoryLine const &);
   PickCategoryLine & operator= (PickCategoryLine const &);
-  list < PickLine, char const *, strcasecmp > bucket;
+  list < PickLine, String, String::casecompare > bucket;
   PickView& theView;
 };
 #endif // _PICKCATEGORYLINE_H_
index 53543ede2ff9ae40de7c783f41c701b8d44cdd80..14c35f19678003bdfbe56bf1f34166d71e49cffb 100644 (file)
@@ -29,8 +29,7 @@ public:
   // this may indicate bad inheritance model.
   virtual bool IsContainer (void) const = 0;
   virtual void insert (PickLine &) = 0;
-  // Never allocate to key, always allocated elsewhere
-  char const *key;
+  String const key;
   virtual ~ PickLine ()
   {
   };
@@ -38,7 +37,7 @@ protected:
   PickLine ()
   {
   };
-  PickLine (char const *aKey):key (aKey)
+  PickLine (String const &aKey):key (aKey)
   {
   };
   PickLine (PickLine const &);
index 862eb716f9573f16a5c710f05a782cd55797c6f0..5c11519cd628ae94d3d191d922811e0151838f81 100644 (file)
@@ -54,22 +54,22 @@ PickPackageLine::paint (HDC hdc, int x, int y, int row, int show_cat)
                         theView.headers[theView.current_col].width, by + 11);
       TextOut (hdc,
               x + theView.headers[theView.current_col].x + HMARGIN / 2, r,
-              pkg.installed->Canonical_version (),
-              strlen (pkg.installed->Canonical_version ()));
+              pkg.installed->Canonical_version ().cstr_oneuse(),
+              pkg.installed->Canonical_version ().size());
       SelectObject (theView.bitmap_dc, theView.bm_rtarrow);
       BitBlt (hdc, x + theView.headers[theView.new_col].x + HMARGIN / 2,
              by, 11, 11, theView.bitmap_dc, 0, 0, SRCCOPY);
       SelectClipRgn (hdc, oldClip2);
     }
 
-  const char *s = pkg.action_caption ();
+  String s = pkg.action_caption ();
   IntersectClipRect (hdc, x + theView.headers[theView.new_col].x,
                     by,
                     x + theView.headers[theView.new_col].x +
                     theView.headers[theView.new_col].width, by + 11);
   TextOut (hdc,
           x + theView.headers[theView.new_col].x + HMARGIN / 2 +
-          NEW_COL_SIZE_SLOP, r, s, strlen (s));
+          NEW_COL_SIZE_SLOP, r, s.cstr_oneuse(), s.size());
   SelectObject (theView.bitmap_dc, theView.bm_spin);
   BitBlt (hdc,
          x + theView.headers[theView.new_col].x + ICON_MARGIN / 2 +
@@ -101,32 +101,25 @@ PickPackageLine::paint (HDC hdc, int x, int y, int row, int show_cat)
   if (pkg.Categories.number () && show_cat)
     {
       int index = 1;
-      if (!strcasecmp (pkg.Categories[1]->key.name, "All"))
+      if (!pkg.Categories[1]->key.name.casecompare( "All"))
        index = 2;
       IntersectClipRect (hdc, x + theView.headers[theView.cat_col].x, by,
                         x + theView.headers[theView.cat_col].x +
                         theView.headers[theView.cat_col].x, by + 11);
       TextOut (hdc, x + theView.headers[theView.cat_col].x + HMARGIN / 2, r,
-              pkg.Categories[index]->key.name,
-              strlen (pkg.Categories[index]->key.name));
+              pkg.Categories[index]->key.name.cstr_oneuse(),
+              pkg.Categories[index]->key.name.size());
       SelectClipRgn (hdc, oldClip2);
     }
 
-  if (!pkg.SDesc ())
-    s = pkg.name;
-  else
-    {
-      static char buf[512];
-      strcpy (buf, pkg.name);
-      strcat (buf, ": ");
-      strcat (buf, pkg.SDesc ());
-      s = buf;
-    }
+  s = pkg.name;
+  if (pkg.SDesc ().size())
+    s += String(": ") + pkg.SDesc ();
   IntersectClipRect (hdc, x + theView.headers[theView.pkg_col].x, by,
                     x + theView.headers[theView.pkg_col].x +
                     theView.headers[theView.pkg_col].width, by + 11);
-  TextOut (hdc, x + theView.headers[theView.pkg_col].x + HMARGIN / 2, r, s,
-          strlen (s));
+  TextOut (hdc, x + theView.headers[theView.pkg_col].x + HMARGIN / 2, r, s.cstr_oneuse(),
+          s.size());
   DeleteObject (oldClip);
   DeleteObject (oldClip2);
   RestoreDC (hdc, oldDC);
index 34f7b1bd0cf2022e11926b9f811c84f8560f41f3..3771a3095a2032abeb5865618d5188d9eefc906e 100644 (file)
@@ -23,9 +23,8 @@ class PickView;
 class PickPackageLine:public PickLine
 {
 public:
-  PickPackageLine (PickView &aView, packagemeta & apkg):pkg (apkg), theView (aView)
+  PickPackageLine (PickView &aView, packagemeta & apkg):PickLine (apkg.key), pkg (apkg), theView (aView)
   {
-    key = apkg.key;
   };
   virtual void paint (HDC hdc, int x, int y, int row, int show_cat);
   virtual int click (int const myrow, int const ClickedRow, int const x);
index 4404a0c8340b89bdfad076234f378637b9378aa4..c8ca466437a4b47222b93810714501bd0ded909e 100644 (file)
@@ -111,17 +111,17 @@ PickView::set_headers ()
 }
 
 void
-PickView::note_width (PickView::Header *hdrs, HDC dc, const char *string, int addend,
+PickView::note_width (PickView::Header *hdrs, HDC dc, String const &string, int addend,
             int column)
 {
-  if (!string)
+  if (!string.size())
     {
       if (hdrs[column].width < addend)
         hdrs[column].width = addend;
       return;
     }
   SIZE s;
-  GetTextExtentPoint32 (dc, string, strlen (string), &s);
+  GetTextExtentPoint32 (dc, string.cstr_oneuse(), string.size(), &s);
   if (hdrs[column].width < s.cx + addend)
     hdrs[column].width = s.cx + addend;
 }
@@ -310,6 +310,8 @@ PickView::init_headers (HDC dc)
   /* src checkbox */
   note_width (headers, dc, 0, HMARGIN + 11, src_col);
   packagedb db;
+  for (size_t n = 1; n <= db.categories.number (); n++)
+      note_width (headers, dc, String ("+ ")+db.categories[n]->name, HMARGIN, cat_col);
   for (size_t n = 1; n <= db.packages.number (); n++)
     {
       packagemeta & pkg = *db.packages[n];
@@ -321,18 +323,10 @@ PickView::init_headers (HDC dc)
           note_width (headers, dc,
                       pkg.versions[n]->Canonical_version (),
                       NEW_COL_SIZE_SLOP + HMARGIN, new_col);
-      for (size_t n = 1; n <= db.categories.number (); n++)
-        note_width (headers, dc, db.categories[n]->name, HMARGIN, cat_col);
-      if (!pkg.SDesc ())
-        note_width (headers, dc, pkg.name, HMARGIN, pkg_col);
-      else
-        {
-          static char buf[512];
-          strcpy (buf, pkg.name);
-          strcat (buf, ": ");
-          strcat (buf, pkg.SDesc ());
-          note_width (headers, dc, buf, HMARGIN, pkg_col);
-        }
+      String s = pkg.name;
+      if (pkg.SDesc ().size())
+       s += String (": ") + pkg.SDesc ();
+      note_width (headers, dc, s, HMARGIN, pkg_col);
     }
   note_width (headers, dc, "keep", NEW_COL_SIZE_SLOP + HMARGIN, new_col);
   note_width (headers, dc, "uninstall", NEW_COL_SIZE_SLOP + HMARGIN, new_col);
index 5d88505013da922592724cca97314b5c71ed78a2..cd392677ac963fd05d0888df47fe6a5f884af44a 100644 (file)
@@ -17,6 +17,7 @@
 #define _PICKVIEW_H_
 
 #include "win32.h"
+#include "String++.h"
 
 #define HMARGIN 10
 #define ROW_MARGIN      5
@@ -118,7 +119,7 @@ private:
   views view_mode;
   void set_headers ();
   void init_headers (HDC dc);
-  void note_width (Header *hdrs, HDC dc, const char *string, int addend,
+  void note_width (Header *hdrs, HDC dc, String const &string, int addend,
       int column);
 
 };
diff --git a/String++.cc b/String++.cc
new file mode 100644 (file)
index 0000000..ff86f6b
--- /dev/null
@@ -0,0 +1,247 @@
+/*
+ * Copyright (c) 2002, 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 String class to replace all the char * manipulation. 
+
+#include "String++.h"
+#include <string.h>
+#include <ctype.h>
+#include "concat.h"
+#include "io_stream.h"
+
+// _data
+
+String::_data::_data(_data const &aData) : count (1), theString (new unsigned char[aData.length]), cstr(0), length (aData.length) {
+  memcpy (theString, aData.theString, aData.length);
+}
+
+String::_data::_data(): count (1), theString(new unsigned char[0]), cstr (0), length (0) {}
+String::_data::_data(size_t aLength): count (1), theString(new unsigned char[aLength]), cstr(0), length (aLength) {}
+String::_data::~_data ()
+{
+    if (theString)
+          delete[] theString;
+      if (cstr)
+           delete[] cstr;
+}
+
+//String
+
+String::String (const char *acString) : theData (new _data(acString ? strlen(acString) : 0))
+{
+  memcpy (theData->theString, acString, theData->length);
+}
+
+String::~String ()
+{
+  if (--theData->count == 0)
+    delete theData;
+}
+
+// able to cache the result if needed.
+char *
+String::cstr ()
+{
+  if (theData->length == 0)
+    return NULL;
+  char * tempcStr =new char[theData->length + 1];
+  // remove when exceptions are done
+  if (!tempcStr)
+        exit (100);
+  tempcStr[theData->length] = '\0';
+  memcpy (tempcStr, theData->theString, theData->length);
+  return tempcStr;
+}
+
+char *
+String::cstr () const
+{
+  if (theData->length == 0)
+    return NULL;
+  char * tempcStr =new char[theData->length + 1];
+  // remove when exceptions are done
+  if (!tempcStr)
+        exit (100);
+  tempcStr[theData->length] = '\0';
+  memcpy (tempcStr, theData->theString, theData->length);
+  return tempcStr;
+}
+
+// able to cache the result if needed.
+char const *
+String::cstr_oneuse () const
+{
+  if (theData->length == 0)
+    return NULL;
+  if (theData->cstr)
+    delete[] theData->cstr;
+  theData->cstr = new char[theData->length + 1];
+  theData->cstr[theData->length] = '\0';
+  memcpy (theData->cstr, theData->theString, theData->length);
+  return theData->cstr;
+}
+
+// does this character exist in the string?
+// 0 is false, 1 is the first position...
+// XXX FIXME: Introduce npos, and change all
+// if (size) calls to be if (size()==npos)
+size_t
+String::find(char aChar) const
+{
+  for (size_t i=0; i < theData->length; ++i)
+    if (theData->theString[i] == aChar)
+      return i+1;
+  return 0;
+}
+
+int
+String::compare (String const &aString, size_t const count) const
+{
+  // trivial cases:
+  if (theData == aString.theData)
+    return 0;
+  size_t length = count ? count : theData->length;
+  if (length > theData->length)
+    length = theData->length;
+  if (length > aString.theData->length)
+    length = aString.theData->length;
+  size_t i;
+  for (i=0; i < length ; ++i)
+    if (theData->theString[i] < aString.theData->theString[i])
+      return -1;
+    else if (theData->theString[i] > aString.theData->theString[i])
+      return 1;
+  // equal for length
+  if (i == count && count != 0)
+    return 0;
+  if (theData->length < aString.theData->length)
+    return -1;
+  else if (theData->length > aString.theData->length)
+    return 1;
+  return 0;
+}
+
+int
+String::casecompare (String const &aString, size_t const count) const
+{
+  // trivial cases:
+  if (theData == aString.theData)
+    return 0;
+  size_t length = count ? count : theData->length;
+  if (length > theData->length)
+    length = theData->length;
+  if (length > aString.theData->length)
+    length = aString.theData->length;
+  size_t i;
+  for (i=0; i < length; ++i)
+    if (toupper(theData->theString[i]) < toupper(aString.theData->theString[i]))
+      return -1;
+    else if (toupper(theData->theString[i]) > toupper(aString.theData->theString[i]))
+      return 1;
+  // equal for length
+  if (i == count && count != 0)
+    return 0;
+  if (theData->length < aString.theData->length)
+    return -1;
+  else if (theData->length > aString.theData->length)
+    return 1;
+  return 0;
+}
+
+String
+String::concat (const char *aString, ...)
+{
+  va_list aList;
+  va_start (aList, aString);
+
+  return vconcat (aString, aList);  
+}
+
+String
+String::vconcat (const char *aString, va_list aList)
+{
+  char *tempString = ::vconcat(aString, aList);
+  String theString = String (tempString);
+  delete[] tempString;
+  return theString;
+}
+
+String &
+String::operator+= (String const &aString)
+{
+  if (theData->count > 1) 
+  {
+    _data * someData = new _data(*theData);
+    --theData->count;
+    theData = someData;
+  }
+
+  unsigned char *tempString = theData->theString;
+  theData->theString = new unsigned char [theData->length + aString.theData->length];
+  // remove when exceptions are done
+  if (!theData->theString)
+    exit (100);
+  memcpy (theData->theString, tempString, theData->length);
+  delete[] tempString;
+  memcpy (&theData->theString[theData->length], aString.theData->theString, aString.theData->length);
+  theData->length += aString.theData->length;
+  return *this;
+}
+
+String
+String::operator + (String const &aString) const
+{
+  unsigned char *tempcString = new unsigned char [theData->length + aString.theData->length];
+  // remove when exceptions are done
+  if (!tempcString)
+      exit (100);
+  memcpy (tempcString, theData->theString, theData->length);
+  memcpy (&tempcString[theData->length], aString.theData->theString, aString.theData->length);
+  return absorb (tempcString, theData->length + aString.theData->length);
+}
+
+String
+String::operator + (char const *aString) const
+{
+  // expensive, but quick to code.
+  return *this + String (aString);
+}
+
+bool
+String::operator == (String const &rhs) const
+{
+  return compare (rhs) ? false : true;
+}
+
+bool
+String::operator == (char const *rhs) const
+{
+    return compare (rhs) ? false : true;
+}
+
+String
+String::absorb (unsigned char *aString, size_t aLength)
+{
+  String theString;
+  theString.theData->theString = aString;
+  theString.theData->length = aLength;
+  return theString;
+}
+
+int
+String::casecompare (String const lhs, String const rhs)
+{
+  return lhs.casecompare (rhs);
+}
diff --git a/String++.h b/String++.h
new file mode 100644 (file)
index 0000000..ba6c100
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2002, 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 String class to replace all the char * manipulation. 
+
+#ifndef CINSTALL_STRING_H
+#define CINSTALL_STRING_H
+
+#include <stdarg.h>
+#include "sys/types.h"
+
+class io_stream;
+class String {
+  class _data;
+public:
+  // Static members first
+  static String concat (const char *s, ...);
+  static String vconcat (const char *, va_list);
+  
+  inline String();
+  inline String (String const &);
+  // We're notperformance bottlenecked.
+  String (const char *); 
+  inline String & operator = (String const &);
+  ~String();
+  // Up to the user to delete[] these.
+  char * cstr();
+  char * cstr() const; // may be less optimal
+  char const * cstr_oneuse() const; // only valid until the next mutator call
+                             // pretends to be const !!
+  inline size_t size() const; // number of characters (!= storage size).
+  size_t find (char) const;
+  // operator == and != can be done if/when we have a 'casesensitive' flag to
+  // the constructors
+  // - means this sorts to the left of the parameter
+  int compare (String const &, size_t const = 0) const;
+  static int compare (String const &, String const &, size_t const = 0);
+  int casecompare (String const &, size_t const = 0) const;
+  static int casecompare (String const &, String const &, size_t const = 0);
+  static int casecompare (String const, String const);
+  String &append (String const &);
+  String &operator += (String const &);
+  String operator + (String const &) const;
+  String operator + (char const *) const;
+  bool operator == (String const &) const;
+  bool operator == (char const *) const;
+    
+private:
+  class _data {
+  public:
+    _data ();
+    _data (size_t);
+    _data (_data const &);
+    ~_data ();
+    unsigned count; //Invariant: all constructors set to 1;
+    // For now, char *, but can be TCHAR, or even UNICODE
+    // when time permits.
+    unsigned char *theString;
+    char *cstr; // cached/oneuse Cstr encoded version
+    size_t length;
+  } *theData; // Invariant, there is always an 
+  static String absorb (unsigned char *, size_t);
+};
+
+String::String() : theData (new _data) {}
+String::String(String const &aString) : theData (aString.theData) 
+{
+  ++theData->count;
+}
+
+String &
+String::operator= (String const &aString)
+{
+  // Don't touch the order
+  ++aString.theData->count;
+  if (--theData->count == 0) 
+    delete theData;
+  theData = aString.theData;
+  return *this;
+}
+
+size_t 
+String::size() const
+{
+  return theData->length;
+}
+
+#endif // CINSTALL_STRING_H
index b857f69c8a3cdd6a855f31605fb033c5eb0b17ee..f117fde1838c3aafb204cc875b561bf36be20505 100644 (file)
@@ -26,7 +26,7 @@ static const char *cvsid =
 #include <stdlib.h>
 #include "log.h"
 #include "port.h"
-#include "concat.h"
+#include "String++.h"
 
 #include "io_stream.h"
 #include "archive.h"
@@ -78,11 +78,11 @@ archive::extract (io_stream * original)
 }
 
 int
-archive::extract_file (archive * source, const char *prefixURL, const char *prefixPath, const char *suffix)
+archive::extract_file (archive * source, String const &prefixURL, String const &prefixPath, String suffix)
 {
   if (!source)
     return 1;
-  const char *destfilename = concat (prefixURL,prefixPath, source->next_file_name (), suffix, 0);
+  String const destfilename = prefixURL+prefixPath+ source->next_file_name ()+ suffix;
   switch (source->next_file_type ())
     {
     case ARCHIVE_FILE_REGULAR:
@@ -91,25 +91,25 @@ archive::extract_file (archive * source, const char *prefixURL, const char *pref
        /* TODO: remove in-the-way directories via mkpath_p */
        if (io_stream::mkpath_p (PATH_TO_FILE, destfilename))
        {
-         log (LOG_TIMESTAMP, "Failed to make the path for %s", destfilename);
+         log (LOG_TIMESTAMP, String ("Failed to make the path for ") + destfilename);
          return 1;}
        io_stream::remove (destfilename);
        io_stream *tmp = io_stream::open (destfilename, "wb");
        if (!tmp)
        {
-         log (LOG_TIMESTAMP, "Failed to open %s for writing", destfilename);
+         log (LOG_TIMESTAMP, String ("Failed to open ") + destfilename + " for writing.");
          return 1;
        }
        io_stream *in = source->extract_file ();
        if (!in)
          {
            delete tmp;
-           log (LOG_TIMESTAMP, "Failed to extract the file %s from the archive",destfilename);
+           log (LOG_TIMESTAMP, String("Failed to extract the file ") + destfilename + " from the archive");
            return 1;
          }
        if (io_stream::copy (in, tmp))
          {
-           log (LOG_TIMESTAMP, "Failed to output %s", destfilename);
+           log (LOG_TIMESTAMP, String("Failed to output ") + destfilename);
            delete tmp;
            io_stream::remove (destfilename);
            return 1;
@@ -122,12 +122,12 @@ archive::extract_file (archive * source, const char *prefixURL, const char *pref
     case ARCHIVE_FILE_SYMLINK:
       {
        if (io_stream::mkpath_p (PATH_TO_FILE, destfilename))
-       {log (LOG_TIMESTAMP, "Failed to make the path for %s", destfilename);
+       {log (LOG_TIMESTAMP, "Failed to make the path for %s", destfilename.cstr_oneuse());
          return 1;}
        io_stream::remove (destfilename);
        int ok =
          io_stream::mklink (destfilename,
-                            concat (prefixURL, source->linktarget (), 0),
+             prefixURL+ source->linktarget (),
                             IO_STREAM_SYMLINK);
        /* FIXME: check what tar's filelength is set to for symlinks */
        source->skip_file ();
@@ -136,12 +136,12 @@ archive::extract_file (archive * source, const char *prefixURL, const char *pref
     case ARCHIVE_FILE_HARDLINK:
       {
        if (io_stream::mkpath_p (PATH_TO_FILE, destfilename))
-       {log (LOG_TIMESTAMP, "Failed to make the path for %s", destfilename);
+       {log (LOG_TIMESTAMP, "Failed to make the path for %s", destfilename.cstr_oneuse());
          return 1;}
        io_stream::remove (destfilename);
        int ok =
          io_stream::mklink (destfilename,
-                            concat (prefixURL, source->linktarget (), 0),
+             prefixURL + source->linktarget (),
                             IO_STREAM_HARDLINK);
        /* FIXME: check what tar's filelength is set to for hardlinks */
        source->skip_file ();
@@ -149,8 +149,8 @@ archive::extract_file (archive * source, const char *prefixURL, const char *pref
       }
     case ARCHIVE_FILE_DIRECTORY:
       {
-       char *path = (char *) alloca (strlen (destfilename));
-       strcpy (path, destfilename);
+       char *path = (char *) alloca (destfilename.size());
+       strcpy (path, destfilename.cstr_oneuse());
        while (path[0] && path[strlen (path) - 1] == '/')
          path[strlen (path) - 1] = 0;
        source->skip_file ();
index dbf4c7afd3e36be979bcb3698470915bc685878b..01309c5c434414eb5621191baa71a2b9de50834e 100644 (file)
--- a/archive.h
+++ b/archive.h
@@ -20,6 +20,8 @@
  * It 
  */
 
+#include "String++.h"
+
 /* The read/write the archive stream to get the archive data is flawed.
  * The problem is that you then need a *different* gzip etc class to be able
  * to ungzip a gzip from within an archive.
@@ -54,7 +56,7 @@ public:
    * given suffix.
    * returns 1 on failure.
    */
-  static int extract_file (archive *, const char *, const char *, const char * = NULL);
+  static int extract_file (archive *, String const &, String const &, String const = String());
 
   /* 
    * To create a stream that will be compressed, you should open the url, and then get a new stream
@@ -78,9 +80,9 @@ public:
    * The way this works is that when read returns 0, you are at the end of *a* file.
    * next_file_name will allow read to be called again, if it returns !NULL
    */
-  virtual const char *next_file_name () = NULL;
+  virtual String const next_file_name () = NULL;
   virtual archive_file_t next_file_type () = ARCHIVE_FILE_INVALID;
-  virtual const char *linktarget () = NULL;
+  virtual String const linktarget () = NULL;
   virtual int skip_file () = 0;
   /* if you are still needing these hints... give up now! */
 //  virtual ~compress ();
index 799c25506b337af286e111ccbfc019567611001b..811aa46aca55feaf6f6c16a7651c9c50c3ab02e4 100644 (file)
@@ -139,7 +139,7 @@ archive_tar::skip_file ()
   return 0;
 }
 
-const char *
+String const
 archive_tar::next_file_name ()
 {
   char *c;
@@ -149,7 +149,7 @@ archive_tar::next_file_name ()
       return state.filename;
     else
       /* End of tar */
-      return NULL;
+      return String();
 
   int r = state.parent->read (&state.tar_header, 512);
 
@@ -292,14 +292,14 @@ archive_tar::next_file_type ()
     }
 }
 
-const char *
+String const
 archive_tar::linktarget ()
 {
   /* TODO: consider .. path traversal issues */
   if (next_file_type () == ARCHIVE_FILE_SYMLINK ||
       next_file_type () == ARCHIVE_FILE_HARDLINK)
     return state.tar_header.linkname;
-  return NULL;
+  return String();
 }
 
 io_stream *
index 5a85dfd5bce0384de9999f6af8a4ca3c1d7ae68d..05b8a4ebeec54179dcdd0718915157e7da3a31e5 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2000, Red Hat, Inc.
+ * Copyright (c) 2002, 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
 #ifndef __TAR_H_
 #define __TAR_H_
 
+#include "io_stream.h"
+#include "archive.h"
+#include "String++.h"
+
 typedef struct
 {
   char name[100];              /*   0 */
@@ -42,8 +47,8 @@ tar_header_type;
 typedef struct tar_map_result_type_s
 {
   struct tar_map_result_type_s *next;
-  char *stored_name;
-  char *mapped_name;
+  String stored_name;
+  String mapped_name;
 }
 tar_map_result_type;
 
@@ -83,7 +88,7 @@ public:
   virtual int seek (long where, io_stream_seek_t whence);
   /* try guessing this one */
   virtual int error ();
-  virtual char *next_file_name ()
+  virtual String next_file_name ()
   {
     return NULL;
   };
@@ -118,7 +123,7 @@ public:
    * for foobar that is an compress, next_file_name is the next
    * extractable filename.
    */
-  virtual const char *next_file_name ();
+  virtual String const next_file_name ();
   virtual archive_file_t next_file_type ();
   /* returns the mtime of the archive file, not of the current file */
   virtual int get_mtime ();
@@ -129,7 +134,7 @@ public:
   {
     return 1;
   };
-  virtual const char *linktarget ();
+  virtual String const linktarget ();
   virtual int skip_file ();
   /* if you are still needing these hints... give up now! */
   virtual ~ archive_tar ();
index aa81890f311275e6737afcde5198ce48753b909d..6e24377673c7d7c38233ac46839717b2bea0e300 100644 (file)
 
 /* normal members */
 
-Category::Category ():next (0), name (0), key (0), packages (0)
+Category::Category ():next (0), name (), key (), packages (0)
 {
 }
 
-Category::Category (const char *categoryname):
+Category::Category (String const &categoryname):
 next (0),
+name (categoryname), key(categoryname),
 packages (0)
 {
-  /* FIXME: search the global category list for name, and reuse that pointer */
-  char *t = new char [strlen(categoryname) + 1];
-  strcpy (t, categoryname);
-  name = t;
-  key = name;
 }
 
 int
 Categorycmp (Category const & a, Category const & b)
 {
-  return strcasecmp (a.name, b.name);
+  return a.name.casecompare (b.name);
 }
 
 int
 Categorycmp (Category & a, Category & b)
 {
-    return strcasecmp (a.name, b.name);
+    return a.name.casecompare (b.name);
 }
index c678e67024cea9e27dff74faa6b218b0c345217c..5f980f819cdd80988f30ddb9efff11c38135c4ce 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef _CATEGORY_H_
 #define _CATEGORY_H_
 
+#include "String++.h"
+
 class Category;
 class CategoryPackage;
 
@@ -30,12 +32,12 @@ class Category
 {
 public:
   Category ();
-  Category (char const *);
+  Category (String const &);
   bool operator== (Category const &rhs) const {return Categorycmp (*this, rhs) ? false : true;}
 
   Category *next;              /* the next category in the list */
-  const char *name;            /* the category */
-  const char *key;             /* always == name */
+  String const name;                   /* the category */
+  String const key;            /* always == name */
   CategoryPackage *packages;   /* the packages in this category */
 };
 
index 9086f3bceac2a0103b7c24593012ac3a95b75dd9..4c985797cdf343623bd56df8ee04f311d0a8e06f 100644 (file)
--- a/choose.cc
+++ b/choose.cc
@@ -42,7 +42,6 @@ static const char *cvsid =
 #include "resource.h"
 #include "state.h"
 #include "ini.h"
-#include "concat.h"
 #include "msg.h"
 #include "log.h"
 #include "find.h"
@@ -549,7 +548,7 @@ scan2 (char *path, unsigned int size)
   if (!parse_filename (path, f))
     return;
 
-  if (f.what[0] != '\0' && f.what[0] != 's')
+  if (f.what.size() != 0 && f.what.cstr_oneuse()[0] != 's')
     return;
 
   packagedb db;
@@ -597,9 +596,9 @@ scan2 (char *path, unsigned int size)
   int added = 0;
   for (size_t n = 1; n <= pkg->versions.number (); n++)
     {
-      if (!strcasecmp (f.ver, pkg->versions[n]->Canonical_version ()))
+      if (!f.ver.casecompare (pkg->versions[n]->Canonical_version ()))
        {
-         /* FIXME: Add a mirror entry */
+         /* FIXME: Add a cached entry */
          added = 1;
        }
     }
@@ -659,56 +658,33 @@ do_choose (HINSTANCE h, HWND owner)
       const char *trust = ((pkg.desired == pkg.prev) ? "prev"
                           : (pkg.desired == pkg.curr) ? "curr"
                           : (pkg.desired == pkg.exp) ? "test" : "unknown");
-      const char *action = pkg.action_caption ();
-      const char *installed =
+      String action = pkg.action_caption ();
+      String const installed =
        pkg.installed ? pkg.installed->Canonical_version () : "none";
 
       log (LOG_BABBLE, "[%s] action=%s trust=%s installed=%s"
           " src?=%s",
-          pkg.name, action, trust, installed,
+          pkg.name.cstr_oneuse(), action.cstr_oneuse(), trust, installed.cstr_oneuse(),
           pkg.desired && pkg.desired->srcpicked ? "yes" : "no");
       if (pkg.Categories.number ())
        {
          /* List categories the package belongs to */
-         int categories_len = 0;
-         for (size_t n = 1; n <= pkg.Categories.number (); n++)
-           categories_len += strlen (pkg.Categories[n]->key.name) + 2;
+         String all_categories = pkg.Categories[1]->key.name;
+         for (size_t n = 2; n <= pkg.Categories.number (); n++)
+           all_categories += String(", ") + pkg.Categories[n]->key.name;
 
-         if (categories_len > 0)
-           {
-             char *categories = new char [categories_len];
-             strcpy (categories, pkg.Categories[1]->key.name);
-             for (size_t n = 2; n <= pkg.Categories.number (); n++)
-               {
-                 strcat (categories, ", ");
-                 strcat (categories, pkg.Categories[n]->key.name);
-               }
-             log (LOG_BABBLE, "     categories=%s", categories);
-             delete[] categories;
-           }
+         log (LOG_BABBLE, String ("     categories=") + all_categories);
        }
       if (pkg.desired && pkg.desired->required)
        {
          /* List other packages this package depends on */
-         int requires_len = 0;
-         Dependency *dp;
-         for (dp = pkg.desired->required; dp; dp = dp->next)
-           if (dp->package)
-             requires_len += strlen (dp->package) + 2;
+         Dependency *dp=pkg.desired->required;
+         String requires = dp->package;
+         for (dp = dp->next ; dp; dp = dp->next)
+           if (dp->package.size())
+             requires += String (", ") + dp->package;
 
-         if (requires_len > 0)
-           {
-             char *requires = new char [requires_len];
-             strcpy (requires, pkg.desired->required->package);
-             for (dp = pkg.desired->required->next; dp; dp = dp->next)
-               if (dp->package)
-                 {
-                   strcat (requires, ", ");
-                   strcat (requires, dp->package);
-                 }
-             log (LOG_BABBLE, "     requires=%s", requires);
-             delete[] requires;
-           }
+             log (LOG_BABBLE, String("     requires=")+ requires);
        }
 #if 0
 
index f333f32d6a9f2ea0f2c5c6a7a5d2e23c3e67936c..71458decd1e226e361358ee01cdee4547647c4ef 100644 (file)
@@ -24,8 +24,7 @@ static const char *cvsid =
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <strings.h>
-#include "concat.h"
+#include "String++.h"
 
 #include "io_stream.h"
 #include "compress.h"
@@ -34,7 +33,8 @@ static const char *cvsid =
 #include "cygpackage.h"
 
 /* this constructor creates an invalid package - further details MUST be provided */
-cygpackage::cygpackage (const char *pkgname):
+cygpackage::cygpackage (String const &pkgname):
+name (pkgname),
 vendor (0),
 packagev (0),
 canonical (0),
@@ -46,8 +46,6 @@ type (package_binary),
 listdata (0),
 listfile (0)
 {
-  name = new char [strlen (pkgname) +1];
-  strcpy (name, pkgname);
   memset( getfilenamebuffer, '\0', _MAX_PATH);
 
   /* FIXME: query the install database for the currently installed 
@@ -57,10 +55,11 @@ listfile (0)
 
 /* create a package given explicit details - perhaps should be modified to take the
    filename and do it's own parsing? */
-cygpackage::cygpackage (const char *pkgname, const char *filename, size_t fs,
-                       const char *version, package_status_t newstatus,
-                       package_type_t newtype):
-fn (0),
+cygpackage::cygpackage (String const &pkgname, String const &filename, size_t const fs,
+                       String const &version, package_status_t const newstatus,
+                       package_type_t const newtype):
+name (pkgname),
+fn (filename),
 sdesc (0),
 ldesc (0),
 status (newstatus),
@@ -69,38 +68,33 @@ listdata (0),
 listfile (0),
 filesize (fs)
 {
-  name = new char [strlen (pkgname) +1];
-  strcpy (name, pkgname);
-  fn = new char [strlen (filename) +1];
-  strcpy (fn, filename);
   memset( getfilenamebuffer, '\0', _MAX_PATH);
   set_canonical_version (version);
 }
 
 /* tell the version */
 void
-cygpackage::set_canonical_version (char const *version)
+cygpackage::set_canonical_version (String const &version)
 {
-  char *curr = strchr (version, '-');
-  canonical = new char [strlen (version) +1];
-  strcpy (canonical, version);
+  canonical = version;
+  char *start = strchr (canonical.cstr_oneuse(), '-');
+  char*curr=start;
   if (curr)
     {
       char *next;
       while ((next = strchr (curr + 1, '-')))
        curr = next;
       /* curr = last - in the version string */
-      packagev = new char [strlen (curr + 1) +1];
-      strcpy (packagev, curr + 1);
-      vendor = new char [strlen (version) +1];
-      strcpy (vendor, version);
-      vendor[curr - version] = '\0';
+      packagev = curr + 1;
+      char tvendor [version.size() +1];
+      strcpy (tvendor, version.cstr_oneuse());
+      tvendor[curr - start] = '\0';
+      vendor=tvendor;
     }
   else
     {
       packagev = 0;
-      vendor = new char [strlen (version) +1];
-      strcpy (vendor, version);
+      vendor = version;
     }
   key = canonical;
 }
@@ -115,40 +109,22 @@ cygpackage::~cygpackage ()
 void
 cygpackage::destroy ()
 {
-
-  if (name)
-    delete[] name;
-  if (vendor)
-    delete[] vendor;
-  if (packagev)
-    delete[] packagev;
-  if (canonical)
-    delete[] canonical;
-  if (fn)
-    delete[] fn;
-  if (listdata)
-    delete listdata;
-  if (sdesc)
-    delete[] sdesc;
-  if (ldesc)
-    delete[] ldesc;
 }
 
-const char *
+String const
 cygpackage::getfirstfile ()
 {
   if (listdata)
     delete listdata;
   listfile =
-    io_stream::open (concat ("cygfile:///etc/setup/", name, ".lst.gz", 0),
-                    "rb");
+    io_stream::open (String ("cygfile:///etc/setup/") + name + ".lst.gz", "rb");
   listdata = compress::decompress (listfile);
   if (!listdata)
     return 0;
   return listdata->gets (getfilenamebuffer, sizeof (getfilenamebuffer));
 }
 
-const char *
+String const
 cygpackage::getnextfile ()
 {
   if (listdata)
@@ -162,49 +138,43 @@ cygpackage::uninstall ()
   if (listdata)
     delete listdata;
   listdata = 0;
-  io_stream::remove (concat ("cygfile:///etc/setup/", name, ".lst.gz", 0));
+  io_stream::remove (String("cygfile:///etc/setup/") + name + ".lst.gz");
 }
 
-const char *
+String const
 cygpackage::Name ()
 {
   return name;
 }
 
-const char *
+String const
 cygpackage::Vendor_version ()
 {
   return vendor;
 }
 
-const char *
+String const
 cygpackage::Package_version ()
 {
   return packagev;
 }
 
-const char *
+String  const
 cygpackage::Canonical_version ()
 {
   return canonical;
 }
 
 void
-cygpackage::set_sdesc (char const *desc)
+cygpackage::set_sdesc (String const &desc)
 {
-  if (sdesc)
-    delete sdesc;
-  sdesc = new char[strlen (desc) + 1];
-  strcpy (sdesc, desc);
+  sdesc = desc;
 }
 
 void
-cygpackage::set_ldesc (char const *desc)
+cygpackage::set_ldesc (String const &desc)
 {
-  if (ldesc)
-    delete ldesc;
-  ldesc = new char[strlen (desc) + 1];
-  strcpy (ldesc, desc);
+  ldesc = desc;
 }
 
 #if 0
index e5897704da2191bb5e8edd72cf2b8c02a4ea6be4..6e447709729c010eb1e549154cba435e93e7ed17 100644 (file)
 #ifndef _CYGPACKAGE_H_
 #define _CYGPACKAGE_H_
 
+#include "String++.h"
+
 class cygpackage:public packageversion
 {
 public:
-  virtual const char *Name ();
-  virtual const char *Vendor_version ();
-  virtual const char *Package_version ();
-  virtual char const *Canonical_version ();
+  virtual String const Name ();
+  virtual String const Vendor_version ();
+  virtual String const Package_version ();
+  virtual String const Canonical_version ();
   virtual package_status_t Status ()
   {
     return status;
@@ -35,13 +37,13 @@ public:
   {
     return type;
   };
-  virtual void set_sdesc (char const *);
-  virtual void set_ldesc (char const *);
-  virtual char const *SDesc ()
+  virtual void set_sdesc (String const &);
+  virtual void set_ldesc (String const &);
+  virtual String const SDesc ()
   {
     return sdesc;
   };
-  virtual char const *LDesc ()
+  virtual String const LDesc ()
   {
     return ldesc;
   };
@@ -49,26 +51,26 @@ public:
 
 
   /* pass the name of the package when constructing */
-  cygpackage (const char *);
-  cygpackage (const char *, const char *, size_t, const char *,
-             package_status_t, package_type_t);
-  void set_canonical_version (char const *);
+  cygpackage (String const &);
+  cygpackage (String const &, String const &, size_t const, String const &,
+             package_status_t const, package_type_t const);
+  void set_canonical_version (String const &);
 
 
   virtual ~ cygpackage ();
   /* TODO: we should probably return a metaclass - file name & path & size & type
      - ie doc/script/binary
    */
-  virtual const char *getfirstfile ();
-  virtual const char *getnextfile ();
+  virtual String const getfirstfile ();
+  virtual String const getnextfile ();
 private:
   void destroy ();
-  char *name;
-  char *vendor;
-  char *packagev;
-  char *canonical;
-  char *fn;
-  char *sdesc, *ldesc;
+  String name;
+  String vendor;
+  String packagev;
+  String canonical;
+  String fn;
+  String sdesc, ldesc;
   char getfilenamebuffer[_MAX_PATH];
 
 //  package_stability_t stability;
index 601239abbd8a8d2be43c211ebddc6bd191d91d72..588d187cedacafb47e814746d00ab0d3f8dc7cfe 100644 (file)
@@ -34,8 +34,6 @@ static const char *cvsid =
 #include "ini.h"
 #include "msg.h"
 #include "state.h"
-#include "concat.h"
-#include "mkdir.h"
 #include "dialog.h"
 #include "version.h"
 #include "mount.h"
@@ -48,8 +46,13 @@ static const char *cvsid =
 #include "package_meta.h"
 #include "package_version.h"
 
+#include "filemanip.h"
+#include "String++.h"
+#include "io_stream.h"
+  
 #include "desktop.h"
 
+
 static OSVERSIONINFO verinfo;
 
 /* Lines starting with '@' are conditionals - include 'N' for NT,
@@ -91,72 +94,75 @@ static const char *etc_profile[] = {
   0
 };
 
-#define COMMAND9XARGS "/E:4096 /c"
-#define COMMAND9XEXE  "\\command.com"
+#define COMMAND9XARGS String("/E:4096 /c")
+#define COMMAND9XEXE  String("\\command.com")
 
-static char *batname;
-static char *iconname;
+static String batname;
+static String iconname;
 
 static void
-make_link (const char *linkpath, const char *title, const char *target)
+make_link (String const &linkpath, String const &title, String const &target)
 {
-  char argbuf[_MAX_PATH];
-  char *fname = concat (linkpath, "/", title, ".lnk", 0);
+  String fname = linkpath + "/" + title + ".lnk";
 
-  if (_access (fname, 0) == 0)
+  if (_access (fname.cstr_oneuse(), 0) == 0)
     return;                    /* already exists */
 
-  msg ("make_link %s, %s, %s\n", fname, title, target);
+  msg ("make_link %s, %s, %s\n", fname.cstr_oneuse(), title.cstr_oneuse(), target.cstr_oneuse());
 
-  mkdir_p (0, fname);
+  io_stream::mkpath_p (PATH_TO_FILE, fname);
 
-  char *exepath;
+  String exepath;
 
+  String argbuf;
   /* If we are running Win9x, build a command line. */
   if (verinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
     {
-      exepath = concat (target, 0);
-      sprintf (argbuf, " ");
+      exepath = target;
+      argbuf = " ";
+//      sprintf (argbuf, " ");
     }
   else
     {
       char windir[MAX_PATH];
 
       GetWindowsDirectory (windir, sizeof (windir));
-      exepath = concat (windir, COMMAND9XEXE, 0);
-      sprintf (argbuf, "%s %s", COMMAND9XARGS, target);
+      exepath = String(windir) + COMMAND9XEXE;
+      argbuf = COMMAND9XARGS + " " + target;
+//      sprintf (argbuf, "%s %s", COMMAND9XARGS, target.cstr_oneuse());
     }
 
-  msg ("make_link_2 (%s, %s, %s, %s)", exepath, argbuf, iconname, fname);
-  make_link_2 (exepath, argbuf, iconname, fname);
+  msg ("make_link_2 (%s, %s, %s, %s)", exepath.cstr_oneuse(), argbuf.cstr_oneuse(), iconname.cstr_oneuse(), fname.cstr_oneuse());
+  make_link_2 (exepath.cstr_oneuse(), argbuf.cstr_oneuse(), iconname.cstr_oneuse(), fname.cstr_oneuse());
 }
 
 static void
-start_menu (const char *title, const char *target)
+start_menu (String const &title, String const &target)
 {
-  char path[_MAX_PATH];
   LPITEMIDLIST id;
   int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
   SHGetSpecialFolderLocation (NULL,
                              issystem ? CSIDL_COMMON_PROGRAMS :
                              CSIDL_PROGRAMS, &id);
-  SHGetPathFromIDList (id, path);
-// following lines added because it appears Win95 does not use common programs
-// unless it comes into play when multiple users for Win95 is enabled
-  msg ("Program directory for program link: %s", path);
-  if (strlen (path) == 0)
+  char _path[_MAX_PATH];
+  SHGetPathFromIDList (id, _path);
+  String path(_path);
+  // Win95 does not use common programs unless multiple users for Win95 is enabled
+  msg ("Program directory for program link: %s", path.cstr_oneuse());
+  if (path.size() == 0)
     {
       SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id);
-      SHGetPathFromIDList (id, path);
-      msg ("Program directory for program link changed to: %s", path);
+      SHGetPathFromIDList (id, _path);
+      path = String(_path);
+      msg ("Program directory for program link changed to: %s", path.cstr_oneuse());
     }
 // end of Win95 addition
-  strcat (path, "/Cygwin");
+  path += "/Cygwin";
   make_link (path, title, target);
 }
 
 static void
-desktop_icon (const char *title, const char *target)
+desktop_icon (String const &title, String const &target)
 {
   char path[_MAX_PATH];
   LPITEMIDLIST id;
@@ -185,18 +191,18 @@ make_cygwin_bat ()
   batname = backslash (cygpath ("/cygwin.bat", 0));
 
   /* if the batch file exists, don't overwrite it */
-  if (_access (batname, 0) == 0)
+  if (_access (batname.cstr_oneuse(), 0) == 0)
     return;
 
-  FILE *bat = fopen (batname, "wt");
+  FILE *bat = fopen (batname.cstr_oneuse(), "wt");
   if (!bat)
     return;
 
   fprintf (bat, "@echo off\n\n");
 
-  fprintf (bat, "%.2s\n", get_root_dir ());
+  fprintf (bat, "%.2s\n", get_root_dir ().cstr_oneuse());
   fprintf (bat, "chdir %s\n\n",
-          backslash (concat (get_root_dir () + 2, "/bin", 0)));
+          backslash (get_root_dir () + "/bin").cstr_oneuse());
 
   fprintf (bat, "bash --login -i\n");
 
@@ -206,10 +212,10 @@ make_cygwin_bat ()
 static void
 make_etc_profile ()
 {
-  char *fname = cygpath ("/etc/profile", 0);
+  String fname = cygpath ("/etc/profile", 0);
 
   /* if the file exists, don't overwrite it */
-  if (_access (fname, 0) == 0)
+  if (_access (fname.cstr_oneuse(), 0) == 0)
     return;
 
   char os;
@@ -230,7 +236,7 @@ make_etc_profile ()
     }
   msg ("os is %c", os);
 
-  FILE *p = fopen (fname, "wb");
+  FILE *p = fopen (fname.cstr_oneuse(), "wb");
   if (!p)
     return;
 
@@ -256,9 +262,8 @@ make_etc_profile ()
 static int
 uexists (const char *path)
 {
-  char *f = cygpath (path, 0);
-  int a = _access (f, 0);
-  delete[] f;
+  String f = cygpath (path, 0);
+  int a = _access (f.cstr_oneuse(), 0);
   if (a == 0)
     return 1;
   return 0;
@@ -267,10 +272,10 @@ uexists (const char *path)
 static void
 make_passwd_group ()
 {
-  char *fname = cygpath ("/etc/postinstall/passwd-grp.bat", 0);
-  mkdir_p (0, fname);
+  String fname = cygpath ("/etc/postinstall/passwd-grp.bat", 0);
+  io_stream::mkpath_p (PATH_TO_FILE, fname);
 
-  FILE *p = fopen (fname, "wt");
+  FILE *p = fopen (fname.cstr_oneuse(), "wt");
   if (!p)
     return;
   if (verinfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
@@ -280,10 +285,10 @@ make_passwd_group ()
       if (pkg && pkg->installed)
        {
          /* mkpasswd and mkgroup are not working on 9x/ME up to 1.1.5-4 */
-         char *border_version = canonicalize_version ("1.1.5-4");
-         char *inst_version =
+         String border_version = canonicalize_version ("1.1.5-4");
+         String inst_version =
            canonicalize_version (pkg->installed->Canonical_version ());
-         if (strcmp (inst_version, border_version) <= 0)
+         if (inst_version.compare(border_version) <= 0)
            goto out;
        }
     }
@@ -314,7 +319,7 @@ save_icon ()
   char *data = (char *) LockResource (res);
   int len = SizeofResource (NULL, rsrc);
 
-  FILE *f = fopen (iconname, "wb");
+  FILE *f = fopen (iconname.cstr_oneuse(), "wb");
   if (f)
     {
       fwrite (data, 1, len, f);
@@ -360,7 +365,7 @@ load_dialog (HWND h)
 }
 
 static int
-check_desktop (const char *title, const char *target)
+check_desktop (String const title, String const target)
 {
   char path[_MAX_PATH];
   LPITEMIDLIST id;
@@ -379,21 +384,21 @@ check_desktop (const char *title, const char *target)
       msg ("Desktop directory for deskop link changed to: %s", path);
     }
   // end of Win95 addition
-  char *fname = concat (path, "/", title, ".lnk", 0);
+  String fname = String::concat (path, "/", title.cstr_oneuse(), ".lnk", 0);
 
-  if (_access (fname, 0) == 0)
+  if (_access (fname.cstr_oneuse(), 0) == 0)
     return 0;                  /* already exists */
 
-  fname = concat (path, "/", title, ".pif", 0);        /* check for a pif as well */
+  fname = String::concat (path, "/", title.cstr_oneuse(), ".pif", 0);  /* check for a pif as well */
 
-  if (_access (fname, 0) == 0)
+  if (_access (fname.cstr_oneuse(), 0) == 0)
     return 0;                  /* already exists */
 
   return IDC_ROOT_DESKTOP;
 }
 
 static int
-check_startmenu (const char *title, const char *target)
+check_startmenu (String const title, String const target)
 {
   char path[_MAX_PATH];
   LPITEMIDLIST id;
@@ -413,14 +418,14 @@ check_startmenu (const char *title, const char *target)
     }
   // end of Win95 addition
   strcat (path, "/Cygwin");
-  char *fname = concat (path, "/", title, ".lnk", 0);
+  String fname = String::concat (path, "/", title.cstr_oneuse(), ".lnk", 0);
 
-  if (_access (fname, 0) == 0)
+  if (_access (fname.cstr_oneuse(), 0) == 0)
     return 0;                  /* already exists */
 
-  fname = concat (path, "/", title, ".pif", 0);        /* check for a pif as well */
+  fname = String::concat (path, "/", title.cstr_oneuse(), ".pif", 0);  /* check for a pif as well */
 
-  if (_access (fname, 0) == 0)
+  if (_access (fname.cstr_oneuse(), 0) == 0)
     return 0;                  /* already exists */
 
   return IDC_ROOT_MENU;
index cf36aadd24495bc6f13e16f9764522327710c1b4..26f50284643bbada581388c305309274ebe58c11 100644 (file)
--- a/dialog.cc
+++ b/dialog.cc
@@ -33,7 +33,7 @@ char *
 eget (HWND h, int id, char *var)
 {
   char tmp[4000];
-  if (var && var != get_root_dir ())
+  if (var && var != get_root_dir ().cstr_oneuse())
     {
       delete [] var;
       var = NULL;
@@ -47,6 +47,16 @@ eget (HWND h, int id, char *var)
   return var;
 }
 
+String
+egetString (HWND h, int id)
+{
+  String aString;
+  char tmp[4000];
+  if (GetDlgItemText (h, id, tmp, sizeof (tmp)) > 0)
+    aString = String (tmp);
+  return aString;
+}
+
 int
 eget (HWND h, int id)
 {
@@ -61,6 +71,12 @@ eset (HWND h, int id, const char *val)
   SetDlgItemText (h, id, val);
 }
 
+void
+eset (HWND h, int id, String const aString)
+{
+  SetDlgItemText (h, id, aString.cstr_oneuse());
+}
+
 void
 eset (HWND h, int id, int val)
 {
index 9211eee14ffc983ea6684904133920a7530fcdd6..2932b2b8a02452cb569d3afb64c770297f4d7b57 100644 (file)
--- a/dialog.h
+++ b/dialog.h
@@ -13,6 +13,8 @@
  *
  */
 
+#include "String++.h"
+
 /* global instance for the application; set in main.cc */
 extern HINSTANCE hinstance;
 
@@ -51,13 +53,18 @@ D (do_splash);
 
 char *eget (HWND h, int id, char *var);
 
+/* Get the value of an EditText control. */
+
+String egetString (HWND h, int id);
+
 /* Same, but convert the value to an integer */
 
 int eget (HWND h, int id);
 
-/* Set the EditText control to the given string or integer */
+/* Set the EditText control to the given value */
 
 void eset (HWND h, int id, const char *var);
+void eset (HWND h, int id, String const);
 void eset (HWND h, int id, int var);
 
 /* RadioButtons.  ids is a null-terminated list of IDs.  Get
index 7029433588d1e708d62974bc56b8e23399f739a2..0a85e65d77b0a2effd720e117778c1def897aec5 100644 (file)
@@ -31,7 +31,7 @@ typedef BOOL WINAPI (*GDFS) (LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER,
                             PULARGE_INTEGER);
 
 int
-diskfull (const char *path)
+diskfull (String const &path)
 {
   WINAPI GDFS gdfs = 0;
 
@@ -43,7 +43,7 @@ diskfull (const char *path)
       if (gdfs)
        {
          ULARGE_INTEGER avail, total, free;
-         if (gdfs (path, &avail, &total, &free))
+         if (gdfs (path.cstr_oneuse(), &avail, &total, &free))
            {
              int perc = avail.QuadPart * 100 / total.QuadPart;
              return 100 - perc;
@@ -52,10 +52,10 @@ diskfull (const char *path)
     }
 
   char root[4];
-  if (path[1] != ':')
+  if (path.cstr_oneuse()[1] != ':')
     return 0;
 
-  root[0] = path[0];
+  root[0] = path.cstr_oneuse()[0];
   root[1] = ':';
   root[2] = '\\';
   root[3] = 0;
index f69a071fb5435f338accd81e975ffc063ab0e530..e95afe9339dbdfedc7b36bb69c16bc39fb10de2f 100644 (file)
@@ -13,5 +13,7 @@
  *
  */
 
+#include "String++.h"
+
 /* returns 0..100 (percent) */
-int diskfull (const char *path);
+int diskfull (String const &path);
index f3542cfbfa8b903e90bd43cca43c010a1cff472a..5152d709119a87f99a8e28ad78fad9426cf2b68e 100644 (file)
@@ -31,7 +31,7 @@ static const char *cvsid =
 #include "msg.h"
 #include "ini.h"
 #include "dialog.h"
-#include "concat.h"
+#include "String++.h"
 #include "geturl.h"
 #include "state.h"
 #include "mkdir.h"
@@ -64,13 +64,12 @@ check_for_cached (packagesource & pkgsource)
 
   DWORD size;
   if ((size =
-       get_file_size (concat (local_dir, "/", pkgsource.Canonical (), 0))) >
+       get_file_size (local_dir +  "/" + pkgsource.Canonical ())) >
       0)
     if (size == pkgsource.size)
       {
        pkgsource.
-         set_cached (concat
-                     ("file://", local_dir, "/", pkgsource.Canonical (), 0));
+         set_cached (String ("file://") + local_dir +  "/" + pkgsource.Canonical ());
        return 1;
       }
 
@@ -79,18 +78,16 @@ check_for_cached (packagesource & pkgsource)
    */
   for (size_t n = 1; n <= pkgsource.sites.number (); n++)
     if ((size =
-        get_file_size (concat
-                       (local_dir, "/",
-                        rfc1738_escape_part (pkgsource.sites[n]->key), "/",
-                        pkgsource.Canonical (), 0))) > 0)
+        get_file_size (local_dir + "/" +
+                        rfc1738_escape_part (pkgsource.sites[n]->key) + "/" +
+                        pkgsource.Canonical ())) > 0)
       if (size == pkgsource.size)
        {
          pkgsource.
-           set_cached (concat
-                       ("file://", local_dir, "/",
+           set_cached (String ("file://") + local_dir + "/" +
                         rfc1738_escape_part (pkgsource.sites[n]->
-                                             key), "/",
-                        pkgsource.Canonical (), 0));
+                                             key) + "/" +
+                        pkgsource.Canonical ());
          return 1;
        }
 
@@ -109,38 +106,38 @@ download_one (packagesource & pkgsource, HWND owner)
   int success = 0;
   for (size_t n = 1; n <= pkgsource.sites.number () && !success; n++)
     {
-      const char *local = concat (local_dir, "/",
+      String const local = local_dir + "/" +
                                  rfc1738_escape_part (pkgsource.sites[n]->
-                                                      key), "/",
-                                 pkgsource.Canonical (), 0);
-      io_stream::mkpath_p (PATH_TO_FILE, concat ("file://", local, 0));
-
-      if (get_url_to_file
-         (concat
-          (pkgsource.sites[n]->key, "/", pkgsource.Canonical (), 0),
-          concat (local, ".tmp", 0), pkgsource.size, owner))
+                                                      key) + "/" +
+                                 pkgsource.Canonical ();
+      io_stream::mkpath_p (PATH_TO_FILE, (String ("file://") + local).cstr_oneuse());
+
+      if (get_url_to_file(String (pkgsource.sites[n]->key) +  "/" + pkgsource.Canonical (),
+          local + ".tmp", pkgsource.size, owner))
        {
          /* FIXME: note new source ? */
          continue;
        }
       else
        {
-         size_t size = get_file_size (concat (local, ".tmp", 0));
+         size_t size = get_file_size (local + ".tmp");
          if (size == pkgsource.size)
            {
-             log (0, "Downloaded %s", local);
-             if (_access (local, 0) == 0)
-               remove (local);
-             rename (concat (local, ".tmp", 0), local);
+             log (LOG_TIMESTAMP, "Downloaded %s", local.cstr_oneuse());
+             if (_access (local.cstr_oneuse(), 0) == 0)
+               remove (local.cstr_oneuse());
+             rename ((local + ".tmp").cstr_oneuse(), local.cstr_oneuse());
              success = 1;
-             pkgsource.set_cached (concat ("file://", local, 0));
+             pkgsource.set_cached (String ("file://") + local);
+             // FIXME: move the downloaded file to the 
+             //  original locations - without the mirror site dir in the way
              continue;
            }
          else
            {
-             log (0, "Download %s wrong size (%u actual vs %d expected)",
-                  local, size, pkgsource.size);
-             remove (concat (local, ".tmp", 0));
+             log (LOG_TIMESTAMP, "Download %s wrong size (%u actual vs %d expected)",
+                  local.cstr_oneuse(), size, pkgsource.size);
+             remove ((local + ".tmp").cstr_oneuse());
              continue;
            }
        }
index 7aea9e038c5984b0df88e74f762152ac59b441a3..16331ca477e54460796cd9d439982c0771981106 100644 (file)
@@ -30,13 +30,13 @@ static const char *cvsid =
 #include "filemanip.h"
 
 unsigned int
-get_file_size (const char *name)
+get_file_size (String const &name)
 {
   HANDLE h;
   WIN32_FIND_DATA buf;
   DWORD ret = 0;
 
-  h = FindFirstFileA (name, &buf);
+  h = FindFirstFileA (name.cstr_oneuse(), &buf);
   if (h != INVALID_HANDLE_VALUE)
     {
       if (buf.nFileSizeHigh == 0)
@@ -46,19 +46,22 @@ get_file_size (const char *name)
   return ret;
 }
 
-char *
-base (const char *s)
+String 
+base (String const &aString)
 {
-  if (!s)
+  if (!aString.size())
     return 0;
-  const char *rv = s;
+  const char *t = aString.cstr();
+  const char *s = t;
+  String rv = s;
   while (*s)
     {
       if ((*s == '/' || *s == ':' || *s == '\\') && s[1])
        rv = s + 1;
       s++;
     }
-  return (char *) rv;
+  delete[] t;
+  return rv;
 }
 
 /* returns the number of characters of path that
@@ -81,64 +84,78 @@ find_tar_ext (const char *path)
 
 /* Parse a filename into package, version, and extension components. */
 int
-parse_filename (const char *in_fn, fileparse & f)
+parse_filename (String const &in_fn, fileparse & f)
 {
   char *p, *ver;
-  char fn[strlen (in_fn) + 1];
-
-  strcpy (fn, in_fn);
+  char fn[in_fn.size() + 1];
+  strcpy (fn, in_fn.cstr_oneuse());
+  
   int n = find_tar_ext (fn);
 
   if (!n)
     return 0;
 
-  strcpy (f.tail, fn + n);
+  f.tail = fn + n;
   fn[n] = '\0';
-  f.pkg[0] = f.what[0] = '\0';
-  p = base (fn);
+  f.pkg = f.what = String();
+  p = base (fn).cstr();
   for (ver = p; *ver; ver++)
-    if (*ver == '-' || *ver == '_')
+    if (*ver == '-')
       if (isdigit (ver[1]))
        {
          *ver++ = 0;
-         strcpy (f.pkg, p);
+         f.pkg = p;
          break;
        }
       else if (strcasecmp (ver, "-src") == 0 ||
               strcasecmp (ver, "-patch") == 0)
        {
          *ver++ = 0;
-         strcpy (f.pkg, p);
-         strcpy (f.what, strlwr (ver));
-         strcpy (f.pkgtar, p);
-         strcat (f.pkgtar, f.tail);
+         f.pkg = p;
+         f.what = strlwr (ver);
+         f.pkgtar = String(p) + f.tail;
          ver = strchr (ver, '\0');
          break;
        }
 
-  if (!f.pkg[0])
-    strcpy (f.pkg, p);
+  if (!f.pkg.size())
+    f.pkg = p;
 
-  if (!f.what[0])
+  if (!f.what.size())
     {
       int n;
-      p = strchr (ver, '\0');
-      strcpy (f.pkgtar, in_fn);
-      if ((p -= 4) >= ver && strcasecmp (p, "-src") == 0)
+      char *p1 = strchr (ver, '\0');
+      f.pkgtar = in_fn;
+      if ((p1 -= 4) >= ver && strcasecmp (p1, "-src") == 0)
        n = 4;
-      else if ((p -= 2) >= ver && strcasecmp (p, "-patch") == 0)
+      else if ((p1 -= 2) >= ver && strcasecmp (p1, "-patch") == 0)
        n = 6;
       else
        n = 0;
       if (n)
        {
-         strcpy (f.what, p + 1);
-         *p = '\0';
-         p = f.pkgtar + (p - fn) + n;
-         memmove (p - n, p, strlen (p));
+         // XXX This maybe broken. What does it do?
+         f.what = p1 + 1;
+         *p1 = '\0';
+         p1 = p + (p1 - fn) + n;
+         memmove (p1 - n, p1, strlen (p1));
+         f.pkgtar = p;
        }
     }
 
-  strcpy (f.ver, *ver ? ver : "0.0");
+  f.ver = *ver ? ver : "0.0";
+  delete[] p;
   return 1;
 }
+
+String
+backslash (String const & aString)
+{
+  char * tempString = aString.cstr();
+  for (char *t = tempString; *t; t++)
+    if (*t == '/')
+      *t = '\\';
+  String theString(tempString);
+  delete[] tempString;
+  return theString;
+}
index d16fc8e7ba6951f29402d7730cf65f8a3b90e22a..c4d1d49169a55837feb157318fab05ed20f47a15 100644 (file)
  *
  */
 
+#include "String++.h"
+
 extern int find_tar_ext (const char *path);
 
 typedef struct
 {
-  char pkgtar[MAX_PATH + 1];
-  char pkg[MAX_PATH + 1];
-  char ver[MAX_PATH + 1];
-  char tail[MAX_PATH + 1];
-  char what[16];
+  String pkgtar;
+  String pkg;
+  String ver;
+  String tail;
+  String what;
 }
 fileparse;
 
-int parse_filename (const char *in_fn, fileparse & f);
-char *base (const char *name);
-unsigned int get_file_size (const char *name);
+int parse_filename (String const & in_fn, fileparse & f);
+String base (String const &);
+unsigned int get_file_size (String const &);
+String backslash (String const &);
diff --git a/find.cc b/find.cc
index c91de52e6e2598970281de6535a61885f9cab64e..a3d7de0277505668b778dde676af80fbb96b6ab4 100644 (file)
--- a/find.cc
+++ b/find.cc
@@ -27,11 +27,13 @@ static const char *cvsid =
 
 #include "port.h"
 
-static void (*for_each) (char *, unsigned int);
+#include "String++.h"
+#include "find.h"
+
 static char dir[_MAX_PATH], *found_part;
 
 static int
-find_sub ()
+find_sub (void (*for_each) (char *, unsigned int))
 {
   WIN32_FIND_DATA wfd;
   HANDLE h;
@@ -55,7 +57,7 @@ find_sub ()
       strcpy (end, wfd.cFileName);
 
       if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
-       find_sub ();
+       find_sub (for_each);
       else
        {
          for_each (found_part, wfd.nFileSizeLow);
@@ -70,11 +72,10 @@ find_sub ()
 }
 
 int
-find (const char *starting_dir, void (*_for_each) (char *, unsigned int))
+find (String const &starting_dir, void (*_for_each) (char *, unsigned int))
 {
-  strcpy (dir, starting_dir);
-  for_each = _for_each;
+  strcpy (dir, starting_dir.cstr_oneuse());
   found_part = dir + strlen (dir) + 1;
 
-  return find_sub ();
+  return find_sub (_for_each);
 }
diff --git a/find.h b/find.h
index 059042988d96726285d8bd8d82a5c8d3af0afa56..74ac66cb685ac775f3865774448cd91f09fa1bec 100644 (file)
--- a/find.h
+++ b/find.h
@@ -19,5 +19,6 @@
    (bytes).  find() returns the number of files found.  Directories
    are scanned but not included in the "found" files. */
 
-extern int find (const char *starting_dir,
+class String;
+extern int find (String const &starting_dir,
                 void (*for_each) (char *, unsigned int));
index adb7c6a94817ba63b6ff22f249930b7b1dbcc97d..dbb220b4d368094222a1045f5ce90aa1e882b8d4 100644 (file)
@@ -74,25 +74,25 @@ found_file (char *path, unsigned int fsize)
   if (!parse_filename (path, f))
     return;
 
-  if (f.what[0] != '\0')
+  if (f.what.size() != 0)
     return;
 
   packagedb db;
   packagemeta &p = db.packages.registerbykey (f.pkg);
   packageversion *pv = new cygpackage (f.pkg);
   ((cygpackage *)pv)->set_canonical_version (f.ver);
-  if (!f.what[0])
-    pv->bin.set_cached (concat ("file://", path, 0));
+  if (!f.what.size())
+    pv->bin.set_cached (String ("file://") + path);
   else
     // patch or src, assume src until someone complains
-    pv->src.set_cached (concat ("file://", path, 0));
+    pv->src.set_cached (String ("file://") + path);
 
   // check for a duplciate version FIXME make this a method or friend
 
 
   int merged = 0;
   for (size_t n = 1; !merged && n <= p.versions.number (); n++)
-    if (!strcasecmp(p.versions[n]->Canonical_version(), pv->Canonical_version()))
+    if (!p.versions[n]->Canonical_version().casecompare (pv->Canonical_version()))
       {
         /* Copy the binary mirror across if this site claims to have an install */
         if (pv->bin.sites.number ())
@@ -101,9 +101,9 @@ found_file (char *path, unsigned int fsize)
         if (pv->src.sites.number ())
           p.versions[n]->src.sites.registerbykey (pv->src.sites[1]->key);
         /* Copy the descriptions across */
-        if (pv->SDesc () && !p.versions[n]->SDesc ())
+        if (pv->SDesc ().size() && !p.versions[n]->SDesc ().size())
           p.versions[n]->set_sdesc (pv->SDesc ());
-        if (pv->LDesc () && !p.versions[n]->LDesc ())
+        if (pv->LDesc ().size() && !p.versions[n]->LDesc ().size())
           p.versions[n]->set_ldesc (pv->LDesc ());
         pv = p.versions[n];
         merged = 1;
index d6ef257e8c2720981845ae096f5d6db44ba6908f..e27c6a4ff3aac3c0ea60727bf334cd9f8f0868d3 100644 (file)
--- a/geturl.cc
+++ b/geturl.cc
@@ -44,6 +44,9 @@ static const char *cvsid =
 #include "mount.h"
 
 #include "threebar.h"
+
+#include "String++.h"  
+
 extern ThreeBarProgressPage Progress;
 
 static int max_bytes = 0;
@@ -55,14 +58,15 @@ int total_download_bytes_sofar = 0;
 static DWORD start_tics;
 
 static void
-init_dialog (char const *url, int length, HWND owner)
+init_dialog (String const &url, int length, HWND owner)
 {
   if (is_local_install)
     return;
 
-  char const *sl = url;
+  char const *temp = url.cstr();
+  char const *sl = temp;
   char const *cp;
-  for (cp = url; *cp; cp++)
+  for (cp = sl; *cp; cp++)
     if (*cp == '/' || *cp == '\\' || *cp == ':')
       sl = cp + 1;
   max_bytes = length;
@@ -71,6 +75,7 @@ init_dialog (char const *url, int length, HWND owner)
   Progress.SetText3("Connecting...");
   Progress.SetBar1(0);
   start_tics = GetTickCount ();
+  delete[] temp;
 }
 
 
@@ -108,12 +113,12 @@ progress (int bytes)
 }
 
 io_stream *
-get_url_to_membuf (char const *_url, HWND owner)
+get_url_to_membuf (String const &_url, HWND owner)
 {
-       log (LOG_BABBLE, "get_url_to_membuf %s", _url);
+  log (LOG_BABBLE, "get_url_to_membuf %s", _url.cstr_oneuse());
   is_local_install = (source == IDC_SOURCE_CWD);
   init_dialog (_url, 0, owner);
-  NetIO *n = NetIO::open (_url);
+  NetIO *n = NetIO::open (_url.cstr_oneuse());
   if (!n || !n->ok ())
     {
       delete n;
@@ -161,49 +166,44 @@ get_url_to_membuf (char const *_url, HWND owner)
   return membuf;
 }
 
-char *
-get_url_to_string (char const *_url, HWND owner)
+// predicate: url has no '\0''s in it.
+String
+get_url_to_string (String const &_url, HWND owner)
 {
   io_stream *stream = get_url_to_membuf (_url, owner);
   if (!stream)
-    return 0;
+    return String();
   size_t bytes = stream->get_size ();
   if (!bytes)
     {
       /* zero length, or error retrieving length */
       delete stream;
       log (LOG_BABBLE, "get_url_to_string(): couldn't retrieve buffer size, or zero length buffer");
-      return 0;
-    }
-  char *rv = new char [bytes + 1];
-  if (!rv)
-    {
-      delete stream;
-      log (LOG_BABBLE, "get_url_to_string(): new failed for rv!");
-      return 0;
+      return String();
     }
+  char temp [bytes + 1];
   /* membufs are quite safe */
-  stream->read (rv, bytes);
-  rv [bytes] = '\0';
+  stream->read (temp, bytes);
+  temp [bytes] = '\0';
   delete stream;
-  return rv;
+  return String(temp);
 }
 
 int
-get_url_to_file (char *_url, char *_filename, int expected_length,
+get_url_to_file (String const &_url, String const &_filename, int expected_length,
                 HWND owner, BOOL allow_ftp_auth)
 {
-  log (LOG_BABBLE, "get_url_to_file %s %s", _url, _filename);
+  log (LOG_BABBLE, "get_url_to_file %s %s", _url.cstr_oneuse(), _filename.cstr_oneuse());
   if (total_download_bytes > 0)
     {
-      int df = diskfull (get_root_dir ());
-         Progress.SetBar3(df);
+      int df = diskfull (get_root_dir ().cstr_oneuse());
+      Progress.SetBar3(df);
     }
   init_dialog (_url, expected_length, owner);
 
-  remove (_filename);          /* but ignore errors */
+  remove (_filename.cstr_oneuse());            /* but ignore errors */
 
-  NetIO *n = NetIO::open (_url, allow_ftp_auth);
+  NetIO *n = NetIO::open (_url.cstr_oneuse(), allow_ftp_auth);
   if (!n || !n->ok ())
     {
       delete n;
@@ -211,13 +211,13 @@ get_url_to_file (char *_url, char *_filename, int expected_length,
       return 1;
     }
 
-  FILE *f = fopen (_filename, "wb");
+  FILE *f = fopen (_filename.cstr_oneuse(), "wb");
   if (!f)
     {
       const char *err = strerror (errno);
       if (!err)
        err = "(unknown error)";
-      fatal (owner, IDS_ERR_OPEN_WRITE, _filename, err);
+      fatal (owner, IDS_ERR_OPEN_WRITE, _filename.cstr_oneuse(), err);
     }
 
   if (n->file_size)
@@ -245,7 +245,7 @@ get_url_to_file (char *_url, char *_filename, int expected_length,
 
   if (total_download_bytes > 0)
     {
-      int df = diskfull (get_root_dir ());
+      int df = diskfull (get_root_dir ().cstr_oneuse());
          Progress.SetBar3(df);
     }
 
index 822afd0b61ca2b0979d5b2645366c0c369c9edbe..6f805c2405834294fd55fb57cb617bd831ea2144 100644 (file)
--- a/geturl.h
+++ b/geturl.h
@@ -20,9 +20,10 @@ extern int total_download_bytes;
 extern int total_download_bytes_sofar;
 
 class io_stream;
+class String;
 
-io_stream *get_url_to_membuf (char const *, HWND owner);
-char *get_url_to_string (char const *, HWND owner);
-int get_url_to_file (char *_url, char *_filename, int expected_size,
+io_stream *get_url_to_membuf (String const &, HWND owner);
+String get_url_to_string (String const&, HWND owner);
+int get_url_to_file (String const &_url, String const &_filename, int expected_size,
                     HWND owner, BOOL allow_ftp_auth = FALSE);
 void dismiss_url_status_dialog ();
diff --git a/hash.h b/hash.h
index c82ae93a7a776397e0baa8abff5b73d830ca98a7..079e72479982bbd2ed7d1edee77fcfcaecb8cfcb 100644 (file)
--- a/hash.h
+++ b/hash.h
@@ -15,6 +15,8 @@
 
 /* Simple hash class for install.cc */
 
+#include  "String++.h"
+
 class hash_internals;
 
 class hash
@@ -29,7 +31,7 @@ public:
 
   /* FIXME: this specialty should be done via a derived class */
   /* specialty for install.cc */
-  void add_subdirs (char const *path);
+  void add_subdirs (String const &path);
   void reverse_sort ();
 
   char *enumerate (char const *prev = 0);
diff --git a/ini.cc b/ini.cc
index 83a7d3943697cf8f05bc2f87c450f6f9a1549ab2..6c33164b7fb696b9f166249940cf5ee320c3c078 100644 (file)
--- a/ini.cc
+++ b/ini.cc
@@ -32,7 +32,7 @@ static const char *cvsid =
 
 #include "ini.h"
 #include "resource.h"
-#include "concat.h"
+#include "String++.h"
 #include "state.h"
 #include "geturl.h"
 #include "dialog.h"
@@ -65,18 +65,20 @@ 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");
+  io_stream *ini_file = io_stream::open (String ("file://") + local_dir + "/" + path, "rb");
   if (!ini_file)
     {
-    note (NULL, IDS_SETUPINI_MISSING, path);
+    note (NULL, IDS_SETUPINI_MISSING, (String ("file://") + local_dir + "/" + path).cstr_oneuse());
     return;
     }
+  else
+    log (LOG_BABBLE, String ("Found ini file - file://") + local_dir + "/" + path);
 
   /* FIXME: only use most recent copy */
   setup_timestamp = 0;
   setup_version = 0;
 
-  ini_init (ini_file, concat ("file://", local_dir,"/", path, 0));
+  ini_init (ini_file, String ("file://") + local_dir + "/" + path);
 
   /*yydebug = 1; */
 
@@ -102,11 +104,11 @@ do_remote_ini (HWND owner)
   for (size_t n = 1; n <= site_list.number (); n++)
     {
       io_stream *ini_file =
-       get_url_to_membuf (concat (site_list[n]->url, "/setup.ini", 0), owner);
+       get_url_to_membuf (site_list[n]->url + "/setup.ini", owner);
 
       if (!ini_file)
        {
-         note (owner, IDS_SETUPINI_MISSING, site_list[n]->url);
+         note (owner, IDS_SETUPINI_MISSING, site_list[n]->url.cstr_oneuse());
          continue;
        }
 
@@ -124,19 +126,18 @@ do_remote_ini (HWND owner)
       else
        {
          /* save known-good setup.ini locally */
-         char const *fp = concat ("file://", local_dir, "/",
-                                  rfc1738_escape_part (site_list[n]->url),
-                                  "/setup.ini", 0);
+         String const fp = String ("file://") + local_dir + "/" +
+                                  rfc1738_escape_part (site_list[n]->url) +
+                                  "/setup.ini";
          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);
+               io_stream::remove (fp.cstr_oneuse());
              delete ini_file;
              delete inistream;
            }
-         delete[] fp;
          ++ini_count;
        }
     }
@@ -158,7 +159,7 @@ do_ini_thread (HINSTANCE h, HWND owner)
       return;
     }
 
-  if (get_root_dir ())
+  if (get_root_dir ().cstr_oneuse())
     {
       io_stream::mkpath_p (PATH_TO_DIR, "cygfile:///etc/setup");
 
@@ -198,9 +199,10 @@ do_ini_thread (HINSTANCE h, HWND owner)
        version);
   if (setup_version)
     {
-      char *ini_version = canonicalize_version (setup_version);
-      char *our_version = canonicalize_version (version);
-      if (strcmp (our_version, ini_version) < 0)
+      String ini_version = canonicalize_version (setup_version);
+      String our_version = canonicalize_version (version);
+      // XXX useversion < operator
+      if (our_version.compare (ini_version) < 0)
        note (owner, IDS_OLD_SETUP_VERSION, version, setup_version);
     }
 
diff --git a/ini.h b/ini.h
index ed76034682a64552747bb653ff26ff24fd222699..324c01da958c8033c71d0bb0b6819566abde39d9 100644 (file)
--- a/ini.h
+++ b/ini.h
@@ -17,7 +17,8 @@
 #define _INI_H_
 
 class io_stream;
-void ini_init (io_stream *, char const *);
+class String;
+void ini_init (io_stream *, String const &);
 #define YYSTYPE char *
 
 #ifdef __cplusplus
index e99a03e32cfebabfb415ad21c3dae3424aa572f7..3b8a43b977ea33dd9d938f72560636d6f5533135 100644 (file)
--- a/inilex.l
+++ b/inilex.l
@@ -23,6 +23,7 @@
 
 #include "ini.h"
 #include "iniparse.h"
+#include "String++.h"
 
 #define YY_INPUT(buf,result,max_size) { result = ini_getchar(buf, max_size); }
 
@@ -90,13 +91,12 @@ static io_stream *input_stream = 0;
 extern char *parse_mirror;
 
 void
-ini_init(io_stream *stream, char const *mirror)
+ini_init(io_stream *stream, String const &mirror)
 {
   input_stream = stream;
   if (parse_mirror)
     delete[] parse_mirror;
-  parse_mirror = new char[strlen (mirror) + 1];
-  strcpy (parse_mirror, mirror);
+  parse_mirror = mirror.cstr();
 }
 
 static int
index 6217c480064b70f32c321401f8e96c8fc30d175d..e8c04118afc0da8127df8c9191bdbce004ab875e 100644 (file)
@@ -97,7 +97,7 @@ simple_line
  | LDESC STRING                        { cpv->set_ldesc ($2); }
  | CATEGORY categories
  | REQUIRES requires
- | INSTALL STRING STRING       { if (!cpv->Canonical_version ())
+ | INSTALL STRING STRING       { if (!cpv->Canonical_version ().size())
                                  {
                                    fileparse f;
                                    if (parse_filename ($2, f))
@@ -126,7 +126,7 @@ simple_line
  | T_UNKNOWN                   { trust = TRUST_UNKNOWN; }
  | /* empty */
  | error '\n' { yylineno --;
-               yyerror ("unrecognized line in package %s (do you have the latest setup?)", cp->name);
+               yyerror ("unrecognized line in package %s (do you have the latest setup?)", cp->name.cstr_oneuse());
                yylineno ++;
              }
  ;
@@ -149,7 +149,7 @@ add_correct_version()
 {
   int merged = 0;
   for (size_t n = 1; !merged && n <= cp->versions.number (); n++)
-      if (!strcasecmp(cp->versions[n]->Canonical_version(), cpv->Canonical_version()))
+      if (!cp->versions[n]->Canonical_version().casecompare(cpv->Canonical_version()))
       {
        /* ASSUMPTIONS:
           categories and requires are consistent for the same version across
@@ -162,9 +162,9 @@ add_correct_version()
        if (cpv->src.sites.number ())
          cp->versions[n]->src.sites.registerbykey (cpv->src.sites[1]->key);
        /* Copy the descriptions across */
-       if (cpv->SDesc () && !cp->versions[n]->SDesc ())
+       if (cpv->SDesc ().size() && !cp->versions[n]->SDesc ().size())
          cp->versions[n]->set_sdesc (cpv->SDesc ());
-       if (cpv->LDesc () && !cp->versions[n]->LDesc ())
+       if (cpv->LDesc ().size() && !cp->versions[n]->LDesc ().size())
          cp->versions[n]->set_ldesc (cpv->LDesc ());
        cpv = (cygpackage *)cp->versions[n];
        merged = 1;
index f39800cd0bf9eccebd0fe0465be0e05fd5687aed..fb2df208e35833cd69e7c83fe091ce6426aa2dd3 100644 (file)
@@ -41,7 +41,6 @@ static const char *cvsid = "\n%%% $Id$\n";
 #include "dialog.h"
 #include "concat.h"
 #include "geturl.h"
-#include "mkdir.h"
 #include "state.h"
 #include "diskfull.h"
 #include "msg.h"
@@ -113,8 +112,8 @@ static const char *standard_dirs[] = {
 static int num_installs, num_replacements, num_uninstalls;
 static void uninstall_one (packagemeta &);
 static int replace_one (packagemeta &);
-static int install_one_source (packagemeta &, packagesource &, char const *,
-                              char const *, package_type_t);
+static int install_one_source (packagemeta &, packagesource &, String const &,
+                              String const &, package_type_t);
 static bool rebootneeded;
 
 /* FIXME: upgrades should be a method too */
@@ -122,8 +121,8 @@ static void
 uninstall_one (packagemeta & pkgm)
 {
   Progress.SetText1 ("Uninstalling...");
-  Progress.SetText2 (pkgm.name);
-  log (0, "Uninstalling %s", pkgm.name);
+  Progress.SetText2 (pkgm.name.cstr_oneuse());
+  log (LOG_TIMESTAMP, String("Uninstalling ") + pkgm.name);
   pkgm.uninstall ();
   num_uninstalls++;
 }
@@ -139,8 +138,8 @@ replace_one (packagemeta & pkg)
 {
   int errors = 0;
   Progress.SetText1 ("Replacing...");
-  Progress.SetText2 (pkg.name);
-  log (0, "Replacing %s", pkg.name);
+  Progress.SetText2 (pkg.name.cstr_oneuse());
+  log (LOG_TIMESTAMP, String( "Replacing ")  + pkg.name);
   pkg.uninstall ();
 
   errors +=
@@ -155,7 +154,7 @@ replace_one (packagemeta & pkg)
 /* install one source at a given prefix. */
 static int
 install_one_source (packagemeta & pkgm, packagesource & source,
-                   char const *prefixURL, char const *prefixPath, package_type_t type)
+                   String const &prefixURL, String const &prefixPath, package_type_t type)
 {
   int errors = 0;
   Progress.SetText2 (source.Base ());
@@ -169,7 +168,7 @@ install_one_source (packagemeta & pkgm, packagesource & source,
     {
       io_stream *tmp =
        io_stream::
-       open (concat ("cygfile:///etc/setup/", pkgm.name, ".lst.gz", 0),
+       open (String ("cygfile:///etc/setup/") + pkgm.name + ".lst.gz",
              "wb");
       lst = new compress_gz (tmp, "w9");
       if (lst->error ())
@@ -184,7 +183,7 @@ install_one_source (packagemeta & pkgm, packagesource & source,
   char msg[64];
   strcpy (msg, "Installing");
   Progress.SetText1 (msg);
-  log (0, "%s %s", msg, source.Cached ());
+  log (LOG_TIMESTAMP, "%s %s", msg, source.Cached ());
   io_stream *tmp = io_stream::open (source.Cached (), "rb");
   archive *thefile = 0;
   if (tmp)
@@ -198,21 +197,25 @@ install_one_source (packagemeta & pkgm, packagesource & source,
   /* FIXME: potential leak of either *tmp or *tmp2 */
   if (thefile)
     {
-      const char *fn;
-      while ((fn = thefile->next_file_name ()))
+      String fn;
+      while ((fn = thefile->next_file_name ()).size())
        {
          if (lst)
-           lst->write (concat (fn, "\n", 0), strlen (fn) + 1);
+           {
+             String tmp=fn + "\n";
+             lst->write (tmp.cstr_oneuse(), tmp.size() + 1);
+           }
+
+         String canonicalfn = prefixPath + fn;
 
-         /* FIXME: concat leaks memory */
-         Progress.SetText3 (concat (prefixPath, fn, 0));
-         log (LOG_BABBLE, "Installing file %s%s%s", prefixURL,prefixPath, fn);
+         Progress.SetText3 (canonicalfn.cstr_oneuse());
+         log (LOG_BABBLE, String("Installing file ") + prefixURL + prefixPath + fn);
          if (archive::extract_file (thefile, prefixURL, prefixPath) != 0)
            {
              //extract to temp location
              if (archive::extract_file (thefile, prefixURL, prefixPath, ".new") != 0)
                {
-                 log (0, "Unable to install file %s%s%s", prefixURL,prefixPath, fn);
+                 log (LOG_TIMESTAMP, String("Unable to install file ")+ prefixURL+prefixPath+ fn);
                  errors++;
                }
              else
@@ -224,14 +227,13 @@ install_one_source (packagemeta & pkgm, packagesource & source,
                      /* Get the short file names */
                      char source[MAX_PATH];
                      unsigned int len =
-                       GetShortPathName (cygpath ("/", fn, ".new", 0),
+                       GetShortPathName (cygpath ("/", fn.cstr_oneuse(), ".new", 0).cstr_oneuse(),
                                          source, MAX_PATH);
                      if (!len || len > MAX_PATH)
                        {
-                         log (0,
+                         log (LOG_TIMESTAMP,
                               "Unable to schedule reboot replacement of file %s with %s (Win32 Error %ld)",
-                              cygpath ("/", fn, 0), cygpath ("/", fn, ".new",
-                                                             0),
+                              cygpath ("/", fn.cstr_oneuse(), 0).cstr_oneuse(), cygpath ("/", fn.cstr_oneuse(), ".new", 0).cstr_oneuse(),
                               GetLastError ());
                          ++errors;
                        }
@@ -239,14 +241,14 @@ install_one_source (packagemeta & pkgm, packagesource & source,
                        {
                          char dest[MAX_PATH];
                          len =
-                           GetShortPathName (cygpath ("/", fn, 0), dest,
+                           GetShortPathName (cygpath ("/", fn.cstr_oneuse(), 0).cstr_oneuse(), dest,
                                              MAX_PATH);
                          if (!len || len > MAX_PATH)
                            {
-                             log (0,
+                             log (LOG_TIMESTAMP,
                                   "Unable to schedule reboot replacement of file %s with %s (Win32 Error %ld)",
-                                  cygpath ("/", fn, 0), cygpath ("/", fn,
-                                                                 ".new", 0),
+                                  cygpath ("/", fn.cstr_oneuse(), 0).cstr_oneuse(), cygpath ("/", fn.cstr_oneuse(),
+                                                                 ".new", 0).cstr_oneuse(),
                                   GetLastError ());
                              ++errors;
 
@@ -256,10 +258,10 @@ install_one_source (packagemeta & pkgm, packagesource & source,
                          if (!WritePrivateProfileString
                                ("rename", dest, source, "WININIT.INI"))
                            {
-                             log (0,
+                             log (LOG_TIMESTAMP,
                                   "Unable to schedule reboot replacement of file %s with %s (Win32 Error %ld)",
-                                  cygpath ("/", fn, 0), cygpath ("/", fn,
-                                                                 ".new", 0),
+                                  cygpath ("/", fn.cstr_oneuse(), 0).cstr_oneuse(), cygpath ("/", fn.cstr_oneuse(),
+                                                                 ".new", 0).cstr_oneuse(),
                                   GetLastError ());
                              ++errors;
                            }
@@ -273,15 +275,14 @@ install_one_source (packagemeta & pkgm, packagesource & source,
                       * - we need a io method to get win32 paths 
                       * or to wrap this system call
                       */
-                     if (!MoveFileEx (cygpath ("/", fn, ".new", 0),
-                                      cygpath ("/", fn, 0),
+                     if (!MoveFileEx (cygpath ("/", fn.cstr_oneuse(), ".new", 0).cstr_oneuse(),
+                                      cygpath ("/", fn.cstr_oneuse(), 0).cstr_oneuse(),
                                       MOVEFILE_DELAY_UNTIL_REBOOT |
                                       MOVEFILE_REPLACE_EXISTING))
                        {
-                         log (0,
+                         log (LOG_TIMESTAMP,
                               "Unable to schedule reboot replacement of file %s with %s (Win32 Error %ld)",
-                              cygpath ("/", fn, 0), cygpath ("/", fn, ".new",
-                                                             0),
+                              cygpath ("/", fn.cstr_oneuse(), 0).cstr_oneuse(), cygpath ("/", fn.cstr_oneuse(), ".new", 0).cstr_oneuse(),
                               GetLastError ());
                          ++errors;
                        }
@@ -303,7 +304,7 @@ install_one_source (packagemeta & pkgm, packagesource & source,
 
   progress (0);
 
-  int df = diskfull (get_root_dir ());
+  int df = diskfull (get_root_dir ().cstr_oneuse());
   Progress.SetBar3 (df);
 
   if (lst)
@@ -416,14 +417,13 @@ do_install_thread (HINSTANCE h, HWND owner)
 
   next_dialog = IDD_DESKTOP;
 
-  mkdir_p (1, get_root_dir ());
+  io_stream::mkpath_p (PATH_TO_DIR, get_root_dir ());
 
   for (i = 0; standard_dirs[i]; i++)
     {
-      char *p = cygpath (standard_dirs[i], 0);
-      if (p)
-       mkdir_p (1, p);
-      delete[] p;
+      String p = cygpath (standard_dirs[i], 0);
+      if (p.size())
+       io_stream::mkpath_p (PATH_TO_DIR, p);
     }
 
   /* Create /var/run/utmp */
@@ -435,13 +435,13 @@ do_install_thread (HINSTANCE h, HWND owner)
   total_bytes = 0;
   total_bytes_sofar = 0;
 
-  int df = diskfull (get_root_dir ());
+  int df = diskfull (get_root_dir ().cstr_oneuse());
   Progress.SetBar3 (df);
 
   int istext = (root_text == IDC_ROOT_TEXT) ? 1 : 0;
   int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
 
-  create_mount ("/", get_root_dir (), istext, issystem);
+  create_mount ("/", get_root_dir ().cstr_oneuse(), istext, issystem);
   create_mount ("/usr/bin", cygpath ("/bin", 0), istext, issystem);
   create_mount ("/usr/lib", cygpath ("/lib", 0), istext, issystem);
   set_cygdrive_flags (istext, issystem);
@@ -511,7 +511,8 @@ do_install_thread (HINSTANCE h, HWND owner)
       const char *err = strerror (temperr);
       if (!err)
        err = "(unknown error)";
-      fatal (owner, IDS_ERR_OPEN_WRITE, err);
+      fatal (owner, IDS_ERR_OPEN_WRITE, "Package Database",
+         err);
     }
 
   if (!errors)
index 2e3ab5af21ee689a3c10211bbcb81b92a8938c4d..2d1485d8b5bc25ab21d045e55d7611f90667f4ef 100644 (file)
@@ -33,6 +33,7 @@ static const char *cvsid =
 #include "io_stream_file.h"
 #include "io_stream_cygfile.h"
 #include "mkdir.h"
+#include "String++.h"
 
 /* Static members */
 io_stream *
@@ -51,23 +52,23 @@ io_stream::factory (io_stream * parent)
 }
 
 io_stream *
-io_stream::open (const char *name, const char *mode)
+io_stream::open (String const &name, String const &mode)
 {
-  if (!name || IsBadStringPtr (name, MAX_PATH) || !name[0] ||
-      !mode || IsBadStringPtr (mode, 5) || !mode[0])
+  if (name.size() < 7 ||
+      mode.size() == 0)
     return NULL;
   /* iterate through the known url prefix's */
-  if (!strncasecmp ("file://", name, 7))
+  if (!name.casecompare ("file://", 7))
     {
-      io_stream_file *rv = new io_stream_file (&name[7], mode);
+      io_stream_file *rv = new io_stream_file (&name.cstr_oneuse()[7], mode.cstr_oneuse());
       if (!rv->error ())
        return rv;
       delete rv;
       return NULL;
     }
-  if (!strncasecmp ("cygfile://", name, 10))
+  if (!name.casecompare ("cygfile://", 10))
     {
-      io_stream_cygfile *rv = new io_stream_cygfile (&name[10], mode);
+      io_stream_cygfile *rv = new io_stream_cygfile (&name.cstr_oneuse()[10], mode.cstr_oneuse());
       if (!rv->error ())
        return rv;
       delete rv;
@@ -77,64 +78,62 @@ io_stream::open (const char *name, const char *mode)
 }
 
 int
-io_stream::mkpath_p (path_type_t isadir, const char *name)
+io_stream::mkpath_p (path_type_t isadir, String const &name)
 {
-  if (!name || IsBadStringPtr (name, MAX_PATH) || !name[0])
+  if (name.size() < 7)
     return 1;
   /* iterate through the known url prefix's */
-  if (!strncasecmp ("file://", name, 7))
+  if (!name.casecompare ("file://", 7))
     {
-      return mkdir_p (isadir == PATH_TO_DIR ? 1 : 0, &name[7]);
+      return mkdir_p (isadir == PATH_TO_DIR ? 1 : 0, &name.cstr_oneuse()[7]);
     }
-  if (!strncasecmp ("cygfile://", name, 10))
+  if (!name.casecompare ("cygfile://", 10))
     {
-      return cygmkdir_p (isadir == PATH_TO_DIR ? 1 : 0, &name[10]);
+      return cygmkdir_p (isadir, &name.cstr_oneuse()[10]);
     }
   return 1;
 }
 
 /* remove a file or directory. */
 int
-io_stream::remove (const char *name)
+io_stream::remove (String const &name)
 {
-  if (!name || IsBadStringPtr (name, MAX_PATH) || !name[0])
+  if (!name.size())
     return 1;
   /* iterate through the known url prefix's */
-  if (!strncasecmp ("file://", name, 7))
-    return io_stream_file::remove (&name[7]);
-  if (!strncasecmp ("cygfile://", name, 10))
-    return io_stream_cygfile::remove (&name[10]);
+  if (!name.casecompare ("file://", 7))
+    return io_stream_file::remove (&name.cstr_oneuse()[7]);
+  if (!name.casecompare ("cygfile://", 10))
+    return io_stream_cygfile::remove (&name.cstr_oneuse()[10]);
   return 1;
 }
 
 int
-io_stream::mklink (const char *from, const char *to,
+io_stream::mklink (String const &from, String const &to,
                   io_stream_link_t linktype)
 {
-  log (LOG_BABBLE, "io_stream::mklink (%s->%s)", from, to);
-  if (!from || IsBadStringPtr (from, MAX_PATH) ||
-      !to || IsBadStringPtr (to, MAX_PATH))
+  log (LOG_BABBLE, String("io_stream::mklink (") + from + "->" + to + ")");
+  if (!from.size() || !to.size())
     {
-      log (LOG_TIMESTAMP,
-          "invalid string in from or to parameters to mklink");
+      log (LOG_TIMESTAMP, "invalid string in from or to parameters to mklink");
       return 1;
     }
   /* iterate through the known url prefixes */
-  if (!strncasecmp ("file://", from, 7))
+  if (!from.casecompare ("file://", 7))
     {
       /* file urls can symlink or hardlink to file url's. */
       /* TODO: allow linking to cygfile url's */
-      if (!strncasecmp ("file://", to, 7))
-       return io_stream_file::mklink (&from[7], &to[7], linktype);
+      if (!to.casecompare ("file://", 7))
+       return io_stream_file::mklink (&from.cstr_oneuse()[7], &to.cstr_oneuse()[7], linktype);
       log (LOG_TIMESTAMP, "Attempt to link across url providers");
       return 1;
     }
-  if (!strncasecmp ("cygfile://", from, 10))
+  if (!from.casecompare ("cygfile://", 10))
     {
       /* cygfile urls can symlink or hardlink to cygfile urls's. */
       /* TODO: allow -> file urls */
-      if (!strncasecmp ("cygfile://", to, 10))
-       return io_stream_cygfile::mklink (&from[10], &to[10], linktype);
+      if (!to.casecompare ("cygfile://", 10))
+       return io_stream_cygfile::mklink (&from.cstr_oneuse()[10], &to.cstr_oneuse()[10], linktype);
       log (LOG_TIMESTAMP, "Attempt to link across url providers");
       return 1;
     }
@@ -144,19 +143,19 @@ io_stream::mklink (const char *from, const char *to,
       /* http urls can symlink to http or ftp url's */
     }
 #endif
-  log (LOG_TIMESTAMP, "Unsupported url providers for %s", from);
+  log (LOG_TIMESTAMP, String ("Unsupported url providers for ") + from);
   return 1;
 }
 
 int
-io_stream::move_copy (const char *from, const char *to)
+io_stream::move_copy (String const &from, String const &to)
 {
   /* parameters are ok - checked before calling us, and we are private */
   io_stream *in = io_stream::open (to, "wb");
   io_stream *out = io_stream::open (from, "rb");
   if (io_stream::copy (in, out))
     {
-      log (LOG_TIMESTAMP, "Failed copy of %s to %s", from, to);
+      log (LOG_TIMESTAMP, String("Failed copy of ") + from + " to "+ to);
       delete out;
       io_stream::remove (to);
       delete in;
@@ -190,6 +189,7 @@ ssize_t io_stream::copy (io_stream * in, io_stream * out)
          return countout ? countout : -1;
        }
     }
+  // XXX FIXME: What if countin < 0? return an error
 
   /* TODO:
      out->set_mtime (in->get_mtime ());
@@ -198,28 +198,27 @@ ssize_t io_stream::copy (io_stream * in, io_stream * out)
 }
 
 int
-io_stream::move (const char *from, const char *to)
+io_stream::move (String const &from, String const &to)
 {
-  if (!from || IsBadStringPtr (from, MAX_PATH) ||
-      !to || IsBadStringPtr (to, MAX_PATH))
+  if (!from.size() || !to.size())
     {
       log (LOG_TIMESTAMP, "invalid string in from or to parameters to move");
       return 1;
     }
   /* iterate through the known url prefixes */
-  if (!strncasecmp ("file://", from, 7))
+  if (!from.casecompare ("file://", 7))
     {
       /* TODO: allow 'move' to cygfile url's */
-      if (strncasecmp ("file://", to, 7))
+      if (to.casecompare ("file://", 7))
        return io_stream::move_copy (from, to);
-      return io_stream_file::move (&from[7], &to[7]);
+      return io_stream_file::move (&from.cstr_oneuse()[7], &to.cstr_oneuse()[7]);
     }
-  if (!strncasecmp ("cygfile://", from, 10))
+  if (!from.casecompare ("cygfile://", 10))
     {
       /* TODO: allow -> file urls */
-      if (strncasecmp ("cygfile://", to, 10))
+      if (to.casecompare ("cygfile://", 10))
        return io_stream::move_copy (from, to);
-      return io_stream_cygfile::move (&from[10], &to[10]);
+      return io_stream_cygfile::move (&from.cstr_oneuse()[10], &to.cstr_oneuse()[10]);
     }
 #if 0
   if (!strmcasecmp ("http://", from, 7))
@@ -227,7 +226,7 @@ io_stream::move (const char *from, const char *to)
       /* http urls can symlink to http or ftp url's */
     }
 #endif
-  log (LOG_TIMESTAMP, "Unsupported url providers for %s", from);
+  log (LOG_TIMESTAMP, "Unsupported url providers for %s", from.cstr_oneuse());
   return 1;
 }
 
@@ -256,15 +255,15 @@ io_stream::gets (char *buffer, size_t length)
 }
 
 int
-io_stream::exists (const char *name)
+io_stream::exists (String const &name)
 {
-  if (!name || IsBadStringPtr (name, MAX_PATH) || !name[0])
+  if (!name.size())
     return 1;
   /* iterate through the known url prefix's */
-  if (!strncasecmp ("file://", name, 7))
-    return io_stream_file::exists (&name[7]);
-  if (!strncasecmp ("cygfile://", name, 10))
-    return io_stream_cygfile::exists (&name[10]);
+  if (!name.casecompare ("file://", 7))
+    return io_stream_file::exists (&name.cstr_oneuse()[7]);
+  if (!name.casecompare ("cygfile://", 10))
+    return io_stream_cygfile::exists (&name.cstr_oneuse()[10]);
   return 1;
 }
 
index f909a156588ede86475f2f9c8c42616255b1c9f5..c7d5da9792418c9d2f190bcd9c470d57a7bfdb9b 100644 (file)
@@ -22,6 +22,9 @@
  * case.
  */
 
+#include <stdio.h>
+#include "String++.h"
+
 /* Some things don't fit cleanly just - TODO
  * make mkdir_p fit in the hierarchy
  */
@@ -91,20 +94,20 @@ public:
    * will return non-NULL. To access the files within the archive use io_stream::factory
    * to create a new stream that will read from the archive.
    */
-  static io_stream *open (const char *, const char *);
-  static int remove (const char *);
-  static int exists (const char *);
+  static io_stream *open (String const &, String const &);
+  static int remove (String const &);
+  static int exists (String const &);
   /* moves physical stream source to dest. A copy will be attempted if a 
    * pointer flip fails.
    */
-  static int move (char const *, char const *);
+  static int move (String const &, String const &);
   /* ensure that we have access to the entire path */
   /* Create a directory, and any needed parent directories.
    * returns 1 on failure.
    */
-  static int mkpath_p (path_type_t, const char *);
+  static int mkpath_p (path_type_t, String const &);
   /* link from, to, type. Returns 1 on failure */
-  static int mklink (const char *, const char *, io_stream_link_t);
+  static int mklink (String const &, String const &, io_stream_link_t);
   /* copy from stream to stream - 0 on success */
   static ssize_t copy (io_stream *, io_stream *);
   /* TODO: we may need two versions of each of these:
@@ -150,7 +153,10 @@ public:
    */
 //  virtual const char* next_file_name() = NULL;
   /* if you are still needing these hints... give up now! */
-    virtual ~ io_stream () = 0;
+  virtual ~ io_stream () = 0;
+
+  io_stream& operator << (io_stream&);
+  
 protected:
   void operator= (const io_stream &);
     io_stream () : destroyed (0)
@@ -159,7 +165,7 @@ protected:
   io_stream (const io_stream &);
   unsigned int destroyed;
 private:
-  static int move_copy (char const *, char const *);
+  static int move_copy (String const &, String const &);
 };
 
 #endif /* _IO_STREAM_H_ */
index d7ccd682ef48716b9e3b07592307d4b02bc34c3a..8e47da91eafd6f94ff85966fa1faa783b5a1b9df 100644 (file)
@@ -41,42 +41,34 @@ static const char *cvsid =
 static void
 get_root_dir_now ()
 {
-  if (get_root_dir ())
+  if (get_root_dir ().size())
     return;
   read_mounts ();
 }
 
-io_stream_cygfile::io_stream_cygfile (const char *name, const char *mode)
+io_stream_cygfile::io_stream_cygfile (String const &name, String const &mode) : fp(), fname()
 {
-  fname = NULL;
-  fp = NULL;
   errno = 0;
-  if (!name || IsBadStringPtr (name, MAX_PATH) || !name[0] ||
-      !mode || IsBadStringPtr (mode, 5) || !mode[0])
+  if (!name.size() || !mode.size())
     return;
 
   /* do this every time because the mount points may change due to fwd/back button use...
    * TODO: make this less...manual
    */
   get_root_dir_now ();
-  if (!get_root_dir ())
+  if (!get_root_dir ().size())
     /* TODO: assign a errno for "no mount table :} " */
     return;
 
-  fname = cygpath (name, 0);
-  lmode = new char[strlen(mode) + 1];
-  strcpy (lmode,mode);
-  fp = fopen (fname, mode);
+  fname = cygpath (name.cstr_oneuse(), 0);
+  lmode = mode;
+  fp = fopen (fname.cstr_oneuse(), mode.cstr_oneuse());
   if (!fp)
     lasterr = errno;
 }
 
 io_stream_cygfile::~io_stream_cygfile ()
 {
-  if (lmode)
-    delete[] lmode;
-  if (fname)
-    delete[] fname;
   if (fp)
     fclose (fp);
   destroyed = 1;
@@ -84,97 +76,83 @@ io_stream_cygfile::~io_stream_cygfile ()
 
 /* Static members */
 int
-io_stream_cygfile::exists (const char *path)
+io_stream_cygfile::exists (String const &path)
 {
   get_root_dir_now ();
-  if (get_root_dir () && _access (cygpath (path, 0), 0) == 0)
+  if (get_root_dir ().size() && _access (cygpath (path.cstr_oneuse(), 0).cstr_oneuse(), 0) == 0)
     return 1;
   return 0;
 }
 
 int
-io_stream_cygfile::remove (const char *path)
+io_stream_cygfile::remove (String const &path)
 {
-  if (!path)
+  if (!path.size())
     return 1;
   get_root_dir_now ();
-  if (!get_root_dir ())
+  if (!get_root_dir ().size())
     /* TODO: assign a errno for "no mount table :} " */
     return 1;
 
-  unsigned long w = GetFileAttributes (cygpath (path, 0));
+  unsigned long w = GetFileAttributes (cygpath (path.cstr_oneuse(),0).cstr_oneuse());
   if (w != 0xffffffff && w & FILE_ATTRIBUTE_DIRECTORY)
     {
-      char *tmp = new char [strlen (cygpath (path, 0)) + 10];
+      char tmp[cygpath (path.cstr_oneuse(),0).size() + 10];
       int i = 0;
       do
        {
-         i++;
-         sprintf (tmp, "%s.old-%d", cygpath (path, 0), i);
+         ++i;
+         sprintf (tmp, "%s.old-%d", cygpath (path.cstr_oneuse(),0).cstr_oneuse(), i);
        }
       while (GetFileAttributes (tmp) != 0xffffffff);
       fprintf (stderr, "warning: moving directory \"%s\" out of the way.\n",
-              path);
-      MoveFile (cygpath (path, 0), tmp);
-      delete[] tmp;
+              path.cstr_oneuse());
+      MoveFile (cygpath (path.cstr_oneuse(),0).cstr_oneuse(), tmp);
     }
-  return !DeleteFileA (cygpath (path, 0));
+  return !DeleteFileA (cygpath (path.cstr_oneuse(),0).cstr_oneuse());
 }
 
 int
-io_stream_cygfile::mklink (const char *from, const char *to,
+io_stream_cygfile::mklink (String const &from, String const &to,
                           io_stream_link_t linktype)
 {
-  /* FIXME: badstring check */
-  if (!from || !to)
+  if (!from.size() || !to.size())
     return 1;
   switch (linktype)
     {
     case IO_STREAM_SYMLINK:
-      return mkcygsymlink (cygpath (from, 0), to);
+      return mkcygsymlink (cygpath (from.cstr_oneuse(),0).cstr_oneuse(), to.cstr_oneuse());
     case IO_STREAM_HARDLINK:
       {
        /* For now, just copy */
        /* textmode alert: should we translate when linking from an binmode to a
           text mode mount and vice verca?
         */
-       io_stream *in = io_stream::open (cygpath (to0), "rb");
+       io_stream *in = io_stream::open (cygpath (to.cstr_oneuse(),0), "rb");
        if (!in)
          {
-           log (LOG_TIMESTAMP, "could not open %s for reading in mklink",
-                to);
+           log (LOG_TIMESTAMP, String("could not open ") + to +" for reading in mklink");
            return 1;
          }
-       io_stream *out = io_stream::open (cygpath (from0), "wb");
+       io_stream *out = io_stream::open (cygpath (from.cstr_oneuse(),0), "wb");
        if (!out)
          {
-           log (LOG_TIMESTAMP, "could not open %s for writing in mklink",
-                from);
+           log (LOG_TIMESTAMP, String("could not open ")+ from + " for writing in mklink");
            delete in;
            return 1;
          }
 
-       ssize_t len;
-       char buf[16384];
-       while ((len = in->read (buf, 16384)) > 0)
+       if (io_stream::copy (in, out))
          {
-           ssize_t wrote = out->write (buf, len);
-           if (wrote != len)
-             {
-               log (LOG_TIMESTAMP, "error writing to %s in mklink", from);
-               delete in;
-               delete out;
-               return 1;
-             }
+           log (LOG_TIMESTAMP, String ("Failed to hardlink ")+ from + "->"  +to +
+               " during file copy.");
+           delete in;
+           delete out;
+           return 1;
          }
        delete in;
        delete out;
-       if (len == 0)
-         return 0;
-       log (LOG_TIMESTAMP,
-            "read error reading %s while copying to %s (emulated hardlink)",
-            to, from);
-       return 1;
+       return 0;
       }
     }
   return 1;
@@ -243,21 +221,21 @@ io_stream_cygfile::error ()
 }
 
 int
-cygmkdir_p (int isadir, const char *name)
+cygmkdir_p (enum path_type_t isadir, String const &name)
 {
-  if (!name || IsBadStringPtr (name, MAX_PATH) || !name[0])
+  if (!name.size())
     return 1;
   get_root_dir_now ();
-  if (!get_root_dir ())
+  if (!get_root_dir ().size())
     /* TODO: assign a errno for "no mount table :} " */
     return 1;
-  return mkdir_p (isadir, cygpath (name, 0));
+  return mkdir_p (isadir == PATH_TO_DIR ? 1 : 0, cygpath (name.cstr_oneuse(),0).cstr_oneuse());
 }
 
 int
 io_stream_cygfile::set_mtime (int mtime)
 {
-  if (!fname)
+  if (!fname.size())
     return 1;
   if (fp)
     fclose (fp);
@@ -266,7 +244,7 @@ io_stream_cygfile::set_mtime (int mtime)
   ftime.dwHighDateTime = ftimev >> 32;
   ftime.dwLowDateTime = ftimev;
   HANDLE h =
-    CreateFileA (fname, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
+    CreateFileA (fname.cstr_oneuse(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
                 0, OPEN_EXISTING,
                 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, 0);
   if (h)
@@ -292,22 +270,21 @@ io_stream_cygfile::set_mtime (int mtime)
 }
 
 int
-io_stream_cygfile::move (char const *from, char const *to)
+io_stream_cygfile::move (String const &from, String const &to)
 {
-  if (!from || IsBadStringPtr (from, MAX_PATH) || !from[0] ||
-      !to || IsBadStringPtr (to, MAX_PATH) || !to[0])
+  if (!from.size() || !to.size())
     return 1;
   get_root_dir_now ();
-  if (!get_root_dir ())
+  if (!get_root_dir ().size())
     /* TODO: assign a errno for "no mount table :} " */
     return 1;
-  return rename (cygpath (from, 0), cygpath (to, 0));
+  return rename (cygpath (from.cstr_oneuse(),0).cstr_oneuse(), cygpath (to.cstr_oneuse(),0).cstr_oneuse());
 }
 
 size_t
 io_stream_cygfile::get_size ()
 {
-  if (!fname)
+  if (!fname.size() )
     return 0;
   return get_file_size (fname);
 }
index 587e35e714a8d8479359fa915e5c23a01968bd2b..24a6c512fead5c879fa2d5846778c5858bbbdb94 100644 (file)
 #ifndef _IO_STREAM_CYGFILE_H_
 #define _IO_STREAM_CYGFILE_H_
 
+#include "io_stream.h"
+#include "String++.h"
 
 /* io_stream on disk files using cygwin paths
  * and potentially understanding links in the future
  */
 
-extern int cygmkdir_p (int isadir, const char *path);
+extern int cygmkdir_p (enum path_type_t isadir, String const &path);
 
 class io_stream_cygfile:public io_stream
 {
 public:
-  static int exists (const char *);
-  static int remove (const char *);
-  static int mklink (const char *, const char *, io_stream_link_t);
-    io_stream_cygfile (const char *, const char *);
+  static int exists (String const &);
+  static int remove (String const &);
+  static int mklink (String const &, String const &, io_stream_link_t);
+    io_stream_cygfile (String const &, String const &);
     virtual ~ io_stream_cygfile ();
   /* read data (duh!) */
   virtual ssize_t read (void *buffer, size_t len);
@@ -49,11 +51,11 @@ public:
   };
   virtual size_t get_size ();
   /* dummy for io_stream_file */
-  virtual const char *next_file_name ()
+  virtual String next_file_name ()
   {
     return NULL;
   };
-  static int move (char const *, char const *);
+  static int move (String const &,String const &);
 private:
   /* always require parameters */
   io_stream_cygfile ()
@@ -61,8 +63,8 @@ private:
   };
   FILE *fp;
   int lasterr;
-  char *fname;
-  char *lmode;
+  String fname;
+  String lmode;
 };
 
 #endif /* _IO_STREAM_CYGFILE_H_ */
index 344aba26ca039368922f913e8ec468e53c74a90a..11244c382f82c67d3a505127a588f8ebb4dec1c5 100644 (file)
@@ -36,79 +36,68 @@ static const char *cvsid =
 #define FACTOR (0x19db1ded53ea710LL)
 #define NSPERSEC 10000000LL
 
-io_stream_file::io_stream_file (const char *name, const char *mode)
+io_stream_file::io_stream_file (String const &name, String const &mode):
+fp(), fname(name),lmode (mode)
 {
-  fname = NULL;
-  fp = NULL;
   errno = 0;
-  if (!name || IsBadStringPtr (name, MAX_PATH) || !name[0] ||
-      !mode || IsBadStringPtr (mode, 5) || !mode[0])
+  if (!name.size() || !mode.size())
     return;
-  lmode = new char[strlen(mode) + 1];
-  strcpy (lmode,mode);
-  fname = new char[strlen(name) + 1];
-  strcpy (fname,name);
-  fp = fopen (name, mode);
+  fp = fopen (name.cstr_oneuse(), mode.cstr_oneuse());
   if (!fp)
     lasterr = errno;
 }
 
 io_stream_file::~io_stream_file ()
 {
-  if (fname)
-    delete[] fname;
-  if (lmode)
-    delete[] lmode;
   if (fp)
     fclose (fp);
   destroyed = 1;
 }
 
 int
-io_stream_file::exists (const char *path)
+io_stream_file::exists (String const &path)
 {
-  if (_access (path, 0) == 0)
+  if (_access (path.cstr_oneuse(), 0) == 0)
     return 1;
   return 0;
 }
 
 int
-io_stream_file::remove (const char *path)
+io_stream_file::remove (String const &path)
 {
-  if (!path)
+  if (!path.size())
     return 1;
 
-  unsigned long w = GetFileAttributes (path);
+  unsigned long w = GetFileAttributes (path.cstr_oneuse());
   if (w != 0xffffffff && w & FILE_ATTRIBUTE_DIRECTORY)
     {
-      char *tmp = new char [strlen (path) + 10];
+      char *tmp = new char [path.size() + 10];
       int i = 0;
       do
        {
          i++;
-         sprintf (tmp, "%s.old-%d", path, i);
+         sprintf (tmp, "%s.old-%d", path.cstr_oneuse(), i);
        }
       while (GetFileAttributes (tmp) != 0xffffffff);
       fprintf (stderr, "warning: moving directory \"%s\" out of the way.\n",
-              path);
-      MoveFile (path, tmp);
+              path.cstr_oneuse());
+      MoveFile (path.cstr_oneuse(), tmp);
       delete[] tmp;
     }
-  return !DeleteFileA (path);
+  return !DeleteFileA (path.cstr_oneuse());
 
 }
 
 int
-io_stream_file::mklink (const char *from, const char *to,
+io_stream_file::mklink (String const &from, String const &to,
                        io_stream_link_t linktype)
 {
-  /* FIXME: badstring check */
-  if (!from || !to)
+  if (!from.size() || !to.size())
     return 1;
   switch (linktype)
     {
     case IO_STREAM_SYMLINK:
-      return mkcygsymlink (from, to);
+      return mkcygsymlink (from.cstr_oneuse(), to.cstr_oneuse());
     case IO_STREAM_HARDLINK:
       return 1;
     }
@@ -180,7 +169,7 @@ io_stream_file::error ()
 int
 io_stream_file::set_mtime (int mtime)
 {
-  if (!fname)
+  if (!fname.size())
     return 1;
   if (fp)
     fclose (fp);
@@ -189,7 +178,7 @@ io_stream_file::set_mtime (int mtime)
   ftime.dwHighDateTime = ftimev >> 32;
   ftime.dwLowDateTime = ftimev;
   HANDLE h =
-    CreateFileA (fname, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
+    CreateFileA (fname.cstr_oneuse(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
                 0, OPEN_EXISTING,
                 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, 0);
   if (h)
@@ -202,18 +191,17 @@ io_stream_file::set_mtime (int mtime)
 }
 
 int
-io_stream_file::move (char const *from, char const *to)
+io_stream_file::move (String const &from, String const &to)
 {
-  if (!from || IsBadStringPtr (from, MAX_PATH) || !from[0] ||
-      !to || IsBadStringPtr (to, MAX_PATH) || !to[0])
+  if (!from.size()|| !to.size())
     return 1;
-  return rename (from, to);
+  return rename (from.cstr_oneuse(), to.cstr_oneuse());
 }
 
 size_t
 io_stream_file::get_size ()
 {
-  if (!fname)
+  if (!fname.size())
     return 0;
   return get_file_size (fname);
 }
index afce55355b25649c2bf6cbebbded3546b072513d..de42059dd3cd063d101641d2c4bdf9ffa8f2ea68 100644 (file)
@@ -16,6 +16,8 @@
 #ifndef _IO_STREAM_FILE_H_
 #define _IO_STREAM_FILE_H_
 
+#include "io_stream.h"
+#include "String++.h"
 
 /* io_stream on disk files
  */
 class io_stream_file:public io_stream
 {
 public:
-  static int exists (const char *);
-  static int remove (const char *);
-  static int mklink (const char *, const char *, io_stream_link_t);
-    io_stream_file (const char *, const char *);
+  static int exists (String const &);
+  static int remove (String const &);
+  static int mklink (String const &, String const &, io_stream_link_t);
+    io_stream_file (String const &,String const &);
     virtual ~ io_stream_file ();
   /* read data (duh!) */
   virtual ssize_t read (void *buffer, size_t len);
@@ -46,11 +48,11 @@ public:
   };
   virtual size_t get_size ();
   /* dummy for io_stream_file */
-  virtual const char *next_file_name ()
+  virtual String next_file_name ()
   {
     return NULL;
   };
-  static int move (char const *, char const *);
+  static int move (String const &,String const &);
 private:
   /* always require parameters */
   io_stream_file ()
@@ -58,8 +60,8 @@ private:
   };
   FILE *fp;
   int lasterr;
-  char *fname;
-  char *lmode;
+  String fname;
+  String lmode;
 };
 
 #endif /* _IO_STREAM_FILE_H_ */
index 2c2a9ef56795482e9083692f6b80e4882242e75f..96fbd289de962374dce440b247037a12c09c20e7 100644 (file)
@@ -36,7 +36,6 @@ static const char *cvsid =
 #include "mount.h"
 #include "concat.h"
 #include "log.h"
-#include "mkdir.h"
 #include "io_stream.h"
 
 #include "localdir.h"
@@ -47,10 +46,10 @@ extern ThreeBarProgressPage Progress;
 void
 save_local_dir ()
 {
-  mkdir_p (1, local_dir);
+  io_stream::mkpath_p (PATH_TO_DIR, local_dir);
 
   io_stream *f;
-  if (get_root_dir ())
+  if (get_root_dir ().size())
     {
       f = io_stream::open ("cygfile:///etc/setup/last-cache", "wb");
       io_stream::remove ("file://last-cache");
@@ -59,9 +58,7 @@ save_local_dir ()
     f = io_stream::open ("file://last-cache", "wb");
   if (f)
     {
-      char temp[1000];
-      sprintf (temp, "%s", local_dir);
-      f->write (temp, strlen (temp));
+      f->write (local_dir.cstr_oneuse(), local_dir.size());
       delete f;
     }
 }
@@ -69,7 +66,7 @@ save_local_dir ()
 static void
 check_if_enable_next (HWND h)
 {
-  EnableWindow (GetDlgItem (h, IDOK), local_dir != 0);
+  EnableWindow (GetDlgItem (h, IDOK), local_dir.size() != 0);
 }
 
 static void
@@ -82,7 +79,7 @@ load_dialog (HWND h)
 static void
 save_dialog (HWND h)
 {
-  local_dir = eget (h, IDC_LOCAL_DIR, local_dir);
+  local_dir = egetString (h, IDC_LOCAL_DIR);
 }
 
 
@@ -92,8 +89,8 @@ browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data)
   switch (msg)
     {
     case BFFM_INITIALIZED:
-      if (local_dir)
-       SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM) local_dir);
+      if (local_dir.size())
+       SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM) local_dir.cstr_oneuse());
       break;
     }
   return 0;
@@ -159,12 +156,7 @@ LocalDirPage::OnInit ()
          char *fg_ret = f->gets (localdir, 1000);
          delete f;
          if (fg_ret)
-           {
-             delete [] local_dir;
-             local_dir = new char [strlen(localdir) +1];
-             local_dir[strlen(localdir)] = '\0';
-             strcpy (local_dir, localdir);
-           }
+           local_dir = String (localdir);
        }
       inited = 1;
     }
@@ -183,8 +175,8 @@ LocalDirPage::OnNext ()
 
   save_dialog (h);
   save_local_dir ();
-  log (0, "Selected local directory: %s", local_dir);
-  if (SetCurrentDirectoryA (local_dir))
+  log (LOG_TIMESTAMP, "Selected local directory: %s", local_dir.cstr_oneuse());
+  if (SetCurrentDirectoryA (local_dir.cstr_oneuse()))
     {
       if (source == IDC_SOURCE_CWD)
        {
@@ -198,7 +190,7 @@ LocalDirPage::OnNext ()
        }
     }
   else
-    note (h, IDS_ERR_CHDIR, local_dir);
+    note (h, IDS_ERR_CHDIR, local_dir.cstr_oneuse());
 
   return 0;
 }
diff --git a/log.cc b/log.cc
index dc7294be5808fe6c28f542eafdaed14827b9486c..a3b2f8170ba4b30b69c8f3e5c4c29e052067fa7d 100644 (file)
--- a/log.cc
+++ b/log.cc
@@ -35,58 +35,66 @@ static const char *cvsid =
 #include "mkdir.h"
 #include "mount.h"
 
+#include "io_stream.h"
+
 struct LogEnt
 {
   LogEnt *next;
-  int flags;
+  enum log_level level;
   time_t when;
-  char msg[1];
+  String msg;
 };
 
 static LogEnt *first_logent = 0;
 static LogEnt **next_logent = &first_logent;
 
-void
-log (int flags, const char *fmt, ...)
+void 
+log (enum log_level level, String const &message)
 {
-  char buf[1000];
-  va_list args;
-  va_start (args, fmt);
-  vsprintf (buf, fmt, args);
-
-  LogEnt *l = (LogEnt *) malloc (sizeof (LogEnt) + strlen (buf) + 20);
+  LogEnt *l = new LogEnt;
   l->next = 0;
-  l->flags = flags;
+  l->level = level;
   time (&(l->when));
   *next_logent = l;
   next_logent = &(l->next);
+  l->msg = message;
 
-  char *b = l->msg;
-  if (flags & LOG_TIMESTAMP)
+  char b[100];
+  b[0]='\0';
+  if (level == LOG_TIMESTAMP)
     {
       struct tm *tm = localtime (&(l->when));
       strftime (b, 1000, "%Y/%m/%d %H:%M:%S ", tm);
-      b += strlen (b);
     }
+  l->msg = String (b) + message;
 
-  strcpy (b, buf);
-  msg ("LOG: %d %s", l->flags, l->msg);
+  msg ("LOG: %d %s", l->level, l->msg.cstr_oneuse());
+}
+
+void
+log (enum log_level level, const char *fmt, ...)
+{
+  char buf[1000];
+  va_list args;
+  va_start (args, fmt);
+  vsprintf (buf, fmt, args);
+  log (level, String(buf));
 }
 
 void
-log_save (int babble, const char *filename, int append)
+log_save (int babble, String const &filename, int append)
 {
   static int been_here = 0;
   if (been_here)
     return;
   been_here = 1;
 
-  mkdir_p (0, filename);
+  io_stream::mkpath_p (PATH_TO_FILE, filename);
 
-  FILE *f = fopen (filename, append ? "at" : "wt");
+  io_stream *f = io_stream::open(String("file://")+filename, append ? "at" : "wt");
   if (!f)
     {
-      fatal (NULL, IDS_NOLOGFILE, filename);
+      fatal (NULL, IDS_NOLOGFILE, filename.cstr_oneuse());
       return;
     }
 
@@ -94,15 +102,16 @@ log_save (int babble, const char *filename, int append)
 
   for (l = first_logent; l; l = l->next)
     {
-      if (babble || !(l->flags & LOG_BABBLE))
+      if (babble || !(l->level == LOG_BABBLE))
        {
-         fputs (l->msg, f);
-         if (l->msg[strlen (l->msg) - 1] != '\n')
-           fputc ('\n', f);
+         char *tstr = l->msg.cstr();
+         f->write (tstr, strlen (tstr));
+         if (tstr[strlen (tstr) - 1] != '\n')
+           f->write ("'\n", 1);
        }
     }
 
-  fclose (f);
+  delete f;
   been_here = 0;
 }
 
@@ -119,15 +128,15 @@ exit_setup (int exit_code)
 
   log (LOG_TIMESTAMP, "Ending cygwin install");
 
-  if (source == IDC_SOURCE_DOWNLOAD || !get_root_dir ())
+  if (source == IDC_SOURCE_DOWNLOAD || !get_root_dir ().size())
     {
-      log_save (LOG_BABBLE, concat (local_dir, "/setup.log.full", 0), 0);
-      log_save (0, concat (local_dir, "/setup.log", 0), 1);
+      log_save (LOG_BABBLE, local_dir + "/setup.log.full", 0);
+      log_save (0, local_dir + "/setup.log", 1);
     }
   else
     {
-      log_save (LOG_BABBLE, cygpath ("/setup.log.full", 0), 0);
-      log_save (0, cygpath ("/setup.log", 0), 1);
+      log_save (LOG_BABBLE, cygpath ("/var/log/setup.log.full", 0), 0);
+      log_save (0, cygpath ("/var/log/setup.log", 0), 1);
     }
 
   ExitProcess (exit_code);
diff --git a/log.h b/log.h
index a17e7221d5ec67f1faab88eecb18537080b429fb..24709f2f585c642c152dc9e1a24c18a73c7dcd04 100644 (file)
--- a/log.h
+++ b/log.h
    until they're written out.  "babble" means the message is just idle
    babbling; it can be ignored for shorter logs. */
 
-#define LOG_BABBLE     1
-#define LOG_TIMESTAMP  2
+#include "String++.h"
 
-void log (int flags, const char *fmt, ...)
+enum log_level {
+  LOG_BABBLE = 1,
+  LOG_TIMESTAMP        = 2
+};
+
+void log (enum log_level level, const char *fmt, ...)
   __attribute__ ((format (printf, 2, 3)));
+void log (enum log_level level, String const &);
 
 /* Here, "babble" means to write out the babble also.  If "append" is
    nonzero, the log is appended to any existing file. */
 
-void log_save (int babble, const char *filename, int append);
+void log_save (int writebabble, String const &filename, int append);
 
 /* This is the only legal way to exit.  It writes out all the logs and things */
 
diff --git a/main.cc b/main.cc
index ac1cfba893c774b0d127505cee7850bf5cf49837..ea0be757c71ccbbd06741cbf1fb9afb6a65b4849 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -162,10 +162,8 @@ WinMain (HINSTANCE h,
 
   char cwd[_MAX_PATH];
   GetCurrentDirectory (sizeof (cwd), cwd);
-  local_dir = new char [strlen (cwd) + 1];
-  local_dir [strlen (cwd)] = '\0';
-  strcpy (local_dir, cwd);
-  log (0, "Current Directory: %s", cwd);
+  local_dir = String (cwd);
+  log (LOG_TIMESTAMP, "Current Directory: %s", cwd);
 
   char **argv;
   int argc;
index fbd05faaf88e95fb014e6ea48ce7c97ab82a7388..b71b22ae8d357eae8cf4d84c80cb0396b667db36 100644 (file)
--- a/mklink2.c
+++ b/mklink2.c
@@ -12,7 +12,7 @@ static const char *cvsid =
 doesn't work. */
 
 void
-make_link_2 (char *exepath, char *args, char *icon, char *lname)
+make_link_2 (char const *exepath, char const *args, char const *icon, char const *lname)
 {
   IShellLink *sl;
   IPersistFile *pf;
index 589021f7be4f462c0c6db7ed5e6f302b1bff4760..8414d8bab1858a1dc0c39a9bbd02a7807c400cba 100644 (file)
--- a/mklink2.h
+++ b/mklink2.h
@@ -6,7 +6,7 @@ doesn't work. */
 extern "C"
 {
 #endif
-  void make_link_2 (char *exepath, char *args, char *icon, char *lname);
+  void make_link_2 (char const *exepath, char const *args, char const *icon, char const *lname);
 
   int mkcygsymlink (const char *from, const char *to);
 
index 0fcb3c4406568f8b94a560b01abe8621c88569f3..79096a5561c4f33a44882a7d6ba91d586776d40b 100644 (file)
--- a/mount.cc
+++ b/mount.cc
@@ -18,8 +18,7 @@
    changes, this is the file to change to match it. */
 
 #if 0
-static const char *cvsid =
-  "\n%%% $Id$\n";
+static const char *cvsid = "\n%%% $Id$\n";
 #endif
 
 #include "win32.h"
@@ -36,54 +35,56 @@ static const char *cvsid =
 #include "state.h"
 #include "concat.h"
 
+#include "String++.h"
+
 static struct mnt
 {
-  const char *native;
-  char *posix;
+  String native;
+  String posix;
   int istext;
 }
 mount_table[255];
 
 struct mnt *root_here = NULL;
 
-static char *
-find2 (HKEY rkey, int *istext, char *what)
+static String
+find2 (HKEY rkey, int *istext, String const &what)
 {
-  char *retval = 0;
-  DWORD retvallen = 0;
-  DWORD flags = 0;
-  DWORD type;
   HKEY key;
 
-  if (RegOpenKeyEx (rkey, what, 0, KEY_READ, &key) != ERROR_SUCCESS)
+  if (RegOpenKeyEx (rkey, what.cstr_oneuse (), 0, KEY_READ, &key) !=
+      ERROR_SUCCESS)
     return 0;
 
+  DWORD retvallen = 0;
+  DWORD type;
+
+  String Sretval;
   if (RegQueryValueEx (key, "native", 0, &type, 0, &retvallen)
       == ERROR_SUCCESS)
     {
-      retval = new char [MAX_PATH + 1];
+      char retval[retvallen];
       if (RegQueryValueEx
          (key, "native", 0, &type, (BYTE *) retval,
-          &retvallen) != ERROR_SUCCESS)
-       {
-         delete[] retval;
-         retval = 0;
-       }
+          &retvallen) == ERROR_SUCCESS)
+       Sretval = String (retval);
     }
 
+  DWORD flags = 0;
   retvallen = sizeof (flags);
   RegQueryValueEx (key, "flags", 0, &type, (BYTE *) & flags, &retvallen);
 
   RegCloseKey (key);
 
-  if (retval)
+  if (Sretval.size ())
     *istext = (flags & MOUNT_BINARY) ? 0 : 1;
 
-  return retval;
+  return Sretval;
 }
 
 void
-create_mount (const char *posix, const char *win32, int istext, int issystem)
+create_mount (String const posix, String const win32, int istext,
+             int issystem)
 {
   char buf[1000];
   HKEY key;
@@ -95,15 +96,15 @@ create_mount (const char *posix, const char *win32, int istext, int issystem)
   sprintf (buf, "Software\\%s\\%s\\%s\\%s",
           CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
           CYGWIN_INFO_CYGWIN_REGISTRY_NAME,
-          CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, posix);
+          CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, posix.cstr_oneuse ());
 
   HKEY kr = issystem ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
-  if (RegCreateKeyEx (kr, buf, 0, (char *) "Cygwin", 0, KEY_ALL_ACCESS,
+  if (RegCreateKeyEx (kr, 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);
+  RegSetValueEx (key, "native", 0, REG_SZ, (BYTE *) win32.cstr_oneuse (),
+                win32.size () + 1);
   flags = 0;
   if (!istext)
     flags |= MOUNT_BINARY;
@@ -117,20 +118,20 @@ create_mount (const char *posix, const char *win32, int istext, int issystem)
 }
 
 static void
-remove1 (HKEY rkey, const char *posix)
+remove1 (HKEY rkey, String const 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);
+          CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, posix.cstr_oneuse ());
 
   RegDeleteKey (rkey, buf);
 }
 
 void
-remove_mount (const char *posix)
+remove_mount (String const posix)
 {
   remove1 (HKEY_LOCAL_MACHINE, posix);
   remove1 (HKEY_CURRENT_USER, posix);
@@ -228,7 +229,7 @@ static int
 in_table (struct mnt *m)
 {
   for (struct mnt * m1 = mount_table; m1 < m; m1++)
-    if (strcasecmp (m1->posix, m->posix) == 0)
+    if (m1->posix.casecompare (m->posix) == 0)
       return 1;
   return 0;
 }
@@ -304,12 +305,10 @@ read_mounts ()
   char buf[10000];
 
   root_here = NULL;
-  for (mnt * m1 = mount_table; m1->posix; m1++)
+  for (mnt * m1 = mount_table; m1->posix.size (); m1++)
     {
-      delete[] m1->posix;
-      if (m1->native)
-       delete[] m1->native;
-      m1->posix = NULL;
+      m1->posix = String ();   //empty string;
+      m1->native = String ();
     }
 
   /* Loop through subkeys */
@@ -324,37 +323,37 @@ read_mounts ()
               CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME);
 
       HKEY key = issystem ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
-      if (RegCreateKeyEx (key, buf, 0, (char *) "Cygwin", 0, KEY_ALL_ACCESS,
+      if (RegCreateKeyEx (key, buf, 0, "Cygwin", 0, KEY_ALL_ACCESS,
                          0, &key, &disposition) != ERROR_SUCCESS)
        break;
       for (int i = 0;; i++, m++)
        {
-         m->posix = new char [MAX_PATH + 1];
+         char aBuffer[MAX_PATH + 1];
          posix_path_size = MAX_PATH;
          /* FIXME: if maximum posix_path_size is 256, we're going to
             run into problems if we ever try to store a mount point that's
             over 256 but is under MAX_PATH. */
-         res = RegEnumKeyEx (key, i, m->posix, &posix_path_size, NULL,
+         res = RegEnumKeyEx (key, i, aBuffer, &posix_path_size, NULL,
                              NULL, NULL, NULL);
 
          if (res == ERROR_NO_MORE_ITEMS)
            {
-             delete[] m->posix;
-             m->posix = NULL;
+             m->posix = String ();
              break;
            }
+         m->posix = String (aBuffer);
 
-         if (!*m->posix || in_table (m))
+         if (!m->posix.size () || in_table (m))
            goto no_go;
          else if (res != ERROR_SUCCESS)
            break;
          else
            {
              m->native = find2 (key, &m->istext, m->posix);
-             if (!m->native)
+             if (!m->native.size ())
                goto no_go;
 
-             if (strcmp (m->posix, "/") == 0)
+             if (m->posix == "/")
                {
                  root_here = m;
                  if (m->istext)
@@ -369,9 +368,8 @@ read_mounts ()
            }
          continue;
        no_go:
-         delete[] m->posix;
-         m->posix = NULL;
-         m--;
+         m->posix = String ();
+         --m;
        }
       RegCloseKey (key);
     }
@@ -379,34 +377,32 @@ read_mounts ()
   if (!root_here)
     {
       root_here = m;
-      m->posix = new char [2];
-      strcpy (m->posix, "/");
+      m->posix = String ("/");
       char windir[_MAX_PATH];
       root_text = IDC_ROOT_BINARY;
       root_scope = (is_admin ())? IDC_ROOT_SYSTEM : IDC_ROOT_USER;
       GetWindowsDirectory (windir, sizeof (windir));
       windir[2] = 0;
-      set_root_dir (concat (windir, "\\cygwin", 0));
+      set_root_dir (String (windir) + "\\cygwin");
       m++;
     }
 }
 
 void
-set_root_dir (const char *val)
+set_root_dir (String const val)
 {
   root_here->native = val;
 }
 
-const char *
+String const
 get_root_dir ()
 {
-  return root_here ? root_here->native : NULL;
+  return root_here ? root_here->native : String ();
 }
 
 /* Return non-zero if PATH1 is a prefix of PATH2.
    Both are assumed to be of the same path style and / vs \ usage.
    Neither may be "".
-   LEN1 = strlen (PATH1).  It's passed because often it's already known.
 
    Examples:
    /foo/ is a prefix of /foo  <-- may seem odd, but desired
@@ -418,39 +414,33 @@ get_root_dir ()
 */
 
 static int
-path_prefix_p (const char *path1, const char *path2, int len1)
+path_prefix_p (String const path1, String const path2)
 {
+  size_t len1 = path1.size ();
   /* Handle case where PATH1 has trailing '/' and when it doesn't.  */
-  if (len1 > 0 && SLASH_P (path1[len1 - 1]))
-    len1--;
+  if (len1 > 0 && SLASH_P (path1.cstr_oneuse ()[len1 - 1]))
+    --len1;
 
   if (len1 == 0)
-    return SLASH_P (path2[0]) && !SLASH_P (path2[1]);
+    return SLASH_P (path2.cstr_oneuse ()[0])
+      && !SLASH_P (path2.cstr_oneuse ()[1]);
 
-  if (strncasecmp (path1, path2, len1) != 0)
+  if (path1.casecompare (path2, len1) != 0)
     return 0;
 
-  return SLASH_P (path2[len1]) || path2[len1] == 0 || path1[len1 - 1] == ':';
+  return SLASH_P (path2.cstr_oneuse ()[len1]) || path2.size () == len1
+    || path1.cstr_oneuse ()[len1 - 1] == ':';
 }
 
-char *
-cygpath (const char *s, ...)
+static String
+cygpath (String const &thePath)
 {
-  va_list v;
-  int max_len = -1;
+  size_t max_len = 0;
   struct mnt *m, *match = NULL;
-
-  va_start (v, s);
-  char *path = vconcat (s, v);
-  if (strncmp (path, "./", 2) == 0)
-    memmove (path, path + 2, strlen (path + 2) + 1);
-  if (strncmp (path, "/./", 3) == 0)
-    memmove (path + 1, path + 3, strlen (path + 3) + 1);
-
-  for (m = mount_table; m->posix; m++)
+  for (m = mount_table; m->posix.size (); m++)
     {
-      int n = strlen (m->posix);
-      if (n < max_len || !path_prefix_p (m->posix, path, n))
+      size_t n = m->posix.size ();
+      if (n <= max_len || !path_prefix_p (m->posix, thePath))
        continue;
       max_len = n;
       match = m;
@@ -459,14 +449,29 @@ cygpath (const char *s, ...)
   if (!match)
     return NULL;
 
-  char *native;
-  if (max_len == (int) strlen (path))
-  {
-    native = new char [strlen (match->native) + 1];
-    strcpy (native, match->native);
-  }
+  String native;
+  if (max_len == thePath.size ())
+    {
+      native = match->native;
+    }
   else
-    native = concat (match->native, "/", path + max_len, NULL);
-  delete[] path;
+    native = match->native + "/" + String (thePath.cstr_oneuse () + max_len);
   return native;
 }
+
+String
+cygpath (const char *s, ...)
+{
+  va_list v;
+
+  va_start (v, s);
+  char *path = vconcat (s, v);
+  if (strncmp (path, "./", 2) == 0)
+    memmove (path, path + 2, strlen (path + 2) + 1);
+  if (strncmp (path, "/./", 3) == 0)
+    memmove (path + 1, path + 3, strlen (path + 3) + 1);
+
+  String thePath (path);
+  delete[]path;
+  return cygpath (thePath);
+}
diff --git a/mount.h b/mount.h
index 8a791cd7c8db64fc3b05c18e747b5ff1fc93085b..1fe3f2b54120738d570b2b6f608137a29b4af052 100644 (file)
--- a/mount.h
+++ b/mount.h
    nonzero if the existing mount is a text mount, else zero for
    binary. */
 
+#include "String++.h"
+
 char *find_mount (int *istext, int *issystem, char *path);
 
 /* Similar to the mount and umount functions, but simplified */
 
-void create_mount (const char *posix, const char *win32, int istext,
+void create_mount (String const posix, String const win32, int istext,
                   int issystem);
-void remove_mount (const char *posix);
+void remove_mount (String const posix);
 void read_mounts ();
 
 /* Sets the cygdrive flags.  Used to make the automounted drives' binary/text
 mode consistent with the standard Cygwin mounts. */
 
 void set_cygdrive_flags (int istext, int issystem);
-char *cygpath (const char *s, ...);
-void set_root_dir (const char *);
-const char *get_root_dir ();
+String cygpath (const char *s, ...);
+void set_root_dir (String const);
+String const get_root_dir ();
diff --git a/msg.cc b/msg.cc
index 24b45e52ff548a4515a54d4f2064ee8353f656ce..1320e75f726c3a2fa17f55135283a887f92c21ee 100644 (file)
--- a/msg.cc
+++ b/msg.cc
@@ -46,7 +46,7 @@ mbox (HWND owner, const char *name, int type, int id, va_list args)
     ExitProcess (0);
 
   vsprintf (buf, fmt, args);
-  log (0, "mbox %s: %s", name, buf);
+  log (LOG_TIMESTAMP, "mbox %s: %s", name, buf);
   return MessageBox (owner, buf, "Cygwin Setup", type);
 }
 
diff --git a/net.cc b/net.cc
index 96aaa877134224e5f8a123c9e451fb46fb1dbb2d..81815a51a8d5f0459bb43ffc7b7be12ac071bc23 100644 (file)
--- a/net.cc
+++ b/net.cc
@@ -113,7 +113,7 @@ NetPage::OnNext ()
 {
   save_dialog (GetHWND ());
 
-  log (0, "net: %s",
+  log (LOG_TIMESTAMP, "net: %s",
        (net_method == IDC_NET_IE5) ? "IE5" :
        (net_method == IDC_NET_DIRECT) ? "Direct" : "Proxy");
 
index 56e65aed4e298f1186cc1a1777b9827c0a20622f..f0f4658191e1e49e6be65d34f617decaf77cb426 100644 (file)
@@ -125,6 +125,7 @@ packagedb::flush ()
 
   io_stream *ndb = io_stream::open (ndbn, "wb");
 
+  // XXX if this failed, try removing any existing .new database?
   if (!ndb)
     return errno ? errno : 1;
 
@@ -141,9 +142,9 @@ packagedb::flush ()
           * also note that we are writing a fictional install source 
           * to keep cygcheck happy.               
           */
-         sprintf (line, "%s %s %d\n", pkgm.name,
-                  concat (pkgm.name, "-",
-                          pkgm.installed->Canonical_version (),
+         sprintf (line, "%s %s %d\n", pkgm.name.cstr_oneuse(),
+                  concat (pkgm.name.cstr_oneuse(), "-",
+                          pkgm.installed->Canonical_version ().cstr_oneuse(),
                           ".tar.bz2", 0), 0);
          ndb->write (line, strlen (line));
        }
@@ -161,11 +162,11 @@ packagedb::flush ()
 int
   packagedb::installeddbread =
   0;
-list < packagemeta, char const *,
-  strcasecmp >
+list < packagemeta, String,
+  String::casecompare >
   packagedb::packages;
-list < Category, char const *,
-  strcasecmp >
+list < Category, String,
+  String::casecompare >
   packagedb::categories;
 PackageDBActions
   packagedb::task =
index a966a76d34dbcd8b085f216a20f00e4f619c2923..6ab2043bd62325bb093bdee3a808ab0f625aaa53 100644 (file)
@@ -18,8 +18,7 @@
 
 /* required to parse this file */
 #include "list.h"
-#include <string.h>
-//class CategoryList;
+#include <String++.h>
 class Category;
 class packagemeta;
 class io_stream;
@@ -37,9 +36,9 @@ public:
   /* 0 on success */
   int flush ();
   /* all seen packages */
-  static list < packagemeta, char const *, strcasecmp > packages;
+  static list < packagemeta, String, String::casecompare > packages;
   /* all seen categories */
-  static list < Category, char const *, strcasecmp > categories;
+  static list < Category, String, String::casecompare > categories;
   static PackageDBActions task;
 private:
   static int installeddbread;  /* do we have to reread this */
index 7d8475beffe8022c77a346c9bde12bd5d9e6f77d..65d0773eb6379b18323df789643e021e65297c52 100644 (file)
@@ -63,11 +63,10 @@ static const char *standard_dirs[] = {
 };
 
 void
-hash::add_subdirs (char const *tpath)
+hash::add_subdirs (String const &tpath)
 {
   char *nonp, *pp;
-  char *path = new char[strlen (tpath) + 1];
-  strcpy (path, tpath);
+  char *path = tpath.cstr();
   for (nonp = path; *nonp == '\\' || *nonp == '/'; nonp++);
   for (pp = path + strlen (path) - 1; pp > nonp; pp--)
     if (*pp == '/' || *pp == '\\')
@@ -152,31 +151,31 @@ packagemeta::uninstall ()
        * but for now: here is ok
        */
       hash dirs;
-      const char *line = installed->getfirstfile ();
+      String line = installed->getfirstfile ();
 
       try_run_script ("/etc/preremove/", name);
-      while (line)
+      while (line.size())
        {
          dirs.add_subdirs (line);
 
-         char *d = cygpath ("/", line, NULL);
-         DWORD dw = GetFileAttributes (d);
+         String d = cygpath ("/", line.cstr_oneuse(),0);
+         DWORD dw = GetFileAttributes (d.cstr_oneuse());
          if (dw != INVALID_FILE_ATTRIBUTES
              && !(dw & FILE_ATTRIBUTE_DIRECTORY))
            {
-             log (LOG_BABBLE, "unlink %s", d);
-             SetFileAttributes (d, dw & ~FILE_ATTRIBUTE_READONLY);
-             DeleteFile (d);
+             log (LOG_BABBLE, String("unlink ")+ d);
+             SetFileAttributes (d.cstr_oneuse(), dw & ~FILE_ATTRIBUTE_READONLY);
+             DeleteFile (d.cstr_oneuse());
            }
          /* Check for Windows shortcut of same name. */
-         d = concat (d, ".lnk", NULL);
-         dw = GetFileAttributes (d);
+         d += ".lnk";
+         dw = GetFileAttributes (d.cstr_oneuse());
          if (dw != INVALID_FILE_ATTRIBUTES
              && !(dw & FILE_ATTRIBUTE_DIRECTORY))
            {
-             log (LOG_BABBLE, "unlink %s", d);
-             SetFileAttributes (d, dw & ~FILE_ATTRIBUTE_READONLY);
-             DeleteFile (d);
+             log (LOG_BABBLE, String("unlink ") + d);
+             SetFileAttributes (d.cstr_oneuse(), dw & ~FILE_ATTRIBUTE_READONLY);
+             DeleteFile (d.cstr_oneuse());
            }
          line = installed->getnextfile ();
        }
@@ -186,9 +185,9 @@ packagemeta::uninstall ()
       char *subdir = 0;
       while ((subdir = dirs.enumerate (subdir)) != 0)
        {
-         char *d = cygpath ("/", subdir, NULL);
-         if (RemoveDirectory (d))
-           log (LOG_BABBLE, "rmdir %s", d);
+         String d = cygpath ("/", subdir,0);
+         if (RemoveDirectory (d.cstr_oneuse()))
+           log (LOG_BABBLE, String("rmdir ")+ d);
        }
       try_run_script ("/etc/postremove/", name);
     }
@@ -204,17 +203,17 @@ packagemeta::add_category (Category & cat)
   catpack.pkg = this;
 }
 
-char const *
+String const
 packagemeta::SDesc () const
 {
   for (size_t n = 1; n <= versions.number (); ++n)
-    if (versions[n]->SDesc ())
+    if (versions[n]->SDesc ().size())
       return versions[n]->SDesc ();
   return NULL;
 };
 
 /* Return an appropriate caption given the current action. */
-char const *
+String 
 packagemeta::action_caption ()
 {
   if (!desired && installed)
index 88ef2dfe1e7f05ee8e8f37698be939155096d1ff..a64d11444e27020231deb552e2df68b92b92a6b9 100644 (file)
@@ -33,7 +33,7 @@ class category;
 
 /* Required to parse this completely */
 #include "list.h"
-#include "strings.h"
+#include "String++.h"
 #include "category.h"
 
 /* 
@@ -56,36 +56,26 @@ public:
 class packagemeta
 {
 public:
-  packagemeta (char const *pkgname):installed_from (0),
+  packagemeta (String const &pkgname):name (pkgname), key(pkgname), installed_from (0),
     //versions (0),
 //    versioncount (0), versionspace (0), 
   installed (0), prev (0), prevtimestamp (0), curr (0), currtimestamp (0),
     exp (0), exptimestamp (0), desired (0)
   {
-    name = new char[strlen (pkgname) + 1];
-      strcpy (name, pkgname);
-    key = name;
-  };
+  }
 
-  packagemeta (char const *pkgname,
-              char const *installedfrom):installed_from (0),
+  packagemeta (String const &pkgname,
+              String const &installedfrom):name (pkgname), key(pkgname),
+              installed_from (installedfrom),
     //versions (0),    versioncount (0), versionspace (0), 
    
     installed (0), prev (0), prevtimestamp (0), curr (0), currtimestamp (0),
     exp (0), exptimestamp (0), desired (0)
   {
-    name = new char[strlen (pkgname) + 1];
-    key = name;
-    strcpy (name, pkgname);
-    installed_from = new char[strlen (installedfrom) + 1];
-    strcpy (installed_from, installedfrom);
   };
 
   ~packagemeta ()
   {
-    delete[] name;
-    if (installed_from)
-      delete[] installed_from;
   };
 
   void add_version (packageversion &);
@@ -116,7 +106,7 @@ public:
   void uninstall ();
   int set_requirements (trusts deftrust = TRUST_CURR, size_t depth = 0);
 
-  char const *action_caption ();
+  String action_caption ();
   packageversion * trustp (trusts const t) const
   {
     return t == TRUST_PREV ? (prev ? prev : (curr ? curr : installed))
@@ -124,20 +114,20 @@ public:
         : exp;
   }
 
-  char *name;                  /* package name, like "cygwin" */
-  char *key;
+  String name;                 /* package name, like "cygwin" */
+  String key;
   /* legacy variable used to output data for installed.db versions <= 2 */
-  char *installed_from;
+  String installed_from;
   /* SDesc is global in theory, across all package versions. 
      LDesc is not: it can be different per version */
-  char const *SDesc () const;
+  String const SDesc () const;
   /* what categories does this package belong in. Note that if multiple versions
    * of a package disagree.... the first one read in will take precedence.
    */
   void add_category (Category &);
   list < CategoryPackage, Category &, Categorycmp > Categories;
 
-  list < packageversion, char const *, strcasecmp > versions;
+  list < packageversion, String, String::casecompare > versions;
   /* which one is installed. */
   packageversion *installed;
   /* which one is listed as "prev" in our available packages db */
index 0c2967f834b424cb5ab38d16e0f172854aeaeb61..5dc0392bd2640cb08b1594a409d1fc0c9b9088f4 100644 (file)
@@ -26,10 +26,8 @@ static const char *cvsid =
 #include <strings.h>
 #include "package_source.h"
 
-site::site (char const *newkey)
+site::site (String const &newkey) : key(newkey)
 {
-  key = new char[strlen (newkey) + 1];
-  strcpy (key, newkey);
 };
   
 void
@@ -71,16 +69,11 @@ packagesource::set_canonical (char const *fn)
   memcpy (filename, bstart + 1, end - bstart - 1);
   filename[end - bstart - 1] = '\0';
 
-  if (cached)
-    delete[] cached;
-  cached = 0;
+  cached = String();
 }
 
 void
-packagesource::set_cached (char const *fp)
+packagesource::set_cached (String const &fp)
 {
-  if (cached)
-    delete[] cached;
-  cached = new char[strlen (fp) + 1];
-  strcpy (cached, fp);
+  cached = fp;
 }
index 4f85011743c5de8fef1995e7fbda6a091bc81a54..108d9ccc4424ce59a4499a9d883f6a1c37888938 100644 (file)
@@ -23,6 +23,7 @@
 /* required to parse this file */
 #include "list.h"
 #include "strings.h"
+#include "String++.h"
 
 /* standard binary package metadata:
  * Name (ie mutt
 class site
 {
 public:
-  site (char const *newkey);
+  site (String const &newkey);
   ~site ()
   {
-    if (key)
-      delete[] key;
   };
-  char *key;
+  String key;
 };
 
 class packagesource
 {
 public:
-  packagesource ():size (0), canonical (0), base (0), filename (0), cached (0)
+  packagesource ():size (0), canonical (0), base (0), filename (0), cached ()
   {
   };
   /* how big is the source file */
@@ -84,12 +83,12 @@ public:
   /* what is the cached filename, to prevent directory scanning during install */
   virtual char const *Cached ()
   {
-    return cached;
+    return cached.cstr_oneuse();
   };
   /* sets the canonical path, and parses and creates base and filename */
   virtual void set_canonical (char const *);
-  virtual void set_cached (char const *);
-  list < site, char const *, strcasecmp > sites;
+  virtual void set_cached (String const &);
+  list < site, String, String::casecompare > sites;
 
   virtual ~ packagesource ()
   {
@@ -99,15 +98,13 @@ public:
       delete []base;
     if (filename)
       delete []filename;
-    if (cached)
-      delete []cached;
   };
 
 private:
   char *canonical;
   char *base;
   char *filename;
-  char *cached;
+  String cached;
 };
 
 #endif /* _PACKAGE_SOURCE_H_ */
index 3a305999892a4e6e855e8b9ce0a74b930c21f213..b2cb1288a868cf6a04b0962eaf35fb374ec330a6 100644 (file)
@@ -42,12 +42,15 @@ class Dependency;
 
 /* Required for parsing */
 #include "package_source.h"
+#include "String++.h"
 
 class Dependency
 {
 public:
+  Dependency (String const &aPackage) : package (aPackage) {}
+  Dependency (Dependency const &);
   Dependency * next;           /* the next package in this dependency list */
-  char const *package;         /* the name of the package that is depended on */
+  String const package;                /* the name of the package that is depended on */
 }
  ;                             /* Dependencies can be used for
                                   recommended/required/related... */
@@ -79,36 +82,34 @@ class packageversion
 {
 public:
   /* for list inserts/mgmt. */
-  const char *key;
+  String key;
   /* name is needed here, because if we are querying a file, the data may be embedded in
      the file */
-  virtual const char *Name () = 0;
-  virtual const char *Vendor_version () = 0;
-  virtual const char *Package_version () = 0;
-  virtual const char *Canonical_version () = 0;
+  virtual String const Name () = 0;
+  virtual String const Vendor_version () = 0;
+  virtual String const Package_version () = 0;
+  virtual String const Canonical_version () = 0;
   virtual package_status_t Status () = 0;
 //  virtual package_stability_t Stability () = 0;
   virtual package_type_t Type () = 0;
   /* TODO: we should probably return a metaclass - file name & path & size & type
      - ie doc/script/binary
    */
-  virtual const char *getfirstfile () = 0;
-  virtual const char *getnextfile () = 0;
-  virtual char const *SDesc () = 0;
-  virtual void set_sdesc (char const *) = 0;
-  virtual char const *LDesc () = 0;
-  virtual void set_ldesc (char const *) = 0;
+  virtual String const getfirstfile () = 0;
+  virtual String const getnextfile () = 0;
+  virtual String const SDesc () = 0;
+  virtual void set_sdesc (String const &) = 0;
+  virtual String const LDesc () = 0;
+  virtual void set_ldesc (String const &) = 0;
   /* FIXME: review this - these are UI variables, should be consistent across all
    * children package types
    */
-  void new_requirement (char const *dependson)
+  void new_requirement (String const &dependson)
   {
-    Dependency *dp;
-    if (!dependson)
+    if (!dependson.size())
         return;
-      dp = new Dependency;
+    Dependency *dp = new Dependency (dependson);
       dp->next = required;
-      dp->package = dependson;
       required = dp;
   }
   Dependency *required;
index 4b67db1f68287e030b565ce38f41eca738775902..cca43c5d669e4fe15a6cd97c7c27c8b5ab7bb8e8 100644 (file)
@@ -42,6 +42,6 @@ do_postinstall (HINSTANCE h, HWND owner)
 {
   next_dialog = 0;
   init_run_script ();
-  SetCurrentDirectory (get_root_dir ());
+  SetCurrentDirectory (get_root_dir ().cstr_oneuse());
   find (cygpath ("/etc/postinstall", 0), run_script_in_etc_postinstall);
 }
diff --git a/res.rc b/res.rc
index 0e9e94e1d43be68ae99e8459d1fdf53d0224dc27..c02e12cf62fc7cd74f7adaa60d4d846867e71b87 100644 (file)
--- a/res.rc
+++ b/res.rc
@@ -59,7 +59,7 @@ BEGIN
     ICON            IDI_CYGWIN,IDC_STATIC,290,0,21,20
     CONTROL         "",IDC_STATIC,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
                     317,1
-    LTEXT           "Select a directory where you want Setup to store the installation files it dowmloads.  The directory will be created if it does not already exist.",
+    LTEXT           "Select a directory where you want Setup to store the installation files it downloads.  The directory will be created if it does not already exist.",
                     IDC_STATIC,21,9,248,16,NOT WS_GROUP
     LTEXT           "Select Local Package Directory",IDC_STATIC_HEADER_TITLE,
                     7,0,258,8,NOT WS_GROUP
index babefb55fd96551f14a8611473a91b56da7e4a06..7aef86527243b840dbf1e46cd39abd6390745808 100644 (file)
@@ -181,6 +181,12 @@ rfc1738_escape_part (const char *url)
 {
   return rfc1738_do_escape (url, 1);
 }
+String
+rfc1738_escape_part (String const &url)
+{
+  char const *t = rfc1738_do_escape (url.cstr_oneuse(), 1);
+  return String (t);
+}
 
 /*
  *  rfc1738_unescape() - Converts escaped characters (%xy numbers) in 
index 8d3670e2b41c103445957315de790ed3ecc62a92..181f0ff1711cac6b1f8dc7afbc624553c2b92c51 100644 (file)
--- a/rfc1738.h
+++ b/rfc1738.h
@@ -35,6 +35,8 @@
 #ifndef _RFC1738_H_
 #define _RFC1738_H_
 
+#include "String++.h"
 char const *rfc1738_escape_part (char const *);
+String rfc1738_escape_part (String const &);
 
 #endif
diff --git a/root.cc b/root.cc
index 87e5be599a77bc036bb1698276acffc24ede9efb..bc1a23bdd09d09601986afcee3a1eed47e316883 100644 (file)
--- a/root.cc
+++ b/root.cc
@@ -33,7 +33,6 @@ static const char *cvsid =
 #include "state.h"
 #include "msg.h"
 #include "mount.h"
-#include "concat.h"
 #include "log.h"
 #include "root.h"
 
@@ -43,7 +42,7 @@ static int su[] = { IDC_ROOT_SYSTEM, IDC_ROOT_USER, 0 };
 static void
 check_if_enable_next (HWND h)
 {
-  EnableWindow (GetDlgItem (h, IDOK), root_text && get_root_dir ()
+  EnableWindow (GetDlgItem (h, IDOK), root_text && get_root_dir ().size()
                && root_scope);
 }
 
@@ -61,7 +60,7 @@ save_dialog (HWND h)
 {
   root_text = rbget (h, rb);
   root_scope = rbget (h, su);
-  set_root_dir (eget (h, IDC_ROOT_DIR, (char *) get_root_dir ()));
+  set_root_dir (egetString (h, IDC_ROOT_DIR));
 }
 
 static int CALLBACK
@@ -70,8 +69,8 @@ browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data)
   switch (msg)
     {
     case BFFM_INITIALIZED:
-      if (get_root_dir ())
-       SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM) get_root_dir ());
+      if (get_root_dir ().size())
+       SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM) get_root_dir ().cstr_oneuse());
       break;
     }
   return 0;
@@ -102,26 +101,34 @@ browse (HWND h)
 static int
 directory_is_absolute ()
 {
-  const char *r = get_root_dir ();
+  
+  const char *r = get_root_dir ().cstr();
   if (isalpha (r[0]) && r[1] == ':' && (r[2] == '\\' || r[2] == '/'))
-    return 1;
+    {
+      delete [] r;
+      return 1;
+    }
+  delete[]r;
   return 0;
 }
 
 static int
 directory_is_rootdir ()
 {
+  char *t=get_root_dir ().cstr();
   const char *c;
-  for (c = get_root_dir (); *c; c++)
+  for (c = t; *c; c++)
     if (isslash (c[0]) && c[1] && !isslash (c[1]))
-      return 0;
+    {delete[]t;
+      return 0;}
+      delete[]t;
   return 1;
 }
 
 static int
 directory_has_spaces ()
 {
-  if (strchr (get_root_dir (), ' '))
+  if (get_root_dir ().find(' '))
     return 1;
   return 0;
 }
@@ -157,7 +164,7 @@ RootPage::Create ()
 void
 RootPage::OnInit ()
 {
-  if (!get_root_dir ())
+  if (!get_root_dir ().size())
     read_mounts ();
   load_dialog (GetHWND ());
 }
@@ -181,9 +188,9 @@ RootPage::OnNext ()
 
   NEXT (IDD_LOCAL_DIR);
 
-  log (0, "root: %s %s %s", get_root_dir (),
-       (root_text == IDC_ROOT_TEXT) ? "text" : "binary",
-       (root_scope == IDC_ROOT_USER) ? "user" : "system");
+  log (LOG_TIMESTAMP, String ("root: ") + get_root_dir () + 
+       (root_text == IDC_ROOT_TEXT ? " text" : " binary")  +
+       (root_scope == IDC_ROOT_USER ? " user" : " system"));
 
   return 0;
 }
index a1ae4f6c1477cd57c0df99b3aac8c321b6e7808c..9c13507c9b49223d56b863e632d143a3d4b9a900 100644 (file)
--- a/script.cc
+++ b/script.cc
@@ -28,10 +28,11 @@ static const char *cvsid =
 #include <stdio.h>
 #include "log.h"
 #include "concat.h"
+#include "filemanip.h"
 #include "mount.h"
 #include "io_stream.h"
 
-static char *sh = 0;
+static String sh = String();
 static const char *cmd = 0;
 static OSVERSIONINFO verinfo;
 
@@ -48,21 +49,20 @@ init_run_script ()
 {
   for (int i = 0; shells[i]; i++)
     {
-      sh = backslash (cygpath (shells[i], 0));
-      if (_access (sh, 0) == 0)
+      sh = backslash (cygpath (shells[i],0).cstr_oneuse());
+      if (_access (sh.cstr_oneuse(), 0) == 0)
        break;
-      delete[] sh;
-      sh = 0;
+      sh = String();
     }
   
   char old_path[_MAX_PATH];
   GetEnvironmentVariable ("PATH", old_path, sizeof (old_path));
   SetEnvironmentVariable ("PATH",
                          backslash (cygpath ("/bin;",
-                                             get_root_dir (), "/usr/bin;",
-                                             old_path, 0)));
+                                             get_root_dir ().cstr_oneuse(), "/usr/bin;",
+                                             old_path, 0)).cstr_oneuse());
 
-  SetEnvironmentVariable ("CYGWINROOT", get_root_dir ());
+  SetEnvironmentVariable ("CYGWINROOT", get_root_dir ().cstr_oneuse());
 
   verinfo.dwOSVersionInfoSize = sizeof (verinfo);
   GetVersionEx (&verinfo);
@@ -97,30 +97,30 @@ run (const char *sh, const char *args, const char *file)
   si.dwFlags = STARTF_USEPOSITION;
 
   b = CreateProcess (0, cmdline, 0, 0, 0,
-                    CREATE_NEW_CONSOLE, 0, get_root_dir (), &si, &pi);
+                    CREATE_NEW_CONSOLE, 0, get_root_dir ().cstr_oneuse(), &si, &pi);
 
   if (b)
     WaitForSingleObject (pi.hProcess, INFINITE);
 }
 
 void
-run_script (char const *dir, char const *fname)
+run_script (String const &dir, String const &fname)
 {
-  char *ext = strrchr (fname, '.');
+  char *ext = strrchr (fname.cstr_oneuse(), '.');
   if (!ext)
     return;
 
-  if (sh && strcmp (ext, ".sh") == 0)
+  if (sh.size() && strcmp (ext, ".sh") == 0)
     {
-      char *f2 = concat (dir, fname, 0);
-      log (0, "running: %s -c %s", sh, f2);
-      run (sh, "-c", f2);
+      char *f2 = concat (dir.cstr_oneuse(), fname.cstr_oneuse(), 0);
+      log (LOG_TIMESTAMP, "running: %s -c %s", sh.cstr_oneuse(), f2);
+      run (sh.cstr_oneuse(), "-c", f2);
       delete[] f2;
     }
   else if (cmd && strcmp (ext, ".bat") == 0)
     {
-      char *f2 = backslash (cygpath (dir, fname, 0));
-      log (0, "running: %s /c %s", cmd, f2);
+      char *f2 = backslash (cygpath (dir.cstr_oneuse(), fname.cstr_oneuse(),0)).cstr();
+      log (LOG_TIMESTAMP, "running: %s /c %s", cmd, f2);
       run (cmd, "/c", f2);
       delete[] f2;
     }
@@ -128,18 +128,18 @@ run_script (char const *dir, char const *fname)
     return;
 
   /* if file exists then delete it otherwise just ignore no file error */
-  io_stream::remove (concat ("cygfile://", dir, fname, ".done", 0));
+  io_stream::remove (String ("cygfile://") + dir+ fname+ ".done");
 
-  io_stream::move (concat ("cygfile://", dir, fname, 0),
-                  concat ("cygfile://", dir, fname, ".done", 0));
+  io_stream::move (String ("cygfile://")+ dir+ fname,
+                  String ("cygfile://")+ dir+ fname+ ".done");
 }
 
 void
-try_run_script (char const *dir, char const *fname)
+try_run_script (String const &dir, String const &fname)
 {
-  if (io_stream::exists (concat ("cygfile://", dir, fname, ".sh", 0)))
-    run_script (dir, concat (fname, ".sh", 0));
-  if (io_stream::exists (concat ("cygfile://", dir, fname, ".bat", 0)))
-    run_script (dir, concat (fname, ".bat", 0));
+  if (io_stream::exists (String ("cygfile://")+ dir+ fname+ ".sh"))
+    run_script (dir.cstr_oneuse(), concat (fname.cstr_oneuse(), ".sh", 0));
+  if (io_stream::exists (String ("cygfile://")+ dir+ fname+ ".bat"))
+    run_script (dir.cstr_oneuse(), concat (fname.cstr_oneuse(), ".bat", 0));
 }
 
index 46f64fc73fef531fd4b597eeb3b9f25b6a54dc22..9b1e462d3e067b41a1c2940c3555844f99f89ca0 100644 (file)
--- a/script.h
+++ b/script.h
 #ifndef SCRIPT_H
 #define SCRIPT_H
 
+#include "String++.h"
+
 /* Run the script fname, found in dir.  If fname has suffix .sh, and
    we have a Bourne shell, execute it using sh.  Otherwise, if fname
    has suffix .bat, execute using cmd */
    
-void run_script (char const *dir, char const *fname);
+void run_script (String const &dir, String const &fname);
 
 /* Initialisation stuff for run_script: sh, cmd, CYGWINROOT and PATH */
 void init_run_script ();
 
 /* Run the scripts fname.sh and fname.bat, found in dir. */
-void try_run_script (char const *dir, char const *fname);
+void try_run_script (String const &dir, String const &fname);
 
 #endif /* SCRIPT_H */
diff --git a/site.cc b/site.cc
index 4cbd18aaafa9a5d8b90380e6a3a90f2f9efaf7b3..eede92eb7d4adfa8e1799992d57f42a17a6e8d64 100644 (file)
--- a/site.cc
+++ b/site.cc
@@ -45,31 +45,28 @@ static const char *cvsid =
 #include "threebar.h"
 extern ThreeBarProgressPage Progress;
 
-list < site_list_type, const char *, strcasecmp > site_list;
-list < site_list_type, const char *, strcasecmp > all_site_list;
-
-static char *other_url = 0;
+list < site_list_type, String, String::casecompare > site_list;
+list < site_list_type, String, String::casecompare > all_site_list;
 
 void
-site_list_type::init (char const *newurl)
+site_list_type::init (String const &newurl)
 {
-  url = new char [strlen (newurl) +1];
-  strcpy (url, newurl);
-  displayed_url = new char [strlen (newurl) +1];
-  strcpy (displayed_url, newurl);
-  char *dot = strchr (displayed_url, '.');
-  if (dot)
-    {
-      dot = strchr (dot, '/');
-      if (dot)
-       *dot = 0;
-    }
-  key = new char[2 * strlen (newurl) + 3];
+  url = newurl;
 
-  dot = displayed_url;
-  dot += strlen (dot);
-  char *dp = key;
-  while (dot != displayed_url)
+  char *dots = newurl.cstr();
+  char *dot = strchr (dots, '.');
+  if (dot)
+      {
+         dot = strchr (dot, '/');
+        if (dot)
+               *dot = 0;
+   }
+  displayed_url = String (dots);
+
+  
+  dot = dots + strlen (dots);
+  char *dp = new char[2 * newurl.size() + 3];
+  while (dot != dots)
     {
       if (*dot == '.' || *dot == '/')
        {
@@ -80,13 +77,16 @@ site_list_type::init (char const *newurl)
            *dp++ = *sp++;
          *dp++ = ' ';
        }
-      dot--;
+      --dot;
     }
   *dp++ = ' ';
-  strcpy (dp, displayed_url);
+  strcpy (dp, dots);
+  delete[] dots;
+  key = String (dp);
+  delete[] dp;
 }
 
-site_list_type::site_list_type (char const *newurl)
+site_list_type::site_list_type (String const &newurl)
 {
   init (newurl);
 }
@@ -125,19 +125,12 @@ void
 save_site_url ()
 {
   io_stream *f = io_stream::open ("cygfile:///etc/setup/last-mirror", "wb");
-  for (size_t n = 1; n <= site_list.number (); n++)
+  if (f)
     {
-      if (f)
-       {
-         // FIXME: write all selected sites
-         TCHAR *temp;
-         temp = new TCHAR[sizeof (TCHAR) * (strlen (site_list[n]->url) + 2)];
-         sprintf (temp, "%s\n", site_list[n]->url);
-         f->write (temp, strlen (temp));
-         delete[] temp;
-       }
+      for (size_t n = 1; n <= site_list.number (); n++)
+        f->write ((site_list[n]->url + "\n").cstr_oneuse(), site_list[n]->url.size() + 1);
+      delete f;
     }
-  delete f;
 }
 
 static int
@@ -147,13 +140,14 @@ get_site_list (HINSTANCE h, HWND owner)
 
   if (LoadString (h, IDS_MIRROR_LST, mirror_url, sizeof (mirror_url)) <= 0)
     return 1;
-  char *mirrors = get_url_to_string (mirror_url, owner);
-  if (!mirrors)
+  char *bol, *eol, *nl, *theString;
+  {
+  String mirrors = get_url_to_string (mirror_url, owner);
+  if (!mirrors.size())
     return 1;
 
-  char *bol, *eol, *nl;
+  nl = theString = mirrors.cstr();}
 
-  nl = mirrors;
   while (*nl)
     {
       bol = nl;
@@ -178,7 +172,7 @@ get_site_list (HINSTANCE h, HWND owner)
            delete newsite;
        }
     }
-  delete[] mirrors;
+  delete[] theString;
 
   return 0;
 }
@@ -211,12 +205,8 @@ get_saved_sites ()
       if (eos < site)
        continue;
 
-      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 (!found)
+      String tempKey = site_list_type (String(site)).key;
+      if  (!all_site_list.getbykey (tempKey))
        {
          /* Don't default to certain machines ever since they suffer
             from bandwidth limitations. */
@@ -234,10 +224,10 @@ get_saved_sites ()
       /* 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]);
+      // Was it an allowed URL? 
+      site_list_type *tempSite;
+      if ((tempSite = all_site_list.getbykey (tempKey)))
+       site_list.registerbyobject (*tempSite);
     }
   delete f;
 
@@ -254,9 +244,8 @@ do_download_site_info_thread (void *p)
   hinst = (HINSTANCE) (context[0]);
   h = (HWND) (context[1]);
 
-  if (all_site_list.number () == 0)
-    {
-      if (get_site_list (hinst, h))
+  if (all_site_list.number () == 0
+      && get_site_list (hinst, h))
        {
          // Error: Couldn't download the site info.  Go back to the Net setup page.
          MessageBox (h, TEXT ("Can't get list of download sites.\n\
@@ -266,12 +255,9 @@ Make sure your network settings are corect and try again."), NULL, MB_OK);
          Progress.PostMessage (WM_APP_SITE_INFO_DOWNLOAD_COMPLETE, 0,
                                IDD_NET);
 
-         _endthread ();
        }
-    }
-
+  else
   // Everything worked, go to the site select page
-
   // Tell the progress page that we're done downloading
   Progress.PostMessage (WM_APP_SITE_INFO_DOWNLOAD_COMPLETE, 0, IDD_SITE);
 
@@ -312,7 +298,7 @@ SitePage::OnNext ()
 
   // Log all the selected URLs from the list.    
   for (size_t n = 1; n <= site_list.number (); n++)
-    log (0, "site: %s", site_list[n]->url);
+    log (LOG_TIMESTAMP, "site: %s", site_list[n]->url.cstr_oneuse());
 
   Progress.SetActivateTask (WM_APP_START_SETUP_INI_DOWNLOAD);
   return IDD_INSTATUS;
@@ -337,8 +323,8 @@ SitePage::OnActivate ()
   // Fill the list box with all known sites.
   PopulateListBox ();
 
-  // Load the user URL box with whatever it was last time.
-  eset (GetHWND (), IDC_EDIT_USER_URL, other_url);
+  // Load the user URL box with nothing - it is in the list already.
+  eset (GetHWND (), IDC_EDIT_USER_URL, "");
 
   // Get the enabled/disabled states of the controls set accordingly.
   CheckControlsAndDisableAccordingly ();
@@ -369,7 +355,7 @@ SitePage::PopulateListBox ()
   for (size_t i = 1; i <= all_site_list.number (); i++)
     {
       j = SendMessage (listbox, LB_ADDSTRING, 0,
-                      (LPARAM) all_site_list[i]->displayed_url);
+                      (LPARAM) all_site_list[i]->displayed_url.cstr_oneuse());
       SendMessage (listbox, LB_SETITEMDATA, j, i);
     }
 
@@ -377,7 +363,7 @@ SitePage::PopulateListBox ()
   for (size_t n = 1; n <= site_list.number (); n++)
     {
       int index = SendMessage (listbox, LB_FINDSTRING, (WPARAM) - 1,
-                              (LPARAM) site_list[n]->displayed_url);
+                              (LPARAM) site_list[n]->displayed_url.cstr_oneuse());
       if (index != LB_ERR)
        {
          // Highlight the selected item
@@ -394,11 +380,7 @@ bool SitePage::OnMessageCmd (int id, HWND hwndctl, UINT code)
     {
     case IDC_EDIT_USER_URL:
       {
-       if (code == EN_CHANGE)
-         {
-           // Text in edit box may have changed.
-           other_url = eget (GetHWND (), IDC_EDIT_USER_URL, other_url);
-         }
+       // FIXME: Make Enter here cause an ADD, not a NEXT.
        break;
       }
     case IDC_URL_LIST:
@@ -406,6 +388,7 @@ bool SitePage::OnMessageCmd (int id, HWND hwndctl, UINT code)
        if (code == LBN_SELCHANGE)
          {
            CheckControlsAndDisableAccordingly ();
+           save_dialog (GetHWND ());
          }
        break;
       }
@@ -414,7 +397,9 @@ bool SitePage::OnMessageCmd (int id, HWND hwndctl, UINT code)
        if (code == BN_CLICKED)
          {
            // User pushed the Add button.
-           other_url = eget (GetHWND (), IDC_EDIT_USER_URL, other_url);
+           String other_url = egetString (GetHWND (), IDC_EDIT_USER_URL);
+           if (other_url.size())
+           {
            site_list_type *
              newsite =
              new
@@ -430,7 +415,7 @@ bool SitePage::OnMessageCmd (int id, HWND hwndctl, UINT code)
            else
              {
                // Log the adding of this new URL.
-               log (0, "Adding site: %s", other_url);
+               log (LOG_BABBLE, "Adding site: %s", other_url.cstr_oneuse());
              }
 
            // Assume the user wants to use it and select it for him.
@@ -438,6 +423,8 @@ bool SitePage::OnMessageCmd (int id, HWND hwndctl, UINT code)
 
            // Update the list box.
            PopulateListBox ();
+           eset (GetHWND (), IDC_EDIT_USER_URL, "");
+           }
          }
        break;
       }
diff --git a/site.h b/site.h
index 45d93554c126001afd0abf8ee9eade8e0d257a41..4be7d597c0e744c00ab8503943393adbecb73921 100644 (file)
--- a/site.h
+++ b/site.h
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include "list.h"
+#include "String++.h"
 
 #include "proppage.h"
 
@@ -51,30 +52,22 @@ void do_download_site_info (HINSTANCE h, HWND owner);
 class site_list_type
 {
 public:
-  site_list_type ():url (0), displayed_url (0), key (0)
+  site_list_type ():url (), displayed_url (0), key (0)
   {
   };
-  site_list_type (char const *);
+  site_list_type (String const &);
   /* workaround for missing placement new in gcc 2.95 */
-  void init (char const *);
-  ~site_list_type ()
-  {
-    if (url)
-      delete[] url;
-    if (displayed_url)
-      delete[] displayed_url;
-    if (key)
-      delete[] key;
-  };
-  char *url;
-  char *displayed_url;
-  char *key;
+  void init (String const &);
+  ~site_list_type () {};
+  String url;
+  String displayed_url;
+  String key;
 };
 
 /* user chosen sites */
-extern list < site_list_type, const char *, strcasecmp > site_list;
+extern list < site_list_type, String, String::casecompare > site_list;
 /* potential sites */
-extern list < site_list_type, const char *, strcasecmp > all_site_list;
+extern list < site_list_type, String, String::casecompare > all_site_list;
 
 void save_site_url ();
 
index b443769f166f2e86a0f16de389f47124beed61fa..ef43419629afde7b1791ecbf58663c4424d35c3b 100644 (file)
--- a/source.cc
+++ b/source.cc
@@ -118,7 +118,7 @@ SourcePage::OnBack ()
 void
 SourcePage::OnDeactivate ()
 {
-  log (0, "source: %s",
+  log (LOG_TIMESTAMP, "source: %s",
        (source == IDC_SOURCE_DOWNLOAD) ? "download" :
        (source == IDC_SOURCE_NETINST) ? "network install" : "from cwd");
 }
diff --git a/state.h b/state.h
index a33bc3ac29b87d899551bc7c68cda19b4534b89a..7ee54f62dcc5d5626866b36310d7728356e41786 100644 (file)
--- a/state.h
+++ b/state.h
  
  */
 
+#include "String++.h"
+
 extern int source;
 
-extern char *local_dir;
+extern String local_dir;
 
 extern int root_text;
 extern int root_scope;
@@ -46,4 +48,3 @@ extern char *net_proxy_passwd;
 extern char *net_ftp_user;
 extern char *net_ftp_passwd;
 
-extern int trust_level;
index 5c0ddff9cb5cc05de65a1bd657be91e6faac4f6b..389c0f292db70430c895835cdb1eec7bc659caac 100644 (file)
@@ -26,9 +26,12 @@ static const char *cvsid =
 #include <ctype.h>
 
 #include "port.h"
-char *
-canonicalize_version (const char *v)
+#include "version.h"
+  
+String 
+canonicalize_version (String const &aString)
 {
+  char *v =aString.cstr();
   static char nv[3][100];
   static int idx = 0;
   char *np;
@@ -52,5 +55,6 @@ canonicalize_version (const char *v)
        *np++ = *v++;
     }
   *np++ = 0;
+  delete[] v;
   return nv[idx];
 }
index c9bebe4261c85740fa6149aadfdd42c4fd0e619f..33e7ff4f71f9dd7175a2afccf91895b70ffe6055 100644 (file)
--- a/version.h
+++ b/version.h
@@ -15,6 +15,8 @@
 
 /* misc version-related things */
 
+#include "String++.h"
+
 extern char *version;
 
-extern char *canonicalize_version (const char *);
+extern String canonicalize_version (String const &);
This page took 0.259131 seconds and 5 git commands to generate.