Possible file open problem - OS/2 classic Rexx 
Author Message
 Possible file open problem - OS/2 classic Rexx

I hope someone can point out the flaw in the following program.

What I'm trying to do is extract the originating IP address from each
of a number of email messages in a PMMail folder. Although the program
could be modified to find any string in a number of files, so you
don't need PMMail to look at this.

PMMail stores messages in a folder with a .MSG extension. The file
format is ASCII text. There are also 3 control files that PMMail uses
to manage the folder that are not used by my program.

SysFileTree is used to get all .MSG filenames. I then run a loop to
open each file in turn and look for the originating IP address. The
program runs fine for the first 12 files then fails to open the
remaining messages.

I've checked that there is nothing odd with the last processed message
by changing the start and end file numbers in the DO loop. It always
processes 12 files before failing.

I assume that files are not being closed and that further attempts to
open files fail. The SAY lines show:
 - the file being processed,
 - the return code from the LINES function,
 - the file index number and the IP address found

Could you kind people take a look at the listing and tell me what I'm
doing wrong?

Thanks

Jim

The listing below is a 'shortened for publication' version.

/* Rexx programme to extract IP address from PMMail email headers
showing where spam originated. Written by Jim Backus 2003-07-25 */

/* Strategy
- use Rexx functions to get directory of all .MSG files in a directory
- read each file line by line looking for "Received:"
- when found save first valid IP address to a variable
- continue until blank line found (this is believed to mark the end of
the headers)
- the final value in the IP variable is the originating IP address.
*/

SearchFor1 = 'Received:'

IF LoadRexxUtil() THEN
  EXIT

/* Following line is for publication - to test the program you'll have
to edit
this to something that works in your environment */

FileNameTemplate = '<path-name/>*.msg'

CALL SysFileTree FileNameTemplate, 'FName.', 'FO'

/* DO idx0 = 1 TO FName.0 */
DO idx0 = 1 TO 14
/* next 2 lines diagnostic */
  SAY 'Processing ' FName.idx0
  say 'lines> ' Lines(FName.idx0)

  Do While Lines(FName.idx0)

    Tline = LineIn(FName.idx0)

if Tline = '' Then
do
  rc = Stream(FName.idx0 'c' 'close')
  leave
end

    If Word(Tline, 1) = SearchFor1 THEN
    DO
      LeftSquare = Pos('[', Tline)
      IF LeftSquare <> 0 THEN
      DO
        RightSquare = Pos(']', Tline)
        IPaddress = SubStr(Tline, LeftSquare+1,
RightSquare-LeftSquare-1)
        SAY idx0 IPaddress
      END
    END
  END

END

EXIT

/* function taken from Teach yourself Rexx in 21 days */

LoadRexxUtil: PROCEDURE
  IF RxFuncQuery('SysLoadFuncs') THEN
    DO
    IF RxFuncAdd( 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' ) THEN
      DO
      SAY "Error: Couldn't load RexxUtil library."
      RETURN 1
      END
    CALL SysLoadFuncs
    END
  RETURN 0

--
Jim Backus  OS/2 user
bona fide replies to jimb-thecirclethingy-jita-dp-demon-dp-co-dp-uk
or remove "NOT" from address
remove dashes and make the obvious substitutions for valid email
address



Wed, 11 Jan 2006 20:32:47 GMT  
 Possible file open problem - OS/2 classic Rexx


Quote:
>   rc = Stream(FName.idx0 'c' 'close')

should be

   rc = Stream(FName.idx0, 'c', 'close')

(note the commas) otherwise you just perform a null stream operation on
a file called 'xxxxx.msg c close'   !!

--
Message sent VIA Followup and E-Mail --

--
Bob Eager
rde at tavi.co.uk
PC Server 325*4; PS/2s 9585, 8595, 9595*2, 8580*3,
P70, PC/AT..



Wed, 11 Jan 2006 21:15:24 GMT  
 Possible file open problem - OS/2 classic Rexx

his sleeves and typed:

Quote:


> >   rc = Stream(FName.idx0 'c' 'close')

> should be

>    rc = Stream(FName.idx0, 'c', 'close')

> (note the commas) otherwise you just perform a null stream operation on
> a file called 'xxxxx.msg c close'   !!

Thanks - haven't tried it but I was sure it would be something
obvious.

--
Jim Backus  OS/2 user
bona fide replies to jimb-thecirclethingy-jita-dp-demon-dp-co-dp-uk
or remove "NOT" from address
remove dashes and make the obvious substitutions for valid email
address



Thu, 12 Jan 2006 02:42:13 GMT  
 Possible file open problem - OS/2 classic Rexx


Quote:
> SysFileTree is used to get all .MSG filenames. I then run a loop to
> open each file in turn and look for the originating IP address. The
> program runs fine for the first 12 files then fails to open the
> remaining messages.
> Could you kind people take a look at the listing and tell me what I'm
> doing wrong?

> The listing below is a 'shortened for publication' version.

Try something like:

DO idx = 1 to FName.0
   DO While Lines(FName.idx0)
      Tline = LineIn(FName.idx0)
      /* Do something */
   END
   call stream FName, 'c', 'close'
END

--

John Small

(remove the z's for email address)



Thu, 12 Jan 2006 18:19:48 GMT  
 Possible file open problem - OS/2 classic Rexx

rolled up his sleeves and typed:

Quote:


> > SysFileTree is used to get all .MSG filenames. I then run a loop to
> > open each file in turn and look for the originating IP address. The
> > program runs fine for the first 12 files then fails to open the
> > remaining messages.
> > Could you kind people take a look at the listing and tell me what I'm
> > doing wrong?

> > The listing below is a 'shortened for publication' version.

> Try something like:

> DO idx = 1 to FName.0
>    DO While Lines(FName.idx0)
>       Tline = LineIn(FName.idx0)
>       /* Do something */
>    END
>    call stream FName, 'c', 'close'
> END

Thanks for that suggestion.

I've remembered ho i made the mistake in the original. I'd left a
space between Stream & the following parenthesis. The interpreter
found the syntax error but said (something like) unexpected comma or
'('. I removed the commas before finding the extra space and then
forgot to put the commas back.

Your post is interesting in that you suggest using
CALL stream ... i.e Procedure form
instead of the
rc = stream(  ... the function form

of syntax.

My Rexx bible is Teach yourself Rexx in 21 days but although it uses
both forms I haven't seen an explanation of the benefits or reasons to
use one instead of the other.

I assume the CALL systax is better when the return value is not
needed. and the rc = function is necessary when a return value is
required.

Is it just a style thing?

--
Jim Backus  OS/2 user
bona fide replies to jimb-thecirclethingy-jita-dp-demon-dp-co-dp-uk
or remove "NOT" from address
remove dashes and make the obvious substitutions for valid email
address



Fri, 13 Jan 2006 06:10:24 GMT  
 Possible file open problem - OS/2 classic Rexx


(glad I was able to help with the commas thing..!)

Quote:
> I've remembered ho i made the mistake in the original. I'd left a
> space between Stream & the following parenthesis. The interpreter
> found the syntax error but said (something like) unexpected comma or
> '('. I removed the commas before finding the extra space and then
> forgot to put the commas back.
> I assume the CALL systax is better when the return value is not
> needed. and the rc = function is necessary when a return value is
> required.

Exactly. When using 'stream' to open a file, you want to check the
result; presumably to see if the file exists.

When closing, you can't do much with the result so you might as well use
CALL.

--
Bob Eager
rde at tavi.co.uk
PC Server 325*4; PS/2s 9585, 8595, 9595*2, 8580*3,
P70, PC/AT..



Fri, 13 Jan 2006 06:30:58 GMT  
 Possible file open problem - OS/2 classic Rexx

Quote:

> I assume the CALL systax is better when the return value is not
> needed. and the rc = function is necessary when a return value is
> required.

Almost, however rc = function() isn't *necessary* because the CALL
syntax will place the retured value being in the result variable. The
only time you *must* use one or the other is when nothing (not just
null) is returned, in which case you must use CALL.

Quote:
> Is it just a style thing?

One way or the other is often clearer or more appropriate for a
particular purpose. For example, if you want to dismantle the result of
a subroutine which returns multiple items with PARSE, using a function
probably makes more sense as you can do "PARSE VALUE function(...) WITH
pattern" instead of doing it in two instructions.

Graham.

--
*-* Please remove spam free prefix before replying *-*



Fri, 13 Jan 2006 07:45:28 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Handling large file (classic rexx OS/2)

2. Rexx Macro Space on Classic OS/2 Rexx

3. Using OS/2 REXX to modify file objects opening menu

4. Sort function, classic rexx OS/2

5. OS/2 classic REXX, SysTempFileName

6. os/2, classic rexx, and a pm interface

7. A SYS3175 error in classic os/2 rexx

8. OS/2 + Classic Rexx on a P4?

9. Difference in OS/2 Classic/Object REXX Read Only

10. how to get timezone in os/2 in classic rexx

11. Problem opening files while using os.path.walk

12. vx-rexx and file open dialog box problem

 

 
Powered by phpBB® Forum Software