4041e047ce5ad23c38b09d00a4f4a453779b820b tdreszer Thu May 5 13:53:49 2011 -0700 Noticed possible bug in raFoldInOneRetName and made simple case of raNextTagVal more efficient. diff --git src/lib/ra.c src/lib/ra.c index 10e27de..7c3ce3d 100644 --- src/lib/ra.c +++ src/lib/ra.c @@ -42,33 +42,43 @@ } lineFileReuse(lf); return TRUE; } boolean raNextTagVal(struct lineFile *lf, char **retTag, char **retVal, struct dyString *dyRecord) // Read next line. Return FALSE at end of file or blank line. Otherwise fill in // *retTag and *retVal and return TRUE. If dy parameter is non-null, then the text parsed // gets appended to dy. Continuation lines in RA file will be joined to produce tag and val, // but dy will be filled with the unedited multiple lines containing the continuation chars. // NOTE: retTag & retVal, if returned, point to static mem which will be overwritten on next call! { *retTag = NULL; *retVal = NULL; -char *line, *raw; +char *line, *raw = NULL; int lineLen,rawLen; -while (lineFileNextFull(lf, &line, &lineLen, &raw, &rawLen)) // Joins continuation lines + +// Don't bother with raw if it isn't used. +char **pRaw = NULL; +int *pRawLen = NULL; +if (dyRecord != NULL) + { + pRaw = &raw; + pRawLen = &rawLen; + } + +while (lineFileNextFull(lf, &line, &lineLen, pRaw, pRawLen)) // Joins continuation lines { char *clippedText = skipLeadingSpaces(line); if (*clippedText == 0) { if (dyRecord) lineFileReuse(lf); // Just so don't loose leading space in dy. return FALSE; } // Append whatever line was read from file. if (dyRecord) { if (raw != NULL) dyStringAppendN(dyRecord, raw, rawLen); else @@ -187,58 +197,58 @@ return hash; } char *raFoldInOneRetName(struct lineFile *lf, struct hash *hashOfHash) /* Fold in one record from ra file into hashOfHash. * This will add ra's and ra fields to whatever already * exists in the hashOfHash, overriding fields of the * same name if they exist already. */ { char *word, *line, *name; struct hash *ra; struct hashEl *hel; /* Get first nonempty non-comment line and make sure * it contains name. */ -if (!lineFileNextReal(lf, &line)) +if (!lineFileNextFullReal(lf, &line)) return NULL; word = nextWord(&line); if (!sameString(word, "name")) errAbort("Expecting 'name' line %d of %s, got %s", lf->lineIx, lf->fileName, word); name = nextWord(&line); if (name == NULL) errAbort("Short name field line %d of %s", lf->lineIx, lf->fileName); /* Find ra hash associated with name, making up a new * one if need be. */ if ((ra = hashFindVal(hashOfHash, name)) == NULL) { ra = newHash(7); hashAdd(hashOfHash, name, ra); hashAdd(ra, "name", lmCloneString(ra->lm, name)); } /* Fill in fields of ra hash with data up to next * blank line or end of file. */ for (;;) { - if (!lineFileNextFull(lf, &line, NULL,NULL,NULL)) + if (!lineFileNextFull(lf, &line, NULL,NULL,NULL)) // Not using FullReal to detect end of stanza break; line = skipLeadingSpaces(line); if (line[0] == 0) - break; + break; // End of stanza detected if (line[0] == '#') continue; word = nextWord(&line); line = skipLeadingSpaces(line); if (line == NULL) line = ""; hel = hashLookup(ra, word); if (hel == NULL) hel = hashAdd(ra, word, lmCloneString(ra->lm, line)); else hel->val = lmCloneString(ra->lm, line); } return hashFindVal(ra, "name"); }