summaryrefslogtreecommitdiff
path: root/ipl/progs/isize.icn
blob: ba26f45a158365e3065c47687d38630c9b9c4346 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
############################################################################
#
#	File:     isize.icn
#
#	Subject:  Program to measure size of an Icon program
#
#	Author:   Ralph E. Griswold
#
#	Date:     May 11, 1999
#
############################################################################
#
#  This file is in the public domain.
#
############################################################################
#
#  This program give several measures of the size of an Icon program.
#  The name of the program is given on the command line.
#
#  The command line option -t produces tab-separated values without
#  labeling instead of multipl labeled lines.
#
############################################################################
#
#  UNIX and the itokens meta-translator
#
############################################################################
#
#  Links:  numbers, options
#
############################################################################

link numbers
link options

$define Col 15

procedure main(args)
   local chaff, code, line, cbytes, nbytes, input, tokens, opts, format

   opts := options(args, "t")
   format := opts["t"]

   input := open(args[1]) | stop("*** cannot open file")

   cbytes := nbytes := code := chaff := 0

   while line := read(input) do {
      line ? {
         tab(many(' \t'))
         if ="#" | pos(0) then {
            chaff +:= 1
            nbytes +:= *line + 1
            }
         else {
            code +:= 1
            cbytes +:= *line + 1
            }
         }
      }

   input := open("itokens " || args[1], "p")
   tokens := read(input)

   if /format then {
      write(left("bytes:", Col), right(cbytes + nbytes, 6))
      write(left("lines:", Col), right(code + chaff, 6))
      write(left("tokens:", Col), right(tokens, 6))
      write(left("% code lines", Col + 2), fix(100 * code, code + chaff, 7, 2))
      write(left("bytes/token:", Col + 2), fix(cbytes, tokens, 7, 2))
      write(left("tokens/code line:", Col + 2), fix(tokens, code, 7, 2))
      }
   else {
      writes(cbytes + nbytes, "\t")
      writes(code + chaff, "\t")
      writes(tokens, "\t")
      writes(fix(100 * code, code + chaff, 7, 2), "\t")
      writes(fix(cbytes, tokens, 7, 2), "\t")
      writes(fix(tokens, code, 7, 2))
      write()
      }

end