NCBI C Toolkit Cross Reference

C/object/objprt.c


  1 /*  objprt.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:  objprt.c
 27 *
 28 * Author:  James Ostell
 29 *   
 30 * Version Creation Date: 4/1/94
 31 *
 32 * $Revision: 6.2 $
 33 *
 34 * File Description:  Object manager for print templates
 35 *
 36 * Modifications:  
 37 * --------------------------------------------------------------------------
 38 * Date     Name        Description of modification
 39 * -------  ----------  -----------------------------------------------------
 40 *
 41 *
 42 * $Log: objprt.c,v $
 43 * Revision 6.2  1998/08/26 17:43:18  kans
 44 * fixed -v -fd warnings in label functions
 45 *
 46 * Revision 6.1  1998/08/24 18:28:07  kans
 47 * removed solaris -v -fd warnings
 48 *
 49 * Revision 6.0  1997/08/25 18:50:22  madden
 50 * Revision changed to 6.0
 51 *
 52 * Revision 4.2  1997/06/19 18:41:42  vakatov
 53 * [WIN32,MSVC++]  Adopted for the "NCBIOBJ.LIB" DLL'ization
 54 *
 55 * Revision 4.1  1995/10/30 18:38:13  kans
 56 * changed true and false fields to truepfb and falsepfb (CodeWarrior error)
 57 *
 58  * Revision 4.0  1995/07/26  13:48:06  ostell
 59  * force revision to 4.0
 60  *
 61  * Revision 3.1  1995/05/15  21:22:00  ostell
 62  * added Log line
 63  *
 64 *
 65 *
 66 * ==========================================================================
 67 */
 68 
 69 /** for ErrPostEx() ****/
 70 
 71 static char *this_module = "ncbiobj";
 72 #define THIS_MODULE this_module
 73 static char *this_file = __FILE__;
 74 #define THIS_FILE this_file
 75 
 76 /**********************/
 77 
 78 #include <objprt.h>
 79 #include <asnprt.h>
 80 
 81 static Boolean loaded = FALSE;
 82 
 83 static PrintTemplatePtr PNTR PTlist = NULL;   /* loaded Templates  */
 84 static Int2 PTnum = 0;              /* sizeof PTlist */
 85 
 86 NLM_EXTERN Boolean LIBCALL ObjPrtAsnLoad(void)
 87 {
 88 
 89         if ( ! loaded) {
 90 
 91                 if ( ! AsnLoad ())
 92                         return FALSE;
 93                 loaded = TRUE;
 94         }
 95 
 96         return TRUE;
 97 }
 98 
 99 /**************************************************
100 *
101 *    PrintTemplateNew()
102 *
103 **************************************************/
104 
105 NLM_EXTERN PrintTemplatePtr LIBCALL PrintTemplateNew(void)
106 {
107         PrintTemplatePtr ptp;
108         PrintTemplatePtr PNTR tmp;
109         Int2 i;
110 
111         ptp = (PrintTemplatePtr) MemNew(sizeof(PrintTemplate));
112         if (ptp == NULL) return ptp;
113 
114     for (i = 0; i < PTnum; i++)    /* add to Template list */
115     {
116         if (PTlist[i] == NULL)
117         {
118             PTlist[i] = ptp;
119             return ptp;
120         }
121     }
122     tmp = PTlist;                 /* expand list as necessary */
123     PTlist = MemNew((sizeof(PrintTemplatePtr) * (PTnum + 20)));
124         if (PTlist == NULL)
125         {
126                 PTlist = tmp;
127                 return (PrintTemplatePtr)MemFree(ptp);
128         }
129 
130     MemCopy(PTlist, tmp, (size_t)(sizeof(PrintTemplatePtr) * PTnum));
131     MemFree(tmp);
132     PTlist[PTnum] = ptp;
133     PTnum += 20;
134         return ptp;
135 }
136 
137 /**************************************************
138 *
139 *    PrintTemplateFree()
140 *
141 **************************************************/
142 NLM_EXTERN PrintTemplatePtr LIBCALL PrintTemplateFree ( PrintTemplatePtr ptr)
143 {
144         Int2 i;
145 
146         if (ptr == NULL) return NULL;
147 
148         MemFree( ptr ->   name);
149         MemFree(ptr -> labelfrom);
150         PrintFormatFree( ptr ->   format);
151     for (i = 0; i < PTnum; i++)
152     {
153         if (PTlist[i] == ptr)
154         {
155             PTlist[i] = NULL;
156             return MemFree(ptr);
157         }
158     }
159     ErrPost(CTX_NCBIOBJ, 1, "PrintTemplateFree: pointer not in PTlist");
160         return MemFree(ptr);
161 }
162 
163 /*****************************************************************************
164 *
165 *   PrintTemplateFreeAll()
166 *       frees all PrintTemplates in memory
167 *
168 *****************************************************************************/
169 NLM_EXTERN void LIBCALL PrintTemplateFreeAll(void)
170 {
171     Int2 i;
172 
173     for (i = 0; i < PTnum; i++)
174     {
175                 PrintTemplateFree(PTlist[i]);
176     }
177 }
178 
179 /*****************************************************************************
180 *
181 *   PrintTemplateInMem(&ptnum)
182 *
183 *****************************************************************************/
184 NLM_EXTERN PrintTemplatePtr PNTR LIBCALL PrintTemplateInMem (Int2Ptr numptr)
185 
186 {
187         *numptr = PTnum;
188         if (! PTnum)
189                 return NULL;
190         else
191                 return PTlist;
192 }
193 
194 /**************************************************
195 *
196 *    PrintTemplateAsnRead()
197 *
198 **************************************************/
199 NLM_EXTERN PrintTemplatePtr LIBCALL PrintTemplateAsnRead ( AsnIoPtr aip, AsnTypePtr orig)
200 {
201         DataVal av;
202         AsnTypePtr atp;
203         PrintTemplatePtr ptr;
204 
205         if (aip == NULL) return NULL;
206 
207 
208         if ( ! loaded){
209                 if ( ! ObjPrtAsnLoad ())
210                         goto erret;
211                 
212         }
213         if (orig == NULL)
214                 atp = AsnReadId(aip, amp, PRINTTEMPLATE);
215         else
216                 atp = AsnLinkType(orig, PRINTTEMPLATE);
217         if(atp == NULL) return NULL;
218 
219         ptr = PrintTemplateNew();
220         if (ptr == NULL) goto erret;
221 
222         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
223 
224         atp = AsnReadId(aip,amp, atp);
225         if (atp == PRINTTEMPLATE_name){
226                 if (AsnReadVal(aip, atp, &av) <= 0)
227                         goto erret;
228                 ptr->name = (CharPtr)av.ptrvalue;
229                 atp = AsnReadId(aip,amp, atp);
230          }
231         if (atp == PRINTTEMPLATE_labelfrom){
232                 if (AsnReadVal(aip, atp, &av) <= 0)
233                         goto erret;
234                 ptr->labelfrom = (CharPtr)av.ptrvalue;
235                 atp = AsnReadId(aip,amp, atp);
236         }
237         if (atp == PRINTTEMPLATE_format){
238                 ptr -> format =PrintFormatAsnRead(aip, atp);
239                 if (ptr -> format == NULL) goto erret;
240                 atp = AsnReadId(aip,amp, atp);
241          }
242         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
243 ret:
244         AsnUnlinkType(orig);
245         return ptr;
246 erret:
247         ptr=PrintTemplateFree(ptr);
248         goto ret;
249 }
250 
251 /**************************************************
252 *
253 *    PrintTemplateAsnWrite()
254 *
255 **************************************************/
256 NLM_EXTERN Boolean LIBCALL PrintTemplateAsnWrite (PrintTemplatePtr ptr,  AsnIoPtr aip, AsnTypePtr orig)
257 {
258         Boolean retval = FALSE;
259         DataVal av;
260         AsnTypePtr atp;
261 
262         if (aip == NULL) return FALSE;
263 
264 
265         if ( ! loaded){
266         if (! ObjPrtAsnLoad()) goto erret;
267         
268 }
269         atp = AsnLinkType(orig, PRINTTEMPLATE);
270         if(atp == NULL) {AsnNullValueMsg(aip,atp); goto erret;}
271         if (! AsnOpenStruct (aip, atp, (Pointer) ptr)) goto erret;
272 
273         if (ptr ->  name != NULL){
274                 av.ptrvalue = (Pointer) ptr -> name;
275                 if ( ! AsnWrite(aip,PRINTTEMPLATE_name, &av)) goto erret;
276         }
277         if (ptr -> labelfrom != NULL){
278                 av.ptrvalue = (Pointer) ptr -> labelfrom;
279                 if ( ! AsnWrite(aip,PRINTTEMPLATE_labelfrom, &av)) goto erret;
280         }
281         if (ptr ->  format != NULL){
282                 if ( ! PrintFormatAsnWrite(ptr -> format, aip, PRINTTEMPLATE_format))
283                         goto erret;
284         }
285         if (! AsnCloseStruct (aip, atp, (Pointer) ptr)) goto erret;
286         retval = TRUE;
287 erret:AsnUnlinkType(orig);
288         return retval;
289 }
290 
291 /**************************************************
292 *
293 *    PrintTemplateSetAsnRead()
294 *
295 **************************************************/
296 NLM_EXTERN Boolean LIBCALL PrintTemplateSetAsnRead ( AsnIoPtr aip )
297 {
298         DataVal av;
299         AsnTypePtr atp, oldatp;
300         PrintTemplatePtr ptr;
301 
302         if (aip == NULL) return FALSE;
303 
304         if ( ! loaded){
305                 if ( ! ObjPrtAsnLoad ())
306                         goto erret;
307                 
308         }
309 
310         atp = AsnReadId(aip, amp, PRINTTEMPLATESET);
311         if(atp == NULL) return FALSE;
312         oldatp = atp;
313 
314         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
315 
316         while ((atp = AsnReadId(aip,amp, atp)) != oldatp)
317         {
318                 ptr = PrintTemplateAsnRead(aip, atp);
319                 if (ptr == NULL) goto erret;
320         }
321         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
322 
323         return TRUE;
324 erret:
325         return FALSE;
326 }
327 
328 /**************************************************
329 *
330 *    PrintFormatNew()
331 *
332 **************************************************/
333 
334 NLM_EXTERN PrintFormatPtr LIBCALL PrintFormatNew(void)
335 {
336 
337         return (PrintFormatPtr) MemNew(sizeof(PrintFormat));
338 
339 }
340 
341 /**************************************************
342 *
343 *    PrintFormatFree()
344 *
345 **************************************************/
346 NLM_EXTERN PrintFormatPtr LIBCALL PrintFormatFree ( PrintFormatPtr head_ptr)
347 {
348          PrintFormatPtr ptr, hold_ptr;
349 
350         if (head_ptr == NULL) return NULL;
351 
352         for (ptr = head_ptr; ptr; ptr = hold_ptr){
353                 hold_ptr = ptr -> next;
354                 MemFree(ptr -> asn1);
355                 MemFree(ptr -> label);
356                 MemFree(ptr -> prefix);
357                 MemFree(ptr -> suffix);
358                 PrintFormFree( ptr ->   form);
359                 MemFree(ptr);
360          }
361         return NULL;
362 }
363 
364 /**************************************************
365 *
366 *    PrintFormatAsnRead()
367 *
368 **************************************************/
369 NLM_EXTERN PrintFormatPtr LIBCALL PrintFormatAsnRead ( AsnIoPtr aip, AsnTypePtr orig)
370 {
371         DataVal av;
372         AsnTypePtr atp;
373         PrintFormatPtr ptr;
374 
375         if (aip == NULL) return NULL;
376 
377 
378         if ( ! loaded){
379                 if ( ! ObjPrtAsnLoad ())
380                         goto erret;
381                 
382         }
383         if (orig == NULL)
384                 atp = AsnReadId(aip, amp, PRINTFORMAT);
385         else
386                 atp = AsnLinkType(orig, PRINTFORMAT);
387         if(atp == NULL) return NULL;
388 
389         ptr = PrintFormatNew();
390         if (ptr == NULL) goto erret;
391 
392         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
393 
394         atp = AsnReadId(aip,amp, atp);
395         if (atp == PRINTFORMAT_asn1){
396                 if (AsnReadVal(aip, atp, &av) <= 0)
397                         goto erret;
398                 ptr->asn1 = (CharPtr)av.ptrvalue;
399                 atp = AsnReadId(aip,amp, atp);
400         }
401         if (atp == PRINTFORMAT_label){
402                 if (AsnReadVal(aip, atp, &av) <= 0)
403                         goto erret;
404                 ptr->label = (CharPtr)av.ptrvalue;
405                 atp = AsnReadId(aip,amp, atp);
406         }
407         if (atp == PRINTFORMAT_prefix){
408                 if (AsnReadVal(aip, atp, &av) <= 0)
409                         goto erret;
410                 ptr->prefix = (CharPtr)av.ptrvalue;
411                 atp = AsnReadId(aip,amp, atp);
412         }
413         if (atp == PRINTFORMAT_suffix){
414                 if (AsnReadVal(aip, atp, &av) <= 0)
415                         goto erret;
416                 ptr->suffix = (CharPtr)av.ptrvalue;
417                 atp = AsnReadId(aip,amp, atp);
418         }
419         if (atp == PRINTFORMAT_form){
420                 ptr -> form =PrintFormAsnRead(aip, atp);
421                 if (ptr -> form == NULL) goto erret;
422                 atp = AsnReadId(aip,amp, atp);
423          }
424         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
425 ret:
426         AsnUnlinkType(orig);
427         return ptr;
428 erret:
429         ptr=PrintFormatFree(ptr);
430         goto ret;
431 }
432 
433 /**************************************************
434 *
435 *    PrintFormatAsnWrite()
436 *
437 **************************************************/
438 NLM_EXTERN Boolean LIBCALL PrintFormatAsnWrite (PrintFormatPtr ptr,  AsnIoPtr aip, AsnTypePtr orig)
439 {
440         Boolean retval = FALSE;
441         DataVal av;
442         AsnTypePtr atp;
443 
444         if (aip == NULL) return FALSE;
445 
446 
447         if ( ! loaded){
448         if (! ObjPrtAsnLoad()) goto erret;
449         
450 }
451         atp = AsnLinkType(orig, PRINTFORMAT);
452         if(atp == NULL) {AsnNullValueMsg(aip,atp); goto erret;}
453         if (! AsnOpenStruct (aip, atp, (Pointer) ptr)) goto erret;
454 
455         if (ptr -> asn1 != NULL){
456                 av.ptrvalue = (Pointer) ptr -> asn1;
457                 if ( ! AsnWrite(aip,PRINTFORMAT_asn1, &av)) goto erret;
458         }
459         if (ptr -> label != NULL){
460                 av.ptrvalue = (Pointer) ptr -> label;
461                 if ( ! AsnWrite(aip,PRINTFORMAT_label, &av)) goto erret;
462         }
463         if (ptr -> prefix != NULL){
464                 av.ptrvalue = (Pointer) ptr -> prefix;
465                 if ( ! AsnWrite(aip,PRINTFORMAT_prefix, &av)) goto erret;
466         }
467         if (ptr -> suffix != NULL){
468                 av.ptrvalue = (Pointer) ptr -> suffix;
469                 if ( ! AsnWrite(aip,PRINTFORMAT_suffix, &av)) goto erret;
470         }
471         if (ptr ->  form != NULL){
472                 if ( ! PrintFormAsnWrite(ptr -> form, aip, PRINTFORMAT_form))
473                         goto erret;
474         }
475         if (! AsnCloseStruct (aip, atp, (Pointer) ptr)) goto erret;
476         retval = TRUE;
477 erret:AsnUnlinkType(orig);
478         return retval;
479 }
480 
481 /**************************************************
482 *
483 *    PrintFormFree()
484 *
485 **************************************************/
486 NLM_EXTERN PrintFormPtr LIBCALL PrintFormFree ( PrintFormPtr ptr)
487 {
488         if (ptr == NULL) return NULL;
489 
490         {Pointer pt = ptr -> data.ptrvalue;
491         switch (ptr ->  choice){
492                 case  PrintForm_block :
493                         PrintFormBlockFree(pt);
494                         break;
495                 case  PrintForm_boolean :
496                         PrintFormBooleanFree(pt);
497                         break;
498                 case  PrintForm_enum :
499                         PrintFormEnumFree(pt);
500                         break;
501                 case  PrintForm_text :
502                         PrintFormTextFree(pt);
503                         break;
504                 case  PrintForm_use_template :
505                         MemFree(pt);
506                         break;
507                 case  PrintForm_user :
508                         UserFormatFree(pt);
509                         break;
510         }}
511         MemFree(ptr);
512         return NULL;
513 }
514 
515 /**************************************************
516 *
517 *    PrintFormAsnRead()
518 *
519 **************************************************/
520 NLM_EXTERN PrintFormPtr LIBCALL PrintFormAsnRead ( AsnIoPtr aip, AsnTypePtr orig)
521 {
522         DataVal av;
523         AsnTypePtr atp;
524         ValNodePtr vnp;
525         Uint1 choice ;
526         AsnReadFunc func;
527 
528         if (aip == NULL) return NULL;
529 
530 
531         if ( ! loaded){
532                 if ( ! ObjPrtAsnLoad ())
533                         goto erret;
534                 
535         }
536         if (orig == NULL)
537                 atp = AsnReadId(aip, amp, PRINTFORM);
538         else
539                 atp = AsnLinkType(orig, PRINTFORM);
540         if(atp == NULL) return NULL;
541 
542         vnp = ValNodeNew(NULL);
543         if (vnp == NULL) goto erret;
544         if ( AsnReadVal(aip, atp, &av) <= 0) goto erret;
545         if ( (atp = AsnReadId(aip, amp, atp)) == NULL) goto erret;
546         func = NULL;
547                 if (atp == PRINTFORM_block){
548                         choice = PrintForm_block;
549                         func = (AsnReadFunc) PrintFormBlockAsnRead;
550                 }
551                         else
552                 if (atp == PRINTFORM_boolean){
553                         choice = PrintForm_boolean;
554                         func = (AsnReadFunc) PrintFormBooleanAsnRead;
555                 }
556                         else
557                 if (atp == PRINTFORM_enum){
558                         choice = PrintForm_enum;
559                         func = (AsnReadFunc) PrintFormEnumAsnRead;
560                 }
561                         else
562                 if (atp == PRINTFORM_text){
563                         choice = PrintForm_text;
564                         func = (AsnReadFunc) PrintFormTextAsnRead;
565                 }
566                         else
567                 if (atp == PRINTFORM_use_template){
568                         choice = PrintForm_use_template;
569                         AsnReadVal(aip,atp,&av);
570                         vnp -> data.ptrvalue = av.ptrvalue;
571                 }
572                         else
573                 if (atp == PRINTFORM_user){
574                         choice = PrintForm_user;
575                         func = (AsnReadFunc) UserFormatAsnRead;
576                 }
577                         else
578                 if (atp == PRINTFORM_null){
579                         choice = PrintForm_null;
580                         AsnReadVal(aip,atp,&av);
581                 }
582                 else
583                         goto erret;
584                 vnp -> choice = choice;
585                 if (func != NULL)
586                         vnp -> data.ptrvalue = (*func) (aip,atp);
587 ret:
588         AsnUnlinkType(orig);
589         return vnp;
590 erret:
591         vnp = PrintFormFree(vnp);
592         goto ret;
593 }
594 
595 /**************************************************
596 *
597 *    PrintFormAsnWrite()
598 *
599 **************************************************/
600 NLM_EXTERN Boolean LIBCALL PrintFormAsnWrite (PrintFormPtr ptr,  AsnIoPtr aip, AsnTypePtr orig)
601 {
602         Boolean retval = FALSE;
603         DataVal av;
604         AsnTypePtr atp;
605         AsnWriteFunc func;
606         AsnTypePtr writetype = NULL;
607         Pointer pnt;
608 
609         if (aip == NULL) return FALSE;
610 
611 
612         if ( ! loaded){
613         if (! ObjPrtAsnLoad()) goto erret;
614         
615 }
616         atp = AsnLinkType(orig, PRINTFORM);
617         if(atp == NULL) {AsnNullValueMsg(aip,atp); goto erret;}
618         av.ptrvalue = (Pointer) ptr;
619         if (! AsnWriteChoice(aip, atp, ptr -> choice, & av)) goto erret;
620         pnt = ptr -> data.ptrvalue;
621         av.intvalue = ptr -> data.intvalue;
622         switch (ptr -> choice)
623         {
624                 case  PrintForm_block :
625                         writetype = PRINTFORM_block;
626                         func = (AsnWriteFunc) PrintFormBlockAsnWrite;
627                         break;
628                 case  PrintForm_boolean :
629                         writetype = PRINTFORM_boolean;
630                         func = (AsnWriteFunc) PrintFormBooleanAsnWrite;
631                         break;
632                 case  PrintForm_enum :
633                         writetype = PRINTFORM_enum;
634                         func = (AsnWriteFunc) PrintFormEnumAsnWrite;
635                         break;
636                 case  PrintForm_text :
637                         writetype = PRINTFORM_text;
638                         func = (AsnWriteFunc) PrintFormTextAsnWrite;
639                         break;
640                 case  PrintForm_use_template :
641                         av.ptrvalue = ptr->data.ptrvalue;
642                         retval = AsnWrite(aip, PRINTFORM_use_template, &av);
643                         break;
644                 case  PrintForm_user :
645                         writetype = PRINTFORM_user;
646                         func = (AsnWriteFunc) UserFormatAsnWrite;
647                         break;
648                 case  PrintForm_null :
649                         retval = AsnWrite(aip, PRINTFORM_null, &av); break;
650         }
651         if (writetype != NULL)
652                         retval = (*func) (pnt, aip,writetype);
653 ret:AsnUnlinkType(orig);
654         return retval;
655 erret:
656         retval = FALSE;
657         goto ret;
658 }
659 
660 /**************************************************
661 *
662 *    PrintFormBlockNew()
663 *
664 **************************************************/
665 
666 NLM_EXTERN PrintFormBlockPtr LIBCALL PrintFormBlockNew(void)
667 {
668         return (PrintFormBlockPtr) MemNew(sizeof(PrintFormBlock));
669 }
670 
671 /**************************************************
672 *
673 *    PrintFormBlockFree()
674 *
675 **************************************************/
676 NLM_EXTERN PrintFormBlockPtr LIBCALL PrintFormBlockFree ( PrintFormBlockPtr ptr)
677 {
678         if (ptr == NULL) return NULL;
679 
680         MemFree(ptr -> separator);
681         PrintFormatFree(  ptr -> components);
682         MemFree(ptr);
683         return NULL;
684 }
685 
686 /**************************************************
687 *
688 *    PrintFormBlockAsnRead()
689 *
690 **************************************************/
691 NLM_EXTERN PrintFormBlockPtr LIBCALL PrintFormBlockAsnRead ( AsnIoPtr aip, AsnTypePtr orig)
692 {
693         DataVal av;
694         AsnTypePtr atp;
695         PrintFormBlockPtr ptr;
696 
697         if (aip == NULL) return NULL;
698 
699 
700         if ( ! loaded){
701                 if ( ! ObjPrtAsnLoad ())
702                         goto erret;
703                 
704         }
705         if (orig == NULL)
706                 atp = AsnReadId(aip, amp, PRINTFORMBLOCK);
707         else
708                 atp = AsnLinkType(orig, PRINTFORMBLOCK);
709         if(atp == NULL) return NULL;
710 
711         ptr = PrintFormBlockNew();
712         if (ptr == NULL) goto erret;
713 
714         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
715 
716         atp = AsnReadId(aip,amp, atp);
717         if (atp == PRINTFORMBLOCK_separator){
718                 if (AsnReadVal(aip, atp, &av) <= 0)
719                         goto erret;
720                 ptr->separator = (CharPtr)av.ptrvalue;
721                 atp = AsnReadId(aip,amp, atp);
722         }
723         if (atp == PRINTFORMBLOCK_components)
724         {
725                 AsnTypePtr now_atp;
726                 PrintFormatPtr current;
727                 PrintFormatPtr head = NULL;
728                 PrintFormatPtr prev = NULL;
729                 if (AsnReadVal(aip, atp, &av) <= 0) /* START_STUCT */
730                         goto erret;
731 
732                 now_atp = atp;
733 
734                 while ((now_atp = AsnReadId(aip, amp, now_atp)) != atp){
735                         if (now_atp == NULL)  goto erret;
736 
737                         current= PrintFormatAsnRead(aip, now_atp);
738                         if (current == NULL)  goto erret;
739 
740                         if (head == NULL)
741                                 head = current;
742                         else
743                                 prev -> next = current;
744                         prev=current;
745                 }
746                 if (AsnReadVal(aip, atp, &av) <=0) /* END_STRUCT */                             goto erret;
747                 ptr -> components = head;
748                 atp = AsnReadId(aip,amp, atp);
749         }
750         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
751 ret:
752         AsnUnlinkType(orig);
753         return ptr;
754 erret:
755         ptr=PrintFormBlockFree(ptr);
756         goto ret;
757 }
758 
759 /**************************************************
760 *
761 *    PrintFormBlockAsnWrite()
762 *
763 **************************************************/
764 NLM_EXTERN Boolean LIBCALL PrintFormBlockAsnWrite (PrintFormBlockPtr ptr,  AsnIoPtr aip, AsnTypePtr orig)
765 {
766         Boolean retval = FALSE;
767         DataVal av;
768         AsnTypePtr atp;
769 
770         if (aip == NULL) return FALSE;
771 
772 
773         if ( ! loaded){
774         if (! ObjPrtAsnLoad()) goto erret;
775         
776 }
777         atp = AsnLinkType(orig, PRINTFORMBLOCK);
778         if(atp == NULL) {AsnNullValueMsg(aip,atp); goto erret;}
779         if (! AsnOpenStruct (aip, atp, (Pointer) ptr)) goto erret;
780 
781         if (ptr -> separator != NULL){
782                 av.ptrvalue = (Pointer) ptr -> separator;
783                 if ( ! AsnWrite(aip,PRINTFORMBLOCK_separator, &av)) goto erret;
784         }
785         if (ptr -> components != NULL){
786         if (! AsnOpenStruct (aip, PRINTFORMBLOCK_components, (Pointer) ptr -> components))
787                         goto erret;
788 
789                 {PrintFormatPtr current;
790                 for(current=ptr -> components; current; current = current -> next){
791                 if ( ! PrintFormatAsnWrite(current,aip,PRINTFORMBLOCK_components_E)) goto erret;
792                 }}
793 
794         if (! AsnCloseStruct (aip, PRINTFORMBLOCK_components, (Pointer) ptr -> components))
795                         goto erret;
796         }
797         if (! AsnCloseStruct (aip, atp, (Pointer) ptr)) goto erret;
798         retval = TRUE;
799 erret:AsnUnlinkType(orig);
800         return retval;
801 }
802 
803 /**************************************************
804 *
805 *    PrintFormBooleanNew()
806 *
807 **************************************************/
808 
809 NLM_EXTERN PrintFormBooleanPtr LIBCALL PrintFormBooleanNew(void)
810 {
811         return (PrintFormBooleanPtr) MemNew(sizeof(PrintFormBoolean));
812 }
813 
814 /**************************************************
815 *
816 *    PrintFormBooleanFree()
817 *
818 **************************************************/
819 NLM_EXTERN PrintFormBooleanPtr LIBCALL PrintFormBooleanFree ( PrintFormBooleanPtr ptr)
820 {
821         if (ptr == NULL) return NULL;
822 
823         MemFree(ptr -> truepfb);
824         MemFree(ptr -> falsepfb);
825         MemFree(ptr);
826         return NULL;
827 }
828 
829 /**************************************************
830 *
831 *    PrintFormBooleanAsnRead()
832 *
833 **************************************************/
834 NLM_EXTERN PrintFormBooleanPtr LIBCALL PrintFormBooleanAsnRead ( AsnIoPtr aip, AsnTypePtr orig)
835 {
836         DataVal av;
837         AsnTypePtr atp;
838         PrintFormBooleanPtr ptr;
839 
840         if (aip == NULL) return NULL;
841 
842 
843         if ( ! loaded){
844                 if ( ! ObjPrtAsnLoad ())
845                         goto erret;
846                 
847         }
848         if (orig == NULL)
849                 atp = AsnReadId(aip, amp, PRINTFORMBOOLEAN);
850         else
851                 atp = AsnLinkType(orig, PRINTFORMBOOLEAN);
852         if(atp == NULL) return NULL;
853 
854         ptr = PrintFormBooleanNew();
855         if (ptr == NULL) goto erret;
856 
857         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
858 
859         atp = AsnReadId(aip,amp, atp);
860         if (atp == PRINTFORMBOOLEAN_true){
861                 if (AsnReadVal(aip, atp, &av) <= 0)
862                         goto erret;
863                 ptr->truepfb = (CharPtr)av.ptrvalue;
864                 atp = AsnReadId(aip,amp, atp);
865         }
866         if (atp == PRINTFORMBOOLEAN_false){
867                 if (AsnReadVal(aip, atp, &av) <= 0)
868                         goto erret;
869                 ptr->falsepfb = (CharPtr)av.ptrvalue;
870                 atp = AsnReadId(aip,amp, atp);
871         }
872         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
873 ret:
874         AsnUnlinkType(orig);
875         return ptr;
876 erret:
877         ptr=PrintFormBooleanFree(ptr);
878         goto ret;
879 }
880 
881 /**************************************************
882 *
883 *    PrintFormBooleanAsnWrite()
884 *
885 **************************************************/
886 NLM_EXTERN Boolean LIBCALL PrintFormBooleanAsnWrite (PrintFormBooleanPtr ptr,  AsnIoPtr aip, AsnTypePtr orig)
887 {
888         Boolean retval = FALSE;
889         DataVal av;
890         AsnTypePtr atp;
891 
892         if (aip == NULL) return FALSE;
893 
894 
895         if ( ! loaded){
896         if (! ObjPrtAsnLoad()) goto erret;
897         
898 }
899         atp = AsnLinkType(orig, PRINTFORMBOOLEAN);
900         if(atp == NULL) {AsnNullValueMsg(aip,atp); goto erret;}
901         if (! AsnOpenStruct (aip, atp, (Pointer) ptr)) goto erret;
902 
903         if (ptr -> truepfb != NULL){
904                 av.ptrvalue = (Pointer) ptr -> truepfb;
905                 if ( ! AsnWrite(aip,PRINTFORMBOOLEAN_true, &av)) goto erret;
906         }
907         if (ptr -> falsepfb != NULL){
908                 av.ptrvalue = (Pointer) ptr -> falsepfb;
909                 if ( ! AsnWrite(aip,PRINTFORMBOOLEAN_false, &av)) goto erret;
910         }
911         if (! AsnCloseStruct (aip, atp, (Pointer) ptr)) goto erret;
912         retval = TRUE;
913 erret:AsnUnlinkType(orig);
914         return retval;
915 }
916 
917 /**************************************************
918 *
919 *    PrintFormEnumNew()
920 *
921 **************************************************/
922 NLM_EXTERN PrintFormEnumPtr LIBCALL PrintFormEnumNew(void)
923 {
924         return (PrintFormEnumPtr) MemNew(sizeof(PrintFormEnum));
925 }
926 
927 /**************************************************
928 *
929 *    PrintFormEnumFree()
930 *
931 **************************************************/
932 NLM_EXTERN PrintFormEnumPtr LIBCALL PrintFormEnumFree ( PrintFormEnumPtr ptr)
933 {
934         if (ptr == NULL) return NULL;
935 
936         ValNodeFreeData(ptr -> values);
937         MemFree(ptr);
938         return NULL;
939 }
940 
941 /**************************************************
942 *
943 *    PrintFormEnumAsnRead()
944 *
945 **************************************************/
946 NLM_EXTERN PrintFormEnumPtr LIBCALL PrintFormEnumAsnRead ( AsnIoPtr aip, AsnTypePtr orig)
947 {
948         ValNodePtr current;
949         DataVal av;
950         AsnTypePtr atp, oldatp;
951         PrintFormEnumPtr ptr;
952 
953         if (aip == NULL) return NULL;
954 
955         if ( ! loaded){
956                 if ( ! ObjPrtAsnLoad ())
957                         goto erret;
958                 
959         }
960         if (orig == NULL)
961                 atp = AsnReadId(aip, amp, PRINTFORMENUM);
962         else
963                 atp = AsnLinkType(orig, PRINTFORMENUM);
964         if(atp == NULL) return NULL;
965         oldatp = atp;
966 
967         ptr = PrintFormEnumNew();
968         if (ptr == NULL) goto erret;
969 
970         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
971 
972         while ((atp = AsnReadId(aip,amp, atp)) != oldatp)
973         {
974                 if (AsnReadVal(aip, atp, &av) <= 0) /* the value */
975                         goto erret;
976 
977                 if (atp == PRINTFORMENUM_values_E)
978                 {
979                         current = ValNodeNew(ptr->values);
980                         if (current == NULL)  goto erret;
981                         current->data.ptrvalue = av.ptrvalue;
982 
983                         if (ptr->values == NULL)
984                                 ptr->values = current;
985                 }
986         }
987         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
988 ret:
989         AsnUnlinkType(orig);
990         return ptr;
991 erret:
992         ptr=PrintFormEnumFree(ptr);
993         goto ret;
994 }
995 
996 /**************************************************
997 *
998 *    PrintFormEnumAsnWrite()
999 *
1000 **************************************************/
1001 NLM_EXTERN Boolean LIBCALL PrintFormEnumAsnWrite (PrintFormEnumPtr ptr,  AsnIoPtr aip, AsnTypePtr orig)
1002 {
1003         Boolean retval = FALSE;
1004         AsnTypePtr atp;
1005         ValNodePtr curr;
1006 
1007         if (aip == NULL) return FALSE;
1008 
1009 
1010         if ( ! loaded){
1011         if (! ObjPrtAsnLoad()) goto erret;
1012         
1013 }
1014         atp = AsnLinkType(orig, PRINTFORMENUM);
1015         if(atp == NULL) {AsnNullValueMsg(aip,atp); goto erret;}
1016         if (! AsnOpenStruct (aip, atp, (Pointer) ptr)) goto erret;
1017 
1018         if (ptr -> values != NULL){
1019                 if (! AsnOpenStruct (aip, PRINTFORMENUM_values, (Pointer) ptr -> values))
1020                         goto erret;
1021                 for (curr = ptr->values; curr != NULL; curr = curr->next)
1022                 {
1023                         if ( ! AsnWrite(aip, PRINTFORMENUM_values_E, &(curr->data))) goto erret;
1024                 }
1025                 if (! AsnCloseStruct (aip, PRINTFORMENUM_values, (Pointer) ptr -> values))
1026                         goto erret;
1027         }
1028         if (! AsnCloseStruct (aip, atp, (Pointer) ptr)) goto erret;
1029         retval = TRUE;
1030 erret:AsnUnlinkType(orig);
1031         return retval;
1032 }
1033 
1034 /**************************************************
1035 *
1036 *    PrintFormTextNew()
1037 *
1038 **************************************************/
1039 NLM_EXTERN PrintFormTextPtr LIBCALL PrintFormTextNew(void)
1040 {
1041         return (PrintFormTextPtr) MemNew(sizeof(PrintFormText));
1042 }
1043 
1044 /**************************************************
1045 *
1046 *    PrintFormTextFree()
1047 *
1048 **************************************************/
1049 NLM_EXTERN PrintFormTextPtr LIBCALL PrintFormTextFree ( PrintFormTextPtr ptr)
1050 {
1051         if (ptr == NULL) return NULL;
1052 
1053         MemFree(ptr -> textfunc);
1054         MemFree(ptr);
1055         return NULL;
1056 }
1057 
1058 /**************************************************
1059 *
1060 *    PrintFormTextAsnRead()
1061 *
1062 **************************************************/
1063 NLM_EXTERN PrintFormTextPtr LIBCALL PrintFormTextAsnRead ( AsnIoPtr aip, AsnTypePtr orig)
1064 {
1065         DataVal av;
1066         AsnTypePtr atp;
1067         PrintFormTextPtr ptr;
1068 
1069         if (aip == NULL) return NULL;
1070 
1071 
1072         if ( ! loaded){
1073                 if ( ! ObjPrtAsnLoad ())
1074                         goto erret;
1075                 
1076         }
1077         if (orig == NULL)
1078                 atp = AsnReadId(aip, amp, PRINTFORMTEXT);
1079         else
1080                 atp = AsnLinkType(orig, PRINTFORMTEXT);
1081         if(atp == NULL) return NULL;
1082 
1083         ptr = PrintFormTextNew();
1084         if (ptr == NULL) goto erret;
1085 
1086         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1087 
1088         atp = AsnReadId(aip,amp, atp);
1089         if (atp == PRINTFORMTEXT_textfunc){
1090                 if (AsnReadVal(aip, atp, &av) <= 0)
1091                         goto erret;
1092                 ptr->textfunc = (CharPtr)av.ptrvalue;
1093                 atp = AsnReadId(aip,amp, atp);
1094         }
1095         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1096 ret:
1097         AsnUnlinkType(orig);
1098         return ptr;
1099 erret:
1100         ptr=PrintFormTextFree(ptr);
1101         goto ret;
1102 }
1103 
1104 /**************************************************
1105 *
1106 *    PrintFormTextAsnWrite()
1107 *
1108 **************************************************/
1109 NLM_EXTERN Boolean LIBCALL PrintFormTextAsnWrite (PrintFormTextPtr ptr,  AsnIoPtr aip, AsnTypePtr orig)
1110 {
1111         Boolean retval = FALSE;
1112         DataVal av;
1113         AsnTypePtr atp;
1114 
1115         if (aip == NULL) return FALSE;
1116 
1117 
1118         if ( ! loaded){
1119         if (! ObjPrtAsnLoad()) goto erret;
1120         
1121 }
1122         atp = AsnLinkType(orig, PRINTFORMTEXT);
1123         if(atp == NULL) {AsnNullValueMsg(aip,atp); goto erret;}
1124         if (! AsnOpenStruct (aip, atp, (Pointer) ptr)) goto erret;
1125 
1126         if (ptr -> textfunc != NULL){
1127                 av.ptrvalue = (Pointer) ptr -> textfunc;
1128                 if ( ! AsnWrite(aip,PRINTFORMTEXT_textfunc, &av)) goto erret;
1129         }
1130         if (! AsnCloseStruct (aip, atp, (Pointer) ptr)) goto erret;
1131         retval = TRUE;
1132 erret:AsnUnlinkType(orig);
1133         return retval;
1134 }
1135 
1136 /**************************************************
1137 *
1138 *    UserFormatNew()
1139 *
1140 **************************************************/
1141 NLM_EXTERN UserFormatPtr LIBCALL UserFormatNew(void)
1142 {
1143         return (UserFormatPtr) MemNew(sizeof(UserFormat));
1144 }
1145 
1146 /**************************************************
1147 *
1148 *    UserFormatFree()
1149 *
1150 **************************************************/
1151 NLM_EXTERN UserFormatPtr LIBCALL UserFormatFree ( UserFormatPtr ptr)
1152 {
1153         if (ptr == NULL) return NULL;
1154 
1155         MemFree(ptr -> printfunc);
1156         MemFree(ptr -> defaultfunc);
1157         MemFree(ptr);
1158         return NULL;
1159 }
1160 
1161 /**************************************************
1162 *
1163 *    UserFormatAsnRead()
1164 *
1165 **************************************************/
1166 NLM_EXTERN UserFormatPtr LIBCALL UserFormatAsnRead ( AsnIoPtr aip, AsnTypePtr orig)
1167 {
1168         DataVal av;
1169         AsnTypePtr atp;
1170         UserFormatPtr ptr;
1171 
1172         if (aip == NULL) return NULL;
1173 
1174 
1175         if ( ! loaded){
1176                 if ( ! ObjPrtAsnLoad ())
1177                         goto erret;
1178                 
1179         }
1180         if (orig == NULL)
1181                 atp = AsnReadId(aip, amp, USERFORMAT);
1182         else
1183                 atp = AsnLinkType(orig, USERFORMAT);
1184         if(atp == NULL) return NULL;
1185 
1186         ptr = UserFormatNew();
1187         if (ptr == NULL) goto erret;
1188 
1189         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1190 
1191         atp = AsnReadId(aip,amp, atp);
1192         if (atp == USERFORMAT_printfunc){
1193                 if (AsnReadVal(aip, atp, &av) <= 0)
1194                         goto erret;
1195                 ptr->printfunc = (CharPtr)av.ptrvalue;
1196                 atp = AsnReadId(aip,amp, atp);
1197         }
1198         if (atp == USERFORMAT_defaultfunc){
1199                 if (AsnReadVal(aip, atp, &av) <= 0)
1200                         goto erret;
1201                 ptr->defaultfunc = (CharPtr)av.ptrvalue;
1202                 atp = AsnReadId(aip,amp, atp);
1203         }
1204         if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
1205 ret:
1206         AsnUnlinkType(orig);
1207         return ptr;
1208 erret:
1209         ptr=UserFormatFree(ptr);
1210         goto ret;
1211 }
1212 
1213 /**************************************************
1214 *
1215 *    UserFormatAsnWrite()
1216 *
1217 **************************************************/
1218 NLM_EXTERN Boolean LIBCALL UserFormatAsnWrite (UserFormatPtr ptr,  AsnIoPtr aip, AsnTypePtr orig)
1219 {
1220         Boolean retval = FALSE;
1221         DataVal av;
1222         AsnTypePtr atp;
1223 
1224         if (aip == NULL) return FALSE;
1225 
1226 
1227         if ( ! loaded){
1228         if (! ObjPrtAsnLoad()) goto erret;
1229         
1230 }
1231         atp = AsnLinkType(orig, USERFORMAT);
1232         if(atp == NULL) {AsnNullValueMsg(aip,atp); goto erret;}
1233         if (! AsnOpenStruct (aip, atp, (Pointer) ptr)) goto erret;
1234 
1235         if (ptr -> printfunc != NULL){
1236                 av.ptrvalue = (Pointer) ptr -> printfunc;
1237                 if ( ! AsnWrite(aip,USERFORMAT_printfunc, &av)) goto erret;
1238         }
1239         if (ptr -> defaultfunc != NULL){
1240                 av.ptrvalue = (Pointer) ptr -> defaultfunc;
1241                 if ( ! AsnWrite(aip,USERFORMAT_defaultfunc, &av)) goto erret;
1242         }
1243         if (! AsnCloseStruct (aip, atp, (Pointer) ptr)) goto erret;
1244         retval = TRUE;
1245 erret:AsnUnlinkType(orig);
1246         return retval;
1247 }
1248 
1249 

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.