home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / isize.icn < prev    next >
Text File  |  2002-01-24  |  2KB  |  84 lines

  1. ############################################################################
  2. #
  3. #    File:     isize.icn
  4. #
  5. #    Subject:  Program to measure size of an Icon program
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     May 11, 1999
  10. #
  11. ############################################################################
  12. #
  13. #  This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program give several measures of the size of an Icon program.
  18. #  The name of the program is given on the command line.
  19. #
  20. #  The command line option -t produces tab-separated values without
  21. #  labeling instead of multipl labeled lines.
  22. #
  23. ############################################################################
  24. #
  25. #  UNIX and the itokens meta-translator
  26. #
  27. ############################################################################
  28. #
  29. #  Links:  numbers, options
  30. #
  31. ############################################################################
  32.  
  33. link numbers
  34. link options
  35.  
  36. $define Col 15
  37.  
  38. procedure main(args)
  39.    local chaff, code, line, cbytes, nbytes, input, tokens, opts, format
  40.  
  41.    opts := options(args, "t")
  42.    format := opts["t"]
  43.  
  44.    input := open(args[1]) | stop("*** cannot open file")
  45.  
  46.    cbytes := nbytes := code := chaff := 0
  47.  
  48.    while line := read(input) do {
  49.       line ? {
  50.          tab(many(' \t'))
  51.          if ="#" | pos(0) then {
  52.             chaff +:= 1
  53.             nbytes +:= *line + 1
  54.             }
  55.          else {
  56.             code +:= 1
  57.             cbytes +:= *line + 1
  58.             }
  59.          }
  60.       }
  61.  
  62.    input := open("itokens " || args[1], "p")
  63.    tokens := read(input)
  64.  
  65.    if /format then {
  66.       write(left("bytes:", Col), right(cbytes + nbytes, 6))
  67.       write(left("lines:", Col), right(code + chaff, 6))
  68.       write(left("tokens:", Col), right(tokens, 6))
  69.       write(left("% code lines", Col + 2), fix(100 * code, code + chaff, 7, 2))
  70.       write(left("bytes/token:", Col + 2), fix(cbytes, tokens, 7, 2))
  71.       write(left("tokens/code line:", Col + 2), fix(tokens, code, 7, 2))
  72.       }
  73.    else {
  74.       writes(cbytes + nbytes, "\t")
  75.       writes(code + chaff, "\t")
  76.       writes(tokens, "\t")
  77.       writes(fix(100 * code, code + chaff, 7, 2), "\t")
  78.       writes(fix(cbytes, tokens, 7, 2), "\t")
  79.       writes(fix(tokens, code, 7, 2))
  80.       write()
  81.       }
  82.  
  83. end
  84.