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