Package-Name: mikmod
Gentoo-Package: media-sound/mikmod
Requires: libmikmod ncurses|ncurses4
Source: ibibliolinux:///apps/sound/players/mikmod-(\d+.\d+.\d+).tar.gz $1
Zap-Before-Install: 1
Repack:
	tar xzvfp "$(SOURCE)"
Compile:
	CC="gcc -I/usr/include/ncurses" $(MAKE) -f ../Makefile configure
	$(MAKE)
	$(MAKE) install
Install:
	$(MAKE) instbin BIN=mikmod
	$(MAKE) instman SECTION=1 MAN=mikmod
Patch: <<EOT
### all of this is Debian
--- mikmod-3.1.6.orig/src/mikmod.1
+++ mikmod-3.1.6/src/mikmod.1
@@ -392,7 +392,7 @@
 .SH AUTHORS
 
 
-MikMod is the result of the work of many people, including:
+\fIMikMod\fP is the result of the work of many people, including:
 Jean-Paul Mikkers, Jake Stine, Miodrag Vallat, Frank Loemker, Steve McIntyre,
 Peter Amstutz, "MenTaLguY", Dimitri Boldyrev, Shlomi Fish, Stefan Tibus,
 Tinic Urou.
--- mikmod-3.1.6.orig/src/display.c
+++ mikmod-3.1.6/src/display.c
@@ -20,7 +20,7 @@
 
 /*==============================================================================
 
-  $Id: display.c,v 1.38 1999/07/05 04:00:02 miod Exp $
+  $Id: display.c,v 1.39 1999/07/11 17:49:33 miod Exp $
 
   Display routines for the different panels and the playlist menu
 
@@ -292,24 +292,18 @@
 	if ((entry=PL_GetCurrent(&playlist))) {
 		CHAR *archive=entry->archive,*file;
 
-		if (archive) {
+		if (archive && !config.fullpaths) {
 			archive=strrchr(entry->archive,PATH_SEP);
-			if (archive) {
-				if (config.fullpaths)
-					while ((archive>entry->archive)&&(*--archive!=PATH_SEP));
-				else
-					archive++;
-			} else
+			if (archive)
+				archive++;
+			else
 				archive=entry->archive;
 		}
 
 		file=strrchr(entry->file,PATH_SEP);
-		if (file) {
-			if (config.fullpaths)
-				while ((file>entry->file)&&(*--file!=PATH_SEP));
-			else
-				file++;
-		} else
+		if (file && !config.fullpaths)
+			file++;
+		else
 			file=entry->file;
 
 		if ((archive)&&(strlen(file)<MAXWIDTH-13)) {
@@ -388,6 +382,7 @@
 			sprintf(time,"/%2d:%02d",
 			        (int)((cur->time/60)%60),(int)(cur->time%60));
 #endif
+#if LIBMIKMOD_VERSION >= 0x030107
 		if (mf->flags&UF_NNA) {
 #ifdef HAVE_SNPRINTF
 			snprintf(channels,17,"%2d/%d+%d->%d",
@@ -396,7 +391,9 @@
 			sprintf(channels,"%2d/%d+%d->%d",
 			     mf->realchn,mf->numchn,mf->totalchn-mf->realchn,mf->totalchn);
 #endif
-		} else {
+		} else
+#endif
+		       {
 #ifdef HAVE_SNPRINTF
 			snprintf(channels,17,"%2d/%d      ",mf->realchn,mf->numchn);
 #else
@@ -829,12 +826,9 @@
 		timelen=strlen(time);
 	}
 	name=strrchr(pos->file,PATH_SEP);
-	if (name) {
-		if (config.fullpaths)
-			while ((name>pos->file)&&(*--name!=PATH_SEP));
-		else
-			name++;
-	} else
+	if (name && !config.fullpaths)
+		name++;
+	else
 		name=pos->file;
 
 	if (pos==cur) sort='>';
@@ -875,8 +869,8 @@
 				sprintf(storage,tmpfmt,nr,sort,name);
 #endif
 			}
-	} else if (strlen(name)>33-timelen) {
-		name=name+strlen(name)-(30-timelen);
+	} else if (strlen(name)>width-7-timelen) {
+		name=name+strlen(name)-(width-10-timelen);
 		if (timelen) {
 			sprintf(tmpfmt,"%%4i %%c...%%-%ds%%s",width-16);
 #ifdef HAVE_SNPRINTF
--- mikmod-3.1.6.orig/src/marchive.c
+++ mikmod-3.1.6/src/marchive.c
@@ -20,7 +20,7 @@
 
 /*==============================================================================
 
-  $Id: marchive.c,v 1.29 1999/07/05 04:00:02 miod Exp $
+  $Id: marchive.c,v 1.30 1999/07/11 17:50:57 miod Exp $
 
   Archive support
 
@@ -206,18 +206,22 @@
 	"*.[Ii][Mm][Ff]",
 	"*.[Ii][Tt]",
 	"*.[Mm][Ee][Dd]",
-	"[Mm][Ee][Dd].*",
 	"*.[Mm][Oo][Dd]",
-	"[Mm][Oo][Dd].*",
 	"*.[Mm][Tt][Mm]",
 	"*.[Nn][Ss][Tt]",	/* noisetracker */
-	"[Nn][Ss][Tt].*",
 	"*.[Ss]3[Mm]",
 	"*.[Ss][Tt][Mm]",
 	"*.[Ss][Tt][Xx]",
 	"*.[Uu][Ll][Tt]",
 	"*.[Uu][Nn][Ii]",
 	"*.[Xx][Mm]",
+	NULL
+};
+
+static CHAR* prefixmodulepatterns[]={
+	"[Mm][Ee][Dd].*",
+	"[Mm][Oo][Dd].*",
+	"[Nn][Ss][Tt].*",
 	"[Xx][Mm].*",		/* found on Aminet */
 	NULL
 };
@@ -260,6 +264,24 @@
 	return 0;
 }
 
+/* The same, but also checks for prefix names */
+static BOOL MA_isModuleFilename2(CHAR* filename)
+{
+	int t;
+
+	/* a filename may not start with '-' since this could be abused to
+	   feed another option to the archiver */
+	if (filename[0]=='-')
+		return 0;
+	for (t=0;modulepatterns[t];t++)
+		if (!fnmatch(modulepatterns[t],filename,FNM_NOESCAPE))
+			return 1;
+	for (t=0;prefixmodulepatterns[t];t++)
+		if (!fnmatch(prefixmodulepatterns[t],filename,FNM_NOESCAPE))
+			return 1;
+	return 0;
+}
+
 /* Determines if a filename extension matches an archive filename extension
    pattern */
 static BOOL MA_MatchExtension(CHAR *archive,CHAR *ends)
@@ -450,7 +472,8 @@
 		if (PL_Load(pl,filename))
 			return;
 
-	/* if filename looks like a module, don't try to unzip the file...*/
+	/* if filename looks like a module and not like an archive, don't try to
+	   unzip the file...*/
 	if (MA_isModuleFilename(filename)) {
 		PL_Add(pl,filename,NULL,0,0);
 		return;
@@ -488,7 +511,7 @@
 					for (t=0;string[t]!=' ';t++);
 					string[t]=0;
 				}
-				if (MA_isModuleFilename(string+MA_archiver[archive].nameoffset))
+				if (MA_isModuleFilename2(string+MA_archiver[archive].nameoffset))
 					PL_Add(pl,(string+MA_archiver[archive].nameoffset),filename,0,0);
 				fgets(string,PATH_MAX,file);
 			}
@@ -503,8 +526,8 @@
 
 			if (!pipe(fd)) {
 				pid_t pid;
-				int status,cur,finished=0;
-				char ch;
+				FILE *file;
+				int status,s;
 
 				switch (pid=fork()) {
 					case -1: /* fork failed */
@@ -534,40 +557,22 @@
 					}
 						break;
 					default: /* fork succeeded, main process code */
-						/* have to wait for the child to ensure the command was
-						   successful and the pipe contains useful
-						   information */
 
-						/* read from the pipe */
 						close(fd[1]);
-						cur=0;
-						for (;;) {
-							/* check if child process has finished */
-							if ((!finished)&&(waitpid(pid,&status,WNOHANG))) {
-								finished=1;
-								/* abnormal exit */
-								if (!WIFEXITED(status)) {
-								  close(fd[0]);
-								  break;
-								}
-							}
-
-							/* check for end of pipe, otherwise read char */
-							if ((!read(fd[0],&ch,1))&&(finished)) break;
-
-							if (ch=='\n') ch=0;
-							string[cur++]=ch;
-							if (!ch) {
-								cur=0;
-								if (!MA_archiver[archive].nameoffset) {
-									for (t=0;string[t]!=' ';t++);
-									string[t]=0;
-								}
-								if (MA_isModuleFilename(string+MA_archiver[archive].nameoffset))
-									PL_Add(pl,(string+MA_archiver[archive].nameoffset),filename,0,0);
-							}
+						if (!(file=fdopen(fd[0],"r"))) {
+							close(fd[1]);
+							waitpid(pid,&status,0);
+							break;
+						}
+						/* read from the pipe */
+						while (fgets(string,PATH_MAX+MAXCOLUMN+1,file)) {
+							s=strlen(string)-1;
+							if (string[s]=='\n') string[s]='\0';
+							if (MA_isModuleFilename2(string+MA_archiver[archive].nameoffset))
+								PL_Add(pl,(string+MA_archiver[archive].nameoffset),filename,0,0);
 						}
-						close(fd[0]);
+						fclose(file);
+						waitpid(pid,&status,0);
 						break;
 				}
 			}
@@ -589,7 +594,7 @@
 			if (spare) {
 				strncpy(spare,slash,dot-slash);spare[dot-slash]=0;
 
-				if (MA_isModuleFilename(spare)) PL_Add(pl,spare,filename,0,0);
+				if (MA_isModuleFilename2(spare)) PL_Add(pl,spare,filename,0,0);
 				free(spare);
 			}
 		}
--- mikmod-3.1.6.orig/src/mconfedit.c
+++ mikmod-3.1.6/src/mconfedit.c
@@ -20,7 +20,7 @@
 
 /*==============================================================================
 
-  $Id: mconfedit.c,v 1.3 1999/07/05 04:00:02 miod Exp $
+  $Id: mconfedit.c,v 1.4 1999/07/11 17:50:08 miod Exp $
 
   The config editor
 
@@ -89,8 +89,10 @@
 
 static MENTRY output_entries[]={
 	{NULL,			0,"The device driver for output"},
-	{"Driver &options [%s]|Enter driver options:|999|12",
+#if LIBMIKMOD_VERSION >= 0x030107
+	{"Driver &options [%s]|Enter driver options:|99|16",
 					0,"Driver options (e.g. \"buffer=14,count=16\" for the OSS-driver)"},
+#endif
 	{"[%c] &Stereo",	0,"mono/stereo output"},
 	{"[%c] 16 &bit output",0,"8/16 bit output"},
 	{"&Frequency      [%d]|Enter mixing frequency:|4000|60000",
@@ -100,7 +102,13 @@
 	{"[%c] S&urround",0,"Use surround mixing"},
 	{"&Reverb            [%d]|Enter reverb amount:|0|15",
 					0,"Reverb amount from 0 (no reverb) to 15"}};
-static MMENU output_menu={0,0,9,1,output_entries,handle_menu,NULL,NULL,1};
+static MMENU output_menu={0,0,
+#if LIBMIKMOD_VERSION >= 0x030107
+                              9,
+#else
+                              8,
+#endif
+                                1,output_entries,handle_menu,NULL,NULL,1};
 
 static MENTRY playback_entries[]={
 	{"&Volume   [%d]|Enter output volume:|0|100",
@@ -134,7 +142,7 @@
 				"Change process priority, MikMod must be restarted to change this"},
 	{"Status&bar     [%o]|None|Small|Big",0,"Size of the statusbar"},
 	{"&On exit             >",&exit_menu,""}};
-static MMENU other_menu={0,0,6,1,other_entries,handle_menu,NULL,NULL,3};
+static MMENU other_menu={0,0,7,1,other_entries,handle_menu,NULL,NULL,3};
 
 static MENTRY entries[]={
 	{"&Output options   >",&output_menu,""},
--- mikmod-3.1.6.orig/src/mikmod.c
+++ mikmod-3.1.6/src/mikmod.c
@@ -404,12 +404,17 @@
 	             ((cfg->driver)&&(cfg->driver!=md_device))||
 	             (!cmp_bit(md_mode,DMODE_16BITS,cfg->mode_16bit))||
 	             (!cmp_bit(md_mode,DMODE_STEREO,cfg->stereo))||
-	             (!cmp_bit(md_mode,DMODE_HQMIXER,cfg->hqmixer))||
-				 ((!driveroptions && cfg->driveroptions) ||
-				  (driveroptions && strcmp(driveroptions,cfg->driveroptions))));
+	             (!cmp_bit(md_mode,DMODE_HQMIXER,cfg->hqmixer))
+#if LIBMIKMOD_VERSION >= 0x030107
+				 ||((!driveroptions && cfg->driveroptions) ||
+				  (driveroptions && strcmp(driveroptions,cfg->driveroptions)))
+#endif
+	             );
 
+#if LIBMIKMOD_VERSION >= 0x030107
 	if (driveroptions) free(driveroptions);
 	driveroptions=strdup(cfg->driveroptions);
+#endif
 
 	md_pansep=128; /* panning separation (0=mono 128=full stereo) */
 	md_volume=(cfg->volume*128)/100;
--- mikmod-3.1.6.orig/src/mlist.c
+++ mikmod-3.1.6/src/mlist.c
@@ -20,7 +20,7 @@
 
 /*==============================================================================
 
-  $Id: mlist.c,v 1.21 1999/07/05 04:00:02 miod Exp $
+  $Id: mlist.c,v 1.22 1999/07/11 17:49:33 miod Exp $
 
   Functions to handle the playlist.
 
@@ -296,7 +296,7 @@
 		else {
 			/* we're loading a playlist, so it might be necessary to convert
 			   playlist paths to relative paths from cwd */
-			if (slash) {
+			if (slash && path_relative(arc?arc:mod)) {
 				CHAR *dummy;
 
 				dummy=malloc(slash+1-filename+strlen(arc?arc:mod)+1);
--- mikmod-3.1.6.orig/src/mutilities.c
+++ mikmod-3.1.6/src/mutilities.c
@@ -20,7 +20,7 @@
 
 /*==============================================================================
 
-  $Id: mutilities.c,v 1.3 1999/07/05 04:00:02 miod Exp $
+  $Id: mutilities.c,v 1.4 1999/07/11 17:49:33 miod Exp $
 
   Some utility functions
 
@@ -68,6 +68,18 @@
 	struct stat sb;
 
 	return (stat(file,&sb)==-1)?0:1;
+}
+
+/* determines if a given path is absolute or relative */
+BOOL path_relative(char *path)
+{
+	if (!path) return 1;
+	
+#if defined(__OS2__)||defined(__EMX__)
+	if (*path && (path[1]==':')) return 0;
+#endif
+
+	return (*path!=PATH_SEP);
 }
 
 /* allocate and return a name for a temporary file */
--- mikmod-3.1.6.orig/src/mutilities.h
+++ mikmod-3.1.6/src/mutilities.h
@@ -20,7 +20,7 @@
 
 /*==============================================================================
 
-  $Id: mutilities.h,v 1.3 1999/07/05 04:00:02 miod Exp $
+  $Id: mutilities.h,v 1.4 1999/07/11 17:49:33 miod Exp $
 
   Some utility functions
 
@@ -37,6 +37,8 @@
 char *get_tmp_name(void);
 
 BOOL file_exist(char*);
+/* determines if a given path is absolute or relative */
+BOOL path_relative(char*);
 
 /* allocate and return a filename including the path for a config file
    'name': filename without the path */
--- mikmod-3.1.6.orig/debian/changelog
+++ mikmod-3.1.6/debian/changelog
@@ -0,0 +1,101 @@
+mikmod (3.1.6-2potato3) oldstable-security; urgency=high
+
+  * Target oldstable-security (oops)
+
+ -- Matt Zimmerman <mdz@debian.org>  Fri,  6 Jun 2003 02:43:40 +0000
+
+mikmod (3.1.6-2potato2) stable-security; urgency=high
+
+  * Fix typo in build-deps
+
+ -- Matt Zimmerman <mdz@debian.org>  Fri,  6 Jun 2003 02:13:24 +0000
+
+mikmod (3.1.6-2potato1) stable-security; urgency=high
+
+  * Non-maintainer upload by the Security Team
+  * Fix buffer overflow when scanning archive contents [marchive.c]
+  * Avoid a potential attack with filenames starting with '-' being
+    interpreted as options to an archive program
+  * Build-Depends: debhelper, likmikmod2-dev, libncurses5-dev
+
+ -- Matt Zimmerman <mdz@debian.org>  Thu,  5 Jun 2003 21:52:15 -0400
+
+mikmod (3.1.6-2) unstable; urgency=low
+
+  * Applied upstream -a level patch
+
+ -- Joseph Carter <knghtbrd@debian.org>  Thu,  5 Aug 1999 06:38:17 -0700
+
+mikmod (3.1.6-1) unstable; urgency=low
+
+  * New upstream version
+  * Policy 3.0.0, debhelper v2 (hi joeyh!)  
+  * Removed Suggests line for non-free archivers since if you have tracks
+    that are compressed with an archiver you know you need the archiver.
+
+ -- Joseph Carter <knghtbrd@debian.org>  Thu,  8 Jul 1999 06:22:27 -0700
+
+mikmod (3.1.5-1) unstable; urgency=low
+
+  * New upstream version (Closes: #34493, #39421)
+  * libmikmod is now a seperate package which will only use ALSA or EsounD
+    if they are available (Closes: #38242, #29133)
+
+ -- Joseph Carter <knghtbrd@debian.org>  Sun, 13 Jun 1999 15:14:32 -0700
+
+mikmod (3.1.2-2) unstable; urgency=low
+
+  * Rebuilt for potato's ALSA
+
+ -- Joseph Carter <knghtbrd@debian.org>  Thu, 28 Jan 1999 12:21:21 -0800
+
+mikmod (3.1.2-1) unstable; urgency=low
+
+  * New upstream version
+
+ -- Joseph Carter <knghtbrd@debian.org>  Fri, 18 Dec 1998 23:58:33 -0800
+
+mikmod (3.0.4-2) unstable; urgency=low
+
+  * Applied 3 upstream patches to fix bugs and add ALSA support
+  * Built also with ALSA support
+
+ -- Joseph Carter <knghtbrd@debian.org>  Tue, 13 Oct 1998 09:38:22 -0700
+
+mikmod (3.0.4-1) unstable; urgency=low
+
+  * New maintainer.
+  * New upstream version.
+  * This package is now DFSG free (GPL and LGPL).
+  * Massive upstream revisions including both non-compressed and compressed
+    sample Impulse Tracker support.
+  * Built with both OSS and EsounD driver support.
+
+ -- Joseph Carter <knghtbrd@debian.org>  Fri,  9 Oct 1998 09:14:53 -0700
+
+mikmod (2.14-3) unstable; urgency=low
+
+  * Libc 6 release - replaces non-maintainer release (fixes bug #14933)
+  * Back to my non-debstd rules file, so changelog.Debian compressed again (fixes bug #15436)
+  * Removed surplus documentation (fixes bug #18111)
+  * Next release (v3.0) due soon, should be DFSG.
+
+ -- Steve McIntyre <stevem@chiark.greenend.org.uk>  Thu, 12 Mar 1998 23:31:32 +0000
+
+mikmod (2.14-2) unstable; urgency=low
+
+  * Oops! Changed banner message from development version...
+
+ -- Steve McIntyre <stevem@chiark.greenend.org.uk>  Wed, 1 Jan 1997 16:40:39 +0000
+
+mikmod (2.14-1) unstable; urgency=low
+
+  * New upstream version.
+  * Fixes Bug#6276 - mikcvt now has a man page.
+  * Fixes Bug#5671 - errors now re-displayed on exit.
+
+ -- Steve McIntyre <stevem@chiark.greenend.org.uk>  Wed, 1 Jan 1997 14:10:39 +0000
+
+Local variables:
+mode: debian-changelog
+End:
--- mikmod-3.1.6.orig/debian/rules
+++ mikmod-3.1.6/debian/rules
@@ -0,0 +1,60 @@
+#!/usr/bin/make -f
+
+#export DH_VERBOSE=1
+export DH_COMPAT=2
+
+PWD=$(shell pwd)
+
+build: build-stamp
+build-stamp:
+	dh_testdir
+
+	mkdir build && cd build && ../configure --prefix=/usr \
+	                                 --mandir=/usr/share/man
+	$(MAKE) -C build
+
+	touch build-stamp
+
+clean:
+	dh_testdir
+	dh_testroot
+	-rm -f build-stamp install-stamp
+
+	-rm -rf build
+
+	dh_clean
+
+install: install-stamp
+install-stamp: build-stamp
+	dh_testdir
+	dh_testroot
+	dh_clean -k
+	dh_installdirs
+
+	$(MAKE) -C build install DESTDIR=$(PWD)/debian/mikmod
+
+	touch install-stamp
+
+# Build architecture-independent files here.
+binary-indep: build install
+
+# Build architecture-dependent files here.
+binary-arch: build install
+	dh_testversion 2
+	dh_testdir
+	dh_testroot
+	dh_installdocs
+	dh_installexamples
+	dh_installchangelogs
+	dh_strip
+	dh_compress
+	dh_fixperms
+	dh_installdeb
+	dh_shlibdeps
+	dh_gencontrol
+	dh_md5sums
+	dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary
+
--- mikmod-3.1.6.orig/debian/control
+++ mikmod-3.1.6/debian/control
@@ -0,0 +1,15 @@
+Source: mikmod
+Section: sound
+Priority: optional
+Maintainer: Joseph Carter <knghtbrd@debian.org>
+Standards-Version: 3.0.0
+Build-Depends: debhelper, libmikmod2-dev, libncurses5-dev
+
+Package: mikmod
+Architecture: any
+Depends: ${shlibs:Depends}
+Description: Portable tracked music player
+ Mikmod is a very portable tracked music player which supports a wide
+ variety of module formats including compressed sample Impulse Tracker
+ modules. It also supports many archive formats, as well as on the fly
+ decompression.
--- mikmod-3.1.6.orig/debian/copyright
+++ mikmod-3.1.6/debian/copyright
@@ -0,0 +1,19 @@
+/*  MikMod example player
+        (c) 1998, 1999 Miodrag Vallat and others - see file AUTHORS for
+        complete list.
+
+        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., 59 Temple Place - Suite 330, Boston, MA
+        02111-1307, USA.
+*/
--- mikmod-3.1.6.orig/debian/mikmod.dirs
+++ mikmod-3.1.6/debian/mikmod.dirs
@@ -0,0 +1,3 @@
+usr/bin
+usr/share/man/man1
+
--- mikmod-3.1.6.orig/debian/mikmod.examples
+++ mikmod-3.1.6/debian/mikmod.examples
@@ -0,0 +1,2 @@
+convert_playlist
+
--- mikmod-3.1.6.orig/debian/mikmod.docs
+++ mikmod-3.1.6/debian/mikmod.docs
@@ -0,0 +1,3 @@
+README
+AUTHORS
+NEWS
EOT

/pkg/mikmod/
/usr/bin/mikmod
/usr/man/man1/mikmod.1.gz
