/*
** Word-Count-File.ced
**
** $VER: Word-Count-File.ced 1.0.1 (27.04.93)
**
** This script counts the number of words in the currently loaded
** file.
**
** This script requires CygnusEd Professional v3.5 (or later) to run.
**
** Copyright © 1990-1993 ASDG, Incorporated  All Rights Reserved
*/


OPTIONS RESULTS


NL = '0A'X

CEDTOFRONT
OKAY2 "This is not a particularly fast way of counting" || NL ||,
	"words, but it does work.  Do you really want to" || NL ||,
	"do this?"
IF (RESULT = 0) THEN DO
	CEDTOFRONT
	OKAY1 "Word Count Aborted"
	EXIT 10
END

BEG OF FILE

STATUS NUMLINES
NumberOfLines = RESULT
WordCount = 0
i = 1

DO WHILE (i <= NumberOfLines)
	STATUS LINEBUFFER
	WordCount = WordCount + WORDS( RESULT )
	DOWN
	i = i + 1
	LASTKEY
	/* Check for a keystroke (~= -1) which is not an key release (< 128) */
	IF (RESULT ~= -1) & (WORD( RESULT, 1 ) < 128) THEN DO
		CEDTOFRONT
		OKAY1 "Word Count Aborted"
		EXIT 10
	END
	DM "Hitting any key will abort the word count.  Line "i", word "WordCount"."
END
DM ""

IF (NumberOfLines = 1) THEN
	LineString = "Line"
ELSE
	LineString = "Lines"

CEDTOFRONT
OKAY1 "Counted" WordCount "Words In" NumberOfLines LineString

EXIT 0
