      SUBROUTINE MAIN
      INTEGER I, JUNK, PNDX
      INTEGER GETARG, IMPUT, ISATTY, CTOI
      INTEGER OPEN
      INTEGER IMINIT
      LOGICAL*1 ARG(40)
      COMMON / CMAN / ANY, TABLE
      INTEGER ANY
      INTEGER TABLE
      COMMON / CPAGE / PAGEFD, PAGESZ
      INTEGER PAGEFD
      INTEGER PAGESZ
      INTEGER MEM( 2560)
      LOGICAL*1 CMEM(5120)
      EQUIVALENCE (CMEM(1),MEM(1))
      COMMON/CDSMEM/MEM
      LOGICAL*1 DOCFIL(40)
      LOGICAL*1 SUFFIX(40)
      LOGICAL*1 TTYFIL(4)
      DATA DOCFIL(1)/126/,DOCFIL(2)/109/,DOCFIL(3)/97/,DOCFIL(4)/110/,DO
     *CFIL(5)/47/,DOCFIL(6)/115/,DOCFIL(7)/0/
      DATA SUFFIX(1)/49/,SUFFIX(2)/0/
      DATA TTYFIL(1)/84/,TTYFIL(2)/73/,TTYFIL(3)/58/,TTYFIL(4)/0/
      CALL QUERY(54Husage:  man [-<pagelen>] [-s<section>] [-a] [name] .
     *..)
      IF (.NOT.(ISATTY(2) .EQ. 1))GOTO 23000
      PAGEFD = OPEN(TTYFIL, 1)
      PAGESZ = 22
      GOTO 23001
23000 CONTINUE
      PAGEFD = -3
      PAGESZ = 30000
23001 CONTINUE
      ANY = 0
      PNDX = 1
      TABLE = IMINIT(2560, 10)
      I=1
23002 IF (.NOT.(GETARG(I, ARG, 40) .NE. -1))GOTO 23004
      IF (.NOT.(ARG(1) .EQ. 45))GOTO 23005
      IF (.NOT.((48.LE.ARG(2).AND.ARG(2).LE.57)))GOTO 23007
      JUNK = 2
      PAGESZ = CTOI(ARG, JUNK)
      IF (.NOT.(PAGESZ .LE. 0 .AND. PAGEFD .NE. -3))GOTO 23009
      CALL CLOSE(PAGEFD)
      PAGEFD = -3
23009 CONTINUE
      GOTO 23008
23007 CONTINUE
      IF (.NOT.(ARG(2) .EQ. 97 .OR. ARG(2) .EQ. 65))GOTO 23011
      ANY = 1
      GOTO 23012
23011 CONTINUE
      IF (.NOT.(ARG(2) .EQ. 115 .OR. ARG(2) .EQ. 83))GOTO 23013
      CALL SCOPY(ARG, 3, SUFFIX, 1)
      GOTO 23014
23013 CONTINUE
      CALL BADARG(ARG)
23014 CONTINUE
23012 CONTINUE
23008 CONTINUE
      GOTO 23006
23005 CONTINUE
      CALL FOLD(ARG)
      JUNK = IMPUT(TABLE, ARG)
      PNDX = PNDX + 1
23006 CONTINUE
23003 I=I+1
      GOTO 23002
23004 CONTINUE
      CALL DOSYN(SUFFIX)
      CALL CONCAT(DOCFIL, SUFFIX, DOCFIL)
      IF (.NOT.(PNDX .EQ. 1 .AND. ANY .EQ. 0))GOTO 23015
      CALL DOTOC(SUFFIX, DOCFIL)
      GOTO 23016
23015 CONTINUE
      CALL DOMAN(SUFFIX, DOCFIL)
23016 CONTINUE
      RETURN
      END
      INTEGER FUNCTION ALLBLK(BUF)
      LOGICAL*1 BUF(100)
      INTEGER I
      I=1
23017 IF (.NOT.(BUF(I) .NE. 10 .AND. BUF(I) .NE. 0))GOTO 23019
      IF (.NOT.(BUF(I) .NE. 32 .AND. BUF(I) .NE. 9))GOTO 23020
      ALLBLK=(0)
      RETURN
23020 CONTINUE
23018 I=I+1
      GOTO 23017
23019 CONTINUE
      ALLBLK=(1)
      RETURN
      END
      SUBROUTINE DOMAN(SUFFIX, FILE)
      LOGICAL*1 SUFFIX(100), FILE(100), NAME(40), BUF(512)
      LOGICAL*1 GTCONF
      INTEGER SIZE(2), NENTRY, I
      INTEGER IMGET
      INTEGER FD
      INTEGER OPEN
      COMMON / CMAN / ANY, TABLE
      INTEGER ANY
      INTEGER TABLE
      LOGICAL*1 ENTRY(40)
      INTEGER FSIZE(2), S1, S2, CMP
      INTEGER GETLIN, GETWRD, AGETHD, STRCMP
      INTEGER DD
      INTEGER*4 PTR
      LOGICAL*1 NOMAN(31)
      LOGICAL*1 PSTR(23)
      LOGICAL*1 DOCDIR(6)
      LOGICAL*1 SINDEX(2)
      LOGICAL*1 SEPR8R(2)
      DATA NOMAN(1)/32/,NOMAN(2)/45/,NOMAN(3)/32/,NOMAN(4)/110/,NOMAN(5)
     */111/,NOMAN(6)/32/,NOMAN(7)/109/,NOMAN(8)/97/,NOMAN(9)/110/,NOMAN(
     *10)/117/,NOMAN(11)/97/,NOMAN(12)/108/,NOMAN(13)/32/,NOMAN(14)/101/
     *,NOMAN(15)/110/,NOMAN(16)/116/,NOMAN(17)/114/,NOMAN(18)/121/,NOMAN
     *(19)/32/,NOMAN(20)/97/,NOMAN(21)/118/,NOMAN(22)/97/,NOMAN(23)/105/
     *,NOMAN(24)/108/,NOMAN(25)/97/,NOMAN(26)/98/,NOMAN(27)/108/,NOMAN(2
     *8)/101/,NOMAN(29)/46/,NOMAN(30)/10/,NOMAN(31)/0/
      DATA PSTR(1)/78/,PSTR(2)/101/,PSTR(3)/120/,PSTR(4)/116/,PSTR(5)/32
     */,PSTR(6)/101/,PSTR(7)/110/,PSTR(8)/116/,PSTR(9)/114/,PSTR(10)/121
     */,PSTR(11)/32/,PSTR(12)/91/,PSTR(13)/110/,PSTR(14)/32/,PSTR(15)/61
     */,PSTR(16)/62/,PSTR(17)/32/,PSTR(18)/78/,PSTR(19)/79/,PSTR(20)/93/
     *,PSTR(21)/63/,PSTR(22)/32/,PSTR(23)/0/
      DATA DOCDIR(1)/126/,DOCDIR(2)/109/,DOCDIR(3)/97/,DOCDIR(4)/110/,DO
     *CDIR(5)/47/,DOCDIR(6)/0/
      DATA SINDEX(1)/105/,SINDEX(2)/0/
      DATA SEPR8R(1)/46/,SEPR8R(2)/0/
      IF (.NOT.(ANY .EQ. 1))GOTO 23022
      CALL TFETCH(SUFFIX, FILE)
23022 CONTINUE
      CALL IMSORT(TABLE)
      CALL IMUNIQ(TABLE)
      NENTRY = 0
      FD = OPEN(FILE, 1)
      IF (.NOT.(FD .EQ. -3))GOTO 23024
      CALL CANT(FILE)
23024 CONTINUE
      I = 1
      CALL STCOPY(DOCDIR, 1, NAME, I)
      CALL STCOPY(SINDEX, 1, NAME, I)
      CALL STCOPY(SUFFIX, 1, NAME, I)
      DD = OPEN(NAME, 1)
      IF (.NOT.(DD .EQ. -3))GOTO 23026
      CALL CANT(NAME)
23026 CONTINUE
      S1 = IMGET(TABLE, NAME)
      S2 = GETLIN(BUF, DD)
23028 CONTINUE
      IF (.NOT.(S1 .EQ. -1 .OR. S2 .EQ. -1))GOTO 23031
      GOTO 23030
23031 CONTINUE
      I = 1
      JUNK = GETWRD(BUF, I, ENTRY)
      CMP = STRCMP(ENTRY, NAME)
      IF (.NOT.(CMP .EQ. -1))GOTO 23033
      S2 = GETLIN(BUF, DD)
      GOTO 23034
23033 CONTINUE
      IF (.NOT.(CMP .EQ. 0))GOTO 23035
      NENTRY = NENTRY + 1
      IF (.NOT.(NENTRY .GT. 1))GOTO 23037
      IF (.NOT.(GTCONF(PSTR) .EQ. 110))GOTO 23039
      S1 = -1
      GOTO 23030
23039 CONTINUE
23037 CONTINUE
      CALL CTOPTR(BUF, I, PTR)
      CALL SEEK(PTR, FD)
      FSIZE(1) = 32767
      FSIZE(2) = 0
      JUNK = AGETHD(FD, BUF, SIZE, FSIZE)
      CALL PRUNIQ(FD, SIZE)
      S1 = IMGET(TABLE, NAME)
      S2 = GETLIN(BUF, DD)
      GOTO 23036
23035 CONTINUE
      CALL PUTLIN(NAME, 3)
      CALL PUTLIN(NOMAN, 3)
      S1 = IMGET(TABLE, NAME)
23036 CONTINUE
23034 CONTINUE
23029 GOTO 23028
23030 CONTINUE
      CALL CLOSE(FD)
      CALL CLOSE(DD)
23041 IF (.NOT.(S1 .NE. -1 .AND. ANY .EQ. 0))GOTO 23042
      CALL PUTLIN(NAME, 3)
      CALL PUTLIN(NOMAN, 3)
      S1 = IMGET(TABLE, NAME)
      GOTO 23041
23042 CONTINUE
      RETURN
      END
      SUBROUTINE DOTOC(SUFFIX, FILE)
      LOGICAL*1 SUFFIX(100), FILE(100), BUF(512)
      INTEGER NXTCOL
      INTEGER IMGET
      LOGICAL*1 NAME(40)
      COMMON / CMAN / ANY, TABLE
      INTEGER ANY
      INTEGER TABLE
      LOGICAL*1 INTSTR(37)
      DATA INTSTR(1)/77/,INTSTR(2)/97/,INTSTR(3)/110/,INTSTR(4)/117/,INT
     *STR(5)/97/,INTSTR(6)/108/,INTSTR(7)/32/,INTSTR(8)/101/,INTSTR(9)/1
     *10/,INTSTR(10)/116/,INTSTR(11)/114/,INTSTR(12)/105/,INTSTR(13)/101
     */,INTSTR(14)/115/,INTSTR(15)/32/,INTSTR(16)/97/,INTSTR(17)/118/,IN
     *TSTR(18)/97/,INTSTR(19)/105/,INTSTR(20)/108/,INTSTR(21)/97/,INTSTR
     *(22)/98/,INTSTR(23)/108/,INTSTR(24)/101/,INTSTR(25)/32/,INTSTR(26)
     */105/,INTSTR(27)/110/,INTSTR(28)/32/,INTSTR(29)/115/,INTSTR(30)/10
     *1/,INTSTR(31)/99/,INTSTR(32)/116/,INTSTR(33)/105/,INTSTR(34)/111/,
     *INTSTR(35)/110/,INTSTR(36)/32/,INTSTR(37)/0/
      CALL TFETCH(SUFFIX, FILE)
      CALL IMSORT(TABLE)
      CALL IMUNIQ(TABLE)
      CALL PUTLIN(INTSTR, 2)
      CALL PUTLNL(SUFFIX, 2)
      CALL PUTCH(10, 2)
      CALL INPACK(NXTCOL, 80, BUF, 2)
23043 IF (.NOT.(IMGET(TABLE, NAME) .NE. -1))GOTO 23044
      CALL DOPACK(NAME, NXTCOL, 80, BUF, 2)
      GOTO 23043
23044 CONTINUE
      CALL FLPACK(NXTCOL, 80, BUF, 2)
      RETURN
      END
      LOGICAL*1 FUNCTION GTCONF(PSTR)
      LOGICAL*1 PSTR(100), BUF(512), C
      LOGICAL*1 CLOWER
      INTEGER JUNK
      INTEGER PROMPT
      COMMON / CPAGE / PAGEFD, PAGESZ
      INTEGER PAGEFD
      INTEGER PAGESZ
      IF (.NOT.(PAGEFD .NE. -3))GOTO 23045
      JUNK = PROMPT(PSTR, BUF, PAGEFD)
      C = CLOWER(BUF(1))
      GOTO 23046
23045 CONTINUE
      C = 121
23046 CONTINUE
      GTCONF=(C)
      RETURN
      END
      SUBROUTINE PRUNIQ(INT, SIZE)
      INTEGER AGTLIN, ALLBLK
      INTEGER T, SIZE(2), N, BLK
      LOGICAL*1 BUF(512)
      LOGICAL*1 GTCONF
      COMMON / CPAGE / PAGEFD, PAGESZ
      INTEGER PAGEFD
      INTEGER PAGESZ
      LOGICAL*1 PSTR(17)
      DATA PSTR(1)/77/,PSTR(2)/111/,PSTR(3)/114/,PSTR(4)/101/,PSTR(5)/32
     */,PSTR(6)/91/,PSTR(7)/110/,PSTR(8)/32/,PSTR(9)/61/,PSTR(10)/62/,PS
     *TR(11)/32/,PSTR(12)/78/,PSTR(13)/79/,PSTR(14)/93/,PSTR(15)/63/,PST
     *R(16)/32/,PSTR(17)/0/
      IF (.NOT.(PAGEFD .EQ. -3))GOTO 23047
23049 IF (.NOT.(AGTLIN(BUF, INT, SIZE) .NE. -1))GOTO 23050
      CALL PUTLIN(BUF, 2)
      GOTO 23049
23050 CONTINUE
      RETURN
23047 CONTINUE
      N = 0
      T = AGTLIN(BUF, INT, SIZE)
23051 IF (.NOT.(T .NE. -1))GOTO 23052
      N = N + 1
      IF (.NOT.(N .GT. PAGESZ))GOTO 23053
      IF (.NOT.(GTCONF(PSTR) .EQ. 110))GOTO 23055
      GOTO 23052
23055 CONTINUE
      N = 0
23056 CONTINUE
23053 CONTINUE
      CALL PUTLIN(BUF, 2)
      BLK = ALLBLK(BUF)
      T = AGTLIN(BUF, INT, SIZE)
      IF (.NOT.(BLK .EQ. 1))GOTO 23057
23059 IF (.NOT.(T .NE. -1))GOTO 23060
      IF (.NOT.(ALLBLK(BUF) .EQ. 0))GOTO 23061
      GOTO 23060
23061 CONTINUE
      T = AGTLIN(BUF, INT, SIZE)
23062 CONTINUE
      GOTO 23059
23060 CONTINUE
23057 CONTINUE
      GOTO 23051
23052 CONTINUE
23063 IF (.NOT.(T .NE. -1))GOTO 23064
      T = AGTLIN(BUF, INT, SIZE)
      GOTO 23063
23064 CONTINUE
      RETURN
      END
      SUBROUTINE TFETCH(SUFFIX, FILE)
      LOGICAL*1 SUFFIX(100), FILE(100)
      LOGICAL*1 NAME(512)
      INTEGER IMINIT
      INTEGER I, JUNK
      INTEGER IMPUT
      COMMON / CMAN / ANY, TABLE
      INTEGER ANY
      INTEGER TABLE
      INTEGER INDEXC, GETLIN
      INTEGER FD
      INTEGER OPEN
      LOGICAL*1 SINDEX(2)
      LOGICAL*1 SECT(2)
      LOGICAL*1 DOCDIR(6)
      LOGICAL*1 SEPR8R(2)
      DATA SINDEX(1)/105/,SINDEX(2)/0/
      DATA SECT(1)/115/,SECT(2)/0/
      DATA DOCDIR(1)/126/,DOCDIR(2)/109/,DOCDIR(3)/97/,DOCDIR(4)/110/,DO
     *CDIR(5)/47/,DOCDIR(6)/0/
      DATA SEPR8R(1)/46/,SEPR8R(2)/0/
      TABLE = IMINIT(2560, 10)
      I = 1
      CALL STCOPY(DOCDIR, 1, NAME, I)
      CALL STCOPY(SINDEX, 1, NAME, I)
      CALL STCOPY(SUFFIX, 1, NAME, I)
      FD = OPEN(NAME, 1)
      IF (.NOT.(FD .EQ. -3))GOTO 23065
      CALL ERROR(37HCannot open index for manual archive.)
23065 CONTINUE
23067 IF (.NOT.(GETLIN(NAME, FD) .NE. -1))GOTO 23068
      I = INDEXC(NAME, 32)
      NAME(I) = 0
      JUNK = IMPUT(TABLE, NAME)
      GOTO 23067
23068 CONTINUE
      CALL CLOSE(FD)
      RETURN
      END
      SUBROUTINE DOSYN(SECT)
      LOGICAL*1 SECT(100)
      INTEGER EQUAL
      LOGICAL*1 CMD(4)
      LOGICAL*1 PRIM(5)
      LOGICAL*1 LIB(4)
      LOGICAL*1 PRIMER(7)
      LOGICAL*1 ONE(2)
      LOGICAL*1 TWO(2)
      LOGICAL*1 THREE(2)
      LOGICAL*1 FOUR(2)
      DATA CMD(1)/99/,CMD(2)/109/,CMD(3)/100/,CMD(4)/0/
      DATA PRIM(1)/112/,PRIM(2)/114/,PRIM(3)/105/,PRIM(4)/109/,PRIM(5)/0
     */
      DATA LIB(1)/108/,LIB(2)/105/,LIB(3)/98/,LIB(4)/0/
      DATA PRIMER(1)/112/,PRIMER(2)/114/,PRIMER(3)/105/,PRIMER(4)/109/,P
     *RIMER(5)/101/,PRIMER(6)/114/,PRIMER(7)/0/
      DATA ONE(1)/49/,ONE(2)/0/
      DATA TWO(1)/50/,TWO(2)/0/
      DATA THREE(1)/51/,THREE(2)/0/
      DATA FOUR(1)/52/,FOUR(2)/0/
      CALL FOLD(SECT)
      IF (.NOT.(EQUAL(SECT, CMD) .EQ. 1))GOTO 23069
      CALL STRCPY(ONE, SECT)
      GOTO 23070
23069 CONTINUE
      IF (.NOT.(EQUAL(SECT, PRIM) .EQ. 1))GOTO 23071
      CALL STRCPY(TWO, SECT)
      GOTO 23072
23071 CONTINUE
      IF (.NOT.(EQUAL(SECT, LIB) .EQ. 1))GOTO 23073
      CALL STRCPY(THREE, SECT)
      GOTO 23074
23073 CONTINUE
      IF (.NOT.(EQUAL(SECT, PRIMER) .EQ. 1))GOTO 23075
      CALL STRCPY(FOUR, SECT)
23075 CONTINUE
23074 CONTINUE
23072 CONTINUE
23070 CONTINUE
      RETURN
      END
