home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / unix_c / usenet / prnews.sh < prev    next >
Encoding:
Text File  |  1989-03-21  |  5.1 KB  |  272 lines

  1.  4-Jan-86 04:15:17-MST,5433;000000000001
  2. Return-Path: <unix-sources-request@BRL.ARPA>
  3. Received: from BRL-TGR.ARPA by SIMTEL20.ARPA with TCP; Sat 4 Jan 86 04:15:10-MST
  4. Received: from usenet by TGR.BRL.ARPA id a007212; 4 Jan 86 5:42 EST
  5. From: "Col. G. L. Sicherman" <colonel@sunybcs.uucp>
  6. Newsgroups: net.sources
  7. Subject: prnews
  8. Message-ID: <2696@sunybcs.UUCP>
  9. Date: 3 Jan 86 15:32:42 GMT
  10. To:       unix-sources@BRL-TGR.ARPA
  11.  
  12. Do you ever get tired of sitting at the terminal and hitting the space
  13. bar?  Well, you should.  You look silly doing it.  The following script
  14. saves you the trouble by _printing_ the news.  If you have troff or
  15. ditroff, it will print in columns in 8-point Roman condensed, so you
  16. can pretend you're reading the New York Herald-Tribune.  It will even
  17. unrot jokes that need it, if you have a suitable rot-detector.
  18.  
  19. Warnings: it's klugy.  You'll probably have to tweak it.  And don't start
  20. it with the -uu option and then read news interactively; you'll clobber
  21. your .newsrc.  And syshats hate it because it's a hog.
  22.  
  23. I think you'll like it.
  24.  
  25. ------- DETACH CAREFULLY ALONG THIS LINE ----------------------------
  26. :    prnews [options] newsgroup ...
  27. :    print all articles in one or more newsgroups
  28. :
  29. :    -y    print with DITROFF, in columns
  30. :    -u    print only unread articles
  31. :    -uu    print only unread articles, mark articles read in .newsrc
  32. : debugging options:
  33. :    -d    divert to standard output
  34. :    -t    divert DITROFF output to standard output
  35. ::::::::::::::::
  36. : ISROT=false
  37. ISROT=/cs/staff/colonel/bin/isrot
  38. TMP=/usr/tmp
  39. NNSED=$TMP/prn$$n
  40. NNTMP=$TMP/prn$$x
  41. NUNU=$TMP/prn$$u
  42. GREPT=$TMP/prn$$g
  43. SED2=$TMP/prn$$s
  44. AWK2=$TMP/prn$$a
  45. PRINP=$TMP/prn$$i
  46. trap "rm -f $TMP/prn$$? ; exit" 0 1 2 13 15
  47. while
  48. test "$*"
  49. do
  50. case $1 in
  51. -y)    YFLAG=YFLAG; shift;;
  52. -uu)    UUFLAG=UUFLAG; UFLAG=UFLAG; shift;;
  53. -u)    UFLAG=UFLAG; shift;;
  54. -d)    DFLAG=DFLAG; shift;;
  55. -t)    TFLAG=TFLAG; shift;;
  56. -)    echo "$0: bad switch $1" >&2;exit;;
  57. *)    break;;
  58. esac
  59. done
  60. :    set up 2 sed scripts and 1 awk script.
  61. cat << \NNSED > $NNSED
  62. s/^[^ ]* /,/
  63. s/$/,/
  64. s/,\([0-9][0-9]*\),/,\1-\1,/g
  65. s/\([0-9][0-9]*\)-\([0-9][0-9]*\)/\1 l\
  66. \2 u/g
  67. s/^,//
  68. s/,$//
  69. s/,/\
  70. /g
  71. NNSED
  72. cat << \XSED >$SED2
  73. s/[     ][     ]*/ /g
  74. s/[     ][     ]*$//
  75. s/\\/&e/g
  76. s/====*/==/g
  77. s/\~\~\~\~*/\~\~/g
  78. s/<><>[<>]*/<>/g
  79. s/___*/__/g
  80. s/|/|\\|/g
  81. s/->/\\(&/g
  82. s/<-/\\(&/g
  83. s/---*/\\(em/g
  84. s/- - [- ]*-/\\-/g
  85. s/-/\\-/g
  86. s/\([ ([]\)"/\1``/g
  87. s/^"/``/
  88. s/ '\([^ ]\)/ `\1/g
  89. s/ '/ \\'/g
  90. s/^'/\\'/
  91. s/"/''/g
  92. s/^\./\\\&./
  93. s/^Subject: \(.*\)$/.SU "\1"/
  94. s/^From: \(.*\)$/.FR "\1"/
  95. s/^Date: \(.*\)$/.DA "\1"/
  96. XSED
  97. cat << \XAWK >$AWK2
  98. $1=="**********" {body=0; slash=index($2,"/"); g=substr($2,1,slash-1);
  99.     if (g!=g0) print ".NG",g; g0=g; print ".NA",substr($2,slash+1);next}
  100. length($1)>20 {print substr($1,1,20),"\&" substr($1,21,40),substr($1,41);
  101.     for (i=2; i<=NF; i++) print $i; next}
  102. /^\./ {print; next}
  103. /^[     ]*$/ {if (body++) print ".sp .6"; else print ".HE"; next}
  104. body<1 {next}
  105. {print}
  106. XAWK
  107. :    now print some NEWS!
  108. if test "$UUFLAG"
  109. then
  110. cp /dev/null $NUNU
  111. fi
  112. if test "$YFLAG"
  113. then
  114. cat << \XFORMAT >$PRINP
  115. .\"    font for news text
  116. .ds NF RC
  117. .nr PO 0.5i
  118. .nr TM 0.5i
  119. .po \n(POu
  120. .ll 1.7i
  121. .ps 8
  122. .vs 1.1m
  123. .de tm    \" top margin
  124. 'sp |\\n(TMu
  125. .nr co 0 1    \" which column
  126. ..
  127. .de en    \" end-macro
  128. .\"    remove yo-yo trap
  129. .    wh -.6i
  130. .    wh -.6i pn
  131. ..
  132. .de pn    \" page-number
  133. .    if \\n(co<1 \{\
  134. '    sp 1
  135. .    tl '''\fBPage %\fP' \}
  136. ..
  137. .em en
  138. .de bm    \" bot margin
  139. .    pn
  140. .    ie \\n+(co<4 \{\
  141. .    po +1.9i
  142. '    sp |\\n(TMu
  143. .    ns \}
  144. .    el \{\
  145. .    po \\n(POu
  146. '    bp \}
  147. ..
  148. .wh -.6i bm
  149. .de NG
  150. .    ce 3
  151. \l'1.5i'
  152. .ft B
  153. \\$1
  154. .ft \*(NF
  155. .    sp -.5
  156. \l'1.5i'
  157. ..
  158. .de NA
  159. .ds N@ \l'1.5i-\w'\fB\\$1\f\*(NF'u/2u'
  160. .ce 1
  161. .ft B
  162. \u\\*(N@\d\\$1\u\\*(N@\d
  163. .ft \*(NF
  164. ..
  165. .\"    SU - subject line(s)
  166. .de SU
  167. .    ds S@ "\\$1
  168. ..
  169. .\"    DA - date
  170. .de DA
  171. .    ds D@ "\\$1
  172. ..
  173. .\"    FR - from whom
  174. .de FR
  175. .    ds F@ "\\$1
  176. ..
  177. .\"    HE - dump heading
  178. .de HE
  179. .    ft B
  180. \\*(S@
  181. .    ft R
  182. .    br
  183. \\*(D@
  184. .    br
  185. .    ft I
  186. \\*(F@:
  187. .    ft \*(NF
  188. .    br
  189. ..
  190. .wh 0 tm
  191. XFORMAT
  192. fi
  193. for i
  194. do
  195.     d=/usr/spool/news/`echo $i | tr . /`
  196.     if test ! -d $d
  197.     then
  198.         echo "prnews: $i not found" >&2
  199.         continue
  200.     fi
  201.     cd $d
  202.     if test "$UFLAG"
  203.     then
  204.         grep "^$i[:!]" $HOME/.newsrc | sed -f $NNSED > $NNTMP
  205.         range=`ls -F | grep -v '[*/]' | sed -e 's/$/ n/' \
  206.         | sort -n $NNTMP - | awk '$2!="n"{x=$2;next} x=="u"{print $1}'`
  207.     else
  208.     range=`ls -F | grep -v '[*/]' | sort -n`
  209.     fi
  210.     for j in $range
  211.     do
  212.         last=$j
  213.         echo '**********' $i/$j '**********'
  214.         if test $i = net.jokes && $ISROT $j
  215.         then
  216.         tr A-Za-z N-ZA-Mn-za-m
  217.         else
  218.         cat
  219.         fi < $j
  220.     done
  221. :
  222. :    build new .newsrc records.
  223. :
  224.     if test "$UUFLAG"
  225.     then
  226.         cat -n $HOME/.newsrc |\
  227.         if grep "    $i[:!]" > $GREPT
  228.         then
  229.             awk '{printf "n %s\t%s", $1, $2}' < $GREPT >> $NUNU
  230.         else
  231.             echo -n n "0    $i:" >> $NUNU
  232.         fi
  233.         echo " 1-$last" >> $NUNU
  234.     fi
  235. done | if test "$YFLAG"
  236. then
  237. sed -f $SED2
  238. else
  239. cat
  240. fi | if test "$YFLAG"
  241. then
  242. awk -f $AWK2
  243. else
  244. cat
  245. fi >> $PRINP
  246. if test "$UUFLAG"
  247. then
  248.     cp $HOME/.newsrc $HOME/.newsrc.bak
  249.     cat -n $HOME/.newsrc.bak | \
  250.     sed -e 's/^/o /' | sort +1n -2 +0 -1 +2 -3 $NUNU - | \
  251.     sort -um +2 -3 | sed 's/^[^    ]*    //' > $HOME/.newsrc
  252. fi &
  253. if test "$DFLAG"
  254. then
  255.     cat $PRINP
  256. elif test "$YFLAG"
  257. then
  258.     if test "$TFLAG"
  259.     then
  260.         ditroff -t $PRINP
  261.     else
  262.         ditroff $PRINP
  263.     fi
  264. else
  265. lpr $PRINP
  266. fi
  267. -- 
  268. Col. G. L. Sicherman
  269. UU: ...{rocksvax|decvax}!sunybcs!colonel
  270. CS: colonel@buffalo-cs
  271. BI: csdsicher@sunyabva
  272.