#!/usr/bin/env bash
-# Copyright 07/06/2015 Aaron Caffrey https://github.com/wifiextender
+# Copyright 07/06/2015, 07/18/2016
+# Aaron Caffrey https://github.com/wifiextender
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# MA 02110-1301, USA.
-# bash bootstrap archlinux
-# ./configure --prefix=$HOME/.cache
-# make && make install
-
-declare -a _bases
-_bases=(
- 'archlinux'
- 'debian'
- 'gentoo'
- 'slackware'
- 'rhel'
- 'frugalware'
- 'angstrom'
+declare -a _bases=(
+ 'archlinux'
+ 'debian'
+ 'gentoo'
+ 'slackware'
+ 'rhel'
+ 'frugalware'
+ 'angstrom'
)
_printf_err() {
- printf '%s\n' "try again with: bash ${0} basedistro"
- printf '%s ' "Bases: ${_bases[@]}"
- printf '\n'
+ printf '%s\n' "try again with: bash ${0} basedistro"
+ printf '%s ' "Bases: ${_bases[@]}"
+ printf '\n'
}
_gen_files() {
# src/Makefile.am
src_files=(
- 'main.c'
- 'functions.c'
- 'functions.h'
- 'constants1.h'
- 'constants2.h'
+ 'main.c'
+ 'functions.c'
+ 'functions.h'
+ 'constants1.h'
+ 'constants2.h'
)
src_makefile=('AM_CPPFLAGS = \
}
-[[ -z $1 ]] && _printf_err $@ || {
- [[ " ${_bases[@]} " =~ " $1 " ]] && \
- _gen_files $@ || _printf_err $@
+[[ -z "${1}" ]] && _printf_err "$@" || {
+ [[ " ${_bases[@]} " =~ " $1 " ]] && \
+ _gen_files "$@" || _printf_err "$@"
}
}
-void get_fans(char *str1)
-{
- FILE *fp;
- bool found_fans = true;
- char tempstr[VLA], buffer[VLA];
- char *all_fans = buffer;
- uint_fast16_t x = 0, y = 0, z = 0, rpm[21];
-
- for (x = 1; x < 20; x++, z++) {
- FILL_ARR(tempstr, HWMON_DIR"/fan"UFINT"_input", x);
-
- if (!(fp = fopen(tempstr, "r")) && x > 1)
- break;
- else if (NULL == fp) { /* no system fans */
- FILL_STR_ARR(1, str1, "Not found, ");
- found_fans = false;
- break;
- }
-
- fscanf(fp, UFINT, &rpm[z]);
- fclose(fp);
+void get_fans(char *str1) {
+ FILE *fp;
+ bool found_fans = true;
+ char tempstr[VLA], buffer[VLA];
+ char *all_fans = buffer;
+ uint_fast16_t x = 0, y = 0, z = 0, rpm[21];
+
+ for (x = 1; x < 20; x++, z++) {
+ FILL_ARR(tempstr, HWMON_DIR"/fan"UFINT"_input", x);
+
+ if (!(fp = fopen(tempstr, "r")) && x > 1)
+ break;
+ else if (NULL == fp) { /* no system fans */
+ FILL_STR_ARR(1, str1, "Not found, ");
+ found_fans = false;
+ break;
}
- if (found_fans) {
- for (x = 0; x < z; x++) {
- if (rpm[x] > 0)
- all_fans += snprintf(all_fans,
- sizeof(buffer) - (uint_least32_t)(all_fans - buffer),
- UFINT" ", rpm[x]);
-
- else {/* Don't include non-spinning or removed fans */
- ++y;
- all_fans += snprintf(all_fans, 5, "%s", "");
- }
- }
+ fscanf(fp, UFINT, &rpm[z]);
+ fclose(fp);
+ }
- FILL_STR_ARR(1, str1, (y != x ? buffer : "Not found, "));
+ if (found_fans) {
+ for (x = 0; x < z; x++) {
+ if (rpm[x] > 0)
+ all_fans += snprintf(all_fans,
+ sizeof(buffer) - (uint_least32_t)(all_fans - buffer),
+ UFINT" ", rpm[x]);
+
+ else {/* Don't include non-spinning or removed fans */
+ ++y;
+ all_fans += snprintf(all_fans, 5, "%s", "");
+ }
}
+
+ FILL_STR_ARR(1, str1, (y != x ? buffer : "Not found, "));
+ }
}
}
-void get_time(char *str1)
-{
+/* The `strftime' man page showed potential bugs */
+void get_time(char *str1) {
char time_str[VLA];
- time_t t = time(NULL);
+ time_t t;
+ struct tm *taim;
- strftime(time_str, VLA, "%I:%M %p", localtime(&t));
+ if (-1 == (t = time(NULL)) ||
+ NULL == (taim = localtime(&t)) ||
+ 0 == (strftime(time_str, VLA, "%I:%M %p", taim))) {
+ ERR("Error:","time() or localtime() or strftime() failed");
+ exit(EXIT_FAILURE);
+ }
FILL_STR_ARR(1, str1, time_str);
}