/*******************************************************************************
* YORKTOWN ADVANCED SGML PARSER (YASP)                                         *
*         An SGML Parser conforming to International Standard ISO 8879 --      *
*         Standard Generalized Markup Language                                 *
*------------------------------------------------------------------------------*
* Written 1987 - 1993 by                                                       *
*         Pierre G. Richard                                                    *
*         IBM T.J. Watson Research Center                                      *
*         Yorktown Heights, New York                                           *
*         petrus@watson.ibm.com                                                *
*------------------------------------------------------------------------------*
* FUNCTION NAME    = YASP / Header File                                        *
* STATUS           = Version 0, Release 1, Level 34 and up                     *
* COMPONENT NAME   = portable.h                                                *
* DESCRIPTIVE NAME = Portability between systems                               *
* DATE_WR          = 02/01/1987                                                *
* AUTHOR           = Pierre G. Richard - PETRUS at YKTVMX                      *
*                                                                              *
* FUNCTIONAL DESCRIPTION =                                                     *
* These definitions to insure portability  (PC/DOS, IBM 370, AIX, UNIX, NT)    *
*                                                                              *
* Despite the portable way modules are written, it is sometimes necessary to   *
* take into account the peculiarities inherent to a given system and compiler: *
* bugs are one of those!  Therefore, source codes have a few specific          *
* pre-processor conditional statements.  They are activated by #DEFINEing      *
* a couple of system/compiler keywords taken in the following list:            *
*                                                                              *
*  System         =>      Compilers:                Original Include file in:  *
*                                                                              *
*  DOS_SYS                C2_00 | C6_00             machine0 (-D)              *
*  OS2V1_SYS              C2_00 | C6_00             machine0 (-D)              *
*  OS2V2_SYS              IBMCSET2                  machine0 (-D)              *
*  CMS_SYS                WATC | IBMC370            machine1 machine2          *
*  MVS_SYS                WATC | IBMC370            machine3 machine4          *
*  AIX_SYS                IBMCAIX | SUNACC | GNUCC  machine0 (-D)              *
*  NT_SYS                 MSVC                      machine0 (-D)              *
*                                                                              *
* The file machine.h is always included before portable.h.  Therefore,         *
* one way is to create a file with the required #DEFINE's and copy it to       *
* machine.h.   Or use the -D compiler option on the invocation command line.   *
*                                                                              *
* CHANGE HISTORY =                                                             *
*+------+--------+--------+---------------------------------------------------+*
*|Number|Date    |Inits   |Change & Reason (brief)                            |*
*+------+--------+--------+---------------------------------------------------+*
*|     1|05/31/90|PETRUS  |Only ANSI Compilers are now allowed                |*
*|     2|09/28/90|PETRUS  |IBM C 370 added (SAA compiler)                     |*
*|     3|09/30/91|PETRUS  |Microsoft C6.00 added                              |*
*|     4|12/20/91|PETRUS  |IBM C/Set2 added                                   |*
*|     5|03/06/92|PETRUS  |Added diffptr for 16-bit machines                  |*
*|     6|07/24/92|PETRUS  |Sun Ansi compiler added                            |*
*|     7|08/08/96|ESPERT  |Windows NT platforms with VC++                     |*
*+------+--------+--------+---------------------------------------------------+*
*******************************************************************************/

/*----------------------------+
| Check Systems and Compilers |
+----------------------------*/
#if defined(DOS_SYS)
#if !defined(C2_00) && !defined(C6_00)
#error Unknown or Incompatible compiler
#endif

#elif defined(OS2V1_SYS)
#if !defined(C2_00) && !defined(C6_00)
#error Unknown or Incompatible compiler
#endif

#elif defined(OS2V2_SYS)
#if !defined(IBMCSET2)
#error Unknown or Incompatible compiler
#endif

#elif defined(NT_SYS)
#if !defined(MSVC)
#error Unknown or Incompatible compiler
#endif

#elif defined(CMS_SYS)
#if !defined(WATC) && !defined(IBMC370)
#error Unknown or Incompatible compiler
#endif

#elif defined(MVS_SYS)
#if !defined(WATC) && !defined(IBMC370)
#error Unknown or Incompatible compiler
#endif

#elif defined(AIX_SYS)
#if !defined(IBMCAIX) && !defined(SUNACC) && !defined(GNUCC)
#error Unknown or Incompatible compiler
#endif

#else
#error Unknown System
#endif


/*------------+
| IBM C2 V1.0 |
+------------*/
#if (defined(C2_00))

#define LINT_ARGS               /* to force prototyping on libraries */
#define P_FCT  pascal           /* Allow a pascal call/return prototype */
#define C_FCT  cdecl
#define const                   /* Bad handling of const */
#define YASP_API

/* COMPACT or LARGE or HUGE have FAR Data */
#if (defined(M_I86SM) || defined(M_I86MM))
#define FAR_D far               /* allow some far data */
#define NEAR_D                  /* disable near data */
#define STACK_BASED             /* disable data based on the stack */
#else                           /* COMPACT, LARGE of HUGE */
#define LARGE_DATA
#define FAR_D                   /* disable far data */
#define NEAR_D near             /* allow some near data */
#define STACK_BASED near        /* allow data based on the stack */
#endif

/* MEDIUM or LARGE or HUGE have FAR CODE */
#if (defined(M_I86SM) || defined(M_I86CM))
#define FAR_C far               /* allow some far code */
#define NEAR_C                  /* disable near code */
#else                           /* MEDIUM, LARGE, or HUGE */
#define LARGE_CODE
#define FAR_C                   /* disable far code */
#define NEAR_C near             /* allow some near code */
#endif

/* allow the difference of pointers in arrays larger than 32K */
#define diffptr(p, q) \
((int)(((*((unsigned far *)&(p)))-(*((unsigned far *)&(q)))) / sizeof(*(q))))

/*----------------+
| Microsoft C6.00 |
+----------------*/
#elif (defined(C6_00))

#define LINT_ARGS               /* to force prototyping on libraries */
#define P_FCT  pascal           /* Allow a pascal call/return prototype */
#define C_FCT  cdecl
#define const                   /* Bad handling of const */
#define YASP_API

/* COMPACT or LARGE or HUGE have FAR Data */
#if (defined(M_I86SM) || defined(M_I86MM))
#define FAR_D _far              /* allow some far data */
#define NEAR_D                  /* disable near data */
#define STACK_BASED             /* disable data based on the stack */
#else                           /* COMPACT, LARGE of HUGE */
#define LARGE_DATA
#define FAR_D                   /* disable far data */
#define NEAR_D near             /* allow some near data */
#define STACK_BASED _based(_segname("_STACK")) /* allow data stack based */
#endif

/* MEDIUM or LARGE or HUGE have FAR CODE */
#if (defined(M_I86SM) || defined(M_I86CM))
#define FAR_C _far              /* allow some far code */
#define NEAR_C                  /* disable near code */
#else                           /* MEDIUM, LARGE, or HUGE */
#define LARGE_CODE
#define FAR_C                   /* disable far code */
#define NEAR_C near             /* allow some near code */
#endif

/* allow the difference of pointers in arrays larger than 32K */
#define diffptr(p, q) \
((int)(((*((unsigned _far *)&(p)))-(*((unsigned _far *)&(q)))) / sizeof(*(q))))

/*------------+
| MSVC for NT |
+------------*/
#elif (defined(MSVC))
#define STACK_BASED
#define P_FCT
#define C_FCT
#define NEAR_C
#define NEAR_D
#define FAR_C
#define FAR_D
#define _loadds
#define const
#define diffptr(p, q)  ((p) - (q))
#define YASP_API __declspec(dllexport)

/*--------------+
| IBM C for 386 |
+--------------*/
#elif (defined(IBMCSET2))

#define _loadds                 /* Disable load_ds (32 bits) */
#define FAR_C                   /* FAR and NEAR disabled */
#define FAR_D
#define NEAR_C
#define NEAR_D
#define STACK_BASED
#define LARGE_DATA
#define LARGE_CODE
#define P_FCT
#define C_FCT
#define diffptr(p, q)  ((p) - (q))
#pragma strings (readonly)
#define YASP_API

/*-----------------------+
| IBM C for AIX (xlc) or |
| SUN Ansi C for (acc)   |
| GNU CC (2.4.5 or up)   |
+-----------------------*/
#elif (defined(IBMCAIX) || defined(SUNACC) || defined(GNUCC))

#define _loadds                 /* Disable load_ds (no DLL) */
#define FAR_C                   /* FAR and NEAR disabled */
#define FAR_D
#define NEAR_C
#define NEAR_D
#define STACK_BASED
#define LARGE_DATA
#define LARGE_CODE
#define P_FCT
#define C_FCT
#define diffptr(p, q)  ((p) - (q))
#define YASP_API

/*-------------------+
| WATERLOO C for 370 |
+-------------------*/
#elif (defined(WATC))

#define const                   /* Bad handling of const */
#define _loadds                 /* Disable load_ds (no DLL) */
#define FAR_C                   /* FAR and NEAR disabled */
#define FAR_D
#define NEAR_C
#define NEAR_D
#define STACK_BASED
#define LARGE_DATA
#define LARGE_CODE
#define P_FCT
#define C_FCT
#define diffptr(p, q)  ((p) - (q))
#define YASP_API

/*--------------+
| IBM C for 370 |
+--------------*/
#elif (defined(IBMC370))

#define _loadds                 /* Disable load_ds (no DLL) */
#define FAR_C                   /* FAR and NEAR disabled */
#define FAR_D
#define NEAR_C
#define NEAR_D
#define STACK_BASED
#define LARGE_DATA
#define LARGE_CODE
#define P_FCT
#define C_FCT
#define diffptr(p, q)  ((p) - (q))
#define YASP_API

/*-----------------+
| Unknown Compiler |
+-----------------*/
#else
#error Unknown Compiler

#endif

#include <stddef.h>
#include <stdarg.h>

/*-----------------------------------------------------------------------------+
|Macros to work with boolean bit(s) in flags.                                  |
+-----------------------------------------------------------------------------*/
#define IS_BITON(i,selec)        ((i) & (selec))
#define SET_BITOFF(i,selec)      i &= ~(selec)
#define SET_BITON(i,selec)       i |=  (selec)

/*-----------------------------------------------------------------------------+
|   general typedefs                                                           |
+-----------------------------------------------------------------------------*/
typedef unsigned char  uchar;
typedef unsigned short ushort;
typedef unsigned int   uint;
typedef unsigned long  ulong;
typedef unsigned char  boolean;
#define LP_FCT P_FCT NEAR_C

/*-----------------------------------------------------------------------------+
|   general constants                                                          |
+-----------------------------------------------------------------------------*/
#define TRUE   (boolean)1
#define FALSE  (boolean)0

#define YASP_PARSER_CODE          /* Recognize myself */

/******************************************************************************/
