ploot

plot images or real-time plain text from a .csv file
Log | Files | Refs | README

commit c529b0f871ecc44395506be3e5eb928caa4b63e0
parent 800a50b0368df65b45838095a362b579cc709d75
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sat,  3 Feb 2018 01:48:52 +0100

adding arg.h, thank you __20h__

Diffstat:
MMakefile | 3+++
Aarg.h | 25+++++++++++++++++++++++++
Mploot.c | 28++++++++++++++++++++++++----
3 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile @@ -2,3 +2,6 @@ CFLAGS = -Wall -Wextra -Werror -std=c89 -pedantic all: ploot.o config.h ${CC} -static -o ploot ploot.o + +clean: + rm -f *.o ploot diff --git a/arg.h b/arg.h @@ -0,0 +1,25 @@ +#define USED(x) ((void)(x)) + +extern char *argv0; + +#define ARGBEGIN(argc, argv) \ + for (argv0 = *argv, argv++, argc--; \ + argv[0] != NULL && argv[0][0] == '-' && argv[0][1] != '\0'; \ + argc--, argv++) { \ + char **arg_v, *arg_s; \ + if (argv[0][1] == '-' && argv[0][2] == '\0') { \ + argv++, argc--; \ + break; \ + } \ + arg_v = argv; \ + for (arg_s = *argv; *arg_s != '\0'; arg_s++) { \ + if (arg_v != argv) \ + break; \ + switch (*arg_s) + +#define ARGEND \ + } \ + } + +#define EARGF(x) \ + ((argv[1] == NULL) ? ((x), NULL) : (argc--, argv++, argv[0])) diff --git a/ploot.c b/ploot.c @@ -1,16 +1,21 @@ +#include <sys/time.h> + #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <sys/time.h> +#include "arg.h" #include "config.h" #define MAX_VAL 80 #define MARGIN 7 -#define HEIGHT 20 #define ABS(x) ((x) < 0 ? -(x) : (x)) #define LEN(x) (sizeof(x) / sizeof(*x)) +char *argv0; +int flag_h = 20; + /* * Set `str' to a human-readable form of `num' with always a width of 7 (+ 1 * the '\0' terminator). Buffer overflow is ensured not to happen due to the @@ -162,8 +167,15 @@ read_time_series(double *valv, time_t *timev) return valv; } +void +usage(void) +{ + printf("usage: %s [-h height]\n", argv0); + exit(1); +} + int -main() +main(int argc, char **argv) { double val[] = { 55, 55, 1, 72, 53, 73, 6, 45, 7, 71, 18, 100, 78, 56, 53, 24, 99, 99, 37, 91, 67, 68, 9, 16, 83, 30, 68, 51, 38, 47, 91, @@ -173,6 +185,14 @@ main() 71, 61, 12, 29, 63, 85, 72, 98, 59, 96, 91, 67, 24, 48, 4, 90, 1, 15, 57, 11, 93, 18, 18, 78, 85, 36, 35, 15, 7, 85, 31, 73, 57, 70 }; - plot(HEIGHT, val, val + LEN(val), "Sample data generated with jot"); + ARGBEGIN(argc, argv) { + case 'h': + flag_h = atoi(EARGF(usage())); + if (flag_h <= 0) + usage(); + break; + } ARGEND; + + plot(flag_h, val, val + LEN(val), "Sample data generated with jot"); return 0; }