[comp.unix.xenix] 'script' on Xenix?

douglasg@hpgrla.HP.COM (@Douglas Genetten) (07/28/88)

Is their a command on Xenix like 'script'
from ULTRIX?

Thanks.

jfh@rpp386.UUCP (John F. Haugh II) (08/01/88)

In article <4960001@hpgrla.HP.COM> douglasg@hpgrla.HP.COM (@Douglas Genetten) writes:
>Is their a command on Xenix like 'script'
>from ULTRIX?
>
>Thanks.

no, but there is now.  cut the bottom off of this article and save it in
the file script.c.  compile that, and you will have a script command.
included is the script from compiling script ...

this will be cleaned up and sent to rich $alz as soon as i get a chance
to write a manpage and makefile.  anyone wanting to help me out could do
that THIS week (aug 1) and email me same.  i won't have time ;-( myself.
--
Script is typescript, started Mon Aug  1 09:46:33 1988
Subscript out of range.
1 - rpp386-> cc -o script -Ox -M3s script.c
script.c
3.8u 2.7s 0:14 45%
2 - rpp386-> ls -l script
-rwxr-xr-x   1 jfh      root       19990 Aug  1 09:47 script
3 - rpp386-> exit
4 - rpp386-> logout
Not a terminal: Not a character device
John's Words of Wisdumb -
Those of you who think you know everything are very annoying to those
of us who do.
Script done Mon Aug  1 09:47:10 1988
--
-------- cut here for script.c ---------
#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <sys/types.h>

FILE	*log;
char	*logname = "typescript";
char	*shell = "/bin/sh";
char	*getenv ();
long	clock;

void	exit ();
void	_exit ();

reader ()
{
	int	c;

	signal (SIGINT, SIG_IGN);
	signal (SIGQUIT, SIG_IGN);

	setbuf (stdout, (char *) 0);
	setbuf (log, (char *) 0);

	time (&clock);
	fprintf (stderr, "Script is %s, started %s",
		logname, asctime (localtime (&clock)));
	fprintf (log, "Script is %s, started %s",
		logname, asctime (localtime (&clock)));

	while ((c = getchar ()) != EOF) {
		putchar (c);
		putc (c, log);
	}
	close (1);
	while (wait ((int *) 0) != -1)
		;

	exit (0);
}

writer ()
{
	int	c;

	signal (SIGINT, SIG_IGN);
	signal (SIGQUIT, SIG_IGN);

	setbuf (stdout, (char *) 0);
	setbuf (log, (char *) 0);

	while ((c = getchar ()) != EOF) {
		putchar (c);
		putc (c, log);
	}
	time (&clock);
	fprintf (stderr, "Script done %s", asctime (localtime (&clock)));
	fprintf (log, "Script done %s", asctime (localtime (&clock)));

	exit (0);
}

main (argc, argv)
int	argc;
char	**argv;
{
	int	pipes[2];		/* pipes for processes */

	if (argc > 1)
		logname = argv[1];

	if (! (log = fopen (logname, "w+"))) {
		perror (logname);
		exit (1);
	}
	if (pipe (pipes) == -1) {
		perror ("can't make pipe");
		exit (1);
	}

	/*
	 * i'm now in the original parent.  after this next fork, the
	 * two processes will be the reader (parent) and an intermediate
	 * process which will fork again.
	 */

	switch (fork ()) {
		case 0:
			close (0);
			dup (pipes[0]);
			close (pipes[0]);

			close (pipes[1]);
			break;
		case -1:
			perror ("can't fork");
			exit (1);
		default:
			close (1);
			dup (pipes[1]);
			close (pipes[1]);

			close (pipes[0]);
			reader ();
	}
	if (pipe (pipes) == -1) {
		perror ("can't make pipe");
		exit (1);
	}

	/*
	 * i'm now in the first child.  after this next fork, the two
	 * processes will be the shell (parent) and writer (child)
	 */

	switch (fork ()) {
		case 0:
			close (0);
			dup (pipes[0]);
			close (pipes[0]);

			close (pipes[1]);

			writer ();
		case -1:
			perror ("can't fork");
			exit (1);
		default:
			close (1);
			dup (pipes[1]);
			close (pipes[1]);

			close (pipes[0]);
			break;
	}
	if (getenv ("SHELL") != (char *) 0)
		shell = getenv ("SHELL");

	close (2);
	dup (1);

	execl (shell, "-h", "-i", (char *) 0);
	perror ("can't exec shell");
	_exit (127);
}
-------- end of script.c -------
-- 
John F. Haugh II                 +--------- Cute Chocolate Quote ---------
HASA, "S" Division               | "USENET should not be confused with
UUCP:   killer!rpp386!jfh        |  something that matters, like CHOCOLATE"
DOMAIN: jfh@rpp386.uucp          |         -- apologizes to Dennis O'Connor