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