mif-table.prl
6.53 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/local/bin/perl5 -w
#
# Copyright (C) 1996-1998 by the Board of Trustees
# of Leland Stanford Junior University.
#
# This file is part of the SimOS distribution.
# See LICENSE file for terms of the license.
#
###
### Documentation
###
# Basically the input to this script is a file with the table described
# as perl data structures. There are four global variables you need to define.
#
# mifTable - an associative array of table attributes
# tableFormat - the name of the maker table format
# cols - the number of columns
# caption - the caption for the table
#
# The following three variables are arrays of associatve arrays. In mifCol
# there is an element for each column. Each element is an associative array
# describing the columns attributes. In mifHeaderCell and mifBodyCell
# there is an element for each cell. These arrays are one dimensional and
# are listed in row major order. Each element is an associative array
# describing the cells attributes.
#
# mifCol - array of associative arrays of:
# width - the width of the column in inches
#
# mifHeaderCell - array of <cell description>
#
# mifBodyCell - array of <cell description>
#
# <cell description> - associative array of:
# text - the text of the cell
# bold - 1 means bold
# alignment - (Left, Center, Right)
# angle - angle in degrees of text
# rowStraddle - the number of rows to straddle
# colStraddle - the number of columns to straddle
# leftBorder - <ruling description>
# rightBorder - <ruling description>
# bottomBorder - <ruling description>
# topBorder - <ruling description>
#
# <ruling description> - (Thin, Thick, Double, None, Very Thin, Medium)
###
### Code
###
# need to avoid errors
$mifCol[0] = 0;
$mifBodyCell[0]{'text'} = "";
$mifHeaderCell[0]{'text'} = "";
# include user table definition
$ARGV[0] || die "Need a file to input!\n";
do $ARGV[0];
###
### MIF header
###
$format = (defined($mifTable{"tableFormat"})) ? $mifTable{"tableFormat"} : "Format A";
print STDOUT "<MIFFile 4.0>\n";
print STDOUT "<Tbls\n";
print STDOUT " <Tbl\n";
print STDOUT " <TblID 1>\n";
print STDOUT " <TblTag `$format'>\n";
###
### column info
###
defined($mifTable{"cols"}) ||
die "You need to specify the number of columns!\n";
print STDOUT " <TblNumColumns ", $mifTable{"cols"}, ">\n";
foreach $i (0..($mifTable{"cols"}-1)) {
print STDOUT " <TblColumnWidth $mifCol[$i]{'width'}\">\n";
}
###
### table title
###
if (defined($mifTable{'caption'})) {
print STDOUT " <TblTitleContent\n";
print STDOUT " <Para\n";
print STDOUT " <PgfTag `TableTitle'>\n";
print STDOUT " <ParaLine\n";
print STDOUT " <String `$mifTable{'caption'}'>\n";
print STDOUT " >\n";
print STDOUT " >\n";
print STDOUT " >\n";
}
###
### header cells
###
doCellArray(\@mifHeaderCell, "TblH", "CellHeading");
###
### body cells
###
doCellArray(\@mifBodyCell, "TblBody", "CellBody");
###
### table footer
###
print STDOUT " >\n";
print STDOUT ">\n";
###
### table reference
###
print STDOUT "<Para\n";
print STDOUT " <PgfTag `Body'>\n";
print STDOUT " <ParaLine\n";
print STDOUT " <String `Table1#'>\n";
print STDOUT " <ATbl 1>\n";
print STDOUT " <String `#'>\n";
print STDOUT " >\n";
print STDOUT ">\n";
exit;
sub doCellArray {
my($cellArrayRef, $cellType, $cellParaTag) = @_;
print STDOUT " <$cellType\n";
$cell = 0;
while ($cell < $#$cellArrayRef) {
print STDOUT " <Row\n";
foreach $i (0..($mifTable{"cols"}-1)) {
print STDOUT " <Cell\n";
$rows = $cellArrayRef->[$cell]{"rowStraddle"};
if (defined($rows) && ($rows != 1)) {
print STDOUT " <CellRows $rows>\n";
}
$cols = $cellArrayRef->[$cell]{"colStraddle"};
if (defined($cols) && ($cols != 1)) {
print STDOUT " <CellColumns $cols>\n";
}
$angle = $cellArrayRef->[$cell]{"angle"};
if (defined($angle)) {
print STDOUT " <CellAngle $angle>\n";
}
$lborder = $cellArrayRef->[$cell]{"leftBorder"};
if (defined($lborder)) {
print STDOUT " <CellLRuling `$lborder'>\n";
}
$rborder = $cellArrayRef->[$cell]{"rightBorder"};
if (defined($rborder)) {
print STDOUT " <CellRRuling `$rborder'>\n";
}
$bborder = $cellArrayRef->[$cell]{"bottomBorder"};
if (defined($bborder)) {
print STDOUT " <CellBRuling `$bborder'>\n";
}
$tborder = $cellArrayRef->[$cell]{"topBorder"};
if (defined($tborder)) {
print STDOUT " <CellTRuling `$tborder'>\n";
}
$text = $cellArrayRef->[$cell]{"text"};
if (defined($text)) {
print STDOUT " <CellContent\n";
print STDOUT " <Para\n";
print STDOUT " <PgfTag `$cellParaTag'>\n";
$align = $cellArrayRef->[$cell]{'alignment'};
$bold = $cellArrayRef->[$cell]{'bold'};
if (defined($align) || defined($bold)) {
print STDOUT " <Pgf\n";
if (defined($align)) {
print STDOUT " <PgfAlignment $align>\n";
}
if (defined($bold) && $bold) {
print STDOUT " <PgfFont <FWeight `Bold'>>\n";
}
print STDOUT " >\n";
}
print STDOUT " <ParaLine\n";
print STDOUT " <String `$text'>\n";
print STDOUT " >\n";
print STDOUT " >\n";
print STDOUT " >\n";
}
print STDOUT " >\n";
$cell++;
}
print STDOUT " >\n";
}
print STDOUT " >\n";
}