コード例 #1
0
TEST_F(TargetParserBasicTest, ParsingError) {
  Argv argv;
  argv.push_back("--option1").push_back("1");
  std::stringstream os;
  ASSERT_NE(0, target_parser.parse(argv.get_vec(), &os));
  ASSERT_EQ("unrecognised option '--option1'\n", os.str());
}
コード例 #2
0
ファイル: files.cpp プロジェクト: bngabonziza/miktex
FILE *
SessionImpl::InitiateProcessPipe (/*[in]*/ const char *		lpszCommand,
        /*[in]*/ FileAccess		access,
        /*[in,out]*/ FileMode &	mode)
{
    Argv argv;
    argv.Build ("", lpszCommand);
    int argc = argv.GetArgc();
    if (argc == 0)
    {
        FATAL_MIKTEX_ERROR ("SessionImpl::InitiateProcessPipe",
                            T_("Invalid command."),
                            lpszCommand);
    }
    string verb = argv[1];
    if (verb == "zcat"
            && argc == 3
            && access.Get() == FileAccess::Read)
    {
        mode = FileMode::Open;
        return (OpenGZipFile(argv[2]));
    }
    else if (verb == "bzcat"
             && argc == 3 &&
             access.Get() == FileAccess::Read)
    {
        mode = FileMode::Open;
        return (OpenBZip2File(argv[2]));
    }
    else
    {
        return (POpen(lpszCommand,
                      access.Get() == FileAccess::Read ? "r" : "w"));
    }
}
コード例 #3
0
ファイル: argv.cpp プロジェクト: testcocoon/testcocoon
Argv::Argv(const Argv &v)
{
  _argc=0;
  _argv=NULL;
  if (v.argc())
    duplicate(_argc,_argv,v.argc(),v.argv());
}
コード例 #4
0
ファイル: CommandLineBuilder.cpp プロジェクト: MiKTeX/miktex
void CommandLineBuilder::AppendArguments(const Argv& argv)
{
  if (argv.GetArgc() > 0)
  {
    AppendArguments(argv.GetArgc() - 1, argv.GetArgv() + 1);
  }
}
コード例 #5
0
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();
}
コード例 #6
0
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());
}
コード例 #7
0
TEST_F(TargetParserBasicTest, OptionNotProvided) {
  ASSERT_EQ(ReturnCode::SUCCESS,
            target_parser.add_string_option("option1", "hs1"));
  Argv argv;
  target_parser.parse(argv.get_vec(), nullptr);
  std::string v;
  ASSERT_EQ(ReturnCode::OPTION_NOT_PROVIDED,
            target_parser.get_string_option("option1", &v));
}
コード例 #8
0
TEST_F(TargetParserBasicTest, InvalidOptionType) {
  ASSERT_EQ(ReturnCode::SUCCESS,
            target_parser.add_string_option("option1", "hs1"));
  Argv argv;
  argv.push_back("--option1").push_back("1");
  target_parser.parse(argv.get_vec(), nullptr);
  int v;
  ASSERT_EQ(ReturnCode::INVALID_OPTION_TYPE,
            target_parser.get_int_option("option1", &v));
}
コード例 #9
0
TEST_F(TargetParserBasicTest, TargetOptionInt) {
  const std::string option_name = "option1";
  const int intv = 9;
  int v;
  target_parser.add_int_option(option_name, "hs1");
  Argv argv;
  argv.push_back("--" + option_name).push_back(std::to_string(intv));
  target_parser.parse(argv.get_vec(), nullptr);
  ASSERT_EQ(ReturnCode::SUCCESS, target_parser.get_int_option(option_name, &v));
  ASSERT_EQ(intv, v);
}
コード例 #10
0
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));
}
コード例 #11
0
TEST_F(TargetParserBasicTest, TargetOptionString) {
  const std::string option_name = "option1";
  const std::string strv = "strv";
  std::string v;
  target_parser.add_string_option(option_name, "hs1");
  Argv argv;
  argv.push_back("--" + option_name).push_back(strv);
  target_parser.parse(argv.get_vec(), nullptr);
  ASSERT_EQ(ReturnCode::SUCCESS,
            target_parser.get_string_option(option_name, &v));
  ASSERT_EQ(strv, v);
}
コード例 #12
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());  
}
コード例 #13
0
ファイル: process.hpp プロジェクト: akoshelnik/openvpn3
 inline int system_cmd(const Argv& argv)
 {
   int ret = -1;
   if (argv.size())
     ret = system_cmd(argv[0], argv);
   return ret;
 }
コード例 #14
0
TEST_F(TargetParserBasicTest, TargetOptionFlag) {
  const std::string option_name_1 = "option1";
  const std::string option_name_2 = "option2";
  bool v1, v2;
  target_parser.add_flag_option(option_name_1, "hs1");
  target_parser.add_flag_option(option_name_2, "hs2");
  Argv argv;
  argv.push_back("--" + option_name_1);
  target_parser.parse(argv.get_vec(), nullptr);
  ASSERT_EQ(ReturnCode::SUCCESS,
            target_parser.get_flag_option(option_name_1, &v1));
  ASSERT_EQ(ReturnCode::SUCCESS,
            target_parser.get_flag_option(option_name_2, &v2));
  ASSERT_TRUE(v1);
  ASSERT_FALSE(v2);
}
コード例 #15
0
bool CompilerInterface::responseFileContainsToArgumentList (const std::string &text,Argv &args) const
{
  FUNCTION_TRACE;
  /* extract all options */
  int pos1=0;
  int pos2=0;
  bool in_string=false;
  int text_lg=text.length();

  for (int i=0;i<text_lg;i++)
  {
    char c=text[i];
    if (c=='"')
      in_string = !in_string;
    if ( !in_string 
        && ( c=='\t' || c==' ' || c=='\n' || c=='\r' ) ) 
    {
      pos2=i;
      if (pos2!=pos1)
      {
        std::string item=text.substr(pos1,pos2-pos1);
        /* add the item */
        System::stripQuotes(item);
        args.append(item.c_str());
      }
      pos1=pos2+1;
    }
  }
  return true;
}
コード例 #16
0
ファイル: process.hpp プロジェクト: akoshelnik/openvpn3
    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;
    }
コード例 #17
0
TEST_F(TargetParserBasicTest, TargetOptionMix) {
  target_parser.add_string_option("option1", "hs1");
  target_parser.add_flag_option("option2", "hs2");
  target_parser.add_int_option("option3", "hs3");
  std::string strv;
  int intv;
  bool boolv;
  Argv argv;
  argv.push_back("--option1").push_back("1")
      .push_back("--option2")
      .push_back("--option3").push_back("1");
  target_parser.parse(argv.get_vec(), nullptr);
  ASSERT_EQ(ReturnCode::SUCCESS,
            target_parser.get_string_option("option1", &strv));
  ASSERT_EQ("1", strv);
  ASSERT_EQ(ReturnCode::SUCCESS,
            target_parser.get_flag_option("option2", &boolv));
  ASSERT_TRUE(boolv);
  ASSERT_EQ(ReturnCode::SUCCESS,
            target_parser.get_int_option("option3", &intv));
  ASSERT_EQ(1, intv);
}
コード例 #18
0
bool CompilerInterface::restrictArgs(const char* selected_source,Argv &backup_args ) 
{
  FUNCTION_TRACE;
  int i;
  backup_args=param_args();

  Argv new_args;
  for (i=0;i<backup_args.argc();i++)
  {
    const char *file=backup_args[i];
    if (!isSource(file) || filename_strcmp(selected_source,file)==0)
      new_args.append(file);
  }

  setArgs(new_args);
  return true;
}
コード例 #19
0
ファイル: producer.cpp プロジェクト: franciscoSoler/nebla
int main(int argc, char **argv)
{
    srand (time(NULL));
    Argv arguments;

    arguments.setArgv(argv);

    int waitTime;
    int numberOfConsumers;
    int numberOfProducers;
    int producerId;
    std::string queuePath;
    char key;
    std::string keyStr;


    producerId = StringUtils::StringToNumber<int>(arguments.getArg(1));
    queuePath = arguments.getArg(2);
    keyStr = arguments.getArg(3);
    key = keyStr[0];
    numberOfConsumers = StringUtils::StringToNumber<int>(arguments.getArg(4));
    numberOfProducers = StringUtils::StringToNumber<int>(arguments.getArg(5));

    MessageQueue<Message> queue(queuePath, key);
    Message dato;
    int counter=0;

    std::cout << "Producer"<< producerId<<" started"<<std::endl;

    while(true)
    {
        waitTime = rand() % 5 + 1;
        sleep(waitTime);

        dato.id = counter * numberOfProducers + producerId;
        counter++;

        std::cout << "Producer:"<<producerId<< " produced:" <<dato.id<<std::endl;

        for(int j=1; j<=numberOfConsumers; j++)
        {
            dato.mtype = j;
            if(queue.put(dato)<0)
                exit(0);
        }
    }

    return 0;
}
コード例 #20
0
bool CompilerInterface::responseFileToArgumentList (const std::string& rsp_file,Argv &args) const
{
  FUNCTION_TRACE;
  bool res=false;
  args.clear();
  FILE *f=fopen(rsp_file.c_str(),"r");
  if (f)
  {
    int sz;
    std::string text;
    char tmp[CHAINE_LEN*16];
    text.clear();

    while ( (sz=fread(tmp,sizeof(char),CHAINE_LEN*16,f)) > 0)
      text+=std::string(tmp,sz);
    
    fclose(f);
    if (!text.empty())
    {
      std::string rsptext;
      switch (text_encoding(text))
      {
        case ENC_UTF16:
          { // Windows .NET 2005 workaround
            DEBUG1("UTF16 Response file\n");
            wchar_t tmp[CHAINE_LEN];
            wchar_t *textws=NULL;
            int sz;
            int tmp_sz=0;
            char *text=NULL;
            f=fopen(rsp_file.c_str(),"rb");
            if (f==NULL) return false;

            while ( (sz=fread(tmp,sizeof(wchar_t),CHAINE_LEN,f)) > 0)
            {
              textws=(wchar_t *)REALLOC(textws,sizeof(wchar_t)*(sz+tmp_sz));
              memcpy(&textws[tmp_sz],tmp,sz*sizeof(wchar_t));
              tmp_sz+=sz;
            }
            fclose(f);
            text=(char*)MALLOC(sizeof(char)*(tmp_sz+1+CHAINE_LEN));
            memset(text,0,tmp_sz+1);
            int offset=0;
            while (textws[offset]==0xFEFF)
              offset++;
            DEBUG2("offset=%i\n",offset);
            wcstombs(text,&textws[offset],tmp_sz-offset);
            text[tmp_sz-offset]='\0';
            DEBUG2("Response file contain:%s\n",text);
#if LOG
            for (int i=0;i<tmp_sz;i++)
            {
               DEBUG5("textws[%i]=%4.4X text[%i]=%c\n",i,textws[i],i,text[i]);
            }
#endif
            FREE(textws);
            rsptext=std::string(text);
            FREE(text);
          }     
          break;
        case ENC_UTF8:
          DEBUG1("UTF8 Response file\n");
          rsptext=utf16_to_ascii(utf8_to_utf16(text));
          break;
        case ENC_ASCII:
          DEBUG1("ASCII Response file\n");
          rsptext=text;
          break;
      }
      rsptext=ascii_correct_eol(rsptext);


      if (!rsptext.empty())
      {
        DEBUG2("Response file contain:%s\n",rsptext.c_str());
        rsptext+="\n"; // add a separator at the end to simplify the process
        res=responseFileContainsToArgumentList(rsptext,args);
      }
    }
  }
  return res;
}
コード例 #21
0
ファイル: main.cpp プロジェクト: thuleqaid/boost_study
int main(int argc, char **argv)
{
	loginit(LEVEL_TRACE);
	/* parse command line */
	std::string indir;
	Argv opts;
	opts.addBoolOption("recusive,r","recursive the directory");
	opts.startGroup("Hidden",false);
	opts.addTextOption("inputdir,d","directory for scan").setOptionPostion("inputdir,d",1);
	opts.stopGroup();
	if (!opts.parse(argc,argv))
	{
		/* command options parsing error */
		opts.showHelp(std::cout);
		LOG(error)<< "Input error";
		return 1;
	}
	else
	{
		indir=opts.getTextOption("inputdir","");
	}
	if (indir.size()<1)
	{
		/* inputdir isnot specified */
		opts.showHelp(std::cout,true);
		LOG(error)<< "Directory must be specified";
		return 1;
	}
	LOG(trace)<< "Current Path:"<<bfs::current_path().generic_string();
	LOG(trace)<< "Input directory:"<<indir;

	bfs::path p(indir);
	bfs::path fullp;
	/* checek input directory */
	if (!bfs::exists(p))
	{
		LOG(error)<<"Not exists";
		return 1;
	}
	else
	{
		if (!bfs::is_directory(p))
		{
			LOG(error)<<"Not a directory";
			return 1;
		}
		else
		{
			/* bfs::absolute will remain '..' or '.' */
			fullp=bfs::canonical(p);
			LOG(trace)<<"Full path:"<<fullp.generic_string();
		}
	}

	/* list files */
	walk(fullp,item_action,opts.getBoolOption("recusive"));

	/* generate a unique filename, used for temperary file */
	std::cout<<bfs::unique_path().generic_string()<<std::endl;

	/* make dir */
	bfs::path tmpfile("temp/abc/def");
	/* path.parent_path() must exist for bfs::create_directory(path) */
	/* makedirs(path) will call create_directory() repeatly until path is created */
	makedirs(tmpfile);
	/* create a temperary file */
	tmpfile/=bfs::unique_path();
	LOG(trace)<<tmpfile.generic_string();
	std::ofstream ofs(tmpfile.generic_string());
	ofs<<"test\n";
	ofs.close();
	/* remove directory */
	bfs::remove_all("temp");
	/* other file operation:
	 * copy, copy_directory, copy_file, copy_symlink
	 *   copy will automaticall choose copy_directory/copy_file/copy_symlink
	 * remove, remove_all
	 *   remove for file, remove_all for directory
	 * rename
	 */

	std::vector<bfs::path> vec;
	findInPath("vim",{"."},vec);
	std::copy(vec.cbegin(),vec.cend(),std::ostream_iterator<bfs::path>(std::cout,"\n"));
	return 0;
}
コード例 #22
0
ファイル: options.cpp プロジェクト: 0x1997/cxxopts
  cxxopts::Options options("tester", " - test basic options");

  options.add_options()
    ("long", "a long option")
    ("s,short", "a short option")
    ("value", "an option with a value", cxxopts::value<std::string>())
    ("a,av", "a short option with a value", cxxopts::value<std::string>())
    ("6,six", "a short number option")
    ;

  Argv argv({
    "tester",
    "--long",
    "-s",
    "--value",
    "value",
    "-a",
    "b",
    "-6"
  });

  char** actual_argv = argv.argv();
  auto argc = argv.argc();

  options.parse(argc, actual_argv);

  CHECK(options.count("long") == 1);
  CHECK(options.count("s") == 1);
  CHECK(options.count("value") == 1);
  CHECK(options.count("a") == 1);
  CHECK(options["value"].as<std::string>() == "value");
コード例 #23
0
ファイル: GpMain.cpp プロジェクト: yukke64/GreenPad
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;
}