This file explains, usually via sample code, some bugs that exist in
this release of Regina. The smaller this file the better!
Outstanding bugs are first; fixed ones at the end of this file.

/*--------------------------------------------------------------------
 * INTERPRET "return" does not work correctly. If a value is returned
 * it does work correctly.
 * Reported by: Paul G. Barnett
 * Bug Number:  020
 * Fixed by:
 * Fixed in:
 */
Interpret "Return"
Say "should not get here!"
Return 1

/*--------------------------------------------------------------------
 * LINES() BIF on transient streams return 1 when really at EOF
 * Run program below as:
 * regina test.rex BUGS
 * and as
 * cat BUGS | regina test.rex
 * Reported by: Mark Hessling
 * Bug Number:  021
 * Fixed by:
 * Fixed in:
 */
/* test.rex */
Parse Arg fn
numlines = 0
Do While(Lines(fn) > 0)
   line = Linein(fn)
   numlines = numlines + 1
End
Say numlines 'in file'

/*--------------------------------------------------------------------
 * Need to fix API call RexxVariablePool() to handle RXSHV_FETCH, RXSHV_SET
 * and RXSHV_DROPV correctly.  They currently behave the same way as
 * RXSHV_SYFET, RXSHV_SYSET and RXSHV_SYDRO respectively. ie the variables
 * are treated symbolically rather than explicitly.
 * Reported by: Mark Hessling
 * Bug Number:  022
 * Fixed by:
 * Fixed in:
 */

/*--------------------------------------------------------------------
 * CALL with parameters fails in various situations with syntax error.
 * Reported by: Dennis Baeris
 * Bug Number:  023
 * Fixed by:
 * Fixed in:
 */
myargs = 'arg1 arg2'
Call "myprog" myargs /* syntax error */
Call "myprog"myargs  /* works */
Call Fred'1234'  /* syntax error */

/*--------------------------------------------------------------------
 * Regina appears to read complete data files into memory in some 
 * operations.  More details to be specified.
 * Reported by: ???
 * Bug Number:  024
 * Fixed by:
 * Fixed in:
 */

/*--------------------------------------------------------------------
 * Clauses in the Interpret command are not traced correctly.
 * Reported by: Dennis Bareis
 * Bug Number:  025
 * Fixed by:
 * Fixed in:
 */

/*--------------------------------------------------------------------
 * The Regina parser incorrectly parses the sample code below, and
 * returns the following error:
 * Error 15 running "/home/mark/Regina-0.08h/bug030.rex", line 1: Invalid hexadecimal or binary constant
 * Error 15.3: Only 0-9, a-f, A-F, and blank are valid in hexadecimal string; found "'<'x"
 * Reported By: Mark Hessling
 * Bug Number:  19991216-29512
 * Fixed By:    
 * Fixed in:
 */
Say '<'x'>'

/*--------------------------------------------------------------------
 * The Regina parser incorrectly parses the sample code below, and
 * returns the following error:
 * Error 14 running "/home/mark/Regina-0.08h/bug29512.rex", line 2: Incomplete DO/IF/SELECT"
 * If the '?' is protected by parentheses, it works.
 * Reported By: Toby ?
 * Bug Number:  19991216-29512
 * Fixed By:    
 * Fixed in:
 */
If (?) > 0 Then say 'OK'
If ? > 0 Then say 'OK'

======================================================================
============================= FIXED ==================================
======================================================================

/*--------------------------------------------------------------------
 * Subroutines cannot have leading numerics in their name.
 * Reported by: Frank M. Ramaekers Jr.
 * Bug Number:  001
 * Fixed by:    Mark Hessling
 * Fixed in:    0.08e
 */
Say 'starting...'
rc = 1000_my_proc( "value" )
Return

1000_my_proc: Procedure
Parse Arg parm .
Say parm
Return 0

/*--------------------------------------------------------------------
 * Calling CHAROUT with the newline character, '0a'x, would result in
 * a CR and LF being output. This only happens under DOS, OS/2 and 
 * Win32 platforms.
 * Reported by: Dennis Bareis
 * Bug Number:  002
 * Fixed by:    Mark Hessling
 * Fixed in:    0.08e
 */
newl = '0a'x
Call charout "myfile", "Line 1" || newl
Return

/*--------------------------------------------------------------------
 * Line continuation character; ',' followed by CRLF in source file
 * would give syntax error.
 * Reported by: Florian Grosse-Coosmann
 * Bug Number:  003
 * Fixed by:    Mark Hessling
 * Fixed in:    0.08e
 */
Say 'Hello', /* line ends in CRLF pair */
    'world'
Return

/*--------------------------------------------------------------------
 * The value of the last token parsed with PARSE contains incorrect
 * leading space(s).
 * Reported by: Dennis Bareis
 * Bug Number:  004
 * Fixed by:    Florian Grosse-Coosmann
 * Fixed in:    0.08f
 */
a = 'one  two  three'
Parse Var a one two three
Say '<' || three || '>'

/*--------------------------------------------------------------------
 * The value returned by CHARS BIF was incorrect especially after a
 * LINEIN call.  The result is the example following would never end.
 * Reported by: Yuri Shemanin
 * Bug Number:  005
 * Fixed by:    Yuri Shemanin
 * Fixed in:    0.08f
 */
f = 'junk'
Do While Chars(f) <> 0
  l = Linein(f)
End

/*--------------------------------------------------------------------
 * On some platforms, if operating system command redirection was
 * done using >FIFO, and the current directory was not writeable by
 * the user, the command would fail. The cause is that the tmpnam()
 * C library function is broken on several compilers.
 * Added workaround to use environment variables, TMP, TEMP or TMPDIR.
 * Reported by: ???
 * Bug Number:  006
 * Fixed by:    Mark Hessling
 * Fixed in:    0.08f
 */

/*--------------------------------------------------------------------
 * On platforms that did not have a C library function, alloca()
 * Regina would leak memory.  This has now been fixed by inclusion
 * of our own alloca() function if one doesn't exist.
 * Reported by: Mark Hessling
 * Bug Number:  007
 * Fixed by:    Mark Hessling
 * Fixed in:    0.08f
 */

/*--------------------------------------------------------------------
 * A bug in the Win95/98 command processor results in any call to
 * an operating system command ALWAYS return 0, even though the
 * command fails.
 * This change attempts to circumvent this bug, but it can't in all
 * circumstances.  If the operating system command called is an
 * executable file, and there is no output/input redirection, then
 * the return code from the executable program will be returned. Any
 * internal COMMAND.COM command, such as COPY, will ALWAYS return 0;
 * there is no way around this until M$ fix there COMMAND.COM.
 * If you use JP Software's 4DOS for NT, then you will have no problems
 * as it correctly returns the error from the internal command.
 * Reported by: Michael Sundermann
 * Bug Number:  008
 * Fixed by:    Michael Sundermann
 * Fixed in:    0.08f
 */

/*--------------------------------------------------------------------
 * The result of the expression (0 = zero) should be 1, but Regina
 * returns 0
 * Reported by: Dan Hofferth
 * Bug Number:  009
 * Fixed by: Florian Grosse-Coosman
 * Fixed in: 0.08f
 */
zero = 0.000
say ( 0 = zero )  /* should say 1, but 0 */

/*--------------------------------------------------------------------
 * A numeric variable "exposed" by a procedure and subsequently used
 * in a loop within the procedure that exposed it, gets an erroneous
 * value.
 * Reported by: rick@emma.panam.wimsey.com
 * Bug Number:  010
 * Fixed by:    Florian Grosse-Coosmann
 * Fixed in:    0.08f
 */
num = 0
Call my_proc
Say 'num = ' num ';should be 6'
Return

my_proc: Procedure Expose num
Say 'num = ' num ';should be 0'
Do 3
   num = num + 1
End
Say 'num = ' num ';should be 3'
num = num + 3
Say 'num = ' num ';should be 6'
Return

/*--------------------------------------------------------------------
 * An error with dropping variables...
 * Reported by: Dennis Bareis
 * Bug Number:  011
 * Fixed by:    Mark Hessling
 * Fixed in:    0.08f
 */
call SaveInfo  "Fred", "FredsValue";
call SaveInfo  "Fred", "FredsValue2";
call HandleUndefCommand "Fred";
call SaveInfo  "Fred", "FredsValue3";
say 'Passed!!!';
exit(0);

HandleUndefCommand:
   SavedAs = "Define." || arg(1);
   say '';
   say '0.DROPPING "' || SavedAs || '"';
   if  symbol(SavedAs) = 'VAR' then
       drop(SavedAs)
   return;
SaveInfo:
   /*--- Check if variable previously existed ------------------------*/
   say '';
   say '0.SETTING - ' || arg(1) || ' to "' || arg(2) || '"';
   SavedAs = "Define." || arg(1);
   if  symbol(SavedAs) = 'VAR' then
       say '1.Already Existed';
   else
       say '1.New info';

   /*--- Save info ---------------------------------------------------*/
   ExecutingCmd = SavedAs || ' = arg(2)'
   say '2.Executing: "' || ExecutingCmd || '"'
   interpret ExecutingCmd;

   /*--- Check variable again! ---------------------------------------*/
   if  symbol(SavedAs) = 'VAR' then
   do
       interpret 'ItsValue = ' || SavedAs;
       say '3.Variable exists, value = "' || ItsValue || '"'
   end
   else
   do
       say '3.JUST SET VAR YET - Variable does not exist - WRONG!';
       exit(1);
   end;
   return;

               ******************** 
OUTPUT (note Define.FRED seems to exist TWICE in multiple cases):

0.SETTING - Fred to "FredsValue"
1.New info
2.Executing: "Define.Fred = arg(2)"
3.Variable exists, value = "FredsValue"

0.SETTING - Fred to "FredsValue2"
1.Already Existed
2.Executing: "Define.Fred = arg(2)"
3.Variable exists, value = "FredsValue2"

0.DROPPING "Define.Fred"

0.SETTING - Fred to "FredsValue3"
1.New info
2.Executing: "Define.Fred = arg(2)"
3.JUST SET VAR YET - Variable does not exist - WRONG!

               ^^^^^^^^^^^^^^^^^^^^
Dumping variables to <stdout>
   Variables from bin no 0
   >>> Variable: EXECUTINGCMD Value: [Define.Fred = arg(2)]
   Variables from bin no 107
   >>> Stem    : Define. Default: [<none>]  Values:
      Sub-bin no 161
      >>> Tail: FRED Value: []
   >>> Stem    : DEFINE. Default: [<none>]  Values:
      Sub-bin no 161
      >>> Tail: FRED Value: [FredsValue3]
   Variables from bin no 109
   >>> Variable: ITSVALUE Value: [FredsValue2]
   Variables from bin no 175
   >>> Variable: SIGL Value: [8]
   Variables from bin no 231
   >>> Variable: SAVEDAS Value: [Define.Fred]

               ^^^^^^^^^^^^^^^^^^^^

/*--------------------------------------------------------------------
 * Allow "stderr" to be used to refer to stderr in STREAM BIF.
 * Reported by: Dennis Bareis
 * Bug Number:  012
 * Fixed by:    Mark Hessling
 * Fixed in:    0.08f
 */
rc = Stream('stderr', 'C', 'QUERY EXISTS')

/*--------------------------------------------------------------------
 * The internal variable SIGL gets updated prematurely.
 * Reported by: Dennis Bareis
 * Bug Number:  013
 * Fixed by:    Florian Grosse-Coosmann
 * Fixed in:    0.08f
 */

Call Alabel
Return

ALabel:
Call AnotherLabel SIGL
Return

AnotherLabel:
Parse Arg lineo
Say lineno
Return

/*--------------------------------------------------------------------
 * A syntax error in a Rexx script passed to the RexxStart() API via
 * the "instore" option, will exit the program, rather than return an
 * error.
 * Reported by: Mark Hessling
 * Bug Number:  014
 * Fixed by:    Florian Grosse-Coosmann
 * Fixed in:    0.08f
 */

/*--------------------------------------------------------------------
 * The VALUE() BIF would not set values of compound variables correctly
 * if the variable is specified in lower case.
 * Reported by: Jeff Parlant and Dennis Bareis
 * Bug Number:  015
 * Fixed by:    Mark Hessling
 * Fixed in:    0.08g
 */

stemname = 'foo.'
foo.0 = 1
foo.1 = 'something'
call func
say foo.0
say foo.1
exit 0
    
func: procedure expose stemname (stemname)
/* trace ?i */
do i = 1 to value(stemname||0)
   r = value(stemname||i,'something else')    
end
return 0

/*--------------------------------------------------------------------
 * The value of the last argument to a procedure when using the ARG() BIF
 * has an incorrect trailing space.
 * Reported by: Mark Hessling
 * Bug Number:  016
 * Fixed by: Mark Hessling
 * Fixed in: 0.08g
 */

Call proc '123', '456'
Return

proc:
Say '<' || arg(1) || '>' /* displays <123>  */
Say '<' || arg(2) || '>' /* displays <456 > */
Return

/*--------------------------------------------------------------------
 * INTERPRET "return Func()" does not work correctly.
 * Reported by: Paul G. Barnett
 * Bug Number:  017
 * Fixed by: Mark Hessling
 * Fixed in: 0.08g - See Bug 020
 */
Interpret "Return F1()"
Say "should not get here!"
Return
F1: Procedure
Say "in F1"
Return 0

/*--------------------------------------------------------------------
 * File names in Regina are always case sensitive, even on non-Unix
 * platforms.  This can result in incorrect read/write pointers when
 * referencing a file by name with different case.
 * Reported by: Jackie Cooper
 * Bug Number:  018
 * Fixed by: Mark Hessling
 * Fixed in: 0.08g
 */
myfile = 'abc'
myupperfile = 'ABC'
Call Lineout, myfile, 'Line1'
Call Lineout, myupperfile, 'Line2'
Call Lineout, myfile
numlines = 0
Do While(Lines(myfile)>0)
   numlines = numlines + 1
End
Say 'Should be 2 lines, but got only' numlines
Return

/*--------------------------------------------------------------------
 * Setting Rexx variables using VALUE BIF produce inconsistent results.
 * Reported by: Dennis Baeris
 * Bug Number:  019
 * Fixed by:    Mark Hessling
 * Fixed in:    0.08h
 */
call value "Upd.3", "text";
say 'a) Upd.3="' || Upd.3          || '"';
say 'b) Upd.3="' || value("Upd.3") || '"';
say 'c) Upd.3="' || value("UPD.3") || '"';

Before fix, output was:
a) Upd.3="UPD.3"
b) Upd.3="text"
c) Upd.3="text"

after fix:
a) Upd.3="text"
b) Upd.3="text"
c) Upd.3="text"

/*--------------------------------------------------------------------
 * Assignment on compound variables does not work.
 * Reported by: Mike Ruskai
 * Bug Number:  026
 * Fixed by:    No fix required.
 * Fixed in:    Checked in 0.08h
 * Comments:    Regina follows the ANSI standard when assigning one
 *              stem variable to another.
 *              Confusion arises between the way that Object Rexx
 *              assigns one stem variable to another; Object Rexx does
 *              NOT follow the ANSI standard.  In Object Rexx, a.=b.
 *              creates a reference from a. to b.; ie a. is the same
 *              stem as b.
 */
foobar.1='One'
foobar.2='Two'
drop foobar.5
say 'FOOBAR.1 set to "One", FOOBAR.2 set to "Two", FOOBAR.5 dropped'
say 'assigning newstem1. to foobar. ...'
newstem1. = foobar.
say 'dropping newstem1.4'
drop newstem1.4
Say 'NEWSTEM1.1 Value:'  '"'newstem1.1'" should be "FOOBAR."'
Say 'NEWSTEM1.2 Value:'  '"'newstem1.2'" should be "FOOBAR."'
Say 'NEWSTEM1.3 Value:'  '"'newstem1.3'" should be "FOOBAR."'
Say 'NEWSTEM1.4 Value:'  '"'newstem1.4'" should be "NEWSTEM1.4"' '<-dropped'
Say 'NEWSTEM1.5 Value:'  '"'newstem1.5'" should be "FOOBAR."'
say 'assigning newstem2. to newstem1. ...'
newstem2. = newstem1.
say 'dropping newstem2.4'
drop newstem2.4
Say 'NEWSTEM2.1 Value:' '"'newstem2.1'" should be "FOOBAR."'
Say 'NEWSTEM2.2 Value:' '"'newstem2.2'" should be "FOOBAR."'
Say 'NEWSTEM2.3 Value:' '"'newstem2.3'" should be "FOOBAR."'
Say 'NEWSTEM2.4 Value:' '"'newstem2.4'" should be "NEWSTEM2.4"' '<-dropped'
Say 'NEWSTEM2.5 Value:' '"'newstem2.5'" should be "FOOBAR."'
/* with default value for source stem */
foobar1. = 'default'
foobar1.1='One'
foobar1.2='Two'
drop foobar1.5
say 'FOOBAR1. set to "default", FOOBAR1.1 set to "One", FOOBAR1.2 set to "Two", FOOBAR1.5 dropped'
say 'assigning newstem. to foobar. ...'
newstem. = foobar1.
say 'dropping newstem.4'
drop newstem.4
Say 'NEWSTEM.1 Value:' '"'newstem.1'" should be "default"'
Say 'NEWSTEM.2 Value:' '"'newstem.2'" should be "default"'
Say 'NEWSTEM.3 Value:' '"'newstem.3'" should be "default"'
Say 'NEWSTEM.4 Value:' '"'newstem.4'" should be "NEWSTEM.4"' '<-dropped'
Say 'NEWSTEM.5 Value:' '"'newstem.5'" should be "default"'
Say 'NEWSTEM.6 Value:' '"'newstem.6'" should be "default"'

/*--------------------------------------------------------------------
 * Inconsistent, invalid return values from STREAM (QUERY EXISTS) when
 * using the EMX port of Regina under OS/2. This bug possible on other
 * platforms.
 * Reported by: Dennis Baeris
 * Bug Number:  027
 * Fixed by:    Mark Hessling
 * Fixed in:    0.08h
 */
fn = 'bug027.txt'
Call Stream fn, 'C', 'OPEN WRITE REPLACE'
Call Lineout fn,'One line'
Call Stream fn, 'C', 'CLOSE'
line = Linein(fn)
Say 'Linein(fn) returned:' '"'line'"' 'should be return "One Line"'
stat = Stream(fn,'S')
Say 'Stream(fn,"S") returned:' '"'stat'"' 'should be return "READY"'
line = Linein(fn)
Say 'Linein(fn) returned:' '"'line'"' 'should be return ""'
stat = Stream(fn,'S')
Say 'Stream(fn,"S") returned:' '"'stat'"' 'should be return "NOTREADY"'

/*--------------------------------------------------------------------
 * If Regina was invoked through the SAA interface, and the script named in
 * the invocation did not exist, the error message did not correctly name
 * it, or crashed.
 * Reported By: Jim Hasslacher, Jr.
 * Bug Number:  029
*  Fixed By:    Jim Hasslacher, Jr.
 * Fixed in:    0.08h
 */

/*--------------------------------------------------------------------
 * Odd behaviour with DELWORD BIF.
 * Line 1 gives '0' and this is correct (no '10' in the string).
 * Line 3 makes the same string as used in line 1 and puts it into a.
 * Line 4 now gives 3 !!!! Yet there is no '10' in there at all
 * The rest is just to prove my point the length of the string doensn't change
 * but after the strip all works as it should...
 * I think the problem occurs when the first character of the searchstring and
 * that of the deleted word are the same.
 *   MH - the problem occurs if the word following the word to be deleted is
 *   1 character shorter than the word being deleted and starts with the
 *   same characters as the word being deleted.  Seems the check for a word
 *   at the end of the string checks 1 character past the end of the string.
 * Reported By: Thomas Zobl
 * Bug Number:  030
 * Fixed By:    Mark Hessling
 * Fixed in:    0.08h
 */
Say Wordpos('10','2 11 1')

b = '2 11 10 1'
a = Delword('2 11 10 1',3,1)
Say Wordpos('10',a)

Say Length(a)
a = Strip(a)
Say Wordpos('10',a)
Say Length(a)

/*--------------------------------------------------------------------
 * Passing a lower or mixed case variable name to RexxVariablePool() when
 * setting a Rexx variable fails.
 *
 * Reported By: Bill Potvin, II
 * Bug Number:  031
 * Fixed By:    Mark Hessling
 * Fixed in:    0.08h
 */
Returncode = SysFileTree("*","Files.")
say files.0 /* always returns FILES.0 */

/*--------------------------------------------------------------------
 * When registering an external function from within the API, an attempt
 * to register a function that is already loaded results in a return code
 * of 1 NOT the correct value of 10 (RXFUNC_DEFINED).
 *
 * Reported By: Bill Potvin, II
 * Bug Number:  033
 * Fixed By:    Mark Hessling
 * Fixed in:    0.08h
 */

/*--------------------------------------------------------------------
 * The STREAM BIF using QUERY EXISTS incorrectly returns a file name
 * when the file does not exist under some circumstances.
 * If in directory e:\regina and a file exists: e:\config.sys, then
 * Stream('e:\config.sys', 'C', 'QUERY EXISTS') returns:
 *  e:\regina\config.sys
 *
 * Reported By: Dennis Baeris
 * Bug Number:  034
 * Fixed By:    Mark Hessling
 * Fixed in:    0.08h
 */

/*--------------------------------------------------------------------
 * The following code causes Regina to crash.
 * Reported by: Florian Grosse-Coosmann
 * Bug Number:  032
 * Fixed By:    Florian Grosse-Coosmann
 * Fixed in:    0.08h
 */
Name = "Florian"
call MyName Name
call MyName2 Name
return 0

MyName:
say "Name =" Name ||  ",arg =" arg(1)
Name = "Coosmann"
say "Name =" Name ||  ",arg =" arg(1)
return

MyName2:
say "Name =" Name ||  ",arg =" arg(1)
Name = "Grosse-Coosmann"
say "Name =" Name ||  ",arg =" arg(1)
return

/*--------------------------------------------------------------------
 * When calling an external subroutine and it is found by use of
 * REGINA_MACROS environment variable, PARSE SOURCE does not return
 * the filename of the file.
 *
 * Reported By: Steve Menschel
 * Bug Number:  19991129-86098
 * Fixed By:    Mark Hessling
 * Fixed in:    0.08h
 */

/*--------------------------------------------------------------------
 * Access to the external environment when using regina.dll under OS/2
 * was not possible.
 * This was due to the way that regina.exe was incorrectly built.
 *
 * Reported By: Paul G Barnett
 * Bug Number:  035
 * Fixed By:    Mark Hessling
 * Fixed in:    0.08h
 */

