summaryrefslogtreecommitdiff
path: root/ipl/procs/filedim.icn
blob: 561e3476a5288e7d33f40c7d7afe52303305df47 (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
############################################################################
#
#	File:     filedim.icn
#
#	Subject:  Procedure to compute file dimensions
#
#	Author:   Ralph E. Griswold
#
#	Date:     April 30, 1993
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  filedim(s, p) computes the number of rows and maximum column width
#  of the file named s.  The procedure p, which defaults to detab, i
#  applied to each line.  For example, to have lines left as is, use
#
#	filedim(s, 1)
#
############################################################################

record textdim(cols, rows)

procedure filedim(s, p)
   local input, rows, cols, line

   /p := detab

   input := open(s) | stop("*** cannot open ", s)

   rows := cols := 0

   while line := p(read(input)) do {
      rows +:= 1
      cols <:= *line
      }

   close(input)

   return textdim(cols, rows)

end