home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga MA Magazine 1998 #6
/
amigamamagazinepolishissue1998.iso
/
coders
/
arexx
/
misc_arexx
/
txtstat.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1997-03-30
|
2KB
|
153 lines
/*
Text stats v1.2 by Fini 'Warp' Alring ©Sun Nov 10 15:05:29 1996
Note: Big files are very TIME consuming, b'coz of potensially raise...?
Purpose: To count different words, and write a stat-file in ram.
Could be rewritten for use with a Wordprocessor etc...
*/
Parse arg Filename CASE
If ~exists(Filename) | Filename = '' then do
Say Filename 'could not be located...'
exit(1)
end
Call Time('R')
Call Open('INDATA',Filename,'R')
Say 'Reading file.'
Data. = ''
i = 0
if Upper(Case)='NOCASE' then do while EOF(INDATA) = 0
i = i + 1
Data.i = ReadLN(INDATA)
end
else do while EOF(INDATA) = 0
i = i + 1
Data.i = Upper(ReadLN(INDATA))
end
/* ^- Read lines from source into Data.i */
Say 'Processing words: (· = One processed line.)'
NumberofLines = i
FWords = 0
Words. = ''
Occur. = 0
do L = 1 to NumberofLines
Call WriteCH(STDOUT,'·')
do W = 1 to Words(Data.L)
Cword = TABstrip(Word(Data.L,W))
N = Lookup(Cword)
If N>0 then do
Occur.N = Occur.N + 1
end
else do
Fwords = Fwords + 1
Occur.Fwords = Occur.Fwords + 1
Words.Fwords = Cword
end
end
end
say ''
say 'Writing Stat-file: RAM:Txtstat.txt'
Call Open('OUTDATA','RAM:Txtstat0.txt','W')
/*
call Writeln(OUTDATA,'Different words in 'Filename' = 'Fwords)
*/
do i = 1 to Fwords
Call writeln(OUTDATA,Words.i' 'Occur.i)
end
Call Close(OUTDATA)
Say 'Sorting list...'
Address command "C:SORT RAM:txtstat0.txt Ram:TXTstat.txt"
Address command "C:Delete RAM:txtstat0.txt quiet"
Call Open('OUTDATA','RAM:Txtstat.txt','A')
Call Seek(OUTDATA,0,'B')
Call WriteLN(OUTDATA,'Different words in 'Filename' = 'Fwords)
Say 'Done... Program ending......Secs elapsed: 'Time('E')
exit(0)
/* Funcs() - Begin */
Add: Procedure
Parse arg V, I
V = V + I
Return V
Lookup: Procedure Expose Words. Fwords
Parse arg Word
Do W = 1 to Fwords
If word = Words.W then return W
End
Return 0
TABstrip: Procedure
Parse Arg W
B = 0
do i = 1 to length(W)
if left(W,i-B) = ' ' then do
W = right(W,Length(W)-1)
B = B + 1
end
end
return W