Example #1
0
static const gchar *
lookup_in_mapping (const struct mapping_entry *mapping,
                   gint                        mapping_size,
                   const gunichar             *key,
                   gint                       *result_len,
                   gint                       *key_consumed)
{
  const struct mapping_entry *hit;

  hit = bsearch (key, mapping, mapping_size, sizeof (struct mapping_entry), compare_mapping_entry);

  if (hit == NULL)
    return NULL;

  *key_consumed = get_length (hit->src);
  *result_len = get_length (hit->ascii);

  return get_ascii_item(ascii_table, hit->ascii);
}
Example #2
0
/******************************************************************************
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);
}