Esempio n. 1
0
/*****************************************************************************
*
*   CharPtr AsnFindPrimName(atp)
*   	returns the string name of an ASN.1 primitive type
*
*****************************************************************************/
NLM_EXTERN CharPtr LIBCALL  AsnFindPrimName (AsnTypePtr atp)
{
	AsnTypePtr atp2;

	atp2 = AsnFindBaseType(atp);
	if (atp2 == NULL)
		return NULL;

	return atp2->type->name;
}
Esempio n. 2
0
/*****************************************************************************
*
*   void AsnEnBinBuf(buf, buflen, aip)
*
*****************************************************************************/
static void LIBCALL AsnEnBinBuf (CharPtr buf, size_t buflen, AsnIoPtr aip, AsnTypePtr atp)
{
    AsnTypePtr atp2;

    atp2 = AsnFindBaseType(atp);
    atp2 = atp2->type;
    AsnEnBinTags(atp2, aip);

    AsnEnBinLen((Uint4)buflen, aip);

    AsnEnBinBytes(buf, (Uint4)buflen, aip);
    return;
}
Esempio n. 3
0
/*****************************************************************************
*
*   CharPtr AsnFindBaseName(atp)
*   	returns the string name of an ASN.1 basic entity
*       returns NULL if not resolved
*       returns NULL if resolves to a primitive type (use AsnFindPrimName)
*
*****************************************************************************/
NLM_EXTERN CharPtr LIBCALL  AsnFindBaseName (AsnTypePtr atp)
{
	AsnTypePtr atp2;

	atp2 = AsnFindBaseType(atp);
	if (atp2 == NULL)
		return NULL;

	if (atp2->name == NULL)
		return NULL;
	else if (IS_UPPER(*atp2->name))
		return atp2->name;
	else
		return NULL;
}
Esempio n. 4
0
/*****************************************************************************
*
*   Int4 AsnLexReadInteger(aip, atp)
*   	expects an INTEGER or ENUMERATED next
*   	assumes none of it has already been read
*   	does not advance to next token
*   	atp points to the definition of this integer for named values
*
*****************************************************************************/
NLM_EXTERN Int4 AsnLexReadInteger (AsnIoPtr aip, AsnTypePtr atp)
{
	Int2 token;
	AsnValxNodePtr avnp;
	AsnTypePtr atp2;

	token = AsnLexWord(aip);      /* read the integer */

	if (token == NUMBER)    /* just a number */
	{
		return AsnLexInteger(aip);
	}

	if (token != IDENT)    /* not number or named value */
	{
		AsnIoErrorMsg(aip, 39, AsnErrGetTypeName(atp->name), aip->linenumber);
		return 0;
	}

			/******************** read a named integer value *********/
	atp2 = AsnFindBaseType(atp);
	if (atp2->branch != NULL)       /* named values */
	{
		avnp = (AsnValxNodePtr) atp2->branch;
		while (avnp != NULL)
		{
			if (StrMatch(avnp->name, aip->word, aip->wordlen))
				return avnp->intvalue;
			avnp = avnp->next;
		}
	}

	if (atp2->type->isa == ENUM_TYPE)   /* enumerated MUST match named value */
	{
		AsnIoErrorMsg(aip, 40, AsnErrGetTypeName(atp->name), aip->linenumber);
		return 0;
	}

		   /******************* could it be a previously defined value? ***/

	AsnIoErrorMsg(aip, 41, AsnErrGetTypeName(atp->name), aip->linenumber);

	return 0;
}
Esempio n. 5
0
/*****************************************************************************
*
*   AsnEnumTypeStr(atp, val)
*       returns string for ennumerated type val or a named integer
*
*****************************************************************************/
NLM_EXTERN CharPtr LIBCALL  AsnEnumTypeStr (AsnTypePtr atp, Int2 val)
{
    AsnValxNodePtr avnp;

    atp = AsnFindBaseType(atp);
    if (atp == NULL)
        return NULL;

    if ((atp->type->isa != ENUM_TYPE) && (atp->type->isa != INTEGER_TYPE))
        return NULL;

	avnp = (AsnValxNodePtr) atp->branch;
	while (avnp != NULL)
	{
		if (val == (Int2) avnp->intvalue)
            return avnp->name;
		else
			avnp = avnp->next;
	}
    return NULL;
}
Esempio n. 6
0
/*****************************************************************************
*
*   Boolean AsnBinBufWrite(aip, atp, buf, buflen)
*
*****************************************************************************/
NLM_EXTERN Boolean LIBCALL AsnBinBufWrite (AsnIoPtr aip, AsnTypePtr atp, CharPtr buf, size_t buflen)
{
    int	isa;
    AsnTypePtr atp2;
    int next_type;

    if (! AsnTypeValidateOut(aip, atp, NULL))
        return FALSE;

    atp2 = AsnFindBaseType(atp);
    isa = atp2->type->isa;
    if (ISA_STRINGTYPE(isa))
        isa = GENERALSTRING_TYPE;

    AsnEnBinTags(atp, aip);	/* put in the tags */

    switch (isa) {
    case GENERALSTRING_TYPE:
    case OCTETS_TYPE:
    case STRSTORE_TYPE:
        AsnEnBinBuf(buf, buflen, aip, atp);
        break;
    default:
        AsnIoErrorMsg(aip, 19, AsnErrGetTypeName(atp->name));
        return FALSE;
    }

    if (atp->tagclass != TAG_NONE)
        AsnEnBinEndIndef(aip);    /* put indefinite encoding */
    next_type = aip->type_indent - 1;   /* end any choices */
    while ((next_type >= 0) &&
            (AsnFindBaseIsa(aip->typestack[next_type].type) == CHOICE_TYPE)) {
        if (aip->typestack[next_type].type->tagclass != TAG_NONE)
            AsnEnBinEndIndef(aip);
        next_type--;
    }
    if (AsnFindBaseIsa(aip->typestack[aip->type_indent - 1].type) == CHOICE_TYPE)
        AsnTypeSetIndent(FALSE, aip, atp);
    return TRUE;
}
Esempio n. 7
0
/*****************************************************************************
*
*	AsnTypePtr AsnLexTReadElementTypeList(aip, amp)
*   	assumes has read first { already
*   	returns token to following element
*
*****************************************************************************/
NLM_EXTERN AsnTypePtr AsnLexTReadElementTypeList (AsnIoPtr aip, AsnModulePtr amp, AsnTypePtr parent)
{
	Int2 token;
	AsnTypePtr atp, atp1, atplast, atp2;
	AsnValxNodePtr avnp;

	token = aip->token;
	atp1 = NULL;
	atplast = NULL;

	if (token != START_STRUCT)
	{
		AsnIoErrorMsg(aip, 37, aip->linenumber);
		return NULL;
	}
	token = AsnLexTWord(aip);
	if (token == COMMENT_TOKEN)
	{
		if (parent != NULL)
			AsnLexTAddTypeComment(aip, &(parent->hints));
		token = AsnLexTWord(aip);
	}

	while (token != END_STRUCT)
	{
		if (atp1 != NULL)        /* not the first */
		{
			if (token != COMMA)
			{
				AsnIoErrorMsg(aip, 66, aip->linenumber);
				return NULL;
			}
			else
			{
				token = AsnLexTWord(aip);
				if (token == COMMENT_TOKEN)
				{
					if (atplast != NULL)
						AsnLexTAddTypeComment(aip, &(atplast->hints));
					token = AsnLexTWord(aip);
				}
			}
		}

		if (token == COMPS_TOKEN)        /* COMPONENTS OF */
		{
			AsnIoErrorMsg(aip, 93, aip->linenumber);
			return NULL;
		}
		else if (token != IDENT)	     /* not named */
		{
			atp = AsnElementTypeNew(NULL);
		}
		else					         /* named Type */
		{
			atp = AsnElementTypeNew(aip);
			token = AsnLexTWord(aip);
			if (token == COMMENT_TOKEN)
			{
				AsnLexTAddTypeComment(aip, &(atp->hints));
				token = AsnLexTWord(aip);
			}
		}
								/* add to chain */
		if (atp1 == NULL)
			atp1 = atp;
		else
			atplast->next = atp;

		token = AsnLexTReadType(aip, amp, atp);

		if (token == OPTIONAL_TOKEN)         /* OPTIONAL */
		{
			atp->optional = TRUE;
			token = AsnLexTWord(aip);
		}
		else if (token == DEFAULT_TOKEN)    /* DEFAULT */
		{
			atp->hasdefault = TRUE;
			avnp = AsnValxNodeNew(NULL, VALUE_ISA_BOOL);
			atp->defaultvalue = avnp;
						/* read the default value */
			atp2 = AsnFindBaseType(atp);

			if (atp2 == NULL)
			{
				AsnIoErrorMsg(aip, 95, AsnErrGetTypeName(atp->name), aip->linenumber);
				return NULL;
			}

			switch (atp2->type->isa)
			{
				case BOOLEAN_TYPE:
					avnp->intvalue = (Int4) AsnLexReadBoolean(aip, atp2);
					break;
				case INTEGER_TYPE:
				case ENUM_TYPE:
					avnp->valueisa = VALUE_ISA_INT;
					avnp->intvalue = AsnLexReadInteger(aip, atp2);
					break;
				case VISIBLESTRING_TYPE:
					avnp->valueisa = VALUE_ISA_PTR;
					avnp->name = (CharPtr) AsnLexReadString(aip, atp2);
					break;
				case REAL_TYPE:
					avnp->valueisa = VALUE_ISA_REAL;
					avnp->realvalue = AsnLexReadReal(aip, atp2);
					break;
				default:
					AsnIoErrorMsg(aip, 94, AsnErrGetTypeName(atp->name));
					return NULL;
			}
			token = AsnLexTWord(aip);
		}
		atplast = atp;

		AsnLexTAddTypeComment(aip, &(atplast->hints));
		if (token == COMMENT_TOKEN)
			token = AsnLexTWord(aip);

	}
	token = AsnLexTWord(aip);   /* read following item */
	if (token == COMMENT_TOKEN)
	{
		if (atplast != NULL)
			AsnLexTAddTypeComment(aip, &(atplast->hints));
		token = AsnLexTWord(aip);
	}
	return atp1;
}
Esempio n. 8
0
/*****************************************************************************
*
*   void AsnTxtBufWrite(aip, atp, buf, buflen)
*
*****************************************************************************/
NLM_EXTERN Boolean LIBCALL AsnTxtBufWrite (AsnIoPtr aip, AsnTypePtr atp, CharPtr buf, size_t buflen)
{
    Int2 isa;
    AsnTypePtr atp2;
    Boolean firstvalue;

    if ((! aip->indent_level) && (aip->typestack[0].type == NULL))
        firstvalue = TRUE;    /* first call to this routine */
    else
        firstvalue = FALSE;

    atp2 = AsnFindBaseType(atp);
    isa = atp2->type->isa;
    if (ISA_STRINGTYPE(isa))
        isa = GENERALSTRING_TYPE;

    switch (isa) {
    case GENERALSTRING_TYPE:
    case OCTETS_TYPE:
    case STRSTORE_TYPE:
        break;
    default:
        AsnIoErrorMsg(aip, 19, AsnErrGetTypeName(atp->name));
        return FALSE;
    }

    if (! AsnTypeValidateOut(aip, atp, NULL))
        return FALSE;

    if (! aip->first[aip->indent_level])
        AsnPrintNewLine(aip);
    else
        aip->first[aip->indent_level] = FALSE;

    atp2 = atp;
    if (firstvalue) {	/* first item, need ::= */
        while ((atp2->name == NULL) || (IS_LOWER(*atp2->name)))
            atp2 = atp2->type;    /* find a Type Reference */
    }

    if (atp2->name != NULL) {
        AsnPrintString(atp2->name, aip);	/* put the element name */
        if (IS_LOWER(*atp2->name))
            AsnPrintChar(' ', aip);
        else
            AsnPrintString(" ::= ", aip);
    }

    switch (isa) {
    case GENERALSTRING_TYPE:
    case STRSTORE_TYPE:
        AsnPrintChar('\"', aip);
        AsnPrintBuf(buf, buflen, aip);
        AsnPrintChar('\"', aip);
        break;
    case OCTETS_TYPE:
        AsnPrintBufOctets(buf, buflen, aip);
        break;
    default:
        AsnIoErrorMsg(aip, 19, AsnErrGetTypeName(atp->name));
        return FALSE;
    }

    if (aip->type_indent) { /* pop out of choice nests */
        if (AsnFindBaseIsa(aip->typestack[aip->type_indent - 1].type) == CHOICE_TYPE) {
            if (aip->type_indent >= 2)
                isa = AsnFindBaseIsa(aip->typestack[aip->type_indent - 2].type);
            else
                isa = NULL_TYPE;    /* just fake it */
            AsnPrintIndent(FALSE, aip);
            AsnTypeSetIndent(FALSE, aip, atp);
        }
    }
    return TRUE;
}
Esempio n. 9
0
/*****************************************************************************
*
*   Boolean AsnBinWrite(aip, atp, valueptr)
*
*****************************************************************************/
NLM_EXTERN Boolean LIBCALL  AsnBinWrite (AsnIoPtr aip, AsnTypePtr atp, DataValPtr dvp)
{
	Int2 isa;
	AsnTypePtr atp2;
	Boolean terminalvalue;
	int next_type;

	terminalvalue = TRUE;   /* most are terminal values */

	if (! AsnTypeValidateOut(aip, atp, dvp))
		return FALSE;

	atp2 = AsnFindBaseType(atp);
	isa = atp2->type->isa;
	if (ISA_STRINGTYPE(isa))
		isa = GENERALSTRING_TYPE;
	
	if (((isa == SEQ_TYPE) || (isa == SET_TYPE) ||
		 (isa == SEQOF_TYPE) || (isa == SETOF_TYPE))
		 && (dvp->intvalue == END_STRUCT))
	{
		AsnEnBinCloseStruct(aip, atp);
		return TRUE;
	}

	AsnEnBinTags(atp, aip);     /* put in the tags */

	if (isa == CHOICE_TYPE)     /* show nothing */
	{
		AsnTypeSetIndent(TRUE, aip, atp);
		return TRUE;
	}

	switch (isa)
	{
		case SEQ_TYPE:
		case SET_TYPE:
		case SEQOF_TYPE:
		case SETOF_TYPE:
			if (dvp->intvalue == START_STRUCT)   /* open brace */
				AsnEnBinOpenStruct(aip, atp);
			else
			{
				AsnIoErrorMsg(aip, 18 );
				return FALSE;
			}
			terminalvalue = FALSE;
			break;
		case BOOLEAN_TYPE:
			AsnEnBinBoolean(dvp->boolvalue, aip, atp);
			break;
		case INTEGER_TYPE:
		case ENUM_TYPE:
			AsnEnBinInteger(dvp->intvalue, aip, atp);
			break;
		case BIGINT_TYPE:
			AsnEnBinBigInt(dvp->bigintvalue, aip, atp);
			break;
		case REAL_TYPE:
			AsnEnBinReal(dvp->realvalue, aip, atp);
			break;
		case GENERALSTRING_TYPE:
			if (! AsnEnBinString((CharPtr) dvp->ptrvalue, aip, atp))
				return FALSE;
			break;
		case NULL_TYPE:
			AsnEnBinNull(aip, atp);
			break;
		case OCTETS_TYPE:
		case STRSTORE_TYPE:
			AsnEnBinOctets((ByteStorePtr) dvp->ptrvalue, aip, atp);
			break;
		default:
			AsnIoErrorMsg(aip, 19, AsnErrGetTypeName(atp->name));
			return FALSE;
	}

	if (terminalvalue)          /* pop out of choice nests */
	{
		if (atp->tagclass != TAG_NONE)
			AsnEnBinEndIndef(aip);    /* put indefinate encoding */
		next_type = aip->type_indent - 1;   /* end any choices */
		while ((next_type >= 0) &&
			(AsnFindBaseIsa(aip->typestack[next_type].type) == CHOICE_TYPE))
		{
			if (aip->typestack[next_type].type->tagclass != TAG_NONE)
				AsnEnBinEndIndef(aip);
			next_type--;
		}
		if (AsnFindBaseIsa(aip->typestack[aip->type_indent - 1].type) == CHOICE_TYPE)
			AsnTypeSetIndent(FALSE, aip, atp);
	}
	return TRUE;
}
Esempio n. 10
0
/*****************************************************************************
*
*   AsnTypePtr AsnTypeFindType(atp, str, typeptr, count, in_it)
*
*****************************************************************************/
NLM_EXTERN AsnTypePtr AsnTypeFindType (AsnTypePtr atp, CharPtr str, AsnTypePtr PNTR typeptr, Int2 count, Boolean in_it)
{
	AsnTypePtr curr, next;
	CharPtr beg;
	Int2 len, isa;
	Boolean is_element,       /* (unamed) element of setof seqof */
		is_type,              /* if a type, must find the original def */
		got_it;
	AsnTypePtr PNTR typenext;
	Int2 newcount;

	if (count < 0)      /* off array ... error condition */
		return NULL;

	beg = str;
	len = 0;
	if (typeptr == NULL)
	{
		typenext = NULL;
		newcount = 0;
	}
	else
	{
		newcount = count - 1;
		if (newcount >= 0)
			typenext = typeptr + 1;
		else
			typenext = NULL;
	}
	is_element = FALSE;
	is_type = FALSE;
	while ((*beg != '.') && (*beg != '\0'))
	{
		beg++; len++;
	}

	if ((*str == 'E') && (len == 1))
		is_element = TRUE;
	else if (IS_UPPER(*str))
		is_type = TRUE;

	curr = atp;			  	/* look at this level */
	while (curr != NULL)
	{
		got_it = FALSE;
		if (is_element)
			got_it = TRUE;
		else if (StrMatch(curr->name, str, len))   /* found it */
		{
			if (! is_type)
				got_it = TRUE;
			else                    /* check that this is the real def */
			{
				if (! curr->imported)
					got_it = TRUE;
			}
		}

		if (got_it)
		{
			if (typeptr != NULL)
				*typeptr = curr;

			if (*beg == '\0')    /* that's it */
				return curr;
			else                 /* go down the path */
			{
				next = AsnFindBaseType(curr);
				isa = next->type->isa;
				if ((next->branch != NULL)   /* go further */
					&& (isa != INTEGER_TYPE)
					&& (isa != ENUM_TYPE))
				{
					next = AsnTypeFindType((AsnTypePtr) next->branch, (beg + 1), typenext, newcount, TRUE);
					if (next != NULL)
						return next;
				}
			}
		}
		curr = curr->next;
	}
	
	if (in_it)     /* processing a path and can't find next node here */
		return NULL;

	curr = atp;           /* start down a level */
	while (curr != NULL)
	{
		if (curr->branch != NULL)
		{
			next = AsnFindBaseType(curr);
			
			if ((next != NULL) && (next->type != NULL))
			{
				isa = next->type->isa;
				if ((next->branch != NULL)   /* go further */
					&& (isa != INTEGER_TYPE)
					&& (isa != ENUM_TYPE))
				{
					next = AsnTypeFindType((AsnTypePtr) next->branch, str, typenext, newcount, FALSE);
					if (next != NULL)
					{
						if (typeptr != NULL)
							*typeptr = curr;
						return next;
					}
				}
			}
			/** else, an error has occurred, unresolved branch **/
		}
		curr = curr->next;
	}
	return NULL;
}
Esempio n. 11
0
/*****************************************************************************
*
*   Boolean AsnTypeValidateOut(aip, atp, dvp)
*   	if not open or closing a SET, SEQ, SETOF, SEQOF, will
*   		put atp in aip->typestack if it validates.
*
*   KNOWN DEFECT:  SET should check for 1 of each non-optional element
*   	It does not right now, it only checks that an element is a valid
*   	member of the SET.
*
*****************************************************************************/
NLM_EXTERN Boolean AsnTypeValidateOut (AsnIoPtr aip, AsnTypePtr atp, DataValPtr dvp)
{
	Int2 isa;
	AsnTypePtr atp2, parent_type, base_type, curr_type;
	Boolean foundit;
	AsnValxNodePtr avnp;

	if ((aip == NULL) || (atp == NULL))
		return FALSE;
		
	curr_type = aip->typestack[aip->type_indent].type;
	base_type = AsnFindBaseType(atp);
	if (base_type == NULL)
	{
		AsnIoErrorMsg(aip, 10, AsnErrGetTypeName(atp->name), "AsnTypeValidateOut");
		return FALSE;
	}
		
	isa = base_type->type->isa;

	if (((isa == SEQ_TYPE) || (isa == SET_TYPE) ||
		 (isa == SEQOF_TYPE) || (isa == SETOF_TYPE))
		 && (dvp->intvalue == END_STRUCT))
	{
		switch (isa)
		{
			case SEQOF_TYPE:
			case SETOF_TYPE:
				break;
			case SEQ_TYPE:       /* check that no more waiting */
				if (curr_type != NULL)   /* check next one */
					atp2 = curr_type->next;
				else                     /* empty sequence written */
					atp2 = (AsnTypePtr) base_type->branch;
				while (atp2 != NULL)
				{
					if (! (atp2->optional || atp2->hasdefault))
					{
						AsnIoErrorMsg(aip, 7, AsnErrGetTypeName(atp2->name), AsnErrGetTypeName(atp->name));
						return FALSE;
					}
					atp2 = atp2->next;
				}
				break;
			default:
				break;
		}
		return TRUE;
	}

	if (aip->type_indent)       /* part of a larger struct */
	{
		foundit = FALSE;
		if (aip->type_indent < 1)
			return FALSE;
			
		parent_type = aip->typestack[aip->type_indent - 1].type;
		base_type = AsnFindBaseType(parent_type);
		if (base_type == NULL)
			return FALSE;
		isa = base_type->type->isa;
		atp2 = (AsnTypePtr) base_type->branch;
		while (atp2 != NULL)
		{
			if (atp2 == atp)
			{
				foundit = TRUE;
				break;
			}
			atp2 = atp2->next;
		}
		if (! foundit)
		{
			atp2 = AsnFindBaseType(atp);
			AsnIoErrorMsg(aip, 22, AsnErrGetTypeName(atp->name),
				AsnErrGetTypeName(atp2->name), AsnErrGetTypeName(parent_type->name));
			return FALSE;
		}
		switch (isa)
		{
			case SETOF_TYPE:       /* just has to be right type */
			case SEQOF_TYPE:
				break;
			case CHOICE_TYPE:      /* can only have one value */
				if (curr_type != NULL)
				{
					AsnIoErrorMsg(aip, 23, AsnErrGetTypeName(parent_type->name),
						AsnErrGetTypeName(atp->name));
					return FALSE;
				}
				break;
			case SET_TYPE:         /* SET should check for 1 of each */
				                   /* non-optional element, but doesn't */
				if (curr_type == atp)
				{
					AsnIoErrorMsg(aip, 24, AsnErrGetTypeName(atp->name),
						AsnErrGetTypeName(parent_type->name));
					return FALSE;
				}
				break;
			case SEQ_TYPE:
				if (curr_type == atp)
				{
					AsnIoErrorMsg(aip, 24, AsnErrGetTypeName(atp->name),
						AsnErrGetTypeName(parent_type->name));
					return FALSE;
				}
				 				 /* check preceeding elements */
				if (curr_type != NULL)
				{
					atp2 = (AsnTypePtr) base_type->branch;
					while (atp2 != curr_type->next)
					{
						if (atp == atp2)
						{
							AsnIoErrorMsg(aip, 6, AsnErrGetTypeName(atp->name),
								AsnErrGetTypeName(parent_type->name));
							return FALSE;
						}
						atp2 = atp2->next;
					}
				}
				else
					atp2 = (AsnTypePtr) base_type->branch;
				while ((atp2 != NULL) && (atp != atp2))
				{
					if (! (atp2->optional || atp2->hasdefault))
					{					/* skipped a non-optional element */
						AsnIoErrorMsg(aip, 7, AsnErrGetTypeName(atp2->name),
							AsnErrGetTypeName(parent_type->name));
						return FALSE;
					}
					atp2 = atp2->next;
				}
				if (atp2 == NULL)  /* element out of order */
				{
					AsnIoErrorMsg(aip, 6, AsnErrGetTypeName(atp->name),
						AsnErrGetTypeName(parent_type->name));
					return FALSE;
				}
				break;
			default:
				AsnIoErrorMsg(aip, 25, AsnErrGetTypeName(parent_type->name),
					parent_type->isa);
				return FALSE;
		}
		base_type = AsnFindBaseType(atp);
		isa = base_type->type->isa;
	}

	if (ISA_STRINGTYPE(isa))
		isa = GENERALSTRING_TYPE;

				/******************* maintain typestack ****************/
	switch (isa)          /* set aip->typestack for non-struct types */
	{					  /* this is done for them in AsnTypeSetIndent() */
		case SEQ_TYPE:
		case SET_TYPE:
		case SEQOF_TYPE:
		case SETOF_TYPE:
		case CHOICE_TYPE:
		default:				   /* terminal value */
			aip->typestack[aip->type_indent].type = atp;
			break;
	}

	switch (isa)          /* check ranges and values */
	{
		case ENUM_TYPE:
			avnp = (AsnValxNodePtr) base_type->branch;
			while (avnp != NULL)
			{
				if (avnp->intvalue == dvp->intvalue)
					return TRUE;
				avnp = avnp->next;
			}
			AsnIoErrorMsg(aip, 12, dvp->intvalue, AsnErrGetTypeName(atp->name));
			return FALSE;
		default :
			break;
	}
	return TRUE;	
}
Esempio n. 12
0
NLM_EXTERN Int2 LIBCALL  AsnTxtReadVal (AsnIoPtr aip, AsnTypePtr atp, DataValPtr valueptr)
{
	Int2 isa, token, retval;
	Boolean terminalvalue;      /* set if read a terminal value */
	AsnTypePtr atp2;
	Boolean read_value;
	DataVal fake_value;
	AsnTypePtr base_type, curr_type;
    PstackPtr currpsp;

	retval = 1;  /* assume success */
    currpsp = & aip->typestack[aip->type_indent];
	curr_type = currpsp->type;

	if (atp == NULL)
		return 0;

	base_type = AsnFindBaseType(atp);     
    if (base_type == NULL)     /* not found */
    {
        base_type = atp;   
        while (base_type->type != NULL)
            base_type = base_type->type;
        if (base_type->imported)
		{
            AsnIoErrorMsg(aip,35, AsnErrGetTypeName(atp->name), base_type->name, aip->linenumber);
			return 0;
		}
       else
		{
            AsnIoErrorMsg(aip,36, AsnErrGetTypeName(atp->name), base_type->name, aip->linenumber);
			return 0;
		}
    }
	isa = base_type->type->isa;

	if (valueptr == NULL)       /* just check the value */
	{
		read_value = FALSE;
		valueptr = &fake_value;
	}
	else
		read_value = TRUE;

	terminalvalue = TRUE;    /* most values are terminal values */

	if (ISA_STRINGTYPE(isa) && isa != UTF8STRING_TYPE)
		isa = GENERALSTRING_TYPE;

	switch (isa)
	{
		case SEQ_TYPE:
		case SET_TYPE:
		case SETOF_TYPE:
		case SEQOF_TYPE:
			terminalvalue = FALSE;  /* handled by AsnTypeSetIndent() */
			if (aip->token != END_STRUCT)   /* should be open brace */
			{
				token = AsnLexWord(aip);    /* read open brace */
				if (token != START_STRUCT)
				{
					AsnIoErrorMsg(aip, 37, aip->linenumber);
					return 0;
				}
				AsnTypeSetIndent(TRUE, aip, atp);  
				retval = START_STRUCT;
				valueptr->intvalue = START_STRUCT;
				terminalvalue = FALSE;
			}
			else
			{			   /* close brace already read in AsnTxtReadId */
				switch (isa)
				{
					case SEQOF_TYPE:
					case SETOF_TYPE:
						break;
					case SEQ_TYPE:       /* check that no more waiting */
        				if (curr_type != NULL)   /* check next one */
		        			atp2 = curr_type->next;
				        else                     /* empty sequence written */
        					atp2 = (AsnTypePtr)base_type->branch;
						while (atp2 != NULL)
						{
							if (! (atp2->optional || atp2->hasdefault))
							{

                                                                AsnIoErrorMsg(aip, 34, AsnErrGetTypeName(atp2->name), base_type->name, aip->linenumber);
								return 0;
							}
							atp2 = atp2->next;
						}
						break;
					default:
						break;
				}
				AsnTypeSetIndent(FALSE, aip, atp);  
				retval = END_STRUCT;
				valueptr->intvalue = END_STRUCT;
			}
			break;
		case CHOICE_TYPE:
			AsnTypeSetIndent(TRUE, aip, atp);  /* nest down to type */
			terminalvalue = FALSE;
			break;
		case BOOLEAN_TYPE:
			valueptr->boolvalue = AsnLexReadBoolean(aip, atp);
			break;
		case INTEGER_TYPE:
		case ENUM_TYPE:
			valueptr->intvalue = AsnLexReadInteger(aip, atp);
			break;
		case BIGINT_TYPE:
			valueptr->bigintvalue = AsnLexReadBigInt(aip, atp);
			break;
		case REAL_TYPE:
			valueptr->realvalue = AsnLexReadReal(aip, atp);
			break;
		case GENERALSTRING_TYPE:
			if (read_value)
			{
				valueptr->ptrvalue = AsnLexReadString(aip, atp);
				if (valueptr->ptrvalue == NULL)
					return 0;
			}
			else
			{
				if (! AsnLexSkipString(aip, atp))
					return 0;
			}
			break;
		case UTF8STRING_TYPE:
			if (read_value)
			{
				valueptr->ptrvalue = AsnLexReadStringUTF8(aip, atp);
				if (valueptr->ptrvalue == NULL)
					return 0;
			}
			else
			{
				if (! AsnLexSkipStringUTF8(aip, atp))
					return 0;
			}
			break;
		case NULL_TYPE:
			AsnLexReadNull(aip, atp);
			break;
		case OCTETS_TYPE:
			if (read_value)
			{
				valueptr->ptrvalue = AsnLexReadOctets(aip, atp);
				if (valueptr->ptrvalue == NULL) return 0;
			}
			else
				AsnLexSkipOctets(aip, atp);
			break;
		case STRSTORE_TYPE:
			if (read_value)
			{
				valueptr->ptrvalue = (ByteStorePtr) AsnLexReadString(aip, atp);
				if (valueptr->ptrvalue == NULL)
					return 0;
			}
			else
			{
				if (! AsnLexSkipString(aip, atp))
					return 0;
			}
			break;
		default:
			AsnIoErrorMsg(aip, 38,  AsnErrGetTypeName(atp->name),aip->linenumber);
			return 0;
	}

	if (terminalvalue)       /* pop out of any CHOICE nests */
	{
		while ((aip->type_indent) &&
			(AsnFindBaseIsa(aip->typestack[aip->type_indent - 1].type) == CHOICE_TYPE))
			AsnTypeSetIndent(FALSE, aip, atp);
	}

	return retval;
}
Esempio n. 13
0
/*****************************************************************************
*
*   AsnTypePtr AsnTxtReadId(aip, amp, atp)
*   	reads identifier for next value
*
*****************************************************************************/
NLM_EXTERN AsnTypePtr LIBCALL  AsnTxtReadId (AsnIoPtr aip, AsnModulePtr amp, AsnTypePtr atp)
{
	Int2 token, isa;
	AsnTypePtr atp2, atp3, atp4;
    PstackPtr currpsp, prevpsp;
	Boolean is_ref;

	if (! aip->type_indent)    /* just starting reading */
	{
		if (atp == NULL)       /* starting an unknown item */
		{
			token = AsnLexWord(aip);
			if (token == EOF_TOKEN)
				return NULL;

			if (token != REF)
			{
				AsnIoErrorMsg(aip, 26, aip->linenumber);
				return NULL;
			}
	
			atp = AsnLexFindType(aip, amp);
			if (atp == NULL)
			{
				AsnIoErrorMsg(aip, 27, aip->linenumber);
				return NULL;
			}

			token = AsnLexWord(aip);
			if (token != ISDEF)
			{
				AsnIoErrorMsg(aip, 28, aip->linenumber);
				return NULL;
			}
		}
		else		   /* reading a known, possibly internal value */
		{
			if ((atp->name != NULL) &&    /* do we need to read a type ref? */
				(IS_UPPER(*atp->name)))
				is_ref = TRUE;
			else
				is_ref = FALSE;

			if ((is_ref) && (aip->scan_for_start))
			{
				token = AsnLexScan(aip, atp->name);  /* scan to start */
				if (token == EOF_TOKEN)
					return NULL;
				if (token != ISDEF)
				{
					AsnIoErrorMsg(aip, 28, aip->linenumber);
					return NULL;
				}
			}
			else if ((is_ref) || (aip->bytes))   /* reading an internal value */
			{
				token = AsnLexWord(aip);
				if (token == EOF_TOKEN)
					return NULL;

				if (! StrMatch(atp->name, aip->word, aip->wordlen))
				{
					AsnIoErrorMsg(aip, 29,AsnErrGetTypeName(atp->name), aip->linenumber);
					return NULL;
				}
				if (token == REF)        /* read of a non-internal value */
				{
					token = AsnLexWord(aip);
					if (token != ISDEF)
					{
						AsnIoErrorMsg(aip, 28, aip->linenumber);
						return NULL;
					}
				}
			}
			
		}

		aip->typestack[0].type = atp;         /* load first type */
		aip->typestack[0].resolved = FALSE;
	
		return atp;
	}

    currpsp = & aip->typestack[aip->type_indent];
    prevpsp = currpsp - 1;

	if (currpsp->type != NULL)   /* reading in a struct */
	{
		token = AsnLexWord(aip);
		switch (token)
		{
			case COMMA:
				break;
			case END_STRUCT:
				return prevpsp->type;

			default:
				AsnIoErrorMsg(aip, 30, aip->linenumber);
				return NULL;
		}
	}

	    /* check for SEQOF and SETOF */
	
	atp = prevpsp->type;
	atp2 = AsnFindBaseType(atp);
	isa = atp2->type->isa;
	if ((isa == SEQOF_TYPE) || (isa == SETOF_TYPE))
	{
		token = AsnLexWord(aip);
        if (token == END_STRUCT)    /* empty set */
            return prevpsp->type;
        aip->tagsaved = TRUE;       /* not empty, note not read */
		atp = (AsnTypePtr) atp2->branch;   /* set of what type? */
		currpsp->type = atp;
		currpsp->resolved = FALSE;
		return atp;   /* no type identifier */
	}
	

	token = AsnLexWord(aip);

	if (token == EOF_TOKEN)
	{
		AsnIoErrorMsg(aip, 17 );
		return NULL;
	}

    if ((token == END_STRUCT) && ((isa == SEQ_TYPE) || (isa == SET_TYPE)))
        return prevpsp->type;   /* empty SET/SEQ */

	if (token != IDENT)
	{
		AsnIoErrorMsg(aip, 31, aip->linenumber);
		return NULL;
	}

	atp = AsnLexFindElement(aip, (AsnTypePtr) atp2->branch);
	if (atp == NULL)
	{
		AsnIoErrorMsg(aip, 32, AsnErrGetTypeName(prevpsp->type->name), aip->linenumber);
		return NULL;
	}

	if (atp2->type->isa == SEQ_TYPE)      /* check sequence order */
	{
		atp3 = currpsp->type;
		if (atp3 != NULL)
		{
			atp4 = (AsnTypePtr) atp2->branch;
			atp3 = atp3->next;
			while (atp4 != atp3)
			{
				if (atp == atp4)
				{
					AsnIoErrorMsg(aip, 33,AsnErrGetTypeName(atp->name), AsnErrGetTypeName(atp2->name), aip->linenumber);
					return NULL;
				}
				atp4 = atp4->next;
			}
		}
		else
			atp3 = (AsnTypePtr) atp2->branch;

		while ((atp3 != NULL) && (atp3 != atp))
		{
			if (! (atp3->optional || atp3->hasdefault))
			{
				AsnIoErrorMsg(aip, 34,AsnErrGetTypeName(atp3->name), AsnErrGetTypeName(atp2->name), aip->linenumber);
				return NULL;
			}
			atp3 = atp3->next;
		}
	}

	currpsp->type = atp;
	currpsp->resolved = FALSE;    /* mark first use */
	return atp;
}
Esempio n. 14
0
/*****************************************************************************
*
*   PrintStackAddItem()
*   	AsnExpOpt callback to add items to print stack
*
*****************************************************************************/
NLM_EXTERN void LIBCALLBACK PrintStackAddItem(AsnExpOptStructPtr aeosp)
{
	PrintFormatItemPtr pfip;
	PrintFormatListPtr pflp, pflp1;
	PrintStackPtr curr, tmp;
	PrintStackItemPtr psip;
	Int2 type_indent, i, j, k, l, start_search;
	PstackPtr pstack;
	AsnTypePtr atp, base;
	Boolean got_one;
	PrintStackListPtr pslp;
	PrintStackListItemPtr pstip;
	AsnTypePtr PNTR types;
	


	type_indent = aeosp->aip->type_indent;
	pstack = aeosp->aip->typestack;
	
	pslp = (PrintStackListPtr)(aeosp->data);
	pstip = pslp->pstip;

	if (pslp->used > 1)
	{
		for (i = 0; i < pslp->used; i++)
		{
			if ((pstip+i)->type_indent >= type_indent)
			{
				pslp->used = i;
				break;
			}
		}
	}

	start_search = pslp->used-1;
	k = (pstip + start_search)->type_indent - 1;
	while (start_search > 0)
	{
		if ((pstip + (start_search - 1))->type_indent < k)
			break;
		start_search--;
	}

	if (pslp->used >= pslp->size)  /* increase array size */
	{
		pslp->pstip = MemNew((size_t)(sizeof(PrintStackListItem) * (pslp->size + 10)));
		MemCopy(pslp->pstip, pstip, (size_t)(sizeof(PrintStackListItem)* pslp->size));
		pslp->size += 10;
		MemFree(pstip);
		pstip = pslp->pstip;
	}

	if (aeosp->the_struct != NULL)   /* it's a struct */
	{
		if (aeosp->dvp->intvalue != START_STRUCT)
			return;
	}

	atp = aeosp->atp;
	base = AsnFindBaseType(atp);


	for (l = start_search; l < pslp->used; l++)
	{
		curr = (pstip + l)->psp;
		pflp = curr->pflp;
		for (i = 0; i < pflp->numitem; i++)
		{
			got_one = FALSE;
			pfip = pflp->list + i;
			j = pfip->numtypes - 1;

			if (! j)
			{
				if (pfip->atp == atp)
					got_one = TRUE;
				else if (pfip->atp == base)
				{                       /* guard against recursion */
					if (curr->is_branch) /* not top level */
					{
						types = curr->branch->types;
						j = curr->branch->numtypes - 1;
					}
				}
			}
			else
				types = pfip->types;

			if ((j) && (types[j] == atp) && (type_indent >= j))
			{
			 	k = type_indent - 1;
				j--;
				while ((j > 0) && (k > 0))
				{
					if (pstack[k].type == types[j])
					{
						j--; k--;
					}
					else
						break;
				}
				if (! j)   /* got all the way through */
				{
					if ((pstack[k].type == types[0]) ||
						(AsnFindBaseType(pstack[k].type) == types[0]))
						got_one = TRUE;
				}
			}

			if (got_one)
			{
				psip = PrintStackItemNew(curr);
				psip->pfip = pfip;
				if (aeosp->the_struct != NULL)
					psip->dv.ptrvalue = aeosp->the_struct;
				else
					psip->dv = *(aeosp->dvp);
				if (pfip->_template != NULL)  /* use template */
				{
					pflp1 = PrintFormatListGet(pfip->_template->name);
					if (pflp1 == NULL)
					{
						ErrPost(CTX_OBJPRT, 1, "Couldn't get format list [%s]",
							pfip->_template->name);
						psip->dv.ptrvalue = NULL;
					}
					else
					{
						tmp = MemNew(sizeof(PrintStack));
						tmp->indent = pfip->indent_level;
						tmp->pflp = pflp1;
						tmp->is_branch = TRUE;
						tmp->branch = pfip;

						psip->dv.ptrvalue = tmp;

						for (j = l+1; j < pslp->used; j++)
						{
							if ((pstip+j)->type_indent == type_indent)
							{
								if (((pstip+j)->psp->indent == tmp->indent) &&
									((pstip+j)->psp->pflp == tmp->pflp))
								{
									(pstip + j)->psp = tmp;
									tmp = NULL;
								}
							}
						}
						if (tmp != NULL)  /* not a duplicate */
						{
							(pstip + pslp->used)->psp = tmp;
							(pstip + pslp->used)->type_indent = type_indent;
							pslp->used++;
						}
					}
				}
			}

		}
	}
	

	return;
}