TIP: Click on subject to list as thread! ANSI
echo: os2rexx
to: Wim Bijlenga
from: Eddy Thilleman
date: 1999-11-18 20:40:25
subject: general open file routines

Hello Wim,

16 Nov 99 08:23, Wim Bijlenga wrote to Eddy Thilleman:

ET>> I've written some (I hope) general (ofcourse) REXX file routines,
ET>> with internal checking for file errors, these can be used as
ET>> functions. Is there interest?

WB> Yes

You're the first to ask for it.

I've made these routines to make it easier to open, read/write and close
files, and not have to code the checks, etc (write once, use many times). I
just want to write something like openfile in the main code and not to have to 
think about all the hassle to handle error situations (like file not present,
or file is present but (for some reason) it can't be opened, etc.

/* file I/O subroutines */

/* search text in file and if found, returns that line */
Search: procedure
parse arg file, text
found = 0
  check = stream( file, 'C', "seek =1" )    /* seek to begin of file */
  do while (Lines( file ) = 1) & \found     /* while not end of file and text
not found */
    Line = strip( LineIn( file ) )          /* read new line */
    if Length( Line ) > 0 then do           /* if Line not empty */
      if pos( translate(text), translate(Line) ) > 0 then do
        found = 1
      end  /* if text is found */
    end  /* if Line not empty */
  end  /* while not end of file */
  if \found then Line = ""           /* if text not found, return empty line
*/
return Line


/* function OpenFile( fname ) */
OpenFile: procedure
parse arg fname
  check = stream( fname, 'c', 'query exists' )
  if length( check ) > 0 then
   do
    check = stream( fname, 'c', 'open' )
    if (check == 'READY') | (check == 'READY:') then
      result = 1
    else
     do
      result = 0
      say fname":" stream( InFile, 'D' )  /* display description about
possible error */
     end
   end
  else
   do
    say fname "not found"
    result = 0
   end
return result


/* function OpenReadFile( fname ) */
OpenReadFile: procedure
parse arg fname
  check = stream( fname, 'c', 'query exists' )
  if length( check ) > 0 then
   do
    check = stream( fname, 'c', 'open read' )
    if (check == 'READY') | (check == 'READY:') then
      result = 1
    else
     do
      result = 0
      say fname":" stream( InFile, 'D' )  /* display description about
possible error */
     end
   end
  else
   do
    say fname "not found"
    result = 0
   end
return result


/* function OpenWriteFile( fname ) */
OpenWriteFile: procedure
parse arg fname
  check = stream( fname, 'c', 'open write' )
  if (check == 'READY') | (check == 'READY:') then
    result = 1
  else
   do
    result = 0
    say fname":" stream( InFile, 'D' )  /* display description about possible
error */
   end
return result


/* function OpenAppendFile( fname ) */
OpenAppendFile: procedure
parse arg fname
  check = stream( fname, 'c', 'open write' )
  if (check == 'READY') | (check == 'READY:') then
   do
    result = 1
    check = stream( fname, 'C', 'seek <' 0 )     /* seek to end of file */
   end
  else
   do
    result = 0
    say fname":" stream( InFile, 'D' )  /* display description about possible
error */
   end
return result


/* function CloseFile( fname ) */
CloseFile: procedure
parse arg fname
  check = stream( fname, 'C', 'close' )
  if (check == 'READY') | (check == 'READY:') then
    result = 1
  else
   do
    result = 0
    say "Error closing" fname":" stream( InFile, 'D' )  /* display description 
about possible error */
   end
return


ET>>   Greetings   -=Eddy=-        email: eddy.thilleman@net.hcc.nl

WB> net.hcc.nl ? My provider is hccnet.nl !

I've that account too.

  Greetings   -=Eddy=-        email: eddy.thilleman@net.hcc.nl

... OS/2: Taking the wind out of Windows.
--- GoldED/2 3.0.1
3615/7
* Origin: Windows98 is a graphic DOS extender (2:500/143.7)

SOURCE: echoes via The OS/2 BBS

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.