home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / DSHL11.ZIP / WORDCNT.CMD < prev   
OS/2 REXX Batch file  |  1991-12-09  |  2KB  |  91 lines

  1. /*--------------------------------------------------*/
  2. /*  Wordcnt -   Text File Word and Line Counter     */
  3. /*  (C) Copyright 1991 Frank V. Castellucci         */
  4. /*  All Rights Reserved                             */
  5. /*                                                  */
  6. /*  $Source: g:/rexxapps/RCS/wordcnt.cmd $          */
  7. /*  $Revision: 1.4 $                                */
  8. /*--------------------------------------------------*/
  9. parse upper arg FileName;
  10.  
  11. result = 'ffff'x;
  12.  
  13. if(FileName <> "") then do
  14.     if(stream(FileName,'c','query exist') <> "") then do
  15.         result = LcAndWc(FileName);
  16.         end
  17.     end
  18.     
  19. else do
  20.     r=charout(,"0d0a"x"[Enter file name]: ")
  21.     parse value linein() with FileName
  22.     if(stream(FileName,'c','query exist') <> "") then do
  23.         result = LcAndWc(FileName);
  24.         end
  25.     end
  26.     
  27. if(result = 'ffff'x) then do
  28.     r=lineout(,"Invalid or non-existant filename entered");
  29.     end
  30.     
  31. exit
  32.  
  33. /*  Line and word counting procedure    */
  34.  
  35. LcAndWc: procedure
  36. fname = Arg(1);
  37.  
  38. r=lineout(,'Opening 'fname);
  39.  
  40. state = stream(fname,'c','open read');
  41.  
  42. if(state = 'READY:') then do
  43.     wc=0;
  44.     lc=0;
  45.     
  46.     do while ( lines(fname) )
  47.         c = charout(,'.');
  48.         lc = lc+1;
  49.         cc=0;dc=1;
  50.         
  51.         bigstring = linein(fname);
  52.         dummy = bigstring;    
  53.         
  54.         
  55.         do while(dummy <> "")
  56.             dummy = subword(bigstring,dc,1);
  57.             
  58.             if(dummy <> "" & datatype(dummy,'m')) then do
  59.                 cc = cc+1;
  60.                 end
  61.                 
  62.             dc = dc+1;    
  63.             end
  64.             
  65.         wc = wc + cc;
  66.         end
  67.         
  68.     r=lineout(," ");
  69.     r=lineout(,LEFT('File',20) "Words   Lines");
  70.     r=lineout(,LEFT(fname,20)   wc'     'lc);
  71.     state = stream(infname,'c','close');
  72.     end
  73.     
  74. else do
  75.     r=lineout(,'Unable to open file' infname' for reading.');
  76.     r=lineout(,stream(infname,'d'));
  77.     r=lineout(,stream(infname,'s'));
  78.     end
  79.     
  80. return 0;
  81.  
  82. /*
  83. $Log:    wordcnt.cmd $
  84. Revision 1.4  91/12/09  02:09:25  FJC
  85. Added '.' feedback for each line read from file.
  86.  
  87. Revision 1.3  91/12/08  19:51:47  FJC
  88. Corrected couting summary and output positioning
  89.  
  90. */
  91.