src/hg/makeDb/trackDbPatch/trackDbPatch.c 1.6
1.6 2010/05/29 22:19:50 kent
Improving indentation. Improving an error message, and the test that triggers it.
Index: src/hg/makeDb/trackDbPatch/trackDbPatch.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/makeDb/trackDbPatch/trackDbPatch.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -b -B -U 4 -r1.5 -r1.6
--- src/hg/makeDb/trackDbPatch/trackDbPatch.c 11 May 2010 01:43:30 -0000 1.5
+++ src/hg/makeDb/trackDbPatch/trackDbPatch.c 29 May 2010 22:19:50 -0000 1.6
@@ -102,20 +102,22 @@
return fileList;
}
-static struct slName *makeFileList(char *filesAndPos)
+static struct slName *makeFileList(struct lineFile *lf, char *filesAndPos)
/* Convert something that looks like "file # file #" to a list of files. This
- * writes zeroes into the filesAndPos input. */
+ * writes zeroes into the filesAndPos input. The lf parameter is just for
+ * error reporting. */
{
struct slName *list = NULL;
char *word;
while ((word = nextWord(&filesAndPos)) != NULL)
{
slNameAddTail(&list, word);
word = nextWord(&filesAndPos);
- if (word == NULL && !isdigit(word[0]))
- errAbort("Expecting number in makeFileList, got %s", word);
+ if (word == NULL || !isdigit(word[0]))
+ errAbort("Expecting number in filePos tag, got %s, line %d of %s", word,
+ lf->lineIx, lf->fileName);
}
return list;
}
@@ -144,9 +146,9 @@
freez(&tag);
}
else if (sameString(tag->name, "filePos"))
{
- patch->fileList = makeFileList(tag->val);
+ patch->fileList = makeFileList(lf, tag->val);
int fileCount = slCount(patch->fileList);
if (fileCount != 1)
{
if (fileCount == 0)
@@ -308,13 +310,16 @@
verbose(2, "Deleting %s in %s\n", patch->track, inName);
else
{
verbose(3, "Got patch %s with %d tags starting %s %s\n", patch->track, slCount(patch->tagList), patch->tagList->name, (char *)patch->tagList->val);
- int indent = 0;
- struct hash *appliedHash = hashNew(0);
+ struct hash *appliedHash = hashNew(0); // keep track of tags patched in
+
+ /* Go through stanza looking for tags to update. */
+ char *lineStart = NULL; // At end of loop points to last line
+ int indent = 0; // # of whitespace chars
for (line = stanza; line != NULL; line = line->next)
{
- char *lineStart = line->name;
+ lineStart = line->name;
char *tagStart = skipLeadingSpaces(lineStart);
boolean copyLine = TRUE;
if (tagStart[0] != 0 && tagStart[0] != '#')
{
@@ -324,9 +329,9 @@
{
if (startsWithWord(tagPatch->name, tagStart))
{
copyLine = FALSE;
- spaceOut(f, indent);
+ mustWrite(f, lineStart, indent);
fprintf(f, "%s %s\n", tagPatch->name, (char*)tagPatch->val);
verbose(2, "Applying patch '%s' to modify %s'\n", (char*)tagPatch->val, tagStart);
++glPatchFieldModifyCount;
hashAdd(appliedHash, tagPatch->name, NULL);
@@ -338,16 +343,18 @@
{
fprintf(f, "%s\n", line->name);
}
}
+
+ /* Go through and add any tags not already patched in. */
struct slPair *tagPatch;
for (tagPatch = patch->tagList; tagPatch != NULL; tagPatch = tagPatch->next)
{
if (!hashLookup(appliedHash, tagPatch->name))
{
- spaceOut(f, indent);
++glPatchFieldAddCount;
verbose(2, "Applying patch to %s adding %s %s\n", patch->track, tagPatch->name, (char*)tagPatch->val);
+ mustWrite(f, lineStart, indent);
fprintf(f, "%s %s\n", tagPatch->name, (char*)tagPatch->val);
hashAdd(appliedHash, tagPatch->name, NULL);
}
}