static bool recdirectory(void) { static const struct opt_items names[] = { { rec_base_directory, -1 }, { STR(LANG_RECORD_CURRENT_DIR) } }; return set_option(str(LANG_RECORD_DIRECTORY), &global_settings.rec_directory, INT, names, 2, NULL ); }
static bool recchannels(void) { static const struct opt_items names[] = { { STR(LANG_CHANNEL_STEREO) }, { STR(LANG_CHANNEL_MONO) } }; return set_option(str(LANG_RECORDING_CHANNELS), &global_settings.rec_channels, INT, names, 2, NULL ); }
int main(int argc, char *argv[]) { int i=1; for (;i<argc; ++i) set_option(argv[i]); load_configure(); nodenet_startup(); return 0; }
int imap_wait_keepalive (pid_t pid) { struct sigaction oldalrm; struct sigaction act; sigset_t oldmask; int rc; short imap_passive = option (OPTIMAPPASSIVE); set_option (OPTIMAPPASSIVE); set_option (OPTKEEPQUIET); sigprocmask (SIG_SETMASK, NULL, &oldmask); sigemptyset (&act.sa_mask); act.sa_handler = alrm_handler; #ifdef SA_INTERRUPT act.sa_flags = SA_INTERRUPT; #else act.sa_flags = 0; #endif sigaction (SIGALRM, &act, &oldalrm); alarm (ImapKeepalive); while (waitpid (pid, &rc, 0) < 0 && errno == EINTR) { alarm (0); /* cancel a possibly pending alarm */ imap_keepalive (); alarm (ImapKeepalive); } alarm (0); /* cancel a possibly pending alarm */ sigaction (SIGALRM, &oldalrm, NULL); sigprocmask (SIG_SETMASK, &oldmask, NULL); unset_option (OPTKEEPQUIET); if (!imap_passive) unset_option (OPTIMAPPASSIVE); return rc; }
//{{{ void options_menu(void) { int choice; int old_value, new_value; int change_made = 0; setTabStops(options_menu_tabs); UI_Menu_Set_Persist(1); while(1) { #ifdef OPTIONS_SUBMENUS choice = UI_Menu_Pick(options_rect, count_options()+OPTIONS_SUBMENUS, &cb_options_menu); if(choice>=0 && choice<OPTIONS_SUBMENUS) { pick_submenu(choice); change_made = 1; continue; } else { choice -= OPTIONS_SUBMENUS; } #else choice = UI_Menu_Pick(options_rect, count_options(), &cb_options_menu); #endif if(choice<0) break; old_value = get_option(options[choice].key); new_value = (old_value+1) % count_choices(options[choice].choices); set_option(options[choice].key, new_value); change_made = 1; #ifdef IS_CALCULATOR if(options[choice].key == OPTION_GRAYSCALE) { if(get_option(OPTION_GRAYSCALE) == OPTION_GRAY_ON) GrayOnThrow(); else GrayOff(); if(w->level) // Only if game is started full_redraw(); } #endif #ifdef PALMOS if(options[choice].key == OPTION_INVERSE) init_colors(); #endif #ifdef REALCOMPUTER if(options[choice].key == OPTION_COLOR) init_colors(); #endif } UI_Menu_Set_Persist(0); if(change_made) save_options(); }
static void start_civetweb(int argc, char *argv[]) { struct mg_callbacks callbacks; char *options[MAX_OPTIONS]; int i; // Edit passwords file if -A option is specified if (argc > 1 && !strcmp(argv[1], "-A")) { if (argc != 6) { show_usage_and_exit(); } exit(mg_modify_passwords_file(argv[2], argv[3], argv[4], argv[5]) ? EXIT_SUCCESS : EXIT_FAILURE); } // Show usage if -h or --help options are specified if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) { show_usage_and_exit(); } options[0] = NULL; set_option(options, "document_root", "."); // Update config based on command line arguments process_command_line_arguments(argv, options); // Make sure we have absolute paths for files and directories set_absolute_path(options, "document_root", argv[0]); set_absolute_path(options, "put_delete_auth_file", argv[0]); set_absolute_path(options, "cgi_interpreter", argv[0]); set_absolute_path(options, "access_log_file", argv[0]); set_absolute_path(options, "error_log_file", argv[0]); set_absolute_path(options, "global_auth_file", argv[0]); set_absolute_path(options, "ssl_certificate", argv[0]); // Make extra verification for certain options verify_existence(options, "document_root", 1); verify_existence(options, "cgi_interpreter", 0); verify_existence(options, "ssl_certificate", 0); // Setup signal handler: quit on Ctrl-C signal(SIGTERM, signal_handler); signal(SIGINT, signal_handler); // Start Civetweb memset(&callbacks, 0, sizeof(callbacks)); callbacks.log_message = &log_message; ctx = mg_start(&callbacks, NULL, (const char **) options); for (i = 0; options[i] != NULL; i++) { free(options[i]); } if (ctx == NULL) { die("%s", "Failed to start Civetweb."); } }
/* Examines any relevant environment variables. Must be called when in * single-thread mode. */ static void read_environment () { Option *o; for (o = vars; o->env; o++) { char *val; if ((val = (char *) getenv (o->env))) set_option (o, val, "Environment variable", o->env); } }
void bind_and_listen(const std::string& port,bool reuse_addr) { boost::asio::ip::tcp::resolver resolver(get_io_service()); boost::asio::ip::tcp::resolver::query query(boost::asio::ip::tcp::v4(),port); boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query); open(endpoint.protocol()); if(reuse_addr) { set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); } bind(endpoint); listen(boost::asio::socket_base::max_connections); }
static bool autoloadbookmark(void) { static const struct opt_items names[] = { { STR(LANG_SET_BOOL_NO) }, { STR(LANG_SET_BOOL_YES) }, { STR(LANG_RESUME_SETTING_ASK) } }; return set_option( str(LANG_BOOKMARK_SETTINGS_AUTOLOAD), &global_settings.autoloadbookmark, INT, names, 3, NULL ); }
int dotogglepickup(void) { union nh_optvalue val; val.b = !flags.pickup; set_option("autopickup", val, FALSE); pline("Autopickup: %s.", flags.pickup ? "ON" : "OFF"); return 0; }
static void set_parameters (struct _options *opts, int flags, int argc, const char **argv) { opts->opt_silent = flags & PAM_SILENT; opts->opt_disallow_null_authtok = flags & PAM_DISALLOW_NULL_AUTHTOK; while (argc-- > 0) { set_option (opts, *argv); ++argv; } }
static bool useMRB(void) { static const struct opt_items names[] = { { STR(LANG_SET_BOOL_NO) }, { STR(LANG_SET_BOOL_YES) }, { STR(LANG_BOOKMARK_SETTINGS_UNIQUE_ONLY) } }; return set_option( str(LANG_BOOKMARK_SETTINGS_MAINTAIN_RECENT_BOOKMARKS), &global_settings.usemrb, INT, names, 3, NULL ); }
boolean nh_set_option(const char *name, union nh_optvalue value, boolean isstring) { boolean rv; if (!api_entry_checkpoint()) return FALSE; rv = set_option(name, value, isstring); api_exit(); return rv; }
/* * Process any command-line switches and any additional GUC variable * settings passed in the startup packet. */ static void process_startup_options(struct session *port, bool am_superuser) { enum guc_ctx gucctx; struct list_cell* gucopts; gucctx = am_superuser ? PGC_SUSET : PGC_BACKEND; /* * First process any command-line switches that were included in the * startup packet, if we are in a regular backend. */ if (port->cmdline_options != NULL) { /* * The maximum possible number of commandline arguments that could * come from port->cmdline_options is (strlen + 1) / 2; see * pg_split_opts(). */ char **av; int maxac; int ac; maxac = 2 + (strlen(port->cmdline_options) + 1) / 2; av = (char**) palloc(maxac * sizeof(char *)); ac = 0; av[ac++] = "postgres"; /* Note this mangles port->cmdline_options */ pg_split_opts(av, &ac, port->cmdline_options); av[ac] = NULL; ASSERT(ac < maxac); (void) process_postgres_switches(ac, av, gucctx); } /* * Process any additional GUC variable settings passed in startup packet. * These are handled exactly like command-line variables. */ gucopts = list_head(port->guc_options); while (gucopts) { char *name; char *value; name = lfirst(gucopts); gucopts = lnext(gucopts); value = lfirst(gucopts); gucopts = lnext(gucopts); set_option(name, value, gucctx, PGC_S_CLIENT); } }
static bool avc(void) { static const struct opt_items names[] = { { STR(LANG_OFF) }, { "20ms", TALK_ID(20, UNIT_MS) }, { "2s", TALK_ID(2, UNIT_SEC) }, { "4s", TALK_ID(4, UNIT_SEC) }, { "8s", TALK_ID(8, UNIT_SEC) } }; return set_option(str(LANG_DECAY), &global_settings.avc, INT, names, 5, set_avc); }
UnixSocketAcceptor<Protocol, Dispatcher>::UnixSocketAcceptor(Dispatcher &dispatcher, UnixEndpoint<Protocol> const &ep, UnixSocketBase::ReuseAddress reuse) : _dispatcher(dispatcher), _fd(-1) { Error err; open(ep.protocol(), err); set_option(reuse, err); bind(ep, err); listen(SOMAXCONN, err); }
static bool backlight_fade_in(void) { static const struct opt_items names[] = { { STR(LANG_OFF) }, { "500ms", TALK_ID(500, UNIT_MS) }, { "1s", TALK_ID(1, UNIT_SEC) }, { "2s", TALK_ID(2, UNIT_SEC) }, }; return set_option(str(LANG_BACKLIGHT_FADE_IN), &global_settings.backlight_fade_in, INT, names, 4, backlight_set_fade_in ); }
static bool dir_filter(void) { static const struct opt_items names[] = { { STR(LANG_FILTER_ALL) }, { STR(LANG_FILTER_SUPPORTED) }, { STR(LANG_FILTER_MUSIC) }, { STR(LANG_FILTER_PLAYLIST) }, { STR(LANG_FILTER_ID3DB) } }; return set_option( str(LANG_FILTER), &global_settings.dirfilter, INT, names, 5, NULL ); }
boolean nh_set_option(const char *name, union nh_optvalue value) { boolean rv; API_ENTRY_CHECKPOINT_RETURN_ON_ERROR(FALSE); rv = set_option(name, value, NULL); API_EXIT(); return rv; }
int main(int argc, char *const argv[]) { int opt; char *srvaddr = "127.0.0.1"; int id = 11; int tag = 1; /* the id and server address don't really matter, * as we don't register to the server. */ while ((opt = getopt(argc, argv, "i:S:nf:t:h:d:")) != -1) { switch (opt) { case 'i': id = atoi(optarg); break; case 'S': srvaddr = optarg; break; case 'n': nonblock = 1; break; case 'f': rate = atoi(optarg); break; case 't': tag = atoi(optarg); break; case 'h': hold = atoi(optarg); break; case 'd': parse_sockaddr_in(&dest_addr, optarg); /* default send to the xcast's port if not set. */ if( dest_addr.sin_port == 0 ) dest_addr.sin_port = htons(MIX_CAST_PORT); break; } } open_audio_out(); set_option(OPT_ACCESS_RAW_AUDIO_PACK, 1); set_event_callback(on_event); id |= (tag<<16); //wrap tag and id client_init(id, DEVTYPE_NETPLAY, srvaddr, AUDIO_PORT); while(1) sleep(10000); return 0; }
static void process_command_line_arguments(char *argv[], char **options) { char *p; FILE *fp = NULL; size_t i, cmd_line_opts_start = 1, line_no = 0; /* Should we use a config file ? */ if (argv[1] != NULL && argv[1][0] != '-') { snprintf(config_file, sizeof(config_file), "%s", argv[1]); cmd_line_opts_start = 2; } else if ((p = strrchr(argv[0], DIRSEP)) == NULL) { /* No command line flags specified. Look where binary lives */ snprintf(config_file, sizeof(config_file)-1, "%s", CONFIG_FILE); config_file[sizeof(config_file)-1] = 0; } else { snprintf(config_file, sizeof(config_file)-1, "%.*s%c%s", (int) (p - argv[0]), argv[0], DIRSEP, CONFIG_FILE); config_file[sizeof(config_file)-1] = 0; } #ifdef CONFIG_FILE2 fp = fopen(config_file, "r"); /* try alternate config file */ if (fp == NULL) { fp = fopen(CONFIG_FILE2, "r"); if (fp != NULL) { strcpy(config_file, CONFIG_FILE2); } } if (fp != NULL) { fclose(fp); } #endif /* read all configurations from a config file */ (void)read_config_file(config_file, options); /* If we're under MacOS and started by launchd, then the second argument is process serial number, -psn_..... In this case, don't process arguments at all. */ if (argv[1] == NULL || memcmp(argv[1], "-psn_", 5) != 0) { /* Handle command line flags. They override config file and default settings. */ for (i = cmd_line_opts_start; argv[i] != NULL; i += 2) { if (argv[i][0] != '-' || argv[i + 1] == NULL) { show_usage_and_exit(); } set_option(options, &argv[i][1], argv[i + 1]); } } }
int mutt_parse_score (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) { SCORE *ptr, *last; char *pattern, *pc; struct pattern_t *pat; mutt_extract_token (buf, s, 0); if (!MoreArgs (s)) { strfcpy (err->data, _("score: too few arguments"), err->dsize); return (-1); } pattern = buf->data; memset (buf, 0, sizeof (BUFFER)); mutt_extract_token (buf, s, 0); if (MoreArgs (s)) { FREE (&pattern); strfcpy (err->data, _("score: too many arguments"), err->dsize); return (-1); } /* look for an existing entry and update the value, else add it to the end of the list */ for (ptr = Score, last = NULL; ptr; last = ptr, ptr = ptr->next) if (mutt_strcmp (pattern, ptr->str) == 0) break; if (!ptr) { if ((pat = mutt_pattern_comp (pattern, 0, err)) == NULL) { FREE (&pattern); return (-1); } ptr = safe_calloc (1, sizeof (SCORE)); if (last) last->next = ptr; else Score = ptr; ptr->pat = pat; ptr->str = pattern; } pc = buf->data; if (*pc == '=') { ptr->exact = 1; pc++; } ptr->val = atoi (pc); set_option (OPTNEEDRESCORE); return 0; }
bool http_client::open(const std::string& url) { set_option(CURLOPT_URL, url.c_str()); if (!request_init()) { return false; } CURLcode code = curl_easy_perform(_curl); // 每次执行完当次请求,重置请求类型为get<默认> // fixed bugs: post请求后,继续用该curl发的所有请求都变成post的。 set_option(CURLOPT_POST, 0); if (CURLE_OK != code) { return false; } return true; }
static bool voice_files(void) { int oldval = global_settings.talk_file; bool ret; ret = set_option( str(LANG_VOICE_FILE), &global_settings.talk_file, INT, voice_names, 4, NULL); if (oldval != 3 && global_settings.talk_file == 3) { /* force reload if newly talking thumbnails, because the clip presence is cached only if enabled */ reload_directory(); } return ret; }
static bool chanconf(void) { static const struct opt_items names[] = { { STR(LANG_CHANNEL_STEREO) }, { STR(LANG_CHANNEL_MONO) }, { STR(LANG_CHANNEL_CUSTOM) }, { STR(LANG_CHANNEL_LEFT) }, { STR(LANG_CHANNEL_RIGHT) }, { STR(LANG_CHANNEL_KARAOKE) } }; return set_option(str(LANG_CHANNEL), &global_settings.channel_config, INT, names, 6, set_chanconf ); }
int parse_options(int argc, char **argv, struct option *options) { int i; for (i = 1; i < argc; i++) { const char *key, *val; key = argv[i]; if (*key == OPTION_CHAR) { int flag = 1; while (flag && *++key) { if (*key == '?' || !strcmp(key, "help")) { print_usage(argc, argv, options); return 1; } if (i < argc) val = argv[i + 1]; else val = NULL; switch (set_option(key, val, options)) { case 2: i++; case 1: flag = 0; case 0: break; case -1: fprintf(stderr, "%s: missing argument value for option %c%s\n", argv[0], OPTION_CHAR, key); print_usage(argc, argv, options); return 1; case -2: fprintf(stderr, "%s: unknown option %c%s\n", argv[0], OPTION_CHAR, key); print_usage(argc, argv, options); return 1; } } } else if (set_option(NULL, key, options) < 0) fprintf(stderr, "%s: invalid argument %s\n", argv[0], key); } return 0; }
static bool recsource(void) { static const struct opt_items names[] = { { STR(LANG_RECORDING_SRC_MIC) }, { STR(LANG_RECORDING_SRC_LINE) }, #ifdef HAVE_SPDIF_IN { STR(LANG_RECORDING_SRC_DIGITAL) }, #endif }; return set_option(str(LANG_RECORDING_SOURCE), &global_settings.rec_source, INT, names, sizeof(names)/sizeof(struct opt_items), NULL ); }
static void process_command_line_arguments(char *argv[], char **options) { char line[MAX_CONF_FILE_LINE_SIZE], opt[sizeof(line)], val[sizeof(line)], *p, cpath[PATH_MAX]; FILE *fp = NULL; size_t i, cmd_line_opts_start = 1, line_no = 0; // Should we use a config file ? if (argv[1] != NULL && argv[1][0] != '-') { snprintf(cpath, sizeof(cpath), "%s", argv[1]); cmd_line_opts_start = 2; } else if ((p = strrchr(argv[0], DIRSEP)) == NULL) { // No command line flags specified. Look where binary lives snprintf(cpath, sizeof(cpath), "%s", CONFIG_FILE); } else { snprintf(cpath, sizeof(cpath), "%.*s%c%s", (int) (p - argv[0]), argv[0], DIRSEP, CONFIG_FILE); } abs_path(cpath, s_config_file, sizeof(s_config_file)); fp = fopen(s_config_file, "r"); // If config file was set in command line and open failed, die if (cmd_line_opts_start == 2 && fp == NULL) { die("Cannot open config file %s: %s", s_config_file, strerror(errno)); } // Load config file settings first if (fp != NULL) { fprintf(stderr, "Loading config file %s\n", s_config_file); // Loop over the lines in config file while (fgets(line, sizeof(line), fp) != NULL) { line_no++; // Ignore empty lines and comments for (i = 0; isspace(* (unsigned char *) &line[i]); ) i++; if (line[i] == '#' || line[i] == '\0') { continue; } if (sscanf(line, "%s %[^\r\n#]", opt, val) != 2) { printf("%s: line %d is invalid, ignoring it:\n %s", s_config_file, (int) line_no, line); } else { set_option(options, opt, val); } } fclose(fp); } }
static bool recfrequency(void) { static const struct opt_items names[] = { { "44.1kHz", TALK_ID(44, UNIT_KHZ) }, { "48kHz", TALK_ID(48, UNIT_KHZ) }, { "32kHz", TALK_ID(32, UNIT_KHZ) }, { "22.05kHz", TALK_ID(22, UNIT_KHZ) }, { "24kHz", TALK_ID(24, UNIT_KHZ) }, { "16kHz", TALK_ID(16, UNIT_KHZ) } }; return set_option(str(LANG_RECORDING_FREQUENCY), &global_settings.rec_frequency, INT, names, 6, NULL ); }
static bool beep(void) { static const struct opt_items names[] = { { STR(LANG_OFF) }, { STR(LANG_WEAK) }, { STR(LANG_MODERATE) }, { STR(LANG_STRONG) }, }; bool ret; ret=set_option( str(LANG_BEEP), &global_settings.beep, INT, names, 4, NULL); return ret; }