      SUBROUTINE MAIN
      LOGICAL*1 ARG(400)
      INTEGER OPEN, GETARG
      INTEGER FD, I, J, WORDS, LINES, CHARS, NFILES
      INTEGER NL, NW, NC, TL, TW, TC
      LOGICAL*1 TOTAL(6)
      DATA TOTAL(1)/116/,TOTAL(2)/111/,TOTAL(3)/116/,TOTAL(4)/97/,TOTAL(
     *5)/108/,TOTAL(6)/0/
      DATA WORDS /1/, LINES /1/, CHARS /1/
      DATA TL /0/, TW /0/, TC /0/
      I = 1
23000 IF(.NOT.(GETARG(I, ARG, 40) .NE. -1))GOTO 23002
      IF(.NOT.(ARG(1) .EQ. 63 .AND. ARG(2) .EQ. 0))GOTO 23003
      CALL ERROR (26Husage:  wc [-lwc] [files].)
      GOTO 23004
23003 CONTINUE
      IF(.NOT.(ARG(1) .EQ. 45 .AND. ARG(2) .NE. 0))GOTO 23005
      LINES = 0
      WORDS = 0
      CHARS = 0
      J = 2
23007 IF(.NOT.(ARG(J) .NE. 0))GOTO 23009
      IF(.NOT.(ARG(J) .EQ. 108 .OR. ARG(J) .EQ. 76))GOTO 23010
      LINES = 1
      GOTO 23011
23010 CONTINUE
      IF(.NOT.(ARG(J) .EQ. 119 .OR. ARG(J) .EQ. 87))GOTO 23012
      WORDS = 1
      GOTO 23013
23012 CONTINUE
      IF(.NOT.(ARG(J) .EQ. 99 .OR. ARG(J) .EQ. 67))GOTO 23014
      CHARS = 1
      GOTO 23015
23014 CONTINUE
      CALL ERROR(23Husage: wc [-lwc] files.)
23015 CONTINUE
23013 CONTINUE
23011 CONTINUE
23008 J = J + 1
      GOTO 23007
23009 CONTINUE
      GOTO 23006
23005 CONTINUE
      NFILES = NFILES + 1
      IF(.NOT.(ARG(1) .EQ. 45))GOTO 23016
      FD = 1
      GOTO 23017
23016 CONTINUE
      FD = OPEN(ARG, 1)
23017 CONTINUE
      IF(.NOT.(FD .EQ. -3))GOTO 23018
      CALL PUTLIN(ARG, 3)
      CALL REMARK(13H: can't open.)
      GOTO 23019
23018 CONTINUE
      CALL DOWC(FD, NL, NW, NC)
      CALL PRINTC(ARG, NL, NW, NC, LINES, WORDS, CHARS)
      TL = TL + NL
      TW = TW + NW
      TC = TC + NC
      IF(.NOT.(FD .NE. 1))GOTO 23020
      CALL CLOSE(FD)
23020 CONTINUE
23019 CONTINUE
23006 CONTINUE
23004 CONTINUE
23001 I = I + 1
      GOTO 23000
23002 CONTINUE
      IF(.NOT.(NFILES .EQ. 0))GOTO 23022
      CALL DOWC(1, NL, NW, NC)
      CALL PRINTC(0, NL, NW, NC, LINES, WORDS, CHARS)
      GOTO 23023
23022 CONTINUE
      IF(.NOT.(NFILES .GT. 1))GOTO 23024
      CALL PRINTC(TOTAL, TL, TW, TC, LINES, WORDS, CHARS)
23024 CONTINUE
23023 CONTINUE
      RETURN
      END
      SUBROUTINE DOWC(FD, NL, NW, NC)
      INTEGER FD, NL, NW, NC
      LOGICAL*1 GETCH
      LOGICAL*1 C
      INTEGER INWORD
      NL = 0
      NW = 0
      NC = 0
      INWORD = 0
23026 IF(.NOT.(GETCH(C, FD) .NE. -1))GOTO 23027
      NC = NC + 1
      IF(.NOT.(C .EQ. 10))GOTO 23028
      NL = NL + 1
23028 CONTINUE
      IF(.NOT.(C .EQ. 32 .OR. C .EQ. 10 .OR. C .EQ. 9))GOTO 23030
      INWORD = 0
      GOTO 23031
23030 CONTINUE
      IF(.NOT.(INWORD .EQ. 0))GOTO 23032
      INWORD = 1
      NW = NW + 1
23032 CONTINUE
23031 CONTINUE
      GOTO 23026
23027 CONTINUE
      RETURN
      END
      SUBROUTINE PRINTC(ARG, NL, NW, NC, LINES, WORDS, CHARS)
      LOGICAL*1 ARG(100)
      INTEGER NL, NW, NC, LINES, WORDS, CHARS
      IF(.NOT.(LINES .EQ. 1))GOTO 23034
      CALL PUTDEC(NL, 8)
23034 CONTINUE
      IF(.NOT.(WORDS .EQ. 1))GOTO 23036
      CALL PUTDEC(NW, 8)
23036 CONTINUE
      IF(.NOT.(CHARS .EQ. 1))GOTO 23038
      CALL PUTDEC(NC, 8)
23038 CONTINUE
      CALL PUTC(32)
      CALL PUTLIN(ARG, 2)
      CALL PUTC(10)
      RETURN
      END
