/* ---------------------------- Uedit.h ----------------------------- */

#define ISK 1
#define ISSPELL 1

#define  UCHAR  		unsigned char
#define BPTT unsigned char *

/* #define BPTR	UCHAR* */

#include "stdlib.h"
#include "exec/types.h"
#include "hardware/blit.h"
#include "exec/execbase.h"
#include "intuition/intuitionbase.h"

#include "workbench/startup.h"
#include "workbench/workbench.h"

#include "exec/memory.h"
#include "exec/io.h"
#include <exec/ports.h>
#include "devices/printer.h"
#include <libraries/dosextens.h>
#include "string.h"

#include "functions.h"

#include "ue.pro"

int FrunKey(short tnum);
#pragma regcall(FrunKey(d0))

/* #include "ue.pragmas" */

#ifdef ISMAIN
   #define  EXTRN /**/
#else
   #define  EXTRN extern
#endif

#define MAXARGS    5	/* used in UEDIT.DEFINES */
										  /* for usn 0X7D1*/
extern char *show;

#define  VERSION  3002L

#define PARTIALVERSION  (VERSION << 10L)  /* X 1024 */

#define STATE_ID    12349

/* for ue9 window titles */

#define VNAME	"Uedit V4.0  "

#define  UCHAR  		unsigned char

#ifdef TRUE
#undef TRUE
#undef FALSE
#endif

#define    TRUE 	   1
#define    FALSE	   0

#define  EOL	  0x0a
#define  TAB	  0x09
#define  BS 	  0x08
#define  DEL	  0x10
#define  ESC	  0x1b
#define  NL 	  0x0d

#define  SHIFTKEYED   1
#define  ALTKEYED	  2
#define  CONTROLKEYED 4
#define  LAMIGA 	  8
#define  RAMIGA 	  9

#define  MAXMENUS		7
#define  MAXITEMS		20
#define  MAXSUBITEMS	12
#define  MAXMENUWIDTH	17

#define  MAXMACROSIZE	20480
#define  MAXWORD	 132
#define  MAXSTACK	 10
#define  MAXLINELEN  9999

#define  MAXTABS	  32
#define  MAXTABTABLES 5
#define  MAXMARGIN    255

#define  MAXLINES	   132
#define  MAXLINECHARS  132

/* ------------ in CB buf-header struct, bufPtr->Flags settings --------- */
#define  TRUETABS	   0x00000001L
#define  AUTOINDENT    0x00000002L
#define  OVERSTRIKE    0x00000004L
#define  AUTOBACKUP    0x00000008L
#define  READONLY	   0x00000010L
#define  WORDWRAP	   0x00000020L
#define  RIGHTJUSTIFY  0x00000040L
#define  MAPCHARS	   0x00000080L
#define  CHANGED	   0x00000100L
#define  USERLOCALA    0x00000200L
#define  USERLOCALB    0x00000400L

#define  FAVORITE	   0x00000800L

#define  BACKEDUP	   0x00001000L
#define  NEEDPACK	   0x00002000L
#define  LOCKED 	   0x00004000L
#define  DELETEIT	   0x00008000L

/* -------- HOW INTERFACE THESE?  no room in defines or such array ---- */
/* put in this order
            CHANGED
            USERLOCALA-H
            FAVORITE
fix such & #defines_ etc
trace each thru
this is tricky and will take time
eoline is okay
be sure to update ue3.c with correct compiler ordering on names
------------------ */
#define  USERLOCALC    0x00010000L
#define  USERLOCALD    0x00020000L
#define  USERLOCALE    0x00040000L
#define  USERLOCALF    0x00080000L
#define  USERLOCALG    0x00100000L
#define  USERLOCALH    0x00200000L
#define  FOLDED        0x00400000L      /* won't need this! */
#define  RESERVE_H     0x00800000L
#define  RESERVE_I     0x01000000L
#define  RESERVE_A     0x02000000L
#define  RESERVE_B     0x04000000L
#define  RESERVE_C     0x08000000L
#define  RESERVE_D     0x10000000L
#define  RESERVE_E     0x20000000L
#define  RESERVE_F     0x40000000L
#define  RESERVE_G     0x80000000L

/* ----------------------- markers used in data blocks ----------------- */
#define  EOFILE   0x03
#define  EOB	  0x02
#define  TRACE    0x01  					/* to trace region to fill */

#define  ISMARKER(a)   (a<=EOFILE && a>0)
#define  ISWEIRD(a)    (a<=EOFILE)
#define  ISGOOD(a)     (a>EOFILE)
#define  ISPRINT(a)    (a>=' ')

/* ------------------------ macro definition tables ---------------- */
#define  menuDown	  71
#define  menuUp 	  72
#define  middleDown   73
#define  middleUp	  75

#define  buttonDown   96
#define  buttonUp	  97
#define  gadget1	  98
#define  gadget2	  99
#define  gadget3	  100
#define  gadget4	  101
#define  closeBox	  102
#define  zeroChar	  103

#define  rexxMacro    1145
#define  idleMacro    1146
#define  preKeyMacro  1147
#define  startupMacro 1148
#define  onAbort      1149
#define  onTitle      1150

/* avail 1151-1199 */

#define  definesMacro 9999

#define ON_TITLE    32767


#define  MAXMODIFIER 11
#define  MAXMACROS   1200

#define  MAXKEYWORDS 50
#define  MAXRAW 	 104   /* NOTE change to 128 & use << in ue8 */

#define  MAXPRINTABLES     64

#define  BLOCKSIZE   256
#define  DATASIZE	 (BLOCKSIZE - 12)

#define    CBOVL   20	/* MAPPING: number of pointers in CB struct !!!! */

#define  NAMELEN	 80

/* --------------------- COLOR variables & defines -------------- */

#define  normalVid   0x00
#define  cursorVid   0X01
#define  hiliteVid   0X02
#define  invertVid   0X04

#define  titleVid   8
#define  msgVid     9
#define  menuVid    10
#define  rulerVid   11
#define  requesterVid 12
#define  ffVid      13
#define  spare1Vid  14
#define  spare2Vid  15

#define  SHOWCURSOR_	   1
#define  VSCROLL_		   2
#define  HSCROLL_		   4
#define  SHOWEOS_		   8
#define  PAGE_  		   16

#define ALLPAGE 	0xfff0

#define  MAXSPLITS  		8

#define STOP_EXEC_LEARN 	2
#define EXEC_LEARN  		1

#ifdef ISMAIN

#define COPYRIGHT (UBYTE *)"Uedit V4.0   Placed in the public domain July 1992                                                                    "

#endif

#define  MAXBUFS		100 			/* WAS 50 !!!!! */
#define  ALLBUFS		100

/* ------------ macro definitions ------------------------------- */
#define  loc(a,b)	 (((ULONG)((struct DB *)a)->BlockNum << 16L) + (ULONG)b - (ULONG)a )

#define MAXPRINTS  12

#define zero(x) nullify(&(x[0]),(long)sizeof(x))

#define  MAXMSGS	 24
#define  MAXLEARN	 200

/* ------------- function names ---------------------- */

#define  abort_ 				1
#define  not_					2
#define  do_					3   /* used for gosub */
#define  while_ 				4   /* avail */
#define  if_					5
#define  else_  				6
#define  goto_  				7
#define  label_ 				8
#define  nothing_				9
#define  return_				10
#define  returnTrue_			11
#define  returnFalse_			12

#define  mouseDown_ 			13
#define  trackMouse_			14
#define  updateDisplay_ 		15
#define  inputWaiting_  		16
#define  thisKey_				17
#define  abortSave_ 			18
#define  restartPrint_  		19
#define  reformat_  			20
#define  runLearn_  			21
#define  fullRefresh_           22
#define  refreshDisplay_		23
#define  abortPrint_			24
/* ------------- AVAIL 			25    */
#define  gosub_		            26
#define  beepDisplay_			27
#define  seeRuler_  			28
#define  setRuler_  			29
/* ----------- AVAIL 30-31 --------------------- */
#define  stopSpell_ 			32
#define  spellerUp_ 			33
#define  hyperClose_			34
#define  hyperUp_				35
#define  inTiny_				36
#define  screenToBack_  		37
#define  screenToFront_ 		38
#define  newFile_				39


#define  nameBuffer_			40

#define  checkedSubMenu_		41
#define  menu_  				42
#define  checkedMenu_			43
#define  subMenu_				44
#define  runKey_				45

#define  gtNum_ 				46
#define  incNum_				47
#define  decNum_				48
#define  equateNum_ 			49
#define  eqNum_ 				50
#define  geNum_ 				51
#define  and_					52
#define  or_					53
#define  mul_					54
#define  div_					55
#define  add_					56
#define  sub_					57
#define  mod_					58
#define  mouseXY_				59
#define  setRGB_				60
#define  isEmpty_				61
#define  getSplitLines_ 		62
#define  getChar_				63
#define  onScreen_  			64
#define  vScroll_				65
#define  hScroll_				66
#define  insertRgn_ 			67
#define  setEol_				68
#define  clearRgn_  			69
#define  swapBuf_				70
#define  print_ 				71
#define  loadFile_  			72
#define  insertFile_			73
#define  alertUser_ 			74
#define  askYesNo_  			75
#define  saveFile_  			76
#define  setFileName_			77
#define  getFileName_			78
#define  flipFlag_  			79
#define  getFlag_				80
#define  toggle_				81
#define  toNumber_  			82
#define  toWord_				83
#define  toUpper_				84
#define  toLower_				85
#define  setLocal_  			86
#define  hexDecimal_			87
#define  fileSize_  			88
#define  locToLine_ 			89
#define  lineToLoc_ 			90
#define  search_				91
#define  saveLearn_ 			92
#define  freeBuf_				93
#define  getLocal_  			94
#define  is_					95
#define  loadLearn_ 			96
#define  quit_  				97
#define  printerCode_			98
#define  saveConfig_			99
#define  loadConfig_			100
#define  moveCursor_			101
#define  equateLoc_ 			102
#define  incLoc_				103
#define  decLoc_				104
#define  eqLoc_ 				105
#define  geLoc_ 				106
#define  gtLoc_ 				107
#define  getKey_				108
#define  inputKey_  			109
#define  swapKey_				110
#define  killKey_				111
#define  delay_ 				112
#define  editBuf_				113
#define  putMsg_				114
#define  inputString_			115
#define  inputNum_  			116
#define  insertChar_			117
#define  copyChar_  			118
#define  clearChar_ 			119
#define  swapChar_  			120
#define  teachOne_  			121
#define  execute_				122
#define  speak_ 				123
#define  copyColData_			124
#define  clearColData_  		125
#define  gadgetName_			126
#define  typeChar_  			127
#define  changeDir_ 			128
#define  inUse_ 				129
#define  setMaxFiles_			130
#define  getMaxFiles_			131
#define  getSerialNum_  		132
#define  getColors_			    133
#define  locToIndex_			134
#define  indexToLoc_			135
#define  locToCol_  			136
#define  colToLoc_  			137
#define  splitWindow_			138
#define  getTabs_				139
#define  getPageRowCol_ 		140
#define  gotoPage_  			141
#define  getKeyVal_ 			142
#define  spell_ 				143
#define  startSpell_			144
#define  stringComp_			145
#define  rexxIn_				146
#define  rexxOut_				147
#define  loadKeys_  			148
#define  saveKeys_  			149
#define  push_  				150
#define  pop_					151
#define  getBufAddr_			152
#define  getStackSize_  		153
#define  rollStack_ 			154
#define  setSearch_ 			155
#define  attachBuf_ 			156
#define  detachBuf_ 			157
#define  copyKey_				158
#define  gotoSplit_ 			159
#define  getSearch_ 			160
#define  fileRequest_			161
#define  peek_  				162
#define  poke_  				163
#define  getAddress_			164
#define  upFlag_				165
#define  downFlag_  			166
#define  switch_				167
#define  case_  				168
#define  default_				169
#define  text_  				170
#define  swapLoc_				171
#define  grep_  				172
#define  setGrep_				173
#define  getGrep_				174
#define  setColors_             175
#define  hyperOpen_ 			176
#define  hyper_ 				177
#define  saveState_ 			178
#define  loadState_ 			179
#define  setTaskPri_			180
#define  draw_  				181
#define  setFont_				182
#define  sortLines_ 			183
#define  compile_               184
#define  compileDefaults_       185
#define  getFont_               186
#define  stackBuf_              187
#define  compareBuf_            188
#define  define_                189
#define  clearBuf_              190
#define  tabsToSpaces_  		191
#define  spacesToTabs_  		192
#define  getRGB_                193
#define  xor_                   194
#define  fold_                  195
#define  setFold_               196
#define  getFold_               197

/* AVAIL 198-199 */

/* -------- function arguments 6-20 are FREE/AVAIL ---------- */
#define  buf_				  1
#define  bufN_  			  2
#define  currentFile_		  3
#define  n_ 				  4
#define  nN_				  5
#define  number_			  6
#define  literal_			  7
#define  keyArg_			  8
#define  REALARG_			  9
#define  byteArg_             10

/* =========== avail 13 14 ====== */

#define  windowSplit_		  11
#define  toTiny_			  12

#define  pmEsc_ 			  15  /* VVVVVVVVVV Mapped !!! VVVVVVVVVV */
#define  userGlobalA_		  16
#define  userGlobalB_		  17
#define  columnar_  		  18
#define  cram_  			  19
#define  rowCol_			  20

#define  markGadgets_		  21
#define  lace_  			  22
#define  spooks_			  23
#define  busies_			  24
#define  teachKeys_ 		  25

/* #define  dummy_  		  26 */ 	 /*WARNING:  Mapped into MAXFILES */
#define  icons_ 			  27
#define  searchCaps_		  28
#define  wildCard_  		  29
#define  eitherOr_  		  30

#define  multiWild_ 		  31
#define  allBut_			  32
#define  singleWhite_		  33
#define  multiWhite_		  34
#define  menuOffset_		  35

#define  learnMode_ 		  36
#define  cmdMultiplier_ 	  37
#define  speakAlerts_		  38
#define  speakMsgs_ 		  39
#define  printTabs_ 		  40

#define  smartTabs_ 		  41
#define  customScreen_  	  42
#define  useKeys_			  43
#define  prefPrint_ 		  44
#define  idleTime_  		  45

#define  hideDisplay_		  46
#define  scrollType_		  47
#define  trapMenus_ 		  48
#define  sWidth_			  49
#define  sHeight_			  50

#define  tinyPriority_  	  51
#define  capsLock_            52
#define  clickTime_           53
#define  userGlobalC_         54
#define  userGlobalD_         55

/* =========== end globals, start locals  ===================== */

#define  trueTabs_  		  56
#define  autoIndent_		  57
#define  overStrike_		  58
#define  autoBackup_		  59
#define  readOnly_  		  60

#define  wordWrap_  		  61
#define  rightJustify_  	  62
#define  mapChars_  		  63

#define  changed_			  64
#define  userLocalA_		  65
#define  userLocalB_		  66

#define  tabTable_  		  67        /* bump up by 1 */
#define  lineLength_		  68
#define  splitSize_ 		  69
#define  leftMargin_		  70

#define  topMargin_ 		  71
#define  bottomMargin_  	  72
#define  pageLines_ 		  73
/* #define eoline_  		  74 */  /* cvtd from eoline to eol */
#define  inputChar_ 		  75
#define  macroNum_  		  76	 /* ^^^^^^^^^^^ Mapped !!! ^^^^^^^^^ */

/*    #define  dummy_		  77  */
#define  color_ 			  78
#define  whiteSpace_		  79
#define  space_ 			  80
#define  alpha_ 			  81
#define  digit_ 			  82
#define  ctlChar_			  83
#define  formFeed_  		  84
#define  tabColumn_ 		  85
#define  lineTooLong_		  86
#define  upperCase_ 		  87
#define  lowerCase_ 		  88
#define  decimalNum_		  89
#define  hexNum_			  90
#define  favorite_  		  91

/* ----------- avail 92-98 ---------- */

#define  atCursor_  		  99  /* VVVVVVVVVV Mapped!!! VVVVVVVV */
#define  sHilite_			  100
#define  eHilite_			  101
#define  sInvert_			  102
#define  eInvert_			  103
#define  sPage_ 			  104
#define  ePage_ 			  105
#define  locA_  			  106
#define  locB_  			  107
#define  locC_  			  108
#define  locD_  			  109
#define  locE_  			  110
#define  locF_  			  111
#define  locG_  			  112
#define  locH_  			  113
#define  locI_  			  114
#define  locJ_  			  115
#define  locSP_ 			  116
#define  locSC_ 			  117
#define  mouseLoc_  		  118 /* ^^^^^^^^^^ Mapped!!! ^^^^^^^^ */

#define  sFile_ 			  119  /* VVVVV VVVVMapped VVVVVVVVV */
#define  eFile_ 			  120
#define  sLine_ 			  121
#define  eLine_ 			  122
#define  upLine_			  123
#define  downLine_  		  124
#define  sWord_ 			  125
#define  eWord_ 			  126
#define  sChar_ 			  127
#define  eChar_ 			  128

#define  char_  			  129
#define  word_  			  130
#define  line_  			  131
#define  hilite_			  132
#define  invert_			  133
#define  all_				  134

#define  loc_				  135
#define  locCD_ 			  136
#define  locEF_ 			  137
#define  locGH_ 			  138
#define  locIJ_ 			  139
#define  locPC_ 			  140  /* ^^^^^^^^^ Mapped ^^^^^^^^^^^ */

#define  normal_			  141  /* vvvvvvvvv Mapped!!! vvvvvvvv */
#define  shft_  			  142
#define  alt_				  143
#define  shftAlt_			  144
#define  ctl_				  145
#define  shftCtl_			  146
#define  altCtl_			  147
#define  shftAltCtl_		  148
#define  lAmiga_			  149
#define  rAmiga_			  150
#define  virtual_			  151
#define  rexxKey_			  152
#define  idle_  			  153
#define  preKey_			  154
#define  defines_             155
#define  startup_			  156
#define  onAbort_             157
#define  onTitle_             158  /* ^^^^^^^^^^ Mapped!!! ^^^^^^^^^ */

/* avail 159-194 */
#define  eForm_ 			  195
#define  sForm_ 			  196
#define  blankLine_ 		  197
#define  sTab_  			  198
#define  eTab_  			  199

/* AVAIL 161-199 */

/* WARNING:  if change these, CHANGE ue3 ASM code and possibly ue9 & ue1 */

#define MAXFCTTOKENS	200

#define MAXARGTOKENS	200


/* ============ structures =============== */

struct DB	{
   UCHAR		Data[DATASIZE];
   UCHAR		endOfBlock; 	/* this saves a LOT of trouble!  */
   UCHAR				eols;
   USHORT				BlockNum;
   struct DB			*LastBlock;
   struct DB			*NextBlock;
};

struct OVL {
   UCHAR *ptrs[CBOVL * 2];
};

		 /* WARNING:  Before switching ptrs around, see UE9.C (atCursor_)
			& UEDIT.DFINES (atCursor_/mouseLoc_)!  Also check OVL structure,
			ue4.c matchPtrs ETC ! Be paranoid.  They may be mapped in ue5/
			ue11 ETC as well! */

struct CB { 	   /* WARNING: these are MAPPED in ue9.c!!! */
   struct DB  *Block;
   struct DB  *SHBlock;
   struct DB  *EHBlock;
   struct DB  *SIBlock;
   struct DB  *EIBlock;
   struct DB  *PBlock;
   struct DB  *EBlock;
   struct DB  *LABlock;
   struct DB  *LBBlock;
   struct DB  *LCBlock;
   struct DB  *LDBlock;
   struct DB  *LEBlock;
   struct DB  *LFBlock;
   struct DB  *LGBlock;
   struct DB  *LHBlock;
   struct DB  *LIBlock;
   struct DB  *LJBlock;
   struct DB  *LSPBlock;
   struct DB  *LSCBlock;
   struct DB  *MBlock;
   UCHAR *Ptr;
   UCHAR *SHPtr;
   UCHAR *EHPtr;
   UCHAR *SIPtr;
   UCHAR *EIPtr;
   UCHAR *PPtr;
   UCHAR *EPtr;
   UCHAR *LAPtr;
   UCHAR *LBPtr;
   UCHAR *LCPtr;
   UCHAR *LDPtr;
   UCHAR *LEPtr;
   UCHAR *LFPtr;
   UCHAR *LGPtr;
   UCHAR *LHPtr;
   UCHAR *LIPtr;
   UCHAR *LJPtr;
   UCHAR *LSPPtr;
   UCHAR *LSCPtr;
   UCHAR *MPtr;

   struct	DB    *NextBlock;
   short  PageCol;
   short  BufNum;

   ULONG  Flags;        /* 168 */

   USHORT LineLength;   /* 172 */
   USHORT PageLines;    /* 174 */
   short  tabTable;     /* 176 */
   short  LeftMargin;   /* 178 */
   short  TopMargin;    /* 180 */
   short  BottomMargin; /* 182 */

   ULONG  colors;       /* 184 */

   long   reserved1;    /* 188 */
   long   reserved2;    /* 192 */

   UCHAR  FileName[NAMELEN + 3];    /* 196 */
};

/* ------------- file requester-------  */

struct FR_struct {
	APTR	FR_Hail 		; /* Hailing text */
	APTR	FR_Ddef 		; /* *Filename array (FCHARS+1) */
	APTR	FR_Ddir 		; /* *Directory array (DSIZE+1) */
	APTR	FR_Wind 		; /* Window requesting or NULL */
	SHORT	FR_Flags		; /* Control. See above. SET TO NULL. */
	APTR	FR_WildFunc 	; /* Func to call for wildcards */
	APTR	FR_MsgFunc  	; /* Func to call with IntuiMessages */
};

struct ST {
	long	   num;
	struct ST *ptr;
};

struct HYPER {
	ULONG			fileSize;					/* size of hyper text file */
	struct HTENTRY  *table; 						/* ptr to lookup table */
	BPTT            fd;						    /* fd if accessing on disk */
	UCHAR			*text;  						/* accessing in memory */
	USHORT  		topEntry;					/* top entry in this table */
	USHORT  		current;	/* history[current] is current lookup index*/
	USHORT  		history[20];			   /* index of last 20 lookups */
};

struct   msgQueue  {
   short  Count;
   ULONG  Class;
   USHORT Code;
   USHORT Qualifier;
   short  MouseX,MouseY;
};

/* ------------------------------ INITS -------------------------------------- */

EXTRN UCHAR *saveFd,*macroptr,*savePtr,*sPP,*fastP,*sss
#ifdef ISMAIN
= NULL
#endif
;

EXTRN UCHAR  *warray,*charData,*wptr,*warpChip,*chipMem
#ifdef ISMAIN
= NULL
#endif
;

EXTRN struct Screen *edScreen
#ifdef ISMAIN
= NULL
#endif
;

EXTRN struct Window *edWindow
#ifdef ISMAIN
= NULL
#endif
;

EXTRN struct DateStamp ds
#ifdef ISMAIN
= {0L,0L,0L}
#endif
;

EXTRN struct TextFont *ffont
#ifdef ISMAIN
= NULL
#endif
;

EXTRN struct BitMap  *bp
#ifdef ISMAIN
= NULL
#endif
;

EXTRN struct ViewPort *vp
#ifdef ISMAIN
= NULL
#endif
;

EXTRN struct MsgPort *mp  /* reply port for our msgs */
#ifdef ISMAIN
= NULL
#endif
;

EXTRN struct IOPrtCmdReq *prtMsg
#ifdef ISMAIN
= NULL
#endif
;

EXTRN struct MsgPort *uport
#ifdef ISMAIN
= NULL
#endif
;

EXTRN struct List *msgList
#ifdef ISMAIN
= NULL
#endif
;

EXTRN struct Port *prtPort
#ifdef ISMAIN
= NULL
#endif
;

EXTRN struct DB    *saveB,*saveBlock,*sBB,*fastB,**fastBlock,*fB,*gB
#ifdef ISMAIN
= NULL
#endif
;

EXTRN struct ST *sStack
#ifdef ISMAIN
=NULL
#endif
;

EXTRN struct CB *curBuf,*saveBuf,*fastBufPtr,*saveBufPtr
#ifdef ISMAIN
= NULL
#endif
;

EXTRN UCHAR *fdprt,*fP,*gP,*ggP,*configPtr,*buffer,*lcmd,*curTable,*colPtr,
			*saveP,**fastPtr
#ifdef ISMAIN
= NULL
#endif
;

EXTRN BPTT fdKeyHelp
#ifdef ISMAIN
= NULL
#endif
;

/* ---------------------
EXTRN USHORT *menuDrawn
#ifdef ISMAIN
= NULL
#endif
;
----------------------- */

EXTRN  long 	   overstrike,autoBackup,readOnly,learnMode,mapChars,
				   busies,speakAlerts,speakMsgs,changed,userLocalA
#ifdef ISMAIN
= 0L
#endif
;

EXTRN  long 	   uga, ugb, kcmd, makeKeyHelp, seccs, miccs,localColor,
                   screenColor
#ifdef ISMAIN
= 0L
#endif
;

EXTRN  long 	   userLocalB,userGlobalA,userGlobalB,userGlobalC,userGlobalD,
                    leftMargin
#ifdef ISMAIN
= 0L
#endif
;

EXTRN  long 	   topMargin,bottomMargin,inpChar,mcrNum,singleWhite
#ifdef ISMAIN
= 0L
#endif
;

EXTRN  long 	   multiWhite, hideDisplay, scrollType,trapMenus,tabTable
#ifdef ISMAIN
= 0L
#endif
;

EXTRN  long 	   rowCol, markGadgets, icons, idleTime, menuOffset, pageLines
#ifdef ISMAIN
= 0L
#endif
;

EXTRN  long 	   rightJustify,prefPrint, cmdMultiplier,lace,teachKeys
#ifdef ISMAIN
= 0L
#endif
;

EXTRN  long 	   searchCaps,useKeys,columnar,cram, tinyCoords
#ifdef ISMAIN
= 0L
#endif
;

EXTRN  long 	   customScreen,smartTabs,wildCard,multiWild,allBut
#ifdef ISMAIN
= 0L
#endif
;

EXTRN  long 	   eitherOr,printTabs,loud,ArpBase,planeWidth,
				   topy,boty,bytes,desty,destx,mask1,mask2,
				   warpChipSize
#ifdef ISMAIN
= 0L
#endif
;

EXTRN  long 	   dummy,splitSize,wordWrap,trueTabs,autoIndent, capsLock, clickTime
#ifdef ISMAIN
= 0L
#endif
;

EXTRN  long 	   tinyPriority,globalFlags
#ifdef ISMAIN
= 0L
#endif
;

EXTRN  long 	   IntuitionBase,GfxBase,DosBase,DiskfontBase,RexxSysBase
#ifdef ISMAIN
= 0L
#endif
;


EXTRN  short	  reportMouse, mouseDown,curCol,keyHelpPos,oldStart,oldStop,
				  oldSplit,oldCurSplit,oldBuf,topaz11,modulo,lineTrace

#ifdef ISMAIN
=0
#endif
;

EXTRN short 	 inputQualifier, primitive, gPage,gRow,gColm,checkit,
                 subflag,oldColors,maxTest
#ifdef ISMAIN
=0
#endif
;

EXTRN short 	 inputChar, macroNum, curMsgIn, curMsgOut, cleared,
				 stopSave, hadAbort, clampAbort,stickMode
#ifdef ISMAIN
=0
#endif
;

EXTRN short 	 menuInset, curLearn, execLearn, oldCursorLine
#ifdef ISMAIN
=0
#endif
;

EXTRN short 	 vscrollamt, hscrollamt, newSplit, gcol, gChar, mouseX,
                 mouseY
				    /*, packing */
#ifdef ISMAIN
=0
#endif
;

EXTRN short 	 oldCursorCol, nSplit, displayFlag,warpUp,
				 startLine,stopLine,didScroll,curSplit
#ifdef ISMAIN
=0
#endif
;

EXTRN short 	 indent,wrap,flipRight,prints,maxLines,menusUp,reformatting
#ifdef ISMAIN
=0
#endif
;

EXTRN short 	 stackDepth,line,prtOpen,vertPixels,horPixels
#ifdef ISMAIN
=0
#endif
;

EXTRN short 	 noDisplay,breakOk
#ifdef ISMAIN
=0
#endif
;

EXTRN short 	 stopPause, noMemory
#ifdef ISMAIN
=0
#endif
;

EXTRN short 	 maxLineChars,charHeight,t1,t2,charWidth,bytesPerRow,backSet
#ifdef ISMAIN
=0
#endif
;

EXTRN short 	 macroLen,tiny,toTiny,saves,fontHeight,suppressClear
#ifdef ISMAIN
=0
#endif
;

EXTRN short splitBufNum[MAXSPLITS], startSplit[MAXSPLITS], stopSplit[MAXSPLITS]
#ifdef ISMAIN
= {0,0,0,0,0,0,0,0}
#endif
;


EXTRN UCHAR 	numArg
#ifdef ISMAIN
=0
#endif
;

/* ---------------------------- nonzero inits ---------------------------------- */

EXTRN  long 	   lineLength
#ifdef ISMAIN
= 77L
#endif
;

EXTRN  long 	   MAXFILES
#ifdef ISMAIN
= 640
#endif
;

EXTRN  long 	   sWidth
#ifdef ISMAIN
= 640L
#endif
;

EXTRN  long 	   sHeight
#ifdef ISMAIN
= 200L
#endif
;

EXTRN  long 	   pmEsc
#ifdef ISMAIN
= 27L
#endif
;

EXTRN  long 	   spooks
#ifdef ISMAIN
= 1L
#endif
;

EXTRN  long 	   eoline
#ifdef ISMAIN
= 10L
#endif
;


EXTRN short 	maxSaveSize
#ifdef ISMAIN
= 4096
#endif
;

EXTRN short 	saveSize
#ifdef ISMAIN
= 512
#endif
;

EXTRN short 	 showTitle,depth,startingUp
#ifdef ISMAIN
= 1
#endif
;

EXTRN short 	colTrack,macNum,visible
#ifdef ISMAIN
= -1
#endif
;

EXTRN UCHAR 	eol
#ifdef ISMAIN
= 10
#endif
;


EXTRN struct TextAttr font
#ifdef ISMAIN
= { "topaz.font",8,0,0 }
#endif
;

EXTRN long charMappings[4]
#ifdef ISMAIN
= {128L,129L,130L,131L}
#endif
;

EXTRN UCHAR   *DFALT_CFG
#ifdef ISMAIN
=(UCHAR *)"Config!"
#endif
;

EXTRN UCHAR   *DFALT_DAT
#ifdef ISMAIN
=(UCHAR *)"Data!"
#endif
;

EXTRN UCHAR coloring[3][4]
#ifdef ISMAIN
=  {0,15,15,0, 5,15,9,9, 10,15,0,15}
#endif
;

EXTRN UCHAR  printKeys[ (2 * MAXPRINTABLES) + 1]
#ifdef ISMAIN
=
"`1234567890-=\\ 0qwertyuiop[] 123asdfghjkl;'  456 zxcvbnm,./ .789\
~!@#$%^&*()_+| 0QWERTYUIOP{} 123ASDFGHJKL:\"  456 ZXCVBNM<>? .789"
#endif
;
/* " */

EXTRN UCHAR  altKeys[(2 * MAXPRINTABLES) + 1]
#ifdef ISMAIN
=
"`1234567890-=\\ 0qwertyuiop[] 123asdfghjkl;'  456 zxcvbnm,./ .789\
~!@#$%^&*()_+| 0QWERTYUIOP{} 123ASDFGHJKL:\"  456 ZXCVBNM<>? .789"
#endif
;
/* " */

#define 		MAXSUCH 	65

EXTRN long   *such[MAXSUCH]  /* WARNING:  These map into .defines ARGS!!! */
#ifdef ISMAIN
={ &pmEsc,
   &userGlobalA,	&userGlobalB,	&columnar,  	&cram,  	 &rowCol,
   &markGadgets,	&lace,  		&spooks,		&busies,	 &teachKeys,
   &MAXFILES,		&icons, 		&searchCaps,	&wildCard,   &eitherOr,
   &multiWild,  	&allBut,		&singleWhite,	&multiWhite, &menuOffset,
   &learnMode,  	&cmdMultiplier, &speakAlerts,	&speakMsgs,  &printTabs,
   &smartTabs,  	&customScreen,  &useKeys,		&prefPrint,  &idleTime,
   &hideDisplay,	&scrollType,	&trapMenus, 	&sWidth,	 &sHeight,
   &tinyPriority,	&capsLock, 		&clickTime, 	&userGlobalC, &userGlobalD,
   &trueTabs,		&autoIndent,	&overstrike,	&autoBackup, &readOnly,
   &wordWrap,		&rightJustify,  &mapChars,  	&changed,	 &userLocalA,
   &userLocalB, 	&tabTable,  	&lineLength,	&splitSize,  &leftMargin,
   &topMargin,  	&bottomMargin,  &pageLines, 	&eoline,	 &inpChar,
   &mcrNum, 		&localColor,	&screenColor,   &tinyCoords }
#endif
;

EXTRN struct NewScreen Screen
#ifdef ISMAIN
= {
0, 0, 640, 400, 2,  			/* LeftEdge, TopEdge, Width, Height, Depth */
0,1,							/* DetailPen, BlockPen */
HIRES | LACE,					/* ViewModes: LACE, HAM also */
CUSTOMSCREEN, /* CUSTOMBITMAP, */
NULL,
"UE",							/* COPYRIGHT, */
NULL,							/* *Gadgets: none */
NULL,							/* *CustomBitMap: none */
}
#endif
;


EXTRN struct NewWindow laceWindow
#ifdef ISMAIN
= {
0,1,							/* left, top */
640,400,						/* width,height */
0,1,							/* detailpen, blockpen */
(CLOSEWINDOW | MENUPICK | RAWKEY | MOUSEBUTTONS ),
/* --- MENUVERIFY | --- */

	/* == SELECTUP | SELECTDOWN | ACTIVEWINDOW | REQVERIFY | REQCLEAR
		DISKREMOVED | DISKINSERTED == */

(WINDOWCLOSE | NOCAREREFRESH | BORDERLESS | BACKDROP | ACTIVATE),
/* --- --- */

	/* SIMPLE_REFRESH | WINDOWDEPTH | GIMMEZEROZERO | RMBTRAP
		| SUPER_BITMAP | INACTIVEWINDOW */

NULL,							/* no custom gadgets */
NULL,							/* no custom menu images, just use checkmark */
COPYRIGHT,
NULL,							/* not pointing to a custom screen structure */
NULL,					/* not using superbitmap, so not pointing to bitmap structure */
0,0,0,0,						/* maxwidth for full window */
CUSTOMSCREEN,
}
#endif
;

EXTRN struct NewWindow TinyWindow
#ifdef ISMAIN
= {
0,0,							/* left, top */
100,22, 						/* width,height */
0,1,							/* detailpen, blockpen */
(RAWKEY | MOUSEBUTTONS),
(WINDOWDEPTH | WINDOWDRAG | NOCAREREFRESH | INACTIVEWINDOW),
NULL,							/* no custom gadgets */
NULL,							/* no custom menu images, just use checkmark */
(UBYTE *)"UE",  				/* starting title */
NULL,							/* not pointing to a custom screen structure */
NULL,				/* not using superbitmap, so not pointing to bitmap structure */
0,0,0,0,
WBENCHSCREEN,
}
#endif
;

EXTRN UCHAR  numArgs[MAXFCTTOKENS]
#ifdef ISMAIN
={
/* null */ 0,
/* abort */ 0,
/* not */ 0,
/* do */ 0,
/* while */ 0,
/* if */ 0,

/* else */ 0,
/* goto */ 0,
/* label */ 0,
/* nothing */ 0,
/* return */ 0,

/* returntrue */ 0,
/* returnfalse */ 0,
/* mousedown */ 0,

/* trackmouse */ 0,
/* updatedisplay */ 0,
/* inputwaiting */ 0,
/* thiskey */ 0,
/* abortSave */ 0,

/* restartprint */ 0,
/* reformat */ 0,

/* runlearn */ 0,
/* fullRefresh*/ 0,
/* refreshdisplay */ 0,
/* abortprint */ 0,
/* dummy */ 0,

/* gosub */ 0,
/* beepdisplay */ 0,
/* seeruler */ 0,
/* setruler */ 0,
/* dummy */ 0,

/* dummy */ 0,
/* stopspell */ 0,
/* spellerup */ 0,
/* hyperClose */   0,
/* hyperUp*/	   0,
/* inTiny */	   0,
/* screenToBack */  0,
/* screenToFront */ 0,
/* newfile */ 0,


/* nameBuffer */   2,

/* checkedSubMenu*/5,
/* menu */  	   4,
/* checkedMenu */  5,
/* subMenu */	   4,
/* runKey */	   1,

/* gtNum */ 	   2,

/* incNum */	   1,
/* decNum */	   1,
/* equateNum */    2,
/* eqNum */ 	   2,
/* geNum */ 	   2,

/* and */		   3,
/* or */		   3,
/* mul */		   3,
/* div */		   3,
/* add */		   3,

/* sub */		   3,
/* mod */		   3,
/* mouseXY */	   2,
/* setRGB  */	   4,
/* isEmpty */	   1,

/* getSplitLines */2,
/* getChar */	   1,

/* onScreen */     1,
/* vScroll */	   1,
/* hScroll */	   1,
/* insertRgn */    4,
/* setEol */	   1,

/* clearRgn */     2,
/* swapBuf */	   2,
/* print */ 	   2,
/* loadFile */     1,
/* insertFile */   3,

/* alertUser */    1,
/* askYesNo */     1,
/* saveFile */     1,
/* setFileName */  2,
/* getFileName */  2,

/* flipFlag */     2,
/* getFlag */	   2,
/* toggle */	   1,
/* toNumber */     2,
/* toWord */	   2,

/* toUpper */	   1,
/* toLower */	   1,
/* setLocal */     3,
/* hexDecimal */   1,
/* fileSize */     2,

/* locToLine */    3,
/* lineToLoc */    3,
/* search */	   4,
/* saveLearn */    1,
/* freeBuf */	   1,

/* getLocal */     3,
/* is */		   2,
/* loadLearn */    1,
/* quit */  	   1,
/* printerCode  */ 4,

/* saveConfig */   1,
/* loadConfig */   1,
/* moveCursor */   2,
/* equateLoc */    3,
/* incLoc */	   2,

/* decLoc */	   2,
/* eqLoc */ 	   3,
/* geLoc */ 	   3,
/* gtLoc */ 	   3,
/* getKey */	   1,

/* inputKey */     1,
/* swapKey */	   2,
/* killKey */	   1,
/* delay */ 	   1,
/* editBuf */	   1,

/* putMsg */	   1,
/* inputString */  1,
/* inputNum */     1,
/* insertChar */   2,
/* copyChar   */   2,

/* clearChar  */   1,
/* swapChar   */   2,
/* teachOne 	*/ 1,
/* execute */	   2,
/* speak */ 	   1,

/* copyColData  */ 5,
/* clearcoldata */ 3,
/* gadgetName */   2,
/* typeChar */     1,
/* changeDir */    1,

/* inUse */ 	   1,
/* setMaxFiles */  1,
/* getMaxFiles */  1,
/* getSerialNum */ 1,
/* getColors */    4,

/* locToIndex */   3,
/* indextoLoc */   3,
/* locToCol */     3,
/* colToLoc */     3,
/* splitWindow */  2,

/* getTabs */	   2,
/* getPageRowCol */3,
/* gotoPage */     2,
/* getKeyVal   */  2,
/* spell   */	   3,

/* startSpell */   3,
/* stringComp */   4,
/* rexxIn */	   5,
/* rexxOut */	   5,
/* loadKeys */  	3,
/* saveKeys */  	3,
/* push */  		2,
/* pop */			2,
/* getBufAddr */	2,
/* getStackSize */  3,
/* rollStack */ 	2,
/* setSearch */ 	1,
/* attachBuf */ 	2,
/* detachBuf */ 	1,
/* copyKey */		2,
/* gotoSplit */ 	1,
/* getsearch */ 	1,
/* fileRequest */	3,
/* peek */  		3,
/* poke */  		3,
/* getAddress */	2,
/* upFlag */		2,
/* downFlag */  	2,
/* switch */		1,
/* case */  		1,
/* default */		0,
/* text */  		5,
/* swapLoc */		3,
/* grep */  		3,
/* setGrep */		1,
/* getGrep */		1,
/* setColors */     4,
/* hyperOpen */ 	3,
/* hyper */ 		4,
/* saveState */ 	1,
/* loadState */ 	1,
/* setTaskPri*/ 	1,
/* draw  */ 		5,
/* setFont */		2,
/* sortLines */ 	2,
/* compile */ 		1,
/* compileDefaults */ 1,
/* getFont */ 		3,
/* stackBuf */ 	    2,
/* compareBuf*/ 	2,
/* define */ 		2,
/* clearBuf*/ 		1,
/* tabstospaces */  1,
/* spacestotabs */  1,
/* getRGB */ 		4,
/* xor */ 		    3,
/* fold */ 		    4,
/* setFold */ 		4,
/* getFold */ 		5,
/* dummy */ 		0,
/* dummy */ 		0
}
#endif
;

/* -------------------- non inits ------------------ */


EXTRN struct ST *nStack[ALLBUFS],*bStack[ALLBUFS];
EXTRN struct Menu *edMenu[MAXMENUS];
EXTRN struct DB *lineBlocks[MAXLINES];
EXTRN struct CB *buf[ALLBUFS + 1], *bufPtrArgs[MAXARGS];
EXTRN  long    *usn;
EXTRN struct RastPort *rp;


EXTRN long bufPopStack[ALLBUFS],numPopStack[ALLBUFS],
			n[ALLBUFS + 1], longArgs[MAXARGS];
EXTRN long printLen[MAXPRINTS],printByte[MAXPRINTS];


EXTRN short cmdLens[MAXMACROS], menuMacroNum[MAXITEMS*MAXMENUS*MAXSUBITEMS];
EXTRN short lineHeight[MAXLINES];
EXTRN short printChoice[MAXPRINTS];
EXTRN short bufferFlags[ALLBUFS];


EXTRN UCHAR xnum[16];
EXTRN UCHAR args[MAXARGS],fontName[32];
EXTRN UCHAR ls[MAXLINES], rv[22], cs[CBOVL * 2];
EXTRN UCHAR dataName[64],gadgetName[4][22], z[MAXLINECHARS],rc[32],
				passive[MAXLINECHARS];
EXTRN UCHAR tabTables[MAXTABTABLES][MAXTABS + 1],lineBuf[MAXLINECHARS];
EXTRN long *longPtrArgs[MAXARGS];
EXTRN UCHAR *cmdTable[MAXMACROS];
EXTRN UCHAR *linePtrs[MAXLINES], *bufferNames[ALLBUFS];
EXTRN UCHAR *printBuf[MAXPRINTS], *ptrArgs[MAXARGS];
EXTRN char    msgSave[128];


EXTRN struct msgQueue msgQ[MAXMSGS+1],learnQ[MAXLEARN + 1];
EXTRN struct HYPER  hyperText;
EXTRN struct BitMap  warpMap;

EXTRN ULONG *menuDrawn;

#define MENUDRAWN   (*menuDrawn & 128L)

/* ------- used by DEFINES in ue3.c ----- */
struct DEFN {       /* size is 40 + data */
    struct DEFN *next;
    USHORT      len;
    UCHAR       source[34];
    UCHAR       target[4];  /* any amt of data */
};


EXTRN struct DEFN *gDefines,*lDefines
#ifdef ISMAIN
= NULL
#endif
;

#define MAX_T    16

struct FOLD {
    UCHAR   x[4];
    UCHAR   num,f,sk,pad;
};

EXTRN struct FOLD foldTests[MAX_T];



