3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "mem/slicc/generator/mif_gen.hh"
36 #include "mem/slicc/symbols/State.hh"
37 #include "mem/slicc/symbols/Event.hh"
38 #include "mem/slicc/symbols/Action.hh"
39 #include "mem/slicc/symbols/Transition.hh"
41 // -- Helper functions
42 string
formatShorthand(const string shorthand
);
43 string
formatCellRuling(const string shorthand
);
45 void printStateTableMIF(const StateMachine
& sm
, ostream
& out
)
47 const string mif_prolog1
=
48 "<MIFFile 5.50> # Generated by Multifacet MIF Mungers Inc\n\
52 <TblTag `Format A'>\n\
55 <TblAlignment Center>\n\
57 # <TblXColumnNum 0>\n\
58 <TblXColumnRuling `Medium'>\n\
60 <TblLRuling `Medium'>\n\
61 <TblRRuling `Medium'>\n\
62 <TblTRuling `Medium'>\n\
63 <TblBRuling `Medium'>\n\
67 <TblColumnWidth 0.51\">\n\
69 <PgfTag `CellHeading'>\n\
70 > # end of TblColumnH\n\
72 <PgfTag `CellBody'>\n\
73 > # end of TblColumnBody\n\
75 <PgfTag `CellHeading'>\n\
76 > # end of TblColumnF\n\
77 > # end of TblColumn\n\
80 <TblColumnWidth 0.51\">\n\
82 <PgfTag `CellHeading'>\n\
83 > # end of TblColumnH\n\
85 <PgfTag `CellBody'>\n\
86 > # end of TblColumnBody\n\
88 <PgfTag `CellHeading'>\n\
89 > # end of TblColumnF\n\
90 > # end of TblColumn\n\
91 > # end of TblFormat\n\
94 <TblColumnWidth 0.51\">\n\
95 <TblColumnWidth 6.00\">\n\
99 <PgfTag `TableTitle'>\n\
101 <PgfAlignment Center>\n\
106 <FWeight `Regular'>\n\
107 <FAngle `Regular'>\n\
108 <FPostScriptName `Times-Roman'>\n\
109 <FEncoding `FrameRoman'>\n\
111 <FUnderlining FNoUnderlining>\n\
120 <FPosition FNormal>\n\
125 <FLanguage USEnglish>\n\
129 > # end of PgfFont\n\
131 <PgfNumString `TABLE 1. '>\n\
135 <MTypeName `Cross-Ref'>\n\
140 const string mif_prolog2
=
142 > # end of ParaLine\n\
144 > # end of TblTitleContent\n\
145 > # end of TblTitle\n\
149 <RowMaxHeight 14.0\">\n\
150 <RowHeight 0.44444\">\n\
152 <CellLRuling `Medium'>\n\
153 <CellBRuling `Medium'>\n\
154 <CellRRuling `Medium'>\n\
155 <CellTRuling `Medium'>\n\
158 <PgfTag `CellHeading'>\n\
160 <PgfAlignment Center>\n\
165 <FWeight `Regular'>\n\
166 <FAngle `Regular'>\n\
167 <FPostScriptName `Times-Roman'>\n\
168 <FEncoding `FrameRoman'>\n\
170 <FUnderlining FNoUnderlining>\n\
179 <FPosition FNormal>\n\
184 <FLanguage USEnglish>\n\
188 > # end of PgfFont\n\
192 > # end of ParaLine\n\
194 > # end of CellContent\n\
197 <CellLRuling `Medium'>\n\
198 <CellBRuling `Medium'>\n\
199 <CellRRuling `Medium'>\n\
200 <CellTRuling `Medium'>\n\
203 <PgfTag `CellHeading'>\n\
208 <FWeight `Regular'>\n\
209 <FAngle `Regular'>\n\
210 <FPostScriptName `Times-Roman'>\n\
211 <FEncoding `FrameRoman'>\n\
213 <FUnderlining FNoUnderlining>\n\
222 <FPosition FNormal>\n\
227 <FLanguage USEnglish>\n\
231 > # end of PgfFont\n\
233 <String `Description'>\n\
234 > # end of ParaLine\n\
236 > # end of CellContent\n\
244 const string row_before_state
=
246 <RowMaxHeight 14.0\">\n\
247 <RowHeight 0.22222\">\n\
251 <PgfTag `CellBody'>\n\
253 <PgfAlignment Center>\n\
258 <FWeight `Regular'>\n\
259 <FAngle `Regular'>\n\
260 <FPostScriptName `Times-Roman'>\n\
261 <FEncoding `FrameRoman'>\n\
263 <FUnderlining FNoUnderlining>\n\
272 <FPosition FNormal>\n\
277 <FLanguage USEnglish>\n\
281 > # end of PgfFont\n\
286 const string row_between_state_desc
=
288 > # end of ParaLine\n\
290 > # end of CellContent\n\
295 <PgfTag `CellBody'>\n\
299 const string row_after_desc
=
301 > # end of ParaLine\n\
303 > # end of CellContent\n\
308 const string mif_epilog
=
309 " > # end of TblBody\n\
316 > # end of ParaLine\n\
323 out
<< formatShorthand( sm
.getShorthand() );
327 for( int i
= 0; i
< sm
.numStates(); i
++ )
329 out
<< row_before_state
;
330 out
<< formatShorthand( sm
.getState( i
).getShorthand() );
331 out
<< row_between_state_desc
;
332 out
<< sm
.getState( i
).getDescription();
333 out
<< row_after_desc
;
340 void printEventTableMIF(const StateMachine
& sm
, ostream
& out
)
342 const string mif_prolog1
=
343 "<MIFFile 5.50> # Generated by Multifacet MIF Mungers Inc\n\
347 <TblTag `Format A'>\n\
350 <TblAlignment Center>\n\
352 # <TblXColumnNum 0>\n\
353 <TblXColumnRuling `Medium'>\n\
355 <TblLRuling `Medium'>\n\
356 <TblRRuling `Medium'>\n\
357 <TblTRuling `Medium'>\n\
358 <TblBRuling `Medium'>\n\
362 <TblColumnWidth 0.51\">\n\
364 <PgfTag `CellHeading'>\n\
365 > # end of TblColumnH\n\
367 <PgfTag `CellBody'>\n\
368 > # end of TblColumnBody\n\
370 <PgfTag `CellHeading'>\n\
371 > # end of TblColumnF\n\
372 > # end of TblColumn\n\
375 <TblColumnWidth 0.51\">\n\
377 <PgfTag `CellHeading'>\n\
378 > # end of TblColumnH\n\
380 <PgfTag `CellBody'>\n\
381 > # end of TblColumnBody\n\
383 <PgfTag `CellHeading'>\n\
384 > # end of TblColumnF\n\
385 > # end of TblColumn\n\
386 > # end of TblFormat\n\
389 <TblColumnWidth 0.51\">\n\
390 <TblColumnWidth 6.00\">\n\
394 <PgfTag `TableTitle'>\n\
396 <PgfAlignment Center>\n\
401 <FWeight `Regular'>\n\
402 <FAngle `Regular'>\n\
403 <FPostScriptName `Times-Roman'>\n\
404 <FEncoding `FrameRoman'>\n\
406 <FUnderlining FNoUnderlining>\n\
415 <FPosition FNormal>\n\
420 <FLanguage USEnglish>\n\
424 > # end of PgfFont\n\
426 <PgfNumString `TABLE 1. '>\n\
430 <MTypeName `Cross-Ref'>\n\
434 const string mif_prolog2
=
436 > # end of ParaLine\n\
438 > # end of TblTitleContent\n\
439 > # end of TblTitle\n\
443 <RowMaxHeight 14.0\">\n\
444 <RowHeight 0.44444\">\n\
446 <CellLRuling `Medium'>\n\
447 <CellBRuling `Medium'>\n\
448 <CellRRuling `Medium'>\n\
449 <CellTRuling `Medium'>\n\
452 <PgfTag `CellHeading'>\n\
457 <FWeight `Regular'>\n\
458 <FAngle `Regular'>\n\
459 <FPostScriptName `Times-Roman'>\n\
460 <FEncoding `FrameRoman'>\n\
462 <FUnderlining FNoUnderlining>\n\
471 <FPosition FNormal>\n\
476 <FLanguage USEnglish>\n\
480 > # end of PgfFont\n\
482 <PgfAlignment Center>\n\
487 <FWeight `Regular'>\n\
488 <FAngle `Regular'>\n\
489 <FPostScriptName `Times-Roman'>\n\
490 <FEncoding `FrameRoman'>\n\
492 <FUnderlining FNoUnderlining>\n\
501 <FPosition FNormal>\n\
506 <FLanguage USEnglish>\n\
510 > # end of PgfFont\n\
514 > # end of ParaLine\n\
516 > # end of CellContent\n\
519 <CellLRuling `Medium'>\n\
520 <CellBRuling `Medium'>\n\
521 <CellRRuling `Medium'>\n\
522 <CellTRuling `Medium'>\n\
525 <PgfTag `CellHeading'>\n\
527 <String `Description'>\n\
528 > # end of ParaLine\n\
530 > # end of CellContent\n\
538 const string row_before_event
=
540 <RowMaxHeight 14.0\">\n\
541 <RowHeight 0.22222\">\n\
545 <PgfTag `CellBody'>\n\
547 <PgfAlignment Center>\n\
552 <FWeight `Regular'>\n\
553 <FAngle `Regular'>\n\
554 <FPostScriptName `Times-Roman'>\n\
555 <FEncoding `FrameRoman'>\n\
557 <FUnderlining FNoUnderlining>\n\
566 <FPosition FNormal>\n\
571 <FLanguage USEnglish>\n\
575 > # end of PgfFont\n\
580 const string row_between_event_desc
=
582 > # end of ParaLine\n\
584 > # end of CellContent\n\
589 <PgfTag `CellBody'>\n\
593 const string row_after_desc
=
595 > # end of ParaLine\n\
597 > # end of CellContent\n\
602 const string mif_epilog
=
603 " > # end of TblBody\n\
610 > # end of ParaLine\n\
617 out
<< formatShorthand( sm
.getShorthand() );
621 for( int i
= 0; i
< sm
.numEvents(); i
++ )
623 out
<< row_before_event
;
624 out
<< formatShorthand( sm
.getEvent( i
).getShorthand() );
625 out
<< row_between_event_desc
;
626 out
<< sm
.getEvent( i
).getDescription();
627 out
<< row_after_desc
;
634 void printActionTableMIF(const StateMachine
& sm
, ostream
& out
)
636 const string mif_prolog1
=
637 "<MIFFile 5.50> # Generated by Multifacet MIF Mungers Inc\n\
641 <TblTag `Format A'>\n\
644 <TblAlignment Center>\n\
646 # <TblXColumnNum 0>\n\
647 <TblXColumnRuling `Medium'>\n\
649 <TblLRuling `Medium'>\n\
650 <TblRRuling `Medium'>\n\
651 <TblTRuling `Medium'>\n\
652 <TblBRuling `Medium'>\n\
656 <TblColumnWidth 0.51\">\n\
658 <PgfTag `CellHeading'>\n\
659 > # end of TblColumnH\n\
661 <PgfTag `CellBody'>\n\
662 > # end of TblColumnBody\n\
664 <PgfTag `CellHeading'>\n\
665 > # end of TblColumnF\n\
666 > # end of TblColumn\n\
669 <TblColumnWidth 0.51\">\n\
671 <PgfTag `CellHeading'>\n\
672 > # end of TblColumnH\n\
674 <PgfTag `CellBody'>\n\
675 > # end of TblColumnBody\n\
677 <PgfTag `CellHeading'>\n\
678 > # end of TblColumnF\n\
679 > # end of TblColumn\n\
680 > # end of TblFormat\n\
683 <TblColumnWidth 0.51\">\n\
684 <TblColumnWidth 6.00\">\n\
688 <PgfTag `TableTitle'>\n\
690 <PgfAlignment Center>\n\
695 <FWeight `Regular'>\n\
696 <FAngle `Regular'>\n\
697 <FPostScriptName `Times-Roman'>\n\
698 <FEncoding `FrameRoman'>\n\
700 <FUnderlining FNoUnderlining>\n\
709 <FPosition FNormal>\n\
714 <FLanguage USEnglish>\n\
718 > # end of PgfFont\n\
720 <PgfNumString `TABLE 1. '>\n\
724 <MTypeName `Cross-Ref'>\n\
728 const string mif_prolog2
=
730 > # end of ParaLine\n\
732 > # end of TblTitleContent\n\
733 > # end of TblTitle\n\
737 <RowMaxHeight 14.0\">\n\
738 <RowHeight 0.44444\">\n\
740 <CellLRuling `Medium'>\n\
741 <CellBRuling `Medium'>\n\
742 <CellRRuling `Medium'>\n\
743 <CellTRuling `Medium'>\n\
746 <PgfTag `CellHeading'>\n\
748 <PgfAlignment Center>\n\
753 <FWeight `Regular'>\n\
754 <FAngle `Regular'>\n\
755 <FPostScriptName `Times-Roman'>\n\
756 <FEncoding `FrameRoman'>\n\
758 <FUnderlining FNoUnderlining>\n\
767 <FPosition FNormal>\n\
772 <FLanguage USEnglish>\n\
776 > # end of PgfFont\n\
780 > # end of ParaLine\n\
782 > # end of CellContent\n\
785 <CellLRuling `Medium'>\n\
786 <CellBRuling `Medium'>\n\
787 <CellRRuling `Medium'>\n\
788 <CellTRuling `Medium'>\n\
791 <PgfTag `CellHeading'>\n\
793 <String `Description'>\n\
794 > # end of ParaLine\n\
796 > # end of CellContent\n\
804 const string row_before_action
=
806 <RowMaxHeight 14.0\">\n\
807 <RowHeight 0.22222\">\n\
811 <PgfTag `CellBody'>\n\
813 <PgfAlignment Center>\n\
818 <FWeight `Regular'>\n\
819 <FAngle `Regular'>\n\
820 <FPostScriptName `Times-Roman'>\n\
821 <FEncoding `FrameRoman'>\n\
823 <FUnderlining FNoUnderlining>\n\
832 <FPosition FNormal>\n\
837 <FLanguage USEnglish>\n\
841 > # end of PgfFont\n\
846 const string row_between_action_desc
=
848 > # end of ParaLine\n\
850 > # end of CellContent\n\
855 <PgfTag `CellBody'>\n\
859 const string row_after_desc
=
861 > # end of ParaLine\n\
863 > # end of CellContent\n\
868 const string mif_epilog
=
869 " > # end of TblBody\n\
876 > # end of ParaLine\n\
883 out
<< formatShorthand( sm
.getShorthand() );
887 for( int i
= 0; i
< sm
.numActions(); i
++ )
889 out
<< row_before_action
;
890 out
<< formatShorthand( sm
.getAction( i
).getShorthand() );
891 out
<< row_between_action_desc
;
892 out
<< sm
.getAction( i
).getDescription();
893 out
<< row_after_desc
;
900 void printTransitionTableMIF(const StateMachine
& sm
, ostream
& out
)
902 const string mif_prolog
=
903 "<MIFFile 5.50> # Generated by Multifacet MIF Mungers Inc\n\
907 <TblTag `Format A'>\n\
910 <TblAlignment Center>\n\
912 # <TblXColumnNum 0>\n\
913 <TblXColumnRuling `Medium'>\n\
915 <TblLRuling `Medium'>\n\
916 <TblRRuling `Medium'>\n\
917 <TblTRuling `Medium'>\n\
918 <TblBRuling `Medium'>\n\
922 const string tbl_fmt_before_col_num
=
926 const string tbl_fmt_after_col_num
=
928 <TblColumnWidth 0.51\">\n\
930 <PgfTag `CellHeading'>\n\
931 > # end of TblColumnH\n\
933 <PgfTag `CellBody'>\n\
934 > # end of TblColumnBody\n\
936 <PgfTag `CellHeading'>\n\
937 > # end of TblColumnF\n\
938 > # end of TblColumn\n\
941 const string tbl_fmt_before_num_cols
=
942 " > # end of TblFormat\n\
946 const string tbl_fmt_each_col_width_begin
=
950 const string tbl_fmt_each_col_width_end
= "\"";
952 const string tbl_before_first_header1
=
957 <PgfTag `TableTitle'>\n\
959 <PgfAlignment Center>\n\
964 <FWeight `Regular'>\n\
965 <FAngle `Regular'>\n\
966 <FPostScriptName `Times-Roman'>\n\
967 <FEncoding `FrameRoman'>\n\
969 <FUnderlining FNoUnderlining>\n\
978 <FPosition FNormal>\n\
983 <FLanguage USEnglish>\n\
987 > # end of PgfFont\n\
989 <PgfNumString `TABLE 1. '>\n\
993 <MTypeName `Cross-Ref'>\n\
998 const string tbl_before_first_header2
=
1000 > # end of ParaLine\n\
1002 > # end of TblTitleContent\n\
1003 > # end of TblTitle\n\
1007 <RowMaxHeight 14.0\">\n\
1008 <RowHeight 0.44444\">";
1010 const string tbl_before_each_header
=
1012 <CellLRuling `Medium'>\n\
1013 <CellBRuling `Medium'>\n\
1014 <CellRRuling `Medium'>\n\
1015 <CellTRuling `Medium'>\n\
1018 <PgfTag `CellHeading'>\n\
1020 <PgfAlignment Center>\n\
1023 <FFamily `Times'>\n\
1025 <FWeight `Regular'>\n\
1026 <FAngle `Regular'>\n\
1027 <FPostScriptName `Times-Roman'>\n\
1028 <FEncoding `FrameRoman'>\n\
1030 <FUnderlining FNoUnderlining>\n\
1039 <FPosition FNormal>\n\
1043 <FStretch 100.0%>\n\
1044 <FLanguage USEnglish>\n\
1048 > # end of PgfFont\n\
1053 const string tbl_before_each_rot_header
=
1055 <CellLRuling `Medium'>\n\
1056 <CellBRuling `Medium'>\n\
1057 <CellRRuling `Medium'>\n\
1058 <CellTRuling `Medium'>\n\
1062 <PgfTag `CellHeading'>\n\
1066 const string tbl_after_each_header
=
1068 > # end of ParaLine\n\
1070 > # end of CellContent\n\
1074 const string before_first_row
=
1081 const string row_before_first_cell
=
1083 <RowMaxHeight 14.0\">\n\
1084 <RowHeight 0.22222\">";
1086 const string row_cell_before_ruling
=
1090 const string row_cell_before_contents
=
1093 <PgfTag `CellBody'>\n\
1095 <PgfAlignment Center>\n\
1098 <FFamily `Times'>\n\
1100 <FWeight `Regular'>\n\
1101 <FAngle `Regular'>\n\
1102 <FPostScriptName `Times-Roman'>\n\
1103 <FEncoding `FrameRoman'>\n\
1105 <FUnderlining FNoUnderlining>\n\
1114 <FPosition FNormal>\n\
1118 <FStretch 100.0%>\n\
1119 <FLanguage USEnglish>\n\
1123 > # end of PgfFont\n\
1128 const string row_cell_after_contents
=
1130 > # end of ParaLine\n\
1132 > # end of CellContent\n\
1136 const string row_empty_cell
=
1138 <CellColor `Cyan'>\n\
1141 <PgfTag `CellBody'>\n\
1144 > # end of ParaLine\n\
1146 > # end of CellContent\n\
1150 const string row_after_last_cell
=
1155 const string mif_epilog
=
1156 " > # end of TblBody\n\
1163 > # end of ParaLine\n\
1169 int i
, j
, num_rows
, num_cols
;
1173 num_rows
= sm
.numStates();
1174 num_cols
= sm
.numEvents() + 1;
1179 // -- Table format (for each column)
1180 for( i
= 0; i
< num_cols
; i
++ )
1182 out
<< tbl_fmt_before_col_num
;
1184 out
<< tbl_fmt_after_col_num
;
1187 // -- Spell out width of each column
1189 // -- FIXME: make following constants into parameters
1190 const float total_table_width
= 7.5; // -- Total page width = 7.5" (portrait mode)
1191 const float min_col_width
= 0.35; // -- Min col width (for legibility)
1192 const float max_col_width
= 0.75; // -- Max col width (for aesthetics)
1195 // -- Calculate column width and clamp it within a range
1196 column_width
= total_table_width
/ num_cols
;
1197 column_width
= ((column_width
< min_col_width
)
1199 : ((column_width
> max_col_width
)
1203 out
<< tbl_fmt_before_num_cols
;
1205 for( i
= 0; i
< num_cols
; i
++ )
1207 out
<< tbl_fmt_each_col_width_begin
<< column_width
<< tbl_fmt_each_col_width_end
;
1210 // -- Column headers
1211 out
<< tbl_before_first_header1
;
1212 out
<< formatShorthand( sm
.getShorthand() );
1213 out
<< " transitions";
1214 out
<< tbl_before_first_header2
;
1216 out
<< tbl_before_each_header
;
1218 out
<< tbl_after_each_header
;
1220 for( i
= 0; i
< sm
.numEvents(); i
++ )
1222 out
<< tbl_before_each_rot_header
;
1223 out
<< formatShorthand( sm
.getEvent(i
).getShorthand() );
1224 out
<< tbl_after_each_header
;
1226 out
<< before_first_row
;
1230 for( i
= 0; i
< num_rows
; i
++ )
1233 out
<< row_before_first_cell
;
1235 // -- Figure out ruling
1236 if (sm
.getState(i
).existPair("format")) {
1237 row_ruling
= formatCellRuling( sm
.getState(i
).lookupPair("format"));
1242 // -- First column = state
1243 out
<< row_cell_before_ruling
;
1245 out
<< row_cell_before_contents
;
1246 out
<< formatShorthand( sm
.getState(i
).getShorthand() );
1247 out
<< row_cell_after_contents
;
1249 // -- One column for each event
1250 for( j
= 0; j
< sm
.numEvents(); j
++ )
1252 const Transition
* trans_ptr
= sm
.getTransPtr( i
, j
);
1254 // -- Figure out ruling
1255 if (sm
.getEvent(j
).existPair("format")) {
1256 col_ruling
= formatCellRuling(sm
.getEvent(j
).lookupPair("format"));
1261 out
<< row_cell_before_ruling
;
1265 if( trans_ptr
!= NULL
)
1270 // -- Get the actions
1271 actions
= formatShorthand( trans_ptr
->getActionShorthands() );
1273 // -- Get the next state
1274 // FIXME: should compare index, not the string
1275 if (trans_ptr
->getNextStateShorthand() !=
1276 sm
.getState(i
).getShorthand() )
1278 nextState
= formatShorthand( trans_ptr
->getNextStateShorthand() );
1284 // -- Print out "actions/next-state"
1285 out
<< row_cell_before_contents
;
1287 if ((nextState
.length() != 0) && (actions
.length() != 0)) {
1291 out
<< row_cell_after_contents
;
1295 out
<< row_empty_cell
;
1300 out
<< row_after_last_cell
;
1308 void printTBETableMIF(const StateMachine& sm, const Vector<Field>& fields, ostream& out)
1310 const string mif_prolog1 =
1311 "<MIFFile 5.50> # Generated by Multifacet MIF Mungers Inc\n\
1315 <TblTag `Format A'>\n\
1318 <TblAlignment Center>\n\
1320 # # <TblXColumnNum 0>\n\
1321 <TblXColumnRuling `Medium'>\n\
1323 <TblLRuling `Medium'>\n\
1324 <TblRRuling `Medium'>\n\
1325 <TblTRuling `Medium'>\n\
1326 <TblBRuling `Medium'>\n\
1330 <TblColumnWidth 0.51\">\n\
1332 <PgfTag `CellHeading'>\n\
1333 > # end of TblColumnH\n\
1335 <PgfTag `CellBody'>\n\
1336 > # end of TblColumnBody\n\
1338 <PgfTag `CellHeading'>\n\
1339 > # end of TblColumnF\n\
1340 > # end of TblColumn\n\
1343 <TblColumnWidth 0.51\">\n\
1345 <PgfTag `CellHeading'>\n\
1346 > # end of TblColumnH\n\
1348 <PgfTag `CellBody'>\n\
1349 > # end of TblColumnBody\n\
1351 <PgfTag `CellHeading'>\n\
1352 > # end of TblColumnF\n\
1353 > # end of TblColumn\n\
1354 > # end of TblFormat\n\
1356 <TblNumColumns 2>\n\
1357 <TblColumnWidth 0.51\">\n\
1358 <TblColumnWidth 6.00\">\n\
1362 <PgfTag `TableTitle'>\n\
1364 <PgfAlignment Center>\n\
1367 <FFamily `Times'>\n\
1369 <FWeight `Regular'>\n\
1370 <FAngle `Regular'>\n\
1371 <FPostScriptName `Times-Roman'>\n\
1372 <FEncoding `FrameRoman'>\n\
1374 <FUnderlining FNoUnderlining>\n\
1383 <FPosition FNormal>\n\
1387 <FStretch 100.0%>\n\
1388 <FLanguage USEnglish>\n\
1392 > # end of PgfFont\n\
1394 <PgfNumString `TABLE 1. '>\n\
1398 <MTypeName `Cross-Ref'>\n\
1400 > # end of Marker\n\
1403 const string mif_prolog2 =
1405 > # end of ParaLine\n\
1407 > # end of TblTitleContent\n\
1408 > # end of TblTitle\n\
1412 <RowMaxHeight 14.0\">\n\
1413 <RowHeight 0.44444\">\n\
1415 <CellLRuling `Medium'>\n\
1416 <CellBRuling `Medium'>\n\
1417 <CellRRuling `Medium'>\n\
1418 <CellTRuling `Medium'>\n\
1421 <PgfTag `CellHeading'>\n\
1423 <PgfAlignment Center>\n\
1426 <FFamily `Times'>\n\
1428 <FWeight `Regular'>\n\
1429 <FAngle `Regular'>\n\
1430 <FPostScriptName `Times-Roman'>\n\
1431 <FEncoding `FrameRoman'>\n\
1433 <FUnderlining FNoUnderlining>\n\
1442 <FPosition FNormal>\n\
1446 <FStretch 100.0%>\n\
1447 <FLanguage USEnglish>\n\
1451 > # end of PgfFont\n\
1455 > # end of ParaLine\n\
1457 > # end of CellContent\n\
1460 <CellLRuling `Medium'>\n\
1461 <CellBRuling `Medium'>\n\
1462 <CellRRuling `Medium'>\n\
1463 <CellTRuling `Medium'>\n\
1466 <PgfTag `CellHeading'>\n\
1469 <FFamily `Times'>\n\
1471 <FWeight `Regular'>\n\
1472 <FAngle `Regular'>\n\
1473 <FPostScriptName `Times-Roman'>\n\
1474 <FEncoding `FrameRoman'>\n\
1476 <FUnderlining FNoUnderlining>\n\
1485 <FPosition FNormal>\n\
1489 <FStretch 100.0%>\n\
1490 <FLanguage USEnglish>\n\
1494 > # end of PgfFont\n\
1496 <String `Description'>\n\
1497 > # end of ParaLine\n\
1499 > # end of CellContent\n\
1507 const string row_before_state =
1509 <RowMaxHeight 14.0\">\n\
1510 <RowHeight 0.22222\">\n\
1514 <PgfTag `CellBody'>\n\
1516 <PgfAlignment Center>\n\
1519 <FFamily `Times'>\n\
1521 <FWeight `Regular'>\n\
1522 <FAngle `Regular'>\n\
1523 <FPostScriptName `Times-Roman'>\n\
1524 <FEncoding `FrameRoman'>\n\
1526 <FUnderlining FNoUnderlining>\n\
1535 <FPosition FNormal>\n\
1539 <FStretch 100.0%>\n\
1540 <FLanguage USEnglish>\n\
1544 > # end of PgfFont\n\
1549 const string row_between_state_desc =
1551 > # end of ParaLine\n\
1553 > # end of CellContent\n\
1558 <PgfTag `CellBody'>\n\
1562 const string row_after_desc =
1564 > # end of ParaLine\n\
1566 > # end of CellContent\n\
1571 const string mif_epilog =
1572 " > # end of TblBody\n\
1579 > # end of ParaLine\n\
1586 out << sm.getShorthand();
1590 for( int i = 0; i < fields.size(); i++ ) {
1591 out << row_before_state;
1592 out << formatShorthand(fields[i].getShorthand());
1593 out << row_between_state_desc;
1594 out << fields[i].getDescription();
1595 out << row_after_desc;
1602 // -- Helper function to do some shorthand formatting (kludge before we
1603 // -- get the tuple attributes into the state machine language.
1604 // -- Current convention:
1605 // -- - each `_' indicates a toggle between normal mode and superscript
1606 // -- - each escaped (using `\') character indicates a letter formatted
1607 // -- using the Symbol character set. \a = alpha, \b = beta, \c = chi etc.
1608 // -- See the FrameMaker character sets manual in the Online Manuals.
1609 // -- - a `!' indicates extra stuff at the end which can be ignored (used
1610 // -- for determining cell ruling and so on)
1612 string
formatShorthand(const string shorthand
)
1614 string munged_shorthand
= "";
1615 bool mode_is_normal
= true;
1616 const string mif_superscript
= "'> <Font <FPosition FSuperscript> <FLocked No> > <String `";
1617 const string mif_normal
= "'> <Font <FPosition FNormal> <FLocked No> > <String `";
1618 const string mif_symbol
= "'> <Font <FFamily `Symbol'> <FPostScriptName `Symbol'> <FEncoding `FrameRoman'> <FLocked No> > <String `";
1619 const string mif_times
= "'> <Font <FFamily `Times'> <FPostScriptName `Times-Roman'> <FEncoding `FrameRoman'> <FLocked No> > <String `";
1622 // -- Walk over the string, processing superscript directives
1623 for( unsigned int i
= 0; i
< shorthand
.length(); i
++ )
1625 if( shorthand
[i
] == '!' )
1627 // -- Reached logical end of shorthand name
1630 else if( shorthand
[i
] == '^' )
1632 // -- Process super/subscript formatting
1634 mode_is_normal
= !mode_is_normal
;
1635 if( mode_is_normal
)
1637 // -- Back to normal mode
1638 munged_shorthand
+= mif_normal
;
1642 // -- Going to superscript mode
1643 munged_shorthand
+= mif_superscript
;
1647 else if( shorthand
[i
] == '\\' )
1649 // -- Process Symbol character set
1650 if( (i
+ 1) < shorthand
.length() )
1652 i
++; // -- Proceed to next char. Yes I know that changing the loop var is ugly!
1653 munged_shorthand
+= mif_symbol
;
1654 munged_shorthand
+= shorthand
[i
];
1655 munged_shorthand
+= mif_times
;
1659 // -- FIXME: Add line number info later
1660 cerr
<< "Encountered a `\\` without anything following it!" << endl
;
1667 // -- Pass on un-munged
1668 munged_shorthand
+= shorthand
[i
];
1671 } // -- end for all characters in shorthand
1673 // -- Do any other munging
1675 // -- Return the formatted shorthand name
1676 return munged_shorthand
;
1681 // -- Helper function to figure out where to put rules in the table (kludge before we
1682 // -- get the tuple attributes into the shorthand machine language.
1683 // -- Current convention:
1684 // -- - a `!' in the shorthand indicates the beginning of ruling information
1685 // -- - `b' => bottom of this row is ruled
1686 // -- - `r' => right of this column is ruled
1688 string
formatCellRuling( const string shorthand
)
1690 for( unsigned int i
= 0; i
< shorthand
.length(); i
++ )
1692 if( shorthand
[i
] == '!' )
1694 // -- OK, found beginning of ruling information
1695 for( unsigned int j
= i
+1; j
< shorthand
.length(); j
++ )
1697 if( shorthand
[j
] == 'b')
1699 // -- Rule the bottom
1700 return "<CellBRuling `Medium'>\n";
1702 else if( shorthand
[j
] == 'r')
1704 // -- Rule the bottom
1705 return "<CellRRuling `Medium'>\n";
1710 // -- No ruling directives recognized, return default ruling
1716 // -- No ruling information found, return default ruling