Skip to content
Browse files

Update commenting, update CFLAGS

  • Loading branch information...
1 parent 5d0f713 commit 7426a7d3cf709ead195c44b65cb9589c451c6fa8 Chris Down committed
Showing with 31 additions and 40 deletions.
  1. +5 −6 Makefile
  2. +26 −34 cellout.c
View
11 Makefile
@@ -2,12 +2,11 @@
PREFIX ?= .
CFLAGS := -ansi -pedantic -Wall -Wextra -Werror \
- -Wno-missing-braces -Wno-missing-field-initializers -Wformat=2 \
- -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith \
- -Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Winline \
- -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code \
- -Wlogical-op -Wfloat-equal -Wstrict-aliasing=2 -Wredundant-decls \
- -Wold-style-definition \
+ -Wformat=2 -Wswitch-default -Wswitch-enum -Wcast-align \
+ -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 \
+ -Wstrict-prototypes -Winline -Wundef -Wnested-externs -Wcast-qual \
+ -Wshadow -Wunreachable-code -Wlogical-op -Wfloat-equal \
+ -Wstrict-aliasing=2 -Wredundant-decls -Wold-style-definition \
${CFLAGS}
cellout: cellout.c
View
60 cellout.c
@@ -1,3 +1,7 @@
+/* (c) Christopher Down 2011
+ * See the COPYING file for copyright information.
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -8,8 +12,7 @@
#define CHARGE_FULL_FILENAME "charge_full"
#define STATUS_FILENAME "status"
-int main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
char status_filename[BUFFER_SIZE],
charge_now_filename[BUFFER_SIZE],
charge_full_filename[BUFFER_SIZE],
@@ -28,21 +31,16 @@ int main(int argc, char *argv[])
*f_status;
battery_found = 0;
- for (arg = 1 ; arg < argc ; arg++)
- {
+ for (arg = 1 ; arg < argc ; arg++) {
if (!strncmp(argv[arg], "-g", 3))
- {
show_graphic = 1;
- }
- else
- {
+ else {
battery_found = 1;
strncpy(battery, argv[arg], BUFFER_SIZE - 1);
}
}
- if (!battery_found)
- {
+ if (!battery_found) {
fputs("Usage: cellout [-g] battery\n", stderr);
exit(1);
}
@@ -60,44 +58,38 @@ int main(int argc, char *argv[])
strcat(charge_now_filename, "/"CHARGE_NOW_FILENAME);
strcat(status_filename, "/"STATUS_FILENAME);
- if ((f_status = fopen(status_filename, "r")) == NULL)
- {
- fprintf(stderr, "Failed to open %s\n", status_filename);
+ if ((f_charge_full = fopen(charge_full_filename, "r")) == NULL) {
+ fprintf(stderr, "Failed to open %s\n", charge_full_filename);
exit(2);
}
- if ((f_charge_now = fopen(charge_now_filename, "r")) == NULL)
- {
+ if ((f_charge_now = fopen(charge_now_filename, "r")) == NULL) {
fprintf(stderr, "Failed to open %s\n", charge_now_filename);
exit(2);
}
- if ((f_charge_full = fopen(charge_full_filename, "r")) == NULL)
- {
- fprintf(stderr, "Failed to open %s\n", charge_full_filename);
+ if ((f_status = fopen(status_filename, "r")) == NULL) {
+ fprintf(stderr, "Failed to open %s\n", status_filename);
exit(2);
}
- if (fgets(charge_now, BUFFER_SIZE, f_charge_now) == NULL)
- fprintf(stderr, "Failed to get line from %s\n", charge_now_filename);
if (fgets(charge_full, BUFFER_SIZE, f_charge_full) == NULL)
fprintf(stderr, "Failed to get line from %s\n", charge_full_filename);
-
+ if (fgets(charge_now, BUFFER_SIZE, f_charge_now) == NULL)
+ fprintf(stderr, "Failed to get line from %s\n", charge_now_filename);
if ((status = fgetc(f_status)) == EOF)
fprintf(stderr, "Failed to get character from %s\n", status_filename);
-
- charge_now[strlen(charge_now)-1] = '\0';
+
charge_full[strlen(charge_full)-1] = '\0';
+ charge_now[strlen(charge_now)-1] = '\0';
/* TODO: atoi() error checking (should be fine since /proc is not directly
* editable (and thus should prevent stupid stuff), but nevertheless...
*/
charge_percentage = atoi(charge_now) * 100 / atoi(charge_full);
- if (show_graphic == 1)
- {
+ if (show_graphic == 1) {
charge_percentage_graphic[0] = '\0';
- for (i = 25; i <= 100; i += 25)
- {
+ for (i = 25; i <= 100; i += 25) {
if (charge_percentage >= i)
strcat(charge_percentage_graphic, "#");
else
@@ -105,11 +97,11 @@ int main(int argc, char *argv[])
}
printf("[%s] %d%c\n", charge_percentage_graphic, charge_percentage,
status);
- }
- else
+ } else
printf("%d%c\n", charge_percentage, status);
- /* We don't want to exit on failure to close. We don't write anything, so it
+ /*
+ * We don't want to exit on failure to close. We don't write anything, so it
* should be fine, but we should still bring it to the attention of the
* user.
*
@@ -119,12 +111,12 @@ int main(int argc, char *argv[])
* be such a rare occurrence that we don't really have to worry about it for
* now.
*/
- if (fclose(f_status) == EOF)
- perror(status_filename);
- if (fclose(f_charge_now) == EOF)
- perror(charge_now_filename);
if (fclose(f_charge_full) == EOF)
perror(charge_full_filename);
+ if (fclose(f_charge_now) == EOF)
+ perror(charge_now_filename);
+ if (fclose(f_status) == EOF)
+ perror(status_filename);
return EXIT_SUCCESS;
}

0 comments on commit 7426a7d

Please sign in to comment.
Something went wrong with that request. Please try again.