home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / vmsproc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  17.1 KB  |  783 lines

  1. /* Interfaces to subprocesses on VMS.
  2.    Copyright (C) 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of XEmacs.
  5.  
  6. XEmacs is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by the
  8. Free Software Foundation; either version 2, or (at your option) any
  9. later version.
  10.  
  11. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14. for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with XEmacs; see the file COPYING.  If not, write to the Free
  18. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Synched up with: Not synched with FSF. */
  21.  
  22.  
  23. /*
  24.     Event flag and `select' emulation
  25.  
  26.     0 is never used
  27.     1 is the terminal
  28.     23 is the timer event flag
  29.     24-31 are reserved by VMS
  30. */
  31. #include    <ssdef.h>
  32. #include    <iodef.h>
  33. #include    <dvidef.h>
  34. #include    <clidef.h>
  35. #include    "vmsproc.h"
  36.  
  37. #define        KEYBOARD_EVENT_FLAG        1
  38. #define        TIMER_EVENT_FLAG        23
  39.  
  40. static VMS_PROC_STUFF    procList[MAX_EVENT_FLAGS+1];
  41.  
  42. get_kbd_event_flag ()
  43. {
  44.   /*
  45.     Return the first event flag for keyboard input.
  46.     */
  47.   VMS_PROC_STUFF    *vs = &procList[KEYBOARD_EVENT_FLAG];
  48.  
  49.   vs->busy = 1;
  50.   vs->pid = 0;
  51.   return (vs->eventFlag);
  52. }
  53.  
  54. get_timer_event_flag ()
  55. {
  56.   /*
  57.     Return the last event flag for use by timeouts
  58.     */
  59.   VMS_PROC_STUFF    *vs = &procList[TIMER_EVENT_FLAG];
  60.  
  61.   vs->busy = 1;
  62.   vs->pid = 0;
  63.   return (vs->eventFlag);
  64. }
  65.  
  66. VMS_PROC_STUFF *
  67. get_vms_process_stuff ()
  68. {
  69.   /*
  70.     Return a process_stuff structure
  71.     
  72.     We use 1-23 as our event flags to simplify implementing
  73.     a VMS `select' call. 
  74.     */
  75.   int i;
  76.   VMS_PROC_STUFF *vs;
  77.  
  78.   for (i=1, vs = procList; i<MAX_EVENT_FLAGS; i++, vs++)
  79.     {
  80.       if (!vs->busy)
  81.     {
  82.       vs->busy = 1;
  83.       vs->inputChan = 0;
  84.       vs->pid = 0;
  85.       sys$clref (vs->eventFlag);
  86.       return (vs);
  87.     }
  88.     }
  89.   return ((VMS_PROC_STUFF *)0);
  90. }
  91.  
  92. give_back_vms_process_stuff (vs)
  93.      VMS_PROC_STUFF *vs;
  94. {
  95.   /*
  96.     Return an event flag to our pool
  97.     */
  98.   vs->busy = 0;
  99.   vs->inputChan = 0;
  100.   vs->pid = 0;
  101. }
  102.  
  103. VMS_PROC_STUFF *
  104. get_vms_process_pointer (pid)
  105.      int pid;
  106. {
  107.   /*
  108.     Given a pid, return the VMS_STUFF pointer
  109.     */
  110.   int            i;
  111.   VMS_PROC_STUFF    *vs;
  112.  
  113.   /* Don't search the last one */
  114.   for (i=0, vs=procList; i<MAX_EVENT_FLAGS; i++, vs++)
  115.     {
  116.       if (vs->busy && vs->pid == pid)
  117.     return (vs);
  118.     }
  119.   return ((VMS_PROC_STUFF *)0);
  120. }
  121.  
  122. start_vms_process_read (vs)
  123.      VMS_PROC_STUFF *vs;
  124. {
  125.   /*
  126.     Start an asynchronous  read on a VMS process
  127.     We will catch up with the output sooner or later
  128.     */
  129.   int            status;
  130.   int            ProcAst ();
  131.  
  132.   status = sys$qio (vs->eventFlag, vs->outputChan, IO$_READVBLK,
  133.            vs->iosb, 0, vs,
  134.            vs->inputBuffer, sizeof (vs->inputBuffer), 0, 0, 0, 0);
  135.   if (status != SS$_NORMAL)
  136.     return (0);
  137.   else
  138.     return (1);
  139. }
  140.  
  141. extern int    waiting_for_ast;        /* in sysdep.c */
  142. extern int    timer_ef;
  143. extern int    input_ef;
  144.  
  145. select (nDesc, rdsc, wdsc, edsc, timeOut)
  146.      int nDesc;
  147.      int *rdsc;
  148.      int *wdsc;
  149.      int *edsc;
  150.      int *timeOut;
  151. {
  152.   /* Emulate a select call
  153.      
  154.      We know that we only use event flags 1-23
  155.      
  156.      timeout == 100000 & bit 0 set means wait on keyboard input until
  157.      something shows up.  If timeout == 0, we just read the event
  158.      flags and return what we find.  */
  159.  
  160.   int nfds = 0;
  161.   int status;
  162.   int time[2];
  163.   int delta = -10000000;
  164.   int zero = 0;
  165.   int timeout = *timeOut;
  166.   unsigned long    mask, readMask, waitMask;
  167.  
  168.   if (rdsc)
  169.     readMask = *rdsc << 1;    /* Unix mask is shifted over 1 */
  170.   else
  171.     readMask = 0;        /* Must be a wait call */
  172.  
  173.   sys$clref (KEYBOARD_EVENT_FLAG);
  174.   sys$setast (0);        /* Block interrupts */
  175.   sys$readef (KEYBOARD_EVENT_FLAG, &mask); /* See what is set */
  176.   mask &= readMask;        /* Just examine what we need */
  177.   if (mask == 0)
  178.     {        /* Nothing set, we must wait */
  179.       if (timeout != 0)
  180.     {    /* Not just inspecting... */
  181.       if (!(timeout == 100000 &&
  182.         readMask == (1 << KEYBOARD_EVENT_FLAG)))
  183.         {
  184.           lib$emul (&timeout, &delta, &zero, time);
  185.           sys$setimr (TIMER_EVENT_FLAG, time, 0, 1);
  186.           waitMask = readMask | (1 << TIMER_EVENT_FLAG);
  187.         }
  188.       else
  189.         waitMask = readMask;
  190.       if (waitMask & (1 << KEYBOARD_EVENT_FLAG))
  191.         {
  192.           sys$clref (KEYBOARD_EVENT_FLAG);
  193.           waiting_for_ast = 1; /* Only if reading from 0 */
  194.         }
  195.       sys$setast (1);
  196.       sys$wflor (KEYBOARD_EVENT_FLAG, waitMask);
  197.       sys$cantim (1, 0);
  198.       sys$readef (KEYBOARD_EVENT_FLAG, &mask);
  199.       if (readMask & (1 << KEYBOARD_EVENT_FLAG))
  200.         waiting_for_ast = 0;
  201.     }
  202.     }
  203.   sys$setast (1);
  204.  
  205.   /*
  206.     Count number of descriptors that are ready
  207.     */
  208.   mask &= readMask;
  209.   if (rdsc)
  210.     *rdsc = (mask >> 1);    /* Back to Unix format */
  211.   for (nfds = 0; mask; mask >>= 1)
  212.     {
  213.       if (mask & 1)
  214.     nfds++;
  215.     }
  216.   return (nfds);
  217. }
  218.  
  219. #define    MAX_BUFF    1024
  220.  
  221. write_to_vms_process (vs, buf, len)
  222.      VMS_PROC_STUFF *vs;
  223.      char *buf;
  224.      int len;
  225. {
  226.   /*
  227.     Write something to a VMS process.
  228.     
  229.     We have to map newlines to carriage returns for VMS.
  230.     */
  231.   char        ourBuff[MAX_BUFF];
  232.   short        iosb[4];
  233.   int            status;
  234.   int            in, out;
  235.  
  236.   while (len > 0)
  237.     {
  238.       out = map_nl_to_cr (buf, ourBuff, len, MAX_BUFF);
  239.       status = sys$qiow (0, vs->inputChan, IO$_WRITEVBLK|IO$M_NOFORMAT,
  240.             iosb, 0, 0, ourBuff, out, 0, 0, 0, 0);
  241.       if (status != SS$_NORMAL || (status = iosb[0]) != SS$_NORMAL)
  242.     {
  243.       error ("Could not write to subprocess: %x", status);
  244.       return (0);
  245.     }
  246.       len =- out;
  247.     }
  248.   return (1);
  249. }
  250.  
  251. static
  252. map_nl_to_cr (in, out, maxIn, maxOut)
  253.      char *in;
  254.      char *out;
  255.      int maxIn;
  256.      int maxOut;
  257. {
  258.   /*
  259.     Copy `in' to `out' remapping `\n' to `\r'
  260.     */
  261.   int            c;
  262.   int            o;
  263.  
  264.   for (o=0; maxIn-- > 0 && o < maxOut; o++)
  265.     {
  266.       c = *in++;
  267.       *out++ = (c == '\n') ? '\r' : c;
  268.     }
  269.   return (o);
  270. }
  271.  
  272. clean_vms_buffer (buf, len)
  273.      char *buf;
  274.      int len;
  275. {
  276.   /*
  277.     Sanitize output from a VMS subprocess
  278.     Strip CR's and NULLs
  279.     */
  280.   char        *oBuf = buf;
  281.   char        c;
  282.   int            l = 0;
  283.  
  284.   while (len-- > 0)
  285.     {
  286.       c = *buf++;
  287.       if (c == '\r' || c == '\0')
  288.     ;
  289.       else
  290.     {
  291.       *oBuf++ = c;
  292.       l++;
  293.     }
  294.     }
  295.   return (l);
  296. }
  297.  
  298. /*
  299.     For the CMU PTY driver
  300. */
  301. #define        PTYNAME        "PYA0:"
  302.  
  303. get_pty_channel (inDevName, outDevName, inChannel, outChannel)
  304.      char *inDevName;
  305.      char *outDevName;
  306.      int *inChannel;
  307.      int *outChannel;
  308. {
  309.   int            PartnerUnitNumber;
  310.   int            status;
  311.   struct {
  312.     int    l;
  313.     char    *a;
  314.   } d;
  315.   struct {
  316.     short    BufLen;
  317.     short    ItemCode;
  318.     int    *BufAddress;
  319.     int    *ItemLength;
  320.   } g[2];
  321.     
  322.   d.l = strlen (PTYNAME);
  323.   d.a = PTYNAME;
  324.   *inChannel = 0;        /* Should be `short' on VMS */
  325.   *outChannel = 0;
  326.   *inDevName = *outDevName = '\0';
  327.   status  = sys$assign (&d, inChannel, 0, 0);
  328.   if (status == SS$_NORMAL)
  329.     {
  330.       *outChannel = *inChannel;
  331.       g[0].BufLen = sizeof (PartnerUnitNumber);
  332.       g[0].ItemCode = DVI$_UNIT;
  333.       g[0].BufAddress = &PartnerUnitNumber;
  334.       g[0].ItemLength = (int *)0;
  335.       g[1].BufLen = g[1].ItemCode = 0;
  336.       status = sys$getdviw (0, *inChannel, 0, &g, 0, 0, 0, 0);
  337.       if (status == SS$_NORMAL)
  338.     {
  339.       sprintf (inDevName, "_TPA%d:", PartnerUnitNumber);
  340.       strcpy (outDevName, inDevName);
  341.     }
  342.     }
  343.   return (status);
  344. }
  345.  
  346. VMSgetwd (buf)
  347.      char *buf;
  348. {
  349.   /*
  350.     Return the current directory
  351.     */
  352.   char curdir[256];
  353.   char *getenv ();
  354.   char *s;
  355.   short len;
  356.   int status;
  357.   struct
  358.     {
  359.       int    l;
  360.       char    *a;
  361.     } d;
  362.  
  363.   s = getenv ("SYS$DISK");
  364.   if (s)
  365.     strcpy (buf, s);
  366.   else
  367.     *buf = '\0';
  368.  
  369.   d.l = 255;
  370.   d.a = curdir;
  371.   status = sys$setddir (0, &len, &d);
  372.   if (status & 1)
  373.     {
  374.       curdir[len] = '\0';
  375.       strcat (buf, curdir);
  376.     }
  377. }
  378.  
  379. static
  380. call_process_ast (vs)
  381.      VMS_PROC_STUFF *vs;
  382. {
  383.   sys$setef (vs->eventFlag);
  384. }
  385.  
  386. void
  387. child_setup (in, out, err, new_argv, env)
  388.      int in, out, err;
  389.      char **new_argv;
  390.      char **env;
  391. {
  392.   /* ??? I suspect that maybe this shouldn't be done on VMS.  */
  393.   /* Close Emacs's descriptors that this process should not have.  */
  394.   close_process_descs ();
  395.  
  396.   if (STRINGP (current_buffer->directory))
  397.     chdir (string_data (XSTRING (current_buffer->directory)));
  398. }
  399.  
  400. DEFUN ("call-process-internal", Fcall_process_internal,
  401.        Scall_process_internal, 1, MANY, 0,
  402.   "Call PROGRAM synchronously in a separate process.\n\
  403. Program's input comes from file INFILE (nil means null device, `NLA0:').\n\
  404. Insert output in BUFFER before point; t means current buffer;\n\
  405.  nil for BUFFER means discard it; 0 means discard and don't wait.\n\
  406. Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.\n\
  407. Remaining arguments are strings passed as command arguments to PROGRAM.\n\
  408. This function waits for PROGRAM to terminate, unless BUFFER is 0;\n\
  409. if you quit, the process is killed.")
  410.   (nargs, args)
  411.      int nargs;
  412.      Lisp_Object *args;
  413. {
  414.   /* This function can GC */
  415.   Lisp_Object display, buffer, path;
  416.   char oldDir[512];
  417.   int inchannel, outchannel;
  418.   int len;
  419.   int call_process_ast ();
  420.   struct
  421.     {
  422.       int l;
  423.       char *a;
  424.     } dcmd, din, dout;
  425.   char inDevName[65];
  426.   char outDevName[65];
  427.   short iosb[4];
  428.   int status;
  429.   int SpawnFlags = CLI$M_NOWAIT;
  430.   VMS_PROC_STUFF *vs;
  431.   VMS_PROC_STUFF *get_vms_process_stuff ();
  432.   int fd[2];
  433.   int filefd;
  434.   int pid;
  435.   char buf[1024];
  436.   int speccount = specpdl_depth ();
  437.   unsigned char **new_argv;
  438.   struct buffer *old = current_buffer;
  439.  
  440.   CHECK_STRING (args[0], 0);
  441.  
  442.   if (nargs <= 1 || NILP (args[1]))
  443.     args[1] = build_string ("NLA0:");
  444.   else
  445.     args[1] = Fexpand_file_name (args[1],
  446.                  current_buffer->directory);
  447.  
  448.   CHECK_STRING (args[1], 1);
  449.  
  450.   {
  451.     Lisp_Object tem;
  452.     buffer = tem = args[2];
  453.     if (nargs <= 2)
  454.       buffer = Qnil;
  455.     else if (!(EQ (tem, Qnil) || EQ (tem, Qt) || EQ (tem, Qzero))
  456.       {
  457.     buffer = Fget_buffer (tem);
  458.     CHECK_BUFFER (buffer, 2);
  459.       }
  460.   }
  461.  
  462.   display = nargs >= 3 ? args[3] : Qnil;
  463.  
  464.   {
  465.     /*
  466.     if (args[0] == "*dcl*" then we need to skip pas the "-c",
  467.     else args[0] is the program to run.
  468.     */
  469.     int i;
  470.     int arg0;
  471.     int firstArg;
  472.  
  473.     if (strcmp (string_data (XSTRING (args[0])), "*dcl*") == 0)
  474.       {
  475.     arg0 = 5;
  476.     firstArg = 6;
  477.       }
  478.     else
  479.       {
  480.     arg0 = 0;
  481.     firstArg = 4;
  482.       }
  483.     len = string_length (XSTRING (args[arg0])) + 1;
  484.     for (i = firstArg; i < nargs; i++)
  485.       {
  486.     CHECK_STRING (args[i], i);
  487.     len += string_length (XSTRING (args[i])) + 1;
  488.       }
  489.     new_argv = alloca (len);
  490.     strcpy (new_argv, string_data (XSTRING (args[arg0])));
  491.     for (i = firstArg; i < nargs; i++)
  492.       {
  493.     strcat (new_argv, " ");
  494.     strcat (new_argv, string_data (XSTRING (args[i])));
  495.       }
  496.     dcmd.l = len-1;
  497.     dcmd.a = new_argv;
  498.     
  499.     status = get_pty_channel (inDevName, outDevName, &inchannel, &outchannel);
  500.     if (!(status & 1))
  501.       error ("Error getting PTY channel: %x", status);
  502.     if (INTP (buffer))
  503.       {
  504.     dout.l = strlen ("NLA0:");
  505.     dout.a = "NLA0:";
  506.       }
  507.     else
  508.       {
  509.     dout.l = strlen (outDevName);
  510.     dout.a = outDevName;
  511.       }
  512.  
  513.     vs = get_vms_process_stuff ();
  514.     if (!vs)
  515.       {
  516.     sys$dassgn (inchannel);
  517.     sys$dassgn (outchannel);
  518.     error ("Too many VMS processes");
  519.       }
  520.     vs->inputChan = inchannel;
  521.     vs->outputChan = outchannel;
  522.   }
  523.  
  524.   filefd = open (string_data (XSTRING (args[1])), O_RDONLY, 0);
  525.   if (filefd < 0)
  526.     {
  527.       sys$dassgn (inchannel);
  528.       sys$dassgn (outchannel);
  529.       give_back_vms_process_stuff (vs);
  530.       report_file_error ("Opening process input file", Fcons (args[1], Qnil));
  531.     }
  532.   else
  533.     close (filefd);
  534.  
  535.   din.l = string_length (XSTRING (args[1]));
  536.   din.a = string_data (XSTRING (args[1]));
  537.  
  538.   /*
  539.       Start a read on the process channel
  540.   */
  541.   if (!INTP (buffer))
  542.     {
  543.       start_vms_process_read (vs);
  544.       SpawnFlags = CLI$M_NOWAIT;
  545.     }
  546.   else
  547.     SpawnFlags = 0;
  548.  
  549.   /*
  550.       On VMS we need to change the current directory
  551.       of the parent process before forking so that
  552.       the child inherit that directory.  We remember
  553.       where we were before changing.
  554.   */
  555.   VMSgetwd (oldDir);
  556.   child_setup (0, 0, 0, 0, 0);
  557.   status = lib$spawn (&dcmd, &din, &dout, &SpawnFlags, 0, &vs->pid,
  558.           &vs->exitStatus, 0, call_process_ast, vs);
  559.   chdir (oldDir);
  560.  
  561.   if (status != SS$_NORMAL)
  562.     {
  563.       sys$dassgn (inchannel);
  564.       sys$dassgn (outchannel);
  565.       give_back_vms_process_stuff (vs);
  566.       error ("Error calling LIB$SPAWN: %x", status);
  567.     }
  568.   pid = vs->pid;
  569.  
  570.   if (INTP (buffer))
  571.     {
  572. #if defined (NO_SUBPROCESSES)
  573.       wait_without_blocking ();
  574. #endif
  575.       return Qnil;
  576.     }
  577.  
  578.   record_unwind_protect (call_process_cleanup,
  579.              Fcons (make_number (fd[0]), make_number (pid)));
  580.  
  581.  
  582.   if (BUFFERP (buffer))
  583.     Fset_buffer (buffer);
  584.  
  585.   while (1)
  586.     {
  587.       QUIT;
  588.  
  589.       sys$waitfr (vs->eventFlag);
  590.       if (vs->iosb[0] & 1)
  591.     {
  592.       if (!NILP (buffer))
  593.         {
  594.           vs->iosb[1] = clean_vms_buffer (vs->inputBuffer, vs->iosb[1]);
  595.           InsCStr (vs->inputBuffer, vs->iosb[1]);
  596.         }
  597.       if (!NILP (display) && INTERACTIVE)
  598.         redisplay ();
  599.       QUIT;
  600.       if (!start_vms_process_read (vs))
  601.         break;        /* The other side went away */
  602.     }
  603.       else
  604.     break;
  605.     }
  606.     sys$dassgn (inchannel);
  607.     sys$dassgn (outchannel);
  608.     give_back_vms_process_stuff (vs);
  609.  
  610.   /* Wait for it to terminate, unless it already has.  */
  611.   wait_for_termination (pid);
  612.  
  613.   set_current_buffer (old);
  614.  
  615.   return unbind_to (speccount, Qnil);
  616. }
  617.  
  618. create_process (process, new_argv)
  619.      Lisp_Object process;
  620.      char *new_argv;
  621. {
  622.   int pid, inchannel, outchannel, forkin, forkout;
  623.   char old_dir[512];
  624.   char in_dev_name[65];
  625.   char out_dev_name[65];
  626.   short iosb[4];
  627.   int status;
  628.   int spawn_flags = CLI$M_NOWAIT;
  629.   int child_sig ();
  630.   struct {
  631.     int l;
  632.     char *a;
  633.   } din, dout, dprompt, dcmd;
  634.   VMS_PROC_STUFF *vs;
  635.   VMS_PROC_STUFF *get_vms_process_stuff ();
  636.     
  637.   status = get_pty_channel (in_dev_name, out_dev_name, &inchannel, &outchannel);
  638.   if (!(status & 1))
  639.     {
  640.       remove_process (process);
  641.       error ("Error getting PTY channel: %x", status);
  642.     }
  643.   dout.l = strlen (out_dev_name);
  644.   dout.a = out_dev_name;
  645.   dprompt.l = strlen (DCL_PROMPT);
  646.   dprompt.a = DCL_PROMPT;
  647.  
  648.   if (strcmp (new_argv, "*dcl*") == 0)
  649.     {
  650.       din.l = strlen (in_dev_name);
  651.       din.a = in_dev_name;
  652.       dcmd.l = 0;
  653.       dcmd.a = (char *)0;
  654.     }
  655.   else
  656.     {
  657.       din.l = strlen ("NLA0:");
  658.       din.a = "NLA0:";
  659.       dcmd.l = strlen (new_argv);
  660.       dcmd.a = new_argv;
  661.     }
  662.  
  663.   /* Delay interrupts until we have a chance to store
  664.      the new fork's pid in its process structure */
  665.   sys$setast (0);
  666.  
  667.   vs = get_vms_process_stuff ();
  668.   if (vs == 0)
  669.     {
  670.       sys$setast (1);
  671.       remove_process (process);
  672.       error ("Too many VMS processes");
  673.     }
  674.   vs->inputChan = inchannel;
  675.   vs->outputChan = outchannel;
  676.  
  677.   /* Start a read on the process channel */
  678.   start_vms_process_read (vs);
  679.  
  680.   /* Switch current directory so that the child inherits it. */
  681.   VMSgetwd (old_dir);
  682.   child_setup (0, 0, 0, 0, 0);
  683.  
  684.   status = lib$spawn (&dcmd, &din, &dout, &spawn_flags, 0, &vs->pid,
  685.               &vs->exitStatus, 0, child_sig, vs, &dprompt);
  686.   chdir (old_dir);
  687.  
  688.   if (status != SS$_NORMAL)
  689.     {
  690.       sys$setast (1);
  691.       remove_process (process);
  692.       error ("Error calling LIB$SPAWN: %x", status);
  693.     }
  694.   vs->pid &= 0xffff;        /* It needs to fit in a FASTINT,
  695.                    we don't need the rest of the bits */
  696.   pid = vs->pid;
  697.  
  698.   /*
  699.     ON VMS process->infd holds the (event flag-1)
  700.     that we use for doing I/O on that process.
  701.     `input_wait_mask' is the cluster of event flags
  702.     we can wait on.
  703.     
  704.     Event flags returned start at 1 for the keyboard.
  705.     Since Unix expects descriptor 0 for the keyboard,
  706.     we substract one from the event flag.
  707.     */
  708.   inchannel = vs->eventFlag-1;
  709.  
  710.   /* Record this as an active process, with its channels.
  711.      As a result, child_setup will close Emacs's side of the pipes.  */
  712.   chan_process[inchannel] = process;
  713.   XPROCESS (process)->infd = make_number (inchannel);
  714.   XPROCESS (process)->outfd = make_number (outchannel);
  715.   XPROCESS (process)->flags = make_number (RUNNING);
  716.  
  717.   /* Delay interrupts until we have a chance to store
  718.      the new fork's pid in its process structure */
  719.  
  720. #define    NO_ECHO        "set term/noecho\r"
  721.   sys$setast (0);
  722.   /*
  723.     Send a command to the process to not echo input
  724.     
  725.     The CMU PTY driver does not support SETMODEs.
  726.     */
  727.   write_to_vms_process (vs, NO_ECHO, strlen (NO_ECHO));
  728.  
  729.   XPROCESS (process)->pid = make_number (pid);
  730.   sys$setast (1);
  731. }
  732.  
  733. child_sig (VMS_PROC_STUFF *vs)
  734. {
  735.   int pid;
  736.   Lisp_Object tail, proc;
  737.   struct Lisp_Process *p;
  738.   int old_errno = errno;
  739.  
  740.   pid = vs->pid;
  741.   sys$setef (vs->eventFlag);
  742.  
  743.   for (tail = Vprocess_alist; XSYMBOL (tail) != XSYMBOL (Qnil); tail = XCDR (tail))
  744.     {
  745.       proc = XCDR (XCAR (tail));
  746.       p = XPROCESS (proc);
  747.       if (EQ (p->childp, Qt) && XINT (p->pid) == pid)
  748.     break;
  749.     }
  750.  
  751.   if (XSYMBOL (tail) == XSYMBOL (Qnil))
  752.     return;
  753.  
  754.   child_changed++;
  755.   p->flags = make_number (EXITED | CHANGED);
  756.   /* Truncate the exit status to 24 bits so that it fits in a FASTINT */
  757.   p->reason = make_number ((vs->exitStatus) & 0xffffff);
  758. }
  759.  
  760. void
  761. syms_of_vmsproc (void)
  762. {
  763.   defsubr (&Scall_process_internal);
  764. }
  765.  
  766. void
  767. init_vmsproc (void)
  768. {
  769.   char *malloc ();
  770.   int i;
  771.   VMS_PROC_STUFF *vs;
  772.  
  773.   for (vs=procList, i=0; i<MAX_EVENT_FLAGS+1; i++, vs++)
  774.     {
  775.       vs->busy = 0;
  776.       vs->eventFlag = i;
  777.       sys$clref (i);
  778.       vs->inputChan = 0;
  779.       vs->pid = 0;
  780.     }
  781.   procList[0].busy = 1;        /* Zero is reserved */
  782. }
  783.