|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T d
Length: 3983 (0xf8f)
Types: TextFile
Names: »dg2ps.c«
└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
└─⟦eba4602b1⟧ »./isode-5.0.tar.Z«
└─⟦d3ac74d73⟧
└─⟦this⟧ »isode-5.0/psap/dg2ps.c«
/* dg2ps.c - datagram-backed abstraction for PStreams */
#ifndef lint
static char *rcsid = "$Header: /f/osi/psap/RCS/dg2ps.c,v 6.0 89/03/18 23:38:13 mrose Rel $";
#endif
/*
* $Header: /f/osi/psap/RCS/dg2ps.c,v 6.0 89/03/18 23:38:13 mrose Rel $
*
*
* $Log: dg2ps.c,v $
* Revision 6.0 89/03/18 23:38:13 mrose
* Release 5.0
*
*/
/*
* NOTICE
*
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
* this agreement.
*
*/
/* LINTLIBRARY */
#include <stdio.h>
#include "psap.h"
struct ps_dg {
int ps_fd;
int ps_maxsize;
struct ps_inout {
struct qbuf *pio_qb;
char *pio_ptr;
int pio_cnt;
IFP pio_fnx;
} ps_input,
ps_output;
};
/* \f
*/
static int dg_prime (ps)
register PS ps;
{
struct qbuf *qb;
register struct ps_dg *pt = (struct ps_dg *) ps -> ps_addr;
register struct ps_inout *pi = &pt -> ps_input;
if (pi -> pio_qb != NULL)
free ((char *) pi -> pio_qb);
if ((*pi -> pio_fnx) (pt -> ps_fd, &qb) == NOTOK)
return ps_seterr (ps, PS_ERR_IO, NOTOK);
pi -> pio_qb = qb;
pi -> pio_ptr = qb -> qb_data, pi -> pio_cnt = qb -> qb_len;
return OK;
}
/* ARGSUSED */
static int dg_read (ps, data, n, in_line)
register PS ps;
PElementData data;
PElementLen n;
int in_line;
{
int cc;
register struct ps_dg *pt = (struct ps_dg *) ps -> ps_addr;
register struct ps_inout *pi = &pt -> ps_input;
if ((cc = pi -> pio_cnt) <= 0)
return 0;
if (cc > n)
cc = n;
bcopy (pi -> pio_ptr, (char *) data, cc);
pi -> pio_ptr += cc, pi -> pio_cnt -= cc;
return cc;
}
/* ARGSUSED */
static int dg_write (ps, data, n, in_line)
register PS ps;
PElementData data;
PElementLen n;
int in_line;
{
register struct ps_dg *pt = (struct ps_dg *) ps -> ps_addr;
register struct ps_inout *po = &pt -> ps_output;
if (po -> pio_cnt < n)
return 0;
bcopy ((char *) data, po -> pio_ptr, n);
po -> pio_ptr += n, po -> pio_cnt -= n;
return n;
}
static int dg_flush (ps)
register PS ps;
{
register struct ps_dg *pt = (struct ps_dg *) ps -> ps_addr;
register struct ps_inout *po = &pt -> ps_output;
register struct qbuf *qb = po -> pio_qb;
qb -> qb_len = po -> pio_ptr - qb -> qb_data;
if ((*po -> pio_fnx) (pt -> ps_fd, qb) != qb -> qb_len)
return ps_seterr (ps, PS_ERR_IO, NOTOK);
po -> pio_ptr = qb -> qb_data, po -> pio_cnt = pt -> ps_maxsize;
return OK;
}
static int dg_close (ps)
register PS ps;
{
register struct ps_dg *pt = (struct ps_dg *) ps -> ps_addr;
if (pt == NULL)
return OK;
if (pt -> ps_input.pio_qb)
free ((char *) pt -> ps_input.pio_qb);
if (pt -> ps_output.pio_qb)
free ((char *) pt -> ps_output.pio_qb);
free ((char *) pt);
return OK;
}
/* \f
*/
int dg_open (ps)
register PS ps;
{
ps -> ps_primeP = dg_prime;
ps -> ps_readP = dg_read;
ps -> ps_writeP = dg_write;
ps -> ps_flushP = dg_flush;
ps -> ps_closeP = dg_close;
return OK;
}
int dg_setup (ps, fd, size, rfx, wfx)
register PS ps;
int fd,
size;
IFP rfx,
wfx;
{
register struct ps_dg *pt;
register struct ps_inout *po;
register struct qbuf *qb;
if ((pt = (struct ps_dg *) calloc (1, sizeof *pt)) == NULL)
return ps_seterr (ps, PS_ERR_NMEM, NOTOK);
ps -> ps_addr = (caddr_t) pt;
pt -> ps_fd = fd;
pt -> ps_maxsize = size;
if ((qb = (struct qbuf *) malloc (sizeof *qb
+ (unsigned) pt -> ps_maxsize))
== NULL)
return ps_seterr (ps, PS_ERR_NMEM, NOTOK);
qb -> qb_data = qb -> qb_base;
po = &pt -> ps_output;
po -> pio_qb = qb;
po -> pio_ptr = qb -> qb_data, po -> pio_cnt = pt -> ps_maxsize;
if ((pt -> ps_input.pio_fnx = rfx) == NULLIFP
|| (po -> pio_fnx = wfx) == NULLIFP)
return ps_seterr (ps, PS_ERR_XXX, NOTOK);
return OK;
}