annotate src/hftctl.c @ 464:4ddaee1a9029

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Fri, 20 Dec 1991 07:15:37 +0000
parents 0d3a6b3b64a4
children 8c615e453683
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
1 /* IBM has disclaimed copyright on this module. */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
2
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
3 /***************************************************************/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
4 /* */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
5 /* Function: hftctl */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
6 /* */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
7 /* Syntax: */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
8 /* #include <sys/ioctl.h> */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
9 /* #include <sys/hft.h> */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
10 /* */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
11 /* int hftctl(fildes, request, arg ) */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
12 /* int fildes, request ; */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
13 /* char *arg ; */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
14 /* */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
15 /* Description: */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
16 /* */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
17 /* Does the following: */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
18 /* 1. determines if fildes is pty */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
19 /* does normal ioctl it is not */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
20 /* 2. places fildes into raw mode */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
21 /* 3. converts ioctl arguments to datastream */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
22 /* 4. waits for 2 secs for acknowledgement before */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
23 /* timimg out. */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
24 /* 5. places response in callers buffer ( just like */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
25 /* ioctl. */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
26 /* 6. returns fildes to its original mode */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
27 /* */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
28 /* User of this program should review steps 1,4, and 3. */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
29 /* hftctl makes no check on the request type. It must be */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
30 /* a HFT ioctl that is supported remotely. */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
31 /* This program will use the SIGALRM and alarm(2). Any */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
32 /* Previous alarms are lost. */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
33 /* */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
34 /* Users of this program are free to modify it any way */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
35 /* they want. */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
36 /* */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
37 /* Return Value: */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
38 /* */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
39 /* If ioctl fails, a value of -1 is returned and errno */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
40 /* is set to indicate the error. */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
41 /* */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
42 /***************************************************************/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
43
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
44
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
45 #include <stdio.h>
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
46 #include <fcntl.h>
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
47 #include <errno.h>
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
48 #include <setjmp.h>
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
49 #include <sys/ioctl.h>
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
50 #include <sys/signal.h>
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
51 #include <sys/devinfo.h>
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
52 #include <termio.h>
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
53 #include <sys/hft.h>
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
54 #include <termios.h>
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
55 #include <sys/tty.h>
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
56 /* #include <sys/pty.h> */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
57 #define REMOTE 0x01
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
58
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
59 #undef ioctl
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
60 static char SCCSid[] = "com/gnuemacs/src,3.1,9021-90/05/03-5/3/90" ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
61
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
62 /*************** LOCAL DEFINES **********************************/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
63
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
64 typedef int (*FUNC)() ; /* pointer to a function */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
65
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
66 #define QDEV ((HFQPDEVCH<<8)|HFQPDEVCL)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
67 #define QLOC ((HFQLOCCH<<8)|HFQLOCCL)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
68 #define QPS ((HFQPRESCH<<8)|HFQPRESCL)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
69
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
70 /*************** EXTERNAL / GLOBAL DATA AREA ********************/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
71
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
72 int hfqry() ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
73 int hfskbd() ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
74 char *malloc() ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
75
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
76 extern int errno ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
77 static jmp_buf hftenv ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
78 static int is_ack_vtd ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
79 static FUNC sav_alrm ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
80 static struct hfctlreq req =
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
81 { 0x1b,'[','x',0,0,0,21,HFCTLREQCH,HFCTLREQCL};
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
82 static struct hfctlack ACK =
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
83 { 0x1b,'[','x',0,0,0,21,HFCTLACKCH,HFCTLACKCL};
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
84
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
85 /* FUNC signal() ; */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
86
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
87 /*************** LOCAL MACROS ***********************************/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
88
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
89 #define HFTYPE(p) ((p->hf_typehi<<8)|(p->hf_typelo))
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
90
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
91 #define BYTE4(p) ( (p)[0]<<24 | (p)[1]<<16 | (p)[2]<<8 | (p)[3] )
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
92
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
93 /* read a buffer */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
94 #define RD_BUF(f,p,l) \
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
95 while ( (l) ) \
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
96 if ( ( j = read((f),(p),(l)) ) < 0 ) \
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
97 if ( errno != EINTR ) return (-1) ; \
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
98 else continue ; \
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
99 else { (l)-=j ; (p)+=j ; }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
100
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
101 /*************** HFTCTL FUNCTION *******************************/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
103 hftctl( fd, request, arg )
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
104 int fd ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
105 int request ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
106 union {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
107 struct hfintro *intro ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
108 struct hfquery *query ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
109 char *c ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
110 } arg ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
111 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
112
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
113 int i ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
114 int fd_flag ; /* fcntl flags */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
115 register union {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
116 struct hfintro *cmd ; /* p.cmd - intro des. */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
117 struct hfqphdevc *ph ; /* p.ph - physical dev.*/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
118 char *c ; /* p.c - char ptr */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
119 } p ; /* general pointer */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
120 int pty_new ; /* pty modes */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
121 int pty_old ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
122 int retcode ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
123 struct termios term_new ; /* terminal attributes */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
124 struct termios term_old ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
125 struct devinfo devInfo ; /* defined in sys/devinfo.h */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
126
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
127
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
128 if ( ioctl( fd, IOCINFO, &devInfo ) == -1 ) return(-1) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
129
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
130 if ( devInfo.devtype != DD_PSEU ) /* is it a pty? */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
131 return (ioctl(fd, request, arg) ) ; /* no, do IOCTL */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
132
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
133 /******* START PTY **************/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
134 /** Pty found, possible HFT */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
135 /** set new file des as raw */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
136 /** as you can. */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
137 /********************************/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
138
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
139 /* Get current state of file */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
140 /* descriptor & save */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
141 if ( ( fd_flag = fcntl( fd, F_GETFL, 0 ) ) == -1 ) return (-1) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
142 if ( ioctl( fd, TCGETS, &term_old ) == -1 ) return (-1) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
143 /* set terminal attr to raw */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
144 /* and to delay on read */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
145 pty_new = pty_old | REMOTE ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
146 memcpy( &term_new, &term_old, sizeof( term_new ) ) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
147 term_new.c_iflag = 0 ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
148 term_new.c_oflag = 0 ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
149 term_new.c_lflag = 0 ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
150 /* term_new.c_line = 0 ; */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
151 for ( i = 1 ; i <= 5 ; i++ )
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
152 term_new.c_cc[i] = 0 ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
153 term_new.c_cc[0] = -1 ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
154 ioctl( fd, TCSETS, &term_new ) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
155 if ( fcntl( fd, F_SETFL, fd_flag & ~O_NDELAY ) == -1 )
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
156 return(-1) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
157 /* call spacific function */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
158 if ( request == HFSKBD )
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
159 retcode = hfskbd( fd, request, arg.c) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
160 else /* assume HFQUERY */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
161 retcode = hfqry( fd, request, arg.c) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
162
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
163 fcntl( fd, F_SETFL, fd_flag ) ; /* reset terminal to original */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
164 ioctl( fd, TCSETS, &term_old ) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
165
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
166
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
167 return( retcode ) ; /* return error */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
168 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
169
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
170 /*************** HFSKBD FUNCTION ******************************/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
171 static hfskbd(fd, request, arg )
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
172 int fd ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
173 int request ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
174 struct hfbuf *arg ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
175 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
176 WR_REQ(fd, request, arg->hf_buflen, arg->hf_bufp,0) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
177 return( GT_ACK(fd, request, arg->hf_bufp) ) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
178 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
179
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
180 /*************** HFQUERY FUNCTION ******************************/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
181 static hfqry(fd, request, arg )
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
182 int fd ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
183 int request ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
184 struct hfquery *arg ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
185 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
186 WR_REQ(fd, request, arg->hf_cmdlen, arg->hf_cmd, arg->hf_resplen ) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
187 return( GT_ACK(fd, request, arg->hf_resp ) ) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
188 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
189
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
190
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
191 /*************** GT_ACK FUNCTION ******************************/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
192 static GT_ACK(fd, req, buf )
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
193 int fd ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
194 int req ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
195 char *buf ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
196 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
197
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
198 struct hfctlack ack ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
199 int i = sizeof( ack ) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
200 int j = 0 ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
201 union {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
202 char *c ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
203 struct hfctlack *ack ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
204 } p ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
205
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
206 int hft_alrm() ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
207
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
208 is_ack_vtd = 0 ; /* flag no ACT VTD yet */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
209
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
210 if ( setjmp( hftenv ) ) /* set environment in case */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
211 { /* of time out */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
212 errno=ENODEV ; /* if time out, set errno */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
213 return( -1 ) ; /* flag error */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
214 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
215
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
216 alarm(3) ; /* time out in 3 secs */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
217 sav_alrm = signal( SIGALRM, hft_alrm ) ;/* prepare to catch time out */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
218
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
219 p.ack = &ack ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
220 while ( ! is_ack_vtd ) /* do until valid ACK VTD */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
221 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
222 RD_BUF(fd, p.c, i ) ; /* read until a ACK VTD is fill*/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
223
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
224 if ( ! memcmp( &ack, &ACK, sizeof( HFINTROSZ ) ) /* the ACK intro & */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
225 && ( ack.hf_request == req ) ) /* is it the response we want ?*/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
226 { /* yes, ACK VTD found */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
227 is_ack_vtd = 1 ; /* quickly, flag it */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
228 break ; /* get the %$%#@ out of here */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
229 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
230
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
231 p.ack = &ack ; /* no, then skip 1st */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
232 ++p.c ; /* char and start over */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
233 i = sizeof( ack ) - 1 ; /* one less ESC to cry over */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
234
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
235 while( ( *p.c != 0x1b ) && i ) /* scan for next ESC */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
236 { ++p.c ; --i ; } /* if any */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
237
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
238 ( i ? memcpy( &ack, p.c, i ) : 0 ) ; /* if any left over, then move */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
239 p.ack = &ack ; /* ESC to front of ack struct */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
240 p.c += i ; /* skip over whats been read */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
241 i = sizeof( ack ) - i ; /* set whats left to be read */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
242 } /***** TRY AGAIN */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
243
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
244 alarm(0) ; /* ACK VTD received, reset alrm*/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
245 signal( SIGALRM, sav_alrm ) ; /* reset signal */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
246
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
247 if ( i = ack.hf_arg_len ) /* any data following ? */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
248 { /* yes, */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
249 RD_BUF(fd,buf,i) ; /* read until it is received */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
250 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
251
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
252 if ( errno = ack.hf_retcode ) /* set errno based on returned */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
253 return (-1) ; /* code, if 0, then no error */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
254 else
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
255 return (0) ; /* if set, then error returned */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
256 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
257
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
258 /*************** HFT_ALRM FUNCTION ******************************/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
259 static hft_alrm(sig) /* Function hft_alrm - handle */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
260 int sig ; /* alarm signal */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
261 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
262 signal( SIGALRM, sav_alrm ) ; /* reset to previous */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
263
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
264 if ( is_ack_vtd ) /* has ack vtd arrived ? */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
265 return(0) ; /* yes, then continue */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
266 else /* no, then return with error */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
267 longjmp( hftenv, -1 ) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
268
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
269 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
270
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
271 /*********************************************************************/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
272 /*** ***/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
273 /*** NOTE: Both the HFCTLREQ and the arg structure should be ***/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
274 /*** sent in one io write operation. If terminal ***/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
275 /*** emulators are in NODELAY mode then multiple writes ***/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
276 /*** may cause bogus information to be read by the emulator ***/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
277 /*** depending on the timing. ***/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
278 /*** ***/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
279 /*********************************************************************/
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
280
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
281 static WR_REQ(fd, request, cmdlen, cmd, resplen )
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
282 int fd ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
283 int request ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
284 int cmdlen ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
285 char *cmd ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
286 int resplen ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
287 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
288 struct {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
289 char *c ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
290 struct hfctlreq *req ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
291 } p ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
292 int size ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
293
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
294 req.hf_request = request ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
295 req.hf_arg_len = cmdlen ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
296 req.hf_rsp_len = resplen ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
297
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
298 if ( cmdlen ) /* if arg structure to pass */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
299 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
300 size = sizeof( struct hfctlreq ) + cmdlen ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
301 if ( ( p.c = malloc(size) ) == NULL ) /* malloc one area */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
302 return( -1 ) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
303
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
304 memcpy( p.c, &req, sizeof( req ) ) ; /* copy CTL REQ struct */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
305 memcpy( p.c + sizeof( req ), cmd, cmdlen ) ; /* copy arg struct */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
306 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
307 else
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
308 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
309 p.req = &req ; /* otherwise use only CTL REQ */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
310 size = sizeof( req ) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
311 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
312
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
313 /* write request to terminal */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
314 if ( write(fd,p.c,size) == -1 ) return (-1) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
315 if ( p.req != &req ) /* free if allocated */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
316 free( p.c ) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
317 return (0) ;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
318
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
319 }