home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / lang / mpw_maci.hqx / IconSamples.pit / col.icn < prev    next >
Encoding:
Text File  |  1986-12-06  |  1.4 KB  |  43 lines

  1. #
  2. #  Program to arrange file names into multiple columns.
  3. #
  4. #  This utility was written to rearrange the file name list from the
  5. #  Macintosh Programmer's Workshop "Files" command into a more convenient
  6. #  format.  "Files" lists file names in a single column.  This program
  7. #  takes the list produced by "Files" and outputs a multi-column list.
  8. #  The names are listed vertically within each column, and the column
  9. #  width is computed dynamically depending upon the sizes of the names
  10. #  listed.  A recommendation is to create a command file "lc" (List
  11. #  in Columns) as follows:
  12. #
  13. #    Files {"Parameters"} | col
  14. #
  15. #  The output from the Files command is "piped" to the "col" program
  16. #  (this program), which prints its list in the current window.
  17. #
  18. #  By putting both the "lc" command file and the "col" program
  19. #  into your {MPW}Tools folder, "lc" can be conveniently issued as a
  20. #  command at any time, using the same parameters as the "Files" command.
  21.  
  22. procedure main()
  23.   local entries,entry,max,cols,width,lines,i,j,t
  24.   repeat {
  25.     entries := []
  26.     max := 0
  27.     while entry := "" ~== read() do {
  28.       max <:= *entry
  29.       put(entries,entry)
  30.     }
  31.     cols := 80 / (max + 2)
  32.     width := 80 / cols
  33.     lines := (*entries + cols - 1) / cols
  34.     every i := 1 to lines do {
  35.       t := ""
  36.       every j := 0 to cols - 1 do
  37.         t ||:= left(entries[i + j * lines],width)
  38.       write(trim(t))
  39.     }
  40.     write("\n",read()) | break
  41.   }
  42. end
  43.