1 /* ***********************************************************
  2    *                                                         *
  3    * Copyright, (C) Honeywell Bull Inc., 1987                *
  4    *                                                         *
  5    * Copyright, (C) Honeywell Information Systems Inc., 1986 *
  6    *                                                         *
  7    *********************************************************** */
  8 
  9 /* HISTORY COMMENTS:
 10   1) change(86-08-27,Flegel), approve(87-07-13,MCR7580),
 11      audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 12      Created from extraction of rcvdata.c
 13   2) change(86-12-10,Flegel), approve(87-07-13,MCR7580),
 14      audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 15      Placed status reply messages into Status buffer .
 16                                                    END HISTORY COMMENTS */
 17 
 18 /* : PROCEDURE FUNCTION (rcvfgdat):
 19 
 20 Receive foreground data and dump it into the foreground terminal data queue
 21 or into the background message queue accordingly.
 22 */
 23 
 24 #include "dos.h"
 25 #include "stdio.h"
 26 #include "ws.h"
 27 #include "alloc.h"
 28 #include "cat.h"
 29 #include "ws_fgb.h"
 30 #include "ws_buf.h"
 31 #include "ws_msg.h"
 32 #include "wsmincap.h"
 33 #include "ws_error.h"
 34 
 35 extern struct fgbstr   *fgbfptr;       /* FG buffer first pointer */
 36 extern struct fgbstr   *fgblptr;       /* FG buffer last pointer */
 37 extern struct fgbstr   *bgbfptr;       /* BG buffer first pointer */
 38 extern struct fgbstr   *bgblptr;       /* BG buffer last pointer */
 39 extern struct fgbstr   *sgbfptr;       /* Status buffer first pointer */
 40 extern struct fgbstr   *sgblptr;       /* Status buffer last pointer */
 41 extern struct allocstr *fgaptr;        /* FG allocation buffer */
 42 extern struct allocstr *bgaptr;        /* BG allocation buffer */
 43 extern int             bgcount;        /* Number of messages in BG buffer */
 44 
 45 rcvfgdat (p_fg_buff_ptr)
 46 struct bstruc *p_fg_buff_ptr;
 47 {
 48 int i;
 49 int length;
 50 struct fgbstr *bufp;
 51 char *p1;
 52 char *f1;
 53 
 54 /* EXTERNAL PROCEDURES */
 55 int  rcvmsg();
 56 char *wsalloc();
 57 
 58 
 59 /* : If no foreground data, return */
 60    if (p_fg_buff_ptr -> bin == p_fg_buff_ptr -> bout)
 61       return (0);
 62 
 63 /* : Allocate space for buffer */
 64    length = p_fg_buff_ptr -> bin - p_fg_buff_ptr -> bout;
 65    if (length < 0)
 66       length += p_fg_buff_ptr ->bsize;
 67 
 68    if (length >WSMINBUF)
 69       length = WSMINBUF;
 70 
 71    if ((p_fg_buff_ptr -> bminor == BG_MESSAGE)
 72       || (p_fg_buff_ptr -> bminor == BG_QUERY)
 73       || (p_fg_buff_ptr -> bminor == STATUS_REPLY))
 74    {
 75       bufp = (struct fgbstr *) wsalloc (bgaptr,length + sizeof(struct fgbstr));
 76    }
 77    else
 78       bufp = (struct fgbstr *) wsalloc (fgaptr,length + sizeof(struct fgbstr));
 79 
 80 /* : If allocation failed, lose the message and return */
 81    if (bufp == NULL)
 82       return (0);
 83 
 84 /* : copy to foreground buffer */
 85    p1    = &bufp->fgb_minor;
 86    *p1++ = p_fg_buff_ptr -> bminor;
 87    f1    = p_fg_buff_ptr -> bout;
 88 
 89    for (i = 0; i < length; i++)
 90    {  *p1++ =  *f1++;
 91       if (f1 > p_fg_buff_ptr -> blast)
 92          f1 = p_fg_buff_ptr -> bfirst;
 93    }
 94 
 95    p_fg_buff_ptr -> bout = f1;
 96    bufp->fgb_length = length;
 97    bufp->fgb_next = NULL;
 98 
 99 /* : Link to previous background message buffer */
100    if ((p_fg_buff_ptr -> bminor == BG_MESSAGE)
101       || (p_fg_buff_ptr -> bminor == BG_QUERY))
102    {  if (bgbfptr == NULL)
103          bgcount = 1;
104       else
105          bgcount++;
106       rcvmsg (bufp, &bgbfptr, &bgblptr);
107    }
108    else if (p_fg_buff_ptr -> bminor == STATUS_REPLY)
109       rcvmsg (bufp, &sgbfptr, &sgblptr);
110 
111 /* : Else link to foreground message buffer */
112    else
113       rcvmsg (bufp, &fgbfptr, &fgblptr);
114 }
115 ^Z