5b560b834bcd65282afeda615c01ee7a7417e842
[beyond-the-titanic.git] / src / ROOMRITE.PAS
1 {//-------------------------------------------------------------------------}\r
2 {/*                                                                         }\r
3 {Copyright (C) 2014 Jason Self <j@jxself.org>                               }\r
4 {                                                                           }\r
5 {This file is free software: you may copy, redistribute and/or modify it    }\r
6 {under the terms of the GNU Affero General Public License as published by   }\r
7 {the Free Software Foundation, either version 3 of the License, or (at your }\r
8 {option) any later version.                                                 }\r
9 {                                                                           }\r
10 {This file is distributed in the hope that it will be useful, but WITHOUT   }\r
11 {ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      }\r
12 {FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License}\r
13 {for more details.                                                          }\r
14 {                                                                           }\r
15 {You should have received a copy of the GNU Affero General Public License   }\r
16 {along with this program; if not, see https://gnu.org/licenses or write to: }\r
17 {  Free Software Foundation, Inc.                                           }\r
18 {  51 Franklin Street, Fifth Floor                                          }\r
19 {  Boston, MA 02110-1301                                                    }\r
20 {  USA                                                                      }\r
21 {                                                                           }\r
22 {This file incorporates work covered by the following copyright and         }\r
23 {permission notice:                                                         }\r
24 {                                                                           }\r
25 {Copyright (C) 1990, 2009 - Apogee Software, Ltd.                           }\r
26 {                                                                           }\r
27 {This file is part of Beyond The Titanic. Beyond The Titanic is free        }\r
28 {software; you can redistribute it and/or modify it under the terms of the  }\r
29 {GNU General Public License as published by the Free Software Foundation;   }\r
30 {either version 3 of the License, or (at your option) any later version.    }\r
31 {                                                                           }\r
32 {This program is distributed in the hope that it will be useful, but WITHOUT}\r
33 {ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      }\r
34 {FITNESS FOR A PARTICULAR PURPOSE.                                          }\r
35 {                                                                           }\r
36 {See the GNU General Public License for more details.                       }\r
37 {                                                                           }\r
38 {You should have received a copy of the GNU General Public License          }\r
39 {along with this program; if not, write to:                                 }\r
40 {  Free Software Foundation, Inc.                                           }\r
41 {  51 Franklin Street, Fifth Floor                                          }\r
42 {  Boston, MA 02110-1301                                                    }\r
43 {  USA                                                                      }\r
44 {                                                                           }\r
45 {Original Source: 1990 Scott Miller                                         }\r
46 {Prepared for public release: 03/19/09 - Joe Siegler, Apogee Software, Ltd. }\r
47 {*/                                                                         }\r
48 {//-------------------------------------------------------------------------}\r
49 program\r
50   Room_Write;\r
51 \r
52     {This program WRITES and READS from the two text files: 'rooms1' and\r
53      'rooms2'.  If a description exceeds 240 letters (Max), then the file\r
54                'rooms2' is used.  Otherwise 'rooms2' = ''.}\r
55                  {This program has the line edit feature!}\r
56 \r
57 uses Crt, Printer;\r
58 \r
59 const\r
60   Max = 240;\r
61 \r
62 type\r
63   DescriptionLength = string[Max];\r
64   ManyChar = string[1];\r
65 \r
66 var\r
67   Rooms1, Rooms2 : file of descriptionlength;\r
68   Position,Counter,Start,Stop : integer;\r
69   Text1, Text2 : descriptionlength;\r
70   Answer : char;\r
71   Letter : manychar;\r
72   List   : boolean;\r
73 \r
74 procedure Diskwrite(text1,text2: Descriptionlength; pointer: integer);\r
75   begin\r
76     seek(rooms1,pointer); seek(rooms2,pointer);\r
77     WRITE(rooms1,text1); WRITE(rooms2,text2);\r
78     writeln('Room description ',pointer,\r
79             ' is written!  Size = ',filesize(rooms1));\r
80     close(rooms1); close(rooms2);\r
81   end; {End of Diskwrite.}\r
82 \r
83 procedure Diskread(start,stop: integer);\r
84 var\r
85 counter : integer;\r
86 text1, text2 : descriptionlength;\r
87   begin\r
88    assign(rooms1,'ROOMS1');\r
89    assign(rooms2,'ROOMS2');\r
90    reset(rooms1);\r
91    reset(rooms2);\r
92    seek(rooms1,start);\r
93    seek(rooms2,start);\r
94     for counter:= start to stop do\r
95       begin\r
96         highvideo;\r
97         READ(rooms1,text1); READ(rooms2,text2);\r
98         if list then\r
99           begin\r
100             writeln(lst,'Description # ',counter);\r
101             writeln(lst,text1,text2);\r
102           end\r
103         else\r
104           begin\r
105             writeln('Here is room description # ',counter);\r
106             lowvideo;\r
107             writeln(text1,text2);\r
108             highvideo;\r
109           end;\r
110       end;\r
111     write('The file contains ',FileSize(rooms1),' room descriptions.');\r
112     close(rooms1); close(rooms2);\r
113   end;  {End of Diskread.}\r
114 \r
115 procedure Beep;\r
116 begin\r
117  if(length(text1)in[70,150,230])or(length(text2)in[70,150,230])then write(^g);\r
118 end;\r
119 \r
120 BEGIN\r
121 repeat          {Main loop.}\r
122   text1:='';\r
123   text2:='';\r
124 \r
125 writeln;\r
126 writeln('Do you want to R)ead or W)rite?');\r
127 readln(answer);\r
128 if upcase(answer) <> 'R' then       {Write to 'Rooms'.}\r
129     begin\r
130       writeln;writeln;\r
131       assign(rooms1,'ROOMS1'); assign(rooms2,'ROOMS2');\r
132       writeln('Now RESETing room files.');\r
133             RESET(rooms1); RESET(rooms2);\r
134       writeln;\r
135       writeln('Input a string not more than ',2*Max,' characters.',\r
136               '  ''\''-Ends string.');\r
137       lowvideo;\r
138         repeat\r
139           letter := ReadKey;\r
140           write(letter);\r
141           if letter = ^h then\r
142             begin\r
143               write(' ', ^h);\r
144               delete(text1,length(text1),1);\r
145 \r
146             end;\r
147           beep;\r
148           if (letter <> '\') and (letter <> ^h) then text1:=text1+letter;\r
149         until (length(text1)=Max) or (letter='\');\r
150         writeln;\r
151         if letter = '\' then\r
152           begin\r
153             highvideo;\r
154             writeln('Total of ',length(text1),' characters.');\r
155             text2:='';\r
156           end\r
157         else\r
158           begin\r
159             writeln;\r
160             highvideo;\r
161             writeln('String #1 is full!  Now writing to string #2.',^g);\r
162             lowvideo;\r
163               repeat\r
164                 letter := ReadKey;\r
165                 write(letter);\r
166                 if letter = ^h then\r
167                   begin\r
168                     write(' ',^h);\r
169                     delete(text2,length(text2),1);\r
170                   end;\r
171                 beep;\r
172                 if (letter <> '\') and (letter <> ^h) then text2:=text2+letter\r
173               until (length(text2)=Max) or (letter='\');\r
174             writeln; highvideo;\r
175             writeln('Total description length = ',\r
176                      length(text1)+length(text2),' characters.');\r
177           end;\r
178       writeln('Now WRITING string to disk.');\r
179       writeln('  At what position?  (Next open is # ',filesize(rooms1),')');\r
180       readln(position);\r
181       Diskwrite(text1,text2,position);\r
182     end\r
183 else                      {Read from 'Rooms'.}\r
184   begin\r
185     writeln;writeln;\r
186     writeln('To the S)creen or the P)rinter');\r
187     readln(answer);\r
188     if(upcase(answer)='P')then List:=True else List:=False;\r
189     assign(rooms1,'ROOMS1');\r
190     reset(rooms1);\r
191     writeln('Filesize = ',filesize(rooms1),\r
192             '  (From 0 to ',filesize(rooms1)-1,')');\r
193     // close(rooms1);\r
194     writeln('Enter starting position:');\r
195     readln(start);\r
196     writeln('Evo filesize rooms1: ');\r
197     writeln(filesize(rooms1));\r
198 \r
199     if(start > filesize(rooms1)-5)then stop:=(filesize(rooms1)-1) else\r
200       begin\r
201         writeln('Enter final position:');\r
202         readln(stop);\r
203       end;\r
204     Diskread(start,stop);\r
205   end;  {End of else clause.}\r
206 writeln;\r
207 writeln('Another room description?  Y)es or N)o');\r
208 read(answer);\r
209 until upcase(answer) = 'N';     {End of Main loop.}\r
210 writeln; writeln(^g,'You are now out of the program.')\r
211 END.\r