static void getLenOfPspSeqs(FILE *fptr, Psprior *psp) { char c; char prevC = 0; int seqInd = -1; boolean inHeader = FALSE; boolean inSeq = FALSE; while ((c = fgetc(fptr)) != EOF) { if( c == '>' ) { inHeader = TRUE; inSeq = FALSE; if(prevC != '>') { seqInd++; //do not increment if >> in header } if(seqInd >= psp->numseqs) { print_error("ERROR in getLenOfSeqs: number of seqs exceed max."); } psp->seqlen[seqInd] = 0; } else if ( inHeader && c == '\n') { inHeader = FALSE; inSeq = TRUE; } else if (inSeq) { if(isFloatingPoint(prevC) && isSpaceChar(c)) { psp->seqlen[seqInd]++; //fprintf(stderr, "case1\n"); } else if(isSpaceChar(prevC) && isSpaceChar(c)) { //do nothing //fprintf(stderr, "case2\n"); } else if(isSpaceChar(prevC) && isFloatingPoint(c)) { //do nothing //fprintf(stderr, "case3\n"); } else if(isFloatingPoint(prevC) && isFloatingPoint(c)) { //do nothing //fprintf(stderr, "case4\n"); } else { fprintf(stderr, "character: %d %d\n", (int)prevC, (int)c); fprintf(stderr, "seqind: %d\n", seqInd); fprintf(stderr, "Invalid format found: %c%c\n", prevC, c); exit(1); } } prevC = c; } }
static integer cmdCount(char *cmdLine, integer deflt) { while (isSpaceChar((codePoint) *cmdLine)) cmdLine++; if (uniStrLen(cmdLine) == 0) return deflt; else return parseInteger(cmdLine, uniStrLen(cmdLine)); }
static DebugWaitFor dbgShowGlobal(char *line, processPo p, termPo loc, insWord ins, void *cl) { char buff[MAX_SYMB_LEN]; integer pos = 0; integer ix = 0; integer llen = uniStrLen(line); enum { initSte, inVar } st = initSte; while (ix < llen) { codePoint cp = nextCodePoint(line, &ix, llen); switch (st) { case initSte: if (!isSpaceChar(cp)) { st = inVar; appendCodePoint(buff, &pos, NumberOf(buff), cp); } continue; case inVar: if (!isSpaceChar(cp)) { appendCodePoint(buff, &pos, NumberOf(buff), cp); continue; } else break; } } if (uniStrLen(buff) > 0) { appendCodePoint(buff, &pos, NumberOf(buff), 0); globalPo glb = globalVar(buff); if (glb != Null) { termPo val = getGlobal(glb); if (val != Null) outMsg(debugOutChnnl, "%s = %,*T\n", buff, displayDepth, val); else outMsg(debugOutChnnl, "%s not set\n", buff); } } resetDeflt("n"); return moreDebug; }
//returns the length of the sequence //This function can easily leads to buffer overflow, but I don't care about security now. static int readSinglePspSeq(FILE *fptr, Psprior *psp, int seqInd) { //int siteInd = 0; double flt = NAN; int c; for(int i = 0; i < psp->seqlen[seqInd]; i++) { fscanf (fptr, "%lf", &flt); psp->prior[seqInd][i] = flt; } while((c = fgetc(fptr)) != '>' && c!= EOF) { if( isSpaceChar(c)) { continue; } else { fprintf(stderr, "ERROR: invalid character found at end of sequence %c", c); } } ungetc(c, fptr); return psp->seqlen[seqInd]; }