option: add function to format a list of short and long options together with their respective descriptions

master
S.J.R. van Schaik 7 years ago
parent 01270673a3
commit d2d2adacec
  1. 1
      Makefile
  2. 9
      include/option.h
  3. 15
      source/option.c

@ -14,6 +14,7 @@ obj-y += source/file.o
obj-y += source/image.o obj-y += source/image.o
obj-y += source/info.o obj-y += source/info.o
obj-y += source/main.o obj-y += source/main.o
obj-y += source/option.o
obj-y += source/pack.o obj-y += source/pack.o
obj-y += source/sign.o obj-y += source/sign.o
obj-y += source/unpack.o obj-y += source/unpack.o

@ -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);

@ -0,0 +1,15 @@
#include <stdio.h>
#include <option.h>
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);
}
}
Loading…
Cancel
Save