/* automatically generated by pepy 8.0 #1 (big-screw), do not edit! */

#include "psap.h"

#define	advise	PY_advise

void	advise ();

/* Generated from module UNIV */

#ifndef	lint
static char *rcsid = "$Header: /xtel/isode/isode/pepsy/RCS/UNIV.py,v 9.0 1992/06/16 12:24:03 isode Rel $";
#endif

#ifndef PEPYPARM
#define PEPYPARM char *
#endif /* PEPYPARM */
extern PEPYPARM NullParm;

/* ARGSUSED */

int	parse_UNIV_EXTERNAL (pe, explicit, len, buffer, parm)
register PE	pe;
int	explicit;
int    *len;
char  **buffer;
PEPYPARM parm;
{
    register PE p22;

#ifdef DEBUG
    (void) testdebug (pe, "UNIV.EXTERNAL");
#endif

    if (explicit
            && PE_ID (pe -> pe_class, pe -> pe_id)
                    != PE_ID (PE_CLASS_UNIV, 8)) {
        advise (NULLCP, "EXTERNAL %s%s/0x%x", PEPY_ERR_BAD_CLASS,
                pe_classlist[pe -> pe_class], pe -> pe_id);
        return NOTOK;
    }
    if ((p22 = prim2seq (pe)) == NULLPE) {
        advise (NULLCP, "EXTERNAL %s%s", PEPY_ERR_BAD_SEQ,
                pe_error (pe -> pe_errno));
        return NOTOK;
    }
    pe = p22;

    {
        register PE p23;

        if ((p23 = first_member (pe)) != NULLPE
                && PE_ID (p23 -> pe_class, p23 -> pe_id)
                        != PE_ID (PE_CLASS_UNIV, 6))
            p23 = NULLPE;
        if (p23 != NULLPE) {
            p22 = p23;

            {	/* direct-reference */
#ifdef DEBUG
                (void) testdebug (p23, "direct-reference");
#endif

                if (p23 -> pe_class != PE_CLASS_UNIV
                        || p23 -> pe_form != PE_FORM_PRIM
                        || p23 -> pe_id != PE_PRIM_OID) {
                    advise (NULLCP, "direct-reference bad class/form/id: %s/%d/0x%x",
                            pe_classlist[p23 -> pe_class], p23 -> pe_form, p23 -> pe_id);
                    return NOTOK;
                }

                if (prim2oid (p23) == NULLOID) {
                    advise (NULLCP, "direct-reference %s%s", PEPY_ERR_BAD_OID,
                            pe_error (p23 -> pe_errno));
                    return NOTOK;
                }
            }
        }
    }

    {
        register PE p24;

        if ((p24 = (pe != p22 ? next_member (pe, p22) : first_member (pe))) 
                    != NULLPE
                && PE_ID (p24 -> pe_class, p24 -> pe_id)
                        != PE_ID (PE_CLASS_UNIV, 2))
            p24 = NULLPE;
        if (p24 != NULLPE) {
            p22 = p24;

            {	/* indirect-reference */
#ifdef DEBUG
                (void) testdebug (p24, "indirect-reference");
#endif

                if (p24 -> pe_class != PE_CLASS_UNIV
                        || p24 -> pe_form != PE_FORM_PRIM
                        || p24 -> pe_id != PE_PRIM_INT) {
                    advise (NULLCP, "indirect-reference bad class/form/id: %s/%d/0x%x",
                            pe_classlist[p24 -> pe_class], p24 -> pe_form, p24 -> pe_id);
                    return NOTOK;
                }

                if (prim2num (p24) == NOTOK
                        && p24 -> pe_errno != PE_ERR_NONE) {
                    advise (NULLCP, "indirect-reference %s%s", PEPY_ERR_BAD_INTEGER,
                            pe_error (p24 -> pe_errno));
                    return NOTOK;
                }
            }
        }
        else {
            /* set default here using yp -> yp_default */
        }

    }

    {
        register PE p25;

        if ((p25 = (pe != p22 ? next_member (pe, p22) : first_member (pe))) 
                    != NULLPE
                && PE_ID (p25 -> pe_class, p25 -> pe_id)
                        != PE_ID (PE_CLASS_UNIV, 7))
            p25 = NULLPE;
        if (p25 != NULLPE) {
            p22 = p25;

            {	/* data-value-descriptor */
#ifdef DEBUG
                (void) testdebug (p25, "data-value-descriptor");
#endif

                if (parse_UNIV_ObjectDescriptor (p25, 1, NULLIP, NULLVP, NullParm) == NOTOK)
                    return NOTOK;
            }
        }
    }

    {
        register PE p26;

        if ((p26 = (pe != p22 ? next_member (pe, p22) : first_member (pe))) != NULLPE) {
            p22 = p26;

            {	/* encoding */
#ifdef DEBUG
                (void) testdebug (p26, "encoding");
#endif

                switch (PE_ID (p26 -> pe_class, p26 -> pe_id)) {
                    case PE_ID (PE_CLASS_CONT, 0):	/* single-ASN1-type */
                        {
                            register PE p27 = p26;

                            {	/* single-ASN1-type TAG PULLUP */
                                register PE p28;

                                if ((p28 = prim2set (p27)) == NULLPE) {
                                    advise (NULLCP, "single-ASN1-type %ssingle-ASN1-type: %s", PEPY_ERR_BAD,
                                            pe_error (p27 -> pe_errno));
                                    return NOTOK;
                                }
                                if (p28 -> pe_cardinal != 1) {
                                    advise (NULLCP, "single-ASN1-type %s single-ASN1-type: %d", PEPY_ERR_TOO_MANY_TAGGED,
                                            p28 -> pe_cardinal);
                                    return NOTOK;
                                }
                                p27 = first_member (p28);
                            }
                            {
#ifdef DEBUG
                                (void) testdebug (p27, "single-ASN1-type");
#endif

                            }
                        }
                        break;
                    case PE_ID (PE_CLASS_CONT, 1):	/* octet-aligned */
                        {
#ifdef DEBUG
                            (void) testdebug (p26, "octet-aligned");
#endif

                        }
                        break;
                    case PE_ID (PE_CLASS_CONT, 2):	/* arbitrary */
                        {
#ifdef DEBUG
                            (void) testdebug (p26, "arbitrary");
#endif

                            if (prim2bit (p26) == NULLPE) {
                                advise (NULLCP, "arbitrary %s%s", PEPY_ERR_BAD_BITS,
                                        pe_error (p26 -> pe_errno));
                                return NOTOK;
                            }
                        }
                        break;

                    default:
                        advise (NULLCP, "encoding %s%s/%d/0x%x", PEPY_ERR_UNKNOWN_CHOICE,
                                pe_classlist[p26 -> pe_class], p26 -> pe_form, p26 -> pe_id);
                        return NOTOK;
                }
            }
        }
        else {
            advise (NULLCP, "EXTERNAL %sencoding element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }


    if (pe -> pe_cardinal > 4) {
        advise (NULLCP, "EXTERNAL %s(4): %d", PEPY_ERR_TOO_MANY_ELEMENTS,
                pe -> pe_cardinal);
        return NOTOK;
    }

    return OK;
}
