{ --- Data types --- }

type prompt_string = string[80];
     line_string = string[80];
     filename_string = string[14];
     file_of_text = text;

{ --- Constants --- }

const CR:  char = #$0D;
      LF:  char = #$0A;
      TAB: char = #$09;
      ESC: char = #$1B;

const cursor0: string[3] = #$1B#$41#$20;            { No cursor }
      cursor1: string[3] = #$1B#$41#$21;            { Underscore cursor }
      cursor2: string[3] = #$1B#$41#$22;            { Block cursor }

const TMAX = 2000;          { max. no. of text chars }
      SMAX = 200;           { Scratch buffer length }
      SCREENTOP = 2;        { top line of screen window }
      SCREENBOTTOM = 24;    { bottom line of screen window }
      PAGELEN = 23;         { max. screen page lines }
      PAGECOL = 80;         { max. screen page colums }
      TABPOS = 8;           { Tabulator position }

label loop;

{ --- Variables --- }

var textfile:          file_of_text;          { disk files }
    blockfile:         file_of_text;
    textname:          filename_string;       { name of text file to edit }
    blockname:         filename_string;       { block file to read/write }

var digits:            set of char;           { numeric chars }
    letters:           set of char;           { alpha chars }
    alphanums:         set of char;           { alphanumeric chars }
    separators:        set of char;           { separator chars }

var text:        array[1..TMAX] of char;      { text string }
    scratch:     array[1..SMAX] of char;      { scratch buffer }
    exp_length:  array[0..127] of integer;    { expanded char length }

var ch:                char;                  { input character }
    text_length:       integer;               { no. of chars in text }
    scratch_length:    integer;               { no. of chars in scratch buffer }
    n_lines:           integer;               { no. of lines }
    page_top_line:     integer;               { top line of page }
    page_bottom_line:  integer;               { bottom line of page }
    index:             integer;               { text index }
    old_index:         integer;               { previous index }
    page_top_index:    integer;               { index of page_top_line }
    page_bottom_index: integer;               { index of page_bottom_line }
    i,j,k:             integer;               { auxiliary indices }
    cx,cy:             integer;               { cursor coordinates }
    block_begin:       integer;               { start and }
    block_end:         integer;               { end index of block }
    finis:             boolean;               { end of input flag }
    yes_flag:          boolean;               { answer = Y(es)? }
    file_flag:         boolean;               { file exists? }
    insert_flag:       boolean;               { text insertion on/off }
    block_flag:        boolean;               { display/hide block? }
    replace_flag:      boolean;               { replace pattern string? }
    crflag, lfflag:    boolean;               { cr/lf flags }
    pattern:           line_string;           { search string }
    replacement:       line_string;           { ..for search string }
    options:           line_string;           { ..for search }
