unix system enhancements

John Owens jso at edison.UUCP
Wed Oct 15 06:28:27 AEST 1986


In article <19 at altunv.UUCP>, brad at altunv.UUCP (Brad Silva) writes:
> In article <1986Oct1.180413.29885 at sq.uucp>, dave at sq.UUCP writes:
> > 	A year or so ago a program called "force" was posted to
> > net.sources. (Sorry but author and date elude me)

Well, I'm the original author, and here it is.  (Of course it is
possible that I never bothered to post it, and that someone else
posted a similar program with the same name.  Naahhh...)

#include <sgtty.h>
#include <stdio.h>

main(argc,argv)
char *argv[];
{
        char ch, *tty;
        static char ttyn[32] = "tty";
        static char devn[32] = "/dev/";
        int fd;
        struct sgttyb ttyb;
        char *strcat();

        if (argc != 2) {
                fprintf(stderr,"Usage: force ttyname\n");
                exit(1);
        }
        tty = argv[1];
        if (*tty >= '0' && *tty <= '9')
                tty=strcat(ttyn,tty);
        if (*tty != '/')
                tty=strcat(devn,tty);
        fprintf(stderr,"force to %s:\n",tty);
        if ((fd=open(tty,2)) == -1) {
                fprintf(stderr,"force: Can't open %s\n",tty);
                exit(1);
        }
        gtty(0,&ttyb);
        ttyb.sg_flags |= RAW;
        stty(0,&ttyb);
        for (;;) {
                if (read(0,&ch,1) != 1) {
                        fprintf(stderr,"read error\r\n");
                        break;
                }
                if (ch == 'P' - 0100)
                        break;
                if (ioctl(fd,TIOCSTI,&ch)) {
                        fprintf(stderr,"ioctl error\r\n");
                        break;
                }
        }
        ttyb.sg_flags &= ~RAW;
        stty(0,&ttyb);
        exit(0);
}

--
John Owens		General Electric Company - Charlottesville, VA
jso at edison.GE.COM	old arpa: jso%edison.GE.COM at seismo.CSS.GOV
+1 804 978 5726		old uucp: {seismo,decuac,houxm,calma}!edison!jso



More information about the Comp.unix mailing list