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

  1. ############################################################################
  2. #
  3. #    File:     lam.icn
  4. #
  5. #    Subject:  Program to laminate files
  6. #
  7. #    Author:   Thomas R. Hicks
  8. #
  9. #    Date:     June 10, 1988
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #  
  17. #     This program laminates files named on the command line onto
  18. #  the standard output, producing a concatenation of corresponding
  19. #  lines from each file named.  If the files are different lengths,
  20. #  empty lines are substituted for missing lines in the shorter
  21. #  files.  A command line argument of the form - s causes the string
  22. #  s to be inserted between the concatenated file lines.
  23. #  
  24. #     Each command line argument is placed in the output line at the
  25. #  point that it appears in the argument list.  For example, lines
  26. #  from file1 and file2 can be laminated with a colon between each
  27. #  line from file1 and the corresponding line from file2 by the com-
  28. #  mand
  29. #  
  30. #          lam file1 -: file2
  31. #  
  32. #     File names and strings may appear in any order in the argument
  33. #  list.  If - is given for a file name, standard input is read at
  34. #  that point.  If a file is named more than once, each of its lines
  35. #  will be duplicated on the output line, except that if standard
  36. #  input is named more than once, its lines will be read alter-
  37. #  nately.  For example, each pair of lines from standard input can
  38. #  be joined onto one line with a space between them by the command
  39. #  
  40. #          lam - "- " -
  41. #  
  42. #  while the command
  43. #  
  44. #          lam file1 "- " file1
  45. #  
  46. #  replicates each line from file1.
  47. #  
  48. ############################################################################
  49. #
  50. #  Links: usage
  51. #
  52. ############################################################################
  53.  
  54. link usage
  55.  
  56. global fndxs
  57.  
  58. procedure main(a)
  59.    local bufs, i
  60.    bufs := list(*a)
  61.    fndxs := []
  62.    if (*a = 0) | a[1] == "?" then Usage("lam file [file | -string]...")
  63.    every i := 1 to *a do {
  64.       if a[i] == "-" then {
  65.          a[i] := &input
  66.             put(fndxs,i)
  67.             }
  68.       else if match("-",a[i]) then {
  69.          bufs[i] := a[i][2:0]
  70.          a[i] := &null
  71.          }
  72.       else {
  73.          if not (a[i] := open(a[i])) then
  74.             stop("Can't open ",a[i])
  75.          else put(fndxs,i)
  76.          }
  77.      }
  78.    if 0 ~= *fndxs then lamr(a,bufs) else Usage("lam file [file | -string]...")
  79. end
  80.  
  81. procedure lamr(args,bufs)
  82.    local i, j
  83.    every i := !fndxs do
  84.       bufs[i] := (read(args[i]) | &null)
  85.    while \bufs[!fndxs] do {
  86.       every j := 1 to *bufs do
  87.          writes(\bufs[j])
  88.       write()
  89.       every i := !fndxs do
  90.          bufs[i] := (read(args[i]) | &null)
  91.      }
  92. end
  93.