home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- *******************************************************************************
-
- Site: Western Michigan University Academic Computer Center
-
- System: Directory/File System Maintenance
-
- Program: maint
-
- Version=01 Level=00 01/24/92 Leonard J. Peirce
-
- Purpose: Memory allocation/initialization routines for command
- structures.
-
- Arguments: See individual routines
-
- External variables: See individual routines
-
- External functions:
-
- Defined: free_com, free_comstr, new_comm
-
- Called: None
-
- Files accessed: None
-
- Return codes: See individual routines
-
- Compiling instructions: See Makefile
-
- Linking instructions: See Makefile
-
- Other information: (C) Copyright 1992, Leonard J. Peirce
-
- ********************************************************************************
- *******************************************************************************/
-
- /******************************************************************************/
- /* */
- /* # I N C L U D E F I L E S */
- /* */
- /******************************************************************************/
-
- #include <malloc.h>
- #if defined(SYSV) || !defined(sun)
- #include <stdio.h>
- #endif
- #include "maint.h"
-
- /******************************************************************************/
- /* */
- /* # D E F I N E S */
- /* */
- /******************************************************************************/
-
- /******************************************************************************/
- /* */
- /* S T R U C T U R E S , U N I O N S , T Y P E D E F S */
- /* */
- /******************************************************************************/
-
- /******************************************************************************/
- /* */
- /* E X T E R N A L D E F I N I T I O N S & D E C L A R A T I O N S */
- /* */
- /******************************************************************************/
-
- #ifndef ultrix
- extern void free();
- #endif
-
- void free_comm(),
- free_comstr();
-
- COM_DEF *new_comm();
-
- /******************************************************************************/
- /* */
- /* ST A T I C D E F I N I T I O N S & D E C L A R A T I O N S */
- /* */
- /******************************************************************************/
-
- /*******************************************************************************
- ********************************************************************************
-
- Function: free_com
-
- Purpose: Free the memory that was allocated for all of the command
- structures for a directory, including all of the memory that
- may have been allocated to hold things such as the copy name,
- the rename name, and the text descriptor.
-
- Global variables:
-
- Name Examine/Modify/Use/Read/Write
- ---- -----------------------------
- none
-
- Return Codes:
-
- Code Reason
- ---- ------
- none
-
- ********************************************************************************
- *******************************************************************************/
-
- void free_comm(dirptr,num_file)
- /******* FORMAL PARAMETERS *******/
- register ENT_DEF *dirptr; /* pointer to directory entries */
- register short num_file; /* number of files in directory */
-
- { /*** free_comm ***/
-
-
- while(num_file-- > 0) /* delete all command structs */
- {
- if(dirptr->command != NULL) /* command struct for this entry? */
- {
- /* free up the command structure and everything associated with it */
-
- free_comstr(dirptr->command);
- }
-
- dirptr++; /* go to next command strucure */
- }
-
- return;
-
- } /*** free_comm ***/
-
- /*******************************************************************************
- ********************************************************************************
-
- Function: free_comstr
-
- Purpose: Free the memory that belongs to a specific command structure.
-
- Global variables:
-
- Name Examine/Modify/Use/Read/Write
- ---- -----------------------------
- none
-
- Return Codes:
-
- Code Reason
- ---- ------
- none
-
- Termination Codes:
-
- Code Reason
- ---- ------
- status failure freeing memory
-
- ********************************************************************************
- *******************************************************************************/
-
- void free_comstr(command_str)
- /******* FORMAL PARAMETERS *******/
- register COM_DEF *command_str; /* pointer to structure to be freed */
-
- { /*** free_comstr ***/
-
- if(command_str->copy_name != NULL)
- {
- /* free up the memory for the copy name */
-
- free(command_str->copy_name);
- }
-
- if(command_str->ren_name != NULL)
- {
- /* free up the memory for the rename name */
-
- free(command_str->ren_name);
- }
-
- if(command_str->text != NULL)
- {
- /* free up the memory for the copy name */
-
- free(command_str->text);
- }
-
- /* now free up the command structure itself */
-
- free((char *) command_str);
-
- return;
-
- } /*** free_comstr ***/
-
- /*******************************************************************************
- ********************************************************************************
-
- Function: new_comm
-
- Purpose: Allocate memory for a new command structure and return a
- pointer to the memory.
-
- Global variables:
-
- Name Examine/Modify/Use/Read/Write
- ---- -----------------------------
- none
-
- Return Codes:
-
- Code Reason
- ---- ------
- ptr pointer to allocated memory
- NULL problems allocating memory
-
- ********************************************************************************
- *******************************************************************************/
-
- COM_DEF *new_comm()
-
- { /*** new_comm ***/
- /******* FORMAL PARAMETERS *******/
- register COM_DEF *ptr; /* pointer to allocated memory */
-
-
- ptr = (COM_DEF *) malloc((u_int) sizeof(COM_DEF));
-
- if(ptr == NULL)
- return(NULL);
-
- memset(ptr,0,sizeof(COM_DEF)); /* initialize it */
- ptr->copy_name = NULL;
- ptr->text = NULL;
- ptr->ren_name = NULL;
-
- return(ptr); /* return pointer to the structure */
-
- } /*** new_comm ***/
-