From 622ee76980a6cfc1a3bff6e1f41351380b70ed8a Mon Sep 17 00:00:00 2001 From: Alex Baines Date: Sun, 30 Apr 2017 02:52:39 +0100 Subject: [PATCH] fix some bugs --- hmmlconv/hmmlconv.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hmmlconv/hmmlconv.c b/hmmlconv/hmmlconv.c index 02d694f..49e366c 100644 --- a/hmmlconv/hmmlconv.c +++ b/hmmlconv/hmmlconv.c @@ -143,7 +143,7 @@ Resource *LookupResource(char *Tag, char *Line) return Res; } -void ProcessAnnotation(Resource* Resources, size_t ResCount, char *Line, FILE *OutFile) +void ProcessAnnotation(char *Line, FILE *OutFile) { SkipWhitespace(&Line); assert(*Line == '"'); @@ -188,10 +188,11 @@ void ProcessAnnotation(Resource* Resources, size_t ResCount, char *Line, FILE *O for(LinePtr = Line; *LinePtr; ++LinePtr) { - int ScanBytes; + int ScanBytes = 0; + int TmpQuoteID; // convert Resource -> ref - if(LinePtr[0] == ' ' && LinePtr[1] == '[' && sscanf(LinePtr+1, "[see Resources, %255[^]]]%n", RefBuf, &ScanBytes) == 1) + if(LinePtr[0] == ' ' && LinePtr[1] == '[' && sscanf(LinePtr+1, "[see Resources, %255[^]]]%n", RefBuf, &ScanBytes) == 1 && ScanBytes) { //printf("Find Resource [%s]\n", RefBuf); Resource *Res = LookupResource(RefBuf, Line); @@ -215,14 +216,14 @@ void ProcessAnnotation(Resource* Resources, size_t ResCount, char *Line, FILE *O } // convert quotes - else if(LinePtr[0] == ' ' && LinePtr[1] == '(' && sscanf(LinePtr+1, "(!quote %d)%n", &QuoteID, &ScanBytes) == 1) + else if(LinePtr[0] == ' ' && LinePtr[1] == '(' && sscanf(LinePtr+1, "(!quote %d)%n", &TmpQuoteID, &ScanBytes) == 1 && ScanBytes) { + QuoteID = TmpQuoteID; fprintf(OutFile, "%.*s", (int)(LinePtr - RunStart), RunStart); LinePtr += ScanBytes; RunStart = LinePtr+1; } - // Used for getting name for Q:'s else if(*LinePtr == ' ') { @@ -388,7 +389,7 @@ int ProcessFile(char *InFileName, FILE *InFile, FILE *OutFile) if(strncmp(LinePtr, "---", 3) == 0){ goto Done; } else { - ProcessAnnotation(Resources, ResCount, LinePtr, OutFile); + ProcessAnnotation(LinePtr, OutFile); } } break; } @@ -467,7 +468,7 @@ OpenOutput:; OutFile = fdopen(OutFileDesc, "w"); if(!OutFile) { - fprintf(stderr, "Error opening %s: %s\n", Args[i], strerror(errno)); + fprintf(stderr, "Error opening %s: %s\n", OutNameBuf, strerror(errno)); } } }