Subject: Collected Debian patches for tf5
Author: Russ Allbery <rra@debian.org>

The packaging for tf5 is maintained in Git using multiple branches for
fixes, which makes it complex to separate the changes into individual
patches.  They are therefore all included in a single Debian patch.

For full commit history and separated commits, see the packaging Git
repository.

--- tf5-5.0beta8.orig/configure.in
+++ tf5-5.0beta8/configure.in
@@ -294,14 +294,19 @@ if test "$enable_ssl" = "yes"; then
     old_CPPFLAGS="$CPPFLAGS"
     while true; do
 	dnl -lssl needs -lcrypto
-	dnl Try in default locations first, then /usr/local/ssl
+	dnl Try in default locations first, then /usr/local/ssl, then try the
+        dnl GnuTLS compatibility layer
 	LIBS="$LIBS -lssl -lcrypto"
 	AC_MSG_CHECKING([for libcrypto and libssl])
 	AC_TRY_LINK_FUNC(SSL_new, AC_MSG_RESULT([yes]),
 	    CFLAGS="$CFLAGS -L/usr/local/ssl/lib";
 	    CPPFLAGS="-I/usr/local/ssl/include $CPPFLAGS";
 	    AC_TRY_LINK_FUNC(SSL_new, AC_MSG_RESULT([/usr/local/ssl]),
-		AC_MSG_RESULT([no]); break))
+		LIBS="$old_LIBS -lgnutls-openssl"
+		CFLAGS="$old_CFLAGS"
+		CPPFLAGS="$old_CPPFLAGS"
+		AC_TRY_LINK_FUNC(SSL_new, AC_MSG_RESULT([gnutls]),
+		    AC_MSG_RESULT([no]); break)))
 	dnl Red Hat 9 and Yellow Dog Linux have ssl.h in a standard place,
 	dnl but it depends on krb5.h which isn't in a standard place.
 	AC_MSG_CHECKING(for ssl kerberos dependency)
@@ -311,9 +316,12 @@ if test "$enable_ssl" = "yes"; then
 	else
 	    AC_MSG_RESULT([no])
 	fi
-	AC_CHECK_HEADER(openssl/ssl.h, , break)
-	AC_DEFINE(HAVE_SSL)
-	ok=1
+	AC_CHECK_HEADER(openssl/ssl.h, ok=1,
+	    [AC_CHECK_HEADERS([gnutls/openssl.h], [ok=1])])
+	if test "$ok" = "1"; then
+	    AC_DEFINE(HAVE_SSL)
+            AC_CHECK_FUNCS(ERR_peek_error)
+	fi
 	break
     done
     if test "$ok" = "0"; then
@@ -591,13 +599,13 @@ fi
 dnl The "right" way of using program_transform_name, program_prefix, and
 dnl program_suffix expects you to use AC_ARG_PROGRAM here and do transformation
 dnl in the Makefile, but we want the values now, so we do it ourselves.
-EXENAME="tf"
+EXENAME="tf" PROGNAME="tf"
 test "${program_prefix}" != "NONE" && EXENAME="${program_prefix}${EXENAME}"
 test "${program_suffix}" != "NONE" && EXENAME="${EXENAME}${program_suffix}"
 if test "${program_transform_name}" != "NONE"; then
     EXENAME=`echo "${EXENAME}" | sed "${program_transform_name}"`
 fi
-LIBNAME="${EXENAME}-lib"
+LIBNAME="${PROGNAME}-lib"
 
 if test "$enable_symlink" = "no"; then
     SYMLINK=""
@@ -608,6 +616,7 @@ else
 fi
 
 AC_SUBST(EXENAME)
+AC_SUBST(PROGNAME)
 AC_SUBST(LIBNAME)
 AC_SUBST(SYMLINK)
 
--- tf5-5.0beta8.orig/src/socket.c
+++ tf5-5.0beta8/src/socket.c
@@ -30,8 +30,12 @@ static const char RCSid[] = "$Id: socket
 #include <signal.h>	/* for killing resolver child process */
 
 #if HAVE_SSL
-# include <openssl/ssl.h>
-# include <openssl/err.h>
+# if HAVE_GNUTLS_OPENSSL_H
+#  include <gnutls/openssl.h>
+# else
+#  include <openssl/ssl.h>
+#  include <openssl/err.h>
+# endif
     SSL_CTX *ssl_ctx;
 #endif
 
@@ -532,9 +536,11 @@ static void ssl_io_err(Sock *sock, int r
     case SSL_ERROR_WANT_WRITE:
 	ssl_io_err_hook("SSL", "SSL_ERROR_WANT_WRITE");
 	break;
+#ifdef SSL_ERROR_WANT_CONNECT
     case SSL_ERROR_WANT_CONNECT:
 	ssl_io_err_hook("SSL", "SSL_ERROR_WANT_CONNECT");
 	break;
+#endif
     case SSL_ERROR_SYSCALL:
 	if (ret == 0) {
 	    ssl_io_err_hook("SSL/system", "invalid EOF");
@@ -2904,9 +2910,12 @@ static int handle_socket_input(const cha
 #if HAVE_SSL
 	    if (xsock->ssl) {
 		count = SSL_read(xsock->ssl, inbuffer, sizeof(inbuffer));
-		if (count == 0 &&
-		    SSL_get_error(xsock->ssl, 0) == SSL_ERROR_SYSCALL &&
-		    ERR_peek_error() == 0)
+		if (count == 0
+# if HAVE_ERR_PEEK_ERROR
+		    && SSL_get_error(xsock->ssl, 0) == SSL_ERROR_SYSCALL &&
+		    ERR_peek_error() == 0
+# endif
+		    )
 		{
 		    /* Treat a count of 0 with no errors as a normal EOF */
 		    goto eof;
--- tf5-5.0beta8.orig/src/tf.1.nroffman
+++ tf5-5.0beta8/src/tf.1.nroffman
@@ -1,11 +1,11 @@
 .\" $Id: tf.1.nroffman,v 34000.8 2007/01/13 23:12:39 kkeys Exp $
-.TH TF 1 LOCAL
+.TH TF 1 "2007-01-13" "TinyFugue 5.0" "TinyFugue"
 .SH NAME
 tf \- TinyFugue, a MUD client
 .SH SYNOPSIS
-.B "tf [-f\fIfile\fB] [-lnq] [\fIworld\fB]"
+.B "tf [\-f\fIfile\fB] [\-lnq] [\fIworld\fB]"
 .br
-.B "tf [-f\fIfile\fB] \fIhost\fB \fIport\fB"
+.B "tf [\-f\fIfile\fB] \fIhost\fB \fIport\fB"
 .SH DESCRIPTION
 \fITinyFugue\fR (also known as "Fugue" or "TF") is a line-based client
 designed for connecting to MUD servers (note: LP, DIKU, and other servers
@@ -48,15 +48,15 @@ world and try to connect to it.
 The \fBhost\fR may be an IP number or regular name format.
 .PP
 OPTIONS
-.IP "-f\fIfile\fR"
+.IP "\-f\fIfile\fR"
 Load \fIfile\fR instead of $HOME/.tfrc at startup.
-.IP "-f"
+.IP "\-f"
 Do not load any personal configuration file.  The library will still be loaded.
-.IP "-l"
+.IP "\-l"
 Disable automatic login.
-.IP "-n"
+.IP "\-n"
 Do not connect to any world at startup.
-.IP "-q"
+.IP "\-q"
 Quiet login (overrides %{quiet} flag).
 
 .SH FEATURES
@@ -109,7 +109,7 @@ Log a session to a file.
 .sp
 Separate LP and Diku style prompts from normal output.
 .sp
-Page output using a --More-- prompt.
+Page output using a \-\-More\-\- prompt.
 .sp
 Recall previously received text.
 
@@ -120,14 +120,14 @@ configuration file "stdlib.tf", located
 TFLIBDIR is defined when \fITF\fR is installed, and is often
 /usr/local/lib/tf.lib, or under the home directory of the installer.
 This library contains many macros
-and definitions essential to the correct operation of \fITF.\fR
+and definitions essential to the correct operation of \fITF\fR.
 
 Next, \fITF\fR will attempt to read your personal configuration
 file, $HOME/.tfrc, in which you can put any \fITF\fR commands you
 want executed automatically at startup.  Two of the most useful
 commands to use in a \fITF\fR configuration file are /addworld and /load.
 
-For backward compatability, \fITF\fR will also try
+For backward compatibility, \fITF\fR will also try
 to read the \fITinyTalk\fR configuration file.
 Its name defautls to $HOME/.tinytalk, or can be defined by the TINYTALK
 environment variable.
@@ -140,19 +140,19 @@ the first Tinyclient with any great numb
 hiliting and suppression of text, simple triggers, and separating input and
 output on the screen.
 Leo Plotkin (Grod) made rather extensive modifications to \fITinytalk\fR
-to produce \fITinywar,\fR which was plagued with some
+to produce \fITinywar\fR, which was plagued with some
 serious bugs and was never officially released (the phrase "Tinywar
 doesn't exist" is often quoted), and is now an unsupported client.
 \fITF\fR began when Greg Hudson (Explorer_Bob) merged many of the new
-features of \fITinywar\fR back into \fITinyTalk,\fR
+features of \fITinywar\fR back into \fITinyTalk\fR,
 and added many new features of his own, most notably the split screen.
 Some of the code in Greg's releases was contributed by Leo Plotkin.
-After Greg moved on to \fIVaporTalk,\fR Ken Keys (Hawkeye) took over design
+After Greg moved on to \fIVaporTalk\fR, Ken Keys (Hawkeye) took over design
 and maintenance of \fITF\fR in July 1991, and continues to make improvements
 in features and performance.
 .PP
 The code size of \fITF\fR has surpassed 300K (unstripped),
-and is signifigantly larger than \fITinytalk.\fR
+and is signifigantly larger than \fITinytalk\fR.
 It is, in fact, more than three times the size of a number of existing servers.
 As of version 3.0, it has 66 builtin commands and 57 library commands,
 each documented in the helpfile.
@@ -225,8 +225,8 @@ default macro library.
 .PP
 The .tinytalk file may not be supported in the future; use .tfrc instead.
 .PP
-The '-' command line option in versions prior to 2.0 is no longer supported,
-and has been replaced with '-l'.
+The '\-' command line option in versions prior to 2.0 is no longer supported,
+and has been replaced with '\-l'.
 
 .SH BUGS
 .PP
--- tf5-5.0beta8.orig/src/tfconfig.h.in
+++ tf5-5.0beta8/src/tfconfig.h.in
@@ -37,10 +37,12 @@
 #define HAVE_LIBZ 0
 #define SOCKS 0
 #define HAVE_SSL 0
+#define HAVE_GNUTLS_OPENSSL_H 0
 
 #define HAVE_BCOPY 0
 #define HAVE_BZERO 0
 #define HAVE_CONNECT 0
+#define HAVE_ERR_PEEK_ERROR 0
 #define HAVE_FILENO 0
 #define HAVE_GETCWD 0
 #define HAVE_GETHOSTBYNAME 0
--- tf5-5.0beta8.orig/src/tfio.c
+++ tf5-5.0beta8/src/tfio.c
@@ -497,6 +497,7 @@ void vSprintf(String *buf, int flags, co
     const conString *Sval;
     int len, min, max, leftjust, stars;
     attr_t attrs = buf->attrs;
+    va_list ap_copy;
 
     if (!(flags & SP_APPEND) && buf->data) Stringtrunc(buf, 0);
     while (*fmt) {
@@ -522,7 +523,9 @@ void vSprintf(String *buf, int flags, co
         case 'x': case 'X': case 'u': case 'o':
         case 'f': case 'e': case 'E': case 'g': case 'G':
         case 'p':
-            vsprintf(tempbuf, spec, ap);
+            va_copy(ap_copy, ap);
+            vsprintf(tempbuf, spec, ap_copy);
+            va_end(ap_copy);
             Stringcat(buf, tempbuf);
             /* eat the arguments used by vsprintf() */
             while (stars--) (void)va_arg(ap, int);
--- tf5-5.0beta8.orig/unix/unix.mak
+++ tf5-5.0beta8/unix/unix.mak
@@ -87,15 +87,15 @@ TF tf$(X):     $(OBJS) $(BUILDERS) $(PCR
 	-test -z "$(STRIP)" || $(STRIP) tf$(X) || true
 
 PREFIXDIRS:
-	test -d "$(bindir)" || mkdir $(bindir)
-	test -d "$(datadir)" || mkdir $(datadir)
+	test -d "$(DESTDIR)$(bindir)" || mkdir $(DESTDIR)$(bindir)
+	test -d "$(DESTDIR)$(datadir)" || mkdir $(DESTDIR)$(datadir)
 
 install_TF $(TF): tf$(X) $(BUILDERS)
-	-@rm -f $(TF)
-	cp tf$(X) $(TF)
-	chmod $(MODE) $(TF)
+	-@rm -f $(DESTDIR)$(TF)
+	cp tf$(X) $(DESTDIR)$(TF)
+	chmod $(MODE) $(DESTDIR)$(TF)
 
-SYMLINK $(SYMLINK): $(TF)
+SYMLINK $(SYMLINK): $(DESTDIR)$(TF)
 	test -z "$(SYMLINK)" || { rm -f $(SYMLINK) && ln -s $(TF) $(SYMLINK); }
 
 LIBRARY $(TF_LIBDIR): ../tf-lib/tf-help ../tf-lib/tf-help.idx
@@ -103,30 +103,30 @@ LIBRARY $(TF_LIBDIR): ../tf-lib/tf-help
 #	@# Overly simplified shell commands, to avoid problems on ultrix
 	-@test -n "$(TF_LIBDIR)" || echo "TF_LIBDIR is undefined."
 	test -n "$(TF_LIBDIR)"
-	test -d "$(TF_LIBDIR)" || mkdir $(TF_LIBDIR)
-	-@test -d "$(TF_LIBDIR)" || echo "Can't make $(TF_LIBDIR) directory.  See if"
-	-@test -d "$(TF_LIBDIR)" || echo "there is already a file with that name."
-	test -d "$(TF_LIBDIR)"
+	test -d "$(DESTDIR)$(TF_LIBDIR)" || mkdir $(DESTDIR)$(TF_LIBDIR)
+	-@test -d "$(DESTDIR)$(TF_LIBDIR)" || echo "Can't make $(TF_LIBDIR) directory.  See if there is already a file with that name."
+	test -d "$(DESTDIR)$(TF_LIBDIR)"
 #
 #	@#rm -f $(TF_LIBDIR)/*;  # wrong: this would remove local.tf, etc.
 	@echo '## Copying library files...'
 	cd ../tf-lib; \
 	for f in *; do test -f $$f && files="$$files $$f"; done; \
-	( cd $(TF_LIBDIR); rm -f $$files tf.help tf.help.index; ); \
-	cp $$files $(TF_LIBDIR); \
-	cd $(TF_LIBDIR); \
+	( cd $(DESTDIR)$(TF_LIBDIR); rm -f $$files tf.help tf.help.index; ); \
+	cp $$files $(DESTDIR)$(TF_LIBDIR); \
+	cd $(DESTDIR)$(TF_LIBDIR); \
 	chmod $(MODE) $$files; chmod ugo-wx $$files
-	-rm -f $(TF_LIBDIR)/CHANGES 
-	cp ../CHANGES $(TF_LIBDIR)
-	chmod $(MODE) $(TF_LIBDIR)/CHANGES; chmod ugo-wx $(TF_LIBDIR)/CHANGES
-	chmod $(MODE) $(TF_LIBDIR)
-	-@cd $(TF_LIBDIR); old=`ls replace.tf 2>/dev/null`; \
+	-rm -f $(DESTDIR)$(TF_LIBDIR)/CHANGES 
+	cp ../CHANGES $(DESTDIR)$(TF_LIBDIR)
+	chmod $(MODE) $(DESTDIR)$(TF_LIBDIR)/CHANGES;
+	chmod ugo-wx $(DESTDIR)$(TF_LIBDIR)/CHANGES
+	chmod $(MODE) $(DESTDIR)$(TF_LIBDIR)
+	-@cd $(DESTDIR)$(TF_LIBDIR); old=`ls replace.tf 2>/dev/null`; \
 	if [ -n "$$old" ]; then \
 	    echo "## WARNING: Obsolete files found in $(TF_LIBDIR): $$old"; \
 	fi
 	@echo '## Creating links so old library names still work...'
 #	@# note: ln -sf isn't portable.
-	@cd $(TF_LIBDIR); \
+	@cd $(DESTDIR)$(TF_LIBDIR); \
 	rm -f bind-bash.tf;    ln -s  kb-bash.tf   bind-bash.tf;    \
 	rm -f bind-emacs.tf;   ln -s  kb-emacs.tf  bind-emacs.tf;   \
 	rm -f completion.tf;   ln -s  complete.tf  completion.tf;   \
