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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/******************************************************************************
* Copyright (C) 2018 Alejandro Colomar Andrés *
* SPDX-License-Identifier: GPL-2.0-only *
******************************************************************************/
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
#include "vision-artificial/menu/parse.h"
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "libalx/base/stdio/sscan.h"
#include "vision-artificial/about/about.h"
#include "vision-artificial/menu/iface.h"
#include "vision-artificial/save/save.h"
#include "vision-artificial/user/iface.h"
/******************************************************************************
******* macros ***************************************************************
******************************************************************************/
#define OPT_LIST "hLuv""f:i:"
/******************************************************************************
******* enums ****************************************************************
******************************************************************************/
/******************************************************************************
******* structs / unions *****************************************************
******************************************************************************/
/******************************************************************************
******* variables ************************************************************
******************************************************************************/
/******************************************************************************
******* static functions (prototypes) ****************************************
******************************************************************************/
static void parse_file (char *arg);
static void parse_iface (char *arg);
/******************************************************************************
******* global functions *****************************************************
******************************************************************************/
void parse (int argc, char *argv[])
{
int opt = 0;
int opt_index = 0;
const struct option long_options[] = {
/* Standard */
{"help", no_argument, 0, 'h'},
{"license", no_argument, 0, 'L'},
{"usage", no_argument, 0, 'u'},
{"version", no_argument, 0, 'v'},
/* Non-standard */
{"file", required_argument, 0, 'f'},
{"iface", required_argument, 0, 'i'},
/* Null */
{0, 0, 0, 0}
};
while ((opt = getopt_long(argc, argv, OPT_LIST, long_options,
&opt_index)) != -1) {
switch (opt) {
/* Standard */
case 'h':
print_share_file(SHARE_HELP);
exit(EXIT_SUCCESS);
case 'L':
print_share_file(SHARE_LICENSE);
exit(EXIT_SUCCESS);
case 'u':
print_share_file(SHARE_USAGE);
exit(EXIT_SUCCESS);
case 'v':
print_version();
exit(EXIT_SUCCESS);
/* Non-standard */
case 'f':
parse_file(optarg);
break;
case 'i':
parse_iface(optarg);
break;
case '?':
/* getopt_long already printed an error message. */
default:
print_share_file(SHARE_USAGE);
exit(EXIT_FAILURE);
}
}
}
/******************************************************************************
******* static functions (definitions) ***************************************
******************************************************************************/
static void parse_file (char *arg)
{
FILE *fp;
/* FIXME */
fp = fopen(arg, "r");
if (!fp)
goto err;
fclose(fp);
saved_path[0] = '\0';
snprintf(saved_name, FILENAME_MAX, "%s", arg);
return;
err:
printf("--file argument not valid\n");
printf("It must be a valid file name (relative to saved dir)\n");
exit(EXIT_FAILURE);
}
static void parse_iface (char *arg)
{
if (alx_sscan_int(&menu_iface_mode, MENU_IFACE_CLUI, 0, MENU_IFACE_TUI,
arg)) {
goto err;
}
user_iface_mode = menu_iface_mode;
return;
err:
printf("--iface argument not valid\n");
printf("It must be an integer [%i U %i]\n", MENU_IFACE_CLUI,
MENU_IFACE_TUI);
exit(EXIT_FAILURE);
}
/******************************************************************************
******* end of file **********************************************************
******************************************************************************/
|