mif/mifmdelete.c, cleanup

rewrite in terms of GENmodule and GENinstance
This commit is contained in:
rlar 2018-01-07 19:54:44 +01:00
parent 703cbf8bd8
commit e2175232a9
1 changed files with 16 additions and 35 deletions

View File

@ -50,8 +50,6 @@ NON-STANDARD FEATURES
/* #include "suffix.h" */
/*
MIFmDelete
@ -62,55 +60,39 @@ model structure. It calls MIFdelete as needed to delete all
instances of the specified model.
*/
int MIFmDelete(
GENmodel **inModel, /* The head of the model list */
GENmodel **models, /* The head of the model list */
IFuid modname, /* The name of the model to delete */
GENmodel *kill /* The model structure to be deleted */
)
{
MIFmodel **model;
MIFmodel *modfast;
MIFmodel **oldmod;
MIFmodel *here=NULL;
Mif_Boolean_t found;
int i;
/* Convert the generic pointers to MIF specific pointers */
model = (MIFmodel **) inModel;
modfast = (MIFmodel *) kill;
GENmodel **prev = models;
GENmodel *model = *prev;
/* Locate the model by name or pointer and cut it out of the list */
oldmod = model;
for(found = MIF_FALSE; *model; model = &((*model)->MIFnextModel)) {
if( (*model)->MIFmodName == modname ||
(modfast && *model == modfast) ) {
here = *model;
*oldmod = (*model)->MIFnextModel;
found = MIF_TRUE;
for (; model; model = model->GENnextModel) {
if (model->GENmodName == modname || (kill && model == kill))
break;
}
oldmod = model;
prev = &(model->GENnextModel);
}
if(! found)
if (!model)
return(E_NOMOD);
*prev = model->GENnextModel;
/* Free the instances under this model if any */
/* by removing from the head of the linked list */
/* until the head is null */
while(here->MIFinstances) {
MIFdelete((GENmodel *) here,
here->MIFinstances->MIFname,
(GENinstance **) &(here->MIFinstances));
}
while (model->GENinstances)
MIFdelete(model, model->GENinstances->GENname, &(model->GENinstances));
MIFmodel *here = (MIFmodel*) model;
int i;
/* Free the model params stuff allocated in MIFget_mod */
for(i = 0; i < here->num_param; i++) {
if(here->param[i]->element)
for (i = 0; i < here->num_param; i++) {
if (here->param[i]->element)
FREE(here->param[i]->element);
FREE(here->param[i]);
}
@ -119,5 +101,4 @@ int MIFmDelete(
/* Free the model and return */
FREE(here);
return(OK);
}