X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=futatabi%2Fflags.cpp;fp=futatabi%2Fflags.cpp;h=4c7537093982671a4775f0b20d7bd7b7c6d0b569;hb=6e116a6bbeb2c047a3bfb084395ec601ce211e6c;hp=0000000000000000000000000000000000000000;hpb=ce2e0615420b706e1ff2405fffcedfba37a9adac;p=nageru diff --git a/futatabi/flags.cpp b/futatabi/flags.cpp new file mode 100644 index 0000000..4c75370 --- /dev/null +++ b/futatabi/flags.cpp @@ -0,0 +1,82 @@ +#include "flags.h" + +#include +#include +#include +#include + +#include + +using namespace std; + +Flags global_flags; + +// Long options that have no corresponding short option. +enum LongOption { + OPTION_HELP = 1000, + OPTION_SLOW_DOWN_INPUT = 1001, + OPTION_HTTP_PORT = 1002 +}; + +void usage() +{ + fprintf(stderr, "Usage: futatabi [OPTION]... SOURCE_URL\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " --help print usage information\n"); + fprintf(stderr, " --slow-down-input slow down input to realtime (default on if no\n"); + fprintf(stderr, " source URL given)\n"); + fprintf(stderr, " -q, --interpolation-quality N 1 = fastest\n"); + fprintf(stderr, " 2 = default (realtime 720p on fast embedded GPUs)\n"); + fprintf(stderr, " 3 = good (realtime 720p on GTX 970 or so)\n"); + fprintf(stderr, " 4 = best (not realtime on any current GPU)\n"); + fprintf(stderr, " -d, --working-directory DIR where to store frames and database\n"); + fprintf(stderr, " --http-port PORT which port to listen on for output\n"); +} + +void parse_flags(int argc, char * const argv[]) +{ + static const option long_options[] = { + { "help", no_argument, 0, OPTION_HELP }, + { "slow-down-input", no_argument, 0, OPTION_SLOW_DOWN_INPUT }, + { "interpolation-quality", required_argument, 0, 'q' }, + { "working-directory", required_argument, 0, 'd' }, + { "http-port", required_argument, 0, OPTION_HTTP_PORT }, + { 0, 0, 0, 0 } + }; + for ( ;; ) { + int option_index = 0; + int c = getopt_long(argc, argv, "q:d:", long_options, &option_index); + + if (c == -1) { + break; + } + switch (c) { + case OPTION_SLOW_DOWN_INPUT: + global_flags.slow_down_input = true; + break; + case 'q': + global_flags.interpolation_quality = atoi(optarg); + break; + case 'd': + global_flags.working_directory = optarg; + break; + case OPTION_HTTP_PORT: + global_flags.http_port = atoi(optarg); + break; + case OPTION_HELP: + usage(); + exit(0); + default: + fprintf(stderr, "Unknown option '%s'\n", argv[option_index]); + fprintf(stderr, "\n"); + usage(); + exit(1); + } + } + + if (global_flags.interpolation_quality < 1 || global_flags.interpolation_quality > 4) { + fprintf(stderr, "Interpolation quality must be 1, 2, 3 or 4.\n"); + usage(); + exit(1); + } +}