1 #ifdef _cplusplus
2 extern "C" {
3 #endif
4 #include "display.h"
5 
6 
7 
8 
9 
10 # line 97 "display.dy"
write_Aln2Display_header(DYNFILE * dfp,Aln2Display * a2d)11 void write_Aln2Display_header(DYNFILE * dfp,Aln2Display * a2d)
12 {
13   return;
14 }
15 
16 
17 # line 103 "display.dy"
write_Aln2Display_function(DYNFILE * dfp,Aln2Display * a2d)18 void write_Aln2Display_function(DYNFILE * dfp,Aln2Display * a2d)
19 {
20 
21   write_Aln2Display_convert_func(dfp,a2d);
22 
23 }
24 
25 
26 # line 111 "display.dy"
write_Aln2Display_convert_func(DYNFILE * dfp,Aln2Display * a2d)27 void write_Aln2Display_convert_func(DYNFILE * dfp,Aln2Display * a2d)
28 {
29   register int i;
30   register int j;
31   register int k;
32   char buffer[MAXLINE];
33 
34 
35   /*** assume file is already loaded into writec ***/
36 
37 
38   sprintf(buffer,"AlnDisplay * convert_AlnBlock_to_AlnDisplay_%s(AlnBlock * alb ",a2d->name);
39   for(i=0;i<a2d->res_len;i++) {
40     strcat(buffer,",");
41 
42     strcat(buffer,a2d->a2dr[i]->type);
43     strcat(buffer,a2d->a2dr[i]->name);
44   }
45   strcat(buffer,")");
46 
47   start_function(dfp,buffer);
48   expr(dfp,"AlnDisplay * out");
49   expr(dfp,"AlnDisplayColumn * adc;");
50   expr(dfp,"AlnDisplayUnit * adu;");
51   expr(dfp,"AlnDisplayField * adf;");
52   expr(dfp,"AlnDisplayNameBlock * adnb;");
53   expr(dfp,"AlnDisplayNameUnit * adnu;");
54   expr(dfp,"AlnIndexField * aif;");
55   expr(dfp,"AlnDisplayIndexUnit * adiu;");
56   expr(dfp,"AlnDisplayIndex * adi;");
57   expr(dfp,"AlnColumn * alc;");
58   expr(dfp,"AlnUnit   * alu;");
59   expr(dfp,"char tempbuf[512]");
60 
61   add_break(dfp);
62 
63   expr(dfp,"out = new_AlnDisplay(alb->len)");
64   add_break(dfp);
65 
66   for(i=0;i<a2d->len;i++) {
67     expr(dfp,"adnb = AlnDisplayNameBlock_no_get(out,%d);",i);
68     expr(dfp,"adnb->direction = ALN_DISPLAY_%s",a2d->s2d[i]->direction);
69     expr(dfp,"adnu = get_next_AlnDisplayNameUnit(adnb);");
70     if( a2d->s2d[i]->name_str != NULL) {
71       expr(dfp,"adnu->name = %s;",a2d->s2d[i]->name_str);
72       expr(dfp,"adnu->should_free = %s;",a2d->s2d[i]->is_static == TRUE ? "FALSE" : "TRUE");
73     }
74     else {
75       expr(dfp,"adnu->name = \"NoName\";");
76       expr(dfp,"adnu->should_free = FALSE;");
77     }
78 
79     if( a2d->s2d[i]->ind_len > 0 ) {
80       /* get the index  */
81       add_break(dfp);
82       add_block_comment(dfp,"This sequence has got an index, get the alndisplayindex");
83       expr(dfp,"adi = AlnDisplayIndex_no_get(out,%d);",i);
84       expr(dfp,"adi->direction = ALN_DISPLAY_%s",a2d->s2d[i]->direction);
85       for(j=0;j< a2d->s2d[i]->ind_len;j++) {
86 	auto Index2Display  * i2d;
87 	i2d = a2d->s2d[i]->i2d[j];
88 
89 	expr(dfp,"adiu = get_next_AlnDisplayIndexUnit(adi);");
90 	expr(dfp,"adiu->start = %s",i2d->eval == NULL ? "0" : i2d->eval);
91 	add_break(dfp);
92       }
93     } /* end of if index*/
94   } /* end of for */
95 
96 
97 
98 
99   expr(dfp,"for(alc = alb->start;alc != NULL;alc = alc->next)");
100   startbrace_tag(dfp,"all columns in AlnBlock");
101   expr(dfp,"adc = new_terminal_AlnDisplayColumn(out);");
102 
103   /*** go over each sequence, and move the labels across ***/
104 
105   for(i=0;i<a2d->len;i++) {
106     j = 0;
107     expr(dfp,"adu = AlnDisplayUnit_no_get(adc,%d)",i);
108     expr(dfp,"alu = alc->alu[%d]",i);
109 
110 
111 
112     /*** start of the labels ***/
113 
114     for(j=0;j<a2d->s2d[i]->len;j++) {
115       expr(dfp,"%s if(alu->text_label != NULL && strcmp(alu->text_label,\"%s\") == 0) ",j == 0 ? "" : "else",a2d->s2d[i]->l2d[j]->label);
116       startbrace_tag(dfp,"if this label");
117 
118 
119       /*** add the index if it is there ***/
120 
121       for(k=0;k<a2d->s2d[i]->l2d[j]->ind_len;k++) {
122 	expr(dfp,"aif = get_next_AlnIndexField(adu)");
123 	expr(dfp,"aif->index_no = %d;",a2d->s2d[i]->l2d[j]->i2d[k]->number);
124 	expr(dfp,"aif->length = %s;",a2d->s2d[i]->l2d[j]->i2d[k]->eval);
125       }
126 
127 
128       if(a2d->s2d[i]->l2d[j]->is_lone == TRUE ) {
129 	expr(dfp,"adc->is_lone = TRUE;");
130       }
131 
132       expr(dfp,"adu->direction = ALN_DISPLAY_%s;",a2d->s2d[i]->l2d[j]->direction == NULL ? "DOWN" : a2d->s2d[i]->l2d[j]->direction);
133       for(k=0;k<a2d->s2d[i]->l2d[j]->len;k++) {
134 	auto Aln2DisplayField * a2df;
135 	a2df = a2d->s2d[i]->l2d[j]->a2df[k];
136 	expr(dfp,"adf = get_next_AlnDisplayField(adu);");
137 
138 
139 	if( a2df->is_sub == TRUE ) {
140 	  expr(dfp,"sprintf(tempbuf,\"%%d\",alu->start);");
141 	  expr(dfp,"push_scan_and_replace_pair(\"%%START\",tempbuf);");
142 	  expr(dfp,"sprintf(tempbuf,\"%%d\",alu->end);");
143 	  expr(dfp,"push_scan_and_replace_pair(\"%%END\",tempbuf);");
144 	}
145 
146 	if( a2df->is_string == TRUE )
147 	  expr(dfp,"adf->characters = \"%s\";",a2df->string);
148 	else if( a2df->is_single == TRUE )
149 	  expr(dfp,"adf->single = %s;",a2df->string);
150 	else if( a2df->is_sub == TRUE) {
151 	  expr(dfp,"strcpy(tempbuf,\"%s\");",a2df->string);
152 	  expr(dfp,"adf->characters = stringalloc(scan_and_replace_line(tempbuf))");
153 	  expr(dfp,"pop_scan_and_replace_pair();");
154 	  expr(dfp,"pop_scan_and_replace_pair();");
155 	}
156 	else expr(dfp,"adf->characters = %s",a2df->string);
157 
158 
159 	if( a2df->is_sub == TRUE )
160 	  expr(dfp,"adf->length = strlen(adf->characters)");
161 	else expr(dfp,"adf->length = %s",a2df->length == NULL ? "1" : a2df->length);
162 	expr(dfp,"adf->direction = ALN_DISPLAY_%s",a2df->direction == NULL ? "RIGHT" : a2df->direction);
163 	expr(dfp,"adf->should_free = %s",a2df->is_static == TRUE ? "FALSE" : "TRUE");
164 	if( a2df->convert != NULL )
165 	  expr(dfp,"adf->convert_func = %s;",a2df->convert);
166       }
167       closebrace(dfp);
168     }
169     expr(dfp,"else ");
170     startbrace(dfp);
171     expr(dfp,"warn(\"In AlnBlock to AlnDisplay %s, got unintretable label [%%s] for sequence %d\",alc->alu[%d]->text_label);",a2d->name,i,i);
172     expr(dfp,"adf = get_next_AlnDisplayField(adu);");
173     expr(dfp,"adf->characters = \"?\";");
174     expr(dfp,"adf->length = 1");
175     expr(dfp,"adf->direction = ALN_DISPLAY_RIGHT");
176     expr(dfp,"adf->should_free = FALSE");
177     closebrace(dfp);
178   }
179 
180   closebrace(dfp);
181 
182   expr(dfp,"return out;");
183 
184   close_function(dfp);
185   add_break(dfp);
186 
187 }
188 
189 
190  /*************************/
191  /* Access/checking func  */
192  /*************************/
193 
194 # line 278 "display.dy"
prepare_Aln2Display(Aln2Display * a2d)195 boolean prepare_Aln2Display(Aln2Display * a2d)
196 {
197   boolean ret = TRUE;
198 
199   number_up_Sequence_Index2Display(a2d);
200 
201   if( crosslink_Index(a2d) == FALSE ){
202     warn("Unable to crosslink Display %s: probably you have not got one of the indexes in the sequence block",a2d->name);
203     ret = FALSE;
204   }
205 
206 
207   return ret;
208 }
209 
210 
211 
212 # line 295 "display.dy"
number_up_Sequence_Index2Display(Aln2Display * a2d)213 void number_up_Sequence_Index2Display(Aln2Display * a2d)
214 {
215   register int i;
216   register int j;
217 
218   for(i=0;i<a2d->len;i++)
219     for(j=0;j<a2d->s2d[i]->ind_len;j++)
220       a2d->s2d[i]->i2d[j]->number = j;
221 }
222 
223 # line 305 "display.dy"
crosslink_Index(Aln2Display * a2d)224 boolean crosslink_Index(Aln2Display * a2d)
225 {
226   register int i;
227   register int j;
228   boolean ret = TRUE;
229 
230   for(i=0;i<a2d->len;i++)
231     for(j=0;j<a2d->s2d[i]->len;j++) {
232       if( crosslink_Label2Display_Index(a2d->s2d[i]->l2d[j],a2d->s2d[i]) == FALSE )
233 	ret = FALSE;
234     }
235 
236 
237   return ret;
238 }
239 
240 
241 
242 # line 323 "display.dy"
crosslink_Label2Display_Index(Label2Display * l2d,Sequence2Display * s2d)243 boolean crosslink_Label2Display_Index(Label2Display * l2d,Sequence2Display * s2d)
244 {
245   register int i;
246   Index2Display * temp;
247   boolean ret = TRUE;
248 
249   for(i=0;i<l2d->ind_len;i++) {
250     temp = Index2Display_from_name(s2d,l2d->i2d[i]->name);
251     if( temp == NULL ) {
252       warn("In Label %s of Sequence number %d, could not crosslink index name %s",l2d->label,s2d->number,l2d->i2d[i]->name);
253       ret = FALSE;
254     }
255 
256     else l2d->i2d[i]->number = temp->number;
257   }
258 
259   return ret;
260 }
261 
262 # line 342 "display.dy"
Index2Display_from_name(Sequence2Display * s2d,char * name)263 Index2Display * Index2Display_from_name(Sequence2Display * s2d,char * name)
264 {
265   register int i;
266 
267   for(i=0;i<s2d->ind_len;i++) {
268     if( strcmp(s2d->i2d[i]->name,name) == 0 )
269       return s2d->i2d[i];
270   }
271 
272   return NULL;
273 }
274 
275 
276 
277  /**************************/
278  /* I/O functions          */
279  /**************************/
280 
281 
282 
283 
284 
285 # line 364 "display.dy"
read_Aln2Display_line(char * line,FILE * ifp)286 Aln2Display         * read_Aln2Display_line(char * line,FILE * ifp)
287 {
288   Sequence2Display * temp;
289   Aln2DisplayResource * tempres;
290   Aln2Display * out;
291   char buffer[MAXLINE];
292   char * runner;
293 
294 
295   runner = strtok(line,spacestr);
296   if( runner == NULL ) {
297     warn("In read_Aln2Display_line, got completely blank line!");
298     return NULL;
299   }
300 
301   if( strcmp(runner,"display") != 0 ) {
302     warn("In read_Aln2Display_line, got non display line... [%s]",line);
303     return NULL;
304   }
305 
306   runner = strtok(NULL,spacestr);
307   if( runner == NULL ) {
308     warn("In read_Sequence2Display_line, got no display name... cannot process!");
309     return NULL;
310   }
311 
312 
313   out = Aln2Display_alloc_std();
314   if( out == NULL)
315     return NULL;
316 
317   out->name = stringalloc(runner);
318 
319 
320   while( fgets(buffer,MAXLINE,ifp) != NULL ) {
321     if( strwhitestartcmp(buffer,"enddisplay",spacestr) == 0 )
322       break;
323     if( strwhitestartcmp(buffer,"sequence",spacestr) == 0 ) {
324       temp = read_Sequence2Display_line(buffer,ifp);
325       if( temp == NULL )
326 	warn("In display number %d.. got bad sequence",out->name);
327       else add_Aln2Display(out,temp);
328     }
329     else if ( strwhitestartcmp(buffer,"resource",spacestr) == 0 ) {
330       tempres = read_Aln2DisplayResource_line(buffer);
331      if( tempres == NULL )
332 	warn("In display %s.. got bad resource",out->name);
333       else add_res_Aln2Display(out,tempres);
334     }
335     else {
336       warn("In aln2display read.. got uninterpretable line [%s]",buffer);
337     }
338 
339   }
340 
341   return out;
342 }
343 
344 
345 # line 423 "display.dy"
read_Sequence2Display_line(char * line,FILE * ifp)346 Sequence2Display    * read_Sequence2Display_line(char * line,FILE * ifp)
347 {
348   Sequence2Display * out;
349   Label2Display * temp;
350   Index2Display * ind;
351   char buffer[MAXLINE];
352   char * runner;
353 
354 
355   runner = strtok(line,spacestr);
356   if( runner == NULL ) {
357     warn("In read_Label2Display_line, got completely blank line!");
358     return NULL;
359   }
360 
361   if( strcmp(runner,"sequence") != 0 ) {
362     warn("In read_Sequecne2Display_line, got non sequence line... [%s]",line);
363     return NULL;
364   }
365 
366   runner = strtok(NULL,spacestr);
367   if( runner == NULL ) {
368     warn("In read_Sequence2Display_line, got no  sequence number... cannot process!");
369     return NULL;
370   }
371 
372 
373   out = Sequence2Display_alloc_std();
374   if( out == NULL)
375     return NULL;
376 
377   if( strcmp(runner,"ALLOTHERS") == 0)
378     out->number = ALL_OTHER_NUMBER;
379   else out->number = atoi(runner);
380 
381 
382   while( fgets(buffer,MAXLINE,ifp) != NULL ) {
383     if( strwhitestartcmp(buffer,"endsequence",spacestr) == 0 )
384       break;
385     else if( strwhitestartcmp(buffer,"name",spacestr) == 0 )
386       read_name_line(out,buffer);
387     else if( strwhitestartcmp(buffer,"label",spacestr) == 0 ) {
388       temp = read_Label2Display_line(buffer,ifp);
389       if( temp == NULL )
390 	warn("In sequence number %d.. got bad label",out->number);
391       else add_Sequence2Display(out,temp);
392     }
393     else if ( strwhitestartcmp(buffer,"index",spacestr) == 0 ) {
394       ind = read_Index2Display_line(buffer);
395       if( ind == NULL )
396 	warn("In sequence number %d, unable to read Index line ",out->number);
397       else add_ind_Sequence2Display(out,ind);
398     }
399 
400     else {
401       warn("In sequence2display.. got uninterpretable line [%s]",buffer);
402     }
403 
404   }
405 
406   return out;
407 }
408 
409 # line 486 "display.dy"
read_Label2Display_line(char * line,FILE * ifp)410 Label2Display       * read_Label2Display_line(char * line,FILE * ifp)
411 {
412   Label2Display * out;
413   Aln2DisplayField * temp;
414   Index2Display * ind;
415   char * runner;
416   char buffer[MAXLINE];
417 
418 
419 
420   runner = strtok(line,spacestr);
421   if( runner == NULL ) {
422     warn("In read_Label2Display_line, got completely blank line!");
423     return NULL;
424   }
425 
426   if( strcmp(runner,"label") != 0 ) {
427     warn("In read_Label2Display_line, got non label line... [%s]",line);
428     return NULL;
429   }
430 
431   runner = strtok(NULL,spacestr);
432   if( runner == NULL ) {
433     warn("In read_Label2Display_line, got no label name... cannot process!");
434     return NULL;
435   }
436 
437 
438 
439 
440   out = Label2Display_alloc_std();
441 
442   if( out == NULL)
443     return NULL;
444 
445   out->label = stringalloc(runner);
446 
447 
448   runner = strtok(NULL,spacestr);
449   while( runner != NULL ) {
450     if( strcmp(runner,"!lone") == 0 ) {
451       out->is_lone = TRUE;
452     }
453 
454     else {
455       warn("Could not understand label modifier %s",runner);
456     }
457     runner = strtok(NULL,spacestr);
458   }
459 
460 
461   while( fgets(buffer,MAXLINE,ifp) != NULL ) {
462     if( strwhitestartcmp(buffer,"endlabel",spacestr) == 0)
463       break;
464     if( strwhitestartcmp(buffer,"field",spacestr) == 0 ) {
465       temp = read_Aln2DisplayField_line(buffer,ifp);
466       if( temp == NULL )
467 	warn("In label %s, unable to read field lines...",out->label);
468       else add_Label2Display(out,temp);
469     }
470     else if( strwhitestartcmp(buffer,"index",spacestr) == 0 ) {
471       ind = read_Index2Display_line(buffer);
472       if( ind == NULL )
473 	warn("In label %s, unable to read Index line ",out->label);
474       else add_ind_Label2Display(out,ind);
475     }
476 
477     else if( strwhitestartcmp(buffer,"direction",spacestr) == 0 ) {
478       runner = strtok(buffer,spacestr);
479       out->direction = string_from_quoted_equality(runner);
480 
481     }
482     else {
483       warn("In reading label [%s], unable to interpret [%s]",out->label,buffer);
484     }
485 
486   }
487 
488   return out;
489 }
490 
491 
492 
493 # line 569 "display.dy"
read_Aln2DisplayField_line(char * line,FILE * ifp)494 Aln2DisplayField    * read_Aln2DisplayField_line(char * line,FILE * ifp)
495 {
496   Aln2DisplayField * out;
497   char ** base;
498   char ** bkstr;
499   char buffer[MAXLINE];
500 
501   out = Aln2DisplayField_alloc();
502   if( out == NULL)
503     return NULL;
504 
505 
506 
507   base = bkstr = breakstring(line,spacestr);
508 
509   for(bkstr++;*bkstr != NULL;bkstr++) {
510     put_away_Aln2DisplayField_strpair(out,*bkstr);
511   }
512   ckfree(base);
513 
514   while( fgets(buffer,MAXLINE,ifp) != NULL ) {
515     if( buffer[0] == '#')
516       continue;
517     if( strwhitestartcmp(buffer,"endfield",spacestr) == 0)
518       break;
519     base = bkstr = breakstring(buffer,spacestr);
520     for(;*bkstr != NULL;bkstr++) {
521       put_away_Aln2DisplayField_strpair(out,*bkstr);
522     }
523 
524 
525     ckfree(base);
526   }
527 
528 
529   return out;
530 
531 }
532 
533 # line 608 "display.dy"
read_name_line(Sequence2Display * s2d,char * name_line)534 boolean read_name_line(Sequence2Display * s2d,char * name_line)
535 {
536   char ** base;
537   char ** bkstr;
538 
539   if( strwhitestartcmp(name_line,"name",spacestr) != 0 ) {
540     warn("Passed a non name line to read name line... [%s]",name_line);
541     return FALSE;
542   }
543 
544 
545   base = bkstr = breakstring(name_line,spacestr);
546 
547   for(bkstr++;*bkstr != NULL;bkstr++) {
548     if( strstartcmp(*bkstr,"string") == 0 ) {
549       s2d->name_str = string_from_quoted_equality(*bkstr);
550     }
551     else if( strstartcmp(*bkstr,"!static") == 0 ) {
552       s2d->is_static = TRUE;
553     }
554     else if( strstartcmp(*bkstr,"length=") == 0 ) {
555       s2d->length = number_from_quoted_equality(*bkstr);
556       if( s2d->length < 0 || s2d->length > 512 ) {
557 	warn("sequence[%d] name length [%d] is ridiculous... setting to 20",s2d->number,s2d->length);
558 	s2d->length = 20;
559       }
560     }
561     else if( strstartcmp(*bkstr,"direction=") ==0 ) {
562       s2d->direction = string_from_quoted_equality(*bkstr);
563     }
564     else {
565       warn("In reading sequence name line for sequence number %d, unable to interpret [%s]",s2d->number,*bkstr);
566     }
567   }
568 
569   if( s2d->direction == NULL )
570     s2d->direction = stringalloc("DOWN");
571 
572   return TRUE;
573 
574 }
575 
576 
577 
578 # line 652 "display.dy"
put_away_Aln2DisplayField_strpair(Aln2DisplayField * a2df,char * pair)579 boolean put_away_Aln2DisplayField_strpair(Aln2DisplayField * a2df,char * pair)
580 {
581   char buffer[20];
582 
583   if( strstartcmp(pair,"string=") == 0) {
584     if( a2df->string != NULL) {
585       warn("Already a string or eval state ment in this Aln2DisplayField, overriding %s",a2df->string);
586       ckfree(a2df->string);
587     }
588     a2df->string = string_from_quoted_equality(pair);
589     a2df->is_string = TRUE;
590     sprintf(buffer,"%d",(int)strlen(a2df->string));
591     a2df->length = stringalloc(buffer);
592     a2df->is_static = TRUE;
593   }
594   else if( strstartcmp(pair,"eval") == 0 ) {
595     if( a2df->string != NULL) {
596       warn("Already a string or eval state ment in this Aln2DisplayField, overriding %s",a2df->string);
597       ckfree(a2df->string);
598     }
599     a2df->string = string_from_quoted_equality(pair);
600   }
601   else if( strstartcmp(pair,"substring") == 0 ) {
602     if( a2df->string != NULL) {
603       warn("Already a string or eval state ment in this Aln2DisplayField, overriding %s",a2df->string);
604       ckfree(a2df->string);
605     }
606     a2df->string = string_from_quoted_equality(pair);
607     a2df->is_sub    = TRUE;
608     a2df->is_static = FALSE;
609   }
610 
611   else if( strstartcmp(pair,"length=") == 0 ) {
612     a2df->length = string_from_quoted_equality(pair);
613   }
614   else if( strstartcmp(pair,"direction=") == 0) {
615     a2df->direction = string_from_quoted_equality(pair);
616   }
617   else if( strstartcmp(pair,"convert=") == 0 ) {
618     a2df->convert = string_from_quoted_equality(pair);
619   }
620   else if( strstartcmp(pair,"!static") == 0) {
621     a2df->is_static = TRUE;
622   }
623   else if( strstartcmp(pair,"!single") == 0) {
624     a2df->is_single = TRUE;
625   }
626   else {
627     warn("Unable to interpret [%s] as a valid Aln2DisplayField tag",pair);
628     return FALSE;
629   }
630 
631   return TRUE;
632 }
633 
634 # line 707 "display.dy"
read_Aln2DisplayResource_line(char * line)635 Aln2DisplayResource * read_Aln2DisplayResource_line(char * line)
636 {
637   Aln2DisplayResource * out;
638   char ** base;
639   char ** bkstr;
640 
641   out = Aln2DisplayResource_alloc();
642   if( out == NULL)
643     return NULL;
644 
645 
646   base = bkstr = breakstring(line,spacestr);
647 
648 
649   for(bkstr++;*bkstr != NULL;bkstr++) {
650 
651     if( strstartcmp(*bkstr,"type=") == 0) {
652 
653       out->type = string_from_quoted_equality(*bkstr);
654     }
655     else if( strstartcmp(*bkstr,"name=") == 0 ) {
656       out->name = string_from_quoted_equality(*bkstr);
657     }
658     else if( strstartcmp(*bkstr,"arg=") == 0) {
659       out->arg = string_from_quoted_equality(*bkstr);
660     }
661     else {
662       warn("Got strange tag [%s] in resource line..., while reading display... ignoring",*bkstr);
663     }
664   }
665   ckfree(base);
666 
667 
668   return out;
669 }
670 
671 
672 
673 
674 # line 746 "display.dy"
read_Index2Display_line(char * line)675 Index2Display * read_Index2Display_line(char * line)
676 {
677   Index2Display * out;
678   char ** bkstr;
679   char ** base;
680 
681   if( strwhitestartcmp(line,"index",spacestr) != 0 ) {
682     warn("Tried to read an Index2Display line with no index! Bad news!");
683     return NULL;
684   }
685 
686 
687   base = bkstr = breakstring(line,spacestr);
688 
689   out = Index2Display_alloc();
690   if( out == NULL )
691     return NULL;
692 
693   bkstr++;
694 
695   out->name = stringalloc(*bkstr);
696 
697   for(bkstr++;*bkstr != NULL;bkstr++) {
698     if( strstartcmp(*bkstr,"start") == 0 ) {
699       if( out->eval != NULL ) {
700 	warn("you are replacing an index evaluation. Remember that each index can only have one length [or start if in sequence]");
701 	ckfree(out->eval);
702       }
703       out->eval = string_from_quoted_equality(*bkstr);
704       out->is_start = TRUE;
705     }
706 
707     else if( strstartcmp(*bkstr,"length") == 0 ) {
708       if( out->eval != NULL ) {
709 	warn("you are replacing an index evaluation. Remember that each index can only have one length [or start if in sequence]");
710 	ckfree(out->eval);
711       }
712       out->eval = string_from_quoted_equality(*bkstr);
713     }
714     else {
715       warn("Found an uninterpretable tag [%s] in index %s",out->name,*bkstr);
716     }
717 
718   }
719 
720   ckfree(base);
721 
722   return out;
723 }
724 
725 
726 
727 
728 # line 799 "display.dy"
show_Aln2Display(Aln2Display * a2d,FILE * ofp)729 void show_Aln2Display(Aln2Display * a2d,FILE * ofp)
730 {
731   register int i;
732 
733   fprintf(ofp,"Display %s\n",a2d->name);
734   for(i=0;i<a2d->res_len;i++)
735     show_Aln2DisplayResource(a2d->a2dr[i],ofp);
736   for(i=0;i<a2d->len;i++)
737     show_Sequence2Display(a2d->s2d[i],ofp);
738 }
739 
740 # line 810 "display.dy"
show_Aln2DisplayResource(Aln2DisplayResource * a2dr,FILE * ofp)741 void show_Aln2DisplayResource(Aln2DisplayResource * a2dr,FILE * ofp)
742 {
743   fprintf(ofp,"Resource [%s] Type [%s] Argument [%s]\n",a2dr->type,a2dr->name,a2dr->arg);
744 }
745 
746 # line 815 "display.dy"
show_Sequence2Display(Sequence2Display * s2d,FILE * ofp)747 void show_Sequence2Display(Sequence2Display * s2d,FILE * ofp)
748 {
749   register int i;
750   fprintf(ofp,"Sequence %d\n",s2d->number);
751   for(i=0;i<s2d->len;i++)
752     show_Label2Display(s2d->l2d[i],ofp);
753 }
754 
755 # line 823 "display.dy"
show_Label2Display(Label2Display * l2d,FILE * ofp)756 void show_Label2Display(Label2Display * l2d,FILE * ofp)
757 {
758   register int i;
759   fprintf(ofp,"\tLabel %s\n",l2d->label);
760   for(i=0;i<l2d->len;i++) {
761     fprintf(ofp,"\t  Field %d",i);
762     show_Aln2DisplayField(l2d->a2df[i],ofp);
763   }
764 }
765 
766 # line 833 "display.dy"
show_Aln2DisplayField(Aln2DisplayField * a2df,FILE * ofp)767 void show_Aln2DisplayField(Aln2DisplayField * a2df,FILE * ofp)
768 {
769   fprintf(ofp," String = [%s], Length [%s], Direction [%s]\n",a2df->string,a2df->length,a2df->direction);
770 }
771 
772 
773 # line 772 "display.c"
774 /* Function:  hard_link_Aln2DisplayField(obj)
775  *
776  * Descrip:    Bumps up the reference count of the object
777  *             Meaning that multiple pointers can 'own' it
778  *
779  *
780  * Arg:        obj [UNKN ] Object to be hard linked [Aln2DisplayField *]
781  *
782  * Return [UNKN ]  Undocumented return value [Aln2DisplayField *]
783  *
784  */
hard_link_Aln2DisplayField(Aln2DisplayField * obj)785 Aln2DisplayField * hard_link_Aln2DisplayField(Aln2DisplayField * obj)
786 {
787     if( obj == NULL )    {
788       warn("Trying to hard link to a Aln2DisplayField object: passed a NULL object");
789       return NULL;
790       }
791     obj->dynamite_hard_link++;
792     return obj;
793 }
794 
795 
796 /* Function:  Aln2DisplayField_alloc(void)
797  *
798  * Descrip:    Allocates structure: assigns defaults if given
799  *
800  *
801  *
802  * Return [UNKN ]  Undocumented return value [Aln2DisplayField *]
803  *
804  */
Aln2DisplayField_alloc(void)805 Aln2DisplayField * Aln2DisplayField_alloc(void)
806 {
807     Aln2DisplayField * out; /* out is exported at end of function */
808 
809 
810     /* call ckalloc and see if NULL */
811     if((out=(Aln2DisplayField *) ckalloc (sizeof(Aln2DisplayField))) == NULL)    {
812       warn("Aln2DisplayField_alloc failed ");
813       return NULL;  /* calling function should respond! */
814       }
815     out->dynamite_hard_link = 1;
816 #ifdef PTHREAD
817     pthread_mutex_init(&(out->dynamite_mutex),NULL);
818 #endif
819     out->string = NULL;
820     out->length = NULL;
821     out->direction = NULL;
822     out->convert = NULL;
823     out->is_static = FALSE;
824     out->is_string = FALSE;
825     out->is_single = FALSE;
826     out->is_sub = FALSE;
827 
828 
829     return out;
830 }
831 
832 
833 /* Function:  free_Aln2DisplayField(obj)
834  *
835  * Descrip:    Free Function: removes the memory held by obj
836  *             Will chain up to owned members and clear all lists
837  *
838  *
839  * Arg:        obj [UNKN ] Object that is free'd [Aln2DisplayField *]
840  *
841  * Return [UNKN ]  Undocumented return value [Aln2DisplayField *]
842  *
843  */
free_Aln2DisplayField(Aln2DisplayField * obj)844 Aln2DisplayField * free_Aln2DisplayField(Aln2DisplayField * obj)
845 {
846     int return_early = 0;
847 
848 
849     if( obj == NULL) {
850       warn("Attempting to free a NULL pointer to a Aln2DisplayField obj. Should be trappable");
851       return NULL;
852       }
853 
854 
855 #ifdef PTHREAD
856     assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
857 #endif
858     if( obj->dynamite_hard_link > 1)     {
859       return_early = 1;
860       obj->dynamite_hard_link--;
861       }
862 #ifdef PTHREAD
863     assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
864 #endif
865     if( return_early == 1)
866       return NULL;
867     if( obj->string != NULL)
868       ckfree(obj->string);
869     if( obj->length != NULL)
870       ckfree(obj->length);
871     if( obj->direction != NULL)
872       ckfree(obj->direction);
873     if( obj->convert != NULL)
874       ckfree(obj->convert);
875 
876 
877     ckfree(obj);
878     return NULL;
879 }
880 
881 
882 /* Function:  hard_link_Index2Display(obj)
883  *
884  * Descrip:    Bumps up the reference count of the object
885  *             Meaning that multiple pointers can 'own' it
886  *
887  *
888  * Arg:        obj [UNKN ] Object to be hard linked [Index2Display *]
889  *
890  * Return [UNKN ]  Undocumented return value [Index2Display *]
891  *
892  */
hard_link_Index2Display(Index2Display * obj)893 Index2Display * hard_link_Index2Display(Index2Display * obj)
894 {
895     if( obj == NULL )    {
896       warn("Trying to hard link to a Index2Display object: passed a NULL object");
897       return NULL;
898       }
899     obj->dynamite_hard_link++;
900     return obj;
901 }
902 
903 
904 /* Function:  Index2Display_alloc(void)
905  *
906  * Descrip:    Allocates structure: assigns defaults if given
907  *
908  *
909  *
910  * Return [UNKN ]  Undocumented return value [Index2Display *]
911  *
912  */
Index2Display_alloc(void)913 Index2Display * Index2Display_alloc(void)
914 {
915     Index2Display * out;/* out is exported at end of function */
916 
917 
918     /* call ckalloc and see if NULL */
919     if((out=(Index2Display *) ckalloc (sizeof(Index2Display))) == NULL)  {
920       warn("Index2Display_alloc failed ");
921       return NULL;  /* calling function should respond! */
922       }
923     out->dynamite_hard_link = 1;
924 #ifdef PTHREAD
925     pthread_mutex_init(&(out->dynamite_mutex),NULL);
926 #endif
927     out->name = NULL;
928     out->eval = NULL;
929     out->is_start = FALSE;
930     out->number = 0;
931 
932 
933     return out;
934 }
935 
936 
937 /* Function:  free_Index2Display(obj)
938  *
939  * Descrip:    Free Function: removes the memory held by obj
940  *             Will chain up to owned members and clear all lists
941  *
942  *
943  * Arg:        obj [UNKN ] Object that is free'd [Index2Display *]
944  *
945  * Return [UNKN ]  Undocumented return value [Index2Display *]
946  *
947  */
free_Index2Display(Index2Display * obj)948 Index2Display * free_Index2Display(Index2Display * obj)
949 {
950     int return_early = 0;
951 
952 
953     if( obj == NULL) {
954       warn("Attempting to free a NULL pointer to a Index2Display obj. Should be trappable");
955       return NULL;
956       }
957 
958 
959 #ifdef PTHREAD
960     assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
961 #endif
962     if( obj->dynamite_hard_link > 1)     {
963       return_early = 1;
964       obj->dynamite_hard_link--;
965       }
966 #ifdef PTHREAD
967     assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
968 #endif
969     if( return_early == 1)
970       return NULL;
971     if( obj->name != NULL)
972       ckfree(obj->name);
973     if( obj->eval != NULL)
974       ckfree(obj->eval);
975 
976 
977     ckfree(obj);
978     return NULL;
979 }
980 
981 
982 /* Function:  swap_Label2Display(list,i,j)
983  *
984  * Descrip:    swap function: an internal for qsort_Label2Display
985  *             swaps two positions in the array
986  *
987  *
988  * Arg:        list [UNKN ] List of structures to swap in [Aln2DisplayField **]
989  * Arg:           i [UNKN ] swap position [int]
990  * Arg:           j [UNKN ] swap position [int]
991  *
992  */
993 /* swap function for qsort function */
swap_Label2Display(Aln2DisplayField ** list,int i,int j)994 void swap_Label2Display(Aln2DisplayField ** list,int i,int j)
995 {
996     Aln2DisplayField * temp;
997     temp=list[i];
998     list[i]=list[j];
999     list[j]=temp;
1000 }
1001 
1002 
1003 /* Function:  qsort_Label2Display(list,left,right,comp)
1004  *
1005  * Descrip:    qsort - lifted from K&R
1006  *             sorts the array using quicksort
1007  *             Probably much better to call sort_Label2Display which sorts from start to end
1008  *
1009  *
1010  * Arg:         list [UNKN ] List of structures to swap in [Aln2DisplayField **]
1011  * Arg:         left [UNKN ] left position [int]
1012  * Arg:        right [UNKN ] right position [int]
1013  * Arg:         comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
1014  *
1015  */
qsort_Label2Display(Aln2DisplayField ** list,int left,int right,int (* comp)(Aln2DisplayField *,Aln2DisplayField *))1016 void qsort_Label2Display(Aln2DisplayField ** list,int left,int right,int (*comp)(Aln2DisplayField * ,Aln2DisplayField * ))
1017 {
1018     int i,last;
1019     if( left >= right )
1020       return;
1021 
1022 
1023     swap_Label2Display(list,left,(left+right)/2);
1024     last = left;
1025     for ( i=left+1; i <= right;i++)  {
1026       if( (*comp)(list[i],list[left]) < 0)
1027         swap_Label2Display (list,++last,i);
1028       }
1029     swap_Label2Display (list,left,last);
1030     qsort_Label2Display(list,left,last-1,comp);
1031     qsort_Label2Display(list,last+1,right,comp);
1032 }
1033 
1034 
1035 /* Function:  sort_Label2Display(obj,comp)
1036  *
1037  * Descrip:    sorts from start to end using comp
1038  *             sorts the array using quicksort by calling qsort_Label2Display
1039  *
1040  *
1041  * Arg:         obj [UNKN ] Object containing list [Label2Display *]
1042  * Arg:        comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
1043  *
1044  */
sort_Label2Display(Label2Display * obj,int (* comp)(Aln2DisplayField *,Aln2DisplayField *))1045 void sort_Label2Display(Label2Display * obj,int (*comp)(Aln2DisplayField *, Aln2DisplayField *))
1046 {
1047     qsort_Label2Display(obj->a2df,0,obj->len-1,comp);
1048     return;
1049 }
1050 
1051 
1052 /* Function:  expand_Label2Display(obj,len)
1053  *
1054  * Descrip:    Really an internal function for add_Label2Display
1055  *
1056  *
1057  * Arg:        obj [UNKN ] Object which contains the list [Label2Display *]
1058  * Arg:        len [UNKN ] Length to add one [int]
1059  *
1060  * Return [UNKN ]  Undocumented return value [boolean]
1061  *
1062  */
expand_Label2Display(Label2Display * obj,int len)1063 boolean expand_Label2Display(Label2Display * obj,int len)
1064 {
1065 
1066 
1067     if( obj->maxlen > obj->len )     {
1068       warn("expand_Label2Display called with no need");
1069       return TRUE;
1070       }
1071 
1072 
1073     if( (obj->a2df = (Aln2DisplayField ** ) ckrealloc (obj->a2df,sizeof(Aln2DisplayField *)*len)) == NULL)   {
1074       warn("ckrealloc failed for expand_Label2Display, returning FALSE");
1075       return FALSE;
1076       }
1077     obj->maxlen = len;
1078     return TRUE;
1079 }
1080 
1081 
1082 /* Function:  add_Label2Display(obj,add)
1083  *
1084  * Descrip:    Adds another object to the list. It will expand the list if necessary
1085  *
1086  *
1087  * Arg:        obj [UNKN ] Object which contains the list [Label2Display *]
1088  * Arg:        add [OWNER] Object to add to the list [Aln2DisplayField *]
1089  *
1090  * Return [UNKN ]  Undocumented return value [boolean]
1091  *
1092  */
1093 /* will expand function if necessary */
add_Label2Display(Label2Display * obj,Aln2DisplayField * add)1094 boolean add_Label2Display(Label2Display * obj,Aln2DisplayField * add)
1095 {
1096     if( obj->len >= obj->maxlen) {
1097       if( expand_Label2Display(obj,obj->len + Label2DisplayLISTLENGTH) == FALSE)
1098         return FALSE;
1099       }
1100 
1101 
1102     obj->a2df[obj->len++]=add;
1103     return TRUE;
1104 }
1105 
1106 
1107 /* Function:  flush_Label2Display(obj)
1108  *
1109  * Descrip:    Frees the list elements, sets length to 0
1110  *             If you want to save some elements, use hard_link_xxx
1111  *             to protect them from being actually destroyed in the free
1112  *
1113  *
1114  * Arg:        obj [UNKN ] Object which contains the list  [Label2Display *]
1115  *
1116  * Return [UNKN ]  Undocumented return value [int]
1117  *
1118  */
flush_Label2Display(Label2Display * obj)1119 int flush_Label2Display(Label2Display * obj)
1120 {
1121     int i;
1122 
1123 
1124     for(i=0;i<obj->len;i++)  { /*for i over list length*/
1125       if( obj->a2df[i] != NULL)  {
1126         free_Aln2DisplayField(obj->a2df[i]);
1127         obj->a2df[i] = NULL;
1128         }
1129       } /* end of for i over list length */
1130 
1131 
1132     obj->len = 0;
1133     return i;
1134 }
1135 
1136 
1137 /* Function:  swap_ind_Label2Display(list,i,j)
1138  *
1139  * Descrip:    swap function: an internal for qsort_ind_Label2Display
1140  *             swaps two positions in the array
1141  *
1142  *
1143  * Arg:        list [UNKN ] List of structures to swap in [Index2Display **]
1144  * Arg:           i [UNKN ] swap position [int]
1145  * Arg:           j [UNKN ] swap position [int]
1146  *
1147  */
1148 /* swap function for qsort function */
swap_ind_Label2Display(Index2Display ** list,int i,int j)1149 void swap_ind_Label2Display(Index2Display ** list,int i,int j)
1150 {
1151     Index2Display * temp;
1152     temp=list[i];
1153     list[i]=list[j];
1154     list[j]=temp;
1155 }
1156 
1157 
1158 /* Function:  qsort_ind_Label2Display(list,left,right,comp)
1159  *
1160  * Descrip:    qsort - lifted from K&R
1161  *             sorts the array using quicksort
1162  *             Probably much better to call sort_ind_Label2Display which sorts from start to end
1163  *
1164  *
1165  * Arg:         list [UNKN ] List of structures to swap in [Index2Display **]
1166  * Arg:         left [UNKN ] left position [int]
1167  * Arg:        right [UNKN ] right position [int]
1168  * Arg:         comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
1169  *
1170  */
qsort_ind_Label2Display(Index2Display ** list,int left,int right,int (* comp)(Index2Display *,Index2Display *))1171 void qsort_ind_Label2Display(Index2Display ** list,int left,int right,int (*comp)(Index2Display * ,Index2Display * ))
1172 {
1173     int i,last;
1174     if( left >= right )
1175       return;
1176 
1177 
1178     swap_ind_Label2Display(list,left,(left+right)/2);
1179     last = left;
1180     for ( i=left+1; i <= right;i++)  {
1181       if( (*comp)(list[i],list[left]) < 0)
1182         swap_ind_Label2Display (list,++last,i);
1183       }
1184     swap_ind_Label2Display (list,left,last);
1185     qsort_ind_Label2Display(list,left,last-1,comp);
1186     qsort_ind_Label2Display(list,last+1,right,comp);
1187 }
1188 
1189 
1190 /* Function:  sort_ind_Label2Display(obj,comp)
1191  *
1192  * Descrip:    sorts from start to end using comp
1193  *             sorts the array using quicksort by calling qsort_ind_Label2Display
1194  *
1195  *
1196  * Arg:         obj [UNKN ] Object containing list [Label2Display *]
1197  * Arg:        comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
1198  *
1199  */
sort_ind_Label2Display(Label2Display * obj,int (* comp)(Index2Display *,Index2Display *))1200 void sort_ind_Label2Display(Label2Display * obj,int (*comp)(Index2Display *, Index2Display *))
1201 {
1202     qsort_ind_Label2Display(obj->i2d,0,obj->ind_len-1,comp);
1203     return;
1204 }
1205 
1206 
1207 /* Function:  expand_ind_Label2Display(obj,len)
1208  *
1209  * Descrip:    Really an internal function for add_ind_Label2Display
1210  *
1211  *
1212  * Arg:        obj [UNKN ] Object which contains the list [Label2Display *]
1213  * Arg:        len [UNKN ] Length to add one [int]
1214  *
1215  * Return [UNKN ]  Undocumented return value [boolean]
1216  *
1217  */
expand_ind_Label2Display(Label2Display * obj,int len)1218 boolean expand_ind_Label2Display(Label2Display * obj,int len)
1219 {
1220 
1221 
1222     if( obj->ind_maxlen > obj->ind_len )     {
1223       warn("expand_Label2Displayind_ called with no need");
1224       return TRUE;
1225       }
1226 
1227 
1228     if( (obj->i2d = (Index2Display ** ) ckrealloc (obj->i2d,sizeof(Index2Display *)*len)) == NULL)   {
1229       warn("ckrealloc failed for expand_Label2Display, returning FALSE");
1230       return FALSE;
1231       }
1232     obj->ind_maxlen = len;
1233     return TRUE;
1234 }
1235 
1236 
1237 /* Function:  add_ind_Label2Display(obj,add)
1238  *
1239  * Descrip:    Adds another object to the list. It will expand the list if necessary
1240  *
1241  *
1242  * Arg:        obj [UNKN ] Object which contains the list [Label2Display *]
1243  * Arg:        add [OWNER] Object to add to the list [Index2Display *]
1244  *
1245  * Return [UNKN ]  Undocumented return value [boolean]
1246  *
1247  */
1248 /* will expand function if necessary */
add_ind_Label2Display(Label2Display * obj,Index2Display * add)1249 boolean add_ind_Label2Display(Label2Display * obj,Index2Display * add)
1250 {
1251     if( obj->ind_len >= obj->ind_maxlen) {
1252       if( expand_ind_Label2Display(obj,obj->ind_len + Label2DisplayLISTLENGTH) == FALSE)
1253         return FALSE;
1254       }
1255 
1256 
1257     obj->i2d[obj->ind_len++]=add;
1258     return TRUE;
1259 }
1260 
1261 
1262 /* Function:  flush_ind_Label2Display(obj)
1263  *
1264  * Descrip:    Frees the list elements, sets length to 0
1265  *             If you want to save some elements, use hard_link_xxx
1266  *             to protect them from being actually destroyed in the free
1267  *
1268  *
1269  * Arg:        obj [UNKN ] Object which contains the list  [Label2Display *]
1270  *
1271  * Return [UNKN ]  Undocumented return value [int]
1272  *
1273  */
flush_ind_Label2Display(Label2Display * obj)1274 int flush_ind_Label2Display(Label2Display * obj)
1275 {
1276     int i;
1277 
1278 
1279     for(i=0;i<obj->ind_len;i++)  { /*for i over list length*/
1280       if( obj->i2d[i] != NULL)   {
1281         free_Index2Display(obj->i2d[i]);
1282         obj->i2d[i] = NULL;
1283         }
1284       } /* end of for i over list length */
1285 
1286 
1287     obj->ind_len = 0;
1288     return i;
1289 }
1290 
1291 
1292 /* Function:  Label2Display_alloc_std(void)
1293  *
1294  * Descrip:    Equivalent to Label2Display_alloc_len(Label2DisplayLISTLENGTH)
1295  *
1296  *
1297  *
1298  * Return [UNKN ]  Undocumented return value [Label2Display *]
1299  *
1300  */
Label2Display_alloc_std(void)1301 Label2Display * Label2Display_alloc_std(void)
1302 {
1303     return Label2Display_alloc_len(Label2DisplayLISTLENGTH);
1304 }
1305 
1306 
1307 /* Function:  Label2Display_alloc_len(len)
1308  *
1309  * Descrip:    Allocates len length to all lists
1310  *
1311  *
1312  * Arg:        len [UNKN ] Length of lists to allocate [int]
1313  *
1314  * Return [UNKN ]  Undocumented return value [Label2Display *]
1315  *
1316  */
Label2Display_alloc_len(int len)1317 Label2Display * Label2Display_alloc_len(int len)
1318 {
1319     Label2Display * out;/* out is exported at the end of function */
1320 
1321 
1322     /* Call alloc function: return NULL if NULL */
1323     /* Warning message alread in alloc function */
1324     if((out = Label2Display_alloc()) == NULL)
1325       return NULL;
1326 
1327 
1328     /* Calling ckcalloc for list elements */
1329     if((out->a2df = (Aln2DisplayField ** ) ckcalloc (len,sizeof(Aln2DisplayField *))) == NULL)   {
1330       warn("Warning, ckcalloc failed in Label2Display_alloc_len");
1331       return NULL;
1332       }
1333     out->len = 0;
1334     out->maxlen = len;
1335 
1336 
1337     if((out->i2d = (Index2Display ** ) ckcalloc (len,sizeof(Index2Display *))) == NULL)  {
1338       warn("Warning, ckcalloc failed in Label2Display_alloc_len");
1339       return NULL;
1340       }
1341     out->ind_len = 0;
1342     out->ind_maxlen = len;
1343 
1344 
1345     return out;
1346 }
1347 
1348 
1349 /* Function:  hard_link_Label2Display(obj)
1350  *
1351  * Descrip:    Bumps up the reference count of the object
1352  *             Meaning that multiple pointers can 'own' it
1353  *
1354  *
1355  * Arg:        obj [UNKN ] Object to be hard linked [Label2Display *]
1356  *
1357  * Return [UNKN ]  Undocumented return value [Label2Display *]
1358  *
1359  */
hard_link_Label2Display(Label2Display * obj)1360 Label2Display * hard_link_Label2Display(Label2Display * obj)
1361 {
1362     if( obj == NULL )    {
1363       warn("Trying to hard link to a Label2Display object: passed a NULL object");
1364       return NULL;
1365       }
1366     obj->dynamite_hard_link++;
1367     return obj;
1368 }
1369 
1370 
1371 /* Function:  Label2Display_alloc(void)
1372  *
1373  * Descrip:    Allocates structure: assigns defaults if given
1374  *
1375  *
1376  *
1377  * Return [UNKN ]  Undocumented return value [Label2Display *]
1378  *
1379  */
Label2Display_alloc(void)1380 Label2Display * Label2Display_alloc(void)
1381 {
1382     Label2Display * out;/* out is exported at end of function */
1383 
1384 
1385     /* call ckalloc and see if NULL */
1386     if((out=(Label2Display *) ckalloc (sizeof(Label2Display))) == NULL)  {
1387       warn("Label2Display_alloc failed ");
1388       return NULL;  /* calling function should respond! */
1389       }
1390     out->dynamite_hard_link = 1;
1391 #ifdef PTHREAD
1392     pthread_mutex_init(&(out->dynamite_mutex),NULL);
1393 #endif
1394     out->label = NULL;
1395     out->direction = NULL;
1396     out->a2df = NULL;
1397     out->len = out->maxlen = 0;
1398     out->i2d = NULL;
1399     out->ind_len = out->ind_maxlen = 0;
1400     out->is_lone = FALSE;
1401 
1402 
1403     return out;
1404 }
1405 
1406 
1407 /* Function:  free_Label2Display(obj)
1408  *
1409  * Descrip:    Free Function: removes the memory held by obj
1410  *             Will chain up to owned members and clear all lists
1411  *
1412  *
1413  * Arg:        obj [UNKN ] Object that is free'd [Label2Display *]
1414  *
1415  * Return [UNKN ]  Undocumented return value [Label2Display *]
1416  *
1417  */
free_Label2Display(Label2Display * obj)1418 Label2Display * free_Label2Display(Label2Display * obj)
1419 {
1420     int return_early = 0;
1421     int i;
1422 
1423 
1424     if( obj == NULL) {
1425       warn("Attempting to free a NULL pointer to a Label2Display obj. Should be trappable");
1426       return NULL;
1427       }
1428 
1429 
1430 #ifdef PTHREAD
1431     assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
1432 #endif
1433     if( obj->dynamite_hard_link > 1)     {
1434       return_early = 1;
1435       obj->dynamite_hard_link--;
1436       }
1437 #ifdef PTHREAD
1438     assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
1439 #endif
1440     if( return_early == 1)
1441       return NULL;
1442     if( obj->label != NULL)
1443       ckfree(obj->label);
1444     if( obj->direction != NULL)
1445       ckfree(obj->direction);
1446     if( obj->a2df != NULL)   {
1447       for(i=0;i<obj->len;i++)    {
1448         if( obj->a2df[i] != NULL)
1449           free_Aln2DisplayField(obj->a2df[i]);
1450         }
1451       ckfree(obj->a2df);
1452       }
1453     if( obj->i2d != NULL)    {
1454       for(i=0;i<obj->ind_len;i++)    {
1455         if( obj->i2d[i] != NULL)
1456           free_Index2Display(obj->i2d[i]);
1457         }
1458       ckfree(obj->i2d);
1459       }
1460 
1461 
1462     ckfree(obj);
1463     return NULL;
1464 }
1465 
1466 
1467 /* Function:  swap_Sequence2Display(list,i,j)
1468  *
1469  * Descrip:    swap function: an internal for qsort_Sequence2Display
1470  *             swaps two positions in the array
1471  *
1472  *
1473  * Arg:        list [UNKN ] List of structures to swap in [Label2Display **]
1474  * Arg:           i [UNKN ] swap position [int]
1475  * Arg:           j [UNKN ] swap position [int]
1476  *
1477  */
1478 /* swap function for qsort function */
swap_Sequence2Display(Label2Display ** list,int i,int j)1479 void swap_Sequence2Display(Label2Display ** list,int i,int j)
1480 {
1481     Label2Display * temp;
1482     temp=list[i];
1483     list[i]=list[j];
1484     list[j]=temp;
1485 }
1486 
1487 
1488 /* Function:  qsort_Sequence2Display(list,left,right,comp)
1489  *
1490  * Descrip:    qsort - lifted from K&R
1491  *             sorts the array using quicksort
1492  *             Probably much better to call sort_Sequence2Display which sorts from start to end
1493  *
1494  *
1495  * Arg:         list [UNKN ] List of structures to swap in [Label2Display **]
1496  * Arg:         left [UNKN ] left position [int]
1497  * Arg:        right [UNKN ] right position [int]
1498  * Arg:         comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
1499  *
1500  */
qsort_Sequence2Display(Label2Display ** list,int left,int right,int (* comp)(Label2Display *,Label2Display *))1501 void qsort_Sequence2Display(Label2Display ** list,int left,int right,int (*comp)(Label2Display * ,Label2Display * ))
1502 {
1503     int i,last;
1504     if( left >= right )
1505       return;
1506 
1507 
1508     swap_Sequence2Display(list,left,(left+right)/2);
1509     last = left;
1510     for ( i=left+1; i <= right;i++)  {
1511       if( (*comp)(list[i],list[left]) < 0)
1512         swap_Sequence2Display (list,++last,i);
1513       }
1514     swap_Sequence2Display (list,left,last);
1515     qsort_Sequence2Display(list,left,last-1,comp);
1516     qsort_Sequence2Display(list,last+1,right,comp);
1517 }
1518 
1519 
1520 /* Function:  sort_Sequence2Display(obj,comp)
1521  *
1522  * Descrip:    sorts from start to end using comp
1523  *             sorts the array using quicksort by calling qsort_Sequence2Display
1524  *
1525  *
1526  * Arg:         obj [UNKN ] Object containing list [Sequence2Display *]
1527  * Arg:        comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
1528  *
1529  */
sort_Sequence2Display(Sequence2Display * obj,int (* comp)(Label2Display *,Label2Display *))1530 void sort_Sequence2Display(Sequence2Display * obj,int (*comp)(Label2Display *, Label2Display *))
1531 {
1532     qsort_Sequence2Display(obj->l2d,0,obj->len-1,comp);
1533     return;
1534 }
1535 
1536 
1537 /* Function:  expand_Sequence2Display(obj,len)
1538  *
1539  * Descrip:    Really an internal function for add_Sequence2Display
1540  *
1541  *
1542  * Arg:        obj [UNKN ] Object which contains the list [Sequence2Display *]
1543  * Arg:        len [UNKN ] Length to add one [int]
1544  *
1545  * Return [UNKN ]  Undocumented return value [boolean]
1546  *
1547  */
expand_Sequence2Display(Sequence2Display * obj,int len)1548 boolean expand_Sequence2Display(Sequence2Display * obj,int len)
1549 {
1550 
1551 
1552     if( obj->maxlen > obj->len )     {
1553       warn("expand_Sequence2Display called with no need");
1554       return TRUE;
1555       }
1556 
1557 
1558     if( (obj->l2d = (Label2Display ** ) ckrealloc (obj->l2d,sizeof(Label2Display *)*len)) == NULL)   {
1559       warn("ckrealloc failed for expand_Sequence2Display, returning FALSE");
1560       return FALSE;
1561       }
1562     obj->maxlen = len;
1563     return TRUE;
1564 }
1565 
1566 
1567 /* Function:  add_Sequence2Display(obj,add)
1568  *
1569  * Descrip:    Adds another object to the list. It will expand the list if necessary
1570  *
1571  *
1572  * Arg:        obj [UNKN ] Object which contains the list [Sequence2Display *]
1573  * Arg:        add [OWNER] Object to add to the list [Label2Display *]
1574  *
1575  * Return [UNKN ]  Undocumented return value [boolean]
1576  *
1577  */
1578 /* will expand function if necessary */
add_Sequence2Display(Sequence2Display * obj,Label2Display * add)1579 boolean add_Sequence2Display(Sequence2Display * obj,Label2Display * add)
1580 {
1581     if( obj->len >= obj->maxlen) {
1582       if( expand_Sequence2Display(obj,obj->len + Sequence2DisplayLISTLENGTH) == FALSE)
1583         return FALSE;
1584       }
1585 
1586 
1587     obj->l2d[obj->len++]=add;
1588     return TRUE;
1589 }
1590 
1591 
1592 /* Function:  flush_Sequence2Display(obj)
1593  *
1594  * Descrip:    Frees the list elements, sets length to 0
1595  *             If you want to save some elements, use hard_link_xxx
1596  *             to protect them from being actually destroyed in the free
1597  *
1598  *
1599  * Arg:        obj [UNKN ] Object which contains the list  [Sequence2Display *]
1600  *
1601  * Return [UNKN ]  Undocumented return value [int]
1602  *
1603  */
flush_Sequence2Display(Sequence2Display * obj)1604 int flush_Sequence2Display(Sequence2Display * obj)
1605 {
1606     int i;
1607 
1608 
1609     for(i=0;i<obj->len;i++)  { /*for i over list length*/
1610       if( obj->l2d[i] != NULL)   {
1611         free_Label2Display(obj->l2d[i]);
1612         obj->l2d[i] = NULL;
1613         }
1614       } /* end of for i over list length */
1615 
1616 
1617     obj->len = 0;
1618     return i;
1619 }
1620 
1621 
1622 /* Function:  swap_ind_Sequence2Display(list,i,j)
1623  *
1624  * Descrip:    swap function: an internal for qsort_ind_Sequence2Display
1625  *             swaps two positions in the array
1626  *
1627  *
1628  * Arg:        list [UNKN ] List of structures to swap in [Index2Display **]
1629  * Arg:           i [UNKN ] swap position [int]
1630  * Arg:           j [UNKN ] swap position [int]
1631  *
1632  */
1633 /* swap function for qsort function */
swap_ind_Sequence2Display(Index2Display ** list,int i,int j)1634 void swap_ind_Sequence2Display(Index2Display ** list,int i,int j)
1635 {
1636     Index2Display * temp;
1637     temp=list[i];
1638     list[i]=list[j];
1639     list[j]=temp;
1640 }
1641 
1642 
1643 /* Function:  qsort_ind_Sequence2Display(list,left,right,comp)
1644  *
1645  * Descrip:    qsort - lifted from K&R
1646  *             sorts the array using quicksort
1647  *             Probably much better to call sort_ind_Sequence2Display which sorts from start to end
1648  *
1649  *
1650  * Arg:         list [UNKN ] List of structures to swap in [Index2Display **]
1651  * Arg:         left [UNKN ] left position [int]
1652  * Arg:        right [UNKN ] right position [int]
1653  * Arg:         comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
1654  *
1655  */
qsort_ind_Sequence2Display(Index2Display ** list,int left,int right,int (* comp)(Index2Display *,Index2Display *))1656 void qsort_ind_Sequence2Display(Index2Display ** list,int left,int right,int (*comp)(Index2Display * ,Index2Display * ))
1657 {
1658     int i,last;
1659     if( left >= right )
1660       return;
1661 
1662 
1663     swap_ind_Sequence2Display(list,left,(left+right)/2);
1664     last = left;
1665     for ( i=left+1; i <= right;i++)  {
1666       if( (*comp)(list[i],list[left]) < 0)
1667         swap_ind_Sequence2Display (list,++last,i);
1668       }
1669     swap_ind_Sequence2Display (list,left,last);
1670     qsort_ind_Sequence2Display(list,left,last-1,comp);
1671     qsort_ind_Sequence2Display(list,last+1,right,comp);
1672 }
1673 
1674 
1675 /* Function:  sort_ind_Sequence2Display(obj,comp)
1676  *
1677  * Descrip:    sorts from start to end using comp
1678  *             sorts the array using quicksort by calling qsort_ind_Sequence2Display
1679  *
1680  *
1681  * Arg:         obj [UNKN ] Object containing list [Sequence2Display *]
1682  * Arg:        comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
1683  *
1684  */
sort_ind_Sequence2Display(Sequence2Display * obj,int (* comp)(Index2Display *,Index2Display *))1685 void sort_ind_Sequence2Display(Sequence2Display * obj,int (*comp)(Index2Display *, Index2Display *))
1686 {
1687     qsort_ind_Sequence2Display(obj->i2d,0,obj->ind_len-1,comp);
1688     return;
1689 }
1690 
1691 
1692 /* Function:  expand_ind_Sequence2Display(obj,len)
1693  *
1694  * Descrip:    Really an internal function for add_ind_Sequence2Display
1695  *
1696  *
1697  * Arg:        obj [UNKN ] Object which contains the list [Sequence2Display *]
1698  * Arg:        len [UNKN ] Length to add one [int]
1699  *
1700  * Return [UNKN ]  Undocumented return value [boolean]
1701  *
1702  */
expand_ind_Sequence2Display(Sequence2Display * obj,int len)1703 boolean expand_ind_Sequence2Display(Sequence2Display * obj,int len)
1704 {
1705 
1706 
1707     if( obj->ind_maxlen > obj->ind_len )     {
1708       warn("expand_Sequence2Displayind_ called with no need");
1709       return TRUE;
1710       }
1711 
1712 
1713     if( (obj->i2d = (Index2Display ** ) ckrealloc (obj->i2d,sizeof(Index2Display *)*len)) == NULL)   {
1714       warn("ckrealloc failed for expand_Sequence2Display, returning FALSE");
1715       return FALSE;
1716       }
1717     obj->ind_maxlen = len;
1718     return TRUE;
1719 }
1720 
1721 
1722 /* Function:  add_ind_Sequence2Display(obj,add)
1723  *
1724  * Descrip:    Adds another object to the list. It will expand the list if necessary
1725  *
1726  *
1727  * Arg:        obj [UNKN ] Object which contains the list [Sequence2Display *]
1728  * Arg:        add [OWNER] Object to add to the list [Index2Display *]
1729  *
1730  * Return [UNKN ]  Undocumented return value [boolean]
1731  *
1732  */
1733 /* will expand function if necessary */
add_ind_Sequence2Display(Sequence2Display * obj,Index2Display * add)1734 boolean add_ind_Sequence2Display(Sequence2Display * obj,Index2Display * add)
1735 {
1736     if( obj->ind_len >= obj->ind_maxlen) {
1737       if( expand_ind_Sequence2Display(obj,obj->ind_len + Sequence2DisplayLISTLENGTH) == FALSE)
1738         return FALSE;
1739       }
1740 
1741 
1742     obj->i2d[obj->ind_len++]=add;
1743     return TRUE;
1744 }
1745 
1746 
1747 /* Function:  flush_ind_Sequence2Display(obj)
1748  *
1749  * Descrip:    Frees the list elements, sets length to 0
1750  *             If you want to save some elements, use hard_link_xxx
1751  *             to protect them from being actually destroyed in the free
1752  *
1753  *
1754  * Arg:        obj [UNKN ] Object which contains the list  [Sequence2Display *]
1755  *
1756  * Return [UNKN ]  Undocumented return value [int]
1757  *
1758  */
flush_ind_Sequence2Display(Sequence2Display * obj)1759 int flush_ind_Sequence2Display(Sequence2Display * obj)
1760 {
1761     int i;
1762 
1763 
1764     for(i=0;i<obj->ind_len;i++)  { /*for i over list length*/
1765       if( obj->i2d[i] != NULL)   {
1766         free_Index2Display(obj->i2d[i]);
1767         obj->i2d[i] = NULL;
1768         }
1769       } /* end of for i over list length */
1770 
1771 
1772     obj->ind_len = 0;
1773     return i;
1774 }
1775 
1776 
1777 /* Function:  Sequence2Display_alloc_std(void)
1778  *
1779  * Descrip:    Equivalent to Sequence2Display_alloc_len(Sequence2DisplayLISTLENGTH)
1780  *
1781  *
1782  *
1783  * Return [UNKN ]  Undocumented return value [Sequence2Display *]
1784  *
1785  */
Sequence2Display_alloc_std(void)1786 Sequence2Display * Sequence2Display_alloc_std(void)
1787 {
1788     return Sequence2Display_alloc_len(Sequence2DisplayLISTLENGTH);
1789 }
1790 
1791 
1792 /* Function:  Sequence2Display_alloc_len(len)
1793  *
1794  * Descrip:    Allocates len length to all lists
1795  *
1796  *
1797  * Arg:        len [UNKN ] Length of lists to allocate [int]
1798  *
1799  * Return [UNKN ]  Undocumented return value [Sequence2Display *]
1800  *
1801  */
Sequence2Display_alloc_len(int len)1802 Sequence2Display * Sequence2Display_alloc_len(int len)
1803 {
1804     Sequence2Display * out; /* out is exported at the end of function */
1805 
1806 
1807     /* Call alloc function: return NULL if NULL */
1808     /* Warning message alread in alloc function */
1809     if((out = Sequence2Display_alloc()) == NULL)
1810       return NULL;
1811 
1812 
1813     /* Calling ckcalloc for list elements */
1814     if((out->l2d = (Label2Display ** ) ckcalloc (len,sizeof(Label2Display *))) == NULL)  {
1815       warn("Warning, ckcalloc failed in Sequence2Display_alloc_len");
1816       return NULL;
1817       }
1818     out->len = 0;
1819     out->maxlen = len;
1820 
1821 
1822     if((out->i2d = (Index2Display ** ) ckcalloc (len,sizeof(Index2Display *))) == NULL)  {
1823       warn("Warning, ckcalloc failed in Sequence2Display_alloc_len");
1824       return NULL;
1825       }
1826     out->ind_len = 0;
1827     out->ind_maxlen = len;
1828 
1829 
1830     return out;
1831 }
1832 
1833 
1834 /* Function:  hard_link_Sequence2Display(obj)
1835  *
1836  * Descrip:    Bumps up the reference count of the object
1837  *             Meaning that multiple pointers can 'own' it
1838  *
1839  *
1840  * Arg:        obj [UNKN ] Object to be hard linked [Sequence2Display *]
1841  *
1842  * Return [UNKN ]  Undocumented return value [Sequence2Display *]
1843  *
1844  */
hard_link_Sequence2Display(Sequence2Display * obj)1845 Sequence2Display * hard_link_Sequence2Display(Sequence2Display * obj)
1846 {
1847     if( obj == NULL )    {
1848       warn("Trying to hard link to a Sequence2Display object: passed a NULL object");
1849       return NULL;
1850       }
1851     obj->dynamite_hard_link++;
1852     return obj;
1853 }
1854 
1855 
1856 /* Function:  Sequence2Display_alloc(void)
1857  *
1858  * Descrip:    Allocates structure: assigns defaults if given
1859  *
1860  *
1861  *
1862  * Return [UNKN ]  Undocumented return value [Sequence2Display *]
1863  *
1864  */
Sequence2Display_alloc(void)1865 Sequence2Display * Sequence2Display_alloc(void)
1866 {
1867     Sequence2Display * out; /* out is exported at end of function */
1868 
1869 
1870     /* call ckalloc and see if NULL */
1871     if((out=(Sequence2Display *) ckalloc (sizeof(Sequence2Display))) == NULL)    {
1872       warn("Sequence2Display_alloc failed ");
1873       return NULL;  /* calling function should respond! */
1874       }
1875     out->dynamite_hard_link = 1;
1876 #ifdef PTHREAD
1877     pthread_mutex_init(&(out->dynamite_mutex),NULL);
1878 #endif
1879     out->number = 0;
1880     out->l2d = NULL;
1881     out->len = out->maxlen = 0;
1882     out->i2d = NULL;
1883     out->ind_len = out->ind_maxlen = 0;
1884     out->name_str = NULL;
1885     out->length = 0;
1886     out->is_static = FALSE;
1887     out->direction = NULL;
1888 
1889 
1890     return out;
1891 }
1892 
1893 
1894 /* Function:  free_Sequence2Display(obj)
1895  *
1896  * Descrip:    Free Function: removes the memory held by obj
1897  *             Will chain up to owned members and clear all lists
1898  *
1899  *
1900  * Arg:        obj [UNKN ] Object that is free'd [Sequence2Display *]
1901  *
1902  * Return [UNKN ]  Undocumented return value [Sequence2Display *]
1903  *
1904  */
free_Sequence2Display(Sequence2Display * obj)1905 Sequence2Display * free_Sequence2Display(Sequence2Display * obj)
1906 {
1907     int return_early = 0;
1908     int i;
1909 
1910 
1911     if( obj == NULL) {
1912       warn("Attempting to free a NULL pointer to a Sequence2Display obj. Should be trappable");
1913       return NULL;
1914       }
1915 
1916 
1917 #ifdef PTHREAD
1918     assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
1919 #endif
1920     if( obj->dynamite_hard_link > 1)     {
1921       return_early = 1;
1922       obj->dynamite_hard_link--;
1923       }
1924 #ifdef PTHREAD
1925     assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
1926 #endif
1927     if( return_early == 1)
1928       return NULL;
1929     if( obj->l2d != NULL)    {
1930       for(i=0;i<obj->len;i++)    {
1931         if( obj->l2d[i] != NULL)
1932           free_Label2Display(obj->l2d[i]);
1933         }
1934       ckfree(obj->l2d);
1935       }
1936     if( obj->i2d != NULL)    {
1937       for(i=0;i<obj->ind_len;i++)    {
1938         if( obj->i2d[i] != NULL)
1939           free_Index2Display(obj->i2d[i]);
1940         }
1941       ckfree(obj->i2d);
1942       }
1943     if( obj->name_str != NULL)
1944       ckfree(obj->name_str);
1945     if( obj->direction != NULL)
1946       ckfree(obj->direction);
1947 
1948 
1949     ckfree(obj);
1950     return NULL;
1951 }
1952 
1953 
1954 /* Function:  hard_link_Aln2DisplayResource(obj)
1955  *
1956  * Descrip:    Bumps up the reference count of the object
1957  *             Meaning that multiple pointers can 'own' it
1958  *
1959  *
1960  * Arg:        obj [UNKN ] Object to be hard linked [Aln2DisplayResource *]
1961  *
1962  * Return [UNKN ]  Undocumented return value [Aln2DisplayResource *]
1963  *
1964  */
hard_link_Aln2DisplayResource(Aln2DisplayResource * obj)1965 Aln2DisplayResource * hard_link_Aln2DisplayResource(Aln2DisplayResource * obj)
1966 {
1967     if( obj == NULL )    {
1968       warn("Trying to hard link to a Aln2DisplayResource object: passed a NULL object");
1969       return NULL;
1970       }
1971     obj->dynamite_hard_link++;
1972     return obj;
1973 }
1974 
1975 
1976 /* Function:  Aln2DisplayResource_alloc(void)
1977  *
1978  * Descrip:    Allocates structure: assigns defaults if given
1979  *
1980  *
1981  *
1982  * Return [UNKN ]  Undocumented return value [Aln2DisplayResource *]
1983  *
1984  */
Aln2DisplayResource_alloc(void)1985 Aln2DisplayResource * Aln2DisplayResource_alloc(void)
1986 {
1987     Aln2DisplayResource * out;  /* out is exported at end of function */
1988 
1989 
1990     /* call ckalloc and see if NULL */
1991     if((out=(Aln2DisplayResource *) ckalloc (sizeof(Aln2DisplayResource))) == NULL)  {
1992       warn("Aln2DisplayResource_alloc failed ");
1993       return NULL;  /* calling function should respond! */
1994       }
1995     out->dynamite_hard_link = 1;
1996 #ifdef PTHREAD
1997     pthread_mutex_init(&(out->dynamite_mutex),NULL);
1998 #endif
1999     out->type = NULL;
2000     out->name = NULL;
2001     out->arg = NULL;
2002 
2003 
2004     return out;
2005 }
2006 
2007 
2008 /* Function:  free_Aln2DisplayResource(obj)
2009  *
2010  * Descrip:    Free Function: removes the memory held by obj
2011  *             Will chain up to owned members and clear all lists
2012  *
2013  *
2014  * Arg:        obj [UNKN ] Object that is free'd [Aln2DisplayResource *]
2015  *
2016  * Return [UNKN ]  Undocumented return value [Aln2DisplayResource *]
2017  *
2018  */
free_Aln2DisplayResource(Aln2DisplayResource * obj)2019 Aln2DisplayResource * free_Aln2DisplayResource(Aln2DisplayResource * obj)
2020 {
2021     int return_early = 0;
2022 
2023 
2024     if( obj == NULL) {
2025       warn("Attempting to free a NULL pointer to a Aln2DisplayResource obj. Should be trappable");
2026       return NULL;
2027       }
2028 
2029 
2030 #ifdef PTHREAD
2031     assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
2032 #endif
2033     if( obj->dynamite_hard_link > 1)     {
2034       return_early = 1;
2035       obj->dynamite_hard_link--;
2036       }
2037 #ifdef PTHREAD
2038     assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
2039 #endif
2040     if( return_early == 1)
2041       return NULL;
2042     if( obj->type != NULL)
2043       ckfree(obj->type);
2044     if( obj->name != NULL)
2045       ckfree(obj->name);
2046     if( obj->arg != NULL)
2047       ckfree(obj->arg);
2048 
2049 
2050     ckfree(obj);
2051     return NULL;
2052 }
2053 
2054 
2055 /* Function:  swap_res_Aln2Display(list,i,j)
2056  *
2057  * Descrip:    swap function: an internal for qsort_res_Aln2Display
2058  *             swaps two positions in the array
2059  *
2060  *
2061  * Arg:        list [UNKN ] List of structures to swap in [Aln2DisplayResource **]
2062  * Arg:           i [UNKN ] swap position [int]
2063  * Arg:           j [UNKN ] swap position [int]
2064  *
2065  */
2066 /* swap function for qsort function */
swap_res_Aln2Display(Aln2DisplayResource ** list,int i,int j)2067 void swap_res_Aln2Display(Aln2DisplayResource ** list,int i,int j)
2068 {
2069     Aln2DisplayResource * temp;
2070     temp=list[i];
2071     list[i]=list[j];
2072     list[j]=temp;
2073 }
2074 
2075 
2076 /* Function:  qsort_res_Aln2Display(list,left,right,comp)
2077  *
2078  * Descrip:    qsort - lifted from K&R
2079  *             sorts the array using quicksort
2080  *             Probably much better to call sort_res_Aln2Display which sorts from start to end
2081  *
2082  *
2083  * Arg:         list [UNKN ] List of structures to swap in [Aln2DisplayResource **]
2084  * Arg:         left [UNKN ] left position [int]
2085  * Arg:        right [UNKN ] right position [int]
2086  * Arg:         comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
2087  *
2088  */
qsort_res_Aln2Display(Aln2DisplayResource ** list,int left,int right,int (* comp)(Aln2DisplayResource *,Aln2DisplayResource *))2089 void qsort_res_Aln2Display(Aln2DisplayResource ** list,int left,int right,int (*comp)(Aln2DisplayResource * ,Aln2DisplayResource * ))
2090 {
2091     int i,last;
2092     if( left >= right )
2093       return;
2094 
2095 
2096     swap_res_Aln2Display(list,left,(left+right)/2);
2097     last = left;
2098     for ( i=left+1; i <= right;i++)  {
2099       if( (*comp)(list[i],list[left]) < 0)
2100         swap_res_Aln2Display (list,++last,i);
2101       }
2102     swap_res_Aln2Display (list,left,last);
2103     qsort_res_Aln2Display(list,left,last-1,comp);
2104     qsort_res_Aln2Display(list,last+1,right,comp);
2105 }
2106 
2107 
2108 /* Function:  sort_res_Aln2Display(obj,comp)
2109  *
2110  * Descrip:    sorts from start to end using comp
2111  *             sorts the array using quicksort by calling qsort_res_Aln2Display
2112  *
2113  *
2114  * Arg:         obj [UNKN ] Object containing list [Aln2Display *]
2115  * Arg:        comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
2116  *
2117  */
sort_res_Aln2Display(Aln2Display * obj,int (* comp)(Aln2DisplayResource *,Aln2DisplayResource *))2118 void sort_res_Aln2Display(Aln2Display * obj,int (*comp)(Aln2DisplayResource *, Aln2DisplayResource *))
2119 {
2120     qsort_res_Aln2Display(obj->a2dr,0,obj->res_len-1,comp);
2121     return;
2122 }
2123 
2124 
2125 /* Function:  expand_res_Aln2Display(obj,len)
2126  *
2127  * Descrip:    Really an internal function for add_res_Aln2Display
2128  *
2129  *
2130  * Arg:        obj [UNKN ] Object which contains the list [Aln2Display *]
2131  * Arg:        len [UNKN ] Length to add one [int]
2132  *
2133  * Return [UNKN ]  Undocumented return value [boolean]
2134  *
2135  */
expand_res_Aln2Display(Aln2Display * obj,int len)2136 boolean expand_res_Aln2Display(Aln2Display * obj,int len)
2137 {
2138 
2139 
2140     if( obj->res_maxlen > obj->res_len )     {
2141       warn("expand_Aln2Displayres_ called with no need");
2142       return TRUE;
2143       }
2144 
2145 
2146     if( (obj->a2dr = (Aln2DisplayResource ** ) ckrealloc (obj->a2dr,sizeof(Aln2DisplayResource *)*len)) == NULL)     {
2147       warn("ckrealloc failed for expand_Aln2Display, returning FALSE");
2148       return FALSE;
2149       }
2150     obj->res_maxlen = len;
2151     return TRUE;
2152 }
2153 
2154 
2155 /* Function:  add_res_Aln2Display(obj,add)
2156  *
2157  * Descrip:    Adds another object to the list. It will expand the list if necessary
2158  *
2159  *
2160  * Arg:        obj [UNKN ] Object which contains the list [Aln2Display *]
2161  * Arg:        add [OWNER] Object to add to the list [Aln2DisplayResource *]
2162  *
2163  * Return [UNKN ]  Undocumented return value [boolean]
2164  *
2165  */
2166 /* will expand function if necessary */
add_res_Aln2Display(Aln2Display * obj,Aln2DisplayResource * add)2167 boolean add_res_Aln2Display(Aln2Display * obj,Aln2DisplayResource * add)
2168 {
2169     if( obj->res_len >= obj->res_maxlen) {
2170       if( expand_res_Aln2Display(obj,obj->res_len + Aln2DisplayLISTLENGTH) == FALSE)
2171         return FALSE;
2172       }
2173 
2174 
2175     obj->a2dr[obj->res_len++]=add;
2176     return TRUE;
2177 }
2178 
2179 
2180 /* Function:  flush_res_Aln2Display(obj)
2181  *
2182  * Descrip:    Frees the list elements, sets length to 0
2183  *             If you want to save some elements, use hard_link_xxx
2184  *             to protect them from being actually destroyed in the free
2185  *
2186  *
2187  * Arg:        obj [UNKN ] Object which contains the list  [Aln2Display *]
2188  *
2189  * Return [UNKN ]  Undocumented return value [int]
2190  *
2191  */
flush_res_Aln2Display(Aln2Display * obj)2192 int flush_res_Aln2Display(Aln2Display * obj)
2193 {
2194     int i;
2195 
2196 
2197     for(i=0;i<obj->res_len;i++)  { /*for i over list length*/
2198       if( obj->a2dr[i] != NULL)  {
2199         free_Aln2DisplayResource(obj->a2dr[i]);
2200         obj->a2dr[i] = NULL;
2201         }
2202       } /* end of for i over list length */
2203 
2204 
2205     obj->res_len = 0;
2206     return i;
2207 }
2208 
2209 
2210 /* Function:  swap_Aln2Display(list,i,j)
2211  *
2212  * Descrip:    swap function: an internal for qsort_Aln2Display
2213  *             swaps two positions in the array
2214  *
2215  *
2216  * Arg:        list [UNKN ] List of structures to swap in [Sequence2Display **]
2217  * Arg:           i [UNKN ] swap position [int]
2218  * Arg:           j [UNKN ] swap position [int]
2219  *
2220  */
2221 /* swap function for qsort function */
swap_Aln2Display(Sequence2Display ** list,int i,int j)2222 void swap_Aln2Display(Sequence2Display ** list,int i,int j)
2223 {
2224     Sequence2Display * temp;
2225     temp=list[i];
2226     list[i]=list[j];
2227     list[j]=temp;
2228 }
2229 
2230 
2231 /* Function:  qsort_Aln2Display(list,left,right,comp)
2232  *
2233  * Descrip:    qsort - lifted from K&R
2234  *             sorts the array using quicksort
2235  *             Probably much better to call sort_Aln2Display which sorts from start to end
2236  *
2237  *
2238  * Arg:         list [UNKN ] List of structures to swap in [Sequence2Display **]
2239  * Arg:         left [UNKN ] left position [int]
2240  * Arg:        right [UNKN ] right position [int]
2241  * Arg:         comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
2242  *
2243  */
qsort_Aln2Display(Sequence2Display ** list,int left,int right,int (* comp)(Sequence2Display *,Sequence2Display *))2244 void qsort_Aln2Display(Sequence2Display ** list,int left,int right,int (*comp)(Sequence2Display * ,Sequence2Display * ))
2245 {
2246     int i,last;
2247     if( left >= right )
2248       return;
2249 
2250 
2251     swap_Aln2Display(list,left,(left+right)/2);
2252     last = left;
2253     for ( i=left+1; i <= right;i++)  {
2254       if( (*comp)(list[i],list[left]) < 0)
2255         swap_Aln2Display (list,++last,i);
2256       }
2257     swap_Aln2Display (list,left,last);
2258     qsort_Aln2Display(list,left,last-1,comp);
2259     qsort_Aln2Display(list,last+1,right,comp);
2260 }
2261 
2262 
2263 /* Function:  sort_Aln2Display(obj,comp)
2264  *
2265  * Descrip:    sorts from start to end using comp
2266  *             sorts the array using quicksort by calling qsort_Aln2Display
2267  *
2268  *
2269  * Arg:         obj [UNKN ] Object containing list [Aln2Display *]
2270  * Arg:        comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
2271  *
2272  */
sort_Aln2Display(Aln2Display * obj,int (* comp)(Sequence2Display *,Sequence2Display *))2273 void sort_Aln2Display(Aln2Display * obj,int (*comp)(Sequence2Display *, Sequence2Display *))
2274 {
2275     qsort_Aln2Display(obj->s2d,0,obj->len-1,comp);
2276     return;
2277 }
2278 
2279 
2280 /* Function:  expand_Aln2Display(obj,len)
2281  *
2282  * Descrip:    Really an internal function for add_Aln2Display
2283  *
2284  *
2285  * Arg:        obj [UNKN ] Object which contains the list [Aln2Display *]
2286  * Arg:        len [UNKN ] Length to add one [int]
2287  *
2288  * Return [UNKN ]  Undocumented return value [boolean]
2289  *
2290  */
expand_Aln2Display(Aln2Display * obj,int len)2291 boolean expand_Aln2Display(Aln2Display * obj,int len)
2292 {
2293 
2294 
2295     if( obj->maxlen > obj->len )     {
2296       warn("expand_Aln2Display called with no need");
2297       return TRUE;
2298       }
2299 
2300 
2301     if( (obj->s2d = (Sequence2Display ** ) ckrealloc (obj->s2d,sizeof(Sequence2Display *)*len)) == NULL)     {
2302       warn("ckrealloc failed for expand_Aln2Display, returning FALSE");
2303       return FALSE;
2304       }
2305     obj->maxlen = len;
2306     return TRUE;
2307 }
2308 
2309 
2310 /* Function:  add_Aln2Display(obj,add)
2311  *
2312  * Descrip:    Adds another object to the list. It will expand the list if necessary
2313  *
2314  *
2315  * Arg:        obj [UNKN ] Object which contains the list [Aln2Display *]
2316  * Arg:        add [OWNER] Object to add to the list [Sequence2Display *]
2317  *
2318  * Return [UNKN ]  Undocumented return value [boolean]
2319  *
2320  */
2321 /* will expand function if necessary */
add_Aln2Display(Aln2Display * obj,Sequence2Display * add)2322 boolean add_Aln2Display(Aln2Display * obj,Sequence2Display * add)
2323 {
2324     if( obj->len >= obj->maxlen) {
2325       if( expand_Aln2Display(obj,obj->len + Aln2DisplayLISTLENGTH) == FALSE)
2326         return FALSE;
2327       }
2328 
2329 
2330     obj->s2d[obj->len++]=add;
2331     return TRUE;
2332 }
2333 
2334 
2335 /* Function:  flush_Aln2Display(obj)
2336  *
2337  * Descrip:    Frees the list elements, sets length to 0
2338  *             If you want to save some elements, use hard_link_xxx
2339  *             to protect them from being actually destroyed in the free
2340  *
2341  *
2342  * Arg:        obj [UNKN ] Object which contains the list  [Aln2Display *]
2343  *
2344  * Return [UNKN ]  Undocumented return value [int]
2345  *
2346  */
flush_Aln2Display(Aln2Display * obj)2347 int flush_Aln2Display(Aln2Display * obj)
2348 {
2349     int i;
2350 
2351 
2352     for(i=0;i<obj->len;i++)  { /*for i over list length*/
2353       if( obj->s2d[i] != NULL)   {
2354         free_Sequence2Display(obj->s2d[i]);
2355         obj->s2d[i] = NULL;
2356         }
2357       } /* end of for i over list length */
2358 
2359 
2360     obj->len = 0;
2361     return i;
2362 }
2363 
2364 
2365 /* Function:  Aln2Display_alloc_std(void)
2366  *
2367  * Descrip:    Equivalent to Aln2Display_alloc_len(Aln2DisplayLISTLENGTH)
2368  *
2369  *
2370  *
2371  * Return [UNKN ]  Undocumented return value [Aln2Display *]
2372  *
2373  */
Aln2Display_alloc_std(void)2374 Aln2Display * Aln2Display_alloc_std(void)
2375 {
2376     return Aln2Display_alloc_len(Aln2DisplayLISTLENGTH);
2377 }
2378 
2379 
2380 /* Function:  Aln2Display_alloc_len(len)
2381  *
2382  * Descrip:    Allocates len length to all lists
2383  *
2384  *
2385  * Arg:        len [UNKN ] Length of lists to allocate [int]
2386  *
2387  * Return [UNKN ]  Undocumented return value [Aln2Display *]
2388  *
2389  */
Aln2Display_alloc_len(int len)2390 Aln2Display * Aln2Display_alloc_len(int len)
2391 {
2392     Aln2Display * out;  /* out is exported at the end of function */
2393 
2394 
2395     /* Call alloc function: return NULL if NULL */
2396     /* Warning message alread in alloc function */
2397     if((out = Aln2Display_alloc()) == NULL)
2398       return NULL;
2399 
2400 
2401     /* Calling ckcalloc for list elements */
2402     if((out->a2dr = (Aln2DisplayResource ** ) ckcalloc (len,sizeof(Aln2DisplayResource *))) == NULL) {
2403       warn("Warning, ckcalloc failed in Aln2Display_alloc_len");
2404       return NULL;
2405       }
2406     out->res_len = 0;
2407     out->res_maxlen = len;
2408 
2409 
2410     if((out->s2d = (Sequence2Display ** ) ckcalloc (len,sizeof(Sequence2Display *))) == NULL)    {
2411       warn("Warning, ckcalloc failed in Aln2Display_alloc_len");
2412       return NULL;
2413       }
2414     out->len = 0;
2415     out->maxlen = len;
2416 
2417 
2418     return out;
2419 }
2420 
2421 
2422 /* Function:  hard_link_Aln2Display(obj)
2423  *
2424  * Descrip:    Bumps up the reference count of the object
2425  *             Meaning that multiple pointers can 'own' it
2426  *
2427  *
2428  * Arg:        obj [UNKN ] Object to be hard linked [Aln2Display *]
2429  *
2430  * Return [UNKN ]  Undocumented return value [Aln2Display *]
2431  *
2432  */
hard_link_Aln2Display(Aln2Display * obj)2433 Aln2Display * hard_link_Aln2Display(Aln2Display * obj)
2434 {
2435     if( obj == NULL )    {
2436       warn("Trying to hard link to a Aln2Display object: passed a NULL object");
2437       return NULL;
2438       }
2439     obj->dynamite_hard_link++;
2440     return obj;
2441 }
2442 
2443 
2444 /* Function:  Aln2Display_alloc(void)
2445  *
2446  * Descrip:    Allocates structure: assigns defaults if given
2447  *
2448  *
2449  *
2450  * Return [UNKN ]  Undocumented return value [Aln2Display *]
2451  *
2452  */
Aln2Display_alloc(void)2453 Aln2Display * Aln2Display_alloc(void)
2454 {
2455     Aln2Display * out;  /* out is exported at end of function */
2456 
2457 
2458     /* call ckalloc and see if NULL */
2459     if((out=(Aln2Display *) ckalloc (sizeof(Aln2Display))) == NULL)  {
2460       warn("Aln2Display_alloc failed ");
2461       return NULL;  /* calling function should respond! */
2462       }
2463     out->dynamite_hard_link = 1;
2464 #ifdef PTHREAD
2465     pthread_mutex_init(&(out->dynamite_mutex),NULL);
2466 #endif
2467     out->name = NULL;
2468     out->a2dr = NULL;
2469     out->res_len = out->res_maxlen = 0;
2470     out->s2d = NULL;
2471     out->len = out->maxlen = 0;
2472     out->other = NULL;
2473 
2474 
2475     return out;
2476 }
2477 
2478 
2479 /* Function:  free_Aln2Display(obj)
2480  *
2481  * Descrip:    Free Function: removes the memory held by obj
2482  *             Will chain up to owned members and clear all lists
2483  *
2484  *
2485  * Arg:        obj [UNKN ] Object that is free'd [Aln2Display *]
2486  *
2487  * Return [UNKN ]  Undocumented return value [Aln2Display *]
2488  *
2489  */
free_Aln2Display(Aln2Display * obj)2490 Aln2Display * free_Aln2Display(Aln2Display * obj)
2491 {
2492     int return_early = 0;
2493     int i;
2494 
2495 
2496     if( obj == NULL) {
2497       warn("Attempting to free a NULL pointer to a Aln2Display obj. Should be trappable");
2498       return NULL;
2499       }
2500 
2501 
2502 #ifdef PTHREAD
2503     assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
2504 #endif
2505     if( obj->dynamite_hard_link > 1)     {
2506       return_early = 1;
2507       obj->dynamite_hard_link--;
2508       }
2509 #ifdef PTHREAD
2510     assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
2511 #endif
2512     if( return_early == 1)
2513       return NULL;
2514     if( obj->name != NULL)
2515       ckfree(obj->name);
2516     if( obj->a2dr != NULL)   {
2517       for(i=0;i<obj->res_len;i++)    {
2518         if( obj->a2dr[i] != NULL)
2519           free_Aln2DisplayResource(obj->a2dr[i]);
2520         }
2521       ckfree(obj->a2dr);
2522       }
2523     if( obj->s2d != NULL)    {
2524       for(i=0;i<obj->len;i++)    {
2525         if( obj->s2d[i] != NULL)
2526           free_Sequence2Display(obj->s2d[i]);
2527         }
2528       ckfree(obj->s2d);
2529       }
2530     if( obj->other != NULL)
2531       free_Sequence2Display(obj->other);
2532 
2533 
2534     ckfree(obj);
2535     return NULL;
2536 }
2537 
2538 
2539 
2540 #ifdef _cplusplus
2541 }
2542 #endif
2543