/**************************************************************************/
/*                                                                        */
/*                                 Sources                                */
/*                                from  the                               */
/*                           XSC SOFTWARE PACKAGE                         */
/*                                                                        */
/*                Copyright (c) 1997 University of Karlsruhe              */
/*                     Institute for Appl. Mathematics                    */
/*                                                                        */
/* This program is free software for non-commercial use. For details, see */
/* the file LICENSE.XSC, distributed with this software package.          */
/*                                                                        */
/* This program is distributed WITHOUT ANY WARRANTY. For details, see the */
/* file LICENSE.XSC, distributed with this software package.              */
/*                                                                        */
/**************************************************************************/

/* RCS $Id: a_exit.c,v 1.2 1997/09/25 16:51:18 ae59 Exp $ */
/*
$Log: a_exit.c,v $
 * Revision 1.2  1997/09/25  16:51:18  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:20:43  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : a_exit.c                              */
/*                                                              */
/*      Entries         : void a_exit(p)                        */
/*                        a_intg p;                             */
/*                                                              */
/*      Arguments       : exit value passed to environment      */
/*                                                              */
/*      Description     : Exit to environment.                  */
/*                                                              */
/*      Date            : 1991-09-18                            */
/*      1991-09-18 : close files and remove temporary files     */
/*      1990-11-15 : E_TPUSH+E_TPOPP                            */
/****************************************************************/

#ifndef ALL_IN_ONE
#ifdef AIX
#include "/u/p88c/runtime/o_defs.h"
#else
#include "o_defs.h"
#endif
#define local
extern a_VOID f_ftop;
#endif

#ifdef LINT_ARGS
local void a_exit(a_intg p)
#else
local void a_exit(p)

a_intg p;
#endif
        {
        register f_text *desc;

        E_TPUSH("a_exit")

        /* close files */
        while (f_ftop!=NULL)
           {
           desc = (f_text *)f_ftop;

           /* put newline character to textfile if opened for output */
           if (desc->asgd==TRUE && desc->fp!=NULL && desc->text==TRUE &&
               desc->outf==TRUE && desc->err==FALSE && desc->eoln==FALSE)
              f_putc((a_char)'\n',desc);

           if (desc->stdi==FALSE && desc->stdo==FALSE && desc->fp!=NULL)
              {
              fclose(desc->fp);

              /* remove temporary file */
              if (desc->temp) remove(desc->name);
              }
           desc->temp = FALSE;
           desc->fp = NULL;

           f_ftop = desc->next;
           }

        exit((int)p);

        E_TPOPP("a_exit")
        return;
        }
