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

  1. ############################################################################
  2. #
  3. #    File:     strpsgml.icn
  4. #
  5. #    Subject:  Program to strip/translate SGML tags
  6. #
  7. #    Author:   Richard L. Goerwitz
  8. #
  9. #    Date:     November 19, 1997
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #    Version:  1.9
  18. #
  19. ############################################################################
  20. #
  21. #  Strip or perform simple translation on SGML <>-style tags.  Usage
  22. #  is as follows:
  23. #
  24. #      strpsgml [-f translation-file] [left-delimiter [right-delimiter]]
  25. #
  26. #  The default left-delimiter is <, the default right delimiter is >.
  27. #  If no translation file is specified, the program acts as a strip-
  28. #  per, simply removing material between the delimiters.  Strpsgml
  29. #  takes its input from stdin, writing to stdout.
  30. #
  31. #  The format of the translation file is:
  32. #
  33. #      code    initialization    completion
  34. #
  35. #  A tab or colon separates the fields.  If you want to use a tab or colon
  36. #  as part of the text (and not as a separator), place a backslash before
  37. #  it.  The completion field is optional.  There is not currently any way
  38. #  of specifying a completion field without an initialization field.  Do
  39. #  not specify delimiters as part of code.
  40. #
  41. #  Note that, if you are translating SGML code into font change or escape
  42. #  sequences, you may get unexpected results.  This isn't strpsgml's
  43. #  fault.  It's just a matter of how your terminal or WP operate.  Some
  44. #  need to be "reminded" at the beginning of each line what mode or font
  45. #  is being used.  Note also that stripsgml assumes < and > as delimiters.
  46. #  If you want to put a greater-than or less-than sign into your text,
  47. #  put a backslash before it.  This will effectively "escape" the spe-
  48. #  cial meaning of those symbols.  It is now possible to change the
  49. #  default delimiters, but the option has not been thoroughly tested.
  50. #
  51. ############################################################################
  52. #
  53. #  Links: scan, stripunb, readtbl
  54. #
  55. ############################################################################
  56.  
  57. link scan
  58. link stripunb
  59. link readtbl
  60.  
  61. procedure main(a)
  62.  
  63.     local usage, _arg, L, R, map_file, t, readtbl, line, stripunb, last_k
  64.  
  65.     usage:=
  66.      "usage:  stripsgml [-f map-file] [left-delimiter(s) [right-delimiter(s)]]"
  67.  
  68.     L := '<'; R := '>'
  69.     while _arg := get(a) do {
  70.         if _arg == "-f" then {
  71.             map_file := open(get(a)) |
  72.                 stop("stripsgml:  can't open map_file\n",usage)
  73.             t := readtbl(map_file)
  74.         }
  75.         else {
  76.             L := _arg
  77.             R := cset(get(a))
  78.         }
  79.     }
  80.  
  81.     every line := !&input do
  82.     write(stripunb(L,R,line,&null,&null,t))  # t is the map table
  83.  
  84.     # last_k is the stack used in stripunb.icn
  85.     if *\last_k ~= 0 then
  86.     stop("Unexpected EOF encountered.  Expecting ", pop(last_k), ".")
  87.  
  88. end
  89.