491
|
1 /* Interfaces to system-dependent kernel and library entries.
|
579
|
2 Copyright (C) 1985, 1986, 1987, 1988, 1992 Free Software Foundation, Inc.
|
491
|
3
|
|
4 This file is part of GNU Emacs.
|
|
5
|
|
6 GNU Emacs is free software; you can redistribute it and/or modify
|
|
7 it under the terms of the GNU General Public License as published by
|
|
8 the Free Software Foundation; either version 1, or (at your option)
|
|
9 any later version.
|
|
10
|
|
11 GNU Emacs is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with GNU Emacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
19
|
|
20
|
|
21 #include <signal.h>
|
|
22 #include <setjmp.h>
|
|
23
|
|
24 #include "config.h"
|
|
25 #include "lisp.h"
|
|
26 #undef NULL
|
|
27
|
|
28 #define min(x,y) ((x) > (y) ? (y) : (x))
|
|
29
|
|
30 /* In this file, open, read and write refer to the system calls,
|
|
31 not our sugared interfaces sys_open, sys_read and sys_write.
|
|
32 Contrariwise, for systems where we use the system calls directly,
|
|
33 define sys_read, etc. here as aliases for them. */
|
|
34 #ifndef read
|
|
35 #define sys_read read
|
|
36 #define sys_write write
|
|
37 #endif /* `read' is not a macro */
|
|
38
|
|
39 #undef read
|
|
40 #undef write
|
|
41
|
|
42 #ifndef close
|
|
43 #define sys_close close
|
|
44 #else
|
|
45 #undef close
|
|
46 #endif
|
|
47
|
|
48 #ifndef open
|
|
49 #define sys_open open
|
|
50 #else /* `open' is a macro */
|
|
51 #undef open
|
|
52 #endif /* `open' is a macro */
|
|
53
|
|
54 #include <stdio.h>
|
|
55 #include <sys/types.h>
|
|
56 #include <sys/stat.h>
|
|
57 #include <errno.h>
|
|
58
|
|
59 extern int errno;
|
|
60 #ifndef VMS
|
|
61 extern char *sys_errlist[];
|
|
62 #endif
|
|
63
|
|
64 #ifdef VMS
|
|
65 #include <rms.h>
|
|
66 #include <ttdef.h>
|
|
67 #include <tt2def.h>
|
|
68 #include <iodef.h>
|
|
69 #include <ssdef.h>
|
|
70 #include <descrip.h>
|
|
71 #include <fibdef.h>
|
|
72 #include <atrdef.h>
|
|
73 #include <ctype.h>
|
|
74 #include <string.h>
|
|
75 #ifdef __GNUC__
|
|
76 #include <sys/file.h>
|
|
77 #else
|
|
78 #include <file.h>
|
|
79 #endif
|
|
80 #undef F_SETFL
|
|
81 #ifndef RAB$C_BID
|
|
82 #include <rab.h>
|
|
83 #endif
|
|
84 #define MAXIOSIZE ( 32 * PAGESIZE ) /* Don't I/O more than 32 blocks at a time */
|
|
85 #endif /* VMS */
|
|
86
|
|
87 #ifndef BSD4_1
|
|
88 #ifdef BSD /* this is done this way to avoid defined (BSD) || defined (USG)
|
|
89 because the vms compiler doesn't grok `defined' */
|
|
90 #include <fcntl.h>
|
|
91 #endif
|
|
92 #ifdef USG
|
|
93 #include <fcntl.h>
|
|
94 #endif
|
|
95 #endif /* not 4.1 bsd */
|
|
96
|
|
97 /* Get DGUX definition for FASYNC - DJB */
|
|
98 #ifdef DGUX
|
|
99 #include <sys/file.h>
|
|
100 #endif /* DGUX */
|
|
101
|
|
102 #include <sys/ioctl.h>
|
579
|
103 #include "systerm.h"
|
491
|
104
|
|
105 #ifdef BSD
|
|
106 #ifdef BSD4_1
|
|
107 #include <wait.h>
|
|
108 #else /* not 4.1 */
|
|
109 #include <sys/wait.h>
|
|
110 #endif /* not 4.1 */
|
|
111 #endif /* BSD */
|
|
112
|
|
113 #ifdef BROKEN_TIOCGWINSZ
|
|
114 #undef TIOCGWINSZ
|
|
115 #endif
|
|
116
|
|
117 #ifdef USG
|
|
118 #include <sys/utsname.h>
|
|
119 #include <string.h>
|
|
120 #ifndef MEMORY_IN_STRING_H
|
|
121 #include <memory.h>
|
|
122 #endif
|
|
123 #ifdef TIOCGWINSZ
|
|
124 #ifdef NEED_SIOCTL
|
|
125 #include <sys/sioctl.h>
|
|
126 #endif
|
|
127 #ifdef NEED_PTEM_H
|
|
128 #include <sys/stream.h>
|
|
129 #include <sys/ptem.h>
|
|
130 #endif
|
|
131 #endif /* TIOCGWINSZ */
|
|
132 #endif /* USG */
|
|
133
|
|
134 extern int quit_char;
|
|
135
|
|
136 #include "screen.h"
|
|
137 #include "window.h"
|
|
138 #include "termhooks.h"
|
|
139 #include "termchar.h"
|
|
140 #include "termopts.h"
|
|
141 #include "dispextern.h"
|
|
142 #include "process.h"
|
|
143
|
|
144 #ifdef NONSYSTEM_DIR_LIBRARY
|
|
145 #include "ndir.h"
|
|
146 #endif /* NONSYSTEM_DIR_LIBRARY */
|
|
147
|
579
|
148 #include "syssignal.h"
|
|
149 #include "systime.h"
|
491
|
150
|
|
151 static int baud_convert[] =
|
|
152 #ifdef BAUD_CONVERT
|
|
153 BAUD_CONVERT;
|
|
154 #else
|
|
155 {
|
|
156 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
|
|
157 1800, 2400, 4800, 9600, 19200, 38400
|
|
158 };
|
|
159 #endif
|
|
160
|
|
161 extern short ospeed;
|
|
162
|
579
|
163 /* The file descriptor for Emacs's input terminal.
|
|
164 Under Unix, this is always left zero;
|
|
165 under VMS, we place the input channel number here.
|
|
166 This allows us to write more code that works for both VMS and Unix. */
|
|
167 static int input_fd;
|
|
168
|
491
|
169 #ifdef VMS
|
|
170 static struct iosb
|
|
171 {
|
|
172 short status;
|
|
173 short offset;
|
|
174 short termlen;
|
|
175 short term;
|
|
176 } input_iosb;
|
|
177
|
|
178 int kbd_input_ast ();
|
|
179
|
|
180 int waiting_for_ast;
|
|
181 int stop_input;
|
|
182 int input_ef = 0;
|
|
183 int timer_ef = 0;
|
|
184 int process_ef = 0;
|
|
185 int input_eflist;
|
|
186 int timer_eflist;
|
|
187
|
|
188 static $DESCRIPTOR (input_dsc, "TT");
|
|
189 static int terminator_mask[2] = { 0, 0 };
|
|
190
|
|
191 static struct sensemode {
|
|
192 short status;
|
|
193 unsigned char xmit_baud;
|
|
194 unsigned char rcv_baud;
|
|
195 unsigned char crfill;
|
|
196 unsigned char lffill;
|
|
197 unsigned char parity;
|
|
198 unsigned char unused;
|
|
199 char class;
|
|
200 char type;
|
|
201 short scr_wid;
|
|
202 unsigned long tt_char : 24, scr_len : 8;
|
|
203 unsigned long tt2_char;
|
|
204 } sensemode_iosb;
|
|
205 #endif /* VMS */
|
|
206
|
|
207 discard_tty_input ()
|
|
208 {
|
579
|
209 struct emacs_tty buf;
|
491
|
210
|
|
211 if (noninteractive)
|
|
212 return;
|
|
213
|
|
214 /* Discarding input is not safe when the input could contain
|
|
215 replies from the X server. So don't do it. */
|
|
216 if (read_socket_hook)
|
|
217 return;
|
|
218
|
|
219 #ifdef VMS
|
|
220 end_kbd_input ();
|
579
|
221 SYS$QIOW (0, input_fd, IO$_READVBLK|IO$M_PURGE, input_iosb, 0, 0,
|
|
222 &buf.main, 0, 0, terminator_mask, 0, 0);
|
491
|
223 queue_kbd_input ();
|
|
224 #else /* not VMS */
|
|
225 #ifdef APOLLO
|
|
226 {
|
|
227 int zero = 0;
|
|
228 ioctl (0, TIOCFLUSH, &zero);
|
|
229 }
|
|
230 #else /* not Apollo */
|
579
|
231 EMACS_GET_TTY (input_fd, &buf);
|
|
232 EMACS_SET_TTY (input_fd, &buf, 0);
|
491
|
233 #endif /* not Apollo */
|
|
234 #endif /* not VMS */
|
|
235 }
|
|
236
|
|
237 #ifdef SIGTSTP
|
|
238
|
|
239 stuff_char (c)
|
|
240 char c;
|
|
241 {
|
|
242 /* Should perhaps error if in batch mode */
|
|
243 #ifdef TIOCSTI
|
|
244 ioctl (0, TIOCSTI, &c);
|
|
245 #else /* no TIOCSTI */
|
|
246 error ("Cannot stuff terminal input characters in this version of Unix.");
|
|
247 #endif /* no TIOCSTI */
|
|
248 }
|
|
249
|
|
250 #endif /* SIGTSTP */
|
|
251
|
|
252 init_baud_rate ()
|
|
253 {
|
|
254 if (noninteractive)
|
|
255 ospeed = 0;
|
|
256 else
|
|
257 {
|
|
258 #ifdef VMS
|
579
|
259 struct sensemode sg;
|
|
260
|
|
261 SYS$QIOW (0, input_fd, IO$_SENSEMODE, &sg, 0, 0,
|
491
|
262 &sg.class, 12, 0, 0, 0, 0 );
|
579
|
263 ospeed = sg.xmit_baud;
|
|
264 #else /* not VMS */
|
|
265 #ifdef HAVE_TERMIO
|
|
266 struct termio sg;
|
|
267
|
|
268 sg.c_cflag = (sg.c_cflag & ~CBAUD) | B9600;
|
491
|
269 tcgetattr (0, &sg);
|
579
|
270 ospeed = sg.c_cflag & CBAUD;
|
|
271 #else /* neither VMS nor TERMIO */
|
|
272 #ifdef HAVE_TERMIOS
|
|
273 struct termios sg;
|
|
274
|
|
275 sg.c_cflag = (sg.c_cflag & ~CBAUD) | B9600;
|
|
276 tcgetattr (0, &sg);
|
|
277 ospeed = sg.c_cflag & CBAUD;
|
|
278 #else /* neither VMS nor TERMIO nor TERMIOS */
|
|
279 struct sgttyb sg;
|
|
280
|
|
281 sg.sg_ospeed = B9600;
|
|
282 ioctl (0, TIOCGETP, &sg);
|
|
283 ospeed = sg.sg_ospeed;
|
|
284 #endif /* not HAVE_TERMIOS */
|
|
285 #endif /* not HAVE_TERMIO */
|
491
|
286 #endif /* not VMS */
|
|
287 }
|
|
288
|
|
289 baud_rate = (ospeed < sizeof baud_convert / sizeof baud_convert[0]
|
|
290 ? baud_convert[ospeed] : 9600);
|
|
291 if (baud_rate == 0)
|
|
292 baud_rate = 1200;
|
|
293 }
|
|
294
|
|
295 /*ARGSUSED*/
|
|
296 set_exclusive_use (fd)
|
|
297 int fd;
|
|
298 {
|
|
299 #ifdef FIOCLEX
|
|
300 ioctl (fd, FIOCLEX, 0);
|
|
301 #endif
|
|
302 /* Ok to do nothing if this feature does not exist */
|
|
303 }
|
|
304
|
|
305 #ifndef subprocesses
|
|
306
|
|
307 wait_without_blocking ()
|
|
308 {
|
|
309 #ifdef BSD
|
|
310 wait3 (0, WNOHANG | WUNTRACED, 0);
|
|
311 #else
|
|
312 croak ("wait_without_blocking");
|
|
313 #endif
|
|
314 synch_process_alive = 0;
|
|
315 }
|
|
316
|
|
317 #endif /* not subprocesses */
|
|
318
|
|
319 int wait_debugging; /* Set nonzero to make following function work under dbx
|
|
320 (at least for bsd). */
|
|
321
|
|
322 SIGTYPE
|
|
323 wait_for_termination_signal ()
|
|
324 {}
|
|
325
|
|
326 /* Wait for subprocess with process id `pid' to terminate and
|
|
327 make sure it will get eliminated (not remain forever as a zombie) */
|
|
328
|
|
329 wait_for_termination (pid)
|
|
330 int pid;
|
|
331 {
|
|
332 while (1)
|
|
333 {
|
|
334 #ifdef subprocesses
|
|
335 #ifdef VMS
|
|
336 int status;
|
|
337
|
|
338 status = sys$forcex (&pid, 0, 0);
|
|
339 break;
|
|
340 #else /* not VMS */
|
|
341
|
|
342 /* Exit if the process has terminated. */
|
|
343 if (!synch_process_alive)
|
|
344 break;
|
|
345 /* Otherwise wait 1 second or until a signal comes in. */
|
|
346 signal (SIGALRM, wait_for_termination_signal);
|
|
347 alarm (1);
|
|
348 pause ();
|
|
349 alarm (0);
|
|
350 signal (SIGALRM, SIG_IGN);
|
|
351 #endif /* not VMS */
|
|
352 #else /* not subprocesses */
|
|
353 #ifndef BSD4_1
|
|
354 if (kill (pid, 0) < 0)
|
|
355 break;
|
|
356 wait (0);
|
|
357 #else /* BSD4_1 */
|
|
358 int status;
|
|
359 status = wait (0);
|
|
360 if (status == pid || status == -1)
|
|
361 break;
|
|
362 #endif /* BSD4_1 */
|
|
363 #endif /* not subprocesses */
|
|
364 }
|
|
365 }
|
|
366
|
|
367 #ifdef subprocesses
|
|
368
|
|
369 /*
|
|
370 * flush any pending output
|
|
371 * (may flush input as well; it does not matter the way we use it)
|
|
372 */
|
|
373
|
|
374 flush_pending_output (channel)
|
|
375 int channel;
|
|
376 {
|
|
377 #ifdef HAVE_TERMIOS
|
|
378 /* If we try this, we get hit with SIGTTIN, because
|
|
379 the child's tty belongs to the child's pgrp. */
|
|
380 #else
|
|
381 #ifdef TCFLSH
|
|
382 ioctl (channel, TCFLSH, 1);
|
|
383 #else
|
|
384 #ifdef TIOCFLUSH
|
|
385 int zero = 0;
|
|
386 /* 3rd arg should be ignored
|
|
387 but some 4.2 kernels actually want the address of an int
|
|
388 and nonzero means something different. */
|
|
389 ioctl (channel, TIOCFLUSH, &zero);
|
|
390 #endif
|
|
391 #endif
|
|
392 #endif
|
|
393 }
|
|
394
|
|
395 #ifndef VMS
|
|
396 /* Set up the terminal at the other end of a pseudo-terminal that
|
|
397 we will be controlling an inferior through.
|
|
398 It should not echo or do line-editing, since that is done
|
|
399 in Emacs. No padding needed for insertion into an Emacs buffer. */
|
|
400
|
|
401 child_setup_tty (out)
|
|
402 int out;
|
|
403 {
|
579
|
404 struct emacs_tty s;
|
|
405
|
|
406 EMACS_GET_TTY (out, &s);
|
|
407
|
491
|
408 #ifdef HAVE_TERMIO
|
579
|
409 s.main.c_oflag |= OPOST; /* Enable output postprocessing */
|
|
410 s.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL on output */
|
|
411 s.main.c_oflag &= ~(NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
|
|
412 /* No output delays */
|
|
413 s.main.c_lflag &= ~ECHO; /* Disable echo */
|
|
414 s.main.c_lflag |= ISIG; /* Enable signals */
|
|
415 s.main.c_iflag &= ~IUCLC; /* Disable map of upper case to lower on
|
|
416 input */
|
|
417 s.main.c_oflag &= ~OLCUC; /* Disable map of lower case to upper on
|
|
418 output */
|
|
419 #if 0
|
|
420 /* Said to be unnecesary: */
|
|
421 s.main.c_cc[VMIN] = 1; /* minimum number of characters to accept */
|
|
422 s.main.c_cc[VTIME] = 0; /* wait forever for at least 1 character */
|
|
423 #endif
|
|
424
|
|
425 s.main.c_lflag |= ICANON; /* Enable erase/kill and eof processing */
|
|
426 s.main.c_cc[VEOF] = 04; /* insure that EOF is Control-D */
|
|
427 s.main.c_cc[VERASE] = 0377; /* disable erase processing */
|
|
428 s.main.c_cc[VKILL] = 0377; /* disable kill processing */
|
|
429
|
491
|
430 #ifdef HPUX
|
579
|
431 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */
|
491
|
432 #endif /* HPUX */
|
579
|
433
|
491
|
434 #ifdef AIX
|
|
435 /* AIX enhanced edit loses NULs, so disable it */
|
|
436 #ifndef IBMR2AIX
|
579
|
437 s.main.c_line = 0;
|
|
438 s.main.c_iflag &= ~ASCEDIT;
|
491
|
439 #endif
|
|
440 /* Also, PTY overloads NUL and BREAK.
|
|
441 don't ignore break, but don't signal either, so it looks like NUL. */
|
579
|
442 s.main.c_iflag &= ~IGNBRK;
|
|
443 s.main.c_iflag &= ~BRKINT;
|
|
444 /* QUIT and INTR work better as signals, so disable character forms */
|
|
445 s.main.c_cc[VQUIT] = 0377;
|
|
446 s.main.c_cc[VINTR] = 0377;
|
|
447 s.main.c_cc[VEOL] = 0377;
|
|
448 s.main.c_lflag &= ~ISIG;
|
|
449 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */
|
491
|
450 #endif /* AIX */
|
|
451
|
|
452 #else /* not HAVE_TERMIO */
|
579
|
453
|
|
454 s.main.sg_flags &= ~(ECHO | CRMOD | ANYP | ALLDELAY | RAW | LCASE
|
|
455 | CBREAK | TANDEM);
|
|
456 s.main.sg_erase = 0377;
|
|
457 s.main.sg_kill = 0377;
|
|
458
|
491
|
459 #endif /* not HAVE_TERMIO */
|
|
460
|
579
|
461 EMACS_SET_TTY (out, &s, 0);
|
491
|
462
|
|
463 #ifdef BSD4_1
|
|
464 if (interrupt_input)
|
|
465 reset_sigio ();
|
|
466 #endif /* BSD4_1 */
|
|
467 #ifdef RTU
|
|
468 {
|
|
469 int zero = 0;
|
|
470 ioctl (out, FIOASYNC, &zero);
|
|
471 }
|
|
472 #endif /* RTU */
|
|
473 }
|
|
474 #endif /* not VMS */
|
|
475
|
|
476 #endif /* subprocesses */
|
|
477
|
|
478 /*ARGSUSED*/
|
|
479 setpgrp_of_tty (pid)
|
|
480 int pid;
|
|
481 {
|
579
|
482 EMACS_SET_TTY_PGRP (input_fd, pid);
|
491
|
483 }
|
|
484
|
|
485 /* Record a signal code and the handler for it. */
|
|
486 struct save_signal
|
|
487 {
|
|
488 int code;
|
|
489 SIGTYPE (*handler) ();
|
|
490 };
|
|
491
|
|
492 /* Suspend the Emacs process; give terminal to its superior. */
|
|
493
|
|
494 sys_suspend ()
|
|
495 {
|
|
496 #ifdef VMS
|
|
497 unsigned long parent_id;
|
|
498
|
|
499 parent_id = getppid ();
|
|
500 if (parent_id && parent_id != 0xffffffff)
|
|
501 {
|
|
502 SIGTYPE (*oldsig)() = (int) signal (SIGINT, SIG_IGN);
|
|
503 int status = LIB$ATTACH (&parent_id) & 1;
|
|
504 signal (SIGINT, oldsig);
|
|
505 return status;
|
|
506 }
|
|
507 else
|
|
508 {
|
|
509 struct {
|
|
510 int l;
|
|
511 char *a;
|
|
512 } d_prompt;
|
|
513 d_prompt.l = sizeof ("Emacs: "); /* Our special prompt */
|
|
514 d_prompt.a = "Emacs: "; /* Just a reminder */
|
|
515 lib$spawn (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt, 0);
|
|
516 return 1;
|
|
517 }
|
|
518 return -1;
|
|
519 #else
|
|
520 #ifdef SIGTSTP
|
|
521
|
579
|
522 EMACS_KILLPG (getpgrp (0), SIGTSTP);
|
491
|
523
|
|
524 #else /* No SIGTSTP */
|
|
525 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
|
|
526 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
|
|
527 kill (getpid (), SIGQUIT);
|
|
528
|
|
529 #else /* No SIGTSTP or USG_JOBCTRL */
|
|
530
|
|
531 /* On a system where suspending is not implemented,
|
|
532 instead fork a subshell and let it talk directly to the terminal
|
|
533 while we wait. */
|
|
534 int pid = fork ();
|
|
535 struct save_signal saved_handlers[5];
|
|
536
|
|
537 saved_handlers[0].code = SIGINT;
|
|
538 saved_handlers[1].code = SIGQUIT;
|
|
539 saved_handlers[2].code = SIGTERM;
|
|
540 #ifdef SIGIO
|
|
541 saved_handlers[3].code = SIGIO;
|
|
542 saved_handlers[4].code = 0;
|
|
543 #else
|
|
544 saved_handlers[3].code = 0;
|
|
545 #endif
|
|
546
|
|
547 if (pid == -1)
|
|
548 error ("Can't spawn subshell");
|
|
549 if (pid == 0)
|
|
550 {
|
|
551 char *sh;
|
|
552
|
|
553 sh = (char *) egetenv ("SHELL");
|
|
554 if (sh == 0)
|
|
555 sh = "sh";
|
|
556 /* Use our buffer's default directory for the subshell. */
|
|
557 {
|
|
558 Lisp_Object dir;
|
|
559 unsigned char *str;
|
|
560 int len;
|
|
561
|
|
562 /* mentioning current_buffer->buffer would mean including buffer.h,
|
|
563 which somehow wedges the hp compiler. So instead... */
|
|
564
|
|
565 dir = intern ("default-directory");
|
|
566 /* Can't use NULL */
|
|
567 if (XFASTINT (Fboundp (dir)) == XFASTINT (Qnil))
|
|
568 goto xyzzy;
|
|
569 dir = Fsymbol_value (dir);
|
|
570 if (XTYPE (dir) != Lisp_String)
|
|
571 goto xyzzy;
|
|
572
|
|
573 str = (unsigned char *) alloca (XSTRING (dir)->size + 2);
|
|
574 len = XSTRING (dir)->size;
|
|
575 bcopy (XSTRING (dir)->data, str, len);
|
|
576 if (str[len - 1] != '/') str[len++] = '/';
|
|
577 str[len] = 0;
|
|
578 chdir (str);
|
|
579 }
|
|
580 xyzzy:
|
|
581 #ifdef subprocesses
|
|
582 close_process_descs (); /* Close Emacs's pipes/ptys */
|
|
583 #endif
|
|
584 nice (-nice (0)); /* Give the new shell the default piority */
|
|
585 execlp (sh, sh, 0);
|
|
586 write (1, "Can't execute subshell", 22);
|
|
587 _exit (1);
|
|
588 }
|
|
589
|
|
590 save_signal_handlers (saved_handlers);
|
|
591 wait_for_termination (pid);
|
|
592 restore_signal_handlers (saved_handlers);
|
|
593
|
|
594 #endif /* no USG_JOBCTRL */
|
|
595 #endif /* no SIGTSTP */
|
|
596 #endif /* not VMS */
|
|
597 }
|
|
598
|
|
599 save_signal_handlers (saved_handlers)
|
|
600 struct save_signal *saved_handlers;
|
|
601 {
|
|
602 while (saved_handlers->code)
|
|
603 {
|
|
604 saved_handlers->handler = signal (saved_handlers->code, SIG_IGN);
|
|
605 saved_handlers++;
|
|
606 }
|
|
607 }
|
|
608
|
|
609 restore_signal_handlers (saved_handlers)
|
|
610 struct save_signal *saved_handlers;
|
|
611 {
|
|
612 while (saved_handlers->code)
|
|
613 {
|
|
614 signal (saved_handlers->code, saved_handlers->handler);
|
|
615 saved_handlers++;
|
|
616 }
|
|
617 }
|
|
618
|
|
619 #ifdef F_SETFL
|
|
620
|
|
621 int old_fcntl_flags;
|
|
622
|
|
623 init_sigio ()
|
|
624 {
|
|
625 #ifdef FASYNC
|
|
626 old_fcntl_flags = fcntl (0, F_GETFL, 0) & ~FASYNC;
|
|
627 #endif
|
|
628 request_sigio ();
|
|
629 }
|
|
630
|
|
631 reset_sigio ()
|
|
632 {
|
|
633 unrequest_sigio ();
|
|
634 }
|
|
635
|
|
636 #ifdef FASYNC /* F_SETFL does not imply existance of FASYNC */
|
|
637
|
|
638 request_sigio ()
|
|
639 {
|
|
640 #ifdef SIGWINCH
|
624
|
641 {
|
|
642 int dummy;
|
|
643
|
|
644 EMACS_SIGUNBLOCKX (SIGWINCH, dummy);
|
|
645 }
|
491
|
646 #endif
|
|
647 fcntl (0, F_SETFL, old_fcntl_flags | FASYNC);
|
|
648
|
|
649 interrupts_deferred = 0;
|
|
650 }
|
|
651
|
|
652 unrequest_sigio ()
|
|
653 {
|
|
654 #ifdef SIGWINCH
|
624
|
655 {
|
|
656 int dummy;
|
|
657
|
|
658 EMACS_SIGBLOCK (SIGWINCH, dummy);
|
|
659 }
|
491
|
660 #endif
|
|
661 fcntl (0, F_SETFL, old_fcntl_flags);
|
|
662 interrupts_deferred = 1;
|
|
663 }
|
|
664
|
|
665 #else /* no FASYNC */
|
|
666 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
|
|
667
|
|
668 request_sigio ()
|
|
669 {
|
|
670 int on = 1;
|
|
671 ioctl (0, FIOASYNC, &on);
|
|
672 interrupts_deferred = 0;
|
|
673 }
|
|
674
|
|
675 unrequest_sigio ()
|
|
676 {
|
|
677 int off = 0;
|
|
678
|
|
679 ioctl (0, FIOASYNC, &off);
|
|
680 interrupts_deferred = 1;
|
|
681 }
|
|
682
|
|
683 #else /* not FASYNC, not STRIDE */
|
|
684
|
|
685 request_sigio ()
|
|
686 {
|
|
687 croak ("request_sigio");
|
|
688 }
|
|
689
|
|
690 unrequest_sigio ()
|
|
691 {
|
|
692 croak ("unrequest_sigio");
|
|
693 }
|
|
694
|
|
695 #endif /* STRIDE */
|
|
696 #endif /* FASYNC */
|
|
697 #endif /* F_SETFL */
|
|
698
|
579
|
699 /* The initial tty mode bits */
|
|
700 struct emacs_tty old_tty;
|
491
|
701
|
|
702 int term_initted; /* 1 if outer tty status has been recorded */
|
|
703
|
579
|
704 #ifdef BSD4_1
|
|
705 /* BSD 4.1 needs to keep track of the lmode bits in order to start
|
|
706 sigio. */
|
|
707 int lmode;
|
|
708 #endif
|
|
709
|
491
|
710 #ifdef F_SETOWN
|
|
711 int old_fcntl_owner;
|
|
712 #endif /* F_SETOWN */
|
|
713
|
|
714 /* This may also be defined in stdio,
|
|
715 but if so, this does no harm,
|
|
716 and using the same name avoids wasting the other one's space. */
|
|
717
|
|
718 #if defined (USG) || defined (DGUX)
|
|
719 unsigned char _sobuf[BUFSIZ+8];
|
|
720 #else
|
|
721 char _sobuf[BUFSIZ];
|
|
722 #endif
|
|
723
|
|
724 #ifdef TIOCGLTC
|
|
725 static struct ltchars new_ltchars = {-1,-1,-1,-1,-1,-1};
|
|
726 #endif
|
|
727 #ifdef TIOCGETC
|
|
728 static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1};
|
|
729 #endif
|
|
730
|
|
731 init_sys_modes ()
|
|
732 {
|
579
|
733 struct emacs_tty tty;
|
|
734
|
491
|
735 #ifdef VMS
|
|
736 #if 0
|
|
737 static int oob_chars[2] = {0, 1 << 7}; /* catch C-g's */
|
|
738 extern int (*interrupt_signal) ();
|
|
739 #endif
|
|
740 #endif
|
|
741
|
|
742 if (noninteractive)
|
|
743 return;
|
|
744
|
|
745 #ifdef VMS
|
|
746 if (!input_ef)
|
|
747 input_ef = get_kbd_event_flag ();
|
|
748 /* LIB$GET_EF (&input_ef); */
|
|
749 SYS$CLREF (input_ef);
|
|
750 waiting_for_ast = 0;
|
|
751 if (!timer_ef)
|
|
752 timer_ef = get_timer_event_flag ();
|
|
753 /* LIB$GET_EF (&timer_ef); */
|
|
754 SYS$CLREF (timer_ef);
|
|
755 if (!process_ef)
|
|
756 {
|
|
757 LIB$GET_EF (&process_ef);
|
|
758 SYS$CLREF (process_ef);
|
|
759 }
|
|
760 if (input_ef / 32 != process_ef / 32)
|
|
761 croak ("Input and process event flags in different clusters.");
|
|
762 if (input_ef / 32 != timer_ef / 32)
|
|
763 croak ("Input and process event flags in different clusters.");
|
|
764 input_eflist = ((unsigned) 1 << (input_ef % 32)) |
|
|
765 ((unsigned) 1 << (process_ef % 32));
|
|
766 timer_eflist = ((unsigned) 1 << (input_ef % 32)) |
|
|
767 ((unsigned) 1 << (timer_ef % 32));
|
|
768 #ifndef VMS4_4
|
|
769 sys_access_reinit ();
|
|
770 #endif
|
|
771 #endif /* not VMS */
|
579
|
772
|
|
773 EMACS_GET_TTY (input_fd, &old_tty);
|
|
774
|
491
|
775 if (!read_socket_hook && EQ (Vwindow_system, Qnil))
|
|
776 {
|
579
|
777 tty = old_tty;
|
491
|
778
|
|
779 #ifdef HAVE_TERMIO
|
579
|
780 tty.main.c_iflag |= (IGNBRK); /* Ignore break condition */
|
|
781 tty.main.c_iflag &= ~ICRNL; /* Disable map of CR to NL on input */
|
491
|
782 #ifdef ISTRIP
|
579
|
783 tty.main.c_iflag &= ~ISTRIP; /* don't strip 8th bit on input */
|
491
|
784 #endif
|
579
|
785 tty.main.c_lflag &= ~ECHO; /* Disable echo */
|
|
786 tty.main.c_lflag &= ~ICANON; /* Disable erase/kill processing */
|
|
787 tty.main.c_lflag |= ISIG; /* Enable signals */
|
491
|
788 if (flow_control)
|
|
789 {
|
579
|
790 tty.main.c_iflag |= IXON; /* Enable start/stop output control */
|
491
|
791 #ifdef IXANY
|
579
|
792 tty.main.c_iflag &= ~IXANY;
|
491
|
793 #endif /* IXANY */
|
|
794 }
|
|
795 else
|
579
|
796 tty.main.c_iflag &= ~IXON; /* Disable start/stop output control */
|
|
797 tty.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL
|
|
798 on output */
|
|
799 tty.main.c_oflag &= ~TAB3; /* Disable tab expansion */
|
491
|
800 #ifdef CS8
|
|
801 if (meta_key)
|
|
802 {
|
579
|
803 tty.main.c_cflag |= CS8; /* allow 8th bit on input */
|
|
804 tty.main.c_cflag &= ~PARENB;/* Don't check parity */
|
491
|
805 }
|
|
806 #endif
|
579
|
807 tty.main.c_cc[VINTR] = quit_char; /* C-g (usually) gives SIGINT */
|
491
|
808 /* Set up C-g for both SIGQUIT and SIGINT.
|
|
809 We don't know which we will get, but we handle both alike
|
|
810 so which one it really gives us does not matter. */
|
579
|
811 tty.main.c_cc[VQUIT] = quit_char;
|
|
812 tty.main.c_cc[VMIN] = 1; /* Input should wait for at least 1 char */
|
|
813 tty.main.c_cc[VTIME] = 0; /* no matter how long that takes. */
|
491
|
814 #ifdef VSWTCH
|
579
|
815 tty.main.c_cc[VSWTCH] = CDEL; /* Turn off shell layering use
|
|
816 of C-z */
|
491
|
817 #endif /* VSWTCH */
|
|
818 #if defined (mips) || defined (HAVE_TCATTR)
|
|
819 /* The following code looks like the right thing in general,
|
|
820 but it is said to cause a crash on USG V.4.
|
|
821 Let's play safe by turning it on only for the MIPS. */
|
|
822 #ifdef VSUSP
|
579
|
823 tty.main.c_cc[VSUSP] = CDEL; /* Turn off mips handling of C-z. */
|
491
|
824 #endif /* VSUSP */
|
|
825 #ifdef V_DSUSP
|
579
|
826 tty.main.c_cc[V_DSUSP] = CDEL; /* Turn off mips handling of C-y. */
|
491
|
827 #endif /* V_DSUSP */
|
|
828 #endif /* mips or HAVE_TCATTR */
|
|
829 #ifdef AIX
|
|
830 #ifndef IBMR2AIX
|
|
831 /* AIX enhanced edit loses NULs, so disable it */
|
579
|
832 tty.main.c_line = 0;
|
|
833 tty.main.c_iflag &= ~ASCEDIT;
|
491
|
834 #else
|
579
|
835 tty.main.c_cc[VSTRT] = 255;
|
|
836 tty.main.c_cc[VSTOP] = 255;
|
|
837 tty.main.c_cc[VSUSP] = 255;
|
|
838 tty.main.c_cc[VDSUSP] = 255;
|
491
|
839 #endif /* IBMR2AIX */
|
|
840 /* Also, PTY overloads NUL and BREAK.
|
|
841 don't ignore break, but don't signal either, so it looks like NUL.
|
|
842 This really serves a purpose only if running in an XTERM window
|
|
843 or via TELNET or the like, but does no harm elsewhere. */
|
579
|
844 tty.main.c_iflag &= ~IGNBRK;
|
|
845 tty.main.c_iflag &= ~BRKINT;
|
491
|
846 #endif
|
|
847 #else /* if not HAVE_TERMIO */
|
|
848 #ifdef VMS
|
579
|
849 tty.main.tt_char |= TT$M_NOECHO;
|
491
|
850 if (meta_key)
|
579
|
851 tty.main.tt_char |= TT$M_EIGHTBIT
|
491
|
852 if (flow_control)
|
579
|
853 tty.main.tt_char |= TT$M_TTSYNC;
|
491
|
854 else
|
579
|
855 tty.main.tt_char &= ~TT$M_TTSYNC;
|
|
856 tty.main.tt2_char |= TT2$M_PASTHRU | TT2$M_XON;
|
491
|
857 #else /* not VMS (BSD, that is) */
|
579
|
858 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS);
|
491
|
859 if (meta_key)
|
579
|
860 tty.main.sg_flags |= ANYP;
|
|
861 tty.main.sg_flags |= interrupt_input ? RAW : CBREAK;
|
491
|
862 #endif /* not VMS (BSD, that is) */
|
|
863 #endif /* not HAVE_TERMIO */
|
|
864
|
579
|
865 /* If going to use CBREAK mode, we must request C-g to interrupt
|
|
866 and turn off start and stop chars, etc. If not going to use
|
|
867 CBREAK mode, do this anyway so as to turn off local flow
|
|
868 control for user coming over network on 4.2; in this case,
|
|
869 only t_stopc and t_startc really matter. */
|
|
870 #ifndef HAVE_TERMIO
|
|
871 #ifdef TIOCGETC
|
|
872 /* Note: if not using CBREAK mode, it makes no difference how we
|
|
873 set this */
|
|
874 tty.tchars = new_tchars;
|
|
875 tty.tchars.t_intrc = quit_char;
|
|
876 if (flow_control)
|
|
877 {
|
|
878 tty.tchars.t_startc = '\021';
|
|
879 tty.tchars.t_stopc = '\023';
|
|
880 }
|
|
881
|
|
882 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
|
|
883 #ifndef LPASS8
|
|
884 #define LPASS8 0
|
491
|
885 #endif
|
579
|
886
|
|
887 #ifdef BSD4_1
|
|
888 #define LNOFLSH 0100000
|
|
889 #endif
|
|
890
|
|
891 tty.lmode = LDECCTQ | LLITOUT | LPASS8 | LNOFLSH | old_tty.lmode;
|
|
892
|
|
893 #ifdef BSD4_1
|
|
894 lmode = tty.lmode;
|
|
895 #endif
|
|
896
|
|
897 #endif /* TIOCGETC */
|
|
898 #endif /* not HAVE_TERMIO */
|
|
899
|
|
900 #ifdef TIOCGLTC
|
|
901 tty.ltchars = new_ltchars;
|
|
902 #endif /* TIOCGLTC */
|
|
903
|
|
904 EMACS_SET_TTY (input_fd, &tty, 0);
|
491
|
905
|
|
906 /* This code added to insure that, if flow-control is not to be used,
|
|
907 we have an unlocked screen at the start. */
|
579
|
908
|
491
|
909 #ifdef TCXONC
|
|
910 if (!flow_control) ioctl (0, TCXONC, 1);
|
|
911 #endif
|
|
912 #ifndef APOLLO
|
|
913 #ifdef TIOCSTART
|
|
914 if (!flow_control) ioctl (0, TIOCSTART, 0);
|
|
915 #endif
|
|
916 #endif
|
|
917
|
|
918 #ifdef AIX
|
|
919 hft_init ();
|
|
920 #ifdef IBMR2AIX
|
|
921 {
|
|
922 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
|
|
923 to be only LF. This is the way that is done. */
|
|
924 struct termio tty;
|
|
925
|
|
926 if (ioctl (1, HFTGETID, &tty) != -1)
|
|
927 write (1, "\033[20l", 5);
|
|
928 }
|
|
929 #endif
|
|
930 #endif
|
|
931
|
|
932 #ifdef VMS
|
|
933 /* Appears to do nothing when in PASTHRU mode.
|
579
|
934 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
|
491
|
935 interrupt_signal, oob_chars, 0, 0, 0, 0);
|
|
936 */
|
|
937 queue_kbd_input (0);
|
|
938 #endif /* VMS */
|
|
939 }
|
|
940
|
|
941 #ifdef F_SETFL
|
|
942 #ifdef F_GETOWN /* F_SETFL does not imply existance of F_GETOWN */
|
|
943 if (interrupt_input)
|
|
944 {
|
|
945 old_fcntl_owner = fcntl (0, F_GETOWN, 0);
|
|
946 fcntl (0, F_SETOWN, getpid ());
|
|
947 init_sigio ();
|
|
948 }
|
|
949 #endif /* F_GETOWN */
|
|
950 #endif /* F_SETFL */
|
|
951
|
|
952 #ifdef BSD4_1
|
|
953 if (interrupt_input)
|
|
954 init_sigio ();
|
|
955 #endif
|
|
956
|
|
957 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
|
|
958 #undef _IOFBF
|
|
959 #endif
|
|
960 #ifdef _IOFBF
|
|
961 /* This symbol is defined on recent USG systems.
|
|
962 Someone says without this call USG won't really buffer the file
|
|
963 even with a call to setbuf. */
|
|
964 setvbuf (stdout, _sobuf, _IOFBF, sizeof _sobuf);
|
|
965 #else
|
|
966 setbuf (stdout, _sobuf);
|
|
967 #endif
|
|
968 set_terminal_modes ();
|
|
969 if (term_initted && no_redraw_on_reenter)
|
|
970 {
|
|
971 if (display_completed)
|
|
972 direct_output_forward_char (0);
|
|
973 }
|
|
974 else
|
|
975 {
|
|
976 screen_garbaged = 1;
|
|
977 #ifdef MULTI_SCREEN
|
|
978 if (SCREENP (Vterminal_screen))
|
|
979 SCREEN_GARBAGED_P (XSCREEN (Vterminal_screen)) = 1;
|
|
980 #endif
|
|
981 }
|
579
|
982
|
491
|
983 term_initted = 1;
|
|
984 }
|
|
985
|
|
986 /* Return nonzero if safe to use tabs in output.
|
|
987 At the time this is called, init_sys_modes has not been done yet. */
|
|
988
|
|
989 tabs_safe_p ()
|
|
990 {
|
579
|
991 struct emacs_tty tty;
|
|
992
|
|
993 EMACS_GET_TTY (input_fd, &tty);
|
|
994 return EMACS_TTY_TABS_OK (&tty);
|
491
|
995 }
|
|
996
|
|
997 /* Get terminal size from system.
|
|
998 Store number of lines into *heightp and width into *widthp.
|
|
999 If zero or a negative number is stored, the value is not valid. */
|
|
1000
|
|
1001 get_screen_size (widthp, heightp)
|
|
1002 int *widthp, *heightp;
|
|
1003 {
|
579
|
1004
|
|
1005 #ifdef TIOCGWINSZ
|
|
1006
|
|
1007 /* BSD-style. */
|
|
1008 struct winsize size;
|
|
1009
|
|
1010 if (ioctl (input_fd, TIOCGWINSZ, &size) == -1)
|
|
1011 *widthp = *heightp = 0;
|
|
1012 else
|
|
1013 {
|
|
1014 *widthp = size.ws_col;
|
|
1015 *heightp = size.ws_row;
|
|
1016 }
|
|
1017
|
|
1018 #else
|
491
|
1019 #ifdef TIOCGSIZE
|
579
|
1020
|
|
1021 /* SunOS - style. */
|
|
1022 struct ttysize size;
|
|
1023
|
|
1024 if (ioctl (input_fd, TIOCGSIZE, &size) == -1)
|
|
1025 *widthp = *heightp = 0;
|
|
1026 else
|
|
1027 {
|
|
1028 *widthp = size.ts_cols;
|
|
1029 *heightp = size.ts_lines;
|
|
1030 }
|
|
1031
|
|
1032 #else
|
491
|
1033 #ifdef VMS
|
579
|
1034
|
|
1035 struct sensemode tty;
|
|
1036
|
|
1037 SYS$QIOW (0, input_fd, IO$_SENSEMODE, &tty, 0, 0,
|
491
|
1038 &tty.class, 12, 0, 0, 0, 0);
|
|
1039 *widthp = tty.scr_wid;
|
|
1040 *heightp = tty.scr_len;
|
579
|
1041
|
491
|
1042 #else /* system doesn't know size */
|
579
|
1043
|
491
|
1044 *widthp = 0;
|
|
1045 *heightp = 0;
|
579
|
1046
|
|
1047 #endif /* not VMS */
|
|
1048 #endif /* not SunOS-style */
|
|
1049 #endif /* not BSD-style */
|
491
|
1050 }
|
579
|
1051
|
491
|
1052
|
579
|
1053 /* Prepare the terminal for exiting Emacs; move the cursor to the
|
|
1054 bottom of the screen, turn off interrupt-driven I/O, etc. */
|
491
|
1055 reset_sys_modes ()
|
|
1056 {
|
|
1057 if (noninteractive)
|
|
1058 {
|
|
1059 fflush (stdout);
|
|
1060 return;
|
|
1061 }
|
|
1062 if (!term_initted)
|
|
1063 return;
|
|
1064 if (read_socket_hook || !EQ (Vwindow_system, Qnil))
|
|
1065 return;
|
|
1066 cursor_to (SCREEN_HEIGHT (selected_screen) - 1, 0);
|
|
1067 clear_end_of_line (SCREEN_WIDTH (selected_screen));
|
|
1068 /* clear_end_of_line may move the cursor */
|
|
1069 cursor_to (SCREEN_HEIGHT (selected_screen) - 1, 0);
|
|
1070 #ifdef IBMR2AIX
|
|
1071 {
|
|
1072 /* HFT devices normally use ^J as a LF/CR. We forced it to
|
|
1073 do the LF only. Now, we need to reset it. */
|
|
1074 struct termio tty;
|
|
1075
|
|
1076 if (ioctl (1, HFTGETID, &tty) != -1)
|
|
1077 write (1, "\033[20h", 5);
|
|
1078 }
|
|
1079 #endif
|
|
1080
|
|
1081 reset_terminal_modes ();
|
|
1082 fflush (stdout);
|
|
1083 #ifdef BSD
|
|
1084 #ifndef BSD4_1
|
|
1085 /* Avoid possible loss of output when changing terminal modes. */
|
|
1086 fsync (fileno (stdout));
|
|
1087 #endif
|
|
1088 #endif
|
579
|
1089
|
491
|
1090 #ifdef F_SETFL
|
|
1091 #ifdef F_SETOWN /* F_SETFL does not imply existance of F_SETOWN */
|
|
1092 if (interrupt_input)
|
|
1093 {
|
|
1094 reset_sigio ();
|
|
1095 fcntl (0, F_SETOWN, old_fcntl_owner);
|
|
1096 }
|
|
1097 #endif /* F_SETOWN */
|
|
1098 #endif /* F_SETFL */
|
|
1099 #ifdef BSD4_1
|
|
1100 if (interrupt_input)
|
|
1101 reset_sigio ();
|
|
1102 #endif /* BSD4_1 */
|
579
|
1103
|
|
1104 while (EMACS_SET_TTY (input_fd, &old_tty, 0) < 0 && errno == EINTR)
|
|
1105 ;
|
491
|
1106
|
|
1107 #ifdef AIX
|
|
1108 hft_reset ();
|
|
1109 #endif
|
|
1110 }
|
|
1111
|
|
1112 #ifdef HAVE_PTYS
|
|
1113
|
|
1114 /* Set up the proper status flags for use of a pty. */
|
|
1115
|
|
1116 setup_pty (fd)
|
|
1117 int fd;
|
|
1118 {
|
|
1119 /* I'm told that TOICREMOTE does not mean control chars
|
|
1120 "can't be sent" but rather that they don't have
|
|
1121 input-editing or signaling effects.
|
|
1122 That should be good, because we have other ways
|
|
1123 to do those things in Emacs.
|
|
1124 However, telnet mode seems not to work on 4.2.
|
|
1125 So TIOCREMOTE is turned off now. */
|
|
1126
|
|
1127 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
|
|
1128 will hang. In particular, the "timeout" feature (which
|
|
1129 causes a read to return if there is no data available)
|
|
1130 does this. Also it is known that telnet mode will hang
|
|
1131 in such a way that Emacs must be stopped (perhaps this
|
|
1132 is the same problem).
|
|
1133
|
|
1134 If TIOCREMOTE is turned off, then there is a bug in
|
|
1135 hp-ux which sometimes loses data. Apparently the
|
|
1136 code which blocks the master process when the internal
|
|
1137 buffer fills up does not work. Other than this,
|
|
1138 though, everything else seems to work fine.
|
|
1139
|
|
1140 Since the latter lossage is more benign, we may as well
|
|
1141 lose that way. -- cph */
|
|
1142 #ifdef FIONBIO
|
|
1143 #ifdef SYSV_PTYS
|
|
1144 {
|
|
1145 int on = 1;
|
|
1146 ioctl (fd, FIONBIO, &on);
|
|
1147 }
|
|
1148 #endif
|
|
1149 #endif
|
|
1150 #ifdef IBMRTAIX
|
|
1151 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
|
|
1152 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
|
|
1153 /* cause EMACS not to die when it should, i.e., when its own controlling */
|
|
1154 /* tty goes away. I've complained to the AIX developers, and they may */
|
|
1155 /* change this behavior, but I'm not going to hold my breath. */
|
|
1156 signal (SIGHUP, SIG_IGN);
|
|
1157 #endif
|
|
1158 }
|
|
1159 #endif /* HAVE_PTYS */
|
|
1160
|
|
1161 #ifdef VMS
|
|
1162
|
|
1163 /* Assigning an input channel is done at the start of Emacs execution.
|
|
1164 This is called each time Emacs is resumed, also, but does nothing
|
|
1165 because input_chain is no longer zero. */
|
|
1166
|
|
1167 init_vms_input ()
|
|
1168 {
|
|
1169 int status;
|
|
1170
|
579
|
1171 if (input_fd == 0)
|
491
|
1172 {
|
579
|
1173 status = SYS$ASSIGN (&input_dsc, &input_fd, 0, 0);
|
491
|
1174 if (! (status & 1))
|
|
1175 LIB$STOP (status);
|
|
1176 }
|
|
1177 }
|
|
1178
|
|
1179 /* Deassigning the input channel is done before exiting. */
|
|
1180
|
|
1181 stop_vms_input ()
|
|
1182 {
|
579
|
1183 return SYS$DASSGN (input_fd);
|
491
|
1184 }
|
|
1185
|
|
1186 short input_buffer;
|
|
1187
|
|
1188 /* Request reading one character into the keyboard buffer.
|
|
1189 This is done as soon as the buffer becomes empty. */
|
|
1190
|
|
1191 queue_kbd_input ()
|
|
1192 {
|
|
1193 int status;
|
|
1194 waiting_for_ast = 0;
|
|
1195 stop_input = 0;
|
579
|
1196 status = SYS$QIO (0, input_fd, IO$_READVBLK,
|
491
|
1197 &input_iosb, kbd_input_ast, 1,
|
|
1198 &input_buffer, 1, 0, terminator_mask, 0, 0);
|
|
1199 }
|
|
1200
|
|
1201 int input_count;
|
|
1202
|
|
1203 /* Ast routine that is called when keyboard input comes in
|
|
1204 in accord with the SYS$QIO above. */
|
|
1205
|
|
1206 kbd_input_ast ()
|
|
1207 {
|
|
1208 register int c = -1;
|
|
1209 int old_errno = errno;
|
|
1210 extern int *input_available_clear_word;
|
|
1211
|
|
1212 if (waiting_for_ast)
|
|
1213 SYS$SETEF (input_ef);
|
|
1214 waiting_for_ast = 0;
|
|
1215 input_count++;
|
|
1216 #ifdef ASTDEBUG
|
|
1217 if (input_count == 25)
|
|
1218 exit (1);
|
|
1219 printf ("Ast # %d,", input_count);
|
|
1220 printf (" iosb = %x, %x, %x, %x",
|
|
1221 input_iosb.offset, input_iosb.status, input_iosb.termlen,
|
|
1222 input_iosb.term);
|
|
1223 #endif
|
|
1224 if (input_iosb.offset)
|
|
1225 {
|
|
1226 c = input_buffer;
|
|
1227 #ifdef ASTDEBUG
|
|
1228 printf (", char = 0%o", c);
|
|
1229 #endif
|
|
1230 }
|
|
1231 #ifdef ASTDEBUG
|
|
1232 printf ("\n");
|
|
1233 fflush (stdout);
|
|
1234 sleep (1);
|
|
1235 #endif
|
|
1236 if (! stop_input)
|
|
1237 queue_kbd_input ();
|
|
1238 if (c >= 0)
|
|
1239 {
|
|
1240 struct input_event e;
|
|
1241 e.kind = ascii_keystroke;
|
|
1242 XSET (buf[i].code, Lisp_Int, cbuf[i]);
|
|
1243 e.screen = selected_screen;
|
|
1244 kbd_buffer_store_event (&e);
|
|
1245 }
|
|
1246
|
|
1247 if (input_available_clear_word)
|
|
1248 *input_available_clear_word = 0;
|
|
1249 errno = old_errno;
|
|
1250 }
|
|
1251
|
|
1252 /* Wait until there is something in kbd_buffer. */
|
|
1253
|
|
1254 wait_for_kbd_input ()
|
|
1255 {
|
|
1256 extern int have_process_input, process_exited;
|
|
1257
|
|
1258 /* If already something, avoid doing system calls. */
|
|
1259 if (detect_input_pending ())
|
|
1260 {
|
|
1261 return;
|
|
1262 }
|
|
1263 /* Clear a flag, and tell ast routine above to set it. */
|
|
1264 SYS$CLREF (input_ef);
|
|
1265 waiting_for_ast = 1;
|
|
1266 /* Check for timing error: ast happened while we were doing that. */
|
|
1267 if (!detect_input_pending ())
|
|
1268 {
|
|
1269 /* No timing error: wait for flag to be set. */
|
|
1270 set_waiting_for_input (0);
|
|
1271 SYS$WFLOR (input_ef, input_eflist);
|
|
1272 clear_waiting_for_input (0);
|
|
1273 if (!detect_input_pending ())
|
|
1274 /* Check for subprocess input availability */
|
|
1275 {
|
|
1276 int dsp = have_process_input || process_exited;
|
|
1277
|
|
1278 SYS$CLREF (process_ef);
|
|
1279 if (have_process_input)
|
|
1280 process_command_input ();
|
|
1281 if (process_exited)
|
|
1282 process_exit ();
|
|
1283 if (dsp)
|
|
1284 {
|
|
1285 update_mode_lines++;
|
|
1286 redisplay_preserve_echo_area ();
|
|
1287 }
|
|
1288 }
|
|
1289 }
|
|
1290 waiting_for_ast = 0;
|
|
1291 }
|
|
1292
|
|
1293 /* Get rid of any pending QIO, when we are about to suspend
|
|
1294 or when we want to throw away pending input.
|
|
1295 We wait for a positive sign that the AST routine has run
|
|
1296 and therefore there is no I/O request queued when we return.
|
|
1297 SYS$SETAST is used to avoid a timing error. */
|
|
1298
|
|
1299 end_kbd_input ()
|
|
1300 {
|
|
1301 #ifdef ASTDEBUG
|
|
1302 printf ("At end_kbd_input.\n");
|
|
1303 fflush (stdout);
|
|
1304 sleep (1);
|
|
1305 #endif
|
|
1306 if (LIB$AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
|
|
1307 {
|
579
|
1308 SYS$CANCEL (input_fd);
|
491
|
1309 return;
|
|
1310 }
|
|
1311
|
|
1312 SYS$SETAST (0);
|
|
1313 /* Clear a flag, and tell ast routine above to set it. */
|
|
1314 SYS$CLREF (input_ef);
|
|
1315 waiting_for_ast = 1;
|
|
1316 stop_input = 1;
|
579
|
1317 SYS$CANCEL (input_fd);
|
491
|
1318 SYS$SETAST (1);
|
|
1319 SYS$WAITFR (input_ef);
|
|
1320 waiting_for_ast = 0;
|
|
1321 }
|
|
1322
|
|
1323 /* Wait for either input available or time interval expiry. */
|
|
1324
|
|
1325 input_wait_timeout (timeval)
|
|
1326 int timeval; /* Time to wait, in seconds */
|
|
1327 {
|
|
1328 int time [2];
|
|
1329 static int zero = 0;
|
|
1330 static int large = -10000000;
|
|
1331
|
|
1332 LIB$EMUL (&timeval, &large, &zero, time); /* Convert to VMS format */
|
|
1333
|
|
1334 /* If already something, avoid doing system calls. */
|
|
1335 if (detect_input_pending ())
|
|
1336 {
|
|
1337 return;
|
|
1338 }
|
|
1339 /* Clear a flag, and tell ast routine above to set it. */
|
|
1340 SYS$CLREF (input_ef);
|
|
1341 waiting_for_ast = 1;
|
|
1342 /* Check for timing error: ast happened while we were doing that. */
|
|
1343 if (!detect_input_pending ())
|
|
1344 {
|
|
1345 /* No timing error: wait for flag to be set. */
|
|
1346 SYS$CANTIM (1, 0);
|
|
1347 if (SYS$SETIMR (timer_ef, time, 0, 1) & 1) /* Set timer */
|
|
1348 SYS$WFLOR (timer_ef, timer_eflist); /* Wait for timer expiry or input */
|
|
1349 }
|
|
1350 waiting_for_ast = 0;
|
|
1351 }
|
|
1352
|
|
1353 /* The standard `sleep' routine works some other way
|
|
1354 and it stops working if you have ever quit out of it.
|
|
1355 This one continues to work. */
|
|
1356
|
|
1357 sys_sleep (timeval)
|
|
1358 int timeval;
|
|
1359 {
|
|
1360 int time [2];
|
|
1361 static int zero = 0;
|
|
1362 static int large = -10000000;
|
|
1363
|
|
1364 LIB$EMUL (&timeval, &large, &zero, time); /* Convert to VMS format */
|
|
1365
|
|
1366 SYS$CANTIM (1, 0);
|
|
1367 if (SYS$SETIMR (timer_ef, time, 0, 1) & 1) /* Set timer */
|
|
1368 SYS$WAITFR (timer_ef); /* Wait for timer expiry only */
|
|
1369 }
|
|
1370
|
|
1371 init_sigio ()
|
|
1372 {
|
|
1373 request_sigio ();
|
|
1374 }
|
|
1375
|
|
1376 reset_sigio ()
|
|
1377 {
|
|
1378 unrequest_sigio ();
|
|
1379 }
|
|
1380
|
|
1381 request_sigio ()
|
|
1382 {
|
|
1383 croak ("request sigio");
|
|
1384 }
|
|
1385
|
|
1386 unrequest_sigio ()
|
|
1387 {
|
|
1388 croak ("unrequest sigio");
|
|
1389 }
|
|
1390
|
|
1391 #endif /* VMS */
|
|
1392
|
|
1393 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
|
|
1394 #ifndef CANNOT_DUMP
|
|
1395 #define NEED_STARTS
|
|
1396 #endif
|
|
1397
|
|
1398 #ifndef SYSTEM_MALLOC
|
|
1399 #ifndef NEED_STARTS
|
|
1400 #define NEED_STARTS
|
|
1401 #endif
|
|
1402 #endif
|
|
1403
|
|
1404 #ifdef NEED_STARTS
|
|
1405 /* Some systems that cannot dump also cannot implement these. */
|
|
1406
|
|
1407 /*
|
|
1408 * Return the address of the start of the text segment prior to
|
|
1409 * doing an unexec. After unexec the return value is undefined.
|
|
1410 * See crt0.c for further explanation and _start.
|
|
1411 *
|
|
1412 */
|
|
1413
|
|
1414 #ifndef CANNOT_UNEXEC
|
|
1415 char *
|
|
1416 start_of_text ()
|
|
1417 {
|
|
1418 #ifdef TEXT_START
|
|
1419 return ((char *) TEXT_START);
|
|
1420 #else
|
|
1421 #ifdef GOULD
|
|
1422 extern csrt ();
|
|
1423 return ((char *) csrt);
|
|
1424 #else /* not GOULD */
|
|
1425 extern int _start ();
|
|
1426 return ((char *) _start);
|
|
1427 #endif /* GOULD */
|
|
1428 #endif /* TEXT_START */
|
|
1429 }
|
|
1430 #endif /* not CANNOT_UNEXEC */
|
|
1431
|
|
1432 /*
|
|
1433 * Return the address of the start of the data segment prior to
|
|
1434 * doing an unexec. After unexec the return value is undefined.
|
|
1435 * See crt0.c for further information and definition of data_start.
|
|
1436 *
|
|
1437 * Apparently, on BSD systems this is etext at startup. On
|
|
1438 * USG systems (swapping) this is highly mmu dependent and
|
|
1439 * is also dependent on whether or not the program is running
|
|
1440 * with shared text. Generally there is a (possibly large)
|
|
1441 * gap between end of text and start of data with shared text.
|
|
1442 *
|
|
1443 * On Uniplus+ systems with shared text, data starts at a
|
|
1444 * fixed address. Each port (from a given oem) is generally
|
|
1445 * different, and the specific value of the start of data can
|
|
1446 * be obtained via the UniPlus+ specific "uvar" system call,
|
|
1447 * however the method outlined in crt0.c seems to be more portable.
|
|
1448 *
|
|
1449 * Probably what will have to happen when a USG unexec is available,
|
|
1450 * at least on UniPlus, is temacs will have to be made unshared so
|
|
1451 * that text and data are contiguous. Then once loadup is complete,
|
|
1452 * unexec will produce a shared executable where the data can be
|
|
1453 * at the normal shared text boundry and the startofdata variable
|
|
1454 * will be patched by unexec to the correct value.
|
|
1455 *
|
|
1456 */
|
|
1457
|
|
1458 char *
|
|
1459 start_of_data ()
|
|
1460 {
|
|
1461 #ifdef DATA_START
|
|
1462 return ((char *) DATA_START);
|
|
1463 #else
|
|
1464 extern int data_start;
|
|
1465 return ((char *) &data_start);
|
|
1466 #endif
|
|
1467 }
|
|
1468 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
|
|
1469
|
|
1470 #ifndef CANNOT_DUMP
|
|
1471 /* Some systems that cannot dump also cannot implement these. */
|
|
1472
|
|
1473 /*
|
|
1474 * Return the address of the end of the text segment prior to
|
|
1475 * doing an unexec. After unexec the return value is undefined.
|
|
1476 */
|
|
1477
|
|
1478 char *
|
|
1479 end_of_text ()
|
|
1480 {
|
|
1481 #ifdef TEXT_END
|
|
1482 return ((char *) TEXT_END);
|
|
1483 #else
|
|
1484 extern int etext;
|
|
1485 return ((char *) &etext);
|
|
1486 #endif
|
|
1487 }
|
|
1488
|
|
1489 /*
|
|
1490 * Return the address of the end of the data segment prior to
|
|
1491 * doing an unexec. After unexec the return value is undefined.
|
|
1492 */
|
|
1493
|
|
1494 char *
|
|
1495 end_of_data ()
|
|
1496 {
|
|
1497 #ifdef DATA_END
|
|
1498 return ((char *) DATA_END);
|
|
1499 #else
|
|
1500 extern int edata;
|
|
1501 return ((char *) &edata);
|
|
1502 #endif
|
|
1503 }
|
|
1504
|
|
1505 #endif /* not CANNOT_DUMP */
|
|
1506
|
|
1507 /* Get_system_name returns as its value
|
|
1508 a string for the Lisp function system-name to return. */
|
|
1509
|
|
1510 #ifdef BSD4_1
|
|
1511 #include <whoami.h>
|
|
1512 #endif
|
|
1513
|
|
1514 #ifdef USG
|
|
1515 /* Can't have this within the function since `static' is #defined to nothing */
|
|
1516 static struct utsname get_system_name_name;
|
|
1517 #endif
|
|
1518
|
|
1519 char *
|
|
1520 get_system_name ()
|
|
1521 {
|
|
1522 #ifdef USG
|
|
1523 uname (&get_system_name_name);
|
|
1524 return (get_system_name_name.nodename);
|
|
1525 #else /* Not USG */
|
|
1526 #ifdef BSD4_1
|
|
1527 return sysname;
|
|
1528 #else /* not USG, not 4.1 */
|
|
1529 static char system_name_saved[32];
|
|
1530 #ifdef VMS
|
|
1531 char *sp;
|
|
1532 if ((sp = egetenv ("SYS$NODE")) == 0)
|
|
1533 sp = "vax-vms";
|
|
1534 else
|
|
1535 {
|
|
1536 char *end;
|
|
1537
|
|
1538 if ((end = index (sp, ':')) != 0)
|
|
1539 *end = '\0';
|
|
1540 }
|
|
1541 strcpy (system_name_saved, sp);
|
|
1542 #else /* not VMS */
|
|
1543 gethostname (system_name_saved, sizeof (system_name_saved));
|
|
1544 #endif /* not VMS */
|
|
1545 return system_name_saved;
|
|
1546 #endif /* not USG, not 4.1 */
|
|
1547 #endif /* not USG */
|
|
1548 }
|
|
1549
|
|
1550 #ifndef VMS
|
|
1551 #ifndef HAVE_SELECT
|
|
1552
|
|
1553 #ifdef HAVE_X_WINDOWS
|
|
1554 /* Cause explanatory error message at compile time,
|
|
1555 since the select emulation is not good enough for X. */
|
|
1556 int *x = &x_windows_lose_if_no_select_system_call;
|
|
1557 #endif
|
|
1558
|
|
1559 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
|
|
1560 * Only checks read descriptors.
|
|
1561 */
|
|
1562 /* How long to wait between checking fds in select */
|
|
1563 #define SELECT_PAUSE 1
|
|
1564 int select_alarmed;
|
|
1565
|
|
1566 /* For longjmp'ing back to read_input_waiting. */
|
|
1567
|
|
1568 jmp_buf read_alarm_throw;
|
|
1569
|
|
1570 /* Nonzero if the alarm signal should throw back to read_input_waiting.
|
|
1571 The read_socket_hook function sets this to 1 while it is waiting. */
|
|
1572
|
|
1573 int read_alarm_should_throw;
|
|
1574
|
|
1575 SIGTYPE
|
|
1576 select_alarm ()
|
|
1577 {
|
|
1578 select_alarmed = 1;
|
|
1579 #ifdef BSD4_1
|
|
1580 sigrelse (SIGALRM);
|
|
1581 #else /* not BSD4_1 */
|
|
1582 signal (SIGALRM, SIG_IGN);
|
|
1583 #endif /* not BSD4_1 */
|
|
1584 if (read_alarm_should_throw)
|
|
1585 longjmp (read_alarm_throw, 1);
|
|
1586 }
|
|
1587
|
|
1588 /* Only rfds are checked. */
|
|
1589 int
|
|
1590 select (nfds, rfds, wfds, efds, timeout)
|
|
1591 int nfds;
|
|
1592 int *rfds, *wfds, *efds, *timeout;
|
|
1593 {
|
|
1594 int ravail = 0, orfds = 0, old_alarm;
|
|
1595 int timeoutval = timeout ? *timeout : 100000;
|
|
1596 int *local_timeout = &timeoutval;
|
|
1597 extern int proc_buffered_char[];
|
|
1598 #ifndef subprocesses
|
|
1599 int process_tick = 0, update_tick = 0;
|
|
1600 #else
|
|
1601 extern int process_tick, update_tick;
|
|
1602 #endif
|
|
1603 SIGTYPE (*old_trap) ();
|
|
1604 unsigned char buf;
|
|
1605
|
|
1606 if (rfds)
|
|
1607 {
|
|
1608 orfds = *rfds;
|
|
1609 *rfds = 0;
|
|
1610 }
|
|
1611 if (wfds)
|
|
1612 *wfds = 0;
|
|
1613 if (efds)
|
|
1614 *efds = 0;
|
|
1615
|
|
1616 /* If we are looking only for the terminal, with no timeout,
|
|
1617 just read it and wait -- that's more efficient. */
|
|
1618 if (orfds == 1 && *local_timeout == 100000 && process_tick == update_tick)
|
|
1619 {
|
|
1620 if (! detect_input_pending ())
|
|
1621 read_input_waiting ();
|
|
1622 *rfds = 1;
|
|
1623 return 1;
|
|
1624 }
|
|
1625
|
|
1626 /* Once a second, till the timer expires, check all the flagged read
|
|
1627 * descriptors to see if any input is available. If there is some then
|
|
1628 * set the corresponding bit in the return copy of rfds.
|
|
1629 */
|
|
1630 while (1)
|
|
1631 {
|
|
1632 register int to_check, bit, fd;
|
|
1633
|
|
1634 if (rfds)
|
|
1635 {
|
|
1636 for (to_check = nfds, bit = 1, fd = 0; --to_check >= 0; bit <<= 1, fd++)
|
|
1637 {
|
|
1638 if (orfds & bit)
|
|
1639 {
|
|
1640 int avail = 0, status = 0;
|
|
1641
|
|
1642 if (bit == 1)
|
|
1643 avail = detect_input_pending (); /* Special keyboard handler */
|
|
1644 else
|
|
1645 {
|
|
1646 #ifdef FIONREAD
|
|
1647 status = ioctl (fd, FIONREAD, &avail);
|
|
1648 #else /* no FIONREAD */
|
|
1649 /* Hoping it will return -1 if nothing available
|
|
1650 or 0 if all 0 chars requested are read. */
|
|
1651 if (proc_buffered_char[fd] >= 0)
|
|
1652 avail = 1;
|
|
1653 else
|
|
1654 {
|
|
1655 avail = read (fd, &buf, 1);
|
|
1656 if (avail > 0)
|
|
1657 proc_buffered_char[fd] = buf;
|
|
1658 }
|
|
1659 #endif /* no FIONREAD */
|
|
1660 }
|
|
1661 if (status >= 0 && avail > 0)
|
|
1662 {
|
|
1663 (*rfds) |= bit;
|
|
1664 ravail++;
|
|
1665 }
|
|
1666 }
|
|
1667 }
|
|
1668 }
|
|
1669 if (*local_timeout == 0 || ravail != 0 || process_tick != update_tick)
|
|
1670 break;
|
|
1671 old_alarm = alarm (0);
|
|
1672 old_trap = (int (*)()) signal (SIGALRM, select_alarm);
|
|
1673 select_alarmed = 0;
|
|
1674 alarm (SELECT_PAUSE);
|
|
1675 /* Wait for a SIGALRM (or maybe a SIGTINT) */
|
|
1676 while (select_alarmed == 0 && *local_timeout != 0
|
|
1677 && process_tick == update_tick)
|
|
1678 {
|
|
1679 /* If we are interested in terminal input,
|
|
1680 wait by reading the terminal.
|
|
1681 That makes instant wakeup for terminal input at least. */
|
|
1682 if (orfds & 1)
|
|
1683 {
|
|
1684 read_input_waiting ();
|
|
1685 if (detect_input_pending ())
|
|
1686 select_alarmed = 1;
|
|
1687 }
|
|
1688 else
|
|
1689 pause ();
|
|
1690 }
|
|
1691 (*local_timeout) -= SELECT_PAUSE;
|
|
1692 /* Reset the old alarm if there was one */
|
|
1693 alarm (0);
|
|
1694 signal (SIGALRM, old_trap);
|
|
1695 if (old_alarm != 0)
|
|
1696 {
|
|
1697 /* Reset or forge an interrupt for the original handler. */
|
|
1698 old_alarm -= SELECT_PAUSE;
|
|
1699 if (old_alarm <= 0)
|
|
1700 kill (getpid (), SIGALRM); /* Fake an alarm with the orig' handler */
|
|
1701 else
|
|
1702 alarm (old_alarm);
|
|
1703 }
|
|
1704 if (*local_timeout == 0) /* Stop on timer being cleared */
|
|
1705 break;
|
|
1706 }
|
|
1707 return ravail;
|
|
1708 }
|
|
1709
|
|
1710 /* Read keyboard input into the standard buffer,
|
|
1711 waiting for at least one character. */
|
|
1712
|
|
1713 /* Make all keyboard buffers much bigger when using X windows. */
|
|
1714 #ifdef HAVE_X_WINDOWS
|
|
1715 #define BUFFER_SIZE_FACTOR 16
|
|
1716 #else
|
|
1717 #define BUFFER_SIZE_FACTOR 1
|
|
1718 #endif
|
|
1719
|
|
1720 read_input_waiting ()
|
|
1721 {
|
|
1722 char buf[256 * BUFFER_SIZE_FACTOR];
|
|
1723 struct input_event e;
|
|
1724 int nread;
|
|
1725
|
|
1726 if (read_socket_hook)
|
|
1727 {
|
|
1728 read_alarm_should_throw = 0;
|
|
1729 if (! setjmp (read_alarm_throw))
|
|
1730 nread = (*read_socket_hook) (0, buf, 256 * BUFFER_SIZE_FACTOR, 1, 0);
|
|
1731 else
|
|
1732 nread = -1;
|
|
1733 }
|
|
1734 else
|
|
1735 nread = read (fileno (stdin), buf, 1);
|
|
1736
|
|
1737 /* Scan the chars for C-g and store them in kbd_buffer. */
|
|
1738 e.kind = ascii_keystroke;
|
|
1739 e.screen = selected_screen;
|
|
1740 for (i = 0; i < nread; i++)
|
|
1741 {
|
|
1742 XSET (e.code, Lisp_Int, buf[i]);
|
|
1743 kbd_buffer_store_event (&e);
|
|
1744 /* Don't look at input that follows a C-g too closely.
|
|
1745 This reduces lossage due to autorepeat on C-g. */
|
|
1746 if (buf[i] == Ctl ('G'))
|
|
1747 break;
|
|
1748 }
|
|
1749 }
|
|
1750
|
|
1751 #endif /* not HAVE_SELECT */
|
|
1752 #endif /* not VMS */
|
|
1753
|
|
1754 #ifdef BSD4_1
|
|
1755 /* VARARGS */
|
|
1756 setpriority ()
|
|
1757 {
|
|
1758 return 0;
|
|
1759 }
|
|
1760
|
|
1761 /*
|
|
1762 * Partially emulate 4.2 open call.
|
|
1763 * open is defined as this in 4.1.
|
|
1764 *
|
|
1765 * - added by Michael Bloom @ Citicorp/TTI
|
|
1766 *
|
|
1767 */
|
|
1768
|
|
1769 int
|
|
1770 sys_open (path, oflag, mode)
|
|
1771 char *path;
|
|
1772 int oflag, mode;
|
|
1773 {
|
|
1774 if (oflag & O_CREAT)
|
|
1775 return creat (path, mode);
|
|
1776 else
|
|
1777 return open (path, oflag);
|
|
1778 }
|
|
1779
|
|
1780 init_sigio ()
|
|
1781 {
|
|
1782 if (noninteractive)
|
|
1783 return;
|
|
1784 lmode = LINTRUP | lmode;
|
|
1785 ioctl (0, TIOCLSET, &lmode);
|
|
1786 }
|
|
1787
|
|
1788 reset_sigio ()
|
|
1789 {
|
|
1790 if (noninteractive)
|
|
1791 return;
|
|
1792 lmode = ~LINTRUP & lmode;
|
|
1793 ioctl (0, TIOCLSET, &lmode);
|
|
1794 }
|
|
1795
|
|
1796 request_sigio ()
|
|
1797 {
|
|
1798 sigrelse (SIGTINT);
|
|
1799
|
|
1800 interrupts_deferred = 0;
|
|
1801 }
|
|
1802
|
|
1803 unrequest_sigio ()
|
|
1804 {
|
|
1805 sighold (SIGTINT);
|
|
1806
|
|
1807 interrupts_deferred = 1;
|
|
1808 }
|
|
1809
|
|
1810 /* still inside #ifdef BSD4_1 */
|
|
1811 #ifdef subprocesses
|
|
1812
|
|
1813 int sigheld; /* Mask of held signals */
|
|
1814
|
|
1815 sigholdx (signum)
|
|
1816 int signum;
|
|
1817 {
|
|
1818 sigheld |= sigbit (signum);
|
|
1819 sighold (signum);
|
|
1820 }
|
|
1821
|
|
1822 sigisheld (signum)
|
|
1823 int signum;
|
|
1824 {
|
|
1825 sigheld |= sigbit (signum);
|
|
1826 }
|
|
1827
|
|
1828 sigunhold (signum)
|
|
1829 int signum;
|
|
1830 {
|
|
1831 sigheld &= ~sigbit (signum);
|
|
1832 sigrelse (signum);
|
|
1833 }
|
|
1834
|
|
1835 sigfree () /* Free all held signals */
|
|
1836 {
|
|
1837 int i;
|
|
1838 for (i = 0; i < NSIG; i++)
|
|
1839 if (sigheld & sigbit (i))
|
|
1840 sigrelse (i);
|
|
1841 sigheld = 0;
|
|
1842 }
|
|
1843
|
|
1844 sigbit (i)
|
|
1845 {
|
|
1846 return 1 << (i - 1);
|
|
1847 }
|
|
1848 #endif /* subprocesses */
|
|
1849 #endif /* BSD4_1 */
|
|
1850
|
|
1851 /* POSIX signals support - DJB */
|
|
1852 /* Anyone with POSIX signals should have ANSI C declarations */
|
|
1853
|
|
1854 #ifdef POSIX_SIGNALS
|
|
1855
|
|
1856 sigset_t old_mask, empty_mask, full_mask, temp_mask;
|
|
1857 static struct sigaction new_action, old_action;
|
|
1858
|
|
1859 init_signals ()
|
|
1860 {
|
|
1861 #ifdef POSIX_SIGNALS
|
|
1862 sigemptyset (&signal_empty_mask);
|
|
1863 sigfillset (&signal_full_mask);
|
|
1864 #endif
|
|
1865 }
|
|
1866
|
|
1867 int (*signal_handler_t) ();
|
|
1868
|
|
1869 signal_handler_t
|
|
1870 sys_signal (int signal_number, signal_handler_t action)
|
|
1871 {
|
|
1872 #ifdef DGUX
|
|
1873 /* This gets us restartable system calls for efficiency.
|
|
1874 The "else" code will works as well. */
|
|
1875 return (berk_signal (signal_number, action));
|
|
1876 #else
|
|
1877 sigemptyset (&new_action.sa_mask);
|
|
1878 new_action.sa_handler = action;
|
|
1879 new_action.sa_flags = NULL;
|
|
1880 new_action (signal_number, &new_action, &old_action);
|
|
1881 return (old_action.sa_handler);
|
|
1882 #endif /* DGUX */
|
|
1883 }
|
|
1884
|
|
1885 int
|
|
1886 sys_sigpause (sigset_t new_mask)
|
|
1887 {
|
|
1888 /* pause emulating berk sigpause... */
|
|
1889 sigsuspend (&new_mask);
|
|
1890 return (EINTR);
|
|
1891 }
|
|
1892
|
|
1893 /* I'd like to have these guys return pointers to the mask storage in here,
|
|
1894 but there'd be trouble if the code was saving multiple masks. I'll be
|
|
1895 safe and pass the structure. It normally won't be more than 2 bytes
|
|
1896 anyhow. - DJB */
|
|
1897
|
|
1898 sigset_t
|
|
1899 sys_sigblock (sigset_t new_mask)
|
|
1900 {
|
|
1901 sigset_t old_mask;
|
|
1902 sigprocmask (SIG_BLOCK, &new_mask, &old_mask);
|
|
1903 return (old_mask);
|
|
1904 }
|
|
1905
|
|
1906 sigset_t
|
|
1907 sys_sigunblock (sigset_t new_mask)
|
|
1908 {
|
|
1909 sigset_t old_mask;
|
|
1910 sigprocmask (SIG_UNBLOCK, &new_mask, &old_mask);
|
|
1911 return (old_mask);
|
|
1912 }
|
|
1913
|
|
1914 sigset_t
|
|
1915 sys_sigsetmask (sigset_t new_mask)
|
|
1916 {
|
|
1917 sigset_t old_mask;
|
|
1918 sigprocmask (SIG_SETMASK, &new_mask, &old_mask);
|
|
1919 return (old_mask);
|
|
1920 }
|
|
1921
|
|
1922 #endif /* POSIX_SIGNALS */
|
|
1923
|
|
1924 #ifndef BSTRING
|
|
1925
|
|
1926 void
|
|
1927 bzero (b, length)
|
|
1928 register char *b;
|
|
1929 register int length;
|
|
1930 {
|
|
1931 #ifdef VMS
|
|
1932 short zero = 0;
|
|
1933 long max_str = 65535;
|
|
1934
|
|
1935 while (length > max_str) {
|
|
1936 (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b);
|
|
1937 length -= max_str;
|
|
1938 b += max_str;
|
|
1939 }
|
|
1940 max_str = length;
|
|
1941 (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b);
|
|
1942 #else
|
|
1943 while (length-- > 0)
|
|
1944 *b++ = 0;
|
|
1945 #endif /* not VMS */
|
|
1946 }
|
|
1947
|
|
1948 /* Saying `void' requires a declaration, above, where bcopy is used
|
|
1949 and that declaration causes pain for systems where bcopy is a macro. */
|
|
1950 bcopy (b1, b2, length)
|
|
1951 register char *b1;
|
|
1952 register char *b2;
|
|
1953 register int length;
|
|
1954 {
|
|
1955 #ifdef VMS
|
|
1956 long max_str = 65535;
|
|
1957
|
|
1958 while (length > max_str) {
|
|
1959 (void) LIB$MOVC3 (&max_str, b1, b2);
|
|
1960 length -= max_str;
|
|
1961 b1 += max_str;
|
|
1962 b2 += max_str;
|
|
1963 }
|
|
1964 max_str = length;
|
|
1965 (void) LIB$MOVC3 (&length, b1, b2);
|
|
1966 #else
|
|
1967 while (length-- > 0)
|
|
1968 *b2++ = *b1++;
|
|
1969 #endif /* not VMS */
|
|
1970 }
|
|
1971
|
|
1972 int
|
|
1973 bcmp (b1, b2, length) /* This could be a macro! */
|
|
1974 register char *b1;
|
|
1975 register char *b2;
|
|
1976 register int length;
|
|
1977 {
|
|
1978 #ifdef VMS
|
|
1979 struct dsc$descriptor_s src1 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b1};
|
|
1980 struct dsc$descriptor_s src2 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b2};
|
|
1981
|
|
1982 return STR$COMPARE (&src1, &src2);
|
|
1983 #else
|
|
1984 while (length-- > 0)
|
|
1985 if (*b1++ != *b2++)
|
|
1986 return 1;
|
|
1987
|
|
1988 return 0;
|
|
1989 #endif /* not VMS */
|
|
1990 }
|
|
1991 #endif /* not BSTRING */
|
|
1992
|
|
1993 #ifdef USG
|
|
1994 /*
|
|
1995 * The BSD random returns numbers in the range of
|
|
1996 * 0 to 2e31 - 1. The USG rand returns numbers in the
|
|
1997 * range of 0 to 2e15 - 1. This is probably not significant
|
|
1998 * in this usage.
|
|
1999 */
|
|
2000
|
|
2001 long
|
|
2002 random ()
|
|
2003 {
|
|
2004 /* Arrange to return a range centered on zero. */
|
|
2005 return (rand () << 15) + rand () - (1 << 29);
|
|
2006 }
|
|
2007
|
|
2008 srandom (arg)
|
|
2009 int arg;
|
|
2010 {
|
|
2011 srand (arg);
|
|
2012 }
|
|
2013
|
|
2014 #endif /* USG */
|
|
2015
|
|
2016 #ifdef BSD4_1
|
|
2017 long random ()
|
|
2018 {
|
|
2019 /* Arrange to return a range centered on zero. */
|
|
2020 return (rand () << 15) + rand () - (1 << 29);
|
|
2021 }
|
|
2022
|
|
2023 srandom (arg)
|
|
2024 int arg;
|
|
2025 {
|
|
2026 srand (arg);
|
|
2027 }
|
|
2028 #endif /* BSD4_1 */
|
|
2029
|
|
2030 #ifdef WRONG_NAME_INSQUE
|
|
2031
|
|
2032 insque (q,p)
|
|
2033 caddr_t q,p;
|
|
2034 {
|
|
2035 _insque (q,p);
|
|
2036 }
|
|
2037
|
|
2038 #endif
|
|
2039
|
|
2040 #ifdef VMS
|
|
2041
|
|
2042 #ifdef getenv
|
|
2043 /* If any place else asks for the TERM variable,
|
|
2044 allow it to be overridden with the EMACS_TERM variable
|
|
2045 before attempting to translate the logical name TERM. As a last
|
|
2046 resort, ask for VAX C's special idea of the TERM variable. */
|
|
2047 #undef getenv
|
|
2048 char *
|
|
2049 sys_getenv (name)
|
|
2050 char *name;
|
|
2051 {
|
|
2052 register char *val;
|
|
2053 static char buf[256];
|
|
2054 static struct dsc$descriptor_s equiv
|
|
2055 = {sizeof (buf), DSC$K_DTYPE_T, DSC$K_CLASS_S, buf};
|
|
2056 static struct dsc$descriptor_s d_name
|
|
2057 = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};
|
|
2058 short eqlen;
|
|
2059
|
|
2060 if (!strcmp (name, "TERM"))
|
|
2061 {
|
|
2062 val = (char *) getenv ("EMACS_TERM");
|
|
2063 if (val)
|
|
2064 return val;
|
|
2065 }
|
|
2066
|
|
2067 d_name.dsc$w_length = strlen (name);
|
|
2068 d_name.dsc$a_pointer = name;
|
|
2069 if (lib$sys_trnlog (&d_name, &eqlen, &equiv) == 1)
|
|
2070 {
|
|
2071 char *str = (char *) xmalloc (eqlen + 1);
|
|
2072 bcopy (buf, str, eqlen);
|
|
2073 str[eqlen] = '\0';
|
|
2074 /* This is a storage leak, but a pain to fix. With luck,
|
|
2075 no one will ever notice. */
|
|
2076 return str;
|
|
2077 }
|
|
2078 return (char *) getenv (name);
|
|
2079 }
|
|
2080 #endif /* getenv */
|
|
2081
|
|
2082 #ifdef abort
|
|
2083 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
|
|
2084 to force a call on the debugger from within the image. */
|
|
2085 #undef abort
|
|
2086 sys_abort ()
|
|
2087 {
|
|
2088 reset_sys_modes ();
|
|
2089 LIB$SIGNAL (SS$_DEBUG);
|
|
2090 }
|
|
2091 #endif /* abort */
|
|
2092 #endif /* VMS */
|
|
2093
|
|
2094 #ifdef VMS
|
|
2095 #ifdef LINK_CRTL_SHARE
|
|
2096 #ifdef SHAREABLE_LIB_BUG
|
|
2097 /* Variables declared noshare and initialized in shareable libraries
|
|
2098 cannot be shared. The VMS linker incorrectly forces you to use a private
|
|
2099 version which is uninitialized... If not for this "feature", we
|
|
2100 could use the C library definition of sys_nerr and sys_errlist. */
|
|
2101 int sys_nerr = 35;
|
|
2102 char *sys_errlist[] =
|
|
2103 {
|
|
2104 "error 0",
|
|
2105 "not owner",
|
|
2106 "no such file or directory",
|
|
2107 "no such process",
|
|
2108 "interrupted system call",
|
|
2109 "i/o error",
|
|
2110 "no such device or address",
|
|
2111 "argument list too long",
|
|
2112 "exec format error",
|
|
2113 "bad file number",
|
|
2114 "no child process",
|
|
2115 "no more processes",
|
|
2116 "not enough memory",
|
|
2117 "permission denied",
|
|
2118 "bad address",
|
|
2119 "block device required",
|
|
2120 "mount devices busy",
|
|
2121 "file exists",
|
|
2122 "cross-device link",
|
|
2123 "no such device",
|
|
2124 "not a directory",
|
|
2125 "is a directory",
|
|
2126 "invalid argument",
|
|
2127 "file table overflow",
|
|
2128 "too many open files",
|
|
2129 "not a typewriter",
|
|
2130 "text file busy",
|
|
2131 "file too big",
|
|
2132 "no space left on device",
|
|
2133 "illegal seek",
|
|
2134 "read-only file system",
|
|
2135 "too many links",
|
|
2136 "broken pipe",
|
|
2137 "math argument",
|
|
2138 "result too large",
|
|
2139 "I/O stream empty",
|
|
2140 "vax/vms specific error code nontranslatable error"
|
|
2141 };
|
|
2142 #endif /* SHAREABLE_LIB_BUG */
|
|
2143 #endif /* LINK_CRTL_SHARE */
|
|
2144 #endif /* VMS */
|
|
2145
|
|
2146 #ifdef INTERRUPTIBLE_OPEN
|
|
2147
|
|
2148 int
|
|
2149 /* VARARGS 2 */
|
|
2150 sys_open (path, oflag, mode)
|
|
2151 char *path;
|
|
2152 int oflag, mode;
|
|
2153 {
|
|
2154 register int rtnval;
|
|
2155
|
|
2156 while ((rtnval = open (path, oflag, mode)) == -1
|
|
2157 && (errno == EINTR));
|
|
2158 return (rtnval);
|
|
2159 }
|
|
2160
|
|
2161 #endif /* INTERRUPTIBLE_OPEN */
|
|
2162
|
|
2163 #ifdef INTERRUPTIBLE_CLOSE
|
|
2164
|
|
2165 sys_close (fd)
|
|
2166 int fd;
|
|
2167 {
|
|
2168 register int rtnval;
|
|
2169
|
|
2170 while ((rtnval = close (fd)) == -1
|
|
2171 && (errno == EINTR));
|
|
2172 return rtnval;
|
|
2173 }
|
|
2174
|
|
2175 #endif /* INTERRUPTIBLE_CLOSE */
|
|
2176
|
|
2177 #ifdef INTERRUPTIBLE_IO
|
|
2178
|
|
2179 int
|
|
2180 sys_read (fildes, buf, nbyte)
|
|
2181 int fildes;
|
|
2182 char *buf;
|
|
2183 unsigned int nbyte;
|
|
2184 {
|
|
2185 register int rtnval;
|
|
2186
|
|
2187 while ((rtnval = read (fildes, buf, nbyte)) == -1
|
|
2188 && (errno == EINTR));
|
|
2189 return (rtnval);
|
|
2190 }
|
|
2191
|
|
2192 int
|
|
2193 sys_write (fildes, buf, nbyte)
|
|
2194 int fildes;
|
|
2195 char *buf;
|
|
2196 unsigned int nbyte;
|
|
2197 {
|
|
2198 register int rtnval;
|
|
2199
|
|
2200 while ((rtnval = write (fildes, buf, nbyte)) == -1
|
|
2201 && (errno == EINTR));
|
|
2202 return (rtnval);
|
|
2203 }
|
|
2204
|
|
2205 #endif /* INTERRUPTIBLE_IO */
|
|
2206
|
|
2207 #ifdef USG
|
|
2208 /*
|
|
2209 * All of the following are for USG.
|
|
2210 *
|
|
2211 * On USG systems the system calls are INTERRUPTIBLE by signals
|
|
2212 * that the user program has elected to catch. Thus the system call
|
|
2213 * must be retried in these cases. To handle this without massive
|
|
2214 * changes in the source code, we remap the standard system call names
|
|
2215 * to names for our own functions in sysdep.c that do the system call
|
|
2216 * with retries. Actually, for portability reasons, it is good
|
|
2217 * programming practice, as this example shows, to limit all actual
|
|
2218 * system calls to a single occurance in the source. Sure, this
|
|
2219 * adds an extra level of function call overhead but it is almost
|
|
2220 * always negligible. Fred Fish, Unisoft Systems Inc.
|
|
2221 */
|
|
2222
|
|
2223 char *sys_siglist[NSIG + 1] =
|
|
2224 {
|
|
2225 #ifdef AIX
|
|
2226 /* AIX has changed the signals a bit */
|
|
2227 "bogus signal", /* 0 */
|
|
2228 "hangup", /* 1 SIGHUP */
|
|
2229 "interrupt", /* 2 SIGINT */
|
|
2230 "quit", /* 3 SIGQUIT */
|
|
2231 "illegal instruction", /* 4 SIGILL */
|
|
2232 "trace trap", /* 5 SIGTRAP */
|
|
2233 "IOT instruction", /* 6 SIGIOT */
|
|
2234 "crash likely", /* 7 SIGDANGER */
|
|
2235 "floating point exception", /* 8 SIGFPE */
|
|
2236 "kill", /* 9 SIGKILL */
|
|
2237 "bus error", /* 10 SIGBUS */
|
|
2238 "segmentation violation", /* 11 SIGSEGV */
|
|
2239 "bad argument to system call", /* 12 SIGSYS */
|
|
2240 "write on a pipe with no one to read it", /* 13 SIGPIPE */
|
|
2241 "alarm clock", /* 14 SIGALRM */
|
|
2242 "software termination signum", /* 15 SIGTERM */
|
|
2243 "user defined signal 1", /* 16 SIGUSR1 */
|
|
2244 "user defined signal 2", /* 17 SIGUSR2 */
|
|
2245 "death of a child", /* 18 SIGCLD */
|
|
2246 "power-fail restart", /* 19 SIGPWR */
|
|
2247 "bogus signal", /* 20 */
|
|
2248 "bogus signal", /* 21 */
|
|
2249 "bogus signal", /* 22 */
|
|
2250 "bogus signal", /* 23 */
|
|
2251 "bogus signal", /* 24 */
|
|
2252 "LAN I/O interrupt", /* 25 SIGAIO */
|
|
2253 "PTY I/O interrupt", /* 26 SIGPTY */
|
|
2254 "I/O intervention required", /* 27 SIGIOINT */
|
|
2255 "HFT grant", /* 28 SIGGRANT */
|
|
2256 "HFT retract", /* 29 SIGRETRACT */
|
|
2257 "HFT sound done", /* 30 SIGSOUND */
|
|
2258 "HFT input ready", /* 31 SIGMSG */
|
|
2259 #else /* not AIX */
|
|
2260 "bogus signal", /* 0 */
|
|
2261 "hangup", /* 1 SIGHUP */
|
|
2262 "interrupt", /* 2 SIGINT */
|
|
2263 "quit", /* 3 SIGQUIT */
|
|
2264 "illegal instruction", /* 4 SIGILL */
|
|
2265 "trace trap", /* 5 SIGTRAP */
|
|
2266 "IOT instruction", /* 6 SIGIOT */
|
|
2267 "EMT instruction", /* 7 SIGEMT */
|
|
2268 "floating point exception", /* 8 SIGFPE */
|
|
2269 "kill", /* 9 SIGKILL */
|
|
2270 "bus error", /* 10 SIGBUS */
|
|
2271 "segmentation violation", /* 11 SIGSEGV */
|
|
2272 "bad argument to system call", /* 12 SIGSYS */
|
|
2273 "write on a pipe with no one to read it", /* 13 SIGPIPE */
|
|
2274 "alarm clock", /* 14 SIGALRM */
|
|
2275 "software termination signum", /* 15 SIGTERM */
|
|
2276 "user defined signal 1", /* 16 SIGUSR1 */
|
|
2277 "user defined signal 2", /* 17 SIGUSR2 */
|
|
2278 "death of a child", /* 18 SIGCLD */
|
|
2279 "power-fail restart", /* 19 SIGPWR */
|
|
2280 #endif /* not AIX */
|
|
2281 0
|
|
2282 };
|
|
2283
|
|
2284 /*
|
|
2285 * Warning, this function may not duplicate 4.2 action properly
|
|
2286 * under error conditions.
|
|
2287 */
|
|
2288
|
|
2289 #ifndef MAXPATHLEN
|
|
2290 /* In 4.1, param.h fails to define this. */
|
|
2291 #define MAXPATHLEN 1024
|
|
2292 #endif
|
|
2293
|
|
2294 #ifndef HAVE_GETWD
|
|
2295
|
|
2296 char *
|
|
2297 getwd (pathname)
|
|
2298 char *pathname;
|
|
2299 {
|
|
2300 char *npath, *spath;
|
|
2301 extern char *getcwd ();
|
|
2302
|
|
2303 spath = npath = getcwd ((char *) 0, MAXPATHLEN);
|
|
2304 /* On Altos 3068, getcwd can return @hostname/dir, so discard
|
|
2305 up to first slash. Should be harmless on other systems. */
|
|
2306 while (*npath && *npath != '/')
|
|
2307 npath++;
|
|
2308 strcpy (pathname, npath);
|
|
2309 free (spath); /* getcwd uses malloc */
|
|
2310 return pathname;
|
|
2311 }
|
|
2312
|
|
2313 #endif /* HAVE_GETWD */
|
|
2314
|
|
2315 /*
|
|
2316 * Emulate rename using unlink/link. Note that this is
|
|
2317 * only partially correct. Also, doesn't enforce restriction
|
|
2318 * that files be of same type (regular->regular, dir->dir, etc).
|
|
2319 */
|
|
2320
|
621
|
2321 #ifndef HAVE_RENAME
|
|
2322
|
491
|
2323 rename (from, to)
|
|
2324 char *from;
|
|
2325 char *to;
|
|
2326 {
|
|
2327 if (access (from, 0) == 0)
|
|
2328 {
|
|
2329 unlink (to);
|
|
2330 if (link (from, to) == 0)
|
|
2331 if (unlink (from) == 0)
|
|
2332 return (0);
|
|
2333 }
|
|
2334 return (-1);
|
|
2335 }
|
|
2336
|
621
|
2337 #endif
|
|
2338
|
491
|
2339 /* Set priority value to PRIO. */
|
|
2340
|
621
|
2341 int
|
491
|
2342 setpriority (which, who, prio)
|
|
2343 int which, who, prio;
|
|
2344 {
|
|
2345 int nice ();
|
|
2346
|
|
2347 nice (prio - nice (0));
|
|
2348 return (0);
|
|
2349 }
|
|
2350
|
|
2351 #ifndef HAVE_VFORK
|
|
2352
|
|
2353 /*
|
|
2354 * Substitute fork for vfork on USG flavors.
|
|
2355 */
|
|
2356
|
|
2357 vfork ()
|
|
2358 {
|
|
2359 return (fork ());
|
|
2360 }
|
|
2361
|
|
2362 #endif /* not HAVE_VFORK */
|
|
2363
|
|
2364 #ifdef MISSING_UTIMES
|
|
2365
|
|
2366 /* HPUX (among others) sets HAVE_TIMEVAL but does not implement utimes. */
|
|
2367
|
|
2368 utimes ()
|
|
2369 {
|
|
2370 }
|
|
2371 #endif
|
|
2372
|
|
2373 #ifdef IRIS_UTIME
|
|
2374
|
|
2375 /* The IRIS (3.5) has timevals, but uses sys V utime, and doesn't have the
|
|
2376 utimbuf structure defined anywhere but in the man page. */
|
|
2377
|
|
2378 struct utimbuf
|
|
2379 {
|
|
2380 long actime;
|
|
2381 long modtime;
|
|
2382 };
|
|
2383
|
|
2384 utimes (name, tvp)
|
|
2385 char *name;
|
|
2386 struct timeval tvp[];
|
|
2387 {
|
|
2388 struct utimbuf utb;
|
|
2389 utb.actime = tvp[0].tv_sec;
|
|
2390 utb.modtime = tvp[1].tv_sec;
|
|
2391 utime (name, &utb);
|
|
2392 }
|
|
2393 #endif /* IRIS_UTIME */
|
|
2394
|
|
2395
|
|
2396 #ifdef HPUX
|
|
2397 #ifndef HAVE_PERROR
|
|
2398
|
|
2399 /* HPUX curses library references perror, but as far as we know
|
|
2400 it won't be called. Anyway this definition will do for now. */
|
|
2401
|
|
2402 perror ()
|
|
2403 {
|
|
2404 }
|
|
2405
|
|
2406 #endif /* not HAVE_PERROR */
|
|
2407 #endif /* HPUX */
|
|
2408
|
|
2409 #ifndef HAVE_DUP2
|
|
2410
|
|
2411 /*
|
|
2412 * Emulate BSD dup2. First close newd if it already exists.
|
|
2413 * Then, attempt to dup oldd. If not successful, call dup2 recursively
|
|
2414 * until we are, then close the unsuccessful ones.
|
|
2415 */
|
|
2416
|
|
2417 dup2 (oldd, newd)
|
|
2418 int oldd;
|
|
2419 int newd;
|
|
2420 {
|
|
2421 register int fd, ret;
|
|
2422
|
|
2423 sys_close (newd);
|
|
2424
|
|
2425 #ifdef F_DUPFD
|
|
2426 fd = fcntl (oldd, F_DUPFD, newd);
|
|
2427 if (fd != newd)
|
|
2428 error ("can't dup2 (%i,%i) : %s", oldd, newd, sys_errlist[errno]);
|
|
2429 #else
|
|
2430 fd = dup (old);
|
|
2431 if (fd == -1)
|
|
2432 return -1;
|
|
2433 if (fd == new)
|
|
2434 return new;
|
|
2435 ret = dup2 (old,new);
|
|
2436 sys_close (fd);
|
|
2437 return ret;
|
|
2438 #endif
|
|
2439 }
|
|
2440
|
|
2441 #endif /* not HAVE_DUP2 */
|
|
2442
|
|
2443 /*
|
|
2444 * Gettimeofday. Simulate as much as possible. Only accurate
|
|
2445 * to nearest second. Emacs doesn't use tzp so ignore it for now.
|
|
2446 * Only needed when subprocesses are defined.
|
|
2447 */
|
|
2448
|
|
2449 #ifdef subprocesses
|
|
2450 #ifndef VMS
|
|
2451 #ifndef HAVE_GETTIMEOFDAY
|
|
2452 #ifdef HAVE_TIMEVAL
|
|
2453
|
|
2454 /* ARGSUSED */
|
|
2455 gettimeofday (tp, tzp)
|
|
2456 struct timeval *tp;
|
|
2457 struct timezone *tzp;
|
|
2458 {
|
|
2459 extern long time ();
|
|
2460
|
|
2461 tp->tv_sec = time ((long *)0);
|
|
2462 tp->tv_usec = 0;
|
|
2463 tzp->tz_minuteswest = -1;
|
|
2464 }
|
|
2465
|
|
2466 #endif
|
|
2467 #endif
|
|
2468 #endif
|
|
2469 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
|
|
2470
|
|
2471 /*
|
|
2472 * This function will go away as soon as all the stubs fixed. (fnf)
|
|
2473 */
|
|
2474
|
|
2475 croak (badfunc)
|
|
2476 char *badfunc;
|
|
2477 {
|
|
2478 printf ("%s not yet implemented\r\n", badfunc);
|
|
2479 reset_sys_modes ();
|
|
2480 exit (1);
|
|
2481 }
|
|
2482
|
|
2483 #endif /* USG */
|
|
2484
|
|
2485 #ifdef DGUX
|
|
2486
|
|
2487 char *sys_siglist[NSIG + 1] =
|
|
2488 {
|
|
2489 "null signal", /* 0 SIGNULL */
|
|
2490 "hangup", /* 1 SIGHUP */
|
|
2491 "interrupt", /* 2 SIGINT */
|
|
2492 "quit", /* 3 SIGQUIT */
|
|
2493 "illegal instruction", /* 4 SIGILL */
|
|
2494 "trace trap", /* 5 SIGTRAP */
|
|
2495 "abort termination", /* 6 SIGABRT */
|
|
2496 "SIGEMT", /* 7 SIGEMT */
|
|
2497 "floating point exception", /* 8 SIGFPE */
|
|
2498 "kill", /* 9 SIGKILL */
|
|
2499 "bus error", /* 10 SIGBUS */
|
|
2500 "segmentation violation", /* 11 SIGSEGV */
|
|
2501 "bad argument to system call", /* 12 SIGSYS */
|
|
2502 "write on a pipe with no reader", /* 13 SIGPIPE */
|
|
2503 "alarm clock", /* 14 SIGALRM */
|
|
2504 "software termination signal", /* 15 SIGTERM */
|
|
2505 "user defined signal 1", /* 16 SIGUSR1 */
|
|
2506 "user defined signal 2", /* 17 SIGUSR2 */
|
|
2507 "child stopped or terminated", /* 18 SIGCLD */
|
|
2508 "power-fail restart", /* 19 SIGPWR */
|
|
2509 "window size changed", /* 20 SIGWINCH */
|
|
2510 "undefined", /* 21 */
|
|
2511 "pollable event occured", /* 22 SIGPOLL */
|
|
2512 "sendable stop signal not from tty", /* 23 SIGSTOP */
|
|
2513 "stop signal from tty", /* 24 SIGSTP */
|
|
2514 "continue a stopped process", /* 25 SIGCONT */
|
|
2515 "attempted background tty read", /* 26 SIGTTIN */
|
|
2516 "attempted background tty write", /* 27 SIGTTOU */
|
|
2517 "undefined", /* 28 */
|
|
2518 "undefined", /* 29 */
|
|
2519 "undefined", /* 30 */
|
|
2520 "undefined", /* 31 */
|
|
2521 "undefined", /* 32 */
|
|
2522 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */
|
|
2523 "I/O is possible", /* 34 SIGIO */
|
|
2524 "exceeded cpu time limit", /* 35 SIGXCPU */
|
|
2525 "exceeded file size limit", /* 36 SIGXFSZ */
|
|
2526 "virtual time alarm", /* 37 SIGVTALRM */
|
|
2527 "profiling time alarm", /* 38 SIGPROF */
|
|
2528 "undefined", /* 39 */
|
|
2529 "file record locks revoked", /* 40 SIGLOST */
|
|
2530 "undefined", /* 41 */
|
|
2531 "undefined", /* 42 */
|
|
2532 "undefined", /* 43 */
|
|
2533 "undefined", /* 44 */
|
|
2534 "undefined", /* 45 */
|
|
2535 "undefined", /* 46 */
|
|
2536 "undefined", /* 47 */
|
|
2537 "undefined", /* 48 */
|
|
2538 "undefined", /* 49 */
|
|
2539 "undefined", /* 50 */
|
|
2540 "undefined", /* 51 */
|
|
2541 "undefined", /* 52 */
|
|
2542 "undefined", /* 53 */
|
|
2543 "undefined", /* 54 */
|
|
2544 "undefined", /* 55 */
|
|
2545 "undefined", /* 56 */
|
|
2546 "undefined", /* 57 */
|
|
2547 "undefined", /* 58 */
|
|
2548 "undefined", /* 59 */
|
|
2549 "undefined", /* 60 */
|
|
2550 "undefined", /* 61 */
|
|
2551 "undefined", /* 62 */
|
|
2552 "undefined", /* 63 */
|
|
2553 "notification message in mess. queue", /* 64 SIGDGNOTIFY */
|
|
2554 0
|
|
2555 };
|
|
2556
|
|
2557 #endif /* DGUX */
|
|
2558
|
|
2559 /* Directory routines for systems that don't have them. */
|
|
2560
|
|
2561 #ifdef SYSV_SYSTEM_DIR
|
|
2562
|
|
2563 #include <dirent.h>
|
|
2564
|
|
2565 #ifndef AIX
|
|
2566 int
|
|
2567 closedir (dirp)
|
|
2568 register DIR *dirp; /* stream from opendir */
|
|
2569 {
|
|
2570 sys_close (dirp->dd_fd);
|
|
2571 free ((char *) dirp->dd_buf); /* directory block defined in <dirent.h> */
|
|
2572 free ((char *) dirp);
|
|
2573 }
|
|
2574 #endif /* not AIX */
|
|
2575 #endif /* SYSV_SYSTEM_DIR */
|
|
2576
|
|
2577 #ifdef NONSYSTEM_DIR_LIBRARY
|
|
2578
|
|
2579 DIR *
|
|
2580 opendir (filename)
|
|
2581 char *filename; /* name of directory */
|
|
2582 {
|
|
2583 register DIR *dirp; /* -> malloc'ed storage */
|
|
2584 register int fd; /* file descriptor for read */
|
|
2585 struct stat sbuf; /* result of fstat */
|
|
2586
|
|
2587 fd = sys_open (filename, 0);
|
|
2588 if (fd < 0)
|
|
2589 return 0;
|
|
2590
|
|
2591 if (fstat (fd, &sbuf) < 0
|
|
2592 || (sbuf.st_mode & S_IFMT) != S_IFDIR
|
|
2593 || (dirp = (DIR *) malloc (sizeof (DIR))) == 0)
|
|
2594 {
|
|
2595 sys_close (fd);
|
|
2596 return 0; /* bad luck today */
|
|
2597 }
|
|
2598
|
|
2599 dirp->dd_fd = fd;
|
|
2600 dirp->dd_loc = dirp->dd_size = 0; /* refill needed */
|
|
2601
|
|
2602 return dirp;
|
|
2603 }
|
|
2604
|
|
2605 void
|
|
2606 closedir (dirp)
|
|
2607 register DIR *dirp; /* stream from opendir */
|
|
2608 {
|
|
2609 sys_close (dirp->dd_fd);
|
|
2610 free ((char *) dirp);
|
|
2611 }
|
|
2612
|
|
2613
|
|
2614 #ifndef VMS
|
|
2615 #define DIRSIZ 14
|
|
2616 struct olddir
|
|
2617 {
|
|
2618 ino_t od_ino; /* inode */
|
|
2619 char od_name[DIRSIZ]; /* filename */
|
|
2620 };
|
|
2621 #endif /* not VMS */
|
|
2622
|
|
2623 struct direct dir_static; /* simulated directory contents */
|
|
2624
|
|
2625 /* ARGUSED */
|
|
2626 struct direct *
|
|
2627 readdir (dirp)
|
|
2628 register DIR *dirp; /* stream from opendir */
|
|
2629 {
|
|
2630 #ifndef VMS
|
|
2631 register struct olddir *dp; /* -> directory data */
|
|
2632 #else /* VMS */
|
|
2633 register struct dir$_name *dp; /* -> directory data */
|
|
2634 register struct dir$_version *dv; /* -> version data */
|
|
2635 #endif /* VMS */
|
|
2636
|
|
2637 for (; ;)
|
|
2638 {
|
|
2639 if (dirp->dd_loc >= dirp->dd_size)
|
|
2640 dirp->dd_loc = dirp->dd_size = 0;
|
|
2641
|
|
2642 if (dirp->dd_size == 0 /* refill buffer */
|
|
2643 && (dirp->dd_size = sys_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0)
|
|
2644 return 0;
|
|
2645
|
|
2646 #ifndef VMS
|
|
2647 dp = (struct olddir *) &dirp->dd_buf[dirp->dd_loc];
|
|
2648 dirp->dd_loc += sizeof (struct olddir);
|
|
2649
|
|
2650 if (dp->od_ino != 0) /* not deleted entry */
|
|
2651 {
|
|
2652 dir_static.d_ino = dp->od_ino;
|
|
2653 strncpy (dir_static.d_name, dp->od_name, DIRSIZ);
|
|
2654 dir_static.d_name[DIRSIZ] = '\0';
|
|
2655 dir_static.d_namlen = strlen (dir_static.d_name);
|
|
2656 dir_static.d_reclen = sizeof (struct direct)
|
|
2657 - MAXNAMLEN + 3
|
|
2658 + dir_static.d_namlen - dir_static.d_namlen % 4;
|
|
2659 return &dir_static; /* -> simulated structure */
|
|
2660 }
|
|
2661 #else /* VMS */
|
|
2662 dp = (struct dir$_name *) dirp->dd_buf;
|
|
2663 if (dirp->dd_loc == 0)
|
|
2664 dirp->dd_loc = (dp->dir$b_namecount&1) ? dp->dir$b_namecount + 1
|
|
2665 : dp->dir$b_namecount;
|
|
2666 dv = (struct dir$_version *)&dp->dir$t_name[dirp->dd_loc];
|
|
2667 dir_static.d_ino = dv->dir$w_fid_num;
|
|
2668 dir_static.d_namlen = dp->dir$b_namecount;
|
|
2669 dir_static.d_reclen = sizeof (struct direct)
|
|
2670 - MAXNAMLEN + 3
|
|
2671 + dir_static.d_namlen - dir_static.d_namlen % 4;
|
|
2672 strncpy (dir_static.d_name, dp->dir$t_name, dp->dir$b_namecount);
|
|
2673 dir_static.d_name[dir_static.d_namlen] = '\0';
|
|
2674 dirp->dd_loc = dirp->dd_size; /* only one record at a time */
|
|
2675 return &dir_static;
|
|
2676 #endif /* VMS */
|
|
2677 }
|
|
2678 }
|
|
2679
|
|
2680 #ifdef VMS
|
|
2681 /* readdirver is just like readdir except it returns all versions of a file
|
|
2682 as separate entries. */
|
|
2683
|
|
2684 /* ARGUSED */
|
|
2685 struct direct *
|
|
2686 readdirver (dirp)
|
|
2687 register DIR *dirp; /* stream from opendir */
|
|
2688 {
|
|
2689 register struct dir$_name *dp; /* -> directory data */
|
|
2690 register struct dir$_version *dv; /* -> version data */
|
|
2691
|
|
2692 if (dirp->dd_loc >= dirp->dd_size - sizeof (struct dir$_name))
|
|
2693 dirp->dd_loc = dirp->dd_size = 0;
|
|
2694
|
|
2695 if (dirp->dd_size == 0 /* refill buffer */
|
|
2696 && (dirp->dd_size = sys_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0)
|
|
2697 return 0;
|
|
2698
|
|
2699 dp = (struct dir$_name *) dirp->dd_buf;
|
|
2700 if (dirp->dd_loc == 0)
|
|
2701 dirp->dd_loc = (dp->dir$b_namecount & 1) ? dp->dir$b_namecount + 1
|
|
2702 : dp->dir$b_namecount;
|
|
2703 dv = (struct dir$_version *) &dp->dir$t_name[dirp->dd_loc];
|
|
2704 strncpy (dir_static.d_name, dp->dir$t_name, dp->dir$b_namecount);
|
|
2705 sprintf (&dir_static.d_name[dp->dir$b_namecount], ";%d", dv->dir$w_version);
|
|
2706 dir_static.d_namlen = strlen (dir_static.d_name);
|
|
2707 dir_static.d_ino = dv->dir$w_fid_num;
|
|
2708 dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3
|
|
2709 + dir_static.d_namlen - dir_static.d_namlen % 4;
|
|
2710 dirp->dd_loc = ((char *) (++dv) - dp->dir$t_name);
|
|
2711 return &dir_static;
|
|
2712 }
|
|
2713
|
|
2714 #endif /* VMS */
|
|
2715
|
|
2716 #endif /* NONSYSTEM_DIR_LIBRARY */
|
|
2717
|
|
2718 /* Functions for VMS */
|
|
2719 #ifdef VMS
|
579
|
2720 #include "vms-pwd.h"
|
491
|
2721 #include <acldef.h>
|
|
2722 #include <chpdef.h>
|
|
2723 #include <jpidef.h>
|
|
2724
|
|
2725 /* Return as a string the VMS error string pertaining to STATUS.
|
|
2726 Reuses the same static buffer each time it is called. */
|
|
2727
|
|
2728 char *
|
|
2729 vmserrstr (status)
|
|
2730 int status; /* VMS status code */
|
|
2731 {
|
|
2732 int bufadr[2];
|
|
2733 short len;
|
|
2734 static char buf[257];
|
|
2735
|
|
2736 bufadr[0] = sizeof buf - 1;
|
|
2737 bufadr[1] = (int) buf;
|
|
2738 if (! (SYS$GETMSG (status, &len, bufadr, 0x1, 0) & 1))
|
|
2739 return "untranslatable VMS error status";
|
|
2740 buf[len] = '\0';
|
|
2741 return buf;
|
|
2742 }
|
|
2743
|
|
2744 #ifdef access
|
|
2745 #undef access
|
|
2746
|
|
2747 /* The following is necessary because 'access' emulation by VMS C (2.0) does
|
|
2748 * not work correctly. (It also doesn't work well in version 2.3.)
|
|
2749 */
|
|
2750
|
|
2751 #ifdef VMS4_4
|
|
2752
|
|
2753 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
|
|
2754 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
|
|
2755
|
|
2756 typedef union {
|
|
2757 struct {
|
|
2758 unsigned short s_buflen;
|
|
2759 unsigned short s_code;
|
|
2760 char *s_bufadr;
|
|
2761 unsigned short *s_retlenadr;
|
|
2762 } s;
|
|
2763 int end;
|
|
2764 } item;
|
|
2765 #define buflen s.s_buflen
|
|
2766 #define code s.s_code
|
|
2767 #define bufadr s.s_bufadr
|
|
2768 #define retlenadr s.s_retlenadr
|
|
2769
|
|
2770 #define R_OK 4 /* test for read permission */
|
|
2771 #define W_OK 2 /* test for write permission */
|
|
2772 #define X_OK 1 /* test for execute (search) permission */
|
|
2773 #define F_OK 0 /* test for presence of file */
|
|
2774
|
|
2775 int
|
|
2776 sys_access (path, mode)
|
|
2777 char *path;
|
|
2778 int mode;
|
|
2779 {
|
|
2780 static char *user = NULL;
|
|
2781 char dir_fn[512];
|
|
2782
|
|
2783 /* translate possible directory spec into .DIR file name, so brain-dead
|
|
2784 * access can treat the directory like a file. */
|
|
2785 if (directory_file_name (path, dir_fn))
|
|
2786 path = dir_fn;
|
|
2787
|
|
2788 if (mode == F_OK)
|
|
2789 return access (path, mode);
|
|
2790 if (user == NULL && (user = (char *) getenv ("USER")) == NULL)
|
|
2791 return -1;
|
|
2792 {
|
|
2793 int stat;
|
|
2794 int flags;
|
|
2795 int acces;
|
|
2796 unsigned short int dummy;
|
|
2797 item itemlst[3];
|
|
2798 static int constant = ACL$C_FILE;
|
|
2799 DESCRIPTOR (path_desc, path);
|
|
2800 DESCRIPTOR (user_desc, user);
|
|
2801
|
|
2802 flags = 0;
|
|
2803 acces = 0;
|
|
2804 if ((mode & X_OK) && ((stat = access (path, mode)) < 0 || mode == X_OK))
|
|
2805 return stat;
|
|
2806 if (mode & R_OK)
|
|
2807 acces |= CHP$M_READ;
|
|
2808 if (mode & W_OK)
|
|
2809 acces |= CHP$M_WRITE;
|
|
2810 itemlst[0].buflen = sizeof (int);
|
|
2811 itemlst[0].code = CHP$_FLAGS;
|
|
2812 itemlst[0].bufadr = (char *) &flags;
|
|
2813 itemlst[0].retlenadr = &dummy;
|
|
2814 itemlst[1].buflen = sizeof (int);
|
|
2815 itemlst[1].code = CHP$_ACCESS;
|
|
2816 itemlst[1].bufadr = (char *) &acces;
|
|
2817 itemlst[1].retlenadr = &dummy;
|
|
2818 itemlst[2].end = CHP$_END;
|
|
2819 stat = SYS$CHECK_ACCESS (&constant, &path_desc, &user_desc, itemlst);
|
|
2820 return stat == SS$_NORMAL ? 0 : -1;
|
|
2821 }
|
|
2822 }
|
|
2823
|
|
2824 #else /* not VMS4_4 */
|
|
2825
|
|
2826 #include <prvdef.h>
|
|
2827 #define ACE$M_WRITE 2
|
|
2828 #define ACE$C_KEYID 1
|
|
2829
|
|
2830 static unsigned short memid, grpid;
|
|
2831 static unsigned int uic;
|
|
2832
|
|
2833 /* Called from init_sys_modes, so it happens not very often
|
|
2834 but at least each time Emacs is loaded. */
|
|
2835 sys_access_reinit ()
|
|
2836 {
|
|
2837 uic = 0;
|
|
2838 }
|
|
2839
|
|
2840 int
|
|
2841 sys_access (filename, type)
|
|
2842 char * filename;
|
|
2843 int type;
|
|
2844 {
|
|
2845 struct FAB fab;
|
|
2846 struct XABPRO xab;
|
|
2847 int status, size, i, typecode, acl_controlled;
|
|
2848 unsigned int *aclptr, *aclend, aclbuf[60];
|
|
2849 union prvdef prvmask;
|
|
2850
|
|
2851 /* Get UIC and GRP values for protection checking. */
|
|
2852 if (uic == 0)
|
|
2853 {
|
|
2854 status = LIB$GETJPI (&JPI$_UIC, 0, 0, &uic, 0, 0);
|
|
2855 if (! (status & 1))
|
|
2856 return -1;
|
|
2857 memid = uic & 0xFFFF;
|
|
2858 grpid = uic >> 16;
|
|
2859 }
|
|
2860
|
|
2861 if (type != 2) /* not checking write access */
|
|
2862 return access (filename, type);
|
|
2863
|
|
2864 /* Check write protection. */
|
|
2865
|
|
2866 #define CHECKPRIV(bit) (prvmask.bit)
|
|
2867 #define WRITEABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
|
|
2868
|
|
2869 /* Find privilege bits */
|
|
2870 status = sys$setprv (0, 0, 0, prvmask);
|
|
2871 if (! (status & 1))
|
|
2872 error ("Unable to find privileges: %s", vmserrstr (status));
|
|
2873 if (CHECKPRIV (PRV$V_BYPASS))
|
|
2874 return 0; /* BYPASS enabled */
|
|
2875 fab = cc$rms_fab;
|
|
2876 fab.fab$b_fac = FAB$M_GET;
|
|
2877 fab.fab$l_fna = filename;
|
|
2878 fab.fab$b_fns = strlen (filename);
|
|
2879 fab.fab$l_xab = &xab;
|
|
2880 xab = cc$rms_xabpro;
|
|
2881 xab.xab$l_aclbuf = aclbuf;
|
|
2882 xab.xab$w_aclsiz = sizeof (aclbuf);
|
|
2883 status = sys$open (&fab, 0, 0);
|
|
2884 if (! (status & 1))
|
|
2885 return -1;
|
|
2886 sys$close (&fab, 0, 0);
|
|
2887 /* Check system access */
|
|
2888 if (CHECKPRIV (PRV$V_SYSPRV) && WRITEABLE (XAB$V_SYS))
|
|
2889 return 0;
|
|
2890 /* Check ACL entries, if any */
|
|
2891 acl_controlled = 0;
|
|
2892 if (xab.xab$w_acllen > 0)
|
|
2893 {
|
|
2894 aclptr = aclbuf;
|
|
2895 aclend = &aclbuf[xab.xab$w_acllen / 4];
|
|
2896 while (*aclptr && aclptr < aclend)
|
|
2897 {
|
|
2898 size = (*aclptr & 0xff) / 4;
|
|
2899 typecode = (*aclptr >> 8) & 0xff;
|
|
2900 if (typecode == ACE$C_KEYID)
|
|
2901 for (i = size - 1; i > 1; i--)
|
|
2902 if (aclptr[i] == uic)
|
|
2903 {
|
|
2904 acl_controlled = 1;
|
|
2905 if (aclptr[1] & ACE$M_WRITE)
|
|
2906 return 0; /* Write access through ACL */
|
|
2907 }
|
|
2908 aclptr = &aclptr[size];
|
|
2909 }
|
|
2910 if (acl_controlled) /* ACL specified, prohibits write access */
|
|
2911 return -1;
|
|
2912 }
|
|
2913 /* No ACL entries specified, check normal protection */
|
|
2914 if (WRITEABLE (XAB$V_WLD)) /* World writeable */
|
|
2915 return 0;
|
|
2916 if (WRITEABLE (XAB$V_GRP) &&
|
|
2917 (unsigned short) (xab.xab$l_uic >> 16) == grpid)
|
|
2918 return 0; /* Group writeable */
|
|
2919 if (WRITEABLE (XAB$V_OWN) &&
|
|
2920 (xab.xab$l_uic & 0xFFFF) == memid)
|
|
2921 return 0; /* Owner writeable */
|
|
2922
|
|
2923 return -1; /* Not writeable */
|
|
2924 }
|
|
2925 #endif /* not VMS4_4 */
|
|
2926 #endif /* access */
|
|
2927
|
|
2928 static char vtbuf[NAM$C_MAXRSS+1];
|
|
2929
|
|
2930 /* translate a vms file spec to a unix path */
|
|
2931 char *
|
|
2932 sys_translate_vms (vfile)
|
|
2933 char * vfile;
|
|
2934 {
|
|
2935 char * p;
|
|
2936 char * targ;
|
|
2937
|
|
2938 if (!vfile)
|
|
2939 return 0;
|
|
2940
|
|
2941 targ = vtbuf;
|
|
2942
|
|
2943 /* leading device or logical name is a root directory */
|
|
2944 if (p = strchr (vfile, ':'))
|
|
2945 {
|
|
2946 *targ++ = '/';
|
|
2947 while (vfile < p)
|
|
2948 *targ++ = *vfile++;
|
|
2949 vfile++;
|
|
2950 *targ++ = '/';
|
|
2951 }
|
|
2952 p = vfile;
|
|
2953 if (*p == '[' || *p == '<')
|
|
2954 {
|
|
2955 while (*++vfile != *p + 2)
|
|
2956 switch (*vfile)
|
|
2957 {
|
|
2958 case '.':
|
|
2959 if (vfile[-1] == *p)
|
|
2960 *targ++ = '.';
|
|
2961 *targ++ = '/';
|
|
2962 break;
|
|
2963
|
|
2964 case '-':
|
|
2965 *targ++ = '.';
|
|
2966 *targ++ = '.';
|
|
2967 break;
|
|
2968
|
|
2969 default:
|
|
2970 *targ++ = *vfile;
|
|
2971 break;
|
|
2972 }
|
|
2973 vfile++;
|
|
2974 *targ++ = '/';
|
|
2975 }
|
|
2976 while (*vfile)
|
|
2977 *targ++ = *vfile++;
|
|
2978
|
|
2979 return vtbuf;
|
|
2980 }
|
|
2981
|
|
2982 static char utbuf[NAM$C_MAXRSS+1];
|
|
2983
|
|
2984 /* translate a unix path to a VMS file spec */
|
|
2985 char *
|
|
2986 sys_translate_unix (ufile)
|
|
2987 char * ufile;
|
|
2988 {
|
|
2989 int slash_seen = 0;
|
|
2990 char *p;
|
|
2991 char * targ;
|
|
2992
|
|
2993 if (!ufile)
|
|
2994 return 0;
|
|
2995
|
|
2996 targ = utbuf;
|
|
2997
|
|
2998 if (*ufile == '/')
|
|
2999 {
|
|
3000 ufile++;
|
|
3001 }
|
|
3002
|
|
3003 while (*ufile)
|
|
3004 {
|
|
3005 switch (*ufile)
|
|
3006 {
|
|
3007 case '/':
|
|
3008 if (slash_seen)
|
|
3009 if (index (&ufile[1], '/'))
|
|
3010 *targ++ = '.';
|
|
3011 else
|
|
3012 *targ++ = ']';
|
|
3013 else
|
|
3014 {
|
|
3015 *targ++ = ':';
|
|
3016 if (index (&ufile[1], '/'))
|
|
3017 *targ++ = '[';
|
|
3018 slash_seen = 1;
|
|
3019 }
|
|
3020 break;
|
|
3021
|
|
3022 case '.':
|
|
3023 if (strncmp (ufile, "./", 2) == 0)
|
|
3024 {
|
|
3025 if (!slash_seen)
|
|
3026 {
|
|
3027 *targ++ = '[';
|
|
3028 slash_seen = 1;
|
|
3029 }
|
|
3030 ufile++; /* skip the dot */
|
|
3031 if (index (&ufile[1], '/'))
|
|
3032 *targ++ = '.';
|
|
3033 else
|
|
3034 *targ++ = ']';
|
|
3035 }
|
|
3036 else if (strncmp (ufile, "../", 3) == 0)
|
|
3037 {
|
|
3038 if (!slash_seen)
|
|
3039 {
|
|
3040 *targ++ = '[';
|
|
3041 slash_seen = 1;
|
|
3042 }
|
|
3043 *targ++ = '-';
|
|
3044 ufile += 2; /* skip the dots */
|
|
3045 if (index (&ufile[1], '/'))
|
|
3046 *targ++ = '.';
|
|
3047 else
|
|
3048 *targ++ = ']';
|
|
3049 }
|
|
3050 else
|
|
3051 *targ++ = *ufile;
|
|
3052 break;
|
|
3053
|
|
3054 default:
|
|
3055 *targ++ = *ufile;
|
|
3056 break;
|
|
3057 }
|
|
3058 ufile++;
|
|
3059 }
|
|
3060 *targ = '\0';
|
|
3061
|
|
3062 return utbuf;
|
|
3063 }
|
|
3064
|
|
3065 char *
|
|
3066 getwd (pathname)
|
|
3067 char *pathname;
|
|
3068 {
|
|
3069 char *ptr;
|
|
3070 strcpy (pathname, egetenv ("PATH"));
|
|
3071
|
|
3072 ptr = pathname;
|
|
3073 while (*ptr)
|
|
3074 {
|
|
3075 if ('a' <= *ptr && *ptr <= 'z')
|
|
3076 *ptr -= 040;
|
|
3077 ptr++;
|
|
3078 }
|
|
3079 return pathname;
|
|
3080 }
|
|
3081
|
|
3082 getppid ()
|
|
3083 {
|
|
3084 long item_code = JPI$_OWNER;
|
|
3085 unsigned long parent_id;
|
|
3086 int status;
|
|
3087
|
|
3088 if (((status = LIB$GETJPI (&item_code, 0, 0, &parent_id)) & 1) == 0)
|
|
3089 {
|
|
3090 errno = EVMSERR;
|
|
3091 vaxc$errno = status;
|
|
3092 return -1;
|
|
3093 }
|
|
3094 return parent_id;
|
|
3095 }
|
|
3096
|
|
3097 #undef getuid
|
|
3098 unsigned
|
|
3099 sys_getuid ()
|
|
3100 {
|
|
3101 return (getgid () << 16) | getuid ();
|
|
3102 }
|
|
3103
|
|
3104 int
|
|
3105 sys_read (fildes, buf, nbyte)
|
|
3106 int fildes;
|
|
3107 char *buf;
|
|
3108 unsigned int nbyte;
|
|
3109 {
|
|
3110 return read (fildes, buf, (nbyte < MAXIOSIZE ? nbyte : MAXIOSIZE));
|
|
3111 }
|
|
3112
|
|
3113 #if 0
|
|
3114 int
|
|
3115 sys_write (fildes, buf, nbyte)
|
|
3116 int fildes;
|
|
3117 char *buf;
|
|
3118 unsigned int nbyte;
|
|
3119 {
|
|
3120 register int nwrote, rtnval = 0;
|
|
3121
|
|
3122 while (nbyte > MAXIOSIZE && (nwrote = write (fildes, buf, MAXIOSIZE)) > 0) {
|
|
3123 nbyte -= nwrote;
|
|
3124 buf += nwrote;
|
|
3125 rtnval += nwrote;
|
|
3126 }
|
|
3127 if (nwrote < 0)
|
|
3128 return rtnval ? rtnval : -1;
|
|
3129 if ((nwrote = write (fildes, buf, nbyte)) < 0)
|
|
3130 return rtnval ? rtnval : -1;
|
|
3131 return (rtnval + nwrote);
|
|
3132 }
|
|
3133 #endif /* 0 */
|
|
3134
|
|
3135 /*
|
|
3136 * VAX/VMS VAX C RTL really loses. It insists that records
|
|
3137 * end with a newline (carriage return) character, and if they
|
|
3138 * don't it adds one (nice of it isn't it!)
|
|
3139 *
|
|
3140 * Thus we do this stupidity below.
|
|
3141 */
|
|
3142
|
|
3143 int
|
|
3144 sys_write (fildes, buf, nbytes)
|
|
3145 int fildes;
|
|
3146 char *buf;
|
|
3147 unsigned int nbytes;
|
|
3148 {
|
|
3149 register char *p;
|
|
3150 register char *e;
|
525
|
3151 int sum = 0;
|
|
3152 struct stat st;
|
|
3153
|
|
3154 fstat (fildes, &st);
|
491
|
3155 p = buf;
|
|
3156 while (nbytes > 0)
|
|
3157 {
|
525
|
3158 int len, retval;
|
|
3159
|
|
3160 /* Handle fixed-length files with carriage control. */
|
|
3161 if (st.st_fab_rfm == FAB$C_FIX
|
|
3162 && ((st.st_fab_rat & (FAB$M_FTN | FAB$M_CR)) != 0))
|
|
3163 {
|
|
3164 len = st.st_fab_mrs;
|
|
3165 retval = write (fildes, p, min (len, nbytes));
|
|
3166 if (retval != len)
|
|
3167 return -1;
|
|
3168 retval++; /* This skips the implied carriage control */
|
|
3169 }
|
|
3170 else
|
|
3171 {
|
|
3172 e = p + min (MAXIOSIZE, nbytes) - 1;
|
|
3173 while (*e != '\n' && e > p) e--;
|
|
3174 if (p == e) /* Ok.. so here we add a newline... sigh. */
|
|
3175 e = p + min (MAXIOSIZE, nbytes) - 1;
|
|
3176 len = e + 1 - p;
|
|
3177 retval = write (fildes, p, len);
|
|
3178 if (retval != len)
|
|
3179 return -1;
|
|
3180 }
|
|
3181 p += retval;
|
|
3182 sum += retval;
|
491
|
3183 nbytes -= retval;
|
|
3184 }
|
|
3185 return sum;
|
|
3186 }
|
|
3187
|
|
3188 /* Create file NEW copying its attributes from file OLD. If
|
|
3189 OLD is 0 or does not exist, create based on the value of
|
|
3190 vms_stmlf_recfm. */
|
|
3191
|
|
3192 /* Protection value the file should ultimately have.
|
|
3193 Set by create_copy_attrs, and use by rename_sansversions. */
|
|
3194 static unsigned short int fab_final_pro;
|
|
3195
|
|
3196 int
|
|
3197 creat_copy_attrs (old, new)
|
|
3198 char *old, *new;
|
|
3199 {
|
|
3200 struct FAB fab = cc$rms_fab;
|
|
3201 struct XABPRO xabpro;
|
|
3202 char aclbuf[256]; /* Choice of size is arbitrary. See below. */
|
|
3203 extern int vms_stmlf_recfm;
|
|
3204
|
|
3205 if (old)
|
|
3206 {
|
|
3207 fab.fab$b_fac = FAB$M_GET;
|
|
3208 fab.fab$l_fna = old;
|
|
3209 fab.fab$b_fns = strlen (old);
|
|
3210 fab.fab$l_xab = (char *) &xabpro;
|
|
3211 xabpro = cc$rms_xabpro;
|
|
3212 xabpro.xab$l_aclbuf = aclbuf;
|
|
3213 xabpro.xab$w_aclsiz = sizeof aclbuf;
|
|
3214 /* Call $OPEN to fill in the fab & xabpro fields. */
|
|
3215 if (sys$open (&fab, 0, 0) & 1)
|
|
3216 {
|
|
3217 sys$close (&fab, 0, 0);
|
|
3218 fab.fab$l_alq = 0; /* zero the allocation quantity */
|
|
3219 if (xabpro.xab$w_acllen > 0)
|
|
3220 {
|
|
3221 if (xabpro.xab$w_acllen > sizeof aclbuf)
|
|
3222 /* If the acl buffer was too short, redo open with longer one.
|
|
3223 Wouldn't need to do this if there were some system imposed
|
|
3224 limit on the size of an ACL, but I can't find any such. */
|
|
3225 {
|
|
3226 xabpro.xab$l_aclbuf = (char *) alloca (xabpro.xab$w_acllen);
|
|
3227 xabpro.xab$w_aclsiz = xabpro.xab$w_acllen;
|
|
3228 if (sys$open (&fab, 0, 0) & 1)
|
|
3229 sys$close (&fab, 0, 0);
|
|
3230 else
|
|
3231 old = 0;
|
|
3232 }
|
|
3233 }
|
|
3234 else
|
|
3235 xabpro.xab$l_aclbuf = 0;
|
|
3236 }
|
|
3237 else
|
|
3238 old = 0;
|
|
3239 }
|
|
3240 fab.fab$l_fna = new;
|
|
3241 fab.fab$b_fns = strlen (new);
|
|
3242 if (!old)
|
|
3243 {
|
|
3244 fab.fab$l_xab = 0;
|
|
3245 fab.fab$b_rfm = vms_stmlf_recfm ? FAB$C_STMLF : FAB$C_VAR;
|
|
3246 fab.fab$b_rat = FAB$M_CR;
|
|
3247 }
|
|
3248
|
|
3249 /* Set the file protections such that we will be able to manipulate
|
|
3250 this file. Once we are done writing and renaming it, we will set
|
|
3251 the protections back. */
|
|
3252 if (old)
|
|
3253 fab_final_pro = xabpro.xab$w_pro;
|
|
3254 else
|
|
3255 sys$setdfprot (0, &fab_final_pro);
|
|
3256 xabpro.xab$w_pro &= 0xff0f; /* set O:rewd for now. This is set back later. */
|
|
3257
|
|
3258 /* Create the new file with either default attrs or attrs copied
|
|
3259 from old file. */
|
|
3260 if (!(SYS$CREATE (&fab, 0, 0) & 1))
|
|
3261 return -1;
|
|
3262 sys$close (&fab, 0, 0);
|
|
3263 /* As this is a "replacement" for creat, return a file descriptor
|
|
3264 opened for writing. */
|
|
3265 return open (new, O_WRONLY);
|
|
3266 }
|
|
3267
|
|
3268 #ifdef creat
|
|
3269 #undef creat
|
|
3270 #include <varargs.h>
|
|
3271 #ifdef __GNUC__
|
|
3272 #ifndef va_count
|
|
3273 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
|
|
3274 #endif
|
|
3275 #endif
|
|
3276
|
|
3277 sys_creat (va_alist)
|
|
3278 va_dcl
|
|
3279 {
|
|
3280 va_list list_incrementor;
|
|
3281 char *name;
|
|
3282 int mode;
|
|
3283 int rfd; /* related file descriptor */
|
|
3284 int fd; /* Our new file descriptor */
|
|
3285 int count;
|
|
3286 struct stat st_buf;
|
|
3287 char rfm[12];
|
|
3288 char rat[15];
|
|
3289 char mrs[13];
|
|
3290 char fsz[13];
|
|
3291 extern int vms_stmlf_recfm;
|
|
3292
|
|
3293 va_count (count);
|
|
3294 va_start (list_incrementor);
|
|
3295 name = va_arg (list_incrementor, char *);
|
|
3296 mode = va_arg (list_incrementor, int);
|
|
3297 if (count > 2)
|
|
3298 rfd = va_arg (list_incrementor, int);
|
|
3299 va_end (list_incrementor);
|
|
3300 if (count > 2)
|
|
3301 {
|
|
3302 /* Use information from the related file descriptor to set record
|
|
3303 format of the newly created file. */
|
|
3304 fstat (rfd, &st_buf);
|
|
3305 switch (st_buf.st_fab_rfm)
|
|
3306 {
|
|
3307 case FAB$C_FIX:
|
|
3308 strcpy (rfm, "rfm = fix");
|
|
3309 sprintf (mrs, "mrs = %d", st_buf.st_fab_mrs);
|
|
3310 strcpy (rat, "rat = ");
|
|
3311 if (st_buf.st_fab_rat & FAB$M_CR)
|
|
3312 strcat (rat, "cr");
|
|
3313 else if (st_buf.st_fab_rat & FAB$M_FTN)
|
|
3314 strcat (rat, "ftn");
|
|
3315 else if (st_buf.st_fab_rat & FAB$M_PRN)
|
|
3316 strcat (rat, "prn");
|
|
3317 if (st_buf.st_fab_rat & FAB$M_BLK)
|
|
3318 if (st_buf.st_fab_rat & (FAB$M_CR|FAB$M_FTN|FAB$M_PRN))
|
|
3319 strcat (rat, ", blk");
|
|
3320 else
|
|
3321 strcat (rat, "blk");
|
|
3322 return creat (name, 0, rfm, rat, mrs);
|
|
3323
|
|
3324 case FAB$C_VFC:
|
|
3325 strcpy (rfm, "rfm = vfc");
|
|
3326 sprintf (fsz, "fsz = %d", st_buf.st_fab_fsz);
|
|
3327 strcpy (rat, "rat = ");
|
|
3328 if (st_buf.st_fab_rat & FAB$M_CR)
|
|
3329 strcat (rat, "cr");
|
|
3330 else if (st_buf.st_fab_rat & FAB$M_FTN)
|
|
3331 strcat (rat, "ftn");
|
|
3332 else if (st_buf.st_fab_rat & FAB$M_PRN)
|
|
3333 strcat (rat, "prn");
|
|
3334 if (st_buf.st_fab_rat & FAB$M_BLK)
|
|
3335 if (st_buf.st_fab_rat & (FAB$M_CR|FAB$M_FTN|FAB$M_PRN))
|
|
3336 strcat (rat, ", blk");
|
|
3337 else
|
|
3338 strcat (rat, "blk");
|
|
3339 return creat (name, 0, rfm, rat, fsz);
|
|
3340
|
|
3341 case FAB$C_STM:
|
|
3342 strcpy (rfm, "rfm = stm");
|
|
3343 break;
|
|
3344
|
|
3345 case FAB$C_STMCR:
|
|
3346 strcpy (rfm, "rfm = stmcr");
|
|
3347 break;
|
|
3348
|
|
3349 case FAB$C_STMLF:
|
|
3350 strcpy (rfm, "rfm = stmlf");
|
|
3351 break;
|
|
3352
|
|
3353 case FAB$C_UDF:
|
|
3354 strcpy (rfm, "rfm = udf");
|
|
3355 break;
|
|
3356
|
|
3357 case FAB$C_VAR:
|
|
3358 strcpy (rfm, "rfm = var");
|
|
3359 break;
|
|
3360 }
|
|
3361 strcpy (rat, "rat = ");
|
|
3362 if (st_buf.st_fab_rat & FAB$M_CR)
|
|
3363 strcat (rat, "cr");
|
|
3364 else if (st_buf.st_fab_rat & FAB$M_FTN)
|
|
3365 strcat (rat, "ftn");
|
|
3366 else if (st_buf.st_fab_rat & FAB$M_PRN)
|
|
3367 strcat (rat, "prn");
|
|
3368 if (st_buf.st_fab_rat & FAB$M_BLK)
|
|
3369 if (st_buf.st_fab_rat & (FAB$M_CR|FAB$M_FTN|FAB$M_PRN))
|
|
3370 strcat (rat, ", blk");
|
|
3371 else
|
|
3372 strcat (rat, "blk");
|
|
3373 }
|
|
3374 else
|
|
3375 {
|
|
3376 strcpy (rfm, vms_stmlf_recfm ? "rfm = stmlf" : "rfm=var");
|
|
3377 strcpy (rat, "rat=cr");
|
|
3378 }
|
|
3379 /* Until the VAX C RTL fixes the many bugs with modes, always use
|
|
3380 mode 0 to get the user's default protection. */
|
|
3381 fd = creat (name, 0, rfm, rat);
|
|
3382 if (fd < 0 && errno == EEXIST)
|
|
3383 {
|
|
3384 if (unlink (name) < 0)
|
|
3385 report_file_error ("delete", build_string (name));
|
|
3386 fd = creat (name, 0, rfm, rat);
|
|
3387 }
|
|
3388 return fd;
|
|
3389 }
|
|
3390 #endif /* creat */
|
|
3391
|
|
3392 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
|
|
3393 sys_fwrite (ptr, size, num, fp)
|
|
3394 register char * ptr;
|
|
3395 FILE * fp;
|
|
3396 {
|
|
3397 register int tot = num * size;
|
|
3398
|
|
3399 while (tot--)
|
|
3400 fputc (*ptr++, fp);
|
|
3401 }
|
|
3402
|
|
3403 /*
|
|
3404 * The VMS C library routine creat actually creates a new version of an
|
|
3405 * existing file rather than truncating the old version. There are times
|
|
3406 * when this is not the desired behavior, for instance, when writing an
|
|
3407 * auto save file (you only want one version), or when you don't have
|
|
3408 * write permission in the directory containing the file (but the file
|
|
3409 * itself is writable). Hence this routine, which is equivalent to
|
|
3410 * "close (creat (fn, 0));" on Unix if fn already exists.
|
|
3411 */
|
|
3412 int
|
|
3413 vms_truncate (fn)
|
|
3414 char *fn;
|
|
3415 {
|
|
3416 struct FAB xfab = cc$rms_fab;
|
|
3417 struct RAB xrab = cc$rms_rab;
|
|
3418 int status;
|
|
3419
|
|
3420 xfab.fab$l_fop = FAB$M_TEF; /* free allocated but unused blocks on close */
|
|
3421 xfab.fab$b_fac = FAB$M_TRN | FAB$M_GET; /* allow truncate and get access */
|
|
3422 xfab.fab$b_shr = FAB$M_NIL; /* allow no sharing - file must be locked */
|
|
3423 xfab.fab$l_fna = fn;
|
|
3424 xfab.fab$b_fns = strlen (fn);
|
|
3425 xfab.fab$l_dna = ";0"; /* default to latest version of the file */
|
|
3426 xfab.fab$b_dns = 2;
|
|
3427 xrab.rab$l_fab = &xfab;
|
|
3428
|
|
3429 /* This gibberish opens the file, positions to the first record, and
|
|
3430 deletes all records from there until the end of file. */
|
|
3431 if ((sys$open (&xfab) & 01) == 01)
|
|
3432 {
|
|
3433 if ((sys$connect (&xrab) & 01) == 01 &&
|
|
3434 (sys$find (&xrab) & 01) == 01 &&
|
|
3435 (sys$truncate (&xrab) & 01) == 01)
|
|
3436 status = 0;
|
|
3437 else
|
|
3438 status = -1;
|
|
3439 }
|
|
3440 else
|
|
3441 status = -1;
|
|
3442 sys$close (&xfab);
|
|
3443 return status;
|
|
3444 }
|
|
3445
|
|
3446 /* Define this symbol to actually read SYSUAF.DAT. This requires either
|
|
3447 SYSPRV or a readable SYSUAF.DAT. */
|
|
3448
|
|
3449 #ifdef READ_SYSUAF
|
|
3450 /*
|
|
3451 * getuaf.c
|
|
3452 *
|
|
3453 * Routine to read the VMS User Authorization File and return
|
|
3454 * a specific user's record.
|
|
3455 */
|
|
3456
|
|
3457 static struct UAF retuaf;
|
|
3458
|
|
3459 struct UAF *
|
|
3460 get_uaf_name (uname)
|
|
3461 char * uname;
|
|
3462 {
|
|
3463 register status;
|
|
3464 struct FAB uaf_fab;
|
|
3465 struct RAB uaf_rab;
|
|
3466
|
|
3467 uaf_fab = cc$rms_fab;
|
|
3468 uaf_rab = cc$rms_rab;
|
|
3469 /* initialize fab fields */
|
|
3470 uaf_fab.fab$l_fna = "SYS$SYSTEM:SYSUAF.DAT";
|
|
3471 uaf_fab.fab$b_fns = 21;
|
|
3472 uaf_fab.fab$b_fac = FAB$M_GET;
|
|
3473 uaf_fab.fab$b_org = FAB$C_IDX;
|
|
3474 uaf_fab.fab$b_shr = FAB$M_GET|FAB$M_PUT|FAB$M_UPD|FAB$M_DEL;
|
|
3475 /* initialize rab fields */
|
|
3476 uaf_rab.rab$l_fab = &uaf_fab;
|
|
3477 /* open the User Authorization File */
|
|
3478 status = sys$open (&uaf_fab);
|
|
3479 if (!(status&1))
|
|
3480 {
|
|
3481 errno = EVMSERR;
|
|
3482 vaxc$errno = status;
|
|
3483 return 0;
|
|
3484 }
|
|
3485 status = sys$connect (&uaf_rab);
|
|
3486 if (!(status&1))
|
|
3487 {
|
|
3488 errno = EVMSERR;
|
|
3489 vaxc$errno = status;
|
|
3490 return 0;
|
|
3491 }
|
|
3492 /* read the requested record - index is in uname */
|
|
3493 uaf_rab.rab$l_kbf = uname;
|
|
3494 uaf_rab.rab$b_ksz = strlen (uname);
|
|
3495 uaf_rab.rab$b_rac = RAB$C_KEY;
|
|
3496 uaf_rab.rab$l_ubf = (char *)&retuaf;
|
|
3497 uaf_rab.rab$w_usz = sizeof retuaf;
|
|
3498 status = sys$get (&uaf_rab);
|
|
3499 if (!(status&1))
|
|
3500 {
|
|
3501 errno = EVMSERR;
|
|
3502 vaxc$errno = status;
|
|
3503 return 0;
|
|
3504 }
|
|
3505 /* close the User Authorization File */
|
|
3506 status = sys$disconnect (&uaf_rab);
|
|
3507 if (!(status&1))
|
|
3508 {
|
|
3509 errno = EVMSERR;
|
|
3510 vaxc$errno = status;
|
|
3511 return 0;
|
|
3512 }
|
|
3513 status = sys$close (&uaf_fab);
|
|
3514 if (!(status&1))
|
|
3515 {
|
|
3516 errno = EVMSERR;
|
|
3517 vaxc$errno = status;
|
|
3518 return 0;
|
|
3519 }
|
|
3520 return &retuaf;
|
|
3521 }
|
|
3522
|
|
3523 struct UAF *
|
|
3524 get_uaf_uic (uic)
|
|
3525 unsigned long uic;
|
|
3526 {
|
|
3527 register status;
|
|
3528 struct FAB uaf_fab;
|
|
3529 struct RAB uaf_rab;
|
|
3530
|
|
3531 uaf_fab = cc$rms_fab;
|
|
3532 uaf_rab = cc$rms_rab;
|
|
3533 /* initialize fab fields */
|
|
3534 uaf_fab.fab$l_fna = "SYS$SYSTEM:SYSUAF.DAT";
|
|
3535 uaf_fab.fab$b_fns = 21;
|
|
3536 uaf_fab.fab$b_fac = FAB$M_GET;
|
|
3537 uaf_fab.fab$b_org = FAB$C_IDX;
|
|
3538 uaf_fab.fab$b_shr = FAB$M_GET|FAB$M_PUT|FAB$M_UPD|FAB$M_DEL;
|
|
3539 /* initialize rab fields */
|
|
3540 uaf_rab.rab$l_fab = &uaf_fab;
|
|
3541 /* open the User Authorization File */
|
|
3542 status = sys$open (&uaf_fab);
|
|
3543 if (!(status&1))
|
|
3544 {
|
|
3545 errno = EVMSERR;
|
|
3546 vaxc$errno = status;
|
|
3547 return 0;
|
|
3548 }
|
|
3549 status = sys$connect (&uaf_rab);
|
|
3550 if (!(status&1))
|
|
3551 {
|
|
3552 errno = EVMSERR;
|
|
3553 vaxc$errno = status;
|
|
3554 return 0;
|
|
3555 }
|
|
3556 /* read the requested record - index is in uic */
|
|
3557 uaf_rab.rab$b_krf = 1; /* 1st alternate key */
|
|
3558 uaf_rab.rab$l_kbf = (char *) &uic;
|
|
3559 uaf_rab.rab$b_ksz = sizeof uic;
|
|
3560 uaf_rab.rab$b_rac = RAB$C_KEY;
|
|
3561 uaf_rab.rab$l_ubf = (char *)&retuaf;
|
|
3562 uaf_rab.rab$w_usz = sizeof retuaf;
|
|
3563 status = sys$get (&uaf_rab);
|
|
3564 if (!(status&1))
|
|
3565 {
|
|
3566 errno = EVMSERR;
|
|
3567 vaxc$errno = status;
|
|
3568 return 0;
|
|
3569 }
|
|
3570 /* close the User Authorization File */
|
|
3571 status = sys$disconnect (&uaf_rab);
|
|
3572 if (!(status&1))
|
|
3573 {
|
|
3574 errno = EVMSERR;
|
|
3575 vaxc$errno = status;
|
|
3576 return 0;
|
|
3577 }
|
|
3578 status = sys$close (&uaf_fab);
|
|
3579 if (!(status&1))
|
|
3580 {
|
|
3581 errno = EVMSERR;
|
|
3582 vaxc$errno = status;
|
|
3583 return 0;
|
|
3584 }
|
|
3585 return &retuaf;
|
|
3586 }
|
|
3587
|
|
3588 static struct passwd retpw;
|
|
3589
|
|
3590 struct passwd *
|
|
3591 cnv_uaf_pw (up)
|
|
3592 struct UAF * up;
|
|
3593 {
|
|
3594 char * ptr;
|
|
3595
|
|
3596 /* copy these out first because if the username is 32 chars, the next
|
|
3597 section will overwrite the first byte of the UIC */
|
|
3598 retpw.pw_uid = up->uaf$w_mem;
|
|
3599 retpw.pw_gid = up->uaf$w_grp;
|
|
3600
|
|
3601 /* I suppose this is not the best sytle, to possibly overwrite one
|
|
3602 byte beyond the end of the field, but what the heck... */
|
|
3603 ptr = &up->uaf$t_username[UAF$S_USERNAME];
|
|
3604 while (ptr[-1] == ' ')
|
|
3605 ptr--;
|
|
3606 *ptr = '\0';
|
|
3607 strcpy (retpw.pw_name, up->uaf$t_username);
|
|
3608
|
|
3609 /* the rest of these are counted ascii strings */
|
|
3610 strncpy (retpw.pw_gecos, &up->uaf$t_owner[1], up->uaf$t_owner[0]);
|
|
3611 retpw.pw_gecos[up->uaf$t_owner[0]] = '\0';
|
|
3612 strncpy (retpw.pw_dir, &up->uaf$t_defdev[1], up->uaf$t_defdev[0]);
|
|
3613 retpw.pw_dir[up->uaf$t_defdev[0]] = '\0';
|
|
3614 strncat (retpw.pw_dir, &up->uaf$t_defdir[1], up->uaf$t_defdir[0]);
|
|
3615 retpw.pw_dir[up->uaf$t_defdev[0] + up->uaf$t_defdir[0]] = '\0';
|
|
3616 strncpy (retpw.pw_shell, &up->uaf$t_defcli[1], up->uaf$t_defcli[0]);
|
|
3617 retpw.pw_shell[up->uaf$t_defcli[0]] = '\0';
|
|
3618
|
|
3619 return &retpw;
|
|
3620 }
|
|
3621 #else /* not READ_SYSUAF */
|
|
3622 static struct passwd retpw;
|
|
3623 #endif /* not READ_SYSUAF */
|
|
3624
|
|
3625 struct passwd *
|
|
3626 getpwnam (name)
|
|
3627 char * name;
|
|
3628 {
|
|
3629 #ifdef READ_SYSUAF
|
|
3630 struct UAF *up;
|
|
3631 #else
|
|
3632 char * user;
|
|
3633 char * dir;
|
|
3634 unsigned char * full;
|
|
3635 #endif /* READ_SYSUAF */
|
|
3636 char *ptr = name;
|
|
3637
|
|
3638 while (*ptr)
|
|
3639 {
|
|
3640 if ('a' <= *ptr && *ptr <= 'z')
|
|
3641 *ptr -= 040;
|
|
3642 ptr++;
|
|
3643 }
|
|
3644 #ifdef READ_SYSUAF
|
|
3645 if (!(up = get_uaf_name (name)))
|
|
3646 return 0;
|
|
3647 return cnv_uaf_pw (up);
|
|
3648 #else
|
|
3649 if (strcmp (name, getenv ("USER")) == 0)
|
|
3650 {
|
|
3651 retpw.pw_uid = getuid ();
|
|
3652 retpw.pw_gid = getgid ();
|
|
3653 strcpy (retpw.pw_name, name);
|
|
3654 if (full = egetenv ("FULLNAME"))
|
|
3655 strcpy (retpw.pw_gecos, full);
|
|
3656 else
|
|
3657 *retpw.pw_gecos = '\0';
|
|
3658 strcpy (retpw.pw_dir, egetenv ("HOME"));
|
|
3659 *retpw.pw_shell = '\0';
|
|
3660 return &retpw;
|
|
3661 }
|
|
3662 else
|
|
3663 return 0;
|
|
3664 #endif /* not READ_SYSUAF */
|
|
3665 }
|
|
3666
|
|
3667 struct passwd *
|
|
3668 getpwuid (uid)
|
|
3669 unsigned long uid;
|
|
3670 {
|
|
3671 #ifdef READ_SYSUAF
|
|
3672 struct UAF * up;
|
|
3673
|
|
3674 if (!(up = get_uaf_uic (uid)))
|
|
3675 return 0;
|
|
3676 return cnv_uaf_pw (up);
|
|
3677 #else
|
|
3678 if (uid == sys_getuid ())
|
|
3679 return getpwnam (egetenv ("USER"));
|
|
3680 else
|
|
3681 return 0;
|
|
3682 #endif /* not READ_SYSUAF */
|
|
3683 }
|
|
3684
|
|
3685 /* return total address space available to the current process. This is
|
|
3686 the sum of the current p0 size, p1 size and free page table entries
|
|
3687 available. */
|
|
3688 vlimit ()
|
|
3689 {
|
|
3690 int item_code;
|
|
3691 unsigned long free_pages;
|
|
3692 unsigned long frep0va;
|
|
3693 unsigned long frep1va;
|
|
3694 register status;
|
|
3695
|
|
3696 item_code = JPI$_FREPTECNT;
|
|
3697 if (((status = LIB$GETJPI (&item_code, 0, 0, &free_pages)) & 1) == 0)
|
|
3698 {
|
|
3699 errno = EVMSERR;
|
|
3700 vaxc$errno = status;
|
|
3701 return -1;
|
|
3702 }
|
|
3703 free_pages *= 512;
|
|
3704
|
|
3705 item_code = JPI$_FREP0VA;
|
|
3706 if (((status = LIB$GETJPI (&item_code, 0, 0, &frep0va)) & 1) == 0)
|
|
3707 {
|
|
3708 errno = EVMSERR;
|
|
3709 vaxc$errno = status;
|
|
3710 return -1;
|
|
3711 }
|
|
3712 item_code = JPI$_FREP1VA;
|
|
3713 if (((status = LIB$GETJPI (&item_code, 0, 0, &frep1va)) & 1) == 0)
|
|
3714 {
|
|
3715 errno = EVMSERR;
|
|
3716 vaxc$errno = status;
|
|
3717 return -1;
|
|
3718 }
|
|
3719
|
|
3720 return free_pages + frep0va + (0x7fffffff - frep1va);
|
|
3721 }
|
|
3722
|
|
3723 define_logical_name (varname, string)
|
|
3724 char *varname;
|
|
3725 char *string;
|
|
3726 {
|
|
3727 struct dsc$descriptor_s strdsc =
|
|
3728 {strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string};
|
|
3729 struct dsc$descriptor_s envdsc =
|
|
3730 {strlen (varname), DSC$K_DTYPE_T, DSC$K_CLASS_S, varname};
|
|
3731 struct dsc$descriptor_s lnmdsc =
|
|
3732 {7, DSC$K_DTYPE_T, DSC$K_CLASS_S, "LNM$JOB"};
|
|
3733
|
|
3734 return LIB$SET_LOGICAL (&envdsc, &strdsc, &lnmdsc, 0, 0);
|
|
3735 }
|
|
3736
|
|
3737 delete_logical_name (varname)
|
|
3738 char *varname;
|
|
3739 {
|
|
3740 struct dsc$descriptor_s envdsc =
|
|
3741 {strlen (varname), DSC$K_DTYPE_T, DSC$K_CLASS_S, varname};
|
|
3742 struct dsc$descriptor_s lnmdsc =
|
|
3743 {7, DSC$K_DTYPE_T, DSC$K_CLASS_S, "LNM$JOB"};
|
|
3744
|
|
3745 return LIB$DELETE_LOGICAL (&envdsc, &lnmdsc);
|
|
3746 }
|
|
3747
|
|
3748 ulimit ()
|
|
3749 {}
|
|
3750
|
|
3751 setpriority ()
|
|
3752 {}
|
|
3753
|
|
3754 setpgrp ()
|
|
3755 {}
|
|
3756
|
|
3757 execvp ()
|
|
3758 {
|
|
3759 error ("execvp system call not implemented");
|
|
3760 }
|
|
3761
|
|
3762 int
|
|
3763 rename (from, to)
|
|
3764 char *from, *to;
|
|
3765 {
|
|
3766 int status;
|
|
3767 struct FAB from_fab = cc$rms_fab, to_fab = cc$rms_fab;
|
|
3768 struct NAM from_nam = cc$rms_nam, to_nam = cc$rms_nam;
|
|
3769 char from_esn[NAM$C_MAXRSS];
|
|
3770 char to_esn[NAM$C_MAXRSS];
|
|
3771
|
|
3772 from_fab.fab$l_fna = from;
|
|
3773 from_fab.fab$b_fns = strlen (from);
|
|
3774 from_fab.fab$l_nam = &from_nam;
|
|
3775 from_fab.fab$l_fop = FAB$M_NAM;
|
|
3776
|
|
3777 from_nam.nam$l_esa = from_esn;
|
|
3778 from_nam.nam$b_ess = sizeof from_esn;
|
|
3779
|
|
3780 to_fab.fab$l_fna = to;
|
|
3781 to_fab.fab$b_fns = strlen (to);
|
|
3782 to_fab.fab$l_nam = &to_nam;
|
|
3783 to_fab.fab$l_fop = FAB$M_NAM;
|
|
3784
|
|
3785 to_nam.nam$l_esa = to_esn;
|
|
3786 to_nam.nam$b_ess = sizeof to_esn;
|
|
3787
|
|
3788 status = SYS$RENAME (&from_fab, 0, 0, &to_fab);
|
|
3789
|
|
3790 if (status & 1)
|
|
3791 return 0;
|
|
3792 else
|
|
3793 {
|
|
3794 if (status == RMS$_DEV)
|
|
3795 errno = EXDEV;
|
|
3796 else
|
|
3797 errno = EVMSERR;
|
|
3798 vaxc$errno = status;
|
|
3799 return -1;
|
|
3800 }
|
|
3801 }
|
|
3802
|
|
3803 /* This function renames a file like `rename', but it strips
|
|
3804 the version number from the "to" filename, such that the "to" file is
|
|
3805 will always be a new version. It also sets the file protection once it is
|
|
3806 finished. The protection that we will use is stored in fab_final_pro,
|
|
3807 and was set when we did a creat_copy_attrs to create the file that we
|
|
3808 are renaming.
|
|
3809
|
|
3810 We could use the chmod function, but Eunichs uses 3 bits per user category
|
|
3811 to describe the protection, and VMS uses 4 (write and delete are seperate
|
|
3812 bits). To maintain portability, the VMS implementation of `chmod' wires
|
|
3813 the W and D bits together. */
|
|
3814
|
|
3815
|
|
3816 static struct fibdef fib; /* We need this initialized to zero */
|
|
3817 char vms_file_written[NAM$C_MAXRSS];
|
|
3818
|
|
3819 int
|
|
3820 rename_sans_version (from,to)
|
|
3821 char *from, *to;
|
|
3822 {
|
|
3823 short int chan;
|
|
3824 int stat;
|
|
3825 short int iosb[4];
|
|
3826 int status;
|
|
3827 struct FAB to_fab = cc$rms_fab;
|
|
3828 struct NAM to_nam = cc$rms_nam;
|
|
3829 struct dsc$descriptor fib_d ={sizeof (fib),0,0,(char*) &fib};
|
|
3830 struct dsc$descriptor fib_attr[2]
|
|
3831 = {{sizeof (fab_final_pro),ATR$C_FPRO,0,(char*) &fab_final_pro},{0,0,0,0}};
|
|
3832 char to_esn[NAM$C_MAXRSS];
|
|
3833
|
|
3834 $DESCRIPTOR (disk,to_esn);
|
|
3835
|
|
3836 to_fab.fab$l_fna = to;
|
|
3837 to_fab.fab$b_fns = strlen (to);
|
|
3838 to_fab.fab$l_nam = &to_nam;
|
|
3839 to_fab.fab$l_fop = FAB$M_NAM;
|
|
3840
|
|
3841 to_nam.nam$l_esa = to_esn;
|
|
3842 to_nam.nam$b_ess = sizeof to_esn;
|
|
3843
|
|
3844 status = SYS$PARSE (&to_fab, 0, 0); /* figure out the full file name */
|
|
3845
|
|
3846 if (to_nam.nam$l_fnb && NAM$M_EXP_VER)
|
|
3847 *(to_nam.nam$l_ver) = '\0';
|
|
3848
|
|
3849 stat = rename (from, to_esn);
|
|
3850 if (stat < 0)
|
|
3851 return stat;
|
|
3852
|
|
3853 strcpy (vms_file_written, to_esn);
|
|
3854
|
|
3855 to_fab.fab$l_fna = vms_file_written; /* this points to the versionless name */
|
|
3856 to_fab.fab$b_fns = strlen (vms_file_written);
|
|
3857
|
|
3858 /* Now set the file protection to the correct value */
|
|
3859 sys$open (&to_fab, 0, 0); /* This fills in the nam$w_fid fields */
|
|
3860
|
|
3861 /* Copy these fields into the fib */
|
|
3862 fib.fib$r_fid_overlay.fib$w_fid[0] = to_nam.nam$w_fid[0];
|
|
3863 fib.fib$r_fid_overlay.fib$w_fid[1] = to_nam.nam$w_fid[1];
|
|
3864 fib.fib$r_fid_overlay.fib$w_fid[2] = to_nam.nam$w_fid[2];
|
|
3865
|
|
3866 sys$close (&to_fab, 0, 0);
|
|
3867
|
|
3868 stat = sys$assign (&disk, &chan, 0, 0); /* open a channel to the disk */
|
|
3869 if (!stat)
|
|
3870 lib$signal (stat);
|
|
3871 stat = sys$qiow (0, chan, IO$_MODIFY, iosb, 0, 0, &fib_d,
|
|
3872 0, 0, 0, &fib_attr, 0);
|
|
3873 if (!stat)
|
|
3874 lib$signal (stat);
|
|
3875 stat = sys$dassgn (chan);
|
|
3876 if (!stat)
|
|
3877 lib$signal (stat);
|
|
3878 strcpy (vms_file_written, to_esn); /* We will write this to the screen*/
|
|
3879 return 0;
|
|
3880 }
|
|
3881
|
|
3882 link (file, new)
|
|
3883 char * file, * new;
|
|
3884 {
|
|
3885 register status;
|
|
3886 struct FAB fab;
|
|
3887 struct NAM nam;
|
|
3888 unsigned short fid[3];
|
|
3889 char esa[NAM$C_MAXRSS];
|
|
3890
|
|
3891 fab = cc$rms_fab;
|
|
3892 fab.fab$l_fop = FAB$M_OFP;
|
|
3893 fab.fab$l_fna = file;
|
|
3894 fab.fab$b_fns = strlen (file);
|
|
3895 fab.fab$l_nam = &nam;
|
|
3896
|
|
3897 nam = cc$rms_nam;
|
|
3898 nam.nam$l_esa = esa;
|
|
3899 nam.nam$b_ess = NAM$C_MAXRSS;
|
|
3900
|
|
3901 status = SYS$PARSE (&fab);
|
|
3902 if ((status & 1) == 0)
|
|
3903 {
|
|
3904 errno = EVMSERR;
|
|
3905 vaxc$errno = status;
|
|
3906 return -1;
|
|
3907 }
|
|
3908 status = SYS$SEARCH (&fab);
|
|
3909 if ((status & 1) == 0)
|
|
3910 {
|
|
3911 errno = EVMSERR;
|
|
3912 vaxc$errno = status;
|
|
3913 return -1;
|
|
3914 }
|
|
3915
|
|
3916 fid[0] = nam.nam$w_fid[0];
|
|
3917 fid[1] = nam.nam$w_fid[1];
|
|
3918 fid[2] = nam.nam$w_fid[2];
|
|
3919
|
|
3920 fab.fab$l_fna = new;
|
|
3921 fab.fab$b_fns = strlen (new);
|
|
3922
|
|
3923 status = SYS$PARSE (&fab);
|
|
3924 if ((status & 1) == 0)
|
|
3925 {
|
|
3926 errno = EVMSERR;
|
|
3927 vaxc$errno = status;
|
|
3928 return -1;
|
|
3929 }
|
|
3930
|
|
3931 nam.nam$w_fid[0] = fid[0];
|
|
3932 nam.nam$w_fid[1] = fid[1];
|
|
3933 nam.nam$w_fid[2] = fid[2];
|
|
3934
|
|
3935 nam.nam$l_esa = nam.nam$l_name;
|
|
3936 nam.nam$b_esl = nam.nam$b_name + nam.nam$b_type + nam.nam$b_ver;
|
|
3937
|
|
3938 status = SYS$ENTER (&fab);
|
|
3939 if ((status & 1) == 0)
|
|
3940 {
|
|
3941 errno = EVMSERR;
|
|
3942 vaxc$errno = status;
|
|
3943 return -1;
|
|
3944 }
|
|
3945
|
|
3946 return 0;
|
|
3947 }
|
|
3948
|
|
3949 croak (badfunc)
|
|
3950 char *badfunc;
|
|
3951 {
|
|
3952 printf ("%s not yet implemented\r\n", badfunc);
|
|
3953 reset_sys_modes ();
|
|
3954 exit (1);
|
|
3955 }
|
|
3956
|
|
3957 long
|
|
3958 random ()
|
|
3959 {
|
|
3960 /* Arrange to return a range centered on zero. */
|
|
3961 return rand () - (1 << 30);
|
|
3962 }
|
|
3963
|
|
3964 srandom (seed)
|
|
3965 {
|
|
3966 srand (seed);
|
|
3967 }
|
|
3968 #endif /* VMS */
|
|
3969
|
|
3970 #ifdef AIX
|
|
3971
|
|
3972 /* Called from init_sys_modes. */
|
|
3973 hft_init ()
|
|
3974 {
|
|
3975 int junk;
|
|
3976
|
|
3977 /* If we're not on an HFT we shouldn't do any of this. We determine
|
|
3978 if we are on an HFT by trying to get an HFT error code. If this
|
|
3979 call fails, we're not on an HFT. */
|
|
3980 #ifdef IBMR2AIX
|
|
3981 if (ioctl (0, HFQERROR, &junk) < 0)
|
|
3982 return;
|
|
3983 #else /* not IBMR2AIX */
|
|
3984 if (ioctl (0, HFQEIO, 0) < 0)
|
|
3985 return;
|
|
3986 #endif /* not IBMR2AIX */
|
|
3987
|
|
3988 /* On AIX the default hft keyboard mapping uses backspace rather than delete
|
|
3989 as the rubout key's ASCII code. Here this is changed. The bug is that
|
|
3990 there's no way to determine the old mapping, so in reset_sys_modes
|
|
3991 we need to assume that the normal map had been present. Of course, this
|
|
3992 code also doesn't help if on a terminal emulator which doesn't understand
|
|
3993 HFT VTD's. */
|
|
3994 {
|
|
3995 struct hfbuf buf;
|
|
3996 struct hfkeymap keymap;
|
|
3997
|
|
3998 buf.hf_bufp = (char *)&keymap;
|
|
3999 buf.hf_buflen = sizeof (keymap);
|
|
4000 keymap.hf_nkeys = 2;
|
|
4001 keymap.hfkey[0].hf_kpos = 15;
|
|
4002 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE;
|
|
4003 #ifdef IBMR2AIX
|
|
4004 keymap.hfkey[0].hf_keyidh = '<';
|
|
4005 #else /* not IBMR2AIX */
|
|
4006 keymap.hfkey[0].hf_page = '<';
|
|
4007 #endif /* not IBMR2AIX */
|
|
4008 keymap.hfkey[0].hf_char = 127;
|
|
4009 keymap.hfkey[1].hf_kpos = 15;
|
|
4010 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT;
|
|
4011 #ifdef IBMR2AIX
|
|
4012 keymap.hfkey[1].hf_keyidh = '<';
|
|
4013 #else /* not IBMR2AIX */
|
|
4014 keymap.hfkey[1].hf_page = '<';
|
|
4015 #endif /* not IBMR2AIX */
|
|
4016 keymap.hfkey[1].hf_char = 127;
|
|
4017 hftctl (0, HFSKBD, &buf);
|
|
4018 }
|
|
4019 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
|
|
4020 at times. */
|
|
4021 line_ins_del_ok = char_ins_del_ok = 0;
|
|
4022 }
|
|
4023
|
|
4024 /* Reset the rubout key to backspace. */
|
|
4025
|
|
4026 hft_reset ()
|
|
4027 {
|
|
4028 struct hfbuf buf;
|
|
4029 struct hfkeymap keymap;
|
|
4030 int junk;
|
|
4031
|
|
4032 #ifdef IBMR2AIX
|
|
4033 if (ioctl (0, HFQERROR, &junk) < 0)
|
|
4034 return;
|
|
4035 #else /* not IBMR2AIX */
|
|
4036 if (ioctl (0, HFQEIO, 0) < 0)
|
|
4037 return;
|
|
4038 #endif /* not IBMR2AIX */
|
|
4039
|
|
4040 buf.hf_bufp = (char *)&keymap;
|
|
4041 buf.hf_buflen = sizeof (keymap);
|
|
4042 keymap.hf_nkeys = 2;
|
|
4043 keymap.hfkey[0].hf_kpos = 15;
|
|
4044 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE;
|
|
4045 #ifdef IBMR2AIX
|
|
4046 keymap.hfkey[0].hf_keyidh = '<';
|
|
4047 #else /* not IBMR2AIX */
|
|
4048 keymap.hfkey[0].hf_page = '<';
|
|
4049 #endif /* not IBMR2AIX */
|
|
4050 keymap.hfkey[0].hf_char = 8;
|
|
4051 keymap.hfkey[1].hf_kpos = 15;
|
|
4052 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT;
|
|
4053 #ifdef IBMR2AIX
|
|
4054 keymap.hfkey[1].hf_keyidh = '<';
|
|
4055 #else /* not IBMR2AIX */
|
|
4056 keymap.hfkey[1].hf_page = '<';
|
|
4057 #endif /* not IBMR2AIX */
|
|
4058 keymap.hfkey[1].hf_char = 8;
|
|
4059 hftctl (0, HFSKBD, &buf);
|
|
4060 }
|
|
4061
|
|
4062 #endif /* AIX */
|