]> git.sur5r.net Git - i3/i3status/blob - src/print_battery_info.c
0853e18a862f92829233619e9d9a46e8ac6d8c3d
[i3/i3status] / src / print_battery_info.c
1 // vim:ts=4:sw=4:expandtab
2 #include <ctype.h>
3 #include <time.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <yajl/yajl_gen.h>
8 #include <yajl/yajl_version.h>
9
10 #include "i3status.h"
11
12 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
13 #include <sys/types.h>
14 #include <sys/sysctl.h>
15 #endif
16
17 #if defined(__OpenBSD__)
18 #include <sys/types.h>
19 #include <sys/ioctl.h>
20 #include <sys/fcntl.h>
21 #include <machine/apmvar.h>
22 #endif
23
24 #if defined(__NetBSD__)
25 #include <fcntl.h>
26 #include <prop/proplib.h>
27 #include <sys/envsys.h>
28 #endif
29
30 /*
31  * Get battery information from /sys. Note that it uses the design capacity to
32  * calculate the percentage, not the last full capacity, so you can see how
33  * worn off your battery is.
34  *
35  */
36 void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, const char *status_chr, const char *status_bat, const char *status_full, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity, bool hide_seconds) {
37     time_t empty_time;
38     struct tm *empty_tm;
39     char buf[1024];
40     char statusbuf[16];
41     char percentagebuf[16];
42     char remainingbuf[256];
43     char emptytimebuf[256];
44     char consumptionbuf[256];
45     const char *walk, *last;
46     char *outwalk = buffer;
47     bool watt_as_unit = false;
48     bool colorful_output = false;
49     int full_design = -1,
50         remaining = -1,
51         present_rate = -1,
52         voltage = -1;
53     charging_status_t status = CS_DISCHARGING;
54
55     memset(statusbuf, '\0', sizeof(statusbuf));
56     memset(percentagebuf, '\0', sizeof(percentagebuf));
57     memset(remainingbuf, '\0', sizeof(remainingbuf));
58     memset(emptytimebuf, '\0', sizeof(emptytimebuf));
59     memset(consumptionbuf, '\0', sizeof(consumptionbuf));
60
61     static char batpath[512];
62     sprintf(batpath, path, number);
63     INSTANCE(batpath);
64
65 #define BATT_STATUS_NAME(status) \
66     (status == CS_CHARGING ? status_chr : (status == CS_DISCHARGING ? status_bat : status_full))
67
68 #if defined(LINUX)
69     if (!slurp(batpath, buf, sizeof(buf))) {
70         OUTPUT_FULL_TEXT(format_down);
71         return;
72     }
73
74     for (walk = buf, last = buf; (walk - buf) < 1024; walk++) {
75         if (*walk == '\n') {
76             last = walk + 1;
77             continue;
78         }
79
80         if (*walk != '=')
81             continue;
82
83         if (BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_NOW")) {
84             watt_as_unit = true;
85             remaining = atoi(walk + 1);
86         } else if (BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_NOW")) {
87             watt_as_unit = false;
88             remaining = atoi(walk + 1);
89         } else if (BEGINS_WITH(last, "POWER_SUPPLY_CURRENT_NOW"))
90             present_rate = abs(atoi(walk + 1));
91         else if (BEGINS_WITH(last, "POWER_SUPPLY_VOLTAGE_NOW"))
92             voltage = abs(atoi(walk + 1));
93         /* on some systems POWER_SUPPLY_POWER_NOW does not exist, but actually
94          * it is the same as POWER_SUPPLY_CURRENT_NOW but with μWh as
95          * unit instead of μAh. We will calculate it as we need it
96          * later. */
97         else if (BEGINS_WITH(last, "POWER_SUPPLY_POWER_NOW"))
98             present_rate = abs(atoi(walk + 1));
99         else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS=Charging"))
100             status = CS_CHARGING;
101         else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS=Full"))
102             status = CS_FULL;
103         else {
104             /* The only thing left is the full capacity */
105             if (last_full_capacity) {
106                 if (!BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_FULL") &&
107                     !BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_FULL"))
108                     continue;
109             } else {
110                 if (!BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_FULL_DESIGN") &&
111                     !BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_FULL_DESIGN"))
112                     continue;
113             }
114
115             full_design = atoi(walk + 1);
116         }
117     }
118
119     /* the difference between POWER_SUPPLY_ENERGY_NOW and
120      * POWER_SUPPLY_CHARGE_NOW is the unit of measurement. The energy is
121      * given in mWh, the charge in mAh. So calculate every value given in
122      * ampere to watt */
123     if (!watt_as_unit) {
124         present_rate = (((float)voltage / 1000.0) * ((float)present_rate / 1000.0));
125
126         if (voltage != -1) {
127             remaining = (((float)voltage / 1000.0) * ((float)remaining / 1000.0));
128             full_design = (((float)voltage / 1000.0) * ((float)full_design / 1000.0));
129         }
130     }
131
132     if ((full_design == -1) || (remaining == -1)) {
133         OUTPUT_FULL_TEXT(format_down);
134         return;
135     }
136
137     (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
138
139     float percentage_remaining = (((float)remaining / (float)full_design) * 100);
140     /* Some batteries report POWER_SUPPLY_CHARGE_NOW=<full_design> when fully
141      * charged, even though that’s plainly wrong. For people who chose to see
142      * the percentage calculated based on the last full capacity, we clamp the
143      * value to 100%, as that makes more sense.
144      * See http://bugs.debian.org/785398 */
145     if (last_full_capacity && percentage_remaining > 100) {
146         percentage_remaining = 100;
147     }
148     if (integer_battery_capacity) {
149         (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00f%%", percentage_remaining);
150     } else {
151         (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%", percentage_remaining);
152     }
153
154     if (present_rate > 0) {
155         float remaining_time;
156         int seconds, hours, minutes, seconds_remaining;
157         if (status == CS_CHARGING)
158             remaining_time = ((float)full_design - (float)remaining) / (float)present_rate;
159         else if (status == CS_DISCHARGING)
160             remaining_time = ((float)remaining / (float)present_rate);
161         else
162             remaining_time = 0;
163
164         seconds_remaining = (int)(remaining_time * 3600.0);
165
166         hours = seconds_remaining / 3600;
167         seconds = seconds_remaining - (hours * 3600);
168         minutes = seconds / 60;
169         seconds -= (minutes * 60);
170
171         if (status == CS_DISCHARGING && low_threshold > 0) {
172             if (strcasecmp(threshold_type, "percentage") == 0 && percentage_remaining < low_threshold) {
173                 START_COLOR("color_bad");
174                 colorful_output = true;
175             } else if (strcasecmp(threshold_type, "time") == 0 && seconds_remaining < 60 * low_threshold) {
176                 START_COLOR("color_bad");
177                 colorful_output = true;
178             } else {
179                 colorful_output = false;
180             }
181         }
182
183         if (hide_seconds)
184             (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d",
185                            max(hours, 0), max(minutes, 0));
186         else
187             (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d:%02d",
188                            max(hours, 0), max(minutes, 0), max(seconds, 0));
189
190         empty_time = time(NULL);
191         empty_time += seconds_remaining;
192         empty_tm = localtime(&empty_time);
193
194         if (hide_seconds)
195             (void)snprintf(emptytimebuf, sizeof(emptytimebuf), "%02d:%02d",
196                            max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0));
197         else
198             (void)snprintf(emptytimebuf, sizeof(emptytimebuf), "%02d:%02d:%02d",
199                            max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0), max(empty_tm->tm_sec, 0));
200
201         (void)snprintf(consumptionbuf, sizeof(consumptionbuf), "%1.2fW",
202                        ((float)present_rate / 1000.0 / 1000.0));
203     } else {
204         /* On some systems, present_rate may not exist. Still, make sure
205          * we colorize the output if threshold_type is set to percentage
206          * (since we don't have any information on remaining time). */
207         if (status == CS_DISCHARGING && low_threshold > 0) {
208             if (strcasecmp(threshold_type, "percentage") == 0 && percentage_remaining < low_threshold) {
209                 START_COLOR("color_bad");
210                 colorful_output = true;
211             }
212         }
213     }
214 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
215     int state;
216     int sysctl_rslt;
217     size_t sysctl_size = sizeof(sysctl_rslt);
218
219     if (sysctlbyname(BATT_LIFE, &sysctl_rslt, &sysctl_size, NULL, 0) != 0) {
220         OUTPUT_FULL_TEXT(format_down);
221         return;
222     }
223
224     present_rate = sysctl_rslt;
225     if (sysctlbyname(BATT_TIME, &sysctl_rslt, &sysctl_size, NULL, 0) != 0) {
226         OUTPUT_FULL_TEXT(format_down);
227         return;
228     }
229
230     remaining = sysctl_rslt;
231     if (sysctlbyname(BATT_STATE, &sysctl_rslt, &sysctl_size, NULL, 0) != 0) {
232         OUTPUT_FULL_TEXT(format_down);
233         return;
234     }
235
236     state = sysctl_rslt;
237     if (state == 0 && present_rate == 100)
238         status = CS_FULL;
239     else if (state == 0 && present_rate < 100)
240         status = CS_CHARGING;
241     else
242         status = CS_DISCHARGING;
243
244     full_design = sysctl_rslt;
245
246     (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
247
248     (void)snprintf(percentagebuf, sizeof(percentagebuf), "%02d%%",
249                    present_rate);
250
251     if (state == 1) {
252         int hours, minutes;
253         minutes = remaining;
254         hours = minutes / 60;
255         minutes -= (hours * 60);
256         (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d",
257                        max(hours, 0), max(minutes, 0));
258         if (strcasecmp(threshold_type, "percentage") == 0 && present_rate < low_threshold) {
259             START_COLOR("color_bad");
260             colorful_output = true;
261         } else if (strcasecmp(threshold_type, "time") == 0 && remaining < (u_int)low_threshold) {
262             START_COLOR("color_bad");
263             colorful_output = true;
264         }
265     }
266 #elif defined(__OpenBSD__)
267     /*
268          * We're using apm(4) here, which is the interface to acpi(4) on amd64/i386 and
269          * the generic interface on macppc/sparc64/zaurus, instead of using sysctl(3) and
270          * probing acpi(4) devices.
271          */
272     struct apm_power_info apm_info;
273     int apm_fd;
274
275     apm_fd = open("/dev/apm", O_RDONLY);
276     if (apm_fd < 0) {
277         OUTPUT_FULL_TEXT("can't open /dev/apm");
278         return;
279     }
280     if (ioctl(apm_fd, APM_IOC_GETPOWER, &apm_info) < 0)
281         OUTPUT_FULL_TEXT("can't read power info");
282
283     close(apm_fd);
284
285     /* Don't bother to go further if there's no battery present. */
286     if ((apm_info.battery_state == APM_BATTERY_ABSENT) ||
287         (apm_info.battery_state == APM_BATT_UNKNOWN)) {
288         OUTPUT_FULL_TEXT(format_down);
289         return;
290     }
291
292     switch (apm_info.ac_state) {
293         case APM_AC_OFF:
294             status = CS_DISCHARGING;
295             break;
296         case APM_AC_ON:
297             status = CS_CHARGING;
298             break;
299         default:
300             /* If we don't know what's going on, just assume we're discharging. */
301             status = CS_DISCHARGING;
302             break;
303     }
304
305     (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
306     /* integer_battery_capacity is implied as battery_life is already in whole numbers. */
307     (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00d%%", apm_info.battery_life);
308
309     if (status == CS_DISCHARGING && low_threshold > 0) {
310         if (strcasecmp(threshold_type, "percentage") == 0 && apm_info.battery_life < low_threshold) {
311             START_COLOR("color_bad");
312             colorful_output = true;
313         } else if (strcasecmp(threshold_type, "time") == 0 && apm_info.minutes_left < (u_int)low_threshold) {
314             START_COLOR("color_bad");
315             colorful_output = true;
316         }
317     }
318
319     /* Can't give a meaningful value for remaining minutes if we're charging. */
320     if (status != CS_CHARGING) {
321         (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d", apm_info.minutes_left / 60, apm_info.minutes_left % 60);
322     } else {
323         (void)snprintf(remainingbuf, sizeof(remainingbuf), "%s", "(CHR)");
324     }
325
326     if (colorful_output)
327         END_COLOR;
328 #elif defined(__NetBSD__)
329     /*
330      * Using envsys(4) via sysmon(4).
331      */
332     int fd, rval, last_full_cap;
333     bool is_found = false;
334     char *sensor_desc;
335     bool is_full = false;
336
337     prop_dictionary_t dict;
338     prop_array_t array;
339     prop_object_iterator_t iter;
340     prop_object_iterator_t iter2;
341     prop_object_t obj, obj2, obj3, obj4, obj5;
342
343     asprintf(&sensor_desc, "acpibat%d", number);
344
345     fd = open("/dev/sysmon", O_RDONLY);
346     if (fd < 0) {
347         OUTPUT_FULL_TEXT("can't open /dev/sysmon");
348         return;
349     }
350
351     rval = prop_dictionary_recv_ioctl(fd, ENVSYS_GETDICTIONARY, &dict);
352     if (rval == -1) {
353         close(fd);
354         return;
355     }
356
357     if (prop_dictionary_count(dict) == 0) {
358         prop_object_release(dict);
359         close(fd);
360         return;
361     }
362
363     iter = prop_dictionary_iterator(dict);
364     if (iter == NULL) {
365         prop_object_release(dict);
366         close(fd);
367     }
368
369     /* iterate over the dictionary returned by the kernel */
370     while ((obj = prop_object_iterator_next(iter)) != NULL) {
371         /* skip this dict if it's not what we're looking for */
372         if ((strlen(prop_dictionary_keysym_cstring_nocopy(obj)) == strlen(sensor_desc)) &&
373             (strncmp(sensor_desc,
374                      prop_dictionary_keysym_cstring_nocopy(obj),
375                      strlen(sensor_desc)) != 0))
376             continue;
377
378         is_found = true;
379
380         array = prop_dictionary_get_keysym(dict, obj);
381         if (prop_object_type(array) != PROP_TYPE_ARRAY) {
382             prop_object_iterator_release(iter);
383             prop_object_release(dict);
384             close(fd);
385             return;
386         }
387
388         iter2 = prop_array_iterator(array);
389         if (!iter2) {
390             prop_object_iterator_release(iter);
391             prop_object_release(dict);
392             close(fd);
393             return;
394         }
395
396         /* iterate over array of dicts specific to target battery */
397         while ((obj2 = prop_object_iterator_next(iter2)) != NULL) {
398             obj3 = prop_dictionary_get(obj2, "description");
399
400             if (obj3 &&
401                 strlen(prop_string_cstring_nocopy(obj3)) == 8 &&
402                 strncmp("charging",
403                         prop_string_cstring_nocopy(obj3),
404                         8) == 0) {
405                 obj3 = prop_dictionary_get(obj2, "cur-value");
406
407                 if (prop_number_integer_value(obj3))
408                     status = CS_CHARGING;
409                 else
410                     status = CS_DISCHARGING;
411
412                 continue;
413             }
414
415             if (obj3 &&
416                 strlen(prop_string_cstring_nocopy(obj3)) == 6 &&
417                 strncmp("charge",
418                         prop_string_cstring_nocopy(obj3),
419                         6) == 0) {
420                 obj3 = prop_dictionary_get(obj2, "cur-value");
421                 obj4 = prop_dictionary_get(obj2, "max-value");
422                 obj5 = prop_dictionary_get(obj2, "type");
423
424                 remaining = prop_number_integer_value(obj3);
425                 full_design = prop_number_integer_value(obj4);
426
427                 if (remaining == full_design)
428                     is_full = true;
429
430                 if (strncmp("Ampere hour",
431                             prop_string_cstring_nocopy(obj5),
432                             11) == 0)
433                     watt_as_unit = false;
434                 else
435                     watt_as_unit = true;
436
437                 continue;
438             }
439
440             if (obj3 &&
441                 strlen(prop_string_cstring_nocopy(obj3)) == 14 &&
442                 strncmp("discharge rate",
443                         prop_string_cstring_nocopy(obj3),
444                         14) == 0) {
445                 obj3 = prop_dictionary_get(obj2, "cur-value");
446                 present_rate = prop_number_integer_value(obj3);
447                 continue;
448             }
449
450             if (obj3 &&
451                 strlen(prop_string_cstring_nocopy(obj3)) == 13 &&
452                 strncmp("last full cap",
453                         prop_string_cstring_nocopy(obj3),
454                         13) == 0) {
455                 obj3 = prop_dictionary_get(obj2, "cur-value");
456                 last_full_cap = prop_number_integer_value(obj3);
457                 continue;
458             }
459
460             if (obj3 &&
461                 strlen(prop_string_cstring_nocopy(obj3)) == 7 &&
462                 strncmp("voltage",
463                         prop_string_cstring_nocopy(obj3),
464                         7) == 0) {
465                 obj3 = prop_dictionary_get(obj2, "cur-value");
466                 voltage = prop_number_integer_value(obj3);
467                 continue;
468             }
469         }
470         prop_object_iterator_release(iter2);
471     }
472
473     prop_object_iterator_release(iter);
474     prop_object_release(dict);
475     close(fd);
476
477     if (!is_found) {
478         OUTPUT_FULL_TEXT(format_down);
479         return;
480     }
481
482     if (last_full_capacity)
483         full_design = last_full_cap;
484
485     if (!watt_as_unit) {
486         present_rate = (((float)voltage / 1000.0) * ((float)present_rate / 1000.0));
487         remaining = (((float)voltage / 1000.0) * ((float)remaining / 1000.0));
488         full_design = (((float)voltage / 1000.0) * ((float)full_design / 1000.0));
489     }
490
491     float percentage_remaining =
492         (((float)remaining / (float)full_design) * 100);
493
494     if (integer_battery_capacity)
495         (void)snprintf(percentagebuf,
496                        sizeof(percentagebuf),
497                        "%d%%",
498                        (int)percentage_remaining);
499     else
500         (void)snprintf(percentagebuf,
501                        sizeof(percentagebuf),
502                        "%.02f%%",
503                        percentage_remaining);
504
505     /*
506      * Handle percentage low_threshold here, and time low_threshold when
507      * we have it.
508      */
509     if (status == CS_DISCHARGING && low_threshold > 0) {
510         if (strcasecmp(threshold_type, "percentage") == 0 && (((float)remaining / (float)full_design) * 100) < low_threshold) {
511             START_COLOR("color_bad");
512             colorful_output = true;
513         }
514     }
515
516     if (is_full)
517         (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(CS_FULL));
518     else
519         (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
520
521     /*
522      * The envsys(4) ACPI routines do not appear to provide a 'time
523      * remaining' figure, so we must deduce it.
524      */
525     float remaining_time;
526     int seconds, hours, minutes, seconds_remaining;
527
528     if (status == CS_CHARGING)
529         remaining_time = ((float)full_design - (float)remaining) / (float)present_rate;
530     else if (status == CS_DISCHARGING)
531         remaining_time = ((float)remaining / (float)present_rate);
532     else
533         remaining_time = 0;
534
535     seconds_remaining = (int)(remaining_time * 3600.0);
536
537     hours = seconds_remaining / 3600;
538     seconds = seconds_remaining - (hours * 3600);
539     minutes = seconds / 60;
540     seconds -= (minutes * 60);
541
542     if (status != CS_CHARGING) {
543         if (hide_seconds)
544             (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d",
545                            max(hours, 0), max(minutes, 0));
546         else
547             (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d:%02d",
548                            max(hours, 0), max(minutes, 0), max(seconds, 0));
549
550         if (low_threshold > 0) {
551             if (strcasecmp(threshold_type, "time") == 0 && ((float)seconds_remaining / 60.0) < (u_int)low_threshold) {
552                 START_COLOR("color_bad");
553                 colorful_output = true;
554             }
555         }
556     } else {
557         if (hide_seconds)
558             (void)snprintf(remainingbuf, sizeof(remainingbuf), "(%02d:%02d until full)",
559                            max(hours, 0), max(minutes, 0));
560         else
561             (void)snprintf(remainingbuf, sizeof(remainingbuf), "(%02d:%02d:%02d until full)",
562                            max(hours, 0), max(minutes, 0), max(seconds, 0));
563     }
564
565     empty_time = time(NULL);
566     empty_time += seconds_remaining;
567     empty_tm = localtime(&empty_time);
568
569     /* No need to show empty time if battery is charging */
570     if (status != CS_CHARGING) {
571         if (hide_seconds)
572             (void)snprintf(emptytimebuf, sizeof(emptytimebuf), "%02d:%02d",
573                            max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0));
574         else
575             (void)snprintf(emptytimebuf, sizeof(emptytimebuf), "%02d:%02d:%02d",
576                            max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0), max(empty_tm->tm_sec, 0));
577     }
578
579     (void)snprintf(consumptionbuf, sizeof(consumptionbuf), "%1.2fW",
580                    ((float)present_rate / 1000.0 / 1000.0));
581 #endif
582
583 #define EAT_SPACE_FROM_OUTPUT_IF_EMPTY(_buf)              \
584     do {                                                  \
585         if (strlen(_buf) == 0) {                          \
586             if (outwalk > buffer && isspace(outwalk[-1])) \
587                 outwalk--;                                \
588             else if (isspace(*(walk + 1)))                \
589                 walk++;                                   \
590         }                                                 \
591     } while (0)
592
593     for (walk = format; *walk != '\0'; walk++) {
594         if (*walk != '%') {
595             *(outwalk++) = *walk;
596             continue;
597         }
598
599         if (BEGINS_WITH(walk + 1, "status")) {
600             outwalk += sprintf(outwalk, "%s", statusbuf);
601             walk += strlen("status");
602         } else if (BEGINS_WITH(walk + 1, "percentage")) {
603             outwalk += sprintf(outwalk, "%s", percentagebuf);
604             walk += strlen("percentage");
605         } else if (BEGINS_WITH(walk + 1, "remaining")) {
606             outwalk += sprintf(outwalk, "%s", remainingbuf);
607             walk += strlen("remaining");
608             EAT_SPACE_FROM_OUTPUT_IF_EMPTY(remainingbuf);
609         } else if (BEGINS_WITH(walk + 1, "emptytime")) {
610             outwalk += sprintf(outwalk, "%s", emptytimebuf);
611             walk += strlen("emptytime");
612             EAT_SPACE_FROM_OUTPUT_IF_EMPTY(emptytimebuf);
613         } else if (BEGINS_WITH(walk + 1, "consumption")) {
614             outwalk += sprintf(outwalk, "%s", consumptionbuf);
615             walk += strlen("consumption");
616             EAT_SPACE_FROM_OUTPUT_IF_EMPTY(consumptionbuf);
617         }
618     }
619
620     if (colorful_output)
621         END_COLOR;
622
623     OUTPUT_FULL_TEXT(buffer);
624 }