adding arg.h, thank you __20h__ - ploot - simple plotting tools
 (HTM) git clone git://bitreich.org/ploot git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/ploot
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit c529b0f871ecc44395506be3e5eb928caa4b63e0
 (DIR) parent 800a50b0368df65b45838095a362b579cc709d75
 (HTM) Author: Josuah Demangeon <mail@josuah.net>
       Date:   Sat,  3 Feb 2018 01:48:52 +0100
       
       adding arg.h, thank you __20h__
       
       Diffstat:
         M Makefile                            |       3 +++
         A arg.h                               |      25 +++++++++++++++++++++++++
         M ploot.c                             |      28 ++++++++++++++++++++++++----
       
       3 files changed, 52 insertions(+), 4 deletions(-)
       ---
 (DIR) 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
 (DIR) 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]))
 (DIR) 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;
        }