$NetBSD: patch-ab,v 1.4 2007/09/29 11:35:11 rillig Exp $ --- src/linux/main_linux.c.orig Sat May 1 16:53:54 2004 +++ src/linux/main_linux.c Thu Dec 2 01:58:01 2004 @@ -3,6 +3,7 @@ UNIX systems */ #include +#include #include #include #include @@ -342,12 +343,59 @@ static void printsonginfo(int current_frame, int total_frames, int limited) { /*Why not printf directly? Our termios hijinks for input kills the output*/ + + /* + * Once again, the termios hijinks cause trouble for NetBSD. \r + * sometimes doesn't get printed. Following is a mostly complete + * rewrite of the text output section as presented in my NetBSD + * pkgsrc package for version 1.92i-mls. The fix was suggested by + * Bruce J.A. Nourish. I'm David Griffith. + */ + char *hi = (char *)malloc(255); char blank[82]; memset(blank, ' ', 80); blank[80] = '\r'; blank[81] = '\0'; + if (total_frames !=0) { + if (limited) { + snprintf(hi, 254, "\rPlaying track %d of %d, channels %c%c%c%c%c%c, %d/%d seconds, %d/%d frames\r", + nsf->current_song, nsf->num_songs, + enabled[0]?'1':'-', enabled[1]?'2':'-', + enabled[2]?'3':'-', enabled[3]?'4':'-', + enabled[4]?'5':'-', enabled[5]?'6':'-', + (int)((float)(current_frame + nsf->playback_rate - 1)/(float)nsf->playback_rate), + (int)((float)(total_frames + nsf->playback_rate - 1)/(float)nsf->playback_rate), + current_frame, + total_frames); + } else { + snprintf(hi, 254, "\rPlaying track %d of %d, channels %c%c%c%c%c%c, %d/? seconds, %d/? frames\r", + nsf->current_song, nsf->num_songs, + enabled[0]?'1':'-', enabled[1]?'2':'-', + enabled[2]?'3':'-', enabled[3]?'4':'-', + enabled[4]?'5':'-', enabled[5]?'6':'-', + (int)((float)(current_frame + nsf->playback_rate - 1)/(float)nsf->playback_rate), + current_frame); + } + } else { + snprintf(hi, 254, "\rPlaying track %d of %d, channels %c%c%c%c%c%c, %d seconds, %d frames\r", + nsf->current_song, nsf->num_songs, + enabled[0]?'1':'-', enabled[1]?'2':'-', + enabled[2]?'3':'-', enabled[3]?'4':'-', + enabled[4]?'5':'-', enabled[5]?'6':'-', + (int)((float)(current_frame + nsf->playback_rate - 1)/(float)nsf->playback_rate), + current_frame); + } + + +/* + * Not only does the following section do funny things to terminals, + * it's a good example of how to use the trinary operator to make your + * code very hard to understand. Please don't use the trinary operator + * when if-then-else will do. + */ +#ifdef __REALLY_BIG_COMMENT__ snprintf(hi, 254, total_frames != 0 ? "Playing track %d/%d, channels %c%c%c%c%c%c, %d/%d sec, %d/%d frames\r": @@ -363,9 +411,16 @@ current_frame, total_frames ); +#endif /* __REALLY_BIG_COMMENT__ */ + +/* + * I'm not sure what this is supposed to do. Under NetBSD it garbles + * the screen, but not to the degree as the above commented-out code. +/* if(!(current_frame%10)) write(STDOUT_FILENO, (void *)blank, strlen(blank)); +*/ write(STDOUT_FILENO, (void *)hi, strlen(hi)); free(hi);