ee0299874fd131a914e6b543cfbadf7efb3638b0
[test/tools/screenshooter.git] / src / main.c
1 /*
2  *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License
15  */
16 /**
17  * @file        src/main.cpp
18  * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
19  * @brief       Main source file of screenshooter
20  */
21
22 #include <popt.h>
23 #include <stdlib.h>
24
25 typedef enum {
26   Capture,
27   Version,
28   Error,
29   Exit
30 } Command;
31
32 Command parseArguments(int argc, const char **argv, int *width, int *height, char **filename) {
33   Command ret = Capture;
34   poptContext optCon;
35   int c;
36
37   struct poptOption optionsTable[] = {
38     // Commands
39     { "version", 'v', POPT_ARG_NONE, NULL, 'v', "show version of this binary and exit", NULL },
40     // Options
41     { "width", 'w', POPT_ARG_INT, width, 'w', "set width of captured image", NULL },
42     { "height", 'h', POPT_ARG_INT, height, 'h', "set height of captured image", NULL },
43     { "file", 'f', POPT_ARG_STRING, filename, 'f', "file name to store captured image in", NULL },
44     POPT_AUTOHELP
45     { NULL, 0, 0, NULL, 0, NULL, NULL }
46   };
47
48   optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
49   poptSetOtherOptionHelp(optCon, "command");
50   if (argc < 2) {
51     poptPrintUsage(optCon, stderr, 0);
52     ret = Error;
53   }
54
55   if (ret != Exit) {
56     while ((c = poptGetNextOpt(optCon)) >= 0) {
57       switch (c) {
58         case 'v':
59           ret = Version;
60           break;
61       }
62     }
63
64     if (c < -1) {
65       fprintf(stderr, "%s: %s\n", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(c));
66       ret = Error;
67     }
68   }
69
70   poptFreeContext(optCon);
71
72   return ret;
73 }
74
75 int main(int argc, const char **argv) {
76   int width, height, ret = EXIT_SUCCESS;
77   char *filename;
78
79   Command command = parseArguments(argc, argv, &width, &height, &filename);
80   switch (command) {
81     case Capture:
82       // TODO: add cupturing function
83       break;
84     case Version:
85       // TODO: add version function
86       break;
87     case Error:
88       ret = EXIT_FAILURE;
89     case Exit:
90       break;
91   }
92
93   return ret;
94 }