* @brief Main source file of screenshooter
*/
+#include <popt.h>
#include <stdlib.h>
+typedef enum {
+ Capture,
+ Version,
+ Error,
+ Exit
+} Command;
+
+Command parseArguments(int argc, const char **argv, int *width, int *height, char **filename) {
+ Command ret = Capture;
+ poptContext optCon;
+ int c;
+
+ struct poptOption optionsTable[] = {
+ // Commands
+ { "version", 'v', POPT_ARG_NONE, NULL, 'v', "show version of this binary and exit", NULL },
+ // Options
+ { "width", 'w', POPT_ARG_INT, width, 'w', "set width of captured image", NULL },
+ { "height", 'h', POPT_ARG_INT, height, 'h', "set height of captured image", NULL },
+ { "file", 'f', POPT_ARG_STRING, filename, 'f', "file name to store captured image in", NULL },
+ POPT_AUTOHELP
+ { NULL, 0, 0, NULL, 0, NULL, NULL }
+ };
+
+ optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
+ poptSetOtherOptionHelp(optCon, "command");
+ if (argc < 2) {
+ poptPrintUsage(optCon, stderr, 0);
+ ret = Error;
+ }
+
+ if (ret != Exit) {
+ while ((c = poptGetNextOpt(optCon)) >= 0) {
+ switch (c) {
+ case 'v':
+ ret = Version;
+ break;
+ }
+ }
+
+ if (c < -1) {
+ fprintf(stderr, "%s: %s\n", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(c));
+ ret = Error;
+ }
+ }
+
+ poptFreeContext(optCon);
+
+ return ret;
+}
+
int main(int argc, const char **argv) {
- (void) argc;
- (void) argv;
+ int width, height, ret = EXIT_SUCCESS;
+ char *filename;
+
+ Command command = parseArguments(argc, argv, &width, &height, &filename);
+ switch (command) {
+ case Capture:
+ // TODO: add cupturing function
+ break;
+ case Version:
+ // TODO: add version function
+ break;
+ case Error:
+ ret = EXIT_FAILURE;
+ case Exit:
+ break;
+ }
- return EXIT_SUCCESS;
+ return ret;
}