1 /*
2  * ===========================================================================
3  *
4  *                             COPYRIGHT 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 Government employee and thus cannot
10  *  be copyrighted.  This software/database is freely available to the
11  *  public for use without a copyright notice.  Restrictions cannot be
12  *  placed on its present or future use.
13  *
14  *  Although all reasonable efforts have been taken to ensure the accuracy
15  *  and reliability of the software and data, the National Library of
16  *  Medicine (NLM) and the U. S. Government do not and cannot warrant the
17  *  performance or results that may be obtained by using this software or
18  *  data.  The NLM and the U. S. Government disclaim all warranties as to
19  *  performance, merchantability or fitness for any particular purpose.
20  *
21  *  Please see that the author is suitably cited in any work or product
22  *  based on this material.
23  *
24  * ===========================================================================
25  *
26  * RCS $Id: objentr.c,v 6.4 1998/08/24 18:42:17 kans Exp $
27  *
28  * Author:   Greg Schuler, Jim Ostell, Jonathan Epstein
29  *
30  * Version Creation Date:   6/28/94
31  *
32  * File Description:  ASN.1 object support for EntrezInfo data block & docsums.
33  *
34  * Modifications:
35  * --------------------------------------------------------------------------
36  * Rev   Date      Name        Description of modification
37  * ----  --------  ----------  ----------------------------------------------
38  * 1.1   06-28-94  Schuler     This file created from definitions extracted
39  *                             from accentr.h
40  * 1.2   08-22-94  Schuler     Added handling for new fields.
41  *
42  * 05-19-95 Schuler     Added rcs Log directive for automatic insertion of
43  *                      modification comments.
44  *
45  * Revision $Log: objentr.c,v $
46  * Revision Revision 6.4  1998/08/24 18:42:17  kans
47  * Revision fixed -v -fd warnings
48  * Revision
49  * Revision Revision 6.3  1998/03/26 23:23:16  yaschenk
50  * Revision adding CdRomAsnLoad() as extern function to load Asn tree
51  * Revision
52  * Revision Revision 6.2  1997/10/10 20:19:13  kans
53  * Revision div->tag now filled by StringNCpy_0
54  * Revision
55  * Revision Revision 6.1  1997/10/07 22:09:48  volodya
56  * Revision new data fields (entrezDate, pStatus, pLanguage, pPubType) have added to DocSum structure
57  * Revision
58  * Revision Revision 6.0  1997/08/25 18:13:16  madden
59  * Revision Revision changed to 6.0
60  * Revision
61  * Revision Revision 5.4  1997/06/26 21:55:46  vakatov
62  * Revision [PC] DLL'd "ncbicdr.lib", "ncbiacc.lib", "ncbinacc.lib" and "ncbicacc.lib"
63  * Revision
64  * Revision Revision 5.3  1997/05/01 21:19:41  epstein
65  * Revision fix leak detected by Purify
66  * Revision
67  * Revision 5.2  1997/03/05  19:23:43  brandon
68  * minor fix.
69  *
70  * Revision 5.1  1997/03/05  19:00:09  brandon
71  * added objet loaders for expanded EntrezInfo structure (including link data)
72  *
73  * Revision 5.0  1996/05/28  13:55:34  ostell
74  * Set to revision 5.0
75  *
76  * Revision 4.1  1995/10/17  20:26:29  epstein
77  * remove to free dsp->extra in DocSumFree
78  *
79  * Revision 4.0  1995/07/26  13:50:32  ostell
80  * force revision to 4.0
81  *
82  * Revision 1.8  1995/07/11  14:54:53  epstein
83  * move DocSumFree from accentr.c and fix docsum object loaders
84  *
85  * Revision 1.7  1995/07/11  12:25:14  epstein
86  * add DocSum object loaders
87  *
88  * Revision 1.6  1995/05/16  14:36:20  schuler
89  * Automatic comment insertion enabled
90  *
91  *
92  * ==========================================================================
93  */
94 
95 #define REVISION_STR "$Revision: 6.4 $"
96 
97 
98 
99 /*** #define WRITE_NEW_STUFF ***/
100 
101 
102 #include <cdrom.h>
103 #include <objentr.h>
104 #include <accentr.h>
105 
106 static Boolean NEAR FieldDataAsnWrite PROTO((EntrezFieldDataPtr p, AsnIoPtr stream, AsnType *type_start));
107 static Boolean NEAR TypeDataAsnWrite PROTO((EntrezTypeDataPtr p, AsnIoPtr stream, AsnType *type_start, int num_fields));
108 
109 static EntrezTypeInfo* EntrezTypeInfo_AsnRead (EntrezTypeInfo *tinf, AsnIo *aio, AsnType *type);
110 static Boolean EntrezTypeInfo_AsnWrite (const EntrezTypeInfo *tinf, AsnIo *aio, AsnType *type);
111 
112 static EntrezFieldInfo* EntrezFieldInfo_AsnRead (EntrezFieldInfo *fld, AsnIo *stream, AsnType *type0);
113 static Boolean EntrezFieldInfo_AsnWrite (const EntrezFieldInfo *fld, AsnIo *stream, AsnType *type);
114 
115 static EntrezLinkInfo* EntrezLinkInfo_AsnRead (EntrezLinkInfo *fld, AsnIo *stream, AsnType *type0);
116 static Boolean EntrezLinkInfo_AsnWrite (const EntrezLinkInfo *fld, AsnIo *stream, AsnType *type);
117 
118 #define EntrezDivInfo_New(a)   EntrezDivInfo_Construct(MemNew(sizeof(EntrezDivInfo),a))
119 #define EntrezDivInfo_Free(a)  (void)MemFree(EntrezDivInfo_Desctuct(a))
120 static  EntrezDivInfo* EntrezDivInfo_Construct (EntrezDivInfo *div, int type_ct);
121 static  EntrezDivInfo* EntrezDivInfo_Destruct (EntrezDivInfo *div);
122 static  EntrezDivInfo* EntrezDivInfo_AsnRead (EntrezDivInfo *div,  AsnIo *ain, AsnType *type_start);
123 static  Boolean EntrezDivInfo_AsnWrite (const EntrezDivInfo *div,  AsnIo *ain, AsnType *type_start);
124 
125 static CdDate * CdDate_AsnRead (CdDate *date, AsnIo *ain, AsnType *type_start);
126 static Boolean CdDate_AsnWrite (const CdDate *date, AsnIo *aout, AsnType *atp);
127 
128 
129 #define Boolean_AsnWrite(a,b,c,d)  \
130 	{ if (d) 	\
131 		{ DataVal val;  val.boolvalue = (a);  \
132 		(d) = AsnWrite(b,c,&val); } }
133 
134 #define Integer_AsnWrite(a,b,c,d)  \
135 	{ if (d) 	\
136 		{ DataVal val;  val.intvalue = (a);  \
137 		(d) = AsnWrite(b,c,&val); } } \
138 
139 #define String_AsnWrite(a,b,c,d)  \
140 	{ if ((d) && ((a)!=NULL) )		\
141 		{ DataVal val;  val.ptrvalue = (void*)(a); \
142 		(d) = AsnWrite(b,c,&val); } } \
143 
144 
145 
146 static int _type_ct;
147 static int _fld_ct;
148 static int _div_ct;
149 
EntrezLinkInfoFree(EntrezLinkInfo * LinkInfo)150 static void LIBCALL EntrezLinkInfoFree(EntrezLinkInfo *LinkInfo)
151 {
152   MemFree(LinkInfo -> tag);
153   MemFree(LinkInfo -> name);
154   MemFree(LinkInfo -> descr);
155   MemFree(LinkInfo);
156 }
157 
158 
159 /*****************************************************************************
160 *
161 *   NetEntAsnLoad()
162 *
163 *****************************************************************************/
164 
165 static Boolean loaded = FALSE;
166 
167 NLM_EXTERN Boolean LIBCALL
CdRomAsnLoad(void)168 CdRomAsnLoad(void)
169 {
170     if (loaded)
171         return TRUE;
172         loaded = TRUE;
173 
174         if (! AllObjLoad()) {
175                 loaded = FALSE;
176                 return FALSE;
177         }
178         if (! AsnLoad()) {
179                 loaded = FALSE;
180                 return FALSE;
181         }
182 
183         return TRUE;
184 }
185 
186 
187 
188 /*****************************************************************************
189 *
190 *   ASN.1 object support:
191 *
192 *
193 *	EntrezInfoFree
194 *	EntrezInfoAsnRead
195 *	EntrezInfoAsnWrite
196 *
197 *****************************************************************************/
198 
EntrezInfoFree(EntrezInfoPtr info)199 NLM_EXTERN EntrezInfoPtr LIBCALL EntrezInfoFree (EntrezInfoPtr info)
200 {
201 	Int2 i;
202 
203 	if (info == NULL)
204 		return NULL;
205 
206 	MemFree(info->volume_label);
207 	for (i = 0; i < info->type_count; i++)
208 		MemFree(info->types[i].fields);
209 	MemFree(info->types);
210 	MemFree(info->descr);
211 	MemFree(info->huff_left);
212 	MemFree(info->huff_right);
213 	if (info->type_names != NULL)
214 	{
215 		for (i = 0; i < info->type_count; i++)
216 			MemFree(info->type_names[i]);
217 		MemFree(info->type_names);
218 	}
219 	if (info->field_names != NULL)
220 	{
221 		for (i = 0; i < info->field_count; i++)
222 			MemFree(info->field_names[i]);
223 		MemFree(info->field_names);
224 	}
225 	for (i = 0; i < info -> link_count; i++)
226 	  EntrezLinkInfoFree(info -> link_info + i);
227 	return MemFree(info);
228 }
229 
230 
EntrezInfoAsnRead(AsnIo * stream,AsnType * type_start)231 NLM_EXTERN EntrezInfoPtr LIBCALL EntrezInfoAsnRead (AsnIo *stream, AsnType *type_start)
232 {
233 	DataVal val;
234 	AsnType *atp, *oldtype;
235     EntrezInfoPtr info;
236 	EntrezTypeDataPtr currtdp = NULL;
237 	EntrezFieldDataPtr currfdp = NULL;
238 	EntrezTypeInfo *tinf;
239 	EntrezFieldInfo *fld;
240 	EntrezLinkInfo *link;
241 	EntrezDivInfo *div;
242 	Int2 typectr, fieldctr;
243 	Int2 huff_left_ctr, huff_right_ctr;
244 	int i;
245 	size_t bytes;
246 
247 	if ((stream == NULL) || (! AsnLoad()))
248 		return NULL;
249 
250 	if (type_start == NULL)           /* Cdrom-inf ::= (self contained) */
251 		atp = AsnReadId(stream, amp, CDROM_INF);
252 	else
253 		atp = AsnLinkType(type_start, CDROM_INF);    /* link in local tree */
254 	oldtype = atp;
255 
256 	AsnReadVal(stream, atp, &val);    /* read the START_STRUCT */
257 
258 	info = (EntrezInfoPtr) MemNew(sizeof(EntrezInfo));
259 	typectr = 0;
260 	fieldctr = 0;
261 	huff_left_ctr = 0;
262 	huff_right_ctr = 0;
263 
264 	while ((atp = AsnReadId(stream, amp, atp)) != oldtype)
265 	{
266 		AsnReadVal(stream, atp, &val);
267 
268 		if (atp == CDROM_INF_volume_label)
269 			info->volume_label = (CharPtr)val.ptrvalue;
270 		else if (atp == CDROM_INF_version)
271 			info->version = (short)val.intvalue;
272 		else if (atp == CDROM_INF_issue)
273 			info->issue = (short)val.intvalue;
274 		else if (atp == CDROM_INF_format)
275 			info->format = (short)val.intvalue;
276 		else if (atp == CDROM_INF_descr)
277 			info->descr = (char*)val.ptrvalue;
278 		else if (atp == CDROM_INF_no_compression)
279 			info->no_compression = val.boolvalue;
280 		else if (atp == CDROM_INF_huff_count)
281 		{
282 			info->huff_count = (Int2)val.intvalue;
283 			info->huff_left = (Int2Ptr) MemNew(sizeof(Int2) * info->huff_count);
284 			info->huff_right = (Int2Ptr) MemNew(sizeof(Int2) * info->huff_count);
285 		}
286 		else if (atp == CDROM_INF_huff_left_E)
287 		{
288 			info->huff_left[huff_left_ctr] = (short)val.intvalue;
289 			huff_left_ctr++;
290 		}
291 		else if (atp == CDROM_INF_huff_right_E)
292 		{
293 			info->huff_right[huff_right_ctr] = (short)val.intvalue;
294 			huff_right_ctr++;
295 		}
296 		else if (atp == CDROM_INF_type_count)
297 		{
298 			info->type_count = (short)val.intvalue;
299 			info->type_names = (char**) MemNew(sizeof(char*) * info->type_count);
300 			info->types = (EntrezTypeData*) MemNew(sizeof(EntrezTypeData) * (size_t)info->type_count);
301 			bytes = (size_t)info->type_count * sizeof(EntrezTypeInfo);
302 			info->type_info = tinf = (EntrezTypeInfo*) MemNew(bytes);
303 		}
304 		else if (atp == CDROM_INF_type_names_E)
305 		{
306 			info->type_names[typectr] = (CharPtr)val.ptrvalue;
307 			typectr++;
308 		}
309 		else if (atp == CDROM_INF_type_bucket_size)
310 			info->type_bucket_size = (Int2)val.intvalue;
311 		else if (atp == CDROM_INF_field_count)
312 		{
313 			info->field_count = (short)val.intvalue;
314 		 	info->field_names = (char **) MemNew(sizeof(char*) * info->field_count);
315 		 	bytes = (size_t)info->field_count * sizeof(EntrezFieldInfo);
316 		 	info->field_info = fld = (EntrezFieldInfo*) MemNew(bytes);
317 		}
318 		else if (atp == CDROM_INF_link_count)
319 		{
320 			info->link_count = val.intvalue;
321 		 	bytes = (size_t)info->link_count * sizeof(EntrezLinkInfo);
322 		 	info->link_info = link = (EntrezLinkInfo*) MemNew(bytes);
323 		}
324 		else if (atp == CDROM_INF_field_names_E)
325 		{
326 			info->field_names[fieldctr] = (char*)val.ptrvalue;
327 			fieldctr++;
328 		}
329 		else if (atp == CDROM_INF_field_bucket_size)
330 			info->field_bucket_size = (short)val.intvalue;
331 
332 
333 		else if (atp == CDROM_INF_types_E)
334 		{
335 			if (val.intvalue == START_STRUCT)
336 			{
337 				if (currtdp == NULL)
338 					currtdp = info->types;
339 				else
340 					currtdp++;
341 				currtdp->fields = (EntrezFieldDataPtr) MemNew(sizeof(EntrezFieldData) * info->field_count);
342 				currfdp = NULL;   /* reset field data chain */
343 			}
344 		}
345 		else if (atp == TYPEDATA_fields_E)
346 		{
347 			if (val.intvalue == START_STRUCT)
348 			{
349 				if (currfdp == NULL)
350 					currfdp = currtdp->fields;
351 				else
352 					currfdp++;
353 			}
354 		}
355 		else if (atp == TYPEDATA_num)
356 			currtdp->num = val.intvalue;
357 		else if (atp == TYPEDATA_num_uids)
358 			currtdp->num_uids = val.intvalue;
359 		else if (atp == TYPEDATA_minuid)
360 			currtdp->minuid = val.intvalue;
361 		else if (atp == TYPEDATA_maxuid)
362 			currtdp->maxuid = val.intvalue;
363 		else if (atp == TYPEDATA_num_bucket)
364 			currtdp->num_bucket = (Int2)val.intvalue;
365 		else if (atp == FIELDDATA_num_terms)
366 			currfdp->num_terms = val.intvalue;
367 		else if (atp == FIELDDATA_num_bucket)
368 			currfdp->num_bucket = (Int2) val.intvalue;
369 
370 		else if (atp == CDROM_INF_release_date)
371 			CdDate_AsnRead(&(info->release_date),stream,atp);
372 		else if (atp == CDROM_INF_close_date)
373 			CdDate_AsnRead(&(info->close_date),stream,atp);
374 
375 		else if (atp == CDROM_INF_type_info_E)
376 			EntrezTypeInfo_AsnRead(tinf++,stream,atp);
377 		else if (atp == CDROM_INF_field_info_E)
378 			EntrezFieldInfo_AsnRead(fld++,stream,atp);
379 		else if (atp == CDROM_INF_link_info_E)
380 			EntrezLinkInfo_AsnRead(link++,stream,atp);
381 
382 		else if (atp == CDROM_INF_div_count)
383 		{
384 			size_t bytes = (size_t)val.intvalue * sizeof(EntrezDivInfo);
385 			info->div_info = div = (EntrezDivInfo*) MemNew(bytes);
386 			info->div_count = (short)val.intvalue;
387 			for (i=0; i<val.intvalue; ++i)
388 				EntrezDivInfo_Construct(div++,info->type_count);
389 			div = info->div_info;
390 		}
391 		else if (atp == CDROM_INF_div_info_E)
392 			EntrezDivInfo_AsnRead(div++,stream,atp);
393 
394 		else
395 		{
396 			AsnKillValue(atp,&val);
397 		}
398 
399 	}
400 	AsnReadVal(stream, atp, &val);    /* read the END_STRUCT */
401 	AsnUnlinkType(type_start);       /* unlink local tree */
402 	return info;
403 }
404 
405 
EntrezInfoAsnWrite(EntrezInfo * info,AsnIo * stream,AsnType * type_start)406 NLM_EXTERN Boolean LIBCALL EntrezInfoAsnWrite (EntrezInfo *info, AsnIo *stream, AsnType *type_start)
407 
408 {
409 	DataVal val;
410 	int i;
411 	AsnType *atp;
412 	Boolean retval = FALSE;
413 
414 	if ((stream == NULL) || (! AsnLoad()))
415 		return FALSE;
416 
417 	atp = AsnLinkType(type_start, CDROM_INF); /* link local tree */
418 
419 	if (atp == NULL)
420 		return FALSE;
421 
422 	if (info == NULL)
423 	{
424 		AsnNullValueMsg(stream, atp);
425 		goto erret;
426 	}
427 
428 	_type_ct = info->type_count;
429 	_fld_ct = info->field_count;
430 	_div_ct = info->div_count;
431 
432 	if (! AsnStartStruct(stream, atp))
433 		goto erret;
434 	val.ptrvalue = info->volume_label;
435 	AsnWrite (stream, CDROM_INF_volume_label, &val);
436 	val.intvalue = info->version;
437 	AsnWrite (stream, CDROM_INF_version, &val);
438 	val.intvalue = info->issue;
439 	AsnWrite (stream, CDROM_INF_issue, &val);
440 	val.intvalue = info->format;
441 	AsnWrite (stream, CDROM_INF_format, &val);
442 	val.ptrvalue = info->descr;
443 	AsnWrite (stream, CDROM_INF_descr, &val);
444 	val.boolvalue = info->no_compression;
445 	AsnWrite (stream, CDROM_INF_no_compression, &val);
446 
447 	val.intvalue = info->huff_count;
448 	AsnWrite (stream, CDROM_INF_huff_count, &val);
449 	AsnStartStruct (stream, CDROM_INF_huff_left);
450 	for (i = 0; i < info->huff_count; i++)
451 	{
452 		val.intvalue = info->huff_left[i];
453 		AsnWrite(stream, CDROM_INF_huff_left_E, &val);
454 	}
455 	AsnEndStruct (stream, CDROM_INF_huff_left);
456 	AsnStartStruct (stream, CDROM_INF_huff_right);
457 	for (i = 0; i < info->huff_count; i++)
458 	{
459 		val.intvalue = info->huff_right[i];
460 		AsnWrite(stream, CDROM_INF_huff_right_E, &val);
461 	}
462 	AsnEndStruct (stream, CDROM_INF_huff_right);
463 
464 	val.intvalue = info->type_count;
465 	AsnWrite (stream, CDROM_INF_type_count, &val);
466 	AsnStartStruct (stream, CDROM_INF_type_names);
467 	for (i = 0; i < info->type_count; i++)
468 	{
469 		val.ptrvalue = info->type_names[i];
470 		AsnWrite(stream, CDROM_INF_type_names_E, &val);
471 	}
472 	AsnEndStruct (stream, CDROM_INF_type_names);
473 
474 	val.intvalue = info->type_bucket_size;
475 	AsnWrite (stream, CDROM_INF_type_bucket_size, &val);
476 
477 	val.intvalue = info->field_count;
478 	AsnWrite (stream, CDROM_INF_field_count, &val);
479 	AsnStartStruct (stream, CDROM_INF_field_names);
480 	for (i = 0; i < info->field_count; i++)
481 	{
482 		val.ptrvalue = info->field_names[i];
483 		AsnWrite(stream, CDROM_INF_field_names_E, &val);
484 	}
485 	AsnEndStruct (stream, CDROM_INF_field_names);
486 
487 	val.intvalue = info->field_bucket_size;
488 	AsnWrite (stream, CDROM_INF_field_bucket_size, &val);
489 
490 	AsnStartStruct (stream, CDROM_INF_types);
491 	for (i = 0; i < info->type_count; i++)
492 	{
493 		TypeDataAsnWrite (&info->types[i], stream, CDROM_INF_types_E,
494 						  info->field_count);
495 	}
496 	AsnEndStruct (stream, CDROM_INF_types);
497 
498 #define WRITE_NEW_STUFF
499 #ifdef WRITE_NEW_STUFF
500 
501 	if (info->release_date.year != 0)
502 		CdDate_AsnWrite(&info->release_date,stream,CDROM_INF_release_date);
503 	if (info->close_date.year != 0)
504 		CdDate_AsnWrite(&info->close_date,stream,CDROM_INF_close_date);
505 
506 	if (info->type_info != NULL)
507 	{
508 		AsnStartStruct(stream,CDROM_INF_type_info);
509 		for (i=0; i<info->type_count; ++i)
510 			EntrezTypeInfo_AsnWrite(&(info->type_info[i]),stream,CDROM_INF_type_info_E);
511 		AsnEndStruct(stream,CDROM_INF_type_info);
512 	}
513 
514 	if (info->field_info != NULL)
515 	{
516 		AsnStartStruct(stream,CDROM_INF_field_info);
517 		for (i=0; i<info->field_count; ++i)
518 			EntrezFieldInfo_AsnWrite(&(info->field_info[i]),stream,CDROM_INF_field_info_E);
519 		AsnEndStruct(stream,CDROM_INF_field_info);
520 	}
521 
522 	if (info->div_count > 0)
523 	{
524 		val.intvalue = info->div_count;
525 		AsnWrite(stream,CDROM_INF_div_count,&val);
526 		AsnStartStruct(stream,CDROM_INF_div_info);
527 		for (i=0; i<info->div_count; ++i)
528 			EntrezDivInfo_AsnWrite(&(info->div_info[i]),stream,CDROM_INF_div_info_E);
529 		AsnEndStruct(stream,CDROM_INF_div_info);
530 	}
531 
532 #endif
533 
534 	if (! AsnEndStruct(stream, atp))
535 		goto erret;
536 
537 	retval = TRUE;
538 
539 erret:
540 	AsnUnlinkType(type_start); /* unlink local tree */
541 	return retval;
542 }
543 
544 
FieldDataAsnWrite(EntrezFieldData * data,AsnIo * stream,AsnType * type_start)545 static Boolean NEAR FieldDataAsnWrite (EntrezFieldData *data, AsnIo *stream, AsnType *type_start)
546 {
547 	DataVal val;
548 	AsnType *atp;
549 	Boolean retval = FALSE;
550 
551 	ASSERT(stream != NULL);
552 
553 	atp = AsnLinkType(type_start,FIELDDATA); /* link local tree */
554 
555 	if (atp == NULL)
556 		return FALSE;
557 
558 	if (data == NULL)
559 	{
560 		AsnNullValueMsg(stream, atp);
561 		goto erret;
562 	}
563 
564 	if (! AsnStartStruct(stream, atp))
565 		goto erret;
566 	val.intvalue = data->num_terms;
567 	AsnWrite (stream, FIELDDATA_num_terms, &val);
568 	val.intvalue = data->num_bucket;
569 	AsnWrite (stream, FIELDDATA_num_bucket, &val);
570 
571 	if (! AsnEndStruct(stream, atp))
572 		goto erret;
573 
574 	retval = TRUE;
575 
576 erret:
577 	AsnUnlinkType(type_start); /* unlink local tree */
578 	return retval;
579 }
580 
TypeDataAsnWrite(EntrezTypeData * data,AsnIoPtr stream,AsnType * type_start,int num_fields)581 static Boolean NEAR TypeDataAsnWrite (EntrezTypeData *data, AsnIoPtr stream,
582                                        AsnType *type_start, int num_fields)
583 {
584 	DataVal val;
585 	AsnType *atp;
586 	int i;
587 	Boolean retval = FALSE;
588 
589 	ASSERT(stream != NULL);
590 
591 	atp = AsnLinkType(type_start, TYPEDATA); /* link local tree */
592 
593 	if (atp == NULL)
594 		return FALSE;
595 
596 	if (data == NULL)
597 	{
598 		AsnNullValueMsg(stream, atp);
599 		goto erret;
600 	}
601 
602 	if (! AsnStartStruct(stream, atp))
603 		goto erret;
604 	val.intvalue = data->num;
605 	AsnWrite (stream, TYPEDATA_num, &val);
606 	val.intvalue = data->num_uids;
607 	AsnWrite (stream, TYPEDATA_num_uids, &val);
608 	val.intvalue = data->minuid;
609 	AsnWrite (stream, TYPEDATA_minuid, &val);
610 	val.intvalue = data->maxuid;
611 	AsnWrite (stream, TYPEDATA_maxuid, &val);
612 	val.intvalue = data->num_bucket;
613 	AsnWrite (stream, TYPEDATA_num_bucket, &val);
614 	AsnStartStruct(stream, TYPEDATA_fields);
615 	for (i=0; i<_fld_ct; ++i)
616 		FieldDataAsnWrite (&data->fields[i], stream, TYPEDATA_fields_E);
617 	AsnEndStruct(stream, TYPEDATA_fields);
618 
619 	if (! AsnEndStruct(stream, atp))
620 		goto erret;
621 
622 	retval = TRUE;
623 
624 erret:
625 	AsnUnlinkType(type_start); /* unlink local tree */
626 	return retval;
627 }
628 
629 
630 /* ========== EntrezTypeInfo ========== */
631 
EntrezTypeInfo_AsnRead(EntrezTypeInfo * tinf,AsnIo * stream,AsnType * type0)632 static EntrezTypeInfo* EntrezTypeInfo_AsnRead (EntrezTypeInfo *tinf, AsnIo *stream, AsnType *type0)
633 {
634 	AsnType *type = type0;
635 	DataVal val;
636 	while ((type = AsnReadId(stream,amp,type)) != type0)
637 	{
638 		AsnReadVal(stream,type,&val);
639 		if (type == TYPE_INFO_id)
640 			tinf->id = (int) val.intvalue;
641 		else if (type == TYPE_INFO_tag) {
642 			strcpy(tinf->tag,(char*)val.ptrvalue);
643 			MemFree((char*)val.ptrvalue);
644 		} else if (type == TYPE_INFO_name)
645 			tinf->name = (char*) val.ptrvalue;
646 		else if (type == TYPE_INFO_descr)
647 			tinf->descr = (char*) val.ptrvalue;
648 		else if (type == TYPE_INFO_asntype)
649 			tinf->asntype = (char*) val.ptrvalue;
650 		else
651 			AsnKillValue(type,&val);
652 	}
653 	AsnReadVal(stream,type,NULL);   /* END STRUCT */
654 	return tinf;
655 }
656 
EntrezTypeInfo_AsnWrite(const EntrezTypeInfo * tinf,AsnIo * stream,AsnType * type)657 static Boolean EntrezTypeInfo_AsnWrite (const EntrezTypeInfo *tinf, AsnIo *stream, AsnType *type)
658 {
659 	ASSERT(tinf != NULL);
660 	ASSERT(stream != NULL);
661 
662 	if (AsnStartStruct(stream,type))
663 	{
664 		Boolean retval = TRUE;
665 		Integer_AsnWrite(tinf->id,stream,TYPE_INFO_id,retval);
666 		String_AsnWrite(tinf->tag,stream,TYPE_INFO_tag,retval);
667 		String_AsnWrite(tinf->name,stream,TYPE_INFO_name,retval);
668 		String_AsnWrite(tinf->descr,stream,TYPE_INFO_descr,retval);
669 		String_AsnWrite(tinf->asntype,stream,TYPE_INFO_asntype,retval);
670 		if (AsnEndStruct(stream,type))
671 			return retval;
672 	}
673 	return FALSE;
674 }
675 
676 
677 /* ========== EntrezFieldInfo ========== */
678 
679 
EntrezFieldInfo_AsnRead(EntrezFieldInfo * fld,AsnIo * stream,AsnType * type0)680 static EntrezFieldInfo* EntrezFieldInfo_AsnRead (EntrezFieldInfo *fld, AsnIo *stream, AsnType *type0)
681 {
682 	AsnType *type = type0;
683 	DataVal val;
684 	while ((type = AsnReadId(stream,amp,type)) != type0)
685 	{
686 		AsnReadVal(stream,type,&val);
687 		if (type == FIELD_INFO_id)
688 			fld->id = (int) val.intvalue;
689 		else if (type == FIELD_INFO_tag)
690 			strcpy(fld->tag,(char*)val.ptrvalue);
691 		else if (type == FIELD_INFO_name)
692 			fld->name = (char*) val.ptrvalue;
693 		else if (type == FIELD_INFO_descr)
694 			fld->descr = (char*) val.ptrvalue;
695 		else if (type == FIELD_INFO_single_token)
696 			fld->single_token = (unsigned) val.boolvalue;
697 		else if (type == FIELD_INFO_has_special)
698 			fld->has_special = (unsigned) val.boolvalue;
699 		else if (type == FIELD_INFO_hier_avail)
700 			fld->hier_avail = (unsigned) val.boolvalue;
701 		else if (type == FIELD_INFO_hier_id)
702 			fld->hier_id = (int) val.intvalue;
703 		else if (type == FIELD_INFO_post_type)
704 			fld->post_type = (PostType) val.intvalue;
705 		else
706 			AsnKillValue(type,&val);
707 	}
708 	AsnReadVal(stream,type,NULL);   /* END STRUCT */
709 	return fld;
710 }
711 
EntrezFieldInfo_AsnWrite(const EntrezFieldInfo * fld,AsnIo * stream,AsnType * type)712 static Boolean EntrezFieldInfo_AsnWrite (const EntrezFieldInfo *fld, AsnIo *stream, AsnType *type)
713 {
714 	ASSERT(fld != NULL);
715 	ASSERT(stream != NULL);
716 
717 	if (AsnStartStruct(stream,type))
718 	{
719 		Boolean retval = TRUE;
720 		Integer_AsnWrite(fld->id,stream,FIELD_INFO_id,retval);
721 		String_AsnWrite(fld->tag,stream,FIELD_INFO_tag,retval);
722 		String_AsnWrite(fld->name,stream,FIELD_INFO_name,retval);
723 		String_AsnWrite(fld->descr,stream,FIELD_INFO_descr,retval);
724 		if (fld->single_token)
725 			Boolean_AsnWrite(fld->single_token,stream,FIELD_INFO_single_token,retval);
726 		if (fld->has_special)
727 			Boolean_AsnWrite(fld->has_special,stream,FIELD_INFO_has_special,retval);
728 		if (fld->hier_avail)
729 		{
730 			Boolean_AsnWrite(fld->hier_avail,stream,FIELD_INFO_hier_avail,retval);
731 			Integer_AsnWrite(fld->hier_id,stream,FIELD_INFO_hier_id,retval);
732 		}
733 		if (fld->post_type != PostType_sort)
734 			Integer_AsnWrite(fld->post_type,stream,FIELD_INFO_post_type,retval);
735 		if (AsnEndStruct(stream,type))
736 			return retval;
737 	}
738 	return FALSE;
739 }
740 
EntrezLinkInfo_AsnRead(EntrezLinkInfo * link,AsnIo * stream,AsnType * type0)741 static EntrezLinkInfo* EntrezLinkInfo_AsnRead (EntrezLinkInfo *link, AsnIo *stream, AsnType *type0)
742 {
743   AsnType *type = type0;
744   DataVal val;
745   while ((type = AsnReadId(stream,amp,type)) != type0)
746     {
747       AsnReadVal(stream,type,&val);
748       if (type == LINK_INFO_id)
749 	link->id = (int) val.intvalue;
750       else if (type == LINK_INFO_tag)
751 	strcpy(link->tag,(char*)val.ptrvalue);
752       else if (type == LINK_INFO_name)
753 	link->name = (char*) val.ptrvalue;
754       else if (type == LINK_INFO_descr)
755 	link->descr = (char*) val.ptrvalue;
756       else if (type == LINK_INFO_dbfrom)
757 	link->dbfrom = (int) val.intvalue;
758       else if (type == LINK_INFO_dbto)
759 	link->dbto = (int) val.intvalue;
760       else if (type == LINK_INFO_reciprocal)
761 	link->reciprocal = (int) val.intvalue;
762       else if (type == LINK_INFO_datasize)
763 	link->datasize = (int) val.intvalue;
764       else
765 	AsnKillValue(type,&val);
766     }
767   AsnReadVal(stream,type,NULL);   /* END STRUCT */
768   return link;
769 }
770 
EntrezLinkInfo_AsnWrite(const EntrezLinkInfo * link,AsnIo * stream,AsnType * type)771 static Boolean EntrezLinkInfo_AsnWrite (const EntrezLinkInfo *link, AsnIo *stream, AsnType *type)
772 {
773   ASSERT(link != NULL);
774   ASSERT(stream != NULL);
775 
776   if (AsnStartStruct(stream,type))
777     {
778       Boolean retval = TRUE;
779       Integer_AsnWrite(link->id,stream,LINK_INFO_id,retval);
780       String_AsnWrite(link->tag,stream,LINK_INFO_tag,retval);
781       String_AsnWrite(link->name,stream,LINK_INFO_name,retval);
782       String_AsnWrite(link->descr,stream,LINK_INFO_descr,retval);
783       Integer_AsnWrite(link->dbfrom,stream,LINK_INFO_dbfrom,retval);
784       Integer_AsnWrite(link->dbto,stream,LINK_INFO_dbto,retval);
785       Integer_AsnWrite(link->datasize,stream,LINK_INFO_datasize,retval);
786       Integer_AsnWrite(link->reciprocal,stream,LINK_INFO_reciprocal,retval);
787       if (AsnEndStruct(stream,type))
788 	return retval;
789     }
790   return FALSE;
791 }
792 
793 
794 /* ========== EntrezDivInfo ========== */
795 
EntrezDivInfo_Construct(EntrezDivInfo * div,int type_ct)796 static EntrezDivInfo* EntrezDivInfo_Construct (EntrezDivInfo *div, int type_ct)
797 {
798 	if (div != NULL)
799 	{
800 		memset((void*)div,0,sizeof(EntrezDivInfo));
801 		div->docs = (long*) MemNew(sizeof(long) * (size_t)type_ct);
802 	}
803 	return div;
804 }
805 
EntrezDivInfo_Destruct(EntrezDivInfo * div)806 static EntrezDivInfo* EntrezDivInfo_Destruct (EntrezDivInfo *div)
807 {
808 	if (div != NULL)
809 	{
810 		MemFree((void*)div->docs);
811 		div->docs = NULL;
812 	}
813 	return div;
814 }
815 
EntrezDivInfo_AsnRead(EntrezDivInfo * div,AsnIo * ain,AsnType * type_start)816 static EntrezDivInfo* EntrezDivInfo_AsnRead (EntrezDivInfo *div,  AsnIo *ain, AsnType *type_start)
817 {
818 	if (div == NULL)
819 		div = (EntrezDivInfo*) MemNew(sizeof(EntrezDivInfo));
820 	if (div != NULL)
821 	{
822 		DataVal val;
823 		AsnType *atp = type_start;
824 		int i;
825 		while ((atp = AsnReadId(ain,amp,atp)) != type_start)
826 		{
827 			AsnReadVal(ain,atp,&val);
828 
829 			if (atp == DIV_INFO_tag)
830 			{
831 				/* memcpy((void*)div->tag,val.ptrvalue,3); */
832 				Nlm_StringNCpy_0 (div->tag, val.ptrvalue, sizeof (div->tag));
833 				div->tag[3] = '\0';
834 			}
835 			else if (atp == DIV_INFO_descr)
836 			{
837 				const char *str = (char*) val.ptrvalue;
838 				div->descr = (str && *str) ? StrSave(str) : NULL;
839 			}
840 			else if (atp == DIV_INFO_reldate)
841 			{
842 				const char *str = (char*) val.ptrvalue;
843 				div->reldate = (str && *str) ? StrSave(str) : NULL;
844 			}
845 			else if (atp == DIV_INFO_date)
846 			{
847 				CdDate_AsnRead(&div->date,ain,atp);
848 			}
849 			else if (atp == DIV_INFO_docs)
850 			{
851 				ASSERT(div->docs != NULL);
852 				i = 0;
853 			}
854 			else if (atp == DIV_INFO_docs_E)
855 			{
856 				div->docs[i++] = val.intvalue;
857 			}
858 			else
859 			{
860 				AsnKillValue(atp,&val);
861 			}
862 		}
863 		AsnReadVal(ain,atp,NULL);   /* END STRUCT */
864 	}
865 	return div;
866 }
867 
EntrezDivInfo_AsnWrite(const EntrezDivInfo * div,AsnIo * stream,AsnType * type)868 static Boolean EntrezDivInfo_AsnWrite (const EntrezDivInfo *div,  AsnIo *stream, AsnType *type)
869 {
870 	ASSERT(div != NULL);
871 	ASSERT(stream != NULL);
872 
873 	if (AsnStartStruct(stream,type))
874 	{
875 		Boolean retval = TRUE;
876 		String_AsnWrite(div->tag,stream,DIV_INFO_tag,retval);
877 		String_AsnWrite(div->descr,stream,DIV_INFO_descr,retval);
878 		String_AsnWrite(div->reldate,stream,DIV_INFO_reldate,retval);
879 		CdDate_AsnWrite(&(div->date),stream,DIV_INFO_date);
880 		if (div->docs != NULL)
881 		{
882 			int i;
883 			AsnStartStruct(stream,DIV_INFO_docs);
884 			for (i=0; i<_type_ct; ++i)
885 				Integer_AsnWrite(div->docs[i],stream,DIV_INFO_docs_E,retval);
886 			AsnEndStruct(stream,DIV_INFO_docs);
887 		}
888 		if (AsnEndStruct(stream,type))
889 			return TRUE;
890 	}
891 	return FALSE;
892 }
893 
894 
895 /* ========== CdDate ========== */
896 
CdDate_AsnRead(CdDate * date,AsnIo * stream,AsnType * type_start)897 static CdDate * CdDate_AsnRead (CdDate *date, AsnIo *stream, AsnType *type_start)
898 {
899 	AsnType *type = type_start;
900 	DataVal val;
901 	while ((type = AsnReadId(stream,amp,type)) != type_start)
902 	{
903 		AsnReadVal(stream,type,&val);
904 		if (type == CD_DATE_year)
905 			date->year = (unsigned) val.intvalue;
906 		else if (type == CD_DATE_month)
907 			date->month = (unsigned) val.intvalue;
908 		else if (type == CD_DATE_day)
909 			date->day = (unsigned) val.intvalue;
910 		else
911 			AsnKillValue(type,&val);
912 	}
913 	AsnReadVal(stream,type,NULL);   /* END STRUCT */
914 	return date;
915 }
916 
CdDate_AsnWrite(const CdDate * date,AsnIo * stream,AsnType * type)917 static Boolean CdDate_AsnWrite (const CdDate *date, AsnIo *stream, AsnType *type)
918 {
919 	ASSERT(date != NULL);
920 	ASSERT(stream != NULL);
921 
922 	if (AsnStartStruct(stream,type))
923 	{
924 		Boolean retval = TRUE;
925 		Integer_AsnWrite(date->year,stream,CD_DATE_year,retval);
926 		Integer_AsnWrite(date->month,stream,CD_DATE_month,retval);
927 		Integer_AsnWrite(date->day,stream,CD_DATE_day,retval);
928 		if (AsnEndStruct(stream,type))
929 			return retval;
930 	}
931 	return FALSE;
932 }
933 
934 
935 
936 /**************************************************
937 *
938 *    DocSumNew()
939 *
940 **************************************************/
941 
DocSumNew(void)942 NLM_EXTERN DocSumPtr LIBCALL DocSumNew(void)
943 {
944    DocSumPtr ptr = MemNew((size_t) sizeof(DocSum));
945 
946    ptr -> no_abstract = 0;
947    ptr -> translated_title = 0;
948    ptr -> no_authors = 0;
949    ptr -> non_document = 0;
950    ptr -> is_segmented = 0;
951    ptr -> is_partial = 0;
952    ptr->entrezDate = 0;
953    ptr->pStatus = ptr->pLanguage = ptr->pPubType = NULL;
954    return ptr;
955 
956 }
957 
958 
959 /**************************************************
960 *
961 *    DocSumAsnRead()
962 *
963 **************************************************/
964 
DocSumAsnRead(AsnIoPtr aip,AsnTypePtr orig)965 NLM_EXTERN DocSumPtr LIBCALL DocSumAsnRead(AsnIoPtr aip, AsnTypePtr orig)
966 {
967    DataVal av;
968    AsnTypePtr atp;
969    Boolean isError = FALSE;
970    AsnReadFunc func;
971    DocSumPtr ptr;
972 
973    if (aip == NULL) {
974       return NULL;
975    }
976 
977    if (orig == NULL) {         /* DocSum ::= (self contained) */
978       atp = AsnReadId(aip, amp, DOCSUM);
979    } else {
980       atp = AsnLinkType(orig, DOCSUM);
981    }
982    /* link in local tree */
983    if (atp == NULL) {
984       return NULL;
985    }
986 
987    ptr = DocSumNew();
988    if (ptr == NULL) {
989       goto erret;
990    }
991    if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
992       goto erret;
993    }
994 
995    atp = AsnReadId(aip,amp, atp);
996    func = NULL;
997 
998    if (atp == DOCSUM_no_abstract) {
999       if ( AsnReadVal(aip, atp, &av) <= 0) {
1000          goto erret;
1001       }
1002       ptr -> no_abstract = av.boolvalue;
1003       atp = AsnReadId(aip,amp, atp);
1004    }
1005    if (atp == DOCSUM_translated_title) {
1006       if ( AsnReadVal(aip, atp, &av) <= 0) {
1007          goto erret;
1008       }
1009       ptr -> translated_title = av.boolvalue;
1010       atp = AsnReadId(aip,amp, atp);
1011    }
1012    if (atp == DOCSUM_no_authors) {
1013       if ( AsnReadVal(aip, atp, &av) <= 0) {
1014          goto erret;
1015       }
1016       ptr -> no_authors = av.boolvalue;
1017       atp = AsnReadId(aip,amp, atp);
1018    }
1019    if (atp == DOCSUM_caption) {
1020       if ( AsnReadVal(aip, atp, &av) <= 0) {
1021          goto erret;
1022       }
1023       ptr -> caption = av.ptrvalue;
1024       atp = AsnReadId(aip,amp, atp);
1025    }
1026    if (atp == DOCSUM_title) {
1027       if ( AsnReadVal(aip, atp, &av) <= 0) {
1028          goto erret;
1029       }
1030       ptr -> title = av.ptrvalue;
1031       atp = AsnReadId(aip,amp, atp);
1032    }
1033    if (atp == DOCSUM_extra) {
1034       if ( AsnReadVal(aip, atp, &av) <= 0) {
1035          goto erret;
1036       }
1037       ptr -> extra = av.ptrvalue;
1038       atp = AsnReadId(aip,amp, atp);
1039    }
1040    if (atp == DOCSUM_non_document) {
1041       if ( AsnReadVal(aip, atp, &av) <= 0) {
1042          goto erret;
1043       }
1044       ptr -> non_document = av.boolvalue;
1045       atp = AsnReadId(aip,amp, atp);
1046    }
1047    if (atp == DOCSUM_is_segmented) {
1048       if ( AsnReadVal(aip, atp, &av) <= 0) {
1049          goto erret;
1050       }
1051       ptr -> is_segmented = av.boolvalue;
1052       atp = AsnReadId(aip,amp, atp);
1053    }
1054    if (atp == DOCSUM_is_partial) {
1055       if ( AsnReadVal(aip, atp, &av) <= 0) {
1056          goto erret;
1057       }
1058       ptr -> is_partial = av.boolvalue;
1059       atp = AsnReadId(aip,amp, atp);
1060    }
1061    if (atp == DOCSUM_create) {
1062       if ( AsnReadVal(aip, atp, &av) <= 0) {
1063          goto erret;
1064       }
1065       CdDate_AsnRead(&ptr->create, aip, atp);
1066       if (aip -> io_failure) {
1067          goto erret;
1068       }
1069       atp = AsnReadId(aip,amp, atp);
1070    }
1071    if (atp == DOCSUM_modify) {
1072       if ( AsnReadVal(aip, atp, &av) <= 0) {
1073          goto erret;
1074       }
1075       CdDate_AsnRead(&ptr->modify, aip, atp);
1076       if (aip -> io_failure) {
1077          goto erret;
1078       }
1079       atp = AsnReadId(aip,amp, atp);
1080    }
1081    if (atp == DOCSUM_link_count) {
1082       Int2 index = 0;
1083 
1084       AsnReadVal(aip, atp, &av);
1085       while ((atp = AsnReadId(aip, amp, atp)) == DOCSUM_link_count_E)
1086       {
1087 	  AsnReadVal(aip, atp, &av);
1088 	  ptr -> link_count[index++] = (short) av.intvalue;
1089       }
1090       AsnReadVal(aip, atp, &av);
1091       atp = AsnReadId(aip,amp, atp);
1092    }
1093    if (atp == DOCSUM_uid) {
1094       if ( AsnReadVal(aip, atp, &av) <= 0) {
1095          goto erret;
1096       }
1097       ptr -> uid = av.intvalue;
1098       atp = AsnReadId(aip,amp, atp);
1099    }
1100    if (atp == DOCSUM_not_yet_neighbored) {
1101       if ( AsnReadVal(aip, atp, &av) <= 0) {
1102          goto erret;
1103       }
1104       ptr -> not_yet_neighbored = av.boolvalue;
1105       atp = AsnReadId(aip,amp, atp);
1106    }
1107 
1108    if (AsnReadVal(aip, atp, &av) <= 0) {
1109       goto erret;
1110    }
1111    /* end struct */
1112 
1113 ret:
1114    AsnUnlinkType(orig);       /* unlink local tree */
1115    return ptr;
1116 
1117 erret:
1118    aip -> io_failure = TRUE;
1119    ptr = DocSumFree(ptr);
1120    goto ret;
1121 }
1122 
1123 
1124 
1125 /**************************************************
1126 *
1127 *    DocSumAsnWrite()
1128 *
1129 **************************************************/
DocSumAsnWrite(DocSumPtr ptr,AsnIoPtr aip,AsnTypePtr orig)1130 NLM_EXTERN Boolean LIBCALL DocSumAsnWrite(DocSumPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
1131 {
1132    DataVal av;
1133    AsnTypePtr atp;
1134    Boolean retval = FALSE;
1135    Int2 index;
1136 
1137    if (aip == NULL) {
1138       return FALSE;
1139    }
1140 
1141    atp = AsnLinkType(orig, DOCSUM);   /* link local tree */
1142    if (atp == NULL) {
1143       return FALSE;
1144    }
1145 
1146    if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
1147    if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
1148       goto erret;
1149    }
1150 
1151    av.boolvalue = ptr -> no_abstract;
1152    if (av.boolvalue) retval = AsnWrite(aip, DOCSUM_no_abstract,  &av);
1153    av.boolvalue = ptr -> translated_title;
1154    if (av.boolvalue) retval = AsnWrite(aip, DOCSUM_translated_title,  &av);
1155    av.boolvalue = ptr -> no_authors;
1156    if (av.boolvalue) retval = AsnWrite(aip, DOCSUM_no_authors,  &av);
1157    if (ptr -> caption != NULL) {
1158       av.ptrvalue = ptr -> caption;
1159       retval = AsnWrite(aip, DOCSUM_caption,  &av);
1160    }
1161    if (ptr -> title != NULL) {
1162       av.ptrvalue = ptr -> title;
1163       retval = AsnWrite(aip, DOCSUM_title,  &av);
1164    }
1165    if (ptr -> extra != NULL) {
1166       av.ptrvalue = ptr -> extra;
1167       retval = AsnWrite(aip, DOCSUM_extra,  &av);
1168    }
1169    av.boolvalue = ptr -> non_document;
1170    if (av.boolvalue) retval = AsnWrite(aip, DOCSUM_non_document,  &av);
1171    av.boolvalue = ptr -> is_segmented;
1172    if (av.boolvalue) retval = AsnWrite(aip, DOCSUM_is_segmented,  &av);
1173    av.boolvalue = ptr -> is_partial;
1174    if (av.boolvalue) retval = AsnWrite(aip, DOCSUM_is_partial,  &av);
1175    if ( ! CdDate_AsnWrite(&ptr -> create, aip, DOCSUM_create)) {
1176       goto erret;
1177    }
1178    if ( ! CdDate_AsnWrite(&ptr -> modify, aip, DOCSUM_modify)) {
1179       goto erret;
1180    }
1181 
1182    for (index = 0; index < DocType_MAX; index++)
1183    {
1184        if (ptr->link_count[index] != 0)
1185        {
1186 	   break;
1187        }
1188    }
1189 
1190    if (index < DocType_MAX)
1191    { /* some non-zero links */
1192        AsnStartStruct(aip, DOCSUM_link_count);
1193        for (index = 0; index < DocType_MAX; index++)
1194        {
1195            av.intvalue = ptr->link_count[index];
1196            AsnWrite(aip, DOCSUM_link_count_E, &av);
1197        }
1198        AsnEndStruct(aip, DOCSUM_link_count);
1199    }
1200 
1201    av.intvalue = ptr -> uid;
1202    if (av.intvalue != 0) retval = AsnWrite(aip, DOCSUM_uid,  &av);
1203 
1204    av.boolvalue = ptr -> not_yet_neighbored;
1205    if (av.boolvalue) retval = AsnWrite(aip, DOCSUM_not_yet_neighbored,  &av);
1206 
1207    if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
1208       goto erret;
1209    }
1210    retval = TRUE;
1211 
1212 erret:
1213    AsnUnlinkType(orig);       /* unlink local tree */
1214    return retval;
1215 }
1216 
1217 
1218 /*****************************************************************************
1219 *
1220 *   DocSumFree(dsp)
1221 *
1222 *****************************************************************************/
DocSumFree(DocSumPtr dsp)1223 NLM_EXTERN DocSumPtr LIBCALL DocSumFree (DocSumPtr dsp)
1224 {
1225     if (dsp == NULL)
1226         return NULL;
1227     MemFree(dsp->caption);
1228     MemFree(dsp->title);
1229     MemFree(dsp->extra);
1230     MemFree(dsp->pStatus);
1231     MemFree(dsp->pLanguage);
1232     MemFree(dsp->pPubType);
1233     return ((DocSumPtr) MemFree(dsp));
1234 }
1235 
1236