summaryrefslogtreecommitdiffstats
path: root/x11-wm/epplets/files/patch-aj
blob: 1a071616997029db42c059ee488e5b7b8b11ae8b (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
--- epplets/E-Power.c.bak	Sat Mar 25 02:35:06 2000
+++ epplets/E-Power.c	Sat Mar 25 03:37:24 2000
@@ -1,5 +1,10 @@
 #include "epplet.h"
 
+#include<stdio.h>
+#include<fcntl.h>
+#include<sys/ioctl.h>
+#include<machine/apm_bios.h>
+
 int                prev_bat_val = 110;
 int                bat_val = 0;
 int                time_val = 0;
@@ -18,25 +23,24 @@
 static void
 cb_timer(void *data)
 {
-   static FILE *f;
+   int fd;
 
-   f = fopen("/proc/apm", "r");
-   if (f)
+   fd = open("/dev/apm", O_RDONLY);
+   if (fd != -1)
      {
 	char s[256], s1[32], s2[32], s3[32];
 	int apm_flags, ac_stat, bat_stat, bat_flags;
 	int  i, hours, minutes, up, up2;
 	char *s_ptr;
+	struct apm_info info;
+	
+	ioctl(fd,APMIO_GETINFO,&info);
+	ac_stat=info.ai_acline;
+	bat_stat=info.ai_batt_stat;
+	time_val=info.ai_batt_time;
+	bat_val=info.ai_batt_life;
 	
-	fgets(s, 255, f);
-	sscanf(s, "%*s %*s %x %x %x %x %s %s %s", &apm_flags, &ac_stat, &bat_stat, &bat_flags, s1, s2, s3);
-	s1[strlen(s1) - 1] = 0;
-	bat_val=atoi(s1);
-	if (!strcmp(s3, "sec"))
-	   time_val = atoi(s2);
-	else if (!strcmp(s3, "min"))
-	   time_val = atoi(s2) * 60;
-	fclose(f);
+	close(fd);
 	
 	up = bat_val - prev_bat_val;
 	up2 = up;
@@ -52,50 +56,47 @@
 	
         s_ptr = s;
 
-        if( bat_flags != 0xff
-	    && bat_flags & 0x80 )
-	  {
-	    s_ptr += Esnprintf( s_ptr, sizeof(s_ptr), "no battery" );
-	  }
-	else
-	  {
 	    if( bat_val > 0 )
-	      s_ptr += Esnprintf( s_ptr, sizeof(s_ptr), "%i%%", bat_val );
+	      s_ptr += Esnprintf( s_ptr, sizeof("%i%%"), "%i%%", bat_val );
 
 	    switch( bat_stat )
 	      {
 		case 0:
-	          s_ptr += Esnprintf( s_ptr, sizeof(s_ptr), ", high" );
+	          s_ptr += Esnprintf( s_ptr, sizeof(", high"), ", high" );
 		  break;
 		case 1:
-	          s_ptr += Esnprintf( s_ptr, sizeof(s_ptr), ", low" );
+	          s_ptr += Esnprintf( s_ptr, sizeof(", low"), ", low" );
 		  break;
 		case 2:
-	          s_ptr += Esnprintf( s_ptr, sizeof(s_ptr), ", crit." );
+	          s_ptr += Esnprintf( s_ptr, sizeof(", crit."), ", crit." );
 		  break;
 		case 3:
-	          s_ptr += Esnprintf( s_ptr, sizeof(s_ptr), ", charge" );
+	          s_ptr += Esnprintf( s_ptr, sizeof(", charge"), ", charge" );
 		  break;
 	      }
-	  }
-	s_ptr += Esnprintf( s_ptr, sizeof(s_ptr), "\n" );
+
+	s_ptr += Esnprintf( s_ptr, sizeof("\n"), "\n" );
 
 
 	if( ac_stat == 1 )
           {
-	    s_ptr += Esnprintf(s_ptr, sizeof(s_ptr), "AC on-line" );
+	    s_ptr += Esnprintf(s_ptr, sizeof("AC on-line"), "AC on-line" );
           }
         else
           {
+	    if( time_val >= 0){
 	    hours = time_val / 3600;
             minutes = (time_val / 60) % 60;
 	    if (up2 > 0)
-	       s_ptr += Esnprintf(s_ptr, sizeof(s_ptr), "(%i:%02i)\n%i:%02i", 
+	       s_ptr += Esnprintf(s_ptr, sizeof("(%i:%02i)\n%i:%02i"), "(%i:%02i)\n%i:%02i", 
 		       		(((100 - bat_val) * 2 * 60) / up2) / 60, 
 		       		(((100 - bat_val) * 2 * 60) / up2) % 60, 
 		       		hours, minutes);
 	    else
-	       s_ptr += Esnprintf(s_ptr, sizeof(s_ptr), "%i:%02i", hours, minutes);
+	       s_ptr += Esnprintf(s_ptr, sizeof("%i:%02i"), "%i:%02i", hours, minutes);
+	    }
+	    else
+	      s_ptr += Esnprintf(s_ptr, sizeof("unknown"),"unknown");
           }
 	Epplet_change_label(label, s);
 


OpenPOWER on IntegriCloud