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

  1. ############################################################################
  2. #
  3. #    File:     diffn.icn
  4. #
  5. #    Subject:  Program to show differences among files
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     January 3, 1994
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #  
  17. #   This program shows the differences between n files. Is is invoked as
  18. #
  19. #        diffn file1 file2 ... filen
  20. #  
  21. ############################################################################
  22. #
  23. #  Links: dif
  24. #
  25. ############################################################################
  26. #
  27. #  Most of the work is done by an external procedure, dif().  This
  28. #  program analyzes the command line arguments, sets up a call to
  29. #  dif(), and displays the results.
  30. #
  31.  
  32.  
  33. link dif
  34. global f1,f2
  35. record dfile(file,linenbr)
  36.  
  37. invocable all
  38.  
  39. procedure main(arg)
  40.   local f, i, files, drec, status
  41.   #
  42.   #  Analyze command line arguments, open the files, and output
  43.   #  some initial display lines.
  44.   #
  45.   if *arg < 2 then stop("usage: diffn file file ...")
  46.   f := list(*arg)
  47.   every i := 1 to *arg do
  48.         f[i] := dfile(open(arg[i]) | stop("Can't open ",arg[i]),0)
  49.   files := list(*arg)
  50.   every i := 1 to *arg do {
  51.     write("File ",i,": ",arg[i])
  52.     files[i] := diff_proc(myread,f[i])
  53.   }
  54.   #
  55.   #  Invoke dif() and display its generated results.
  56.   #
  57.   every drec := dif(files) do {
  58.     status := "diffs"
  59.     write("==================================")
  60.     every i := 1 to *drec do {
  61.       write("---- File ",i,", ",
  62.                (drec[i].pos > f[i].linenbr & "end of file") |
  63.          "line " || drec[i].pos,
  64.          " ---- (",arg[i],")")
  65.       listrange(drec[i].diffs,drec[i].pos)
  66.     }
  67.   }
  68.   if /status then write("==== Files match ====")
  69.   return
  70. end
  71.  
  72.  
  73. #
  74. #  listrange() -- List a range of differing lines, each preceded by its
  75. #  line number.
  76. #
  77. procedure listrange(dlist,linenbr)
  78.   local x
  79.   every x := !dlist do {
  80.     write(x); linenbr +:= 1
  81.   }
  82.   return
  83. end
  84.  
  85.  
  86. #
  87. #  myread() -- Line-reading procedure to pass to dif().
  88. #
  89. procedure myread(x)
  90.   return x.linenbr <- x.linenbr + 1 & read(x.file)
  91. end
  92.  
  93.