• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ parse_argv函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中parse_argv函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_argv函数的具体用法?C++ parse_argv怎么用?C++ parse_argv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了parse_argv函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char*argv[]) {
        _cleanup_bus_unref_ sd_bus *bus = NULL;
        int r;

        setlocale(LC_ALL, "");
        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                goto finish;

        r = bus_open_transport(arg_transport, arg_host, false, &bus);
        if (r < 0) {
                log_error("Failed to create bus connection: %s", strerror(-r));
                goto finish;
        }

        r = localectl_main(bus, argc, argv);

finish:
        pager_close();

        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
开发者ID:ariscop,项目名称:systemd,代码行数:25,代码来源:localectl.c


示例2: init_chibach

void
init_chibach( int *argc, char ***argv ) {
  assert( argc != NULL );
  assert( argv != NULL );

  chibach_log = NULL;
  initialized = false;
  chibach_started = false;
  run_as_daemon = false;

  chibach_name = xstrdup( basename( *argv[ 0 ] ) );

  parse_argv( argc, argv );
  set_chibach_home();
  set_chibach_tmp();
  check_chibach_tmp();
  if ( run_as_daemon ) {
    init_log( get_chibach_name(), get_chibach_log(), LOGGING_TYPE_FILE );
  }
  else {
    init_log( get_chibach_name(), get_chibach_log(), LOGGING_TYPE_FILE | LOGGING_TYPE_STDOUT );
  }
  ignore_sigpipe();
  set_exit_handler();
  set_usr1_handler();
  init_stat();
  init_timer();
  init_messenger( get_chibach_tmp() );
  if ( datapath_id != 0 ) {
    init_openflow_switch_interface( datapath_id, controller.ip, controller.port );
  }

  initialized = true;
}
开发者ID:aigamo,项目名称:trema,代码行数:34,代码来源:chibach.c


示例3: main

int main(int argc, char*argv[]) {
        sd_bus *bus = NULL;
        int r;

        setlocale(LC_ALL, "");
        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                goto finish;

        r = bus_connect_transport(arg_transport, arg_host, false, &bus);
        if (r < 0) {
                log_error_errno(r, "Failed to create bus connection: %m");
                goto finish;
        }

        r = localectl_main(bus, argc, argv);

finish:
        /* make sure we terminate the bus connection first, and then close the
         * pager, see issue #3543 for the details. */
        sd_bus_flush_close_unref(bus);
        pager_close();

        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
开发者ID:halfline,项目名称:systemd,代码行数:28,代码来源:localectl.c


示例4: run

static int run(int argc, char *argv[]) {
        _cleanup_close_ int  fd = -1, saved_stderr = -1;
        int r;

        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                return r;

        fd = sd_journal_stream_fd(arg_identifier, arg_priority, arg_level_prefix);
        if (fd < 0)
                return log_error_errno(fd, "Failed to create stream fd: %m");

        saved_stderr = fcntl(STDERR_FILENO, F_DUPFD_CLOEXEC, 3);

        r = rearrange_stdio(STDIN_FILENO, fd, fd); /* Invalidates fd on succcess + error! */
        TAKE_FD(fd);
        if (r < 0)
                return log_error_errno(r, "Failed to rearrange stdout/stderr: %m");

        if (argc <= optind)
                (void) execl("/bin/cat", "/bin/cat", NULL);
        else
                (void) execvp(argv[optind], argv + optind);
        r = -errno;

        /* Let's try to restore a working stderr, so we can print the error message */
        if (saved_stderr >= 0)
                (void) dup3(saved_stderr, STDERR_FILENO, 0);

        return log_error_errno(r, "Failed to execute process: %m");
}
开发者ID:falconindy,项目名称:systemd,代码行数:34,代码来源:cat.c


示例5: main

int main(int argc, char* argv[])
{
	parse_argv(argc, argv);

	printf("listen address:     %s:%d\n", inet_ntoa(server_address.sin_addr),
		ntohs(server_address.sin_port));
	printf("broadcast address   %s:%d\n", inet_ntoa(bcast_address.sin_addr),
		ntohs(bcast_address.sin_port));
	printf("tftp address:       %s\n", inet_ntoa(tftp_ip));
	printf("nbp name:           %s\n", nbp_name);

	/* install signal handler */
	if (install_signal_handler() == -1) {
		perror("sigaction() failed");
		exit(-1);
	}

	/* init sockets */
	if (init_socket() == -1) {
		perror("init_socket()");
		release_all();
		exit(1);
	}

	if (foreground) {
		pdhcp();
	} else {
		daemon(0,0);
		pdhcp();
	}

	return 0;
}
开发者ID:EntropyWorks,项目名称:pxe-pdhcp,代码行数:33,代码来源:pxe-pdhcp.c


示例6: parse_config

void parse_config(char *configfile,struct mfshell_user_options *opts)
{
    FILE            *fp;

    char            **argv = NULL;              // create our own argv
    int             argc;                       // create one own argc
    int             new_items = 0;

    fp = fopen(configfile,"r");
    if(fp == NULL) return;

    // getopt_long() expect at least argc >= 1 and argv[0] != NULL
    argv = (char**)calloc(1,sizeof(char*));
    argv[0] = strdup("mediafire-shell");
    argc = 1;

    new_items = config_file_read(fp, &argc, &argv);
    fprintf(stderr,"argc = %d\n", argc);

    parse_argv(argc, argv, opts);

    if(new_items > 0)
    {
        string_array_free(argv);
    }
    else
    {
        free(argv[0]);
        free(argv);
    }

    return;
}
开发者ID:KrieghofGames,项目名称:mediafire-fuse,代码行数:33,代码来源:config.c


示例7: main

int main(int argc, char *argv[]) {
        _cleanup_strv_free_erase_ char **l = NULL;
        usec_t timeout;
        char **p;
        int r;

        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                goto finish;

        if (arg_timeout > 0)
                timeout = now(CLOCK_MONOTONIC) + arg_timeout;
        else
                timeout = 0;

        r = ask_password_auto(arg_message, arg_icon, arg_id, arg_keyname, timeout, arg_flags, &l);
        if (r < 0) {
                log_error_errno(r, "Failed to query password: %m");
                goto finish;
        }

        STRV_FOREACH(p, l) {
                puts(*p);

                if (!arg_multiple)
                        break;
        }
开发者ID:KrisShannon,项目名称:systemd,代码行数:30,代码来源:ask-password.c


示例8: main

int main(int argc, char *argv[]) {
        bool enabled;
        int r;

        r = parse_argv(argc, argv);
        if (r <= 0)
                goto finish;

        log_set_target(LOG_TARGET_AUTO);
        log_parse_environment();
        log_open();

        umask(0022);

        r = proc_cmdline_get_bool("systemd.firstboot", &enabled);
        if (r < 0) {
                log_error_errno(r, "Failed to parse systemd.firstboot= kernel command line argument, ignoring: %m");
                goto finish;
        }
        if (r > 0 && !enabled) {
                r = 0; /* disabled */
                goto finish;
        }

        r = process_locale();
        if (r < 0)
                goto finish;

        r = process_keymap();
        if (r < 0)
                goto finish;

        r = process_timezone();
        if (r < 0)
                goto finish;

        r = process_hostname();
        if (r < 0)
                goto finish;

        r = process_machine_id();
        if (r < 0)
                goto finish;

        r = process_root_password();
        if (r < 0)
                goto finish;

finish:
        free(arg_root);
        free(arg_locale);
        free(arg_locale_messages);
        free(arg_keymap);
        free(arg_timezone);
        free(arg_hostname);
        string_erase(arg_root_password);
        free(arg_root_password);

        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
开发者ID:htejun,项目名称:systemd,代码行数:60,代码来源:firstboot.c


示例9: builtin_main

int builtin_main(int argc, char *argv[], void *userdata) {
        _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
        enum udev_builtin_cmd cmd;
        int r;

        log_set_max_level(LOG_DEBUG);

        r = parse_argv(argc, argv);
        if (r <= 0)
                return r;

        udev_builtin_init();

        cmd = udev_builtin_lookup(arg_command);
        if (cmd < 0) {
                log_error("Unknown command '%s'", arg_command);
                r = -EINVAL;
                goto finish;
        }

        r = find_device(arg_syspath, "/sys", &dev);
        if (r < 0) {
                log_error_errno(r, "Failed to open device '%s': %m", arg_syspath);
                goto finish;
        }

        r = udev_builtin_run(dev, cmd, arg_command, true);
        if (r < 0)
                log_debug_errno(r, "Builtin command '%s' fails: %m", arg_command);

finish:
        udev_builtin_exit();
        return r;
}
开发者ID:htejun,项目名称:systemd,代码行数:34,代码来源:udevadm-test-builtin.c


示例10: main

int main(int argc, char *argv[]) {
        _cleanup_(evcat_freep) Evcat *e = NULL;
        int r;

        log_set_target(LOG_TARGET_AUTO);
        log_parse_environment();
        log_open();

        setlocale(LC_ALL, "");
        if (!is_locale_utf8())
                log_warning("Locale is not set to UTF-8. Codepoints will not be printed!");

        r = parse_argv(argc, argv);
        if (r <= 0)
                goto finish;

        r = evcat_new(&e);
        if (r < 0)
                goto finish;

        r = evcat_run(e);

finish:
        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
开发者ID:275288698,项目名称:systemd-ubuntu-with-dbus,代码行数:25,代码来源:evcat.c


示例11: main

int main(int argc, char *argv[]) {
        sd_bus *bus = NULL;
        int r;

        setlocale(LC_ALL, "");
        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                goto finish;

        r = bus_connect_transport(arg_transport, arg_host, false, &bus);
        if (r < 0) {
                log_error_errno(r, "Failed to create bus connection: %m");
                goto finish;
        }

        r = timedatectl_main(bus, argc, argv);

finish:
        sd_bus_flush_close_unref(bus);
        pager_close();

        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
开发者ID:GuillaumeSeren,项目名称:systemd,代码行数:26,代码来源:timedatectl.c


示例12: main

int main(int argc, char *argv[]) {
        _cleanup_(proxy_freep) Proxy *p = NULL;
        int r;

        log_set_target(LOG_TARGET_JOURNAL_OR_KMSG);
        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                goto finish;

        r = proxy_new(&p, STDIN_FILENO, STDOUT_FILENO, arg_address);
        if (r < 0)
                goto finish;

        r = rename_service(p->destination_bus, p->local_bus);
        if (r < 0)
                log_debug_errno(r, "Failed to rename process: %m");

        r = proxy_run(p);

finish:
        sd_notify(false,
                  "STOPPING=1\n"
                  "STATUS=Shutting down.");

        free(arg_address);

        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
开发者ID:RaghavanSanthanam,项目名称:systemd,代码行数:31,代码来源:stdio-bridge.c


示例13: main

int main(int argc, char *argv[]) {
        int r, k;
        struct kmod_ctx *ctx;

        r = parse_argv(argc, argv);
        if (r <= 0)
                return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;

        log_set_target(LOG_TARGET_AUTO);
        log_parse_environment();
        log_open();

        umask(0022);

        if (parse_proc_cmdline(parse_proc_cmdline_item) < 0)
                return EXIT_FAILURE;

        ctx = kmod_new(NULL, NULL);
        if (!ctx) {
                log_error("Failed to allocate memory for kmod.");
                goto finish;
        }

        kmod_load_resources(ctx);
        kmod_set_log_fn(ctx, systemd_kmod_log, NULL);

        r = 0;

        if (argc > optind) {
                int i;

                for (i = optind; i < argc; i++) {
                        k = apply_file(ctx, argv[i], false);
                        if (k < 0 && r == 0)
                                r = k;
                }

        } else {
                _cleanup_free_ char **files = NULL;
                char **fn, **i;

                STRV_FOREACH(i, arg_proc_cmdline_modules) {
                        k = load_module(ctx, *i);
                        if (k < 0 && r == 0)
                                r = k;
                }

                k = conf_files_list_nulstr(&files, ".conf", NULL, conf_file_dirs);
                if (k < 0) {
                        log_error("Failed to enumerate modules-load.d files: %s", strerror(-k));
                        if (r == 0)
                                r = k;
                        goto finish;
                }

                STRV_FOREACH(fn, files) {
                        k = apply_file(ctx, *fn, true);
                        if (k < 0 && r == 0)
                                r = k;
                }
开发者ID:vitalikp,项目名称:systemd,代码行数:60,代码来源:modules-load.c


示例14: main

int main(int argc, char **argv)
{
	struct manager *m = NULL;
	int r;

	srand(time(NULL));

	r = parse_argv(argc, argv);
	if (r < 0)
		return EXIT_FAILURE;
	if (!r)
		return EXIT_SUCCESS;

	r = manager_new(&m);
	if (r < 0)
		goto finish;

	r = sd_notify(false, "READY=1\n"
			     "STATUS=Running..");
	if (r < 0) {
		log_vERR(r);
		goto finish;
	}

	r = manager_run(m);

finish:
	sd_notify(false, "STATUS=Exiting..");
	manager_free(m);

	log_debug("exiting..");
	return abs(r);
}
开发者ID:275288698,项目名称:jiadu_miraclecast,代码行数:33,代码来源:miracled.c


示例15: parse_argv_for_restore

void parse_argv_for_restore(int argc, char * argv[], opts_restore_t * opts)
{
    parse_argv(argc, argv, &(opts->base));

    int c;
    opterr = 0;
    optind = 1;

    while ((c = getopt(argc, argv, "fri")) != -1) {
        switch (c) {
            case 'f':
                opts->strategy = STRATEGY_FLUSH;
                return;

            case 'r':
                opts->strategy = STRATEGY_REPLACE;
                return;

            case 'i':
                opts->strategy = STRATEGY_IGNORE;
                return;

            default:
                break;
        }
    }
}
开发者ID:nullptr-cc,项目名称:redis-extra-tools,代码行数:27,代码来源:redis_restore.c


示例16: main

int main(int argc, char* argv[]) {
        int r;

        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                goto finish;

        if (argc > optind) {
                int i, q;

                for (i = optind; i < argc; i++) {
                        q = print_home(argv[i]);
                        if (q < 0)
                                r = q;
                }
        } else
                r = list_homes();


finish:
        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
开发者ID:jrch2k10,项目名称:systemd-hicd,代码行数:25,代码来源:path.c


示例17: main

int main(int argc, char *argv[])
{
	mmatic *mm;
	struct flowcalc *fc;
	void *h;
	struct module *mod;
	char *name, *s;
	tlist *ls;
	void *pdata;

	/*
	 * initialization
	 */
	mm = mmatic_create();
	fc = mmatic_zalloc(mm, sizeof *fc);
	fc->mm = mm;
	fc->modules = tlist_create(NULL, mm);

	/* read options */
	if (parse_argv(fc, argc, argv))
		return 1;

	/* enable all modules found in given directory */
	if (tlist_count(fc->modules) == 0) {
		ls = pjf_ls(fc->dir, mm);
		tlist_iter_loop(ls, name) {
			s = strrchr(name, '.');
			if (s && streq(s, ".so")) {
				*s = 0;
				tlist_push(fc->modules, name);
			}
		}
开发者ID:VaniKandhasamy,项目名称:flowcalc,代码行数:32,代码来源:flowcalc.c


示例18: main

int main(int argc, char **argv)
{
	int ret;

	parse_argv(argc, argv);

	/* seed random number generator */
	srandom(time(NULL));

	worker_init();
	printf("testing single-proposer case...\n");
	ret = run_paxos(0);
	if (ret) {
		fprintf(stderr, "run_paxos(0) failed with error code %d\n",
			ret);
		return EXIT_FAILURE;
	}
	printf("testing multi-proposer case...\n");
	ret = run_paxos(1);
	if (ret) {
		fprintf(stderr, "run_paxos(1) failed with error code %d\n",
			ret);
		return EXIT_FAILURE;
	}
	return EXIT_SUCCESS;
}
开发者ID:cmccabe,项目名称:consensus-fun,代码行数:26,代码来源:test_paxos.c


示例19: main

int main(int argc, char *argv[]) {
        Context context = {};
        int r, n, fd;

        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                goto finish;

        r = sd_event_default(&context.event);
        if (r < 0) {
                log_error_errno(r, "Failed to allocate event loop: %m");
                goto finish;
        }

        r = sd_resolve_default(&context.resolve);
        if (r < 0) {
                log_error_errno(r, "Failed to allocate resolver: %m");
                goto finish;
        }

        r = sd_resolve_attach_event(context.resolve, context.event, 0);
        if (r < 0) {
                log_error_errno(r, "Failed to attach resolver: %m");
                goto finish;
        }

        sd_event_set_watchdog(context.event, true);

        n = sd_listen_fds(1);
        if (n < 0) {
                log_error("Failed to receive sockets from parent.");
                r = n;
                goto finish;
        } else if (n == 0) {
                log_error("Didn't get any sockets passed in.");
                r = -EINVAL;
                goto finish;
        }

        for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) {
                r = add_listen_socket(&context, fd);
                if (r < 0)
                        goto finish;
        }

        r = sd_event_loop(context.event);
        if (r < 0) {
                log_error_errno(r, "Failed to run event loop: %m");
                goto finish;
        }

finish:
        context_free(&context);

        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
开发者ID:floppym,项目名称:systemd,代码行数:59,代码来源:socket-proxyd.c


示例20: main

int main(int argc, char *argv[]) {
        const char *id = NULL;
        int retval = EXIT_SUCCESS;
        int r;

        /* This is mostly intended to be used for scripts which want
         * to detect whether we are being run in a virtualized
         * environment or not */

        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;

        switch (arg_mode) {

        case ANY_VIRTUALIZATION: {
                int v;

                v = detect_virtualization(&id);
                if (v < 0) {
                        log_error("Failed to check for virtualization: %s", strerror(-v));
                        return EXIT_FAILURE;
                }

                retval = v != VIRTUALIZATION_NONE ? EXIT_SUCCESS : EXIT_FAILURE;
                break;
        }

        case ONLY_CONTAINER:
                r = detect_container(&id);
                if (r < 0) {
                        log_error("Failed to check for container: %s", strerror(-r));
                        return EXIT_FAILURE;
                }

                retval = r > 0 ? EXIT_SUCCESS : EXIT_FAILURE;
                break;

        case ONLY_VM:
                r = detect_vm(&id);
                if (r < 0) {
                        log_error("Failed to check for vm: %s", strerror(-r));
                        return EXIT_FAILURE;
                }

                retval = r > 0 ? EXIT_SUCCESS : EXIT_FAILURE;
                break;
        }

        if (!arg_quiet)
                puts(id ? id : "none");

        return retval;
}
开发者ID:MOBO-OSS,项目名称:systemd-relative,代码行数:57,代码来源:detect-virt.c



注:本文中的parse_argv函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ parse_array函数代码示例发布时间:2022-05-30
下一篇:
C++ parse_arguments函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap