--- /Stores/stash/emacs/src-21.1/src/sysdep.c Mon Oct 8 11:02:08 2001 +++ ./src/sysdep.c Sat Feb 2 14:35:50 2002 @@ -60,6 +60,21 @@ #define min(x,y) ((x) > (y) ? (y) : (x)) +#ifdef VMS +/* In this file, open, read and write refer to the system calls, + not our sugared interfaces sys_open, sys_read and sys_write. + Contrariwise, for systems where we use the system calls directly, + define sys_read, etc. here as aliases for them. */ +#ifndef read +#define sys_read read +#define sys_write write +#endif /* `read' is not a macro */ + +#undef read +#undef write + +#endif + #ifdef WINDOWSNT #define read sys_read #define write sys_write @@ -69,9 +84,23 @@ #endif #endif /* not WINDOWSNT */ +#ifdef VMS +#ifndef close +#define sys_close close +#else +#undef close +#endif + +#ifndef open +#define sys_open open +#else /* `open' is a macro */ +#undef open +#endif /* `open' is a macro */ +#endif + /* Does anyone other than VMS need this? */ #ifndef fwrite -#define sys_fwrite fwrite +#define sys_write write #else #undef fwrite #endif @@ -131,6 +160,7 @@ #include #include #include +#include #ifdef __GNUC__ #include #else @@ -141,6 +171,15 @@ #include #endif #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */ +int waiting_for_ast = 1; +unsigned int input_ef = 0; +unsigned int input_eflist = 0; +unsigned int timer_ef = 0; +unsigned int timer_eflist = 0; +unsigned int process_ef = 0; +unsigned int stop_input = 0; +unsigned int ast_queued = 0; +const unsigned __int64 reqidt = 0xdeadbeefdeadbeef; #endif /* VMS */ #ifndef BSD4_1 @@ -1026,7 +1065,11 @@ if (read_socket_hook) return; +#ifndef VMS croak ("request_sigio"); +#else + sys$setast(1); +#endif } void @@ -1035,7 +1078,11 @@ if (read_socket_hook) return; +#ifndef VMS croak ("unrequest_sigio"); +#else + sys$setast(0); +#endif } #endif /* _CX_UX */ @@ -1319,7 +1366,9 @@ input_ef = get_kbd_event_flag (); /* LIB$GET_EF (&input_ef); */ SYS$CLREF (input_ef); +#if 0 waiting_for_ast = 0; +#endif if (!timer_ef) timer_ef = get_timer_event_flag (); /* LIB$GET_EF (&timer_ef); */ @@ -1948,13 +1997,16 @@ queue_kbd_input () { int status; - extern kbd_input_ast (); + extern void kbd_input_ast (); +#if 0 waiting_for_ast = 0; +#endif stop_input = 0; status = SYS$QIO (0, input_fd, IO$_READVBLK, &input_iosb, kbd_input_ast, 1, &input_buffer, 1, 0, terminator_mask, 0, 0); + ast_queued = 1; } int input_count; @@ -1962,16 +2014,315 @@ /* Ast routine that is called when keyboard input comes in in accord with the SYS$QIO above. */ -void kbd_input_ast () { + int old_errno = errno; + + ast_queued = 0; + + if (! stop_input) + { + extern EMACS_TIME *input_available_clear_time; + static struct input_event buf[4096]; + register int passes = -1; + + if (input_available_clear_time) + EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); + +#ifdef ASTDEBUG + fprintf (stderr, "ASTDEBUG: AST occured!\n"); +#endif + + while (1) + { + register int c = -1; + register int nread = 0; + int i; + + passes++; + + if (read_socket_hook) + nread = (*read_socket_hook) (0, buf, 4096, 0, 0); + else + { +#if 0 + if (interrupt_input_blocked) + { + interrupt_input_pending = 1; + return -1; + } + + interrupt_input_pending = 0; +#endif + if (passes == 0) + { +#ifdef ASTDEBUG + input_count++; + if (input_count == 25) + exit (1); + printf ("Ast # %d,", input_count); + printf (" iosb = %x, %x, %x, %x", + input_iosb.offset, input_iosb.status, + input_iosb.termlen, input_iosb.term); +#endif + if (input_iosb.offset) + { + c = input_buffer; +#ifdef ASTDEBUG + printf (", char = 0%o", c); +#endif + } +#ifdef ASTDEBUG + printf ("\n"); + fflush (stdout); + sleep (1); +#endif + queue_kbd_input (); + } + if (c >= 0) + { + extern int meta_key; /* in keyboard.c */ + + nread = 1; + buf->kind = ascii_keystroke; + buf->modifiers = 0; + if (meta_key == 1 && (c & 0x80)) + buf->modifiers = meta_modifier; + if (meta_key != 2) + c &= ~0x80; + + XSET (buf->code, Lisp_Int, c); +#ifdef MULTI_FRAME + XSETFRAME (buf->frame_or_window, selected_frame); +#else + buf->frame_or_window = Qnil; +#endif + } + } + + /* Scan the chars for C-g and store them in kbd_buffer. */ + for (i = 0; i < nread; i++) + { +#ifdef ASTDEBUG + { + extern Lisp_Object Qexternal_debugging_output; + + switch (buf[i].kind) + { + case no_event: + fprintf (stderr, "ASTDEBUG: buf[%d] = no event\n", i); + break; + case ascii_keystroke: + fprintf (stderr, + "ASTDEBUG: buf[%d] = ASCII keystroke with\n", i); + fprintf (stderr, " .code = "); + Fprin1 (buf[i].code, Qexternal_debugging_output); + fprintf (stderr, "\n"); + fprintf (stderr, " .frame_or_window = "); + Fprin1 (buf[i].frame_or_window, + Qexternal_debugging_output); + fprintf (stderr, "\n"); + fprintf (stderr, + " .timestamp = %d\n", + buf[i].timestamp); + break; + case non_ascii_keystroke: + fprintf (stderr, + "ASTDEBUG: buf[%d] = keystroke with\n", i); + fprintf (stderr, " .code = "); + Fprin1 (buf[i].code, Qexternal_debugging_output); + fprintf (stderr, "\n"); + fprintf (stderr, + " .modifiers = %d\n", + buf[i].modifiers); + fprintf (stderr, " .frame_or_window = "); + Fprin1 (buf[i].frame_or_window, + Qexternal_debugging_output); + fprintf (stderr, "\n"); + fprintf (stderr, + " .timestamp = %d\n", + buf[i].timestamp); + break; + case mouse_click: + fprintf (stderr, + "ASTDEBUG: buf[%d] = mouse click with\n", i); + fprintf (stderr, " .code = "); + Fprin1 (buf[i].code, Qexternal_debugging_output); + fprintf (stderr, "\n"); + fprintf (stderr, + " .modifiers = %d\n", + buf[i].modifiers); + fprintf (stderr, " .frame_or_window = "); + Fprin1 (buf[i].frame_or_window, + Qexternal_debugging_output); + fprintf (stderr, "\n"); + fprintf (stderr, " .x = "); + Fprin1 (buf[i].x, Qexternal_debugging_output); + fprintf (stderr, "\n"); + fprintf (stderr, " .y = "); + Fprin1 (buf[i].y, Qexternal_debugging_output); + fprintf (stderr, "\n"); + fprintf (stderr, + " .timestamp = %d\n", + buf[i].timestamp); + break; + case scroll_bar_click: + fprintf (stderr, + "ASTDEBUG: buf[%d] = mouse click with\n", i); + fprintf (stderr, " .code = "); + Fprin1 (buf[i].code, Qexternal_debugging_output); + fprintf (stderr, "\n"); + fprintf (stderr, + " .modifiers = %d\n", + buf[i].modifiers); + fprintf (stderr, " .part = "); + switch (buf[i].part) + { + case scroll_bar_above_handle: + fprintf (stderr, "scroll_bar_above_handle\n"); + break; + case scroll_bar_handle: + fprintf (stderr, "scroll_bar_handle\n"); + break; + case scroll_bar_below_handle: + fprintf (stderr, "scroll_bar_below_handle\n"); + break; + } + fprintf (stderr, " .frame_or_window = "); + Fprin1 (buf[i].frame_or_window, + Qexternal_debugging_output); + fprintf (stderr, "\n"); + fprintf (stderr, " .x = "); + Fprin1 (buf[i].x, Qexternal_debugging_output); + fprintf (stderr, "\n"); + fprintf (stderr, " .y = "); + Fprin1 (buf[i].y, Qexternal_debugging_output); + fprintf (stderr, "\n"); + fprintf (stderr, + " .timestamp = %d\n", + buf[i].timestamp); + break; + case selection_request_event: + fprintf (stderr, + "ASTDEBUG: buf[%d] = selection request event with\n", i); + fprintf (stderr, + " .requestor = %u\n", + SELECTION_EVENT_REQUESTOR (&buf[i])); + fprintf (stderr, + " .selection = %u\n", + SELECTION_EVENT_SELECTION (&buf[i])); + fprintf (stderr, + " .target = %u\n", + SELECTION_EVENT_TARGET (&buf[i])); + fprintf (stderr, + " .property = %u\n", + SELECTION_EVENT_PROPERTY (&buf[i])); + fprintf (stderr, + " .time = %u\n", + SELECTION_EVENT_TIME (&buf[i])); + break; + case selection_clear_event: + fprintf (stderr, + "ASTDEBUG: buf[%d] = selection clear event with\n", i); + fprintf (stderr, + " .requestor = %u\n", + SELECTION_EVENT_REQUESTOR (&buf[i])); + fprintf (stderr, + " .selection = %u\n", + SELECTION_EVENT_SELECTION (&buf[i])); + fprintf (stderr, + " .target = %u\n", + SELECTION_EVENT_TARGET (&buf[i])); + fprintf (stderr, + " .property = %u\n", + SELECTION_EVENT_PROPERTY (&buf[i])); + fprintf (stderr, + " .time = %u\n", + SELECTION_EVENT_TIME (&buf[i])); + break; + case delete_window_event: + fprintf (stderr, + "ASTDEBUG: buf[%d] = delete window event with\n", + i); + fprintf (stderr, " .frame_or_window = "); + Fprin1 (buf[i].frame_or_window, + Qexternal_debugging_output); + break; + default: + fprintf (stderr, + "ASTDEBUG: buf[%d] = some odd event with\n", i); + } + } +#endif + kbd_buffer_store_event (&buf[i]); + /* Don't look at input that follows a C-g too closely. + This reduces lossage due to autorepeat on C-g. */ + if (buf[i].kind == ascii_keystroke + && XINT(buf[i].code) == quit_char) + break; + } + + if (nread <= 0) + break; + } + } + { +#ifdef ASTDEBUG + fprintf (stderr, "ASTDEBUG: setting the event flag %d\n", input_ef); +#endif + sys$setef (input_ef); + } + + errno = old_errno; +} + +end_kbd_input () +{ +#ifdef ASTDEBUG + printf ("At end_kbd_input.\n"); + fflush (stdout); + sleep (1); +#endif + if (lib$ast_in_prog ()) /* Don't wait if suspending from kbd_buffer_store_event! */ + { + sys$cancel (input_fd); + return; + } + + if (ast_queued) + { + sys$setast (0); + /* Clear a flag, and tell ast routine above to set it. */ + sys$clref (input_ef); +#if 0 + waiting_for_ast = 1; +#endif + stop_input = 1; + sys$cancel (input_fd); + sys$setast (1); +#if 1 + sys$waitfr (input_ef); +#endif + sys$clref (input_ef); +#if 0 + waiting_for_ast = 0; +#endif + stop_input = 0; + } +} + +void +kbd_input_ast2 () +{ register int c = -1; int old_errno = errno; extern EMACS_TIME *input_available_clear_time; if (waiting_for_ast) SYS$SETEF (input_ef); +#if 0 waiting_for_ast = 0; +#endif input_count++; #ifdef ASTDEBUG if (input_count == 25) @@ -1998,6 +2349,10 @@ if (c >= 0) { struct input_event e; +#ifdef VMS + /* contents are not zero! -Roar */ + bzero(&e,sizeof(e)); +#endif e.kind = ascii_keystroke; XSETINT (e.code, c); e.frame_or_window = selected_frame; @@ -2008,8 +2363,8 @@ errno = old_errno; } -/* Wait until there is something in kbd_buffer. */ +#if 0 void wait_for_kbd_input () { @@ -2050,6 +2405,7 @@ } waiting_for_ast = 0; } +#endif /* Get rid of any pending QIO, when we are about to suspend or when we want to throw away pending input. @@ -2058,7 +2414,7 @@ SYS$SETAST is used to avoid a timing error. */ void -end_kbd_input () +end_kbd_input2 () { #ifdef ASTDEBUG printf ("At end_kbd_input.\n"); @@ -2074,16 +2430,21 @@ SYS$SETAST (0); /* Clear a flag, and tell ast routine above to set it. */ SYS$CLREF (input_ef); +#if 0 waiting_for_ast = 1; +#endif stop_input = 1; SYS$CANCEL (input_fd); SYS$SETAST (1); SYS$WAITFR (input_ef); +#if 0 waiting_for_ast = 0; +#endif } /* Wait for either input available or time interval expiry. */ +#if 0 void input_wait_timeout (timeval) int timeval; /* Time to wait, in seconds */ @@ -2106,12 +2467,13 @@ if (!detect_input_pending ()) { /* No timing error: wait for flag to be set. */ - SYS$CANTIM (1, 0); - if (SYS$SETIMR (timer_ef, time, 0, 1) & 1) /* Set timer */ + SYS$CANTIM (reqidt, 0); + if (SYS$SETIMR (timer_ef, time, 0, reqidt) & 1) /* Set timer */ SYS$WFLOR (timer_ef, timer_eflist); /* Wait for timer expiry or input */ } waiting_for_ast = 0; } +#endif /* The standard `sleep' routine works some other way and it stops working if you have ever quit out of it. @@ -2126,33 +2488,35 @@ LIB$EMUL (&timeval, &large, &zero, time); /* Convert to VMS format */ - SYS$CANTIM (1, 0); - if (SYS$SETIMR (timer_ef, time, 0, 1) & 1) /* Set timer */ + SYS$CANTIM (reqidt, 0); + if (SYS$SETIMR (timer_ef, time, 0, reqidt) & 1) /* Set timer */ SYS$WAITFR (timer_ef); /* Wait for timer expiry only */ } void -init_sigio (fd) - int fd; +init_sigio2 (fd) + int fd; { request_sigio (); } -reset_sigio () +reset_sigio2 () { unrequest_sigio (); } void -request_sigio () +request_sigio2 () { - croak ("request sigio"); + sys$setast(1); +/* croak ("request sigio");*/ } void -unrequest_sigio () +unrequest_sigio2 () { - croak ("unrequest sigio"); + sys$setast(0); +/* croak ("unrequest sigio");*/ } #endif /* VMS */ @@ -2262,7 +2626,11 @@ #ifdef TEXT_END return ((char *) TEXT_END); #else +#ifdef VMS + int etext; +#else extern int etext; +#endif return ((char *) &etext); #endif } @@ -3254,9 +3622,18 @@ if (oflag & O_CREAT) return creat (path, mode); #endif - +#ifdef VMS +turn_on_atimers(0); +#endif +if (0) { +char buf[90]; +printf("dirs %s %s\n",getcwd(buf,90),path); + } while ((rtnval = open (path, oflag, mode)) == -1 && (errno == EINTR)); +#ifdef VMS +turn_on_atimers(1); +#endif return (rtnval); } @@ -3709,7 +4086,11 @@ MKDIR_PROTOTYPE #else int +#ifdef VMS +mkdir2 (dpath, dmode) +#else mkdir (dpath, dmode) +#endif char *dpath; int dmode; #endif @@ -4210,9 +4591,13 @@ #undef read int -sys_read (fildes, buf, nbyte) +sys_read (fildes, buf, nbyte) int fildes; +#ifdef VMS + void *buf; +#else char *buf; +#endif unsigned int nbyte; { return read (fildes, buf, (nbyte < MAXIOSIZE ? nbyte : MAXIOSIZE)); @@ -4250,9 +4635,13 @@ #undef write int -sys_write (fildes, buf, nbytes) +sys_write (fildes, buf, nbytes) int fildes; +#ifndef VMS char *buf; +#else + void *buf; +#endif unsigned int nbytes; { register char *p; @@ -4384,7 +4773,7 @@ #endif int -sys_creat (va_alist) +sys_creat (va_alist) va_dcl { va_list list_incrementer; @@ -4813,7 +5202,7 @@ vaxc$errno = status; return -1; } - free_pages *= 512; + free_pages *= 8192; /* was 512; */ item_code = JPI$_FREP0VA; if (((status = LIB$GETJPI (&item_code, 0, 0, &frep0va)) & 1) == 0) @@ -4873,13 +5262,19 @@ } int -execvp () +execvp2 () { error ("execvp system call not implemented"); return -1; } int +sys_execvp(const char *__file, __char_ptr_const_ptr32 __argv) +{ +decc$execvp(__file,__argv); +} + +int rename (from, to) char *from, *to; { @@ -4979,9 +5374,14 @@ SYS$OPEN (&to_fab, 0, 0); /* This fills in the nam$w_fid fields */ /* Copy these fields into the fib */ +/* fib.fib$r_fid_overlay.fib$w_fid[0] = to_nam.nam$w_fid[0]; fib.fib$r_fid_overlay.fib$w_fid[1] = to_nam.nam$w_fid[1]; fib.fib$r_fid_overlay.fib$w_fid[2] = to_nam.nam$w_fid[2]; +*/ + fib.fib$w_fid[0] = to_nam.nam$w_fid[0]; + fib.fib$w_fid[1] = to_nam.nam$w_fid[1]; + fib.fib$w_fid[2] = to_nam.nam$w_fid[2]; SYS$CLOSE (&to_fab, 0, 0); @@ -5077,7 +5477,7 @@ } long -random () +random2 () { /* Arrange to return a range centered on zero. */ return rand () - (1 << 30); @@ -5272,7 +5672,11 @@ #ifndef BSTRING #ifndef bcmp int -bcmp (b1, b2, length) /* This could be a macro! */ +#ifdef VMS +bcmp2 (b1, b2, length) /* This could be a macro! */ +#else +bcmp (b1, b2, length) /* This could be a macro! */ +#endif register char *b1; register char *b2; register int length; @@ -5295,22 +5699,39 @@ #ifndef HAVE_STRSIGNAL char * -strsignal (code) - int code; +strsignal (signo) + int signo; { char *signame = 0; - if (0 <= code && code < NSIG) + if (0 <= signo && signo < NSIG) { #ifdef VMS - signame = sys_errlist[code]; + signame = sys_errlist[signo]; #else /* Cast to suppress warning if the table has const char *. */ - signame = (char *) sys_siglist[code]; + signame = (char *) sys_siglist[signo]; #endif } return signame; } #endif /* HAVE_STRSIGNAL */ + +#ifdef VMS +fork () +{ + return vfork(); +} + +int +sys_select2 (nfds, rfds, wfds, efds, timeout) + int nfds; + int *rfds, *wfds, *efds; + int *timeout; +{ +return select(nfds, rfds, wfds, efds, timeout); +} + +#endif