home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / euphor10.zip / LINES.EX < prev    next >
Text File  |  1993-05-18  |  2KB  |  61 lines

  1. -- lines.e
  2. -- show how many lines and characters there are in a file or bunch of files
  3. -- usage: lines.bat files...
  4. -- example: lines *.e
  5. constant SCREEN = 1
  6. constant TRUE = 1
  7.  
  8. function scan(integer fileNum) 
  9. -- count lines, non-blank lines, characters
  10.     object line
  11.     integer lines, nb_lines, chars
  12.  
  13.     lines = 0
  14.     nb_lines = 0
  15.     chars = 0
  16.     while TRUE do
  17.     line = gets(fileNum)
  18.     if atom(line) then
  19.         return {nb_lines, lines, chars} -- end of file
  20.     else
  21.         lines = lines + 1
  22.         chars = chars + length(line) + 1 -- add 1 to match dir cmd
  23.         if find(TRUE, line != ' ' and line != '\t' and line != '\n') then
  24.         nb_lines = nb_lines + 1
  25.         end if
  26.     end if
  27.     end while
  28. end function
  29.  
  30. include getnames.e
  31.  
  32. procedure lines()
  33. -- process all files 
  34.     integer fileNum
  35.     sequence count, total_count
  36.     sequence file_names
  37.  
  38.     -- gather file names
  39.     file_names = get_names()
  40.  
  41.     -- process all files    
  42.     total_count = {0, 0, 0}
  43.     puts(1, "non-blank-lines   lines   chars\n")
  44.     for i = 1 to length(file_names) do
  45.         fileNum = open(file_names[i], "r")   
  46.         if fileNum = -1 then
  47.             printf(SCREEN, "cannot open %s\n", {file_names[i]})
  48.         else
  49.         count = scan(fileNum)
  50.         total_count = total_count + count
  51.         printf(SCREEN, "       %8d%8d%8d %s\n", count & {file_names[i]})
  52.         close(fileNum)
  53.         end if
  54.     end for
  55.     if length(file_names) > 1 then
  56.     printf(SCREEN, "       %8d%8d%8d total\n", total_count)
  57.     end if
  58. end procedure
  59.  
  60. lines()
  61.