/*
 * This file is part of uudeview, the simple and friendly multi-part multi-
 * file uudecoder  program  (c)  1994 by Frank Pilhofer. The author may be
 * contacted by his email address,          fp@informatik.uni-frankfurt.de
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */


#include <malloc.h>
#include <stdio.h>

#ifndef NO_POSIX
#ifndef _DOS
#include <unistd.h>
#endif
#endif

#include "uudeview.h"

/*
 * free some memory
 **/

void killfread (fileread *data)
{
  if (data != NULL) {
    free (data->subject);
    free (data->origin);
    free (data->filename);
    free (data->sfname);
    free (data->mimeid);
    free (data);
  }
}

void killfile (uufile *data)
{
  if (data != NULL) {
    free      (data->filename);
    free      (data->subfname);
    free      (data->mimeid);
    killfread (data->data);
    killfile  (data->NEXT);

    free      (data);
  }
}

void killlist (uulist *data)
{
  if (data != NULL) {
    if (data->binfile != NULL && data->tarblock == -1)
      unlink (data->binfile);

    free     (data->filename);
    free     (data->binfile);
    free     (data->subfname);
    free     (data->mimeid);
    killfile (data->thisfile);
    free     (data->misparts);
    killlist (data->branch);
    killlist (data->NEXT);

    free     (data);
  }
}

void killext (extlist *data)
{
  if (data != NULL) {
    killext (data->NEXT);
    free    (data);
  }
}

void killif (infile *data)
{
  if (data != NULL) {
    if (data->delflag) {
      if (unlink (data->name) != 0)
        printf ("Warning: Couldn't unlink file %s\n", data->name);
    }
    killif (data->NEXT);
    free   (data);
  }
}

/*****************************************************************************
 + Frank Pilhofer                             fp@informatik.uni-frankfurt.de +
 +---------------------------------------------------------------------------+
 | Department of Computer Sciences * University of Frankfurt / Main, Germany |
 *****************************************************************************/
