NCBI C Toolkit Cross Reference

C/object/objmedli.c


  1 /*  objmedli.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:  objmedli.c
 27 *
 28 * Author:  James Ostell
 29 *   
 30 * Version Creation Date: 1/1/91
 31 *
 32 * $Revision: 6.5 $
 33 *
 34 * File Description:  Object manager for module NCBI-Medline
 35 *
 36 * Modifications:  
 37 * --------------------------------------------------------------------------
 38 * Date     Name        Description of modification
 39 * -------  ----------  -----------------------------------------------------
 40 * 05-13-93 Schuler     All public functions are now declared LIBCALL.
 41 *
 42 *
 43 * $Log: objmedli.c,v $
 44 * Revision 6.5  2009/10/02 19:44:49  kans
 45 * address clang static analyzer warnings
 46 *
 47 * Revision 6.4  1998/08/26 17:43:17  kans
 48 * fixed -v -fd warnings in label functions
 49 *
 50 * Revision 6.3  1998/08/24 18:28:06  kans
 51 * removed solaris -v -fd warnings
 52 *
 53 * Revision 6.2  1997/10/28 16:09:11  grisha
 54 * fixed bug in function MedlineEntryAsnRead() to load status
 55 *
 56 * Revision 6.1  1997/09/03 12:55:56  ostell
 57 * added support for MedlineEntry.status
 58 *
 59 * Revision 6.0  1997/08/25 18:50:13  madden
 60 * Revision changed to 6.0
 61 *
 62 * Revision 4.9  1997/08/20 19:17:08  madden
 63 * Version 6 of ASN.1
 64 *
 65 * Revision 4.8  1997/06/19 18:41:35  vakatov
 66 * [WIN32,MSVC++]  Adopted for the "NCBIOBJ.LIB" DLL'ization
 67 *
 68 * Revision 4.7  1996/08/14 20:57:32  grisha
 69 * Check ASN.1 version. Write pub_type if version set to 0
 70 *
 71  * Revision 4.6  1996/08/12  14:07:21  grisha
 72  * Generate pub_type if ASN.1 spec version >= 5
 73  *
 74  * Revision 4.5  1996/07/30  15:23:01  epstein
 75  * correct logic errors for different spec_versions
 76  *
 77  * Revision 4.4  1996/07/24  16:35:54  ostell
 78  * corrected AsnRead putting pub_type in gene slot.
 79  *
 80  * Revision 4.3  1996/05/20  19:43:50  ostell
 81  * added pub_type
 82  *
 83  * Revision 4.2  1996/03/29  21:09:59  ostell
 84  * added support for PubMedId
 85  *
 86  * Revision 4.1  1995/12/22  17:16:07  grisha
 87  * add function MedlineSiFree(), because new Client/Server
 88  * library for MedArch server needs this function
 89  *
 90  * Revision 4.0  1995/07/26  13:48:06  ostell
 91  * force revision to 4.0
 92  *
 93  * Revision 3.5  1995/05/15  21:22:00  ostell
 94  * added Log line
 95  *
 96 *
 97 *
 98 * ==========================================================================
 99 */
100 
101 #include <objmedli.h>
102 #include <asnmedli.h>
103 #include <objmgr.h>
104 
105 static Boolean loaded = FALSE;
106 
107 /*****************************************************************************
108 *
109 *   MedlineEntry ObjMgr Routines
110 *
111 *****************************************************************************/
112 static CharPtr typename = "MedlineEntry";
113 
114 static Pointer LIBCALLBACK MedlineEntryNewFunc (void)
115 {
116         return (Pointer) MedlineEntryNew();
117 }
118 
119 static Pointer LIBCALLBACK MedlineEntryFreeFunc (Pointer data)
120 {
121         return (Pointer) MedlineEntryFree ((MedlineEntryPtr) data);
122 }
123 
124 static Boolean LIBCALLBACK MedlineEntryAsnWriteFunc (Pointer data, AsnIoPtr aip, AsnTypePtr atp)
125 {
126         return MedlineEntryAsnWrite((MedlineEntryPtr)data, aip, atp);
127 }
128 
129 static Pointer LIBCALLBACK MedlineEntryAsnReadFunc (AsnIoPtr aip, AsnTypePtr atp)
130 {
131         return (Pointer) MedlineEntryAsnRead (aip, atp);
132 }
133 
134 static Int2 LIBCALLBACK MedlineEntryLabelFunc ( Pointer data, CharPtr buffer, Int2 buflen, Uint1 content)
135 {
136         Int2 rsult = 0;
137 
138         switch (content)
139         {
140                 case OM_LABEL_BOTH:
141                 case OM_LABEL_CONTENT:
142                 case OM_LABEL_SUMMARY:
143                 case OM_LABEL_TYPE:
144                 default:
145                         rsult = LabelCopy(buffer, typename, buflen);
146         }
147         return rsult;
148 }
149 
150 /*****************************************************************************
151 *
152 *   Medline Object routines
153 *
154 *****************************************************************************/
155 
156 /*****************************************************************************
157 *
158 *   MedlineAsnLoad()
159 *
160 *****************************************************************************/
161 NLM_EXTERN Boolean LIBCALL MedlineAsnLoad (void)
162 {
163     if (loaded)
164         return TRUE;
165     loaded = TRUE;
166 
167     if (! GeneralAsnLoad())
168     {
169         loaded = FALSE;
170         return FALSE;
171     }
172     if (! BiblioAsnLoad())
173     {
174         loaded = FALSE;
175         return FALSE;
176     }
177     if (! AsnLoad())
178     {
179         loaded = FALSE;
180         return FALSE;
181     }
182 
183         ObjMgrTypeLoad(OBJ_MEDLINE_ENTRY, "Medline-entry", typename, "MEDLINE entry",
184                 MEDLINE_ENTRY, MedlineEntryNewFunc, MedlineEntryAsnReadFunc, MedlineEntryAsnWriteFunc,
185                 MedlineEntryFreeFunc, MedlineEntryLabelFunc, NULL);
186 
187     return TRUE;
188 }
189 
190 /*****************************************************************************
191 *
192 *   MedlineMeshNew()
193 *
194 *****************************************************************************/
195 NLM_EXTERN MedlineMeshPtr LIBCALL MedlineMeshNew (void)
196 {
197         MedlineMeshPtr mmp;
198 
199         mmp = (MedlineMeshPtr)MemNew(sizeof(MedlineMesh));
200         return mmp;
201 }
202 
203 /*****************************************************************************
204 *
205 *   MedlineMeshFree()
206 *
207 *****************************************************************************/
208 NLM_EXTERN MedlineMeshPtr LIBCALL MedlineMeshFree (MedlineMeshPtr mmp)
209 {
210     if (mmp == NULL)
211         return mmp;
212 
213     MemFree(mmp->term);
214     ValNodeFreeData(mmp->qual);
215     
216         return (MedlineMeshPtr)MemFree(mmp);
217 }
218 
219 /*****************************************************************************
220 *
221 *   MedlineMeshAsnRead(aip, atp)
222 *
223 *****************************************************************************/
224 NLM_EXTERN MedlineMeshPtr LIBCALL MedlineMeshAsnRead (AsnIoPtr aip, AsnTypePtr orig)
225 {
226         MedlineMeshPtr mmp=NULL;
227         DataVal av;
228         AsnTypePtr atp, oldatp;
229     ValNodePtr first, anp = NULL;
230 
231         if (! loaded)
232         {
233                 if (! MedlineAsnLoad())
234                         return mmp;
235         }
236 
237         if (aip == NULL)
238                 return mmp;
239 
240         if (orig == NULL)           /* MedlineMesh ::= */
241                 atp = AsnReadId(aip, amp, MEDLINE_MESH);
242         else
243                 atp = AsnLinkType(orig, MEDLINE_MESH);
244     oldatp = atp;
245     if (atp == NULL)
246         return mmp;
247 
248         mmp = MedlineMeshNew();
249     if (mmp == NULL) goto erret;
250 
251     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the SEQUENCE */
252     first = NULL;
253     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
254     {
255         if (atp == NULL) goto erret;
256         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
257         if (atp == MEDLINE_MESH_qual)     /* SET OF medline-qual */
258         {
259            while ((atp = AsnReadId(aip, amp, atp)) != MEDLINE_MESH_qual)
260            {
261                if (atp == NULL) goto erret;
262                if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
263                if ((atp == MEDLINE_MESH_qual_E) && (av.intvalue == START_STRUCT))
264                {
265                    anp = ValNodeNew(first);
266                    if (anp == NULL) goto erret;
267                    if (first == NULL)
268                     first = anp;
269                }
270                else if (atp == MEDLINE_QUAL_mp)
271                     anp->choice = (Uint1)av.boolvalue;
272                 else if (atp == MEDLINE_QUAL_subh)
273                     anp->data.ptrvalue = av.ptrvalue;
274            }
275            mmp->qual = first;
276            if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end of SET OF */
277         }
278         else if (atp == MEDLINE_MESH_mp)
279             mmp->mp = av.boolvalue;
280         else if (atp == MEDLINE_MESH_term)
281             mmp->term = (CharPtr)av.ptrvalue;
282     }
283 
284         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the END STRUCT */
285 ret:
286         AsnUnlinkType(orig);
287         return mmp;
288 erret:
289     mmp = MedlineMeshFree(mmp);
290     goto ret;
291 }
292 
293 /*****************************************************************************
294 *
295 *   MedlineMeshAsnWrite(mmp, aip, atp) 
296 *
297 *****************************************************************************/
298 NLM_EXTERN Boolean LIBCALL MedlineMeshAsnWrite (MedlineMeshPtr mmp, AsnIoPtr aip, AsnTypePtr orig)
299 {
300         DataVal av;
301         AsnTypePtr atp;
302     ValNodePtr anp;
303     Boolean retval = FALSE;
304 
305         if (! loaded)
306         {
307                 if (! MedlineAsnLoad())
308                         return FALSE;
309         }
310 
311         if (aip == NULL)
312                 return FALSE;
313 
314         atp = AsnLinkType(orig, MEDLINE_MESH);
315     if (atp == NULL) return FALSE;
316 
317         if (mmp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
318 
319     if (! AsnOpenStruct(aip, atp, (Pointer)mmp)) goto erret;
320     if (mmp->mp)
321     {
322         av.boolvalue = TRUE;
323         if (! AsnWrite(aip, MEDLINE_MESH_mp, &av)) goto erret;
324     }
325     av.ptrvalue = mmp->term;
326     if (! AsnWrite(aip, MEDLINE_MESH_term, &av)) goto erret;
327     if (mmp->qual != NULL)
328     {                                               /* start SET OF */
329         if (! AsnOpenStruct(aip, MEDLINE_MESH_qual, (Pointer)mmp->qual))
330             goto erret;
331         anp = mmp->qual;
332         while (anp != NULL)
333         {
334             if (! AsnOpenStruct(aip, MEDLINE_MESH_qual_E, (Pointer)anp))
335                 goto erret;
336             if (anp->choice != 0)
337             {
338                 av.boolvalue = TRUE;
339                 if (! AsnWrite(aip, MEDLINE_QUAL_mp, &av)) goto erret;
340             }
341             av.ptrvalue = anp->data.ptrvalue;
342             if (! AsnWrite(aip, MEDLINE_QUAL_subh, &av)) goto erret;
343             if (! AsnCloseStruct(aip, MEDLINE_MESH_qual_E, (Pointer)anp))
344                 goto erret;
345             anp = anp->next;
346         }
347         if (! AsnCloseStruct(aip, MEDLINE_MESH_qual, (Pointer)mmp->qual))
348             goto erret;
349     }
350 
351     if (! AsnCloseStruct(aip, atp, (Pointer)mmp)) goto erret;
352     retval = TRUE;
353 erret:
354         AsnUnlinkType(orig);
355         return retval;
356 }
357 
358 /*****************************************************************************
359 *
360 *   MedlineRnNew()
361 *
362 *****************************************************************************/
363 NLM_EXTERN MedlineRnPtr LIBCALL MedlineRnNew (void)
364 {
365         MedlineRnPtr mrp;
366 
367         mrp = (MedlineRnPtr)MemNew(sizeof(MedlineRn));
368         return mrp;
369 }
370 
371 /*****************************************************************************
372 *
373 *   MedlineRnFree()
374 *
375 *****************************************************************************/
376 NLM_EXTERN MedlineRnPtr LIBCALL MedlineRnFree (MedlineRnPtr mrp)
377 {
378     if (mrp == NULL)
379         return mrp;
380 
381     MemFree(mrp->cit);
382     MemFree(mrp->name);
383     
384         return (MedlineRnPtr)MemFree(mrp);
385 }
386 
387 /*****************************************************************************
388 *
389 *   MedlineRnAsnRead(aip, atp)
390 *
391 *****************************************************************************/
392 NLM_EXTERN MedlineRnPtr LIBCALL MedlineRnAsnRead (AsnIoPtr aip, AsnTypePtr orig)
393 {
394         MedlineRnPtr mrp=NULL;
395         DataVal av;
396         AsnTypePtr atp;
397 
398         if (! loaded)
399         {
400                 if (! MedlineAsnLoad())
401                         return mrp;
402         }
403 
404         if (aip == NULL)
405                 return mrp;
406 
407         if (orig == NULL)           /* MedlineRn ::= */
408                 atp = AsnReadId(aip, amp, MEDLINE_RN);
409         else
410                 atp = AsnLinkType(orig, MEDLINE_RN);
411     if (atp == NULL) return mrp;
412 
413         mrp = MedlineRnNew();
414     if (mrp == NULL) goto erret;
415 
416     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the SEQUENCE */
417     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;  /* type */
418     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
419     mrp->type = (Uint1)av.intvalue;
420     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
421     if (atp == MEDLINE_RN_cit)
422     {
423         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
424         mrp->cit = (CharPtr)av.ptrvalue;
425         atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
426     }
427     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
428     mrp->name = (CharPtr)av.ptrvalue;
429 
430     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
431         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the END STRUCT */
432 ret:
433         AsnUnlinkType(orig);
434         return mrp;
435 erret:
436     mrp = MedlineRnFree(mrp);
437     goto ret;
438 }
439 
440 /*****************************************************************************
441 *
442 *   MedlineRnAsnWrite(mrp, aip, atp) 
443 *
444 *****************************************************************************/
445 NLM_EXTERN Boolean LIBCALL MedlineRnAsnWrite (MedlineRnPtr mrp, AsnIoPtr aip, AsnTypePtr orig)
446 {
447         DataVal av;
448         AsnTypePtr atp;
449     Boolean retval = TRUE;
450 
451         if (! loaded)
452         {
453                 if (! MedlineAsnLoad())
454                         return FALSE;
455         }
456 
457         if (aip == NULL)
458                 return FALSE;
459 
460         atp = AsnLinkType(orig, MEDLINE_RN);
461     if (atp == NULL) return FALSE;
462 
463         if (mrp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
464 
465     if (! AsnOpenStruct(aip, atp, (Pointer)mrp)) goto erret;
466     av.intvalue = (Int4)mrp->type;
467     if (! AsnWrite(aip, MEDLINE_RN_type, &av)) goto erret;
468     if (mrp->cit != NULL)
469     {
470         av.ptrvalue = mrp->cit;
471         if (! AsnWrite(aip, MEDLINE_RN_cit, &av)) goto erret;
472     }
473     av.ptrvalue = mrp->name;
474     if (! AsnWrite(aip, MEDLINE_RN_name, &av)) goto erret;
475     if (! AsnCloseStruct(aip, atp, (Pointer)mrp)) goto erret;
476     retval = TRUE;
477 erret:
478         AsnUnlinkType(orig);
479         return retval;
480 }
481 
482 /*****************************************************************************
483 *
484 *   MedlineSiFree(msp)
485 *
486 *****************************************************************************/
487 NLM_EXTERN ValNodePtr LIBCALL MedlineSiFree (ValNodePtr msp)
488 {
489         if (msp != NULL)
490         {
491                 MemFree (msp->data.ptrvalue);
492                 MemFree (msp);
493         }
494          
495         return NULL; 
496 }
497 
498 /*****************************************************************************
499 *
500 *   MedlineSiAsnRead(aip, atp)
501 *
502 *****************************************************************************/
503 NLM_EXTERN ValNodePtr LIBCALL MedlineSiAsnRead (AsnIoPtr aip, AsnTypePtr orig)
504 {
505         ValNodePtr msp=NULL;
506         DataVal av;
507         AsnTypePtr atp;
508 
509         if (! loaded)
510         {
511                 if (! MedlineAsnLoad())
512                         return msp;
513         }
514 
515         if (aip == NULL)
516                 return msp;
517 
518         if (orig == NULL)           /* MedlineSi ::= */
519                 atp = AsnReadId(aip, amp, MEDLINE_SI);
520         else
521                 atp = AsnLinkType(orig, MEDLINE_SI);
522     if (atp == NULL) return msp;
523 
524         msp = ValNodeNew(NULL);
525     if (msp == NULL) goto erret;
526 
527     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the SEQUENCE */
528     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;  /* type */
529     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
530     msp->choice = (Uint1)av.intvalue;
531     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
532     if (atp == MEDLINE_SI_cit)
533     {
534         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
535         msp->data.ptrvalue = av.ptrvalue;
536         atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
537     }
538     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;  /* end struct */
539 ret:
540         AsnUnlinkType(orig);
541         return msp;
542 erret:
543     msp = ValNodeFreeData(msp);
544     goto ret;
545 }
546 
547 /*****************************************************************************
548 *
549 *   MedlineSiAsnWrite(msp, aip, atp) 
550 *
551 *****************************************************************************/
552 NLM_EXTERN Boolean LIBCALL MedlineSiAsnWrite (ValNodePtr msp, AsnIoPtr aip, AsnTypePtr orig)
553 {
554         DataVal av;
555         AsnTypePtr atp;
556     Boolean retval = FALSE;
557 
558         if (! loaded)
559         {
560                 if (! MedlineAsnLoad())
561                         return FALSE;
562         }
563 
564         if (aip == NULL)
565                 return FALSE;
566 
567         atp = AsnLinkType(orig, MEDLINE_SI);
568     if (atp == NULL) return FALSE;
569 
570         if (msp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
571 
572     if (! AsnOpenStruct(aip, atp, (Pointer)msp)) goto erret;
573     av.intvalue = (Int4)msp->choice;
574     if (! AsnWrite(aip, MEDLINE_SI_type, &av)) goto erret;
575     if (msp->data.ptrvalue != NULL)
576     {
577         av.ptrvalue = msp->data.ptrvalue;
578         if (! AsnWrite(aip, MEDLINE_SI_cit, &av)) goto erret;
579     }
580     if (! AsnCloseStruct(aip, atp, (Pointer)msp)) goto erret;
581     retval = TRUE;
582 erret:
583         AsnUnlinkType(orig);
584         return retval;
585 }
586 
587 /*****************************************************************************
588 *
589 *   MedlineEntryNew()
590 *
591 *****************************************************************************/
592 NLM_EXTERN MedlineEntryPtr LIBCALL MedlineEntryNew (void)
593 {
594         MedlineEntryPtr mep;
595 
596         mep = (MedlineEntryPtr)MemNew(sizeof(MedlineEntry));
597         return mep;
598 }
599 
600 /*****************************************************************************
601 *
602 *   MedlineEntryFree()
603 *
604 *****************************************************************************/
605 NLM_EXTERN MedlineEntryPtr LIBCALL MedlineEntryFree (MedlineEntryPtr mep)
606 {
607     MedlineMeshPtr mmp, mmpnext;
608     MedlineRnPtr mrp, mrpnext;
609         MedlineFieldPtr mfp, mfpnext;
610 
611     if (mep == NULL)
612         return mep;
613 
614     DateFree(mep->em);
615     CitArtFree(mep->cit);
616     MemFree(mep->abstract);
617     mmp = mep->mesh;
618     while (mmp != NULL)
619     {
620         mmpnext = mmp->next;
621         MedlineMeshFree(mmp);
622         mmp = mmpnext;
623     }
624     mrp = mep->substance;
625     while (mrp != NULL)
626     {
627         mrpnext = mrp->next;
628         MedlineRnFree(mrp);
629         mrp = mrpnext;
630     }
631     ValNodeFreeData(mep->xref);
632     ValNodeFreeData(mep->idnum);
633     ValNodeFreeData(mep->gene);
634         ValNodeFreeData(mep->pub_type);
635         for (mfp = mep->mlfield; mfp != NULL; mfp = mfpnext)
636         {
637                 mfpnext = mfp->next;
638                 MedlineFieldFree(mfp);
639         }
640 
641         ObjMgrDelete(OBJ_MEDLINE_ENTRY, (Pointer)mep);
642 
643         return (MedlineEntryPtr)MemFree(mep);
644 }
645 
646 /*****************************************************************************
647 *
648 *   MedlineEntryAsnRead(aip, atp)
649 *
650 *****************************************************************************/
651 NLM_EXTERN MedlineEntryPtr LIBCALL MedlineEntryAsnRead (AsnIoPtr aip, AsnTypePtr orig)
652 {
653         MedlineEntryPtr mep=NULL;
654         DataVal av;
655         AsnTypePtr atp, oldatp;
656     MedlineMeshPtr mmp, mmplast;
657     MedlineRnPtr mrp, mrplast;
658         MedlineFieldPtr mfp, mfplast;
659     ValNodePtr anp, anplast;
660 
661         if (! loaded)
662         {
663                 if (! MedlineAsnLoad())
664                         return mep;
665         }
666 
667         if (aip == NULL)
668                 return mep;
669 
670         if (orig == NULL)           /* MedlineEntry ::= */
671                 atp = AsnReadId(aip, amp, MEDLINE_ENTRY);
672         else
673                 atp = AsnLinkType(orig, MEDLINE_ENTRY);
674     oldatp = atp;
675     if (atp == NULL) return mep;
676 
677         mep = MedlineEntryNew();
678     if (mep == NULL) goto erret;
679 
680     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the SEQUENCE */
681     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;  /* uid */
682         if (atp == MEDLINE_ENTRY_uid)                                                             /* but now its optional */
683         {
684                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
685                 mep->uid = av.intvalue;
686                 atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;  /* entry month */
687         }
688     mep->em = DateAsnRead(aip, atp);
689     if (mep->em == NULL) goto erret;
690     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;   /* citation */
691     mep->cit = CitArtAsnRead(aip, atp);
692     if (mep->cit == NULL) goto erret;
693     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
694     {
695         if (atp == NULL) goto erret;
696         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
697         if (atp == MEDLINE_ENTRY_abstract)
698         {
699             mep->abstract = (CharPtr)av.ptrvalue;
700         }
701                 else if (atp == MEDLINE_ENTRY_pmid)
702                 {
703                         mep->pmid = av.intvalue;
704                 }
705         else if (atp == MEDLINE_ENTRY_mesh)
706         {
707             mmplast = NULL;
708             while ((atp = AsnReadId(aip, amp, atp)) != MEDLINE_ENTRY_mesh)
709             {
710                 if (atp == NULL) goto erret;
711                mmp = MedlineMeshAsnRead(aip, atp);
712                 if (mmp == NULL) goto erret;
713                if (mmplast == NULL)
714                     mep->mesh = mmp;
715                 else
716                     mmplast->next = mmp;
717                 mmplast = mmp;
718             }
719             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end of SET OF */
720         }
721         else if (atp == MEDLINE_ENTRY_substance)
722         {
723             mrplast = NULL;
724             while ((atp = AsnReadId(aip, amp, atp)) != MEDLINE_ENTRY_substance)
725             {
726                 if (atp == NULL) goto erret;
727                 mrp = MedlineRnAsnRead(aip, atp);
728                 if (mrp == NULL) goto erret;
729                 if (mrplast == NULL)
730                     mep->substance = mrp;
731                 else
732                     mrplast->next = mrp;
733                 mrplast = mrp;
734             }
735             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end SET OF */
736         }
737         else if (atp == MEDLINE_ENTRY_xref)
738         {
739             anplast = NULL;
740             while ((atp = AsnReadId(aip, amp, atp)) == MEDLINE_ENTRY_xref_E)
741             {
742                 anp = MedlineSiAsnRead(aip, atp);
743                 if (anp == NULL) goto erret;
744                 if (mep->xref == NULL)
745                     mep->xref = anp;
746                 else if (anplast != NULL)
747                     anplast->next = anp;
748                 anplast = anp;
749             }
750             if (atp == NULL) goto erret;
751             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
752         }
753         else if (atp == MEDLINE_ENTRY_idnum)
754         {
755             anp = NULL;
756             while ((atp = AsnReadId(aip, amp, atp)) != MEDLINE_ENTRY_idnum)
757             {
758                 if (atp == NULL) goto erret;
759                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
760                 anp = ValNodeNew(anp);
761                 if (anp == NULL) goto erret;
762                 if (mep->idnum == NULL)
763                     mep->idnum = anp;
764                 anp->data.ptrvalue = av.ptrvalue;   /* VisibleString */
765             }
766             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end SET OF */
767         }
768         else if (atp == MEDLINE_ENTRY_gene)
769         {
770             anp = NULL;
771             while ((atp = AsnReadId(aip, amp, atp)) != MEDLINE_ENTRY_gene)
772             {
773                 if (atp == NULL) goto erret;
774                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
775                 anp = ValNodeNew(anp);
776                 if (anp == NULL) goto erret;
777                 if (mep->gene == NULL)
778                     mep->gene = anp;
779                 anp->data.ptrvalue = av.ptrvalue;   /* VisibleString */
780             }
781             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end SET OF */
782         }
783         else if (atp == MEDLINE_ENTRY_pub_type)
784         {
785             anp = NULL;
786             while ((atp = AsnReadId(aip, amp, atp)) != MEDLINE_ENTRY_pub_type)
787             {
788                 if (atp == NULL) goto erret;
789                 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
790                 anp = ValNodeNew(anp);
791                 if (anp == NULL) goto erret;
792                 if (mep->pub_type == NULL)
793                     mep->pub_type = anp;
794                 anp->data.ptrvalue = av.ptrvalue;   /* VisibleString */
795             }
796             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end SET OF */
797         }
798         else if (atp == MEDLINE_ENTRY_mlfield)
799         {
800             mfplast = NULL;
801             while ((atp = AsnReadId(aip, amp, atp)) != MEDLINE_ENTRY_mlfield)
802             {
803                 if (atp == NULL) goto erret;
804                mfp = MedlineFieldAsnRead(aip, atp);
805                 if (mfp == NULL) goto erret;
806                if (mfplast == NULL)
807                     mep->mlfield = mfp;
808                 else
809                     mfplast->next = mfp;
810                 mfplast = mfp;
811             }
812             if (AsnReadVal(aip, atp, &av) <= 0) goto erret;   /* end of SET OF */
813         }
814         else if (atp == MEDLINE_ENTRY_status)
815         {
816             mep->status = (Uint1)(av.intvalue);
817         }
818     }
819 
820         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the END STRUCT */
821 ret:
822         AsnUnlinkType(orig);
823         return mep;
824 erret:
825     mep = MedlineEntryFree(mep);
826     goto ret;
827 }
828 
829 /*****************************************************************************
830 *
831 *   MedlineEntryAsnWrite(mep, aip, atp) 
832 *
833 *****************************************************************************/
834 NLM_EXTERN Boolean LIBCALL MedlineEntryAsnWrite (MedlineEntryPtr mep, AsnIoPtr aip, AsnTypePtr orig)
835 {
836         DataVal av;
837         AsnTypePtr atp;
838     MedlineMeshPtr mmp;
839     MedlineRnPtr mrp;
840         MedlineFieldPtr mfp;
841     ValNodePtr anp;
842     Boolean retval = FALSE, writemuid = FALSE;
843 
844         if (! loaded)
845         {
846                 if (! MedlineAsnLoad())
847                         return FALSE;
848         }
849 
850         if (aip == NULL)
851                 return FALSE;
852 
853         atp = AsnLinkType(orig, MEDLINE_ENTRY);
854     if (atp == NULL) return FALSE;
855 
856         if (mep == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
857 
858     if (! AsnOpenStruct(aip, atp, (Pointer)mep)) goto erret;
859 
860         if (mep->uid > 0)        /* now it is optional */
861         {
862                 writemuid = TRUE;
863         }
864         else if (aip->spec_version > 0 && aip->spec_version < 5)
865         {
866                 ErrPostEx(SEV_ERROR,0,0,"ASN4: MUID=0 written");
867                 writemuid = TRUE;
868         }
869 
870         if (writemuid)
871         {
872                 av.intvalue = mep->uid;
873                 if (! AsnWrite(aip, MEDLINE_ENTRY_uid, &av)) goto erret;
874         }
875     if (! DateAsnWrite(mep->em, aip, MEDLINE_ENTRY_em)) goto erret;
876     if (! CitArtAsnWrite(mep->cit, aip, MEDLINE_ENTRY_cit)) goto erret;
877     if (mep->abstract != NULL)
878     {
879         av.ptrvalue = mep->abstract;
880         if (! AsnWrite(aip, MEDLINE_ENTRY_abstract, &av)) goto erret;
881     }
882     if (mep->mesh != NULL)
883     {
884         if (! AsnOpenStruct(aip, MEDLINE_ENTRY_mesh, (Pointer)mep->mesh))
885             goto erret;
886         mmp = mep->mesh;
887         while (mmp != NULL)
888         {
889             if (! MedlineMeshAsnWrite(mmp, aip, MEDLINE_ENTRY_mesh_E))
890                 goto erret;
891             mmp = mmp->next;
892         }
893         if (! AsnCloseStruct(aip, MEDLINE_ENTRY_mesh, (Pointer)mep->mesh))
894             goto erret;
895     }
896     if (mep->substance != NULL)
897     {
898         if (! AsnOpenStruct(aip, MEDLINE_ENTRY_substance, (Pointer)mep->substance))
899             goto erret;
900         mrp = mep->substance;
901         while (mrp != NULL)
902         {
903             if (! MedlineRnAsnWrite(mrp, aip, MEDLINE_ENTRY_substance_E))
904                 goto erret;
905             mrp = mrp->next;
906         }
907         if (! AsnCloseStruct(aip, MEDLINE_ENTRY_substance, (Pointer)mep->substance))
908             goto erret;
909     }
910     if (mep->xref != NULL)
911     {
912         if (! AsnOpenStruct(aip, MEDLINE_ENTRY_xref, (Pointer)mep->xref))
913             goto erret;
914         anp = mep->xref;
915         while (anp != NULL)
916         {
917             if (! MedlineSiAsnWrite(anp, aip, MEDLINE_ENTRY_xref_E))
918                 goto erret;
919             anp = anp->next;
920         }
921         if (! AsnCloseStruct(aip, MEDLINE_ENTRY_xref, (Pointer)mep->xref))
922             goto erret;
923     }
924     if (mep->idnum != NULL)
925     {
926         if (! AsnOpenStruct(aip, MEDLINE_ENTRY_idnum, (Pointer)mep->idnum))
927             goto erret;
928         anp = mep->idnum;
929         while (anp != NULL)
930         {
931             av.ptrvalue = anp->data.ptrvalue;
932             if (! AsnWrite(aip, MEDLINE_ENTRY_idnum_E, &av)) goto erret;
933             anp = anp->next;
934         }
935         if (! AsnCloseStruct(aip, MEDLINE_ENTRY_idnum, (Pointer)mep->idnum))
936             goto erret;
937     }
938     if (mep->gene != NULL)
939     {
940         if (! AsnOpenStruct(aip, MEDLINE_ENTRY_gene, (Pointer)mep->gene))
941             goto erret;
942         anp = mep->gene;
943         while (anp != NULL)
944         {
945             av.ptrvalue = anp->data.ptrvalue;
946             if (! AsnWrite(aip, MEDLINE_ENTRY_gene_E, &av)) goto erret;
947             anp = anp->next;
948         }
949         if (! AsnCloseStruct(aip, MEDLINE_ENTRY_gene, (Pointer)mep->gene))
950             goto erret;
951     }
952         if (mep->pmid > 0)       /* PubMedId */
953         {
954                 if (aip->spec_version > 0 && aip->spec_version < 5)  /* ASN4 strip new value */
955                 {
956                         ErrPostEx(SEV_ERROR,0,0,"ASN4: PubMedId stripped");
957                 }
958                 else
959                 {
960                         av.intvalue = mep->pmid;
961                         if (! AsnWrite(aip, MEDLINE_ENTRY_pmid, &av)) goto erret;
962                 }
963         }
964 
965     if (    mep->pub_type != NULL
966          && (aip->spec_version >= 5 || aip->spec_version == 0) ) {
967         if (! AsnOpenStruct(aip, MEDLINE_ENTRY_pub_type, (Pointer)mep->pub_type))
968             goto erret;
969         anp = mep->pub_type;
970         while (anp != NULL)
971         {
972             av.ptrvalue = anp->data.ptrvalue;
973             if (! AsnWrite(aip, MEDLINE_ENTRY_pub_type_E, &av)) goto erret;
974             anp = anp->next;
975         }
976         if (! AsnCloseStruct(aip, MEDLINE_ENTRY_pub_type, (Pointer)mep->pub_type))
977             goto erret;
978     }
979 
980     if (    mep->mlfield != NULL
981          && (aip->spec_version >= 6 || aip->spec_version == 0) ) {
982         if (! AsnOpenStruct(aip, MEDLINE_ENTRY_mlfield, (Pointer)mep->mlfield))
983             goto erret;
984         mfp = mep->mlfield;
985         while (mfp != NULL)
986         {
987                         if (! MedlineFieldAsnWrite(mfp, aip, MEDLINE_ENTRY_mlfield_E))
988                                 goto erret;
989                         mfp = mfp->next;
990         }
991         if (! AsnCloseStruct(aip, MEDLINE_ENTRY_mlfield, (Pointer)mep->mlfield))
992             goto erret;
993     }
994 
995         if (mep->status > 0)     /* medline processing status level */
996         {
997                 if ((aip->spec_version == 0) || (aip->spec_version >= 6))
998                 {
999                         av.intvalue = (Int4)(mep->status);
1000                         if (! AsnWrite(aip, MEDLINE_ENTRY_status, &av)) goto erret;
1001                 }
1002         }
1003 
1004     if (! AsnCloseStruct(aip, atp, (Pointer)mep)) goto erret;
1005     retval = TRUE;
1006 erret:
1007         AsnUnlinkType(orig);
1008         return retval;
1009 }
1010 
1011 /*****************************************************************************
1012 *
1013 *   MedlineFieldNew()
1014 *
1015 *****************************************************************************/
1016 NLM_EXTERN MedlineFieldPtr LIBCALL MedlineFieldNew (void)
1017 {
1018         MedlineFieldPtr mfp;
1019 
1020         mfp = (MedlineFieldPtr)MemNew(sizeof(MedlineField));
1021         return mfp;
1022 }
1023 
1024 /*****************************************************************************
1025 *
1026 *   MedlineFieldFree()
1027 *
1028 *****************************************************************************/
1029 NLM_EXTERN MedlineFieldPtr LIBCALL MedlineFieldFree (MedlineFieldPtr mfp)
1030 {
1031         DocRefPtr dfp, next;
1032     if (mfp == NULL)
1033         return mfp;
1034 
1035     MemFree(mfp->str);
1036         for (dfp = mfp->ids; dfp != NULL; dfp = next)
1037         {
1038                 next = dfp->next;
1039                 DocRefFree(dfp);
1040         }
1041     
1042         return (MedlineFieldPtr)MemFree(mfp);
1043 }
1044 
1045 /*****************************************************************************
1046 *
1047 *   MedlineFieldAsnRead(aip, atp)
1048 *
1049 *****************************************************************************/
1050 NLM_EXTERN MedlineFieldPtr LIBCALL MedlineFieldAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1051 {
1052         MedlineFieldPtr mfp=NULL;
1053         DataVal av;
1054         AsnTypePtr atp, oldatp;
1055         DocRefPtr drp, prev = NULL;
1056 
1057         if (! loaded)
1058         {
1059                 if (! MedlineAsnLoad())
1060                         return mfp;
1061         }
1062 
1063         if (aip == NULL)
1064                 return mfp;
1065 
1066         if (orig == NULL)           /* MedlineField ::= */
1067                 atp = AsnReadId(aip, amp, MEDLINE_FIELD);
1068         else
1069                 atp = AsnLinkType(orig, MEDLINE_FIELD);
1070     if (atp == NULL) return mfp;
1071         oldatp = atp;
1072 
1073         mfp = MedlineFieldNew();
1074     if (mfp == NULL) goto erret;
1075 
1076     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the SEQUENCE */
1077     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;  /* type */
1078     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1079     mfp->type = (Uint1)av.intvalue;
1080     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
1081     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1082     mfp->str = (CharPtr)av.ptrvalue;
1083 
1084     while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
1085         {
1086                 if (atp == NULL) goto erret;
1087                 if (atp == MEDLINE_FIELD_ids_E)
1088                 {
1089                         drp = DocRefAsnRead(aip, atp);
1090                         if (prev == NULL)
1091                                 mfp->ids = drp;
1092                         else
1093                                 prev->next = drp;
1094                         prev = drp;
1095                 }
1096                 else
1097                         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1098         }
1099         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the END STRUCT */
1100 ret:
1101         AsnUnlinkType(orig);
1102         return mfp;
1103 erret:
1104     mfp = MedlineFieldFree(mfp);
1105     goto ret;
1106 }
1107 
1108 /*****************************************************************************
1109 *
1110 *   MedlineFieldAsnWrite(mfp, aip, atp) 
1111 *
1112 *****************************************************************************/
1113 NLM_EXTERN Boolean LIBCALL MedlineFieldAsnWrite (MedlineFieldPtr mfp, AsnIoPtr aip, AsnTypePtr orig)
1114 {
1115         DataVal av;
1116         AsnTypePtr atp;
1117     Boolean retval = TRUE;
1118         DocRefPtr drp;
1119 
1120         if (! loaded)
1121         {
1122                 if (! MedlineAsnLoad())
1123                         return FALSE;
1124         }
1125 
1126         if (aip == NULL)
1127                 return FALSE;
1128 
1129         atp = AsnLinkType(orig, MEDLINE_FIELD);
1130     if (atp == NULL) return FALSE;
1131 
1132         if (mfp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1133 
1134     if (! AsnOpenStruct(aip, atp, (Pointer)mfp)) goto erret;
1135     av.intvalue = (Int4)mfp->type;
1136     if (! AsnWrite(aip, MEDLINE_FIELD_type, &av)) goto erret;
1137     av.ptrvalue = mfp->str;
1138     if (! AsnWrite(aip, MEDLINE_FIELD_str, &av)) goto erret;
1139         if (mfp->ids != NULL)
1140         {
1141                 if (! AsnOpenStruct(aip, MEDLINE_FIELD_ids, (Pointer)mfp->ids)) goto erret;
1142                 for (drp = mfp->ids; drp != NULL; drp = drp->next)
1143                 {
1144                         if (! DocRefAsnWrite(drp, aip, MEDLINE_FIELD_ids_E))
1145                                 goto erret;
1146                 }
1147                 if (! AsnCloseStruct(aip, MEDLINE_FIELD_ids, (Pointer)mfp->ids)) goto erret;
1148         }
1149     if (! AsnCloseStruct(aip, atp, (Pointer)mfp)) goto erret;
1150     retval = TRUE;
1151 erret:
1152         AsnUnlinkType(orig);
1153         return retval;
1154 }
1155 
1156 
1157 /*****************************************************************************
1158 *
1159 *   DocRefNew()
1160 *
1161 *****************************************************************************/
1162 NLM_EXTERN DocRefPtr LIBCALL DocRefNew (void)
1163 {
1164         DocRefPtr drp;
1165 
1166         drp = (DocRefPtr)MemNew(sizeof(DocRef));
1167         return drp;
1168 }
1169 
1170 /*****************************************************************************
1171 *
1172 *   DocRefFree()
1173 *
1174 *****************************************************************************/
1175 NLM_EXTERN DocRefPtr LIBCALL DocRefFree (DocRefPtr drp)
1176 {
1177     if (drp == NULL)
1178         return drp;
1179 
1180         return (DocRefPtr)MemFree(drp);
1181 }
1182 
1183 /*****************************************************************************
1184 *
1185 *   DocRefAsnRead(aip, atp)
1186 *
1187 *****************************************************************************/
1188 NLM_EXTERN DocRefPtr LIBCALL DocRefAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1189 {
1190         DocRefPtr drp=NULL;
1191         DataVal av;
1192         AsnTypePtr atp;
1193 
1194         if (! loaded)
1195         {
1196                 if (! MedlineAsnLoad())
1197                         return drp;
1198         }
1199 
1200         if (aip == NULL)
1201                 return drp;
1202 
1203         if (orig == NULL)           /* DocRef ::= */
1204                 atp = AsnReadId(aip, amp, DOCREF);
1205         else
1206                 atp = AsnLinkType(orig, DOCREF);
1207     if (atp == NULL) return drp;
1208 
1209         drp = DocRefNew();
1210     if (drp == NULL) goto erret;
1211 
1212     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the SEQUENCE */
1213     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;  /* type */
1214     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1215     drp->type = (Uint1)av.intvalue;
1216     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
1217     if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1218     drp->uid = av.intvalue;
1219 
1220     atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
1221         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the END STRUCT */
1222 ret:
1223         AsnUnlinkType(orig);
1224         return drp;
1225 erret:
1226     drp = DocRefFree(drp);
1227     goto ret;
1228 }
1229 
1230 /*****************************************************************************
1231 *
1232 *   DocRefAsnWrite(drp, aip, atp) 
1233 *
1234 *****************************************************************************/
1235 NLM_EXTERN Boolean LIBCALL DocRefAsnWrite (DocRefPtr drp, AsnIoPtr aip, AsnTypePtr orig)
1236 {
1237         DataVal av;
1238         AsnTypePtr atp;
1239     Boolean retval = TRUE;
1240 
1241         if (! loaded)
1242         {
1243                 if (! MedlineAsnLoad())
1244                         return FALSE;
1245         }
1246 
1247         if (aip == NULL)
1248                 return FALSE;
1249 
1250         atp = AsnLinkType(orig, DOCREF);
1251     if (atp == NULL) return FALSE;
1252 
1253         if (drp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1254 
1255     if (! AsnOpenStruct(aip, atp, (Pointer)drp)) goto erret;
1256     av.intvalue = (Int4)drp->type;
1257     if (! AsnWrite(aip, DOCREF_type, &av)) goto erret;
1258     av.intvalue = (Int4)drp->uid;
1259     if (! AsnWrite(aip, DOCREF_uid, &av)) goto erret;
1260     if (! AsnCloseStruct(aip, atp, (Pointer)drp)) goto erret;
1261     retval = TRUE;
1262 erret:
1263         AsnUnlinkType(orig);
1264         return retval;
1265 }
1266 
1267 
1268 

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.