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

#include "psap.h"

#ifndef lint
static char *pepyid = "pepy 8.0 #1 (big-screw) of Sat Jun 27 17:49:54 EDT 1992";
#endif

#define	advise	PY_advise

void	advise ();

/* Generated from module UDQPDU */
# line 25 "rcv_udq.py"

#include <stdio.h>
#include "sector1.h"
#undef PEPYPARM
#define PEPYPARM int *

void	adios ();


#define	bitstr2int(arg,val,cnt) \
{ \
    char   *cp; \
 \
    cp = bitstr2strb (arg, &cnt); \
    val = strb2int (cp, cnt); \
    free (cp); \
}


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

/* ARGSUSED */

int	unbuild_UDQPDU_UDQpdu (pe, explicit, len, buffer, parm)
PE	pe;
int	explicit;
int    *len;
char  **buffer;
PEPYPARM parm;
{
#ifdef DEBUG
    (void) testdebug (pe, "UDQPDU.UDQpdu");
#endif

    switch (PE_ID (pe -> pe_class, pe -> pe_id)) {
        case PE_ID (PE_CLASS_CONT, 7):	/* udqpdu */
            {
#ifdef DEBUG
                (void) testdebug (pe, "udqpdu");
#endif

                if (unbuild_UDQPDU_COupdate (pe, 0, NULLIP, NULLVP, (PEPYPARM)parm) == NOTOK)
                    return NOTOK;
            }
            break;

        default:
            advise (NULLCP, "UDQpdu %s%s/%d/0x%x", PEPY_ERR_UNKNOWN_CHOICE,
                    pe_classlist[pe -> pe_class], pe -> pe_form, pe -> pe_id);
            return NOTOK;
    }

    return OK;
}

/* ARGSUSED */

int	unbuild_UDQPDU_COupdate (pe, explicit, len, buffer, parm)
register PE	pe;
int	explicit;
int    *len;
char  **buffer;
PEPYPARM parm;
{
# line 56 "rcv_udq.py"
    
	TEXT_UPDATE	*arg = (TEXT_UPDATE *)parm;

    register PE p0;

#ifdef DEBUG
    (void) testdebug (pe, "UDQPDU.COupdate");
#endif

    if (explicit) {
        if (pe -> pe_class != PE_CLASS_UNIV
                || pe -> pe_form != PE_FORM_CONS
                || pe -> pe_id != PE_CONS_SEQ) {
            advise (NULLCP, "COupdate bad class/form/id: %s/%d/0x%x",
                    pe_classlist[pe -> pe_class], pe -> pe_form, pe -> pe_id);
            return NOTOK;
        }
    }
    else
        if (pe -> pe_form != PE_FORM_CONS) {
            advise (NULLCP, "COupdate bad form: %d", pe -> pe_form);
            return NOTOK;
        }

    if ((p0 = prim2seq (pe)) == NULLPE) {
        advise (NULLCP, "COupdate %s%s", PEPY_ERR_BAD_SEQ,
                pe_error (pe -> pe_errno));
        return NOTOK;
    }
    pe = p0;

    {
        register PE p1;

        if ((p1 = first_member (pe)) != NULLPE) {
            p0 = p1;

            {	/* coName */
#ifdef DEBUG
                (void) testdebug (p1, "coName");
#endif

                if (parse_UNIV_PrintableString (p1, 1, NULLIP, &(arg->updates.co_list.co_name), NullParm) == NOTOK)
                    return NOTOK;
            }
        }
        else {
            advise (NULLCP, "COupdate %scoName element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }

    {
        register PE p2;

        if ((p2 = (pe != p0 ? next_member (pe, p0) : first_member (pe))) != NULLPE) {
            p0 = p2;

            {	/* objectUpdate */
#ifdef DEBUG
                (void) testdebug (p2, "objectUpdate");
#endif

                switch (PE_ID (p2 -> pe_class, p2 -> pe_id)) {
                    case PE_ID (PE_CLASS_CONT, 0):	/* characterUpdate */
                        {
#ifdef DEBUG
                            (void) testdebug (p2, "characterUpdate");
#endif

                            if (parse_UNIV_PrintableString (p2, 0, NULLIP, &(arg->updates.co_list.co_cmd.char_update), NullParm) == NOTOK)
                                return NOTOK;
                            {
# line 67 "rcv_udq.py"
arg->updates.co_list.co_type = 0;
                            }
                        }
                        break;
                    case PE_ID (PE_CLASS_CONT, 1):	/* booleanUpdate */
                        {
                            register PE p3;

#ifdef DEBUG
                            (void) testdebug (p2, "booleanUpdate");
#endif

                            if ((p3 = prim2seq (p2)) == NULLPE) {
                                advise (NULLCP, "booleanUpdate %s%s", PEPY_ERR_BAD_SEQ,
                                        pe_error (p2 -> pe_errno));
                                return NOTOK;
                            }
                            p2 = p3;

                            {
                                register PE p4;

                                if ((p4 = first_member (p2)) != NULLPE) {
                                    p3 = p4;

                                    {	/* values */
                                        register PE p5;

#ifdef DEBUG
                                        (void) testdebug (p4, "values");
#endif

                                        if ((p5 = prim2bit (p4)) == NULLPE) {
                                            advise (NULLCP, "values %s%s", PEPY_ERR_BAD_BITS,
                                                    pe_error (p4 -> pe_errno));
                                            return NOTOK;
                                        }
                                        arg->updates.co_list.co_cmd.bool_update.value  = bitstr2strb (p4, &( arg->updates.co_list.co_cmd.bool_update.val_count));
                                    }
                                }
                                else {
                                    advise (NULLCP, "booleanUpdate %svalues element", PEPY_ERR_MISSING);
                                    return NOTOK;
                                }

                            }

                            {
                                register PE p6;

                                if ((p6 = (p2 != p3 ? next_member (p2, p3) : first_member (p2))) != NULLPE) {
                                    p3 = p6;

                                    {	/* mask */
                                        register PE p7;

#ifdef DEBUG
                                        (void) testdebug (p6, "mask");
#endif

                                        if ((p7 = prim2bit (p6)) == NULLPE) {
                                            advise (NULLCP, "mask %s%s", PEPY_ERR_BAD_BITS,
                                                    pe_error (p6 -> pe_errno));
                                            return NOTOK;
                                        }
                                        arg->updates.co_list.co_cmd.bool_update.mask  = bitstr2strb (p6, &( arg->updates.co_list.co_cmd.bool_update.mask_count));
                                    }
                                }
                                else {
                                    advise (NULLCP, "booleanUpdate %smask element", PEPY_ERR_MISSING);
                                    return NOTOK;
                                }

                            }


                            if (p2 -> pe_cardinal > 2) {
                                advise (NULLCP, "booleanUpdate %s(2): %d", PEPY_ERR_TOO_MANY_ELEMENTS,
                                        p2 -> pe_cardinal);
                                return NOTOK;
                            }
                            {
# line 76 "rcv_udq.py"
arg->updates.co_list.co_type = 1;
                            }
                        }
                        break;
                    case PE_ID (PE_CLASS_CONT, 2):	/* symbolicUpdate */
                        {
                            register integer p8;

#ifdef DEBUG
                            (void) testdebug (p2, "symbolicUpdate");
#endif

                            if ((p8 = prim2num (p2)) == NOTOK
                                    && p2 -> pe_errno != PE_ERR_NONE) {
                                advise (NULLCP, "symbolicUpdate %s%s", PEPY_ERR_BAD_INTEGER,
                                        pe_error (p2 -> pe_errno));
                                return NOTOK;
                            }
                            arg->updates.co_list.co_cmd.sym_update = p8;
                            {
# line 80 "rcv_udq.py"
arg->updates.co_list.co_type = 2;
                            }
                        }
                        break;
                    case PE_ID (PE_CLASS_CONT, 3):	/* integerUpdate */
                        {
                            register integer p9;

#ifdef DEBUG
                            (void) testdebug (p2, "integerUpdate");
#endif

                            if ((p9 = prim2num (p2)) == NOTOK
                                    && p2 -> pe_errno != PE_ERR_NONE) {
                                advise (NULLCP, "integerUpdate %s%s", PEPY_ERR_BAD_INTEGER,
                                        pe_error (p2 -> pe_errno));
                                return NOTOK;
                            }
                            arg->updates.co_list.co_cmd.int_update = p9;
                            {
# line 84 "rcv_udq.py"
arg->updates.co_list.co_type = 3;
                            }
                        }
                        break;
                    case PE_ID (PE_CLASS_CONT, 4):	/* bitStringUpdate */
                        {
                            register PE p10;

#ifdef DEBUG
                            (void) testdebug (p2, "bitStringUpdate");
#endif

                            if ((p10 = prim2bit (p2)) == NULLPE) {
                                advise (NULLCP, "bitStringUpdate %s%s", PEPY_ERR_BAD_BITS,
                                        pe_error (p2 -> pe_errno));
                                return NOTOK;
                            }
                            {
# line 87 "rcv_udq.py"
 bitstr2int (p10,
				       arg->updates.co_list.co_cmd.bit_update.bitstring,
				       arg->updates.co_list.co_cmd.bit_update.bitcount);
			arg->updates.co_list.co_type = 4;
                            }
                        }
                        break;

                    default:
                        advise (NULLCP, "objectUpdate %s%s/%d/0x%x", PEPY_ERR_UNKNOWN_CHOICE,
                                pe_classlist[p2 -> pe_class], p2 -> pe_form, p2 -> pe_id);
                        return NOTOK;
                }
            }
        }
        else {
            advise (NULLCP, "COupdate %sobjectUpdate element", PEPY_ERR_MISSING);
            return NOTOK;
        }

    }


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

    return OK;
}
