/******************************************************************************/
/*  This is the include file for a C program using the E! API.                */
/******************************************************************************/
/******************************************************************************/
/*  WARNING :                                                                 */
/*  All strings involved in API functions are supposed to be PASCAL strings.  */
/*  So they are NOT null terminated and the first byte of the string is ac-   */
/*  tually the string length. This is also true for strings adresses you      */
/*  pass to E! API functions                                                  */
/******************************************************************************/


#ifndef E_API

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE 1
#endif

/******************************************************************************/
/*  This global variable is initialized to the default value used by E! to    */
/*  install the API interrupt handler. This value may be changed dynamical-   */
/*  ly using a Profile. So the API program must also change the interrupt     */
/*  number.                                                                   */
/******************************************************************************/
extern int E_Vec;

/******************************************************************************/
/*    Values to pass in AH to specify the E! API service you want to use      */
/*    FUNCTION_REQUEST   = 0;      Call a E! function - code in BX            */
/******************************************************************************/

#define   EDITBUFF_REQUEST   1   /* Request Editbuffer address              */
#define   FLAGS_REQUEST      2   /* Request flags block address             */
#define   ATTR_REQUEST       3   /* Request attribute block address         */
#define   MARG_REQUEST       4   /* Request margins+misc. block address     */
#define   MESS_REQUEST       5   /* Request messages block address          */
#define   FLOW_REQUEST       6   /* Request pointers array address-text flow*/
#define   NAME_REQUEST       7   /* Request current name address            */

#define   STATUS_REQUEST     8   /* Request curr.line, line#, column etc... */

#define   LOCK_REQUEST       20  /* Request locked extensions array addr.   */
#define   COMP_REQUEST       21  /* Request compile commands block addr.    */
#define   SCR_REQUEST        22  /* Request screen address                  */

#define   DISPLINE_SERVICE   9   /* Display contents of edit buffer */
#define   REFRESH_SERVICE    10  /* Rebuild the whole E! screeen    */
#define   MASK_SERVICE       11  /* Refresh text mask               */
#define   STORE_SERVICE      12  /* Store edit Buffer to text       */
#define   CHANGE_SERVICE     13  /* Set change flag to true         */
#define   SEEK_SERVICE       14  /* Set active line                 */
#define   VERSION_SERVICE    15  /* Return version number           */
#define   REGISTER_SERVICE   16  /* Execute command after exit      */
#define   GETMEM_SERVICE     17  /* Request memory for API program  */
#define   FREEMEM_SERVICE    18  /* Free API program owned memory   */
#define   E_IDLE_SERVICE     19  /* Resident program may call E! API*/

#define   MODIF_SERVICE      23  /* Was the file modified ?         */

/******************************************************************************/
/*    If AH is set to 0 please use one of the following function code         */
/*    and pass it to E! API thru BX.                                          */
/******************************************************************************/

#define   ALIGN_TEXT           1 /* Align text to cursor                   */
#define   PASCAL_STYLE         2 /* See documentation (Ctrl B)             */
#define   CLEAR_LINE           3 /* Clear line                             */
#define   REPEAT_CHAR          4 /* Repeat specified character             */
#define   CLEAR_EOL            5 /* Erase end of line                      */
#define   WRAP                 6 /* Toggle Wordwrap                        */
#define   _43LINES             7 /* Toggle 35/43/50 lines mode             */
#define   DELETE_LEFT          8 /* Delete left character                  */
#define   NEXT_TAB             9 /* Go to next tab                         */
#define   JUSTIFICATION       10 /* Toggle justify mode                    */
#define   EDIT                12 /* Edit a file                            */
#define   ENTER               13 /* Insert a line or validate a command    */
#define   INSERT_NAME         14 /* Insert filename                        */
#define   MACRO               16 /* Execute active macro                   */
#define   RESTORE_MACRO       17 /* Restore previous macro                 */
#define   REPEAT_SEARCH       19 /* Repeat last search                     */
#define   INSERT_DATE         20 /* Insert date and time                   */
#define   INIT_SEARCH         22 /* Initialize search variables            */
#define   DEL_WORD            23 /* Delet current word                     */
#define   LIST_DIR            26 /* List current line as a directory       */
#define   REMOVE_LINE        127 /* Remove current line                    */
#define   PREV_TAB           271 /* Go to previous tab                     */
#define   CONTINUE           272 /* Insert a continue-mark in macro        */
#define   WORD_MARK          273 /* Mark the current Word                  */
#define   END_OF_BLOCK       274 /* Go to end of block                     */
#define   REMOVE_TAB         275 /* Remove current tab position            */
#define   RECORD_TAB         276 /* Create a new tab positioneur           */
#define   BLOCK_BEGIN        277 /* Go to block begin                      */
#define   UNMARK             278 /* Unmark block                           */
#define   REMOVE_TABS        279 /* Remove all tab positions               */
#define   OVERLAY            280 /* Overlay block at cursor position       */
#define   PARAGRAPH          281 /* Go to next paragraph                   */
#define   ADJUST             286 /* Adjust block position                  */
#define   SPLIT              287 /* Split line at cursor                   */
#define   DELETE_BLOCK       288 /* Delete marked block                    */
#define   FILL_BLOCK         289 /* Fill block with specified character    */
#define   SORT               290 /* Sort block                             */
#define   BOX                291 /* Draw a box around the block            */
#define   JOIN               292 /* Join current line and next line        */
#define   BOOKMARK           293 /* Drop bookmark                          */
#define   LINE_MARK          294 /* Mark lines                             */
#define   SENTENCE_MARK      300 /* Mark sentences                         */
#define   GRAPHICS           301 /* Toggle control characters access       */
#define   COPY_BLOCK         302 /* Copy block to cursor position          */
#define   REMOVE_SPACES      303 /* Remove trailing blanks                 */
#define   BLOCK_MARK         304 /* Mark block                             */
#define   MOVE_BLOCK         306 /* Move block                             */
#define   HELP               315 /* Load help file                         */
#define   SAVE               316 /* Save current file                      */
#define   QUIT               317 /* Quit current file                      */
#define   QUIT_SAVE          318 /* Quite and save current file            */
#define   WINDOW             319 /* Create/Remove window                   */
#define   DRAW               320 /* Toggle draw mode                       */
#define   NAME               321 /* Name current file                      */
#define   LOAD               322 /* Edit a new file                        */
#define   RESTORE            323 /* Restore (undo) current line            */
#define   NEXT               324 /* Go to next file                        */
#define   LINE_BEGIN         327 /* Go to line begin                       */
#define   UP                 328 /* Up                                     */
#define   PREV_PAGE          329 /* Scroll screen up                       */
#define   LEFT               331 /* Left                                   */
#define   RIGHT              333 /* Right                                  */
#define   EOL                335 /* Go to end of line                      */
#define   DOWN               336 /* Down                                   */
#define   NEXT_PAGE          337 /* Scroll screen down                     */
#define   TOGGLE_INSERT      338 /* Toggle insert mode                     */
#define   DEL_CHAR           339 /* Delete character at cursor             */
#define   SCROLL_RIGHT       340 /* Scroll right                           */
#define   SCROLL_LEFT        341 /* Scroll left                            */
#define   SCROLL_UP          342 /* Scroll up                              */
#define   SCROLL_DOWN        343 /* Scroll down                            */
#define   CENTER_LINE        344 /* Center line in window                  */
#define   RAISE_LINE         345 /* Raise line to top of window            */
#define   CLEAR_WINDOWS      346 /* Delete all windows                     */
#define   UPCASE_WORD        350 /* Upcase word                            */
#define   LOWCASE_WORD       351 /* Lowcase word                           */
#define   UPCASE_BLOCK       352 /* Upcase block                           */
#define   LOWCASE_BLOCK      353 /* Lowcase block                          */
#define   CENTER_BLOCK       354 /* Center text in block                   */
#define   FORMAT_PAR         355 /* Format paragraph                       */
#define   FORMAT_BLOCK       356 /* Format paragraphs within block         */
#define   KEYHELP            360 /* Key oriented help                      */
#define   PAGE_RIGHT         362 /* Scroll page right                      */
#define   PAGE_LEFT          363 /* Scroll page left                       */
#define   CHANGE_WINDOW      364 /* Change active window                   */
#define   DELETE_WINDOW      365 /* Supprime une fenˆtre                   */
#define   ZOOM               366 /* Zoom / Unzoom active window            */
#define   NEXT_ERROR         367 /* Go to next compilation error           */
#define   PREV_ERROR         368 /* Go to previous compilation error       */
#define   PREVIOUS           369 /* Go to previous file                    */
#define   PREV_WORD          371 /* Go to previous word                    */
#define   NEXT_WORD          372 /* Go to next word                        */
#define   TEXT_END           373 /* Go to end of text                      */
#define   PAGE_BOTTOM        374 /* Go to bottom of window                 */
#define   TEXT_BEGIN         375 /* Go to text begin                       */
#define   TEXTMARK1          376 /* Drop text mark 1                       */
#define   TEXTMARK2          377 /* Drop text mark 2                       */
#define   TEXTMARK3          378 /* Drop text mark 3                       */
#define   UNMARK_TEXTS       379 /* Remove text marks                      */
#define   REFRESH            380 /* Reload (refresh) original file         */
#define   PAIRED_BRACE       381 /* See documentation                      */
#define   MATCH_BRACE        382 /* See documentation                      */
#define   UNDO               383 /* Restore removed lines                  */
#define   INSERT_DOS         384 /* Insert captured lines (DOS SHELL)      */
#define   SEARCH_WORD        385 /* Search current word                    */
#define   INSERT_BLOCK       386 /* Insert blanks before block             */
#define   INSERT_BLANK       387 /* Insert blanks without moving cursor    */
#define   PAGE_TOP           388 /* Go to top of window                    */

#define   CALLFAILED         0xFF
/* A bad function id has been passed to Call_E_Function */

/******************************************************************************/
/*  WARNING : THESE STRUCTURES MUST BE PACKED !!!                             */
/******************************************************************************/
typedef unsigned int BOOL;

typedef struct flagrecord
        {
         BOOL   addonlast,     /* Key down insert newline on last line flag */
                alarmflag,     /* Error beep flag                      */
                asciimode,     /* Control characters entry flag        */
                autobackflag,  /* Backspace behaviour flag             */
                autosaveflag,  /* Autosave flag                        */
                autoscrollflag,/* Autoscroll flag                      */
                autotabflag,   /* Autotab flag                         */
                bakflag,       /* .BAK files generation flag           */
                blanksflag,    /* Strip trailing spaces when saving flag*/
                compflag,      /* Compression mode flag                */
                ega_vga_ok,    /* 43 lines mode flag                   */
                flag35,        /* 35 lines mode flag - EGA_VGA_OK must be on*/
                logflag,       /* Log file flag                        */
                pausemode,     /* Pause on return from DOS flag        */
                shiftflag,     /* Accelerated cursor flag              */
                warning,       /* Warning before saving flag           */
                enter_classic, /* Split line using ENTER flag          */
                refresh,       /* Display authorization                */
                selfinsert;    /* Bracket auto insertion flag          */

        } FLAGRECORD;

 typedef struct attrrecord
        {
          char text_attr,        /* Edited text attribute   */
               blockattr,        /* Marked block attribute  */
               commandlineattr,  /* Command line attribute  */
               lostatuslineattr, /* Status line 1 attribute */
               histatuslineattr, /* Status line 2 attribute */
               messageattr,      /* Messages attribute      */
               helpattr,         /* Help line attribute     */
               cursorattr;       /* Virtual cursor attribute*/
        }
        ATTRRECORD;

 typedef struct margrecord
        {
          unsigned int shiftkeycount,   /* Delay value for secondary help lines */
                       autosavelimit,   /* Seconds# for autosave                */
                       scrollamountglb, /* Left / Right scroll amount           */
                       drawmodel,       /* Drawing style                        */
                       leftmargin,      /* Left margin                          */
                       parmargin,       /* New paragraph margin                 */
                       rightmargin;     /* Right margin                         */

        }
        MARGRECORD;

typedef struct statusrecord
        {
          unsigned int linenum,    /* Line number of current text    */
                       line;       /* Current row in current text    */
                  char col,        /* Current column in current text */
                       firstcol,   /* First displayed column         */
                       lower,      /* Displayed lines number         */
                       nbwin;      /* Number of windows              */

        } STATUSRECORD;

/******************************************************************************/
/* E! strings are PASCAL strings! First byte is length of string              */
/******************************************************************************/

typedef struct messagerecord
        {
          char helpline [3][80]; /* Help line and 3 secondary help lines */
          char editerrormessages [47][38]; /* Error messages */
        }
        MESSAGERECORD;

typedef char LOCKARRAY   [25][3]; /* locked extensions */

typedef char COMPILELINE [128];

typedef struct compileentry
        {
         char fileext [3];
         COMPILELINE  compcommand;
        }
        COMPILEEXT[10];

typedef char      textline[256];  /* Each line has 255 char. max.    */
typedef textline  *lineptr;
typedef char far  *commandline;

/******************************************************************************/
/*                         E_API functions                                    */
/******************************************************************************/

char   Call_E_Function ( unsigned );
       /* Use this function to execute a E! function */

void far *Request_E_Address ( char );
       /* Use this function to get the address of E! variables */

void   Get_E_Status ( STATUSRECORD *);
       /* Use this function to get cursor current position and window status */

void   Request_E_Service ( char );
       /* Use this function to get special services */

void   Get_E_Version ( char *, char *);
       /* Retrieve E! version */

void   RegisterCommand ( commandline );
       /* Execute a E! command after exit*/

char   Seek_E_Line ( unsigned , char );
       /* Call E! seek function and return error code */

BOOL   Get_E_Memory( unsigned,
                     unsigned,
                     void **,
                     BOOL *);
       /* Request a block of memory from E! heap to store permanent information */

BOOL   Free_E_Memory ( unsigned );
       /* Free a previously requested memory block */

BOOL   Is_E_Idle ();
       /* Is E! idle ? */

BOOL   Is_File_Modified ();
       /* Was the file modified ? */

#define E_API
#endif
