home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume30 / langmml / part01 < prev    next >
Encoding:
Text File  |  1992-05-23  |  8.1 KB  |  272 lines

  1. Newsgroups: comp.sources.misc
  2. From: oscar@cui.unige.ch (" (Oscar Nierstrasz)")
  3. Subject:  v30i015:  langmml - turn The Language List into a Framemaker document, Part01/01
  4. Message-ID: <1992May23.175007.17027@sparky.imd.sterling.com>
  5. X-Md4-Signature: c09795adf007bf6e96522b6895e3e117
  6. Date: Sat, 23 May 1992 17:50:07 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: oscar@cui.unige.ch (Oscar Nierstrasz)
  10. Posting-number: Volume 30, Issue 15
  11. Archive-name: langmml/part01
  12. Environment: Framemaker
  13.  
  14. langmml is a shell script that generates a Framemaker MML document
  15. from The Language List -- a list of all known programming languages
  16. regularly posted on comp.lang.misc.  The List is a plain ascii file.
  17. The script generates a prettier version of the same document.
  18. There are two subscripts used by langmml -- framechars and quote --
  19. which are also included.
  20.  
  21. Oscar Nierstrasz
  22.  
  23. #! /bin/sh
  24. # This is a shell archive.  The files and directories it contains
  25. # may be unpacked by running it through /bin/sh.
  26. # Packaged by oscar at cuisun48 on Sat May 2 17:32:29 MET DST 1992
  27. # Contents:
  28. # -rwxr-xr-x  1 oscar        4021 May  2 17:31 langmml
  29. # -rwxr-xr-x  1 oscar         257 May  2 17:15 framechars
  30. # -rwxr-xr-x  1 oscar         905 May  2 17:15 quote
  31. if test -f langmml
  32. then echo 'shar: langmml -- file exists'
  33. else echo x - langmml
  34. sed 's/^|//' > langmml << 'eof'
  35. |#! /bin/sh
  36. |#
  37. |# langmml    --- generate MML file from The Language List
  38. |#
  39. |# Uses: quote framechars
  40. |#
  41. |# Author: Oscar Nierstrasz (oscar@cui.unige.ch) May 1992
  42. |#
  43. |# The Language List is regularly posted on comp.lang.misc.
  44. |# This shell script generates a FrameMaker MML file from the List
  45. |# that can be loaded into a Framemaker document, thus producing
  46. |# a prettier, more readable version of the list for printing out.
  47. |# Language names are shown in bold.
  48. |#
  49. |# Heuristics have been tailored for Version 1.7 of the List.
  50. |# You must define paragraph tags for Title, SubTitle, Body, Note, Lang
  51. |# and Sub for the document template that you will use.
  52. |#
  53. |# Suggestions:
  54. |# Title is for the document title (big, bold & centred).
  55. |# Subtitle is for the List itself and the appendices (bold & centred).
  56. |# Body is an ordinary paragraph.
  57. |# Note is a subsection heading (bold, italic).
  58. |# Lang is a language entry (first-line left-indented).
  59. |# Sub is a sub-entry for homonymic languages (indented).
  60. |
  61. |u='Usage: langmml <langlist>'
  62. |
  63. |case $# in
  64. |0 ) echo "$u" 1>&2 ; exit ;;
  65. |esac
  66. |
  67. |# Print the prologue:
  68. |
  69. |cat << 'eof'
  70. |<MML file -- generated by `langmml'>
  71. |<Units pica>
  72. |<!DefineTag Title>
  73. |<!DefineTag SubTitle>
  74. |<!DefineTag Body>
  75. |<!DefineTag Note>
  76. |<!DefineTag Lang>
  77. |<!DefineTag Sub>
  78. |<Comment -- linefeed = hard return>
  79. |<!DefineMacro lf "\\x0d " >
  80. |<!DefineMacro cr "\\x0a " >
  81. |<!DefineMacro endash        "<Character \\xd0 >" >
  82. |<!DefineMacro emdash        "<Character \\xd1 >" >
  83. |eof
  84. |
  85. |# INTRODUCTION
  86. |
  87. |# Process the introduction.
  88. |# Try to guess which lines are supposed to be broken, and
  89. |# which can be justified.  Mode 0 means the previous line was blank.
  90. |# Mode 1 means we are inside a justified paragraph.  Mode 2 means we
  91. |# are inside a list.
  92. |
  93. |awk '/\* \* \* \*/ { exit }
  94. |    { print } ' $* | \
  95. |quote | \
  96. |framechars | \
  97. |awk 'BEGIN { mode = 0 }
  98. |/^The Language List/ && (mode==0) {
  99. |    printf "\n<Title>\n%s", $0 ; mode = 1 ; next }
  100. |/^[A-Z].*: / && (mode==0) { printf "\n<Body>\n%s", $0 ; mode = 2 ; next }
  101. |/^[A-Z].*:$/ && (mode==0) { printf "\n<Note>\n%s", $0 ; mode = 2 ; next }
  102. |/^[A-Z]/ && (mode==0) { printf "\n<Note>\n%s", $0 ; mode = 2 ; next }
  103. |/^ / && (mode==0) { printf "\n<Body>\n%s", $0 ; mode = 1 ; next }
  104. |/^ / && (mode==1) { printf "<lf>\\\n%s", $0 ; next }
  105. |/^./ && (mode==1) { printf "\n%s", $0 ; next }
  106. |/^./ && (mode==2) { printf "<lf>\\\n%s", $0 ; next }
  107. |/^$/ { print ; mode = 0 }' | sed 's/^ *//'
  108. |
  109. |# BODY
  110. |
  111. |# Process the list itself.
  112. |# Embold the name of each language.  (Occurring on the first line
  113. |# of a paragraph before " - ".)  Homonyms are listed as a separate
  114. |# paragraph called <Sub>.
  115. |
  116. |awk '(NR==1),/\* \* \* \*/ { next }
  117. |/APPENDIX/ { exit }
  118. |    { print } ' $* | \
  119. |quote | \
  120. |framechars | \
  121. |awk 'BEGIN { print "\n<SubTitle>The Language List" ; mode = 0 }
  122. |/^ *[0-9]*\. / && (mode==0) {
  123. |    n = index($0,". ")
  124. |    printf "\n<Sub>\n%s", $0
  125. |    mode = 1 ; next }
  126. |/ -$/ && (mode==0) {
  127. |    printf "\n<Lang><Bold>%s<Plain> <emdash>", substr($0,0,length-2)
  128. |    mode = 1 ; next }
  129. |/ - / && (mode==0) {
  130. |    n = index($0," - ")
  131. |    printf "\n<Lang><Bold>%s<Plain> <emdash>", substr($0,0,n-1)
  132. |    printf "\n%s", substr($0,n+3)
  133. |    mode = 1 ; next }
  134. |/^[a-z]*: / || /^ftp [a-z ]*:/ {
  135. |    n = index($0,": ")
  136. |    printf "<lf>\\\n<Italic>%s:<Plain>", substr($0,0,n-1)
  137. |    printf "\n%s", substr($0,n+2)
  138. |    next }
  139. |/./ { printf "\n%s", $0 ; next }
  140. |/^$/ { print ; mode = 0 }' | sed 's/^ *//'
  141. |
  142. |# APPENDIX
  143. |
  144. |# Process the appendices.
  145. |# Again, try to guess where lines are supposed to be broken.
  146. |# Mode 3 means we are building up the subtitle.
  147. |
  148. |awk '/APPENDIX/ { app = 1 }
  149. |(app==1) { print } ' $* | \
  150. |quote | \
  151. |framechars | \
  152. |awk 'BEGIN { mode = 0 }
  153. |/^APPENDIX/ { printf "\n<SubTitle>%s", $0 ; mode = 3 ; next }
  154. |/^$/ && (mode==3) { next }
  155. |/./ && (mode==3) { printf "<lf>\\\n%s", $0 ; mode = 0 ; next }
  156. |/^==*$/ { next }
  157. |/^19[0-9][0-9]  / && (mode==0) {
  158. |    printf "\n<Body>%s", $0 ; mode = 2 ; next }
  159. |/./ && (mode==0) { printf "\n<Body>%s", $0 ; mode = 1 ; next }
  160. |/./ && (mode==1) { printf "\n%s", $0 ; next }
  161. |/./ && (mode==2) { printf "<lf>\\\n%s", $0 ; next }
  162. |/^$/ { print ; mode = 0 }' | sed 's/^ *//'
  163. |
  164. |exit
  165. |
  166. eof
  167. if test `wc -c < langmml` -ne 4021
  168. then echo 'shar: langmml damaged (should be 4021 bytes)'
  169. fi
  170. fi
  171. if test -f framechars
  172. then echo 'shar: framechars -- file exists'
  173. else echo x - framechars
  174. sed 's/^|//' > framechars << 'eof'
  175. |#! /bin/sed -f
  176. |#
  177. |# framechars    --- escape ascii characters with special meaning for Frame
  178. |#
  179. |# Author: Oscar Nierstrasz oscar@cui.unige.ch (920502)
  180. |s/\\/&&/g
  181. |s/    /\\t/g
  182. |s/[<>]/\\&/g
  183. |s/--/<Character \\xd0 >/g
  184. |s/``/<Character \\xd2 >/g
  185. |s/''/<Character \\xd3 >/g
  186. eof
  187. if test `wc -c < framechars` -ne 257
  188. then echo 'shar: framechars damaged (should be 257 bytes)'
  189. fi
  190. fi
  191. if test -f quote
  192. then echo 'shar: quote -- file exists'
  193. else echo x - quote
  194. sed 's/^|//' > quote << 'eof'
  195. |#! /bin/awk -f
  196. |#
  197. |# quote        --- convert double quotes to matched pairs of single quotes
  198. |#
  199. |# Correctly handles multi-line quotes.
  200. |# Tries to protect double quotes within equations, but
  201. |# will probably screw up for multi-line equations with quotes.
  202. |#
  203. |# Author: Oscar Nierstrasz @ utcsrgv!oscar    840529
  204. |# 881222: fixed handling of umlauts (\")
  205. |
  206. |BEGIN {    FS = "\""
  207. |    q[0] = "``"
  208. |    q[1] = "''"
  209. |    j = 0
  210. |    }
  211. |
  212. |/^\.EQ/,/^\.EN/ { print ; next }
  213. |/^\./ { print ; next }
  214. |
  215. |/\"/ {    if ($0 ~ /\$/) {
  216. |        n = split ($1, eq, "$") + 1
  217. |        k = n % 2
  218. |        printf "%s", $1
  219. |        for (i=2; i<=NF; i++) {
  220. |            if (k == 0)
  221. |                printf "%s%s", q[j], $i
  222. |            else    printf "\"%s", $i
  223. |            j = 1-j
  224. |            n = k + split ($i, eq, "$") + 1
  225. |            k = n % 2
  226. |            }
  227. |        printf "\n"
  228. |        }
  229. |    else {
  230. |        for (i=1; i<NF; i++) {
  231. |            if ($i ~ /\\$/)
  232. |                printf "%s\"", $i
  233. |            else {
  234. |                printf "%s%s", $i, q[j]
  235. |                j = 1-j
  236. |                }
  237. |            }
  238. |        printf "%s", $NF
  239. |        printf "\n"
  240. |        }
  241. |    next
  242. |    }
  243. |
  244. |{ print }
  245. |
  246. eof
  247. if test `wc -c < quote` -ne 905
  248. then echo 'shar: quote damaged (should be 905 bytes)'
  249. fi
  250. fi
  251. exit
  252.  
  253. -------------------------------------------------------------------
  254. Dr. O.M. Nierstrasz                 | Tel:    41 (22) 787.65.80
  255. Centre Universitaire d'Informatique | Fax:            735.39.05
  256. (University of Geneva)              | Home:           733.95.68
  257. 12 rue du Lac, CH-1207 Geneva       | E-mail: oscar@cui.unige.ch
  258. SWITZERLAND                         |         oscar@cgeuge51.bitnet
  259. -------------------------------------------------------------------
  260.             AFTER SEPT 1992:
  261. -------------------------------------------------------------------
  262. Dr. O.M. Nierstrasz                 | Tel:    41 (22) 705.71.11
  263. Centre Universitaire d'Informatique | Fax:            320.29.27
  264. University of Geneva                | Home:           733.95.68
  265. 24, rue du General-Dufour           |
  266. CH-1211 Geneva 4                    | E-mail: oscar@cui.unige.ch
  267. SWITZERLAND                         |         oscar@cgeuge51.bitnet
  268. -------------------------------------------------------------------
  269.  
  270.  
  271. exit 0 # Just in case...
  272.