/*--------------------------------------------------------------------
 * FICHERO:  BdtAgrRe.c
 * OBJETIVO: Definir la funcin Bdt_AgregaRegistro()
 * AUTOR:    Pedro Reina
 * FECHA:    V.14.7.1995
 *------------------------------------------------------------------*/

/*--------------------------------------------------------------------
 * Ficheros de cabecera
 *------------------------------------------------------------------*/

#include "BaseDato.h"

/*--------------------------------------------------------------------
 * Definicin de funciones
 *------------------------------------------------------------------*/

/*--------------------------------------------------------------Olimpo
 * FUNCION:  Bdt_AgregaRegistro()
 * OBJETIVO: Agregar un registro desde memoria al fichero,
 *           ponindolo al final de ste
 * ENTRADAS: La base de datos y una variable donde dejar el
 *           nmero de registro
 * SALIDAS:  Lgica indicando si el registro se ha escrito. En 
 *           la variable queda indicado el nmero de registro
 * NOTA:     Los registros se cuentan a partir de 0
 * EJEMPLO:  Bdt_AgregaRegistro (Agenda,&Numero)
 *------------------------------------------------------------------*/
logico Bdt_AgregaRegistro (Base, Numero)
basedato Base;
entero  *Numero;
  {
  logico Respuesta = NO;
  entero Total;

  if ( Bdt_ModoApertura(Base) == BDT_ACTUALIZACION )
    {
    Total = Bdt_TotalRegistro(Base);
    Fch_Coloca (Bdt_Fichero(Base), Bdt_ComienzoRegistro(Base) +
                                   Total * Bdt_LongitudRegistro(Base));
    if ( Fch_EscribeOcteto (Bdt_Fichero(Base), Bdt_InfoActual(Base),
                            Bdt_LongitudRegistro(Base)) )
      {
      Respuesta = SI;
      Bdt_PonTotalRegistro(Base,Total+1);
      Bdt_PonActual (Base,Total);
      *Numero = Total;
      Bdt_PonModificado (Base,SI);
      }
    }

  return ( Respuesta );
  }