OSDN Git Service

Add more tests
authorwifiextender <router@archlinux.info>
Wed, 20 Jul 2016 04:41:17 +0000 (06:41 +0200)
committerwifiextender <router@archlinux.info>
Wed, 20 Jul 2016 04:41:17 +0000 (06:41 +0200)
bootstrap
m4/tests.m4
src/functions.c
src/main.c

index 1a707b5..58fc2e4 100644 (file)
--- a/bootstrap
+++ b/bootstrap
@@ -1,6 +1,7 @@
 #!/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() {
@@ -82,11 +78,11 @@ _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 = \
@@ -126,7 +122,7 @@ EOF
 }
 
 
-[[ -z $1 ]] && _printf_err $@ || {
-    [[ " ${_bases[@]} " =~ " $1 " ]] && \
-        _gen_files $@ || _printf_err $@
+[[ -z "${1}" ]] && _printf_err "$@" || {
+  [[ " ${_bases[@]} " =~ " $1 " ]] && \
+    _gen_files "$@" || _printf_err "$@"
 }
index 6f56370..5bb85c2 100644 (file)
@@ -82,6 +82,7 @@ AC_DEFUN([TEST_TYPEZ],[
 
   CHECK_TYPEZ([
     size_t,
+    time_t,
     float,
     double,
     signed char,
@@ -108,7 +109,7 @@ AC_DEFUN([TEST_TYPEZ],[
     sys/utsname.h    \
     unistd.h         \
   ],[],[
-    ERR([Some header files are missing.])
+    ERR([Missing core header files.])
   ])
 
   AC_CHECK_FUNCS([  \
index 46d3079..3765ee6 100644 (file)
@@ -233,44 +233,43 @@ void get_voltage(char *str1) {
 }
 
 
-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, "));
+  }
 }
 
 
@@ -337,12 +336,18 @@ void get_volume(char *str1) {
 }
 
 
-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);
 }
index 5060da6..a0d43b7 100644 (file)
@@ -27,8 +27,7 @@
 #include "constants1.h"
 #include "functions.h"
 
-int main(void)
-{
+int main(void) {
   struct timespec tc = {0};
   tc.tv_nsec = sysconf(_SC_CLK_TCK) * 1000000L;