// find elements of "charlie" <-> "bravo" <-> "alpha" static void test_find_element() { char element_data1[] = "alpha"; char element_data2[] = "bravo"; char element_data3[] = "charlie"; char no_such_element[] = "NO SUCH ELEMENT"; dlist_element *new_element = create_dlist(); insert_after_dlist( new_element, element_data1 ); insert_after_dlist( new_element, element_data2 ); insert_after_dlist( new_element, element_data3 ); dlist_element *e = NULL; e = find_element( new_element, element_data3 ); assert_true( new_element->next == e ); e = find_element( new_element, element_data2 ); assert_true( new_element->next->next == e ); e = find_element( new_element, element_data1 ); assert_true( new_element->next->next->next == e ); e = find_element( new_element->next->next->next, element_data2 ); assert_true( new_element->next->next == e ); e = find_element( new_element, no_such_element ); assert_true( e == NULL ); delete_dlist( new_element ); }
Graph* init_edge(Graph *g) { vertex src, dest; weight w; for (int i = 0; i < g->vexnum; i++) { for (int j = 0; j < g->vexnum; j++) { g->w[i][j] = INF; } } printf("Please input the edge (format v1, v2, w): \n"); do { scanf("%c, %c, %d", &src, &dest, &w); if (w != -1) { int row = find_element(g->vex, g->vexnum, src); int col = find_element(g->vex, g->vexnum, dest); if (row != -1 && col != -1) { g->w[row][col] = w; g->edgnum++; } } } while (w != -1); return g; }
bool find_element (char * question, char * module_name, PrologElement * head, int element_id) { db_element el; el . type = 0; if (! find_element (question, element_id, & el)) return false; PrologAtom * atom; switch (el . type) { case 0: head -> setEarth (); return true; case 1: head -> setPair (); find_element (question, module_name, head -> getLeft (), el . reference); find_element (question, module_name, head -> getRight (), el . reference_right); return true; case 2: head -> setVar (el . reference); return true; case 3: atom = find_or_create_atom (question, el . reference); if (atom == NULL) return false; head -> setAtom (atom); return true; case 4: head -> setSlash (); return true; case 5: head -> setFail (); return true; case 6: if (! find_text (question, el . reference)) return false; head -> setText (question); return true; case 7: head -> setHead (NULL); return true; case 8: head -> setInteger (el . reference); return true; case 9: head -> setDouble (el . value); return true; default: return false; } return true; }
bool read_clause (PrologElement * parameters, char * module_name, char * atom_name, int ordering) { AREA area; int module_id = find_module_id (area, module_name); if (module_id < 0) return false; int atom_id = find_atom_id (area, module_id, atom_name); if (atom_id < 0) return false; PrologAtom * atom = find_or_create_atom (module_name, atom_name); if (atom == NULL) return false; db_clause clause; if (! find_clause (area, module_id, atom_id, ordering, & clause)) return false; if (fast) { mysql_term_reader trd (root, area); PrologElement * trdx = trd . readElement (); if (trdx != 0) { root -> getValue (trdx, area, 0); parameters -> setPair (trdx, root -> earth ()); return true; } return false; } parameters -> setPair (); parameters = parameters -> getLeft (); parameters -> setPair (); PrologElement * head = parameters -> getLeft (); head -> setPair (); head -> getLeft () -> setAtom (atom); head = head -> getRight (); if (! find_element (area, module_name, head, clause . parameters)) return false; // head -> setInteger (clause . parameters); head = parameters -> getRight (); if (! find_element (area, module_name, head, clause . body)) return false; // head -> setInteger (clause . body); return true; }
/* !DO NOT ALTER FUNCTION SIGNATURE! */ int callback_ofc_capable_switch_xdpd_mgmt_cross_connections_xdpd_mgmt_cross_connection (void ** data, XMLDIFF_OP op, xmlNodePtr node, struct nc_err** error) { nc_verb_verbose("%s: data=%p, op=%d\n", __PRETTY_FUNCTION__, data, op); print_element_names(node, 0); uint64_t dpid_1 = 0; uint64_t dpid_2 = 0; uint64_t port_no1 = 0; uint64_t port_no2 = 0; if (XMLDIFF_ADD & op) { int i=0; xmlNodePtr lsi; for (lsi = node->children->next; NULL != lsi; lsi = lsi->next, ++i) { assert(xmlStrEqual(lsi->name, BAD_CAST "switch")); // resolve dpid char buf[255]; xmlStrPrintf(buf, sizeof(buf), "/ofc:capable-switch/ofc:logical-switches/ofc:switch[ofc:id='%s']", XML_GET_CONTENT(lsi->children->children)); xmlXPathObjectPtr xpath_obj_ptr = get_node(lsi->doc, namespace_mapping, buf); assert(xpath_obj_ptr); assert(xpath_obj_ptr->nodesetval); // there can only be one lsi with this id if (1 == xpath_obj_ptr->nodesetval->nodeNr) { xmlNodePtr dpid_node = find_element(BAD_CAST "datapath-id", xpath_obj_ptr->nodesetval->nodeTab[0]->children); assert(dpid_node); if (0 == i) { dpid_1 = parse_dpid(XML_GET_CONTENT(dpid_node->children)); } else { dpid_2 = parse_dpid(XML_GET_CONTENT(dpid_node->children)); } } else { // otherwise something is really screwed assert(0); } xmlXPathFreeObject(xpath_obj_ptr); xmlNodePtr requested_portnum = find_element(BAD_CAST "requested-of-port-number", lsi->children); if (NULL != requested_portnum) { if (0 == i) { port_no1 = strtoul(XML_GET_CONTENT(requested_portnum->children), NULL, 10); } else { port_no2 = strtoul(XML_GET_CONTENT(requested_portnum->children), NULL, 10); } } } nc_verb_verbose("dpid_1 = %lx, dpid_2 = %lx\n", dpid_1, dpid_2); lsi_cross_connect(ofc_state.xmp_client_handle, dpid_1, port_no1, dpid_2, port_no2); } return EXIT_SUCCESS; }
static _pSLAssoc_Array_Element_Type *store_object (SLang_Assoc_Array_Type *a, _pSLAssoc_Array_Element_Type *e, SLstr_Type *s, unsigned long hash, SLang_Object_Type *obj) { if ((e != NULL) || (NULL != (e = find_element (a, s, hash)))) { #if SLANG_OPTIMIZE_FOR_SPEED if ((a->is_scalar_type == 0) && (e->value.o_data_type != SLANG_INT_TYPE)) #endif SLang_free_object (&e->value); } else { if ((a->num_occupied == a->resize_num) && (-1 == resize_table (a))) return NULL; if (NULL == (e = find_empty_element (a->elements, a->table_len, s, hash))) return NULL; if (e->key == Deleted_Key) a->num_deleted--; else a->num_occupied++; if (NULL == (e->key = _pSLstring_dup_hashed_string (s, hash))) return NULL; e->hash = hash; } e->value = *obj; return e; }
/****************************************************************************** Specify a property of an element that is to be returned. This should be called (usually multiple times) before a call to the routine ply_get_element(). This routine should be used in preference to the less flexible old routine called ply_get_element_setup(). Entry: plyfile - file identifier elem_name - which element we're talking about prop - property to add to those that will be returned ******************************************************************************/ void ply_get_property(PlyFile *plyfile, char *elem_name, PlyProperty *prop) { PlyElement *elem; PlyProperty *prop_ptr; int index; // find information about the element elem = find_element (plyfile, elem_name); plyfile->which_elem = elem; // deposit the property information into the element's description */ prop_ptr = find_property (elem, prop->name, &index); if (prop_ptr == NULL) { log_error("Can't find property '%s' in element '%s'\n", prop->name, elem_name); return; } prop_ptr->internal_type = prop->internal_type; prop_ptr->offset = prop->offset; prop_ptr->count_internal = prop->count_internal; prop_ptr->count_offset = prop->count_offset; // specify that the user wants this property */ elem->store_prop[index] = STORE_PROP; }
bool PlannerThread::loadObjs() { string line; vector<string> aux_objs, temp_vect; vector<string> labels; objFile.open(objFileName.c_str()); object_IDs.clear(); if (objFile.is_open()){ getline(objFile, line); aux_objs = split(line, ';'); for (int j = 0; j < aux_objs.size(); ++j){ temp_vect = split(aux_objs[j], ','); temp_vect[0].replace(temp_vect[0].find("("),1,""); temp_vect[1].replace(temp_vect[1].find(")"),1,""); object_IDs.push_back(temp_vect); if (find_element(labels,temp_vect[1]) == 1) { yWarning("There are objects that share labels: %s", temp_vect[1].c_str()); } labels.push_back(temp_vect[1]); } objFile.close(); } else { yWarning("unable to open objects file!"); return false; } return true; }
int main(void) { printf("Enter the number of elements in the list, followed by each element, followed by the element to find.\n"); printf("Elements must be sorted.\n"); printf("> "); size_t arr_sz; while (scanf("%zu", &arr_sz) == 1) { listy_buff.arr_sz = arr_sz; size_t i; for (i = 0; i < arr_sz; i++) { scanf("%u", &arr_buff[i]); } unsigned n; scanf("%u", &n); ssize_t idx = find_element(&listy_buff, n); if (idx == -1) { printf("No such element.\n"); } else { printf("element_at(%zd) = %u\n", idx, arr_buff[idx]); } printf("> "); } return 0; }
void lirc_channel_message(struct LIRCServer_struct* server, struct LIRCClientData_struct* client, char *channel, char *message) { char temp[MAX_IRC_MESSAGE_SIZE]; dlnode_t* client_node; LIRCChannelData* c = (LIRCChannelData*)find_element(server->channel_list, channel, lirc_channel_cmp); if (c == NULL) { return; } /* Send a message to all connected clients inside the channel */ client_node = c->client_list->head; sprintf(temp, ":%s!~%[email protected] PRIVMSG %s %s\r\n", client->nick, client->user, channel, message); while (client_node != NULL) { struct LIRCClientData_struct *client_node_data = (struct LIRCClientData_struct *)client_node->data; if (client_node_data == client) { client_node = client_node->next; continue; } send(client_node_data->socket, temp, strlen(temp), 0); client_node = client_node->next; } }
//**************************************************************************** void CTerminal::get_terminal_entry(LPARAM lParam) { LV_DISPINFO *lpdi = (LV_DISPINFO *) lParam; static TCHAR szString[MAX_TERM_CHARS + 1]; // there's where we're crashing on long strings!! // item number is: lpdi->item.iItem if (lpdi->item.mask & LVIF_TEXT) { term_lview_item_p lvptr = find_element(lpdi->item.iItem) ; if (lvptr == NULL) { wsprintf(szString, _T("listview element %d not found [%u total]"), lpdi->item.iItem, curr_row); lpdi->item.pszText = szString ; set_term_attr(WIN_BCYAN, WIN_RED) ; } else { #ifdef UNICODE str_ascii_to_unicode(lvptr->msg, szString, MAX_TERM_CHARS); // this crashes on input strings > 260 bytes // one can only copy *into* lpdi->item.pszText for strings < 260 chars. // int result = str_ascii_to_unicode(lvptr->msg, lpdi->item.pszText, MAX_TERM_CHARS); lpdi->item.pszText = szString ; #else lpdi->item.pszText = lvptr->msg ; #endif set_term_attr(lvptr->fgnd, lvptr->bgnd) ; // set up for TerminalCustomDraw() } } }
double parameter_value(char *pname, long elem_type, long param, LINE_LIST *beamline) { ELEMENT_LIST *eptr; long lresult; double dresult; char *p_elem; long data_type; log_entry("parameter_value"); eptr = NULL; data_type = entity_description[elem_type].parameter[param].type; if (find_element(pname, &eptr, &(beamline->elem))) { p_elem = eptr->p_elem; switch (data_type) { case IS_DOUBLE: dresult = *((double*)(p_elem+entity_description[elem_type].parameter[param].offset)); log_exit("parameter_value"); return(dresult); case IS_LONG: lresult = *((long*)(p_elem+entity_description[elem_type].parameter[param].offset)); log_exit("parameter_value"); return((double)lresult); case IS_STRING: default: bombElegant("unknown/invalid variable quantity", NULL); exitElegant(1); } } fprintf(stdout, "error: unable to find value of parameter %ld for element %s of type %ld\n", param, pname, elem_type); fflush(stdout); exitElegant(1); return(0.0); }
int main () { int notpassed = 0; int passed = 0; struct array array1; check (init_array (&array1)) test (add_element (&array1, 1), NO_ERRORS) test (add_element (&array1, 8), NO_ERRORS) test (change_element(&array1, 12, 33), WRITE_TO_UNALLOCATED_MEMORY) test (change_element(&array1, 1, 33), NO_ERRORS) test (add_element (&array1, 41), NO_ERRORS) test (add_element (&array1, 3), NO_ERRORS) test (add_element (&array1, 9), NO_ERRORS) test (elements_sum (&array1), NO_ERRORS) test (add_element (&array1, 13), NO_ERRORS) test (verbose_full_print (&array1), NO_ERRORS) test (remove_element (&array1, 4), NO_ERRORS) test (print_array (&array1), NO_ERRORS) test (find_element(&array1, 120), ELEMENT_NOT_FOUND) test (print_array (&array1), NO_ERRORS) test (print_array (&array1), NO_ERRORS) test (print_element(&array1, 40), GARBAGE_READ) test (zero_array (&array1), NO_ERRORS) test (print_array (&array1), NO_ERRORS) printf ("datalen = %i, memlen = %i\n", get_datalen (&array1), get_memlen (&array1)); for (int i = 0; i < 305; i ++) check (add_element (&array1, 41)); printf ("Passed %i, not passed %i.\n", passed, notpassed); test (delete_array (&array1), NO_ERRORS) print_exit_message (); return 0; }
/* * do_return() * * Given an element reference, ask the changer/picker to move that * element back to its source slot. */ static int do_return(const char *cname, int argc, char **argv) { struct changer_element_status *ces; struct changer_move cmd; uint16_t type, element; ++argv; --argc; if (argc < 2) { warnx("%s: too few arguments", cname); goto usage; } else if (argc > 3) { warnx("%s: too many arguments", cname); goto usage; } type = parse_element_type(*argv); ++argv; --argc; /* Handle voltag virtual Changer Element Type */ if (CHET_VT == type) { find_element(*argv, &type, &element); } else { element = parse_element_unit(*argv); } ++argv; --argc; /* Get the status */ ces = get_element_status((unsigned int)type, (unsigned int)element, CHET_VT == type); if (NULL == ces) errx(1, "%s: null element status pointer", cname); if (!(ces->ces_flags & CES_SOURCE_VALID)) errx(1, "%s: no source information", cname); (void) memset(&cmd, 0, sizeof(cmd)); cmd.cm_fromtype = type; cmd.cm_fromunit = element; cmd.cm_totype = ces->ces_source_type; cmd.cm_tounit = ces->ces_source_addr; if (ioctl(changer_fd, CHIOMOVE, &cmd) == -1) err(1, "%s: CHIOMOVE", changer_name); free(ces); return(0); usage: (void) fprintf(stderr, "usage: %s %s " "<from ET> <from EU>\n", getprogname(), cname); return(1); }
void move_drive_error( library_t *library, uint_t source, uint_t dest, int *err) { /* Down the drive(s), not the robot */ int downed_one = 0; drive_state_t *drive_to_down; dev_ent_t *un = library->un; uchar_t buf[library->ele_dest_len + sizeof (element_status_data_t) + sizeof (element_status_page_t) + 50]; storage_element_t *desc; if (drive_to_down = find_element(library->drive, source)) { /* The source is a drive */ down_drive(drive_to_down, SAM_STATE_CHANGE); downed_one++; } else { /* * The source is not a drive. Read the storage element of the * source. If full then set error to RECOVERED_MEDIA_MOVE. This * tells the requester to set the CES_occupied status bit in the * catalog entry. */ mutex_unlock(&library->un->io_mutex); if (read_element_status(library, STORAGE_ELEMENT, source, 1, buf, sizeof (buf)) > 0) { desc = (storage_element_t *)(buf + sizeof (element_status_data_t) + sizeof (element_status_page_t)); if (desc->full) *err = RECOVERED_MEDIA_MOVE; } mutex_lock(&library->un->io_mutex); } if (drive_to_down = find_element(library->drive, dest)) { down_drive(drive_to_down, SAM_STATE_CHANGE); downed_one++; } if (downed_one == 0) DevLog(DL_ERR(5333), source, dest, 0); }
/* delete all elements matching an attribute name/value return LDB Error on failure */ static int msg_delete_element(struct ldb_module *module, struct ldb_message *msg, const char *name, const struct ldb_val *val) { struct ldb_context *ldb = ldb_module_get_ctx(module); unsigned int i; int found, ret; struct ldb_message_element *el; const struct ldb_schema_attribute *a; found = find_element(msg, name); if (found == -1) { return LDB_ERR_NO_SUCH_ATTRIBUTE; } i = (unsigned int) found; el = &(msg->elements[i]); a = ldb_schema_attribute_by_name(ldb, el->name); for (i=0;i<el->num_values;i++) { bool matched; if (a->syntax->operator_fn) { ret = a->syntax->operator_fn(ldb, LDB_OP_EQUALITY, a, &el->values[i], val, &matched); if (ret != LDB_SUCCESS) return ret; } else { matched = (a->syntax->comparison_fn(ldb, ldb, &el->values[i], val) == 0); } if (matched) { if (el->num_values == 1) { return msg_delete_attribute(module, ldb, msg, name); } ret = ltdb_index_del_value(module, msg->dn, el, i); if (ret != LDB_SUCCESS) { return ret; } if (i<el->num_values-1) { memmove(&el->values[i], &el->values[i+1], sizeof(el->values[i])* (el->num_values-(i+1))); } el->num_values--; /* per definition we find in a canonicalised message an attribute value only once. So we are finished here */ return LDB_SUCCESS; } } /* Not found */ return LDB_ERR_NO_SUCH_ATTRIBUTE; }
void theme::modify_label(const std::string& id, const std::string& text) { theme::label* label = dynamic_cast<theme::label*>(&find_element(id)); if(!label) { LOG_DP << "Theme contains no label called '" << id << "'.\n"; return; } label->set_text(text); }
/** * @brief Deletes a sub node. * * Deletes a sub node from the node. * @param sub_node The pointer of the sub node to * delete. */ inline void delete_sub_node( const RStarTreeNodeSharedPtr &sub_node) { assert(!get_leaf()); remove_element(get_index(sub_node)); assert(find_element(sub_node) == -1); }
bool PlannerThread::checkGoalCompletion() { for (int t = 0; t < goal.size(); ++t){ if (find_element(state, goal[t]) == 0){ return false; } } return true; }
/** * @brief Deletes an element. * * Deletes an element from the node. * @param element The pointer of the element to delete. */ inline void delete_element( const BoundedObjectSharedPtr &element) { assert(get_leaf()); remove_element(get_index(element)); assert(find_element(element) == -1); }
bool OWLDatabase::node(id_t id, tags_t &attrs, tags_t &tags) { bool found = find_element(transaction, "nodes", "node_tags", id, attrs, tags); if (found) { const double lat = lexical_cast<double>(required_attribute(attrs, "lat")) / SCALE; const double lon = lexical_cast<double>(required_attribute(attrs, "lon")) / SCALE; attrs["lat"] = to_string_d(lat); attrs["lon"] = to_string_d(lon); } return found; }
bool PlannerThread::checkHoldingSymbols() { vector<string> holding_symbols; if (plan_level >= 1){ for (int t = 0; t < subgoals[plan_level-1].size(); ++t){ if (find_element(subgoals[plan_level],subgoals[plan_level-1][t]) == 1){ holding_symbols.push_back(subgoals[plan_level-1][t]); } } if (holding_symbols.size() != 0){ holding_symbols.erase(holding_symbols.end()); } for (int t = 0; t < holding_symbols.size(); ++t){ if (find_element(state, holding_symbols[t])== 0){ yInfo("situation changed, receding in plan"); return false; } } } return true; }
cons* true_find_element(cons** list, char* str) { cons* foundPtr = find_element(list, str); if (foundPtr != NULL) { if (strcmp(foundPtr->str, str)) { foundPtr = foundPtr->cdr; } return foundPtr; } else { return NULL; } }
bool PlyReader::hasProperty(const std::string& elementName, const std::string& propertyName) const { SURGSIM_ASSERT(isValid()) << "'" << m_filename << "' is an invalid .ply file"; bool result = false; PlyElement* element = find_element(m_data->plyFile, elementName.c_str()); if (element != nullptr) { int index; result = find_property(element, propertyName.c_str(), &index) != nullptr; } return result; }
void theme::set_object_location(theme::object& element, std::string rect_str, std::string ref_id) { theme::object ref_element = element; if(ref_id.empty()) { ref_id = element.get_id(); } else { ref_element = find_element(ref_id); } if(ref_element.get_id() == ref_id) { SDL_Rect location_ref_rect = ref_element.get_location(); element.modify_location(rect_str, location_ref_rect); } }
static void assoc_delete_key (SLang_Assoc_Array_Type *a, char *key) { _pSLAssoc_Array_Element_Type *e; e = find_element (a, key, _pSLstring_get_hash (key)); if (e == NULL) return; _pSLang_free_slstring ((char *) e->key); SLang_free_object (&e->value); e->key = Deleted_Key; a->num_deleted++; }
void select_find(unsigned int* number_of_nodes) { if(0 == *number_of_nodes){ puts("the tree is empty, first create a tree root"); }else{ if(0 > find_element()){ printf("not found\n"); }else{ printf("found\n"); } printf("%d elements\ndone.\n", *number_of_nodes); } }
OFDPE remove_action( action_list *list, action *action ) { assert( list != NULL ); assert( action != NULL ); dlist_element *element = find_element( get_first_element( list ), action ); if ( element == NULL ) { return ERROR_NOT_FOUND; } delete_action( action ); delete_dlist_element( element ); return OFDPE_SUCCESS; }
OFDPE remove_action_bucket( bucket_list *list, bucket *bucket ) { assert( list != NULL ); assert( bucket != NULL ); dlist_element *elemenet = find_element( list, bucket ); if ( elemenet == NULL ) { return ERROR_NOT_FOUND; } delete_action_bucket( bucket ); delete_dlist_element( elemenet ); return OFDPE_SUCCESS; }
void lirc_client_setnick(struct LIRCServer_struct* server, int socket, char* nick) { LIRCClientData* client = (LIRCClientData*)find_element(server->client_list, &socket, lirc_client_cmp); if (client != NULL && client->nick != NULL) { dlnode_t* channel_node; char temp[MAX_IRC_MESSAGE_SIZE]; sprintf(temp, ":%s!~%[email protected] NICK :", client->nick, client->user); printf("Nickname changed from %s ", client->nick); free(client->nick); client->nick = safe_strdup(nick); printf("to %s.\n", client->nick); /* Send an acknowledgement response to the client to say * everything went ok. */ sprintf(temp + strlen(temp), "%s\r\n", client->nick); send(socket, temp, strlen(temp), 0); /* Let every client know of every joined channel that * the nickname has been changed. This code doesn't check for * two or more clients in two or more rooms and couple result * in duplicates. */ channel_node = client->channel_list->head; while (channel_node != NULL) { struct LIRCChannelData_struct* c = (struct LIRCChannelData_struct*)channel_node->data; dlnode_t* client_node = c->client_list->head; while (client_node != NULL) { LIRCClientData* c_data = (LIRCClientData*)client_node->data; send(c_data->socket, temp, strlen(temp), 0); client_node = client_node->next; } channel_node = channel_node->next; } } }