home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 551.lha / Cookie / Cookie.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1991-09-08  |  1.7 KB  |  42 lines

  1. /************************************************************************/
  2. /*  COOKIE.REXX - ARexx script to print out a fortune cookie        */
  3. /*                                    */
  4. /*  Written by Rick Stevens, 28 July 1991                */
  5. /*  THIS PROGRAM IS RELEASED TO THE PUBLIC DOMAIN            */
  6. /************************************************************************/
  7. options results
  8.  
  9. say ""                    /* Display blank line        */
  10. say "The ARexx Cookie Monster says:"    /* Tell user we'er the monster    */
  11. if open(infile,'S:Cookie.dat','r') = 0 then
  12.     do                    /* Can we open the file?    */
  13.     say "Sorry, I ate all of the cookies!  <BURP!>"
  14.                     /* Nope, say something silly!    */
  15.     say ""                /* Add in a blank line        */
  16.     exit                /* Terminate script        */
  17.     end
  18.  
  19. flen = seek(infile,0,'E')        /* Get file length        */
  20. fpos = time('seconds')            /* Get a seed value for RANDU    */
  21. fpos = randu(fpos)            /* Get a position and reseed    */
  22. fpos = fpos * flen            /* Compute a seek position    */
  23. x = index(fpos,".")            /* Find the decimal point    */
  24. fpos = left(fpos,x-1);            /* Extract the whole part    */
  25. seek(infile,fpos,'B')            /* Seek to the position        */
  26. do while x ~= '0C'x            /* While it's not a form feed...*/
  27.     x = readch(infile,1)        /* ...read another character    */
  28. end
  29. x = readch(infile,1)            /* Grab the LF following the FF    */
  30.  
  31. breakflag = 0                /* Clear breakflag        */
  32. do while breakflag = 0            /* While we've got a cookie...    */
  33.     fstring = readln(infile)        /* ...read a line from file    */
  34.     if index(fstring,'0C'x) ~= 0 then    /* Did we find an end of cookie?*/
  35.     breakflag = 1            /* Yup, set break flag        */
  36.     else                /* Nope, so...            */
  37.     say fstring            /* ...send string        */
  38. end
  39. close(infile)               /* Close the input file        */
  40. say ""                    /* Display blank line        */
  41. exit
  42.