本文整理汇总了C++中Argv类的典型用法代码示例。如果您正苦于以下问题:C++ Argv类的具体用法?C++ Argv怎么用?C++ Argv使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Argv类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST_F
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: if
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: duplicate
Argv::Argv(const Argv &v)
{
_argc=0;
_argv=NULL;
if (v.argc())
duplicate(_argc,_argv,v.argc(),v.argv());
}
示例4: AppendArguments
void CommandLineBuilder::AppendArguments(const Argv& argv)
{
if (argv.GetArgc() > 0)
{
AppendArguments(argv.GetArgc() - 1, argv.GetArgv() + 1);
}
}
示例5: system_cmd
inline int system_cmd(const Argv& argv)
{
int ret = -1;
if (argv.size())
ret = system_cmd(argv[0], argv);
return ret;
}
示例6: responseFileContainsToArgumentList
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;
}
示例7: ArgvWrapper
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;
}
示例8: restrictArgs
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;
}
示例9: main
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;
}
示例10: responseFileToArgumentList
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;
}
示例11: main
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;
}
示例12: options
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");
示例13: kmain
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;
}