[comp.sys.amiga.programmer] REXX and files

bj@cbmvax.commodore.com (Brian Jackson) (02/25/91)

In article <91053.124724FORDE@vm.poly.edu> FORDE@vm.poly.edu writes:
>I am new to Amiga Rexx and I am having problems with certain
>Rexx commands. I am trying to use the showdir(), open(), and
>readln() commands, but theprogram doesnt want to work. could
>someone send me a few examples of working with files through
>rexx on the amiga.  I am used to REXX on the IBM mainframe.

You'll need to make your own little ASCII "testfile" for this...
 
/* t.rexx - shows open(), showdir() ,readln() and close() usage */

dirline = showdir('dh0:')

do x = 1 to words(dirline)
	say "word" x "=" word(dirline, x )
end
	
success = open( infile, "testfile", "read")
if (success) then
	do while ~eof(infile)
		inline = readln(infile)
		say inline
	end
	close(infile)

/* end */

bj

 -----------------------------------------------------------------------
 | Brian Jackson  Software Engineer, Commodore-Amiga Inc.  GEnie: B.J. |
 | bj@cbmvax.cbm.commodore.com    or  ...{uunet|rutgers}!cbmvax!bj     |
 | "We defy augury"                                                    |
 -----------------------------------------------------------------------

cpc@czaeap.UUCP (Chris Cebelenski) (02/27/91)

In article <91053.124724FORDE@vm.poly.edu>, FORDE@vm.poly.edu writes:

> I am new to Amiga Rexx and I am having problems with certain
> Rexx commands. I am trying to use the showdir(), open(), and
> readln() commands, but theprogram doesnt want to work. could
> someone send me a few examples of working with files through
> rexx on the amiga.  I am used to REXX on the IBM mainframe.
> #! rnews 1970
> Path: aminet!gdc!portal!fernwood!uunet!cs.utexas.edu!wuarchi


Here's a short AREXX program that uses many of these things.  You should
find it on a fish disk soon, but I'll post it here also:

/* FixRC.REXX
   Author: Chris Cebelenski
   Feburary, 1990
   Version 1.0a
   Description: 	Updates your dnewsrc file to include new newsgroups
*/

/* Notes:  Make sure you change the opens to open the correct
	   .dnewsrc file.  Maybe later I'll work it up for
	   multiple entries, but for now it's hardcoded. FIXME

	   No extraneous directories should exist in your UUNEWS:
	   directory.  If there are any, they will be added to
	   your newslist!  FIXME

	   This program is VERY slow if you get lots of newsgroups.
	   This is because I added the newsgroups to the end of the
	   search list.  It usually runs in batch mode under DCRON,
	   so I don't worry about it much.

*/


PLC:
	DEBUG = 0	/* No debugging information */
	YourDIR = showdir("UUNEWS:",'D'," ")
	NumEntries = words(YourDIR)
	if DEBUG >= 1 then Say NumEntries " Found."
	Tst = open('RCFILE',"UULIB:cpc.dnewsrc","R")
	If Tst = 0 then do
		say "%Can't find your .dnewsrc file!"
		exit(1)
	end
	Count = 0
	do until eof('RCFILE')
		Count = Count + 1
		Newsgroup.Count = readln('RCFILE')
	end
	do I = 1 to NumEntries
		Flag = 0
		Do J = 1 to count
			If DEBUG >= 3 then say "Checking " word(YourDIR,I) " " word(Newsgroup.J,2)
			if word(YourDIR,I) = word(Newsgroup.J,2) then do
				Flag = 1
				If DEBUG >= 2 then say word(YourDIR,I) " Found."
			end
		end
		if Flag = 0 then do
			If DEBUG >= 2 then say word(YourDIR,I) "Not found."
			count = count + 1
			Newsgroup.Count = "y " word(YourDIR,I) " 0 - -"
		end
	end
	tmp = close('RCFILE')
	Tst = Open("RCFILE","uulib:cpc.dnewsrc","w")
	if tst ~= 1 then do
		Say "%Error writing to dnewsrc file!"
		exit(2)
	end
	do I = 1 to count
		l = writeln('RCFILE',Newsgroup.I)
	end
	tmp = close('RCFILE')
	exit(0)

==========================================================================
    Chris Cebelenski        UUCP: portal.com!gdc!aminet!czaeap!cpc
    The Red Mage                : cpc@czaeap.UUCP
                                 // "Amiga - The way REAL people compute"
                               \X/
               Sex, and Drugs, and Rock and Roll-Playing!     (DEVO RULES)
==========================================================================
NOTE: Due to brain dead mailers, this message can *NOT* be REPLIED to, to
reach me you MUST send a NEW message.  Sorry!