static int fill_mapping(GtSeqid2SeqnumMapping *mapping, GtBioseq *bioseq, GtSeqCol *seqcol, GT_UNUSED GtError *err) { GtUword i, j, nof_sequences, nof_files; int had_err = 0; gt_error_check(err); gt_assert(mapping && (bioseq || seqcol) && !(bioseq && seqcol)); if (bioseq) { nof_files = 1; } else { gt_assert(seqcol); nof_files = gt_seq_col_num_of_files(seqcol); } for (j = 0; !had_err && j < nof_files; j++) { if (bioseq) nof_sequences = gt_bioseq_number_of_sequences(bioseq); else { gt_assert(seqcol); nof_sequences = gt_seq_col_num_of_seqs(seqcol, j); } for (i = 0; !had_err && i < nof_sequences; i++) { char *desc; if (bioseq) desc = gt_cstr_dup(gt_bioseq_get_description(bioseq, i)); else desc = gt_seq_col_get_description(seqcol, j, i); had_err = handle_description(mapping, desc, i, j, err); gt_free(desc); } } return had_err; }
static int handle_category(xmlNode *n, sylverant_quest_list_t *l) { xmlChar *name, *type; int rv = 0; uint32_t type_num; void *tmp; sylverant_quest_category_t *cat; /* Grab the attributes we're expecting */ name = xmlGetProp(n, XC"name"); type = xmlGetProp(n, XC"type"); /* Make sure we have both of them... */ if(!name || !type) { debug(DBG_ERROR, "Name or type not given for category\n"); rv = -1; goto err; } /* Make sure the type is sane */ if(!xmlStrcmp(type, XC"normal")) { type_num = SYLVERANT_QUEST_NORMAL; } else if(!xmlStrcmp(type, XC"battle")) { type_num = SYLVERANT_QUEST_BATTLE; } else if(!xmlStrcmp(type, XC"challenge")) { type_num = SYLVERANT_QUEST_CHALLENGE; } else if(!xmlStrcmp(type, XC"government")) { type_num = SYLVERANT_QUEST_GOVERNMENT; } else { debug(DBG_ERROR, "Invalid category type: %s\n", (char *)type); rv = -2; goto err; } /* Allocate space for the category */ tmp = realloc(l->cats, (l->cat_count + 1) * sizeof(sylverant_quest_category_t)); if(!tmp) { debug(DBG_ERROR, "Couldn't allocate space for category\n"); perror("realloc"); rv = -3; goto err; } l->cats = (sylverant_quest_category_t *)tmp; cat = l->cats + l->cat_count++; /* Clear the category out */ memset(cat, 0, sizeof(sylverant_quest_category_t)); /* Copy over what we have so far */ cat->type = type_num; strncpy(cat->name, (const char *)name, 31); cat->name[31] = '\0'; /* Now that we're done with that, deal with any children of the node */ n = n->children; while(n) { if(n->type != XML_ELEMENT_NODE) { /* Ignore non-elements. */ n = n->next; continue; } else if(!xmlStrcmp(n->name, XC"description")) { if(handle_description(n, cat)) { rv = -4; goto err; } } else if(!xmlStrcmp(n->name, XC"quest")) { if(handle_quest(n, cat)) { rv = -5; goto err; } } else { debug(DBG_WARN, "Invalid Tag %s on line %hu\n", (char *)n->name, n->line); } n = n->next; } err: xmlFree(name); xmlFree(type); return rv; }