2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 #include "command-line-options.h"
40 const char * const opt;
41 const char * const optDescription;
45 std::cout << std::left << " --";
46 std::cout.width( 18 );
48 std::cout << optDescription;
49 std::cout << std::endl;
53 Argument EXPECTED_ARGS[] =
55 { "no-vsync", "Disable VSync on Render" },
56 { "width", "Stage Width" },
57 { "height", "Stage Height" },
58 { "dpi", "Emulated DPI" },
59 { "view", "Stereocopic 3D view mode ([0]=MONO, 1=STEREO_HORZ, 2=STEREO_VERT, 3=STEREO_INTERLACED)" },
60 { "stereo-base", "Distance in millimeters between left/right cameras [65.0]" },
76 typedef std::vector< int > UnhandledContainer;
80 std::cout << "Available options:" << std::endl;
81 Argument* arg = EXPECTED_ARGS;
89 } // unnamed namespace
91 CommandLineOptions::CommandLineOptions(int *argc, char **argv[])
93 stageWidth(0), stageHeight(0),
99 // We do not want to print out errors.
100 int origOptErrValue( opterr );
105 const struct option options[]=
107 { EXPECTED_ARGS[OPTION_NO_VSYNC].opt, no_argument, &noVSyncOnRender, 1 }, // "--no-vsync"
108 { EXPECTED_ARGS[OPTION_STAGE_WIDTH].opt, required_argument, NULL, 'w' }, // "--width"
109 { EXPECTED_ARGS[OPTION_STAGE_HEIGHT].opt, required_argument, NULL, 'h' }, // "--height"
110 { EXPECTED_ARGS[OPTION_DPI].opt, required_argument, NULL, 'd' }, // "--dpi"
111 { EXPECTED_ARGS[OPTION_STEREO_MODE].opt, required_argument, NULL, 'v' }, // "--view"
112 { EXPECTED_ARGS[OPTION_STEREO_BASE].opt, required_argument, NULL, 's' }, // "--stereo-base"
113 { EXPECTED_ARGS[OPTION_HELP].opt, no_argument, &help, '?' }, // "--help"
114 { 0, 0, 0, 0 } // end of options
117 int shortOption( 0 );
118 int optionIndex( 0 );
120 const char* optString = "-w:h:d:v:s:"; // The '-' ensures that argv is NOT permuted
121 bool optionProcessed( false );
123 UnhandledContainer unhandledOptions; // We store indices of options we do not handle here
127 shortOption = getopt_long( *argc, *argv, optString, options, &optionIndex );
129 switch ( shortOption )
133 // Check if we want help
137 optionProcessed = true;
146 stageWidth = atoi( optarg );
147 optionProcessed = true;
156 stageHeight = atoi( optarg );
157 optionProcessed = true;
166 stageDPI.assign( optarg );
167 optionProcessed = true;
176 viewMode = atoi(optarg);
177 optionProcessed = true;
186 stereoBase = atoi(optarg);
187 optionProcessed = true;
194 // All command-line options have been parsed.
200 unhandledOptions.push_back( optind - 1 );
204 } while ( shortOption != -1 );
206 // Take out the options we have processed
207 if ( optionProcessed )
209 if ( !unhandledOptions.empty() )
213 // Overwrite the argv with the values from the unhandled indices
214 const UnhandledContainer::const_iterator endIter = unhandledOptions.end();
215 for ( UnhandledContainer::iterator iter = unhandledOptions.begin(); iter != endIter; ++iter )
217 (*argv)[ index++ ] = (*argv)[ *iter ];
219 *argc = unhandledOptions.size() + 1; // +1 for the program name
223 // There are no unhandled options, so we should just have the program name
227 optind = 1; // Reset to start
230 opterr = origOptErrValue; // Reset opterr value.
234 CommandLineOptions::~CommandLineOptions()
238 } // namespace Adaptor
240 } // namespace Internal