allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) (09/24/89)
Posting-number: Volume 8, Issue 46 Submitted-by: ron@mlfarm.UUCP (Ronald Florence) Archive-name: bsnews.p1 Since posting the original bsnews 1.1 (Bootstrap News) package, I have received a number of requests for a version of "rnews.c" which can be compiled under DOS. I have also added the option of command line arguments for installations where rnews is invoked from a script instead of by "uux", and a provision for output to stdout instead of a spool file. The Makefile entry for "rnews.exe" and some of the defines in "rnews.c" may require tailoring to fit different DOS C compilers. The shar package includes a simple but useful patch to the "pn" news poster which was suggested by Bill Davidsen (davidsen@crdos1). __________________________________________________________ #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # Makefile # rnews.c # pn.proto.patch # This archive created: Tue Sep 19 09:37:59 1989 # By: Ronald Florence (Maple Lawn Farm, Stonington, CT) export PATH; PATH=/bin:/usr/bin:$PATH echo shar: "extracting 'Makefile'" '(2026 characters)' if test -f 'Makefile' then echo shar: "will not over-write existing file 'Makefile'" else sed 's/^X//' << \SHAR_EOF > 'Makefile' X# Makefile for bootstrap news X# copyright 1989 Ronald Florence (ron@mlfarm, 9/16/89) X# X# To build bootstrap news: X# 1. Change READER to your favorite mail reader with the option flag X# used to specify a spool file. X# 2. Change HOST to the name of your news feed. If you get news X# from more than one host, select the one to which you feed news, X# and change FEEDER to something like Usenet_news. X# 3. Run make. X# X XREADER = Mail -f XHOST = mlfarm XFEEDER = news@$(HOST).UUCP X XSPOOL = /usr/spool/news XNEWSSPOOL = $(SPOOL)/bsnews XNEWSDIR = /usr/lib/news XSEQFILE = $(NEWSDIR)/seq XBINDIR = /usr/bin XCOMPRESS = $(BINDIR)/compress XCFLAGS = -O -s -DFeeder='"$(FEEDER)"' -DNewsspool='"$(NEWSSPOOL)"' XPGMS = uurec pn checknews rnews readnews XFILES = spoolfile seqfile XSRCS = checknews.c rnews.c uurec.proto pn.proto readnews.proto XSHELL = /bin/sh X Xbsnews: install X Xinstall: $(PGMS) $(FILES) X cp $(PGMS) $(BINDIR) X cd $(BINDIR) X chgrp bin $(PGMS) X chown bin $(PGMS) X @echo X @echo "Add \"rnews\" to /usr/lib/uucp/L.cmds or the equivalent for a" X @echo "uux feed. For a mail feed, create a sendmail alias for rnews:" X @echo "|/usr/bin/uurec or run \"uurec\" periodically from cron with" X @echo "/usr/spool/mail/rnews as input." X @ [ -x $(COMPRESS) ] || { echo "You need $(COMPRESS) for compressed feeds."; } X Xspoolfile: X [ -d $(SPOOL) ] || mkdir $(SPOOL) X [ -f $(NEWSSPOOL) ] || > $(NEWSSPOOL) X chmod 666 $(NEWSSPOOL) X Xseqfile: X [ -f $(SEQFILE) ] || { mkdir $(NEWSDIR); echo "1" > $(SEQFILE); } X chmod 666 $(SEQFILE) X Xuurec: uurec.proto X sed "s|/usr/spool/news/bsnews|$(NEWSSPOOL)|" uurec.proto > uurec X chmod +x uurec X Xpn: pn.proto X sed "s/BigNode/$(HOST)/" pn.proto > pn X chmod +x pn X Xreadnews: readnews.proto X sed "s|Mail -f /usr/spool/news/bsnews|$(READER) $(NEWSSPOOL)|" readnews.proto > readnews X chmod +x readnews X Xshar: Readme Makefile $(SRCS) X shar -a Readme Makefile $(SRCS) > bsnews.shar X Xclean: X rm -f $(PGMS) X Xrnews.exe: rnews.c X cc -dos -DDOS -DFeeder='"$(FEEDER)"' rnews.c -o rnews.exe X SHAR_EOF if test 2026 -ne "`wc -c < 'Makefile'`" then echo shar: "error transmitting 'Makefile'" '(should have been 2026 characters)' fi fi echo shar: "extracting 'rnews.c'" '(2498 characters)' if test -f 'rnews.c' then echo shar: "will not over-write existing file 'rnews.c'" else sed 's/^X//' << \SHAR_EOF > 'rnews.c' X/* X * rnews.c X * copyright 1989 Ronald Florence (ron@mlfarm 8/14/89) X * X * modified for DOS (ron@mlfarm, 9/16/89) X */ X X#include <stdio.h> X#include <time.h> X X#ifndef Feeder X#define Feeder "Usenet" X#endif X X#ifndef DOS X#define Readmode "r" X#define Compress "/usr/bin/compress -dc > %s" Xchar *mktemp(); X#else X#include <fcntl.h> X#define Readmode "rb" X#define Compress "compress -d %s" X#endif X X#define bye(s) perror(s), exit(1) X Xlong time(); XFILE *nf, *cf; X Xmain(argc, argv) X int argc; X char *argv[]; X{ X int i; X X#ifndef Newsspool X nf = stdout; X#else X if (!(nf = fopen(Newsspool, "a"))) X bye(Newsspool); X#endif X if (argc > 1) X for (i = 1; i < argc; i++) X { X if ((cf = freopen(argv[i], Readmode, stdin)) == NULL) X bye(argv[i]); X parse(); X } X else X { X#ifdef DOS X setmode(fileno(stdin), O_BINARY); X#endif X parse(); X } X} X X Xparse() X{ X register c; X int new = 1, n; X char buf[BUFSIZ], dcomp[40], tmpnews[20]; X X while (fgets(buf, BUFSIZ, stdin) != NULL) X { X /* batched? */ X if (!strncmp(buf, "#! ", 3)) X { X /* compressed? */ X if (!strncmp(buf+3, "cunbatch", 8)) X { X#ifndef DOS X sprintf(tmpnews, mktemp("newsart.XXXXXX")); X sprintf(dcomp, Compress, tmpnews); X if (!(cf = popen(dcomp, "w"))) X bye(dcomp); X#else X sprintf(tmpnews, "%08.8lX.Z", time()); X if (!(cf = fopen(tmpnews, "wb"))) X bye(tmpnews); X#endif X while ((c = getchar()) != EOF) X putc(c, cf); X#ifndef DOS X pclose(cf); X#else X fclose(cf); X tmpnews[8] = '\0'; X sprintf(dcomp, Compress, tmpnews); X if (system(dcomp)) X bye(dcomp); X#endif X if ((cf = freopen(tmpnews, Readmode, stdin)) == NULL) X bye(tmpnews); X /* and loop around to unbatch */ X continue; X } X /* unpack the batch */ X else if (sscanf(buf+3, "rnews %d", &n) == 1) X { X timestamp(nf); X for (c = 0; c < n; c += strlen(buf)) X { X if (fgets(buf, BUFSIZ, stdin) == NULL) X break; X if (!strncmp(buf, "From ", 5)) X putc('>', nf); X fputs(buf, nf); X } X putc('\n', nf); X continue; X } X } X /* it must be unbatched */ X else X { X if (new) X { X timestamp(nf); X new = 0; X } X if (!strncmp(buf, "From ", 5)) X putc('>', nf); X fputs(buf, nf); X } X } X if (!new) X putc('\n', nf); X unlink(tmpnews); X} X X Xtimestamp(newsfile) XFILE *newsfile; X{ X long clock; X char *ctime(); X X time(&clock); X fprintf(newsfile, "From %s %s", Feeder, ctime(&clock)); X} SHAR_EOF if test 2498 -ne "`wc -c < 'rnews.c'`" then echo shar: "error transmitting 'rnews.c'" '(should have been 2498 characters)' fi fi echo shar: "extracting 'pn.proto.patch'" '(45 characters)' if test -f 'pn.proto.patch' then echo shar: "will not over-write existing file 'pn.proto.patch'" else sed 's/^X//' << \SHAR_EOF > 'pn.proto.patch' X18c18 X< read Subject rest X--- X> read Subject SHAR_EOF if test 45 -ne "`wc -c < 'pn.proto.patch'`" then echo shar: "error transmitting 'pn.proto.patch'" '(should have been 45 characters)' fi fi exit 0 # End of shell archive -- Ronald Florence ...{hsi,rayssd}!mlfarm!ron