      SUBROUTINE MAIN
      COMMON /TCS/ ANSTRY(100), FDHIS, FDREV, FDSCR, FLAG, INSERT, MYANC
     *S, MAXVER, SEEKPT(2)
      INTEGER ANSTRY, FDHIS, FDREV, FDSCR, FLAG, INSERT, MYANCS, MAXVER,
     * SEEKPT
      INTEGER GETARG, GETLIN
      LOGICAL*1 HISTRY(40)
      LOGICAL*1 RVISN(40)
      LOGICAL*1 NWHSTY(40)
      LOGICAL*1 REASON(512)
      LOGICAL*1 WANTED(40)
      INTEGER PROMPT
      INTEGER I
      CALL QUERY(44Husage:  delta revision history [newhistory].)
      IF (.NOT.(GETARG(1, RVISN, 40) .EQ. -1 .OR. GETARG(2, HISTRY, 40) 
     *.EQ. -1))GOTO 23000
      CALL ERROR(46H? usage:  delta revision history [newhistory].)
23000 CONTINUE
      IF (.NOT.(GETARG(3, NWHSTY, 40) .EQ. -1))GOTO 23002
      CALL SCOPY(HISTRY, 1, NWHSTY, 1)
23002 CONTINUE
      WANTED(1) = 0
      CALL MAKDEL(HISTRY, RVISN, NWHSTY, WANTED)
      END
      SUBROUTINE MAKDEL(HISFIL, REVFIL, NEWFIL, WANTED)
      COMMON /TCS/ ANSTRY(100), FDHIS, FDREV, FDSCR, FLAG, INSERT, MYANC
     *S, MAXVER, SEEKPT(2)
      INTEGER ANSTRY, FDHIS, FDREV, FDSCR, FLAG, INSERT, MYANCS, MAXVER,
     * SEEKPT
      INTEGER GETTAB
      INTEGER ISTAB1, ISTAB2
      LOGICAL*1 HISFIL(40)
      LOGICAL*1 REVFIL(40)
      LOGICAL*1 NEWFIL(40)
      LOGICAL*1 SCRFIL(40)
      LOGICAL*1 WANTED(40)
      LOGICAL*1 HISBUF(512)
      LOGICAL*1 REVBUF(512)
      INTEGER BMATCH, CREATE, REMOVE, INDEXC
      INTEGER EQUAL, GETLIN, IABS, HASH, LINGET, OPEN, PROMPT
      INTEGER C, CAND, COUNT, JUNK
      LOGICAL*1 DATE( 10), TIME( 9)
      INTEGER FROM, TO
      INTEGER HIGH, NOW( 7)
      INTEGER IREC1, IREC2
      INTEGER I, J, K
      INTEGER KMID, KS, KS1
      INTEGER LEN1, LEN2, LOW, MIDPT
      INTEGER KEY
      INTEGER NIL
      INTEGER P, R, S
      INTEGER MMM, NNN
      LOGICAL*1 SCT(4)
      DATA SCT(1)/83/,SCT(2)/67/,SCT(3)/84/,SCT(4)/0/
      FDREV = OPEN(REVFIL, 1)
      IF (.NOT.(FDREV .EQ. -3))GOTO 23004
      CALL CANT(REVFIL)
23004 CONTINUE
      FDSCR = OPEN( HISFIL, 1)
      IF (.NOT.( FDSCR .EQ. -3 ))GOTO 23006
      CALL ERROR(30H? Can't find TCS history file.)
23006 CONTINUE
      CALL CLOSE(FDSCR)
      CALL SCRATF(SCT, SCRFIL)
      FDSCR = CREATE(SCRFIL, 2)
      IF (.NOT.(FDSCR .EQ. -3))GOTO 23008
      CALL CANT(SCRFIL)
23008 CONTINUE
      CALL PUTLIN(8HHistory?, 3)
      CALL PUTCH(10, 3)
23010 CONTINUE
      I = PROMPT(2H> , HISBUF, 1)
      IF (.NOT.(I .EQ. -1))GOTO 23013
      GOTO 23012
23013 CONTINUE
      IF (.NOT.((I .EQ. 2) .AND. (HISBUF(1) .EQ. 46)))GOTO 23015
      GOTO 23012
23015 CONTINUE
      CALL PUTLIN(4H%%c , FDSCR)
      CALL PUTLIN(HISBUF, FDSCR)
23011 GOTO 23010
23012 CONTINUE
      CALL SETGET(HISFIL, WANTED)
      CALL INCVNO(WANTED)
      CALL PUTLIN(17HNew Version is # , 3)
      CALL PUTLIN(WANTED, 3)
      CALL PUTCH(10, 3)
      MAXVER = MAXVER + 1
      CALL VIRINT
      J = 1
23017 IF (.NOT.(J.LT.  32513-J))GOTO 23019
      IF (.NOT.(GETLIN(REVBUF, FDREV) .EQ. -1))GOTO 23020
      GOTO 23019
23020 CONTINUE
      ISTAB1=J
      ISTAB2= J
      CALL SETTAB(ISTAB1, ISTAB2)
      KEY = HASH(REVBUF)
      ISTAB1= 32513-J
      ISTAB2= KEY
      CALL SETTAB(ISTAB1, ISTAB2)
23018 J = J+1
      GOTO 23017
23019 CONTINUE
      CALL CLOSE(FDREV)
      NNN = J - 1
      IF (.NOT.(NNN .EQ. 0))GOTO 23022
      CALL ERROR(23HRevision file is empty.)
23022 CONTINUE
      CALL DOSORT(NNN)
      J = 1
23024 IF (.NOT.(J .LT. NNN))GOTO 23026
      IF (.NOT.(GETTAB( 32513-J) .NE. GETTAB( 32513-J-1)))GOTO 23027
      ISTAB1=J
      ISTAB2= -GETTAB(J)
      CALL SETTAB(ISTAB1, ISTAB2)
23027 CONTINUE
23025 J = J + 1
      GOTO 23024
23026 CONTINUE
      ISTAB1=NNN
      ISTAB2= -GETTAB(NNN)
      CALL SETTAB(ISTAB1, ISTAB2)
      I = NNN+3
23029 IF (.NOT.(I .LT.  32513-NNN))GOTO 23031
      IF (.NOT.(LINGET(HISBUF, 0) .EQ. -1))GOTO 23032
      GOTO 23031
23032 CONTINUE
      KEY = HASH(HISBUF)
      J = 0
      LOW = 0
      HIGH = NNN+1
23034 IF (.NOT.(LOW+1 .LT. HIGH))GOTO 23035
      MIDPT = (LOW+HIGH) / 2
      KMID =  32513-MIDPT
      IF (.NOT.(GETTAB(KMID) .LT. KEY))GOTO 23036
      LOW = MIDPT
      GOTO 23037
23036 CONTINUE
      HIGH = MIDPT
      IF (.NOT.(GETTAB(KMID) .EQ. KEY))GOTO 23038
      J = MIDPT
23038 CONTINUE
23037 CONTINUE
      GOTO 23034
23035 CONTINUE
      ISTAB1=I
      ISTAB2= J
      CALL SETTAB(ISTAB1, ISTAB2)
23030 I = I + 1
      GOTO 23029
23031 CONTINUE
      TOTSIZ = I-1
      MMM = TOTSIZ - NNN - 2
      IF (.NOT.(MMM .EQ. 0))GOTO 23040
      CALL ERROR(22HHistory file is empty.)
23040 CONTINUE
      CAND = TOTSIZ+1
      NIL = TOTSIZ+1
      K = NNN+1
      ISTAB1=CAND+ 1
      ISTAB2= NNN+2
      CALL SETTAB(ISTAB1, ISTAB2)
      ISTAB1=CAND+ 2
      ISTAB2= 0
      CALL SETTAB(ISTAB1, ISTAB2)
      ISTAB1=CAND+ 0
      ISTAB2= NIL
      CALL SETTAB(ISTAB1, ISTAB2)
      ISTAB1=K
      ISTAB2= CAND
      CALL SETTAB(ISTAB1, ISTAB2)
      CAND = CAND+ 3
      ISTAB1=CAND+ 1
      ISTAB2= TOTSIZ+1
      CALL SETTAB(ISTAB1, ISTAB2)
      ISTAB1=CAND+ 2
      ISTAB2= NNN+1
      CALL SETTAB(ISTAB1, ISTAB2)
      ISTAB1=CAND+ 0
      ISTAB2= NIL
      CALL SETTAB(ISTAB1, ISTAB2)
      ISTAB1=K+1
      ISTAB2= CAND
      CALL SETTAB(ISTAB1, ISTAB2)
      CAND = CAND+ 3
      I = NNN+3
23042 IF (.NOT.(I .LE. TOTSIZ))GOTO 23044
      P = GETTAB(I)
      IF (.NOT.(P .NE. 0))GOTO 23045
      R = NNN+1
      C = GETTAB(R)
23047 CONTINUE
      J = IABS(GETTAB(P))
      LOW = R
      HIGH = K
23050 IF (.NOT.(LOW .LE. HIGH))GOTO 23051
      S = (LOW+HIGH) / 2
      KS = GETTAB(S)
      IF (.NOT.(GETTAB(KS+ 2) .GE. J))GOTO 23052
      HIGH = S - 1
      GOTO 23053
23052 CONTINUE
      KS1 = GETTAB(S+1)
      IF (.NOT.(GETTAB(KS1+ 2) .GE. J))GOTO 23054
      GOTO 23051
23054 CONTINUE
      LOW = S+1
23053 CONTINUE
      GOTO 23050
23051 CONTINUE
      IF (.NOT.(LOW .LE. HIGH))GOTO 23056
      IF (.NOT.(GETTAB(KS1+ 2) .GT. J))GOTO 23058
      ISTAB1=R
      ISTAB2= C
      CALL SETTAB(ISTAB1, ISTAB2)
      R = S + 1
      IF (.NOT.(CAND .GT.  32513-3 ))GOTO 23060
      CALL ERROR(28HFiles are too big to handle.)
23060 CONTINUE
      ISTAB1=CAND+ 1
      ISTAB2= I
      CALL SETTAB(ISTAB1, ISTAB2)
      ISTAB1=CAND+ 2
      ISTAB2= J
      CALL SETTAB(ISTAB1, ISTAB2)
      ISTAB1=CAND+ 0
      ISTAB2= KS
      CALL SETTAB(ISTAB1, ISTAB2)
      C = CAND
      CAND = CAND+ 3
23058 CONTINUE
      IF (.NOT.(S .EQ. K))GOTO 23062
      ISTAB1=K+2
      ISTAB2= GETTAB(K+1)
      CALL SETTAB(ISTAB1, ISTAB2)
      K = K + 1
      GOTO 23049
23062 CONTINUE
23056 CONTINUE
      IF (.NOT.(GETTAB(P) .LT. 0))GOTO 23064
      GOTO 23049
23064 CONTINUE
      P = P + 1
23065 CONTINUE
23048 GOTO 23047
23049 CONTINUE
      ISTAB1=R
      ISTAB2= C
      CALL SETTAB(ISTAB1, ISTAB2)
23045 CONTINUE
23043 I = I + 1
      GOTO 23042
23044 CONTINUE
      C = GETTAB(K)
      I = NNN+3
23066 IF (.NOT.(I .LE. TOTSIZ))GOTO 23068
      ISTAB1=I
      ISTAB2= 0
      CALL SETTAB(ISTAB1, ISTAB2)
23067 I = I + 1
      GOTO 23066
23068 CONTINUE
      ISTAB1=TOTSIZ+1
      ISTAB2= NNN+1
      CALL SETTAB(ISTAB1, ISTAB2)
23069 IF (.NOT.(C .NE. NIL))GOTO 23070
      I = GETTAB(C+ 1)
      J = GETTAB(C+ 2)
      ISTAB1=I
      ISTAB2= J
      CALL SETTAB(ISTAB1, ISTAB2)
      C = GETTAB(C+ 0)
      GOTO 23069
23070 CONTINUE
      CALL RSTGET()
      FDREV = OPEN(REVFIL, 1)
      IF (.NOT.(FDREV .EQ. -3))GOTO 23071
      CALL CANT(REVFIL)
23071 CONTINUE
      IREC1 = 0
      IREC2 = 0
      COUNT = 0
      I = NNN+2
      FLAG =  3
23073 CONTINUE
      IREC1 = IREC1 + 1
      IF (.NOT.(IREC1 .LE. MMM))GOTO 23076
      LEN1 = LINGET(HISBUF, 1)
23076 CONTINUE
      I = I + 1
      J = GETTAB(I)
      IF (.NOT.(J .EQ. 0))GOTO 23078
      IF (.NOT.(FLAG .NE.  1))GOTO 23080
      IF (.NOT.(FLAG .EQ.  2))GOTO 23082
      CALL PUTTAG(4H%%E )
23082 CONTINUE
      CALL PUTTAG(4H%%D )
      FLAG =  1
23080 CONTINUE
      CALL PUTLIN(HISBUF, FDSCR)
      GOTO 23079
23078 CONTINUE
23084 CONTINUE
      IREC2 = IREC2 + 1
      IF (.NOT.(IREC2 .LE. NNN))GOTO 23087
      LEN2 = GETLIN(REVBUF, FDREV)
23087 CONTINUE
      IF (.NOT.(IREC2 .GE. J))GOTO 23089
      GOTO 23086
23089 CONTINUE
      IF (.NOT.(FLAG .NE.  2))GOTO 23091
      IF (.NOT.(FLAG .EQ.  1))GOTO 23093
      CALL PUTTAG(4H%%E )
23093 CONTINUE
      CALL PUTTAG(4H%%I )
      FLAG =  2
23091 CONTINUE
      CALL PUTLIN(REVBUF, FDSCR)
23085 GOTO 23084
23086 CONTINUE
      IF (.NOT.(IREC2 .GT. NNN))GOTO 23095
      GOTO 23075
23095 CONTINUE
      IF (.NOT.(EQUAL(HISBUF, REVBUF) .EQ. 1))GOTO 23097
      IF (.NOT.(FLAG .NE.  3))GOTO 23099
      CALL PUTTAG(4H%%E )
      FLAG =  3
23099 CONTINUE
      COUNT = COUNT + 1
      CALL PUTLIN(HISBUF, FDSCR)
      GOTO 23098
23097 CONTINUE
      IF (.NOT.(FLAG .NE.  1))GOTO 23101
      IF (.NOT.(FLAG .EQ.  2))GOTO 23103
      CALL PUTTAG(4H%%E )
23103 CONTINUE
      CALL PUTTAG(4H%%D )
23101 CONTINUE
      CALL PUTLIN(HISBUF, FDSCR)
      CALL PUTTAG(4H%%E )
      CALL PUTTAG(4H%%I )
      CALL PUTLIN(REVBUF, FDSCR)
      FLAG =  2
23098 CONTINUE
23079 CONTINUE
23074 GOTO 23073
23075 CONTINUE
      IF (.NOT.(FLAG .NE.  3))GOTO 23105
      CALL PUTTAG(4H%%E )
23105 CONTINUE
23107 IF (.NOT.(LINGET(HISBUF, 1) .NE. -1))GOTO 23108
      CALL PUTLIN(HISBUF, FDSCR)
      GOTO 23107
23108 CONTINUE
      CALL CLOSE(FDHIS)
      CALL CLOSE(FDREV)
      CALL CLOSE(FDSCR)
      CALL PUTNUM(NNN - COUNT, 1, 3)
      CALL REMARK(12H insertions.)
      CALL PUTNUM(MMM - COUNT, 1, 3)
      CALL REMARK(11H deletions.)
      CALL PUTNUM(COUNT, 1, 3)
      CALL REMARK(11H unchanged.)
      FDHIS = CREATE(NEWFIL, 2)
      IF (.NOT.(FDHIS .EQ. -3))GOTO 23109
      CALL CANT(NEWFIL)
23109 CONTINUE
      FDSCR = OPEN(SCRFIL, 1)
      IF (.NOT.(FDSCR .EQ. -3))GOTO 23111
      CALL PUTLIN(17HTemp file error: , 3)
      CALL CANT(SCRFIL)
23111 CONTINUE
      CALL PUTLIN(4H%%s , FDHIS)
      CALL PUTNUM(NNN - COUNT, 1, FDHIS)
      CALL PUTCH(47, FDHIS)
      CALL PUTNUM(MMM - COUNT, 1, FDHIS)
      CALL PUTCH(47, FDHIS)
      CALL PUTNUM(COUNT, 1, FDHIS)
      CALL PUTCH(10, FDHIS)
      CALL PUTLIN(4H%%d , FDHIS)
      CALL PUTLIN(2HD , FDHIS)
      CALL PUTLIN(WANTED, FDHIS)
      CALL PUTCH(32, FDHIS)
      CALL GETNOW(NOW)
      CALL FMTDAT( DATE, TIME, NOW, 1)
      CALL PUTLIN( DATE, FDHIS)
      CALL PUTCH(32, FDHIS)
      CALL PUTLIN( TIME, FDHIS)
      CALL PUTCH(32, FDHIS)
      CALL MAILID(REVBUF)
      I = INDEXC(REVBUF, 32)
      IF (.NOT.(I .GT. 0))GOTO 23113
      REVBUF(I) = 0
23113 CONTINUE
      CALL PUTLIN(REVBUF, FDHIS)
      CALL PUTCH(32, FDHIS)
      CALL PUTNUM(MAXVER, 1, FDHIS)
      CALL PUTCH(32, FDHIS)
      CALL PUTNUM(MYANCS, 1, FDHIS)
      CALL PUTCH(10, FDHIS)
23115 IF (.NOT.(GETLIN(HISBUF, FDSCR) .NE. -1))GOTO 23116
      CALL PUTLIN(HISBUF, FDHIS)
      GOTO 23115
23116 CONTINUE
      CALL CLOSE(FDSCR)
      CALL CLOSE(FDHIS)
      JUNK = REMOVE(SCRFIL)
      CALL VIRFIN
      RETURN
      END
      SUBROUTINE PARSE(INBUF, FROM, OUTARA, DELIM)
      LOGICAL*1 INBUF(512)
      INTEGER FROM
      INTEGER OUTARA(16)
      LOGICAL*1 DELIM
      INTEGER PTR
      PTR = FROM
23117 IF (.NOT.(INBUF(PTR) .EQ. DELIM))GOTO 23118
      PTR = PTR+1
      GOTO 23117
23118 CONTINUE
      I=1
23119 IF (.NOT.(INBUF(PTR) .NE. 10))GOTO 23121
      OUTARA(I) = PTR
23122 IF (.NOT.((INBUF(PTR) .NE. DELIM) .AND. (INBUF(PTR) .NE. 10)))GOTO
     * 23123
      PTR = PTR+1
      GOTO 23122
23123 CONTINUE
23124 IF (.NOT.((INBUF(PTR) .EQ. DELIM) .AND. (INBUF(PTR) .NE. 10)))GOTO
     * 23125
      INBUF(PTR) = 0
      PTR = PTR+1
      GOTO 23124
23125 CONTINUE
23120 I=I+1
      GOTO 23119
23121 CONTINUE
      INBUF(PTR) = 0
      OUTARA(I) = 0
      RETURN
      END
      INTEGER FUNCTION BMATCH(LIN, FROM, PAT)
      LOGICAL*1 LIN (512), PAT(512)
      INTEGER FROM, I, J
      I = FROM
      J=1
23126 IF (.NOT.(PAT(J) .NE. 0))GOTO 23128
      IF (.NOT.(LIN(I).NE.PAT(J)))GOTO 23129
      BMATCH = 0
      RETURN
23129 CONTINUE
      I = I + 1
23127 J = J + 1
      GOTO 23126
23128 CONTINUE
      BMATCH = I
      RETURN
      END
      INTEGER FUNCTION BMCH2(LIN, FROM, PAT)
      LOGICAL*1 LIN (512), PAT(512)
      INTEGER FROM
      INTEGER EQUAL
      LOGICAL*1 TEMP(512)
      CALL SCOPY(LIN, FROM, TEMP, 1)
      BMCH2=(EQUAL(TEMP, PAT))
      RETURN
      END
      INTEGER FUNCTION CTOI2(BUF, FIXED)
      LOGICAL*1 BUF
      INTEGER FIXED
      INTEGER CTOI
      INTEGER PTR
      PTR = FIXED
      CTOI2=(CTOI(BUF, PTR))
      RETURN
      END
      SUBROUTINE SETGET (FILNAM, WANTED)
      LOGICAL*1 FILNAM(40)
      LOGICAL*1 WANTED(40)
      COMMON /TCS/ ANSTRY(100), FDHIS, FDREV, FDSCR, FLAG, INSERT, MYANC
     *S, MAXVER, SEEKPT(2)
      INTEGER ANSTRY, FDHIS, FDREV, FDSCR, FLAG, INSERT, MYANCS, MAXVER,
     * SEEKPT
      INTEGER BMATCH, BMCH2, CLOSE, CTOI2, GETLIN, OPEN, NOTE
      INTEGER JUNK
      LOGICAL*1 INBUF(512)
      INTEGER ARRAY(16)
      INTEGER I
      INTEGER THREAD, IPREV, ITHIS
      FDHIS = OPEN(FILNAM, 1)
      IF (.NOT.(FDHIS .EQ. -3))GOTO 23131
      CALL ERROR(31HCannot locate TCS history file.)
23131 CONTINUE
      I=1
23133 IF (.NOT.(I.LE.100))GOTO 23135
      ANSTRY(I) = 0
23134 I=I+1
      GOTO 23133
23135 CONTINUE
      THREAD = -1
23136 CONTINUE
      I = GETLIN(INBUF, FDHIS)
      IF (.NOT.(I .EQ. -1))GOTO 23139
      CALL ERROR(36HUnexpected EOF on history-info scan.)
23139 CONTINUE
      CALL PUTLIN(INBUF, FDSCR)
      IF (.NOT.(BMATCH(INBUF, 1, 3H%%T) .NE. 0))GOTO 23141
      CALL ERROR(37HNonexistant revision level requested.)
23141 CONTINUE
      IF (.NOT.(BMATCH(INBUF, 1, 4H%%d ) .NE. 0))GOTO 23143
      CALL PARSE(INBUF, 5, ARRAY, 32)
      ITHIS = CTOI2(INBUF, ARRAY(6))
      IPREV = CTOI2(INBUF, ARRAY(7))
      IF (.NOT.(THREAD .LT. 0))GOTO 23145
      MAXVER = ITHIS
      THREAD = 0
23145 CONTINUE
      IF (.NOT.(THREAD .EQ. 0))GOTO 23147
      IF (.NOT.((WANTED(1) .EQ. 0) .OR. (BMCH2(INBUF, ARRAY(2), WANTED) 
     *.EQ. 1)))GOTO 23149
      IF (.NOT.(WANTED(1) .EQ. 0))GOTO 23151
      CALL SCOPY(INBUF, ARRAY(2), WANTED, 1)
      CALL PUTLIN(10HVersion # , 3)
      CALL PUTLIN(WANTED, 3)
      CALL PUTCH(10, 3)
23151 CONTINUE
      ANSTRY(ITHIS) = 1
      MYANCS = ITHIS
      THREAD = IPREV
      IF (.NOT.(THREAD .EQ. 0))GOTO 23153
      GOTO 23138
23153 CONTINUE
      GOTO 23150
23149 CONTINUE
      GOTO 23137
23150 CONTINUE
      GOTO 23148
23147 CONTINUE
      IF (.NOT.(ITHIS .EQ. THREAD))GOTO 23155
      ANSTRY(ITHIS) = 1
      THREAD = IPREV
      IF (.NOT.(THREAD .EQ. 0))GOTO 23157
      GOTO 23138
23157 CONTINUE
23155 CONTINUE
23148 CONTINUE
23143 CONTINUE
23137 GOTO 23136
23138 CONTINUE
      JUNK = NOTE(SEEKPT, FDHIS)
      RETURN
      END
      SUBROUTINE RSTGET()
      COMMON /TCS/ ANSTRY(100), FDHIS, FDREV, FDSCR, FLAG, INSERT, MYANC
     *S, MAXVER, SEEKPT(2)
      INTEGER ANSTRY, FDHIS, FDREV, FDSCR, FLAG, INSERT, MYANCS, MAXVER,
     * SEEKPT
      CALL SEEK(SEEKPT, FDHIS)
      INSERT = 0
      RETURN
      END
      INTEGER FUNCTION LINGET(INBUF, PSTHRU)
      LOGICAL*1 INBUF(512)
      INTEGER PSTHRU
      COMMON /TCS/ ANSTRY(100), FDHIS, FDREV, FDSCR, FLAG, INSERT, MYANC
     *S, MAXVER, SEEKPT(2)
      INTEGER ANSTRY, FDHIS, FDREV, FDSCR, FLAG, INSERT, MYANCS, MAXVER,
     * SEEKPT
      INTEGER BMATCH, CTOI2, GETLIN
      INTEGER CURNST, I
23159 CONTINUE
      I = GETLIN(INBUF, FDHIS)
      IF (.NOT.(I .EQ. -1))GOTO 23162
      CALL ERROR(36HUnexpected EOF on history-data scan.)
23162 CONTINUE
      IF (.NOT.(BMATCH(INBUF, 1, 4H%%E ) .NE. 0))GOTO 23164
      IF (.NOT.(CTOI2(INBUF, 5) .EQ. 1))GOTO 23166
      IF (.NOT.(PSTHRU .EQ. 1))GOTO 23168
      CALL PUTLIN(INBUF, FDSCR)
23168 CONTINUE
      GOTO 23161
23166 CONTINUE
      IF (.NOT.(INSERT .EQ. 0))GOTO 23170
      IF (.NOT.(CTOI2(INBUF, 5) .EQ. CURNST))GOTO 23172
      INSERT = 1
23172 CONTINUE
23170 CONTINUE
      GOTO 23165
23164 CONTINUE
      IF (.NOT.(BMATCH(INBUF, 1, 4H%%I ) .NE. 0))GOTO 23174
      IF (.NOT.(ANSTRY(CTOI2(INBUF, 5)) .EQ. 1))GOTO 23176
      INSERT = 1
      GOTO 23177
23176 CONTINUE
      IF (.NOT.(INSERT .EQ. 1))GOTO 23178
      CURNST = CTOI2(INBUF, 5)
      INSERT = 0
23178 CONTINUE
23177 CONTINUE
      GOTO 23175
23174 CONTINUE
      IF (.NOT.(BMATCH(INBUF, 1, 4H%%D ) .NE. 0))GOTO 23180
      IF (.NOT.(ANSTRY(CTOI2(INBUF, 5)) .EQ. 1))GOTO 23182
      IF (.NOT.(INSERT .EQ. 1))GOTO 23184
      CURNST = CTOI2(INBUF, 5)
      INSERT = 0
23184 CONTINUE
23182 CONTINUE
      GOTO 23181
23180 CONTINUE
      IF (.NOT.(INSERT .EQ. 1))GOTO 23186
      LINGET=(I)
      RETURN
23186 CONTINUE
23181 CONTINUE
23175 CONTINUE
23165 CONTINUE
      IF (.NOT.(PSTHRU .EQ. 1))GOTO 23188
      IF (.NOT.(FLAG .EQ.  1))GOTO 23190
      CALL PUTTAG(4H%%E )
      FLAG =  3
23190 CONTINUE
      CALL PUTLIN(INBUF, FDSCR)
23188 CONTINUE
23160 GOTO 23159
23161 CONTINUE
      LINGET=(-1)
      RETURN
      END
      INTEGER FUNCTION HASH (MCARD)
      LOGICAL*1 MCARD(512)
      INTEGER I, N
      HASH = 0
      I=1
23192 IF (.NOT.(MCARD(I) .NE. 0))GOTO 23194
      N = MCARD(I)
      IF (.NOT.(N .LT. 0))GOTO 23195
      N = (N+ 32687) +  1
23195 CONTINUE
      IF (.NOT.(HASH .LT.  32687/2 ))GOTO 23197
      HASH = HASH + HASH + 1
      GOTO 23198
23197 CONTINUE
      HASH = (HASH- 32687) + HASH-1
23198 CONTINUE
      HASH = N - HASH
      IF (.NOT.(HASH .LT. 0))GOTO 23199
      HASH = (HASH+ 32687) +  1
23199 CONTINUE
23193 I= I + 1
      GOTO 23192
23194 CONTINUE
      RETURN
      END
      SUBROUTINE INCVNO( IN )
      LOGICAL*1 IN(512)
      INTEGER CTOI, ITOC
      INTEGER EFLAG
      INTEGER I, KI, N
      LOGICAL*1 TMP(10)
      I = 1
      EFLAG =  0
23201 CONTINUE
      KI = I
      N = CTOI(IN, I)
      IF (.NOT.(N .GT. 0))GOTO 23204
      EFLAG =  0
23204 CONTINUE
      IF (.NOT.(IN(I) .NE. 46))GOTO 23206
      GOTO 23203
23206 CONTINUE
      I = I+1
      IF (.NOT.(EFLAG .EQ.  1))GOTO 23208
      CALL ERROR(29HTCS Version number corrupted!)
23208 CONTINUE
      EFLAG =  1
23207 CONTINUE
23202 GOTO 23201
23203 CONTINUE
      IF (.NOT.(N .EQ. 0))GOTO 23210
      CALL ERROR(29HTCS Version Number corrupted!)
23210 CONTINUE
      N = N+1
      I = ITOC(N, TMP, 10)
      CALL SCOPY(TMP, 1, IN, KI)
      IN(KI+I) = 0
      RETURN
      END
      SUBROUTINE PUTNUM(N, W, FILE)
      LOGICAL*1 CHARS( 20)
      INTEGER ITOC
      INTEGER I, N, ND, W
      ND = ITOC(N, CHARS,  20)
      I=ND+1
23212 IF (.NOT.(I.LE.W))GOTO 23214
      CALL PUTCH(32, FILE)
23213 I=I+1
      GOTO 23212
23214 CONTINUE
      I=1
23215 IF (.NOT.(I.LE.ND))GOTO 23217
      CALL PUTCH(CHARS(I), FILE)
23216 I=I+1
      GOTO 23215
23217 CONTINUE
      RETURN
      END
      SUBROUTINE APUTLN(STR, OFF, OUTFD)
      LOGICAL*1 STR(512)
      INTEGER OFF, OUTFD
      LOGICAL*1 TMPLIN(512)
      INTEGER I, J
      I = OFF-1
      J = 1
23218 CONTINUE
      I = I+1
      TMPLIN(J) = STR(I)
      J = J+1
23219 IF (.NOT.((STR(I) .EQ. 0) .OR. (STR(I) .EQ. 10)))GOTO 23218
23220 CONTINUE
      TMPLIN(J) = 0
      CALL PUTLIN(TMPLIN, OUTFD)
      RETURN
      END
      SUBROUTINE PUTTAG( TAG )
      LOGICAL*1 TAG(20)
      COMMON /TCS/ ANSTRY(100), FDHIS, FDREV, FDSCR, FLAG, INSERT, MYANC
     *S, MAXVER, SEEKPT(2)
      INTEGER ANSTRY, FDHIS, FDREV, FDSCR, FLAG, INSERT, MYANCS, MAXVER,
     * SEEKPT
      CALL PUTLIN(TAG, FDSCR)
      CALL PUTNUM(MAXVER, 1, FDSCR)
      CALL PUTCH(10, FDSCR)
      RETURN
      END
      INTEGER FUNCTION GETTAB(VIRNDX)
      INTEGER VIRNDX, PHYNDX, PAGE
      INTEGER VIRPHY
      COMMON / CTAB / TAB(8192)
      INTEGER TAB
      PAGE = VIRPHY(VIRNDX, PHYNDX)
      GETTAB=(TAB(PHYNDX))
      RETURN
      END
      SUBROUTINE SETTAB(VIRNDX, VALUE)
      INTEGER VIRNDX, VALUE, PAGE, PHYNDX
      INTEGER VIRPHY
      COMMON / CTAB / TAB(8192)
      INTEGER TAB
      PAGE = VIRPHY(VIRNDX, PHYNDX)
      TAB(PHYNDX) = VALUE
      CALL PDIRTY(PAGE)
      RETURN
      END
      SUBROUTINE MAPPHY(I)
      INTEGER I, N, J, PND, JUNK
      INTEGER NOTE
      INTEGER CREATE
      COMMON / CVIRT / VIRIND(128), PHYIND(128), DSKADR(128)
      INTEGER VIRIND
      INTEGER PHYIND
      INTEGER*4 DSKADR
      COMMON / CVFILE / VIRUNT, VIREND, VPFILE(40)
      INTEGER VIRUNT
      INTEGER*4 VIREND
      LOGICAL*1 VPFILE
      COMMON / CLRU / LRUP(32), MRUP(32), PFNP(32)
      INTEGER LRUP
      INTEGER MRUP
      INTEGER PFNP
      LOGICAL*1 VPF(4)
      DATA VPF(1)/118/,VPF(2)/112/,VPF(3)/102/,VPF(4)/0/
      IF (.NOT.(VIRUNT .EQ. -3))GOTO 23221
      CALL SCRATF(VPF, VPFILE)
      VIRUNT = CREATE(VPFILE, -3)
      IF (.NOT.(VIRUNT .EQ. -3))GOTO 23223
      CALL ERROR(24HCannot open paging file.)
23223 CONTINUE
      JUNK = NOTE(VIREND, VIRUNT)
23221 CONTINUE
      N = LRUP(1)
      J = PFNP(N)
      PND = IABS(PHYIND(J))
      CALL PAGOUT(J)
      PHYIND(I) = PND
      CALL PAGIN(I)
      PFNP(N) = I
      CALL MRUSET(N)
      RETURN
      END
      SUBROUTINE MRUSET(N)
      INTEGER N, I, J
      COMMON / CLRU / LRUP(32), MRUP(32), PFNP(32)
      INTEGER LRUP
      INTEGER MRUP
      INTEGER PFNP
      IF (.NOT.(N .NE. 1))GOTO 23225
      J = LRUP(N)
      I = MRUP(N)
      MRUP(J) = I
      LRUP(I) = J
      I = MRUP(1)
      MRUP(1) = N
      LRUP(I) = N
      LRUP(N) = 1
      MRUP(N) = I
23225 CONTINUE
      RETURN
      END
      SUBROUTINE PAGIN(I)
      INTEGER I, N, JUNK
      INTEGER READF, PTREQ
      COMMON / CVIRT / VIRIND(128), PHYIND(128), DSKADR(128)
      INTEGER VIRIND
      INTEGER PHYIND
      INTEGER*4 DSKADR
      COMMON / CVFILE / VIRUNT, VIREND, VPFILE(40)
      INTEGER VIRUNT
      INTEGER*4 VIREND
      LOGICAL*1 VPFILE
      COMMON / CTAB / TAB(8192)
      INTEGER TAB
      N = PHYIND(I)
      IF (.NOT.(PTREQ(DSKADR(I), 0) .EQ. 1))GOTO 23227
      JUNK = N + 256
23229 IF (.NOT.(N .LT. JUNK))GOTO 23231
      TAB(N) = 0
23230 N=N+1
      GOTO 23229
23231 CONTINUE
      GOTO 23228
23227 CONTINUE
      CALL SEEK(DSKADR(I), VIRUNT)
      JUNK = READF(TAB(N), 512, VIRUNT)
23228 CONTINUE
      RETURN
      END
      SUBROUTINE PAGOUT(J)
      INTEGER J, N, JUNK, RESET
      INTEGER WRITEF, PTREQ, NOTE
      COMMON / CVIRT / VIRIND(128), PHYIND(128), DSKADR(128)
      INTEGER VIRIND
      INTEGER PHYIND
      INTEGER*4 DSKADR
      COMMON / CVFILE / VIRUNT, VIREND, VPFILE(40)
      INTEGER VIRUNT
      INTEGER*4 VIREND
      LOGICAL*1 VPFILE
      COMMON / CTAB / TAB(8192)
      INTEGER TAB
      IF (.NOT.(PHYIND(J) .LT. 0))GOTO 23232
      N = IABS(PHYIND(J))
      IF (.NOT.(PTREQ(DSKADR(J), 0) .EQ. 1))GOTO 23234
      CALL PTRCPY(VIREND, DSKADR(J))
      RESET = 1
      GOTO 23235
23234 CONTINUE
      RESET = 0
23235 CONTINUE
      CALL SEEK(DSKADR(J), VIRUNT)
      JUNK = WRITEF(TAB(N), 512, VIRUNT)
      IF (.NOT.(RESET .EQ. 1))GOTO 23236
      JUNK = NOTE(VIREND, VIRUNT)
23236 CONTINUE
23232 CONTINUE
      PHYIND(J) = 0
      RETURN
      END
      SUBROUTINE PDIRTY(I)
      INTEGER I, N
      COMMON / CVIRT / VIRIND(128), PHYIND(128), DSKADR(128)
      INTEGER VIRIND
      INTEGER PHYIND
      INTEGER*4 DSKADR
      COMMON / CLRU / LRUP(32), MRUP(32), PFNP(32)
      INTEGER LRUP
      INTEGER MRUP
      INTEGER PFNP
      PHYIND(I) = -IABS(PHYIND(I))
      N=1
23238 IF (.NOT.(N .LE. 32))GOTO 23240
      IF (.NOT.(PFNP(N) .EQ. I))GOTO 23241
      GOTO 23240
23241 CONTINUE
23239 N=N+1
      GOTO 23238
23240 CONTINUE
      CALL MRUSET(N)
      RETURN
      END
      SUBROUTINE VIRINT
      INTEGER I, J
      COMMON / CVIRT / VIRIND(128), PHYIND(128), DSKADR(128)
      INTEGER VIRIND
      INTEGER PHYIND
      INTEGER*4 DSKADR
      COMMON / CVFILE / VIRUNT, VIREND, VPFILE(40)
      INTEGER VIRUNT
      INTEGER*4 VIREND
      LOGICAL*1 VPFILE
      COMMON / CLRU / LRUP(32), MRUP(32), PFNP(32)
      INTEGER LRUP
      INTEGER MRUP
      INTEGER PFNP
      I=1
      J=1
23243 IF (.NOT.(I .LE. 128))GOTO 23245
      VIRIND(I) = J
      CALL PTRCPY(0,DSKADR(I))
      IF (.NOT.(I .LE. 32))GOTO 23246
      PHYIND(I) = J
      GOTO 23247
23246 CONTINUE
      PHYIND(I) = 0
23247 CONTINUE
23244 I=I+1
      J=J+256
      GOTO 23243
23245 CONTINUE
      VIRUNT = -3
      I=1
23248 IF (.NOT.(I .LE. 32))GOTO 23250
      LRUP(I) = I - 1
      MRUP(I) = I + 1
      PFNP(I) = I
23249 I=I+1
      GOTO 23248
23250 CONTINUE
      LRUP(1) = 32
      MRUP(32) = 1
      RETURN
      END
      INTEGER FUNCTION VIRPHY(VIRTND, PHYSND)
      INTEGER VIRTND, PHYSND, I
      COMMON / CVIRT / VIRIND(128), PHYIND(128), DSKADR(128)
      INTEGER VIRIND
      INTEGER PHYIND
      INTEGER*4 DSKADR
      I = ((VIRTND - 1) / 256) + 1
      IF (.NOT.(PHYIND(I) .EQ. 0))GOTO 23251
      CALL MAPPHY(I)
23251 CONTINUE
      PHYSND = IABS(PHYIND(I)) + (VIRTND - VIRIND(I))
      VIRPHY=(I)
      RETURN
      END
      SUBROUTINE VIRFIN
      COMMON / CVFILE / VIRUNT, VIREND, VPFILE(40)
      INTEGER VIRUNT
      INTEGER*4 VIREND
      LOGICAL*1 VPFILE
      INTEGER JUNK
      INTEGER REMOVE
      IF (.NOT.(VIRUNT .NE. -3))GOTO 23253
      CALL CLOSE(VIRUNT)
      JUNK = REMOVE(VPFILE)
23253 CONTINUE
      RETURN
      END
      SUBROUTINE DOSORT(NNN)
      INTEGER NNN
      INTEGER S, LEFT(20), RIGHT(20), L, R, I, J, P, ITEMP, KI, KJ
      INTEGER CMPINT
      INTEGER GETTAB
      INTEGER ISTAB1, ISTAB2
      S = 1
      LEFT(1) = 1
      RIGHT(1) = NNN
23255 CONTINUE
      L = LEFT(S)
      R = RIGHT(S)
      S = S - 1
23258 CONTINUE
      I = L
      J = R
      P = R
23261 CONTINUE
23264 IF (.NOT.(CMPINT(I, P) .LT. 0))GOTO 23265
      I = I + 1
      GOTO 23264
23265 CONTINUE
23266 IF (.NOT.(CMPINT(P, J) .LT. 0))GOTO 23267
      J = J - 1
      GOTO 23266
23267 CONTINUE
      IF (.NOT.(I .LE. J))GOTO 23268
      ITEMP = GETTAB(I)
      ISTAB1=I
      ISTAB2= GETTAB(J)
      CALL SETTAB(ISTAB1, ISTAB2)
      ISTAB1=J
      ISTAB2= ITEMP
      CALL SETTAB(ISTAB1, ISTAB2)
      KI =  32513 - I
      KJ =  32513 - J
      ITEMP = GETTAB(KI)
      ISTAB1=KI
      ISTAB2= GETTAB(KJ)
      CALL SETTAB(ISTAB1, ISTAB2)
      ISTAB1=KJ
      ISTAB2= ITEMP
      CALL SETTAB(ISTAB1, ISTAB2)
      I = I + 1
      J = J - 1
23268 CONTINUE
23262 IF (.NOT.(I .GT. J))GOTO 23261
23263 CONTINUE
      IF (.NOT.(J - L .LT. R - I))GOTO 23270
      IF (.NOT.(I .LT. R))GOTO 23272
      S = S + 1
      LEFT(S) = I
      RIGHT(S) = R
23272 CONTINUE
      R = J
      GOTO 23271
23270 CONTINUE
      IF (.NOT.(L .LT. J))GOTO 23274
      S = S + 1
      LEFT(S) = L
      RIGHT(S) = J
23274 CONTINUE
      L = I
23271 CONTINUE
23259 IF (.NOT.(L .GE. R))GOTO 23258
23260 CONTINUE
23256 IF (.NOT.(S .EQ. 0))GOTO 23255
23257 CONTINUE
      RETURN
      END
      INTEGER FUNCTION CMPINT(I, J)
      INTEGER I, J
      INTEGER KI, KJ, VI, VJ, STATUS
      INTEGER GETTAB
      INTEGER ISTAB1, ISTAB2
      KI =  32513 - I
      KJ =  32513 - J
      VI = GETTAB(KI)
      VJ = GETTAB(KJ)
      IF (.NOT.(VI .LT. VJ))GOTO 23276
      STATUS = -1
      GOTO 23277
23276 CONTINUE
      IF (.NOT.(VI .GT. VJ))GOTO 23278
      STATUS = 1
      GOTO 23279
23278 CONTINUE
      VI = GETTAB(I)
      VJ = GETTAB(J)
      IF (.NOT.(VI .LT. VJ))GOTO 23280
      STATUS = -1
      GOTO 23281
23280 CONTINUE
      IF (.NOT.(VI .GT. VJ))GOTO 23282
      STATUS = 1
      GOTO 23283
23282 CONTINUE
      STATUS = 0
23283 CONTINUE
23281 CONTINUE
23279 CONTINUE
23277 CONTINUE
      CMPINT=(STATUS)
      RETURN
      END
