/* NetRexx ************************************************************ * 22.05.2013 Walter Pachl translated from REXX **********************************************************************/ options replace format comments java crossref symbols nobinary parse arg dsn . if dsn = '' then dsn = 'test.txt' cnt=0 totChars=0 /*count of the total num of chars*/ totLetters=0 /*count of the total num letters.*/ indent=' '.left(20) /*used for indentation of output.*/ lines = scanFile(dsn) loop l_ = 1 to lines[0] line = lines[l_] Say '>'line'<' line.length /* that's in test.txt */ /* lrx=left_right(line) Parse lrx leftx rightx Say ' 'leftx Say ' 'rightx */ loop k=1 for line.length() /*loop over characters */ totChars=totChars+1 /*Increment total number of chars*/ c=line.substr(k,1) /*get character number k */ cnt[c]=cnt[c]+1 /*increment the character's count*/ End end l_ w=totChars.length /*used for right-aligning counts.*/ say 'file -----' dsn "----- has" lines[0] 'records.' say 'file -----' dsn "----- has" totChars 'characters.' Loop L=0 to 255 /* display nonzero letter counts */ c=l.d2c /* the character in question */ if cnt[c]>0 & c.datatype('M')>0 Then Do /* was found in the file */ /* and is a latin letter */ say indent "(Latin) letter " c 'count:' cnt[c].right(w) /* tell */ totLetters=totLetters+cnt[c] /* increment number of letters */ End End say 'file -----' dsn "----- has" totLetters '(Latin) letters.' say ' other charactes follow' other=0 loop m=0 to 255 /* now for non-letters */ c=m.d2c /* the character in question */ y=c.c2x /* the hex representation */ if cnt[c]>0 & c.datatype('M')=0 Then Do /* was found in the file */ /* and is not a latin letter */ other=other+cnt[c] /* increment count */ _=cnt[c].right(w) /* prepare output of count */ select /*make the character viewable. */ when c<<' ' | m==255 then say indent "'"y"'x character count:" _ when c==' ' then say indent "blank character count:" _ otherwise say indent " " c 'character count:' _ end end end say 'file -----' dsn "----- has" other 'other characters.' say 'file -----' dsn "----- has" totLetters 'letters.' -- Read a file and return contents as a Rexx indexed string method scanFile(dsn) public static returns Rexx fileLines = '' do inFile = File(dsn) inFileScanner = Scanner(inFile) loop l_ = 1 while inFileScanner.hasNext() fileLines[0] = l_ fileLines[l_] = inFileScanner.nextLine() end l_ inFileScanner.close() catch ex = FileNotFoundException ex.printStackTrace end return fileLines