1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
/*
* PCBIN.C - binary IO for PPC
*
* Source Version: 2.0
* Software Release #92-0043
*
*/
#include "cpyright.h"
#include "ppc.h"
#define N_TYPES 7
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* _PC_PR_FLUSH - flush function to hang on the io_flush_hook */
int _PC_pr_flush(fp)
FILE *fp;
{PROCESS *pp;
pp = (PROCESS *) fp;
PC_flush(pp);
return(FALSE);}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* _PC_PR_TELL - a no-op tell to hang on the io_tell_hook */
long _PC_pr_tell(fp)
FILE *fp;
{return(0L);}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* _PC_PR_SEEK - a no-op seek to hang on the io_seek_hook */
int _PC_pr_seek(stream, offset, whence)
FILE *stream;
long offset;
int whence;
{return(0);}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* _PC_PR_READ_A - a read function to hang on the io_read_hook sometimes */
size_t _PC_pr_read_a(ptr, size, nitems, pp)
byte *ptr;
size_t size, nitems;
PROCESS *pp;
{char *s;
s = PC_gets(ptr, size*nitems, pp);
if (s != NULL)
PRINT(stdout, "| %s", s);
return(s == NULL ? 0 : strlen(s));}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* _PC_PR_READ_B - a read function to hang on the io_read_hook sometimes */
size_t _PC_pr_read_b(ptr, size, nitems, pp)
byte *ptr;
size_t size, nitems;
PROCESS *pp;
{unsigned char *cp;
long ni;
size_t len;
len = size*nitems;
cp = (unsigned char *) ptr;
/* vacuum anything left in the PROCESS ring into the buffer */
/* copy the output to the buffer */
ni = _PC_buffer_out((char *) cp, pp, len, TRUE);
len -= ni;
cp += ni;
while (TRUE)
{ni = read(pp->in, (char *) cp, len);
if (ni < 0)
continue;
/* if not enough note what has come and get some more */
if (ni < len)
{len -= ni;
cp += ni;}
/* buffer up anything left over */
else if (ni > len)
{cp += len;
ni -= len;
_PC_buffer_in((char *) cp, ni, pp);
break;}
/* if right on quit while ahead */
else
break;};
return(nitems);}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* _PC_PR_WRITE - a write function to hang on the io_write_hook */
size_t _PC_pr_write(ptr, size, nitems, pp)
byte *ptr;
size_t size, nitems;
PROCESS *pp;
{size_t ni, len;
len = size*nitems;
ni = write(pp->out, ptr, len);
return(ni/size);}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* PC_RECV_FORMATS - receive binary formats from the given PROCESS */
int PC_recv_formats(pp)
PROCESS *pp;
{long nc;
char s[LRG_TXT_BUFFER+2];
PC_ERR_TRAP(FALSE);
PC_block(pp);
PC_set_attr(pp, PC_LINE, TRUE);
for (nc = 0; nc < LRG_TXT_BUFFER; nc = strlen(s))
{if (PC_status(pp) != RUNNING)
PC_error("PROCESS NOT RUNNING %d %d - PC_RECV_FORMATS",
pp->status, pp->reason);
PC_gets(s+nc, MAXLINE, pp);
if (strcmp(s+nc, "END FORMATS\n") == 0)
break;};
_PD_rd_prim_extras(pp->vif, ' ', '\f', s);
PC_unblock(pp);
return(TRUE);}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* PC_SEND_FORMATS - send binary formats to the parent PROCESS connected
* - to standard in and out
*/
int PC_send_formats()
{PFSize_t writeh;
PFInt flushh;
FILE *fp;
extern char *_PD_tbuffer;
fp = stdout;
fflush(fp);
SC_setbuf(fp, NULL);
/* remember the I/O hooks */
writeh = io_write_hook;
flushh = io_flush_hook;
/* reset the I/O hooks */
io_write_hook = (PFSize_t) fwrite;
io_flush_hook = (PFInt) fflush;
if ((PC_terminal == NULL) || (PC_terminal->vif == NULL))
{io_write_hook = writeh;
io_flush_hook = flushh;
return(FALSE);};
_PD_wr_prim_extras(fp, PC_terminal->vif->chart, ' ', '\f');
io_write(_PD_tbuffer, 1, strlen(_PD_tbuffer), fp);
io_flush(fp);
/* restore the I/O hooks */
io_write_hook = writeh;
io_flush_hook = flushh;
PRINT(fp, "END FORMATS\n");
return(TRUE);}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* _PC_BIN_READ - do binary read from a PROCESS */
int _PC_bin_read(ptr, type, nitems, pp)
byte *ptr;
char *type;
size_t nitems;
PROCESS *pp;
{PDBfile *file;
int ni;
syment *ep;
PFfflush flushh;
PFfseek seekh;
PFftell tellh;
PFfread readh;
file = pp->vif;
switch (setjmp(_PD_read_err))
{case ABORT : return(FALSE);
case ERR_FREE : return(TRUE);
default : memset(PD_err, 0, MAXLINE);
break;};
ep = _PD_mk_syment(type, nitems, 0L, NULL, NULL);
/* remember the I/O hooks */
flushh = io_flush_hook;
tellh = io_tell_hook;
seekh = io_seek_hook;
readh = io_read_hook;
/* reset the I/O hooks */
io_flush_hook = (PFfflush) _PC_pr_flush;
io_tell_hook = (PFftell) _PC_pr_tell;
io_seek_hook = (PFfseek) _PC_pr_seek;
io_read_hook = (PFfread) _PC_pr_read_b;
ni = _PD_rd_syment(file, ep, type, ptr);
_PD_rl_syment(ep);
/* restore the I/O hooks */
io_flush_hook = flushh;
io_tell_hook = tellh;
io_read_hook = readh;
io_seek_hook = seekh;
return((int) ni);}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* _PC_BIN_WRITE - do binary write to a PROCESS */
int _PC_bin_write(ptr, type, nitems, pp)
byte *ptr;
char *type;
size_t nitems;
PROCESS *pp;
{PDBfile *file;
int ni;
PFfflush flushh;
PFfseek seekh;
PFftell tellh;
PFfwrite writeh;
file = pp->vif;
switch (setjmp(_PD_write_err))
{case ABORT : return(FALSE);
case ERR_FREE : return(TRUE);
default : memset(PD_err, 0, MAXLINE);
break;};
/* remember the I/O hooks */
flushh = io_flush_hook;
tellh = io_tell_hook;
seekh = io_seek_hook;
writeh = io_write_hook;
/* reset the I/O hooks */
io_flush_hook = (PFfflush) _PC_pr_flush;
io_tell_hook = (PFftell) _PC_pr_tell;
io_seek_hook = (PFfseek) _PC_pr_seek;
io_write_hook = (PFfwrite) _PC_pr_write;
ni = _PD_wr_syment(file, ptr, nitems, type, type);
/* restore the I/O hooks */
io_flush_hook = flushh;
io_tell_hook = tellh;
io_write_hook = writeh;
io_seek_hook = seekh;
return(ni);}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
|