summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xMakefile12
-rwxr-xr-xbuild.sh7
-rwxr-xr-xconfig.mk39
-rw-r--r--main.c81
4 files changed, 139 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100755
index 0000000..b7b585e
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,12 @@
+# Big kram's stats app
+#clear ; vim main.c ; gcc main.c -Wall -Wextra -Wpedantic -std=c99 -o stats
+
+CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os
+
+CC = tcc
+
+
+all:
+ ${CC} ${CFLAGS} main.c -o stats
+
+.PHONY: all clean dist install uninstall
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..cfe5ef0
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+clear
+
+vim main.c
+
+make
diff --git a/config.mk b/config.mk
new file mode 100755
index 0000000..982dc21
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,39 @@
+# dwm version
+VERSION = 6.8
+
+# Customize below to fit your system
+
+# paths
+PREFIX = /usr/local
+MANPREFIX = ${PREFIX}/share/man
+
+X11INC = /usr/X11R6/include
+X11LIB = /usr/X11R6/lib
+
+# Xinerama, comment if you don't want it
+XINERAMALIBS = -lXinerama
+XINERAMAFLAGS = -DXINERAMA
+
+# freetype
+FREETYPELIBS = -lfontconfig -lXft
+FREETYPEINC = /usr/include/freetype2
+# OpenBSD (uncomment)
+#FREETYPEINC = ${X11INC}/freetype2
+#MANPREFIX = ${PREFIX}/man
+
+# includes and libs
+INCS = -I${X11INC} -I${FREETYPEINC}
+LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS}
+
+# flags
+CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
+#CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
+CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os ${INCS} ${CPPFLAGS}
+LDFLAGS = ${LIBS}
+
+# Solaris
+#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
+#LDFLAGS = ${LIBS}
+
+# compiler and linker
+CC = cc
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..0c90732
--- /dev/null
+++ b/main.c
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+/* Enums make words into numbers, ergo no magic numbers */
+enum MODE {
+ MODE_MAX,
+ MODE_MIN,
+ MODE_DIFF
+};
+
+void help(){
+ printf("Usage: stats <numbers>\n");
+ exit(1);
+}
+
+/* ADDING UP ALL THE VALUES */
+int sigma(int argc, char * argv[]) {
+ char *endptr;
+ int sum = 0;
+
+ for (int i = 1; i < argc; i++) {
+
+ sum += strtol(argv[i], &endptr, 10); /* convert the value to an integer and add it on */
+ if (endptr == argv[i] || *endptr != '\0') {
+ help();
+ }
+
+ }
+ return sum;
+}
+
+/* FINDING MEAN */
+float average(int n, int sum) {
+ float mean = (float) sum / n;
+ return mean;
+}
+
+/* FINDING THE MIN/MAX/DIFFERENCE */
+int range(int argc, char * argv[], enum MODE mode) {
+ int low = strtol(argv[1], NULL, 10);
+ int high = low;
+
+ for (int i = 1; i < argc; i++) {
+ int val = strtol(argv[i], NULL, 10);
+ if (val > high) high = val;
+ if (low > val) low = val;
+ }
+
+ /* Check once and return what we need */
+ switch (mode) {
+ case MODE_MAX:
+ return high;
+ case MODE_MIN:
+ return low;
+ case MODE_DIFF:
+ return high - low;
+ }
+ return 1;
+}
+
+int main(int argc, char * argv[]) {
+ if (argc < 2) { /* Stop empty input */
+ help();
+ }
+
+ int n = argc - 1; /* this is how many numbers there are */
+ int sum = sigma(argc, argv); /* sigma means adding them all together */
+ float mean = average(n, sum); /* the sum divided by the however many numbers there are */
+ int min = range(argc, argv, MODE_MIN); /* Using enums here to use words instead of numbers */
+ int max = range(argc, argv, MODE_MAX);
+ int diff = range(argc, argv, MODE_DIFF);
+
+
+ /* align text left for 6 and 10 right */
+ printf("%-6s %10d\n", "num:", n);
+ printf("%-6s %10d\n", "sum:", sum);
+ printf("%-6s %10.3f\n", "mean:", mean);
+ printf("%-6s %10d\n", "min:", min);
+ printf("%-6s %10d\n", "max:", max);
+ printf("%-6s %10d\n", "range:", diff);
+}