|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: F T
Length: 2816 (0xb00)
Types: TextFile
Names: »FreeProp.c«
└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
└─⟦this⟧ »EUUGD11/euug-87hel/sec1/offconv/FreeProp.c«
/*
*
* Description
* Free a property structure and associated memory resources.
*
* Output
*
* Input
* pProp Pointer to the property structure to be deallocated.
*
* Diagnostics
* Returns 0 if successful, -1 if unsuccessful (unknown data type).
*
* Author
* Randi J. Rost
* Digital Equipment Corp.
* Workstation Systems Engineering
* Palo Alto, CA
*
* History
* 17-Nov-86 Created
*
*/
#include <stdio.h>
#include "off.h"
OFFFreeProperty(pProp)
OFFProperty *pProp;
{
OFFProperty *newprop;
int i;
int nostrings = 1;
if (strcmp(pProp->PropName, "comment") == 0)
{
free(pProp->PropData);
free(pProp);
return(0);
}
if (strcmp(pProp->PropName, "nl") == 0)
{
free(pProp);
return(0);
}
if (strcmp(pProp->PropName, "name") == 0 ||
strcmp(pProp->PropName, "author") == 0 ||
strcmp(pProp->PropName, "type") == 0 ||
strcmp(pProp->PropName, "description") == 0 ||
strcmp(pProp->PropName, "copyright") == 0)
{
free(pProp->PropData);
free(pProp);
return(0);
}
else
{
nostrings;
for (i = 0; i < strlen(pProp->DataFormat); i++)
if (pProp->DataFormat[i] == 's') nostrings = 0;
switch(newprop->PropType)
{
case OFF_DEFAULT_DATA:
if (!nostrings)
FreeStrings(pProp->PropData, pProp->DataFormat, 1);
break;
case OFF_GENERIC_DATA:
if (!nostrings)
FreeStrings(pProp->PropData + sizeof(long),
pProp->DataFormat, pProp->PropCount);
break;
case OFF_INDEXED_POLY_DATA:
if (nostrings)
FreeStrings(pProp->PropData + 3 * sizeof(long),
pProp->DataFormat, pProp->PropCount);
break;
default:
return(-1);
break;
} /* switch */
free(pProp->PropData);
free(pProp);
}
return(0);
}
static int FreeStrings(dataptr, format)
char *dataptr;
char *format;
{
int i;
char *ptr;
ptr = dataptr;
for (i = 0; i < strlen(format); i++)
{
switch(format[i])
{
case 'i':
/* Make sure we're aligned on word boundary */
ptr += (((int) ptr % 4) == 0) ? 0 : 4 - (int) ptr % 4;
ptr += sizeof(long);
break;
case 'b':
ptr++;
break;
case 'd':
/* Make sure we're aligned on word boundary */
ptr += (((int) ptr % 4) == 0) ? 0 : 4 - (int) ptr % 4;
ptr += sizeof(double);
break;
case 'h':
/* Make sure we're aligned on halfword boundary */
ptr += (((int) ptr % 2) == 0) ? 0 : 1;
ptr += sizeof(short);
break;
case 'f':
/* Make sure we're aligned on word boundary */
ptr += (((int) ptr % 4) == 0) ? 0 : 4 - (int) ptr % 4;
ptr += sizeof(float);
break;
case 's':
/* Make sure we're aligned on word boundary */
ptr += (((int) ptr % 4) == 0) ? 0 : 4 - (int) ptr % 4;
free(*((char **) ptr));
ptr += sizeof(char *);
break;
default:
return(-1);
}
}
}