summaryrefslogtreecommitdiff
path: root/net/wmnet/files/patch-main.c
blob: 4634d148a59138d8bca6960a515777f18c01cf6c (plain) (blame)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
--- main.c.orig	Sat Jun  5 15:28:39 2004
+++ main.c	Sat Jun  5 15:28:46 2004
@@ -32,11 +32,11 @@
 #define LED_SZE_Y (4)
 
 #define LED_ON_NET_X (87)
-#define LED_ON_NET_Y (66)
+#define LED_ON_NET_Y (92)
 #define LED_OFF_NET_X (93)
-#define LED_OFF_NET_Y (66)
+#define LED_OFF_NET_Y (92)
 #define LED_ERR_NET_X (81)
-#define LED_ERR_NET_Y (66)
+#define LED_ERR_NET_Y (92)
 
 #define LED_PWR_X (53)
 #define LED_PWR_Y (7)
@@ -52,6 +52,7 @@
 static unsigned findInterface(char const*);
 static void printversion(void);
 static char const *rateToStr(unsigned long);
+static double getRate(unsigned long, char *);
 static void SetErrLED(int);
 static void SetOffLED(int);
 static void SetOnLED(int);
@@ -68,7 +69,7 @@
 ------------------------------------------------------------------------------*/
 static void DrawActiveIFS(char const* name)
 {
-    copyXPMArea(5, 84, 30, 10, 5, 5);
+    copyXPMArea(5, 110, 30, 10, 5, 5);
 
 	if (name) {
 		int ii, kk = 5;
@@ -77,9 +78,9 @@
 			int const ch = toupper(name[ii]);
 
 			if (ch >= 'A' && ch <= 'Z')
-				copyXPMArea((ch - 'A') * 6, 74, 6, 9, kk, 5);
+				copyXPMArea((ch - 'A') * 6, 100, 6, 9, kk, 5);
 			else
-				copyXPMArea((ch - '0') * 6, 64, 6, 9, kk, 5);
+				copyXPMArea((ch - '0') * 6, 90, 6, 9, kk, 5);
 			kk += 6;
 		}
 	}
@@ -91,25 +92,22 @@
 static void DrawStats(unsigned ifCurr, int height, int x_left, int y_bottom)
 {
     unsigned baseLine = y_bottom - height / 2;
-    unsigned maxVal = 0, ii;
+    unsigned maxVal = 0, ii, currVal = 0;
     char const* ptr = 0;
 
     /* Find the maximum value. We'll scale the graph to this value. */
+	unsigned long rcv, xmt;
 
 	for (ii = 0; ii < G_WIDTH; ++ii) {
-		unsigned long rcv, xmt;
 
 		ifGetData(ifCurr, ii, &xmt, &rcv);
 
 		xmt /= delay;
 		rcv /= delay;
-
-		if (rcv > maxVal)
-			maxVal = rcv;
-		if (xmt > maxVal)
-			maxVal = xmt;
+		currVal = xmt > rcv ? xmt : rcv ;
+		if (currVal > maxVal)
+			maxVal = currVal;
     }
-    ptr = rateToStr(maxVal);
 
     /* Now draw the data points. */
 
@@ -127,27 +125,58 @@
 		}
 		for (jj = 0; jj < height; ++jj)
 			if (y_bottom - jj <= start && y_bottom - jj >= stop)
-				copyXPMArea(100 + 1, 68, 1, 1, ii + x_left, y_bottom - jj);
+				copyXPMArea(99 + 1, 106, 1, 1, ii + x_left, y_bottom - jj);
 			else
-				copyXPMArea(100, 68, 1, 1, ii + x_left, y_bottom - jj);
+				copyXPMArea(99, 106, 1, 1, ii + x_left, y_bottom - jj);
 
 		/* Draw the base line. */
 
-		copyXPMArea(100 + 3, 68, 1, 1, ii + x_left, baseLine);
+		copyXPMArea(100, 106, 1, 1, ii + x_left, baseLine);
 	}
 
-    /* Now draw the data rate... */
+    /* Now draw the download data rate... */
+	
+	/* Clear area */
+	copyXPMArea( 6, 111, 54 , 9 , 6, 63);
+
+	ptr = rateToStr(rcv);
+	copyXPMArea(('D' - 'A') * 6, 100, 6, 9, 6,
+				62);
+	copyXPMArea(64, 90, 4, 9, 12,
+				62);
+	for (ii = 20; *ptr; ++ptr)
+		if (isdigit(*ptr)) {
+			copyXPMArea((*ptr - '0') * 6, 90, 6, 9, 1 + ii, 62 );
+			ii += 6;
+		} else if ('.' == *ptr) {
+			copyXPMArea(60, 90, 4, 9, 1 + ii, 62);
+			ii += 4;
+		} else {
+			copyXPMArea((toupper(*ptr) - 'A') * 6, 100, 6, 9, 1 + ii,
+						62);
+			ii += 6;
+		}
+    
+	/* Now draw the upload data rate... */
+	
+	/* Clear area */
+	copyXPMArea( 6, 111, 54 , 9 , 6, 76);
 
-	for (ii = 5; *ptr; ++ptr)
+	ptr = rateToStr(xmt);
+	copyXPMArea(('U' - 'A') * 6, 100, 6, 9, 6,
+				75);
+	copyXPMArea(64, 90, 4, 9, 12,
+				75);
+	for (ii = 20; *ptr; ++ptr)
 		if (isdigit(*ptr)) {
-			copyXPMArea((*ptr - '0') * 6, 64, 6, 9, 1 + ii, y_bottom - 10);
+			copyXPMArea((*ptr - '0') * 6, 90, 6, 9, 1 + ii, 75 );
 			ii += 6;
 		} else if ('.' == *ptr) {
-			copyXPMArea(60, 64, 4, 9, 1 + ii, y_bottom - 10);
+			copyXPMArea(60, 90, 4, 9, 1 + ii, 75);
 			ii += 4;
 		} else {
-			copyXPMArea((toupper(*ptr) - 'A') * 6, 74, 6, 9, 1 + ii,
-						y_bottom - 10);
+			copyXPMArea((toupper(*ptr) - 'A') * 6, 100, 6, 9, 1 + ii,
+						75);
 			ii += 6;
 		}
 
@@ -205,41 +234,39 @@
 ------------------------------------------------------------------------------*/
 static char const* rateToStr(unsigned long rate)
 {
-	static char buffer[7];
-	char scaleFactor, *ptr = buffer;
+	static char buffer[14];
+	char scaleFactor='\0', *ptr = buffer;
 
-	/* Based upon its magnitude, determine how much 'rate' needs to be
-	   scaled and also indicate its unit of scale. */
-
-	if (rate > 1000000) {
-		rate /= 100000;
-		scaleFactor = 'M';
-	} else if (rate > 1000) {
-		rate /= 100;
-		scaleFactor = 'K';
-	} else {
-		rate *= 10;
-		scaleFactor = '\0';
-	}
+	double drate = getRate(rate,&scaleFactor);
 
-	/* Transform the value into a left - justified string. */
-
-	if (rate >= 1000)
-		*ptr++ = rate / 1000 + '0';
-	if (rate >= 100)
-		*ptr++ = (rate / 100) % 10 + '0';
-	if (rate >= 10)
-		*ptr++ = (rate / 10) % 10 + '0';
-	if (scaleFactor) {
-		*ptr++ = '.';
-		*ptr++ = rate % 10 + '0';
-	}
+	/* Transform the rate value into a left - justified string. */
+	ptr+=sprintf(ptr,"%.1f",drate);
 	*ptr++ = scaleFactor;
 	*ptr = '\0';
 	return buffer;
 }
 
 /*------------------------------------------------------------------------------
+  getRate
+------------------------------------------------------------------------------*/
+static double getRate(unsigned long rate, char *scaleFactor)
+{
+	 double drate = rate;
+
+	/* Based upon its magnitude, determine how much 'rate' needs to be
+	   scaled and also indicate its unit of scale. */
+
+	if (rate > 1048576) {
+		drate /= 1048576;
+		*scaleFactor = 'M';
+	} else if (rate > 1024) {
+		drate /= 1024;
+		*scaleFactor = 'K';
+	}
+	return drate;
+}
+
+/*------------------------------------------------------------------------------
   SetErrLED
 ------------------------------------------------------------------------------*/
 static void SetErrLED(int led)
@@ -314,10 +341,11 @@
 {
     static char const txt[] =
 		"\nwmnet, v1p2 - A network interface monitor for WindowMaker.\n\n"
-		"\t-h         this help screen\n"
-		"\t-i name    start with interface 'name'\n"
-		"\t-u delay   seconds between samples (defaults to 1)\n"
-		"\t-v         print the version number\n";
+		"\t-h               this help screen\n"
+		"\t-i name          start with interface 'name'\n"
+		"\t-u delay         seconds between samples (defaults to 1)\n"
+		"\t-geom <geometry> geometry to use\n"
+		"\t-v               print the version number\n";
 
     fputs(txt, stderr);
 }
@@ -425,6 +453,13 @@
 			case 'v':
 				printversion();
 				return 0;
+			
+			case 'g':
+				if (ii + 1 == argc) {
+					printf("wmnet: must specify geometry\n");
+					return 0;
+				}
+				break;
 
 			default:
 				usage();