From: frank.kaefer@stasys.sta.sub.org (Frank Kaefer)
Newsgroups: de.comp.sources.os9,comp.os.os9
Subject: MNews Prerelease Part08/09
Date: 23 Dec 92 19:41:45 GMT
Followup-To: de.comp.sources.d
Organization: Stasys News Server, Starnberg, Germany
NNTP-Posting-Host: stasys.sta.sub.org

Submitted-by: Ulrich Dessauer <ud@Nightmare.ddt.sub.org>
Archive-name: mnews/part08

: ----- Cut here ----- Cut here ----- Cut here ----- Cut here -----
: Use  sh filename  to extract shell archive
: This shell archive contains following files:
:     'RNEWS/compr7.c                               3373 bytes'
:     'RNEWS/conv.c                                 2289 bytes'
:     'RNEWS/logit.c                                 940 bytes'
:     'RNEWS/mail.c                                  779 bytes'
:     'RNEWS/rnews.c                                5196 bytes'
:     'RNEWS/rnews.h                                 624 bytes'
:     'RNEWS/send.c                                 2835 bytes'
:     'SBATCH/Makefile                               589 bytes'
:     'SBATCH/batch.c                               2157 bytes'
:     'SBATCH/com.c                                 2736 bytes'
:     'SBATCH/com7.c                                1777 bytes'
:     'SBATCH/conv.c                                3579 bytes'
:     'SBATCH/exec.c                                 859 bytes'
:     'SBATCH/file.c                                1820 bytes'
:     'SBATCH/none.c                                1136 bytes'
:     'SBATCH/sbatch.c                              7077 bytes'
: 
if test -f 'RNEWS/compr7.c' ; then
  echo 'File RNEWS/compr7.c already exists, overwriting it'
  del 'RNEWS/compr7.c'
fi
echo Extracting \"'RNEWS/compr7.c'\"
sed "s/^X//" >'RNEWS/compr7.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log:	compr7.c_v $
X * Revision 1.1  90/08/31  15:38:01  ud
X * Initial revision
X * 
X */
X# ifndef	LINT
Xstatic char rcsid[] = "$Id: compr7.c_v 1.1 90/08/31 15:38:01 ud Exp $";
X# endif		LINT
X# include <stdio.h>
X# include <ctype.h>
X# include <modes.h>
X# include "rnews.h"
X
Xextern void	free ();
Xextern void	logit ();
Xextern void	start_rnews ();
Xextern long	lseek ();
Xextern char	*findmod ();
Xextern char	*index ();
Xextern char	*mktemp ();
Xextern char	*strcpy ();
X
Xint
Xexec (cmd)
Xchar *cmd;
X{
X	extern int os9forkc ();
X	extern char **environ;
X	char *newcmd;
X	register char *x;
X	char *arg[10];
X	int t,pid;
X	
X	if ((newcmd = (char *) malloc ((unsigned int) (strlen (cmd) + 2))) == (char *) NULL)
X		return (-1);
X	t = 0;
X	(void) strcpy (newcmd,cmd);
X	x = newcmd;
X	while (*x && (t < 9)) {
X		arg[t++] = x;
X		while (*x && (!isspace (*x)))
X			++x;
X		if (*x) {
X			*x++ = '\0';
X			while (isspace (*x))
X				++x;
X		}
X	}
X	arg[t] = NULL;
X	logit (4,"Fork: '%s'\n",arg[0]);
X	pid = os9exec (os9forkc,findmod (arg[0],arg[0]),arg,environ,0,0,3);
X	logit ((pid < 0) ? 2 : 4,"pid of '%s' is %d\n",arg[0],pid);
X	free (newcmd);
X	return (pid);
X}
X
Xvoid	
Xcompr7 (fd,scratch,cmd)
Xint fd;
Xint scratch;
Xchar *cmd;
X{
X	int		old0, old1;
X	int		pid1, pid2;
X	int		pip;
X	int		o, t, status;
X	char		tmp[40 + sizeof (TEMPDIR)];
X	unsigned int	siz, temp;
X	register char	*x;
X	register int	n;
X	char		*buf;
X	
X	if ((pip = create ("/pipe",S_IREAD | S_IWRITE,03, 0)) < 0) {
X		error |= FATAL;
X		return;
X	}
X	(void) sprintf (tmp, "%s/dec.XXXXXX", TEMPDIR);
X	(void) mktemp (tmp);
X	if ((o = create (tmp,S_IREAD | S_IWRITE,03, 0)) < 0) {
X		logit (2,"ERROR:  Can't create tmpfile '%s'\n",tmp);
X		(void) close (pip);
X		error |= FATAL;
X		return;
X	}
X	old0 = dup (0);
X	old1 = dup (1);
X	if (fd != 0) {
X		(void) close (0);
X		(void) dup (fd);
X	}
X	(void) close (1);
X	(void) dup (pip);
X	if ((pid1 = exec (decode)) < 0) {
X		(void) close (1);
X		(void) dup (old1);
X		if (fd != 0) {
X			(void) close (0);
X			(void) dup (old0);
X		}
X		(void) close (pip);
X		(void) close (o);
X		_unlink (tmp);
X		error |= FATAL;
X		return;
X	}
X	(void) close (1);
X	(void) close (0);
X	if (fd != 0)
X		(void) close (fd);
X	else {
X		(void) close (old0);
X		old0 = -1;
X	}
X	(void) dup (pip);
X	(void) close (pip);
X	(void) dup (o);
X	if ((pid2 = exec (cmd)) < 0) {
X		(void) close (1);
X		(void) dup (old1);
X		(void) close (0);
X		if (old0 != -1)
X			(void) dup (old0);
X		(void) close (o);
X		_unlink (tmp);
X		error |= FATAL;
X		return;
X	}
X	(void) close (0);
X	if (old0 != -1) {
X		(void) dup (old0);
X		(void) close (old0);
X	}
X	(void) close (1);
X	(void) dup (old1);
X	(void) close (old1);
X	while (((t = wait (&status)) != -1) && ((pid1 != -1) || (pid2 != -1))) {
X		logit (status ? 2 : 4,"%d returns %d\n",t,status);
X		if (t == pid1) {
X			if (status)
X				error |= FATAL;
X			pid1 = -1;
X		}
X		if (t == pid2) {
X			if (status)
X				error |= FATAL;
X			pid2 = -1;
X		}
X	}
X	(void) lseek (o,0,0);
X	siz = 20000;
X	while (siz && ((buf = (char *) malloc (siz + 5)) == (char *) NULL))
X		siz -= 1000;
X	if (!siz) {
X		(void) close (o);
X		_unlink (tmp);
X		error |= FATAL;
X		return;
X	}
X	while ((n = read (o,buf,siz)) > 0) {
X		temp = n;
X		(void) lseek (o,(long) 0-n,1);
X		x = buf;
X		while (n-- > 0) {
X			if (*x && index ("\l\r",*x))
X				*x = *x == '\l' ? '\r' : '\l';
X			++x;
X		}
X		(void) write (o,buf,temp);
X	}
X	(void) lseek (o,0,0);
X	start_rnews (o,scratch);
X	(void) close (o);
X	free (buf);
X	_unlink (tmp);
X}
__END__OF__THIS__FILE__
if test -f 'RNEWS/conv.c' ; then
  echo 'File RNEWS/conv.c already exists, overwriting it'
  del 'RNEWS/conv.c'
fi
echo Extracting \"'RNEWS/conv.c'\"
sed "s/^X//" >'RNEWS/conv.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log:	conv.c_v $
X * Revision 1.1  90/08/31  15:38:06  ud
X * Initial revision
X * 
X */
X# ifndef	LINT
Xstatic char rcsid[] = "$Id: conv.c_v 1.1 90/08/31 15:38:06 ud Exp $";
X# endif		LINT
X# include	<stdio.h>
X# include	"rnews.h"
X
Xextern char	*malloc ();
Xextern char	*strdup ();
X
Xtypedef struct _keymap {
X	char		*seq;
X	int		len;
X	unsigned char	map;
X	struct _keymap	*next;
X} keymap;
X
Xstatic keymap	*kmap[256];
X
Xstatic int	isinit = FALSE;
X
Xstatic keymap kdefault[] = {
X#ifdef	ISO
X	"\\\"A",	3,	0xc4,		NULL,
X	"\\\"O",	3,	0xd6,		NULL,
X	"\\\"U",	3,	0xdc,		NULL,
X	"\\\"a",	3,	0xe4,		NULL,
X	"\\\"o",	3,	0xf6,		NULL,
X	"\\\"u",	3,	0xfc,		NULL,
X	"\\\"s",	3,	0xdf,		NULL,
X
X	"A\\\"",	3,	0xc4,		NULL,
X	"O\\\"",	3,	0xd6,		NULL,
X	"U\\\"",	3,	0xdc,		NULL,
X	"a\\\"",	3,	0xe4,		NULL,
X	"o\\\"",	3,	0xf6,		NULL,
X	"u\\\"",	3,	0xfc,		NULL,
X	"s\\\"",	3,	0xdf,		NULL,
X#endif	ISO
X#ifdef	CUMANA_ST
X	"\\\"A",	3,	0x8e,		NULL,
X	"\\\"O",	3,	0x99,		NULL,
X	"\\\"U",	3,	0x9a,		NULL,
X	"\\\"a",	3,	0x84,		NULL,
X	"\\\"o",	3,	0x94,		NULL,
X	"\\\"u",	3,	0x81,		NULL,
X	"\\\"s",	3,	0xe1,		NULL,
X
X	"A\\\"",	3,	0x8e,		NULL,
X	"O\\\"",	3,	0x99,		NULL,
X	"U\\\"",	3,	0x9a,		NULL,
X	"a\\\"",	3,	0x84,		NULL,
X	"o\\\"",	3,	0x94,		NULL,
X	"u\\\"",	3,	0x81,		NULL,
X	"s\\\"",	3,	0xe1,		NULL,
X#endif	CUMANA_ST
X	NULL,		0,	0,		NULL
X};
X
Xstatic void
Xinit_conv ()
X{
X	register int	t;
X	keymap		*tmp, *t2;
X
X	for (t = 0; t < 256; ++t)
X		kmap[t] = NULL;
X	for (t = 0; kdefault[t].seq; ++t)
X		if (tmp = (keymap *) malloc (sizeof (keymap)))
X			if (tmp->seq = strdup (kdefault[t].seq)) {
X				tmp->len = kdefault[t].len;
X				tmp->map = kdefault[t].map;
X				tmp->next = 0;
X				if (t2 = kmap[tmp->seq[0] & 0xff]) {
X					while (t2->next)
X						t2 = t2->next;
X					t2->next = tmp;
X				} else
X					kmap[tmp->seq[0] & 0xff] = tmp;
X			} else
X				free ((char *) tmp);
X	isinit = TRUE;
X}
X
Xvoid
Xconv_8bit (s, n, fp)
Xregister char *s;
Xregister int n;
Xregister FILE *fp;
X{
X	unsigned char	c;
X	register keymap	*tmp;
X
X	if (!isinit)
X		init_conv ();
X	while (n-- > 0)
X		if (tmp = kmap[((unsigned char) *s) & 0xff]) {
X			while (tmp)
X				if ((n >= tmp->len) && (!strncmp (s, tmp->seq, tmp->len)))
X					break;
X				else
X					tmp = tmp->next;
X			if (tmp) {
X				n -= tmp->len - 1;
X				s += tmp->len;
X				putc (tmp->map, fp);
X			} else
X				putc (*s++, fp);
X		} else
X			putc (*s++, fp);
X}
__END__OF__THIS__FILE__
if test -f 'RNEWS/logit.c' ; then
  echo 'File RNEWS/logit.c already exists, overwriting it'
  del 'RNEWS/logit.c'
fi
echo Extracting \"'RNEWS/logit.c'\"
sed "s/^X//" >'RNEWS/logit.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log:	logit.c_v $
X * Revision 1.1  90/08/31  15:38:12  ud
X * Initial revision
X * 
X */
X# ifndef	LINT
Xstatic char rcsid[] = "$Id: logit.c_v 1.1 90/08/31 15:38:12 ud Exp $";
X# endif		LINT
X# include <stdio.h>
X# include <time.h>
X# include "rnews.h"
X
Xextern time_t		time ();
Xextern char		*asctime ();
Xextern struct tm	*localtime ();
X
X /*VARARGS2*/
Xvoid
Xlogit (nr,a,b,c,d,e,f)
Xint nr;
Xchar *a,*b,*c,*d,*e,*f;
X{
X	static int	first = TRUE;
X	time_t		t;
X	struct tm	*tt;
X	static char	tbuf[32];
X
X	if (first) {
X		(void) time (&t);
X		if (tt = localtime (& t))
X			sprintf (tbuf, "%02d/%02d/%02d  %02d:%02d:%02d",
X				tt -> tm_year, tt -> tm_mon + 1, tt -> tm_mday,
X				tt -> tm_hour, tt -> tm_min, tt -> tm_sec);
X		else
X			tbuf[0] = '\0';
X		(void) fprintf (stderr,"Start: %s", tbuf);
X		first = FALSE;
X	}
X	(void) fprintf (stderr,a,b,c,d,e,f);
X	if ((!lp) || (Debug < nr))
X		return;
X	(void) fprintf (lp,"%s: ", tbuf);
X	(void) fprintf (lp,a,b,c,d,e,f);
X}
__END__OF__THIS__FILE__
if test -f 'RNEWS/mail.c' ; then
  echo 'File RNEWS/mail.c already exists, overwriting it'
  del 'RNEWS/mail.c'
fi
echo Extracting \"'RNEWS/mail.c'\"
sed "s/^X//" >'RNEWS/mail.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log:	mail.c_v $
X * Revision 1.1  90/08/31  15:38:14  ud
X * Initial revision
X * 
X */
X# ifndef	LINT
Xstatic char rcsid[] = "$Id: mail.c_v 1.1 90/08/31 15:38:14 ud Exp $";
X# endif		LINT
X# include	<stdio.h>
X
Xextern char	*cuserid ();
Xextern FILE	*popen ();
X
Xvoid
Xsend_mail (lost, articles)
Xint lost;
Xint articles;
X{
X	char	cmd[128];
X	char	*name;
X	FILE	*fp;
X	
X	if ((name = cuserid ()) == (char *) NULL)
X		name = "postmaster";
X	(void) sprintf (cmd, "%s %s", findmod ("/h0/ETC/CMDS/rmail", "rmail"), name);
X	if ((fp = popen (cmd, "w")) == (FILE *) NULL) {
X		logit (2, "ERROR: Can't fork rmail\n");
X		return;
X	}
X	(void) fprintf (fp, "Subject: Failed articles\n\n");
X	(void) fprintf (fp, "Spooled: %d\n", articles);
X	(void) fprintf (fp, "Failed:  %d\n", lost);
X	(void) pclose (fp);
X}
__END__OF__THIS__FILE__
if test -f 'RNEWS/rnews.c' ; then
  echo 'File RNEWS/rnews.c already exists, overwriting it'
  del 'RNEWS/rnews.c'
fi
echo Extracting \"'RNEWS/rnews.c'\"
sed "s/^X//" >'RNEWS/rnews.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log:	main.c_v $
X * Revision 1.1  90/08/31  15:38:17  ud
X * Initial revision
X * 
X */
X# ifndef	LINT
Xstatic char rcsid[] = "$Id: main.c_v 1.1 90/08/31 15:38:17 ud Exp $";
Xstatic char copyright[] = "Copyright (C) 1989, 1990 by Ulrich Dessauer, Germering, Germany.\n";
X# endif		LINT
X# include <stdio.h>
X# include <modes.h>
X# define EXTERN
X# include "rnews.h"
X
Xextern void     compr ();
Xextern void	compr7 ();
Xextern void	exit ();
Xextern void	logit ();
Xextern void	send_mail ();
Xextern long	lseek ();
Xextern char	*info_str ();
Xextern char	*malloc ();
Xextern char	*mktemp ();
Xextern char	*strcpy ();
Xextern FILE	*fopen ();
X
Xvoid		start_rnews ();
X
Xextern int	errno;
X
Xstatic int yet;
X
Xstatic char *help[] = {
X	"Syntax: rnews [<opts>] [<file>] [<opts>]\n",
X	"Function: reading standard input or file and parsing batched news\n",
X	"Options:\n",
X	"     -d<=>num      Debuglevel\n",
X	NULL
X};
X
Xvoid
Xusage ()
X{
X	int t;
X	
X	for (t=0;help[t];++t)
X		(void) fputs (help[t],stderr);
X}
X
Xvoid
Xparse_args (ac,av)
Xint ac;
Xchar *av[];
X{
X	int t;
X	char *x;
X	int i;
X
X	Debug = 0;
X	i = -1;
X	for (t=1;t<ac;++t)
X		if (*av[t] == '-') {
X			x = av[t] + 1;
X			while (*x) {
X				switch (*x) {
X					case 'd':
X						x += (*(x+1) == '=' ? 2 : 1);
X						Debug = atoi (x);
X						while (*x)
X							++x;
X						break;
X					case '?':
X					default:
X						usage ();
X						exit (1);
X				}
X				if (*x)
X					++x;
X			}
X		} else
X			if (i == -1)
X				if ((i = open (av[t],S_IREAD)) != -1) {
X					(void) close (0);
X					(void) dup (i);
X					(void) close (i);
X					i = 0;
X				}
X}
X
Xmain (argc,argv)
Xint argc;
Xchar *argv[];
X{
X	char	tmp[40 + sizeof (TEMPDIR)];
X	char	s[512];
X	int	i;
X	
X	parse_args (argc,argv);
X	(void) sprintf (tmp, "%s/rn.XXXXXX", TEMPDIR);
X	(void) mktemp (tmp);
X	unlink (tmp);
X	if ((i = create (tmp,S_IWRITE | S_IREAD,03, 0)) < 0)
X		exit (_errmsg (1,"Can't create temp-file!\n"));
X
X	if ((info_str (INEWS,s,512) == (char *) NULL) || ((inews= (char *) malloc ((unsigned int) (strlen (s) + 2))) == (char *) NULL))
X		inews = INEWS;
X	else
X		(void) strcpy (inews, s);
X	if ((info_str (UNCOMPRESS,s,512) == (char *) NULL) || ((uncompress = (char *) malloc ((unsigned int) (strlen (s) + 2))) == (char *) NULL))
X		uncompress = UNCOMPRESS;
X	else
X		(void) strcpy (uncompress,s);
X	if ((info_str (MELT,s,512) == (char *) NULL) || ((melt = (char *) malloc ((unsigned int) (strlen (s) + 2))) == (char *) NULL))
X		melt = MELT;
X	else
X		(void) strcpy (melt,s);
X	if ((info_str (DECODE,s,512) == (char *) NULL) || ((decode = (char *) malloc ((unsigned int) (strlen (s) + 2))) == (char *) NULL))
X		decode = DECODE;
X	else
X		(void) strcpy (decode,s);
X
X	if ((info_str (RNEWSLOG,s,512) == (char *) NULL) || ((lpfn = (char *) malloc ((unsigned int) (strlen (s) + 2))) == (char *) NULL))
X		lpfn = LPFN;
X	else
X		(void) strcpy (lpfn,s);
X
X	if ((info_str (RNEWS_SPOOL, s, 512) == (char *) NULL) || ((rnews_spool = malloc ((unsigned int) strlen (s) + 2)) == (char *) NULL))
X		rnews_spool = RNEWS_SPOOLDIR;
X	else
X		(void) strcpy (rnews_spool, s);
X
X	if (access (lpfn,S_IWRITE) < 0)
X		lp = NULL;
X	else
X		lp = fopen (lpfn,"a");
X
X	logit (0,"=== Started (Level %d) ===\n",Debug);
X	error = 0;
X	lost = 0;
X	yet = 0;
X	articles = 0;
X	start_rnews (0,i);
X	(void) close (i);
X	_unlink (tmp);
X	logit (0,"Exits with error %d (Received %d articles)\n",error, articles);
X
X	if (lp) {
X		(void) fclose (lp);
X		lp = NULL;
X	}
X	if (lost)
X		send_mail (lost, articles);
X	exit (error & FATAL ? error : 0);
X}
X
Xvoid
Xstart_rnews (fd,i)
Xint fd;
Xint i;
X{
X	char s[512], sav;
X	int len,mode;
X	int n;
X
X	len = -1;
X	mode = NONE;
X	while ((n = readln (fd,s,512)) > 0) {
X		sav = s[n-1];
X		s[n-1] = '\0';
X		logit (6,"Start_rnews reads '%s'\n",s);
X		if (*s == '#')
X			if (!strncmp (s,BATCHHEAD,BATCHLEN)) {
X				len = get_len (s);
X				logit (1,"Receive batched, len = %d\n",len);
X				mode = BATCH;
X				break;
X			} else if (!strncmp (s,COMHEAD,COMLEN)) {
X				logit (1,"Receive batch/compr\n");
X				mode = COM;
X				break;
X			} else if (!strncmp (s,COM7HEAD,COM7LEN)) {
X				logit (1,"Receive batch/compr/encode\n");
X				mode = COM7;
X				break;
X			} else if (!strncmp (s,FREHEAD,FRELEN)) {
X				logit (1,"Receive batch/freeze\n");
X				mode = FRE;
X				break;
X			} else if (!strncmp (s,FRE7HEAD,FRE7LEN)) {
X				logit (1,"Receive batch/freeze/encode\n");
X				mode = FRE7;
X				break;
X			} else {
X				(void) writeln (i,s,(unsigned int) (n - 1));
X				(void) writeln (i, &sav, 1);
X			}
X		else {
X			(void) writeln (i,s,(unsigned int) (n - 1));
X			(void) writeln (i, &sav, 1);
X		}
X	}
X	if (yet & (1<<mode)) {
X		logit (2,"ERROR: This batch already done\n");
X		error |= SIMPLE;
X		return;
X	} else
X		yet |= 1<<mode;
X	switch (mode) {
X		case NONE:
X			(void) lseek (i,0,0);
X			n = _gs_size (i);
X			logit (3,"Send single File, size = %d\n",n);
X			(void) send_to_inews (i,n);
X			break;
X		case BATCH:
X			logit (3,"Send batch to inews\n");
X			while ((len = send_to_inews (fd,len)) != -1)
X				logit (3,"Sent, next len = %d\n",len);
X			logit (3,"Finished sending batch to inews\n");
X			break;
X		case COM:
X		case FRE:
X			logit (3,"Send compress\n");
X			compr (fd,i,mode == COM ? uncompress : melt);
X			break;
X		case COM7:
X		case FRE7:
X			logit (3,"Send compress/encode\n");
X			compr7 (fd,i,mode == COM7 ? uncompress : melt);
X			break;
X	}
X}
__END__OF__THIS__FILE__
if test -f 'RNEWS/rnews.h' ; then
  echo 'File RNEWS/rnews.h already exists, overwriting it'
  del 'RNEWS/rnews.h'
fi
echo Extracting \"'RNEWS/rnews.h'\"
sed "s/^X//" >'RNEWS/rnews.h' <<'__END__OF__THIS__FILE__'
X/*
X * $Log:	rnews.h_v $
X * Revision 1.1  90/08/31  15:38:22  ud
X * Initial revision
X * 
X */
X# include	"news.h"
X
X# define	RNEWSLOG	"rnews.logfile"
X# define	LPFN		MNEWS_RNEWS_LOGFILE
X
X# define	RNEWS_SPOOL	"RNEWS.DIR"
X# define	RNEWS_SPOOLDIR	MNEWS_RNEWS_SPOOLDIR
X# define	RNEWS_SPOOLSEQ	".seq"
X
X# ifndef	EXTERN
X# define	EXTERN		extern
X# endif		EXTERN
X
XEXTERN char	*inews;
XEXTERN char	*uncompress;
XEXTERN char	*melt;
XEXTERN char	*decode;
XEXTERN int	error;
X
XEXTERN FILE	*lp;
XEXTERN char	*lpfn;
XEXTERN char	*rnews_spool;
XEXTERN int	Debug;
XEXTERN int	articles;
XEXTERN int	lost;
X
X# define	_unlink(s)	if (Debug < 3) (void) unlink(s)
__END__OF__THIS__FILE__
if test -f 'RNEWS/send.c' ; then
  echo 'File RNEWS/send.c already exists, overwriting it'
  del 'RNEWS/send.c'
fi
echo Extracting \"'RNEWS/send.c'\"
sed "s/^X//" >'RNEWS/send.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log:	send.c_v $
X * Revision 1.1  90/08/31  15:38:45  ud
X * Initial revision
X * 
X */
X# ifndef	LINT
Xstatic char rcsid[] = "$Id: send.c_v 1.1 90/08/31 15:38:45 ud Exp $";
X# endif		LINT
X# include <stdio.h>
X# include <ctype.h>
X# include <modes.h>
X# include "rnews.h"
X
Xextern void	logit ();
Xextern char	*realloc ();
Xextern FILE	*xpopen ();
X
Xvoid		save_it ();
X
Xint
Xget_len (s)
Xregister char *s;
X{
X	if (strlen (s) <= BATCHLEN)
X		return (-1);
X	s += BATCHLEN;
X	while (*s && (!isdigit (*s)))
X		++s;
X	if (!*s)
X		return (-1);
X	else
X		return (atoi (s));
X}
X
Xint
Xsend_to_inews (fd,len)
Xint fd,len;
X{
X	static char *buf = NULL;
X	static int csiz = 0;
X	char s[512];
X	int n;
X	int asone;
X	FILE *fp;
X	int nlen;
X	
X	if (!(fp = xpopen (inews,"w"))) {
X		logit (1,"Can't execute '%s'\n", inews);
X		error |= FATAL;
X		return (FALSE);
X	}
X	asone = FALSE;
X	if (len > csiz) {
X		while (len > csiz)
X			csiz += 2048;
X		if (!(buf = (char *) realloc (buf,(unsigned int) (csiz + 5)))) {
X			csiz = 0;
X			while ((len > 0) && ((n = readln (fd,s,512)) > 0)) {
X				s[n] = '\0';
X				logit (6,"Send line '%s' to %s\n", s, inews);
X				(void) fputs (s,fp);
X				len -= n;
X			}
X			asone = FALSE;
X		}
X	}
X	if (len <= csiz)
X		if ((n = read (fd,buf,(unsigned int) len)) == len) {
X			logit (4,"Send article with %d Bytes to %s\n", len, inews);
X			(void) fwrite (buf,n,1,fp);
X			asone = TRUE;
X		} else
X			logit (2,"ERROR: Can't send to %s (reached eof, errno = %d)\n", inews, errno);
X	nlen = -1;
X	while ((n = readln (fd,s,512)) > 0) {
X		s[n] = '\0';
X		if (!strncmp (s,BATCHHEAD,BATCHLEN)) {
X			nlen = get_len (s);
X			logit (3,"Got next batchentry, len = %d\n",nlen);
X			break;
X		} else
X			logit (6,"Skiping junk '%s'\n",s);
X	}
X	n = pclose (fp);
X	logit (n ? 2 : 3,"Pclose returns %d\n",n);
X	if (n)
X		if (asone) {
X			save_it (buf, len);
X			++lost;
X			error |= SIMPLE;
X		} else
X			error |= FATAL;
X	++articles;
X	return (nlen);
X}
X
Xvoid
Xsave_it (buf, len)
Xchar *buf;
Xint len;
X{
X	char	seq[128];
X	char	fn[128];
X	int	fd;
X	int	nr;
X	int	t;
X	
X	(void) sprintf (seq, "%s/%s", rnews_spool, RNEWS_SPOOLSEQ);
X	t = 20;
X	do {
X		if (access (seq, S_IREAD | S_IWRITE) < 0) {
X			fd = create (seq, S_IWRITE | S_ISHARE, 03 | S_ISHARE);
X			nr = 1;
X		} else {
X			fd = open (seq, S_IREAD | S_IWRITE | S_ISHARE);
X			if (fd > 0) {
X				(void) read (fd, &nr, 4);
X				(void) lseek (fd, 0, 0L);
X			}
X		}
X		if (fd < 0)
X			sleep (1);
X	} while ((fd < 0) && (t-- > 0));
X	if (fd < 0) {
X		logit (2, "Can't get spool-seq (errno = %d)\n", errno);
X		error |= FATAL;
X		return;
X	}
X	(void) sprintf (fn, "%s/%05d", rnews_spool, nr++);
X	(void) write (fd, &nr, 4);
X	(void) close (fd);
X	while (access (fn, 0) == 0)
X		(void) strcat (fn, "a");
X	if ((fd = create (fn, S_IWRITE, 03)) < 0) {
X		logit (2, "Can't create spoolfile '%s'\n", fn);
X		error |= FATAL;
X		return;
X	}
X	(void) write (fd, buf, (unsigned int) len);
X	(void) close (fd);
X}
__END__OF__THIS__FILE__
if test -f 'SBATCH/Makefile' ; then
  echo 'File SBATCH/Makefile already exists, overwriting it'
  del 'SBATCH/Makefile'
fi
echo Extracting \"'SBATCH/Makefile'\"
sed "s/^X//" >'SBATCH/Makefile' <<'__END__OF__THIS__FILE__'
X# $Id: Makefile_v 1.1 90/08/31 15:40:27 ud Exp $
X# $Log:	Makefile_v $
X# Revision 1.1  90/08/31  15:40:27  ud
X# Initial revision
X# 
X#
XCC=	cc
XG=	-g
XCFLAGS=	-qt=/dd/TMP $G -v=.. -v=../8BIT
XLIBS=	-l=/dd/LIB/os9lib.l -l=/h3/LIB/8bit.l
XLFLAGS=	-q $(LIBS) $G
XODIR=	/h0/ETC/CMDS
X
XBATCHC=	sbatch.c batch.c none.c com.c com7.c file.c exec.c conv.c
XBATCHR=	sbatch.r batch.r none.r com.r com7.r file.r exec.r conv.r
X
X$(ODIR)/sbatch:	$(BATCHR)
X	$(CC) $(LFLAGS) $(BATCHR) -f=$(ODIR)/sbatch
X	fixmod -uo2.39 -ua8002 $(ODIR)/sbatch
X
Xtags:	$(BATCHC)
X	echo "Ctags:" $?
X	ctags $?
X
Xsbatch.r:	sbatch.c sbatch.h
__END__OF__THIS__FILE__
if test -f 'SBATCH/batch.c' ; then
  echo 'File SBATCH/batch.c already exists, overwriting it'
  del 'SBATCH/batch.c'
fi
echo Extracting \"'SBATCH/batch.c'\"
sed "s/^X//" >'SBATCH/batch.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log:	batch.c_v $
X * Revision 1.1  90/08/31  15:40:10  ud
X * Initial revision
X * 
X */
X# ifndef	LINT
Xstatic char rcsid[] = "$Id: batch.c_v 1.1 90/08/31 15:40:10 ud Exp $";
X# endif		LINT
X# include <stdio.h>
X# include <modes.h>
X# include <dir.h>
X# include "sbatch.h"
X
Xextern void		closedir ();
Xextern void		send_file ();
Xextern void		free ();
Xextern long		lseek ();
Xextern char		*conv_8bit ();
Xextern char		*malloc ();
Xextern char		*mktemp ();
Xextern char		*strcat ();
Xextern char		*strcpy ();
Xextern DIR		*opendir ();
Xextern struct direct	*readdir ();
X
Xvoid
Xsend_batch (fd, sys)
Xint fd;
Xchar *sys;
X{
X	char	tmp[40 + sizeof (TEMPDIR)];
X	int	i;
X
X	(void) sprintf (tmp, "%s/s_bt.XXXXXX", TEMPDIR);
X	(void) mktemp (tmp);
X	while ((i = make_batch (fd, tmp)) != -1) {
X		send_file (sys, i);
X		(void) unlink (tmp);
X	}
X	if (!access (tmp,0))
X		(void) unlink (tmp);
X}
X
Xvoid
X_copy (in,out)
Xregister int in, out;
X{
X	static char	*_bufptr = NULL;
X	static char	sbuf[130];
X	static int	siz;
X	register int	n;
X	register char	*buf;
X
X	if (!_bufptr) {
X		siz = 20000;
X		while (siz && (!(_bufptr = malloc (siz + 16))))
X			siz -= 1000;
X		if (!siz) {
X			siz = 128;
X			_bufptr = sbuf;
X		}
X	}
X	buf = _bufptr;
X	while ((n = read (in,buf,siz)) > 0)
X		(void) write (out,buf,(unsigned int) n);
X}
X
Xint
Xmake_batch (fd, tmp)
Xint fd;
Xchar *tmp;
X{
X	int	found;
X	char	s[128];
X	int	o,i,siz,fsiz;
X	char	*fn;
X	int	n;
X
X	if ((o = create (tmp,S_IWRITE | S_IREAD,03,0)) < 0) {
X		(void) fprintf (stderr,"Can't create '%s' (errno = %d)\n",tmp,errno);
X		error = TRUE;
X		return (-1);
X	}
X	found = FALSE;
X	fsiz = 0;
X	while ((n = readln (fd, buffer, 500)) > 0) {
X		buffer[n-1] = '\0';
X		fprintf (stderr, "Spooling %s\n", buffer);
X		if (!(fn = conv_8bit (buffer)))
X			continue;
X		if ((i = open (fn, S_IREAD)) < 0) {
X			fprintf (stderr, "File %s doesn't exists?!?\n", fn);
X			continue;
X		}
X		siz = _gs_size (i);
X		(void) sprintf (s,"%s %d\n",BATCHHEAD,siz);
X		(void) write (o,s,(unsigned int) strlen (s));
X		_copy (i,o);
X		(void) close (i);
X		unlink (fn);
X		found = TRUE;
X		fsiz += siz;
X		if (fsiz > maxsiz)
X			break;
X	}
X	if (found) {
X		lseek (o, 0, 0);
X		return (o);
X	} else {
X		close (o);
X		return (-1);
X	}
X}
X
X
__END__OF__THIS__FILE__
if test -f 'SBATCH/com.c' ; then
  echo 'File SBATCH/com.c already exists, overwriting it'
  del 'SBATCH/com.c'
fi
echo Extracting \"'SBATCH/com.c'\"
sed "s/^X//" >'SBATCH/com.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log:	com.c_v $
X * Revision 1.1  90/08/31  15:40:13  ud
X * Initial revision
X * 
X */
X# ifndef	LINT
Xstatic char rcsid[] = "$Id: com.c_v 1.1 90/08/31 15:40:13 ud Exp $";
X# endif		LINT
X# include	<stdio.h>
X# include	<types.h>
X# include	<modes.h>
X# include	"sbatch.h"
X
Xextern void	free ();
Xextern void	send_file ();
Xextern long	lseek ();
Xextern char	*index ();
Xextern char	*malloc ();
Xextern char	*mktemp ();
Xextern char	*strcpy ();
X
Xvoid
Xlfcr (fd)
Xregister int fd;
X{
X	static char	*_bufptr = NULL;
X	static char	sbuf[130];
X	static u_int	siz;
X	register char	*buf;
X	register char	*x;
X	register u_int	temp;
X	register int	n;
X	
X	if (!_bufptr) {
X		siz = 20000;
X		while (siz && (!(_bufptr = malloc (siz + 5))))
X			siz -= 1000;
X		if (!siz) {
X			siz = 128;
X			_bufptr = sbuf;
X		}
X	}
X	buf = _bufptr;
X	while ((n = read (fd,buf,siz)) > 0) {
X		(void) lseek (fd,(long) -n,1);
X		temp = (u_int) n;
X		x = buf;
X		while (n-- > 0) {
X			if (*x && (index ("\l\r",*x) != (char *) NULL))
X				*x = *x == '\l' ? '\r' : '\l';
X			++x;
X		}
X		(void) write (fd,buf,temp);
X	}
X}
X
Xvoid
Xsend_com (fd, sys, mode)
Xint fd;
Xchar *sys;
Xint mode;
X{
X	char	tmp[40 + sizeof (TEMPDIR)];
X	int	i;
X	
X	(void) sprintf (tmp, "%s/s_bt.XXXXXX", TEMPDIR);
X	(void) mktemp (tmp);
X	while ((i = make_batch (fd, tmp)) != -1) {
X		lfcr (i);
X		(void) lseek (i,0,0);
X		i = compress_it (i,tmp,mode == COM ? compress : freeze, TRUE);
X		if (i != -1)
X			send_file (sys,i);
X		(void) unlink (tmp);
X	}
X	if (!access (tmp,0))
X		(void) unlink (tmp);
X}
X
Xvoid
Xexec_cprs (cmd)
Xchar *cmd;
X{
X	int t,pid,status;
X	
X	pid = _exec (cmd);
X	if (pid < 0) {
X		(void) fprintf (stderr,"Can't fork '%s' (errno = %d)\n", cmd, errno);
X		error = TRUE;
X		return;
X	} else
X		while (((t = wait (&status)) != pid) && (t != -1))
X			;
X	if (status) {
X		(void) fprintf (stderr,"'%s' returns %d (errno = %d)\n",cmd,status,errno);
X		error = TRUE;
X	}
X	return;
X}	
X
Xint
Xcompress_it (fd,sf,cmd,header)
Xint fd;
Xchar *sf;
Xchar *cmd;
Xint header;
X{
X	char	tmp[40 + sizeof (TEMPDIR)];
X	int	o0, o1;
X	int	o;
X	
X	fprintf (stderr, "Compress %d bytes\n", _gs_size (fd));
X	(void) sprintf (tmp, "%s/cpr.XXXXXX", TEMPDIR);
X	(void) mktemp (tmp);
X	if ((o = create (tmp,S_IREAD | S_IWRITE,03, 0)) < 0) {
X		(void) fprintf (stderr,"Can't create '%s' (errno = %d)\n",tmp,errno);
X		error = TRUE;
X		return (-1);
X	}
X	if (header) {
X		(void) write (o,COMHEAD,COMLEN);
X		(void) write (o,"\l",1);
X	}
X	o0 = dup (0);
X	o1 = dup (1);
X	(void) close (0);
X	(void) dup (fd);
X	(void) close (fd);
X	(void) close (1);
X	(void) dup (o);
X	exec_cprs (cmd);
X	(void) close (0);
X	(void) dup (o0);
X	(void) close (1);
X	(void) dup (o1);
X	(void) close (o0);
X	(void) close (o1);
X	(void) lseek (o,0,0);
X	lfcr (o);
X	(void) lseek (o,0,0);
X	(void) unlink (sf);
X	(void) strcpy (sf,tmp);
X	return (o);
X}
__END__OF__THIS__FILE__
if test -f 'SBATCH/com7.c' ; then
  echo 'File SBATCH/com7.c already exists, overwriting it'
  del 'SBATCH/com7.c'
fi
echo Extracting \"'SBATCH/com7.c'\"
sed "s/^X//" >'SBATCH/com7.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log:	com7.c_v $
X * Revision 1.1  90/08/31  15:40:17  ud
X * Initial revision
X * 
X */
X# ifndef	LINT
Xstatic char rcsid[] = "$Id: com7.c_v 1.1 90/08/31 15:40:17 ud Exp $";
X# endif		LINT
X# include	<stdio.h>
X# include	<modes.h>
X# include	"sbatch.h"
X
Xextern void	lfcr ();
Xextern void	send_file ();
Xextern long	lseek ();
Xextern char	*mktemp ();
Xextern char	*strcpy ();
X
Xvoid
Xsend_com7 (fd, sys, mode)
Xint fd;
Xchar *sys;
Xint mode;
X{
X	char	tmp[40 + sizeof (TEMPDIR)],
X		tmp2[40 + sizeof (TEMPDIR)];
X	int	i, status, t;
X	int	o, o0, o1;
X	int	pid;
X	
X	(void) sprintf (tmp, "%s/s_bt.XXXXXX", TEMPDIR);
X	(void) mktemp (tmp);
X	while ((i = make_batch (fd, tmp)) != -1) {
X		lfcr (i);
X		(void) lseek (i,0,0);
X		i = compress_it (i,tmp,mode == COM7 ? compress : freeze, FALSE);
X		(void) sprintf (tmp2, "%s/enc.XXXXXX", TEMPDIR);
X		(void) mktemp (tmp2);
X		if ((o = create (tmp2,S_IREAD | S_IWRITE,03, 0)) < 0) {
X			(void) fprintf (stderr,"Can't create tmp2 '%s' (errno = %d)\n",tmp2,errno);
X			(void) close (i);
X			(void) unlink (tmp);
X			error = TRUE;
X			return;
X		}
X		(void) write (o,COM7HEAD,COM7LEN);
X		(void) write (o,"\n",1);
X		o0 = dup (0);
X		(void) close (0);
X		(void) dup (i);
X		(void) close (i);
X		o1 = dup (1); 
X		(void) close (1);
X		(void) dup (o);
X		pid = _exec (encode);
X		(void) close (1); 
X		(void) dup (o1);
X		(void) close (0); 
X		(void) dup (o0);
X		if (pid < 0) {
X			(void) fprintf (stderr,"Can't fork '%s' (errno = %d)\n",encode,errno);
X			error = TRUE;
X		}
X		while (((t = wait (&status)) != pid) && (t != -1))
X			;
X		if (status) {
X			(void) fprintf (stderr,"'%s' retuns %d (errno = %d)\n",encode,status,errno);
X			error = TRUE;
X		}
X		(void) unlink (tmp);
X		(void) lseek (o,0,0);
X		send_file (sys,o);
X		(void) unlink (tmp2);
X	}
X	if (!access (tmp,0))
X		(void) unlink (tmp);
X}
__END__OF__THIS__FILE__
if test -f 'SBATCH/conv.c' ; then
  echo 'File SBATCH/conv.c already exists, overwriting it'
  del 'SBATCH/conv.c'
fi
echo Extracting \"'SBATCH/conv.c'\"
sed "s/^X//" >'SBATCH/conv.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log:	conv.c_v $
X * Revision 1.1  90/08/31  15:41:09  ud
X * Initial revision
X * 
X */
X# ifndef	LINT
Xstatic char rcsid[] = "$Id: conv.c_v 1.1 90/08/31 15:41:09 ud Exp $";
X# endif		LINT
X# include	<stdio.h>
X# include	<c8type.h>
X# include	<types.h>
X# include	<modes.h>
X# include	"sbatch.h"
X
Xextern char	*strdup ();
X
Xstatic char	*ext_tab[256];
X
Xchar *
Xconv_8bit (ofn)
Xchar *ofn;
X{
X	static char	tmpfn[40 + sizeof (TEMPDIR)];
X	FILE		*ifp, *ofp;
X	int		fd;
X	int		siz;
X	char		buf[258];
X	int		rconv;
X	int		sizlimit;
X	register char	*text;
X	register int	n, t;
X	register char	*ptr;
X
X	sprintf (tmpfn, "%s/convXXXXXX", TEMPDIR);
X	mktemp (tmpfn);
X	rconv = convmode;
X	sizlimit = maxartsiz;
X	if (index (ofn, '|')) {
X		while (*ofn != '|')
X			switch (to8lower (*ofn++)) {
X				case 'n':
X					rconv = FALSE;
X					break;
X				case 'c':
X					rconv = TRUE;
X					break;
X				case 's':
X					sizlimit = atoi (*ofn == '=' ? ofn + 1 : ofn) << 10;
X					break;
X			}
X			while ((*ofn != '|') && (*ofn != ','))
X				++ofn;
X		++ofn;
X	}
X	if (! (ifp = fopen (ofn, "r"))) {
X		fprintf (stderr, "Can't open %s\n", ofn);
X		return (NULL);
X	}
X	if ((siz = _gs_size (fileno (ifp))) < 0)
X		siz = 4096;
X	if ((sizlimit != -1) && (siz > sizlimit)) {
X		fprintf (stderr, "File exceeds limit of %d kByte (article %s has %d kBytes)\n",
X			(sizlimit >> 10) + 1, ofn, (siz >> 10) + 1);
X		fclose (ifp);
X		return (NULL);
X	}
X	if ((fd = create (tmpfn, S_IWRITE | S_ISIZE, 03, siz)) != -1) {
X		if (! (ofp = fdopen (fd, "w")))
X			close (fd);
X	} else
X		ofp = NULL;
X	if (! ofp) {
X		fprintf (stderr, "Can't create tempfile %s\n", tmpfn);
X		fclose (ifp);
X		return (NULL);
X	}
X	while (fgets (buf, 256, ifp)) {
X		n = strlen (buf);
X		if (rconv) {
X			ptr = buf;
X			t = n;
X			while (t-- > 0)
X				if (!(text = ext_tab[((unsigned char) *ptr++)]))
X					putc (*(ptr - 1), ofp);
X				else
X					fputs (text, ofp);
X		} else
X			fputs (buf, ofp);
X	}
X	fclose (ifp);
X	fclose (ofp);
X	return (tmpfn);
X}
X
Xstatic char *
Xget_tab (s, c)
Xchar *s;
Xunsigned char *c;
X{
X	char	*ptr;
X
X	ptr = s;
X	while (*s && (!is8space (*s)))
X		++s;
X	if (!*s)
X		return (NULL);
X	*s++ = '\0';
X	while (is8space (*s))
X		++s;
X	if (*s == '\\')
X		++s;
X	*c = 0;
X	switch (*ptr) {
X		case '#':
X			++ptr;
X			/* Fall through ... */
X		case '1': case '2': case '3': case '4': case '5':
X		case '6': case '7': case '8': case '9':
X			while (*ptr && index ("0123456789", *ptr)) {
X				*c *= 10;
X				*c += *ptr++ - '0';
X			}
X			break;
X		case '0':
X			++ptr;
X			if (*ptr != 'x') {
X				while (*ptr && index ("01234567", *ptr)) {
X					*c *= 8;
X					*c += *ptr++ - '0';
X				}
X				break;
X			}
X			/* Fall through ... */
X		case '$':
X			++ptr;
X			while (*ptr && index ("01234567890abcdefABCDEF", *ptr)) {
X				*c *= 16;
X				*c += (((*ptr >= '0' && *ptr <= '9')) ? (*ptr - '0') :
X				      (((*ptr >= 'a' && *ptr <= 'f')) ? (*ptr - 'a' + 10) :
X				      (*ptr - 'A' + 10)));
X				++ptr;
X			}
X			break;
X		case '\\':
X			++ptr;
X			/* Fall through ... */
X		default:
X			*c = *ptr;
X			break;
X	}
X	return (s);
X}
X
Xvoid
Xsetup_8bit ()
X{
X	register int	t;
X	char		*buf;
X	int		fd, n;
X	char		*ptr;
X	unsigned char	c;
X
X	for (t = 0; t < 256; ++t)
X		ext_tab[t] = NULL;
X	if (!(buf = malloc (strlen (newslib) + 64)))
X		exit (_errmsg (1, "Can't alloc in setup_8bit for buffer.\n"));
X	sprintf (buf, "%s/%s", newslib, EXT_TAB);
X	if ((fd = open (buf, S_IREAD)) != -1) {
X		while ((n = readln (fd, buf, 64)) > 0) {
X			if ((n == 1) || (buf[0] == '#'))
X				continue;
X			buf[n - 1] = '\0';
X			if (ptr = get_tab (buf, &c))
X				if (!(ext_tab[c] = strdup (ptr)))
X					exit (_errmsg (1, "Can't alloc for conv-table.\n"));
X		}
X		close (fd);
X	}
X	free (buf);
X}
__END__OF__THIS__FILE__
if test -f 'SBATCH/exec.c' ; then
  echo 'File SBATCH/exec.c already exists, overwriting it'
  del 'SBATCH/exec.c'
fi
echo Extracting \"'SBATCH/exec.c'\"
sed "s/^X//" >'SBATCH/exec.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log:	exec.c_v $
X * Revision 1.1  90/08/31  15:40:25  ud
X * Initial revision
X * 
X */
X# ifndef	LINT
Xstatic char rcsid[] = "$Id: exec.c_v 1.1 90/08/31 15:40:25 ud Exp $";
X# endif		LINT
X# include <stdio.h>
X# include "sbatch.h"
X
Xextern void	free ();
Xextern char	*malloc ();
Xextern char	*findmod ();
Xextern char	*strcpy ();
X
Xint
X_exec (lcmd)
Xchar *lcmd;
X{
X	char		**arg;
X	int		pid, t;
X	register char	*x;
X	char		*cmd;
X	
X	if ((cmd = malloc ((unsigned int) (strlen (lcmd) + 5))) == (char *) NULL) {
X		(void) fprintf (stderr,"Can't malloc (errno = %d)\n",errno);
X		error = TRUE;
X		return (-1);
X	}
X	(void) strcpy (cmd, lcmd);
X	if (getargs (cmd, &arg) <= 0) {
X		fprintf (stderr, "Can't split off %s\n", cmd);
X		error = TRUE;
X		return (-1);
X	}
X	pid = os9exec (os9forkc,findmod (arg[0], arg[0]),arg,environ,0,0,3);
X	free (cmd);
X	free ((char *) arg);
X	return (pid);
X}
__END__OF__THIS__FILE__
if test -f 'SBATCH/file.c' ; then
  echo 'File SBATCH/file.c already exists, overwriting it'
  del 'SBATCH/file.c'
fi
echo Extracting \"'SBATCH/file.c'\"
sed "s/^X//" >'SBATCH/file.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log:	file.c_v $
X * Revision 1.1  90/08/31  15:40:22  ud
X * Initial revision
X * 
X */
X# ifndef	LINT
Xstatic char rcsid[] = "$Id: file.c_v 1.1 90/08/31 15:40:22 ud Exp $";
X# endif		LINT
X# include <stdio.h>
X# include "sbatch.h"
X
Xextern void	free ();
Xextern char	*index ();
X
Xint
Xexec_xmit (sys)
Xchar *sys;
X{
X	char		*cmd;
X	int		pid;
X	register char	*p1, *p2, *p3;
X	int		siz;
X	int		t;
X
X	for (t = 0; t < 2; ++t) {
X		if (!t) {
X			siz = 0;
X			p1 = command;
X		} else {
X			if (!(cmd = malloc (siz + 32)))
X				return (-1);
X			p1 = command;
X			p2 = cmd;
X		}
X		while (*p1)
X			if (*p1 == '%') {
X				++p1;
X				switch (*p1) {
X					case 'G':
X						if (!t)
X							++siz;
X						else {
X							if (grade)
X								*p2++ = grade;
X							else
X								*p2++ = DEF_GRADE;
X						}
X						++p1;
X						break;
X					case 'S':
X						if (!t)
X							siz += strlen (sys);
X						else {
X							p3 = sys;
X							while (*p3)
X								*p2++ = *p3++;
X						}
X						++p1;
X						break;
X					default:
X						if (!t)
X							siz += 2;
X						else {
X							*p2++ = '%';
X							*p2++ = *p1;
X						}
X						++p1;
X						break;
X				}
X			} else {
X				if (!t)
X					++siz, ++p1;
X				else
X					*p2++ = *p1++;
X			}
X	}
X	*p2 = '\0';
X	pid = _exec (cmd);
X	free (cmd);
X	return (pid);
X}
X
Xvoid
Xsend_file (sys,fd)
Xchar *sys;
Xint fd;
X{
X	int old0;
X	int pid,status,ret;
X
X	fprintf (stderr, "Sending %d bytes\n", _gs_size (fd));
X	old0 = dup (0);
X	(void) close (0);
X	(void) dup (fd);
X	(void) close (fd);
X	pid = exec_xmit (sys);
X	if (pid < 0)
X		(void) fprintf (stderr,"Can't fork '%s' (errno = %d)\n",command,errno);
X	(void) close (0);
X	(void) dup (old0);
X	(void) close (old0);
X	if (pid < 0)
X		error = TRUE;
X	else
X		while (((ret = wait (&status)) != -1) && (ret != pid))
X			;
X	if (status) {
X		(void) fprintf (stderr,"'%s' returns %d (errno = %d)\n",command,status,errno);
X		error = TRUE;
X	}
X}
__END__OF__THIS__FILE__
if test -f 'SBATCH/none.c' ; then
  echo 'File SBATCH/none.c already exists, overwriting it'
  del 'SBATCH/none.c'
fi
echo Extracting \"'SBATCH/none.c'\"
sed "s/^X//" >'SBATCH/none.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log:	none.c_v $
X * Revision 1.1  90/08/31  15:40:19  ud
X * Initial revision
X * 
X */
X# ifndef	LINT
Xstatic char rcsid[] = "$Id: none.c_v 1.1 90/08/31 15:40:19 ud Exp $";
X# endif		LINT
X# include <stdio.h>
X# include <modes.h>
X# include "sbatch.h"
X
Xextern void		free ();
Xextern char		*conv_8bit ();
Xextern char		*malloc ();
Xextern char		*strcat ();
Xextern char		*strcpy ();
X
Xint
Xsend_single (fd, sys)
Xint fd;
Xchar *sys;
X{
X	int	i,old0,t,status,pid;
X	int	n;
X	char	*fn;
X
X	while ((n = readln (fd, buffer, 500)) > 0) {
X		buffer[n-1] = '\0';
X		if (!(fn = conv_8bit (buffer)))
X			continue;
X		if ((i = open (fn,  S_IREAD)) < 0)
X			continue;
X		old0 = dup (0); 
X		(void) close (0);
X		(void) dup (i);
X		(void) close (i);
X		if ((pid = exec_xmit (sys)) < 0) {
X			(void) fprintf (stderr,"Can't fork '%s' (errno = %d)\n",command,errno);
X			error = TRUE;
X		} else {
X			while (((t = wait (&status)) != pid) && (t != -1))
X				;
X			if (status) {
X				(void) fprintf (stderr,"'%s' returns %d (errno = %d)\n",command,status,errno);
X				error = TRUE;
X			}
X		}
X		(void) close (0);
X		(void) dup (old0);
X		(void) close (old0);
X		unlink (fn);
X	}
X	return (0);
X}
__END__OF__THIS__FILE__
if test -f 'SBATCH/sbatch.c' ; then
  echo 'File SBATCH/sbatch.c already exists, overwriting it'
  del 'SBATCH/sbatch.c'
fi
echo Extracting \"'SBATCH/sbatch.c'\"
sed "s/^X//" >'SBATCH/sbatch.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log:	sbatch.c_v $
X * Revision 1.1  90/08/31  15:40:05  ud
X * Initial revision
X * 
X */
X# ifndef	LINT
Xstatic char rcsid[] = "$Id: sbatch.c_v 1.1 90/08/31 15:40:05 ud Exp $";
Xstatic char copyright[] = "Copyright (C) 1989, 1990 by Ulrich Dessauer, Germering, Germany.\n";
X# endif		LINT
X# include <stdio.h>
X# include <c8type.h>
X# include <modes.h>
X# define EXTERN
X# include "sbatch.h"
X
Xextern char		*info_str ();
Xextern char		*malloc ();
Xextern char		*rindex ();
Xextern char		*strcpy ();
Xextern char		*strdup ();
X
Xvoid			get_info ();
X
Xchar *help[] = {
X	"Syntax: sbatch [<opts>] <system> [<opts>]\n",
X	"Function: sends spoolt newsarticle to <system>\n",
X	"Options:\n",
X	"     -c         Send articles compressed\n",
X	"     -c7        Send articles compressed and encoded\n",
X	"     -cf        Use freeze as the compression program\n",
X	"     -cf7       Like c7 but use freeze\n",
X	"     -B=<bits>  Number of bits for compress (12 - 16)\n",
X	"     -G=<grade> A grading character for the transport mechanism\n",
X	"     -b         Send articles batched (default)\n",
X	"     -s         Send articles as single files\n",
X	"     -C=<cmd>   command to be used when sending articles\n",
X	"     -f=<nr>    sets the maximum spoolfile size to <nr> kByte\n",
X	"     -a=<nr>    sets the maximum size of a single article to <nr> kByte\n",
X	"     -n=<sys>   if systemname for command differs from systemname in filename\n",
X	"     -t         transform 8 bit characters into equivalent 7 bit replacements\n",
X	NULL
X};
X
Xstatic void
Xusage ()
X{
X	int t;
X	
X	for (t=0;help[t];++t)
X		(void) fputs (help[t],stderr);
X}
X
Xstatic int
Xhand (sig)
Xint sig;
X{
X	++error;
X}
X
Xint
Xmain (argc,argv)
Xint argc;
Xchar *argv[];
X{
X	register char	*ptr;
X	int		mode;
X	int		freeze_it;
X	char		*system;
X	char		*sysfn;
X	char		*x;
X	int		t, u, st;
X	char 		*spfn;
X	int		fd;
X	char		batchtmp[40 + sizeof (BATCH_TMP)];
X
X	setuid (getmuid ());
X	system = NULL;
X	sysfn = NULL;
X	mode = BATCH;
X	command = NULL;
X	maxsiz = DEF_MAXSIZ;
X	maxartsiz = DEF_MAXARTSIZ;
X	bitsize = DEF_BITSIZE;
X	grade = DEF_GRADE;
X	convmode = FALSE;
X	error = FALSE;
X	intercept (hand);
X	for (t=1;t<argc;++t)
X		if (*argv[t] == '-') {
X			x = argv[t] + 1;
X			while (*x) {
X				switch (*x) {
X					case 'b':
X						++x;
X						mode = BATCH;
X						break;
X					case 'c':
X						++x;
X						if (*x == 'f') {
X							freeze_it = TRUE;
X							++x;
X						} else
X							freeze_it = FALSE;
X						if (*x == '7') {
X							mode = freeze_it ? FRE7 : COM7;
X							++x;
X						} else
X							mode = freeze_it ? FRE : COM;
X						break;
X					case 's':
X						++x;
X						mode = NONE;
X						break;
X					case 'f':
X						x += (*(x+1) == '=') ? 2 : 1;
X						/* in kByte, so mult with  1024 */
X						maxsiz = atoi (x) << 10;
X						while (*x)
X							++x;
X						break;
X					case 'a':
X						x += (*(x+1) == '=') ? 2 : 1;
X						maxartsiz = atoi (x) << 10;
X						while (*x)
X							++x;
X						break;
X					case 'B':
X						x += (*(x+1) == '=') ? 2 : 1;
X						u = atoi (x);
X						if ((u >= 12) && (u <= 16))
X							bitsize = u;
X						while (*x)
X							++x;
X						break;
X					case 'G':
X						x += (*(x+1) == '=') ? 2 : 1;
X						grade = *x++;
X						break;
X					case 'C':
X						x += (*(x+1) == '=') ? 2 : 1;
X						command = x;
X						while (*x)
X							++x;
X						break;
X					case 'n':
X						x += (*(x+1) == '=') ? 2 : 1;
X						sysfn = strdup (x);
X						while (*x)
X							++x;
X						break;
X					case 't':
X						++x;
X						convmode = TRUE;
X						break;
X					case '?':
X					default:
X						usage ();
X						if (*x != '?')
X							(void) fprintf (stderr,"Unknown Option '%c'\n",*x);
X						exit (*x == '?');
X						break;
X				}
X			}
X		} else
X			if (system)
X				exit (_errmsg (1,"Can't send to more than one system at a time\n"));
X			else
X				system = argv[t];
X	if (!system)
X		exit (_errmsg (1, "Missing system\n"));
X	get_info ();
X	setup_8bit ();
X	if (!command)
X		command = transport;
X	if (!sysfn)
X		if (!(sysfn = strdup (system)))
X			exit (_errmsg (1, "Can't alloc memory\n"));
X	ptr = sysfn;
X	while (*ptr)
X		if (is8ascii (*ptr) && is8alnum (*ptr))
X			++ptr;
X		else
X			*ptr++ = '_';
X	if (!(spfn = malloc (strlen (batchdir) + 40)))
X		exit (_errmsg (1, "Can't alloc memory\n"));
X	sprintf (spfn, "%s/%s", batchdir, sysfn);
X	if (access (spfn, 0) < 0)
X		exit (_errmsg (0, "No aritcle spooled\n"));
X	if (chdir (newsdir) < 0)
X		exit (_errmsg (1, "Can't chdir to %s\n", newsdir));
X	sprintf (batchtmp, "%s.%d.%.24s", BATCH_TMP, getpid (), sysfn);
X	batchtmp[28] = '\0';
X# if	0
X	t = 20;
X	while (((st = info_lock (BATCHLOCK,-1)) < 0) && (t-- > 0))
X		(void) sleep (1);
X	if (st < 0)
X		exit (_errmsg (1,"Unable to lock '%s'\n", BATCHLOCK));
X# endif
X	error = rename (spfn, batchtmp);
X# if	0
X	info_unlock (BATCHLOCK);
X# endif
X	if (error)
X		exit (_errmsg (1, "Can't rename %s to %s\n", spfn, batchtmp));
X	fprintf (stderr, "Spooling news for %s\n", system);
X	sprintf (spfn, "%s/%s", batchdir, batchtmp);
X	if ((fd = open (spfn, S_IREAD)) < 0)
X		exit (_errmsg (1, "Can't open %s\n", spfn));
X	switch (mode) {
X		case NONE:
X			(void) send_single (fd, system);
X			break;
X		case BATCH:
X			send_batch (fd, system);
X			break;
X		case COM:
X		case FRE:
X			/* increase maxsiz by 80% */
X			maxsiz = (maxsiz * 180) / 100;
X			send_com (fd, system, mode);
X			break;
X		case COM7:
X		case FRE7:
X			/* increase maxsiz by 40% */
X			maxsiz = (maxsiz * 140) / 100;
X			send_com7 (fd, system, mode);
X			break;
X		default:
X			exit (_errmsg (1,"Unknown mode %d\n",mode));
X			break;
X	}
X	close (fd);
X	if (!error)
X		unlink (spfn);
X	else
X		rename (spfn, sysfn);
X	if (error)
X		(void) fprintf (stderr,"Error = %d\n",error);
X	exit (error);
X}
X
Xvoid
Xget_info ()
X{
X	char s[256];
X	
X	if ((info_str (COMPRESS,s,250) == (char *) NULL) || ((compress = malloc ((unsigned int) (strlen (s) + 10))) == (char *) NULL)) {
X		if (!(compress = malloc (sizeof (COMPRESS) + 10)))
X			exit (_errmsg (1, "Can't alloc memory.\n"));
X		strcpy (compress, COMPRESS);
X	} else
X		(void) strcpy (compress,s);
X	if (bitsize != DEF_BITSIZE) {
X		sprintf (s, "-b%d", bitsize);
X		strcat (compress, s);
X	}
X	if ((info_str (FREEZE,s,250) == (char *) NULL) || ((freeze = malloc ((unsigned int) (strlen (s) + 2))) == (char *) NULL))
X		freeze = FREEZE;
X	else
X		(void) strcpy (freeze,s);
X	if ((info_str (ENCODE,s,250) == (char *) NULL) || ((encode = malloc ((unsigned int) (strlen (s) + 2))) == (char *) NULL))
X		encode = ENCODE;
X	else
X		(void) strcpy (encode,s);
X	if ((info_str (TRANSPORT, s, 250) == (char *) NULL) || ((transport = malloc ((unsigned int) (strlen (s) + 2))) == (char *) NULL))
X		transport = TRANSPORT_DFLT;
X	else
X		(void) strcpy (transport, s);
X	if ((info_str (BATCHDIR,s,250) == (char *) NULL) || ((batchdir = malloc ((unsigned int) (strlen (s) + 2))) == (char *) NULL))
X		batchdir = DEF_BATCHDIR;
X	else
X		(void) strcpy (batchdir,s);
X	if ((info_str (NEWSDIR,s,250) == (char *) NULL) || ((newsdir = malloc ((unsigned int) (strlen (s) + 2))) == (char *) NULL))
X		newsdir = DEF_NEWSDIR;
X	else
X		(void) strcpy (newsdir,s);
X	if ((info_str (LIBDIR,s,250) == (char *) NULL) || ((newslib = malloc ((unsigned int) (strlen (s) + 2))) == (char *) NULL))
X		newslib = DEF_LIBDIR;
X	else
X		(void) strcpy (newslib,s);
X}
__END__OF__THIS__FILE__
exit 0
: end of shell archive

-- 
Frank Kaefer # fkk@stasys.sta.sub.org # Starnberg, Germany
Xref: sparky de.comp.sources.os9:12 comp.os.os9:1557