/**************************************************************************/
/*                                                                        */
/*                                 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: b_pool.c,v 1.2 1997/09/25 17:05:30 ae59 Exp $ */
/*
$Log: b_pool.c,v $
 * Revision 1.2  1997/09/25  17:05:30  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:21:36  ae59
 * Put under RCS control
 *
 */
/*************************************************************************
 *                                                                       *
 * Descriptive Name : Lvarpool           Processor : C                   *
 *                                                                       *
 * Pool for Variables of type dynamic                                    *
 * ==================================                                    *
 *                                                                       *
 * Include files :  b_lari.h  - definitions for INTERN standard functions*
 *                                                                       *
 * Function value : int       - 0                                        *
 *                                                                       *
 * Used Number Base :  2**32                                             *
 *                                                                       *
 * Used Functions :                                                      *
 *                     Intern arithmetic                                 *
 *                                                                       *
 * Used Global INTERN Variables and Constants :                          *
 *    LhV[10]
 *                                                                       *
 * Used UNSIGNED Global Variables :                                      *
 *    Ldebug          Flag for printing additional information           *
 *                                                                       */
/*      Date            : 1991-09-09                            */
/*      1991-09-09 : reduce max. line length                    */
/*      1990-09-04 : Larith.h replaced by b_lari.h              *
 *************************************************************************/

#ifdef AIX
#include "/u/p88c/runtime/base/b_lari.h"
#else
#include "b_lari.h"
#endif

static dynamic   LhV[numvar];

#ifdef Debug
extern int       Ldebug;
#endif

/****************************************************************
 * Constants for Routine Lvarpool                               *
 ****************************************************************/

static int next = 0;

/****************************************************************
 * Algorithm for Fetching a new Variable                        *
 ****************************************************************/

#ifdef LINT_ARGS
dynamic *b_get_(void)
#else
dynamic *b_get_()
#endif
#define  LRoutine    "Lvarget"
{
#ifdef Debug
   Ldebug -= 1;                            /* Diminish Debug Level */
   if (Ldebug >= 0) printf("\n Entering Routine %s",LRoutine);
#endif

#ifdef Debug
   if (Ldebug >= 0) {
      printf("\n  (Lvarget 78) assigning : %d\n",next);
      }
#endif

   if (next >= numvar-1) {
      Lerror(ALLOC);            /* Error Message                */
      }
   else {
      next++;
      EXIT(&(LhV[next])); /* Return address of next free variable */
      }
   EXIT(NULL);               /* Return NULL if no variable available */
}
#undef  LRoutine


/****************************************************************
 * Algorithm for Returning Variables                            *
 ****************************************************************/

#ifdef LINT_ARGS
int b_drop(int  n)
#else
int b_drop(n)
int  n;
#endif
#define  LRoutine    "Lvardrop"
{
#ifdef Debug
   Ldebug -= 1;                            /* Diminish Debug Level */
   if (Ldebug >= 0) printf("\n Entering Routine %s",LRoutine);
#endif

   next = max(next-n,0);        /*   avoiding negative indices      */

#ifdef Debug
   if (Ldebug >= 0) {
      printf("\n  (Lvardrop 118) next = %d\n",next);
      }
#endif

   EXIT(0);
}
