    include  "RECORDS"
    include  "VTINC"
    externalstring (72)fnspec  SYSMESS (integer  i)
    !
    ! Special routines from PMM to handle file referencing and i/o
    externalintegerfnspec  READIN(string (maxname)name  file,
       integer  extra, integername  base,start,fend,limit)
    externalintegerfnspec  WRITEOUT(string (maxname)name  file,
       integer  base,start,fend,limit)
    externalroutinespec  MOVE(integer  length,from,to)
    externalroutinespec  DELETEVM(integer  base,limit)
    !

    constinteger  RET=10
    constinteger  CASEBIT=32;          !upper<->lower
    conststring (13) HELPFILE="ECCE_HELP"
    conststring (13) DICTFILE="ECCE_DICT"

    record  format  desc fm(integer  len, addr)
    external  integer  fn  spec  spawn alias  "LIB$SPAWN" (record (desc fm)name  com)
    external  routine  call out(string (255) s)
      record (desc fm) comdesc
      integer  flag
      comdesc_len=length(s)
      comdesc_addr=addr(s)+1
      if  s # "" then  flag = spawn(comdesc) else  flag = spawn(nil)
      printstring(sysmess(flag)) if  flag&1=0
    end

    external  routine  view(string (255) key)
      record (desc fm) comdesc
      integer  flag
      string (255) s
      s <- "HELP/LIBRARY=".helpfile." VECCE ".key
      comdesc_len=length(s)
      comdesc_addr=addr(s)+1
      flag = spawn(comdesc)
      return  if  flag&1#0
      printstring(" * Help not available")
    end

    external  routine  CONNECT EDFILE(record (edfile)name  f)
    !  Reference file specified by F_NAME
    !   allocate store to hold it + extra bytes specified by F_FLAG
    !   place the file in store
    !   Return store addresses in F_START1/F_LIM
    !          file addresses in F_START2/F_LIM2
    !              ( START1 <= START2 <= LIM2 <= LIM )
    !   Update F_NAME to full file name
    !
    ! Discard any previous input file
      deletevm(f_start1,f_lim) if  f_start1 # 0
    ! Read the file in
      f_flag = readin(f_name,f_flag>>9,f_start1,f_start2,f_lim2,f_lim)
      if  f_flag # 0 start
        print string(" *".sysmess(f_flag).": ".f_name)
        newline
        f_start1 = 0;  f_start2 = 0;  f_lim2 = 0
      finish
      f_lim1 = f_start1
    !  Ensure that file does not end with partial line
      f_lim2 = f_lim2-1 while  f_lim2 # f_start2 and  byteinteger(f_lim2-1)#nl
    end ;  !connect edfile

    include  "IMP_INCLUDE:CONNECT.INC";  !dictionary connection
    external  routine  CONNECT DICTIONARY(integername  base)
    integer  f,s,l
      on  event  3,4,9,15 start
        return
      finish
      connect file(DICTFILE,0,s,l)
      base = s {%if f&1 # 0
    end

    endoflist
    include  "IMP_INCLUDE:RMSDEF.INC"
    list
    external  routine  DISCONNECT EDFILE(record (edfile)name  out)
    integer  i,k
      if  out_flag < 0 or  out_change < 0 start
        deletevm(out_start1,out_lim)
        return
      finish
      i = out_lim1-out_start1;  !upper half
      out_start2=out_start2-i
      move(i,out_start1,out_start2);  ! concatenated to lower
      out_fp = out_fp + out_start2 - out_start1 if  out_start1 <= out_fp < out_lim1
        ! In case backup needs to re-enter
      out_lim1=out_start1
      cycle
        i = writeout(out_name,out_start1,out_start2,out_lim2,out_lim)
        exit  if  i = 0
        print string(" *".sysmess(i).": ".out_name)
        newline
        if  i = rms cre or  i = rms ext or  i = rms ful start
          print string(" * Insufficient disc space to write the output file *")
          newlines(2)
          print string(" Do you want a chance to delete some files?"); new line
          vt prompt("Y(es) or N(o)? ")
          read symbol(k) until  k!casebit = 'y' or  k!casebit = 'n'
          vt prompt("")
          if   k!casebit =  'y' start
            print string("You will need at least ")
            write((out_lim2-out_start2)>>9+1,0)
            print string(" free blocks to write the file."); new line
            print string("LOGOUT will return control to VECCE"); newline
            set video mode(0); ! to flush
            call out("")
         else
            print string(" Abandon complete edit? "); new line
            vt prompt("Y(es) or N(o)? ")
            read symbol(k) until  k!casebit = 'y' or  k!casebit = 'n'
            vt prompt("")
            out_change = -1 and  exit  if   k!casebit =  'y'
          finish
        else
          print string(" Please supply alternative file-name: ")
          select input(0);  prompt("")
          out_name = ""
          read symbol(k) until  k # ' '
          cycle
            out_name = out_name.tostring(k);  read symbol(k)
          repeat  until  k < ' '
          newline
        finish
      repeat
    end

    external  routine  BACKUP EDFILE(record (edfile)name  out)
       disconnect edfile(out)
    end

    !!!!!!!!!!!!!!!!!!!  Editor parameters and options  !!!!!!!!!!!!!!!!!
    external  record (opt fm) OPTIONS

    include  "IMP_INCLUDE:CLIPARSE.INC"
    externalroutine  SET PARAMETERS(string (maxname)name  in,sec,out,
                                    string (255) parm)
      integer  t, save options
      constinteger  MINWIN0=24, MAXWIN0=99
      on  event  5 start
        printstring(event_message);  newline
        stop
      finish
      !       Initialise the Editor Options to their default values
      options = 0;           ! Zero whole record
      OPTIONS_mapcase = 1
      OPTIONS_width   = 80
      OPTIONS_minwin  = minwin0
      OPTIONS_ttype   = -1
      OPTIONS_wrows   = 255
      OPTIONS_wcols   = 255
      OPTIONS_ctop    = 99
      OPTIONS_ccols   = 255
      OPTIONS_maxwin  = maxwin0
      OPTIONS_tabs(t) = 8*t for  t = 0,1,maxtab

      !NB QualifierI returns zero if the qualifier is not present.  Similarly,
      !   QualifierS returns the null string

      In       = Qualifier S("FILE")
      Out      = Qualifier S("OUTPUT")
      Sec      = Qualifier S("SECNAME")
      OPTIONS_Pre      = Qualifier S("PRE")
      OPTIONS_Logfile  = Qualifier S("LOG")
      OPTIONS_Map Case = 0 unless  Qualifier Present("MATCH")
      OPTIONS_Mark     = 0 if  Qualifier Present("HILIGHT")
      OPTIONS_Mark     = 1 if  Qualifier Present("MARK")
      OPTIONS_Early    = 0 if  Qualifier Present("LATE")
      OPTIONS_Early    = 1 if  Qualifier Present("EARLY")
      OPTIONS_Dmode    = 1 if  Qualifier Present("INSERT")
      OPTIONS_Emode    = 1 if  Qualifier Present("EMODE")
      OPTIONS_Exptabs  = 1 if  Qualifier Present("TAB_EXPAND")
      OPTIONS_Width    = Qualifier I("WIDTH")
      OPTIONS_Margin   = Qualifier I("MARGIN")
      OPTIONS_Min Win  = Qualifier I("MINWIN") if  Qualifier Present("MINWIN")
      OPTIONS_T Type   = Qualifier I("TTYPE")  if  Qualifier Present("TTYPE")
      OPTIONS_W Top    = Qualifier I("WTOP")
      OPTIONS_W Rows   = Qualifier I("WROWS")  if  Qualifier Present("WROWS")
      OPTIONS_W Left   = Qualifier I("WLEFT")
      OPTIONS_W Cols   = Qualifier I("WCOLS")  if  Qualifier Present("WCOLS")
      OPTIONS_C Top    = Qualifier I("CTOP")   if  Qualifier Present("CTOP")
      OPTIONS_C Left   = Qualifier I("CLEFT")
      OPTIONS_C Cols   = Qualifier I("CCOLS")  if  Qualifier Present("CCOLS")
      OPTIONS_Max Win  = Qualifier I("MAXWIN") if  Qualifier Present("MAXWIN")
      OPTIONS_Vmode    = Qualifier I("VMODE")
    end

    external  integer  array  spec  INITDEF(0:255)

    external  integer  map  DEF(integer  i)
      result  == initdef(i)
    end

    const  integer  MACBOUND=8191

    external  byte  map  MAC(integer  i)
      own  byte  array  M(0:MACBOUND)
      result  == m(i)
    end

    end  of  file