~ubuntu-branches/ubuntu/dapper/ncbi-tools6/dapper

« back to all changes in this revision

Viewing changes to object/objbibli.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2002-04-04 22:13:09 UTC
  • Revision ID: james.westby@ubuntu.com-20020404221309-vfze028rfnlrldct
Tags: upstream-6.1.20011220a
ImportĀ upstreamĀ versionĀ 6.1.20011220a

Show diffs side-by-side

added added

removed removed

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