void UmlArtifact::write(FileOut & out) { const char * k = (_uml_20) ? "ownedMember" : "packagedElement"; out.indent(); out << "<" << k << " xmi:type=\"uml:Artifact\""; out.id(this); out << " name=\""; out.quote((const char *)name()); //[jasa] ambiguous call out << "\">\n"; out.indent(+1); write_description_properties(out); const Q3PtrVector<UmlItem> ch = children(); unsigned i; unsigned n = ch.size(); unsigned rank = 0; for (i = 0; i != n; i += 1) { UmlItem * x = ch[i]; if ((x->kind() == aNcRelation) && (x->stereotype() == "manifest") && (((UmlNcRelation *) x)->relationKind() == aDependency)) write_manifest(out, ((UmlNcRelation *) x)->target(), "dependency", ++rank); else ch[i]->write(out); } if (stereotype() == "source") { const Q3PtrVector<UmlClass> & cls = associatedClasses(); n = cls.size(); for (i = 0; i != n; i += 1) write_manifest(out, cls[i], "source", ++rank); } else { const Q3PtrVector<UmlArtifact> & arts = associatedArtifacts(); n = arts.size(); for (i = 0; i != n; i += 1) write_manifest(out, arts[i], 0, ++rank); } out.indent(-1); out.indent(); out << "</" << k << ">\n"; unload(); }
// Put the object name into a manifest file given a set of included files. // Returns true on success, otherwise false. bool manifest_put(const char *manifest_path, struct file_hash *object_hash, struct hashtable *included_files) { int ret = 0; gzFile f2 = NULL; struct manifest *mf = NULL; char *tmp_file = NULL; // We don't bother to acquire a lock when writing the manifest to disk. A // race between two processes will only result in one lost entry, which is // not a big deal, and it's also very unlikely. int fd1 = open(manifest_path, O_RDONLY | O_BINARY); if (fd1 == -1) { // New file. mf = create_empty_manifest(); } else { gzFile f1 = gzdopen(fd1, "rb"); if (!f1) { cc_log("Failed to gzdopen manifest file"); close(fd1); goto out; } mf = read_manifest(f1); gzclose(f1); if (!mf) { cc_log("Failed to read manifest file; deleting it"); x_unlink(manifest_path); mf = create_empty_manifest(); } } if (mf->n_objects > MAX_MANIFEST_ENTRIES) { // Normally, there shouldn't be many object entries in the manifest since // new entries are added only if an include file has changed but not the // source file, and you typically change source files more often than // header files. However, it's certainly possible to imagine cases where // the manifest will grow large (for instance, a generated header file that // changes for every build), and this must be taken care of since // processing an ever growing manifest eventually will take too much time. // A good way of solving this would be to maintain the object entries in // LRU order and discarding the old ones. An easy way is to throw away all // entries when there are too many. Let's do that for now. cc_log("More than %u entries in manifest file; discarding", MAX_MANIFEST_ENTRIES); free_manifest(mf); mf = create_empty_manifest(); } else if (mf->n_file_infos > MAX_MANIFEST_FILE_INFO_ENTRIES) { // Rarely, file_info entries can grow large in pathological cases where // many included files change, but the main file does not. This also puts // an upper bound on the number of file_info entries. cc_log("More than %u file_info entries in manifest file; discarding", MAX_MANIFEST_FILE_INFO_ENTRIES); free_manifest(mf); mf = create_empty_manifest(); } tmp_file = format("%s.tmp", manifest_path); int fd2 = create_tmp_fd(&tmp_file); f2 = gzdopen(fd2, "wb"); if (!f2) { cc_log("Failed to gzdopen %s", tmp_file); goto out; } add_object_entry(mf, object_hash, included_files); if (write_manifest(f2, mf)) { gzclose(f2); f2 = NULL; if (x_rename(tmp_file, manifest_path) == 0) { ret = 1; } else { cc_log("Failed to rename %s to %s", tmp_file, manifest_path); goto out; } } else { cc_log("Failed to write manifest file"); goto out; } out: if (mf) { free_manifest(mf); } if (tmp_file) { free(tmp_file); } if (f2) { gzclose(f2); } return ret; }
void process_fastq_to_sff(char *sff_file) { FILE *sff_fp; if ( (sff_fp = fopen(sff_file, "w")) == NULL ) { fprintf(stderr, "[err] Could not open file '%s' for writing.\n", sff_file); exit(1); } sff_common_header ch; /* sff files are in big endian notation so adjust appropriately */ /* Linux version, not in use any more ch.magic = be32toh(h.magic); ch.index_len = be32toh(h.index_len); ch.header_len = be16toh(h.header_len); ch.key_len = be16toh(h.key_len); ch.flow = h.flow;//ff; ch.flow_len = be16toh(h.flow_len); ch.flowgram_format = h.flowgram_format;//0x01; ch.key = h.key;//"GACT"; char v[4] = {0x00,0x00,0x00,0x01}; //ch.version = ; memcpy(ch.version,v,4); */ ch.magic = ntohl(h.magic); ch.index_len = ntohl(h.index_len); ch.header_len = ntohs(h.header_len); ch.key_len = ntohs(h.key_len); ch.flow = h.flow;//ff; ch.flow_len = ntohs(h.flow_len); ch.flowgram_format = h.flowgram_format;//0x01; ch.key = h.key;//"GACT"; char v[4] = {0x00,0x00,0x00,0x01}; //ch.version = ; memcpy(ch.version,v,4); int header_size = sizeof(ch.magic) + sizeof(*(ch.version))*4 + sizeof(ch.index_offset) + sizeof(ch.index_len) + sizeof(ch.nreads) + sizeof(ch.header_len) + sizeof(ch.key_len) + sizeof(ch.flow_len) + sizeof(ch.flowgram_format) //+ (sizeof(char) * htobe16(ch.flow_len) ) //+ (sizeof(char) * htobe16(ch.key_len) ) ; + (sizeof(char) * htons(ch.flow_len) ) + (sizeof(char) * htons(ch.key_len) ) ; if ( !(header_size % PADDING_SIZE == 0) ) { header_size += PADDING_SIZE - (header_size % PADDING_SIZE); } fseek(sff_fp,header_size,SEEK_SET); ch.nreads = 0; unsigned int numreads = reads.size(); for (unsigned int i = 0; i < numreads; i++) { if(reads[i]->discarded) continue; sff_read_header readHeader; readHeader.nbases = reads[i]->read.length(); readHeader.name = (char*)malloc(sizeof(char)*strlen(reads[i]->readID)); memcpy( readHeader.name, reads[i]->readID, (size_t) strlen(reads[i]->readID) );//This line causes a problem on slarti with sff_extract readHeader.name_len = strlen(reads[i]->readID); /*Working with clip points*/ readHeader.clip_qual_left = reads[i]->lclip; readHeader.clip_qual_right = reads[i]->rclip; readHeader.clip_adapter_left = 0;//reads[i]->lclip; readHeader.clip_adapter_right = 0;//reads[i]->rclip; readHeader.header_len = sizeof(readHeader.header_len) + sizeof(readHeader.name_len) + sizeof(readHeader.nbases) + sizeof(readHeader.clip_qual_left) + sizeof(readHeader.clip_qual_right) + sizeof(readHeader.clip_adapter_left) + sizeof(readHeader.clip_adapter_right) + (sizeof(char) * readHeader.name_len); if ( !( readHeader.header_len % 8 == 0) ) { readHeader.header_len += 8 - (readHeader.header_len % 8); } sff_read_data readData; readData.bases = (char*)reads[i]->read.c_str(); readData.flow_index = reads[i]->flow_index; readData.flowgram = reads[i]->flowgram; readData.quality = (uint8_t*)malloc(sizeof(uint8_t)*(readHeader.nbases)); int j=0; for(j=0; j<readHeader.nbases; ++j) { readData.quality[j] = reads[i]->quality[j] - 33; } //readData.quality[j] = '\0'; write_sff_read_header(sff_fp, &(readHeader)); //write_sff_read_data(sff_fp, &(readData), htobe16(ch.flow_len), htobe32(readHeader.nbases)); write_sff_read_data(sff_fp, &(readData), htons(ch.flow_len), htonl(readHeader.nbases)); //free(rd.bases); free(readData.flow_index); free(readData.flowgram); free(readData.quality); ch.nreads += 1; } /* Linux edition, not in use any more ch.nreads = be32toh(ch.nreads);//be32toh(reads.size()); ch.index_offset = be64toh( ftell(sff_fp) ); */ ch.nreads = ntohl(ch.nreads); ch.index_offset = be64toh( ftell(sff_fp) ); write_manifest(sff_fp); fseek(sff_fp, 0, SEEK_SET); // seek back to beginning of file write_sff_common_header(sff_fp, &ch); fclose(sff_fp); }
/* * Put the object name into a manifest file given a set of included files. * Returns true on success, otherwise false. */ bool manifest_put(const char *manifest_path, struct file_hash *object_hash, struct hashtable *included_files) { int ret = 0; int fd1; int fd2; gzFile f2 = NULL; struct manifest *mf = NULL; char *tmp_file = NULL; /* * We don't bother to acquire a lock when writing the manifest to disk. A * race between two processes will only result in one lost entry, which is * not a big deal, and it's also very unlikely. */ fd1 = open(manifest_path, O_RDONLY | O_BINARY); if (fd1 == -1) { /* New file. */ mf = create_empty_manifest(); } else { gzFile f1 = gzdopen(fd1, "rb"); if (!f1) { cc_log("Failed to gzdopen manifest file"); close(fd1); goto out; } mf = read_manifest(f1); gzclose(f1); if (!mf) { cc_log("Failed to read manifest file; deleting it"); x_unlink(manifest_path); mf = create_empty_manifest(); } } if (mf->n_objects > MAX_MANIFEST_ENTRIES) { /* * Normally, there shouldn't be many object entries in the manifest since * new entries are added only if an include file has changed but not the * source file, and you typically change source files more often than * header files. However, it's certainly possible to imagine cases where * the manifest will grow large (for instance, a generated header file that * changes for every build), and this must be taken care of since * processing an ever growing manifest eventually will take too much time. * A good way of solving this would be to maintain the object entries in * LRU order and discarding the old ones. An easy way is to throw away all * entries when there are too many. Let's do that for now. */ cc_log("More than %u entries in manifest file; discarding", MAX_MANIFEST_ENTRIES); free_manifest(mf); mf = create_empty_manifest(); } tmp_file = format("%s.tmp.%s", manifest_path, tmp_string()); fd2 = safe_create_wronly(tmp_file); if (fd2 == -1) { cc_log("Failed to open %s", tmp_file); goto out; } f2 = gzdopen(fd2, "wb"); if (!f2) { cc_log("Failed to gzdopen %s", tmp_file); goto out; } add_object_entry(mf, object_hash, included_files); if (write_manifest(f2, mf)) { gzclose(f2); f2 = NULL; if (x_rename(tmp_file, manifest_path) == 0) { ret = 1; } else { cc_log("Failed to rename %s to %s", tmp_file, manifest_path); goto out; } } else { cc_log("Failed to write manifest file"); goto out; } out: if (mf) { free_manifest(mf); } if (tmp_file) { free(tmp_file); } if (f2) { gzclose(f2); } return ret; }