Exemplo n.º 1
0
/*****************************************************************************
*
*   Int8 AsnLexReadBigInt(aip, atp)
*   	expects an INTEGER 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 Int8 AsnLexReadBigInt (AsnIoPtr aip, AsnTypePtr atp)
{
	Int2 token;

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

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

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

			/******************** read a named integer value *********/
			/**** not supported for bigint *****/

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

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

	return (Int8)0;
}
Exemplo n.º 2
0
/*****************************************************************************
*
*   void AsnLexSkipOctets(aip, atp)
*   	expects Octets type next
*   	assumes none of it has already been read
*   	does not advance to next token
*   	atp points to the definition of this OCTET STRING
*
*****************************************************************************/
NLM_EXTERN void AsnLexSkipOctets (AsnIoPtr aip, AsnTypePtr atp)
{
	Int2 token, left, len;
    Int4 line;

	token = AsnLexWord(aip);      /* read the start */
	if (token != START_BITHEX)
	{
		AsnIoErrorMsg(aip, 45, AsnErrGetTypeName(atp->name), aip->linenumber);
		return;
	}

    line = aip->linenumber;
	token = AsnLexWord(aip);   /* read the octet(s) */
    left = 0;
	while (token == IN_BITHEX)
	{
        len = aip->wordlen + left;
        left = len % 2;
		token = AsnLexWord(aip);
	}

    if (left)
	{
        AsnIoErrorMsg(aip, 48, AsnErrGetTypeName(atp->name), line);
		return;
	}
	
	if (token != OCTETS)
		AsnIoErrorMsg(aip, 47, AsnErrGetTypeName(atp->name), aip->linenumber);

	return;
}
Exemplo n.º 3
0
/*****************************************************************************
*
*   ByteStorePtr AsnLexReadOctets(aip, atp)
*   	expects Octets type next
*   	assumes none of it has already been read
*   	does not advance to next token
*   	atp points to the definition of this OCTET STRING
*
*****************************************************************************/
NLM_EXTERN ByteStorePtr AsnLexReadOctets (AsnIoPtr aip, AsnTypePtr atp)
{
	Int2 token, len;
	ByteStorePtr ssp = NULL;
	Byte tbuf[256]; /* was 101 - changed to handle occasional hand-edited ASN.1? */
	Int4 bytes, left, added;

	token = AsnLexWord(aip);      /* read the start */
	if (token != START_BITHEX)
	{
		AsnIoErrorMsg(aip, 45, AsnErrGetTypeName(atp->name), aip->linenumber);
		return NULL;
	}
	ssp = BSNew(0);
	if (ssp == NULL) return ssp;
	token = AsnLexWord(aip);   /* read the octet(s) */
	left = 0;
	while (token == IN_BITHEX)
	{
		len = (Int2)(aip->wordlen + left);
		MemCopy((tbuf + left), aip->word, (len - left));
		tbuf[len] = '\0';
		added = AsnTypeStringToHex(tbuf, len, tbuf, &left);
		if (added < 0)
		{
			AsnIoErrorMsg(aip, 46, AsnErrGetTypeName(atp->name), aip->linenumber);
			return NULL;
		}
		if (added)
		{
			bytes = BSWrite(ssp, tbuf, added);
			if (bytes != added)
			{
				ssp = BSFree(ssp);
				return ssp;
			}
		}
		if (left)   /* left a char */
		{
			MemCopy(tbuf, ((aip->word)+(aip->wordlen - left)),left);
		}

		token = AsnLexWord(aip);
	}
	
	if (token != OCTETS)
	{
		AsnIoErrorMsg(aip, 47, AsnErrGetTypeName(atp->name), aip->linenumber);
		return NULL;
	}

	return ssp;
}
Exemplo n.º 4
0
/*****************************************************************************
*
*   void AsnLexSkipStruct(aip)
*   	skips current structure and all substructures
*       Does NOT read following element
*
*****************************************************************************/
NLM_EXTERN void AsnLexSkipStruct (AsnIoPtr aip)
{
	int type_indent = 1;
	Int2 token;

	while (type_indent)
	{
		token = AsnLexWord(aip);
		switch (token)
		{
			case START_STRUCT:       /* another substructure */
				type_indent++;
				break;
			case END_STRUCT: 		/* a close brace */
				type_indent--;
				break;
			case EOF_TOKEN:
				AsnIoErrorMsg(aip, 17);
				return;
			default:
				break;
		}
	}

	return;
}
Exemplo n.º 5
0
/*****************************************************************************
*
*   Int2 AsnLexTReadTypeAssign(aip, amp)
*   	reads a type assignment for one type
*       assumes has read name already
*   	returns token to following item
*       returns 0 on error
*
*****************************************************************************/
NLM_EXTERN Int2 AsnLexTReadTypeAssign (AsnIoPtr aip, AsnModulePtr amp)
{
	AsnTypePtr atp;
	Int2 token;
	AsnOptionPtr aop;

							/* store the typereference */

	atp = AsnTypeNew(aip, amp);
	aop = AsnIoOptionGet(aip, OP_TYPEORDER, 0, NULL);
	if (aop != NULL)   /* add ordered display */
	{
		AsnOptionNew(&(atp->hints), OP_TYPEORDER, 0, aop->data, NULL);
		aop->data.intvalue++;
	}

	if ((token = AsnLexTWord(aip)) != ISDEF)
	{
		AsnIoErrorMsg(aip, 28, aip->linenumber);
		return 0;
	}
	
	token = AsnLexTWord(aip);   /* get next element */

	token = AsnLexTReadType(aip, amp, atp);

	return token;
}
Exemplo n.º 6
0
/*****************************************************************************
*
*   AsnTypePtr AsnTypeFind(amp, str)
*   	finds a type in a module or set of modules
*   	str is a path with dot separation.
*   	E is used to indicate an element of SEQOF or SETOF
*   	looks for partial paths as well
*
*   if called with amp == NULL
*       searches all loaded modules
*   returns a single node at the end of the path
*
*****************************************************************************/
NLM_EXTERN AsnTypePtr LIBCALL  AsnTypeFind (AsnModulePtr amp, CharPtr str)
{
	AsnModulePtr amp2;
	AsnTypePtr atp;

    if (amp == NULL)
	{
		if (amps == NULL)
		{
			AsnIoErrorMsg(NULL, (Int2)105);
			return NULL;
		}
        amp = (AsnModulePtr) amps->data.ptrvalue;
	}

	amp2 = amp;
	atp = NULL;

	while (amp2 != NULL)
	{
		atp = AsnTypeFindType(amp2->types, str, NULL, 0, FALSE);
		if (atp != NULL)
			return atp;
		else
			amp2 = amp2->next;
	}

	return atp;       /* not found */
}
Exemplo n.º 7
0
NLM_EXTERN AsnIoConnPtr QUERY_AsnIoConnOpen (
  const char* mode,
  CONN conn
)
{
  Int1          type;
  AsnIoConnPtr  aicp;

  if (strcmp(mode, "r") == 0)
    type = (ASNIO_IN | ASNIO_TEXT);
  else if (strcmp(mode, "rb") == 0)
    type = (ASNIO_IN | ASNIO_BIN);
  else if (strcmp(mode, "w") == 0)
    type = (ASNIO_OUT | ASNIO_TEXT);
  else if (strcmp(mode, "wb") == 0)
    type = (ASNIO_OUT | ASNIO_BIN);
  else {
    AsnIoErrorMsg (NULL, 81, mode);
    return NULL;
  }

  aicp = (AsnIoConnPtr) MemNew (sizeof (AsnIoConn));
  aicp->aip = AsnIoNew (type, NULL, (Pointer) aicp, AsnIoConnRead, AsnIoConnWrite);
  aicp->conn = conn;
  return aicp;
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
0
/*****************************************************************************
*
*   void AsnLexReadNull(aip, atp)
*
*****************************************************************************/
NLM_EXTERN void AsnLexReadNull (AsnIoPtr aip, AsnTypePtr atp)
{
	AsnLexWord(aip);
	if (! StrMatch("NULL", aip->word, aip->wordlen))
	{
		AsnIoErrorMsg(aip, 57, AsnErrGetTypeName(atp->name), aip->linenumber);
		return;
	}
	return;
}
Exemplo n.º 10
0
static Pointer AsnLexReadStringEx (AsnIoPtr aip, AsnTypePtr atp, Uint1 fix_non_print)
{
	Int2 token;
	ByteStorePtr ssp;
	CharPtr result=NULL;
	Int4 bytes;

	token = AsnLexWordEx (aip, fix_non_print);      /* read the start */
	if (token != START_STRING)
	{
		AsnIoErrorMsg(aip, 43, AsnErrGetTypeName(atp->name), aip->linenumber);
		return NULL;
	}

	ssp = BSNew(0);
	if (ssp == NULL) return result;
	token = AsnLexWordEx (aip, fix_non_print);   /* read the string(s) */
	while (token == IN_STRING)
	{
		bytes = BSWrite(ssp, aip->word, (Int4)aip->wordlen);
		if (bytes != (Int4)(aip->wordlen))
		{
			BSFree(ssp);
			return result;
		}
		token = AsnLexWord(aip);
	}

	if (token == ERROR_TOKEN) return NULL;

	if (token != END_STRING)
	{
		AsnIoErrorMsg(aip, 44, AsnErrGetTypeName(atp->name), aip->linenumber);
		return NULL;
	}
	if (AsnFindBaseIsa(atp) == STRSTORE_TYPE)    /* string store */
		return ssp;

	result = (CharPtr) BSMerge(ssp, NULL);
	BSFree(ssp);

	return result;
}
Exemplo n.º 11
0
/*****************************************************************************
*
*   AsnEnumStr(type, val)
*
*****************************************************************************/
NLM_EXTERN CharPtr LIBCALL  AsnEnumStr (CharPtr type, Int2 val)
{
    AsnTypePtr atp;

	if (amps == NULL)
	{
		AsnIoErrorMsg(NULL, (Int2)105);
		return NULL;
	}
    atp = AsnTypeFind((AsnModulePtr)amps->data.ptrvalue, type);
    return AsnEnumTypeStr(atp, val);
}
Exemplo n.º 12
0
/*****************************************************************************
*
*   AsnTypePtr AsnGetType(aip, amp)
*   	return pointer to type of last element read
*
*****************************************************************************/
NLM_EXTERN AsnTypePtr AsnGetType (AsnIoPtr aip, AsnModulePtr amp)
{
	AsnTypePtr atp;
	AsnPrimTypePtr aptp;
	Int2 wordlen;
	Int2 token;

	wordlen = aip->wordlen;
	token = aip->token;

	if (ISA_ASNTYPE(aip->token))     /* a primitive */
	{
		aptp = asnprimtypes;
		while (aptp->isa != token)
			aptp++;
		return (AsnTypePtr)aptp;
	}
	else if (ISA_BASETYPE(aip->token))    /* an application type */
	{
		aptp = asnapptypes;
		while (aptp->isa != token)
			aptp++;
		return (AsnTypePtr)aptp;
	}

	if (aip->token != REF)        /* not a type */
	{
		AsnIoErrorMsg(aip, 98, aip->word, aip->linenumber);
		return NULL;
	}

		/**************** not a primitive - do we have it already? *******/

	atp = amp->types;
	while (atp != NULL)
	{
		if (StrMatch(atp->name, aip->word, wordlen))   /* it matches */
		{
			if (atp->imported == TRUE)   /* reference to imported type */
				atp->resolved = TRUE;
			return atp;
		}
		else
			atp = atp->next;
	}

		/*************** not defined - add unresolved node *************/

	atp = AsnTypeNew(aip, amp);

	return atp;
}
Exemplo n.º 13
0
/*****************************************************************************
*
*   AsnTypePtr AsnTypeNew(aip, amp)
*
*****************************************************************************/
NLM_EXTERN AsnTypePtr AsnTypeNew (AsnIoPtr aip, AsnModulePtr amp)
{
	AsnTypePtr atp, next;
	Int2 token;

	next = amp->types;
	atp = amp->types;

	if ((token = AsnLexTMatchToken(aip)) != 0)    /* it's a reserved word */
		AsnIoErrorMsg(aip, 67, asnwords[token - 1], aip->linenumber);

	while (next != NULL)
	{
		atp = next;
		next = atp->next;
		if (StrMatch(atp->name, aip->word, aip->wordlen))     /* already used name */
		{
			if (! atp->resolved)     /* needs to be resolved yet, so OK */
				return atp;
			else                     /* already defined */
			{
				AsnIoErrorMsg(aip, 99, AsnErrGetTypeName(atp->name), aip->linenumber);
			}
		}
	}

	next = (AsnTypePtr) MemNew(sizeof(AsnType));
	next->tagclass = TAG_NONE;    /* default tag class */
	next->name = AsnLexSaveWord(aip);
	amp->lasttype++;       /* increment defined types isa */
	next->isa = amp->lasttype;

	if (atp == NULL)    /* first one */
		amp->types = next;
	else
		atp->next = next;

	return next;
}
Exemplo n.º 14
0
static Boolean AsnLexSkipStringEx (AsnIoPtr aip, AsnTypePtr atp, Uint1 fix_non_print)
{
	Int2 token;

	token = AsnLexWordEx(aip, fix_non_print);      /* read the start */
	if (token != START_STRING)
	{
		AsnIoErrorMsg(aip, 43, AsnErrGetTypeName(atp->name), aip->linenumber);
		return FALSE;
	}

	token = AsnLexWordEx(aip, fix_non_print);   /* read the string(s) */
	while (token == IN_STRING)
		token = AsnLexWord(aip);

	if (token == ERROR_TOKEN) return FALSE;

	if (token != END_STRING)
		AsnIoErrorMsg(aip, 44, AsnErrGetTypeName(atp->name), aip->linenumber);

	return TRUE;
}
Exemplo n.º 15
0
/*****************************************************************************
*
*   Boolean AsnLexReadBoolean(aip, atp)
*   	expects a BOOLEAN next
*   	assumes none of it has already been read
*   	does not advance to next token
*   	atp points to the definition of this BOOLEN
*
*****************************************************************************/
NLM_EXTERN Boolean AsnLexReadBoolean (AsnIoPtr aip, AsnTypePtr atp)
{
	AsnLexWord(aip);      /* read the boolean */

	if (StrMatch("TRUE", aip->word, aip->wordlen))
		return TRUE;
	else if (StrMatch("FALSE", aip->word, aip->wordlen))
		return FALSE;

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

	return FALSE;      /* just for lint */
}
Exemplo n.º 16
0
/*****************************************************************************
*
*   AsnModulePtr AsnCheckModule(amp, aip)
*
*****************************************************************************/
NLM_EXTERN AsnModulePtr AsnCheckModule (AsnModulePtr amp, AsnIoPtr aip)
{
	AsnTypePtr atp;
	Boolean ok = TRUE;

	atp = amp->types;              /* check that everything got resolved */
	while (atp != NULL)
	{
		if (atp->resolved != TRUE)
		{
			if (atp->imported != TRUE)    /* only imported not resolved */
			{
				AsnIoErrorMsg(aip, 100,	AsnErrGetTypeName(atp->name), amp->modulename);
				ok = FALSE;
			}
			else
				AsnIoErrorMsg(aip, 101,	AsnErrGetTypeName(atp->name), amp->modulename);
		}

		if (atp->imported == TRUE)
		{
			if (atp->branch == NULL)
			{
				AsnIoErrorMsg(aip, 102,	AsnErrGetTypeName(atp->name), amp->modulename);
				ok = FALSE;
			}
		}

		atp = atp->next;
	}

	AsnSetTags(amp->types);      /* assign tags */

	if (ok)
		return amp;
	else
		return NULL;
}
Exemplo n.º 17
0
/*****************************************************************************
*
*   AsnTypePathFind(amp, str, countptr)
*   	like AsnTypeFind() but allocates an array of AsnTypePtr and fills
*       it in with the proper path.  Sets countptr to sizeof array.
*       Returns array or NULL on failure
*
*****************************************************************************/
NLM_EXTERN AsnTypePtr PNTR LIBCALL  AsnTypePathFind (AsnModulePtr amp, CharPtr str, Int2Ptr countptr)
{
	AsnModulePtr amp2;
	AsnTypePtr atp;
	Int2 count;
	AsnTypePtr PNTR typeptr;
	CharPtr ptr;

	*countptr = 0;
	count = 1;
	ptr = str;
	while (*ptr != '\0')
	{
		if (*ptr == '.')
			count++;
		ptr++;
	}
	typeptr = (AsnTypePtr*) MemNew(sizeof(AsnTypePtr) * count);

    if (amp == NULL)
	{
		if (amps == NULL)
		{
			AsnIoErrorMsg(NULL, (Int2)105);
			return NULL;
		}
        amp = (AsnModulePtr) amps->data.ptrvalue;
	}

	amp2 = amp;
	atp = NULL;

	while (amp2 != NULL)
	{
		atp = AsnTypeFindType(amp2->types, str, typeptr, count, FALSE);
		if (atp != NULL)
		{
			*countptr = count;
			return typeptr;
		}
		else
			amp2 = amp2->next;
	}

	MemFree(typeptr);
	return NULL;       /* not found */
}
Exemplo n.º 18
0
/*****************************************************************************
*
*   AsnLexTReadModule(aip)
*
*****************************************************************************/
NLM_EXTERN AsnModulePtr AsnLexTReadModule (AsnIoPtr aip)
{
	AsnModulePtr amp;
	AsnOptionPtr aop;
	DataVal dv;

					/* get name and look for valid start */

	amp = AsnLexTStartModule(aip);
	if (amp == NULL)
		return amp;

	aop = AsnIoOptionGet(aip, OP_TYPEORDER, 0, NULL);
	if (aop == NULL)
	{
		MemSet(&dv, 0, sizeof(DataVal));
		aop = AsnIoOptionNew(aip, OP_TYPEORDER, 0, dv, NULL);
	}
	aop->data.intvalue = 1;  /* start the order counter */

			   		/* scan declarations */
	
	while (aip->token != END_TOKEN)     /* END */
	{
		if (aip->token == REF)        /* its a type assignment */
			aip->token = AsnLexTReadTypeAssign(aip, amp);
		/**************************** not implemented yet ********
		else if (token == IDENT) 
			aip->token = AsnReadDefinedValue(aip, amp);
		**********************************************************/
		else
		{
			AsnIoErrorMsg(aip, 60, aip->linenumber, aip->word);
			return NULL;
		}
	}

	amp = AsnCheckModule(amp, aip);

	return amp;
}
Exemplo n.º 19
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;
}
Exemplo n.º 20
0
/*****************************************************************************
*
*   AsnModulePtr AsnLexTStartModule(aip)
*   	if $Revision: in comment in first line of file, puts the string
*        containing the revision number in amp->filename
*       if --$Revision: X.YY
*     			stores "YY"
*       if --$Revision: X.Y  stores "XY"
*   	if --$Revision: X
*               stores "X"
*
*****************************************************************************/
NLM_EXTERN AsnModulePtr AsnLexTStartModule (AsnIoPtr aip)
{
	Int2 token;
	AsnModulePtr amp;
	Int2 asntype;
	AsnTypePtr atp;
	Boolean wasref;
	Char buf[10];
	CharPtr from, to;
	Int2 len;

	amp = (AsnModulePtr) MemNew(sizeof(AsnModule));

	token = AsnLexTWord(aip);    /* get the module name or $Revision: */

        while (token == COMMENT_TOKEN)
        {
                token = AsnLexTWord(aip);
	}


	if (token == REVISION_TOKEN)            /* revision of file */
	{
		to = buf;
		*to = '\0';
                len = (Int2)(aip->wordlen);
		if (len == 4)     /* x.yy */
		{
			from = aip->word + 2;
			len -= 2;
		}
		else
			from = aip->word;

		if (len)
		{
			if (IS_DIGIT(*from))
			{
				*to = *from; to++; from++;len--;
			}
			while ((len) && (! IS_DIGIT(*from)))
			{
				len--; from++;
			}
			if ((len) && (IS_DIGIT(*from)))
			{
				*to = *from; to++;
			}
			*to = '\0';
			amp->filename = StringSave(buf);
		}
			
		token = AsnLexTWord(aip);     /* get the module name */

		while (token == COMMENT_TOKEN)
		{
			token = AsnLexTWord(aip);
		}
	}

	if (token != REF)
	{
		MemFree(amp->filename);
		amp = (AsnModulePtr) MemFree(amp);
		return amp;
	}

	if ((asntype = AsnLexTMatchToken(aip)) != 0)     /* any predefined value is wrong */
	{
		AsnIoErrorMsg(aip, 67, asnwords[asntype -1], aip->linenumber);
		return NULL;
	}

						     /* create a new module */


	amp->modulename = AsnLexSaveWord(aip);
	amp->lasttype = 400;
	amp->lastvalue = 10000;

	token = AsnLexTWord(aip);

        while (token == COMMENT_TOKEN)
        {
                token = AsnLexTWord(aip);
	}

	if (token == START_STRUCT)       /* it has an object identifier */
	{
		AsnIoErrorMsg(aip, 68);
		    /* skip object identifier */
		AsnLexSkipStruct(aip);
		token = AsnLexTWord(aip);  /* next token */
	}

        while (token == COMMENT_TOKEN)
        {
                token = AsnLexTWord(aip);
	}

	if (token != DEF_TOKEN)        /* DEFINITIONS */
	{
		AsnIoErrorMsg(aip, 69, asnwords[DEF_TOKEN - 401], aip->linenumber);
		return NULL;
	}
	else
		token = AsnLexTWord(aip);

    while (token == COMMENT_TOKEN)
    {
        token = AsnLexTWord(aip);
    }
    while (token != ISDEF && token != BEGIN_TOKEN && token != ERROR_TOKEN)
    {
        token = AsnLexTWord(aip);
    }
	if (token != ISDEF)           /* ::= */
	{
		AsnIoErrorMsg(aip, 69, "::=", aip->linenumber);
		return NULL;
	}
	else
		token = AsnLexTWord(aip);

        while (token == COMMENT_TOKEN)
        {
                token = AsnLexTWord(aip);
	}

	if (token != BEGIN_TOKEN)    /* BEGIN */
	{
		AsnIoErrorMsg(aip, 69, asnwords[BEGIN_TOKEN - 401], aip->linenumber);
		return NULL;
	}
	else
		token = AsnLexTWord(aip);

        while (token == COMMENT_TOKEN)
        {
                token = AsnLexTWord(aip);
	}

	if (token == EXPORTS_TOKEN)     /* read any EXPORTS */
	{
		wasref = FALSE;
		while ((token = AsnLexTWord(aip)) != SEMI_COLON)
		{
			if (token == REF)     /* should be REF */
			{
				if (wasref)
				{
					AsnIoErrorMsg(aip, 66, aip->linenumber);
					return NULL;
				}
				atp = AsnTypeNew(aip, amp);
				atp->exported = TRUE;
				wasref = TRUE;
			}
			else if (token == COMMA)
			{
				if (! wasref)
				{
					AsnIoErrorMsg(aip, 70, aip->linenumber);
					return NULL;
				}
			   	wasref = FALSE;
			}
			else if (token != COMMENT_TOKEN)
			{
				AsnIoErrorMsg(aip, 59, ' ', aip->linenumber);
				return NULL;
			}
		}
						   /* get next after semi-colon */

		token = AsnLexTWord(aip);
	}

        while (token == COMMENT_TOKEN)
        {
                token = AsnLexTWord(aip);
	}

	if (token == IMPORTS_TOKEN)             /* IMPORTS */
	{
		wasref = FALSE;
		token = AsnLexTWord(aip);

		while (token != SEMI_COLON)
		{
			if (token == REF)     /* should be REF */
			{
				atp = AsnTypeNew(aip, amp);
				atp->imported = TRUE;
				wasref = TRUE;
			}
			else if (token == COMMA)
			{
				if (! wasref)
				{
					AsnIoErrorMsg(aip, 70, aip->linenumber);
					return NULL;
				}
			   	wasref = FALSE;
			}
			else if (token == FROM_TOKEN)
			{
				if (! wasref)
				{
					AsnIoErrorMsg(aip, 71, aip->linenumber);
					return NULL;
				}
				else								/* read source module */
					token = AsnLexTWord(aip);

				if (token != REF)
				{
					AsnIoErrorMsg(aip, 72, aip->linenumber);
					return NULL;
				}
				else
				{
					atp = amp->types;
					while (atp != NULL)
					{
						if ((atp->imported == TRUE) && (atp->branch == NULL))
							atp->branch = AsnLexSaveWord(aip);
						atp = atp->next;
					}
				}
				wasref = FALSE;
			}
			else if (token == START_STRUCT)
			{
				AsnIoErrorMsg(aip, 73, aip->linenumber);
				AsnLexSkipStruct(aip);
				token = AsnLexTWord(aip);
				wasref = FALSE;
			}
			else if (token != COMMENT_TOKEN)
				AsnIoErrorMsg(aip, 96, aip->linenumber);

			token = AsnLexTWord(aip);
		}
						   /* get next after semi-colon */
		token = AsnLexTWord(aip);
	}

        while (token == COMMENT_TOKEN)
        {
                token = AsnLexTWord(aip);
	}

	if (token == EXPORTS_TOKEN)     /* EXPORTS out of place */
		AsnIoErrorMsg(aip, 97, aip->linenumber);

	return amp;
}
Exemplo n.º 21
0
/*****************************************************************************
*
*	AsnTypePtr AsnLexTReadAlternativeTypeList(aip, amp, parent)
*   	assumes has read first { already
*   	returns token to following element
*
*****************************************************************************/
NLM_EXTERN AsnTypePtr AsnLexTReadAlternativeTypeList (AsnIoPtr aip, AsnModulePtr amp, AsnTypePtr
						      parent)
{
	Int2 token;
	AsnTypePtr atp, atp1, atplast;

	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 != 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);
		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;
}
Exemplo n.º 22
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;
}
Exemplo n.º 23
0
/*****************************************************************************
*
*   Int2 AsnLexTReadType(aip, amp, atp)
*   	reads a type assignment for one type
*       assumes has read name already
*       assumes has read next input item after name
*   	returns token to following item
*       returns 0 on error
*
*****************************************************************************/
NLM_EXTERN Int2 AsnLexTReadType (AsnIoPtr aip, AsnModulePtr amp, AsnTypePtr atp)
{
	Int2 isa;
	Boolean first;
	AsnValxNodePtr avnp, prevavnp;
	Int2 token;

	token = aip->token;

	if (token == COMMENT_TOKEN)
	{
		AsnLexTAddTypeComment(aip, &(atp->hints));
		token = AsnLexTWord(aip);
	}

	if (token == IMPLICIT_TOKEN) 
	{
		atp->implicit = TRUE;
		token = AsnLexTWord(aip);
	}

	if (token == START_TAG)                      /* TAG */
	{
		token = AsnLexTWord(aip);
		if (ISA_TAGCLASS(token))
		{
			switch (token)
			{
				case UNIV_TAG_TOKEN:
					atp->tagclass = TAG_UNIVERSAL;
					break;
				case PRIV_TAG_TOKEN:
					atp->tagclass = TAG_PRIVATE;
					break;
				case AP_TAG_TOKEN:
					atp->tagclass = TAG_APPLICATION;
					break;
			}
			token = AsnLexTWord(aip);
		}
		else
			atp->tagclass = TAG_CONTEXT;

		if (token == NUMBER)
		{
			atp->tagnumber = (Int2) AsnLexInteger(aip);
			token = AsnLexTWord(aip);
			if (token != END_TAG)
			{
				AsnIoErrorMsg(aip, 61, aip->linenumber);
				return 0;
			}
			else
				token = AsnLexTWord(aip);
		}
		else if (token == IDENT)
		{
			AsnIoErrorMsg(aip, 62, aip->linenumber);
			return 0;
		}
		else
		{
			AsnIoErrorMsg(aip, 63, aip->linenumber);
			return 0;
		}
	}

	atp->type = AsnGetType(aip, amp);
	isa = atp->type->isa;
	
	token = AsnLexTWord(aip);   /* read next token */

	AsnLexTAddTypeComment(aip, &(atp->hints));  /* check for stored comments */

	if (token == COMMENT_TOKEN)
		token = AsnLexTWord(aip);
            
 					/*********** SubType Processing *********************/
	if (token == OPEN_PAREN)
	{
		AsnIoErrorMsg(aip, 64, aip->linenumber);
		return 0;
	}
	                 /******************* process various types *********/
	
	if (isa < 400)       /* operate on builtin types */
		switch (isa)
	{
		case INTEGER_TYPE:           /* check for named integers */
			if (token != START_STRUCT)
				break;
		case ENUM_TYPE:
			if (token != START_STRUCT)
			{
				AsnIoErrorMsg(aip, 65, aip->linenumber);
				return 0;
			}

									 /* read named integers */
			first = TRUE;
			avnp = NULL;
			prevavnp = NULL;
			token = AsnLexTWord(aip);
			if (token == COMMENT_TOKEN)
			{
			    AsnLexTAddTypeComment(aip, &(atp->hints));  /* check for stored comments */
			    token = AsnLexTWord(aip);
		        }
			    
			while (token != END_STRUCT)
			{
				avnp = AsnValxNodeNew(avnp, VALUE_ISA_NAMED_INT);

				if (! first)
				{
					if (token != COMMA)
					{
						AsnIoErrorMsg(aip, 66, aip->linenumber);
						return 0;
					}
					else
					{
						token = AsnLexTWord(aip);
						if (token == COMMENT_TOKEN)
						{
							AsnLexTAddTypeComment(aip, &(prevavnp->aop));
							token = AsnLexTWord(aip);
						}
					}
							
				}
				else
				{
					first = FALSE;
					atp->branch = avnp;
				}

				if (token != IDENT)
				{
					AsnIoErrorMsg(aip, 86, aip->linenumber);
					return 0;
				}
				avnp->name = AsnLexSaveWord(aip);
				token = AsnLexTWord(aip);
				if (token != OPEN_PAREN)
				{
					AsnIoErrorMsg(aip, 87, aip->linenumber);
					return 0;
				}
				avnp->intvalue = AsnLexReadInteger(aip, atp);
				token = AsnLexTWord(aip);
				if (token != CLOSE_PAREN)
				{
					AsnIoErrorMsg(aip, 88, aip->linenumber);
					return 0;
				}
				token = AsnLexTWord(aip);
				if (token == COMMENT_TOKEN)
					token = AsnLexTWord(aip);

				AsnLexTAddTypeComment(aip, &(avnp->aop));  /* check for stored comments */
				prevavnp = avnp;
			}
			token = AsnLexTWord(aip);
			if (token == COMMENT_TOKEN)
			{
				AsnLexTAddTypeComment(aip, &(prevavnp->aop));
				token = AsnLexTWord(aip);
			}
			break;
		case SETOF_TYPE:			/* create branch for type */
		case SEQOF_TYPE:
			atp->branch = AsnElementTypeNew(NULL);   /* get unnamed element for type */
			token = AsnLexTReadType(aip, amp, (AsnTypePtr) atp->branch);
			break;
		case SEQ_TYPE:
		case SET_TYPE:
			atp->branch = AsnLexTReadElementTypeList(aip, amp, atp);
			token = aip->token;
			break;
		case CHOICE_TYPE:
			atp->branch = AsnLexTReadAlternativeTypeList(aip, amp, atp);
			token = aip->token;
			break;
	}
	atp->resolved = TRUE;
	return token;
}
Exemplo n.º 24
0
/*****************************************************************************
*
*   FloatHi AsnLexReadReal(aip, atp)
*   	expects a REAL next
*   	assumes none of it has already been read
*   	does not advance to next token
*   	atp points to the definition of this REAL
*
*****************************************************************************/
NLM_EXTERN FloatHi AsnLexReadReal (AsnIoPtr aip, AsnTypePtr atp)
{
	Int2 token;
	double mantissa, result;
	int	base, exponent;
	char buf[15];

	result = 0.0;
	token = AsnLexWord(aip);      /* read the { */
	if (token != START_STRUCT)
	{
		AsnIoErrorMsg(aip, 49, AsnErrGetTypeName(atp->name), aip->linenumber);
		return (FloatHi)result;
	}

	token = AsnLexWord(aip);      /* read mantissa */
	if (token != NUMBER)
	{
		AsnIoErrorMsg(aip, 50, AsnErrGetTypeName(atp->name), aip->linenumber);
		return (FloatHi)result;
	}
	MemCopy(buf, aip->word, (size_t)aip->wordlen);
	buf[aip->wordlen] = '\0';
	mantissa = atof(buf);

	token = AsnLexWord(aip);      /* read comma */
	if (token != COMMA)
	{
		AsnIoErrorMsg(aip, 51, AsnErrGetTypeName(atp->name), aip->linenumber);
		return (FloatHi)result;
	}

	token = AsnLexWord(aip);      /* read base */
	if (token != NUMBER)
	{
		AsnIoErrorMsg(aip, 52, AsnErrGetTypeName(atp->name), aip->linenumber);
		return (FloatHi)result;
	}
	MemCopy(buf, aip->word, (size_t)aip->wordlen);
	buf[aip->wordlen] = '\0';
	base = atoi(buf);
	if ((base != 2) && (base != 10))
	{
		AsnIoErrorMsg(aip, 53, AsnErrGetTypeName(atp->name), aip->linenumber);
		return (FloatHi)result;
	}

	token = AsnLexWord(aip);
	if (token != COMMA)
	{
		AsnIoErrorMsg(aip, 54, AsnErrGetTypeName(atp->name), aip->linenumber);
		return (FloatHi)result;
	}

	token = AsnLexWord(aip);
	if (token != NUMBER)
	{
		AsnIoErrorMsg(aip, 55, AsnErrGetTypeName(atp->name), aip->linenumber);
		return (FloatHi)result;
	}
	MemCopy(buf, aip->word, (size_t)aip->wordlen);
	buf[aip->wordlen] = '\0';
	exponent = atoi(buf);

	token = AsnLexWord(aip);
	if (token != END_STRUCT)
	{
		AsnIoErrorMsg(aip, 56, AsnErrGetTypeName(atp->name), aip->linenumber);
		return (FloatHi)result;
	}
    
    if (base == 10)      /* range checking only on base 10, for doubles */
    {
    	if (exponent > DBL_MAX_10_EXP)   /* exponent too big */
    		return	(FloatHi)DBL_MAX;
    	else if (exponent < DBL_MIN_10_EXP)  /* exponent too small */
    		return (FloatHi)result;
    }
    	
	result = mantissa * Nlm_Powi((double)base, exponent);

	return (FloatHi)result;
}
Exemplo n.º 25
0
/*****************************************************************************
*
*   void AsnModuleLink(amp)
*   	links IMPORT types with EXPORTS from other modules
*   	if cannot link an IMPORT, no errors are generated
*
*****************************************************************************/
NLM_EXTERN void LIBCALL  AsnModuleLink (AsnModulePtr amp)
{
	AsnTypePtr atp, atp2, typestack[10];
	AsnModulePtr currmod, mod;
	Boolean found;

	currmod = amp;
	while (currmod != NULL)
	{
		atp = currmod->types;
		while (atp != NULL)
		{
			if ((atp->imported) && (atp->type == NULL)) /* link imported types */
			{
				mod = amp;
				if (mod == currmod)
					mod = mod->next;
				found = FALSE;
				while ((mod != NULL) && (! found))
				{
					atp2 = mod->types;
					while ((atp2 != NULL) && (! found))
					{
						if ((! atp2->imported) &&
                        	(! StringCmp(atp2->name, atp->name)))
						{
							if (atp2->exported)
							{
								atp->type = atp2;
								found = TRUE;
							}
							else
							{
								AsnIoErrorMsg(NULL, 84,	AsnErrGetTypeName(atp2->name),
									mod->modulename);
								atp2 = atp2->next;
							}
						}
						else
							atp2 = atp2->next;
					}
					mod = mod->next;
					if (mod == currmod)
						mod = mod->next;
				}
			}
			atp = atp->next;
		}
		currmod = currmod->next;
	}

	/*** Fill in the XML names *********/

	currmod = amp;
	while (currmod != NULL)
	{
		atp = currmod->types;
		while (atp != NULL)
		{
			AddXMLname(atp, typestack, (Int2)0);
			atp = atp->next;
		}
		currmod = currmod->next;
	}


	return;
}
Exemplo n.º 26
0
/*****************************************************************************
*
*   AsnTreeLoad(file, &avn, &at, &amp)
*
*****************************************************************************/
NLM_EXTERN Boolean LIBCALL  AsnTreeLoad (char *file, AsnValxNodePtr *avnptr, AsnTypePtr *atptr, AsnModulePtr *ampptr)
{
    AsnValxNodePtr avn = NULL, avncurr;
    AsnTypePtr at = NULL, atcurr;
    AsnModulePtr amp = NULL, ampcurr;
    ValNodePtr anp, ampanp;
    int numval, numtype, nummod, i;
    FILE * fp;
    int isa, next;
    long intvalue;
    double realvalue;
    char name[PATH_MAX], fname[60];
    CharPtr ptr;
    int bools[5], tagclass, tagnumber, defaultvalue, type, branch;

                    /* check to see if we already have it (could happen) */

    anp = names;
    ampanp = amps;
    while (anp != NULL)
    {
        if (! StringCmp((CharPtr)anp->data.ptrvalue, file))
        {                               /* have it */
            if (* ampptr == NULL)       /* fill dynamic load */
            {
                * ampptr = (AsnModulePtr) ampanp->data.ptrvalue;
                * atptr = (* ampptr)->types;
                     /* don't really need avnptr filled in */
            }
            return TRUE;
        }
        ampanp = ampanp->next;
        anp = anp->next;
    }

	if (! ProgMon("Load ASN.1 Trees"))
		return FALSE;

    if (* ampptr != NULL)      /* static load, add to list */
    {
        AsnStoreTree(file, (* ampptr));
        return TRUE;        /* already loaded */
    }

    if (! FindPath("ncbi", "ncbi", "asnload", name, sizeof (name)))
	{
		AsnIoErrorMsg(NULL, 85);
        return FALSE;
	}

    FileBuildPath (name, NULL, file);/* add file to path */

    fp = FileOpen(name, "r");
    if (fp == NULL)
    {
        AsnIoErrorMsg(NULL, 83, (CharPtr) name);
        return FALSE;
    }

    fscanf(fp, "%d %d %d", &numval, &numtype, &nummod);

    if (numval)
        avn = (AsnValxNodePtr) MemNew(numval * sizeof(AsnValxNode));
    at  = (AsnTypePtr)   MemNew(numtype * sizeof(AsnType));
    amp = (AsnModulePtr) MemNew(nummod  * sizeof(AsnModule));

    *avnptr = avn;
    *atptr = at;
    *ampptr = amp;

    avncurr = avn;
    for (i = 0; i < numval; i++)
    {
        fscanf(fp, "%d %s %ld %lf %d", &isa, name, &intvalue, &realvalue, &next);
        avncurr->valueisa = isa;
        if (*name != '-')
            avncurr->name = StringSave(name);
        avncurr->intvalue = (Int4)intvalue;
        avncurr->realvalue = (FloatHi)realvalue;
        avncurr->next = (AsnValxNodePtr) PointerDecode((Int2)next, avn, at);
        avncurr++;
    }

    atcurr = at;
    for (i = 0; i < numtype; i++)
    {
        fscanf(fp, "%d %s %d %d %d %d %d %d %d %d %d %d %d",
            &isa, name, &tagclass, &tagnumber, bools, bools+1, bools+2,
            bools+3, bools+4, &defaultvalue, &type, &branch, &next);
        atcurr->isa = isa;
        if (*name != '-')
        {
            atcurr->name = StringSave(name);
            ptr = atcurr->name;
            while (*ptr != '\0')
            {
                if (*ptr == '!')
                    *ptr = ' ';
                ptr++;
            }
        }
        atcurr->tagclass = (Uint1)tagclass;
        atcurr->tagnumber = tagnumber;
        atcurr->implicit = (Boolean)bools[0];
        atcurr->optional = (Boolean)bools[1];
        atcurr->hasdefault = (Boolean)bools[2];
        atcurr->exported = (Boolean)bools[3];
        atcurr->imported = (Boolean)bools[4];
        atcurr->defaultvalue = (AsnValxNodePtr)PointerDecode((Int2)defaultvalue, avn, at);
        atcurr->type = (AsnTypePtr)PointerDecode((Int2)type, avn, at);
        atcurr->branch = PointerDecode((Int2)branch, avn, at);
        atcurr->next = (AsnTypePtr)PointerDecode((Int2)next, avn,at);
        atcurr++;
    }

    ampcurr = amp;
    for (i = 0; i < nummod; i++)
    {
        fscanf(fp, "%s %s %d %d", name, fname, &type, &next);
        if (*name != '-')
            ampcurr->modulename = StringSave(name);
		if (*fname != '-')
			ampcurr->filename = StringSave(fname);
        ampcurr->types = (AsnTypePtr)PointerDecode((Int2)type, avn, at);
        if (next != -32000)
            ampcurr->next = &amp[next];
        ampcurr++;
    }

    FileClose(fp);
                                  /* store it in list */
    AsnStoreTree(file, (* ampptr));

    return TRUE;
}
Exemplo n.º 27
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;	
}
Exemplo n.º 28
0
/*****************************************************************************
*
*   Int2 AsnLexTWord(aip)
*   	reads words, punctuation, and asn keywords with 2 parts
*   	returns tokens defined at top
*
*****************************************************************************/
NLM_EXTERN Int2 AsnLexTWord (AsnIoPtr aip)
{
	register CharPtr pos;
	register int len;
	Int1 state;
	Int2 token, asntype, linepos;
	int done;
	Boolean first = FALSE, hitnewline = FALSE;
	CharPtr commentptr;

	if (! aip->bytes)   /* no data loaded */
	{
		hitnewline = TRUE;
		first = TRUE;
		AsnIoGets(aip);
	}
		
	linepos = aip->linepos;
	pos = aip->linebuf + linepos;
	state = aip->state;
	len = 0;
	token = -1;

	while (*pos == '\n' || *pos == '\r')    /* skip empty lines */
	{
		hitnewline = TRUE;
		pos = AsnIoGets(aip);

		if (pos == NULL)
			return EOF_TOKEN;
	}
	
	if (state == IN_STRING_STATE)
	{
		aip->word = pos;
		if (* pos == '\"')    /* end of string */
		{
			token = END_STRING;
			pos++;
			state = 0;        /* reset state */
		}
		else
		{
			token = IN_STRING;
			while ((* pos != '\"') && (* pos != '\n') && (* pos != '\r'))
			{
				pos++; len++;
			}

			if ((*pos != '\n') && (*pos != '\r') && (* (pos + 1) == '\"')) /* internal quote */
			{
				len++;        /* include in previous string */
				pos += 2;     /* point to rest of string */
			}
		}
	}
	else if (state == IN_BITHEX_STATE)
	{
		aip->word = pos;
		if (*pos == '\'')  			  /* end of binhex */
		{
			state = 0;              /* set to normal */
			pos++;                       /* move past quote */
			while (IS_WHITESP(*pos))
				pos++;
			if (* pos == 'H')
				token = OCTETS;
			else if (* pos == 'B')
				token = ASNBITS;
			else
			{
				AsnIoErrorMsg(aip, 58, aip->linenumber);
				token = ERROR_TOKEN;
			}
		}
		else
		{
			token = IN_BITHEX;
			while ((* pos != '\'') && (* pos != '\n') && (* pos != '\r'))
			{
				pos++; len++;
			}
		}   
	}
	else              /* normal scanning */
	{
		done = 0;
		while (! done)
		{
			while (* pos <= ' ')     /* skip leading white space */
			{
				if (*pos == '\n' || *pos == '\r')
				{
					hitnewline = TRUE;
					pos = AsnIoGets(aip);

					if (pos == NULL)
						return EOF_TOKEN;
				}
				else
					pos++;
			}
			done = 1;
			
			while (done && (*pos == '-') && (*(pos+1) == '-'))   /* skip comments */
			{
				pos += 2;
				if (first)   /* could be revision */
				{
				 	first = FALSE;
					if (StrMatch(asnwords[57], pos, 10))  /* $Revision: */
					{
						token = REVISION_TOKEN;
						pos += 10;
						while (IS_WHITESP(*pos))
							pos++;
						aip->word = pos;
						while (IS_DIGIT(*pos))       /* eg. 1.2 */
						{
							len++;
							pos++;
						}
						if (*pos == '.')        /* take after . if present */
						{
							pos++;
                                                        len++;
							while (IS_DIGIT(*pos))
							{
								len++;
								pos++;
							}
						}
					}
				}
				commentptr = pos;
				
				done = 0;
				while (! done)   /* skip to end of comment */
				{
					if ((*pos == '-') && (*(pos +1) == '-'))
					{
						if (token != REVISION_TOKEN)
						{
							AsnLexTAddComment(commentptr, pos, aip);
							if ((! hitnewline) && (aip->token != COMMENT_TOKEN))
								token = COMMENT_TOKEN;
						}
						pos += 2;
						done = 1;
					}
					else if (*pos == '\n' || *pos == '\r')
					{
						if (token != REVISION_TOKEN)
						{
							AsnLexTAddComment(commentptr, pos, aip);
							if ((! hitnewline) && (aip->token != COMMENT_TOKEN))
								token = COMMENT_TOKEN;
						}

						done = 1;
					}
					else
						pos++;
				}

				if ((token == REVISION_TOKEN) || (token == COMMENT_TOKEN))
				{
					aip->linepos = pos - aip->linebuf;
					aip->state = state;
					aip->wordlen = len;
					aip->token = token;
					return token;
				}

				if (*pos <= ' ')
					done = 0;
				else
					done = 1;
			}
		}

		aip->word = pos;
		if (* pos == '\"')
		{
			token = START_STRING;
			state = IN_STRING_STATE;
		}
		else if (* pos == '\'')
		{
			token = START_BITHEX;
			state = IN_BITHEX_STATE;
		}
		else if (* pos == ',')
			token = COMMA;
		else if (* pos == '{')
			token = START_STRUCT;
		else if (* pos == '}')
			token = END_STRUCT;
		else if (* pos == '[')
			token = START_TAG;
		else if (* pos == ']')
			token = END_TAG;
		else if (* pos == '(')
			token = OPEN_PAREN;
		else if (* pos == ')')
			token = CLOSE_PAREN;
		else if (* pos == ';')
			token = SEMI_COLON;
		else if (* pos == ':')
		{
			if ((*(pos + 1) == ':') && (*(pos + 2) == '='))
			{
				token = ISDEF;
				pos += 2;
				len = 3;
			}
			else
			{
				AsnIoErrorMsg(aip, 59, *pos, aip->linenumber);
				token = ERROR_TOKEN;
			}
		}
		else if (IS_UPPER(*pos))  /* a reference or keyword */
		{
			token = REF;
			while ((IS_ALPHANUM(*pos)) || (*pos == '-'))
			{
				pos++; len++;
			}

			aip->wordlen = len;
			asntype = AsnLexTMatchToken(aip);    /* check types */
			if (asntype)          /* did it match ? */
			{
				if ((asntype > 27) && (asntype < 57))   /* not a primitive type */
				{
					token = asntype + 400;   /* make a keyword type */
					if (asntype == COMPS_TOKEN)  /* COMPONENTS OF */
					{
						if ((*(pos + 1) == 'O') &&
							(*(pos + 2) == 'F') &&
							(IS_WHITESP(*(pos+3))))
						{
							pos += 3;    /* move past OF */
							len += 3;
						}
						else
							AsnIoErrorMsg(aip, 89, aip->linenumber);
					}
				}
				else if (asntype == 57)    /* StringStore */
					token = STRSTORE_TYPE;
				else if (asntype == 59)    /* BitInt */
					token = BIGINT_TYPE;
				else
				{
					switch (asntype)
					{
						case 3:				/* BIT */
						case 4:				/* OCTET */
							if (! StrMatch(asnwords[11], (pos+1), 6))
								AsnIoErrorMsg(aip, 90, aip->linenumber);
							pos += 7;       /* move past STRING */
							len += 7;
							break;
						case 11:			/* SEQUENCE */
						case 13:			/* SET */
							if ((*(pos + 1) == 'O') &&
								(*(pos + 2) == 'F'))
							{
								asntype++;   /* SET or SEQ OF */
								pos += 3;
								len += 3;
								if (! IS_WHITESP(*pos))
									AsnIoErrorMsg(aip, 91, aip->linenumber);
							}
							break;
						case 6:				/* OBJECT */
							if ((! StrMatch(asnwords[55], (pos+1), 10)))  /* IDENTIFIER */
								AsnIoErrorMsg(aip, 92, aip->linenumber);
							pos += 11;
							len += 11;
							break;
						default:
							break;
					}
					token = asntype + 300;   /* change to point at type */
				}
			}
			pos--;    /* move back for increment at end */
			len--;
		}
		else if (IS_LOWER(*pos))  /* an identifier or valuereference */
		{
			token = IDENT;
			while ((IS_ALPHANUM(*pos)) || (*pos == '-'))
			{
				pos++; len++;
			}
			pos--;		  /* move back for increment at end */
			len--;
		}
		else if ((IS_DIGIT(*pos)) || ((*pos == '-') && (IS_DIGIT(*(pos+1)))))
		{
			token = NUMBER;
			if (*pos == '-')
			{
				pos++; len++;
			}

			while (IS_DIGIT(*pos))
			{
				pos++; len++;
			}
			pos--;    /* move back for increment at end */
			len--;
		}
		else
		{
			AsnIoErrorMsg(aip, 59, *pos, aip->linenumber);
			token = ERROR_TOKEN;
		}
		len++; pos++;     /* move over last symbol */
	}
	aip->linepos = pos - aip->linebuf;
	aip->state = state;
	aip->wordlen = len;
	aip->token = token;
	return token;
}
Exemplo n.º 29
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;
}
Exemplo n.º 30
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;
}