| 1 |
/* |
| 2 |
* The Regina Rexx Interpreter |
| 3 |
* Copyright (C) 1992 Anders Christensen <[email protected]> |
| 4 |
* |
| 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. |
| 9 |
* |
| 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. |
| 14 |
* |
| 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. |
| 18 |
*/ |
| 19 |
|
| 20 |
/* |
| 21 |
* Tests the functionality of functions |
| 22 |
*/ |
| 23 |
|
| 24 |
written = 0 |
| 25 |
|
| 26 |
/*========= test recursivity in arguments ==============*/ |
| 27 |
call notify 'arguments' |
| 28 |
call ch echoargs( echoarg(1), echoarg(2) ), "1 2" |
| 29 |
|
| 30 |
|
| 31 |
call notify 'comments' |
| 32 |
call ch echoargs( 'foo' ), 'foo' /* can't take comment before "(" */ |
| 33 |
|
| 34 |
|
| 35 |
call notify 'nullargs' |
| 36 |
call ch echoargs( 1, 2, , 4, , , 7 ), '1 2 4 7' |
| 37 |
call ch echoargs( 1, 2, ), '1 2' |
| 38 |
call ch echoargs( 1, 2,, ), '1 2' |
| 39 |
call ch echoargs( , 2,, ), ' 2' |
| 40 |
|
| 41 |
|
| 42 |
call notify 'labels' |
| 43 |
call ch foobar(), 'foo' |
| 44 |
|
| 45 |
|
| 46 |
call notify 'external' |
| 47 |
signal on notready |
| 48 |
call stream 'testfile', 'c', 'close' |
| 49 |
'rm -f testfile' |
| 50 |
file = 'testfile' |
| 51 |
call lineout file, 'if (arg(1)=0) then' |
| 52 |
call lineout file, ' return 0' |
| 53 |
call lineout file, 'else' |
| 54 |
call lineout file, ' return 1+"'file'"(arg(1)-1)' |
| 55 |
call lineout file |
| 56 |
|
| 57 |
result = 'testfile'( 4,5,6 ) |
| 58 |
call ch result, 4 |
| 59 |
|
| 60 |
|
| 61 |
call notify 'result' |
| 62 |
result = 'marker' |
| 63 |
junk = echoarg( 'foo' ) |
| 64 |
call ch result, 'marker' |
| 65 |
|
| 66 |
call echoarg 'foo' |
| 67 |
call ch result, 'foo' |
| 68 |
|
| 69 |
|
| 70 |
call notify 'builtin' |
| 71 |
call ch 'CENTER'('X',5), ' X ' /* is builtin uppercase? */ |
| 72 |
/* call ch center('X',5), '5-X-5' /* internal before builtin? */ */ |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
call notify 'whole' |
| 77 |
call ch left( 'foobar', 3.0 ), 'foo' |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
signal afterargs |
| 82 |
|
| 83 |
center: |
| 84 |
return arg(2) || '-' || arg(1) || '-' || arg(2) |
| 85 |
|
| 86 |
|
| 87 |
echoargs: |
| 88 |
do i=1 to arg() |
| 89 |
if i=1 then |
| 90 |
result = arg(1) |
| 91 |
else |
| 92 |
result = result arg(i) |
| 93 |
end |
| 94 |
return result |
| 95 |
|
| 96 |
echoarg: |
| 97 |
return arg(1) |
| 98 |
|
| 99 |
|
| 100 |
foobar: |
| 101 |
return 'foo' |
| 102 |
|
| 103 |
foobar: |
| 104 |
return 'bar' |
| 105 |
|
| 106 |
afterargs: |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
say ' ' |
| 112 |
exit 0 |
| 113 |
|
| 114 |
|
| 115 |
ch: procedure expose sigl |
| 116 |
parse arg first, second |
| 117 |
if first ^== second then do |
| 118 |
say |
| 119 |
say 'first = /'first'/' |
| 120 |
say 'second = /'second'/' |
| 121 |
say "FuncTrip: error in " sigl":" sourceline(sigl) ; end |
| 122 |
return |
| 123 |
|
| 124 |
|
| 125 |
notify: |
| 126 |
parse arg word . |
| 127 |
written = written + length(word) + 2 |
| 128 |
if written>75 then do |
| 129 |
written = length(word) |
| 130 |
say ' ' |
| 131 |
end |
| 132 |
call charout , word || ', ' |
| 133 |
return |
| 134 |
|
| 135 |
|
| 136 |
error: |
| 137 |
say 'Error discovered in function insert()' |
| 138 |
return |
| 139 |
|