home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / armlinux / alpha / PARTITIONS / USR_GZ / usr / lib / trn / Speller < prev   
Encoding:
Text File  |  1995-05-14  |  3.4 KB  |  164 lines

  1. #!/bin/sh
  2. # $Id: Speller.SH,v 3.0 1992/02/23 21:25:39 davison Trn $
  3. #    Speller - a script to disassemble a posting; use ispell to spell-
  4. #    check the body along with the Subject, Keywords, and Summary lines;
  5. #    and put it all back together again.
  6. #
  7. #    Written by Eric Schnoebelen, (eric@cirr.com)
  8. #                    Fri May 14 20:33:48 CDT 1993
  9.  
  10. export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0; kill $$)
  11.  
  12. # what pager you use--if you have kernal paging use cat
  13. pager="${PAGER-/bin/more}"
  14. # either the ispell program or "none"
  15. ispell=/usr/bin/ispell
  16. ispell_options=
  17. test=test
  18. sed=/usr/bin/sed
  19. echo=/bin/echo
  20. cat=/bin/cat
  21. awk=/usr/bin/awk
  22. rm=/bin/rm
  23. mv=/bin/mv
  24. diff=diff
  25. ed=ed
  26. spell=spell
  27. basename=/usr/bin/basename
  28.  
  29. tmpdir="${TMPDIR-/tmp}"
  30.  
  31. # get us some temporary files.
  32. hdrs=$tmpdir/sp$$hdr
  33. body=$tmpdir/sp$$body
  34. sig=$tmpdir/sp$$sig
  35. mine=$tmpdir/sp$$mine
  36. quoted=$tmpdir/sp$$quoted
  37. bad=$tmpdir/sp$$bad
  38.  
  39. Cmdname=`$basename $0`
  40.  
  41. if $test "X$1" = X; then
  42.     $echo "$Cmdname: insufficent arguments" >&2
  43.     $echo "$Cmdname: usage: $Cmdname <filename>" >&2 
  44.     exit 1
  45. fi
  46.  
  47. trap "$rm -f $hdrs $body $body~ $sig $mine $quoted $bad; exit 1" 0 1 2 15
  48.  
  49. while $test "X$1" != X; do
  50.  
  51.     # create the files, so that cat is quiet later..
  52.     >$hdrs
  53.     >$body
  54.     >$sig
  55.     >$mine
  56.     >$quoted
  57.  
  58.     # tear the wanted headers out and toss them at body, leaving the 
  59.     # the remainder to be put back in later.
  60.  
  61.     $awk 'BEGIN { inhdr = 1; keephdr = 0; insig = 0 } 
  62.     /^$/        { 
  63.             inhdr = 0;
  64.             print $0 > Body;
  65.             next;
  66.             }
  67.     /^-- $/        {
  68.             insig = 1;
  69.             print $0 > Sig;
  70.             next;
  71.             }
  72.     /^Subject: /    { 
  73.             if (inhdr) { 
  74.                 keephdr = 1;
  75.                 print $0 > Body;
  76.                 next;
  77.             }  
  78.             }
  79.     /^Keywords: /    {
  80.             if (inhdr) { 
  81.                 keephdr = 1;
  82.                 print $0 > Body 
  83.             }
  84.             next;
  85.             }
  86.     /^Summary: /    { if (inhdr) { 
  87.                 keephdr = 1;
  88.                 print $0 > Body 
  89.             }
  90.             next;
  91.             }
  92.     /^[ \t]/    {
  93.                 if (keephdr && indhr) {
  94.                 print $0 > Body;
  95.                 } else if (inhdr) {
  96.                 print $0 > Hdrs;
  97.                 }
  98.             }
  99.     /^.*: /        { if (inhdr) { 
  100.                 keephdr = 0;
  101.                 print $0 > Hdrs;
  102.                 next;
  103.             } }
  104.     /^.*$/        { if (!inhdr && !insig) {
  105.                 print $0 > Body;
  106.                 next;
  107.             } 
  108.             if (insig) {
  109.                 print $0 > Sig;
  110.                 next
  111.             } }
  112.     ' Body=$body Hdrs=$hdrs Sig=$sig $1
  113.  
  114.     # now rip out the quoted text from the article, so we only
  115.     # spell check our own pristine prose..
  116.  
  117.     if $test "X$QUOTECHARS" = X ; then
  118.     $mv $body $mine
  119.     else
  120.     $sed -e "/^$QUOTECHARS/s/.*//" $body >$mine
  121.     $diff -e $mine $body > $quoted
  122.     fi
  123.  
  124.     # ok, we've torn everything asunder, now lets spell check
  125.     # the guts of the article..
  126.  
  127.     if $test "X$ispell" = "Xnone"; then
  128.     $spell $ispell_options $mine > $bad
  129.     if $test -s $bad ; then
  130.         ($echo ---- misspelled words -------------------------------------
  131.          #$cat $bad | fmt
  132.          $cat $bad | pr -t -4
  133.          $echo -----------------------------------------------------------
  134.         ) | $pager
  135.     else
  136.         $echo 'No misspelled words.'
  137.     fi
  138.     else
  139.     $ispell $ispell_options $mine
  140.     fi
  141.  
  142.     if $test $? -ne 0; then
  143.     $echo "$Cmdname: error returned, leaving message untouched"
  144.  
  145.     # don't want to mess with this file again, either
  146.     shift
  147.     continue
  148.     fi
  149.  
  150.     # resurrect the body of the article..
  151.     if $test -s $quoted ; then
  152.     ($cat $quoted; $echo w $body; $echo q) | $ed - $mine
  153.     else
  154.     $mv $mine $body
  155.     fi
  156.  
  157.     # ..and re-assemble the article.
  158.     $cat $hdrs $body $sig >$1
  159.  
  160.     # move to the next filename!
  161.     shift
  162.  
  163. done
  164.