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

  1. ############################################################################
  2. #
  3. #    File:     diffu.icn
  4. #
  5. #    Subject:  Program to show differences in files
  6. #
  7. #    Author:   Rich Morin
  8. #
  9. #    Date:     January 3, 1993
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program exercises the dif() procedure, making it act like the
  18. #  UNIX diff(1) file difference command.
  19. #
  20. #  Usage: diffu f1 f2
  21. #
  22. #    3d2
  23. #    < c
  24. #    7,8c6,7
  25. #    < g
  26. #    < h
  27. #    ---
  28. #    > i
  29. #    > j
  30. #
  31. ############################################################################
  32. #
  33. #  Links:  dif
  34. #
  35. ############################################################################
  36.  
  37. link dif
  38.  
  39. invocable all
  40.  
  41. procedure main(arg)
  42.   local f1, f2, ldr, n1, p1, n2, p2, h
  43.  
  44.   if *arg ~= 2 then
  45.     zot("usage: diffu f1 f2")
  46.  
  47.   f1 := open(arg[1]) | zot("cannot open " || arg[1])
  48.   f2 := open(arg[2]) | zot("cannot open " || arg[2])
  49.  
  50.   every ldr := dif([f1,f2]) do {
  51.     n1 := *ldr[1].diffs; p1 := ldr[1].pos
  52.     n2 := *ldr[2].diffs; p2 := ldr[2].pos
  53.  
  54.     if n1 = 0 then {            # add lines
  55.       h := p1-1 || "a" || p2
  56.       if n2 > 1 then
  57.         h ||:= "," || (p2 + n2 - 1)
  58.       write(h)
  59.       every write("> " || !ldr[2].diffs)
  60.     }
  61.     else if n2 = 0 then {        # delete lines
  62.       h := p1
  63.       if n1 > 1 then
  64.         h ||:= "," || (p1 + n1 - 1)
  65.       h ||:= "d" || p2-1
  66.       write(h)
  67.       every write("< " || !ldr[1].diffs)
  68.     }
  69.     else {                # change lines
  70.       h := p1
  71.       if n1 > 1 then
  72.         h ||:= "," || (p1 + n1 - 1)
  73.       h ||:= "c" || p2
  74.       if n2 > 1 then
  75.         h ||:= "," || (p2 + n2 - 1)
  76.       write(h)
  77.       every write("< " || !ldr[1].diffs)
  78.       write("---")
  79.       every write("> " || !ldr[2].diffs)
  80.     }
  81.   }
  82. end
  83.  
  84.  
  85. procedure zot(msg)                # exit w/message
  86.   write(&errout, "diff: " || msg)
  87.   exit(1)
  88. end
  89.