home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / shuffile.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  69 lines

  1. ############################################################################
  2. #
  3. #    File:     shuffile.icn
  4. #
  5. #    Subject:  Program to shuffle lines in a file
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     May 12, 1996
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #  
  17. #     This program writes a version of the input file with the lines
  18. #  shuffled.  For example, the result of shuffling
  19. #  
  20. #                   On the Future!-how it tells
  21. #                   Of the rapture that impells
  22. #                  To the swinging and the ringing
  23. #                   Of the bells, bells, bells-
  24. #                Of the bells, bells, bells, bells,
  25. #                          Bells, bells, bells-
  26. #            To the rhyming and the chiming of the bells!
  27. #  
  28. #  is
  29. #  
  30. #            To the rhyming and the chiming of the bells!
  31. #                  To the swinging and the ringing
  32. #                          Bells, bells, bells-
  33. #                   Of the bells, bells, bells-
  34. #                   On the Future!-how it tells
  35. #                Of the bells, bells, bells, bells,
  36. #                   Of the rapture that impells
  37. #  
  38. #  The following options are supported:
  39. #
  40. #    -s i    Set random seed to i; default 0
  41. #    -r    Set random seed using randomize(); overrides -s
  42. #
  43. #  Limitation:
  44. #
  45. #     This program stores the input file in memory and shuffles pointers to
  46. #     the lines; there must be enough memory available to store the entire
  47. #     file.
  48. #  
  49. ############################################################################
  50. #
  51. #  Links: options, random
  52. #
  53. ############################################################################
  54.  
  55. link options
  56. link random
  57.  
  58. procedure main(args)
  59.    local opts, L
  60.  
  61.    opts := options(args, "rs+")
  62.    &random := \opts["s"]
  63.    if \opts["r"] then randomize()
  64.  
  65.    L := []
  66.    every put(L, !&input)
  67.    every write(!shuffle(L))
  68. end
  69.