chiark
/
gitweb
/
~ian
/
chiark-utils.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
c0e8d68
)
fixed error handling
author
ianmdlvl
<ianmdlvl>
Sun, 12 Dec 2004 16:33:20 +0000
(16:33 +0000)
committer
ianmdlvl
<ianmdlvl>
Sun, 12 Dec 2004 16:33:20 +0000
(16:33 +0000)
cprogs/xacpi-simple.c
patch
|
blob
|
history
diff --git
a/cprogs/xacpi-simple.c
b/cprogs/xacpi-simple.c
index 157ed59356d46b6b08bbba65c60312a6cfbc9d24..fb9ecff50507a27b460ccbdc703ab21ba110b646 100644
(file)
--- a/
cprogs/xacpi-simple.c
+++ b/
cprogs/xacpi-simple.c
@@
-11,6
+11,7
@@
* cyan | red | dimgrey charged - low [1]
* grey | red | dimgrey charging&discharching, low [1]
* ... darkgreen ... no batteries present
* cyan | red | dimgrey charged - low [1]
* grey | red | dimgrey charging&discharching, low [1]
* ... darkgreen ... no batteries present
+ * ... yellow ... error
*
* [1] battery must be quite badly degraded
*/
*
* [1] battery must be quite badly degraded
*/
@@
-34,7
+35,8
@@
#define TOP 60
#define BOTTOM 3600
#define TOP 60
#define BOTTOM 3600
-#define TIMEOUT 5000 /* milliseconds */
+#define TIMEOUT 5000 /* milliseconds */
+#define TIMEOUT_ONERROR 3333 /* milliseconds */
static const char program_name[]= "xacpi-simple";
static const char program_name[]= "xacpi-simple";
@@
-49,6
+51,7
@@
static void badusage(void) { fail("bad usage"); }
#define CHGST_DISCHARGING 0 /* Reflects order in E(state,charging_state) */
#define CHGST_CHARGING 1 /* in fields table. Also, much code assumes */
#define CHGST_CHARGED 2 /* exactly these three possible states. */
#define CHGST_DISCHARGING 0 /* Reflects order in E(state,charging_state) */
#define CHGST_CHARGING 1 /* in fields table. Also, much code assumes */
#define CHGST_CHARGED 2 /* exactly these three possible states. */
+#define CHGST_ERROR 8 /* Except that this one is an extra bit. */
/*---------- structure of and results from /proc/acpi/battery/... ----------*/
/* variables thisbat_... are the results from readbattery();
/*---------- structure of and results from /proc/acpi/battery/... ----------*/
/* variables thisbat_... are the results from readbattery();
@@
-166,6
+169,13
@@
static int readbattery(void) { /* 0=>ok, -1=>couldn't */
return batfailf("line without a colon");
*colon= 0;
return batfailf("line without a colon");
*colon= 0;
+ for (batlinevalue= colon+1;
+ *batlinevalue && isspace((unsigned char)*batlinevalue);
+ batlinevalue++);
+
+ if (!strcmp(batlinebuf,"ERROR"))
+ return batfailf("kernel reports error");
+
for (p=batlinebuf; p<colon; p++)
if (*p == ' ')
*p= '_';
for (p=batlinebuf; p<colon; p++)
if (*p == ' ')
*p= '_';
@@
-178,10
+188,6
@@
static int readbattery(void) { /* 0=>ok, -1=>couldn't */
continue;
label_interesting:
continue;
label_interesting:
- for (batlinevalue= colon+1;
- *batlinevalue && isspace((unsigned char)*batlinevalue);
- batlinevalue++);
-
if (field->unit) {
*field->valuep= strtoul(batlinevalue,&ep,10);
if (field->unit) {
*field->valuep= strtoul(batlinevalue,&ep,10);
@@
-261,7
+267,7
@@
static void acquiredata(void) {
r= readbattery();
tidybattery();
r= readbattery();
tidybattery();
- if (r)
continue;
+ if (r)
{ charging_state_mask |= CHGST_ERROR; continue; }
if (!thisbat_info_present || !thisbat_state_present)
continue;
if (!thisbat_info_present || !thisbat_state_present)
continue;
@@
-313,6
+319,7
@@
static void initacquire(void) {
C(cyan) \
C(grey) \
C(darkgreen) \
C(cyan) \
C(grey) \
C(darkgreen) \
+ C(yellow) \
C(white) \
GC(remain) \
GC(white) \
C(white) \
GC(remain) \
GC(white) \
@@
-366,15
+373,20
@@
static void setforeground(Gcstate *g, unsigned long px) {
if (!r) fail("XChangeGC");
}
if (!r) fail("XChangeGC");
}
+static void show_solid(unsigned long px) {
+ setbackground(px);
+ XClearWindow(disp,win);
+}
+
static void show(void) {
double elap, then;
int i, leftmost_lit, leftmost_nondeg, beyond, first_beyond;
static void show(void) {
double elap, then;
int i, leftmost_lit, leftmost_nondeg, beyond, first_beyond;
- if (!charging_state_mask)
{
-
setbackgroun
d(pix_darkgreen);
- XClearWindow(disp,win);
- return;
- }
+ if (!charging_state_mask)
+
return show_soli
d(pix_darkgreen);
+
+ if (charging_state_mask & CHGST_ERROR)
+ return show_solid(pix_yellow);
setbackground(pix_dimgrey);
XClearWindow(disp,win);
setbackground(pix_dimgrey);
XClearWindow(disp,win);
@@
-439,7
+451,6
@@
static void colour(unsigned long *pix_r, const char *name) {
static void initgraphics(int argc, char **argv) {
int r;
static void initgraphics(int argc, char **argv) {
int r;
- XTextProperty tp;
const char *geom_string;
XSizeHints *normal_hints;
XWMHints *wm_hints;
const char *geom_string;
XSizeHints *normal_hints;
XWMHints *wm_hints;
@@
-492,9
+503,6
@@
static void initgraphics(int argc, char **argv) {
class_hint->res_name= program_name_silly;
class_hint->res_class= program_name_silly;
class_hint->res_name= program_name_silly;
class_hint->res_class= program_name_silly;
- /*r= XStringListToTextProperty(&program_name_silly, 1, &tp);
- if (!r) fail("XStringListtoTextProperty");*/
-
XmbSetWMProperties(disp,win, program_name,program_name,
argv,argc, normal_hints, wm_hints, class_hint);
XmbSetWMProperties(disp,win, program_name,program_name,
argv,argc, normal_hints, wm_hints, class_hint);
@@
-517,7
+525,7
@@
static void newgeometry(void) {
static void eventloop(void) {
XEvent ev;
struct pollfd pfd;
static void eventloop(void) {
XEvent ev;
struct pollfd pfd;
- int r;
+ int r
, timeout
;
newgeometry();
refresh();
newgeometry();
refresh();
@@
-528,7
+536,8
@@
static void eventloop(void) {
pfd.fd= ConnectionNumber(disp);
pfd.events= POLLIN|POLLERR;
pfd.fd= ConnectionNumber(disp);
pfd.events= POLLIN|POLLERR;
- r= poll(&pfd,1,TIMEOUT);
+ timeout= !(charging_state_mask & CHGST_ERROR) ? TIMEOUT : TIMEOUT_ONERROR;
+ r= poll(&pfd,1,timeout);
if (r==-1 && errno!=EINTR) failr("poll",errno);
while (XPending(disp)) {
if (r==-1 && errno!=EINTR) failr("poll",errno);
while (XPending(disp)) {