home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / arexx / misc_arexx / txtstat.rexx < prev    next >
OS/2 REXX Batch file  |  1997-03-30  |  2KB  |  153 lines

  1. /* 
  2.  
  3.      Text stats v1.2 by Fini 'Warp' Alring ©Sun Nov 10 15:05:29 1996 
  4.  
  5.  
  6.   Note: Big files are very TIME consuming, b'coz of potensially raise...?
  7.  
  8.  
  9.  
  10.  Purpose: To count different words, and write a stat-file in ram. 
  11.  
  12.  Could be rewritten for use with a Wordprocessor etc...
  13.  
  14.  
  15. */
  16.  
  17.  
  18.  
  19.  
  20. Parse arg Filename CASE
  21.  
  22. If ~exists(Filename) | Filename = '' then do
  23.     Say Filename 'could not be located...'
  24.     exit(1)
  25. end
  26.  
  27. Call Time('R')
  28.  
  29. Call Open('INDATA',Filename,'R')
  30.  
  31. Say 'Reading file.'
  32.  
  33. Data. = ''
  34. i = 0
  35.  
  36. if Upper(Case)='NOCASE' then do while EOF(INDATA) = 0
  37.     i = i + 1
  38.     Data.i = ReadLN(INDATA)
  39. end
  40. else do  while EOF(INDATA) = 0
  41.     i = i + 1
  42.     Data.i = Upper(ReadLN(INDATA))
  43. end
  44. /* ^- Read lines from source into Data.i */
  45.  
  46. Say 'Processing words:  (· = One processed line.)'
  47.  
  48. NumberofLines = i
  49. FWords = 0
  50. Words. = ''
  51. Occur. = 0
  52.  
  53. do L = 1 to NumberofLines 
  54.  
  55.     Call WriteCH(STDOUT,'·')
  56.  
  57.     do W = 1 to Words(Data.L)    
  58.     
  59.         Cword = TABstrip(Word(Data.L,W))
  60.     
  61.         N = Lookup(Cword)
  62.     
  63.         If N>0 then do
  64.         
  65.             Occur.N = Occur.N + 1
  66.         
  67.         end
  68.         else do
  69.         
  70.             Fwords = Fwords + 1
  71.             Occur.Fwords = Occur.Fwords + 1
  72.             Words.Fwords = Cword 
  73.         
  74.         end
  75.     
  76.     end
  77.  
  78. end
  79.  
  80. say ''
  81. say 'Writing Stat-file: RAM:Txtstat.txt'
  82.  
  83. Call Open('OUTDATA','RAM:Txtstat0.txt','W')
  84. /*
  85. call Writeln(OUTDATA,'Different words in 'Filename' = 'Fwords)
  86. */
  87. do i = 1 to Fwords
  88.     Call writeln(OUTDATA,Words.i' 'Occur.i)
  89. end
  90.  
  91. Call Close(OUTDATA)
  92.  
  93. Say 'Sorting list...'
  94. Address command "C:SORT RAM:txtstat0.txt Ram:TXTstat.txt"
  95. Address command "C:Delete RAM:txtstat0.txt quiet"
  96.  
  97.  
  98. Call Open('OUTDATA','RAM:Txtstat.txt','A')
  99.  
  100.  
  101. Call Seek(OUTDATA,0,'B')
  102. Call WriteLN(OUTDATA,'Different words in 'Filename' = 'Fwords)
  103.  
  104. Say 'Done... Program ending......Secs elapsed: 'Time('E')
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115. exit(0)
  116.  
  117.  
  118.  
  119. /* Funcs() - Begin */
  120.  
  121.  
  122.  
  123.  
  124.  
  125. Add: Procedure 
  126.     Parse arg V, I
  127.     V = V + I
  128. Return V
  129.  
  130.  
  131.  
  132. Lookup: Procedure Expose Words. Fwords
  133.     Parse arg Word
  134.  
  135.     Do W = 1 to Fwords
  136.         If word = Words.W then return W
  137.     End
  138.  
  139. Return 0
  140.  
  141.  
  142. TABstrip: Procedure
  143.     Parse Arg W
  144.     B = 0
  145.     do i = 1 to length(W)
  146.     
  147.         if left(W,i-B) = '    ' then do
  148.         
  149.             W = right(W,Length(W)-1)
  150.             B = B + 1
  151.         end
  152.     end
  153. return W