/************
 *                  +--------------------------------+
 *                  | THIS FILE MUST MATCH midas.inc |
 *                  +--------------------------------+
 *
 *  Description: Common X-Midas block shared between all primitives, e.g.
 *               X-Midas common structure.
 *               Defines runtime environment variables
 *
 *  Author:      JGS 4/2/90
 *  Author:      Copy of midas.inc
 */
#ifndef _midas_h

#include "cdefs.h"

#define L_mlevels 32    /* max # of 'ordinary' macro levels */
#define L_macros 96     /* max spawned macro level */
#define L_auxs 64       /* max size of read auxilary list */
#define L_auxbytes 4096 /* max total characters of all auxs */
#define L_maxauxindex 255       /* max index into auxiliary table */
#define L_cmd_chars 2048        /* max chars in command line */
#define L_gsw_chars 2048        /* max global switch chars */
#define L_files 10      /* max files/prim for overwrite autochk */
#define L_shellfiles 10 /* max results array files open at once */
#define L_userscr 32    /* max user scratch fields */
#define L_pipe_name 32  /* max length of pipe name */
#define L_MAXSPA_ 16    /* max scalars per atom */

#define L_shrmask 56    /* shared section mask - bits 3,4,5 */

#define LS_midas 1
#define LS_tables 2
#define LS_results 3
#define LS_messages 4
#define LS_dictionary 5
#define LS_macrostack 6
#define LS_pipe_headers 7
#define LS_pipe_buffers 8
#define LS_cntrl_widgets 9
#define LS_ds_structs 10
#define LS_user_offset 10
#define LS_user1 11
#define LS_user2 12
#define LS_user3 13
#define LS_pname 14

typedef struct {
  int_2 table[7][4];
} COLORTYPE;

/************************ X-MIDAS COMMON STRUCTURE **************************/

#define FILENAME_LEN    81      /* Max. filename length + '\0' */

typedef struct { /* This must match the definition in midas.inc */
  int_4  number_parameters;

  int_4  verify;
  int_4  debug;
  int_4  break_;
  int_4  beep;
  int_4  status;
  int_4  count;
  int_4  mode;

  char   OS_type[4];
  char   OS_name[4];
  char   machine[4];
  char   hostname[16];

  real_4 pause;
  int_4  seed;
  real_4 tolerance;

  char   nformat[4];
  int_4  sysunlock;

  char   command_name[40];
  char   command_support;
  int_1  engine;
  int_2  fill;

  char   home_path[256];
  char   login_path[60];
  char   read_id[60];
  char   write_id[60];
  char   user_id[8];
  int_4  write_aux;
  int_4  read_auxs;
  int_4  read_aux[L_auxs];

  char  plot_node[40];          /* X-Windows screen designator */
  char  plot_node2[40];         /* secondary screen designator */
  int_4 left;                   /* default X-WIndows left  */
  int_4 top;                    /* default X-Windows top */
  int_4 width;                  /* default X-Windows width */
  int_4 height;                 /* default X-Windows height */
  int_4 window_id;              /* X-Windows window ID */
  int_2 window_w;               /* X-Window actual width (pixels) */
  int_2 window_h;               /* X-Window actual hght (pixels) */
  COLORTYPE colormap[4];        /* colormap environments */

  int_4 visClass;                /* default /VISCLASS */
  int_4 visDepth;                /* default /VISDEPTH */
  int_4 visID;                   /* default /VISUALID */

} MCSTRUCT;
#define L_midas_common sizeof(MCSTRUCT)
typedef MCSTRUCT MCOMMON;

typedef struct { /* This must match the definition in midas.inc */
  int_4  id;
  int_4  verbose;
  int_4  warn;
  int_4  alert;
  int_4  spawn;
  int_4  files;
  real_8 todo;
  char   command_name[40];
  int_4  messagelog;
  bool_4 okio;
} MUSTRUCT;
#define L_midas_unique sizeof(MUSTRUCT)
typedef MUSTRUCT MUNIQUE;


/* MCOMMON (i.e. MCSTRUCT) pointer for C/C++ host primitive support.
 * initCommand(..) initializes this pointer.
 */
#ifdef __cplusplus
extern MCOMMON* const Mc;
#else
extern MCOMMON* Mc;
#endif


/* MUNIQUE (i.e. MUSTRUCT) pointer for C/C++ primitive support (thread local storage)
 * initCommand(..) initializes this pointer.
 */
#ifdef __cplusplus
 #if defined(_WORKAROUND_INTEL_COMPILER_ERROR_0_1561) || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1110))
  extern __thread MUNIQUE* Mu; /* workaround for Intel C++ compiler bug for versions prior to 11.1.059 (by removing const) */
 #else
  extern __thread MUNIQUE* const Mu;
 #endif
#else
  extern __thread MUNIQUE* Mu;
#endif

#define _midas_h
#endif /* _midas_h */
