~ubuntu-branches/ubuntu/edgy/acpi/edgy

« back to all changes in this revision

Viewing changes to main.c

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2005-04-13 14:39:43 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050413143943-27nitf6i1ibhcfkd
Tags: 0.09-1
* New upstream release:
  - Deal with missing discharge or charging rates. Closes: #226306
  - Better handling of "unknown" "charging rate" and "present state" fields.
    Closes: #169351
  - BugFree(TM) !
* Corrected messed up version number in last changelog entry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
static void do_show_batteries(char *acpi_path, int show_empty_slots)/*{{{*/
29
29
{
30
 
    struct list *batteries;
 
30
        struct list *batteries;
31
31
 
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);
35
35
}
36
36
 
37
37
static void do_show_thermal(char *acpi_path, int show_empty_slots, int temperature_units) {/*{{{*/
38
 
    struct list *thermal;
39
 
    thermal = find_devices(acpi_path, "thermal_zone", FALSE);
40
 
    if (!thermal) {
41
 
        /* old acpi directory structure */
42
 
        thermal = find_devices(acpi_path, "thermal", TRUE); 
43
 
    }
44
 
    print_thermal_information(thermal, show_empty_slots, temperature_units);
45
 
    free_devices(thermal);
 
38
        struct list *thermal;
 
39
        thermal = find_devices(acpi_path, "thermal_zone", FALSE);
 
40
        if (!thermal) {
 
41
                /* old acpi directory structure */
 
42
                thermal = find_devices(acpi_path, "thermal", TRUE); 
 
43
        }
 
44
        print_thermal_information(thermal, show_empty_slots, temperature_units);
 
45
        free_devices(thermal);
46
46
}
47
47
 
48
48
static void do_show_ac_adapter(char *acpi_path, int show_empty_slots)/*{{{*/
49
49
{
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);
54
54
}
55
55
 
56
56
static int version(void)/*{{{*/
57
57
{
58
 
    printf(ACPI_VERSION_STRING "\n"
 
58
        printf(ACPI_VERSION_STRING "\n"
59
59
"\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"
63
63
);
64
 
    return 1;
 
64
        return 1;
65
65
}
66
66
 
67
67
static int usage(char *argv[])/*{{{*/
68
68
{
69
 
    printf(
 
69
        printf(
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"
73
73
"\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"
89
89
"\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"
93
93
"\n"
94
94
"Report bugs to Grahame Bowland <grahame@angrygoats.net>.\n"
95
95
);
96
 
    return 1;
 
96
        return 1;
97
97
}
98
98
 
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' }, 
116
 
    { 0, 0, 0, 0 }, 
 
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' }, 
 
117
        { 0, 0, 0, 0 }, 
117
118
};
118
119
 
119
120
int main(int argc, char *argv[])/*{{{*/
120
121
{
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);
129
 
 
130
 
    if (!acpi_path) {
131
 
        fprintf(stderr, "Out of memory in main()\n");
132
 
        return -1;
133
 
    }
134
 
 
135
 
    while ((ch = getopt_long(argc, argv, "VbBtTaAsShvfkcd:", long_options, &option_index)) != -1) {
136
 
        switch (ch) {
137
 
            case 'V':
138
 
                show_everything = 1;
139
 
                break;
140
 
            case 'b':
141
 
                show_batteries = 1;
142
 
                break;
143
 
            case 'B':
144
 
                show_batteries = 0;
145
 
                break;
146
 
            case 't':
147
 
                show_thermal = 1;
148
 
                break;
149
 
            case 'T':
150
 
                show_thermal = 0;
151
 
                break;
152
 
            case 'a':
153
 
                show_ac_adapter = 1;
154
 
                break;
155
 
            case 'A':
156
 
                show_ac_adapter = 0;
157
 
                break;
158
 
            case 's':
159
 
                show_empty_slots = 1;
160
 
                break;
161
 
            case 'S':
162
 
                show_empty_slots = 0;
163
 
                break;
164
 
            case 'v':
165
 
                return version();
166
 
                break;
167
 
            case 'f':
168
 
                temperature_units = TEMP_FAHRENHEIT;
169
 
                break;
170
 
            case 'k':
171
 
                temperature_units = TEMP_KELVIN;
172
 
                break;
173
 
            case 'c':
174
 
                temperature_units = TEMP_CELCIUS;
175
 
                break;
176
 
            case 'd':
177
 
                free(acpi_path);
178
 
                acpi_path = strdup(optarg);
179
 
                if (!acpi_path) {
180
 
                    fprintf(stderr, "Out of memory in main()\n");
181
 
                    return -1;
182
 
                }
183
 
                break;
184
 
            case 'h':
185
 
            default:
186
 
                return usage(argv);
187
 
        }
188
 
    }
189
 
 
190
 
    if (show_everything || show_batteries) {
191
 
        do_show_batteries(acpi_path, show_empty_slots);
192
 
    }
193
 
    if (show_everything || show_thermal) {
194
 
        do_show_thermal(acpi_path, show_empty_slots, temperature_units);
195
 
    }
196
 
    if (show_everything || show_ac_adapter) {
197
 
        do_show_ac_adapter(acpi_path, show_empty_slots);
198
 
    }
199
 
    return 0;
 
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);
 
130
 
 
131
        if (!acpi_path) {
 
132
                fprintf(stderr, "Out of memory in main()\n");
 
133
                return -1;
 
134
        }
 
135
 
 
136
        while ((ch = getopt_long(argc, argv, "VbBtTaAsShvfkcd:", long_options, &option_index)) != -1) {
 
137
                switch (ch) {
 
138
                        case 'V':
 
139
                                show_everything = 1;
 
140
                                break;
 
141
                        case 'b':
 
142
                                show_batteries = 1;
 
143
                                break;
 
144
                        case 'B':
 
145
                                show_batteries = 0;
 
146
                                break;
 
147
                        case 't':
 
148
                                show_thermal = 1;
 
149
                                break;
 
150
                        case 'T':
 
151
                                show_thermal = 0;
 
152
                                break;
 
153
                        case 'a':
 
154
                                show_ac_adapter = 1;
 
155
                                break;
 
156
                        case 'A':
 
157
                                show_ac_adapter = 0;
 
158
                                break;
 
159
                        case 's':
 
160
                                show_empty_slots = 1;
 
161
                                break;
 
162
                        case 'S':
 
163
                                show_empty_slots = 0;
 
164
                                break;
 
165
                        case 'v':
 
166
                                return version();
 
167
                                break;
 
168
                        case 'f':
 
169
                                temperature_units = TEMP_FAHRENHEIT;
 
170
                                break;
 
171
                        case 'k':
 
172
                                temperature_units = TEMP_KELVIN;
 
173
                                break;
 
174
                        case 'c':
 
175
                                temperature_units = TEMP_CELSIUS;
 
176
                                break;
 
177
                        case 'd':
 
178
                                free(acpi_path);
 
179
                                acpi_path = strdup(optarg);
 
180
                                if (!acpi_path) {
 
181
                                        fprintf(stderr, "Out of memory in main()\n");
 
182
                                        return -1;
 
183
                                }
 
184
                                break;
 
185
                        case 'h':
 
186
                        default:
 
187
                                return usage(argv);
 
188
                }
 
189
        }
 
190
 
 
191
        if (show_everything || show_batteries) {
 
192
                do_show_batteries(acpi_path, show_empty_slots);
 
193
        }
 
194
        if (show_everything || show_thermal) {
 
195
                do_show_thermal(acpi_path, show_empty_slots, temperature_units);
 
196
        }
 
197
        if (show_everything || show_ac_adapter) {
 
198
                do_show_ac_adapter(acpi_path, show_empty_slots);
 
199
        }
 
200
        return 0;
200
201
}
201
202