|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/object/objbibli.c |
source navigation diff markup identifier search freetext search file search |
1 /* objbibli.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: objbibli.c
27 *
28 * Author: James Ostell
29 *
30 * Version Creation Date: 1/1/91
31 *
32 * $Revision: 6.8 $
33 *
34 * File Description: Object manager for module NCBI-Biblio
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date Name Description of modification
39 * ------- ---------- -----------------------------------------------------
40 * 05-13-93 Schuler All public functions are now declared LIBCALL.
41 * 07-19-93 Ostell Support for ASN30 added
42 *
43 * $Log: objbibli.c,v $
44 * Revision 6.8 2009/10/02 19:44:48 kans
45 * address clang static analyzer warnings
46 *
47 * Revision 6.7 2006/02/22 17:31:45 kans
48 * fix to AuthListMatch (CB)
49 *
50 * Revision 6.6 2005/05/18 17:31:01 bollin
51 * added AffilMatch and AuthorMatch functions
52 *
53 * Revision 6.5 2001/10/09 15:57:38 kans
54 * AuthListMatch does StringICmp if both are structured last names, StringNICmp otherwise
55 *
56 * Revision 6.4 2000/01/18 19:40:51 ostell
57 * added support for PubStatusDate, ArticleIds
58 *
59 * Revision 6.3 2000/01/05 18:44:12 kans
60 * increased buffer size in AuthListMatch, which was overflowing
61 *
62 * Revision 6.2 1998/08/24 18:27:59 kans
63 * removed solaris -v -fd warnings
64 *
65 * Revision 6.1 1997/11/13 21:31:59 kans
66 * fixed endless loop in CitArtFree (Kuzio)
67 *
68 * Revision 6.0 1997/08/25 18:49:19 madden
69 * Revision changed to 6.0
70 *
71 * Revision 4.7 1997/08/20 19:16:53 madden
72 * Version 6 of ASN.1
73 *
74 * Revision 4.6 1997/06/19 18:40:46 vakatov
75 * [WIN32,MSVC++] Adopted for the "NCBIOBJ.LIB" DLL'ization
76 *
77 * Revision 4.5 1997/03/18 15:30:07 ostell
78 * make IdPatMatch case insensitive
79 *
80 * Revision 4.4 1996/12/12 21:49:08 tatiana
81 * CiSubMatch changed to compare the dates from both ImpPrint.date and date
82 *
83 * Revision 4.3 1996/12/04 18:18:41 kans
84 * CitSubMatch calls ImprintMatch only if both imp fields not NULL, and
85 * calls DateMatch if date fields not NULL
86 *
87 * Revision 4.2 1996/07/30 15:50:50 epstein
88 * correct logic errors for different spec_versions
89 *
90 * Revision 4.1 1996/03/29 21:09:59 ostell
91 * added support for PubMedId
92 *
93 * Revision 4.0 1995/07/26 13:48:06 ostell
94 * force revision to 4.0
95 *
96 * Revision 3.6 1995/05/24 21:20:50 ostell
97 * typo fix
98 *
99 * Revision 3.5 1995/05/24 19:10:27 ostell
100 * added filtering (grep for "ASN3 strip") to conform to old version 3.0
101 * asn.1 spec.
102 *
103 * Revision 3.4 1995/05/15 21:22:00 ostell
104 * added Log line
105 *
106 *
107 *
108 * ==========================================================================
109 */
110 #include <asnbibli.h>
111 #include <objbibli.h>
112
113
114 static Boolean loaded = FALSE;
115
116 /*****************************************************************************
117 *
118 * Bibliographic Object routines
119 *
120 *****************************************************************************/
121
122 /*****************************************************************************
123 *
124 * BiblioAsnLoad()
125 *
126 *****************************************************************************/
127 NLM_EXTERN Boolean LIBCALL BiblioAsnLoad (void)
128 {
129 if (loaded)
130 return TRUE;
131 loaded = TRUE;
132
133 if (! GeneralAsnLoad())
134 {
135 loaded = FALSE;
136 return FALSE;
137 }
138 if (! AsnLoad())
139 {
140 loaded = FALSE;
141 return FALSE;
142 }
143 return TRUE;
144 }
145
146 /*****************************************************************************
147 *
148 * AffilNew()
149 *
150 *****************************************************************************/
151 NLM_EXTERN AffilPtr LIBCALL AffilNew (void)
152 {
153 AffilPtr afp;
154
155 afp = (AffilPtr)MemNew(sizeof(Affil));
156 return afp;
157 }
158
159 /*****************************************************************************
160 *
161 * AffilFree()
162 *
163 *****************************************************************************/
164 NLM_EXTERN AffilPtr LIBCALL AffilFree (AffilPtr afp)
165 {
166 if (afp == NULL)
167 return afp;
168 MemFree(afp->affil);
169 MemFree(afp->div);
170 MemFree(afp->city);
171 MemFree(afp->sub);
172 MemFree(afp->country);
173 MemFree(afp->street);
174 MemFree(afp->email);
175 MemFree(afp->fax);
176 MemFree(afp->phone);
177 MemFree(afp->postal_code);
178 return (AffilPtr)MemFree(afp);
179 }
180
181 /*****************************************************************************
182 *
183 * AffilAsnRead(aip, atp)
184 *
185 *****************************************************************************/
186 NLM_EXTERN AffilPtr LIBCALL AffilAsnRead (AsnIoPtr aip, AsnTypePtr orig)
187 {
188 AffilPtr afp=NULL;
189 DataVal av;
190 AsnTypePtr atp;
191
192 if (! loaded)
193 {
194 if (! BiblioAsnLoad())
195 return afp;
196 }
197
198 if (aip == NULL)
199 return afp;
200
201 if (orig == NULL) /* Affil ::= */
202 atp = AsnReadId(aip, amp, AFFIL);
203 else
204 atp = AsnLinkType(orig, AFFIL);
205 if (atp == NULL)
206 return afp;
207
208 afp = AffilNew();
209 if (afp == NULL)
210 goto erret;
211
212 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the CHOICE */
213 atp = AsnReadId(aip, amp, atp); /* read the CHOICE id */
214 if (atp == NULL)
215 goto erret;
216
217 if (atp == AFFIL_str) /* just the VisibleString */
218 {
219 afp->choice = 1; /* choice type is str */
220 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* get the string */
221 afp->affil = (CharPtr)av.ptrvalue; /* keep it */
222 }
223 else /* affiliation structure */
224 {
225 afp->choice = 2; /* choice type is std */
226 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the START_STRUCT */
227
228 while ((atp = AsnReadId(aip, amp, atp)) != AFFIL_std)
229 {
230 if (atp == NULL)
231 goto erret;
232 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
233 if (atp == AFFIL_std_affil)
234 afp->affil = (CharPtr)av.ptrvalue;
235 else if (atp == AFFIL_std_div)
236 afp->div = (CharPtr)av.ptrvalue;
237 else if (atp == AFFIL_std_city)
238 afp->city = (CharPtr)av.ptrvalue;
239 else if (atp == AFFIL_std_sub)
240 afp->sub = (CharPtr)av.ptrvalue;
241 else if (atp == AFFIL_std_country)
242 afp->country = (CharPtr)av.ptrvalue;
243 else if (atp == AFFIL_std_street)
244 afp->street = (CharPtr)av.ptrvalue;
245 else if (atp == AFFIL_std_email)
246 afp->email = (CharPtr)av.ptrvalue;
247 else if (atp == AFFIL_std_fax)
248 afp->fax = (CharPtr)av.ptrvalue;
249 else if (atp == AFFIL_std_phone)
250 afp->phone = (CharPtr)av.ptrvalue;
251 else if (atp == AFFIL_std_postal_code)
252 {
253 if (aip->spec_version == 3) /* ASN3 strip new value */
254 {
255 ErrPostEx(SEV_ERROR,0,0,"ASN3: postal_code stripped");
256 MemFree((CharPtr)(av.ptrvalue));
257 }
258 else
259 afp->postal_code = (CharPtr)av.ptrvalue;
260 }
261 }
262 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the END STRUCT */
263 }
264 ret:
265 AsnUnlinkType(orig);
266 return afp;
267 erret:
268 afp = AffilFree(afp);
269 goto ret;
270 }
271
272 /*****************************************************************************
273 *
274 * AffilAsnWrite(afp, aip, atp)
275 *
276 *****************************************************************************/
277 NLM_EXTERN Boolean LIBCALL AffilAsnWrite (AffilPtr afp, AsnIoPtr aip, AsnTypePtr orig)
278 {
279 DataVal av;
280 AsnTypePtr atp;
281 Boolean retval = FALSE;
282
283 if (! loaded)
284 {
285 if (! BiblioAsnLoad())
286 return FALSE;
287 }
288
289 if (aip == NULL)
290 return FALSE;
291
292 atp = AsnLinkType(orig, AFFIL);
293 if (atp == NULL)
294 return FALSE;
295
296 if (afp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
297
298 if (! AsnWrite(aip, atp, &av)) /* write the tag */
299 goto erret;
300
301 if (afp->choice == 1) /* string */
302 {
303 av.ptrvalue = afp->affil;
304 if (! AsnWrite(aip, AFFIL_str, &av)) /* write the string */
305 goto erret;
306 }
307 else /* std */
308 {
309 if (! AsnOpenStruct(aip, AFFIL_std, (Pointer)afp))
310 goto erret;
311 if (afp->affil != NULL)
312 {
313 av.ptrvalue = afp->affil;
314 if (! AsnWrite(aip, AFFIL_std_affil, &av))
315 goto erret;
316 }
317 if (afp->div != NULL)
318 {
319 av.ptrvalue = afp->div;
320 if (! AsnWrite(aip, AFFIL_std_div, &av)) goto erret;
321 }
322 if (afp->city != NULL)
323 {
324 av.ptrvalue = afp->city;
325 if (! AsnWrite(aip, AFFIL_std_city, &av)) goto erret;
326 }
327 if (afp->sub != NULL)
328 {
329 av.ptrvalue = afp->sub;
330 if (! AsnWrite(aip, AFFIL_std_sub, &av)) goto erret;
331 }
332 if (afp->country != NULL)
333 {
334 av.ptrvalue = afp->country;
335 if (! AsnWrite(aip, AFFIL_std_country, &av)) goto erret;
336 }
337 if (afp->street != NULL)
338 {
339 av.ptrvalue = afp->street;
340 if (! AsnWrite(aip, AFFIL_std_street, &av)) goto erret;
341 }
342 if (afp->email != NULL)
343 {
344 av.ptrvalue = afp->email;
345 if (! AsnWrite(aip, AFFIL_std_email, &av)) goto erret;
346 }
347 if (afp->fax != NULL)
348 {
349 av.ptrvalue = afp->fax;
350 if (! AsnWrite(aip, AFFIL_std_fax, &av)) goto erret;
351 }
352 if (afp->phone != NULL)
353 {
354 av.ptrvalue = afp->phone;
355 if (! AsnWrite(aip, AFFIL_std_phone, &av)) goto erret;
356 }
357 if (afp->postal_code != NULL)
358 {
359 if (aip->spec_version == 3) /* ASN3 strip new value */
360 {
361 ErrPostEx(SEV_ERROR,0,0,"ASN3: postal_code stripped");
362 }
363 else
364 {
365 av.ptrvalue = afp->postal_code;
366 if (! AsnWrite(aip, AFFIL_std_postal_code, &av)) goto erret;
367 }
368 }
369
370 if (! AsnCloseStruct(aip, AFFIL_std, (Pointer)afp))
371 goto erret;
372 }
373 retval = TRUE;
374 erret:
375 AsnUnlinkType(orig);
376 return retval;
377 }
378
379 /*****************************************************************************
380 *
381 * AffilMatch(ap1, ap2)
382 *
383 *****************************************************************************/
384 NLM_EXTERN Boolean AffilMatch (AffilPtr ap1, AffilPtr ap2)
385 {
386 if (ap1 == NULL && ap2 == NULL)
387 {
388 return TRUE;
389 }
390 else if (ap1 == NULL || ap2 == NULL)
391 {
392 return FALSE;
393 }
394 else if (ap1->choice != ap2->choice)
395 {
396 return FALSE;
397 }
398 else if (StringCmp (ap1->affil, ap2->affil) != 0
399 || StringCmp (ap1->div, ap2->div) != 0
400 || StringCmp (ap1->city, ap2->city) != 0
401 || StringCmp (ap1->sub, ap2->sub) != 0
402 || StringCmp (ap1->country, ap2->country) != 0
403 || StringCmp (ap1->street, ap2->street) != 0
404 || StringCmp (ap1->email, ap2->email) != 0
405 || StringCmp (ap1->fax, ap2->fax) != 0
406 || StringCmp (ap1->phone, ap2->phone) != 0
407 || StringCmp (ap1->postal_code, ap2->postal_code) != 0)
408 {
409 return FALSE;
410 }
411 else
412 {
413 return TRUE;
414 }
415 }
416
417 /*****************************************************************************
418 *
419 * AuthListNew()
420 *
421 *****************************************************************************/
422 NLM_EXTERN AuthListPtr LIBCALL AuthListNew (void)
423 {
424 AuthListPtr alp;
425
426 alp = (AuthListPtr)MemNew(sizeof(AuthList));
427 return alp;
428 }
429
430 /*****************************************************************************
431 *
432 * AuthListFree()
433 *
434 *****************************************************************************/
435 NLM_EXTERN AuthListPtr LIBCALL AuthListFree (AuthListPtr alp)
436 {
437 ValNodePtr curr, next;
438
439 if (alp == NULL)
440 return alp;
441
442 curr = alp->names;
443 while (curr != NULL)
444 {
445 if (alp->choice == 1) /* std type */
446 AuthorFree((AuthorPtr) curr->data.ptrvalue);
447 else /* ml or str */
448 MemFree(curr->data.ptrvalue);
449 next = curr->next;
450 MemFree(curr);
451 curr = next;
452 }
453 if (alp->affil != NULL)
454 AffilFree(alp->affil);
455 return (AuthListPtr)MemFree(alp);
456 }
457
458 /*****************************************************************************
459 *
460 * AuthListAsnRead(aip, atp)
461 *
462 *****************************************************************************/
463 NLM_EXTERN AuthListPtr LIBCALL AuthListAsnRead (AsnIoPtr aip, AsnTypePtr orig)
464 {
465 AuthListPtr alp=NULL;
466 DataVal av;
467 AsnTypePtr atp, seqofptr;
468 Uint1 choice;
469 ValNodePtr anp;
470
471 if (! loaded)
472 {
473 if (! BiblioAsnLoad())
474 return alp;
475 }
476
477 if (aip == NULL)
478 return alp;
479
480 if (orig == NULL) /* AuthList ::= */
481 atp = AsnReadId(aip, amp, AUTH_LIST);
482 else
483 atp = AsnLinkType(orig, AUTH_LIST);
484 if (atp == NULL)
485 return alp;
486
487 alp = AuthListNew();
488 if (alp == NULL)
489 goto erret;
490
491 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the START STRUCT */
492 atp = AsnReadId(aip, amp, atp); /* read names id */
493 if (atp == NULL)
494 goto erret;
495 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the CHOICE */
496 atp = AsnReadId(aip, amp, atp); /* read the CHOICE id */
497 if (atp == NULL)
498 goto erret;
499 seqofptr = atp; /* keep to find end of loop */
500 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the START for SEQUENCE OF */
501
502 if (atp == AUTH_LIST_names_std) /* Authors */
503 choice = 1; /* choice type is str */
504 else if (atp == AUTH_LIST_names_ml) /* medline */
505 choice = 2;
506 else /* strings */
507 choice = 3;
508
509 alp->choice = choice;
510
511 anp = NULL;
512 while ((atp = AsnReadId(aip, amp, atp)) != seqofptr)
513 {
514 if (atp == NULL)
515 goto erret;
516 anp = ValNodeNew(anp); /* add to linked list */
517 if (anp == NULL)
518 goto erret;
519 if (alp->names == NULL)
520 alp->names = anp;
521 anp->choice = choice; /* not really necessary */
522 if (choice == 1) /* std */
523 anp->data.ptrvalue = (Pointer) AuthorAsnRead(aip, atp);
524 else
525 {
526 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* string types */
527 anp->data.ptrvalue = av.ptrvalue;
528 }
529 if (anp->data.ptrvalue == NULL)
530 goto erret;
531 }
532 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* SEQ OF end STRUCT */
533
534 atp = AsnReadId(aip, amp, atp);
535 if (atp == NULL)
536 goto erret;
537 if (atp == AUTH_LIST_affil) /* has an affiliation */
538 {
539 alp->affil = AffilAsnRead(aip, atp);
540 if (alp->affil == NULL)
541 goto erret;
542 atp = AsnReadId(aip, amp, atp);
543 if (atp == NULL)
544 goto erret;
545 }
546 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* END STRUCT */
547 ret:
548 AsnUnlinkType(orig);
549 return alp;
550 erret:
551 alp = AuthListFree(alp);
552 goto ret;
553 }
554
555 /*****************************************************************************
556 *
557 * AuthListAsnWrite(alp, aip, atp)
558 *
559 *****************************************************************************/
560 NLM_EXTERN Boolean LIBCALL AuthListAsnWrite (AuthListPtr alp, AsnIoPtr aip, AsnTypePtr orig)
561 {
562 DataVal av;
563 AsnTypePtr atp, seqofptr, elementptr;
564 Int1 choice;
565 ValNodePtr anp;
566 Boolean retval = FALSE;
567
568 if (! loaded)
569 {
570 if (! BiblioAsnLoad())
571 return FALSE;
572 }
573
574 if (aip == NULL)
575 return FALSE;
576
577 atp = AsnLinkType(orig, AUTH_LIST);
578 if (atp == NULL)
579 return FALSE;
580
581 if (alp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
582
583 if (! AsnOpenStruct(aip, atp, (Pointer)alp)) /* open AuthList SEQUENCE */
584 goto erret;
585
586 av.ptrvalue = alp->names;
587 if (! AsnWriteChoice(aip, AUTH_LIST_names, (Int2)alp->choice, &av)) goto erret;
588
589 /* write CHOICE for SEQUENCE OF */
590 choice = alp->choice;
591 if (choice == 1 ) /* std */
592 {
593 seqofptr = AUTH_LIST_names_std;
594 elementptr = AUTH_LIST_names_std_E;
595 }
596 else if (choice == 2) /* ml */
597 {
598 seqofptr = AUTH_LIST_names_ml;
599 elementptr = AUTH_LIST_names_ml_E;
600 }
601 else
602 {
603 seqofptr = AUTH_LIST_names_str;
604 elementptr = AUTH_LIST_names_str_E;
605 }
606
607 if (! AsnOpenStruct(aip, seqofptr, (Pointer)alp->names)) /* start SEQUENCE OF */
608 goto erret;
609
610 anp = alp->names;
611
612 while (anp != NULL)
613 {
614 if (choice == 1) /* Author */
615 {
616 if (! AuthorAsnWrite((AuthorPtr) anp->data.ptrvalue, aip, elementptr))
617 goto erret;
618 }
619 else /* str or medline */
620 {
621 av.ptrvalue = anp->data.ptrvalue;
622 if (! AsnWrite(aip, elementptr, &av)) goto erret;
623 }
624 anp = anp->next;
625 }
626
627 if (! AsnCloseStruct(aip, seqofptr, (Pointer)alp->names)) /* end SEQUENCE OF */
628 goto erret;
629
630 if (alp->affil != NULL) /* affiliation */
631 {
632 if (! AffilAsnWrite(alp->affil, aip, AUTH_LIST_affil))
633 goto erret;
634 }
635
636 if (! AsnCloseStruct(aip, atp, (Pointer)alp)) /* end AuthList SEQUENCE */
637 goto erret;
638 retval = TRUE;
639 erret:
640 AsnUnlinkType(orig);
641 return retval;
642 }
643
644 /*****************************************************************************
645 *
646 * AuthorNew()
647 *
648 *****************************************************************************/
649 NLM_EXTERN AuthorPtr LIBCALL AuthorNew (void)
650 {
651 AuthorPtr ap;
652
653 ap = (AuthorPtr)MemNew(sizeof(Author));
654 if (ap == NULL) return ap;
655 ap->is_corr = (Uint1)255;
656 return ap;
657 }
658
659 /*****************************************************************************
660 *
661 * AuthorFree()
662 *
663 *****************************************************************************/
664 NLM_EXTERN AuthorPtr LIBCALL AuthorFree (AuthorPtr ap)
665 {
666 if (ap == NULL)
667 return ap;
668
669 PersonIdFree(ap->name);
670 if (ap->affil != NULL)
671 AffilFree(ap->affil);
672 return (AuthorPtr)MemFree(ap);
673 }
674
675 /*****************************************************************************
676 *
677 * AuthorAsnRead(aip, atp)
678 *
679 *****************************************************************************/
680 NLM_EXTERN AuthorPtr LIBCALL AuthorAsnRead (AsnIoPtr aip, AsnTypePtr orig)
681 {
682 AuthorPtr ap=NULL;
683 DataVal av;
684 AsnTypePtr atp, oldatp;
685
686 if (! loaded)
687 {
688 if (! BiblioAsnLoad())
689 return ap;
690 }
691
692 if (aip == NULL)
693 return ap;
694
695 if (orig == NULL) /* Author ::= */
696 atp = AsnReadId(aip, amp, AUTHOR);
697 else
698 atp = AsnLinkType(orig, AUTHOR);
699 oldatp = atp; /* points to start of SEQUENCE */
700 if (atp == NULL)
701 return ap;
702
703 ap = AuthorNew();
704 if (ap == NULL)
705 goto erret;
706
707 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the open SEQUENCE */
708 atp = AsnReadId(aip, amp, atp); /* read the name id */
709 if (atp == NULL)
710 goto erret;
711 ap->name = PersonIdAsnRead(aip, atp); /* read the PersonId */
712 if (ap->name == NULL)
713 goto erret;
714
715 while ((atp = AsnReadId(aip, amp, atp)) != oldatp) /* read SEQUENCE */
716 {
717 if (atp == NULL)
718 goto erret;
719 if (atp == AUTHOR_affil)
720 {
721 ap->affil = AffilAsnRead(aip, atp);
722 if (ap->affil == NULL)
723 goto erret;
724 }
725 else
726 {
727 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
728 if (atp == AUTHOR_level)
729 ap->lr[0] = (Uint1) av.intvalue;
730 else if (atp == AUTHOR_role)
731 ap->lr[1] = (Uint1) av.intvalue;
732 else if (atp == AUTHOR_is_corr)
733 {
734 if (av.boolvalue)
735 ap->is_corr = 1;
736 else
737 ap->is_corr = 0;
738 }
739 }
740 }
741
742 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end of SEQUENCE */
743 ret:
744 AsnUnlinkType(orig);
745 return ap;
746 erret:
747 ap = AuthorFree(ap);
748 goto ret;
749 }
750
751 /*****************************************************************************
752 *
753 * AuthorAsnWrite(ap, aip, atp)
754 *
755 *****************************************************************************/
756 NLM_EXTERN Boolean LIBCALL AuthorAsnWrite (AuthorPtr ap, AsnIoPtr aip, AsnTypePtr orig)
757 {
758 DataVal av;
759 AsnTypePtr atp;
760 Boolean retval = FALSE;
761
762 if (! loaded)
763 {
764 if (! BiblioAsnLoad())
765 return FALSE;
766 }
767
768 if (aip == NULL)
769 return FALSE;
770
771 atp = AsnLinkType(orig, AUTHOR);
772 if (atp == NULL)
773 return FALSE;
774
775 if (ap == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
776
777 if (! AsnOpenStruct(aip, atp, (Pointer)ap)) /* open the SEQUENCE */
778 goto erret;
779
780 if (! PersonIdAsnWrite(ap->name, aip, AUTHOR_name)) /* write the name */
781 goto erret;
782
783 if (ap->lr[0] != 0) /* level set */
784 {
785 av.intvalue = (Int4) ap->lr[0];
786 if (! AsnWrite(aip, AUTHOR_level, &av)) goto erret;
787 }
788
789 if (ap->lr[1] != 0) /* role set */
790 {
791 av.intvalue = (Int4) ap->lr[1];
792 if (! AsnWrite(aip, AUTHOR_role, &av)) goto erret;
793 }
794
795 if (ap->affil != NULL)
796 {
797 if (! AffilAsnWrite(ap->affil, aip, AUTHOR_affil))
798 goto erret;
799 }
800
801 if (ap->is_corr != 255)
802 {
803 av.boolvalue = (Boolean) ap->is_corr;
804 AsnWrite(aip, AUTHOR_is_corr, &av);
805 }
806
807 if (! AsnCloseStruct(aip, atp, (Pointer)ap)) /* end SEQUENCE */
808 goto erret;
809 retval = TRUE;
810 erret:
811 AsnUnlinkType(orig);
812 return retval;
813 }
814
815 /*****************************************************************************
816 *
817 * AuthorMatch(ap1, ap2)
818 *
819 *****************************************************************************/
820 NLM_EXTERN Boolean LIBCALL AuthorMatch (AuthorPtr ap1, AuthorPtr ap2)
821 {
822 if (ap1 == NULL && ap2 == NULL)
823 {
824 return TRUE;
825 }
826 else if (ap1 == NULL || ap2 == NULL)
827 {
828 return FALSE;
829 }
830
831 if (ap1->is_corr != ap2->is_corr
832 || ap1->lr[0] != ap2->lr[0]
833 || ap1->lr[1] != ap2->lr[1])
834 return FALSE;
835
836 if (!PersonIdMatch (ap1->name, ap2->name))
837 {
838 return FALSE;
839 }
840
841 /* compare affil */
842 if (!AffilMatch (ap1->affil, ap2->affil))
843 {
844 return FALSE;
845 }
846 return TRUE;
847 }
848
849 /*****************************************************************************
850 *
851 * CitArtNew()
852 *
853 *****************************************************************************/
854 NLM_EXTERN CitArtPtr LIBCALL CitArtNew (void)
855 {
856 CitArtPtr cap;
857
858 cap = (CitArtPtr)MemNew(sizeof(CitArt));
859 return cap;
860 }
861
862 /*****************************************************************************
863 *
864 * CitArtFree()
865 *
866 *****************************************************************************/
867 NLM_EXTERN CitArtPtr LIBCALL CitArtFree (CitArtPtr cap)
868 {
869 ArticleIdPtr aip, aipnext;
870
871 if (cap == NULL)
872 return cap;
873
874 TitleFree(cap->title);
875 AuthListFree(cap->authors);
876 if (cap->from == 1) /* journal */
877 CitJourFree((CitJourPtr) cap->fromptr);
878 else /* book or proceedings */
879 CitBookFree((CitBookPtr) cap->fromptr);
880
881 for (aip = cap->ids; aip != NULL; )
882 {
883 aipnext = aip->next;
884 ArticleIdFree(aip);
885 aip = aipnext;
886 }
887 return (CitArtPtr)MemFree(cap);
888 }
889
890 /*****************************************************************************
891 *
892 * CitArtAsnRead(aip, atp)
893 *
894 *****************************************************************************/
895 NLM_EXTERN CitArtPtr LIBCALL CitArtAsnRead (AsnIoPtr aip, AsnTypePtr orig)
896 {
897 CitArtPtr cap=NULL;
898 DataVal av;
899 AsnTypePtr atp;
900 ArticleIdPtr aidp;
901 ArticleIdPtr PNTR aidp_add;
902
903 if (! loaded)
904 {
905 if (! BiblioAsnLoad())
906 return cap;
907 }
908
909 if (aip == NULL)
910 return cap;
911
912 if (orig == NULL) /* CitArt ::= */
913 atp = AsnReadId(aip, amp, CIT_ART);
914 else
915 atp = AsnLinkType(orig, CIT_ART);
916 if (atp == NULL)
917 return cap;
918
919 cap = CitArtNew();
920 if (cap == NULL)
921 goto erret;
922
923 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the open SEQUENCE */
924
925 atp = AsnReadId(aip, amp, atp); /* read title id */
926 if (atp == CIT_ART_title)
927 {
928 cap->title = TitleAsnRead(aip, atp); /* read the titles */
929 if (cap->title == NULL)
930 goto erret;
931
932 atp = AsnReadId(aip, amp, atp); /* read the authors id */
933 }
934 if (atp == CIT_ART_authors)
935 {
936 cap->authors = AuthListAsnRead(aip, atp);
937 if (cap->authors == NULL)
938 goto erret;
939
940 atp = AsnReadId(aip, amp, atp); /* read from tag */
941 }
942 if (atp == NULL)
943 goto erret;
944 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* balance from CHOICE */
945
946 atp = AsnReadId(aip, amp, atp); /* read the from CHOICE */
947 if (atp == NULL)
948 goto erret;
949 if (atp == CIT_ART_from_journal)
950 {
951 cap->from = 1;
952 cap->fromptr = (Pointer) CitJourAsnRead(aip, atp);
953 }
954 else if (atp == CIT_ART_from_book)
955 {
956 cap->from = 2;
957 cap->fromptr = (Pointer) CitBookAsnRead(aip, atp);
958 }
959 else
960 {
961 cap->from = 3;
962 cap->fromptr = (Pointer) CitProcAsnRead(aip, atp);
963 }
964
965 if (cap->fromptr == NULL)
966 goto erret;
967
968 atp = AsnReadId(aip, amp, atp);
969 if (atp == NULL)
970 goto erret;
971
972 if (atp == CIT_ART_ids)
973 {
974 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
975 aidp_add = &(cap->ids);
976 while ((atp = AsnReadId(aip, amp, atp)) == ARTICLEIDSET_E)
977 {
978 aidp = ArticleIdAsnRead(aip, atp);
979 if (aidp == NULL) goto erret;
980 *aidp_add = aidp;
981 aidp_add = &(aidp->next);
982 }
983 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* END STRUCT */
984 atp = AsnReadId(aip, amp, atp);
985
986 }
987 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end of SEQUENCE */
988 ret:
989 AsnUnlinkType(orig);
990 return cap;
991 erret:
992 cap = CitArtFree(cap);
993 goto ret;
994 }
995
996 /*****************************************************************************
997 *
998 * CitArtAsnWrite(cap, aip, atp)
999 *
1000 *****************************************************************************/
1001 NLM_EXTERN Boolean LIBCALL CitArtAsnWrite (CitArtPtr cap, AsnIoPtr aip, AsnTypePtr orig)
1002 {
1003 DataVal av;
1004 AsnTypePtr atp;
1005 Boolean retval = FALSE;
1006 ArticleIdPtr aidp;
1007
1008 if (! loaded)
1009 {
1010 if (! BiblioAsnLoad())
1011 return FALSE;
1012 }
1013
1014 if (aip == NULL)
1015 return FALSE;
1016
1017 atp = AsnLinkType(orig, CIT_ART);
1018 if (atp == NULL)
1019 return FALSE;
1020
1021 if (cap == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1022
1023 if (! AsnOpenStruct(aip, atp, (Pointer)cap)) /* open the SEQUENCE */
1024 goto erret;
1025
1026 if (cap->title != NULL)
1027 {
1028 if (! TitleAsnWrite(cap->title, aip, CIT_ART_title)) /* write the title(s) */
1029 goto erret;
1030 }
1031 if (cap->authors != NULL)
1032 {
1033 if (! AuthListAsnWrite(cap->authors, aip, CIT_ART_authors)) /* authors */
1034 goto erret;
1035 }
1036
1037 av.ptrvalue = cap->fromptr;
1038 if (! AsnWriteChoice(aip, CIT_ART_from, (Int2)cap->from, &av)) goto erret;
1039
1040 if (cap->from == 1)
1041 retval = CitJourAsnWrite((CitJourPtr) cap->fromptr, aip, CIT_ART_from_journal);
1042 else if (cap->from == 2)
1043 retval = CitBookAsnWrite((CitBookPtr) cap->fromptr, aip, CIT_ART_from_book);
1044 else
1045 retval = CitProcAsnWrite((CitBookPtr) cap->fromptr, aip, CIT_ART_from_proc);
1046
1047 if (retval == FALSE)
1048 goto erret;
1049 retval = FALSE;
1050
1051 if (cap->ids != NULL)
1052 {
1053 if (! AsnOpenStruct(aip, CIT_ART_ids, (Pointer)cap)) goto erret;
1054 for (aidp = cap->ids; aidp != NULL; aidp = aidp->next)
1055 {
1056 if (! ArticleIdAsnWrite(aidp, aip, ARTICLEIDSET_E)) goto erret;
1057 }
1058 if (! AsnCloseStruct(aip, CIT_ART_ids, (Pointer)cap)) goto erret;
1059 }
1060
1061 if (! AsnCloseStruct(aip, atp, (Pointer)cap)) /* close the SEQUENCE */
1062 goto erret;
1063 retval = TRUE;
1064 erret:
1065 AsnUnlinkType(orig);
1066 return retval;
1067 }
1068
1069 /*****************************************************************************
1070 *
1071 * ImprintNew()
1072 *
1073 *****************************************************************************/
1074 NLM_EXTERN ImprintPtr LIBCALL ImprintNew (void)
1075 {
1076 ImprintPtr ip;
1077
1078 ip = (ImprintPtr)MemNew(sizeof(Imprint));
1079 return ip;
1080 }
1081
1082 /*****************************************************************************
1083 *
1084 * ImprintFree()
1085 *
1086 *****************************************************************************/
1087 NLM_EXTERN ImprintPtr LIBCALL ImprintFree (ImprintPtr ip)
1088 {
1089 PubStatusDatePtr psdp, psdpnext;
1090
1091 if (ip == NULL)
1092 return ip;
1093
1094 DateFree(ip->date);
1095 DateFree(ip->cprt);
1096 MemFree(ip->volume);
1097 MemFree(ip->issue);
1098 MemFree(ip->pages);
1099 MemFree(ip->section);
1100 MemFree(ip->part_sup);
1101 MemFree(ip->language);
1102 MemFree(ip->part_supi);
1103 AffilFree(ip->pub);
1104 CitRetractFree(ip->retract);
1105 for (psdp = ip->history; psdp != NULL; )
1106 {
1107 psdpnext = psdp->next;
1108 PubStatusDateFree(psdp);
1109 psdp = psdpnext;
1110 }
1111 return (ImprintPtr)MemFree(ip);
1112 }
1113
1114 /*****************************************************************************
1115 *
1116 * ImprintAsnRead(aip, atp)
1117 *
1118 *****************************************************************************/
1119 NLM_EXTERN ImprintPtr LIBCALL ImprintAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1120 {
1121 ImprintPtr ip=NULL;
1122 DataVal av;
1123 AsnTypePtr atp, oldatp;
1124 PubStatusDatePtr psdp;
1125 PubStatusDatePtr PNTR psdp_add;
1126
1127 if (! loaded)
1128 {
1129 if (! BiblioAsnLoad())
1130 return ip;
1131 }
1132
1133 if (aip == NULL)
1134 return ip;
1135
1136 if (orig == NULL) /* Imprint ::= */
1137 atp = AsnReadId(aip, amp, IMPRINT);
1138 else
1139 atp = AsnLinkType(orig, IMPRINT);
1140 oldatp = atp;
1141 if (atp == NULL)
1142 return ip;
1143
1144 ip = ImprintNew();
1145 if (ip == NULL)
1146 goto erret;
1147
1148 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the SEQUENCE start */
1149 atp = AsnReadId(aip, amp, atp); /* read the date */
1150 if (atp == NULL)
1151 goto erret;
1152 ip->date = DateAsnRead(aip, atp);
1153 if (ip->date == NULL)
1154 goto erret;
1155
1156 psdp_add = &(ip->history);
1157 while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
1158 {
1159 if (atp == NULL)
1160 goto erret;
1161 if (atp == IMPRINT_pub)
1162 {
1163 ip->pub = AffilAsnRead(aip, atp);
1164 if (ip->pub == NULL)
1165 goto erret;
1166 }
1167 else if (atp == IMPRINT_cprt)
1168 {
1169 ip->cprt = DateAsnRead(aip, atp);
1170 if (ip->cprt == NULL)
1171 goto erret;
1172 }
1173 else if (atp == IMPRINT_retract)
1174 {
1175 ip->retract = CitRetractAsnRead(aip, atp);
1176 if (ip->retract == NULL) goto erret;
1177 }
1178 else if (atp == PUBSTATUSDATESET_E)
1179 {
1180 psdp = PubStatusDateAsnRead(aip, atp);
1181 if (psdp == NULL) goto erret;
1182 *psdp_add = psdp;
1183 psdp_add = &(psdp->next);
1184 }
1185 else
1186 {
1187 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1188 if (atp == IMPRINT_volume)
1189 ip->volume = (CharPtr)av.ptrvalue;
1190 else if (atp == IMPRINT_issue)
1191 ip->issue = (CharPtr)av.ptrvalue;
1192 else if (atp == IMPRINT_pages)
1193 ip->pages = (CharPtr)av.ptrvalue;
1194 else if (atp == IMPRINT_section)
1195 ip->section = (CharPtr)av.ptrvalue;
1196 else if (atp == IMPRINT_part_sup)
1197 ip->part_sup = (CharPtr)av.ptrvalue;
1198 else if (atp == IMPRINT_language)
1199 ip->language = (CharPtr)av.ptrvalue;
1200 else if (atp == IMPRINT_prepub)
1201 ip->prepub = (Uint1)av.intvalue;
1202 else if (atp == IMPRINT_part_supi)
1203 ip->part_supi = (CharPtr)av.ptrvalue;
1204 else if (atp == IMPRINT_pubstatus)
1205 ip->pubstatus = (Uint1)(av.intvalue);
1206
1207 }
1208 }
1209 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end struct */
1210 ret:
1211 AsnUnlinkType(orig);
1212 return ip;
1213 erret:
1214 ip = ImprintFree(ip);
1215 goto ret;
1216 }
1217
1218 /*****************************************************************************
1219 *
1220 * ImprintAsnWrite(ip, aip, atp)
1221 *
1222 *****************************************************************************/
1223 NLM_EXTERN Boolean LIBCALL ImprintAsnWrite (ImprintPtr ip, AsnIoPtr aip, AsnTypePtr orig)
1224 {
1225 DataVal av;
1226 AsnTypePtr atp;
1227 Boolean retval = FALSE;
1228 PubStatusDatePtr psdp;
1229
1230 if (! loaded)
1231 {
1232 if (! BiblioAsnLoad())
1233 return FALSE;
1234 }
1235
1236 if (aip == NULL)
1237 return FALSE;
1238
1239 atp = AsnLinkType(orig, IMPRINT);
1240 if (atp == NULL)
1241 return FALSE;
1242
1243 if (ip == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1244
1245 if (! AsnOpenStruct(aip, atp, (Pointer)ip))
1246 goto erret;
1247 if (! DateAsnWrite(ip->date, aip, IMPRINT_date))
1248 goto erret;
1249 if (ip->volume != NULL)
1250 {
1251 av.ptrvalue = ip->volume;
1252 if (! AsnWrite(aip, IMPRINT_volume, &av)) goto erret;
1253 }
1254 if (ip->issue != NULL)
1255 {
1256 av.ptrvalue = ip->issue;
1257 if (! AsnWrite(aip, IMPRINT_issue, &av)) goto erret;
1258 }
1259 if (ip->pages != NULL)
1260 {
1261 av.ptrvalue = ip->pages;
1262 if (! AsnWrite(aip, IMPRINT_pages, &av)) goto erret;
1263 }
1264 if (ip->section != NULL)
1265 {
1266 av.ptrvalue = ip->section;
1267 if (! AsnWrite(aip, IMPRINT_section, &av)) goto erret;
1268 }
1269 if (ip->pub != NULL)
1270 {
1271 if (! AffilAsnWrite(ip->pub, aip, IMPRINT_pub))
1272 goto erret;
1273 }
1274 if (ip->cprt != NULL)
1275 {
1276 if (! DateAsnWrite(ip->cprt, aip, IMPRINT_cprt))
1277 goto erret;
1278 }
1279 if (ip->part_sup != NULL)
1280 {
1281 av.ptrvalue = ip->part_sup;
1282 if (! AsnWrite(aip, IMPRINT_part_sup, &av)) goto erret;
1283 }
1284 if (ip->language != NULL)
1285 {
1286 av.ptrvalue = ip->language;
1287 if (! AsnWrite(aip, IMPRINT_language, &av)) goto erret;
1288 }
1289 if (ip->prepub != 0)
1290 {
1291 av.intvalue = ip->prepub;
1292 if (! AsnWrite(aip, IMPRINT_prepub, &av)) goto erret;
1293 }
1294 if (ip->part_supi != NULL)
1295 {
1296 av.ptrvalue = ip->part_supi;
1297 if (! AsnWrite(aip, IMPRINT_part_supi, &av)) goto erret;
1298 }
1299 if (ip->retract != NULL)
1300 {
1301 if (! CitRetractAsnWrite(ip->retract, aip, IMPRINT_retract))
1302 goto erret;
1303 }
1304 if (ip->pubstatus)
1305 {
1306 av.intvalue = (Int4)(ip->pubstatus);
1307 if (! AsnWrite(aip, IMPRINT_pubstatus, &av)) goto erret;
1308 }
1309 if (ip->history != NULL)
1310 {
1311 if (! AsnOpenStruct(aip, IMPRINT_history, (Pointer)ip)) goto erret;
1312 for (psdp = ip->history; psdp != NULL; psdp = psdp->next)
1313 {
1314 if (! PubStatusDateAsnWrite(psdp, aip, PUBSTATUSDATESET_E))
1315 goto erret;
1316 }
1317 if (! AsnCloseStruct(aip, IMPRINT_history, (Pointer)ip)) goto erret;
1318 }
1319 if (! AsnCloseStruct(aip, atp, (Pointer)ip))
1320 goto erret;
1321 retval = TRUE;
1322 erret:
1323 AsnUnlinkType(orig);
1324 return retval;
1325 }
1326
1327 /*****************************************************************************
1328 *
1329 * CitRetractNew()
1330 *
1331 *****************************************************************************/
1332 NLM_EXTERN CitRetractPtr LIBCALL CitRetractNew (void)
1333 {
1334 CitRetractPtr crp;
1335
1336 crp = (CitRetractPtr)MemNew(sizeof(CitRetract));
1337 return crp;
1338 }
1339
1340 /*****************************************************************************
1341 *
1342 * CitRetractFree()
1343 *
1344 *****************************************************************************/
1345 NLM_EXTERN CitRetractPtr LIBCALL CitRetractFree (CitRetractPtr crp)
1346 {
1347 if (crp == NULL)
1348 return crp;
1349
1350 MemFree(crp->exp);
1351 return (CitRetractPtr)MemFree(crp);
1352 }
1353
1354 /*****************************************************************************
1355 *
1356 * CitRetractAsnRead(aip, atp)
1357 *
1358 *****************************************************************************/
1359 NLM_EXTERN CitRetractPtr LIBCALL CitRetractAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1360 {
1361 CitRetractPtr crp=NULL;
1362 DataVal av;
1363 AsnTypePtr atp;
1364
1365 if (! loaded)
1366 {
1367 if (! BiblioAsnLoad())
1368 return crp;
1369 }
1370
1371 if (aip == NULL)
1372 return crp;
1373
1374 if (orig == NULL) /* CitRetract ::= */
1375 atp = AsnReadId(aip, amp, CITRETRACT);
1376 else
1377 atp = AsnLinkType(orig, CITRETRACT);
1378 if (atp == NULL)
1379 return crp;
1380
1381 crp = CitRetractNew();
1382 if (crp == NULL)
1383 goto erret;
1384
1385 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the SEQUENCE start */
1386
1387 atp = AsnReadId(aip, amp, atp); /* read the type */
1388 if (atp == NULL)
1389 goto erret;
1390 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1391 crp->type = (Uint1)av.intvalue;
1392
1393 atp = AsnReadId(aip, amp, atp); /* read the exp? */
1394 if (atp == CITRETRACT_exp)
1395 {
1396 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1397 crp->exp = (CharPtr)av.ptrvalue;
1398 atp = AsnReadId(aip, amp, atp); /* read the CLOSE */
1399 }
1400
1401 if (atp == NULL) goto erret;
1402 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end struct */
1403 ret:
1404 AsnUnlinkType(orig);
1405 return crp;
1406 erret:
1407 crp = CitRetractFree(crp);
1408 goto ret;
1409 }
1410
1411 /*****************************************************************************
1412 *
1413 * CitRetractAsnWrite(ip, aip, atp)
1414 *
1415 *****************************************************************************/
1416 NLM_EXTERN Boolean LIBCALL CitRetractAsnWrite (CitRetractPtr crp, AsnIoPtr aip, AsnTypePtr orig)
1417 {
1418 DataVal av;
1419 AsnTypePtr atp;
1420 Boolean retval = FALSE;
1421
1422 if (! loaded)
1423 {
1424 if (! BiblioAsnLoad())
1425 return FALSE;
1426 }
1427
1428 if (aip == NULL)
1429 return FALSE;
1430
1431 atp = AsnLinkType(orig, CITRETRACT);
1432 if (atp == NULL)
1433 return FALSE;
1434
1435 if (crp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1436
1437 if (! AsnOpenStruct(aip, atp, (Pointer)crp))
1438 goto erret;
1439
1440 av.intvalue = (Int4)crp->type;
1441 if (! AsnWrite(aip, CITRETRACT_type, &av)) goto erret;
1442
1443 if (crp->exp != NULL)
1444 {
1445 av.ptrvalue = (Pointer)crp->exp;
1446 if (! AsnWrite(aip, CITRETRACT_exp, &av)) goto erret;
1447 }
1448
1449 if (! AsnCloseStruct(aip, atp, (Pointer)crp))
1450 goto erret;
1451 retval = TRUE;
1452 erret:
1453 AsnUnlinkType(orig);
1454 return retval;
1455 }
1456
1457 /*****************************************************************************
1458 *
1459 * CitJourNew()
1460 *
1461 *****************************************************************************/
1462 NLM_EXTERN CitJourPtr LIBCALL CitJourNew (void)
1463 {
1464 CitJourPtr cjp;
1465
1466 cjp = (CitJourPtr)MemNew(sizeof(CitJour));
1467 return cjp;
1468 }
1469
1470 /*****************************************************************************
1471 *
1472 * CitJourFree()
1473 *
1474 *****************************************************************************/
1475 NLM_EXTERN CitJourPtr LIBCALL CitJourFree (CitJourPtr cjp)
1476 {
1477 if (cjp == NULL)
1478 return cjp;
1479
1480 TitleFree(cjp->title);
1481 ImprintFree(cjp->imp);
1482 return (CitJourPtr)MemFree(cjp);
1483 }
1484
1485 /*****************************************************************************
1486 *
1487 * CitJourAsnRead(aip, atp)
1488 *
1489 *****************************************************************************/
1490 NLM_EXTERN CitJourPtr LIBCALL CitJourAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1491 {
1492 CitJourPtr cjp=NULL;
1493 DataVal av;
1494 AsnTypePtr atp;
1495
1496 if (! loaded)
1497 {
1498 if (! BiblioAsnLoad())
1499 return cjp;
1500 }
1501
1502 if (aip == NULL)
1503 return cjp;
1504
1505 if (orig == NULL) /* CitJour ::= */
1506 atp = AsnReadId(aip, amp, CIT_JOUR);
1507 else
1508 atp = AsnLinkType(orig, CIT_JOUR);
1509 if (atp == NULL)
1510 return cjp;
1511
1512 cjp = CitJourNew();
1513 if (cjp == NULL)
1514 goto erret;
1515
1516 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the open SEQUENCE */
1517 atp = AsnReadId(aip, amp, atp); /* read title id */
1518 if (atp == NULL)
1519 goto erret;
1520 cjp->title = TitleAsnRead(aip, atp);
1521 if (cjp->title == NULL)
1522 goto erret;
1523 atp = AsnReadId(aip, amp, atp); /* read imprint id */
1524 if (atp == NULL)
1525 goto erret;
1526 cjp->imp = ImprintAsnRead(aip, atp);
1527 if (cjp->imp == NULL)
1528 goto erret;
1529 atp = AsnReadId(aip, amp, atp); /* read the close SEQUENCE id */
1530 if (atp == NULL)
1531 goto erret;
1532 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end of SEQUENCE */
1533 ret:
1534 AsnUnlinkType(orig);
1535 return cjp;
1536 erret:
1537 cjp = CitJourFree(cjp);
1538 goto ret;
1539 }
1540
1541 /*****************************************************************************
1542 *
1543 * CitJourAsnWrite(cjp, aip, atp)
1544 *
1545 *****************************************************************************/
1546 NLM_EXTERN Boolean LIBCALL CitJourAsnWrite (CitJourPtr cjp, AsnIoPtr aip, AsnTypePtr orig)
1547 {
1548 AsnTypePtr atp;
1549 Boolean retval = FALSE;
1550
1551 if (! loaded)
1552 {
1553 if (! BiblioAsnLoad())
1554 return FALSE;
1555 }
1556
1557 if (aip == NULL)
1558 return FALSE;
1559
1560 atp = AsnLinkType(orig, CIT_JOUR);
1561 if (atp == NULL)
1562 return FALSE;
1563
1564 if (cjp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1565
1566 if (! AsnOpenStruct(aip, atp, (Pointer)cjp)) /* open the SEQUENCE */
1567 goto erret;
1568 if (! TitleAsnWrite(cjp->title, aip, CIT_JOUR_title))
1569 goto erret;
1570 if (! ImprintAsnWrite(cjp->imp, aip, CIT_JOUR_imp))
1571 goto erret;
1572 if (! AsnCloseStruct(aip, atp, (Pointer)cjp)) /* end SEQUENCE */
1573 goto erret;
1574 retval = TRUE;
1575 erret:
1576 AsnUnlinkType(orig);
1577 return retval;
1578 }
1579
1580 /*****************************************************************************
1581 *
1582 * CitBookNew()
1583 *
1584 *****************************************************************************/
1585 NLM_EXTERN CitBookPtr LIBCALL CitBookNew (void)
1586 {
1587 CitBookPtr cbp;
1588
1589 cbp = (CitBookPtr)MemNew(sizeof(CitBook));
1590 return cbp;
1591 }
1592
1593 /*****************************************************************************
1594 *
1595 * CitBookFree()
1596 *
1597 *****************************************************************************/
1598 NLM_EXTERN CitBookPtr LIBCALL CitBookFree (CitBookPtr cbp)
1599 {
1600 ValNodePtr anp, nextp;
1601
1602 if (cbp == NULL)
1603 return cbp;
1604
1605 TitleFree(cbp->title);
1606 TitleFree(cbp->coll);
1607 AuthListFree(cbp->authors);
1608 ImprintFree(cbp->imp);
1609 if (cbp->othertype == 1) /* Cit-proc */
1610 {
1611 anp = (ValNodePtr)cbp->otherdata;
1612 while (anp != NULL)
1613 {
1614 switch (anp->choice)
1615 {
1616 case 1: /* number ... a CharPtr */
1617 MemFree(anp->data.ptrvalue);
1618 break;
1619 case 2: /* date ... a DatePtr */
1620 DateFree((DatePtr)anp->data.ptrvalue);
1621 break;
1622 case 3: /* place ... an AffilPtr */
1623 AffilFree((AffilPtr)anp->data.ptrvalue);
1624 break;
1625 }
1626 nextp = anp->next;
1627 MemFree(anp);
1628 anp = nextp;
1629 }
1630 }
1631 else if (cbp->othertype == 2) /* Cit-let */
1632 MemFree(cbp->otherdata); /* man-id ... a CharPtr */
1633
1634 return (CitBookPtr)MemFree(cbp);
1635 }
1636
1637 /*****************************************************************************
1638 *
1639 * CitBookAsnRead(aip, atp)
1640 *
1641 *****************************************************************************/
1642 NLM_EXTERN CitBookPtr LIBCALL CitBookAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1643 {
1644 CitBookPtr cbp=NULL;
1645 DataVal av;
1646 AsnTypePtr atp;
1647
1648 if (! loaded)
1649 {
1650 if (! BiblioAsnLoad())
1651 return cbp;
1652 }
1653
1654 if (aip == NULL)
1655 return cbp;
1656
1657 if (orig == NULL) /* CitBook ::= */
1658 atp = AsnReadId(aip, amp, CIT_BOOK);
1659 else
1660 atp = AsnLinkType(orig, CIT_BOOK);
1661 if (atp == NULL)
1662 return cbp;
1663
1664 cbp = CitBookNew();
1665 if (cbp == NULL)
1666 goto erret;
1667
1668 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the open SEQUENCE */
1669 atp = AsnReadId(aip, amp, atp); /* read title id */
1670 if (atp == NULL)
1671 goto erret;
1672 cbp->title = TitleAsnRead(aip, atp);
1673 if (cbp->title == NULL)
1674 goto erret;
1675 atp = AsnReadId(aip, amp, atp); /* read coll or authors id */
1676 if (atp == NULL)
1677 goto erret;
1678 if (atp == CIT_BOOK_coll)
1679 {
1680 cbp->coll = TitleAsnRead(aip, atp);
1681 if (cbp->coll == NULL)
1682 goto erret;
1683 atp = AsnReadId(aip, amp, atp); /* read authors id */
1684 if (atp == NULL)
1685 goto erret;
1686 }
1687 cbp->authors = AuthListAsnRead(aip, atp);
1688 if (cbp->authors == NULL)
1689 goto erret;
1690 atp = AsnReadId(aip, amp, atp); /* read imprint id */
1691 if (atp == NULL)
1692 goto erret;
1693 cbp->imp = ImprintAsnRead(aip, atp);
1694 if (cbp->imp == NULL)
1695 goto erret;
1696
1697 atp = AsnReadId(aip, amp, atp); /* read the close SEQUENCE id */
1698 if (atp == NULL)
1699 goto erret;
1700 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end of SEQUENCE */
1701 ret:
1702 AsnUnlinkType(orig);
1703 return cbp;
1704 erret:
1705 cbp = CitBookFree(cbp);
1706 goto ret;
1707 }
1708
1709 /*****************************************************************************
1710 *
1711 * CitBookAsnWrite(cbp, aip, atp)
1712 *
1713 *****************************************************************************/
1714 NLM_EXTERN Boolean LIBCALL CitBookAsnWrite (CitBookPtr cbp, AsnIoPtr aip, AsnTypePtr orig)
1715 {
1716 AsnTypePtr atp;
1717 Boolean retval = FALSE;
1718
1719 if (! loaded)
1720 {
1721 if (! BiblioAsnLoad())
1722 return FALSE;
1723 }
1724
1725 if (aip == NULL)
1726 return FALSE;
1727
1728 atp = AsnLinkType(orig, CIT_BOOK);
1729 if (atp == NULL)
1730 return FALSE;
1731
1732 if (cbp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1733
1734 if (! AsnOpenStruct(aip, atp, (Pointer)cbp)) /* open the SEQUENCE */
1735 goto erret;
1736 if (! TitleAsnWrite(cbp->title, aip, CIT_BOOK_title))
1737 goto erret;
1738 if (cbp->coll != NULL)
1739 {
1740 if (! TitleAsnWrite(cbp->coll, aip, CIT_BOOK_coll))
1741 goto erret;
1742 }
1743 if (! AuthListAsnWrite(cbp->authors, aip, CIT_BOOK_authors))
1744 goto erret;
1745 if (! ImprintAsnWrite(cbp->imp, aip, CIT_BOOK_imp))
1746 goto erret;
1747 if (! AsnCloseStruct(aip, atp, (Pointer)cbp)) /* end SEQUENCE */
1748 goto erret;
1749 retval = TRUE;
1750 erret:
1751 AsnUnlinkType(orig);
1752 return retval;
1753 }
1754
1755 /*****************************************************************************
1756 *
1757 * CitProcAsnRead(aip, atp)
1758 *
1759 *****************************************************************************/
1760 NLM_EXTERN CitBookPtr LIBCALL CitProcAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1761 {
1762 CitBookPtr cpp=NULL;
1763 DataVal av;
1764 AsnTypePtr atp;
1765 ValNodePtr anp;
1766
1767 if (! loaded)
1768 {
1769 if (! BiblioAsnLoad())
1770 return cpp;
1771 }
1772
1773 if (aip == NULL)
1774 return cpp;
1775
1776 if (orig == NULL) /* CitProc ::= */
1777 atp = AsnReadId(aip, amp, CIT_PROC);
1778 else
1779 atp = AsnLinkType(orig, CIT_PROC);
1780 if (atp == NULL)
1781 return cpp;
1782
1783 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the open SEQUENCE */
1784 atp = AsnReadId(aip, amp, atp); /* read book id */
1785 if (atp == NULL)
1786 goto erret;
1787 cpp = CitBookAsnRead(aip, atp); /* read the book */
1788 if (cpp == NULL)
1789 goto erret;
1790 cpp->othertype = 1; /* mark as a Cit-proc */
1791 atp = AsnReadId(aip, amp, atp); /* read the meet id */
1792 if (atp == NULL)
1793 goto erret;
1794 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* open struct */
1795 atp = AsnReadId(aip, amp, atp); /* number id */
1796 if (atp == NULL)
1797 goto erret;
1798 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1799 anp = ValNodeNew(NULL);
1800 if (anp == NULL)
1801 goto erret;
1802 cpp->otherdata = (Pointer)anp;
1803 anp->choice = 1;
1804 anp->data.ptrvalue = av.ptrvalue;
1805 atp = AsnReadId(aip, amp, atp); /* date id */
1806 if (atp == NULL)
1807 goto erret;
1808 anp = ValNodeNew(anp);
1809 if (anp == NULL)
1810 goto erret;
1811 anp->choice = 2;
1812 anp->data.ptrvalue = (Pointer)DateAsnRead(aip, atp);
1813 if (anp->data.ptrvalue == NULL)
1814 goto erret;
1815 atp = AsnReadId(aip, amp, atp); /* place id */
1816 if (atp == NULL)
1817 goto erret;
1818 anp = ValNodeNew(anp);
1819 if (anp == NULL)
1820 goto erret;
1821 anp->choice = 3;
1822 anp->data.ptrvalue = (Pointer)AffilAsnRead(aip, atp);
1823 if (anp->data.ptrvalue == NULL)
1824 goto erret;
1825 atp = AsnReadId(aip, amp, atp); /* end meet struct */
1826 if (atp == NULL)
1827 goto erret;
1828 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1829
1830 atp = AsnReadId(aip, amp, atp); /* read the close SEQUENCE id */
1831 if (atp == NULL)
1832 goto erret;
1833 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end of SEQUENCE */
1834 ret:
1835 AsnUnlinkType(orig);
1836 return cpp;
1837 erret:
1838 cpp = CitBookFree(cpp);
1839 goto ret;
1840 }
1841
1842 /*****************************************************************************
1843 *
1844 * CitProcAsnWrite(cpp, aip, atp)
1845 *
1846 *****************************************************************************/
1847 NLM_EXTERN Boolean LIBCALL CitProcAsnWrite (CitBookPtr cpp, AsnIoPtr aip, AsnTypePtr orig)
1848 {
1849 DataVal av;
1850 AsnTypePtr atp;
1851 ValNodePtr anp;
1852 Boolean retval = FALSE;
1853
1854 if (! loaded)
1855 {
1856 if (! BiblioAsnLoad())
1857 return FALSE;
1858 }
1859
1860 if (aip == NULL)
1861 return FALSE;
1862
1863 atp = AsnLinkType(orig, CIT_PROC);
1864 if (atp == NULL)
1865 return FALSE;
1866
1867 if (cpp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1868
1869 if (! AsnOpenStruct(aip, atp, (Pointer)cpp)) /* open the SEQUENCE */
1870 goto erret;
1871 if (! CitBookAsnWrite(cpp, aip, CIT_PROC_book)) /* write the book */
1872 goto erret;
1873 if (! AsnOpenStruct(aip, CIT_PROC_meet, (Pointer)cpp->otherdata))
1874 goto erret;
1875 anp = (ValNodePtr)cpp->otherdata;
1876 av.ptrvalue = anp->data.ptrvalue;
1877 if (! AsnWrite(aip, MEETING_number, &av)) goto erret;
1878 anp = anp->next;
1879 if (! DateAsnWrite((DatePtr)anp->data.ptrvalue, aip, MEETING_date))
1880 goto erret;
1881 anp = anp->next;
1882 if (! AffilAsnWrite((AffilPtr)anp->data.ptrvalue, aip, MEETING_place))
1883 goto erret;
1884 if (! AsnCloseStruct(aip, CIT_PROC_meet, (Pointer)cpp->otherdata))
1885 goto erret;
1886 if (! AsnCloseStruct(aip, atp, (Pointer)cpp)) /* end SEQUENCE */
1887 goto erret;
1888 retval = TRUE;
1889 erret:
1890 AsnUnlinkType(orig);
1891 return retval;
1892 }
1893
1894 /*****************************************************************************
1895 *
1896 * CitLetAsnRead(aip, atp)
1897 *
1898 *****************************************************************************/
1899 NLM_EXTERN CitBookPtr LIBCALL CitLetAsnRead (AsnIoPtr aip, AsnTypePtr orig)
1900 {
1901 CitBookPtr clp=NULL;
1902 DataVal av;
1903 AsnTypePtr atp;
1904
1905 if (! loaded)
1906 {
1907 if (! BiblioAsnLoad())
1908 return clp;
1909 }
1910
1911 if (aip == NULL)
1912 return clp;
1913
1914 if (orig == NULL) /* CitLet ::= */
1915 atp = AsnReadId(aip, amp, CIT_LET);
1916 else
1917 atp = AsnLinkType(orig, CIT_LET);
1918 if (atp == NULL)
1919 return clp;
1920
1921 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the open SEQUENCE */
1922 atp = AsnReadId(aip, amp, atp); /* read book id */
1923 if (atp == NULL)
1924 goto erret;
1925 clp = CitBookAsnRead(aip, atp); /* read the book */
1926 if (clp == NULL)
1927 goto erret;
1928 clp->othertype = 2; /* mark as a Cit-let */
1929 atp = AsnReadId(aip, amp, atp); /* read the man-id if present */
1930 if (atp == NULL)
1931 goto erret;
1932 if (atp == CIT_LET_man_id)
1933 {
1934 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1935 clp->otherdata = av.ptrvalue;
1936 atp = AsnReadId(aip, amp, atp); /* end struct */
1937 if (atp == NULL)
1938 goto erret;
1939 }
1940 if (atp == CIT_LET_type) /* read type if present */
1941 {
1942 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1943 clp->let_type = (Uint1) av.intvalue;
1944 atp = AsnReadId(aip, amp, atp);
1945 if (atp == NULL)
1946 goto erret;
1947 }
1948 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end of SEQUENCE */
1949 ret:
1950 AsnUnlinkType(orig);
1951 return clp;
1952 erret:
1953 clp = CitBookFree(clp);
1954 goto ret;
1955 }
1956
1957 /*****************************************************************************
1958 *
1959 * CitLetAsnWrite(clp, aip, atp)
1960 *
1961 *****************************************************************************/
1962 NLM_EXTERN Boolean LIBCALL CitLetAsnWrite (CitBookPtr clp, AsnIoPtr aip, AsnTypePtr orig)
1963 {
1964 DataVal av;
1965 AsnTypePtr atp;
1966 Boolean retval = FALSE;
1967
1968 if (! loaded)
1969 {
1970 if (! BiblioAsnLoad())
1971 return FALSE;
1972 }
1973
1974 if (aip == NULL)
1975 return FALSE;
1976
1977 atp = AsnLinkType(orig, CIT_LET);
1978 if (atp == NULL)
1979 return FALSE;
1980
1981 if (clp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1982
1983 if (! AsnOpenStruct(aip, atp, (Pointer)clp)) /* open the SEQUENCE */
1984 goto erret;
1985 if (! CitBookAsnWrite(clp, aip, CIT_LET_cit)) /* write the book */
1986 goto erret;
1987 if (clp->otherdata != NULL) /* man-id */
1988 {
1989 av.ptrvalue = clp->otherdata;
1990 if (! AsnWrite(aip, CIT_LET_man_id, &av)) goto erret;
1991 }
1992 if (clp->let_type) /* type of Cit-let */
1993 {
1994 av.intvalue = (Int4)clp->let_type;
1995 if (! AsnWrite(aip, CIT_LET_type, &av)) goto erret;
1996 }
1997 if (! AsnCloseStruct(aip, atp, (Pointer)clp)) /* end SEQUENCE */
1998 goto erret;
1999 retval = TRUE;
2000 erret:
2001 AsnUnlinkType(orig);
2002 return retval;
2003 }
2004
2005 /*****************************************************************************
2006 *
2007 * CitPatNew()
2008 *
2009 *****************************************************************************/
2010 NLM_EXTERN CitPatPtr LIBCALL CitPatNew (void)
2011 {
2012 CitPatPtr cpp;
2013
2014 cpp = (CitPatPtr)MemNew(sizeof(CitPat));
2015 return cpp;
2016 }
2017
2018 /*****************************************************************************
2019 *
2020 * CitPatFree()
2021 *
2022 *****************************************************************************/
2023 NLM_EXTERN CitPatPtr LIBCALL CitPatFree (CitPatPtr cpp)
2024 {
2025 if (cpp == NULL)
2026 return cpp;
2027
2028 MemFree(cpp->title);
2029 AuthListFree(cpp->authors);
2030 MemFree(cpp->country);
2031 MemFree(cpp->doc_type);
2032 MemFree(cpp->number);
2033 DateFree(cpp->date_issue);
2034 ValNodeFreeData(cpp->_class);
2035 MemFree(cpp->app_number);
2036 DateFree(cpp->app_date);
2037
2038 AuthListFree(cpp->applicants);
2039 AuthListFree(cpp->assignees);
2040 PatPrioritySetFree(cpp->priority);
2041 MemFree(cpp->abstract);
2042
2043 return (CitPatPtr)MemFree(cpp);
2044 }
2045
2046 /*****************************************************************************
2047 *
2048 * CitPatAsnRead(aip, atp)
2049 *
2050 *****************************************************************************/
2051 NLM_EXTERN CitPatPtr LIBCALL CitPatAsnRead (AsnIoPtr aip, AsnTypePtr orig)
2052 {
2053 CitPatPtr cpp=NULL;
2054 DataVal av;
2055 AsnTypePtr atp, oldatp;
2056 ValNodePtr vnp;
2057
2058 if (! loaded)
2059 {
2060 if (! BiblioAsnLoad())
2061 return cpp;
2062 }
2063
2064 if (aip == NULL)
2065 return cpp;
2066
2067 if (orig == NULL) /* CitPat ::= */
2068 atp = AsnReadId(aip, amp, CIT_PAT);
2069 else
2070 atp = AsnLinkType(orig, CIT_PAT);
2071 oldatp = atp;
2072 if (atp == NULL)
2073 return cpp;
2074
2075 cpp = CitPatNew();
2076 if (cpp == NULL)
2077 goto erret;
2078
2079 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the open SEQUENCE */
2080 atp = AsnReadId(aip, amp, atp); /* read title id */
2081 if (atp == NULL)
2082 goto erret;
2083 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2084 cpp->title = (CharPtr)av.ptrvalue;
2085 atp = AsnReadId(aip, amp, atp); /* read author list id */
2086 if (atp == NULL)
2087 goto erret;
2088 cpp->authors = AuthListAsnRead(aip, atp);
2089 if (cpp->authors == NULL)
2090 goto erret;
2091 atp = AsnReadId(aip, amp, atp ); /* country */
2092 if (atp == NULL)
2093 goto erret;
2094 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2095 cpp->country = (CharPtr)av.ptrvalue;
2096 atp = AsnReadId(aip, amp, atp ); /* doc_type */
2097 if (atp == NULL)
2098 goto erret;
2099 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2100 cpp->doc_type = (CharPtr)av.ptrvalue;
2101
2102 while ((atp = AsnReadId(aip, amp, atp)) != oldatp) /* read options */
2103 {
2104 if (atp == NULL)
2105 goto erret;
2106 if (atp == CIT_PAT_date_issue)
2107 {
2108 cpp->date_issue = DateAsnRead(aip, atp);
2109 if (cpp->date_issue == NULL)
2110 goto erret;
2111 }
2112 else if (atp == CIT_PAT_app_date)
2113 {
2114 cpp->app_date = DateAsnRead(aip, atp);
2115 if (cpp->app_date == NULL)
2116 goto erret;
2117 }
2118 else if (atp == CIT_PAT_applicants)
2119 {
2120 cpp->applicants = AuthListAsnRead(aip, atp);
2121 if (cpp->applicants == NULL)
2122 goto erret;
2123 }
2124 else if (atp == CIT_PAT_assignees)
2125 {
2126 cpp->assignees = AuthListAsnRead(aip, atp);
2127 if (cpp->assignees == NULL)
2128 goto erret;
2129 }
2130 else if (atp == CIT_PAT_priority)
2131 {
2132 cpp->priority = PatPrioritySetAsnRead(aip, atp, CIT_PAT_priority_E);
2133 if (cpp->priority == NULL)
2134 goto erret;
2135 }
2136 else
2137 {
2138 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2139 if (atp == CIT_PAT_number)
2140 {
2141 cpp->number = (CharPtr)av.ptrvalue;
2142 }
2143 if (atp == CIT_PAT_class)
2144 {
2145 while ((atp = AsnReadId(aip, amp, atp)) != CIT_PAT_class)
2146 {
2147 if (atp == NULL) goto erret;
2148 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2149 vnp = ValNodeNew(cpp->_class);
2150 if (vnp == NULL) goto erret;
2151 if (cpp->_class == NULL)
2152 cpp->_class = vnp;
2153 vnp->data.ptrvalue = (CharPtr)av.ptrvalue;
2154 }
2155 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2156 }
2157 else if (atp == CIT_PAT_app_number)
2158 cpp->app_number = (CharPtr)av.ptrvalue;
2159 else if (atp == CIT_PAT_abstract)
2160 cpp->abstract = (CharPtr)av.ptrvalue;
2161 }
2162 }
2163 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end of SEQUENCE */
2164 ret:
2165 AsnUnlinkType(orig);
2166 return cpp;
2167 erret:
2168 cpp = CitPatFree(cpp);
2169 goto ret;
2170 }
2171
2172 /*****************************************************************************
2173 *
2174 * CitPatAsnWrite(cpp, aip, atp)
2175 *
2176 *****************************************************************************/
2177 NLM_EXTERN Boolean LIBCALL CitPatAsnWrite (CitPatPtr cpp, AsnIoPtr aip, AsnTypePtr orig)
2178 {
2179 DataVal av;
2180 AsnTypePtr atp;
2181 Boolean retval = FALSE;
2182 ValNodePtr vnp;
2183
2184 if (! loaded)
2185 {
2186 if (! BiblioAsnLoad())
2187 return FALSE;
2188 }
2189
2190 if (aip == NULL)
2191 return FALSE;
2192
2193 atp = AsnLinkType(orig, CIT_PAT);
2194 if (atp == NULL)
2195 return FALSE;
2196
2197 if (cpp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2198
2199 if (! AsnOpenStruct(aip, atp, (Pointer)cpp)) /* open the SEQUENCE */
2200 goto erret;
2201 av.ptrvalue = cpp->title;
2202 if (! AsnWrite(aip, CIT_PAT_title, &av)) goto erret;
2203 if (! AuthListAsnWrite(cpp->authors, aip, CIT_PAT_authors))
2204 goto erret;
2205 av.ptrvalue = cpp->country;
2206 if (! AsnWrite(aip, CIT_PAT_country, &av)) goto erret;
2207 av.ptrvalue = cpp->doc_type;
2208 if (! AsnWrite(aip, CIT_PAT_doc_type, &av)) goto erret;
2209 if (cpp->number != NULL)
2210 {
2211 av.ptrvalue = cpp->number;
2212 if (! AsnWrite(aip, CIT_PAT_number, &av)) goto erret;
2213 }
2214 if (cpp->date_issue != NULL)
2215 {
2216 if (! DateAsnWrite(cpp->date_issue, aip, CIT_PAT_date_issue))
2217 goto erret;
2218 }
2219 if (cpp->_class != NULL)
2220 {
2221 if (! AsnOpenStruct(aip, CIT_PAT_class, (Pointer)(cpp->_class)))
2222 goto erret;
2223 for (vnp = cpp->_class; vnp != NULL; vnp = vnp->next)
2224 {
2225 av.ptrvalue = vnp->data.ptrvalue;
2226 if (! AsnWrite(aip, CIT_PAT_class_E, &av)) goto erret;
2227 }
2228 if (! AsnCloseStruct(aip, CIT_PAT_class, (Pointer)(cpp->_class)))
2229 goto erret;
2230 }
2231 if (cpp->app_number != NULL)
2232 {
2233 av.ptrvalue = cpp->app_number;
2234 if (! AsnWrite(aip, CIT_PAT_app_number, &av)) goto erret;
2235 }
2236 if (cpp->app_date != NULL)
2237 {
2238 if (! DateAsnWrite(cpp->app_date, aip, CIT_PAT_app_date))
2239 goto erret;
2240 }
2241
2242 if (cpp->applicants != NULL)
2243 {
2244 if (! AuthListAsnWrite(cpp->applicants, aip, CIT_PAT_applicants))
2245 goto erret;
2246 }
2247 if (cpp->assignees != NULL)
2248 {
2249 if (! AuthListAsnWrite(cpp->assignees, aip, CIT_PAT_assignees))
2250 goto erret;
2251 }
2252 if (cpp->priority != NULL)
2253 {
2254 if (! PatPrioritySetAsnWrite(cpp->priority, aip, CIT_PAT_priority, CIT_PAT_priority_E))
2255 goto erret;
2256 }
2257 if (cpp->abstract != NULL)
2258 {
2259 av.ptrvalue = cpp->abstract;
2260 if (! AsnWrite(aip, CIT_PAT_abstract, &av)) goto erret;
2261 }
2262
2263 if (! AsnCloseStruct(aip, atp, (Pointer)cpp)) /* end SEQUENCE */
2264 goto erret;
2265 retval = TRUE;
2266 erret:
2267 AsnUnlinkType(orig);
2268 return retval;
2269 }
2270
2271 /*****************************************************************************
2272 *
2273 * IdPatNew()
2274 *
2275 *****************************************************************************/
2276 NLM_EXTERN IdPatPtr LIBCALL IdPatNew (void)
2277 {
2278 IdPatPtr idp;
2279
2280 idp = (IdPatPtr)MemNew(sizeof(IdPat));
2281 return idp;
2282 }
2283
2284 /*****************************************************************************
2285 *
2286 * IdPatFree()
2287 *
2288 *****************************************************************************/
2289 NLM_EXTERN IdPatPtr LIBCALL IdPatFree (IdPatPtr idp)
2290 {
2291 if (idp == NULL)
2292 return idp;
2293
2294 MemFree(idp->country);
2295 MemFree(idp->number);
2296 MemFree(idp->app_number);
2297 MemFree(idp->doc_type);
2298 return (IdPatPtr)MemFree(idp);
2299 }
2300
2301 /*****************************************************************************
2302 *
2303 * IdPatAsnRead(aip, atp)
2304 *
2305 *****************************************************************************/
2306 NLM_EXTERN IdPatPtr LIBCALL IdPatAsnRead (AsnIoPtr aip, AsnTypePtr orig)
2307 {
2308 IdPatPtr idp=NULL;
2309 DataVal av;
2310 AsnTypePtr atp;
2311
2312 if (! loaded)
2313 {
2314 if (! BiblioAsnLoad())
2315 return idp;
2316 }
2317
2318 if (aip == NULL)
2319 return idp;
2320
2321 if (orig == NULL) /* IdPat ::= */
2322 atp = AsnReadId(aip, amp, ID_PAT);
2323 else
2324 atp = AsnLinkType(orig, ID_PAT);
2325 if (atp == NULL)
2326 return idp;
2327
2328 idp = IdPatNew();
2329 if (idp == NULL)
2330 goto erret;
2331
2332 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the open SEQUENCE */
2333 atp = AsnReadId(aip, amp, atp ); /* country */
2334 if (atp == NULL)
2335 goto erret;
2336 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2337 idp->country = (CharPtr)av.ptrvalue;
2338 atp = AsnReadId(aip, amp, atp ); /* CHOICE */
2339 if (atp == NULL)
2340 goto erret;
2341 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2342 atp = AsnReadId(aip, amp, atp ); /* number or app_number */
2343 if (atp == NULL)
2344 goto erret;
2345 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2346 if (atp == ID_PAT_id_number)
2347 idp->number = (CharPtr)av.ptrvalue;
2348 else
2349 idp->app_number = (CharPtr)av.ptrvalue;
2350 atp = AsnReadId(aip, amp, atp); /* end or doc-type */
2351 if (atp == NULL)
2352 goto erret;
2353 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2354 if (atp == ID_PAT_doc_type)
2355 {
2356 idp->doc_type = av.ptrvalue;
2357 atp = AsnReadId(aip, amp, atp);
2358 if (atp == NULL) goto erret;
2359 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end of SEQUENCE */
2360 }
2361 ret:
2362 AsnUnlinkType(orig);
2363 return idp;
2364 erret:
2365 idp = IdPatFree(idp);
2366 goto ret;
2367 }
2368
2369 /*****************************************************************************
2370 *
2371 * IdPatAsnWrite(idp, aip, atp)
2372 *
2373 *****************************************************************************/
2374 NLM_EXTERN Boolean LIBCALL IdPatAsnWrite (IdPatPtr idp, AsnIoPtr aip, AsnTypePtr orig)
2375 {
2376 DataVal av;
2377 AsnTypePtr atp, numtype;
2378 Int2 choicenum;
2379 Boolean retval = FALSE;
2380
2381 if (! loaded)
2382 {
2383 if (! BiblioAsnLoad())
2384 return FALSE;
2385 }
2386
2387 if (aip == NULL)
2388 return FALSE;
2389
2390 atp = AsnLinkType(orig, ID_PAT);
2391 if (atp == NULL)
2392 return FALSE;
2393
2394 if (idp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2395
2396 if (! AsnOpenStruct(aip, atp, (Pointer)idp)) /* open the SEQUENCE */
2397 goto erret;
2398 av.ptrvalue = idp->country;
2399 if (! AsnWrite(aip, ID_PAT_country, &av)) goto erret;
2400 if (idp->number != NULL)
2401 {
2402 choicenum = 0; /* number */
2403 av.ptrvalue = idp->number;
2404 numtype = ID_PAT_id_number;
2405 }
2406 else
2407 {
2408 choicenum = 1; /* app_number */
2409 av.ptrvalue = idp->app_number;
2410 numtype = ID_PAT_id_app_number;
2411 }
2412
2413 if (! AsnWriteChoice(aip, ID_PAT_id, choicenum, &av)) goto erret;
2414 if (! AsnWrite(aip, numtype, &av)) goto erret;
2415
2416 if (idp->doc_type != NULL)
2417 {
2418 av.ptrvalue = idp->doc_type;
2419 if (! AsnWrite(aip, ID_PAT_doc_type, &av)) goto erret;
2420 }
2421
2422 if (! AsnCloseStruct(aip, atp, (Pointer)idp)) /* end SEQUENCE */
2423 goto erret;
2424 retval = TRUE;
2425 erret:
2426 AsnUnlinkType(orig);
2427 return retval;
2428 }
2429
2430 /*****************************************************************************
2431 *
2432 * Boolean IdPatMatch(a,b)
2433 *
2434 *****************************************************************************/
2435 NLM_EXTERN Boolean LIBCALL IdPatMatch (IdPatPtr a, IdPatPtr b)
2436 {
2437 if ((a == NULL) || (b == NULL))
2438 return FALSE;
2439
2440 if (StringICmp(a->country, b->country)) /* countries must match */
2441 return FALSE;
2442
2443 if ((a->number != NULL) && (b->number != NULL))
2444 {
2445 if (! StringICmp(a->number, b->number))
2446 return TRUE;
2447 else
2448 return FALSE;
2449 }
2450 else
2451 {
2452 if (! StringICmp(a->app_number, b->app_number))
2453 return TRUE;
2454 else
2455 return FALSE;
2456 }
2457 }
2458
2459 /*****************************************************************************
2460 *
2461 * CitGenNew()
2462 *
2463 *****************************************************************************/
2464 NLM_EXTERN CitGenPtr LIBCALL CitGenNew (void)
2465 {
2466 CitGenPtr cgp;
2467
2468 cgp = (CitGenPtr)MemNew(sizeof(CitGen));
2469 if (cgp == NULL) return cgp;
2470 cgp->muid = -1;
2471 cgp->pmid = -1;
2472 cgp->serial_number = -1; /* not set */
2473 return cgp;
2474 }
2475
2476 /*****************************************************************************
2477 *
2478 * CitGenFree()
2479 *
2480 *****************************************************************************/
2481 NLM_EXTERN CitGenPtr LIBCALL CitGenFree (CitGenPtr cgp)
2482 {
2483 if (cgp == NULL)
2484 return cgp;
2485
2486 MemFree(cgp->cit);
2487 AuthListFree(cgp->authors);
2488 TitleFree(cgp->journal);
2489 MemFree(cgp->volume);
2490 MemFree(cgp->issue);
2491 MemFree(cgp->pages);
2492 DateFree(cgp->date);
2493 MemFree(cgp->title);
2494
2495 return (CitGenPtr)MemFree(cgp);
2496 }
2497
2498 /*****************************************************************************
2499 *
2500 * CitGenAsnRead(aip, atp)
2501 *
2502 *****************************************************************************/
2503 NLM_EXTERN CitGenPtr LIBCALL CitGenAsnRead (AsnIoPtr aip, AsnTypePtr orig)
2504 {
2505 CitGenPtr cgp=NULL;
2506 DataVal av;
2507 AsnTypePtr atp, oldatp;
2508
2509 if (! loaded)
2510 {
2511 if (! BiblioAsnLoad())
2512 return cgp;
2513 }
2514
2515 if (aip == NULL)
2516 return cgp;
2517
2518 if (orig == NULL) /* CitGen ::= */
2519 atp = AsnReadId(aip, amp, CIT_GEN);
2520 else
2521 atp = AsnLinkType(orig, CIT_GEN);
2522 oldatp = atp;
2523 if (atp == NULL)
2524 return cgp;
2525
2526 cgp = CitGenNew();
2527 if (cgp == NULL)
2528 goto erret;
2529
2530 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the open SEQUENCE */
2531 while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
2532 {
2533 if (atp == NULL)
2534 goto erret;
2535 if (atp == CIT_GEN_authors)
2536 {
2537 cgp->authors = AuthListAsnRead(aip, atp);
2538 if (cgp->authors == NULL)
2539 goto erret;
2540 }
2541 else if (atp == CIT_GEN_journal)
2542 {
2543 cgp->journal = TitleAsnRead(aip, atp);
2544 if (cgp->journal == NULL)
2545 goto erret;
2546 }
2547 else if (atp == CIT_GEN_date)
2548 {
2549 cgp->date = DateAsnRead(aip, atp);
2550 if (cgp->date == NULL)
2551 goto erret;
2552 }
2553 else
2554 {
2555 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2556 if (atp == CIT_GEN_cit)
2557 cgp->cit = (CharPtr)av.ptrvalue;
2558 else if (atp == CIT_GEN_volume)
2559 cgp->volume = (CharPtr)av.ptrvalue;
2560 else if (atp == CIT_GEN_issue)
2561 cgp->issue = (CharPtr)av.ptrvalue;
2562 else if (atp == CIT_GEN_pages)
2563 cgp->pages = (CharPtr)av.ptrvalue;
2564 else if (atp == CIT_GEN_serial_number)
2565 cgp->serial_number = (Int2) av.intvalue;
2566 else if (atp == CIT_GEN_title)
2567 cgp->title = (CharPtr)av.ptrvalue;
2568 else if (atp == CIT_GEN_muid)
2569 cgp->muid = av.intvalue;
2570 else if (atp == CIT_GEN_pmid)
2571 cgp->pmid = av.intvalue;
2572 }
2573 }
2574 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end of SEQUENCE */
2575 ret:
2576 AsnUnlinkType(orig);
2577 return cgp;
2578 erret:
2579 cgp = CitGenFree(cgp);
2580 goto ret;
2581 }
2582
2583 /*****************************************************************************
2584 *
2585 * CitGenAsnWrite(cgp, aip, atp)
2586 *
2587 *****************************************************************************/
2588 NLM_EXTERN Boolean LIBCALL CitGenAsnWrite (CitGenPtr cgp, AsnIoPtr aip, AsnTypePtr orig)
2589 {
2590 DataVal av;
2591 AsnTypePtr atp;
2592 Boolean retval = FALSE;
2593
2594 if (! loaded)
2595 {
2596 if (! BiblioAsnLoad())
2597 return FALSE;
2598 }
2599
2600 if (aip == NULL)
2601 return FALSE;
2602
2603 atp = AsnLinkType(orig, CIT_GEN);
2604 if (atp == NULL)
2605 return FALSE;
2606
2607 if (cgp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2608
2609 if (! AsnOpenStruct(aip, atp, (Pointer)cgp)) /* open the SEQUENCE */
2610 goto erret;
2611 if (cgp->cit != NULL)
2612 {
2613 av.ptrvalue = cgp->cit;
2614 if (! AsnWrite(aip, CIT_GEN_cit, &av)) goto erret;
2615 }
2616 if (cgp->authors != NULL)
2617 {
2618 if (! AuthListAsnWrite(cgp->authors, aip, CIT_GEN_authors))
2619 goto erret;
2620 }
2621 if (cgp->muid >= 0)
2622 {
2623 av.intvalue = cgp->muid;
2624 if (! AsnWrite(aip, CIT_GEN_muid, &av)) goto erret;
2625 }
2626 if (cgp->journal != NULL)
2627 {
2628 if (! TitleAsnWrite(cgp->journal, aip, CIT_GEN_journal))
2629 goto erret;
2630 }
2631 if (cgp->volume != NULL)
2632 {
2633 av.ptrvalue = cgp->volume;
2634 if (! AsnWrite(aip, CIT_GEN_volume, &av)) goto erret;
2635 }
2636 if (cgp->issue != NULL)
2637 {
2638 av.ptrvalue = cgp->issue;
2639 if (! AsnWrite(aip, CIT_GEN_issue, &av)) goto erret;
2640 }
2641 if (cgp->pages != NULL)
2642 {
2643 av.ptrvalue = cgp->pages;
2644 if (! AsnWrite(aip, CIT_GEN_pages, &av)) goto erret;
2645 }
2646 if (cgp->date != NULL)
2647 {
2648 if (! DateAsnWrite(cgp->date, aip, CIT_GEN_date))
2649 goto erret;
2650 }
2651 if (cgp->serial_number >= 0)
2652 {
2653 av.intvalue = (Int4)cgp->serial_number;
2654 if (! AsnWrite(aip, CIT_GEN_serial_number, &av)) goto erret;
2655 }
2656 if (cgp->title != NULL)
2657 {
2658 av.ptrvalue = cgp->title;
2659 if (! AsnWrite(aip, CIT_GEN_title, &av)) goto erret;
2660 }
2661 if (cgp->pmid > 0)
2662 {
2663 if (aip->spec_version > 0 && aip->spec_version < 5) /* ASN4 strip new value */
2664 {
2665 ErrPostEx(SEV_ERROR,0,0,"ASN4: PubMedId stripped");
2666 }
2667 else
2668 {
2669 av.intvalue = cgp->pmid;
2670 if (! AsnWrite(aip, CIT_GEN_pmid, &av)) goto erret;
2671 }
2672 }
2673 if (! AsnCloseStruct(aip, atp, (Pointer)cgp)) /* end SEQUENCE */
2674 goto erret;
2675 retval = TRUE;
2676 erret:
2677 AsnUnlinkType(orig);
2678 return retval;
2679 }
2680
2681 /*****************************************************************************
2682 *
2683 * TitleFree()
2684 *
2685 *****************************************************************************/
2686 NLM_EXTERN ValNodePtr LIBCALL TitleFree (ValNodePtr tp)
2687 {
2688 ValNodePtr next;
2689
2690 if (tp == NULL)
2691 return tp;
2692
2693 while (tp != NULL)
2694 {
2695 MemFree(tp->data.ptrvalue);
2696 next = tp->next;
2697 MemFree(tp);
2698 tp = next;
2699 }
2700
2701 return tp;
2702 }
2703
2704 /*****************************************************************************
2705 *
2706 * TitleAsnRead(aip, atp)
2707 *
2708 *****************************************************************************/
2709 NLM_EXTERN ValNodePtr LIBCALL TitleAsnRead (AsnIoPtr aip, AsnTypePtr orig)
2710 {
2711 ValNodePtr first=NULL, tp;
2712 DataVal av;
2713 AsnTypePtr atp, oldatp;
2714
2715 if (! loaded)
2716 {
2717 if (! BiblioAsnLoad())
2718 return first;
2719 }
2720
2721 if (aip == NULL)
2722 return NULL;
2723
2724 if (orig == NULL) /* Title ::= */
2725 atp = AsnReadId(aip, amp, TITLE);
2726 else
2727 atp = AsnLinkType(orig, TITLE);
2728 oldatp = atp;
2729 if (atp == NULL)
2730 return first;
2731
2732 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the open SET OF */
2733 while ((atp = AsnReadId(aip, amp, atp)) != oldatp)
2734 {
2735 if (atp == NULL)
2736 goto erret;
2737 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the CHOICE */
2738 atp = AsnReadId(aip, amp, atp); /* type of CHOICE */
2739 if (atp == NULL)
2740 goto erret;
2741 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2742 tp = ValNodeNew(first);
2743 if (tp == NULL)
2744 goto erret;
2745 tp->data.ptrvalue = av.ptrvalue;
2746 if (first == NULL)
2747 first = tp;
2748 if (atp == TITLE_E_name)
2749 tp->choice = 1;
2750 else if (atp == TITLE_E_tsub)
2751 tp->choice = 2;
2752 else if (atp == TITLE_E_trans)
2753 tp->choice = 3;
2754 else if (atp == TITLE_E_jta)
2755 tp->choice = 4;
2756 else if (atp == TITLE_E_iso_jta)
2757 tp->choice = 5;
2758 else if (atp == TITLE_E_ml_jta)
2759 tp->choice = 6;
2760 else if (atp == TITLE_E_coden)
2761 tp->choice = 7;
2762 else if (atp == TITLE_E_issn)
2763 tp->choice = 8;
2764 else if (atp == TITLE_E_abr)
2765 tp->choice = 9;
2766 else if (atp == TITLE_E_isbn)
2767 tp->choice = 10;
2768 }
2769 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end of SET OF */
2770 ret:
2771 AsnUnlinkType(orig);
2772 return first;
2773 erret:
2774 first = TitleFree(first);
2775 goto ret;
2776 }
2777
2778 /*****************************************************************************
2779 *
2780 * TitleAsnWrite(tp, aip, atp)
2781 *
2782 *****************************************************************************/
2783 NLM_EXTERN Boolean LIBCALL TitleAsnWrite (ValNodePtr tp, AsnIoPtr aip, AsnTypePtr orig)
2784 {
2785 DataVal av;
2786 AsnTypePtr atp, atp2;
2787 ValNodePtr oldtp;
2788 Boolean retval = FALSE;
2789
2790 if (! loaded)
2791 {
2792 if (! BiblioAsnLoad())
2793 return FALSE;
2794 }
2795
2796 if (aip == NULL)
2797 return FALSE;
2798
2799 atp = AsnLinkType(orig, TITLE);
2800 if (atp == NULL)
2801 return FALSE;
2802
2803 if (tp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
2804
2805 oldtp = tp;
2806 if (! AsnOpenStruct(aip, atp, (Pointer)oldtp)) /* open the SET OF */
2807 goto erret;
2808 while (tp != NULL)
2809 {
2810 av.ptrvalue = tp->data.ptrvalue;
2811 switch (tp->choice)
2812 {
2813 case Cit_title_name:
2814 atp2 = TITLE_E_name;
2815 break;
2816 case Cit_title_tsub:
2817 atp2 = TITLE_E_tsub;
2818 break;
2819 case Cit_title_trans:
2820 atp2 = TITLE_E_trans;
2821 break;
2822 case Cit_title_jta:
2823 atp2 = TITLE_E_jta;
2824 break;
2825 case Cit_title_iso_jta:
2826 atp2 = TITLE_E_iso_jta;
2827 break;
2828 case Cit_title_ml_jta:
2829 atp2 = TITLE_E_ml_jta;
2830 break;
2831 case Cit_title_coden:
2832 atp2 = TITLE_E_coden;
2833 break;
2834 case Cit_title_issn:
2835 atp2 = TITLE_E_issn;
2836 break;
2837 case Cit_title_abr:
2838 atp2 = TITLE_E_abr;
2839 break;
2840 case Cit_title_isbn:
2841 atp2 = TITLE_E_isbn;
2842 break;
2843 default:
2844 atp2 = NULL;
2845 break;
2846 }
2847 if (atp2 != NULL)
2848 {
2849 if (! AsnWriteChoice(aip, TITLE_E, (Int2)tp->choice, &av)) goto erret;
2850 if (! AsnWrite(aip, atp2, &av)) goto erret;
2851 }
2852 tp = tp->next;
2853 }
2854 if (! AsnCloseStruct(aip, atp, (Pointer)oldtp)) /* end SET OF */
2855 goto erret;
2856 retval = TRUE;
2857 erret:
2858 AsnUnlinkType(orig);
2859 return retval;
2860 }
2861
2862 /*****************************************************************************
2863 *
2864 * CitSubNew()
2865 *
2866 *****************************************************************************/
2867 NLM_EXTERN CitSubPtr LIBCALL CitSubNew (void)
2868 {
2869 CitSubPtr csp;
2870
2871 csp = (CitSubPtr)MemNew(sizeof(CitSub));
2872 return csp;
2873 }
2874
2875 /*****************************************************************************
2876 *
2877 * CitSubFree()
2878 *
2879 *****************************************************************************/
2880 NLM_EXTERN CitSubPtr LIBCALL CitSubFree (CitSubPtr csp)
2881 {
2882 if (csp == NULL)
2883 return csp;
2884
2885 AuthListFree(csp->authors);
2886 ImprintFree(csp->imp);
2887 DateFree(csp->date);
2888 MemFree(csp->descr);
2889 return (CitSubPtr)MemFree(csp);
2890 }
2891
2892 /*****************************************************************************
2893 *
2894 * CitSubAsnRead(aip, atp)
2895 *
2896 *****************************************************************************/
2897 NLM_EXTERN CitSubPtr LIBCALL CitSubAsnRead (AsnIoPtr aip, AsnTypePtr orig)
2898 {
2899 CitSubPtr csp=NULL;
2900 DataVal av;
2901 AsnTypePtr atp;
2902
2903 if (! loaded)
2904 {
2905 if (! BiblioAsnLoad())
2906 return csp;
2907 }
2908
2909 if (aip == NULL)
2910 return csp;
2911
2912 if (orig == NULL) /* CitSub ::= */
2913 atp = AsnReadId(aip, amp, CIT_SUB);
2914 else
2915 atp = AsnLinkType(orig, CIT_SUB);
2916 if (atp == NULL)
2917 return csp;
2918
2919 csp = CitSubNew();
2920 if (csp == NULL)
2921 goto erret;
2922
2923 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the open SEQUENCE */
2924 atp = AsnReadId(aip, amp, atp); /* read authors id */
2925 if (atp == NULL)
2926 goto erret;
2927 csp->authors = AuthListAsnRead(aip, atp);
2928 if (csp->authors == NULL)
2929 goto erret;
2930 atp = AsnReadId(aip, amp, atp); /* read imprint id */
2931 if (atp == NULL)
2932 goto erret;
2933
2934 if (atp == CIT_SUB_imp)
2935 {
2936 csp->imp = ImprintAsnRead(aip, atp);
2937 if (csp->imp == NULL)
2938 goto erret;
2939
2940 atp = AsnReadId(aip, amp, atp);
2941 if (atp == NULL)
2942 goto erret;
2943 }
2944
2945 if (atp == CIT_SUB_medium) /* nope, got medium */
2946 {
2947 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2948 csp->medium = (Uint1) av.intvalue;
2949 atp = AsnReadId(aip, amp, atp);
2950 if (atp == NULL)
2951 goto erret;
2952 }
2953
2954 if (atp == CIT_SUB_date) /* nope, got date */
2955 {
2956 csp->date = DateAsnRead(aip, atp);
2957 if (csp->date == NULL) goto erret;
2958 atp = AsnReadId(aip, amp, atp);
2959 if (atp == NULL)
2960 goto erret;
2961 }
2962
2963 if (atp == CIT_SUB_descr) /* nope, got descr */
2964 {
2965 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
2966 csp->descr = (CharPtr) av.ptrvalue;
2967 atp = AsnReadId(aip, amp, atp);
2968 if (atp == NULL)
2969 goto erret;
2970 }
2971
2972 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end of SEQUENCE */
2973 ret:
2974 AsnUnlinkType(orig);
2975 return csp;
2976 erret:
2977 csp = CitSubFree(csp);
2978 goto ret;
2979 }
2980
2981 /*****************************************************************************
2982 *
2983 * CitSubAsnWrite(csp, aip, atp)
2984 *
2985 *****************************************************************************/
2986 NLM_EXTERN Boolean LIBCALL CitSubAsnWrite (CitSubPtr csp, AsnIoPtr aip, AsnTypePtr orig)
2987 {
2988 AsnTypePtr atp;
2989 DataVal av;
2990 Boolean retval = FALSE;
2991
2992 if (! loaded)
2993 {
2994 if (! BiblioAsnLoad())
2995 return FALSE;
2996 }
2997
2998 if (aip == NULL)
2999 return FALSE;
3000
3001 atp = AsnLinkType(orig, CIT_SUB);
3002 if (atp == NULL)
3003 return FALSE;
3004
3005 if (csp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
3006
3007 if (! AsnOpenStruct(aip, atp, (Pointer)csp)) /* open the SEQUENCE */
3008 goto erret;
3009 if (! AuthListAsnWrite(csp->authors, aip, CIT_SUB_authors))
3010 goto erret;
3011
3012 if (csp->imp != NULL)
3013 {
3014 if (! ImprintAsnWrite(csp->imp, aip, CIT_SUB_imp))
3015 goto erret;
3016 }
3017
3018 if (csp->medium)
3019 {
3020 av.intvalue = (Int4)csp->medium;
3021 if (! AsnWrite(aip, CIT_SUB_medium, &av)) goto erret;
3022 }
3023
3024 if (csp->date != NULL)
3025 {
3026 if (! DateAsnWrite(csp->date, aip, CIT_SUB_date)) goto erret;
3027 }
3028
3029 if (csp->descr != NULL)
3030 {
3031 av.ptrvalue = (Pointer)csp->descr;
3032 if (! AsnWrite(aip, CIT_SUB_descr, &av)) goto erret;
3033 }
3034
3035 if (! AsnCloseStruct(aip, atp, (Pointer)csp)) /* end SEQUENCE */
3036 goto erret;
3037 retval = TRUE;
3038 erret:
3039 AsnUnlinkType(orig);
3040 return retval;
3041 }
3042
3043 /*****************************************************************************
3044 *
3045 * Int2 CitArtMatch(a, b)
3046 * returns 0 = same article
3047 * 1,-1 = different article
3048 *
3049 *****************************************************************************/
3050 NLM_EXTERN Int2 LIBCALL CitArtMatch(CitArtPtr a, CitArtPtr b)
3051 {
3052 Int2 retval = 1;
3053
3054
3055 if (a == NULL)
3056 return (Int2) -1;
3057 else if (b == NULL)
3058 return retval;
3059
3060 if (a->from != b->from) /* different types */
3061 {
3062 if (a->from < b->from)
3063 return (Int2) -1;
3064 else
3065 return retval;
3066 }
3067
3068
3069 if (a->from == 1) /* journal article */
3070 retval = CitJourMatch((CitJourPtr)a->fromptr, (CitJourPtr)b->fromptr);
3071 else /* book or proceedings */
3072 retval = CitBookMatch((CitBookPtr)a->fromptr, (CitBookPtr)b->fromptr);
3073
3074
3075
3076 if (retval) /* different sources */
3077 return retval;
3078
3079
3080 /* check all authors */
3081 retval = AuthListMatch(a->authors, b->authors, TRUE);
3082
3083
3084 if (retval)
3085 return retval;
3086
3087
3088
3089 retval = TitleMatch(a->title, b->title, Cit_title_name);
3090 if ((retval > 1) || (retval < -1)) /* not same type or NULL */
3091 retval = 0; /* matched everything else ok */
3092
3093
3094
3095 return retval;
3096 }
3097
3098 /*****************************************************************************
3099 *
3100 * Int2 CitBookMatch(a, b)
3101 * returns 0 = same book
3102 * 1,-1 = different book
3103 * Also does Cit-proc and Cit-let
3104 *
3105 *****************************************************************************/
3106 NLM_EXTERN Int2 LIBCALL CitBookMatch (CitBookPtr a, CitBookPtr b)
3107 {
3108 Int2 retval = 1;
3109
3110
3111
3112 if (a == NULL)
3113 return (Int2) -1;
3114 else if (b == NULL)
3115 return retval;
3116
3117 if (a->othertype > b->othertype)
3118 return (Int2)1;
3119 else if (a->othertype < b->othertype)
3120 return (Int2)-1;
3121
3122 retval = AuthListMatch(a->authors, b->authors, TRUE);
3123 if (retval)
3124 return retval;
3125
3126 retval = ImprintMatch(a->imp, b->imp, FALSE);
3127 if (retval)
3128 return retval;
3129
3130 retval = TitleMatch(a->title, b->title, Cit_title_name);
3131 if (retval == 2) /* not same type, it fails */
3132 retval = 1;
3133 else if (retval == -2)
3134 retval = -1;
3135 return retval;
3136 }
3137
3138 /*****************************************************************************
3139 *
3140 * Int2 CitGenMatch(a, b, all)
3141 * returns 0 = same Cit-gen
3142 * 1,-1 = different Cit-gen
3143 * if (all) then all fields must be shared
3144 * otherwise, match only shared fields
3145 *
3146 *****************************************************************************/
3147 NLM_EXTERN Int2 LIBCALL CitGenMatch (CitGenPtr a, CitGenPtr b, Boolean all)
3148 {
3149 Int2 retval = 0, i;
3150 CharPtr ap, bp;
3151
3152 if (a == NULL)
3153 return (Int2) -1;
3154 else if (b == NULL)
3155 return (Int2)1;
3156
3157 for (i = 0; i < 5; i++)
3158 {
3159 switch (i)
3160 {
3161 case 0:
3162 ap = a->volume;
3163 bp = b->volume;
3164 break;
3165 case 1:
3166 ap = a->issue;
3167 bp = b->issue;
3168 break;
3169 case 2:
3170 ap = a->pages;
3171 bp = b->pages;
3172 break;
3173 case 3:
3174 ap = a->title;
3175 bp = b->title;
3176 break;
3177 case 4:
3178 ap = a->cit;
3179 bp = b->cit;
3180 break;
3181 }
3182 if ((ap != NULL) && (bp != NULL))
3183 {
3184 retval = StringICmp(ap, bp);
3185 if (retval > 0)
3186 return (Int2) 1;
3187 else if (retval < 0)
3188 return (Int2) -1;
3189 }
3190 else if (all)
3191 {
3192 if ((ap == NULL) && (bp != NULL))
3193 return (Int2) -1;
3194 else if ((ap != NULL) && (bp == NULL))
3195 return (Int2) 1;
3196 }
3197 }
3198
3199 if (((a->authors != NULL) && (b->authors != NULL)) ||
3200 (((a->authors != NULL) || (b->authors != NULL)) && all))
3201 {
3202 retval = AuthListMatch(a->authors, b->authors, TRUE);
3203 if (retval)
3204 return retval;
3205 }
3206
3207 if (((a->muid != 0) && (b->muid != 0)) || all)
3208 {
3209 if (a->muid > b->muid)
3210 return (Int2) 1;
3211 else if (a->muid < b->muid)
3212 return (Int2) -1;
3213 }
3214
3215 if (((a->serial_number != -1) && (b->serial_number != -1)) || all)
3216 {
3217 if (a->serial_number > b->serial_number)
3218 return (Int2) 1;
3219 else if (a->serial_number < b->serial_number)
3220 return (Int2) -1;
3221 }
3222
3223 if (((a->journal != NULL) && (b->journal != NULL)) || all)
3224 {
3225 for (i = 1; i <= 10; i++)
3226 {
3227 if (a->journal == NULL && b->journal == NULL) /* JAK */
3228 break;
3229 retval = TitleMatch(a->journal, b->journal, (Uint1)i);
3230 if (! retval) /* match */
3231 break;
3232 if ((retval == -1) || (retval == 1)) /* same type, diff journal */
3233 return retval;
3234 }
3235 if (retval == 2) /* couldn't match the journal names, fail */
3236 return (Int2) 1;
3237 else if (retval == -2)
3238 return (Int2) -1;
3239 }
3240
3241 if (((a->date != NULL) && (b->date != NULL)) ||
3242 (((a->date != NULL) || (b->date != NULL)) && all))
3243 {
3244 retval = DateMatch(a->date, b->date, TRUE);
3245 if (retval == 2)
3246 retval = 1;
3247 else if (retval == -2)
3248 retval = -1;
3249 }
3250
3251 if (all) { /* JAK */
3252 if (a->volume == NULL && b->volume == NULL &&
3253 a->issue == NULL && b->issue == NULL &&
3254 a->pages == NULL && b->pages == NULL &&
3255 a->title == NULL && b->title == NULL &&
3256 a->cit == NULL && b->cit == NULL &&
3257 a->authors == NULL && b->authors == NULL &&
3258 a->muid == -1 && b->muid == -1 &&
3259 a->journal == NULL && b->journal == NULL &&
3260 a->date == NULL && b->date == NULL &&
3261 a->serial_number != -1 && b->serial_number != -1) {
3262 return -1;
3263 }
3264 }
3265
3266 return retval;
3267 }
3268
3269 /*****************************************************************************
3270 *
3271 * Int2 CitSubMatch(a, b)
3272 * returns 0 = same submission
3273 * 1,-1 = different submission
3274 *
3275 *****************************************************************************/
3276 NLM_EXTERN Int2 LIBCALL CitSubMatch (CitSubPtr a, CitSubPtr b)
3277 {
3278 Int2 retval = 1;
3279 DatePtr da = NULL, db = NULL;
3280
3281 if (a == NULL)
3282 return (Int2) -1;
3283 else if (b == NULL)
3284 return retval;
3285
3286 retval = AuthListMatch(a->authors, b->authors, TRUE);
3287 if (retval)
3288 return retval;
3289
3290 if (a->imp != NULL && b->imp != NULL) {
3291 retval = ImprintMatch(a->imp, b->imp, FALSE);
3292 if (retval)
3293 return retval;
3294 } else {
3295 if (a->imp != NULL) {
3296 da = a->imp->date;
3297 }
3298 if (b->imp != NULL) {
3299 db = b->imp->date;
3300 }
3301 }
3302 if (da == NULL && a->date != NULL) {
3303 da = a->date;
3304 }
3305 if (db == NULL && b->date != NULL) {
3306 db = b->date;
3307 }
3308 if (da != NULL && db != NULL) {
3309 retval = DateMatch(a->date, b->date, TRUE);
3310 if (retval == 2)
3311 retval = 1;
3312 else if (retval == -2)
3313 retval = -1;
3314 }
3315
3316 return retval;
3317 }
3318
3319 /*****************************************************************************
3320 *
3321 * Int2 CitJourMatch(a, b)
3322 * returns 0 = same journal
3323 * 1,-1 = different journal
3324 *
3325 *****************************************************************************/
3326 NLM_EXTERN Int2 LIBCALL CitJourMatch (CitJourPtr a, CitJourPtr b)
3327 {
3328 Int2 retval = 1, i;
3329 static Uint1 journals[6] = { /* precedence for matching journal names */
3330 5 , /* iso_jta */
3331 6 , /* medline_jta */
3332 7 , /* coden */
3333 8 , /* issn */
3334 1 , /* name */
3335 4 }; /* jta */
3336
3337
3338 if (a == NULL)
3339 return (Int2) -1;
3340 else if (b == NULL)
3341 return retval;
3342
3343 for (i = 0; i < 6; i++)
3344 {
3345 retval = TitleMatch(a->title, b->title, journals[i]);
3346 if (! retval) /* match */
3347 break;
3348 if ((retval == -1) || (retval == 1)) /* same type, diff journal */
3349 return retval;
3350 }
3351 if (retval == 2) /* couldn't match the journal names, fail */
3352 return (Int2) 1;
3353 else if (retval == -2)
3354 return (Int2) -1;
3355
3356 retval = ImprintMatch(a->imp, b->imp, FALSE);
3357 if (retval)
3358 return retval;
3359 return retval;
3360 }
3361
3362 /*****************************************************************************
3363 *
3364 * Int2 AuthListMatch(a, b, all)
3365 * returns 0 = same first author
3366 * 1,-1 = different first author
3367 * if (all) all authors must match
3368 *
3369 *****************************************************************************/
3370 NLM_EXTERN Int2 LIBCALL AuthListMatch(AuthListPtr a, AuthListPtr b, Boolean all)
3371 {
3372 Int2 retval = 1, lastnames = 0, i;
3373 size_t len, tlen;
3374 Char name[2][256];
3375 ValNodePtr vnp[2];
3376 Uint1 listtype[2];
3377 AuthorPtr ap;
3378 PersonIdPtr pip;
3379 NameStdPtr nsp;
3380
3381
3382
3383 if (a == NULL)
3384 return (Int2) -1;
3385 else if (b == NULL)
3386 return retval;
3387
3388 vnp[0] = a->names;
3389 vnp[1] = b->names;
3390 listtype[0] = a->choice;
3391 listtype[1] = b->choice;
3392 while ((vnp[0] != NULL) && (vnp[1] != NULL))
3393 {
3394 len = 32000;
3395 for (i = 0; i < 2; i++)
3396 {
3397 name[i][0] = '\0';
3398 if (listtype[i] == 1) /* std */
3399 {
3400 ap = (AuthorPtr)(vnp[i]->data.ptrvalue);
3401 pip = ap->name;
3402 if (pip->choice == 2) /* std */
3403 {
3404 nsp = (NameStdPtr)pip->data;
3405 if (nsp->names[0] != NULL) { /* last name */
3406 StringMove(name[i], nsp->names[0]);
3407 lastnames++;
3408 } else if (nsp->names[3] != NULL) /* full name */
3409 StringMove(name[i], nsp->names[3]);
3410 }
3411 else if (pip->choice > 2)
3412 StringMove(name[i], (CharPtr)pip->data);
3413 }
3414 else
3415 StringMove(name[i], (CharPtr)(vnp[i]->data.ptrvalue));
3416 tlen = StringLen(name[i]);
3417 if (tlen < len)
3418 len = tlen;
3419 vnp[i] = vnp[i]->next;
3420 }
3421 if (len == 0) /* nothing in one or more names */
3422 {
3423 if (StringLen(name[0]) < tlen)
3424 return (Int2)-1;
3425 else
3426 return (Int2) 1;
3427 }
3428 if (lastnames == 2) {
3429 retval = (Int2)StringICmp(name[0], name[1]);
3430 } else {
3431 retval = (Int2)StringNICmp(name[0], name[1], tlen);
3432 }
3433 if (retval < 0)
3434 return (Int2) -1;
3435 else if (retval > 0)
3436 return (Int2) 1;
3437 if (! all) /* first only */
3438 return retval;
3439 }
3440
3441 if (vnp[0] != NULL) /* more names in a */
3442 return (Int2) 1;
3443 else if (vnp[1] != NULL) /* more names in b */
3444 return (Int2) -1;
3445 else
3446 return (Int2) 0;
3447 }
3448
3449 /*****************************************************************************
3450 *
3451 * Int2 TitleMatch(a,b,type)
3452 * if can find two titles of "type" returns
3453 * 0=they match
3454 * 1,-1 = they don't match
3455 * 2,-2 = couldn't find two of "type"
3456 *
3457 *****************************************************************************/
3458 NLM_EXTERN Int2 LIBCALL TitleMatch( ValNodePtr a, ValNodePtr b, Uint1 type)
3459 {
3460 Int2 retval = 2;
3461 Uint1 ca=0, cb=0;
3462 CharPtr t1=NULL, t2=NULL;
3463
3464
3465
3466 if ((a == NULL) || (b == NULL))
3467 return retval;
3468
3469 while (a != NULL)
3470 {
3471 if (a->choice == type)
3472 {
3473 t1 = (CharPtr)(a->data.ptrvalue);
3474 ca = type;
3475 break;
3476 }
3477 else if (a->choice > ca)
3478 ca = a->choice;
3479 a = a->next;
3480 }
3481
3482 while (b != NULL)
3483 {
3484 if (b->choice == type)
3485 {
3486 t2 = (CharPtr)(b->data.ptrvalue);
3487 cb = type;
3488 break;
3489 }
3490 else if (b->choice > cb)
3491 cb = b->choice;
3492 b = b->next;
3493 }
3494
3495 if (ca < cb)
3496 retval = -2;
3497 else
3498 retval = 2;
3499
3500 if ((t1 == NULL) || (t2 == NULL))
3501 return retval;
3502
3503 retval = StringICmp(t1, t2);
3504 if (retval > 0)
3505 return (Int2) 1;
3506 else if (retval < 0)
3507 return (Int2) -1;
3508 else
3509 return retval;
3510 }
3511
3512 /*****************************************************************************
3513 *
3514 * Int2 ImprintMatch(a, b, all)
3515 * returns 0 = same
3516 * 1, -1 = different
3517 * if (all) then all fields in one must be in the other
3518 * else, matches only fields found in both
3519 * NOTE: does not match on Imprint.pub or Imprint.prepub
3520 *
3521 *****************************************************************************/
3522 NLM_EXTERN Int2 LIBCALL ImprintMatch (ImprintPtr a, ImprintPtr b, Boolean all)
3523 {
3524 Int2 retval = 1, i;
3525 CharPtr ap, bp;
3526
3527
3528
3529 if ((a == NULL) || (b == NULL))
3530 return retval;
3531
3532 retval = DateMatch(a->date, b->date, all);
3533 if (retval == 2)
3534 retval = 1;
3535 else if (retval == -2)
3536 retval = -1;
3537 if (retval)
3538 return retval;
3539
3540 for (i = 0; i < 6; i++)
3541 {
3542 switch (i)
3543 {
3544 case 0:
3545 ap = a->volume;
3546 bp = b->volume;
3547 break;
3548 case 1:
3549 ap = a->issue;
3550 bp = b->issue;
3551 break;
3552 case 2:
3553 ap = a->pages;
3554 bp = b->pages;
3555 break;
3556 case 3:
3557 ap = a->section;
3558 bp = b->section;
3559 break;
3560 case 4:
3561 ap = a->part_sup;
3562 bp = b->part_sup;
3563 break;
3564 case 5:
3565 ap = a->language;
3566 bp = b->language;
3567 break;
3568
3569 }
3570 if ((ap != NULL) && (bp != NULL))
3571 {
3572 retval = StringICmp(ap, bp);
3573 if (retval > 0)
3574 return (Int2) 1;
3575 else if (retval < 0)
3576 return (Int2) -1;
3577 }
3578 else if (all)
3579 {
3580 if ((ap == NULL) && (bp != NULL))
3581 return (Int2) -1;
3582 else if ((ap != NULL) && (bp == NULL))
3583 return (Int2) 1;
3584 }
3585 }
3586
3587 if ((a->cprt != NULL) || (b->cprt != NULL))
3588 {
3589 retval = DateMatch(a->cprt, b->cprt, all);
3590 if (retval == 2)
3591 retval = 1;
3592 else if (retval == -2)
3593 retval = -1;
3594 if (retval)
3595 return retval;
3596 }
3597 return retval;
3598 }
3599
3600 /*****************************************************************************
3601 *
3602 * PatPriorityNew()
3603 *
3604 *****************************************************************************/
3605 NLM_EXTERN PatPriorityPtr LIBCALL PatPriorityNew (void)
3606 {
3607 PatPriorityPtr ppp;
3608
3609 ppp = (PatPriorityPtr)MemNew(sizeof(PatPriority));
3610 return ppp;
3611 }
3612
3613 /*****************************************************************************
3614 *
3615 * PatPrioritySetFree()
3616 *
3617 *****************************************************************************/
3618 NLM_EXTERN PatPriorityPtr LIBCALL PatPrioritySetFree (PatPriorityPtr ppp)
3619 {
3620 PatPriorityPtr next;
3621
3622 while (ppp != NULL)
3623 {
3624 next = ppp->next;
3625 MemFree(ppp->country);
3626 MemFree(ppp->number);
3627 DateFree(ppp->date);
3628 MemFree(ppp);
3629 ppp = next;
3630 }
3631 return ppp;
3632 }
3633
3634 /*****************************************************************************
3635 *
3636 * PatPrioritySetAsnRead(aip, atp)
3637 *
3638 *****************************************************************************/
3639 NLM_EXTERN PatPriorityPtr LIBCALL PatPrioritySetAsnRead (AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
3640 {
3641 PatPriorityPtr ppp=NULL, head = NULL, last;
3642 DataVal av;
3643 AsnTypePtr atp;
3644
3645 if (! loaded)
3646 {
3647 if (! BiblioAsnLoad())
3648 return ppp;
3649 }
3650
3651 if ((aip == NULL) || (set == NULL) || (element == NULL))
3652 return ppp;
3653
3654
3655 if (! AsnReadVal(aip, set, &av)) goto erret; /* START_STRUCT */
3656
3657 atp = set;
3658 head = NULL;
3659 last = NULL;
3660
3661 while ((atp = AsnReadId(aip, amp, atp)) != set)
3662 {
3663 if (atp == NULL) goto erret;
3664 ppp = PatPriorityNew();
3665 if (ppp == NULL)
3666 goto erret;
3667
3668 if (head == NULL)
3669 head = ppp;
3670 else
3671 last->next = ppp;
3672 last = ppp;
3673
3674 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the open SEQUENCE */
3675 atp = AsnReadId(aip, amp, atp ); /* country */
3676 if (atp == NULL)
3677 goto erret;
3678 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
3679 ppp->country = av.ptrvalue;
3680 atp = AsnReadId(aip, amp, atp ); /* number */
3681 if (atp == NULL)
3682 goto erret;
3683 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
3684 ppp->number = av.ptrvalue;
3685 atp = AsnReadId(aip, amp, atp ); /* date */
3686 if (atp == NULL)
3687 goto erret;
3688 ppp->date = DateAsnRead(aip, atp);
3689 if (ppp->date == NULL) goto erret;
3690 atp = AsnReadId(aip, amp, atp); /* end struct */
3691 if (atp == NULL) goto erret;
3692 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
3693 }
3694 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end SEQUENCE OF */
3695 ret:
3696 return head;
3697 erret:
3698 head = PatPrioritySetFree(head);
3699 goto ret;
3700 }
3701
3702 /*****************************************************************************
3703 *
3704 * PatPrioritySetAsnWrite(ppp, aip, atp)
3705 *
3706 *****************************************************************************/
3707 NLM_EXTERN Boolean LIBCALL PatPrioritySetAsnWrite (PatPriorityPtr ppp, AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
3708 {
3709 DataVal av;
3710 Boolean retval = FALSE;
3711 PatPriorityPtr tmp;
3712
3713 if (! loaded)
3714 {
3715 if (! BiblioAsnLoad())
3716 return FALSE;
3717 }
3718
3719 if ((aip == NULL) || (set == NULL) || (element == NULL))
3720 return FALSE;
3721
3722 if (ppp == NULL) { AsnNullValueMsg(aip, set); goto erret; }
3723
3724 if (! AsnOpenStruct(aip, set, (Pointer)ppp)) /* open the SEQUENCE OF */
3725 goto erret;
3726
3727 for (tmp = ppp; tmp != NULL; tmp = tmp->next)
3728 {
3729 if (! AsnOpenStruct(aip, element, (Pointer)tmp)) /* open the SEQUENCE */
3730 goto erret;
3731
3732
3733 av.ptrvalue = tmp->country;
3734 if (! AsnWrite(aip, PATENT_PRIORITY_country, &av)) goto erret;
3735 av.ptrvalue = tmp->number;
3736 if (! AsnWrite(aip, PATENT_PRIORITY_number, &av)) goto erret;
3737 if (! DateAsnWrite(tmp->date, aip, PATENT_PRIORITY_date)) goto erret;
3738
3739 if (! AsnCloseStruct(aip, element, (Pointer)tmp))
3740 goto erret;
3741 }
3742
3743 if (! AsnCloseStruct(aip, set, (Pointer)ppp)) /* end SEQUENCE OF */
3744 goto erret;
3745 retval = TRUE;
3746 erret:
3747 return retval;
3748 }
3749
3750
3751 /*****************************************************************************
3752 *
3753 * ArticleIdNew()
3754 *
3755 *****************************************************************************/
3756 NLM_EXTERN ArticleIdPtr LIBCALL ArticleIdNew (void)
3757 {
3758 ArticleIdPtr aidp;
3759
3760 aidp = (ArticleIdPtr)MemNew(sizeof(ArticleId));
3761 return aidp;
3762 }
3763
3764 /*****************************************************************************
3765 *
3766 * ArticleIdFree()
3767 *
3768 *****************************************************************************/
3769 NLM_EXTERN ArticleIdPtr LIBCALL ArticleIdFree (ArticleIdPtr aidp)
3770 {
3771 if (aidp == NULL)
3772 return aidp;
3773
3774 switch (aidp->choice)
3775 {
3776 case ARTICLEID_DOI: /* string types */
3777 case ARTICLEID_PII:
3778 case ARTICLEID_PMCPID:
3779 case ARTICLEID_PMPID:
3780 MemFree (aidp->data.ptrvalue);
3781 break;
3782
3783 case ARTICLEID_OTHER: /* dbtag */
3784 DbtagFree ((DbtagPtr)(aidp->data.ptrvalue));
3785 break;
3786 default: /* integer types */
3787 break;
3788 }
3789
3790 return (ArticleIdPtr)MemFree(aidp);
3791 }
3792
3793 /*****************************************************************************
3794 *
3795 * ArticleIdAsnRead(aip, atp)
3796 *
3797 *****************************************************************************/
3798 NLM_EXTERN ArticleIdPtr LIBCALL ArticleIdAsnRead (AsnIoPtr aip, AsnTypePtr orig)
3799 {
3800 ArticleIdPtr aidp=NULL;
3801 AsnTypePtr atp;
3802 Uint1 choice = 0;
3803 DataVal av;
3804
3805 if (! loaded)
3806 {
3807 if (! BiblioAsnLoad())
3808 return aidp;
3809 }
3810
3811 if (aip == NULL)
3812 return aidp;
3813
3814 if (orig == NULL) /* ArticleId ::= */
3815 atp = AsnReadId(aip, amp, ARTICLEID);
3816 else
3817 atp = AsnLinkType(orig, ARTICLEID);
3818 if (atp == NULL)
3819 return aidp;
3820
3821 aidp = ArticleIdNew();
3822 if (aidp == NULL)
3823 goto erret;
3824
3825 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the CHOICE */
3826 atp = AsnReadId(aip, amp, atp); /* read the CHOICE id */
3827 if (atp == NULL)
3828 goto erret;
3829
3830 if (atp == ARTICLEID_pubmed)
3831 choice = 1;
3832 else if (atp == ARTICLEID_medline)
3833 choice = 2;
3834 else if (atp == ARTICLEID_doi)
3835 choice = 3;
3836 else if (atp == ARTICLEID_pii)
3837 choice = 4;
3838 else if (atp == ARTICLEID_pmcid)
3839 choice = 5;
3840 else if (atp == ARTICLEID_pmcpid)
3841 choice = 6;
3842 else if (atp == ARTICLEID_pmpid)
3843 choice = 7;
3844 else if (atp == ARTICLEID_other)
3845 choice = 8;
3846 else
3847 {
3848 ErrPostEx(SEV_ERROR, 0,0, "Unrecognized ArticleId");
3849 goto erret;
3850 }
3851
3852 aidp->choice = choice;
3853 if (choice == ARTICLEID_OTHER)
3854 {
3855 aidp->data.ptrvalue = DbtagAsnRead(aip, atp);
3856 if (aidp->data.ptrvalue == NULL)
3857 goto erret;
3858 }
3859 else
3860 {
3861 if (AsnReadVal(aip, atp, &(aidp->data)) <= 0)
3862 goto erret;
3863 }
3864
3865 ret:
3866 AsnUnlinkType(orig);
3867 return aidp;
3868 erret:
3869 aidp = ArticleIdFree(aidp);
3870 goto ret;
3871 }
3872
3873 /*****************************************************************************
3874 *
3875 * ArticleIdAsnWrite(aidp, aip, atp)
3876 *
3877 *****************************************************************************/
3878 NLM_EXTERN Boolean LIBCALL ArticleIdAsnWrite (ArticleIdPtr aidp, AsnIoPtr aip, AsnTypePtr orig)
3879 {
3880 DataVal av;
3881 AsnTypePtr atp, atp2;
3882 Boolean retval = FALSE;
3883
3884 if (! loaded)
3885 {
3886 if (! BiblioAsnLoad())
3887 return FALSE;
3888 }
3889
3890 if (aip == NULL)
3891 return FALSE;
3892
3893 atp = AsnLinkType(orig, ARTICLEID);
3894 if (atp == NULL)
3895 return FALSE;
3896
3897 if (aidp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
3898
3899 if (! aidp->choice)
3900 goto erret;
3901
3902 if (! AsnWrite(aip, atp, &av)) /* write the tag */
3903 goto erret;
3904
3905 atp2 = NULL;
3906 switch (aidp->choice)
3907 {
3908 case ARTICLEID_PUBMED:
3909 atp2 = ARTICLEID_pubmed;
3910 break;
3911 case ARTICLEID_MEDLINE:
3912 atp2 = ARTICLEID_medline;
3913 break;
3914 case ARTICLEID_DOI:
3915 atp2 = ARTICLEID_doi;
3916 break;
3917 case ARTICLEID_PII:
3918 atp2 = ARTICLEID_pii;
3919 break;
3920 case ARTICLEID_PMCID:
3921 atp2 = ARTICLEID_pmcid;
3922 break;
3923 case ARTICLEID_PMCPID:
3924 atp2 = ARTICLEID_pmcpid;
3925 break;
3926 case ARTICLEID_PMPID:
3927 atp2 = ARTICLEID_pmpid;
3928 break;
3929 case ARTICLEID_OTHER:
3930 atp2 = ARTICLEID_other;
3931 break;
3932 default:
3933 break;
3934 }
3935
3936 if (aidp->choice == ARTICLEID_OTHER)
3937 {
3938 if (! DbtagAsnWrite((DbtagPtr)(aidp->data.ptrvalue), aip, atp2))
3939 goto erret;
3940 }
3941 else if (atp2 != NULL)
3942 {
3943 if (! AsnWrite(aip, atp2, &(aidp->data)))
3944 goto erret;
3945 }
3946 else
3947 goto erret;
3948
3949 retval = TRUE;
3950 erret:
3951 AsnUnlinkType(orig);
3952 return retval;
3953 }
3954
3955
3956 /*****************************************************************************
3957 *
3958 * PubStatusDateNew()
3959 *
3960 *****************************************************************************/
3961 NLM_EXTERN PubStatusDatePtr LIBCALL PubStatusDateNew (void)
3962 {
3963 PubStatusDatePtr psdp;
3964
3965 psdp = (PubStatusDatePtr)MemNew(sizeof(PubStatusDate));
3966 return psdp;
3967 }
3968
3969 /*****************************************************************************
3970 *
3971 * PubStatusDateFree()
3972 *
3973 *****************************************************************************/
3974 NLM_EXTERN PubStatusDatePtr LIBCALL PubStatusDateFree (PubStatusDatePtr psdp)
3975 {
3976 if (psdp == NULL)
3977 return psdp;
3978 DateFree (psdp->date);
3979 return (PubStatusDatePtr)MemFree(psdp);
3980 }
3981
3982 /*****************************************************************************
3983 *
3984 * PubStatusDateAsnRead(aip, atp)
3985 *
3986 *****************************************************************************/
3987 NLM_EXTERN PubStatusDatePtr LIBCALL PubStatusDateAsnRead (AsnIoPtr aip, AsnTypePtr orig)
3988 {
3989 PubStatusDatePtr psdp=NULL;
3990 DataVal av;
3991 AsnTypePtr atp, oldatp;
3992
3993 if (! loaded)
3994 {
3995 if (! BiblioAsnLoad())
3996 return psdp;
3997 }
3998
3999 if (aip == NULL)
4000 return psdp;
4001
4002 if (orig == NULL) /* PubStatusDate ::= */
4003 atp = AsnReadId(aip, amp, PUBSTATUSDATE);
4004 else
4005 atp = AsnLinkType(orig, PUBSTATUSDATE);
4006 if (atp == NULL)
4007 return psdp;
4008
4009 psdp = PubStatusDateNew();
4010 if (psdp == NULL)
4011 goto erret;
4012
4013 oldatp = atp;
4014 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the START STRUCT */
4015 atp = AsnReadId(aip, amp, atp); /* read the PubStatus */
4016 if (atp == NULL)
4017 goto erret;
4018 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
4019 psdp->pubstatus = (Uint1)(av.intvalue);
4020 atp = AsnReadId(aip, amp, atp);
4021 if (atp == NULL) goto erret;
4022 psdp->date = DateAsnRead(aip, atp);
4023 if (psdp->date == NULL)
4024 goto erret;
4025 atp = AsnReadId(aip, amp, atp);
4026 if (atp == NULL) goto erret;
4027 if (AsnReadVal(aip, oldatp, &av) <= 0) goto erret; /* read the END STRUCT */
4028
4029 ret:
4030 AsnUnlinkType(orig);
4031 return psdp;
4032 erret:
4033 psdp = PubStatusDateFree(psdp);
4034 goto ret;
4035 }
4036
4037 /*****************************************************************************
4038 *
4039 * PubStatusDateAsnWrite(psdp, aip, atp)
4040 *
4041 *****************************************************************************/
4042 NLM_EXTERN Boolean LIBCALL PubStatusDateAsnWrite (PubStatusDatePtr psdp, AsnIoPtr aip, AsnTypePtr orig)
4043 {
4044 DataVal av;
4045 AsnTypePtr atp;
4046 Boolean retval = FALSE;
4047
4048 if (! loaded)
4049 {
4050 if (! BiblioAsnLoad())
4051 return FALSE;
4052 }
4053
4054 if (aip == NULL)
4055 return FALSE;
4056
4057 atp = AsnLinkType(orig, PUBSTATUSDATE);
4058 if (atp == NULL)
4059 return FALSE;
4060
4061 if (psdp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
4062
4063 if (! AsnOpenStruct(aip, atp, (Pointer)psdp))
4064 goto erret;
4065
4066 av.intvalue = (Int4)(psdp->pubstatus);
4067 if (! AsnWrite(aip, PUBSTATUSDATE_pubstatus, &av)) goto erret;
4068 if (! DateAsnWrite(psdp->date, aip, PUBSTATUSDATE_date)) goto erret;
4069
4070 if (! AsnCloseStruct(aip, atp, (Pointer)psdp)) goto erret;
4071
4072 retval = TRUE;
4073 erret:
4074 AsnUnlinkType(orig);
4075 return retval;
4076 }
4077 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |