/** print commandline help */ static void _print_help(char *name) { printf("Capture portion of screen & display on LED hardware - %s\n" "Usage: %s [options]\n\n" "Valid options:\n" "\t--help\t\t\t-h\t\tThis help text\n" "\t--mechanism <name>\t-m <name>\tCapture mechanism (default: \"Xlib\")\n" "\t--plugin-help\t\t-p\t\tList of installed plugins + information\n" "\t--config <file>\t\t-c <file>\tLoad this config file (default: ~/.ledcat.xml) \n" "\t--x <x>\t\t\t-x <x>\t\tX-coordinate of capture rectangle (default: 0)\n" "\t--y <y>\t\t\t-y <y>\t\tY-coordinate of capture rectangle (default: 0)\n" "\t--dimensions <w>x<h>\t-d <w>x<h>\tDefine width and height of capture rectangle. (default: auto)\n" "\t--fps <n>\t\t-f <n>\t\tFramerate to play multiple frames at (default: 25)\n" "\t--loglevel <level>\t-l <level>\tOnly show messages with loglevel <level> (default: info)\n\n", PACKAGE_URL, name); printf("\n"); _print_loglevels(); capture_print_mechanisms(); }
/** print commandline help */ static void _print_help(char *name) { printf("Send image to LED hardware - %s\n" "Usage: %s [options] <file(s)>\n\n" "Choose \"-\" as <file> to read from stdin\n\n" "Valid options:\n" "\t--help\t\t\t-h\t\tThis help text\n" "\t--plugin-help\t\t-p\t\tList of installed plugins + information\n" "\t--config <file>\t\t-c <file>\tLoad this prefs file [~/.ledcat.xml] \n" "\t--dimensions <w>x<h>\t-d <w>x<h>\tDefine width and height of input frames. [auto]\n" "\t--big-endian\t\t-b\t\tRAW data is big-endian ordered [off]\n" "\t--loop\t\t\t-L\t\tDon't exit after last file but start over with first [off]\n" "\t--fps <n>\t\t-F <n>\t\tFramerate to play multiple frames at. (Ignored when --signal is used) [25]\n" #if HAVE_IMAGEMAGICK == 1 "\t--raw\t\t\t-r\t\tTreat input files as raw-files (false)\n" #endif "\t--format <format>\t-f <format>\tPixelformat of raw frame - doesn't have effect without --raw. (s. http://gegl.org/babl/ for supported formats)\n" "\t--loglevel <level>\t-l <level>\tOnly show messages with loglevel <level> (info)\n\n", PACKAGE_URL, name); /* print loglevels */ printf("\n"); _print_loglevels(); }
/** 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 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; }