Exemple #1
0
static Boolean GenericReestablishNet(CharPtr svcName, Boolean showErrs)
{
    Monitor *mon = NULL;
    Boolean retval;
    CharPtr buf;

    buf = MemNew(2 * StrLen(svcName) + 60);

    if (showErrs) {
        sprintf (buf, "Re-establishing %s Service", svcName);
        mon = MonitorStrNew(buf, 40);
        sprintf (buf, "Requesting %s service", svcName);
        MonitorStrValue(mon, buf);
    }
    NetFini();
    retval = TRUE;

    if (! myNetInit())
    {
        sprintf (buf, "%s get failed; re-contacting dispatcher", svcName);
        MonitorStrValue(mon, buf);
        retval = FALSE;
        if (ForceNetInit())
        { /* successfully established contact w/dispatcher */
            sprintf (buf, "%s get failed; re-requesting %s service",
                     svcName, svcName);
            MonitorStrValue(mon, buf);
            retval = myNetInit();
        }
        else {
            ErrPost(CTX_UNKNOWN, 1, "Unable to re-contact dispatcher");
            if (showErrs) {
                ErrShow();
            }
        }
    }

    MonitorFree(mon);

    if (! retval )
    {
        sprintf (buf, "Unable to re-establish %s service", svcName);
        ErrPost(CTX_UNKNOWN, 1, buf);
        if (showErrs) {
            ErrShow();
        }
    }

    MemFree(buf);
    AsnIoSetBufsize(asnin,4390);
    return retval;
}
Exemple #2
0
static
int	mfmt_process_article( void *handle, MedArt *article )
{
    MedlineEntryPtr	asn_article;
    int			rv;

    /* Clear error status */

    asn_hand->have_error = FALSE;

    /* Is the file open? */

    if( asn_hand->open_state != open_output &&
	asn_hand->open_state != init_output ) {

	/* The file is closed - this is an error */

	ErrPost(CTX_MFMT_MEDASN, ASN_OUTPUT_NOT_OPEN,
	    "%s: ASN output to %s was not successfully opened",
	    (asn_hand->name == NULL) ? "ASN output" : asn_hand->name,
	    (asn_hand->file == NULL) ? "???" : asn_hand->file );
	return( FALSE );
    }

    /* If this is the first article - output the PubSet */

    if( asn_hand->count == 0 ) {
	DataVal	v;
	AsnWrite(asn_hand->ioptr, PUB_SET, &v);
	AsnStartStruct(asn_hand->ioptr, PUB_SET_medline);
    }

    /* Convert the article to ASN1 notation */

    asn_article = medline2asn( article, NULL );
    asn_hand->have_error = ErrFetch( &asn_hand->error );
    if( asn_hand->have_error ) return( FALSE );

    /* Write out the article */

    asn_hand->count++;
    rv = MedlineEntryAsnWrite(asn_article, asn_hand->ioptr, PUB_SET_medline_E);
    asn_hand->have_error = ErrFetch( &asn_hand->error );

    /* Handle errors */

    return( rv );
}
Exemple #3
0
/*============================================================================*\
 * Function:
 *	NetSuggestReadAsn
 *
 * Purpose:
 *	Reads SuggestResponse from network file.
 *
 * Parameters:
 *	none
 *
 * Return:
 *	Pointer to read SuggestResponse structure.
 *
\*----------------------------------------------------------------------------*/
static SuggestResponsePtr
NetSuggestReadAsn(void)
{
    SuggestResponsePtr pSuggResp;
    short erract;
    ErrDesc err;

    ErrGetOpts(&erract, NULL);
    ErrSetOpts(ERR_IGNORE, 0);
    ErrFetch(&err); /* clear any pending error */

    pSuggResp = SuggestResponseAsnRead(pAsnIn, NULL);

    if (ErrFetch(&err))
    {
        ErrPost(CTX_UNKNOWN, 1, "Null message read from server");
    }
    ErrSetOpts(erract, 0);

    return pSuggResp;
}
Exemple #4
0
int
#endif
main(int argc, char *argv[])
{
  Nlm_Int2 retval;

  Nlm_SetupArguments(argc, argv);

#ifdef MSC_VIRT
  if ( !_vheapinit(0, 1250, _VM_ALLSWAP) )
    {
      ErrPost(CTX_NCBIOBJ, 1, "Can't open virtual memory");
      return 1;
    }
#endif

  /* Initialize connection library's logger, registry and lock */
  CONNECT_Init(0);

  retval = Nlm_Main();

  NlmThreadJoinAll();

  Nlm_FreeConfigStruct();
  ErrSetLogfile(NULL, 0);
  Nlm_ReleaseAppContext();

#ifdef MSC_VIRT
  _vheapterm();
#endif

  NlmThreadDestroyAll();

#if   defined(OS_MSWIN)
  return retval;
#elif defined(OS_UNIX) || defined(OS_VMS)
  exit( retval );
#endif
}
Exemple #5
0
/**************************************************
*
*    PrintFormatListFree()
*
**************************************************/
NLM_EXTERN PrintFormatListPtr PrintFormatListFree ( PrintFormatListPtr ptr)
{
	Int2 i;

	if (ptr == NULL) return NULL;

	for (i = 0; i < ptr->numitem; i++)
	{
		MemFree(ptr->list[i].types);
	}
	MemFree(ptr->list);
    for (i = 0; i < PFLnum; i++)
    {
        if (PFLlist[i] == ptr)
        {
            PFLlist[i] = NULL;
            return MemFree(ptr);
        }
    }
    ErrPost(CTX_NCBIOBJ, 1, "PrintFormatListFree: pointer not in PFLlist");
	return MemFree(ptr);
}
Exemple #6
0
Boolean ID1ArchInit (void)

{
    

    myNetInit = ID1ArchInit;

    if (! NetInit())
        return FALSE;

    svcp = NI_GenericGetService(dispatcher, NULL, "ID1", "ID1", TRUE);
    if (svcp == NULL)
    {
        ErrPost(CTX_UNKNOWN, 1, "NI_ServiceGet [%s] (%s)", ni_errlist[ni_errno], ni_errtext);
        ID1ArchFini();
        return FALSE;
    }

    asnin = svcp->raip;
    AsnIoSetBufsize(asnin,4390);
    asnout = svcp->waip;
    return TRUE;
}
Exemple #7
0
SeqEntryPtr
ID1ArchSeqEntryGet (Int4 gi,CharPtr db, Int4 ent, Int4Ptr status, Int2 maxplex)
{
	Int4 i;
	SeqEntryPtr sep=NULL;
	Int4 retval = 0;
#if 0 
	if (maxplex < 0 || maxplex > 4){
		ErrPost(CTX_UNKNOWN, 2, "ID1ArchSeqEntryGet: maxplex(%d) out of range (0-4)", maxplex);
		return NULL;
	}
#endif
	for (i = 0; i < ID_SERV_RETRIES; i++){
		if (i > 0){
			if (! ReestablishNetID1Arch())
			break;
		}
		sep = s_ID1ArchSeqEntryGet (gi, db, ent, status, maxplex);
		if (sep) break; /* success */
		if(status && *status > 0 ) break; /* valid error - no retry */
	}
	return sep;
}
Exemple #8
0
/*****************************************************************************
*
*   PubSetAsnRead(aip, atp)
*   	atp is the current type (if identifier of a parent struct)
*            assumption is readIdent has occurred
*       if atp == NULL, then assumes it stands alone and read ident
*            has not occurred.
*
*****************************************************************************/
NLM_EXTERN ValNodePtr LIBCALL PubSetAsnRead (AsnIoPtr aip, AsnTypePtr orig)
{
	DataVal av;
	AsnTypePtr atp, settype;
    Pointer pnt;
    ValNodePtr anp=NULL, cit, curr;
    Uint1 choice;
    AsnReadFunc func;
    Boolean first;

	if (! loaded)
	{
		if (! PubAsnLoad())
			return anp;
	}

	if (aip == NULL)
		return anp;

	if (orig == NULL)           /* PubSet ::= (self contained) */
		atp = AsnReadId(aip, amp, PUB_SET);
	else
		atp = AsnLinkType(orig, PUB_SET);    /* link in local tree */
    if (atp == NULL) return anp;

	anp = ValNodeNew(NULL);
    if (anp == NULL) goto erret;

	if (AsnReadVal(aip, atp, &av) <= 0)    /* read the CHOICE value (nothing) */
        goto erret;
	settype = AsnReadId(aip, amp, atp);  /* find the choice */
    if (settype == NULL) goto erret;
    if (AsnReadVal(aip, settype, &av) <= 0)    /* read START_STRUCT */
        goto erret;

	if (settype == PUB_SET_pub)
    {
        choice = 1;
        func = (AsnReadFunc) PubAsnRead;
    }
    else if (settype == PUB_SET_medline)
    {
        choice = 3;
        func = (AsnReadFunc) MedlineEntryAsnRead;
    }
    else if (settype == PUB_SET_article)
    {
        choice = 5;
        func = (AsnReadFunc) CitArtAsnRead;
    }
    else if (settype == PUB_SET_journal)
    {
        choice = 6;
        func = (AsnReadFunc) CitJourAsnRead;
    }
    else if (settype == PUB_SET_book)
    {
        choice = 7;
        func = (AsnReadFunc) CitBookAsnRead;
    }
    else if (settype == PUB_SET_proc)
    {
        choice = 8;
        func = (AsnReadFunc) CitBookAsnRead;
    }
    else if (settype == PUB_SET_patent)
    {
        choice = 9;
        func = (AsnReadFunc) CitPatAsnRead;
    }

    anp->choice = choice;
    first = TRUE;
    curr = NULL;
    while ((atp = AsnReadId(aip, amp, settype)) != settype)
    {
        if (atp == NULL) goto erret;
        pnt = (* func)(aip, atp);
        if (pnt == NULL) goto erret;
        if (settype == PUB_SET_pub)   /* already a Pub */
        {
            cit = (ValNodePtr)pnt;
        }
        else                          /* make into a Pub */
        {
            cit = ValNodeNew(NULL);
            if (cit == NULL) goto erret;
            cit->data.ptrvalue = pnt;
            cit->choice = choice;
        }

        if (first)
        {
            anp->data.ptrvalue = (Pointer)cit;
            first = FALSE;
        }
        else
        {
            curr->next = cit;
        }
        curr = cit;
    }
    if (AsnReadVal(aip, settype, &av) <= 0)   /* read END_STRUCT for SET OF */
        goto erret;
	if (anp == NULL)
		ErrPost(CTX_NCBIOBJ, 1, "Empty SET OF Pub.  line %ld", aip->linenumber);
ret:
	AsnUnlinkType(orig);       /* unlink local tree */
	return anp;
erret:
    anp = PubSetFree(anp);
    goto ret;
}
Exemple #9
0
PCSAN LIBCALL LoadCSAN(CharPtr pcFile)
{

   FILE *f;
   Char fullpath [PATH_MAX];
   CharPtr ptr;
   PCSAN pcsanHead = NULL;
   PCSAN pcsanTemp = NULL;
   Char pcBuf[250];
   CharPtr ppcParse[125];
   CharPtr pcTemp = NULL;
   CharPtr pcTest = NULL;
   CharPtr pcSeqPart = NULL;
   ValNodePtr pvn = NULL;
   long int val = 0;
   Int4 i = 0;
   Int4 iString = 0;
   Int4 iLen =0;
   Int4 iWC =0;
   Int4 iWL = 0;
   Int4 iGi = 0;

   if (!pcFile) return(NULL);

   ProgramPath (fullpath, sizeof (fullpath) - 1);
   ptr = StringRChr (fullpath, DIRDELIMCHR);
   if (ptr != NULL) {
      *ptr = '\0';
   }

   /* printf("FULLPATH[%s]\n",IsNullStr(fullpath)); */

   FileBuildPath (fullpath, NULL, pcFile);
   /* printf("FULLPATH[%s]\n",IsNullStr(fullpath)); */

   if ((f = FileOpen (fullpath, "r")) == NULL)
     {
      if (FindPath ("NCBI", "NCBI", "DATA", fullpath, sizeof (fullpath) - 1))
        {
          FileBuildPath (fullpath, NULL, pcFile);
          f = FileOpen (fullpath, "r");
          if (f == NULL)
	    {
             ErrPost(CTX_NCBIOBJ, 1, "Couldn't open [%s] in LoadCSA", IsNullStr(fullpath));
             return (NULL);
            }
       }
     else
       {
         ErrPost(CTX_NCBIOBJ, 1, "FindPath failed in LoadNeighbors");
         return (NULL);
       }
    }

  do   /* get each line, tokenize into ppcParse */
     {
      pcBuf[0] = '\0';
      pcTest = fgets(pcBuf,  (size_t)250,  f);
      /* printf("[%s]\n",IsNullStr(pcTest)); */
      if (pcTest)
        {
		   iLen = StringLen(pcTest);
           /* Break into words delimited by whitespace or "|" */
           /* gi|123456| */
           /* printf("LineLength %d\n",(int) iLen); */
           for (i=0; i < 125; i++) ppcParse[i] = NULL;
           pcTemp = pcTest;
           ppcParse[0] = pcTest;
           iWC = 1;
           while ((*pcTemp != '\0') && (iWC < 125))
             {
                 if ((*pcTemp == '|') || (*pcTemp == ' ') || (*pcTemp == '\t') || (*pcTemp == '\n'))
                   {
                      *pcTemp = '\0';  /* terminate current word */
                       do {
                            pcTemp++;  /* skip whitespace to next word */
                          }  while ((*pcTemp == '|') || (*pcTemp == ' ') || (*pcTemp == '\t') || (*pcTemp == '\n'));
                       ppcParse[iWC] = pcTemp;  /* start next word */
                       iWC++;
                   }
                 else
                   pcTemp++;
             }

     /* DEBUG TEST */

/*           for (i=0; i<125; i++)
             if (ppcParse[i] != NULL)
               {
                 printf("%ld/%ld [%s]\n",i,iWC, IsNullStr(ppcParse[i]));
               } */

     /* If ppcParse[0] is "gi" then this is a VALID sequence line and the last
        word parsed is the sequence */
      if (ppcParse[0][0] != '\0')
        {
           iWL = StringLen(ppcParse[0]);
           if (iWL == 2)
             if (((ppcParse[0][0] == 'g') ||
                (ppcParse[0][0] == 'G')) &&
                ((ppcParse[0][1] == 'i') ||
                (ppcParse[0][1] == 'I')))
               {
                 /* next word should be GI */
                  iGi = 0;
                  if (StrToInt4 (ppcParse[1], &iGi))
                    {
                      /* printf("GI is (%ld)\n",iGi); */
                      if (iGi == 0) goto parserr;
                      /* find the 2nd last string = sequence */
                      /* last string is stripped off line terminator, by the way... */
                      iString=2; /* start after GI */
                      while (ppcParse[iString+1] != NULL)
                        {  /* iString is the LAST sting - line terminator */
                              iString++;
                         }
                      pcsanTemp = pcsanHead;
                      while (pcsanTemp)
                        {  /* look for existing pcsan */
                         if (iGi == pcsanTemp->iGi)
                          {
                            break;
                          }
                         pcsanTemp = pcsanTemp->next;
                        }
                      if (!pcsanTemp) /* otherwise add a new one */
                        {
                          pcsanTemp = NewCSAN();
                          pcsanTemp->next = pcsanHead;
                          pcsanHead = pcsanTemp; /* put at head of list */
                          pcsanTemp->iGi = iGi;
                        }
                      /* Initialize fields */
                      pcSeqPart = NULL;
                      pcSeqPart = StringSave(ppcParse[iString-1]);
                      /* printf("SEQ [%ld]= [%s]\n",(long) iString-1, IsNullStr(pcSeqPart)); */
                      ValNodeAddStr(&pcsanTemp->pvnSeqAlnPart, 0,  pcSeqPart);
                    }  /* if GI */
               }  /* if line starts with GI */
         }  /* if line starts with a word */
      } /* if pcTest */
    } while (pcTest);


  printf("REPORT\n");
  pcsanTemp = pcsanHead;
  while (pcsanTemp)
  {
     printf("GI = [%ld]\n", (long) pcsanTemp->iGi);
     pvn = pcsanTemp->pvnSeqAlnPart;
     while (pvn)
       {
         printf(">%s<\n",(char *) IsNullStr(pvn->data.ptrvalue));
         pvn = pvn->next;
       }
     pcsanTemp = pcsanTemp->next;
  }

   FileClose(f);
   return pcsanHead;


parserr:
   FileClose(f);
   ErrPostEx(SEV_FATAL,0,0, "Error in input format \n");
   FreeCSAN(pcsanHead);
   return NULL;

}
Exemple #10
0
/*****************************************************************************
*
*   LinkSetAsnRead(aip, atp)
*   	atp is the current type (if identifier of a parent struct)
*            assumption is readIdent has occurred
*       if atp == NULL, then assumes it stands alone and read ident
*            has not occurred.
*
*****************************************************************************/
NLM_EXTERN LinkSetPtr LIBCALL LinkSetAsnRead (AsnIoPtr aip, AsnTypePtr orig)
{
	DataVal av;
	AsnTypePtr atp;
    LinkSetPtr lsp=NULL;
    Int4 num, i;
    Int4Ptr ptr;

	if (! loaded)
	{
		if (! AccessAsnLoad())
			return lsp;
	}

	if (aip == NULL)
		return lsp;

	if (orig == NULL)           /* LinkSet ::= (self contained) */
		atp = AsnReadId(aip, amp, LINK_SET);
	else
		atp = AsnLinkType(orig, LINK_SET);    /* link in local tree */
    if (atp == NULL)
        return lsp;

	lsp = LinkSetNew();
    if (lsp == NULL)
        goto erret;

	if (AsnReadVal(aip, atp, &av) <= 0)    /* read the start struct */
        goto erret;
	atp = AsnReadId(aip, amp, atp);  /* find the num */
    if (atp == NULL)
        goto erret;
	if (AsnReadVal(aip, atp, &av) <= 0)     /* get the num */
        goto erret;
    num = av.intvalue;
    lsp->num = num;

    atp = AsnReadId(aip, amp, atp);  /* start seq of uids */
    if (atp == NULL)
        goto erret;
    if (AsnReadVal(aip, atp, &av) <= 0)
        goto erret;
    ptr = (Int4Ptr)MemNew((size_t)(sizeof(Int4) * (num + 1)));  /* 0 sentinel at end */
    if (ptr == NULL)
        goto erret;
    lsp->uids = ptr;
    i = 0;
    while ((atp = AsnReadId(aip, amp, atp)) == LINK_SET_uids_E)
    {
        if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
        ptr[i] = av.intvalue;
        i++;
        if (i > num)
            break;
    }
    if (atp == NULL)
        goto erret;
    if (i != num)
    {
        ErrPost(CTX_NCBIOBJ, 0, "Incorrect number of uids in Link-set. line %ld",
            aip->linenumber);
        goto erret;
    }
    if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end seq of */

    atp = AsnReadId(aip, amp, atp);
    if (atp == NULL)
        goto erret;
    if (atp == LINK_SET_weights)
    {
        if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
        ptr = (Int4Ptr)MemNew((size_t)(sizeof(Int4) * (num + 1)));  /* 0 sentinel at end */
        if (ptr == NULL)
            goto erret;
        lsp->weights = ptr;
        i = 0;
        while ((atp = AsnReadId(aip, amp, atp)) == LINK_SET_weights_E)
        {
            if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
            ptr[i] = av.intvalue;
            i++;
            if (i > num)
                break;
        }
        if (atp == NULL)
            goto erret;
        if (i != num)
        {   
            ErrPost(CTX_NCBIOBJ, 0, "Incorrect number of weights in Link-set. line %ld",
                aip->linenumber);
            goto erret;
        }
        if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end seq of */

	    if ((atp = AsnReadId(aip, amp, atp)) == NULL)
	        goto erret;
    }

    if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end struct */
ret:
	AsnUnlinkType(orig);       /* unlink local tree */
	return lsp;
erret:
    lsp = LinkSetFree(lsp);
    goto ret;
}
Exemple #11
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;
}
Exemple #12
0
/*****************************************************************************
*
*   PrintFormatTraverse(pfp, pflp, index, indent)
*
*****************************************************************************/
NLM_EXTERN Int2 PrintFormatTraverse(PrintFormatPtr pfp, PrintFormatListPtr pflp, Int2 index, Int2 indent)
{
	PrintFormatItemPtr pfip;
	CharPtr template_format;
	PrintTemplatePtr usetemplate;
	Int2 count = 0, retcount;
	PrintFormBlockPtr pfbp;
	AsnTypePtr atp;
	AsnTypePtr PNTR typeptr = NULL;
	Int2 typecount = 0;

	while (pfp != NULL)
	{
		usetemplate = NULL;
		if (pfp->form->choice == PrintForm_use_template)
		{
			template_format = (CharPtr)(pfp->form->data.ptrvalue);
			usetemplate = PrintTemplateFind(template_format);
			if (usetemplate == NULL)
			{
				ErrPost(CTX_OBJPRT, 1, "..couldn't find template [%s]\n", template_format);
				return 0;
			}
			
		}
		if (pflp != NULL)
		{
			pfip = &(pflp->list[index]);
			pfip->sort_key = index;
			pfip->indent_level = indent;
			pfip->format = pfp;
			atp = AsnFind(pfp->asn1);   /* get the node */
			if (atp == NULL)
			{
				ErrPost(CTX_OBJPRT, 1, "PrintFormatTraverse: can't find [%s]", pfp->asn1);
				return 0;
			}
			pfip->atp = atp;
			pfip->isa = AsnFindBaseIsa(atp);
			
			pfip->_template = usetemplate;
			typeptr = AsnTypePathFind(NULL, pfp->asn1, &typecount);
			if (typeptr == NULL)
				return 0;
			pfip->types = typeptr;
			pfip->numtypes = typecount;

		}
		index++;
		count++;
		if (pfp->form->choice == PrintForm_block)
		{
			pfbp = (PrintFormBlockPtr)(pfp->form->data.ptrvalue);
			retcount = PrintFormatTraverse(pfbp->components, pflp, index, (Int2)(indent+1));

			if (retcount == 0)  /* failure */
				return 0;
			count += retcount;
			index += retcount;
		}
		pfp = pfp->next;
	}
	return count;
}
Exemple #13
0
/*****************************************************************************
*
*   PrintTemplateSetPtr PrintTemplateSetLoad()
*       loads PrintTemplates
*       If path== NULL, looks for "prt.prt" in the "data" directory
*
*****************************************************************************/
static Boolean PrintTemplateSetLoadInt ( CharPtr path, Boolean verbose )
{
	AsnIoPtr aip;
	FILE *f;
	Boolean retval;
	Char filename [80];
	Char fullpath [PATH_MAX];
	CharPtr ptr;
	ErrSev lastLevel;

	aip = NULL;
	if (path != NULL && *path != '\0' && StringRChr (path, DIRDELIMCHR) != NULL) {
		StringNCpy (fullpath, path, sizeof (fullpath) - 1);
		if ((aip = AsnIoOpen (fullpath, "r")) == NULL) {
		    if (verbose) {
	    		ErrPost(CTX_NCBIOBJ, 1, "Couldn't open [%s]", fullpath);
		    }
			return FALSE;
		}
	} else {
		if (path != NULL && *path != '\0') {
			StringNCpy (filename, path, sizeof (filename) - 1);
		} else {
			StringCpy (filename, "prt.prt");
		}
		ProgramPath (fullpath, sizeof (fullpath) - 1);
		ptr = StringRChr (fullpath, DIRDELIMCHR);
		if (ptr != NULL) {
			*ptr = '\0';
		}
		FileBuildPath (fullpath, NULL, filename);
		/* silence SEV_INFO errors from FileOpen() */
		if ((lastLevel = ErrGetMessageLevel()) < SEV_WARNING)
			ErrSetMessageLevel (SEV_WARNING);
		if ((f = FileOpen (fullpath, "r")) == NULL) {
			ErrSetMessageLevel (lastLevel);
			if (FindPath ("NCBI", "NCBI", "DATA", fullpath, sizeof (fullpath) - 1)) {
				FileBuildPath (fullpath, NULL, filename);
				if ((aip = AsnIoOpen (fullpath, "r")) == NULL) {
				    if (verbose) {
					    ErrPost(CTX_NCBIOBJ, 1, "Couldn't open [%s]", fullpath);
				    }
					return FALSE;
				}
			} else {
			    if (verbose) {
			    	ErrPost(CTX_NCBIOBJ, 1, "FindPath failed in PrintTemplateSetLoad - ncbi configuration file missing or incorrect");
			    }
				return FALSE;
			}
		} else {
			ErrSetMessageLevel (lastLevel);
			FileClose (f);
			if ((aip = AsnIoOpen(fullpath, "r")) == NULL) {
			    if (verbose) {
				    ErrPost(CTX_NCBIOBJ, 1, "Couldn't open [%s]", fullpath);
			    }
				return FALSE;
			}
		}
	}

    retval = PrintTemplateSetAsnRead(aip);

    AsnIoClose(aip);
    return retval;
}