inline int system_cmd(const Argv& argv) { int ret = -1; if (argv.size()) ret = system_cmd(argv[0], argv); return ret; }
TEST_F(TargetParserIfaceTest, DispatchEmpty) { OptionsParser main_parser; Argv argv; argv.push_back("name") .push_back(json_path.string()); main_parser.parse(argv.size(), argv.get(), &dummy_parser); ASSERT_EQ(0u, dummy_parser.input.size()); }
TEST_F(TargetParserIfaceTest, NoDispatch) { OptionsParser main_parser; Argv argv; argv.push_back("name") .push_back(json_path.string()); main_parser.parse(argv.size(), argv.get(), nullptr); SUCCEED(); }
ArgvWrapper(const Argv& argv) { size_t i; argc = argv.size(); cargv = new char *[argc+1]; for (i = 0; i < argc; ++i) cargv[i] = string_alloc(argv[i]); cargv[i] = NULL; }
TEST_F(TargetParserIfaceTest, DispatchPositional) { OptionsParser main_parser; Argv argv; argv.push_back("name") .push_back(json_path.string()) .push_back("--") .push_back("unknown"); main_parser.parse(argv.size(), argv.get(), &dummy_parser); ASSERT_EQ(1u, dummy_parser.input.size()); ASSERT_EQ("unknown", dummy_parser.input.at(0)); }
TEST_F(TargetParserIfaceTest, DispatchMany) { OptionsParser main_parser; Argv argv; argv.push_back("name") .push_back(json_path.string()) .push_back("--"); size_t iters = 16; for (size_t i = 0; i < iters; i++) { argv.push_back("--unknown" + std::to_string(i)) .push_back(std::to_string(i)); } main_parser.parse(argv.size(), argv.get(), &dummy_parser); ASSERT_EQ(2 * iters, dummy_parser.input.size()); }
int kmain() { LOGGER( "kmain() begin" ); Argv arg; ulong i; LOGGER( "argv processed" ); //-- まずオプションスイッチを処理 int optL = -1; int optC = 0; for( i=1; i<arg.size() && arg[i][0]==TEXT('-'); ++i ) switch( arg[i][1] ) { case TEXT('c'): optC = String::GetInt( arg[i]+2 ); break; case TEXT('l'): optL = String::GetInt( arg[i]+2 ); break; } LOGGER( "option processed" ); //-- 次にファイル名 Path file; if( i < arg.size() ) { file = arg[i]; if( !file.isFile() ) { ulong j; // ""無しで半スペ入りでもそれなりに対処 for( j=i+1; j<arg.size(); ++j ) { file += ' '; file += arg[j]; if( file.isFile() ) break; } if( j==arg.size() ) file = arg[i]; else i=j; } } LOGGER( "filename processed" ); //-- 余ってる引数があれば、それで新規プロセス起動 if( ++i < arg.size() ) { String cmd; for( ; i<arg.size(); ++i ) { cmd += TEXT('\"'); cmd += arg[i]; cmd += TEXT("\" "); } ::BootNewProcess( cmd.c_str() ); } LOGGER( "newprocess booted" ); //-- メインウインドウ発進 GreenPadWnd wnd; if( !wnd.StartUp(file,optC,optL) ) return -1; LOGGER( "kmain() startup ok" ); //-- メインループ wnd.ShowUp2(); LOGGER( "showup!" ); wnd.MsgLoop(); LOGGER( "fin" ); return 0; }