Next version of JABA
[jabaws.git] / binaries / src / fasta34 / re_getlib.c
1 /* re_getlib.c - re-acquire a sequence given lseek, lcont */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 #include "defs.h"
8 #include "mm_file.h"
9
10 #define GETLIB (m_fptr->getlib)
11
12 int
13 re_getlib(unsigned char *aa1,
14           int maxn,     /* longest aa1 */
15           int maxt3,    /* alternate maxn */
16           int loff,     /* overlap */
17           int lcont,
18           int term_code,
19           long *loffset,        /* offset from real start of sequence */
20           long *l_off_p,        /* coordinate of sequence start */
21           struct lmf_str *m_fptr) {
22
23   unsigned char *aa1ptr;
24   int icont, maxt, ccont, n1;
25   char libstr[20];
26   fseek_t lmark; 
27   
28   aa1ptr = aa1;
29   icont=0;
30
31   *loffset = 0l;
32   maxt = maxn;
33   n1 = -1;
34   for (ccont=0; ccont<=lcont-1; ccont++) {
35
36     n1= GETLIB(aa1ptr,maxt,libstr,sizeof(libstr),&lmark,&icont,m_fptr,l_off_p);
37
38     if (term_code && m_fptr->lib_aa && aa1ptr[n1-1]!=term_code) {
39       aa1ptr[n1++]=term_code;
40       aa1ptr[n1]=0;
41     }
42
43     if (aa1ptr!=aa1) n1 += loff;
44
45     if (icont>lcont-1) break;
46
47     if (icont) {
48       maxt = maxt3;
49       memcpy(aa1,&aa1[n1-loff],loff);
50       aa1ptr= &aa1[loff];
51       *loffset += n1 - loff;
52     }
53     else {
54       maxt = maxn;
55       aa1ptr=aa1;
56     }
57   }
58   return n1;
59 }