option: add function to format a list of short and long options together with their respective descriptions
This commit is contained in:
parent
01270673a3
commit
d2d2adacec
3 changed files with 25 additions and 0 deletions
1
Makefile
1
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
|
||||
|
|
|
|||
9
include/option.h
Normal file
9
include/option.h
Normal file
|
|
@ -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);
|
||||
15
source/option.c
Normal file
15
source/option.c
Normal file
|
|
@ -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…
Add table
Add a link
Reference in a new issue