/* ps2pe.c - presentation stream to presentation element */
static char *rcsid
= "$Header: /f/osi/psap/RCS/ps2pe.c,v 7.3 91/02/22 09:36:30 mrose Interim $";
* $Header: /f/osi/psap/RCS/ps2pe.c,v 7.3 91/02/22 09:36:30 mrose Interim $
* Revision 7.3 91/02/22 09:36:30 mrose
* Revision 7.2 91/01/07 12:40:32 mrose
* Revision 7.1 90/07/27 08:47:25 mrose
* Revision 7.0 89/11/23 22:13:18 mrose
* 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
PE
ps2pe_aux (ps
, top
, all
)
register PElementLen len
;
if (top
&& ps_prime (ps
, 0) == NOTOK
)
if (ps_read_id (ps
, top
, &class, &form
, &id
) == NOTOK
)
if ((pe
= pe_alloc (class, form
, id
)) == NULLPE
)
return ps_seterr (ps
, PS_ERR_NMEM
, NULLPE
);
if (ps_read_len (ps
, &pe
-> pe_len
) == NOTOK
)
if (len
== PE_LEN_INDF
) {
(void) ps_seterr (ps
, PS_ERR_INDF
, NULLPE
);
if (ps
-> ps_inline
) { /* "ultra-efficiency"... */
if (ps
-> ps_base
== NULLCP
|| ps
-> ps_cnt
< len
) {
(void) ps_seterr (ps
, PS_ERR_EOF
, NULLPE
);
pe
-> pe_prim
= (PElementData
) ps
-> ps_ptr
;
ps
-> ps_ptr
+= len
, ps
-> ps_cnt
-= len
;
if ((pe
-> pe_prim
= PEDalloc (len
)) == NULLPED
) {
(void) ps_seterr (ps
, PS_ERR_NMEM
, NULLPE
);
if (ps_read (ps
, pe
-> pe_prim
, len
) == NOTOK
) {
SLOG (psap_log
, LLOG_DEBUG
, NULLCP
,
("error reading primitive, %d bytes: %s",
len
, ps_error (ps
-> ps_errno
)));
if (len
!= 0 && ps_read_cons (ps
, &pe
-> pe_cons
, len
) == NOTOK
)
if (top
&& ps_prime (ps
, -1) == NOTOK
)
if (psap_log
-> ll_events
& LLOG_DEBUG
) {
LLOG (psap_log
, LLOG_PDUS
, ("PE read thus far"));
pe2text (psap_log
, pe
, 1, NOTOK
);
static int pe_id_overshift
= PE_ID_MASK
<< (PE_ID_BITS
- PE_ID_SHIFT
);
int ps_read_id (ps
, top
, class, form
, id
)
register PElementClass
*class;
register PElementForm
*form
;
if (ps_read (ps
, &c
, 1) == NOTOK
) {
if (top
&& ps
-> ps_errno
== PS_ERR_EOF
)
ps
-> ps_errno
= PS_ERR_NONE
;
SLOG (psap_log
, LLOG_DEBUG
, NULLCP
,
("error reading initial octet: %s", ps_error (ps
-> ps_errno
)));
*class = (c
& PE_CLASS_MASK
) >> PE_CLASS_SHIFT
;
*form
= (c
& PE_FORM_MASK
) >> PE_FORM_SHIFT
;
for (j
= 0;; j
<<= PE_ID_SHIFT
) {
if (ps_read (ps
, &d
, 1) == NOTOK
) {
if (ps
-> ps_errno
== PS_ERR_EOF
)
ps
-> ps_errno
= PS_ERR_EOFID
;
return ps_seterr (ps
, PS_ERR_OVERID
, NOTOK
);
DLOG (psap_log
, LLOG_DEBUG
, ("class=%d form=%d id=%d",*class, *form
, *id
));
int ps_read_len (ps
, len
)
register PElementLen
*len
;
if (ps_read (ps
, &c
, 1) == NOTOK
) {
SLOG (psap_log
, LLOG_DEBUG
, NULLCP
,
("error reading initial length octet: %s",
ps_error (ps
-> ps_errno
)));
if ((i
= c
) & PE_LEN_XTND
) {
if ((i
&= PE_LEN_MASK
) > sizeof (PElementLen
))
return ps_seterr (ps
, PS_ERR_OVERLEN
, NOTOK
);
if (ps_read (ps
, &c
, 1) == NOTOK
) {
if (ps
-> ps_errno
== PS_ERR_EOF
)
ps
-> ps_errno
= PS_ERR_EOFLEN
;
j
= (j
<< 8) | (c
& 0xff);
SLOG (psap_log
, LLOG_DEBUG
, NULLCP
, ("len=%d", *len
));
int ps_read_cons (ps
, pe
, len
)
register PElementLen len
;
cc
= ps
-> ps_byteno
+ len
;
if ((p
= ps2pe_aux (ps
, 0, 1)) == NULLPE
) {
LLOG (psap_log
, LLOG_DEBUG
,
("error building indefinite constructor, %s",
ps_error (ps
-> ps_errno
)));
LLOG (psap_log
, LLOG_DEBUG
,
("error building constructor, stream at %d, wanted %d: %s",
ps
-> ps_byteno
, cc
, ps_error (ps
-> ps_errno
)));
if (len
== PE_LEN_INDF
) {
if (p
-> pe_class
== PE_CLASS_UNIV
&& p
-> pe_id
== PE_UNIV_EOC
) {
for (q
= p
; p
= ps2pe_aux (ps
, 0, 1); q
= q
-> pe_next
= p
) {
if (p
-> pe_class
== PE_CLASS_UNIV
&& p
-> pe_id
== PE_UNIV_EOC
) {
for (q
= p
;; q
= q
-> pe_next
= p
) {
if (cc
< ps
-> ps_byteno
)
return ps_seterr (ps
, PS_ERR_LEN
, NOTOK
);
if (cc
== ps
-> ps_byteno
)
if ((p
= ps2pe_aux (ps
, 0, 1)) == NULLPE
)