From b24c88b303ce96fe9515efb2a465ad025f334f4f Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Tue, 13 Nov 2001 01:49:32 +0000 Subject: [PATCH] 2001-11-13 Robert Collins * Makefile.in (CFLAGS): Add warnings and -Werr. (WARNONLY_FLAGS): For sources that produce (harmless) errors no matter what. (OBJS): Add io_stream class' objects. (autoload.o): Use WARNONLY_FLAGS. (inilex.o): Ditto. (iniparse.o): Ditto. * archive.cc: New file. * archive.h: New file. * archive_tar.cc: New file. * archive_tar.h: New file. * archive_tar_file.cc: New file. * autoload.c: Fix compiler warnings (unused, deprecated conversion). * choose.cc: Use io_stream.h, not mount.h. Run indent. (find_tar_ext): Rewritten to use strstr, and to accept .tar as an extension. (read_installed_db): Use io_streams. * choose.h: Run indent. * compress.cc: New file. * compress.h: New file. * compress_bz.cc: New file. * compress_bz.h: New file. * compress_gz.cc: New file. * compress_gz.h: New file. * concat.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). * concat.h: Run indent. * desktop.cc: Run indent. Include mklink2.h rather than redefining by hand. (cvsid): Fix compiler warnings (unused, deprecated conversion). (etc_profile): Fix compiler warning (deprecated conversion). (make_link): Fix compiler warning (deprecated conversion). Tidy up use of args variable - consolidate into argbuf. (start_menu): Fix compiler warning (deprecated conversion). (desktop_icon): Fix compiler warning (deprecated conversion). (make_etc_profile): Fix compiler warning (deprecated conversion). (uexists): Fix compiler warning (deprecated conversion). (check_desktop): Fix compiler warning (deprecated conversion). (check_startmenu): Fix compiler warning (deprecated conversion). * dialog.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). (fatal): Fix compiler warning (deprecated conversion). * dialog.h: Run indent. * diskfull.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). * download.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). (download_one): Fix compiler warning (signed vs unsigned comparison). * filemanip.h: Run indent. * find.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). (find): Fix compiler warning (deprecated conversion). * find.h: Run indent. * fromcwd.cc: Run indent. * geturl.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). (dialog_cmd): Return a value. (dialog_proc): Remove unused variables. Return a value. (get_url_to_file): Fix compiler warning (deprecated conversion). * geturl.h: Run indent. * hash.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). * hash.h: Run indent. * ini.cc: Run indent. Use io_streams. (cvsid): Fix compiler warnings (unused, deprecated conversion). (do_ini): Use io_streams for local io. * ini.h: Run indent. * inilex.l (ignore_line): Fix compiler warning (is not a prototype). Fix compiler warning (brackets for truth assignment). * install.cc: Run indent. Fix compiler warning (/* in comment). Use io_streams. (cvsid): Fix compiler warnings (unused, deprecated conversion). (dialog_cmd): Return a value. (dialog_proc): Return a value. (start_tics): Deleted - was unused. (badrename): Fix compiler warnings (unused, deprecated conversion). (standard_dirs): Fix compiler warning (deprecated conversion). (exists): Remove. (uninstall_one): Convert to io_streams. (install_one): Convert to io_streams. (do_install): Convert to io_streans. Fix compiler warning (deprecated conversion). * io_stream.cc: New file. * io_stream.h: New file. * io_stream_cygfile.cc: New file. * io_stream_cygfile.h: New file. * io_stream_file.cc: New file. * io_stream_file.h: New file. * localdir.cc: Run indent. Use io_streams. (cvsid): Fix compiler warnings (unused, deprecated conversion). (get_root_dir_now): Remove. (save_local_dir): Convert to io_streams. (dialog_cmd): Return a value. (do_local_dir): Convert to io_streams. (log.cc): Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). (log): Fix compiler warning (deprecated conversion). (log_save): Fix compiler warning (deprecated conversion). * log.h: Run indent. (log): Fix compiler warning (deprecated conversion). (log_save): Fix compiler warning (deprecated conversion). * main.cc: Run indent. Don't include "netio.h". (cvsid): Fix compiler warnings (unused, deprecated conversion). (netio_test): Remove. (sid_auth): Fix compiler warning (partially bracketed initialiser). (WinMain): Return a value. * mkdir.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). * mklink2.c: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). (mkcygsymlink): New function. * mklink2.h: New file. * mount.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). (create_mount): Remove unused variables. (cygpath): Fix compiler warning (signed vs unsigned comparison). * mount.h: Run indent. * msg.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). (msg): Fix compiler warning (deprecated conversion). (mbox): Fix compiler warning (deprecated conversion). * msg.h: Run indent. (msg): Fix compiler warning (deprecated conversion). * net.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). (dialog_cmd): Return a value. * netio.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). (auth_cmd): Return a value. * netio.h: Run indent. * nio-file.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). (NetIO_File::NetIO_File): Fix compiler warning (deprecated conversion). * nio-file.h: Run indent. * nio-ftp.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). * nio-ftp.h: Run indent. * nio-http.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). * nio-http.h: Run indent. * nio-ie5.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). * nio-ie5.h: Run indent. * other.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). (dialog_cmd): Return a value. * port.h: Run indent. * postinstall.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). (cmd): Fix compiler warning (deprecated conversion). (eun): Fix compiler warning (deprecated conversion). * root.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). * simpsock.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). * simpsock.h: Run indent. * site.cc: Run indent. Use io_streams. (cvsid): Fix compiler warnings (unused, deprecated conversion). (get_root_dir_now): Remove. (save_site_url): Convert to io_streams. (dialog_cmd): Return 0. (get_initial_list_idx): Convert to io_streans. * source.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). (check_if_enable_next): Remove. (load_dialog): Remove unused variables. (save_dialog): Ditto. (dialog_cmd): Return a value. * splash.cc: Return a value. (cvsid): Fix compiler warnings (unused, deprecated conversion). (dialog_cmd): Return a value. * state.cc: Run indent. (cvsid): Fix compiler warnings (unused, deprecated conversion). * state.h: Run indent. * tar.cc: Remove. * tar.h: Remove. --- ChangeLog | 184 +++++++++++++ Makefile.in | 46 +++- archive.cc | 224 ++++++++++++++++ archive.h | 90 +++++++ archive_tar.cc | 309 ++++++++++++++++++++++ archive_tar.h | 164 ++++++++++++ archive_tar_file.cc | 131 +++++++++ autoload.c | 5 +- choose.cc | 50 ++-- choose.h | 81 +++--- compress.cc | 119 +++++++++ compress.h | 55 ++++ compress_bz.cc | 207 +++++++++++++++ compress_bz.h | 72 +++++ compress_gz.cc | 614 +++++++++++++++++++++++++++++++++++++++++++ compress_gz.h | 79 ++++++ concat.cc | 18 +- concat.h | 6 +- desktop.cc | 188 +++++++------ dialog.cc | 22 +- dialog.h | 42 +-- diskfull.cc | 13 +- download.cc | 33 ++- filemanip.h | 5 +- find.cc | 37 +-- find.h | 3 +- fromcwd.cc | 23 +- geturl.cc | 58 ++-- geturl.h | 8 +- hash.cc | 20 +- hash.h | 11 +- ini.cc | 53 ++-- ini.h | 97 +++---- inilex.l | 4 +- install.cc | 206 ++++++++------- io_stream.cc | 193 ++++++++++++++ io_stream.h | 137 ++++++++++ io_stream_cygfile.cc | 270 +++++++++++++++++++ io_stream_cygfile.h | 62 +++++ io_stream_file.cc | 188 +++++++++++++ io_stream_file.h | 59 +++++ localdir.cc | 47 ++-- log.cc | 16 +- log.h | 7 +- main.cc | 92 ++++--- mkdir.cc | 8 +- mklink2.c | 36 ++- mklink2.h | 15 ++ mount.cc | 122 +++++---- mount.h | 9 +- msg.cc | 9 +- msg.h | 2 +- net.cc | 20 +- netio.cc | 17 +- netio.h | 7 +- nio-file.cc | 18 +- nio-file.h | 5 +- nio-ftp.cc | 66 +++-- nio-ftp.h | 7 +- nio-http.cc | 95 ++++--- nio-http.h | 7 +- nio-ie5.cc | 32 ++- nio-ie5.h | 9 +- other.cc | 7 +- port.h | 1 - postinstall.cc | 21 +- root.cc | 12 +- simpsock.cc | 23 +- simpsock.h | 11 +- site.cc | 94 +++---- source.cc | 35 +-- splash.cc | 7 +- state.cc | 5 +- state.h | 36 +-- tar.cc | 567 --------------------------------------- tar.h | 49 ---- 76 files changed, 4262 insertions(+), 1438 deletions(-) create mode 100644 archive.cc create mode 100644 archive.h create mode 100644 archive_tar.cc create mode 100644 archive_tar.h create mode 100644 archive_tar_file.cc create mode 100644 compress.cc create mode 100644 compress.h create mode 100644 compress_bz.cc create mode 100644 compress_bz.h create mode 100644 compress_gz.cc create mode 100644 compress_gz.h create mode 100644 io_stream.cc create mode 100644 io_stream.h create mode 100644 io_stream_cygfile.cc create mode 100644 io_stream_cygfile.h create mode 100644 io_stream_file.cc create mode 100644 io_stream_file.h create mode 100644 mklink2.h delete mode 100644 tar.cc delete mode 100644 tar.h diff --git a/ChangeLog b/ChangeLog index d8717e3d..ce045000 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,187 @@ +2001-11-13 Robert Collins + + * Makefile.in (CFLAGS): Add warnings and -Werr. + (WARNONLY_FLAGS): For sources that produce (harmless) errors no matter what. + (OBJS): Add io_stream class' objects. + (autoload.o): Use WARNONLY_FLAGS. + (inilex.o): Ditto. + (iniparse.o): Ditto. + * archive.cc: New file. + * archive.h: New file. + * archive_tar.cc: New file. + * archive_tar.h: New file. + * archive_tar_file.cc: New file. + * autoload.c: Fix compiler warnings (unused, deprecated conversion). + * choose.cc: Use io_stream.h, not mount.h. + Run indent. + (find_tar_ext): Rewritten to use strstr, and to accept .tar as an extension. + (read_installed_db): Use io_streams. + * choose.h: Run indent. + * compress.cc: New file. + * compress.h: New file. + * compress_bz.cc: New file. + * compress_bz.h: New file. + * compress_gz.cc: New file. + * compress_gz.h: New file. + * concat.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + * concat.h: Run indent. + * desktop.cc: Run indent. + Include mklink2.h rather than redefining by hand. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (etc_profile): Fix compiler warning (deprecated conversion). + (make_link): Fix compiler warning (deprecated conversion). + Tidy up use of args variable - consolidate into argbuf. + (start_menu): Fix compiler warning (deprecated conversion). + (desktop_icon): Fix compiler warning (deprecated conversion). + (make_etc_profile): Fix compiler warning (deprecated conversion). + (uexists): Fix compiler warning (deprecated conversion). + (check_desktop): Fix compiler warning (deprecated conversion). + (check_startmenu): Fix compiler warning (deprecated conversion). + * dialog.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (fatal): Fix compiler warning (deprecated conversion). + * dialog.h: Run indent. + * diskfull.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + * download.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (download_one): Fix compiler warning (signed vs unsigned comparison). + * filemanip.h: Run indent. + * find.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (find): Fix compiler warning (deprecated conversion). + * find.h: Run indent. + * fromcwd.cc: Run indent. + * geturl.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (dialog_cmd): Return a value. + (dialog_proc): Remove unused variables. + Return a value. + (get_url_to_file): Fix compiler warning (deprecated conversion). + * geturl.h: Run indent. + * hash.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + * hash.h: Run indent. + * ini.cc: Run indent. + Use io_streams. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (do_ini): Use io_streams for local io. + * ini.h: Run indent. + * inilex.l (ignore_line): Fix compiler warning (is not a prototype). + Fix compiler warning (brackets for truth assignment). + * install.cc: Run indent. + Fix compiler warning (/* in comment). + Use io_streams. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (dialog_cmd): Return a value. + (dialog_proc): Return a value. + (start_tics): Deleted - was unused. + (badrename): Fix compiler warnings (unused, deprecated conversion). + (standard_dirs): Fix compiler warning (deprecated conversion). + (exists): Remove. + (uninstall_one): Convert to io_streams. + (install_one): Convert to io_streams. + (do_install): Convert to io_streans. + Fix compiler warning (deprecated conversion). + * io_stream.cc: New file. + * io_stream.h: New file. + * io_stream_cygfile.cc: New file. + * io_stream_cygfile.h: New file. + * io_stream_file.cc: New file. + * io_stream_file.h: New file. + * localdir.cc: Run indent. + Use io_streams. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (get_root_dir_now): Remove. + (save_local_dir): Convert to io_streams. + (dialog_cmd): Return a value. + (do_local_dir): Convert to io_streams. + (log.cc): Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (log): Fix compiler warning (deprecated conversion). + (log_save): Fix compiler warning (deprecated conversion). + * log.h: Run indent. + (log): Fix compiler warning (deprecated conversion). + (log_save): Fix compiler warning (deprecated conversion). + * main.cc: Run indent. + Don't include "netio.h". + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (netio_test): Remove. + (sid_auth): Fix compiler warning (partially bracketed initialiser). + (WinMain): Return a value. + * mkdir.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + * mklink2.c: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (mkcygsymlink): New function. + * mklink2.h: New file. + * mount.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (create_mount): Remove unused variables. + (cygpath): Fix compiler warning (signed vs unsigned comparison). + * mount.h: Run indent. + * msg.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (msg): Fix compiler warning (deprecated conversion). + (mbox): Fix compiler warning (deprecated conversion). + * msg.h: Run indent. + (msg): Fix compiler warning (deprecated conversion). + * net.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (dialog_cmd): Return a value. + * netio.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (auth_cmd): Return a value. + * netio.h: Run indent. + * nio-file.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (NetIO_File::NetIO_File): Fix compiler warning (deprecated conversion). + * nio-file.h: Run indent. + * nio-ftp.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + * nio-ftp.h: Run indent. + * nio-http.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + * nio-http.h: Run indent. + * nio-ie5.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + * nio-ie5.h: Run indent. + * other.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (dialog_cmd): Return a value. + * port.h: Run indent. + * postinstall.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (cmd): Fix compiler warning (deprecated conversion). + (eun): Fix compiler warning (deprecated conversion). + * root.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + * simpsock.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + * simpsock.h: Run indent. + * site.cc: Run indent. + Use io_streams. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (get_root_dir_now): Remove. + (save_site_url): Convert to io_streams. + (dialog_cmd): Return 0. + (get_initial_list_idx): Convert to io_streans. + * source.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (check_if_enable_next): Remove. + (load_dialog): Remove unused variables. + (save_dialog): Ditto. + (dialog_cmd): Return a value. + * splash.cc: Return a value. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + (dialog_cmd): Return a value. + * state.cc: Run indent. + (cvsid): Fix compiler warnings (unused, deprecated conversion). + * state.h: Run indent. + * tar.h: Remove. + * tar.cc: Remove. + 2001-11-12 Christopher Faylor * desktop.cc (start_menu): Change start menu name to "Cygwin". diff --git a/Makefile.in b/Makefile.in index 0b3bfdf8..d1236b62 100644 --- a/Makefile.in +++ b/Makefile.in @@ -35,7 +35,9 @@ CC := @CC@ CC_FOR_TARGET := $(CC) CXX := @CXX@ -CFLAGS := @CFLAGS@ +CFLAGS := @CFLAGS@ -Werror -Winline -Wall -Wpointer-arith -Wcast-align\ + -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes \ + -Wmissing-declarations -Wcomments CXXFLAGS := @CXXFLAGS@ $(CFLAGS) -fno-exceptions -fno-rtti CXX := @CXX@ @@ -48,6 +50,11 @@ MINGW_INCLUDES := -I. -I$(srcdir) -I$(mingw_source)/include $(w32api_include) -I MINGW_CXXFLAGS := -MMD $(CXXFLAGS) -mno-cygwin $(MINGW_INCLUDES) -mwindows MINGW_CFLAGS := -MMD $(CFLAGS) -mno-cygwin $(MINGW_INCLUDES) -mwindows +# to avoid false errors that assembly generates +WARNONLY_CFLAGS := -MMD @CFLAGS@ -Winline -Wall -Wpointer-arith -Wcast-align \ + -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes \ + -Wmissing-declarations -Wcomments \ + -mno-cygwin $(MINGW_INCLUDES) -mwindows ZLIB := zlib/libzcygw.a BZ2LIB := $(bupdir)/bz2lib/libbz2.a @@ -73,8 +80,14 @@ ALL_LDFLAGS := ${filter-out -I%, \ PROGS := setup$(EXEEXT) OBJS = \ + archive.o \ + archive_tar.o \ + archive_tar_file.o \ autoload.o \ choose.o \ + compress.o \ + compress_bz.o \ + compress_gz.o \ concat.o \ desktop.o \ dialog.o \ @@ -88,6 +101,9 @@ OBJS = \ inilex.o \ iniparse.o \ install.o \ + io_stream.o \ + io_stream_cygfile.o \ + io_stream_file.o \ localdir.o \ log.o \ main.o \ @@ -111,7 +127,6 @@ OBJS = \ source.o \ splash.o \ state.o \ - tar.o \ version.o \ $E @@ -166,8 +181,7 @@ version.c : $(srcdir)/ChangeLog Makefile V=`grep '^\$$Revision.*' $(srcdir)/ChangeLog \ | sed -e 's/\$$Revision:* *//' \ -e 's/ *$$.*//'` ;\ - echo "char *version = \"$$V\";" > version.tmp ;\ - echo "static char *id = \"\\n%%% setup-version $$V\\n\";" >> version.tmp + echo "const char *version = \"$$V\";" > version.tmp ;\ mv version.tmp version.c %.o: %.rc @@ -196,12 +210,30 @@ endif autoload.o: autoload.c ifdef VERBOSE - $(CC) $(MINGW_CFLAGS) -c -o $@ $< -fno-inline-functions + $(CC) $(WARNONLY_CFLAGS) -c -o $@ $< -fno-inline-functions else - @echo $(CC) -c $(CFLAGS) ... $( + * + */ + +/* Archive IO operations + */ + +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif + +#include "win32.h" +#include +#include +#include "log.h" +#include "port.h" +#include "concat.h" + +#include "io_stream.h" +#include "archive.h" +#include "archive_tar.h" + +/* In case you are wondering why the file magic is not in one place: + * It could be. But there is little (any?) benefit. + * What is important is that the file magic required for any _task_ is centralised. + * One such task is identifying archives + * + * to federate into each class one might add a magic parameter to the constructor, which + * the class could test itself. + */ + +/* GNU TAR: + * offset 257 string ustar\040\040\0 + */ + + +#define longest_magic 265 + +archive * +archive::extract (io_stream * original) +{ + if (!original) + return NULL; + char magic[longest_magic]; + if (original->peek (magic, longest_magic) > 0) + { + if (memcmp (&magic[257], "ustar\040\040\0", 8) == 0) + { + /* tar */ + archive_tar *rv = new archive_tar (original); + if (!rv->error ()) + return rv; + return NULL; + } +#if 0 + else if (memcmp (magic, "BZh", 3) == 0) + { + archive_bz *rv = new archive_bz (original); + if (!rv->error ()) + return rv; + return NULL; + } +#endif + } + return NULL; +} + +int +archive::extract_file (archive * source, const char *prefix) +{ + if (!source) + return 1; + const char *destfilename = concat (prefix, source->next_file_name (), 0); + switch (source->next_file_type ()) + { + case ARCHIVE_FILE_REGULAR: + { + + /* 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); + 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); + 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); + return 1; + } + char buffer[16384]; + ssize_t countin, countout; + while ((countin = in->read (buffer, 16384)) > 0) + { + countout = tmp->write (buffer, countin); + if (countout != countin) + { + log (LOG_TIMESTAMP, "Failed to write %ld bytes to %s", + countin, destfilename); + io_stream::remove (destfilename); + delete tmp; + delete in; + return 1; + } + } + tmp->set_mtime (in->get_mtime ()); + delete in; + delete tmp; + if (countin < 0) + { + log (LOG_TIMESTAMP, "File IO error reading from archive"); + io_stream::remove (destfilename); + } + } + break; + case ARCHIVE_FILE_SYMLINK: + { + if (io_stream::mkpath_p (PATH_TO_FILE, destfilename)) + {log (LOG_TIMESTAMP, "Failed to make the path for %s", destfilename); + return 1;} + io_stream::remove (destfilename); + int ok = + io_stream::mklink (destfilename, + concat (prefix, source->linktarget (), 0), + IO_STREAM_SYMLINK); + /* FIXME: check what tar's filelength is set to for symlinks */ + source->skip_file (); + return ok; + } + case ARCHIVE_FILE_HARDLINK: + { + if (io_stream::mkpath_p (PATH_TO_FILE, destfilename)) + {log (LOG_TIMESTAMP, "Failed to make the path for %s", destfilename); + return 1;} + io_stream::remove (destfilename); + int ok = + io_stream::mklink (destfilename, + concat (prefix, source->linktarget (), 0), + IO_STREAM_HARDLINK); + /* FIXME: check what tar's filelength is set to for hardlinks */ + source->skip_file (); + return ok; + } + case ARCHIVE_FILE_DIRECTORY: + { + char *path = (char *) alloca (strlen (destfilename)); + strcpy (path, destfilename); + while (path[0] && path[strlen (path) - 1] == '/') + path[strlen (path) - 1] = 0; + source->skip_file (); + return io_stream::mkpath_p (PATH_TO_DIR, path); + } + case ARCHIVE_FILE_INVALID: + source->skip_file (); + break; + } + return 0; +} + +#if 0 +ssize_t archive::read (void *buffer, size_t len) +{ + log (LOG_TIMESTAMP, "archive::read called"); + return 0; +} + +ssize_t archive::write (void *buffer, size_t len) +{ + log (LOG_TIMESTAMP, "archive::write called"); + return 0; +} + +ssize_t archive::peek (void *buffer, size_t len) +{ + log (LOG_TIMESTAMP, "archive::peek called"); + return 0; +} + +long +archive::tell () +{ + log (LOG_TIMESTAMP, "bz::tell called"); + return 0; +} + +int +archive::error () +{ + log (LOG_TIMESTAMP, "archive::error called"); + return 0; +} + +const char * +archive::next_file_name () +{ + log (LOG_TIMESTAMP, "archive::next_file_name called"); + return NULL; +} + +archive::~archive () +{ + log (LOG_TIMESTAMP, "archive::~archive called"); + return; +} +#endif diff --git a/archive.h b/archive.h new file mode 100644 index 00000000..43771465 --- /dev/null +++ b/archive.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2001, Robert Collins. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +#ifndef _ARCHIVE_H_ +#define _ARCHIVE_H_ + +/* this is the parent class for all archive IO operations. + * It + */ + +/* 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. + * The correct way is to + * 1) retrieve the file name. + * 2) the user creates their own output object. + * 3) the user calls extract_file (output strea,). + */ + +typedef enum +{ + ARCHIVE_FILE_INVALID, + ARCHIVE_FILE_REGULAR, + ARCHIVE_FILE_HARDLINK, + ARCHIVE_FILE_SYMLINK, + ARCHIVE_FILE_DIRECTORY +} +archive_file_t; + + +class archive:public io_stream +{ +public: + /* get an archive child class from an io_stream */ + static archive *extract (io_stream *); + /* get an ouput stream for the next files from the archive. + * returns NULL on failure. + * The stream is not taken over - it will not be automatically deleted + */ + virtual io_stream *extract_file () = NULL; + /* extract the next file to the given prefix in one step + * returns 1 on failure. + */ + static int extract_file (archive *, const char *); + + /* + * To create a stream that will be compressed, you should open the url, and then get a new stream + * from compress::compress. + */ + /* read data - not valid for archives (duh!) + * Could be made valid via the read-child-directly model + */ +// virtual ssize_t read(void *buffer, size_t len) {return -1;}; + /* provide data to (double duh!) */ +// virtual ssize_t write(void *buffer, size_t len) { return -1;}; + /* read data without removing it from the class's internal buffer */ +// virtual ssize_t peek(void *buffer, size_t len); +// virtual long tell (); + /* try guessing this one */ +// virtual int error (); + /* Find out the next stream name - + * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar + * for foobar that is an compress, next_file_name is the next + * extractable filename. + * 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 archive_file_t next_file_type () = ARCHIVE_FILE_INVALID; + virtual const char *linktarget () = NULL; + virtual int skip_file () = 0; + /* if you are still needing these hints... give up now! */ +// virtual ~compress (); +private: +// archive () {}; +}; + +#endif /* _ARCHIVE_H_ */ diff --git a/archive_tar.cc b/archive_tar.cc new file mode 100644 index 00000000..f531ef3d --- /dev/null +++ b/archive_tar.cc @@ -0,0 +1,309 @@ +/* + * Copyright (c) 2000, 2001, Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by DJ Delorie + * + */ + +/* Built-in tar functionality. See tar.h for usage. */ + +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif + +#include "win32.h" +#include +#include +#include +#include +#include + +//#include "zlib/zlib.h" +#include "io_stream.h" +//#include "compress.h" +#include "archive.h" +#include "archive_tar.h" +#include "mkdir.h" +#include "log.h" +#include "filemanip.h" +#include "concat.h" + +#include "port.h" +#if 0 +#undef _WIN32 +#include "bzlib.h" + +#define FACTOR (0x19db1ded53ea710LL) +#define NSPERSEC 10000000LL +#define SYMLINK_COOKIE "!" +#endif +static int err; + +//static char file_name[_MAX_PATH+512]; +//static char have_longname = 0; +//static int file_length; + +static char buf[512]; + +int _tar_verbose = 0; +FILE *_tar_vfile = 0; +#define vp if (_tar_verbose) fprintf +#define vp2 if (_tar_verbose>1) fprintf + +archive_tar::archive_tar (io_stream * original) +{ + archive_children = 0; + if (_tar_vfile == 0) + _tar_vfile = stderr; + + vp2 (_tar_vfile, "tar: open `%p'\n", original); + + if (!original) + { + state.lasterr = EBADF; + return; + } + state.parent = original; + + if (sizeof (state.tar_header) != 512) + { + /* drastic, but important */ + fprintf (stderr, "compilation error: tar header struct not 512" + " bytes (it's %d)\n", sizeof (state.tar_header)); + exit_setup (1); + } +} + +ssize_t +archive_tar::read (void *buffer, size_t len) +{ + return -1; +} + +ssize_t +archive_tar::write (void *buffer, size_t len) +{ + return 0; +} + +ssize_t +archive_tar::peek (void *buffer, size_t len) +{ + return 0; +} + +int +archive_tar::error () +{ + return state.lasterr; +} + +long +archive_tar::tell () +{ + return state.file_offset; +} + +int +archive_tar::skip_file () +{ + while (state.file_length > state.file_offset) + { + int len = state.parent->read (buf, 512); + state.file_offset += 512; + if (len != 512) + return 1; + } + state.file_length = 0; + state.file_offset = 0; + state.header_read = 0; + return 0; +} + +const char * +archive_tar::next_file_name () +{ + char *c; + + if (state.header_read) + if (strlen (state.filename)) + return state.filename; + else + /* End of tar */ + return NULL; + + int r = state.parent->read (&state.tar_header, 512); + + /* See if we're at end of file */ + if (r != 512) + return NULL; + + /* See if the header is all zeros (i.e. last block) */ + int n = 0; + for (r = 512 / sizeof (int); r; r--) + n |= ((int *) &state.tar_header)[r - 1]; + if (n == 0) + return NULL; + + if (!state.have_longname && state.tar_header.typeflag != 'L') + { + memcpy (state.filename, state.tar_header.name, 100); + state.filename[100] = 0; + } + + sscanf (state.tar_header.size, "%o", &state.file_length); + state.file_offset = 0; + +// vp2 (_tar_vfile, "%c %9d %s\n", state.tar_header.typeflag, +// state.file_length, state.filename); + + switch (state.tar_header.typeflag) + { + case 'L': /* GNU tar long name extension */ + /* we read the 'file' into the long filename, then call back into here + * to find out if the actual file is a real file, or a special file.. + */ + if (state.file_length > _MAX_PATH) + { + skip_file (); + fprintf (stderr, "error: long file name exceeds %d characters\n", + _MAX_PATH); + err++; + state.parent->read (&state.tar_header, 512); + sscanf (state.tar_header.size, "%o", &state.file_length); + state.file_offset = 0; + skip_file (); + return next_file_name (); + } + c = state.filename; + /* FIXME: this should be a single read() call */ + while (state.file_length > state.file_offset) + { + int need = + state.file_length - state.file_offset > + 512 ? 512 : state.file_length - state.file_offset; + if (state.parent->read (buf, 512) < 512) + return 0; + memcpy (c, buf, need); + c += need; + state.file_offset += need; + } + *c = 0; + state.have_longname = 1; + return next_file_name (); + + case '3': /* char */ + case '4': /* block */ + case '6': /* fifo */ + fprintf (stderr, "warning: not extracting special file %s\n", + state.filename); + err++; + return next_file_name (); + + case '0': /* regular file */ + case 0: /* regular file also */ + case '2': /* symbolic link */ + case '5': /* directory */ + case '7': /* contiguous file */ + state.header_read = 1; + return state.filename; + + case '1': /* hard link, we just copy */ + state.header_read = 1; + return state.filename; + + default: + fprintf (stderr, "error: unknown (or unsupported) file type `%c'\n", + state.tar_header.typeflag); + err++; + skip_file (); + return next_file_name (); + } + return NULL; +} + +archive_tar::~archive_tar () +{ + if (state.parent) + delete state.parent; +} + +# if 0 +static void +fix_time_stamp (char *path) +{ + int mtime; + long long ftimev; + FILETIME ftime; + HANDLE h; + + sscanf (tar_header.mtime, "%o", &mtime); + ftimev = mtime * NSPERSEC + FACTOR; + ftime.dwHighDateTime = ftimev >> 32; + ftime.dwLowDateTime = ftimev; + h = CreateFileA (path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, + 0, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, 0); + if (h) + { + SetFileTime (h, 0, 0, &ftime); + CloseHandle (h); + } +} +#endif +archive_file_t +archive_tar::next_file_type () +{ + switch (state.tar_header.typeflag) + { + /* regular files */ + case '0': + case 0: + case '7': + return ARCHIVE_FILE_REGULAR; + case '1': + return ARCHIVE_FILE_HARDLINK; + case '5': + return ARCHIVE_FILE_DIRECTORY; + case '2': + return ARCHIVE_FILE_SYMLINK; + default: + return ARCHIVE_FILE_INVALID; + } +} + +const char * +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; +} + +io_stream * +archive_tar::extract_file () +{ + if (archive_children) + return NULL; + archive_tar_file *rv = new archive_tar_file (state); + return rv; +} + +int +archive_tar::get_mtime () +{ + if (state.parent) + return state.parent->get_mtime (); + return 0; +} diff --git a/archive_tar.h b/archive_tar.h new file mode 100644 index 00000000..7a28c991 --- /dev/null +++ b/archive_tar.h @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2000, Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by DJ Delorie + * Made OOP by R Collins + * + */ + +#ifndef __TAR_H_ +#define __TAR_H_ + +typedef struct +{ + char name[100]; /* 0 */ + char mode[8]; /* 100 */ + char uid[8]; /* 108 */ + char gid[8]; /* 116 */ + char size[12]; /* 124 */ + char mtime[12]; /* 136 */ + char chksum[8]; /* 148 */ + char typeflag; /* 156 */ + char linkname[100]; /* 157 */ + char magic[6]; /* 257 */ + char version[2]; /* 263 */ + char uname[32]; /* 265 */ + char gname[32]; /* 297 */ + char devmajor[8]; /* 329 */ + char devminor[8]; /* 337 */ + char prefix[155]; /* 345 */ + char junk[12]; /* 500 */ +} +tar_header_type; + +typedef struct tar_map_result_type_s +{ + struct tar_map_result_type_s *next; + char *stored_name; + char *mapped_name; +} +tar_map_result_type; + +class tar_state +{ +public: + tar_state ():lasterr (0), eocf (0), have_longname ('\0'), file_offset (0), + file_length (0), header_read (0) + { + parent = NULL; + filename[0] = '\0'; + tar_map_result = NULL; + }; + io_stream *parent; + int lasterr; + int eocf; + char have_longname; + /* where in the current file are we? */ + size_t file_offset; + size_t file_length; + int header_read; + tar_header_type tar_header; + char filename[_MAX_PATH + 512]; + tar_map_result_type *tar_map_result; +}; + +class archive_tar_file:public io_stream +{ +public: + archive_tar_file (tar_state &); + virtual ssize_t read (void *buffer, size_t len); + /* provide data to (double duh!) */ + virtual ssize_t write (void *buffer, size_t len); + /* read data without removing it from the class's internal buffer */ + virtual ssize_t peek (void *buffer, size_t len); + virtual long tell (); + /* try guessing this one */ + virtual int error (); + virtual char *next_file_name () + { + return NULL; + }; + virtual int get_mtime (); + virtual int set_mtime (int) + { + return 1; + }; + virtual ~ archive_tar_file (); +private: + tar_state & state; +}; + +class archive_tar:public archive +{ +public: + archive_tar (io_stream * original); + virtual io_stream *extract_file (); + /* read data (duh!) */ + virtual ssize_t read (void *buffer, size_t len); + /* provide data to (double duh!) */ + virtual ssize_t write (void *buffer, size_t len); + /* read data without removing it from the class's internal buffer */ + virtual ssize_t peek (void *buffer, size_t len); + virtual long tell (); + /* try guessing this one */ + virtual int error (); + /* Find out the next stream name - + * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar + * for foobar that is an compress, next_file_name is the next + * extractable filename. + */ + virtual const char *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 (); + /* only of use when we support writing to tar */ + virtual int set_mtime (int) + { + return 1; + }; + virtual const char *linktarget (); + virtual int skip_file (); + /* if you are still needing these hints... give up now! */ + virtual ~ archive_tar (); +private: + archive_tar () + { + }; + tar_state state; + unsigned int archive_children; +}; + +/* Only one tarfile may be open at a time. gzipped files handled + automatically */ + +/* returns zero on success, nonzero on failure */ +//int tar_open (const char *pathname); + +/* pass adjusted path, returns zero on success, nonzero on failure */ +//int tar_read_file (char *path); + + +#if 0 +/* pass path to tar file and from/to pairs for path prefix (NULLs at + end , returns zero if completely successful, nonzero (counts + errors) on failure */ +int tar_auto (char *pathname, char **map); +#endif + + +//int tar_mkdir_p (int isadir, char *path); + +/* +extern int _tar_verbose; +extern FILE * _tar_vfile; +*/ + +#endif diff --git a/archive_tar_file.cc b/archive_tar_file.cc new file mode 100644 index 00000000..178d0a05 --- /dev/null +++ b/archive_tar_file.cc @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2001, Robert Collins + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +/* An individual stream from a tar archive. */ + +#if 0 +static const char *cvsid = "\n%%% $Id$\n"; +#endif + +#include "win32.h" +#include +#include +#include +#include +#include + +#include "zlib/zlib.h" +#include "io_stream.h" +#include "compress.h" +#include "archive.h" +#include "archive_tar.h" +#include "log.h" +#include "concat.h" + +#include "port.h" + +archive_tar_file::archive_tar_file (tar_state & newstate):state (newstate) +{ +} + +archive_tar_file::~archive_tar_file () +{ + state.header_read = 0; +} + +/* Virtual memebrs */ +ssize_t archive_tar_file::read (void *buffer, size_t len) +{ + /* how many bytes do we want to give the user */ + int + want = min (len, state.file_length - state.file_offset); + /* how many do we need to read after that to line up the file pointer */ + int + roundup = (512 - (want % 512)) % 512; + if (want) + { + ssize_t + got = state.parent->read (buffer, want); + char + throwaway[512]; + ssize_t + got2 = state.parent->read (throwaway, roundup); + if (got == want && got2 == roundup) + { + state.file_offset += got; + return got; + } + else + { + /* unexpected EOF or read error in the tar parent stream */ + /* the user can query the parent for the error */ + state.lasterr = EIO; + return EIO; + } + } + return 0; +} + +/* provide data to (double duh!) */ +ssize_t archive_tar_file::write (void *buffer, size_t len) +{ + /* write not supported */ + return EBADF; +} + +/* read data without removing it from the class's internal buffer */ +ssize_t archive_tar_file::peek (void *buffer, size_t len) +{ + int + want = min (len, state.file_length - state.file_offset); + if (want) + { + ssize_t + got = state.parent->peek (buffer, want); + if (got == want) + { + return got; + } + else + { + /* unexpected EOF or read error in the tar parent stream */ + /* the user can query the parent for the error */ + state.lasterr = EIO; + return EIO; + } + } + return 0; +} + +long +archive_tar_file::tell () +{ + return state.file_offset; +} + +/* try guessing this one */ +int +archive_tar_file::error () +{ + return state.lasterr; +} + +int +archive_tar_file::get_mtime () +{ + int mtime; + sscanf (state.tar_header.mtime, "%o", &mtime); + return mtime; +} diff --git a/autoload.c b/autoload.c index f9406b99..2d1ee74d 100644 --- a/autoload.c +++ b/autoload.c @@ -12,8 +12,9 @@ * Written by DJ Delorie * */ - -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = "\n%%% $Id$\n"; +#endif #include "win32.h" diff --git a/choose.cc b/choose.cc index 8128e3ea..5d039b8c 100644 --- a/choose.cc +++ b/choose.cc @@ -45,7 +45,7 @@ static const char *cvsid = #include "log.h" #include "find.h" #include "filemanip.h" -#include "mount.h" +#include "io_stream.h" #include "choose.h" #include "port.h" @@ -140,10 +140,9 @@ set_action (Package * pkg, bool preinc) return; } /* the passed in trust level is missing... */ - if (!preinc /* auto set */ - && pkg->installed - && pkg->action > ACTION_CURR) /* There is no current version */ - (int)pkg->action = ACTION_SAME_CURR; + if (!preinc /* auto set */ + && pkg->installed && pkg->action > ACTION_CURR) /* There is no current version */ + (int) pkg->action = ACTION_SAME_CURR; break; /* ACTION_SAME_* are used when the installed version is the same as the given action. */ @@ -1032,9 +1031,10 @@ _view::click (int row, int x) { if (lines[n].get_category () || (lines[n].get_pkg () && strcasecmp (pkg->name, - lines[n]. - get_pkg ()-> - name) < 0)) + lines + [n].get_pkg + ()->name) < + 0)) { insert_at (n, line); n = nlines; @@ -1158,7 +1158,8 @@ create_listview (HWND dlg, RECT * r) default_trust (lv, TRUST_CURR); set_view_mode (lv, VIEW_CATEGORY); if (!SetDlgItemText (dlg, IDC_CHOOSE_VIEWCAPTION, chooser->mode_caption ())) - log (LOG_BABBLE, "Failed to set View button caption %ld", GetLastError ()); + log (LOG_BABBLE, "Failed to set View button caption %ld", + GetLastError ()); for (Package * foo = package; foo->name; foo++) add_required (foo); static int ta[] = { IDC_CHOOSE_CURR, 0 }; @@ -1284,18 +1285,14 @@ base (const char *s) int find_tar_ext (const char *path) { - char *p = strchr (path, '\0') - 7; - if (p <= path) - return 0; - if (*p == '.') - { - if (strcmp (p, ".tar.gz") != 0) - return 0; - } - else if (--p <= path || strcmp (p, ".tar.bz2") != 0) - return 0; - - return p - path; + /* check in longest first order */ + char *ext = strstr (path, ".tar.bz2"); + if (ext) + return ext - path; + if ((ext = strstr (path, ".tar.gz"))); + return ext - path; + if ((ext = strstr (path, ".tar"))); + return ext - path; } /* Parse a filename into package, version, and extension components. */ @@ -1520,17 +1517,16 @@ _Info::_Info (const char *_install, const char *_version, int _install_size, static void read_installed_db () { - if (!get_root_dir ()) - return; - char line[1000], pkgname[1000], inst[1000], src[1000]; int instsz, srcsz; - FILE *db = fopen (cygpath ("/etc/setup/installed.db", 0), "rt"); + io_stream *db = + io_stream::open (concat ("cygfile://", "/etc/setup/installed.db", 0), + "rt"); if (!db) return; - while (fgets (line, 1000, db)) + while (db->gets (line, 1000)) { int parseable; src[0] = 0; @@ -1570,7 +1566,7 @@ read_installed_db () break; } } - fclose (db); + delete db; } int diff --git a/choose.h b/choose.h index 9fb82176..188a6077 100644 --- a/choose.h +++ b/choose.h @@ -45,7 +45,8 @@ typedef enum ACTION_SAME_TEST = ACTION_TEST + ACTION_SAME, /* Last action. */ ACTION_SAME_LAST -} actions; +} +actions; typedef enum { @@ -54,7 +55,8 @@ typedef enum VIEW_PACKAGE, VIEW_CATEGORY, NVIEW -} views; +} +views; struct _header { @@ -70,46 +72,55 @@ typedef class _view view; class pick_line { - public: - void set_line (Package *_pkg); - void set_line (Category *_cat); - void paint (HDC hdc, int x, int y, int row, int show_cat); - Package *get_pkg (void) { return pkg; }; - Category *get_category (void) { return cat; }; - int click (int x); - private: - Package *pkg; - Category *cat; +public: + void set_line (Package * _pkg); + void set_line (Category * _cat); + void paint (HDC hdc, int x, int y, int row, int show_cat); + Package *get_pkg (void) + { + return pkg; + }; + Category *get_category (void) + { + return cat; + }; + int click (int x); +private: + Package * pkg; + Category *cat; }; class _view { - public: - int num_columns; - views get_view_mode () { return view_mode; }; - void set_view_mode(views _mode); - struct _header *headers; +public: + int num_columns; + views get_view_mode () + { + return view_mode; + }; + void set_view_mode (views _mode); + struct _header *headers; _view (views mode, HDC dc); - const char *mode_caption (); - void insert_pkg (Package *); - void insert_category (Category *, int); - void clear_view (void); - int click (int row, int x); - int current_col; - int new_col; - int src_col; - int cat_col; - int pkg_col; - int last_col; - pick_line * lines; - int nlines; + const char *mode_caption (); + void insert_pkg (Package *); + void insert_category (Category *, int); + void clear_view (void); + int click (int row, int x); + int current_col; + int new_col; + int src_col; + int cat_col; + int pkg_col; + int last_col; + pick_line *lines; + int nlines; - private: +private: views view_mode; - void set_headers (void); - void init_headers (HDC dc); - void insert_at (int, pick_line); - void insert_under (int linen, pick_line line); + void set_headers (void); + void init_headers (HDC dc); + void insert_at (int, pick_line); + void insert_under (int linen, pick_line line); }; #endif /* __cplusplus */ diff --git a/compress.cc b/compress.cc new file mode 100644 index 00000000..7b200703 --- /dev/null +++ b/compress.cc @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2001, Robert Collins. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +/* Archive IO operations + */ + +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif + +#include "win32.h" +#include +#include "log.h" +#include "port.h" + +#include "io_stream.h" +#include "compress.h" +#include "zlib/zlib.h" +#include "compress_gz.h" +#include "compress_bz.h" + +/* In case you are wondering why the file magic is not in one place: + * It could be. But there is little (any?) benefit. + * What is important is that the file magic required for any _task_ is centralised. + * One such task is identifying compresss + * + * to federate into each class one might add a magic parameter to the constructor, which + * the class could test itself. + */ + +#define longest_magic 3 + +io_stream * +compress::decompress (io_stream * original) +{ + if (!original) + return NULL; + char magic[longest_magic]; + if (original->peek (magic, longest_magic) > 0) + { + if (memcmp (magic, "\037\213", 2) == 0) + { + /* tar */ + compress_gz *rv = new compress_gz (original); + if (!rv->error ()) + return rv; + return NULL; + } + else if (memcmp (magic, "BZh", 3) == 0) + { + compress_bz *rv = new compress_bz (original); + if (!rv->error ()) + return rv; + return NULL; + } + } + return NULL; +} + +ssize_t +compress::read (void *buffer, size_t len) +{ + log (LOG_TIMESTAMP, "compress::read called"); + return 0; +} + +ssize_t +compress::write (void *buffer, size_t len) +{ + log (LOG_TIMESTAMP, "compress::write called"); + return 0; +} + +ssize_t +compress::peek (void *buffer, size_t len) +{ + log (LOG_TIMESTAMP, "compress::peek called"); + return 0; +} + +long +compress::tell () +{ + log (LOG_TIMESTAMP, "bz::tell called"); + return 0; +} + +int +compress::error () +{ + log (LOG_TIMESTAMP, "compress::error called"); + return 0; +} + +const char * +compress::next_file_name () +{ + log (LOG_TIMESTAMP, "compress::next_file_name called"); + return NULL; +} + +compress::~compress () +{ + log (LOG_TIMESTAMP, "compress::~compress called"); + return; +} diff --git a/compress.h b/compress.h new file mode 100644 index 00000000..c0871b28 --- /dev/null +++ b/compress.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2001, Robert Collins. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +#ifndef _COMPRESS_H_ +#define _COMPRESS_H_ + +/* this is the parent class for all compress IO operations. + * It + */ + +class compress:public io_stream +{ +public: + /* Get a decompressed stream from a normal stream. If this function returns non-null + * a valid compress header was found. The io_stream pointer passed to decompress + * should be discarded. The old io_stream will be automatically closed when the + * decompression stream is closed + */ + static io_stream *decompress (io_stream *); + /* + * To create a stream that will be compressed, you should open the url, and then get a new stream + * from compress::compress. + */ + /* read data (duh!) */ + virtual ssize_t read (void *buffer, size_t len); + /* provide data to (double duh!) */ + virtual ssize_t write (void *buffer, size_t len); + /* read data without removing it from the class's internal buffer */ + virtual ssize_t peek (void *buffer, size_t len); + virtual long tell (); + /* try guessing this one */ + virtual int error (); + /* Find out the next stream name - + * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar + * for foobar that is an compress, next_file_name is the next + * extractable filename. + */ + virtual const char *next_file_name () = NULL; + /* if you are still needing these hints... give up now! */ + virtual ~ compress (); +}; + +#endif /* _COMPRESS_H_ */ diff --git a/compress_bz.cc b/compress_bz.cc new file mode 100644 index 00000000..43b8e29d --- /dev/null +++ b/compress_bz.cc @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2001, Robert Collins. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +/* Archive IO operations for bz2 files. + derived from the fd convenience functions in the libbz2 package. + */ + +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif + +#include "win32.h" +#include +#include +#include "log.h" +#include "port.h" + +#include "io_stream.h" +#include "compress.h" +#include "compress_bz.h" +#undef _WIN32 +#include "bzlib.h" + +compress_bz::compress_bz (io_stream * parent) : peeklen (0) +{ + /* read only via this constructor */ + original = 0; + lasterr = 0; + if (!parent || parent->error ()) + { + lasterr = EBADF; + return; + } + original = parent; + + initialisedOk = 0; + bufN = 0; + writing = 0; + strm.bzalloc = 0; + strm.bzfree = 0; + strm.opaque = 0; + int ret = BZ2_bzDecompressInit (&(strm), 0, 0); + if (ret) + { + lasterr = ret; + return; + } + strm.avail_in = 0; + strm.next_in = 0; + initialisedOk = 1; +} + +ssize_t compress_bz::read (void *buffer, size_t len) +{ + if (!initialisedOk || writing) + return EBADF; + if (len == 0) + return 0; + + if (peeklen) + { + ssize_t tmplen = min (peeklen, len); + peeklen -= tmplen; + memcpy (buffer, peekbuf, tmplen); + memmove (peekbuf, peekbuf + tmplen, tmplen); + ssize_t tmpread = read (&((char *) buffer)[tmplen], len - tmplen); + if (tmpread >= 0) + return tmpread + tmplen; + else + return tmpread; + } + + strm.avail_out = len; + strm.next_out = (char *) buffer; + int + rlen = 1; + while (1) + { + if (original->error ()) + { + lasterr = original->error (); + return -1; + } + if (strm.avail_in == 0 && rlen > 0) + { + rlen = original->read (buf, 4096); + if (rlen < 0) + { + lasterr = rlen; + return -1; + } + bufN = rlen; + strm.avail_in = rlen; + strm.next_in = buf; + } + int + ret = BZ2_bzDecompress (&strm); + if (ret != BZ_OK && ret != BZ_STREAM_END) + { + lasterr = ret; + return -1; + } + if (ret == BZ_OK && rlen == 0 && strm.avail_out) + { + /* unexpected end of file */ + lasterr = EIO; + return -1; + } + if (ret == BZ_STREAM_END) + return len - strm.avail_out; + if (strm.avail_out == 0) + return len; + } + + /* not reached */ + return 0; +} + +ssize_t compress_bz::write (void *buffer, size_t len) +{ + log (LOG_TIMESTAMP, "compress_bz::write called"); + return 0; +} + +ssize_t compress_bz::peek (void *buffer, size_t len) +{ + log (LOG_TIMESTAMP, "compress_bz::peek called"); + if (writing) + { + lasterr = EBADF; + return -1; + } + /* can only peek 512 bytes */ + if (len > 512) + return ENOMEM; + + if (len > peeklen) + { + size_t want = len - peeklen; + ssize_t got = read (&peekbuf[peeklen], want); + if (got >= 0) + peeklen += got; + else + /* error */ + return got; + /* we may have read less than requested. */ + memcpy (buffer, peekbuf, peeklen); + return peeklen; + } + else + { + memcpy (buffer, peekbuf, len); + return len; + } + return 0; +} + +long +compress_bz::tell () +{ + log (LOG_TIMESTAMP, "compress_bz::tell called"); + return 0; +} + +int +compress_bz::error () +{ + log (LOG_TIMESTAMP, "compress_bz::error called"); + return 0; +} + +int +compress_bz::set_mtime (int time) +{ + if (original) + return original->set_mtime (time); + return 1; +} + +int +compress_bz::get_mtime () +{ + if (original) + return original->get_mtime (); + return 0; +} + +compress_bz::~compress_bz () +{ + log (LOG_TIMESTAMP, "compress_bz::~bz called"); + if (initialisedOk) + BZ2_bzDecompressEnd (&strm); + return; +} diff --git a/compress_bz.h b/compress_bz.h new file mode 100644 index 00000000..91cd99c9 --- /dev/null +++ b/compress_bz.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2001, Robert Collins. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +#ifndef _COMPRESS_BZ_H_ +#define _COMPRESS_BZ_H_ + +/* this is the bz2 class for all compressed IO operations. + */ + +#ifdef _WIN32 +#undef _WIN32 +#include "bzlib.h" +#define _WIN32 +#else +#include "bzlib.h" +#endif + +class compress_bz:public compress +{ +public: + /* assumes decompression */ + compress_bz (io_stream *); + /* allows comp/decomp but this implementation only handles comp */ + compress_bz (io_stream *, const char *); + /* read data (duh!) */ + virtual ssize_t read (void *buffer, size_t len); + /* provide data to (double duh!) */ + virtual ssize_t write (void *buffer, size_t len); + /* read data without removing it from the class's internal buffer */ + virtual ssize_t peek (void *buffer, size_t len); + virtual long tell (); + /* try guessing this one */ + virtual int error (); + /* Find out the next stream name - + * ie for foo.tar.bz, at offset 0, next_file_name = foo.tar + * for foobar that is an compress, next_file_name is the next + * extractable filename. + */ + virtual const char *next_file_name () + { + return NULL; + }; + virtual int set_mtime (int); + virtual int get_mtime (); + /* if you are still needing these hints... give up now! */ + virtual ~ compress_bz (); +private: + io_stream *original; + char peekbuf[512]; + size_t peeklen; + int lasterr; + bz_stream strm; + int initialisedOk; + int bufN; + char buf[4096]; + int writing; + +}; + +#endif /* _COMPRESS_BZ_H_ */ diff --git a/compress_gz.cc b/compress_gz.cc new file mode 100644 index 00000000..ee9c322e --- /dev/null +++ b/compress_gz.cc @@ -0,0 +1,614 @@ +/* + * Copyright (c) 2001, Robert Collins. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +/* Archive IO operations for gz files + * Portions copyright under the zlib licence - this class was derived from gzio.c in that + * library. + */ + +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif + +#include "win32.h" +#include +#include +#include +#include "log.h" +#include "port.h" + +#include "io_stream.h" +#include "compress.h" +#include "zlib/zlib.h" +#include "compress_gz.h" + +#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */ +#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ +#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ +#define COMMENT 0x10 /* bit 4 set: file comment present */ +#define RESERVED 0xE0 /* bits 5..7: reserved */ + + +/* TODO make this a static member and federate the magic logic */ +static int gz_magic[2] = { 0x1f, 0x8b }; /* gzip magic header */ + +/* + * Predicate: the stream is open for read. For writing the class constructor variant with + * mode must be called directly + */ +compress_gz::compress_gz (io_stream * parent) +{ + construct (parent, "r"); +} + +compress_gz::compress_gz (io_stream * parent, const char *openmode) +{ + construct (parent, openmode); +} + +void +compress_gz::construct (io_stream * parent, const char *openmode) +{ + if (!parent) + { + z_err = Z_STREAM_ERROR; + return; + } + + original = parent; + peeklen = 0; + int err; + int level = Z_DEFAULT_COMPRESSION; /* compression level */ + int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */ + char *p = (char *) openmode; + char fmode[80]; /* copy of openmode, without the compression level */ + char *m = fmode; + + stream.zalloc = (alloc_func) NULL; + stream.zfree = (free_func) NULL; + stream.opaque = (voidpf) NULL; + stream.next_in = inbuf = NULL; + stream.next_out = outbuf = NULL; + stream.avail_in = stream.avail_out = 0; + z_err = Z_OK; + z_eof = 0; + crc = crc32 (0L, Z_NULL, 0); + msg = NULL; + transparent = 0; + + mode = '\0'; + do + { + if (*p == 'r') + mode = 'r'; + if (*p == 'w' || *p == 'a') + mode = 'w'; + if (*p >= '0' && *p <= '9') + { + level = *p - '0'; + } + else if (*p == 'f') + { + strategy = Z_FILTERED; + } + else if (*p == 'h') + { + strategy = Z_HUFFMAN_ONLY; + } + else + { + *m++ = *p; /* copy the mode */ + } + } + while (*p++ && m != fmode + sizeof (fmode)); + if (mode == '\0') + { + destroy (); + z_err = Z_STREAM_ERROR; + return; + } + + + if (mode == 'w') + { + err = deflateInit2 (&(stream), level, + Z_DEFLATED, -MAX_WBITS, 8, strategy); + /* windowBits is passed < 0 to suppress zlib header */ + + stream.next_out = outbuf = (Byte *) malloc (16384); + if (err != Z_OK || outbuf == Z_NULL) + { + destroy (); + z_err = Z_STREAM_ERROR; + return; + } + } + else + { + + stream.next_in = inbuf = (unsigned char *) malloc (16384); + err = inflateInit2 (&stream, -MAX_WBITS); + /* windowBits is passed < 0 to tell that there is no zlib header. + * Note that in this case inflate *requires* an extra "dummy" byte + * after the compressed stream in order to complete decompression and + * return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are + * present after the compressed stream. + */ + if (err != Z_OK || inbuf == Z_NULL) + { + destroy (); + z_err = Z_STREAM_ERROR; + return; + } + } + stream.avail_out = 16384; + + errno = 0; + if (mode == 'w') + { + /* Write a very simple .gz header: + */ + char temp[20]; + sprintf (temp, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1], + Z_DEFLATED, 0 /*flags */ , 0, 0, 0, 0 /*time */ , + 0 /*xflags */ , 0x0b); + original->write (temp, 10); + startpos = 10L; + /* We use 10L instead of ftell(s->file) to because ftell causes an + * fflush on some systems. This version of the library doesn't use + * startpos anyway in write mode, so this initialization is not + * necessary. + */ + } + else + { + + check_header (); /* skip the .gz header */ + startpos = (original->tell () - stream.avail_in); + } + + return; +} + +/* =========================================================================== + Outputs a long in LSB order to the given file +*/ +void +compress_gz::putLong (unsigned long x) +{ + int n; + for (n = 0; n < 4; n++) + { + unsigned char c = (unsigned char) (x & 0xff); + original->write (&c, 1); + x = x >> 8; + } +} + + +uLong +compress_gz::getLong () +{ + uLong x = (uLong) get_byte (); + int c; + + x += ((uLong) get_byte ()) << 8; + x += ((uLong) get_byte ()) << 16; + c = get_byte (); + if (c == EOF) + z_err = Z_DATA_ERROR; + x += ((uLong) c) << 24; + return x; +} + + +ssize_t +compress_gz::read (void *buffer, size_t len) +{ + if (!len) + return 0; + + if (peeklen) + { + ssize_t tmplen = min (peeklen, len); + peeklen -= tmplen; + memcpy (buffer, peekbuf, tmplen); + memmove (peekbuf, peekbuf + tmplen, tmplen); + ssize_t tmpread = read (&((char *) buffer)[tmplen], len - tmplen); + if (tmpread >= 0) + return tmpread + tmplen; + else + return tmpread; + } + + Bytef *start = (Bytef *) buffer; /* starting point for crc computation */ + Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */ + + if (mode != 'r') + return Z_STREAM_ERROR; + + if (z_err == Z_DATA_ERROR || z_err == Z_ERRNO) + return -1; + if (z_err == Z_STREAM_END) + return 0; /* EOF */ + + next_out = (Byte *) buffer; + stream.next_out = (Bytef *) buffer; + stream.avail_out = len; + + while (stream.avail_out != 0) + { + + if (transparent) + { + /* Copy first the lookahead bytes: */ + uInt n = stream.avail_in; + if (n > stream.avail_out) + n = stream.avail_out; + if (n > 0) + { + memcpy (stream.next_out, stream.next_in, n); + next_out += n; + stream.next_out = next_out; + stream.next_in += n; + stream.avail_out -= n; + stream.avail_in -= n; + } + if (stream.avail_out > 0) + { + stream.avail_out -= original->read (next_out, stream.avail_out); + } + len -= stream.avail_out; + stream.total_in += (uLong) len; + stream.total_out += (uLong) len; + if (len == 0) + z_eof = 1; + return (int) len; + } + if (stream.avail_in == 0 && !z_eof) + { + + errno = 0; + stream.avail_in = original->read (inbuf, 16384); + if (stream.avail_in == 0) + { + z_eof = 1; + if (original->error ()) + { + z_err = Z_ERRNO; + break; + } + } + stream.next_in = inbuf; + } + z_err = inflate (&(stream), Z_NO_FLUSH); + + if (z_err == Z_STREAM_END) + { + /* Check CRC and original size */ + crc = crc32 (crc, start, (uInt) (stream.next_out - start)); + start = stream.next_out; + + if (getLong () != crc) + { + z_err = Z_DATA_ERROR; + } + else + { + (void) getLong (); + /* The uncompressed length returned by above getlong() may + * be different from stream.total_out) in case of + * concatenated .gz files. Check for such files: + */ + check_header (); + if (z_err == Z_OK) + { + uLong total_in = stream.total_in; + uLong total_out = stream.total_out; + + inflateReset (&(stream)); + stream.total_in = total_in; + stream.total_out = total_out; + crc = crc32 (0L, Z_NULL, 0); + } + } + } + if (z_err != Z_OK || z_eof) + break; + } + crc = crc32 (crc, start, (uInt) (stream.next_out - start)); + + return (int) (len - stream.avail_out); +} + + +/* =========================================================================== + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of bytes actually written (0 in case of error). +*/ +ssize_t +compress_gz::write (void *buffer, size_t len) +{ + if (mode != 'w') + return Z_STREAM_ERROR; + + stream.next_in = (Bytef *) buffer; + stream.avail_in = len; + + while (stream.avail_in != 0) + { + + if (stream.avail_out == 0) + { + + stream.next_out = outbuf; + if (original->write (outbuf, 16384) != 16384) + { + z_err = Z_ERRNO; + break; + } + stream.avail_out = 16384; + } + z_err = deflate (&(stream), Z_NO_FLUSH); + if (z_err != Z_OK) + break; + } + crc = crc32 (crc, (const Bytef *) buffer, len); + + return (int) (len - stream.avail_in); +} + +ssize_t +compress_gz::peek (void *buffer, size_t len) +{ + log (LOG_TIMESTAMP, "compress_gz::peek called"); + if (mode != 'r') + return Z_STREAM_ERROR; + /* can only peek 512 bytes */ + if (len > 512) + return ENOMEM; + + if (len > peeklen) + { + size_t want = len - peeklen; + ssize_t got = read (&peekbuf[peeklen], want); + if (got >= 0) + peeklen += got; + else + /* error */ + return got; + /* we may have read less than requested. */ + memcpy (buffer, peekbuf, peeklen); + return peeklen; + } + else + { + memcpy (buffer, peekbuf, len); + return len; + } +} + +long +compress_gz::tell () +{ + log (LOG_TIMESTAMP, "compress_gz::tell called"); + return 0; +} + +int +compress_gz::error () +{ +// log (LOG_TIMESTAMP, "compress_gz::error called"); + return z_err; +} + +int +compress_gz::set_mtime (int time) +{ + if (original) + return original->set_mtime (time); + return 1; +} + +int +compress_gz::get_mtime () +{ + if (original) + return original->get_mtime (); + return 0; +} + +void +compress_gz::destroy () +{ + if (msg) + free (msg); + if (stream.state != NULL) + { + if (mode == 'w') + { + z_err = deflateEnd (&(stream)); + } + else if (mode == 'r') + { + z_err = inflateEnd (&(stream)); + } + } + + if (inbuf) + + free (inbuf); + if (outbuf) + free (outbuf); + if (original) + delete original; +} + +compress_gz::~compress_gz () +{ + log (LOG_TIMESTAMP, "compress_gz::~gz called"); + if (mode == 'w') + { + z_err = do_flush (Z_FINISH); + if (z_err != Z_OK) + { + destroy (); + return; + } + + putLong (crc); + putLong (stream.total_in); + } + destroy (); + return; +} + +int +compress_gz::do_flush (int flush) +{ + uInt len; + int done = 0; + if (mode != 'w') + return Z_STREAM_ERROR; + stream.avail_in = 0; /* should be zero already anyway */ + for (;;) + { + len = 16384 - stream.avail_out; + if (len != 0) + { + if ((uInt) original->write (outbuf, len) != len) + { + z_err = Z_ERRNO; + return Z_ERRNO; + } + stream.next_out = outbuf; + stream.avail_out = 16384; + } + if (done) + break; + z_err = deflate (&(stream), flush); + /* Ignore the second of two consecutive flushes: */ + if (len == 0 && z_err == Z_BUF_ERROR) + z_err = Z_OK; + /* deflate has finished flushing only when it hasn't used up + * all the available space in the output buffer: + */ + done = (stream.avail_out != 0 || z_err == Z_STREAM_END); + if (z_err != Z_OK && z_err != Z_STREAM_END) + break; + } + return z_err == Z_STREAM_END ? Z_OK : z_err; +} + + +#if 0 + +gzclose (lst); +#endif +/* =========================================================================== + * Read a byte from a gz_stream; update next_in and avail_in. Return EOF + * for end of file. + * IN assertion: the stream s has been sucessfully opened for reading. + */ +int +compress_gz::get_byte () +{ + if (z_eof) + return EOF; + if (stream.avail_in == 0) + { + errno = 0; + stream.avail_in = original->read (inbuf, 16384); + if (stream.avail_in == 0) + { + z_eof = 1; + if (original->error ()) + z_err = Z_ERRNO; + return EOF; + } + stream.next_in = inbuf; + } + stream.avail_in--; + return *(stream.next_in)++; +} + + +/* =========================================================================== + Check the gzip header of a gz_stream opened for reading. Set the stream + mode to transparent if the gzip magic header is not present; set s->err + to Z_DATA_ERROR if the magic header is present but the rest of the header + is incorrect. + IN assertion: the stream s has already been created sucessfully; + s->stream.avail_in is zero for the first time, but may be non-zero + for concatenated .gz files. +*/ +void +compress_gz::check_header () +{ + int method; /* method byte */ + int flags; /* flags byte */ + uInt len; + int c; + /* Check the gzip magic header */ + for (len = 0; len < 2; len++) + { + c = get_byte (); + if (c != gz_magic[len]) + { + if (len != 0) + stream.avail_in++, stream.next_in--; + if (c != EOF) + { + stream.avail_in++, stream.next_in--; + transparent = 1; + } + z_err = stream.avail_in != 0 ? Z_OK : Z_STREAM_END; + return; + } + } + method = get_byte (); + flags = get_byte (); + if (method != Z_DEFLATED || (flags & RESERVED) != 0) + { + z_err = Z_DATA_ERROR; + return; + } + + /* Discard time, xflags and OS code: */ + for (len = 0; len < 6; len++) + (void) get_byte (); + if ((flags & EXTRA_FIELD) != 0) + { /* skip the extra field */ + len = (uInt) get_byte (); + len += ((uInt) get_byte ()) << 8; + /* len is garbage if EOF but the loop below will quit anyway */ + while (len-- != 0 && get_byte () != EOF); + } + if ((flags & ORIG_NAME) != 0) + { /* skip the original file name */ + while ((c = get_byte ()) != 0 && c != EOF); + } + if ((flags & COMMENT) != 0) + { /* skip the .gz file comment */ + while ((c = get_byte ()) != 0 && c != EOF); + } + if ((flags & HEAD_CRC) != 0) + { /* skip the header crc */ + for (len = 0; len < 2; len++) + (void) get_byte (); + } + z_err = z_eof ? Z_DATA_ERROR : Z_OK; +} diff --git a/compress_gz.h b/compress_gz.h new file mode 100644 index 00000000..38bf1ed6 --- /dev/null +++ b/compress_gz.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2001, Robert Collins. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +#ifndef _COMPRESS_GZ_H_ +#define _COMPRESS_GZ_H_ + +/* this is the parent class for all compress IO operations. + * It + */ + +class compress_gz:public compress +{ +public: + /* assumes decompression */ + compress_gz (io_stream *); + /* the mode allows control, but this implementation only does compression */ + compress_gz (io_stream *, const char *); + /* read data (duh!) */ + virtual ssize_t read (void *buffer, size_t len); + /* provide data to (double duh!) */ + virtual ssize_t write (void *buffer, size_t len); + /* read data without removing it from the class's internal buffer */ + virtual ssize_t peek (void *buffer, size_t len); + virtual long tell (); + /* try guessing this one */ + virtual int error (); + /* Find out the next stream name - + * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar + * for foobar that is an compress, next_file_name is the next + * extractable filename. + */ + virtual const char *next_file_name () + { + return NULL; + }; + virtual int set_mtime (int); + virtual int get_mtime (); + /* if you are still needing these hints... give up now! */ + virtual ~ compress_gz (); +private: + compress_gz () + { + }; + char peekbuf[512]; + size_t peeklen; + void construct (io_stream *, const char *); + void check_header (); + int get_byte (); + unsigned long getLong (); + void putLong (unsigned long); + void destroy (); + int do_flush (int); + io_stream *original; + /* from zlib */ + z_stream stream; + int z_err; /* error code for last stream operation */ + int z_eof; /* set if end of input file */ + unsigned char *inbuf; /* input buffer */ + unsigned char *outbuf; /* output buffer */ + uLong crc; /* crc32 of uncompressed data */ + char *msg; /* error message */ + int transparent; /* 1 if input file is not a .gz file */ + char mode; /* 'w' or 'r' */ + long startpos; /* start of compressed data in file (header skipped) */ +}; + +#endif /* _COMPRESS_GZ_H_ */ diff --git a/concat.cc b/concat.cc index 96c6900f..0f49c038 100644 --- a/concat.cc +++ b/concat.cc @@ -16,7 +16,11 @@ /* See concat.h. Note that we canonicalize the result, this avoids multiple slashes being interpreted as UNCs. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif + #include #include @@ -61,12 +65,12 @@ vconcat (const char *s, va_list v) strcpy (rv, s); v = save_v; while (1) - { - arg = va_arg (v, char *); - if (arg == 0) - break; - strcat (rv, arg); - } + { + arg = va_arg (v, char *); + if (arg == 0) + break; + strcat (rv, arg); + } va_end (v); char *d, *p; diff --git a/concat.h b/concat.h index a9038c29..257b5507 100644 --- a/concat.h +++ b/concat.h @@ -20,12 +20,12 @@ name or URL, and will canonicalize the result accordingly (i.e. replace \ with /, collapse multiple /// to a single /, etc.) */ -char * concat (const char *s, ...); -char * vconcat (const char *, va_list); +char *concat (const char *s, ...); +char *vconcat (const char *, va_list); /* convert slashes to backslashes */ -char * backslash (char *s); +char *backslash (char *s); /* Used when treating / and \ as equivalent. */ #define SLASH_P(ch) \ diff --git a/desktop.cc b/desktop.cc index 70766f58..44955cb0 100644 --- a/desktop.cc +++ b/desktop.cc @@ -18,7 +18,10 @@ that unlike other do_* functions, this one is called directly from install.cc */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include @@ -39,9 +42,7 @@ static char *cvsid = "\n%%% $Id$\n"; #include "port.h" -extern "C" { - void make_link_2 (char *exepath, char *args, char *icon, char *lname); -}; +#include "mklink2.h" static OSVERSIONINFO verinfo; @@ -53,7 +54,7 @@ static OSVERSIONINFO verinfo; @* */ -static char *etc_profile[] = { +static const char *etc_profile[] = { "PATH=\"/usr/local/bin:/usr/bin:/bin:$PATH\"", "", "USER=\"`id -un`\"", @@ -93,79 +94,83 @@ static char *batname; static char *iconname; static void -make_link (char *linkpath, char *title, char *target) +make_link (const char *linkpath, const char *title, const char *target) { char argbuf[_MAX_PATH]; char *fname = concat (linkpath, "/", title, ".lnk", 0); if (_access (fname, 0) == 0) - return; /* already exists */ + return; /* already exists */ msg ("make_link %s, %s, %s\n", fname, title, target); mkdir_p (0, fname); - char *exepath, *args; + char *exepath; /* If we are running Win9x, build a command line. */ if (verinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) { - exepath = target; - args = ""; + exepath = concat (target, 0); + sprintf (argbuf, " "); } else { - char *pccmd; char windir[MAX_PATH]; GetWindowsDirectory (windir, sizeof (windir)); exepath = concat (windir, COMMAND9XEXE, 0); sprintf (argbuf, "%s %s", COMMAND9XARGS, target); - args = argbuf; } - msg ("make_link_2 (%s, %s, %s, %s)", exepath, args, iconname, fname); - make_link_2 (exepath, args, iconname, fname); + msg ("make_link_2 (%s, %s, %s, %s)", exepath, argbuf, iconname, fname); + make_link_2 (exepath, argbuf, iconname, fname); } static void -start_menu (char *title, char *target) +start_menu (const char *title, const char *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); + 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) { - SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id); - SHGetPathFromIDList (id, path); - msg("Program directory for program link changed to: %s",path); - } + msg ("Program directory for program link: %s", path); + if (strlen (path) == 0) + { + SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id); + SHGetPathFromIDList (id, path); + msg ("Program directory for program link changed to: %s", path); + } // end of Win95 addition strcat (path, "/Cygwin"); make_link (path, title, target); } static void -desktop_icon (char *title, char *target) +desktop_icon (const char *title, const char *target) { char path[_MAX_PATH]; LPITEMIDLIST id; int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0; //SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_DESKTOP : CSIDL_COMMON_DESKTOPDIRECTORY, &id); - SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_DESKTOPDIRECTORY : CSIDL_DESKTOPDIRECTORY, &id); + SHGetSpecialFolderLocation (NULL, + issystem ? CSIDL_COMMON_DESKTOPDIRECTORY : + CSIDL_DESKTOPDIRECTORY, &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("Desktop directory for desktop link: %s",path); - if ( strlen(path) == 0) { - SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id); - SHGetPathFromIDList (id, path); - msg("Desktop directory for deskop link changed to: %s",path); - } + msg ("Desktop directory for desktop link: %s", path); + if (strlen (path) == 0) + { + SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id); + SHGetPathFromIDList (id, path); + msg ("Desktop directory for deskop link changed to: %s", path); + } // end of Win95 addition make_link (path, title, target); } @@ -186,7 +191,8 @@ make_cygwin_bat () fprintf (bat, "@echo off\n\n"); fprintf (bat, "%.2s\n", get_root_dir ()); - fprintf (bat, "chdir %s\n\n", backslash (concat (get_root_dir () + 2, "/bin", 0))); + fprintf (bat, "chdir %s\n\n", + backslash (concat (get_root_dir () + 2, "/bin", 0))); fprintf (bat, "bash --login -i\n"); @@ -205,18 +211,18 @@ make_etc_profile () char os; switch (verinfo.dwPlatformId) { - case VER_PLATFORM_WIN32_NT: - os = 'N'; - break; - case VER_PLATFORM_WIN32_WINDOWS: - if (verinfo.dwMinorVersion == 0) - os = '5'; - else - os = '8'; - break; - default: - os = '?'; - break; + case VER_PLATFORM_WIN32_NT: + os = 'N'; + break; + case VER_PLATFORM_WIN32_WINDOWS: + if (verinfo.dwMinorVersion == 0) + os = '5'; + else + os = '8'; + break; + default: + os = '?'; + break; } msg ("os is %c", os); @@ -224,14 +230,14 @@ make_etc_profile () if (!p) return; - int i, allow=1; - for (i=0; etc_profile[i]; i++) + int i, allow = 1; + for (i = 0; etc_profile[i]; i++) { if (etc_profile[i][0] == '@') { allow = 0; msg ("profile: %s", etc_profile[i]); - for (char *cp = etc_profile[i]+1; *cp; cp++) + for (const char *cp = etc_profile[i] + 1; *cp; cp++) if (*cp == os || *cp == '*') allow = 1; msg ("allow is %d\n", allow); @@ -244,7 +250,7 @@ make_etc_profile () } static int -uexists (char *path) +uexists (const char *path) { char *f = cygpath (path, 0); int a = _access (f, 0); @@ -266,12 +272,12 @@ make_passwd_group () if (verinfo.dwPlatformId != VER_PLATFORM_WIN32_NT) { Package *pkg = getpkgbyname ("cygwin"); - if (pkg && is_download_action (pkg) && - pkg->action != ACTION_SRC_ONLY) + if (pkg && is_download_action (pkg) && pkg->action != ACTION_SRC_ONLY) { /* 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 = canonicalize_version (pkg->info[pkg->trust].version); + char *inst_version = + canonicalize_version (pkg->info[pkg->trust].version); if (strcmp (inst_version, border_version) <= 0) goto out; } @@ -285,7 +291,7 @@ make_passwd_group () if (!uexists ("/etc/group")) fprintf (p, "bin\\mkgroup -l > etc\\group\n"); - out: +out: fclose (p); } @@ -312,7 +318,7 @@ save_icon () } static void -do_desktop_setup() +do_desktop_setup () { save_icon (); @@ -320,13 +326,15 @@ do_desktop_setup() make_etc_profile (); make_passwd_group (); - if (root_menu) { - start_menu ("Cygwin Bash Shell", batname); - } + if (root_menu) + { + start_menu ("Cygwin Bash Shell", batname); + } - if (root_desktop) { - desktop_icon ("Cygwin", batname); - } + if (root_desktop) + { + desktop_icon ("Cygwin", batname); + } } static int da[] = { IDC_ROOT_DESKTOP, 0 }; @@ -346,61 +354,69 @@ load_dialog (HWND h) check_if_enable_next (h); } -static int check_desktop (char *title, char *target) +static int +check_desktop (const char *title, const char *target) { char path[_MAX_PATH]; LPITEMIDLIST id; int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0; - SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_DESKTOPDIRECTORY : CSIDL_DESKTOPDIRECTORY, &id); + SHGetSpecialFolderLocation (NULL, + issystem ? CSIDL_COMMON_DESKTOPDIRECTORY : + CSIDL_DESKTOPDIRECTORY, &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 ("Desktop directory for desktop link: %s",path); - if (strlen (path) == 0) { - SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id); - SHGetPathFromIDList (id, path); - msg ("Desktop directory for deskop link changed to: %s",path); - } + msg ("Desktop directory for desktop link: %s", path); + if (strlen (path) == 0) + { + SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id); + SHGetPathFromIDList (id, path); + msg ("Desktop directory for deskop link changed to: %s", path); + } // end of Win95 addition char *fname = concat (path, "/", title, ".lnk", 0); if (_access (fname, 0) == 0) - return 0; /* already exists */ + return 0; /* already exists */ - fname = concat (path, "/", title, ".pif", 0); /* check for a pif as well */ + fname = concat (path, "/", title, ".pif", 0); /* check for a pif as well */ if (_access (fname, 0) == 0) - return 0; /* already exists */ + return 0; /* already exists */ return IDC_ROOT_DESKTOP; } -static int check_startmenu (char *title, char *target) +static int +check_startmenu (const char *title, const char *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); + 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) { - SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id); - SHGetPathFromIDList (id, path); - msg ("Program directory for program link changed to: %s",path); - } + msg ("Program directory for program link: %s", path); + if (strlen (path) == 0) + { + SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id); + SHGetPathFromIDList (id, path); + msg ("Program directory for program link changed to: %s", path); + } // end of Win95 addition strcat (path, "/Cygwin"); char *fname = concat (path, "/", title, ".lnk", 0); if (_access (fname, 0) == 0) - return 0; /* already exists */ + return 0; /* already exists */ - fname = concat (path, "/", title, ".pif", 0); /* check for a pif as well */ + fname = concat (path, "/", title, ".pif", 0); /* check for a pif as well */ if (_access (fname, 0) == 0) - return 0; /* already exists */ + return 0; /* already exists */ return IDC_ROOT_MENU; } @@ -408,7 +424,7 @@ static int check_startmenu (char *title, char *target) static void save_dialog (HWND h) { - root_desktop= rbget (h, da); + root_desktop = rbget (h, da); root_menu = rbget (h, ma); } @@ -426,7 +442,7 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) case IDOK: save_dialog (h); - do_desktop_setup(); + do_desktop_setup (); NEXT (IDD_S_POSTINSTALL); break; @@ -439,6 +455,7 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) NEXT (0); break; } + return 0; } static BOOL CALLBACK @@ -463,8 +480,11 @@ do_desktop (HINSTANCE h) verinfo.dwOSVersionInfoSize = sizeof (verinfo); GetVersionEx (&verinfo); - root_desktop = check_desktop("Cygwin",backslash (cygpath ("/cygwin.bat", 0))); - root_menu = check_startmenu("Cygwin Bash Shell",backslash (cygpath ("/cygwin.bat", 0))); + root_desktop = + check_desktop ("Cygwin", backslash (cygpath ("/cygwin.bat", 0))); + root_menu = + check_startmenu ("Cygwin Bash Shell", + backslash (cygpath ("/cygwin.bat", 0))); int rv = 0; diff --git a/dialog.cc b/dialog.cc index 824edd12..646b7a65 100644 --- a/dialog.cc +++ b/dialog.cc @@ -16,7 +16,10 @@ /* The purpose of this file is to provide common functionality for all the dialogs in the program. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include @@ -60,14 +63,14 @@ eset (HWND h, int id, const char *val) void eset (HWND h, int id, int val) { - SetDlgItemInt (h, id, (UINT)val, TRUE); + SetDlgItemInt (h, id, (UINT) val, TRUE); } int rbget (HWND h, int *ids) { int i; - for (i=0; ids[i]; i++) + for (i = 0; ids[i]; i++) if (IsDlgButtonChecked (h, ids[i]) == BST_CHECKED) return ids[i]; return 0; @@ -77,22 +80,17 @@ void rbset (HWND h, int *ids, int id) { int i; - for (i=0; ids[i]; i++) - CheckDlgButton (h, ids[i], id==ids[i] ? BST_CHECKED : BST_UNCHECKED); + for (i = 0; ids[i]; i++) + CheckDlgButton (h, ids[i], id == ids[i] ? BST_CHECKED : BST_UNCHECKED); } void -fatal (char *msg) +fatal (const char *msg) { DWORD e = GetLastError (); char *buf; FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - 0, - e, - 0, - (CHAR *)&buf, - 0, - 0); + 0, e, 0, (CHAR *) & buf, 0, 0); MessageBox (0, buf, msg, 0); exit_setup (1); } diff --git a/dialog.h b/dialog.h index 8c6af891..810d5f20 100644 --- a/dialog.h +++ b/dialog.h @@ -26,20 +26,20 @@ extern int exit_msg; /* prototypes for all the do_* functions (most called by main.cc) */ -D(do_choose); -D(do_desktop); -D(do_download); -D(do_fromcwd); -D(do_ini); -D(do_install); -D(do_local_dir); -D(do_net); -D(do_other); -D(do_postinstall); -D(do_root); -D(do_site); -D(do_source); -D(do_splash); +D (do_choose); +D (do_desktop); +D (do_download); +D (do_fromcwd); +D (do_ini); +D (do_install); +D (do_local_dir); +D (do_net); +D (do_other); +D (do_postinstall); +D (do_root); +D (do_site); +D (do_source); +D (do_splash); #undef D @@ -48,25 +48,25 @@ D(do_splash); /* Get the value of an EditText control. Pass the previously stored value and it will free the memory if needed. */ - + char *eget (HWND h, int id, char *var); /* Same, but convert the value to an integer */ -int eget (HWND h, int id); +int eget (HWND h, int id); /* Set the EditText control to the given string or integer */ -void eset (HWND h, int id, const char *var); -void eset (HWND h, int id, int var); +void eset (HWND h, int id, const char *var); +void eset (HWND h, int id, int var); /* RadioButtons. ids is a null-terminated list of IDs. Get returns the selected ID (or zero), pass an ID to set */ -int rbget (HWND h, int *ids); -void rbset (HWND h, int *ids, int id); +int rbget (HWND h, int *ids); +void rbset (HWND h, int *ids, int id); /* *This* version of fatal (compare with msg.h) uses GetLastError() to format a suitable error message. Similar to perror() */ -void fatal (char *msg); +void fatal (const char *msg) __attribute__ ((noreturn)); diff --git a/diskfull.cc b/diskfull.cc index 72ac50e7..70294335 100644 --- a/diskfull.cc +++ b/diskfull.cc @@ -18,14 +18,17 @@ handle disks bigger than 2G, and a new API that isn't always available. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include "diskfull.h" -typedef BOOL WINAPI (*GDFS)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, - PULARGE_INTEGER); +typedef BOOL WINAPI (*GDFS) (LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, + PULARGE_INTEGER); int diskfull (const char *path) @@ -43,7 +46,7 @@ diskfull (const char *path) if (gdfs (path, &avail, &total, &free)) { int perc = avail.QuadPart * 100 / total.QuadPart; - return 100-perc; + return 100 - perc; } } } @@ -62,7 +65,7 @@ diskfull (const char *path) if (GetDiskFreeSpace (root, &junk, &junk, &free_clusters, &total_clusters)) { int perc = free_clusters * 100 / total_clusters; - return 100-perc; + return 100 - perc; } return 0; diff --git a/download.cc b/download.cc index 75704ba9..872eb64c 100644 --- a/download.cc +++ b/download.cc @@ -16,7 +16,10 @@ /* The purpose of this file is to download all the files we need to do the installation. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" @@ -34,8 +37,7 @@ static char *cvsid = "\n%%% $Id$\n"; #include "log.h" #include "port.h" -DWORD -get_file_size (const char *name) +DWORD get_file_size (const char *name) { HANDLE h; WIN32_FIND_DATA buf; @@ -52,22 +54,20 @@ get_file_size (const char *name) } static int -download_one (char *name, int expected_size, int action) +download_one (char *name, unsigned int expected_size, int action) { char *local = name; - int errors = 0; DWORD size; if ((size = get_file_size (local)) > 0) if (size == expected_size && action != ACTION_SRC_ONLY - && action != ACTION_REDO ) + && action != ACTION_REDO) return 0; mkdir_p (0, local); if (get_url_to_file (concat (MIRROR_SITE, "/", name, 0), - concat (local, ".tmp", 0), - expected_size)) + concat (local, ".tmp", 0), expected_size)) { note (IDS_DOWNLOAD_FAILED, name); return 1; @@ -78,13 +78,13 @@ download_one (char *name, int expected_size, int action) if (size == expected_size) { log (0, "Downloaded %s", local); - if ( _access (local , 0) == 0) - remove ( local ); + if (_access (local, 0) == 0) + remove (local); rename (concat (local, ".tmp", 0), local); } else { - log (0, "Download %s wrong size (%d actual vs %d expected)", + log (0, "Download %s wrong size (%ld actual vs %d expected)", local, size, expected_size); note (IDS_DOWNLOAD_SHORT, local, size, expected_size); return 1; @@ -97,30 +97,27 @@ download_one (char *name, int expected_size, int action) void do_download (HINSTANCE h) { - int i; int errors = 0; total_download_bytes = 0; total_download_bytes_sofar = 0; - for (Package *pkg = package; pkg->name; pkg++) + for (Package * pkg = package; pkg->name; pkg++) if (is_download_action (pkg)) { Info *pi = pkg->info + pkg->trust; DWORD size = get_file_size (pi->install); char *local = pi->install; if (pkg->action != ACTION_SRC_ONLY && - (pkg->action == ACTION_REDO || - size != pi->install_size)) + (pkg->action == ACTION_REDO || size != pi->install_size)) total_download_bytes += pi->install_size; local = pi->source; size = get_file_size (pi->source); if (pkg->srcpicked && - (pkg->action == ACTION_SRC_ONLY || - size != pi->source_size)) + (pkg->action == ACTION_SRC_ONLY || size != pi->source_size)) total_download_bytes += pi->source_size; } - for (Package *pkg = package; pkg->name; pkg++) + for (Package * pkg = package; pkg->name; pkg++) if (is_download_action (pkg)) { int e = 0; diff --git a/filemanip.h b/filemanip.h index 496968fb..fecb800d 100644 --- a/filemanip.h +++ b/filemanip.h @@ -22,8 +22,9 @@ typedef struct char ver[MAX_PATH + 1]; char tail[MAX_PATH + 1]; char what[16]; -} fileparse; +} +fileparse; -int parse_filename (const char *in_fn, fileparse& f); +int parse_filename (const char *in_fn, fileparse & f); char *base (const char *name); DWORD get_file_size (const char *name); diff --git a/find.cc b/find.cc index 511c25a7..c91de52e 100644 --- a/find.cc +++ b/find.cc @@ -16,7 +16,10 @@ /* The purpose of this file is to doa recursive find on a given directory, calling a given function for each file found. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include @@ -24,7 +27,7 @@ static char *cvsid = "\n%%% $Id$\n"; #include "port.h" -static void (*for_each)(char *, unsigned int); +static void (*for_each) (char *, unsigned int); static char dir[_MAX_PATH], *found_part; static int @@ -43,29 +46,31 @@ find_sub () if (h == INVALID_HANDLE_VALUE) return 0; - do { - if (strcmp (wfd.cFileName, ".") == 0 - || strcmp (wfd.cFileName, "..") == 0) - continue; + do + { + if (strcmp (wfd.cFileName, ".") == 0 + || strcmp (wfd.cFileName, "..") == 0) + continue; - strcpy (end, wfd.cFileName); + strcpy (end, wfd.cFileName); - if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - find_sub (); - else - { - for_each (found_part, wfd.nFileSizeLow); - rv++; - } + if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + find_sub (); + else + { + for_each (found_part, wfd.nFileSizeLow); + rv++; + } - } while (FindNextFile (h, &wfd)); + } + while (FindNextFile (h, &wfd)); FindClose (h); return rv; } int -find (char *starting_dir, void (*_for_each)(char *, unsigned int)) +find (const char *starting_dir, void (*_for_each) (char *, unsigned int)) { strcpy (dir, starting_dir); for_each = _for_each; diff --git a/find.h b/find.h index 4c389130..05904298 100644 --- a/find.h +++ b/find.h @@ -19,4 +19,5 @@ (bytes). find() returns the number of files found. Directories are scanned but not included in the "found" files. */ -extern int find (char *starting_dir, void (*for_each)(char *, unsigned int)); +extern int find (const char *starting_dir, + void (*for_each) (char *, unsigned int)); diff --git a/fromcwd.cc b/fromcwd.cc index 14113bf1..5ca05c26 100644 --- a/fromcwd.cc +++ b/fromcwd.cc @@ -26,7 +26,8 @@ that we search recursively. */ #if 0 -static const char *cvsid = "\n%%% $Id$\n"; +static const char *cvsid = + "\n%%% $Id$\n"; #endif #include "win32.h" @@ -53,7 +54,7 @@ static int is_test_version (char *v) { int i; - for (i=0; v[i] && isdigit (v[i]); i++) ; + for (i = 0; v[i] && isdigit (v[i]); i++); return (i >= 6) ? 1 : 0; } @@ -62,19 +63,19 @@ canonicalize_version (const char *v) { static char nv[3][100]; static int idx = 0; - char *np ; + char *np; const char *dp; int i; - idx = (idx+1) % 3; + idx = (idx + 1) % 3; np = nv[idx]; while (*v) { if (isdigit (*v)) { - for (dp=v; *dp && isdigit (*dp); dp++) ; - for (i=dp-v; i<12; i++) + for (dp = v; *dp && isdigit (*dp); dp++); + for (i = dp - v; i < 12; i++) *np++ = '0'; while (v < dp) *np++ = *v++; @@ -106,7 +107,7 @@ found_file (char *path, unsigned int fsize) } if (p == NULL) - p = new_package (f.pkg); + p = new_package (f.pkg); int trust = is_test_version (f.ver) ? TRUST_TEST : TRUST_CURR; @@ -120,11 +121,11 @@ found_file (char *path, unsigned int fsize) } if (p->info[trust].version) - free(p->info[trust].version); + free (p->info[trust].version); p->info[trust].version = _strdup (f.ver); if (p->info[trust].install) - free(p->info[trust].install); + free (p->info[trust].install); p->info[trust].install = _strdup (path); p->info[trust].install_size = fsize; @@ -150,7 +151,7 @@ do_fromcwd (HINSTANCE h) char srcpath[_MAX_PATH]; for (i = 0; i < npackages; i++) { - p = package+i; + p = package + i; for (t = TRUST_PREV; t <= TRUST_TEST; t++) if (p->info[t].install) { @@ -168,7 +169,7 @@ do_fromcwd (HINSTANCE h) } if (h != INVALID_HANDLE_VALUE) { - msg("-- got it"); + msg ("-- got it"); FindClose (h); p->info[t].source = _strdup (srcpath); p->info[t].source_size = wfd.nFileSizeLow; diff --git a/geturl.cc b/geturl.cc index b1842c91..5b126213 100644 --- a/geturl.cc +++ b/geturl.cc @@ -17,7 +17,10 @@ netio.cc. We add a progress dialog and some convenience functions (like collect to string or file */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include "commctrl.h" @@ -60,13 +63,12 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) case IDCANCEL: exit_setup (0); } + return 0; } static BOOL CALLBACK dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam) { - int i, j; - HWND listbox; switch (message) { case WM_INITDIALOG: @@ -90,16 +92,18 @@ dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam) static WINAPI DWORD dialog (void *) { - int rv = 0; MSG m; - HWND local_gw_dialog = CreateDialog (hinstance, MAKEINTRESOURCE (IDD_DLSTATUS), - 0, dialog_proc); + HWND local_gw_dialog = + CreateDialog (hinstance, MAKEINTRESOURCE (IDD_DLSTATUS), + 0, dialog_proc); ShowWindow (local_gw_dialog, SW_SHOWNORMAL); UpdateWindow (local_gw_dialog); - while (GetMessage (&m, 0, 0, 0) > 0) { - TranslateMessage (&m); - DispatchMessage (&m); - } + while (GetMessage (&m, 0, 0, 0) > 0) + { + TranslateMessage (&m); + DispatchMessage (&m); + } + return 0; } static DWORD start_tics; @@ -121,16 +125,16 @@ init_dialog (char *url, int length) SendMessage (gw_pprogress, PBM_SETRANGE, 0, MAKELPARAM (0, 100)); SendMessage (gw_iprogress, PBM_SETRANGE, 0, MAKELPARAM (0, 100)); } - char *sl=url, *cp; - for (cp=url; *cp; cp++) + char *sl = url, *cp; + for (cp = url; *cp; cp++) if (*cp == '/' || *cp == '\\' || *cp == ':') - sl = cp+1; + sl = cp + 1; max_bytes = length; SetWindowText (gw_url, sl); SetWindowText (gw_rate, "Connecting..."); SendMessage (gw_progress, PBM_SETPOS, (WPARAM) 0, 0); ShowWindow (gw_progress, (length > 0) ? SW_SHOW : SW_HIDE); - if (length > 0 ) + if (length > 0) SetWindowText (gw_progress_text, "Package"); else SetWindowText (gw_progress_text, " "); @@ -160,9 +164,9 @@ progress (int bytes) int kbps; static unsigned int last_tics = 0; DWORD tics = GetTickCount (); - if (tics == start_tics) // to prevent division by zero + if (tics == start_tics) // to prevent division by zero return; - if (tics < last_tics + 200) // to prevent flickering updates + if (tics < last_tics + 200) // to prevent flickering updates return; last_tics = tics; @@ -175,13 +179,14 @@ progress (int bytes) int perc = bytes / (max_bytes / 100); SendMessage (gw_progress, PBM_SETPOS, (WPARAM) perc, 0); sprintf (buf, "%3d %% (%dk/%dk) %d kb/s\n", - perc, bytes/1000, max_bytes/1000, kbps); + perc, bytes / 1000, max_bytes / 1000, kbps); if (total_download_bytes > 0) - { - int totalperc = (total_download_bytes_sofar + bytes) / ( - total_download_bytes / 100); - SendMessage (gw_pprogress, PBM_SETPOS, (WPARAM) totalperc, 0); - } + { + int totalperc = + (total_download_bytes_sofar + + bytes) / (total_download_bytes / 100); + SendMessage (gw_pprogress, PBM_SETPOS, (WPARAM) totalperc, 0); + } } else sprintf (buf, "%d %d kb/s\n", bytes, kbps); @@ -189,7 +194,8 @@ progress (int bytes) SetWindowText (gw_rate, buf); } -struct GUBuf { +struct GUBuf +{ GUBuf *next; int count; char buf[2000]; @@ -214,7 +220,7 @@ get_url_to_string (char *_url) GUBuf *bufs = 0; GUBuf **nextp = &bufs; - int total_bytes = 1; /* for the NUL */ + int total_bytes = 1; /* for the NUL */ progress (0); while (1) { @@ -265,7 +271,7 @@ get_url_to_file (char *_url, char *_filename, int expected_length, } init_dialog (_url, expected_length); - remove (_filename); /* but ignore errors */ + remove (_filename); /* but ignore errors */ NetIO *n = NetIO::open (_url, allow_ftp_auth); if (!n || !n->ok ()) @@ -278,7 +284,7 @@ get_url_to_file (char *_url, char *_filename, int expected_length, FILE *f = fopen (_filename, "wb"); if (!f) { - char *err = strerror (errno); + const char *err = strerror (errno); if (!err) err = "(unknown error)"; fatal (IDS_ERR_OPEN_WRITE, _filename, err); diff --git a/geturl.h b/geturl.h index 5256a607..20ac573c 100644 --- a/geturl.h +++ b/geturl.h @@ -19,7 +19,7 @@ extern int total_download_bytes; extern int total_download_bytes_sofar; -char *get_url_to_string (char *_url); -int get_url_to_file (char *_url, char *_filename, int expected_size, - BOOL allow_ftp_auth = FALSE); -void dismiss_url_status_dialog (); +char *get_url_to_string (char *_url); +int get_url_to_file (char *_url, char *_filename, int expected_size, + BOOL allow_ftp_auth = FALSE); +void dismiss_url_status_dialog (); diff --git a/hash.cc b/hash.cc index a465fd86..22603313 100644 --- a/hash.cc +++ b/hash.cc @@ -15,14 +15,18 @@ /* Simple hash class for install.cc */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include #include #include "hash.h" -class hash_internals { +class hash_internals +{ public: char **keys; int numkeys; @@ -50,7 +54,7 @@ void hash::add (char *string) { int i; - for (i=0; inumkeys; i++) + for (i = 0; i < h->numkeys; i++) if (strcmp (h->keys[i], string) == 0) return; if (h->numkeys >= h->maxkeys) @@ -60,7 +64,7 @@ hash::add (char *string) } h->keys[h->numkeys] = _strdup (string); - h->numkeys ++; + h->numkeys++; } @@ -68,7 +72,7 @@ int hash::has (char *string) { int i; - for (i=0; inumkeys; i++) + for (i = 0; i < h->numkeys; i++) if (strcmp (h->keys[i], string) == 0) return 1; return 0; @@ -79,7 +83,7 @@ hash::enumerate (char *prev) { if (prev == 0) h->prev_index = -1; - h->prev_index ++; + h->prev_index++; if (h->prev_index >= h->numkeys) return 0; return h->keys[h->prev_index]; @@ -88,8 +92,8 @@ hash::enumerate (char *prev) static int rev_len (const void *va, const void *vb) { - char *a = *(char **)va; - char *b = *(char **)vb; + char *a = *(char **) va; + char *b = *(char **) vb; return strcmp (b, a); } diff --git a/hash.h b/hash.h index 2f5407ae..6a280890 100644 --- a/hash.h +++ b/hash.h @@ -17,11 +17,12 @@ class hash_internals; -class hash { +class hash +{ hash_internals *h; - public: - hash (); - ~hash (); +public: + hash (); + ~hash (); void add (char *string); int has (char *string); @@ -30,5 +31,5 @@ class hash { void add_subdirs (char *path); void reverse_sort (); - char *enumerate (char *prev=0); + char *enumerate (char *prev = 0); }; diff --git a/ini.cc b/ini.cc index d99cfc3c..02c826b0 100644 --- a/ini.cc +++ b/ini.cc @@ -18,7 +18,10 @@ flex parsers are provided also. We check to see if this setup.ini is older than the one we used last time, and if so, warn the user. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" @@ -33,11 +36,12 @@ static char *cvsid = "\n%%% $Id$\n"; #include "geturl.h" #include "dialog.h" #include "msg.h" -#include "mkdir.h" #include "log.h" #include "version.h" #include "mount.h" +#include "io_stream.h" + unsigned int setup_timestamp = 0; char *setup_version = 0; @@ -68,7 +72,7 @@ do_ini (HINSTANCE h) ini_init (ini_file); setup_timestamp = 0; - /*yydebug = 1;*/ + /*yydebug = 1; */ if (yyparse () || error_count > 0) { @@ -80,24 +84,28 @@ do_ini (HINSTANCE h) else { /* save known-good setup.ini locally */ - FILE *inif = fopen ("setup.ini", "wb"); - if (inif) + io_stream *inistream = io_stream::open ("file://setup.ini", "wb"); + if (inistream) { - fwrite (ini_file, 1, strlen (ini_file), inif); - fclose (inif); + inistream->write (ini_file, strlen (ini_file)); + delete inistream; } } if (get_root_dir ()) { - mkdir_p (1, cygpath ("/etc/setup", 0)); + io_stream::mkpath_p (PATH_TO_DIR, "cygfile:///etc/setup"); unsigned int old_timestamp = 0; - FILE *ots = fopen (cygpath ("/etc/setup/timestamp", 0), "rt"); + io_stream *ots = + io_stream::open ("cygfile:///etc/setup/timestamp", "rt"); if (ots) { - fscanf (ots, "%u", &old_timestamp); - fclose (ots); + char temp[20]; + memset (temp, '\0', 20); + if (ots->read (temp, 19)) + sscanf (temp, "%u", &old_timestamp); + delete ots; if (old_timestamp && setup_timestamp && (old_timestamp > setup_timestamp)) { @@ -108,16 +116,20 @@ do_ini (HINSTANCE h) } if (setup_timestamp) { - FILE *nts = fopen (cygpath ("/etc/setup/timestamp", 0), "wt"); + io_stream *nts = + io_stream::open ("cygfile:///etc/setup/timestamp", "wt"); if (nts) { - fprintf (nts, "%u", setup_timestamp); - fclose (nts); + char temp[20]; + sprintf (temp, "%u", setup_timestamp); + nts->write (temp, strlen (temp)); + delete nts; } } } - msg ("setup_version is %s, our_version is %s", setup_version?:"(null)", version); + msg ("setup_version is %s, our_version is %s", setup_version ? : "(null)", + version); if (setup_version) { char *ini_version = canonicalize_version (setup_version); @@ -131,7 +143,8 @@ do_ini (HINSTANCE h) extern int yylineno; -extern "C" int yyerror (char *s, ...) +extern "C" int +yyerror (char *s, ...) { char buf[1000]; int len; @@ -154,14 +167,16 @@ extern "C" int yyerror (char *s, ...) strcpy (error_buf, buf); } error_count++; + /* TODO: is return 0 correct? */ + return 0; } -extern "C" int fprintf (FILE *f, const char *s, ...); +extern "C" int fprintf (FILE * f, const char *s, ...); static char stderrbuf[1000]; int -fprintf (FILE *f, const char *fmt, ...) +fprintf (FILE * f, const char *fmt, ...) { char buf[1000]; int rv; @@ -174,7 +189,7 @@ fprintf (FILE *f, const char *fmt, ...) if (char *nl = strchr (stderrbuf, '\n')) { *nl = 0; - /*OutputDebugString (stderrbuf);*/ + /*OutputDebugString (stderrbuf); */ MessageBox (0, buf, "Cygwin Setup", 0); stderrbuf[0] = 0; } diff --git a/ini.h b/ini.h index 74d04f33..9aff36d6 100644 --- a/ini.h +++ b/ini.h @@ -41,14 +41,16 @@ typedef enum TRUST_CURR, TRUST_TEST, NTRUST -} trusts; +} +trusts; typedef enum { EXCLUDE_NONE = 0, EXCLUDE_BY_SETUP, EXCLUDE_NOT_FOUND -} excludes; +} +excludes; #define is_download_action(pkg) \ ((pkg)->action == ACTION_PREV || \ @@ -75,55 +77,58 @@ typedef enum #define SRCACTION_YES 1 typedef struct _Info { - char *version; /* version part of filename */ - char *install; /* file name to install */ + char *version; /* version part of filename */ + char *install; /* file name to install */ unsigned int install_size; /* in bytes */ - int install_exists; /* install file exists on disk */ - int derived; /* True if we "figured out" that this version should - go here but it was not in setup.ini */ - char *source; /* sources for installed binaries */ + int install_exists; /* install file exists on disk */ + int derived; /* True if we "figured out" that this version should + go here but it was not in setup.ini */ + char *source; /* sources for installed binaries */ unsigned int source_size; /* in bytes */ - int source_exists; /* source file exists on disk */ + int source_exists; /* source file exists on disk */ #ifdef __cplusplus - _Info (const char *_install, const char *_version, - int _install_size, const char *_source = NULL, - int _source_size = 0); + _Info (const char *_install, const char *_version, + int _install_size, const char *_source = NULL, + int _source_size = 0); #endif -} Info; /* +1 for TRUST_UNKNOWN */ +} +Info; /* +1 for TRUST_UNKNOWN */ typedef struct _CategoryPackage { - struct _CategoryPackage *next; /* The next package pointer in the list */ - char *pkgname; /* This should be Package *, but the packages can move*/ -} CategoryPackage; + struct _CategoryPackage *next; /* The next package pointer in the list */ + char *pkgname; /* This should be Package *, but the packages can move */ +} +CategoryPackage; struct _Category { - struct _Category *next; /* the next category in the list */ - char *name; /* the category */ - CategoryPackage *packages; /* the packages in this category */ + struct _Category *next; /* the next category in the list */ + char *name; /* the category */ + CategoryPackage *packages; /* the packages in this category */ }; typedef struct _Dependency { - struct _Dependency *next; /* the next package in this dependency list */ - char *package; /* the name of the package that is depended on */ -} Dependency; /* Dependencies can be used for - recommended/required/related... */ + struct _Dependency *next; /* the next package in this dependency list */ + char *package; /* the name of the package that is depended on */ +} +Dependency; /* Dependencies can be used for + recommended/required/related... */ struct _Package { - char *name; /* package name, like "cygwin" */ - char *sdesc; /* short description (replaces "name" if provided) */ - char *ldesc; /* long description (multi-line) */ - Category *category; /* the categories the package belongs to */ - Dependency *required; /* the packages required for this package to work */ - actions action; /* A range of states applicable to this package */ - trusts trust; /* Selects among info[] below, a subset of action */ - int srcpicked; /* True if source is required */ - - Info *installed; /* Info on installed package */ - trusts installed_ix; /* Index into info array for currently installed package */ - excludes exclude; /* true if this package should be excluded */ + char *name; /* package name, like "cygwin" */ + char *sdesc; /* short description (replaces "name" if provided) */ + char *ldesc; /* long description (multi-line) */ + Category *category; /* the categories the package belongs to */ + Dependency *required; /* the packages required for this package to work */ + actions action; /* A range of states applicable to this package */ + trusts trust; /* Selects among info[] below, a subset of action */ + int srcpicked; /* True if source is required */ + + Info *installed; /* Info on installed package */ + trusts installed_ix; /* Index into info array for currently installed package */ + excludes exclude; /* true if this package should be excluded */ /* The reason for this weird layout is to allow for loops that scan either the info array, based on trust value or the infoscan array based on a pointer, @@ -140,20 +145,22 @@ extern Category *category; extern int ncategories; #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -Package *new_package (char *name); -void ini_init (char *string); -Package *getpkgbyname (const char *pkgname); -void new_requirement (Package *package, char *dependson); -Category *getcategorybyname (const char *categoryname); -Category *getpackagecategorybyname (Package *pkg, const char *categoryname); -Category *register_category (const char *name); -void add_category (Package *package, Category *cat); + Package *new_package (char *name); + void ini_init (char *string); + Package *getpkgbyname (const char *pkgname); + void new_requirement (Package * package, char *dependson); + Category *getcategorybyname (const char *categoryname); + Category *getpackagecategorybyname (Package * pkg, + const char *categoryname); + Category *register_category (const char *name); + void add_category (Package * package, Category * cat); #ifdef __cplusplus } #endif -#endif /* _INI_H_ */ +#endif /* _INI_H_ */ diff --git a/inilex.l b/inilex.l index 0e4db7f8..9b55d226 100644 --- a/inilex.l +++ b/inilex.l @@ -27,7 +27,7 @@ #define YY_INPUT(buf,result,max_size) { result = ini_getchar(buf, max_size); } static int ini_getchar(char *buf, int max_size); -static void ignore_line (); +static void ignore_line (void); %} @@ -119,7 +119,7 @@ static void ignore_line () { char c; - while (c = input ()) + while ((c = input ())) { if (c == EOF) return; diff --git a/install.cc b/install.cc index 96b0c4da..ecdbf6ab 100644 --- a/install.cc +++ b/install.cc @@ -17,9 +17,12 @@ the install list (in ini.h). Note that we use a separate thread to maintain the progress dialog, so we avoid the complexity of handling two tasks in one thread. We also create or update all the - files in /etc/setup/* and create the mount points. */ + files in /etc/setup/\* and create the mount points. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include "commctrl.h" @@ -39,7 +42,6 @@ static char *cvsid = "\n%%% $Id$\n"; #include "geturl.h" #include "mkdir.h" #include "state.h" -#include "tar.h" #include "diskfull.h" #include "msg.h" #include "mount.h" @@ -47,6 +49,11 @@ static char *cvsid = "\n%%% $Id$\n"; #include "hash.h" #include "mount.h" #include "filemanip.h" +#include "io_stream.h" +#include "compress.h" +#include "compress_gz.h" +#include "archive.h" +#include "archive_tar.h" #include "port.h" @@ -71,13 +78,12 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) case IDCANCEL: exit_setup (1); } + return 0; } static BOOL CALLBACK dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam) { - int i, j; - HWND listbox; switch (message) { case WM_INITDIALOG: @@ -102,19 +108,19 @@ dialog (void *) int rv = 0; MSG m; HWND ins_dialog = CreateDialog (hinstance, MAKEINTRESOURCE (IDD_INSTATUS), - 0, dialog_proc); + 0, dialog_proc); if (ins_dialog == 0) fatal ("create dialog"); ShowWindow (ins_dialog, SW_SHOWNORMAL); UpdateWindow (ins_dialog); - while (GetMessage (&m, 0, 0, 0) > 0) { - TranslateMessage (&m); - DispatchMessage (&m); - } + while (GetMessage (&m, 0, 0, 0) > 0) + { + TranslateMessage (&m); + DispatchMessage (&m); + } + return rv; } -static DWORD start_tics; - static void init_dialog () { @@ -160,14 +166,13 @@ progress (int bytes) static void badrename (char *o, char *n) { - char buf[1000]; - char *err = strerror (errno); + const char *err = strerror (errno); if (!err) err = "(unknown error)"; note (IDS_ERR_RENAME, o, n, err); } -static char *standard_dirs[] = { +static const char *standard_dirs[] = { "/bin", "/etc", "/lib", @@ -191,14 +196,14 @@ hash::add_subdirs (char *path) { char *nonp, *pp; for (nonp = path; *nonp == '\\' || *nonp == '/'; nonp++); - for (pp = path + strlen(path) - 1; pp>nonp; pp--) + for (pp = path + strlen (path) - 1; pp > nonp; pp--) if (*pp == '/' || *pp == '\\') { - int i, s=0; + int i, s = 0; char c = *pp; *pp = 0; - for (i=0; standard_dirs[i]; i++) - if (strcmp (standard_dirs[i]+1, path) == 0) + for (i = 0; standard_dirs[i]; i++) + if (strcmp (standard_dirs[i] + 1, path) == 0) { s = 1; break; @@ -209,24 +214,18 @@ hash::add_subdirs (char *path) } } -static int -exists (const char *file) -{ - if (_access (file, 0) == 0) - return 1; - return 0; -} - static int num_installs, num_uninstalls; static void -uninstall_one (Package *pkg, bool src) +uninstall_one (Package * pkg, bool src) { hash dirs; char line[_MAX_PATH]; - gzFile lst = gzopen (cygpath ("/etc/setup/", pkg->name, - (src ? "-src.lst.gz" : ".lst.gz"), 0), "rb"); + io_stream *tmp = + io_stream::open (concat ("cygfile:///etc/setup/", pkg->name, + (src ? "-src.lst.gz" : ".lst.gz"), 0), "rb"); + io_stream *lst = compress::decompress (tmp); if (lst) { SetWindowText (ins_pkgname, pkg->name); @@ -236,10 +235,10 @@ uninstall_one (Package *pkg, bool src) else log (0, "Uninstalling old %s", pkg->name); - while (gzgets (lst, line, sizeof (line))) + while (lst->gets (line, sizeof (line))) { - if (line[strlen(line)-1] == '\n') - line[strlen(line)-1] = 0; + if (line[strlen (line) - 1] == '\n') + line[strlen (line) - 1] = 0; dirs.add_subdirs (line); @@ -251,7 +250,7 @@ uninstall_one (Package *pkg, bool src) DeleteFile (d); } } - gzclose (lst); + delete lst; remove (cygpath ("/etc/setup/", pkg->name, ".lst.gz", 0)); @@ -275,45 +274,54 @@ uninstall_one (Package *pkg, bool src) static int -install_one (Package *pkg, bool isSrc) +install_one (Package * pkg, bool isSrc) { int errors = 0; - char *extra; + const char *extra; const char *file; int file_size; + archive *thefile = NULL; Info *pi = pkg->info + pkg->trust; if (!isSrc) { extra = ""; file_size = pi->install_size; - file = pi->install; + file = concat ("file://", pi->install, 0); } else if (pi->source) { extra = "-src"; file_size = pi->source_size; - file = pi->source; + file = concat ("file://", pi->source, 0); } else return 0; char name[strlen (pkg->name) + strlen (extra) + 1]; strcat (strcpy (name, pkg->name), extra); - + + /* FIXME: this may file now */ char *basef = base (file); SetWindowText (ins_pkgname, basef); - if (!exists (file)) + if (!io_stream::exists (file)) file = basef; - if (!exists (file)) + if (!io_stream::exists (file)) { note (IDS_ERR_OPEN_READ, file, "No such file"); return 1; } - gzFile lst = gzopen (cygpath ("/etc/setup/", name, ".lst.gz", 0), - "wb9"); + io_stream *tmp = + io_stream::open (concat ("cygfile:///etc/setup/", name, ".lst.gz", 0), + "wb"); + io_stream *lst = new compress_gz (tmp, "w9"); + if (lst->error ()) + { + delete lst; + lst = NULL; + } package_bytes = file_size; @@ -342,44 +350,60 @@ install_one (Package *pkg, bool isSrc) case ACTION_TEST: strcat (msg, " test version..."); break; + default: + /* FIXME: log this somehow */ + break; } SetWindowText (ins_action, msg); log (0, "%s%s", msg, file); - tar_open (file); - - char *fn; - while (fn = tar_next_file ()) + tmp = io_stream::open (file, "rb"); + if (tmp) { - char *dest_file; - - if (lst) - gzprintf (lst, "%s\n", fn); - - dest_file = cygpath (isSrc ? "/usr/src/" : "/", fn, NULL); - - SetWindowText (ins_filename, dest_file); - log (LOG_BABBLE, "Installing file %s", dest_file); - if (tar_read_file (dest_file) != 0) + io_stream *tmp2 = compress::decompress (tmp); + if (tmp2) + thefile = archive::extract (tmp2); + else + thefile = archive::extract (tmp); + /* FIXME: potential leak of either *tmp or *tmp2 */ + if (thefile) { - log (0, "Unable to install file %s", dest_file); - errors++; - } + const char *fn; + while ((fn = thefile->next_file_name ())) + { + char *dest_file; + + if (lst) + lst->write (concat (fn, "\n", 0), strlen (fn) + 1); + + dest_file = + concat ("cygfile://", isSrc ? "/usr/src/" : "/", NULL); + + /* FIXME: concat leaks memory */ + SetWindowText (ins_filename, concat (dest_file, fn, 0)); + log (LOG_BABBLE, "Installing file %s%s", dest_file, fn); + if (archive::extract_file (thefile, dest_file) != 0) + { + log (0, "Unable to install file %s%s", dest_file, fn); + errors++; + } + + progress (tmp->tell ()); + free (dest_file); + num_installs++; + } + delete thefile; - progress (tar_ftell ()); - free (dest_file); - num_installs++; + total_bytes_sofar += file_size; + } } - tar_close (); - - total_bytes_sofar += file_size; progress (0); int df = diskfull (get_root_dir ()); SendMessage (ins_diskfull, PBM_SETPOS, (WPARAM) df, 0); if (lst) - gzclose (lst); + delete lst; if (!errors) { @@ -387,7 +411,9 @@ install_one (Package *pkg, bool isSrc) pkg->installed_ix = pkg->trust; if (pkg->installed) free (pkg->installed); - pkg->installed = new Info (inf->install, inf->version, inf->install_size, inf->source, inf->source_size); + pkg->installed = + new Info (inf->install, inf->version, inf->install_size, inf->source, + inf->source_size); } return errors; @@ -404,22 +430,26 @@ check_for_old_cygwin () return; char msg[sizeof (buf) + 132]; - sprintf (msg, "An old version of cygwin1.dll was found here:\r\n%s\r\nDelete?", buf); - switch (MessageBox (NULL, msg, - "What's that doing there?", MB_YESNO | MB_ICONQUESTION | MB_TASKMODAL)) + sprintf (msg, + "An old version of cygwin1.dll was found here:\r\n%s\r\nDelete?", + buf); + switch (MessageBox + (NULL, msg, "What's that doing there?", + MB_YESNO | MB_ICONQUESTION | MB_TASKMODAL)) { case IDYES: if (!DeleteFile (buf)) { sprintf (msg, "Couldn't delete file %s.\r\n" - "Is the DLL in use by another application?\r\n" - "You should delete the old version of cygwin1.dll\r\nat your earliest convenience.", - buf); - MessageBox (NULL, buf, "Couldn't delete file", MB_OK | MB_ICONEXCLAMATION | MB_TASKMODAL); + "Is the DLL in use by another application?\r\n" + "You should delete the old version of cygwin1.dll\r\nat your earliest convenience.", + buf); + MessageBox (NULL, buf, "Couldn't delete file", + MB_OK | MB_ICONEXCLAMATION | MB_TASKMODAL); } break; default: - break; + break; } return; @@ -437,7 +467,7 @@ do_install (HINSTANCE h) mkdir_p (1, get_root_dir ()); - for (i=0; standard_dirs[i]; i++) + for (i = 0; standard_dirs[i]; i++) { char *p = cygpath (standard_dirs[i], 0); mkdir_p (1, p); @@ -445,11 +475,8 @@ do_install (HINSTANCE h) } /* Create /var/run/utmp */ - char *utmp = cygpath ("/var/run/utmp", 0); - FILE *ufp = fopen (utmp, "wb"); - if (ufp) - fclose (ufp); - free (utmp); + io_stream *utmp = io_stream::open ("cygfile:///var/run/utmp", "wb"); + delete utmp; dismiss_url_status_dialog (); @@ -469,7 +496,7 @@ do_install (HINSTANCE h) create_mount ("/usr/lib", cygpath ("/lib", 0), istext, issystem); set_cygdrive_flags (istext, issystem); - for (Package *pkg = package; pkg->name; pkg++) + for (Package * pkg = package; pkg->name; pkg++) { Info *pi = pkg->info + pkg->trust; if (pkg->action != ACTION_SRC_ONLY) @@ -478,7 +505,7 @@ do_install (HINSTANCE h) total_bytes += pi->source_size; } - for (Package *pkg = package; pkg->name; pkg++) + for (Package * pkg = package; pkg->name; pkg++) { if (is_uninstall_action (pkg)) { @@ -499,7 +526,7 @@ do_install (HINSTANCE h) errors++; } } - } // end of big package loop + } // end of big package loop ShowWindow (ins_dialog, SW_HIDE); @@ -514,7 +541,7 @@ do_install (HINSTANCE h) if (!ndb) { - char *err = strerror (errno); + const char *err = strerror (errno); if (!err) err = "(unknown error)"; fatal (IDS_ERR_OPEN_WRITE, ndb, err); @@ -523,18 +550,19 @@ do_install (HINSTANCE h) if (odb) { char line[1000], pkgname[1000]; - int printit; while (fgets (line, 1000, odb)) { sscanf (line, "%s", pkgname); Package *pkg = getpkgbyname (pkgname); - if (!pkg || (!is_download_action (pkg) && pkg->action != ACTION_UNINSTALL)) + if (!pkg + || (!is_download_action (pkg) + && pkg->action != ACTION_UNINSTALL)) fputs (line, ndb); } } - for (Package *pkg = package; pkg->name; pkg++) + for (Package * pkg = package; pkg->name; pkg++) if (is_download_action (pkg)) { Info *pi = pkg->info + pkg->installed_ix; diff --git a/io_stream.cc b/io_stream.cc new file mode 100644 index 00000000..ea11e204 --- /dev/null +++ b/io_stream.cc @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2001, Robert Collins. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +/* this is the parent class for all IO operations. It's flexable enough to be cover for + * HTTP access, local file access, and files being extracted from archives. + * It also encapsulates the idea of an archive, and all non-archives become the special + * case. + */ + +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif + +#include "win32.h" +#include +#include "log.h" +#include "port.h" + +#include "io_stream.h" +#include "io_stream_file.h" +#include "io_stream_cygfile.h" +#include "mkdir.h" + +/* Static members */ +io_stream * +io_stream::factory (io_stream * parent) +{ + /* something like, + * if !next_file_name + * return NULL + * switch (magic_id(peek (parent), max_magic_length)) + * case io_stream * foo = new tar + * case io_stream * foo = new bz2 + * return foo + */ + log (LOG_TIMESTAMP, "io_stream::factory has been called"); + return NULL; +} + +io_stream * +io_stream::open (const char *name, const char *mode) +{ + if (!name || IsBadStringPtr (name, MAX_PATH) || !name[0] || + !mode || IsBadStringPtr (mode, 5) || !mode[0]) + return NULL; + /* iterate through the known url prefix's */ + if (!strncasecmp ("file://", name, 7)) + { + io_stream_file *rv = new io_stream_file (&name[7], mode); + if (!rv->error ()) + return rv; + delete rv; + return NULL; + } + if (!strncasecmp ("cygfile://", name, 10)) + { + io_stream_cygfile *rv = new io_stream_cygfile (&name[10], mode); + if (!rv->error ()) + return rv; + delete rv; + return NULL; + } + return NULL; +} + +int +io_stream::mkpath_p (path_type_t isadir, const char *name) +{ + if (!name || IsBadStringPtr (name, MAX_PATH) || !name[0]) + return 1; + /* iterate through the known url prefix's */ + if (!strncasecmp ("file://", name, 7)) + { + return mkdir_p (isadir == PATH_TO_DIR ? 1 : 0, &name[7]); + } + if (!strncasecmp ("cygfile://", name, 10)) + { + return cygmkdir_p (isadir == PATH_TO_DIR ? 1 : 0, &name[10]); + } + return 1; +} + +/* remove a file or directory. */ +int +io_stream::remove (const char *name) +{ + if (!name || IsBadStringPtr (name, MAX_PATH) || !name[0]) + 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]); + return 1; +} + +int +io_stream::mklink (const char *from, const char *to, + io_stream_link_t linktype) +{ + if (!from || IsBadStringPtr (from, MAX_PATH) || + !to || IsBadStringPtr (to, MAX_PATH)) + { + 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)) + { + /* 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); + log (LOG_TIMESTAMP, "Attempt to link across url providers"); + return 1; + } + if (!strncasecmp ("cygfile://", from, 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); + log (LOG_TIMESTAMP, "Attempt to link across url providers"); + return 1; + } +#if 0 + if (!strmcasecmp ("http://", from, 7)) + { + /* http urls can symlink to http or ftp url's */ + } +#endif + log (LOG_TIMESTAMP, "Unsupported url providers for %s", from); + return 1; +} + +char * +io_stream::gets (char *buffer, size_t length) +{ + char *pos = buffer; + size_t count = 0; + while (count + 1 < length && read (pos, 1) == 1) + { + count++; + pos++; + if (*(pos - 1) == '\n') + { + /* end of line */ + /* TODO: remove the \r if it is present depending on the + * file's mode + */ + break; + } + } + if (count == 0 || error ()) + /* EOF when no chars found, or an error */ + return NULL; + *pos = '\0'; + return buffer; +} + +int +io_stream::exists (const char *name) +{ + if (!name || IsBadStringPtr (name, MAX_PATH) || !name[0]) + 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]); + return 1; +} + +/* virtual members */ + +io_stream::~io_stream () +{ + log (LOG_TIMESTAMP, "io_stream::~io_stream called"); + return; +} diff --git a/io_stream.h b/io_stream.h new file mode 100644 index 00000000..da85109a --- /dev/null +++ b/io_stream.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2001, Robert Collins. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +#ifndef _IO_STREAM_H_ +#define _IO_STREAM_H_ + +/* this is the parent class for all IO operations. It's flexable enough to be cover for + * HTTP access, local file access, and files being extracted from archives. + * It also encapsulates the idea of an archive, and all non-archives become the special + * case. + */ + +/* Some things don't fit cleanly just - TODO + * make mkdir_p fit in the hierarchy + */ + +//Where is this defined? +typedef signed long ssize_t; + +#if __GNUC__ +#define _ATTR_(foo) __attribute__ foo +#else +#define _ATTR_(foo) +#endif + +typedef enum +{ + PATH_TO_DIR, + PATH_TO_FILE +} +path_type_t; + +typedef enum +{ + IO_STREAM_INVALID, + IO_STREAM_STREAM, + IO_STREAM_COMPRESS, + IO_STREAM_ARCHIVE +} +io_stream_type_t; + +typedef enum +{ + IO_STREAM_SYMLINK, + IO_STREAM_HARDLINK +} +io_stream_link_t; + +class io_stream +{ +public: + /* create a new stream from an existing one - used to get + * decompressed data + * or open archives. + * will return NULL if there is no sub-stream available (ie (peek() + * didn't match any known magic number) && nextfilename () = NULL + */ + static io_stream *factory (io_stream *); + /* open a stream by url. The particular stream type returned + * will depend on the url passed. + * ie for file:// it will be a disk file. + * for ftp:// it will perform an upload to a ftp site. + * the second parameter - mode can specify r|w && t|b. Other flags are not currently + * supported. + * Automatic decompression does not occur. Compressed files will return a io_stream + * from archive::decompress. This behaviour is by design - to allow deliberate access + * to the compressed data. + * To create a stream that will be compressed, you should open the url, and then get a new stream + * from archive::compress. + * If a stream is opened for reading, and it's an archive, the next_file_name method + * 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 *); + /* 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 *); + /* link from, to, type. Returns 1 on failure */ + static int mklink (const char *, const char *, io_stream_link_t); + /* TODO: we may need two versions of each of these: + 1 for external use - when the path is known + 1 for inline use, for example to set the mtime of a file being written + into a tarball + */ + /* set the modification time of a file - returns 1 on failure + * may distrupt internal state - use after all important io is complete + */ + virtual int set_mtime (int) = 0; + /* get the mtime for a file TODO make this a stat(0 style call */ + virtual int get_mtime () = 0; + /* read data (duh!) */ + virtual ssize_t read (void *buffer, size_t len) = 0; + /* provide data to (double duh!) */ + virtual ssize_t write (void *buffer, size_t len) = 0; + /* read data without removing it from the class's internal buffer */ + virtual ssize_t peek (void *buffer, size_t len) = 0; + /* ever read the f* functions from libc ? */ + virtual long tell () = 0; + /* try guessing this one */ + virtual int error () = 0; + /* hmm, yet another for the guessing books */ + virtual char *gets (char *, size_t len); + /* what sort of stream is this? + * known types are: + * IO_STREAM_INVALID - not a valid stream. + * IO_STREAM_STREAM - just another stream. + * IO_STREAM_COMPRESS - a compressed or compressing stream. + * IO_STREAM_ARCHIVE - an archive of some sort, with > 0 files. + * this is a crutch for real runtime type evaluation. + */ + /* Find out the next stream name - + * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar + * for foobar that is an archive, next_file_name is the next + * extractable filename. + */ +// virtual const char* next_file_name() = NULL; + /* if you are still needing these hints... give up now! */ + virtual ~ io_stream (); +}; + +#endif /* _IO_STREAM_H_ */ diff --git a/io_stream_cygfile.cc b/io_stream_cygfile.cc new file mode 100644 index 00000000..c4e93438 --- /dev/null +++ b/io_stream_cygfile.cc @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2001, Robert Collins. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif + + +#include "win32.h" +#include +#include +#include "log.h" +#include "port.h" +#include "mount.h" +#include "mkdir.h" +#include "mklink2.h" +#include + +#include "io_stream.h" +#include "io_stream_cygfile.h" + +/* For set mtime */ +#define FACTOR (0x19db1ded53ea710LL) +#define NSPERSEC 10000000LL + +static void +get_root_dir_now () +{ + if (get_root_dir ()) + return; + read_mounts (); +} + +io_stream_cygfile::io_stream_cygfile (const char *name, const char *mode) +{ + fname = NULL; + fp = NULL; + errno = 0; + if (!name || IsBadStringPtr (name, MAX_PATH) || !name[0] || + !mode || IsBadStringPtr (mode, 5) || !mode[0]) + 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 ()) + /* TODO: assign a errno for "no mount table :} " */ + return; + + fname = cygpath (name, 0); + lmode = strdup (mode); + fp = fopen (fname, mode); + if (!fp) + lasterr = errno; +} + +io_stream_cygfile::~io_stream_cygfile () +{ + if (lmode) + free (lmode); + if (fname) + free (fname); + if (fp) + fclose (fp); +} + +/* Static members */ +int +io_stream_cygfile::exists (const char *path) +{ + get_root_dir_now (); + if (get_root_dir () && _access (cygpath (path, 0), 0) == 0) + return 1; + return 0; +} + +int +io_stream_cygfile::remove (const char *path) +{ + if (!path) + return 1; + get_root_dir_now (); + if (!get_root_dir ()) + /* TODO: assign a errno for "no mount table :} " */ + return 1; + + unsigned long w = GetFileAttributes (cygpath (path, 0)); + if (w != 0xffffffff && w & FILE_ATTRIBUTE_DIRECTORY) + { + char *tmp = (char *) malloc (strlen (cygpath (path, 0)) + 10); + int i = 0; + do + { + i++; + sprintf (tmp, "%s.old-%d", cygpath (path, 0), i); + } + while (GetFileAttributes (tmp) != 0xffffffff); + fprintf (stderr, "warning: moving directory \"%s\" out of the way.\n", + path); + MoveFile (cygpath (path, 0), tmp); + free (tmp); + } + return !DeleteFileA (cygpath (path, 0)); +} + +int +io_stream_cygfile::mklink (const char *from, const char *to, + io_stream_link_t linktype) +{ + /* FIXME: badstring check */ + if (!from || !to) + return 1; + switch (linktype) + { + case IO_STREAM_SYMLINK: + return mkcygsymlink (cygpath (from, 0), to); + 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 (to, 0), "rb"); + if (!in) + { + log (LOG_TIMESTAMP, "could not open %s for reading in mklink", + to); + return 1; + } + io_stream *out = io_stream::open (cygpath (from, 0), "wb"); + if (!out) + { + log (LOG_TIMESTAMP, "could not open %s for writing in mklink", + from); + delete in; + return 1; + } + + ssize_t len; + char buf[16384]; + while ((len = in->read (buf, 16384)) > 0) + { + 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; + } + } + 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 1; +} + + +/* virtuals */ + +ssize_t io_stream_cygfile::read (void *buffer, size_t len) +{ + if (fp) + return fread (buffer, 1, len, fp); + return 0; +} + +ssize_t io_stream_cygfile::write (void *buffer, size_t len) +{ + if (fp) + return fwrite (buffer, 1, len, fp); + return 0; +} + +ssize_t io_stream_cygfile::peek (void *buffer, size_t len) +{ + log (LOG_TIMESTAMP, "io_stream_cygfile::peek called"); + if (fp) + { + int + pos = ftell (fp); + ssize_t + rv = fread (buffer, 1, len, fp); + fseek (fp, pos, SEEK_SET); + return rv; + } + return 0; +} + +long +io_stream_cygfile::tell () +{ + if (fp) + { + return ftell (fp); + } + return 0; +} + +int +io_stream_cygfile::error () +{ + if (fp) + return ferror (fp); + return lasterr; +} + +int +cygmkdir_p (int isadir, const char *name) +{ + if (!name || IsBadStringPtr (name, MAX_PATH) || !name[0]) + return 1; + get_root_dir_now (); + if (!get_root_dir ()) + /* TODO: assign a errno for "no mount table :} " */ + return 1; + return mkdir_p (isadir, cygpath (name, 0)); +} + + +int +io_stream_cygfile::set_mtime (int mtime) +{ + if (!fname) + return 1; + if (fp) + fclose (fp); + long long ftimev = mtime * NSPERSEC + FACTOR; + FILETIME ftime; + ftime.dwHighDateTime = ftimev >> 32; + ftime.dwLowDateTime = ftimev; + HANDLE h = + CreateFileA (fname, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, + 0, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, 0); + if (h) + { + SetFileTime (h, 0, 0, &ftime); + CloseHandle (h); + fp = fopen (fname, lmode); + if (!fp) + lasterr = errno; + return 0; + } + fp = fopen (fname, lmode); + if (!fp) + lasterr = errno; + return 1; +} diff --git a/io_stream_cygfile.h b/io_stream_cygfile.h new file mode 100644 index 00000000..fcd00a31 --- /dev/null +++ b/io_stream_cygfile.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2001, Robert Collins. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +#ifndef _IO_STREAM_CYGFILE_H_ +#define _IO_STREAM_CYGFILE_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); + +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 *); + virtual ~io_stream_cygfile (); + /* read data (duh!) */ + virtual ssize_t read (void *buffer, size_t len); + /* provide data to (double duh!) */ + virtual ssize_t write (void *buffer, size_t len); + /* read data without removing it from the class's internal buffer */ + virtual ssize_t peek (void *buffer, size_t len); + virtual long tell (); + /* can't guess, oh well */ + virtual int error (); + virtual int set_mtime (int); + /* not relevant yet */ + virtual int get_mtime () {return 0;}; + /* dummy for io_stream_file */ + virtual const char *next_file_name () + { + return NULL; + }; +private: + /* always require parameters */ + io_stream_cygfile () + { + }; + FILE *fp; + int lasterr; + char *fname; + char *lmode; +}; + +#endif /* _IO_STREAM_CYGFILE_H_ */ diff --git a/io_stream_file.cc b/io_stream_file.cc new file mode 100644 index 00000000..48b35c24 --- /dev/null +++ b/io_stream_file.cc @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2001, Robert Collins. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif + +#include "win32.h" +#include +#include +#include +#include "log.h" +#include "port.h" +#include "mklink2.h" + +#include "io_stream.h" +#include "io_stream_file.h" + +/* for set_mtime */ +#define FACTOR (0x19db1ded53ea710LL) +#define NSPERSEC 10000000LL + +io_stream_file::io_stream_file (const char *name, const char *mode) +{ + fname = NULL; + fp = NULL; + errno = 0; + if (!name || IsBadStringPtr (name, MAX_PATH) || !name[0] || + !mode || IsBadStringPtr (mode, 5) || !mode[0]) + return; + lmode = strdup (mode); + fname = strdup (name); + fp = fopen (name, mode); + if (!fp) + lasterr = errno; +} + +io_stream_file::~io_stream_file () +{ + if (fname) + free (fname); + if (fp) + fclose (fp); +} + +int +io_stream_file::exists (const char *path) +{ + if (_access (path, 0) == 0) + return 1; + return 0; +} + +int +io_stream_file::remove (const char *path) +{ + if (!path) + return 1; + + unsigned long w = GetFileAttributes (path); + if (w != 0xffffffff && w & FILE_ATTRIBUTE_DIRECTORY) + { + char *tmp = (char *) malloc (strlen (path) + 10); + int i = 0; + do + { + i++; + sprintf (tmp, "%s.old-%d", path, i); + } + while (GetFileAttributes (tmp) != 0xffffffff); + fprintf (stderr, "warning: moving directory \"%s\" out of the way.\n", + path); + MoveFile (path, tmp); + free (tmp); + } + return !DeleteFileA (path); + +} + +int +io_stream_file::mklink (const char *from, const char *to, + io_stream_link_t linktype) +{ + /* FIXME: badstring check */ + if (!from || !to) + return 1; + switch (linktype) + { + case IO_STREAM_SYMLINK: + return mkcygsymlink (from, to); + case IO_STREAM_HARDLINK: + return 1; + } + return 1; +} + +/* virtuals */ + + +ssize_t io_stream_file::read (void *buffer, size_t len) +{ + if (fp) + return fread (buffer, 1, len, fp); + return 0; +} + +ssize_t io_stream_file::write (void *buffer, size_t len) +{ + if (fp) + return fwrite (buffer, 1, len, fp); + return 0; +} + +ssize_t io_stream_file::peek (void *buffer, size_t len) +{ + log (LOG_TIMESTAMP, "io_stream_file::peek called"); + if (fp) + { + int + pos = ftell (fp); + ssize_t + rv = fread (buffer, 1, len, fp); + fseek (fp, pos, SEEK_SET); + return rv; + } + return 0; +} + +long +io_stream_file::tell () +{ + if (fp) + { + return ftell (fp); + } + return 0; +} + +int +io_stream_file::error () +{ + if (fp) + return ferror (fp); + return lasterr; +} + +int +io_stream_file::set_mtime (int mtime) +{ + if (!fname) + return 1; + if (fp) + fclose (fp); + long long ftimev = mtime * NSPERSEC + FACTOR; + FILETIME ftime; + ftime.dwHighDateTime = ftimev >> 32; + ftime.dwLowDateTime = ftimev; + HANDLE h = + CreateFileA (fname, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, + 0, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, 0); + if (h) + { + SetFileTime (h, 0, 0, &ftime); + CloseHandle (h); + fp = fopen (fname, lmode); + if (!fp) + lasterr = errno; + return 0; + } + fp = fopen (fname, lmode); + if (!fp) + lasterr = errno; + return 1; +} diff --git a/io_stream_file.h b/io_stream_file.h new file mode 100644 index 00000000..ad9e0e87 --- /dev/null +++ b/io_stream_file.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2001, Robert Collins. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +#ifndef _IO_STREAM_FILE_H_ +#define _IO_STREAM_FILE_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 *); + virtual ~io_stream_file (); + /* read data (duh!) */ + virtual ssize_t read (void *buffer, size_t len); + /* provide data to (double duh!) */ + virtual ssize_t write (void *buffer, size_t len); + /* read data without removing it from the class's internal buffer */ + virtual ssize_t peek (void *buffer, size_t len); + virtual long tell (); + /* can't guess, oh well */ + virtual int error (); + virtual int set_mtime (int); + /* not relevant yet */ + virtual int get_mtime () {return 0;}; + /* dummy for io_stream_file */ + virtual const char *next_file_name () + { + return NULL; + }; +private: + /* always require parameters */ + io_stream_file () + { + }; + FILE *fp; + int lasterr; + char *fname; + char *lmode; +}; + +#endif /* _IO_STREAM_FILE_H_ */ diff --git a/localdir.cc b/localdir.cc index 6f388448..602d5edc 100644 --- a/localdir.cc +++ b/localdir.cc @@ -15,11 +15,13 @@ */ /* The purpose of this file is to ask the user where they want the - root of the installation to be, and to ask whether the user prefers - text or binary mounts. */ + * locally downloaded package files to be cached + */ -static char *cvsid = +#if 0 +static const char *cvsid = "\n%%% $Id$\n"; +#endif #include "win32.h" #include @@ -35,34 +37,23 @@ static char *cvsid = #include "concat.h" #include "log.h" #include "mkdir.h" - -static void -get_root_dir_now () -{ - int istext; - int issystem; - if (get_root_dir ()) - return; - read_mounts (); -} +#include "io_stream.h" void save_local_dir () { - get_root_dir_now (); - if (!get_root_dir ()) - return; - mkdir_p (1, local_dir); - FILE *f = fopen (cygpath ("/etc/setup/last-cache", 0), "wb"); - if (!f) - return; - fprintf (f, "%s", local_dir); - fclose (f); + io_stream *f = io_stream::open ("cygfile:///etc/setup/last-cache", "wb"); + if (f) + { + char temp[1000]; + sprintf (temp, "%s", local_dir); + f->write (temp, strlen (temp)); + delete f; + } } - static void check_if_enable_next (HWND h) { @@ -116,7 +107,6 @@ browse (HWND h) } } - static BOOL dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) { @@ -176,6 +166,7 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) NEXT (0); break; } + return 0; } static BOOL CALLBACK @@ -200,13 +191,13 @@ do_local_dir (HINSTANCE h) static int inited = 0; if (!inited) { - FILE *f = fopen (cygpath ("/etc/setup/last-cache", 0), "rt"); + io_stream *f = + io_stream::open ("cygfile:///etc/setup/last-cache", "rt"); if (f) { char localdir[1000]; - localdir[0] = '\0'; - char *fg_ret = fgets (localdir, 1000, f); - fclose (f); + char *fg_ret = f->gets (localdir, 1000); + delete f; if (fg_ret) { free (local_dir); diff --git a/log.cc b/log.cc index 6cd2de4b..c54ca927 100644 --- a/log.cc +++ b/log.cc @@ -15,7 +15,10 @@ /* The purpose of this file is to centralize all the logging functions. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include @@ -32,7 +35,8 @@ static char *cvsid = "\n%%% $Id$\n"; #include "mkdir.h" #include "mount.h" -struct LogEnt { +struct LogEnt +{ LogEnt *next; int flags; time_t when; @@ -43,7 +47,7 @@ static LogEnt *first_logent = 0; static LogEnt **next_logent = &first_logent; void -log (int flags, char *fmt, ...) +log (int flags, const char *fmt, ...) { char buf[1000]; va_list args; @@ -70,7 +74,7 @@ log (int flags, char *fmt, ...) } void -log_save (int babble, char *filename, int append) +log_save (int babble, const char *filename, int append) { static int been_here = 0; if (been_here) @@ -88,12 +92,12 @@ log_save (int babble, char *filename, int append) LogEnt *l; - for (l=first_logent; l; l=l->next) + for (l = first_logent; l; l = l->next) { if (babble || !(l->flags & LOG_BABBLE)) { fputs (l->msg, f); - if (l->msg[strlen(l->msg)-1] != '\n') + if (l->msg[strlen (l->msg) - 1] != '\n') fputc ('\n', f); } } diff --git a/log.h b/log.h index 40c4b9d6..a17e7221 100644 --- a/log.h +++ b/log.h @@ -20,13 +20,14 @@ #define LOG_BABBLE 1 #define LOG_TIMESTAMP 2 -void log (int flags, char *fmt, ...); +void log (int flags, const char *fmt, ...) + __attribute__ ((format (printf, 2, 3))); /* 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, char *filename, int append); +void log_save (int babble, const char *filename, int append); /* This is the only legal way to exit. It writes out all the logs and things */ -void exit_setup (int exit_code); +void exit_setup (int exit_code) __attribute__ ((noreturn)); diff --git a/main.cc b/main.cc index 5ce4de9c..29faee8c 100644 --- a/main.cc +++ b/main.cc @@ -23,7 +23,10 @@ those don't count, although they could). Replace the IDD_S_* with IDD_* if you create a real dialog for those steps. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" @@ -33,7 +36,6 @@ static char *cvsid = "\n%%% $Id$\n"; #include "dialog.h" #include "state.h" #include "msg.h" -#include "netio.h" #include "find.h" #include "mount.h" #include "log.h" @@ -41,8 +43,6 @@ static char *cvsid = "\n%%% $Id$\n"; #include "port.h" -void netio_test (char *); - int next_dialog; int exit_msg = 0; @@ -62,10 +62,10 @@ void set_default_dacl () { /* To assure that the created files have a useful ACL, the - default DACL in the process token is set to full access to - everyone. This applies to files and subdirectories created - in directories which don't propagate permissions to child - objects. */ + default DACL in the process token is set to full access to + everyone. This applies to files and subdirectories created + in directories which don't propagate permissions to child + objects. */ /* Create a buffer which has enough room to contain the TOKEN_DEFAULT_DACL structure plus an ACL with one ACE. */ @@ -84,8 +84,8 @@ set_default_dacl () /* Get the SID for "Everyone". */ PSID sid; - SID_IDENTIFIER_AUTHORITY sid_auth = SECURITY_WORLD_SID_AUTHORITY; - if (!AllocateAndInitializeSid(&sid_auth, 1, 0, 0, 0, 0, 0, 0, 0, 0, &sid)) + SID_IDENTIFIER_AUTHORITY sid_auth = { SECURITY_WORLD_SID_AUTHORITY }; + if (!AllocateAndInitializeSid (&sid_auth, 1, 0, 0, 0, 0, 0, 0, 0, 0, &sid)) { log (LOG_TIMESTAMP, "AllocateAndInitializeSid() failed: %lu", GetLastError ()); @@ -94,16 +94,18 @@ set_default_dacl () /* Create the ACE which grants full access to "Everyone" and store it in dacl->DefaultDacl. */ - if (!AddAccessAllowedAce (dacl->DefaultDacl, ACL_REVISION, GENERIC_ALL, sid)) + if (!AddAccessAllowedAce + (dacl->DefaultDacl, ACL_REVISION, GENERIC_ALL, sid)) { - log (LOG_TIMESTAMP, "AddAccessAllowedAce() failed: %lu", GetLastError ()); + log (LOG_TIMESTAMP, "AddAccessAllowedAce() failed: %lu", + GetLastError ()); goto out; } /* Get the processes access token. */ HANDLE token; if (!OpenProcessToken (GetCurrentProcess (), - TOKEN_READ | TOKEN_ADJUST_DEFAULT, &token)) + TOKEN_READ | TOKEN_ADJUST_DEFAULT, &token)) { log (LOG_TIMESTAMP, "OpenProcessToken() failed: %lu", GetLastError ()); goto out; @@ -123,9 +125,7 @@ out: int WINAPI WinMain (HINSTANCE h, - HINSTANCE hPrevInstance, - LPSTR command_line, - int cmd_show) + HINSTANCE hPrevInstance, LPSTR command_line, int cmd_show) { hinstance = h; @@ -144,7 +144,7 @@ WinMain (HINSTANCE h, for (argc = 0, argv = __argv; *argv; argv++) log (LOG_TIMESTAMP, "%d - '%s'\n", argc++, *argv); log (LOG_TIMESTAMP, "%d parameters passed\n", argc); - + /* Set the default DACL only on NT/W2K. 9x/ME has no idea of access control lists and security at all. */ if (iswinnt) @@ -154,20 +154,48 @@ WinMain (HINSTANCE h, { switch (next_dialog) { - case IDD_SPLASH: do_splash (h); break; - case IDD_SOURCE: do_source (h); break; - case IDD_LOCAL_DIR: do_local_dir (h); break; - case IDD_ROOT: do_root (h); break; - case IDD_NET: do_net (h); break; - case IDD_SITE: do_site (h); break; - case IDD_OTHER_URL: do_other (h); break; - case IDD_S_LOAD_INI: do_ini (h); break; - case IDD_S_FROM_CWD: do_fromcwd (h); break; - case IDD_CHOOSE: do_choose (h); break; - case IDD_S_DOWNLOAD: do_download (h); break; - case IDD_S_INSTALL: do_install (h); break; - case IDD_DESKTOP: do_desktop (h); break; - case IDD_S_POSTINSTALL: do_postinstall (h); break; + case IDD_SPLASH: + do_splash (h); + break; + case IDD_SOURCE: + do_source (h); + break; + case IDD_LOCAL_DIR: + do_local_dir (h); + break; + case IDD_ROOT: + do_root (h); + break; + case IDD_NET: + do_net (h); + break; + case IDD_SITE: + do_site (h); + break; + case IDD_OTHER_URL: + do_other (h); + break; + case IDD_S_LOAD_INI: + do_ini (h); + break; + case IDD_S_FROM_CWD: + do_fromcwd (h); + break; + case IDD_CHOOSE: + do_choose (h); + break; + case IDD_S_DOWNLOAD: + do_download (h); + break; + case IDD_S_INSTALL: + do_install (h); + break; + case IDD_DESKTOP: + do_desktop (h); + break; + case IDD_S_POSTINSTALL: + do_postinstall (h); + break; default: next_dialog = 0; @@ -176,4 +204,6 @@ WinMain (HINSTANCE h, } exit_setup (0); + /* Keep gcc happy :} */ + return 0; } diff --git a/mkdir.cc b/mkdir.cc index 42ae4747..1a6e55b1 100644 --- a/mkdir.cc +++ b/mkdir.cc @@ -15,7 +15,10 @@ /* see mkdir.h */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" @@ -45,7 +48,8 @@ mkdir_p (int isadir, const char *in_path) { if (gse == ERROR_ALREADY_EXISTS) { - fprintf (stderr, "warning: deleting \"%s\" so I can make a directory there\n", + fprintf (stderr, + "warning: deleting \"%s\" so I can make a directory there\n", path); if (DeleteFileA (path)) return mkdir_p (isadir, path); diff --git a/mklink2.c b/mklink2.c index 8ff5df43..fbd05faa 100644 --- a/mklink2.c +++ b/mklink2.c @@ -1,7 +1,12 @@ +#include #include "win32.h" #include "shlobj.h" +#include "mklink2.h" -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif /* This part of the code must be in C because the C++ interface to COM doesn't work. */ @@ -11,7 +16,7 @@ make_link_2 (char *exepath, char *args, char *icon, char *lname) { IShellLink *sl; IPersistFile *pf; - WCHAR widepath [_MAX_PATH]; + WCHAR widepath[_MAX_PATH]; CoCreateInstance (&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (LPVOID *) & sl); @@ -27,3 +32,30 @@ make_link_2 (char *exepath, char *args, char *icon, char *lname) pf->lpVtbl->Release (pf); sl->lpVtbl->Release (sl); } + +#define SYMLINK_COOKIE "!" + +/* Predicate: file is not currently in existence. + * A file race can occur otherwise. + */ +int +mkcygsymlink (const char *from, const char *to) +{ + char buf[512]; + unsigned long w; + HANDLE h = CreateFileA (from, GENERIC_WRITE, 0, 0, CREATE_NEW, + FILE_ATTRIBUTE_NORMAL, 0); + if (h == INVALID_HANDLE_VALUE) + return 1; + strcpy (buf, SYMLINK_COOKIE); + strcat (buf, to); + if (WriteFile (h, buf, strlen (buf) + 1, &w, NULL)) + { + CloseHandle (h); + SetFileAttributesA (from, FILE_ATTRIBUTE_SYSTEM); + return 0; + } + CloseHandle (h); + DeleteFileA (from); + return 1; +} diff --git a/mklink2.h b/mklink2.h new file mode 100644 index 00000000..589021f7 --- /dev/null +++ b/mklink2.h @@ -0,0 +1,15 @@ + +/* This part of the code must be in C because the C++ interface to COM +doesn't work. */ + +#ifdef __cplusplus +extern "C" +{ +#endif + void make_link_2 (char *exepath, char *args, char *icon, char *lname); + + int mkcygsymlink (const char *from, const char *to); + +#ifdef __cplusplus +}; +#endif diff --git a/mount.cc b/mount.cc index 105f78f9..8c01f798 100644 --- a/mount.cc +++ b/mount.cc @@ -17,7 +17,10 @@ Cygwin's mount table. If the format or location of the mount table changes, this is the file to change to match it. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" @@ -34,18 +37,18 @@ static char *cvsid = "\n%%% $Id$\n"; #include "concat.h" static struct mnt - { - const char *native; - char *posix; - int istext; - } mount_table[255]; +{ + const char *native; + char *posix; + int istext; +} +mount_table[255]; struct mnt *root_here = NULL; static char * find2 (HKEY rkey, int *istext, char *what) { - char buf[1000]; char *retval = 0; DWORD retvallen = 0; DWORD flags = 0; @@ -59,8 +62,9 @@ find2 (HKEY rkey, int *istext, char *what) == ERROR_SUCCESS) { retval = (char *) malloc (MAX_PATH + 1); - if (RegQueryValueEx (key, "native", 0, &type, (BYTE *) retval, &retvallen) - != ERROR_SUCCESS) + if (RegQueryValueEx + (key, "native", 0, &type, (BYTE *) retval, + &retvallen) != ERROR_SUCCESS) { free (retval); retval = 0; @@ -68,7 +72,7 @@ find2 (HKEY rkey, int *istext, char *what) } retvallen = sizeof (flags); - RegQueryValueEx (key, "flags", 0, &type, (BYTE *)&flags, &retvallen); + RegQueryValueEx (key, "flags", 0, &type, (BYTE *) & flags, &retvallen); RegCloseKey (key); @@ -82,9 +86,8 @@ void create_mount (const char *posix, const char *win32, int istext, int issystem) { char buf[1000]; - char *retval = 0; HKEY key; - DWORD retvallen = 0, disposition; + DWORD disposition; DWORD flags; remove_mount (posix); @@ -92,23 +95,24 @@ 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); HKEY kr = issystem ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; - if (RegCreateKeyEx (kr, buf, 0, "Cygwin", 0, KEY_ALL_ACCESS, + if (RegCreateKeyEx (kr, buf, 0, (char *) "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, + strlen (win32) + 1); flags = 0; if (!istext) flags |= MOUNT_BINARY; if (issystem) flags |= MOUNT_SYSTEM; - RegSetValueEx (key, "flags", 0, REG_DWORD, (BYTE *)&flags, sizeof (flags)); - - RegCloseKey(key); + RegSetValueEx (key, "flags", 0, REG_DWORD, (BYTE *) & flags, + sizeof (flags)); + + RegCloseKey (key); read_mounts (); } @@ -120,8 +124,7 @@ remove1 (HKEY rkey, const char *posix) sprintf (buf, "Software\\%s\\%s\\%s\\%s", CYGWIN_INFO_CYGNUS_REGISTRY_NAME, CYGWIN_INFO_CYGWIN_REGISTRY_NAME, - CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, - posix); + CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, posix); RegDeleteKey (rkey, buf); } @@ -144,28 +147,28 @@ set_cygdrive_flags (HKEY key, int istext, DWORD cygdrive_flags) else cygdrive_flags &= ~MOUNT_BINARY; RegSetValueEx (key, CYGWIN_INFO_CYGDRIVE_FLAGS, 0, REG_DWORD, - (BYTE *)&cygdrive_flags, sizeof (cygdrive_flags)); + (BYTE *) & cygdrive_flags, sizeof (cygdrive_flags)); } } static LONG -get_cygdrive_flags (HKEY key, DWORD *cygdrive_flags) +get_cygdrive_flags (HKEY key, DWORD * cygdrive_flags) { - DWORD retvallen = sizeof(*cygdrive_flags); + DWORD retvallen = sizeof (*cygdrive_flags); LONG status = RegQueryValueEx (key, CYGWIN_INFO_CYGDRIVE_FLAGS, 0, 0, - (BYTE *)cygdrive_flags, &retvallen); + (BYTE *) cygdrive_flags, &retvallen); return status; } static DWORD -default_cygdrive(HKEY key) +default_cygdrive (HKEY key) { RegSetValueEx (key, CYGWIN_INFO_CYGDRIVE_PREFIX, 0, REG_SZ, - (BYTE *)CYGWIN_INFO_CYGDRIVE_DEFAULT_PREFIX, + (BYTE *) CYGWIN_INFO_CYGDRIVE_DEFAULT_PREFIX, strlen (CYGWIN_INFO_CYGDRIVE_DEFAULT_PREFIX) + 1); DWORD cygdrive_flags = MOUNT_AUTO; RegSetValueEx (key, CYGWIN_INFO_CYGDRIVE_FLAGS, 0, REG_DWORD, - (BYTE *)&cygdrive_flags, sizeof (cygdrive_flags)); + (BYTE *) & cygdrive_flags, sizeof (cygdrive_flags)); return cygdrive_flags; } @@ -185,7 +188,7 @@ set_cygdrive_flags (int istext, int issystem) HKEY key; DWORD disposition; LONG status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, buf, 0, 0, 0, - KEY_ALL_ACCESS, 0, &key, &disposition); + KEY_ALL_ACCESS, 0, &key, &disposition); if (status == ERROR_SUCCESS) { DWORD cygdrive_flags = 0; @@ -195,14 +198,15 @@ set_cygdrive_flags (int istext, int issystem) set_cygdrive_flags (key, istext, cygdrive_flags); found_system = 1; } - RegCloseKey(key); + RegCloseKey (key); } } HKEY key; DWORD disposition; - LONG status = RegCreateKeyEx (HKEY_CURRENT_USER, buf, 0, 0, 0, KEY_ALL_ACCESS, - 0, &key, &disposition); + LONG status = + RegCreateKeyEx (HKEY_CURRENT_USER, buf, 0, 0, 0, KEY_ALL_ACCESS, + 0, &key, &disposition); if (status != ERROR_SUCCESS) fatal ("set_cygdrive_flags"); @@ -210,20 +214,20 @@ set_cygdrive_flags (int istext, int issystem) status = get_cygdrive_flags (key, &cygdrive_flags); if (status == ERROR_FILE_NOT_FOUND && !found_system) { - cygdrive_flags = default_cygdrive(key); + cygdrive_flags = default_cygdrive (key); status = ERROR_SUCCESS; } if (status == ERROR_SUCCESS) set_cygdrive_flags (key, istext, cygdrive_flags); - RegCloseKey(key); + RegCloseKey (key); } static int in_table (struct mnt *m) { - for (struct mnt *m1 = mount_table; m1 < m; m1++) + for (struct mnt * m1 = mount_table; m1 < m; m1++) if (strcasecmp (m1->posix, m->posix) == 0) return 1; return 0; @@ -247,7 +251,7 @@ is_admin () // Get the process token for the current process HANDLE token; - BOOL status = OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &token); + BOOL status = OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &token); if (!status) return 0; @@ -255,26 +259,33 @@ is_admin () UCHAR token_info[1024]; PTOKEN_GROUPS groups = (PTOKEN_GROUPS) token_info; DWORD token_info_len = sizeof (token_info); - status = GetTokenInformation (token, TokenGroups, token_info, token_info_len, &token_info_len); - CloseHandle(token); + status = + GetTokenInformation (token, TokenGroups, token_info, token_info_len, + &token_info_len); + CloseHandle (token); if (!status) return 0; // Create the Administrators group SID PSID admin_sid; - SID_IDENTIFIER_AUTHORITY authority = SECURITY_NT_AUTHORITY; - status = AllocateAndInitializeSid (&authority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &admin_sid); + SID_IDENTIFIER_AUTHORITY authority = { SECURITY_NT_AUTHORITY }; + status = + AllocateAndInitializeSid (&authority, 2, SECURITY_BUILTIN_DOMAIN_RID, + DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, + &admin_sid); if (!status) return 0; // Check to see if the user is a member of the Administrators group status = 0; - for (UINT i=0; iGroupCount; i++) { - if (EqualSid(groups->Groups[i].Sid, admin_sid)) { - status = 1; - break; + for (UINT i = 0; i < groups->GroupCount; i++) + { + if (EqualSid (groups->Groups[i].Sid, admin_sid)) + { + status = 1; + break; + } } - } // Destroy the Administrators group SID FreeSid (admin_sid); @@ -293,7 +304,7 @@ read_mounts () char buf[10000]; root_here = NULL; - for (mnt *m1 = mount_table; m1->posix; m1++) + for (mnt * m1 = mount_table; m1->posix; m1++) { free (m1->posix); if (m1->native) @@ -313,10 +324,10 @@ read_mounts () CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME); HKEY key = issystem ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; - if (RegCreateKeyEx (key, buf, 0, "Cygwin", 0, KEY_ALL_ACCESS, + if (RegCreateKeyEx (key, buf, 0, (char *) "Cygwin", 0, KEY_ALL_ACCESS, 0, &key, &disposition) != ERROR_SUCCESS) break; - for (int i = 0; ;i++, m++) + for (int i = 0;; i++, m++) { m->posix = (char *) malloc (MAX_PATH + 1); posix_path_size = MAX_PATH; @@ -342,7 +353,7 @@ read_mounts () m->native = find2 (key, &m->istext, m->posix); if (!m->native) goto no_go; - + if (strcmp (m->posix, "/") == 0) { root_here = m; @@ -371,7 +382,7 @@ read_mounts () m->posix = strdup ("/"); char windir[_MAX_PATH]; root_text = IDC_ROOT_BINARY; - root_scope = (is_admin()) ? IDC_ROOT_SYSTEM : IDC_ROOT_USER; + root_scope = (is_admin ())? IDC_ROOT_SYSTEM : IDC_ROOT_USER; GetWindowsDirectory (windir, sizeof (windir)); windir[2] = 0; set_root_dir (concat (windir, "\\cygwin", 0)); @@ -425,8 +436,8 @@ char * cygpath (const char *s, ...) { va_list v; - int i, max_len = -1; - struct mnt *m, *match; + int max_len = -1; + struct mnt *m, *match = NULL; va_start (v, s); char *path = vconcat (s, v); @@ -435,7 +446,7 @@ cygpath (const char *s, ...) 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; m++) { int n = strlen (m->posix); if (n < max_len || !path_prefix_p (m->posix, path, n)) @@ -444,8 +455,11 @@ cygpath (const char *s, ...) match = m; } + if (!match) + return NULL; + char *native; - if (max_len == strlen (path)) + if (max_len == (int) strlen (path)) native = strdup (match->native); else native = concat (match->native, "/", path + max_len, NULL); diff --git a/mount.h b/mount.h index f0b5374c..8a791cd7 100644 --- a/mount.h +++ b/mount.h @@ -17,13 +17,14 @@ nonzero if the existing mount is a text mount, else zero for binary. */ -char * find_mount (int *istext, int *issystem, char *path); +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, int issystem); -void remove_mount (const char *posix); -void read_mounts (); +void create_mount (const char *posix, const char *win32, int istext, + int issystem); +void remove_mount (const char *posix); +void read_mounts (); /* Sets the cygdrive flags. Used to make the automounted drives' binary/text mode consistent with the standard Cygwin mounts. */ diff --git a/msg.cc b/msg.cc index 496c2190..df558559 100644 --- a/msg.cc +++ b/msg.cc @@ -16,7 +16,10 @@ /* The purpose of this file is to centralize all the message functions. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include @@ -25,7 +28,7 @@ static char *cvsid = "\n%%% $Id$\n"; #include "log.h" void -msg (char *fmt, ...) +msg (const char *fmt, ...) { char buf[1000]; va_list args; @@ -35,7 +38,7 @@ msg (char *fmt, ...) } static int -mbox (char *name, int type, int id, va_list args) +mbox (const char *name, int type, int id, va_list args) { char buf[1000], fmt[1000]; diff --git a/msg.h b/msg.h index ddd37854..5c7523b1 100644 --- a/msg.h +++ b/msg.h @@ -17,7 +17,7 @@ OutputDebugString, which can be seen while debugging under GDB or via a debug message monitor. */ -void msg(char *fmt, ...); +void msg (const char *fmt, ...); /* This pops up a dialog with text from the string table ("id"), which is interpreted like printf. The program exits when the user diff --git a/net.cc b/net.cc index 37342350..6fd788b7 100644 --- a/net.cc +++ b/net.cc @@ -16,7 +16,10 @@ /* The purpose of this file is to get the network configuration information from the user. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include @@ -108,6 +111,7 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) NEXT (0); break; } + return 0; } static BOOL CALLBACK @@ -119,11 +123,14 @@ dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam) load_dialog (h); // Check to see if any radio buttons are selected. If not, select a default. - if ((!SendMessage(GetDlgItem (h, IDC_NET_IE5), BM_GETCHECK, 0, 0) == BST_CHECKED) - && (!SendMessage(GetDlgItem (h, IDC_NET_PROXY), BM_GETCHECK, 0, 0) == BST_CHECKED)) - { - SendMessage(GetDlgItem (h, IDC_NET_DIRECT), BM_CLICK, 0, 0); - } + if ( + (!SendMessage (GetDlgItem (h, IDC_NET_IE5), BM_GETCHECK, 0, 0) == + BST_CHECKED) + && (!SendMessage (GetDlgItem (h, IDC_NET_PROXY), BM_GETCHECK, 0, 0) + == BST_CHECKED)) + { + SendMessage (GetDlgItem (h, IDC_NET_DIRECT), BM_CLICK, 0, 0); + } return FALSE; case WM_COMMAND: return HANDLE_WM_COMMAND (h, wParam, lParam, dialog_cmd); @@ -145,4 +152,3 @@ do_net (HINSTANCE h) (net_method == IDC_NET_IE5) ? "IE5" : (net_method == IDC_NET_DIRECT) ? "Direct" : "Proxy"); } - diff --git a/netio.cc b/netio.cc index e76f0c95..6a4bcf32 100644 --- a/netio.cc +++ b/netio.cc @@ -17,7 +17,10 @@ methods known to setup. To add a new method, create a pair of nio-*.[ch] files and add the logic to NetIO::open here */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include @@ -78,7 +81,7 @@ NetIO::set_url (char *Purl) *ep = 0; proto = _strdup (bp); *ep = ':'; - bp = ep+3; + bp = ep + 3; ep = bp + strcspn (bp, ":/"); c = *ep; @@ -88,7 +91,7 @@ NetIO::set_url (char *Purl) if (*ep == ':') { - port = atoi (ep+1); + port = atoi (ep + 1); ep = strchr (ep, '/'); } @@ -112,7 +115,9 @@ NetIO * NetIO::open (char *url, BOOL allow_ftp_auth) { NetIO *rv = 0; - enum {http, ftp, file} proto; + enum + { http, ftp, file } + proto; if (strncmp (url, "http://", 7) == 0) proto = http; else if (strncmp (url, "ftp://", 6) == 0) @@ -136,6 +141,9 @@ NetIO::open (char *url, BOOL allow_ftp_auth) case ftp: rv = new NetIO_FTP (url, allow_ftp_auth); break; + case file: + rv = new NetIO_File (url); + break; } } @@ -203,6 +211,7 @@ auth_cmd (HWND h, int id, HWND hwndctl, UINT code) exit_setup (1); break; } + return 0; } static BOOL CALLBACK diff --git a/netio.h b/netio.h index 9cd47e1a..046d4d4d 100644 --- a/netio.h +++ b/netio.h @@ -16,7 +16,8 @@ /* This is the parent class for all the access methods known to setup (i.e. ways to download files from the internet or other sources */ -class NetIO { +class NetIO +{ protected: NetIO (char *url, BOOL allow_ftp_auth = FALSE); void set_url (char *url); @@ -31,13 +32,13 @@ public: char *host; int port; char *path; - virtual ~NetIO (); + virtual ~ NetIO (); /* The user calls this function to create a suitable accessor for the given URL. It uses the network setup state in state.h. If anything fails, either the return values is NULL or the returned object is !ok() */ - static NetIO * open (char *url, BOOL allow_ftp_auth = FALSE); + static NetIO *open (char *url, BOOL allow_ftp_auth = FALSE); /* If !ok() that means the transfer isn't happening. */ virtual int ok (); diff --git a/nio-file.cc b/nio-file.cc index d4ee4316..9b55a040 100644 --- a/nio-file.cc +++ b/nio-file.cc @@ -16,7 +16,10 @@ /* The purpose of this file is to manage access to files stored on the local disk (i.e. "downloading" setup.ini). Called from netio.cc */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include @@ -29,18 +32,17 @@ static char *cvsid = "\n%%% $Id$\n"; #include "msg.h" #include "filemanip.h" -NetIO_File::NetIO_File (char *Purl) - : NetIO (Purl) +NetIO_File::NetIO_File (char *Purl): +NetIO (Purl) { - struct stat s; fd = fopen (path, "rb"); if (fd) { - file_size = get_file_size(path); + file_size = get_file_size (path); } else { - char *err = strerror (errno); + const char *err = strerror (errno); if (!err) err = "(unknown error)"; note (IDS_ERR_OPEN_READ, path, err); @@ -50,7 +52,7 @@ NetIO_File::NetIO_File (char *Purl) NetIO_File::~NetIO_File () { if (fd) - fclose ((FILE *)fd); + fclose ((FILE *) fd); } int @@ -62,5 +64,5 @@ NetIO_File::ok () int NetIO_File::read (char *buf, int nbytes) { - return fread (buf, 1, nbytes, (FILE *)fd); + return fread (buf, 1, nbytes, (FILE *) fd); } diff --git a/nio-file.h b/nio-file.h index 6d2eb928..9989941e 100644 --- a/nio-file.h +++ b/nio-file.h @@ -15,11 +15,12 @@ /* see nio-file.cc */ -class NetIO_File : public NetIO { +class NetIO_File:public NetIO +{ public: NetIO_File (char *url); void *fd; - ~NetIO_File (); + ~NetIO_File (); virtual int ok (); virtual int read (char *buf, int nbytes); }; diff --git a/nio-ftp.cc b/nio-ftp.cc index c0d0bbc9..33d4cc35 100644 --- a/nio-ftp.cc +++ b/nio-ftp.cc @@ -17,7 +17,8 @@ channels. It is intentionally simplistic. */ #if 0 -static const char *cvsid = "\n%%% $Id$\n"; +static const char *cvsid = + "\n%%% $Id$\n"; #endif #include "win32.h" @@ -41,20 +42,22 @@ static int cmd_port = 0; static char *last_line; static int -ftp_line (SimpleSocket *s) +ftp_line (SimpleSocket * s) { - do { - last_line = s->gets (); - log (LOG_BABBLE, "ftp > %s", last_line ? last_line : "error"); - } while (last_line && (!isdigit (last_line[0]) || last_line[3] != ' ')); - return atoi (last_line ?: "0"); + do + { + last_line = s->gets (); + log (LOG_BABBLE, "ftp > %s", last_line ? last_line : "error"); + } + while (last_line && (!isdigit (last_line[0]) || last_line[3] != ' ')); + return atoi (last_line ? : "0"); } -NetIO_FTP::NetIO_FTP (char *Purl, BOOL allow_ftp_auth) - : NetIO (Purl, allow_ftp_auth) +NetIO_FTP::NetIO_FTP (char *Purl, BOOL allow_ftp_auth):NetIO (Purl, allow_ftp_auth) { s = 0; - int code; + int + code; if (port == 0) port = 21; @@ -63,7 +66,8 @@ NetIO_FTP::NetIO_FTP (char *Purl, BOOL allow_ftp_auth) { if (cmd) cmd->printf ("QUIT\r\n"); - delete cmd; + delete + cmd; free (cmd_host); cmd = 0; cmd_host = 0; @@ -71,14 +75,15 @@ NetIO_FTP::NetIO_FTP (char *Purl, BOOL allow_ftp_auth) if (cmd == 0) { - SimpleSocket *c = new SimpleSocket (host, port); + SimpleSocket * + c = new SimpleSocket (host, port); code = ftp_line (c); -auth_retry: + auth_retry: if (net_ftp_user) - c->printf ("USER %s\r\n", net_ftp_user); + c->printf ("USER %s\r\n", net_ftp_user); else - c->printf ("USER anonymous\r\n"); + c->printf ("USER anonymous\r\n"); code = ftp_line (c); if (code == 331) { @@ -88,8 +93,8 @@ auth_retry: c->printf ("PASS cygwin-setup@\r\n"); code = ftp_line (c); } - if (code == 530) /* Authentication failed, retry */ - { + if (code == 530) /* Authentication failed, retry */ + { get_ftp_auth (); if (net_ftp_user && net_ftp_passwd) goto auth_retry; @@ -97,7 +102,8 @@ auth_retry: if (code < 200 || code >= 300) { - delete c; + delete + c; return; } @@ -110,27 +116,33 @@ auth_retry: } cmd->printf ("PASV\r\n"); - do { - code = ftp_line (cmd); - } while (code == 226); /* previous RETR */ + do + { + code = ftp_line (cmd); + } + while (code == 226); /* previous RETR */ if (code != 227) return; - char *paren = strchr (last_line, '('); + char * + paren = strchr (last_line, '('); if (!paren) return; - int i1, i2, i3, i4, p1, p2; - sscanf (paren+1, "%d,%d,%d,%d,%d,%d", &i1, &i2, &i3, &i4, &p1, &p2); - char tmp[20]; + int + i1, i2, i3, i4, p1, p2; + sscanf (paren + 1, "%d,%d,%d,%d,%d,%d", &i1, &i2, &i3, &i4, &p1, &p2); + char + tmp[20]; sprintf (tmp, "%d.%d.%d.%d", i1, i2, i3, i4); - s = new SimpleSocket (tmp, p1*256 + p2); + s = new SimpleSocket (tmp, p1 * 256 + p2); cmd->printf ("RETR %s\r\n", path); code = ftp_line (cmd); if (code != 150 && code != 125) { - delete s; + delete + s; s = 0; return; } diff --git a/nio-ftp.h b/nio-ftp.h index d4567b1e..0f84e8cf 100644 --- a/nio-ftp.h +++ b/nio-ftp.h @@ -17,12 +17,13 @@ class SimpleSocket; -class NetIO_FTP : public NetIO { +class NetIO_FTP:public NetIO +{ SimpleSocket *s; public: - NetIO_FTP (char *url, BOOL allow_ftp_auth = FALSE); - virtual ~NetIO_FTP (); + NetIO_FTP (char *url, BOOL allow_ftp_auth = FALSE); + virtual ~ NetIO_FTP (); /* If !ok() that means the transfer isn't happening. */ virtual int ok (); diff --git a/nio-http.cc b/nio-http.cc index 7f17aa50..f452e48d 100644 --- a/nio-http.cc +++ b/nio-http.cc @@ -17,7 +17,8 @@ channels. It is intentionally simplistic. */ #if 0 -static const char *cvsid = "\n%%% $Id$\n"; +static const char *cvsid = + "\n%%% $Id$\n"; #endif #include "win32.h" @@ -35,11 +36,11 @@ static const char *cvsid = "\n%%% $Id$\n"; #include "nio-http.h" static char six2pr[64] = { - 'A','B','C','D','E','F','G','H','I','J','K','L','M', - 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z', - 'a','b','c','d','e','f','g','h','i','j','k','l','m', - 'n','o','p','q','r','s','t','u','v','w','x','y','z', - '0','1','2','3','4','5','6','7','8','9','+','/' + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; static char * @@ -56,7 +57,7 @@ base64_encode (char *username, char *password) strcpy (up, username); strcat (up, ":"); strcat (up, password); - ep = (unsigned char *)up + strlen (up); + ep = (unsigned char *) up + strlen (up); *ep++ = 0; *ep++ = 0; *ep++ = 0; @@ -65,7 +66,7 @@ base64_encode (char *username, char *password) rp = rv; - for (ep = (unsigned char *)up; *ep; ep += 3) + for (ep = (unsigned char *) up; *ep; ep += 3) { block[0] = six2pr[ep[0] >> 2]; block[1] = six2pr[((ep[0] << 4) & 0x30) | ((ep[1] >> 4) & 0x0f)]; @@ -86,10 +87,9 @@ base64_encode (char *username, char *password) return rv; } -NetIO_HTTP::NetIO_HTTP (char *Purl, BOOL allow_ftp_auth) - : NetIO (Purl, allow_ftp_auth) +NetIO_HTTP::NetIO_HTTP (char *Purl, BOOL allow_ftp_auth):NetIO (Purl, allow_ftp_auth) { - retry_get: +retry_get: if (port == 0) port = 80; @@ -98,9 +98,10 @@ NetIO_HTTP::NetIO_HTTP (char *Purl, BOOL allow_ftp_auth) else s = new SimpleSocket (host, port); - if (!s->ok()) + if (!s->ok ()) { - delete s; + delete + s; s = NULL; return; } @@ -121,61 +122,69 @@ NetIO_HTTP::NetIO_HTTP (char *Purl, BOOL allow_ftp_auth) s->printf ("\r\n"); - char *l = s->gets (); - int code; + char * + l = s->gets (); + int + code; if (!l) return; sscanf (l, "%*s %d", &code); if (code >= 300 && code < 400) { - while ((l = s->gets ()) != 0) { - if (_strnicmp (l, "Location:", 9) == 0) - { - char *u = l + 9; - while (*u == ' ' || *u == '\t') - u++; - set_url (u); - delete s; - goto retry_get; - } - } + while ((l = s->gets ()) != 0) + { + if (_strnicmp (l, "Location:", 9) == 0) + { + char * + u = l + 9; + while (*u == ' ' || *u == '\t') + u++; + set_url (u); + delete + s; + goto retry_get; + } + } } - if (code == 401) /* authorization required */ + if (code == 401) /* authorization required */ { get_auth (); - delete s; + delete + s; goto retry_get; } - if (code == 407) /* proxy authorization required */ + if (code == 407) /* proxy authorization required */ { get_proxy_auth (); - delete s; + delete + s; goto retry_get; } - if (code == 500 /* ftp authentication through proxy required */ - && net_method == IDC_NET_PROXY - && !strncmp (url, "ftp://", 6)) + if (code == 500 /* ftp authentication through proxy required */ + && net_method == IDC_NET_PROXY && !strncmp (url, "ftp://", 6)) { get_ftp_auth (); if (net_ftp_user && net_ftp_passwd) - { - delete s; + { + delete + s; url = concat ("ftp://", net_ftp_user, - ":", net_ftp_passwd, - "@", url + 6, 0); - goto retry_get; + ":", net_ftp_passwd, "@", url + 6, 0); + goto retry_get; } } if (code >= 300) { - delete s; + delete + s; s = 0; return; } - while ((l = s->gets ()) != 0) { - if (_strnicmp (l, "Content-Length:", 15) == 0) - sscanf (l, "%*s %d", &file_size); - } + while ((l = s->gets ()) != 0) + { + if (_strnicmp (l, "Content-Length:", 15) == 0) + sscanf (l, "%*s %d", &file_size); + } } NetIO_HTTP::~NetIO_HTTP () diff --git a/nio-http.h b/nio-http.h index 5206c11e..ad2a76ea 100644 --- a/nio-http.h +++ b/nio-http.h @@ -17,12 +17,13 @@ class SimpleSocket; -class NetIO_HTTP : public NetIO { +class NetIO_HTTP:public NetIO +{ SimpleSocket *s; public: - NetIO_HTTP (char *url, BOOL allow_ftp_auth = FALSE); - virtual ~NetIO_HTTP (); + NetIO_HTTP (char *url, BOOL allow_ftp_auth = FALSE); + virtual ~ NetIO_HTTP (); /* If !ok() that means the transfer isn't happening. */ virtual int ok (); diff --git a/nio-ie5.cc b/nio-ie5.cc index 912d4f55..fb3843e8 100644 --- a/nio-ie5.cc +++ b/nio-ie5.cc @@ -18,7 +18,10 @@ must already have installed and configured IE5. This module is called from netio.cc, which is called from geturl.cc */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" @@ -31,8 +34,8 @@ static char *cvsid = "\n%%% $Id$\n"; static HINTERNET internet = 0; -NetIO_IE5::NetIO_IE5 (char *_url) - : NetIO (_url) +NetIO_IE5::NetIO_IE5 (char *_url): +NetIO (_url) { int resend = 0; @@ -55,12 +58,11 @@ NetIO_IE5::NetIO_IE5 (char *_url) INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD | - INTERNET_FLAG_EXISTING_CONNECT | - INTERNET_FLAG_PASSIVE; + INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_PASSIVE; connection = InternetOpenUrl (internet, url, NULL, 0, flags, 0); - try_again: +try_again: if (net_user && net_passwd) { @@ -87,7 +89,7 @@ NetIO_IE5::NetIO_IE5 (char *_url) if (GetLastError () == ERROR_INTERNET_EXTENDED_ERROR) { char buf[2000]; - DWORD e, l=sizeof (buf); + DWORD e, l = sizeof (buf); InternetGetLastResponseInfo (&e, buf, &l); MessageBox (0, buf, "Internet Error", 0); } @@ -107,16 +109,16 @@ NetIO_IE5::NetIO_IE5 (char *_url) HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &type, &type_s, NULL)) { - if (type == 401) /* authorization required */ + if (type == 401) /* authorization required */ { - flush_io(); + flush_io (); get_auth (); resend = 1; goto try_again; } - else if (type == 407) /* proxy authorization required */ + else if (type == 407) /* proxy authorization required */ { - flush_io(); + flush_io (); get_proxy_auth (); resend = 1; goto try_again; @@ -135,9 +137,11 @@ NetIO_IE5::flush_io () { DWORD actual = 0; char buf[1024]; - do { - InternetReadFile (connection, buf, 1024, &actual); - } while (actual > 0); + do + { + InternetReadFile (connection, buf, 1024, &actual); + } + while (actual > 0); } NetIO_IE5::~NetIO_IE5 () diff --git a/nio-ie5.h b/nio-ie5.h index 4cc71d56..5b6e9253 100644 --- a/nio-ie5.h +++ b/nio-ie5.h @@ -15,12 +15,13 @@ /* see nio-ie5.cc */ -class NetIO_IE5 : public NetIO { +class NetIO_IE5:public NetIO +{ HINTERNET connection; public: - NetIO_IE5 (char *url); - ~NetIO_IE5 (); + NetIO_IE5 (char *url); + ~NetIO_IE5 (); virtual int ok (); virtual int read (char *buf, int nbytes); - void flush_io(); + void flush_io (); }; diff --git a/other.cc b/other.cc index f44f8245..f8625c2c 100644 --- a/other.cc +++ b/other.cc @@ -16,7 +16,10 @@ /* This handles the "other URL" option from the mirror site selection. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include @@ -76,6 +79,7 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) NEXT (0); break; } + return 0; } static BOOL CALLBACK @@ -102,4 +106,3 @@ do_other (HINSTANCE h) log (0, "site: %s", other_url); } - diff --git a/port.h b/port.h index c2c019ad..5f0f6ae2 100644 --- a/port.h +++ b/port.h @@ -24,5 +24,4 @@ #define _access access #define _strdup strdup - #endif diff --git a/postinstall.cc b/postinstall.cc index 34987bd8..977408c2 100644 --- a/postinstall.cc +++ b/postinstall.cc @@ -16,7 +16,10 @@ /* The purpose of this file is to run all the post-install scripts in their various forms. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" @@ -32,14 +35,14 @@ static char *cvsid = "\n%%% $Id$\n"; #include "port.h" static char *sh = 0; -static char *cmd = 0; +static const char *cmd = 0; static OSVERSIONINFO verinfo; static void -run (char *sh, char *args, char *file) +run (const char *sh, const char *args, const char *file) { BOOL b; - char cmdline [_MAX_PATH]; + char cmdline[_MAX_PATH]; STARTUPINFO si; PROCESS_INFORMATION pi; @@ -47,7 +50,7 @@ run (char *sh, char *args, char *file) memset (&pi, 0, sizeof (pi)); memset (&si, 0, sizeof (si)); si.cb = sizeof (si); - si.lpTitle = "Cygwin Setup Post-Install Script"; + si.lpTitle = (char *) "Cygwin Setup Post-Install Script"; si.dwFlags = STARTF_USEPOSITION; b = CreateProcess (0, cmdline, 0, 0, 0, @@ -86,7 +89,7 @@ each (char *fname, unsigned int size) cygpath ("/etc/postinstall/", fname, ".done", 0)); } -static char *shells [] = { +static const char *shells[] = { "/bin/sh.exe", "/usr/bin/sh.exe", "/bin/bash.exe", @@ -99,7 +102,7 @@ do_postinstall (HINSTANCE h) { next_dialog = 0; int i; - for (i=0; shells[i]; i++) + for (i = 0; shells[i]; i++) { sh = backslash (cygpath (shells[i], 0)); if (_access (sh, 0) == 0) @@ -112,8 +115,8 @@ do_postinstall (HINSTANCE h) GetEnvironmentVariable ("PATH", old_path, sizeof (old_path)); SetEnvironmentVariable ("PATH", backslash (cygpath ("/bin;", - get_root_dir (), "/usr/bin;", - old_path, 0))); + get_root_dir (), "/usr/bin;", + old_path, 0))); SetEnvironmentVariable ("CYGWINROOT", get_root_dir ()); SetCurrentDirectory (get_root_dir ()); diff --git a/root.cc b/root.cc index 8ecda171..98dfd6fa 100644 --- a/root.cc +++ b/root.cc @@ -17,7 +17,10 @@ root of the installation to be, and to ask whether the user prefers text or binary mounts. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include @@ -39,7 +42,8 @@ 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 () && root_scope); + EnableWindow (GetDlgItem (h, IDOK), root_text && get_root_dir () + && root_scope); } static void @@ -143,7 +147,7 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) case IDOK: save_dialog (h); - if (! directory_is_absolute ()) + if (!directory_is_absolute ()) { note (IDS_ROOT_ABSOLUTE); break; @@ -169,6 +173,7 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) NEXT (0); break; } + return 0; } static BOOL CALLBACK @@ -199,4 +204,3 @@ do_root (HINSTANCE h) (root_text == IDC_ROOT_TEXT) ? "text" : "binary", (root_scope == IDC_ROOT_USER) ? "user" : "system"); } - diff --git a/simpsock.cc b/simpsock.cc index 880b2a58..5a98386f 100644 --- a/simpsock.cc +++ b/simpsock.cc @@ -16,7 +16,8 @@ /* Simplified socket access functions */ #if 0 -static const char *cvsid = "\n%%% $Id$\n"; +static const char *cvsid = + "\n%%% $Id$\n"; #endif #include "win32.h" @@ -37,7 +38,7 @@ SimpleSocket::SimpleSocket (const char *hostname, int port) { initted = 1; WSADATA d; - WSAStartup (MAKEWORD (1,1), &d); + WSAStartup (MAKEWORD (1, 1), &d); } s = INVALID_SOCKET; @@ -80,7 +81,7 @@ SimpleSocket::SimpleSocket (const char *hostname, int port) name.sin_port = htons (port); memcpy (&name.sin_addr, ip, 4); - if (connect (s, (sockaddr *)&name, sizeof(name))) + if (connect (s, (sockaddr *) & name, sizeof (name))) { msg ("Can't connect to %s:%d", hostname, port); closesocket (s); @@ -146,7 +147,7 @@ SimpleSocket::fill () } else if (r < 0 && putp == getp) { - invalidate(); + invalidate (); } return r; } @@ -156,7 +157,7 @@ SimpleSocket::gets () { if (getp > 0 && putp > getp) { - memmove (buf, buf+getp, putp-getp); + memmove (buf, buf + getp, putp - getp); putp -= getp; getp = 0; } @@ -166,7 +167,7 @@ SimpleSocket::gets () // getp is zero, always, here, and putp is the count char *nl; - while ((nl = (char *)memchr (buf, '\n', putp)) == NULL && putp < SSBUFSZ) + while ((nl = (char *) memchr (buf, '\n', putp)) == NULL && putp < SSBUFSZ) if (fill () <= 0) break; @@ -196,11 +197,11 @@ SimpleSocket::read (char *ubuf, int ulen) if (!ok ()) return -1; - int n, rv=0; + int n, rv = 0; if (putp > getp) { - n = MIN (ulen, putp-getp); - memmove (ubuf, buf+getp, n); + n = MIN (ulen, putp - getp); + memmove (ubuf, buf + getp, n); getp += n; ubuf += n; ulen -= n; @@ -210,9 +211,9 @@ SimpleSocket::read (char *ubuf, int ulen) { n = recv (s, ubuf, ulen, 0); if (n < 0) - invalidate(); + invalidate (); if (n <= 0) - return rv > 0 ? rv : n; + return rv > 0 ? rv : n; ubuf += n; ulen -= n; rv += n; diff --git a/simpsock.h b/simpsock.h index e09e6612..6f678ec1 100644 --- a/simpsock.h +++ b/simpsock.h @@ -15,7 +15,8 @@ /* Simplified socket access functions */ -class SimpleSocket { +class SimpleSocket +{ SOCKET s; char *buf; @@ -23,9 +24,9 @@ class SimpleSocket { int fill (); void invalidate (void); - public: - SimpleSocket (const char *hostname, int port); - ~SimpleSocket (); +public: + SimpleSocket (const char *hostname, int port); + ~SimpleSocket (); int ok (); @@ -33,5 +34,5 @@ class SimpleSocket { int write (const char *buf, int len); char *gets (); - int read (char *buf, int len); + int read (char *buf, int len); }; diff --git a/site.cc b/site.cc index 8172caad..7338630a 100644 --- a/site.cc +++ b/site.cc @@ -16,7 +16,10 @@ /* The purpose of this file is to get the list of mirror sites and ask the user which mirror site they want to download from. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include @@ -29,19 +32,21 @@ static char *cvsid = "\n%%% $Id$\n"; #include "geturl.h" #include "msg.h" #include "concat.h" -#include "mount.h" #include "log.h" +#include "io_stream.h" #include "port.h" #define NO_IDX (-1) #define OTHER_IDX (-2) -typedef struct { +typedef struct +{ char *url; char *displayed_url; char *sort_key; -} site_list_type; +} +site_list_type; static site_list_type *site_list = 0; static int list_idx = NO_IDX; @@ -82,31 +87,21 @@ save_dialog (HWND h) } } -static void -get_root_dir_now () -{ - int istext; - int issystem; - if (get_root_dir ()) - return; - read_mounts (); -} - void save_site_url () { - if (! MIRROR_SITE) - return; - - get_root_dir_now (); - if (!get_root_dir ()) + if (!MIRROR_SITE) return; - FILE *f = fopen (cygpath ("/etc/setup/last-mirror", 0), "wb"); - if (!f) - return; - fprintf (f, "%s\n", MIRROR_SITE); - fclose (f); + io_stream *f = io_stream::open ("cygfile:///etc/setup/last-mirror", "wb"); + if (f) + { + char temp[_MAX_PATH]; + /* TODO: potential buffer overflow. we need snprintf asap. */ + sprintf (temp, "%s\n", MIRROR_SITE); + f->write (temp, strlen (temp)); + delete f; + } } static BOOL @@ -141,6 +136,7 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) NEXT (0); break; } + return 0; } static BOOL CALLBACK @@ -152,12 +148,14 @@ dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam) { case WM_INITDIALOG: listbox = GetDlgItem (h, IDC_URL_LIST); - for (i=0; site_list[i].url; i++) + for (i = 0; site_list[i].url; i++) { - j = SendMessage (listbox, LB_ADDSTRING, 0, (LPARAM)site_list[i].displayed_url); + j = + SendMessage (listbox, LB_ADDSTRING, 0, + (LPARAM) site_list[i].displayed_url); SendMessage (listbox, LB_SETITEMDATA, j, i); } - j = SendMessage (listbox, LB_ADDSTRING, 0, (LPARAM)"Other URL"); + j = SendMessage (listbox, LB_ADDSTRING, 0, (LPARAM) "Other URL"); SendMessage (listbox, LB_SETITEMDATA, j, OTHER_IDX); load_dialog (h); return FALSE; @@ -170,8 +168,8 @@ dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam) static int site_sort (const void *va, const void *vb) { - site_list_type *a = (site_list_type *)va; - site_list_type *b = (site_list_type *)vb; + site_list_type *a = (site_list_type *) va; + site_list_type *b = (site_list_type *) vb; return strcmp (a->sort_key, b->sort_key); } @@ -190,10 +188,10 @@ get_site_list (HINSTANCE h) /* null plus account for possibly missing NL plus account for "Other - URL" from previous run. */ + URL" from previous run. */ int nmirrors = 3; - for (bol=mirrors; *bol; bol++) + for (bol = mirrors; *bol; bol++) if (*bol == '\n') nmirrors++; @@ -204,9 +202,9 @@ get_site_list (HINSTANCE h) while (*nl) { bol = nl; - for (eol = bol; *eol && *eol != '\n'; eol++) ; + for (eol = bol; *eol && *eol != '\n'; eol++); if (*eol) - nl = eol+1; + nl = eol + 1; else nl = eol; while (eol > bol && eol[-1] == '\r') @@ -226,7 +224,8 @@ get_site_list (HINSTANCE h) if (dot) *dot = 0; } - site_list[nmirrors].sort_key = (char *) malloc (2*strlen (bol) + 3); + site_list[nmirrors].sort_key = + (char *) malloc (2 * strlen (bol) + 3); dot = site_list[nmirrors].displayed_url; dot += strlen (dot); @@ -237,8 +236,8 @@ get_site_list (HINSTANCE h) { char *sp; if (dot[3] == 0) - *dp++ = '~'; /* sort .com/.edu/.org together */ - for (sp=dot+1; *sp && *sp != '.' && *sp != '/';) + *dp++ = '~'; /* sort .com/.edu/.org together */ + for (sp = dot + 1; *sp && *sp != '.' && *sp != '/';) *dp++ = *sp++; *dp++ = ' '; } @@ -269,19 +268,14 @@ get_site_list (HINSTANCE h) static void get_initial_list_idx () { - get_root_dir_now (); - if (!get_root_dir ()) - return; - - FILE *f = fopen (cygpath ("/etc/setup/last-mirror", 0), "rt"); + io_stream *f = io_stream::open ("cygfile:///etc/setup/last-mirror", "rt"); if (!f) return; char site[1000]; - site[0]='\0'; - char * fg_ret = fgets (site, 1000, f); - fclose (f); - if (! fg_ret) + char *fg_ret = f->gets (site, 1000); + delete f; + if (!fg_ret) return; char *eos = site + strlen (site) - 1; @@ -296,17 +290,16 @@ get_initial_list_idx () if (strcmp (site_list[i].url, site) == 0) break; - if (! site_list[i].url) + if (!site_list[i].url) { /* Don't default to certain machines ever since they suffer - from bandwidth limitations. */ + from bandwidth limitations. */ if (strnicmp (site, NOSAVE1, NOSAVE1_LEN) == 0 || strnicmp (site, NOSAVE2, NOSAVE2_LEN) == 0 || strnicmp (site, NOSAVE3, NOSAVE3_LEN) == 0) return; - site_list[i].displayed_url = - site_list[i].url = _strdup (site); - site_list[i+1].url = 0; + site_list[i].displayed_url = site_list[i].url = _strdup (site); + site_list[i + 1].url = 0; } mirror_idx = list_idx = i; @@ -333,4 +326,3 @@ do_site (HINSTANCE h) if (mirror_idx != OTHER_IDX) log (0, "site: %s", mirror_site); } - diff --git a/source.cc b/source.cc index 63688698..40f23bdf 100644 --- a/source.cc +++ b/source.cc @@ -17,7 +17,10 @@ user choose the source of the install - from the net, from the current directory, or to just download files. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include @@ -27,25 +30,18 @@ static char *cvsid = "\n%%% $Id$\n"; #include "msg.h" #include "log.h" -static int rb[] = { IDC_SOURCE_NETINST, IDC_SOURCE_DOWNLOAD, IDC_SOURCE_CWD, 0 }; - -static void -check_if_enable_next (HWND h) -{ - EnableWindow (GetDlgItem (h, IDOK), source ? 1 : 0); -} +static int rb[] = + { IDC_SOURCE_NETINST, IDC_SOURCE_DOWNLOAD, IDC_SOURCE_CWD, 0 }; static void load_dialog (HWND h) { - int i; rbset (h, rb, source); } static void save_dialog (HWND h) { - int i; source = rbget (h, rb); } @@ -78,6 +74,7 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) default: break; } + return 0; } static BOOL CALLBACK @@ -88,11 +85,16 @@ dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam) case WM_INITDIALOG: load_dialog (h); // Check to see if any radio buttons are selected. If not, select a default. - if ((!SendMessage(GetDlgItem (h, IDC_SOURCE_DOWNLOAD), BM_GETCHECK, 0, 0) == BST_CHECKED) - && (!SendMessage(GetDlgItem (h, IDC_SOURCE_CWD), BM_GETCHECK, 0, 0) == BST_CHECKED)) - { - SendMessage(GetDlgItem (h, IDC_SOURCE_NETINST), BM_SETCHECK, BST_CHECKED, 0); - } + if ( + (!SendMessage + (GetDlgItem (h, IDC_SOURCE_DOWNLOAD), BM_GETCHECK, 0, + 0) == BST_CHECKED) + && (!SendMessage (GetDlgItem (h, IDC_SOURCE_CWD), BM_GETCHECK, 0, 0) + == BST_CHECKED)) + { + SendMessage (GetDlgItem (h, IDC_SOURCE_NETINST), BM_SETCHECK, + BST_CHECKED, 0); + } return FALSE; case WM_COMMAND: return HANDLE_WM_COMMAND (h, wParam, lParam, dialog_cmd); @@ -104,7 +106,7 @@ void do_source (HINSTANCE h) { int rv = 0; - /* source = IDC_SOURCE_CWD;*/ + /* source = IDC_SOURCE_CWD; */ source = IDC_SOURCE_NETINST; rv = DialogBox (h, MAKEINTRESOURCE (IDD_SOURCE), 0, dialog_proc); if (rv == -1) @@ -114,4 +116,3 @@ do_source (HINSTANCE h) (source == IDC_SOURCE_DOWNLOAD) ? "download" : (source == IDC_SOURCE_NETINST) ? "network install" : "from cwd"); } - diff --git a/splash.cc b/splash.cc index c437630c..f31375e5 100644 --- a/splash.cc +++ b/splash.cc @@ -16,7 +16,10 @@ /* The purpose of this file is to display the program name, version, copyright notice, and project URL. */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #include "win32.h" #include @@ -49,6 +52,7 @@ dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) NEXT (0); break; } + return 0; } static BOOL CALLBACK @@ -73,4 +77,3 @@ do_splash (HINSTANCE h) if (rv == -1) fatal (IDS_DIALOG_FAILED); } - diff --git a/state.cc b/state.cc index ccac2e94..66c61fcd 100644 --- a/state.cc +++ b/state.cc @@ -15,7 +15,10 @@ /* All we do here is instantiate the extern'd variables from state.h */ -static char *cvsid = "\n%%% $Id$\n"; +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif #define extern #include "state.h" diff --git a/state.h b/state.h index eb695d2d..d3fb88cd 100644 --- a/state.h +++ b/state.h @@ -18,29 +18,29 @@ information that the user has provided so far. These are set by the various dialogs and used by the various actions. */ -extern int source; +extern int source; -extern char * local_dir; +extern char *local_dir; -extern int root_text; -extern int root_scope; -extern int root_menu; -extern int root_desktop; +extern int root_text; +extern int root_scope; +extern int root_menu; +extern int root_desktop; -extern int net_method; -extern char * net_proxy_host; -extern int net_proxy_port; +extern int net_method; +extern char *net_proxy_host; +extern int net_proxy_port; -extern char * net_user; -extern char * net_passwd; -extern char * net_proxy_user; -extern char * net_proxy_passwd; -extern char * net_ftp_user; -extern char * net_ftp_passwd; +extern char *net_user; +extern char *net_passwd; +extern char *net_proxy_user; +extern char *net_proxy_passwd; +extern char *net_ftp_user; +extern char *net_ftp_passwd; -extern char * mirror_site; -extern char * other_url; +extern char *mirror_site; +extern char *other_url; -extern int trust_level; +extern int trust_level; #define MIRROR_SITE (mirror_site ? mirror_site : other_url) diff --git a/tar.cc b/tar.cc deleted file mode 100644 index 7d16a84e..00000000 --- a/tar.cc +++ /dev/null @@ -1,567 +0,0 @@ -/* - * Copyright (c) 2000, 2001, Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * A copy of the GNU General Public License can be found at - * http://www.gnu.org/ - * - * Written by DJ Delorie - * - */ - -/* Built-in tar functionality. See tar.h for usage. */ - -static char *cvsid = "\n%%% $Id$\n"; - -#include "win32.h" -#include -#include -#include -#include - -#include "zlib/zlib.h" -#include "tar.h" -#include "mkdir.h" -#include "log.h" -#include "filemanip.h" - -#include "port.h" -#undef _WIN32 -#include "bzlib.h" - -#define FACTOR (0x19db1ded53ea710LL) -#define NSPERSEC 10000000LL -#define SYMLINK_COOKIE "!" - -typedef struct { - char name[100]; /* 0 */ - char mode[8]; /* 100 */ - char uid[8]; /* 108 */ - char gid[8]; /* 116 */ - char size[12]; /* 124 */ - char mtime[12]; /* 136 */ - char chksum[8]; /* 148 */ - char typeflag; /* 156 */ - char linkname[100]; /* 157 */ - char magic[6]; /* 257 */ - char version[2]; /* 263 */ - char uname[32]; /* 265 */ - char gname[32]; /* 297 */ - char devmajor[8]; /* 329 */ - char devminor[8]; /* 337 */ - char prefix[155]; /* 345 */ - char junk[12]; /* 500 */ -} tar_header_type; - -typedef struct tar_map_result_type_s { - struct tar_map_result_type_s *next; - char *stored_name; - char *mapped_name; -} tar_map_result_type; - -static tar_map_result_type *tar_map_result = 0; - -static int err; - -static char file_name[_MAX_PATH+512]; -static char have_longname = 0; -static int file_length; - -static tar_header_type tar_header; -static char buf[512]; - -static int _tar_file_size = 0; -int _tar_verbose = 0; -FILE * _tar_vfile = 0; -#define vp if (_tar_verbose) fprintf -#define vp2 if (_tar_verbose>1) fprintf - -class gzbz -{ - protected: - union - { - gzFile g; - BZFILE *b; - }; - int fd; -public: - virtual int read (void *buf, int len) {}; - virtual int close () {}; - virtual off_t tell () {}; - operator int () {return (int) g;} -}; - -class gz: public gzbz -{ - public: - gz (const char *pathname) - { - g = gzopen (pathname, "rb"); - } - int read (void *buf, int len) - { - return gzread (g, buf, len); - } - int close () - { - return gzclose (g); - } - off_t tell () {return gzctell (g);} - ~gz () {close ();} -}; - -class bz: public gzbz -{ - public: - bz (const char *pathname) - { - fd = open (pathname, O_RDONLY | O_BINARY); - if (fd) - b = BZ2_bzdopen (fd, "rb"); - else - b = NULL; - } - int read (void *buf, int len) - { - return BZ2_bzread (b, buf, len); - } - int close () - { - BZ2_bzclose (b); - return 0; - } - off_t tell () {return ::tell (fd);} - ~bz () {close ();} -}; - -gzbz *z = NULL; - -static char * -xstrdup (char *c) -{ - char *r = (char *) malloc (strlen (c) + 1); - if (!r) - exit_setup (1); - strcpy (r, c); - return r; -} - -int -tar_open (const char *pathname) -{ - if (_tar_vfile == 0) - _tar_vfile = stderr; - - vp2 (_tar_vfile, "tar: open `%s'\n", pathname); - DWORD size; - if ((size = get_file_size (pathname)) == 0) - return 1; - _tar_file_size = size; - - if (strstr (pathname, ".bz2")) - z = new bz (pathname); - else - z = new gz (pathname); - if (sizeof (tar_header) != 512) - { - /* drastic, but important */ - fprintf (stderr, "compilation error: tar header struct not 512" - " bytes (it's %d)\n", sizeof (tar_header)); - exit_setup (1); - } - err = 0; - return *z ? 0 : 1; -} - -int -tar_ftell () -{ - return z->tell (); -} - -static void -skip_file () -{ - while (file_length > 0) - { - z->read (buf, 512); - file_length -= 512; - } -} - -char * -tar_next_file () -{ - int r, n; - char *c; - r = z->read (&tar_header, 512); - - /* See if we're at end of file */ - if (r != 512) - return 0; - - /* See if the header is all zeros (i.e. last block) */ - n = 0; - for (r = 512/sizeof (int); r; r--) - n |= ((int *)&tar_header)[r-1]; - if (n == 0) - return 0; - - if (!have_longname && tar_header.typeflag != 'L') - { - memcpy (file_name, tar_header.name, 100); - file_name[100] = 0; - } - - sscanf (tar_header.size, "%o", &file_length); - - vp2 (_tar_vfile, "%c %9d %s\n", tar_header.typeflag, file_length, file_name); - - switch (tar_header.typeflag) - { - case 'L': /* GNU tar long name extension */ - if (file_length > _MAX_PATH) - { - skip_file (); - fprintf (stderr, "error: long file name exceeds %d characters\n", - _MAX_PATH); - err++; - z->read (&tar_header, 512); - sscanf (tar_header.size, "%o", &file_length); - skip_file (); - return tar_next_file (); - } - c = file_name; - while (file_length > 0) - { - int need = file_length > 512 ? 512 : file_length; - if (z->read (buf, 512) < 512) - return 0; - memcpy (c, buf, need); - c += need; - file_length -= need; - } - *c = 0; - have_longname = 1; - return tar_next_file (); - - case '3': /* char */ - case '4': /* block */ - case '6': /* fifo */ - fprintf (stderr, "warning: not extracting special file %s\n", - file_name); - err++; - return tar_next_file (); - - case '0': /* regular file */ - case 0: /* regular file also */ - case '2': /* symbolic link */ - case '5': /* directory */ - case '7': /* contiguous file */ - return file_name; - - case '1': /* hard link, we just copy */ - return file_name; - - default: - fprintf (stderr, "error: unknown (or unsupported) file type `%c'\n", - tar_header.typeflag); - err++; - skip_file (); - return tar_next_file (); - } -} - -static void -fix_time_stamp (char *path) -{ - int mtime; - long long ftimev; - FILETIME ftime; - HANDLE h; - - sscanf (tar_header.mtime, "%o", &mtime); - ftimev = mtime * NSPERSEC + FACTOR; - ftime.dwHighDateTime = ftimev >> 32; - ftime.dwLowDateTime = ftimev; - h = CreateFileA (path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, - 0, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, 0); - if (h) - { - SetFileTime (h, 0, 0, &ftime); - CloseHandle (h); - } -} - -static FILE * -common_fopen (char *path) -{ - FILE *out; - out = fopen (path, "wb"); - if (!out) - { - /* maybe we need to create a directory */ - if (mkdir_p (0, path)) - { - skip_file (); - return 0; - } - out = fopen (path, "wb"); - } - if (!out) - { - fprintf (stderr, "unable to write to file %s\n", path); - perror ("The error was"); - skip_file (); - return 0; - } - return out; -} - -static void -prepare_for_file (char *path) -{ - DWORD w; - mkdir_p (0, path); - - w = GetFileAttributes (path); - if (w != 0xffffffff && w & FILE_ATTRIBUTE_DIRECTORY) - { - char *tmp = (char *) malloc (strlen (path) + 10); - int i = 0; - do { - i++; - sprintf (tmp, "%s.old-%d", path, i); - } while (GetFileAttributes (tmp) != 0xffffffff); - fprintf (stderr, "warning: moving directory \"%s\" out of the way.\n", path); - MoveFile (path, tmp); - free (tmp); - } - - DeleteFileA (path); -} - -int -tar_read_file (char *path) -{ - FILE *out, *copy; - HANDLE h; - DWORD w, startticks; - int got; - tar_map_result_type *tmr; - - switch (tar_header.typeflag) - { - case '0': /* regular files */ - case 0: - case '7': - vp (_tar_vfile, "F %s\n", path); - prepare_for_file (path); - out = common_fopen (path); - if (!out) - return 1; - - while (file_length > 0) - { - int put; - int want = file_length > 512 ? 512 : file_length; - got = z->read (buf, 512); - if (got < 512) - { - fprintf (stderr, "tar: unexpected end of file reading %s\n", path); - fclose (out); - remove (path); - return 1; - } - put = fwrite (buf, 1, want, out); - if (put < want) - { - fprintf (stderr, "tar: out of disk space writing %s\n", path); - fclose (out); - remove (path); - skip_file (); - return 1; - } - file_length -= want; - } - fclose (out); - - fix_time_stamp (path); - - /* we need this to do hard links below */ - tmr = (tar_map_result_type *) malloc (sizeof (tar_map_result_type)); - tmr->next = tar_map_result; - tmr->stored_name = xstrdup (file_name); - tmr->mapped_name = xstrdup (path); - tar_map_result = tmr; - - return 0; - - case '1': /* hard links; we just copy */ - for (tmr = tar_map_result; tmr; tmr=tmr->next) - if (strcmp (tmr->stored_name, tar_header.linkname) == 0) - break; - if (!tmr) - { - fprintf (stderr, "tar: can't find %s to link %s to\n", - tar_header.linkname, path); - return 1; - } - vp (_tar_vfile, "H %s <- %s\n", path, tmr->mapped_name); - prepare_for_file (path); - copy = fopen (tmr->mapped_name, "rb"); - if (!copy) - { - fprintf (stderr, "tar: unable to read %s\n", tmr->mapped_name); - return 1; - } - out = common_fopen (path); - if (!out) - return 1; - - while ((got = fread (buf, 1, 512, copy)) > 0) - { - int put = fwrite (buf, 1, got, out); - if (put < got) - { - fprintf (stderr, "tar: out of disk space writing %s\n", path); - fclose (out); - fclose (copy); - remove (path); - return 1; - } - } - fclose (out); - fclose (copy); - - fix_time_stamp (path); - return 0; - - case '5': /* directories */ - vp (_tar_vfile, "D %s\n", path); - while (path[0] && path[strlen (path)-1] == '/') - path[strlen (path) - 1] = 0; - return mkdir_p (1, path); - - - case '2': /* symbolic links */ - vp (_tar_vfile, "L %s -> %s\n", path, tar_header.linkname); - prepare_for_file (path); - h = CreateFileA (path, GENERIC_WRITE, 0, 0, CREATE_NEW, - FILE_ATTRIBUTE_NORMAL, 0); - if (h == INVALID_HANDLE_VALUE) - { - fprintf (stderr, "error: unable to create symlink \"%s\" -> \"%s\"\n", - path, tar_header.linkname); - return 1; - } - strcpy (buf, SYMLINK_COOKIE); - strcat (buf, tar_header.linkname); - if (WriteFile (h, buf, strlen (buf) + 1, &w, NULL)) - { - CloseHandle (h); - SetFileAttributesA (path, FILE_ATTRIBUTE_SYSTEM); - return 0; - } - CloseHandle (h); - fprintf (stderr, "error: unable to write symlink \"%s\"\n", path); - DeleteFileA (path); - return 1; - } -} - -int -tar_close () -{ -#if 0 - while (tar_map_result) - { - tar_map_result_type *t = tar_map_result->next; - free (tar_map_result->stored_name); - free (tar_map_result->mapped_name); - free (tar_map_result); - tar_map_result = t; - } -#endif - tar_map_result = 0; - - if (z->close ()) - err++; - return err; /* includes errors for skipped files, etc */ -} - -typedef struct { - char *from; - int from_len; - char *to; - int to_len; -} map_type; - -static map_type *map; -static int nmaps; - -int -tar_auto (char *pathname, char **maplist) -{ - char *c; - int err = 0; - int i, j; - map_type mtemp; - char newname[_MAX_PATH+512]; - static char twiddles[] = "|\b/\b-\b\\\b"; - int t = 0; - - for (nmaps=0; maplist[nmaps*2]; nmaps++) ; - map = (map_type *) malloc ((nmaps+1) * sizeof (map_type)); - for (nmaps=0; maplist[nmaps*2]; nmaps++) - { - map[nmaps].from = maplist[nmaps*2]; - map[nmaps].from_len = strlen (maplist[nmaps*2]); - map[nmaps].to = maplist[nmaps*2+1]; - map[nmaps].to_len = strlen (maplist[nmaps*2+1]); - } - /* bubble sort - expect the maps to be short */ - for (i=0; i= map[i].from_len - && strncmp (c, map[i].from, map[i].from_len) == 0) - { - strcpy (newname, map[i].to); - strcpy (newname+map[i].to_len, c + map[i].from_len); - c = newname; - break; - } - - t = (t+2) % 8; - fwrite (twiddles+t, 1, 2, stderr); - - if (tar_read_file (c)) - err++; - } - if (tar_close ()) - err++; - - fwrite (" \b", 1, 2, stderr); - - vp2 (_tar_vfile, "tar_auto returns %d\n", err); - return err; -} diff --git a/tar.h b/tar.h deleted file mode 100644 index 2c0bb4c3..00000000 --- a/tar.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2000, Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * A copy of the GNU General Public License can be found at - * http://www.gnu.org/ - * - * Written by DJ Delorie - * - */ - -#ifndef __TAR_H_ -#define __TAR_H_ - -/* Only one tarfile may be open at a time. gzipped files handled - automatically */ - -/* returns zero on success, nonzero on failure */ -int tar_open (const char *pathname); - -/* returns pointer to static buf containing name of next file */ -char * tar_next_file (); - -/* byte position in [compressed] file */ -int tar_ftell (); - -/* pass adjusted path, returns zero on success, nonzero on failure */ -int tar_read_file (char *path); - -/* closes the file */ -int tar_close (); - -/* pass path to tar file and from/to pairs for path prefix (NULLs at - end , returns zero if completely successful, nonzero (counts - errors) on failure */ -int tar_auto (char *pathname, char **map); - -int tar_mkdir_p (int isadir, char *path); - -/* -extern int _tar_verbose; -extern FILE * _tar_vfile; -*/ - -#endif -- 2.43.5