static int parse_options(term_t options, p_options *info) { term_t tail = PL_copy_term_ref(options); term_t head = PL_new_term_ref(); term_t arg = PL_new_term_ref(); info->window = MAYBE; while(PL_get_list(tail, head, tail)) { atom_t name; int arity; if ( !PL_get_name_arity(head, &name, &arity) || arity != 1 ) return type_error(head, "option"); _PL_get_arg(1, head, arg); if ( name == ATOM_stdin ) { if ( !get_stream(arg, info, &info->streams[0]) ) return FALSE; } else if ( name == ATOM_stdout ) { if ( !get_stream(arg, info, &info->streams[1]) ) return FALSE; } else if ( name == ATOM_stderr ) { if ( !get_stream(arg, info, &info->streams[2]) ) return FALSE; } else if ( name == ATOM_process ) { info->pid = PL_copy_term_ref(arg); } else if ( name == ATOM_detached ) { if ( !PL_get_bool(arg, &info->detached) ) return type_error(arg, "boolean"); } else if ( name == ATOM_cwd ) { #ifdef __WINDOWS__ if ( !PL_get_wchars(arg, NULL, &info->cwd, CVT_ATOM|CVT_STRING|CVT_EXCEPTION|BUF_MALLOC) ) return FALSE; #else if ( !PL_get_chars(arg, &info->cwd, CVT_ATOM|CVT_STRING|CVT_EXCEPTION|BUF_MALLOC|REP_FN) ) return FALSE; #endif } else if ( name == ATOM_window ) { if ( !PL_get_bool(arg, &info->window) ) return type_error(arg, "boolean"); } else if ( name == ATOM_env ) { if ( !parse_environment(arg, info) ) return FALSE; } else return domain_error(head, "process_option"); } if ( !PL_get_nil(tail) ) return type_error(tail, "list"); return TRUE; }
int guestfs_impl_parse_environment_list (guestfs_h *g, char * const *strings) { return parse_environment (g, getenv_from_strings, strings); }
int guestfs_impl_parse_environment (guestfs_h *g) { return parse_environment (g, call_getenv, NULL); }
BOOST_PROGRAM_OPTIONS_DECL parsed_options parse_environment(const options_description& desc, const char* prefix) { return parse_environment(desc, string(prefix)); }
BOOST_PROGRAM_OPTIONS_DECL parsed_options parse_environment(const options_description& desc, const std::string& prefix) { return parse_environment(desc, detail::prefix_name_mapper(prefix)); }
/* ************************************************** */ int do_configuration(void) { xmlSchemaValidCtxtPtr sv_ctxt = NULL; xmlSchemaParserCtxtPtr sp_ctxt = NULL; xmlSchemaPtr schema = NULL; xmlParserCtxtPtr p_ctxt = NULL; xmlDocPtr doc = NULL; xmlXPathContextPtr xp_ctx = NULL; xmlXPathObjectPtr simul_xobj = NULL; xmlXPathObjectPtr entity_xobj = NULL; xmlXPathObjectPtr environment_xobj = NULL; xmlXPathObjectPtr bundle_xobj = NULL; xmlXPathObjectPtr node_xobj = NULL; xmlNodeSetPtr nodeset; xmlpathobj_t xpathobj[] = {{&simul_xobj, (xmlChar *) XML_X_SIMULATION}, {&entity_xobj, (xmlChar *) XML_X_ENTITY}, {&environment_xobj, (xmlChar *) XML_X_ENVIRONMENT}, {&bundle_xobj, (xmlChar *) XML_X_BUNDLE}, {&node_xobj, (xmlChar *) XML_X_NODE}}; int ok = 0, i; /* Check XML version */ LIBXML_TEST_VERSION; /* Initialise and parse schema */ sp_ctxt = xmlSchemaNewParserCtxt(schemafile); if (sp_ctxt == NULL) { fprintf(stderr, "config: XML schema parser initialisation failure (do_configuration())\n"); ok = -1; goto cleanup; } xmlSchemaSetParserErrors(sp_ctxt, (xmlSchemaValidityErrorFunc) xml_error, (xmlSchemaValidityWarningFunc) xml_warning, NULL); schema = xmlSchemaParse(sp_ctxt); if (schema == NULL) { fprintf(stderr, "config: error in schema %s (do_configuration())\n", schemafile); ok = -1; goto cleanup; } xmlSchemaSetValidErrors(sv_ctxt, (xmlSchemaValidityErrorFunc) xml_error, (xmlSchemaValidityWarningFunc) xml_warning, NULL); sv_ctxt = xmlSchemaNewValidCtxt(schema); if (sv_ctxt == NULL) { fprintf(stderr, "config: XML schema validator initialisation failure (do_configuration())\n"); ok = -1; goto cleanup; } /* Initialise and parse document */ p_ctxt = xmlNewParserCtxt(); if (p_ctxt == NULL) { fprintf(stderr, "config: XML parser initialisation failure (do_configuration())\n"); ok = -1; goto cleanup; } doc = xmlCtxtReadFile(p_ctxt, configfile, NULL, XML_PARSE_NONET | XML_PARSE_NOBLANKS | XML_PARSE_NSCLEAN); if (doc == NULL) { fprintf(stderr, "config: failed to parse %s (do_configuration())\n", configfile); ok = -1; goto cleanup; } /* Validate document */ if (xmlSchemaValidateDoc(sv_ctxt, doc)) { fprintf(stderr, "config: error in configuration file %s (do_configuration())\n", configfile); ok = -1; goto cleanup; } /* Create xpath context */ xp_ctx = xmlXPathNewContext(doc); if (xp_ctx == NULL) { fprintf(stderr, "config: XPath initialisation failure (do_configuration())\n"); ok = -1; goto cleanup; } xmlXPathRegisterNs(xp_ctx, (xmlChar *) XML_NS_ID, (xmlChar *) XML_NS_URL); /* Get xpath obj */ for (i = 0 ; i < (int) (sizeof(xpathobj) / sizeof(xpathobj[0])); i++) { *xpathobj[i].ptr = xmlXPathEvalExpression(xpathobj[i].expr, xp_ctx); if (*xpathobj[i].ptr == NULL) { fprintf(stderr, "config: unable to evaluate xpath \"%s\" (do_configuration())\n", xpathobj[i].expr); ok = -1; goto cleanup; } } /***************/ /* Counting... */ /***************/ nodeset = entity_xobj->nodesetval; if ((entities.size = (nodeset) ? nodeset->nodeNr : 0) == 0) { fprintf(stderr, "config: no entity defined (do_configuration())\n"); ok = -1; goto cleanup; } fprintf(stderr, "\nFound %d entities...\n", entities.size); nodeset = environment_xobj->nodesetval; if (((nodeset) ? nodeset->nodeNr : 0) == 0) { fprintf(stderr, "config: no environment defined (do_configuration())\n"); ok = -1; goto cleanup; } fprintf(stderr, "Found 1 environment...\n"); nodeset = bundle_xobj->nodesetval; if ((bundles.size = (nodeset) ? nodeset->nodeNr : 0) == 0) { fprintf(stderr, "config: no bundle defined (do_configuration())\n"); ok = -1; goto cleanup; } fprintf(stderr, "Found %d bundles...\n", bundles.size); if ((dflt_params = das_create()) == NULL) { ok = -1; goto cleanup; } /**************/ /* Simulation */ /**************/ if (parse_simulation(simul_xobj->nodesetval)) { ok = -1; goto cleanup; } /**********/ /* Entity */ /**********/ /* initialize library paths */ config_set_usr_modulesdir(); user_path_list = g_strsplit(user_modulesdir, ":", 0); /* TOCLEAN */ sys_path_list = g_strsplit(sys_modulesdir, ":", 0); /* TOCLEAN */ /* parse */ if (parse_entities(entity_xobj->nodesetval)) { ok = -1; goto cleanup; } /**************/ /* Measure */ /**************/ if (parse_measure()) { ok = -1; goto cleanup; } /***************/ /* Environment */ /***************/ if (parse_environment(environment_xobj->nodesetval)) { ok = -1; goto cleanup; } /***************/ /* Bundle */ /***************/ if (parse_bundles(bundle_xobj->nodesetval)) { ok = -1; goto cleanup; } /***************/ /* Nodes */ /***************/ if (parse_nodes(node_xobj->nodesetval)) { ok = -1; goto cleanup; } /* edit by Quentin Lampin <*****@*****.**> */ gchar **path = NULL; for (path = user_path_list ; *path ; path++) { g_free(*path); } path = NULL; for (path = sys_path_list ; *path ; path++) { g_free(*path); } /* end of edition */ cleanup: clean_params(); for (i = 0 ; i < (int) (sizeof(xpathobj) / sizeof(xpathobj[0])); i++) { xmlXPathFreeObject(*xpathobj[i].ptr); } if (xp_ctx) { xmlXPathFreeContext(xp_ctx); } if (sp_ctxt) { xmlSchemaFreeParserCtxt(sp_ctxt); } if (schema) { xmlSchemaFree(schema); } if (sv_ctxt) { xmlSchemaFreeValidCtxt(sv_ctxt); } if (doc) { xmlFreeDoc(doc); } if (p_ctxt) { xmlFreeParserCtxt(p_ctxt); } xmlCleanupParser(); return ok; }
extern void args_parse(args_info *args, int argc, char **argv) { // Initialize those parts of *args that we need later. args->files_name = NULL; args->files_file = NULL; args->files_delim = '\0'; // Check how we were called. { // Remove the leading path name, if any. const char *name = strrchr(argv[0], '/'); if (name == NULL) name = argv[0]; else ++name; // NOTE: It's possible that name[0] is now '\0' if argv[0] // is weird, but it doesn't matter here. // Look for full command names instead of substrings like // "un", "cat", and "lz" to reduce possibility of false // positives when the programs have been renamed. if (strstr(name, "xzcat") != NULL) { opt_mode = MODE_DECOMPRESS; opt_stdout = true; } else if (strstr(name, "unxz") != NULL) { opt_mode = MODE_DECOMPRESS; } else if (strstr(name, "lzcat") != NULL) { opt_format = FORMAT_LZMA; opt_mode = MODE_DECOMPRESS; opt_stdout = true; } else if (strstr(name, "unlzma") != NULL) { opt_format = FORMAT_LZMA; opt_mode = MODE_DECOMPRESS; } else if (strstr(name, "lzma") != NULL) { opt_format = FORMAT_LZMA; } } // First the flags from the environment parse_environment(args, argv[0], "XZ_DEFAULTS"); parse_environment(args, argv[0], "XZ_OPT"); // Then from the command line parse_real(args, argc, argv); // Never remove the source file when the destination is not on disk. // In test mode the data is written nowhere, but setting opt_stdout // will make the rest of the code behave well. if (opt_stdout || opt_mode == MODE_TEST) { opt_keep_original = true; opt_stdout = true; } // When compressing, if no --format flag was used, or it // was --format=auto, we compress to the .xz format. if (opt_mode == MODE_COMPRESS && opt_format == FORMAT_AUTO) opt_format = FORMAT_XZ; // Compression settings need to be validated (options themselves and // their memory usage) when compressing to any file format. It has to // be done also when uncompressing raw data, since for raw decoding // the options given on the command line are used to know what kind // of raw data we are supposed to decode. if (opt_mode == MODE_COMPRESS || opt_format == FORMAT_RAW) coder_set_compression_settings(); // If no filenames are given, use stdin. if (argv[optind] == NULL && args->files_name == NULL) { // We don't modify or free() the "-" constant. The caller // modifies this so don't make the struct itself const. static char *names_stdin[2] = { (char *)"-", NULL }; args->arg_names = names_stdin; args->arg_count = 1; } else { // We got at least one filename from the command line, or // --files or --files0 was specified. args->arg_names = argv + optind; args->arg_count = argc - optind; } return; }
AvahiDomainBrowser* avahi_domain_browser_new( AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, const char *domain, AvahiDomainBrowserType btype, AvahiLookupFlags flags, AvahiDomainBrowserCallback callback, void *userdata) { AvahiDomainBrowser *db = NULL; DBusMessage *message = NULL, *reply = NULL; DBusError error; char *path; int32_t i_interface, i_protocol, bt; uint32_t u_flags; assert(client); assert(callback); dbus_error_init (&error); if (!avahi_client_is_connected(client)) { avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE); goto fail; } if (!domain) domain = ""; if (!(db = avahi_new (AvahiDomainBrowser, 1))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } db->ref = 1; db->client = client; db->callback = callback; db->userdata = userdata; db->path = NULL; db->interface = interface; db->protocol = protocol; db->static_browse_domains = NULL; db->defer_timeout = NULL; AVAHI_LLIST_PREPEND(AvahiDomainBrowser, domain_browsers, client->domain_browsers, db); if (!(client->flags & AVAHI_CLIENT_IGNORE_USER_CONFIG)) { parse_environment(db); parse_domain_file(db); } db->static_browse_domains = avahi_string_list_reverse(db->static_browse_domains); if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "DomainBrowserNew"))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; u_flags = (uint32_t) flags; bt = btype; if (!(dbus_message_append_args( message, DBUS_TYPE_INT32, &i_interface, DBUS_TYPE_INT32, &i_protocol, DBUS_TYPE_STRING, &domain, DBUS_TYPE_INT32, &bt, DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } if (!(reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error)) || dbus_error_is_set(&error)) { avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR); goto fail; } if (!dbus_message_get_args (reply, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID) || dbus_error_is_set(&error) || !path) { avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR); goto fail; } if (!(db->path = avahi_strdup(path))) { /* FIXME: We don't remove the object on the server side */ avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } if (db->static_browse_domains && btype == AVAHI_DOMAIN_BROWSER_BROWSE) { struct timeval tv = { 0, 0 }; if (!(db->defer_timeout = client->poll_api->timeout_new(client->poll_api, &tv, defer_timeout_callback, db))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } } dbus_message_unref(message); dbus_message_unref(reply); return db; fail: if (dbus_error_is_set(&error)) { avahi_client_set_dbus_error(client, &error); dbus_error_free(&error); } if (db) avahi_domain_browser_free(db); if (message) dbus_message_unref(message); if (reply) dbus_message_unref(reply); return NULL; }