fix: error

This commit is contained in:
kuoi 2023-04-16 13:50:30 +08:00
parent 650d39cff9
commit 83f11ebd67
2 changed files with 33 additions and 31 deletions

View file

@ -168,6 +168,7 @@ link -w -o readseq -t MPST -c 'MPS ' <20>
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include "ureadseq.h" #include "ureadseq.h"

View file

@ -18,6 +18,7 @@
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#define UREADSEQ_G #define UREADSEQ_G
@ -123,7 +124,7 @@ Local void readline(FILE *f, char *s, long *linestart)
} }
} }
Local void getline(struct ReadSeqVars *V) Local void cgetline(struct ReadSeqVars *V)
{ {
readline(V->f, V->s, &V->linestart); readline(V->f, V->s, &V->linestart);
} }
@ -200,7 +201,7 @@ Local void readLoop(short margin, boolean addfirst,
if (addfirst) addseq(V->s, V); if (addfirst) addseq(V->s, V);
do { do {
getline(V); cgetline(V);
V->done = feof(V->f); V->done = feof(V->f);
V->done |= (*endTest)(&addend, &ungetend, V); V->done |= (*endTest)(&addend, &ungetend, V);
if (V->addit && (addend || !V->done) && if (V->addit && (addend || !V->done) &&
@ -231,7 +232,7 @@ Local void readIG(struct ReadSeqVars *V)
while (!V->allDone) { while (!V->allDone) {
do { do {
getline(V); cgetline(V);
for (si = V->s; *si != 0 && *si < ' '; si++) for (si = V->s; *si != 0 && *si < ' '; si++)
*si = ' '; /* drop controls */ *si = ' '; /* drop controls */
if (*si == 0) *V->s = 0; /* chop line to empty */ if (*si == 0) *V->s = 0; /* chop line to empty */
@ -257,13 +258,13 @@ Local void readStrider(struct ReadSeqVars *V)
{ /* ? only 1 seq/file ? */ { /* ? only 1 seq/file ? */
while (!V->allDone) { while (!V->allDone) {
getline(V); cgetline(V);
if (strstr(V->s, "; DNA sequence ") == V->s) if (strstr(V->s, "; DNA sequence ") == V->s)
strcpy(V->seqid, (V->s) + 16); strcpy(V->seqid, (V->s) + 16);
else else
strcpy(V->seqid, (V->s) + 1); strcpy(V->seqid, (V->s) + 1);
while ((!feof(V->f)) && (*V->s == ';')) { while ((!feof(V->f)) && (*V->s == ';')) {
getline(V); cgetline(V);
} }
if (feof(V->f)) if (feof(V->f))
V->allDone = true; V->allDone = true;
@ -285,17 +286,17 @@ Local void readPIR(struct ReadSeqVars *V)
while (!V->allDone) { while (!V->allDone) {
while (!(feof(V->f) || strstr(V->s, "ENTRY") || while (!(feof(V->f) || strstr(V->s, "ENTRY") ||
strstr(V->s, "SEQUENCE"))) strstr(V->s, "SEQUENCE")))
getline(V); cgetline(V);
strcpy(V->seqid, (V->s) + 16); strcpy(V->seqid, (V->s) + 16);
while (!(feof(V->f) || strstr(V->s, "SEQUENCE") == V->s)) while (!(feof(V->f) || strstr(V->s, "SEQUENCE") == V->s))
getline(V); cgetline(V);
readLoop(0, false, endPIR, V); readLoop(0, false, endPIR, V);
if (!V->allDone) { if (!V->allDone) {
while (!( while (!(
feof(V->f) || feof(V->f) ||
((*V->s != 0) && (strstr(V->s, "ENTRY") == V->s)))) ((*V->s != 0) && (strstr(V->s, "ENTRY") == V->s))))
getline(V); cgetline(V);
} }
if (feof(V->f)) V->allDone = true; if (feof(V->f)) V->allDone = true;
} }
@ -314,14 +315,14 @@ Local void readGenBank(struct ReadSeqVars *V)
while (!V->allDone) { while (!V->allDone) {
strcpy(V->seqid, (V->s) + 12); strcpy(V->seqid, (V->s) + 12);
while (!(feof(V->f) || strstr(V->s, "ORIGIN") == V->s)) while (!(feof(V->f) || strstr(V->s, "ORIGIN") == V->s))
getline(V); cgetline(V);
readLoop(0, false, endGB, V); readLoop(0, false, endGB, V);
if (!V->allDone) { if (!V->allDone) {
while (!( while (!(
feof(V->f) || feof(V->f) ||
((*V->s != 0) && (strstr(V->s, "LOCUS") == V->s)))) ((*V->s != 0) && (strstr(V->s, "LOCUS") == V->s))))
getline(V); cgetline(V);
} }
if (feof(V->f)) V->allDone = true; if (feof(V->f)) V->allDone = true;
} }
@ -351,11 +352,11 @@ Local void readNBRF(struct ReadSeqVars *V)
{ {
while (!V->allDone) { while (!V->allDone) {
strcpy(V->seqid, (V->s) + 4); strcpy(V->seqid, (V->s) + 4);
getline(V); /*skip title-junk line*/ cgetline(V); /*skip title-junk line*/
readLoop(0, false, endNBRF, V); readLoop(0, false, endNBRF, V);
if (!V->allDone) { if (!V->allDone) {
while (!(feof(V->f) || (*V->s != 0 && *V->s == '>'))) while (!(feof(V->f) || (*V->s != 0 && *V->s == '>')))
getline(V); cgetline(V);
} }
if (feof(V->f)) V->allDone = true; if (feof(V->f)) V->allDone = true;
} }
@ -377,7 +378,7 @@ Local void readPearson(struct ReadSeqVars *V)
if (!V->allDone) { if (!V->allDone) {
while ( while (
!(feof(V->f) || ((*V->s != 0) && (*V->s == '>')))) !(feof(V->f) || ((*V->s != 0) && (*V->s == '>'))))
getline(V); cgetline(V);
} }
if (feof(V->f)) V->allDone = true; if (feof(V->f)) V->allDone = true;
} }
@ -395,7 +396,7 @@ Local void readEMBL(struct ReadSeqVars *V)
while (!V->allDone) { while (!V->allDone) {
strcpy(V->seqid, (V->s) + 5); strcpy(V->seqid, (V->s) + 5);
do { do {
getline(V); cgetline(V);
} while (!(feof(V->f) | (strstr(V->s, "SQ ") == V->s))); } while (!(feof(V->f) | (strstr(V->s, "SQ ") == V->s)));
readLoop(0, false, endEMBL, V); readLoop(0, false, endEMBL, V);
@ -403,7 +404,7 @@ Local void readEMBL(struct ReadSeqVars *V)
while ( while (
!(feof(V->f) | ((*V->s != '\0') & !(feof(V->f) | ((*V->s != '\0') &
(strstr(V->s, "ID ") == V->s)))) (strstr(V->s, "ID ") == V->s))))
getline(V); cgetline(V);
} }
if (feof(V->f)) V->allDone = true; if (feof(V->f)) V->allDone = true;
} }
@ -422,13 +423,13 @@ Local void readZuker(struct ReadSeqVars *V)
/*! 1st string is Zuker's Fortran format */ /*! 1st string is Zuker's Fortran format */
while (!V->allDone) { while (!V->allDone) {
getline(V); /*s == "seqLen seqid string..."*/ cgetline(V); /*s == "seqLen seqid string..."*/
strcpy(V->seqid, (V->s) + 6); strcpy(V->seqid, (V->s) + 6);
readLoop(0, false, endZuker, V); readLoop(0, false, endZuker, V);
if (!V->allDone) { if (!V->allDone) {
while ( while (
!(feof(V->f) | ((*V->s != '\0') & (*V->s == '(')))) !(feof(V->f) | ((*V->s != '\0') & (*V->s == '('))))
getline(V); cgetline(V);
} }
if (feof(V->f)) V->allDone = true; if (feof(V->f)) V->allDone = true;
} }
@ -471,7 +472,7 @@ Local void readPlain(struct ReadSeqVars *V)
do { do {
addseq(V->s, V); addseq(V->s, V);
V->done = feof(V->f); V->done = feof(V->f);
getline(V); cgetline(V);
} while (!V->done); } while (!V->done);
if (V->choice == kListSequences) addinfo(V->seqid, V); if (V->choice == kListSequences) addinfo(V->seqid, V);
V->allDone = true; V->allDone = true;
@ -482,7 +483,7 @@ Local void readUWGCG(struct ReadSeqVars *V)
/* /*
10nov91: Reading GCG files casued duplication of last line when 10nov91: Reading GCG files casued duplication of last line when
EOF followed that line !!! EOF followed that line !!!
fix: getline now sets *V->s = 0 fix: cgetline now sets *V->s = 0
*/ */
char *si; char *si;
@ -498,7 +499,7 @@ Local void readUWGCG(struct ReadSeqVars *V)
*si = 0; *si = 0;
do { do {
V->done = feof(V->f); V->done = feof(V->f);
getline(V); cgetline(V);
if (!V->done) addseq((V->s), V); if (!V->done) addseq((V->s), V);
} while (!V->done); } while (!V->done);
if (V->choice == kListSequences) addinfo(V->seqid, V); if (V->choice == kListSequences) addinfo(V->seqid, V);
@ -517,7 +518,7 @@ Local void readOlsen(struct ReadSeqVars *V)
rewind(V->f); rewind(V->f);
V->nseq = 0; V->nseq = 0;
do { do {
getline(V); cgetline(V);
V->done = feof(V->f); V->done = feof(V->f);
if (V->done && !(*V->s)) if (V->done && !(*V->s))
@ -618,7 +619,7 @@ Local void readMSF(struct ReadSeqVars *V)
rewind(V->f); rewind(V->f);
V->nseq = 0; V->nseq = 0;
do { do {
getline(V); cgetline(V);
V->done = feof(V->f); V->done = feof(V->f);
if (V->done && !(*V->s)) if (V->done && !(*V->s))
@ -698,7 +699,7 @@ Local void readPAUPinterleaved(struct ReadSeqVars *V)
domatch = (V->matchchar > 0); domatch = (V->matchchar > 0);
do { do {
getline(V); cgetline(V);
V->done = feof(V->f); V->done = feof(V->f);
if (V->done && !(*V->s)) if (V->done && !(*V->s))
@ -798,7 +799,7 @@ Local void readPAUPsequential(struct ReadSeqVars *V)
/* rewind(V->f); V->nseq= 0; << do in caller !*/ /* rewind(V->f); V->nseq= 0; << do in caller !*/
indata = true; /* call here after we find "matrix" */ indata = true; /* call here after we find "matrix" */
do { do {
getline(V); cgetline(V);
V->done = feof(V->f); V->done = feof(V->f);
if (V->done && !(*V->s)) if (V->done && !(*V->s))
@ -901,7 +902,7 @@ Local void readPhylipInterleaved(struct ReadSeqVars *V)
* V->topseqlen); */ * V->topseqlen); */
do { do {
getline(V); cgetline(V);
V->done = feof(V->f); V->done = feof(V->f);
if (V->done && !(*V->s)) break; if (V->done && !(*V->s)) break;
@ -953,7 +954,7 @@ Local void readPhylipSequential(struct ReadSeqVars *V)
while (isdigit(*si)) si++; while (isdigit(*si)) si++;
skipwhitespace(si); skipwhitespace(si);
V->topseqlen = atol(si); V->topseqlen = atol(si);
getline(V); cgetline(V);
while (!V->allDone) { while (!V->allDone) {
V->seqlencount = 0; V->seqlencount = 0;
strncpy(V->seqid, (V->s), 10); strncpy(V->seqid, (V->s), 10);
@ -982,10 +983,10 @@ Local void readSeqMain(struct ReadSeqVars *V, const long skiplines_,
if (V->f == NULL) if (V->f == NULL)
V->err = eFileNotFound; V->err = eFileNotFound;
else { else {
for (l = skiplines_; l > 0; l--) getline(V); for (l = skiplines_; l > 0; l--) cgetline(V);
do { do {
getline(V); cgetline(V);
for (l = strlen(V->s); (l > 0) && (V->s[l] == ' '); l--) for (l = strlen(V->s); (l > 0) && (V->s[l] == ' '); l--)
; ;
} while ((l == 0) && !feof(V->f)); } while ((l == 0) && !feof(V->f));
@ -1036,7 +1037,7 @@ Local void readSeqMain(struct ReadSeqVars *V, const long skiplines_,
/* rewind(V->f); V->nseq= 0; ?? assume /* rewind(V->f); V->nseq= 0; ?? assume
* it is at top ?? skiplines ... */ * it is at top ?? skiplines ... */
while (!done) { while (!done) {
getline(V); cgetline(V);
tolowerstr(V->s); tolowerstr(V->s);
if (strstr(V->s, "matrix")) if (strstr(V->s, "matrix"))
done = true; done = true;
@ -1086,7 +1087,7 @@ Local void readSeqMain(struct ReadSeqVars *V, const long skiplines_,
case kFitch: case kFitch:
strcpy(V->seqid, V->s); strcpy(V->seqid, V->s);
getline(V); cgetline(V);
readFitch(V); readFitch(V);
break; break;
@ -1095,7 +1096,7 @@ Local void readSeqMain(struct ReadSeqVars *V, const long skiplines_,
gotuw = (strstr(V->s, "..") != gotuw = (strstr(V->s, "..") !=
NULL); NULL);
if (gotuw) readUWGCG(V); if (gotuw) readUWGCG(V);
getline(V); cgetline(V);
} while (!(feof(V->f) || V->allDone)); } while (!(feof(V->f) || V->allDone));
break; break;
} }