; WC
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; Print the number of words, lines, characters and non-blank characters.
; Implicit parameters: output to console
;!proteus -o
; Start up
FUNCTION ONSTART()
IF STREQ(ARGV(3), "..")
CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " filename"
CONSOLELN ""
CONSOLELN "Purpose: count words and characters in filename"
ABORT 0
FI
_NW = 0
_NC = 0
RETURN
; Count number of words in line
TKH = TOKNEW(L, " ")
NTK = TOKNUM(TKH)
; Add to NC the number of characters in each word
FOR CurTok = 1 TO NTK
ADD(@NC, STRLEN(TOKGET(TKH, CurTok)))
NEXT
TOKFREE(TKH)
ADD(@NW, NTK)
; Print totals at the end
FUNCTION ONEND()
PRINTLN "Statistics for file: " _F
PRINTLN "Size: " _S
PRINTLN "Number of non-blanks: " _NC " (" \
PFORMAT("2.2f", MUL(FDIV(_NC, _S), 100)) "%)"
PRINTLN "Number of lines: " _N
PRINTLN "Number of words: " _NW
RETURN