// Returns false on EOI or error bool pop () { m_cur_char = readOne (); if (!eoi() && !error()) m_cur_loc.feed (m_cur_char); return !error() && !eoi(); }
std::vector<DatasetElem> DatasetReader::readAll() { std::vector<DatasetElem> dataset; DatasetElem elem; while (readOne(elem)) { dataset.push_back(elem); } return dataset; }
void oocMaskCounts(char *oocFile, bits32 *tileCounts, int tileSize, bits32 maxPat) /* Set items of tileCounts to maxPat if they are in oocFile. * Effectively masks this out of index.*/ { if (oocFile != NULL) { bits32 sig, psz; FILE *f = mustOpen(oocFile, "rb"); boolean mustSwap = FALSE; mustReadOne(f, sig); mustReadOne(f, psz); if (sig == oocSig) mustSwap = FALSE; else if (sig == oocSigSwapped) { mustSwap = TRUE; psz = byteSwap32(psz); } else errAbort("Bad signature on %s\n", oocFile); if (psz != tileSize) errAbort("Oligo size mismatch in %s. Expecting %d got %d\n", oocFile, tileSize, psz); if (mustSwap) { union {bits32 whole; UBYTE bytes[4];} u,v; while (readOne(f, u)) { v.bytes[0] = u.bytes[3]; v.bytes[1] = u.bytes[2]; v.bytes[2] = u.bytes[1]; v.bytes[3] = u.bytes[0]; tileCounts[v.whole] = maxPat; } } else { bits32 oli; while (readOne(f, oli)) tileCounts[oli] = maxPat; } fclose(f); } }
void DataReader::read(pn_data_t* data) { /* while (pn_data_next(data)) { readOne(data); } */ do { readOne(data); } while (pn_data_next(data)); }
int HexBinaryDecoderBuf::readFromDevice() { int c; int n; if ((n = readOne()) == -1) return -1; if (n >= '0' && n <= '9') c = n - '0'; else if (n >= 'A' && n <= 'F') c = n - 'A' + 10; else if (n >= 'a' && n <= 'f') c = n - 'a' + 10; else throw DataFormatException(); c <<= 4; if ((n = readOne()) == -1) throw DataFormatException(); if (n >= '0' && n <= '9') c |= n - '0'; else if (n >= 'A' && n <= 'F') c |= n - 'A' + 10; else if (n >= 'a' && n <= 'f') c |= n - 'a' + 10; else throw DataFormatException(); return c; }
I pString_Connection::syncDoRead(A *pdataobj) { I result; MSBuffer *hb=headBuffer(); MSBuffer *db=readBuffer(); ipcWarn(wrnlvl(),"%t pString_Connection::syncDoRead\n"); *pdataobj=readOne(); if(*pdataobj==(A)0) { if(isInReset()) result=syncFillError("reset","Reset occurred. No message read."); else result=0; } else result=1; return result; }
struct cdaAli *wormCdaAlisInRange(char *chromId, int start, int end) /* Return list of cdna alignments that overlap range. */ { struct cdaAli *list = NULL, *el; char fileName[512]; FILE *ixFile, *aliFile; bits32 sig; int s, e; long fpos; aliFile = wormOpenGoodAli(); sprintf(fileName, "%s%s.alx", cdnaDir, chromId); ixFile = mustOpen(fileName, "rb"); mustReadOne(ixFile, sig); if (sig != alxSig) errAbort("Bad signature on %s", fileName); for (;;) { if (!readOne(ixFile, s)) break; mustReadOne(ixFile, e); mustReadOne(ixFile, fpos); if (e <= start) continue; if (s >= end) break; AllocVar(el); fseek(aliFile, fpos, SEEK_SET); el = cdaLoadOne(aliFile); if (el == NULL) errAbort("Truncated cdnaAli file"); slAddHead(&list, el); } slReverse(&list); fclose(aliFile); fclose(ixFile); return list; }
struct xaAli *xaRdRange(FILE *ix, FILE *data, int start, int end, boolean condensed) /* Return list of all xaAlis that range from start to end. * Assumes that ix and data files are open. If condensed * don't fill int query, target, qSym, tSym, or hSym. */ { int s, e; int maxS, minE; long offset; struct xaAli *list = NULL, *xa; /* Scan through index file looking for things in range. * When find one read it from data file and add it to list. */ fseek(ix, sizeof(bits32), SEEK_SET); for (;;) { if (!readOne(ix, s)) break; mustReadOne(ix, e); mustReadOne(ix, offset); if (s >= end) break; maxS = max(s, start); minE = min(e, end); if (minE - maxS > 0) { fseek(data, offset, SEEK_SET); xa = xaReadNext(data, condensed); slAddHead(&list, xa); } } slReverse(&list); return list; }
struct patSpace *makePatSpace(struct dnaSeq **seqArray, int arraySize, char *oocFileName) /* Allocate a pattern space and fill from sequences. (Each element of seqArray is a list of sequences. */ { struct patSpace *ps = newPatSpace(); int i; int startIx = 0; int total = 0; long startTime, endTime; struct dnaSeq *seq; int globalOver = 0, localOver = 0; bits16 maxPat; bits16 *listSizes; startTime = clock1000(); maxPat = ps->maxPat = maxPatCount; for (i=0; i<arraySize; ++i) { for (seq = seqArray[i]; seq != NULL; seq = seq->next) { total += seq->size; countPatSpace(seq, ps); } } endTime = clock1000(); printf("%4.2f seconds to countPatSpace %d bases\n", 0.001*(endTime-startTime), total ); listSizes = ps->listSizes; /* Scan through over-popular patterns and set their count to value * where they won't be added to pat space. */ { bits32 sig, psz; FILE *f = mustOpen(oocFileName, "rb"); bits32 oli; mustReadOne(f, sig); mustReadOne(f, psz); if (sig != oocSig) errAbort("Bad signature on %s\n", oocFileName); if (psz != patSize) errAbort("Oligo size mismatch in %s. Expecting %d got %d\n", oocFileName, patSize, psz); while (readOne(f, oli)) listSizes[oli] = maxPat; fclose(f); } startTime = clock1000(); allocPatSpaceLists(ps); endTime = clock1000(); printf("%4.2f seconds to allocPatSpaceLists\n", 0.001*(endTime-startTime) ); startTime = clock1000(); /* Zero out pattern counts that aren't oversubscribed. */ for (i=0; i<patSpaceSize; ++i) { if (listSizes[i] < maxPat) listSizes[i] = 0; } if (dumpMe) fprintf(dumpOut, "BlockIx vs. Seq position table:\n"); for (i=0; i<arraySize; ++i) { int j; for (seq = seqArray[i], j=0; seq != NULL; seq = seq->next, ++j) { startIx = addToPatSpace(i, j, seq, startIx, ps); if (startIx >= maxBlockCount) errAbort("Too many blocks, can only handle %d\n", maxBlockCount); } } ps->blocksUsed = startIx; if (dumpMe) fprintf(dumpOut, "\n"); printf("%d blocks of %d used\n", ps->blocksUsed, maxBlockCount); /* Zero local over-popular patterns. */ for (i=0; i<patSpaceSize; ++i) { if (listSizes[i] >= maxPat) listSizes[i] = 0; } endTime = clock1000(); printf("%4.2f seconds to addToPatSpace\n", 0.001*(endTime-startTime) ); return ps; }
static GraphType init(int argc, char *argv[], opts_t* opts) { int c; GraphType graphType = unknown; cmd = argv[0]; opterr = 0; while ((c = getopt(argc, argv, optList)) != -1) { switch (c) { case 'c': graphType = circle; if (setOne(optarg, opts)) errexit(c); break; case 'C': graphType = cylinder; if (setTwo(optarg, opts)) errexit(c); break; case 'M': graphType = mobius; if (setTwo(optarg, opts)) errexit(c); break; case 'd': opts->directed = 1; break; case 'G': opts->isPartial = 1; case 'g': graphType = grid; optarg = setFold (optarg, opts); if (setTwo(optarg, opts)) errexit(c); break; case 'h': graphType = hypercube; if (setOne(optarg, opts)) errexit(c); break; case 'k': graphType = complete; if (setOne(optarg, opts)) errexit(c); break; case 'b': graphType = completeb; if (setTwo(optarg, opts)) errexit(c); break; case 'B': graphType = ball; if (setTwo(optarg, opts)) errexit(c); break; case 'm': graphType = trimesh; if (setOne(optarg, opts)) errexit(c); break; case 'r': graphType = randomg; if (setTwo(optarg, opts)) errexit(c); break; case 'R': graphType = randomt; if (setOne(optarg, opts)) errexit(c); break; case 'n': opts->pfx = optarg; break; case 'N': opts->name = optarg; break; case 'o': opts->outfile = openFile(optarg, "w"); break; case 'p': graphType = path; if (setOne(optarg, opts)) errexit(c); break; case 'S': graphType = sierpinski; if (setOne(optarg, opts)) errexit(c); break; case 's': graphType = star; if (setOne(optarg, opts)) errexit(c); break; case 't': graphType = tree; if (setTwoOpt(optarg, opts, 2)) errexit(c); break; case 'T': graphType = torus; if (setTwoTwoOpt(optarg, opts, 0)) errexit(c); break; case 'i': if (readOne(optarg,&(opts->cnt))) errexit(c); break; case 'v': opts->Verbose = 1; break; case 'w': graphType = wheel; if (setOne(optarg, opts)) errexit(c); break; case '?': if (optopt == '?') usage(0); else fprintf(stderr, "Unrecognized flag \"-%c\" - ignored\n", optopt); break; } } argc -= optind; argv += optind; if (!opts->outfile) opts->outfile = stdout; if (graphType == unknown) { fprintf(stderr, "Graph type not set\n"); usage(1); } return graphType; }