-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmdline_parser.c
102 lines (91 loc) · 2.83 KB
/
cmdline_parser.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
caltool - Touch screen calibration tool for XCSoar Glide Computer - http://www.openvario.org/
Copyright (C) 2014 The openvario project
A detailed list of copyright holders can be found in the file "AUTHORS"
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "version.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
void cmdline_parser(int argc, char **argv, int *rotation, int *use_calfile, char *cal_file){
// locale variables
int c;
int rot;
const char* Usage = "\n"\
" -v print version information\n"\
" -c [calibration file] specify file for calibration\n" \
" -r [rotation] sets rotation of touch calibration default=landscape \n"\
"\n";
// check commandline arguments
while ((c = getopt (argc, argv, "vr:c:")) != -1)
{
switch (c) {
case 'v':
//sprintf(s, "sensord V0.1 %s %s", __DATE__
printf("caltool V%c.%c RELEASE %c build: %s %s\n", VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE, __DATE__, __TIME__);
printf("caltool Copyright (C) 2015 see AUTHORS on www.openvario.org\n");
printf("This program comes with ABSOLUTELY NO WARRANTY;\n");
printf("This is free software, and you are welcome to redistribute it under certain conditions;\n");
exit(EXIT_FAILURE);
break;
// calibration file
case 'c':
if (optarg != NULL)
{
strcpy(cal_file, optarg);
}
else
{
printf("Error: Argument needed !!\n");
printf("Exiting ...\n");
exit(EXIT_FAILURE);
}
break;
// screen rotation
case 'r':
if (optarg != NULL)
{
// convert input parameter to string
rot = atoi(optarg);
switch (rot){
case 0:
case 1:
case 2:
case 3:
*rotation = rot;
break;
default:
printf("Error: Unknown argument for -r !!\n");
printf("Exiting ...\n");
exit(EXIT_FAILURE);
break;
}
*use_calfile = 1;
}
else
{
printf("Error: Unknown argument for -r !!\n");
printf("Exiting ...\n");
exit(EXIT_FAILURE);
}
break;
case '?':
printf("Unknow option %c\n", optopt);
printf("Usage: caltool [OPTION]\n%s",Usage);
printf("Exiting ...\n");
exit(EXIT_FAILURE);
break;
}
}
}