home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1014 < prev    next >
Internet Message Format  |  1990-12-28  |  5KB

  1. From: lwall@jato.Jpl.Nasa.Gov (Larry Wall)
  2. Newsgroups: alt.sources
  3. Subject: Re: Casefix - "Fix" all upper/lower case messages
  4. Message-ID: <3083@jato.Jpl.Nasa.Gov>
  5. Date: 13 Mar 90 20:36:46 GMT
  6.  
  7. In article <6392@orca.wv.tek.com> jeff@quark.WV.TEK.COM (Jeff Beadles) writes:
  8. : HAVE YOU BEEN SHOUTED AT ONCE TOO OFTEN IN ALL UPPER CASE?
  9. : or, do you hate it when you get messages that are in all lower case?
  10. : If so, then casefix might be the next best thing to user education.
  11. : I tossed this together one morning, when I had received yet another file that
  12. : was in all upper case.  It works as a filter, so you can do things like
  13. : (from rn)
  14. :   End of article 123 (of 123)--what next? [npq] | ~/.bin/casefix | more
  15. : Have fun!   I'll send it to comp.sources.misc in a few weeks.  (Time to get any
  16. : remaining kinks out.)
  17.  
  18. Here's something that does proper nouns too.  Think of it as complementary
  19. to the casefix program, since this trades a little more startup time (and
  20. running time (and memory)) for the proper nouns.  It was written for Peter Yee
  21. a while back to translate Nasa Headline News, which comes out in upper-case
  22. only, and which he was (bless his heart) translating by hand every time.
  23.  
  24. So the exception list that comes with it is for Nasa stuff, but you could
  25. make it do whatever you want.  Any proper nouns in /usr/dict/words, and
  26. any acronyms containing no vowels, are automatically capitalized without
  27. having to be in the exception list.
  28.  
  29. Requires perl 3.0, patchlevel 12.
  30.  
  31. Larry Wall
  32. lwall@jpl-devvax.jpl.nasa.gov
  33.  
  34. #!/bin/sh
  35. : make a subdirectory, cd to it, and run this through sh.
  36. echo 'If this kit is complete, "End of kit" will echo at the end'
  37. echo Extracting unuc
  38. sed >unuc <<'!STUFFY!FUNK!' -e 's/X//'
  39. X#!/usr/bin/perl
  40. X
  41. Xprint STDERR "Loading proper nouns...\n";
  42. Xopen(DICT,"/usr/dict/words") || die "Can't find /usr/dict/words: $!\n";
  43. Xwhile (<DICT>) {
  44. X    if (/^[A-Z]/) {
  45. X    chop;
  46. X    ($lower = $_) =~ y/A-Z/a-z/;
  47. X    $proper{$lower} = $_;
  48. X    }
  49. X}
  50. Xclose DICT;
  51. Xprint STDERR "Loading exceptions...\n";
  52. X
  53. Xopen(PATS,"unuc.pats") || die "Can't find unuc.pats: $!\n";
  54. X
  55. X$prog = <<'EOT';
  56. Xwhile (<>) {
  57. X    next if /[a-z]/;
  58. X    y/A-Z/a-z/;
  59. X    s/(\w+)/$proper{$1} ? $proper{$1} : $1/eg;
  60. X    s/^(\s*)([a-z])/$1 . (($tmp = $2) =~ y:a-z:A-Z:,$tmp)/e;
  61. X    s/([-.?!]["']?(\n\s*|  \s*)["']?)([a-z])/$1 . (($tmp = $3) =~ y:a-z:A-Z:,$tmp)/eg;
  62. X    s/\b([b-df-hj-np-tv-xz]+)\b/(($tmp = $1) =~ y:a-z:A-Z:,$tmp)/eg;
  63. X    s/([a-z])'([SDT])\b/$1 . "'" . (($tmp = $2) =~ y:A-Z:a-z:,$tmp)/eg;
  64. XEOT
  65. Xwhile (<PATS>) {
  66. X    chop;
  67. X    next if /^$/;
  68. X    next if /^#/;
  69. X    if (! /;$/) {
  70. X    $foo = $_;
  71. X    $foo =~ y/A-Z/a-z/;
  72. X    print STDERR "Dup $_\n" if $proper{$foo};
  73. X    $foo =~ s/([^\w ])/\\$1/g;
  74. X    $foo =~ s/ /(\\s+)/g;
  75. X    $foo = "\\b" . $foo if $foo =~ /^\w/;
  76. X    $foo .= "\\b" if $foo =~ /\w$/;
  77. X    $i = 0;
  78. X    ($bar = $_) =~ s/ /'$' . ++$i/eg;
  79. X    $_ = "s/$foo/$bar/gi;";
  80. X    }
  81. X    $prog .= '    ' . $_ . "\n";
  82. X}
  83. Xclose PATS;
  84. X$prog .= "}\ncontinue {\n    print;\n}\n";
  85. X
  86. X$/ = '';
  87. X#print $prog;
  88. Xeval $prog; die $@ if $@;
  89. !STUFFY!FUNK!
  90. echo Extracting unuc.pats
  91. sed >unuc.pats <<'!STUFFY!FUNK!' -e 's/X//'
  92. XA.M.
  93. XAir Force
  94. XAir Force Base
  95. XAir Force Station
  96. XAmerican
  97. XApr.
  98. XAriane
  99. XAug.
  100. XAugust
  101. XBureau of Labor Statistics
  102. XCIT
  103. XCaltech
  104. XCape Canaveral
  105. XChallenger
  106. XChina
  107. XCorporation
  108. XCrippen
  109. XDaily News in Brief
  110. XDaniel Quayle
  111. XDec.
  112. XDiscovery
  113. XEdwards
  114. XEndeavour
  115. XFeb.
  116. XFord Aerospace
  117. XFri.
  118. XGeneral Dynamics
  119. XGeorge Bush
  120. XHeadline News
  121. XHOTOL
  122. XI
  123. XII
  124. XIII
  125. XIV
  126. XIX
  127. XInstitute of Technology
  128. XJPL
  129. XJan.
  130. XJul.
  131. XJun.
  132. XKennedy Space Center
  133. XLDEF
  134. XLong Duration Exposure Facility
  135. XLong March
  136. XMar.
  137. XMarch
  138. XMartin
  139. XMartin Marietta
  140. XMercury
  141. XMon.
  142. Xin May
  143. Xs/\bmay (\d)/May $1/g;
  144. Xs/\boffice of (\w)/'Office of ' . (($tmp = $1) =~ y:a-z:A-Z:,$tmp)/eg;
  145. XNational Science Foundation
  146. XNASA Select
  147. XNew Mexico
  148. XNov.
  149. XOMB
  150. XOct.
  151. XOffice of Management and Budget
  152. XPresident
  153. XPresident Bush
  154. XRichard Truly
  155. XRocketdyne
  156. XRussian
  157. XRussians
  158. XSat.
  159. XSep.
  160. XSoviet
  161. XSoviet Union
  162. XSoviets
  163. XSpace Shuttle
  164. XSun.
  165. XThu.
  166. XTue.
  167. XU.S.
  168. XUnion of Soviet Socialist Republics
  169. XUnited States
  170. XVI
  171. XVII
  172. XVIII
  173. XVice President
  174. XVice President Quayle
  175. XWed.
  176. XWhite Sands
  177. XKaman Aerospace
  178. XAerospace Daily
  179. XAviation Week
  180. XSpace Technology
  181. XWashington Post
  182. XLos Angeles Times
  183. XNew York Times
  184. XAerospace Industries Association
  185. Xpresident of
  186. XJohnson Space Center
  187. XSpace Services
  188. XInc.
  189. XCo.
  190. XHughes Aircraft
  191. XCompany
  192. XOrbital Sciences
  193. XSwedish Space
  194. XArnauld
  195. XNicogosian
  196. XMagellan
  197. XGalileo
  198. XMir
  199. XJet Propulsion Laboratory
  200. XUniversity
  201. XDepartment of Defense
  202. XOrbital Science
  203. XOMS
  204. XUnited Press International
  205. XUnited Press
  206. XUPI
  207. XAssociated Press
  208. XAP
  209. XCable News Network
  210. XCape York
  211. XZenit
  212. XSYNCOM
  213. XEastern
  214. XWestern
  215. XTest Range
  216. XJcsat
  217. XJapanese Satellite Communications
  218. XDefence Ministry
  219. XDefense Ministry
  220. XSkynet
  221. XFixed Service Structure
  222. XLaunch Processing System
  223. XAsiasat
  224. XLaunch Control Center
  225. XEarth
  226. XCNES
  227. XGlavkosmos
  228. XPacific
  229. XAtlantic
  230. !STUFFY!FUNK!
  231. echo ""
  232. echo "End of kit"
  233. : I do not append .signature, but someone might mail this.
  234. exit
  235.