From df8b19a28eee02f23178584737080001ce8873d1 Mon Sep 17 00:00:00 2001 From: Micah Cowan Date: Fri, 28 Sep 2007 14:47:46 -0700 Subject: [PATCH] Gisle's MS-DOS support --- AUTHORS | 6 +- ChangeLog.README | 2 + msdos/ChangeLog | 4 ++ msdos/Makefile.DJ | 67 ++++++++++++++++++++++ msdos/config.h | 143 ++++++++++++++++++++++++++++++++++++++++++++++ src/ChangeLog | 5 ++ src/connect.c | 2 +- src/init.c | 38 ++++++++---- src/main.c | 14 +++++ src/openssl.c | 2 +- src/options.h | 4 ++ src/sysdep.h | 6 +- src/url.c | 2 +- src/utils.c | 6 +- 14 files changed, 278 insertions(+), 23 deletions(-) create mode 100644 msdos/ChangeLog create mode 100644 msdos/Makefile.DJ create mode 100644 msdos/config.h diff --git a/AUTHORS b/AUTHORS index 94adf57e..49a48ca6 100644 --- a/AUTHORS +++ b/AUTHORS @@ -28,9 +28,9 @@ Ian Abbott. Contributed bugfixes, Windows-related fixes, provided a prototype implementation of the new recursive code, and more. Co-maintained Wget during the 1.8 release cycle. -Gisle Vanem. Contributed Windows improvements, including a port of -run_with_timeout to Windows, additions to Makefiles, and many bug -reports and fixes. +Gisle Vanem. Contributed Windows and MS-DOS improvements, including a +port of run_with_timeout to Windows, additions to Makefiles, and many +bug reports and fixes. Mauro Tortonesi. Improved IPv6 support, adding support for dual family systems. Refactored and enhanced FTP IPv6 code. Maintained GNU diff --git a/ChangeLog.README b/ChangeLog.README index d50b0782..19394501 100644 --- a/ChangeLog.README +++ b/ChangeLog.README @@ -10,5 +10,7 @@ Please note that Wget has more than one ChangeLog file: windows/ChangeLog: documents only changes to files in the windows directory + msdos/ChangeLog: documents only changes to files in the msdos directory + When checking to see if a patch you sent in has been applied, please look in the appropriate ChangeLog(s). diff --git a/msdos/ChangeLog b/msdos/ChangeLog new file mode 100644 index 00000000..dcf81278 --- /dev/null +++ b/msdos/ChangeLog @@ -0,0 +1,4 @@ +2007-09-24 Gisle Vanem + + * Makefile.DJ, config.h: Added to support building on MS-DOS via + DJGPP. diff --git a/msdos/Makefile.DJ b/msdos/Makefile.DJ new file mode 100644 index 00000000..bed35cd1 --- /dev/null +++ b/msdos/Makefile.DJ @@ -0,0 +1,67 @@ +# +# GNU Makefile for wget / djgpp / MSDOS. +# By Gisle Vanem . +# +.SUFFIXES: .exe .map + +USE_OPENSSL = 0 +USE_IPV6 = 1 + +OPENSSL_ROOT = e:/net/OpenSSL.099 +ZLIB_ROOT = e:/djgpp/contrib/zlib + +VPATH = ../src +OBJ_DIR = djgpp.obj +CC = gcc +CFLAGS = -O2 -g -Wall -Wcast-align -I. -I../src -I/dev/env/WATT_ROOT/inc \ + -DHAVE_CONFIG_H -DENABLE_DEBUG + +# LDFLAGS = -s + +ifeq ($(USE_OPENSSL),1) + CFLAGS += -DHAVE_OPENSSL -DHAVE_SSL -I$(OPENSSL_ROOT) + EX_LIBS += $(OPENSSL_ROOT)/lib/libssl.a $(OPENSSL_ROOT)/lib/libcrypt.a \ + $(ZLIB_ROOT)/libz.a + SOURCES = ../src/openssl.c ../src/http-ntlm.c +endif + +ifeq ($(USE_IPV6),1) + CFLAGS += -DENABLE_IPV6 +endif + +EX_LIBS += /dev/env/WATT_ROOT/lib/libwatt.a + +SOURCES += $(addprefix ../src/, cmpt.c connect.c cookies.c ftp.c ftp-basic.c \ + ftp-ls.c ftp-opie.c getopt.c hash.c host.c html-parse.c html-url.c \ + http.c init.c log.c main.c gen-md5.c gnu-md5.c netrc.c progress.c \ + recur.c res.c retr.c safe-ctype.c url.c utils.c version.c convert.c \ + xmalloc.c ptimer.c spider.c) + +OBJECTS = $(addprefix $(OBJ_DIR)/, $(notdir $(SOURCES:.c=.o))) + +all: $(OBJ_DIR) ../wget-dos.exe + @echo 'Welcome to Wget' + +$(OBJ_DIR): + mkdir $(OBJ_DIR) + +../wget-dos.exe: $(OBJECTS) + $(CC) $(LDFLAGS) -o $@ $^ $(EX_LIBS) + +clean: + rm -f $(OBJECTS) $(MAPFILE) + +vclean realclean: clean + rm -f ../wget-dos.exe depend.dj + - rmdir $(OBJ_DIR) + +$(OBJ_DIR)/%.o: %.c + $(CC) $(CFLAGS) -o $@ -c $< + @echo + +depend: + $(CC) -MM $(CFLAGS) $(SOURCES) | \ + sed -e 's/^\([a-zA-Z0-9_-]*\.o:\)/$$(OBJ_DIR)\/\1/' > depend.dj + +-include depend.dj + diff --git a/msdos/config.h b/msdos/config.h new file mode 100644 index 00000000..b5a46255 --- /dev/null +++ b/msdos/config.h @@ -0,0 +1,143 @@ +/* Configuration header file for MS-DOS/Watt-32 + + Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + In addition, as a special exception, the Free Software Foundation + gives permission to link the code of its release of Wget with the + OpenSSL project's "OpenSSL" library (or with modified versions of it + that use the same license as the "OpenSSL" library), and distribute + the linked executables. You must obey the GNU General Public License + in all respects for all of the code used other than "OpenSSL". If you + modify this file, you may extend this exception to your version of the + file, but you are not obligated to do so. If you do not wish to do + so, delete this exception statement from your version. */ + + +#ifndef CONFIG_DOS_H +#define CONFIG_DOS_H + +#include +#include +#include +#include + +#ifdef __DJGPP__ +#include +#endif + +#include + +#if defined(__WATCOMC__) && (__WATCOMC__ >= 1250) /* OW 1.5+ */ + #define OPENWATCOM_15 +#endif + +#if defined(__HIGHC__) + #define inline + #define HAVE_UNISTD_H 1 + #define HAVE_UTIME_H 1 +#endif + +#if defined(__WATCOMC__) || defined(__BORLANDC__) + #define inline +#endif + +#ifdef HAVE_SSL + #define OPENSSL_NO_KRB5 +#endif + +#define STDC_HEADERS 1 +#define RETSIGTYPE void + +#define USE_OPIE 1 +#define USE_DIGEST 1 +#define DEBUG + +#ifdef __DJGPP__ + #define HAVE_STRUCT_UTIMBUF 1 + #define HAVE_UNAME 1 + #define HAVE_UTIME_H 1 + #define HAVE_STRCASECMP 1 + #define HAVE_STRNCASECMP 1 + #define HAVE_SYS_SELECT_H 1 + #define HAVE_USLEEP 1 + #define HAVE_SIGNAL 1 + #define HAVE_BASENAME 1 + #define HAVE_SIGSETJMP 1 + #define HAVE_SIGBLOCK 1 + #define HAVE__BOOL 1 + + #if (DJGPP_MINOR >= 4) + #include + #define HAVE_SNPRINTF 1 + #define HAVE_VSNPRINTF 1 + #define HAVE_UINT32_T 1 + #endif +#endif + +#ifdef __HIGHC__ + #define HAVE_STRUCT_UTIMBUF 1 + #define HAVE_UTIME_H 1 +#endif + +#ifdef OPENWATCOM_15 + #define HAVE_STRCASECMP + #define HAVE_STRNCASECMP +#endif + +#define HAVE_GETHOSTBYNAME 1 +#define HAVE_GETHOSTNAME 1 +#define HAVE_SELECT 1 +#define HAVE_STRDUP 1 +#define HAVE_STRERROR 1 +#define HAVE_STRSTR 1 +#define HAVE_MKTIME 1 +#define HAVE_STDARG_H 1 +#define HAVE_STDLIB_H 1 +#define HAVE_STRING_H 1 +#define HAVE_SIGNAL_H 1 +#define HAVE_GETTIMEOFDAY 1 +#define HAVE_MD5 1 +#define HAVE_BUILTIN_MD5 1 +#define HAVE_ISATTY 1 +#define HAVE_MEMMOVE 1 + +#define OS_TYPE "DOS" +#define CTRLBREAK_BACKGND 1 +#define PROTOTYPES 1 + +#define WGET_USE_STDARG + +#define lookup_host wget_lookuphost +#define select select_s +#define socklen_t int + +#define sock_read wget_sock_read +#define sock_write wget_sock_write +#define sock_close wget_sock_close + +#if defined(__DJGPP__) + #define MKDIR(p,a) mkdir(p,a) +#else + #define strcasecmp stricmp + #define MKDIR(p,a) mkdir(p) +#endif + +#if !defined(MSDOS) +#define MSDOS +#endif + +#endif /* CONFIG_DOS_H */ diff --git a/src/ChangeLog b/src/ChangeLog index 17e39860..e0583343 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2007-09-24 Gisle Vanem + + * connect.c, init.c, main.c, openssl.c, options.h, sysdep.h, + url.c, utils.c: Added support for building on MS-DOS. + 2007-09-24 Jochen Roderburg * http.c (http_zero): Remove no-longer-used local_size variable. diff --git a/src/connect.c b/src/connect.c index 11d6e193..0188353c 100644 --- a/src/connect.c +++ b/src/connect.c @@ -668,7 +668,7 @@ test_socket_open (int sock) /* Basic socket operations, mostly EINTR wrappers. */ -#ifdef WINDOWS +#if defined(WINDOWS) || defined(MSDOS) # define read(fd, buf, cnt) recv (fd, buf, cnt, 0) # define write(fd, buf, cnt) send (fd, buf, cnt, 0) # define close(fd) closesocket (fd) diff --git a/src/init.c b/src/init.c index 7d861922..d8c71764 100644 --- a/src/init.c +++ b/src/init.c @@ -103,7 +103,7 @@ CMD_DECLARE (cmd_spec_verbose); add any entries that allocate memory (e.g. cmd_string and cmd_vector) to the cleanup() function below. */ -static struct { +static const struct { const char *name; void *place; bool (*action) (const char *, const char *, void *); @@ -241,7 +241,10 @@ static struct { { "useragent", NULL, cmd_spec_useragent }, { "verbose", NULL, cmd_spec_verbose }, { "wait", &opt.wait, cmd_time }, - { "waitretry", &opt.waitretry, cmd_time } + { "waitretry", &opt.waitretry, cmd_time }, +#ifdef MSDOS + { "wdebug", &opt.wdebug, cmd_boolean }, +#endif }; /* Look up CMDNAME in the commands[] and return its position in the @@ -313,10 +316,10 @@ defaults (void) #endif /* The default for file name restriction defaults to the OS type. */ -#if !defined(WINDOWS) && !defined(__CYGWIN__) - opt.restrict_files_os = restrict_unix; -#else +#if defined(WINDOWS) || defined(MSDOS) || defined(__CYGWIN__) opt.restrict_files_os = restrict_windows; +#else + opt.restrict_files_os = restrict_unix; #endif opt.restrict_files_ctrl = true; opt.restrict_files_case = restrict_no_case_restriction; @@ -333,14 +336,27 @@ home_dir (void) if (!home) { -#ifndef WINDOWS +#if defined(MSDOS) + /* Under MSDOS, if $HOME isn't defined, use the directory where + `wget.exe' resides. */ + const char *_w32_get_argv0 (void); /* in libwatt.a/pcconfig.c */ + char *p, buf[PATH_MAX]; + + strcpy (buf, _w32_get_argv0 ()); + p = strrchr (buf, '/'); /* djgpp */ + if (!p) + p = strrchr (buf, '\\'); /* others */ + assert (p); + *p = '\0'; + home = buf; +#elif !defined(WINDOWS) /* If HOME is not defined, try getting it from the password file. */ struct passwd *pwd = getpwuid (getuid ()); if (!pwd || !pwd->pw_dir) return NULL; home = pwd->pw_dir; -#else /* WINDOWS */ +#else /* !WINDOWS */ /* Under Windows, if $HOME isn't defined, use the directory where `wget.exe' resides. */ home = ws_mypath (); @@ -750,10 +766,10 @@ cmd_string (const char *com, const char *val, void *place) return true; } -#ifndef WINDOWS -# define ISSEP(c) ((c) == '/') -#else +#if defined(WINDOWS) || defined(MSDOS) # define ISSEP(c) ((c) == '/' || (c) == '\\') +#else +# define ISSEP(c) ((c) == '/') #endif /* Like the above, but handles tilde-expansion when reading a user's @@ -791,7 +807,7 @@ cmd_file (const char *com, const char *val, void *place) *pstring = concat_strings (home, "/", val, (char *) 0); } -#ifdef WINDOWS +#if defined(WINDOWS) || defined(MSDOS) /* Convert "\" to "/". */ { char *s; diff --git a/src/main.c b/src/main.c index 4f0c123c..ea3088c2 100644 --- a/src/main.c +++ b/src/main.c @@ -244,6 +244,9 @@ static struct cmdline_option option_data[] = { "version", 'V', OPT_FUNCALL, (void *) print_version, no_argument }, { "wait", 'w', OPT_VALUE, "wait", -1 }, { "waitretry", 0, OPT_VALUE, "waitretry", -1 }, +#ifdef MSDOS + { "wdebug", 0, OPT_BOOLEAN, "wdebug", -1 }, +#endif }; #undef WHEN_DEBUG @@ -386,6 +389,10 @@ Logging and input file:\n"), #ifdef ENABLE_DEBUG N_("\ -d, --debug print lots of debugging information.\n"), +#endif +#ifdef MSDOS + N_("\ + --wdebug print Watt-32 debug output.\n"), #endif N_("\ -q, --quiet quiet (no output).\n"), @@ -680,6 +687,7 @@ There is NO WARRANTY, to the extent permitted by law.\n"), stdout); exit (0); } + int main (int argc, char *const *argv) { @@ -891,8 +899,14 @@ Can't timestamp and not clobber old files at the same time.\n")); exit (1); } +#ifdef MSDOS + if (opt.wdebug) + dbug_init(); + sock_init(); +#else if (opt.background) fork_to_background (); +#endif /* Initialize progress. Have to do this after the options are processed so we know where the log file is. */ diff --git a/src/openssl.c b/src/openssl.c index 71faa0c0..0d4ec155 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -356,7 +356,7 @@ openssl_close (int fd, void *arg) xfree_null (ctx->last_error); xfree (ctx); -#ifdef WINDOWS +#if defined(WINDOWS) || defined(MSDOS) closesocket (fd); #else close (fd); diff --git a/src/options.h b/src/options.h index 7fda95e3..5fc49e2a 100644 --- a/src/options.h +++ b/src/options.h @@ -131,6 +131,10 @@ struct options bool debug; /* Debugging on/off */ #endif +#ifdef MSDOS + bool wdebug; /* Watt-32 tcp/ip debugging on/off */ +#endif + bool timestamping; /* Whether to use time-stamping. */ bool backup_converted; /* Do we save pre-converted files as *.orig? */ diff --git a/src/sysdep.h b/src/sysdep.h index 98b3c13b..2c7ba31e 100644 --- a/src/sysdep.h +++ b/src/sysdep.h @@ -69,15 +69,15 @@ typedef unsigned char _Bool; # define __bool_true_false_are_defined 1 #endif -/* Needed for compilation under OS/2: */ -#ifdef __EMX__ +/* Needed for compilation under OS/2 and MSDOS */ +#if defined(__EMX__) || defined(MSDOS) # ifndef S_ISLNK # define S_ISLNK(m) 0 # endif # ifndef lstat # define lstat stat # endif -#endif /* __EMX__ */ +#endif /* __EMX__ || MSDOS */ /* Reportedly, stat() macros are broken on some old systems. Those systems will have to fend for themselves, as I will not introduce diff --git a/src/url.c b/src/url.c index d721501a..9b20c519 100644 --- a/src/url.c +++ b/src/url.c @@ -1220,7 +1220,7 @@ append_char (char ch, struct growable *dest) enum { filechr_not_unix = 1, /* unusable on Unix, / and \0 */ - filechr_not_windows = 2, /* unusable on Windows, one of \|/<>?:*" */ + filechr_not_windows = 2, /* unusable on MSDOS/Windows, one of \|/<>?:*" */ filechr_control = 4 /* a control character, e.g. 0-31 */ }; diff --git a/src/utils.c b/src/utils.c index 0a222d99..937eb57f 100644 --- a/src/utils.c +++ b/src/utils.c @@ -287,9 +287,9 @@ datetime_str (time_t t) } /* The Windows versions of the following two functions are defined in - mswindows.c. */ + mswindows.c. On MSDOS this function should never be called. */ -#ifndef WINDOWS +#if !defined(WINDOWS) && !defined(MSDOS) void fork_to_background (void) { @@ -333,7 +333,7 @@ fork_to_background (void) freopen ("/dev/null", "w", stdout); freopen ("/dev/null", "w", stderr); } -#endif /* not WINDOWS */ +#endif /* !WINDOWS && !MSDOS */ /* "Touch" FILE, i.e. make its mtime ("modified time") equal the time specified with TM. The atime ("access time") is set to the current -- 2.39.2