home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************/
- /* COOKIE.REXX - ARexx script to print out a fortune cookie */
- /* */
- /* Written by Rick Stevens, 28 July 1991 */
- /* THIS PROGRAM IS RELEASED TO THE PUBLIC DOMAIN */
- /************************************************************************/
- options results
-
- say "" /* Display blank line */
- say "The ARexx Cookie Monster says:" /* Tell user we'er the monster */
- if open(infile,'S:Cookie.dat','r') = 0 then
- do /* Can we open the file? */
- say "Sorry, I ate all of the cookies! <BURP!>"
- /* Nope, say something silly! */
- say "" /* Add in a blank line */
- exit /* Terminate script */
- end
-
- flen = seek(infile,0,'E') /* Get file length */
- fpos = time('seconds') /* Get a seed value for RANDU */
- fpos = randu(fpos) /* Get a position and reseed */
- fpos = fpos * flen /* Compute a seek position */
- x = index(fpos,".") /* Find the decimal point */
- fpos = left(fpos,x-1); /* Extract the whole part */
- seek(infile,fpos,'B') /* Seek to the position */
- do while x ~= '0C'x /* While it's not a form feed...*/
- x = readch(infile,1) /* ...read another character */
- end
- x = readch(infile,1) /* Grab the LF following the FF */
-
- breakflag = 0 /* Clear breakflag */
- do while breakflag = 0 /* While we've got a cookie... */
- fstring = readln(infile) /* ...read a line from file */
- if index(fstring,'0C'x) ~= 0 then /* Did we find an end of cookie?*/
- breakflag = 1 /* Yup, set break flag */
- else /* Nope, so... */
- say fstring /* ...send string */
- end
- close(infile) /* Close the input file */
- say "" /* Display blank line */
- exit
-