--- acpitool-0.5.orig/src/battery.cpp	2008-07-24 01:04:16.000000000 +0200
+++ acpitool-0.5/src/battery.cpp	2009-05-14 21:58:06.000000000 +0200
@@ -133,13 +133,13 @@
             	    else
             		Precision = 4;
             	    
-		    if(strncmp(Batt_Info[i]->Charging_State,"char",4)==0) 
+		    if(strncasecmp(Batt_Info[i]->Charging_State,"char",4)==0) 
 		    {
 			Is_Charging = 1;
 		    }
 		    else
 		    {
-			if(strncmp(Batt_Info[i]->Charging_State,"disch",5)==0) Is_Discharging = 1;
+			if(strncasecmp(Batt_Info[i]->Charging_State,"disch",5)==0) Is_Discharging = 1;
 		    }
 		    		    
 	    	    if(Show_Time)      // calculate remaining or charging time only if present battery rate != 0 //
@@ -482,7 +482,7 @@
 int Get_Battery_Info_from_Sys(const int bat_nr, Battery_Info *bat_info, int verbose)
 {
     ifstream file_in;
-    char filename[6][65], str[100], temp[100];
+    char filename[6][65], str[100], temp[100], attr[100];
     int bat_count = 0, start = 0, findex = 0;
     DIR *battery_dir;
     char *name, *dirname;
@@ -588,142 +588,66 @@
 	    return -1;
     	}
     	
-    	memset(str, '\0', 100);
-	for(int t=0; t<5; t++)
-	    fgets(str, 100, power_fp);            /* skip first 5 lines */
+	strncpy(bat_info->Technology, "unknown", 7);
+	strncpy(bat_info->Voltage_Now, "unknown", 7);
+	strncpy(bat_info->Present_Rate, "unknown", 7);
+	strncpy(bat_info->Design_Cap, "unknown", 7);
+	strncpy(bat_info->LastFull_Cap, "unknown", 7);
+	strncpy(bat_info->Remaining_Cap, "unknown", 7);
+	strncpy(bat_info->Model, "unknown", 7);
+	strncpy(bat_info->Serial, "unknown", 7);
+
+	// see linux-2.6/drivers/power/power_supply_sysfs.c
+	// there can be different number of lines, so read up to 40 lines
+	for(int t=0; t<40; t++) {
     	
-    	/* get battery status (full, charging, ...) */
     	memset(str, '\0', 100);
-    	fgets(str, 100, power_fp);
-    	if (strlen(str)>0)
-    	{
+	    memset(attr, '\0', 100);
     	    memset(temp, '\0', 100);
+	    fgets(str, 100, power_fp);
+	    sscanf(str, "%[^=]s %*s %[^\n]", attr);
     	    sscanf(str, "%*[^=] %*c %s %[^\n]",temp); 
+	    if (strcmp(attr,"POWER_SUPPLY_STATUS")==0) {
     	    strncpy(bat_info->Charging_State, temp, 12);
     	}   
-	
-	    
-	/* get battery presence (0 or 1) */    
-	memset(str, '\0', 100);
-	fgets(str, 100, power_fp);   
-	if (strlen(str)>0)
-	{
-	    memset(temp, '\0', 100);
-	    strncpy(temp, str+21, 1);
-    	    if(strncmp(temp,"1",1)==0)
-    	        bat_info->Battery_Present = 1;               /* yes, we have a battery */
-    	    else
-    	    {
-    		bat_info->Battery_Present = 0;
-    		printf(" Battery is not present, bailing out. \n");
-    		return 0;                                    /* bail out if battery is not present */
-    	    }
+	    else if (strcmp(attr,"POWER_SUPPLY_TYPE")==0) {
+	    		strncpy(bat_info->Bat_Type, temp, 12);
     	}
-    	    
-    	    
-    	/* get technology */    
-	fgets(str, 100, power_fp);   
-	if (strlen(str)>0)
-    	{
-    	    memset(temp, '\0', 100);
-    	    sscanf(str, "%*[^=] %*c %s %[^\n]",temp); 
+	    else if (strcmp(attr,"POWER_SUPPLY_TECHNOLOGY")==0) {
     	    strncpy(bat_info->Technology, temp, 12);
     	} 
-    	else
-    	    strncpy(bat_info->Technology, "unknown", 7);
-    	
-
-	fgets(str, 100, power_fp);    	/* skip 1 line */	
-
-
-	/* get voltage_now */    
-	fgets(str, 100, power_fp);
-	if (strlen(str)>0)
-    	{
-    	    memset(temp, '\0', 100);
-    	    sscanf(str, "%*[^=] %*c %s %[^\n]",temp); 
+	    else if (strcmp(attr,"POWER_SUPPLY_VOLTAGE_NOW")==0) {
     	    strncpy(bat_info->Voltage_Now, temp, 12);
     	}    
-    	else
-    	    strncpy(bat_info->Voltage_Now, "unknown", 7);
-
-    	
-	/* get current_now, which I believe is the charging rate ? */    
-	fgets(str, 100, power_fp);
-	if (strlen(str)>0)
-    	{
-    	    memset(temp, '\0', 100);
-    	    sscanf(str, "%*[^=] %*c %s %[^\n]",temp); 
-    	    strncpy(bat_info->Present_Rate, temp, 12);
+	    else if (strcmp(attr,"POWER_SUPPLY_CURRENT_NOW")==0) {
+			strncpy(bat_info->Present_Rate, temp, 9);
     	}       
-    	else
-    	    strncpy(bat_info->Present_Rate, "unknown", 7);
-
-	
-	/* get charge_full_design */    
-	fgets(str, 100, power_fp);
-	if (strlen(str)>0)
-    	{
-    	    memset(temp, '\0', 100);
-    	    sscanf(str, "%*[^=] %*c %s %[^\n]",temp); 
-    	    strncpy(bat_info->Design_Cap, temp, 12);
+	    else if (strcmp(attr,"POWER_SUPPLY_ENERGY_FULL_DESIGN")==0) {
+			strncpy(bat_info->Design_Cap, temp, 9);
     	}          
-    	else
-    	    strncpy(bat_info->Design_Cap, "unknown", 7);
-
-
-	/* get charge_full, which is the last full capacity I guess ? */    
-	fgets(str, 100, power_fp);   
-	if (strlen(str)>0)
-    	{
-    	    memset(temp, '\0', 100);
-    	    sscanf(str, "%*[^=] %*c %s %[^\n]",temp); 
-    	    strncpy(bat_info->LastFull_Cap, temp, 12);
+	    else if (strcmp(attr,"POWER_SUPPLY_ENERGY_FULL")==0 ) {
+			strncpy(bat_info->LastFull_Cap, temp, 9);
     	}       
-    	else
-    	    strncpy(bat_info->LastFull_Cap, "unknown", 7);
-
-
-	/* get charge_now */    
-	fgets(str, 100, power_fp);   
-	if (strlen(str)>0)
-    	{
-    	    memset(temp, '\0', 100);
-    	    sscanf(str, "%*[^=] %*c %s %[^\n]",temp); 
-    	    strncpy(bat_info->Remaining_Cap, temp, 12);
+	    else if (strcmp(attr,"POWER_SUPPLY_ENERGY_NOW")==0) {
+			strncpy(bat_info->Remaining_Cap, temp, 9);
     	}       
-    	else
-    	    strncpy(bat_info->Remaining_Cap, "unknown", 7);
-
-
-	/* get model_name */  
-	  
-	fgets(str, 100, power_fp);   
-	if (strlen(str)>0)
-    	{
-    	    memset(temp, '\0', 100);
-	    strncpy(temp, str+24, 12);         // use strncpy here because sscanf chokes on blanks in this one ? //
-
-    	    memset(str, '\0', 100);
-    	    sscanf(temp, "%[^\n]", str);       // strip trailing \n, fucks up output //
-    	    
-    	    strncpy(bat_info->Model, str, 12);
+	    else if (strcmp(attr,"POWER_SUPPLY_MODEL_NAME")==0) {
+			strncpy(bat_info->Model, temp, 12);			
     	}       
-    	else
-    	    strncpy(bat_info->Model, "unknown", 7);
-
-	fgets(str, 100, power_fp);   
-	
-	/* get serial */    
-	fgets(str, 100, power_fp);   
-	if (strlen(str)!=0)
-    	{
-    	    memset(temp, '\0', 100);
-    	    sscanf(str, "%*[^=] %*c %s %[^\n]",temp); 
+	    else if (strcmp(attr,"POWER_SUPPLY_SERIAL_NUMBER")==0) {
     	    strncpy(bat_info->Serial, temp, 12);
     	}       
-    	else
-    	    strncpy(bat_info->Serial, "unknown", 7);
+	    else if (strcmp(attr,"POWER_SUPPLY_PRESENT")==0) {
+			if(strncmp(temp,"1",1)==0) {
+				bat_info->Battery_Present = 1;
+			}
+			else {
+				bat_info->Battery_Present = 0;
+				printf(" Battery is not present, bailing out. \n");
+				return 0;
+			}
+	    }
+	}
     
     	fclose(power_fp);
 	}
