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 / irsort.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  75 lines

  1. ############################################################################
  2. #
  3. #    File:     irsort.icn
  4. #
  5. #    Subject:  Program to sort Icon record declaration
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     June 23, 2000
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #  
  17. #     This program reads an Icon program and writes an equivalent
  18. #  program with the record declaration sorted alphabetically at the
  19. #  end. Global, link, invocable, and procedure declarations come in the order
  20. #  they appear in the original program.
  21. #  
  22. #     Comments and white space between declarations are attached to
  23. #  the next following declaration.
  24. #  
  25. #  Limitations: This program only recognizes declarations that start
  26. #  at the beginning of a line.
  27. #  
  28. #     Comments and interline white space between declarations may
  29. #  not come out as intended.
  30. #
  31. #  Note:  This program is still raw.  White space and comments related
  32. #  to records may not come out as expected.  A closed parenthesis in
  33. #  a comment in the midst of a record declaration will cause havok.
  34. #
  35. ############################################################################
  36.  
  37.  
  38. procedure main(args)
  39.    local line, x, i, recordtable, recordlist, comments, recordname 
  40.  
  41.    comments := []            # list of comment lines
  42.    recordtable := table()        # table of record declarations
  43.  
  44.    while line := read() do {
  45.      line ? {
  46.         if ="record" &            #  record declaration
  47.            tab(many('\t ')) &
  48.            recordname := tab(upto('(')) | stop("*** bad syntax: ",line)
  49.         then {                # if main, force sorting order
  50.            recordtable[recordname] := x := []
  51.            put(x, line)
  52.            if upto(')', line) then next else while line := read() do {
  53.               put(x, line)
  54.               if upto(')', line) then break next
  55.               }
  56.            }
  57.                     #  other declarations
  58.          else if =("global" | "procedure" | "link" | "invocable")
  59.          then {
  60.             while write(get(comments))
  61.             write(line)
  62.             }
  63.          else put(comments, line)
  64.          }
  65.       }
  66.  
  67.    while write(get(comments))
  68.  
  69.    recordlist := sort(recordtable, 3)        #  sort record
  70.  
  71.    while get(recordlist) do
  72.       every write(!get(recordlist))
  73.  
  74. end
  75.