summaryrefslogtreecommitdiff
path: root/ipl/procs/filedim.icn
diff options
context:
space:
mode:
Diffstat (limited to 'ipl/procs/filedim.icn')
-rw-r--r--ipl/procs/filedim.icn45
1 files changed, 45 insertions, 0 deletions
diff --git a/ipl/procs/filedim.icn b/ipl/procs/filedim.icn
new file mode 100644
index 0000000..561e347
--- /dev/null
+++ b/ipl/procs/filedim.icn
@@ -0,0 +1,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