aboutsummaryrefslogtreecommitdiff
path: root/sys/fmtio/strtbl.x
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /sys/fmtio/strtbl.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'sys/fmtio/strtbl.x')
-rw-r--r--sys/fmtio/strtbl.x81
1 files changed, 81 insertions, 0 deletions
diff --git a/sys/fmtio/strtbl.x b/sys/fmtio/strtbl.x
new file mode 100644
index 00000000..7ec0205d
--- /dev/null
+++ b/sys/fmtio/strtbl.x
@@ -0,0 +1,81 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+# STRTBL -- Print a list of strings on the named file. If NCOL is zero,
+# the maximum number of columns is calculated based on the maximum
+# string length. If NCOL is nonzero, it is taken to be the maximum
+# number of columns (the actual number may be less, depending on the
+# maximum string length). FIRST_COL and LAST_COL define where on the
+# page the table will be placed.
+
+procedure strtbl (fd, buf, strp, nstr, first_col, last_col, maxch, ncol)
+
+int fd # output file
+char buf[ARB] # buffer containing the strings
+int strp[ARB] # array of string pointers
+int nstr # number of strings
+int first_col, last_col # where to place table on a line
+int maxch # maximum chars to print from a string
+int ncol # desired number of columns (0 to autoscale)
+
+pointer sp, obuf, op
+int row, i, j, p, nspaces, maxlen, colwidth, numcol, numrow, str
+int strlen()
+
+begin
+ call smark (sp)
+ call salloc (obuf, last_col + 1, TY_CHAR)
+
+ maxlen = 0
+ do i = 1, nstr
+ maxlen = max (maxlen, strlen(buf[strp[i]]))
+ if (maxch > 0)
+ maxlen = min (maxch, maxlen)
+ numcol = max (1, (last_col - first_col + 1) / (maxlen + 2))
+
+ if (ncol > 0)
+ numcol = min (numcol, ncol)
+ colwidth = (last_col - first_col + 1) / numcol
+ numrow = (nstr + numcol-1) / numcol
+
+ # For each row in the table:
+ do row = 1, numrow {
+ op = obuf
+
+ # Space to the first column.
+ do i = 2, first_col {
+ Memc[op] = ' '
+ op = op + 1
+ }
+
+ # For each string in the row:
+ do i = 1, numcol {
+ str = row + (i-1) * numrow
+ if (str > nstr)
+ next
+ p = strp[str]
+
+ # Output the string.
+ for (j=0; buf[p+j] != EOS && j < maxlen; j=j+1) {
+ Memc[op] = buf[p+j]
+ op = op + 1
+ }
+
+ # Advance to the next column.
+ if (i < numcol) {
+ nspaces = max (2, colwidth - j)
+ for (j=1; j <= nspaces; j=j+1) {
+ Memc[op] = ' '
+ op = op + 1
+ }
+ }
+ }
+
+ # Terminate this row of the table.
+ Memc[op] = '\n'
+ op = op + 1
+ Memc[op] = EOS
+ call putline (fd, Memc[obuf])
+ }
+
+ call sfree (sp)
+end