slidescript/src/inc/x3basic.h

276 lines
11 KiB
C

/* ------------------------------------------------------------ */
/* file information */
/* ------------------------------------------------------------ */
// Filename: x3basic.h
// Purpose: UX3 basic definitions
// License: MIT/X. (c) OldCoder (Robert Kiraly) 1987-2021.
/* ------------------------------------------------------------ */
/* header file setup */
/* ------------------------------------------------------------ */
#ifndef _X3BASIC_H /* skip this file if loaded */
#define _X3BASIC_H 1 /* flag this file */
/* ------------------------------------------------------------ */
/* basic definitions */
/* ------------------------------------------------------------ */
#ifndef ZERO
#define ZERO 0
#endif // Endif ZERO
#ifndef ONE
#define ONE 1
#endif // Endif ONE
#ifndef FALSE
#define FALSE 0
#endif // Endif FALSE
#ifndef TRUE
#define TRUE 1
#endif // Endif TRUE
#ifndef CH_EOS
#define CH_EOS '\0'
#endif // Endif CH_EOS
#ifndef x3u_char
#define x3u_char unsigned char
#endif
#ifndef x3u_int
#define x3u_int unsigned int
#endif
#ifndef x3u_long
#define x3u_long unsigned long
#endif
#ifndef MODPRIV // Module-private
#define MODPRIV static
#endif // Endif MODPRIV
#ifndef MODPUB // Module-public
#define MODPUB
#endif // Endif MODPUB
#ifndef REG_VAR
#define REG_VAR
#endif // Endif NULL_PTR
/* ------------------------------------------------------------ */
/* "erase item" macro functions */
/* ------------------------------------------------------------ */
/* If "dp" is a data pointer (of any type) and "nb" is a short */
/* or long integer, "b_clr(dp,nb)" clears "nb" bytes to zero, */
/* starting with the first byte pointed to by "dp". */
/* Note: "nb" may use any integer data type, but the value of */
/* "nb" should fit into an unsigned integer. */
#define b_clr(dp,nb) \
{ \
REG_VAR char *cp = (char *) (dp); \
REG_VAR u_int x = (u_int) (nb); \
while (x-- > ZERO) *cp++ = CH_EOS; \
}
/* ------------------------------------------------------------ */
/* If "a[]" is an array, "a_clr(a)" clears the array (bytewise) */
/* to zero. "a[]" must be an array and not a pointer. The */
/* array must have a known fixed size. */
#define a_clr(a) b_clr ((char *) (&((a)[0])),sizeof(a))
/* ------------------------------------------------------------ */
/* If "p" is a pointer to a structure or variable, "p_clr(p)" */
/* clears the structure or variable. The pointer object must */
/* have a known fixed size. */
#define p_clr(p) b_clr ((char *) (p),sizeof(*p))
/* ------------------------------------------------------------ */
/* If "x" is a variable (and not an array), "v_clr(x)" clears */
/* the variable (bytewise) to zero. The variable must have a */
/* known fixed size. */
#define v_clr(x) b_clr ((char *) (&(x)),sizeof(x))
/* ------------------------------------------------------------ */
/* handle "void" data type */
/* ------------------------------------------------------------ */
/* The following five symbols provide a portable interface to */
/* the "void" data type. These five symbols are translated */
/* appropriately for systems which don't support the "void" */
/* type. */
/* (a) V_FUNC -- defines a void function */
/* (b) V_PROTO -- declares a void function */
/* (c) NO_PARAM -- void function parameter type */
/* (d) V_CAST -- void typecast */
/* (e) V_OBJ -- void pointer object */
/* ------------------------------------------------------------ */
/* V_FUNC may be used to declare a void function in the follow- */
/* ing context: */
/* */
/* V_FUNC function-definition(...) { ... } */
/* V_FUNC should not be used in function declarations or */
/* function prototypes. */
/* ------------------------------------------------------------ */
/* V_PROTO may be used to declare a void function in the */
/* following two contexts: */
/* */
/* V_PROTO function-declaration(); */
/* V_PROTO function-prototype(...); */
/* V_PROTO should not be used in function definitions. */
/* ------------------------------------------------------------ */
/* NO_PARAM may be used to declare a void function argument; */
/* for example, */
/* */
/* int foo(NO_PARAM) { ... } */
/* NO_PARAM may be used in function declarations, in function */
/* definitions, and in function prototypes. */
/* ------------------------------------------------------------ */
/* "V_OBJ *" translates into the appropriate void-pointer data */
/* type; for example, */
/* */
/* V_OBJ *malloc (argp1 (u_int)); */
/* ------------------------------------------------------------ */
/* V_CAST translates into a "void" typecast; for example, */
/* */
/* char *strcpy (argp2(char *,char *)); */
/* V_CAST strcpy (s,t); */
/* ------------------------------------------------------------ */
/* if "void" is not supported */
#ifdef NO_VOID /* "void" type is not supported */
#define NO_PARAM /* void parameter type (empty) */
#define V_CAST /* void typecast (no effect) */
#define V_FUNC /* void function definition */
#define V_OBJ char /* void pointer object */
#define V_PROTO extern /* void function declaration */
#endif /* endif "void not supported" */
/* ------------------------------------------------------------ */
/* if "void" is supported */
#ifndef NO_VOID /* "void" type is supported */
#ifdef NO_PROTO /* prototypes are not supported */
#define NO_PARAM /* void parameter type (empty) */
#else /* prototypes are supported */
#define NO_PARAM void /* void parameter type */
#endif /* endif NO_PARAM */
#endif /* endif "void is supported" */
#ifndef NO_VOID /* "void" type is supported */
#define V_CAST (void) /* void typecast */
#define V_FUNC void /* void function definition */
#define V_OBJ void /* void pointer object */
#define V_PROTO void /* void function declaration */
#endif /* endif "void is supported" */
/* ------------------------------------------------------------ */
/* ANSI prototype setup */
/* ------------------------------------------------------------ */
/* The following "argp#(...)" macros may be used in ANSI */
/* function prototypes. "#" should be replaced with the number */
/* of function arguments; e.g.: */
/* */
/* V_OBJ *malloc (argp1(u_int)); */
/* char *strcpy (argp2(char *,char *)); */
/* The "argp#(...)" macros discard their arguments on systems */
/* which do not support ANSI prototypes. */
/* The "ellipse" construct "..." counts as one argument. */
/* ------------------------------------------------------------ */
#ifdef NO_PROTO
#define argp0()
#define argp1(a)
#define argp2(a,b)
#define argp3(a,b,c)
#define argp4(a,b,c,d)
#define argp5(a,b,c,d,e)
#define argp6(a,b,c,d,e,f)
#define argp7(a,b,c,d,e,f,g)
#define argp8(a,b,c,d,e,f,g,h)
#define argp9(a,b,c,d,e,f,g,h,i)
#else
#define argp0() NO_PARAM
#define argp1(a) a
#define argp2(a,b) a,b
#define argp3(a,b,c) a,b,c
#define argp4(a,b,c,d) a,b,c,d
#define argp5(a,b,c,d,e) a,b,c,d,e
#define argp6(a,b,c,d,e,f) a,b,c,d,e,f
#define argp7(a,b,c,d,e,f,g) a,b,c,d,e,f,g
#define argp8(a,b,c,d,e,f,g,h) a,b,c,d,e,f,g,h
#define argp9(a,b,c,d,e,f,g,h,i) a,b,c,d,e,f,g,h,i
#endif
/* ------------------------------------------------------------ */
/* null pointers of various types */
/* ------------------------------------------------------------ */
/* Note: NULLXP is a null function pointer. */
#ifndef NULLXP
#define NULL_PTR ((void *) ZERO)
#define NULLCP ((char *) ZERO)
#define NULLFP ((FILE *) ZERO)
#define NULLVP ((V_OBJ *) ZERO)
#define NULLXP ((int (*)()) ZERO)
#endif // Endif NULLXP
/* ------------------------------------------------------------ */
/* resolve global variables */
/* ------------------------------------------------------------ */
#ifdef RES_UX3 /* resolve external variables? */
#define UX3_EXT /* yes */
#else /* no */
#define UX3_EXT extern /* variables are externals */
#endif
#ifdef VMS /* VMS host */
#undef UX3_EXT
#ifdef RES_UX3 /* resolve externals? */
#define UX3_EXT globaldef
#else /* don't resolve externals */
#define UX3_EXT globalref
#endif /* endif RES_UX3 */
#endif /* endif VMS */
/* ------------------------------------------------------------ */
/* wrap it up */
/* ------------------------------------------------------------ */
#endif // Endif _X3BASIC_H