--- orig-Clock.c	Tue Jul 15 21:30:09 2003
+++ Clock.c	Tue Jul 15 21:24:32 2003
@@ -113,10 +113,14 @@
         offset(twentyfour), XtRImmediate, (XtPointer) TRUE},
     {XtNbrief, XtCBoolean, XtRBoolean, sizeof(Boolean),
         offset(brief), XtRImmediate, (XtPointer) FALSE},
     {XtNstrftime, XtCString, XtRString, sizeof(String),
         offset(strftime), XtRString, ""},
+    {XtNwithapm7, XtCBoolean, XtRBoolean, sizeof(Boolean),
+        offset(withapm7), XtRImmediate, (XtPointer) TRUE},
+    {XtNwithapm8, XtCBoolean, XtRBoolean, sizeof(Boolean),
+        offset(withapm8), XtRImmediate, (XtPointer) TRUE},
     {XtNchime, XtCBoolean, XtRBoolean, sizeof(Boolean),
 	offset(chime), XtRImmediate, (XtPointer) FALSE },
     {XtNpadding, XtCMargin, XtRInt, sizeof(int),
         offset(padding), XtRImmediate, (XtPointer) 8},
     {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
@@ -439,10 +443,40 @@
       static char utime[35];
       Time_t tsec;
       tsec = time(NULL);
       sprintf (utime, "%10lu seconds since Epoch", (unsigned long)tsec);
       return utime;
+   } else if (w->clock.withapm7 || w->clock.withapm8) {
+      static char long12[80];
+      int c,i;
+      FILE *f;
+
+      strftime(long12, sizeof long12, "%a %b %d %H:%M:%S", tm);
+      f=fopen("/proc/apm","r");
+      if(f) {
+	i=w->clock.withapm8?7:6;
+	while(i) {
+	  c=fgetc(f);
+	  if(c==EOF)
+	    break;
+	  if(c==' ')
+	    i--;
+	}
+	if(!i) {
+	  i=strlen(long12);
+	  while(i<sizeof(long12)) {
+	    long12[i++]=c;
+	    c=fgetc(f);
+	    if(c==EOF || c==' ') {
+	      long12[i]='\0';
+	      break;
+	    }
+	  }
+	}
+	fclose(f);
+      }
+      return long12;
    } else if (*w->clock.strftime) {
      /*Note: this code is probably excessively paranoid 
        about buffer overflow.  The extra size 10 padding
        is also meant as a further guard against programmer 
        error, although it is a little controversial*/
--- orig-Clock.h	Tue Jul 15 21:30:15 2003
+++ Clock.h	Tue Jul 15 21:24:48 2003
@@ -65,10 +65,12 @@
 /* Parameters:
 
  Name		     Class		RepType		Default Value
  ----		     -----		-------		-------------
  twentyfour	     Boolean		Boolean		True
+ withapm7	     Boolean		Boolean		True
+ withapm8	     Boolean		Boolean		True
  analog		     Boolean		Boolean		True
  background	     Background		Pixel		white
  backingStore	     BackingStore	BackingStore	default
  border		     BorderColor	Pixel		Black
  borderWidth	     BorderWidth	Dimension	1
@@ -95,10 +97,14 @@
 #define XtNhand "hands"
 
 
 		/* Boolean: 24-hour if TRUE */
 #define XtNtwentyfour "twentyfour"
+
+      /* Boolean: Show battery life if TRUE */
+#define XtNwithapm7 "withapm7"
+#define XtNwithapm8 "withapm8"
 
 		/* Boolean: digital if FALSE */
 #define XtNanalog "analog"
 
 		/* Boolean: only hour/minute if TRUE */
--- orig-ClockP.h	Tue Jul 15 21:30:27 2003
+++ ClockP.h	Tue Jul 15 21:24:55 2003
@@ -87,10 +87,12 @@
 	 Boolean beeped;
 	 Boolean analog;
 	 Boolean brief;
 	 Boolean twentyfour;
 	 Boolean utime;
+	 Boolean withapm7;
+	 Boolean withapm8;
          String strftime;
 	 Boolean show_second_hand;
 	 Dimension second_hand_length;
 	 Dimension minute_hand_length;
 	 Dimension hour_hand_length;
--- orig-xclock.c	Tue Jul 15 21:30:40 2003
+++ xclock.c	Tue Jul 15 21:23:11 2003
@@ -61,10 +61,12 @@
 {"-d",		"*clock.analog",	XrmoptionNoArg,		"FALSE"},
 {"-digital",	"*clock.analog",	XrmoptionNoArg,		"FALSE"},
 {"-analog",	"*clock.analog",	XrmoptionNoArg,		"TRUE"},
 {"-twelve",	"*clock.twentyfour",	XrmoptionNoArg,		"FALSE"},
 {"-twentyfour",	"*clock.twentyfour",	XrmoptionNoArg,		"TRUE"},
+{"-withapm7",	"*clock.withapm7",	XrmoptionNoArg,		"TRUE"},
+{"-withapm8",	"*clock.withapm8",	XrmoptionNoArg,		"TRUE"},
 {"-brief",	"*clock.brief",		XrmoptionNoArg,		"TRUE"},
 {"-utime",	"*clock.utime",		XrmoptionNoArg,		"TRUE"},
 {"-strftime",	"*clock.strftime",	XrmoptionSepArg,	NULL},
 #ifdef XRENDER
 {"-face",	"*clock.face",		XrmoptionSepArg,	NULL},
@@ -95,11 +97,12 @@
 	(void) printf ("       [-fn <font_name>] [-help] [-padding <pixels>]\n");
 	(void) printf ("       [-rv] [-update <seconds>] [-display displayname]\n");
 #ifdef XRENDER
 	(void) printf ("       [-render] [-face <face name>] [-sharp]\n");
 #endif
-	(void) printf ("       [-geometry geom] [-twelve] [-twentyfour]\n\n");
+	(void) printf ("       [-geometry geom] [-twelve] [-twentyfour] [-withapm7]\n");
+	(void) printf ("       [-withapm8]\n\n");
 	exit(1);
 }
 
 static void 
 die(Widget w, XtPointer client_data, XtPointer call_data)
--- orig-xclock.man	Tue Jul 15 21:30:57 2003
+++ xclock.man	Tue Jul 15 21:31:07 2003
@@ -33,10 +33,11 @@
 \fBxclock\fP [ \fB\-help\fP ] [ \fB\-analog\fP ] [ \fB\-digital\fP ]
 [ \fB\-brief\fP ] [ \fB\-chime\fP ] [ \fB\-hd\fP \fIcolor\fP ]
 [ \fB\-hl\fP \fIcolor\fP ] [ \fB\-update\fP \fIseconds\fP ]
 [ \fB\-strftime\fP \fIformat\fP ]
 [ \fB\-padding\fP \fInumber\fP ]
+[ \fB\-withapm7\fP ] [ \fB\-withapm8\fP ]
 .SH DESCRIPTION
 The
 .I xclock 
 program displays the time in analog or digital form.  The time is continuously
 updated at a frequency which may be specified by the user.
@@ -74,10 +75,19 @@
 twelve hour format.
 .TP 8
 .B \-twentyfour
 This option indicates that a digital clock should display the time in
 twenty-four hour format.  This is the default when a digital clock is used.
+.TP 8
+.B \-withapm7
+This option indicates that the digital clock should display the seventh word
+of /proc/apm, which might be your current battery charge.
+.TP 8
+.B \-withapm8
+This option indicates that the digital clock should display the eighth word
+of /proc/apm, which might be your remaining battery life.  This option
+overrides the -withapm7 option.
 .TP 8
 .B \-chime
 This option indicates that the clock should chime 
 once on the half hour and twice on the hour.
 .TP 8
