mirror of https://github.com/xzeldon/htop.git
netbsd: style: declare variables on first use rather than C89-style
This commit is contained in:
parent
fdcdc54ec4
commit
93ca5af953
|
@ -330,49 +330,43 @@ bool Platform_getNetworkIO(NetworkIOData* data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
||||||
int fd;
|
|
||||||
bool isACAD, isBattery;
|
|
||||||
int64_t isPresent, isConnected;
|
|
||||||
int64_t curCharge, maxCharge;
|
|
||||||
int64_t totalCharge, totalCapacity;
|
|
||||||
prop_dictionary_t dict, fields, props;
|
prop_dictionary_t dict, fields, props;
|
||||||
prop_object_iterator_t devIter, fieldsIter;
|
prop_object_t device, class;
|
||||||
prop_object_t device, class, fieldsArray, curValue, maxValue, descField;
|
|
||||||
|
|
||||||
totalCharge = 0;
|
int64_t totalCharge = 0;
|
||||||
totalCapacity = 0;
|
int64_t totalCapacity = 0;
|
||||||
|
|
||||||
*percent = NAN;
|
*percent = NAN;
|
||||||
*isOnAC = AC_ERROR;
|
*isOnAC = AC_ERROR;
|
||||||
|
|
||||||
fd = open(_PATH_SYSMON, O_RDONLY);
|
int fd = open(_PATH_SYSMON, O_RDONLY);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (prop_dictionary_recv_ioctl(fd, ENVSYS_GETDICTIONARY, &dict) != 0)
|
if (prop_dictionary_recv_ioctl(fd, ENVSYS_GETDICTIONARY, &dict) != 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
devIter = prop_dictionary_iterator(dict);
|
prop_object_iterator_t devIter = prop_dictionary_iterator(dict);
|
||||||
if (devIter == NULL)
|
if (devIter == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
while ((device = prop_object_iterator_next(devIter)) != NULL) {
|
while ((device = prop_object_iterator_next(devIter)) != NULL) {
|
||||||
fieldsArray = prop_dictionary_get_keysym(dict, device);
|
prop_object_t fieldsArray = prop_dictionary_get_keysym(dict, device);
|
||||||
if (fieldsArray == NULL)
|
if (fieldsArray == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
fieldsIter = prop_array_iterator(fieldsArray);
|
prop_object_iterator_t fieldsIter = prop_array_iterator(fieldsArray);
|
||||||
if (fieldsIter == NULL)
|
if (fieldsIter == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
isACAD = false;
|
bool isACAdapter = false;
|
||||||
isBattery = false;
|
bool isBattery = false;
|
||||||
|
|
||||||
/* only assume battery is not present if explicitly stated */
|
/* only assume battery is not present if explicitly stated */
|
||||||
isPresent = 1;
|
int64_t isPresent = 1;
|
||||||
isConnected = 0;
|
int64_t isConnected = 0;
|
||||||
curCharge = 0;
|
int64_t curCharge = 0;
|
||||||
maxCharge = 0;
|
int64_t maxCharge = 0;
|
||||||
|
|
||||||
while ((fields = prop_object_iterator_next(fieldsIter)) != NULL) {
|
while ((fields = prop_object_iterator_next(fieldsIter)) != NULL) {
|
||||||
props = prop_dictionary_get(fields, "device-properties");
|
props = prop_dictionary_get(fields, "device-properties");
|
||||||
|
@ -385,16 +379,16 @@ void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (prop_string_equals_cstring(class, "ac-adapter")) {
|
if (prop_string_equals_cstring(class, "ac-adapter")) {
|
||||||
isACAD = true;
|
isACAdapter = true;
|
||||||
} else if (prop_string_equals_cstring(class, "battery")) {
|
} else if (prop_string_equals_cstring(class, "battery")) {
|
||||||
isBattery = true;
|
isBattery = true;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
curValue = prop_dictionary_get(fields, "cur-value");
|
prop_object_t curValue = prop_dictionary_get(fields, "cur-value");
|
||||||
maxValue = prop_dictionary_get(fields, "max-value");
|
prop_object_t maxValue = prop_dictionary_get(fields, "max-value");
|
||||||
descField = prop_dictionary_get(fields, "description");
|
prop_object_t descField = prop_dictionary_get(fields, "description");
|
||||||
|
|
||||||
if (descField == NULL || curValue == NULL)
|
if (descField == NULL || curValue == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -416,7 +410,7 @@ void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
||||||
totalCapacity += maxCharge;
|
totalCapacity += maxCharge;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isACAD) {
|
if (isACAdapter) {
|
||||||
*isOnAC = isConnected ? AC_PRESENT : AC_ABSENT;
|
*isOnAC = isConnected ? AC_PRESENT : AC_ABSENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue