/*
 * utils.h - header file for utils.c
 *
 * Author: John DiMarco, University of Toronto, CSLab
 *         jdd@cs.toronto.edu
 */

/* 
 * $Id: utils.h,v 1.1 1998/03/27 15:48:10 jdd Exp $
 */

#ifndef __utils_h
#define __utils_h

#include <sys/syslog.h>

/* new - mallocs any sized type */
#ifndef lint
#define new(t) (t *)mylib_malloc(sizeof(t),__FILE__,__LINE__)
#else
#define new(t) (t *)NULL
#endif

/* mem - mallocs a given number of bytes */
#define mem(l) mylib_malloc((unsigned)l,__FILE__,__LINE__)

/* rmem - reallocs a given number of bytes */
#define rmem(c,l) mylib_realloc(c,(unsigned)l,__FILE__,__LINE__)

/* s - returns a copy of a given string */
#define s(c) mylib_scopy(c,__FILE__,__LINE__)

/* rs - returns a copy of the second string in place of the first string, 
        using realloc */
#define rs(c,d) mylib_srcopy(c,strlen(d),__FILE__,__LINE__)

/* assert - error message if statement is false */
#ifdef DEBUG
#define assert(c) if(!(c))(void)fprintf(stderr,"%s: %d: Assert false\n",__FILE__,__LINE__)
#else
#define assert(c) 0
#endif

/* STREQ - indicate whether two strings are equal */
#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)

#define loop for(;;)
#define NUL(x) (x)NULL
#ifndef TRUE
#define TRUE 1 
#endif
#ifndef FALSE
#define FALSE 0 
#endif
#define YES 1
#define NO 0

/* Error - print like fprintf(stderr, ...) and die. Progname included at
	   beginning of message, newline at end. */
extern void Error();
/* Warning - like error, without dying */
extern void Warning();

#define LOG_FILE -1
#define LOG_STDOUT -2
#define LOG_STDERR -3

#ifndef LOG_PID
#define LOG_PID 0x01
#endif /* LOG_PID */

extern char *mylib_malloc();   
extern char *mylib_realloc();
extern char *mylib_scopy();
extern char *mylib_srcopy();
extern char *cat();
extern char *getstr();
extern FILE *efopen();
extern void efclose();
extern void dfprintf();
extern int writeline();
extern char *readline();
extern void setlog();
extern void logmsg();
extern char *strsubst();

extern char *progname; /* application's name. Used by Error, Warning. */
extern int d; /* debug level */

#endif /* __utils_h */
