summaryrefslogtreecommitdiff
blob: 0db48ceb407d5460c19c048347f545451abd1615 (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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
diff -uNr slurm-0.2.3/slurm.c slurm-0.2.3-theme/slurm.c
--- slurm-0.2.3/slurm.c	2003-04-27 19:11:55.000000000 +0300
+++ slurm-0.2.3-theme/slurm.c	2003-05-26 18:22:08.000000000 +0300
@@ -217,6 +217,10 @@
 #include "src/if_media.h"
 #include "src/if_media.c"
 
+/* theme support */
+#include "src/theme.h"
+#include "src/theme.c"
+
 #ifdef __HPUX__
 #include "src/hpux.h"
 #include "src/hpux.c"
@@ -673,7 +677,7 @@
             /* TX graph */
             if (tx_graph[x][y] == 1)
             {
-                chcolor(COLOR_YELLOW, colors.ingoing[1]);
+                chcolor(colors.outgoing[0], colors.outgoing[1]);
                 mvprintw(10+y, x+1, "x");
             }
             else
@@ -979,7 +983,7 @@
             /* TX graph */
             if (tx_graph[x][y] == 1)
             {
-                chcolor(COLOR_YELLOW, colors.ingoing[1]);
+                chcolor(colors.outgoing[0], colors.outgoing[1]);
                 mvprintw(6+y, x+1, "x");
             }
             else
@@ -1234,7 +1238,8 @@
                     "    -c            old classic/combined view\n"
                     "    -s            split window mode with stats\n"
                     "    -l            large split window mode\n"
-                    "    -i interface  select network interface\n\n",
+                    "    -i interface  select network interface\n"
+                    "    -t themefile  use colors from themefile\n\n",
 					REFRESH_MIN, REFRESH_MAX);
     _exit(code);
 }
@@ -1295,16 +1300,16 @@
     {
         mvprintw(20, 9, "Received Packets:");
         mvprintw(22, 6, "Errors on Receiving:");
-        mvprintw(20, 45,"Transmited Packets:");
+        mvprintw(20, 44,"Transmitted Packets:");
         switch(data_type)
         {
 			case TYPE_MEGA:
                 mvprintw(21,10, "MBytes Received:");
-                mvprintw(21,46, "MBytes Transmited:");
+                mvprintw(21,45, "MBytes Transmitted:");
                 break;
 			case TYPE_GIGA:
 				mvprintw(21,10, "GBytes Received:");
-                mvprintw(21,46, "GBytes Transmited:");
+                mvprintw(21,45, "GBytes Transmitted:");
                 break;
         }
     }
@@ -1385,30 +1390,21 @@
     unsigned short int first = 1;
     unsigned short int disconnected = 0;
 	char hostname[MAXHOSTNAMELEN+1];
+    char themefile[MAX_PATH_LEN+1];
 	long refreshdelay = REFRESH_DEFAULT;
 	float tmpdelay;
     int op;
 	int z_option = FALSE;
 	hostname[0] = '\0';
+    themefile[0] = '\0';
 
     /* HP-UX related as of now but could become standard */
     ifdata.if_valid = 0;
     ifdata.if_id = 0;
     ifdata.if_amount = 0;
 
-    colors.ingoing[0] = 2; colors.ingoing[1] = 1;
-    colors.outgoing[0] = 3; colors.outgoing[1] = 1;
-    colors.intersection[0] = 2; colors.intersection[1] = 1;
-    colors.background = 0;
-    colors.data[0] = 6; colors.data[1] = 1;
-    colors.border[0] = 7; colors.border[1] = 1;
-    colors.labels[0] = 7; colors.labels[1] = 1;
-    colors.power_led[0] = 2; colors.power_led[1] = 1;
-    colors.power_led[2] = 1; colors.power_led[3] = 1;
-    colors.version[0] = 7; colors.version[1] = 1;
-
     /* handle command line options */
-    while ((op = getopt(argc, argv, "Hhzd:clsi:")) != EOF)
+    while ((op = getopt(argc, argv, "Hhzd:clsi:t:")) != EOF)
     {
         switch (op)
         {
@@ -1462,12 +1458,17 @@
                 /* use default split window mode */
                 displaymode = MODE_SPLIT;
                 break;
+            case 't':
+                /* theme file to read */
+                strncpy(themefile, optarg, MAX_PATH_LEN);
+                themefile[MAX_PATH_LEN] = '\0';
+                break;
             default:
                 usage(1, argv);
                 break;
         }
     }
-
+    
     if (!validinterface)
     {
         fprintf(stderr, "specified device does not exist or cannot "
@@ -1476,6 +1477,9 @@
         usage(1, argv);
     }
 
+    /* read theme file or use defaults */
+    read_theme(themefile);
+
     /* Initialize some info variables */
     stats.tx_packets = 0; stats.tx_bytes = 0; stats.tx_errors = 0;
     stats.rx_packets = 0; stats.rx_bytes = 0; stats.rx_errors = 0;
diff -uNr slurm-0.2.3/src/theme.c slurm-0.2.3-theme/src/theme.c
--- slurm-0.2.3/src/theme.c	1970-01-01 02:00:00.000000000 +0200
+++ slurm-0.2.3-theme/src/theme.c	2003-05-26 18:21:54.000000000 +0300
@@ -0,0 +1,103 @@
+
+void read_theme(char *theme_file) {
+    FILE *theme_ptr;
+    char current_line[MAX_LINE_LEN];
+    char *iterator;
+
+    /* set defaults colors. structure colors defined in slurm.h */
+    colors.background =     DEFAULT_BACKGROUND;
+    colors.ingoing[0] =     DEFAULT_INGOING_COLOR;
+    colors.ingoing[1] =     DEFAULT_INGOING_BOLD;
+    colors.outgoing[0] =    DEFAULT_OUTGOING_COLOR;
+    colors.outgoing[1] =    DEFAULT_OUTGOING_BOLD;
+    colors.intersection[0] =    DEFAULT_INTERSECTION_COLOR;
+    colors.intersection[1] =    DEFAULT_INTERSECTION_BOLD;
+    colors.data[0] =        DEFAULT_DATA_COLOR;
+    colors.data[1] =        DEFAULT_DATA_BOLD;
+    colors.border[0] =      DEFAULT_BORDER_COLOR;
+    colors.border[1] =      DEFAULT_BORDER_BOLD;
+    colors.labels[0] =      DEFAULT_LABELS_COLOR;
+    colors.labels[1] =      DEFAULT_LABELS_BOLD;
+    colors.power_led[0] =   DEFAULT_POWER_LED_1_COLOR;
+    colors.power_led[1] =   DEFAULT_POWER_LED_1_BOLD;
+    colors.power_led[2] =   DEFAULT_POWER_LED_2_COLOR;
+    colors.power_led[3] =   DEFAULT_POWER_LED_2_BOLD;
+    colors.version[0] =     DEFAULT_VERSION_COLOR;
+    colors.version[1] =     DEFAULT_VERSION_BOLD;
+
+    /* no theme file given, just setting the defaults */
+    if(strlen(theme_file) == 0)
+        return;
+
+    /* try to open the file */
+    if((theme_ptr = fopen(theme_file, "r")) == NULL) {
+        perror("can't open theme file");
+        exit(EXIT_FAILURE);
+    }
+
+    /* read every line of config file */
+    while((fgets(current_line, MAX_LINE_LEN, theme_ptr)) != NULL) {
+        iterator = current_line;
+
+        /* skip whitespace */
+        while(*iterator == ' ' || *iterator == '\t')
+            iterator++;
+        
+        /* skip comments and empty lines */
+        if(*iterator == '#' || *iterator == '\n' || iterator == NULL)
+            continue;
+            
+        /* search for settings */
+        search_value(iterator, "background",    &colors.background);
+
+        search_value(iterator, "data_color",    &colors.data[0]);
+        search_value(iterator, "data_bold",     &colors.data[1]);
+
+        search_value(iterator, "ingoing_color", &colors.ingoing[0]);
+        search_value(iterator, "ingoing_bold",  &colors.ingoing[1]);
+        search_value(iterator, "outgoing_color",    &colors.outgoing[0]);
+        search_value(iterator, "outgoing_bold",     &colors.outgoing[1]);
+        search_value(iterator, "intersection_color",  &colors.intersection[0]);
+        search_value(iterator, "intersection_bold",   &colors.intersection[1]);
+
+        search_value(iterator, "power_led_1_color", &colors.power_led[0]);
+        search_value(iterator, "power_led_1_bold",  &colors.power_led[1]);
+        search_value(iterator, "power_led_2_color", &colors.power_led[2]);
+        search_value(iterator, "power_led_2_bold",  &colors.power_led[3]);
+
+        search_value(iterator, "version_color", &colors.version[0]);
+        search_value(iterator, "version_bold",  &colors.version[1]);
+        search_value(iterator, "labels_color",  &colors.labels[0]);
+        search_value(iterator, "labels_bold",   &colors.labels[1]);
+        search_value(iterator, "border_color",  &colors.border[0]);
+        search_value(iterator, "border_bold",   &colors.border[1]);
+    
+    }
+
+    /* close file */
+    fclose(theme_ptr);
+}
+
+void search_value(char *line, char *setting, int *dest) {
+    char *tmp;
+    
+    tmp = line;
+    
+    /* check for setting */
+    if(strstr(line, setting) == NULL)
+        return;
+
+    /* read variable name */
+    while(*tmp != ' ' && *tmp != '\t' && *tmp != '\n' && *tmp != '\0')
+        tmp++;
+
+    /* read whitespace */
+    while(*tmp == ' ' || *tmp == '\t')
+        tmp++;
+    
+    /* set value */
+    *dest = atoi(tmp);
+    
+    return;
+}
+
diff -uNr slurm-0.2.3/src/theme.h slurm-0.2.3-theme/src/theme.h
--- slurm-0.2.3/src/theme.h	1970-01-01 02:00:00.000000000 +0200
+++ slurm-0.2.3-theme/src/theme.h	2003-05-26 18:21:54.000000000 +0300
@@ -0,0 +1,28 @@
+
+/* default colors and bolding settings */
+#define DEFAULT_BACKGROUND          0
+#define DEFAULT_INGOING_COLOR       2
+#define DEFAULT_INGOING_BOLD        1
+#define DEFAULT_OUTGOING_COLOR      3
+#define DEFAULT_OUTGOING_BOLD       1
+#define DEFAULT_INTERSECTION_COLOR  2
+#define DEFAULT_INTERSECTION_BOLD   1
+#define DEFAULT_DATA_COLOR          6
+#define DEFAULT_DATA_BOLD           1
+#define DEFAULT_BORDER_COLOR        7
+#define DEFAULT_BORDER_BOLD         1
+#define DEFAULT_LABELS_COLOR        7
+#define DEFAULT_LABELS_BOLD         1
+#define DEFAULT_POWER_LED_1_COLOR   2
+#define DEFAULT_POWER_LED_1_BOLD    1
+#define DEFAULT_POWER_LED_2_COLOR   1
+#define DEFAULT_POWER_LED_2_BOLD    1
+#define DEFAULT_VERSION_COLOR       7
+#define DEFAULT_VERSION_BOLD        1
+
+#define MAX_PATH_LEN    256
+#define MAX_LINE_LEN    256
+
+void read_theme(char *theme_file);
+void search_value(char *line, char *setting, int *dest);
+
diff -uNr slurm-0.2.3/theme.sample slurm-0.2.3-theme/theme.sample
--- slurm-0.2.3/theme.sample	1970-01-01 02:00:00.000000000 +0200
+++ slurm-0.2.3-theme/theme.sample	2003-05-26 17:59:13.000000000 +0300
@@ -0,0 +1,20 @@
+# colors: -1 default, 0 black, 1 red, 2 green, 3 yellow, 4 blue, 5 magenta,
+#          6 cyan, 7 white
+# bold: 0 off, 1 on (default)
+
+background      0
+data_color      1
+labels_color    7
+border_color    7
+version_color   7
+
+outgoing_color     -1
+outgoing_bold       0
+ingoing_color       7
+# intersection_color not used
+#intersection_color  7
+
+power_led_1_color   2
+power_led_2_color   1
+
+# eof