/*
 * prgetty.c
 *
 * Allows us to send a sequence of ditty and stty parameters to a
 * port, and then keeping the port open forever, thus preserving
 * any sticky stty parameters, that might otherwise fall off when
 * the port gets closed.
 */

#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#include <termio.h>


/* Paths to ditty:
 * For SCO (MPI and Realport), ditty resides in /usr/bin/ditty.
 * For AIX (Asynch adapters), ditty resides in /usr/lbin/tty/stty-digi
 * For AIX (Realport), ditty resides in /usr/lbin/tty/stty-ncxa
 */
char dittycommand[256] = "/usr/bin/ditty";

/* Default Path to our devices:
 * For SCO Unix (MPI and Realport) it is /dev
 * For SCO Unixware/SVR4/NCR Unix (MPI and Realport) it is /dev/term
 * For Solaris (Asynch adapters and Realport), it is /dev/dty
 * For AIX  (Asynch adapters and Realport( it is /dev
 */
char tty_name[256] = "/dev/";



main(int ac, char **av)
{
        int i, fd;
        char new_line[256];

	/* Did they supply /dev/ttyxxx or just ttyxxx */
	if (*av[1] == '/')
		strcpy(tty_name, av[1]);
	else
        	strcat(tty_name, av[1]);

        fd = open(tty_name, O_RDWR);
        if (fd < 0) {
                perror(av[1]);
                exit(-1);
        }

        strcpy(new_line, dittycommand);
        strcat(new_line, " ");
        for (i = 1; i < ac; i++) {
                strcat(new_line, av[i]);
                strcat(new_line, " ");
        }

        system(new_line);

        while(1)
                sleep(999999);
}
