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
|
# 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
|