RefPtr<SyncPoint> SyncPointManager::get_syncpoint_no_lock(const std::string & component, const std::string & identifier) { if (component == "") { throw SyncPointInvalidComponentException(component.c_str(), identifier.c_str()); } // insert a new SyncPoint if no SyncPoint with the same identifier exists, // otherwise, use that SyncPoint std::pair<std::set<RefPtr<SyncPoint> >::iterator,bool> insert_ret; insert_ret = syncpoints_.insert( RefPtr<SyncPoint>(new SyncPoint(identifier, logger_))); std::set<RefPtr<SyncPoint> >::iterator sp_it = insert_ret.first; // add component to the set of watchers (*sp_it)->add_watcher(component); if (identifier != "/") { // create prefix SyncPoints. // If this is the root SyncPoint ("/"), there will be no prefix std::string prefix = find_prefix(identifier); RefPtr<SyncPoint> predecessor = get_syncpoint_no_lock(component, prefix); predecessor->successors_.insert(*sp_it); (*sp_it)->predecessor_ = predecessor; } return *sp_it; }
/* Determines if the prefix of the option matches any option and affects the * preprocessor. */ bool compopt_prefix_affects_cpp(const char *option) { /* prefix options have to take concatentated args */ const struct compopt *co = find_prefix(option); return co && (co->type & TAKES_CONCAT_ARG) && (co->type & AFFECTS_CPP); }
trie_tree* trie_tree_create_end() { assert(be_creating); assert(!be_inserting); trie_tree* tree = (trie_tree*)malloc(sizeof(trie_tree)); init_array(&tree->node_array, sizeof(trie_node)); init_array(&successor_array, sizeof(trie_successor)); append_array(&tree->node_array, 2); memset(get_array_elem(&tree->node_array, 0), 0, sizeof(trie_node)*2); trie_node* head_node = (trie_node*)get_array_elem(&tree->node_array, HEAD_INDEX); head_node->check = HEAD_CHECK; head_node->base = HEAD_INDEX; for(int input_index = 0; input_index<input_cache.len; input_index++) { int prefix_index, node_index, base_index; trie_input* input_node = (trie_input*)get_array_elem(&input_cache, input_index); while( find_prefix(tree, input_node->str, &prefix_index, &node_index) ) { get_all_successors(input_node->str, prefix_index, input_index); base_index = find_base_index_by_successors(tree, node_index); insert_successors(tree, base_index, node_index); } mark_word_node(tree, node_index); } empty_array(&input_cache); empty_array(&successor_array); be_creating = false; return tree; }
void trie_tree_insert_end(trie_tree* tree) { assert(!be_creating); assert(be_inserting); init_array(&successor_array, sizeof(trie_successor)); for(int input_index = 0; input_index<input_cache.len; input_index++) { int prefix_index, node_index; trie_input* input_node = (trie_input*)get_array_elem(&input_cache, input_index); while( find_prefix(tree, input_node->str, &prefix_index, &node_index) ) { int base_index = abs(((trie_node*)get_array_elem(&tree->node_array, node_index))->base); get_all_successors(input_node->str, prefix_index, input_index); delete_existing_successors(tree, node_index); if(base_index == node_index || !check_insert_successors(tree, node_index) ) { reset_successors(tree, node_index); base_index = find_base_index_by_successors(tree, node_index); } insert_successors(tree, base_index, node_index); } mark_word_node(tree, node_index); } print_node(tree, 1, 0); empty_array(&input_cache); empty_array(&successor_array); be_inserting = false; }
/******************************************************************** * FUNCTION xml_msg_check_xmlns_attr * * Check the default NS and the prefix map in the msg; * * INPUTS: * msg == message in progress * nsid == namespace ID to check * badns == namespace URI of the bad namespace * used if the nsid is the INVALID marker * attrs == Q to hold the xml_attr_t, if generated * * OUTPUTS: * msg->prefixQ will be populated as needed, * could be partially populated if some error returned * * XMLNS attr entry may be added to the attrs Q * * RETURNS: * status *********************************************************************/ status_t xml_msg_check_xmlns_attr (xml_msg_hdr_t *msg, xmlns_id_t nsid, const xmlChar *badns, xml_attrs_t *attrs) { const xmlChar *pfix; xmlChar *buff; xml_attr_t *attr; status_t res; #ifdef DEBUG if (!msg || !attrs) { return SET_ERROR(ERR_INTERNAL_PTR); } #endif /* no namespace is always ok, and if it is the same as the * current default, then nothing to do */ if (!nsid) { return NO_ERR; } /* not the default, see if prefix already set for this NS */ pfix = find_prefix(msg, nsid); if (pfix) { return NO_ERR; } /* check if this namespace ID already covered because the * xmlns decl is already present in the attrs list parameter */ for (attr = (xml_attr_t *)dlq_firstEntry(attrs); attr != NULL; attr = (xml_attr_t *)dlq_nextEntry(attr)) { if (attr->attr_xmlns_ns == nsid) { return NO_ERR; } } /* not already covered */ buff = NULL; res = xml_msg_gen_new_prefix(msg, nsid, &buff, 0); if (res == NO_ERR) { if (nsid == xmlns_inv_id()) { res = xml_add_inv_xmlns_attr(attrs, nsid, buff, badns); } else { res = xml_add_xmlns_attr(attrs, nsid, buff); } } if (buff) { m__free(buff); } return res; } /* xml_msg_check_xmlns_attr */
int words_begin_with(struct prefix_tree const *t, char const *prefix) { // find the node corresponding with the prefix struct node const *start_point = find_prefix(t->root, prefix); if (start_point == NULL) { return 0; } return words_descended_from(start_point); }
static struct node const * find_prefix(struct node const *n, char const *p) { if (n == NULL) { return NULL; } else if (*p == '\0') { return n; } else { int pos = *p - 'a'; // pos=0 for 'a', 1 for 'b',... return find_prefix(n->children[pos], p + 1); } }
/* add to |e| the set of command names in mode and its descendants, that begin with |name|. */ void CommandTree::extensions(std::set<const char*,StrCmp>& e, const char* name) const { for (const_iterator it = find_prefix(name); it != end(); ++it) if (isInitial(name,it->first)) e.insert(it->first); else break; // any element not starting with |name| ends search for (size_t j = 0; j < n_desc(); ++j) { const CommandTree& mode = nextMode(j); mode.extensions(e,name); } }
/** * Finish the queue of xmlns_pmap_t records for the current message * * /param msg message in progrss * /param attrs the top-level attrs list (e;g, rpc_in_attrs) * * /return status of operation *********************************************************************/ status_t xml_msg_finish_prefix_map (xml_msg_hdr_t *msg, xml_attrs_t *attrs) { xmlns_pmap_t *newpmap; xmlChar *buff = NULL; xmlns_id_t wdaid; status_t res = NO_ERR; assert(msg && "msg is NULL"); assert(attrs && "attrs is NULL"); wdaid = xmlns_wda_id(); /* make sure XMLNS decl for wd:default is in the map * if the report-all-tagged mode is active */ if (msg->withdef == NCX_WITHDEF_REPORT_ALL_TAGGED && !find_prefix(msg, wdaid)) { /* add a prefix an xmlns attr for WD */ res = xml_msg_gen_new_prefix(msg, wdaid, &buff, 0); if (res == NO_ERR) { res = xml_add_xmlns_attr(attrs, wdaid, buff); } if (res == NO_ERR) { /* create a new prefix map */ newpmap = xmlns_new_pmap(0); if (newpmap == NULL) { res = ERR_INTERNAL_MEM; } else { newpmap->nm_id = wdaid; newpmap->nm_pfix = buff; newpmap->nm_topattr = TRUE; add_pmap(msg, newpmap); } } } if (buff && (res != NO_ERR)) { m__free(buff); } return res; } /* xml_msg_finish_prefix_map */
/******************************************************************** * FUNCTION xml_msg_get_prefix_xpath * * Find the namespace prefix for the specified namespace ID * If it is not there then create one in the msg prefix map * Always returns a prefix, instead of using a default * * creates a new pfixmap if needed * * !!! MUST BE CALLED BEFORE THE <rpc-reply> XML OUTPUT * !!! HAS BEGUN. CANNOT BE CALLED BY OUTPUT FUNCTIONS * !!! DURING THE <get> OR <get-config> OUTPUT GENERATION * * INPUTS: * msg == message to search * nsid == namespace ID to find * * RETURNS: * pointer to prefix if found, else NULL if not found *********************************************************************/ const xmlChar * xml_msg_get_prefix_xpath (xml_msg_hdr_t *msg, xmlns_id_t nsid) { #ifdef DEBUG if (!msg) { SET_ERROR(ERR_INTERNAL_PTR); return NULL; } if (!nsid) { SET_ERROR(ERR_INTERNAL_VAL); return NULL; } #endif /* see if a prefix is already present in the rpc-reply element */ const xmlChar *pfix = find_prefix(msg, nsid); if (pfix) { return pfix; } /* need to create a new prefix map and save it for real */ xmlns_pmap_t *newpmap = xmlns_new_pmap(0); if (!newpmap) { SET_ERROR(ERR_INTERNAL_MEM); return NULL; } /* generate a prefix ID */ newpmap->nm_id = nsid; status_t res = xml_msg_gen_new_prefix(msg, nsid, &newpmap->nm_pfix, 0); if (res != NO_ERR) { xmlns_free_pmap(newpmap); return NULL; } /* add the new prefix mapping to the prefixQ */ add_pmap(msg, newpmap); return newpmap->nm_pfix; } /* xml_msg_get_prefix_xpath */
static void add_leg(point *fr, point *to, const char *prefix, int flags) { leg *l; fr->order++; to->order++; l = osmalloc(ossizeof(leg)); l->fr = fr; l->to = to; if (prefix) l->prefix = find_prefix(prefix); else l->prefix = NULL; l->next = headleg.next; l->dir = 0; l->fDone = 0; l->broken = 0; l->flags = flags; headleg.next = l; }
CommandNode::const_iterator CommandTree::look_up (const char* name, CheckResult& status, CommandTree const* & where) const { CommandNode::const_iterator result; // might remain undefined CommandNode::const_iterator it = find_prefix(name); // in our |mode| only if (it != end() and isInitial(name,it->first)) // anything found here? { if (isEqual(name,it->first)) // got exact match here return status=Found, where=this, it; // record partial match, then scan ahead for any further partial matches if (status!=NotFound) // we found a partial match, and had at least one status = Ambiguous; else { status=PartialMatch; where=this; result=it; if (++it != end() and isInitial(name,it->first)) status = Ambiguous; } } bool not_found_before = status==NotFound; // now look in descendant modes; if any has exact match, return that for (unsigned int i=0; i<n_desc(); ++i) { it = nextMode(i).look_up(name,status,where); if (status==Found) // found exact match, |where| has been set return it; // |where| has been set by recursive |lookup| if (not_found_before and status!=NotFound) // got a first partial match { not_found_before = false; // only one can be the first result=it; // export result from first successful recursive |look_up| } } // now |status| can be anything except |Found| return result; // value should not be used if |status==NotFound| }
/******************************************************************** * Add an ncid or ncxid to a prefix map. * * \param msg the message in progrss * \param attrs the the top-level attrs list (e;g, rpc_in_attrs) * \param ncid the ncid to add. * \return status *********************************************************************/ status_t xml_msg_add_ncid_to_prefix_map (xml_msg_hdr_t* msg, xml_attrs_t* attrs, xmlns_id_t ncid) { status_t res = NO_ERR; if (!find_prefix(msg, ncid) ) { /* add a prefix an xmlns attr for NETCONF */ xmlChar *buff = NULL; res = xml_msg_gen_new_prefix(msg, ncid, &buff, 0); if (res != NO_ERR) { m__free( buff ); return res; } res = xml_add_xmlns_attr(attrs, ncid, buff); if (res != NO_ERR) { m__free( buff ); return res; } /* create a new prefix map */ xmlns_pmap_t *newpmap = xmlns_new_pmap(0); if (!newpmap) { m__free( buff ); return ERR_INTERNAL_MEM; } newpmap->nm_id = ncid; newpmap->nm_pfix = buff; newpmap->nm_topattr = TRUE; add_pmap(msg, newpmap); } return res; } /* xml_msg_add_ncid_to_prefix_map */
/******************************************************************** * FUNCTION xml_msg_get_prefix_start_tag * * Find the namespace prefix for the specified namespace ID * DO NOT CREATE A NEW PREFIX MAP IF IT IS NOT THERE * does not create any pfixmap, just returns NULL if not found * * INPUTS: * msg == message to search * nsid == namespace ID to find * * RETURNS: * pointer to prefix if found, else NULL if not found *********************************************************************/ const xmlChar * xml_msg_get_prefix_start_tag (xml_msg_hdr_t *msg, xmlns_id_t nsid) { #ifdef DEBUG if (!msg) { SET_ERROR(ERR_INTERNAL_PTR); return NULL; } if (!nsid) { SET_ERROR(ERR_INTERNAL_VAL); return NULL; } #endif /* see if a prefix is already present in the rpc-reply element */ const xmlChar *pfix = find_prefix(msg, nsid); if (pfix) { return pfix; } else { return NULL; } } /* xml_msg_get_prefix_start_tag */
static void start_handler(void *userdata, const char *name, const char **attrs) { apr_xml_parser *parser = userdata; apr_xml_elem *elem; apr_xml_attr *attr; apr_xml_attr *prev; char *colon; const char *quoted; char *elem_name; /* punt once we find an error */ if (parser->error) return; elem = apr_pcalloc(parser->p, sizeof(*elem)); /* prep the element */ elem->name = elem_name = apr_pstrdup(parser->p, name); /* fill in the attributes (note: ends up in reverse order) */ while (*attrs) { attr = apr_palloc(parser->p, sizeof(*attr)); attr->name = apr_pstrdup(parser->p, *attrs++); attr->value = apr_pstrdup(parser->p, *attrs++); attr->next = elem->attr; elem->attr = attr; } /* hook the element into the tree */ if (parser->cur_elem == NULL) { /* no current element; this also becomes the root */ parser->cur_elem = parser->doc->root = elem; } else { /* this element appeared within the current elem */ elem->parent = parser->cur_elem; /* set up the child/sibling links */ if (elem->parent->last_child == NULL) { /* no first child either */ elem->parent->first_child = elem->parent->last_child = elem; } else { /* hook onto the end of the parent's children */ elem->parent->last_child->next = elem; elem->parent->last_child = elem; } /* this element is now the current element */ parser->cur_elem = elem; } /* scan the attributes for namespace declarations */ for (prev = NULL, attr = elem->attr; attr; attr = attr->next) { if (strncmp(attr->name, APR_KW_xmlns, 5) == 0) { const char *prefix = &attr->name[5]; apr_xml_ns_scope *ns_scope; /* test for xmlns:foo= form and xmlns= form */ if (*prefix == 0x3A) { /* a namespace prefix declaration must have a non-empty value. */ if (attr->value[0] == '\0') { parser->error = APR_XML_NS_ERROR_INVALID_DECL; return; } ++prefix; } else if (*prefix != '\0') { /* advance "prev" since "attr" is still present */ prev = attr; continue; } /* quote the URI before we ever start working with it */ quoted = apr_xml_quote_string(parser->p, attr->value, 1); /* build and insert the new scope */ ns_scope = apr_pcalloc(parser->p, sizeof(*ns_scope)); ns_scope->prefix = prefix; ns_scope->ns = apr_xml_insert_uri(parser->doc->namespaces, quoted); ns_scope->emptyURI = *quoted == '\0'; ns_scope->next = elem->ns_scope; elem->ns_scope = ns_scope; /* remove this attribute from the element */ if (prev == NULL) elem->attr = attr->next; else prev->next = attr->next; /* Note: prev will not be advanced since we just removed "attr" */ } else if (strcmp(attr->name, APR_KW_xmlns_lang) == 0) { /* save away the language (in quoted form) */ elem->lang = apr_xml_quote_string(parser->p, attr->value, 1); /* remove this attribute from the element */ if (prev == NULL) elem->attr = attr->next; else prev->next = attr->next; /* Note: prev will not be advanced since we just removed "attr" */ } else { /* advance "prev" since "attr" is still present */ prev = attr; } } /* ** If an xml:lang attribute didn't exist (lang==NULL), then copy the ** language from the parent element (if present). ** ** NOTE: elem_size() *depends* upon this pointer equality. */ if (elem->lang == NULL && elem->parent != NULL) elem->lang = elem->parent->lang; /* adjust the element's namespace */ colon = strchr(elem_name, 0x3A); if (colon == NULL) { /* * The element is using the default namespace, which will always * be found. Either it will be "no namespace", or a default * namespace URI has been specified at some point. */ elem->ns = find_prefix(parser, ""); } else if (APR_XML_NS_IS_RESERVED(elem->name)) { elem->ns = APR_XML_NS_NONE; } else { *colon = '\0'; elem->ns = find_prefix(parser, elem->name); elem->name = colon + 1; if (APR_XML_NS_IS_ERROR(elem->ns)) { parser->error = elem->ns; return; } } /* adjust all remaining attributes' namespaces */ for (attr = elem->attr; attr; attr = attr->next) { /* * apr_xml_attr defines this as "const" but we dup'd it, so we * know that we can change it. a bit hacky, but the existing * structure def is best. */ char *attr_name = (char *)attr->name; colon = strchr(attr_name, 0x3A); if (colon == NULL) { /* * Attributes do NOT use the default namespace. Therefore, * we place them into the "no namespace" category. */ attr->ns = APR_XML_NS_NONE; } else if (APR_XML_NS_IS_RESERVED(attr->name)) { attr->ns = APR_XML_NS_NONE; } else { *colon = '\0'; attr->ns = find_prefix(parser, attr->name); attr->name = colon + 1; if (APR_XML_NS_IS_ERROR(attr->ns)) { parser->error = attr->ns; return; } } } }
/* Determines if argument takes a concatentated argument by comparing prefixes. */ bool compopt_takes_concat_arg(const char *option) { const struct compopt *co = find_prefix(option); return co && (co->type & TAKES_CONCAT_ARG); }
uint32_t find_prefix(const StorageSequence &sequence) { return find_prefix(sequence.begin(), sequence.end()); }
void bcp_implementation::scan_license(const fs::path& p, const fileview& v) { std::pair<const license_info*, int> licenses = get_licenses(); // // scan file for all the licenses in the list: // int license_count = 0; int author_count = 0; int nonbsl_author_count = 0; bool has_non_bsl_license = false; fileview::const_iterator start_of_license = v.begin(), end_of_license = v.end(); bool start_in_middle_of_line = false; for(int i = 0; i < licenses.second; ++i) { boost::match_results<fileview::const_iterator> m; if(boost::regex_search(v.begin(), v.end(), m, licenses.first[i].license_signature)) { start_of_license = m[0].first; end_of_license = m[0].second; if (is_non_bsl_license(i) && i < licenses.second - 1) has_non_bsl_license = true; // add this license to the list: m_license_data[i].files.insert(p); ++license_count; // // scan for the associated copyright declarations: // boost::regex_iterator<const char*> cpy(v.begin(), v.end(), licenses.first[i].copyright_signature); boost::regex_iterator<const char*> ecpy; while(cpy != ecpy) { #if 0 // Not dealing with copyrights because we don't have the years if ((*cpy)[0].first < start_of_license) start_of_license = (*cpy)[0].first; if ((*cpy)[0].second > end_of_license) end_of_license = (*cpy)[0].second; #endif // extract the copy holders as a list: std::string author_list = cpy->format(licenses.first[i].copyright_formatter, boost::format_all); // now enumerate that list for all the names: static const boost::regex author_separator("(?:\\s*,(?!\\s*(?:inc|ltd)\\b)\\s*|\\s+(,\\s*)?(and|&)\\s+)|by\\s+", boost::regex::perl | boost::regex::icase); boost::regex_token_iterator<std::string::const_iterator> atr(author_list.begin(), author_list.end(), author_separator, -1); boost::regex_token_iterator<std::string::const_iterator> eatr; while(atr != eatr) { // get the reformatted authors name: std::string name = format_authors_name(*atr); // add to list of authors for this file: if(name.size() && name[0] != '-') { m_license_data[i].authors.insert(name); // add file to author index: m_author_data[name].insert(p); ++author_count; // If this is not the Boost Software License (license 0), and the author hasn't given // blanket permission, note this for the report. if (has_non_bsl_license && m_bsl_authors.find(name) == m_bsl_authors.end()) { ++nonbsl_author_count; m_authors_for_bsl_migration.insert(name); } } ++atr; } ++cpy; } while (start_of_license != v.begin() && *start_of_license != '\r' && *start_of_license != '\n' && *start_of_license != '.') --start_of_license; if (start_of_license != v.begin()) { if (*start_of_license == '.') start_in_middle_of_line = true; ++start_of_license; } while (end_of_license != v.end() && *end_of_license != '\r' && *end_of_license != '\n') ++end_of_license; } } if(license_count == 0) m_unknown_licenses.insert(p); if(license_count && !author_count) m_unknown_authors.insert(p); if (has_non_bsl_license) { bool converted = false; if (nonbsl_author_count == 0 && license_count == 1) { // Grab a few lines of context fileview::const_iterator context_start = context_before_license(v, start_of_license); fileview::const_iterator context_end = context_after_license(v, end_of_license); // TBD: For files that aren't C++ code, this will have to // change. std::string prefix = find_prefix(v, start_of_license); // Create enough information to permit manual verification of // the correctness of the transformation std::string before_conversion = html_escape(context_start, start_of_license); before_conversion += "<b>"; before_conversion += html_escape(start_of_license, end_of_license); before_conversion += "</b>"; before_conversion += html_escape(end_of_license, context_end); std::string after_conversion = html_escape(context_start, start_of_license); if (start_in_middle_of_line) after_conversion += '\n'; after_conversion += "<b>"; for (int i = 0; i < boost_license_lines; ++i) { if (i > 0) after_conversion += '\n'; after_conversion += prefix + boost_license_text[i]; } after_conversion += "</b>"; after_conversion += html_escape(end_of_license, context_end); m_converted_to_bsl[p] = std::make_pair(before_conversion, after_conversion); // Perform the actual conversion if (m_bsl_convert_mode) { try{ std::ofstream out((m_boost_path / p).string().c_str()); if (!out) { std::string msg("Cannot open file for license conversion: "); msg += p.string(); std::runtime_error e(msg); boost::throw_exception(e); } out << std::string(v.begin(), start_of_license); if (start_in_middle_of_line) out << std::endl; for (int j = 0; j < boost_license_lines; ++j) { if (j > 0) out << std::endl; out << prefix << boost_license_text[j]; } out << std::string(end_of_license, v.end()); converted = true; } catch(const std::exception& e) { std::cerr << e.what() << std::endl; } } } if (!converted) { if (nonbsl_author_count > 0) m_cannot_migrate_to_bsl.insert(p); else m_can_migrate_to_bsl.insert(p); } } }