fix remapping behavior. Remapping is only necessary if we are rendering on the workbe...
[AROS-Contrib.git] / regina / trip / stack.rexx
blob83f8f54bf417a454fe91a78c52a50fbd8ccc4f27
1 /*
2 * The Regina Rexx Interpreter
3 * Copyright (C) 1992 Anders Christensen <anders@solan.unit.no>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /* testing the implementation of the stack */
21 trace o
22 written = 0
23 options MAKEBUF_BIF DROPBUF_BIF DESBUF_BIF
25 /* first check PUSH */
26 call notify 'push'
27 push 'first'
28 push 'second'
29 pull one
30 pull two
32 if (one^=="SECOND") | (two^=="FIRST") then
33 call complain 'The PUSH statement does not work'
35 call notify 'queue'
36 queue 'first'
37 queue 'second'
38 pull one
39 pull two
41 if (one^=="FIRST") | (two^=="SECOND") then
42 call complain 'The QUEUE statement does not work'
44 queue
45 push
46 pull one
47 pull two
49 if (one^=='') | (two^=="") then
50 call complain 'Either QUEUE or PUSH do not stack empty lines'
52 /* the queued() function */
53 call notify 'queued'
54 call ch queued(), 0
55 push 'one'
56 call ch queued(), 1
57 push 'two'
58 queue 'three'
59 call ch queued(), 3
61 parse pull first
62 call ch first, 'two'
63 parse pull second
64 call ch second, 'one'
65 parse pull third
66 call ch third, 'three'
67 call ch queued(), 0
69 push 'one'
70 push 'two'
71 call makebuf
72 push 'three'
73 call ch queued(), 3
74 push 'four'
75 call makebuf
76 call ch queued(), 4
77 push 'five'
79 call dropbuf
80 call ch queued(), 4
81 call dropbuf
82 call ch queued(), 2
83 call dropbuf
84 call ch queued(), 0
85 call dropbuf
86 call ch queued(), 0
90 call notify 'commands'
92 address system
94 /*----- Let's see if it can pipe the stack ----------------------------*/
96 queue 'To be or not to be'
97 'LIFO> tr abcdefghijkl ABCDEFGHIJKL >LIFO'
99 parse pull line
100 if line^=='To BE or not to BE' then
101 call complain 'Can not pipe the stack-contents through a command'
103 queue 'To be or not to be'
104 Address System 'tr abcdefghijkl ABCDEFGHIJKL' With Input LIFO '' Output LIFO ''
106 parse pull line
107 if line^=='To BE or not to BE' then
108 call complain 'Can not pipe the stack-contents through a command using ANSI extensions'
110 /*----- does it clear the stack when command just read a few lines ----*/
111 queue 'asdf asdf'
112 queue 'zxcv zxcv'
113 queue 'tyui tyui'
114 queue 'ghjk ghjk'
116 'LIFO> head -2 | wc >LIFO'
117 if queued()^=='1' then
118 call complain 'Commands does not clear stack'
120 parse pull lines words chars .
121 if lines words chars^=='2 4 20' then
122 call complain 'Something is incorrect in the stack'
124 queue 'asdf asdf'
125 queue 'zxcv zxcv'
126 queue 'tyui tyui'
127 queue 'ghjk ghjk'
129 Address System 'head -2 | wc' With Input LIFO '' Output LIFO ''
130 if queued()^=='1' then
131 call complain 'Commands does not clear stack using ANSI extensions'
133 parse pull lines words chars .
134 if lines words chars^=='2 4 20' then
135 call complain 'Something is incorrect in the stack using ANSI extensions'
137 /*----- let's see if it really send it through system(3) ---------------*/
138 /* sorry, too many machines don't set the USER environment variable. */
140 address system
142 'whoami >LIFO'
143 'echo $USER >LIFO'
144 parse pull myself .
145 parse pull alsome .
146 if myself^==alsome then
147 call complain 'Command did not resolve environment variable'
150 /*----- let's take it for some heavy piping ----------------------------*/
151 signal next_test
152 dict_words = '/usr/dict/words'
153 if ^stream(dict_words, 'c', 'readable') then do
154 'man sh > /tmp/dict 2>/dev/null'
155 'man csh >> /tmp/dict 2>/dev/null'
156 'man vi >> /tmp/dict 2>/dev/null'
157 'cat /tmp/dict | tr -cs ''a-zA-z0-9'' '' '' | sort -u > /tmp/dict_words'
158 dict_words = '/tmp/dict_words'
161 words = 'wc'('-l dict_words')
162 'cat' dict_words '>LIFO'
163 if words != queued() then
164 call complain 'Could not get all short lines to the stack'
166 'LIFO> cat >LIFO'
167 if words != queued() then
168 call complain 'Could not correctly run short lines on the stack'
170 'LIFO> sort -0.3 >LIFO'
171 if words != queued() then
172 call complain 'Could not correctly "rotate" short lines on the stack'
174 'LIFO> wc -l >LIFO'
175 if queued() != 1 then
176 call complain 'Could not flush short lines into the stack'
178 parse pull lines .
179 if words != lines then
180 call complain 'Not all short lines flushed got through'
182 /*----- then, let's try the same thing with some longer lines ----------*/
183 oldtrace = trace()
184 trace off
185 'awk "BEGIN{while(1){print \"yes\"};}"' copies('X',10) '| head -10000 >LIFO'
186 trace oldtrace
187 if queued()!=10000 then
188 call complain 'Could not put 10000 lines to the stack'
190 'LIFO> cat >LIFO'
191 if queued() != 10000 then
192 call complain 'Could not run long lines through cat'
194 'LIFO> sort >FIFO'
195 if queued() != 10000 then
196 call complain 'Could not rotate long lines on the stack'
198 'LIFO> wc -l >LIFO'
199 if queued() != 1 then
200 call complain 'Could not flush long stack to program'
202 next_test:
203 /*----- The nullstring is a valid command ------------------------------*/
205 * This is kind of hard to check, but at least we can try to send a
206 * nullstring as a command, and try to catch any errors that might
207 * occur from it.
209 call notify 'empty command'
213 /* The setting of RC variable checked in signal.rexx */
217 call notify 'buffers'
219 * try to check the performance of buffers. However, this is
220 * specific to some implementations
222 do queued() ; pull ; end /* just in case ... */
224 res = makebuf() makebuf() makebuf()
225 if res \== '1 2 3' then
226 call complain 'MAKEBUF does not return correct return value'
229 res = dropbuf() dropbuf() dropbuf() dropbuf() dropbuf()
230 if res \= '2 1 0 0 0' then
231 call complain 'DROPBUF does not return correct return value'
234 push 'second'
235 push 'third'
236 call makebuf
237 push 'fourth'
238 call dropbuf
239 parse pull line1
240 parse pull line2
241 if line1\='third' | line2\='second' then
242 call complain 'DROPBUF kills line below the buffer'
244 call makebuf
245 push 'first'
246 call makebuf
247 push 'second'
248 parse pull line1
249 parse pull line2
250 brc = makebuf()
251 if line1\='second' | line2\='first' | brc\='2' then
252 call complain 'Reading lines doesn''t remove buffers'
254 call desbuf
255 push 'first'
256 push 'second'
257 res= dropbuf()
258 if queued()>0 | res\=0 then
259 call complain 'DROPBUF does not remove ''zeroth'' buffer'
262 call desbuf
263 call makebuf
264 call makebuf
265 push 'first'
266 call makebuf
267 push 'second'
268 call makebuf
269 push 'third'
270 call makebuf
271 call makebuf
272 res = dropbuf(-3)
273 parse pull line
274 if res\=3 | line\='second' then
275 call complain 'DROPBUF with negative argument did not work'
277 call desbuf
278 push 'first'
279 call makebuf
280 push 'second'
281 res = dropbuf(0)
282 if queued()\=0 | res\=0 then
283 call complain 'DROPBUF with zero argument didn''t clear stack'
287 say ''
288 exit 0
291 ch: procedure expose sigl
292 parse arg first, second
293 if first ^== second then do
295 say "first= /"first"/"
296 say "second=/"second"/"
297 say "FuncTrip: error in " sigl":" sourceline(sigl) ; end
298 return
301 notify:
302 parse arg word
303 written = written + length(word) + 2
304 if written>75 then do
305 written = length(word)
306 say ' '
308 call charout , word || ', '
309 return
312 error:
313 say 'Error discovered in function insert()'
314 return
317 complain:
318 say ' ...'
319 say 'Tripped in line' sigl':' arg(1)'.'
320 length = charout(,' (')
321 return