static int write_trailer(AVFormatContext *s) { int i; write_tags(s->pb, s->metadata); for (i = 0; i < s->nb_streams; i++) { put_tag(s->pb, ID_STREAM); put_byte(s->pb, '\n'); write_tags(s->pb, s->streams[i]->metadata); } for (i = 0; i < s->nb_chapters; i++) { AVChapter *ch = s->chapters[i]; put_tag(s->pb, ID_CHAPTER); put_byte(s->pb, '\n'); url_fprintf(s->pb, "TIMEBASE=%d/%d\n", ch->time_base.num, ch->time_base.den); url_fprintf(s->pb, "START=%"PRId64"\n", ch->start); url_fprintf(s->pb, "END=%"PRId64"\n", ch->end); write_tags(s->pb, ch->metadata); } put_flush_packet(s->pb); return 0; }
ErrorCode WriteVtk::write_file(const char *file_name, const bool overwrite, const FileOptions& opts, const EntityHandle *output_list, const int num_sets, const std::vector<std::string>& /* qa_list */, const Tag* tag_list, int num_tags, int /* export_dimension */) { ErrorCode rval; // Get precision for node coordinates int precision; if (MB_SUCCESS != opts.get_int_option("PRECISION", precision)) precision = DEFAULT_PRECISION; if (MB_SUCCESS == opts.get_null_option("STRICT")) mStrict = true; else if (MB_SUCCESS == opts.get_null_option("RELAXED")) mStrict = false; else mStrict = DEFAULT_STRICT; // Get entities to write Range nodes, elems; rval = gather_mesh(output_list, num_sets, nodes, elems); if (MB_SUCCESS != rval) return rval; // Honor overwrite flag if (!overwrite) { rval = writeTool->check_doesnt_exist(file_name); if (MB_SUCCESS != rval) return rval; } // Create file std::ofstream file(file_name); if (!file) { MB_SET_ERR(MB_FILE_WRITE_ERROR, "Could not open file: " << file_name); } file.precision(precision); // Write file if ((rval = write_header(file )) != MB_SUCCESS || (rval = write_nodes( file, nodes )) != MB_SUCCESS || (rval = write_elems( file, nodes, elems)) != MB_SUCCESS || (rval = write_tags ( file, true, nodes, tag_list, num_tags)) != MB_SUCCESS || (rval = write_tags ( file, false, elems, tag_list, num_tags)) != MB_SUCCESS) { file.close(); remove(file_name); return rval; } return MB_SUCCESS; }
void relation(const osmium::Relation& relation) { if (m_write_change_ops) { open_close_op_tag(relation.visible() ? (relation.version() == 1 ? operation::op_create : operation::op_modify) : operation::op_delete); } write_prefix(); m_out += "<relation"; write_meta(relation); if (relation.tags().empty() && relation.members().empty()) { m_out += "/>\n"; return; } m_out += ">\n"; for (const auto& member : relation.members()) { write_prefix(); m_out += " <member type=\""; m_out += item_type_to_name(member.type()); oprintf(m_out, "\" ref=\"%" PRId64 "\" role=\"", member.ref()); xml_string(m_out, member.role()); m_out += "\"/>\n"; } write_tags(relation.tags()); write_prefix(); m_out += "</relation>\n"; }
void way(const osmium::Way& way) { if (m_write_change_ops) { open_close_op_tag(way.visible() ? (way.version() == 1 ? operation::op_create : operation::op_modify) : operation::op_delete); } write_prefix(); m_out += "<way"; write_meta(way); if (way.tags().empty() && way.nodes().empty()) { m_out += "/>\n"; return; } m_out += ">\n"; for (const auto& node_ref : way.nodes()) { write_prefix(); oprintf(m_out, " <nd ref=\"%" PRId64 "\"/>\n", node_ref.ref()); } write_tags(way.tags()); write_prefix(); m_out += "</way>\n"; }
void node(const osmium::Node& node) { if (m_write_change_ops) { open_close_op_tag(node.visible() ? (node.version() == 1 ? operation::op_create : operation::op_modify) : operation::op_delete); } write_prefix(); m_out += "<node"; write_meta(node); if (node.location()) { m_out += " lat=\""; osmium::util::double2string(std::back_inserter(m_out), node.location().lat_without_check(), 7); m_out += "\" lon=\""; osmium::util::double2string(std::back_inserter(m_out), node.location().lon_without_check(), 7); m_out += "\""; } if (node.tags().empty()) { m_out += "/>\n"; return; } m_out += ">\n"; write_tags(node.tags()); write_prefix(); m_out += "</node>\n"; }
static int write_trailer(AVFormatContext *s) { int i; write_tags(s->pb, s->metadata); for (i = 0; i < s->nb_streams; i++) { avio_write(s->pb, ID_STREAM, sizeof(ID_STREAM) - 1); avio_w8(s->pb, '\n'); write_tags(s->pb, s->streams[i]->metadata); } for (i = 0; i < s->nb_chapters; i++) { AVChapter *ch = s->chapters[i]; avio_write(s->pb, ID_CHAPTER, sizeof(ID_CHAPTER) - 1); avio_w8(s->pb, '\n'); avio_printf(s->pb, "TIMEBASE=%d/%d\n", ch->time_base.num, ch->time_base.den); avio_printf(s->pb, "START=%"PRId64"\n", ch->start); avio_printf(s->pb, "END=%"PRId64"\n", ch->end); write_tags(s->pb, ch->metadata); } return 0; }
void changeset(const osmium::Changeset& changeset) { write_prefix(); m_out += "<changeset"; oprintf(m_out, " id=\"%" PRId32 "\"", changeset.id()); if (changeset.created_at()) { m_out += " created_at=\""; m_out += changeset.created_at().to_iso(); m_out += "\""; } oprintf(m_out, " num_changes=\"%" PRId32 "\"", changeset.num_changes()); if (changeset.closed_at()) { m_out += " closed_at=\""; m_out += changeset.closed_at().to_iso(); m_out += "\" open=\"false\""; } else { m_out += " open=\"true\""; } if (changeset.bounds()) { oprintf(m_out, " min_lon=\"%.7f\"", changeset.bounds().bottom_left().lon_without_check()); oprintf(m_out, " min_lat=\"%.7f\"", changeset.bounds().bottom_left().lat_without_check()); oprintf(m_out, " max_lon=\"%.7f\"", changeset.bounds().top_right().lon_without_check()); oprintf(m_out, " max_lat=\"%.7f\"", changeset.bounds().top_right().lat_without_check()); } if (!changeset.user_is_anonymous()) { m_out += " user=\""; xml_string(m_out, changeset.user()); oprintf(m_out, "\" uid=\"%d\"", changeset.uid()); } if (changeset.tags().empty()) { m_out += "/>\n"; return; } m_out += ">\n"; write_tags(changeset.tags()); write_prefix(); m_out += "</changeset>\n"; }
void relation(const osmium::Relation& relation) { m_out << "r"; write_meta(relation); m_out << " M"; int n=0; for (const auto& member : relation.members()) { if (n++ != 0) { m_out << ","; } m_out << item_type_to_char(member.type()) << member.ref() << "!" << member.role(); } write_tags(relation.tags()); m_out << "\n"; ::write(this->fd(), m_out.str().c_str(), m_out.str().size()); m_out.str(""); }
char load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity, char immediate_load) { ImlibLoader *loader; lopt opt; int res; struct stat st; assert(im); if (stat(im->real_file, &st) < 0) return 0; if (!get_options(&opt, im)) return 0; if (!get_loader(&opt, &loader)) goto fail_context; if (loader) { char *ofile, tmp[] = "/tmp/imlib2_loader_id3-XXXXXX"; int dest; if ((dest = mkstemp(tmp)) < 0) { fprintf(stderr, "Unable to create a temporary file\n"); goto fail_context; } res = extract_pic(id3_tag_get_frame(opt.ctx->tag, opt.index - 1), dest); close(dest); if (!res) { unlink(tmp); goto fail_context; } ofile = im->real_file; im->real_file = strdup(tmp); res = loader->load(im, progress, progress_granularity, immediate_load); free(im->real_file); im->real_file = ofile; unlink(tmp); } else { /* The tag actually provides a image url rather than image data. * Practically, dunno if such a tag exists on earth :) * Here's the code anyway... */ union id3_field *field; id3_length_t length; char const *data; char *url, *file, *ofile; field = id3_frame_field (id3_tag_get_frame(opt.ctx->tag, opt.index - 1), 4); data = (char const *)id3_field_getbinarydata(field, &length); if (!data || !length) { fprintf(stderr, "No link image URL present\n"); goto fail_context; } url = (char *)malloc((length + 1) * sizeof(char)); strncpy(url, data, length); url[length] = '\0'; file = (strncmp(url, "file://", 7) ? url : url + 7); if (!(loader = __imlib_FindBestLoaderForFile(file, 0))) { fprintf(stderr, "No loader found for file %s\n", file); free(url); goto fail_context; } ofile = im->real_file; im->real_file = file; res = loader->load(im, progress, progress_granularity, immediate_load); if (!im->loader) __imlib_AttachTag(im, "id3-link-url", 0, url, destructor_data); else free(url); im->real_file = ofile; } if (!im->loader) write_tags(im, &opt); #ifdef DEBUG if (!im->loader) { ImlibImageTag *cur = im->tags; fprintf(stderr, "Tags for file %s:\n", im->file); while (cur) { fprintf(stderr, "\t%s: (%d) %s\n", cur->key, cur->val, (char *)cur->data); cur = cur->next; } } #endif context_delref(opt.ctx); return res; fail_context: context_delref(opt.ctx); return 0; }
int find_repeats(GapIO *io, int handle, /*del */ int mode, int min_match, int mask, float percd, /* del */ int num_contigs, contig_list_t *contig_array, char *out_name) { int *cends, *nends; int *sav1, *sav2, *sav3, *sav4, *sav5; char *consensus; int max_consensus, max_read_length, database_size, number_of_contigs; int consensus_length, ret, task_mask; int max_matches; int i,j; int num_f_matches, num_r_matches; Contig_parms *contig_list; Hidden_params p; p.min = p.max = p.verbose = p.use_conf = p.qual_val = p.window_len =0; p.test_mode = 0; p.start = 0; p.lwin1 = 0; p.lcnt1 = 0; p.rwin1 = 0; p.rcnt1 = 0; p.do_it = 0; max_consensus = maxseq; /* global! */ max_matches = max_consensus / 20; consensus = NULL; contig_list = NULL; cends = nends = sav1 = sav2 = sav3 = sav4 = sav5 = NULL; if ((cends = (int *)xmalloc(max_consensus * sizeof(int)))==NULL){ goto bail_out; } if ((nends = (int *)xmalloc(max_consensus * sizeof(int)))==NULL){ goto bail_out; } if ((sav2 = (int *)xmalloc(max_matches * sizeof(int)))==NULL){ goto bail_out; } if ((sav4 = (int *)xmalloc(max_matches * sizeof(int)))==NULL){ goto bail_out; } if ((sav5 = (int *)xmalloc(max_matches * sizeof(int)))==NULL){ goto bail_out; } max_read_length = find_max_gel_len(io, 0, 0); if ((consensus = (char *)xmalloc(max_consensus * sizeof(char)))==NULL){ goto bail_out; } database_size = io_dbsize(io); number_of_contigs = num_contigs; if ( ! (contig_list = get_contig_list ( database_size, io, number_of_contigs, contig_array ))) { goto bail_out; } task_mask = ADDTITLE | NORMALCONSENSUS; if ( mask == 3 ) task_mask |= MASKING; consensus_length = 0; /* printf("TASK mask %d mask %d mode %d\n",task_mask,mask,mode); */ if ( ret = make_consensus ( task_mask, io, consensus, NULL, contig_list, number_of_contigs, &consensus_length, max_read_length, max_consensus, p, consensus_cutoff ) ) { goto bail_out; } ret = repeat_search ( mode, min_match, &sav4, &sav2, &sav5, max_matches, consensus, consensus_length, &num_f_matches, &num_r_matches ); if( ret < 0 ) { goto bail_out; } /* get the output arrays filled in to fit with old routines!!*/ if ((sav1 = (int *)xmalloc((num_f_matches + num_r_matches + 1) * sizeof(int)))==NULL){ goto bail_out; } if ((sav3 = (int *)xmalloc((num_f_matches + num_r_matches + 1) * sizeof(int)))==NULL){ goto bail_out; } for ( i=0;i<num_f_matches; i++ ) { if ( -1 != (j = (contig_listel_from_con_pos ( contig_list, number_of_contigs, sav2[i] )))) { sav1[i] = contig_list[j].contig_left_gel; sav2[i] = sav2[i] + contig_list[j].contig_start - contig_list[j].contig_start_offset - 1; } else { goto bail_out; } if ( -1 != (j = (contig_listel_from_con_pos ( contig_list, number_of_contigs, sav4[i] )))) { sav3[i] = contig_list[j].contig_left_gel; sav4[i] = sav4[i] + contig_list[j].contig_start - contig_list[j].contig_start_offset - 1; } else { goto bail_out; } } for ( i=num_f_matches; i<num_f_matches+num_r_matches;i++ ) { if ( -1 != (j = (contig_listel_from_con_pos ( contig_list, number_of_contigs, sav2[i] )))) { sav1[i] = -contig_list[j].contig_left_gel; sav2[i] = sav2[i] + contig_list[j].contig_start - contig_list[j].contig_start_offset - 1;; } else { goto bail_out; } if ( -1 != (j = (contig_listel_from_con_pos ( contig_list, number_of_contigs, sav4[i] )))) { sav3[i] = contig_list[j].contig_left_gel; sav4[i] = sav4[i] + contig_list[j].contig_start - contig_list[j].contig_start_offset - 1; } else { goto bail_out; } } /* end new */ flush2t(io); /* FIXME write_tags needs arguments changing from f_int to int */ if (out_name) { write_tags(io, out_name, num_f_matches+num_r_matches, sav1, sav2, sav3, sav4, sav5); } plot_rpt(io, num_f_matches+num_r_matches, sav1, sav2, sav3, sav4, sav5); if ( cends ) xfree(cends); if ( nends ) xfree(nends); if ( sav1 ) xfree(sav1); if ( sav2 ) xfree(sav2); if ( sav3 ) xfree(sav3); if ( sav4 ) xfree(sav4); if ( sav5 ) xfree(sav5); if ( consensus ) xfree(consensus); if ( contig_list ) xfree(contig_list); return 0; bail_out: if ( cends ) xfree(cends); if ( nends ) xfree(nends); if ( sav1 ) xfree(sav1); if ( sav2 ) xfree(sav2); if ( sav3 ) xfree(sav3); if ( sav4 ) xfree(sav4); if ( sav5 ) xfree(sav5); if ( consensus ) xfree(consensus); if ( contig_list ) xfree(contig_list); return -1; } /* end FindRepeats */