home *** CD-ROM | disk | FTP | other *** search
/ Best Objectech Shareware Selections / UNTITLED.iso / boss / word / text / 001 / api.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-08-19  |  18.5 KB  |  427 lines

  1. {//////////////////////////////////////////////////////////////////////////////}
  2. { This an example UNIT showing how to use the E! API interrupt routines.       }
  3. { This file may be compiled using Turbo Pascal 4.0/5.0                         }
  4. {//////////////////////////////////////////////////////////////////////////////}
  5. {$A-,B-,D-,E+,F-,I-,L-,N-,R-,S-,V-}
  6.  
  7. UNIT API;
  8.  
  9. INTERFACE
  10.  
  11. USES DOS;
  12.  
  13. TYPE
  14.  
  15.  { These are the declarations of useful Records allowing you to retrieve }
  16.  { more easily E! variables values.                                      }
  17.  
  18.  FlagRecord = RECORD
  19.                AddOnLast      : boolean; { Key down insert newline on last line flag }
  20.                AlarmFlag      : boolean; { Error beep flag                      }
  21.                AsciiMode      : boolean; { Control characters entry flag        }
  22.                AutoBackFlag   : boolean; { Backspace behaviour flag             }
  23.                AutoSaveFlag   : boolean; { Autosave flag                        }
  24.                AutoScrollFlag : boolean; { Autoscroll flag                      }
  25.                AutoTabFlag    : boolean; { Autotab flag                         }
  26.                BakFlag        : boolean; { .BAK files generation flag           }
  27.                BlanksFlag     : boolean; { Strip trailing spaces when saving flag}
  28.                CompFlag       : boolean; { Compression mode flag                }
  29.                Ega_Vga_OK     : boolean; { 43 lines mode flag                   }
  30.                Flag35         : boolean; { 35 lines mode flag - EGA_VGA_OK must be on}
  31.                LogFlag        : boolean; { Log file flag                        }
  32.                PauseMode      : boolean; { Pause on return from DOS flag        }
  33.                ShiftFlag      : boolean; { Accelerated cursor flag              }
  34.                Warning        : boolean; { Warning before saving flag           }
  35.                Enter_Classic  : boolean; { Split line using ENTER flag          }
  36.                Refresh        : boolean; { Display authorization                }
  37.                SelfInsert     : boolean; { Braces autoinsertion flag            }
  38.               END;
  39.  
  40.  AttrRecord = RECORD
  41.                Text_Attr        : byte;  { Edited text attribute   }
  42.                BlockAttr        : byte;  { Marked block attribute  }
  43.                CommandLineAttr  : byte;  { Command line attribute  }
  44.                LoStatusLineAttr : byte;  { Status line 1 attribute }
  45.                HiStatusLineAttr : byte;  { Status line 2 attribute }
  46.                MessageAttr      : byte;  { Messages attribute      }
  47.                HelpAttr         : byte;  { Help line attribute     }
  48.                CursorAttr       : byte;  { Virtual cursor attribute}
  49.               END;
  50.  
  51.  MargRecord = RECORD
  52.                 ShiftKeyCount   : word;   { Delay value for secondary help lines }
  53.                 AutoSaveLimit   : word;   { Seconds# for autosave                }
  54.                 ScrollAmountGlb : integer;{ Left / Right scroll amount           }
  55.                 DrawModel       : integer;{ Drawing style                        }
  56.                 LeftMargin      : integer;{ Left margin                          }
  57.                 ParMargin       : integer;{ New paragraph margin                 }
  58.                 RightMargin     : integer;{ Right margin                         }
  59.               END;
  60.  
  61.  MessageRecord = RECORD
  62.                   HelpLine          : array[1..4] of string[80];
  63.                     { Help line and 3 secondary help lines }
  64.                   EditErrorMessages : array[1..47] of string[43];
  65.                     { Error messages --> 38 for the english version}
  66.                  END;
  67.  
  68.  StatusRecord =  RECORD
  69.                   linenum,            { Line number of current text    }
  70.                   line    : word;     { Current row in current text    }
  71.                   col,                { Current column in current text }
  72.                   firstcol,           { First displayed column         }
  73.                   lower,              { Displayed lines number         }
  74.                   nbwin   : byte;     { Number of windows              }
  75.                  END;
  76.  
  77.  LockArray    =  array [1..25] of string[3];
  78.                  { locked extensions }
  79.  
  80.  compileline  = string[128];
  81.  
  82.  compileentry = RECORD
  83.                  fileext     : string[3];
  84.                  compcommand : compileline;
  85.                 END;
  86.  
  87.  CompileExt   = array [1..10] of compileentry;
  88.                  { block of compile commands definitions }
  89.  
  90. textline   = string;                  { Each line has 255 char. max.       }
  91. lineptr    = ^textline;               { Textflow points to a pointers ar-  }
  92. textflowar = array [0..1] of lineptr; { ray (1 to linenum - see above).    }
  93. textflow   = ^textflowar;             { Each pointer points to a text line.}
  94.  
  95. commandline = string[80];
  96.  
  97. CONST
  98.  
  99.    E_Vec : byte = $C0; { No de l'interruption utilisĂ©e par E!  }
  100.  
  101.    { This value may be changed if it conflicts with an already used  }
  102.    { interrupt vector. See E! API USER's GUIDE.                      }
  103.  
  104.    { Values to pass in AH to specify the E! API service you want to use }
  105.    FUNCTION_REQUEST   = 0;   { Call a E! function - code in BX }
  106.  
  107.    EDITBUFF_REQUEST   = 1;   { Request Editbuffer address              }
  108.    FLAGS_REQUEST      = 2;   { Request flags block address             }
  109.    ATTR_REQUEST       = 3;   { Request attribute block address         }
  110.    MARG_REQUEST       = 4;   { Request margins+misc. block address     }
  111.    MESS_REQUEST       = 5;   { Request messages block address          }
  112.    FLOW_REQUEST       = 6;   { Request pointers array address-text flow}
  113.    NAME_REQUEST       = 7;   { Request current name address            }
  114.  
  115.    STATUS_REQUEST     = 8;   { Request curr.line, line#, column etc... }
  116.  
  117.    LOCK_REQUEST       = 20;  { Request locked extensions array addr.   }
  118.    COMP_REQUEST       = 21;  { Request compile commands block addr.    }
  119.    SCR_REQUEST        = 22;  { Request screen address                  }
  120.  
  121.    DISPLINE_SERVICE   = 9;   { Display contents of edit buffer }
  122.    REFRESH_SERVICE    = 10;  { Rebuild the whole E! screeen    }
  123.    MASK_SERVICE       = 11;  { Refresh text mask               }
  124.    STORE_SERVICE      = 12;  { Store edit Buffer to text       }
  125.    CHANGE_SERVICE     = 13;  { Set change flag to true         }
  126.    SEEK_SERVICE       = 14;  { Set active line                 }
  127.    VERSION_SERVICE    = 15;  { Return version number           }
  128.    REGISTER_SERVICE   = 16;  { Execute command after exit      }
  129.    GETMEM_SERVICE     = 17;  { Request memory for API program  }
  130.    FREEMEM_SERVICE    = 18;  { Free API program owned memory   }
  131.    E_IDLE_SERVICE     = 19;  { Resident program may call E! API}
  132.    MODIF_SERVICE      = 23;  { Was the file modified ?         }
  133.  
  134.    { If AH is set to 0 please use one of the following function code }
  135.    { and pass it to E! API thru BX.                                  }
  136.  
  137.    ALIGN_TEXT         = 001; { Align text to cursor                   }
  138.    PASCAL_STYLE       = 002; { See documentation (Ctrl B)             }
  139.    CLEAR_LINE         = 003; { Clear line                             }
  140.    REPEAT_CHAR        = 004; { Repeat specified character             }
  141.    CLEAR_EOL          = 005; { Erase end of line                      }
  142.    WRAP               = 006; { Toggle Wordwrap                        }
  143.    _43LINES           = 007; { Toggle 35/43/50 lines mode             }
  144.    DELETE_LEFT        = 008; { Delete left character                  }
  145.    NEXT_TAB           = 009; { Go to next tab                         }
  146.    JUSTIFICATION      = 010; { Toggle justify mode                    }
  147.    EDIT               = 012; { Edit a file                            }
  148.    ENTER              = 013; { Insert a line or validate a command    }
  149.    INSERT_NAME        = 014; { Insert filename                        }
  150.    MACRO              = 016; { Execute active macro                   }
  151.    RESTORE_MACRO      = 017; { Restore previous macro                 }
  152.    REPEAT_SEARCH      = 019; { Repeat last search                     }
  153.    INSERT_DATE        = 020; { Insert date and time                   }
  154.    INIT_SEARCH        = 022; { Initialize search variables            }
  155.    DEL_WORD           = 023; { Delet current word                     }
  156.    LIST_DIR           = 026; { List current line as a directory       }
  157.    REMOVE_LINE        = 127; { Remove current line                    }
  158.    PREV_TAB           = 271; { Go to previous tab                     }
  159.    CONTINUE           = 272; { Insert a continue-mark in macro        }
  160.    WORD_MARK          = 273; { Mark the current Word                  }
  161.    END_OF_BLOCK       = 274; { Go to end of block                     }
  162.    REMOVE_TAB         = 275; { Remove current tab position            }
  163.    RECORD_TAB         = 276; { Create a new tab positioneur           }
  164.    BLOCK_BEGIN        = 277; { Go to block begin                      }
  165.    UNMARK             = 278; { Unmark block                           }
  166.    REMOVE_TABS        = 279; { Remove all tab positions               }
  167.    OVERLAY            = 280; { Overlay block at cursor position       }
  168.    PARAGRAPH          = 281; { Go to next paragraph                   }
  169.    ADJUST             = 286; { Adjust block position                  }
  170.    SPLIT              = 287; { Split line at cursor                   }
  171.    DELETE_BLOCK       = 288; { Delete marked block                    }
  172.    FILL_BLOCK         = 289; { Fill block with specified character    }
  173.    SORT               = 290; { Sort block                             }
  174.    BOX                = 291; { Draw a box around the block            }
  175.    JOIN               = 292; { Join current line and next line        }
  176.    BOOKMARK           = 293; { Drop bookmark                          }
  177.    LINE_MARK          = 294; { Mark lines                             }
  178.    SENTENCE_MARK      = 300; { Mark sentences                         }
  179.    GRAPHICS           = 301; { Toggle control characters access       }
  180.    COPY_BLOCK         = 302; { Copy block to cursor position          }
  181.    REMOVE_SPACES      = 303; { Remove trailing blanks                 }
  182.    BLOCK_MARK         = 304; { Mark block                             }
  183.    MOVE_BLOCK         = 306; { Move block                             }
  184.    HELP               = 315; { Load help file                         }
  185.    SAVE               = 316; { Save current file                      }
  186.    QUIT               = 317; { Quit current file                      }
  187.    QUIT_SAVE          = 318; { Quite and save current file            }
  188.    WINDOW             = 319; { Create/Remove window                   }
  189.    DRAW               = 320; { Toggle draw mode                       }
  190.    NAME               = 321; { Name current file                      }
  191.    LOAD               = 322; { Edit a new file                        }
  192.    RESTORE            = 323; { Restore (undo) current line            }
  193.    NEXT               = 324; { Go to next file                        }
  194.    LINE_BEGIN         = 327; { Go to line begin                       }
  195.    UP                 = 328; { Up                                     }
  196.    PREV_PAGE          = 329; { Scroll screen up                       }
  197.    LEFT               = 331; { Left                                   }
  198.    RIGHT              = 333; { Right                                  }
  199.    EOL                = 335; { Go to end of line                      }
  200.    DOWN               = 336; { Down                                   }
  201.    NEXT_PAGE          = 337; { Scroll screen down                     }
  202.    TOGGLE_INSERT      = 338; { Toggle insert mode                     }
  203.    DEL_CHAR           = 339; { Delete character at cursor             }
  204.    SCROLL_RIGHT       = 340; { Scroll right                           }
  205.    SCROLL_LEFT        = 341; { Scroll left                            }
  206.    SCROLL_UP          = 342; { Scroll up                              }
  207.    SCROLL_DOWN        = 343; { Scroll down                            }
  208.    CENTER_LINE        = 344; { Center line in window                  }
  209.    RAISE_LINE         = 345; { Raise line to top of window            }
  210.    CLEAR_WINDOWS      = 346; { Delete all windows                     }
  211.    UPCASE_WORD        = 350; { Upcase word                            }
  212.    LOWCASE_WORD       = 351; { Lowcase word                           }
  213.    UPCASE_BLOCK       = 352; { Upcase block                           }
  214.    LOWCASE_BLOCK      = 353; { Lowcase block                          }
  215.    CENTER_BLOCK       = 354; { Center text in block                   }
  216.    FORMAT_PAR         = 355; { Format paragraph                       }
  217.    FORMAT_BLOCK       = 356; { Format paragraphs within block         }
  218.    KEYHELP            = 360; { Key oriented help                      }
  219.    PAGE_RIGHT         = 362; { Scroll page right                      }
  220.    PAGE_LEFT          = 363; { Scroll page left                       }
  221.    CHANGE_WINDOW      = 364; { Change active window                   }
  222.    DELETE_WINDOW      = 365; { Supprime une fenĂȘtre                   }
  223.    ZOOM               = 366; { Zoom / Unzoom active window            }
  224.    NEXT_ERROR         = 367; { Go to next compilation error           }
  225.    PREV_ERROR         = 368; { Go to previous compilation error       }
  226.    PREVIOUS           = 369; { Go to previous file                    }
  227.    PREV_WORD          = 371; { Go to previous word                    }
  228.    NEXT_WORD          = 372; { Go to next word                        }
  229.    TEXT_END           = 373; { Go to end of text                      }
  230.    PAGE_BOTTOM        = 374; { Go to bottom of window                 }
  231.    TEXT_BEGIN         = 375; { Go to text begin                       }
  232.    TEXTMARK1          = 376; { Drop text mark 1                       }
  233.    TEXTMARK2          = 377; { Drop text mark 2                       }
  234.    TEXTMARK3          = 378; { Drop text mark 3                       }
  235.    UNMARK_TEXTS       = 379; { Remove text marks                      }
  236.    REFRESH            = 380; { Reload (refresh) original file         }
  237.    PAIRED_BRACE       = 381; { See documentation                      }
  238.    MATCH_BRACE        = 382; { See documentation                      }
  239.    UNDO               = 383; { Restore removed lines                  }
  240.    INSERT_DOS         = 384; { Insert captured lines (DOS SHELL)      }
  241.    SEARCH_WORD        = 385; { Search current word                    }
  242.    INSERT_BLOCK       = 386; { Insert blanks before block             }
  243.    INSERT_BLANK       = 387; { Insert blanks without moving cursor    }
  244.    PAGE_TOP           = 388; { Go to top of window                    }
  245.  
  246. CALLFAILED = $FF;
  247. { A bad function id has been passed to Call_E_Function }
  248.  
  249.  
  250. Function  Call_E_Function(funcno : word) : byte;
  251.  { Use this function to execute a E! function }
  252.  
  253. Function  Request_E_Address(request_name : byte) : pointer;
  254.  { Use this function to get the address of E! variables }
  255.  
  256. Procedure Get_E_Status(VAR status : statusrecord);
  257.  { Use this function to get cursor current position and window status }
  258.  
  259. Procedure Request_E_Service(service : byte);
  260.  { Use this function to get special services }
  261.  
  262. Procedure Get_E_Version(VAR major, minor : byte);
  263.  { Retrieve E! version }
  264.  
  265. Procedure RegisterCommand(commandstr : commandline);
  266.  { Execute a E! command after exit}
  267.  
  268. Function Seek_E_Line(line : word; curpos : byte):byte;
  269.  { Call E! seek function and return error code }
  270.  
  271. Function Get_E_Memory(paragraphs, memID : word;
  272.                       VAR blockptr : pointer;
  273.                       VAR firsttime : boolean):boolean;
  274. { Request a block of memory from E! heap to store permanent information }
  275.  
  276. Function Free_E_Memory(memID : word):boolean;
  277. { Free a previously requested memory block }
  278.  
  279. Function Is_E_Idle:boolean;
  280. { Is E! idle ? }
  281.  
  282. Function Is_File_Modified:boolean;
  283. { Was the current file modified ? }
  284.  
  285. IMPLEMENTATION
  286.  
  287. Function Call_E_Function(funcno : word):byte;
  288. { Call E! function #funcno and return error code }
  289. { Example : retcode:=Call_E_Function(Page_Top)   }
  290.  
  291. VAR  regs : registers;
  292.  
  293. BEGIN
  294.  regs.AH:=0;
  295.  regs.BX:=funcno;
  296.  Intr(E_Vec, regs);
  297.  Call_E_Function:=regs.AL;
  298. END;
  299.  
  300. Function Request_E_Address(request_name : byte):pointer;
  301. { Returns a pointer to the requested variables block }
  302.  
  303. VAR  regs : registers;
  304.  
  305. BEGIN
  306.  IF NOT request_name IN [1..7, 20..22] THEN Exit;
  307.  regs.AH:=request_name;
  308.  Intr(E_Vec, regs);
  309.  Request_E_Address:=Ptr(regs.ES, regs.BX);
  310. END;
  311.  
  312. Procedure Get_E_Status(VAR status : statusrecord);
  313. { Loads status members with appropriate values }
  314.  
  315. VAR  regs : registers;
  316.  
  317. BEGIN
  318.  regs.AH:=STATUS_REQUEST;
  319.  Intr(E_Vec, regs);
  320.  WITH status DO
  321.  BEGIN
  322.   linenum :=regs.CX;
  323.   line    :=regs.DX;
  324.   col     :=regs.AH;
  325.   firstcol:=regs.AL;
  326.   lower   :=regs.BH;
  327.   nbwin   :=regs.BL;
  328.  END;
  329. END;
  330.  
  331. Procedure Request_E_Service(service:byte);
  332.  
  333. VAR  regs : registers;
  334.  
  335. BEGIN
  336.  regs.AH:=service;
  337.  Intr(E_Vec, regs);
  338. END;
  339.  
  340. Procedure Get_E_Version(VAR major, minor : byte);
  341.  
  342. VAR  regs : registers;
  343.  
  344. BEGIN
  345.  regs.AH:=VERSION_SERVICE;
  346.  Intr(E_Vec, regs);
  347.  major:=regs.AH;
  348.  minor:=regs.AL;
  349. END;
  350.  
  351. Procedure RegisterCommand(commandstr : commandline);
  352.  
  353. VAR  regs : registers;
  354.  
  355. BEGIN
  356.  regs.AH:=REGISTER_SERVICE;
  357.  regs.ES:=Seg(commandstr);
  358.  regs.BX:=Ofs(commandstr);
  359.  Intr(E_Vec, regs);
  360. END;
  361.  
  362. Function Seek_E_Line(line : word; curpos : byte):byte;
  363. { Call E! seek function and return error code }
  364.  
  365. VAR  regs : registers;
  366.  
  367. BEGIN
  368.  regs.AH:=SEEK_SERVICE;
  369.  regs.BX:=line;
  370.  regs.AL:=curpos;
  371.  Intr(E_Vec, regs);
  372.  Seek_E_Line:=regs.AL;
  373. END;
  374.  
  375. Function Get_E_Memory(paragraphs, memID : word;
  376.                       VAR blockptr : pointer;
  377.                       VAR firsttime : boolean):boolean;
  378.  
  379. VAR  regs : registers;
  380.  
  381. BEGIN
  382.  regs.AH:=GETMEM_SERVICE;
  383.  regs.DX:=memID;
  384.  regs.CX:=paragraphs;
  385.  Intr(E_Vec, regs);
  386.  IF regs.AL = 0 THEN blockptr:=Ptr(regs.ES, regs.BX);
  387.  firsttime:=regs.AH = 1;
  388.  Get_E_Memory:=regs.AL = 0;
  389. END;
  390.  
  391. Function Free_E_Memory(memID : word):boolean;
  392.  
  393. VAR  regs : registers;
  394.  
  395. BEGIN
  396.  regs.AH:=FREEMEM_SERVICE;
  397.  regs.DX:=memID;
  398.  Intr(E_Vec, regs);
  399.  Free_E_Memory:=regs.AL = 0;
  400. END;
  401.  
  402. function getflagstatus(flagid:byte):boolean;
  403.  
  404. VAR  regs : registers;
  405.  
  406. BEGIN
  407.  regs.AH:=flagid;
  408.  Intr(E_Vec, regs);
  409.  getflagstatus:=regs.AL = 1;
  410. END;
  411.  
  412. Function Is_E_Idle:boolean;
  413.  
  414. BEGIN
  415.  Is_E_Idle:=getflagstatus(E_IDLE_SERVICE);
  416. END;
  417.  
  418. Function Is_File_Modified:boolean;
  419.  
  420. VAR  regs : registers;
  421.  
  422. BEGIN
  423.  Is_File_Modified:=getflagstatus(MODIF_SERVICE);
  424. END;
  425.  
  426. END.
  427.