static int gt_fasta_reader_rec_run(GtFastaReader *fasta_reader, GtFastaReaderProcDescription proc_description, GtFastaReaderProcSequencePart proc_sequence_part, GtFastaReaderProcSequenceLength proc_sequence_length, void *data, GtError *err) { GtFastaReaderRec *fr = gt_fasta_reader_rec_cast(fasta_reader); GtStr *description, *sequence; int had_err = 0; gt_error_check(err); /* at least one function has to be defined */ gt_assert(proc_description || proc_sequence_part || proc_sequence_length); /* init */ description = gt_str_new(); sequence = gt_str_new(); /* make sure file is not empty */ if (!gt_io_has_char(fr->seqio)) { gt_error_set(err, "sequence file \"%s\" is empty", gt_io_get_filename(fr->seqio)); had_err = -1; } /* parse file */ while (!had_err && gt_io_has_char(fr->seqio)) { /* reset */ gt_str_reset(description); gt_str_reset(sequence); /* parse entry */ had_err = parse_fasta_entry(description, sequence, fr->seqio, err); /* process entry */ if (!had_err && proc_description) { had_err = proc_description(gt_str_get(description), gt_str_length(description), data, err); } if (!had_err && proc_sequence_part) { had_err = proc_sequence_part(gt_str_get(sequence), gt_str_length(sequence), data, err); } if (!had_err && proc_sequence_length) had_err = proc_sequence_length(gt_str_length(sequence), data, err); } /* free */ gt_str_delete(description); gt_str_delete(sequence); return had_err; }
static int parse_bed_file(GtBEDParser *bed_parser, GtIO *bed_file, GtError *err) { int had_err = 0; gt_error_check(err); gt_assert(bed_file); while (!had_err && gt_io_has_char(bed_file)) { switch (gt_io_peek(bed_file)) { case BLANK_CHAR: had_err = bed_parser_blank_line(bed_file, err); break; case COMMENT_CHAR: had_err = bed_parser_comment_line(bed_file, err); break; case GT_CARRIAGE_RETURN: gt_io_next(bed_file); if (gt_io_peek(bed_file) == GT_END_OF_LINE) gt_io_next(bed_file); break; case GT_END_OF_LINE: gt_io_next(bed_file); break; default: had_err = bed_line(bed_parser, bed_file, err); } } if (!had_err) had_err = gt_io_expect(bed_file, GT_END_OF_FILE, err); return had_err; }
static int parse_obo_file(GtOBOParseTree *obo_parse_tree, GtIO *obo_file, GtError *err) { int had_err = 0; gt_error_check(err); gt_assert(obo_parse_tree && obo_file); while (!had_err && ignored_char(obo_file)) { had_err = ignored_line(obo_file, err); } if (!had_err) had_err = header(obo_parse_tree, obo_file, err); while (!had_err && gt_io_has_char(obo_file)) { switch (gt_io_peek(obo_file)) { case OBO_BLANK_CHAR: had_err = blank_line(obo_file, err); break; case OBO_COMMENT_CHAR: had_err = comment_line(obo_file, err); break; case GT_CARRIAGE_RETURN: gt_io_next(obo_file); if (gt_io_peek(obo_file) == GT_END_OF_LINE) gt_io_next(obo_file); break; case GT_END_OF_LINE: gt_io_next(obo_file); break; default: had_err = stanza(obo_parse_tree, obo_file, err); } } if (!had_err) had_err = gt_io_expect(obo_file, GT_END_OF_FILE, err); if (!had_err) had_err = gt_obo_parse_tree_validate_stanzas(obo_parse_tree, err); return had_err; }
static int parse_xrf_abbr_file(GtXRFAbbrParseTree *xrf_abbr_parse_tree, GtIO *xrf_abbr_file, GtError *err) { int had_err = 0; gt_error_check(err); gt_assert(xrf_abbr_parse_tree && xrf_abbr_file); while (!had_err && gt_xrf_abbr_parse_tree_ignored_char(xrf_abbr_file)) { had_err = gt_xrf_abbr_parse_tree_ignored_line(xrf_abbr_file, err); } while (!had_err && gt_io_has_char(xrf_abbr_file)) { switch (gt_io_peek(xrf_abbr_file)) { case XRF_BLANK_CHAR: had_err = gt_xrf_abbr_parse_tree_blank_line(xrf_abbr_file, err); break; case XRF_COMMENT_CHAR: had_err = gt_xrf_abbr_parse_tree_comment_line(xrf_abbr_file, err); break; case GT_CARRIAGE_RETURN: gt_io_next(xrf_abbr_file); if (gt_io_peek(xrf_abbr_file) == GT_END_OF_LINE) gt_io_next(xrf_abbr_file); break; case GT_END_OF_LINE: gt_io_next(xrf_abbr_file); break; default: had_err = gt_xrf_abbr_parse_tree_entry(xrf_abbr_parse_tree, xrf_abbr_file, err); } } if (!had_err) had_err = gt_io_expect(xrf_abbr_file, GT_END_OF_FILE, err); if (!had_err) had_err = gt_xrf_abbr_parse_tree_validate_entries(xrf_abbr_parse_tree, err); return had_err; }