Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / uip / RCS / ttym.c,v
1 head    1.6;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.6
9 date    92.02.03.17.57.22;      author jromine; state Exp;
10 branches;
11 next    1.5;
12
13 1.5
14 date    92.02.03.16.36.16;      author jromine; state Exp;
15 branches;
16 next    1.4;
17
18 1.4
19 date    90.04.05.15.03.23;      author sources; state Exp;
20 branches;
21 next    1.3;
22
23 1.3
24 date    90.03.12.10.24.37;      author sources; state Exp;
25 branches;
26 next    1.2;
27
28 1.2
29 date    90.02.09.11.08.37;      author sources; state Exp;
30 branches;
31 next    1.1;
32
33 1.1
34 date    90.02.09.11.07.39;      author sources; state Exp;
35 branches;
36 next    ;
37
38
39 desc
40 @@
41
42
43 1.6
44 log
45 @STDC/SYS5/getpw
46 @
47 text
48 @/* ttym.c - miscellaneous routines */
49 #ifndef lint
50 static char ident[] = "@@(#)$Id: ttym.c,v 1.5 1992/02/03 16:36:16 jromine Exp jromine $";
51 #endif  lint
52
53 #include <pwd.h>
54 #ifndef NSIG
55 #include <signal.h>
56 #endif  NSIG
57 #include <sys/time.h>
58
59 static int  ttyf ();
60
61 /* \f */
62
63 static  ttym (fd, command, line, user, vec)
64 int     fd;
65 char   *command,
66        *line,
67        *user,
68       **vec;
69 {
70     TYPESIG     (*pstat) ();
71     char   *ap,
72            *term,
73            *myself,
74            *getlogin (),
75            *rindex (),
76            *ttyname ();
77     struct passwd  *pw;
78 #ifndef __STDC__
79 #ifdef  SYS5
80     struct passwd  *getpwuid ();
81 #endif
82 #endif /* !__STDC__ */
83
84     if ((term = ap = ttyname (2)) && (term = rindex (term, '/')))
85         term++;
86     if (term == NULL || *term == NULL)
87         term = ap;
88     if ((myself = getlogin ()) == NULL || *myself == NULL)
89         myself = (pw = getpwuid (getuid ())) ? pw -> pw_name : NULL;
90
91     pstat = signal (SIGPIPE, SIG_IGN);
92     (void) write (fd, command, strlen (command));
93     (void) write (fd, "", 1);
94
95     if (term)
96         (void) write (fd, term, strlen (term));
97     (void) write (fd, "", 1);
98
99     if (myself)
100         (void) write (fd, myself, strlen (myself));
101     (void) write (fd, "", 1);
102
103     if (line && *line)
104         (void) write (fd, line, strlen (line));
105     (void) write (fd, "", 1);
106
107     if (user && *user)
108         (void) write (fd, user, strlen (user));
109     (void) write (fd, "", 1);
110
111     if (vec)
112         while (ap = *vec++) {
113             (void) write (fd, ap, strlen (ap));
114             (void) write (fd, "", 1);
115         }
116
117     (void) write (fd, "", 1);
118     (void) signal (SIGPIPE, pstat);
119 }
120
121 /* \f */
122
123 static int  ttyv (fd)
124 int     fd;
125 {
126     int     ifds,
127             nbits;
128     char    c;
129     struct timeval tv;
130
131     ifds = 1 << fd;
132     nbits = getdtablesize();
133     tv.tv_sec = SMLWAIT;
134     tv.tv_usec = 0;
135     if (select (nbits, &ifds, (int *) 0, (int *) 0, &tv) <= 0
136             || read (fd, &c, 1) != 1)
137         return NOTOK;
138     if (c == NULL)
139         return fd;
140     putc (c, stderr);
141
142     (void) ttyf (fd, stderr);
143     return NOTOK;
144 }
145
146
147 static int  ttyf (fd, f)
148 int     fd;
149 FILE * f;
150 {
151     int     i;
152     char    buffer[BUFSIZ];
153
154     while ((i = read (fd, buffer, sizeof buffer)) > 0)
155         (void) fwrite (buffer, sizeof (char), i, f);
156     return i;
157 }
158 @
159
160
161 1.5
162 log
163 @fix
164 @
165 text
166 @d3 1
167 a3 1
168 static char ident[] = "@@(#)$Id: ttym.c,v 1.4 1990/04/05 15:03:23 sources Exp jromine $";
169 d32 1
170 d34 1
171 @
172
173
174 1.4
175 log
176 @add ID
177 @
178 text
179 @d3 1
180 a3 1
181 static char ident[] = "@@(#)$Id:$";
182 d30 4
183 a33 2
184     struct passwd  *pw,
185                    *getpwuid ();
186 @
187
188
189 1.3
190 log
191 @TYPESIG fixup
192 @
193 text
194 @d2 3
195 @
196
197
198 1.2
199 log
200 @ANSI compilance
201 @
202 text
203 @d20 1
204 a20 1
205     int     (*pstat) ();
206 @
207
208
209 1.1
210 log
211 @Initial revision
212 @
213 text
214 @d9 2
215 @