Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!rutgers!ll-xn!mit-eddie!genrad!decvax!mcnc!ece-csc!uvacs!edison!toylnd!news From: news@toylnd.UUCP (News) Newsgroups: net.sources Subject: archnews for the 7300 (partial repost) Message-ID: <115@toylnd.UUCP> Date: Sun, 19-Oct-86 20:26:47 EDT Article-I.D.: toylnd.115 Posted: Sun Oct 19 20:26:47 1986 Date-Received: Wed, 22-Oct-86 22:25:13 EDT Organization: Dave & Anne Charlottesville, Va Lines: 286 #!/bin/sh # # The version of archnews which I posted had two very important missing lines: # a fflush without which the summary file gets replicated lines and an exit # when a bounce occurs writing a file to the floppy. Since the diffs were # about 3/4 the size of archnews the following is a new archnews.c and # archnews.1 # # David Albrecht # # echo 'Start of ../archnews.post1, part 01 of 01:' echo 'x - archnews.c' sed 's/^X//' > archnews.c << '/' X#define MAXSTRING 132 X#define MAXDIR 60 X X#include X X#include "ndir.h" X#include X Xchar newsbuf[512], archdir[MAXDIR], make_dirs[8][MAXDIR], target[MAXDIR]; Xchar in_string[MAXSTRING]; X XFILE *summaries = {stdout}; X Xmain(argc,argv) Xint argc; Xchar **argv; X{ char rootdir[MAXDIR], newspath[MAXDIR], newsgroup[MAXDIR]; X X getcwd(rootdir, MAXDIR); X *newspath = '\0'; X *newsgroup = '\0'; X if (argc > 1) { X strcpy(archdir, argv[1]); X if (argc > 2) { X summaries = fopen(argv[2], "a"); X if (!summaries) { X fprintf(stderr, "unable to open summary file %s\n", argv[2]); X exit(1); X } X } X } X else { X fprintf(stderr, "archnews archive_directory [ summary_file ]\n"); X exit(1); X } X procdir(rootdir, newspath, newsgroup, 0); X} X Xprocdir(dirpath, newspath, newsgroup, level) Xchar *dirpath, *newspath, *newsgroup; X{ DIR *directory; X FILE *fp, *fp1, *pin, *pout; X struct direct *dp; X struct stat buf; X int ldirpath, lnewspath, lnewsgroup, i, f_status, child_status, pid; X char entryname[MAXDIR], *str, c; X X if (!(directory = opendir(dirpath))) { X fprintf(stderr, "unable to open directory %s\n", dirpath); X } X else { X while (dp = readdir(directory)) { X X if (*(dp->d_name) == '.') continue; X X *entryname= '\0'; X strncat(entryname, dp->d_name, dp->d_namlen); X fp = fopen(entryname, "r"); X if (!fp) { X fprintf(stderr, "unable to open file %s/%s\n", X dirpath, entryname); X continue; X } X X fstat(fileno(fp), &buf); X if (buf.st_mode & S_IFDIR) { X fclose(fp); X X ldirpath = strlen(dirpath); X strcat(dirpath, "/"); X strcat(dirpath, entryname); X X lnewspath = strlen(newspath); X if (lnewspath) { X strcat(newspath, "/"); X } X strcat(newspath, entryname); X X lnewsgroup = strlen(newsgroup); X if (lnewsgroup) { X strcat(newsgroup, "."); X } X strcat(newsgroup, entryname); X X strcpy(target, archdir); X strcat(target, "/"); X strcat(target, newspath); X fp = fopen(target, "r"); X if (!fp) { X strcpy(&make_dir[level][0], target); X } X else { X fclose(fp); X } X X chdir(entryname); X X procdir(dirpath, newspath, newsgroup, level + 1); X X make_dir[level][0] = '\0'; X dirpath[ldirpath] = '\0'; X chdir(dirpath); X newspath[lnewspath] = '\0'; X newsgroup[lnewsgroup] = '\0'; X } X else { X for (i = 0; i < level; i++) { X if (make_dir[i][0]) { X if (mkdir(&make_dir[i][0], 0777)) { X fprintf(stderr, "cannot create directory %s, archive full\n", X &make_dir[i][0]); X } X else { X make_dir[i][0] = '\0'; X } X } X } X X strcpy(target, archdir); X strcat(target, "/"); X strcat(target, newspath); X strcat(target, "/"); X strcat(target, entryname); X strcat(target, ".Z"); X fp1 = fopen(target, "w"); X if (!fp1) { X fprintf(stderr, "unable to create %s, archive full\n", target); X exit(1); X } X X fflush(summaries); X if (pipe_command("/usr/lib/news/compress", "compress", &pin, &pout)) { X fprintf(stderr, "pipe to /usr/lib/news/compress failed\n"); X exit(1); X } X X if (!(pid = fork())) { X X fclose(fp); X fclose(pin); X X c = getc(pout); X while (!feof(pout)) { X if ((f_status = putc(c, fp1)) == EOF) { X break; X } X c = getc(pout); X } X fclose(fp1); X X if (f_status == EOF) { X while (!feof(pout)) getc(pout); X fclose(pout); X exit(1); X } X else { X fclose(pout); X exit(0); X } X } X else { X X fclose(fp1); X fclose(pout); X X *newsbuf = '\0'; X str = newsbuf; X i = 0; X while (fgets(in_string, MAXSTRING - 1, fp)) { X fputs(in_string, pin); X if (!strncmp(in_string, "Subject", 7)) { X sprintf(str, "%s:%s - %s", newsgroup, entryname, in_string); X str += strlen(str); X } X else if (!strncmp(in_string, "Summary", 7)) { X sprintf(str, "%s:%s - %s", newsgroup, entryname, in_string); X str += strlen(str); X } X else if (!strncmp(in_string, "Keywords", 8)) { X sprintf(str, "%s:%s - %s", newsgroup, entryname, in_string); X str += strlen(str); X } X } X fclose(fp); X fclose(pin); X X while (wait(&child_status) != pid); X if (child_status >> 8) { X fprintf(stderr, "write to %s failed, archive full\n", X target); X unlink(target); X exit(1); X } X else { X fputs(newsbuf, summaries); X unlink(entryname); X } X } X } X } X closedir(directory); X } X} X Xpipe_command(path, command, pin, pout) Xchar *path, *command; XFILE **pin; XFILE **pout; X X{ int fildes1[2], fildes2[2], status = 0; X X if (pipe(fildes1)) { X fprintf(stderr, "cannot create pipes for %s command\n", path); X status = 1; X } X if (pipe(fildes2)) { X fprintf(stderr, "cannot create pipes for %s command\n", path); X status = 1; X } X if (!fork()) { X close(fildes1[1]); X close(fildes2[0]); X close(0); X dup(fildes1[0]); X close(fildes1[0]); X close(1); X dup(fildes2[1]); X close(fildes2[1]); X (void) execlp(path, command, (char *) NULL); X perror(path); X _exit(1); X } X else { X close(fildes1[0]); X close(fildes2[1]); X *pin = fdopen(fildes1[1], "w"); X *pout = fdopen(fildes2[0], "r"); X if (!(*pin) || !(*pout)) status = 1; X } X return(status); X} / echo 'x - archnews.1' sed 's/^X//' > archnews.1 << '/' X.TH ARCHNEWS 1 local X.SH NAME Xarchnews \- archive expired news to a floppy X.SH SYNOPSIS X.B archnews Xfloppy directory [ summary file ] X.SH DESCRIPTION X.I Archnews Xis a program that takes news which has been expired by the news expire utility Xand archives it to a floppy disk. It should be invoked in the root directory Xof the tree which is desired to be archived. X.I Archnews Xif no summary file is specified will print to standard output the subject Xand summary of the files which Xit archives. The summary file gives an easy index to the floppy archives. XThe files are Xstored after compression via the news compress utility Xin the same tree structure as the tree being archived. X.pp XWhen the floppy device gets full X.I archnews Xwill fail and may simply be reissued to continue archiving the remaining Xfiles. X.SH AUTHOR XDavid Albrecht / echo 'Part 01 of ../archnews.post1 complete.' exit