From 495a7cf3cfedeb128b6e43a735710f0757fff7e3 Mon Sep 17 00:00:00 2001 From: tth Date: Wed, 5 Dec 2018 18:14:52 +0100 Subject: [PATCH] added basic options handling --- fake-values.c | 21 +++++++++++++++++++-- funcs.c | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/fake-values.c b/fake-values.c index 09f95bf..4ba730c 100644 --- a/fake-values.c +++ b/fake-values.c @@ -3,16 +3,33 @@ */ #include +#include + #include "funcs.h" int verbosity; +/* --------------------------------------------------------------- */ + int main(int argc, char *argv[]) { -fprintf(stderr, "fake values - %s %s\n", __DATE__, __TIME__); +int opt; + +while ((opt = getopt(argc, argv, "v")) != -1) { + switch (opt) { + case 'v': verbosity++; break; + default: break; + } + } + +if (verbosity > 1) + fprintf(stderr, "fake values - %s %s\n", __DATE__, __TIME__); + + -verbosity = 1; printf("%f %d\n", dtime(), random1000(0)); return 0; } + +/* --------------------------------------------------------------- */ diff --git a/funcs.c b/funcs.c index b099c2a..0587335 100644 --- a/funcs.c +++ b/funcs.c @@ -16,7 +16,7 @@ int random1000(int foo) { int value; if (verbosity) - fprintf(stderr, "%s(%d)\n", __func__, foo); + fprintf(stderr, ">>> %s(%d)\n", __func__, foo); value = rand() % 1000; return value; }