/* _fm_clr.c *********** Copyright 1986-1991 by Vermont Creative Software *********** _fm_clr() Clears all the field definitions for a form Call #include void _fm_clr(fmp) FORMPTR fmp; Pointer to a form structure Returns None Description The _fm_clr() function frees the memory allocated for all the fields, background text, and picture strings defined with calls to pic_def(). This function traverses the linked list of field structures for the specified form. Memory is released for (1) all picture strings defined using pic_def(), (2) the choice, toggle, and range structures associated with any fields, and (3) all associated field structures. The header node for the linked list of fields remains. The linked list of background text structures is traversed. The memory for all background item structures is released. The header node for this linked list remains. The memory associated with programmer-defined text strings and memory files are not released. This includes field names, field messages, field help strings, background text strings, choice list memory files, and help memory files. Memory is not released for these variables because Vermont Views cannot assume this memory was obtained from the heap. Data variables are not freed. Related Functions fm_free() Cautions Memory associated with field names, field messages, field help strings, back ground text, choice list memory files, and help memory files is not released by this function. The memory associated with the form structure is not released. Use fm_free() to accomplish this task. This is a historical function only. */ #include #include #ifdef OLD_STYLE void FASTCALL _fm_clr(fmp) FORMPTR fmp; #else void FASTCALL _fm_clr(FORMPTR fmp) #endif { int i = 0; PTR itemp; UCHAR * picp, * glob_picp; NODEPTR item_ndp, pic_ndp, hd_ndp; DFIELDPTR dfldp; #ifndef NO_DEBUG_CODE static UCHAR fn[] = "_fm_clr"; #endif INIT_MODULE(fn); /*----------------------------------------------------------------------------*/ /* Free all the items in the form */ /*----------------------------------------------------------------------------*/ hd_ndp = fmp->item_hdndp; /* Free the linked list of items */ while ((item_ndp = hd_ndp->next_ndp) != hd_ndp) { itemp = item_ndp->datap; switch (_i_tag(itemp)) { case (DFLDTAG): dfldp = (DFIELDPTR)itemp; if (!_fm_issr(fmp) || i++ < ((SRPTR)fmp)->datacolq) { if (dfldp->clistp) /*free the choice list structure */ cl_free(dfldp->clistp); if (dfldp->togglep) /*free the toggle structure */ mem_free((PTR) dfldp->togglep); if (dfldp->mtogglep) /*free the muti/spin toggle struct*/ mem_free((PTR) dfldp->mtogglep); if (dfldp->rangep) /*free the range structure */ mem_free((PTR) dfldp->rangep); } /*----------------------------------------------------------------------------*/ /* check the global linked list of picture strings to see if we should free it*/ /*----------------------------------------------------------------------------*/ picp = dfldp->picp; pic_ndp = (_pichdndp) ? nd_first(_pichdndp) : (NODEPTR)NULLP; /*get the first node in the list */ while ((pic_ndp) && (glob_picp = (UCHAR *)pic_ndp->datap)) { /*traverse list */ if (picp == glob_picp) { /*is this the picture in the field */ nd_del(pic_ndp);/*delete picture node */ break; /*all done here - move to next field */ } pic_ndp = nd_next(pic_ndp); /*check the next picture node */ } nd_del(item_ndp); /*free the node */ break; case (MEMOTAG): if (((MEMOPTR)itemp)->clistp) cl_free(((MEMOPTR)itemp)->clistp); wn_free(((MEMOPTR)itemp)->wnp); nd_del(item_ndp); /*free the node */ break; case (LBOXTAG): wn_free(((LBOXPTR)itemp)->wnp); nd_del(item_ndp); /*free the node */ break; case (MFLDTAG): /*Free autoread sub-forms if any */ if (fmp->flags & FMVVD && ((MFIELDPTR)itemp)->vvd_flags & FLDAUTORD && ((MFIELDPTR)itemp)->sub_formp->vvd_flags & FMAUTORD) { fm_dn(((MFIELDPTR)itemp)->sub_formp); fm_free(((MFIELDPTR)itemp)->sub_formp); } nd_del(item_ndp); /*free the node */ break; case (SRTAG): fm_free((DFORMPTR)itemp); /*free the scrollable form */ item_ndp->datap = NULLP; nd_del(item_ndp); /*free the node */ break; } } fmp->cur_item = -1; fmp->itemq = 0; /*----------------------------------------------------------------------------*/ /* Free all the background items */ /*----------------------------------------------------------------------------*/ hd_ndp = fmp->bg_hdndp; /* Free the linked list */ while (hd_ndp->next_ndp != hd_ndp) nd_del(hd_ndp->next_ndp); EXIT_NOERRH(fn); return; }