From d2d2adacecdca66bc9c138474f1362804c34a28d Mon Sep 17 00:00:00 2001 From: "S.J.R. van Schaik" Date: Tue, 12 Sep 2017 16:01:55 +0200 Subject: [PATCH] option: add function to format a list of short and long options together with their respective descriptions --- Makefile | 1 + include/option.h | 9 +++++++++ source/option.c | 15 +++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 include/option.h create mode 100644 source/option.c diff --git a/Makefile b/Makefile index e83381d..22533c3 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ obj-y += source/file.o obj-y += source/image.o obj-y += source/info.o obj-y += source/main.o +obj-y += source/option.o obj-y += source/pack.o obj-y += source/sign.o obj-y += source/unpack.o diff --git a/include/option.h b/include/option.h new file mode 100644 index 0000000..59389a1 --- /dev/null +++ b/include/option.h @@ -0,0 +1,9 @@ +#pragma once + +struct opt_desc { + const char *short_name; + const char *long_name; + const char *desc; +}; + +void format_options(struct opt_desc *entries); diff --git a/source/option.c b/source/option.c new file mode 100644 index 0000000..2745eae --- /dev/null +++ b/source/option.c @@ -0,0 +1,15 @@ +#include + +#include + +void format_options(struct opt_desc *entries) +{ + struct opt_desc *entry; + + for (entry = entries; entry->long_name; ++entry) { + fprintf(stderr, "%7s %-16s %s\n", + entry->short_name ? entry->short_name : "", + entry->long_name, + entry->desc); + } +}