home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / alt / sources / 2842 < prev    next >
Encoding:
Text File  |  1992-12-22  |  11.3 KB  |  375 lines

  1. Newsgroups: alt.sources
  2. Path: sparky!uunet!mcsun!fuug!news.funet.fi!ousrvr.oulu.fi!phoenix!yaz
  3. From: yaz@phoenix.oulu.fi
  4. Subject: NewsAgent: uutimet (preliminary)
  5. Message-ID: <1992Dec21.233325.17428@ousrvr.oulu.fi>
  6. Followup-To: alt.sources.d
  7. Lines: 362
  8. Sender: news@ousrvr.oulu.fi
  9. Organization: University of Oulu, Finland
  10. X-Newsagent: :: uutimet -- news-agent by yaz@phoenix.oulu.fi ::
  11. Date: Mon, 21 Dec 1992 23:33:25 GMT
  12.  
  13. #! /bin/sh
  14. # This is a shell archive.  Remove anything before this line, then unpack
  15. # it by saving it into a file and typing "sh file".  To overwrite existing
  16. # files, type "sh file -c".  You can also feed this as standard input via
  17. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  18. # will see the following message at the end:
  19. #        "End of shell archive."
  20. # Contents:  readme.yaz uutimet telagent.c nagent.c
  21. # Wrapped by yaz@phoenix on Tue Dec 22 01:31:28 1992
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. if test -f readme.yaz -a "${1}" != "-c" ; then 
  24.   echo shar: Will not over-write existing file \"readme.yaz\"
  25. else
  26. echo shar: Extracting \"readme.yaz\" \(1645 characters\)
  27. sed "s/^X//" >readme.yaz <<'END_OF_readme.yaz'
  28. XThis is a readme-file for the first published packaged NewsAgent by yaz.
  29. XCompile the following c-programs with your favorite ccompiler and
  30. Xmv them to your bin-directory. Place the sh-script into any directory
  31. Xwhere you want it, I use src/sh but it might not be proper on your
  32. Xaccount.
  33. X
  34. XWhy: I wrote this bunch of programs because GNUS was too slow on
  35. X     the computer I used, and I did not want to stick with telnet
  36. X     any more.  
  37. X
  38. XWhat: uutimet does not save read article numbers, neither it reads them.
  39. X      It is fast, useful, and pretty. (Hah, listen to the man boast).
  40. X      It uses less , or user defined pager, to page the output.
  41. X      It does ugly quotes in follow-up, and does not believe in
  42. X      Follow-Up-To or whatever.
  43. X
  44. XWho: Tuomas "yaz" Kaikkonen wrote this in his freetime.
  45. X     (yaz@phoenix.oulu.fi)
  46. X
  47. XContents :
  48. X
  49. Xnagent.c           : this is the newsreader 
  50. Xtelagent.c         : and this is the general purpose telnet substitute
  51. Xuutimet            : the sh-script to rule them all
  52. X
  53. XUsage:
  54. X
  55. Xuutimet
  56. X
  57. XThe first two programs are used by the third one. If you want to use them
  58. Xalone:
  59. X
  60. X
  61. Xnagent <newsgroup> [article]
  62. X
  63. XWhere <newsgroup> is any newsgroup name known to your $NNTPSERVER and
  64. Xif you want to read spesific article, then give that as the third
  65. Xargument [article]. If you omit the article number, then the newsreader
  66. Xnagent shows the current high- and low-article counts for that group.
  67. X
  68. Xwhatever | telagent host port
  69. X
  70. X
  71. XWhere whatever is any command which output is used as the input to
  72. Xthe telnet substitute program.
  73. X
  74. X
  75. XMore help can be found from the sh-file when you run it.
  76. X
  77. X
  78. XMerry Xmas & a happy new year!
  79. X
  80. X--Tuomas
  81. END_OF_readme.yaz
  82. if test 1645 -ne `wc -c <readme.yaz`; then
  83.     echo shar: \"readme.yaz\" unpacked with wrong size!
  84. fi
  85. # end of overwriting check
  86. fi
  87. if test -f uutimet -a "${1}" != "-c" ; then 
  88.   echo shar: Will not over-write existing file \"uutimet\"
  89. else
  90. echo shar: Extracting \"uutimet\" \(3644 characters\)
  91. sed "s/^X//" >uutimet <<'END_OF_uutimet'
  92. X#!/bin/sh
  93. X#
  94. X# Simple sh-script for news reading+posting <yaz@phoenix.oulu.fi> 92/12/09
  95. X
  96. Xeditori="memacs"
  97. Xlessi="less"
  98. Xvali="help"
  99. Xgroup="oy.test"
  100. Xnumber="1"
  101. Xwhile true
  102. Xdo
  103. X    case $vali in
  104. X        help) echo "help - this help";
  105. X            echo "conn [NNTPserver name] - connect a NNTPserver";
  106. X            echo "list - list of newsgroups with $lessi";
  107. X            echo "join [group name] - join a newsgroup";
  108. X            echo "next - read next article with $lessi";
  109. X            echo "Next - read next article without $lessi";
  110. X            echo "prev - read prev article with $lessi";
  111. X            echo "Prev - read prev article without $lessi";
  112. X             echo "goto [article number] - goto article";
  113. X            echo "read - read current article with $lessi";
  114. X            echo "Read - read current article without $lessi";
  115. X            echo "post - post an article edited with $editori";
  116. X            echo "foll - post a follow-up to current article edited with $editori";
  117. X            echo "show - show current variables";
  118. X            echo "quit - quit this program";;
  119. X        conn) NNTPSERVER="$toka";
  120. X            export NNTPSERVER;
  121. X            echo "quit" | telagent $NNTPSERVER 119 | head -1 | cut -d" " -f2-;;
  122. X        list) bartfile="`whoami`$$";
  123. X            echo list > $bartfile;
  124. X            echo quit >> $bartfile;
  125. X            cat $bartfile | telagent $NNTPSERVER 119 | $lessi;
  126. X            rm $bartfile;;
  127. X        join) echo "joining newsgroup $toka";
  128. X            group=$toka;
  129. X            nagent $group;
  130. X            number=`nagent $group | cut -d"-" -f1`;;
  131. X        next) number=`expr $number + 1`;
  132. X            nagent $group $number | $lessi;;
  133. X        Next) number=`expr $number + 1`;
  134. X            nagent $group $number;;
  135. X        prev) number=`expr $number - 1`;
  136. X            nagent $group $number | $lessi;;
  137. X        Prev) number=`expr $number - 1`;
  138. X            nagent $group $number;;
  139. X        goto) echo "going to article number $toka in group $group";
  140. X            number=$toka;;
  141. X        read) nagent $group $number | $lessi;;
  142. X        Read) nagent $group $number;;
  143. X        post) artfile="`whoami`$$";
  144. X            echo "Path: `who am i | cut -d\! -f1`!`whoami`" > $artfile;
  145. X            echo "Newsgroups: $group" >> $artfile;
  146. X            echo "From: `whoami`@`hostname`.oulu.fi" >> $artfile;
  147. X            echo "Subject ?";
  148. X            read artsubj;
  149. X            echo "Subject: $artsubj" >> $artfile;
  150. X            echo "Lines: " >> $artfile;
  151. X            echo "Followup-To: " >> $artfile;
  152. X            echo "Organization: " >> $artfile;
  153. X            echo "X-NewsAgent: :: uutimet -- news-agent by yaz@phoenix.oulu.fi ::" >> $artfile;
  154. X            echo "" >> $artfile;
  155. X            $editori $artfile;
  156. X            nlines=`cat $artfile | wc -l`;
  157. X            nlines=`expr $nlines - 8`;
  158. X            echo "" >> $artfile;
  159. X            echo "." >> $artfile;
  160. X            echo "quit" >> $artfile;
  161. X            echo post | cat - $artfile | sed 6s/"Lines: "/"Lines: $nlines"/ | telagent $NNTPSERVER 119;
  162. X            rm $artfile;;
  163. X        foll) artfile="`whoami`$$";
  164. X            echo "Path: `who am i | cut -d\! -f1`!`whoami`" > $artfile;
  165. X            echo "Newsgroups: $group" >> $artfile;
  166. X            echo "From: `whoami`@`hostname`.oulu.fi" >> $artfile;
  167. X            nagent $group $number | grep "^Subject:" | tr -d '\015' | sed s/"Re: "//g | sed s/"^Subject: "/"Subject: Re: "/g >> $artfile;
  168. X            echo "Lines: " >> $artfile;
  169. X            echo "Followup-To: " >> $artfile;
  170. X            echo "Organization: " >> $artfile;
  171. X            echo "X-NewsAgent: :: uutimet -- news-agent by yaz@phoenix.oulu.fi ::" >> $artfile;
  172. X            echo "" >> $artfile;
  173. X            nagent $group $number | sed s/"^"/"> "/g | tr -d '\015' >> $artfile;
  174. X            $editori $artfile;
  175. X            nlines=`cat $artfile | wc -l`;
  176. X            nlines=`expr $nlines - 8`;
  177. X            echo "" >> $artfile;
  178. X            echo "." >> $artfile;
  179. X            echo "quit" >> $artfile;
  180. X            echo post | cat - $artfile | sed 6s/"Lines: "/"Lines: $nlines"/ | telagent $NNTPSERVER 119;
  181. X            rm $artfile;;
  182. X        show) echo "NNTPserver: $NNTPSERVER";
  183. X            nagent $group;
  184. X            echo "current article number:$number";;
  185. X        quit) exit ;;
  186. X        *) echo "read the help with command help";;
  187. X    esac
  188. X    echo ":: uutimet -- news-agent by yaz@phoenix.oulu.fi ::"
  189. X    read vali toka
  190. Xdone
  191. END_OF_uutimet
  192. if test 3644 -ne `wc -c <uutimet`; then
  193.     echo shar: \"uutimet\" unpacked with wrong size!
  194. fi
  195. chmod +x uutimet
  196. # end of overwriting check
  197. fi
  198. if test -f telagent.c -a "${1}" != "-c" ; then 
  199.   echo shar: Will not over-write existing file \"telagent.c\"
  200. else
  201. echo shar: Extracting \"telagent.c\" \(1126 characters\)
  202. sed "s/^X//" >telagent.c <<'END_OF_telagent.c'
  203. X#include <sys/types.h>
  204. X#include <sys/socket.h>
  205. X#include <netinet/in.h>
  206. X#include <netdb.h>
  207. X#include <stdio.h>
  208. X#include <signal.h>
  209. X
  210. Xmain(argc,argv) /* telagent main */
  211. Xint argc;
  212. Xchar *argv[];
  213. X{
  214. X    int i,j,sd,port=23;
  215. X    struct sockaddr_in server;
  216. X    struct hostent *hp, *gethostbyname();
  217. X    char text[512];
  218. X    char string[512];
  219. X    FILE *out_file,*in_file;
  220. X
  221. X    if (argc<2) {
  222. X        fprintf(stderr, "Usage: %s <host> [port]\n", argv[0]);
  223. X        exit(1);
  224. X    }
  225. X    if (argc == 3) port=atoi(argv[2]);
  226. X    sd=socket(AF_INET,SOCK_STREAM,0);
  227. X    if(sd<0) { perror("socket"); exit(1); }
  228. X    server.sin_family = AF_INET;
  229. X    hp=gethostbyname(argv[1]);
  230. X    if(hp==0) {
  231. X        fprintf(stderr, "%s: Unknown host\n",argv[1]);
  232. X        exit(2);
  233. X    }
  234. X    bcopy(hp->h_addr, &server.sin_addr, hp->h_length);
  235. X    server.sin_port=htons(port);
  236. X
  237. X    if(connect(sd,&server,sizeof(server))<0) {
  238. X        perror("connecting stream socket");
  239. X        exit(1);
  240. X    }
  241. X    in_file=fdopen(sd,"r+");
  242. X    out_file=fdopen(sd,"r+");
  243. X    while(fgets(string, 512, stdin)!=NULL) fputs(string, out_file);
  244. X    fflush(out_file);
  245. X    for(string[0]=0;fgets(string, 512, in_file)!=NULL;) printf("%s",string);
  246. X    close(out_file);
  247. X    close(in_file);
  248. X    close(sd);
  249. X    return 0;
  250. X}
  251. X
  252. END_OF_telagent.c
  253. if test 1126 -ne `wc -c <telagent.c`; then
  254.     echo shar: \"telagent.c\" unpacked with wrong size!
  255. fi
  256. # end of overwriting check
  257. fi
  258. if test -f nagent.c -a "${1}" != "-c" ; then 
  259.   echo shar: Will not over-write existing file \"nagent.c\"
  260. else
  261. echo shar: Extracting \"nagent.c\" \(2375 characters\)
  262. sed "s/^X//" >nagent.c <<'END_OF_nagent.c'
  263. X#include <sys/types.h>
  264. X#include <sys/socket.h>
  265. X#include <netinet/in.h>
  266. X#include <netdb.h>
  267. X#include <stdio.h>
  268. X#include <signal.h>
  269. X
  270. Xint getword(s,t,p)  /* return one word from input string, s, position p */
  271. Xint p;            /* to output string t; getword returns new position */
  272. Xchar s[],t[];
  273. X{
  274. X    int i;
  275. X
  276. X    while(s[p]==' ' || s[p]==':' &&
  277. X        (s[p]!='\n' && s[p]!=0)) p++;
  278. X    
  279. X    for (i=0,t[0]=0;s[p+i]!=' ' && s[p+i]!=':' && s[p+i]!='\n';
  280. X        t[i]=s[p+(i++)]);
  281. X        t[i]=0;
  282. X    return(p+i);
  283. X}
  284. X
  285. Xmain(argc,argv) /* nagent main */
  286. Xint argc;
  287. Xchar *argv[];
  288. X{
  289. X    int i,j,sd;
  290. X    struct sockaddr_in server;
  291. X    struct hostent *hp, *gethostbyname();
  292. X    char text[512];
  293. X    char string[512];
  294. X    FILE *out_file,*in_file;
  295. X
  296. X    if (argc<2) {
  297. X        fprintf(stderr, "Usage: %s <group> [article_number]\n", argv[0]);
  298. X        exit(1);
  299. X    }
  300. X
  301. X    sd=socket(AF_INET,SOCK_STREAM,0);
  302. X    if(sd<0) { perror("socket"); exit(1); }
  303. X    server.sin_family = AF_INET;
  304. X    hp=gethostbyname(getenv("NNTPSERVER"));
  305. X    if(hp==0) {
  306. X        fprintf(stderr, "%s: Unkown host\n",getenv("NNTPSERVER"));
  307. X        exit(2);
  308. X    }
  309. X    bcopy(hp->h_addr, &server.sin_addr, hp->h_length);
  310. X    server.sin_port=htons(119);
  311. X
  312. X    if(connect(sd,&server,sizeof(server))<0) {
  313. X        perror("connecting stream socket");
  314. X        exit(1);
  315. X    }
  316. X    in_file=fdopen(sd,"r+");
  317. X    out_file=fdopen(sd,"r+");
  318. X    fgets(string, 512, in_file);
  319. X    fprintf(out_file, "group %s\n", argv[1]);
  320. X    fflush(out_file);
  321. X    fgets(string, 512, in_file);
  322. X    if (string[0] != '2' || string[1] != '1' || string[2] != '1') {
  323. X        printf("%s",string);
  324. X        fprintf(out_file, "quit\n");
  325. X        fflush(out_file);
  326. X        argc = 0;
  327. X    } else {
  328. X        if (argc == 2) {
  329. X            i=getword(string,text,0);
  330. X            i=getword(string,text,i);
  331. X            i=getword(string,text,i);
  332. X            printf("%s-", text);
  333. X            i=getword(string,text,i);
  334. X            printf("%s ", text);
  335. X            i=getword(string,text,i);
  336. X            printf("%s\n", text);
  337. X            fprintf(out_file, "quit\n");
  338. X            fflush(out_file);
  339. X        }
  340. X    }        
  341. X    if (argc == 3) {
  342. X        fprintf(out_file, "article %s\n", argv[2]);
  343. X        fflush(out_file);
  344. X        fgets(string, 512, in_file);
  345. X        if (string[0] != '2' || string[1] != '2' || string[2] != '0') {
  346. X            printf("%s",string);
  347. X        } else {
  348. X            fgets(string, 512, in_file);
  349. X            fprintf(out_file, "quit\n");
  350. X            fflush(out_file);
  351. X            for(string[0]=0;fgets(string, 512, in_file)!=NULL;)
  352. X            {
  353. X                printf("%s",string);
  354. X                if (string[0] == '.' && string[1] == '\r') {
  355. X                    fgets(string, 512, in_file);
  356. X                }
  357. X            }
  358. X        }
  359. X    }
  360. X    close(out_file);
  361. X    close(in_file);
  362. X    close(sd);
  363. X    return 0;
  364. X}
  365. X
  366. END_OF_nagent.c
  367. if test 2375 -ne `wc -c <nagent.c`; then
  368.     echo shar: \"nagent.c\" unpacked with wrong size!
  369. fi
  370. # end of overwriting check
  371. fi
  372. echo shar: End of shell archive.
  373. exit 0
  374.  
  375.