      SUBROUTINE MAIN
      LOGICAL*1 ARG(402)
      INTEGER OPEN, GETARG, INDEXC
      INTEGER FD, I, J, WORDS, LINES, CHARS, NFILES
      INTEGER NL(2), NW(2), NC(2), TL(2), TW(2), TC(2)
      LOGICAL*1 TOTAL(6)
      LOGICAL*1 USESTR(29)
      LOGICAL*1 NULL(1)
      LOGICAL*1 ST001Z(13)
      DATA TOTAL(1)/116/,TOTAL(2)/111/,TOTAL(3)/116/,TOTAL(4)/97/,TOTAL(
     *5)/108/,TOTAL(6)/0/
      DATA USESTR(1)/117/,USESTR(2)/115/,USESTR(3)/97/,USESTR(4)/103/,US
     *ESTR(5)/101/,USESTR(6)/58/,USESTR(7)/32/,USESTR(8)/32/,USESTR(9)/1
     *19/,USESTR(10)/99/,USESTR(11)/32/,USESTR(12)/91/,USESTR(13)/45/,US
     *ESTR(14)/108/,USESTR(15)/119/,USESTR(16)/99/,USESTR(17)/93/,USESTR
     *(18)/32/,USESTR(19)/91/,USESTR(20)/102/,USESTR(21)/105/,USESTR(22)
     */108/,USESTR(23)/101/,USESTR(24)/93/,USESTR(25)/32/,USESTR(26)/46/
     *,USESTR(27)/46/,USESTR(28)/46/,USESTR(29)/0/
      DATA NULL(1)/0/
      DATA WORDS /1/, LINES /1/, CHARS /1/
      DATA ST001Z(1)/58/,ST001Z(2)/32/,ST001Z(3)/99/,ST001Z(4)/97/,ST001
     *Z(5)/110/,ST001Z(6)/39/,ST001Z(7)/116/,ST001Z(8)/32/,ST001Z(9)/111
     */,ST001Z(10)/112/,ST001Z(11)/101/,ST001Z(12)/110/,ST001Z(13)/0/
      CALL QUERY(USESTR)
      TL(1) = 0
      TL(2) = 0
      TW(1) = 0
      TW(2) = 0
      TC(1) = 0
      TC(2) = 0
      I = 1
23000 IF (.NOT.(GETARG(I, ARG, 36) .NE. -1))GOTO 23002
      IF (.NOT.(ARG(1) .EQ. 45 .AND. ARG(2) .NE. 0))GOTO 23003
      LINES = 0
      WORDS = 0
      CHARS = 0
      CALL FOLD(ARG)
      IF (.NOT.(INDEXC(ARG, 108) .GT. 0))GOTO 23005
      LINES = 1
23005 CONTINUE
      IF (.NOT.(INDEXC(ARG, 119) .GT. 0))GOTO 23007
      WORDS = 1
23007 CONTINUE
      IF (.NOT.(INDEXC(ARG, 99) .GT. 0))GOTO 23009
      CHARS = 1
23009 CONTINUE
      GOTO 23004
23003 CONTINUE
      NFILES = NFILES + 1
      IF (.NOT.(ARG(1) .EQ. 45))GOTO 23011
      FD = 1
      GOTO 23012
23011 CONTINUE
      FD = OPEN(ARG, 1)
23012 CONTINUE
      IF (.NOT.(FD .EQ. -3))GOTO 23013
      CALL PUTLIN(ARG, 3)
      CALL REMARK(ST001Z)
      GOTO 23014
23013 CONTINUE
      CALL DOWC(FD, NL, NW, NC)
      CALL PRINTC(ARG, NL, NW, NC, LINES, WORDS, CHARS)
      TL(1) = TL(1) + NL(1)
      TL(2) = TL(2) + NL(2)
      IF (.NOT.(TL(2) .GE. 10000))GOTO 23015
      TL(1) = TL(1) + 1
      TL(2) = TL(2) - 10000
23015 CONTINUE
      TW(1) = TW(1) + NW(1)
      TW(2) = TW(2) + NW(2)
      IF (.NOT.(TW(2) .GE. 10000))GOTO 23017
      TW(1) = TW(1) + 1
      TW(2) = TW(2) - 10000
23017 CONTINUE
      TC(1) = TC(1) + NC(1)
      TC(2) = TC(2) + NC(2)
      IF (.NOT.(TC(2) .GE. 10000))GOTO 23019
      TC(1) = TC(1) + 1
      TC(2) = TC(2) - 10000
23019 CONTINUE
      IF (.NOT.(FD .NE. 1))GOTO 23021
      CALL CLOSE(FD)
23021 CONTINUE
23014 CONTINUE
23004 CONTINUE
23001 I = I + 1
      GOTO 23000
23002 CONTINUE
      IF (.NOT.(NFILES .EQ. 0))GOTO 23023
      CALL DOWC(1, NL, NW, NC)
      CALL PRINTC(NULL, NL, NW, NC, LINES, WORDS, CHARS)
      GOTO 23024
23023 CONTINUE
      IF (.NOT.(NFILES .GT. 1))GOTO 23025
      CALL PRINTC(TOTAL, TL, TW, TC, LINES, WORDS, CHARS)
23025 CONTINUE
23024 CONTINUE
      RETURN
      END
      SUBROUTINE DOWC(FD, NL, NW, NC)
      INTEGER FD, NL(2), NW(2), NC(2)
      LOGICAL*1 GETCH
      LOGICAL*1 C
      INTEGER INWORD
      NL(1) = 0
      NL(2) = 0
      NW(1) = 0
      NW(2) = 0
      NC(1) = 0
      NC(2) = 0
      INWORD = 0
23027 IF (.NOT.(GETCH(C, FD) .NE. -1))GOTO 23028
      NC(2) = NC(2) + 1
      IF (.NOT.(NC(2) .GE. 10000))GOTO 23029
      NC(1) = NC(1) + 1
      NC(2) = 0
23029 CONTINUE
      IF (.NOT.(C .EQ. 10))GOTO 23031
      NL(2) = NL(2) + 1
      IF (.NOT.(NL(2) .GE. 10000))GOTO 23033
      NL(1) = NL(1) + 1
      NL(2) = 0
23033 CONTINUE
23031 CONTINUE
      IF (.NOT.(C .EQ. 32 .OR. C .EQ. 10 .OR. C .EQ. 9))GOTO 23035
      INWORD = 0
      GOTO 23036
23035 CONTINUE
      IF (.NOT.(INWORD .EQ. 0))GOTO 23037
      INWORD = 1
      NW(2) = NW(2) + 1
      IF (.NOT.(NW(2) .GE. 10000))GOTO 23039
      NW(1) = NW(1) + 1
      NW(2) = 0
23039 CONTINUE
23037 CONTINUE
23036 CONTINUE
      GOTO 23027
23028 CONTINUE
      RETURN
      END
      SUBROUTINE PRINTC(ARG, NL, NW, NC, LINES, WORDS, CHARS)
      LOGICAL*1 ARG(100), BUF(20)
      INTEGER DITOC
      INTEGER NL(2), NW(2), NC(2), LINES, WORDS, CHARS, JUNK
      IF (.NOT.(LINES .EQ. 1))GOTO 23041
      JUNK = DITOC(NL, BUF, 20)
      CALL PUTSTR(BUF, 8, 2)
23041 CONTINUE
      IF (.NOT.(WORDS .EQ. 1))GOTO 23043
      JUNK = DITOC(NW, BUF, 20)
      CALL PUTSTR(BUF, 8, 2)
23043 CONTINUE
      IF (.NOT.(CHARS .EQ. 1))GOTO 23045
      JUNK = DITOC(NC, BUF, 20)
      CALL PUTSTR(BUF, 8, 2)
23045 CONTINUE
      CALL PUTCH(32,2)
      CALL PUTLIN(ARG, 2)
      CALL PUTCH(10,2)
      RETURN
      END
