home *** CD-ROM | disk | FTP | other *** search
-
- /*
- *
- * 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;
-
- {
- 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
- {
- for (i = 0; i < strlen(pProp->DataFormat); i++)
- if (pProp->DataFormat[i] == 's') nostrings = 0;
- switch(pProp->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_DATA:
- if (nostrings)
- FreeStrings(pProp->PropData + 2 * 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);
- }
- }
- return(0);
- }
-