Have programs display version information in their usage help

This way we don't have to introduce new options for retrieving
version info. For those programs that do not output their usage
by default (e.g. because they would process stdin), you may pass
a "-?" option to get help - and thus version information.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
This commit is contained in:
Bernhard Nortmann 2016-10-21 18:50:34 +02:00
parent 5792814010
commit 569f189693
7 changed files with 26 additions and 7 deletions

View File

@ -336,6 +336,13 @@ void print_boot1_file_head(boot1_file_head_t *hdr, loader_type type)
printf("Unknown boot0 header version\n");
}
static void usage(const char *cmd)
{
puts("sunxi-bootinfo " VERSION "\n");
printf("Usage: %s [<filename>]\n", cmd);
printf(" With no <filename> given, will read from stdin instead\n");
}
int main(int argc, char * argv[])
{
FILE *in = stdin;
@ -352,8 +359,11 @@ int main(int argc, char * argv[])
}
if (argc > 1) {
in = fopen(argv[1], "rb");
if (!in)
fail("open input: ");
if (!in) {
if (*argv[1] == '-')
usage(argv[0]);
fail("open input");
}
}
int len;

2
fel.c
View File

@ -28,6 +28,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include "common.h"
#include "portable_endian.h"
#include "progress.h"
@ -1565,6 +1566,7 @@ int main(int argc, char **argv)
#endif
if (argc <= 1) {
puts("sunxi-fel " VERSION "\n");
printf("Usage: %s [options] command arguments... [command...]\n"
" -v, --verbose Verbose logging\n"
" -p, --progress \"write\" transfers show a progress bar\n"

1
fexc.c
View File

@ -215,6 +215,7 @@ done:
*/
static inline void app_usage(const char *arg0, int mode)
{
fputs("sunxi-fexc " VERSION "\n\n", stderr);
errf("Usage: %s [-vq]%s[<input> [<output>]]\n", arg0,
mode ? " " : " [-I <infmt>] [-O <outfmt>] ");

View File

@ -39,6 +39,7 @@
#include <errno.h>
#include <getopt.h>
#include "common.h"
#include "portable_endian.h"
#if defined(CONFIG_BCH_CONST_PARAMS)
@ -62,7 +63,6 @@
#define cpu_to_be32 htobe32
#define kfree free
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define BCH_PRIMITIVE_POLY 0x5803
@ -916,7 +916,9 @@ static int create_image(const struct image_info *info)
static void display_help(int status)
{
fprintf(status == EXIT_SUCCESS ? stdout : stderr,
"Usage: sunxi-nand-image-builder [OPTIONS] source-image output-image\n"
"sunxi-nand-image-builder %s\n"
"\n"
"Usage: sunxi-nand-image-builder [OPTIONS] source-image output-image\n"
"\n"
"Creates a raw NAND image that can be read by the sunxi NAND controller.\n"
"\n"
@ -960,8 +962,8 @@ static void display_help(int status)
" A normal image can be generated with\n"
" sunxi-nand-image-builder -p 16384 -o 1280 -e 0x400000 -s -c 40/1024\n"
" A boot0 image can be generated with\n"
" sunxi-nand-image-builder -p 16384 -o 1280 -e 0x400000 -s -b -u 4096 -c 64/1024\n"
);
" sunxi-nand-image-builder -p 16384 -o 1280 -e 0x400000 -s -b -u 4096 -c 64/1024\n",
VERSION);
exit(status);
}

View File

@ -24,9 +24,11 @@
#include <strings.h>
#include <fcntl.h>
#include "nand-common.h"
#include "common.h"
void usage(const char *cmd)
{
puts("sunxi-nand-part " VERSION "\n");
printf("usage: %s [-f a10|a20] nand-device\n", cmd);
printf(" %s nand-device 'name2 len2 [usertype2]' ['name3 len3 [usertype3]'] ...\n", cmd);
printf(" %s [-f a10|a20] nand-device start1 'name1 len1 [usertype1]' ['name2 len2 [usertype2]'] ...\n", cmd);

View File

@ -20,6 +20,7 @@
#include <string.h>
#include <unistd.h>
#include "common.h"
#include "portable_endian.h"
struct phoenix_ptable {
@ -76,6 +77,7 @@ err:
static void usage(char **argv)
{
puts("phoenix-info " VERSION "\n");
printf("Usage: %s [options] [phoenix_image]\n"
" -v verbose\n"
" -q quiet\n"

2
pio.c
View File

@ -165,7 +165,7 @@ static const char *argv0;
static void usage(int rc )
{
fputs("sunxi-pio " VERSION "\n\n", stderr);
fprintf(stderr, "usage: %s -m|-i input [-o output] pin..\n", argv0);
fprintf(stderr," -m mmap - read pin state from system\n");
fprintf(stderr," -i read pin state from file\n");