#ident "$URL: svn://elmer/devel/SVN/SDDAS/trunk/libCfg/ItemValue.c $ %D% SwRI" #include #include #include "Destroy.h" #include "ItemValue.h" #include "libCfg_local.h" /* * void *V - pointer to an ItemValue structure * * This routine will free up all memory within this structure */ void DestroyItemValue(void *V) { int i, j; DestroyObj_t *D; ItemValue_t *I = (ItemValue_t *)V; D = I->Destroy; for (i=D->NToFree-1; i>=0; i--) { for (j=0; jNToFree-1].next) (D->Free)((void *)I[D->NToFree-1].next); free((char*)I); free((char*)D); } /* * int n - the number of ItemValue structure to create * * Initializes ItemValue structures and attaches to it the destroy routine for * freeing up memory. */ ItemValue_t *CreateItemValue(int n) { ItemValue_t *I, *i; DestroyObj_t *D; if (!(I = (ItemValue_t *)calloc(n, sizeof(ItemValue_t)))) { return NULL; } if (!(D = (DestroyObj_t *)calloc(1, sizeof(DestroyObj_t)))) { free((char*)I); return NULL; } for (i=I; inext = i + 1; } i->next = (ItemValue_t *)0; i->n_Values = 0; D->NToFree = n; D->Free = DestroyItemValue; I->Destroy = D; return I; } /* * ItemValue_t *I - node to start query * char *item - 'item' to query * int elmt - index into array when there are multiple values for the item * * This routine returns the string pointer to a string associated to the 'item'. */ char *FindItemValue (ItemValue_t *I, const char *item, SDDAS_INT elmt) { if (I == NULL) { return NULL; } if (strcmp (I->Item, item) == 0) { if (elmt >= I->n_Values) return NULL; return I->Value [elmt]; } else { return FindItemValue (I->next, item, elmt); } } /* * StrHier S - tree node to start query * char *s - string to query for * int elmt - index of value from string query * * Uses FindItemValue by referencing the ItemValue from the node's StrHier */ char *ValueFromItem (StrHier S, const char *s, SDDAS_INT elmt) { ItemValue_t *I = (ItemValue_t *) S->info; return FindItemValue (I, s, elmt); }