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

  1. ############################################################################
  2. #
  3. #    File:     diffsort.icn
  4. #
  5. #    Subject:  Program to reorder "diff" output
  6. #
  7. #    Author:   Gregg M. Townsend
  8. #
  9. #    Date:     May 31, 1994
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #   Usage:  diffsort [file]
  18. #
  19. #   Diffsort reorders the output from the Unix "diff" program by moving
  20. #   one-line entries such as "Common subdirectory ..." and "Only in ..."
  21. #   to the front of the output file and sorting them.  Actual difference
  22. #   records then follow, in the original order, separated by lines of
  23. #   equal signs.
  24. #
  25. ############################################################################
  26.  
  27.  
  28. global clines    # comment lines
  29. global dlines    # diff lines
  30.  
  31.  
  32. ##  main program
  33.  
  34. procedure main(args)
  35.    clines := []
  36.    dlines := []
  37.  
  38.    if *args > 0 then
  39.       every dofile(!args)
  40.    else
  41.       dofile()
  42.  
  43.    every write(!sort(clines))
  44.    every write(!dlines)
  45. end
  46.  
  47.  
  48. ##  dofile(fname) - process one named file, or standard input if unnamed  
  49.  
  50. procedure dofile(fname)
  51.    local f, separator
  52.  
  53.    if /fname then
  54.       f := &input
  55.    else
  56.       f := open(fname) | stop("can't open ", fname)
  57.  
  58.    separator := "\n\n" || repl("=", 78) || "\n\n"
  59.  
  60.    every !f ? {
  61.       if any(&ucase) then
  62.          put(clines, &subject)
  63.       else {
  64.          if ="diff " then
  65.             put(dlines, separator)
  66.          put(dlines, &subject)
  67.       }
  68.    }
  69.  
  70.    close(f)
  71.    return
  72. end
  73.