#include <perms.h>
extern void Changefilesize(_imp_string255 File, int Newsize, int *Flag);
extern void Uctranslate(int Addr, int L);
extern _imp_string255 Ucstring(_imp_string255 S);
const _imp_string255 Snl = _imp_str_literal("\n");
void Move(int Length, int From, int To) {
  asm("LB LENGTH");
  asm("JAT 14,<L99>");
  asm("LDTB X'18000000'");
  asm("LDB  %B");
  asm("LDA FROM");
  asm("CYD 0");
  asm("LDA TO");
  asm("MV  %L= %DR");
L99:;
}
extern void Prompt(_imp_string255 S);
extern _imp_string255 Interrupt(void);
extern void Tojournal(int From, int Len);
typedef struct Frf {
  int Conad;
  int Filetype;
  int Datastart;
  int Datend;
  int Size;
  int Rup;
  int Eep;
  int Mode;
  int Users;
  int Arch;
  _imp_string255 Tran;
  _imp_string255 Date;
  _imp_string255 Time;
  int Count;
  int Spare1;
  int Spare2;
} Frf;
typedef struct Rf {
  int Conad;
  int Filetype;
  int Datastart;
  int Dataend;
} Rf;
extern void Finfo(_imp_string255 File, int Mode, /*C_TYPE_RECORD_FORMAT*/ Frf R,
                  int *Flag);
extern void Reroutecontingency(int Ep, int Class, long long int Mask,
                               void Close(int A, int B), int *Flag);
extern void Signal(int Ep, int Class, int Subclass, int *Flag);
extern void Cherish(_imp_string255 Name);
extern _imp_string255 Uinfs(int N);
extern void Getjournal(_imp_string255 *File, int *Flag);
extern void Sendfile(_imp_string255 File, _imp_string255 Device,
                     _imp_string255 Name, int Copies, int Forms, int *Flag);
extern void Destroy(_imp_string255 File, int *Flag);
extern void Setuse(_imp_string255 File, int Mode, int Value);
extern void Disconnect(_imp_string255 S, int *Flag);
extern void Rename(_imp_string255 Oldn, _imp_string255 Newn, int *Flag);
extern void Modpdfile(int Ep, _imp_string255 Pdfile, _imp_string255 Member,
                      _imp_string255 Infile, int *Flag);
extern int Parmap(void);
extern void Setpar(_imp_string255 S);
extern _imp_string255 Spar(int N);
extern void Newgen(_imp_string255 S, _imp_string255 T, int *Flag);
extern void Setwork(int *Addr, int *Flag);
extern void Setfname(_imp_string255 Name);
extern void Psysmes(int Root, int Flag);
extern void Connect(_imp_string255 S, int Access, int Maxbytes, int Protection,
                    /*C_TYPE_RECORD_FORMAT*/ Rf R, int *Flag);
extern void Outfile(_imp_string255 Name, int Length, int Maxbytes,
                    int Protection, int *Conad, int *Flag);
extern int *Comreg(int I);
const unsigned char Onecase[256 /*0:255*/] = {
    0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   10,  11,  12,  13,  14,
    15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,
    30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,
    45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,
    60,  61,  62,  63,  64,  65,  66,  67,  68,  69,  70,  71,  72,  73,  74,
    75,  76,  77,  78,  79,  80,  81,  82,  83,  84,  85,  86,  87,  88,  89,
    90,  91,  92,  93,  94,  95,  96,  65,  66,  67,  68,  69,  70,  71,  72,
    73,  74,  75,  76,  77,  78,  79,  80,  81,  82,  83,  84,  85,  86,  87,
    88,  89,  90,  123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
    135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
    150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
    165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
    180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
    195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
    210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
    225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
    240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
    255};
const unsigned char Twocase[256 /*0:255*/] = {
    0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   10,  11,  12,  13,  14,
    15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,
    30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,
    45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,
    60,  61,  62,  63,  64,  65,  66,  67,  68,  69,  70,  71,  72,  73,  74,
    75,  76,  77,  78,  79,  80,  81,  82,  83,  84,  85,  86,  87,  88,  89,
    90,  91,  92,  93,  94,  95,  96,  97,  98,  99,  100, 101, 102, 103, 104,
    105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
    120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
    135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
    150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
    165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
    180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
    195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
    210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
    225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
    240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
    255};
const _imp_string255 Sysdictname = _imp_str_literal("SUBSYS.EDITDICT");
const _imp_string255 Privdictname = _imp_str_literal("E#EDITDICT");
const _imp_string255 Prt[3 /*0:2*/] = {_imp_str_literal("Edit"),
                                       _imp_str_literal("Look"),
                                       _imp_str_literal("Recall")};
const int Sscharfiletype = 3;
const int Maxi = 0x02000000;
const unsigned char Sps[134 /*-2:131*/] = {[0 ... 1] = 10, [2 ... 133] = ' '};
const unsigned char Root[3 /*0:2*/] = {59, 78, 58};
int Ed(int Emode, _imp_string255 S);
void Edit(_imp_string255 S) {
  int I;
  _imp_string255 S1;
  _imp_string255 S2;
  _imp_string255 Holds;
  const _imp_string255 Termmess[2 /*1:2*/] = {_imp_str_literal("completed"),
                                              _imp_str_literal("abandoned")};
  Holds = S;
  if (!_imp_cond_resolve(S, S1, _imp_str_literal(","), S2))
    S = _imp_join(S, _imp_join(_imp_str_literal(","), S));
  I = Ed(0, S);
  if (1 <= I && I <= 2) {
    Printch(Nl);
    Printstring(_imp_join(
        _imp_str_literal("EDIT "),
        _imp_join(Holds, _imp_join(_imp_str_literal("  "), Termmess(I)))));
    Printch(Nl);
  }
  return;
}
void Look(_imp_string255 S) {
  int I;
  if (S == _imp_str_literal("")) S = _imp_str_literal("T#LIST");
  I = Ed(1, _imp_join(S, _imp_str_literal(",.NULL")));
  Printstring(
      _imp_join(_imp_str_literal("LOOK "),
                _imp_join(S, _imp_join(_imp_str_literal(" finished."), Snl))));
}
void Recall(_imp_string255 S) {
  int Flag;
  int I;
  _imp_string255 File;
  Getjournal(File, Flag);
  if (Flag != 0) goto Err;
  I = Ed(2, _imp_join(File, _imp_str_literal(",.NULL")));
Err:
  if (Flag != 0) Psysmes(58, Flag);
}
int Ed(int Emode, _imp_string255 S) {
  typedef struct Cell {
    int Ll;
    int Lp;
    int Rp;
    int Rl;
  } Cell;
  void Initialise(int *Flag);
  int Maptxt(int I);
  void Insert(void);
  int Find(void);
  int Findb(void);
  void Replace(void);
  void Delete(void);
  void Printtext(void);
  int Charson(int N);
  int Lineson(int N);
  int Charsback(int N);
  int Linesback(int N);
  int Readcstring(void);
  int Newcell(void);
  void Ermess(int No, int Lett);
  int Returncell(int I);
  void Returnlist(/*C_TYPE_RECORD_FORMAT*/ Cell One,
                  /*C_TYPE_RECORD_FORMAT*/ Cell Two);
  void Copy(int I);
  void Extendwork(void);
  int Readtext(void);
  int Readi(int *N);
  void Killpart(void);
  void Extract(int Adr);
  void Forclose(int Class, int Subclass);
  void Exit(int Why);
  void Position(int I);
  void Hsave(void);
  void Hrestore(void);
  int Nextword(void);
  int Initdict(void);
  void Sethashes(void);
  int Lookup(void);
  _imp_string255 Fileused[20 /*1:20*/];
  int Fileusedcount;
  Cell *Top;
  Cell *Bot;
  Cell *Set;
  Cell *Cur;
  Cell *Beg;
  Cell *End;
  Cell *Txt;
  Cell *New;
  Cell *Htop;
  Cell *Hbot;
  Cell *Hcur;
  Cell *Scur;
  unsigned char Slinel;
  unsigned char Slinest;
  unsigned char Sparast;
  int Topa;
  int Bota;
  int Seta;
  int Curp;
  int Begp;
  int Endp;
  int Txtp;
  int Cadold;
  int Cadnew;
  int Tmpnew;
  int Newg;
  int Asl;
  int Wsp;
  int Wse;
  int Level;
  int Comp;
  int I;
  int J;
  int K;
  int Newnewf;
  int Flag;
  int Eterminate;
  int Caseind;
  int Haltered;
  int Altered;
  int Hcurp;
  int Hset;
  int Back;
  int Changed;
  int Nlc;
  int Intstop;
  int Linecomplete;
  int Lcomp;
  unsigned char Case;
  long long int Sysdict;
  long long int Privdict;
  long long int Tempdict;
  const unsigned char Spellch[128 /*0:127*/] = {[0 ... 44] = 0,
                                                [45 ... 47] = 0,
                                                [48 ... 57] = 0,
                                                [58 ... 64] = 0,
                                                'A',
                                                'B',
                                                'C',
                                                'D',
                                                'E',
                                                'F',
                                                'G',
                                                'H',
                                                'I',
                                                'J',
                                                'K',
                                                'L',
                                                'M',
                                                'N',
                                                'O',
                                                'P',
                                                'Q',
                                                'R',
                                                'S',
                                                'T',
                                                'U',
                                                'V',
                                                'W',
                                                'X',
                                                'Y',
                                                'Z',
                                                [91 ... 96] = 0,
                                                'A',
                                                'B',
                                                'C',
                                                'D',
                                                'E',
                                                'F',
                                                'G',
                                                'H',
                                                'I',
                                                'J',
                                                'K',
                                                'L',
                                                'M',
                                                'N',
                                                'O',
                                                'P',
                                                'Q',
                                                'R',
                                                'S',
                                                'T',
                                                'U',
                                                'V',
                                                'W',
                                                'X',
                                                'Y',
                                                'Z',
                                                [123 ... 127] = 0};
  const int Maxhash = 10;
  unsigned char Word[33 /*-1:31*/];
  int Hash[11 /*0:10*/];
  _imp_string255 Ssowner;
  const _imp_string255 Tempfile = _imp_str_literal("T#EH");
  _imp_string255 Pfn;
  _imp_string255 Prstring;
  _imp_string255 Newpdf;
  _imp_string255 Newpdm;
  _imp_string255 Oldf;
  _imp_string255 Newf;
  _imp_string255 Cyf;
  static int Ed_sw;
  static void *Ed[32 /*0:31*/] = {
      &&Ed_0,  &&Ed_1,       &&Ed_2,  &&Ed_3,  &&Ed_4,  &&Ed_5,  &&Ed_6,
      &&Ed_7,  &&Ed_8,       &&Ed_9,  &&Ed_10, &&Ed_11, &&Ed_12, &&Ed_13,
      &&Ed_14, &&Ed_15,      &&Ed_16, &&Ed_17, &&Ed_18, &&Ed_19, &&Ed_20,
      &&Ed_21, &&Ed_default, &&Ed_23, &&Ed_24, &&Ed_25, &&Ed_26, &&Ed_27,
      &&Ed_28, &&Ed_29,      &&Ed_30, &&Ed_31,
  };
  Cell Lastrec[7 /*0:6*/];
  typedef struct Cform {
    unsigned char Lett;
    unsigned char Flags;
    unsigned char Level;
    unsigned char Swno;
    unsigned char Errno;
    unsigned char Loop;
    unsigned short Count;
    int Par;
  } Cform;
  Cform *Curcom;
  Cform *Lastcom;
  Rf Rr;
  Frf Ehr;
  Cform Clist[100 /*0:99*/];
  const int Backwards = 1;
  const int Numpar = 2;
  const int Textpar = 4;
  const int Filepar = 8;
  const int Error = 128;
  const int Notinlook = 128;
  const int Special = 64;
  const int Allpar = Numpar | Textpar | Filepar;
  const int Needss = 32;
  const int Stopspell = 16;
  const int Nl = 10;
  const int Command = 1;
  const int Textchar = 2;
  const int Numchar = 3;
  const int Filechar = 4;
  const int Fileend = 5;
  const int Minus = 6;
  const int Loopstart = 7;
  const int Loopend = 8;
  const int Nonnull = 9;
  const int Space = 32;
  const int Syntaxerror = 0;
  const int Invalidloop = 1;
  const int Chinlook = 2;
  const unsigned char Chartype[128 /*0:127*/] = {[0 ... 9] = 0,
                                                 10,
                                                 [11 ... 24] = 0,
                                                 10,
                                                 [26 ... 31] = 0,
                                                 32,
                                                 [33 ... 38] = 9,
                                                 2,
                                                 7,
                                                 8,
                                                 [42 ... 43] = 3,
                                                 9,
                                                 6,
                                                 [46 ... 47] = 2,
                                                 [48 ... 57] = 3,
                                                 [58 ... 59] = 9,
                                                 4,
                                                 9,
                                                 5,
                                                 2,
                                                 9,
                                                 [65 ... 73] = 1,
                                                 1,
                                                 1,
                                                 1,
                                                 [77 ... 78] = 1,
                                                 [79 ... 85] = 1,
                                                 9,
                                                 [87 ... 89] = 1,
                                                 1,
                                                 [91 ... 95] = 9,
                                                 9,
                                                 [97 ... 105] = 1,
                                                 1,
                                                 1,
                                                 9,
                                                 [109 ... 110] = 1,
                                                 [111 ... 117] = 1,
                                                 9,
                                                 [119 ... 121] = 1,
                                                 1,
                                                 [123 ... 126] = 9,
                                                 0};
  const int Comdef[26 /*65:90*/] = {
      134676511, 33554448,  66,        202051743, 50331648,  1572872,
      385876114, 301989968, 270492,    469762194, 285212720, 452984978,
      101003295, 520093696, 352321584, 168378383, 251658240, 235753631,
      268435456, 16777232,  336814271, -1,        419430544, 486539264,
      503316480, 436207616};
  if (_imp_on_event(12)) return (2);
  int Newcell(void) {
    int I;
    int J;
    int K;
    Cell *Clear;
    I = Asl;
    if (I == 0) {
      I = (Wsp + 3) & 0xFFFFFFFC;
      J = I + 4096;
      if (J > Wse) Extendwork();
      Wsp = J;
      K = 0;
      while (J > I) {
        J = J - 16;
        *Integer(J) = K;
        K = J;
      }
    }
    Asl = *Integer(I);
    Clear = Record(I);
    *Clear = 0;
    return (I);
  }
  void Returnlist(/*C_TYPE_RECORD_FORMAT*/ Cell One,
                  /*C_TYPE_RECORD_FORMAT*/ Cell Two) {
    Cell *Work;
    int I;
    Work = &One;
    while (Work != &Two) {
      I = *Work->Rl;
      if (I == 0) {
        _imp_monitor();
        break;
      }
      Work = Record(Returncell(Addr(*Work)));
    }
  }
  int Returncell(int I) {
    *Integer(I) = Asl;
    Asl = I;
    return (*Integer(I + 12));
  }
  int Readtext(void) {
    int Marker;
    int Char;
    int Skippedch;
    while (Nextsymbol() <= ' ') Skipsymbol();
    if (Nextsymbol() == '<') {
      Marker = '>';
      Char = 0;
    } else {
      Readsymbol(Marker);
      if (Marker != '.' && Marker != '/' && Marker != '?') return (0);
      Char = Nextch();
      if (Char == Marker) {
        Readch(Skippedch);
        if (Nextch() != Marker) return (0);
      }
    }
    Prompt(_imp_join(Tostring(Marker), _imp_str_literal(":")));
    Txt = Record(Newcell());
    *Txt->Ll = 0;
    *Txt->Lp = Wsp;
    do {
      Readch(Skippedch);
      do {
        if (Wsp == Wse) Extendwork();
        *Byteinteger(Wsp) = Char;
        Wsp = Wsp + 1;
        do
          Readch(Char);
        while (Marker == '>' && (Char == Nl || Char == ' '));
      } while (Char != Marker);
      Char = Nextch();
    } while (Char == Marker);
    *Txt->Rp = Wsp - 1;
    *Txt->Rl = 0;
    if (Level == 0)
      Prompt(Prstring);
    else
      Prompt(_imp_str_literal("):"));
    return (1);
  }
  int Readi(int *N) {
    int J;
    int I;
    int Sign;
    int K;
    do
      Readsymbol(I);
    while (I <= ' ');
    if (I == '-')
      Sign = -1;
    else
      Sign = +1;
    if ('-' == I || I == '+') Readsymbol(I);
    if (I == '*') {
      J = 1;
      K = Maxi;
    } else {
      J = 0;
      K = 0;
      while ('0' <= I && I <= '9') {
        K = 10 * K + I - '0';
        if (K >= Maxi) return (0);
        if (J != 0)
          Skipsymbol();
        else
          J = 1;
        I = Nextsymbol();
        while (I == ' ') {
          Skipsymbol();
          I = Nextsymbol();
        }
      }
    }
    N = K * Sign;
    return (J);
  }
  int Maptxt(int Adr) {
    _imp_string255 Owner;
    _imp_string255 Rest;
    _imp_string255 File;
    int Hole;
    int Flag;
    int I;
    int D;
    int Q;
    Adr = Imod(Adr);
    Txt = Record(Adr);
    D = *Txt->Lp;
    Q = *Byteinteger(D);
    if (Q == 0) {
      Q = *Txt->Rp - D;
      if (Q > 31) Q = 31;
      *Byteinteger(D) = Q;
      File = *String(D);
      if (File == Newf) {
        Flag = 266;
        goto Err;
      }
      if (File == Oldf)
        Hole = Cadold;
      else {
        Connect(File, 0, 0, 0, Rr, Flag);
        if (Flag != 0) goto Err;
        if (Rr.Filetype != 3) {
          Flag = 267;
          Setfname(File);
          goto Err;
        }
        Hole = Rr.Conad;
        if (!_imp_cond_resolve(File, Owner, _imp_str_literal("."), Rest))
          File = _imp_join(Ssowner, _imp_join(_imp_str_literal("."), File));
        I = 1;
        while (I <= Fileusedcount && Fileused(I) != File) I = I + 1;
        if (Fileusedcount < I && I <= 20) {
          Fileusedcount = I;
          Uctranslate(Addr(File) + 1, *Length(File));
          Fileused(I) = File;
        }
      }
      *Byteinteger(D) = 0;
      D = Hole + *Integer(Hole + 4);
      *Txt->Lp = D;
      *Txt->Rp = Hole + *Integer(Hole) - 1;
    }
    if (*Txt->Rp < D) return (0);
    return (1);
  Err:
    Psysmes(31, Flag);
    return (0);
  }
  void Separate(void) {
    New = Record(Newcell());
    *Integer(*Cur->Ll + 12) = Addr(*New->Ll);
    *New->Ll = *Cur->Ll;
    *New->Lp = *Cur->Lp;
    *New->Rp = Curp - 1;
    *Cur->Lp = Curp;
    *Cur->Ll = Addr(*New->Ll);
    *New->Rl = Addr(*Cur->Ll);
    Altered = Altered + 1;
  }
  void Hsave(void) {
    int I;
    int J;
    Cell *Work;
    Cell *Last;
    Cell *Copy;
    if (Haltered < Altered) {
      Returnlist(*Record(*Htop->Rl), *Hbot);
      I = *Top->Rl;
      Last = Htop;
      for (;;) {
        Copy = Record(I);
        if (Copy == Bot) break;
        J = Newcell();
        *Last->Rl = J;
        Work = Record(J);
        *Work->Ll = Addr(*Last);
        *Work->Lp = *Copy->Lp;
        *Work->Rp = *Copy->Rp;
        I = *Copy->Rl;
        if (Copy == Cur) {
          Hcur = Work;
          Scur = Cur;
          Hcurp = Curp;
        }
        Last = Work;
      }
      if (Cur == Bot) {
        Hcur = Hbot;
        Scur = Cur;
        Hcurp = Curp;
      }
      *Hbot->Ll = Addr(*Last);
      *Last->Rl = Addr(*Hbot);
      Haltered = Altered;
      return;
    }
    if (Scur != Cur) {
      Copy = Top;
      Work = Htop;
      for (;;) {
        if (Copy == Cur) break;
        Copy = Record(*Copy->Rl);
        Work = Record(*Work->Rl);
      }
      Hcur = Work;
      Scur = Cur;
    }
    Hcurp = Curp;
  }
  void Hrestore(void) {
    int I;
    int J;
    Cell *Work;
    Cell *Last;
    Cell *Copy;
    Seta = 0;
    Returnlist(*Record(*Top->Rl), *Bot);
    Last = Top;
    I = *Htop->Rl;
    for (;;) {
      Copy = Record(I);
      if (Copy == Hbot) break;
      J = Newcell();
      *Last->Rl = J;
      Work = Record(J);
      *Work->Ll = Addr(*Last);
      *Work->Lp = *Copy->Lp;
      *Work->Rp = *Copy->Rp;
      I = *Copy->Rl;
      if (*Work->Lp == *Work->Rp && *Work->Rp == 0) {
        Set = Work;
        Seta = J;
      }
      if (Copy == Hcur) {
        Cur = Work;
        Scur = Work;
        Curp = Hcurp;
      }
      Last = Work;
    }
    if (Hcur == Hbot) {
      Cur = Bot;
      Scur = Bot;
      Curp = Hcurp;
    }
    *Last->Rl = Bota;
    *Bot->Ll = Addr(*Last);
    Altered = Haltered;
  }
  void Insert(void) {
    int New;
    int Previous;
    int Ac;
    if (*Txt->Lp != *Txt->Rp || *Txt->Rp != 0) Changed = 1;
    Altered = Altered + 1;
    if (Curp != *Cur->Lp) Separate();
    Ac = Addr(*Cur->Ll);
    Previous = *Integer(Ac);
    New = Addr(*Txt->Ll);
    *Integer(Ac) = New;
    *Integer(Previous + 12) = New;
    *Integer(New) = Previous;
    *Integer(New + 12) = Ac;
  }
  int Find(void) {
    int Lenb;
    int Tlen;
    int First;
    int Tlp;
    int B;
    int Dr0;
    int Dr1;
    int Acc0;
    int Acc1;
    Beg = Cur;
    Begp = Curp;
    Tlp = *Txt->Lp;
    Tlen = *Txt->Rp - Tlp + 1;
    First = *Byteinteger(Tlp);
  Start:
    if (Begp == 0) return (0);
  Again:
    Lenb = *Beg->Rp - Begp + 1;
    B = (32 * Caseind) << 8 | First;
    Dr0 = 0x58000000 | Lenb;
    Dr1 = Begp;
    asm("LB B");
    asm("LD DR0");
    asm("SWNE  %L= %DR");
    asm("JCC 8,<FIRSTNOTFOUND>");
    asm("STD DR0");
    Begp = Dr1;
    if (Caseind != 0) goto Imp1;
    if (Tlen == 1) goto Found;
    if (*Beg->Rp - Begp + 1 < Tlen) goto Imp1;
    Dr0 = 0x58000000 | (Tlen - 1);
    Dr1 = Tlp + 1;
    Acc0 = Dr0;
    Acc1 = Begp + 1;
    asm("LD DR0");
    asm("LSD ACC0");
    asm("PUT X'A500'");
    asm("JCC 8,<FOUND>");
    Begp = Begp + 1;
    goto Again;
  Found:;
    End = Beg;
    Endp = Begp + Tlen;
    if (Endp > *End->Rp) {
      End = Record(*End->Rl);
      Endp = *End->Lp;
    }
    Txtp = *Txt->Rp;
    return (1);
  Firstnotfound:;
    Beg = Record(*Beg->Rl);
    Begp = *Beg->Lp;
    goto Start;
  Imp1:
    End = Beg;
    Endp = Begp;
    Txtp = *Txt->Lp;
    for (;;) {
      if (Case(*Byteinteger(Endp)) != Case(*Byteinteger(Txtp))) break;
      Endp = Endp + 1;
      if (Endp > *End->Rp) {
        End = Record(*End->Rl);
        Endp = *End->Lp;
      }
      if (Txtp == *Txt->Rp) return (1);
      Txtp = Txtp + 1;
      if (Endp == 0) {
        Beg = End;
        Begp = 0;
        return (0);
      }
    }
    Begp = Begp + 1;
    if (Begp > *Beg->Rp) {
      Beg = Record(*Beg->Rl);
      Begp = *Beg->Lp;
      goto Start;
    }
    goto Again;
  }
  int Findb(void) {
    int Last;
    End = Cur;
    Endp = Curp;
    Last = Case(*Byteinteger(*Txt->Rp));
    for (;;) {
      do
        if (Endp == *End->Lp) {
          if (*Integer(*End->Ll + 8) == 0) {
            Beg = End;
            Begp = Endp;
            return (0);
          }
          End = Record(*End->Ll);
          Endp = *End->Rp;
        } else
          Endp = Endp - 1;
      while (Case(*Byteinteger(Endp)) != Last);
      Beg = End;
      Begp = Endp;
      Txtp = *Txt->Rp;
      do {
        if (Txtp <= *Txt->Lp) {
          Endp = Endp + 1;
          if (Endp > *End->Rp) {
            End = Record(*End->Rl);
            Endp = *End->Lp;
          }
          return (1);
        }
        Begp = Begp - 1;
        if (Begp < *Beg->Lp) {
          if (*Integer(*Beg->Ll + 8) == 0) {
            Begp = *Beg->Lp;
            return (0);
          }
          Beg = Record(*Beg->Ll);
          Begp = *Beg->Rp;
        }
        Txtp = Txtp - 1;
      } while (Case(*Byteinteger(Txtp)) == Case(*Byteinteger(Begp)));
    }
  }
  void Delete(void) {
    int I;
    Changed = 1;
    Altered = Altered + 1;
    if (Addr(*Beg->Ll) == Addr(*End->Ll)) {
      if (Begp == Endp) return;
      if (Begp == *Beg->Lp)
        *Beg->Lp = Endp;
      else {
        End = Record(Newcell());
        *End->Rl = *Beg->Rl;
        *Integer(*End->Rl) = Addr(*End->Ll);
        *End->Rp = *Beg->Rp;
        *End->Lp = Endp;
        *End->Ll = Addr(*Beg->Ll);
        *Beg->Rl = Addr(*End->Ll);
        *Beg->Rp = Begp - 1;
      }
    } else {
      I = *Beg->Rl;
      while (I != Addr(*End->Ll)) I = Returncell(I);
      *Beg->Rl = I;
      *End->Ll = Addr(*Beg->Ll);
      *End->Lp = Endp;
      if (Begp == *Beg->Lp) {
        *End->Ll = *Beg->Ll;
        if (*End->Ll != 0) *Integer(*End->Ll + 12) = I;
        I = Returncell(Addr(*Beg->Ll));
      } else
        *Beg->Rp = Begp - 1;
    }
    Cur = End;
    Curp = Endp;
  }
  void Printtext(void) {
    int I;
    int J;
    J = 0;
    if (Begp == *Beg->Lp) {
      if (*Beg->Ll == Topa)
        Printstring(_imp_join(_imp_str_literal("*T*"), Snl));
      if (*Beg->Ll == Seta)
        Printstring(_imp_join(_imp_str_literal("*S*"), Snl));
    }
    for (;;) {
      if (Begp == Curp && Addr(*Beg->Ll) == Addr(*Cur->Ll)) Printch(94);
      if (Begp == Endp && Addr(*Beg->Ll) == Addr(*End->Ll)) {
        if (Begp == 0) {
          if (Addr(*Beg->Ll) == Seta)
            Printstring(_imp_join(_imp_str_literal("*S*"), Snl));
          if (Addr(*Beg->Ll) == Bota)
            Printstring(_imp_join(_imp_str_literal("*B*"), Snl));
        }
        return;
      }
      I = *Byteinteger(Begp);
      Printch(I);
      if (I == Nl) {
        Nlc = Nlc + 1;
        if ((Nlc & 3) == 0 &&
            Ucstring(Interrupt()) == _imp_str_literal("STOP")) {
          Intstop = 1;
          return;
        }
      }
      Begp = Begp + 1;
      if (Begp > *Beg->Rp) {
        Beg = Record(*Beg->Rl);
        Begp = *Beg->Lp;
      }
    }
  }
  int Charson(int N) {
    int Len;
    End = Cur;
    Endp = Curp;
    while (Endp != 0) {
      Len = *End->Rp - Endp;
      if (N <= Len) {
        Endp = Endp + N;
        return (1);
      }
      N = N - (Len + 1);
      End = Record(*End->Rl);
      Endp = *End->Lp;
      if (N == 0) return (1);
    }
    return (0);
  }
  int Lineson(int Count) {
    int Lene;
    int B;
    int Dr0;
    int Dr1;
    if (Count == Maxi) return (Charson(Count));
    End = Cur;
    Endp = Curp;
  Again:
    if (Endp == 0) return (0);
    Lene = *End->Rp - Endp + 1;
    B = 0x000A;
    Dr0 = 0x58000000 | Lene;
    Dr1 = Endp;
    asm("LB B");
    asm("LD DR0");
    asm("PUT X'A300'");
    asm("JCC 8,<NEXTSECT>");
    asm("STD DR0");
    Endp = Dr1 + 1;
    if (Endp > *End->Rp) {
      End = Record(*End->Rl);
      Endp = *End->Lp;
    }
    Count = Count - 1;
    if (Count == 0) return (1);
    goto Again;
  Nextsect:
    End = Record(*End->Rl);
    Endp = *End->Lp;
    goto Again;
  }
  int Charsback(int N) {
    int Len;
    Beg = Cur;
    Begp = Curp;
    for (;;) {
      Len = Begp - *Beg->Lp;
      if (Len - N >= 0) {
        Begp = Begp - N;
        return (1);
      }
      Begp = *Beg->Lp;
      N = N - (Len + 1);
      if (*Integer(*Beg->Ll + 8) == 0) return (0);
      Beg = Record(*Beg->Ll);
      Begp = *Beg->Rp;
    }
  }
  int Linesback(int N) {
    int I;
    if (N == Maxi) return (Charsback(N));
    Beg = Cur;
    Begp = Curp;
    I = -1;
    do {
      if (Begp == *Beg->Lp) {
        if (*Integer(*Beg->Ll + 8) == 0)
          if (I == N - 1)
            return (1);
          else
            return (0);
        Beg = Record(*Beg->Ll);
        Begp = *Beg->Rp;
      } else
        Begp = Begp - 1;
      if (*Byteinteger(Begp) == Nl) I = I + 1;
    } while (I != N);
    Begp = Begp + 1;
    if (Begp > *Beg->Rp) {
      Beg = Record(*Beg->Rl);
      Begp = *Beg->Lp;
    }
    return (1);
  }
  void Position(int N) {
    int I;
    N = N - 1;
    if (N < 0) N = 0;
    if (N > 132) N = 132;
    I = Linesback(0);
    I = 0;
    for (;;) {
      if (I == N) {
        Cur = Beg;
        Curp = Begp;
        return;
      }
      if (Begp == 0 || *Byteinteger(Begp) == Nl) {
        if (Begp != 0) {
          End = Beg;
          Endp = Begp + 1;
          if (Endp > *End->Rp) {
            End = Record(*End->Rl);
            Endp = *End->Lp;
          }
        }
        Cur = Beg;
        Curp = Begp;
        Txt = Record(Newcell());
        *Txt->Ll = 0;
        *Txt->Lp = Addr(Sps(0));
        *Txt->Rp = *Txt->Lp + N - I - 1;
        *Txt->Rl = 0;
        Insert();
        return;
      }
      Begp = Begp + 1;
      I = I + 1;
      if (Begp > *Beg->Rp) {
        Beg = Record(*Beg->Rl);
        Begp = *Beg->Lp;
      }
    }
  }
  void Killpart(void) {
    int Dummy;
    Altered = Altered + 1;
    *Integer(*Set->Ll + 12) = *Set->Rl;
    *Integer(*Set->Rl) = *Set->Ll;
    if (Addr(*Cur->Ll) == Seta) {
      Cur = Record(*Cur->Rl);
      Curp = *Cur->Lp;
    }
    Dummy = Returncell(Seta);
    Seta = 0;
  }
  void Extract(int Adr) {
    _imp_string255 Device;
    _imp_string255 File;
    _imp_string255 Owner;
    _imp_string255 Rest;
    int I;
    int Flag;
    int Count;
    int Conad;
    int L;
    int Mod;
    if (Curp == 0) return;
    Txt = Record(Adr);
    *Byteinteger(*Txt->Lp) = *Txt->Rp - *Txt->Lp;
    File = *String(*Txt->Lp);
    Uctranslate(Addr(File) + 1, *Length(File));
    if (_imp_cond_resolve(File, File, _imp_str_literal("-MOD"), NULL))
      Mod = 1;
    else
      Mod = 0;
    if (*Charno(File, 1) != '.') {
      if (!_imp_cond_resolve(File, Owner, _imp_str_literal("."), Rest))
        File = _imp_join(Ssowner, _imp_join(_imp_str_literal("."), File));
      I = 0;
      while (I < Fileusedcount) {
        I = I + 1;
        if (Fileused(I) == File) {
          Flag = 266;
          goto Err;
        }
      }
    } else {
      Device = File;
      File = Tempfile;
    }
    L = *Cur->Rp - Curp + 1;
    Count = L;
    Beg = Record(*Cur->Rl);
    while (*Beg->Lp != 0) {
      Count = Count + *Beg->Rp - *Beg->Lp + 1;
      Beg = Record(*Beg->Rl);
    }
    if (Mod != 0) {
      Connect(File, 3, 0, 0, Rr, Flag);
      if (Flag == 218)
        Mod = 0;
      else {
        if (Flag != 0) goto Err;
        if (Rr.Filetype != 3) {
          Flag = 267;
          Setfname(File);
          goto Err;
        }
        Count = Rr.Dataend + Count;
        Disconnect(File, Flag);
        Changefilesize(File, Count, Flag);
        if (Flag != 0) goto Err;
        Connect(File, 3, 0, 0, Rr, Flag);
        if (Flag != 0) goto Err;
        I = Rr.Conad + Rr.Dataend;
        *Integer(Rr.Conad) = Count;
        *Integer(Rr.Conad + 8) = (Count + 4095) & 0xFFFFF000;
      }
    }
    if (Mod == 0) {
      Outfile(File, Count + 32, 0, 0, Conad, Flag);
      if (Flag != 0) goto Err;
      *Integer(Conad) = Count + 32;
      I = Conad + 32;
      *Integer(Conad + 12) = Sscharfiletype;
    }
    Move(L, Curp, I);
    I = I + L;
    Beg = Record(*Cur->Rl);
    while (*Beg->Lp != 0) {
      Count = *Beg->Rp - *Beg->Lp + 1;
      Move(Count, *Beg->Lp, I);
      I = I + Count;
      Beg = Record(*Beg->Rl);
    }
    Disconnect(File, Flag);
    if (File == Tempfile) {
      Sendfile(File, Device, _imp_str_literal("EDITOUT"), 0, 0, Flag);
      if (Flag != 0) Psysmes(1000, Flag);
    }
    return;
  Err:
    Psysmes(31, Flag);
  }
  void Replace(void) {
    if (Begp != *Beg->Lp) {
      Cur = Beg;
      Curp = Begp;
      Separate();
    }
    Cur = End;
    Curp = Endp;
    if (Endp == *End->Lp)
      New = Record(*Cur->Ll);
    else {
      Separate();
      if (Addr(*Beg->Ll) == Addr(*End->Ll)) Beg = New;
    }
    if (Addr(*Beg->Ll) != Addr(*Bot->Ll) && Addr(*New->Ll) != Addr(*Top->Ll)) {
      Changed = 1;
      Altered = Altered + 1;
      *Cur->Ll = *Beg->Ll;
      *Integer(*Beg->Ll + 12) = *New->Rl;
      *Beg->Ll = *Set->Ll;
      *Integer(*Set->Ll + 12) = Addr(*Beg->Ll);
      *New->Rl = Seta;
      *Set->Ll = Addr(*New->Ll);
    }
  }
  void Copy(int I) {
    Txt = Record(Newcell());
    Move(16, I, Addr(*Txt->Ll));
  }
  int Layout(int Param, int Justify) {
    int Just(int First, int Last, int Desired, int Ss);
    int Linel;
    int Linest;
    int Parast;
    int I;
    int J;
    int K;
    int Ptopp;
    int Sym;
    int Line;
    int Firstpos;
    int N;
    int Scurp;
    Cell *Ptop;
    Cell *Pbot;
    Cell *Scur;
    unsigned char Cline[161 /*0:160*/];
    int Adjustline(int Initlength);
    asm("LSS PARAM");
    asm("IMDV 1000");
    asm("IMDV 100");
    asm("ST LINEST");
    asm("LSS %TOS");
    asm("ST PARAST");
    asm("LSS %TOS");
    asm("ST LINEL");
    if (Linel == 0) Linel = Slinel;
    if (Linest == 0) Linest = Slinest;
    if (Parast == 0) Parast = Sparast;
    Slinel = Linel;
    Slinest = Linest;
    Sparast = Parast;
    Txt = Record(Newcell());
    *Txt->Lp = Addr(Sps(-2));
    *Txt->Rp = *Txt->Lp + 1;
    I = Find();
    Cur = Beg;
    Curp = Begp;
    End = Cur;
    Endp = Curp;
    for (;;) {
      if (Charsback(1) == 0) break;
      if (*Byteinteger(Begp) != ' ') break;
      Delete();
    }
    Cur = End;
    Curp = Endp;
    *Txt = 0;
    Insert();
    Pbot = Txt;
    Cur = Pbot;
    Curp = *Cur->Rp;
    Txt = Record(Newcell());
    *Txt->Lp = Addr(Sps(-2));
    *Txt->Rp = *Txt->Lp + 1;
    I = Findb();
    Ptop = End;
    Ptopp = Endp;
    Cur = Ptop;
    Curp = Ptopp;
    I = Returncell(Addr(*Txt));
    Line = 0;
    for (;;) {
      Line = Line + 1;
      if (Line == 1)
        I = Parast;
      else
        I = Linest;
      J = I - 1;
      while (J >= 1) {
        Cline(J) = ' ';
        J = J - 1;
      }
      Firstpos = I;
      if (Cur == Pbot) break;
      Scur = Cur;
      Scurp = Curp;
      for (;;) {
        I = *Byteinteger(Curp);
        if (I != ' ' && I != Nl) break;
        if (Curp < *Cur->Rp)
          Curp = Curp + 1;
        else {
          Cur = Record(*Cur->Rl);
          Curp = *Cur->Lp;
          if (Cur == Pbot) goto Wayout;
        }
      }
      N = Firstpos;
      for (;;) {
        Sym = *Byteinteger(Curp);
        if (Justify == 0 || N <= Firstpos || Cline(N - 1) != ' ' ||
            ' ' != Sym) {
          Cline(N) = Sym;
          N = N + 1;
        }
        if (Curp < *Cur->Rp)
          Curp = Curp + 1;
        else {
          Cur = Record(*Cur->Rl);
          Curp = *Cur->Lp;
        }
        while (Sym == Nl && N > Firstpos + 1 && Cline(N - 2) == ' ') {
          N = N - 1;
          Cline(N - 1) = Nl;
        }
        if (Sym == Nl || N > Linel + 1 || Cur == Pbot) break;
      }
      J = Adjustline(N - 1);
      I = Firstpos;
      if (I < Linest) I = Linest;
      if (Justify != 0 && Cur != Pbot) J = Just(I, J - 1, Linel, 0);
      Beg = Scur;
      Begp = Scurp;
      End = Cur;
      Endp = Curp;
      Delete();
      if (J <= Firstpos) break;
      Txt = Record(Newcell());
      *Txt->Lp = Wsp;
      for (I = 1; I <= J; I++) {
        *Byteinteger(Wsp) = Cline(I);
        Wsp = Wsp + 1;
      }
      *Txt->Rp = Wsp - 1;
      Insert();
    }
  Wayout:;
    Scur = Record(*Pbot->Ll);
    *Scur->Rl = *Pbot->Rl;
    Cur = Record(*Pbot->Rl);
    *Cur->Ll = *Pbot->Ll;
    Curp = *Cur->Lp;
    I = Returncell(Addr(*Pbot));
    I = Charson(2);
    Cur = End;
    Curp = Endp;
    return (I);
    int Adjustline(int Last) {
      int I;
      int J;
      int K;
      int Xcurp;
      Cell *Xcur;
      if (Cur == Pbot) return (Last);
      if (Sym == Nl && Linel <= Last && Last <= Linel + 1) return (Last);
      if (Last < Linel) goto Tooshort;
      I = Last + 1;
      while (I > Firstpos) {
        if (Cline(I) == ' ') break;
        I = I - 1;
      }
      if (I == Firstpos) {
        Cline(Last + 1) = Nl;
        return (Last + 1);
      }
      J = Charsback(Last - I + 1);
      Cline(I) = Nl;
      Curp = Begp;
      Cur = Beg;
      return (I);
    Tooshort:;
      Xcur = Cur;
      Xcurp = Curp;
      J = *Byteinteger(Curp);
      while (J == ' ' || J == Nl) {
        if (Curp < *Cur->Rp)
          Curp = Curp + 1;
        else {
          Cur = Record(*Cur->Rl);
          Curp = *Cur->Lp;
          if (Cur == Pbot) goto Miss;
        }
        J = *Byteinteger(Curp);
      }
      I = Last + 1;
      for (;;) {
        J = *Byteinteger(Curp);
        if (J == ' ' || J == Nl) break;
        Cline(I) = J;
        if (I > Linel) goto Miss;
        I = I + 1;
        if (Curp < *Cur->Rp)
          Curp = Curp + 1;
        else {
          Cur = Record(*Cur->Rl);
          Curp = *Cur->Lp;
          if (Cur == Pbot) {
            Cline(Last) = ' ';
            return (I - 1);
          }
        }
      }
      Cline(Last) = ' ';
      Cline(I) = Nl;
      Sym = Nl;
      return (Adjustline(I));
    Miss:;
      Cur = Xcur;
      Curp = Xcurp;
      return (Last);
    }
    int Just(int First, int Last, int Desired, int Ss) {
      void Insertsp(int After);
      int Gaps;
      int Needed;
      int I;
      int Flip;
      int Sgaps;
      int Sym;
      Needed = Desired - Last;
      Gaps = 0;
      Sgaps = 0;
      if (Needed <= 0) return (Last + 1);
      for (I = First + 1; I <= Last; I++)
        if (Cline(I) == ' ') {
          Sym = Cline(I - 1);
          if (Sym != ' ') Gaps = Gaps + 1;
          if (Sym == '.' || Sym == ',' || Sym == ';' || Sym == '!' ||
              Sym == '?')
            Sgaps = Sgaps + 1;
        }
      if (Gaps == 0) return (Last + 1);
      if (Ss == 0 && Sgaps > 0) {
        I = First + 1;
        for (;;) {
          if (Cline(I) == ' ') {
            Sym = Cline(I - 1);
            if (Sym == '.' || Sym == ',' || Sym == ';' || Sym == '?' ||
                Sym == '!') {
              Insertsp(I);
              Sgaps = Sgaps - 1;
              Needed = Needed - 1;
              if (0 < Needed && Needed > Sgaps) {
                Insertsp(I);
                Needed = Needed - 1;
              }
              if (Needed <= 0) return (Last + 1);
            }
          }
          I = I + 1;
          if (I >= Last || Sgaps <= 0) break;
        }
      }
      Flip = 1;
      if ((Line & 1) != 0) Flip = -1;
      if (Flip > 0)
        I = First + 1;
      else
        I = Last;
      for (;;) {
        if (Cline(I) == ' ' && Cline(I - 1) != ' ') {
          Insertsp(I);
          I = I + Flip;
          Needed = Needed - 1;
          if (Needed <= 0) return (Last + 1);
        }
        I = I + Flip;
        if (First >= I || I >= Last) break;
      }
      return (Just(First, Last, Desired, 1));
      void Insertsp(int After) {
        int K;
        for (K = Last + 2; K >= After + 1; K--) Cline(K) = Cline(K - 1);
        Last = Last + 1;
      }
    }
  }
  int Initdict(void) {
    const int Maxpdict = 0x4000 - 0x20;
    int I;
    int Conad;
    Connect(Sysdictname, 0, 0, 0, Rr, I);
    if (I == 0) {
      Conad = Rr.Conad;
      if (Rr.Filetype != 4) I = 267;
      Sysdict = Conad + *Integer(Conad + 4);
      Sysdict = Sysdict | (*Integer(Conad) - *Integer(Conad + 4)) * 0x800000000;
    } else
      Sysdict = -1;
    if (I != 0) {
      Setfname(Sysdictname);
      Psysmes(Root(Emode), I);
    }
    Connect(Privdictname, 3, 0, 0, Rr, I);
    if (I == 218) {
      Outfile(Privdictname, Maxpdict, 0, 0, Conad, I);
      if (I == 0) {
        *Integer(Conad + 12) = 4;
        *Integer(Conad) = Maxpdict;
        Cherish(Privdictname);
        Rr.Conad = Conad;
        Rr.Filetype = 4;
        Rr.Datastart = 32;
        Rr.Dataend = Maxpdict;
      }
    }
    if (I != 0) return (I);
    if (Rr.Filetype != 4) {
      Setfname(Privdictname);
      return (267);
    }
    Conad = Rr.Conad;
    Privdict = Conad + *Integer(Conad + 4);
    Privdict = Privdict | (*Integer(Conad) - *Integer(Conad + 4)) * 0x800000000;
    Wsp = (Wsp + 3) & (-4);
    Tempdict = 0x0000800000000000 + Wsp;
    if (Wsp + 4096 >= Wse) Extendwork();
    for (I = 0; I <= 1023; I++) {
      *Integer(Wsp) = 0;
      Wsp = Wsp + 4;
    }
    return (0);
  }
  int Nextword(void) {
    int Ch;
    int L;
    if (Curp == 0) return (0);
    Ch = *Byteinteger(Curp) & 127;
    while (Spellch(Ch) > 0) {
      if (Charsback(1) == 0) break;
      Cur = Beg;
      Curp = Begp;
      Ch = *Byteinteger(Curp) & 127;
    }
    for (;;) {
      Ch = *Byteinteger(Curp) & 127;
      if (65 <= Spellch(Ch) && Spellch(Ch) <= 90) break;
      if (Curp < *Cur->Rp)
        Curp = Curp + 1;
      else {
        Cur = Record(*Cur->Rl);
        Curp = *Cur->Lp;
        if (Curp == 0) return (0);
      }
    }
    L = 1;
    for (;;) {
      Ch = *Byteinteger(Curp) & 127;
      if (Spellch(Ch) == 0) break;
      Word(L) = Spellch(Ch);
      L = L + 1;
      if (L > 31) break;
      if (Curp < *Cur->Rp)
        Curp = Curp + 1;
      else {
        Cur = Record(*Cur->Rl);
        Curp = *Cur->Lp;
        if (Curp == 0) break;
      }
    }
    if (L == 2) return (Nextword());
    Word(0) = L - 1;
    Word(-1) = Word(0);
    return (1);
  }
  void Sethashes(void) {
    int I;
    int J;
    const int Hconsts[57 /*0:56*/] = {
        0,    1,    997,  47,  2897, 19,   937,  2203, 311,  1019, 23,   3041,
        823,  227,  2239, 211, 3181, 197,  3889, 191,  2447, 179,  2153, 167,
        163,  3121, 2213, 149, 139,  2551, 131,  3947, 113,  2707, 107,  103,
        3109, 97,   2647, 83,  79,   3797, 71,   2333, 61,   3517, 53,   43,
        3821, 37,   31,   29,  17,   13,   11,   7,    5};
    for (I = 1; I <= Maxhash; I++) Hash(I) = 0;
    for (I = 1; I <= Maxhash; I++)
      for (J = 1; J <= Word(0); J++)
        Hash(I) = Hash(I) + Word(J) * Hconsts(J + 2 * I);
  }
  int Lookup(void) {
    int I;
    int J;
    I = Addr(Hash(1));
    asm("LD SYSDICT");
    asm("JCC 7,<NO SYS>");
    asm("LCT I");
    asm("LSS (%CTB+0)");
    asm("IMDV SYSDICT");
    asm("LB (%DR+%TOS)");
    asm("LSS (%CTB+1)");
    asm("IMDV SYSDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+2)");
    asm("IMDV SYSDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+3)");
    asm("IMDV SYSDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+4)");
    asm("IMDV SYSDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+5)");
    asm("IMDV SYSDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+6)");
    asm("IMDV SYSDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+7)");
    asm("IMDV SYSDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+8)");
    asm("IMDV SYSDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+9)");
    asm("IMDV SYSDICT");
    asm("ADB (%DR+%TOS)");
    asm("STB J");
    if (J == 10) return (1);
  Nosys:;
    asm("LD PRIVDICT");
    asm("LCT I");
    asm("LSS (%CTB+0)");
    asm("IMDV PRIVDICT");
    asm("LB (%DR+%TOS)");
    asm("LSS (%CTB+1)");
    asm("IMDV PRIVDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+2)");
    asm("IMDV PRIVDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+3)");
    asm("IMDV PRIVDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+4)");
    asm("IMDV PRIVDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+5)");
    asm("IMDV PRIVDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+6)");
    asm("IMDV PRIVDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+7)");
    asm("IMDV PRIVDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+8)");
    asm("IMDV PRIVDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+9)");
    asm("IMDV PRIVDICT");
    asm("ADB (%DR+%TOS)");
    asm("STB J");
    if (J == 10) return (2);
    asm("LD TEMPDICT");
    asm("LCT I");
    asm("LSS (%CTB+0)");
    asm("IMDV TEMPDICT");
    asm("LB (%DR+%TOS)");
    asm("LSS (%CTB+1)");
    asm("IMDV TEMPDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+2)");
    asm("IMDV TEMPDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+3)");
    asm("IMDV TEMPDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+4)");
    asm("IMDV TEMPDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+5)");
    asm("IMDV TEMPDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+6)");
    asm("IMDV TEMPDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+7)");
    asm("IMDV TEMPDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+8)");
    asm("IMDV TEMPDICT");
    asm("ADB (%DR+%TOS)");
    asm("LSS (%CTB+9)");
    asm("IMDV TEMPDICT");
    asm("ADB (%DR+%TOS)");
    asm("STB J");
    if (J == 10) return (3);
    return (0);
  }
  void Enter(void) {
    int I;
    I = Addr(Hash(1));
    asm("LD PRIVDICT");
    asm("LCT I");
    asm("LB 1");
    asm("LSS (%CTB+0)");
    asm("IMDV PRIVDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+1)");
    asm("IMDV PRIVDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+2)");
    asm("IMDV PRIVDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+3)");
    asm("IMDV PRIVDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+4)");
    asm("IMDV PRIVDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+5)");
    asm("IMDV PRIVDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+6)");
    asm("IMDV PRIVDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+7)");
    asm("IMDV PRIVDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+8)");
    asm("IMDV PRIVDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+9)");
    asm("IMDV PRIVDICT");
    asm("STB (%DR+%TOS)");
  }
  void Entertemp(void) {
    int I;
    I = Addr(Hash(1));
    asm("LD TEMPDICT");
    asm("LCT I");
    asm("LB 1");
    asm("LSS (%CTB+0)");
    asm("IMDV TEMPDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+1)");
    asm("IMDV TEMPDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+2)");
    asm("IMDV TEMPDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+3)");
    asm("IMDV TEMPDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+4)");
    asm("IMDV TEMPDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+5)");
    asm("IMDV TEMPDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+6)");
    asm("IMDV TEMPDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+7)");
    asm("IMDV TEMPDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+8)");
    asm("IMDV TEMPDICT");
    asm("STB (%DR+%TOS)");
    asm("LSS (%CTB+9)");
    asm("IMDV TEMPDICT");
    asm("STB (%DR+%TOS)");
  }
  void Extendwork(void) {
    Printstring(_imp_join(
        _imp_str_literal("\nWORKSPACE FULL\nEDIT:E     INVOKED"), Snl));
    Exit(0);
    _imp_signal(12, 1, 0, _imp_str_literal(""));
  }
  void Exit(int Why) {
    int Savetempfile(_imp_string255 * Nf, int F);
    _imp_string255 Mess;
    int L;
    int Filelength;
    int Flag;
    int I;
    Pfn = _imp_str_literal("");
    if (Why >= 0 && Sysdict != 0) Disconnect(Privdictname, Flag);
    if (Newf == _imp_str_literal(".NULL") ||
        ((Newg == 1 || Cyf == Oldf) && Changed == 0)) {
      if (Newg == 1) Disconnect(Oldf, Flag);
      if (Cyf != _imp_str_literal("")) Disconnect(Newpdf, Flag);
      Eterminate = 1;
      goto Exout;
    }
    if (Seta != 0) Killpart();
    Filelength = 0;
    Cur = Record(*Top->Rl);
    while (*Cur->Lp != 0) {
      Filelength = Filelength + *Cur->Rp - *Cur->Lp + 1;
      Cur = Record(*Cur->Rl);
    }
    L = Filelength + 32;
    if (Why > 0) goto Saveedit;
    Outfile(Newf, L, 0, 0, Cadnew, Flag);
    if (Flag == 0) goto Writeit;
    if (Newf == Tempfile || Flag == 275 || Flag == 276 || Flag == 280 ||
        Flag == 308 || Flag == 309)
      goto Abort;
    Psysmes(59, Flag);
  Saveedit:;
    Pfn = _imp_str_literal("E#EHA");
    Outfile(Pfn, L, 0, 0, Cadnew, I);
    if (I != 0) goto Exout;
    Mess = _imp_join(_imp_str_literal("EDITed text will be saved in "),
                     _imp_join(Pfn, Snl));
    if (Why != 3)
      Printstring(Mess);
    else
      Tojournal(Addr(Mess), *Length(Mess));
    Newf = Pfn;
    Newg = 0;
    Cyf = _imp_str_literal("");
  Writeit:;
    Tmpnew = Cadnew;
    *Integer(Tmpnew) = Filelength + 32;
    *Integer(Tmpnew + 4) = 32;
    *Integer(Tmpnew + 12) = 3;
    Tmpnew = Tmpnew + 32;
    Cur = Record(*Top->Rl);
    while (*Cur->Lp != 0) {
      I = *Cur->Rp - *Cur->Lp + 1;
      Move(I, *Cur->Lp, Tmpnew);
      Tmpnew = Tmpnew + I;
      Cur = Record(Returncell(Addr(*Cur)));
    }
    if (Newg == 1) {
      Disconnect(Oldf, Flag);
      if (Flag != 0)
        if (Savetempfile(Oldf, Flag) != 0)
          goto Abort;
        else {
          Setuse(Tempfile, -1, 0);
          Newgen(Tempfile, Oldf, Flag);
          if (Flag != 0) goto Abort;
        }
    } else if (Cyf != _imp_str_literal("")) {
      Modpdfile(2, Newpdf, Newpdm, _imp_str_literal(""), Flag);
      Modpdfile(1, Newpdf, Newpdm, Newf, Flag);
      if (Flag != 0)
        if (Savetempfile(Cyf, Flag) != 0) goto Abort;
      Disconnect(Newpdf, Flag);
    } else
      Disconnect(Newf, Flag);
    Eterminate = 1;
    goto Exout;
  Abort:
    Psysmes(59, Flag);
  Exout:;
    I = 1;
    while (I <= Fileusedcount) {
      Disconnect(Fileused(I), Flag);
      I = I + 1;
    }
    return;
    int Savetempfile(_imp_string255 * Nf, int Flag) {
      Psysmes(59, Flag);
      Printstring(
          _imp_join(_imp_str_literal("Unable to copy EDITed text into "), Nf));
      Pfn = _imp_str_literal("E#EHA");
      Rename(Newf, Pfn, Flag);
      if (Flag == 0)
        Printstring(
            _imp_join(_imp_str_literal("\nIt has been saved in "),
                      _imp_join(Pfn, _imp_join(_imp_str_literal("."), Snl))));
      else
        Printstring(
            _imp_join(_imp_str_literal("\nUnable to save editing"), Snl));
      return (Flag);
    }
  }
  void Checkff(int *Flag) {
    int I;
    int Dooutfile;
    int Cmode;
    int Newsize;
    _imp_string255 Tempf;
    _imp_string255 Owner;
    Cyf = _imp_str_literal("");
    Flag = 0;
    Dooutfile = 0;
    if (Newf != _imp_str_literal(".NULL"))
      if (_imp_cond_resolve(Newf, Owner, _imp_str_literal("."), Tempf) &&
          Owner != Ssowner) {
        Flag = 258;
        Setfname(Newf);
      } else {
        if (_imp_cond_resolve(Newf, Newpdf, _imp_str_literal("_"), Newpdm))
          Cmode = 0;
        else
          Cmode = 3;
        Dooutfile = -1;
        if (Cmode == 0) Connect(Newpdf, 3, 0, 0, Rr, Flag);
        if (Flag == 0) Connect(Newf, Cmode, 0, 0, Rr, Flag);
        Fileusedcount = 1;
        Fileused(1) =
            _imp_join(Ssowner, _imp_join(_imp_str_literal("."), Newf));
        if (Newf == Oldf) {
          if (Flag == 0) {
            if (Cmode == 3) {
              Newf = Tempfile;
              Newg = 1;
              Setuse(Oldf, -1, 0);
            }
          } else
            Oldf = _imp_str_literal(".NEW");
        } else if (Flag == 0) {
          Printstring(_imp_join(Newf, _imp_str_literal(" already exists")));
          if (Rr.Filetype != 3) {
            Printstring(_imp_str_literal(" but is not a character file"));
            Flag = 267;
            Setfname(Newf);
          }
          Newline();
          if (Cmode == 3) Dooutfile = 0;
        }
        if ((Cmode == 3 && Flag == 218) || (Cmode == 0 && Flag == 288)) {
          Flag = 0;
          Printstring(_imp_join(Newf, _imp_str_literal(" is a new ")));
          if (Cmode == 0)
            Printstring(_imp_join(_imp_str_literal("member"), Snl));
          else
            Printstring(_imp_join(_imp_str_literal("file"), Snl));
          Newnewf = 1;
        }
        if (Flag == 0)
          if (Cmode == 0) {
            Cyf = Newf;
            Newf = Tempfile;
          }
      }
    if (Flag == 0)
      if (Oldf != _imp_str_literal(".NEW")) {
        Connect(Oldf, 0, 0, 0, Rr, Flag);
        Tempf = Oldf;
        if (!_imp_cond_resolve(Tempf, NULL, _imp_str_literal("."), NULL))
          Tempf = _imp_join(Ssowner, _imp_join(_imp_str_literal("."), Tempf));
        Fileusedcount = Fileusedcount + 1;
        Fileused(Fileusedcount) = Tempf;
        if (Flag == 0) {
          Cadold = Rr.Conad;
          if (Rr.Filetype != 3) {
            Flag = 267;
            Setfname(Oldf);
          }
        }
      }
    if (Flag == 0 && Dooutfile != 0) {
      if (Oldf == _imp_str_literal(".NEW"))
        Newsize = 4096;
      else
        Newsize = *Integer(Cadold) + 2048;
      Outfile(Newf, -Newsize, -1, 0, I, Flag);
    }
  }
  Prstring = Ucstring(Interrupt());
  Prstring = _imp_join(Prt(Emode), _imp_str_literal(":"));
  *Comreg(24) = 0;
  Caseind = 1;
  Case = &Onecase;
  Ssowner = Uinfs(1);
  for (I = 0; I <= 6; I++) Lastrec(I).Lp = 0;
  if (Emode == 0) {
    Finfo(_imp_str_literal("E#EHA"), 1, Ehr, Flag);
    if (Flag != 218) {
      Printstring(
          _imp_str_literal("\nFormer editing is saved in file E#EHA. Rename or "
                           "destroy before\nattempting any further EDITs"));
      return (2);
    }
    Reroutecontingency(3, 65, 0xF0000000F << ('V' - 64), Forclose, Flag);
  }
  I = 128 * 0x1000;
  Sysdict = 0;
  Word(0) = 0;
  Setwork(I, Flag);
  if (Flag != 0) goto Err;
  Wsp = I + *Integer(I + 4);
  Wse = I + *Integer(I + 8);
  Comp = 0;
  Slinest = 1;
  Sparast = 6;
  Slinel = 72;
  Asl = 0;
  Initialise(Flag);
  if (Flag != 0) goto Err;
  Lastcom = &Clist(0);
  for (;;) {
    Linecomplete = Readcstring();
    if (Linecomplete < 0) {
      Prompt(Prstring);
      while (Nextsymbol() != Nl) Skipsymbol();
    }
    if (Hset == 0) Hsave();
    I = 0;
    while (I < Comp) {
      if (I != 0 && *Curcom->Swno != 0) Lastcom = Curcom;
      Curcom = &Clist(I);
      I = I + 1;
      J = *Curcom->Flags;
      if ((J & Needss) != 0 && Seta == 0) {
        Ermess(3, *Curcom->Lett);
        I = Comp - 1;
        continue;
      }
      Back = J & Backwards;
      if ((J & Stopspell) != 0) Word(0) = 0;
      if ((J & Error) == 0) goto *Ed[Ed_sw = *Curcom->Swno];
      Ermess(*Curcom->Errno, *Curcom->Lett);
      I = Comp - 1;
      continue;
    Ed_0:;
      if (Ucstring(Interrupt()) == _imp_str_literal("STOP")) goto L31;
      Curcom->Count = *Curcom->Count + 1;
      if (*Curcom->Count >= *Curcom->Par)
        *Curcom->Count = 0;
      else
        I = *Curcom->Loop;
      continue;
    Ed_1:;
      Cur = Record(*Top->Rl);
      Curp = *Cur->Lp;
      continue;
    Ed_2:;
      Cur = Bot;
      Curp = 0;
      continue;
    Ed_3:;
      Exit(0);
      Reroutecontingency(0, 0, 0, Forclose, Flag);
      return (Eterminate);
    Ed_4:;
      if (Maptxt(*Curcom->Par) == 0) break;
      Copy(*Curcom->Par);
      Insert();
      continue;
    Ed_5:;
      if (Maptxt(*Curcom->Par) == 0) break;
      if (Back == 0)
        K = Find();
      else
        K = Findb();
      Cur = Beg;
      Curp = Begp;
      if (K == 0)
        goto L31;
      else
        continue;
    Ed_6:;
      if (Back == 0 && *Curcom->Par > 0) {
        K = Lineson(*Curcom->Par);
        Cur = End;
        Curp = Endp;
      } else {
        K = Linesback(*Curcom->Par);
        Cur = Beg;
        Curp = Begp;
      }
      if (K == 0)
        goto L31;
      else
        continue;
    Ed_7:;
      if (Maptxt(*Curcom->Par) == 0) break;
      if (Back == 0)
        K = Find();
      else
        K = Findb();
      if (K == 0) {
        Cur = Beg;
        Curp = Begp;
        goto L31;
      }
      Cur = End;
      Curp = Endp;
      continue;
    Ed_8:;
      if (Back == 0) {
        K = Charson(*Curcom->Par);
        Cur = End;
        Curp = Endp;
      } else {
        K = Charsback(*Curcom->Par);
        Cur = Beg;
        Curp = Begp;
      }
      if (K == 0)
        goto L31;
      else
        continue;
    Ed_9:;
      if (Maptxt(*Curcom->Par) == 0) break;
      if (Back == 0) {
        if (Find() == 0) {
          End = Beg;
          Endp = Begp;
        } else {
          Beg = Cur;
          Begp = Curp;
          Cur = End;
          Curp = Endp;
          K = Lineson(1);
          Cur = Beg;
          Curp = Begp;
        }
        J = Linesback(0);
      } else {
        K = Findb();
        End = Cur;
        Endp = Curp;
        Cur = Beg;
        Curp = Begp;
        K = Linesback(0);
        Cur = End;
        Curp = Endp;
        K = Lineson(1);
      }
      Printtext();
      if (Intstop == 1) break;
      continue;
    Ed_10:;
      if (I == Comp && *Lastcom->Lett == 'P') continue;
      if (Back == 0 && *Curcom->Par > 0) {
        J = Linesback(0);
        K = Lineson(*Curcom->Par);
      } else {
        K = Linesback(*Curcom->Par);
        J = Lineson(1);
      }
      Printtext();
      if (J == 0 || K == 0) goto L31;
      if (Intstop == 1) break;
      continue;
    Ed_11:;
      if (Maptxt(*Curcom->Par) == 0) break;
      if (Back == 0) {
        if (Find() == 0) {
          Cur = Beg;
          Curp = Begp;
          goto L31;
        }
        Beg = Cur;
        Begp = Curp;
      } else {
        if (Findb() == 0) {
          Cur = Beg;
          Curp = Begp;
          goto L31;
        }
        End = Cur;
        Endp = Curp;
      }
      Delete();
      continue;
    Ed_12:;
      J = Linesback(0);
      if (*Curcom->Par == 0) {
        Cur = Beg;
        Curp = Begp;
        continue;
      }
      if (Back == 0)
        K = Lineson(*Curcom->Par);
      else {
        End = Beg;
        Endp = Begp;
        K = Linesback(*Curcom->Par);
      }
      if (K == 0) goto L31;
      Delete();
      continue;
    Ed_13:;
      if (Maptxt(*Curcom->Par) == 0) break;
      if (Back == 0)
        K = Find();
      else
        K = Findb();
      if (K == 0) {
        Cur = Beg;
        Curp = Begp;
        goto L31;
      }
      Delete();
      continue;
    Ed_14:;
      if (Back == 0) {
        Beg = Cur;
        Begp = Curp;
        K = Charson(*Curcom->Par);
      } else {
        K = Charsback(*Curcom->Par);
        End = Cur;
        Endp = Curp;
      }
      if (K == 0) goto L31;
      Delete();
      continue;
    Ed_15:;
      if (Emode == 0 && Changed != 0) {
        Prompt(_imp_str_literal("QUIT:"));
        Readsymbol(J);
        Prompt(Prstring);
      } else
        J = 'Q';
      if ('Q' == Onecase(J) || Onecase(J) == 'Y') {
        if (Newnewf == 1)
          Destroy(Newf, J);
        else if (Newg == 1)
          Disconnect(Oldf, J);
        else
          Disconnect(Newf, J);
        if (Cyf != _imp_str_literal("")) Disconnect(Newpdf, J);
        if (Sysdict != 0) Disconnect(Privdictname, J);
        J = 1;
        while (J <= Fileusedcount) {
          Disconnect(Fileused(J), Flag);
          J = J + 1;
        }
        return (2);
      }
      continue;
    Ed_16:;
      if (Seta != 0) Killpart();
      Seta = Newcell();
      Txt = Record(Seta);
      Insert();
      Set = Txt;
      continue;
    Ed_17:;
      Cur = Set;
      Killpart();
      continue;
    Ed_18:;
      Hrestore();
      continue;
    Ed_19:;
      if (Maptxt(*Curcom->Par) == 0) break;
      if (Back == 0) {
        if (Find() == 0) {
          Cur = Beg;
          Curp = Begp;
          goto L31;
        }
        Beg = Cur;
        Begp = Curp;
      } else {
        if (Findb() == 0) {
          Cur = Beg;
          Curp = Begp;
          goto L31;
        }
        End = Cur;
        Endp = Curp;
      }
      Replace();
      continue;
    Ed_20:;
      J = Linesback(0);
      if (*Curcom->Par == 0) {
        Cur = Beg;
        Curp = Begp;
        continue;
      }
      if (Back == 0)
        K = Lineson(*Curcom->Par);
      else {
        End = Beg;
        Endp = Begp;
        K = Linesback(*Curcom->Par);
      }
      if (K == 0) goto L31;
      Replace();
      continue;
    Ed_21:;
      Cur = Record(Seta);
      Curp = 0;
      continue;
    Ed_23:;
      Position(*Curcom->Par);
      continue;
    Ed_24:
      Extract(*Curcom->Par);
      continue;
    Ed_25:;
      if (Newf != _imp_str_literal(".NULL")) {
        J = Seta;
        if (Seta != 0) Killpart();
        K = Curp - *Cur->Rp - 1;
        while (Cur != Top) {
          K = K + *Cur->Rp - *Cur->Lp + 1;
          Cur = Record(*Cur->Ll);
        }
        Exit(-1);
        if (Newf == Tempfile)
          if (Cyf == _imp_str_literal(""))
            Newf = Oldf;
          else if (Pfn == _imp_str_literal(""))
            Newf = Cyf;
          else
            return (2);
        Printstring(_imp_join(_imp_str_literal("All changes incorporated in "),
                              _imp_join(Newf, Snl)));
        if (J != 0)
          Printstring(_imp_str_literal("NB Separator *S* has been killed\n"));
        S = _imp_join(Newf, _imp_join(_imp_str_literal(","), Newf));
        Returnlist(*Htop, *Hbot);
        J = Returncell(Addr(*Hbot));
        Initialise(Flag);
        if (Flag != 0) goto Err;
        J = Charson(K);
        Cur = End;
        Curp = Endp;
      }
      continue;
    Ed_26:;
      if (Caseind == 0) {
        Caseind = 1;
        Case = &Onecase;
      } else {
        Caseind = 0;
        Case = &Twocase;
      }
      continue;
    Ed_27:;
      if (Layout(*Curcom->Par, 0) == 0) goto L31;
      continue;
    Ed_28:;
      if (Layout(*Curcom->Par, 1) == 0) goto L31;
      continue;
    Ed_29:;
      if (Sysdict == 0) {
        J = Initdict();
        if (J != 0) {
          Ermess(4, 0);
          goto L31;
        }
      }
      do {
        J = Nextword();
        if (J <= 0) goto L31;
        Sethashes();
        J = Lookup();
      } while (J == 0);
      J = Charsback(Word(-1));
      Cur = Beg;
      Curp = Begp;
      continue;
    Ed_30:;
      if (Word(0) == 0) {
        Ermess(5, 0);
        goto L31;
      }
      Enter();
      J = Charson(Word(0));
      Curp = Endp;
      Cur = End;
      continue;
    Ed_31:;
      if (Word(0) == 0) {
        Ermess(5, 0);
        goto L31;
      }
      Entertemp();
      J = Charson(Word(0));
      Curp = Endp;
      Cur = End;
      continue;
    L31:;
      I = Comp - 1;
    }
  }
Err:
  *Comreg(24) = Flag;
  Psysmes(Root(Emode), Flag);
  return (0);
  int Readcstring(void) {
    void Goodcommand(int Sym, int Flag, int Param);
    void Badcommand(int Sym, int Errno);
    static int Sub_sw;
    static void *Sub[10 /*1:10*/] = {
        &&Sub_1, &&Sub_2, &&Sub_3, &&Sub_4, &&Sub_5,
        &&Sub_6, &&Sub_7, &&Sub_8, &&Sub_9, &&Sub_default,
    };
    static int Stype_sw;
    static void *Stype[10 /*1:10*/] = {
        &&Stype_1, &&Stype_2, &&Stype_3, &&Stype_4, &&Stype_5,
        &&Stype_6, &&Stype_7, &&Stype_8, &&Stype_9, &&Stype_10,
    };
    int I;
    int J;
    int K;
    int Sym;
    int Err;
    int Def;
    int Cflags;
    int Parval;
    int Lrptr;
    unsigned char Loopback[41 /*0:40*/];
    Cform *Currcomp;
    if (_imp_on_event(9)) {
      Printstring(_imp_str_literal("Input Ended "));
      Exit(1);
      _imp_signal(12, 2, 0, _imp_str_literal(""));
    }
    Lcomp = Comp;
    Comp = 0;
    Level = 0;
    Hset = 0;
    Nlc = 0;
    Intstop = 0;
    Linecomplete = 0;
    goto Normal;
  Reenter:;
    Level = Level + 1;
    Prompt(_imp_str_literal("):"));
    Loopback(Level) = Comp;
  Normal:;
    do {
      for (;;) {
        Sym = Onecase(Nextsymbol());
        J = Chartype(Sym);
        if (J != 0 && J != Space) break;
        Skipsymbol();
      }
      Err = Syntaxerror;
      goto *Stype[Stype_sw = (J)-1];
    Stype_3:;
      if (Comp == 0 && Lcomp > 1 && Readi(I) > 0 && Nextsymbol() == Nl) {
        Currcomp = &Clist(Lcomp - 2);
        if (*Currcomp->Lett == ']')
          Comp = Lcomp - 1;
        else {
          Currcomp = &Clist(Lcomp - 1);
          Comp = Lcomp;
        }
        *Currcomp = 0;
        *Currcomp->Lett = ']';
        *Currcomp->Par = I;
        continue;
      }
    Stype_2:;
    Stype_4:;
    Stype_5:;
    Stype_6:;
    Stype_9:;
    Sub_7:;
    Sub_8:;
    Sub_6:;
    Sub_9:;
    Sub_5:;
    Sub_1:;
      Skipsymbol();
    Bad:
      Badcommand(Sym, Err);
      Goodcommand('P', Numpar, 1);
      Linecomplete = -1;
      continue;
    Stype_10:;
      Skipsymbol();
      if (Level > 0 || Comp == 0) continue;
      Goodcommand('P', Numpar, 1);
      Linecomplete = 1;
      continue;
    Stype_8:;
      Skipsymbol();
      if (Level == 0) goto Bad;
      if (Loopback(Level) >= Comp) goto Bad;
      if (Readi(I) > 0) {
        Goodcommand(Sym, 0, I);
        *Currcomp->Loop = Loopback(Level);
        Level = Level - 1;
        goto Backup;
      }
      Err = Invalidloop;
      goto Bad;
    Stype_7:;
      Skipsymbol();
      goto Reenter;
    Backup:;
      if (Level == 0) Prompt(Prstring);
      if (I < 0) return (I);
      continue;
    Stype_1:;
      Skipsymbol();
      Def = Comdef(Sym);
      Lrptr = Def >> 12 & 15;
      Cflags = Def & (Stopspell | Needss);
      Parval = 0;
      if (Emode != 0 && (Def & Notinlook) != 0) {
        Err = Chinlook;
        goto Bad;
      }
      if ((Def & Allpar) == 0) goto Noparam;
      for (;;) {
        K = Nextsymbol();
        if (K == Nl && Level == 0) goto Bad;
        if (K > ' ') break;
        Skipsymbol();
      }
      J = Chartype(K);
      if (J == Minus) {
        if ((Def & Backwards) == 0) goto Bad;
        Cflags = Cflags | Backwards;
        do {
          Skipsymbol();
          K = Nextsymbol();
        } while (K <= ' ');
        J = Chartype(K);
      }
      goto *Sub[Sub_sw = (J)-1];
    Sub_3:;
      if ((Def & Numpar) == 0) goto Bad;
      if (Readi(Parval) == 0) goto Bad;
      if ((Sym == 'L' || Sym == 'J') && Parval != 0) {
        asm("LSS PARVAL");
        asm("IMDV 1000");
        asm("IMDV 100");
        asm("ST I");
        asm("LSS %TOS");
        asm("ST J");
        asm("LSS %TOS");
        asm("ST K");
        if (I == 0) I = Slinest;
        if (J == 0) J = Sparast;
        if (K == 0) K = Slinel;
        if (0 >= I || I >= K || 0 >= J || J >= K || K > 132 || J > 50) goto Bad;
      }
      Cflags = Cflags | Numpar;
      goto Noparam;
    Sub_2:;
      if ((Def & Textpar) == 0) goto Bad;
      if (K != '\'') {
        if (Readtext() == 0) goto Bad;
        Lastrec(Lrptr) = *Txt;
      } else {
        Skipsymbol();
        if (Lastrec(Lrptr).Lp == 0) goto Bad;
        Copy(Addr(Lastrec(Lrptr)));
      }
      Parval = Addr(*Txt);
      Cflags = Cflags | Textpar;
      goto Noparam;
    Sub_4:;
      if ((Def & Filepar) == 0) goto Bad;
      if (Readtext() == 0) goto Bad;
      Cflags = Cflags | Filepar;
      Parval = Addr(*Txt);
    Noparam:;
      if ((Def & Special) != 0) {
        if (Sym == 'H') Hset = 1;
        if (Sym == 'C') {
          if (Parval > Comp) Parval = Comp;
          for (Comp = Comp - 1; Comp >= Comp - Parval; Comp--)
            if ((Clist(Comp).Flags & Textpar) != 0)
              J = Returncell(Clist(Comp).Par);
          if (Comp == 0)
            Level = 0;
          else
            Level = Clist(Comp - 1).Level;
          if (Level == 0)
            Prompt(Prstring);
          else
            Prompt(_imp_str_literal("):"));
          continue;
        }
      }
      Goodcommand(Sym, Cflags, Parval);
    } while (Linecomplete == 0);
    return (Linecomplete);
    void Goodcommand(int Sym, int Flags, int Param) {
      int Lab;
      int I;
      if (Comp > 99) {
        Printstring(_imp_join(_imp_str_literal("TOO MANY COMMANDS"), Snl));
        Exit(0);
        _imp_signal(12, 3, 0, _imp_str_literal(""));
      }
      if (Comp == 0 && Lcomp > 0) {
        I = 0;
        do {
          Curcom = &Clist(I);
          if ((*Curcom->Flags & (Textpar | Filepar)) != 0)
            J = Returncell(*Curcom->Par);
          I = I + 1;
        } while (I != Lcomp);
        Lcomp = 0;
      }
      if ('A' <= Sym && Sym <= 'Z')
        Lab = Comdef(Sym) >> 16;
      else
        Lab = 0;
      if ((Flags & (Textpar | Filepar)) == 0) Lab = Lab >> 8;
      Currcomp = &Clist(Comp);
      Comp = Comp + 1;
      *Currcomp = 0;
      *Currcomp->Lett = Sym;
      *Currcomp->Flags = Flags;
      if ((Flags & Error) == 0)
        *Currcomp->Par = Param;
      else
        *Currcomp->Errno = Param;
      *Currcomp->Level = Level;
      Currcomp->Swno = Lab;
    }
    void Badcommand(int Sym, int Errno) { Goodcommand(Sym, Error, Errno); }
    goto Sub_skip;
  Sub_default:
    fprintf(stderr, "Switch label 'Sub(%d):' not set in %s", Sub_sw + 1,
            __PRETTY_FUNCTION__);
    exit(1) /* or %signal ... */;
  Sub_skip:;
  }
  void Ermess(int No, int Lett) {
    _imp_string255 A;
    _imp_string255 B;
    _imp_string255 C;
    const _imp_string255 Etext[6 /*0:5*/] = {
        _imp_str_literal("Syntax error in command string"),
        _imp_str_literal("Invalid loop repetition count"),
        _imp_str_literal("## not allowed when '&&'ing"),
        _imp_str_literal("Separator S not set for ##"),
        _imp_str_literal("Cannot create private lexicon"),
        _imp_str_literal("No word set up for Y command")};
    A = Etext(No);
    if (_imp_cond_resolve(A, B, _imp_str_literal("##"), C))
      A = _imp_join(B, _imp_join(Tostring(Lett), C));
    if (_imp_cond_resolve(A, B, _imp_str_literal("&&"), C))
      A = _imp_join(B, _imp_join(Prt(Emode), C));
    Printstring(_imp_join(A, Snl));
  }
  void Forclose(int Class, int Subclass) {
    int Flag;
    const unsigned char Ecode[4 /*6:9*/] = {2, 1, 2, 3};
    Reroutecontingency(0, 0, 0, Forclose, Flag);
    Exit(Ecode(Subclass & 15));
    Signal(3, Class, Subclass, Flag);
  }
  void Initialise(int *Flag) {
    Prompt(Prstring);
    Newnewf = 0;
    Newg = 0;
    Eterminate = 0;
    Fileusedcount = 0;
    Setpar(S);
    if (Parmap() != 3) {
      Flag = 263;
      return;
    }
    Oldf = Spar(1);
    Newf = Spar(2);
    Checkff(Flag);
    if (Flag != 0) return;
    Bot = Record(Newcell());
    Top = Record(Newcell());
    Htop = Record(Newcell());
    Hbot = Record(Newcell());
    *Htop->Rl = Addr(*Hbot);
    *Hbot->Ll = Addr(*Htop);
    Bota = Addr(*Bot->Ll);
    *Top->Rl = Bota;
    Topa = Addr(*Top->Ll);
    *Bot->Ll = Topa;
    Cur = Bot;
    Curp = 0;
    Altered = 0;
    Changed = 0;
    Seta = 0;
    if (Oldf != _imp_str_literal(".NEW"))
      if (*Integer(Cadold) > *Integer(Cadold + 4)) {
        Txt = Record(Newcell());
        *Txt->Lp = Cadold + *Integer(Cadold + 4);
        *Txt->Rp = Cadold + *Integer(Cadold) - 1;
        Insert();
        if (Emode != 2) {
          Cur = Record(*Top->Rl);
          Curp = *Cur->Lp;
        }
      }
    Changed = 0;
    Altered = 0;
    Haltered = -1;
    Hsave();
  }
  goto Ed_skip;
Ed_default:
  fprintf(stderr, "Switch label 'Ed(%d):' not set in %s", Ed_sw,
          __PRETTY_FUNCTION__);
  exit(1) /* or %signal ... */;
Ed_skip:;
}
