/*
 *  Copyright 1992 Science Applications International Corporation.
 */

/*
 * NAME    
 *	utilities.h
 *
 * SYNOPSIS
 *      Contains a few utility defines and macros.
 *
 * DESCRIPTION
 *
 *
 * DIAGNOSTICS
 *
 *
 * FILES
 *
 *
 * SEE ALSO
*
 *
 * AUTHOR
 *	B. MacRitchie, June 29, 1992
 *
 *
 * MODIFICATIONS
 *
 */

/*
 *	SccsId:  @(#)utilities.h	16.1 8/3/93 SAIC
 */

#ifndef _UTILITIES_H_
#define _UTILITIES_H_

#include <malloc.h>
#include <string.h>
#include "proto.h"


/* 
 * from aesir.h
 */

/*
 * The following make the use of malloc much easier.  You generally want
 * to use UALLOC() to dynamically allocate space and UFREE() to free
 * the space up.
 *
 * UALLOC       - Allocate permanent memory.
 * UALLOCA      - Allocate temporary memory that is automatically free'd
 *                when calling procedure returns.
 * UREALLOC     - Change the size of allocated memory from a previous
 *                UALLOC() call (only on permanent memory).
 * UFREE        - Free permanent memory and set pointer to NULL.
 */

#ifndef UFREE
#define	UFREE(p)		if (p) {free ((char*) (p)); p = 0; }


#endif

#ifndef UALLOC
#define UALLOC(type, n)		(type *) malloc ((unsigned) (n) * (sizeof (type)))
#endif

#ifndef UCALLOC
#define UCALLOC(type, n)	(type *) calloc ((unsigned) (n), (sizeof (type)))
#endif

#ifndef UREALLOC
#define UREALLOC(p,type,n)	((p) ? (type *) realloc ((char *) (p), (unsigned) \
							 (sizeof (type) * (n))) \
				 : UALLOC (type, n))
#endif

/* 
 * end aesir.h
 */

#ifdef __STDC__
#define	VOID	void
#else
#define	VOID	char
#endif

/* opaque pointers. */
typedef	VOID	*Ptr;


/* Are two strings equal? */
#define STREQL(a,b)		(strcmp ((a), (b)) == 0)
#define STRNEQL(a,b,n)		(strncmp ((a), (b), (n)) == 0)

#define STRLEN(s)		((s) ? strlen(s) : 0)

#define MAX(x,y)                (((x) > (y)) ? (x) : (y))
#define MIN(x,y)                (((x) < (y)) ? (x) : (y))


Proto	(int,	bcmp, ());
Proto	(int,	bcopy, ());
Proto	(int,	bzero, ());
Proto	(int,	fflush, ());
Proto	(int,	tolower, ());

#ifndef DEC
Proto (int,     fprintf, ());
#endif

/*
 * case change macros copied from libdb30's dbselect.h
 */

#define UPPERCASE(s,l) { int i_; for (i_ = 0; i_ < l; i_++) s[i_]=toupper(s[i_]); }
#define LOWERCASE(s,l) { int i_; for (i_ = 0; i_ < l; i_++) s[i_]=tolower(s[i_]); }

#endif 	/* end _UTILITIES_H_ */
