Debian Codegraph @

gcc/testsuite/gm2/projects/pim/run/pass/random/WriteMap.mod

raw
1 (* Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
2 Free Software Foundation, Inc. *)
3 (* This file is part of Chisel.
4
5 Chisel is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 3, or (at your option) any later
8 version.
9
10 Chisel is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with gm2; see the file COPYING. If not, write to the Free Software
17 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
18
19 IMPLEMENTATION MODULE WriteMap ;
20
21
22 FROM DynamicStrings IMPORT String, EqualArray ;
23 FROM RoomMap IMPORT MaxNoOfRooms, Rooms, DoorStatus ;
24 FROM NumberIO IMPORT CardToStr ;
25
26 IMPORT FIO ;
27 IMPORT SFIO ;
28
29
30 VAR
31 outfile: FIO.File ;
32
33
34 (*
35 SetOutputFile - set the output file to, name.
36 *)
37
38 PROCEDURE SetOutputFile (name: String) ;
39 BEGIN
40 IF EqualArray (name, '-')
41 THEN
42 outfile := FIO.StdOut
43 ELSE
44 outfile := SFIO.OpenToWrite(name)
45 END
46 END SetOutputFile ;
47
48
49 (*
50 WriteCard -
51 *)
52
53 PROCEDURE WriteCard (c, n: CARDINAL) ;
54 VAR
55 a: ARRAY [0..50] OF CHAR ;
56 BEGIN
57 CardToStr(c, n, a) ;
58 WriteString(a)
59 END WriteCard ;
60
61
62 (*
63 WriteString -
64 *)
65
66 PROCEDURE WriteString (a: ARRAY OF CHAR) ;
67 BEGIN
68 FIO.WriteString(outfile, a)
69 END WriteString ;
70
71
72 (*
73 WriteLn -
74 *)
75
76 PROCEDURE WriteLn ;
77 BEGIN
78 FIO.WriteLine(outfile)
79 END WriteLn ;
80
81
82 (*
83 WriteMapText - writes out the map in textual form.
84 *)
85
86 PROCEDURE WriteMapText ;
87 VAR
88 i: CARDINAL ;
89 BEGIN
90 MakeRoomNumbers ;
91 FOR i := 1 TO MaxNoOfRooms DO
92 IF RoomExists(i)
93 THEN
94 WriteRoom(i)
95 END
96 END ;
97 WriteString('END.') ; WriteLn ; FIO.Close(outfile)
98 END WriteMapText ;
99
100
101 (*
102 MakeRoomNumbers - makes room numbers for the rooms that exist.
103 *)
104
105 PROCEDURE MakeRoomNumbers ;
106 VAR
107 i, j: CARDINAL ;
108 BEGIN
109 j := 1 ;
110 FOR i := 1 TO MaxNoOfRooms DO
111 IF RoomExists(i)
112 THEN
113 Rooms[i].RoomNo := j ;
114 INC(j)
115 END
116 END
117 END MakeRoomNumbers ;
118
119
120 (*
121 WriteRoom - writes out the room coordinates.
122 *)
123
124 PROCEDURE WriteRoom (r: CARDINAL) ;
125 VAR
126 i: CARDINAL ;
127 BEGIN
128 WITH Rooms[r] DO
129 WriteString('ROOM') ; WriteCard(RoomNo, 4) ; WriteLn ;
130 WriteString('WALL') ; WriteLn ;
131 FOR i := 1 TO NoOfWalls DO
132 WITH Walls[i] DO
133 WriteCard(X1, 8) ; WriteCard(Y1, 4) ;
134 WriteCard(X2, 4) ; WriteCard(Y2, 4) ; WriteLn
135 END
136 END ;
137 FOR i := 1 TO NoOfDoors DO
138 WriteString('DOOR') ;
139 WITH Doors[i] DO
140 WITH Position DO
141 WriteCard(X1, 4) ; WriteCard(Y1, 4) ;
142 WriteCard(X2, 4) ; WriteCard(Y2, 4)
143 END ;
144 WriteString(' STATUS ') ;
145 WriteStatus(StateOfDoor) ;
146 WriteString(' LEADS TO') ;
147 WriteCard(Rooms[LeadsTo].RoomNo, 4) ; WriteLn
148 END
149 END ;
150 WriteString('END') ; WriteLn
151 END
152 END WriteRoom ;
153
154
155 (*
156 WriteStatus - writes the status of a door.
157 *)
158
159 PROCEDURE WriteStatus (s: DoorStatus) ;
160 BEGIN
161 CASE s OF
162
163 Open : WriteString('OPEN ') |
164 Closed : WriteString('CLOSED') |
165 Secret : WriteString('SECRET')
166
167 ELSE
168 HALT
169 END
170 END WriteStatus ;
171
172
173 (*
174 RoomExists - returns true if a room exists.
175 *)
176
177 PROCEDURE RoomExists (r: CARDINAL) : BOOLEAN ;
178 BEGIN
179 RETURN( Rooms[r].RoomNo#0 )
180 END RoomExists ;
181
182
183 BEGIN
184 outfile := FIO.StdOut
185 END WriteMap.