int process_update_command ( char *key, size_t nkey, uint32_t flags, char *value, size_t nbytes, int32_t exptime_int, int comm ) { item *it; enum store_item_type ret; int32_t vlen = ( int32_t ) nbytes; if ( exptime_int < 0 ) exptime_int = REALTIME_MAXDELTA + 1; vlen += 2; if ( vlen < 0 || vlen - 2 < 0 ) { return false; } it = item_alloc (key, nkey, flags, realtime (exptime_int), value, vlen); if ( it == 0 ) { if ( comm == NREAD_SET ) { it = item_get (key, nkey); if ( it ) { item_unlink (it); item_remove (it); } } return false; } ret = store_item (it, comm); item_remove (it); if ( ret != STORED ) { return false; } return true; }
/****************************************************************************** Read an element from an ascii file. Entry: plyfile - file identifier elem_ptr - pointer to element ******************************************************************************/ void ascii_get_element(PlyFile *plyfile, char *elem_ptr) { //int i,j,k; int j,k; PlyElement *elem; PlyProperty *prop; char **words; int nwords; int which_word; //FILE *fp = plyfile->fp; char *elem_data,*item; char *item_ptr; int item_size; int int_val; unsigned int uint_val; double double_val; int list_count; int store_it; char **store_array; char *orig_line; char *other_data; int other_flag; other_data = NULL; // the kind of element we're reading currently elem = plyfile->which_elem; // do we need to setup for other_props? if (elem->other_offset != NO_OTHER_PROPS) { char **ptr; other_flag = 1; // make room for other_props other_data = (char *) myalloc (elem->other_size); // store pointer in user's structure to the other_props ptr = (char **) (elem_ptr + elem->other_offset); *ptr = other_data; } else { other_flag = 0; } // read in the element words = get_words(plyfile->fp, &nwords, &orig_line); if (words == NULL) { fprintf (stderr, "ply_get_element: unexpected end of file\n"); exit (-1); } which_word = 0; for (j = 0; j < elem->nprops; j++) { prop = elem->props[j]; store_it = (elem->store_prop[j] | other_flag); // store either in the user's structure or in other_props if (elem->store_prop[j]) { elem_data = elem_ptr; } else { elem_data = other_data; } if (prop->is_list) { // a list // get and store the number of items in the list get_ascii_item (words[which_word++], prop->count_external, &int_val, &uint_val, &double_val); if (store_it) { item = elem_data + prop->count_offset; store_item(item, prop->count_internal, int_val, uint_val, double_val); } // allocate space for an array of items and store a ptr to the array list_count = int_val; item_size = ply_type_size[prop->internal_type]; store_array = (char **) (elem_data + prop->offset); if (list_count == 0) { if (store_it) { *store_array = NULL; } } else { if (store_it) { item_ptr = (char *) myalloc (sizeof (char) * item_size * list_count); item = item_ptr; *store_array = item_ptr; } // read items and store them into the array for (k = 0; k < list_count; k++) { get_ascii_item (words[which_word++], prop->external_type, &int_val, &uint_val, &double_val); if (store_it) { store_item (item, prop->internal_type, int_val, uint_val, double_val); item += item_size; } } } } else { // not a list get_ascii_item (words[which_word++], prop->external_type, &int_val, &uint_val, &double_val); if (store_it) { item = elem_data + prop->offset; store_item (item, prop->internal_type, int_val, uint_val, double_val); } } } free (words); }