/* @(#)defs.h	1.5 06/06/26 Copyright 1985 J. Schilling */
/*
 *	Copyright (c) 1985 J. Schilling
 */
/*
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * See the file CDDL.Schily.txt in this distribution for details.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file CDDL.Schily.txt from this distribution.
 */

#ifndef	_DEFS_H
#define	_DEFS_H

#ifdef FILE
typedef FILE *file;
#else
typedef int file;
#endif
typedef int		file_desc;
typedef unsigned char	byte;
typedef unsigned short	word;
typedef char		*string;
#ifndef STYPEDEF
typedef char		*pointer;
#endif
typedef char		*buffer;
typedef char		**vector;
typedef int		(*function)();
typedef short		(*sfunc)();
typedef char		(*cfunc)();
typedef long		(*lfunc)();
typedef pointer		(*pfunc)();
typedef function	*dispatch;
typedef union  {
		char		_c;
		short		_s;
		long		_l;
		pointer		_p;
		function	_f;
		} any;

#define	true	1
#define	false	0
#define	not	!
#define	SUCCESS	0
#define	ERROR  (-1)

#define	null(n) ((n) == NULL)
#define	negotive(n) ((n) < 0)
#define	negative(n) ((n) < 0)

#define	forever		for (;;)
#define	iter(i, max)	for (i = 0; i < max; i++)
#define	begin	{
#define	end	}
#define	elif	else if

#define	isnull(n)	((n) == NULL)
#define	abs(x)		((x < 0) ? -(x) : (x))
#define	max(x, y)	(((x) < (y)) ? (y) : (x))
#define	min(x, y)	(((x) < (y)) ? (x) : (y))

#define	isoctal(c)	('0' <= (c) && (c) <= '7')
#define	ishex(c)	(('a' <= (c) && (c) <= 'f')||('A' <= (c) &&(c) <= 'F'))
#define	iswhite(c)	((c) == ' ' || (c) == '\t' || (c) == '\n')
#ifndef	isalpha
#	define	isalpha(c)	(islower(c) || isupper(c))
#	define	isdigit(c)	('0' <= (c) && (c) <= '9')
#	define	islower(c)	('a' <= (c) && (c) <= 'z')
#	define	isupper(c)	('A' <= (c) && (c) <= 'Z')
#	define	tolower(c)	(isupper(c) ? ((c) + ('a' - 'A')) : (c))
#	define	toupper(c)	(islower(c) ? ((c) - ('a' - 'A')) : (c))
#endif

/* extern int _fillbuf(); */
/*
 *	special "defined" routines
 */
#define	allocate(dest, amnt, fail)\
		if (null(dest = alloc(amnt, 0))) {\
			fprintf(stderr, "PANIC - allocation failure");\
			fail;\
		}
#define	openfile(dest, fil, mode, fail)\
		if (null(dest = fileopen(fil, mode))) {\
			fprintf(stderr, "cannot open file %s\n", fil);\
			fail;\
		}
#define	on(s, b)\
		allocate(_j, sizeof (jumpinfo), exit(0));\
		handle(s, &b, onhandle, (long)_j);\
		if (not setjmp(_j))

#endif	/* _DEFS_H */
