#include "ace/Message_Queue.h"
#include "ace/OS.h"
#include "ace/Log_Msg.h"
#include "ace/Get_Opt.h"
#include <iostream>
#include <fstream>
#define ACE_NDEBUG 0
using namespace std;
int ACE_TMAIN(int argc, ACE_TCHAR * argv[])
{
const ACE_TCHAR options[] = "f:F:s:S:vVhHdD" ;
int opt=0;
ACE_Get_Opt cmd_opts(argc, argv, options);
cmd_opts.long_option(ACE_TEXT("config"),'f',ACE_Get_Opt::ARG_REQUIRED);//长参数关联到短参数
cmd_opts.long_option(ACE_TEXT("segment"),'s',ACE_Get_Opt::ARG_REQUIRED);
cmd_opts.long_option(ACE_TEXT("CONFIG") ,'f',ACE_Get_Opt::ARG_REQUIRED);
cmd_opts.long_option(ACE_TEXT("SEGMENT"),'s',ACE_Get_Opt::ARG_REQUIRED);
ACE_LOG_MSG->priority_mask( LM_DEBUG | LM_INFO , ACE_Log_Msg::PROCESS );//设置日志级别
while((opt = cmd_opts()) != EOF)
{
switch(opt)
{
case 'f':
case 'F':
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT("File: -fF[%d]:%s\n"),cmd_opts.opt_ind(), cmd_opts.opt_arg()) );
}
break;
case 's':
case 'S':
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT("Segment: -sS[%d]:%s\n"), cmd_opts.opt_ind(), cmd_opts.opt_arg()));
}
break;
case 'v':
case 'V':
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT("Version: -vV[%d]: %s\n"),cmd_opts.opt_ind(), cmd_opts.opt_arg()));
}
break;
case 'h':
case 'H':
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT( "Help: -hH[%d]: %s\n" ),cmd_opts.opt_ind(), cmd_opts.opt_arg()));
}
break;
default :
{
if(NULL == cmd_opts.opt_arg())
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT( "UnKnown option[%d]\n"),cmd_opts.opt_ind()));
}
else
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT( "UnKnown option[%d]: %s\n"),cmd_opts.opt_ind(), cmd_opts.opt_arg()));
}
}
}
}
return 0;
#include "ace/OS.h"
#include "ace/Log_Msg.h"
#include "ace/Get_Opt.h"
#include <iostream>
#include <fstream>
#define ACE_NDEBUG 0
using namespace std;
int ACE_TMAIN(int argc, ACE_TCHAR * argv[])
{
const ACE_TCHAR options[] = "f:F:s:S:vVhHdD" ;
int opt=0;
ACE_Get_Opt cmd_opts(argc, argv, options);
cmd_opts.long_option(ACE_TEXT("config"),'f',ACE_Get_Opt::ARG_REQUIRED);//长参数关联到短参数
cmd_opts.long_option(ACE_TEXT("segment"),'s',ACE_Get_Opt::ARG_REQUIRED);
cmd_opts.long_option(ACE_TEXT("CONFIG") ,'f',ACE_Get_Opt::ARG_REQUIRED);
cmd_opts.long_option(ACE_TEXT("SEGMENT"),'s',ACE_Get_Opt::ARG_REQUIRED);
ACE_LOG_MSG->priority_mask( LM_DEBUG | LM_INFO , ACE_Log_Msg::PROCESS );//设置日志级别
while((opt = cmd_opts()) != EOF)
{
switch(opt)
{
case 'f':
case 'F':
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT("File: -fF[%d]:%s\n"),cmd_opts.opt_ind(), cmd_opts.opt_arg()) );
}
break;
case 's':
case 'S':
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT("Segment: -sS[%d]:%s\n"), cmd_opts.opt_ind(), cmd_opts.opt_arg()));
}
break;
case 'v':
case 'V':
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT("Version: -vV[%d]: %s\n"),cmd_opts.opt_ind(), cmd_opts.opt_arg()));
}
break;
case 'h':
case 'H':
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT( "Help: -hH[%d]: %s\n" ),cmd_opts.opt_ind(), cmd_opts.opt_arg()));
}
break;
default :
{
if(NULL == cmd_opts.opt_arg())
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT( "UnKnown option[%d]\n"),cmd_opts.opt_ind()));
}
else
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT( "UnKnown option[%d]: %s\n"),cmd_opts.opt_ind(), cmd_opts.opt_arg()));
}
}
}
}
return 0;
}
###############################################
运行:
ace_tst --segment sss 等价于如下参数 ace_tst -s sss