/*
 * alloc.c
 *
 * $Author: dm3e $
 * $Date: 1993/02/03 13:57:54 $
 * $Revision: 1.8 $
 * $State: Exp $
 * $Locker:  $
 */

/***********************************************************
        Copyright 1991 by Carnegie Mellon University

                      All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/

#include <stdio.h>
#include "rxemt.h"
#include "alloc.h"
#include "tools.h"

/***************************************************************************
 * [exported] new_tree
 *
 * Description:
 *      Creates new space for a tree
 *
 * Arguments:
 *
 * Environment:
 *
 * History:
 *      Wed Jun 10 13:19:24 1992 - created by David Allen Markley
 *
 ***************************************************************************/
new_tree(tree)
tree_t *tree;
{
    tree_t n_tree;

    if (NULL == (n_tree = (tree_t)malloc(sizeof(struct tree_s)))) {
	Log("can's malloc enough space.\n");
	exit(-1);
    }
    bzero(n_tree, sizeof(struct tree_s));
    n_tree->name = copy_string("");
    n_tree->owner = copy_string("");
    n_tree->src_path = copy_string("");
    n_tree->db_path = copy_string("");
    if (NULL == *tree) {
	*tree = n_tree;
    } else {
	(*tree)->next = n_tree;
	*tree = n_tree;
    }
}

/***************************************************************************
 * [exported] new_env
 *
 * Description:
 *      Creates new space for and environment.
 *
 * Arguments:
 *
 * Environment:
 *
 * History:
 *      Wed Jun 10 13:20:05 1992 - created by David Allen Markley
 *
 ***************************************************************************/
new_env(env)
edb_t *env;
{
    edb_t n_env;

    if (NULL == (n_env = (edb_t)malloc(sizeof(struct edb_s)))) {
	Log("can's malloc enough space.\n");
	exit(-1);
    }
    bzero(n_env, sizeof(struct edb_s));
    n_env->name = copy_string("");
    if (NULL == *env) {
	*env = n_env;
    } else {
	(*env)->next = n_env;
	*env = n_env;
    }
}

/***************************************************************************
 * [exported] new_sys
 *
 * Description:
 *      Creates new space for a system type.
 *
 * Arguments:
 *
 * Environment:
 *
 * History:
 *      Wed Jun 10 13:20:37 1992 - created by David Allen Markley
 *
 ***************************************************************************/
new_sys(sys)
edb_sys_t *sys;
{
    edb_sys_t n_sys;

    if (NULL == (n_sys = (edb_sys_t)malloc(sizeof(struct edb_sys_s)))) {
	Log("can's malloc enough space.\n");
	exit(-1);
    }
    bzero(n_sys, sizeof(struct edb_sys_s));
    n_sys->name = copy_string("");
    n_sys->path = copy_string("");
    if (NULL == *sys) {
	*sys = n_sys;
    } else {
	(*sys)->next = n_sys;
	*sys = n_sys;
    }
}

/***************************************************************************
 * [exported] new_rep
 *
 * Description:
 *      Creates new space for a replcation site.
 *
 * Arguments:
 *
 * Environment:
 *
 * History:
 *      Wed Jun 10 13:21:08 1992 - created by David Allen Markley
 *
 ***************************************************************************/
new_rep(rep)
edb_rep_t *rep;
{
    edb_rep_t n_rep;

    if (NULL == (n_rep = (edb_rep_t)malloc(sizeof(struct edb_rep_s)))) {
	Log("can's malloc enough space.\n");
	exit(-1);
    }
    bzero(n_rep, sizeof(struct edb_rep_s));
    n_rep->name = copy_string("");
    if (NULL == *rep) {
	*rep = n_rep;
    } else {
	(*rep)->next = n_rep;
	*rep = n_rep;
    }
}

/***************************************************************************
 * [exported] new_depothost
 *
 * Description:
 *      Creates new space for a depot host.
 *
 * Arguments:
 *
 * Environment:
 *
 * History:
 *      Wed Jun 10 13:21:33 1992 - created by David Allen Markley
 *
 ***************************************************************************/
new_depothost(dh)
edb_depot_t *dh;
{
    edb_depot_t n_dh;

    if (NULL == (n_dh = (edb_depot_t)malloc(sizeof(struct edb_depot_s)))) {
	Log("can's malloc enough space.\n");
	exit(-1);
    }
    bzero(n_dh, sizeof(struct edb_depot_s));
    n_dh->hostname = copy_string("");
    if (NULL == *dh) {
	*dh = n_dh;
    } else {
	(*dh)->next = n_dh;
	*dh = n_dh;
    }
}

/***************************************************************************
 * [exported] new_llist
 *
 * Description:
 *
 * Arguments:
 *
 * Environment:
 *
 * History:
 *      Wed Oct  7 16:01:36 1992 - created by David Allen Markley
 *
 ***************************************************************************/
long new_llist(list, strA, strB, val)
llist_t *list;
char *strA, *strB;
int val;
{
    llist_t n_list;

    if (NULL == (n_list = (llist_t)malloc(sizeof(struct llist)))) {
	Log("can's malloc enough space.\n");
	exit(-42);
    }
    bzero(n_list, sizeof(struct llist));
    if (NULL == *list) {
	*list = n_list;
    } else {
	(*list)->next = n_list;
	*list = n_list;
    }
    (*list)->buffA = (char *)copy_string(strA);
    (*list)->buffB = (char *)copy_string(strB);
    (*list)->value = val;
    return 0;
}

/***************************************************************************
 * [exported] new_req_in
 *
 * Description:
 *
 * Arguments:
 *
 * Environment:
 *
 * History:
 *      Wed Oct  7 16:07:38 1992 - created by David Allen Markley
 *
 ***************************************************************************/
req_in_t new_req_in()
{
    req_in_t n_req;

    if (NULL == (n_req = (req_in_t)malloc(sizeof(struct req_in)))) {
	Log("can't malloc enough space.\n");
	return NULL;
    }
    bzero(n_req, sizeof(struct req_in));
    return n_req;
}
