
/******
 * Includes
 ******/

#include <exec/types.h>
#include <exec/ports.h>
#include <dos/dos.h>
#include <intuition/screens.h>



/******
 * Defines
 ******/

#define ASM		__asm
#define SAVEDS		__saveds
#define RG(x)		register __ ## x

#define MAXCOLOR	256	/* Max # of colors. ProgED 2.0 can save up to 256 colours.
				   1.0 & 1.1 releases could save only 32 colours. */

#define MAXDEPTH	8	/* Log2 of MAXCOLOR */

#define MAXREXXARGS	10	/* Max # of arguments for ARexx cmds */

#define MAXFILENAME	121	/* Max filename lenght */

#define	INSCHAR		1	/* UNDO: Insert char (INS) */
#define REPCHAR		2	/* UNDO: Replace char (OVR) */
#define	DELCHAR		3	/* UNDO: Delete char */
#define	BACKCHAR	4	/* UNDO: Backspace char */
#define	CUTLINE		5	/* UNDO: Cut line */
#define	PASTELINE	6	/* UNDO: Paste line */
#define	CLEARBLOCK	7	/* UNDO: Clear block */
#define	CUTBLOCK	8	/* UNDO: Cut block */
#define	PASTEBLOCK	9	/* UNDO: Paste block */
#define REPLACE		10	/* UNDO: Replace */
#define UPPERCASE	11	/* UNDO: Upper case char */
#define LOWERCASE	12	/* UNDO: Lower case char */
#define TOGGLECASE	13	/* UNDO: Toggle case char */
#define SWAPLINE	14	/* UNDO: Swap lines */
#define DOUBLELINE	15	/* UNDO: Double line */
#define UPPERCASEBLOCK	16	/* UNDO: Upper case block */
#define LOWERCASEBLOCK	17	/* UNDO: Lower case block */
#define TOGGLECASEBLOCK	18	/* UNDO: Toggle case block */
#define LAYOUTBLOCK	19	/* UNDO: Layout block */
#define INDENTBLOCK	20	/* UNDO: Indent block */
/* The followings are avaiable from ProgED 2.0 and above */
#define DELEOL		21	/* UNDO: Delete EOL */
#define	DELWORD		22	/* UNDO: Delete word */
#define	BACKWORD	23	/* UNDO: Backspace word */

#define MAXMARKER	10	/* Max # of markers */

#define IND_MR		'0'	/* Words in Prefs.KeyWordInd[] MUST START with */
#define IND_ML		'1'	/* one of this chars. They identify type of */
#define IND_SR		'2'	/* indentation to assign at the word. */
#define IND_SL		'3'	/* In ProgED 1.0 & 1.1 one of this chars */
#define IND_MR_SR	'4'	/* should start the string. From 2.0 */
#define IND_MR_SL	'5'	/* one of them must START the string. */
#define IND_ML_SR	'6'
#define IND_ML_SL	'7'

#define NO_SEL		0	/* If PEDWindow.Block=NO_SEL -> No block marked */
#define BLOCK_SEL	1	/* If PEDWindow.Block=BLOCK_SEL -> Start of a block is marked */
#define COLBLOCK_SEL	2	/* If PEDWindow.Block=COLBLOCK_SEL -> Start of a column block is marked */



/******
 *
 * Template structure
 * ------------------
 *
 * It stores the activation string & the program to execute. This
 * structure is linked via NextTemplate field in a list. The
 * access pointer is stored in Template field of Prefs structure.
 *
 ******/

#define MAXTEMPLATE	21

struct MyTemplate
{
	char			 Template[MAXTEMPLATE+1];
	struct MyProgram	*Prg;
	struct MyTemplate	*NextTemplate;
};



/******
 *
 * Scanner structure
 * -----------------
 *
 * It stores the scanners in a linked list accessible via Scan field
 * of Prefs structure. In each structure you can find the BPTR to
 * seglist of the scanner, the entry point to the scanner, the
 * identification pattern for this scanner and the name of scanner.
 *
 ******/

#define MAXEXTSCAN	31
#define MAXSCANNAME	121

struct MyScan
{
	BPTR		 SegList;
	ULONG		(* ASM ScanFunction)(RG(a0) char *,RG(a1) char *);
	char		 ScanExtension[MAXEXTSCAN+1],
			 Name[MAXSCANNAME+1];
	struct MyScan	*NextScan;
};



/******
 *
 * CommandData structure
 * ---------------------
 *
 * An external cmd will receive this struct at each call.
 *
 ******/

struct CommandData
{
	char			 *CommandLine;
	void			**CommandArgs;
	struct PEDWindow	 *CurrentWindow,
				 *FirstWindow;
	struct Prefs		 *CurrentPrefs;
	LONG ASM (*ExecuteInternalCommand)(RG(a0) char *);
};



/******
 *
 * MyProgram structure
 * -------------------
 *
 * This structure stores a command (internal/external/shell or arexx).
 * Each ProgED program is build up by a linked list of this structures
 * linked via NextProgram field.
 * The String field stores the command,Dir the current dir (used only
 * if the cmd is of TYPE_SHELL or TYPE_AREXX). In Output field you can
 * find the output file for TYPE_AREXX & TYPE_SHELL cmds (default CON:)
 * Type specify type of cmd (see TYPE_xxx defines). Async field is
 * TRUE if a TYPE_SHELL cmd have to be runned async.
 * If Shanghai is TRUE then the command (SHELL/AREXX) must be runned
 * in shanghai mode (ProgED screen became the default public screen).
 * Secs specify the number of seconds of shanghai mode (if it's
 * enabled).
 * NOTE: From ProgED 1.0/1.1 this structure is changed due to
 * introduction of Shanghai & Secs fields.
 *
 ******/

#define	TYPE_DUMMY	0
#define	TYPE_INTERNAL	1
#define	TYPE_SHELL	2
#define	TYPE_AREXX	3
#define	TYPE_TEXT	4

struct MyProgram
{
	char			*String,
				*Dir,
				*Output;
	UBYTE			 Type,
				 Async,
				 Shanghai,
				 Secs;
	struct MyProgram	*NextProgram;
};



/******
 *
 * APIClient structure
 * --------------
 *
 * APIClient stores API clients. In each structure you can find the
 * MsgPort  (ac_ClientPort), notify flags (ac_Notify), name (ac_Name)
 * of this client.
 * The ac_Next field links up a list of clients. The access pointer
 * to the list is the Clients field of Prefs structure.
 *
 * This structure have to be used when a new client want to 
 * register itself at API ProgED port.
 *
 ******/

struct APIClient
{
	struct MsgPort		*ac_ClientPort;
	ULONG			 ac_Notify;	/* See NOTIFY_xxx defines */
	char			*ac_name;
	struct APIClient	*ac_Next;
};

#define	NOTIFY_ON_SHOW_HIDE	0x00000001	/* Notify if ProgED closes & opens its screen */
#define	NOTIFY_ON_KEY		0x00000002	/* Notify each key pressed */



/******
 *
 * APIMessage structure
 * --------------------
 *
 * A client must use this structure to communicate with ProgED.
 * Type of message is in am_MsgType field. The am_MsgArg[] array
 * is used to communicate the message arguments'. am_RC specify
 * the return code (see RC_xxx defines).
 *
 ******/

struct APIMessage
{
	struct Message		 am_Message;
	ULONG			 am_MsgType,
				 am_MsgArg[10],
				 am_RC;
};

/* This defines specify msg that ProgED can send to the clients.
   Noone needs arguments */

#define PED_API_QUIT	0x80000000	/* PED is quitting -> quit yourself */
#define PED_API_HIDE	0x80000001	/* PED is closing its screen -> close your windows */
#define PED_API_SHOW	0x80000002	/* PED is opening its screen -> open your windows */
#define PED_API_KEY	0x80000003	/* A key was pressed */

/* This defines specify msg that a client can send to ProgED */

#define	PED_API_REGISTER		0x90000000	/* Register me. Arg[0] = &struct APIClient */
#define	PED_API_UNREGISTER		0x90000001	/* Unregister me. Arg[0] = &struct APIClient */

#define PED_API_ADD_INTERNAL_COMMAND	0x90000002	/* Add an external cmd: Arg[0] = &struct ArexxExtCmds */
#define PED_API_REM_INTERNAL_COMMAND	0x90000003	/* Remove an ext cmd: Arg[0] =&struct ArexxExtCmds */

#define PED_API_GET_ACTIVE_WINDOW	0x90000004	/* Get active window */
#define PED_API_GET_WINDOW_LIST		0x90000005	/* Get first window */
#define PED_API_GET_SCREEN_ADDRESS	0x90000006	/* Get screen address */
#define PED_API_GET_PREFS_ADDRESS	0x90000007	/* Get prefs address */
#define PED_API_GET_PUBSCRNAME		0x90000008	/* Get screen name */



/******
 *
 * Menus structures
 * ----------------
 *
 * ProgED stores its menus using this structures. They builds up a tree
 * like Intuition menus tree.
 *
 * Description:
 *
 * MyMenu
 * ------
 *
 * Name:	String to be used in rendering.
 * Items:	Points to items of this menu.
 * NextMenu:	Next menu :-)
 *
 *
 * MyItem
 * ------
 *
 * Name:	String to be used in rendering.
 * Key:		String or char to render hotkey of this item.
 * Subs:	Subitems of this item.
 * Prgs:	ProgED Program to be executed at each activation of this item.
 * CheckType:	See CHECK_xxx defines. If this field not is equal to
 *		CHECK_NONE then this item is a check item. The value
 *		defines the preference flag to be used in rendering.
 * NextItem:	Next item ( Noooooo! Really? )
 *
 *
 * MySub
 * ------
 *
 * Name:	String to be used in rendering.
 * Key:		String or char to render hotkey of this subitem.
 * Prgs:	ProgED Program to be executed at each activation of this subitem.
 * CheckType:	See CHECK_xxx defines. If this field not is equal to
 *		CHECK_NONE then this item is a check item. The value
 *		defines the preference flag to be used in rendering.
 * NextSub:	Next subitem ( I waited for it... )
 *
 * The access pointer to the tree can be find in Menu field of Prefs structure.
 *
 ******/

#define MAXMENUNAME	30

struct MyMenu
{
	char			 Name[MAXMENUNAME+1];
	struct MyItem		*Items;
	struct MyMenu		*NextMenu;
};

struct MyItem
{
	char			 Name[MAXMENUNAME+1];
	char			 Key[MAXMENUNAME+1];
	struct MySub		*Subs;
	struct MyProgram	*Prg;
	UBYTE			 CheckType;
	struct MyItem		*NextItem;
};

struct MySub
{
	char			 Name[MAXMENUNAME+1];
	char			 Key[MAXMENUNAME+1];
	struct MyProgram	*Prg;
	UBYTE			 CheckType;
	struct MySub		*NextSub;
};

#define CHECK_NONE		0
#define CHECK_USEKEYWORDCOL	1
#define CHECK_USECOMMENT1COL	2
#define CHECK_USECOMMENT2COL	3	/* From ProgED 2.0 I changed CHECK_xxx */
#define CHECK_ERASERIGHT	4	/* flags due to the "splitting" of */
#define CHECK_SHOWCURPOS	5	/* CHECK_USECOMMENT flag into the */
#define CHECK_SHOWPATHNAME	6	/* couple CHECK_USECOMMENT1 and */
#define CHECK_AUTOARRANGEVER	7	/* CHECK_USECOMMENT2. */
#define CHECK_AUTOARRANGEHOR	8
#define CHECK_ARRANGEFAVOURITE	9
#define CHECK_USEBACKUP		10
#define CHECK_SAFESAVE		11
#define CHECK_UNFOLDGOTOMARKER	12
#define CHECK_UNFOLDGOTOLINE	13
#define CHECK_UNFOLDGOTOBYTE	14
#define CHECK_UNFOLDGOTOSCAN	15
#define CHECK_UNFOLDSEARCH	16
#define CHECK_AUTOFOLD		17
#define CHECK_USEKWINDENTATION	18
#define CHECK_FASTLOADING	19
#define CHECK_USECLOCK		20
#define CHECK_BLANKBORDERS	21
#define CHECK_AUTORELOAD	22
#define CHECK_AUTORELOADPRJ	23
#define CHECK_USEMOUSEBLANKER	24
#define CHECK_USEAPPICON	25
#define CHECK_USEAPPITEM	26
#define CHECK_SETDEFPUBSCR	27
#define CHECK_USETEMPLATE	28
#define CHECK_USEAUTOCASE	29
#define CHECK_NUM		30



/******
 *
 * MyKey structure
 * ---------------
 *
 * This structure stores the programs to be executed at each key pressed.
 * In Qual & Code fields you can find the Intuition Qualifier & Code
 * Activation values. Prg points to a MyProgram structure that ProgED
 * will execute at the activation. NextKey points to the next structure
 * of the list. The access pointer is the Key field of Prefs structure.
 *
 ******/

struct MyKey
{
	ULONG			 Qual,
				 Code;
	struct MyProgram	*Prg;
	struct MyKey		*NextKey;
};



/******
 *
 * Event structure
 * ---------------
 *
 * An array of this structures builds up the UNDO queue.
 * I think that noone is interested in its contents, so I
 * will not describe it. Perhaps I will do it later ... :-(
 *
 ******/

struct Event
{
	UBYTE		 Type;
	UBYTE		 Arg1;
	char		*Arg2;
	ULONG		 Arg3,
			 Arg4,
			 Arg5,
			 Arg6,
			 Arg7;
	LONG		 Col,
			 Line;
};



/******
 *
 * Folder structure
 * ---------------
 *
 * This structure stores each text fold's. Each text has a linker list
 * of this structures in Folder field of PEDText structure. If a line
 * is in a fold its Folder field points to a Folder structure, too.
 *
 * Description
 * -----------
 *
 * Name:	Name of the fold. It will be used in rendering.
 * Num:		# of lines folded.
 * Line:	Pointer to the line of the cursor at fold time.
 * Col:		# of column of the cursor at fold time.
 * Start:	First line of the fold.
 * Stop:	Last line of the fold.
 * NextFolder:	This field links up a list of this structures.
 *
 ******/

#define MAXFOLDNAME	49

struct Folder
{
	char		 Name[MAXFOLDNAME+1];
	long		 Num;
	struct Line	*Line;
	long		 Col;
	struct Line	*Start,
			*End;

	struct Folder	*NextFolder;
};



/******
 *
 * Marker structure
 * ----------------
 *
 * The Marker structure stores a position of the text (yeah!)
 * The Line field points to the line while the Col field contains
 * the column number.
 *
 ******/

struct Marker
{
	struct Line	*Line;
	long		 Col;
};

/* This structure contains the "static" markers. This new type of
   markers are saved together the file. You can access to the list
   list of the "static" markers using the field "LMarker" of the
   PEDText structure. */
struct LinkedMarker
{
	struct Line		*Line;	/* Pointer to the line */
	long			 Col;	/* Column */
	struct LinkedMarker	*Next;	/* Pointer to next structure */
};



/******
 *
 * ArexxExtCmds structure
 * ----------------------
 *
 * This structures stores datas about the internal & external cmds.
 * It have to be used when a client wants to add an external cmd.
 *
 * Description:
 * ------------
 *
 * External:	Set up to TRUE,never FALSE.
 * Name:	Name of the command.
 * Template:	ReadArgs Template's of the command.
 * Default:	Array of the default values.
 * CommFunc:	Pointer to the external function. This, generally,
 *		is in the code of the client (REMEMBER TO USE __saveds option!)
 * NextCmd:	Don't use it ! ):-|
 *
 ******/

struct ArexxExtCmds
{
	UBYTE			 External;
	char			*Name;
	char			*Template;
	void			*Defaults[MAXREXXARGS];
	LONG ASM		(*CommFunc)( RG(a0) struct CommandData *);
	struct ArexxExtCmds	*NextCmd;
};



/******
 *
 * Line structure
 * --------------
 *
 * The Line structure stores a line of the text. The field Buffer
 * points to a zero termined string (the line itself).
 * The PrevLine & NextLine pointers points to the next & previous
 * line (I'm a genious, isn't it ? ). If the line is folded the Folder
 * field point to the relative Folder structure. If the line isn't
 * folded it contains NULL.
 *
 ******/

struct Line
{
	char		*Buffer;
	struct Line	*PrevLine,
			*NextLine;
	struct Folder	*Folder;
};



/******
 *
 * PEDText structure
 * -----------------
 *
 * This structure stores a text.
 *
 * Description:
 * ------------
 *
 * Filename:	Name of the file loaded (with PATH!).
 * MaxCol:	Number of columns.
 * MaxLine:	Number of lines.
 * Size:	Lenght of the text.
 * Changes:	Changes from last save.
 * FirstLine:	Pointer to the first line of text.
 * LastLine:	I must write it?
 * Events:	Pointer to the Events array to be used for undo.DON'T TOUCH!
 * LastEvent:	DON'T TOUCH!
 * NumEvent:	DON'T TOUCH!
 * NumRedo:	DON'T TOUCH!
 * UndoLevels:	Undo queue lenght.
 * Folder:	Pointer to the first folder of this text.
 * LinesFolded:	Lines not visible (because folds).
 * NumFolds:	Number of folds (lenght of list accessible via Folder field).
 * AutoSave:	This is a timer. When it reaches zero then an autosave occurs.
 * DateStamp:	Date of last change.
 * THE FOLLOWINGS FIELDS ARE PRESENT FROM 2.0 RELEASE
 * MemoryPool:	MemoryPool used to allocate the memory for the text.
 * StickyReply: DON'T TOUCH!
 * FileType:	Pointer to the FileType structure of this text.
 * LMarker:	Pointer to the first "static" marker of this text.
 * UntitledFlag:TRUE if this is a "fresh" text (Untitled yet).
 *
 ******/

struct PEDText
{
	char		 FileName[200];

	LONG		 MaxCol,
			 MaxLine;

	ULONG		 Size;

	ULONG		 Changes;

	struct Line	*FirstLine,
			*LastLine;

	struct Event	 *Events;
	LONG		 LastEvent;
	ULONG		 NumEvent,
			 NumRedo,
			 UndoLevels;

	struct Folder	*Folder;
	int		 LinesFolded;
	int		 NumFolds;

	ULONG		 AutoSave;

	struct DateStamp DateStamp;

	APTR		 MemoryPool;

	APTR		 StickyReply;

	struct FileType	*FileType;

	struct LinkedMarker *LMarker;

	UBYTE		 UntitledFlag;
};



/******
 *
 * PEDWindow structure
 * -------------------
 *
 * This structure stores datas about ProgED windows'.
 *
 * Description:
 * ------------
 *
 * Window:		Intuition window. It can be NULL, however. It happens
 *			if the window is freezed.
 * GadgetScrollX,
 * GadgetScrollY,
 * GadgetUpArrow,
 * GadgetDownArrow,
 * GadgetLeftArrow,
 * GadgetRightArrow:	Pointers to the scrollers and arrows gadgets.
 * ImageUpArrow,	
 * ImageDownArrow,
 * ImageLeftArrow,
 * ImageRightArrow:	Pointer to arrows images'.
 * OldSx,OldSy:		Stores position of the text in window at last refresh.
 * Sx,Sy:		Position of text in window.
 * Text:		Pointer to the text (structure PEDText).
 * NumCol:		Number of visible columns.
 * NumLine:		Number of visible lines.
 * Left,
 * Right,
 * Width,
 * Height:		Store windows info when ProgED needs close its screen.
 * ZoomInfo:		Store intuition zoom data.
 * Title:		Title of this window. ProgED refresh it when needed.
 * CursorCol,
 * CursorLine:		Position of the cursor in the text.
 * LastCursorCol:	Column of the cursor at last insert.
 * MLine:		TRUE=Lines block,FALSE=normal block.
 * Block:		See COL_xxx defines.
 * BlockLine:		Line number of start.
 * BlockCol:		Column number of start.
 * Line:		Pointer to the line of the cursor.
 * RealNumCol:		Lenght of the line buffer.
 * LogicNumCol:		Lenght of the line (it's greather than RealNumCol,
 * 			because TABs can use more space than 1 column!).
 * FWidth:		Chars Width of text font.
 * FHeight:		Chars Height of text font.
 * FBase:		Chars Baseline of text font.
 * WOffsetX:		Offset X from window left border.
 * WOffsetY:		Offset Y from window top border.
 * RP:			window rastport.
 * Ins:			TRUE=insert mode, FALSE=overwrite mode.
 * CuttedLine:		Pointer to line clipboard (NULL=empty).
 * Marker:		Array of markers for this window.
 * Frozen:		TRUE=window frozen,FALSE=window open.
 * Locked:		If this field is >0 then the window is locked!
 *			NOTE: If this window is "splitted" you MUST look
 *			at split master window to read this field! Since
 *			the SplitMaster field of a split master window
 *			points to the master itself you should use ALWAYS:
 *
 *			    [window pointer]->SplitMaster->Locked
 *
 *			to read this field. If you don't use it you
 *			can manipulate a locked text!
 * OldLine,
 * LineBuffer,
 * Pun,
 * InsLine,
 * Warn:		Fields used when a handler loads the file in this window.
 * OldKeys:		Last keys pressed in this window. Useful for template checks.
 * PunOldKeys:		Points to the last key in OldKeys array.
 * NextSplit:		If this field isn't NULL then this window was splitted.
 *			This field links up a list of twins windows.
 *			The first window in this list owns the text, while
 *			others can ONLY use it but not free it!
 * SplitMaster:		This field points to the text owner of the twins windows.
 *			Generally this field points to the structure itself
 *			(generally the text owner is the window itself!).
 *			if a window isn't the text owner then this field
 *			points to the window that own it.
 *			Yeah! I know, it's crazy... But it's the truth...
 * NextWindow:		Points to the next window.
 * UserData:		If you need to add data in a window use this array...
 * CurBitMap:		DON'T TOUCH THIS! (From V2.0)
 *
 ******/

struct PEDWindow
{
	struct Window	*Window;

	struct Gadget	*GadgetScrollX,
			*GadgetScrollY,
			*GadgetUpArrow,
			*GadgetDownArrow,
			*GadgetLeftArrow,
			*GadgetRightArrow;

	struct Image	*ImageUpArrow,
			*ImageDownArrow,
			*ImageLeftArrow,
			*ImageRightArrow;

	int		 OldSx,
			 OldSy,
			 Sx,
			 Sy;

	struct PEDText	*Text;

	LONG		 NumCol,
			 NumLine;

	WORD		 Left,
			 Top,
			 Width,
			 Height;

	WORD		 ZoomInfo[4];

	char		 Title[200];

	LONG		 CursorCol;
	LONG		 CursorLine;
	LONG		 LastCursorCol;

	UBYTE		 MLine,
			 Block;
	LONG		 BlockLine,
			 BlockCol;

	struct Line	*Line;
	UWORD		 RealNumCol;
	UWORD		 LogicNumCol;

	UWORD		 FWidth,
			 FHeight,
			 FBase,
			 WOffsetX,
			 WOffsetY;
	struct RastPort *RP;

	UBYTE		 Ins;

	char		*CuttedLine;

	struct Marker	 Marker[MAXMARKER];

	UBYTE		 Frozen;

	ULONG		 Locked;

	struct Line	*OldLine;
	UBYTE		*LineBuffer,
			*Pun,
			 InsLine,
			 Warn;

	UBYTE		 OldKeys[MAXTEMPLATE];
	UBYTE		 PunOldKeys;

	struct PEDWindow *NextSplit,
			 *SplitMaster;

	struct PEDWindow *NextWindow;

	ULONG		 UserData[16];

	struct BitMap	*CurBitMap;
};



/******
 *
 * FileType structure
 * ------------------
 *
 * This structure stores datas about ProgED filetypes. From 2.0.
 *
 * Description:
 * ------------
 *
 * Node:		DON'T TOUCH THIS!
 * Label:		Label used to name the filetype.
 * Pattern:		AmigaDOS pattern of files.
 * UseKeyWordColors:	TRUE=activate keywords colors.
 * KeyAlpha:		DON'T TOUCH THIS!
 * KeyWord:		Pointer to an array containing the keywords.
 * NumKeyWord:		Number of keyword in KeyWord array.
 * GestColorOff:	This is the charS that disable keywords colors.
 * GestColorOn:		See GestColorOff... From 2.0 these fields are
 *			arrays.
 * UseComment1Colors:	TRUE=activate comments colors across lines.
 * UseComment2Colors:	TRUE=activate comments colors on single line.
 * ColorAllLine:	TRUE=color all line on "single line comments".
 * CheckColorLines:	# of lines checked for a comment.
 * Comment1Pen:		Pen to be used rendering the (*-*) comment.
 * Comment2Pen:		Pen to be used rendering the // comment.
 * Comment1On:		Comment initial string.
 * Comment2Off:		Comment final string.
 * Comment2On:		Comment initial string for // comment.
 * DefBits:		Default bits of saved file.
 * CreateIcons:		TRUE=Create icons at save.
 * DefComment:		Comment of saved file.
 * SearchFoldFileName:	Name of filename of the external folder.
 * SearchFoldSeg:	Seglist of the folder.
 * SearchFold:		Pointer to the function into the seglist.
 * FoldStartStr:	Start string. Used (optionally) by the folder.
 * FoldStopStr:		Stop string. Used (optionally) by the folder.
 * UseKeyWordInd:	TRUE=Use keyword indentation.
 * KeyWordInd:		Array of keywords needed for indentation.
 * NumKeyWordInd:	Number of keywords in KeyWordInd array.
 * Template:		Pointer to first Template structure.
 * UseTemplate:		TRUE=Activate templates.
 * Brackets:		Pointer to an array containing the brackets strings
 *			for brackets match.
 * NumBrackets:		Number of strings in Brackets array.
 * DictWord:		Pointer to an array containing the dictionary words.
 * NumDictWord:		Number of word in DictWord array.
 * UseAutoCase:		TRUE=Activate autocase.
 * GestCaseOff:		Case management off chars.
 * GestCaseOn:		Case management on chars.
 * UseAutoSave:		TRUE=Activate autosave.
 * MinAutoSave:		Number of minutes for autosave.
 *			it simply load file slowly.
 * EraseRight:		TRUE=erase blanks & tabs on the right.
 * Backup:		TRUE=create backup at save.
 * BackupDir:		Dir to store backups. If it's empty ProgED
 *			will use the dir used to save file.
 * SaveRefs:		TRUE=Save related referements.
 * RefsDir:		Dir to store refs. If it's empty ProgED
 *			will use the dir used to save file.
 * CheckPar:		TRUE=Activate () check on lines.
 * Left,
 * Right:		Column borders used in block layouting.
 * Tab:			Size of tabs.
 * IndJump:		# of chars per levels of indentation.
 *			Better if you set it equal to Tab size.
 * AutoFold:		TRUE=Auto fold all functions in text at load.
 * InsStart:		Ins flag at window creation. TRUE=ins,FALSE=ovr.
 * TabEqSpace:		TRUE=tab equal spaces.
 * WordWrapping:	TRUE=Word wrapping active.
 * RightWW:		Right margin for word wrapping.
 * SaveMarkers:		TRUE=Save "static" markers together files.
 * RefsDir:		Dir to store markers files. If it's empty ProgED
 *			will use the dir used to save file.
 * SeparatorsString:	Specify separators.
 * SepChar[256]:	Table of separators.
 * AutoReLoad:		TRUE=Reload files opened at last quit.
 * NextFileType:	Pointer to the next filetype of the list.
 *
 ******/

#define MAXFILETYPELABEL	21
#define MAXFILETYPEPATTERN	51
#define MAXCOLONOFF		11
#define MAXCOMMENT		19
#define MAXCOMMENT2		79
#define MAXFOLDFUNCNAME		49
#define MAXCASEONOFF		11
#define MAXSEPARATORSSTRING	149
#define MAXFOLDSTR		19

struct FileType
{
	struct Node		 Node;

	char			 Label[MAXFILETYPELABEL+1],
				 Pattern[MAXFILETYPEPATTERN+1];

	UBYTE			 UseKeyWordColors;
	UBYTE			 KeyAlpha[256];
	char			 **KeyWord;
	int			 NumKeyWord;
	char			 GestColorOff[MAXCOLONOFF+1],
				 GestColorOn[MAXCOLONOFF+1];

	UBYTE			 UseComment1Colors;
	UBYTE			 UseComment2Colors;
	UBYTE			 ColorAllLine;
	UWORD			 CheckColorLines;

	UBYTE			 Comment1Pen,
				 Comment2Pen;
	char			 Comment1On[MAXCOMMENT+1],
				 Comment1Off[MAXCOMMENT+1],
				 Comment2On[MAXCOMMENT+1];

	LONG			 DefBits;
	UBYTE			 CreateIcons;
	char			 DefComment[MAXCOMMENT2+1];

	char			 SearchFoldFileName[MAXFOLDFUNCNAME+1];
	BPTR			 SearchFoldSeg;
	ULONG			(* ASM SearchFold)(RG(a0) struct PEDWindow *,RG(d0) LONG,RG(d1) LONG,RG(a1) ULONG *,RG(a2) ULONG *,RG(a3) char *);
	char			 FoldStartStr[MAXFOLDSTR+1],
				 FoldStopStr[MAXFOLDSTR+1];

	UBYTE			 UseKeyWordInd;
	char			**KeyWordInd;
	int			 NumKeyWordInd;

	struct MyTemplate	*Template;
	UBYTE			 UseTemplate;

	char			**Brackets;
	int			 NumBrackets;

	char			**DictWord;
	int			 NumDictWord;
	UBYTE			 UseAutoCase;
	char			 GestCaseOff[MAXCASEONOFF+1],
				 GestCaseOn[MAXCASEONOFF+1];

	UBYTE			 UseAutoSave;
	UWORD			 MinAutoSave;

	UBYTE			 EraseRight;

	UBYTE			 Backup;
	char			 BackupDir[MAXFILENAME+1];

	UBYTE			 SaveRefs;
	char			 RefsDir[MAXFILENAME+1];

	UBYTE			 CheckPar;

	UWORD			 Left,
				 Right;

	UBYTE			 Tab;

	UWORD			 IndJump;

	UBYTE			 AutoFold;

	UBYTE			 InsStart;

	UBYTE			 TabEqSpace;

	UBYTE			 WordWrapping;
	UWORD			 RightWW;

	UBYTE			 SaveMarkers;
	char			 MarkerDir[MAXFILENAME+1];

	char			 SeparatorsString[MAXSEPARATORSSTRING+1];
	UBYTE			 SepChar[256];

	UBYTE			 AutoReLoad;

	struct FileType		*NextFileType;
};



/******
 *
 * Prefs structure
 * ---------------
 *
 * This structure stores datas about ProgED preferences.
 *
 * NOTE: From 2.0 this structure is changed. It will changes at
 *       each release, if necessary. SO DON'T USE IT, PLEASE.
 *       If it's necessary do it but, perharps, your job will
 *       not work on future releases of ProgED.
 *
 * Description:
 * ------------
 *
 * ScreenMode:		This is the DisplayID of the screen used. If you want
 *			to copy WB screen use 0xFFFF0000, if you want to open
 *			on a public screen use 0xFFFF0001 and put in
 *			PublicScreenName field the screen name.
 * ScreenWidth,
 * ScreenHeight,
 * ScreenOverscanType,
 * ScreenDepth,
 * ScreenAutoScroll:	Properties of the screen. They are used only if
 *			ScreenMode doesn't is equal to 0xFFFF0000 (clone
 *			WB screen) or 0xFFFF0001 (Open on WB screen).
 * ScreenColors:	Colors of the the custom screen.
 * ScreenFontName,
 * ScreenFontSize:	Name & size of the screen font.
 * MenuFontName,
 * MenuFontSize:	Name & size of the menu font.
 * TextFontName,
 * TextFontSize:	Name & size of the text font.
 * GadgetFontName,
 * GadgetFontSize:	Name & size of the gadgets font.
 * APIClients:		Pointer to an array containing the filenames of
 *			ProgED clients.
 * NumAPIClients:	Number of ProgED clients in APIClients array.
 * Scan:		Pointer to first scanner.
 * Ref:			Pointer to an array containing the search strings
 *			for references creation.
 * NumRef:		Number of strings in Ref Array.
 * RAMReference:	TRUE=Keep reference file in RAM.
 * ReferenceCase:	TRUE=Activate case sensitivity for references.
 * ReferenceFile:	Filename of references file.
 * HuntPath:		Pointer to an array containing the search patterns
 *			for hunter.
 * NumHuntPath:		Number of patterns in HuntPath array.
 * ProjectFiles:	Pointer to an array containing the filenames
 *			of files in project.
 * NumProjectFiles:	Number of files in ProjectFiles array.
 * SeparateItems:	TRUE=Put a bar if the label of a menu is empty.
 * Menu:		Pointer to the menu tree's.
 * HelpFile:		Help file to use when user press HELP key.
 * Key:			Pointer to the list of hotkeys.
 * LeftBorder,
 * RightBorder,
 * TopBorder,
 * BottomBorder:	Scroller limits. Exceding them window will scroll.
 * BackPen:		Pen to be used in background rendering.
 * PaperPen:		Pen to be used in paper rendering.
 * DefTextPen:		Pen to be used in text rendering.
 * PaperBlockPen:	Pen to be used in block rendering.
 * CursorPen:		Pen to be used in cursor rendering (From 2.0!).
 * MarkCursorPen:	Pen to be used in cursor rendering if I'm marking (From 2.0!).
 * ScreenPens:		Screen pens to be used for SA_Pens. (12 pens+1 ~0).
 * ShowCursorPos:	TRUE=show cursor position in window title.
 * ShowPathName:	TRUE=show file path in window title.
 * AutoArrangeVer:	TRUE=arrange vertically automatically.
 * AutoArrangeHor:	TRUE=arrange horizontally automatically.
 * Favourite:		TRUE=give half screen to active window.
 * UnfoldOnGotoMarker:	TRUE=Unfold on goto marker.
 * UnfoldOnGotoLine:	TRUE=Unfold on goto line.
 * UnfoldOnGotoByte:	TRUE=Unfold on goto byte.
 * UnfoldOnGotoScan:	TRUE=Unfold on goto scan.
 * UnfoldOnSearch:	TRUE=Unfold on search & matching bracket.
 * UseRightGadget:	TRUE=Create right scroller gadget.
 * UseBottomGadget:	TRUE=Create bottom scroller gadget.
 * UseRTSysReq:		TRUE=Activate ReqTools system-requesters.
 * UseRTFileReq:	TRUE=Activate ReqTools file-requesters.
 * UseRTFontReq:	TRUE=Activate ReqTools font-requesters.
 * UseRTScreenReq:	TRUE=Activate ReqTools screenmode-requesters.
 * Clipboard:		Clipboard number used.
 * UseSetDefPubScr:	TRUE=use SetDefPubScreen to make ProgED screen
 *			the default public screen (very useful!).
 * UseClock:		TRUE=activate clock on the screen bar.
 * Save:		TRUE=Safe save.
 * BlankBorders:	TRUE=Make screen border blank.
 * UseAppIcon:		TRUE=Create an AppIcon on WB screen.
 * UseMenuItem:		TRUE=Create an AppItem on WB menu.
 * MouseBlanker:	TRUE=Activate mouse blanker.
 * FastLoad:		TRUE=Activate fast load. If ProgED haven't memory
 * MaxCol:		Max # of columns in texts. Set it at least at 300.
 *			Don't ask me why ProgED guru if you have 80 in
 *			this field!
 * AltStep:	 	Step of scroller with ALT key.
 * FastMode:		TRUE=Activate FAST mode (try it!)
 * StartUpMacro:	Filename of ARexx macro executed at startup.
 * PreIconifyMacro:	Filename of ARexx macro executed when ProgED closes
 *			its screen.
 * PostIconifyMacro:	Filename of ARexx macro executed when ProgED opens
 *			its screen.
 * LeftExtraSpace,
 * RightExtraSpace,
 * TopExtraSpace,
 * BottomExtraSpace:	Space (in pixels) leaved out when ProgED arrange
 *			its windows.
 * XpkLib[5]:		Name of XPK library used.
 * XpkMode:		XPK library mode used.
 * XpkPos:		DON'T TOUCH THIS!
 * XpkPassWord:		Password for XPK library.
 * UndoLevels:		Lenght of undo queues.
 * PublicScreenName:	Name of public screen on which you wish open ProgED
 *			screen.
 * FileTypes:		Pointer to the first filetype mounted.
 * LMouse[]:		ProgED programs executed at left mouse button
 *			pressure.
 * MMouse[]:		ProgED programs executed at middle mouse button
 *			pressure.
 * AskSetFileType:	Show requester to ask user if he/she wants
 *			change filetype at new/load operation.
 * AskChangeFileType:	Show requester to ask user if he/she wants
 *			change filetype at file-name change.
 * EOLChar:		Ascii code used to show CR chars. 0=none.
 * FavouritePerc:	Percentual of screen height used by active
 *			window (for window arranging).
 * AutoReloadPrj:	TRUE=Reload last project used.
 *
 ******/

#define MAXFONTNAM	49
#define MAXSTARTUPMACRO	99
#define MAXREFNAME	99

struct PEDColor
{
	ULONG	Red,
		Green,
		Blue;
};

struct Prefs
{
	ULONG			 ScreenMode;
	UWORD			 ScreenWidth;
	UWORD			 ScreenHeight;
	UWORD			 ScreenOverscanType;
	UBYTE			 ScreenDepth;
	UBYTE			 ScreenAutoScroll;

	struct PEDColor		 ScreenColors[MAXCOLOR];

	char			 ScreenFontName[MAXFONTNAM+1];
	UWORD			 ScreenFontSize;

	char			 MenuFontName[MAXFONTNAM+1];
	UWORD			 MenuFontSize;

	char			 TextFontName[MAXFONTNAM+1];
	UWORD			 TextFontSize;

	char			 GadgetFontName[MAXFONTNAM+1];
	UWORD			 GadgetFontSize;

	char			**APIClients;
	int			 NumAPIClients;

	struct MyScan		*Scan;

	char			**Ref;
	int			 NumRef;
	UBYTE			 RAMReference;
	UBYTE			 ReferenceCase;
	char			 ReferenceFile[MAXREFNAME+1];

	char			**HuntPath;
	int			 NumHuntPath;

	char			**ProjectFiles;
	int			 NumProjectFiles;

	UBYTE			 SeparateItems;
	struct MyMenu		*Menu;
	char			 HelpFile[MAXFILENAME+1];

	struct MyKey		*Key;

	UBYTE			 LeftBorder;
	UBYTE			 RightBorder;
	UBYTE			 TopBorder;
	UBYTE			 BottomBorder;

	UBYTE			 BackPen;
	UBYTE			 PaperPen;
	UBYTE			 DefTextPen;
	UBYTE			 PaperBlockPen;
	UBYTE			 CursorPen;
	UBYTE			 MarkCursorPen;
	UWORD			 ScreenPens[13];

	UBYTE			 ShowCursorPos;
	UBYTE			 ShowPathName;

	UBYTE			 AutoArrangeVer;
	UBYTE			 AutoArrangeHor;
	UBYTE			 Favourite;

	UBYTE			 UnfoldOnGotoMarker;
	UBYTE			 UnfoldOnGotoLine;
	UBYTE			 UnfoldOnGotoByte;
	UBYTE			 UnfoldOnGotoScan;
	UBYTE			 UnfoldOnSearch;

	UBYTE			 UseRightGadget;
	UBYTE			 UseBottomGadget;

	UBYTE			 UseRTSysReq;
	UBYTE			 UseRTFileReq;
	UBYTE			 UseRTFontReq;
	UBYTE			 UseRTScreenReq;

	UBYTE			 Clipboard;

	UBYTE			 UseSetDefPubScr;

	UBYTE			 UseClock;

	UBYTE			 Save;

	UBYTE			 BlankBorders;

	UBYTE			 UseAppIcon;

	UBYTE			 UseMenuItem;

	UBYTE			 MouseBlanker;

	UBYTE			 FastLoad;

	UWORD			 MaxCol;

	UBYTE			 AltStep;

	UBYTE			 FastMode;

	char			 StartUpMacro[MAXSTARTUPMACRO];
	char			 PreIconifyMacro[MAXSTARTUPMACRO];
	char			 PostIconifyMacro[MAXSTARTUPMACRO];

	LONG			 LeftExtraSpace,
				 RightExtraSpace,
				 TopExtraSpace,
				 BottomExtraSpace;

	char			 XpkLib[5];
	UBYTE			 XpkMode;
	int			 XpkPos;
	char			 XpkPassWord[52];

        ULONG			 UndoLevels;

	char			 PublicScreenName[MAXPUBSCREENNAME+1];

	struct FileType		*FileTypes;

	struct MyProgram	*LMouse[8],
				*MMouse[8];

	UBYTE			 AskSetFileType,
				 AskChangeFileType;

	UBYTE			 EOLChar;

	UBYTE			 FavouritePerc;

	UBYTE			 AutoReloadPrj;
};
