--- eflite-0.4.1.orig/es.c
+++ eflite-0.4.1/es.c
@@ -329,7 +329,7 @@
   char *p;
 
   p = getenv("HOME");
-  sprintf(buf, "%s/.es.conf", p);
+  snprintf(buf, sizeof(buf), "%s/.es.conf", p);
   fp = fopen(buf, "r");
   if (!fp) fp = fopen("/etc/es.conf", "r");
   if (!fp) return 1;
@@ -438,7 +438,7 @@
   char logname[200];
 
   if ((flags & 0xffff) > DEBUG) return;
-  sprintf(logname, "%s/es.log", getenv("HOME"));
+  sprintf(logname, sizeof(logname), "%s/es.log", getenv("HOME"));
   va_start(arg, text);
   vsnprintf(buf, 200, text, arg);
   va_end(arg);
--- eflite-0.4.1.orig/Makefile.in
+++ eflite-0.4.1/Makefile.in
@@ -28,7 +28,7 @@
 #CFLAGS+= -DDEBUG=2
 
 # For making releases
-FLITE_LIBS:=-L$(flite_dir)/lib -lflite_$(FL_VOX) -lflite_$(FL_LEX) -lflite_$(FL_LANG) -lflite
+FLITE_LIBS:=-L$(flite_dir)/lib -lflite_$(subst cmu_us_kal16,cmu_us_kal,$(FL_VOX)) -lflite_$(FL_LEX) -lflite_$(FL_LANG) -lflite
 
 eflite: fs.o es.o soccon.o sockopen.o tone.o
 	$(CC) $(LDFLAGS) -o $@ $^ -lm $(LIBS) $(FLITE_LIBS) $(AUDIOLIBS)
--- eflite-0.4.1.orig/fs.c
+++ eflite-0.4.1/fs.c
@@ -9,7 +9,7 @@
  * GNU General Public License, as published by the Free Software
  * Foundation.  Please see the file COPYING for details.
  *
- * $Id: fs.c,v 1.19 2007/01/18 23:58:42 mgorse Exp $
+ * $Id: fs.c,v 1.22 2008/03/05 15:21:43 mgorse Exp $
  *
  * Notes:
  *
@@ -505,19 +505,6 @@
   }
 }
 
-
-
-static void play_audio_close(void *cancel)
-{
-  if (audiodev)
-  {
-	audio_drain(audiodev);
-	close_audiodev();
-	//	usleep(5000);
-  }
-}
-
-
 static inline void determine_playlen(int speed, cst_wave *wptr, int type, int *pl, int *s)
 {
   int playlen, skip;
@@ -573,12 +560,12 @@
 	type = ac[ac_head].type;
 	WAVE_UNLOCK;
 	pthread_testcancel();
-	pthread_cleanup_push(play_audio_close, NULL);
-
+	
 	es_log(2, "Opening audio device.");
 	/* We abuse the wave mutex here to avoid being canceled
 	 * while the audio device is being openned */
 	WAVE_LOCK;
+	assert(audiodev == NULL);
 	audiodev = audio_open(wptr->sample_rate, wptr->num_channels, CST_AUDIO_LINEAR16);
 	WAVE_UNLOCK;
 	if (audiodev == NULL)
@@ -606,8 +593,8 @@
 #ifdef DEBUG
 	  start_time = get_ticks_count();
 #endif
-	  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
       audio_write(audiodev, wptr->samples + skip, playlen * 2);
+      pthread_testcancel();
 	  es_log(2, "Write took %.2f seconds.", get_ticks_count() - start_time);
 	}
     es_log(2, "play: syncing.");
@@ -617,16 +604,16 @@
     audio_flush(audiodev);
 	pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
 	es_log(2, "Flush took %.2f seconds.", get_ticks_count() - start_time);
-    es_log(2, "play: Closing audio device");
-	close_audiodev();
-	pthread_cleanup_pop(0);
-	  pthread_testcancel();
-	  TEXT_LOCK;
+    	pthread_testcancel();
+
+	TEXT_LOCK;
     time_left -= ((float)playlen) / wptr->sample_rate;
 	pthread_cond_signal(&text_condition);
 	TEXT_UNLOCK;
 
 	WAVE_LOCK;
+	es_log(2, "play: Closing audio device");
+	close_audiodev();
     ac_destroy(&ac[ac_head]);
 	ac_head++;
 	if (ac_head == ac_tail)
@@ -894,6 +881,7 @@
 	WAVE_LOCK_NI;
 	pthread_cond_signal(&wave_condition); // necessary because we inhibit cancellation while waiting
 	pthread_cancel(wave_thread);
+	if (audiodev != NULL) audio_drain(audiodev);
 	WAVE_UNLOCK_NI;
   }
 
@@ -917,7 +905,10 @@
   }
 	
   /* At this point, no thread is running */
-  
+
+  // Make sure audio device is closed
+  close_audiodev();
+
   /* Free any wave data */
   es_log(2, "s_clear: freeing wave data: %d", ac_tail);
   for (i = 0; i < ac_tail; i++)
--- eflite-0.4.1.orig/debian/watch
+++ eflite-0.4.1/debian/watch
@@ -0,0 +1,3 @@
+version=2
+http://sf.net/eflite/eflite-(.*)\.tar\.gz debian uupdate
+
--- eflite-0.4.1.orig/debian/compat
+++ eflite-0.4.1/debian/compat
@@ -0,0 +1 @@
+7
--- eflite-0.4.1.orig/debian/eflite.1
+++ eflite-0.4.1/debian/eflite.1
@@ -0,0 +1,45 @@
+.\"                                      Hey, EMACS: -*- nroff -*-
+.\" First parameter, NAME, should be all caps
+.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
+.\" other parameters are allowed: see man(7), man(1)
+.TH EFLITE 1 "June 24, 2002"
+.\" Please adjust this date whenever revising the manpage.
+.\"
+.\" Some roff macros, for reference:
+.\" .nh        disable hyphenation
+.\" .hy        enable hyphenation
+.\" .ad l      left justify
+.\" .ad b      justify to both left and right margins
+.\" .nf        disable filling
+.\" .fi        enable filling
+.\" .br        insert line break
+.\" .sp <n>    insert n+1 empty lines
+.\" for manpage-specific macros, see man(7)
+.SH NAME
+eflite \- a speech server for Festival lite 
+.SH SYNOPSIS
+.B eflite
+.SH DESCRIPTION
+This manual page documents briefly the
+.B eflite
+command.
+This manual page was written for the Debian distribution
+because the original program does not have a manual page.
+Instead, it has documentation in /usr/share/doc/eflite/README*
+.PP
+.\" TeX users may be more comfortable with the \fB<whatever>\fP and
+.\" \fI<whatever>\fP escape sequences to invode bold face and italics, 
+.\" respectively.
+\fBeflite\fP is a program that is used as a backend for
+screen reader applications.
+It is usually not called by the user, instead it is invoked by
+the application which needs to output information via Festival Lite's
+speech synthesis engine.
+.SH OPTIONS
+This program does not have any options at this time.
+Instead, it's controlled by the data received via STDIN.
+.SH SEE ALSO
+.BR emacspeak (1),
+.SH AUTHOR
+This manual page was written by Mario Lang <mlang@debian.org>,
+for the Debian GNU/Linux system (but may be used by others).
--- eflite-0.4.1.orig/debian/dirs
+++ eflite-0.4.1/debian/dirs
@@ -0,0 +1 @@
+usr/bin
--- eflite-0.4.1.orig/debian/README.Debian
+++ eflite-0.4.1/debian/README.Debian
@@ -0,0 +1,14 @@
+eflite for Debian
+-----------------
+
+Now that Festival Lite 1.2 supports generating shared libraries,
+this version of eflite is linked against them.  This saves
+a very large amount of space.
+
+A emacspeak server blurb file is also included, so that
+emacspeakconfig should automatically pick eflite up as a possible
+speech server to select.  Note that you need to install
+eflite prior to installing emacspeak if you want to see eflite
+as a possible speech server to choose from.
+ 
+ -- Mario Lang <mlang@debian.org>, Wed, 26 Mar 2003 11:38:52 +0200
--- eflite-0.4.1.orig/debian/copyright
+++ eflite-0.4.1/debian/copyright
@@ -0,0 +1,17 @@
+This package was debianized by Mario Lang <mlang@delysid.org> on
+Tue,  7 May 2002 12:38:52 +0200.
+
+It was downloaded from ftp://prdownloads.sf.net/pub/sourceforge/eflite/
+
+Upstream Author: Michael P. Gorse <mgorse@alum.wpi.edu>
+
+
+Copyright: Copyright (C) 2001 by Roger Butenuth
+           Copyright 2002 by Michael Gorse
+           Copyright 2006 by Lukas Loehrer
+
+eflite is licensed under the GNU General Public License.
+On Debian systems you can find a copy of the GPL in
+the file `/usr/share/common-licenses/GPL'.
+
+
--- eflite-0.4.1.orig/debian/install
+++ eflite-0.4.1/debian/install
@@ -0,0 +1 @@
+debian/eflite.blurb usr/share/emacs/site-lisp/emacspeak/blurbs
--- eflite-0.4.1.orig/debian/changelog
+++ eflite-0.4.1/debian/changelog
@@ -0,0 +1,141 @@
+eflite (0.4.1-6.4.201403211331) ucs4-0-0-0; urgency=low
+
+  * UCS auto build. No patches were applied to the original source package
+
+ -- Univention builddaemon <buildd@univention.de>  Fri, 21 Mar 2014 13:31:06 +0100
+
+eflite (0.4.1-6) unstable; urgency=low
+
+  * rules: Fix build against multi-arch libflite (Closes: Bug#676730).
+  * control: build-depend on multi-arch libflite.
+
+ -- Samuel Thibault <sthibault@debian.org>  Sun, 10 Jun 2012 17:12:17 +0200
+
+eflite (0.4.1-5) unstable; urgency=low
+
+  [ Samuel Thibault ]
+  * Set eflite Multi-Arch: foreign.
+  * Bump Standards-Version to 3.9.3 (no change needed)
+  * Depend on hardening-check.
+  * Set DEB_BUILD_HARDENING=1 to enable hardening.
+
+ -- Samuel Thibault <sthibault@debian.org>  Fri, 08 Jun 2012 22:47:53 +0200
+
+eflite (0.4.1-4) unstable; urgency=low
+
+  [ Mario Lang ]
+  * Add Homepage field to debian/control.
+
+  [ Samuel Thibault ]
+  * es.c: Fix buffer overflow (Closes: #507108).
+  * Makefile.in: Fix flite link flags (Closes: #577864).
+  * debian/control:
+    - Add myself in Uploaders.
+    - Bump Standards-Version to 3.9.1 (no changes needed).
+    - Document that only English is supported.
+
+ -- Samuel Thibault <sthibault@debian.org>  Tue, 27 Jul 2010 01:48:07 +0200
+
+eflite (0.4.1-3) unstable; urgency=low
+
+  * Apply upstream patches from CVS to fix a race (Closes: Bug#542468).
+  * Disable test during build since it requires sound hardware (fixes
+    FTBFS).
+
+ -- Mario Lang <mlang@debian.org>  Thu, 27 Aug 2009 15:17:11 +0200
+
+eflite (0.4.1-2) unstable; urgency=low
+
+  * Switch to debhelper 7.
+  * Add Vcs-* fields to debian/control.
+  * Fix debian/watch file to use sf.net redirector (which is broken right now)
+    (Closes: Bug#449891).
+  * Upgrade ancient Standards-Version to 3.8.3.
+  * Add Copyright years/holders to debian/copyright.
+  * Add device: description to eflite.blurb.
+
+ -- Mario Lang <mlang@debian.org>  Thu, 27 Aug 2009 13:52:05 +0200
+
+eflite (0.4.1-1) unstable; urgency=low
+
+  * New upstream release (Closes: Bug#391511).
+
+ -- Mario Lang <mlang@debian.org>  Fri, 26 Jan 2007 20:38:30 +0100
+
+eflite (0.3.8-2) unstable; urgency=low
+
+  * Fix blurb file (Closes Bug#354918).
+
+ -- Mario Lang <mlang@debian.org>  Sun, 23 Apr 2006 12:36:58 +0200
+
+eflite (0.3.8-1) unstable; urgency=low
+
+  * New upstream bugfix release.
+
+ -- Mario Lang <mlang@debian.org>  Wed, 25 Feb 2004 13:55:10 +0100
+
+eflite (0.3.7-2) unstable; urgency=low
+
+  * Lower the Recommends: emacspeak to Suggests, and add yasr too.
+
+ -- Mario Lang <mlang@debian.org>  Thu, 20 Nov 2003 17:31:19 +0100
+
+eflite (0.3.7-1) unstable; urgency=low
+
+  * New upstream version.
+
+ -- Mario Lang <mlang@debian.org>  Fri,  1 Aug 2003 14:45:10 +0200
+
+eflite (0.3.6-1) unstable; urgency=low
+
+  * New upstream release (merged the flite_include_dir patch upstream)
+  * Set Standards-Version to 3.5.9
+  * Use dh_compat 4 and depend on debhepler >> 4.
+  * Patch Makefile.in to link with shared libs.
+
+ -- Mario Lang <mlang@debian.org>  Wed, 26 Mar 2003 10:33:51 +0100
+
+eflite (0.3.5-2) unstable; urgency=low
+
+  * Relink against 16bit voice (Closes: Bug#169803)
+
+ -- Mario Lang <mlang@debian.org>  Thu, 13 Feb 2003 09:59:20 +0100
+
+eflite (0.3.5-1) unstable; urgency=low
+
+  * New upstream version (Closes: Bug#177294)
+
+ -- Mario Lang <mlang@debian.org>  Tue, 21 Jan 2003 11:00:46 +0100
+
+eflite (0.3.4-1) unstable; urgency=low
+
+  * New upstream version.
+
+ -- Mario Lang <mlang@debian.org>  Tue, 10 Dec 2002 11:20:02 +0100
+
+eflite (0.3.3-1) unstable; urgency=low
+
+  * New upstream version.
+  * Add eflite.blurb file (Closes: Bug#169802)
+  * Add "Recommends: emacspeak" to debian/control.
+
+ -- Mario Lang <mlang@debian.org>  Wed, 20 Nov 2002 11:30:00 +0100
+
+eflite (0.3.2-1) unstable; urgency=low
+
+  * New upstream version.
+
+ -- Mario Lang <mlang@delysid.org>  Tue, 25 Jun 2002 00:38:52 +0200
+
+eflite (0.2.2-2) unstable; urgency=low
+
+  * Make it lintian clean.
+
+ -- Mario Lang <mlang@delysid.org>  Tue, 24 Jun 2002 20:38:52 +0200
+
+eflite (0.2.2-1) unstable; urgency=low
+
+  * Initial release.
+
+ -- Mario Lang <mlang@delysid.org>  Tue,  7 May 2002 12:38:52 +0200
+
--- eflite-0.4.1.orig/debian/control
+++ eflite-0.4.1/debian/control
@@ -0,0 +1,23 @@
+Source: eflite
+Section: sound
+Priority: extra
+Maintainer: Debian Accessibility Team <debian-accessibility@lists.debian.org>
+Uploaders: Mario Lang <mlang@debian.org>, Samuel Thibault <sthibault@debian.org>
+Vcs-Browser: http://git.debian.org/?p=pkg-a11y/eflite.git;a=summary
+Vcs-Git: git://git.debian.org/git/pkg-a11y/eflite.git
+Build-Depends: debhelper (>= 7.0.50~), flite1-dev (>= 1.4-release-5), hardening-wrapper
+Standards-Version: 3.9.3
+
+Package: eflite
+Architecture: any
+Multi-Arch: foreign
+Depends: ${misc:Depends}, ${shlibs:Depends}
+Suggests: emacspeak, yasr
+Description: Festival-Lite based emacspeak speech server
+ EFlite is a speech server for Emacspeak and other screen readers that
+ allows them to interface with Festival Lite, a free text-to-speech
+ engine developed at the CMU Speech Center as an off-shoot of Festival.
+ .
+ Due to limitations inherited from its backend, EFlite does only provide
+ support for the English language at the moment.
+Homepage: http://eflite.sourceforge.net/
--- eflite-0.4.1.orig/debian/eflite.blurb
+++ eflite-0.4.1/debian/eflite.blurb
@@ -0,0 +1,4 @@
+blurb: eflite
+program: /usr/bin/eflite
+tcl:
+device: Soundcard with eflite
--- eflite-0.4.1.orig/debian/eflite.manpages
+++ eflite-0.4.1/debian/eflite.manpages
@@ -0,0 +1 @@
+debian/eflite.1
--- eflite-0.4.1.orig/debian/examples
+++ eflite-0.4.1/debian/examples
@@ -0,0 +1 @@
+eflite_test.txt
--- eflite-0.4.1.orig/debian/rules
+++ eflite-0.4.1/debian/rules
@@ -0,0 +1,22 @@
+#!/usr/bin/make -f
+
+DEB_HOST_MULTIARCH  ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
+
+export DEB_BUILD_HARDENING=1
+
+%:
+	dh $@
+
+override_dh_auto_configure:
+	flite_dir=/usr/lib/$(DEB_HOST_MULTIARCH) flite_include_dir=/usr/include/flite dh_auto_configure -- --with-vox=cmu_us_kal16
+
+override_dh_auto_install:
+	dh_auto_install -- prefix=$(CURDIR)/debian/eflite/usr
+
+override_dh_auto_test:
+	# Disable test since it requires sound hardware
+
+override_dh_auto_clean:
+	dh_auto_clean
+	rm -f eflite config.status config.log config.guess config.sub Makefile 
+
