/* This software is distributed under the Lesser General Public License */
/* (C) Universitaet Passau 1986-1994 */
/* Sgraph Source, 1988-1994 by Michael Himsolt */

#ifndef STD
#define STD

/*
#define SGRAPH_STANDALONE
*/

#ifdef SGRAPH_STANDALONE
#undef GRAPHED
#endif


#include <assert.h>
#include <stdio.h>
#ifndef __GNUC__
#ifndef MALLOC_HEADER
#define MALLOC_HEADER
#include <malloc.h>
#endif
#else
#include <malloc.h>
#endif

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923
#endif

#ifndef nil
#define	nil	NULL
#endif

#ifndef TRUE
#define TRUE	(0==0)
#endif
#ifndef FALSE
#define	FALSE	(0==1)
#endif

#if !defined(__cpluscplus) && !defined(true)
#define	true	TRUE
#endif

#if !defined(__cpluscplus) && !defined(false)
#define	false	FALSE
#endif

#ifndef iif
#define	iif(b,e1,e2)	((b) ? (e1) : (e2))
#endif
#ifndef maximum
#define	maximum(x,y)	iif ((x) > (y), (x), (y))
#endif
#ifndef minimum
#define	minimum(x,y)	iif ((x) < (y), (x), (y))
#endif

#if !defined(__cplusplus) && !defined(bool)
#define	bool	int
#endif

#ifndef Local
#define	Local	static
#endif

#ifndef Global
#define	Global
#endif

typedef	void (*Pointer_to_procedure)();

typedef	struct	attributes {
    /*	char	*key; */
    union	{
	int	integer;
	char	*data;
    }
    value;
}
Attributes;

#define	attr_flags(x)		((x)->attrs.value.integer)
#define	attr_int(x)		((x)->attrs.value.integer)
#define	attr_data(x)		((x)->attrs.value.data)
#define	attr_data_of_type(x,t)	((t)attr_data(x))
#define	set_attr_data(x, v)	(attr_data(x)=(char*)v)

#if FALSE
#define attr_key(x)		((x)->attrs.key)
#endif

typedef	enum {
    ATTR_INTEGER,
    ATTR_DATA
#if FALSE
    /* The following two are unused ... */
    ,ATTR_KEY_INTEGER,
    ATTR_KEY_DATA
#endif
}
Attributes_type;

#define ATTR_FLAGS ATTR_INTEGER

extern	Attributes	make_attr (Attributes_type attr_type, ...);

extern	char	*strsave(char *s);
extern	char	*strnsave(char *s, int len);

#ifndef GRAPHED
#ifndef SGRAPH_STANDALONE
extern	char	*mymalloc (unsigned int size);
extern	char	*mycalloc (unsigned int n, unsigned int size);
extern	void	myfree   (); /* no parameter due to mixed pointer types */

#endif
#endif

#ifdef SGRAPH_STANDALONE
#define mymalloc(s)   malloc(s)
#define mycalloc(n,s) calloc((n),(s))
#define myfree(s)     free(s)
#endif

#endif
