946ec4deb61682f1608c3c8f08dfd1ed838fc6d6 kent Mon Jan 11 14:56:33 2021 -0800 Added a basic tab-sep output a line to library. diff --git src/lib/obscure.c src/lib/obscure.c index 609e321..5bb41cd 100644 --- src/lib/obscure.c +++ src/lib/obscure.c @@ -184,30 +184,43 @@ colAlloc = colCount + 1; // +1 so we can detect unexpected input and complain lmAllocArray(hash->lm, row, colAlloc); } int count = chopByChar(line, '\t', row, colAlloc); if (count != colCount) { errAbort("Expecting %d words, got more than that line %d of %s", colCount, lf->lineIx, lf->fileName); } hashAdd(hash, row[keyColIx], lmCloneRow(hash->lm, row, colCount) ); } lineFileClose(&lf); return hash; } +void writeTsvRow(FILE *f, int rowSize, char **row) +/* Write out row of strings to a line in tab-sep file */ +{ +if (rowSize > 0) + { + fprintf(f, "%s", row[0]); + int i; + for (i=1; i<rowSize; ++i) + fprintf(f, "\t%s", row[i]); + } +fprintf(f, "\n"); +} + struct slPair *slPairTwoColumnFile(char *fileName) /* Read in a two column file into an slPair list */ { char *row[2]; struct slPair *list = NULL; struct lineFile *lf = lineFileOpen(fileName, TRUE); while (lineFileRow(lf, row)) slPairAdd(&list, row[0], cloneString(row[1])); lineFileClose(&lf); slReverse(&list); return list; } struct slName *readAllLines(char *fileName) /* Read all lines of file into a list. (Removes trailing carriage return.) */