本文整理汇总了C++中opt_init函数的典型用法代码示例。如果您正苦于以下问题:C++ opt_init函数的具体用法?C++ opt_init怎么用?C++ opt_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了opt_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: opt_init
/* duck: search duckduckgo with a query string */
int CmdHandler::duck(char *out, struct command *c)
{
char query[MAX_MSG];
int opt;
static struct l_option long_opts[] = {
{ "help", NO_ARG, 'h' },
{ 0, 0, 0 }
};
opt_init();
while ((opt = l_getopt_long(c->argc, c->argv, "", long_opts)) != EOF) {
switch (opt) {
case 'h':
HELPMSG(out, CMDNAME, CMDUSAGE, CMDDESCR);
return EXIT_SUCCESS;
case '?':
snprintf(out, MAX_MSG, "%s", l_opterr());
return EXIT_FAILURE;
default:
return EXIT_FAILURE;
}
}
if (l_optind == c->argc) {
USAGEMSG(out, CMDNAME, CMDUSAGE);
return EXIT_FAILURE;
}
argvcat(query, c->argc, c->argv, l_optind, 1);
snprintf(out, MAX_MSG, "[DUCK] %s%s", DDG_QUERY, tw::pencode(query).c_str());
return EXIT_SUCCESS;
}
示例2: option_table_create
/*
* Create getopt_long(3) option table and return.
* Also create shortopts table if sp != NULL and return by value.
*/
static struct option * option_table_create (optparse_t p, char **sp)
{
struct option_info *o;
struct option *opts;
int n;
int j;
ListIterator i;
n = list_count (p->option_list);
opts = malloc ((n + 1) * sizeof (struct option));
if (opts == NULL)
return (NULL);
j = 0;
i = list_iterator_create (p->option_list);
while ((o = list_next (i))) {
if (o->isdoc)
continue;
/* Initialize option field from cached option structure */
opt_init (&opts[j++], o->p_opt);
if (sp) {
*sp = optstring_append (*sp, o->p_opt);
if (*sp == NULL) {
free (opts);
opts = NULL;
break;
}
}
}
list_iterator_destroy (i);
return (opts);
}
示例3: opt_init
/* active: view current poll */
int CmdHandler::active(char *out, struct command *c)
{
int opt;
static struct l_option long_opts[] = {
{ "help", NO_ARG, 'h' },
{ 0, 0, 0 }
};
opt_init();
while ((opt = l_getopt_long(c->argc, c->argv, "", long_opts)) != EOF) {
switch (opt) {
case 'h':
HELPMSG(out, CMDNAME, CMDUSAGE, CMDDESCR);
return EXIT_SUCCESS;
case '?':
snprintf(out, MAX_MSG, "%s", l_opterr());
return EXIT_FAILURE;
default:
return EXIT_FAILURE;
}
}
if (l_optind != c->argc) {
USAGEMSG(out, CMDNAME, CMDUSAGE);
return EXIT_FAILURE;
}
if (!*poll)
snprintf(out, MAX_MSG, "[ACTIVE] no poll has been created");
else
snprintf(out, MAX_MSG, "[ACTIVE] %s/%s", SP_HOST, poll);
return EXIT_SUCCESS;
}
示例4: main
int main(int argc,char** argv)
{
//load config
configure conf(conf_path);
conf.parse_config_file();
//conf.load_from_db(); //从远程数据库加载参数
conf.load_from_url(); //从远程url加载参数
//conf.debug_print();
//parse opt
if(!opt_init(argc,argv,conf))
return 0;
//load module manager
modmgr mgr(&conf);
mgr.load_modules(conf.modules_path);
//mgr.print_modules();
//start
switch(conf.run_state)
{
case RUN_CRON:
run_cron(conf,mgr);
break;
case RUN_LIVE:
run_live(conf,mgr);
break;
case RUN_NULL:
break;
}
return 0;
}
示例5: parse_opts
static int parse_opts(int argc, char** argv, options_t* opt)
{
opt_state_t s;
int id;
opt_init(args, &s, &argc, argv);
while((id = opt_next(&s)) != -1)
{
switch(id)
{
case OPT_THREADS: opt->threads = atoi(s.arg_val); break;
case OPT_CDMIN: opt->cd_min_deferred = atoi(s.arg_val); break;
case OPT_CDMAX: opt->cd_max_deferred = atoi(s.arg_val); break;
case OPT_CDCONF: opt->cd_conf_group = atoi(s.arg_val); break;
case OPT_GCINITIAL: opt->gc_initial = atoi(s.arg_val); break;
case OPT_GCFACTOR: opt->gc_factor = atof(s.arg_val); break;
case OPT_SCHED:
if(!strcmp(s.arg_val, "coop"))
opt->mpmcq = false;
else if(!strcmp(s.arg_val, "mpmcq"))
opt->mpmcq = true;
break;
case OPT_NOYIELD: opt->noyield = true; break;
case OPT_FORCECD: opt->forcecd = true; break;
default: exit(-1);
}
}
argv[argc] = NULL;
return argc;
}
示例6: bpf_optimize
/*
* Optimize the filter code in its dag representation.
*/
void
bpf_optimize(struct block **rootp)
{
struct block *root;
root = *rootp;
opt_init(root);
opt_loop(root, 0);
opt_loop(root, 1);
intern_blocks(root);
#ifdef BDEBUG
if (dflag > 1) {
printf("after intern_blocks()\n");
opt_dump(root);
}
#endif
opt_root(rootp);
#ifdef BDEBUG
if (dflag > 1) {
printf("after opt_root()\n");
opt_dump(root);
}
#endif
opt_cleanup();
}
示例7: genrsa_main
int genrsa_main(int argc, char **argv)
{
BN_GENCB *cb = BN_GENCB_new();
PW_CB_DATA cb_data;
ENGINE *eng = NULL;
BIGNUM *bn = BN_new();
BIO *out = NULL;
BIGNUM *e;
RSA *rsa = NULL;
const EVP_CIPHER *enc = NULL;
int ret = 1, num = DEFBITS, private = 0;
unsigned long f4 = RSA_F4;
char *outfile = NULL, *passoutarg = NULL, *passout = NULL;
char *inrand = NULL, *prog, *hexe, *dece;
OPTION_CHOICE o;
if (bn == NULL || cb == NULL)
goto end;
BN_GENCB_set(cb, genrsa_cb, bio_err);
prog = opt_init(argc, argv, genrsa_options);
while ((o = opt_next()) != OPT_EOF) {
switch (o) {
case OPT_EOF:
case OPT_ERR:
BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
goto end;
case OPT_HELP:
ret = 0;
opt_help(genrsa_options);
goto end;
case OPT_3:
f4 = 3;
break;
case OPT_F4:
f4 = RSA_F4;
break;
case OPT_OUT:
outfile = opt_arg();
break;
case OPT_ENGINE:
eng = setup_engine(opt_arg(), 0);
break;
case OPT_RAND:
inrand = opt_arg();
break;
case OPT_PASSOUT:
passoutarg = opt_arg();
break;
case OPT_CIPHER:
if (!opt_cipher(opt_unknown(), &enc))
goto end;
break;
}
}
argc = opt_num_rest();
argv = opt_rest();
private = 1;
示例8: john_init
static void john_init(char *name, int argc, char **argv)
{
int make_check = (argc == 2 && !strcmp(argv[1], "--make_check"));
if (make_check)
argv[1] = "--test=0";
#if CPU_DETECT
if (!CPU_detect()) {
#if CPU_REQ
#if CPU_FALLBACK
#if defined(__DJGPP__) || defined(__CYGWIN32__)
#error CPU_FALLBACK is incompatible with the current DOS and Win32 code
#endif
if (!make_check) {
#define CPU_FALLBACK_PATHNAME JOHN_SYSTEMWIDE_EXEC "/" CPU_FALLBACK_BINARY
execv(CPU_FALLBACK_PATHNAME, argv);
perror("execv: " CPU_FALLBACK_PATHNAME);
}
#endif
fprintf(stderr, "Sorry, %s is required\n", CPU_NAME);
if (make_check)
exit(0);
error();
#endif
}
#endif
if (!make_check) {
path_init(argv);
status_init(NULL, 1);
opt_init(name, argc, argv);
if (options.flags & FLG_CONFIG_CLI)
{
cfg_init(options.config, 1);
cfg_init(CFG_ALT_NAME, 0);
}
else
{
#if JOHN_SYSTEMWIDE
cfg_init(CFG_PRIVATE_FULL_NAME, 1);
cfg_init(CFG_PRIVATE_ALT_NAME, 1);
#endif
cfg_init(CFG_FULL_NAME, 1);
cfg_init(CFG_ALT_NAME, 0);
}
}
john_register_all();
common_init();
sig_init();
john_load();
}
示例9: help_main
int help_main(int argc, char **argv)
{
FUNCTION *fp;
int i, nl;
FUNC_TYPE tp;
char *prog;
HELP_CHOICE o;
DISPLAY_COLUMNS dc;
prog = opt_init(argc, argv, help_options);
while ((o = opt_next()) != OPT_hEOF) {
switch (o) {
case OPT_hERR:
case OPT_hEOF:
BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
return 1;
case OPT_hHELP:
opt_help(help_options);
return 0;
}
}
if (opt_num_rest() != 0) {
BIO_printf(bio_err, "Usage: %s\n", prog);
return 1;
}
calculate_columns(&dc);
BIO_printf(bio_err, "Standard commands");
i = 0;
tp = FT_none;
for (fp = functions; fp->name != NULL; fp++) {
nl = 0;
if (i++ % dc.columns == 0) {
BIO_printf(bio_err, "\n");
nl = 1;
}
if (fp->type != tp) {
tp = fp->type;
if (!nl)
BIO_printf(bio_err, "\n");
if (tp == FT_md) {
i = 1;
BIO_printf(bio_err,
"\nMessage Digest commands (see the `dgst' command for more details)\n");
} else if (tp == FT_cipher) {
i = 1;
BIO_printf(bio_err,
"\nCipher commands (see the `enc' command for more details)\n");
}
}
BIO_printf(bio_err, "%-*s", dc.width, fp->name);
}
BIO_printf(bio_err, "\n\n");
return 0;
}
示例10: help_main
int help_main(int argc, char **argv)
{
FUNCTION *fp;
int i, nl;
FUNC_TYPE tp;
char *prog;
HELPLIST_CHOICE o;
prog = opt_init(argc, argv, help_options);
while ((o = opt_next()) != OPT_EOF) {
switch (o) {
default:
BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
return 1;
case OPT_HELP:
opt_help(help_options);
return 0;
}
}
argc = opt_num_rest();
argv = opt_rest();
if (argc != 0) {
BIO_printf(bio_err, "Usage: %s\n", prog);
return 1;
}
BIO_printf(bio_err, "\nStandard commands");
i = 0;
tp = FT_none;
for (fp = functions; fp->name != NULL; fp++) {
nl = 0;
if (((i++) % COLUMNS) == 0) {
BIO_printf(bio_err, "\n");
nl = 1;
}
if (fp->type != tp) {
tp = fp->type;
if (!nl)
BIO_printf(bio_err, "\n");
if (tp == FT_md) {
i = 1;
BIO_printf(bio_err,
"\nMessage Digest commands (see the `dgst' command for more details)\n");
} else if (tp == FT_cipher) {
i = 1;
BIO_printf(bio_err,
"\nCipher commands (see the `enc' command for more details)\n");
}
}
BIO_printf(bio_err, FORMAT, fp->name);
}
BIO_printf(bio_err, "\n\n");
return 0;
}
示例11: list_main
int list_main(int argc, char **argv)
{
char *prog;
HELPLIST_CHOICE o;
int done = 0;
prog = opt_init(argc, argv, list_options);
while ((o = opt_next()) != OPT_EOF) {
switch (o) {
case OPT_EOF: /* Never hit, but suppresses warning */
case OPT_ERR:
BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
return 1;
case OPT_HELP:
opt_help(list_options);
break;
case OPT_COMMANDS:
list_type(FT_general);
break;
case OPT_DIGEST_COMMANDS:
list_type(FT_md);
break;
case OPT_DIGEST_ALGORITHMS:
EVP_MD_do_all_sorted(list_md_fn, bio_out);
break;
case OPT_CIPHER_COMMANDS:
list_type(FT_cipher);
break;
case OPT_CIPHER_ALGORITHMS:
EVP_CIPHER_do_all_sorted(list_cipher_fn, bio_out);
break;
case OPT_PK_ALGORITHMS:
list_pkey();
break;
case OPT_PK_METHOD:
list_pkey_meth();
break;
case OPT_DISABLED:
list_disabled();
break;
case OPT_MISSING_HELP:
list_missing_help();
break;
}
done = 1;
}
if (!done) {
BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
return 1;
}
return 0;
}
示例12: main
int main(int ac, char **av)
{
OPTION_CHOICE o;
char **rest;
char *prog;
bio_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
prog = opt_init(ac, av, options);
while ((o = opt_next()) != OPT_EOF) {
switch (c) {
case OPT_NOTUSED:
case OPT_EOF:
case OPT_ERR:
printf("%s: Usage error; try -help.\n", prog);
return 1;
case OPT_HELP:
opt_help(options);
return 0;
case OPT_IN:
printf("in %s\n", opt_arg());
break;
case OPT_INFORM:
printf("inform %s\n", opt_arg());
break;
case OPT_OUT:
printf("out %s\n", opt_arg());
break;
case OPT_COUNT:
printf("count %s\n", opt_arg());
break;
case OPT_U:
printf("u %s\n", opt_arg());
break;
case OPT_FLAG:
printf("flag\n");
break;
case OPT_STR:
printf("str %s\n", opt_arg());
break;
}
}
argc = opt_num_rest();
argv = opt_rest();
printf("args = %d\n", argc);
if (argc)
while (*argv)
printf(" %s\n", *argv++);
return 0;
}
示例13: main
/**
@brief AutoBuilder Entry Point
@param argc Number of arguments passed through argv
@param argv String representation of arguments passed to the
application
@return EXIT_SUCCESS on success or a non-zero integer on failure.
**/
int
main (int argc, char ** argv)
{
conf_t conf;
conf_err_t cerr;
opt_t opt;
opt_err_t oerr;
const char *db_type, *db_host, *db_port, *db_user, *db_pass, *db_db;
/* Parse the command line */
oerr = opt_init(&opt, argc, argv, 1);
if (oerr != OPT_OK)
{
fprintf (stderr, "%s\n", SHORT_HELP);
opt_destroy (&opt);
return EXIT_FAILURE;
}
if (opt.help)
{
fprintf (stderr, "%s\n", HELP_TXT);
return EXIT_SUCCESS;
}
/* Parse the configuration */
cerr = conf_init (&conf, opt.conf);
if (cerr != CONF_OK)
{
fprintf (stderr, "Configuration Error: %s", conf_get_err (&conf));
conf_destroy (&conf);
opt_destroy (&opt);
return EXIT_FAILURE;
}
/* Read Database Options */
db_type = conf_get (&conf, "DB_TYPE");
db_host = conf_get (&conf, "DB_HOST");
db_port = conf_get (&conf, "DB_PORT");
db_user = conf_get (&conf, "DB_USER");
db_pass = conf_get (&conf, "DB_PASS");
db_db = conf_get (&conf, "DB_DB");
/* Connect to the database */
//db_connect (db_type, db_host, db_port, db_user, db_pass, db_db);
/* Cleanup */
conf_destroy (&conf);
opt_destroy (&opt);
return EXIT_SUCCESS;
}
示例14: opt_init
/* about: print bot information */
int CmdHandler::about(char *out, struct command *c)
{
int opt, type;
static struct l_option long_opts[] = {
{ "help", NO_ARG, 'h' },
{ "latest-release", NO_ARG, 'r' },
{ "source", NO_ARG, 's' },
{ 0, 0, 0 }
};
opt_init();
type = ABT;
while ((opt = l_getopt_long(c->argc, c->argv, "rs", long_opts)) != EOF) {
switch (opt) {
case 'h':
HELPMSG(out, CMDNAME, CMDUSAGE, CMDDESCR);
return EXIT_SUCCESS;
case 'r':
type = REL;
break;
case 's':
type = SRC;
break;
case '?':
snprintf(out, MAX_MSG, "%s", l_opterr());
return EXIT_FAILURE;
default:
return EXIT_FAILURE;
}
}
if (l_optind != c->argc) {
USAGEMSG(out, CMDNAME, CMDUSAGE);
return EXIT_FAILURE;
}
switch (type) {
case REL:
case SRC:
snprintf(out, MAX_MSG, "[ABOUT] %s",
type == REL ? RELEASE : SOURCE);
break;
default:
snprintf(out, MAX_MSG, "[ABOUT] %s is running " BOT_NAME
" " BOT_VERSION ". Find out more at "
BOT_WEBSITE, bot_name);
break;
}
return EXIT_SUCCESS;
}
示例15: gendsa_main
int gendsa_main(int argc, char **argv)
{
ENGINE *e = NULL;
BIO *out = NULL, *in = NULL;
DSA *dsa = NULL;
const EVP_CIPHER *enc = NULL;
char *dsaparams = NULL;
char *outfile = NULL, *passoutarg = NULL, *passout = NULL, *prog;
OPTION_CHOICE o;
int ret = 1, private = 0, verbose = 0;
const BIGNUM *p = NULL;
prog = opt_init(argc, argv, gendsa_options);
while ((o = opt_next()) != OPT_EOF) {
switch (o) {
case OPT_EOF:
case OPT_ERR:
opthelp:
BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
goto end;
case OPT_HELP:
ret = 0;
opt_help(gendsa_options);
goto end;
case OPT_OUT:
outfile = opt_arg();
break;
case OPT_PASSOUT:
passoutarg = opt_arg();
break;
case OPT_ENGINE:
e = setup_engine(opt_arg(), 0);
break;
case OPT_R_CASES:
if (!opt_rand(o))
goto end;
break;
case OPT_CIPHER:
if (!opt_cipher(opt_unknown(), &enc))
goto end;
break;
case OPT_VERBOSE:
verbose = 1;
break;
}
}
argc = opt_num_rest();
argv = opt_rest();
private = 1;