1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////////
28 // Pre-defined commands
29 ///////////////////////////////////////////////////////////////////////////////
31 #define MAKE_ARG(X,Y,Z) { "--"X, (Y), (Z) }
36 const int optionCount
;
41 MAKE_ARG( "add", 1, CLI_PARAM_ADD_FILE
),
42 MAKE_ARG( "add-file", 1, CLI_PARAM_ADD_FILE
),
43 MAKE_ARG( "add-job", 3, CLI_PARAM_ADD_JOB
),
44 MAKE_ARG( "force-start", 0, CLI_PARAM_FORCE_START
),
45 MAKE_ARG( "no-force-start", 0, CLI_PARAM_NO_FORCE_START
),
46 MAKE_ARG( "force-enqueue", 0, CLI_PARAM_FORCE_ENQUEUE
),
47 MAKE_ARG( "no-force-enqueue", 0, CLI_PARAM_NO_FORCE_ENQUEUE
),
48 MAKE_ARG( "skip-avisynth-check", 0, CLI_PARAM_SKIP_AVS_CHECK
),
49 MAKE_ARG( "skip-vapoursynth-check", 0, CLI_PARAM_SKIP_VPS_CHECK
),
50 MAKE_ARG( "no-deadlock-detection", 0, CLI_PARAM_NO_DEADLOCK
),
51 MAKE_ARG( "no-style", 0, CLI_PARAM_NO_GUI_STYLE
),
52 MAKE_ARG( "first-run", 0, CLI_PARAM_FIRST_RUN
),
53 MAKE_ARG( "console", 0, CLI_PARAM_OTHER
),
54 MAKE_ARG( "no-console", 0, CLI_PARAM_OTHER
),
55 MAKE_ARG( "force-cpu-no-64bit", 0, CLI_PARAM_OTHER
),
56 MAKE_ARG( "force-cpu-no-sse", 0, CLI_PARAM_OTHER
),
57 MAKE_ARG( "force-cpu-no-intel", 0, CLI_PARAM_OTHER
),
61 ///////////////////////////////////////////////////////////////////////////////
63 ///////////////////////////////////////////////////////////////////////////////
65 CLIParser::CLIParser(const QStringList
&args
)
69 m_iter
= m_args
.constBegin();
71 //Skip the application name, which is expected at args[0]
72 if(m_iter
!= m_args
.constEnd()) m_iter
++;
75 CLIParser::~CLIParser(void)
80 bool CLIParser::nextOption(int &identifier
, QStringList
*options
)
83 if(options
) options
->clear();
86 if(m_iter
!= m_args
.constEnd())
88 const QString current
= *(m_iter
++);
89 for(size_t i
= 0; s_parameters
[i
].longName
!= NULL
; i
++)
91 if(X264_STRCMP(current
, QString::fromLatin1(s_parameters
[i
].longName
)))
93 numOpts
= s_parameters
[i
].optionCount
;
94 identifier
= s_parameters
[i
].identifier
;
100 qWarning("Invalid command-line option \"%s\" was encountered!", current
.toUtf8().constData());
101 m_iter
= m_args
.constEnd();
105 while((identifier
>= 0) && (numOpts
> 0))
107 if(m_iter
!= m_args
.constEnd())
117 qWarning("Too few arguments for command \"--%s\" specified!", identifier2string(identifier
));
122 return ((identifier
>= 0) && (numOpts
<= 0));
125 bool CLIParser::checkFlag(const int &identifier
, const QStringList
&args
)
127 CLIParser
parser(args
);
130 while(parser
.nextOption(currentId
, NULL
))
132 if(currentId
== identifier
)
141 const char *CLIParser::identifier2string(const int &identifier
)
143 const char *longName
= NULL
;
145 for(size_t i
= 0; s_parameters
[i
].longName
!= NULL
; i
++)
147 if(s_parameters
[i
].identifier
== identifier
)
149 longName
= s_parameters
[i
].longName
;