/** parse commandline arguments */ static NftResult _parse_args(int argc, char *argv[]) { int index, argument; static struct option loptions[] = { {"help", 0, 0, 'h'}, {"plugin-help", 0, 0, 'p'}, {"loglevel", required_argument, 0, 'l'}, {"config", required_argument, 0, 'c'}, {"dimensions", required_argument, 0, 'd'}, {"fps", required_argument, 0, 'F'}, {"format", required_argument, 0, 'f'}, {"big-endian", no_argument, 0, 'b'}, {"loop", no_argument, 0, 'L'}, #if HAVE_IMAGEMAGICK == 1 {"raw", no_argument, 0, 'r'}, #endif {0,0,0,0} }; #if HAVE_IMAGEMAGICK == 1 const char arglist[] = "hpl:c:d:F:f:bLr"; #else const char arglist[] = "hpl:c:d:F:f:bL"; #endif while((argument = getopt_long(argc, argv, arglist, loptions, &index)) >= 0) { switch(argument) { /* --help */ case 'h': { _print_help(argv[0]); return NFT_FAILURE; } /* --plugin-help */ case 'p': { _print_plugin_help(); return NFT_FAILURE; } /* --config */ case 'c': { /* save filename for later */ strncpy(_c.prefsfile, optarg, sizeof(_c.prefsfile)); break; } /** --loop */ case 'L': { _c.do_loop = TRUE; break; } /** --dimensions */ case 'd': { if(sscanf(optarg, "%dx%d", (int*) &_c.width, (int*) &_c.height) != 2) { NFT_LOG(L_ERROR, "Invalid dimension \"%s\" (Use something like 320x400)", optarg); return NFT_FAILURE; } break; } /** --fps */ case 'F': { if(sscanf(optarg, "%d", (int*) &_c.fps) != 1) { NFT_LOG(L_ERROR, "Invalid framerate \"%s\" (Use an integer)", optarg); return NFT_FAILURE; } break; } /** --loglevel */ case 'l': { if(!nft_log_level_set(nft_log_level_from_string(optarg))) { _print_loglevels(); return NFT_FAILURE; } break; } /** --format */ case 'f': { strncpy(_c.pixelformat, optarg, sizeof(_c.pixelformat)); break; } #if HAVE_IMAGEMAGICK == 1 /** --raw */ case 'r': { _c.raw = TRUE; break; } #endif /** --big-endian */ case 'b': { _c.is_big_endian = TRUE; break; } /* invalid argument */ case '?': { NFT_LOG(L_ERROR, "argument %d is invalid", index); _print_help(argv[0]); return NFT_FAILURE; } /* unhandled arguments */ default: { NFT_LOG(L_ERROR, "argument %d is invalid", index); break; } } } _c.files = &argv[optind]; return NFT_SUCCESS; }
/** parse commandline arguments */ static int _parse_args(int argc, char *argv[]) { int index, argument; static struct option loptions[] = { {"help", no_argument, 0, 'h'}, {"plugin-help", no_argument, 0, 'p'}, {"dimensions", required_argument, 0, 'D'}, {"driver", required_argument, 0, 'd'}, {"input", required_argument, 0, 'i'}, {"actor", required_argument, 0, 'a'}, {"morph", required_argument, 0, 'm'}, {"fps", required_argument, 0, 'f'}, {"seed", required_argument, 0, 's'}, {0, 0, 0, 0 } }; while((argument = getopt_long(argc, argv, "hpD:d:i:a:m:f:s:", loptions, &index)) >= 0) { switch(argument) { /* --help */ case 'h': { _print_help(argv[0]); return EXIT_FAILURE; } /* --plugin-help */ case 'p': { _print_plugin_help(); return EXIT_FAILURE; } /* --dimensions */ case 'D': { if (std::sscanf (optarg, "%dx%d", &width, &height) != 2) { std::cerr << "Invalid dimensions: '" << optarg << "'. Use <width>x<height> (e.g. 320x200)\n"; return EXIT_FAILURE; } break; } /* --driver */ case 'd': { if (!DisplayDriverFactory::instance().has_driver (optarg)) { std::cerr << "Unsupported display driver: " << optarg << "\n"; return EXIT_FAILURE; } driver_name = optarg; break; } /* --input */ case 'i': { /* save name for later */ input_name = optarg; break; } /* --actor */ case 'a': { /* save name for later */ actor_name = optarg; break; } /* --morph */ case 'm': { /* save filename for later */ morph_name = optarg; break; } /* --fps */ case 'f': { /* set framerate */ std::sscanf(optarg, "%d", &framerate); break; } /* --seed */ case 's': { have_seed = 1; std::sscanf(optarg, "%u", &seed); break; } /* invalid argument */ case '?': { std::fprintf(stderr, "argument %d is invalid\n", index); _print_help(argv[0]); return EXIT_FAILURE; } /* unhandled arguments */ default: { std::fprintf(stderr, "argument %d is invalid\n", index); break; } } } return EXIT_SUCCESS; }
/** parse commandline arguments */ static NftResult _parse_args(int argc, char *argv[]) { int index, argument; static struct option loptions[] = { {"help", 0, 0, 'h'}, {"plugin-help", 0, 0, 'p'}, {"loglevel", required_argument, 0, 'l'}, {"config", required_argument, 0, 'c'}, {"x", required_argument, 0, 'x'}, {"y", required_argument, 0, 'y'}, {"dimensions", required_argument, 0, 'd'}, {"fps", required_argument, 0, 'f'}, {"mechanism", required_argument, 0, 'm'}, {0,0,0,0} }; while((argument = getopt_long(argc, argv, "hpl:c:x:y:d:f:m:", loptions, &index)) >= 0) { switch(argument) { /** --help */ case 'h': { _print_help(argv[0]); return NFT_FAILURE; } /* --plugin-help */ case 'p': { _print_plugin_help(); return NFT_FAILURE; } /* --mechanism */ case 'm': { _c.method = capture_method_from_string(optarg); break; } /** --config */ case 'c': { /* save filename for later */ strncpy(_c.prefsfile, optarg, sizeof(_c.prefsfile)); break; } /** --x */ case 'x': { if(sscanf(optarg, "%d", (int*) &_c.x) != 1) { NFT_LOG(L_ERROR, "Invalid x-coordinate \"%s\" (Use an integer)", optarg); return NFT_FAILURE; } break; } /** --y */ case 'y': { if(sscanf(optarg, "%d", (int*) &_c.y) != 1) { NFT_LOG(L_ERROR, "Invalid y-coordinate \"%s\" (Use an integer)", optarg); return NFT_FAILURE; } break; } /** --dimensions */ case 'd': { if(sscanf(optarg, "%dx%d", (int*) &_c.width, (int*) &_c.height) != 2) { NFT_LOG(L_ERROR, "Invalid dimension \"%s\" (Use something like 320x400)", optarg); return NFT_FAILURE; } break; } /** --fps */ case 'f': { if(sscanf(optarg, "%d", (int*) &_c.fps) != 1) { NFT_LOG(L_ERROR, "Invalid framerate \"%s\" (Use an integer)", optarg); return NFT_FAILURE; } break; } /** --loglevel */ case 'l': { if(!nft_log_level_set(nft_log_level_from_string(optarg))) { _print_loglevels(); return NFT_FAILURE; } break; } /* invalid argument */ case '?': { NFT_LOG(L_ERROR, "argument %d is invalid", index); _print_help(argv[0]); return NFT_FAILURE; } /* unhandled arguments */ default: { NFT_LOG(L_ERROR, "argument %d is invalid", index); break; } } } return NFT_SUCCESS; }