/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* |_o_o|\\ Copyright (c) 1986 The Software Distillery.  All Rights Reserved */
/* |. o.| || This program may not be distributed without the permission of   */
/* | .  | || the authors.                                                    */
/* | o  | ||    Dave Baker     Ed Burnette  Stan Chow    Jay Denebeim        */
/* |  . |//     Gordon Keener  Jack Rouse   John Toebes  Doug Walker         */
/* ======          BBS:(919)-471-6436      VOICE:(919)-469-4210              */ 
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
 * VERY loosely based on the input.device example by Rob Peck, 12/1/85
 */

/*
 * termproc() frees all of the stuff which copyproc() allocated for its
 * functionality.
 */

#include "popcli.h"

static void DosFree( GLOBAL_DATA *, char * );

void termproc( gptr, bye )
GLOBAL_DATA *gptr;
register struct Process *bye;
{
   register struct CDIR                   *current, *next;
   register struct CommandLineInterface   *byecli;

   /* Free the path chain, the CLI structure block, then unlock the       */
   /* current directory.                                                  */

   byecli = (struct CommandLineInterface *)(bye->pr_CLI << 2);
   if (byecli)
   {
      for (current = (struct CDIR *)(byecli->cli_CommandDir << 2);
           current != NULL;
           current = next)
      {
         next = (struct CDIR *)(current->next << 2);
         UnLock( current->lock );
         DosFree( gptr, (char *)current );
      }

      DosFree( gptr, (char *)byecli );
      bye->pr_CLI = NULL;
   }

   UnLock( bye->pr_CurrentDir );
   bye->pr_CurrentDir = NULL;
}

/*
 * Back up 4 bytes, get the length, and free that much
 * Block should have been allocated with DosAlloc, in copyproc.c
 */

static void DosFree( gptr, mem )
struct GLOBAL_DATA *gptr;
char *mem;
{
   register long    *old;

   old = (long *)(mem - 4);

   FreeMem( (char *)old, *old );
}

