Added new x265 tuning options (PSNR and Grain).
[simple-x264-launcher.git] / src / cli.cpp
blobfe3f62d2d37f920ac6cd10b1a99c6e9b3676e1d1
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
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.
9 //
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 ///////////////////////////////////////////////////////////////////////////////
22 #pragma once
24 #include "cli.h"
25 #include "global.h"
27 ///////////////////////////////////////////////////////////////////////////////
28 // Pre-defined commands
29 ///////////////////////////////////////////////////////////////////////////////
31 #define MAKE_ARG(X,Y,Z) { "--"X, (Y), (Z) }
33 static struct
35 const char *longName;
36 const int optionCount;
37 const int identifier;
39 s_parameters[] =
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 ),
58 { NULL, 0, 0 }
61 ///////////////////////////////////////////////////////////////////////////////
62 // CLI Parser
63 ///////////////////////////////////////////////////////////////////////////////
65 CLIParser::CLIParser(const QStringList &args)
67 m_args(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)
77 /*Nothing to do*/
80 bool CLIParser::nextOption(int &identifier, QStringList *options)
82 identifier = -1;
83 if(options) options->clear();
84 int numOpts = 0;
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;
95 break;
98 if(identifier < 0)
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())
109 if(options)
111 *options << *m_iter;
113 m_iter++; numOpts--;
115 else
117 qWarning("Too few arguments for command \"--%s\" specified!", identifier2string(identifier));
118 break;
122 return ((identifier >= 0) && (numOpts <= 0));
125 bool CLIParser::checkFlag(const int &identifier, const QStringList &args)
127 CLIParser parser(args);
128 int currentId;
130 while(parser.nextOption(currentId, NULL))
132 if(currentId == identifier)
134 return true;
138 return false;
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;
153 return longName;