65b46010dfbb303e0323379096e7d7336d23502e
braney
  Tue May 20 11:27:52 2014 -0700
fixed a couple of bugs in splitFileByColumn #13297
diff --git src/utils/splitFileByColumn/splitFileByColumn.c src/utils/splitFileByColumn/splitFileByColumn.c
index 459e2fe..cc12bb7 100644
--- src/utils/splitFileByColumn/splitFileByColumn.c
+++ src/utils/splitFileByColumn/splitFileByColumn.c
@@ -110,31 +110,31 @@
 	fprintf(f, "%s", headerText);
     hashAdd(chromFpHash, baseName, f);
     freez(&outFileName);
     fileCount++;
     }
 else if (hel->val == NULL)
     {
     /* File has been opened before but is closed -- close prevFile, append. */
     char *outFileName = getFileName(baseName);
     if (prevBaseName != NULL)
 	{
 	prevHel = hashLookup(chromFpHash, prevBaseName);
 	if (prevHel != NULL)
 	    carefulClose((FILE **)&(prevHel->val));
 	}
-    f = mustOpen(outFileName, "a");
+    hel->val = f = mustOpen(outFileName, "a");
     freez(&outFileName);
     }
 else if (!sameString(baseName, prevBaseName))
     {
     errAbort("program error: a cached file pointer is open but baseName (%s)"
 	     " != prevBaseName (%s)", baseName, prevBaseName);
     }
 else
     {
     /* Write to open file pointer. */
     f = hel->val;
     }
 
 if (prevBaseName == NULL || !sameString(baseName, prevBaseName))
     {
@@ -145,32 +145,32 @@
 return f;
 }
 
 
 void addTailAndClose(struct hashEl *hel)
 /* Given an element of chromFpHash, add tailerText if specified (which may
  * require reopening the file) and close the file pointer. */
 {
 if (tailerText != NULL)
     {
     FILE *f = (FILE *)(hel->val);
     if (f == NULL)
 	{
 	char *outFileName = getFileName(hel->name);
 	hel->val = f = mustOpen(outFileName, "a");
-	fprintf(f, "%s", tailerText);
 	}
+    fprintf(f, "%s", tailerText);
     }
 carefulClose((FILE **)&(hel->val));
 }
 
 void closeFiles(struct hash *chromFpHash)
 /* Apply addTailAndClose to all items in chromFpHash. */
 {
 hashTraverseEls(chromFpHash, addTailAndClose);
 }
 
 
 void splitFileByColumn(char *inFileName)
 /* splitFileByColumn - Split text input into files named by column value. */
 {
 struct lineFile *lf = lineFileOpen(inFileName, TRUE);