REXX Tips & Tricks, Version 2.80


Inf-HTML [About][Toc][Index] 0.9b (c) 1995 Peter Childs


The function LINEOUT() in Object REXX



The function <LINEOUT seems to have a bug in Object REXX. 
For example the REXX program below should write all three messages to the 
file TEST001.LOG in the current directory at program start. But in Object 
REXX, it writes only the first message to this file; the other two 
messages go into the files C:\OS2\TEST001.LOG and C:\MPTN\TEST001.LOG. 
[Tested with OBJREXX 6.00 12 Jul 1996] 
[Fixed in OBJREXX 6.00 26 Feb 1997 and newer versions (included in WARP 4 
Fixpack #6)] 

 
/*                                                                    */
/* sample program to show a bug in the LineOut routine in Object REXX */
/*                                                                    */

                    /* set the name for the logfile                   */
  logFileName = ILog( 'TEST001.LOG' )
                    /* logFileName now contains the fully qualified   */
                    /* name of the logfile                            */

                    /* write the name of the logfile to the screen    */
  say 'MAIN: logFileName is : "' || logFileName || '"'
  say '      Current directory is : "' || directory() || '"'

                    /* write something to the logfile                 */
                    /* Note: This is written to the *correct* logfile */
  call log 'Testing 1, currrent directory is ' || directory()

                    /* write the name of the logfile to the screen    */
  say 'MAIN: logFileName is : "' || logFileName || '"'
  say '      Current directory is : "' || directory() || '"'

                    /* now change the directory                       */
  call directory 'C:\OS2'

                    /* write the name of the logfile to the screen    */
  say 'MAIN: logFileName is : "' || logFileName || '"'
  say '      Current directory is : "' || directory() || '"'

                    /* ... and write something to the logfile         */
                    /* Note: This goes to the file C:\OS2\TEST001.LOG */
                    /*       and not into the correct logfile!!!      */
  call log 'Testing 2, currrent directory is ' || directory()

                    /* now change the directory again                 */
  call directory 'C:\MPTN'

                    /* write the name of the logfile to the screen    */
  say 'MAIN: logFileName is : "' || logFileName || '"'
  say '      Current directory is : "' || directory() || '"'

                    /* ... and write something to the logfile         */
                    /* Note: This goes to the file C:\MPTN\TEST001.LOG*/
                    /*       and not into the correct logfile!!!      */
  call log 'Testing 3, currrent directory is ' || directory()

                    /* write the name of the logfile to the screen    */
  say 'MAIN: logFileName is : "' || logFileName || '"'
  say '      Current directory is : "' || directory() || '"'

exit

/* ------------------------------------------------------------------ */
/*-function: get the fully qualified name of the logfile              */
/*                                                                    */
/*-call:     ilog logfilename                                         */
/*                                                                    */
/*-where:    logfilename - name of the logfile                        */
/*                                                                    */
/*-returns:  fully qualified name of the logfile                      */
/*                                                                    */
/*                                                                    */
ILOG: PROCEDURE
  parse arg logFilename

                        /* open or create the logfile                 */
  logStatus = stream( logFileName, 'c', 'OPEN WRITE')
  if logStatus <> 'READY:' then
  do
    say 'Error: Cannot create the logfile "' || logFileName || '"!'
    exit 255
  end /* if */

                        /* close the logfile                          */
  call stream logFileName, 'c', 'CLOSE'

                        /* get the fully qualified name of the        */
                        /* logfile                                    */
  newLogFileName = translate( stream( logFileName, 'c', 'QUERY EXISTS' ) )

                    /* write the name of the logfile to the screen    */
  say 'ILOG: logFileName is : "' || newLogFileName || '"'
  say '      Current directory is : "' || directory() || '"'

RETURN newLogFileName

/* ------------------------------------------------------------------ */
/*-function: log a message and clear the rest of the line             */
/*                                                                    */
/*-call:     log message                                              */
/*                                                                    */
/*-where:    message - message to show                                */
/*                                                                    */
/*-returns:  ''                                                       */
/*                                                                    */
/*-Note:     You do not need the 'call' keyword to use this routine.  */
/*           The name of the logfile is saved in the global variable  */
/*           'logFileName'.                                           */
/*                                                                    */
Log: PROCEDURE expose logFileName
  parse arg logmsg

                    /* write the name of the logfile to the screen    */
  say ' LOG: logFileName is : "' || logFileName || '"'
  say '      Current directory is : "' || directory() || '"'

                    /* error occurs also if the file is explicitly    */
                    /* opened before writing to the file!             */
/*
  rc = stream( logFileName, 'c', 'OPEN WRITE')
*/

  call lineout logFileName, logmsg

                    /* the error does *not* occur, if the logfile is  */
                    /* *not* closed                                   */

                    /* close the logfile                              */
  rc = stream( logFileName, 'c', 'CLOSE')

RETURN ''

  

Inf-HTML End Run - Successful