28
28
static void do_show_batteries(char *acpi_path, int show_empty_slots)/*{{{*/
30
struct list *batteries;
30
struct list *batteries;
32
batteries = find_devices(acpi_path, "battery", TRUE);
33
print_battery_information(batteries, show_empty_slots);
34
free_devices(batteries);
32
batteries = find_devices(acpi_path, "battery", TRUE);
33
print_battery_information(batteries, show_empty_slots);
34
free_devices(batteries);
37
37
static void do_show_thermal(char *acpi_path, int show_empty_slots, int temperature_units) {/*{{{*/
39
thermal = find_devices(acpi_path, "thermal_zone", FALSE);
41
/* old acpi directory structure */
42
thermal = find_devices(acpi_path, "thermal", TRUE);
44
print_thermal_information(thermal, show_empty_slots, temperature_units);
45
free_devices(thermal);
39
thermal = find_devices(acpi_path, "thermal_zone", FALSE);
41
/* old acpi directory structure */
42
thermal = find_devices(acpi_path, "thermal", TRUE);
44
print_thermal_information(thermal, show_empty_slots, temperature_units);
45
free_devices(thermal);
48
48
static void do_show_ac_adapter(char *acpi_path, int show_empty_slots)/*{{{*/
50
struct list *ac_adapter;
51
ac_adapter = find_devices(acpi_path, "ac_adapter", TRUE);
52
print_ac_adapter_information(ac_adapter, show_empty_slots);
53
free_devices(ac_adapter);
50
struct list *ac_adapter;
51
ac_adapter = find_devices(acpi_path, "ac_adapter", TRUE);
52
print_ac_adapter_information(ac_adapter, show_empty_slots);
53
free_devices(ac_adapter);
56
56
static int version(void)/*{{{*/
58
printf(ACPI_VERSION_STRING "\n"
58
printf(ACPI_VERSION_STRING "\n"
60
60
"Copyright (C) 2001 Grahame Bowland.\n"
61
61
"This is free software; see the source for copying conditions. There is NO\n"
62
62
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
67
67
static int usage(char *argv[])/*{{{*/
70
70
"Usage: acpi [OPTION]...\n"
71
71
"Shows information from the /proc filesystem, such as battery status or\n"
72
72
"thermal information.\n"
74
" -b, --battery battery information\n"
75
" -B, --without-battery suppress battery information\n"
76
" -t, --thermal thermal information\n"
77
" -T, --without-thermal suppress thermal information\n"
78
" -a, --ac-adapter ac adapter information\n"
79
" -A, --without-ac-adapter suppress ac-adapter information\n"
80
" -V, --everything show every device, overrides above options\n"
81
" -s, --show-empty show non-operational devices\n"
82
" -S, --hide-empty hide non-operational devices\n"
83
" -c, --celcius use celcius as the temperature unit\n"
84
" -f, --fahrenheit use fahrenheit as the temperature unit\n"
85
" -k, --kelvin use kelvin as the temperature unit\n"
86
" -d, --directory <dir> path to ACPI info (/proc/acpi)\n"
87
" -h, --help display this help and exit\n"
88
" -v, --version output version information and exit\n"
74
" -b, --battery battery information\n"
75
" -B, --without-battery suppress battery information\n"
76
" -t, --thermal thermal information\n"
77
" -T, --without-thermal suppress thermal information\n"
78
" -a, --ac-adapter ac adapter information\n"
79
" -A, --without-ac-adapter suppress ac-adapter information\n"
80
" -V, --everything show every device, overrides above options\n"
81
" -s, --show-empty show non-operational devices\n"
82
" -S, --hide-empty hide non-operational devices\n"
83
" -c, --celsius use celsius as the temperature unit\n"
84
" -f, --fahrenheit use fahrenheit as the temperature unit\n"
85
" -k, --kelvin use kelvin as the temperature unit\n"
86
" -d, --directory <dir> path to ACPI info (/proc/acpi)\n"
87
" -h, --help display this help and exit\n"
88
" -v, --version output version information and exit\n"
90
90
"By default, acpi displays information on installed system batteries.\n"
91
91
"Non-operational devices, for example empty battery slots are hidden.\n"
92
"The default unit of temperature is degrees celcius.\n"
92
"The default unit of temperature is degrees celsius.\n"
94
94
"Report bugs to Grahame Bowland <grahame@angrygoats.net>.\n"
99
99
static struct option long_options[] = {/*{{{*/
100
{ "help", 0, 0, 'h' },
101
{ "version", 0, 0, 'v' },
102
{ "verbose", 0, 0, 'V' },
103
{ "battery", 0, 0, 'b' },
104
{ "without-battery", 0, 0, 'B' },
105
{ "thermal", 0, 0, 't' },
106
{ "without-thermal", 0, 0, 'T' },
107
{ "ac-adapter", 0, 0, 'a' },
108
{ "without-ac-adapter", 0, 0, 'A' },
109
{ "show-empty", 0, 0, 's' },
110
{ "hide-empty", 0, 0, 'S' },
111
{ "celcius", 0, 0, 'c' },
112
{ "fahrenheit", 0, 0, 'f' },
113
{ "kelvin", 0, 0, 'k' },
114
{ "directory", 1, 0, 'd' },
115
{ "everything", 0, 0, 'V' },
100
{ "help", 0, 0, 'h' },
101
{ "version", 0, 0, 'v' },
102
{ "verbose", 0, 0, 'V' },
103
{ "battery", 0, 0, 'b' },
104
{ "without-battery", 0, 0, 'B' },
105
{ "thermal", 0, 0, 't' },
106
{ "without-thermal", 0, 0, 'T' },
107
{ "ac-adapter", 0, 0, 'a' },
108
{ "without-ac-adapter", 0, 0, 'A' },
109
{ "show-empty", 0, 0, 's' },
110
{ "hide-empty", 0, 0, 'S' },
111
{ "celcius", 0, 0, 'c' },
112
{ "celsius", 0, 0, 'c' },
113
{ "fahrenheit", 0, 0, 'f' },
114
{ "kelvin", 0, 0, 'k' },
115
{ "directory", 1, 0, 'd' },
116
{ "everything", 0, 0, 'V' },
119
120
int main(int argc, char *argv[])/*{{{*/
121
int show_everything = 0;
122
int show_batteries = 1;
123
int show_thermal = 0;
124
int show_ac_adapter = 0;
125
int show_empty_slots = 0;
126
int temperature_units = TEMP_CELCIUS;
127
int ch, option_index;
128
char *acpi_path = strdup(ACPI_PATH);
131
fprintf(stderr, "Out of memory in main()\n");
135
while ((ch = getopt_long(argc, argv, "VbBtTaAsShvfkcd:", long_options, &option_index)) != -1) {
159
show_empty_slots = 1;
162
show_empty_slots = 0;
168
temperature_units = TEMP_FAHRENHEIT;
171
temperature_units = TEMP_KELVIN;
174
temperature_units = TEMP_CELCIUS;
178
acpi_path = strdup(optarg);
180
fprintf(stderr, "Out of memory in main()\n");
190
if (show_everything || show_batteries) {
191
do_show_batteries(acpi_path, show_empty_slots);
193
if (show_everything || show_thermal) {
194
do_show_thermal(acpi_path, show_empty_slots, temperature_units);
196
if (show_everything || show_ac_adapter) {
197
do_show_ac_adapter(acpi_path, show_empty_slots);
122
int show_everything = 0;
123
int show_batteries = 1;
124
int show_thermal = 0;
125
int show_ac_adapter = 0;
126
int show_empty_slots = 0;
127
int temperature_units = TEMP_CELSIUS;
128
int ch, option_index;
129
char *acpi_path = strdup(ACPI_PATH);
132
fprintf(stderr, "Out of memory in main()\n");
136
while ((ch = getopt_long(argc, argv, "VbBtTaAsShvfkcd:", long_options, &option_index)) != -1) {
160
show_empty_slots = 1;
163
show_empty_slots = 0;
169
temperature_units = TEMP_FAHRENHEIT;
172
temperature_units = TEMP_KELVIN;
175
temperature_units = TEMP_CELSIUS;
179
acpi_path = strdup(optarg);
181
fprintf(stderr, "Out of memory in main()\n");
191
if (show_everything || show_batteries) {
192
do_show_batteries(acpi_path, show_empty_slots);
194
if (show_everything || show_thermal) {
195
do_show_thermal(acpi_path, show_empty_slots, temperature_units);
197
if (show_everything || show_ac_adapter) {
198
do_show_ac_adapter(acpi_path, show_empty_slots);