argParser.cpp
6.5 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#include "argParser.h"
ArgParser::ArgParser(){}
ArgParser::~ArgParser(){}
void ArgParser::readArgs(char** argv, int argc)
{
int opt;
int long_index = 0;
static struct option long_options[] = {
{"audio", required_argument, NULL, 'A'},
{"subtitle", required_argument, NULL, 'S'},
{"text", required_argument, NULL, 'T'},
{"video", required_argument, NULL, 'V'},
{"language", required_argument, NULL, 'l'},
{"background", required_argument, NULL, 'b'},
{"resolution", required_argument, NULL, 'r'},
{"position", required_argument, NULL, 'p'},
{"mode", required_argument, NULL, 'm'},
{"id", required_argument, NULL, 'i'},
{"no-mixer", no_argument, NULL, 'x'},
{"help", no_argument, NULL, 'h'},
{0, 0, 0, 0 }
};
while ((opt = getopt_long_only(argc, argv, "A:S:T:V:l:b:r:p:m:", long_options, &long_index))!= -1)
{
switch (opt)
{
case 'A':
if(argc <= 5)
returnErr("Insuficient arguments. Try again");
globalArgs.service = _REC_AUDIO;
globalArgs.input = optarg;
break;
case 'S':
if(argc <= 6 || (globalArgs.service == _REC_VIDEO && argc <= 9))
returnErr("Insuficient arguments. Try again");
if(globalArgs.service == _REC_VIDEO){ // ativa o serviço de vídeo e legendas
globalArgs.service = _VIDEO_WITH_SRT;
globalArgs.input_srt = optarg;
}else{
globalArgs.service = _ONLY_SRT;
globalArgs.input = optarg;
}
break;
case 'T':
if(argc <= 5)
returnErr("Insuficient arguments. Try again");
globalArgs.service = _TEXT;
globalArgs.input = optarg;
break;
case 'V':
if(argc <= 7 || ((globalArgs.service == _ONLY_SRT && argc <= 9)))
returnErr("Insuficient arguments. Try again");
if(globalArgs.service == _ONLY_SRT){ // ativa o serviço de vídeo e legendas
globalArgs.service = _VIDEO_WITH_SRT;
globalArgs.input_srt = globalArgs.input;
}else if(globalArgs.mixer == _NO_MIXER) // desativa a mixagem
globalArgs.service = _WITHOUT_MIXER;
else
globalArgs.service = _REC_VIDEO;
globalArgs.input = optarg;
break;
case 'l':
if (strcmp(optarg,"portugues") == 0)
globalArgs.language = _PORTUGUESE;
else if (strcmp(optarg,"libras") == 0)
globalArgs.language = _GLOSA;
else
returnErr("--language");
break;
case 'b':
if (strcmp(optarg,"opaque") == 0)
globalArgs.back = _OPAQUE;
else if (strcmp(optarg,"transp") == 0)
globalArgs.back = _TRANSPARENT;
else
returnErr("--background");
break;
case 'r':
if (strcmp(optarg,"small") == 0)
globalArgs.size = _SMALL;
else if (strcmp(optarg,"medium") == 0)
globalArgs.size = _MEDIUM;
else if (strcmp(optarg,"large") == 0)
globalArgs.size = _LARGE;
else
returnErr("--resolution");
break;
case 'p':
if (strcmp(optarg,"top_left") == 0)
globalArgs.position = _TOP_LEFT;
else if (strcmp(optarg,"top_right") == 0)
globalArgs.position = _TOP_RIGHT;
else if (strcmp(optarg,"bottom_right") == 0)
globalArgs.position = _BOTTOM_RIGHT;
else if (strcmp(optarg,"bottom_left") == 0)
globalArgs.position = _BOTTOM_LEFT;
else
returnErr("--position");
break;
case 'm':
if(strcmp(optarg,"prod") == 0)
globalArgs.mode = _PROD;
else if (strcmp(optarg,"devel") == 0)
globalArgs.mode = _DEVEL;
else
returnErr("--mode");
break;
case 'i':
globalArgs.id = optarg;
break;
case 'x':
if(globalArgs.service == _REC_VIDEO) // desativa a mixagem
globalArgs.service = _WITHOUT_MIXER;
else
globalArgs.mixer = _NO_MIXER;
break;
case 'h':
help();
break;
case '?':
/* o getopt já mostra o erro no terminal!*/
break;
default:
printf("\nUsage: %s [Service_option] filepath [Options] --id [name] --mode [devel,prod]\n", argv[0]);
printf("\nTry --help for more informations.");
throw lavidlib::RuntimeException();
}
}
if (argc < 2){
printf("Not enough arguments.\nTry --help.\n");
throw lavidlib::RuntimeException();
}
/* Mostra os argumentos restantes depois das opções de linha de comando */
if (optind < argc)
{
printf("non-option ARGV-elements: ");
while (optind < argc)
printf("%s ", argv[optind++]);
}
}
void ArgParser::help()
{
std::cout << std::endl
<< "Usage Summary: vlibras [Service_option] filepath [Options] --id [name] --mode [devel,prod]"
<< "\n\nService_option:"
<< "\n\tVideo with Subtitles -V, --video [filePath] -S, --subtitle [filePath]"
<< "\n\tVideo Recognize -V, --video [filePath]"
<< "\n\tAudio Recognize -A, --audio [filepath]"
<< "\n\tText -T, --text [filePath]"
<< "\n\tSubtitles only -S, --subtitle [filePath]"
<< "\n\nOptions:"
<< "\n\t-l, --language [portugues,libras]"
<< "\n\t-b, --background [opaque,transp]"
<< "\n\t-r, --resolution [small,medium,large]"
<< "\n\t-p, --position [top_left,top_right,bottom_left,bottom_right]"
<< "\n\t-m, --mode [devel,prod]"
<< "\n\t--id [name] Relative to the unique ID on the Database."
<< "\n\t--no-mixer Disables mixing with the original video."
<< "\n\nSee man vlibras for detailed descriptions."
<< std::endl;
throw lavidlib::RuntimeException(); //para nao iniciar o vlibras
}
void ArgParser::returnErr(string option)
{
cout << "Option '" << option << "' contains an invalid argument." << endl;
throw lavidlib::RuntimeException();
}
int ArgParser::getService()
{
return globalArgs.service;
}
int ArgParser::getLanguage()
{
return globalArgs.language;
}
int ArgParser::getPosition()
{
return globalArgs.position;
}
int ArgParser::getSize()
{
return globalArgs.size;
}
int ArgParser::getBackground()
{
return globalArgs.back;
}
int ArgParser::getMode()
{
return globalArgs.mode;
}
int ArgParser::getOption()
{
return globalArgs.mixer;
}
string ArgParser::getInput()
{
return globalArgs.input;
}
string ArgParser::getInputSRT()
{
return globalArgs.input_srt;
}
string ArgParser::getId()
{
return globalArgs.id;
}