本文整理汇总了C++中poptSetOtherOptionHelp函数的典型用法代码示例。如果您正苦于以下问题:C++ poptSetOtherOptionHelp函数的具体用法?C++ poptSetOtherOptionHelp怎么用?C++ poptSetOtherOptionHelp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了poptSetOtherOptionHelp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse_opt
static
void parse_opt(int argc, char **argv)
{
int c;
poptContext optCon;
const char *no_arg;
struct poptOption optionsTable[] = {
{ "loops" , 'n', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_INT,
&arg_loops , 0, "pp loops", "count" },
{ "time" , 't', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_INT,
&arg_maxtime, 0, "max time", "ms" },
{ "maxsize" , 0, POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_INT,
&arg_maxmsize , 0, "maximal messagesize", "size" },
{ "nokill" , 'k', POPT_ARGFLAG_OR | POPT_ARG_VAL,
&arg_nokill, 1, "Dont kill the server afterwards", NULL },
{ "port" , 'p', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_STRING,
&arg_port, 0, "server port to use", "port" },
{ "verbose" , 'v', POPT_ARG_NONE,
NULL , 'v', "increase verbosity", NULL },
POPT_AUTOHELP
POPT_TABLEEND
};
optCon = poptGetContext(NULL, argc, (const char **) argv, optionsTable, 0);
poptSetOtherOptionHelp(optCon, "[serveraddr]");
while ((c = poptGetNextOpt(optCon)) >= 0) {
switch (c) { // c = poptOption.val;
case 'v': arg_verbose++; break;
}
}
if (c < -1) { /* an error occurred during option processing */
fprintf(stderr, "%s: %s\n",
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
poptStrerror(c));
poptPrintHelp(optCon, stderr, 0);
exit(1);
}
// arg_1 = poptGetArg(optCon);
// arg_2 = poptGetArg(optCon);
arg_servername = poptGetArg(optCon);
is_server = !arg_servername;
no_arg = poptGetArg(optCon); // should return NULL
if (no_arg) {
fprintf(stderr, "%s: %s\n",
no_arg, poptStrerror(POPT_ERROR_BADOPT));
poptPrintHelp(optCon, stderr, 0);
exit(1);
}
poptFreeContext(optCon);
}
示例2: parse_opt
static
void parse_opt(int argc, char **argv)
{
int c;
poptContext optCon;
const char *no_arg;
struct poptOption optionsTable[] = {
{ "loops" , 'n', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_INT,
&arg_loops , 0, "pp loops", "count" },
{ "time" , 't', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_INT,
&arg_maxtime, 0, "max time", "ms" },
{ "maxsize" , 0, POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_INT,
&arg_maxmsize , 0, "maximal messagesize", "size" },
{ "once" , '1', POPT_ARGFLAG_OR | POPT_ARG_VAL,
&arg_run_once, 1, "stop after one client", NULL },
{ "verbose" , 'v', POPT_ARG_NONE,
NULL , 'v', "increase verbosity", NULL },
POPT_AUTOHELP
POPT_TABLEEND
};
optCon = poptGetContext(NULL, argc, (const char **) argv, optionsTable, 0);
poptSetOtherOptionHelp(optCon, "[serveraddr]");
while ((c = poptGetNextOpt(optCon)) >= 0) {
switch (c) { // c = poptOption.val;
case 'v': arg_verbose++; break;
//default: fprintf(stderr, "unhandled popt value %d\n", c); break;
}
}
if (c < -1) { /* an error occurred during option processing */
fprintf(stderr, "%s: %s\n",
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
poptStrerror(c));
poptPrintHelp(optCon, stderr, 0);
exit(1);
}
// arg_1 = poptGetArg(optCon);
// arg_2 = poptGetArg(optCon);
/* if (arg_client)*/ {
const char *server = poptGetArg(optCon);
if (server) arg_server_addr = server;
}
no_arg = poptGetArg(optCon); // should return NULL
if (no_arg) {
fprintf(stderr, "%s: %s\n",
no_arg, poptStrerror(POPT_ERROR_BADOPT));
poptPrintHelp(optCon, stderr, 0);
exit(1);
}
poptFreeContext(optCon);
}
示例3: parse_opt
void parse_opt(int argc, char **argv)
{
int c;
poptContext optCon;
const char *no_arg;
struct poptOption optionsTable[] = {
{ "send" , 's', POPT_ARGFLAG_OR | POPT_ARG_VAL,
&arg_send, 1, "first send", NULL },
{ "lport" , 'l', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_INT,
&arg_listenport, 0, "listen on port", "port" },
{ "lname" , 'n', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_STRING,
&arg_listenname, 0, "listen on name", "name" },
{ "verbose" , 'v', POPT_ARG_NONE,
NULL , 'v', "increase verbosity", NULL },
POPT_AUTOHELP
POPT_TABLEEND
};
optCon = poptGetContext(NULL, argc, (const char **) argv, optionsTable, 0);
poptSetOtherOptionHelp(optCon, "[peer address]");
while ((c = poptGetNextOpt(optCon)) >= 0) {
switch (c) { // c = poptOption.val;
case 'v': arg_verbose++; break;
//default: fprintf(stderr, "unhandled popt value %d\n", c); break;
}
}
if (c < -1) { /* an error occurred during option processing */
fprintf(stderr, "%s: %s\n",
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
poptStrerror(c));
poptPrintHelp(optCon, stderr, 0);
exit(1);
}
{
const char *s;
s = poptGetArg(optCon);
if (s) {
arg_peer_str = s;
}
}
no_arg = poptGetArg(optCon); // should return NULL
if (no_arg) {
fprintf(stderr, "%s: %s\n",
no_arg, poptStrerror(POPT_ERROR_BADOPT));
poptPrintHelp(optCon, stderr, 0);
exit(1);
}
poptFreeContext(optCon);
}
示例4: main
int
main(int argc, const char *argv[])
{
Socket* serverSock, *controlSock;
int c;
poptContext optCon = poptGetContext(NULL, argc, argv, options, 0);
poptSetOtherOptionHelp(optCon, "configFile");
while ((c = poptGetNextOpt(optCon)) >= 0) {
switch (c) {
case 'v':
printf(V_STRING, VERSION);
printf(COPYRIGHT);
return 0;
}
}
setup_logging (logfile_name, log_level);
if (c < -1) {
/* an error occurred during option processing */
fprintf(stderr, "%s: %s\n",
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
poptStrerror(c));
return -1;
}
loginfo (V_STRING, VERSION);
loginfo (COPYRIGHT);
struct sigaction new_action, old_action;
new_action.sa_handler = sigpipe_handler;
sigemptyset (&new_action.sa_mask);
new_action.sa_flags = 0;
sigaction (SIGPIPE, NULL, &old_action);
if (old_action.sa_handler != SIG_IGN)
sigaction (SIGPIPE, &new_action, NULL);
prepare_stdin(NULL);
eventloop_init();
session = (Session*) malloc(sizeof(Session));
memset(session, 0, sizeof(Session));
session->state = ProxyState_PAUSED;
serverSock = socket_server_new("proxy_server", listen_port, on_connect, NULL);
controlSock = socket_server_new("proxy_server_control", listen_port + 1, on_control_connect, NULL);
eventloop_on_stdin(stdin_handler, session);
eventloop_run();
socket_free(serverSock);
socket_free(controlSock);
return(0);
}
示例5: main
int main(int argc, const char **argv)
{
NET_API_STATUS status;
struct libnetapi_ctx *ctx = NULL;
const char *hostname = NULL;
const char *domain = NULL;
uint8_t *buffer = NULL;
poptContext pc;
int opt;
struct poptOption long_options[] = {
POPT_AUTOHELP
POPT_COMMON_LIBNETAPI_EXAMPLES
POPT_TABLEEND
};
status = libnetapi_init(&ctx);
if (status != 0) {
return status;
}
pc = poptGetContext("getdc", argc, argv, long_options, 0);
poptSetOtherOptionHelp(pc, "hostname domainname");
while((opt = poptGetNextOpt(pc)) != -1) {
}
if (!poptPeekArg(pc)) {
poptPrintHelp(pc, stderr, 0);
goto out;
}
hostname = poptGetArg(pc);
if (!poptPeekArg(pc)) {
poptPrintHelp(pc, stderr, 0);
goto out;
}
domain = poptGetArg(pc);
/* NetGetDCName */
status = NetGetDCName(hostname, domain, &buffer);
if (status != 0) {
printf("GetDcName failed with: %s\n", libnetapi_errstr(status));
} else {
printf("%s\n", (char *)buffer);
}
out:
NetApiBufferFree(buffer);
libnetapi_free(ctx);
poptFreeContext(pc);
return status;
}
示例6: main
int main(int argc, const char **argv)
{
NET_API_STATUS status;
struct libnetapi_ctx *ctx = NULL;
const char *hostname = NULL;
const char *sharename = NULL;
poptContext pc;
int opt;
struct poptOption long_options[] = {
POPT_AUTOHELP
POPT_COMMON_LIBNETAPI_EXAMPLES
POPT_TABLEEND
};
status = libnetapi_init(&ctx);
if (status != 0) {
return status;
}
pc = poptGetContext("share_del", argc, argv, long_options, 0);
poptSetOtherOptionHelp(pc, "hostname sharename");
while((opt = poptGetNextOpt(pc)) != -1) {
}
if (!poptPeekArg(pc)) {
poptPrintHelp(pc, stderr, 0);
goto out;
}
hostname = poptGetArg(pc);
if (!poptPeekArg(pc)) {
poptPrintHelp(pc, stderr, 0);
goto out;
}
sharename = poptGetArg(pc);
/* NetShareDel */
status = NetShareDel(hostname,
sharename,
0);
if (status != 0) {
printf("NetShareDel failed with: %s\n",
libnetapi_get_error_string(ctx, status));
goto out;
}
out:
libnetapi_free(ctx);
poptFreeContext(pc);
return status;
}
示例7: main
int main(int argc, char *argv[]){
char errbuf[PCAP_ERRBUF_SIZE], *device="any",*output_filename="/tmp/test.dump",*filter;
const char *tmp;
struct bpf_program fcode;
int count=0;
int timer=10;
int c;
poptContext context;
struct poptOption optionsTable[] = {
{"output", 'o', POPT_ARG_STRING, &output_filename, 'o'},
{"count", 'c', POPT_ARG_INT, &count, 'c'},
{"time", 't', POPT_ARG_INT, &timer, 't'},
{NULL,0,0,NULL,0}
};
context = poptGetContext(NULL, argc, (const char **) argv, optionsTable, 0);
poptSetOtherOptionHelp(context, "<tcpdump filter>");
while (poptGetNextOpt(context) >= 0) {}
filter = (char *)malloc(256);
strcpy (filter,"");
while ((tmp = poptGetArg(context))!=NULL) {
if (strcmp(filter,"")) filter = strcat(filter," ");
filter = strcat(filter,tmp);
}
if (strcmp(filter,"")==0) filter = "port 3306";
poptFreeContext(context);
printf("file=%s, count=%d, time=%d, filter=%s\n",output_filename,count,timer,filter);
signal(SIGTERM, cleanup);
signal(SIGALRM, cleanup);
signal(SIGINT, cleanup);
memset(errbuf,0,PCAP_ERRBUF_SIZE);
descr = pcap_open_live(device,BUFSIZ,0,100,errbuf);
if (descr == NULL) {
fprintf(stderr, "Couldn't open device %s: %s\n", device, errbuf);
return(2);
}
if (pcap_compile(descr, &fcode, filter, 0, 0) < 0){
fprintf(stderr,"can not analyze filter:%s\n", filter);
exit(1);
}
if (pcap_setfilter(descr,&fcode) == -1) {
fprintf(stderr, "filter can not use: %s\n", filter);
exit(1);
}
dumper = pcap_dump_open(descr,output_filename);
alarm(timer);
pcap_loop(descr,count,write_captured_packet,NULL);
pcap_close(descr);
pcap_dump_close(dumper);
exit(0);
}
示例8: main
/** Process command line arguements and decide how to proceed.
* Includes explanatory text for inline help and self-documentation.
*/
int main( int argc, char *argv[] )
{
int descend_flag = 0, hadoop_flag = 0, stats_flag = 0, verbose_flag = 0, json_flag = 0;
int count = 0, ret_val = 0;
g_dir_arg = "."; /// set the default directory argument to "here"
poptContext pc;
struct poptOption po[] = {
{"descend", 'd', POPT_ARG_NONE, &descend_flag, 0, UNIMPL"Parallelise and descend into subdirectories.", NULL},
{"stats", 's', POPT_ARG_NONE, &stats_flag, 0, "Print detailed statistics.", NULL},
{"verbose", 'v', POPT_ARG_NONE, &verbose_flag, 0, UNIMPL"Expand statistics output for each subdirectory.", NULL},
{"json", 'j', POPT_ARG_NONE, &json_flag, 0, UNIMPL"Write output in JSON format.", NULL},
POPT_AUTOHELP
POPT_TABLEEND
};
pc = poptGetContext(NULL, argc, (const char **)argv, po, 0);
poptSetOtherOptionHelp(pc, "[directory]");
while ( (count = poptGetNextOpt(pc) ) >= 0 ) {
printf("poptGetNextOpt return val %d\n", count);
}
for ( count = 0 ; poptPeekArg(pc) != NULL ; ++count ) {
asprintf(&g_dir_arg, (char*)poptGetArg(pc));
if ( count > 0 ) {
poptPrintUsage(pc, stderr, 0);
goto EXITNOW;
}
}
if ( descend_flag + hadoop_flag + stats_flag + verbose_flag + json_flag > 5 ) {
poptPrintUsage(pc, stderr, 0);
goto EXITNOW;
} else {
if ( descend_flag != POPT_ARG_NONE ) printf("%s: %s %s\n", PROGNAME, UNIMPL, "descend");
else if ( stats_flag != POPT_ARG_NONE ) ret_val = getdirent(g_dir_arg);
else if ( verbose_flag != POPT_ARG_NONE ) printf("%s: %s %s\n", PROGNAME, UNIMPL, "verbose");
else if ( json_flag != POPT_ARG_NONE ) printf("%s: %s %s\n", PROGNAME, UNIMPL, "json");
else ret_val = quickcount(g_dir_arg);
}
if ( ret_val == 0 ) {
exit(EXIT_SUCCESS);
} else {
goto EXITNOW;
}
EXITNOW:
exit(EXIT_FAILURE);
}
示例9: show_help
/* Show program help. */
static void show_help (poptContext ctx)
{
size_t ix;
show_banner ();
poptSetOtherOptionHelp (ctx, mocp_summary);
poptPrintHelp (ctx, stdout, 0);
printf ("\nEnvironment variables:\n\n");
for (ix = 0; ix < ARRAY_SIZE(environment_variables); ix += 1)
printf (" %-34s%s\n", environment_variables[ix].name,
environment_variables[ix].desc);
printf ("\n");
}
示例10: main
int main(int argc, const char *argv[])
{
const char *config_file = get_dyn_CONFIGFILE();
const char *sequence = "";
poptContext pc;
char *buff;
TALLOC_CTX *ctx = talloc_stackframe();
struct poptOption long_options[] = {
POPT_AUTOHELP
POPT_COMMON_VERSION
POPT_TABLEEND
};
load_case_tables();
pc = poptGetContext(NULL, argc, argv, long_options,
POPT_CONTEXT_KEEP_FIRST);
poptSetOtherOptionHelp(pc, "[OPTION...] <sequence-string>");
while(poptGetNextOpt(pc) != -1);
setup_logging(poptGetArg(pc), true);
sequence = poptGetArg(pc);
if (sequence == NULL) {
fprintf(stderr, "ERROR: missing sequence string\n");
return 1;
}
dbf = x_stderr;
DEBUGLEVEL = 0;
AllowDebugChange = false;
if (!lp_load(config_file,false,true,false,true)) {
fprintf(stderr,"Error loading services.\n");
return 1;
}
while(next_token_talloc(ctx, &sequence, &buff, NULL)) {
printf("[%s]\n", buff);
}
talloc_free(ctx);
return 0;
}
示例11: main
int main(int argc, const char *argv[])
{
int c;
char
*fetch = NULL,
*convert = NULL;
poptContext pc;
struct poptOption options[] = {
USERLAND_RESERVED_OPTIONS
{"fetch", 'f', POPT_ARG_STRING, &fetch, 0, "Fetch all wav files or specified wav file from the Palm", "[file|all]"},
{"convert", 'c', POPT_ARG_STRING, &convert, 0, "Convert <file>.wav.pdb file to wav", "file"},
POPT_TABLEEND
};
pc = poptGetContext("pilot-wav", argc, argv, options, 0);
poptSetOtherOptionHelp(pc,"\n\n"
" Decodes Palm Voice Memo files to wav files you can read\n\n"
" Example arguments: \n"
" pilot-wav -p /dev/pilot -f MyVoiceMemo.wav.pdb\n"
" pilot-wav -c MyVoiceMemo.wav.pdb\n\n");
if (argc < 2 ) {
poptPrintUsage(pc,stderr,0);
return 1;
}
while ((c = poptGetNextOpt(pc)) >= 0) {
fprintf(stderr," ERROR: Unhandled option %d.\n",c);
return 1;
}
if (c < -1) {
plu_badoption(pc,c);
}
if(convert != NULL)
pdb_to_wav(convert);
if(fetch != NULL)
do_fetch(fetch);
return 0;
}
示例12: g_new0
AirOptionCtx *air_option_context_new(
const char *helpstr,
int *argc,
char ***argv,
AirOptionEntry *entries)
{
AirOptionCtx *aoctx;
#if USE_GOPTION
GOptionContext *octx = NULL;
#elif USE_POPT
poptContext octx = NULL;
int i = 0;
#endif
aoctx = g_new0(AirOptionCtx, 1);
#if USE_GOPTION
octx = g_option_context_new(helpstr);
if (entries) {
g_option_context_add_main_entries(octx, entries, NULL);
}
#elif USE_POPT
aoctx->options = g_array_sized_new(TRUE, TRUE, sizeof(AirOptionEntry), 64);
if (entries) {
for (i=0; !AF_OPTION_EMPTY(entries[i]); i++) {
g_array_append_val(aoctx->options, entries[i]);
}
}
octx = poptGetContext(NULL, *argc, (const char **) *argv,
(AirOptionEntry *) aoctx->options->data, 0);
poptSetOtherOptionHelp(octx, helpstr);
#endif
aoctx->argc = argc;
aoctx->argv = argv;
aoctx->octx = octx;
return aoctx;
}
示例13: process_options
poptContext process_options(int argc, const char **argv,
struct poptOption *options,
const char *help)
{
int c;
poptContext opts = poptGetContext(NULL, argc, argv, options, 0);
poptSetOtherOptionHelp(opts, help);
while ((c = poptGetNextOpt(opts)) >= 0) {
/* no options require explicit handling */
}
if (c < -1) {
fprintf(stderr, "%s: %s\n",
poptBadOption(opts, POPT_BADOPTION_NOALIAS),
poptStrerror(c));
poptPrintUsage(opts, stderr, 0);
exit(1);
}
return opts;
}
示例14: poptSetOtherOptionHelp
bool Utils::parse(const poptContext& pc)
{ // http://privatemisc.blogspot.com/2012/12/popt-basic-example.html
poptSetOtherOptionHelp(pc, "[ARG...]");
// process options and handle each val returned
int val;
while ((val = poptGetNextOpt(pc)) >= 0)
{
}
// poptGetNextOpt returns -1 when the final argument has been parsed
if (val != -1)
{
poptPrintUsage(pc, stderr, 0);
// handle error
switch (val)
{
case POPT_ERROR_NOARG:
printf("Argument expected but missing for an option.\n");
return false;
case POPT_ERROR_BADOPT:
printf("Failed to parse argument.\n");
return false;
case POPT_ERROR_BADNUMBER:
case POPT_ERROR_OVERFLOW:
printf("Option could not be converted to number\n");
return false;
default:
printf("Unknown error in option processing\n");
return false;
}
}
poptFreeContext(pc);
return true;
}
示例15: main
int main(int argc, const char **argv)
{
poptContext pc;
int opt;
struct tevent_context *evt_ctx;
struct messaging_context *msg_ctx;
static struct poptOption long_options[] = {
/* POPT_AUTOHELP */
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, help_options,
0, "Help options:", NULL },
{ "timeout", 't', POPT_ARG_INT, &timeout, 't',
"Set timeout value in seconds", "TIMEOUT" },
POPT_COMMON_SAMBA
POPT_TABLEEND
};
TALLOC_CTX *frame = talloc_stackframe();
int ret = 0;
load_case_tables();
setup_logging(argv[0], DEBUG_STDOUT);
/* Parse command line arguments using popt */
pc = poptGetContext(
"smbcontrol", argc, (const char **)argv, long_options, 0);
poptSetOtherOptionHelp(pc, "[OPTION...] <destination> <message-type> "
"<parameters>");
if (argc == 1)
usage(pc);
while ((opt = poptGetNextOpt(pc)) != -1) {
switch(opt) {
case 't': /* --timeout */
break;
default:
fprintf(stderr, "Invalid option\n");
poptPrintHelp(pc, stderr, 0);
break;
}
}
/* We should now have the remaining command line arguments in
argv. The argc parameter should have been decremented to the
correct value in the above switch statement. */
argv = (const char **)poptGetArgs(pc);
argc = 0;
if (argv != NULL) {
while (argv[argc] != NULL) {
argc++;
}
}
if (argc <= 1)
usage(pc);
lp_load_global(get_dyn_CONFIGFILE());
/* Need to invert sense of return code -- samba
* routines mostly return True==1 for success, but
* shell needs 0. */
if (!(evt_ctx = tevent_context_init(NULL)) ||
!(msg_ctx = messaging_init(NULL, evt_ctx))) {
fprintf(stderr, "could not init messaging context\n");
TALLOC_FREE(frame);
exit(1);
}
ret = !do_command(evt_ctx, msg_ctx, argc, argv);
TALLOC_FREE(frame);
return ret;
}