asmon: Remove set but unused variables.
[dockapps.git] / asmon / asmon / asmon.c
blobaba65a59680d8e645c67019d13036e1c072f285f
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <time.h>
4 #include <string.h>
5 #include <fcntl.h>
6 #include <unistd.h>
7 #include <ctype.h>
8 #include <sys/utsname.h>
10 #include <sys/wait.h>
11 #include <sys/param.h>
12 #include <sys/types.h>
14 #include <X11/Xlib.h>
15 #include <X11/xpm.h>
16 #include <X11/extensions/shape.h>
18 #include <libdockapp/wmgeneral.h>
19 #include <libdockapp/misc.h>
21 #include "asmon-master.xpm"
22 #include "asmon-mask.xbm"
24 #ifdef __solaris__
25 #include <utmp.h>
26 #endif
28 #define EXEC_ON_CLICK 1
29 #define ASMON_VERSION "0.71"
30 #define CHAR_WIDTH 5
31 #define CHAR_HEIGHT 7
33 #define BCHAR_WIDTH 6
34 #define BCHAR_HEIGHT 9
36 #define BOFFX (9)
37 #define BOFFY (111)
38 #define BREDX (3)
39 #define BREDY (111)
40 #define BGREENX (87)
41 #define BGREENY (66)
43 #define LITEW (4)
44 #define LITEH (4)
46 #define B_OFF (0)
47 #define B_RED (1)
48 #define B_GREEN (2)
51 /* Evil globals I haven't removed yet */
52 long last_pageins=0, last_pageouts=0;
53 long last_swapins=0, last_swapouts=0;
54 //double old;
55 static int has_kern26 = 0;
57 #ifdef EXEC_ON_CLICK
58 char Command[256]="";
59 #endif
61 /* functions */
62 void DrawUptime(void);
63 void usage(void);
64 void printversion(void);
65 void asmon_routine(int Xpid, int allmem);
66 void DrawLite(int state, int dx, int dy);
67 void DrawCPU(void);
68 void DrawLoad(void);
69 #ifdef __solaris__
70 float DrawMemSwap(void);
71 extern int getLoad(float *);
72 extern int getSwap(unsigned long *, unsigned long *);
73 extern int getMem(unsigned long *, unsigned long *);
74 extern int getCPU(unsigned long *, unsigned long *,
75 unsigned long *, unsigned long *,
76 unsigned long *, unsigned long *,
77 unsigned long *, unsigned long *);
78 #else
79 void DrawXmem(int Xpid, float total);
80 float DrawMemSwap(float total, int allmem);
81 #endif
83 int main(int argc, char *argv[])
85 FILE *fp;
86 int i;
87 int allmem=1;
88 int Xpid=1;
89 char *ProgName;
90 struct utsname name;
91 int kernMajor, kernMinor, kernRev;
93 ProgName = argv[0];
95 if (strlen(ProgName) >= 5)
96 ProgName += (strlen(ProgName) - 5);
98 for (i=1; i<argc; i++) {
99 char *arg = argv[i];
100 if (*arg=='-') {
101 switch (arg[1]) {
102 case 'd' :
103 if (strcmp(arg+1, "display")) {
104 usage();
105 exit(1);
107 break;
108 #ifdef EXEC_ON_CLICK
109 case 'e' :
110 if ( argv[++i] ) {
111 strncpy( Command, argv[i], 253);
112 strcat( Command, " &");
113 } else {
114 usage();
115 exit(0);
117 break;
118 #endif
119 case 'v' :
120 printversion();
121 exit(0);
122 break;
123 case 'u' :
124 #ifdef __solaris__
125 fprintf(stderr, "X Server memory stats unavailable for Solaris.\n");
126 exit(0);
127 #endif
128 Xpid=0;
129 break;
130 default:
131 usage();
132 exit(0);
133 break;
137 #ifndef __solaris__
138 if ( Xpid != 0) {
139 if ( (fp = fopen("/var/run/server.0.pid", "r")) != NULL)
141 fscanf(fp, " %d", &Xpid);
142 fclose(fp);
143 } else {
144 if ( (fp = fopen("/tmp/.X0-lock", "r")) != NULL)
146 fscanf(fp, " %d", &Xpid);
147 fclose(fp);
148 } else {
149 Xpid=0;
153 #endif
154 /* Open 64x64 window */
155 openXwindow(argc, argv, asmon_master_xpm, asmon_mask_bits, asmon_mask_width, asmon_mask_height);
157 if( uname( &name ) != -1 )
159 if( strcmp( name.sysname, "Linux" ) == 0 )
161 sscanf(name.release, "%d.%d.%d", &kernMajor, &kernMinor,
162 &kernRev);
163 if(( kernMajor == 2 ) && ( kernMinor == 6 ))
164 has_kern26 = 1;
167 else
169 fprintf(stderr, "Can't find system name\n");
170 exit(1);
173 asmon_routine(Xpid, allmem);
174 return(0);
177 /**************************************************************************/
179 void usage(void) {
180 fprintf(stderr, "\nasmon %s - by Brad Hall (bkh@rio.vg)\n\t\toriginally based on Timecop's wmcpu\n\n", ASMON_VERSION);
181 fprintf(stderr, "The top bar: left is the CPU usage, right is the load average\n");
182 fprintf(stderr, "The middle bar: left memory usage devided by ticks into shared, buffers, and\n\t\t cached, respectively, and the number of megs used\n");
183 fprintf(stderr, "The lower bar: the left swap usage and the number of megs swappedd avg\n");
184 fprintf(stderr, "The bottom: the left is a set of LED's marking page's and swap's, the right is\n\t\t a bar representing the amount of memory that the X server \n\t\t is taking up, and the exact megs\n\n usage:\n");
185 fprintf(stderr, "\t-display <display name>\n");
186 fprintf(stderr, "\t-h\tthis screen\n");
187 fprintf(stderr, "\t-v\tprint the version number\n");
188 #ifndef __solaris__
189 fprintf(stderr, "\t-u\tforce asmon to show uptime, rather than X mem use\n");
190 #endif
191 #ifdef EXEC_ON_CLICK
192 fprintf(stderr, "\t-e cmd\texecute 'cmd' on mouse click\n");
193 #endif
194 fprintf(stderr, "\n");
197 /**************************************************************************/
199 void printversion(void)
201 fprintf(stderr, "asmon %s\n", ASMON_VERSION);
204 /**************************************************************************/
206 void asmon_routine(int Xpid, int allmem)
208 int xpm_X=0, xpm_Y=0, count=0;
209 XEvent Event;
210 float total=0.0;
212 while(1)
214 DrawCPU();
215 DrawLoad();
217 /* Only run every 15 iterations */
218 if ( count == 0 || count == 15)
219 #ifdef __solaris__
220 total=DrawMemSwap();
221 #else
222 total=DrawMemSwap(total, allmem);
223 #endif
225 #ifdef __solaris__
226 DrawUptime();
227 #else
228 /* X mem or Uptime? */
229 if (Xpid == 0)
231 DrawUptime();
232 } else {
233 if (count == 5)
234 DrawXmem(Xpid, total);
236 #endif
238 /* Redraw Windows */
239 RedrawWindowXY(xpm_X, xpm_Y);
240 while (XPending(display))
242 XNextEvent(display, &Event);
243 switch (Event.type)
245 #ifdef EXEC_ON_CLICK
246 case ButtonPress:
247 #if 0
248 fprintf(stderr,"system(%s)\n",Command);
249 #endif
250 if (Command[ 0 ]) system(Command);
251 break;
252 #endif
253 case Expose:
254 RedrawWindowXY(xpm_X, xpm_Y);
255 break;
256 case DestroyNotify:
257 XCloseDisplay(display);
258 exit(0);
259 break;
262 count++;
263 if (count > 30)
264 count = 0;
265 usleep(150000);
270 /**************************************************************************/
272 #ifdef __solaris__
274 /* CPU Usage Meter */
275 void DrawCPU
277 void
280 unsigned long cpuIdle, cpuUser, cpuKern, cpuWait;
281 unsigned long pageIn, pageOut, swapIn, swapOut;
283 /* remember the statistics read last time */
284 static float cpustat[4] = {0.0, 0.0, 0.0, 0.0};
285 float fields[4] = {0.0, 0.0, 0.0, 0.0};
286 float cputotal = 0.0;
288 getCPU(&cpuIdle, &cpuUser, &cpuKern, &cpuWait,
289 &pageIn, &pageOut, &swapIn, &swapOut);
291 // Calculate CPU stuff
292 fields[0] = ((float)cpuIdle - cpustat[0]);
293 cpustat[0] = (float)cpuIdle;
294 cputotal += fields[0];
296 fields[1] = ((float)cpuUser - cpustat[1]);
297 cpustat[1] = (float)cpuUser;
298 cputotal += fields[1];
300 fields[2] = ((float)cpuKern - cpustat[2]);
301 cpustat[2] = (float)cpuKern;
302 cputotal += fields[2];
304 fields[3] = ((float)cpuWait - cpustat[3]);
305 cpustat[3] = (float)cpuWait;
306 cputotal += fields[3];
308 // CPU Bar
309 if(cputotal > 0)
311 cputotal = ((cputotal - (fields[0] + fields[2])) * 1.55);
312 if (cputotal > 26) cputotal = 26;
313 copyXPMArea(3, 84, cputotal, 9, 5, 5);
314 copyXPMArea(15, 105, (27 - cputotal), 9, (5 + cputotal), 5);
315 copyXPMArea(16, 46, 2, 14, 32, 2);
318 // Page In/Out
319 if (pageIn > last_pageins) DrawLite(B_RED, 5, 48);
320 else DrawLite(B_OFF, 5, 48);
322 if (pageOut > last_pageouts) DrawLite(B_RED, 10, 48);
323 else DrawLite(B_OFF, 10, 48);
325 last_pageins = pageIn;
326 last_pageouts = pageOut;
328 // Swap In/Out
329 if (swapIn > last_swapins) DrawLite(B_RED, 5, 53);
330 else DrawLite(B_OFF, 5, 53);
332 if (swapOut > last_swapouts) DrawLite(B_RED, 10, 53);
333 else DrawLite(B_OFF, 10, 53);
335 last_swapins = swapIn;
336 last_swapouts = swapOut;
339 #else
341 /* CPU Usage Meter */
342 void DrawCPU(void)
344 FILE *fp;
345 static double cpustat[7]; /* remember the statistics read last time */
346 //double fields[7], info[7], cputotal=0.0,idlee=0.0;
347 double fields[7], info[7], cputotal=0.0;
348 long pageins=0, pageouts=0, swapins=0, swapouts=0 ;
349 char buf[128];
350 int i;
352 if( (fp = fopen("/proc/stat", "r")) != NULL)
354 if( has_kern26 > 0 )
356 // CPU data
357 fscanf(fp, "cpu %lf %lf %lf %lf %lf %lf %lf", info, info+1,
358 info+2, info+3, info+4, info+5, info+6);
360 fclose(fp);
362 if( (fp = fopen("/proc/vmstat", "r")) != NULL)
364 // gather data for LED's
365 while( fgets(buf, 127, fp) )
367 if (strstr(buf, "pgpgin"))
368 sscanf(buf, "pgpgin %ld", &pageins);
370 if (strstr(buf, "pgpgout"))
371 sscanf(buf, "pgpgout %ld", &pageouts);
373 if (strstr(buf, "pswpin"))
374 sscanf(buf, "pswpin %ld", &swapins);
376 if (strstr(buf, "pswpout"))
377 sscanf(buf, "pswpout %ld", &swapouts);
379 fclose(fp);
381 } else {
382 // CPU data
383 fscanf(fp, "cpu %lf %lf %lf %lf", info, info+1, info+2,
384 info+3);
386 // gather data for LED's
387 while( fgets(buf, 127, fp) )
389 if (strstr(buf, "page"))
390 sscanf(buf, "page %ld %ld", &pageins, &pageouts);
392 if (strstr(buf, "swap"))
393 sscanf(buf, "swap %ld %ld", &swapins, &swapouts);
395 fclose(fp);
398 // Calculate CPU stuff
399 if( has_kern26 > 0 )
401 for(i = 0; i < 7; i++)
403 fields[i] = info[i] - cpustat[i];
404 cputotal += fields[i];
405 cpustat[i] = info[i];
407 } else {
408 for(i = 0; i < 4; i++)
410 fields[i] = info[i] - cpustat[i];
411 cputotal += fields[i];
412 cpustat[i] = info[i];
415 //idlee=info[3]-old;
417 //old=info[3];
419 // CPU Bar
421 //cputotal = 100 * l1 ;
422 //cputotal=(100-(idlee*100/16))*26/100;
423 if(cputotal > 0)
425 cputotal = (cputotal-(fields[3]+fields[4]))*1.55;
426 if ( cputotal > 26 ) cputotal = 26;
427 copyXPMArea(3,84,cputotal,9,5,5);
428 copyXPMArea(15,105,(27-cputotal),9,(5+cputotal),5);
429 copyXPMArea(16,46,2,14,32,2);
432 // Page In/Out
433 if (pageins > last_pageins)
435 DrawLite(B_RED, 5, 48);
436 } else {
437 DrawLite(B_OFF, 5, 48);
440 if (pageouts > last_pageouts)
442 DrawLite(B_RED, 10, 48);
443 } else {
444 DrawLite(B_OFF, 10, 48);
446 last_pageins = pageins;
447 last_pageouts = pageouts;
449 // Swap In/Out
450 if (swapins > last_swapins)
452 DrawLite(B_RED, 5, 53);
453 } else {
454 DrawLite(B_OFF, 5, 53);
457 if (swapouts > last_swapouts)
459 DrawLite(B_RED, 10, 53);
460 } else {
461 DrawLite(B_OFF, 10, 53);
463 last_swapins = swapins;
464 last_swapouts = swapouts;
468 #endif
470 /**************************************************************************/
472 /* Load Average */
473 void DrawLoad(void)
475 int tempy, tempa;
476 static float oldv = -1.0;
477 float ftmp;
479 #ifdef __solaris__
480 if (getLoad(&ftmp) != -1)
482 #else
483 FILE *fp;
484 if( (fp = fopen("/proc/loadavg", "r")) != NULL)
486 fscanf(fp, "%f", &ftmp);
487 fclose(fp);
488 #endif
489 if(oldv != ftmp)
491 oldv = ftmp;
492 tempa=(ftmp+0.005)*100;
493 tempy=tempa%10;
494 copyXPMArea(3+(tempy*6),66,6,9,50,5);
495 tempy=tempa/10;
496 tempy=tempy%10;
497 copyXPMArea(3+(tempy*6),66,6,9,44,5);
498 copyXPMArea(65,66,3,9,41,5);
499 tempy=tempa/100;
500 if ( tempy > 9 )
502 tempy=(tempy-10);
503 copyXPMArea(3+(tempy*6),95,6,9,34,5);
504 } else {
505 copyXPMArea(3+(tempy*6),66,6,9,34,5);
511 /**************************************************************************/
513 #ifdef __solaris__
515 /* Mem/Swap Meter */
516 float DrawMemSwap
518 void
521 unsigned long memMax, memFree, swapMax, swapFree;
522 unsigned long MEMmem, MEMswap;
523 float memUsed, swapUsed;
524 int tempy, tempa;
526 getMem(&memMax, &memFree);
527 memUsed = (float)(memMax - memFree);
529 getSwap(&swapMax, &swapFree);
530 swapUsed = (float)(swapMax - swapFree);
532 /* MEM Meter */
533 if (memMax == 0)
534 MEMmem = 0;
535 else
537 if (((float)memMax / 1048576) >= 1)
538 MEMmem = ((memUsed * 31) / (float)memMax);
539 else
540 MEMmem = ((memUsed * 36) / (float)memMax);
543 // refresh
544 copyXPMArea(4, 115, 55, 11, 4, 18);
546 // Bar
547 copyXPMArea(3, 75, MEMmem, 9, 5, 19);
548 copyXPMArea(15, 105, (36 - MEMmem), 9, (5 + MEMmem), 19);
549 // Numbers
550 tempa = (memUsed / 1048576);
551 tempy = (tempa % 10);
552 copyXPMArea((3 + (tempy * 6)), 66, 6, 9, 50, 19);
553 tempy = ((tempa / 10) % 10);
554 copyXPMArea((3 + (tempy * 6)), 66, 6, 9, 44, 19);
555 tempy = ((tempa / 100) % 10);
556 if (tempy != 0)
558 copyXPMArea((3 + (tempy * 6)), 66, 6, 9, 38, 19);
559 copyXPMArea(16, 46, 2, 14, 35, 16);
561 else
563 copyXPMArea(16, 46, 2, 14, 41, 16);
566 // refresh
567 copyXPMArea(4, 115, 55, 11, 4, 32);
569 /* SWAP Meter */
570 if (swapMax == 0)
571 MEMswap = 0;
572 else
574 if (((float)swapMax / 1048576) >= 1)
575 MEMswap = ((swapUsed * 31) / (float)swapMax);
576 else
577 MEMswap = ((swapUsed * 36) / (float)swapMax);
579 // Bar
580 copyXPMArea(3, 75, MEMswap, 9, 5, 33);
581 copyXPMArea(15, 105, (36 - MEMswap), 9, (5 + MEMswap), 33);
582 // Numbers
583 tempa = (swapUsed / 1048576);
584 tempy = (tempa % 10);
585 copyXPMArea((3 + (tempy * 6)), 66, 6, 9, 50, 33);
586 tempy = ((tempa / 10) % 10);
587 copyXPMArea((3 + (tempy * 6)), 66, 6, 9, 44, 33);
588 tempy = ((tempa / 100) % 10);
589 if (tempy != 0)
591 copyXPMArea((3 + (tempy * 6)), 66, 6, 9, 38, 33);
592 copyXPMArea(16, 46, 2, 14, 42, 16);
594 else
596 copyXPMArea(16, 46, 2, 14, 41, 30);
599 return (float)memMax;
602 #else
604 /* Mem/Swap Meter */
605 float DrawMemSwap(float total, int allmem)
607 FILE *fp;
608 if( (fp = fopen("/proc/meminfo", "r")) != NULL)
610 static float stotal=0.0, sshared=0.0, sbuffers=0.0, scached=0.0;
611 char junk[128];
612 float used, freeM, shared, buffers, cached, swaptotal,
613 swapused, swapfreeM;
614 unsigned long MEMshar,MEMbuff, MEMswap;
615 int tempy, tempa;
617 if( has_kern26 > 0 )
619 float scratch;
621 while(!feof(fp))
623 fgets(junk, 120, fp);
624 if (strstr(junk, "MemTotal"))
626 sscanf(junk, "MemTotal: %f kB", &scratch);
627 total = scratch * 1024;
629 if (strstr(junk, "MemFree"))
631 sscanf(junk, "MemFree: %f kB", &scratch);
632 freeM = scratch * 1024;
633 used = total - freeM;
635 if (strstr(junk, "Buffers"))
637 sscanf(junk, "Buffers: %f kB", &scratch);
638 buffers = scratch * 1024;
640 if (strstr(junk, "Cached"))
642 sscanf(junk, "Cached: %f kB", &scratch);
643 cached = scratch * 1024;
645 if (strstr(junk, "SwapTotal"))
647 sscanf(junk, "SwapTotal: %f kB", &scratch);
648 swaptotal = scratch * 1024;
650 if (strstr(junk, "SwapFree"))
652 sscanf(junk, "SwapFree: %f kB", &scratch);
653 swapfreeM = scratch * 1024;
654 swapused = swaptotal - swapfreeM;
657 } else {
658 fgets(junk, 80, fp);
659 fscanf(fp, "Mem: %f %f %f %f %f %f\nSwap: %f %f %f", &total,
660 &used, &freeM, &shared, &buffers, &cached,
661 &swaptotal, &swapused, &swapfreeM);
663 fclose(fp);
665 /* All mem areas */
666 if(stotal != total || sshared != shared || sbuffers != buffers || scached != cached)
668 stotal = total; sshared = shared; sbuffers = buffers; scached = cached;
669 if ( (total/101048576) >= 1)
671 MEMshar=((used-buffers-cached)/total)*27;
672 MEMbuff=(buffers/total)*27;
673 } else {
674 MEMshar=((used-buffers-cached)/total)*33;
675 MEMbuff=(buffers/total)*33;
677 // refresh
678 copyXPMArea(4, 115, 55, 11, 4, 18);
679 // Bar
680 if ( (total/101048576) >= 1)
682 copyXPMArea(3,75,((used/total)*28),9,5,19);
683 } else {
684 copyXPMArea(3,75,((used/total)*34),9,5,19);
686 // Separators
687 copyXPMArea(15,105,1,9,5+MEMshar,19);
688 copyXPMArea(15,105,1,9,7+MEMshar+MEMbuff,19);
689 copyXPMArea(15,105,(36-(used/total)*34),9,(5+(used/total)*34),19);
690 // Numbers
691 tempa=used/1048576;
692 tempy=tempa%10;
693 copyXPMArea(3+(tempy*6),66,6,9,50,19);
694 tempy=(tempa/10)%10;
695 copyXPMArea(3+(tempy*6),66,6,9,44,19);
696 tempy=(tempa/100)%10;
697 if ( (total/101048576) >= 1) {
698 copyXPMArea(3+(tempy*6),66,6,9,38,19);
699 copyXPMArea(16,46,2,14,35,16);
700 } else {
701 copyXPMArea(16,46,2,14,41,16);
704 /* SWAP Meter */
705 if ( swaptotal == 0 ) MEMswap = 0;
706 else {
707 if ( (total/101048576) >= 1)
708 MEMswap=(swapused*31)/swaptotal;
709 else MEMswap=(swapused*36)/swaptotal;
711 // refresh
712 copyXPMArea(4, 115, 55, 11, 4, 32);
713 // Bar
714 copyXPMArea(3,75,MEMswap,9,5,33);
715 copyXPMArea(15,105,(36-(MEMswap)),9,5+MEMswap,33);
716 // Numbers
717 tempa=swapused/1048576;
718 tempy=tempa%10;
719 copyXPMArea(3+(tempy*6),66,6,9,50,33);
720 tempy=(tempa/10)%10;
721 copyXPMArea(3+(tempy*6),66,6,9,44,33);
722 tempy=tempa/100;
723 if ( tempy != 0 ) {
724 copyXPMArea(3+(tempy*6),66,6,9,38,33);
725 copyXPMArea(16,46,2,14,35,30);
726 } else {
727 copyXPMArea(16,46,2,14,41,30);
730 return(total);
733 #endif
735 /**************************************************************************/
737 #ifndef __solaris__
739 /* X Mem Usage */
740 void DrawXmem(int Xpid, float total)
742 FILE *fp;
743 char buf[128], XFileName[256];
744 float ratio;
745 long old_Xsize=-1, Xsize=0;
747 sprintf(XFileName, "/proc/%d/status", Xpid);
749 if ((fp = fopen(XFileName, "r")) != NULL)
751 while( fgets(buf, 127, fp) )
753 if (strstr(buf, "VmSize"))
754 sscanf(buf, "VmSize: %ld", &Xsize);
756 if(old_Xsize!=Xsize)
758 int tempy, tempa, tempb;
759 old_Xsize=Xsize;
760 ratio=Xsize/(total/1024);
761 if ( Xsize > (total/1024) ) Xsize=total/1024;
762 Xsize=Xsize/1024;
763 tempy=Xsize%10;
764 copyXPMArea(3+(tempy*6),66,6,9,50,48);
765 tempa=Xsize/10;
766 tempy=tempa%10;
767 tempb=Xsize/100;
768 if ( Xsize > 100 )
770 copyXPMArea(3,84,((ratio)*17),11,18,47);
771 copyXPMArea(15,105,(23-((ratio)*17)),11,(18+(ratio*22)),47);
772 copyXPMArea(3+(tempy*6),66,6,9,44,48);
773 copyXPMArea(3+(tempb*6),66,6,9,38,48);
774 copyXPMArea(16,46,2,14,36,46);
775 } else {
776 copyXPMArea(3,84,((ratio)*22),11,18,47);
777 copyXPMArea(15,105,(23-((ratio)*22)),11,(18+(ratio*22)),47);
778 copyXPMArea(3+(tempy*6),66,6,9,44,48);
779 copyXPMArea(16,46,2,14,41,46);
782 fclose(fp);
786 #endif
788 /**************************************************************************/
790 /* Uptime */
791 void DrawUptime(void)
793 int upt, days=0,hours=0,mins=0, old_mins=-1,old_hours=-1;
795 #ifdef __solaris__
796 struct utmp * pUtmp;
797 struct utmp idUtmp;
798 idUtmp.ut_type = BOOT_TIME;
799 setutent();
800 pUtmp = getutid(&idUtmp);
801 upt = (time(0) - pUtmp->ut_time);
802 #else
803 FILE *fp;
804 if( (fp = fopen("/proc/uptime", "r")) != NULL)
805 fscanf(fp, "%d",&upt);
806 fclose(fp);
807 #endif
808 mins=(upt/60)%60;
809 hours=(upt/3600)%24;
810 days=(upt/86400);
811 if(old_hours!=hours)
812 old_hours=hours;
813 if(old_mins!=mins)
815 int tempy;
816 old_mins=mins;
817 if ( days > 9 )
819 copyXPMArea(20,105,36,9,18,48);
820 tempy=hours%10;
821 copyXPMArea(3+(tempy*6),66,6,9,50,48);
822 tempy=hours/10;
823 copyXPMArea(3+(tempy*6),66,6,9,44,48);
824 copyXPMArea(63,66,3,9,41,48);
825 tempy=days%10;
826 copyXPMArea(3+(tempy*6),66,6,9,34,48);
827 tempy=(days/10)%10;
828 copyXPMArea(3+(tempy*6),66,6,9,28,48);
829 tempy=days/100;
830 copyXPMArea(3+(tempy*6),66,6,9,22,48);
831 } else {
832 tempy=mins%10;
833 copyXPMArea(3+(tempy*6),66,6,9,50,48);
834 tempy=mins/10;
835 copyXPMArea(3+(tempy*6),66,6,9,44,48);
836 copyXPMArea(63,66,3,9,41,48);
837 tempy=hours%10;
838 copyXPMArea(3+(tempy*6),66,6,9,34,48);
839 tempy=hours/10;
840 copyXPMArea(3+(tempy*6),66,6,9,28,48);
841 copyXPMArea(63,66,3,9,25,48);
842 tempy=days%10;
843 copyXPMArea(3+(tempy*6),66,6,9,18,48);
849 /**************************************************************************/
851 /* Drawing LED's */
852 void DrawLite(int state, int dx, int dy)
854 switch(state)
856 case B_RED:
857 copyXPMArea(BREDX, BREDY, LITEW, LITEH, dx, dy);
858 break;
859 case B_GREEN:
860 copyXPMArea(BGREENX, BGREENY, LITEW, LITEH, dx, dy);
861 break;
862 default:
863 case B_OFF:
864 copyXPMArea(BOFFX, BOFFY, LITEW, LITEH, dx, dy);
865 break;
870 /* EOF */