--- gpm-1.17.8/gpm-root.c Sat May 8 07:51:06 1999 +++ gpm-1.17/gpm-root.c Fri May 21 22:46:32 1999 @@ -179,6 +179,7 @@ int f_free(int mode, DrawItem *self, int uid); int f_time(int mode, DrawItem *self, int uid); int f_pipe(int mode, DrawItem *self, int uid); +int f_apm (int mode, DrawItem *self, int uid); #line 191 "gpm-root.y" @@ -1148,6 +1149,7 @@ {"f.free",T_FUNC,f_free}, {"f.time",T_FUNC,f_time}, {"f.pipe",T_FUN2,f_pipe}, + {"f.apm",T_FUNC,f_apm}, {"f.nop",T_FUNC,NULL}, {NULL,0,NULL} }; @@ -1625,8 +1627,51 @@ /*---------------------------------------------------------------------*/ int f_pipe(int mode, DrawItem *self, int uid) {return 0;} - /*====================================================================*/ - int fixone(Draw *ptr, int uid) +/*---------------------------------------------------------------------*/ +int f_apm(int mode, DrawItem *self, int uid) +{ +FILE *f; +long l1,l2; +char s[80],s1[8],s2[8],*acline,*battry; + + l1=l2=0; + acline=" ? "; + battry=acline; + switch (mode) + { + case F_CREATE: /* modify name, just to fake its length */ + self->clientdata=malloc(strlen(self->name)+30); + self->name=realloc(self->name,strlen(self->name)+30); + strcpy(self->clientdata,self->name); + strcat(self->clientdata," %s %s:%s %s"); + sprintf(self->name,self->clientdata,acline,battry," ? "," ? "); + break; + + case F_POST: + if (!(f=fopen("/proc/apm","r"))) return 1; + fscanf(f,"%*s %*s %*s %i %i %*s %s %s",&l1,&l2,s1,s2); + switch (l1) { + case 0 : acline="Battery"; break; + case 1 : acline="~AC~"; break; + case 2 : acline="Backup"; break; + } + switch (l2) { + case 0 : battry="high"; break; + case 1 : battry="low"; break; + case 2 : battry="critical"; break; + case 3 : battry="charging"; break; + } + sprintf(self->name,self->clientdata,acline,battry,s1,s2); + fclose(f); + + case F_INVOKE: + break; + } + return 0; +} + +/*====================================================================*/ +int fixone(Draw *ptr, int uid) { int hei,wid; DrawItem *item;