summaryrefslogtreecommitdiff
path: root/audio/nosefart/patches/patch-ab
blob: 40f9e5b99d2bd7c12da4526096c2104ebe6c224a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
$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 <ctype.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -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);