25
25
#include <getopt.h>
28
static void do_show_batteries(char *acpi_path, int show_empty_slots)/*{{{*/
28
struct device device[4] = {
29
{ BATTERY, "battery", "power_supply", "BAT" },
30
{ AC_ADAPTER, "ac_adapter", "power_supply", "AC" },
31
{ THERMAL_ZONE, "thermal_zone", "thermal", "thermal_zone" },
32
{ COOLING_DEV, "fan", "thermal", "cooling_device" }
35
static void do_show_batteries(char *acpi_path, int show_empty_slots, int proc_interface)
30
37
struct list *batteries;
32
batteries = find_devices(acpi_path, "battery", TRUE);
39
batteries = find_devices(acpi_path, BATTERY, proc_interface);
33
40
print_battery_information(batteries, show_empty_slots);
34
41
free_devices(batteries);
37
static void do_show_thermal(char *acpi_path, int show_empty_slots, int temperature_units) {/*{{{*/
44
static void do_show_ac_adapter(char *acpi_path, int show_empty_slots, int proc_interface)
46
struct list *ac_adapter;
48
ac_adapter = find_devices(acpi_path, AC_ADAPTER, proc_interface);
49
print_ac_adapter_information(ac_adapter, show_empty_slots);
50
free_devices(ac_adapter);
53
static void do_show_thermal(char *acpi_path, int show_empty_slots, int temperature_units, int proc_interface) {
38
54
struct list *thermal;
39
thermal = find_devices(acpi_path, "thermal_zone", FALSE);
41
/* old acpi directory structure */
42
thermal = find_devices(acpi_path, "thermal", TRUE);
56
thermal = find_devices(acpi_path, THERMAL_ZONE, proc_interface);
44
57
print_thermal_information(thermal, show_empty_slots, temperature_units);
45
58
free_devices(thermal);
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);
61
static void do_show_cooling(char *acpi_path, int show_empty_slots, int proc_interface) {
64
cooling = find_devices(acpi_path, COOLING_DEV, proc_interface);
65
print_cooling_information(cooling, show_empty_slots);
66
free_devices(cooling);
56
static int version(void)/*{{{*/
69
static int version(void)
58
71
printf(ACPI_VERSION_STRING "\n"
60
73
"Copyright (C) 2001 Grahame Bowland.\n"
74
" 2008 Michael Meskes.\n"
61
75
"This is free software; see the source for copying conditions. There is NO\n"
62
76
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
67
static int usage(char *argv[])/*{{{*/
81
static int usage(char *argv[])
70
84
"Usage: acpi [OPTION]...\n"
71
85
"Shows information from the /proc filesystem, such as battery status or\n"
72
86
"thermal information.\n"
74
" -b, --battery battery information\n"
88
" -b, --battery battery information\n"
75
89
" -B, --without-battery suppress battery information\n"
76
" -t, --thermal thermal information\n"
90
" -a, --ac-adapter ac adapter information\n"
91
" -A, --without-ac-adapter suppress ac-adapter information\n"
92
" -t, --thermal thermal information\n"
77
93
" -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"
94
" -c, --cooling cooling information\n"
95
" -C, --without-cooling suppress cooling information\n"
96
" -V, --everything show every device, overrides above options\n"
97
" -s, --show-empty show non-operational devices\n"
98
" -S, --hide-empty hide non-operational devices\n"
99
" -f, --fahrenheit use fahrenheit as the temperature unit\n"
100
" -k, --kelvin use kelvin as the temperature unit\n"
101
" -d, --directory <dir> path to ACPI info (/sys/class resp. /proc/acpi)\n"
102
" -p, --proc use old proc interface instead of new sys interface\n"
103
" -h, --help display this help and exit\n"
104
" -v, --version output version information and exit\n"
90
106
"By default, acpi displays information on installed system batteries.\n"
91
107
"Non-operational devices, for example empty battery slots are hidden.\n"
92
108
"The default unit of temperature is degrees celsius.\n"
94
"Report bugs to Grahame Bowland <grahame@angrygoats.net>.\n"
110
"Report bugs to Michael Meskes <meskes@debian.org>.\n"
99
static struct option long_options[] = {/*{{{*/
115
static struct option long_options[] = {
100
116
{ "help", 0, 0, 'h' },
101
117
{ "version", 0, 0, 'v' },
102
118
{ "verbose", 0, 0, 'V' },
103
119
{ "battery", 0, 0, 'b' },
104
120
{ "without-battery", 0, 0, 'B' },
121
{ "ac-adapter", 0, 0, 'a' },
122
{ "without-ac-adapter", 0, 0, 'A' },
105
123
{ "thermal", 0, 0, 't' },
106
124
{ "without-thermal", 0, 0, 'T' },
107
{ "ac-adapter", 0, 0, 'a' },
108
{ "without-ac-adapter", 0, 0, 'A' },
125
{ "cooling", 0, 0, 'c' },
126
{ "without-cooling", 0, 0, 'C' },
109
127
{ "show-empty", 0, 0, 's' },
110
128
{ "hide-empty", 0, 0, 'S' },
111
{ "celcius", 0, 0, 'c' },
112
{ "celsius", 0, 0, 'c' },
113
129
{ "fahrenheit", 0, 0, 'f' },
114
130
{ "kelvin", 0, 0, 'k' },
115
131
{ "directory", 1, 0, 'd' },
116
132
{ "everything", 0, 0, 'V' },
133
{ "proc", 0, 0, 'p' },
120
int main(int argc, char *argv[])/*{{{*/
137
int main(int argc, char *argv[])
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;
139
int show_batteries = TRUE;
140
int show_ac_adapter = FALSE;
141
int show_thermal = FALSE;
142
int show_cooling = FALSE;
143
int show_empty_slots = FALSE;
144
int proc_interface = FALSE;
127
145
int temperature_units = TEMP_CELSIUS;
128
146
int ch, option_index;
129
char *acpi_path = strdup(ACPI_PATH);
147
char *acpi_path = strdup(ACPI_PATH_SYS);
131
149
if (!acpi_path) {
132
150
fprintf(stderr, "Out of memory in main()\n");
136
while ((ch = getopt_long(argc, argv, "VbBtTaAsShvfkcd:", long_options, &option_index)) != -1) {
154
while ((ch = getopt_long(argc, argv, "pVbBtTaAsShvfkcCd:", long_options, &option_index)) != -1) {
157
show_batteries = show_ac_adapter = show_thermal = show_cooling = TRUE;
160
show_batteries = TRUE;
163
show_batteries = FALSE;
166
show_ac_adapter = TRUE;
169
show_ac_adapter = FALSE;
175
show_thermal = FALSE;
181
show_cooling = FALSE;
160
show_empty_slots = 1;
184
show_empty_slots = TRUE;
163
show_empty_slots = 0;
187
show_empty_slots = FALSE;
166
190
return version();