Subject: Re: .nsf audio file player
To: None <tech-pkg@NetBSD.org>
From: Bruce J.A. Nourish <bjan+tech-pkg@bjan.net>
List: tech-pkg
Date: 10/21/2003 11:42:56
On Tue, Oct 21, 2003 at 10:31:31AM -0700, Dave wrote:
>  One problem: as
> it's playing a file, it spews text in a rather messy way that I'm sure
> isn't the way it should be under Linux, but I have no way to test this.

You are referring to the way it sometimes continues the status display
half way on a line, screwing everything up? (I think there is also a
problem relating to $d in the format string, but I'm not immediately
sure what to do about that).

Looking at the ktrace output, you'll see occasional "short writes" on
standard output. Write cannot flush the whole string, so the CR at the
end never gets printed. (Presumably Linux and FreeBSD have bigger I/O
buffers, or somehow manage to get tty writes out the door faster than
we can.)

The simplest solution is to put the CR at the beginning of the string:

--- main_linux.c.bruce	2003-10-21 11:19:37.000000000 -0700
+++ main_linux.c	2003-10-21 11:20:03.000000000 -0700
@@ -238,10 +238,10 @@
 
    snprintf(hi, 254, 
    total_frames != 0 ? 
-   "Playing track %d of %d, channels %c%c%c%c%c%c, %d/%d seconds, %d/%d frames\r":
+   "\rPlaying track %d of %d, channels %c%c%c%c%c%c, %d/%d seconds, %d/%d frames":
    (limited ?
-   "Playing track %d of %d, channels %c%c%c%c%c%c, %d/? seconds, %11$d/? frames\r":
-   "Playing track %d of %d, channels %c%c%c%c%c%c, %d seconds, %11$d frames\r"), 
+   "\rPlaying track %d of %d, channels %c%c%c%c%c%c, %d/? seconds, %11$d/? frames":
+   "\rPlaying track %d of %d, channels %c%c%c%c%c%c, %d seconds, %11$d frames"), 
    nsf->current_song, nsf->num_songs, 
    enabled[0]?'1':'-',      enabled[1]?'2':'-',
    enabled[2]?'3':'-',      enabled[3]?'4':'-',

-- 
Bruce J.A. Nourish <bjan+public@bjan.net> http://bjan.net