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

  1. ############################################################################
  2. #
  3. #    File:     diffsum.icn
  4. #
  5. #    Subject:  Program to count lines affected by a diff
  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:  diffsum [file]
  18. #
  19. #  Diffsum reads a file containing output from a run of the Unix "diff"
  20. #  utility.  Diffsum handles either normal diffs or context diffs.  For
  21. #  each pair of files compared, diffsum reports two numbers:
  22. #    1. the number of lines added or changed
  23. #    2. the net change in file size
  24. #  The first of these indicates the magnitude of the changes and the
  25. #  second the net effect on file size.
  26. #
  27. ############################################################################
  28.  
  29. global oldname, newname
  30. global added, deleted, chgadd, chgdel
  31.  
  32. procedure main(args)
  33.    local f, line
  34.  
  35.    if *args > 0 then
  36.       f := open(args[1]) | stop("can't open ", args[1])
  37.    else
  38.       f := &input
  39.  
  40.    added := deleted := 0
  41.    oldname := newname := ""
  42.    chgadd := chgdel := 0
  43.  
  44.    while line := read(f) do line ? {
  45.       if =" " then
  46.          next
  47.       else if ="***" then {
  48.          chgadd := 0
  49.          chgdel := +1
  50.          }
  51.       else if ="---" then {        # n.b. must precede tests below
  52.          chgadd := +1
  53.          chgdel := 0
  54.          }
  55.       else if any('+>') then
  56.          added +:= 1
  57.       else if any('-<') then
  58.          deleted +:= 1
  59.       else if ="!" then {
  60.          added +:= chgadd
  61.          deleted +:= chgdel
  62.          }
  63.       else if ="diff" then {
  64.          report()
  65.          while =" -" do tab(upto(' '))
  66.          tab(many(' '))
  67.          oldname := tab(upto(' ')) | "???"
  68.          tab(many(' '))
  69.          newname := tab(0)
  70.          }
  71.       else if ="Only " then
  72.          only()
  73.       }
  74.    report()
  75. end
  76.  
  77. procedure report()
  78.    local net
  79.  
  80.    if added > 0 | deleted > 0 then {
  81.       net := string(added - deleted)
  82.       if net > 0 then
  83.          net := "+" || net
  84.       write(right(added, 6) || right(net, 8), "\t", oldname, " ", newname)
  85.       }
  86.    added := deleted := 0
  87.    chgadd := chgdel := 0
  88.    return
  89. end
  90.  
  91. procedure only()
  92.    report()
  93.    if tab(-2) & ="." & any('oa') then
  94.       return
  95.    tab(1)
  96.    write("#\t", tab(0))
  97. end
  98.