home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume1 / newsweed < prev    next >
Internet Message Format  |  1986-11-30  |  6KB

  1. Date: Sun, 11 Nov 84 15:12:12 pst
  2. From: decvax!decwrl!turtlevax!ken (Ken Turkowski)
  3. Subject: Re: Table of contents for news
  4. Newsgroups: mod.sources
  5.  
  6. Subject: Newsweed: a program to delete unwanted news articles
  7.  
  8. # This is a shell archive.  Remove anything before this line, then
  9. # unpack it by saving it in a file and typing "sh file".  (Files
  10. # unpacked will be owned by you and have default permissions.)
  11. #
  12. # This archive contains:
  13. # newsweed newsweed.1
  14.  
  15. echo x - newsweed
  16. cat > "newsweed" << '//E*O*F newsweed//'
  17. #! /bin/sh
  18. TEMP=/tmp/weed$$
  19. : ${NEWSRC=$HOME/.newsrc}
  20. trap 'rm ${TEMP}?; exit' 0 2
  21. echo Making list of article titles
  22. readnews -l $* | sort -o ${TEMP}a
  23. if test -s ${TEMP}a
  24. then
  25.     cp ${TEMP}a ${TEMP}b
  26.     echo Please remove article titles which you do not wish to read
  27.     sleep 1
  28.     # Delete the next line if you don't have reset
  29.     reset    # So that vi's CRLF doesn't get trashed by another vi
  30.     ${EDITOR-vi} ${TEMP}b
  31.     if cmp -s ${TEMP}a ${TEMP}b
  32.     then
  33.     echo No articles deleted.
  34.     else
  35.     comm -23 ${TEMP}a ${TEMP}b | sed 's/ .*//' > ${TEMP}c
  36.     echo Removing unwanted articles
  37.     cp $NEWSRC $NEWSRC.old
  38.     awk 'BEGIN    {
  39.     groupcount = 1
  40.     }
  41.  
  42. /^options/    {
  43.     options = $0
  44.     }
  45.  
  46. /^[^/]*:/    {            # .newsrc input -- subscribed group
  47.     j = index($0, ":")
  48.     group = substr($0, 1, j-1)
  49.     i = groupindex[group] = groupcount++
  50.     newsgroup[i] = group
  51.     grouptype[i] = ":"
  52.     newsread[i] = substr($0, j+2)    # list of articles read
  53.     }
  54.  
  55. /^[^/]*!/    {            # .newsrc input -- unsubscribed group
  56.     j = index($0, "!")
  57.     group = substr($0, 1, j-1)
  58.     i = groupindex[group] = groupcount++
  59.     newsgroup[i] = group
  60.     grouptype[i] = "!"
  61.     newsread[i] = substr($0, j+2)    # list of articles read
  62.     }
  63.  
  64. /^[^ /]+\/[0-9]+/    {        # readnews -l output
  65.     j = index($0, "/")
  66.     group = substr($0, 1, j-1)
  67.     i = groupindex[group]
  68.     if (!i) {        # not previously encountered
  69.         i = groupindex[group] = groupcount++
  70.         newsgroup[i] = group
  71.         grouptype[i] = ":"
  72.     }
  73.     k = index($0, " ")
  74.     if (k == 0)
  75.         article = substr($0, j+1)
  76.     else
  77.         article = substr($0, j+1, k-j-1)
  78.     if (newsread[i])
  79.         newsread[i] = newsread[i] "," article
  80.     else
  81.         newsread[i] = article
  82.     }
  83.  
  84. END    {
  85.     if (options != 0)
  86.         print options
  87.     for (i = 1; i < groupcount; i++) {
  88.         n = split(newsread[i], artlist, ",")
  89.         for (j = 1; j <= n; j++) {
  90.         if (split(artlist[j], range, "-") == 1) {
  91.             rangelist[j] = artlist[j]
  92.         }
  93.         else {
  94.             artlist[j] = range[1]
  95.             rangelist[j] = range[2]
  96.         }
  97.         }
  98.         # sort articles
  99.         sorted = 0
  100.         start = 1
  101.         while (sorted == 0) {
  102.         sorted = 1
  103.         for (j = start; j < n; j++) {
  104.             if (j == start && !artlist[start]) {
  105.             start++
  106.             continue
  107.             }
  108.             if (artlist[j+1] < artlist[j]) {    # swap
  109.             temp = artlist[j+1]
  110.             artlist[j+1] = artlist[j]
  111.             artlist[j] = temp
  112.             temp = rangelist[j+1]
  113.             rangelist[j+1] = rangelist[j]
  114.             rangelist[j] = temp
  115.             sorted = 0
  116.             }
  117.             if (artlist[j] && rangelist[j]+1 == artlist[j+1]) {    # merge
  118.             artlist[j+1] = artlist[j]
  119.             artlist[j] = ""
  120.             rangelist[j] = ""
  121.             }
  122.         }
  123.         }
  124.         printf "%s%s", newsgroup[i], grouptype[i]
  125.         first = 1
  126.         for (j = start; j <= n; j++) {
  127.         if (artlist[j]) {
  128.             if (first == 0) printf ","
  129.             else printf " "
  130.             first = 0
  131.             if (artlist[j] != rangelist[j])
  132.             printf "%d-%d", artlist[j], rangelist[j]
  133.             else
  134.             printf "%d", artlist[j]
  135.         }
  136.         }
  137.         printf "\n"
  138.     }
  139.     }' $NEWSRC.old ${TEMP}c > ${TEMP}d
  140.     cp ${TEMP}d $NEWSRC
  141.     fi
  142. else
  143.     echo No news.
  144. fi
  145. //E*O*F newsweed//
  146.  
  147. echo x - newsweed.1
  148. sed 's/^x//' > "newsweed.1" << '//E*O*F newsweed.1//'
  149. x.TH NEWSWEED 1 local
  150. x.SH NAME
  151. xnewsweed
  152. x.SH SYNOPSIS
  153. x.B newsweed
  154. x[readnews options]
  155. x.br
  156. x.B readnews
  157. x.SH DESCRIPTION
  158. x.I Newsweed
  159. xis a program to help in managing the vast number of articles
  160. xin the network news.
  161. xIt is used to delete articles that are not interesting
  162. xbefore using
  163. x.IR readnews ,
  164. x.IR vnews ,
  165. xor
  166. x.I rn
  167. xto read them.
  168. x.PP
  169. xA while after invoking
  170. x.I newsweed,
  171. xthe user is presented with a list of titles of news articles
  172. xin his preferred editor,
  173. xas indicated by the environment variable EDITOR
  174. x(\fIvi\fR is the default).
  175. xThen the user deletes lines containing titles of undesired articles,
  176. xwrites the file,
  177. xand lets
  178. x.I newsweed
  179. xmodify the
  180. x.I .newsrc
  181. xfile so that the undesired articles will not be presented.
  182. xThe previous
  183. x.I .newsrc
  184. xis saved as
  185. x.I .newsrc.old.
  186. xIf a newsrc file other than $HOME/.newsrc is desired,
  187. xone may set the environment variable
  188. x.I NEWSRC
  189. xto an appropriate filename.
  190. x.PP
  191. xTypically, one ends up deleting 80% of new news,
  192. xand saving an immense amount of time.
  193. x.SH FILES
  194. x~/.newsrc
  195. x.SH SEE ALSO
  196. xreadnews(1), vnews(1), rn(1), checknews(1)
  197. x.SH AUTHOR
  198. xKen Turkowski (turtlevax!ken)
  199. x.SH BUGS
  200. xThe title file is presented in alphabetical order
  201. xand should remain in alphabetical order;
  202. xotherwise not all of the uninteresting articles will be deleted
  203. x(this could be fixed with yet one more sort, though).
  204. x.PP
  205. xIt may take a long time to generate the titles file if
  206. x.I newsweed
  207. xis used to catch up on a backlog of news,
  208. xas after returning from vacation;
  209. xthe csh ^Z stop signal is useful to put newsweed into the background
  210. xduring phases other than the EDIT phase.
  211. x.PP
  212. xThe options line must not be continued with tabs on subsequent lines.
  213. x.PP
  214. xSome machines may not like long command lines,
  215. xso the awk program may need to be put into a file.
  216. x.PP
  217. xSmall machines may bomb because of the large amount of memory
  218. xused when there are a lot of newsgroups.
  219. xI suspect that the awk script could be rewritten
  220. xto be more conservative of memory.
  221. //E*O*F newsweed.1//
  222.  
  223. echo Possible errors detected by \'sum\' [hopefully none]:
  224. temp=/tmp/shar$$
  225. trap "rm -f $temp; exit" 0 1 2 3 15
  226. cat > $temp <<\!!!
  227. 30088     3 newsweed
  228. 51017     2 newsweed.1
  229. !!!
  230. sum  newsweed newsweed.1 | sed 's=[^ ]*/==' | diff -b $temp -
  231. exit 0
  232.  
  233.  
  234.