/
Sapphire/bin/
Sapphire/db/
Sapphire/db/OLC_rooms/
Sapphire/db/abi/
Sapphire/db/em_src/
Sapphire/db/helps/
Sapphire/db/helps/emman/ifunc/
Sapphire/db/npcs/Tatt/
Sapphire/db/objects/Tatt/
Sapphire/db/q_data/
Sapphire/db/rooms/Tatt/
Sapphire/doc/
Sapphire/doc/em/
Sapphire/etc/
Sapphire/src/abic/
Sapphire/src/areacon/
Sapphire/src/client/
Sapphire/src/embc/
Sapphire/src/emi/
Sapphire/src/emi/test/
Sapphire/src/include/
Sapphire/src/sapphire/em/
Sapphire/src/tcon/
/*
 * Copyright (C) 1995-1997 Christopher D. Granz
 *
 * This header may not be removed.
 *
 * Refer to the file "License" included in this package for further
 * information and before using any of the following.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "emi.h"


/*
 * Functions
 */

/*
 * Allocates a new array.
 */
EM_ARRAY *array_alloc( register size_t rsSize )
{
    register EM_ARRAY *p;

    p                     = alloc_mem( sizeof( EM_ARRAY ) );
    p->sCount             = 1;
    p->sSize              = rsSize;
    p->pElements          = alloc_mem( ( sizeof( EM_VALUE ) * rsSize ) );
    p->pElements[0].iType = TYPE_INVALID;
    return ( p );
}


/*
 * Decreases array usage count.  If usage is equal to 0 frees the array.
 */
void array_free( register EM_ARRAY *p )
{
    register EM_VALUE *pValue;

    if ( --p->sCount > 0 )
        return;

    if ( ( pValue = p->pElements ) != NULL )
    {
        if ( pValue->iType != TYPE_INVALID )
        {
            register size_t rs;

            for ( rs = p->sSize; rs > 0; rs--, pValue++ )
                delete_value( pValue );
        }

        free_mem( (void **) &p->pElements );
    }
}


/*
 * Copys a pointer to an array.
 */
EM_ARRAY *array_copy( register EM_ARRAY *p )
{
    if ( p == NULL )
        return ( NULL );

    p->sCount++;
    return ( p );
}


/*
 * End of array.c
 */