25c8c6fbc1b49012dcde16119ddb1be663ede442
angie
  Fri Jun 1 11:43:04 2012 -0700
Refactoring for #6152: there's nothing formatter-specific about annoFormatterOption,so move it out into independent annoOption.

diff --git src/lib/annoFormatter.c src/lib/annoFormatter.c
index cac50b3..34525bf 100644
--- src/lib/annoFormatter.c
+++ src/lib/annoFormatter.c
@@ -1,119 +1,26 @@
 /* annoFormatter -- aggregates, formats and writes output from multiple sources */
 
 #include "annoFormatter.h"
 
-static struct annoFormatterOption *annoFormatterOptionCloneList(struct annoFormatterOption *list)
-/* Return a newly allocated copy of list. */
-{
-struct annoFormatterOption *newList = NULL, *afo;
-for (afo = list;  afo != NULL;  afo = afo->next)
-    {
-    struct annoFormatterOption *newAfo = CloneVar(afo);
-    newAfo->spec.name = cloneString(afo->spec.name);
-    newAfo->value = NULL;
-    unsigned opFlags = opFlags;
-    if (opFlags & OPTION_MULTI)
-	{
-	switch (opFlags & OPTION_TYPE_MASK)
-	    {
-	    case OPTION_STRING:
-		newAfo->value = slNameCloneList((struct slName *)(afo->value));
-		break;
-	    default:
-		errAbort("annoFormatterOptionCloneList: OPTION_MULTI implemented only for "
-			 "OPTION_STRING (not 0x%x)", opFlags);
-	    }
-	}
-    else
-	{
-	switch (opFlags & OPTION_TYPE_MASK)
-	    {
-	    // For numeric singleton values, we are overloading value.
-	    case OPTION_DOUBLE:
-	    case OPTION_FLOAT:
-	    case OPTION_LONG_LONG:
-	    case OPTION_INT:
-	    case OPTION_BOOLEAN:
-		newAfo->value = afo->value;
-		break;
-	    case OPTION_STRING:
-		newAfo->value = cloneString((char *)afo->value);
-		break;
-	    default:
-		errAbort("annoFormatterOptionCloneList: unrecognized op type 0x%x", opFlags);
-	    }
-	}
-    slAddHead(&newList, newAfo);
-    }
-slReverse(&newList);
-return newList;
-}
-
-static void annoFormatterOptionFreeList(struct annoFormatterOption **pList)
-/* Free the same things that we clone above. */
-{
-if (pList == NULL)
-    return;
-struct annoFormatterOption *afo, *nextAfo;
-for (afo = *pList;  afo != NULL;  afo = nextAfo)
-    {
-    nextAfo = afo->next;
-    freeMem(afo->spec.name);
-    unsigned opFlags = opFlags;
-    if (opFlags & OPTION_MULTI)
-	{
-	switch (opFlags & OPTION_TYPE_MASK)
-	    {
-	    case OPTION_STRING:
-		slNameFreeList(&(afo->value));
-		break;
-	    default:
-		errAbort("annoFormatterOptionFreeList: OPTION_MULTI implemented only for "
-			 "OPTION_STRING (not 0x%x)", opFlags);
-	    }
-	}
-    else
-	{
-	switch (opFlags & OPTION_TYPE_MASK)
-	    {
-	    // No need to free overloaded numeric values
-	    case OPTION_DOUBLE:
-	    case OPTION_FLOAT:
-	    case OPTION_LONG_LONG:
-	    case OPTION_INT:
-	    case OPTION_BOOLEAN:
-		break;
-	    case OPTION_STRING:
-		freeMem(afo->value);
-		break;
-	    default:
-		errAbort("annoFormatterOptionFreeList: unrecognized op type 0x%x", opFlags);
-	    }
-	}
-    freeMem(afo);
-    }
-*pList = NULL;
-}
-
-struct annoFormatterOption *annoFormatterGetOptions(struct annoFormatter *self)
+struct annoOption *annoFormatterGetOptions(struct annoFormatter *self)
 /* Return supported options and current settings.  Callers can modify and free when done. */
 {
-return annoFormatterOptionCloneList(self->options);
+return annoOptionCloneList(self->options);
 }
 
-void annoFormatterSetOptions(struct annoFormatter *self, struct annoFormatterOption *newOptions)
+void annoFormatterSetOptions(struct annoFormatter *self, struct annoOption *newOptions)
 /* Free old options and use clone of newOptions. */
 {
-annoFormatterOptionFreeList(&(self->options));
-self->options = annoFormatterOptionCloneList(newOptions);
+annoOptionFreeList(&(self->options));
+self->options = annoOptionCloneList(newOptions);
 }
 
 void annoFormatterFree(struct annoFormatter **pSelf)
 /* Free self. This should be called at the end of subclass close methods, after
  * subclass-specific connections are closed and resources are freed. */
 {
 if (pSelf == NULL)
     return;
-annoFormatterOptionFreeList(&((*pSelf)->options));
+annoOptionFreeList(&((*pSelf)->options));
 freez(pSelf);
 }