/
fa_parseopt.c
261 lines (218 loc) · 8.01 KB
/
fa_parseopt.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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*
Copyright (C) 2013 xubinbin Ðì±ò±ò (Beijing China)
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/>.
filename: fa_parseopt.c
version : v1.1.0
time : 2013/08/02 16:20
author : xubinbin ( xubbwd@gmail.com )
code URL: http://code.google.com/p/tsdemux/
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __GNUC__
#include <getopt.h>
#else
#include "getopt.h"
#include "getopt.c"
#endif
#include "fa_parseopt.h"
/*global option vaule*/
char opt_inputfile[256] = "";
char opt_video_outputfile[256] = "";
char opt_audio_outputfile[256] = "";
const char *usage =
"\n\n"
"Usage: tsdemux <-i> <inputfile> <-v> <video_outputfile> [options] \n"
" tsdemux <-i> <inputfile> <-a> <audio_outputfile> [options] \n"
" tsdemux <-i> <inputfile> <-v> <video_outputfile> <-a> <audio_outputfile> [options] \n"
"\n\n"
"See also:\n"
" --help for a description of all options for ...\n"
" --license for the license terms for falab.\n\n";
const char *default_set =
"\n\n"
"No argument input, run by default settings\n"
" --type [resample]\n"
" --downfactor [160]\n"
" --upfactor [147]\n"
" --gain [1.0]\n"
"\n\n";
const char *help =
"\n\n"
"Usage: faresample <-i> <inputfile> <-v> <video_outputfile> <-a> <audio_outputfile> [options] \n"
"Options:\n"
" -i <inputfile> Set ts input filename\n"
" -o <video_outputfile> Set video output filename\n"
" -o <audio_outputfile> Set audio output filename\n"
" --help Show this abbreviated help.\n"
" --long-help Show complete help.\n"
" --license for the license terms for falab.\n"
"\n\n";
const char *license =
"\n\n"
"************************************** WARN *******************************************\n"
"* Please note that the use of this software may require the payment of patent *\n"
"* royalties. You need to consider this issue before you start building derivative *\n"
"* works. We are not warranting or indemnifying you in any way for patent royalities! *\n"
"* *\n"
"* YOU ARE SOLELY RESPONSIBLE FOR YOUR OWN ACTIONS! *\n"
"*****************************************************************************************\n"
"\n"
"\n"
"Copyright (C) 2013 xubinbin Ðì±ò±ò (Beijing China)\n"
"\n"
"This program is free software: you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published by\n"
"the Free Software Foundation, either version 3 of the License, or\n"
"(at your option) any later version.\n"
"\n"
"This program is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
"GNU General Public License for more details.\n"
"\n"
"You should have received a copy of the GNU General Public License\n"
"along with this program. If not, see <http://www.gnu.org/licenses/>.\n"
"\n"
"\n"
" ---xubinbin 2012.08.02"
"\n";
static void fa_printopt()
{
FA_PRINT("NOTE: configuration is below\n");
FA_PRINT("NOTE: inputfile = %s\n", opt_inputfile);
FA_PRINT("NOTE: video outputfile= %s\n", opt_video_outputfile);
FA_PRINT("NOTE: audio outputfile= %s\n", opt_audio_outputfile);
}
/**
* @brief: check the input value valid, should check the valid scope
*
* @return: 0 if success, -1 if error
*/
static int fa_checkopt(int argc)
{
if(argc < 5) {
FA_PRINT_ERR("FAIL: input and output file should input\n");
return -1;
}
if(strlen(opt_inputfile) == 0) {
FA_PRINT_ERR("FAIL: input and output file should input\n");
return -1;
}
if(strlen(opt_video_outputfile) == 0 && strlen(opt_audio_outputfile) == 0) {
FA_PRINT_ERR("FAIL: input and output file should input\n");
return -1;
}
FA_PRINT("SUCC: check option ok\n");
return 0;
}
/**
* @brief: parse the command line
* this is the simple template which will be used by falab projects
*
* @param:argc
* @param:argv[]
*
* @return: 0 if success, -1 if error(input value maybe not right)
*/
int fa_parseopt(int argc, char *argv[])
{
int ret;
const char *die_msg = NULL;
while (1) {
static char * const short_options = "hHLli:v:a:";
static struct option long_options[] =
{
{ "help" , 0, 0, 'h'},
{ "help" , 0, 0, 'H'},
{ "license" , 0, 0, 'L'},
{ "license" , 0, 0, 'l'},
{ "input" , 1, 0, 'i'},
{ "video output" , 1, 0, 'v'},
{ "audio output" , 1, 0, 'a'},
{0 , 0, 0, 0},
};
int c = -1;
int option_index = 0;
c = getopt_long(argc, argv, short_options, long_options, &option_index);
if (c == -1) {
break;
}
if (!c) {
die_msg = usage;
break;
}
switch (c) {
case 'h': {
die_msg = help;
break;
}
case 'H': {
die_msg = help;
break;
}
case 'L': {
die_msg = license;
break;
}
case 'l': {
die_msg = license;
break;
}
case 'i': {
if (sscanf(optarg, "%s", opt_inputfile) > 0) {
FA_PRINT("SUCC: inputfile is %s\n", opt_inputfile);
}else {
FA_PRINT_ERR("FAIL: no inputfile\n");
}
break;
}
case 'v': {
if (sscanf(optarg, "%s", opt_video_outputfile) > 0) {
FA_PRINT("SUCC: video outputfile is %s\n", opt_video_outputfile);
}else {
FA_PRINT_ERR("FAIL: no video outputfile\n");
}
break;
}
case 'a': {
if (sscanf(optarg, "%s", opt_audio_outputfile) > 0) {
FA_PRINT("SUCC: audio outputfile is %s\n", opt_audio_outputfile);
}else {
FA_PRINT_ERR("FAIL: no audio outputfile\n");
}
break;
}
case '?':
default:
die_msg = usage;
break;
}
}
if(die_msg) {
FA_PRINT("%s\n", die_msg);
goto fail;
}
/*check the input validity*/
ret = fa_checkopt(argc);
if(ret) {
die_msg = usage;
FA_PRINT("%s\n", die_msg);
goto fail;
}
/*print the settings*/
fa_printopt();
return 0;
fail:
return -1;
}