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

  1. ############################################################################
  2. #
  3. #    File:     edscript.icn
  4. #
  5. #    Subject:  Program to produce script for ed(1)
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     March 7, 1998
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #  
  17. #     This program takes specifications for global edits from standard
  18. #  input and outputs an edit script for the UNIX editor ed to standard output.
  19. #  Edscript is primarily useful for making complicated literal sub-
  20. #  stitutions that involve characters that have syntactic meaning to
  21. #  ed and hence are difficult to enter in ed.
  22. #  
  23. #     Each specification begins with a delimiter, followed by a tar-
  24. #  get string, followed by the delimiter, followed by the replace-
  25. #  ment string, followed by the delimiter.  For example
  26. #  
  27. #          |...|**|
  28. #          |****||
  29. #  
  30. #  specifies the replacement of all occurrences of three consecutive
  31. #  periods by two asterisks, followed by the deletion of all
  32. #  occurrences of four consecutive asterisks.  Any character may be
  33. #  used for the delimiter, but the same character must be used in
  34. #  all three positions in any specification, and the delimiter char-
  35. #  acter cannot be used in the target or replacement strings.
  36. #  
  37. #  Diagnostic:
  38. #  
  39. #     Any line that does not have proper delimiter structure is noted
  40. #  and does not contribute to the edit script.
  41. #  
  42. #  Reference:
  43. #  
  44. #     "A Tutorial Introduction to the UNIX Text Editor", Brian W. Kernighan.
  45. #  AT&T Bell Laboratories.
  46. #  
  47. ############################################################################
  48.  
  49. procedure main()
  50.    local line, image, object, char
  51.    while line := read() do {
  52.       line ? {
  53.          char := move(1) | {error(line); next}
  54.          image := tab(find(char)) | {error(line); next}
  55.          move(1)
  56.          object := tab(find(char)) | {error(line); next}
  57.          }
  58.       write("g/",xform(image),"/s//",xform(object),"/g")
  59.    }
  60.    write("w\nq")
  61. end
  62.  
  63. #  process characters that have meaning to ed
  64. #
  65. procedure insert()
  66.    static special
  67.    initial special := '\\/^&*[.$%'
  68.    suspend {
  69.       tab(upto(special)) ||
  70.       "\\" ||
  71.       move(1) ||
  72.       (insert() | tab(0))
  73.       }
  74. end
  75.  
  76. procedure error(line)
  77.    write(&errout,"*** erroneous input: ",line)
  78. end
  79.  
  80. #  transform line
  81. #
  82. procedure xform(line)
  83.    line ?:= insert()
  84.    return line
  85. end
  86.