NCBI C Toolkit Cross Reference

C/object/objblock.c


  1 /*  objblock.c
  2 * ===========================================================================
  3 *
  4 *                            PUBLIC DOMAIN NOTICE                          
  5 *               National Center for Biotechnology Information
  6 *                                                                          
  7 *  This software/database is a "United States Government Work" under the   
  8 *  terms of the United States Copyright Act.  It was written as part of    
  9 *  the author's official duties as a United States Government employee and 
 10 *  thus cannot be copyrighted.  This software/database is freely available 
 11 *  to the public for use. The National Library of Medicine and the U.S.    
 12 *  Government have not placed any restriction on its use or reproduction.  
 13 *                                                                          
 14 *  Although all reasonable efforts have been taken to ensure the accuracy  
 15 *  and reliability of the software and data, the NLM and the U.S.          
 16 *  Government do not and cannot warrant the performance or results that    
 17 *  may be obtained by using this software or data. The NLM and the U.S.    
 18 *  Government disclaim all warranties, express or implied, including       
 19 *  warranties of performance, merchantability or fitness for any particular
 20 *  purpose.                                                                
 21 *                                                                          
 22 *  Please cite the author in any work or product based on this material.   
 23 *
 24 * ===========================================================================
 25 *
 26 * File Name:  objblock.c
 27 *
 28 * Author:  James Ostell
 29 *   
 30 * Version Creation Date: 8/10/92
 31 *
 32 * $Revision: 6.3 $
 33 *
 34 * File Description:  Object manager for module GenBank-General,
 35 *                                       EMBL-General, PIR-General, SWISSPROT-General
 36 *
 37 * Modifications:  
 38 * --------------------------------------------------------------------------
 39 * Date     Name        Description of modification
 40 * -------  ----------  -----------------------------------------------------
 41 * 05-13-93 Schuler     All public functions are now declared LIBCALL.
 42 * 05-17-93 Schuler     pdbblock.class renamed pdpblock.pdbclass because
 43 *                      class is a C++ keyword.
 44 *
 45 * $Log: objblock.c,v $
 46 * Revision 6.3  2004/04/01 13:43:07  lavr
 47 * Spell "occurred", "occurrence", and "occurring"
 48 *
 49 * Revision 6.2  2003/05/16 17:21:05  bazhin
 50 * Fixed bug in PrfBlockAsnWrite().
 51 *
 52 * Revision 6.1  1998/08/24 18:27:59  kans
 53 * removed solaris -v -fd warnings
 54 *
 55 * Revision 6.0  1997/08/25 18:49:26  madden
 56 * Revision changed to 6.0
 57 *
 58 * Revision 4.1  1997/06/19 18:40:54  vakatov
 59 * [WIN32,MSVC++]  Adopted for the "NCBIOBJ.LIB" DLL'ization
 60 *
 61 * Revision 4.0  1995/07/26 13:48:06  ostell
 62 * force revision to 4.0
 63 *
 64  * Revision 3.1  1995/05/15  21:22:00  ostell
 65  * added Log line
 66  *
 67 *
 68 *
 69 * ==========================================================================
 70 */
 71 #include <objblock.h>              /* the public interface */
 72 #include <asnblock.h>        /* the AsnTool header */
 73 
 74 static Boolean loaded = FALSE;
 75 
 76 /*****************************************************************************
 77 *
 78 *   SeqBlockAsnLoad()
 79 *
 80 *****************************************************************************/
 81 NLM_EXTERN Boolean LIBCALL SeqBlockAsnLoad (void)
 82 {
 83     if (loaded)
 84         return TRUE;
 85     loaded = TRUE;
 86 
 87     if (! GeneralAsnLoad())
 88     {
 89         loaded = FALSE;
 90         return FALSE;
 91     }
 92     if (! SeqLocAsnLoad())
 93     {
 94         loaded = FALSE;
 95         return FALSE;
 96     }
 97     if (! AsnLoad())
 98     {
 99         loaded = FALSE;
100         return FALSE;
101     }
102     return TRUE;
103 }
104 
105 /*****************************************************************************
106 *
107 *   PirBlockNew()
108 *
109 *****************************************************************************/
110 NLM_EXTERN PirBlockPtr LIBCALL PirBlockNew (void)
111 {
112     return (PirBlockPtr)MemNew(sizeof(PirBlock));
113 }
114 
115 /*****************************************************************************
116 *
117 *   PirBlockFree(pbp)
118 *       Frees a PirBlock and associated data
119 *
120 *****************************************************************************/
121 NLM_EXTERN PirBlockPtr LIBCALL PirBlockFree (PirBlockPtr pbp)
122 {
123     if (pbp == NULL)
124         return pbp;
125 
126     MemFree(pbp->host);
127     MemFree(pbp->source);
128     MemFree(pbp->summary);
129     MemFree(pbp->genetic);
130     MemFree(pbp->includes);
131     MemFree(pbp->placement);
132     MemFree(pbp->superfamily);
133     ValNodeFreeData(pbp->keywords);
134     MemFree(pbp->cross_reference);
135     MemFree(pbp->date);
136     MemFree(pbp->seq_raw);
137     SeqIdSetFree(pbp->seqref);
138         return (PirBlockPtr)MemFree(pbp);
139 }
140 /*****************************************************************************
141 *
142 *   PirBlockAsnWrite(pbp, aip, atp)
143 *       atp is the current type (if identifier of a parent struct)
144 *       if atp == NULL, then assumes it stands alone (PirBlock ::=)
145 *
146 *****************************************************************************/
147 NLM_EXTERN Boolean LIBCALL PirBlockAsnWrite (PirBlockPtr pbp, AsnIoPtr aip, AsnTypePtr orig)
148 {
149         DataVal av;
150         AsnTypePtr atp;
151     ValNodePtr anp;
152     Boolean retval = FALSE;
153 
154         if (! loaded)
155         {
156                 if (! SeqBlockAsnLoad())
157                         return FALSE;
158         }
159 
160         if (aip == NULL)
161                 return FALSE;
162 
163         atp = AsnLinkType(orig, PIR_BLOCK);   /* link local tree */
164     if (atp == NULL) goto erret;
165 
166         if (pbp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
167 
168     if (! AsnOpenStruct(aip, atp, (Pointer)pbp)) goto erret;
169 
170     if (pbp->had_punct)
171     {
172         av.boolvalue = pbp->had_punct;
173         if (! AsnWrite(aip, PIR_BLOCK_had_punct, &av)) goto erret;
174     }
175     if (pbp->host != NULL)
176     {
177         av.ptrvalue = pbp->host;
178         if (! AsnWrite(aip, PIR_BLOCK_host, &av)) goto erret;
179     }
180     if (pbp->source != NULL)
181     {
182         av.ptrvalue = pbp->source;
183         if (! AsnWrite(aip, PIR_BLOCK_source, &av)) goto erret;
184     }
185     if (pbp->summary != NULL)
186     {
187         av.ptrvalue = pbp->summary;
188         if (! AsnWrite(aip, PIR_BLOCK_summary, &av)) goto erret;
189     }
190     if (pbp->genetic != NULL)
191     {
192         av.ptrvalue = pbp->genetic;
193         if (! AsnWrite(aip, PIR_BLOCK_genetic, &av)) goto erret;
194     }
195     if (pbp->includes != NULL)
196     {
197         av.ptrvalue = pbp->includes;
198         if (! AsnWrite(aip, PIR_BLOCK_includes, &av)) goto erret;
199     }
200     if (pbp->placement != NULL)
201     {
202         av.ptrvalue = pbp->placement;
203         if (! AsnWrite(aip, PIR_BLOCK_placement, &av)) goto erret;
204     }
205     if (pbp->superfamily != NULL)
206     {
207         av.ptrvalue = pbp->superfamily;
208         if (! AsnWrite(aip, PIR_BLOCK_superfamily, &av)) goto erret;
209     }
210     if (pbp->keywords != NULL)
211     {
212         if (! AsnOpenStruct(aip, PIR_BLOCK_keywords, (Pointer)pbp->keywords)) goto erret;
213         anp = pbp->keywords;
214         while (anp != NULL)
215         {
216             if (! AsnWrite(aip, PIR_BLOCK_keywords_E, &anp->data)) goto erret;
217             anp = anp->next;
218         }
219         if (! AsnCloseStruct(aip, PIR_BLOCK_keywords, (Pointer)pbp->keywords)) goto erret;
220     }
221     if (pbp->cross_reference != NULL)
222     {
223         av.ptrvalue = pbp->cross_reference;
224         if (! AsnWrite(aip, PIR_BLOCK_cross_reference, &av)) goto erret;
225     }
226     if (pbp->date != NULL)
227     {
228         av.ptrvalue = pbp->date;
229         if (! AsnWrite(aip, PIR_BLOCK_date, &av)) goto erret;
230     }
231     if (pbp->seq_raw != NULL)
232     {
233         av.ptrvalue = pbp->seq_raw;
234         if (! AsnWrite(aip, PIR_BLOCK_seq_raw, &av)) goto erret;
235     }
236     if (pbp->seqref != NULL)
237         {
238         if (! SeqIdSetAsnWrite(pbp->seqref, aip, PIR_BLOCK_seqref, PIR_BLOCK_seqref_E))
239                         goto erret;
240         }
241 
242     if (! AsnCloseStruct(aip, atp, (Pointer)pbp)) goto erret;
243     retval = TRUE;
244 erret:
245         AsnUnlinkType(orig);       /* unlink local tree */
246         return retval;
247 }
248 
249 /*****************************************************************************
250 *
251 *   PirBlockAsnRead(aip, atp)
252 *       atp is the current type (if identifier of a parent struct)
253 *            assumption is readIdent has occurred
254 *       if atp == NULL, then assumes it stands alone and read ident
255 *            has not occurred.
256 *
257 *****************************************************************************/
258 NLM_EXTERN PirBlockPtr LIBCALL PirBlockAsnRead (AsnIoPtr aip, AsnTypePtr orig)
259 {
260         DataVal av;
261         AsnTypePtr atp, oldatp;
262     PirBlockPtr pbp=NULL;
263     ValNodePtr tmp, tmp2;
264 
265         if (! loaded)
266         {
267                 if (! SeqBlockAsnLoad())
268                         return pbp;
269         }
270 
271         if (aip == NULL)
272                 return pbp;
273 
274         if (orig == NULL)           /* PirBlock ::= (self contained) */
275                 atp = AsnReadId(aip, amp, PIR_BLOCK);
276         else
277                 atp = AsnLinkType(orig, PIR_BLOCK);    /* link in local tree */
278     oldatp = atp;
279     if (atp == NULL) return pbp;
280 
281     pbp = PirBlockNew();
282     if (pbp == NULL) goto erret;
283 
284     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* read the start struct */
285     
286     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
287     {
288         if (atp == NULL) goto erret;
289         if (atp == PIR_BLOCK_seqref)
290                 {
291             pbp->seqref = SeqIdSetAsnRead(aip, atp, PIR_BLOCK_seqref_E);
292                         if (pbp->seqref == NULL) goto erret;
293                 }
294                 else
295                 {
296                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
297             if (atp == PIR_BLOCK_host)
298                     pbp->host = (CharPtr)av.ptrvalue;
299                 else if (atp == PIR_BLOCK_source)
300                 pbp->source = (CharPtr)av.ptrvalue;
301                 else if (atp == PIR_BLOCK_had_punct)
302                 pbp->had_punct = av.boolvalue;
303                 else if (atp == PIR_BLOCK_cross_reference)
304                  pbp->cross_reference = (CharPtr)av.ptrvalue;
305             else if (atp == PIR_BLOCK_seq_raw)
306                     pbp->seq_raw = (CharPtr)av.ptrvalue;
307                 else if (atp == PIR_BLOCK_summary)
308                 pbp->summary = (CharPtr)av.ptrvalue;
309                 else if (atp == PIR_BLOCK_genetic)
310                 pbp->genetic = (CharPtr)av.ptrvalue;
311                 else if (atp == PIR_BLOCK_includes)
312                 pbp->includes = (CharPtr)av.ptrvalue;
313                 else if (atp == PIR_BLOCK_placement)
314                 pbp->placement = (CharPtr)av.ptrvalue;
315                 else if (atp == PIR_BLOCK_superfamily)
316                 pbp->superfamily = (CharPtr)av.ptrvalue;
317                 else if (atp == PIR_BLOCK_date)
318                 pbp->date = (CharPtr)av.ptrvalue;
319                 else if (atp == PIR_BLOCK_keywords)
320             {
321                     tmp = NULL;
322                 while ((atp = AsnReadId(aip, amp, atp)) == PIR_BLOCK_keywords_E)
323                     {
324                     tmp2 = ValNodeNew(tmp);
325                         if (tmp2 == NULL) goto erret;
326                     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
327                         tmp2->data.ptrvalue = av.ptrvalue;
328                         if (tmp == NULL)
329                         pbp->keywords = tmp2;
330                         tmp = tmp2;
331                 }
332                     if (atp == NULL) goto erret;
333                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end struct */
334                 }
335                 }
336     }
337     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* end struct */
338 ret:
339         AsnUnlinkType(orig);       /* unlink local tree */
340         return pbp;
341 erret:
342     pbp = PirBlockFree(pbp);
343     goto ret;
344 }
345 
346 /*****************************************************************************
347 *
348 *   GBBlockNew()
349 *
350 *****************************************************************************/
351 NLM_EXTERN GBBlockPtr LIBCALL GBBlockNew (void)
352 {
353     return (GBBlockPtr)MemNew(sizeof(GBBlock));
354 }
355 
356 /*****************************************************************************
357 *
358 *   GBBlockFree(gbp)
359 *       Frees a GBBlock and associated data
360 *
361 *****************************************************************************/
362 NLM_EXTERN GBBlockPtr LIBCALL GBBlockFree (GBBlockPtr gbp)
363 {
364     if (gbp == NULL)
365         return gbp;
366 
367     ValNodeFreeData(gbp->extra_accessions);
368     MemFree(gbp->source);
369     MemFree(gbp->origin);
370     ValNodeFreeData(gbp->keywords);
371     MemFree(gbp->date);
372     MemFree(gbp->div);
373     MemFree(gbp->taxonomy);
374     DateFree(gbp->entry_date);
375         return (GBBlockPtr)MemFree(gbp);
376 }
377 
378 /*****************************************************************************
379 *
380 *   GBBlockAsnWrite(gbp, aip, atp)
381 *       atp is the current type (if identifier of a parent struct)
382 *       if atp == NULL, then assumes it stands alone (GBBlock ::=)
383 *
384 *****************************************************************************/
385 NLM_EXTERN Boolean LIBCALL GBBlockAsnWrite (GBBlockPtr gbp, AsnIoPtr aip, AsnTypePtr orig)
386 {
387         DataVal av;
388         AsnTypePtr atp;
389     ValNodePtr anp;
390     Boolean retval = FALSE;
391 
392         if (! loaded)
393         {
394                 if (! SeqBlockAsnLoad())
395                         return FALSE;
396         }
397 
398         if (aip == NULL)
399                 return FALSE;
400 
401         atp = AsnLinkType(orig, GB_BLOCK);   /* link local tree */
402     if (atp == NULL) return FALSE;
403 
404         if (gbp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
405 
406     if (! AsnOpenStruct(aip, atp, (Pointer)gbp)) goto erret;
407 
408     if (gbp->extra_accessions != NULL)
409     {
410         if (! AsnOpenStruct(aip, GB_BLOCK_extra_accessions, (Pointer)gbp->extra_accessions)) goto erret;
411         anp = gbp->extra_accessions;
412         while (anp != NULL)
413         {
414             if (! AsnWrite(aip, GB_BLOCK_extra_accessions_E, &anp->data)) goto erret;
415             anp = anp->next;
416         }
417         if (! AsnCloseStruct(aip, GB_BLOCK_extra_accessions, (Pointer)gbp->extra_accessions)) goto erret;
418     }
419     if (gbp->source != NULL)
420     {
421         av.ptrvalue = gbp->source;
422         if (! AsnWrite(aip, GB_BLOCK_source, &av)) goto erret;
423     }
424     if (gbp->keywords != NULL)
425     {
426         if (! AsnOpenStruct(aip, GB_BLOCK_keywords, (Pointer)gbp->keywords)) goto erret;
427         anp = gbp->keywords;
428         while (anp != NULL)
429         {
430             if (! AsnWrite(aip, GB_BLOCK_keywords_E, &anp->data)) goto erret;
431             anp = anp->next;
432         }
433         if (! AsnCloseStruct(aip, GB_BLOCK_keywords, (Pointer)gbp->keywords)) goto erret;
434     }
435     if (gbp->origin != NULL)
436     {
437         av.ptrvalue = gbp->origin;
438         if (! AsnWrite(aip, GB_BLOCK_origin, &av)) goto erret;
439     }
440     if (gbp->date != NULL)
441     {
442         av.ptrvalue = gbp->date;
443         if (! AsnWrite(aip, GB_BLOCK_date, &av)) goto erret;
444     }
445     if (gbp->entry_date != NULL)
446     {
447         if (! DateAsnWrite(gbp->entry_date, aip, GB_BLOCK_entry_date)) goto erret;
448     }
449     if (gbp->div != NULL)
450     {
451         av.ptrvalue = gbp->div;
452         if (! AsnWrite(aip, GB_BLOCK_div, &av)) goto erret;
453     }
454     if (gbp->taxonomy != NULL)
455     {
456         av.ptrvalue = gbp->taxonomy;
457         if (! AsnWrite(aip, GB_BLOCK_taxonomy, &av)) goto erret;
458     }
459 
460     if (! AsnCloseStruct(aip, atp, (Pointer)gbp)) goto erret;
461     retval = TRUE;
462 erret:
463         AsnUnlinkType(orig);       /* unlink local tree */
464         return retval;
465 }
466 
467 /*****************************************************************************
468 *
469 *   GBBlockAsnRead(aip, atp)
470 *       atp is the current type (if identifier of a parent struct)
471 *            assumption is readIdent has occurred
472 *       if atp == NULL, then assumes it stands alone and read ident
473 *            has not occurred.
474 *
475 *****************************************************************************/
476 NLM_EXTERN GBBlockPtr LIBCALL GBBlockAsnRead (AsnIoPtr aip, AsnTypePtr orig)
477 {
478         DataVal av;
479         AsnTypePtr atp, oldatp;
480     GBBlockPtr gbp=NULL;
481     ValNodePtr tmp, tmp2;
482 
483         if (! loaded)
484         {
485                 if (! SeqBlockAsnLoad())
486                         return gbp;
487         }
488 
489         if (aip == NULL)
490                 return gbp;
491 
492         if (orig == NULL)           /* GBBlock ::= (self contained) */
493                 atp = AsnReadId(aip, amp, GB_BLOCK);
494         else
495                 atp = AsnLinkType(orig, GB_BLOCK);    /* link in local tree */
496     oldatp = atp;
497     if (atp == NULL) return gbp;
498 
499     gbp = GBBlockNew();
500     if (gbp == NULL) goto erret;
501 
502     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* read the start struct */
503     
504     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
505     {
506         if (atp == NULL) goto erret;
507         if (atp == GB_BLOCK_entry_date)
508         {
509             gbp->entry_date = DateAsnRead(aip, atp);
510             if (gbp->entry_date == NULL) goto erret;
511         }
512         else
513         {
514             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
515             if (atp == GB_BLOCK_source)
516                 gbp->source = (CharPtr)av.ptrvalue;
517             else if (atp == GB_BLOCK_origin)
518                 gbp->origin = (CharPtr)av.ptrvalue;
519             else if (atp == GB_BLOCK_date)
520                 gbp->date = (CharPtr)av.ptrvalue;
521             else if (atp == GB_BLOCK_keywords)
522             {
523                 tmp = NULL;
524                 while ((atp = AsnReadId(aip, amp, atp)) == GB_BLOCK_keywords_E)
525                 {
526                     tmp2 = ValNodeNew(tmp);
527                     if (tmp2 == NULL) goto erret;
528                     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
529                     tmp2->data.ptrvalue = av.ptrvalue;
530                     if (tmp == NULL)
531                         gbp->keywords = tmp2;
532                     tmp = tmp2;
533                 }
534                 if (atp == NULL) goto erret;
535                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end struct */
536             }
537             else if (atp == GB_BLOCK_extra_accessions)
538             {
539                 tmp = NULL;
540                 while ((atp = AsnReadId(aip, amp, atp)) == GB_BLOCK_extra_accessions_E)
541                 {
542                     tmp2 = ValNodeNew(tmp);
543                     if (tmp2 == NULL) goto erret;
544                     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
545                     tmp2->data.ptrvalue = av.ptrvalue;
546                     if (tmp == NULL)
547                         gbp->extra_accessions = tmp2;
548                     tmp = tmp2;
549                 }
550                 if (atp == NULL) goto erret;
551                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end struct */
552             }
553             else if (atp == GB_BLOCK_div)
554                 gbp->div = (CharPtr)av.ptrvalue;
555             else if (atp == GB_BLOCK_taxonomy)
556                 gbp->taxonomy = (CharPtr)av.ptrvalue;
557         }
558     }
559     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* end struct */
560 ret:
561         AsnUnlinkType(orig);       /* unlink local tree */
562         return gbp;
563 erret:
564     gbp = GBBlockFree(gbp);
565     goto ret;
566 }
567 
568 /*****************************************************************************
569 *
570 *   SPBlockNew()
571 *
572 *****************************************************************************/
573 NLM_EXTERN SPBlockPtr LIBCALL SPBlockNew (void)
574 {
575     return (SPBlockPtr)MemNew(sizeof(SPBlock));
576 }
577 
578 /*****************************************************************************
579 *
580 *   SPBlockFree(sbp)
581 *       Frees a SPBlock and associated data
582 *
583 *****************************************************************************/
584 NLM_EXTERN SPBlockPtr LIBCALL SPBlockFree (SPBlockPtr sbp)
585 {
586     ValNodePtr anp, next;
587 
588     if (sbp == NULL)
589         return sbp;
590 
591     ValNodeFreeData(sbp->extra_acc);
592     ValNodeFreeData(sbp->plasnm);
593     SeqIdSetFree(sbp->seqref);
594     anp = sbp->dbref;
595     while (anp != NULL)
596     {
597         next = anp->next;
598         DbtagFree((DbtagPtr)anp->data.ptrvalue);
599         MemFree(anp);
600         anp = next;
601     }
602     ValNodeFreeData(sbp->keywords);
603         DateFree(sbp->created);
604         DateFree(sbp->sequpd);
605         DateFree(sbp->annotupd);
606         return (SPBlockPtr)MemFree(sbp);
607 }
608 
609 /*****************************************************************************
610 *
611 *   SPBlockAsnWrite(sbp, aip, atp)
612 *       atp is the current type (if identifier of a parent struct)
613 *       if atp == NULL, then assumes it stands alone (SPBlock ::=)
614 *
615 *****************************************************************************/
616 NLM_EXTERN Boolean LIBCALL SPBlockAsnWrite (SPBlockPtr sbp, AsnIoPtr aip, AsnTypePtr orig)
617 {
618         DataVal av;
619         AsnTypePtr atp;
620     ValNodePtr anp;
621         Boolean retval = FALSE;
622 
623         if (! loaded)
624         {
625                 if (! SeqBlockAsnLoad())
626                         return FALSE;
627         }
628 
629         if (aip == NULL)
630                 return FALSE;
631 
632         atp = AsnLinkType(orig, SP_BLOCK);   /* link local tree */
633         if (atp == NULL) return FALSE;
634 
635         if (sbp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
636 
637     if (! AsnOpenStruct(aip, atp, (Pointer)sbp)) goto erret;
638 
639     av.intvalue = sbp->_class;
640     if (! AsnWrite(aip, SP_BLOCK_class, &av)) goto erret;
641 
642     if (sbp->extra_acc != NULL)
643     {
644         if (! AsnOpenStruct(aip, SP_BLOCK_extra_acc, (Pointer)sbp->extra_acc)) goto erret;
645         anp = sbp->extra_acc;
646         while (anp != NULL)
647         {
648             if (! AsnWrite(aip, SP_BLOCK_extra_acc_E, &anp->data)) goto erret;
649             anp = anp->next;
650         }
651         if (! AsnCloseStruct(aip, SP_BLOCK_extra_acc, (Pointer)sbp->extra_acc)) goto erret;
652     }
653     if (sbp->imeth)
654     {
655         av.boolvalue = sbp->imeth;
656         if (! AsnWrite(aip, SP_BLOCK_imeth, &av)) goto erret;
657     }
658     if (sbp->plasnm != NULL)
659     {
660         if (! AsnOpenStruct(aip, SP_BLOCK_plasnm, (Pointer)sbp->plasnm)) goto erret;
661         anp = sbp->plasnm;
662         while (anp != NULL)
663         {
664             if (! AsnWrite(aip, SP_BLOCK_plasnm_E, &anp->data)) goto erret;
665             anp = anp->next;
666         }
667         if (! AsnCloseStruct(aip, SP_BLOCK_plasnm, (Pointer)sbp->plasnm)) goto erret;
668     }
669     if (sbp->seqref != NULL)
670         {
671         if (! SeqIdSetAsnWrite(sbp->seqref, aip, SP_BLOCK_seqref, SP_BLOCK_seqref_E))
672                         goto erret;
673         }
674 
675     if (sbp->dbref != NULL)
676     {
677         if (! AsnOpenStruct(aip, SP_BLOCK_dbref, (Pointer)sbp->dbref)) goto erret;
678         anp = sbp->dbref;
679         while (anp != NULL)
680         {
681             if (! DbtagAsnWrite((DbtagPtr)anp->data.ptrvalue, aip, SP_BLOCK_dbref_E))
682                                 goto erret;
683             anp = anp->next;
684         }
685         if (! AsnCloseStruct(aip, SP_BLOCK_dbref, (Pointer)sbp->dbref)) goto erret;
686     }
687 
688     if (sbp->keywords != NULL)
689     {
690         if (! AsnOpenStruct(aip, SP_BLOCK_keywords, (Pointer)sbp->keywords)) goto erret;
691         anp = sbp->keywords;
692         while (anp != NULL)
693         {
694             if (! AsnWrite(aip, SP_BLOCK_keywords_E, &anp->data)) goto erret;
695             anp = anp->next;
696         }
697         if (! AsnCloseStruct(aip, SP_BLOCK_keywords, (Pointer)sbp->keywords)) goto erret;
698     }
699 
700         if (sbp->created != NULL)
701         {
702                 if (! DateAsnWrite(sbp->created, aip, SP_BLOCK_created)) goto erret;
703         }
704 
705         if (sbp->sequpd != NULL)
706         {
707                 if (! DateAsnWrite(sbp->sequpd, aip, SP_BLOCK_sequpd)) goto erret;
708         }
709 
710         if (sbp->annotupd != NULL)
711         {
712                 if (! DateAsnWrite(sbp->annotupd, aip, SP_BLOCK_annotupd)) goto erret;
713         }
714 
715     if (! AsnCloseStruct(aip, atp, (Pointer)sbp)) goto erret;
716         retval = TRUE;
717 erret:
718         AsnUnlinkType(orig);       /* unlink local tree */
719         return retval;
720 }
721 
722 /*****************************************************************************
723 *
724 *   SPBlockAsnRead(aip, atp)
725 *       atp is the current type (if identifier of a parent struct)
726 *            assumption is readIdent has occurred
727 *       if atp == NULL, then assumes it stands alone and read ident
728 *            has not occurred.
729 *
730 *****************************************************************************/
731 NLM_EXTERN SPBlockPtr LIBCALL SPBlockAsnRead (AsnIoPtr aip, AsnTypePtr orig)
732 {
733         DataVal av;
734         AsnTypePtr atp, oldatp;
735     SPBlockPtr sbp=NULL;
736     ValNodePtr tmp, tmp2;
737 
738         if (! loaded)
739         {
740                 if (! SeqBlockAsnLoad())
741                         return sbp;
742         }
743 
744         if (aip == NULL)
745                 return sbp;
746 
747         if (orig == NULL)           /* SPBlock ::= (self contained) */
748                 atp = AsnReadId(aip, amp, SP_BLOCK);
749         else
750                 atp = AsnLinkType(orig, SP_BLOCK);    /* link in local tree */
751     oldatp = atp;
752         if (atp == NULL) return sbp;
753 
754     sbp = SPBlockNew();
755         if (sbp == NULL) goto erret;
756 
757     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* read the start struct */
758     
759     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
760     {
761                 if (atp == NULL) goto erret;
762         if (atp == SP_BLOCK_seqref)
763                 {
764             sbp->seqref = SeqIdSetAsnRead(aip, atp, SP_BLOCK_seqref_E);
765                         if (sbp->seqref == NULL) goto erret;
766                 }
767                 else if (atp == SP_BLOCK_created)
768                 {
769                         sbp->created = DateAsnRead(aip, atp);
770                         if (sbp->created == NULL) goto erret;
771                 }
772                 else if (atp == SP_BLOCK_sequpd)
773                 {
774                         sbp->sequpd = DateAsnRead(aip, atp);
775                         if (sbp->sequpd == NULL) goto erret;
776                 }
777                 else if (atp == SP_BLOCK_annotupd)
778                 {
779                         sbp->annotupd = DateAsnRead(aip, atp);
780                         if (sbp->annotupd == NULL) goto erret;
781                 }
782         else
783         {
784             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
785             if (atp == SP_BLOCK_class)
786                 sbp->_class = (Uint1) av.intvalue;
787             else if (atp == SP_BLOCK_imeth)
788                 sbp->imeth = av.boolvalue;
789             else if (atp == SP_BLOCK_extra_acc)
790             {
791                 tmp = NULL;
792                 while ((atp = AsnReadId(aip, amp, atp)) == SP_BLOCK_extra_acc_E)
793                 {
794                     tmp2 = ValNodeNew(tmp);
795                                         if (tmp2 == NULL) goto erret;
796                     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
797                     tmp2->data.ptrvalue = av.ptrvalue;
798                     if (tmp == NULL)
799                         sbp->extra_acc = tmp2;
800                     tmp = tmp2;
801                 }
802                                 if (atp == NULL) goto erret;
803                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end struct */
804             }
805             else if (atp == SP_BLOCK_plasnm)
806             {
807                 tmp = NULL;
808                 while ((atp = AsnReadId(aip, amp, atp)) == SP_BLOCK_plasnm_E)
809                 {
810                     tmp2 = ValNodeNew(tmp);
811                                         if (tmp2 == NULL) goto erret;
812                     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
813                     tmp2->data.ptrvalue = av.ptrvalue;
814                     if (tmp == NULL)
815                         sbp->plasnm = tmp2;
816                     tmp = tmp2;
817                 }
818                                 if (atp == NULL) goto erret;
819                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end struct */
820             }
821             else if (atp == SP_BLOCK_keywords)
822             {
823                 tmp = NULL;
824                 while ((atp = AsnReadId(aip, amp, atp)) == SP_BLOCK_keywords_E)
825                 {
826                     tmp2 = ValNodeNew(tmp);
827                                         if (tmp2 == NULL) goto erret;
828                     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
829                     tmp2->data.ptrvalue = av.ptrvalue;
830                     if (tmp == NULL)
831                         sbp->keywords = tmp2;
832                     tmp = tmp2;
833                 }
834                                 if (atp == NULL) goto erret;
835                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end struct */
836             }
837             else if (atp == SP_BLOCK_dbref)
838             {
839                 tmp = NULL;
840                 while ((atp = AsnReadId(aip, amp, atp)) == SP_BLOCK_dbref_E)
841                 {
842                     tmp2 = ValNodeNew(tmp);
843                                         if (tmp2 == NULL) goto erret;
844                     tmp2->data.ptrvalue = (Pointer)DbtagAsnRead(aip, atp);
845                                         if (tmp2->data.ptrvalue == NULL) goto erret;
846                     if (tmp == NULL)
847                         sbp->dbref = tmp2;
848                     tmp = tmp2;
849                 }
850                                 if (atp == NULL) goto erret;
851                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end struct */
852             }
853         }
854     }
855     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* end struct */
856 ret:
857         AsnUnlinkType(orig);       /* unlink local tree */
858         return sbp;
859 erret:
860         sbp = SPBlockFree(sbp);
861         goto ret;
862 }
863 
864 /*****************************************************************************
865 *
866 *   EMBLBlockNew()
867 *
868 *****************************************************************************/
869 NLM_EXTERN EMBLBlockPtr LIBCALL EMBLBlockNew (void)
870 {
871         EMBLBlockPtr ebp;
872 
873     ebp = (EMBLBlockPtr)MemNew(sizeof(EMBLBlock));
874         if (ebp == NULL) return NULL;
875         ebp->div = 255;    /* for not-set */
876         ebp->_class = 1;   /* for standard */
877         return ebp;
878 }
879 
880 /*****************************************************************************
881 *
882 *   EMBLBlockFree(ebp)
883 *       Frees a EMBLBlock and associated data
884 *
885 *****************************************************************************/
886 NLM_EXTERN EMBLBlockPtr LIBCALL EMBLBlockFree (EMBLBlockPtr ebp)
887 {
888     ValNodePtr anp, next;
889         EMBLXrefPtr ecurr, enext;
890 
891     if (ebp == NULL)
892         return ebp;
893 
894         DateFree(ebp->creation_date);
895         DateFree(ebp->update_date);
896         ecurr = ebp->xref;
897         while (ecurr != NULL)
898         {
899                 enext = ecurr->next;
900                 MemFree(ecurr->name);
901             anp = ecurr->id;
902             while (anp != NULL)
903         {
904                 next = anp->next;
905                         ObjectIdFree((ObjectIdPtr)anp->data.ptrvalue);
906                 MemFree(anp);
907             anp = next;
908             }
909                 MemFree(ecurr);
910                 ecurr = enext;
911         }
912     ValNodeFreeData(ebp->extra_acc);
913     ValNodeFreeData(ebp->keywords);
914         return (EMBLBlockPtr)MemFree(ebp);
915 }
916 /*****************************************************************************
917 *
918 *   EMBLBlockAsnWrite(ebp, aip, atp)
919 *       atp is the current type (if identifier of a parent struct)
920 *       if atp == NULL, then assumes it stands alone (EMBLBlock ::=)
921 *
922 *****************************************************************************/
923 NLM_EXTERN Boolean LIBCALL EMBLBlockAsnWrite (EMBLBlockPtr ebp, AsnIoPtr aip, AsnTypePtr orig)
924 {
925         DataVal av;
926         AsnTypePtr atp;
927     ValNodePtr anp;
928         EMBLXrefPtr xref;
929         Boolean retval = FALSE;
930 
931         if (! loaded)
932         {
933                 if (! SeqBlockAsnLoad())
934                         return FALSE;
935         }
936 
937         if (aip == NULL)
938                 return FALSE;
939 
940         atp = AsnLinkType(orig, EMBL_BLOCK);   /* link local tree */
941         if (atp == NULL) return FALSE;
942 
943         if (ebp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
944 
945     if (! AsnOpenStruct(aip, atp, (Pointer)ebp)) goto erret;
946 
947     if (ebp->_class != 1) {
948         av.intvalue = ebp->_class;
949         if (! AsnWrite(aip, EMBL_BLOCK_class, &av)) goto erret;
950     }
951         if (ebp->div != 255)
952         {
953             av.intvalue = ebp->div;
954         if (! AsnWrite(aip, EMBL_BLOCK_div, &av)) goto erret;
955         }
956 
957         if (ebp->creation_date != NULL)
958         {
959                 if (! DateAsnWrite(ebp->creation_date, aip, EMBL_BLOCK_creation_date)) goto erret;
960         }
961 
962         if (ebp->update_date != NULL)
963         {
964                 if (! DateAsnWrite(ebp->update_date, aip, EMBL_BLOCK_update_date)) goto erret;
965         }
966 
967     if (ebp->extra_acc != NULL)
968     {
969         if (! AsnOpenStruct(aip, EMBL_BLOCK_extra_acc, (Pointer)ebp->extra_acc)) goto erret;
970         anp = ebp->extra_acc;
971         while (anp != NULL)
972         {
973             if (! AsnWrite(aip, EMBL_BLOCK_extra_acc_E, &anp->data)) goto erret;
974             anp = anp->next;
975         }
976         if (! AsnCloseStruct(aip, EMBL_BLOCK_extra_acc, (Pointer)ebp->extra_acc)) goto erret;
977     }
978 
979     if (ebp->keywords != NULL)
980     {
981         if (! AsnOpenStruct(aip, EMBL_BLOCK_keywords, (Pointer)ebp->keywords)) goto erret;
982         anp = ebp->keywords;
983         while (anp != NULL)
984         {
985             if (! AsnWrite(aip, EMBL_BLOCK_keywords_E, &anp->data)) goto erret;
986             anp = anp->next;
987         }
988         if (! AsnCloseStruct(aip, EMBL_BLOCK_keywords, (Pointer)ebp->keywords)) goto erret;
989     }
990 
991     if (ebp->xref != NULL)
992     {
993         if (! AsnOpenStruct(aip, EMBL_BLOCK_xref, (Pointer)ebp->xref)) goto erret;
994         xref = ebp->xref;
995                 while (xref != NULL)
996                 {
997                         if (! AsnOpenStruct(aip, EMBL_BLOCK_xref_E, (Pointer)xref)) goto erret;
998 
999                         if (xref->name != NULL)
1000                         {
1001                                 av.ptrvalue = xref->name;
1002                                 if (! AsnWriteChoice(aip, EMBL_XREF_dbname, (Int2)0, &av)) goto erret;
1003                                 if (! AsnWrite(aip, EMBL_DBNAME_name, &av)) goto erret;
1004                         }
1005                         else
1006                         {
1007                                 av.intvalue = xref->_class;
1008                                 if (! AsnWriteChoice(aip, EMBL_XREF_dbname, (Int2)1, &av)) goto erret;
1009                                 if (! AsnWrite(aip, EMBL_DBNAME_code, &av)) goto erret;
1010                         }
1011                         if (! AsnOpenStruct(aip, EMBL_XREF_id, (Pointer)xref->id)) goto erret;
1012                         anp = xref->id;
1013                 while (anp != NULL)
1014             {
1015                     if (! ObjectIdAsnWrite((ObjectIdPtr)anp->data.ptrvalue, aip, EMBL_XREF_id_E)) goto erret;
1016                 anp = anp->next;
1017                 }
1018                         if (! AsnCloseStruct(aip, EMBL_XREF_id, (Pointer)xref->id)) goto erret;
1019                         if (! AsnCloseStruct(aip, EMBL_BLOCK_xref_E, (Pointer)xref)) goto erret;
1020                         xref = xref->next;
1021                 }
1022         if (! AsnCloseStruct(aip, EMBL_BLOCK_xref, (Pointer)ebp->xref)) goto erret;
1023     }
1024 
1025     if (! AsnCloseStruct(aip, atp, (Pointer)ebp)) goto erret;
1026         retval = TRUE;
1027 erret:
1028         AsnUnlinkType(orig);       /* unlink local tree */
1029         return retval;
1030 }
1031 
1032 /*****************************************************************************
1033 *
1034 *   EMBLBlockAsnRead(aip, atp)
1035 *       atp is the current type (if identifier of a parent struct)
1036 *            assumption is readIdent has occurred
1037 *       if atp == NULL, then assumes it stands alone and read ident
1038 *            has not occurred.
1039 *
1040 *****************************************************************************/
1041 NLM_EXTERN EMBLBlockPtr LIBCALL EMBLBlockAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1042 {
1043         DataVal av;
1044         AsnTypePtr atp, oldatp;
1045     EMBLBlockPtr ebp=NULL;
1046     ValNodePtr tmp, tmp2;
1047         EMBLXrefPtr etmp, etmp2;
1048 
1049         if (! loaded)
1050         {
1051                 if (! SeqBlockAsnLoad())
1052                         return ebp;
1053         }
1054 
1055         if (aip == NULL)
1056                 return ebp;
1057 
1058         if (orig == NULL)           /* EMBLBlock ::= (self contained) */
1059                 atp = AsnReadId(aip, amp, EMBL_BLOCK);
1060         else
1061                 atp = AsnLinkType(orig, EMBL_BLOCK);    /* link in local tree */
1062     oldatp = atp;
1063         if (atp == NULL) return ebp;
1064 
1065     ebp = EMBLBlockNew();
1066         if (ebp == NULL) goto erret;
1067 
1068     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* read the start struct */
1069     
1070     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
1071     {
1072                 if (atp == NULL) goto erret;
1073                 if (atp == EMBL_BLOCK_creation_date)
1074                 {
1075                         ebp->creation_date = DateAsnRead(aip, atp);
1076                         if (ebp->creation_date == NULL) goto erret;
1077                 }
1078                 else if (atp == EMBL_BLOCK_update_date)
1079                 {
1080                         ebp->update_date = DateAsnRead(aip, atp);
1081                         if (ebp->update_date == NULL) goto erret;
1082                 }
1083         else
1084         {
1085             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1086             if (atp == EMBL_BLOCK_class)
1087                 ebp->_class = (Uint1) av.intvalue;
1088             else if (atp == EMBL_BLOCK_div)
1089                 ebp->div = (Uint1) av.intvalue;
1090             else if (atp == EMBL_BLOCK_extra_acc)
1091             {
1092                 tmp = NULL;
1093                 while ((atp = AsnReadId(aip, amp, atp)) == EMBL_BLOCK_extra_acc_E)
1094                 {
1095                     tmp2 = ValNodeNew(tmp);
1096                                         if (tmp2 == NULL) goto erret;
1097                     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1098                     tmp2->data.ptrvalue = av.ptrvalue;
1099                     if (tmp == NULL)
1100                         ebp->extra_acc = tmp2;
1101                     tmp = tmp2;
1102                 }
1103                                 if (atp == NULL) goto erret;
1104                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end struct */
1105             }
1106             else if (atp == EMBL_BLOCK_keywords)
1107             {
1108                 tmp = NULL;
1109                 while ((atp = AsnReadId(aip, amp, atp)) == EMBL_BLOCK_keywords_E)
1110                 {
1111                     tmp2 = ValNodeNew(tmp);
1112                                         if (tmp2 == NULL) goto erret;
1113                     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1114                     tmp2->data.ptrvalue = av.ptrvalue;
1115                     if (tmp == NULL)
1116                         ebp->keywords = tmp2;
1117                     tmp = tmp2;
1118                 }
1119                                 if (atp == NULL) goto erret;
1120                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end struct */
1121             }
1122             else if (atp == EMBL_BLOCK_xref)
1123             {
1124                                 etmp = NULL;
1125                                 while ((atp = AsnReadId(aip, amp, atp)) == EMBL_BLOCK_xref_E)
1126                                 {
1127                                         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* start struct */
1128                                         etmp2 = (EMBLXrefPtr)MemNew(sizeof(EMBLXref));
1129                                         if (etmp2 == NULL) goto erret;
1130                                         if (etmp == NULL)
1131                                                 ebp->xref = etmp2;
1132                                         else
1133                                                 etmp->next = etmp2;
1134                                         etmp = etmp2;
1135 
1136                                         atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;   /* dbname CHOICE */
1137                                         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1138                                         atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;   /* which CHOICE */
1139                                         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1140                                         if (atp == EMBL_DBNAME_name)
1141                                                 etmp2->name = (CharPtr)av.ptrvalue;
1142                                         else
1143                                                 etmp2->_class = (Uint1) av.intvalue;
1144                                         atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;   /* start struct EMBL_XREF_id */
1145                                         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1146                         tmp = NULL;
1147                     while ((atp = AsnReadId(aip, amp, atp)) == EMBL_XREF_id_E)
1148                         {
1149                         tmp2 = ValNodeNew(tmp);
1150                                                 if (tmp2 == NULL) goto erret;
1151                             tmp2->data.ptrvalue = (Pointer)ObjectIdAsnRead(aip, atp);
1152                                                 if (tmp2->data.ptrvalue == NULL) goto erret;
1153 
1154                                                 if (tmp == NULL)
1155                                 etmp2->id = tmp2;
1156                             tmp = tmp2;
1157                     }
1158                                         if (atp == NULL) goto erret;
1159                         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end struct EMBL_XREF_id */
1160 
1161                                         atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;  /* end struct EMBL_BLOCK_xref_E */
1162                                         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1163                                 }
1164                                 if (atp == NULL) goto erret;
1165                                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end struct EMBL_BLOCK_xref */
1166             }
1167         }
1168     }
1169     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* end struct */
1170 ret:
1171         AsnUnlinkType(orig);       /* unlink local tree */
1172         return ebp;
1173 erret:
1174         ebp = EMBLBlockFree(ebp);
1175         goto ret;
1176 }
1177 
1178 /*****************************************************************************
1179 *
1180 *       PRF-Block       - PRF specific block
1181 *               by A. Ogiwara
1182 *
1183 *****************************************************************************/
1184 
1185 /*****************************************************************************
1186 *
1187 *       PrfBlockNew()
1188 *
1189 *****************************************************************************/
1190 NLM_EXTERN PrfBlockPtr  LIBCALL PrfBlockNew(void)
1191 {
1192         return (PrfBlockPtr)MemNew(sizeof(PrfBlock));
1193 }
1194 
1195 /*****************************************************************************
1196 *
1197 *       PrfBlockFree(pbp)
1198 *               Frees a PrfBlock and associated data
1199 *
1200 *****************************************************************************/
1201 NLM_EXTERN PrfBlockPtr  LIBCALL PrfBlockFree (PrfBlockPtr pbp)
1202 {
1203         if ( pbp == NULL )
1204                 return pbp;
1205 
1206         if ( pbp->extra_src ) {
1207                 MemFree( pbp->extra_src->host );
1208                 MemFree( pbp->extra_src->part );
1209                 MemFree( pbp->extra_src->state );
1210                 MemFree( pbp->extra_src->strain );
1211                 MemFree( pbp->extra_src->taxon );
1212                 MemFree(pbp->extra_src);
1213         }
1214         ValNodeFreeData( pbp->keywords );
1215         return (PrfBlockPtr)MemFree( pbp );
1216 }
1217 
1218 /*****************************************************************************
1219 *
1220 *       PrfBlockAsnWrite( pbp, aip, atp )
1221 *
1222 *****************************************************************************/
1223 NLM_EXTERN Boolean      LIBCALL PrfBlockAsnWrite (PrfBlockPtr pbp, AsnIoPtr aip, AsnTypePtr     orig)
1224 {
1225         PrfExtSrcPtr    pxsp;
1226         AsnTypePtr      atp;
1227         ValNodePtr      vnp;
1228         DataVal         val;
1229         Boolean         retval = FALSE;
1230 
1231         if ( ! loaded ) {
1232                 if ( ! SeqBlockAsnLoad() )
1233                         return FALSE;
1234         }
1235 
1236         if ( aip == NULL )
1237                 return FALSE;
1238         
1239         atp = AsnLinkType( orig, PRF_BLOCK );
1240         if ( atp == NULL )      return FALSE;
1241 
1242         if ( pbp == NULL ) { AsnNullValueMsg( aip, atp );  goto erret; }
1243 
1244         if ( ! AsnOpenStruct( aip, atp, (Pointer)pbp ) )  goto erret;
1245 
1246         pxsp = pbp->extra_src;
1247         if ( pxsp && ( pxsp->host || pxsp->part || pxsp->state ||
1248              pxsp->strain || pxsp->taxon ) ) {
1249                 if ( ! AsnOpenStruct( aip, PRF_BLOCK_extra_src,
1250                      (Pointer)pxsp ) )
1251                         goto erret;
1252                 if ( pxsp->host ) {
1253                         val.ptrvalue = pxsp->host;
1254                         if ( ! AsnWrite( aip, PRF_EXTRASRC_host, &val ) )
1255                                 goto erret;
1256                 }
1257                 if ( pxsp->part ) {
1258                         val.ptrvalue = pxsp->part;
1259                         if ( ! AsnWrite( aip, PRF_EXTRASRC_part, &val ) )
1260                                 goto erret;
1261                 }
1262                 if ( pxsp->state ) {
1263                         val.ptrvalue = pxsp->state;
1264                         if ( ! AsnWrite( aip, PRF_EXTRASRC_state, &val ) )
1265                                 goto erret;
1266                 }
1267                 if ( pxsp->strain ) {
1268                         val.ptrvalue = pxsp->strain;
1269                         if ( ! AsnWrite( aip, PRF_EXTRASRC_strain, &val ) )
1270                                 goto erret;
1271                 }
1272                 if ( pxsp->taxon ) {
1273                         val.ptrvalue = pxsp->taxon;
1274                         if ( ! AsnWrite( aip, PRF_EXTRASRC_taxon, &val ) )
1275                                 goto erret;
1276                 }
1277                 if ( ! AsnCloseStruct( aip, PRF_BLOCK_extra_src,
1278                      (Pointer)pxsp ) )
1279                         goto erret;
1280         }
1281 
1282         if ( pbp->keywords ) {
1283                 vnp = pbp->keywords;
1284                 if ( ! AsnOpenStruct( aip, PRF_BLOCK_keywords, (Pointer)vnp ) )
1285                         goto erret;
1286                 for ( ; vnp; vnp = vnp->next ) {
1287                         if ( ! AsnWrite( aip, PRF_BLOCK_keywords_E,
1288                              &vnp->data ) )
1289                                 goto erret;
1290                 }
1291                 if ( ! AsnCloseStruct( aip, PRF_BLOCK_keywords, (Pointer)vnp ) )
1292                         goto erret;
1293         }
1294 
1295         if ( ! AsnCloseStruct( aip, atp, (Pointer)pbp ) )  goto erret;
1296         retval = TRUE;
1297 
1298     erret:
1299         AsnUnlinkType( orig );          /* unlink local tree */
1300         return retval;
1301 }
1302 
1303 /*****************************************************************************
1304 *
1305 *       PrfBlockAsnRead( aip, atp )
1306 *
1307 *****************************************************************************/
1308 NLM_EXTERN PrfBlockPtr  LIBCALL PrfBlockAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1309 {
1310         AsnTypePtr      atp, oldatp;
1311         PrfBlockPtr     pbp=NULL;
1312         DataVal         val;
1313         ValNodePtr      vnp, vnp2;
1314 
1315         if ( ! loaded ) {
1316                 if ( ! SeqBlockAsnLoad() )      return pbp;
1317         }
1318 
1319         if ( aip == NULL )      return pbp;
1320         if ( orig == NULL )     atp = AsnReadId( aip, amp, PRF_BLOCK );
1321         else                    atp = AsnLinkType( orig, PRF_BLOCK );
1322         oldatp = atp;
1323         if ( atp == NULL )      return pbp;
1324 
1325         pbp = PrfBlockNew();
1326         if ( pbp == NULL )      goto erret;
1327         pbp->extra_src = NULL;
1328 
1329         if ( AsnReadVal( aip, atp, &val ) <= 0 ) goto erret; /* start struct */
1330 
1331         while ( ( atp = AsnReadId( aip, amp, atp ) ) != oldatp ) {
1332                 if ( atp == NULL )      goto erret;
1333 
1334                 if ( atp == PRF_BLOCK_extra_src ) {
1335                         if ( AsnReadVal( aip, atp, &val ) <= 0 ) goto erret;
1336                         if ( pbp->extra_src == NULL )
1337                                 pbp->extra_src = (PrfExtSrcPtr)MemNew( sizeof(PrfExtSrc) );
1338                         if ( pbp->extra_src == NULL )   goto erret;
1339                 } else if ( atp == PRF_BLOCK_keywords ) {
1340                         if ( AsnReadVal( aip, atp, &val ) <= 0 ) goto erret;
1341                         vnp = NULL;
1342                         while ( ( atp = AsnReadId( aip, amp, atp ) )
1343                                 == PRF_BLOCK_keywords_E ) {
1344                                 vnp2 = ValNodeNew( vnp );
1345                                 if ( vnp2 == NULL ) goto erret;
1346                                 if ( AsnReadVal( aip, atp, &val ) <= 0 )
1347                                         goto erret;
1348                                 vnp2->data.ptrvalue = val.ptrvalue;
1349                                 if ( vnp == NULL )
1350                                         pbp->keywords = vnp2;
1351                                 vnp = vnp2;
1352                         }
1353                         if ( atp == NULL ) goto erret;
1354                         if ( AsnReadVal( aip, atp, &val ) <= 0 ) goto erret;
1355                 } else {
1356                         if ( AsnReadVal( aip, atp, &val ) <= 0 ) goto erret;
1357                         if ( atp == PRF_EXTRASRC_host ) {
1358                                 pbp->extra_src->host = (CharPtr)val.ptrvalue;
1359                         } else if ( atp == PRF_EXTRASRC_part ) {
1360                                 pbp->extra_src->part = (CharPtr)val.ptrvalue;
1361                         } else if ( atp == PRF_EXTRASRC_state ) {
1362                                 pbp->extra_src->state = (CharPtr)val.ptrvalue;
1363                         } else if ( atp == PRF_EXTRASRC_strain ) {
1364                                 pbp->extra_src->strain = (CharPtr)val.ptrvalue;
1365                         } else if ( atp == PRF_EXTRASRC_taxon ) {
1366                                 pbp->extra_src->taxon = (CharPtr)val.ptrvalue;
1367                         }
1368                 }
1369         }
1370 
1371         if ( AsnReadVal( aip, atp, &val ) <= 0 ) goto erret; /* end struct */
1372     ret:
1373         AsnUnlinkType( orig );
1374         return pbp;
1375     erret:
1376         pbp = PrfBlockFree( pbp );
1377         goto ret;
1378 }
1379 
1380 /*****************************************************************************
1381 *
1382 *       PDB-Block       - PDB specific block
1383 *
1384 *****************************************************************************/
1385 
1386 /*****************************************************************************
1387 *
1388 *       PdbBlockNew()
1389 *
1390 *****************************************************************************/
1391 NLM_EXTERN PdbBlockPtr  LIBCALL PdbBlockNew(void)
1392 {
1393         return (PdbBlockPtr)MemNew(sizeof(PdbBlock));
1394 }
1395 
1396 /*****************************************************************************
1397 *
1398 *       PdbBlockFree(pdbp)
1399 *               Frees a PdbBlock and associated data
1400 *
1401 *****************************************************************************/
1402 NLM_EXTERN PdbBlockPtr  LIBCALL PdbBlockFree (PdbBlockPtr pdbp)
1403 {
1404         if ( pdbp == NULL )
1405                 return pdbp;
1406 
1407         DateFree(pdbp->deposition);
1408         MemFree(pdbp->pdbclass);
1409         ValNodeFreeData( pdbp->compound );
1410         ValNodeFreeData(pdbp->source);
1411         MemFree(pdbp->exp_method);
1412         if (pdbp->replace != NULL)
1413         {
1414                 DateFree(pdbp->replace->date);
1415                 ValNodeFreeData(pdbp->replace->ids);
1416                 MemFree(pdbp->replace);
1417         }
1418         return (PdbBlockPtr)MemFree( pdbp );
1419 }
1420 
1421 /*****************************************************************************
1422 *
1423 *       PdbBlockAsnWrite( pdbp, aip, atp )
1424 *
1425 *****************************************************************************/
1426 NLM_EXTERN Boolean      LIBCALL PdbBlockAsnWrite (PdbBlockPtr pdbp,     AsnIoPtr aip, AsnTypePtr orig)
1427 {
1428         PdbRepPtr       prp;
1429         AsnTypePtr      atp;
1430         ValNodePtr      vnp;
1431         DataVal         val;
1432         Boolean         retval = FALSE;
1433 
1434         if ( ! loaded ) {
1435                 if ( ! SeqBlockAsnLoad() )
1436                         return FALSE;
1437         }
1438 
1439         if ( aip == NULL )
1440                 return FALSE;
1441         
1442         atp = AsnLinkType( orig, PDB_BLOCK );
1443         if ( atp == NULL )      return FALSE;
1444 
1445         if ( pdbp == NULL ) { AsnNullValueMsg( aip, atp );  goto erret; }
1446 
1447         if ( ! AsnOpenStruct( aip, atp, (Pointer)pdbp ) )  goto erret;
1448 
1449         if (! DateAsnWrite(pdbp->deposition, aip, PDB_BLOCK_deposition))
1450                 goto erret;
1451 
1452         val.ptrvalue = (Pointer) pdbp->pdbclass;
1453         if (! AsnWrite(aip, PDB_BLOCK_class, &val)) goto erret;
1454 
1455         if ( pdbp->compound )
1456         {
1457                 vnp = pdbp->compound;
1458                 if ( ! AsnOpenStruct( aip, PDB_BLOCK_compound, (Pointer)vnp ) )
1459                         goto erret;
1460                 for ( ; vnp; vnp = vnp->next )
1461                 {
1462                         if ( ! AsnWrite( aip, PDB_BLOCK_compound_E, &vnp->data ) )
1463                                 goto erret;
1464                 }
1465                 if ( ! AsnCloseStruct( aip, PDB_BLOCK_compound, (Pointer)vnp ) )
1466                         goto erret;
1467         }
1468 
1469         if ( pdbp->source )
1470         {
1471                 vnp = pdbp->source;
1472                 if ( ! AsnOpenStruct( aip, PDB_BLOCK_source, (Pointer)vnp ) )
1473                         goto erret;
1474                 for ( ; vnp; vnp = vnp->next )
1475                 {
1476                         if ( ! AsnWrite( aip, PDB_BLOCK_source_E, &vnp->data ) )
1477                                 goto erret;
1478                 }
1479                 if ( ! AsnCloseStruct( aip, PDB_BLOCK_source, (Pointer)vnp ) )
1480                         goto erret;
1481         }
1482 
1483         if (pdbp->exp_method != NULL)
1484         {
1485                 val.ptrvalue = (Pointer) pdbp->exp_method;
1486                 if (! AsnWrite(aip, PDB_BLOCK_exp_method, &val)) goto erret;
1487         }
1488 
1489         if (pdbp->replace != NULL)
1490         {
1491                 prp = pdbp->replace;
1492                 if ( ! AsnOpenStruct( aip, PDB_BLOCK_replace, (Pointer)prp ) )
1493                         goto erret;
1494 
1495                 if (! DateAsnWrite(prp->date, aip, PDB_REPLACE_date)) goto erret;
1496 
1497                 vnp = prp->ids;
1498                 if ( ! AsnOpenStruct( aip, PDB_REPLACE_ids, (Pointer)vnp ) )
1499                         goto erret;
1500                 for ( ; vnp; vnp = vnp->next )
1501                 {
1502                         if ( ! AsnWrite( aip, PDB_REPLACE_ids_E, &vnp->data ) )
1503                                 goto erret;
1504                 }
1505                 if ( ! AsnCloseStruct( aip, PDB_REPLACE_ids, (Pointer)vnp ) )
1506                         goto erret;
1507 
1508                 if ( ! AsnCloseStruct( aip, PDB_BLOCK_replace, (Pointer)prp ) )
1509                         goto erret;
1510 
1511         }
1512 
1513         if ( ! AsnCloseStruct( aip, atp, (Pointer)pdbp ) )  goto erret;
1514         retval = TRUE;
1515 
1516     erret:
1517         AsnUnlinkType( orig );          /* unlink local tree */
1518         return retval;
1519 }
1520 
1521 /*****************************************************************************
1522 *
1523 *       PdbBlockAsnRead( aip, atp )
1524 *
1525 *****************************************************************************/
1526 NLM_EXTERN PdbBlockPtr  LIBCALL PdbBlockAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1527 {
1528         AsnTypePtr      atp, oldatp;
1529         PdbBlockPtr     pdbp=NULL;
1530         PdbRepPtr prp = NULL;
1531         DataVal         val;
1532         ValNodePtr      vnp;
1533 
1534         if ( ! loaded ) {
1535                 if ( ! SeqBlockAsnLoad() )      return pdbp;
1536         }
1537 
1538         if ( aip == NULL )      return pdbp;
1539         if ( orig == NULL )
1540                 atp = AsnReadId( aip, amp, PDB_BLOCK );
1541         else
1542                 atp = AsnLinkType( orig, PDB_BLOCK );
1543         oldatp = atp;
1544         if ( atp == NULL )      return pdbp;
1545 
1546         pdbp = PdbBlockNew();
1547         if ( pdbp == NULL )     goto erret;
1548 
1549         if ( AsnReadVal( aip, atp, &val ) <= 0 ) goto erret; /* start struct */
1550 
1551         while ( ( atp = AsnReadId( aip, amp, atp ) ) != oldatp )
1552         {
1553                 if ( atp == NULL )      goto erret;
1554 
1555                 if (atp == PDB_BLOCK_deposition)
1556                 {
1557                         pdbp->deposition = DateAsnRead(aip, atp);
1558                         if (pdbp->deposition == NULL) goto erret;
1559                 }
1560                 else if (atp == PDB_REPLACE_date)
1561                 {
1562                         prp->date = DateAsnRead(aip, atp);
1563                         if (prp->date == NULL) goto erret;
1564                 }
1565                 else
1566                 {
1567                         if (! AsnReadVal(aip, atp, &val)) goto erret;
1568                         if (atp == PDB_BLOCK_replace)
1569                         {
1570                                 if (prp == NULL)
1571                                 {
1572                                         prp = (PdbRepPtr)MemNew(sizeof(PdbRep));
1573                                         if (prp == NULL) goto erret;
1574                                         pdbp->replace = prp;
1575                                 }
1576                         }
1577                         else if (atp == PDB_BLOCK_class)
1578                                 pdbp->pdbclass = (CharPtr)val.ptrvalue;
1579                         else if (atp == PDB_BLOCK_compound_E)
1580                         {
1581                                 vnp = ValNodeNew(pdbp->compound);
1582                                 if (vnp == NULL) goto erret;
1583                                 if (pdbp->compound == NULL)
1584                                         pdbp->compound = vnp;
1585                                 vnp->data.ptrvalue = val.ptrvalue;
1586                         }
1587                         else if (atp == PDB_BLOCK_source_E)
1588                         {
1589                                 vnp = ValNodeNew(pdbp->source);
1590                                 if (vnp == NULL) goto erret;
1591                                 if (pdbp->source == NULL)
1592                                         pdbp->source = vnp;
1593                                 vnp->data.ptrvalue = val.ptrvalue;
1594                         }
1595                         else if (atp == PDB_BLOCK_exp_method)
1596                                 pdbp->exp_method = (CharPtr)val.ptrvalue;
1597                         else if (atp == PDB_REPLACE_ids_E)
1598                         {
1599                                 vnp = ValNodeNew(prp->ids);
1600                                 if (vnp == NULL) goto erret;
1601                                 if (prp->ids == NULL)
1602                                         prp->ids = vnp;
1603                                 vnp->data.ptrvalue = val.ptrvalue;
1604                         }
1605                 }
1606         }
1607 
1608         if ( AsnReadVal( aip, atp, &val ) <= 0 ) goto erret; /* end struct */
1609     ret:
1610         AsnUnlinkType( orig );
1611         return pdbp;
1612     erret:
1613         pdbp = PdbBlockFree( pdbp );
1614         goto ret;
1615 }
1616 
1617 

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.