Add --help
Provide command-line help, with -h/--help option.
This commit is contained in:
parent
ee93f3f23a
commit
35a111d56e
1 changed files with 48 additions and 1 deletions
|
@ -10,19 +10,59 @@
|
||||||
|
|
||||||
struct args {
|
struct args {
|
||||||
const char *serial;
|
const char *serial;
|
||||||
|
SDL_bool help;
|
||||||
Uint16 port;
|
Uint16 port;
|
||||||
Uint16 max_size;
|
Uint16 max_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void usage(const char *arg0) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Usage: %s [options] [serial]\n"
|
||||||
|
"\n"
|
||||||
|
" serial\n"
|
||||||
|
" The device serial number. Mandatory only if several devices\n"
|
||||||
|
" are connected to adb.\n"
|
||||||
|
"\n"
|
||||||
|
"Options:\n"
|
||||||
|
"\n"
|
||||||
|
" -h, --help\n"
|
||||||
|
" Print this help.\n"
|
||||||
|
"\n"
|
||||||
|
" -m, --max-size value\n"
|
||||||
|
" Limit both the width and height of the video to value. The\n"
|
||||||
|
" other dimension is computed so that the device aspect-ratio\n"
|
||||||
|
" is preserved.\n"
|
||||||
|
" Default is %d%s.\n"
|
||||||
|
"\n"
|
||||||
|
" -p, --port port\n"
|
||||||
|
" Set the TCP port the client listens on.\n"
|
||||||
|
" Default is %d.\n"
|
||||||
|
"\n"
|
||||||
|
"Shortcuts:\n"
|
||||||
|
"\n"
|
||||||
|
" Ctrl+f: switch fullscreen mode\n"
|
||||||
|
" Ctrl+g: resize window to 1:1 (pixel-perfect)\n"
|
||||||
|
" Ctrl+x: resize window to optimal size (remove black borders)\n"
|
||||||
|
"\n",
|
||||||
|
arg0,
|
||||||
|
DEFAULT_MAX_SIZE, DEFAULT_MAX_SIZE ? "" : " (unlimited)",
|
||||||
|
DEFAULT_LOCAL_PORT);
|
||||||
|
}
|
||||||
|
|
||||||
static int parse_args(struct args *args, int argc, char *argv[]) {
|
static int parse_args(struct args *args, int argc, char *argv[]) {
|
||||||
static const struct option long_options[] = {
|
static const struct option long_options[] = {
|
||||||
|
{"help", no_argument, NULL, 'h'},
|
||||||
{"port", required_argument, NULL, 'p'},
|
{"port", required_argument, NULL, 'p'},
|
||||||
{"max-size", required_argument, NULL, 'm'},
|
{"max-size", required_argument, NULL, 'm'},
|
||||||
{NULL, 0, NULL, 0 },
|
{NULL, 0, NULL, 0 },
|
||||||
};
|
};
|
||||||
int c;
|
int c;
|
||||||
while ((c = getopt_long(argc, argv, "p:m:", long_options, NULL)) != -1) {
|
while ((c = getopt_long(argc, argv, "hp:m:", long_options, NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case 'h': {
|
||||||
|
args->help = SDL_TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'p': {
|
case 'p': {
|
||||||
char *endptr;
|
char *endptr;
|
||||||
long value = strtol(optarg, &endptr, 0);
|
long value = strtol(optarg, &endptr, 0);
|
||||||
|
@ -72,14 +112,21 @@ int main(int argc, char *argv[]) {
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
struct args args = {
|
struct args args = {
|
||||||
|
.help = SDL_FALSE,
|
||||||
.serial = NULL,
|
.serial = NULL,
|
||||||
.max_size = DEFAULT_MAX_SIZE,
|
.max_size = DEFAULT_MAX_SIZE,
|
||||||
.port = DEFAULT_LOCAL_PORT,
|
.port = DEFAULT_LOCAL_PORT,
|
||||||
};
|
};
|
||||||
if (parse_args(&args, argc, argv)) {
|
if (parse_args(&args, argc, argv)) {
|
||||||
|
usage(argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args.help) {
|
||||||
|
usage(argv[0]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
av_register_all();
|
av_register_all();
|
||||||
|
|
||||||
if (avformat_network_init()) {
|
if (avformat_network_init()) {
|
||||||
|
|
Loading…
Reference in a new issue