/***** do not edit -- this file was generated mechanically *****/



/****************************************  from ../h/rt.h:  */

#ifndef RT_DOT_H	/* only include once */
#define RT_DOT_H 1

/*
 * Include files.
 */



/****************************************  from ../h/define.h:  */

#define Config "bsd, pthreads.c"
#define Graphics 1
#define CoClean

/*
 * Icon configuration file for BSD
 */

#define UNIX 1
#define LoadFunc

#define CComp "gcc"
#define COpts "-O2 -I/usr/X11R6/include"
#define ICONC_XLIB "-L/usr/X11R6/lib -lX11"

/****************************************   end ../h/define.h   */


/****************************************  from ../h/arch.h:  */

/* generated by infer.c */
#define IntBits 32
#define WordBits 64

/****************************************   end ../h/arch.h   */


/****************************************  from ../h/config.h:  */

/*
 * Icon configuration.
 */

/*
 * System-specific definitions are in define.h, which is loaded first.
 */

/*
 *  A number of symbols are defined here.
 *  Some enable or disable certain Icon features, for example:
 *	NoCoexpr	disables co-expressions
 *	LoadFunc	enables dynamic loading
 *
 *  Other definitions may occur for different configurations. These include:
 *	DeBug		debugging code
 *	MultiThread	support for multiple programs under the interpreter
 *
 *  Many definitions reflect remnants of past research projects.
 *  Changing them to values not used in standard configurations
 *  may result in an unbuildable or nonfunctioning system.
 */

/*
 * If COMPILER is not defined, code for the interpreter is compiled.
 */

#ifndef COMPILER
   #define COMPILER 0
#endif

/*
 * The following definitions serve to cast common conditionals is
 *  a positive way, while allowing defaults for the cases that
 *  occur most frequently.  That is, if co-expressions are not supported,
 *  NoCoexpr is defined in define.h, but if they are supported, no
 *  definition is needed in define.h; nonetheless subsequent conditionals
 *  can be cast as #ifdef Coexpr.
 */

#ifndef NoCoexpr
   #undef Coexpr
   #define Coexpr
#endif					/* NoCoexpr */

#ifdef NoCoexpr
   #undef MultiThread
   #undef EventMon
   #undef Eve
#endif					/* NoCoexpr */

#if COMPILER
   #undef Eve
   #undef MultiThread
   #undef EventMon
#endif					/* COMPILER */

#ifdef Eve
   #undef EventMon
   #undef MultiThread
   #define EventMon
   #define MultiThread
#endif					/* Eve */

#ifndef NoLargeInts
   #undef LargeInts
   #define LargeInts
#endif					/* NoLargeInts */

#ifdef EventMon
   #undef MultiThread
   #define MultiThread
#endif					/* EventMon */

/*
 * Graphics definitions.
 */
#ifdef Graphics

   #ifndef XWindows
      #ifdef MSWIN
         #undef WinGraphics
         #define WinGraphics 1
      #else				/* Graphics */
         #define XWindows 1
      #endif				/* Graphics */
   #endif				/* XWindows */

   #ifndef NoXpmFormat
      #ifdef XWindows
         #undef HaveXpmFormat
         #define HaveXpmFormat
      #endif				/* XWindows */
   #endif				/* NoXpmFormat */

   #undef LineCodes
   #define LineCodes

   #undef Polling
   #define Polling

   #ifndef ICONC_XLIB
      #ifdef WinGraphics
         #define ICONC_XLIB "-luser32 -lgdi32 -lcomdlg32 -lwinmm"
      #else				/* WinGraphics */
         #define ICONC_XLIB "-L/usr/X11R6/lib -lX11"
      #endif				/* WinGraphics */
   #endif				/* ICONC_XLIB */

#endif					/* Graphics */

/*
 * Data sizes and alignment.
 */

#define WordSize sizeof(word)

#ifndef StackAlign
   #define StackAlign 8
#endif					/* StackAlign */

/*
 * Other defaults.
 */

#ifdef DeBug
   #undef DeBugTrans
   #undef DeBugLinker
   #undef DeBugIconx
   #define DeBugTrans
   #define DeBugLinker
   #define DeBugIconx
#endif					/* DeBug */

#ifndef MaxHdr
   /*
    * Maximum allowable BinaryHeader size.
    * WARNING: changing this invalidates old BinaryHeader executables.
    */
   #define MaxHdr 8192
#endif					/* MaxHdr */

#ifndef MaxPath
   #define MaxPath 256
#endif					/* MaxPath */

#ifndef SourceSuffix
   #define SourceSuffix ".icn"
#endif					/* SourceSuffix */

/*
 * Representations of directories. LocalDir is the "current working directory".
 *  SourceDir is where the source file is.
 */

#define LocalDir ""
#define SourceDir (char *)NULL

#ifndef TargetDir
   #define TargetDir LocalDir
#endif					/* TargetDir */

/*
 * Features enabled by default.
 */
#ifndef NoPipes
   #define Pipes
#endif					/* Pipes */

#ifndef NoKeyboardFncs
   #define KeyboardFncs
#endif					/* KeyboardFncs */

#ifndef NoReadDirectory
   #define ReadDirectory
#endif					/* ReadDirectory */

#ifndef NoSysOpt
   #define SysOpt
#endif					/* SysOpt */

/*
 *  The following definitions assume ANSI C.
 */
#define Cat(x,y) x##y
#define Lit(x) #x
#define Bell '\a'

/*
 * Miscellaney.
 */

#ifndef DiffPtrs
   #define DiffPtrs(p1,p2) (word)((p1)-(p2))
#endif					/* DiffPtrs */

#ifndef AllocReg
   #define AllocReg(n) malloc(n)
#endif					/* AllocReg */

#ifndef RttSuffix
   #define RttSuffix ".r"
#endif					/* RttSuffix */

#ifndef DBSuffix
   #define DBSuffix ".db"
#endif					/* DBSuffix */

#ifndef PPInit
   #define PPInit ""
#endif					/* PPInit */

#ifndef PPDirectives
   #define PPDirectives {"passthru", PpKeep},
#endif					/* PPDirectives */

#ifndef NoSrcColumnInfo
   #define SrcColumnInfo
#endif					/* NoSrcColumnInfo */

#ifndef ExecSuffix
   #define ExecSuffix ""
#endif					/* ExecSuffix */

#ifndef CSuffix
   #define CSuffix ".c"
#endif					/* CSuffix */

#ifndef HSuffix
   #define HSuffix ".h"
#endif					/* HSuffix */

#ifndef ObjSuffix
   #define ObjSuffix ".o"
#endif					/* ObjSuffix */

#ifndef LibSuffix
   #define LibSuffix ".a"
#endif					/* LibSuffix */

#ifndef CComp
   #define CComp "cc"
#endif					/* CComp */

#ifndef COpts
   #define COpts ""
#endif					/* COpts */

/*
 * Note, size of the hash table is a power of 2:
 */
#define IHSize 128
#define IHasher(x)	(((unsigned int)(unsigned long)(x))&(IHSize-1))

#if COMPILER

   /*
    * Code for the compiler.
    */
   #undef MultiThread		/* no way -- interpreter only */
   #undef EventMon		/* presently not supported in the compiler */

#else					/* COMPILER */

   /*
    * Code for the interpreter.
    */
   #ifndef IcodeSuffix
      #define IcodeSuffix ""
   #endif				/* IcodeSuffix */

   #ifndef IcodeASuffix
      #define IcodeASuffix ""
   #endif				/* IcodeASuffix */

   #ifndef U1Suffix
      #define U1Suffix ".u1"
   #endif				/* U1Suffix */

   #ifndef U2Suffix
      #define U2Suffix ".u2"
   #endif				/* U2Suffix */

   #ifndef USuffix
      #define USuffix ".u"
   #endif				/* USuffix */

#endif					/* COMPILER */

/*
 *  Vsizeof is for use with variable-sized (i.e., indefinite)
 *   structures containing an array of descriptors declared of size 1
 *   to avoid compiler warnings associated with 0-sized arrays.
 */

#define Vsizeof(s)	(sizeof(s) - sizeof(struct descrip))

/*
 * Other sizeof macros:
 *
 *  Wsizeof(x)	-- Size of x in words.
 *  Vwsizeof(x) -- Size of x in words, minus the size of a descriptor.	Used
 *   when structures have a potentially null list of descriptors
 *   at their end.
 */

#define Wsizeof(x)	((sizeof(x) + sizeof(word) - 1) / sizeof(word))
#define Vwsizeof(x) \
   ((sizeof(x) - sizeof(struct descrip) + sizeof(word) - 1) / sizeof(word))

/****************************************   end ../h/config.h   */


/****************************************  from ../h/sys.h:  */

/*
 * sys.h -- system include files.
 */

/*
 * Universal (Standard 1989 ANSI C) includes.
 */
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

/*
 * POSIX (1003.1-1996) includes.
 */
#include <dirent.h>
#include <fcntl.h>
#include <grp.h>
#include <pwd.h>
#include <termios.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
#include <sys/utsname.h>

/*
 * Operating-system-dependent includes.
 */
#if MSWIN
   #include <windows.h>
   #include <sys/cygwin.h>
   #include <sys/select.h>
   
   #ifdef WinGraphics
      #define int_PASCAL int PASCAL
      #define LRESULT_CALLBACK LRESULT CALLBACK
      #define BOOL_CALLBACK BOOL CALLBACK
      #include <mmsystem.h>
      #include <process.h>


/****************************************  from ../wincap/dibutil.h:  */

/*
 *  dibutil.h
 *
 *  Copyright (c) 1991 Microsoft Corporation. All rights reserved.
 *
 *  Header file for Device-Independent Bitmap (DIB) API.  Provides
 *  function prototypes and constants for the following functions:
 *
 *  FindDIBBits()		- Sets pointer to the DIB bits
 *  DIBWidth()			- Gets the DIB width
 *  DIBHeight()			- Gets the DIB height
 *  DIBNumColors()		- Calculates number of colors in the DIB's color table
 *  PaletteSize()		- Calculates the buffer size required by a palette
 *  CreateDIBPalette()	- Creates a palette from a DIB
 *  DIBToBitmap()		- Creates a bitmap from a DIB
 *  BitmapToDIB()		- Creates a DIB from a bitmap
 *  PalEntriesOnDevice()- Gets the number of palette entries
 *  GetSystemPalette()	- Gets the current palette
 *
 */


/****************************************  from ../wincap/dibapi.h:  */

/*
 *  dibapi.h
 *
 *  Copyright (c) 1991 Microsoft Corporation. All rights reserved
 *
 *  Header file for Device-Independent Bitmap (DIB) API.  Provides
 *  function prototypes and constants for the following functions:
 *
 *  PrintWindow()       - Prints all or part of a window
 *  PrintScreen()       - Prints the entire screen
 *  CopyWindowToDIB()   - Copies a window to a DIB
 *  CopyScreenToDIB()   - Copies entire screen to a DIB
 *  CopyWindowToBitmap()- Copies a window to a standard Bitmap
 *  CopyScreenToBitmap()- Copies entire screen to a standard Bitmap
 *  PrintDIB()          - Prints the specified DIB
 *  SaveDIB()           - Saves the specified dib in a file
 *  LoadDIB()           - Loads a DIB from a file
 *  DestroyDIB()        - Deletes DIB when finished using it
 *
 * See the file DIBAPI.TXT for more information about these functions.
 *
 */

/* Handle to a DIB */
#define HDIB HANDLE

/* Print Area selection */
#define PW_WINDOW        1
#define PW_CLIENT        2

/* Print Options selection */
#define PW_BESTFIT       1
#define PW_STRETCHTOPAGE 2
#define PW_SCALE         3

/* Function prototypes */
WORD    PrintWindow(HWND, WORD, WORD, WORD, WORD, LPSTR);
WORD    PrintScreen(LPRECT, WORD, WORD, WORD, LPSTR);
HDIB   	CopyWindowToDIB(HWND, WORD);
HDIB   	CopyScreenToDIB(LPRECT);
HBITMAP	CopyWindowToBitmap(HWND, WORD);
HBITMAP	CopyScreenToBitmap(LPRECT);
WORD    PrintDIB(HDIB, WORD, WORD, WORD, LPSTR);
WORD   	SaveDIB(HDIB, LPSTR);
HDIB   	LoadDIB(LPSTR);
WORD   	DestroyDIB(HDIB);

/****************************************   end ../wincap/dibapi.h   */

/* DIB constants */
#define PALVERSION   0x300

/* DIB macros */
#define WIDTHBYTES(bits)	(((bits) + 31) / 32 * 4)
#define IS_WIN30_DIB(lpbi)  ((*(LPDWORD)(lpbi)) == sizeof(BITMAPINFOHEADER))

/* function prototypes */
LPSTR    	FindDIBBits(LPSTR lpbi);
DWORD		DIBWidth(LPSTR lpDIB);
DWORD		DIBHeight(LPSTR lpDIB);
WORD     	DIBNumColors(LPSTR lpbi);
WORD     	PaletteSize(LPSTR lpbi);
HPALETTE 	CreateDIBPalette(HDIB hDIB);
HBITMAP  	DIBToBitmap(HDIB hDIB, HPALETTE hPal);
HDIB     	BitmapToDIB(HBITMAP hBitmap, HPALETTE hPal);
int			PalEntriesOnDevice(HDC hDC);
HPALETTE 	GetSystemPalette(void);

/****************************************   end ../wincap/dibutil.h   */
   #endif				/* WinGraphics */

   #undef Type
   #undef lst1
   #undef lst2
#endif					/* MSWIN */

/*
 * Window-system-dependent includes.
 */
#ifdef XWindows
   #ifdef HaveXpmFormat


/****************************************  from ../xpm/xpm.h:  */

/* Copyright 1990-92 GROUPE BULL -- See license conditions in file COPYRIGHT */
/*****************************************************************************\
* xpm.h:                                                                      *
*                                                                             *
*  XPM library                                                                *
*  Include file                                                               *
*                                                                             *
*  Developed by Arnaud Le Hors                                                *
\*****************************************************************************/

#ifndef XPM_h
#define XPM_h

#ifdef VMS


/****************************************  from decw$include:Xlib.h:  */

/* [file not found] */

/****************************************   end decw$include:Xlib.h   */


/****************************************  from decw$include:Intrinsic.h:  */

/* [file not found] */

/****************************************   end decw$include:Intrinsic.h   */


/****************************************  from sys$library:stdio.h:  */

/* [file not found] */

/****************************************   end sys$library:stdio.h   */
#else
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#endif

/* we keep the same codes as for Bitmap management */
#ifndef _XUTIL_H_
#ifdef VMS


/****************************************  from decw$include:Xutil.h:  */

/* [file not found] */

/****************************************   end decw$include:Xutil.h   */
#else
#include <X11/Xutil.h>
#endif
#endif

/* Return ErrorStatus codes:
 * null     if full success
 * positive if partial success
 * negative if failure
 */

#define XpmColorError    1
#define XpmSuccess       0
#define XpmOpenFailed   -1
#define XpmFileInvalid  -2
#define XpmNoMemory     -3
#define XpmColorFailed  -4


typedef struct {
    char *name;				/* Symbolic color name */
    char *value;			/* Color value */
    Pixel pixel;			/* Color pixel */
}      XpmColorSymbol;

typedef struct {
    char *name;				/* name of the extension */
    unsigned int nlines;		/* number of lines in this extension */
    char **lines;			/* pointer to the extension array of 
					   strings */
}      XpmExtension;

typedef struct {
    unsigned long valuemask;		/* Specifies which attributes are
					 * defined */

    Visual *visual;			/* Specifies the visual to use */
    Colormap colormap;			/* Specifies the colormap to use */
    unsigned int depth;			/* Specifies the depth */
    unsigned int width;			/* Returns the width of the created
					 * pixmap */
    unsigned int height;		/* Returns the height of the created
					 * pixmap */
    unsigned int x_hotspot;		/* Returns the x hotspot's
					 * coordinate */
    unsigned int y_hotspot;		/* Returns the y hotspot's
					 * coordinate */
    unsigned int cpp;			/* Specifies the number of char per
					 * pixel */
    Pixel *pixels;			/* List of used color pixels */
    unsigned int npixels;		/* Number of pixels */
    XpmColorSymbol *colorsymbols;	/* Array of color symbols to
					 * override */
    unsigned int numsymbols;		/* Number of symbols */
    char *rgb_fname;			/* RGB text file name */
    unsigned int nextensions;		/* number of extensions */
    XpmExtension *extensions;		/* pointer to array of extensions */

    /* Infos */
    unsigned int ncolors;		/* Number of colors */
    char ***colorTable;			/* Color table pointer */
    char *hints_cmt;			/* Comment of the hints section */
    char *colors_cmt;			/* Comment of the colors section */
    char *pixels_cmt;			/* Comment of the pixels section */
    unsigned int mask_pixel;		/* Transparent pixel's color table
					 * index */
    /* Color Allocation Directives */
    unsigned int exactColors;		/* Only use exact colors for visual */
    unsigned int closeness;		/* Allowable RGB deviation */

}      XpmAttributes;

/* Xpm attribute value masks bits */
#define XpmVisual	   (1L<<0)
#define XpmColormap	   (1L<<1)
#define XpmDepth	   (1L<<2)
#define XpmSize		   (1L<<3)	/* width & height */
#define XpmHotspot	   (1L<<4)	/* x_hotspot & y_hotspot */
#define XpmCharsPerPixel   (1L<<5)
#define XpmColorSymbols	   (1L<<6)
#define XpmRgbFilename	   (1L<<7)
#define XpmInfos	   (1L<<8)	/* all infos members */
#define XpmExtensions      (1L<<10)

#define XpmReturnPixels	   (1L<<9)
#define XpmReturnInfos	   XpmInfos
#define XpmReturnExtensions XpmExtensions

#define XpmExactColors     (1L<<11)
#define XpmCloseness	   (1L<<12)

/*
 * minimal portability layer between ansi and KR C 
 */

/* forward declaration of functions with prototypes */

#if __STDC__ || defined(__cplusplus) || defined(c_plusplus)
 /* ANSI || C++ */
#define FUNC(f, t, p) extern t f p
#define LFUNC(f, t, p) static t f p
#else					/* K&R */
#define FUNC(f, t, p) extern t f()
#define LFUNC(f, t, p) static t f()
#endif					/* end of K&R */


/*
 * functions declarations
 */

#ifdef __cplusplus
extern "C" {
#endif

    FUNC(XpmCreatePixmapFromData, int, (Display * display,
					Drawable d,
					char **data,
					Pixmap * pixmap_return,
					Pixmap * shapemask_return,
					XpmAttributes * attributes));

    FUNC(XpmCreateDataFromPixmap, int, (Display * display,
					char ***data_return,
					Pixmap pixmap,
					Pixmap shapemask,
					XpmAttributes * attributes));

    FUNC(XpmReadFileToPixmap, int, (Display * display,
				    Drawable d,
				    char *filename,
				    Pixmap * pixmap_return,
				    Pixmap * shapemask_return,
				    XpmAttributes * attributes));

    FUNC(XpmWriteFileFromPixmap, int, (Display * display,
				       char *filename,
				       Pixmap pixmap,
				       Pixmap shapemask,
				       XpmAttributes * attributes));

    FUNC(XpmCreateImageFromData, int, (Display * display,
				       char **data,
				       XImage ** image_return,
				       XImage ** shapemask_return,
				       XpmAttributes * attributes));

    FUNC(XpmCreateDataFromImage, int, (Display * display,
				       char ***data_return,
				       XImage * image,
				       XImage * shapeimage,
				       XpmAttributes * attributes));

    FUNC(XpmReadFileToImage, int, (Display * display,
				   char *filename,
				   XImage ** image_return,
				   XImage ** shapeimage_return,
				   XpmAttributes * attributes));

    FUNC(XpmWriteFileFromImage, int, (Display * display,
				      char *filename,
				      XImage * image,
				      XImage * shapeimage,
				      XpmAttributes * attributes));

    FUNC(XpmAttributesSize, int, ());
    FUNC(XpmFreeAttributes, int, (XpmAttributes * attributes));
    FUNC(XpmFreeExtensions, int, (XpmExtension * extensions, int nextensions));

#ifdef __cplusplus
}					/* for C++ V2.0 */

#endif


/* backward compatibility */

/* for version 3.0c */
#define XpmPixmapColorError  XpmColorError
#define XpmPixmapSuccess     XpmSuccess
#define XpmPixmapOpenFailed  XpmOpenFailed
#define XpmPixmapFileInvalid XpmFileInvalid
#define XpmPixmapNoMemory    XpmNoMemory
#define XpmPixmapColorFailed XpmColorFailed

#define XpmReadPixmapFile(dpy, d, file, pix, mask, att) \
    XpmReadFileToPixmap(dpy, d, file, pix, mask, att)
#define XpmWritePixmapFile(dpy, file, pix, mask, att) \
    XpmWriteFileFromPixmap(dpy, file, pix, mask, att)

/* for version 3.0b */
#define PixmapColorError  XpmColorError
#define PixmapSuccess     XpmSuccess
#define PixmapOpenFailed  XpmOpenFailed
#define PixmapFileInvalid XpmFileInvalid
#define PixmapNoMemory    XpmNoMemory
#define PixmapColorFailed XpmColorFailed

#define ColorSymbol XpmColorSymbol

#define XReadPixmapFile(dpy, d, file, pix, mask, att) \
    XpmReadFileToPixmap(dpy, d, file, pix, mask, att)
#define XWritePixmapFile(dpy, file, pix, mask, att) \
    XpmWriteFileFromPixmap(dpy, file, pix, mask, att)
#define XCreatePixmapFromData(dpy, d, data, pix, mask, att) \
    XpmCreatePixmapFromData(dpy, d, data, pix, mask, att)
#define XCreateDataFromPixmap(dpy, data, pix, mask, att) \
    XpmCreateDataFromPixmap(dpy, data, pix, mask, att)

#endif

/****************************************   end ../xpm/xpm.h   */
   #else				/* HaveXpmFormat */
      #include <X11/Xlib.h>
   #endif				/* HaveXpmFormat */
   #include <X11/Xutil.h>
   #include <X11/Xos.h>
   #include <X11/Xatom.h>
#endif					/* XWindows */

/*
 * Feature-dependent includes.
 */
#ifdef LoadFunc
   #include <dlfcn.h>
#endif					/* LoadFunc */

/****************************************   end ../h/sys.h   */


/****************************************  from ../h/typedefs.h:  */

/*
 * typedefs for the run-time system.
 */

typedef int ALIGN;		/* pick most stringent type for alignment */
typedef unsigned int DIGIT;

/*
 * Default sizing and such.
 */

/*
 * Set up typedefs and related definitions depending on whether or not
 * ints and pointers are the same size.
 */

#if IntBits != WordBits
   typedef long int word;
   typedef unsigned long int uword;
#else					/* IntBits != WordBits */
   typedef int word;
   typedef unsigned int uword;
#endif					/* IntBits != WordBits */

typedef void *pointer;

/*
 * Typedefs to make some things easier.
 */

typedef int (*fptr)();
typedef struct descrip *dptr;

typedef word C_integer;

/*
 * A success continuation is referenced by a pointer to an integer function
 *  that takes no arguments.
 */
typedef int (*continuation) (void);

#if !COMPILER

   /*
    * Typedefs for the interpreter.
    */

   /*
    * Icode consists of operators and arguments.  Operators are small integers,
    *  while arguments may be pointers.  To conserve space in icode files on
    *  computers with 16-bit ints, icode is written by the linker as a mixture
    *  of ints and words (longs).  When an icode file is read in and processed
    *  by the interpreter, it looks like a C array of mixed ints and words.
    *  Accessing this "nonstandard" structure is handled by a union of int and
    *  word pointers and incrementing is done by incrementing the appropriate
    *  member of the union (see the interpreter).  This is a rather dubious
    *  method and certainly not portable.  A better way might be to address
    *  icode with a char *, but the incrementing code might be inefficient
    *  (at a place that experiences a lot of execution activity).
    *
    * For the moment, the dubious coding is isolated under control of the
    *  size of integers.
    */

   #if IntBits != WordBits

      typedef union {
         int *op;
         word *opnd;
         } inst;

      #else				/* IntBits != WordBits */

      typedef union {
         word *op;
         word *opnd;
         } inst;

   #endif				/* IntBits != WordBits */

#endif					/* COMPILER */

/****************************************   end ../h/typedefs.h   */


/****************************************  from ../h/cstructs.h:  */

/*
 * cstructs.h - structures and accompanying manifest constants for functions
 *  in the common subdirectory.
 */

/*
 * fileparts holds a file name broken down into parts.
 */
struct fileparts {			/* struct of file name parts */
   char *dir;				/* directory */
   char *name;				/* name */
   char *ext;				/* extension */
   };

/*
 * xval - holds references to literal constants
 */
union xval {
   long ival;		/* integer */
   double rval;		/*  real */
   word sval;		/*  offset into string space of string */
   };

/*
 * str_buf references a string buffer. Strings are built a character
 *  at a time. When a buffer "fragment" is filled, another is allocated
 *  and the the current string copied to it.
 */
struct str_buf_frag {
   struct str_buf_frag *next;     /* next buffer fragment */
   char s[1];                     /* variable size buffer, really > 1 */
   };

struct str_buf {
   unsigned int size;             /* total size of current buffer */
   char *strtimage;               /* start of string currently being built */
   char *endimage;                /* next free character in buffer */
   char *end;                     /* end of current buffer */
   struct str_buf_frag *frag_lst; /* list of buffer fragments */
   struct str_buf *next;          /* buffers can be put on free list */
   };

#define AppChar(sbuf, c) do {\
   if ((sbuf).endimage >= (sbuf).end)\
      new_sbuf(&(sbuf));\
   *((sbuf).endimage)++ = (c);\
   } while (0)

/*
 * implement contains information about the implementation of an operation.
 */
#define NoRsltSeq  -1L	     /* no result sequence: {} */
#define UnbndSeq   -2L       /* unbounded result sequence: {*} */

#define DoesRet    01	     /* operation (or "body" function) returns */
#define DoesFail   02	     /* operation (or "body" function) fails */
#define DoesSusp   04	     /* operation (or "body" function) suspends */
#define DoesEFail 010        /* fails through error conversion */
#define DoesFThru 020	     /* only "body" functions can "fall through" */

struct implement {
   struct implement *blink;   /* link for bucket chain in hash tables */
   char oper_typ;             /* 'K'=keyword, 'F'=function, 'O'=operator */
   char prefix[2];	      /* prefix to make start of name unique */
   char *name;		      /* function/operator/keyword name */
   char *op;		      /* operator symbol (operators only) */
   int nargs;		      /* number of arguments operation requires */
   int *arg_flgs;             /* array of arg flags: deref/underef, var len*/
   long min_result;	      /* minimum result sequence length */
   long max_result;	      /* maiximum result sequence length */
   int resume;		      /* flag - resumption after last result */
   int ret_flag;	      /* DoesRet, DoesFail, DoesSusp */
   int use_rslt;              /* flag - explicitly uses result location */
   char *comment;	      /* description of operation */
   int ntnds;		      /* size of tnds array */
   struct tend_var *tnds;     /* pointer to array of info about tended vars */
   int nvars;                 /* size of vars array */
   struct ord_var  *vars;     /* pointer to array of info about ordinary vars */
   struct il_code *in_line;    /* inline version of the operation */
   int iconc_flgs;	      /* flags for internal use by the compiler */
   };

/*
 * These codes are shared between the data base and rtt. They are defined
 *  here, though not all are used by the data base.
 */
#define TndDesc   1  /* a tended descriptor */
#define TndStr    2  /* a tended character pointer */
#define TndBlk    3  /* a tended block pointer */
#define OtherDcl  4  /* a declaration that is not special */
#define IsTypedef 5  /* a typedef */
#define VArgLen   6  /* identifier for length of variable parm list */
#define RsltLoc   7  /* the special result location of an operation */
#define Label     8  /* label */
#define RtParm   16  /* undereferenced parameter of run-time routine */
#define DrfPrm   32  /* dereferenced parameter of run-time routine */
#define VarPrm   64  /* variable part of parm list (with RtParm or DrfPrm) */
#define PrmMark 128  /* flag - used while recognizing params of body fnc */
#define ByRef   256  /* flag - parameter to body function passed by reference */

/*
 * Flags to indicate what types are returned from the function implementing
 *  a body. These are unsed in determining the calling conventions
 *  of the function.
 */
#define RetInt   1  /* body/function returns a C_integer */
#define RetDbl   2  /* body/function returns a C_double */
#define RetOther 4  /* body (not function itself) returns something else */
#define RetNoVal 8  /* function returns no value */
#define RetSig  16  /* function returns a signal */

/*
 * tend_var contains information about a tended variable in the "declare {...}"
 *  action of an operation.
 */
struct tend_var {
   int var_type;           /* TndDesc, TndStr, or TndBlk */
   struct il_c *init;      /* initial value from declaration */
   char *blk_name;         /* TndBlk: struct name of block */
   };

/*
 * ord_var contains information about an ordinary variable in the
 *  "declare {...}" action of an operation.
 */
struct ord_var {
   char *name;        /* name of variable */
   struct il_c *dcl;  /* declaration of variable (includes name) */
   };

/*
 * il_code has information about an action in an operation.
 */
#define IL_If1     1
#define IL_If2     2
#define IL_Tcase1  3
#define IL_Tcase2  4
#define IL_Lcase   5
#define IL_Err1    6
#define IL_Err2    7
#define IL_Lst     8
#define IL_Const   9
#define IL_Bang   10
#define IL_And    11
#define IL_Cnv1   12
#define IL_Cnv2   13
#define IL_Def1   14
#define IL_Def2   15
#define IL_Is     16
#define IL_Var    17
#define IL_Subscr 18
#define IL_Block  19
#define IL_Call   20
#define IL_Abstr  21
#define IL_VarTyp 22
#define IL_Store  23
#define IL_Compnt 24
#define IL_TpAsgn 25
#define IL_Union  26
#define IL_Inter  27
#define IL_New    28
#define IL_IcnTyp 29
#define IL_Acase  30

#define CM_Fields -1

union il_fld {
   struct il_code *fld;
   struct il_c *c_cd;
   int *vect;
   char *s;
   word n;
   };

struct il_code {
   int il_type;
   union il_fld u[1];   /* actual number of fields varies with type */
   };

/*
 * The following manifest constants are used to describe types, conversions,
 *   and returned values. Non-negative numbers are reserved for types described
 *   in the type specification system.
 */
#define TypAny    -1
#define TypEmpty  -2
#define TypVar    -3
#define TypCInt   -4
#define TypCDbl   -5
#define TypCStr   -6
#define TypEInt   -7
#define TypECInt  -8
#define TypTStr   -9
#define TypTCset -10
#define RetDesc  -11
#define RetNVar  -12
#define RetSVar  -13
#define RetNone  -14

/*
 * il_c describes a piece of C code.
 */
#define ILC_Ref    1   /* nonmodifying reference to var. in sym. tab. */
#define ILC_Mod    2   /* modifying reference to var. in sym. tab */
#define ILC_Tend   3   /* tended var. local to inline block */
#define ILC_SBuf   4   /* string buffer */
#define ILC_CBuf   5   /* cset buffer */
#define ILC_Ret    6   /* return statement */
#define ILC_Susp   7   /* suspend statement */
#define ILC_Fail   8   /* fail statement */
#define ILC_Goto   9   /* goto */
#define ILC_CGto  10   /* conditional goto */
#define ILC_Lbl   11   /* label */
#define ILC_LBrc  12   /* '{' */
#define ILC_RBrc  13   /* '}' */
#define ILC_Str   14   /* arbitrary string of code */
#define ILC_EFail 15   /* errorfail statement */

#define RsltIndx -1   /* symbol table index for "result" */

struct il_c {
   int il_c_type;
   struct il_c *code[3];
   word n;
   char *s;
   struct il_c *next;
   };

/*
 * The parameter value of a run-time operation may be in one of several
 *  different locations depending on what conversions have been done to it.
 *  These codes are shared by rtt and iconc.
 */
#define PrmTend    1   /* in tended location */
#define PrmCStr    3   /* converted to C string: tended location */
#define PrmInt     4   /* converted to C int: non-tended location */
#define PrmDbl     8   /* converted to C double: non-tended location */

/*
 * Kind of RLT return statement supported.
 */
#define TRetNone  0   /* does not support an RTL return statement */
#define TRetBlkP  1   /* block pointer */
#define TRetDescP 2   /* descriptor pointer */
#define TRetCharP 3   /* character pointer */
#define TRetCInt  4   /* C integer */
#define TRetSpcl  5   /* RLT return statement has special form & semenatics */

/*
 * Codes for dereferencing needs.
 */
#define DrfNone  0  /* not a variable type */
#define DrfGlbl  1  /* treat as a global variable */
#define DrfCnst  2  /* type of values in variable doesn't change */
#define DrfSpcl  3  /* special dereferencing: trapped variable */

/*
 * Information about an Icon type.
 */
struct icon_type {
   char *id;		/* name of type */
   int support_new;	/* supports RTL "new" construct */
   int deref;		/* dereferencing needs */
   int rtl_ret;		/* kind of RTL return supported if any */
   char *typ;		/* for variable: initial type */
   int num_comps;	/* for aggregate: number of type components */
   int compnts;		/* for aggregate: index of first component */
   char *abrv;		/* abreviation used for type tracing */
   char *cap_id;	/* name of type with first character capitalized */
   };

/*
 * Information about a component of an aggregate type.
 */
struct typ_compnt {
   char *id;		/* name of component */
   int n;		/* position of component within type aggragate */
   int var;		/* flag: this component is an Icon-level variable */
   int aggregate;	/* index of type that owns the component */
   char *abrv;		/* abreviation used for type tracing */
   };

extern int num_typs;                 /* number of types in table */
extern struct icon_type icontypes[]; /* table of icon types */

/*
 * Type inference needs to know where most of the standard types
 *  reside. Some have special uses outside operations written in
 *  RTL code, such as the null type for initializing variables, and
 *  others have special semantics, such as trapped variables.
 */
extern int str_typ;                  /* index of string type */
extern int int_typ;                  /* index of integer type */
extern int rec_typ;                  /* index of record type */
extern int proc_typ;                 /* index of procedure type */
extern int coexp_typ;                /* index of co-expression type */
extern int stv_typ;                  /* index of sub-string trapped var type */
extern int ttv_typ;                  /* index of table-elem trapped var type */
extern int null_typ;                 /* index of null type */
extern int cset_typ;                 /* index of cset type */
extern int real_typ;                 /* index of real type */
extern int list_typ;                 /* index of list type */
extern int tbl_typ;                  /* index of table type */

extern int num_cmpnts;                 /* number of aggregate components */
extern struct typ_compnt typecompnt[]; /* table of aggregate components */
extern int str_var;                    /* index of trapped string variable */
extern int trpd_tbl;                   /* index of trapped table */
extern int lst_elem;                   /* index of list element */
extern int tbl_val;                    /* index of table element value */
extern int tbl_dflt;                   /* index of table default */

/*
 * minimum number of unsigned ints needed to hold the bits of a cset - only
 *  used in translators, not in the run-time system.
 */
#define BVectSize 16

/****************************************   end ../h/cstructs.h   */


/****************************************  from ../h/mproto.h:  */

/*
 * mproto.h -- prototypes for functions common to several modules.
 */

#define NewStruct(type) alloc(sizeof(struct type))

pointer	alloc		(unsigned int n);
unsigned short *bitvect	(char *image, int len);
char	*canonize	(char *path);
void	clear_sbuf	(struct str_buf *sbuf);
int	cmp_pre		(char *pre1, char *pre2);
void	cset_init	(FILE *f, unsigned short *bv);
void	db_chstr	(char *s1, char *s2);
void	db_close	(void);
void	db_code		(struct implement *ip);
void	db_dscrd	(struct implement *ip);
void	db_err1		(int fatal, char *s1);
void	db_err2		(int fatal, char *s1, char *s2);
struct implement *db_ilkup (char *id, struct implement **tbl);
struct implement *db_impl  (int oper_typ);
int	db_open		(char *s, char **lrgintflg);
char	*db_string	(void);
int	db_tbl		(char *section, struct implement **tbl);
char	*findexe	(char *name, char *buf, size_t len);
char	*findonpath	(char *name, char *buf, size_t len);
char	*followsym	(char *name, char *buf, size_t len);
struct fileparts *fparse(char *s);
void	free_stbl	(void);
void	id_comment	(FILE *f);
void	init_sbuf	(struct str_buf *sbuf);
void	init_str	(void);
long	longwrite	(char *s, long len, FILE *file);
char	*makename	(char *dest, char *d, char *name, char *e);
long	millisec	(void);
struct il_code *new_il	(int il_type, int size);
void	new_sbuf	(struct str_buf *sbuf);
void	nxt_pre		(char *pre, char *nxt, int n);
char	*pathfind	(char *buf, char *path, char *name, char *extn);
int	ppch		(void);
void	ppdef		(char *name, char *value);
void	ppecho		(void);
int	ppinit		(char *fname, char *inclpath, int m4flag);
int	prt_i_str	(FILE *f, char *s, int len);
char	*relfile	(char *prog, char *mod);
char	*salloc		(char *s);
int	smatch		(char *s, char *t);
char	*spec_str	(char *s);
char	*str_install	(struct str_buf *sbuf);
int	tonum		(int c);
void	lear_sbuf	(struct str_buf *sbuf);

#ifndef SysOpt
   int	getopt		(int argc, char * const argv[], const char *optstring);
#endif					/* NoSysOpt */

/****************************************   end ../h/mproto.h   */


/****************************************  from ../h/cpuconf.h:  */

/*
 *  Configuration parameters that depend on computer architecture.
 *  Some depend on values defined in config.h, which is always
 *  included before this file.
 */

#ifndef CStateSize
   #define CStateSize 15		/* size of C state for co-expressions */
#endif					/* CStateSize */

/*
 * The following definitions depend on the sizes of ints and pointers.
 */

/*
 * Most of the present implementations use 32-bit "words".  Note that
 *  WordBits is the number of bits in an Icon integer, not necessarily
 *  the number of bits in an int (given by IntBits).  In some systems
 *  an Icon integer is a long, not an int.
 *
 *  MaxStrLen must not be so large as to overlap flags.
 */

/*
 * 64-bit words.
 */

#if WordBits == 64

   #ifndef MinLong
      #define MinLong  ((long int)0x8000000000000000) /* smallest long int */
   #endif

   #ifndef MaxLong
      #define MaxLong  ((long int)0x7fffffffffffffff) /* largest long integer */
   #endif

   #define MaxStrLen 017777777777L		/* maximum string length */

   #ifndef MaxNegInt
      #define MaxNegInt "-9223372036854775808"
   #endif

   #ifndef F_Nqual
      #define F_Nqual 0x8000000000000000	/* set if NOT string qualifier*/
   #endif				/* F_Nqual */

   #ifndef F_Var
      #define F_Var	0x4000000000000000	/* set if variable */
   #endif				/* F_Var */

   #ifndef F_Ptr
      #define F_Ptr	0x1000000000000000	/* set if value field is ptr */
   #endif				/* F_Ptr */

   #ifndef F_Typecode
      #define F_Typecode  0x2000000000000000	/* set if dword incls typecode*/
   #endif				/* F_Typecode */

#endif					/* WordBits == 64 */

/*
 * 32-bit words.
 */

#if WordBits == 32

   #define MaxLong  ((long int)017777777777L)   /* largest long integer */
   #define MinLong  ((long int)020000000000L)   /* smallest long integer */

   #define MaxNegInt "-2147483648"

   #define MaxStrLen 0777777777		/* maximum string length */

   #define F_Nqual	0x80000000	/* set if NOT string qualifier */
   #define F_Var	0x40000000	/* set if variable */
   #define F_Ptr	0x10000000	/* set if value field is pointer */
   #define F_Typecode	0x20000000	/* set if dword includes type code */

#endif					/* WordBits == 32 */

/*
 * Values that depend on the number of bits in an int (not necessarily
 * the same as the number of bits in a word).
 */

#if IntBits == 64
   #define LogIntBits	6			/* log of IntBits */
   #define MaxUnsigned 01777777777777777777777L /* largest unsigned integer */
   #define MaxInt	0777777777777777777777L /* largest int */
   /*
    * Cset initialization and access macros.
    */
   #define fwd(w0, w1, w2, w3) \
      (((w0) & 0xffff) | (((unsigned)(w1) & 0xffff) << 16) | \
      (((unsigned)(w2) & 0xffff) << 32) | (((unsigned)(w3) & 0xffff) << 48))
   #define cset_display(w0,w1,w2,w3,w4,w5,w6,w7,w8,w9,wa,wb,wc,wd,we,wf) \
      {fwd(w0,w1,w2,w3),fwd(w4,w5,w6,w7),fwd(w8,w9,wa,wb),fwd(wc,wd,we,wf)}
   #define Cset32(b,c) (*CsetPtr(b,c)>>(32*CsetOff((b)>>5)))  /* 32b of cset */
#endif					/* IntBits == 64 */

#if IntBits == 32
   #define LogIntBits	5		/* log of IntBits */
   #define MaxUnsigned	037777777777	/* largest unsigned integer */
   #define MaxInt	017777777777	/* largest int */
   /*
    * Cset initialization and access macros.
    */
   #define twd(w0,w1)	(((w0)&0xffff) | (((unsigned)w1)<<16))
   #define cset_display(w0,w1,w2,w3,w4,w5,w6,w7,w8,w9,wa,wb,wc,wd,we,wf) \
      {twd(w0,w1),twd(w2,w3),twd(w4,w5),twd(w6,w7), \
       twd(w8,w9),twd(wa,wb),twd(wc,wd),twd(we,wf)}
   #define Cset32(b,c) (*CsetPtr(b,c))	/* 32 bits of cset */
#endif					/* IntBits == 32 */

#ifndef LogHuge
   #define LogHuge 309			/* maximum base-10 exp+1 of real */
#endif					/* LogHuge */

#ifndef Big
   #define Big 9007199254740992.	/* larger than 2^53 lose precision */
#endif					/* Big */

#ifndef Precision
   #define Precision 10			/* digits in string from real */
#endif					/* Precision */

/*
 * Parameters that configure tables and sets:
 *
 *  HSlots	Initial number of hash buckets; must be a power of 2.
 *  LogHSlots	Log to the base 2 of HSlots.
 *
 *  HSegs	Maximum number of hash bin segments; the maximum number of
 *		hash bins is HSlots * 2 ^ (HSegs - 1).
 *
 *		If Hsegs is increased above 20, the arrays log2h[] and segsize[]
 *		in the runtime system will need modification.
 *
 *  MaxHLoad	Maximum loading factor; more hash bins are allocated when
 *		the average bin exceeds this many entries.
 *
 *  MinHLoad	Minimum loading factor; if a newly created table (e.g. via
 *		copy()) is more lightly loaded than this, bins are combined.
 *
 *  Because splitting doubles the number of hash bins, and combining halves it,
 *  MaxHLoad should be at least twice MinHLoad.
 */

#ifndef HSlots
   #define HSlots     16
   #define LogHSlots  4
#endif					/* HSlots */

#if ((1 << LogHSlots) != HSlots)
   #error HSlots and LogHSlots are inconsistent
#endif					/* HSlots / LogHSlots consistency */

#ifndef HSegs
   #define HSegs	 20
#endif					/* HSegs */

#ifndef MinHLoad
   #define MinHLoad  1
#endif					/* MinHLoad */

#ifndef MaxHLoad
   #define MaxHLoad  5
#endif					/* MaxHLoad */

/*
 * The number of bits in each base-B digit; the type DIGIT (unsigned int)
 *  in rt.h must be large enough to hold this many bits.
 *  It must be at least 2 and at most WordBits / 2.
 */
#define NB           (WordBits / 2)

/*
 * The number of decimal digits at which the image lf a large integer
 * goes from exact to approximate (to avoid possible long delays in
 * conversion from large integer to string because of its quadratic
 * complexity).
 */
#define MaxDigits	30

/*
 * Memory sizing.
 */
#ifndef AlcMax
   #define AlcMax 25
#endif					/* AlcMax */

/*
 * Maximum sized block that can be allocated (via malloc() or such).
 */
#ifndef MaxBlock
   #define MaxBlock MaxUnsigned
#endif					/* MaxBlock */

/*
 * What follows is default memory sizing. Implementations with special
 *  requirements may specify these values in define.h.
 */

#ifndef MaxStrSpace
   #define MaxStrSpace 500000		/* size of the string space in bytes */
#endif					/* MaxStrSpace */

#ifndef MaxAbrSize
   #define MaxAbrSize 500000		/* size of the block region in bytes */
#endif					/* MaxAbrSize */

#ifndef MinAbrSize
   #define MinAbrSize	 5000		/* minimum block region size */
#endif					/* MinAbrSize */

#ifndef MStackSize
   #ifdef MultiThread
      #define MStackSize 20000		/* size of the main stack in words */
   #else				/* MultiThread */
      #define MStackSize 10000		/* size of the main stack in words */
   #endif				/* MultiThread */
#endif					/* MStackSize */

#ifndef StackSize
   #define StackSize	2000		/* words in co-expression stack */
#endif					/* StackSize */

#ifndef QualLstSize
   #define QualLstSize	5000		/* size of qualifier pointer region */
#endif					/* QualLstSize */

#ifndef ActStkBlkEnts
   #ifdef Coexpr
      #define ActStkBlkEnts   25	/* number of entries in an astkblk */
   #else				/* Coexpr */
      #define ActStkBlkEnts    1	/* number of entries in an astkblk */
   #endif				/* Coexpr */
#endif					/* ActStkBlkEnts */

#ifndef RegionCushion
   #define RegionCushion 10		/* % memory cushion to avoid thrashing*/
#endif					/* RegionCushion */

#ifndef RegionGrowth
   #define RegionGrowth 200		/* % region growth when full */
#endif					/* RegionGrowth */

/****************************************   end ../h/cpuconf.h   */


/****************************************  from ../h/monitor.h:  */

/*
 * This file contains definitions for the various event codes and values
 * that go to make up event streams.
 */

/*
 * Note: the blank character should *not* be used as an event code.
 */

#ifdef EventMon

/*
 * Allocation events use lowercase codes.
 */
#define E_Lrgint	'\114'		/* Large integer allocation */
#define E_Real		'\144'		/* Real allocation */
#define E_Cset		'\145'		/* Cset allocation */
#define E_File		'\147'		/* File allocation */
#define E_Record	'\150'		/* Record allocation */
#define E_Tvsubs	'\151'		/* Substring tv allocation */
#define E_External	'\152'		/* External allocation */
#define E_List		'\153'		/* List allocation */
#define E_Lelem		'\155'		/* List element allocation */
#define E_Table		'\156'		/* Table allocation */
#define E_Telem		'\157'		/* Table element allocation */
#define E_Tvtbl		'\160'		/* Table-element tv allocation */
#define E_Set		'\161'		/* Set allocation */
#define E_Selem		'\164'		/* Set element allocation */
#define E_Slots		'\167'		/* Hash header allocation */
#define E_Coexpr	'\170'		/* Co-expression allocation */
#define E_Refresh	'\171'		/* Refresh allocation */
#define E_Alien		'\172'		/* Alien allocation */
#define E_Free		'\132'		/* Free region */
#define E_String	'\163'		/* String allocation */

/*
 * Some other monitoring codes.
 */
#define	E_BlkDeAlc	'\055'		/* Block deallocation */
#define	E_StrDeAlc	'\176'		/* String deallocation */

/*
 * These are not "events"; they are provided for uniformity in tools
 *  that deal with types.
 */
#define E_Integer	'\100'		/* Integer value pseudo-event */
#define E_Null		'\044'		/* Null value pseudo-event */
#define E_Proc		'\045'		/* Procedure value pseudo-event */
#define E_Kywdint	'\136'		/* Integer keyword value pseudo-event */
#define E_Kywdpos	'\046'		/* Position value pseudo-event */
#define E_Kywdsubj	'\052'		/* Subject value pseudo-event */

/*
 * Codes for main sequence events
 */

   /*
    * Timing events
    */
#define E_Tick		'\056'		/* Clock tick */

   /*
    * Code-location event
    */
#define E_Loc		'\174'		/* Location change */
#define E_Line		'\355'		/* Line change */

   /*
    * Virtual-machine instructions
    */
#define E_Opcode	'\117'		/* Virtual-machine instruction */

   /*
    * Type-conversion events
    */
#define E_Aconv		'\111'		/* Conversion attempt */
#define E_Tconv		'\113'		/* Conversion target */
#define E_Nconv		'\116'		/* Conversion not needed */
#define E_Sconv		'\121'		/* Conversion success */
#define E_Fconv		'\112'		/* Conversion failure */

   /*
    * Structure events
    */
#define	E_Lbang		'\301'		/* List generation */
#define	E_Lcreate	'\302'		/* List creation */
#define	E_Lget		'\356'		/* List get/pop -- only E_Lget used */
#define	E_Lpop		'\356'		/* List get/pop */
#define	E_Lpull		'\304'		/* List pull */
#define	E_Lpush		'\305'		/* List push */
#define	E_Lput		'\306'		/* List put */
#define	E_Lrand		'\307'		/* List random reference */
#define	E_Lref		'\310'		/* List reference */
#define E_Lsub		'\311'		/* List subscript */
#define	E_Rbang		'\312'		/* Record generation */
#define	E_Rcreate	'\313'		/* Record creation */
#define	E_Rrand		'\314'		/* Record random reference */
#define	E_Rref		'\315'		/* Record reference */
#define E_Rsub		'\316'		/* Record subscript */
#define	E_Sbang		'\317'		/* Set generation */
#define	E_Screate	'\320'		/* Set creation */
#define	E_Sdelete	'\321'		/* Set deletion */
#define	E_Sinsert	'\322'		/* Set insertion */
#define	E_Smember	'\323'		/* Set membership */
#define	E_Srand		'\336'		/* Set random reference */
#define	E_Sval		'\324'		/* Set value */
#define	E_Tbang		'\325'		/* Table generation */
#define	E_Tcreate	'\326'		/* Table creation */
#define	E_Tdelete	'\327'		/* Table deletion */
#define	E_Tinsert	'\330'		/* Table insertion */
#define	E_Tkey		'\331'		/* Table key generation */
#define	E_Tmember	'\332'		/* Table membership */
#define	E_Trand		'\337'		/* Table random reference */
#define	E_Tref		'\333'		/* Table reference */
#define	E_Tsub		'\334'		/* Table subscript */
#define	E_Tval		'\335'		/* Table value */

   /*
    * Scanning events
    */

#define E_Snew		'\340'		/* Scanning environment creation */
#define E_Sfail		'\341'		/* Scanning failure */
#define E_Ssusp		'\342'		/* Scanning suspension */
#define E_Sresum	'\343'		/* Scanning resumption */
#define E_Srem		'\344'		/* Scanning environment removal */
#define E_Spos		'\346'		/* Scanning position */

   /*
    * Assignment
    */

#define E_Assign	'\347'		/* Assignment */
#define	E_Value		'\350'		/* Value assigned */

   /*
    * Sub-string assignment
    */

#define E_Ssasgn	'\354'		/* Sub-string assignment */
   /*
    * Interpreter stack events
    */

#define E_Intcall	'\351'		/* interpreter call */
#define E_Intret	'\352'		/* interpreter return */
#define E_Stack		'\353'		/* stack depth */

   /*
    * Expression events
    */
#define E_Ecall		'\143'		/* Call of operation */
#define E_Efail		'\146'		/* Failure from expression */
#define E_Bsusp		'\142'		/* Suspension from operation */
#define E_Esusp		'\141'		/* Suspension from alternation */
#define E_Lsusp		'\154'		/* Suspension from limitation */
#define E_Eresum	'\165'		/* Resumption of expression */
#define E_Erem		'\166'		/* Removal of a suspended generator */

   /*
    * Co-expression events
    */

#define E_Coact		'\101'		/* Co-expression activation */
#define E_Coret		'\102'		/* Co-expression return */
#define E_Cofail	'\104'		/* Co-expression failure */

   /*
    * Procedure events
    */

#define E_Pcall		'\103'		/* Procedure call */
#define E_Pfail		'\106'		/* Procedure failure */
#define E_Pret		'\122'		/* Procedure return */
#define E_Psusp		'\123'		/* Procedure suspension */
#define E_Presum	'\125'		/* Procedure resumption */
#define E_Prem		'\126'		/* Suspended procedure removal */

#define E_Fcall		'\072'		/* Function call */
#define E_Ffail		'\115'		/* Function failure */
#define E_Fret		'\120'		/* Function return */
#define E_Fsusp		'\127'		/* Function suspension */
#define E_Fresum	'\131'		/* Function resumption */
#define E_Frem		'\133'		/* Function suspension removal */

#define E_Ocall		'\134'		/* Operator call */
#define E_Ofail		'\135'		/* Operator failure */
#define E_Oret		'\140'		/* Operator return */
#define E_Osusp		'\173'		/* Operator suspension */
#define E_Oresum	'\175'		/* Operator resumption */
#define E_Orem		'\177'		/* Operator suspension removal */

   /*
    * Garbage collections
    */

#define E_Collect	'\107'		/* Garbage collection */
#define E_EndCollect	'\360'		/* End of garbage collection */
#define E_TenureString	'\361'		/* Tenure a string region */
#define E_TenureBlock	'\362'		/* Tenure a block region */

/*
 * Termination Events
 */
#define E_Error		'\105'		/* Run-time error */
#define E_Exit		'\130'		/* Program exit */

   /*
    * I/O events
    */
#define E_MXevent	'\370'		/* monitor input event */

#endif					/* EventMon */

/****************************************   end ../h/monitor.h   */


/****************************************  from ../h/rmacros.h:  */

/*
 *  Definitions for macros and manifest constants used in the compiler
 *  interpreter.
 */

/*
 *  Definitions common to the compiler and interpreter.
 */

/*
 * Constants that are not likely to vary between implementations.
 */

#define BitOffMask (IntBits-1)
#define CsetSize (256/IntBits)	/* number of ints to hold 256 cset
				 *  bits. Use (256/IntBits)+1 if
				 *  256 % IntBits != 0 */
#define MinListSlots	    8	/* number of elements in an expansion
				 * list element block  */

#define MaxCvtLen	   257	/* largest string in conversions; the extra
				 *  one is for a terminating null */
#define MaxReadStr	   512	/* largest string to read() in one piece */
#define MaxIn		  32767	/* largest number of bytes to read() at once */
#define RandA        1103515245	/* random seed multiplier */
#define RandC	      453816694	/* random seed additive constant */
#define RanScale 4.65661286e-10	/* random scale factor = 1/(2^31-1) */

#define Pi 3.14159265358979323846264338327950288419716939937511

/*
 * File status flags in status field of file blocks.
 */
#define Fs_Read		 01	/* read access */
#define Fs_Write	 02	/* write access */
#define Fs_Create	 04	/* file created on open */
#define Fs_Append	010	/* append mode */
#define Fs_Pipe		020	/* reading/writing on a pipe */
#define Fs_Untrans    01000	/* untranslated mode file */
#define Fs_Directory  02000	/* reading a directory */
#define Fs_Reading     0100     /* last file operation was read */
#define Fs_Writing     0200     /* last file operation was write */

#ifdef Graphics
   #define Fs_Window   0400	/* reading/writing on a window */

   #define XKey_Window 0
   #define XKey_Fg 1

   #ifndef SHORT
      #define SHORT int
   #endif				/* SHORT */
   #ifndef LONG
      #define LONG int
   #endif				/* LONG */

   /*
    * Perform a "C" return, not processed by RTT
    */
   #define VanquishReturn(s) return s;
#endif					/* Graphics */

/*
 * Codes returned by runtime support routines.
 *  Note, some conversion routines also return type codes. Other routines may
 *  return positive values other than return codes. sort() places restrictions
 *  on Less, Equal, and Greater.
 */

#define Less		-1
#define Equal		0
#define Greater		1

#define CvtFail		-2
#define Cvt		-3
#define NoCvt		-4
#define Failed		-5
#define Defaulted	-6
#define Succeeded	-7
#define Error		-8

#define GlobalName	0
#define StaticName	1
#define ParamName	2
#define LocalName	3

/*
 * Pointer to block.
 */
#define BlkLoc(d)	((d).vword.bptr)

/*
 * Check for null-valued descriptor.
 */
#define ChkNull(d)	((d).dword==D_Null)

/*
 * Check for equivalent descriptors.
 */
#define EqlDesc(d1,d2)	((d1).dword == (d2).dword && BlkLoc(d1) == BlkLoc(d2))

/*
 * Integer value.
 */
#define IntVal(d)	((d).vword.integr)

/*
 * Offset from top of block to value of variable.
 */
#define Offset(d)	((d).dword & OffsetMask)

/*
 * Check for pointer.
 */
#define Pointer(d)	((d).dword & F_Ptr)

/*
 * Check for qualifier.
 */
#define Qual(d)		(!((d).dword & F_Nqual))

/*
 * Length of string.
 */
#define StrLen(q)	((q).dword)

/*
 * Location of first character of string.
 */
#define StrLoc(q)	((q).vword.sptr)

/*
 * Assign a C string to a descriptor. Assume it is reasonable to use the
 *   descriptor expression more than once, but not the string expression.
 */
#define AsgnCStr(d,s) (StrLoc(d) = (s), StrLen(d) = strlen(StrLoc(d)))

/*
 * Type of descriptor.
 */
#define Type(d)		(int)((d).dword & TypeMask)

/*
 * Check for variable.
 */
#define Var(d)		((d).dword & F_Var)

/*
 * Location of the value of a variable.
 */
#define VarLoc(d)	((d).vword.descptr)

/*
 *  Important note:  The code that follows is not strictly legal C.
 *   It tests to see if pointer p2 is between p1 and p3. This may
 *   involve the comparison of pointers in different arrays, which
 *   is not well-defined.  The casts of these pointers to unsigned "words"
 *   (longs or ints, depending) works with all C compilers and architectures
 *   on which Icon has been implemented.  However, it is possible it will
 *   not work on some system.  If it doesn't, there may be a "false
 *   positive" test, which is likely to cause a memory violation or a
 *   loop. It is not practical to implement Icon on a system on which this
 *   happens.
 */

#define InRange(p1,p2,p3) ((uword)(p2) >= (uword)(p1) && (uword)(p2) < (uword)(p3))

/*
 * Get floating-point number from real block.
 */
#ifdef Double
   #define GetReal(dp,res) *((struct size_dbl *)&(res)) =\
         *((struct size_dbl *)&(BlkLoc(*dp)->realblk.realval))
#else					/* Double */
   #define GetReal(dp,res)	res = BlkLoc(*dp)->realblk.realval
#endif					/* Double */

/*
 * Absolute value, maximum, and minimum.
 * N.B. UNSAFE MACROS: may evaluate arguments multiple times.
 */
#define Abs(x)		(((x) < 0) ? (-(x)) : (x))
#define Max(x,y)        ((x)>(y)?(x):(y))
#define Min(x,y)        ((x)<(y)?(x):(y))

/*
 * Number of elements of a C array, and element size.
 */
#define ElemCount(a) (sizeof(a)/sizeof(a[0]))
#define ElemSize(a) (sizeof(a[0]))

/*
 * Construct an integer descriptor.
 */
#define MakeInt(i,dp)		do { \
			 (dp)->dword = D_Integer; \
			 IntVal(*dp) = (word)(i); \
			 } while (0)

/*
 * Construct a string descriptor.
 */
#define MakeStr(s,len,dp)      do { \
			 StrLoc(*dp) = (s); \
			 StrLen(*dp) = (len); \
			 } while (0)

/*
 * Offset in word of cset bit.
 */
#define CsetOff(b)	((b) & BitOffMask)

/*
 * Set bit b in cset c.
 */
#define Setb(b,c)	(*CsetPtr(b,c) |= (01 << CsetOff(b)))

/*
 * Test bit b in cset c.
 */
#define Testb(b,c)	((*CsetPtr(b,c) >> CsetOff(b)) & 01)

/*
 * Check whether a set or table needs resizing.
 */
#define SP(p) ((struct b_set *)p)
#define TooCrowded(p) \
   ((SP(p)->size > MaxHLoad*(SP(p)->mask+1)) && (SP(p)->hdir[HSegs-1] == NULL))
#define TooSparse(p) \
   ((SP(p)->hdir[1] != NULL) && (SP(p)->size < MinHLoad*(SP(p)->mask+1)))

/*
 * Definitions and declarations used for storage management.
 */
#define F_Mark		0100000		/* bit for marking blocks */

/*
 * Argument values for the built-in Icon user function "collect()".
 */
#define Static  1			/* collection is for static region */
#define Strings	2			/* collection is for strings */
#define Blocks	3			/* collection is for blocks */

/*
 * Get type of block pointed at by x.
 */
#define BlkType(x)   (*(word *)x)

/*
 * BlkSize(x) takes the block pointed to by x and if the size of
 *  the block as indicated by bsizes[] is nonzero it returns the
 *  indicated size; otherwise it returns the second word in the
 *  block contains the size.
 */
#define BlkSize(x) (bsizes[*(word *)x & ~F_Mark] ? \
		     bsizes[*(word *)x & ~F_Mark] : *((word *)x + 1))

/*
 * Here are the events we support (in addition to keyboard characters)
 */
#define MOUSELEFT	(-1)
#define MOUSEMID	(-2)
#define MOUSERIGHT	(-3)
#define MOUSELEFTUP	(-4)
#define MOUSEMIDUP	(-5)
#define MOUSERIGHTUP	(-6)
#define MOUSELEFTDRAG	(-7)
#define MOUSEMIDDRAG	(-8)
#define MOUSERIGHTDRAG	(-9)
#define RESIZED		(-10)
#define LASTEVENTCODE	RESIZED

/*
 * Type codes (descriptors and blocks).
 */
#define T_String	-1	/* string -- for reference; not used */
#define T_Null		 0	/* null value */
#define T_Integer	 1	/* integer */

#ifdef LargeInts
   #define T_Lrgint	 2	/* long integer */
#endif					/* LargeInts */

#define T_Real		 3	/* real number */
#define T_Cset		 4	/* cset */
#define T_File		 5	/* file */
#define T_Proc		 6	/* procedure */
#define T_Record	 7	/* record */
#define T_List		 8	/* list header */
#define T_Lelem		 9	/* list element */
#define T_Set		10	/* set header */
#define T_Selem		11	/* set element */
#define T_Table		12	/* table header */
#define T_Telem		13	/* table element */
#define T_Tvtbl		14	/* table element trapped variable */
#define T_Slots		15	/* set/table hash slots */
#define T_Tvsubs	16	/* substring trapped variable */
#define T_Refresh	17	/* refresh block */
#define T_Coexpr	18	/* co-expression */
#define T_External	19	/* external block */
#define T_Kywdint	20	/* integer keyword */
#define T_Kywdpos	21	/* keyword &pos */
#define T_Kywdsubj	22	/* keyword &subject */
#define T_Kywdwin	23	/* keyword &window */
#define T_Kywdstr	24	/* string keyword */
#define T_Kywdevent	25	/* keyword &eventsource, etc. */

#define MaxType		26	/* maximum type number */

/*
 * Definitions for keywords.
 */

#define k_pos kywd_pos.vword.integr	/* value of &pos */
#define k_random kywd_ran.vword.integr	/* value of &random */
#define k_trace kywd_trc.vword.integr	/* value of &trace */
#define k_dump kywd_dmp.vword.integr	/* value of &dump */

#ifdef FncTrace
   #define k_ftrace kywd_ftrc.vword.integr	/* value of &ftrace */
#endif					/* FncTrace */

/*
 * Descriptor types and flags.
 */

#define D_Null		(T_Null     | D_Typecode)
#define D_Integer	(T_Integer  | D_Typecode)

#ifdef LargeInts
   #define D_Lrgint	(T_Lrgint | D_Typecode | F_Ptr)
#endif					/* LargeInts */

#define D_Real		(T_Real     | D_Typecode | F_Ptr)
#define D_Cset		(T_Cset     | D_Typecode | F_Ptr)
#define D_File		(T_File     | D_Typecode | F_Ptr)
#define D_Proc		(T_Proc     | D_Typecode | F_Ptr)
#define D_List		(T_List     | D_Typecode | F_Ptr)
#define D_Lelem		(T_Lelem    | D_Typecode | F_Ptr)
#define D_Table		(T_Table    | D_Typecode | F_Ptr)
#define D_Telem		(T_Telem    | D_Typecode | F_Ptr)
#define D_Set		(T_Set      | D_Typecode | F_Ptr)
#define D_Selem		(T_Selem    | D_Typecode | F_Ptr)
#define D_Record	(T_Record   | D_Typecode | F_Ptr)
#define D_Tvsubs	(T_Tvsubs   | D_Typecode | F_Ptr | F_Var)
#define D_Tvtbl		(T_Tvtbl    | D_Typecode | F_Ptr | F_Var)
#define D_Kywdint	(T_Kywdint  | D_Typecode | F_Ptr | F_Var)
#define D_Kywdpos	(T_Kywdpos  | D_Typecode | F_Ptr | F_Var)
#define D_Kywdsubj	(T_Kywdsubj | D_Typecode | F_Ptr | F_Var)
#define D_Refresh	(T_Refresh  | D_Typecode | F_Ptr)
#define D_Coexpr	(T_Coexpr   | D_Typecode | F_Ptr)
#define D_External	(T_External | D_Typecode | F_Ptr)
#define D_Slots		(T_Slots    | D_Typecode | F_Ptr)
#define D_Kywdwin	(T_Kywdwin  | D_Typecode | F_Ptr | F_Var)
#define D_Kywdstr	(T_Kywdstr  | D_Typecode | F_Ptr | F_Var)
#define D_Kywdevent	(T_Kywdevent| D_Typecode | F_Ptr | F_Var)

#define D_Var		(F_Var | F_Nqual | F_Ptr)
#define D_Typecode	(F_Nqual | F_Typecode)

#define TypeMask	63	/* type mask */
#define OffsetMask	(~(D_Var)) /* offset mask for variables */

/*
 * "In place" dereferencing.
 */
#define Deref(d) if (Var(d)) deref(&d, &d)

/*
 * Construct a substring trapped variable.
 */
#define SubStr(dest,var,len,pos)\
   if ((var)->dword == D_Tvsubs)\
      (dest)->vword.bptr = (union block *)alcsubs(len, (pos) +\
         BlkLoc(*(var))->tvsubs.sspos - 1, &BlkLoc(*(var))->tvsubs.ssvar);\
   else\
      (dest)->vword.bptr = (union block *)alcsubs(len, pos, (var));\
   (dest)->dword = D_Tvsubs;

/*
 * Find debug struct in procedure frame, assuming debugging is enabled.
 *  Note that there is always one descriptor in array even if it is not
 *  being used.
 */
#define PFDebug(pf) ((struct debug *)((char *)(pf).tend.d +\
   sizeof(struct descrip) * ((pf).tend.num ? (pf).tend.num : 1)))

/*
 * Macro for initialized procedure block.
 */
#define B_IProc(n) struct {word title; word blksize; int (*ccode)();\
   word nparam; word ndynam; word nstatic; word fstatic;\
   struct sdescrip quals[n];}

#define ssize    (curstring->size)
#define strbase  (curstring->base)
#define strend   (curstring->end)
#define strfree  (curstring->free)

#define abrsize  (curblock->size)
#define blkbase  (curblock->base)
#define blkend   (curblock->end)
#define blkfree  (curblock->free)

#if COMPILER

   #ifdef Graphics
      #define Poll() if (!pollctr--) pollctr = pollevent()
   #else				/* Graphics */
      #define Poll()
   #endif				/* Graphics */

#else					/* COMPILER */

   /*
    * Definitions for the interpreter.
    */

   /*
    * Codes returned by invoke to indicate action.
    */
   #define I_Builtin	201	/* A built-in routine is to be invoked */
   #define I_Fail	202	/* goal-directed evaluation failed */
   #define I_Continue	203	/* Continue execution in the interp loop */
   #define I_Vararg	204	/* A function with a variable number of args */

   /*
    * Generator types.
    */
   #define G_Csusp		1
   #define G_Esusp		2
   #define G_Psusp		3
   #define G_Fsusp		4
   #define G_Osusp		5

   /*
    * Evaluation stack overflow margin
    */
   #define PerilDelta 100

   /*
    * Macros for pushing values on the interpreter stack.
    */

   /*
    * Push descriptor.
    */
   #define PushDescSP(SP,d)  {*++SP=((d).dword); SP++; *SP =((d).vword.integr);}

   /*
    * Push null-valued descriptor.
    */
   #define PushNullSP(SP)	{*++SP = D_Null; SP++; *SP = 0;}

   /*
    * Push word.
    */
   #define PushValSP(SP,v)	{*++SP = (word)(v);}

   /*
    * Shorter Versions of the Push*SP macros that assume sp points to the top
    * of the stack.
    */
   #define PushDesc(d)		PushDescSP(sp,d)
   #define PushNull		PushNullSP(sp)
   #define PushVal(x)		PushValSP(sp,x)
   #define PushAVal(x)		PushValSP(sp,x)

   /*
    * Macros related to function and operator definition.
    */

   /*
    * Procedure block for a function.
    */

   #define FncBlock(f,nargs,deref) \
      struct b_iproc Cat(B,f) = {\
      T_Proc,\
      Vsizeof(struct b_proc),\
      Cat(Z,f),\
      nargs,\
      -1,\
      deref, 0,\
      {sizeof(Lit(f))-1,Lit(f)}};

   /*
    * Procedure block for an operator.
    */
   #define OpBlock(f,nargs,sname,xtrargs)\
      struct b_iproc Cat(B,f) = {\
      T_Proc,\
      Vsizeof(struct b_proc),\
      Cat(O,f),\
      nargs,\
      -1,\
      xtrargs,\
      0,\
      {sizeof(sname)-1,sname}};

   /*
    * Operator declaration.
    */
   #define OpDcl(nm,n,pn) OpBlock(nm,n,pn,0) Cat(O,nm)(cargp) register dptr cargp;

   /*
    * Operator declaration with extra working argument.
    */
   #define OpDclE(nm,n,pn) OpBlock(nm,-n,pn,0) Cat(O,nm)(cargp) register dptr cargp;

   /*
    * Agent routine declaration.
    */
   #define AgtDcl(nm) Cat(A,nm)(cargp) register dptr cargp;

   /*
    * Macros to access Icon arguments in C functions.
    */

   /*
    * n-th argument.
    */
   #define Arg(n)	(cargp[n])

   /*
    * Type field of n-th argument.
    */
   #define ArgType(n)	(cargp[n].dword)

   /*
    * Value field of n-th argument.
    */
   #define ArgVal(n)	(cargp[n].vword.integr)

   /*
    * Specific arguments.
    */
   #define Arg0	(cargp[0])
   #define Arg1	(cargp[1])
   #define Arg2	(cargp[2])
   #define Arg3	(cargp[3])
   #define Arg4	(cargp[4])
   #define Arg5	(cargp[5])
   #define Arg6	(cargp[6])
   #define Arg7	(cargp[7])
   #define Arg8	(cargp[8])

   /*
    * Miscellaneous macro definitions.
    */

   #ifdef MultiThread
      #define glbl_argp (curpstate->Glbl_argp)
      #define kywd_err  (curpstate->Kywd_err)
      #define kywd_pos  (curpstate->Kywd_pos)
      #define kywd_prog  (curpstate->Kywd_prog)
      #define kywd_ran  (curpstate->Kywd_ran)
      #define k_eventcode (curpstate->eventcode)
      #define k_eventsource (curpstate->eventsource)
      #define k_eventvalue (curpstate->eventval)
      #define k_subject (curpstate->ksub)
      #define kywd_trc  (curpstate->Kywd_trc)
      #define mainhead (curpstate->Mainhead)
      #define code (curpstate->Code)
      #define ecode (curpstate->Ecode)
      #define records (curpstate->Records)
      #define ftabp (curpstate->Ftabp)
      #ifdef FieldTableCompression
         #define ftabwidth (curpstate->Ftabwidth)
         #define foffwidth (curpstate->Foffwidth)
         #define ftabcp (curpstate->Ftabcp)
         #define ftabsp (curpstate->Ftabsp)
         #define focp (curpstate->Focp)
         #define fosp (curpstate->Fosp)
         #define fo (curpstate->Fo)
         #define bm (curpstate->Bm)
      #endif				/* FieldTableCompression */
      #define fnames (curpstate->Fnames)
      #define efnames (curpstate->Efnames)
      #define globals (curpstate->Globals)
      #define eglobals (curpstate->Eglobals)
      #define gnames (curpstate->Gnames)
      #define egnames (curpstate->Egnames)
      #define statics (curpstate->Statics)
      #define estatics (curpstate->Estatics)
      #define n_globals (curpstate->NGlobals)
      #define n_statics (curpstate->NStatics)
      #define strcons (curpstate->Strcons)
      #define filenms (curpstate->Filenms)
      #define efilenms (curpstate->Efilenms)
      #define ilines (curpstate->Ilines)
      #define elines (curpstate->Elines)
      #define current_line_ptr (curpstate->Current_line_ptr)

      #ifdef Graphics
         #define amperX   (curpstate->AmperX)
         #define amperY   (curpstate->AmperY)
         #define amperRow (curpstate->AmperRow)
         #define amperCol (curpstate->AmperCol)
         #define amperInterval (curpstate->AmperInterval)
         #define lastEventWin (curpstate->LastEventWin)
         #define lastEvFWidth (curpstate->LastEvFWidth)
         #define lastEvLeading (curpstate->LastEvLeading)
         #define lastEvAscent (curpstate->LastEvAscent)
         #define kywd_xwin (curpstate->Kywd_xwin)
         #define xmod_control (curpstate->Xmod_Control)
         #define xmod_shift (curpstate->Xmod_Shift)
         #define xmod_meta (curpstate->Xmod_Meta)
      #endif				/* Graphics */

      #ifdef EventMon
         #define linenum  (curpstate->Linenum)
         #define column   (curpstate->Column)
         #define lastline (curpstate->Lastline)
         #define lastcol  (curpstate->Lastcol)
      #endif				/* EventMon */

      #define coexp_ser (curpstate->Coexp_ser)
      #define list_ser  (curpstate->List_ser)
      #define set_ser   (curpstate->Set_ser)
      #define table_ser (curpstate->Table_ser)

      #define curstring (curpstate->stringregion)
      #define curblock  (curpstate->blockregion)
      #define strtotal  (curpstate->stringtotal)
      #define blktotal  (curpstate->blocktotal)

      #define coll_tot  (curpstate->colltot)
      #define coll_stat (curpstate->collstat)
      #define coll_str  (curpstate->collstr)
      #define coll_blk  (curpstate->collblk)

      #define lastop    (curpstate->Lastop)
      #define lastopnd  (curpstate->Lastopnd)

      #define xargp     (curpstate->Xargp)
      #define xnargs    (curpstate->Xnargs)

      #define k_current     (curpstate->K_current)
      #define k_errornumber (curpstate->K_errornumber)
      #define k_errortext   (curpstate->K_errortext)
      #define k_errorvalue  (curpstate->K_errorvalue)
      #define have_errval   (curpstate->Have_errval)
      #define t_errornumber (curpstate->T_errornumber)
      #define t_have_val    (curpstate->T_have_val)
      #define t_errorvalue  (curpstate->T_errorvalue)

      #define k_main        (curpstate->K_main)
      #define k_errout      (curpstate->K_errout)
      #define k_input       (curpstate->K_input)
      #define k_output      (curpstate->K_output)

      #define ENTERPSTATE(p) if (((p)!=NULL)) { curpstate = (p); }
   #endif				/* MultiThread */

#endif					/* COMPILER */

/*
 * Constants controlling expression evaluation.
 */
#if COMPILER
   #define A_Resume	-1	/* expression failed: resume a generator */
   #define A_Continue	-2	/* expression returned: continue execution */
   #define A_FallThru	-3      /* body function: fell through end of code */
   #define A_Coact	1	/* co-expression activation */
   #define A_Coret	2	/* co-expression return */
   #define A_Cofail	3	/* co-expression failure */
#else					/* COMPILER */
   #define A_Resume	1	/* routine failed */
   #define A_Pret_uw	2	/* interp unwind for Op_Pret */
   #define A_Unmark_uw	3	/* interp unwind for Op_Unmark */
   #define A_Pfail_uw	4	/* interp unwind for Op_Pfail */
   #define A_Lsusp_uw	5	/* interp unwind for Op_Lsusp */
   #define A_Eret_uw	6	/* interp unwind for Op_Eret */
   #define A_Continue	7	/* routine returned */
   #define A_Coact	8	/* co-expression activated */
   #define A_Coret	9	/* co-expression returned */
   #define A_Cofail	10	/* co-expression failed */
   #ifdef MultiThread
      #define A_MTEvent	11	/* multithread event */
   #endif				/* MultiThread */
#endif					/* COMPILER */

/*
 * Address of word containing cset bit b (c is a struct descrip of type Cset).
 */
#define CsetPtr(b,c)	(BlkLoc(c)->cset.bits + (((b)&0377) >> LogIntBits))

/****************************************   end ../h/rmacros.h   */


/****************************************  from ../h/rstructs.h:  */

/*
 * Run-time data structures.
 */

/*
 * Structures common to the compiler and interpreter.
 */

/*
 * Run-time error numbers and text.
 */
struct errtab {
   int err_no;			/* error number */
   char *errmsg;		/* error message */
   };

/*
 * Descriptor
 */

struct descrip {		/* descriptor */
   word dword;			/*   type field */
   union {
      word integr;		/*   integer value */
      char *sptr;		/*   pointer to character string */
      union block *bptr;	/*   pointer to a block */
      dptr descptr;		/*   pointer to a descriptor */
      } vword;
   };

struct sdescrip {
   word length;			/*   length of string */
   char *string;		/*   pointer to string */
   };

#ifdef LargeInts
struct b_bignum {		/* large integer block */
   word title;			/*   T_Lrgint */
   word blksize;		/*   block size */
   word msd, lsd;		/*   most and least significant digits */
   int sign;			/*   sign; 0 positive, 1 negative */
   DIGIT digits[1];		/*   digits */
   };
#endif					/* LargeInts */

struct b_real {			/* real block */
   word title;			/*   T_Real */
   double realval;		/*   value */
   };

struct b_cset {			/* cset block */
   word title;			/*   T_Cset */
   word size;			/*   size of cset */
   unsigned int bits[CsetSize];		/*   array of bits */
   };

struct b_file {			/* file block */
   word title;			/*   T_File */
   FILE *fd;			/*   Unix file descriptor */
   word status;			/*   file status */
   struct descrip fname;	/*   file name (string qualifier) */
   };

struct b_lelem {		/* list-element block */
   word title;			/*   T_Lelem */
   word blksize;		/*   size of block */
   union block *listprev;	/*   previous list-element block */
   union block *listnext;	/*   next list-element block */
   word nslots;			/*   total number of slots */
   word first;			/*   index of first used slot */
   word nused;			/*   number of used slots */
   struct descrip lslots[1];	/*   array of slots */
   };

struct b_list {			/* list-header block */
   word title;			/*   T_List */
   word size;			/*   current list size */
   word id;			/*   identification number */
   union block *listhead;	/*   pointer to first list-element block */
   union block *listtail;	/*   pointer to last list-element block */
   };

struct b_proc {			/* procedure block */
   word title;			/*   T_Proc */
   word blksize;		/*   size of block */

   #if COMPILER
      int (*ccode)();
   #else				/* COMPILER */
      union {			/*   entry points for */
         int (*ccode)();	/*     C routines */
         uword ioff;		/*     and icode as offset */
         pointer icode;		/*     and icode as absolute pointer */
         } entryp;
   #endif				/* COMPILER */

   word nparam;			/*   number of parameters */
   word ndynam;			/*   number of dynamic locals */
   word nstatic;		/*   number of static locals */
   word fstatic;		/*   index (in global table) of first static */

   struct descrip pname;	/*   procedure name (string qualifier) */
   struct descrip lnames[1];	/*   list of local names (qualifiers) */
   };

struct b_record {		/* record block */
   word title;			/*   T_Record */
   word blksize;		/*   size of block */
   word id;			/*   identification number */
   union block *recdesc;	/*   pointer to record constructor */
   struct descrip fields[1];	/*   fields */
   };

/*
 * Alternate uses for procedure block fields, applied to records.
 */
#define nfields	nparam		/* number of fields */
#define recnum nstatic		/* record number */
#define recid fstatic		/* record serial number */
#define recname	pname		/* record name */

struct b_selem {		/* set-element block */
   word title;			/*   T_Selem */
   union block *clink;		/*   hash chain link */
   uword hashnum;		/*   hash number */
   struct descrip setmem;	/*   the element */
   };

/*
 * A set header must be a proper prefix of a table header,
 *  and a set element must be a proper prefix of a table element.
 */
struct b_set {			/* set-header block */
   word title;			/*   T_Set */
   word size;			/*   size of the set */
   word id;			/*   identification number */
   word mask;			/*   mask for slot num, equals n slots - 1 */
   struct b_slots *hdir[HSegs];	/*   directory of hash slot segments */
   };

struct b_table {		/* table-header block */
   word title;			/*   T_Table */
   word size;			/*   current table size */
   word id;			/*   identification number */
   word mask;			/*   mask for slot num, equals n slots - 1 */
   struct b_slots *hdir[HSegs];	/*   directory of hash slot segments */
   struct descrip defvalue;	/*   default table element value */
   };

struct b_slots {		/* set/table hash slots */
   word title;			/*   T_Slots */
   word blksize;		/*   size of block */
   union block *hslots[HSlots];	/*   array of slots (HSlots * 2^n entries) */
   };

struct b_telem {		/* table-element block */
   word title;			/*   T_Telem */
   union block *clink;		/*   hash chain link */
   uword hashnum;		/*   for ordering chain */
   struct descrip tref;		/*   entry value */
   struct descrip tval;		/*   assigned value */
   };

struct b_tvsubs {		/* substring trapped variable block */
   word title;			/*   T_Tvsubs */
   word sslen;			/*   length of substring */
   word sspos;			/*   position of substring */
   struct descrip ssvar;	/*   variable that substring is from */
   };

struct b_tvtbl {		/* table element trapped variable block */
   word title;			/*   T_Tvtbl */
   union block *clink;		/*   pointer to table header block */
   uword hashnum;		/*   hash number */
   struct descrip tref;		/*   entry value */
   };

struct b_external {		/* external block */
   word title;			/*   T_External */
   word blksize;		/*   size of block */
   word exdata[1];		/*   words of external data */
   };

struct astkblk {		  /* co-expression activator-stack block */
   int nactivators;		  /*   valid activator entries in this block */
   struct astkblk *astk_nxt;	  /*   next activator block */
   struct actrec {		  /*   activator record */
      word acount;		  /*     number of calls by this activator */
      struct b_coexpr *activator; /*     the activator itself */
      } arec[ActStkBlkEnts];
   };

/*
 * Structure for keeping set/table generator state across a suspension.
 */
struct hgstate {		/* hashed-structure generator state */
   int segnum;			/* current segment number */
   word slotnum;		/* current slot number */
   word tmask;			/* structure mask before suspension */
   word sgmask[HSegs];		/* mask in use when the segment was created */
   uword sghash[HSegs];		/* hashnum in process when seg was created */
   };

/*
 * Structure for chaining tended descriptors.
 */
struct tend_desc {
   struct tend_desc *previous;
   int num;
   struct descrip d[1]; /* actual size of array indicated by num */
   };

/*
 * Structure for mapping string names of functions and operators to block
 * addresses.
 */
struct pstrnm {
   char *pstrep;
   struct b_proc *pblock;
   };

struct dpair {
   struct descrip dr;
   struct descrip dv;
   };

/*
 * Allocated memory region structure.  Each program has linked lists of
 * string and block regions.
 */
struct region {
   word  size;				/* allocated region size in bytes */
   char *base;				/* start of region */
   char *end;				/* end of region */
   char *free;				/* free pointer */
   struct region *prev, *next;		/* forms a linked list of regions */
   struct region *Gprev, *Gnext;	/* global (all programs) lists */
   };

#ifdef Double
   /*
    * Data type the same size as a double but without alignment requirements.
    */
   struct size_dbl {
      char s[sizeof(double)];
      };
#endif					/* Double */

#if COMPILER

/*
 * Structures for the compiler.
 */
   struct p_frame {
      struct p_frame *old_pfp;
      struct descrip *old_argp;
      struct descrip *rslt;
      continuation succ_cont;
      struct tend_desc tend;
      };
   #endif				/* COMPILER */

/*
 * when debugging is enabled a debug struct is placed after the tended
 *  descriptors in the procedure frame.
 */
struct debug {
   struct b_proc *proc;
   char *old_fname;
   int old_line;
   };

union numeric {			/* long integers or real numbers */
   long integer;
   double real;
   #ifdef LargeInts
      struct b_bignum *big;
   #endif				/* LargeInts */
   };

#if COMPILER
struct b_coexpr {		/* co-expression stack block */
   word title;			/*   T_Coexpr */
   word size;			/*   number of results produced */
   word id;			/*   identification number */
   struct b_coexpr *nextstk;	/*   pointer to next allocated stack */
   continuation fnc;		/*   function containing co-expression code */
   struct p_frame *es_pfp;	/*   current procedure frame pointer */
   dptr es_argp;		/*   current argument pointer */
   struct tend_desc *es_tend;	/*   current tended pointer */
   char *file_name;		/*   current file name */
   word line_num;		/*   current line_number */
   dptr tvalloc;		/*   where to place transmitted value */
   struct descrip freshblk;	/*   refresh block pointer */
   struct astkblk *es_actstk;	/*   pointer to activation stack structure */
   word cstate[CStateSize];	/*   C state information */
   struct p_frame pf;           /*   initial procedure frame */
   };

struct b_refresh {		/* co-expression block */
   word title;			/*   T_Refresh */
   word blksize;		/*   size of block */
   word nlocals;		/*   number of local variables */
   word nargs;			/*   number of arguments */
   word ntemps;                 /*   number of temporary descriptors */
   word wrk_size;		/*   size of non-descriptor work area */
   struct descrip elems[1];	/*   locals and arguments */
   };

#else					/* COMPILER */

/*
 * Structures for the interpreter.
 */

/*
 * Declarations for entries in tables associating icode location with
 *  source program location.
 */
struct ipc_fname {
   word ipc;		/* offset of instruction into code region */
   word fname;		/* offset of file name into string region */
   };

struct ipc_line {
   word ipc;		/* offset of instruction into code region */
   int line;		/* line number */
   };

#ifdef MultiThread
/*
 * Program state encapsulation.  This consists of the VARIABLE parts of
 * many global structures.
 */
struct progstate {
   long hsize;				/* size of the icode */
   struct progstate *parent;
   struct descrip parentdesc;		/* implicit "&parent" */
   struct descrip eventmask;		/* implicit "&eventmask" */
   struct descrip opcodemask;		/* implicit "&opcodemask" */
   struct descrip eventcode;		/* &eventcode */
   struct descrip eventval;		/* &eventval */
   struct descrip eventsource;		/* &eventsource */
   dptr Glbl_argp;			/* global argp */

   /*
    * trapped variable keywords' values
    */
   struct descrip Kywd_err;
   struct descrip Kywd_pos;
   struct descrip ksub;
   struct descrip Kywd_prog;
   struct descrip Kywd_ran;
   struct descrip Kywd_trc;
   struct b_coexpr *Mainhead;
   char *Code;
   char *Ecode;
   word *Records;
   int *Ftabp;
   #ifdef FieldTableCompression
      short Ftabwidth, Foffwidth;
      unsigned char *Ftabcp, *Focp;
      short *Ftabsp, *Fosp;
      int *Fo;
      char *Bm;
   #endif				/* FieldTableCompression */
   dptr Fnames, Efnames;
   dptr Globals, Eglobals;
   dptr Gnames, Egnames;
   dptr Statics, Estatics;
   int NGlobals, NStatics;
   char *Strcons;
   struct ipc_fname *Filenms, *Efilenms;
   struct ipc_line *Ilines, *Elines;
   struct ipc_line * Current_line_ptr;

   #ifdef Graphics
      struct descrip AmperX, AmperY, AmperRow, AmperCol;/* &x, &y, &row, &col */
      struct descrip AmperInterval;			/* &interval */
      struct descrip LastEventWin;			/* last Event() win */
      int LastEvFWidth;
      int LastEvLeading;
      int LastEvAscent;
      uword PrevTimeStamp;				/* previous timestamp */
      uword Xmod_Control, Xmod_Shift, Xmod_Meta;	/* control,shift,meta */
      struct descrip Kywd_xwin[2];			/* &window + ... */
   #endif				/* Graphics */

   #ifdef EventMon
      word Linenum, Column, Lastline, Lastcol;
   #endif				/* EventMon */

   word Coexp_ser;			/* this program's serial numbers */
   word List_ser;
   word Set_ser;
   word Table_ser;

   uword stringtotal;			/* cumulative total allocation */
   uword blocktotal;			/* cumulative total allocation */
   word colltot;			/* total number of collections */
   word collstat;			/* number of static collect requests */
   word collstr;			/* number of string collect requests */
   word collblk;			/* number of block collect requests */
   struct region *stringregion;
   struct region *blockregion;

   word Lastop;

   dptr Xargp;
   word Xnargs;

   struct descrip K_current;
   int K_errornumber;
   char *K_errortext;
   struct descrip K_errorvalue;
   int Have_errval;
   int T_errornumber;
   int T_have_val;
   struct descrip T_errorvalue;

   struct descrip K_main;
   struct b_file K_errout;
   struct b_file K_input;
   struct b_file K_output;
   };

#endif					/* MultiThread */

/*
 * Frame markers
 */
struct ef_marker {		/* expression frame marker */
   inst ef_failure;		/*   failure ipc */
   struct ef_marker *ef_efp;	/*   efp */
   struct gf_marker *ef_gfp;	/*   gfp */
   word ef_ilevel;		/*   ilevel */
   };

struct pf_marker {		/* procedure frame marker */
   word pf_nargs;		/*   number of arguments */
   struct pf_marker *pf_pfp;	/*   saved pfp */
   struct ef_marker *pf_efp;	/*   saved efp */
   struct gf_marker *pf_gfp;	/*   saved gfp */
   dptr pf_argp;		/*   saved argp */
   inst pf_ipc;			/*   saved ipc */
   word pf_ilevel;		/*   saved ilevel */
   dptr pf_scan;		/*   saved scanning environment */

   #ifdef MultiThread
      struct progstate *pf_prog;/*   saved program state pointer */
   #endif				/* MultiThread */

   struct descrip pf_locals[1];	/*   descriptors for locals */
   };

struct gf_marker {		/* generator frame marker */
   word gf_gentype;		/*   type */
   struct ef_marker *gf_efp;	/*   efp */
   struct gf_marker *gf_gfp;	/*   gfp */
   inst gf_ipc;			/*   ipc */
   struct pf_marker *gf_pfp;	/*   pfp */
   dptr gf_argp;		/*   argp */
   };

/*
 * Generator frame marker dummy -- used only for sizing "small"
 *  generator frames where procedure information need not be saved.
 *  The first five members here *must* be identical to those for
 *  gf_marker.
 */
struct gf_smallmarker {		/* generator frame marker */
   word gf_gentype;		/*   type */
   struct ef_marker *gf_efp;	/*   efp */
   struct gf_marker *gf_gfp;	/*   gfp */
   inst gf_ipc;			/*   ipc */
   };

/*
 * b_iproc blocks are used to statically initialize information about
 *  functions.	They are identical to b_proc blocks except for
 *  the pname field which is a sdescrip (simple/string descriptor) instead
 *  of a descrip.  This is done because unions cannot be initialized.
 */

struct b_iproc {		/* procedure block */
   word ip_title;		/*   T_Proc */
   word ip_blksize;		/*   size of block */
   int (*ip_entryp)();		/*   entry point (code) */
   word ip_nparam;		/*   number of parameters */
   word ip_ndynam;		/*   number of dynamic locals */
   word ip_nstatic;		/*   number of static locals */
   word ip_fstatic;		/*   index (in global table) of first static */

   struct sdescrip ip_pname;	/*   procedure name (string qualifier) */
   struct descrip ip_lnames[1];	/*   list of local names (qualifiers) */
   };

struct b_coexpr {		/* co-expression stack block */
   word title;			/*   T_Coexpr */
   word size;			/*   number of results produced */
   word id;			/*   identification number */
   struct b_coexpr *nextstk;	/*   pointer to next allocated stack */
   struct pf_marker *es_pfp;	/*   current pfp */
   struct ef_marker *es_efp;	/*   efp */
   struct gf_marker *es_gfp;	/*   gfp */
   struct tend_desc *es_tend;	/*   current tended pointer */
   dptr es_argp;		/*   argp */
   inst es_ipc;			/*   ipc */
   word es_ilevel;		/*   interpreter level */
   word *es_sp;			/*   sp */
   dptr tvalloc;		/*   where to place transmitted value */
   struct descrip freshblk;	/*   refresh block pointer */
   struct astkblk *es_actstk;	/*   pointer to activation stack structure */

   #ifdef MultiThread
      struct progstate *program;
   #endif				/* MultiThread */

   word cstate[CStateSize];	/*   C state information */
   };

struct b_refresh {		/* co-expression block */
   word title;			/*   T_Refresh */
   word blksize;		/*   size of block */
   word *ep;			/*   entry point */
   word numlocals;		/*   number of locals */
   struct pf_marker pfmkr;	/*   marker for enclosing procedure */
   struct descrip elems[1];	/*   arguments and locals, including Arg0 */
   };

#endif					/* COMPILER */

union block {			/* general block */
   struct b_real realblk;
   struct b_cset cset;
   struct b_file file;
   struct b_proc proc;
   struct b_list list;
   struct b_lelem lelem;
   struct b_table table;
   struct b_telem telem;
   struct b_set set;
   struct b_selem selem;
   struct b_record record;
   struct b_tvsubs tvsubs;
   struct b_tvtbl tvtbl;
   struct b_refresh refresh;
   struct b_coexpr coexpr;
   struct b_external externl;
   struct b_slots slots;

   #ifdef LargeInts
      struct b_bignum bignumblk;
   #endif				/* LargeInts */
   };

/****************************************   end ../h/rstructs.h   */

#ifdef Graphics


/****************************************  from ../h/graphics.h:  */

/*
 * graphics.h - macros and types used in Icon's graphics interface.
 */

#ifdef XWindows


/****************************************  from ../h/xwin.h:  */

#ifdef XWindows

#define DRAWOP_AND			GXand
#define DRAWOP_ANDINVERTED		GXandInverted
#define DRAWOP_ANDREVERSE		GXandReverse
#define DRAWOP_CLEAR			GXclear
#define DRAWOP_COPY			GXcopy
#define DRAWOP_COPYINVERTED		GXcopyInverted
#define DRAWOP_EQUIV			GXequiv
#define DRAWOP_INVERT			GXinvert
#define DRAWOP_NAND			GXnand
#define DRAWOP_NOOP			GXnoop
#define DRAWOP_NOR			GXnor
#define DRAWOP_OR			GXor
#define DRAWOP_ORINVERTED		GXorInverted
#define DRAWOP_ORREVERSE		GXorReverse
#define DRAWOP_REVERSE			0x10
#define DRAWOP_SET			GXset
#define DRAWOP_XOR			GXxor

#define XLFD_Foundry	 1
#define XLFD_Family	 2
#define XLFD_Weight	 3
#define XLFD_Slant	 4
#define XLFD_SetWidth	 5
#define XLFD_AddStyle	 6
#define XLFD_Size	 7
#define XLFD_PointSize	 8
#define XLFD_Spacing	11
#define XLFD_CharSet	13

#define TEXTWIDTH(w,s,n) XTextWidth((w)->context->font->fsp, s, n)
#define SCREENDEPTH(w)\
        DefaultDepth((w)->window->display->display, w->window->display->screen)
#define ASCENT(w) ((w)->context->font->fsp->ascent)
#define DESCENT(w) ((w)->context->font->fsp->descent)
#define LEADING(w) ((w)->context->leading)
#define FHEIGHT(w) ((w)->context->font->height)
#define FWIDTH(w) ((w)->context->font->fsp->max_bounds.width)
#define LINEWIDTH(w) ((w)->context->linewidth)
#define DISPLAYHEIGHT(w)\
        DisplayHeight(w->window->display->display, w->window->display->screen)
#define DISPLAYWIDTH(w)\
        DisplayWidth(w->window->display->display, w->window->display->screen)
#define FS_SOLID FillSolid
#define FS_STIPPLE FillStippled
#define hidecrsr(x) /* noop */
#define UpdateCursorPos(x, y) /* noop */
#define showcrsr(x) /* noop */
#define SysColor XColor
#define ARCWIDTH(arc) ((arc).width)
#define ARCHEIGHT(arc) ((arc).height)
#define RECX(rec) ((rec).x)
#define RECY(rec) ((rec).y)
#define RECWIDTH(rec) ((rec).width)
#define RECHEIGHT(rec) ((rec).height)
#define ANGLE(ang) (-(ang) * 180 / Pi * 64)
#define EXTENT(ang) (-(ang) * 180 / Pi * 64)
#define ISICONIC(w) ((w)->window->iconic == IconicState)
#define ISFULLSCREEN(w) (0)
#define ISROOTWIN(w) ((w)->window->iconic == RootState)
#define ISNORMALWINDOW(w) ((w)->window->iconic == NormalState)
#define ICONFILENAME(w) ((w)->window->iconimage)
#define ICONLABEL(w) ((w)->window->iconlabel)
#define WINDOWLABEL(w) ((w)->window->windowlabel)
#define RootState IconicState+1
#define MaximizedState IconicState+2
#define HiddenState IconicState+3

/*
 * The following constants define limitations in the system, gradually being
 * removed as this code is rewritten to use dynamic allocation.
 */
#define WMAXCOLORS	256
#define MAXCOLORNAME	40
#define MAXDISPLAYNAME	64
#define SHARED          0
#define MUTABLE         1
#define NUMCURSORSYMS	78

/*
 * Macros to ease coding in which every X call must be done twice.
 */
#define RENDER2(func,v1,v2) {\
   if (stdwin) func(stddpy, stdwin, stdgc, v1, v2); \
   func(stddpy, stdpix, stdgc, v1, v2);}
#define RENDER3(func,v1,v2,v3) {\
   if (stdwin) func(stddpy, stdwin, stdgc, v1, v2, v3); \
   func(stddpy, stdpix, stdgc, v1, v2, v3);}
#define RENDER4(func,v1,v2,v3,v4) {\
   if (stdwin) func(stddpy, stdwin, stdgc, v1, v2, v3, v4); \
   func(stddpy, stdpix, stdgc, v1, v2, v3, v4);}
#define RENDER6(func,v1,v2,v3,v4,v5,v6) {\
   if (stdwin) func(stddpy, stdwin, stdgc, v1, v2, v3, v4, v5, v6); \
   func(stddpy, stdpix, stdgc, v1, v2, v3, v4, v5, v6);}
#define RENDER7(func,v1,v2,v3,v4,v5,v6,v7) {\
   if (stdwin) func(stddpy, stdwin, stdgc, v1, v2, v3, v4, v5, v6, v7); \
   func(stddpy, stdpix, stdgc, v1, v2, v3, v4, v5, v6, v7);}

#define MAXDESCENDER(w) (w->context->font->fsp->max_bounds.descent)

/*
 * Macros to perform direct window system calls from graphics routines
 */
#define STDLOCALS(w) \
   wcp wc = (w)->context; \
   wsp ws = (w)->window; \
   wdp wd = ws->display; \
   GC      stdgc  = wc->gc; \
   Display *stddpy = wd->display; \
   Window  stdwin  = ws->win; \
   Pixmap  stdpix  = ws->pix;

#define drawarcs(w, arcs, narcs) \
   { STDLOCALS(w); RENDER2(XDrawArcs,arcs,narcs); }
#define drawlines(w, points, npoints) \
   { STDLOCALS(w); RENDER3(XDrawLines,points,npoints,CoordModeOrigin); }
#define drawpoints(w, points, npoints) \
   { STDLOCALS(w); RENDER3(XDrawPoints,points,npoints,CoordModeOrigin); }
#define drawrectangles(w, recs, nrecs) { \
   STDLOCALS(w); \
   for(i=0; i<nrecs; i++) { \
     RENDER4(XDrawRectangle,recs[i].x,recs[i].y,recs[i].width,recs[i].height);\
     }}

#define drawsegments(w, segs, nsegs) \
   { STDLOCALS(w); RENDER2(XDrawSegments,segs,nsegs); }
#define drawstrng(w, x, y, s, slen) \
   { STDLOCALS(w); RENDER4(XDrawString, x, y, s, slen); }
#define fillarcs(w, arcs, narcs) \
   { STDLOCALS(w); RENDER2(XFillArcs, arcs, narcs); }
#define fillpolygon(w, points, npoints) \
   { STDLOCALS(w); RENDER4(XFillPolygon, points, npoints, Complex, CoordModeOrigin); }

/*
 * "get" means remove them from the Icon list and put them on the ghost queue
 */
#define EVQUEGET(w,d) { \
   int i;\
   wsp ws = (w)->window; \
   if (!c_get((struct b_list *)BlkLoc(ws->listp),&d)) fatalerr(0,NULL); \
   if (Qual(d)) {\
      ws->eventQueue[ws->eQfront++] = *StrLoc(d); \
      if (ws->eQfront >= EQUEUELEN) ws->eQfront = 0; \
      ws->eQback = ws->eQfront; \
      } \
   }
#define EVQUEEMPTY(w) (BlkLoc((w)->window->listp)->list.size == 0)

/*
 * Colors.  These are allocated within displays. Pointers
 * into the display's color table are also kept on a per-window
 * basis so that they may be (de)allocated when a window is cleared.
 * Colors are aliased by r,g,b value.  Allocations by name and r,g,b
 * share when appropriate.
 *
 * Color (de)allocation comprises a simple majority of the space
 * requirements of the current implementation.  A monochrome-only
 * version would take a lot less space.
 *
 * The name field is the string returned by WAttrib.  For a mutable
 * color this is of the form "-47" followed by a second C string
 * containing the current color setting.
 */
typedef struct wcolor {
   unsigned long c;			/* X pixel value */
   int		refcount;		/* reference count */
   int		type;			/* SHARED or MUTABLE */
   int		next;			/* next entry in hash chain */
   unsigned short r, g, b;		/* rgb for colorsearch */
   char		name[6+MAXCOLORNAME];	/* name for WAttrib & WColor reads */
} *wclrp;

/*
 * macros performing row/column to pixel y,x translations
 * computation is 1-based and depends on the current font's size.
 * exception: XTOCOL as defined is 0-based, because that's what its
 * clients seem to need.
 */
#define ROWTOY(w,row) ((row-1) * LEADING(w) + ASCENT(w))
#define COLTOX(w,col) ((col-1) * FWIDTH(w))
#define YTOROW(w,y)   ((y>0) ? ((y) / LEADING(w) + 1) : ((y) / LEADING(w)))
#define XTOCOL(w,x)  (!FWIDTH(w) ? (x) : ((x) / FWIDTH(w)))

#define STDLOCALS(w) \
   wcp wc = (w)->context; \
   wsp ws = (w)->window; \
   wdp wd = ws->display; \
   GC      stdgc  = wc->gc; \
   Display *stddpy = wd->display; \
   Window  stdwin  = ws->win; \
   Pixmap  stdpix  = ws->pix;

#endif					/* XWindows */

/****************************************   end ../h/xwin.h   */
#endif					/* XWindows */

#ifdef WinGraphics


/****************************************  from ../h/mswin.h:  */

/*
 * mswin.h - macros and types used in the MS Windows graphics interface.
 */

#define DRAWOP_AND			R2_MASKPEN
#define DRAWOP_ANDINVERTED		R2_MASKNOTPEN
#define DRAWOP_ANDREVERSE		R2_NOTMASKPEN
#define DRAWOP_CLEAR			R2_BLACK
#define DRAWOP_COPY			R2_COPYPEN
#define DRAWOP_COPYINVERTED		R2_NOTCOPYPEN
#define DRAWOP_EQUIV			R2_NOTXORPEN
#define DRAWOP_INVERT			R2_NOT
#define DRAWOP_NAND			R2_MASKNOTPEN
#define DRAWOP_NOOP			R2_NOP
#define DRAWOP_NOR			R2_MERGENOTPEN
#define DRAWOP_OR			R2_MERGEPEN
#define DRAWOP_ORINVERTED		R2_MERGEPENNOT
#define DRAWOP_ORREVERSE		R2_NOTMERGEPEN
#define DRAWOP_REVERSE			R2_USER1
#define DRAWOP_SET			R2_WHITE
#define DRAWOP_XOR			R2_XORPEN

#define TEXTWIDTH(w,s,n) textWidth(w, s, n)
#define SCREENDEPTH(w) getdepth(w)
#define ASCENT(w)  ((w)->context->font->ascent)
#define ASCENTC(wc)  ((wc)->font->ascent)
#define DESCENT(w) ((w)->context->font->descent)
#define LEADING(w) ((w)->context->leading)
#define FHEIGHT(w) ((w)->context->font->height)
#define FHEIGHTC(wc) ((wc)->font->height)
#define FWIDTH(w)  ((w)->context->font->charwidth)
#define FWIDTHC(wc)  ((wc)->font->charwidth)
#define LINEWIDTH(w) ((w)->context->pen.lopnWidth.x)
#define DISPLAYHEIGHT(w) devicecaps(w, VERTRES)
#define DISPLAYWIDTH(w) devicecaps(w, HORZRES)
#define wsync(w) /* noop */
#define SysColor unsigned long
#define RED(x) GetRValue(x)
#define GREEN(x) GetGValue(x)
#define BLUE(x) GetBValue(x)
#define ARCWIDTH(arc) (arc).width
#define ARCHEIGHT(arc) (arc).height
/*
 * These get fixed up in the window-system-specific code
 */
#define RECX(rec) (rec).left
#define RECY(rec) (rec).top
#define RECWIDTH(rec) (rec).right
#define RECHEIGHT(rec) (rec).bottom
/*
 *
 */
#define ANGLE(ang) (ang)
#define EXTENT(ang) (ang)
#define FULLARC 2 * Pi
#define ISICONIC(w) (IsIconic((w)->window->iconwin))
#define ISFULLSCREEN(w) 0
#define ISROOTWIN(w) (0) 0
#define ISNORMALWINDOW(w) 0
#define ICONFILENAME(w) ""
#define ICONLABEL(w) ((w)->window->iconlabel)
#define WINDOWLABEL(w) ((w)->window->windowlabel)

#define MAXDESCENDER(w) DESCENT(w)

/*
 * gemeotry bitmasks
 */
#define GEOM_WIDTH           1
#define GEOM_HEIGHT          2
#define GEOM_POSX            4
#define GEOM_POSY            8
/*
 * fill styles
 */
#define FS_SOLID             1
#define FS_STIPPLE           2
#define FS_OPAQUESTIPPLE     4
/*
 * the special ROP code for mode reverse
 */
#define R2_USER1            (R2_LAST << 1)
/*
 * window states
 */
#define WS_NORMAL            0
#define WS_MIN               1
#define WS_MAX               2

/*
 * input masks
 */
#define PointerMotionMask    1

/*
 * something I think should be #defined
 */
#define EOS                  '\0'

/* size of the working buffer, used for dialog messages and such */
#define PMSTRBUFSIZE         2048
/*
 * the bitmasks for the modifier keys
 */
#define ControlMask          (1L << 16L)
#define Mod1Mask             (2L << 16L)
#define ShiftMask            (4L << 16L)
#define VirtKeyMask          (8L << 16L)

/* some macros for Windows */

#define MAKERGB(r,g,b) RGB(r,g,b)
#define RGB16TO8(x) if ((x) > 0xff) (x) = (((x) >> 8) & 0xff)
#define hidecrsr(ws) if (ws->hasCaret) HideCaret(ws->iconwin)
#define showcrsr(ws) if (ws->hasCaret) ShowCaret(ws->iconwin)
#define FNTWIDTH(size) ((size) & 0xFFFF)
#define FNTHEIGHT(size) ((size) >> 16)
#define MAKEFNTSIZE(height, width) (((height) << 16) | (width))
#define WaitForEvent(msgnum, msgstruc) ObtainEvents(NULL, WAIT_EVT, msgnum, msgstruc)

/*
 * "get" means remove them from the Icon list and put them on the ghost que
 */
#define EVQUEGET(ws,d) { \
  int i;\
  if (!c_get((struct b_list *)BlkLoc((ws)->listp),&d)) fatalerr(0,NULL); \
  if (Qual(d)) {\
      (ws)->eventQueue[(ws)->eQfront++] = *StrLoc(d); \
      if ((ws)->eQfront >= EQUEUELEN) (ws)->eQfront = 0; \
      (ws)->eQback = (ws)->eQfront; \
      } \
  }
#define EVQUEEMPTY(ws) (BlkLoc((ws)->listp)->list.size == 0)

#define SHARED          0
#define MUTABLE         1
#define MAXCOLORNAME	40
/*
 * color structure, inspired by X code (xwin.h)
 */
typedef struct wcolor {
  int		refcount;
  char		name[6+MAXCOLORNAME];	/* name for WAttrib & WColor reads */
  SysColor	c;
  int           type;			/* SHARED or MUTABLE */
} *wclrp;

/*
 * we make the segment structure look like this so that we can
 * cast it to POINTL structures that can be passed to GpiPolyLineDisjoint
 */
typedef struct {
   LONG x1, y1;
   LONG x2, y2;
   } XSegment;

typedef POINT XPoint;
typedef RECT XRectangle;

typedef struct {
  LONG x, y;
  LONG width, height;
  double angle1, angle2;
  } XArc;

/*
 * macros performing row/column to pixel y,x translations
 * computation is 1-based and depends on the current font's size.
 * exception: XTOCOL as defined is 0-based, because that's what its
 * clients seem to need.
 */
#define ROWTOY(wb, row)  ((row - 1) * LEADING(wb) + ASCENT(wb))
#define COLTOX(wb, col)  ((col - 1) * FWIDTH(wb))
#define YTOROW(wb, y)    (((y) - ASCENT(w)) /  LEADING(wb) + 1)
#define XTOCOL(w,x)  (!FWIDTH(w) ? (x) : ((x) / FWIDTH(w)))

/*
 * system size values
 */
#define BORDERWIDTH      (GetSystemMetrics(SM_CXBORDER)) /* 1 */
#define BORDERHEIGHT     (GetSystemMetrics(SM_CYBORDER)) /* 1 */
#define TITLEHEIGHT      (GetSystemMetrics(SM_CYCAPTION)) /* 20 */
#define FRAMEWIDTH	 (GetSystemMetrics(SM_CXFRAME))   /* 4 */
#define FRAMEHEIGHT	 (GetSystemMetrics(SM_CYFRAME))   /* 4 */

#define STDLOCALS(w) \
   wcp wc = (w)->context;\
   wsp ws = (w)->window;\
   HWND stdwin = ws->win;\
   HBITMAP stdpix = ws->pix;\
   HDC stddc = CreateWinDC(w);\
   HDC pixdc = CreatePixDC(w, stddc);

#define STDFONT \
   { if(stdwin)SelectObject(stddc, wc->font->font); SelectObject(pixdc,wc->font->font); }

#define FREE_STDLOCALS(w) do { SelectObject(pixdc, (w)->window->theOldPix); ReleaseDC((w)->window->iconwin, stddc); DeleteDC(pixdc); } while (0)

#define MAXXOBJS 8

#define GammaCorrection 1.0

/****************************************   end ../h/mswin.h   */
#endif					/* WinGraphics */

#ifndef MAXXOBJS
   #define MAXXOBJS 256
#endif					/* MAXXOBJS */

#ifndef MAXCOLORNAME
   #define MAXCOLORNAME 40
#endif					/* MAXCOLORNAME */

#ifndef MAXFONTWORD
   #define MAXFONTWORD 40
#endif					/* MAXFONTWORD */

#define POLLSLEEP	20	 /* milliseconds sleep while awaiting event */

#define DEFAULTFONTSIZE 14

#define FONTATT_SPACING		0x01000000
#define FONTFLAG_MONO		0x00000001
#define FONTFLAG_PROPORTIONAL	0x00000002

#define FONTATT_SERIF		0x02000000
#define FONTFLAG_SANS		0x00000004
#define FONTFLAG_SERIF		0x00000008

#define FONTATT_SLANT		0x04000000
#define FONTFLAG_ROMAN		0x00000010
#define FONTFLAG_ITALIC		0x00000020
#define FONTFLAG_OBLIQUE	0x00000040

#define FONTATT_WEIGHT		0x08000000
#define FONTFLAG_LIGHT		0x00000100
#define FONTFLAG_MEDIUM		0x00000200
#define FONTFLAG_DEMI		0x00000400
#define FONTFLAG_BOLD		0x00000800

#define FONTATT_WIDTH		0x10000000
#define FONTFLAG_CONDENSED	0x00001000
#define FONTFLAG_NARROW		0x00002000
#define FONTFLAG_NORMAL		0x00004000
#define FONTFLAG_WIDE		0x00008000
#define FONTFLAG_EXTENDED	0x00010000

/*
 * EVENT HANDLING
 *
 * Each window keeps an associated queue of events waiting to be
 * processed.  The queue consists of <eventcode,x,y> triples,
 * where eventcodes are strings for normal keyboard events, and
 * integers for mouse and special keystroke events.
 *
 * The main queue is an icon list.  In addition, there is a queue of
 * old keystrokes maintained for cooked mode operations, maintained
 * in a little circular array of chars.
 */
#define EQ_MOD_CONTROL (1L<<16L)
#define EQ_MOD_META    (1L<<17L)
#define EQ_MOD_SHIFT   (1L<<18L)

#define EVQUESUB(w,i) *evquesub(w,i)
#define EQUEUELEN 256

/*
 * mode bits for the Icon window context (as opposed to X context)
 */

#define ISINITIAL(w)    ((w)->window->bits & 1)
#define ISINITIALW(ws)  ((ws)->bits & 1)
#define ISCURSORON(w)   ((w)->window->bits & 2)
#define ISCURSORONW(ws) ((ws->bits) & 2)
#define ISMAPPED(w)	((w)->window->bits & 4)
#define ISREVERSE(w)    ((w)->context->bits & 8)
#define ISXORREVERSE(w)	((w)->context->bits & 16)
#define ISXORREVERSEW(w) ((w)->bits & 16)
#define ISCLOSED(w)	((w)->window->bits & 64)
#define ISRESIZABLE(w)	((w)->window->bits & 128)
#define ISEXPOSED(w)    ((w)->window->bits & 256)
#define ISCEOLON(w)     ((w)->window->bits & 512)
#define ISECHOON(w)     ((w)->window->bits & 1024)

#define SETCURSORON(w)  ((w)->window->bits |= 2)
/* 4 is available */
#define SETMAPPED(w)   ((w)->window->bits |= 4)
#define SETREVERSE(w)   ((w)->context->bits |= 8)
#define SETXORREVERSE(w) ((w)->context->bits |= 16)
#define SETCLOSED(w)	((w)->window->bits |= 64)
#define SETRESIZABLE(w)	((w)->window->bits |= 128)
#define SETEXPOSED(w)   ((w)->window->bits |= 256)
#define SETCEOLON(w)    ((w)->window->bits |= 512)
#define SETECHOON(w)    ((w)->window->bits |= 1024)

#define CLRCURSORON(w)  ((w)->window->bits &= ~2)
#define CLRMAPPED(w)    ((w)->window->bits &= ~4)
#define CLRREVERSE(w)   ((w)->context->bits &= ~8)
#define CLRXORREVERSE(w) ((w)->context->bits &= ~16)
#define CLRCLOSED(w)	((w)->window->bits &= ~64)
#define CLRRESIZABLE(w)	((w)->window->bits &= ~128)
#define CLREXPOSED(w)   ((w)->window->bits &= ~256)
#define CLRCEOLON(w)    ((w)->window->bits &= ~512)
#define CLRECHOON(w)    ((w)->window->bits &= ~1024)

#ifdef XWindows
   #define ISZOMBIE(w)     ((w)->window->bits & 1)
   #define SETZOMBIE(w)    ((w)->window->bits |= 1)
   #define CLRZOMBIE(w)    ((w)->window->bits &= ~1)
#endif					/* XWindows */

#ifdef WinGraphics
   #define ISTOBEHIDDEN(ws)  ((ws)->bits & 4096)
   #define SETTOBEHIDDEN(ws) ((ws)->bits |= 4096)
   #define CLRTOBEHIDDEN(ws) ((ws)->bits &= ~4096)
#endif					/* WinGraphics */

/*
 * Window Resources
 * Icon "Resources" are a layer on top of the window system resources,
 * provided in order to facilitate resource sharing and minimize the
 * number of calls to the window system.  Resources are reference counted.
 * These data structures are simple sets of pointers
 * into internal window system structures.
 */

/*
 * Fonts are allocated within displays.
 */
typedef struct _wfont {
   int		refcount;
   int		serial;			/* serial # */
   struct _wfont *previous, *next;
   char		*name;			/* name for WAttrib and fontsearch */

   #ifdef XWindows
      int	height;			/* font height */
      XFontStruct *fsp;			/* X font pointer */
   #endif				/* XWindows */

   #ifdef WinGraphics
      HFONT	font;
      LONG	ascent;
      LONG	descent;
      LONG	charwidth;
      LONG	height;
   #endif				/* WinGraphics */

   } wfont, *wfp;

/*
 * These structures and definitions are used for colors and images.
 */
typedef struct {
   long red, green, blue;		/* color components, linear 0 - 65535*/
   } LinearColor;

struct palentry {			/* entry for one palette member */
   LinearColor clr;			/* RGB value of color */
   char used;				/* nonzero if char is used */
   char valid;				/* nonzero if entry is valid & opaque */
   char transpt;			/* nonzero if char is transparent */
   };

struct imgdata {			/* image loaded from a file */
   int width, height;			/* image dimensions */
   struct palentry *paltbl;		/* pointer to palette table */
   unsigned char *data;			/* pointer to image data */
   };

struct imgmem {
   int x, y, width, height;

   #ifdef XWindows
      XImage *im;
   #endif				/* XWindows */

   #ifdef WinGraphics
      COLORREF *crp;
   #endif				/* WinGraphics */
   };

#define TCH1 '~'			/* usual transparent character */
#define TCH2 0377			/* alternate transparent character */
#define PCH1 ' '			/* punctuation character */
#define PCH2 ','			/* punctuation character */

#define GIFMAX 256			/* maximum colors in a GIF file */

#ifdef XWindows
/*
 * Displays are maintained in a global list in rwinrsc.r.
 */
typedef struct _wdisplay {
   int		refcount;
   int		serial;			/* serial # */
   char		name[MAXDISPLAYNAME];
   Display *	display;
   Visual *	visual;
   GC		icongc;
   Colormap	cmap;
   double	gamma;
   int		screen;
   int		numFonts;
   wfp		fonts;
   int          numColors;		/* number of allocated color structs */
   int          cpSize;			/* max number of slots before realloc */
   struct wcolor **colrptrs;		/* array of pointers to those colors */
   Cursor	cursors[NUMCURSORSYMS];
   struct _wdisplay *previous, *next;
   } *wdp;
#endif					/* XWindows */

/*
 * "Context" comprises the graphics context, and the font (i.e. text context).
 * Foreground and background colors (pointers into the display color table)
 * are stored here to reduce the number of window system queries.
 * Contexts are allocated out of a global array in rwinrsrc.c.
 */
typedef struct _wcontext {
   int		refcount;
   int		serial;			/* serial # */
   struct _wcontext *previous, *next;
   int		clipx, clipy, clipw, cliph;
   char		*patternname;
   wfp		font;
   int		dx, dy;
   int		fillstyle;
   int		drawop;
   double	gamma;			/* gamma correction value */
   int		bits;			/* context bits */

   #ifdef XWindows
      wdp	display;
      GC	gc;			/* X graphics context */
      wclrp	fg, bg;
      int	linestyle;
      int	linewidth;
      int	leading;		/* inter-line leading */
   #endif				/* XWindows */

   #ifdef WinGraphics
      LOGPEN	pen;
      LOGPEN	bgpen;
      LOGBRUSH	brush;
      LOGBRUSH	bgbrush;
      HRGN	cliprgn;
      HBITMAP	pattern;
      SysColor	fg, bg;
      char	*fgname, *bgname;
      int	leading, bkmode;
   #endif				/* WinGraphics*/

   } wcontext, *wcp;

/*
 * Native facilities include the following child controls (windows) that
 * persist on the canvas and intercept various events.
 */
#ifdef WinGraphics
   #define CHILD_BUTTON 0
   #define CHILD_SCROLLBAR 1
   #define CHILD_EDIT 2
   typedef struct childcontrol {
      int  type;			/* what kind of control? */
      HWND win;				/* child window handle */
      HFONT font;
      char *id;				/* child window string id */
      } childcontrol;
#endif					/* WinGraphics */

/*
 * "Window state" includes the actual X window and references to a large
 * number of resources allocated on a per-window basis.  Windows are
 * allocated out of a global array in rwinrsrc.c.  Windows remember the
 * first WMAXCOLORS colors they allocate, and deallocate them on clearscreen.
 */
typedef struct _wstate {
   int		refcount;		/* reference count */
   int		serial;			/* serial # */
   struct _wstate *previous, *next;
   int		pixheight;		/* backing pixmap height, in pixels */
   int		pixwidth;		/* pixmap width, in pixels */
   char		*windowlabel;		/* window label */
   char		*iconimage;		/* icon pixmap file name */
   char		*iconlabel;		/* icon label */
   struct imgdata initimage;		/* initial image data */
   struct imgdata initicon;		/* initial icon image data */
   int		y, x;			/* current cursor location, in pixels*/
   int		pointery, pointerx;	/* current mouse location, in pixels */
   int		posy, posx;		/* desired upper lefthand corner */
   unsigned int	height;			/* window height, in pixels */
   unsigned int	width;			/* window width, in pixels */
   int		bits;			/* window bits */
   int		theCursor;		/* index into cursor table */
   word		timestamp;		/* last event time stamp */
   char		eventQueue[EQUEUELEN];  /* queue of cooked-mode keystrokes */
   int		eQfront, eQback;
   char		*cursorname;
   struct descrip filep, listp;		/* icon values for this window */

   #ifdef XWindows
      wdp	display;
      Window	win;			/* X window */
      Pixmap	pix;			/* current screen state */
      Pixmap	initialPix;		/* an initial image to display */
      Window	iconwin;		/* icon window */
      Pixmap	iconpix;		/* icon pixmap */
      int	normalx, normaly;	/* pos to remember when maximized */
      int	normalw, normalh;	/* size to remember when maximized */
      int	numColors;		/* allocated color info */
      short	*theColors;		/* indices into display color table */
      int	numiColors;		/* allocated color info for the icon */
      short	*iconColors;		/* indices into display color table */
      int	iconic;			/* window state; icon, window or root*/
      int	iconx, icony;		/* location of icon */
      unsigned int iconw, iconh;	/* width and height of icon */
      long	wmhintflags;		/* window manager hints */
   #endif				/* XWindows */

   #ifdef WinGraphics
      HWND	win;			/* client window */
      HWND	iconwin;		/* client window when iconic */
      HBITMAP	pix;			/* backing bitmap */
      HBITMAP	iconpix;		/* backing bitmap */
      HBITMAP	initialPix;		/* backing bitmap */
      HBITMAP	theOldPix;
      int	hasCaret;
      HCURSOR	curcursor;
      HCURSOR	savedcursor;
      HMENU	menuBar;
      int	nmMapElems;
      char **	menuMap;
      HWND	focusChild;
      int	nChildren;
      childcontrol *child;
   #endif				/* WinGraphics */

   } wstate, *wsp;

/*
 * Icon window file variables are actually pointers to "bindings"
 * of a window and a context.  They are allocated out of a global
 * array in rwinrsrc.c.  There is one binding per Icon window value.
 */
typedef struct _wbinding {
   int refcount;
   int serial;
   struct _wbinding *previous, *next;
   wcp context;
   wsp window;
   } wbinding, *wbp;

/*
 * Table entry for string <-> integer mapping.
 */
typedef struct {
   char *s;
   int i;
   } stringint, *siptr;


/*
 * Gamma Correction value to compensate for nonlinear monitor color response
 */
#ifndef GammaCorrection
   #define GammaCorrection 2.5
#endif					/* GammaCorrection */

/*
 * Attributes
 */
#define A_ASCENT	1
#define A_BG		2
#define A_CANVAS	3
#define A_CEOL		4
#define A_CLIPH		5
#define A_CLIPW		6
#define A_CLIPX		7
#define A_CLIPY		8
#define A_COL		9
#define A_COLUMNS	10
#define A_CURSOR	11
#define A_DEPTH		12
#define A_DESCENT	13
#define A_DISPLAY	14
#define A_DISPLAYHEIGHT	15
#define A_DISPLAYWIDTH	16
#define A_DRAWOP	17
#define A_DX		18
#define A_DY		19
#define A_ECHO		20
#define A_FG		21
#define A_FHEIGHT	22
#define A_FILLSTYLE	23
#define A_FONT		24
#define A_FWIDTH	25
#define A_GAMMA		26
#define A_GEOMETRY	27
#define A_HEIGHT	28
#define A_ICONIC	29
#define A_ICONIMAGE     30
#define A_ICONLABEL	31
#define A_ICONPOS	32
#define A_IMAGE		33
#define A_LABEL		34
#define A_LEADING	35
#define A_LINES		36
#define A_LINESTYLE	37
#define A_LINEWIDTH	38
#define A_PATTERN	39
#define A_POINTERCOL	40
#define A_POINTERROW	41
#define A_POINTERX	42
#define A_POINTERY	43
#define A_POINTER	44
#define A_POS		45
#define A_POSX		46
#define A_POSY		47
#define A_RESIZE	48
#define A_REVERSE	49
#define A_ROW		50
#define A_ROWS		51
#define A_SIZE		52
#define A_VISUAL	53
#define A_WIDTH		54
#define A_WINDOWLABEL   55
#define A_X		56
#define A_Y		57

#define NUMATTRIBS	57

/*
 * flags for ConsoleFlags
 */
/* I/O redirection flags */
#define StdOutRedirect        1
#define StdErrRedirect        2
#define StdInRedirect         4
#define OutputToBuf           8

/****************************************   end ../h/graphics.h   */
#endif					/* Graphics */



/****************************************  from ../h/rexterns.h:  */

/*
 * External declarations for the run-time system.
 */

/*
 * External declarations common to the compiler and interpreter.
 */

extern struct b_proc *op_tbl;   /* operators available for string invocation */
extern int op_tbl_sz;           /* number of operators in op_tbl */
extern int debug_info;		/* flag: debugging information is available */
extern int err_conv;		/* flag: error conversion is supported */
extern int dodump;		/* termination dump */
extern int line_info;		/* flag: line information is available */
extern char *file_name;		/* source file for current execution point */
extern int line_num;		/* line number for current execution point */

extern unsigned char allchars[];/* array for making one-character strings */
extern char *blkname[];		/* print names for block types. */
extern char *currend;		/* current end of memory region */
extern dptr *quallist;		/* start of qualifier list */
extern int bsizes[];		/* sizes of blocks */
extern int firstd[];		/* offset (words) of first descrip. */
extern uword segsize[];		/* size of hash bucket segment */
extern int k_level;		/* value of &level */

extern struct b_coexpr *stklist;/* base of co-expression stack list */
extern struct b_cset blankcs;   /* ' ' */
extern struct b_cset lparcs;    /* '(' */
extern struct b_cset rparcs;    /* ')' */
extern struct b_cset fullcs;    /* cset containing all characters */
extern struct descrip blank;	/* blank */
extern struct descrip emptystr;	/* empty string */

extern struct descrip kywd_dmp; /* descriptor for &dump */
extern struct descrip nullptr;	/* descriptor with null block pointer */
extern struct descrip lcase;	/* lowercase string */
extern struct descrip letr;	/* letter "r" */
extern struct descrip maps2;	/* second argument to map() */
extern struct descrip maps3;	/* third argument to map() */
extern struct descrip nulldesc;	/* null value */
extern struct descrip onedesc;	/* one */
extern struct descrip ucase;	/* uppercase string */
extern struct descrip zerodesc;	/* zero */

extern word mstksize;		/* size of main stack in words */
extern word stksize;		/* size of co-expression stacks in words */
extern word qualsize;		/* size of string qualifier list */
extern word memcushion;		/* memory region cushion factor */
extern word memgrowth;		/* memory region growth factor */
extern uword stattotal;		/* cumulative total of all static allocations */
				/* N.B. not currently set */

extern struct tend_desc *tend;  /* chain of tended descriptors */

/*
 * Externals that are conditional on features.
 */
#ifdef FncTrace
   extern struct descrip kywd_ftrc;	/* descriptor for &ftrace */
#endif					/* FncTrace */

#ifdef Polling
   extern int pollctr;
#endif					/* Polling */

#ifdef EventMon
   extern char typech[];
   extern word oldsum;
   extern struct descrip csetdesc;	/* cset descriptor */
   extern struct descrip eventdesc;	/* event descriptor */
   extern struct b_iproc mt_llist;
   extern struct descrip rzerodesc;	/* real descriptor */
   extern struct b_real realzero;	/* real zero block */
#endif					/* EventMon */

/*
 * Externals conditional on multithreading.
 */
   extern struct region rootstring;
   extern struct region rootblock;
#ifndef MultiThread
   extern dptr glbl_argp;		/* argument pointer */
   extern struct region *curstring;
   extern struct region *curblock;
   extern struct descrip k_current;	/* &current */
   extern char *k_errortext;		/* value of &errortext */
   extern int have_errval;		/* &errorvalue has a legal value */
   extern int k_errornumber;		/* value of &errornumber */
   extern int t_errornumber;		/* tentative k_errornumber value */
   extern int t_have_val;		/* tentative have_errval flag */
   extern struct b_file k_errout;	/* value of &errout */
   extern struct b_file k_input;	/* value of &input */
   extern struct b_file k_output;	/* value of &output */
   extern struct descrip k_errorvalue;	/* value of &errorvalue */
   extern struct descrip kywd_err;	/* &error */
   extern struct descrip kywd_pos;	/* descriptor for &pos */
   extern struct descrip kywd_prog;	/* descriptor for &prog */
   extern struct descrip kywd_ran;	/* descriptor for &random */
   extern struct descrip k_subject;	/* &subject */
   extern struct descrip kywd_trc;	/* descriptor for &trace */
   extern struct descrip k_eventcode;	/* &eventcode */
   extern struct descrip k_eventsource;	/* &eventsource */
   extern struct descrip k_eventvalue;	/* &eventvalue */
   extern struct descrip k_main;	/* value of &main */
   extern struct descrip t_errorvalue;	/* tentative k_errorvalue value */
   extern uword blktotal;		/* cumul total of all block allocs */
   extern uword strtotal;		/* cumul total of all string allocs */
   extern word coll_tot;		/* total number of collections */
   extern word coll_stat;		/* collections from static reqests */
   extern word coll_str;		/* collections from string requests */
   extern word coll_blk;		/* collections from block requests */
   extern dptr globals;			/* start of global variables */
   extern dptr eglobals;		/* end of global variables */
   extern dptr gnames;			/* start of global variable names */
   extern dptr egnames;			/* end of global variable names */
   extern dptr estatics;		/* end of static variables */
   extern int n_globals;		/* number of global variables */
   extern int n_statics;		/* number of static variables */
   extern struct b_coexpr *mainhead;	/* &main */
#endif					/* MultiThread */

/*
 * Externals that differ between compiler and interpreter.
 */
#if !COMPILER
   /*
    * External declarations for the interpreter.
    */

   extern int ixinited;			/* iconx has initialized */
   extern inst ipc;			/* interpreter program counter */
   extern int ilevel;			/* interpreter level */
   extern int ntended;			/* number of active tended descriptors*/
   extern struct b_cset k_ascii;	/* value of &ascii */
   extern struct b_cset k_cset;		/* value of &cset */
   extern struct b_cset k_digits;	/* value of &lcase */
   extern struct b_cset k_lcase;	/* value of &lcase */
   extern struct b_cset k_letters;	/* value of &letters */
   extern struct b_cset k_ucase;	/* value of &ucase */
   extern struct descrip tended[];	/* tended descriptors */
   extern struct ef_marker *efp;	/* expression frame pointer */
   extern struct gf_marker *gfp;	/* generator frame pointer */
   extern struct pf_marker *pfp;	/* procedure frame pointer */
   extern word *sp;			/* interpreter stack pointer */
   extern word *stack;			/* interpreter stack base */
   extern word *stackend;		/* end of evaluation stack */

   extern struct pstrnm pntab[];
   extern int pnsize;

   #ifdef MultiThread
      extern struct progstate *curpstate;
      extern struct progstate rootpstate;
      extern int noMTevents;		/* no MT events during GC */
   #else				/* MultiThread */
      extern char *code;		/* start of icode */
      extern char *ecode;		/* end of icode */
      extern dptr statics;		/* start of static variables */
      extern char *strcons;		/* start of the string constants */
      extern dptr fnames;		/* field names */
      extern dptr efnames;		/* end of field names */
      extern word *records;
      extern int *ftabp;		/* field table pointer */
      #ifdef FieldTableCompression
         extern word ftabwidth, foffwidth;
         extern unsigned char *ftabcp;
         extern short *ftabsp;
      #endif				/* FieldTableCompression */
      extern dptr xargp;
      extern word xnargs;

      extern word lastop;
   #endif				/* MultiThread */

#else					/* COMPILER */

   extern struct descrip statics[];	/* array of static variables */
   extern struct b_proc *builtins[];	/* pointers to builtin functions */
   extern int noerrbuf;			/* error buffering */
   extern struct p_frame *pfp;		/* procedure frame pointer */
   extern struct descrip trashcan;	/* dummy descriptor, never read */
   extern int largeints;		/* flag: large integers supported */

#endif					/* COMPILER */

/*
 * graphics
 */
#ifdef Graphics

   extern stringint attribs[], drawops[];
   extern wbp wbndngs;
   extern wcp wcntxts;
   extern wsp wstates;
   extern int GraphicsLeft, GraphicsUp, GraphicsRight, GraphicsDown;
   extern int GraphicsHome, GraphicsPrior, GraphicsNext, GraphicsEnd;
   extern int win_highwater, canvas_serial, context_serial;
   extern clock_t starttime;		/* start time in milliseconds */

   #ifndef MultiThread
      extern struct descrip kywd_xwin[];
      extern struct descrip lastEventWin;
      extern int lastEvFWidth, lastEvLeading, lastEvAscent;
      extern struct descrip amperCol;
      extern struct descrip amperRow;
      extern struct descrip amperX;
      extern struct descrip amperY;
      extern struct descrip amperInterval;
      extern uword xmod_control, xmod_shift, xmod_meta;
   #endif				/* MultiThread */

   #ifdef XWindows
      extern struct _wdisplay * wdsplys;
      extern stringint cursorsyms[];
   #endif				/* XWindows */

   #ifdef WinGraphics
      extern HINSTANCE mswinInstance;
      extern int ncmdShow;
   #endif				/* WinGraphics */

#endif					/* Graphics */

/****************************************   end ../h/rexterns.h   */


/****************************************  from ../h/rproto.h:  */

/*
 * Prototypes for run-time functions.
 */

/*
 * Prototypes common to the compiler and interpreter.
 */
void		EVInit		(void);
int		activate	(dptr val, struct b_coexpr *ncp, dptr result);
word		add		(word a,word b);
void		addmem (struct b_set *ps, struct b_selem *pe, union block **pl);
struct astkblk	*alcactiv	(void);
struct b_cset	*alccset	(void);
struct b_file	*alcfile	(FILE *fd,int status,dptr name);
union block	*alchash	(int tcode);
struct b_list	*alclist	(uword size);
struct b_lelem	*alclstb	(uword nslots,uword first,uword nused);
struct b_real	*alcreal	(double val);
struct b_slots	*alcsegment	(word nslots);
struct b_selem	*alcselem	(dptr mbr,uword hn);
char		*alcstr		(char	*s,word slen);
struct b_telem	*alctelem	(void);
struct b_tvtbl	*alctvtbl	(dptr tbl,dptr ref,uword hashnum);
int		anycmp		(dptr dp1,dptr dp2);
int		bfunc		(void);
struct b_proc	*bi_strprc	(dptr s, C_integer arity);
void		c_exit		(int i);
int		c_get		(struct b_list *hp, struct descrip *res);
void		c_put		(struct descrip *l, struct descrip *val);
int		cnv_c_dbl	(dptr s, double *d);
int		cnv_c_int	(dptr s, C_integer *d);
int		cnv_c_str	(dptr s, dptr d);
int		cnv_cset	(dptr s, dptr d);
int		cnv_ec_int	(dptr s, C_integer *d);
int		cnv_eint	(dptr s, dptr d);
int		cnv_int		(dptr s, dptr d);
int		cnv_real	(dptr s, dptr d);
int		cnv_str		(dptr s, dptr d);
int		cnv_tcset	(struct b_cset *cbuf, dptr s, dptr d);
int		cnv_tstr	(char *sbuf, dptr s, dptr d);
int		co_chng		(struct b_coexpr *ncp, struct descrip *valloc,
				   struct descrip *rsltloc,
				   int swtch_typ, int first);
void		co_init		(struct b_coexpr *sblkp);
void		coclean		(word *old);
void		coacttrace	(struct b_coexpr *ccp,struct b_coexpr *ncp);
void		cofailtrace	(struct b_coexpr *ccp,struct b_coexpr *ncp);
void		corettrace	(struct b_coexpr *ccp,struct b_coexpr *ncp);
int		coswitch	(word *old, word *new, int first);
int		cplist		(dptr dp1,dptr dp2,word i,word j);
int		cpset		(dptr dp1,dptr dp2,word size);
void		cpslots		(dptr dp1,dptr slotptr,word i, word j);
int		csetcmp		(unsigned int *cs1,unsigned int *cs2);
int		cssize		(dptr dp);
word		cvpos		(long pos,long len);
void		datainit	(void);
void		deallocate	(union block *bp);
int		def_c_dbl	(dptr s, double df, double * d);
int		def_c_int	(dptr s, C_integer df, C_integer * d);
int		def_c_str	(dptr s, char * df, dptr d);
int		def_cset	(dptr s, struct b_cset * df, dptr d);
int		def_ec_int	(dptr s, C_integer df, C_integer * d);
int		def_eint	(dptr s, C_integer df, dptr d);
int		def_int		(dptr s, C_integer df, dptr d);
int		def_real	(dptr s, double df, dptr d);
int		def_str		(dptr s, dptr df, dptr d);
int		def_tcset (struct b_cset *cbuf,dptr s,struct b_cset *df,dptr d);
int		def_tstr	(char *sbuf, dptr s, dptr df, dptr d);
word		div3		(word a,word b);
int		doasgn		(dptr dp1,dptr dp2);
int		doimage		(int c,int q);
int		dp_pnmcmp	(struct pstrnm *pne,dptr dp);
void		drunerr		(int n, double v);
void		dumpact		(struct b_coexpr *ce);
void		env_int	(char *name,word *variable,int non_neg, uword limit);
int		equiv		(dptr dp1,dptr dp2);
int		err		(void);
void		err_msg		(int n, dptr v);
void		error		(char *s1, char *s2);
void		fatalerr	(int n,dptr v);
int		findcol		(word *ipc);
char		*findfile	(word *ipc);
int		findipc		(int line);
int		findline	(word *ipc);
int		findloc		(word *ipc);
void		fpetrap		(int);
int		getvar		(char *s,dptr vp);
uword		hash		(dptr dp);
union block	**hchain	(union block *pb,uword hn);
union block	*hgfirst	(union block *bp, struct hgstate *state);
union block	*hgnext		(union block*b,struct hgstate*s,union block *e);
union block	*hmake		(int tcode,word nslots,word nelem);
void		icon_init	(char *name, int *argcp, char *argv[]);
void		iconhost	(char *hostname);
int		idelay		(int n);
int		interp		(int fsig,dptr cargp);
void		irunerr		(int n, C_integer v);
int		lexcmp		(dptr dp1,dptr dp2);
word		longread	(char *s,int width,long len,FILE *fname);
union block	**memb		(union block *pb,dptr x,uword hn, int *res);
void		mksubs		(dptr var,dptr val,word i,word j, dptr result);
word		mod3		(word a,word b);
word		mul		(word a,word b);
word		neg		(word a);
void		new_context	(int fsig, dptr cargp); /* w/o Coexpr: a stub */
int		numcmp		(dptr dp1,dptr dp2,dptr dp3);
void		outimage	(FILE *f,dptr dp,int noimage);
struct b_coexpr	*popact		(struct b_coexpr *ce);
word		prescan		(dptr d);
int		pstrnmcmp	(struct pstrnm *a,struct pstrnm *b);
int		pushact		(struct b_coexpr *ce, struct b_coexpr *actvtr);
int		putstr		(FILE *f,dptr d);
char		*qsearch	(char *key, char *base, int nel, int width,
				   int (*cmp)());
int		qtos		(dptr dp,char *sbuf);
int		 radix		(int sign, register int r, register char *s,
				   register char *end_s, union numeric *result);
char		*reserve	(int region, word nbytes);
void		retderef		(dptr valp, word *low, word *high);
void		segvtrap	(int);
void		stkdump		(int);
word		sub		(word a,word b);
void		syserr		(char *s);
struct b_coexpr	*topact		(struct b_coexpr *ce);
void		xmfree		(void);

#ifdef MultiThread
   void	resolve			(struct progstate *pstate);
   struct b_coexpr *loadicode (char *name, struct b_file *theInput,
      struct b_file *theOutput, struct b_file *theError,
      C_integer bs, C_integer ss, C_integer stk);
   void actparent (int eventcode);
   int mt_activate   (dptr tvalp, dptr rslt, struct b_coexpr *ncp);
#else					/* MultiThread */
   void	resolve			(void);
#endif					/* MultiThread */

#ifdef EventMon
   void EVAsgn	(dptr dx);
#endif					/* EventMon */

#ifdef ExternalFunctions
   dptr	extcall			(dptr x, int nargs, int *signal);
#endif					/* ExternalFunctions */

#ifdef LargeInts
   struct b_bignum *alcbignum	(word n);
   word		bigradix	(int sign, int r, char *s, char *x,
						   union numeric *result);
   double	bigtoreal	(dptr da);
   int		realtobig	(dptr da, dptr dx);
   int		bigtos		(dptr da, dptr dx);
   void		bigprint	(FILE *f, dptr da);
   int		cpbignum	(dptr da, dptr db);
   int		bigadd		(dptr da, dptr db, dptr dx);
   int		bigsub		(dptr da, dptr db, dptr dx);
   int		bigmul		(dptr da, dptr db, dptr dx);
   int		bigdiv		(dptr da, dptr db, dptr dx);
   int		bigmod		(dptr da, dptr db, dptr dx);
   int		bigneg		(dptr da, dptr dx);
   int		bigpow		(dptr da, dptr db, dptr dx);
   int		bigpowri        (double a, dptr db, dptr drslt);
   int		bigand		(dptr da, dptr db, dptr dx);
   int		bigor		(dptr da, dptr db, dptr dx);
   int		bigxor		(dptr da, dptr db, dptr dx);
   int		bigshift	(dptr da, dptr db, dptr dx);
   word		bigcmp		(dptr da, dptr db);
   int		bigrand		(dptr da, dptr dx);
#endif					/* LargeInts */

#ifdef FAttrib
   char *make_mode(mode_t st_mode);
#endif					/* FAttrib */

#ifdef Graphics
   /*
    * portable graphics routines in rwindow.r and rwinrsc.r
    */
   wcp	alc_context	(wbp w);
   wbp	alc_wbinding	(void);
   wsp	alc_winstate	(void);
   int	atobool		(char *s);
   void	c_push		(dptr l,dptr val);  /* in fstruct.r */
   int	docircles	(wbp w, int argc, dptr argv, int fill);
   void	drawCurve	(wbp w, XPoint *p, int n);
   char	*evquesub	(wbp w, int i);
   void	genCurve	(wbp w, XPoint *p, int n, void (*h)());
   wsp	getactivewindow	(void);
   int	getpattern	(wbp w, char *answer);
   struct palentry *palsetup(int p);
   int	palnum		(dptr d);
   int	parsecolor	(wbp w, char *s, long *r, long *g, long *b);
   int	parsefont	(char *s, char *fam, int *sty, int *sz);
   int	parsegeometry	(char *buf, SHORT *x, SHORT *y, SHORT *w, SHORT *h);
   int	parsepattern	(char *s, int len, int *w, int *nbits, C_integer *bits);
   void	qevent		(wsp ws, dptr e, int x, int y, uword t, long f);
   int	readGIF		(char *fname, int p, struct imgdata *d);
   int	rectargs	(wbp w, int argc, dptr argv, int i,
			   word *px, word *py, word *pw, word *ph);
   char	*rgbkey		(int p, double r, double g, double b);
   int	setsize		(wbp w, char *s);
   char	*si_i2s		(siptr sip, int i);
   int	si_s2i		(siptr sip, char *s);
   int	ulcmp		(pointer p1, pointer p2);
   int	wattrib		(wbp w, char *s, long len, dptr answer, char *abuf);
   int	wgetche		(wbp w, dptr res);
   int	wgetchne	(wbp w, dptr res);
   int	wgetevent	(wbp w, dptr res);
   int	wgetstrg	(char *s, long maxlen, FILE *f);
   void	wgoto		(wbp w, int row, int col);
   int	wlongread	(char *s, int elsize, int nelem, FILE *f);
   void	wputstr		(wbp w, char *s, int len);
   int	writeGIF	(wbp w, char *filename,
			  int x, int y, int width, int height);
   int	xyrowcol	(dptr dx);

   /*
    * graphics implementation routines supplied for each platform
    * (excluding those defined as macros for X-windows)
    */
   int	SetPattern	(wbp w, char *name, int len);
   int	SetPatternBits	(wbp w, int width, C_integer *bits, int nbits);
   int	allowresize	(wbp w, int on);
   int	blimage		(wbp w, int x, int y, int wd, int h,
			  int ch, unsigned char *s, word len);
   int	capture		(wbp w, int x, int y, int width, int hgt, short *data);
   wcp	clone_context	(wbp w);
   int	copyArea	(wbp w,wbp w2,int x,int y,int wd,int h,int x2,int y2);
   int	do_config	(wbp w, int status);
   int	dumpimage	(wbp w, char *filename, unsigned int x, unsigned int y,
			   unsigned int width, unsigned int height);
   void	eraseArea	(wbp w, int x, int y, int width, int height);
   void	fillrectangles	(wbp w, XRectangle *recs, int nrecs);
   void	free_binding	(wbp w);
   void	free_context	(wcp wc);
   void	free_mutable	(wbp w, int mute_index);
   int	free_window	(wsp ws);
   void	freecolor	(wbp w, char *s);
   char	*get_mutable_name (wbp w, int mute_index);
   void	getbg		(wbp w, char *answer);
   void	getcanvas	(wbp w, char *s);
   int	getdefault	(wbp w, char *prog, char *opt, char *answer);
   void	getdisplay	(wbp w, char *answer);
   void	getdrawop	(wbp w, char *answer);
   void	getfg		(wbp w, char *answer);
   void	getfntnam	(wbp w, char *answer);
   void	geticonic	(wbp w, char *answer);
   int	geticonpos	(wbp w, char *s);
   void	getlinestyle	(wbp w, char *answer);
   int	getpixel_init	(wbp w, struct imgmem *imem);
   int	getpixel_term	(wbp w, struct imgmem *imem);
   int	getpixel	(wbp w,int x,int y,long *rv,char *s,struct imgmem *im);
   void	getpointername	(wbp w, char *answer);
   int	getpos		(wbp w);
   int	getvisual	(wbp w, char *answer);
   int	isetbg		(wbp w, int bg);
   int	isetfg		(wbp w, int fg);
   int	lowerWindow	(wbp w);
   int	mutable_color	(wbp w, dptr argv, int ac, int *retval);
   int	nativecolor	(wbp w, char *s, long *r, long *g, long *b);

   int pollevent	(void);
   void wflush		(wbp w);

   int	query_pointer	(wbp w, XPoint *pp);
   int	query_rootpointer (XPoint *pp);
   int	raiseWindow	(wbp w);
   int	readimage	(wbp w, char *filename, int x, int y, int *status);
   int	rebind		(wbp w, wbp w2);
   int	set_mutable	(wbp w, int i, char *s);
   int	setbg		(wbp w, char *s);
   int	setcanvas	(wbp w, char *s);
   void	setclip		(wbp w);
   int	setcursor	(wbp w, int on);
   int	setdisplay	(wbp w, char *s);
   int	setdrawop	(wbp w, char *val);
   int	setfg		(wbp w, char *s);
   int	setfillstyle	(wbp w, char *s);
   int	setfont		(wbp w, char **s);
   int	setgamma	(wbp w, double gamma);
   int	setgeometry	(wbp w, char *geo);
   int	setheight	(wbp w, SHORT new_height);
   int	seticonicstate	(wbp w, char *s);
   int	seticonlabel	(wbp w, char *val);
   int	seticonpos	(wbp w, char *s);
   int	setimage	(wbp w, char *val);
   int	setleading	(wbp w, int i);
   int	setlinestyle	(wbp w, char *s);
   int	setlinewidth	(wbp w, LONG linewid);
   int	setpointer	(wbp w, char *val);
   int	setwidth	(wbp w, SHORT new_width);
   int	setwindowlabel	(wbp w, char *val);
   int	strimage	(wbp w, int x, int y, int width, int height,
			   struct palentry *e, unsigned char *s,
			   word len, int on_icon);
   void	toggle_fgbg	(wbp w);
   int	walert		(wbp w, int volume);
   void	warpPointer	(wbp w, int x, int y);
   int	wclose		(wbp w);
   void	wflush		(wbp w);
   int	wgetq		(wbp w, dptr res);
   FILE	*wopen		(char *nm, struct b_list *hp, dptr attr, int n, int *e);
   int	wputc		(int ci, wbp w);
   #ifndef wsync
   void	wsync		(wbp w);
   #endif				/* wsync */
   void	xdis		(wbp w, char *s, int n);

   #ifdef XWindows
      /*
       * Implementation routines specific to X-Windows
       */
      void	unsetclip		(wbp w);
      int	moveResizeWindow	(wbp w, int x, int y, int wd, int h);
      int	resetfg			(wbp w);
      int	setfgrgb		(wbp w, int r, int g, int b);
      int	setbgrgb		(wbp w, int r, int g, int b);

      XColor	xcolor			(wbp w, LinearColor clr);
      LinearColor	lcolor		(wbp w, XColor color);
      int	pixmap_open		(wbp w, dptr attribs, int argc);
      int	pixmap_init		(wbp w);
      int	remap			(wbp w, int x, int y);
      int	seticonimage		(wbp w, dptr dp);
      int	translate_key_event	(XKeyEvent *k1, char *s, KeySym *k2);
      wdp	alc_display		(char *s);
      void	free_display		(wdp wd);
      wfp	alc_font		(wbp w, char **s);
      wfp	tryfont			(wbp w, char *s);
      wclrp	alc_rgb			(wbp w, char *s, unsigned int r,
					   unsigned int g, unsigned int b,
					   int is_iconcolor);
      int	alc_centry		(wdp wd);
      wclrp	alc_color		(wbp w, char *s);
      void	copy_colors		(wbp w1, wbp w2);
      void	free_xcolor		(wbp w, unsigned long c);
      void	free_xcolors		(wbp w, int extent);
      int	go_virtual		(wbp w);
      int	resizePixmap		(wbp w, int width, int height);
      void	wflushall		(void);
   #endif				/* XWindows */

   #ifdef WinGraphics
      /*
       * Implementation routines specific to MS Windows
       */
      int playmedia		(wbp w, char *s);
      char *nativecolordialog	(wbp w,long r,long g, long b,char *s);
      int nativefontdialog	(wbp w, char *buf, int flags, int fheight);
      char *nativeopendialog	(wbp w,char *s1,char *s2,char *s3,int i,int j);
      char *nativeselectdialog	(wbp w,struct b_list *,char *s);
      char *nativesavedialog	(wbp w,char *s1,char *s2,char *s3,int i,int j);
      HFONT mkfont		(char *s);
      int sysTextWidth		(wbp w, char *s, int n);
      int sysFontHeight		(wbp w);
      int mswinsystem		(char *s);
      void UpdateCursorPos	(wsp ws, wcp wc);
      LRESULT_CALLBACK WndProc	(HWND, UINT, WPARAM, LPARAM);
      HDC CreateWinDC		(wbp);
      HDC CreatePixDC		(wbp, HDC);
      HBITMAP loadimage	(wbp wb, char *filename, unsigned int *width,
			unsigned int *height, int atorigin, int *status);
      void wfreersc();
      int getdepth(wbp w);
      HBITMAP CreateBitmapFromData(char *data);
      int resizePixmap(wbp w, int width, int height);
      int textWidth(wbp w, char *s, int n);
      int	seticonimage		(wbp w, dptr dp);
      int devicecaps(wbp w, int i);
      void fillarcs(wbp wb, XArc *arcs, int narcs);
      void drawarcs(wbp wb, XArc *arcs, int narcs);
      void drawlines(wbinding *wb, XPoint *points, int npoints);
      void drawpoints(wbinding *wb, XPoint *points, int npoints);
      void drawrectangles(wbp wb, XRectangle *recs, int nrecs);
      void fillpolygon(wbp w, XPoint *pts, int npts);
      void drawsegments(wbinding *wb, XSegment *segs, int nsegs);
      void drawstrng(wbinding *wb, int x, int y, char *s, int slen);
      void unsetclip(wbp w);

   #endif				/* WinGraphics */

#endif					/* Graphics */

/*
 * Prototypes for the run-time system.
 */

struct b_external *alcextrnl	(int n);
struct b_record *alcrecd	(int nflds,union block *recptr);
struct b_tvsubs *alcsubs	(word len,word pos,dptr var);
int	bfunc		(void);
long	ckadd		(long i, long j);
long	ckmul		(long i, long j);
long	cksub		(long i, long j);
void	cmd_line	(int argc, char **argv, dptr rslt);
struct b_coexpr *create	(continuation fnc,struct b_proc *p,int ntmp,int wksz);
int	collect		(int region);
void	cotrace		(struct b_coexpr *ccp, struct b_coexpr *ncp,
			   int swtch_typ, dptr valloc);
int	cvcset		(dptr dp,int * *cs,int *csbuf);
int	cvnum		(dptr dp,union numeric *result);
int	cvreal		(dptr dp,double *r);
void	deref		(dptr dp1, dptr dp2);
void	envset		(void);
int	eq		(dptr dp1,dptr dp2);
int	get_name	(dptr dp1, dptr dp2);
int	getch		(void);
int	getche		(void);
double	getdbl		(dptr dp);
int	getimage	(dptr dp1, dptr dp2);
int	getstrg		(char *buf, int maxi, struct b_file *fbp);
void	hgrow		(union block *bp);
void	hshrink		(union block *bp);
C_integer iipow		(C_integer n1, C_integer n2);
void	init		(char *name, int *argcp, char *argv[], int trc_init);
int	kbhit		(void);
int	mkreal		(double r,dptr dp);
int	nthcmp		(dptr d1,dptr d2);
void	nxttab		(C_integer *col, dptr *tablst, dptr endlst,
			   C_integer *last, C_integer *interval);
int	order		(dptr dp);
int	printable	(int c);
int	ripow		(double r, C_integer n, dptr rslt);
void	rtos		(double n,dptr dp,char *s);
int	sig_rsm		(void);
struct b_proc *strprc	(dptr s, C_integer arity);
int	subs_asgn	(dptr dest, const dptr src);
int	trcmp3		(struct dpair *dp1,struct dpair *dp2);
int	trefcmp		(dptr d1,dptr d2);
int	tvalcmp		(dptr d1,dptr d2);
int	tvcmp4		(struct dpair *dp1,struct dpair *dp2);
int	tvtbl_asgn	(dptr dest, const dptr src);
void	varargs		(dptr argp, int nargs, dptr rslt);

#ifdef MultiThread
   struct b_coexpr *alccoexp (long icodesize, long stacksize);
#else					/* MultiThread */
   struct b_coexpr *alccoexp (void);
#endif					/* MultiThread */

#if COMPILER

   struct b_refresh *alcrefresh	(int na, int nl, int nt, int wk_sz);
   void	atrace			(void);
   void	ctrace			(void);
   void	failtrace		(void);
   void	initalloc		(void);
   int	invoke			(int n, dptr args, dptr rslt, continuation c);
   void	rtrace			(void);
   void	strace			(void);
   void	tracebk			(struct p_frame *lcl_pfp, dptr argp);
   int	xdisp			(struct p_frame *fp, dptr dp, int n, FILE *f);

#else					/* COMPILER */

   struct b_refresh *alcrefresh	(word *e, int nl, int nt);
   void	atrace			(dptr dp);
   void	ctrace			(dptr dp, int nargs, dptr arg);
   void	failtrace		(dptr dp);
   int	invoke			(int nargs, dptr *cargs, int *n);
   void	rtrace			(dptr dp, dptr rval);
   void	strace			(dptr dp, dptr rval);
   void	tracebk			(struct pf_marker *lcl_pfp, dptr argp);
   int	xdisp			(struct pf_marker *fp, dptr dp, int n, FILE *f);

   #define Fargs dptr cargp
   int	Obscan			(int nargs, Fargs);
   int	Ocreate			(word *entryp, Fargs);
   int	Oescan			(int nargs, Fargs);
   int	Ofield			(int nargs, Fargs);
   int	Olimit			(int nargs, Fargs);
   int	Ollist			(int nargs, Fargs);
   int	Omkrec			(int nargs, Fargs);

   #ifdef MultiThread
      void	initalloc	(word codesize, struct progstate *p);
   #else				/* MultiThread */
      void	initalloc	(word codesize);
   #endif				/* MultiThread */

#endif					/* COMPILER */

/****************************************   end ../h/rproto.h   */

#endif					/* RT_DOT_H */

/****************************************   end ../h/rt.h   */
