--- xpbiff.c.orig	Wed Oct 26 23:42:52 1994
+++ xpbiff.c	Sun Sep  8 03:16:26 2002
@@ -74,6 +74,12 @@
 #endif
 #endif /* SUN_AUDIO */
 
+#ifdef BSD_AUDIO
+#include <sys/soundcard.h>
+#define MAX_SOUND_VOL 95
+#define MIN_SOUND_VOL 05
+#endif
+
 #ifndef X11R3
 #include <X11/Xaw/Box.h>
 #include <X11/Xaw/Label.h>
@@ -116,7 +122,11 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <math.h>
+#ifdef HAVE_GETPWUID
+#include <pwd.h>
+#endif /* HAVE_GETPWUID */
 
 #ifdef YOUBIN
 
@@ -149,11 +159,13 @@
 
 #ifndef YOUBIN
 
+#ifndef SPOOLPATH
 #ifdef USG
 #define SPOOLPATH	"/usr/mail/"
 #else
 #define SPOOLPATH	"/usr/spool/mail/"
 #endif
+#endif
 
 #else /* YOUBIN */
 
@@ -324,7 +336,7 @@
     NULL
 };
 
-#ifdef SUN_AUDIO
+#if (defined(SUN_AUDIO) || defined(BSD_AUDIO))
 String mail_sndfile;
 int volume;
 #endif
@@ -399,7 +411,7 @@
     {"nomailPixmapMask", "NomailPixmapMask", XtRBitmap, sizeof(Pixmap),
 	 (Cardinal)&noPixmapMask, XtRBitmap, None},
 #endif
-#ifdef SUN_AUDIO
+#if (defined(SUN_AUDIO) || defined(BSD_AUDIO))
     {"mailSndFile", "MailSndFile", XtRString, sizeof(String),
      (Cardinal)&mail_sndfile, XtRString, None},
     {"volume", "Volume", XtRInt, sizeof(int),
@@ -445,7 +457,7 @@
     {"-server",		"*server",		XrmoptionSepArg,	NULL},
     {"-preserve",	"*preserve",		XrmoptionNoArg,		"true"},
 #endif /* YOUBIN */
-#ifdef SUN_AUDIO
+#if (defined(SUN_AUDIO) || defined(BSD_AUDIO))
     {"-sndfile",	"*mailSndFile",		XrmoptionSepArg,	NULL},
     {"-volume",		"*volume",		XrmoptionSepArg,	NULL},
 #endif
@@ -485,9 +497,9 @@
     XGCValues		values;
     XtTranslations	newTranslations;
     static XtActionsRec redrawActions[] = {
-	{"expose", (XtCallbackProc) redraw_callback},
-	{"select", (XtCallbackProc) popup_again},
-	{"quit", (XtCallbackProc) quit},
+	{"expose", (XtActionProc) redraw_callback},
+	{"select", (XtActionProc) popup_again},
+	{"quit", (XtActionProc) quit},
     };
 
     static char		*overrideTranslations =
@@ -498,6 +510,9 @@
     int			dummy;
     int			i;
 
+#ifdef HAVE_GETPWUID
+    struct passwd	*pw;
+#endif
 #ifdef JCONVERT
     char		*locale_name;
     Locale_ent		*p;
@@ -514,28 +529,40 @@
 #endif /* !YOUBIN */
 
 #ifdef YOUBIN
-	if ((prog_name = strrchr(argv[0], '/')) != NULL) {
-	    prog_name++;
-	} else {
-	    prog_name = argv[0];
-	}
+    if ((prog_name = strrchr(argv[0], '/')) != NULL) {
+	prog_name++;
+    } else {
+	prog_name = argv[0];
+    }
 #else	/* !YOUBIN */
-    if (spoolPath != NULL && spoolPath[0] != '\0')
+    if (spoolPath != NULL && spoolPath[0] != '\0') {
 	strcpy(spool_path, spoolPath);
-    else
+    } else {
     	strcpy(spool_path, SPOOLPATH);
-    if (spool_path[strlen(spool_path) - 1] != '/')
+    }
+    if (spool_path[strlen(spool_path) - 1] != '/') {
 	strcat(spool_path, "/");
+    }
+
 #ifdef GETENV_MAIL
-    if (getenv("MAIL") != NULL)
+    if (getenv("MAIL") != NULL) {
 	strcpy(spool_path, getenv("MAIL"));
-    else
-#endif
-#ifndef NO_CUSERID
-	strcat(spool_path, cuserid(NULL));
-#else
+    } else {
+#endif /* GETENV_MAIL */
+
+#ifdef HAVE_GETPWUID
+	pw = getpwuid(getuid());
+	strcat(spool_path, pw->pw_name);
+#elif defined(NO_CUSERID)
 	strcat(spool_path, getenv("USER"));
-#endif
+#else
+	strcat(spool_path, (char *)cuserid(NULL));
+#endif /* NO_CUSERID && HAVE_GETPWUID */
+
+#ifdef GETENV_MAIL
+    }
+#endif /* GETENV_MAIL */
+
 #endif /* !YOUBIN */
 
 #ifdef XI18N
@@ -646,7 +673,7 @@
 	    fprintf(stderr, "		[-server host]\n");
 	    fprintf(stderr, "		[-nopreserve]\n");
 #endif
-#ifdef SUN_AUDIO
+#if (defined(SUN_AUDIO) || defined(BSD_AUDIO))
 	    fprintf(stderr, "		[-sndfile audio_file]\n");
 	    fprintf(stderr, "		[-volume percentage]\n");
 #endif
@@ -775,7 +802,7 @@
     /* Interval timer start	 */
 #ifndef YOUBIN
     polling_id = XtAppAddTimeOut(app_con,
-				 (unsigned long) polling_time, Polling, NULL);
+				 (unsigned long) polling_time, (XtTimerCallbackProc) Polling, NULL);
 #else  /* YOUBIN */
     if (server == NULL) {
 	gethostname(serv_name, sizeof(serv_name));
@@ -931,7 +958,7 @@
 		PopupMailHeader(mail_header);
 	    XSync(XtDisplay(toplevel), 0);
 	    if (bell == True)
-		beep(XtDisplay(toplevel), 0);
+		beep(XtDisplay(toplevel));
 	    /*	XBell(XtDisplay(toplevel), 0); */
 	}
 	else if (file_stat.st_size > mail_size) {
@@ -955,7 +982,8 @@
 		PopupMailHeader(mail_header);
 	    XSync(XtDisplay(toplevel), 0);
 	    if (bell == True)
-		XBell(XtDisplay(toplevel), 0);
+		beep(XtDisplay(toplevel));
+	    /*	XBell(XtDisplay(toplevel), 0); */
 	}
 	else {
 	    mail_size = file_stat.st_size;
@@ -982,7 +1010,7 @@
     /* No arrive */
 
     polling_id = XtAppAddTimeOut(XtWidgetToApplicationContext(toplevel),
-				 (unsigned long) polling_time, Polling, NULL);
+				 (unsigned long) polling_time, (XtTimerCallbackProc) Polling, NULL);
 
 }
 #endif /* !YOUBIN */
@@ -1071,7 +1099,7 @@
     if (popdown == True) {
 	popdown_button = XtCreateManagedWidget("popdown_button", commandWidgetClass, info_base, NULL,
 					       ZERO);
-	XtAddCallback(popdown_button, XtNcallback, BreakPopup, (XtPointer) NULL);
+	XtAddCallback(popdown_button, XtNcallback, (XtCallbackProc) BreakPopup, (XtPointer) NULL);
     }
     arg_count = 0;
     XtSetArg(args[arg_count], XtNlabel, head);
@@ -1147,7 +1175,8 @@
 		PopupMailHeader(mail_header);
 	    XSync(XtDisplay(toplevel), 0);
 	    if (bell == True)
-		XBell(XtDisplay(toplevel), 0);
+		beep(XtDisplay(toplevel));
+	    /*	XBell(XtDisplay(toplevel), 0); */
 	}
 	else {
 	    mail_size = file_stat.st_size;
@@ -1169,7 +1198,7 @@
 
     XtRemoveTimeOut(polling_id);
     polling_id = XtAppAddTimeOut(XtWidgetToApplicationContext(toplevel),
-				 (unsigned long) polling_time, Polling, NULL);
+				 (unsigned long) polling_time, (XtTimerCallbackProc) Polling, NULL);
 }
 #endif /* !YOUBIN */
 
@@ -1749,13 +1778,22 @@
 static void beep (display)
     Display *display; 
 {
-#ifdef SUN_AUDIO
+#if defined(SUN_AUDIO) || defined(BSD_AUDIO)
     int		audiofd, filefd;
-    int		rn, wn, len;
+    int		rn;
+#ifdef SUN_AUDIO
+    int		wn, len;
     unsigned char	buf[256];
     Audio_filehdr	*au_hdr;
     audio_info_t 	ais;
-
+#elif defined(BSD_AUDIO)
+    int mixerfd, mixerid, supported;
+    static int bsize;
+    static char *buf;
+    struct stat sbuf;
+    int level, level_tmp;
+#endif
+	
     if (mail_sndfile) {
 	audiofd = open( "/dev/audio", O_WRONLY | O_NDELAY ); 
 	if (audiofd < 0)
@@ -1766,6 +1804,7 @@
 		return;
 	    }
 
+#ifdef SUN_AUDIO
 	if( ioctl( audiofd, AUDIO_GETINFO, &ais ) )
 	    {
 		fprintf(stderr, "%s: Problem retrieving /dev/audio info.\n",
@@ -1782,6 +1821,24 @@
 	    return;
 	}
 
+#elif defined(BSD_AUDIO)
+	/* Open the mixer device */
+	mixerfd = open ("/dev/mixer", O_RDWR, 0);
+	if (mixerfd > 0)
+	    {
+		if (volume > MAX_SOUND_VOL)
+			volume = MAX_SOUND_VOL;
+		else if (volume < MIN_SOUND_VOL)
+			volume = MIN_SOUND_VOL;
+		mixerid = SOUND_MIXER_PCM;
+		    /* storing volume level */
+		ioctl(mixerfd,MIXER_READ(mixerid),&level_tmp);
+
+		level = (volume << 8) | volume;
+		ioctl(mixerfd,MIXER_WRITE(mixerid),&level);
+	}
+#endif
+
 	filefd = open(mail_sndfile, O_RDONLY);
 	if (filefd < 0)
 	    {
@@ -1791,6 +1848,7 @@
 		return;
 	    }
 
+#ifdef SUN_AUDIO
 	/* Read in the audio header */
 	rn = read(filefd, buf, sizeof(Audio_filehdr)); 
 
@@ -1841,12 +1899,28 @@
 		    usleep(1000);
 		}
 	    }
-	close(audiofd);
+#elif defined(BSD_AUDIO)
+	ioctl(audiofd, SNDCTL_DSP_RESET, 0);
+	fstat(filefd, &sbuf);
+	bsize = sbuf.st_size;
+	buf = malloc((u_int)bsize);
+	if ( (rn = read(filefd, buf, bsize)) > 0)
+	    write(audiofd, buf, rn);
+	ioctl(audiofd, SNDCTL_DSP_SYNC, 0);
+	free(buf);
+	if (mixerfd > 0)
+	    {
+		    /* restoring volume level */
+		ioctl(mixerfd,MIXER_WRITE(mixerid),&level_tmp);
+		close(mixerfd);
+	    }
+#endif
+	close(audiofd); 
 	close(filefd);
     }
     else
-    XBell (display, volume);
-#else  /* !SUN_AUDIO */
+    XBell (display, 0);
+#else  /* !SUN_AUDIO && !BSD_AUDIO */
     XBell (display, 0);
 #endif /* SUN_AUDIO */
     return;
@@ -1917,12 +1991,12 @@
 
 		if (popup_time)
 		    XtAppAddTimeOut(XtWidgetToApplicationContext(toplevel),
-				    (unsigned long) popup_time, BreakPopup, NULL);
+				    (unsigned long) popup_time, (XtTimerCallbackProc) BreakPopup, NULL);
 	    }
 	}
 	XSync(XtDisplay(toplevel), 0);
 	if (bell == True) {
-	    beep(XtDisplay(toplevel), 0);
+	    beep(XtDisplay(toplevel));
 	}
     } else if (mail_size < saved_mail_size){
 	/* No mail */
@@ -2031,7 +2105,7 @@
 	    }
 	    if (popup_time)
 		XtAppAddTimeOut(XtWidgetToApplicationContext(toplevel),
-				(unsigned long) popup_time, BreakPopup, NULL);
+				(unsigned long) popup_time, (XtTimerCallbackProc) BreakPopup, NULL);
 	}
 	if (raise == True) {
 	    XRaiseWindow(XtDisplay(toplevel), XtWindow(toplevel));
