SAWYER_EXPORT std::string PodFormatter::toNroff(const ParserResult &parsed) { // Generate POD documentation into a temporary file TempFile tmpfile(tempFileName(".pod")); parsed.emit(tmpfile.stream, sharedFromThis()); tmpfile.stream.close(); std::string cmd = "pod2man" " --center='" + escapeSingleQuoted(chapterName_) + "'" " --date='" + escapeSingleQuoted(dateString_) + "'" " --name='" + escapeSingleQuoted(pageName_) + "'" " --release='" + escapeSingleQuoted(versionString_) + "'" " --section='" + escapeSingleQuoted(chapterNumber_) + "'" " " + tmpfile.name; FILE *f = popen(cmd.c_str(), "r"); if (!f) { #include <Sawyer/WarningsOff.h> // suppress strerror unsafe warning from Microsoft C++ throw std::runtime_error(std::string("cannot run command: ") + strerror(errno) + "\ncommand: " + cmd); #include <Sawyer/WarningsRestore.h> } std::string result; while (1) { std::string line = readOneLine(f); if (line.empty()) break; result += line; } if (-1 == Sawyer::pclose(f)) throw std::runtime_error("command failed: " + cmd); return result; }
/*! Attempts to read a line and returns an LByteArray containing the line. This wraps around readOneLine and provides a hack to do additional unwrapping for a malformed vCard where a space is not added to the start of the line continuation. Some malformed vCards we get look like this: (Case 1) ORG:A B C (CRLF-SPACE wrapping is employed for the first time, then the space is subsequently omitted). But a valid vCard can be weirdly wrapped without the CRLF-SPACE, if it's quoted-printable and ends in an equals, eg. (Case 2) ORG;ENCODING=QUOTED-PRINTABLE:A= B= C Unwrap in Case 1 but not in Case 2 - leave that for the QP-decoder in QVR::unencode */ LByteArray LineReader::readLine() { QByteArray colon(VersitUtils::encode(':', mCodec)); QByteArray equals(VersitUtils::encode('=', mCodec)); if (!mPushedLines.isEmpty()) { LByteArray retval(mPushedLines.pop()); return retval; } readOneLine(&mBuffer); // Hack: read the next line and see if it's a continuation of this line while (true) { int prevStart = mBuffer.mStart; int prevEnd = mBuffer.mEnd; // readOneLine only appends to mBuffer so these saved offsets should remain valid readOneLine(&mBuffer); // Get an LByteArray of the previous line. This should be fast because copying the // LByteArray copies the QByteArray, which is implicitly shared LByteArray prevLine(mBuffer.mData, prevStart, prevEnd); if (mBuffer.isEmpty() || mBuffer.contains(colon) || prevLine.endsWith(equals)) { // Normal, the next line is empty, or a new property, or it's been wrapped using // QUOTED-PRINTABLE. Rewind it back one line so it gets read next time round. mBuffer.setBounds(prevStart, prevEnd); break; } else { // Some silly vCard generator has probably wrapped a line without prepending a space // Join the previous line with this line by deleting the characters between prevEnd and // mStart (eg. any newline characters) int crlfLen = mBuffer.mStart-prevEnd; mBuffer.mData.remove(prevEnd, crlfLen); mBuffer.setBounds(prevStart, mBuffer.mEnd - crlfLen); } } mBuffer.dropOldData(); mOdometer += mBuffer.size(); return mBuffer; }
FASTQ readOneSequence(FILE *fin){ FASTQ sequence; char *dummy; do{ sequence.name=readOneLine(fin); }while(sequence.name[0]!='@' && sequence.name[0]!='\0'); sequence.dna=readOneLine(fin); dummy=readOneLine(fin); /*if(strcmp(dummy, "+\n")!=0 && !feof(stdin)){*/ if(dummy[0]!='+' && !feof(stdin)){ fprintf(stderr, "This file does not seem to be the fastq format. EXIT\n"); exit(3); } free(dummy); sequence.quality=readOneLine(fin); chomp(sequence.name); chomp(sequence.dna); chomp(sequence.quality); sequence.length=strlen(sequence.dna); sequence.dnaShow=NULL; sequence.qualityShow=NULL; return sequence; }
HashGraph* readGraphGDFFormat( FILE* f, //input file in GDF format string gname, //the input graph name Ortholog& orth, //ortholog name to ortholog id mapping OrthologInfoList& orthinfolist //return value, the orthology info ) { if(feof(f)) return NULL; orthinfolist.clear(); HashGraph* retG=new HashGraph(); AttributeValue attrval; attrval.type='s'; attrval.value=gname; //set graph attributes Attributes* gattrs=new Attributes; gattrs->insert(Attributes::value_type("name", attrval)); retG->setGraphAttrs(gattrs); debug(31, "set graph attribute\n"); string str; bool readnode=true; int orthIndex=-1; vector<string> attrnames; vector<char> attrtypes; vector<string> defvalues; hash_map<string, int, strhash, eqstr> nodemap; string attrname, defvalue; char attrtype; char buff[50]; while(readOneLine(f, str)) { debug(31, str<<endl); //now parse the string if(str.substr(4, 4)=="def>") { debug(31, "readnode = "<<readnode<<endl); if(str.substr(0, 8)=="nodedef>") readnode=true; else readnode=false; debug(31, "readnode = "<<readnode<<endl); attrnames.clear(); attrtypes.clear(); defvalues.clear(); int start=8; string seg; do{ start=getOneSegment(str, start, ',', seg); debug(31, "start="<<start<<endl); debug(31, "string::npos="<<string::npos<<endl); parseGDFAttribute(seg, attrname, attrtype, defvalue); if(attrname=="orthologies") orthIndex=attrnames.size(); attrnames.push_back(attrname); attrtypes.push_back(attrtype); defvalues.push_back(defvalue); }while(start!=string::npos); }else { debug(31, "read values"<<endl); debug(31, "orthIndex: "<<orthIndex<<endl); if(readnode) { assert(attrnames[0]=="name"); int start=0; string seg; int i=0; Attributes* nattrs=new Attributes; OrthologInfo orthinfo; do{ start=getOneSegment(str, start, ',', seg); if(i==0) nodemap[seg]=orthinfolist.size(); debug(31, "getOneSegment: "<<seg<<endl); if(i==orthIndex)//if the attribute name is orthologies { debug(31, "orthologies\n"); string orthlabel; int p=0; do{ p=getOneSegment(seg, p, ':', orthlabel); debug(31, "orth label: "<<orthlabel); uint32_t orthid=orth.getOrthologID(orthlabel); orthinfo.push_back(orthid); attrval.type='i'; sprintf(buff, "%u", orthid); attrval.value=string(buff); nattrs->insert(Attributes::value_type("orthology", attrval)); }while(p!=string::npos); }else { attrval.type=attrtypes[i]; if(seg.empty()) { attrval.value=defvalues[i]; nattrs->insert(Attributes::value_type(attrnames[i], attrval)); } else { vector<string> items; readItems(seg, ':', items); for(unsigned int ii=0; ii<items.size(); ii++) { attrval.value=items[ii]; nattrs->insert(Attributes::value_type(attrnames[i], attrval)); } } } i++; }while(start!=string::npos); if(orthIndex<0) { attrval.type='i'; attrval.value="0"; nattrs->insert(Attributes::value_type("orthology", attrval)); orthinfo.push_back(0); } retG->addNode(nattrs); orthinfolist.push_back(orthinfo); }else { assert(attrnames[0]=="node1" && attrnames[1]=="node2"); int start=0; string seg; int i=0; Attributes* eattrs=new Attributes; int n1, n2; do{ start=getOneSegment(str, start, ',', seg); if(i==0) { n1=nodemap[seg]; } else if(i==1) { n2=nodemap[seg]; }else { attrval.type=attrtypes[i]; if(seg.empty()) { attrval.value=defvalues[i]; eattrs->insert(Attributes::value_type(attrnames[i], attrval)); } else { vector<string> items; readItems(seg, ':', items); for(unsigned int ii=0; ii<items.size(); ii++) { attrval.value=items[ii]; eattrs->insert(Attributes::value_type(attrnames[i], attrval)); } } } i++; }while(start!=string::npos); retG->setEdge(n1, n2, eattrs); } } } return retG; }